10#ifndef XTENSOR_XMASKED_VIEW_HPP
11#define XTENSOR_XMASKED_VIEW_HPP
13#include "xaccessible.hpp"
14#include "xexpression.hpp"
15#include "xiterable.hpp"
16#include "xsemantic.hpp"
18#include "xtensor_forward.hpp"
19#include "xtl/xmasked_value.hpp"
28 template <
class CTD,
class CTM>
31 template <
class D,
bool is_const>
32 class xmasked_view_stepper;
35 struct xcontainer_inner_types;
37 template <
class CTD,
class CTM>
40 using data_type = std::decay_t<CTD>;
41 using mask_type = std::decay_t<CTM>;
42 using base_value_type =
typename data_type::value_type;
43 using flag_type =
typename mask_type::value_type;
46 using value_type = xtl::xmasked_value<base_value_type, flag_type>;
47 using reference = xtl::xmasked_value<val_reference, mask_reference>;
48 using const_reference = xtl::xmasked_value<typename data_type::const_reference, typename mask_type::const_reference>;
49 using size_type =
typename data_type::size_type;
53 template <
class CTD,
class CTM>
57 using inner_shape_type =
typename std::decay_t<CTD>::inner_shape_type;
77 template <
class CTD,
class CTM>
88 using temporary_type =
typename inner_types::temporary_type;
90 using data_type =
typename inner_types::data_type;
91 using mask_type =
typename inner_types::mask_type;
95 static constexpr bool is_data_const = std::is_const<std::remove_reference_t<value_expression>>
::value;
97 using base_value_type =
typename inner_types::base_value_type;
98 using base_reference =
typename data_type::reference;
99 using base_const_reference =
typename data_type::const_reference;
101 using flag_type =
typename inner_types::flag_type;
102 using flag_reference =
typename mask_type::reference;
103 using flag_const_reference =
typename mask_type::const_reference;
105 using val_reference =
typename inner_types::val_reference;
106 using mask_reference =
typename inner_types::mask_reference;
108 using value_type =
typename inner_types::value_type;
109 using reference =
typename inner_types::reference;
110 using const_reference =
typename inner_types::const_reference;
112 using pointer = xtl::xclosure_pointer<reference>;
113 using const_pointer = xtl::xclosure_pointer<const_reference>;
115 using size_type =
typename inner_types::size_type;
116 using difference_type =
typename data_type::difference_type;
118 using bool_load_type = xtl::xmasked_value<typename data_type::bool_load_type, mask_type>;
120 using shape_type =
typename data_type::shape_type;
121 using strides_type =
typename data_type::strides_type;
123 static constexpr layout_type static_layout = data_type::static_layout;
124 static constexpr bool contiguous_layout =
false;
126 using inner_shape_type =
typename data_type::inner_shape_type;
127 using inner_strides_type =
typename data_type::inner_strides_type;
128 using inner_backstrides_type =
typename data_type::inner_backstrides_type;
133 using stepper =
typename iterable_base::stepper;
134 using const_stepper =
typename iterable_base::const_stepper;
136 template <layout_type L>
138 template <layout_type L>
140 template <layout_type L>
142 template <layout_type L>
145 template <
class S, layout_type L>
147 template <
class S, layout_type L>
149 template <
class S, layout_type L>
151 template <
class S, layout_type L>
154 using iterator =
typename iterable_base::iterator;
155 using const_iterator =
typename iterable_base::const_iterator;
156 using reverse_iterator =
typename iterable_base::reverse_iterator;
157 using const_reverse_iterator =
typename iterable_base::const_reverse_iterator;
159 template <
class D,
class M>
164 size_type
size()
const noexcept;
165 const inner_shape_type&
shape()
const noexcept;
166 const inner_strides_type&
strides()
const noexcept;
167 const inner_backstrides_type&
backstrides()
const noexcept;
172 bool is_contiguous()
const noexcept;
177 template <
class...
Args>
180 template <
class...
Args>
181 const_reference operator()(
Args...
args)
const;
183 template <
class...
Args>
186 template <
class...
Args>
187 const_reference unchecked(
Args...
args)
const;
189 using accessible_base::at;
190 using accessible_base::operator[];
194 using accessible_base::periodic;
203 bool has_linear_assign(
const S&
strides)
const noexcept;
205 data_type&
value()
noexcept;
206 const data_type&
value()
const noexcept;
209 const mask_type&
visible()
const noexcept;
211 using iterable_base::begin;
212 using iterable_base::cbegin;
213 using iterable_base::cend;
214 using iterable_base::crbegin;
215 using iterable_base::crend;
216 using iterable_base::end;
217 using iterable_base::rbegin;
218 using iterable_base::rend;
221 stepper stepper_begin(
const S&
shape)
noexcept;
226 const_stepper stepper_begin(
const S&
shape)
const noexcept;
243 void assign_temporary_impl(temporary_type&&
tmp);
252 template <
class D,
bool is_const>
258 using masked_view_type = std::decay_t<D>;
259 using value_type =
typename masked_view_type::value_type;
260 using reference = std::
261 conditional_t<is_const, typename masked_view_type::const_reference, typename masked_view_type::reference>;
262 using pointer = std::
263 conditional_t<is_const, typename masked_view_type::const_pointer, typename masked_view_type::pointer>;
264 using size_type =
typename masked_view_type::size_type;
265 using difference_type =
typename masked_view_type::difference_type;
266 using data_type =
typename masked_view_type::data_type;
267 using mask_type =
typename masked_view_type::mask_type;
268 using value_stepper = std::conditional_t<is_const, typename data_type::const_stepper, typename data_type::stepper>;
269 using mask_stepper = std::conditional_t<is_const, typename mask_type::const_stepper, typename mask_type::stepper>;
274 void step(size_type
dim);
275 void step_back(size_type
dim);
276 void step(size_type
dim, size_type
n);
277 void step_back(size_type
dim, size_type
n);
278 void reset(size_type
dim);
279 void reset_back(size_type
dim);
284 reference operator*()
const;
307 template <
class CTD,
class CTM>
308 template <
class D,
class M>
322 template <
class CTD,
class CTM>
325 return m_data.size();
331 template <
class CTD,
class CTM>
334 return m_data.shape();
340 template <
class CTD,
class CTM>
343 return m_data.strides();
349 template <
class CTD,
class CTM>
352 return m_data.backstrides();
361 template <
class CTD,
class CTM>
364 return m_data.layout();
367 template <
class CTD,
class CTM>
377 template <
class CTD,
class CTM>
381 std::fill(this->begin(), this->end(), value);
394 template <
class CTD,
class CTM>
395 template <
class...
Args>
398 return reference(m_data(
args...), m_mask(
args...));
407 template <
class CTD,
class CTM>
408 template <
class...
Args>
411 return const_reference(m_data(
args...), m_mask(
args...));
433 template <
class CTD,
class CTM>
434 template <
class...
Args>
437 return reference(m_data.unchecked(
args...), m_mask.unchecked(
args...));
459 template <
class CTD,
class CTM>
460 template <
class...
Args>
463 return const_reference(m_data.unchecked(
args...), m_mask.unchecked(
args...));
473 template <
class CTD,
class CTM>
487 template <
class CTD,
class CTM>
496 template <
class CTD,
class CTM>
500 return m_data.has_linear_assign(
strides) && m_mask.has_linear_assign(
strides);
506 template <
class CTD,
class CTM>
515 template <
class CTD,
class CTM>
524 template <
class CTD,
class CTM>
533 template <
class CTD,
class CTM>
539 template <
class CTD,
class CTM>
543 return stepper(value().stepper_begin(shape), visible().stepper_begin(shape));
546 template <
class CTD,
class CTM>
548 inline auto xmasked_view<CTD, CTM>::stepper_end(
const S& shape,
layout_type l)
noexcept -> stepper
550 return stepper(value().stepper_end(shape, l), visible().stepper_end(shape, l));
553 template <
class CTD,
class CTM>
555 inline auto xmasked_view<CTD, CTM>::stepper_begin(
const S& shape)
const noexcept -> const_stepper
557 return const_stepper(value().stepper_begin(shape), visible().stepper_begin(shape));
560 template <
class CTD,
class CTM>
562 inline auto xmasked_view<CTD, CTM>::stepper_end(
const S& shape,
layout_type l)
const noexcept
565 return const_stepper(value().stepper_end(shape, l), visible().stepper_end(shape, l));
568 template <
class CTD,
class CTM>
569 inline auto xmasked_view<CTD, CTM>::operator=(
const self_type& rhs) -> self_type&
571 temporary_type tmp(rhs);
572 return this->assign_temporary(std::move(tmp));
575 template <
class CTD,
class CTM>
577 inline auto xmasked_view<CTD, CTM>::operator=(
const xexpression<E>& e) -> self_type&
579 return semantic_base::operator=(e);
582 template <
class CTD,
class CTM>
584 inline auto xmasked_view<CTD, CTM>::operator=(
const E& e) -> disable_xexpression<E, self_type>&
586 std::fill(this->begin(), this->end(), e);
590 template <
class CTD,
class CTM>
591 inline void xmasked_view<CTD, CTM>::assign_temporary_impl(temporary_type&& tmp)
593 std::copy(tmp.cbegin(), tmp.cend(), this->begin());
596 template <
class CTD,
class CTM>
597 inline xmasked_view<CTD, CTM> masked_view(CTD&& data, CTM&& mask)
599 return xmasked_view<CTD, CTM>(std::forward<CTD>(data), std::forward<CTM>(mask));
606 template <
class D,
bool C>
607 inline xmasked_view_stepper<D, C>::xmasked_view_stepper(value_stepper vs, mask_stepper ms) noexcept
613 template <
class D,
bool C>
614 inline void xmasked_view_stepper<D, C>::step(size_type dim)
620 template <
class D,
bool C>
621 inline void xmasked_view_stepper<D, C>::step_back(size_type dim)
627 template <
class D,
bool C>
628 inline void xmasked_view_stepper<D, C>::step(size_type dim, size_type n)
634 template <
class D,
bool C>
635 inline void xmasked_view_stepper<D, C>::step_back(size_type dim, size_type n)
637 m_vs.step_back(dim, n);
638 m_ms.step_back(dim, n);
641 template <
class D,
bool C>
642 inline void xmasked_view_stepper<D, C>::reset(size_type dim)
648 template <
class D,
bool C>
649 inline void xmasked_view_stepper<D, C>::reset_back(size_type dim)
651 m_vs.reset_back(dim);
652 m_ms.reset_back(dim);
655 template <
class D,
bool C>
656 inline void xmasked_view_stepper<D, C>::to_begin()
662 template <
class D,
bool C>
663 inline void xmasked_view_stepper<D, C>::to_end(
layout_type l)
669 template <
class D,
bool C>
670 inline auto xmasked_view_stepper<D, C>::operator*() const -> reference
672 return reference(*m_vs, *m_ms);
Base class for implementation of common expression access methods.
reference back()
Returns a reference to the last element of the expression.
reference front()
Returns a reference to the first element of the expression.
Base class for implementation of common expression constant access methods.
size_type dimension() const noexcept
Returns the number of dimensions of the expression.
bool in_bounds(Args... args) const
Returns true only if the the specified position is a valid entry in the expression.
size_type shape(size_type index) const
Returns the i-th dimension of the expression.
Base class for multidimensional iterable constant expressions.
Base class for multidimensional iterable expressions.
View on an xoptional_assembly or xoptional_assembly_adaptor hiding values depending on a given mask.
const inner_strides_type & strides() const noexcept
Returns the strides of the xmasked_view.
const inner_backstrides_type & backstrides() const noexcept
Returns the backstrides of the xmasked_view.
const inner_shape_type & shape() const noexcept
Returns the shape of the xmasked_view.
mask_type & visible() noexcept
Return an expression for the mask of the xmasked_view.
void fill(const T &value)
Fills the data with the given value.
layout_type layout() const noexcept
Return the layout_type of the xmasked_view.
data_type & value() noexcept
Return an expression for the values of the xmasked_view.
size_type size() const noexcept
Returns the number of elements in the xmasked_view.
xmasked_view(D &&data, M &&mask)
Creates an xmasked_view, given the xoptional_assembly or xoptional_assembly_adaptor and the mask.
Implementation of the xsemantic_base interface for multidimensional views.
auto strides(const E &e, stride_type type=stride_type::normal) noexcept
Get strides of an object.
standard mathematical functions for xexpressions