11#ifndef QUGAR_LIBRARY_TENSOR_INDEX_TP_HPP
12#define QUGAR_LIBRARY_TENSOR_INDEX_TP_HPP
32template<
int dim>
class TensorIndexTP;
75 [[nodiscard]]
int size()
const;
101 template<
int aux_dim = dim>
102 requires(aux_dim == dim && dim > 0)
106 template<
int aux_dim = dim>
107 requires(aux_dim == dim && dim == 0)
114 template<
int aux_dim = dim>
115 requires(aux_dim == dim && dim > 0)
134 template<
int aux_dim = dim>
135 requires(aux_dim == dim && dim > 0)
141 assert(0 <= flat_index && flat_index < total_size);
143 for (
int dir = dim - 1; dir >= 0; --dir) {
144 total_size /= size(dir);
145 const auto ind = flat_index / total_size;
146 this->operator()(dir) = ind;
147 flat_index -= ind * total_size;
158 template<
int aux_dim = dim>
159 requires(aux_dim == dim && dim > 0)
165 template<
typename... T>
166 requires(dim > 1 &&
sizeof...(T) == dim && std::conjunction_v<std::is_same<int, T>...>)
194 template<
typename S> [[nodiscard]]
int flat(
const S &size)
const;
215 template<
int aux_dim = dim>
216 requires(aux_dim == dim && dim > 1)
225 [[nodiscard]] std::size_t
hash()
const;
231template<
int dim>
struct hash<
qugar::TensorIndexTP<dim>>
271 [[nodiscard]]
int size()
const;
277 [[nodiscard]] std::array<TensorIndexRangeTP<dim>, 2>
split()
const;
303 [[nodiscard]]
int flat()
const;
Iterator class for tensor index ranges.
Definition tensor_index_tp.hpp:282
TensorIndexTP< dim > index_
Iterator index.
Definition tensor_index_tp.hpp:328
bool operator!=(const Iterator &rhs) const
Compares if two iterators are different. They are considered to be different if at least one of the c...
const TensorIndexTP< dim > & operator*() const
Dereference operator.
Iterator & operator++()
Pre increments the iterator.
bool operator==(const Iterator &rhs) const
Compares if two iterators are equal. They are considered to be equal if their indices and bounds are ...
const TensorIndexTP< dim > * operator->() const
Indirection operator.
int flat() const
Transforms the current tensor index into a flat one by considering the upper bound as associated size...
TensorIndexTP< dim > lower_bound_
Lower bound.
Definition tensor_index_tp.hpp:330
Iterator operator++(int)
Post increments the iterator.
Iterator(const TensorIndexTP< dim > &index, const TensorIndexTP< dim > &lower_bound, const TensorIndexTP< dim > &upper_bound)
Constructs a new iterator object given and index and its lower and upper bounds.
TensorIndexTP< dim > upper_bound_
Upper bound.
Definition tensor_index_tp.hpp:332
Class representing a dim-dimensional range defined by lower and upper tensor bounds.
Definition tensor_index_tp.hpp:243
bool is_in_range(int index) const
Checks that the given index is contained in the range.
std::array< TensorIndexRangeTP< dim >, 2 > split() const
Splits the current range along the direction with a largest number of indices.
TensorIndexRangeTP(int upper_bound)
Constructs a new TensorIndexRangeTP object from its upper bound. The lower bound is assumed to be zer...
TensorIndexRangeTP(const TensorIndexTP< dim > &upper_bound)
Constructs a new TensorIndexRangeTP object from its upper bound. The lower bound is assumed to be zer...
Iterator cbegin() const
Creates a begin iterator.
TensorSizeTP< dim > get_sizes() const
Gets the sizes along all the directions.
const TensorIndexTP< dim > & get_upper_bound() const
Gets the upper bound.
TensorIndexRangeTP(const TensorIndexTP< dim > &lower_bound, const TensorIndexTP< dim > &upper_bound)
Constructs a new TensorIndexRangeTP object from its lower and upper bounds.
TensorIndexTP< dim > upper_bound_
Upper bounds.
Definition tensor_index_tp.hpp:375
int size() const
returns the number of entries in the range.
bool is_in_range(const TensorIndexTP< dim > &index) const
Checks that the given index is contained in the range.
Iterator end() const
Creates an end iterator.
Iterator begin() const
Creates a begin iterator.
const TensorIndexTP< dim > & get_lower_bound() const
Gets the lower bound.
TensorIndexTP< dim > lower_bound_
Lower bounds.
Definition tensor_index_tp.hpp:373
TensorIndexRangeTP(const TensorSizeTP< dim > &upper_bound)
Constructs a new TensorIndexRangeTP object from its upper bound. The lower bound is assumed to be zer...
Iterator cend() const
Creates an end iterator.
Class representing a dim-dimensional tensor-product indices.
Definition tensor_index_tp.hpp:95
TensorIndexTP(int ind)
Constructs a new TensorIndexTP object from an index.
Definition tensor_index_tp.hpp:116
bool operator<(const TensorIndexTP< dim > &rhs) const
Checks if the current tensor index is smaller than rhs. To determine if one is smaller than the other...
TensorIndexTP()
Definition tensor_index_tp.hpp:108
const Vector< int, dim > & as_Vector() const
Returns the tensor index casted as a Vector.
Definition tensor_index_tp.hpp:176
TensorIndexTP()
Default constructor. Initializes indices to zero.
Definition tensor_index_tp.hpp:103
Vector< int, dim > & as_Vector()
Returns the tensor index casted as a Vector.
TensorIndexTP< dim - 1 > remove_component(int comp) const
Creates a new index by removing one of its component.
TensorIndexTP(T... indices)
Constructs the tensor index from an argument list.
Definition tensor_index_tp.hpp:167
int flat(const S &size) const
Gets the flat index associated to the current tensor index for a given tensor size.
TensorIndexTP(const TensorSizeTP< dim > &indices)
Constructs a new TensorIndexTP object from its indices.
TensorIndexTP(int flat_index, const TensorIndexTP< dim > &size)
Constructs a new TensorIndexTP object from a flat index and an associated tensor size following the l...
Definition tensor_index_tp.hpp:136
TensorIndexTP(int flat_index, const TensorSizeTP< dim > &size)
Constructs a new TensorIndexTP object from a flat index and an associated tensor size following the l...
Definition tensor_index_tp.hpp:160
bool operator!=(const TensorIndexTP< dim > &rhs) const
Checks if two tensor indices are different by comparing all its components. They are different if at ...
std::size_t hash() const
Computes a hash value for the tensor index.
TensorIndexTP(const Vector< int, dim > &indices)
Constructs a new TensorIndexTP object from its indices.
bool operator==(const TensorIndexTP< dim > &rhs) const
Checks if two tensor indices are equal by comparing all its components. They are equal if all the com...
Class representing a dim-dimensional tensor-product sizes container.
Definition tensor_index_tp.hpp:38
TensorSizeTP< dim > operator+(const TensorSizeTP< dim > &rhs) const
Adds two TensorSizeTP objects.
int size() const
Gets the total number of entries (product of sizes along all directions).
TensorSizeTP(const TensorIndexTP< dim > &sizes)
Construct a new TensorSizeTP object from sizes along directions.
const Vector< int, dim > & as_Vector() const
Returns the tensor size casted as a Vector.
Vector< int, dim > & as_Vector()
Returns the tensor size casted as a Vector.
TensorSizeTP()
Default constructor. Initializes indices to zero.
bool operator==(const TensorSizeTP< dim > &rhs) const
Checks if two tensor sizes are equal by comparing all its components. They are equal if all the compo...
TensorSizeTP(const Vector< int, dim > &sizes)
Construct a new TensorSizeTP object from sizes along directions.
TensorSizeTP(const int size)
Construct a new TensorSizeTP object from size along directions.
QUGaR's main namespace.
Definition affine_transf.hpp:28
::algoim::uvector< T, dim > Vector
Class representing a vector.
Definition vector.hpp:31
std::ptrdiff_t index
Definition types.hpp:19
Definition tensor_index_tp.hpp:230
size_t operator()(const qugar::TensorIndexTP< dim > &tid) const noexcept
Definition tensor_index_tp.hpp:233