deep_causality_sparse
CausalSparse - Efficient Sparse Matrix Operations
deep_causality_sparse is a Rust library providing an efficient implementation of Compressed Sparse Row (CSR) matrices. It is designed for scenarios where data is predominantly zero, offering significant memory savings and computational performance improvements over dense matrix representations. This crate enables robust and fast operations on sparse data, crucial for many scientific computing, machine learning, and data analysis tasks.
Key Features
- Compressed Sparse Row (CSR) Format: Leverages the CSR storage format for optimal memory usage and efficient row-wise access, ideal for sparse matrices.
- Intuitive Construction: Easily create
CsrMatrixinstances from triplet lists ((row, col, value)) with automatic handling of duplicate entries and zero-valued elements. - Comprehensive Operations: Supports a wide range of matrix operations, including:
- Arithmetic: Addition (
add_matrix), Subtraction (sub_matrix), Scalar Multiplication (scalar_mult). - Vector & Matrix Multiplication: Efficient matrix-vector product (
vec_mult) and matrix-matrix product (mat_mult). - Transformation: Transpose (
transpose).
- Arithmetic: Addition (
- Robust Error Handling: Provides clear
SparseMatrixErrortypes for dimension mismatches, shape incompatibilities, and index out-of-bounds conditions, ensuring reliable computations. - Efficient Element Access & Iteration:
get_value_atfor individual element retrieval, and various iterators (iter_non_zeros,iter_rows,iter_cols) for efficient traversal of non-zero elements. - Memory Efficiency: By storing only non-zero elements,
CsrMatrixis highly memory-efficient for sparse datasets.
Installation
Add deep_causality_sparse to your Cargo.toml file:
[]
= "0.1.0" # Or the latest version
Usage
Here are some basic examples demonstrating the core functionalities of deep_causality_sparse.
Basic Matrix Operations
use CsrMatrix;
To run this example, use cargo run --example basic_matrix_ops.
Technical Details
Compressed Sparse Row (CSR) Format
The CsrMatrix internally stores the sparse matrix using three main vectors:
row_indices: A vector of lengthrows + 1.row_indices[i]stores the index incol_indicesandvalueswhere the non-zero elements of rowibegin.row_indices[rows]stores the total number of non-zero elements.col_indices: Stores the column index for each non-zero element. These are ordered by row, then by column within each row.values: Stores the actual non-zero values, corresponding one-to-one withcol_indices.
This format is particularly efficient for operations that process data row by row, such as matrix-vector multiplication, as it allows direct access to the non-zero elements of any given row.
Efficient Operations
Operations like matrix addition and subtraction iterate through the non-zero elements of both matrices simultaneously, merging them efficiently. Matrix-vector and matrix-matrix multiplications are optimized to leverage the sparse structure, avoiding multiplications by zero.
📚 Docs
👨💻👩💻 Contribution
Contributions are welcomed especially related to documentation, example code, and fixes. If unsure where to start, just open an issue and ask.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in deep_causality by you, shall be licensed under the MIT licence, without any additional terms or conditions.
📜 Licence
This project is licensed under the MIT license.
👮️ Security
For details about security, please read the security policy.
💻 Author
- Marvin Hansen.
- Github GPG key ID: 369D5A0B210D39BC
- GPG Fingerprint: 4B18 F7B2 04B9 7A72 967E 663E 369D 5A0B 210D 39BC