superlu_sys/
supermatrix.rs1use libc::{c_int, c_void};
2use std::slice;
3
4pub type int_t = c_int;
5
6#[derive(Clone, Copy, PartialEq)]
7#[repr(C)]
8pub enum Stype_t {
9 SLU_NC,
10 SLU_NCP,
11 SLU_NR,
12 SLU_SC,
13 SLU_SCP,
14 SLU_SR,
15 SLU_DN,
16 SLU_NR_loc,
17}
18
19#[derive(Clone, Copy, PartialEq)]
20#[repr(C)]
21pub enum Dtype_t {
22 SLU_S,
23 SLU_D,
24 SLU_C,
25 SLU_Z,
26}
27
28#[derive(Clone, Copy, PartialEq)]
29#[repr(C)]
30pub enum Mtype_t {
31 SLU_GE,
32 SLU_TRLU,
33 SLU_TRUU,
34 SLU_TRL,
35 SLU_TRU,
36 SLU_SYL,
37 SLU_SYU,
38 SLU_HEL,
39 SLU_HEU,
40}
41
42#[derive(Clone, Copy)]
43#[repr(C)]
44pub struct SuperMatrix {
45 pub Stype: Stype_t,
46 pub Dtype: Dtype_t,
47 pub Mtype: Mtype_t,
48 pub nrow: int_t,
49 pub ncol: int_t,
50 pub Store: *mut c_void,
51}
52
53impl SuperMatrix {
54 pub fn data_to_vec(&self) -> Option<Vec<f64>> {
55 match self.Stype {
56 Stype_t::SLU_DN => {}
57 _ => return None,
58 }
59
60 match self.Dtype {
61 Dtype_t::SLU_D => {}
62 _ => return None,
63 }
64
65 unsafe {
66 let store = self.Store as *const DNformat;
67 if store.is_null() {
68 return None;
69 }
70
71 let dn_format = &*store;
72 let nnz = (self.nrow * self.ncol) as usize;
73 match self.Dtype {
74 Dtype_t::SLU_D => {
75 let values = slice::from_raw_parts(dn_format.nzval as *const f64, nnz);
76 Some(values.to_vec())
77 }
78 _ => None,
79 }
80 }
81 }
82}
83
84#[derive(Clone, Copy)]
85#[repr(C)]
86pub struct NCformat {
87 pub nnz: int_t,
88 pub nzval: *mut c_void,
89 pub rowind: *mut int_t,
90 pub colptr: *mut int_t,
91}
92
93#[derive(Clone, Copy)]
94#[repr(C)]
95pub struct DNformat {
96 pub lda: int_t,
97 pub nzval: *mut c_void,
98}
99
100#[derive(Clone, Copy)]
101#[repr(C)]
102pub struct SCformat {
103 pub nnz: int_t,
104 pub nsuper: int_t,
105 pub nzval: *mut c_void,
106 pub nzval_colptr: *mut int_t,
107 pub rowind: *mut int_t,
108 pub rowind_colptr: *mut int_t,
109 pub col_to_sup: *mut int_t,
110 pub sup_to_col: *mut int_t,
111}