10#ifndef XOPTIONAL_ASSEMBLY_BASE_HPP
11#define XOPTIONAL_ASSEMBLY_BASE_HPP
13#include "xiterable.hpp"
14#include "xoptional_assembly_storage.hpp"
15#include "xtensor_forward.hpp"
19 template <
class D,
bool is_const>
20 class xoptional_assembly_stepper;
47 using raw_value_expression =
typename inner_types::raw_value_expression;
48 using base_value_type =
typename raw_value_expression::value_type;
49 using base_reference =
typename raw_value_expression::reference;
50 using base_const_reference =
typename raw_value_expression::const_reference;
52 using raw_flag_expression =
typename inner_types::raw_flag_expression;
53 using flag_type =
typename raw_flag_expression::value_type;
54 using flag_reference =
typename raw_flag_expression::reference;
55 using flag_const_reference =
typename raw_flag_expression::const_reference;
57 using storage_type =
typename inner_types::storage_type;
59 using value_type =
typename storage_type::value_type;
60 using reference =
typename storage_type::reference;
61 using const_reference =
typename storage_type::const_reference;
62 using pointer =
typename storage_type::pointer;
63 using const_pointer =
typename storage_type::const_pointer;
64 using size_type =
typename raw_value_expression::size_type;
65 using difference_type =
typename raw_value_expression::difference_type;
66 using simd_value_type = xt_simd::simd_type<value_type>;
69 using shape_type =
typename raw_value_expression::shape_type;
70 using strides_type =
typename raw_value_expression::strides_type;
71 using backstrides_type =
typename raw_value_expression::backstrides_type;
73 using inner_shape_type =
typename raw_value_expression::inner_shape_type;
74 using inner_strides_type =
typename raw_value_expression::inner_strides_type;
75 using inner_backstrides_type =
typename raw_value_expression::inner_backstrides_type;
78 using stepper =
typename iterable_base::stepper;
79 using const_stepper =
typename iterable_base::const_stepper;
81 static constexpr layout_type static_layout = raw_value_expression::static_layout;
82 static constexpr bool contiguous_layout = raw_value_expression::contiguous_layout;
85 using value_expression = raw_value_expression&;
86 using flag_expression = raw_flag_expression&;
87 using const_value_expression =
const raw_value_expression&;
88 using const_flag_expression =
const raw_flag_expression&;
90 template <layout_type L>
92 template <layout_type L>
94 template <layout_type L>
96 template <layout_type L>
99 template <
class S, layout_type L>
101 template <
class S, layout_type L>
103 template <
class S, layout_type L>
105 template <
class S, layout_type L>
108 using linear_iterator =
typename storage_type::iterator;
109 using const_linear_iterator =
typename storage_type::const_iterator;
110 using reverse_linear_iterator =
typename storage_type::reverse_iterator;
111 using const_reverse_linear_iterator =
typename storage_type::const_reverse_iterator;
113 using iterator =
typename iterable_base::iterator;
114 using const_iterator =
typename iterable_base::const_iterator;
115 using reverse_iterator =
typename iterable_base::reverse_iterator;
116 using const_reverse_iterator =
typename iterable_base::const_reverse_iterator;
219 linear_iterator linear_begin()
noexcept;
220 linear_iterator linear_end()
noexcept;
227 reverse_linear_iterator linear_rbegin()
noexcept;
228 reverse_linear_iterator linear_rend()
noexcept;
230 const_reverse_linear_iterator linear_rbegin()
const noexcept;
232 const_reverse_linear_iterator linear_crbegin()
const noexcept;
281 using assembly_type =
typename D::assembly_type;
282 using value_type =
typename assembly_type::value_type;
283 using reference = std::
284 conditional_t<is_const, typename assembly_type::const_reference, typename assembly_type::reference>;
285 using pointer = std::conditional_t<is_const, typename assembly_type::const_pointer, typename assembly_type::pointer>;
286 using size_type =
typename assembly_type::size_type;
287 using difference_type =
typename assembly_type::difference_type;
288 using raw_value_expression =
typename assembly_type::raw_value_expression;
289 using raw_flag_expression =
typename assembly_type::raw_flag_expression;
290 using value_stepper = std::
291 conditional_t<is_const, typename raw_value_expression::const_stepper, typename raw_value_expression::stepper>;
292 using flag_stepper = std::
293 conditional_t<is_const, typename raw_flag_expression::const_stepper, typename raw_flag_expression::stepper>;
298 void step(size_type
dim);
299 void step_back(size_type
dim);
300 void step(size_type
dim, size_type
n);
301 void step_back(size_type
dim, size_type
n);
302 void reset(size_type
dim);
303 void reset_back(size_type
dim);
330 return value().size();
339 return value().dimension();
348 return value().shape();
366 return value().strides();
375 return value().backstrides();
449 return value().layout();
455 return value().is_contiguous();
466 std::fill(this->linear_begin(), this->linear_end(),
value);
480 template <
class...
Args>
493 template <
class...
Args>
509 template <
class...
Args>
525 template <
class...
Args>
551 template <
class...
Args>
577 template <
class...
Args>
604 inline auto xoptional_assembly_base<D>::operator[](size_type i) -> reference
631 inline auto xoptional_assembly_base<D>::operator[](size_type i)
const -> const_reference
644 template <
class... Args>
658 template <
class...
Args>
756 template <
class...
Args>
767 return derived_cast().storage_impl();
771 inline auto xoptional_assembly_base<D>::storage() const noexcept -> const storage_type&
773 return derived_cast().storage_impl();
777 inline auto xoptional_assembly_base<D>::data() noexcept -> value_type*
779 return storage().data();
783 inline auto xoptional_assembly_base<D>::data() const noexcept -> const value_type*
785 return storage().data();
789 inline auto xoptional_assembly_base<D>::data_offset() const noexcept -> const size_type
829 return linear_iterator(
value().linear_begin(),
has_value().linear_begin());
833 inline auto xoptional_assembly_base<D>::linear_end() noexcept -> linear_iterator
835 return linear_iterator(
value().linear_end(),
has_value().linear_end());
839 inline auto xoptional_assembly_base<D>::linear_begin() const noexcept -> const_linear_iterator
841 return linear_cbegin();
845 inline auto xoptional_assembly_base<D>::linear_end() const noexcept -> const_linear_iterator
847 return linear_cend();
851 inline auto xoptional_assembly_base<D>::linear_cbegin() const noexcept -> const_linear_iterator
853 return const_linear_iterator(
value().linear_cbegin(),
has_value().linear_cbegin());
857 inline auto xoptional_assembly_base<D>::linear_cend() const noexcept -> const_linear_iterator
859 return const_linear_iterator(
value().linear_cend(),
has_value().linear_cend());
863 inline auto xoptional_assembly_base<D>::linear_rbegin() noexcept -> reverse_linear_iterator
865 return reverse_linear_iterator(linear_end());
869 inline auto xoptional_assembly_base<D>::linear_rend() noexcept -> reverse_linear_iterator
871 return reverse_linear_iterator(linear_begin());
875 inline auto xoptional_assembly_base<D>::linear_rbegin() const noexcept -> const_reverse_linear_iterator
877 return linear_crbegin();
881 inline auto xoptional_assembly_base<D>::linear_rend() const noexcept -> const_reverse_linear_iterator
883 return linear_crend();
887 inline auto xoptional_assembly_base<D>::linear_crbegin() const noexcept -> const_reverse_linear_iterator
889 return const_reverse_linear_iterator(linear_cend());
893 inline auto xoptional_assembly_base<D>::linear_crend() const noexcept -> const_reverse_linear_iterator
895 return const_reverse_linear_iterator(linear_cbegin());
900 inline auto xoptional_assembly_base<D>::stepper_begin(
const S&
shape)
noexcept -> stepper
907 inline auto xoptional_assembly_base<D>::stepper_end(
const S&
shape,
layout_type l)
noexcept -> stepper
914 inline auto xoptional_assembly_base<D>::stepper_begin(
const S&
shape)
const noexcept -> const_stepper
921 inline auto xoptional_assembly_base<D>::stepper_end(
const S&
shape,
layout_type l)
const noexcept
933 return derived_cast().value_impl();
942 return derived_cast().value_impl();
951 return derived_cast().has_value_impl();
960 return derived_cast().has_value_impl();
966 return *
static_cast<derived_type*
>(
this);
970 inline auto xoptional_assembly_base<D>::derived_cast() const noexcept -> const derived_type&
972 return *
static_cast<const derived_type*
>(
this);
979 template <
class D,
bool C>
980 inline xoptional_assembly_stepper<D, C>::xoptional_assembly_stepper(value_stepper vs, flag_stepper fs) noexcept
986 template <
class D,
bool C>
987 inline void xoptional_assembly_stepper<D, C>::step(size_type dim)
993 template <
class D,
bool C>
994 inline void xoptional_assembly_stepper<D, C>::step_back(size_type dim)
1000 template <
class D,
bool C>
1001 inline void xoptional_assembly_stepper<D, C>::step(size_type dim, size_type n)
1007 template <
class D,
bool C>
1008 inline void xoptional_assembly_stepper<D, C>::step_back(size_type dim, size_type n)
1010 m_vs.step_back(dim, n);
1011 m_fs.step_back(dim, n);
1014 template <
class D,
bool C>
1015 inline void xoptional_assembly_stepper<D, C>::reset(size_type dim)
1021 template <
class D,
bool C>
1022 inline void xoptional_assembly_stepper<D, C>::reset_back(size_type dim)
1024 m_vs.reset_back(dim);
1025 m_fs.reset_back(dim);
1028 template <
class D,
bool C>
1029 inline void xoptional_assembly_stepper<D, C>::to_begin()
1035 template <
class D,
bool C>
1036 inline void xoptional_assembly_stepper<D, C>::to_end(
layout_type l)
1042 template <
class D,
bool C>
1043 inline auto xoptional_assembly_stepper<D, C>::operator*() const -> reference
1045 return reference(*m_vs, *m_fs);
Base class for multidimensional iterable constant expressions.
Base class for multidimensional iterable expressions.
Base class for dense multidimensional optional assemblies.
const inner_backstrides_type & backstrides() const noexcept
Returns the backstrides of the optional assembly.
reference front()
Returns a reference to the first element of the optional assembly.
bool in_bounds(Args... args) const
Returns true only if the the specified position is a valid entry in the expression.
size_type size() const noexcept
Returns the number of element in the optional assembly.
reference back()
Returns a reference to the last element of the optional assembly.
const inner_shape_type & shape() const noexcept
Returns the shape of the optional assembly.
value_expression value() noexcept
Return an expression for the values of the optional assembly.
void fill(const T &value)
Fills the data with the given value.
bool has_linear_assign(const S &strides) const noexcept
Checks whether the xoptional_assembly_base can be linearly assigned to an expression with the specifi...
layout_type layout() const noexcept
Return the layout_type of the container.
constexpr size_type dimension() const noexcept
Returns the number of dimensions of the optional assembly.
bool broadcast_shape(S &shape, bool reuse_cache=false) const
Broadcast the shape of the optional assembly to the specified parameter.
const inner_strides_type & strides() const noexcept
Returns the strides of the optional assembly.
reference flat(size_type args)
Returns a reference to the element at the specified position of the underlying storage in the optiona...
void resize(const S &shape, bool force=false)
Resizes the optional assembly.
auto & reshape(const S &shape, layout_type layout=static_layout) &
Reshapes the optional assembly.
flag_expression has_value() noexcept
Return an expression for the missing mask of the optional assembly.
auto operator*(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t< detail::multiplies, E1, E2 >
Multiplication.
standard mathematical functions for xexpressions