Multidimensional array API

mdarray

template<typename StorageT, typename IndexMapT = dynamic_cindex_map, typename InplaceArithmeticT = inplace_arithmetics>
class mdarray

template for a multi-dimensional array class

Template Parameters:
  • StorageT – storage object to use to keep the data

  • IndexMapT – the index map

  • InplaceArithmeticT – unary (inplace) arithmetics implementation

Public Types

typedef StorageT storage_type

type of the buffer object

typedef storage_type::value_type value_type

arrays element type

typedef IndexMapT map_type

index map type

typedef mdarray<storage_type, map_type, InplaceArithmeticT> array_type

type of the array

typedef storage_type::iterator iterator

iterator type

typedef storage_type::const_iterator const_iterator

const iterator type

typedef storage_type::reverse_iterator reverse_iterator

reverse iterator

typedef storage_type::const_reverse_iterator const_reverse_iterator

const reverse iterator

typedef InplaceArithmeticT inplace_arithmetic

inplace arithmetics type

typedef array_view<array_type> view_type

view type

typedef array_view<const array_type> const_view_type

const view type

typedef size_t size_type

type used for size

Public Functions

inline mdarray()

default constructor

inline explicit mdarray(const map_type &map, const storage_type &s)

construct from map and storage

Construct an array from an index map and a storage.

Parameters:
  • map – the index map instance

  • s – array storage

inline explicit mdarray(map_type &&map, storage_type &&s)

move construct from map and storage

Move construct an array from rvalue refernces to an index map and a storage.

Parameters:
  • map – rvalue reference to the index map

  • s – rvalue reference to the storage

template<typename ArrayT>
inline explicit mdarray(const array_view<ArrayT> &view)

constrcut from a view

This constructor creates a new array from an array view instance. The resulting array object has the same shape as the view.

Template Parameters:

ArrayT – storage type of the view

Parameters:

view – reference to the view

template<typename ...MDArrayArgsT>
inline explicit mdarray(const mdarray<MDArrayArgsT...> &array)

construction from an other array

This constructor can be used for instance along with expression templates in order to construct an array from an expression.

Template Parameters:

MDArrayArgsT – template parameters of mdarray

Parameters:

array – reference to the source array

template<typename ...MDArrayArgsT>
inline array_type &operator=(const mdarray<MDArrayArgsT...> &array)

assignment from a different array type

Assign the data from a different array type to this one.

Throws:
Template Parameters:

MDArrayArgsT – template parameters of the source type

Parameters:

array – reference to the source array

Returns:

reference to the updated array

inline array_type &operator=(const std::initializer_list<value_type> &l)

assignment from an initializer list

Assigns the values given by an initializer list to an allocated array. If the number of elements in the list does not match the number of elements in the array an exception is thrown.

Throws:

size_mismatch_error – if list size and array size do not match

Parameters:

l – reference to an initializer list

Returns:

reference to the array

inline const map_type &map() const

get index map

Returns a const reference to the index map of the array.

Returns:

reference to index map

template<typename ContainerT>
inline ContainerT shape() const

shape to container

This returns a container of type ContainerT with the number of elements stored in the array.

Template Parameters:

ContainerT – container type

Returns:

instance of ContainerT with shape data

inline size_t size() const

get size of array

Returns the total number of elements stored in the array.

Returns:

total number of elements

inline size_t rank() const

get number of dimensions

Returns the number of dimensions of the array.

Returns:

number of dimensions

inline value_type &operator[](size_t i)

get referece to element i

Returns a reference to the element at linear index i. No index checking is done! Thus use this operator with care.

Parameters:

i – linear index

Returns:

reference to the element at linear index i

inline value_type operator[](size_t i) const

get value at i

Returns the value of the element at the linar array index i. No index checking is done! Thus use this operator with care.

Parameters:

i – linear index of the element

Returns:

value of the element at linear index i

inline value_type &at(size_t i)

get value at i

Return a reference to the value at linear index i. This method performs index checking.

Throws:

index_error – if i exceeds array size

Parameters:

i – linear index of element

