Comment on Compiling typed Python: types are very broad hints and they are sometimes lies.
UlrikHD@programming.dev 1 year agoInteresting stuff, might give me an excuse to look into rust in the future. Thanks!
Comment on Compiling typed Python: types are very broad hints and they are sometimes lies.
UlrikHD@programming.dev 1 year agoInteresting stuff, might give me an excuse to look into rust in the future. Thanks!
Turun@feddit.de 1 year ago
I personally did one project with PyO3 and it was a breeze.
For data analysis I initially implemented my physics model in python (say f=m*a), but during a fitting procedure (what is “a”, given a measured “m” and “f”?) this part of the code is called thousands of times.
Writing such a simple function is rust (twi numbers in (m and a guess for a), one number out (predicted f)) was easy. Since there are no complex data structures involved the borrow checker was happy the whole way through. Rust has bindings for numpy with the ndarray crate/library, so even that was simple.
Simply writing the numerics in rust gave a 40x speedup in my case. I got another 2.5x by making the main loop of my calculation parallel. With the rayon crate this is again a single line change, turning
for x in array {…}
intofor x in array.par_iter() {…}