Skip to content

Commit be35a26

Browse files
committed
add fixed_shape::operator==
1 parent 41be223 commit be35a26

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

include/xtensor/xstorage.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,19 @@ namespace xt
16921692
return sizeof...(X) == 0;
16931693
}
16941694

1695+
template <std::size_t... Y>
1696+
XTENSOR_FIXED_SHAPE_CONSTEXPR bool operator==(const fixed_shape<Y...>& b) const {
1697+
if (size() != b.size()) {
1698+
return false;
1699+
}
1700+
for (std::size_t i = 0; i < size(); ++i) {
1701+
if ((*this)[i] != b[i]) {
1702+
return false;
1703+
}
1704+
}
1705+
return true;
1706+
}
1707+
16951708
private:
16961709

16971710
XTENSOR_CONSTEXPR_ENHANCED_STATIC cast_type m_array = cast_type({X...});
@@ -1702,6 +1715,7 @@ namespace xt
17021715
constexpr typename fixed_shape<X...>::cast_type fixed_shape<X...>::m_array;
17031716
#endif
17041717

1718+
17051719
#undef XTENSOR_FIXED_SHAPE_CONSTEXPR
17061720

17071721
template <class E, std::ptrdiff_t Start, std::ptrdiff_t End = -1>

test/test_xbuilder.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,6 @@ namespace xt
380380
XT_EXPECT_ANY_THROW(xt::concatenate(xt::xtuple(fa, ta)));
381381
}
382382

383-
template <std::size_t... I, std::size_t... J>
384-
bool operator==(fixed_shape<I...>, fixed_shape<J...>)
385-
{
386-
std::array<std::size_t, sizeof...(I)> ix = {I...};
387-
std::array<std::size_t, sizeof...(J)> jx = {J...};
388-
return sizeof...(J) == sizeof...(I) && std::equal(ix.begin(), ix.end(), jx.begin());
389-
}
390-
391383
#ifndef VS_SKIP_CONCATENATE_FIXED
392384
// This test mimics the relevant parts of `TEST(xbuilder, concatenate)`
393385
TEST(xbuilder, concatenate_fixed)

test/test_xstorage.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ namespace xt
207207
svector_type e(src);
208208
EXPECT_EQ(size_t(10), d.size());
209209
EXPECT_EQ(size_t(1), d[2]);
210-
210+
211211
svector_type f = { 1, 2, 3, 4 };
212212
EXPECT_EQ(size_t(4), f.size());
213213
EXPECT_EQ(size_t(3), f[2]);
@@ -221,7 +221,7 @@ namespace xt
221221
TEST(svector, assign)
222222
{
223223
svector_type a = { 1, 2, 3, 4 };
224-
224+
225225
svector_type src1(10, 2);
226226
a = src1;
227227
EXPECT_EQ(size_t(10), a.size());
@@ -332,7 +332,7 @@ namespace xt
332332
EXPECT_EQ(i, a[i]);
333333
}
334334
}
335-
335+
336336
TEST(fixed_shape, fixed_shape)
337337
{
338338
fixed_shape<3, 4, 5> af;
@@ -344,4 +344,14 @@ namespace xt
344344
EXPECT_EQ(a.front(), size_t(3));
345345
EXPECT_EQ(a.size(), size_t(3));
346346
}
347+
348+
TEST(fixed_shape, operator_eq)
349+
{
350+
fixed_shape<2, 3> a, b;
351+
fixed_shape<5> c;
352+
fixed_shape<2, 4> d;
353+
EXPECT_TRUE(a == b);
354+
EXPECT_FALSE(a == c);
355+
EXPECT_FALSE(a == d);
356+
}
347357
}

0 commit comments

Comments
 (0)