From a06c676857c8c0364bb06fc8862681a04cdf2b13 Mon Sep 17 00:00:00 2001 From: Jan Domanski Date: Wed, 4 Nov 2020 18:43:37 +0000 Subject: [PATCH] Address review comments --- regtest/core/rt-make-value/main.cpp | 4 +- regtest/tools/rt-make-angle/main.cpp | 12 ++-- regtest/tools/rt-make-grid/main.cpp | 1 + .../tools/rt-make-lattice-reduction/main.cpp | 8 +-- regtest/tools/rt-make-random/main.cpp | 69 ++++++++++++------- regtest/tools/rt-make-random/output.reference | 12 ++-- src/ves/TargetDistribution.cpp | 1 - 7 files changed, 67 insertions(+), 40 deletions(-) diff --git a/regtest/core/rt-make-value/main.cpp b/regtest/core/rt-make-value/main.cpp index a3749c0334..80fe0390a6 100644 --- a/regtest/core/rt-make-value/main.cpp +++ b/regtest/core/rt-make-value/main.cpp @@ -11,14 +11,14 @@ using namespace PLMD; int testConstructor(std::ofstream &ofs) { ofs << "testConstructor" << std::endl; - Value *value = new Value(); + std::unique_ptr value (new Value()); ofs << value->get() << std::endl; return 0; } int testConstructorWithName(std::ofstream &ofs) { ofs << "testConstructorWithName" << std::endl; - Value *value = new Value("name"); + std::unique_ptr value (new Value()); ofs << value->get() << std::endl; return 0; } diff --git a/regtest/tools/rt-make-angle/main.cpp b/regtest/tools/rt-make-angle/main.cpp index 576b13cb9f..51dc1ecc28 100644 --- a/regtest/tools/rt-make-angle/main.cpp +++ b/regtest/tools/rt-make-angle/main.cpp @@ -33,8 +33,8 @@ int testCompute4Vectors45Degrees(std::ofstream &ofs) { Angle angle; double result = angle.compute(vector1, vector2, d1, d2); ofs << result << std::endl; - ofs << d1[0] << " " << d1[1] << " " << d1[2] << std::endl; - ofs << d2[0] << " " << d2[1] << " " << d2[2] << std::endl; + ofs << d1 << std::endl; + ofs << d2 << std::endl; return 0; } @@ -46,8 +46,8 @@ int testCompute4VectorsParallel(std::ofstream &ofs) { Angle angle; double result = angle.compute(vector1, vector2, d1, d2); ofs << result << std::endl; - ofs << d1[0] << " " << d1[1] << " " << d1[2] << std::endl; - ofs << d2[0] << " " << d2[1] << " " << d2[2] << std::endl; + ofs << d1 << std::endl; + ofs << d2 << std::endl; return 0; } @@ -59,8 +59,8 @@ int testCompute4VectorsAntiParallel(std::ofstream &ofs) { Angle angle; double result = angle.compute(vector1, vector2, d1, d2); ofs << result << std::endl; - ofs << d1[0] << " " << d1[1] << " " << d1[2] << std::endl; - ofs << d2[0] << " " << d2[1] << " " << d2[2] << std::endl; + ofs << d1 << std::endl; + ofs << d2 << std::endl; return 0; } diff --git a/regtest/tools/rt-make-grid/main.cpp b/regtest/tools/rt-make-grid/main.cpp index 6797f11412..bf46163edf 100644 --- a/regtest/tools/rt-make-grid/main.cpp +++ b/regtest/tools/rt-make-grid/main.cpp @@ -15,6 +15,7 @@ std::unique_ptr createGrid() { const std::vector grid_args_ = {value}; std::unique_ptr gridBase = GridBase::create( "external.bias", grid_args_, gridfile, false, false, false); + delete value; return gridBase; } diff --git a/regtest/tools/rt-make-lattice-reduction/main.cpp b/regtest/tools/rt-make-lattice-reduction/main.cpp index dadfad45d4..3f3ec41816 100644 --- a/regtest/tools/rt-make-lattice-reduction/main.cpp +++ b/regtest/tools/rt-make-lattice-reduction/main.cpp @@ -7,7 +7,7 @@ using namespace PLMD; int testReduce(std::ofstream &ofs) { ofs << "testReduce2" << std::endl; - Tensor *tensor = new Tensor(1.0, 2.0, 3.0, 5.0, 4.0, 3.0, 10.0, 8.0, 2.0); + std::unique_ptr tensor (new Tensor(1.0, 2.0, 3.0, 5.0, 4.0, 3.0, 10.0, 8.0, 2.0)); LatticeReduction::reduce(*tensor); ofs << tensor->getRow(0)[0] << " " << tensor->getRow(0)[1] << " " << tensor->getRow(0)[2] << std::endl; ofs << tensor->getRow(1)[0] << " " << tensor->getRow(1)[1] << " " << tensor->getRow(1)[2] << std::endl; @@ -17,7 +17,7 @@ int testReduce(std::ofstream &ofs) { int testReduceSlow(std::ofstream &ofs) { ofs << "testReduceSlow" << std::endl; - Tensor *tensor = new Tensor(1.0, 2.0, 3.0, 5.0, 4.0, 3.0, 10.0, 8.0, 2.0); + std::unique_ptr tensor (new Tensor(1.0, 2.0, 3.0, 5.0, 4.0, 3.0, 10.0, 8.0, 2.0)); LatticeReduction::reduceSlow(*tensor); ofs << tensor->getRow(0)[0] << " " << tensor->getRow(0)[1] << " " << tensor->getRow(0)[2] << std::endl; ofs << tensor->getRow(1)[0] << " " << tensor->getRow(1)[1] << " " << tensor->getRow(1)[2] << std::endl; @@ -27,7 +27,7 @@ int testReduceSlow(std::ofstream &ofs) { int testReduceFast(std::ofstream &ofs) { ofs << "testReduceFast" << std::endl; - Tensor *tensor = new Tensor(1.0, 2.0, 3.0, 5.0, 4.0, 3.0, 10.0, 8.0, 2.0); + std::unique_ptr tensor (new Tensor(1.0, 2.0, 3.0, 5.0, 4.0, 3.0, 10.0, 8.0, 2.0)); LatticeReduction::reduceFast(*tensor); ofs << tensor->getRow(0)[0] << " " << tensor->getRow(0)[1] << " " << tensor->getRow(0)[2] << std::endl; ofs << tensor->getRow(1)[0] << " " << tensor->getRow(1)[1] << " " << tensor->getRow(1)[2] << std::endl; @@ -37,7 +37,7 @@ int testReduceFast(std::ofstream &ofs) { int testIsReduced(std::ofstream &ofs) { ofs << "testIsReduced" << std::endl; - Tensor *tensor = new Tensor(1.0, 2.0, 3.0, 5.0, 4.0, 3.0, 10.0, 8.0, 2.0); + std::unique_ptr tensor (new Tensor(1.0, 2.0, 3.0, 5.0, 4.0, 3.0, 10.0, 8.0, 2.0)); bool result1 = LatticeReduction::isReduced(*tensor); ofs << result1 << std::endl; LatticeReduction::reduce(*tensor); diff --git a/regtest/tools/rt-make-random/main.cpp b/regtest/tools/rt-make-random/main.cpp index efb7b5fc67..3f24bd3c03 100644 --- a/regtest/tools/rt-make-random/main.cpp +++ b/regtest/tools/rt-make-random/main.cpp @@ -13,61 +13,82 @@ int testConstructor(std::ofstream &ofs) { int testRandU01(std::ofstream &ofs) { ofs << "testRandU01" << std::endl; - Random *random = new Random("random"); - ofs << random->RandU01() << std::endl; - random->IncreasedPrecis(true); - ofs << random->RandU01() << std::endl; + Random random("random"); + ofs << random.RandU01() << std::endl; + random.IncreasedPrecis(true); + ofs << random.RandU01() << std::endl; return 0; } int testU01d(std::ofstream &ofs) { ofs << "testU01d" << std::endl; - Random *random = new Random("random"); - ofs << random->U01d() << std::endl; + Random random("random"); + ofs << random.U01d() << std::endl; return 0; } int testU01(std::ofstream &ofs) { ofs << "testU01" << std::endl; - Random *random = new Random("random"); - ofs << random->U01() << std::endl; + Random random("random"); + ofs << random.U01() << std::endl; return 0; } int testWriteStateFull(std::ofstream &ofs) { ofs << "testWriteStateFull" << std::endl; - Random *random = new Random("random"); - random->WriteStateFull(ofs); + Random random("random"); + random.WriteStateFull(ofs); return 0; } -int testString(std::ofstream &ofs) { - ofs << "testString" << std::endl; - Random *random = new Random("random"); +int testStringSimple(std::ofstream &ofs) { + ofs << "testStringSimple" << std::endl; + Random random("random"); std::string str = ""; - random->toString(str); + random.U01(); + random.toString(str); ofs << str << std::endl; - random->fromString(str); + random.fromString(str); + return 0; +} + +int testStringComplex(std::ofstream &ofs) { + ofs << "testStringComplex" << std::endl; + Random random("random"); + std::string str = ""; + random.toString(str); + ofs << str << std::endl; + random.fromString(str); return 0; } int testGaussian(std::ofstream &ofs) { ofs << "testGaussian" << std::endl; - Random *random = new Random("random"); - double result = random->Gaussian(); + Random random("random"); + double result = random.Gaussian(); ofs << result << std::endl; return 0; } -int testShuffle(std::ofstream &ofs) { - ofs << "testShuffle" << std::endl; - Random *random = new Random("random"); +int testShuffleSimple(std::ofstream &ofs) { + ofs << "testShuffleSimple" << std::endl; + Random random("random"); std::vector vector = {1, 2}; - random->Shuffle(vector); + random.Shuffle(vector); ofs << vector[0] << " " << vector[1] << std::endl; return 0; } +int testShuffleComplex(std::ofstream &ofs) { + ofs << "testShuffleComplex" << std::endl; + Random random("random"); + std::vector vector = {1, 2, 3, 4}; + random.Shuffle(vector); + ofs << vector[0] << " " << vector[1] << " " << vector[2] << " " << vector[3] << std::endl; + return 0; +} + + int main() { std::ofstream ofs("output"); testConstructor(ofs); @@ -75,8 +96,10 @@ int main() { testU01d(ofs); testU01(ofs); testWriteStateFull(ofs); - testString(ofs); + testStringSimple(ofs); + testStringComplex(ofs); testGaussian(ofs); - testShuffle(ofs); + testShuffleSimple(ofs); + testShuffleComplex(ofs); return 0; } diff --git a/regtest/tools/rt-make-random/output.reference b/regtest/tools/rt-make-random/output.reference index cff42b55a7..0691da6f42 100644 --- a/regtest/tools/rt-make-random/output.reference +++ b/regtest/tools/rt-make-random/output.reference @@ -8,10 +8,14 @@ testU01 0.415999 testWriteStateFull random -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -testString -0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0 +0 0 0 2128236579 1624379149 1358580979 704877633 1580723810 101929267 563613512 1636807826 1954899097 1505795335 530511967 1404280278 197493099 1131570933 1817129560 1998097157 1264817709 1474833169 896544303 143542612 823378840 16531729 1441282327 1137522503 114807987 74243042 1784484492 1115438165 823564440 2007237709 1458777923 0 0 +testStringSimple +530511967|893351816|784558821|2128236579|1624379149|1358580979|704877633|1580723810|101929267|563613512|1636807826|1954899097|1505795335|530511967|1404280278|197493099|1131570933|1817129560|1998097157|1264817709|1474833169|896544303|143542612|823378840|16531729|1441282327|1137522503|114807987|74243042|1784484492|1115438165|823564440|2007237709|1458777923 +testStringComplex +0|0|0|2128236579|1624379149|1358580979|704877633|1580723810|101929267|563613512|1636807826|1954899097|1505795335|530511967|1404280278|197493099|1131570933|1817129560|1998097157|1264817709|1474833169|896544303|143542612|823378840|16531729|1441282327|1137522503|114807987|74243042|1784484492|1115438165|823564440|2007237709|1458777923 testGaussian -0.836854 -testShuffle +testShuffleSimple 2 1 +testShuffleComplex +4 1 2 3 diff --git a/src/ves/TargetDistribution.cpp b/src/ves/TargetDistribution.cpp index 86df61f8e5..ed4f904e69 100644 --- a/src/ves/TargetDistribution.cpp +++ b/src/ves/TargetDistribution.cpp @@ -33,7 +33,6 @@ #include "tools/Keywords.h" #include "GridProjWeights.h" -#include namespace PLMD { namespace ves {