Enum MtxData

Source
pub enum MtxData<T: Num, const NDIM: usize = 2> {
    Dense([usize; NDIM], Vec<T>, SymInfo),
    Sparse([usize; NDIM], Vec<[usize; NDIM]>, Vec<T>, SymInfo),
}
Expand description

The main enum of this crate, corresponding to the 2 kind of usage of mtx files. Both contains a first line with dimensions. Dense is a list of numbers. Sparse is a list of coordinates and values.

Variants§

§

Dense([usize; NDIM], Vec<T>, SymInfo)

§

Sparse([usize; NDIM], Vec<[usize; NDIM]>, Vec<T>, SymInfo)

Implementations§

Source§

impl<T: Num, const NDIM: usize> MtxData<T, NDIM>

Source

pub fn from_file<P>(path: P) -> Result<Self, MtxError>
where P: AsRef<Path>,

Build a MtxData from a matrix market (usually .mtx) file.

§Example
use matrix_market_rs::{MtxData, SymInfo, MtxError};
use std::fs::File;
use std::io::Write;

fn main() -> Result<(), MtxError> {
    let mtx_content = r#"
    %%MatrixMarket matrix coordinate integer symmetric
    2 2 2
    1 1 3
    2 2 4
    "#;
    
    let mut f = File::create("sparse2x2.mtx")?;
    f.write_all(mtx_content.trim().as_bytes());
    let shape = [2,2];
    let indices = vec![[0,0], [1,1]];
    let nonzeros = vec![3,4];
    let sym = SymInfo::Symmetric;
    
    let sparse:MtxData<i32> = MtxData::from_file("sparse2x2.mtx")?;
    assert_eq!(sparse, MtxData::Sparse(shape, indices, nonzeros, sym));
    Ok(())
}
§Errors

It could fail for many reasons but for example:

  • File doesn’t match the matrix market format.
  • an IO error (file not found etc.)

Trait Implementations§

Source§

impl<T: Clone + Num, const NDIM: usize> Clone for MtxData<T, NDIM>

Source§

fn clone(&self) -> MtxData<T, NDIM>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Num, const NDIM: usize> Debug for MtxData<T, NDIM>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq + Num, const NDIM: usize> PartialEq for MtxData<T, NDIM>

Source§

fn eq(&self, other: &MtxData<T, NDIM>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq + Num, const NDIM: usize> Eq for MtxData<T, NDIM>

Source§

impl<T: Num, const NDIM: usize> StructuralPartialEq for MtxData<T, NDIM>

Auto Trait Implementations§

§

impl<T, const NDIM: usize> Freeze for MtxData<T, NDIM>

§

impl<T, const NDIM: usize> RefUnwindSafe for MtxData<T, NDIM>
where T: RefUnwindSafe,

§

impl<T, const NDIM: usize> Send for MtxData<T, NDIM>
where T: Send,

§

impl<T, const NDIM: usize> Sync for MtxData<T, NDIM>
where T: Sync,

§

impl<T, const NDIM: usize> Unpin for MtxData<T, NDIM>
where T: Unpin,

§

impl<T, const NDIM: usize> UnwindSafe for MtxData<T, NDIM>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.