TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
BLAS interface

Detailed Description

Interface to parts of the BLAS library.

Typedefs

using nda::dcomplex = std::complex<double>
 Alias for std::complex<double> type.
 

Functions

template<typename X , typename Y >
requires ((Scalar<X> or MemoryVector<X>) and (Scalar<Y> or MemoryVector<X>))
auto nda::blas::dot (X const &x, Y const &y)
 Interface to the BLAS dot routine.
 
template<typename X , typename Y >
auto nda::blas::dot_generic (X const &x, Y const &y)
 Generic implementation of nda::blas::dot for types not supported by BLAS/LAPACK.
 
template<typename X , typename Y >
requires ((Scalar<X> or MemoryVector<X>) and (Scalar<Y> or MemoryVector<X>))
auto nda::blas::dotc (X const &x, Y const &y)
 Interface to the BLAS dotc routine.
 
template<typename X , typename Y >
auto nda::blas::dotc_generic (X const &x, Y const &y)
 Generic implementation of nda::blas::dotc for types not supported by BLAS/LAPACK.
 
template<Matrix A, Matrix B, MemoryMatrix C>
requires ((MemoryMatrix<A> or is_conj_array_expr<A>) and (MemoryMatrix<B> or is_conj_array_expr<B>) and have_same_value_type_v<A, B, C> and is_blas_lapack_v<get_value_t<A>>)
void nda::blas::gemm (get_value_t< A > alpha, A const &a, B const &b, get_value_t< A > beta, C &&c)
 Interface to the BLAS gemm routine.
 
template<bool VBATCH = false, Matrix A, Matrix B, MemoryMatrix C>
requires ((MemoryMatrix<A> or is_conj_array_expr<A>) and (MemoryMatrix<B> or is_conj_array_expr<B>) and have_same_value_type_v<A, B, C> and is_blas_lapack_v<get_value_t<A>>)
void nda::blas::gemm_batch (get_value_t< A > alpha, std::vector< A > const &va, std::vector< B > const &vb, get_value_t< A > beta, std::vector< C > &vc)
 Implements a batched version of nda::blas::gemm taking vectors of matrices as arguments.
 
template<ArrayOfRank< 3 > A, ArrayOfRank< 3 > B, MemoryArrayOfRank< 3 > C>
requires ((MemoryArrayOfRank<A, 3> or (is_conj_array_expr<A>)) and (MemoryArrayOfRank<B, 3> or (is_conj_array_expr<B>)) and have_same_value_type_v<A, B, C> and is_blas_lapack_v<get_value_t<A>>)
void nda::blas::gemm_batch_strided (get_value_t< A > alpha, A const &a, B const &b, get_value_t< A > beta, C &&c)
 Implements a strided batched version of nda::blas::gemm taking 3-dimensional arrays as arguments.
 
template<Matrix A, Matrix B, MemoryMatrix C>
void nda::blas::gemm_generic (typename A::value_type alpha, A const &a, B const &b, typename A::value_type beta, C &&c)
 Generic nda::blas::gemm implementation for types not supported by BLAS/LAPACK.
 
template<Matrix A, Matrix B, MemoryMatrix C>
void nda::blas::gemm_vbatch (get_value_t< A > alpha, std::vector< A > const &va, std::vector< B > const &vb, get_value_t< A > beta, std::vector< C > &vc)
 Wrapper of nda::blas::gemm_batch that allows variable sized matrices.
 
template<Matrix A, MemoryVector X, MemoryVector Y>
requires ((MemoryMatrix<A> or is_conj_array_expr<A>) and have_same_value_type_v<A, X, Y> and is_blas_lapack_v<get_value_t<A>>)
void nda::blas::gemv (get_value_t< A > alpha, A const &a, X const &x, get_value_t< A > beta, Y &&y)
 Interface to the BLAS gemv routine.
 
template<typename A , typename X , typename Y >
void nda::blas::gemv_generic (get_value_t< A > alpha, A const &a, X const &x, get_value_t< A > beta, Y &&y)
 Generic nda::blas::gemv implementation for types not supported by BLAS/LAPACK.
 
template<MemoryVector X, MemoryVector Y, MemoryMatrix M>
requires (have_same_value_type_v<X, Y, M> and mem::have_compatible_addr_space<X, Y, M> and is_blas_lapack_v<get_value_t<X>>)
void nda::blas::ger (get_value_t< X > alpha, X const &x, Y const &y, M &&m)
 Interface to the BLAS ger routine.
 
