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

ok

template<typename T = double>
class qip::Array< T >

N-dimensional array with arithmetic operators.

Stores data in a flat std::vector; indices are computed from the shape. Element-wise arithmetic (+, -, *, /) is provided between arrays of identical shape, and between an array and its element type (see operator+=, etc.). Row and column views (ArrayView) are available for 2D arrays.

#include <Array.hpp>

+ Inheritance diagram for qip::Array< T >:

Public Member Functions

template<typename... Args>
 Array (std::size_t first, Args... rest)
 Constructs an N-dimensional array with the given dimension sizes.
 
template<typename... Args>
void resize (std::size_t first, Args... rest)
 Resizes the array. Note: invalidates all underlying data.
 
std::size_t size () const
 Returns the total number of elements.
 
std::size_t size (std::size_t dim) const
 Returns the size of a specific dimension.
 
std::size_t dimensions () const
 Returns the number of dimensions.
 
const std::vector< std::size_t > & shape () const
 Returns the shape (sizes of all dimensions) of the array.
 
template<typename... Args>
Tat (std::size_t first, Args... rest)
 Access element with bounds checking.
 
template<typename... Args>
T at (std::size_t first, Args... rest) const
 Const access to element with bounds checking.
 
template<typename... Args>
Toperator() (std::size_t first, Args... rest)
 Access element without bounds checking.
 
template<typename... Args>
T operator() (std::size_t first, Args... rest) const
 Const access to element without bounds checking.
 
Tdata ()
 Pointer to the first element of the underlying contiguous storage.
 
const Tdata () const
 
const std::vector< T > & vector () const
 Const reference to the underlying flat data vector.
 
std::size_t rows () const
 Number of rows (equivalent to size(0)).
 
std::size_t cols () const
 Number of columns (equivalent to size(1)).
 
ArrayView< Trow (std::size_t i)
 A view onto the ith row. Only defined for 2D arrays.
 
ArrayView< const Trow (std::size_t i) const
 
ArrayView< Tcol (std::size_t j)
 A view onto the jth column. Only defined for 2D arrays.
 
ArrayView< const Tcol (std::size_t j) const
 
auto begin ()
 Iterator to the beginning.
 
auto cbegin () const
 Constant iterator to the beginning.
 
auto end ()
 Iterator to the end.
 
auto cend () const
 Constant iterator to the end.
 
auto rbegin ()
 Reverse iterator to the beginning of the data.
 
auto crbegin () const
 Constant reverse iterator to the beginning of the data.
 
auto rend ()
 Reverse iterator to the end of the data.
 
auto crend () const
 Constant reverse iterator to the end of the data.
 
Array< T > & operator+= (const Array< T > &other)
 Element-wise arithmetic between arrays of identical shape (+, -, *, /).
 
Array< T > & operator-= (const Array< T > &other)
 
Array< T > & operator*= (const Array< T > &other)
 
Array< T > & operator/= (const Array< T > &other)
 
Array< T > & operator+= (const T &t)
 Element-wise scalar arithmetic (+, -, *, /).
 
Array< T > & operator-= (const T &t)
 
Array< T > & operator*= (const T &t)
 
Array< T > & operator/= (const T &t)
 

Constructor & Destructor Documentation

◆ Array()

template<typename T >
template<typename... Args>
qip::Array< T >::Array ( std::size_t  first,
Args...  rest 
)

Constructs an N-dimensional array with the given dimension sizes.

e.g., Array(3,6,2) creates a 362 array.

Member Function Documentation

◆ resize()

template<typename T >
template<typename... Args>
void qip::Array< T >::resize ( std::size_t  first,
Args...  rest 
)

Resizes the array. Note: invalidates all underlying data.

◆ size() [1/2]

template<typename T = double>
std::size_t qip::Array< T >::size ( ) const
inline

Returns the total number of elements.

◆ size() [2/2]

template<typename T = double>
std::size_t qip::Array< T >::size ( std::size_t  dim) const
inline

Returns the size of a specific dimension.

◆ dimensions()

template<typename T = double>
std::size_t qip::Array< T >::dimensions ( ) const
inline

Returns the number of dimensions.

◆ shape()

template<typename T = double>
const std::vector< std::size_t > & qip::Array< T >::shape ( ) const
inline

Returns the shape (sizes of all dimensions) of the array.

◆ at() [1/2]

template<typename T >
template<typename... Args>
T & qip::Array< T >::at ( std::size_t  first,
Args...  rest 
)

Access element with bounds checking.

◆ at() [2/2]

template<typename T >
template<typename... Args>
T qip::Array< T >::at ( std::size_t  first,
Args...  rest 
) const

Const access to element with bounds checking.

◆ operator()() [1/2]

template<typename T >
template<typename... Args>
T & qip::Array< T >::operator() ( std::size_t  first,
Args...  rest 
)

Access element without bounds checking.

◆ operator()() [2/2]

template<typename T >
template<typename... Args>
T qip::Array< T >::operator() ( std::size_t  first,
Args...  rest 
) const

Const access to element without bounds checking.

◆ data()

template<typename T = double>
T * qip::Array< T >::data ( )
inline

Pointer to the first element of the underlying contiguous storage.

◆ vector()

template<typename T = double>
const std::vector< T > & qip::Array< T >::vector ( ) const
inline

Const reference to the underlying flat data vector.

◆ rows()

template<typename T = double>
std::size_t qip::Array< T >::rows ( ) const
inline

Number of rows (equivalent to size(0)).

◆ cols()

template<typename T = double>
std::size_t qip::Array< T >::cols ( ) const
inline

Number of columns (equivalent to size(1)).

◆ row()

template<typename T >
ArrayView< T > qip::Array< T >::row ( std::size_t  i)

A view onto the ith row. Only defined for 2D arrays.

◆ col()

template<typename T >
ArrayView< T > qip::Array< T >::col ( std::size_t  j)

A view onto the jth column. Only defined for 2D arrays.

◆ begin()

template<typename T = double>
auto qip::Array< T >::begin ( )
inline

Iterator to the beginning.

◆ cbegin()

template<typename T = double>
auto qip::Array< T >::cbegin ( ) const
inline

Constant iterator to the beginning.

◆ end()

template<typename T = double>
auto qip::Array< T >::end ( )
inline

Iterator to the end.

◆ cend()

template<typename T = double>
auto qip::Array< T >::cend ( ) const
inline

Constant iterator to the end.

◆ rbegin()

template<typename T = double>
auto qip::Array< T >::rbegin ( )
inline

Reverse iterator to the beginning of the data.

◆ crbegin()

template<typename T = double>
auto qip::Array< T >::crbegin ( ) const
inline

Constant reverse iterator to the beginning of the data.

◆ rend()

template<typename T = double>
auto qip::Array< T >::rend ( )
inline

Reverse iterator to the end of the data.

◆ crend()

template<typename T = double>
auto qip::Array< T >::crend ( ) const
inline

Constant reverse iterator to the end of the data.

◆ operator+=() [1/2]

template<typename T >
Array< T > & qip::Array< T >::operator+= ( const Array< T > &  other)

Element-wise arithmetic between arrays of identical shape (+, -, *, /).

◆ operator+=() [2/2]

template<typename T >
Array< T > & qip::Array< T >::operator+= ( const T t)

Element-wise scalar arithmetic (+, -, *, /).

Array op T is provided for +, -, *, /. T op Array is provided only for * and +.


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