5 ms·
I wonder why not just try to use more Pythonic solutions such as numba within scipy. I realize that maybe not in all cases can the same performance as Fortran
by radarsat1 3y ago
I wonder why not just try to use more Pythonic solutions such as numba within scipy. I realize that maybe not in all cases can the same performance as Fortran be achieved but it strikes me as much more hackable for Python programmers than having to learn an new (old) language just for certain core algorithms. One of the principal reasons for switching to C implementations is because more people understand C than Fortran. This seems doubly true for Python-based jit solutions like numba or jax, so why not just skip C altogether and go for a more native port?
- adastra22 3y agoNumpy is Fortran btw.
- remram 3y agoFrom numpy.org: > The core of NumPy is well-optimized C code.
- taeric 3y agoAmusingly, "well-optimized C code" includes calling out to fortran libraries. :D https://numpy.org/doc/1.13/user/building.html https://numpy.org/doc/1.13/user/building.html
- cfcf14 3y agoIt's turtles all the way down, except for the final turtle, which is Fortran...
- bee_rider 3y agoThe last turtle is probably assembly, or at least intrinsics, in most good BLAS implementations. Probably called from C, because that’s easier in C. The nice thing about Fortran is that you get something almost as good, but a normal engineer can write it. There are more C programmers than Fortran programmers, but there are more Fortran programmers than there are C programmers who can write really good assembly kernels. And all the C programmers in that last group are already working on vendor BLAS implementations.
- whimsicalism 3y agoThat's a 6 year old documentation page, modern numpy does not use fortran in any way except that maybe you have a particular BLAS reference implementation.
- adastra22 3y agoNumpy is basically a wrapper to BLAS and LAPACK though, so it seems a bit odd to ignore the fact that those system libraries are usually written in Fortran.
- whimsicalism 3y agoThe reference implementation is written in Fortran, but I'm not sure about the implementations actually used. OpenBLAS has fortran components, but I believe cuBLAS and MKL are vast majority C/C++.
- taeric 3y agoThis is a very fair challenge. My understanding was that the main ones in use were fortran and it is very interesting to see that may not be the case. Love to see any benchmark or other comparisons on the options, if you know of any good links.
- adastra22 3y agocuBLAS is not Fortran because it targets NVIDIA GPUs. Despite what the grandparent says, MKL does include some Fortran in its codebase. Most other vendor-provided BLAS and LAPACK libraries are based on the reference Fortran implementation. Even OpenBLAS, the open-source reimplementation, has large parts written in Fortran.
- taeric 3y agoI did link to the old one.... but if you follow the link to the new, it still has that section? I'm confused.
- milancurcic 3y agoThe well-optimized part is C calling Fortran. :)
- whimsicalism 3y agono?
- taeric 3y agoIf you are using any of the faster libraries for it, it is? Right?
- whimsicalism 3y agoI don't believe that numpy requires any fortran [0] and most BLAS implementations are not written in Fortran either. [0]: https://github.com/search?q=repo%3Anumpy%2Fnumpy+path%3A**%2F*.f&type=code&ref=advsearch https://github.com/search?q=repo%3Anumpy%2Fnumpy+path%3A**%2...
- adastra22 3y agoMost BLAS and LAPACK implementations are written in Fortran. There are some C/C++ alternatives, but those are the exceptions (even if some are widely used in the FOSS community) and they still don’t benchmark as well even in 2023.
- whimsicalism 3y agocuBLAS benchmarks pretty well :) but sure, I am not super familiar with the state of CPU BLAS frameworks so I will take your word for it.
- bee_rider 3y agoThe good BLAS libraries are MKL and BLIS nowadays, I’m pretty sure. BLIS is C and assembly if I remember correctly. MKL is a big library, Wikipedia lists the languages used as C, C++, Fortran, and I think it is also pretty well known that they’ve sprinkled some magic assembly in there.
- 3y ago
- deleted 3y ago[deleted]
- bee_rider 3y agoNumpy is most importantly BLAS and LAPACK, which can be implemented in any language. The best CPU version is probably still MKL, which is a mix of Fortran, C, and assembly. C is used for these kinds of projects because it is easy to sprinkle assembly into C. Fortran solves a particular problem: produce a pretty good binary from readable code that a normal PHD student or engineer can write. This is not really the problem that a tuned BLAS/LAPACK library has to face, vendors throw very experienced folks at these libraries to chase after those last 5% performance boosts that Fortran leaves on the table.
- zaikunzhang 3y agoA native port is indeed planned. However, since we are talking about a project of about 10K lines of code (though many of the lines are comments), such a port will not be delivered very soon. In fact, native implementations of PRIMA in Python, MATLAB, C++, Julia, and R will all be done in the future. See https://github.com/libprima/prima#other-languages https://github.com/libprima/prima#other-languages . But they will take time. PRIMA has been a one-man project since it started three years ago. Community help is greatly needed. Thanks.