layout¶
Defined in xtensor/xlayout.hpp
-
enum
xt
::
layout_type
¶ layout_type enum for xcontainer based xexpressions
Values:
-
enumerator
dynamic
¶ dynamic layout_type: you can resize to row major, column major, or use custom strides
-
enumerator
any
¶ layout_type compatible with all others
-
enumerator
row_major
¶ row major layout_type
-
enumerator
column_major
¶ column major layout_type
-
enumerator
-
template<class ...
Args
>
constexpr layout_typext
::
compute_layout
(Args... args) noexcept¶ Implementation of the following logical table:
Using bitmasks to avoid nested if-else statements.| d | a | r | c | --+---+---+---+---+ d | d | d | d | d | a | d | a | r | c | r | d | r | r | d | c | d | c | d | c | d = dynamic, a = any, r = row_major, c = column_major.
- Return
the output layout, computed with the previous logical table.
- Parameters
args
: the input layouts.
xcontainer¶
Defined in xtensor/xcontainer.hpp
-
template<class
D
>
classxt
::
xcontainer
: public xt::xcontiguous_iterable<D>, private xt::xaccessible<D>¶ Base class for dense multidimensional containers.
The xcontainer class defines the interface for dense multidimensional container classes. It 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 xcontainer provides the interface.
Subclassed by xt::xstrided_container< xtensor_container< EC, N, L, Tag > >, xt::xstrided_container< xarray_adaptor< EC, L, SC, Tag > >, xt::xstrided_container< xarray_container< EC, L, SC, Tag > >, xt::xstrided_container< xtensor_view< EC, N, L, Tag > >, xt::xstrided_container< xtensor_adaptor< EC, N, L, Tag > >, xt::xstrided_container< D >
Size and shape
-
size_type
size
() const noexcept¶ Returns the number of element in the container.
-
constexpr size_type
dimension
() const noexcept¶ Returns the number of dimensions of the container.
-
constexpr const inner_shape_type &
shape
() const noexcept¶ Returns the shape of the container.
-
constexpr const inner_strides_type &
strides
() const noexcept¶ Returns the strides of the container.
-
constexpr const inner_backstrides_type &
backstrides
() const noexcept¶ Returns the backstrides of the container.
Data
-
template<class
T
>
voidfill
(const T &value)¶ Fills the container with the given value.
- Parameters
value
: the value to fill the container with.
-
storage_type &
storage
() noexcept¶ Returns a reference to the buffer containing the elements of the container.
-
const storage_type &
storage
() const noexcept¶ Returns a constant reference to the buffer containing the elements of the container.
-
pointer
data
() noexcept¶ Returns a pointer to the underlying array serving as element storage.
The pointer is such that range [data(); data() + size()] is always a valid range, even if the container is empty (data() is not is not dereferenceable in that case)
-
const_pointer
data
() const noexcept¶ Returns a constant pointer to the underlying array serving as element storage.
The pointer is such that range [data(); data() + size()] is always a valid range, even if the container is empty (data() is not is not dereferenceable in that case)
-
const size_type
data_offset
() const noexcept¶ Returns the offset to the first element in the container.
-
template<class ...
Args
>
autooperator()
(Args... args) -> reference¶ Returns a reference to the element at the specified position in the container.
- Parameters
args
: a list of indices specifying the position in the container. Indices must be unsigned integers, the number of indices should be equal or greater than the number of dimensions of the container.
-
template<class ...
Args
>
autooperator()
(Args... args) const -> const_reference¶ Returns a constant reference to the element at the specified position in the container.
- Parameters
args
: a list of indices specifying the position in the container. Indices must be unsigned integers, the number of indices should be equal or greater than the number of dimensions of the container.
-
template<class ...
Args
>
autounchecked
(Args... args) -> reference¶ Returns a reference to the element at the specified position in the container.
- 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 container. Indices must be unsigned integers, the number of indices must be equal to the number of dimensions of the container, else the behavior is undefined.
-
template<class ...
Args
>
autounchecked
(Args... args) const -> const_reference¶ Returns a constant reference to the element at the specified position in the container.
- 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 container. Indices must be unsigned integers, the number of indices must be equal to the number of dimensions of the container, else the behavior is undefined.
-
template<class
It
>
autoelement
(It first, It last) -> reference¶ Returns a reference to the element at the specified position in the container.
- 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 container.
-
template<class
It
>
autoelement
(It first, It last) const -> const_reference¶ Returns a reference to the element at the specified position in the container.
- 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 container.
Broadcasting
Public Functions
-
template<class ...
Args
>
autoat
(Args... args) -> reference¶ Returns a reference to the element at the specified position in the expression, after dimension and bounds checking.
- Parameters
args
: a list of indices specifying the position in the expression. Indices must be unsigned integers, the number of indices should be equal to the number of dimensions of the expression.
- 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
>
autoat
(Args... args) const -> const_reference¶ Returns a constant reference to the element at the specified position in the expression, after dimension and bounds checking.
- Parameters
args
: a list of indices specifying the position in the expression. Indices must be unsigned integers, the number of indices should be equal to the number of dimensions of the expression.
- 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
>
autoperiodic
(Args... args) -> reference¶ Returns a reference to the element at the specified position in the expression, after applying periodicity to the indices (negative and ‘overflowing’ indices are changed).
- Parameters
args
: a list of indices specifying the position in the expression. Indices must be integers, the number of indices should be equal to the number of dimensions of the expression.
-
template<class ...
Args
>
autoperiodic
(Args... args) const -> const_reference¶ Returns a constant reference to the element at the specified position in the expression, after applying periodicity to the indices (negative and ‘overflowing’ indices are changed).
- Parameters
args
: a list of indices specifying the position in the expression. Indices must be integers, the number of indices should be equal to the number of dimensions of the expression.
-
reference
front
()¶ Returns a reference to the first element of the expression.
-
const_reference
front
() const¶ Returns a constant reference to first the element of the expression.
-
reference
back
()¶ Returns a reference to the last element of the expression.
-
const_reference
back
() const¶ Returns a constant reference to last the element of the expression.
xstrided_container¶
Defined in xtensor/xcontainer.hpp
-
template<class
D
>
classxt
::
xstrided_container
: public xt::xcontainer<D>¶ Partial implementation of xcontainer that embeds the strides and the shape.
The xstrided_container class is a partial implementation of the xcontainer interface that embed the strides and the shape of the multidimensional container. It does not embed the data container, this responsibility is delegated to the inheriting classes.
- Template Parameters
D
: The derived type, i.e. the inheriting class for which xstrided_container provides the partial imlpementation of xcontainer.
Broadcasting
-
template<class
S
= shape_type>
voidresize
(S &&shape, bool force = false)¶ Resizes the container.
- Warning
Contrary to STL containers like std::vector, resize does NOT preserve the container elements.
- Parameters
shape
: the new shapeforce
: force reshaping, even if the shape stays the same (default: false)
-
template<class
S
= shape_type>
voidresize
(S &&shape, layout_type l)¶ Resizes the container.
- Warning
Contrary to STL containers like std::vector, resize does NOT preserve the container elements.
- Parameters
shape
: the new shapel
: the new layout_type
-
template<class
S
= shape_type>
voidresize
(S &&shape, const strides_type &strides)¶ Resizes the container.
- Warning
Contrary to STL containers like std::vector, resize does NOT preserve the container elements.
- Parameters
shape
: the new shapestrides
: the new strides
-
layout_type
layout
() const noexcept¶ Return the layout_type of the container.
- Return
layout_type of the container
-
template<class
S
>
auto &reshape
(S &&shape, layout_type layout) &¶ Reshapes the container and keeps old elements.
The
shape
argument can have one of its value equal to-1
, in this case the value is inferred from the number of elements in the container and the remaining values in theshape
.xt::xarray<int> a = { 1, 2, 3, 4, 5, 6, 7, 8 }; a.reshape({-1, 4}); //a.shape() is {2, 4}
- Parameters
shape
: the new shape (has to have same number of elements as the original container)layout
: the layout to compute the strides (defaults to static layout of the container, or for a container with dynamic layout to XTENSOR_DEFAULT_LAYOUT)