Returns:

reference to the value at i

inline value_type at(size_t i) const

get value at i

Return the value of element i. This method performs index checking.

Throws:

index_error – if i exceeds array size

Parameters:

i – linear index of element

Returns:

value at i

inline void insert(size_t i, const value_type &value)

insert value at index i

Insert value at index i.

Throws:

index_error – if i exceeds the size of the array

Parameters:
  • i – linear index of the element

  • value – the value to store at index i

template<typename ContainerT, typename = typename enable_element_cont<ContainerT>::type>
inline value_type &operator()(const ContainerT &index)

return element reference

Returns the reference to a single elemnt of the array determined by a multidimensional index of unsigned integers stored in a container of type ContainerT. This method performs no range checking.

Template Parameters:

ContainerT – index container type

Parameters:

index – reference to index container

Returns:

reference to the element

template<typename ContainerT, typename = typename enable_element_cont<ContainerT>::type>
inline value_type operator()(const ContainerT &index) const

return element value

Returns the value of a single elemnt of the array determined by a multidimensional index of unsigned integers stored in a container of type ContainerT. This method performs no range checking.

Template Parameters:

ContainerT – index container type

Parameters:

index – reference to index container

Returns:

value of the element

template<typename ContainerT, typename = typename enable_view_cont<ContainerT>::type>
inline array_view<const array_type> operator()(const ContainerT &slices) const

return array view

Return a view on the array determined by a set of slices stored in a container type ContainerT.

Template Parameters:

ContainerT – slice container type

Parameters:

slices – reference to the container

Returns:

array_view instance

template<typename ContainerT, typename = typename enable_view_cont<ContainerT>::type>
inline array_view<array_type> operator()(const ContainerT &slices)

return array view

Return a view on the array determined by a set of slices stored in a container type ContainerT.

Template Parameters:

ContainerT – slice container type

Parameters:

slices – reference to the container

Returns:

array_view instance

template<typename ...IndicesT, typename = typename enable_valid_index<IndicesT...>::type>
inline view_type_trait<array_type, IndicesT...>::type operator()(IndicesT... indexes)

multiindex access

The () operator allows multindex access to the data stored in the array. Like the [] operator it does not perform any checks of index ranges and should thus be used with care. However, due to the missign checks it is extremely fast. If index checking is required have a look the corresponding at() member function.

Template Parameters:

IndicesT – index types

Parameters:

indexes – list of index values

Returns:

reference to the value at the given index

template<typename ...IndicesT, typename = typename enable_valid_index<IndicesT...>::type>
inline view_type_trait<constarray_type, IndicesT...>::const_type operator()(IndicesT... indexes) const

multiindex access

The () operator allows multindex access to the data stored in the array. Like the [] operator it does not perform any checks of index ranges and should thus be used with care. However, due to the missign checks it is extremely fast. If index checking is required have a look the corresponding at() member function.

Template Parameters:

IndicesT – index types

Parameters:

indexes – list of index values

Returns:

value at the given index

inline const value_type *data() const

return const pointer

Return a const pointer to the data stored in the array.

Returns:

pointer to data

inline value_type *data()

return pointer

Return a pointer to the data stored in the array.

Returns:

pointer to data

inline value_type &front()

reference to first element

Return a reference to the first element in the linear view of the array.

Returns:

reference to first element

inline value_type front() const

value of first element

Return the value of the first element in the linear view of the array.

Returns:

value of the first element

inline value_type &back()

reference to last element

Return a reference to the last element in the linear view of the array.

Returns:

reference to last element

inline value_type back() const

value of last element

Return the value of the last element in the linear view of the array.

Returns:

value of last element

inline iterator begin()

iterator to first element

Returns a non-const iterator to the first element in the array.

Returns:

iterator to first element

inline iterator end()

iterator to last element

Returns a non-const iterator to the last element in the array.

Returns:

iterator to last element

inline const_iterator begin() const

const-iterator to first element

Returns a const-iterator to the first element in the array.

Returns:

iterator to first element

inline const_iterator end() const

const-iterator to last element

