0% found this document useful (0 votes)
23 views

Rust For Numerical Programming - R - Rust

Rust is not as easy to code in as Python and its numerical programming library ecosystem is not as developed. However, Rust compiles to highly efficient code and has better support for multithreading than C++. While Rust may become more useful for numerical programming in the future, for current projects it may be better to stick with Python and use Cython or C++ for performance-critical code sections.

Uploaded by

tres pepitos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Rust For Numerical Programming - R - Rust

Rust is not as easy to code in as Python and its numerical programming library ecosystem is not as developed. However, Rust compiles to highly efficient code and has better support for multithreading than C++. While Rust may become more useful for numerical programming in the future, for current projects it may be better to stick with Python and use Cython or C++ for performance-critical code sections.

Uploaded by

tres pepitos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

9/7/23, 5:59 Rust for Numerical Programming : r/rust

r/rust Search Community Iniciar sesión

r/rust • hace 1 a
Unirse
por attofreak

Rust for Numerical Programming


I have not tried Rust before, but after the news about Carbon from Google began circulating, I was interested
in knowing whether that language is fit for numerical programming, with more flexibility and memory safety. I
am not a computer science professional or programmer in the sense of the backend professionals etc. Just use
programming languages for numerical calculations and simulations in Physics.

Looking around for Carbon (there wasn't much about numerical programming), I came across Rust a couple of
times. At some point, there was this paper comparing different languages for "carbon footprint" or efficiency
metric of some sort. C was at top, of course, with a metric of "1" (maybe the reference metric for all other
languages). Rust was at 1.03. Every other language came after that, and the "high level" languages like Python,
MATLAB, Java, all had double-digit metrics. So very slow/inefficient/large carbon footprint.

Is Rust "easy" to code in, as in Python? Or does it have a well-developed suite of libraries for numerical
computations (e.g. Linear Algebra, Integration, Optimisation, Parallelisation, GPU/CUDA support)? Will it be

20 11 Compartir

Ordenar por: Mejores 11 comentarios

Añadir un comentario

mbecks • hace 1 a

The numerical ecosystem isn't as advanced as python. There are still some good numerics crates, but
whether you could easily port your projects from python depends on the python tools you are using and
whether you could find a suitable replacement. I know that there are plenty of crates relating to physics
simulation to check out. Some of them can be pretty hard to use / find good enough examples for so it
usually takes more time than it would for python.

In terms of ease, you do have to think about memory management more when coding in rust. On the plus
side you have more control over how the application handles multithreading, and basic multithreading is
made pretty easy. Also things that compile tend to work, and when they don't compile the message is
usually helpful. I remember in the beginning, some seemed cryptic but then there's google.

good luck and happy programming


23 Responder Compartir

attofreak • hace 1 a

Thanks, that was quick and answered all my questions. I guess I should stick to Python, there is not
much time with projects to spend on a new language. I might have to deal with C++ for gaining speed
when needed (Cython etc.), and that is already extra work enough. Maybe Rust will become more
useful to user-side numerical programming in coming years.

https://www.reddit.com/r/rust/comments/w7blge/rust_for_numerical_programming/ 1/7
9/7/23, 5:59 Rust for Numerical Programming : r/rust

5 Responder Compartir
Iniciar sesión
1 respuesta más

jpet • hace 1 a

I've done lots of numerical programming in C++ and Python, and some in Rust.

Pros:

The language is excellent for writing high-performance code, including numerical libraries.
Some excellent libraries like nalgebra
Library ecosystem works much better than in C++. If you want to use a third-party dependency, just
use it. Vs. C++ where no matter how sophisticated the library is, it's often easier to just rewrite it
yourself than get another third-party dependency working.
Libraries are also more interoperable, partly due the community (e.g. lib authors agreeing on
common shared libs for basic vocabulary types), and partly due to the language ( transmute , similar
to C++'s reinterpret_cast , allows you to legally cast e.g. &lib1:Mat4x4 to &lib2:Mat4x4 , as
long as the layouts match. In C++ that's undefined behavior, so using multiple libs often means a
bunch of expensive conversions that are semantically no-ops but can't be removed).
Rust's lifetime system isn't just for memory safety! It also helps avoid bugs when you're using e.g.
lots of views into matrices, and don't want to accidentally change the data out from underneath.

Cons:

Still not as many third-party numerics libs as C++, and *way* fewer than Python.
Rust makes the syntax clunky compared to either C++ (e.g. with Eigen or Ceres) or Python (numpy et
al). Your code will be littered with clone() calls, array indexing is too limited (by the language) to
return things like submatrix views so you can't have nice syntax like numpy, etc.
17 Responder Compartir

attofreak • hace 1 a

Thanks for your input, it always helps to know more from someone with a lot of experience. I will keep
watching how Rust community evolves, it seems very promising and a good middle ground between
C/C++ and Python. Will have to get rid of the clunky syntax!

There was this article, talking about Rust as a numerical programming tool, and it says something
peculiar:

You can’t use Rust arrays to represent a matrix bigger than 4x8, how useful is that?

It seems to be related to this clone() call, and clone -ing arrays is a very difficult/complicated
process?

Python modules seem to work very well with each other. At least the big ones, numpy , scipy ,
pandas , stats , cupy even (with special functions to convert to/from numpy arrays). If I combine
that with Cython and jit-type vectorisation, will it be sufficient enough? Or is C++ something one
should fall back on, when looking for efficient/high speed numerical computing? We are reaching limits
with Python, takes days sometimes (even with numpy/cupy), so I have been wondering if it would help
to finally move to C++, or wrestle with Cython directly?
3 Responder Compartir

https://www.reddit.com/r/rust/comments/w7blge/rust_for_numerical_programming/ 2/7
9/7/23, 5:59 Rust for Numerical Programming : r/rust

3 respuestas más
Iniciar sesión

g4nt1 • hace 1 a

I’d look into https://dimforge.com/

Clearly harder to get started than the much more mature python numerical programming ecosystem
6 Responder Compartir

[eliminado] • hace 1 a

So you can contextualize my answer/opinion (take it with a grain of salt): I have 10 years of experience in
Python and Matlab, ~3 years of experience with C/C++, and a few weeks of experience with Rust.

It feels to me like coding in Rust is about as "hard" as C or C++. Probably easier than C++ because you
don't have 30 years of conflicting standards/versions all stacked on top of each other and used in hideous
combination in the same codebase (cough cough openfoam). You definitely will not find it "easy" to
migrate py3 codebases to Rust. In many cases it would be impossible without re-implementing a bunch of
python packages you are using - in most cases for numerical programming, an enormous undertaking.

With respect to the carbon footprint of Python vs C vs Rust: if you are using Python properly you are
doing most of your computations within some other library that is most likely written in C. For example if
you'e using numpy and you vectorize your operations properly, and you aren't implementing algorithms
yourself in standard Python, you're effectively "using C" but with a Python wrapper. So from a carbon
footprint perspective you should think about how much of your computations are actually being done "by
Python" vs by a package that is mostly a C extension. Your programs probably are not actually 100x less
efficient than they would be if you reimplemented everything in C, and if they are, likely you could reduce
your carbon footprint by optimizing your Python code with a much better "ROI" than by fully migrating to
C or Rust.
3 Responder Compartir

attofreak • hace 1 a

I try to be as "Pythonic" as I can. Sometimes have to use for loops, but I try to parallelise those in
multiprocessing too, where possible. With the decorators from Cython, I can perhaps further cut
down time wasted in checking data types. Python is pretty great in simplifying the clutter of low-level
programming languages.
2 Responder Compartir

Más publicaciones que te podrían gustar

Relacionado Rust Programming

r/rust

Higher level languages over Rust?


10 upvotes · 10 comentarios

r/learnprogramming

https://www.reddit.com/r/rust/comments/w7blge/rust_for_numerical_programming/ 3/7
9/7/23, 5:59 Rust for Numerical Programming : r/rust

Looking for suggestions for programming languages ​based on these conditions


Iniciar sesión
2 upvotes · 18 comentarios

https://www.reddit.com/r/rust/comments/w7blge/rust_for_numerical_programming/ 4/7
9/7/23, 5:59 Rust for Numerical Programming : r/rust

r/bioinformatics
Iniciar sesión
Does Rust's performance advantage over python extend to numpy/pandas?
28 upvotes · 15 comentarios

r/cpp

Anchors: C++ library for self-adjusting computations


21 upvotes · 7 comentarios

r/dataanalysis

Which language (R / Python) has better libraries for working with Excel?
5 upvotes · 7 comentarios

r/rust

Pixelate images - an intro to Rust and the image crate

youtu.be
129 upvotes · 11 comentarios

r/rust

Choose the Right Option

youtube
153 upvotes · 13 comentarios

r/rust

Using Arc<[T]> instead of Vec<T>


314 upvotes · 95 comentarios

r/rust

Regex engine internals as a library


326 upvotes · 25 comentarios

r/rust

10~17x faster than what? A performance analysis of Intel' x86-simd-sort (AVX-512)


345 upvotes · 28 comentarios

r/rust

[Media] Self driving car simulation - Road Fighter AI (code in comments)


156 upvotes · 11 comentarios

https://www.reddit.com/r/rust/comments/w7blge/rust_for_numerical_programming/ 5/7
9/7/23, 5:59 Rust for Numerical Programming : r/rust

r/rust
Iniciar sesión
Announcing regex-lite (similar to the regex crate, but more lightweight)
116 upvotes · 24 comentarios

r/rust

Festival v1.0.0 - A music player


178 upvotes · 25 comentarios

r/rust

Finished building a working Game Boy Color emulator using Rust and WebAssembly 🎮🕹️
383 upvotes · 31 comentarios

r/rust

I Made a RISC-V Computer Inside Terraria that runs Rust Code!


1,1 mil upvotes · 64 comentarios

r/rust

Vec<T> internally uses RawVec<T>, which internally uses Unique<T>. Unique is a nightly feature, so why
isn't Vec only available for nightly builds?
356 upvotes · 61 comentarios

r/rust

A walkthough on how to write derive procedural macros


130 upvotes · 23 comentarios

r/rust

Announcing Velo - Your Rust-Powered Brainstorming and Note-Taking Tool


237 upvotes · 31 comentarios

r/rust

Observing your rust application with tracing


161 upvotes · 20 comentarios

r/rust

This Week in Rust # 500!!


208 upvotes · 18 comentarios

r/rust

Alternative Rust Discussion Venues


437 upvotes · 256 comentarios

https://www.reddit.com/r/rust/comments/w7blge/rust_for_numerical_programming/ 6/7
9/7/23, 5:59 Rust for Numerical Programming : r/rust

r/rust
Iniciar sesión
Fyrox Game Engine 0.30
146 upvotes · 34 comentarios

r/rust

Talk about Undefined Behavior, unsafe Rust, and Miri


118 upvotes · 47 comentarios

r/rust

Leveraging Heap Profiling and tokio-console to Pinpoint Rust Memory Leak Issue
136 upvotes · 5 comentarios

r/rust

[media] Czkawka 6.0 - File cleaner, now finds similar audio files by content, files by size and name and fix
and speedup similar images search
130 upvotes · 7 comentarios

https://www.reddit.com/r/rust/comments/w7blge/rust_for_numerical_programming/ 7/7

You might also like