Basix
Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
basix::ndarray< T, N, Allocator > Class Template Reference

#include <ndarray.h>

Public Member Functions

 ndarray (std::array< size_type, N > shape, value_type value=T(), const Allocator &alloc=Allocator())
 
template<std::size_t _N = N, typename = std::enable_if_t<_N == 2>>
 ndarray (size_type rows, size_type cols, value_type value=T(), const Allocator &alloc=Allocator())
 
template<typename Vector , typename = std::enable_if_t<std::is_class<Vector>::value>>
 ndarray (std::array< size_type, N > shape, Vector &&x)
 Constructs an n-dimensional array from a vector.
 
template<typename = std::enable_if_t<N == 2>>
constexpr ndarray (std::initializer_list< std::initializer_list< T >> list)
 
template<typename Span , typename = std::enable_if_t<has_shape<Span>::value>>
constexpr ndarray (Span &s)
 
 ndarray (const ndarray &x)=default
 Copy constructor.
 
 ndarray (ndarray &&x)=default
 Move constructor.
 
 ~ndarray ()=default
 Destructor.
 
ndarrayoperator= (const ndarray &x)=default
 Copy assignment.
 
ndarrayoperator= (ndarray &&x)=default
 Move assignment.
 
template<std::size_t _N = N, typename = std::enable_if_t<_N == 2>>
constexpr reference operator() (size_type i, size_type j)
 
template<std::size_t _N = N, typename = std::enable_if_t<_N == 2>>
constexpr const_reference operator() (size_type i, size_type j) const
 
template<std::size_t _N = N, typename = std::enable_if_t<_N == 3>>
constexpr reference operator() (size_type i, size_type j, size_type k)
 Return a reference to the element at specified location (i, j, k)
 
template<std::size_t _N = N, typename = std::enable_if_t<_N == 3>>
constexpr const_reference operator() (size_type i, size_type j, size_type k) const
 Return a reference to the element at specified location (i, j, k)
 
template<std::size_t _N = N, typename = std::enable_if_t<_N == 2>>
constexpr tcb::span< value_type > row (size_type i)
 
template<std::size_t _N = N, typename = std::enable_if_t<_N == 2>>
constexpr tcb::span< const value_type > row (size_type i) const
 
template<std::size_t _N = N, typename = std::enable_if_t<_N == 3>>
constexpr ndspan< value_type, 2 > row (size_type i)
 Access a row in the array.
 
template<std::size_t _N = N, typename = std::enable_if_t<_N == 3>>
constexpr ndspan< const value_type, 2 > row (size_type i) const
 Access a row in the array (const version)
 
constexpr value_type * data () noexcept
 
constexpr const value_type * data () const noexcept
 
constexpr size_type size () const noexcept
 
template<int _N = N, typename = std::enable_if_t<_N == 2>>
constexpr std::array< size_type, 2 > strides () const noexcept
 Returns the strides of the array.
 
constexpr bool empty () const noexcept
 

Public Attributes

std::array< size_type, N > shape
 The shape of the array.
 

Static Public Attributes

static constexpr size_type rank = size_type(N)
 The rank of the array.
 

Friends

template<typename Array >
std::ostream & operator<< (std::ostream &out, const Array &array)
 Pretty printing, useful for debuging.
 

Detailed Description

template<typename T, std::size_t N, class Allocator = std::allocator<T>>
class basix::ndarray< T, N, Allocator >

This class provides a dynamic n-dimensional row-wise array data structure

Constructor & Destructor Documentation

◆ ndarray() [1/4]

template<typename T , std::size_t N, class Allocator = std::allocator<T>>
basix::ndarray< T, N, Allocator >::ndarray ( std::array< size_type, N >  shape,
value_type  value = T(),
const Allocator &  alloc = Allocator() 
)
inline

Construct an n-dimensional array

Parameters
[in]shapeThe shape the array {rows, cols}
[in]valueInitial value for all entries
[in]allocThe memory allocator for the data storage

◆ ndarray() [2/4]

template<typename T , std::size_t N, class Allocator = std::allocator<T>>
template<std::size_t _N = N, typename = std::enable_if_t<_N == 2>>
basix::ndarray< T, N, Allocator >::ndarray ( size_type  rows,
size_type  cols,
value_type  value = T(),
const Allocator &  alloc = Allocator() 
)
inline