Returns a const-iterator to the last element in the array.

Returns:

iterator to last element

inline reverse_iterator rbegin()

return reverse iterator to last element

inline const_reverse_iterator rbegin() const

return const reverse iterator to last element

inline reverse_iterator rend()

return reverse iterator to 0-1 element

inline const_reverse_iterator rend() const

return const reverse iterator to 0-1 element

inline array_type &operator+=(value_type s)

unary addition of a scalar

array_type a = ...;
array_type::value_type s = ...;

a += s;
!

Parameters:

s – the scalar value to add

Returns:

array reference

template<typename ArrayT>
inline array_type &operator+=(const ArrayT &v)

unary addition of an array

array_type1 a = ...;
array_tyep2 b = ...;

a += b;
!

Template Parameters:

ArrayT – type of the array to add

Parameters:

v – reference to the array to add

Returns:

reference to the original array

inline array_type &operator-=(value_type s)

unary subtraction of a scalar

array_type a = ...;
array_type::value_type s = ...;

a -= s;
!

Parameters:

s – the scalar value to subtract

Returns:

array reference

template<typename ArrayT>
inline array_type &operator-=(const ArrayT &v)

unary subtraction of an array

array_type1 a = ...;
array_tyep2 b = ...;

a -= b;
!

Template Parameters:

ArrayT – type of the array to subtract

Parameters:

v – reference to the array to subtract

Returns:

reference to the original array

inline array_type &operator*=(value_type s)

unary multiplication of a scalar

array_type a = ...;
array_type::value_type s = ...;

a *= s;
!

Parameters:

s – the scalar value to multiply with

Returns:

array reference

template<typename ArrayT>
inline array_type &operator*=(const ArrayT &v)

unary multiplication of an array

array_type1 a = ...;
array_tyep2 b = ...;

a *= b;
!

Template Parameters:

ArrayT – type of the array to multiply

Parameters:

v – reference to the array to multiply

Returns:

reference to the original array

inline array_type &operator/=(value_type s)

unary division of a scalar

array_type a = ...;
array_type::value_type s = ...;

a /= s;
!

Parameters:

s – the scalar value to divide by

Returns:

array reference

template<typename ArrayT>
inline array_type &operator/=(const ArrayT &v)

unary division of an array

array_type1 a = ...;
array_tyep2 b = ...;

a /= b;
!

Template Parameters:

ArrayT – type of the array to divide by

Parameters:

v – reference to the array to divide by

Returns:

reference to the original array

Public Static Functions

template<typename ...ArrayArgsT>
static inline array_type create(ArrayArgsT... arguments)

generic construction function

This function can be used for easy array construction. It uses the array_factory template in the background.

Template Parameters:

ArrayArgsT – variadic argument types

Parameters:

arguments – variadic argument list

Returns:

array instance

template<typename Element1T, typename Element2T>
static inline array_type create(const std::initializer_list<Element1T> &l1, const std::initializer_list<Element2T> &l2)

construction from initializer list

This version of the static create function uses an initializer list. The first initializer list holds shape information while the second holds the data which will be stored in the array.

Template Parameters:
  • Element1T – element type of shape list

  • Element2T – element type of data list

Parameters:
  • l1 – instance of shape list

  • l2 – instance of data list

Returns:

instance of array_type

Public Static Attributes

static constexpr type_id_t type_id = type_id_map<value_type>::type_id

type ID of the element type

Operators

template<typename StorageT, typename IndexMapT, typename InplaceArithmeticT>
bool pni::operator==(const mdarray<StorageT, IndexMapT, InplaceArithmeticT> &b1, const mdarray<StorageT, IndexMapT, InplaceArithmeticT> &b2)

equality comparison operator

Returns true if thwo arrays are equal. This is the case when all element stored in the arrays are equal.

Parameters:
  • b1 – array on the lhs of the comparison

  • b2 – array on the rhs of the comparison

Returns:

true if all elements are equal, false otherwise

