3 ms·
Numpy is often faster because it’s often using highly optimized simd, or makes use of BLAS/Fortran/LAPACK/MKL/CuBLAS implementations. A pure rust implementatio
by dagmx 4y ago
Numpy is often faster because it’s often using highly optimized simd, or makes use of BLAS/Fortran/LAPACK/MKL/CuBLAS implementations.
A pure rust implementation will likely always be slower by virtue of not using the same tightly designed optimized code.
Side note: A fun implementation detail of numpy is that after you install it from pypi, it does a user side compile of some of the modules on first import. Which means you need to be somewhat careful if you ever relocate an install of it to a new machine
- orlp 4y agoAnd note that for example on Apple M1 it's essentially impossible to beat an implementation that uses Apple's Accelerate library for things like matrix multiplication, because Apple uses undocumented instructions unavailable to the public in that library.
- orangepurple 4y agoDeprecated since version 1.20: The native libraries on macOS, provided by Accelerate, are not fit for use in NumPy since they have bugs that cause wrong output under easily reproducible conditions. If the vendor fixes those bugs, the library could be reinstated, but until then users compiling for themselves should use another linear algebra library or use the built-in (but slower) default, see the next section. Source: https://numpy.org/doc/stable/user/building.html https://numpy.org/doc/stable/user/building.html
- dagmx 4y agoAdded back the very next release https://numpy.org/doc/stable/release/1.21.0-notes.html https://numpy.org/doc/stable/release/1.21.0-notes.html > With the release of macOS 11.3, several different issues that numpy was encountering when using Accelerate Framework’s implementation of BLAS and LAPACK should be resolved.
- remram 4y agoInteresting! Using what compiler?
- dagmx 4y agoI believe it looks to see what’s available and otherwise falls back to less efficient implementations.
- the8472 4y agoIf numpy uses runtime detection of available SIMD instructions while rust is only compiled with the x86-64 baseline (which only includes SSE2) then compiling the module with `RUSTFLAGS=-Ctarget-cpu=native` might provide some additional performance gains on number-crunchy code.