accelerate_general/vector_f64.rs
1use std::ffi::{c_double, c_int};
2
3#[link(name = "Accelerate", kind = "framework")]
4extern "C" {
5 /// Computes the linear combination of two double-precision vectors `x` and `y` as:
6 /// `y = alpha * x + beta * y`.
7 /// This modifies the `y` vector in-place.
8 ///
9 /// # Precision
10 /// This function operates on `f64` numbers.
11 ///
12 /// # Parameters
13 /// - `n`: The number of elements in the vectors `x` and `y`.
14 /// - `alpha`: The scalar that scales the `x` vector.
15 /// - `x`: A pointer to the first input vector of `f64` numbers.
16 /// - `inc_x`: The increment between elements in `x`.
17 /// - `beta`: The scalar that scales the `y` vector.
18 /// - `y`: A pointer to the second input vector, which stores the result in-place.
19 /// - `inc_y`: The increment between elements in `y`.
20 ///
21 /// # Safety
22 /// This is an `unsafe` C function, and it is the caller's responsibility to ensure that
23 /// the memory regions accessed by `x` and `y` (up to `n * inc_x` and `n * inc_y` respectively)
24 /// are valid and within bounds.
25 #[link_name = "catlas_daxpby"]
26 pub fn lin_comb_catlas(
27 n: c_int,
28 alpha: c_double,
29 x: *const c_double,
30 inc_x: c_int,
31 beta: c_double,
32 y: *mut c_double,
33 inc_y: c_int,
34 );
35
36 /// Sets all elements in the double-precision vector `x` to the given value `alpha`.
37 ///
38 /// # Precision
39 /// This function operates on `f64` numbers.
40 ///
41 /// # Parameters
42 /// - `n`: The number of elements in the vector `x`.
43 /// - `alpha`: The scalar value to set all elements of `x`.
44 /// - `x`: A pointer to the vector to be modified in-place.
45 /// - `inc_x`: The increment between elements in `x`.
46 ///
47 /// # Safety
48 /// This is an `unsafe` C function, and it is the caller's responsibility to ensure that
49 /// the memory region accessed by `x` (up to `n * inc_x`) is valid and within bounds.
50 #[link_name = "catlas_dset"]
51 pub fn set(n: c_int, alpha: c_double, x: *mut c_double, inc_x: c_int);
52
53 /// Computes the dot product of two double-precision vectors `X` and `Y`.
54 ///
55 /// # Precision
56 /// This function operates on `f64` (double-precision) numbers.
57 ///
58 /// # Parameters
59 /// - `n`: The number of elements in the vectors `X` and `Y`.
60 /// - `x`: A pointer to the first input vector of `f64` numbers.
61 /// - `inc_x`: The increment (stride) between elements in `x`. For example, if `inc_x = 7`, every 7th element is used.
62 /// - `y`: A pointer to the second input vector of `f64` numbers.
63 /// - `inc_y`: The increment (stride) between elements in `y`. For example, if `inc_y = 7`, every 7th element is used.
64 ///
65 /// # Returns
66 /// - The dot product of `x` and `y` as a `f64`.
67 ///
68 /// # Safety
69 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` and `y`
70 /// (up to `n * inc_x` and `n * inc_y`) are valid and within bounds.
71 #[link_name = "cblas_ddot"]
72 pub fn dot(
73 n: c_int,
74 x: *const c_double,
75 inc_x: c_int,
76 y: *const c_double,
77 inc_y: c_int,
78 ) -> c_double;
79
80 /// Computes the sum of the absolute values of elements in a double-precision vector.
81 ///
82 /// # Precision
83 /// This function operates on double-precision (`f64`) numbers.
84 ///
85 /// # Parameters
86 /// - `n`: The number of elements in the vector.
87 /// - `x`: A pointer to the input vector `x`.
88 /// - `inc_x`: The increment between elements in `x`.
89 ///
90 /// # Returns
91 /// Returns the sum of the absolute values of the elements in `x`.
92 ///
93 /// # Safety
94 /// This is an `unsafe` C function. The caller must ensure that the memory region accessed by `x`
95 /// (up to `n * inc_x` elements) is valid and within bounds.
96 #[link_name = "cblas_dasum"]
97 pub fn norm1(n: c_int, x: *const c_double, inc_x: c_int) -> c_double;
98
99 /// Computes `y = alpha * x + y` where `x` and `y` are vectors.
100 ///
101 /// # Precision
102 /// This function operates on double-precision (`f64`) numbers.
103 ///
104 /// # Parameters
105 /// - `n`: The number of elements in vectors `x` and `y`.
106 /// - `alpha`: The scalar factor.
107 /// - `x`: A pointer to vector `x`.
108 /// - `inc_x`: The increment between elements in `x`.
109 /// - `y`: A pointer to vector `y`, which is modified in place.
110 /// - `inc_y`: The increment between elements in `y`.
111 ///
112 /// # Safety
113 /// This is an `unsafe` C function. The caller must ensure that the memory regions for `x` and `y`
114 /// (up to `n * inc_x` and `n * inc_y` elements, respectively) are valid and within bounds.
115 #[link_name = "cblas_daxpy"]
116 pub fn lin_comb(
117 n: c_int,
118 alpha: c_double,
119 x: *const c_double,
120 inc_x: c_int,
121 y: *mut c_double,
122 inc_y: c_int,
123 );
124
125 /// Copies vector `x` to vector `y`.
126 ///
127 /// # Precision
128 /// This function operates on double-precision (`f64`) numbers.
129 ///
130 /// # Parameters
131 /// - `n`: The number of elements in vectors `x` and `y`.
132 /// - `x`: A pointer to vector `x`.
133 /// - `inc_x`: The increment between elements in `x`.
134 /// - `y`: A pointer to vector `y`, which will store the result.
135 /// - `inc_y`: The increment between elements in `y`.
136 ///
137 /// # Safety
138 /// This is an `unsafe` C function. The caller must ensure that the memory regions for `x` and `y`
139 /// (up to `n * inc_x` and `n * inc_y` elements, respectively) are valid and within bounds.
140 #[link_name = "cblas_dcopy"]
141 pub fn copy(n: c_int, x: *const c_double, inc_x: c_int, y: *mut c_double, inc_y: c_int);
142
143 /// Finds the index of the element with the largest absolute value in the double-precision vector `x`.
144 ///
145 /// # Precision
146 /// This function operates on `f64` numbers.
147 ///
148 /// # Parameters
149 /// - `n`: The number of elements in the vector `x`.
150 /// - `x`: A pointer to the input vector of `f64` numbers.
151 /// - `inc_x`: The increment between elements in `x`.
152 ///
153 /// # Returns
154 /// - The index of the element with the largest absolute value.
155 ///
156 /// # Safety
157 /// This is an `unsafe` C function. The caller must ensure that the memory region accessed by `x`
158 /// (up to `n * inc_x`) is valid and within bounds.
159 #[link_name = "cblas_idamax"]
160 pub fn argmax_mod(n: c_int, x: *const c_double, inc_x: c_int) -> c_int;
161
162}