template<typename StorageT, typename IndexMapT, typename InplaceArithmeticT>
bool pni::operator!=(const mdarray<StorageT, IndexMapT, InplaceArithmeticT> &b1, const mdarray<StorageT, IndexMapT, InplaceArithmeticT> &b2)

inequality comparison operator

Returns true if thwo arrays are not equal.

Parameters:
  • b1 – array on the lhs of the comparison

  • b2 – array on the rhs of the comparison

Returns:

true if not equal, false otherwise

template<typename StorageT, typename IndexMapT, typename InplaceArithmeticT>
std::istream &pni::operator>>(std::istream &is, mdarray<StorageT, IndexMapT, InplaceArithmeticT> &a)

input stream operator

Read data from an input stream.

Parameters:
  • is – input stream

  • a – array where to store the data

Returns:

reference to input stream

template<typename StorageT, typename IndexMapT, typename InplaceArithmeticT>
std::ostream &pni::operator<<(std::ostream &o, const mdarray<StorageT, IndexMapT, InplaceArithmeticT> &a)

output operator

Writes content of a DArray to an output stream.

Parameters:
  • o – output stream

  • a – array to output

Returns:

output stream

array_view

template<typename ArrayT>
class array_view

provides a view on a part of an array

The ArrayView class provides a view on the part of an array. No new memory is allocated. An array view can be obtained from an array using the () operator.

darray<float32> a(std::vector<size_t>{3,4,10});

//create a (4,10) view from the above array
auto view = a(1,slice{0,4},Slice{0,10});

//the view can now be used like any other array - however, no new
//memory isallocated.

//create an array from the view
darray<float32> roi(view.shape<std::vector<size_t> >(),
                darray<float32>::storage_type(view));

Template Parameters:

ArrayT – array type for the view

Public Types

using storage_type = ArrayT

storage type

using value_type = typename ArrayT::value_type

type of the data values

using array_type = array_view<storage_type>

type of the view

using shared_ptr = std::shared_ptr<array_type>

shared pointer type

using unique_ptr = std::unique_ptr<array_type>

unique pointer type

using iterator = container_iterator<array_type>

iterator type

using const_iterator = container_iterator<const array_type>

const iterator type

using view_type = array_view<array_type>

view type

using index_type = std::vector<size_t>

index type

using inplace_arithmetic = typename ArrayT::inplace_arithmetic

inplace arithetic type

using map_type = index_map<index_type, typename ArrayT::map_type::implementation_type>

map type

Public Functions

inline array_view(storage_type &a, const array_selection &s)

constructor

Constructs a new ArrayView from an existing array and some additional information.

Parameters:
  • a – reference to the original array

  • s – selection object defining the description dimension

inline array_view(storage_type &a, array_selection &&s)

constructor

This constructor accepts an rvalue reference for the selection. In some cases this might be more efficient than copy construction.

Parameters:
  • a – reference to the original array

  • s – rvalue reference to the selection object

inline array_view(const array_type &c)

copy constructor

inline array_view(array_type &&c)

move constructor

template<typename ElementT>
inline array_type &operator=(const ElementT &e)

copy assignment operator

inline array_type &operator=(array_type &&a)

move assignment operator

template<typename ContainerT, typename = typename enable_element_cont<ContainerT>::type>
inline value_type &operator()(const ContainerT &index)

access with container index

Using a container object to hold the multidimensional indices to access view data.

Throws:

shape_mismatch_error – if size of container does not match view rank

Template Parameters:

ContainerT – container type for index values

Parameters:

index – container with multidimensional index

Returns:

reference to value at index

template<typename ContainerT, typename = typename enable_element_cont<ContainerT>::type>
inline value_type operator()(const ContainerT &index) const

access with container index

Using a container object to hold the multidimensional indices to access view data.

Throws:

shape_mismatch_error – if size of container does not match view rank

Template Parameters:

ContainerT – container type for index values

Parameters:

index – container with multidimensional index

Returns:

value at index

template<typename ...ITypes>
inline value_type &operator()(ITypes... indices)

multidimensional access to data

() operator allows access to the data using a multidimensional index represented by the arguments of the operator.

