10#ifndef XTENSOR_INDEX_VIEW_HPP 
   11#define XTENSOR_INDEX_VIEW_HPP 
   20#include "../core/xexpression.hpp" 
   21#include "../core/xiterable.hpp" 
   22#include "../core/xoperation.hpp" 
   23#include "../core/xsemantic.hpp" 
   24#include "../core/xstrides.hpp" 
   25#include "../utils/xutils.hpp" 
   36        template <
class Tag, 
class CT, 
class I>
 
   39        template <
class CT, 
class I>
 
   45        template <
class CT, 
class I>
 
   50        template <
class CT, 
class I>
 
   58    template <
class CT, 
class I>
 
   61    template <
class CT, 
class I>
 
   64        using xexpression_type = std::decay_t<CT>;
 
 
   68    template <
class CT, 
class I>
 
   71        using inner_shape_type = std::array<std::size_t, 1>;
 
 
   90    template <
class CT, 
class I>
 
   91    class xindex_view : 
public xview_semantic<xindex_view<CT, I>>,
 
   93                        public extension::xindex_view_base_t<CT, I>
 
   98        using xexpression_type = std::decay_t<CT>;
 
   99        using semantic_base = xview_semantic<self_type>;
 
  101        using extension_base = extension::xindex_view_base_t<CT, I>;
 
  102        using expression_tag = 
typename extension_base::expression_tag;
 
  104        using value_type = 
typename xexpression_type::value_type;
 
  105        using reference = inner_reference_t<CT>;
 
  106        using const_reference = 
typename xexpression_type::const_reference;
 
  107        using pointer = 
typename xexpression_type::pointer;
 
  108        using const_pointer = 
typename xexpression_type::const_pointer;
 
  109        using size_type = 
typename xexpression_type::size_type;
 
  110        using difference_type = 
typename xexpression_type::difference_type;
 
  113        using inner_shape_type = 
typename iterable_base::inner_shape_type;
 
  114        using shape_type = inner_shape_type;
 
  116        using indices_type = I;
 
  118        using stepper = 
typename iterable_base::stepper;
 
  119        using const_stepper = 
typename iterable_base::const_stepper;
 
  122        using base_index_type = xindex_type_t<shape_type>;
 
  124        using bool_load_type = 
typename xexpression_type::bool_load_type;
 
  127        static constexpr bool contiguous_layout = 
false;
 
  129        template <
class CTA, 
class I2>
 
  136        disable_xexpression<E, self_type>& operator=(
const E& e);
 
  138        size_type 
size() const noexcept;
 
  140        const inner_shape_type& 
shape() const noexcept;
 
  141        size_type 
shape(size_type index) const;
 
  143        bool is_contiguous() const noexcept;
 
  148        reference operator()(size_type idx = size_type(0));
 
  149        template <class... Args>
 
  150        reference operator()(size_type idx0, size_type idx1, Args... args);
 
  153        disable_integral_t<S, reference> operator[](const S& index);
 
  155        reference operator[](std::initializer_list<OI> index);
 
  156        reference operator[](size_type i);
 
  159        reference element(It first, It last);
 
  161        const_reference operator()(size_type idx = size_type(0)) const;
 
  162        template <class... Args>
 
  163        const_reference operator()(size_type idx0, size_type idx1, Args... args) const;
 
  166        disable_integral_t<S, const_reference> operator[](const S& index) const;
 
  168        const_reference operator[](std::initializer_list<OI> index) const;
 
  169        const_reference operator[](size_type i) const;
 
  172        const_reference element(It first, It last) const;
 
  184        stepper stepper_begin(const ST& 
shape);
 
  189        const_stepper stepper_begin(const ST& 
shape) const;
 
  197        rebind_t<E> build_index_view(E&& e) const;
 
  202        const indices_type m_indices;
 
  203        const inner_shape_type m_shape;
 
  205        void assign_temporary_impl(temporary_type&& tmp);
 
 
  232    template <class ECT, class CCT>
 
  238        using xexpression_type = std::decay_t<ECT>;
 
  239        using const_reference = 
typename xexpression_type::const_reference;
 
  241        template <
class ECTA, 
class CCTA>
 
  245        disable_xexpression<E, self_type&> operator=(
const E&);
 
  248        disable_xexpression<E, self_type&> 
operator+=(
const E&);
 
  251        disable_xexpression<E, self_type&> 
operator-=(
const E&);
 
  254        disable_xexpression<E, self_type&> 
operator*=(
const E&);
 
  257        disable_xexpression<E, self_type&> 
operator/=(
const E&);
 
  260        disable_xexpression<E, self_type&> 
operator%=(
const E&);
 
  265        self_type& apply(F&& func);
 
 
  286    template <
class CT, 
class I>
 
  287    template <
