ampsci
High-precision calculations for one- and two-valence atomic systems
LinAlg::Vector< T >

ok

template<typename T = double>
class LinAlg::Vector< T >

Owning 1D array; inherits from Matrix<T> with a single column.

Stores elements contiguously. Provides 1D index access via [], (), and at(), plus arithmetic operators and GSL interop inherited from Matrix.

Supports inner product (a * b), matrix-vector product (A * v), and outer product (outer_product(a, b)).

Vector vs View<T>:** Use Vector<T> when you need to own the data (e.g. storing a result, passing to a solver). Use View<T> (LinAlg::View) for non-owning, zero-copy access into an existing array e.g. a row or column of a Matrix, obtained via Matrix::row_view() or Matrix::column_view().

Template Parameters
TElement type (default: double).

#include <Vector.hpp>

+ Inheritance diagram for LinAlg::Vector< T >:

Public Member Functions

 Vector ()
 Default construct: empty vector.
 
 Vector (std::size_t dimension)
 Construct zero-initialised vector of length dimension
 
 Vector (std::initializer_list< T > l)
 Construct from initialiser list: Vector<double> v = {1.0, 2.0, 3.0};
 
 Vector (std::vector< T > &&v)
 Construct from std::vector by move.
 
 Vector (const std::vector< T > &v)
 Construct from std::vector by copy.
 
 Vector (const Matrix< T > &&m)
 Construct from single-column Matrix by move.
 
 Vector (const Matrix< T > &m)
 Construct from single-column Matrix by copy.
 
T & operator[] (std::size_t i)
 Element access by index, no range checking, mutable.
 
operator[] (std::size_t i) const
 Element access by index, no range checking, const.
 
T & at (std::size_t i)
 Element access by index, with range checking, mutable.
 
at (std::size_t i) const
 Element access by index, with range checking, const.
 
T & operator() (std::size_t i)
 Element access by index, with range checking, mutable.
 
operator() (std::size_t i) const
 Element access by index, with range checking, const.
 
Vector< T > conj () const
 Returns element-wise complex conjugate.
 
auto real () const
 Returns real part of each element as a new Vector.
 
auto imag () const
 Returns imaginary part of each element as a new Vector.
 
auto complex () const
 Returns a complex-valued copy of this Vector.
 
Vector< T > transpose () const =delete
 Transpose is not defined for Vector (deleted)
 
Vector< T > & operator+= (const Vector< T > &rhs)
 Addition assignment: element-wise *this += rhs
 
Vector< T > & operator-= (const Vector< T > rhs)
 Subtraction assignment: element-wise *this -= rhs
 
Vector< T > & operator*= (const T x)
 Scalar multiplication assignment: *this *= x
 
Vector< T > & operator/= (const T x)
 Scalar division assignment: *this /= x
 
auto as_gsl_view ()
 Returns a GSL vector view of the underlying data (no copy). The Vector must remain in scope for the lifetime of the view.
 
auto as_gsl_view () const
 Returns a const GSL vector view of the underlying data (no copy). The Vector must remain in scope for the lifetime of the view.
 
- Public Member Functions inherited from LinAlg::Matrix< T >
 Matrix ()
 Default initialiser.
 
 Matrix (std::size_t rows, std::size_t cols)
 Initialise a blank matrix rows*cols, filled with 0.
 
 Matrix (std::size_t rows, std::size_t cols, const T &value)
 Initialise a matrix rows*cols, filled with 'value'.
 
 Matrix (std::size_t dimension)
 Initialise a blank square matrix dimension*dimension, filled with 0.
 
 Matrix (std::initializer_list< std::initializer_list< T > > ll)
 Initialise a matrix from initialiser list. {{},{},{}}. Each row must be same length.
 
 Matrix (std::size_t rows, std::size_t cols, std::initializer_list< T > l)
 Initialise a matrix from single initialiser list. {...}.
 
 Matrix (std::size_t rows, std::size_t cols, std::vector< T > &&v)
 Initialise a matrix from single initialiser list. {...}.
 
 Matrix (std::size_t rows, std::size_t cols, const std::vector< T > &v)
 Initialise a matrix from single initialiser list. {...}.
 
void resize (std::size_t rows, std::size_t cols)
 Resizes matrix to new dimension; all values reset to default.
 
void resize (std::size_t rows, std::size_t cols, const T &value)
 Resizes matrix to new dimension; all values reset to 'value'.
 
std::size_t rows () const
 Return rows [major index size].
 
std::size_t cols () const
 Return columns [minor index size].
 
std::size_t size () const
 Return rows*columns [total array size].
 
bool empty () const
 Bool - is empty? (same as size==0)
 
T * data ()
 Pointer to first element; for std::complex<T> this is complex<T>*, not T*.
 
const T * data () const
 Const pointer to first element; for std::complex<T> this is const complex<T>*, not const T*.
 
T * operator[] (std::size_t i)
 [] index access (no range checking). [i] returns pointer to ith row, mutable
 
const T * operator[] (std::size_t i) const
 [] index access (no range checking). [i] returns const pointer to ith row
 
T & at (std::size_t row_i, std::size_t col_j)
 at(i,j): element access with range checking, mutable
 
at (std::size_t row_i, std::size_t col_j) const
 at(i,j): element access with range checking, const
 
const T & atc (std::size_t row_i, std::size_t col_j) const
 at(i,j): element access with range checking, const ref
 
T & operator() (std::size_t i, std::size_t j)
 () index access with range checking, mutable
 
operator() (std::size_t i, std::size_t j) const
 () index access with range checking, const
 
auto begin ()
 iterators for underlying std::vector (entire data)
 
auto cbegin () const
 
auto end ()
 
auto cend () const
 
const T * row (std::size_t row) const
 Returns raw c pointer to start of a row.
 
View< T > row_view (std::size_t row)
 Returns a mutable 'View' of a row.
 
View< const T > row_view (std::size_t row) const
 Returns an immutable 'View' of a row.
 
View< T > column_view (std::size_t col)
 Returns a mutable 'View' of a column.
 
View< const T > column_view (std::size_t col) const
 Returns an immutable 'View' of a column.
 
Matrix_view< T > matrix_view ()
 Returns a mutable view of the entire matrix (no ownership, no resize)
 
Matrix_view< const T > matrix_view () const
 Returns an immutable view of the entire matrix (no ownership, no resize)
 
auto as_gsl_view ()
 Returns a GSL matrix view for use with GSL functions (no copy).
 
auto as_gsl_view () const
 Const GSL matrix view; see as_gsl_view()
 
determinant () const
 Returns the determinant via LU decomposition (GSL).
 
Matrix< T > & invert_in_place ()
 Inverts the matrix in place via LU decomposition (GSL).
 
Matrix< T > inverse () const
 Returns inverse of the matrix; original is unchanged.
 
Matrix< T > transpose () const
 Returns the transpose of the matrix.
 
Matrix< T > & make_identity ()
 Constructs a diagonal unit matrix (identity), in place; only for square.
 
Matrix< T > & zero ()
 Sets all elements to zero, in place.
 
Matrix< T > conj () const
 Returns conjugate of matrix.
 
auto real () const
 Returns real part of complex matrix (changes type; returns a real matrix)
 
auto imag () const
 Returns imag part of complex matrix (changes type; returns a real matrix)
 
auto complex () const
 Converts a real to complex matrix (changes type; returns a complex matrix)
 
Matrix< T > & conj_in_place ()
 Conjugates matrix, in place.
 
Matrix< T > & mult_elements_by (const Matrix< T > &a)
 Elementwise multiply in place: M_ij *= a_ij.
 
