xindex_view

Defined in xtensor/xindex_view.hpp

template<class CT, class I>
class xindex_view : public xt::xview_semantic<xindex_view<CT, I>>, public xt::xiterable<xindex_view<CT, I>>, public extension::xindex_view_base_t<CT, I>

View of an xexpression from vector of indices.

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

See also

index_view, filter

Template Parameters:
  • CT – the closure type of the xexpression type underlying this view

  • I – the index array type of the view

Constructor

template<class CTA, class I2>
inline xindex_view(CTA &&e, I2 &&indices) noexcept

Constructs an xindex_view, 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

inline size_type size() const noexcept

Returns the size of the xindex_view.

inline size_type dimension() const noexcept

Returns the number of dimensions of the xindex_view.

inline const inner_shape_type &shape() const noexcept

Returns the shape of the xindex_view.

inline size_type shape(size_type index) const

Returns the i-th dimension of the expression.

Data

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

Fills the view with the given value.

Parameters:

value – the value to fill the view with.

inline reference operator()(size_type idx = size_type(0))

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

Parameters:

idx – index specifying the position in the index_view. More indices may be provided, only the last one will be used.

inline reference unchecked(size_type idx)

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

Parameters:

idx – index specifying the position in the index_view.

inline const_reference operator()(size_type idx = size_type(0)) const

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

Parameters:

idx – index specifying the position in the index_view. More indices may be provided, only the last one will be used.

inline const_reference unchecked(size_type idx) const

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

Parameters:

idx – index specifying the position in the index_view.

inline xexpression_type &expression() noexcept

Returns a reference to the underlying expression of the view.

inline const xexpression_type &expression() const noexcept

Returns a constant reference to the underlying expression of the view.

template<class S>
inline auto operator[](const S &index) -> disable_integral_t<S, reference>

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

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>
inline auto element(It first, It) -> reference

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

Parameters:

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

template<class It>
inline auto element(It first, It) const -> const_reference

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

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>
inline bool broadcast_shape(O &shape, bool reuse_cache = false) const

Broadcast the shape of the xindex_view 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 O>
inline bool has_linear_assign(const O&) const noexcept

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

Returns:

a boolean indicating whether a linear assign is possible

Extended copy semantic

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

The extended assignment operator.

template<class ECT, class CCT>
class 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 also

filtration

Template Parameters:
  • ECT – the closure type of the xexpression type underlying this filtration

  • CCR – the closure type of the filtering xexpression type

Constructor

template<class ECTA, class CCTA>
inline xfiltration(ECTA &&e, CCTA &&condition)

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

Parameters:

Extended copy semantic

template<class E>
inline auto operator=(const E &e) -> disable_xexpression<E, self_type&>

Assigns the scalar e to *this.

Parameters:

e – the scalar to assign.

Returns:

a reference to \ *this.

Computed assignement

template<class E>
inline auto operator+=(const E &e) -> disable_xexpression<E, self_type&>

Adds the scalar e to *this.

Parameters:

e – the scalar to add.

Returns:

a reference to *this.

template<class E>
inline auto operator-=(const E &e) -> disable_xexpression<E, self_type&>

Subtracts the scalar e from *this.

Parameters:

e – the scalar to subtract.

Returns:

a reference to *this.

template<class E>
inline auto operator*=(const E &e) -> disable_xexpression<E, self_type&>

Multiplies *this with the scalar e.

Parameters:

e – the scalar involved in the operation.

Returns:

a reference to *this.

template<class E>
inline auto operator/=(const E &e) -> disable_xexpression<E, self_type&>

Divides *this by the scalar e.

Parameters:

e – the scalar involved in the operation.

Returns:

a reference to *this.

template<class E>
inline auto operator%=(const E &e) -> disable_xexpression<E, self_type&>

Computes the remainder of *this after division by the scalar e.

Parameters:

e – the scalar involved in the operation.

Returns:

a reference to *this.

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

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<layout_type L = ::xt::layout_type::row_major, class E, class O>
inline auto xt::filter(E &&e, O &&condition) noexcept

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, argwhere(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}

See also

filtration

Template Parameters:

L – the traversal order

Parameters:
  • e – the underlying xexpression

  • condition – xexpression with shape of e which selects indices

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

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: