Skip to content

Commit

Permalink
Refactor checksum implementation in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
mdimura committed Oct 9, 2019
1 parent 677bae1 commit b738658
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions FlexLabel/test/testFlexLabel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,11 @@ Eigen::Matrix4Xf readPqr(const std::string &fName)

float checksum(const Grid3D &grid)
{
float sum = grid.discStep * grid.grid.size();
for (int i = 0; i < 3; ++i) {
sum += grid.originXYZ[i] + grid.shape[i];
}
for (const float &v : grid.grid) {
sum += v;
}
return sum;
using std::accumulate;
return grid.discStep * grid.grid.size()
+ accumulate(grid.originXYZ.begin(), grid.originXYZ.end(), 0.0f)
+ accumulate(grid.shape.begin(), grid.shape.end(), 0)
+ accumulate(grid.grid.begin(), grid.grid.end(), 0.0f);
}

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


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

if (fabs(checksum(grid) - 50183.00000f) > 0.00001f) {
if (fabs(checksum(grid) - 50182.99219f) > 0.00001f) {
cout << "dyeDensity() AV1 produced an unexpected result\n";
cout << "checksum = " << std::setprecision(5) << std::fixed
<< checksum(grid) << endl;
Expand All @@ -194,7 +190,7 @@ int main()
// Takes 16 ms on a Core i7-4930K CPU
cout << "AV3 calculation took: " << dtMs << " ms" << endl;
// savePqr("testDensityAV3.pqr", grid);
if (fabs(checksum(grid) - 49989.75391f) > 0.00001f) {
if (fabs(checksum(grid) - 49991.96094f) > 0.00001f) {
cout << "dyeDensity() AV3 produced an unexpected result\n";
cout << "checksum = " << std::setprecision(5) << std::fixed
<< checksum(grid) << endl;
Expand All @@ -216,7 +212,7 @@ int main()
// Takes 4.5 ms on a Core i7-4930K CPU
cout << "addWeights took: " << dtMs << " ms " << endl;
// savePqr("testContactDensityAV3.pqr", grid);
if (fabs(checksum(grid) - 117905.71875f) > 0.00001f) {
if (fabs(checksum(grid) - 117907.15625f) > 0.00001f) {
cout << "addWeights() produced an unexpected result\n";
cout << "checksum = " << std::setprecision(5) << std::fixed
<< checksum(grid) << endl;
Expand Down

0 comments on commit b738658

Please sign in to comment.