pub struct SparseMatrixF32 { /* private fields */ }Expand description
Owned sparse single-precision matrix handle backed by the Swift bridge.
Implementations§
Source§impl SparseMatrixF32
impl SparseMatrixF32
Sourcepub fn new(rows: usize, columns: usize) -> Option<Self>
pub fn new(rows: usize, columns: usize) -> Option<Self>
Examples found in repository?
examples/07_sparse_linear_algebra.rs (line 24)
6fn main() {
7 let values = [2.0_f32, 4.0];
8 let indices = [0_i64, 2_i64];
9 let dense = [1.0_f32, 2.0, 3.0];
10 let dot = sparse_dot_dense_f32(&values, &indices, &dense).expect("dense dot");
11 assert!((dot - 14.0).abs() < 1.0e-6);
12
13 let sparse_dot = sparse_dot_sparse_f32(&values, &indices, &[3.0_f32, 5.0], &[0_i64, 2_i64])
14 .expect("sparse dot");
15 assert!((sparse_dot - 26.0).abs() < 1.0e-6);
16
17 let mut accum = vec![10.0_f32, 10.0, 10.0];
18 sparse_add_to_dense_f32(&values, &indices, 0.5, &mut accum).expect("accumulate");
19 assert!(accum
20 .iter()
21 .zip([11.0_f32, 10.0, 12.0])
22 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
23
24 let mut matrix = SparseMatrixF32::new(2, 2).expect("matrix");
25 matrix
26 .set_property(sparse_matrix_property::LOWER_TRIANGULAR)
27 .expect("property");
28 matrix.insert_entry(0, 0, 2.0).expect("a00");
29 matrix.insert_entry(1, 0, 1.0).expect("a10");
30 matrix.insert_entry(1, 1, 3.0).expect("a11");
31 matrix.commit().expect("commit");
32
33 let mut rhs = [2.0_f32, 7.0];
34 matrix
35 .triangular_solve_vector(blas_transpose::NO_TRANS, 1.0, &mut rhs)
36 .expect("solve vector");
37 assert!(rhs
38 .iter()
39 .zip([1.0_f32, 2.0])
40 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
41
42 println!("sparse smoke passed: dot={dot} accum={accum:?} solve={rhs:?}");
43}Sourcepub fn set_property(&mut self, property: i32) -> Result<()>
pub fn set_property(&mut self, property: i32) -> Result<()>
Examples found in repository?
examples/07_sparse_linear_algebra.rs (line 26)
6fn main() {
7 let values = [2.0_f32, 4.0];
8 let indices = [0_i64, 2_i64];
9 let dense = [1.0_f32, 2.0, 3.0];
10 let dot = sparse_dot_dense_f32(&values, &indices, &dense).expect("dense dot");
11 assert!((dot - 14.0).abs() < 1.0e-6);
12
13 let sparse_dot = sparse_dot_sparse_f32(&values, &indices, &[3.0_f32, 5.0], &[0_i64, 2_i64])
14 .expect("sparse dot");
15 assert!((sparse_dot - 26.0).abs() < 1.0e-6);
16
17 let mut accum = vec![10.0_f32, 10.0, 10.0];
18 sparse_add_to_dense_f32(&values, &indices, 0.5, &mut accum).expect("accumulate");
19 assert!(accum
20 .iter()
21 .zip([11.0_f32, 10.0, 12.0])
22 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
23
24 let mut matrix = SparseMatrixF32::new(2, 2).expect("matrix");
25 matrix
26 .set_property(sparse_matrix_property::LOWER_TRIANGULAR)
27 .expect("property");
28 matrix.insert_entry(0, 0, 2.0).expect("a00");
29 matrix.insert_entry(1, 0, 1.0).expect("a10");
30 matrix.insert_entry(1, 1, 3.0).expect("a11");
31 matrix.commit().expect("commit");
32
33 let mut rhs = [2.0_f32, 7.0];
34 matrix
35 .triangular_solve_vector(blas_transpose::NO_TRANS, 1.0, &mut rhs)
36 .expect("solve vector");
37 assert!(rhs
38 .iter()
39 .zip([1.0_f32, 2.0])
40 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
41
42 println!("sparse smoke passed: dot={dot} accum={accum:?} solve={rhs:?}");
43}Sourcepub fn insert_entry(
&mut self,
row: usize,
column: usize,
value: f32,
) -> Result<()>
pub fn insert_entry( &mut self, row: usize, column: usize, value: f32, ) -> Result<()>
Examples found in repository?
examples/07_sparse_linear_algebra.rs (line 28)
6fn main() {
7 let values = [2.0_f32, 4.0];
8 let indices = [0_i64, 2_i64];
9 let dense = [1.0_f32, 2.0, 3.0];
10 let dot = sparse_dot_dense_f32(&values, &indices, &dense).expect("dense dot");
11 assert!((dot - 14.0).abs() < 1.0e-6);
12
13 let sparse_dot = sparse_dot_sparse_f32(&values, &indices, &[3.0_f32, 5.0], &[0_i64, 2_i64])
14 .expect("sparse dot");
15 assert!((sparse_dot - 26.0).abs() < 1.0e-6);
16
17 let mut accum = vec![10.0_f32, 10.0, 10.0];
18 sparse_add_to_dense_f32(&values, &indices, 0.5, &mut accum).expect("accumulate");
19 assert!(accum
20 .iter()
21 .zip([11.0_f32, 10.0, 12.0])
22 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
23
24 let mut matrix = SparseMatrixF32::new(2, 2).expect("matrix");
25 matrix
26 .set_property(sparse_matrix_property::LOWER_TRIANGULAR)
27 .expect("property");
28 matrix.insert_entry(0, 0, 2.0).expect("a00");
29 matrix.insert_entry(1, 0, 1.0).expect("a10");
30 matrix.insert_entry(1, 1, 3.0).expect("a11");
31 matrix.commit().expect("commit");
32
33 let mut rhs = [2.0_f32, 7.0];
34 matrix
35 .triangular_solve_vector(blas_transpose::NO_TRANS, 1.0, &mut rhs)
36 .expect("solve vector");
37 assert!(rhs
38 .iter()
39 .zip([1.0_f32, 2.0])
40 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
41
42 println!("sparse smoke passed: dot={dot} accum={accum:?} solve={rhs:?}");
43}Sourcepub fn commit(&mut self) -> Result<()>
pub fn commit(&mut self) -> Result<()>
Examples found in repository?
examples/07_sparse_linear_algebra.rs (line 31)
6fn main() {
7 let values = [2.0_f32, 4.0];
8 let indices = [0_i64, 2_i64];
9 let dense = [1.0_f32, 2.0, 3.0];
10 let dot = sparse_dot_dense_f32(&values, &indices, &dense).expect("dense dot");
11 assert!((dot - 14.0).abs() < 1.0e-6);
12
13 let sparse_dot = sparse_dot_sparse_f32(&values, &indices, &[3.0_f32, 5.0], &[0_i64, 2_i64])
14 .expect("sparse dot");
15 assert!((sparse_dot - 26.0).abs() < 1.0e-6);
16
17 let mut accum = vec![10.0_f32, 10.0, 10.0];
18 sparse_add_to_dense_f32(&values, &indices, 0.5, &mut accum).expect("accumulate");
19 assert!(accum
20 .iter()
21 .zip([11.0_f32, 10.0, 12.0])
22 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
23
24 let mut matrix = SparseMatrixF32::new(2, 2).expect("matrix");
25 matrix
26 .set_property(sparse_matrix_property::LOWER_TRIANGULAR)
27 .expect("property");
28 matrix.insert_entry(0, 0, 2.0).expect("a00");
29 matrix.insert_entry(1, 0, 1.0).expect("a10");
30 matrix.insert_entry(1, 1, 3.0).expect("a11");
31 matrix.commit().expect("commit");
32
33 let mut rhs = [2.0_f32, 7.0];
34 matrix
35 .triangular_solve_vector(blas_transpose::NO_TRANS, 1.0, &mut rhs)
36 .expect("solve vector");
37 assert!(rhs
38 .iter()
39 .zip([1.0_f32, 2.0])
40 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
41
42 println!("sparse smoke passed: dot={dot} accum={accum:?} solve={rhs:?}");
43}pub fn rows(&self) -> Result<usize>
pub fn columns(&self) -> Result<usize>
pub fn nonzero_count(&self) -> Result<usize>
Sourcepub fn triangular_solve_vector(
&self,
transpose: i32,
alpha: f32,
values: &mut [f32],
) -> Result<()>
pub fn triangular_solve_vector( &self, transpose: i32, alpha: f32, values: &mut [f32], ) -> Result<()>
Examples found in repository?
examples/07_sparse_linear_algebra.rs (line 35)
6fn main() {
7 let values = [2.0_f32, 4.0];
8 let indices = [0_i64, 2_i64];
9 let dense = [1.0_f32, 2.0, 3.0];
10 let dot = sparse_dot_dense_f32(&values, &indices, &dense).expect("dense dot");
11 assert!((dot - 14.0).abs() < 1.0e-6);
12
13 let sparse_dot = sparse_dot_sparse_f32(&values, &indices, &[3.0_f32, 5.0], &[0_i64, 2_i64])
14 .expect("sparse dot");
15 assert!((sparse_dot - 26.0).abs() < 1.0e-6);
16
17 let mut accum = vec![10.0_f32, 10.0, 10.0];
18 sparse_add_to_dense_f32(&values, &indices, 0.5, &mut accum).expect("accumulate");
19 assert!(accum
20 .iter()
21 .zip([11.0_f32, 10.0, 12.0])
22 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
23
24 let mut matrix = SparseMatrixF32::new(2, 2).expect("matrix");
25 matrix
26 .set_property(sparse_matrix_property::LOWER_TRIANGULAR)
27 .expect("property");
28 matrix.insert_entry(0, 0, 2.0).expect("a00");
29 matrix.insert_entry(1, 0, 1.0).expect("a10");
30 matrix.insert_entry(1, 1, 3.0).expect("a11");
31 matrix.commit().expect("commit");
32
33 let mut rhs = [2.0_f32, 7.0];
34 matrix
35 .triangular_solve_vector(blas_transpose::NO_TRANS, 1.0, &mut rhs)
36 .expect("solve vector");
37 assert!(rhs
38 .iter()
39 .zip([1.0_f32, 2.0])
40 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
41
42 println!("sparse smoke passed: dot={dot} accum={accum:?} solve={rhs:?}");
43}pub fn triangular_solve_matrix_row_major( &self, transpose: i32, rhs_columns: usize, alpha: f32, values: &mut [f32], ) -> Result<()>
Trait Implementations§
Source§impl Drop for SparseMatrixF32
impl Drop for SparseMatrixF32
impl Send for SparseMatrixF32
impl Sync for SparseMatrixF32
Auto Trait Implementations§
impl Freeze for SparseMatrixF32
impl RefUnwindSafe for SparseMatrixF32
impl Unpin for SparseMatrixF32
impl UnsafeUnpin for SparseMatrixF32
impl UnwindSafe for SparseMatrixF32
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more