Skip to content

Commit

Permalink
introduced TiledRange::is_congruent
Browse files Browse the repository at this point in the history
  • Loading branch information
evaleev committed Sep 13, 2024
1 parent 5cc3ce3 commit 2527e80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/TiledArray/tiled_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,19 @@ inline bool operator==(const TiledRange& r1, const TiledRange& r2) {
std::equal(r1.data().begin(), r1.data().end(), r2.data().begin());
}

/// Test that two TiledRange objects are congruent

/// Two tranges are congruent if one is a translation of another (i.e. their
/// ranks and extents of all tiles) agree \param r1 a TiledRange object \param
/// r2 a TiledRange object
inline bool is_congruent(const TiledRange& r1, const TiledRange& r2) {
return r1.rank() == r2.rank() &&
std::equal(r1.begin(), r1.end(), r2.begin(),
[](const auto& tr1_1, const auto& tr1_2) {
return is_congruent(tr1_1, tr1_2);
});
}

inline bool operator!=(const TiledRange& r1, const TiledRange& r2) {
return !operator==(r1, r2);
}
Expand Down
13 changes: 13 additions & 0 deletions tests/tiled_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,26 @@ BOOST_AUTO_TEST_CASE(comparison) {
TiledRange r1{{0, 2, 4, 6, 8, 10}, {0, 2, 4, 6, 8, 10}};
TiledRange r2{{0, 2, 4, 6, 8, 10}, {0, 2, 4, 6, 8, 10}};
TiledRange r3{{0, 3, 6, 9, 12, 15}, {0, 3, 6, 9, 12, 15}};
BOOST_CHECK(r1 == r1); // self-comparison
BOOST_CHECK(r1 == r2); // check equality operator
BOOST_CHECK(!(r1 != r2)); // check not-equal operator
BOOST_CHECK(
!(r1 == r3)); // check for inequality with different number of tiles.
BOOST_CHECK(r1 != r3);
}

BOOST_AUTO_TEST_CASE(congruency) {
TiledRange r1{{0, 2, 4, 6, 8, 10}, {0, 2, 4, 6, 8, 10}};
TiledRange r2{{1, 3, 5, 7, 9, 11}, {2, 4, 6, 8, 10, 12}};
TiledRange r3{{0, 3, 6, 9, 12, 15}, {0, 3, 6, 9, 12, 15}};
BOOST_CHECK(r1 == r1 && is_congruent(r1, r1)); // congruent with self
BOOST_CHECK(r1 != r2 &&
is_congruent(r1, r2)); // r1 and r2 are not equal but congruent
BOOST_CHECK(
r1 != r3 &&
!is_congruent(r1, r3)); // r1 and r3 are not equal and not congruent
}

BOOST_AUTO_TEST_CASE(assignment) {
TiledRange r1;

Expand Down

0 comments on commit 2527e80

Please sign in to comment.