template<MemoryMatrix A>
int nda::blas::get_ld (A const &a)
 Get the leading dimension in LAPACK jargon of an nda::MemoryMatrix.
 
template<MemoryMatrix A>
int nda::blas::get_ncols (A const &a)
 Get the number of columns in LAPACK jargon of an nda::MemoryMatrix.
 
template<ArrayOrScalar A, ArrayOrScalar B>
auto nda::blas::outer_product (A const &a, B const &b)
 Calculate the outer product of two contiguous arrays/views/scalars.
 
template<typename X >
requires (MemoryVector<X> or is_conj_array_expr<X>)
void nda::blas::scal (get_value_t< X > alpha, X &&x)
 Interface to the BLAS scal routine.
 

Variables

template<bool conj, bool transpose>
const char nda::blas::get_op
 Variable template that determines the BLAS matrix operation tag ('N','T','C') based on the given boolean flags for conjugation and transposition.
 
template<Array A>
static constexpr bool nda::blas::has_C_layout
 Constexpr variable that is true if the given nda::Array type has a C memory layout.
 
template<Array A>
static constexpr bool nda::blas::has_F_layout
 Constexpr variable that is true if the given nda::Array type has a Fortran memory layout.
 
template<typename A >
static constexpr bool nda::blas::is_conj_array_expr = false
 Constexpr variable that is true if the given type is a conjugate lazy expression.
 
template<MemoryArray A>
static constexpr bool nda::blas::is_conj_array_expr< expr_call< conj_f, A > > = true
 Specialization of nda::blas::is_conj_array_expr for the conjugate lazy expressions.
 

Function Documentation

◆ dot()

template<typename X , typename Y >
requires ((Scalar<X> or MemoryVector<X>) and (Scalar<Y> or MemoryVector<X>))
auto nda::blas::dot ( X const & x,
Y const & y )

#include <nda/blas/dot.hpp>

Interface to the BLAS dot routine.

This function forms the dot product of two vectors. It calculates

  • \( \mathbf{x}^T \mathbf{y} \) in case that both \( \mathbf{x} \) and \( \mathbf{y} \) are vectors,
  • \( x \mathbf{y} \) in case that \( x \) is a scalar and \( \mathbf{y} \) is a vector,
  • \( \mathbf{x} y \) in case that \( \mathbf{x} \) is a vector and \( y \) is a scalar or
  • \( x y \) in case that both \( x \) and \( y \) are scalars.
Template Parameters
Xnda::MemoryVector or nda::Scalar type.
Ynda::MemoryVector or nda::Scalar type.
Parameters
xInput vector/scalar.
yInput vector/scalar.
Returns
Vector/scalar result of the dot product.

Definition at line 61 of file dot.hpp.

◆ dot_generic()

template<typename X , typename Y >
auto nda::blas::dot_generic ( X const & x,
Y const & y )

#include <nda/blas/dot.hpp>

Generic implementation of nda::blas::dot for types not supported by BLAS/LAPACK.

Template Parameters
XVector/Scalar type.
YVector/Scalar type.
Parameters
xInput vector/scalar.
yInput vector/scalar.
Returns
Vector/scalar result of the dot product.

Definition at line 176 of file dot.hpp.

◆ dotc()

template<typename X , typename Y >
requires ((Scalar<X> or MemoryVector<X>) and (Scalar<Y> or MemoryVector<X>))
auto nda::blas::dotc ( X const & x,
Y const & y )

#include <nda/blas/dot.hpp>

Interface to the BLAS dotc routine.

This function forms the dot product of two vectors. It calculates

  • \( \mathbf{x}^H \mathbf{y} \) in case that both \( \mathbf{x} \) and \( \mathbf{y} \) are vectors,
  • \( \bar{x} \mathbf{y} \) in case that \( x \) is a scalar and \( \mathbf{y} \) is a vector,
  • \( \mathbf{x}^H y \) in case that \( \mathbf{x} \) is a vector and \( y \) is a scalar or
  • \( \bar{x} y \) in case that both \( x \) and \( y \) are scalars.
