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
#[cfg(target_os = "windows")]
pub type SuiteSparseLong = libc::c_longlong;
#[cfg(not(target_os = "windows"))]
pub type SuiteSparseLong = libc::c_long;
pub type SuiteSparseInt = libc::c_int;
extern "C" {
pub fn camd_order(
n: SuiteSparseInt,
ap: *const SuiteSparseInt,
ai: *const SuiteSparseInt,
p: *mut SuiteSparseInt,
control: *mut libc::c_double,
info: *mut libc::c_double,
constraint: *mut SuiteSparseInt,
) -> SuiteSparseInt;
pub fn camd_l_order(
n: SuiteSparseLong,
ap: *const SuiteSparseLong,
ai: *const SuiteSparseLong,
p: *mut SuiteSparseLong,
control: *mut libc::c_double,
info: *mut libc::c_double,
constraint: *mut SuiteSparseLong,
) -> SuiteSparseLong;
pub fn camd_valid(
n_rows: SuiteSparseInt,
n_cols: SuiteSparseInt,
ap: *const SuiteSparseInt,
ai: *const SuiteSparseInt,
) -> SuiteSparseInt;
pub fn camd_l_valid(
n_rows: SuiteSparseLong,
n_cols: SuiteSparseLong,
ap: *const SuiteSparseLong,
ai: *const SuiteSparseLong,
) -> SuiteSparseLong;
pub fn camd_cvalid(n: SuiteSparseInt, constraint: *const SuiteSparseInt);
pub fn camd_l_cvalid(
n: SuiteSparseLong,
constraint: *const SuiteSparseLong,
);
pub fn camd_defaults(control: *mut libc::c_double);
pub fn camd_l_defaults(control: *mut libc::c_double);
pub fn camd_control(control: *const libc::c_double);
pub fn camd_l_control(control: *const libc::c_double);
pub fn camd_info(info: *const libc::c_double);
pub fn camd_l_info(info: *const libc::c_double);
}
pub const CAMD_CONTROL: usize = 5;
pub const CAMD_INFO: usize = 20;
pub const CAMD_DENSE: usize = 0;
pub const CAMD_AGGRESSIVE: usize = 1;
pub const CAMD_STATUS: usize = 0;
pub const CAMD_N: usize = 1;
pub const CAMD_NZ: usize = 2;
pub const CAMD_SYMMETRY: usize = 3;
pub const CAMD_NZDIAG: usize = 4;
pub const CAMD_NZ_A_PLUS_AT: usize = 5;
pub const CAMD_NDENSE: usize = 6;
pub const CAMD_MEMORY: usize = 7;
pub const CAMD_NCMPA: usize = 8;
pub const CAMD_LNZ: usize = 9;
pub const CAMD_NDIV: usize = 10;
pub const CAMD_NMULTSUBS_LDL: usize = 11;
pub const CAMD_NMULTSUBS_LU: usize = 12;
pub const CAMD_DMAX: usize = 13;
pub const CAMD_OK: isize = 0;
pub const CAMD_OUT_OF_MEMORY: isize = -1;
pub const CAMD_INVALID: isize = -2;
pub const CAMD_OK_BUT_JUMBLED: isize = 1;
#[cfg(test)]
mod tests {
use super::SuiteSparseInt;
#[test]
fn camd_valid() {
let n: SuiteSparseInt = 3;
let ap = &[0, 2, 4, 5];
let ai = &[1, 2, 0, 1, 0];
let valid =
unsafe { super::camd_valid(n, n, ap.as_ptr(), ai.as_ptr()) };
assert_eq!(valid, super::CAMD_OK as SuiteSparseInt);
let ai = &[2, 1, 0, 1, 0];
let valid =
unsafe { super::camd_valid(n, n, ap.as_ptr(), ai.as_ptr()) };
assert_eq!(valid, super::CAMD_OK_BUT_JUMBLED as SuiteSparseInt);
let ai = &[1, 2, 0, 1, 1];
let valid =
unsafe { super::camd_valid(n, n, ap.as_ptr(), ai.as_ptr()) };
assert_eq!(valid, super::CAMD_OK as SuiteSparseInt);
let valid =
unsafe { super::camd_valid(n, n + 1, ap.as_ptr(), ai.as_ptr()) };
assert_eq!(valid, super::CAMD_INVALID as SuiteSparseInt);
let valid = unsafe {
super::camd_valid(n + 1, n + 1, ap.as_ptr(), ai.as_ptr())
};
assert_eq!(valid, super::CAMD_INVALID as SuiteSparseInt);
use super::SuiteSparseLong as Long;
let n: Long = 3;
let ap: &[Long] = &[0, 2, 4, 5];
let ai: &[Long] = &[1, 2, 0, 1, 0];
let valid =
unsafe { super::camd_l_valid(n, n, ap.as_ptr(), ai.as_ptr()) };
assert_eq!(valid, super::CAMD_OK as Long);
}
#[test]
fn camd_order() {
let n: SuiteSparseInt = 3;
let ap = &[0, 2, 4, 5];
let ai = &[1, 2, 0, 1, 0];
let mut perm = [0; 3];
let mut control = [0.; super::CAMD_CONTROL];
let mut info = [0.; super::CAMD_INFO];
let constraint: *const SuiteSparseInt = std::ptr::null();
unsafe {
super::camd_defaults(control.as_mut_ptr());
}
let res = unsafe {
super::camd_order(
n,
ap.as_ptr(),
ai.as_ptr(),
perm.as_mut_ptr(),
control.as_mut_ptr(),
info.as_mut_ptr(),
constraint as *mut SuiteSparseInt,
)
};
assert_eq!(res, super::CAMD_OK as SuiteSparseInt);
}
}