Construct an n-dimensional array

Parameters
[in]rowsThe number of rows
[in]colsThe number of columns
[in]valueInitial value for all entries
[in]allocThe memory allocator for the data storage

◆ ndarray() [3/4]

template<typename T , std::size_t N, class Allocator = std::allocator<T>>
template<typename = std::enable_if_t<N == 2>>
constexpr basix::ndarray< T, N, Allocator >::ndarray ( std::initializer_list< std::initializer_list< T >>  list)
inlineconstexpr
Todo:
Decide what to do here Construct an n-dimensional array using nested initializer lists
Parameters
[in]listThe nested initializer list

◆ ndarray() [4/4]

template<typename T , std::size_t N, class Allocator = std::allocator<T>>
template<typename Span , typename = std::enable_if_t<has_shape<Span>::value>>
constexpr basix::ndarray< T, N, Allocator >::ndarray ( Span &  s)
inlineconstexpr

Construct an n-dimensional array from an n-dimensional span

Parameters
[in]sThe span

Member Function Documentation

◆ data() [1/2]

template<typename T , std::size_t N, class Allocator = std::allocator<T>>
constexpr const value_type* basix::ndarray< T, N, Allocator >::data ( ) const
inlineconstexprnoexcept

Get pointer to the first element of the underlying storage (const version)

Warning
Use this with caution - the data storage may be strided

◆ data() [2/2]

template<typename T , std::size_t N, class Allocator = std::allocator<T>>
constexpr value_type* basix::ndarray< T, N, Allocator >::data ( )
inlineconstexprnoexcept

Get pointer to the first element of the underlying storage

Warning
Use this with caution - the data storage may be strided

◆ empty()

template<typename T , std::size_t N, class Allocator = std::allocator<T>>
constexpr bool basix::ndarray< T, N, Allocator >::empty ( ) const
inlineconstexprnoexcept

Checks whether the container is empty

Returns
Returns true if underlying storage is empty

◆ operator()() [1/2]

template<typename T , std::size_t N, class Allocator = std::allocator<T>>
template<std::size_t _N = N, typename = std::enable_if_t<_N == 2>>
constexpr reference basix::ndarray< T, N, Allocator >::operator() ( size_type  i,
size_type  j 
)
inlineconstexpr

Return a reference to the element at specified location (i, j)

Parameters
[in]iRow index
[in]jColumn index
Returns
Reference to the (i, j) item
Note
No bounds checking is performed

◆ operator()() [2/2]

template<typename T , std::size_t N, class Allocator = std::allocator<T>>
template<std::size_t _N = N, typename = std::enable_if_t<_N == 2>>
constexpr const_reference basix::ndarray< T, N, Allocator >::operator() ( size_type  i,
size_type  j 
) const
inlineconstexpr

Return a reference to the element at specified location (i, j) (const version)

Parameters
[in]iRow index
[in]jColumn index
Returns
Reference to the (i, j) item
Note
No bounds checking is performed

◆ row() [1/2]

template<typename T , std::size_t N, class Allocator = std::allocator<T>>
template<std::size_t _N = N, typename = std::enable_if_t<_N == 2>>
constexpr tcb::span<value_type> basix::ndarray< T, N, Allocator >::row ( size_type  i)
inlineconstexpr

Access a row in the array

Parameters
[in]iRow index
Returns
Span of the row data

◆ row() [2/2]

template<typename T , std::size_t N, class Allocator = std::allocator<T>>
template<std::size_t _N = N, typename = std::enable_if_t<_N == 2>>
constexpr tcb::span<const value_type> basix::ndarray< T, N, Allocator >::row ( size_type  i) const
inlineconstexpr

Access a row in the array (const version)

Parameters
[in]iRow index
Returns
Span of the row data

◆ size()

template<typename T , std::size_t N, class Allocator = std::allocator<T>>
constexpr size_type basix::ndarray< T, N, Allocator >::size ( ) const
inlineconstexprnoexcept

Returns the number of elements in the array

Warning
Use this caution - the data storage may be strided, i.e. the size of the underlying storage may be greater than sizeof(T)*(rows * cols)

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