accelerate_general/vector_c64.rs
1use num_complex::Complex;
2use std::ffi::{c_double, c_int};
3
4#[link(name = "Accelerate", kind = "framework")]
5extern "C" {
6 /// Computes the linear combination of two double-precision complex vectors `x` and `y` as:
7 /// `y = alpha * x + beta * y`.
8 /// This modifies the `y` vector in-place.
9 ///
10 /// # Precision
11 /// This function operates on `Complex<f64>` complex numbers.
12 ///
13 /// # Parameters
14 /// - `n`: The number of elements in the vectors `x` and `y`.
15 /// - `alpha`: A pointer to the scalar that scales the `x` vector.
16 /// - `x`: A pointer to the first input vector of complex numbers.
17 /// - `inc_x`: The increment between elements in `x`.
18 /// - `beta`: A pointer to the scalar that scales the `y` vector.
19 /// - `y`: A pointer to the second input vector, which stores the result in-place.
20 /// - `inc_y`: The increment between elements in `y`.
21 ///
22 /// # Safety
23 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by
24 /// `x` and `y` (up to `n * inc_x` and `n * inc_y` respectively) are valid and within bounds.
25 #[link_name = "catlas_zaxpby"]
26 pub fn lin_comb_catlas(
27 n: c_int,
28 alpha: *const Complex<c_double>,
29 x: *const Complex<c_double>,
30 inc_x: c_int,
31 beta: *const Complex<c_double>,
32 y: *mut Complex<c_double>,
33 inc_y: c_int,
34 );
35
36 /// Sets all elements in the double-precision complex vector `x` to the given complex value `alpha`.
37 ///
38 /// # Precision
39 /// This function operates on `Complex<f64>` complex numbers.
40 ///
41 /// # Parameters
42 /// - `n`: The number of elements in the vector `x`.
43 /// - `alpha`: A pointer to the complex 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. The caller must ensure that the memory region accessed by `x`
49 /// (up to `n * inc_x`) is valid and within bounds.
50 #[link_name = "catlas_zset"]
51 pub fn set(n: c_int, alpha: *const Complex<c_double>, x: *mut Complex<c_double>, inc_x: c_int);
52
53 /// Computes the dot product of the complex conjugate of the first double-precision complex vector `X`
54 /// with the second double-precision complex vector `Y`, and stores the result in `DOTC`.
55 ///
56 /// # Precision
57 /// This function operates on `Complex<f64>` numbers (double-precision complex numbers).
58 ///
59 /// # Parameters
60 /// - `n`: The number of elements in the vectors `X` and `Y`.
61 /// - `x`: A pointer to the first input vector of `Complex<f64>` numbers. The elements of `x` are conjugated before the dot product.
62 /// - `inc_x`: The increment (stride) between elements in `x`. For example, if `inc_x = 7`, every 7th element is used.
63 /// - `y`: A pointer to the second input vector of `Complex<f64>` numbers.
64 /// - `inc_y`: The increment (stride) between elements in `y`.
65 /// - `dotc`: A pointer to store the result of the conjugated dot product (`Complex<f64>`).
66 ///
67 /// # Safety
68 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` and `y`
69 /// (up to `n * inc_x` and `n * inc_y`) are valid and within bounds, and that the memory pointed to by `dotc` is valid.
70 #[link_name = "cblas_zdotc_sub"]
71 pub fn dot_conj(
72 n: c_int,
73 x: *const Complex<c_double>,
74 inc_x: c_int,
75 y: *const Complex<c_double>,
76 inc_y: c_int,
77 dotc: *mut Complex<c_double>,
78 );
79
80 /// Computes the dot product of two double-precision complex vectors `X` and `Y`, and stores the result in `DOTU`.
81 ///
82 /// # Precision
83 /// This function operates on `Complex<f64>` numbers (double-precision complex numbers).
84 ///
85 /// # Parameters
86 /// - `n`: The number of elements in the vectors `X` and `Y`.
87 /// - `x`: A pointer to the first input vector of `Complex<f64>` numbers.
88 /// - `inc_x`: The increment (stride) between elements in `x`. For example, if `inc_x = 7`, every 7th element is used.
89 /// - `y`: A pointer to the second input vector of `Complex<f64>` numbers.
90 /// - `inc_y`: The increment (stride) between elements in `y`.
91 /// - `dotu`: A pointer to store the result of the dot product (`Complex<f64>`).
92 ///
93 /// # Safety
94 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` and `y`
95 /// (up to `n * inc_x` and `n * inc_y`) are valid and within bounds, and that the memory pointed to by `dotu` is valid.
96 #[link_name = "cblas_zdotu_sub"]
97 pub fn dot_unconj(
98 n: c_int,
99 x: *const Complex<c_double>,
100 inc_x: c_int,
101 y: *const Complex<c_double>,
102 inc_y: c_int,
103 dotu: *mut Complex<c_double>,
104 );
105
106 /// Computes the sum of the absolute values of real and imaginary parts of elements in a vector (single-precision complex).
107 ///
108 /// # Precision
109 /// This function operates on single-precision complex numbers (`Complex<f64>`).
110 ///
111 /// # Parameters
112 /// - `n`: The number of elements in the vector `X`.
113 /// - `x`: A pointer to the source vector `X` (stored as single-precision complex numbers).
114 /// - `inc_x`: The stride between elements in `X`. For example, if `inc_x = 7`, every 7th element is used.
115 ///
116 /// # Return Value
117 /// Returns a single floating-point value containing the sum of the absolute values of both the real and imaginary parts of the vector.
118 ///
119 /// # Safety
120 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` are valid.
121 #[link_name = "cblas_dzasum"]
122 pub fn norm1(
123 n: c_int, // Number of elements in the vector
124 x: *const Complex<c_double>, // Pointer to source vector X
125 inc_x: c_int, // Stride within vector X
126 ) -> c_double;
127
128 /// Computes the unitary norm (Euclidean norm or 2-norm) of a vector (single-precision complex).
129 ///
130 /// # Precision
131 /// This function operates on single-precision complex numbers (`Complex<f64>`).
132 ///
133 /// # Parameters
134 /// - `n`: The length of the vector `X`.
135 /// - `x`: A pointer to the vector `X` (stored as single-precision complex numbers).
136 /// - `inc_x`: The stride between elements in `X`. For example, if `inc_x = 7`, every 7th element is used.
137 ///
138 /// # Return Value
139 /// Returns the unitary norm (Euclidean norm) of the vector.
140 ///
141 /// # Safety
142 /// This is an `unsafe` C function. The caller must ensure that the memory regions accessed by `x` are valid.
143 #[link_name = "cblas_dznrm2"]
144 pub fn norm2(
145 n: c_int, // Length of vector X
146 x: *const Complex<c_double>, // Pointer to vector X
147 inc_x: c_int, // Stride within vector X
148 ) -> c_double;
149
150 /// Finds the index of the element with the largest absolute value in the double-precision complex vector `x`.
151 ///
152 /// # Precision
153 /// This function operates on `Complex<f64>` numbers.
154 ///
155 /// # Parameters
156 /// - `n`: The number of elements in the vector `x`.
157 /// - `x`: A pointer to the input vector of `Complex<f64>` numbers.
158 /// - `inc_x`: The increment between elements in `x`.
159 ///
160 /// # Returns
161 /// - The index of the element with the largest absolute value.
162 ///
163 /// # Safety
164 /// This is an `unsafe` C function. The caller must ensure that the memory region accessed by `x`
165 /// (up to `n * inc_x`) is valid and within bounds.
166 #[link_name = "cblas_izamax"]
167 pub fn argmax_mod(n: c_int, x: *const Complex<c_double>, inc_x: c_int) -> c_int;
168}