6 ms·
The author is I think being a bit unfair to C++ when it comes to matrix/array handling. Their example of things that would be difficult to do in C/C++: A = B
by radioactivist 10y ago
The author is I think being a bit unfair to C++ when it comes to matrix/array handling. Their example of things that would be difficult to do in C/C++:
A = B
A = 3.24 * B
C = A * B
B = exp(A)
norm = sqrt(sum(A * * 2))
Quoting:
"Similar C/C++ code simply does not exist ... Having to use libraries instead of intrinsic functions means the resulting code is never as neat, as transferable, or as easy to learn."
While this statement is true, I think strongly undersells how well these kinds of libraries can be "baked" into C++ through operator overloading, templating, etc. See for example, the Eigen library [http://eigen.tuxfamily.org/ http://eigen.tuxfamily.org/].
- deleted 10y ago[deleted]
- m_mueller 10y agohere's the problem: These kind of libraries will never come close touching Fortran's built-in features, simply because the compiler can't automatically optimise for knowledge about the code that only the library has. Even arrays not knowing their size is still an issue, let alone array based ops like shown in the article. Fortran is not the fastest language around the block, but if you don't want to go into non-portable machine-based hand-tuned optimisations (e.g. loop unrolling) it's hard to beat. Basically, if you optimise for both runtime and programmer time for HPC applications I'd argue that Fortran is top of the crop.
- radioactivist 10y agoWell, in the case of Eigen it's an entirely header based library, so the compiler can optimize some things. Not to mention the template based meta-programming strategies [1] Eigen itself uses to simplify and optimize during compilation (including vectorization and loop unrolling). The fact that this kind of infrastructure can be built up in a library in C++, i.e. it doesn't have to be baked into the compiler, is a huge plus I think relative to Fortran. [1] https://eigen.tuxfamily.org/dox/TopicInsideEigenExample.html https://eigen.tuxfamily.org/dox/TopicInsideEigenExample.html
- whyever 10y agoI don't think this is true. C++ matrix template libraries are competitive with anything that Fortran can do.
- pbsd 10y agoNot to mention all of that array behavior is available on the standard C++ library with std::valarray<T>, e.g., https://godbolt.org/g/JBSvuH https://godbolt.org/g/JBSvuH. There was talk of a more thorough standard multi-dimensional array type, but I have no idea what's the status on that.
- sampo 10y agoGotta admit that array slicing syntax is still friendlier in Fortran a = [1,2,3,4,5,6] a(1:3) ! gives [1,2,3] than with std::valarray a = {1,2,3,4,5,6}; a[slice(0,3,0)]; // gives {1,2,3} And I couldn't even find examples on how to do slicing with multi-dimensional arrays in std::valarray? In Fortran it's just a(1:3,1:3)
- pbsd 10y agostd::valarray does not have multidimensional support at all. In fact, std::valarray is a relatively abandoned part of the standard library. You'll have to go with one of the 3rd party libraries for better support. My point was not so much that valarray is awesome, but that articles like this one tend to fight a very strawman version of C++, even when just sticking to strictly standard components.
- KKKKkkkk1 10y agoIf anything, saying that C++ has no support for linear algebra is giving it too much credit. C++ has an abundance of libraries that are broken in various strange and marvelous ways. Typically, you find out about the brokenness only after you made the investment of learning the library and put it into production, so that there is no way back. Your comment about valarray is a good example of this.
- pbsd 10y agoThat's a criticism I'm entirely on board with, and is not limited to linear algebra libraries. HTTP client libraries are worse, there's not a single good one.