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