Template Parameters
Xnda::MemoryVector or nda::Scalar type.
Ynda::MemoryVector or nda::Scalar type.
Parameters
xInput vector/scalar.
yInput vector/scalar.
Returns
Vector/scalar result of the dot product.

Definition at line 103 of file dot.hpp.

◆ dotc_generic()

template<typename X , typename Y >
auto nda::blas::dotc_generic ( X const & x,
Y const & y )

#include <nda/blas/dot.hpp>

Generic implementation of nda::blas::dotc for types not supported by BLAS/LAPACK.

Template Parameters
XVector/Scalar type.
YVector/Scalar type.
Parameters
xInput vector/scalar.
yInput vector/scalar.
Returns
Vector/scalar result of the dot product.

Definition at line 194 of file dot.hpp.

◆ gemm()

template<Matrix A, Matrix B, MemoryMatrix C>
requires ((MemoryMatrix<A> or is_conj_array_expr<A>) and (MemoryMatrix<B> or is_conj_array_expr<B>) and have_same_value_type_v<A, B, C> and is_blas_lapack_v<get_value_t<A>>)
void nda::blas::gemm ( get_value_t< A > alpha,
A const & a,
B const & b,
get_value_t< A > beta,
C && c )

#include <nda/blas/gemm.hpp>

Interface to the BLAS gemm routine.

This function performs one of the matrix-matrix operations

\[ \mathbf{C} \leftarrow \alpha \mathrm{op}(\mathbf{A}) \mathrm{op}(\mathbf{B}) + \beta \mathbf{C} \;, \]

where \( \mathrm{op}(\mathbf{X}) \) is one of

  • \( \mathrm{op}(\mathbf{X}) = \mathbf{X} \),
  • \( \mathrm{op}(\mathbf{X}) = \mathbf{X}^T \) or
  • \( \mathrm{op}(\mathbf{X}) = \mathbf{X}^H \).

Here, \( \alpha \) and \( \beta \) are scalars, and \( \mathbf{A} \), \( \mathbf{B} \) are matrices with \( \mathrm{op}(\mathbf{A}) \) is an m-by-k matrix, \( \mathrm{op}(\mathbf{B}) \) is a k-by-n matrix and \( \mathrm{op}(\mathbf{C}) \) is an m-by-n matrix.

Template Parameters
Anda::Matrix type.
Bnda::Matrix type.
Cnda::MemoryMatrix type.
Parameters
alphaInput scalar.
aInput matrix of size m-by-k.
bInput matrix of size k-by-n.
betaInput scalar.
cInput/Output matrix of size m-by-n.

Definition at line 101 of file gemm.hpp.

◆ gemm_batch()

template<bool VBATCH = false, Matrix A, Matrix B, MemoryMatrix C>
requires ((MemoryMatrix<A> or is_conj_array_expr<A>) and (MemoryMatrix<B> or is_conj_array_expr<B>) and have_same_value_type_v<A, B, C> and is_blas_lapack_v<get_value_t<A>>)
void nda::blas::gemm_batch ( get_value_t< A > alpha,
std::vector< A > const & va,
std::vector< B > const & vb,
get_value_t< A > beta,
std::vector< C > & vc )

#include <nda/blas/gemm_batch.hpp>

Implements a batched version of nda::blas::gemm taking vectors of matrices as arguments.

This routine is a batched version of nda::blas::gemm, performing multiple gemm operations in a single call. Each gemm operation performs a matrix-matrix product with general matrices.

Template Parameters
VBATCHAllow for variable sized matrices.
Anda::Matrix type.
Bnda::Matrix type.
Cnda::MemoryMatrix type.
Parameters
alphaInput scalar.
vastd::vector of input matrices.
vbstd::vector of input matrices.
betaInput scalar.
vcstd::vector of input/output matrices.

Definition at line 69 of file gemm_batch.hpp.

◆ gemm_batch_strided()

template<ArrayOfRank< 3 > A, ArrayOfRank< 3 > B, MemoryArrayOfRank< 3 > C>
requires ((MemoryArrayOfRank<A, 3> or (is_conj_array_expr<A>)) and (MemoryArrayOfRank<B, 3> or (is_conj_array_expr<B>)) and have_same_value_type_v<A, B, C> and is_blas_lapack_v<get_value_t<A>>)
void nda::blas::gemm_batch_strided ( get_value_t< A > alpha,
A const & a,
B const & b,
get_value_t< A > beta,
C && c )

