Skip to content

Commit

Permalink
introduced member versions of TiledRange1::make_uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
evaleev committed Sep 16, 2024
1 parent 4d4c06b commit 057df5a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/TiledArray/tiled_range1.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,21 @@ class TiledRange1 {
return make_uniform(Range1(0, range_extent), target_tile_size);
}

/// same as make_uniform(const Range1&, std::size_t), using the element_range
/// of this TiledRange1
TiledRange1 make_uniform(std::size_t target_tile_size) const {
return make_uniform(this->elements_range(), target_tile_size);
}

/// make as uniformly-tiled range as possible out of this TiledRange1, with
/// the same number of tiles as this
TiledRange1 make_uniform() const {
return make_uniform(
this->elements_range(),
(this->elements_range().extent() + this->tile_extent() - 1) /
this->tile_extent());
}

/// shifts this TiledRange1

/// @param[in] shift the shift to apply
Expand Down
8 changes: 8 additions & 0 deletions tests/tiled_range1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ BOOST_AUTO_TEST_CASE(make_uniform) {
BOOST_REQUIRE_NO_THROW(TiledRange1::make_uniform(59, 10));
BOOST_CHECK(TiledRange1::make_uniform(59, 10) ==
(TiledRange1{0, 10, 20, 30, 40, 50, 59}));

// member versions
BOOST_REQUIRE_NO_THROW((TiledRange1{0, 10, 20, 30, 40, 50}.make_uniform(30)));
BOOST_CHECK((TiledRange1{0, 10, 20, 30, 40, 50}.make_uniform(30) ==
TiledRange1{0, 25, 50}));
BOOST_REQUIRE_NO_THROW((TiledRange1{0, 40, 50}.make_uniform()));
BOOST_CHECK(
(TiledRange1{0, 40, 50}.make_uniform() == TiledRange1{0, 25, 50}));
}

BOOST_AUTO_TEST_CASE(shift) {
Expand Down

0 comments on commit 057df5a

Please sign in to comment.