<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
BLAS Level 1: vectors operations, O(n) work

Vector operations that perform \(O(n)\) work on \(O(n)\) data. More...

Functions

template<TLAPACK_VECTOR vector_t, disable_if_allow_optblas_t< vector_t > = 0>
auto tlapack::asum (vector_t const &x)
 Vector 1-norm: \(\sum_{i=0}^{n-1} |Re(x_i)| + |Im(x_i)|\).
 
template<TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, TLAPACK_SCALAR alpha_t, class T = type_t<vectorY_t>, disable_if_allow_optblas_t< pair< alpha_t, T >, pair< vectorX_t, T >, pair< vectorY_t, T > > = 0>
void tlapack::axpy (const alpha_t &alpha, const vectorX_t &x, vectorY_t &y)
 Add scaled vector, \(y := \alpha x + y\).
 
template<TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, class T = type_t<vectorY_t>, disable_if_allow_optblas_t< pair< vectorX_t, T >, pair< vectorY_t, T > > = 0>
void tlapack::copy (const vectorX_t &x, vectorY_t &y)
 Copy vector, \(y := x\).
 
template<TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, class T = type_t<vectorY_t>, disable_if_allow_optblas_t< pair< vectorX_t, T >, pair< vectorY_t, T > > = 0>
auto tlapack::dot (const vectorX_t &x, const vectorY_t &y)
 
template<TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, class T = type_t<vectorY_t>, disable_if_allow_optblas_t< pair< vectorX_t, T >, pair< vectorY_t, T > > = 0>
auto tlapack::dotu (const vectorX_t &x, const vectorY_t &y)
 
template<TLAPACK_VECTOR vector_t, class abs_f >
size_type< vector_ttlapack::iamax (const vector_t &x, const IamaxOpts< abs_f > &opts)
 Return \(\arg\max_{i=0}^{n-1} |x_i|\).
 
template<TLAPACK_VECTOR vector_t, class abs_f >
size_type< vector_ttlapack::iamax_ec (const vector_t &x, abs_f absf)
 Return \(\arg\max_{i=0}^{n-1} |x_i|\).
 
template<TLAPACK_VECTOR vector_t, class abs_f >
size_type< vector_ttlapack::iamax_nc (const vector_t &x, abs_f absf)
 Return \(\arg\max_{i=0}^{n-1} |x_i|\).
 
template<typename T , enable_if_t< is_same_v< T, real_type< T > >, int > = 0>
void tlapack::lartg (const T &a, const T &b, real_type< T > &c, T &s, T &r)
 Construct plane rotation that eliminates b, such that:
 
template<TLAPACK_VECTOR vector_t, disable_if_allow_optblas_t< vector_t > = 0>
auto tlapack::nrm2 (const vector_t &x)
 
template<TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, TLAPACK_REAL c_type, TLAPACK_SCALAR s_type, class T = type_t<vectorX_t>, disable_if_allow_optblas_t< pair< vectorX_t, T >, pair< vectorY_t, T >, pair< c_type, real_type< T > >, pair< s_type, real_type< T > > > = 0>
void tlapack::rot (vectorX_t &x, vectorY_t &y, const c_type &c, const s_type &s)
 Apply plane rotation:
 
template<TLAPACK_COMPLEX T, enable_if_t< is_complex< T >, int > = 0, disable_if_allow_optblas_t< T > = 0>
void tlapack::rotg (T &a, const T &b, real_type< T > &c, T &s)
 Construct plane rotation that eliminates b, such that:
 
template<TLAPACK_REAL T, enable_if_t< is_real< T >, int > = 0, disable_if_allow_optblas_t< T > = 0>
void tlapack::rotg (T &a, T &b, T &c, T &s)
 Construct plane rotation that eliminates b, such that:
 
template<int flag, TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, enable_if_t<((-2<=flag) &&(flag<=1)), int > = 0, class T = type_t<vectorX_t>, enable_if_t< is_same_v< T, real_type< T > >, int > = 0, disable_if_allow_optblas_t< pair< vectorX_t, T >, pair< vectorY_t, T > > = 0>
void tlapack::rotm (vectorX_t &x, vectorY_t &y, const T h[4])
 Apply modified (fast) plane rotation, H:
 
template<TLAPACK_REAL T, enable_if_t< is_real< T >, int > = 0, disable_if_allow_optblas_t< T > = 0>
int tlapack::rotmg (T &d1, T &d2, T &a, const T &b, T h[4])
 Construct modified (fast) plane rotation, H, that eliminates b, such that.
 
template<TLAPACK_VECTOR vector_t, TLAPACK_SCALAR alpha_t, class T = type_t<vector_t>, disable_if_allow_optblas_t< pair< alpha_t, T >, pair< vector_t, T > > = 0>
void tlapack::scal (const alpha_t &alpha, vector_t &x)
 Scale vector by constant, \(x := \alpha x\).
 
