xoptional_assembly_base¶
Defined in xtensor/xoptional_assembly_base.hpp
- template <class D>
-
class
xt::xoptional_assembly_base¶ Base class for dense multidimensional optional assemblies.
The xoptional_assembly_base class defines the interface for dense multidimensional optional assembly classes. Optional assembly classes hold optional values and are optimized for tensor operations. xoptional_assembly_base does not embed any data container, this responsibility is delegated to the inheriting classes.
- Template Parameters
D: The derived type, i.e. the inheriting class for which xoptional_assembly_base provides the interface.
Inherits from xt::xiterable< D >
Size and shape
-
auto
size() const¶ Returns the number of element in the optional assembly.
-
constexpr auto
dimension() const¶ Returns the number of dimensions of the optional assembly.
-
auto
shape() const¶ Returns the shape of the optional assembly.
-
auto
shape(size_type index) const¶ Returns the i-th dimension of the expression.
-
auto
strides() const¶ Returns the strides of the optional assembly.
-
auto
backstrides() const¶ Returns the backstrides of the optional assembly.
- template <class S = shape_type>
-
void
resize(const S &shape, bool force = false)¶ Resizes the optional assembly.
- Parameters
shape: the new shapeforce: force reshaping, even if the shape stays the same (default: false)
- template <class S = shape_type>
-
void
resize(const S &shape, layout_type l)¶ Resizes the optional assembly.
- Parameters
shape: the new shapel: the new layout_type
- template <class S = shape_type>
-
void
resize(const S &shape, const strides_type &strides)¶ Resizes the optional assembly.
- Parameters
shape: the new shapestrides: the new strides
-
layout_type
layout() const¶ Return the layout_type of the container.
- Return
- layout_type of the container
- template <class T>
-
void
fill(const T &value)¶ Fills the data with the given value.
- Parameters
value: the value to fill the data with.
- template <class S>
-
auto &
reshape(const S &shape, layout_type layout)¶ Reshapes the optional assembly.
- Parameters
shape: the new shapelayout: the new layout
Data
- template <class… Args>
-
bool
in_bounds(Args... args) const¶ Returns
trueonly if the the specified position is a valid entry in the expression.- Return
- bool
- Parameters
args: a list of indices specifying the position in the expression.
- template <class… Args>
-
auto
operator()(Args... args)¶ Returns a reference to the element at the specified position in the optional assembly.
- Parameters
args: a list of indices specifying the position in the optional assembly. Indices must be unsigned integers, the number of indices should be equal or greater than the number of dimensions of the optional assembly.
- template <class… Args>
-
auto
operator()(Args... args) const¶ Returns a constant reference to the element at the specified position in the optional assembly.
- Parameters
args: a list of indices specifying the position in the optional assembly. Indices must be unsigned integers, the number of indices should be equal or greater than the number of dimensions of the optional assembly.
- template <class… Args>
-
auto
at(Args... args)¶ Returns a reference to the element at the specified position in the optional assembly, after dimension and bounds checking.
- Parameters
args: a list of indices specifying the position in the optional assembly. Indices must be unsigned integers, the number of indices should be equal to the number of dimensions of the optional assembly.
- Exceptions
std::out_of_range: if the number of argument is greater than the number of dimensions or if indices are out of bounds.
- template <class… Args>
-
auto
at(Args... args) const¶ Returns a constant reference to the element at the specified position in the optional assembly, after dimension and bounds checking.
- Parameters
args: a list of indices specifying the position in the optional assembly. Indices must be unsigned integers, the number of indices should be equal to the number of dimensions of the optional assembly.
- Exceptions
std::out_of_range: if the number of argument is greater than the number of dimensions or if indices are out of bounds.
- template <class… Args>
-
auto
unchecked(Args... args)¶ Returns a reference to the element at the specified position in the optional assembly.
- Warning
- This method is meant for performance, for expressions with a dynamic number of dimensions (i.e. not known at compile time). Since it may have undefined behavior (see parameters), operator() should be prefered whenever it is possible.
- Warning
- This method is NOT compatible with broadcasting, meaning the following code has undefined behavior:
xt::xarray<double> a = {{0, 1}, {2, 3}}; xt::xarray<double> b = {0, 1}; auto fd = a + b; double res = fd.uncheked(0, 1);
- Parameters
args: a list of indices specifying the position in the optional assembly. Indices must be unsigned integers, the number of indices must be equal to the number of dimensions of the optional assembly, else the behavior is undefined.
- template <class… Args>
-
auto
unchecked(Args... args) const¶ Returns a constant reference to the element at the specified position in the optional assembly.
- Warning
- This method is meant for performance, for expressions with a dynamic number of dimensions (i.e. not known at compile time). Since it may have undefined behavior (see parameters), operator() should be prefered whenever it is possible.
- Warning
- This method is NOT compatible with broadcasting, meaning the following code has undefined behavior:
xt::xarray<double> a = {{0, 1}, {2, 3}}; xt::xarray<double> b = {0, 1}; auto fd = a + b; double res = fd.uncheked(0, 1);
- Parameters
args: a list of indices specifying the position in the optional assembly. Indices must be unsigned integers, the number of indices must be equal to the number of dimensions of the optional assembly, else the behavior is undefined.
- template <class S>
-
auto
operator[](const S &index)¶ Returns a reference to the element at the specified position in the optional assembly.
- Parameters
index: a sequence of indices specifying the position in the optional assembly. Indices must be unsigned integers, the number of indices in the list should be equal or greater than the number of dimensions of the optional assembly.
- template <class S>
-
auto
operator[](const S &index) const¶ Returns a constant reference to the element at the specified position in the optional assembly.
- Parameters
index: a sequence of indices specifying the position in the optional assembly. Indices must be unsigned integers, the number of indices in the list should be equal or greater than the number of dimensions of the optional assembly.
- template <class… Args>
-
auto
periodic(Args... args)¶ Returns a reference to the element at the specified position in the optional assembly, after applying periodicity to the indices (negative and ‘overflowing’ indices are changed).
- Parameters
args: a list of indices specifying the position in the optional assembly. Indices must be unsigned integers, the number of indices should be equal to the number of dimensions of the optional assembly.
- template <class… Args>
-
auto
periodic(Args... args) const¶ Returns a constant reference to the element at the specified position in the optional assembly, after applying periodicity to the indices (negative and ‘overflowing’ indices are changed).
- Parameters
args: a list of indices specifying the position in the optional assembly. Indices must be unsigned integers, the number of indices should be equal to the number of dimensions of the optional assembly.
- template <class It>
-
auto
element(It first, It last)¶ Returns a reference to the element at the specified position in the optional assembly.
- Parameters
first: iterator starting the sequence of indiceslast: iterator ending the sequence of indices The number of indices in the sequence should be equal to or greater than the number of dimensions of the optional assembly.
- template <class It>
-
auto
element(It first, It last) const¶ Returns a constant reference to the element at the specified position in the optional assembly.
- Parameters
first: iterator starting the sequence of indiceslast: iterator ending the sequence of indices The number of indices in the sequence should be equal to or greater than the number of dimensions of the optional assembly.
Broadcasting
- template <class S>
-
bool
broadcast_shape(S &shape, bool reuse_cache = false) const¶ Broadcast the shape of the optional assembly to the specified parameter.
- Return
- a boolean indicating whether the broadcasting is trivial
- Parameters
shape: the result shapereuse_cache: parameter for internal optimization
- template <class S>
-
bool
has_linear_assign(const S &strides) const¶ Checks whether the xoptional_assembly_base can be linearly assigned to an expression with the specified strides.
- Return
- a boolean indicating whether a linear assign is possible
-
auto
value()¶ Return an expression for the values of the optional assembly.
-
auto
value() const¶ Return a constant expression for the values of the optional assembly.
-
auto
has_value()¶ Return an expression for the missing mask of the optional assembly.
-
auto
has_value() const¶ Return a constant expression for the missing mask of the optional assembly.
Public Functions
- template <layout_type L>
-
auto
begin() Returns an iterator to the first element of the expression.
- Template Parameters
L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L, class S>
-
auto
begin(const S &shape) Returns an iterator to the first element of the expression.
The iteration is broadcasted to the specified shape.
- Parameters
shape: the shape used for broadcasting
- Template Parameters
S: type of theshapeparameter.L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L>
-
auto
begin() const Returns a constant iterator to the first element of the expression.
- Template Parameters
L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L, class S>
-
auto
begin(const S &shape) const Returns a constant iterator to the first element of the expression.
The iteration is broadcasted to the specified shape.
- Parameters
shape: the shape used for broadcasting
- Template Parameters
S: type of theshapeparameter.L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L>
-
auto
end() Returns an iterator to the element following the last element of the expression.
- Template Parameters
L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L, class S>
-
auto
end(const S &shape) Returns an iterator to the element following the last element of the expression.
The iteration is broadcasted to the specified shape.
- Parameters
shape: the shape used for broadcasting
- Template Parameters
S: type of theshapeparameter.L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L>
-
auto
end() const Returns a constant iterator to the element following the last element of the expression.
- Template Parameters
L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L, class S>
-
auto
end(const S &shape) const Returns a constant iterator to the element following the last element of the expression.
The iteration is broadcasted to the specified shape.
- Parameters
shape: the shape used for broadcasting
- Template Parameters
S: type of theshapeparameter.L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L>
-
auto
rbegin() Returns an iterator to the first element of the reversed expression.
- Template Parameters
L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L, class S>
-
auto
rbegin(const S &shape) Returns an iterator to the first element of the reversed expression.
The iteration is broadcasted to the specified shape.
- Parameters
shape: the shape used for broadcasting
- Template Parameters
S: type of theshapeparameter.L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L>
-
auto
rbegin() const Returns a constant iterator to the first element of the reversed expression.
- Template Parameters
L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L, class S>
-
auto
rbegin(const S &shape) const Returns a constant iterator to the first element of the reversed expression.
The iteration is broadcasted to the specified shape.
- Parameters
shape: the shape used for broadcasting
- Template Parameters
S: type of theshapeparameter.L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L>
-
auto
rend() Returns an iterator to the element following the last element of the reversed expression.
- Template Parameters
L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L, class S>
-
auto
rend(const S &shape) Returns an iterator to the element following the last element of the reversed expression.
The iteration is broadcasted to the specified shape.
- Parameters
shape: the shape used for broadcasting
- Template Parameters
S: type of theshapeparameter.L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L>
-
auto
rend() const Returns a constant iterator to the element following the last element of the reversed expression.
- Template Parameters
L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.
- template <layout_type L, class S>
-
auto
rend(const S &shape) const Returns a constant iterator to the element following the last element of the reversed expression.
The iteration is broadcasted to the specified shape.
- Parameters
shape: the shape used for broadcasting
- Template Parameters
S: type of theshapeparameter.L: order used for the traversal. Default value isXTENSOR_DEFAULT_TRAVERSAL.