Generate Rust code with Sympy, for both scalars and matrices.
Project description
Symars
Generate Rust code from SymPy expressions, including matrices.
Requirements
sympy
sortedcontainers
Use
pip install .- See
examples.ipynb. - Refer to
docs/user_docs.pdffor details. - See
rust_generated/src/sym/*.rsfor sample generated code.
Support
Supported linear algebra crate
nalgebra, returns a matrix (including row and column vectors, which share the underlying typenalgebra::SMatrix)faer, passes in a mutable slice of matrix and modifies it.- Both
Row,ColandMatare supported.
- Both
- Built-in array
[f32; N]and[f64; N]for vector. - Sparse matrix with its triplet representation stored in
Vec<(usize, usize, value_type)>.
If you want to support your own linear algebra crate, refer to
nalgebra.py.
Supported data types
f32, f64
Supported operations
+ - * /
powf, sqrt
powi // only for constant integers
sin, cos, tan, cot, asin, acos, atan2
sinh, cosh, tanh, asinh, acosh, atanh
exp, exp2
floor, ceil // behavior of frac is different in rust and sympy.
ln // sp.log(x)
log // sp.log(x, base)
min, max // sp.Min, sp.Max; note to use only for normal numbers (not inf, nan)
signum // sp.sign
abs
Note
- Some functions are ambiguous (for example,
sign). Please refer to documentation for their semantics. - Please handle NaN and inf carefully by yourself.
- We don't do indent/format.
cargo fmtdo it for us. - Generated function has parameters in lexicographical order of identifiers (default in
sortedcontainers). - If you are using rust-analyzer VSCode extension, try to put your numerical computation code in a crate different from your driver code, especially when the code exceeds say, 10000 lines. Otherwise, your rust-analyzer may hang often.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
symars-0.0.1.tar.gz
(9.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
symars-0.0.1-py3-none-any.whl
(11.8 kB
view details)
File details
Details for the file symars-0.0.1.tar.gz.
File metadata
- Download URL: symars-0.0.1.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
622c7eae9a467042bcdcc560b164b70c628560d9fde6b7478639f1b047bb3b21
|
|
| MD5 |
7a22fcc7ffd77bebd8f71c6030f090ce
|
|
| BLAKE2b-256 |
4fd41f4845dcaeb356465f816039d6526048beb4ecdfd0de65fed8ce16370fbd
|
File details
Details for the file symars-0.0.1-py3-none-any.whl.
File metadata
- Download URL: symars-0.0.1-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a43b9f758904915e67209f4e7c3b1b569c85a8a8d5c8c261fe7beca0ec018b0f
|
|
| MD5 |
ccc633c189651a21a77bcaf735973101
|
|
| BLAKE2b-256 |
b002c55601bdcfe1b5046e9f797da3da9a1c33d1d42279ccd442d5d114882f86
|