xmasked_view

Defined in xtensor/views/xmasked_view.hpp

template<class CTD, class CTM>
class xmasked_view : public xt::xview_semantic<xmasked_view<CTD, CTM>>, private xt::xaccessible<xmasked_view<CTD, CTM>>, private xt::xiterable<xmasked_view<CTD, CTM>>

View on an xoptional_assembly or xoptional_assembly_adaptor hiding values depending on a given mask.

The xmasked_view class implements a view on an xoptional_assembly or xoptional_assembly_adaptor, it takes this xoptional_assembly and a mask as input. The mask is an xexpression containing boolean values, whenever the value of the mask is false, the optional value of xmasked_view is considered missing, otherwise it depends on the underlying xoptional_assembly.

Template Parameters:
  • CTD – The type of expression holding the values.

  • CTM – The type of expression holding the mask.

Constructors

template<class D, class M>
inline xmasked_view(D &&data, M &&mask)

Creates an xmasked_view, given the xoptional_assembly or xoptional_assembly_adaptor and the mask.

Parameters:

Size and shape

inline size_type size() const noexcept

Returns the number of elements in the xmasked_view.

inline const inner_shape_type &shape() const noexcept

Returns the shape of the xmasked_view.

inline const inner_strides_type &strides() const noexcept

Returns the strides of the xmasked_view.

inline const inner_backstrides_type &backstrides() const noexcept

Returns the backstrides of the xmasked_view.

inline layout_type layout() const noexcept

Return the layout_type of the xmasked_view.

Returns:

layout_type of the xmasked_view

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

Fills the data with the given value.

Parameters:

value – the value to fill the data with.

Data

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

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

Parameters:

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

template<class ...Args>
inline const_reference operator()(Args... args) const

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

Parameters:

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

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

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

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 xmasked_view. Indices must be unsigned integers, the number of indices must be equal to the number of dimensions of the xmasked_view, 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 xmasked_view.

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 xmasked_view. Indices must be unsigned integers, the number of indices must be equal to the number of dimensions of the xmasked_view, 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 xmasked_view.

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 xmasked_view.

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

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

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 xmasked_view.

inline data_type &value() noexcept

Return an expression for the values of the xmasked_view.

inline const data_type &value() const noexcept

Return a constant expression for the values of the xmasked_view.

inline mask_type &visible() noexcept

Return an expression for the mask of the xmasked_view.

inline const mask_type &visible() const noexcept

Return a constant expression for the mask of the xmasked_view.

Public Functions

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.

const_reference at(Args... args) const

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.

Throws:

std::out_of_range – if the number of argument is greater than the number of dimensions or if indices are out of bounds.

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.

disable_integral_t<S, const_reference> operator[](const S &index) const

Returns a constant 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.

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.

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 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.

const_reference periodic(Args... args) const

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.

layout_iterator<L> begin() noexcept

Returns an iterator to the first element of the expression.

Template Parameters:

L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

broadcast_iterator<S, L> begin(const S &shape) noexcept

Returns an iterator to the first element of the expression.

The iteration is broadcasted to the specified shape.

Parameters:

shape – the shape used for broadcasting

Template Parameters:
  • S – type of the shape parameter.

  • L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

const_layout_iterator<L> begin() const noexcept

Returns a constant iterator to the first element of the expression.

Template Parameters:

L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

const_broadcast_iterator<S, L> begin(const S &shape) const noexcept

Returns a constant iterator to the first element of the expression.

The iteration is broadcasted to the specified shape.

Parameters:

shape – the shape used for broadcasting

Template Parameters:
  • S – type of the shape parameter.

  • L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

layout_iterator<L> end() noexcept

Returns an iterator to the element following the last element of the expression.

Template Parameters:

L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

broadcast_iterator<S, L> end(const S &shape) noexcept

Returns an iterator to the element following the last element of the expression.

The iteration is broadcasted to the specified shape.

Parameters:

shape – the shape used for broadcasting

Template Parameters:
  • S – type of the shape parameter.

  • L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

const_layout_iterator<L> end() const noexcept

Returns a constant iterator to the element following the last element of the expression.

Template Parameters:

L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

const_broadcast_iterator<S, L> end(const S &shape) const noexcept

Returns a constant iterator to the element following the last element of the expression.

The iteration is broadcasted to the specified shape.

Parameters:

shape – the shape used for broadcasting

Template Parameters:
  • S – type of the shape parameter.

  • L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

reverse_layout_iterator<L> rbegin() noexcept

Returns an iterator to the first element of the reversed expression.

Template Parameters:

L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

reverse_broadcast_iterator<S, L> rbegin(const S &shape) noexcept

Returns an iterator to the first element of the reversed expression.

The iteration is broadcasted to the specified shape.

Parameters:

shape – the shape used for broadcasting

Template Parameters:
  • S – type of the shape parameter.

  • L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

const_reverse_layout_iterator<L> rbegin() const noexcept

Returns a constant iterator to the first element of the reversed expression.

Template Parameters:

L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

const_reverse_broadcast_iterator<S, L> rbegin(const S &shape) const noexcept

Returns a constant iterator to the first element of the reversed expression.

The iteration is broadcasted to the specified shape.

Parameters:

shape – the shape used for broadcasting

Template Parameters:
  • S – type of the shape parameter.

  • L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

reverse_layout_iterator<L> rend() noexcept

Returns an iterator to the element following the last element of the reversed expression.

Template Parameters:

L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

reverse_broadcast_iterator<S, L> rend(const S &shape) noexcept

Returns an iterator to the element following the last element of the reversed expression.

The iteration is broadcasted to the specified shape.

Parameters:

shape – the shape used for broadcasting

Template Parameters:
  • S – type of the shape parameter.

  • L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

const_reverse_layout_iterator<L> rend() const noexcept

Returns a constant iterator to the element following the last element of the reversed expression.

Template Parameters:

L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.

const_reverse_broadcast_iterator<S, L> rend(const S &shape) const noexcept

Returns a constant iterator to the element following the last element of the reversed expression.

The iteration is broadcasted to the specified shape.

Parameters:

shape – the shape used for broadcasting

Template Parameters:
  • S – type of the shape parameter.

  • L – order used for the traversal. Default value is XTENSOR_DEFAULT_TRAVERSAL.