From 68a21c5a5952913d6192be747efd245887bc36cc Mon Sep 17 00:00:00 2001 From: Alexis Placet <2400067+Alex-PLACET@users.noreply.github.com> Date: Thu, 30 Apr 2026 13:24:54 +0200 Subject: [PATCH 1/2] Fix substring calculation in CSV cell parsing and add lexical_cast for signed and unsigned char --- include/xtensor/io/xcsv.hpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/include/xtensor/io/xcsv.hpp b/include/xtensor/io/xcsv.hpp index 080ccaf54..2fd347745 100644 --- a/include/xtensor/io/xcsv.hpp +++ b/include/xtensor/io/xcsv.hpp @@ -66,7 +66,7 @@ namespace xt } size_t last = cell.find_last_not_of(' '); - return cell.substr(first, last == std::string::npos ? cell.size() : last + 1); + return cell.substr(first, last == std::string::npos ? cell.size() : last - first + 1); } template <> @@ -93,6 +93,18 @@ namespace xt return std::stoi(cell); } + template <> + inline signed char lexical_cast(const std::string& cell) + { + return static_cast(std::stoi(cell)); + } + + template <> + inline unsigned char lexical_cast(const std::string& cell) + { + return static_cast(std::stoul(cell)); + } + template <> inline long lexical_cast(const std::string& cell) { From fe3ba6cf3ab495f7877197a28ba66c82205edd6b Mon Sep 17 00:00:00 2001 From: Alexis Placet <2400067+Alex-PLACET@users.noreply.github.com> Date: Tue, 5 May 2026 16:13:02 +0200 Subject: [PATCH 2/2] Add const reverse iterators to xstorage --- include/xtensor/containers/xstorage.hpp | 10 ++++++++++ test/test_xfixed.cpp | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/include/xtensor/containers/xstorage.hpp b/include/xtensor/containers/xstorage.hpp index efeb6571e..26d4a8ccd 100644 --- a/include/xtensor/containers/xstorage.hpp +++ b/include/xtensor/containers/xstorage.hpp @@ -1640,6 +1640,16 @@ namespace xt return m_array.cend(); } + auto crbegin() const + { + return m_array.crbegin(); + } + + auto crend() const + { + return m_array.crend(); + } + constexpr std::size_t operator[](std::size_t idx) const { return m_array[idx]; diff --git a/test/test_xfixed.cpp b/test/test_xfixed.cpp index b4af22af2..3a6e8181b 100644 --- a/test/test_xfixed.cpp +++ b/test/test_xfixed.cpp @@ -22,6 +22,7 @@ #include "xtensor/core/xnoalias.hpp" #include "xtensor/io/xio.hpp" #include "xtensor/misc/xmanipulation.hpp" +#include "xtensor/views/xview.hpp" #include "test_common_macros.hpp" @@ -306,6 +307,13 @@ namespace xt using tiny_tensor = xtensor_fixed, layout_type::row_major, false>; EXPECT_GT(sizeof(fixed_tensor), sizeof(tiny_tensor)); } + + TEST(xtensor_fixed, iterators) + { + auto arr = xt::xtensor({5, 5, 5, 5, 5}); + auto fixed_arr = xt::xtensor_fixed>{1, 2, 3}; + xt::view(arr, xt::range(0, 3)) = fixed_arr + 1; + } } #endif