rsparse
A Rust library for solving sparse linear systems using direct methods.
Science Score: 57.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 4 DOI reference(s) in README -
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (7.0%) to scientific vocabulary
Keywords
Repository
A Rust library for solving sparse linear systems using direct methods.
Basic Info
Statistics
- Stars: 17
- Watchers: 1
- Forks: 3
- Open Issues: 1
- Releases: 1
Topics
Metadata Files
README.md
rsparse
A Rust library for solving sparse linear systems using direct methods.
Data structures
- CSC matrix (
Sprs) - Triplet matrix (
Trpl)
Features
- Convert from dense
[Vec<T>]orVec<Vec<T>>matrix to CSC sparse matrixSprs - Convert from sparse to dense
Vec<Vec<T>> - Convert from a triplet format matrix
Trplto CSCSprs - Sparse matrix addition [C=A+B]
- Sparse matrix multiplication [C=A*B]
- Transpose sparse matrices
- Solve sparse linear systems
Solvers
- lsolve: Solve a lower triangular system. Solves Lx=b where x and b are dense.
- ltsolve: Solve L’x=b where x and b are dense.
- usolve: Solve an upper triangular system. Solves Ux=b where x and b are dense
- utsolve: Solve U’x=b where x and b are dense
- cholsol: A\b solver using Cholesky factorization. Where A is a defined positive
Sprsmatrix and b is a dense vector - lusol: A\b solver using LU factorization. Where A is a square
Sprsmatrix and b is a dense vector - qrsol: A\b solver using QR factorization. Where A is a rectangular
Sprsmatrix and b is a dense vector
Examples
Basic matrix operations
```rust use rsparse;
fn main() { // Create a CSC sparse matrix A let a = rsparse::data::Sprs{ // Maximum number of entries nzmax: 5, // number of rows m: 3, // number of columns n: 3, // Values x: vec![1., 9., 9., 2., 9.], // Indices i: vec![1, 2, 2, 0, 2], // Pointers p: vec![0, 2, 3, 5] };
// Import the same matrix from a dense structure
let mut a2 = rsparse::data::Sprs::new_from_vec(
&[
vec![0., 0., 2.],
vec![1., 0., 0.],
vec![9., 9., 9.]
]
);
// Check if they are the same
assert_eq!(a.nzmax, a2.nzmax);
assert_eq!(a.m,a2.m);
assert_eq!(a.n,a2.n);
assert_eq!(a.x,a2.x);
assert_eq!(a.i,a2.i);
assert_eq!(a.p,a2.p);
// Transform A to dense and print result
println!("\nA");
print_matrix(&a.to_dense());
// Transpose A
let at = rsparse::transpose(&a);
// Transform to dense and print result
println!("\nAt");
print_matrix(&at.to_dense());
// B = A + A'
let b = &a + &at;
// Transform to dense and print result
println!("\nB");
print_matrix(&b.to_dense());
// C = A * B
let c = &a * &b;
// Transform to dense and print result
println!("\nC");
print_matrix(&c.to_dense());
}
fn print_matrix(vec: &[Vec
Output:
``` A 0 0 2 1 0 0 9 9 9
At 0 1 9 0 0 9 2 0 9
B 0 1 11 1 0 9 11 9 18
C 22 18 36 0 1 11 108 90 342 ```
Solve a linear system
```rust use rsparse;
fn main() { // Arbitrary A matrix (dense) let a = [ vec![8.2541e-01, 9.5622e-01, 4.6698e-01, 8.4410e-03, 6.3193e-01, 7.5741e-01, 5.3584e-01, 3.9448e-01], vec![7.4808e-01, 2.0403e-01, 9.4649e-01, 2.5086e-01, 2.6931e-01, 5.5866e-01, 3.1827e-01, 2.9819e-02], vec![6.3980e-01, 9.1615e-01, 8.5515e-01, 9.5323e-01, 7.8323e-01, 8.6003e-01, 7.5761e-01, 8.9255e-01], vec![1.8726e-01, 8.9339e-01, 9.9796e-01, 5.0506e-01, 6.1439e-01, 4.3617e-01, 7.3369e-01, 1.5565e-01], vec![2.8015e-02, 6.3404e-01, 8.4771e-01, 8.6419e-01, 2.7555e-01, 3.5909e-01, 7.6644e-01, 8.9905e-02], vec![9.1817e-01, 8.6629e-01, 5.9917e-01, 1.9346e-01, 2.1960e-01, 1.8676e-01, 8.7020e-01, 2.7891e-01], vec![3.1999e-01, 5.9988e-01, 8.7402e-01, 5.5710e-01, 2.4707e-01, 7.5652e-01, 8.3682e-01, 6.3145e-01], vec![9.3807e-01, 7.5985e-02, 7.8758e-01, 3.6881e-01, 4.4553e-01, 5.5005e-02, 3.3908e-01, 3.4573e-01], ];
// Convert A to sparse
let mut a_sparse = rsparse::data::Sprs::new();
a_sparse.from_vec(&a);
// Generate arbitrary b vector
let mut b = [
0.4377,
0.7328,
0.1227,
0.1817,
0.2634,
0.6876,
0.8711,
0.4201
];
// Known solution:
/*
0.264678,
-1.228118,
-0.035452,
-0.676711,
-0.066194,
0.761495,
1.852384,
-0.282992
*/
// A*x=b -> solve for x -> place x in b
rsparse::lusol(&a_sparse, &mut b, 1, 1e-6);
println!("\nX");
println!("{:?}", &b);
} ```
Output:
X
[0.2646806068156303, -1.2280777288645675, -0.035491404094236435, -0.6766064748053932, -0.06619898266432682, 0.7615102544801993, 1.8522970972589123, -0.2830302118359591]
Documentation
Documentation is available at docs.rs.
Sources
- Davis, T. (2006). Direct Methods for Sparse Linear Systems. Society for Industrial and Applied Mathematics. https://doi.org/10.1137/1.9780898718881
- CSparse: A Concise Sparse Matrix Package in C
Owner
- Name: Ricard Lado
- Login: RLado
- Kind: user
- Location: Barcelona
- Company: Universitat Ramon Llull (IQS School of Engineering)
- Website: lado.one
- Repositories: 24
- Profile: https://github.com/RLado
PhD Candidate. I love Linux and all things open source.
Citation (CITATION.cff)
cff-version: 1.2.0
title: rsparse
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- family-names: Lado-Roigé
given-names: Ricard
orcid: 'https://orcid.org/0000-0002-6421-7351'
repository-code: 'https://github.com/RLado/rsparse'
url: 'https://crates.io/crates/rsparse'
abstract: >-
A Rust library for solving sparse linear systems using
direct methods.
keywords:
- sparse-matrices
- linear-algebra
- math
- rust
license: MIT
version: 1.2.1
date-released: '2025-03-29'
GitHub Events
Total
- Issues event: 3
- Watch event: 3
- Delete event: 1
- Issue comment event: 9
- Push event: 8
- Pull request review event: 2
- Pull request event: 6
- Fork event: 1
- Create event: 2
Last Year
- Issues event: 3
- Watch event: 3
- Delete event: 1
- Issue comment event: 9
- Push event: 8
- Pull request review event: 2
- Pull request event: 6
- Fork event: 1
- Create event: 2
Committers
Last synced: over 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| Ricard Lado | r****o@h****m | 54 |
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 6
- Total pull requests: 10
- Average time to close issues: 6 days
- Average time to close pull requests: about 23 hours
- Total issue authors: 5
- Total pull request authors: 3
- Average comments per issue: 1.17
- Average comments per pull request: 1.2
- Merged pull requests: 10
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 2
- Pull requests: 6
- Average time to close issues: N/A
- Average time to close pull requests: 1 day
- Issue authors: 2
- Pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 1.0
- Merged pull requests: 6
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- MothNik (3)
- RLado (1)
- cheginit (1)
- Voidheart88 (1)
- Makogan (1)
Pull Request Authors
- RLado (5)
- Masterchef365 (4)
- MothNik (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cargo 24,900 total
- Total dependent packages: 2
- Total dependent repositories: 1
- Total versions: 18
- Total maintainers: 1
crates.io: rsparse
A Rust library for solving sparse linear systems using direct methods.
- Documentation: https://docs.rs/rsparse/
- License: MIT
-
Latest release: 1.2.1
published 9 months ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v3 composite