A tensor library for Rust
Go to file
Julius Koskela f9c29aefd5
Rank 3 contraction not working yet
Signed-off-by: Julius Koskela <julius.koskela@unikie.com>
2023-12-30 01:39:57 +02:00
docs More cases of contraction working, still some issues with misaligned symmetries 2023-12-29 22:52:24 +02:00
examples Rank 3 contraction not working yet 2023-12-30 01:39:57 +02:00
src Rank 3 contraction not working yet 2023-12-30 01:39:57 +02:00
.gitignore 🚀 WIP implementation of N-rank Tensor 2023-12-26 01:47:13 +02:00
Cargo.lock Reduce cloning 2023-12-29 18:40:53 +02:00
Cargo.toml Reduce cloning 2023-12-29 18:40:53 +02:00
LICENSE 🚀 WIP implementation of N-rank Tensor 2023-12-26 01:47:13 +02:00
README.md Reduce cloning 2023-12-29 18:40:53 +02:00
rust-toolchain.toml 🚀 WIP implementation of N-rank Tensor 2023-12-26 01:47:13 +02:00
rustfmt.toml 🚀 WIP implementation of N-rank Tensor 2023-12-26 01:47:13 +02:00

Mainfold

// Create two tensors with different ranks and shapes
let mut tensor1 = Tensor::<i32, 2>::from([2, 2]); // 2x2 tensor
let mut tensor2 = Tensor::<i32, 1>::from([2]);    // 2-element vector

// Fill tensors with some values
tensor1.buffer_mut().copy_from_slice(&[1, 2, 3, 4]);
tensor2.buffer_mut().copy_from_slice(&[5, 6]);

// Calculate tensor product
let product = tensor1.tensor_product(&tensor2);

println!("T1 * T2 = {}", product);

// Check shape of the resulting tensor
assert_eq!(product.shape(), Shape::new([2, 2, 2]));

// Check buffer of the resulting tensor
assert_eq!(product.buffer(), &[5, 6, 10, 12, 15, 18, 20, 24]);