xindexview

Defined in xtensor/xindexview.hpp

template <class CT, class I>
class xt::xindexview

View of an xexpression from vector of indices.

The xindexview class implements a flat (1D) view into a multidimensional xexpression yielding the values at the indices of the index array. xindexview is not meant to be used directly, but only with the index_view and filter helper functions.

See
index_view, filter
Template Parameters
  • CT: the closure type of the xexpression type underlying this view
  • I: the index array type of the view

Inherits from xt::xview_semantic< xindexview< CT, I > >, xt::xiterable< xindexview< CT, I > >

Extended copy semantic

template <class E>
auto operator=(const xexpression<E> &e)

The extended assignment operator.

Constructor

template <class I2>
xindexview(CT e, I2 &&indices)

Constructs an xindexview, selecting the indices specified by indices.

The resulting xexpression has a 1D shape with a length of n for n indices.

Parameters
  • e: the underlying xexpression for this view
  • indices: the indices to select

Size and shape

auto size() const

Returns the size of the xindexview.

auto dimension() const

Returns the number of dimensions of the xindexview.

auto shape() const

Returns the shape of the xindexview.

Data

template <class... Args>
auto operator()(std::size_t idx, Args…) const

Returns the element at the specified position in the xindexview.

Parameters
  • idx: the position in the view

template <class It>
auto element(It first, It)

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

Parameters
  • first: iterator starting the sequence of indices The number of indices in the sequence should be equal to or greater 1.

Broadcasting

template <class O>
bool broadcast_shape(O &shape) const

Broadcast the shape of the xindexview to the specified parameter.

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

template <class O>
bool is_trivial_broadcast(const O&) 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

template <class ECT, class CCT>
class xt::xfiltration

Filter of a xexpression for fast scalar assign.

The xfiltration class implements a lazy filtration of a multidimentional xexpression, optimized for scalar and computed scalar assignments. Actually, the xfiltration class IS NOT an xexpression and the scalar and computed scalar assignments are the only method it provides. The filtering condition is not evaluated until the filtration is assigned.

xfiltration is not meant to be used directly, but only with the filtration helper function.

See
filtration
Template Parameters
  • ECT: the closure type of the xexpression type underlying this filtration
  • CCR: the closure type of the filtering xexpression type

Extended copy semantic

template <class E>
auto operator=(const E &e)

Assigns the scalar e to *this.

Return
a reference to \ *this.
Parameters
  • e: the scalar to assign.

Constructor

xfiltration(ECT e, CCT condition)

Constructs a xfiltration on the given expression e, selecting the elements matching the specified condition.

Parameters

Computed assignement

template <class E>
auto operator+=(const E &e)

Adds the scalar e to *this.

Return
a reference to *this.
Parameters
  • e: the scalar to add.

template <class E>
auto operator-=(const E &e)

Subtracts the scalar e from *this.

Return
a reference to *this.
Parameters
  • e: the scalar to subtract.

template <class E>
auto operator*=(const E &e)

Multiplies *this with the scalar e.

Return
a reference to *this.
Parameters
  • e: the scalar involved in the operation.

template <class E>
auto operator/=(const E &e)

Divides *this by the scalar e.

Return
a reference to *this.
Parameters
  • e: the scalar involved in the operation.

template <class E, class I>
auto xt::index_view(E &&e, I &&indices)

creates an indexview from a container of indices.

Returns a 1D view with the elements at indices selected.

xarray<double> a = {{1,5,3}, {4,5,6}};
b = index_view(a, {{0, 0}, {1, 0}, {1, 1}});
std::cout << b << std::endl; // {1, 4, 5}
b += 100;
std::cout << a << std::endl; // {{101, 5, 3}, {104, 105, 6}}
Parameters
  • e: the underlying xexpression
  • indices: the indices to select

template <class E, class O>
auto xt::filter(E &&e, O &&condition)

creates a view into e filtered by condition.

Returns a 1D view with the elements selected where condition evaluates to true. This is equivalent to

{index_view(e, where(condition));}
The returned view is not optimal if you just want to assign a scalar to the filtered elements. In that case, you should consider using the filtration function instead.

xarray<double> a = {{1,5,3}, {4,5,6}};
b = filter(a, a >= 5);
std::cout << b << std::endl; // {5, 5, 6}
Parameters
  • e: the underlying xexpression
  • condition: xexpression with shape of e which selects indices

See
filtration

template <class E, class C>
auto xt::filtration(E &&e, C &&condition)

creates a filtration of e filtered by condition.

Returns a lazy filtration optimized for scalar assignment. Actually, scalar assignment and computed scalar assignments are the only available methods of the filtration, the filtration IS NOT an xexpression.

xarray<double> a = {{1,5,3}, {4,5,6}};
filtration(a, a >= 5) += 2;
std::cout << a << std::endl; // {{1, 7, 3}, {4, 7, 8}}
Parameters