Skip to main content

SparseMatrixF32

Struct SparseMatrixF32 

Source
pub struct SparseMatrixF32 { /* private fields */ }
Expand description

Owned sparse single-precision matrix handle backed by the Swift bridge.

Implementations§

Source§

impl SparseMatrixF32

Source

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}
Source

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}
Source

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}
Source

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}
Source

pub fn rows(&self) -> Result<usize>

Source

pub fn columns(&self) -> Result<usize>

Source

pub fn nonzero_count(&self) -> Result<usize>

Source

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}
Source

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for SparseMatrixF32

Source§

impl Sync for SparseMatrixF32

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.