Skip to content

Commit

Permalink
More generic implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
spectre-ns committed Jan 1, 2024
1 parent 1555d4d commit 995896b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions include/xtensor/xbuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ namespace xt
using value_type = xtl::promote_type_t<typename std::decay_t<CT>::value_type...>;

template <class It>
inline value_type access(const tuple_type& t, size_type axis, It first, It last) const
inline value_type access(const tuple_type& t, size_type axis, It first, It) const
{
auto get_item = [&](auto& arr)
{
Expand All @@ -548,7 +548,8 @@ namespace xt
{
after_axis = true;
}
const auto& stride = arr.strides()[i];
const auto& shape = arr.shape();
const size_t stride = std::accumulate(shape.begin() + i + 1, shape.end(), 1, std::multiplies<size_t>());
const auto len = (*(first + i + after_axis));
offset += len * stride;
}
Expand Down
6 changes: 3 additions & 3 deletions test/test_xbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ namespace xt
ASSERT_EQ(3, l(1, 1));
ASSERT_EQ(3, l(2, 0));

// auto t = stack(xtuple(arange(3), arange(3, 6), arange(6, 9)));
// xarray<double> ar = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
// ASSERT_TRUE(t == ar);
auto t = stack(xtuple(arange(3), arange(3, 6), arange(6, 9)));
xarray<double> ar = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
ASSERT_TRUE(t == ar);
}

TEST(xbuilder, hstack)
Expand Down

0 comments on commit 995896b

Please sign in to comment.