From da944039c3bb0bc72b329b0129e185ca45cba8d3 Mon Sep 17 00:00:00 2001 From: Alexandre Hoffmann Date: Wed, 9 Apr 2025 10:56:27 +0200 Subject: [PATCH 1/6] feurst commit --- include/xtensor/containers/xfixed.hpp | 5 +- include/xtensor/containers/xscalar.hpp | 5 +- include/xtensor/containers/xstorage.hpp | 24 +- include/xtensor/core/xexpression.hpp | 3 + include/xtensor/core/xshape.hpp | 2 + include/xtensor/generators/xbuilder.hpp | 2 +- include/xtensor/generators/xgenerator.hpp | 12 +- include/xtensor/generators/xrandom.hpp | 19 +- include/xtensor/misc/xfft.hpp | 62 ++-- include/xtensor/misc/xmanipulation.hpp | 22 +- include/xtensor/misc/xset_operation.hpp | 8 +- include/xtensor/misc/xsort.hpp | 14 +- include/xtensor/misc/xtl_concepts.hpp | 23 ++ include/xtensor/utils/xtensor_simd.hpp | 2 + include/xtensor/utils/xutils.hpp | 17 +- include/xtensor/views/xview.hpp | 424 ++++++++++------------ 16 files changed, 306 insertions(+), 338 deletions(-) create mode 100644 include/xtensor/misc/xtl_concepts.hpp diff --git a/include/xtensor/containers/xfixed.hpp b/include/xtensor/containers/xfixed.hpp index 9661142dc..1d5686ffe 100644 --- a/include/xtensor/containers/xfixed.hpp +++ b/include/xtensor/containers/xfixed.hpp @@ -325,8 +325,7 @@ namespace xt explicit xfixed_container(const inner_shape_type& shape, layout_type l = L); explicit xfixed_container(const inner_shape_type& shape, value_type v, layout_type l = L); - // remove this enable_if when removing the other value_type constructor - template , class EN = std::enable_if_t> + template > requires (IX::value != 0) xfixed_container(nested_initializer_list_t t); ~xfixed_container() = default; @@ -639,7 +638,7 @@ namespace xt * Note: for clang < 3.8 this is an initializer_list and the size is not checked at compile-or runtime. */ template - template + template requires (IX::value != 0) inline xfixed_container::xfixed_container(nested_initializer_list_t t) { XTENSOR_ASSERT_MSG( diff --git a/include/xtensor/containers/xscalar.hpp b/include/xtensor/containers/xscalar.hpp index bfeba09b7..724efa0c9 100644 --- a/include/xtensor/containers/xscalar.hpp +++ b/include/xtensor/containers/xscalar.hpp @@ -316,7 +316,10 @@ namespace xt template using is_xscalar = detail::is_xscalar_impl; - + + template + concept is_xscalar_concept = is_xscalar>::value; + namespace detail { template diff --git a/include/xtensor/containers/xstorage.hpp b/include/xtensor/containers/xstorage.hpp index a3185259a..f756cd3fb 100644 --- a/include/xtensor/containers/xstorage.hpp +++ b/include/xtensor/containers/xstorage.hpp @@ -25,14 +25,6 @@ namespace xt { - - namespace detail - { - template - using require_input_iter = typename std::enable_if< - std::is_convertible::iterator_category, std::input_iterator_tag>::value>::type; - } - template struct is_contiguous_container : std::true_type { @@ -64,7 +56,7 @@ namespace xt explicit uvector(size_type count, const allocator_type& alloc = allocator_type()); uvector(size_type count, const_reference value, const allocator_type& alloc = allocator_type()); - template > + template uvector(InputIt first, InputIt last, const allocator_type& alloc = allocator_type()); uvector(std::initializer_list init, const allocator_type& alloc = allocator_type()); @@ -277,7 +269,7 @@ namespace xt } template - template + template inline uvector::uvector(InputIt first, InputIt last, const allocator_type& alloc) : m_allocator(alloc) , p_begin(nullptr) @@ -675,10 +667,10 @@ namespace xt svector(const std::vector& vec); - template > + template svector(IT begin, IT end, const allocator_type& alloc = allocator_type()); - template > + template requires (N != N2) explicit svector(const svector& rhs); svector& operator=(const svector& rhs); @@ -686,7 +678,7 @@ namespace xt svector& operator=(const std::vector& rhs); svector& operator=(std::initializer_list il); - template > + template requires (N != N2) svector& operator=(const svector& rhs); svector(const svector& other); @@ -809,7 +801,7 @@ namespace xt } template - template + template inline svector::svector(IT begin, IT end, const allocator_type& alloc) : m_allocator(alloc) { @@ -817,7 +809,7 @@ namespace xt } template - template + template requires (N != N2) inline svector::svector(const svector& rhs) : m_allocator(rhs.get_allocator()) { @@ -876,7 +868,7 @@ namespace xt } template - template + template requires (N != N2) inline svector& svector::operator=(const svector& rhs) { m_allocator = std::allocator_traits::select_on_container_copy_construction( diff --git a/include/xtensor/core/xexpression.hpp b/include/xtensor/core/xexpression.hpp index f32879035..00b2c79b3 100644 --- a/include/xtensor/core/xexpression.hpp +++ b/include/xtensor/core/xexpression.hpp @@ -178,6 +178,9 @@ namespace xt template using is_xexpression = is_crtp_base_of; + + template + concept xexpression_concept = is_xexpression::value; template using enable_xexpression = typename std::enable_if::value, R>::type; diff --git a/include/xtensor/core/xshape.hpp b/include/xtensor/core/xshape.hpp index b4027d9dd..e5f97de04 100644 --- a/include/xtensor/core/xshape.hpp +++ b/include/xtensor/core/xshape.hpp @@ -508,6 +508,8 @@ namespace xt }; } + template concept fixed_shape_container_concept = detail::is_fixed::shape_type>::value; + template struct promote_shape { diff --git a/include/xtensor/generators/xbuilder.hpp b/include/xtensor/generators/xbuilder.hpp index cb94cea0f..8a2f61147 100644 --- a/include/xtensor/generators/xbuilder.hpp +++ b/include/xtensor/generators/xbuilder.hpp @@ -833,7 +833,7 @@ namespace xt return detail::make_xgenerator(detail::concatenate_impl(std::move(t), axis), shape); } - template ::value>> + template inline auto concatenate(std::tuple&& t) { using shape_type = detail::concat_fixed_shape_t::shape_type...>; diff --git a/include/xtensor/generators/xgenerator.hpp b/include/xtensor/generators/xgenerator.hpp index 95c4fb753..b36971507 100644 --- a/include/xtensor/generators/xgenerator.hpp +++ b/include/xtensor/generators/xgenerator.hpp @@ -59,6 +59,8 @@ namespace xt template class xgenerator; + + template concept xgenerator_concept = is_specialization_of>::value; template struct xiterable_inner_types> @@ -80,10 +82,8 @@ namespace xt * overlapping_memory_checker_traits * *************************************/ - template - struct overlapping_memory_checker_traits< - E, - std::enable_if_t::value && is_specialization_of::value>> + template requires without_memory_address_concept + struct overlapping_memory_checker_traits { static bool check_overlap(const E&, const memory_range&) { @@ -165,7 +165,7 @@ namespace xt template const_stepper stepper_end(const O& shape, layout_type) const noexcept; - template ::value>> + template requires has_assign_to_v void assign_to(xexpression& e) const noexcept; const functor_type& functor() const noexcept; @@ -371,7 +371,7 @@ namespace xt } template - template + template requires has_assign_to_v inline void xgenerator::assign_to(xexpression& e) const noexcept { e.derived_cast().resize(m_shape); diff --git a/include/xtensor/generators/xrandom.hpp b/include/xtensor/generators/xrandom.hpp index dbb2819d7..1f488e5ae 100644 --- a/include/xtensor/generators/xrandom.hpp +++ b/include/xtensor/generators/xrandom.hpp @@ -29,6 +29,7 @@ #include "../generators/xgenerator.hpp" #include "../views/xindex_view.hpp" #include "../views/xview.hpp" +#include "../misc/xtl_concepts.hpp" namespace xt { @@ -175,13 +176,11 @@ namespace xt template void shuffle(xexpression& e, E& engine = random::get_default_random_engine()); - template - std::enable_if_t::value, xtensor> - permutation(T e, E& engine = random::get_default_random_engine()); + template + xtensor permutation(T e, E& engine = random::get_default_random_engine()); - template - std::enable_if_t>::value, std::decay_t> - permutation(T&& e, E& engine = random::get_default_random_engine()); + template + std::decay_t permutation(T&& e, E& engine = random::get_default_random_engine()); template xtensor choice( @@ -835,8 +834,8 @@ namespace xt * * @return randomly permuted copy of container or arange. */ - template - std::enable_if_t::value, xtensor> permutation(T e, E& engine) + template + xtensor permutation(T e, E& engine) { xt::xtensor res = xt::arange(e); shuffle(res, engine); @@ -844,8 +843,8 @@ namespace xt } /// @cond DOXYGEN_INCLUDE_SFINAE - template - std::enable_if_t>::value, std::decay_t> permutation(T&& e, E& engine) + template + std::decay_t permutation(T&& e, E& engine) { using copy_type = std::decay_t; copy_type res = e; diff --git a/include/xtensor/misc/xfft.hpp b/include/xtensor/misc/xfft.hpp index 5e54303ee..ad77708f7 100644 --- a/include/xtensor/misc/xfft.hpp +++ b/include/xtensor/misc/xfft.hpp @@ -5,6 +5,7 @@ #include +#include "./xtl_concepts.hpp" #include "../containers/xarray.hpp" #include "../core/xmath.hpp" #include "../core/xnoalias.hpp" @@ -19,9 +20,7 @@ namespace xt { namespace detail { - template < - class E, - typename std::enable_if::type::value_type>::value, bool>::type = true> + template inline auto radix2(E&& e) { using namespace xt::placeholders; @@ -119,19 +118,19 @@ namespace xt } } // namespace detail - /** + /** * @brief 1D FFT of an Nd array along a specified axis * @param e an Nd expression to be transformed to the fourier domain * @param axis the axis along which to perform the 1D FFT * @return a transformed xarray of the specified precision */ - template < - class E, - typename std::enable_if::type::value_type>::value, bool>::type = true> + template inline auto fft(E&& e, std::ptrdiff_t axis = -1) { - using value_type = typename std::decay_t::value_type; - using precision = typename value_type::value_type; + using value_type = typename std::decay::type::value_type; + if constexpr (xtl::is_complex::type::value_type>::value) + { + using precision = typename value_type::value_type; const auto saxis = xt::normalize_axis(e.dimension(), axis); const size_t N = e.shape(saxis); const bool powerOfTwo = !(N == 0) && !(N & (N - 1)); @@ -150,29 +149,19 @@ namespace xt } } return out; - } - - /** - * @brief 1D FFT of an Nd array along a specified axis - * @param e an Nd expression to be transformed to the fourier domain - * @param axis the axis along which to perform the 1D FFT - * @return a transformed xarray of the specified precision - */ - template < - class E, - typename std::enable_if::type::value_type>::value, bool>::type = true> - inline auto fft(E&& e, std::ptrdiff_t axis = -1) - { - using value_type = typename std::decay::type::value_type; - return fft(xt::cast>(e), axis); - } - - template < - class E, - typename std::enable_if::type::value_type>::value, bool>::type = true> - auto ifft(E&& e, std::ptrdiff_t axis = -1) + } + else + { + return fft(xt::cast>(e), axis); + } + } + + template + inline auto ifft(E&& e, std::ptrdiff_t axis = -1) { - // check the length of the data on that axis + if constexpr (xtl::is_complex::type::value_type>::value) + { + // check the length of the data on that axis const std::size_t n = e.shape(axis); if (n == 0) { @@ -182,15 +171,12 @@ namespace xt auto fft_res = xt::fft::fft(complex_args, axis); fft_res = xt::conj(fft_res); return fft_res; - } - - template < - class E, - typename std::enable_if::type::value_type>::value, bool>::type = true> - inline auto ifft(E&& e, std::ptrdiff_t axis = -1) - { + } + else + { using value_type = typename std::decay::type::value_type; return ifft(xt::cast>(e), axis); + } } /* diff --git a/include/xtensor/misc/xmanipulation.hpp b/include/xtensor/misc/xmanipulation.hpp index 42395dd57..9be2a9649 100644 --- a/include/xtensor/misc/xmanipulation.hpp +++ b/include/xtensor/misc/xmanipulation.hpp @@ -22,6 +22,7 @@ #include "../utils/xutils.hpp" #include "../views/xrepeat.hpp" #include "../views/xstrided_view.hpp" +#include "xtl_concepts.hpp" namespace xt { @@ -64,7 +65,7 @@ namespace xt template auto squeeze(E&& e); - template ::value, int> = 0> + template auto squeeze(E&& e, S&& axis, Tag check_policy = Tag()); template @@ -210,20 +211,21 @@ namespace xt return transpose_impl(std::forward(e), std::forward(permutation), check_policy::none()); } - template >::value>* = nullptr> - inline void compute_transposed_strides(E&& e, const S&, X& strides) - { - std::copy(e.strides().crbegin(), e.strides().crend(), strides.begin()); - } - - template >::value>* = nullptr> - inline void compute_transposed_strides(E&&, const S& shape, X& strides) + template + inline void compute_transposed_strides(E&& e, const S& shape, X& strides) { + if constexpr (has_data_interface>::value) + { + std::copy(e.strides().crbegin(), e.strides().crend(), strides.begin()); + } + else + { // In the case where E does not have a data interface, the transposition // makes use of a flat storage adaptor that has layout XTENSOR_DEFAULT_TRAVERSAL // which should be the one inverted. layout_type l = transpose_layout(XTENSOR_DEFAULT_TRAVERSAL); compute_strides(shape, l, strides); + } } } @@ -588,7 +590,7 @@ namespace xt * @param check_policy select check_policy. With check_policy::full(), selecting an axis * which is greater than one will throw a runtime_error. */ - template ::value, int>> + template inline auto squeeze(E&& e, S&& axis, Tag check_policy) { return detail::squeeze_impl(std::forward(e), std::forward(axis), check_policy); diff --git a/include/xtensor/misc/xset_operation.hpp b/include/xtensor/misc/xset_operation.hpp index 598382855..c5a434c21 100644 --- a/include/xtensor/misc/xset_operation.hpp +++ b/include/xtensor/misc/xset_operation.hpp @@ -87,7 +87,7 @@ namespace xt * @param test_elements an array * @return a boolean array */ - template ::value>> + template requires has_iterator_interface_concept inline auto isin(E&& element, F&& test_elements) noexcept { auto lambda = detail::lambda_isin::value>::make(std::forward(test_elements @@ -106,7 +106,7 @@ namespace xt * @param test_elements_end iterator to the end of an array * @return a boolean array */ - template ::value>> + template inline auto isin(E&& element, I&& test_elements_begin, I&& test_elements_end) noexcept { auto lambda = [&test_elements_begin, &test_elements_end](const auto& t) @@ -143,7 +143,7 @@ namespace xt * @param test_elements an array * @return a boolean array */ - template ::value>> + template requires has_iterator_interface_concept inline auto in1d(E&& element, F&& test_elements) noexcept { XTENSOR_ASSERT(element.dimension() == 1ul); @@ -162,7 +162,7 @@ namespace xt * @param test_elements_end iterator to the end of an array * @return a boolean array */ - template ::value>> + template inline auto in1d(E&& element, I&& test_elements_begin, I&& test_elements_end) noexcept { XTENSOR_ASSERT(element.dimension() == 1ul); diff --git a/include/xtensor/misc/xsort.hpp b/include/xtensor/misc/xsort.hpp index 9261ac8c4..d76a38b71 100644 --- a/include/xtensor/misc/xsort.hpp +++ b/include/xtensor/misc/xsort.hpp @@ -563,9 +563,8 @@ namespace xt */ template < class E, - class C, - class R = detail::flatten_sort_result_type_t, - class = std::enable_if_t::value, int>> + xtl::non_integral_concept C, + class R = detail::flatten_sort_result_type_t> inline R partition(const xexpression& e, C kth_container, placeholders::xtuph /*ax*/) { const auto& de = e.derived_cast(); @@ -596,7 +595,7 @@ namespace xt return partition(e, std::array({kth}), tag); } - template ::value, int>> + template inline auto partition(const xexpression& e, C kth_container, std::ptrdiff_t axis = -1) { using eval_type = typename detail::sort_eval_type::type; @@ -658,9 +657,8 @@ namespace xt */ template < class E, - class C, - class R = typename detail::linear_argsort_result_type::type>::type, - class = std::enable_if_t::value, int>> + xtl::non_integral_concept C, + class R = typename detail::linear_argsort_result_type::type>::type> inline R argpartition(const xexpression& e, C kth_container, placeholders::xtuph) { using eval_type = typename detail::sort_eval_type::type; @@ -704,7 +702,7 @@ namespace xt return argpartition(e, std::array({kth}), tag); } - template ::value, int>> + template inline auto argpartition(const xexpression& e, C kth_container, std::ptrdiff_t axis = -1) { using eval_type = typename detail::sort_eval_type::type; diff --git a/include/xtensor/misc/xtl_concepts.hpp b/include/xtensor/misc/xtl_concepts.hpp new file mode 100644 index 000000000..c56b6f09f --- /dev/null +++ b/include/xtensor/misc/xtl_concepts.hpp @@ -0,0 +1,23 @@ +/*************************************************************************** + * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ + +#ifndef XTENSOR_CONCEPTS_HPP +#define XTENSOR_CONCEPTS_HPP + +#include +#include + +namespace xtl +{ + template concept integral_concept = xtl::is_integral::value; + template concept non_integral_concept = !xtl::is_integral::value; + template concept complex_concept = xtl::is_complex::type::value_type>::value; +} + +#endif // XTENSOR_CONCEPTS_HPP diff --git a/include/xtensor/utils/xtensor_simd.hpp b/include/xtensor/utils/xtensor_simd.hpp index b6cad1470..12f3de497 100644 --- a/include/xtensor/utils/xtensor_simd.hpp +++ b/include/xtensor/utils/xtensor_simd.hpp @@ -268,6 +268,8 @@ namespace xt struct has_simd_interface : detail::has_simd_interface_impl { }; + + template concept has_simd_interface_concept = has_simd_interface::value; template struct has_simd_type : std::integral_constant>::value> diff --git a/include/xtensor/utils/xutils.hpp b/include/xtensor/utils/xutils.hpp index 91d402e7f..a2475a7dc 100644 --- a/include/xtensor/utils/xutils.hpp +++ b/include/xtensor/utils/xutils.hpp @@ -585,7 +585,9 @@ namespace xt struct has_data_interface().data())>> : std::true_type { }; - + + template concept has_data_interface_concept = has_data_interface::value; + template struct has_strides : std::false_type { @@ -605,6 +607,9 @@ namespace xt struct has_iterator_interface().begin())>> : std::true_type { }; + + template + concept has_iterator_interface_concept = has_iterator_interface::value; /****************************** * is_iterator implementation * @@ -623,7 +628,10 @@ namespace xt : std::true_type { }; - + + template concept iterator_concept = is_iterator::value; + template concept input_iterator_concept = std::is_convertible::iterator_category, std::input_iterator_tag>::value; + /******************************************** * xtrivial_default_construct implemenation * ********************************************/ @@ -792,6 +800,8 @@ namespace xt : std::true_type { }; + + template constexpr bool has_assign_to_v = has_assign_to ::value ; /************************************* * overlapping_memory_checker_traits * @@ -806,6 +816,9 @@ namespace xt struct has_memory_address().begin()))>> : std::true_type { }; + + template concept with_memory_address_concept = has_memory_address< std::decay_t >::value; + template concept without_memory_address_concept = !has_memory_address< std::decay_t >::value; struct memory_range { diff --git a/include/xtensor/views/xview.hpp b/include/xtensor/views/xview.hpp index 85515da22..0c4868afc 100644 --- a/include/xtensor/views/xview.hpp +++ b/include/xtensor/views/xview.hpp @@ -289,6 +289,9 @@ namespace xt }; } + template concept contiguous_view_concept = detail::is_contiguous_view::value; + template concept strided_view_concept = detail::is_strided_view, S...>::value; + template struct xcontainer_inner_types> { @@ -493,95 +496,72 @@ namespace xt template bool has_linear_assign(const ST& strides) const; - template - std::enable_if_t stepper_begin(const ST& shape); - template - std::enable_if_t stepper_end(const ST& shape, layout_type l); - - template - std::enable_if_t stepper_begin(const ST& shape) const; - template - std::enable_if_t stepper_end(const ST& shape, layout_type l) const; - - template - std::enable_if_t stepper_begin(const ST& shape); - template - std::enable_if_t stepper_end(const ST& shape, layout_type l); - - template - std::enable_if_t stepper_begin(const ST& shape) const; - template - std::enable_if_t stepper_end(const ST& shape, layout_type l) const; - - template - std::enable_if_t::value, storage_type&> storage(); + template + stepper stepper_begin(const ST& shape); + template + stepper stepper_end(const ST& shape, layout_type l); + + template + const_stepper stepper_begin(const ST& shape) const; + template + const_stepper stepper_end(const ST& shape, layout_type l) const; + + template requires has_data_interface_concept + storage_type& storage(); - template - std::enable_if_t::value, const storage_type&> storage() const; + template requires has_data_interface_concept + const storage_type& storage() const; - template - std::enable_if_t::value && is_strided_view, linear_iterator> linear_begin(); + template requires has_data_interface_concept and strided_view_concept + linear_iterator linear_begin(); - template - std::enable_if_t::value && is_strided_view, linear_iterator> linear_end(); + template requires has_data_interface_concept and strided_view_concept + linear_iterator linear_end(); - template - std::enable_if_t::value && is_strided_view, const_linear_iterator> - linear_begin() const; + template requires has_data_interface_concept and strided_view_concept + const_linear_iterator linear_begin() const; - template - std::enable_if_t::value && is_strided_view, const_linear_iterator> - linear_end() const; + template requires has_data_interface_concept and strided_view_concept + const_linear_iterator linear_end() const; - template - std::enable_if_t::value && is_strided_view, const_linear_iterator> - linear_cbegin() const; + template requires has_data_interface_concept and strided_view_concept + const_linear_iterator linear_cbegin() const; - template - std::enable_if_t::value && is_strided_view, const_linear_iterator> - linear_cend() const; + template requires has_data_interface_concept and strided_view_concept + const_linear_iterator linear_cend() const; - template - std::enable_if_t::value && is_strided_view, reverse_linear_iterator> - linear_rbegin(); + template requires has_data_interface_concept and strided_view_concept + reverse_linear_iterator linear_rbegin(); - template - std::enable_if_t::value && is_strided_view, reverse_linear_iterator> - linear_rend(); + template requires has_data_interface_concept and strided_view_concept + reverse_linear_iterator linear_rend(); - template - std::enable_if_t::value && is_strided_view, const_reverse_linear_iterator> - linear_rbegin() const; + template requires has_data_interface_concept and strided_view_concept + const_reverse_linear_iterator linear_rbegin() const; - template - std::enable_if_t::value && is_strided_view, const_reverse_linear_iterator> - linear_rend() const; + template requires has_data_interface_concept and strided_view_concept + const_reverse_linear_iterator linear_rend() const; - template - std::enable_if_t::value && is_strided_view, const_reverse_linear_iterator> - linear_crbegin() const; + template requires has_data_interface_concept and strided_view_concept + const_reverse_linear_iterator linear_crbegin() const; - template - std::enable_if_t::value && is_strided_view, const_reverse_linear_iterator> - linear_crend() const; + template requires has_data_interface_concept and strided_view_concept + const_reverse_linear_iterator linear_crend() const; - template - std::enable_if_t::value && is_strided_view, const inner_strides_type&> - strides() const; + template requires has_data_interface_concept and strided_view_concept + const inner_strides_type& strides() const; - template - std::enable_if_t::value && is_strided_view, const inner_strides_type&> - backstrides() const; + template requires has_data_interface_concept and strided_view_concept + const inner_strides_type& backstrides() const; - template - std::enable_if_t::value && is_strided_view, const_pointer> data() const; + template requires has_data_interface_concept and strided_view_concept + const_pointer data() const; - template - std::enable_if_t::value && is_strided_view, pointer> data(); + template requires has_data_interface_concept and strided_view_concept + pointer data(); - template - std::enable_if_t::value && is_strided_view, std::size_t> - data_offset() const noexcept; + template requires has_data_interface_concept and strided_view_concept + std::size_t data_offset() const noexcept; template inline It data_xbegin_impl(It begin) const noexcept; @@ -595,13 +575,13 @@ namespace xt inline const_container_iterator data_xend(layout_type l, size_type offset) const noexcept; // Conversion operator enabled for statically "scalar" views - template >::value, int>> + template operator reference() { return (*this)(); } - template >::value, int>> + template operator const_reference() const { return (*this)(); @@ -615,8 +595,7 @@ namespace xt template < class E, - class T = xexpression_type, - class = std::enable_if_t::value && is_contiguous_view, int>> + class T = xexpression_type> requires has_data_interface_concept and contiguous_view_concept void assign_to(xexpression& e, bool force_resize) const; template @@ -632,39 +611,36 @@ namespace xt template using simd_return_type = xt_simd::simd_return_type; - template - using enable_simd_interface = std::enable_if_t::value && is_strided_view, R>; - - template - enable_simd_interface store_simd(size_type i, const simd& e); + template requires has_simd_interface_concept and strided_view_concept + void store_simd(size_type i, const simd& e); template < class align, class requested_type = value_type, std::size_t N = xt_simd::simd_traits::size, - class T = xexpression_type> - enable_simd_interface> load_simd(size_type i) const; + class T = xexpression_type> requires has_simd_interface_concept and strided_view_concept + simd_return_type load_simd(size_type i) const; - template - enable_simd_interface data_element(size_type i); + template requires has_simd_interface_concept and strided_view_concept + reference data_element(size_type i); - template - enable_simd_interface data_element(size_type i) const; + template requires has_simd_interface_concept and strided_view_concept + const_reference data_element(size_type i) const; - template - enable_simd_interface flat(size_type i); + template requires has_simd_interface_concept and strided_view_concept + reference flat(size_type i); - template - enable_simd_interface flat(size_type i) const; + template requires has_simd_interface_concept and strided_view_concept + const_reference flat(size_type i) const; private: // VS 2015 workaround (yes, really) - template - struct lesser_condition - { - static constexpr bool value = (I + newaxis_count_before(I + 1) < sizeof...(S)); - }; + //template + //struct lesser_condition + //{ + // static constexpr bool value = (I + newaxis_count_before(I + 1) < sizeof...(S)); + //}; CT m_e; slice_type m_slices; @@ -708,11 +684,11 @@ namespace xt template ::size_type... I, class... Args> const_reference access_impl(std::index_sequence, Args... args) const; - template ::size_type I, class... Args> - std::enable_if_t::value, size_type> index(Args... args) const; + template ::size_type I, class... Args> requires (I + newaxis_count_before(I + 1) < sizeof...(S)) + size_type index(Args... args) const; - template ::size_type I, class... Args> - std::enable_if_t::value, size_type> index(Args... args) const; + template ::size_type I, class... Args> requires (!(I + newaxis_count_before(I + 1) < sizeof...(S))) + size_type index(Args... args) const; template ::size_type, class T> size_type sliced_access(const xslice& slice) const; @@ -1151,112 +1127,100 @@ namespace xt * on a realized container. */ template - template - inline auto xview::storage() -> std::enable_if_t::value, storage_type&> + template requires has_data_interface_concept + inline auto xview::storage() -> storage_type& { return m_e.storage(); } template - template + template requires has_data_interface_concept inline auto xview::storage() const - -> std::enable_if_t::value, const storage_type&> + -> const storage_type& { return m_e.storage(); } template - template - auto xview::linear_begin() - -> std::enable_if_t::value && is_strided_view, linear_iterator> + template requires (has_data_interface_concept and strided_view_concept) + auto xview::linear_begin() -> linear_iterator { return m_e.storage().begin() + data_offset(); } template - template - auto xview::linear_end() - -> std::enable_if_t::value && is_strided_view, linear_iterator> + template requires has_data_interface_concept and strided_view_concept + auto xview::linear_end() -> linear_iterator { return m_e.storage().begin() + data_offset() + this->size(); } template - template - auto xview::linear_begin() const - -> std::enable_if_t::value && is_strided_view, const_linear_iterator> + template requires has_data_interface_concept and strided_view_concept + auto xview::linear_begin() const -> const_linear_iterator { return linear_cbegin(); } template - template - auto xview::linear_end() const - -> std::enable_if_t::value && is_strided_view, const_linear_iterator> + template requires has_data_interface_concept and strided_view_concept + auto xview::linear_end() const -> const_linear_iterator { return linear_cend(); } template - template - auto xview::linear_cbegin() const - -> std::enable_if_t::value && is_strided_view, const_linear_iterator> + template requires has_data_interface_concept and strided_view_concept + auto xview::linear_cbegin() const -> const_linear_iterator { return m_e.storage().cbegin() + data_offset(); } template - template - auto xview::linear_cend() const - -> std::enable_if_t::value && is_strided_view, const_linear_iterator> + template requires has_data_interface_concept and strided_view_concept + auto xview::linear_cend() const -> const_linear_iterator { return m_e.storage().cbegin() + data_offset() + this->size(); } template - template - auto xview::linear_rbegin() - -> std::enable_if_t::value && is_strided_view, reverse_linear_iterator> + template requires has_data_interface_concept and strided_view_concept + auto xview::linear_rbegin() -> reverse_linear_iterator { return reverse_linear_iterator(linear_end()); } template - template - auto xview::linear_rend() - -> std::enable_if_t::value && is_strided_view, reverse_linear_iterator> + template requires has_data_interface_concept and strided_view_concept + auto xview::linear_rend() -> reverse_linear_iterator { return reverse_linear_iterator(linear_begin()); } template - template - auto xview::linear_rbegin() const - -> std::enable_if_t::value && is_strided_view, const_reverse_linear_iterator> + template requires has_data_interface_concept and strided_view_concept + auto xview::linear_rbegin() const -> const_reverse_linear_iterator { return linear_crbegin(); } template - template - auto xview::linear_rend() const - -> std::enable_if_t::value && is_strided_view, const_reverse_linear_iterator> + template requires has_data_interface_concept and strided_view_concept + auto xview::linear_rend() const -> const_reverse_linear_iterator { return linear_crend(); } template - template - auto xview::linear_crbegin() const - -> std::enable_if_t::value && is_strided_view, const_reverse_linear_iterator> + template requires has_data_interface_concept and strided_view_concept + auto xview::linear_crbegin() const -> const_reverse_linear_iterator { return const_reverse_linear_iterator(linear_end()); } template - template - auto xview::linear_crend() const - -> std::enable_if_t::value && is_strided_view, const_reverse_linear_iterator> + template requires has_data_interface_concept and strided_view_concept + auto xview::linear_crend() const -> const_reverse_linear_iterator { return const_reverse_linear_iterator(linear_begin()); } @@ -1265,9 +1229,8 @@ namespace xt * Return the strides for the underlying container of the view. */ template - template - inline auto xview::strides() const - -> std::enable_if_t::value && is_strided_view, const inner_strides_type&> + template requires has_data_interface_concept and strided_view_concept + inline auto xview::strides() const -> const inner_strides_type& { if (!m_strides_computed) { @@ -1278,9 +1241,8 @@ namespace xt } template - template - inline auto xview::backstrides() const - -> std::enable_if_t::value && is_strided_view, const inner_strides_type&> + template requires has_data_interface_concept and strided_view_concept + inline auto xview::backstrides() const -> const inner_strides_type& { if (!m_strides_computed) { @@ -1294,17 +1256,15 @@ namespace xt * Return the pointer to the underlying buffer. */ template - template - inline auto xview::data() const - -> std::enable_if_t::value && is_strided_view, const_pointer> + template requires has_data_interface_concept and strided_view_concept + inline auto xview::data() const -> const_pointer { return m_e.data(); } template - template - inline auto xview::data() - -> std::enable_if_t::value && is_strided_view, pointer> + template requires has_data_interface_concept and strided_view_concept + inline auto xview::data() -> pointer { return m_e.data(); } @@ -1334,9 +1294,8 @@ namespace xt * Return the offset to the first element of the view in the underlying container. */ template - template - inline auto xview::data_offset() const noexcept - -> std::enable_if_t::value && is_strided_view, std::size_t> + template requires has_data_interface_concept and strided_view_concept + inline std::size_t xview::data_offset() const noexcept { if (!m_strides_computed) { @@ -1451,7 +1410,7 @@ namespace xt // Assign to operator enabled for contigous views template - template + template requires has_data_interface_concept and contiguous_view_concept void xview::assign_to(xexpression& e, bool force_resize) const { auto& de = e.derived_cast(); @@ -1474,45 +1433,44 @@ namespace xt } template - template - inline auto xview::store_simd(size_type i, const simd& e) -> enable_simd_interface + template requires has_simd_interface_concept and strided_view_concept + inline auto xview::store_simd(size_type i, const simd& e) -> void { return m_e.template store_simd(data_offset() + i, e); } template - template - inline auto xview::load_simd(size_type i) const - -> enable_simd_interface> + template requires has_simd_interface_concept and strided_view_concept + inline auto xview::load_simd(size_type i) const -> simd_return_type { return m_e.template load_simd(data_offset() + i); } template - template - inline auto xview::data_element(size_type i) -> enable_simd_interface + template requires has_simd_interface_concept and strided_view_concept + inline auto xview::data_element(size_type i) -> reference { return m_e.data_element(data_offset() + i); } template - template - inline auto xview::data_element(size_type i) const -> enable_simd_interface + template requires has_simd_interface_concept and strided_view_concept + inline auto xview::data_element(size_type i) const -> const_reference { return m_e.data_element(data_offset() + i); } template - template - inline auto xview::flat(size_type i) -> enable_simd_interface + template requires has_simd_interface_concept and strided_view_concept + inline auto xview::flat(size_type i) -> reference { XTENSOR_ASSERT(is_contiguous()); return m_e.flat(data_offset() + i); } template - template - inline auto xview::flat(size_type i) const -> enable_simd_interface + template requires has_simd_interface_concept and strided_view_concept + inline auto xview::flat(size_type i) const -> const_reference { XTENSOR_ASSERT(is_contiguous()); return m_e.flat(data_offset() + i); @@ -1635,9 +1593,8 @@ namespace xt } template - template ::size_type I, class... Args> - inline auto xview::index(Args... args) const - -> std::enable_if_t::value, size_type> + template ::size_type I, class... Args> requires (I + newaxis_count_before(I + 1) < sizeof...(S)) + inline auto xview::index(Args... args) const -> size_type { return sliced_access(I) + newaxis_count_before(I + 1)>( std::get(I + 1)>(m_slices), @@ -1646,9 +1603,8 @@ namespace xt } template - template ::size_type I, class... Args> - inline auto xview::index(Args... args) const - -> std::enable_if_t::value, size_type> + template ::size_type I, class... Args> requires (!(I + newaxis_count_before(I + 1) < sizeof...(S))) + inline auto xview::index(Args... args) const -> size_type { return argument() + newaxis_count()>(args...); } @@ -1928,76 +1884,66 @@ namespace xt * stepper api * ***************/ - template - template - inline auto xview::stepper_begin(const ST& shape) -> std::enable_if_t - { - size_type offset = shape.size() - this->dimension(); - return stepper(this, m_e.stepper_begin(m_e.shape()), offset); - } - - template - template - inline auto xview::stepper_end(const ST& shape, layout_type l) - -> std::enable_if_t - { - size_type offset = shape.size() - this->dimension(); - return stepper(this, m_e.stepper_end(m_e.shape(), l), offset, true, l); - } - - template - template - inline auto xview::stepper_begin(const ST& shape) const - -> std::enable_if_t - { - size_type offset = shape.size() - this->dimension(); - const xexpression_type& e = m_e; - return const_stepper(this, e.stepper_begin(m_e.shape()), offset); - } - - template - template - inline auto xview::stepper_end(const ST& shape, layout_type l) const - -> std::enable_if_t - { - size_type offset = shape.size() - this->dimension(); - const xexpression_type& e = m_e; - return const_stepper(this, e.stepper_end(m_e.shape(), l), offset, true, l); - } - - template - template - inline auto xview::stepper_begin(const ST& shape) -> std::enable_if_t + template + template + inline auto xview::stepper_begin(const ST& shape) -> stepper { - size_type offset = shape.size() - this->dimension(); + const size_type offset = shape.size() - this->dimension(); + if constexpr (is_strided_view) + { return stepper(this, data_xbegin(), offset); - } - - template - template - inline auto xview::stepper_end(const ST& shape, layout_type l) - -> std::enable_if_t + } + else + { + return stepper(this, m_e.stepper_begin(m_e.shape()), offset); + } + } + + template + template + inline auto xview::stepper_end(const ST& shape, layout_type l) -> stepper { - size_type offset = shape.size() - this->dimension(); + const size_type offset = shape.size() - this->dimension(); + if constexpr (is_strided_view) + { return stepper(this, data_xend(l, offset), offset); + } + else + { + return stepper(this, m_e.stepper_end(m_e.shape(), l), offset, true, l); + } + } + + template + template + inline auto xview::stepper_begin(const ST& shape) const -> const_stepper + { + const size_type offset = shape.size() - this->dimension(); + if constexpr (is_strided_view) + { + return const_stepper(this, data_xbegin(), offset); + } + else + { + const xexpression_type& e = m_e; + return const_stepper(this, e.stepper_begin(m_e.shape()), offset); + } } - - template - template - inline auto xview::stepper_begin(const ST& shape) const - -> std::enable_if_t - { - size_type offset = shape.size() - this->dimension(); - return const_stepper(this, data_xbegin(), offset); - } - - template - template - inline auto xview::stepper_end(const ST& shape, layout_type l) const - -> std::enable_if_t - { - size_type offset = shape.size() - this->dimension(); - return const_stepper(this, data_xend(l, offset), offset); + + template + template + inline auto xview::stepper_end(const ST& shape, layout_type l) const -> const_stepper + { + const size_type offset = shape.size() - this->dimension(); + if constexpr (is_strided_view) + { + return const_stepper(this, data_xend(l, offset), offset); + } + else + { + const xexpression_type& e = m_e; + return const_stepper(this, e.stepper_end(m_e.shape(), l), offset, true, l); + } } /******************************** From f8d7fba6085e16fbd0cb6d66b5a0568627c18a4f Mon Sep 17 00:00:00 2001 From: Alexandre Hoffmann Date: Wed, 9 Apr 2025 16:24:02 +0200 Subject: [PATCH 2/6] - --- include/xtensor/containers/xfixed.hpp | 10 +- include/xtensor/containers/xscalar.hpp | 6 +- include/xtensor/containers/xstorage.hpp | 18 +- include/xtensor/core/xexpression.hpp | 2 +- include/xtensor/core/xshape.hpp | 3 +- include/xtensor/generators/xgenerator.hpp | 17 +- include/xtensor/generators/xrandom.hpp | 10 +- include/xtensor/misc/xfft.hpp | 86 ++--- include/xtensor/misc/xmanipulation.hpp | 24 +- include/xtensor/misc/xset_operation.hpp | 8 +- include/xtensor/misc/xsort.hpp | 5 +- include/xtensor/misc/xtl_concepts.hpp | 13 +- include/xtensor/utils/xtensor_simd.hpp | 5 +- include/xtensor/utils/xutils.hpp | 33 +- include/xtensor/views/xview.hpp | 398 ++++++++++++---------- 15 files changed, 348 insertions(+), 290 deletions(-) diff --git a/include/xtensor/containers/xfixed.hpp b/include/xtensor/containers/xfixed.hpp index 1d5686ffe..61d5da06a 100644 --- a/include/xtensor/containers/xfixed.hpp +++ b/include/xtensor/containers/xfixed.hpp @@ -325,8 +325,8 @@ namespace xt explicit xfixed_container(const inner_shape_type& shape, layout_type l = L); explicit xfixed_container(const inner_shape_type& shape, value_type v, layout_type l = L); - template > requires (IX::value != 0) - xfixed_container(nested_initializer_list_t t); + template > + requires(IX::value != 0) xfixed_container(nested_initializer_list_t t); ~xfixed_container() = default; @@ -638,8 +638,10 @@ namespace xt * Note: for clang < 3.8 this is an initializer_list and the size is not checked at compile-or runtime. */ template - template requires (IX::value != 0) - inline xfixed_container::xfixed_container(nested_initializer_list_t t) + template + requires(IX::value != 0) inline xfixed_container::xfixed_container( + nested_initializer_list_t t + ) { XTENSOR_ASSERT_MSG( detail::check_initializer_list_shape::run(t, this->shape()) == true, diff --git a/include/xtensor/containers/xscalar.hpp b/include/xtensor/containers/xscalar.hpp index 724efa0c9..e97db8e64 100644 --- a/include/xtensor/containers/xscalar.hpp +++ b/include/xtensor/containers/xscalar.hpp @@ -316,10 +316,10 @@ namespace xt template using is_xscalar = detail::is_xscalar_impl; - - template + + template concept is_xscalar_concept = is_xscalar>::value; - + namespace detail { template diff --git a/include/xtensor/containers/xstorage.hpp b/include/xtensor/containers/xstorage.hpp index f756cd3fb..ae0d26673 100644 --- a/include/xtensor/containers/xstorage.hpp +++ b/include/xtensor/containers/xstorage.hpp @@ -670,16 +670,16 @@ namespace xt template svector(IT begin, IT end, const allocator_type& alloc = allocator_type()); - template requires (N != N2) - explicit svector(const svector& rhs); + template + requires(N != N2) explicit svector(const svector& rhs); svector& operator=(const svector& rhs); svector& operator=(svector&& rhs) noexcept(std::is_nothrow_move_assignable::value); svector& operator=(const std::vector& rhs); svector& operator=(std::initializer_list il); - template requires (N != N2) - svector& operator=(const svector& rhs); + template + requires(N != N2) svector& operator=(const svector& rhs); svector(const svector& other); svector(svector&& other) noexcept(std::is_nothrow_move_constructible::value); @@ -809,8 +809,8 @@ namespace xt } template - template requires (N != N2) - inline svector::svector(const svector& rhs) + template + requires(N != N2) inline svector::svector(const svector& rhs) : m_allocator(rhs.get_allocator()) { assign(rhs.begin(), rhs.end()); @@ -868,8 +868,10 @@ namespace xt } template - template requires (N != N2) - inline svector& svector::operator=(const svector& rhs) + template + requires(N != N2) inline svector& svector::operator=( + const svector& rhs + ) { m_allocator = std::allocator_traits::select_on_container_copy_construction( rhs.get_allocator() diff --git a/include/xtensor/core/xexpression.hpp b/include/xtensor/core/xexpression.hpp index 00b2c79b3..1f8c98194 100644 --- a/include/xtensor/core/xexpression.hpp +++ b/include/xtensor/core/xexpression.hpp @@ -178,7 +178,7 @@ namespace xt template using is_xexpression = is_crtp_base_of; - + template concept xexpression_concept = is_xexpression::value; diff --git a/include/xtensor/core/xshape.hpp b/include/xtensor/core/xshape.hpp index e5f97de04..28fbe43cc 100644 --- a/include/xtensor/core/xshape.hpp +++ b/include/xtensor/core/xshape.hpp @@ -508,7 +508,8 @@ namespace xt }; } - template concept fixed_shape_container_concept = detail::is_fixed::shape_type>::value; + template + concept fixed_shape_container_concept = detail::is_fixed::shape_type>::value; template struct promote_shape diff --git a/include/xtensor/generators/xgenerator.hpp b/include/xtensor/generators/xgenerator.hpp index b36971507..360901a64 100644 --- a/include/xtensor/generators/xgenerator.hpp +++ b/include/xtensor/generators/xgenerator.hpp @@ -59,8 +59,9 @@ namespace xt template class xgenerator; - - template concept xgenerator_concept = is_specialization_of>::value; + + template + concept xgenerator_concept = is_specialization_of>::value; template struct xiterable_inner_types> @@ -82,8 +83,8 @@ namespace xt * overlapping_memory_checker_traits * *************************************/ - template requires without_memory_address_concept - struct overlapping_memory_checker_traits + template + requires without_memory_address_concept struct overlapping_memory_checker_traits { static bool check_overlap(const E&, const memory_range&) { @@ -165,8 +166,8 @@ namespace xt template const_stepper stepper_end(const O& shape, layout_type) const noexcept; - template requires has_assign_to_v - void assign_to(xexpression& e) const noexcept; + template + requires has_assign_to_v void assign_to(xexpression& e) const noexcept; const functor_type& functor() const noexcept; @@ -371,8 +372,8 @@ namespace xt } template - template requires has_assign_to_v - inline void xgenerator::assign_to(xexpression& e) const noexcept + template + inline requires has_assign_to_v void xgenerator::assign_to(xexpression& e) const noexcept { e.derived_cast().resize(m_shape); m_f.assign_to(e); diff --git a/include/xtensor/generators/xrandom.hpp b/include/xtensor/generators/xrandom.hpp index 1f488e5ae..5e365f667 100644 --- a/include/xtensor/generators/xrandom.hpp +++ b/include/xtensor/generators/xrandom.hpp @@ -27,9 +27,9 @@ #include "../core/xtensor_config.hpp" #include "../generators/xbuilder.hpp" #include "../generators/xgenerator.hpp" +#include "../misc/xtl_concepts.hpp" #include "../views/xindex_view.hpp" #include "../views/xview.hpp" -#include "../misc/xtl_concepts.hpp" namespace xt { @@ -177,10 +177,10 @@ namespace xt void shuffle(xexpression& e, E& engine = random::get_default_random_engine()); template - xtensor permutation(T e, E& engine = random::get_default_random_engine()); + xtensor permutation(T e, E& engine = random::get_default_random_engine()); template - std::decay_t permutation(T&& e, E& engine = random::get_default_random_engine()); + std::decay_t permutation(T&& e, E& engine = random::get_default_random_engine()); template xtensor choice( @@ -835,7 +835,7 @@ namespace xt * @return randomly permuted copy of container or arange. */ template - xtensor permutation(T e, E& engine) + xtensor permutation(T e, E& engine) { xt::xtensor res = xt::arange(e); shuffle(res, engine); @@ -844,7 +844,7 @@ namespace xt /// @cond DOXYGEN_INCLUDE_SFINAE template - std::decay_t permutation(T&& e, E& engine) + std::decay_t permutation(T&& e, E& engine) { using copy_type = std::decay_t; copy_type res = e; diff --git a/include/xtensor/misc/xfft.hpp b/include/xtensor/misc/xfft.hpp index ad77708f7..954b55a9b 100644 --- a/include/xtensor/misc/xfft.hpp +++ b/include/xtensor/misc/xfft.hpp @@ -5,7 +5,6 @@ #include -#include "./xtl_concepts.hpp" #include "../containers/xarray.hpp" #include "../core/xmath.hpp" #include "../core/xnoalias.hpp" @@ -13,6 +12,7 @@ #include "../misc/xcomplex.hpp" #include "../views/xaxis_slice_iterator.hpp" #include "../views/xview.hpp" +#include "./xtl_concepts.hpp" namespace xt { @@ -118,65 +118,65 @@ namespace xt } } // namespace detail - /** + /** * @brief 1D FFT of an Nd array along a specified axis * @param e an Nd expression to be transformed to the fourier domain * @param axis the axis along which to perform the 1D FFT * @return a transformed xarray of the specified precision */ - template + template inline auto fft(E&& e, std::ptrdiff_t axis = -1) { - using value_type = typename std::decay::type::value_type; - if constexpr (xtl::is_complex::type::value_type>::value) - { - using precision = typename value_type::value_type; - const auto saxis = xt::normalize_axis(e.dimension(), axis); - const size_t N = e.shape(saxis); - const bool powerOfTwo = !(N == 0) && !(N & (N - 1)); - xt::xarray> out = xt::eval(e); - auto begin = xt::axis_slice_begin(out, saxis); - auto end = xt::axis_slice_end(out, saxis); - for (auto iter = begin; iter != end; iter++) + using value_type = typename std::decay::type::value_type; + if constexpr (xtl::is_complex::type::value_type>::value) { - if (powerOfTwo) - { - xt::noalias(*iter) = detail::radix2(*iter); - } - else + using precision = typename value_type::value_type; + const auto saxis = xt::normalize_axis(e.dimension(), axis); + const size_t N = e.shape(saxis); + const bool powerOfTwo = !(N == 0) && !(N & (N - 1)); + xt::xarray> out = xt::eval(e); + auto begin = xt::axis_slice_begin(out, saxis); + auto end = xt::axis_slice_end(out, saxis); + for (auto iter = begin; iter != end; iter++) { - xt::noalias(*iter) = detail::transform_bluestein(*iter); + if (powerOfTwo) + { + xt::noalias(*iter) = detail::radix2(*iter); + } + else + { + xt::noalias(*iter) = detail::transform_bluestein(*iter); + } } + return out; } - return out; - } - else - { - return fft(xt::cast>(e), axis); - } - } + else + { + return fft(xt::cast>(e), axis); + } + } template inline auto ifft(E&& e, std::ptrdiff_t axis = -1) { - if constexpr (xtl::is_complex::type::value_type>::value) - { - // check the length of the data on that axis - const std::size_t n = e.shape(axis); - if (n == 0) + if constexpr (xtl::is_complex::type::value_type>::value) + { + // check the length of the data on that axis + const std::size_t n = e.shape(axis); + if (n == 0) + { + XTENSOR_THROW(std::runtime_error, "Cannot take the iFFT along an empty dimention"); + } + auto complex_args = xt::conj(e); + auto fft_res = xt::fft::fft(complex_args, axis); + fft_res = xt::conj(fft_res); + return fft_res; + } + else { - XTENSOR_THROW(std::runtime_error, "Cannot take the iFFT along an empty dimention"); + using value_type = typename std::decay::type::value_type; + return ifft(xt::cast>(e), axis); } - auto complex_args = xt::conj(e); - auto fft_res = xt::fft::fft(complex_args, axis); - fft_res = xt::conj(fft_res); - return fft_res; - } - else - { - using value_type = typename std::decay::type::value_type; - return ifft(xt::cast>(e), axis); - } } /* diff --git a/include/xtensor/misc/xmanipulation.hpp b/include/xtensor/misc/xmanipulation.hpp index 9be2a9649..f0af92892 100644 --- a/include/xtensor/misc/xmanipulation.hpp +++ b/include/xtensor/misc/xmanipulation.hpp @@ -214,18 +214,18 @@ namespace xt template inline void compute_transposed_strides(E&& e, const S& shape, X& strides) { - if constexpr (has_data_interface>::value) - { - std::copy(e.strides().crbegin(), e.strides().crend(), strides.begin()); - } - else - { - // In the case where E does not have a data interface, the transposition - // makes use of a flat storage adaptor that has layout XTENSOR_DEFAULT_TRAVERSAL - // which should be the one inverted. - layout_type l = transpose_layout(XTENSOR_DEFAULT_TRAVERSAL); - compute_strides(shape, l, strides); - } + if constexpr (has_data_interface>::value) + { + std::copy(e.strides().crbegin(), e.strides().crend(), strides.begin()); + } + else + { + // In the case where E does not have a data interface, the transposition + // makes use of a flat storage adaptor that has layout XTENSOR_DEFAULT_TRAVERSAL + // which should be the one inverted. + layout_type l = transpose_layout(XTENSOR_DEFAULT_TRAVERSAL); + compute_strides(shape, l, strides); + } } } diff --git a/include/xtensor/misc/xset_operation.hpp b/include/xtensor/misc/xset_operation.hpp index c5a434c21..04339cf6f 100644 --- a/include/xtensor/misc/xset_operation.hpp +++ b/include/xtensor/misc/xset_operation.hpp @@ -87,8 +87,8 @@ namespace xt * @param test_elements an array * @return a boolean array */ - template requires has_iterator_interface_concept - inline auto isin(E&& element, F&& test_elements) noexcept + template + inline requires has_iterator_interface_concept auto isin(E&& element, F&& test_elements) noexcept { auto lambda = detail::lambda_isin::value>::make(std::forward(test_elements )); @@ -143,8 +143,8 @@ namespace xt * @param test_elements an array * @return a boolean array */ - template requires has_iterator_interface_concept - inline auto in1d(E&& element, F&& test_elements) noexcept + template + inline requires has_iterator_interface_concept auto in1d(E&& element, F&& test_elements) noexcept { XTENSOR_ASSERT(element.dimension() == 1ul); XTENSOR_ASSERT(test_elements.dimension() == 1ul); diff --git a/include/xtensor/misc/xsort.hpp b/include/xtensor/misc/xsort.hpp index d76a38b71..aa9ea4cfa 100644 --- a/include/xtensor/misc/xsort.hpp +++ b/include/xtensor/misc/xsort.hpp @@ -561,10 +561,7 @@ namespace xt * * @return partially sorted xcontainer */ - template < - class E, - xtl::non_integral_concept C, - class R = detail::flatten_sort_result_type_t> + template > inline R partition(const xexpression& e, C kth_container, placeholders::xtuph /*ax*/) { const auto& de = e.derived_cast(); diff --git a/include/xtensor/misc/xtl_concepts.hpp b/include/xtensor/misc/xtl_concepts.hpp index c56b6f09f..163139812 100644 --- a/include/xtensor/misc/xtl_concepts.hpp +++ b/include/xtensor/misc/xtl_concepts.hpp @@ -10,14 +10,17 @@ #ifndef XTENSOR_CONCEPTS_HPP #define XTENSOR_CONCEPTS_HPP -#include #include +#include namespace xtl { - template concept integral_concept = xtl::is_integral::value; - template concept non_integral_concept = !xtl::is_integral::value; - template concept complex_concept = xtl::is_complex::type::value_type>::value; + template + concept integral_concept = xtl::is_integral::value; + template + concept non_integral_concept = !xtl::is_integral::value; + template + concept complex_concept = xtl::is_complex::type::value_type>::value; } -#endif // XTENSOR_CONCEPTS_HPP +#endif // XTENSOR_CONCEPTS_HPP diff --git a/include/xtensor/utils/xtensor_simd.hpp b/include/xtensor/utils/xtensor_simd.hpp index 12f3de497..59816114b 100644 --- a/include/xtensor/utils/xtensor_simd.hpp +++ b/include/xtensor/utils/xtensor_simd.hpp @@ -268,8 +268,9 @@ namespace xt struct has_simd_interface : detail::has_simd_interface_impl { }; - - template concept has_simd_interface_concept = has_simd_interface::value; + + template + concept has_simd_interface_concept = has_simd_interface::value; template struct has_simd_type : std::integral_constant>::value> diff --git a/include/xtensor/utils/xutils.hpp b/include/xtensor/utils/xutils.hpp index a2475a7dc..4ecab7a41 100644 --- a/include/xtensor/utils/xutils.hpp +++ b/include/xtensor/utils/xutils.hpp @@ -585,9 +585,10 @@ namespace xt struct has_data_interface().data())>> : std::true_type { }; - - template concept has_data_interface_concept = has_data_interface::value; - + + template + concept has_data_interface_concept = has_data_interface::value; + template struct has_strides : std::false_type { @@ -607,7 +608,7 @@ namespace xt struct has_iterator_interface().begin())>> : std::true_type { }; - + template concept has_iterator_interface_concept = has_iterator_interface::value; @@ -628,10 +629,13 @@ namespace xt : std::true_type { }; - - template concept iterator_concept = is_iterator::value; - template concept input_iterator_concept = std::is_convertible::iterator_category, std::input_iterator_tag>::value; - + + template + concept iterator_concept = is_iterator::value; + template + concept input_iterator_concept = std:: + is_convertible::iterator_category, std::input_iterator_tag>::value; + /******************************************** * xtrivial_default_construct implemenation * ********************************************/ @@ -800,8 +804,9 @@ namespace xt : std::true_type { }; - - template constexpr bool has_assign_to_v = has_assign_to ::value ; + + template + constexpr bool has_assign_to_v = has_assign_to::value; /************************************* * overlapping_memory_checker_traits * @@ -816,9 +821,11 @@ namespace xt struct has_memory_address().begin()))>> : std::true_type { }; - - template concept with_memory_address_concept = has_memory_address< std::decay_t >::value; - template concept without_memory_address_concept = !has_memory_address< std::decay_t >::value; + + template + concept with_memory_address_concept = has_memory_address>::value; + template + concept without_memory_address_concept = !has_memory_address>::value; struct memory_range { diff --git a/include/xtensor/views/xview.hpp b/include/xtensor/views/xview.hpp index 0c4868afc..5d22f7499 100644 --- a/include/xtensor/views/xview.hpp +++ b/include/xtensor/views/xview.hpp @@ -289,8 +289,10 @@ namespace xt }; } - template concept contiguous_view_concept = detail::is_contiguous_view::value; - template concept strided_view_concept = detail::is_strided_view, S...>::value; + template + concept contiguous_view_concept = detail::is_contiguous_view::value; + template + concept strided_view_concept = detail::is_strided_view, S...>::value; template struct xcontainer_inner_types> @@ -496,72 +498,85 @@ namespace xt template bool has_linear_assign(const ST& strides) const; - template - stepper stepper_begin(const ST& shape); - template - stepper stepper_end(const ST& shape, layout_type l); - - template - const_stepper stepper_begin(const ST& shape) const; - template - const_stepper stepper_end(const ST& shape, layout_type l) const; - - template requires has_data_interface_concept - storage_type& storage(); + template + stepper stepper_begin(const ST& shape); + template + stepper stepper_end(const ST& shape, layout_type l); - template requires has_data_interface_concept - const storage_type& storage() const; + template + const_stepper stepper_begin(const ST& shape) const; + template + const_stepper stepper_end(const ST& shape, layout_type l) const; + + template + requires has_data_interface_concept storage_type& storage(); - template requires has_data_interface_concept and strided_view_concept - linear_iterator linear_begin(); + template + const requires has_data_interface_concept storage_type& storage() const; - template requires has_data_interface_concept and strided_view_concept - linear_iterator linear_end(); + template + requires has_data_interface_conceptand strided_view_concept linear_iterator linear_begin(); - template requires has_data_interface_concept and strided_view_concept - const_linear_iterator linear_begin() const; + template + requires has_data_interface_conceptand strided_view_concept linear_iterator linear_end(); - template requires has_data_interface_concept and strided_view_concept - const_linear_iterator linear_end() const; + template + requires has_data_interface_conceptand strided_view_concept + const_linear_iterator linear_begin() const; - template requires has_data_interface_concept and strided_view_concept - const_linear_iterator linear_cbegin() const; + template + requires has_data_interface_conceptand strided_view_concept + const_linear_iterator linear_end() const; - template requires has_data_interface_concept and strided_view_concept - const_linear_iterator linear_cend() const; + template + requires has_data_interface_conceptand strided_view_concept + const_linear_iterator linear_cbegin() const; - template requires has_data_interface_concept and strided_view_concept - reverse_linear_iterator linear_rbegin(); + template + requires has_data_interface_conceptand strided_view_concept + const_linear_iterator linear_cend() const; - template requires has_data_interface_concept and strided_view_concept - reverse_linear_iterator linear_rend(); + template + requires has_data_interface_conceptand strided_view_concept + reverse_linear_iterator linear_rbegin(); - template requires has_data_interface_concept and strided_view_concept - const_reverse_linear_iterator linear_rbegin() const; + template + requires has_data_interface_conceptand strided_view_concept + reverse_linear_iterator linear_rend(); - template requires has_data_interface_concept and strided_view_concept - const_reverse_linear_iterator linear_rend() const; + template + requires has_data_interface_conceptand strided_view_concept + const_reverse_linear_iterator linear_rbegin() const; - template requires has_data_interface_concept and strided_view_concept - const_reverse_linear_iterator linear_crbegin() const; + template + requires has_data_interface_conceptand strided_view_concept + const_reverse_linear_iterator linear_rend() const; - template requires has_data_interface_concept and strided_view_concept - const_reverse_linear_iterator linear_crend() const; + template + requires has_data_interface_conceptand strided_view_concept + const_reverse_linear_iterator linear_crbegin() const; - template requires has_data_interface_concept and strided_view_concept - const inner_strides_type& strides() const; + template + requires has_data_interface_conceptand strided_view_concept + const_reverse_linear_iterator linear_crend() const; - template requires has_data_interface_concept and strided_view_concept - const inner_strides_type& backstrides() const; + template + requires has_data_interface_conceptand const strided_view_concept inner_strides_type& + strides() const; - template requires has_data_interface_concept and strided_view_concept - const_pointer data() const; + template + requires has_data_interface_conceptand const strided_view_concept inner_strides_type& + backstrides() const; - template requires has_data_interface_concept and strided_view_concept - pointer data(); + template + requires has_data_interface_conceptand strided_view_concept const_pointer data() const; - template requires has_data_interface_concept and strided_view_concept - std::size_t data_offset() const noexcept; + template + requires has_data_interface_conceptand strided_view_concept pointer data(); + + template + requires has_data_interface_conceptand strided_view_concept std::size_t + data_offset() const noexcept; template inline It data_xbegin_impl(It begin) const noexcept; @@ -593,10 +608,9 @@ namespace xt xtl::xclosure_pointer operator&() const&; xtl::xclosure_pointer operator&() &&; - template < - class E, - class T = xexpression_type> requires has_data_interface_concept and contiguous_view_concept - void assign_to(xexpression& e, bool force_resize) const; + template + requires has_data_interface_conceptand contiguous_view_concept void + assign_to(xexpression& e, bool force_resize) const; template using rebind_t = xview; @@ -611,33 +625,38 @@ namespace xt template using simd_return_type = xt_simd::simd_return_type; - template requires has_simd_interface_concept and strided_view_concept - void store_simd(size_type i, const simd& e); + template + requires has_simd_interface_conceptand strided_view_concept void + store_simd(size_type i, const simd& e); template < class align, class requested_type = value_type, std::size_t N = xt_simd::simd_traits::size, - class T = xexpression_type> requires has_simd_interface_concept and strided_view_concept - simd_return_type load_simd(size_type i) const; + class T = xexpression_type> + requires has_simd_interface_conceptand strided_view_concept + simd_return_type load_simd(size_type i) const; - template requires has_simd_interface_concept and strided_view_concept - reference data_element(size_type i); + template + requires has_simd_interface_conceptand strided_view_concept + reference data_element(size_type i); - template requires has_simd_interface_concept and strided_view_concept - const_reference data_element(size_type i) const; + template + requires has_simd_interface_conceptand strided_view_concept + const_reference data_element(size_type i) const; - template requires has_simd_interface_concept and strided_view_concept - reference flat(size_type i); + template + requires has_simd_interface_conceptand strided_view_concept reference flat(size_type i); - template requires has_simd_interface_concept and strided_view_concept - const_reference flat(size_type i) const; + template + requires has_simd_interface_conceptand strided_view_concept + const_reference flat(size_type i) const; private: // VS 2015 workaround (yes, really) - //template - //struct lesser_condition + // template + // struct lesser_condition //{ // static constexpr bool value = (I + newaxis_count_before(I + 1) < sizeof...(S)); //}; @@ -684,11 +703,11 @@ namespace xt template ::size_type... I, class... Args> const_reference access_impl(std::index_sequence, Args... args) const; - template ::size_type I, class... Args> requires (I + newaxis_count_before(I + 1) < sizeof...(S)) - size_type index(Args... args) const; + template ::size_type I, class... Args> + requires(I + newaxis_count_before(I + 1) < sizeof...(S)) size_type index(Args... args) const; - template ::size_type I, class... Args> requires (!(I + newaxis_count_before(I + 1) < sizeof...(S))) - size_type index(Args... args) const; + template ::size_type I, class... Args> + requires(!(I + newaxis_count_before(I + 1) < sizeof...(S))) size_type index(Args... args) const; template ::size_type, class T> size_type sliced_access(const xslice& slice) const; @@ -1127,100 +1146,111 @@ namespace xt * on a realized container. */ template - template requires has_data_interface_concept - inline auto xview::storage() -> storage_type& + template + inline requires has_data_interface_concept auto xview::storage() -> storage_type& { return m_e.storage(); } template - template requires has_data_interface_concept - inline auto xview::storage() const - -> const storage_type& + template + inline requires has_data_interface_concept auto xview::storage() const -> const storage_type& { return m_e.storage(); } template - template requires (has_data_interface_concept and strided_view_concept) - auto xview::linear_begin() -> linear_iterator + template + requires(has_data_interface_conceptand strided_view_concept) auto xview::linear_begin() + -> linear_iterator { return m_e.storage().begin() + data_offset(); } template - template requires has_data_interface_concept and strided_view_concept - auto xview::linear_end() -> linear_iterator + template + requires has_data_interface_conceptand strided_view_concept auto + xview::linear_end() -> linear_iterator { return m_e.storage().begin() + data_offset() + this->size(); } template - template requires has_data_interface_concept and strided_view_concept - auto xview::linear_begin() const -> const_linear_iterator + template + requires has_data_interface_conceptand strided_view_concept auto + xview::linear_begin() const -> const_linear_iterator { return linear_cbegin(); } template - template requires has_data_interface_concept and strided_view_concept - auto xview::linear_end() const -> const_linear_iterator + template + requires has_data_interface_conceptand strided_view_concept auto + xview::linear_end() const -> const_linear_iterator { return linear_cend(); } template - template requires has_data_interface_concept and strided_view_concept - auto xview::linear_cbegin() const -> const_linear_iterator + template + requires has_data_interface_conceptand strided_view_concept auto + xview::linear_cbegin() const -> const_linear_iterator { return m_e.storage().cbegin() + data_offset(); } template - template requires has_data_interface_concept and strided_view_concept - auto xview::linear_cend() const -> const_linear_iterator + template + requires has_data_interface_conceptand strided_view_concept auto + xview::linear_cend() const -> const_linear_iterator { return m_e.storage().cbegin() + data_offset() + this->size(); } template - template requires has_data_interface_concept and strided_view_concept - auto xview::linear_rbegin() -> reverse_linear_iterator + template + requires has_data_interface_conceptand strided_view_concept auto + xview::linear_rbegin() -> reverse_linear_iterator { return reverse_linear_iterator(linear_end()); } template - template requires has_data_interface_concept and strided_view_concept - auto xview::linear_rend() -> reverse_linear_iterator + template + requires has_data_interface_conceptand strided_view_concept auto + xview::linear_rend() -> reverse_linear_iterator { return reverse_linear_iterator(linear_begin()); } template - template requires has_data_interface_concept and strided_view_concept - auto xview::linear_rbegin() const -> const_reverse_linear_iterator + template + requires has_data_interface_conceptand strided_view_concept auto + xview::linear_rbegin() const -> const_reverse_linear_iterator { return linear_crbegin(); } template - template requires has_data_interface_concept and strided_view_concept - auto xview::linear_rend() const -> const_reverse_linear_iterator + template + requires has_data_interface_conceptand strided_view_concept auto + xview::linear_rend() const -> const_reverse_linear_iterator { return linear_crend(); } template - template requires has_data_interface_concept and strided_view_concept - auto xview::linear_crbegin() const -> const_reverse_linear_iterator + template + requires has_data_interface_conceptand strided_view_concept auto + xview::linear_crbegin() const -> const_reverse_linear_iterator { return const_reverse_linear_iterator(linear_end()); } template - template requires has_data_interface_concept and strided_view_concept - auto xview::linear_crend() const -> const_reverse_linear_iterator + template + requires has_data_interface_conceptand strided_view_concept auto + xview::linear_crend() const -> const_reverse_linear_iterator { return const_reverse_linear_iterator(linear_begin()); } @@ -1229,8 +1259,9 @@ namespace xt * Return the strides for the underlying container of the view. */ template - template requires has_data_interface_concept and strided_view_concept - inline auto xview::strides() const -> const inner_strides_type& + template + requires has_data_interface_conceptand inline strided_view_concept auto + xview::strides() const -> const inner_strides_type& { if (!m_strides_computed) { @@ -1241,8 +1272,9 @@ namespace xt } template - template requires has_data_interface_concept and strided_view_concept - inline auto xview::backstrides() const -> const inner_strides_type& + template + requires has_data_interface_conceptand inline strided_view_concept auto + xview::backstrides() const -> const inner_strides_type& { if (!m_strides_computed) { @@ -1256,15 +1288,17 @@ namespace xt * Return the pointer to the underlying buffer. */ template - template requires has_data_interface_concept and strided_view_concept - inline auto xview::data() const -> const_pointer + template + requires has_data_interface_conceptand inline strided_view_concept auto + xview::data() const -> const_pointer { return m_e.data(); } template - template requires has_data_interface_concept and strided_view_concept - inline auto xview::data() -> pointer + template + requires has_data_interface_conceptand inline strided_view_concept auto + xview::data() -> pointer { return m_e.data(); } @@ -1294,8 +1328,9 @@ namespace xt * Return the offset to the first element of the view in the underlying container. */ template - template requires has_data_interface_concept and strided_view_concept - inline std::size_t xview::data_offset() const noexcept + template + requires has_data_interface_conceptand inline strided_view_concept std::size_t + xview::data_offset() const noexcept { if (!m_strides_computed) { @@ -1410,8 +1445,9 @@ namespace xt // Assign to operator enabled for contigous views template - template requires has_data_interface_concept and contiguous_view_concept - void xview::assign_to(xexpression& e, bool force_resize) const + template + requires has_data_interface_conceptand contiguous_view_concept void + xview::assign_to(xexpression& e, bool force_resize) const { auto& de = e.derived_cast(); de.resize(shape(), force_resize); @@ -1433,44 +1469,50 @@ namespace xt } template - template requires has_simd_interface_concept and strided_view_concept - inline auto xview::store_simd(size_type i, const simd& e) -> void + template + requires has_simd_interface_conceptand inline strided_view_concept auto + xview::store_simd(size_type i, const simd& e) -> void { return m_e.template store_simd(data_offset() + i, e); } template - template requires has_simd_interface_concept and strided_view_concept - inline auto xview::load_simd(size_type i) const -> simd_return_type + template + requires has_simd_interface_conceptand inline strided_view_concept auto + xview::load_simd(size_type i) const -> simd_return_type { return m_e.template load_simd(data_offset() + i); } template - template requires has_simd_interface_concept and strided_view_concept - inline auto xview::data_element(size_type i) -> reference + template + requires has_simd_interface_conceptand inline strided_view_concept auto + xview::data_element(size_type i) -> reference { return m_e.data_element(data_offset() + i); } template - template requires has_simd_interface_concept and strided_view_concept - inline auto xview::data_element(size_type i) const -> const_reference + template + requires has_simd_interface_conceptand inline strided_view_concept auto + xview::data_element(size_type i) const -> const_reference { return m_e.data_element(data_offset() + i); } template - template requires has_simd_interface_concept and strided_view_concept - inline auto xview::flat(size_type i) -> reference + template + requires has_simd_interface_conceptand inline strided_view_concept auto + xview::flat(size_type i) -> reference { XTENSOR_ASSERT(is_contiguous()); return m_e.flat(data_offset() + i); } template - template requires has_simd_interface_concept and strided_view_concept - inline auto xview::flat(size_type i) const -> const_reference + template + requires has_simd_interface_conceptand inline strided_view_concept auto + xview::flat(size_type i) const -> const_reference { XTENSOR_ASSERT(is_contiguous()); return m_e.flat(data_offset() + i); @@ -1593,8 +1635,9 @@ namespace xt } template - template ::size_type I, class... Args> requires (I + newaxis_count_before(I + 1) < sizeof...(S)) - inline auto xview::index(Args... args) const -> size_type + template ::size_type I, class... Args> + requires(I + newaxis_count_before(I + 1) < sizeof...(S)) inline auto xview::index(Args... args + ) const -> size_type { return sliced_access(I) + newaxis_count_before(I + 1)>( std::get(I + 1)>(m_slices), @@ -1603,8 +1646,9 @@ namespace xt } template - template ::size_type I, class... Args> requires (!(I + newaxis_count_before(I + 1) < sizeof...(S))) - inline auto xview::index(Args... args) const -> size_type + template ::size_type I, class... Args> + requires(!(I + newaxis_count_before(I + 1) < sizeof...(S)) + ) inline auto xview::index(Args... args) const -> size_type { return argument() + newaxis_count()>(args...); } @@ -1884,66 +1928,66 @@ namespace xt * stepper api * ***************/ - template + template template inline auto xview::stepper_begin(const ST& shape) -> stepper { - const size_type offset = shape.size() - this->dimension(); - if constexpr (is_strided_view) - { - return stepper(this, data_xbegin(), offset); - } - else - { - return stepper(this, m_e.stepper_begin(m_e.shape()), offset); - } - } - - template + const size_type offset = shape.size() - this->dimension(); + if constexpr (is_strided_view) + { + return stepper(this, data_xbegin(), offset); + } + else + { + return stepper(this, m_e.stepper_begin(m_e.shape()), offset); + } + } + + template template inline auto xview::stepper_end(const ST& shape, layout_type l) -> stepper { - const size_type offset = shape.size() - this->dimension(); - if constexpr (is_strided_view) - { - return stepper(this, data_xend(l, offset), offset); - } - else - { - return stepper(this, m_e.stepper_end(m_e.shape(), l), offset, true, l); - } - } - - template + const size_type offset = shape.size() - this->dimension(); + if constexpr (is_strided_view) + { + return stepper(this, data_xend(l, offset), offset); + } + else + { + return stepper(this, m_e.stepper_end(m_e.shape(), l), offset, true, l); + } + } + + template template inline auto xview::stepper_begin(const ST& shape) const -> const_stepper { - const size_type offset = shape.size() - this->dimension(); - if constexpr (is_strided_view) - { - return const_stepper(this, data_xbegin(), offset); - } - else - { - const xexpression_type& e = m_e; - return const_stepper(this, e.stepper_begin(m_e.shape()), offset); - } - } - - template + const size_type offset = shape.size() - this->dimension(); + if constexpr (is_strided_view) + { + return const_stepper(this, data_xbegin(), offset); + } + else + { + const xexpression_type& e = m_e; + return const_stepper(this, e.stepper_begin(m_e.shape()), offset); + } + } + + template template inline auto xview::stepper_end(const ST& shape, layout_type l) const -> const_stepper { - const size_type offset = shape.size() - this->dimension(); - if constexpr (is_strided_view) - { - return const_stepper(this, data_xend(l, offset), offset); - } - else - { - const xexpression_type& e = m_e; - return const_stepper(this, e.stepper_end(m_e.shape(), l), offset, true, l); - } + const size_type offset = shape.size() - this->dimension(); + if constexpr (is_strided_view) + { + return const_stepper(this, data_xend(l, offset), offset); + } + else + { + const xexpression_type& e = m_e; + return const_stepper(this, e.stepper_end(m_e.shape(), l), offset, true, l); + } } /******************************** From f959b367bd17b86963daf1c7d3ce3e59782f4adb Mon Sep 17 00:00:00 2001 From: Alexandre Hoffmann Date: Wed, 9 Apr 2025 16:49:50 +0200 Subject: [PATCH 3/6] with precommit --- include/xtensor/containers/xfixed.hpp | 8 +- include/xtensor/containers/xstorage.hpp | 14 +- include/xtensor/generators/xgenerator.hpp | 9 +- include/xtensor/misc/xset_operation.hpp | 6 +- include/xtensor/views/xview.hpp | 213 ++++++++++++---------- 5 files changed, 134 insertions(+), 116 deletions(-) diff --git a/include/xtensor/containers/xfixed.hpp b/include/xtensor/containers/xfixed.hpp index 61d5da06a..aedac1ae6 100644 --- a/include/xtensor/containers/xfixed.hpp +++ b/include/xtensor/containers/xfixed.hpp @@ -326,7 +326,8 @@ namespace xt explicit xfixed_container(const inner_shape_type& shape, value_type v, layout_type l = L); template > - requires(IX::value != 0) xfixed_container(nested_initializer_list_t t); + requires(IX::value != 0) + xfixed_container(nested_initializer_list_t t); ~xfixed_container() = default; @@ -639,9 +640,8 @@ namespace xt */ template template - requires(IX::value != 0) inline xfixed_container::xfixed_container( - nested_initializer_list_t t - ) + requires(IX::value != 0) + inline xfixed_container::xfixed_container(nested_initializer_list_t t) { XTENSOR_ASSERT_MSG( detail::check_initializer_list_shape::run(t, this->shape()) == true, diff --git a/include/xtensor/containers/xstorage.hpp b/include/xtensor/containers/xstorage.hpp index ae0d26673..30fbc49c1 100644 --- a/include/xtensor/containers/xstorage.hpp +++ b/include/xtensor/containers/xstorage.hpp @@ -671,7 +671,8 @@ namespace xt svector(IT begin, IT end, const allocator_type& alloc = allocator_type()); template - requires(N != N2) explicit svector(const svector& rhs); + requires(N != N2) + explicit svector(const svector& rhs); svector& operator=(const svector& rhs); svector& operator=(svector&& rhs) noexcept(std::is_nothrow_move_assignable::value); @@ -679,7 +680,8 @@ namespace xt svector& operator=(std::initializer_list il); template - requires(N != N2) svector& operator=(const svector& rhs); + requires(N != N2) + svector& operator=(const svector& rhs); svector(const svector& other); svector(svector&& other) noexcept(std::is_nothrow_move_constructible::value); @@ -810,7 +812,8 @@ namespace xt template template - requires(N != N2) inline svector::svector(const svector& rhs) + requires(N != N2) + inline svector::svector(const svector& rhs) : m_allocator(rhs.get_allocator()) { assign(rhs.begin(), rhs.end()); @@ -869,9 +872,8 @@ namespace xt template template - requires(N != N2) inline svector& svector::operator=( - const svector& rhs - ) + requires(N != N2) + inline svector& svector::operator=(const svector& rhs) { m_allocator = std::allocator_traits::select_on_container_copy_construction( rhs.get_allocator() diff --git a/include/xtensor/generators/xgenerator.hpp b/include/xtensor/generators/xgenerator.hpp index 360901a64..aba7b46e2 100644 --- a/include/xtensor/generators/xgenerator.hpp +++ b/include/xtensor/generators/xgenerator.hpp @@ -84,7 +84,8 @@ namespace xt *************************************/ template - requires without_memory_address_concept struct overlapping_memory_checker_traits + requires without_memory_address_concept + struct overlapping_memory_checker_traits { static bool check_overlap(const E&, const memory_range&) { @@ -167,7 +168,8 @@ namespace xt const_stepper stepper_end(const O& shape, layout_type) const noexcept; template - requires has_assign_to_v void assign_to(xexpression& e) const noexcept; + requires has_assign_to_v + void assign_to(xexpression& e) const noexcept; const functor_type& functor() const noexcept; @@ -373,7 +375,8 @@ namespace xt template template - inline requires has_assign_to_v void xgenerator::assign_to(xexpression& e) const noexcept + requires has_assign_to_v + inline void xgenerator::assign_to(xexpression& e) const noexcept { e.derived_cast().resize(m_shape); m_f.assign_to(e); diff --git a/include/xtensor/misc/xset_operation.hpp b/include/xtensor/misc/xset_operation.hpp index 04339cf6f..eb87dcc53 100644 --- a/include/xtensor/misc/xset_operation.hpp +++ b/include/xtensor/misc/xset_operation.hpp @@ -88,7 +88,8 @@ namespace xt * @return a boolean array */ template - inline requires has_iterator_interface_concept auto isin(E&& element, F&& test_elements) noexcept + requires has_iterator_interface_concept + inline auto isin(E&& element, F&& test_elements) noexcept { auto lambda = detail::lambda_isin::value>::make(std::forward(test_elements )); @@ -144,7 +145,8 @@ namespace xt * @return a boolean array */ template - inline requires has_iterator_interface_concept auto in1d(E&& element, F&& test_elements) noexcept + requires has_iterator_interface_concept + inline auto in1d(E&& element, F&& test_elements) noexcept { XTENSOR_ASSERT(element.dimension() == 1ul); XTENSOR_ASSERT(test_elements.dimension() == 1ul); diff --git a/include/xtensor/views/xview.hpp b/include/xtensor/views/xview.hpp index 5d22f7499..c3103ecb9 100644 --- a/include/xtensor/views/xview.hpp +++ b/include/xtensor/views/xview.hpp @@ -509,74 +509,80 @@ namespace xt const_stepper stepper_end(const ST& shape, layout_type l) const; template - requires has_data_interface_concept storage_type& storage(); + requires has_data_interface_concept + storage_type& storage(); template - const requires has_data_interface_concept storage_type& storage() const; + requires has_data_interface_concept + const storage_type& storage() const; template - requires has_data_interface_conceptand strided_view_concept linear_iterator linear_begin(); + requires has_data_interface_concept and strided_view_concept + linear_iterator linear_begin(); template - requires has_data_interface_conceptand strided_view_concept linear_iterator linear_end(); + requires has_data_interface_concept and strided_view_concept + linear_iterator linear_end(); template - requires has_data_interface_conceptand strided_view_concept - const_linear_iterator linear_begin() const; + requires has_data_interface_concept and strided_view_concept + const_linear_iterator linear_begin() const; template - requires has_data_interface_conceptand strided_view_concept - const_linear_iterator linear_end() const; + requires has_data_interface_concept and strided_view_concept + const_linear_iterator linear_end() const; template - requires has_data_interface_conceptand strided_view_concept - const_linear_iterator linear_cbegin() const; + requires has_data_interface_concept and strided_view_concept + const_linear_iterator linear_cbegin() const; template - requires has_data_interface_conceptand strided_view_concept - const_linear_iterator linear_cend() const; + requires has_data_interface_concept and strided_view_concept + const_linear_iterator linear_cend() const; template - requires has_data_interface_conceptand strided_view_concept - reverse_linear_iterator linear_rbegin(); + requires has_data_interface_concept and strided_view_concept + reverse_linear_iterator linear_rbegin(); template - requires has_data_interface_conceptand strided_view_concept - reverse_linear_iterator linear_rend(); + requires has_data_interface_concept and strided_view_concept + reverse_linear_iterator linear_rend(); template - requires has_data_interface_conceptand strided_view_concept - const_reverse_linear_iterator linear_rbegin() const; + requires has_data_interface_concept and strided_view_concept + const_reverse_linear_iterator linear_rbegin() const; template - requires has_data_interface_conceptand strided_view_concept - const_reverse_linear_iterator linear_rend() const; + requires has_data_interface_concept and strided_view_concept + const_reverse_linear_iterator linear_rend() const; template - requires has_data_interface_conceptand strided_view_concept - const_reverse_linear_iterator linear_crbegin() const; + requires has_data_interface_concept and strided_view_concept + const_reverse_linear_iterator linear_crbegin() const; template - requires has_data_interface_conceptand strided_view_concept - const_reverse_linear_iterator linear_crend() const; + requires has_data_interface_concept and strided_view_concept + const_reverse_linear_iterator linear_crend() const; template - requires has_data_interface_conceptand const strided_view_concept inner_strides_type& - strides() const; + requires has_data_interface_concept and strided_view_concept + const inner_strides_type& strides() const; template - requires has_data_interface_conceptand const strided_view_concept inner_strides_type& - backstrides() const; + requires has_data_interface_concept and strided_view_concept + const inner_strides_type& backstrides() const; template - requires has_data_interface_conceptand strided_view_concept const_pointer data() const; + requires has_data_interface_concept and strided_view_concept + const_pointer data() const; template - requires has_data_interface_conceptand strided_view_concept pointer data(); + requires has_data_interface_concept and strided_view_concept + pointer data(); template - requires has_data_interface_conceptand strided_view_concept std::size_t - data_offset() const noexcept; + requires has_data_interface_concept and strided_view_concept + std::size_t data_offset() const noexcept; template inline It data_xbegin_impl(It begin) const noexcept; @@ -609,8 +615,8 @@ namespace xt xtl::xclosure_pointer operator&() &&; template - requires has_data_interface_conceptand contiguous_view_concept void - assign_to(xexpression& e, bool force_resize) const; + requires has_data_interface_concept and contiguous_view_concept + void assign_to(xexpression& e, bool force_resize) const; template using rebind_t = xview; @@ -626,31 +632,32 @@ namespace xt using simd_return_type = xt_simd::simd_return_type; template - requires has_simd_interface_conceptand strided_view_concept void - store_simd(size_type i, const simd& e); + requires has_simd_interface_concept and strided_view_concept + void store_simd(size_type i, const simd& e); template < class align, class requested_type = value_type, std::size_t N = xt_simd::simd_traits::size, class T = xexpression_type> - requires has_simd_interface_conceptand strided_view_concept - simd_return_type load_simd(size_type i) const; + requires has_simd_interface_concept and strided_view_concept + simd_return_type load_simd(size_type i) const; template - requires has_simd_interface_conceptand strided_view_concept - reference data_element(size_type i); + requires has_simd_interface_concept and strided_view_concept + reference data_element(size_type i); template - requires has_simd_interface_conceptand strided_view_concept - const_reference data_element(size_type i) const; + requires has_simd_interface_concept and strided_view_concept + const_reference data_element(size_type i) const; template - requires has_simd_interface_conceptand strided_view_concept reference flat(size_type i); + requires has_simd_interface_concept and strided_view_concept + reference flat(size_type i); template - requires has_simd_interface_conceptand strided_view_concept - const_reference flat(size_type i) const; + requires has_simd_interface_concept and strided_view_concept + const_reference flat(size_type i) const; private: @@ -704,10 +711,12 @@ namespace xt const_reference access_impl(std::index_sequence, Args... args) const; template ::size_type I, class... Args> - requires(I + newaxis_count_before(I + 1) < sizeof...(S)) size_type index(Args... args) const; + requires(I + newaxis_count_before(I + 1) < sizeof...(S)) + size_type index(Args... args) const; template ::size_type I, class... Args> - requires(!(I + newaxis_count_before(I + 1) < sizeof...(S))) size_type index(Args... args) const; + requires(!(I + newaxis_count_before(I + 1) < sizeof...(S))) + size_type index(Args... args) const; template ::size_type, class T> size_type sliced_access(const xslice& slice) const; @@ -1147,110 +1156,112 @@ namespace xt */ template template - inline requires has_data_interface_concept auto xview::storage() -> storage_type& + requires has_data_interface_concept + inline auto xview::storage() -> storage_type& { return m_e.storage(); } template template - inline requires has_data_interface_concept auto xview::storage() const -> const storage_type& + requires has_data_interface_concept + inline auto xview::storage() const -> const storage_type& { return m_e.storage(); } template template - requires(has_data_interface_conceptand strided_view_concept) auto xview::linear_begin() - -> linear_iterator + requires(has_data_interface_concept and strided_view_concept) + auto xview::linear_begin() -> linear_iterator { return m_e.storage().begin() + data_offset(); } template template - requires has_data_interface_conceptand strided_view_concept auto - xview::linear_end() -> linear_iterator + requires has_data_interface_concept and strided_view_concept + auto xview::linear_end() -> linear_iterator { return m_e.storage().begin() + data_offset() + this->size(); } template template - requires has_data_interface_conceptand strided_view_concept auto - xview::linear_begin() const -> const_linear_iterator + requires has_data_interface_concept and strided_view_concept + auto xview::linear_begin() const -> const_linear_iterator { return linear_cbegin(); } template template - requires has_data_interface_conceptand strided_view_concept auto - xview::linear_end() const -> const_linear_iterator + requires has_data_interface_concept and strided_view_concept + auto xview::linear_end() const -> const_linear_iterator { return linear_cend(); } template template - requires has_data_interface_conceptand strided_view_concept auto - xview::linear_cbegin() const -> const_linear_iterator + requires has_data_interface_concept and strided_view_concept + auto xview::linear_cbegin() const -> const_linear_iterator { return m_e.storage().cbegin() + data_offset(); } template template - requires has_data_interface_conceptand strided_view_concept auto - xview::linear_cend() const -> const_linear_iterator + requires has_data_interface_concept and strided_view_concept + auto xview::linear_cend() const -> const_linear_iterator { return m_e.storage().cbegin() + data_offset() + this->size(); } template template - requires has_data_interface_conceptand strided_view_concept auto - xview::linear_rbegin() -> reverse_linear_iterator + requires has_data_interface_concept and strided_view_concept + auto xview::linear_rbegin() -> reverse_linear_iterator { return reverse_linear_iterator(linear_end()); } template template - requires has_data_interface_conceptand strided_view_concept auto - xview::linear_rend() -> reverse_linear_iterator + requires has_data_interface_concept and strided_view_concept + auto xview::linear_rend() -> reverse_linear_iterator { return reverse_linear_iterator(linear_begin()); } template template - requires has_data_interface_conceptand strided_view_concept auto - xview::linear_rbegin() const -> const_reverse_linear_iterator + requires has_data_interface_concept and strided_view_concept + auto xview::linear_rbegin() const -> const_reverse_linear_iterator { return linear_crbegin(); } template template - requires has_data_interface_conceptand strided_view_concept auto - xview::linear_rend() const -> const_reverse_linear_iterator + requires has_data_interface_concept and strided_view_concept + auto xview::linear_rend() const -> const_reverse_linear_iterator { return linear_crend(); } template template - requires has_data_interface_conceptand strided_view_concept auto - xview::linear_crbegin() const -> const_reverse_linear_iterator + requires has_data_interface_concept and strided_view_concept + auto xview::linear_crbegin() const -> const_reverse_linear_iterator { return const_reverse_linear_iterator(linear_end()); } template template - requires has_data_interface_conceptand strided_view_concept auto - xview::linear_crend() const -> const_reverse_linear_iterator + requires has_data_interface_concept and strided_view_concept + auto xview::linear_crend() const -> const_reverse_linear_iterator { return const_reverse_linear_iterator(linear_begin()); } @@ -1260,8 +1271,8 @@ namespace xt */ template template - requires has_data_interface_conceptand inline strided_view_concept auto - xview::strides() const -> const inner_strides_type& + requires has_data_interface_concept and strided_view_concept + inline auto xview::strides() const -> const inner_strides_type& { if (!m_strides_computed) { @@ -1273,8 +1284,8 @@ namespace xt template template - requires has_data_interface_conceptand inline strided_view_concept auto - xview::backstrides() const -> const inner_strides_type& + requires has_data_interface_concept and strided_view_concept + inline auto xview::backstrides() const -> const inner_strides_type& { if (!m_strides_computed) { @@ -1289,16 +1300,16 @@ namespace xt */ template template - requires has_data_interface_conceptand inline strided_view_concept auto - xview::data() const -> const_pointer + requires has_data_interface_concept and strided_view_concept + inline auto xview::data() const -> const_pointer { return m_e.data(); } template template - requires has_data_interface_conceptand inline strided_view_concept auto - xview::data() -> pointer + requires has_data_interface_concept and strided_view_concept + inline auto xview::data() -> pointer { return m_e.data(); } @@ -1329,8 +1340,8 @@ namespace xt */ template template - requires has_data_interface_conceptand inline strided_view_concept std::size_t - xview::data_offset() const noexcept + requires has_data_interface_concept and strided_view_concept + inline std::size_t xview::data_offset() const noexcept { if (!m_strides_computed) { @@ -1446,8 +1457,8 @@ namespace xt // Assign to operator enabled for contigous views template template - requires has_data_interface_conceptand contiguous_view_concept void - xview::assign_to(xexpression& e, bool force_resize) const + requires has_data_interface_concept and contiguous_view_concept + void xview::assign_to(xexpression& e, bool force_resize) const { auto& de = e.derived_cast(); de.resize(shape(), force_resize); @@ -1470,40 +1481,40 @@ namespace xt template template - requires has_simd_interface_conceptand inline strided_view_concept auto - xview::store_simd(size_type i, const simd& e) -> void + requires has_simd_interface_concept and strided_view_concept + inline auto xview::store_simd(size_type i, const simd& e) -> void { return m_e.template store_simd(data_offset() + i, e); } template template - requires has_simd_interface_conceptand inline strided_view_concept auto - xview::load_simd(size_type i) const -> simd_return_type + requires has_simd_interface_concept and strided_view_concept + inline auto xview::load_simd(size_type i) const -> simd_return_type { return m_e.template load_simd(data_offset() + i); } template template - requires has_simd_interface_conceptand inline strided_view_concept auto - xview::data_element(size_type i) -> reference + requires has_simd_interface_concept and strided_view_concept + inline auto xview::data_element(size_type i) -> reference { return m_e.data_element(data_offset() + i); } template template - requires has_simd_interface_conceptand inline strided_view_concept auto - xview::data_element(size_type i) const -> const_reference + requires has_simd_interface_concept and strided_view_concept + inline auto xview::data_element(size_type i) const -> const_reference { return m_e.data_element(data_offset() + i); } template template - requires has_simd_interface_conceptand inline strided_view_concept auto - xview::flat(size_type i) -> reference + requires has_simd_interface_concept and strided_view_concept + inline auto xview::flat(size_type i) -> reference { XTENSOR_ASSERT(is_contiguous()); return m_e.flat(data_offset() + i); @@ -1511,8 +1522,8 @@ namespace xt template template - requires has_simd_interface_conceptand inline strided_view_concept auto - xview::flat(size_type i) const -> const_reference + requires has_simd_interface_concept and strided_view_concept + inline auto xview::flat(size_type i) const -> const_reference { XTENSOR_ASSERT(is_contiguous()); return m_e.flat(data_offset() + i); @@ -1636,8 +1647,8 @@ namespace xt template template ::size_type I, class... Args> - requires(I + newaxis_count_before(I + 1) < sizeof...(S)) inline auto xview::index(Args... args - ) const -> size_type + requires(I + newaxis_count_before(I + 1) < sizeof...(S)) + inline auto xview::index(Args... args) const -> size_type { return sliced_access(I) + newaxis_count_before(I + 1)>( std::get(I + 1)>(m_slices), @@ -1647,8 +1658,8 @@ namespace xt template template ::size_type I, class... Args> - requires(!(I + newaxis_count_before(I + 1) < sizeof...(S)) - ) inline auto xview::index(Args... args) const -> size_type + requires(!(I + newaxis_count_before(I + 1) < sizeof...(S))) + inline auto xview::index(Args... args) const -> size_type { return argument() + newaxis_count()>(args...); } From 4809115e7fd53148a5926c99f82d2ead2d5e1ab0 Mon Sep 17 00:00:00 2001 From: Alexandre Hoffmann Date: Thu, 10 Apr 2025 08:31:34 +0200 Subject: [PATCH 4/6] minor corrections suggested by Johan --- include/xtensor/containers/xscalar.hpp | 2 +- include/xtensor/containers/xstorage.hpp | 8 ++++---- include/xtensor/utils/xutils.hpp | 3 --- include/xtensor/views/xview.hpp | 4 ++-- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/xtensor/containers/xscalar.hpp b/include/xtensor/containers/xscalar.hpp index e97db8e64..9464f4721 100644 --- a/include/xtensor/containers/xscalar.hpp +++ b/include/xtensor/containers/xscalar.hpp @@ -318,7 +318,7 @@ namespace xt using is_xscalar = detail::is_xscalar_impl; template - concept is_xscalar_concept = is_xscalar>::value; + concept xscalar_concept = is_xscalar>::value; namespace detail { diff --git a/include/xtensor/containers/xstorage.hpp b/include/xtensor/containers/xstorage.hpp index 30fbc49c1..96fbdfffe 100644 --- a/include/xtensor/containers/xstorage.hpp +++ b/include/xtensor/containers/xstorage.hpp @@ -56,7 +56,7 @@ namespace xt explicit uvector(size_type count, const allocator_type& alloc = allocator_type()); uvector(size_type count, const_reference value, const allocator_type& alloc = allocator_type()); - template + template uvector(InputIt first, InputIt last, const allocator_type& alloc = allocator_type()); uvector(std::initializer_list init, const allocator_type& alloc = allocator_type()); @@ -269,7 +269,7 @@ namespace xt } template - template + template inline uvector::uvector(InputIt first, InputIt last, const allocator_type& alloc) : m_allocator(alloc) , p_begin(nullptr) @@ -667,7 +667,7 @@ namespace xt svector(const std::vector& vec); - template + template svector(IT begin, IT end, const allocator_type& alloc = allocator_type()); template @@ -803,7 +803,7 @@ namespace xt } template - template + template inline svector::svector(IT begin, IT end, const allocator_type& alloc) : m_allocator(alloc) { diff --git a/include/xtensor/utils/xutils.hpp b/include/xtensor/utils/xutils.hpp index 4ecab7a41..8f40b0c05 100644 --- a/include/xtensor/utils/xutils.hpp +++ b/include/xtensor/utils/xutils.hpp @@ -632,9 +632,6 @@ namespace xt template concept iterator_concept = is_iterator::value; - template - concept input_iterator_concept = std:: - is_convertible::iterator_category, std::input_iterator_tag>::value; /******************************************** * xtrivial_default_construct implemenation * diff --git a/include/xtensor/views/xview.hpp b/include/xtensor/views/xview.hpp index c3103ecb9..de7146786 100644 --- a/include/xtensor/views/xview.hpp +++ b/include/xtensor/views/xview.hpp @@ -596,13 +596,13 @@ namespace xt inline const_container_iterator data_xend(layout_type l, size_type offset) const noexcept; // Conversion operator enabled for statically "scalar" views - template + template operator reference() { return (*this)(); } - template + template operator const_reference() const { return (*this)(); From d1210c6b2fd4dc9a5e62453640ae3f9e66560e51 Mon Sep 17 00:00:00 2001 From: Alexandre Hoffmann Date: Thu, 10 Apr 2025 15:25:59 +0200 Subject: [PATCH 5/6] required should work with clang, hopefully.... --- include/xtensor/views/xview.hpp | 144 ++++++++++++++++---------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/include/xtensor/views/xview.hpp b/include/xtensor/views/xview.hpp index de7146786..67145e967 100644 --- a/include/xtensor/views/xview.hpp +++ b/include/xtensor/views/xview.hpp @@ -517,72 +517,72 @@ namespace xt const storage_type& storage() const; template - requires has_data_interface_concept and strided_view_concept - linear_iterator linear_begin(); + linear_iterator linear_begin() + requires(has_data_interface_concept and strided_view_concept); template - requires has_data_interface_concept and strided_view_concept - linear_iterator linear_end(); + linear_iterator linear_end() + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - const_linear_iterator linear_begin() const; + const_linear_iterator linear_begin() const + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - const_linear_iterator linear_end() const; + const_linear_iterator linear_end() const + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - const_linear_iterator linear_cbegin() const; + const_linear_iterator linear_cbegin() const + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - const_linear_iterator linear_cend() const; + const_linear_iterator linear_cend() const + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - reverse_linear_iterator linear_rbegin(); + reverse_linear_iterator linear_rbegin() + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - reverse_linear_iterator linear_rend(); + reverse_linear_iterator linear_rend() + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - const_reverse_linear_iterator linear_rbegin() const; + const_reverse_linear_iterator linear_rbegin() const + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - const_reverse_linear_iterator linear_rend() const; + const_reverse_linear_iterator linear_rend() const + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - const_reverse_linear_iterator linear_crbegin() const; + const_reverse_linear_iterator linear_crbegin() const + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - const_reverse_linear_iterator linear_crend() const; + const_reverse_linear_iterator linear_crend() const + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - const inner_strides_type& strides() const; + const inner_strides_type& strides() const + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - const inner_strides_type& backstrides() const; + const inner_strides_type& backstrides() const + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - const_pointer data() const; + const_pointer data() const + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - pointer data(); + pointer data() + requires has_data_interface_concept and strided_view_concept; template - requires has_data_interface_concept and strided_view_concept - std::size_t data_offset() const noexcept; + std::size_t data_offset() const noexcept + requires has_data_interface_concept and strided_view_concept; template inline It data_xbegin_impl(It begin) const noexcept; @@ -615,8 +615,8 @@ namespace xt xtl::xclosure_pointer operator&() &&; template - requires has_data_interface_concept and contiguous_view_concept - void assign_to(xexpression& e, bool force_resize) const; + void assign_to(xexpression& e, bool force_resize) const + requires has_data_interface_concept and contiguous_view_concept; template using rebind_t = xview; @@ -632,32 +632,32 @@ namespace xt using simd_return_type = xt_simd::simd_return_type; template - requires has_simd_interface_concept and strided_view_concept - void store_simd(size_type i, const simd& e); + void store_simd(size_type i, const simd& e) + requires has_simd_interface_concept and strided_view_concept; template < class align, class requested_type = value_type, std::size_t N = xt_simd::simd_traits::size, class T = xexpression_type> - requires has_simd_interface_concept and strided_view_concept - simd_return_type load_simd(size_type i) const; + simd_return_type load_simd(size_type i) const + requires has_simd_interface_concept and strided_view_concept; template - requires has_simd_interface_concept and strided_view_concept - reference data_element(size_type i); + reference data_element(size_type i) + requires has_simd_interface_concept and strided_view_concept; template - requires has_simd_interface_concept and strided_view_concept - const_reference data_element(size_type i) const; + const_reference data_element(size_type i) const + requires has_simd_interface_concept and strided_view_concept; template - requires has_simd_interface_concept and strided_view_concept - reference flat(size_type i); + reference flat(size_type i) + requires has_simd_interface_concept and strided_view_concept; template - requires has_simd_interface_concept and strided_view_concept - const_reference flat(size_type i) const; + const_reference flat(size_type i) const + requires has_simd_interface_concept and strided_view_concept; private: @@ -1172,96 +1172,96 @@ namespace xt template template - requires(has_data_interface_concept and strided_view_concept) auto xview::linear_begin() -> linear_iterator + requires(has_data_interface_concept and strided_view_concept) { return m_e.storage().begin() + data_offset(); } template template - requires has_data_interface_concept and strided_view_concept auto xview::linear_end() -> linear_iterator + requires has_data_interface_concept and strided_view_concept { return m_e.storage().begin() + data_offset() + this->size(); } template template - requires has_data_interface_concept and strided_view_concept auto xview::linear_begin() const -> const_linear_iterator + requires has_data_interface_concept and strided_view_concept { return linear_cbegin(); } template template - requires has_data_interface_concept and strided_view_concept auto xview::linear_end() const -> const_linear_iterator + requires has_data_interface_concept and strided_view_concept { return linear_cend(); } template template - requires has_data_interface_concept and strided_view_concept auto xview::linear_cbegin() const -> const_linear_iterator + requires has_data_interface_concept and strided_view_concept { return m_e.storage().cbegin() + data_offset(); } template template - requires has_data_interface_concept and strided_view_concept auto xview::linear_cend() const -> const_linear_iterator + requires has_data_interface_concept and strided_view_concept { return m_e.storage().cbegin() + data_offset() + this->size(); } template template - requires has_data_interface_concept and strided_view_concept auto xview::linear_rbegin() -> reverse_linear_iterator + requires has_data_interface_concept and strided_view_concept { return reverse_linear_iterator(linear_end()); } template template - requires has_data_interface_concept and strided_view_concept auto xview::linear_rend() -> reverse_linear_iterator + requires has_data_interface_concept and strided_view_concept { return reverse_linear_iterator(linear_begin()); } template template - requires has_data_interface_concept and strided_view_concept auto xview::linear_rbegin() const -> const_reverse_linear_iterator + requires has_data_interface_concept and strided_view_concept { return linear_crbegin(); } template template - requires has_data_interface_concept and strided_view_concept auto xview::linear_rend() const -> const_reverse_linear_iterator + requires has_data_interface_concept and strided_view_concept { return linear_crend(); } template template - requires has_data_interface_concept and strided_view_concept auto xview::linear_crbegin() const -> const_reverse_linear_iterator + requires has_data_interface_concept and strided_view_concept { return const_reverse_linear_iterator(linear_end()); } template template - requires has_data_interface_concept and strided_view_concept auto xview::linear_crend() const -> const_reverse_linear_iterator + requires has_data_interface_concept and strided_view_concept { return const_reverse_linear_iterator(linear_begin()); } @@ -1271,8 +1271,8 @@ namespace xt */ template template - requires has_data_interface_concept and strided_view_concept inline auto xview::strides() const -> const inner_strides_type& + requires has_data_interface_concept and strided_view_concept { if (!m_strides_computed) { @@ -1284,8 +1284,8 @@ namespace xt template template - requires has_data_interface_concept and strided_view_concept inline auto xview::backstrides() const -> const inner_strides_type& + requires has_data_interface_concept and strided_view_concept { if (!m_strides_computed) { @@ -1300,16 +1300,16 @@ namespace xt */ template template - requires has_data_interface_concept and strided_view_concept inline auto xview::data() const -> const_pointer + requires has_data_interface_concept and strided_view_concept { return m_e.data(); } template template - requires has_data_interface_concept and strided_view_concept inline auto xview::data() -> pointer + requires has_data_interface_concept and strided_view_concept { return m_e.data(); } @@ -1340,8 +1340,8 @@ namespace xt */ template template - requires has_data_interface_concept and strided_view_concept inline std::size_t xview::data_offset() const noexcept + requires has_data_interface_concept and strided_view_concept { if (!m_strides_computed) { @@ -1457,8 +1457,8 @@ namespace xt // Assign to operator enabled for contigous views template template - requires has_data_interface_concept and contiguous_view_concept void xview::assign_to(xexpression& e, bool force_resize) const + requires has_data_interface_concept and contiguous_view_concept { auto& de = e.derived_cast(); de.resize(shape(), force_resize); @@ -1481,40 +1481,40 @@ namespace xt template template - requires has_simd_interface_concept and strided_view_concept inline auto xview::store_simd(size_type i, const simd& e) -> void + requires has_simd_interface_concept and strided_view_concept { return m_e.template store_simd(data_offset() + i, e); } template template - requires has_simd_interface_concept and strided_view_concept inline auto xview::load_simd(size_type i) const -> simd_return_type + requires has_simd_interface_concept and strided_view_concept { return m_e.template load_simd(data_offset() + i); } template template - requires has_simd_interface_concept and strided_view_concept inline auto xview::data_element(size_type i) -> reference + requires has_simd_interface_concept and strided_view_concept { return m_e.data_element(data_offset() + i); } template template - requires has_simd_interface_concept and strided_view_concept inline auto xview::data_element(size_type i) const -> const_reference + requires has_simd_interface_concept and strided_view_concept { return m_e.data_element(data_offset() + i); } template template - requires has_simd_interface_concept and strided_view_concept inline auto xview::flat(size_type i) -> reference + requires has_simd_interface_concept and strided_view_concept { XTENSOR_ASSERT(is_contiguous()); return m_e.flat(data_offset() + i); @@ -1522,8 +1522,8 @@ namespace xt template template - requires has_simd_interface_concept and strided_view_concept inline auto xview::flat(size_type i) const -> const_reference + requires has_simd_interface_concept and strided_view_concept { XTENSOR_ASSERT(is_contiguous()); return m_e.flat(data_offset() + i); From 8e48331f27471c9c9078143a3a9c0472541f2610 Mon Sep 17 00:00:00 2001 From: Alexandre Hoffmann Date: Fri, 11 Apr 2025 10:59:02 +0200 Subject: [PATCH 6/6] should work with clang --- include/xtensor/containers/xfixed.hpp | 6 +- include/xtensor/containers/xstorage.hpp | 12 +- include/xtensor/generators/xgenerator.hpp | 8 +- include/xtensor/misc/xset_operation.hpp | 4 +- include/xtensor/views/xview.hpp | 173 ++++++++++------------ 5 files changed, 97 insertions(+), 106 deletions(-) diff --git a/include/xtensor/containers/xfixed.hpp b/include/xtensor/containers/xfixed.hpp index aedac1ae6..4ab3a75c3 100644 --- a/include/xtensor/containers/xfixed.hpp +++ b/include/xtensor/containers/xfixed.hpp @@ -326,8 +326,8 @@ namespace xt explicit xfixed_container(const inner_shape_type& shape, value_type v, layout_type l = L); template > - requires(IX::value != 0) - xfixed_container(nested_initializer_list_t t); + xfixed_container(nested_initializer_list_t t) + requires(IX::value != 0); ~xfixed_container() = default; @@ -640,8 +640,8 @@ namespace xt */ template template - requires(IX::value != 0) inline xfixed_container::xfixed_container(nested_initializer_list_t t) + requires(IX::value != 0) { XTENSOR_ASSERT_MSG( detail::check_initializer_list_shape::run(t, this->shape()) == true, diff --git a/include/xtensor/containers/xstorage.hpp b/include/xtensor/containers/xstorage.hpp index 96fbdfffe..28ad238e5 100644 --- a/include/xtensor/containers/xstorage.hpp +++ b/include/xtensor/containers/xstorage.hpp @@ -671,8 +671,8 @@ namespace xt svector(IT begin, IT end, const allocator_type& alloc = allocator_type()); template - requires(N != N2) - explicit svector(const svector& rhs); + explicit svector(const svector& rhs) + requires(N != N2); svector& operator=(const svector& rhs); svector& operator=(svector&& rhs) noexcept(std::is_nothrow_move_assignable::value); @@ -680,8 +680,8 @@ namespace xt svector& operator=(std::initializer_list il); template - requires(N != N2) - svector& operator=(const svector& rhs); + svector& operator=(const svector& rhs) + requires(N != N2); svector(const svector& other); svector(svector&& other) noexcept(std::is_nothrow_move_constructible::value); @@ -812,8 +812,8 @@ namespace xt template template - requires(N != N2) inline svector::svector(const svector& rhs) + requires(N != N2) : m_allocator(rhs.get_allocator()) { assign(rhs.begin(), rhs.end()); @@ -872,8 +872,8 @@ namespace xt template template - requires(N != N2) inline svector& svector::operator=(const svector& rhs) + requires(N != N2) { m_allocator = std::allocator_traits::select_on_container_copy_construction( rhs.get_allocator() diff --git a/include/xtensor/generators/xgenerator.hpp b/include/xtensor/generators/xgenerator.hpp index aba7b46e2..f4dfc191f 100644 --- a/include/xtensor/generators/xgenerator.hpp +++ b/include/xtensor/generators/xgenerator.hpp @@ -84,7 +84,7 @@ namespace xt *************************************/ template - requires without_memory_address_concept + requires(without_memory_address_concept) struct overlapping_memory_checker_traits { static bool check_overlap(const E&, const memory_range&) @@ -168,8 +168,8 @@ namespace xt const_stepper stepper_end(const O& shape, layout_type) const noexcept; template - requires has_assign_to_v - void assign_to(xexpression& e) const noexcept; + void assign_to(xexpression& e) const noexcept + requires(has_assign_to_v); const functor_type& functor() const noexcept; @@ -375,8 +375,8 @@ namespace xt template template - requires has_assign_to_v inline void xgenerator::assign_to(xexpression& e) const noexcept + requires(has_assign_to_v) { e.derived_cast().resize(m_shape); m_f.assign_to(e); diff --git a/include/xtensor/misc/xset_operation.hpp b/include/xtensor/misc/xset_operation.hpp index eb87dcc53..94b7e23a7 100644 --- a/include/xtensor/misc/xset_operation.hpp +++ b/include/xtensor/misc/xset_operation.hpp @@ -88,8 +88,8 @@ namespace xt * @return a boolean array */ template - requires has_iterator_interface_concept inline auto isin(E&& element, F&& test_elements) noexcept + requires(has_iterator_interface_concept) { auto lambda = detail::lambda_isin::value>::make(std::forward(test_elements )); @@ -145,8 +145,8 @@ namespace xt * @return a boolean array */ template - requires has_iterator_interface_concept inline auto in1d(E&& element, F&& test_elements) noexcept + requires(has_iterator_interface_concept) { XTENSOR_ASSERT(element.dimension() == 1ul); XTENSOR_ASSERT(test_elements.dimension() == 1ul); diff --git a/include/xtensor/views/xview.hpp b/include/xtensor/views/xview.hpp index 67145e967..be4c05e1a 100644 --- a/include/xtensor/views/xview.hpp +++ b/include/xtensor/views/xview.hpp @@ -509,12 +509,12 @@ namespace xt const_stepper stepper_end(const ST& shape, layout_type l) const; template - requires has_data_interface_concept - storage_type& storage(); + storage_type& storage() + requires(has_data_interface_concept); template - requires has_data_interface_concept - const storage_type& storage() const; + const storage_type& storage() const + requires(has_data_interface_concept); template linear_iterator linear_begin() @@ -522,67 +522,67 @@ namespace xt template linear_iterator linear_end() - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template const_linear_iterator linear_begin() const - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template const_linear_iterator linear_end() const - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template const_linear_iterator linear_cbegin() const - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template const_linear_iterator linear_cend() const - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template reverse_linear_iterator linear_rbegin() - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template reverse_linear_iterator linear_rend() - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template const_reverse_linear_iterator linear_rbegin() const - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template const_reverse_linear_iterator linear_rend() const - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template const_reverse_linear_iterator linear_crbegin() const - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template const_reverse_linear_iterator linear_crend() const - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template const inner_strides_type& strides() const - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template const inner_strides_type& backstrides() const - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template const_pointer data() const - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template pointer data() - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template std::size_t data_offset() const noexcept - requires has_data_interface_concept and strided_view_concept; + requires(has_data_interface_concept and strided_view_concept); template inline It data_xbegin_impl(It begin) const noexcept; @@ -616,7 +616,7 @@ namespace xt template void assign_to(xexpression& e, bool force_resize) const - requires has_data_interface_concept and contiguous_view_concept; + requires(has_data_interface_concept and contiguous_view_concept); template using rebind_t = xview; @@ -633,7 +633,7 @@ namespace xt template void store_simd(size_type i, const simd& e) - requires has_simd_interface_concept and strided_view_concept; + requires(has_simd_interface_concept and strided_view_concept); template < class align, @@ -641,32 +641,32 @@ namespace xt std::size_t N = xt_simd::simd_traits::size, class T = xexpression_type> simd_return_type load_simd(size_type i) const - requires has_simd_interface_concept and strided_view_concept; + requires(has_simd_interface_concept and strided_view_concept); template reference data_element(size_type i) - requires has_simd_interface_concept and strided_view_concept; + requires(has_simd_interface_concept and strided_view_concept); template const_reference data_element(size_type i) const - requires has_simd_interface_concept and strided_view_concept; + requires(has_simd_interface_concept and strided_view_concept); template reference flat(size_type i) - requires has_simd_interface_concept and strided_view_concept; + requires(has_simd_interface_concept and strided_view_concept); template const_reference flat(size_type i) const - requires has_simd_interface_concept and strided_view_concept; + requires(has_simd_interface_concept and strided_view_concept); private: // VS 2015 workaround (yes, really) - // template - // struct lesser_condition - //{ - // static constexpr bool value = (I + newaxis_count_before(I + 1) < sizeof...(S)); - //}; + template + struct lesser_condition + { + static constexpr bool value = (I + newaxis_count_before(I + 1) < sizeof...(S)); + }; CT m_e; slice_type m_slices; @@ -711,11 +711,6 @@ namespace xt const_reference access_impl(std::index_sequence, Args... args) const; template ::size_type I, class... Args> - requires(I + newaxis_count_before(I + 1) < sizeof...(S)) - size_type index(Args... args) const; - - template ::size_type I, class... Args> - requires(!(I + newaxis_count_before(I + 1) < sizeof...(S))) size_type index(Args... args) const; template ::size_type, class T> @@ -1156,16 +1151,16 @@ namespace xt */ template template - requires has_data_interface_concept inline auto xview::storage() -> storage_type& + requires(has_data_interface_concept) { return m_e.storage(); } template template - requires has_data_interface_concept inline auto xview::storage() const -> const storage_type& + requires(has_data_interface_concept) { return m_e.storage(); } @@ -1181,7 +1176,7 @@ namespace xt template template auto xview::linear_end() -> linear_iterator - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return m_e.storage().begin() + data_offset() + this->size(); } @@ -1189,7 +1184,7 @@ namespace xt template template auto xview::linear_begin() const -> const_linear_iterator - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return linear_cbegin(); } @@ -1197,7 +1192,7 @@ namespace xt template template auto xview::linear_end() const -> const_linear_iterator - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return linear_cend(); } @@ -1205,7 +1200,7 @@ namespace xt template template auto xview::linear_cbegin() const -> const_linear_iterator - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return m_e.storage().cbegin() + data_offset(); } @@ -1213,7 +1208,7 @@ namespace xt template template auto xview::linear_cend() const -> const_linear_iterator - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return m_e.storage().cbegin() + data_offset() + this->size(); } @@ -1221,7 +1216,7 @@ namespace xt template template auto xview::linear_rbegin() -> reverse_linear_iterator - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return reverse_linear_iterator(linear_end()); } @@ -1229,7 +1224,7 @@ namespace xt template template auto xview::linear_rend() -> reverse_linear_iterator - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return reverse_linear_iterator(linear_begin()); } @@ -1237,7 +1232,7 @@ namespace xt template template auto xview::linear_rbegin() const -> const_reverse_linear_iterator - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return linear_crbegin(); } @@ -1245,7 +1240,7 @@ namespace xt template template auto xview::linear_rend() const -> const_reverse_linear_iterator - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return linear_crend(); } @@ -1253,7 +1248,7 @@ namespace xt template template auto xview::linear_crbegin() const -> const_reverse_linear_iterator - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return const_reverse_linear_iterator(linear_end()); } @@ -1261,7 +1256,7 @@ namespace xt template template auto xview::linear_crend() const -> const_reverse_linear_iterator - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return const_reverse_linear_iterator(linear_begin()); } @@ -1271,29 +1266,27 @@ namespace xt */ template template - inline auto xview::strides() const -> const inner_strides_type& - requires has_data_interface_concept and strided_view_concept - { - if (!m_strides_computed) - { - compute_strides(std::integral_constant{}); - m_strides_computed = true; + inline auto xview::strides() const + -> const inner_strides_type& requires(has_data_interface_conceptand strided_view_concept) { + if (!m_strides_computed) + { + compute_strides(std::integral_constant{}); + m_strides_computed = true; + } + return m_strides; } - return m_strides; - } template template - inline auto xview::backstrides() const -> const inner_strides_type& - requires has_data_interface_concept and strided_view_concept - { - if (!m_strides_computed) - { - compute_strides(std::integral_constant{}); - m_strides_computed = true; + inline auto xview::backstrides() const + -> const inner_strides_type& requires(has_data_interface_conceptand strided_view_concept) { + if (!m_strides_computed) + { + compute_strides(std::integral_constant{}); + m_strides_computed = true; + } + return m_backstrides; } - return m_backstrides; - } /** * Return the pointer to the underlying buffer. @@ -1301,7 +1294,7 @@ namespace xt template template inline auto xview::data() const -> const_pointer - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return m_e.data(); } @@ -1309,7 +1302,7 @@ namespace xt template template inline auto xview::data() -> pointer - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { return m_e.data(); } @@ -1341,7 +1334,7 @@ namespace xt template template inline std::size_t xview::data_offset() const noexcept - requires has_data_interface_concept and strided_view_concept + requires(has_data_interface_concept and strided_view_concept) { if (!m_strides_computed) { @@ -1458,7 +1451,7 @@ namespace xt template template void xview::assign_to(xexpression& e, bool force_resize) const - requires has_data_interface_concept and contiguous_view_concept + requires(has_data_interface_concept and contiguous_view_concept) { auto& de = e.derived_cast(); de.resize(shape(), force_resize); @@ -1482,7 +1475,7 @@ namespace xt template template inline auto xview::store_simd(size_type i, const simd& e) -> void - requires has_simd_interface_concept and strided_view_concept + requires(has_simd_interface_concept and strided_view_concept) { return m_e.template store_simd(data_offset() + i, e); } @@ -1490,7 +1483,7 @@ namespace xt template template inline auto xview::load_simd(size_type i) const -> simd_return_type - requires has_simd_interface_concept and strided_view_concept + requires(has_simd_interface_concept and strided_view_concept) { return m_e.template load_simd(data_offset() + i); } @@ -1498,7 +1491,7 @@ namespace xt template template inline auto xview::data_element(size_type i) -> reference - requires has_simd_interface_concept and strided_view_concept + requires(has_simd_interface_concept and strided_view_concept) { return m_e.data_element(data_offset() + i); } @@ -1506,7 +1499,7 @@ namespace xt template template inline auto xview::data_element(size_type i) const -> const_reference - requires has_simd_interface_concept and strided_view_concept + requires(has_simd_interface_concept and strided_view_concept) { return m_e.data_element(data_offset() + i); } @@ -1514,7 +1507,7 @@ namespace xt template template inline auto xview::flat(size_type i) -> reference - requires has_simd_interface_concept and strided_view_concept + requires(has_simd_interface_concept and strided_view_concept) { XTENSOR_ASSERT(is_contiguous()); return m_e.flat(data_offset() + i); @@ -1523,7 +1516,7 @@ namespace xt template template inline auto xview::flat(size_type i) const -> const_reference - requires has_simd_interface_concept and strided_view_concept + requires(has_simd_interface_concept and strided_view_concept) { XTENSOR_ASSERT(is_contiguous()); return m_e.flat(data_offset() + i); @@ -1647,21 +1640,19 @@ namespace xt template template ::size_type I, class... Args> - requires(I + newaxis_count_before(I + 1) < sizeof...(S)) - inline auto xview::index(Args... args) const -> size_type - { - return sliced_access(I) + newaxis_count_before(I + 1)>( - std::get(I + 1)>(m_slices), - args... - ); - } - - template - template ::size_type I, class... Args> - requires(!(I + newaxis_count_before(I + 1) < sizeof...(S))) inline auto xview::index(Args... args) const -> size_type { - return argument() + newaxis_count()>(args...); + if constexpr (lesser_condition::value) + { + return sliced_access(I) + newaxis_count_before(I + 1)>( + std::get(I + 1)>(m_slices), + args... + ); + } + else + { + return argument() + newaxis_count()>(args...); + } } template