gspx 0.1.2

Sparse graph signal processing and spectral graph wavelets in Rust
Documentation
//! Unified error type for all `gspx` public APIs.

use std::io;

use thiserror::Error;

#[derive(Debug, Error)]
/// Error type for all `gspx` operations.
pub enum GspError {
    /// Dimension mismatch between graph, signal, or kernel data.
    #[error("dimension mismatch: {0}")]
    Dimensions(String),
    /// Index out-of-bounds access.
    #[error("index out of bounds: {0}")]
    Index(String),
    /// Invalid kernel parameters.
    #[error("invalid kernel: {0}")]
    InvalidKernel(String),
    /// Invalid filter scales.
    #[error("invalid scale(s): {0}")]
    InvalidScales(String),
    /// Sparse factorization failure.
    #[error("factorization failure: {0}")]
    Factorization(String),
    /// Singular linear solve.
    #[error("singular solve: {0}")]
    SingularSolve(String),
    /// Parse or decode failure.
    #[error("parse/decode failure: {0}")]
    Parse(String),
    /// I/O error.
    #[error("I/O error: {0}")]
    Io(#[from] io::Error),
    /// Cache load/store error.
    #[error("cache error: {0}")]
    Cache(String),
    /// Requested named resource is unavailable.
    #[error("resource not found: {0}")]
    ResourceNotFound(String),
    /// Unsupported file/data format.
    #[error("unsupported data format: {0}")]
    UnsupportedFormat(String),
}

impl From<serde_json::Error> for GspError {
    fn from(value: serde_json::Error) -> Self {
        Self::Parse(value.to_string())
    }
}

impl From<matrw::MatrwError> for GspError {
    fn from(value: matrw::MatrwError) -> Self {
        Self::Parse(value.to_string())
    }
}

impl From<sprs::errors::LinalgError> for GspError {
    fn from(value: sprs::errors::LinalgError) -> Self {
        Self::Factorization(value.to_string())
    }
}