SparseElement

Trait SparseElement 

Source
pub trait SparseElement:
    Copy
    + PartialEq
    + Add<Output = Self>
    + Sub<Output = Self>
    + Mul<Output = Self>
    + Default
    + Debug {
    // Required methods
    fn sparse_zero() -> Self;
    fn sparse_one() -> Self;

    // Provided methods
    fn zero() -> Self { ... }
    fn one() -> Self { ... }
    fn is_zero(&self) -> bool { ... }
}
Expand description

Trait for types that can be used as sparse matrix elements

This trait captures the minimal requirements for sparse matrix element types, supporting both integer and floating-point types. It provides the basic arithmetic operations and identity elements needed for sparse matrix operations.

§Design Philosophy

Unlike Float or ScientificNumber, this trait is intentionally minimal to support the widest range of numeric types in sparse matrices, including:

  • Integer types (u8, i32, u64, etc.) for graph adjacency matrices, binary operators, etc.
  • Floating-point types (f32, f64) for numerical computation

§Examples

use scirs2_core::numeric::SparseElement;

// Integer sparse matrix element
let a: u8 = 1;
let b: u8 = 2;
assert_eq!(a + b, 3);
assert_eq!(u8::sparse_zero(), 0);
assert_eq!(u8::sparse_one(), 1);
assert!(u8::sparse_zero().is_zero());

// Float sparse matrix element
let x: f64 = 1.0;
let y: f64 = 2.0;
assert_eq!(x + y, 3.0);
assert_eq!(f64::sparse_zero(), 0.0);
assert_eq!(f64::sparse_one(), 1.0);
assert!(f64::sparse_zero().is_zero());

Required Methods§

Source

fn sparse_zero() -> Self

The zero element (additive identity) for sparse matrix operations

This method is prefixed with sparse_ to avoid ambiguity with num_traits::Zero::zero().

Source

fn sparse_one() -> Self

The one element (multiplicative identity) for sparse matrix operations

This method is prefixed with sparse_ to avoid ambiguity with num_traits::One::one().

Provided Methods§

Source

fn zero() -> Self

👎Deprecated since 0.1.0-rc.2: Use sparse_zero() instead to avoid ambiguity with num_traits::Zero

The zero element (additive identity)

§Deprecation Notice

This method is deprecated to avoid ambiguity with num_traits::Zero::zero(). Use sparse_zero() instead.

Source

fn one() -> Self

👎Deprecated since 0.1.0-rc.2: Use sparse_one() instead to avoid ambiguity with num_traits::One

The one element (multiplicative identity)

§Deprecation Notice

This method is deprecated to avoid ambiguity with num_traits::One::one(). Use sparse_one() instead.

Source

fn is_zero(&self) -> bool

Check if value is zero

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SparseElement for f32

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for f64

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for i8

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for i16

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for i32

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for i64

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for i128

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for isize

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for u8

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for u16

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for u32

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for u64

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for u128

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Source§

impl SparseElement for usize

Source§

fn sparse_zero() -> Self

Source§

fn sparse_one() -> Self

Implementors§