darray<Float32> data({100,200,100});
auto view = data(slice(50,75),slice(0,200),slice(25,41));
std::cout<<view(3,34,10)<<std::endl;
! This works essentially the same as for the Array template.

Template Parameters:

ITypes – index types

Parameters:

indices – instances of ITypes determining the index

Returns:

reference to the value at multidimensional index

template<typename ...ITypes>
inline value_type operator()(ITypes... indices) const

multidimensional access to data

() operator allows access to the data using a multidimensional index represented by the arguments of the operator.

darray<float32> data({100,200,100});
auto view = data(slice(50,75),slice(0,200),slice(25,41));
std::cout<<view(3,34,10)<<std::endl;
! This works essentially the same as for the Array template.

Template Parameters:

ITypes – index types

Parameters:

indices – instances of ITypes determining the multidimensional index

Returns:

value at multidimensional index

template<typename ContainerT>
inline ContainerT shape() const

get shape of the view

This returns the shape of the array view. This shape includes only those dimensions where the number of elements along the original array is not equal 1.

Returns:

Shape object

inline value_type &operator[](size_t i)

linearzed access

Provides access to the linearized data. With this operator linear access is provided to the elements of the view.

Throws:

memory_access_error – if some of the involved objects is not allocated

Parameters:

i – linear index of the element

Returns:

reference to the value at index i

inline value_type operator[](size_t i) const

linearized access

Provides const access to the linearized data. With this operator linear access is provided to the elements of the view.

Throws:

memory_access_error – if some of the involved objects is not allocated

Parameters:

i – linear index of the element

Returns:

value at index i

inline const value_type *data() const

get pointer to data

This method returns a pointer to the storage covered by the view. However, this is only possible if the selection on which the view is passed is contiguous. In the case of a non contiguous view an exception will be thrown.

Throws:

shape_mismatch_error – if selection not contiguous

Returns:

const pointer to data

inline value_type *data()

get pointer to data

This method returns a pointer to the storage covered by the view. However, this is only possible if the selection on which the view is passed is contiguous. In the case of a non contiguous view an exception will be thrown.

Throws:

shape_mismatch_error – if selection not contiguous

Returns:

const pointer to data

inline value_type &at(size_t i)

get value at index i

Return a reference to the element at linear index i within the view. Unlike the [] operators this member function will throw an exception if the index exceeds the size of the view.

Throws:

index_error – in case that the index exceeds the size of the view

Parameters:

i – index at which to get the data

Returns:

reference to the element at index i

inline value_type at(size_t i) const

get value at index i

Return the value of the element at linear index i within the view. Unlike the [] operators this member function will throw an exception if the index exceeds the size of the view.

Throws:

index_error – in case that the index exceeds the size of the view

Parameters:

i – index at which to get the data

Returns:

reference to the element at index i

inline void insert(size_t i, const value_type &v)

insert value at i

Insert a new value at the linear index i of the view.

Throws:

index_error – if i exceeds total size

Parameters:
  • i – linear index

  • v – new value to insert

inline value_type &front()

return reference to the first element

inline value_type front() const

return value of first element

inline value_type &back()

return reference ot the last vlaue

inline value_type back() const

return value of last element

inline size_t size() const

get size

Return the total number of elements referenced by this view.

Returns:

total number of elements

inline size_t rank() const

get rank of the view

Returns the number of dimensions of the array.

Returns:

number of dimensions

inline iterator begin()

iterator to first element

Return an interator to the first element of the array view.

Returns:

iterator to the first element

inline iterator end()

iterator to last element

Return an iterator to the last element of the array view.

Returns:

iterator to last element

inline const_iterator begin() const

const iterator to first element

Return an const interator to the first element of the array view.

Returns:

iterator to the first element

inline const_iterator end() const

const iterator to last element

Return an const iterator to the last+1 element of the array view. The iterator is thus invalid.

Returns:

iterator to last element

inline array_type &operator+=(value_type s)

unary addition of a scalar

array_type a = ...;
array_type::value_type s = ...;
auto view = a(0,slice(0,100),slice(3,23));

