Skip to main content

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.pdf for details.
  • See rust_generated/src/sym/*.rs for sample generated code.

Support

Supported linear algebra crate

  • nalgebra, returns a matrix (including row and column vectors, which share the underlying type nalgebra::SMatrix)
  • faer, passes in a mutable slice of matrix and modifies it.
    • Both Row, Col and Mat are supported.
  • 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

  1. Some functions are ambiguous (for example, sign). Please refer to documentation for their semantics.
  2. Please handle NaN and inf carefully by yourself.
  3. We don't do indent/format. cargo fmt do it for us.
  4. Generated function has parameters in lexicographical order of identifiers (default in sortedcontainers).
  5. 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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

symars-0.0.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

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

Hashes for symars-0.0.1.tar.gz
Algorithm Hash digest
SHA256 622c7eae9a467042bcdcc560b164b70c628560d9fde6b7478639f1b047bb3b21
MD5 7a22fcc7ffd77bebd8f71c6030f090ce
BLAKE2b-256 4fd41f4845dcaeb356465f816039d6526048beb4ecdfd0de65fed8ce16370fbd

See more details on using hashes here.

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

Hashes for symars-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a43b9f758904915e67209f4e7c3b1b569c85a8a8d5c8c261fe7beca0ec018b0f
MD5 ccc633c189651a21a77bcaf735973101
BLAKE2b-256 b002c55601bdcfe1b5046e9f797da3da9a1c33d1d42279ccd442d5d114882f86

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page