#linear-algebra #sparse #linear #suite-sparse #algebra #graph-blas #api-bindings

graphblas_sparse_linear_algebra

Wrapper for SuiteSparse:GraphBLAS

80 releases (43 breaking)

0.44.0 Apr 2, 2024
0.43.0 Mar 17, 2024
0.42.1 Mar 9, 2024
0.36.0 Nov 28, 2023
0.3.0 Jul 8, 2021

#81 in Math

Download history 7/week @ 2024-01-11 7/week @ 2024-02-01 20/week @ 2024-02-08 182/week @ 2024-02-15 510/week @ 2024-02-22 266/week @ 2024-02-29 253/week @ 2024-03-07 186/week @ 2024-03-14 20/week @ 2024-03-21 126/week @ 2024-03-28 72/week @ 2024-04-04 6/week @ 2024-04-11

230 downloads per month
Used in 2 crates

CC-BY-NC-4.0

2MB
38K SLoC

test

graphblas_sparse_linear_algebra

Rust wrapper for SuiteSparse:GraphBLAS

Minimum example

use graphblas_sparse_linear_algebra::collections::sparse_matrix::operations::{
    FromMatrixElementList, GetSparseMatrixElementValue,
};
use graphblas_sparse_linear_algebra::collections::sparse_matrix::{
    MatrixElementList, Size, SparseMatrix,
};
use graphblas_sparse_linear_algebra::collections::Collection;
use graphblas_sparse_linear_algebra::context::Context;
use graphblas_sparse_linear_algebra::operators::apply::{
    ApplyBinaryOperator, BinaryOperatorApplier,
};
use graphblas_sparse_linear_algebra::operators::binary_operator::{Assignment, First};
use graphblas_sparse_linear_algebra::operators::mask::SelectEntireMatrix;
use graphblas_sparse_linear_algebra::operators::options::{
    OptionsForOperatorWithMatrixAsFirstArgument, OptionsForOperatorWithMatrixAsSecondArgument,
};

fn main() {
    let context = Context::init_default().unwrap();

    let element_list = MatrixElementList::<u8>::from_element_vector(vec![
        (1, 1, 1).into(),
        (2, 1, 2).into(),
        (4, 2, 4).into(),
        (5, 2, 5).into(),
    ]);

    let matrix_size: Size = (10, 15).into();
    let matrix = SparseMatrix::<u8>::from_element_list(
        &context.to_owned(),
        &matrix_size,
        &element_list,
        &First::<u8>::new(),
    )
    .unwrap();

    let mut product_matrix = SparseMatrix::<u8>::new(&context, &matrix_size).unwrap();

    let operator = BinaryOperatorApplier::new();
    let first_argument = 10;
    operator
        .apply_with_matrix_as_left_argument(
            &matrix,
            &First::<u8>::new(),
            &first_argument,
            &Assignment::new(),
            &mut product_matrix,
            &SelectEntireMatrix::new(&context),
            &OptionsForOperatorWithMatrixAsFirstArgument::new_default(),
        )
        .unwrap();

    println!("{}", product_matrix);

    assert_eq!(product_matrix.number_of_stored_elements().unwrap(), 4);
    assert_eq!(product_matrix.element_value(&2, &1).unwrap(), Some(2));
    assert_eq!(product_matrix.element_value(&9, &1).unwrap(), None);

    let operator = BinaryOperatorApplier::new();
    let second_argument = 10;
    operator
        .apply_with_matrix_as_right_argument(
            &second_argument,
            &First::<u8>::new(),
            &matrix,
            &Assignment::new(),
            &mut product_matrix,
            &SelectEntireMatrix::new(&context),
            &OptionsForOperatorWithMatrixAsSecondArgument::new_default(),
        )
        .unwrap();

    println!("{}", matrix);
    println!("{}", product_matrix);

    assert_eq!(product_matrix.number_of_stored_elements().unwrap(), 4);
    assert_eq!(product_matrix.element_value(&2, &1).unwrap(), Some(10));
    assert_eq!(product_matrix.element_value(&9, &1).unwrap(), None);
 }

Dependencies

graphblas_sparse_linear_algebra uses the SuiteSparse:GraphBLAS implementation developed by Timothy A. Davis.

Building from source

Please make sure to meet the requirements for building suitesparse_graphblas_sys.

Compatibility

graphblas_sparse_linear_algebra is mostly compatible with the GraphBLAS specification version 2.0 and uses SuiteSparse:GraphBLAS v8.2.0.

Contributing

Awesome, contributions are welcome. Graphblas_sparse_linear_algebra and your contribution may be relicensed and integrated into commercial software in the future. Therefore, you will be asked to agree to the Contributor License Agreement when you make a pull request.

Licensing

graphblas_sparse_linear_algebra is licensed under Creative Commons Attribution Non Commercial 4.0 International. For other licensing options, please contact Sam Dekker.

Dependencies

~1.5–5MB
~109K SLoC