use suitesparse_graphblas_sys::GrB_Descriptor;
use super::{
graphblas_descriptor, GetClearOutputBeforeUse, GetGraphblasDescriptor, GetOperatorMaskOptions,
GetOperatorOptions, GetTransposeSecondMatrixArgument, WithTransposeMatrixArgument,
};
unsafe impl Send for OptionsForOperatorWithMatrixAsSecondArgument {}
unsafe impl Sync for OptionsForOperatorWithMatrixAsSecondArgument {}
#[derive(Debug, Clone)]
pub struct OptionsForOperatorWithMatrixAsSecondArgument {
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 GetOptionsForOperatorWithMatrixAsSecondArgument:
GetOperatorOptions + GetTransposeSecondMatrixArgument
{
}
impl GetOperatorOptions for OptionsForOperatorWithMatrixAsSecondArgument {}
impl GetOptionsForOperatorWithMatrixAsSecondArgument
for OptionsForOperatorWithMatrixAsSecondArgument
{
}
impl GetClearOutputBeforeUse for OptionsForOperatorWithMatrixAsSecondArgument {
fn clear_output_before_use(&self) -> bool {
self.clear_output_before_use
}
}
impl GetOperatorMaskOptions for OptionsForOperatorWithMatrixAsSecondArgument {
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 GetTransposeSecondMatrixArgument for OptionsForOperatorWithMatrixAsSecondArgument {
fn transpose_second_matrix_argument(&self) -> bool {
self.transpose_matrix_argument
}
}
impl GetGraphblasDescriptor for OptionsForOperatorWithMatrixAsSecondArgument {
fn graphblas_descriptor(&self) -> GrB_Descriptor {
self.graphblas_descriptor
}
}
impl WithTransposeMatrixArgument for OptionsForOperatorWithMatrixAsSecondArgument {
fn with_negated_transpose_matrix_argument(&self) -> Self {
OptionsForOperatorWithMatrixAsSecondArgument::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 {
OptionsForOperatorWithMatrixAsSecondArgument::new(
self.clear_output_before_use,
self.use_mask_structure_of_stored_values_as_mask,
self.use_mask_complement,
transpose_matrix,
)
}
}
}
impl OptionsForOperatorWithMatrixAsSecondArgument {
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,
false,
transpose_matrix_argument,
),
}
}
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,
false,
transpose_matrix_argument,
),
}
}
}
#[cfg(test)]
mod tests {
use std::ptr;
use super::*;
#[test]
fn test_options() {
let default_options = OptionsForOperatorWithMatrixAsSecondArgument::new_default();
let expected_value: GrB_Descriptor = ptr::null_mut();
assert_eq!(default_options.graphblas_descriptor(), expected_value)
}
}