class CTA, 
class I2>
 
  289        : m_e(std::forward<CTA>(e))
 
  290        , m_indices(std::forward<I2>(indices))
 
  291        , m_shape({m_indices.size()})
 
 
  304    template <
class CT, 
class I>
 
  308        return semantic_base::operator=(e);
 
 
  313    template <
class CT, 
class I>
 
  315    inline auto xindex_view<CT, I>::operator=(
const E& e) -> disable_xexpression<E, self_type>&
 
  317        std::fill(this->
begin(), this->
end(), e);
 
  321    template <
class CT, 
class I>
 
  322    inline void xindex_view<CT, I>::assign_temporary_impl(temporary_type&& tmp)
 
  324        std::copy(tmp.cbegin(), tmp.cend(), this->begin());
 
  334    template <
class CT, 
class I>
 
  337        return compute_size(
shape());
 
 
  343    template <
class CT, 
class I>
 
  352    template <
class CT, 
class I>
 
  361    template <
class CT, 
class I>
 
  367    template <
class CT, 
class I>
 
  368    inline layout_type xindex_view<CT, I>::layout() const noexcept
 
  370        return static_layout;
 
  373    template <
class CT, 
class I>
 
  374    inline bool xindex_view<CT, I>::is_contiguous() const noexcept
 
  390    template <
class CT, 
class I>
 
  394        std::fill(this->
begin(), this->
end(), value);
 
 
  402    template <
class CT, 
class I>
 
  405        return m_e[m_indices[idx]];
 
 
  408    template <
class CT, 
class I>
 
  409    template <
class... Args>
 
  412        return this->
operator()(idx1, 
static_cast<size_type
>(args)...);
 
  419    template <
class CT, 
class I>
 
  430    template <
class CT, 
class I>
 
  433        return m_e[m_indices[idx]];
 
 
  436    template <
class CT, 
class I>
 
  437    template <
class... Args>
 
  447    template <
class CT, 
class I>
 
  459    template <
class CT, 
class I>
 
  461    inline auto xindex_view<CT, I>::operator[](
const S& index) -> disable_integral_t<S, reference>
 
  463        return m_e[m_indices[index[0]]];
 
 
  466    template <
class CT, 
class I>
 
  468    inline auto xindex_view<CT, I>::operator[](std::initializer_list<OI> index) -> reference
 
  470        return m_e[m_indices[*(index.begin())]];
 
  473    template <
class CT, 
class I>
 
  474    inline auto xindex_view<CT, I>::operator[](size_type i) -> reference
 
  485    template <
class CT, 
class I>
 
  487    inline auto xindex_view<CT, I>::operator[](
const S& index) 
const -> disable_integral_t<S, const_reference>
 
  489        return m_e[m_indices[index[0]]];
 
 
  492    template <
class CT, 
class I>
 
  494    inline auto xindex_view<CT, I>::operator[](std::initializer_list<OI> index) 
const -> const_reference
 
  496        return m_e[m_indices[*(index.begin())]];
 
  499    template <
class CT, 
class I>
 
  500    inline auto xindex_view<CT, I>::operator[](size_type i) 
const -> const_reference
 
  510    template <
class CT, 
class I>
 
  512    inline auto xindex_view<CT, I>::element(It first, It ) -> reference
 
  514        return m_e[m_indices[(*first)]];
 
 
  522    template <
class CT, 
class I>
 
  524    inline auto xindex_view<CT, I>::element(It first, It ) 
const -> const_reference
 
  526        return m_e[m_indices[(*first)]];
 
 
  532    template <
class CT, 
class I>
 
  541    template <
class CT, 
class I>
 
  559    template <
class CT, 
class I>
 
  563        return xt::broadcast_shape(m_shape, 
shape);
 
 
  571    template <
class CT, 
class I>
 
  584    template <
class CT, 
class I>
 
  586    inline auto xindex_view<CT, I>::stepper_begin(
const ST& shape) -> stepper
 
  588        size_type offset = shape.size() - 
dimension();
 
  589        return stepper(
this, offset);
 
  592    template <
class CT, 
class I>
 
  594    inline auto xindex_view<CT, I>::stepper_end(
const ST& 
shape, 
layout_type) -> stepper
 
  597        return stepper(
this, offset, 
true);
 
  600    template <
class CT, 
class I>
 
  605        return const_stepper(
this, offset);
 
  608    template <
class CT, 
class I>
 
  613        return const_stepper(
this, offset, 
true);
 
  616    template <
class CT, 
class I>
 
  620        return rebind_t<E>(std::forward<E>(e), indices_type(m_indices));
 
  638    template <
class ECT, 
class CCT>
 
  639    template <
class ECTA, 
class CCTA>
 
  641        : m_e(std::forward<ECTA>(e))
 
  642        , m_condition(std::forward<CCTA>(condition))
 
 
  657    template <
