10#ifndef XTENSOR_AXIS_ITERATOR_HPP
11#define XTENSOR_AXIS_ITERATOR_HPP
13#include "../views/xstrided_view.hpp"
39 using xexpression_type = std::decay_t<CT>;
40 using size_type =
typename xexpression_type::size_type;
41 using difference_type =
typename xexpression_type::difference_type;
42 using shape_type =
typename xexpression_type::shape_type;
44 using reference = std::remove_reference_t<xtl::apply_cv_t<CT, value_type>>;
45 using pointer = xtl::xclosure_pointer<std::remove_reference_t<xtl::apply_cv_t<CT, value_type>>>;
47 using iterator_category = std::forward_iterator_tag;
52 xaxis_iterator(CTA&& e, size_type axis, size_type index, size_type offset);
60 bool equal(
const self_type& rhs)
const;
64 using storing_type = xtl::ptr_closure_type_t<CT>;
65 mutable storing_type p_expression;
67 size_type m_add_offset;
70 template <
class T,
class CTA>
71 T get_storage_init(CTA&& e)
const;
84 auto axis_begin(E&& e,
typename std::decay_t<E>::size_type axis);
90 auto axis_end(E&& e,
typename std::decay_t<E>::size_type axis);
99 auto derive_xstrided_view(
101 typename std::decay_t<CT>::size_type axis,
102 typename std::decay_t<CT>::size_type offset
105 using xexpression_type = std::decay_t<CT>;
106 using shape_type =
typename xexpression_type::shape_type;
107 using strides_type =
typename xexpression_type::strides_type;
109 const auto& e_shape = e.shape();
110 shape_type shape(e_shape.size() - 1);
111 auto nxt = std::copy(e_shape.cbegin(), e_shape.cbegin() + axis, shape.begin());
112 std::copy(e_shape.cbegin() + axis + 1, e_shape.end(), nxt);
114 const auto& e_strides = e.strides();
115 strides_type
strides(e_strides.size() - 1);
116 auto nxt_strides = std::copy(e_strides.cbegin(), e_strides.cbegin() + axis,
strides.begin());
117 std::copy(e_strides.cbegin() + axis + 1, e_strides.end(), nxt_strides);
119 return strided_view(std::forward<CT>(e), std::move(shape), std::move(
strides), offset, e.layout());
124 template <
class T,
class CTA>
125 inline T xaxis_iterator<CT>::get_storage_init(CTA&& e)
const
127 if constexpr (xtl::pointer_concept<T>)
165 : p_expression(get_storage_init<storing_type>(std::forward<CTA>(e)))
167 , m_add_offset(static_cast<size_type>(e.
strides()[axis]))
168 , m_sv(detail::derive_xstrided_view<CTA>(std::forward<CTA>(e), axis, offset))
184 m_sv.set_offset(m_sv.data_offset() + m_add_offset);
196 self_type tmp(*
this);
226 return xtl::closure_pointer(
operator*());
244 return p_expression == rhs.p_expression && m_index == rhs.m_index
256 return lhs.
equal(rhs);
266 return !(lhs == rhs);
285 return return_type(std::forward<E>(e), 0);
296 inline auto axis_begin(E&& e,
typename std::decay_t<E>::size_type axis)
299 return return_type(std::forward<E>(e), axis);
312 using size_type =
typename std::decay_t<E>::size_type;
318 static_cast<size_type
>(e.strides()[0]) * e.shape()[0]
331 inline auto axis_end(E&& e,
typename std::decay_t<E>::size_type axis)
333 using size_type =
typename std::decay_t<E>::size_type;
339 static_cast<size_type
>(e.strides()[axis]) * e.shape()[axis]
Class for iteration over (N-1)-dimensional slices, where N is the dimension of the underlying express...
reference operator*() const
Returns the strided view at the current iteration position.
pointer operator->() const
Returns a pointer to the strided view at the current iteration position.
xaxis_iterator(CTA &&e, size_type axis)
Constructs an xaxis_iterator.
self_type & operator++()
Increments the iterator to the next position and returns it.
bool equal(const self_type &rhs) const
Checks equality of the xaxis_slice_iterator and rhs.
View of an xexpression using strides.
size_type data_offset() const noexcept
Returns the offset to the first element in the view.
auto strides(const E &e, stride_type type=stride_type::normal) noexcept
Get strides of an object.
standard mathematical functions for xexpressions
auto axis_begin(E &&e)
Returns an iterator to the first element of the expression for axis 0.
auto axis_end(E &&e)
Returns an iterator to the element following the last element of the expression for axis 0.
auto strided_view(E &&e, S &&shape, X &&stride, std::size_t offset=0, layout_type layout=L) noexcept
Construct a strided view from an xexpression, shape, strides and offset.