view += s;
!

Parameters:

s – the scalar value to add

Returns:

view reference

template<typename RightT>
inline array_type &operator+=(const RightT &v)

unary addition of an array

array_type1 a = ...;
array_tyep2 b = ...;
auto view = a(1,slice(0,100),slice(3,23));

view += b;
!

Template Parameters:

RightT – type of the array to add

Parameters:

v – reference to the array to add

Returns:

reference to the original view

inline array_type &operator-=(value_type s)

unary subtraction of a scalar

array_type a = ...;
array_type::value_type s = ...;
auto view = a(0,slice(0,100),slice(3,23));

view -= s;
!

Parameters:

s – the scalar value to subtract

Returns:

view reference

template<typename RightT>
inline array_type &operator-=(const RightT &v)

unary subtraction of an array

array_type1 a = ...;
array_tyep2 b = ...;

auto view = a(0,slice(0,100),slice(2,23));

view -= b;
!

Template Parameters:

RightT – type of the array to subtract

Parameters:

v – reference to the array to subtract

Returns:

reference to the original view

inline array_type &operator*=(value_type s)

unary multiplication of a scalar

array_type a = ...;
array_type::value_type s = ...;
auto view = a(slice(0,100),10,slice(2,23));

view *= s;
!

Parameters:

s – the scalar value to multiply with

Returns:

view reference

template<typename RightT>
inline array_type &operator*=(const RightT &v)

unary multiplication of an array

array_type1 a = ...;
array_tyep2 b = ...;
auto view = a(slice(0,100),100,slice(2,102));

view *= b;
!

Template Parameters:

RightT – type of the array to multiply

Parameters:

v – reference to the array to multiply

Returns:

reference to the original view

inline array_type &operator/=(value_type s)

unary division of a scalar

array_type a = ...;
array_type::value_type s = ...;
auto view = a(slice(0,100),slice(2,3),slice(4,10));

view /= s;
!

Parameters:

s – the scalar value to divide by

Returns:

array reference

template<typename RightT>
inline array_type &operator/=(const RightT &v)

unary division of an array

array_type1 a = ...;
array_tyep2 b = ...;
auto view = a(slice(0,100),10,10);

view /= b;
!

Template Parameters:

RightT – type of the array to divide by

Parameters:

v – reference to the array to divide by

Returns:

reference to the original view

inline const map_type &map() const

return reference to index map

inline bool is_contiguous() const

check if contiguous

Returns true if the view is contiguous. Otherweise false.

Returns:

true if contiguous selection, false otherwise

Public Static Attributes

static const type_id_t type_id = ArrayT::type_id

type id of the value_type

Operators

template<typename ArrayT>
bool pni::operator==(const array_view<ArrayT> &a, const array_view<ArrayT> &b)

compare two array views

Returns true if all elements of a an b are equal. The two views must have equal size. Otherwise a size_mismatch_excpetion is thrown.

Template Parameters:

ArrayT – array type for the view

Parameters:
  • a – lhs value of the operator

  • b – rhs value of the operator

Returns:

true if all elements are equal, flase otherwise

template<typename ArrayT>
bool pni::operator!=(const array_view<ArrayT> &a, const array_view<ArrayT> &b)

compare two array views

Returns false if all elements in a an b are equal. a and b must have equal size, otherwise a size_mismatch_error exception is thrown.

Template Parameters:

ArrayT – array type for the view

Parameters:
  • a – lhs value of the operator

  • b – rhs value of the operator

Returns:

false if all values are equal, true otherwise

template<typename ArrayT>
std::istream &pni::operator>>(std::istream &stream, array_view<ArrayT> &v)

input operator for view

Write data from a stream to a view.

Template Parameters:

ArrayT – array type of the view

Parameters:
  • stream – reference to the input stream

  • v – reference to the view

Returns:

reference to the modified input stream

template<typename ArrayT>
std::ostream &pni::operator<<(std::ostream &stream, const array_view<ArrayT> &v)

output operator for view

Output a view instance to a stream.

Template Parameters:

