Converts a tensor element specification into a linear index. More...
#include <TensorIndices.h>
Public Types | |
using | Index_t = Base_t::Index_t |
Type of a single index in the tensor. More... | |
using | DimSize_t = Base_t::DimSize_t |
Type for the specification of a dimension size. More... | |
using | LinIndex_t = Base_t::LinIndex_t |
Type of the linear index. More... | |
using | MinorTensor_t = TensorIndices< rank()-1 > |
Type of the tensor indices with rank smaller by one. More... | |
Public Member Functions | |
template<typename... OTHERDIMS> | |
TensorIndices (DimSize_t first, OTHERDIMS...others) | |
Constructor: initialises the dimension of the tensor. More... | |
template<typename ITER , typename = std::enable_if_t <std::is_convertible<decltype(*(ITER())), DimSize_t>::value, void>> | |
TensorIndices (ITER dimIter) | |
Constructor: initialises the dimension of the tensor. More... | |
template<typename... OTHERINDICES> | |
LinIndex_t | operator() (Index_t first, OTHERINDICES...others) const |
Returns the linear index corresponding to the tensor indices. More... | |
template<typename ITER > | |
std::enable_if_t < std::is_convertible < decltype(*(ITER())), DimSize_t >::value, LinIndex_t > | operator() (ITER indexIter) const |
Returns the linear index corresponding to the tensor indices. More... | |
template<typename... OTHERINDICES> | |
LinIndex_t | at (Index_t first, OTHERINDICES...others) const |
Returns the linear index corresponding to the tensor indices. More... | |
template<typename ITER > | |
std::enable_if_t < std::is_convertible < decltype(*(ITER())), DimSize_t >::value, LinIndex_t > | at (ITER indexIter) const |
Returns the linear index corresponding to the tensor indices. More... | |
template<typename... OTHERINDICES> | |
bool | has (Index_t first, OTHERINDICES...others) const |
Returns whether the specified set of indices is valid. More... | |
template<typename ITER > | |
std::enable_if_t < std::is_convertible < decltype(*(ITER())), DimSize_t >::value, bool > | has (ITER indexIter) const |
Returns whether the specified set of indices is valid. More... | |
template<unsigned int DIM> | |
DimSize_t | dim () const |
Returns the size of the specified dimension. More... | |
template<unsigned int DIM> | |
bool | hasIndex (Index_t index) const |
Returns whether a index is valid within a specified dimension. More... | |
template<unsigned int DIM = 0> | |
DimSize_t | size () const |
Returns the size of the minor tensor. More... | |
bool | hasLinIndex (LinIndex_t linIndex) const |
Returns whether the specified linear index is valid in this tensor. More... | |
MinorTensor_t const & | minorTensor () const |
bool | operator== (TensorIndices< RANK > const &t) const |
Returns whether all sizes of the tensor t are the same as this one. More... | |
bool | operator!= (TensorIndices< RANK > const &t) const |
Returns whether any size of the tensor t is different from this one. More... | |
Static Public Member Functions | |
static constexpr unsigned int | rank () |
Rank of this tensor. More... | |
Protected Member Functions | |
DimSize_t | totalSize () const |
Returns the total size of this tensor (the same as size() ) More... | |
Protected Attributes | |
MinorTensor_t | m |
the rest of the tensor indices More... | |
DimSize_t | totSize |
size of this tensor More... | |
Private Types | |
using | Base_t = TensorIndices< 1U > |
type of base class More... | |
Friends | |
template<unsigned int R, unsigned int D> | |
struct | details::ExtractTensorDimension |
Converts a tensor element specification into a linear index.
Example to use a 6 x 3 x 2 x 4 tensor of rank 4:
This will map the content of the vector v
as a tensor of rank 4.
Definition at line 46 of file TensorIndices.h.
|
private |
type of base class
Definition at line 177 of file TensorIndices.h.
using util::TensorIndices< RANK >::DimSize_t = Base_t::DimSize_t |
Type for the specification of a dimension size.
Definition at line 185 of file TensorIndices.h.
using util::TensorIndices< RANK >::Index_t = Base_t::Index_t |
Type of a single index in the tensor.
Definition at line 182 of file TensorIndices.h.
using util::TensorIndices< RANK >::LinIndex_t = Base_t::LinIndex_t |
Type of the linear index.
Definition at line 188 of file TensorIndices.h.
using util::TensorIndices< RANK >::MinorTensor_t = TensorIndices<rank() - 1> |
Type of the tensor indices with rank smaller by one.
Definition at line 195 of file TensorIndices.h.
|
inline |
Constructor: initialises the dimension of the tensor.
OTHERINDICES | types of the other index values |
first | the size of the first dimension |
others | size of each of the other dimensions |
Example to initialise indices for a 6 x 3 x 2 x 4 tensor of rank 4:
Definition at line 211 of file TensorIndices.h.
|
inline |
Constructor: initialises the dimension of the tensor.
ITER | type of iterator to dimension sizes |
dimIter | iterator pointing to the first dimension size |
Dimensions are initialised from the values pointed by the specified iterator. The iterator is required to be a forward iterator pointing to a type convertible to a DimSize_t
type. The iterator must be valid when increased up to rank() - 1
times, so that all the rank()
dimensions can be extracted.
Example to initialise indices for a 6 x 3 x 2 x 4 tensor of rank 4:
Note that no end
iterator is required.
Definition at line 240 of file TensorIndices.h.
|
inline |
Returns the linear index corresponding to the tensor indices.
OTHERINDICES | types of the other index values |
first | the index of the first dimension |
others | the indices of the other dimensions |
std::out_of_range | if any of the indices is not valid |
If any of the index values is not in the valid index range, an exception is thrown.
Use it as:
(in the example, note that the last line has two indices out of range and an exception will be thrown).
Definition at line 321 of file TensorIndices.h.
|
inline |
Returns the linear index corresponding to the tensor indices.
ITER | type of iterator to dimension sizes |
indexIter | iterator pointing to the first dimension size |
std::out_of_range | if any of the indices is not valid |
If any of the index values is not in the valid index range, an exception is thrown.
Use it as:
The behaviour is the same as in at()(Index_t first, OTHERINDICES... others)
.
Definition at line 351 of file TensorIndices.h.
|
inline |
Returns the size of the specified dimension.
DIM | the dimension (0 is the first one) |
Code won't compile for DIM larger than the tensor rank.
Definition at line 424 of file TensorIndices.h.
|
inline |
Returns whether the specified set of indices is valid.
OTHERINDICES | types of the other index values |
first | the index of the first dimension |
others | the indices of the other dimensions |
If any of the index values is not in the valid index range, an exception is thrown.
Use it as:
(in the example, note that the last line has two indices out of range and an exception will be thrown).
Definition at line 384 of file TensorIndices.h.
|
inline |
Returns whether the specified set of indices is valid.
ITER | type of iterator to dimension sizes |
indexIter | iterator pointing to the first dimension size |
If any of the index values is not in the valid index range, an exception is thrown.
Use it as:
The behaviour is the same as in has()(Index_t first, OTHERINDICES... others)
.
Definition at line 412 of file TensorIndices.h.
|
inline |
Returns whether a index is valid within a specified dimension.
DIM | the dimension (0 is the first one) |
index | the value of the index to be tested |
Use it as:
Definition at line 453 of file TensorIndices.h.
|
inline |
Returns whether the specified linear index is valid in this tensor.
Definition at line 478 of file TensorIndices.h.
|
inline |
Returns the tensor of rank Rank-1
from stripping the first dimension Note that the minorTensor variable was previously named "minor". However, minor is also defined in sys/types.h to mean something completely different.
Definition at line 485 of file TensorIndices.h.
|
inline |
Returns whether any size of the tensor t is different from this one.
Definition at line 492 of file TensorIndices.h.
|
inline |
Returns the linear index corresponding to the tensor indices.
OTHERINDICES | types of the other index values |
first | the index of the first dimension |
others | the indices of the other dimensions |
No check is performed on the validity of the indices (that is, whether they fall within the dimension range).
Use it as:
(in the example, note that the last line has two indices out of range and the return value will not be valid!).
Definition at line 265 of file TensorIndices.h.
|
inline |
Returns the linear index corresponding to the tensor indices.
ITER | type of iterator to dimension sizes |
indexIter | iterator pointing to the first dimension size |
No check is performed on the validity of the indices (that is, whether they fall within the dimension range).
Use it as:
The behaviour is the same as in operator()(Index_t first, OTHERINDICES... others)
.
Definition at line 291 of file TensorIndices.h.
|
inline |
Returns whether all sizes of the tensor t are the same as this one.
Definition at line 488 of file TensorIndices.h.
|
inlinestatic |
|
inline |
Returns the size of the minor tensor.
DIM | the index of the outer dimension of the minor tensor |
The total size of the tensor obtained after stripping the DIM most outer dimensions if returned. Therefore, size<0>()
is the size of the full tensor, while size<1>()
is the size of the tensor obtained by stripping the first dimension (that is, the tensor returned by minor()
), and so on.
Code won't compile for DIM larger than the tensor rank.
Definition at line 471 of file TensorIndices.h.
|
inlineprotected |
Returns the total size of this tensor (the same as size()
)
Definition at line 506 of file TensorIndices.h.
|
friend |
Definition at line 500 of file TensorIndices.h.
|
protected |
the rest of the tensor indices
Definition at line 502 of file TensorIndices.h.
|
protected |
size of this tensor
Definition at line 503 of file TensorIndices.h.