#include <nda/blas/gemm_batch.hpp>

Implements a strided batched version of nda::blas::gemm taking 3-dimensional arrays as arguments.

This function is similar to nda::blas::gemm_batch except that it takes 3-dimensional arrays as arguments instead of vectors of matrices. The first dimension of the arrays indexes the matrices to be multiplied.

Template Parameters
Anda::ArrayOfRank<3> type.
Bnda::ArrayOfRank<3> type.
Cnda::ArrayOfRank<3> type.
Parameters
alphaInput scalar.
a3-dimensional input array.
b3-dimensional input array.
betaInput scalar.
c3-dimensional input/output array.

Definition at line 221 of file gemm_batch.hpp.

◆ gemm_generic()

template<Matrix A, Matrix B, MemoryMatrix C>
void nda::blas::gemm_generic ( typename A::value_type alpha,
A const & a,
B const & b,
typename A::value_type beta,
C && c )

#include <nda/blas/gemm.hpp>

Generic nda::blas::gemm implementation for types not supported by BLAS/LAPACK.

Template Parameters
ASome matrix type.
BSome matrix type.
CSome matrix type.
Parameters
alphaInput scalar.
aInput matrix of size m-by-k.
bInput matrix of size k-by-n.
betaInput scalar.
cInput/Output matrix of size m-by-n.

Definition at line 59 of file gemm.hpp.

◆ gemm_vbatch()

template<Matrix A, Matrix B, MemoryMatrix C>
void nda::blas::gemm_vbatch ( get_value_t< A > alpha,
std::vector< A > const & va,
std::vector< B > const & vb,
get_value_t< A > beta,
std::vector< C > & vc )

#include <nda/blas/gemm_batch.hpp>

Wrapper of nda::blas::gemm_batch that allows variable sized matrices.

Template Parameters
Anda::Matrix type.
Bnda::Matrix type.
Cnda::MemoryMatrix type.
Parameters
alphaInput scalar.
vastd::vector of input matrices.
vbstd::vector of input matrices.
betaInput scalar.
vcstd::vector of input/output matrices.

Definition at line 199 of file gemm_batch.hpp.

◆ gemv()

template<Matrix A, MemoryVector X, MemoryVector Y>
requires ((MemoryMatrix<A> or is_conj_array_expr<A>) and have_same_value_type_v<A, X, Y> and is_blas_lapack_v<get_value_t<A>>)
void nda::blas::gemv ( get_value_t< A > alpha,
A const & a,
X const & x,
get_value_t< A > beta,
Y && y )

#include <nda/blas/gemv.hpp>

Interface to the BLAS gemv routine.

This function performs one of the matrix-vector operations

  • \( \mathbf{y} \leftarrow \alpha \mathbf{A} \mathbf{x} + \beta \mathbf{y} \),
  • \( \mathbf{y} \leftarrow \alpha \mathbf{A}^T \mathbf{x} + \beta \mathbf{y} \),
  • \( \mathbf{y} \leftarrow \alpha \mathbf{A}^H \mathbf{x} + \beta \mathbf{y} \),

where \( \alpha \) and \( \beta \) are scalars, \( \mathbf{x} \) and \( \mathbf{y} \) are vectors and \( \mathbf{A} \) is an m-by-n matrix.

Template Parameters
Anda::Matrix type.
Xnda::MemoryVector type.
Ynda::MemoryVector type.
Parameters
alphaInput scalar.
aInput matrix of size m-by-n.
xInput vector of size n.
betaInput scalar.
yInput/Output vector of size m.

Definition at line 89 of file gemv.hpp.

◆ gemv_generic()

template<typename A , typename X , typename Y >
void nda::blas::gemv_generic ( get_value_t< A > alpha,
A const & a,
X const & x,
get_value_t< A > beta,
Y && y )

#include <nda/blas/gemv.hpp>

Generic nda::blas::gemv implementation for types not supported by BLAS/LAPACK.

Template Parameters
ASome matrix type.
XSome vector type.
YSome vector type.
Parameters
alphaInput scalar.
aInput matrix of size m-by-n.
xInput vector of size n.
betaInput scalar.
yInput/Output vector of size m.

Definition at line 57 of file gemv.hpp.

