10#ifndef XTENSOR_AXIS_ITERATOR_HPP
11#define XTENSOR_AXIS_ITERATOR_HPP
13#include "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<apply_cv_t<CT, value_type>>;
45 using pointer = xtl::xclosure_pointer<std::remove_reference_t<apply_cv_t<CT, value_type>>>;
47 using iterator_category = std::forward_iterator_tag;
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 std::enable_if_t<std::is_pointer<T>::value, T> get_storage_init(
CTA&&
e)
const;
73 template <
class T,
class CTA>
74 std::enable_if_t<!std::is_pointer<T>::value, T> get_storage_init(
CTA&&
e)
const;
87 auto axis_begin(E&&
e,
typename std::decay_t<E>::size_type axis);
93 auto axis_end(E&&
e,
typename std::decay_t<E>::size_type axis);
102 auto derive_xstrided_view(
104 typename std::decay_t<CT>::size_type axis,
105 typename std::decay_t<CT>::size_type
offset
108 using xexpression_type = std::decay_t<CT>;
109 using shape_type =
typename xexpression_type::shape_type;
110 using strides_type =
typename xexpression_type::strides_type;
113 shape_type shape(
e_shape.size() - 1);
127 template <
class T,
class CTA>
128 inline std::enable_if_t<std::is_pointer<T>::value, T> xaxis_iterator<CT>::get_storage_init(CTA&& e)
const
134 template <
class T,
class CTA>
135 inline std::enable_if_t<!std::is_pointer<T>::value, T> xaxis_iterator<CT>::get_storage_init(CTA&& e)
const
168 : p_expression(get_storage_init<storing_type>(std::
forward<
CTA>(
e)))
187 m_sv.set_offset(m_sv.data_offset() + m_add_offset);
229 return xtl::closure_pointer(
operator*());
247 return p_expression ==
rhs.p_expression && m_index ==
rhs.m_index
248 && m_sv.data_offset() ==
rhs.m_sv.data_offset();
288 return return_type(std::forward<E>(
e), 0);
299 inline auto axis_begin(E&&
e,
typename std::decay_t<E>::size_type axis)
302 return return_type(std::forward<E>(
e), axis);
315 using size_type =
typename std::decay_t<E>::size_type;
321 static_cast<size_type
>(
e.strides()[0]) *
e.shape()[0]
334 inline auto axis_end(E&&
e,
typename std::decay_t<E>::size_type axis)
336 using size_type =
typename std::decay_t<E>::size_type;
342 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.
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.
bool operator==(const xaxis_iterator< CT > &lhs, const xaxis_iterator< CT > &rhs)
Checks equality of the iterators.
auto axis_end(E &&e)
Returns an iterator to the element following the last element of the expression for axis 0.
bool operator!=(const xaxis_iterator< CT > &lhs, const xaxis_iterator< CT > &rhs)
Checks inequality of the iterators.
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.