Matrix< T > & operator+= (const Matrix< T > &rhs)
 In-place elementwise addition; dimensions must match.
 
Matrix< T > & operator-= (const Matrix< T > &rhs)
 In-place elementwise subtraction; dimensions must match.
 
Matrix< T > & operator*= (const T x)
 In-place scalar multiply: M_ij *= x.
 
Matrix< T > & operator/= (const T x)
 In-place scalar divide: M_ij /= x.
 
Matrix< T > & operator+= (T aI)
 M += aI: adds a to diagonal elements (scalar treated as a*Identity)
 
Matrix< T > & operator-= (T aI)
 M -= aI: subtracts a from diagonal elements (scalar treated as a*Identity)
 

Friends

Vector< T > operator+ (Vector< T > lhs, const Matrix< T > &rhs)
 Element-wise addition: lhs + rhs
 
Vector< T > operator- (Vector< T > lhs, const Matrix< T > &rhs)
 Element-wise subtraction: lhs - rhs
 
Vector< T > operator* (const T x, Vector< T > rhs)
 Scalar multiplication: x * v
 
Vector< T > operator* (Vector< T > lhs, const T x)
 Scalar multiplication: v * x
 
Vector< T > operator/ (Vector< T > lhs, const T x)
 Scalar division: v / x
 
Vector< T > operator* (const Matrix< T > &a, const Vector< T > &b)
 Matrix-vector product: returns A * b, i.e. v_i = sum_j A_ij * b_j
 
operator* (const Vector< T > &a, const Vector< T > &b)
 Inner (dot) product: returns sum_i a_i * b_i
 
Matrix< T > outer_product (const Vector< T > &a, const Vector< T > &b)
 Outer product: returns matrix M with M_ij = a_i * b_j
 

Additional Inherited Members

- Protected Attributes inherited from LinAlg::Matrix< T >
std::size_t m_rows
 
std::size_t m_cols
 
std::vector< T > m_data {}
 

Constructor & Destructor Documentation

◆ Vector() [1/7]

template<typename T = double>
LinAlg::Vector< T >::Vector ( )
inline

Default construct: empty vector.

◆ Vector() [2/7]

template<typename T = double>
LinAlg::Vector< T >::Vector ( std::size_t  dimension)
inline

Construct zero-initialised vector of length dimension

◆ Vector() [3/7]

template<typename T = double>
LinAlg::Vector< T >::Vector ( std::initializer_list< T >  l)
inline

Construct from initialiser list: Vector<double> v = {1.0, 2.0, 3.0};

◆ Vector() [4/7]

template<typename T = double>
LinAlg::Vector< T >::Vector ( std::vector< T > &&  v)
inline

Construct from std::vector by move.

◆ Vector() [5/7]

template<typename T = double>
LinAlg::Vector< T >::Vector ( const std::vector< T > &  v)
inline

Construct from std::vector by copy.

◆ Vector() [6/7]

template<typename T = double>
LinAlg::Vector< T >::Vector ( const Matrix< T > &&  m)
inline

Construct from single-column Matrix by move.

◆ Vector() [7/7]

template<typename T = double>
LinAlg::Vector< T >::Vector ( const Matrix< T > &  m)
inline

Construct from single-column Matrix by copy.

Member Function Documentation

◆ operator[]() [1/2]

template<typename T = double>
T & LinAlg::Vector< T >::operator[] ( std::size_t  i)
inline

Element access by index, no range checking, mutable.

◆ operator[]() [2/2]

template<typename T = double>
T LinAlg::Vector< T >::operator[] ( std::size_t  i) const
inline

Element access by index, no range checking, const.

◆ at() [1/2]

template<typename T = double>
T & LinAlg::Vector< T >::at ( std::size_t  i)
inline

Element access by index, with range checking, mutable.

◆ at() [2/2]

template<typename T = double>
T LinAlg::Vector< T >::at ( std::size_t  i) const
inline