◆ ger()

template<MemoryVector X, MemoryVector Y, MemoryMatrix M>
requires (have_same_value_type_v<X, Y, M> and mem::have_compatible_addr_space<X, Y, M> and is_blas_lapack_v<get_value_t<X>>)
void nda::blas::ger ( get_value_t< X > alpha,
X const & x,
Y const & y,
M && m )

#include <nda/blas/ger.hpp>

Interface to the BLAS ger routine.

This function performs the rank 1 operation

\[ \mathbf{M} \leftarrow \alpha \mathbf{x} \mathbf{y}^H + \mathbf{M} ;, \]

where \( \alpha \) is a scalar, \( \mathbf{x} \) is an m element vector, \( \mathbf{y} \) is an n element vector and \( \mathbf{M} \) is an m-by-n matrix.

Template Parameters
Xnda::MemoryVector type.
Ynda::MemoryVector type.
Mnda::MemoryMatrix type.
Parameters
alphaInput scalar.
xInput left vector (column vector) of size m.
yInput right vector (row vector) of size n.
mInput/Output matrix of size m-by-n to which the outer product is added.

Definition at line 68 of file ger.hpp.

◆ get_ld()

template<MemoryMatrix A>
int nda::blas::get_ld ( A const & a)

#include <nda/blas/tools.hpp>

Get the leading dimension in LAPACK jargon of an nda::MemoryMatrix.

Template Parameters
Anda::MemoryMatrix type.
Parameters
anda::MemoryMatrix object.
Returns
Leading dimension.

Definition at line 109 of file tools.hpp.

◆ get_ncols()

template<MemoryMatrix A>
int nda::blas::get_ncols ( A const & a)

#include <nda/blas/tools.hpp>

Get the number of columns in LAPACK jargon of an nda::MemoryMatrix.

Template Parameters
Anda::MemoryMatrix type.
Parameters
anda::MemoryMatrix object.
Returns
Number of columns.

Definition at line 121 of file tools.hpp.

◆ outer_product()

template<ArrayOrScalar A, ArrayOrScalar B>
auto nda::blas::outer_product ( A const & a,
B const & b )

#include <nda/blas/ger.hpp>

Calculate the outer product of two contiguous arrays/views/scalars.

For general multidimensional arrays/views, it calculates their tensor outer product, i.e.

c(i,j,k,...,u,v,w,...) = a(i,j,k,...) * b(u,v,w,...)

If one of the arguments is a scalar, it multiplies each element of the other argument by the scalar which returns a lazy nda::expr object.

If both arguments are scalars, it returns their products.

Template Parameters
Anda::ArrayOrScalar type.
Bnda::ArrayOrScalar type.
Parameters
aInput array/scalar.
bInput array/scalar.
Returns
(Lazy) Outer product.

Definition at line 111 of file ger.hpp.

◆ scal()

template<typename X >
requires (MemoryVector<X> or is_conj_array_expr<X>)
void nda::blas::scal ( get_value_t< X > alpha,
X && x )

#include <nda/blas/scal.hpp>

Interface to the BLAS scal routine.

Scales a vector by a constant. This function calculates

\[ \mathbf{x} \leftarrow \alpha \mathbf{x} ;, \]

where \( \alpha \) is a scalar constant and \( \mathbf{x} \) is a vector.

Template Parameters
Xnda::MemoryVector or a conjugate array expression.
Parameters
alphaInput scalar.
xInput/Output vector to be scaled.

Definition at line 49 of file scal.hpp.

Variable Documentation

◆ get_op

template<bool conj, bool transpose>
const char nda::blas::get_op

#include <nda/blas/tools.hpp>

Initial value:
= []() {
static_assert(!(conj and not transpose), "Error in nda::blas::get_op: Cannot use conjugate operation alone in blas operations");
if constexpr (conj and transpose)
return 'C';
else if constexpr (transpose)
return 'T';
else
return 'N';
}()
auto transpose(A &&a)
Transpose the memory layout of an nda::MemoryArray or an nda::expr_call.

Variable template that determines the BLAS matrix operation tag ('N','T','C') based on the given boolean flags for conjugation and transposition.

Template Parameters
conjBoolean flag for conjugation.
transposeBoolean flag for transposition.

Definition at line 91 of file tools.hpp.