Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabianmurariu/rustgraphblas
rust-library to wrap GraphBLAS.h
https://github.com/fabianmurariu/rustgraphblas
graph-algorithms graphblas rust-library
Last synced: about 17 hours ago
JSON representation
rust-library to wrap GraphBLAS.h
- Host: GitHub
- URL: https://github.com/fabianmurariu/rustgraphblas
- Owner: fabianmurariu
- Created: 2019-12-25T16:24:44.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-19T15:27:27.000Z (almost 2 years ago)
- Last Synced: 2024-05-18T05:03:14.691Z (8 months ago)
- Topics: graph-algorithms, graphblas, rust-library
- Language: Rust
- Size: 79.1 KB
- Stars: 26
- Watchers: 5
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# rustgraphblas
Wrapper for `GraphBLAS.h` exposing a nicer rust API
Exposes a set of routines over sparse matrices and sparse vectors combined with
various semirings. This allows graphs to be represented as sparse matrices and
various algorithms (bfs, connected components, page rank, ..) to be implemented
as a set of linear algebra operations.More about GraphBLAS [here](http://graphblas.org/index.php?title=Graph_BLAS_Forum)
Requirements: build and install GraphBLAS dependency, for details see[here](https://github.com/DrTimothyAldenDavis/GraphBLAS/blob/stable/README.md "GraphBLAS readme")
```bash
cd deps/GraphBLAS
make clean install
```Example of BFS from [bfs5m.c](https://github.com/fabianmurariu/SuiteSparse/blob/master/GraphBLAS/Demo/Source/bfs5m.c#L33)
```rust
/**
* this is the test for the graph on the cover of
* Graph Algorithms in the Language of Linear Algebra
* where by multiplying a boolean matrix with
* a boolean vector on the and/or semiring until there are no successor we get BFS
* */
fn graph_blas_port_bfs(){
let s:u64 = 0; // start at 0
let n = 7; //verticeslet mut A = SparseMatrix::::empty((n, n));
let edges_n:usize = 10;
A.load(edges_n as u64, &vec![true; edges_n],
&[0, 0, 1, 1, 2, 3, 4, 5, 6, 6],
&[1, 3, 6, 4, 5, 2, 5, 2, 2, 3]);let mut v = SparseVector::::empty(n);
let mut q = SparseVector::::empty(n);let mut default_desc = Descriptor::default();
// GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL) ; // make v dense
v.assign_all(empty_mask::(), None, 0, n, &default_desc);//finish pending work on v
assert_eq!(n, v.nvals());
// GrB_Vector_setElement (q, true, s) ; // q[s] = true, false elsewhere
q.insert(s, true);// GrB_Monoid_new (&Lor, GrB_LOR, (bool) false) ;
// GrB_Semiring_new (&Boolean, Lor, GrB_LAND) ;
// FIXME: Semirings do not OWN monoids
let lor_monoid = SparseMonoid::::new(BinaryOp::::lor(), false);
let lor_monoid2 = SparseMonoid::::new(BinaryOp::::lor(), false);
let or_and_semi = Semiring::new(lor_monoid, BinaryOp::::land());let mut desc = Descriptor::default();
desc.set(Field::Mask, Value::SCMP).set(Field::Output, Value::Replace);let mut successor = true;
let mut level:i32 = 1;
while successor && level <= (n as i32) {
v.assign_all(Some(&q), None, level, n, &default_desc);q.vxm(Some(&v), None, &A, &or_and_semi, &desc);
q.reduce(&mut successor, None, &lor_monoid2, &default_desc);
level = level + 1;
}
assert_eq!(v.get(0), Some(1));assert_eq!(v.get(1), Some(2));
assert_eq!(v.get(3), Some(2));assert_eq!(v.get(4), Some(3));
assert_eq!(v.get(6), Some(3));
assert_eq!(v.get(2), Some(3));assert_eq!(v.get(5), Some(4));
}
```