<T>LAPACK 0.1.2
C++ Template Linear Algebra PACKage
|
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_t > | tlapack::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_t > | tlapack::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_t > | tlapack::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\). | |
Vector operations that perform \(O(n)\) work on \(O(n)\) data.
These are memory bound, since every operation requires a memory read or write.
Vector 1-norm: \(\sum_{i=0}^{n-1} |Re(x_i)| + |Im(x_i)|\).
[in] | x | A n-element vector. |
void tlapack::axpy | ( | const alpha_t & | alpha, |
const vectorX_t & | x, | ||
vectorY_t & | y | ||
) |
Add scaled vector, \(y := \alpha x + y\).
[in] | alpha | Scalar. |
[in] | x | A n-element vector. |
[in,out] | y | A vector with at least n elements. |
void tlapack::copy | ( | const vectorX_t & | x, |
vectorY_t & | y | ||
) |
Copy vector, \(y := x\).
[in] | x | A n-element vector x. |
[out] | y | A vector of at least n elements. |
auto tlapack::dot | ( | const vectorX_t & | x, |
const vectorY_t & | y | ||
) |
[in] | x | A n-element vector. |
[in] | y | A n-element vector. |
auto tlapack::dotu | ( | const vectorX_t & | x, |
const vectorY_t & | y | ||
) |
[in] | x | A n-element vector. |
[in] | y | A n-element vector. |
Return \(\arg\max_{i=0}^{n-1} |x_i|\).
[in] | x | The n-element vector x. |
[in] | opts | Options. Define the behavior of checks for NaNs. Also define the absolute value function.
|
Return \(\arg\max_{i=0}^{n-1} |x_i|\).
Version with NaN checks.
[in] | x | The n-element vector x. |
[in] | absf | Absolute value function. In reference BLAS, absf(a) := |Re(a)| + |Im(a)|. We also use |a| to denote absf(a). |
NAN
in \(x\) if it exists,Infinity
in \(x\) if it exists,Return \(\arg\max_{i=0}^{n-1} |x_i|\).
Version with no NaN checks.
[in] | x | The n-element vector x. |
[in] | absf | Absolute value function. In reference BLAS, absf(a) := |Re(a)| + |Im(a)| We also use |a| to denote absf(a). |
Infinity
in \(x\) if it exists,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}. \]
[in] | a | On entry, scalar a. On exit, set to r. |
[in] | b | On entry, scalar b. On exit, set to s, 1/c, or 0. |
[out] | c | Cosine of rotation; real. |
[out] | s | Sine of rotation. |
[out] | r | The nonzero component of the rotated vector. |
[in] | x | A n-element vector. |
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}. \]
[in,out] | x | A n-element vector. |
[in,out] | y | A n-element vector. |
[in] | c | Cosine of rotation; real. |
[in] | s | Sine of rotation; scalar. |
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}. \]
[in,out] | a | On entry, scalar a. On exit, set to r. |
[in] | b | Scalar b. |
[out] | c | Cosine of rotation; real. |
[out] | s | Sine 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
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}. \]
[in,out] | a | On entry, scalar a. On exit, set to r. |
[in,out] | b | On entry, scalar b. On exit, set to s, 1/c, or 0. |
[out] | c | Cosine of rotation; real. |
[out] | s | Sine of rotation; real. |
void tlapack::rotm | ( | vectorX_t & | x, |
vectorY_t & | y, | ||
const T | 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}. \]
flag | Defines the format of H.
|
[in,out] | x | A n-element vector. |
[in,out] | y | A n-element vector. |
[in] | h | 4-element array with the modified plane rotation. \[ h = { h_{11}, h_{21}, h_{12}, h_{22} }. \] |
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}. \]
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:
\[ H = \begin{bmatrix} h_{11} & h_{12} \\ h_{21} & h_{22} \end{bmatrix} \]
\[ H = \begin{bmatrix} 1 & h_{12} \\ h_{21} & 1 \end{bmatrix} \]
\[ H = \begin{bmatrix} h_{11} & 1 \\ -1 & h_{22} \end{bmatrix} \]
\[ H = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \]
[in,out] | d1 | sqrt(d1) is scaling factor for vector x. |
[in,out] | d2 | sqrt(d2) is scaling factor for vector y. |
[in,out] | a | On entry, scalar a. On exit, set to z. |
[in] | b | Scalar b. |
[out] | h | 4-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.)
void tlapack::scal | ( | const alpha_t & | alpha, |
vector_t & | x | ||
) |
Scale vector by constant, \(x := \alpha x\).
[in] | alpha | Scalar. |
[in,out] | x | A n-element vector. |
void tlapack::swap | ( | vector_t & | x, |
vector_t & | y | ||
) |
Swap vectors, \(x <=> y\).
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)
. void tlapack::swap | ( | vectorX_t & | x, |
vectorY_t & | y | ||
) |
Swap vectors, \(x <=> y\).
[in,out] | x | A n-element vector. |
[in,out] | y | A n-element vector. |