rust-numpy
setuptools-rust
Our great sponsors
rust-numpy | setuptools-rust | |
---|---|---|
10 | 5 | |
1,015 | 557 | |
5.1% | 1.4% | |
6.7 | 8.6 | |
9 days ago | 25 days ago | |
Rust | Python | |
BSD 2-clause "Simplified" License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
rust-numpy
-
Numba: A High Performance Python Compiler
On the contrary, it can use and interface with numpy quite easily: https://github.com/PyO3/rust-numpy
- Carefully exploring Rust as a Python developer
-
Hmm
Once I figured out the right tools, it was easy. Its just "maturin new". It automatically converts python floats and strings. Numpy arrays come through as a special Pyarray type, that you need to unwrap, but that's just one builtin function. Using pyo3, maturin and numpy, https://github.com/PyO3/rust-numpy it's fairly easy.
-
Man, I love this language.
If I'm understanding this documentation correctly then you may be able to pass the numpy array directly with func(df['col'].to_numpy) which may save some conversion.
-
[D] Is Rust stable/mature enough to be used for production ML? Is making Rust-based python wrappers a good choice for performance heavy uses and internal ML dependencies in 2021?
Otherwise, though, Rust is an excellent choice. The many advantages of Rust (great package manager, memory safety, modern language features, ...) are already well documented so I won't repeat them here. Specifically for writing Python libraries, check out PyO3, maturin, and rust-numpy, which allow for seamless integration with the Python scientific computing ecosystem. Dockerizing/packaging is a non-issue, with the aforementioned libraries you can easily publish Rust libraries as pip packages or compile them from source as part of your docker build. We have several successful production deployments of Rust code at OpenAI, and I have personally found it to be a joy to work with.
-
Writing Rust libraries for the Python scientific computing ecosystem
Integration with numpy uses the rust-numpy crate: Example of method that accepts numpy arrays as arguments Example of a method that returns a numpy array to Python (this performs a copy, there ought to be a way to avoid it but the current implementation has been plenty fast for my use case so far)
-
Feasibility of Using a Python Image Super Resolution Library in My Rust App
This example maybe helpful.
-
Julia is the better language for extending Python
Given that it's via pyO3, you could even pass the numpy arrays using https://github.com/PyO3/rust-numpy and get ndarrays at the other side.
Same no copy, slightly more user friendly approach.
Further criticism of the actual approach - even if we didn't do zero copy, there's no preallocation for the vector despite the size being known upfront, and nested vectors are very slow by default.
So you could speed up the entire thing by passing it to ndarray, and then running a single call to sum over the 2D array you'd find at the other end. (https://docs.rs/ndarray/0.15.1/ndarray/struct.ArrayBase.html...)
-
Parsing PDF Documents in Rust
I believe converting between pandas Series (e.g. columns) and numpy ndarrays can be pretty cheap, right? Once they're in that format, you can use rust to work directly on the numpy memory buffer with rust-numpy. Otherwise, feather is a format designed for IPC of columnar data; pyarrow is in pandas (might be an optional dependency) and may be pretty quick for that, and rust has an arrow implementation too.
-
PyO3: Rust Bindings for the Python Interpreter
https://github.com/PyO3/rust-numpy
setuptools-rust
-
How do i go about building a vidoe conferencing app?
For Python specifically, In addition to using rust-cpython or PyO3, maturin makes it really comfortable to build, package, and publish Rust code into Python packages and, if your niche doesn't quite fit, there's setuptools-python which might do it.
-
Python extensions in Rust
Aside from the PyO3 and rust-cpython crates already mentioned, I'd suggest maturin as a way to integrate your build processes or possibly setuptools-rust.
-
Good use cases for Rust? I'm trying to find a reason to use Rust
Compiled modules for Python stuff (I'd recommend PyO3 but the last one I started was before that worked on stable Rust, so I used its progenitor, rust-cpython. See also maturin or setuptools-rust).
-
Can someone help me understand PyO3? I'm not sure how it works.
...but you will need to rename the generated library to match import conventions. setuptools-rust or Maturin can help with that.
-
PyO3: Rust Bindings for the Python Interpreter
Between pyodide, pyo3, rust-cpython, and rustpython, I think Pyo3 is the best way to drop in rust in a python project for a speed up, if that is your goal. Some of the demos show using python from rust, but to me the biggest feature is without a doubt compiling rust code to native python modules. I'm using it to speed up image manipulation backed by numpy arrays.
There’s a setuptools rust [0] extension package that can be used to hook the compilation of the rust into the wheel building or install from source. Maturin [1] seems to be regarded as the new and improved solution for this, but I found that it’s angled toward the using python from rust.
There’s also the rust numpy [2] package by the same org which is fantastic in that it lets you pass a numpy matrix to a native method written in rust and convert it to the rust equivalent data structure, perform whatever transformation you want (in parallel using rayon [3]), and return the array. When building for release, I was seeing speed ups of 100x over numpy on the most matrix mathable function imaginable, and numpy is no joke.
I think there is a lot of potential for these two ecosystems together. If there’s not a python package for something, there’s probably a rust crate.
If anyone is interested the python package that I'm building with some rust backend, its called pyrogis [4] for making custom image manipulations through numpy arrays.
https://github.com/PyO3/setuptools-rust
What are some alternatives?
RustPython - A Python Interpreter written in Rust
maturin - Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python packages
julia - The Julia Programming Language
pybind11 - Seamless operability between C++11 and Python
polars - Dataframes powered by a multithreaded, vectorized query engine, written in Rust
tokenizers - 💥 Fast State-of-the-Art Tokenizers optimized for Research and Production
rayon - Rayon: A data parallelism library for Rust
winsafe-examples - Examples of native Windows applications written in Rust with WinSafe.
image-super-resolution - 🔎 Super-scale your images and run experiments with Residual Dense and Adversarial Networks.
opencv-python - Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.
PyO3 - Rust bindings for the Python interpreter
json - Strongly typed JSON library for Rust