template<TLAPACK_VECTOR vector_t>
void tlapack::swap (vector_t &x, vector_t &y)
 Swap vectors, \(x <=> y\).
 
template<TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, class T = type_t<vectorY_t>, disable_if_allow_optblas_t< pair< vectorX_t, T >, pair< vectorY_t, T > > = 0>
void tlapack::swap (vectorX_t &x, vectorY_t &y)
 Swap vectors, \(x <=> y\).
 

Detailed Description

Vector operations that perform \(O(n)\) work on \(O(n)\) data.


These are memory bound, since every operation requires a memory read or write.


Function Documentation

◆ asum()

auto tlapack::asum ( vector_t const x)

Vector 1-norm: \(\sum_{i=0}^{n-1} |Re(x_i)| + |Im(x_i)|\).

Parameters
[in]xA n-element vector.

◆ axpy()

template<TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, TLAPACK_SCALAR alpha_t, class T = type_t<vectorY_t>, disable_if_allow_optblas_t< pair< alpha_t, T >, pair< vectorX_t, T >, pair< vectorY_t, T > > = 0>
void tlapack::axpy ( const alpha_t alpha,
const vectorX_t x,
vectorY_t y 
)

Add scaled vector, \(y := \alpha x + y\).

Parameters
[in]alphaScalar.
[in]xA n-element vector.
[in,out]yA vector with at least n elements.

◆ copy()

template<TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, class T = type_t<vectorY_t>, disable_if_allow_optblas_t< pair< vectorX_t, T >, pair< vectorY_t, T > > = 0>
void tlapack::copy ( const vectorX_t x,
vectorY_t y 
)

Copy vector, \(y := x\).

Parameters
[in]xA n-element vector x.
[out]yA vector of at least n elements.

◆ dot()

template<TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, class T = type_t<vectorY_t>, disable_if_allow_optblas_t< pair< vectorX_t, T >, pair< vectorY_t, T > > = 0>
auto tlapack::dot ( const vectorX_t x,
const vectorY_t y 
)
Returns
dot product, \(x^H y\).
See also
dotu for unconjugated version, \(x^T y\).
Parameters
[in]xA n-element vector.
[in]yA n-element vector.

◆ dotu()

template<TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, class T = type_t<vectorY_t>, disable_if_allow_optblas_t< pair< vectorX_t, T >, pair< vectorY_t, T > > = 0>
auto tlapack::dotu ( const vectorX_t x,
const vectorY_t y 
)
Returns
unconjugated dot product, \(x^T y\).
See also
dot for conjugated version, \(x^H y\).
Parameters
[in]xA n-element vector.
[in]yA n-element vector.

◆ iamax()

template<TLAPACK_VECTOR vector_t, class abs_f >
size_type< vector_t > tlapack::iamax ( const vector_t x,
const IamaxOpts< abs_f > &  opts 
)

Return \(\arg\max_{i=0}^{n-1} |x_i|\).

See also
iamax_nc( const vector_t& x, abs_f absf ) for the version that does not check for NaNs.
iamax_ec( const vector_t& x, abs_f absf ) for the version that check for NaNs.
Parameters
[in]xThe n-element vector x.
[in]optsOptions. Define the behavior of checks for NaNs. Also define the absolute value function.
  • Default NaN check controlled by TLAPACK_DEFAULT_NANCHECK
  • Default absolute value function as in Reference BLAS, |a| := |Re(a)| + |Im(a)|.

◆ iamax_ec()

template<TLAPACK_VECTOR vector_t, class abs_f >
size_type< vector_t > tlapack::iamax_ec ( const vector_t x,
abs_f  absf 
)

Return \(\arg\max_{i=0}^{n-1} |x_i|\).

Version with NaN checks.

See also
iamax_nc(const vector_t& x, abs_f absf) for the version that does not check for NaNs.
Parameters
[in]xThe n-element vector x.
[in]absfAbsolute value function. In reference BLAS, absf(a) := |Re(a)| + |Im(a)|. We also use |a| to denote absf(a).
Returns
In priority order:
  1. 0 if n <= 0,
  2. the index of the first NAN in \(x\) if it exists,
  3. the index of the first Infinity in \(x\) if it exists,
  4. the Index of the infinity-norm of \(x\), \(|| x ||_{inf}\), \(\arg\max_{i=0}^{n-1} |x_i|\).

◆ iamax_nc()

template<TLAPACK_VECTOR vector_t, class abs_f >
size_type< vector_t > tlapack::iamax_nc ( const vector_t x,
abs_f  absf 
)

