Skip to content

Commit

Permalink
don't count identity transform as success
Browse files Browse the repository at this point in the history
  • Loading branch information
bencwallace committed Dec 14, 2024
1 parent 690b295 commit a828ff4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/include/lattice.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ template <int Dim> class transform {
*/
box<Dim> operator*(const box<Dim> &b) const;

/** @brief Returns true if the transform is the identity. */
bool is_identity() const;

/**
* @brief Returns the inverse transform.
*
Expand Down
9 changes: 9 additions & 0 deletions src/lattice/transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ template <int Dim> box<Dim> transform<Dim>::operator*(const box<Dim> &b) const {
return box<Dim>(intervals);
}

template <int Dim> bool transform<Dim>::is_identity() const {
for (int i = 0; i < Dim; ++i) {
if (perm_[i] != i || signs_[i] != 1) {
return false;
}
}
return true;
}

template <int Dim> transform<Dim> transform<Dim>::inverse() const {
std::array<int, Dim> perm;
std::array<int, Dim> signs;
Expand Down
4 changes: 4 additions & 0 deletions src/walks/walk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ walk<Dim>::walk(int num_steps, std::optional<unsigned int> seed)

template <int Dim>
std::optional<std::vector<point<Dim>>> walk<Dim>::try_pivot(int step, const transform<Dim> &trans) const {
if (trans.is_identity()) {
return {};
}

std::vector<point<Dim>> new_points(num_steps() - step - 1);
for (int i = step + 1; i < num_steps(); ++i) {
auto q = pivot_point(step, i, trans);
Expand Down
8 changes: 8 additions & 0 deletions src/walks/walk_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ template <int Dim> walk_node<Dim> &walk_tree<Dim>::find_node(int n) {
/* HIGH-LEVEL FUNCTIONS */

template <int Dim> bool walk_tree<Dim>::try_pivot(int n, const transform<Dim> &r) {
if (r.is_identity()) {
return false;
}

root_->shuffle_up(n);
auto root_symm = root_->symm_;
root_->symm_ = root_->symm_ * r;
Expand All @@ -95,6 +99,10 @@ template <int Dim> bool walk_tree<Dim>::try_pivot(int n, const transform<Dim> &r
}

template <int Dim> bool walk_tree<Dim>::try_pivot_fast(int n, const transform<Dim> &t) {
if (t.is_identity()) {
return false;
}

walk_node<Dim> *w = &find_node(n); // TODO: a pointer seems to be needed, but why?
walk_node<Dim> w_copy(*w);
auto success = !w_copy.shuffle_intersect(t, w->is_left_child());
Expand Down

0 comments on commit a828ff4

Please sign in to comment.