Basic linear algebra algorithms (since C++26)
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Numerics library
Interpolations
Generic numeric operations
C-style checked integer arithmetic
Mathematical special functions (C++17)
Mathematical constants (C++20)
Basic linear algebra algorithms (C++26)
Data-parallel types (SIMD) (C++26)
Floating-point environment (C++11)
Bit manipulation (C++20)
Saturation arithmetic (C++26)
(C++17)
(C++17)
(C++20)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++26)
Basic linear algebra algorithms
Basic linear algebra algorithms are based on the dense Basic Linear Algebra Subroutines (BLAS) which corresponds to a subset of the BLAS Standard. These algorithms that access the elements of arrays view those elements through std::mdspan representing vector or matrix.
The BLAS algorithms are categorized into three sets of operations called levels, which generally correspond to the degree of the polynomial in the complexities of algorithms:
- BLAS 1: All algorithms with std::mdspan parameters perform a count of std::mdspan array accesses and arithmetic operations that are linear in the maximum product of extents of any std::mdspan parameter. These algorithms contain vector operations such as dot products, norms, and vector addition.
- BLAS 2: All algorithms have general complexity in quadratic time. These algorithms contain matrix-vector operations such as matrix-vector multiplications and a solver of the triangular linear system.
- BLAS 3: All algorithms have general complexity in cubic time. These algorithms contain matrix-matrix operations such as matrix-matrix multiplications and a solver of the multiple triangular linear systems.
Contents
In-place transformations
Defined in header
<linalg>
Defined in namespace
std::linalg
(C++26)
(class template) [edit]
(C++26)
(class template) [edit]
(C++26)
(class template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
BLAS 1 functions
Defined in header
<linalg>
Defined in namespace
std::linalg
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
BLAS 2 functions
Defined in header
<linalg>
Defined in namespace
std::linalg
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
BLAS 3 functions
Defined in header
<linalg>
Defined in namespace
std::linalg
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(C++26)
(function template) [edit]
(function template) [edit]
Helper items
Defined in header
<linalg>
Defined in namespace
std::linalg
(tag)[edit]
(tag)[edit]
(tag)[edit]
(C++26)
(class template) [edit]
[edit] Notes
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_linalg |
202311L |
(C++26) | Basic linear algebra algorithms (BLAS) |
[edit] Example
Run this code
#include <cassert> #include <cstddef> #include <execution> #include <linalg> #include <mdspan> #include <numeric> #include <vector> int main() { std::vector <double> x_vec(42); std::ranges::iota (x_vec, 0.0); std::mdspan x(x_vec.data(), x_vec.size()); // x[i] *= 2.0, executed sequentially std::linalg::scale (2.0, x); // x[i] *= 3.0, executed in parallel std::linalg::scale (std::execution::par_unseq, 3.0, x); for (std::size_t i{}; i != x.size(); ++i) assert (x[i] == 6.0 * static_cast<double>(i)); }