Return \(\arg\max_{i=0}^{n-1} |x_i|\).

Version with no NaN checks.

See also
iamax_ec(const vector_t& x, abs_f absf) for the version that check for NaNs.
Parameters
[in]xThe n-element vector x.
[in]absfAbsolute value function. In reference BLAS, absf(a) := |Re(a)| + |Im(a)| We also use |a| to denote absf(a).
Returns
In priority order:
  1. 0 if n <= 0,
  2. the index of the first Infinity in \(x\) if it exists,
  3. the Index of the infinity-norm of \(x\), \(|| x ||_{inf}\), \(\arg\max_{i=0}^{n-1} |x_i|\).

◆ lartg()

template<typename T , enable_if_t< is_same_v< T, real_type< T > >, int > = 0>
void tlapack::lartg ( const T &  a,
const T &  b,
real_type< T > &  c,
T &  s,
T &  r 
)

Construct plane rotation that eliminates b, such that:

\[ \begin{bmatrix} r \\ 0 \end{bmatrix} := \begin{bmatrix} c & s \\ -s & c \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix}. \]

See also
rot to apply the rotation.
Parameters
[in]aOn entry, scalar a. On exit, set to r.
[in]bOn entry, scalar b. On exit, set to s, 1/c, or 0.
[out]cCosine of rotation; real.
[out]sSine of rotation.
[out]rThe nonzero component of the rotated vector.

◆ nrm2()

auto tlapack::nrm2 ( const vector_t x)
Returns
2-norm of vector, \(|| x ||_2 := (\sum_{i=0}^{n-1} |x_i|^2)^{1/2}\).
Parameters
[in]xA n-element vector.

◆ rot()

template<TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, TLAPACK_REAL c_type, TLAPACK_SCALAR s_type, class T = type_t<vectorX_t>, disable_if_allow_optblas_t< pair< vectorX_t, T >, pair< vectorY_t, T >, pair< c_type, real_type< T > >, pair< s_type, real_type< T > > > = 0>
void tlapack::rot ( vectorX_t x,
vectorY_t y,
const c_type c,
const s_type s 
)

Apply plane rotation:

\[ \begin{bmatrix} x^T \\ y^T \end{bmatrix} := \begin{bmatrix} c & s \\ -s & c \end{bmatrix} \begin{bmatrix} x^T \\ y^T \end{bmatrix}. \]

See also
rotg to generate the rotation.
Parameters
[in,out]xA n-element vector.
[in,out]yA n-element vector.
[in]cCosine of rotation; real.
[in]sSine of rotation; scalar.

◆ rotg() [1/2]

template<TLAPACK_COMPLEX T, enable_if_t< is_complex< T >, int > = 0, disable_if_allow_optblas_t< T > = 0>
void tlapack::rotg ( T &  a,
const T &  b,
real_type< T > &  c,
T &  s 
)

Construct plane rotation that eliminates b, such that:

\[ \begin{bmatrix} r \\ 0 \end{bmatrix} = \begin{bmatrix} c & s \\ -s & c \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix}. \]

See also
rot to apply the rotation.
Parameters
[in,out]aOn entry, scalar a. On exit, set to r.
[in]bScalar b.
[out]cCosine of rotation; real.
[out]sSine of rotation; complex.

Anderson E (2017) Algorithm 978: Safe scaling in the level 1 BLAS. ACM Trans Math Softw 44:. https://doi.org/10.1145/3061665

◆ rotg() [2/2]

template<TLAPACK_REAL T, enable_if_t< is_real< T >, int > = 0, disable_if_allow_optblas_t< T > = 0>
void tlapack::rotg ( T &  a,
T &  b,
T &  c,
T &  s 
)

Construct plane rotation that eliminates b, such that:

\[ \begin{bmatrix} r \\ 0 \end{bmatrix} := \begin{bmatrix} c & s \\ -s & c \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix}. \]

See also
rot to apply the rotation.
Parameters
[in,out]aOn entry, scalar a. On exit, set to r.
[in,out]bOn entry, scalar b. On exit, set to s, 1/c, or 0.
[out]cCosine of rotation; real.
[out]sSine of rotation; real.

◆ rotm()

template<int flag, TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, enable_if_t<((-2<=flag) &&(flag<=1)), int > = 0, class T = type_t<vectorX_t>, enable_if_t< is_same_v< T, real_type< T > >, int > = 0, disable_if_allow_optblas_t< pair< vectorX_t, T >, pair< vectorY_t, T > > = 0>
void tlapack::rotm ( vectorX_t x,
vectorY_t y,
const h[4] 
)

Apply modified (fast) plane rotation, H:

\[ \begin{bmatrix} x^T \\ y^T \end{bmatrix} := H \begin{bmatrix} x^T \\ y^T \end{bmatrix}. \]

