-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathalgebra.rs
More file actions
62 lines (58 loc) · 1.53 KB
/
algebra.rs
File metadata and controls
62 lines (58 loc) · 1.53 KB
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
use clarabel::algebra::FloatT;
#[repr(C)]
// This struct is for interfacing with C only and should be synched with clarabel::algebra::CscMatrix
pub struct ClarabelCscMatrix<T = f64> {
/// number of rows
pub m: usize,
/// number of columns
pub n: usize,
/// CSC format column pointer.
///
/// This field should have length `n+1`. The last entry corresponds
/// to the the number of nonzeros and should agree with the lengths
/// of the `rowval` and `nzval` fields.
pub colptr: *const usize,
/// vector of row indices
pub rowval: *const usize,
/// vector of non-zero matrix elements
pub nzval: *const T,
}
#[allow(non_snake_case)]
unsafe fn _internal_Cscmatrix_init<T: FloatT>(
ptr: *mut ClarabelCscMatrix<T>,
m: usize,
n: usize,
colptr: *const usize,
rowval: *const usize,
nzval: *const T,
) {
*ptr = ClarabelCscMatrix::<T> {
m,
n,
colptr,
rowval,
nzval,
};
}
#[no_mangle]
pub unsafe extern "C" fn clarabel_CscMatrix_f32_init(
ptr: *mut ClarabelCscMatrix<f32>,
m: usize,
n: usize,
colptr: *const usize,
rowval: *const usize,
nzval: *const f32,
) {
_internal_Cscmatrix_init::<f32>(ptr, m, n, colptr, rowval, nzval);
}
#[no_mangle]
pub unsafe extern "C" fn clarabel_CscMatrix_f64_init(
ptr: *mut ClarabelCscMatrix<f64>,
m: usize,
n: usize,
colptr: *const usize,
rowval: *const usize,
nzval: *const f64,
) {
_internal_Cscmatrix_init::<f64>(ptr, m, n, colptr, rowval, nzval);
}