Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      Basic linear algebra algorithms(since C++26)

      From cppreference.com
      <cpp‎ |numeric
       
       
       
      Basic linear algebra algorithms
       

      Basic linear algebra algorithms are based on the dense Basic Linear Algebra Subroutines (BLAS) which corresponds to a subset of theBLAS Standard. These algorithms that access the elements of arrays view those elements throughstd::mdspan representing vector or matrix.

      The BLAS algorithms are categorized into three sets of operations calledlevels, which generally correspond to the degree of the polynomial in the complexities of algorithms:

      • BLAS 1: All algorithms withstd::mdspan parameters perform a count ofstd::mdspan array accesses and arithmetic operations that arelinear in the maximum product of extents of anystd::mdspan parameter. These algorithms containvector operations such as dot products, norms, and vector addition.
      • BLAS 2: All algorithms have general complexity inquadratic time. These algorithms containmatrix-vector operations such as matrix-vector multiplications and a solver of the triangular linear system.
      • BLAS 3: All algorithms have general complexity incubic time. These algorithms containmatrix-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 namespacestd::linalg
      std::mdspan accessor policy whose reference represents the product of a scaling factor that is fixed and its nestedstd::mdspan accessor's reference
      (class template)[edit]
      std::mdspan accessor policy whose reference represents the complex conjugate of its nestedstd::mdspan accessor's reference
      (class template)[edit]
      std::mdspan layout mapping policy that swaps the rightmost two indices, extents, and strides of any unique layout mapping policy
      (class template)[edit]
      (C++26)
      returns a new read-onlystd::mdspan computed by the elementwise product of the scaling factor and the corresponding elements of the givenstd::mdspan
      (function template)[edit]
      (C++26)
      returns a new read-onlystd::mdspan whose elements are the complex conjugates of the corresponding elements of the givenstd::mdspan
      (function template)[edit]
      (C++26)
      returns a newstd::mdspan representing the transpose of the input matrix by the givenstd::mdspan
      (function template)[edit]
      returns a conjugate transpose view of an object
      (function template)[edit]

      BLAS 1 functions

      Defined in header<linalg>
      Defined in namespacestd::linalg
      generates plane rotation
      (function template)[edit]
      applies plane rotation to vectors
      (function template)[edit]
      swaps all corresponding elements of matrix or vector
      (function template)[edit]
      (C++26)
      overwrites matrix or vector with the result of computing the elementwise multiplication by a scalar
      (function template)[edit]
      (C++26)
      copies elements of one matrix or vector into another
      (function template)[edit]
      (C++26)
      adds vectors or matrices elementwise
      (function template)[edit]
      (C++26)
      returns nonconjugated dot product of two vectors
      (function template)[edit]
      (C++26)
      returns conjugated dot product of two vectors
      (function template)[edit]
      returns scaled sum of squares of the vector elements
      (function template)[edit]
      returns Euclidean norm of a vector
      (function template)[edit]
      returns sum of absolute values of the vector elements
      (function template)[edit]
      returns index of maximum absolute value of vector elements
      (function template)[edit]
      returns Frobenius norm of a matrix
      (function template)[edit]
      returns one norm of a matrix
      (function template)[edit]
      returns infinity norm of a matrix
      (function template)[edit]

      BLAS 2 functions

      Defined in header<linalg>
      Defined in namespacestd::linalg
      computes matrix-vector product
      (function template)[edit]
      computes symmetric matrix-vector product
      (function template)[edit]
      computes Hermitian matrix-vector product
      (function template)[edit]
      computes triangular matrix-vector product
      (function template)[edit]
      solves a triangular linear system
      (function template)[edit]
      performs nonsymmetric nonconjugated rank-1 update of a matrix
      (function template)[edit]
      performs nonsymmetric conjugated rank-1 update of a matrix
      (function template)[edit]
      performs rank-1 update of a symmetric matrix
      (function template)[edit]
      performs rank-1 update of a Hermitian matrix
      (function template)[edit]
      performs rank-2 update of a symmetric matrix
      (function template)[edit]
      performs rank-2 update of a Hermitian matrix
      (function template)[edit]

      BLAS 3 functions

      Defined in header<linalg>
      Defined in namespacestd::linalg
      computes matrix-matrix product
      (function template)[edit]
      computes symmetric matrix-matrix product
      (function template)[edit]
      computes Hermitian matrix-matrix product
      (function template)[edit]
      computes triangular matrix-matrix product
      (function template)[edit]
      performs rank-k update of a symmetric matrix
      (function template)[edit]
      performs rank-k update of a Hermitian matrix
      (function template)[edit]
      performs rank-2k update of a symmetric matrix
      (function template)[edit]
      performs rank-2k update of a Hermitian matrix
      (function template)[edit]
      solves multiple triangular linear systems
      (function template)[edit]

      Helper items

      Defined in header<linalg>
      Defined in namespacestd::linalg
      describe the order of elements in anstd::mdspan withlinalg::layout_blas_packed layout
      (tag)[edit]
      specify whether algorithms and other users of a matrix should access the upper triangle or lower triangle of the matrix
      (tag)[edit]
      specify whether algorithms should access diagonal entries of the matrix
      (tag)[edit]
      std::mdspan layout mapping policy that represents a square matrix that stores only the entries in one triangle, in a packed contiguous format
      (class template)[edit]

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_linalg202311L(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));}

      [edit]External links

      1. BLAS homepage
      2. BLAS Technical Forum
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/linalg&oldid=179968"

      [8]ページ先頭

      ©2009-2025 Movatter.jp