ArrayT – array type of the view

Parameters:
  • stream – reference to output stream

  • v – view instance

Returns:

reference to the modified stream

scalar

template<typename ElementT>
class scalar

Scalar template for scalar values.

This template is used in expression tempaltes. Its purpose is to give scalar values an array like interface.

Template Parameters:

ElementT – scalar type of the data stored.

Public Types

typedef ElementT value_type

native data type of the scalar

typedef scalar<ElementT> array_type

type of the scalar itself

typedef std::array<ElementT, 1> storage_type

storage type

typedef scalar_iterator<array_type> iterator

iterator

typedef scalar_iterator<const array_type> const_iterator

const iterator

typedef array_view<array_type> view_type

view type

Public Functions

inline scalar()

default constructor

inline scalar(const array_type &s)

copy constructor

inline scalar(const value_type &r)

constructor from a scalar value

inline ~scalar()

destructor

inline array_type &operator=(const value_type &v)

assignment from ElementT value

Assigns a value of type ElementT to the scalar.

Parameters:

v – value to assign

Returns:

reference to array_type

inline array_type &operator=(const array_type &v)

assignment from Scalar<ElementT>

This is the most trivial case. An object of type Scalar<ElementT> is assigned to an other object of type Scalar<ElementT>.

Parameters:

v – value of scalar<ElementT> to assign

Returns:

reference to array_type

inline operator ElementT() const

conversion operator

Allows conversion from an instance of scalar<ElementT> to a variable of type ElementT.

Returns:

value of type ElementT

inline ElementT operator[](size_t i) const

get data

Return the single data value independent of what value of i is given.

Parameters:

i – linear index of the value

Returns:

value of the scalar

inline ElementT &operator[](size_t i)

get reference to data

Return a reference to the data stored in the scalar. No matter what value of i is passed to this operator - it will always return the same reference.

Parameters:

i – index

Returns:

reference to the scalar data

inline ElementT at(size_t i) const

get data value

Return the value of the data stored in the instance no matter of the value of the index.

Parameters:

i – index

Returns:

data value

inline ElementT &at(size_t i)

get data reference

Return a reference to the data stored in the scalar no matter what index is passed to the method.

Parameters:

i – index

Returns:

reference to data

inline void insert(size_t i, const ElementT &v)

set data value

Method to set a data value. The index does not matter.

Parameters:
  • i – index

  • v – value

inline const storage_type &storage() const

get reference to the storage object

Return a const reference to the static buffer that holds the scalar data.

Returns:

reference to buffer object

template<typename ...IndicesT>
inline ElementT &operator()(IndicesT... indices)

get reference to the data

Returns the reference to the data value no matter how many or what indices are passed.

Template Parameters:

IndicesT – index types

Parameters:

indices – multidimensional index

Returns:

reference to data

template<typename ...IndicesT>
inline ElementT operator()(IndicesT... indices) const

get value of data

Return the value of the scalar. The number of indices or their type do not matter.

Template Parameters:

IndicesT – index types

Parameters:

indices – multidimensional index

Returns:

data value

template<template<typename...> class ContainerT, typename ...ContainerTemplateArgumentsT>
inline ElementT &operator()(const ContainerT<ContainerTemplateArgumentsT...>&)

get reference to data

Return a reference to the data. The multidimensional index is passed by a container. The number of indices or their value are ignored.

Template Parameters:
  • ContainerT – container template

  • ContainerTemplateArgumentsT – template arguments for the container template

Returns:

reference to the data

template<template<typename...> class ContainerT, typename ...ContainerTemplateArgumentsT>
inline ElementT operator()(const ContainerT<ContainerTemplateArgumentsT...>&) const

get data value

Return the data value. The multidimensional index is passed by a container. The number of indices or their value are ignored.

Template Parameters:
  • ContainerT – container template

  • ContainerTemplateArgumentsT – template arguments of the container template

Returns:

data value

inline size_t size() const

get size

For a scalar object this method always returns 1. This is due to the fact that one needs to allocate only one block of memory of sizeof(ElementT) bytes to hold the scalar data.