class ECT, 
class CCT>
 
  659    inline auto xfiltration<ECT, CCT>::operator=(
const E& e) -> disable_xexpression<E, self_type&>
 
  662            [
this, &e](const_reference v, 
bool cond)
 
 
  680    template <
class ECT, 
class CCT>
 
  682    inline auto xfiltration<ECT, CCT>::operator+=(
const E& e) -> disable_xexpression<E, self_type&>
 
  685            [&e](const_reference v, 
bool cond)
 
  687                return cond ? v + e : v;
 
 
  697    template <
class ECT, 
class CCT>
 
  699    inline auto xfiltration<ECT, CCT>::operator-=(
const E& e) -> disable_xexpression<E, self_type&>
 
  702            [&e](const_reference v, 
bool cond)
 
  704                return cond ? v - e : v;
 
 
  714    template <
class ECT, 
class CCT>
 
  716    inline auto xfiltration<ECT, CCT>::operator*=(
const E& e) -> disable_xexpression<E, self_type&>
 
  719            [&e](const_reference v, 
bool cond)
 
  721                return cond ? v * e : v;
 
 
  731    template <
class ECT, 
class CCT>
 
  733    inline auto xfiltration<ECT, CCT>::operator/=(
const E& e) -> disable_xexpression<E, self_type&>
 
  736            [&e](const_reference v, 
bool cond)
 
  738                return cond ? v / e : v;
 
 
  748    template <
class ECT, 
class CCT>
 
  750    inline auto xfiltration<ECT, CCT>::operator%=(
const E& e) -> disable_xexpression<E, self_type&>
 
  753            [&e](const_reference v, 
bool cond)
 
  755                return cond ? v % e : v;
 
 
  760    template <
class ECT, 
class CCT>
 
  762    inline auto xfiltration<ECT, CCT>::apply(F&& func) -> self_type&
 
  764        std::transform(m_e.cbegin(), m_e.cend(), m_condition.cbegin(), m_e.begin(), func);
 
  784    template <
class E, 
class I>
 
  788        return view_type(std::forward<E>(e), std::forward<I>(indices));
 
 
  791    template <
class E, std::
size_t L>
 
  792    inline auto index_view(E&& e, 
const xindex (&indices)[L]) 
noexcept 
  794        using view_type = xindex_view<xclosure_t<E>, std::array<xindex, L>>;
 
  795        return view_type(std::forward<E>(e), xt::to_array(indices));
 
  819    template <layout_type L = XTENSOR_DEFAULT_TRAVERSAL, 
class E, 
class O>
 
  820    inline auto filter(E&& e, O&& condition) 
noexcept 
  822        auto indices = 
argwhere<L>(std::forward<O>(condition));
 
  824        return view_type(std::forward<E>(e), std::move(indices));
 
 
  844    template <
class E, 
class C>
 
  848        return filtration_type(std::forward<E>(e), std::forward<C>(condition));
 
 
Base class for xexpressions.
Filter of a xexpression for fast scalar assign.
xfiltration(ECTA &&e, CCTA &&condition)
Constructs a xfiltration on the given expression e, selecting the elements matching the specified con...
View of an xexpression from vector of indices.
xindex_view(CTA &&e, I2 &&indices) noexcept
Constructs an xindex_view, selecting the indices specified by indices.
bool has_linear_assign(const O &) const noexcept
size_type size() const noexcept
Returns the size of the xindex_view.
reference unchecked(size_type idx)
reference operator()(size_type idx=size_type(0))
Returns a reference to the element at the specified position in the xindex_view.
xexpression_type & expression() noexcept
bool broadcast_shape(O &shape, bool reuse_cache=false) const
const inner_shape_type & shape() const noexcept
void fill(const T &value)
size_type dimension() const noexcept
Base class for multidimensional iterable expressions.
auto end() noexcept -> layout_iterator< L >
auto begin() noexcept -> layout_iterator< L >
auto operator%=(const E &e) -> disable_xexpression< E, derived_type & >
auto operator+=(const E &e) -> disable_xexpression< E, derived_type & >
auto operator*=(const E &e) -> disable_xexpression< E, derived_type & >
auto operator/=(const E &e) -> disable_xexpression< E, derived_type & >
auto operator-=(const E &e) -> disable_xexpression< E, derived_type & >
auto argwhere(const T &arr)
return vector of indices where arr is not zero
standard mathematical functions for xexpressions
xarray_container< uvector< T, A >, L, xt::svector< typename uvector< T, A >::size_type, 4, SA, true > > xarray
Alias template on xarray_container with default parameters for data container type and shape / stride...
auto filtration(E &&e, C &&condition) noexcept
creates a filtration of e filtered by condition.
auto index_view(E &&e, I &&indices) noexcept
creates an indexview from a container of indices.
auto filter(E &&e, O &&condition) noexcept
creates a view into e filtered by condition.