CustomIndexArray< Typ, Tags > Class Template Reference
|
CPP API
|
A class template for an array with custom indices. More...
#include <custom_index_array.h>
Classes | |
| class | Slice |
| A Slice represents a slice of data along one dimension, given a start and end index into that dimension. More... | |
Public Types | |
| using | const_iterator = typename InternalArrayType::const_iterator |
| using | Index = ::mio::Index< Tags... > |
| using | InternalArrayType = Eigen::Array< Type, Eigen::Dynamic, 1 > |
| using | iterator = typename InternalArrayType::iterator |
| using | reference = Type & |
| using | Type = Typ |
| using | value_type = Type |
Public Member Functions | |
| auto & | array () |
| auto const & | array () const |
| array returns a reference to the internally stored flat array. More... | |
| iterator | begin () |
| Get a start iterator for the elements. More... | |
| const_iterator | begin () const |
| Get a start iterator for the elements. More... | |
| template<class OtherType > | |
| requires std::convertible_to< Type, OtherType > CustomIndexArray< OtherType, Tags... > | convert () const |
| Convert internally stored data to OtherType and save into new CustomIndexArray. More... | |
| CustomIndexArray () | |
| Create an empty CustomIndexArray with size 0. Use the resize member function to add entries. More... | |
| template<std::input_or_output_iterator Iter> | |
| CustomIndexArray (Index const &dims, Iter b, Iter e) | |
| Initializes array with values from a range. More... | |
| iterator | end () |
| Get an end iterator for the elements. More... | |
| const_iterator | end () const |
| Get an end iterator for the elements. More... | |
| size_t | get_flat_index (Index const &index) const |
| get_flat_index returns the flat index into the stored array, given the indices of each category More... | |
| Ts | m_numel (product(dims)) |
| Ts | m_y (InternalArrayType::Constant(m_numel, 1, Type{std::forward< Ts >(args)...})) |
| constexpr size_t | numel () const |
| numel returns the number of elements More... | |
| CustomIndexArray & | operator= (const Type &scalar) |
| Assign the same value to each element of the array. More... | |
| Type & | operator[] (Index const &index) |
| returns the entry of the array given a MultiIndex More... | |
| Type const & | operator[] (Index const &index) const |
| returns the entry of the array given a flat index index More... | |
| template<class... Ts> | |
| requires (std::is_constructible_v< Type, Ts... >) CustomIndexArray(Index const &dims | |
CustomIndexArray constructor, that initializes the array to constant instances of CustsomIndexArray::Type. More... | |
| void | resize (Index new_dims) |
| Resize all dimensions, invalidating entries. More... | |
| template<class Tag > | |
| void | resize (mio::Index< Tag > new_dim) |
| Resize a single dimension, invalidating entries. More... | |
| template<class IOContext > | |
| void | serialize (IOContext &io) const |
| serialize this. More... | |
| void | set_multiple (const std::vector< typename CustomIndexArray< Typ, Tags... >::Index > &indices, const Typ &value) |
| Set multiple entries to the same value. More... | |
| template<typename Tag > | |
| mio::Index< Tag > | size () const |
| returns the size along the dimension provided as template parameter More... | |
| Index | size () const |
| returns the size of the array along all dimensions. More... | |
| bool | operator== (const CustomIndexArray &other) const |
| Equality comparison. More... | |
| bool | operator!= (const CustomIndexArray &other) const |
| Equality comparison. More... | |
| template<typename Tag > | |
| Slice< Tag, iterator > | slice (Seq< size_t > idx_seq) |
| Creates a slice into the multidimensional array. More... | |
| template<typename Tag > | |
| Slice< Tag, const_iterator > | slice (Seq< size_t > idx_seq) const |
| Creates a slice into the multidimensional array. More... | |
| template<typename Tag > | |
| Slice< Tag, iterator > | slice (mio::Index< Tag > idx) |
| Creates a slice into the multidimensional array. More... | |
| template<typename Tag > | |
| Slice< Tag, const_iterator > | slice (mio::Index< Tag > idx) const |
| Creates a slice into the multidimensional array. More... | |
| template<typename Tag > | |
| requires std::is_enum_v< Tag > Slice< Tag, iterator > | slice (Tag idx) |
| Creates a slice into the multidimensional array. More... | |
| template<typename Tag > | |
| requires std::is_enum_v< Tag > Slice< Tag, const_iterator > | slice (Tag idx) const |
| Creates a slice into the multidimensional array. More... | |
Static Public Member Functions | |
| template<class IOContext > | |
| static IOResult< CustomIndexArray > | deserialize (IOContext &io) |
| deserialize an object of this class. More... | |
Public Attributes | |
| Ts && | args: m_dimensions{dims} |
Static Protected Member Functions | |
| template<class IOContext , class Derived > | |
| static IOResult< Derived > | deserialize (IOContext &io, Tag< Derived >) |
| deserialize an object of a class derived from this class. More... | |
Private Attributes | |
| Index | m_dimensions |
| size_t | m_numel |
| InternalArrayType | m_y {} |
Detailed Description
template<class Typ, class... Tags>
class mio::CustomIndexArray< Typ, Tags >
A class template for an array with custom indices.
This class stores an array of elements that can be queried using a MultiIndex. Each index in the MultiIndex is associated with a category, or dimension into a multidimensional array.
Example:
struct AgeGroup{};
enum class Gender { Female, Male, Diverse, Count, //number of values in the enum to allow iterating over the enum }; struct Gender{};
CustomIndexArray<size_t, AgeGroup, Gender> populations({Index<AgeGroup>(2), Index<Gender>(Gender::Count)});
Here, populations represents a 2x3 size_t array (though the data is stored contigously). An element can be accessed using a MultiIndex:
auto x = populations[{Index<AgeGroup>(0), Index<Gender>(Gender::Female)}];
If the category is an enum class, the Index class can be omitted for convenience in almost all cases since Index<E> is implicitly constructible from enum type E, e.g.:
CustomIndexArray<size_t, AgeGroup, Gender> populations({Index<AgeGroup>(2), Gender::Count}); auto x = populations[{Index<AgeGroup>(0), Gender::Female}];
- Template Parameters
-
Typ the type stored in the array Tags Types that tag the custom Index types, must be unique.
Member Typedef Documentation
◆ const_iterator
| using mio::CustomIndexArray< Typ, Tags >::const_iterator = typename InternalArrayType::const_iterator |
◆ Index
| using mio::CustomIndexArray< Typ, Tags >::Index = ::mio::Index<Tags...> |
◆ InternalArrayType
| using mio::CustomIndexArray< Typ, Tags >::InternalArrayType = Eigen::Array<Type, Eigen::Dynamic, 1> |
◆ iterator
| using mio::CustomIndexArray< Typ, Tags >::iterator = typename InternalArrayType::iterator |
◆ reference
| using mio::CustomIndexArray< Typ, Tags >::reference = Type& |
◆ Type
| using mio::CustomIndexArray< Typ, Tags >::Type = Typ |
◆ value_type
| using mio::CustomIndexArray< Typ, Tags >::value_type = Type |
Constructor & Destructor Documentation
◆ CustomIndexArray() [1/2]
|
inlineexplicit |
Create an empty CustomIndexArray with size 0. Use the resize member function to add entries.
◆ CustomIndexArray() [2/2]
|
inline |
Initializes array with values from a range.
Each element of the array will be assigned the corresponding value from the range.
- Template Parameters
-
Iter Iterator class.
- Parameters
-
dims dimensions of the array. b begin of the range of values. e end of the range of values.
Member Function Documentation
◆ array() [1/2]
|
inline |
◆ array() [2/2]
|
inline |
array returns a reference to the internally stored flat array.
- Returns
- const reference to the CustomIndexArray::InternalArrayType instance
◆ begin() [1/2]
|
inline |
Get a start iterator for the elements.
- Returns
- random access iterator
◆ begin() [2/2]
|
inline |
Get a start iterator for the elements.
- Returns
- random access iterator
◆ convert()
|
inline |
Convert internally stored data to OtherType and save into new CustomIndexArray.
- Template Parameters
-
OtherType The type to convert into.
- Returns
- New CustomIndexArray of OtherType with copy of internal data.
◆ deserialize() [1/2]
|
inlinestatic |
deserialize an object of this class.
- See also
- mio::deserialize
◆ deserialize() [2/2]
|
inlinestaticprotected |
deserialize an object of a class derived from this class.
- See also
- mio::deserialize
◆ end() [1/2]
|
inline |
Get an end iterator for the elements.
- Returns
- random access iterator
◆ end() [2/2]
|
inline |
Get an end iterator for the elements.
- Returns
- random access iterator
◆ get_flat_index()
|
inline |
get_flat_index returns the flat index into the stored array, given the indices of each category
- Parameters
-
indices the custom indices for each category
- Returns
- a flat index into the data structure storing the compartment populations
◆ m_numel()
| Ts mio::CustomIndexArray< Typ, Tags >::m_numel | ( | product(dims) | ) |
◆ m_y()
|
inline |
◆ numel()
|
inlineconstexpr |
numel returns the number of elements
This corresponds to the product of the dimension sizes
- Returns
- number of elements
◆ operator!=()
|
inline |
Equality comparison.
◆ operator=()
|
inline |
Assign the same value to each element of the array.
- Parameters
-
scalar scalar value.
◆ operator==()
|
inline |
Equality comparison.
◆ operator[]() [1/2]
|
inline |
returns the entry of the array given a MultiIndex
- Parameters
-
MultiIndex
- Returns
- the value at the index
◆ operator[]() [2/2]
|
inline |
returns the entry of the array given a flat index index
- Parameters
-
index a flat index
- Returns
- the value at the index
◆ requires()
| mio::CustomIndexArray< Typ, Tags >::requires | ( | std::is_constructible_v< Type, Ts... > | ) | const & |
CustomIndexArray constructor, that initializes the array to constant instances of CustsomIndexArray::Type.
It forwards the arguments for initializer_list construction of the contained objects.
- Template Parameters
-
Ts The argument types of the constructor arguments of Type
- Parameters
-
args The constructor arguments of Type
◆ resize() [1/2]
|
inline |
Resize all dimensions, invalidating entries.
All entries of the CustomIndexArray should be reassigned a new value after a resize, as it may delete or reorder entries in an unexpected way. Newly added entries are default constructed.
- Parameters
-
new_dims New dimensions.
◆ resize() [2/2]
|
inline |
Resize a single dimension, invalidating entries.
All entries of the CustomIndexArray should be reassigned a new value after a resize, as it may delete or reorder entries in an unexpected way. Newly added entries are default constructed.
- Parameters
-
new_dim New dimension size.
- Template Parameters
-
Tag The dimension to resize.
◆ serialize()
|
inline |
serialize this.
- See also
- mio::serialize
◆ set_multiple()
|
inline |
Set multiple entries to the same value.
- Parameters
-
indices A list of indices to be set to the same value. value The value to set.
◆ size() [1/2]
|
inline |
returns the size along the dimension provided as template parameter
- Template Parameters
-
Tag Tag of the queried dimension/category
- Returns
- size along a specified dimension
◆ size() [2/2]
|
inline |
returns the size of the array along all dimensions.
- Returns
- multi-index with size of the array along all dimensions.
◆ slice() [1/6]
|
inline |
Creates a slice into the multidimensional array.
Selects a single index of one dimension.
- Template Parameters
-
The Tag corresponding to the dimension of the slice
- Parameters
-
idx index to be selected for the slice.
◆ slice() [2/6]
|
inline |
Creates a slice into the multidimensional array.
Selects a single index of one dimension.
- Template Parameters
-
The Tag corresponding to the dimension of the slice
- Parameters
-
idx index to be selected for the slice.
◆ slice() [3/6]
|
inline |
Creates a slice into the multidimensional array.
Selects a sequence of indices of one dimension.
- Template Parameters
-
The Tag corresponding to the dimension of the slice
- Parameters
-
idx_seq An index sequence, consisting of the first index, the number of indices and a stride
- Returns
- The slice
◆ slice() [4/6]
|
inline |
Creates a slice into the multidimensional array.
Selects a sequence of indices of one dimension.
- Template Parameters
-
The Tag corresponding to the dimension of the slice
- Parameters
-
idx_seq An index sequence, consisting of the first index, the number of indices and a stride
- Returns
- The slice
◆ slice() [5/6]
|
inline |
Creates a slice into the multidimensional array.
Selects a single index of one dimension.
- Template Parameters
-
The Tag corresponding to the dimension of the slice
- Parameters
-
idx index to be selected for the slice.
◆ slice() [6/6]
|
inline |
Creates a slice into the multidimensional array.
Selects a single index of one dimension.
- Template Parameters
-
The Tag corresponding to the dimension of the slice
- Parameters
-
idx index to be selected for the slice.
Member Data Documentation
◆ args
| Ts&& mio::CustomIndexArray< Typ, Tags >::args |
◆ m_dimensions
|
private |
◆ m_numel
|
private |
◆ m_y
|
private |
Generated by