Returns:

1

inline size_t rank() const

get rank

Return the number of dimensions of the scalar. This is always 0.

Returns:

0

template<typename ContainerT>
inline ContainerT shape() const

get shape

Returns the shape of the scalar - this is a container with a single value 1.

Returns:

container with 1

inline iterator begin()

get iterator to first element

inline iterator end()

get iterator to last+1 element

inline const_iterator begin() const

get const iterator to first element

inline const_iterator end() const

get const iterator to last+1 element

Public Static Attributes

static const type_id_t type_id = type_id_map<ElementT>::type_id

type ID of the data type held by the scalar

Operators

template<typename ElementT>
bool pni::operator==(const scalar<ElementT> &a, const scalar<ElementT> &b)

== operator for scalar

Returns true if the two value of a and b are equal.

Template Parameters:

ElementT – data type for the scalar instance

Parameters:
  • a – lhs value of the operator

  • b – rhs value of the operator

Returns:

true if both are equal, false otherwise

template<typename ElementT>
bool pni::operator!=(const scalar<ElementT> &a, const scalar<ElementT> &b)

!= operator for scalar

Returns true if the two value of a and b are not equal.

Template Parameters:

ElementT – data type for the scalar instance

Parameters:
  • a – lhs value of the operator

  • b – rhs value of the operator

Returns:

false if both are equal, true otherwise

template<typename ElementT>
std::ostream &pni::operator<<(std::ostream &os, const scalar<ElementT> &s)

stream output operator

Write content to output stream.

Parameters:
  • os – output stream

  • s – scalar value

Returns:

reference to output stream

template<typename ElementT>
std::istream &pni::operator>>(std::istream &is, scalar<ElementT> &s)

input strema data

Read content from input stream

Parameters:
  • is – input stream

  • s – scalar

Returns:

reference to input stream

slice

class slice

index slice

This types represents an index slice for an array. A slice can be used to identify an index range along a single dimensions. slice objects are of particular importance for creating array_view from mdarray instancers.

A slice includes all indices between the the first and last index of the slice where the last index is not included. A stride can be passed during construction which determines the number of steps between each subsequent element. If the stride is not 1 the last index will be adopted so that the

Public Functions

inline slice()

default constructor

explicit slice(size_t first, size_t last, size_t stride = 1)

standard constructor

This is the default constructor for a Slice object.

Throws:

range_error – if the first index exceeds the last

Parameters:
  • first – first index

  • last – index

  • stride – steps between subsequent elements

explicit slice(const std::initializer_list<size_t> &l)

construction from a initializer list

This can be used for implicit conversion which is sometimes quite useful for the creation fo array views.

mdarray<...>  a({10,100});

//default construction of a view
auto v1 = a(slice(1,4),slice(50,100));

//one can also use initializer lists
auto v2 = a({1,4},{50,100});
! If the initializer list has only two elements they are treated as first and last element of the slice and the stride is set to 1. In the case of a three element initializer list the last element is considered as the stride of the slice.

Throws:

range_error – if the first element is larger than the last

Parameters:

l – initializer list

explicit slice(size_t index)

construction from a single index

Constructor uses a single index. This constructor is equivalent to use slice(index,index+1,1).

Parameters:

index – single index from which to create the slice

inline ~slice()

destructor

slice &operator=(const slice &s)

copy assignment operator

inline size_t first() const

return the first element

Returns:

first element of slice

inline size_t last() const

return last element

Returns:

last element of slice

inline size_t stride() const

return stride

Returns:

stride of the slice

Functions

PNINEXUS_EXPORT size_t pni::size(const slice &s)

compute slice size

<>

Computes the number of elements spanned by a slice.

\[ size=\frac{last-first+stride-1}{stride} \]

Parameters:

s – slice object

Returns:

number of spanned elements

PNINEXUS_EXPORT size_t pni::span(const slice &s)

compute total elements spanned

Computes the total number of elements spanned by the slice.

\[ span = last-first \]

Parameters:

s – slice for which to compute the span

Returns:

total number of elements