45
0
Fork
You've already forked elara-math
0
Project Elara's tensor and math library for scientific computing (Original Edition)
  • Rust 86.2%
  • C 9.2%
  • CMake 2.8%
  • Just 1.3%
  • Shell 0.5%
Jacky Song 835de5cbe6 Github to Codeberg migration
See elaraproject/project-issues#27
Signed-off-by: Jacky Song <jacky.song.elara@gmail.com>
2026年06月11日 18:55:04 -04:00
.githooks Added pre-commit hook 2023年02月01日 19:57:10 -05:00
.well-known Add funding manifest referrer 2025年07月12日 00:05:47 +08:00
bindings Make as_str cbindgen-compatible 2025年07月19日 16:12:27 +08:00
c_examples Add (incomplete) C example for showcasing bindings 2025年07月19日 16:17:48 +08:00
examples Basic implementation of alternate autodiff API 2026年01月26日 11:27:43 -05:00
src Github to Codeberg migration 2026年06月11日 18:55:04 -04:00
.gitignore Add (incomplete) C example for showcasing bindings 2025年07月19日 16:17:48 +08:00
.gitmodules Add newest (Codeberg) version of Elara Log 2026年06月11日 18:54:16 -04:00
ACKNOWLEDGEMENTS.md Remove old elara-log submodule to prepare for new version of elara-log 2025年04月11日 03:49:16 -04:00
Cargo.toml Merge branch 'main' of https://codeberg.org/elaraproject/elara-math 2026年03月28日 12:03:51 -04:00
cbindgen.toml Remove extraneous doc comments from bindings and renames 2025年07月19日 15:30:13 +08:00
CODE_OF_CONDUCT.md Github to Codeberg migration 2026年06月11日 18:55:04 -04:00
justfile Add justfile for common build tasks 2025年07月19日 02:50:54 +08:00
LICENSE Create LICENSE 2022年10月22日 10:33:02 -04:00
README.md Update README to reach parity with community edition 2026年01月26日 11:44:48 -05:00
TODO.md Update TODO 2023年05月26日 13:13:46 -04:00

Elara Math (original edition)

Elara Math is a Rust-native vectorized math library, developed as part of Project Elara's suite of open-source software libraries. It contains support for:

  • Tensors: N-dimensional arrays with built-in support for automatic differentiation)* (supported)
  • Fully-vectorized opertions and linear algebra with tensors (supported)
  • Fast solvers for integrals & differential equations with GPU acceleration (partially supported**, work-in-progress)
  • Basic machine learning tools for building feedforward fully-connected neural networks, with two APIs: one PyTorch-style, one TensorFlow-style (supported)

*: GPU tensors are not available yet, but GPU acceleration is planned to be added in the future

**: Numerical integration is supported out-of-the-box. However, the numerical differential equation solver has been (temporarily) moved to a separate library, elara-array, which is currently being developed in parallel.

elara-math is public domain software, meaning it is copyright-free, so you can use it for basically any project you want, however you want, with or without attribution.

Shoutouts: Acknowledgements

It is intended to both contain a set of ready-to-use solvers and vectorized math on NumPy-style N-dimensional arrays, as well as a flexible user-friendly API that can be used to make more specialized/advanced libraries for computational tasks.

Disclaimer

This repository hosts the original edition of the elara-math library. Please note that with our recent move to prioritizing MIT-licensed community edition libraries as our recommended avenue for open-source contributors (see elara-array-community, elara-gfx-community, and elara-math-community), contributors are strongly encouraged to send contributions to the community edition repositories. All original edition libraries will still be developed, but at a much, much slower pace. If you are a contributor, please only contribute to the original edition libraries if:

  1. You are okay dedicating your work to the public domain and thus making it un-copyrighted
  2. You accept that your work is likely not going to make it to the most actively-developed parts of Project Elara

We are aware that these are major dealbreakers for a plurality of developers, which is why the community editions exist in the first place. By being MIT-licensed and encouraged for contributors, there isn't as much of a hurdle/sacrifice involved in contributing. That being said, Project Elara's original edition libraries are still essential - they form the public domain core of the project, which we do believe tremendously in the value in. So if you are sure you want to dedicate your work to the public domain, go ahead and contribute here. Otherwise, send your contributions to the community edition of this library!

Demo

As an example, here is a working tiny neural network using elara-math and its companion library elara-log (elara-log is automatically installed when you install elara-math), ported from this excellent Python demo:

useelara_log::prelude::*;useelara_math::prelude::*;constEPOCHS: usize =10000;constLR: f64 =1e-5;fn forward_pass(data: &Tensor,weights: &Tensor,biases: &Tensor)-> Tensor{(&data.matmul(&weights)+biases).relu()}fn main(){// Initialize logging library
Logger::new().init().unwrap();lettrain_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]];lettrain_labels=tensor![[0.0],[1.0],[1.0],[0.0]].reshape([4,1]);letweights=Tensor::rand([3,1]);letbiases=Tensor::rand([4,1]);println!("Weights before training:\n{:?}",weights);forepochin0..(EPOCHS+1){letoutput=forward_pass(&train_data,&weights,&biases);letloss=elara_math::mse(&output,&train_labels);println!("Epoch {}, loss {:?}",epoch,loss);loss.backward();weights.update(LR);weights.zero_grad();biases.update(LR);biases.zero_grad();}letpred_data=tensor![[1.0,0.0,0.0]];letpred=forward_pass(&pred_data,&weights,&biases);println!("Weights after training:\n{:?}",weights);println!("Prediction [1, 0, 0] -> {:?}",pred);}

For more examples, including basic usage of tensors, using automatic differentiation, and building more complex neural networks, please feel free to see the examples folder.

Usage

To use elara-math for your own project, simply add it to your project with Cargo:

cargo add elara-math elara-log-ng

Then in your code, just import the library:

useelara_log::prelude::*;// this is required
useelara_math::prelude::*;// load prelude
fn main(){// Initialize elara-math's logging
// library first
Logger::new().init().unwrap();// rest of your code
// ...
}

The library's prelude is designed for user-friendliness and contains a variety of modules pre-loaded. For those who want finer-grained control, you can individually import the modules you need.

Bindings

Elara Math has experimental C/C++ bindings generated by cbindgen. The header file for the library is available in the bindings/ folder (elara_math.h).

An example is available in c_examples/autograd.c. It assumes you have first built the library with cargo build and have CMake installed.

⚠️ Right now, the C/C++ bindings are not yet functional due to NdArray and parts of the Rust standard library not having a stable ABI, which means that they are not supported by #[repr(C)]. We will continue to work on the bindings to bring them to usable readiness with time, but they cannot be used as of right now.

Developing

To develop elara-math, first clone the repository:

git clone https://codeberg.org/elaraproject/elara-math
git submodule update --init --recursive

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!

Contributors

  • Jacky Song
  • Jerry Teng