From 7781852ea29bf908be0d0022f50134ede61e1239 Mon Sep 17 00:00:00 2001 From: Drew Hubley Date: Sun, 23 Nov 2025 13:26:52 -0400 Subject: [PATCH 1/4] Removed impl functions in favor of std::apply --- include/xtensor/core/xfunction.hpp | 143 +++++++---------------------- 1 file changed, 35 insertions(+), 108 deletions(-) diff --git a/include/xtensor/core/xfunction.hpp b/include/xtensor/core/xfunction.hpp index 8f85892fb..5533ece21 100644 --- a/include/xtensor/core/xfunction.hpp +++ b/include/xtensor/core/xfunction.hpp @@ -355,24 +355,6 @@ namespace xt private: - template - layout_type layout_impl(std::index_sequence) const noexcept; - - template - const_reference access_impl(std::index_sequence, Args... args) const; - - template - const_reference unchecked_impl(std::index_sequence, Args... args) const; - - template - const_reference element_access_impl(std::index_sequence, It first, It last) const; - - template - const_reference data_element_impl(std::index_sequence, size_type i) const; - - template - auto load_simd_impl(std::index_sequence, size_type i) const; - template const_stepper build_stepper(Func&& f, std::index_sequence) const noexcept; @@ -437,9 +419,6 @@ namespace xt using data_type = std::tuple>()))...>; - template - reference deref_impl(std::index_sequence) const; - template difference_type tuple_max_diff(std::index_sequence, const data_type& lhs, const data_type& rhs) const; @@ -499,13 +478,6 @@ namespace xt void step_leading(); private: - - template - reference deref_impl(std::index_sequence) const; - - template - simd_return_type step_simd_impl(std::index_sequence); - const xfunction_type* p_f; std::tuple::const_stepper...> m_st; }; @@ -593,7 +565,9 @@ namespace xt template inline layout_type xfunction::layout() const noexcept { - return layout_impl(std::make_index_sequence()); + return std::apply([&](auto&... e){ + return compute_layout(e.layout()...); + }, m_e); } template @@ -628,7 +602,13 @@ namespace xt { // The static cast prevents the compiler from instantiating the template methods with signed integers, // leading to warning about signed/unsigned conversions in the deeper layers of the access methods - return access_impl(std::make_index_sequence(), static_cast(args)...); + + return std::apply([&](auto&... e){ + XTENSOR_TRY(check_index(shape(), args...)); + XTENSOR_CHECK_DIMENSION(shape(), args...); + return m_f(e(args...)...); + + }, m_e); } /** @@ -643,7 +623,9 @@ namespace xt template inline auto xfunction::flat(size_type index) const -> const_reference { - return data_element_impl(std::make_index_sequence(), index); + return std::apply([&](auto&... e){ + return m_f(e.data_element(index)...); + }, m_e); } /** @@ -671,7 +653,9 @@ namespace xt { // The static cast prevents the compiler from instantiating the template methods with signed integers, // leading to warning about signed/unsigned conversions in the deeper layers of the access methods - return unchecked_impl(std::make_index_sequence(), static_cast(args)...); + return std::apply([&](const auto&... e){ + return m_f(e.unchecked(static_cast(args)...)...); + }, m_e); } /** @@ -685,7 +669,10 @@ namespace xt template inline auto xfunction::element(It first, It last) const -> const_reference { - return element_access_impl(std::make_index_sequence(), first, last); + std::apply([&](auto&... e){ + XTENSOR_TRY(check_element_index(shape(), first, last)); + return m_f(e.element(first, last)...); + }, m_e); } //@} @@ -819,7 +806,9 @@ namespace xt template inline auto xfunction::data_element(size_type i) const -> const_reference { - return data_element_impl(std::make_index_sequence(), i); + return std::apply([&](auto&... e){ + return m_f(e.data_element(i)...); + }, m_e); } template @@ -833,7 +822,9 @@ namespace xt template inline auto xfunction::load_simd(size_type i) const -> simd_return_type { - return load_simd_impl(std::make_index_sequence(), i); + return std::apply([&](auto&... e){ + return m_f.simd_apply((e.template load_simd(i))...); + },m_e); } template @@ -848,55 +839,6 @@ namespace xt return m_f; } - template - template - inline layout_type xfunction::layout_impl(std::index_sequence) const noexcept - { - return compute_layout(std::get(m_e).layout()...); - } - - template - template - inline auto xfunction::access_impl(std::index_sequence, Args... args) const - -> const_reference - { - XTENSOR_TRY(check_index(shape(), args...)); - XTENSOR_CHECK_DIMENSION(shape(), args...); - return m_f(std::get(m_e)(args...)...); - } - - template - template - inline auto xfunction::unchecked_impl(std::index_sequence, Args... args) const - -> const_reference - { - return m_f(std::get(m_e).unchecked(args...)...); - } - - template - template - inline auto xfunction::element_access_impl(std::index_sequence, It first, It last) const - -> const_reference - { - XTENSOR_TRY(check_element_index(shape(), first, last)); - return m_f((std::get(m_e).element(first, last))...); - } - - template - template - inline auto xfunction::data_element_impl(std::index_sequence, size_type i) const - -> const_reference - { - return m_f((std::get(m_e).data_element(i))...); - } - - template - template - inline auto xfunction::load_simd_impl(std::index_sequence, size_type i) const - { - return m_f.simd_apply((std::get(m_e).template load_simd(i))...); - } - template template inline auto xfunction::build_stepper(Func&& f, std::index_sequence) const noexcept @@ -987,7 +929,9 @@ namespace xt template inline auto xfunction_iterator::operator*() const -> reference { - return deref_impl(std::make_index_sequence()); + return std::apply([&](auto&... it){ + return (p_f->m_f)(*it...); + }, m_it); } template @@ -1010,13 +954,6 @@ namespace xt return std::get(m_it) < std::get(rhs.m_it); } - template - template - inline auto xfunction_iterator::deref_impl(std::index_sequence) const -> reference - { - return (p_f->m_f)(*std::get(m_it)...); - } - template template inline auto xfunction_iterator::tuple_max_diff( @@ -1140,28 +1077,18 @@ namespace xt template inline auto xfunction_stepper::operator*() const -> reference { - return deref_impl(std::make_index_sequence()); - } - - template - template - inline auto xfunction_stepper::deref_impl(std::index_sequence) const -> reference - { - return (p_f->m_f)(*std::get(m_st)...); - } - - template - template - inline auto xfunction_stepper::step_simd_impl(std::index_sequence) -> simd_return_type - { - return (p_f->m_f.simd_apply)(std::get(m_st).template step_simd()...); + return std::apply([&](auto&... e){ + return (p_f->m_f)(*e...); + }, m_st); } template template inline auto xfunction_stepper::step_simd() -> simd_return_type { - return step_simd_impl(std::make_index_sequence()); + return std::apply([&](auto&... st){ + return (p_f->m_f.simd_apply)(st.template step_simd()...); + }, m_st); } template From 97dd8f1e3d2ce881db087b9f05d212234a3655dd Mon Sep 17 00:00:00 2001 From: Drew Hubley Date: Sun, 23 Nov 2025 17:54:16 -0400 Subject: [PATCH 2/4] All tests passing --- include/xtensor/core/xfunction.hpp | 2 +- test/CMakeLists.txt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/xtensor/core/xfunction.hpp b/include/xtensor/core/xfunction.hpp index 5533ece21..bcb0055da 100644 --- a/include/xtensor/core/xfunction.hpp +++ b/include/xtensor/core/xfunction.hpp @@ -669,7 +669,7 @@ namespace xt template inline auto xfunction::element(It first, It last) const -> const_reference { - std::apply([&](auto&... e){ + return std::apply([&](auto&... e){ XTENSOR_TRY(check_element_index(shape(), first, last)); return m_f(e.element(first, last)...); }, m_e); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8341230ee..4b143ff29 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -62,9 +62,9 @@ OPTION(XTENSOR_ENABLE_WERROR "Turn on -Werror" OFF) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXSIMD_ENABLE_XTL_COMPLEX=1") if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT WIN32)) CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported) - if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") - endif() + # if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march") + # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") + # endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -Wunused-parameter -Wextra -Wreorder -Wconversion -Wno-sign-conversion ") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast -Wunused-variable -ftemplate-backtrace-limit=0") if (XTENSOR_DISABLE_EXCEPTIONS) From dd986646a820b949e9acecf6ddcfe3d7896c669f Mon Sep 17 00:00:00 2001 From: Drew Hubley Date: Sun, 23 Nov 2025 20:28:44 -0400 Subject: [PATCH 3/4] Undo changes to cmake --- test/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4b143ff29..8341230ee 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -62,9 +62,9 @@ OPTION(XTENSOR_ENABLE_WERROR "Turn on -Werror" OFF) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXSIMD_ENABLE_XTL_COMPLEX=1") if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT WIN32)) CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported) - # if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march") - # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") - # endif() + if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") + endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -Wunused-parameter -Wextra -Wreorder -Wconversion -Wno-sign-conversion ") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast -Wunused-variable -ftemplate-backtrace-limit=0") if (XTENSOR_DISABLE_EXCEPTIONS) From 242a5ca5963c463e752f0b112f91f94acdbc5ace Mon Sep 17 00:00:00 2001 From: Drew Hubley Date: Sun, 23 Nov 2025 20:29:16 -0400 Subject: [PATCH 4/4] formatting --- include/xtensor/core/xfunction.hpp | 108 ++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 34 deletions(-) diff --git a/include/xtensor/core/xfunction.hpp b/include/xtensor/core/xfunction.hpp index bcb0055da..200a35d47 100644 --- a/include/xtensor/core/xfunction.hpp +++ b/include/xtensor/core/xfunction.hpp @@ -478,6 +478,7 @@ namespace xt void step_leading(); private: + const xfunction_type* p_f; std::tuple::const_stepper...> m_st; }; @@ -565,9 +566,13 @@ namespace xt template inline layout_type xfunction::layout() const noexcept { - return std::apply([&](auto&... e){ - return compute_layout(e.layout()...); - }, m_e); + return std::apply( + [&](auto&... e) + { + return compute_layout(e.layout()...); + }, + m_e + ); } template @@ -603,12 +608,15 @@ namespace xt // The static cast prevents the compiler from instantiating the template methods with signed integers, // leading to warning about signed/unsigned conversions in the deeper layers of the access methods - return std::apply([&](auto&... e){ - XTENSOR_TRY(check_index(shape(), args...)); - XTENSOR_CHECK_DIMENSION(shape(), args...); - return m_f(e(args...)...); - - }, m_e); + return std::apply( + [&](auto&... e) + { + XTENSOR_TRY(check_index(shape(), args...)); + XTENSOR_CHECK_DIMENSION(shape(), args...); + return m_f(e(args...)...); + }, + m_e + ); } /** @@ -623,9 +631,13 @@ namespace xt template inline auto xfunction::flat(size_type index) const -> const_reference { - return std::apply([&](auto&... e){ - return m_f(e.data_element(index)...); - }, m_e); + return std::apply( + [&](auto&... e) + { + return m_f(e.data_element(index)...); + }, + m_e + ); } /** @@ -653,9 +665,13 @@ namespace xt { // The static cast prevents the compiler from instantiating the template methods with signed integers, // leading to warning about signed/unsigned conversions in the deeper layers of the access methods - return std::apply([&](const auto&... e){ - return m_f(e.unchecked(static_cast(args)...)...); - }, m_e); + return std::apply( + [&](const auto&... e) + { + return m_f(e.unchecked(static_cast(args)...)...); + }, + m_e + ); } /** @@ -669,10 +685,14 @@ namespace xt template inline auto xfunction::element(It first, It last) const -> const_reference { - return std::apply([&](auto&... e){ - XTENSOR_TRY(check_element_index(shape(), first, last)); - return m_f(e.element(first, last)...); - }, m_e); + return std::apply( + [&](auto&... e) + { + XTENSOR_TRY(check_element_index(shape(), first, last)); + return m_f(e.element(first, last)...); + }, + m_e + ); } //@} @@ -806,9 +826,13 @@ namespace xt template inline auto xfunction::data_element(size_type i) const -> const_reference { - return std::apply([&](auto&... e){ - return m_f(e.data_element(i)...); - }, m_e); + return std::apply( + [&](auto&... e) + { + return m_f(e.data_element(i)...); + }, + m_e + ); } template @@ -822,9 +846,13 @@ namespace xt template inline auto xfunction::load_simd(size_type i) const -> simd_return_type { - return std::apply([&](auto&... e){ - return m_f.simd_apply((e.template load_simd(i))...); - },m_e); + return std::apply( + [&](auto&... e) + { + return m_f.simd_apply((e.template load_simd(i))...); + }, + m_e + ); } template @@ -929,9 +957,13 @@ namespace xt template inline auto xfunction_iterator::operator*() const -> reference { - return std::apply([&](auto&... it){ - return (p_f->m_f)(*it...); - }, m_it); + return std::apply( + [&](auto&... it) + { + return (p_f->m_f)(*it...); + }, + m_it + ); } template @@ -1077,18 +1109,26 @@ namespace xt template inline auto xfunction_stepper::operator*() const -> reference { - return std::apply([&](auto&... e){ - return (p_f->m_f)(*e...); - }, m_st); + return std::apply( + [&](auto&... e) + { + return (p_f->m_f)(*e...); + }, + m_st + ); } template template inline auto xfunction_stepper::step_simd() -> simd_return_type { - return std::apply([&](auto&... st){ - return (p_f->m_f.simd_apply)(st.template step_simd()...); - }, m_st); + return std::apply( + [&](auto&... st) + { + return (p_f->m_f.simd_apply)(st.template step_simd()...); + }, + m_st + ); } template