Skip to content

Commit c238c83

Browse files
authored
Merge pull request #2263 from zhujun98/fix_histogram_compatibility_with_pytensor
Fix histogram compatibility with containers beyond xtensor
2 parents 1c9b74a + 2ffe43c commit c238c83

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

include/xtensor/xhistogram.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,8 @@ namespace xt
176176

177177
auto n = data.size();
178178

179-
auto bin_edges = histogram_bin_edges(data, xt::ones<value_type>({ n }), bins);
180-
181179
return detail::histogram_imp(std::forward<E1>(data),
182-
std::forward<E1>(bin_edges),
180+
histogram_bin_edges(data, xt::ones<value_type>({ n }), bins),
183181
xt::ones<value_type>({ n }),
184182
density,
185183
true);
@@ -198,10 +196,8 @@ namespace xt
198196
template <class E1, class E2>
199197
inline auto histogram(E1&& data, std::size_t bins, E2&& weights, bool density = false)
200198
{
201-
auto bin_edges = histogram_bin_edges(data, weights, bins);
202-
203199
return detail::histogram_imp(std::forward<E1>(data),
204-
std::forward<E1>(bin_edges),
200+
histogram_bin_edges(data, weights, bins),
205201
std::forward<E2>(weights),
206202
density,
207203
true);

test/test_xhistogram.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ namespace xt
3838
EXPECT_EQ(count(0), 2.);
3939
EXPECT_EQ(count(1), 2.);
4040
}
41+
42+
{
43+
xt::xarray<double> arr = {1., 1., 2., 2.};
44+
xt::xtensor<double, 1> count = xt::histogram(arr, std::size_t(2));
45+
46+
EXPECT_EQ(count.size(), std::size_t(2) );
47+
EXPECT_EQ(count(0), 2.);
48+
EXPECT_EQ(count(1), 2.);
49+
}
4150
}
4251

4352
TEST(xhistogram, bincount)

0 commit comments

Comments
 (0)