Multidimensional array API¶
mdarray
¶
-
template<typename
StorageT
, typenameIndexMapT
= dynamic_cindex_map, typenameInplaceArithmeticT
= inplace_arithmetics>
classpni
::
mdarray
¶ template for a multi-dimensional array class
- Template Parameters
StorageT
: storage object to use to keep the dataIndexMapT
: the index mapInplaceArithmeticT
: unary (inplace) arithmetics implementation
Public Types
-
typedef storage_type::value_type
value_type
¶ arrays element 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
-
mdarray
()¶ default constructor
-
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 instances
: array storage
-
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 maps
: rvalue reference to the storage
-
template<typename
ArrayT
>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
>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
>
array_type &operator=
(const mdarray<MDArrayArgsT...> &array)¶ assignment from a different array type
Assign the data from a different array type to this one.
- Return
reference to the updated array
- Exceptions
size_mismatch_error
: if array sizes do not matchshape_mismatch_error
: if shapes do not match
- Template Parameters
MDArrayArgsT
: template parameters of the source type
- Parameters
array
: reference to the source array
-
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.
- Return
reference to the array
- Exceptions
size_mismatch_error
: if list size and array size do not match
- Parameters
l
: reference to an initializer list
-
const map_type &
map
() const¶ get index map
Returns a const reference to the index map of the array.
- Return
reference to index map
-
template<typename
ContainerT
>
ContainerTshape
() const¶ shape to container
This returns a container of type ContainerT with the number of elements stored in the array.
- Return
instance of ContainerT with shape data
- Template Parameters
ContainerT
: container type
-
size_t
size
() const¶ get size of array
Returns the total number of elements stored in the array.
- Return
total number of elements
-
size_t
rank
() const¶ get number of dimensions
Returns the number of dimensions of the array.
- Return
number of dimensions
-
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.
- Return
reference to the element at linear index i
- Parameters
i
: linear index
-
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.
- Return
value of the element at linear index i
- Parameters
i
: linear index of the element
-
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.
- Return
reference to the value at i
- Exceptions
index_error
: if i exceeds array size
- Parameters
i
: linear index of element
-
value_type
at
(size_t i) const¶ get value at i
Return the value of element i. This method performs index checking.
- Return
value at i
- Exceptions
index_error
: if i exceeds array size
- Parameters
i
: linear index of element
-
void
insert
(size_t i, const value_type &value)¶ insert value at index i
Insert value at index i.
- Exceptions
index_error
: if i exceeds the size of the array
- Parameters
i
: linear index of the elementvalue
: the value to store at index i
-
template<typename
ContainerT
, typename = typename enable_element_cont<ContainerT>::type>
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.
- Return
reference to the element
- Template Parameters
ContainerT
: index container type
- Parameters
index
: reference to index container
-
template<typename
ContainerT
, typename = typename enable_element_cont<ContainerT>::type>
value_typeoperator()
(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.
- Return
value of the element
- Template Parameters
ContainerT
: index container type
- Parameters
index
: reference to index container
-
template<typename
ContainerT
, typename = typename enable_view_cont<ContainerT>::type>
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.
- Return
array_view instance
- Template Parameters
ContainerT
: slice container type
- Parameters
slices
: reference to the container
-
template<typename
ContainerT
, typename = typename enable_view_cont<ContainerT>::type>
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.
- Return
array_view instance
- Template Parameters
ContainerT
: slice container type
- Parameters
slices
: reference to the container
-
template<typename ...
IndicesT
, typename = typename enable_valid_index<IndicesT...>::type>
view_type_trait<array_type, IndicesT...>::typeoperator()
(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.
- Return
reference to the value at the given index
- Template Parameters
IndicesT
: index types
- Parameters
indexes
: list of index values
-
template<typename ...
IndicesT
, typename = typename enable_valid_index<IndicesT...>::type>
view_type_trait<const array_type, IndicesT...>::const_typeoperator()
(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.
- Return
value at the given index
- Template Parameters
IndicesT
: index types
- Parameters
indexes
: list of index values
-
const value_type *
data
() const¶ return const pointer
Return a const pointer to the data stored in the array.
- Return
pointer to data
-
value_type *
data
()¶ return pointer
Return a pointer to the data stored in the array.
- Return
pointer to data
-
value_type &
front
()¶ reference to first element
Return a reference to the first element in the linear view of the array.
- Return
reference to first element
-
value_type
front
() const¶ value of first element
Return the value of the first element in the linear view of the array.
- Return
value of the first element
-
value_type &
back
()¶ reference to last element
Return a reference to the last element in the linear view of the array.
- Return
reference to last element
-
value_type
back
() const¶ value of last element
Return the value of the last element in the linear view of the array.
- Return
value of last element
-
iterator
begin
()¶ iterator to first element
Returns a non-const iterator to the first element in the array.
- Return
iterator to first element
-
iterator
end
()¶ iterator to last element
Returns a non-const iterator to the last element in the array.
- Return
iterator to last element
-
const_iterator
begin
() const¶ const-iterator to first element
Returns a const-iterator to the first element in the array.
- Return
iterator to first element
-
const_iterator
end
() const¶ const-iterator to last element
Returns a const-iterator to the last element in the array.
- Return
iterator to last element
-
reverse_iterator
rbegin
()¶ return reverse iterator to last element
-
const_reverse_iterator
rbegin
() const¶ return const reverse iterator to last element
-
reverse_iterator
rend
()¶ return reverse iterator to 0-1 element
-
const_reverse_iterator
rend
() const¶ return const reverse iterator to 0-1 element
-
array_type &
operator+=
(value_type s)¶ unary addition of a scalar
!array_type a = ...; array_type::value_type s = ...; a += s;
- Return
array reference
- Parameters
s
: the scalar value to add
-
template<typename
ArrayT
>
array_type &operator+=
(const ArrayT &v)¶ unary addition of an array
!array_type1 a = ...; array_tyep2 b = ...; a += b;
- Return
reference to the original array
- Template Parameters
ArrayT
: type of the array to add
- Parameters
v
: reference to the array to add
-
array_type &
operator-=
(value_type s)¶ unary subtraction of a scalar
!array_type a = ...; array_type::value_type s = ...; a -= s;
- Return
array reference
- Parameters
s
: the scalar value to subtract
-
template<typename
ArrayT
>
array_type &operator-=
(const ArrayT &v)¶ unary subtraction of an array
!array_type1 a = ...; array_tyep2 b = ...; a -= b;
- Return
reference to the original array
- Template Parameters
ArrayT
: type of the array to subtract
- Parameters
v
: reference to the array to subtract
-
array_type &
operator*=
(value_type s)¶ unary multiplication of a scalar
!array_type a = ...; array_type::value_type s = ...; a *= s;
- Return
array reference
- Parameters
s
: the scalar value to multiply with
-
template<typename
ArrayT
>
array_type &operator*=
(const ArrayT &v)¶ unary multiplication of an array
!array_type1 a = ...; array_tyep2 b = ...; a *= b;
- Return
reference to the original array
- Template Parameters
ArrayT
: type of the array to multiply
- Parameters
v
: reference to the array to multiply
-
array_type &
operator/=
(value_type s)¶ unary division of a scalar
!array_type a = ...; array_type::value_type s = ...; a /= s;
- Return
array reference
- Parameters
s
: the scalar value to divide by
-
template<typename
ArrayT
>
array_type &operator/=
(const ArrayT &v)¶ unary division of an array
!array_type1 a = ...; array_tyep2 b = ...; a /= b;
- Return
reference to the original array
- Template Parameters
ArrayT
: type of the array to divide by
- Parameters
v
: reference to the array to divide by
Public Static Functions
-
template<typename ...
ArrayArgsT
>
array_typecreate
(ArrayArgsT... arguments)¶ generic construction function
This function can be used for easy array construction. It uses the array_factory template in the background.
- Return
array instance
- Template Parameters
ArrayArgsT
: variadic argument types
- Parameters
arguments
: variadic argument list
-
template<typename
Element1T
, typenameElement2T
>
array_typecreate
(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.
- Return
instance of array_type
- Template Parameters
Element1T
: element type of shape listElement2T
: element type of data list
- Parameters
l1
: instance of shape listl2
: instance of data list
Public Static Attributes
-
constexpr type_id_t
type_id
= type_id_map<value_type>::type_id¶ type ID of the element type
Operators¶
-
template<typename
StorageT
, typenameIndexMapT
, typenameInplaceArithmeticT
>
boolpni
::
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.
- Return
true if all elements are equal, false otherwise
- Parameters
b1
: array on the lhs of the comparisonb2
: array on the rhs of the comparison
-
template<typename
StorageT
, typenameIndexMapT
, typenameInplaceArithmeticT
>
boolpni
::
operator!=
(const mdarray<StorageT, IndexMapT, InplaceArithmeticT> &b1, const mdarray<StorageT, IndexMapT, InplaceArithmeticT> &b2)¶ inequality comparison operator
Returns true if thwo arrays are not equal.
- Return
true if not equal, false otherwise
- Parameters
b1
: array on the lhs of the comparisonb2
: array on the rhs of the comparison
-
template<typename
StorageT
, typenameIndexMapT
, typenameInplaceArithmeticT
>
std::istream &pni
::
operator>>
(std::istream &is, mdarray<StorageT, IndexMapT, InplaceArithmeticT> &a)¶ input stream operator
Read data from an input stream.
- Return
reference to input stream
- Parameters
is
: input streama
: array where to store the data
-
template<typename
StorageT
, typenameIndexMapT
, typenameInplaceArithmeticT
>
std::ostream &pni
::
operator<<
(std::ostream &o, const mdarray<StorageT, IndexMapT, InplaceArithmeticT> &a)¶ output operator
Writes content of a DArray to an output stream.
- Return
output stream
- Parameters
o
: output streama
: array to output
array_view
¶
-
template<typename
ArrayT
>
classpni
::
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
array_type
= array_view<storage_type>¶ type of the view
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
map_type
= index_map<index_type, typename ArrayT::map_type::implementation_type>¶ map type
Public Functions
-
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 arrays
: selection object defining the description dimension
-
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 arrays
: rvalue reference to the selection object
-
array_view
(const array_type &c)¶ copy constructor
-
array_view
(array_type &&c)¶ move constructor
-
template<typename
ElementT
>
array_type &operator=
(const ElementT &e)¶ copy assignment operator
-
array_type &
operator=
(array_type &&a)¶ move assignment operator
-
template<typename
ContainerT
, typename = typename enable_element_cont<ContainerT>::type>
value_type &operator()
(const ContainerT &index)¶ access with container index
Using a container object to hold the multidimensional indices to access view data.
- Return
reference to value at index
- Exceptions
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
-
template<typename
ContainerT
, typename = typename enable_element_cont<ContainerT>::type>
value_typeoperator()
(const ContainerT &index) const¶ access with container index
Using a container object to hold the multidimensional indices to access view data.
- Return
value at index
- Exceptions
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
-
template<typename ...
ITypes
>
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.
! This works essentially the same as for the Array template.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;
- Return
reference to the value at multidimensional index
- Template Parameters
ITypes
: index types
- Parameters
indices
: instances of ITypes determining the index
-
template<typename ...
ITypes
>
value_typeoperator()
(ITypes... indices) const¶ multidimensional access to data
() operator allows access to the data using a multidimensional index represented by the arguments of the operator.
! This works essentially the same as for the Array template.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;
- Return
value at multidimensional index
- Template Parameters
ITypes
: index types
- Parameters
indices
: instances of ITypes determining the multidimensional index
-
template<typename
ContainerT
>
ContainerTshape
() 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.
- Return
Shape object
-
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.
- Return
reference to the value at index i
- Exceptions
memory_access_error
: if some of the involved objects is not allocated
- Parameters
i
: linear index of the element
-
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.
- Return
value at index i
- Exceptions
memory_access_error
: if some of the involved objects is not allocated
- Parameters
i
: linear index of the element
-
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.
- Return
const pointer to data
- Exceptions
shape_mismatch_error
: if selection not contiguous
-
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.
- Return
const pointer to data
- Exceptions
shape_mismatch_error
: if selection not contiguous
-
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.
- Return
reference to the element at index i
- Exceptions
index_error
: in case that the index exceeds the size of the view
- Parameters
i
: index at which to get the data
-
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.
- Return
reference to the element at index i
- Exceptions
index_error
: in case that the index exceeds the size of the view
- Parameters
i
: index at which to get the data
-
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.
- Exceptions
index_error
: if i exceeds total size
- Parameters
i
: linear indexv
: new value to insert
-
value_type &
front
()¶ return reference to the first element
-
value_type
front
() const¶ return value of first element
-
value_type &
back
()¶ return reference ot the last vlaue
-
value_type
back
() const¶ return value of last element
-
size_t
size
() const¶ get size
Return the total number of elements referenced by this view.
- Return
total number of elements
-
size_t
rank
() const¶ get rank of the view
Returns the number of dimensions of the array.
- Return
number of dimensions
-
iterator
begin
()¶ iterator to first element
Return an interator to the first element of the array view.
- Return
iterator to the first element
-
iterator
end
()¶ iterator to last element
Return an iterator to the last element of the array view.
- Return
iterator to last element
-
const_iterator
begin
() const¶ const iterator to first element
Return an const interator to the first element of the array view.
- Return
iterator to the first element
-
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.
- Return
iterator to last element
-
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;
- Return
view reference
- Parameters
s
: the scalar value to add
-
template<typename
RightT
>
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;
- Return
reference to the original view
- Template Parameters
RightT
: type of the array to add
- Parameters
v
: reference to the array to add
-
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;
- Return
view reference
- Parameters
s
: the scalar value to subtract
-
template<typename
RightT
>
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;
- Return
reference to the original view
- Template Parameters
RightT
: type of the array to subtract
- Parameters
v
: reference to the array to subtract
-
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;
- Return
view reference
- Parameters
s
: the scalar value to multiply with
-
template<typename
RightT
>
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;
- Return
reference to the original view
- Template Parameters
RightT
: type of the array to multiply
- Parameters
v
: reference to the array to multiply
-
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;
- Return
array reference
- Parameters
s
: the scalar value to divide by
-
template<typename
RightT
>
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;
- Return
reference to the original view
- Template Parameters
RightT
: type of the array to divide by
- Parameters
v
: reference to the array to divide by
-
bool
is_contiguous
() const¶ check if contiguous
Returns true if the view is contiguous. Otherweise false.
- Return
true if contiguous selection, false otherwise
Operators¶
-
template<typename
ArrayT
>
boolpni
::
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.
- Return
true if all elements are equal, flase otherwise
- Template Parameters
ArrayT
: array type for the view
- Parameters
a
: lhs value of the operatorb
: rhs value of the operator
-
template<typename
ArrayT
>
boolpni
::
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.
- Return
false if all values are equal, true otherwise
- Template Parameters
ArrayT
: array type for the view
- Parameters
a
: lhs value of the operatorb
: rhs value of the operator
-
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.
- Return
reference to the modified input stream
- Template Parameters
ArrayT
: array type of the view
- Parameters
stream
: reference to the input streamv
: reference to the view
-
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.
- Return
reference to the modified stream
- Template Parameters
ArrayT
: array type of the view
- Parameters
stream
: reference to output streamv
: view instance
scalar
¶
-
template<typename
ElementT
>
classpni
::
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 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
-
scalar
()¶ default constructor
-
scalar
(const array_type &s)¶ copy constructor
-
scalar
(const value_type &r)¶ constructor from a scalar value
-
~scalar
()¶ destructor
-
array_type &
operator=
(const value_type &v)¶ assignment from ElementT value
Assigns a value of type ElementT to the scalar.
- Return
reference to array_type
- Parameters
v
: value to assign
-
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>.
- Return
reference to array_type
- Parameters
v
: value of scalar<ElementT> to assign
-
operator ElementT
() const¶ conversion operator
Allows conversion from an instance of scalar<ElementT> to a variable of type ElementT.
- Return
value of type ElementT
-
ElementT
operator[]
(size_t i) const¶ get data
Return the single data value independent of what value of i is given.
- Return
value of the scalar
- Parameters
i
: linear index of the value
-
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.
- Return
reference to the scalar data
- Parameters
i
: index
-
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.
- Return
data value
- Parameters
i
: index
-
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.
- Return
reference to data
- Parameters
i
: index
-
void
insert
(size_t i, const ElementT &v)¶ set data value
Method to set a data value. The index does not matter.
- Parameters
i
: indexv
: value
-
const storage_type &
storage
() const¶ get reference to the storage object
Return a const reference to the static buffer that holds the scalar data.
- Return
reference to buffer object
-
template<typename ...
IndicesT
>
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.
- Return
reference to data
- Template Parameters
IndicesT
: index types
- Parameters
indices
: multidimensional index
-
template<typename ...
IndicesT
>
ElementToperator()
(IndicesT... indices) const¶ get value of data
Return the value of the scalar. The number of indices or their type do not matter.
- Return
data value
- Template Parameters
IndicesT
: index types
- Parameters
indices
: multidimensional index
-
template<template<typename...> class
ContainerT
, typename ...ContainerTemplateArgumentsT
>
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.
- Return
reference to the data
- Template Parameters
ContainerT
: container templateContainerTemplateArgumentsT
: template arguments for the container template
-
template<template<typename...> class
ContainerT
, typename ...ContainerTemplateArgumentsT
>
ElementToperator()
(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.
- Return
data value
- Template Parameters
ContainerT
: container templateContainerTemplateArgumentsT
: template arguments of the container template
-
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.
- Return
1
-
size_t
rank
() const¶ get rank
Return the number of dimensions of the scalar. This is always 0.
- Return
0
-
template<typename
ContainerT
>
ContainerTshape
() const¶ get shape
Returns the shape of the scalar - this is a container with a single value 1.
- Return
container with 1
-
const_iterator
begin
() const¶ get const iterator to first element
-
const_iterator
end
() const¶ get const iterator to last+1 element
Operators¶
-
template<typename
ElementT
>
boolpni
::
operator==
(const scalar<ElementT> &a, const scalar<ElementT> &b)¶ == operator for scalar
Returns true if the two value of a and b are equal.
- Return
true if both are equal, false otherwise
- Template Parameters
ElementT
: data type for the scalar instance
- Parameters
a
: lhs value of the operatorb
: rhs value of the operator
-
template<typename
ElementT
>
boolpni
::
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.
- Return
false if both are equal, true otherwise
- Template Parameters
ElementT
: data type for the scalar instance
- Parameters
a
: lhs value of the operatorb
: rhs value of the operator
slice
¶
-
class
pni
::
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
-
slice
()¶ default constructor
-
slice
(size_t first, size_t last, size_t stride = 1)¶ standard constructor
This is the default constructor for a Slice object.
- Exceptions
range_error
: if the first index exceeds the last
- Parameters
first
: first indexlast
: indexstride
: steps between subsequent elements
-
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.
! 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.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});
- Exceptions
range_error
: if the first element is larger than the last
- Parameters
l
: initializer list
-
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
-
~slice
()¶ destructor
-
size_t
first
() const¶ return the first element
- Return
first element of slice
-
size_t
last
() const¶ return last element
- Return
last element of slice
-
size_t
stride
() const¶ return stride
- Return
stride of the slice
-