Skip to content

Commit b738658

Browse files
committed
Refactor checksum implementation in the test
1 parent 677bae1 commit b738658

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

FlexLabel/test/testFlexLabel.cxx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,11 @@ Eigen::Matrix4Xf readPqr(const std::string &fName)
7878

7979
float checksum(const Grid3D &grid)
8080
{
81-
float sum = grid.discStep * grid.grid.size();
82-
for (int i = 0; i < 3; ++i) {
83-
sum += grid.originXYZ[i] + grid.shape[i];
84-
}
85-
for (const float &v : grid.grid) {
86-
sum += v;
87-
}
88-
return sum;
81+
using std::accumulate;
82+
return grid.discStep * grid.grid.size()
83+
+ accumulate(grid.originXYZ.begin(), grid.originXYZ.end(), 0.0f)
84+
+ accumulate(grid.shape.begin(), grid.shape.end(), 0)
85+
+ accumulate(grid.grid.begin(), grid.grid.end(), 0.0f);
8986
}
9087

9188
void printDistanceHist(const std::vector<float> &distances)
@@ -138,7 +135,6 @@ int main()
138135
atoms.col(iat) = atoms.col(10);
139136
}
140137

141-
142138
/*atoms= readPqr("short_helix.pqr");
143139
atoms(3, 56) = 0.0f; //remove the attachment atom itself
144140
source = atoms.col(56).head<3>();*/
@@ -152,7 +148,7 @@ int main()
152148
Grid3D grid = minLinkerLength(atoms, source, linkerL, linkerD, dyeR,
153149
discStep);
154150
// savePqr("testMinL.pqr", grid);
155-
if (fabs(checksum(grid) - 667073.62500f) > 0.00001f) {
151+
if (fabs(checksum(grid) - 667076.87500f) > 0.00001f) {
156152
cout << "minLinkerLength() produced an unexpected result\n";
157153
cout << "checksum = " << std::setprecision(5) << std::fixed
158154
<< checksum(grid) << endl;
@@ -167,7 +163,7 @@ int main()
167163
cout << "AV1 calculation took: " << dtMs << " ms" << endl;
168164
// savePqr("testDensityAV1.pqr", grid);
169165

170-
if (fabs(checksum(grid) - 50183.00000f) > 0.00001f) {
166+
if (fabs(checksum(grid) - 50182.99219f) > 0.00001f) {
171167
cout << "dyeDensity() AV1 produced an unexpected result\n";
172168
cout << "checksum = " << std::setprecision(5) << std::fixed
173169
<< checksum(grid) << endl;
@@ -194,7 +190,7 @@ int main()
194190
// Takes 16 ms on a Core i7-4930K CPU
195191
cout << "AV3 calculation took: " << dtMs << " ms" << endl;
196192
// savePqr("testDensityAV3.pqr", grid);
197-
if (fabs(checksum(grid) - 49989.75391f) > 0.00001f) {
193+
if (fabs(checksum(grid) - 49991.96094f) > 0.00001f) {
198194
cout << "dyeDensity() AV3 produced an unexpected result\n";
199195
cout << "checksum = " << std::setprecision(5) << std::fixed
200196
<< checksum(grid) << endl;
@@ -216,7 +212,7 @@ int main()
216212
// Takes 4.5 ms on a Core i7-4930K CPU
217213
cout << "addWeights took: " << dtMs << " ms " << endl;
218214
// savePqr("testContactDensityAV3.pqr", grid);
219-
if (fabs(checksum(grid) - 117905.71875f) > 0.00001f) {
215+
if (fabs(checksum(grid) - 117907.15625f) > 0.00001f) {
220216
cout << "addWeights() produced an unexpected result\n";
221217
cout << "checksum = " << std::setprecision(5) << std::fixed
222218
<< checksum(grid) << endl;

0 commit comments

Comments
 (0)