Skip to content

Commit 4eecc73

Browse files
committed
Minor fix. Some wierd behavior observed in conda environment,
but it was due to a mixture of system library and conda library. Clean installation of conda env and alamode solved the issue.
1 parent f64ffd7 commit 4eecc73

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

alm/cluster.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,32 +161,30 @@ void Cluster::init(const std::unique_ptr<System> &system, const std::unique_ptr<
161161
void Cluster::generate_unique_clusters(const size_t natmin, const std::vector<std::vector<int>> &map_p2s,
162162
std::vector<std::set<IntList>> &cluster_out) const
163163
{
164-
int *pair_tmp;
164+
std::vector<int> pair_vec;
165165

166166
for (auto order = 0; order < maxorder; ++order) {
167167

168168
cluster_out[order].clear();
169169

170-
allocate(pair_tmp, order + 2);
170+
pair_vec.resize(order + 2);
171171

172172
for (size_t i = 0; i < natmin; ++i) {
173173

174174
const auto iat = map_p2s[i][0];
175175

176176
for (const auto &it: interaction_cluster[order][i]) {
177177

178-
pair_tmp[0] = iat;
178+
pair_vec[0] = iat;
179179
for (auto j = 0; j < order + 1; ++j) {
180-
pair_tmp[j + 1] = it.atom[j];
180+
pair_vec[j + 1] = it.atom[j];
181181
}
182-
insort(order + 2, pair_tmp);
183182

184-
// Ignore many-body case
185-
// if (!satisfy_nbody_rule(order + 2, pair_tmp, order)) continue;
186-
cluster_out[order].insert(IntList(order + 2, pair_tmp));
183+
// Use std::sort for deterministic, stable ordering across platforms
184+
std::sort(pair_vec.begin(), pair_vec.end());
185+
cluster_out[order].insert(IntList(pair_vec));
187186
}
188187
}
189-
deallocate(pair_tmp);
190188
}
191189
}
192190

alm/cluster.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,24 @@ class IntList
4545
}
4646
}
4747

48+
// Constructor from std::vector for modern C++ style
49+
explicit IntList(const std::vector<int> &vec) : iarray(vec)
50+
{}
51+
explicit IntList(std::vector<int> &&vec) : iarray(std::move(vec))
52+
{}
53+
4854
auto operator<(const IntList &a) const -> bool
4955
{
5056
return std::lexicographical_compare(iarray.begin(), iarray.end(), a.iarray.begin(), a.iarray.end());
5157
}
5258

5359
auto operator==(const IntList &a) const -> bool
5460
{
55-
const auto n = iarray.size();
56-
const auto n_ = a.iarray.size();
57-
if (n != n_) return false;
58-
for (size_t i = 0; i < n; ++i) {
59-
if (iarray[i] != a.iarray[i]) return false;
60-
}
61-
return true;
61+
// Use vector's built-in equality operator for consistency
62+
// This is required for std::unordered_set<IntList> in fcs.cpp
63+
// and ensures consistent behavior across platforms
64+
// std::cout << "== operator called\n";
65+
return iarray == a.iarray;
6266
}
6367
};
6468

0 commit comments

Comments
 (0)