Chi-Tech
chi_data_types::NDArray< T > Class Template Reference

#include <ndarray.h>

Data Structures

struct  bool_pack
 

Public Member Functions

template<typename D >
 NDArray (const std::vector< D > &dims)
 
template<typename D , size_t N>
 NDArray (const std::array< D, N > &dims)
 
template<typename D >
 NDArray (const std::initializer_list< D > &dims)
 
template<typename D >
 NDArray (const std::vector< D > &dims, T value)
 
template<typename D , size_t N>
 NDArray (const std::array< D, N > &dims, T value)
 
template<typename D >
 NDArray (const std::initializer_list< D > &dims, T value)
 
 NDArray ()
 
 NDArray (NDArray< T > const &other)
 
NDArray< T > & operator= (NDArray< T > const &other)
 
 NDArray (NDArray< T > &&other) noexcept
 
NDArray< T > & operator= (NDArray< T > &&)=delete
 
void set (T value)
 
void swap (NDArray< T > &other)
 
size_t size () const noexcept
 
bool empty () const noexcept
 
T * begin () const noexcept
 
const T * cbegin () const noexcept
 
T * end () const noexcept
 
const T * cend () const noexcept
 
T * data () const noexcept
 
size_t rank () const noexcept
 
std::vector< size_t > dimension () const
 
template<typename D >
void resize (const std::vector< D > &dims)
 
template<typename D , size_t N>
void resize (const std::array< D, N > &dims)
 
template<typename D >
void resize (const std::initializer_list< D > &dims)
 
template<typename... Args>
T & operator() (Args... args) noexcept
 
template<typename... Args>
T const & operator() (Args... args) const noexcept
 
template<typename... Args>
T & at (Args... args) noexcept
 
template<typename... Args>
size_t MapNDtoLin (Args... args) const
 
 ~NDArray ()
 

Private Types

template<class... U>
using conjunction = std::is_same< bool_pack< true, U::value... >, bool_pack< U::value..., true > >
 
template<typename... U>
using AllIntegral = typename conjunction< std::is_integral< U >... >::type
 

Private Attributes

size_t rank_
 
size_t * dimensions_
 
size_t * strides_
 
size_t size_
 
T * base_
 

Detailed Description

template<typename T>
class chi_data_types::NDArray< T >

Definition at line 16 of file ndarray.h.

Member Typedef Documentation

◆ AllIntegral

template<typename T >
template<typename... U>
using chi_data_types::NDArray< T >::AllIntegral = typename conjunction<std::is_integral<U>...>::type
private

Definition at line 35 of file ndarray.h.

◆ conjunction

template<typename T >
template<class... U>
using chi_data_types::NDArray< T >::conjunction = std::is_same< bool_pack<true,U::value...>, bool_pack<U::value..., true> >
private

Definition at line 29 of file ndarray.h.

Constructor & Destructor Documentation

◆ NDArray() [1/9]

template<typename T >
template<typename D >
chi_data_types::NDArray< T >::NDArray ( const std::vector< D > &  dims)
inlineexplicit

Creates an array with the specified number of elements in each dimension, from a vector-list.

Parameters
dimsstd::vector list of the number of elements in each dimension.
Exceptions
std::bad_allocif memory allocation fails.

This constructor creates an array with the specified size.

Definition at line 49 of file ndarray.h.

◆ NDArray() [2/9]

template<typename T >
template<typename D , size_t N>
chi_data_types::NDArray< T >::NDArray ( const std::array< D, N > &  dims)
inlineexplicit

Creates an array with the specified number of elements in each dimension, from an array.

Parameters
dimsstd::array list of the number of elements in each dimension.
Exceptions
std::bad_allocif memory allocation fails.

This constructor creates an array with the specified size.

Definition at line 93 of file ndarray.h.

◆ NDArray() [3/9]

template<typename T >
template<typename D >
chi_data_types::NDArray< T >::NDArray ( const std::initializer_list< D > &  dims)
inline

Creates an array with the specified number of elements in each dimension, from an initializer-list.

Parameters
dimsstd::vector list of the number of elements in each dimension.
Exceptions
std::bad_allocif memory allocation fails.

This constructor creates an array with the specified size.

Definition at line 134 of file ndarray.h.

◆ NDArray() [4/9]

template<typename T >
template<typename D >
chi_data_types::NDArray< T >::NDArray ( const std::vector< D > &  dims,
value 
)
inlineexplicit

Creates an array with the specified number of elements in each dimension, from a vector. Each entry in the array is assigned the designated value.

Parameters
dimsstd::vector list of the number of elements in each dimension.
valueThe value to assing to each element.
Exceptions
std::bad_allocif memory allocation fails.

This constructor creates an array with the specified size.

Definition at line 185 of file ndarray.h.

◆ NDArray() [5/9]

template<typename T >
template<typename D , size_t N>
chi_data_types::NDArray< T >::NDArray ( const std::array< D, N > &  dims,
value 
)
inlineexplicit

Creates an array with the specified number of elements in each dimension, from an array. Each entry in the array is assigned the designated value.

Parameters
dimsstd::array list of the number of elements in each dimension.
valueThe value to assing to each element.
Exceptions
std::bad_allocif memory allocation fails.

This constructor creates an array with the specified size.

Definition at line 230 of file ndarray.h.

◆ NDArray() [6/9]

template<typename T >
template<typename D >
chi_data_types::NDArray< T >::NDArray ( const std::initializer_list< D > &  dims,
value 
)
inline

Creates an array with the specified number of elements in each dimension, from an initializer-list. Each entry in the array is assigned the designated value.

Parameters
dimsstd::initializer list of the number of elements in each dimension.
valueThe value to assing to each element.
Exceptions
std::bad_allocif memory allocation fails.

This constructor creates an array with the specified size.

Definition at line 273 of file ndarray.h.

◆ NDArray() [7/9]

template<typename T >
chi_data_types::NDArray< T >::NDArray ( )
inline

Creates an empty array.

Exceptions
std::bad_allocif memory allocation fails.

This constructor creates an empty array and initializes the reference count to one.

Definition at line 317 of file ndarray.h.

◆ NDArray() [8/9]

template<typename T >
chi_data_types::NDArray< T >::NDArray ( NDArray< T > const &  other)
inline

Copy construct from another array.

Parameters
otherThe array to copy.

Definition at line 326 of file ndarray.h.

◆ NDArray() [9/9]

template<typename T >
chi_data_types::NDArray< T >::NDArray ( NDArray< T > &&  other)
inlinenoexcept

Move constructor.

Definition at line 359 of file ndarray.h.

◆ ~NDArray()

template<typename T >
chi_data_types::NDArray< T >::~NDArray ( )
inline

Deletes the array.

The destructor deletes the underlying array data.

Definition at line 607 of file ndarray.h.

Member Function Documentation

◆ at()

template<typename T >
template<typename... Args>
T & chi_data_types::NDArray< T >::at ( Args...  args)
inlinenoexcept

Accesses the specified element with safety checks.

Parameters
argsThe indices of the desired element.
Exceptions
std::invalid_argumentif the number of arguments are incorrect and std::out_of_range if one of the dimension-indices are out of range.
Returns
Read/write reference to the element.

Definition at line 547 of file ndarray.h.

◆ begin()

template<typename T >
T * chi_data_types::NDArray< T >::begin ( ) const
inlinenoexcept

Returns an iterator pointing to the beginning of the array.

Definition at line 397 of file ndarray.h.

◆ cbegin()

template<typename T >
const T * chi_data_types::NDArray< T >::cbegin ( ) const
inlinenoexcept

Returns a constant iterator pointing to the beginning of the array.

Definition at line 400 of file ndarray.h.

◆ cend()

template<typename T >
const T * chi_data_types::NDArray< T >::cend ( ) const
inlinenoexcept

Returns a constant iterator pointing to the end of the array

Definition at line 406 of file ndarray.h.

◆ data()

template<typename T >
T * chi_data_types::NDArray< T >::data ( ) const
inlinenoexcept

Returns a pointer to the underlying array data.

Definition at line 409 of file ndarray.h.

◆ dimension()

template<typename T >
std::vector< size_t > chi_data_types::NDArray< T >::dimension ( ) const
inline

Returns the dimension of the array.

Definition at line 415 of file ndarray.h.

◆ empty()

template<typename T >
bool chi_data_types::NDArray< T >::empty ( ) const
inlinenoexcept

Returns true if the array has no elements.

Definition at line 394 of file ndarray.h.

◆ end()

template<typename T >
T * chi_data_types::NDArray< T >::end ( ) const
inlinenoexcept

Returns an iterator pointing to the end of the array.

Definition at line 403 of file ndarray.h.

◆ MapNDtoLin()

template<typename T >
template<typename... Args>
size_t chi_data_types::NDArray< T >::MapNDtoLin ( Args...  args) const
inline

Returns a linear index to the specified element with safety checks.

Parameters
argsThe indices of the desired element.
Exceptions
std::invalid_argumentif the number of arguments are incorrect and std::out_of_range if one of the dimension-indices are out of range.
Returns
Linear index to the specified element.

Definition at line 579 of file ndarray.h.

◆ operator()() [1/2]

template<typename T >
template<typename... Args>
T const & chi_data_types::NDArray< T >::operator() ( Args...  args) const
inlinenoexcept

Accesses the specified element.

Parameters
argsThe indices of the desired element.
Returns
Read reference to the element.

Definition at line 524 of file ndarray.h.

◆ operator()() [2/2]

template<typename T >
template<typename... Args>
T & chi_data_types::NDArray< T >::operator() ( Args...  args)
inlinenoexcept

Accesses the specified element.

Parameters
argsThe indices of the desired element.
Returns
Read/write reference to the element.

Definition at line 504 of file ndarray.h.

◆ operator=() [1/2]

template<typename T >
NDArray< T > & chi_data_types::NDArray< T >::operator= ( NDArray< T > &&  )
delete

Deleted move assignment operator

◆ operator=() [2/2]

template<typename T >
NDArray< T > & chi_data_types::NDArray< T >::operator= ( NDArray< T > const &  other)
inline

Assign from another array.

Parameters
otherThe array to copy.

Definition at line 352 of file ndarray.h.

◆ rank()

template<typename T >
size_t chi_data_types::NDArray< T >::rank ( ) const
inlinenoexcept

Returns the rank of the array.

Definition at line 412 of file ndarray.h.

◆ resize() [1/3]

template<typename T >
template<typename D , size_t N>
void chi_data_types::NDArray< T >::resize ( const std::array< D, N > &  dims)
inline

Resizes the array with an array.

Parameters
dimsstd::array of the number of elements in each dimension.
Exceptions
std::bad_allocif memory allocation fails.

This method resizes the array to the specified number of elements. If the current size is equal to the new size, no memory allocation occurs.

Definition at line 459 of file ndarray.h.

◆ resize() [2/3]

template<typename T >
template<typename D >
void chi_data_types::NDArray< T >::resize ( const std::initializer_list< D > &  dims)
inline

Resizes the array with an initializer_list.

Parameters
dimsstd::initializer_list of the number of elements in each dimension.
Exceptions
std::bad_allocif memory allocation fails.

This method resizes the array to the specified number of elements. If the current size is equal to the new size, no memory allocation occurs.

Definition at line 484 of file ndarray.h.

◆ resize() [3/3]

template<typename T >
template<typename D >
void chi_data_types::NDArray< T >::resize ( const std::vector< D > &  dims)
inline

Resizes the array with a vector.

Parameters
dimsstd::vector of the number of elements in each dimension.
Exceptions
std::bad_allocif memory allocation fails.

This method resizes the array to the specified number of elements. If the current size is equal to the new size, no memory allocation occurs.

Definition at line 434 of file ndarray.h.

◆ set()

template<typename T >
void chi_data_types::NDArray< T >::set ( value)
inline

Sets a value to all the items in the array.

Definition at line 372 of file ndarray.h.

◆ size()

template<typename T >
size_t chi_data_types::NDArray< T >::size ( ) const
inlinenoexcept

Returns the number of elements in the array.

Definition at line 391 of file ndarray.h.

◆ swap()

template<typename T >
void chi_data_types::NDArray< T >::swap ( NDArray< T > &  other)
inline

Swap the contents of this array with another array.

Parameters
otherThe array to swap with.

Definition at line 381 of file ndarray.h.

Field Documentation

◆ base_

template<typename T >
T* chi_data_types::NDArray< T >::base_
private

Definition at line 23 of file ndarray.h.

◆ dimensions_

template<typename T >
size_t* chi_data_types::NDArray< T >::dimensions_
private

Definition at line 20 of file ndarray.h.

◆ rank_

template<typename T >
size_t chi_data_types::NDArray< T >::rank_
private

Definition at line 19 of file ndarray.h.

◆ size_

template<typename T >
size_t chi_data_types::NDArray< T >::size_
private

Definition at line 22 of file ndarray.h.

◆ strides_

template<typename T >
size_t* chi_data_types::NDArray< T >::strides_
private

Definition at line 21 of file ndarray.h.


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