Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding comparison operators to fixed_shape. #2352

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/xtensor/xstorage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,18 @@ namespace xt
constexpr typename fixed_shape<X...>::cast_type fixed_shape<X...>::m_array;
#endif

template <std::size_t... X1, std::size_t... X2>
XTENSOR_FIXED_SHAPE_CONSTEXPR bool operator==(const fixed_shape<X1...>&, const fixed_shape<X2...>&)
{
return std::is_same<fixed_shape<X1...>, fixed_shape<X2...>>::value;
}

template <std::size_t... X1, std::size_t... X2>
XTENSOR_FIXED_SHAPE_CONSTEXPR bool operator!=(const fixed_shape<X1...>& lhs, const fixed_shape<X2...>& rhs)
{
return !(lhs == rhs);
}

#undef XTENSOR_FIXED_SHAPE_CONSTEXPR

template <class E, std::ptrdiff_t Start, std::ptrdiff_t End = -1>
Expand Down
8 changes: 0 additions & 8 deletions test/test_xbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,6 @@ namespace xt
XT_EXPECT_ANY_THROW(xt::concatenate(xt::xtuple(fa, ta)));
}

template <std::size_t... I, std::size_t... J>
bool operator==(fixed_shape<I...>, fixed_shape<J...>)
{
std::array<std::size_t, sizeof...(I)> ix = {I...};
std::array<std::size_t, sizeof...(J)> jx = {J...};
return sizeof...(J) == sizeof...(I) && std::equal(ix.begin(), ix.end(), jx.begin());
}

#ifndef VS_SKIP_CONCATENATE_FIXED
// This test mimics the relevant parts of `TEST(xbuilder, concatenate)`
TEST(xbuilder, concatenate_fixed)
Expand Down
8 changes: 0 additions & 8 deletions test/test_xreducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,14 +939,6 @@ namespace xt
EXPECT_EQ(b.dimension(), 0u);
EXPECT_EQ(minmax(b)(), (A{1.2, 1.2}));
}

template <std::size_t... I, std::size_t... J>
bool operator==(fixed_shape<I...>, fixed_shape<J...>)
{
std::array<std::size_t, sizeof...(I)> ix = {I...};
std::array<std::size_t, sizeof...(J)> jx = {J...};
return sizeof...(J) == sizeof...(I) && std::equal(ix.begin(), ix.end(), jx.begin());
}

TEST(xreducer, keep_dims)
{
Expand Down