Element access by index, with range checking, const.

◆ operator()() [1/2]

template<typename T = double>
T & LinAlg::Vector< T >::operator() ( std::size_t  i)
inline

Element access by index, with range checking, mutable.

◆ operator()() [2/2]

template<typename T = double>
T LinAlg::Vector< T >::operator() ( std::size_t  i) const
inline

Element access by index, with range checking, const.

◆ conj()

template<typename T >
Vector< T > LinAlg::Vector< T >::conj ( ) const

Returns element-wise complex conjugate.

◆ real()

template<typename T >
auto LinAlg::Vector< T >::real ( ) const

Returns real part of each element as a new Vector.

◆ imag()

template<typename T >
auto LinAlg::Vector< T >::imag ( ) const

Returns imaginary part of each element as a new Vector.

◆ complex()

template<typename T >
auto LinAlg::Vector< T >::complex ( ) const

Returns a complex-valued copy of this Vector.

◆ transpose()

template<typename T = double>
Vector< T > LinAlg::Vector< T >::transpose ( ) const
delete

Transpose is not defined for Vector (deleted)

◆ operator+=()

template<typename T >
Vector< T > & LinAlg::Vector< T >::operator+= ( const Vector< T > &  rhs)

Addition assignment: element-wise *this += rhs

◆ operator-=()

template<typename T >
Vector< T > & LinAlg::Vector< T >::operator-= ( const Vector< T >  rhs)

Subtraction assignment: element-wise *this -= rhs

◆ operator*=()

template<typename T >
Vector< T > & LinAlg::Vector< T >::operator*= ( const T  x)

Scalar multiplication assignment: *this *= x

◆ operator/=()

template<typename T >
Vector< T > & LinAlg::Vector< T >::operator/= ( const T  x)

Scalar division assignment: *this /= x

◆ as_gsl_view() [1/2]

template<typename T >
auto LinAlg::Vector< T >::as_gsl_view ( )

Returns a GSL vector view of the underlying data (no copy). The Vector must remain in scope for the lifetime of the view.

◆ as_gsl_view() [2/2]

template<typename T >
auto LinAlg::Vector< T >::as_gsl_view ( ) const

Returns a const GSL vector view of the underlying data (no copy). The Vector must remain in scope for the lifetime of the view.

Friends And Related Symbol Documentation

◆ operator+

template<typename T = double>
Vector< T > operator+ ( Vector< T >  lhs,
const Matrix< T > &  rhs 
)
friend

Element-wise addition: lhs + rhs

◆ operator-

template<typename T = double>
Vector< T > operator- ( Vector< T >  lhs,
const Matrix< T > &  rhs 
)
friend

Element-wise subtraction: lhs - rhs

◆ operator* [1/4]

template<typename T = double>
Vector< T > operator* ( const T  x,
Vector< T >  rhs 
)
friend

Scalar multiplication: x * v

◆ operator* [2/4]

template<typename T = double>
Vector< T > operator* ( Vector< T >  lhs,
const T  x 
)
friend

Scalar multiplication: v * x

◆ operator/

template<typename T = double>
Vector< T > operator/ ( Vector< T >  lhs,
const T  x 
)
friend

Scalar division: v / x

◆ operator* [3/4]

template<typename T = double>
Vector< T > operator* ( const Matrix< T > &  a,
const Vector< T > &  b 
)
friend

Matrix-vector product: returns A * b, i.e. v_i = sum_j A_ij * b_j

◆ operator* [4/4]

template<typename T = double>
T operator* ( const Vector< T > &  a,
const Vector< T > &  b 
)
friend

Inner (dot) product: returns sum_i a_i * b_i

◆ outer_product

template<typename T = double>
Matrix< T > outer_product ( const Vector< T > &  a,
const Vector< T > &  b 
)
friend

Outer product: returns matrix M with M_ij = a_i * b_j


The documentation for this class was generated from the following files: