# layout

Defined in `xtensor/core/xlayout.hpp`

enum class 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

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

  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.

  Parameters:

    args – the input layouts.

  Returns:

    the output layout, computed with the previous logical table.

# xcontainer

Defined in `xtensor/containers/xcontainer.hpp`

template<class D>
class 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::xfixed_container< typename storage_type::value_type, S, L, SH, Tag >, xt::xfixed_container< T, FSH, L, Sharable >, xt::xstrided_container< D >

  Size and shape

  inline size_type size() const noexcept

    Returns the number of element in the container.

  size_type dimension() const noexcept

    Returns the number of dimensions of the container.

  const inner_shape_type &shape() const noexcept

    Returns the shape of the container.

  const inner_strides_type &strides() const noexcept

    Returns the strides of the container.

  const inner_backstrides_type &backstrides() const noexcept

    Returns the backstrides of the container.

  Data

  template<class T>
  inline void fill(const T &value)

    Fills the container with the given value.

    Parameters:

      value – the value to fill the container with.

  inline const size_type data_offset() const noexcept

    Returns the offset to the first element in the container.

  template<class ...Args>
  inline reference operator()(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>
  inline const_reference operator()(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>
  inline reference unchecked(Args... args)

    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 preferred 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>
  inline const_reference unchecked(Args... args) const

    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 preferred 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>
  inline reference element(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>
  inline const_reference element(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>
  inline bool broadcast_shape(S &shape, bool reuse_cache = false) const

    Broadcast the shape of the container to the specified parameter.

    Parameters:

      - shape – the result shape

      - reuse_cache – parameter for internal optimization

    Returns:

      a boolean indicating whether the broadcasting is trivial

  template<class S>
  inline bool has_linear_assign(const S &strides) const noexcept

    Checks whether the xcontainer can be linearly assigned to an expression with the specified strides.

    Returns:

      a boolean indicating whether a linear assign is possible

  Public Functions

  template<class ...Args>
  inline reference at(Args... args)

    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.

    Throws:

      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>
  inline disable_integral_t<S, reference> operator[](const S &index)

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

    Parameters:

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

  inline reference back()

    Returns a reference to the last element of the expression.

  inline reference front()

    Returns a reference to the first element of the expression.

  template<class ...Args>
  inline reference periodic(Args... args)

    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.

# xstrided_container

Defined in `xtensor/containers/xcontainer.hpp`

template<class D>
class 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.

  Subclassed by xt::xarray_adaptor< xbuffer_adaptor< xtl::closure_type_t< T * >, xt::no_ownership, detail::default_allocator_for_ptr_t< T > >, L, SC >, xt::xarray_adaptor< value_container &, L, SC >, xt::xarray_adaptor< flag_container &, L, SC >, xt::xarray_adaptor< const value_container &, L, SC >, xt::xarray_adaptor< const flag_container &, L, SC >, xt::xarray_adaptor< EC, L, SC, xoptional_expression_tag >, xt::xarray_container< temporary_container_t< storage_type >, L, SC, Tag >, xt::xarray_container< uvector< T, A >, L, xt::svector< typename uvector< T, A >::size_type, 4, SA, true > >, xt::xarray_container< xtl::xoptional_vector< T, A, BC >, L, xt::svector< typename uvector< T, A >::size_type, 4, SA, true >, xoptional_expression_tag >, xt::xarray_container< EC, L, SC, xoptional_expression_tag >, xt::xtensor_adaptor< xbuffer_adaptor< xtl::closure_type_t< T * >, xt::no_ownership, detail::default_allocator_for_ptr_t< T > >, N, L >, xt::xtensor_adaptor< value_container &, N, L >, xt::xtensor_adaptor< flag_container &, N, L >, xt::xtensor_adaptor< const value_container &, N, L >, xt::xtensor_adaptor< const flag_container &, N, L >, xt::xtensor_adaptor< EC, N, L, xoptional_expression_tag >, xt::xtensor_container< temporary_container_t< storage_type >, N, L, Tag >, xt::xtensor_container< uvector< T, A >, N, L >, xt::xtensor_container< xtl::xoptional_vector< T, A, BC >, N, L, xoptional_expression_tag >, xt::xtensor_container< std::vector< T, A >, 2, layout_type::row_major >, xt::xtensor_container< EC, N, L, xoptional_expression_tag >, xt::xtensor_view< EC, N, L, xoptional_expression_tag >

  Broadcasting

  template<class S = shape_type>
  inline void resize(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 shape

      - force – force reshaping, even if the shape stays the same (default: false)

  template<class S = shape_type>
  inline void resize(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 shape

      - l – the new layout_type

  template<class S = shape_type>
  inline void resize(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 shape

      - strides – the new strides

  template<class S = shape_type>
  inline auto &reshape(S &&shape, layout_type layout = base_type::static_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 the `shape`.

        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)

  inline layout_type layout() const noexcept

    Return the layout_type of the container.

    Returns:

      layout_type of the container