use suitesparse_graphblas_sys::GrB_Descriptor;
use super::{
graphblas_descriptor, GetClearOutputBeforeUse, GetGraphblasDescriptor, GetOperatorMaskOptions,
GetOperatorOptions, GetTransposeMatrixArgument, WithTransposeMatrixArgument,
};
unsafe impl Send for OptionsForOperatorWithMatrixArgument {}
unsafe impl Sync for OptionsForOperatorWithMatrixArgument {}
#[derive(Debug, Clone)]
pub struct OptionsForOperatorWithMatrixArgument {
clear_output_before_use: bool,
use_mask_structure_of_stored_values_as_mask: bool,
use_mask_complement: bool,
transpose_matrix_argument: bool,
graphblas_descriptor: GrB_Descriptor,
}
pub trait GetOptionsForOperatorWithMatrixArgument:
GetOperatorOptions + GetTransposeMatrixArgument
{
}
impl GetOperatorOptions for OptionsForOperatorWithMatrixArgument {}
impl GetOptionsForOperatorWithMatrixArgument for OptionsForOperatorWithMatrixArgument {}
impl GetClearOutputBeforeUse for OptionsForOperatorWithMatrixArgument {
fn clear_output_before_use(&self) -> bool {
self.clear_output_before_use
}
}
impl GetOperatorMaskOptions for OptionsForOperatorWithMatrixArgument {
fn use_mask_structure_of_stored_values_as_mask(&self) -> bool {
self.use_mask_structure_of_stored_values_as_mask
}
fn use_mask_complement(&self) -> bool {
self.use_mask_complement
}
}
impl GetTransposeMatrixArgument for OptionsForOperatorWithMatrixArgument {
fn transpose_matrix_argument(&self) -> bool {
self.transpose_matrix_argument
}
}
impl GetGraphblasDescriptor for OptionsForOperatorWithMatrixArgument {
fn graphblas_descriptor(&self) -> GrB_Descriptor {
self.graphblas_descriptor
}
}
impl WithTransposeMatrixArgument for OptionsForOperatorWithMatrixArgument {
fn with_negated_transpose_matrix_argument(&self) -> Self {
OptionsForOperatorWithMatrixArgument::new(
self.clear_output_before_use,
self.use_mask_structure_of_stored_values_as_mask,
self.use_mask_complement,
!self.transpose_matrix_argument,
)
}
fn with_transpose_matrix_argument(&self, transpose_matrix: bool) -> Self {
if transpose_matrix == self.transpose_matrix_argument {
self.clone()
} else {
OptionsForOperatorWithMatrixArgument::new(
self.clear_output_before_use,
self.use_mask_structure_of_stored_values_as_mask,
self.use_mask_complement,
transpose_matrix,
)
}
}
}
impl OptionsForOperatorWithMatrixArgument {
pub fn new(
clear_output_before_use: bool,
use_mask_structure_of_stored_values_as_mask: bool,
use_mask_complement: bool,
transpose_matrix_argument: bool,
) -> Self {
Self {
clear_output_before_use,
use_mask_structure_of_stored_values_as_mask,
use_mask_complement,
transpose_matrix_argument,
graphblas_descriptor: graphblas_descriptor(
clear_output_before_use,
false,
false,
transpose_matrix_argument,
false,
),
}
}
pub fn new_default() -> Self {
let clear_output_before_use = false;
let use_mask_structure_of_stored_values_as_mask = false;
let use_mask_complement = false;
let transpose_matrix_argument = false;
Self {
clear_output_before_use,
use_mask_structure_of_stored_values_as_mask,
use_mask_complement,
transpose_matrix_argument,
graphblas_descriptor: graphblas_descriptor(
clear_output_before_use,
false,
false,
transpose_matrix_argument,
false,
),
}
}
}
#[cfg(test)]
mod tests {
use std::ptr;
use super::*;
#[test]
fn test_options() {
let default_options = OptionsForOperatorWithMatrixArgument::new_default();
let expected_value: GrB_Descriptor = ptr::null_mut();
assert_eq!(default_options.graphblas_descriptor(), expected_value)
}
}