10#ifndef XTENSOR_VIEW_UTILS_HPP
11#define XTENSOR_VIEW_UTILS_HPP
17#include "xtensor_forward.hpp"
28 constexpr std::size_t integral_count();
32 constexpr std::size_t integral_count_before(std::size_t i);
36 constexpr std::size_t integral_skip(std::size_t i);
40 constexpr std::size_t newaxis_count();
44 constexpr std::size_t newaxis_count_before(std::size_t i);
48 constexpr std::size_t newaxis_skip(std::size_t i);
50 template <
class S,
class It>
51 inline disable_xslice<S, std::size_t> get_slice_value(
const S& s, It&)
noexcept
53 return static_cast<std::size_t
>(s);
56 template <
class S,
class It>
57 inline auto get_slice_value(
const xslice<S>& slice, It& it)
noexcept
59 return slice.derived_cast()(
typename S::size_type(*it));
68 template <
class T,
class S,
layout_type L,
class... SL>
69 struct view_temporary_type_impl
74 template <
class T,
class I, std::size_t N,
layout_type L,
class... SL>
75 struct view_temporary_type_impl<T, std::array<I, N>, L, SL...>
77 using type =
xt::xtensor<T, N + newaxis_count<SL...>() - integral_count<SL...>(), L>;
81 template <
class E,
class... SL>
84 using type =
typename detail::view_temporary_type_impl<
85 std::decay_t<typename E::value_type>,
86 typename E::shape_type,
91 template <
class E,
class...
SL>
101 template <
class T,
class...
S>
102 struct integral_count_impl
104 static constexpr std::size_t count(std::size_t
i)
noexcept
107 ? (integral_count_impl<S...>::count(
i - 1)
108 + (xtl::is_integral<std::remove_reference_t<T>>::value ? 1 : 0))
114 struct integral_count_impl<void>
116 static constexpr std::size_t count(std::size_t )
noexcept
123 template <
class... S>
124 constexpr std::size_t integral_count()
126 return detail::integral_count_impl<S..., void>::count(
sizeof...(S));
129 template <
class... S>
130 constexpr std::size_t integral_count_before(std::size_t i)
132 return detail::integral_count_impl<S..., void>::count(i);
142 struct is_newaxis : std::false_type
147 struct is_newaxis<xnewaxis<T>> :
public std::true_type
151 template <
class T,
class... S>
152 struct newaxis_count_impl
154 static constexpr std::size_t count(std::size_t i)
noexcept
157 ? (newaxis_count_impl<S...>::count(i - 1)
158 + (is_newaxis<std::remove_reference_t<T>>::value ? 1 : 0))
164 struct newaxis_count_impl<void>
166 static constexpr std::size_t count(std::size_t )
noexcept
173 template <
class... S>
174 constexpr std::size_t newaxis_count()
176 return detail::newaxis_count_impl<S..., void>::count(
sizeof...(S));
179 template <
class... S>
180 constexpr std::size_t newaxis_count_before(std::size_t i)
182 return detail::newaxis_count_impl<S..., void>::count(i);
192 template <
class T,
class... S>
193 struct integral_skip_impl
195 static constexpr std::size_t count(std::size_t i)
noexcept
197 return i == 0 ? count_impl() : count_impl(i);
202 static constexpr std::size_t count_impl(std::size_t i)
noexcept
205 + (xtl::is_integral<std::remove_reference_t<T>>::value
206 ? integral_skip_impl<S...>::count(i)
207 : integral_skip_impl<S...>::count(i - 1));
210 static constexpr std::size_t count_impl() noexcept
212 return xtl::is_integral<std::remove_reference_t<T>>::value
213 ? 1 + integral_skip_impl<S...>::count(0)
219 struct integral_skip_impl<void>
221 static constexpr std::size_t count(std::size_t i)
noexcept
228 template <
class... S>
229 constexpr std::size_t integral_skip(std::size_t i)
231 return detail::integral_skip_impl<S..., void>::count(i);
241 template <
class T,
class... S>
242 struct newaxis_skip_impl
244 static constexpr std::size_t count(std::size_t i)
noexcept
246 return i == 0 ? count_impl() : count_impl(i);
251 static constexpr std::size_t count_impl(std::size_t i)
noexcept
254 + (is_newaxis<std::remove_reference_t<T>>::value
255 ? newaxis_skip_impl<S...>::count(i)
256 : newaxis_skip_impl<S...>::count(i - 1));
259 static constexpr std::size_t count_impl() noexcept
261 return is_newaxis<std::remove_reference_t<T>>::value ? 1 + newaxis_skip_impl<S...>::count(0)
267 struct newaxis_skip_impl<void>
269 static constexpr std::size_t count(std::size_t i)
noexcept
276 template <
class... S>
277 constexpr std::size_t newaxis_skip(std::size_t i)
279 return detail::newaxis_skip_impl<S..., void>::count(i);
standard mathematical functions for xexpressions