Crates.io | elara-math |
lib.rs | elara-math |
version | 0.1.1 |
source | src |
created_at | 2023-02-21 19:11:11.261479 |
updated_at | 2023-06-02 17:07:10.487427 |
description | Rust-native tensor and math library |
homepage | |
repository | https://github.com/elaraproject/elara-math |
max_upload_size | |
id | 791001 |
size | 44,434 |
Elara Math is a Rust-native math library, with (current or planned support for):
*: GPU tensors are not available yet, but GPU acceleration is planned to be added in the future
As an example, here is a working tiny neural network using elara-math
.
use elara_math::prelude::*;
const EPOCHS: usize = 10000;
const LR: f64 = 1e-5;
fn main() {
let train_data = tensor![
[0.0, 0.0, 1.0],
[1.0, 1.0, 1.0],
[1.0, 0.0, 1.0],
[0.0, 1.0, 1.0]];
let train_labels = tensor![
[0.0],
[1.0],
[1.0],
[0.0]
].reshape([4, 1]);
let mut weights = Tensor::rand([3, 1]);
for epoch in 0..EPOCHS {
let output = train_data.matmul(&weights).relu();
let loss = elara_math::mse(&output, &train_labels);
println!("Epoch {}, loss: {:?}", epoch, loss);
loss.backward();
let adjustment = weights.grad() * LR;
weights = weights - Tensor::new(adjustment);
weights.zero_grad();
}
let pred_data = tensor![[1.0, 0.0, 0.0]];
let pred = &pred_data.matmul(&weights).relu();
println!("Weights after training: {:?}", weights);
println!("Prediction [1, 0, 0] -> {:?}", pred.borrow().data);
}
To develop elara-math
, first clone the repository:
git clone https://github.com/elaraproject/elara-math
Then, copy over the pre-commit githook:
cp .githooks/pre-commit .git/hooks/pre-commit && chmod a+x .git/hooks/pre-commit
You should then be all set to start making changes!