accelerate_general/
vector_f32.rs

1use std::ffi::{c_double, c_float, c_int};
2
3#[link(name = "Accelerate", kind = "framework")]
4extern "C" {
5    /// Computes the linear combination of two single-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 `f32` 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 `f32` 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_saxpby"]
26    pub fn lin_comb_catlas(
27        n: c_int,
28        alpha: c_float,
29        x: *const c_float,
30        inc_x: c_int,
31        beta: c_float,
32        y: *mut c_float,
33        inc_y: c_int,
34    );
35
36    /// Sets all elements in the single-precision vector `x` to the given value `alpha`.
37    ///
38    /// # Precision
39    /// This function operates on `f32` 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_sset"]
51    pub fn set(n: c_int, alpha: c_float, x: *mut c_float, inc_x: c_int);
52
53    /// Computes the dot product of two single-precision vectors.
54    ///
55    /// # Precision
56    /// This function operates on `f32` 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 `f32` numbers.
61    /// - `inc_x`: The increment between elements in `x`.
62    /// - `y`: A pointer to the second input vector of `f32` numbers.
63    /// - `inc_y`: The increment between elements in `y`.
64    ///
65    /// # Returns
66    /// - The dot product of `x` and `y`.
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_sdot"]
72    pub fn dot(
73        n: c_int,
74        x: *const c_float,
75        inc_x: c_int,
76        y: *const c_float,
77        inc_y: c_int,
78    ) -> c_float;
79
80    /// Computes the dot product of two single-precision vectors, with an added scalar.
81    ///
82    /// # Precision
83    /// This function operates on `f32` numbers.
84    ///
85    /// # Parameters
86    /// - `n`: The number of elements in the vectors `x` and `y`.
87    /// - `sb`: A scalar value to be added to the result of the dot product.
88    /// - `x`: A pointer to the first input vector of `f32` numbers.
89    /// - `inc_x`: The increment between elements in `x`.
90    /// - `y`: A pointer to the second input vector of `f32` numbers.
91    /// - `inc_y`: The increment between elements in `y`.
92    ///
93    /// # Returns
94    /// - The scalar `sb` added to the dot product of `x` and `y`.
95    ///
96    /// # Safety
97    /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` and `y`
98    /// (up to `n * inc_x` and `n * inc_y`) are valid and within bounds.
99    #[link_name = "cblas_sdsdot"]
100    pub fn dot_plus(
101        n: c_int,
102        sb: c_float,
103        x: *const c_float,
104        inc_x: c_int,
105        y: *const c_float,
106        inc_y: c_int,
107    ) -> c_float;
108
109    /// Computes the dot product of two single-precision vectors `X` and `Y`, and returns the result as a double-precision number.
110    ///
111    /// # Precision
112    /// This function operates on `f32` (single-precision) vectors and returns an `f64` (double-precision) result.
113    ///
114    /// # Parameters
115    /// - `n`: The number of elements in the vectors `X` and `Y`.
116    /// - `x`: A pointer to the first input vector of `f32` numbers.
117    /// - `inc_x`: The increment (stride) between elements in `x`. For example, if `inc_x = 7`, every 7th element is used.
118    /// - `y`: A pointer to the second input vector of `f32` numbers.
119    /// - `inc_y`: The increment (stride) between elements in `y`.
120    ///
121    /// # Returns
122    /// - The dot product of `x` and `y` as a `f64`.
123    ///
124    /// # Safety
125    /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` and `y`
126    /// (up to `n * inc_x` and `n * inc_y`) are valid and within bounds.
127    #[link_name = "cblas_dsdot"]
128    pub fn dot_as_f64(
129        n: c_int,
130        x: *const c_float,
131        inc_x: c_int,
132        y: *const c_float,
133        inc_y: c_int,
134    ) -> c_double;
135
136    /// Computes the sum of the absolute values of the elements in the single-precision vector `x`.
137    ///
138    /// # Precision
139    /// This function operates on `f32` numbers.
140    ///
141    /// # Parameters
142    /// - `n`: The number of elements in the vector `x`.
143    /// - `x`: A pointer to the input vector of `f32` numbers.
144    /// - `inc_x`: The increment between elements in `x`.
145    ///
146    /// # Returns
147    /// - The sum of the absolute values of the elements in `x`.
148    ///
149    /// # Safety
150    /// This is an `unsafe` C function. The caller must ensure that the memory region accessed by `x`
151    /// (up to `n * inc_x`) is valid and within bounds.
152    #[link_name = "cblas_sasum"]
153    pub fn norm1(n: c_int, x: *const c_float, inc_x: c_int) -> c_float;
154
155    /// Performs the operation y = alpha * x + y for single-precision vectors.
156    ///
157    /// # Precision
158    /// This function operates on `f32` complex numbers.
159    ///
160    /// # Parameters
161    /// - `n`: The number of elements in the vectors.
162    /// - `alpha`: The scalar that scales the vector `x`.
163    /// - `x`: A pointer to the input vector `x`.
164    /// - `inc_x`: The increment between elements in `x`.
165    /// - `y`: A pointer to the input/output vector `y`, which stores the result in-place.
166    /// - `inc_y`: The increment between elements in `y`.
167    ///
168    /// # Safety
169    /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` and `y` are valid and within bounds.
170    #[link_name = "cblas_saxpy"]
171    pub fn scale_plus(
172        n: c_int,
173        alpha: c_float,
174        x: *const c_float,
175        inc_x: c_int,
176        y: *mut c_float,
177        inc_y: c_int,
178    );
179
180    /// Multiplies each element of a vector by a constant.
181    ///
182    /// This function performs the operation `x[i] = alpha * x[i]` for each element in the vector `x`.
183    ///
184    /// # Precision
185    /// This function operates on single-precision (`f32`) numbers.
186    ///
187    /// # Parameters
188    /// - `n`: The number of elements in the vector `x`.
189    /// - `alpha`: The constant to multiply each element of `x` by.
190    /// - `x`: A pointer to the vector `x`. The result is stored in-place.
191    /// - `inc_x`: Stride within `x`. For example, if `inc_x` is 7, every 7th element is scaled by `alpha`.
192    ///
193    /// # Safety
194    /// This is an `unsafe` C function. The caller must ensure that the pointer passed to `x` is valid and that accessing `x` up to `n * inc_x` is safe.
195    #[link_name = "cblas_sscal"]
196    pub fn scale(n: c_int, alpha: c_float, x: *mut c_float, inc_x: c_int);
197
198    /// Exchanges the elements of two single-precision vectors `x` and `y`.
199    ///
200    /// # Precision
201    /// This function operates on single-precision (`f32`) numbers.
202    ///
203    /// # Parameters
204    /// - `n`: The number of elements in vectors `x` and `y`.
205    /// - `x`: A pointer to the first vector `x`. On return, contains elements copied from vector `y`.
206    /// - `inc_x`: The increment between elements in vector `x`.
207    /// - `y`: A pointer to the second vector `y`. On return, contains elements copied from vector `x`.
208    /// - `inc_y`: The increment between elements in vector `y`.
209    ///
210    /// # Safety
211    /// This is an `unsafe` C function. The caller must ensure that the pointers passed to `x` and `y` are valid, and that accessing `x` and `y` up to `n * inc_x` and `n * inc_y` is safe.
212    #[link_name = "cblas_sswap"]
213    pub fn swap(n: c_int, x: *mut f32, inc_x: c_int, y: *mut f32, inc_y: c_int);
214
215    /// Computes the L2 norm (Euclidean length) of a single-precision vector `x`.
216    ///
217    /// # Precision
218    /// This function operates on `f32` numbers (single-precision).
219    ///
220    /// # Parameters
221    /// - `n`: Length of vector `x`.
222    /// - `x`: A pointer to the vector `x`.
223    /// - `inc_x`: The increment (stride) between elements in `x`. For example, if `inc_x = 7`, every 7th element is used.
224    ///
225    /// # Returns
226    /// - The L2 norm (Euclidean length) of vector `x`.
227    ///
228    /// # Safety
229    /// This is an `unsafe` C function. The caller must ensure that the memory region accessed by `x` (up to `n * inc_x`) is valid and within bounds.
230    #[link_name = "cblas_snrm2"]
231    pub fn norm2(n: c_int, x: *const c_float, inc_x: c_int) -> c_float;
232
233    /// Copies the contents of vector `x` into vector `y` for single-precision vectors.
234    ///
235    /// # Precision
236    /// This function operates on `f32` complex numbers.
237    ///
238    /// # Parameters
239    /// - `n`: The number of elements in the vectors.
240    /// - `x`: A pointer to the input vector `x`.
241    /// - `inc_x`: The increment between elements in `x`.
242    /// - `y`: A pointer to the output vector `y`.
243    /// - `inc_y`: The increment between elements in `y`.
244    ///
245    /// # Safety
246    /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` and `y` are valid and within bounds.
247    #[link_name = "cblas_scopy"]
248    pub fn copy(n: c_int, x: *const c_float, inc_x: c_int, y: *mut c_float, inc_y: c_int);
249
250    /// Finds the index of the element with the largest absolute value in the single-precision vector `x`.
251    ///
252    /// # Precision
253    /// This function operates on `f32` numbers.
254    ///
255    /// # Parameters
256    /// - `n`: The number of elements in the vector `x`.
257    /// - `x`: A pointer to the input vector of `f32` numbers.
258    /// - `inc_x`: The increment between elements in `x`.
259    ///
260    /// # Returns
261    /// - The index of the element with the largest absolute value.
262    ///
263    /// # Safety
264    /// This is an `unsafe` C function. The caller must ensure that the memory region accessed by `x`
265    /// (up to `n * inc_x`) is valid and within bounds.
266    #[link_name = "cblas_isamax"]
267    pub fn argmax_mod(n: c_int, x: *const c_float, inc_x: c_int) -> c_int;
268}