Skip to content

Added linear algebra library#39

Open
imlvts wants to merge 1 commit into
masterfrom
linear-algebra
Open

Added linear algebra library#39
imlvts wants to merge 1 commit into
masterfrom
linear-algebra

Conversation

@imlvts
Copy link
Copy Markdown
Collaborator

@imlvts imlvts commented May 26, 2026

#[cfg(not(all(feature = "dense", feature = "csr")))] fn main() {}
#[cfg(all(feature = "dense", feature = "csr"))] fn main() {
use linalg::{einsum::einsum, tensor::NDIndex, dense::Dense, csr::Csr};

// 3x3 sparse adjacency
let a = Csr::<u32, f32>::from_coo(3, &mut vec![
    (0, 1, 1.0), (1, 2, 1.0), (2, 0, 1.0),
]);

// 3x2 dense features
let mut x = Dense::<f32>::zeros(vec![3, 2]);
x.fill_from(&[1.0, 2.0,  3.0, 4.0,  5.0, 6.0]);

let mut y = Dense::<f32>::zeros(vec![3, 2]);

einsum::<f32>(
    "ab,bc->ac",
    &[&a as &dyn NDIndex<f32>, &x],
    &mut [&mut y as &mut dyn NDIndex<f32>],
).unwrap();

assert_eq!(y.get(&[0, 0]), 3.0);  // row 0 picks up row 1 of x
assert_eq!(y.get(&[1, 1]), 6.0);  // row 1 picks up row 2 of x
assert_eq!(y.get(&[2, 0]), 1.0);  // row 2 picks up row 0 of x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant