Volume Cartographer 2.27.0
Public Types | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
volcart::NDArray< T > Class Template Reference

Dynamically-allocated N-Dimensional Array. More...

#include <vc/core/types/NDArray.hpp>

Inheritance diagram for volcart::NDArray< T >:
[legend]

Public Types

using Container = std::vector< T >
 
using IndexType = typename Container::size_type
 
using Extent = std::vector< IndexType >
 
using Index = std::vector< IndexType >
 
using iterator = typename Container::iterator
 
using const_iterator = typename Container::const_iterator
 

Public Member Functions

 NDArray (std::size_t n)
 Default constructor. More...
 
 NDArray (std::size_t n, Extent e)
 Constructor with dimensions. More...
 
template<typename... Es>
 NDArray (std::size_t n, Es... extents)
 
template<typename InputIt >
 NDArray (std::size_t n, Extent e, InputIt first, InputIt last)
 Constructor with range initialization. More...
 
void setExtents (Extent e)
 Set the extent of the array's dimensions. More...
 
template<typename... Es>
void setExtents (Es... extents)
 
auto dims () const -> std::size_t
 Get the number of dimensions of the array. More...
 
auto extents () const -> Extent
 Get the extent (size) of the array's dimensions. More...
 
auto size () const -> std::size_t
 Get the total number of elements in the array. More...
 
auto operator() (Index index) -> T &
 Per-element access. More...
 
auto operator() (Index index) const -> const T &
 
template<typename... Is>
auto operator() (Is... indices) -> T &
 
template<typename... Is>
auto operator() (Is... indices) const -> const T &
 
auto slice (IndexType index) -> NDArray
 Get slice of array by dropping highest dimension. More...
 
auto as_vector () -> Container
 Return copy of raw data. More...
 
auto as_vector () const -> Container
 
auto data () -> typename Container::value_type *
 Get a pointer to the start of the underlying data. More...
 
auto data () const -> typename Container::value_type *
 
auto begin () -> iterator
 Return an iterator that points to the first element in the array. More...
 
auto begin () const -> const_iterator
 Return an iterator that points to the first element in the array. More...
 
auto end () -> iterator
 Return an iterator that points to the past-the-end element in the array. More...
 
auto end () const -> const_iterator
 Return an iterator that points to the past-the-end element in the array. More...
 
auto front () -> T &
 Return a reference to the first element in the array. More...
 
auto front () const -> const T &
 Return a reference to the first element in the array. More...
 
auto back () -> T &
 Return a reference to the last element in the array. More...
 
auto back () const -> const T &
 Return a reference to the last element in the array. More...
 

Static Public Member Functions

static void Flatten (NDArray &a, std::size_t dim)
 Flatten an array by dropping a dimension and appending the data to the next highest dimension. More...
 

Private Member Functions

void resize_container_ ()
 
auto index_to_data_index_ (Index i) const -> IndexType
 

Private Attributes

std::size_t dim_ {1}
 
Extent extents_
 
Container data_
 

Detailed Description

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

Dynamically-allocated N-Dimensional Array.

Array is immediately allocated upon construction.

Modified from origin project YANDA: https://github.com/csparker247/yanda

Template Parameters
TType of array elements

Definition at line 28 of file NDArray.hpp.

Member Typedef Documentation

◆ const_iterator

template<typename T >
using volcart::NDArray< T >::const_iterator = typename Container::const_iterator

Const iterator type

Definition at line 42 of file NDArray.hpp.

◆ Container

template<typename T >
using volcart::NDArray< T >::Container = std::vector<T>

Storage container alias

Definition at line 32 of file NDArray.hpp.

◆ Extent

template<typename T >
using volcart::NDArray< T >::Extent = std::vector<IndexType>

Extents type

Definition at line 36 of file NDArray.hpp.

◆ Index

template<typename T >
using volcart::NDArray< T >::Index = std::vector<IndexType>

N-Dim Array Index type

Definition at line 38 of file NDArray.hpp.

◆ IndexType

template<typename T >
using volcart::NDArray< T >::IndexType = typename Container::size_type

Container index type

Definition at line 34 of file NDArray.hpp.

◆ iterator

template<typename T >
using volcart::NDArray< T >::iterator = typename Container::iterator

Iterator type

Definition at line 40 of file NDArray.hpp.

Constructor & Destructor Documentation

◆ NDArray() [1/4]

template<typename T >
volcart::NDArray< T >::NDArray ( std::size_t  n)
inlineexplicit

Default constructor.

Definition at line 46 of file NDArray.hpp.

◆ NDArray() [2/4]

template<typename T >
volcart::NDArray< T >::NDArray ( std::size_t  n,
Extent  e 
)
inlineexplicit

Constructor with dimensions.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 49 of file NDArray.hpp.

◆ NDArray() [3/4]

template<typename T >
template<typename... Es>
volcart::NDArray< T >::NDArray ( std::size_t  n,
Es...  extents 
)
inlineexplicit

Definition at line 60 of file NDArray.hpp.

◆ NDArray() [4/4]

template<typename T >
template<typename InputIt >
volcart::NDArray< T >::NDArray ( std::size_t  n,
Extent  e,
InputIt  first,
InputIt  last 
)
inlineexplicit

Constructor with range initialization.

Definition at line 71 of file NDArray.hpp.

Member Function Documentation

◆ as_vector() [1/2]

template<typename T >
volcart::NDArray< T >::as_vector ( ) -> Container
inline

Return copy of raw data.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 174 of file NDArray.hpp.

◆ as_vector() [2/2]

template<typename T >
auto volcart::NDArray< T >::as_vector ( ) const -> Container
inline

Definition at line 177 of file NDArray.hpp.

◆ back() [1/2]

template<typename T >
auto volcart::NDArray< T >::back ( ) -> T&
inline

Return a reference to the last element in the array.

Definition at line 212 of file NDArray.hpp.

◆ back() [2/2]

template<typename T >
auto volcart::NDArray< T >::back ( ) const -> const T&
inline

Return a reference to the last element in the array.

Definition at line 215 of file NDArray.hpp.

◆ begin() [1/2]

template<typename T >
auto volcart::NDArray< T >::begin ( ) -> iterator
inline

Return an iterator that points to the first element in the array.

Definition at line 191 of file NDArray.hpp.

◆ begin() [2/2]

template<typename T >
auto volcart::NDArray< T >::begin ( ) const -> const_iterator
inline

Return an iterator that points to the first element in the array.

Definition at line 194 of file NDArray.hpp.

◆ data() [1/2]

template<typename T >
volcart::NDArray< T >::data ( ) -> typename Container::value_type*
inline

Get a pointer to the start of the underlying data.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 180 of file NDArray.hpp.

◆ data() [2/2]

template<typename T >
auto volcart::NDArray< T >::data ( ) const -> typename Container::value_type*
inline

Definition at line 183 of file NDArray.hpp.

◆ dims()

template<typename T >
auto volcart::NDArray< T >::dims ( ) const -> std::size_t
inline

Get the number of dimensions of the array.

Definition at line 113 of file NDArray.hpp.

◆ end() [1/2]

template<typename T >
auto volcart::NDArray< T >::end ( ) -> iterator
inline

Return an iterator that points to the past-the-end element in the array.

Definition at line 200 of file NDArray.hpp.

◆ end() [2/2]

template<typename T >
auto volcart::NDArray< T >::end ( ) const -> const_iterator
inline

Return an iterator that points to the past-the-end element in the array.

Definition at line 203 of file NDArray.hpp.

◆ extents()

template<typename T >
auto volcart::NDArray< T >::extents ( ) const -> Extent
inline

Get the extent (size) of the array's dimensions.

Definition at line 116 of file NDArray.hpp.

◆ Flatten()

template<typename T >
static void volcart::NDArray< T >::Flatten ( NDArray< T > &  a,
std::size_t  dim 
)
inlinestatic

Flatten an array by dropping a dimension and appending the data to the next highest dimension.

Definition at line 222 of file NDArray.hpp.

◆ front() [1/2]

template<typename T >
auto volcart::NDArray< T >::front ( ) -> T&
inline

Return a reference to the first element in the array.

Definition at line 206 of file NDArray.hpp.

◆ front() [2/2]

template<typename T >
auto volcart::NDArray< T >::front ( ) const -> const T&
inline

Return a reference to the first element in the array.

Definition at line 209 of file NDArray.hpp.

◆ index_to_data_index_()

template<typename T >
auto volcart::NDArray< T >::index_to_data_index_ ( Index  i) const -> IndexType
inlineprivate

Convert item index to data index

Definition at line 268 of file NDArray.hpp.

◆ operator()() [1/4]

template<typename T >
auto volcart::NDArray< T >::operator() ( Index  index) -> T&
inline

Per-element access.

Definition at line 124 of file NDArray.hpp.

◆ operator()() [2/4]

template<typename T >
auto volcart::NDArray< T >::operator() ( Index  index) const -> const T&
inline

Definition at line 134 of file NDArray.hpp.

◆ operator()() [3/4]

template<typename T >
template<typename... Is>
auto volcart::NDArray< T >::operator() ( Is...  indices) -> T&
inline

Definition at line 144 of file NDArray.hpp.

◆ operator()() [4/4]

template<typename T >
template<typename... Is>
auto volcart::NDArray< T >::operator() ( Is...  indices) const -> const T&
inline

Definition at line 151 of file NDArray.hpp.

◆ resize_container_()

template<typename T >
void volcart::NDArray< T >::resize_container_ ( )
inlineprivate

Resize the data container to current extents

Definition at line 254 of file NDArray.hpp.

◆ setExtents() [1/2]

template<typename T >
template<typename... Es>
void volcart::NDArray< T >::setExtents ( Es...  extents)
inline

Definition at line 107 of file NDArray.hpp.

◆ setExtents() [2/2]

template<typename T >
void volcart::NDArray< T >::setExtents ( Extent  e)
inline

Set the extent of the array's dimensions.

Warning
Does not guarantee validity of stored values after resize

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 95 of file NDArray.hpp.

◆ size()

template<typename T >
auto volcart::NDArray< T >::size ( ) const -> std::size_t
inline

Get the total number of elements in the array.

Definition at line 119 of file NDArray.hpp.

◆ slice()

template<typename T >
auto volcart::NDArray< T >::slice ( IndexType  index) -> NDArray
inline

Get slice of array by dropping highest dimension.

Definition at line 157 of file NDArray.hpp.

Member Data Documentation

◆ data_

template<typename T >
Container volcart::NDArray< T >::data_
private

Data storage

Definition at line 251 of file NDArray.hpp.

◆ dim_

template<typename T >
std::size_t volcart::NDArray< T >::dim_ {1}
private

Number of dimensions

Definition at line 247 of file NDArray.hpp.

◆ extents_

template<typename T >
Extent volcart::NDArray< T >::extents_
private

Dimension extents

Definition at line 249 of file NDArray.hpp.


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