See also
rotmg to generate the rotation, and for fuller description.
Template Parameters
flagDefines the format of H.
  • For flag = -1,

    \[ H = \begin{bmatrix} h_{11} & h_{12} \\ h_{21} & h_{22} \end{bmatrix} \]

  • For flag = 0,

    \[ H = \begin{bmatrix} 1 & h_{12} \\ h_{21} & 1 \end{bmatrix} \]

  • For flag = 1,

    \[ H = \begin{bmatrix} h_{11} & 1 \\ -1 & h_{22} \end{bmatrix} \]

  • For flag = -2,

    \[ H = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \]

Parameters
[in,out]xA n-element vector.
[in,out]yA n-element vector.
[in]h4-element array with the modified plane rotation.

\[ h = { h_{11}, h_{21}, h_{12}, h_{22} }. \]

◆ rotmg()

template<TLAPACK_REAL T, enable_if_t< is_real< T >, int > = 0, disable_if_allow_optblas_t< T > = 0>
int tlapack::rotmg ( T &  d1,
T &  d2,
T &  a,
const T &  b,
h[4] 
)

Construct modified (fast) plane rotation, H, that eliminates b, such that.

\[ \begin{bmatrix} z \\ 0 \end{bmatrix} := H \begin{bmatrix} \sqrt{d_1} & 0 \\ 0 & \sqrt{d_2} \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix}. \]

See also
rotm to apply the rotation.

With modified plane rotations, vectors u and v are held in factored form as

\[ \begin{bmatrix} u^T \\ v^T \end{bmatrix} = \begin{bmatrix} \sqrt{d_1} & 0 \\ 0 & \sqrt{d_2} \end{bmatrix} \begin{bmatrix} x^T \\ y^T \end{bmatrix}. \]

Application of H to vectors x and y requires 4n flops (2n mul, 2n add) instead of 6n flops (4n mul, 2n add) as in standard plane rotations.

Let h = [ \(h_{11}, h_{21}, h_{12}, h_{22}\) ]. Then H has one of the following forms:

  • For flag = -1,

    \[ H = \begin{bmatrix} h_{11} & h_{12} \\ h_{21} & h_{22} \end{bmatrix} \]

  • For flag = 0,

    \[ H = \begin{bmatrix} 1 & h_{12} \\ h_{21} & 1 \end{bmatrix} \]

  • For flag = 1,

    \[ H = \begin{bmatrix} h_{11} & 1 \\ -1 & h_{22} \end{bmatrix} \]

  • For flag = -2,

    \[ H = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \]

Parameters
[in,out]d1sqrt(d1) is scaling factor for vector x.
[in,out]d2sqrt(d2) is scaling factor for vector y.
[in,out]aOn entry, scalar a. On exit, set to z.
[in]bScalar b.
[out]h4-element array with the modified plane rotation.

\[ h = { h_{11}, h_{21}, h_{12}, h_{22} }. \]

Hammarling, Sven. A note on modifications to the Givens plane rotation. IMA Journal of Applied Mathematics, 13:215-218, 1974. http://dx.doi.org/10.1093/imamat/13.2.215 (Note the notation swaps u <=> x, v <=> y, d_i -> l_i.)

◆ scal()

template<TLAPACK_VECTOR vector_t, TLAPACK_SCALAR alpha_t, class T = type_t<vector_t>, disable_if_allow_optblas_t< pair< alpha_t, T >, pair< vector_t, T > > = 0>
void tlapack::scal ( const alpha_t alpha,
vector_t x 
)

Scale vector by constant, \(x := \alpha x\).

Parameters
[in]alphaScalar.
[in,out]xA n-element vector.

◆ swap() [1/2]

template<TLAPACK_VECTOR vector_t>
void tlapack::swap ( vector_t x,
vector_t y 
)

Swap vectors, \(x <=> y\).

See also
tlapack::swap(vectorX_t& x, vectorY_t& y)
Note
This overload avoids unexpected behavior as follows. Without it, the unspecialized call swap( x, y ) using arrays with std::complex entries would call std::swap, while swap( x, y ) using arrays with float or double entries would call tlapack::swap. Use tlapack::swap(x,y) instead of swap(x,y) .

◆ swap() [2/2]

template<TLAPACK_VECTOR vectorX_t, TLAPACK_VECTOR vectorY_t, class T = type_t<vectorY_t>, disable_if_allow_optblas_t< pair< vectorX_t, T >, pair< vectorY_t, T > > = 0>
void tlapack::swap ( vectorX_t x,
vectorY_t y 
)

Swap vectors, \(x <=> y\).

Parameters
[in,out]xA n-element vector.
[in,out]yA n-element vector.