Skip to content

Commit 995896b

Browse files
committed
More generic implementation
1 parent 1555d4d commit 995896b

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

include/xtensor/xbuilder.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ namespace xt
535535
using value_type = xtl::promote_type_t<typename std::decay_t<CT>::value_type...>;
536536

537537
template <class It>
538-
inline value_type access(const tuple_type& t, size_type axis, It first, It last) const
538+
inline value_type access(const tuple_type& t, size_type axis, It first, It) const
539539
{
540540
auto get_item = [&](auto& arr)
541541
{
@@ -548,7 +548,8 @@ namespace xt
548548
{
549549
after_axis = true;
550550
}
551-
const auto& stride = arr.strides()[i];
551+
const auto& shape = arr.shape();
552+
const size_t stride = std::accumulate(shape.begin() + i + 1, shape.end(), 1, std::multiplies<size_t>());
552553
const auto len = (*(first + i + after_axis));
553554
offset += len * stride;
554555
}

test/test_xbuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,9 @@ namespace xt
466466
ASSERT_EQ(3, l(1, 1));
467467
ASSERT_EQ(3, l(2, 0));
468468

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

474474
TEST(xbuilder, hstack)

0 commit comments

Comments
 (0)