graphblas_sparse_linear_algebra/context/
configuration.rs

1use suitesparse_graphblas_sys::{
2    GxB_Format_Value, GxB_Format_Value_GxB_BY_COL, GxB_Format_Value_GxB_BY_ROW,
3    GxB_Global_Option_set, GxB_Option_Field_GxB_FORMAT,
4};
5
6use crate::error::SparseLinearAlgebraError;
7
8use super::Context;
9
10#[derive(Copy, Clone, Debug)]
11pub enum MatrixStorageFormat {
12    ByRow,
13    ByColumn,
14}
15
16impl Into<GxB_Format_Value> for MatrixStorageFormat {
17    fn into(self) -> GxB_Format_Value {
18        match self {
19            MatrixStorageFormat::ByRow => GxB_Format_Value_GxB_BY_ROW,
20            MatrixStorageFormat::ByColumn => GxB_Format_Value_GxB_BY_COL,
21        }
22    }
23}
24
25pub(crate) trait SetMatrixFormat {
26    fn set_matrix_format(
27        &mut self,
28        format: MatrixStorageFormat,
29    ) -> Result<(), SparseLinearAlgebraError>;
30}
31
32impl SetMatrixFormat for Context {
33    fn set_matrix_format(
34        &mut self,
35        format: MatrixStorageFormat,
36    ) -> Result<(), SparseLinearAlgebraError> {
37        self.call_without_detailed_error_information(|| unsafe {
38            // TODO: use GrB_set() once it becomes available
39            GxB_Global_Option_set(
40                GxB_Option_Field_GxB_FORMAT as i32,
41                <MatrixStorageFormat as Into<GxB_Format_Value>>::into(format),
42            )
43        })?;
44        Ok(())
45    }
46}
47
48#[cfg(test)]
49mod tests {}