-
Notifications
You must be signed in to change notification settings - Fork 27
Description
Remove [linalg] from C++26?
FR-029-273 29.9 [linalg] Remove linalg from C++26 says:
Special math functions were added in the standard with the justification they were hard to implement and the expectation was that standard libraries maintainers would be the most qualified to do that work for the benefit of a small number of C++ users. But because standard library maintainers are not domain experts in all domains, and because their time is limited and their resources scarce....
(NVIDIA has an optimized implementation, btw)
Distinguish
- time / effort
- expertise
Everything requires time and effort. Special math functions require mathematical expertise.
Prof. Kahan (of IEEE 754 fame) circa 2004: the world creates one numerical analyst a year.
BLAS was designed as part of a separation of concerns between performance engineers and numerical analysts. I explained this in detail in my CppCon 2023 talk.
Special math function example: fast inverse square root
Depends on knowledge of
- classical methods for approximating functions of real or complex numbers
- floating-point representation on computers
- computer hardware, e.g., relative performance of different instructions
Example of (1): Newton's method, a classical iteration
float Q_rsqrt(float number) {
constexpr float threehalfs = 1.5f;
float x2 = number * 0.5f;
float y = number;
std::int32_t i = std::bit_cast<std::int32_t>(y);
i = 0x5f3759df - (i >> 1); // approx 1/sqrt
y = std::bit_cast<float>(i);
y = y * (threehalfs - (x2 * y * y)); // Newton's method, 1st iteration
y = y * (threehalfs - (x2 * y * y)); // optional 2nd iteration
return y;
}Special math function example: Bessel functions of the first kind
Solutions of the following differential equation:
that "describe[s] the radial part of vibrations of a circular membrane":
BLAS example
Matrix-matrix multiply:
That's it! Normal plus and times! Elementary school math!
