accelerate_general/vector_c32.rs
1use num_complex::Complex;
2use std::ffi::{c_float, c_int};
3
4#[link(name = "Accelerate", kind = "framework")]
5extern "C" {
6 /// Sets all elements in the single-precision complex vector `x` to the given complex value `alpha`.
7 ///
8 /// # Precision
9 /// This function operates on `Complex<f32>` complex numbers.
10 ///
11 /// # Parameters
12 /// - `n`: The number of elements in the vector `x`.
13 /// - `alpha`: A pointer to the complex value to set all elements of `x`.
14 /// - `x`: A pointer to the vector to be modified in-place.
15 /// - `inc_x`: The increment between elements in `x`.
16 ///
17 /// # Safety
18 /// This is an `unsafe` C function, and it is the caller's responsibility to ensure that
19 /// the memory region accessed by `x` (up to `n * inc_x`) is valid and within bounds.
20 #[link_name = "catlas_cset"]
21 pub fn set(n: c_int, alpha: *const Complex<c_float>, x: *mut Complex<c_float>, inc_x: c_int);
22
23 /// Computes the dot product of the complex conjugate of the first single-precision complex vector `X`
24 /// with the second single-precision complex vector `Y`.
25 ///
26 /// # Precision
27 /// This function operates on `Complex<f32>` numbers.
28 ///
29 /// # Parameters
30 /// - `n`: The number of elements in the vectors.
31 /// - `x`: A pointer to the first input vector of complex numbers (complex conjugate).
32 /// - `inc_x`: The increment between elements in `x`.
33 /// - `y`: A pointer to the second input vector of complex numbers.
34 /// - `inc_y`: The increment between elements in `y`.
35 /// - `dotc`: A pointer to store the result of the dot product (complex conjugate).
36 ///
37 /// # Safety
38 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` and `y`
39 /// (up to `n * inc_x` and `n * inc_y`) are valid and within bounds, and that the memory pointed to by `dotc` is valid.
40 #[link_name = "cblas_cdotc_sub"]
41 pub fn dot_conj_plus(
42 n: c_int,
43 x: *const Complex<c_float>,
44 inc_x: c_int,
45 y: *const Complex<c_float>,
46 inc_y: c_int,
47 dotc: *mut Complex<c_float>,
48 );
49
50 /// Computes the dot product of two single-precision complex vectors `X` and `Y`, without conjugating the first vector.
51 ///
52 /// # Precision
53 /// This function operates on `Complex<f32>` numbers.
54 ///
55 /// # Parameters
56 /// - `n`: The number of elements in the vectors `X` and `Y`.
57 /// - `x`: A pointer to the first input vector of `Complex<f32>` numbers.
58 /// - `inc_x`: The increment between elements in `x`.
59 /// - `y`: A pointer to the second input vector of `Complex<f32>` numbers.
60 /// - `inc_y`: The increment between elements in `y`.
61 /// - `dotu`: A pointer to store the result of the dot product (`Complex<f32>`).
62 ///
63 /// # Safety
64 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` and `y`
65 /// (up to `n * inc_x` and `n * inc_y`) are valid and within bounds, and that the memory pointed to by `dotu` is valid.
66 #[link_name = "cblas_cdotu_sub"]
67 pub fn dot_unconj_plus(
68 n: c_int,
69 x: *const Complex<c_float>,
70 inc_x: c_int,
71 y: *const Complex<c_float>,
72 inc_y: c_int,
73 dotu: *mut Complex<c_float>,
74 );
75
76 /// Computes a constant times a vector plus a vector (single-precision complex).
77 ///
78 /// `Y = alpha * X + Y`
79 ///
80 /// This function modifies the vector `Y` in-place.
81 ///
82 /// # Precision
83 /// This function operates on `f32` complex numbers.
84 ///
85 /// # Parameters
86 /// - `n`: The number of elements in the vectors `X` and `Y`.
87 /// - `alpha`: A pointer to the complex scalar that scales vector `X`.
88 /// - `x`: A pointer to the input vector `X` (of complex numbers).
89 /// - `inc_x`: The stride between elements in vector `X`.
90 /// - `y`: A pointer to the input/output vector `Y` (of complex numbers).
91 /// - `inc_y`: The stride between elements in vector `Y`.
92 ///
93 /// # Safety
94 /// This is an `unsafe` function. The caller must ensure that the memory regions pointed to by `x` and `y` are valid
95 /// and that accessing the data up to `n * inc_x` and `n * inc_y` is safe.
96 #[link_name = "cblas_caxpy"]
97 pub fn scaled_plus(
98 n: c_int, // Number of elements in vectors
99 alpha: *const Complex<c_float>, // Scaling factor for X (complex scalar)
100 x: *const Complex<c_float>, // Input vector X
101 inc_x: c_int, // Stride within X
102 y: *mut Complex<c_float>, // Input/output vector Y
103 inc_y: c_int, // Stride within Y
104 );
105
106 /// Copies a vector to another vector (single-precision complex).
107 ///
108 /// Copies the elements from the vector `X` to the vector `Y`.
109 ///
110 /// # Precision
111 /// This function operates on `f32` complex numbers.
112 ///
113 /// # Parameters
114 /// - `n`: The number of elements in the vectors `X` and `Y`.
115 /// - `x`: A pointer to the source vector `X` (complex numbers).
116 /// - `inc_x`: The stride between elements in vector `X`.
117 /// - `y`: A pointer to the destination vector `Y` (complex numbers).
118 /// - `inc_y`: The stride between elements in vector `Y`.
119 ///
120 /// # Safety
121 /// This is an `unsafe` function. The caller must ensure that the memory regions pointed to by `x` and `y` are valid
122 /// and that accessing the data up to `n * inc_x` and `n * inc_y` is safe.
123 #[link_name = "cblas_ccopy"]
124 pub fn copy(
125 n: c_int, // Number of elements in vectors
126 x: *const Complex<c_float>, // Source vector X
127 inc_x: c_int, // Stride within X
128 y: *mut Complex<c_float>, // Destination vector Y
129 inc_y: c_int, // Stride within Y
130 );
131
132 /// Multiplies each element of a complex vector by a constant scaling factor.
133 ///
134 /// # Precision
135 /// This function operates on single-precision complex numbers (`Complex<f32>`).
136 ///
137 /// # Parameters
138 /// - `n`: The number of elements in the vector `X`.
139 /// - `alpha`: A pointer to the constant scaling factor.
140 /// - `x`: A pointer to the input/output vector `X`. The result is stored in-place.
141 /// - `inc_x`: The stride between elements in `X`. For example, if `inc_x` is 7, every 7th element of `X` is used.
142 ///
143 /// # Safety
144 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` are valid and that the stride `inc_x` is correctly set.
145 ///
146 /// # Discussion
147 /// The function scales each element in the vector `X` by a constant value `alpha`, modifying `X` in place.
148 #[link_name = "cblas_cscal"]
149 pub fn scale_by_c32(
150 n: c_int,
151 alpha: *const Complex<c_float>,
152 x: *mut Complex<c_float>,
153 inc_x: c_int,
154 );
155
156 /// Multiplies each element of a complex vector `X` by a constant scalar `alpha`.
157 ///
158 /// # Precision
159 /// This function operates on single-precision complex numbers (`Complex<f32>`).
160 ///
161 /// # Parameters
162 /// - `n`: The number of elements in vector `X`.
163 /// - `alpha`: The constant scalar that scales each element of `X`.
164 /// - `x`: A pointer to the complex vector `X`, which is modified in place.
165 /// - `inc_x`: The increment (stride) between elements in `X`. For example, if `inc_x` is 7, every 7th element is used.
166 ///
167 /// # Safety
168 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `X` are valid.
169 ///
170 /// # Discussion
171 /// This function scales each element of the complex vector `X` by the constant `alpha`.
172 #[link_name = "cblas_csscal"]
173 pub fn scale_by_f32(n: c_int, alpha: c_float, x: *mut Complex<c_float>, inc_x: c_int);
174
175 /// Exchanges the elements of two complex vectors `X` and `Y`.
176 ///
177 /// # Precision
178 /// This function operates on single-precision complex numbers (`Complex<f32>`).
179 ///
180 /// # Parameters
181 /// - `n`: The number of elements in vectors `X` and `Y`.
182 /// - `x`: A pointer to the first complex vector `X`. On return, contains elements copied from vector `Y`.
183 /// - `inc_x`: The increment (stride) between elements in `X`. For example, if `inc_x` is 7, every 7th element is used.
184 /// - `y`: A pointer to the second complex vector `Y`. On return, contains elements copied from vector `X`.
185 /// - `inc_y`: The increment (stride) between elements in `Y`. For example, if `inc_y` is 7, every 7th element is used.
186 ///
187 /// # Safety
188 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `X` and `Y` are valid and within bounds.
189 ///
190 /// # Discussion
191 /// This function swaps the elements between two complex vectors `X` and `Y` in place.
192 #[link_name = "cblas_cswap"]
193 pub fn swap(
194 n: c_int,
195 x: *mut Complex<c_float>,
196 inc_x: c_int,
197 y: *mut Complex<c_float>,
198 inc_y: c_int,
199 );
200
201 /// Computes the sum of the absolute values of real and imaginary parts of elements in a vector (single-precision complex).
202 ///
203 /// # Precision
204 /// This function operates on single-precision complex numbers (`Complex<f32>`).
205 ///
206 /// # Parameters
207 /// - `n`: The number of elements in the vector `X`.
208 /// - `x`: A pointer to the source vector `X` (stored as single-precision complex numbers).
209 /// - `inc_x`: The stride between elements in `X`. For example, if `inc_x = 7`, every 7th element is used.
210 ///
211 /// # Return Value
212 /// Returns a single floating-point value containing the sum of the absolute values of both the real and imaginary parts of the vector.
213 ///
214 /// # Safety
215 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` are valid.
216 #[link_name = "cblas_scasum"]
217 pub fn norm1(
218 n: c_int, // Number of elements in the vector
219 x: *const Complex<c_float>, // Pointer to source vector X
220 inc_x: c_int, // Stride within vector X
221 ) -> c_float;
222
223 /// Computes the unitary norm (Euclidean norm or 2-norm) of a vector (single-precision complex).
224 ///
225 /// # Precision
226 /// This function operates on single-precision complex numbers (`Complex<f32>`).
227 ///
228 /// # Parameters
229 /// - `n`: The length of the vector `X`.
230 /// - `x`: A pointer to the vector `X` (stored as single-precision complex numbers).
231 /// - `inc_x`: The stride between elements in `X`. For example, if `inc_x = 7`, every 7th element is used.
232 ///
233 /// # Return Value
234 /// Returns the unitary norm (Euclidean norm) of the vector.
235 ///
236 /// # Safety
237 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` are valid.
238 #[link_name = "cblas_scnrm2"]
239 pub fn norm2(
240 n: c_int, // Length of vector X
241 x: *const Complex<c_float>, // Pointer to vector X
242 inc_x: c_int, // Stride within vector X
243 ) -> c_float;
244
245 /// Finds the index of the element with the largest absolute value in the single-precision complex vector `x`.
246 ///
247 /// # Precision
248 /// This function operates on `Complex<f32>` numbers.
249 ///
250 /// # Parameters
251 /// - `n`: The number of elements in the vector `x`.
252 /// - `x`: A pointer to the input vector of `Complex<f32>` numbers.
253 /// - `inc_x`: The increment between elements in `x`.
254 ///
255 /// # Returns
256 /// - The index of the element with the largest absolute value.
257 ///
258 /// # Safety
259 /// This is an `unsafe` C function. The caller must ensure that the memory region accessed by `x`
260 /// (up to `n * inc_x`) is valid and within bounds.
261 #[link_name = "cblas_icamax"]
262 pub fn argmax_mod(n: c_int, x: *const Complex<c_float>, inc_x: c_int) -> c_int;
263
264 /// Computes the linear combination of two single-precision complex vectors `x` and `y` as:
265 /// `y = alpha * x + beta * y`.
266 /// This modifies the `y` vector in-place.
267 ///
268 /// # Precision
269 /// This function operates on `Complex<f32>` complex numbers.
270 ///
271 /// # Parameters
272 /// - `n`: The number of elements in the vectors `x` and `y`.
273 /// - `alpha`: A pointer to the scalar that scales the `x` vector.
274 /// - `x`: A pointer to the first input vector of complex numbers.
275 /// - `inc_x`: The increment between elements in `x`.
276 /// - `beta`: A pointer to the scalar that scales the `y` vector.
277 /// - `y`: A pointer to the second input vector, which stores the result in-place.
278 /// - `inc_y`: The increment between elements in `y`.
279 ///
280 /// # Safety
281 /// This is an `unsafe` C function, and it is the caller's responsibility to ensure that
282 /// the memory regions accessed by `x` and `y` (up to `n * inc_x` and `n * inc_y` respectively)
283 /// are valid and within bounds.
284 #[link_name = "catlas_caxpby"]
285 pub fn lin_comb_c32_catlas(
286 n: c_int,
287 alpha: *const Complex<c_float>,
288 x: *const Complex<c_float>,
289 inc_x: c_int,
290 beta: *const Complex<c_float>,
291 y: *mut Complex<c_float>,
292 inc_y: c_int,
293 );
294
295}