layout

Defined in xtensor/xlayout.hpp

enum xt::layout_type

layout_type enum for xcontainer based xexpressions

Values:

xtdynamic = 0x00

dynamic layout_type: you can resize to row major, column major, or use custom strides

xtany = 0xFF

layout_type compatible with all others

xtrow_major = 0x01

row major layout_type

xtcolumn_major = 0x02

column major layout_type

template <class… Args>
constexpr layout_type xt::compute_layout(Args... args)

Implementation of the following logical table:

  | 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.
Using bitmasks to avoid nested if-else statements.

Return
the output layout, computed with the previous logical table.
Parameters
  • args: the input layouts.

xcontainer

Defined in xtensor/xcontainer.hpp

template <class D>
class xt::xcontainer

Base class for dense multidimensional containers.

Base class for dense multidimensional optional assemblies.

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.

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 xcontainer provides the interface.

Template Parameters

Inherits from xt::xiterable< D >

Subclassed by xt::xstrided_container< D >

Size and shape

auto xt::xcontainersize() const

Returns the number of element in the container.

constexpr auto xt::xcontainerdimension() const

Returns the number of dimensions of the container.

constexpr auto xt::xcontainershape() const

Returns the shape of the container.

constexpr auto xt::xcontainerstrides() const

Returns the strides of the container.

constexpr auto xt::xcontainerbackstrides() const

Returns the backstrides of the container.

Data

auto xt::xcontainerstorage()

Returns a reference to the buffer containing the elements of the container.

auto xt::xcontainerstorage() const

Returns a constant reference to the buffer containing the elements of the container.

auto xt::xcontainerdata()

Returns the offset to the first element in the container.

auto xt::xcontainerdata_offset() const

Returns the offset to the first element in the container.

template <class… Args>
auto xt::xcontaineroperator()(Args... args)

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>
auto xt::xcontaineroperator()(Args... args) const

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>
auto xt::xcontainerat(Args... args)

Returns a reference to the element at the specified position in the container, after dimension and bounds checking.

Parameters
  • args: a list of indices specifying the position in the container. Indices must be unsigned integers, the number of indices should be equal to the number of dimensions of the container.
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 xt::xcontainerat(Args... args) const

Returns a constant reference to the element at the specified position in the container, after dimension and bounds checking.

Parameters
  • args: a list of indices specifying the position in the container. Indices must be unsigned integers, the number of indices should be equal to the number of dimensions of the container.
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 S>
auto xt::xcontaineroperator[](const S &index)

Returns a reference to the element at the specified position in the container.

Parameters
  • index: a sequence of indices specifying the position in the container. Indices must be unsigned integers, the number of indices in the list should be equal or greater than the number of dimensions of the container.

template <class S>
auto xt::xcontaineroperator[](const S &index) const

Returns a constant reference to the element at the specified position in the container.

Parameters
  • index: a sequence of indices specifying the position in the container. Indices must be unsigned integers, the number of indices in the list should be equal or greater than the number of dimensions of the container.

template <class It>
auto xt::xcontainerelement(It first, It last)

Returns a reference to the element at the specified position in the container.

Parameters
  • first: iterator starting the sequence of indices
  • last: 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>
auto xt::xcontainerelement(It first, It last) const

Returns a reference to the element at the specified position in the container.

Parameters
  • first: iterator starting the sequence of indices
  • last: 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

template <class S>
bool xt::xcontainerbroadcast_shape(S &shape, bool reuse_cache = false) const

Broadcast the shape of the container to the specified parameter.

Return
a boolean indicating whether the broadcasting is trivial
Parameters
  • shape: the result shape

template <class S>
bool xt::xcontaineris_trivial_broadcast(const S &strides) const

Compares the specified strides with those of the container to see whether the broadcasting is trivial.

Return
a boolean indicating whether the broadcasting is trivial

xstrided_container

Defined in xtensor/xcontainer.hpp

template <class D>
class xt::xstrided_container

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.

Inherits from xt::xcontainer< D >

Public Functions

template <class S = shape_type>
void xt::xstrided_containerresize(S &&shape, bool force = false)

resizes the container.

Parameters
  • shape: the new shape
  • force: force reshaping, even if the shape stays the same (default: false)

template <class S = shape_type>
void xt::xstrided_containerresize(S &&shape, layout_type l)

resizes the container.

Parameters
  • shape: the new shape
  • l: the new layout_type

template <class S = shape_type>
void xt::xstrided_containerresize(S &&shape, const strides_type &strides)

Resizes the container.

Parameters
  • shape: the new shape
  • strides: the new strides

template <class S = shape_type>
void xt::xstrided_containerreshape(S &&shape, layout_type layout = base_type::static_layout)

Reshapes the container and keeps old elements.

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)

layout_type xt::xstrided_containerlayout() const

Return the layout_type of the container.

Return
layout_type of the container