From c2769b81e61060004a6ad91ce5a65c02a345028c Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 8 Sep 2016 11:54:41 -0400 Subject: [PATCH] Move over from boost/random to c++11 random. --- vtkm/benchmarking/BenchmarkDeviceAdapter.cxx | 15 ++-- .../benchmarking/BenchmarkFieldAlgorithms.cxx | 75 ++++++------------- .../BenchmarkTopologyAlgorithms.cxx | 75 +++++++++---------- vtkm/exec/testing/UnitTestCellDerivative.cxx | 18 ++--- .../testing/UnitTestParametricCoordinates.cxx | 14 ++-- vtkm/testing/TestingImplicitFunctions.h | 10 +-- vtkm/testing/UnitTestTransform3D.cxx | 20 ++--- 7 files changed, 88 insertions(+), 139 deletions(-) diff --git a/vtkm/benchmarking/BenchmarkDeviceAdapter.cxx b/vtkm/benchmarking/BenchmarkDeviceAdapter.cxx index 7e412fbb3..ab5b49de0 100644 --- a/vtkm/benchmarking/BenchmarkDeviceAdapter.cxx +++ b/vtkm/benchmarking/BenchmarkDeviceAdapter.cxx @@ -33,17 +33,12 @@ #include #include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -VTKM_THIRDPARTY_POST_INCLUDE #include -#include #include -#include -#include -#include +#include #include +#include #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN @@ -167,7 +162,7 @@ private: ValueArrayHandle ValueHandle_src; ValueArrayHandle ValueHandle_dst; - boost::mt19937 Rng; + std::mt19937 Rng; VTKM_CONT_EXPORT BenchCopy(){ @@ -362,7 +357,7 @@ private: typedef vtkm::cont::ArrayHandle ValueArrayHandle; ValueArrayHandle ValueHandle; - boost::mt19937 Rng; + std::mt19937 Rng; VTKM_CONT_EXPORT BenchSort(){ @@ -392,7 +387,7 @@ private: struct BenchSortByKey { typedef vtkm::cont::ArrayHandle ValueArrayHandle; - boost::mt19937 Rng; + std::mt19937 Rng; vtkm::Id N_KEYS; ValueArrayHandle ValueHandle; IdArrayHandle KeyHandle; diff --git a/vtkm/benchmarking/BenchmarkFieldAlgorithms.cxx b/vtkm/benchmarking/BenchmarkFieldAlgorithms.cxx index 41c8fb7f2..6c9e037e4 100644 --- a/vtkm/benchmarking/BenchmarkFieldAlgorithms.cxx +++ b/vtkm/benchmarking/BenchmarkFieldAlgorithms.cxx @@ -34,10 +34,7 @@ #include #include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -VTKM_THIRDPARTY_POST_INCLUDE - +#include #include namespace vtkm { @@ -276,28 +273,19 @@ private: VTKM_CONT_EXPORT BenchBlackScholes() { - typedef boost::uniform_real ValueRange; - typedef boost::mt19937 MTGenerator; - typedef boost::variate_generator Generator; - - boost::mt19937 rng; - - boost::uniform_real price_range(Value(5.0f),Value(30.0f)); - boost::uniform_real strike_range(Value(1.0f),Value(100.0f)); - boost::uniform_real year_range(Value(0.25f),Value(10.0f)); - - Generator priceGenerator(rng, price_range); - Generator strikeGenerator(rng, strike_range); - Generator yearGenerator(rng, year_range); + std::mt19937 rng; + std::uniform_real_distribution price_range(Value(5.0f),Value(30.0f)); + std::uniform_real_distribution strike_range(Value(1.0f),Value(100.0f)); + std::uniform_real_distribution year_range(Value(0.25f),Value(10.0f)); this->price.resize(ARRAY_SIZE); this->strike.resize(ARRAY_SIZE); this->years.resize(ARRAY_SIZE); for(std::size_t i=0; i < ARRAY_SIZE; ++i ) { - this->price[i] = priceGenerator(); - this->strike[i] = strikeGenerator(); - this->years[i] = yearGenerator(); + this->price[i] = price_range(rng); + this->strike[i] = strike_range(rng); + this->years[i] = year_range(rng); } this->StockPrice = vtkm::cont::make_ArrayHandle(this->price); @@ -344,20 +332,15 @@ private: VTKM_CONT_EXPORT BenchMath() { - typedef boost::uniform_real ValueRange; - typedef boost::mt19937 MTGenerator; - typedef boost::variate_generator Generator; - - boost::mt19937 rng; - boost::uniform_real range; - Generator generator(rng, range); + std::mt19937 rng; + std::uniform_real_distribution range; this->input.resize(ARRAY_SIZE); for(std::size_t i=0; i < ARRAY_SIZE; ++i ) { - this->input[i] = vtkm::Vec(generator(), - generator(), - generator()); + this->input[i] = vtkm::Vec(range(rng), + range(rng), + range(rng)); } this->InputHandle = vtkm::cont::make_ArrayHandle(this->input); @@ -397,20 +380,15 @@ private: VTKM_CONT_EXPORT BenchFusedMath() { - typedef boost::uniform_real ValueRange; - typedef boost::mt19937 MTGenerator; - typedef boost::variate_generator Generator; - - boost::mt19937 rng; - boost::uniform_real range; - Generator generator(rng, range); + std::mt19937 rng; + std::uniform_real_distribution range; this->input.resize(ARRAY_SIZE); for(std::size_t i=0; i < ARRAY_SIZE; ++i ) { - this->input[i] = vtkm::Vec(generator(), - generator(), - generator()); + this->input[i] = vtkm::Vec(range(rng), + range(rng), + range(rng)); } this->InputHandle = vtkm::cont::make_ArrayHandle(this->input); @@ -448,16 +426,9 @@ private: VTKM_CONT_EXPORT BenchEdgeInterp() { - typedef boost::mt19937 MTGenerator; - typedef boost::variate_generator > Generator; - typedef boost::variate_generator > WGenerator; - - boost::mt19937 rng; - boost::uniform_real weight_range(0.0f,1.0f); - WGenerator wgenerator(rng, weight_range); - - boost::uniform_real field_range; - Generator fgenerator(rng, field_range); + std::mt19937 rng; + std::uniform_real_distribution weight_range(0.0f,1.0f); + std::uniform_real_distribution field_range; //basically the core challenge is to generate an array whose //indexing pattern matches that of a edge based algorithm. @@ -479,13 +450,13 @@ private: this->weight.resize( esize ); for(std::size_t i=0; i < esize; ++i ) { - this->weight[i] = wgenerator(); + this->weight[i] = weight_range(rng); } this->field.resize( psize ); for(std::size_t i=0; i < psize; ++i ) { - this->field[i] = fgenerator(); + this->field[i] = field_range(rng); } this->FieldHandle = vtkm::cont::make_ArrayHandle(this->field); diff --git a/vtkm/benchmarking/BenchmarkTopologyAlgorithms.cxx b/vtkm/benchmarking/BenchmarkTopologyAlgorithms.cxx index b2b5ca127..e3f14d31e 100644 --- a/vtkm/benchmarking/BenchmarkTopologyAlgorithms.cxx +++ b/vtkm/benchmarking/BenchmarkTopologyAlgorithms.cxx @@ -32,18 +32,7 @@ #include #include -#ifdef VTKM_MSVC -#pragma warning(disable:4723) -#endif - -VTKM_THIRDPARTY_PRE_INCLUDE -#include -VTKM_THIRDPARTY_POST_INCLUDE - -#ifdef VTKM_MSVC -#pragma warning(default:4723) -#endif - +#include #include namespace vtkm { @@ -166,6 +155,35 @@ class BenchmarkTopologyAlgorithms { private: + template struct NumberGenerator {}; + + template + struct NumberGenerator::value + >::type + > + { + std::mt19937 rng; + std::uniform_real_distribution distribution; + NumberGenerator(T low, T high): rng(), distribution(low,high) {} + T next() { return distribution(rng); } + }; + + template + struct NumberGenerator::value + >::type + > + { + std::mt19937 rng; + std::uniform_int_distribution distribution; + + NumberGenerator(T low, T high): rng(), distribution(low,high) {} + T next() { return distribution(rng); } + }; + template struct BenchCellToPointAvg { std::vector< Value > input; @@ -174,21 +192,14 @@ private: VTKM_CONT_EXPORT BenchCellToPointAvg() { - typedef boost::uniform_real ValueRange; - typedef boost::mt19937 MTGenerator; - typedef boost::variate_generator Generator; - - boost::mt19937 rng; - boost::uniform_real range(static_cast(1.0), + NumberGenerator generator(static_cast(1.0), static_cast(100.0)); - Generator generator(rng, range); - //cube size is points in each dim const std::size_t csize = (CUBE_SIZE-1)*(CUBE_SIZE-1)*(CUBE_SIZE-1); this->input.resize( csize ); for(std::size_t i=0; i < csize; ++i ) { - this->input[i] = generator(); + this->input[i] = generator.next(); } this->InputHandle = vtkm::cont::make_ArrayHandle(this->input); } @@ -229,20 +240,14 @@ private: VTKM_CONT_EXPORT BenchPointToCellAvg() { - typedef boost::uniform_real ValueRange; - typedef boost::mt19937 MTGenerator; - typedef boost::variate_generator Generator; - - boost::mt19937 rng; - boost::uniform_real range(static_cast(1.0), + NumberGenerator generator(static_cast(1.0), static_cast(100.0)); - Generator generator(rng, range); const std::size_t psize = (CUBE_SIZE)*(CUBE_SIZE)*(CUBE_SIZE); this->input.resize( psize ); for(std::size_t i=0; i < psize; ++i ) { - this->input[i] = generator(); + this->input[i] = generator.next(); } this->InputHandle = vtkm::cont::make_ArrayHandle(this->input); } @@ -284,23 +289,17 @@ private: VTKM_CONT_EXPORT BenchClassification() { - typedef boost::uniform_real ValueRange; - typedef boost::mt19937 MTGenerator; - typedef boost::variate_generator Generator; - - boost::mt19937 rng; - boost::uniform_real range(static_cast(1.0), + NumberGenerator generator(static_cast(1.0), static_cast(100.0)); - Generator generator(rng, range); const std::size_t psize = (CUBE_SIZE)*(CUBE_SIZE)*(CUBE_SIZE); this->input.resize( psize ); for(std::size_t i=0; i < psize; ++i ) { - this->input[i] = generator(); + this->input[i] = generator.next(); } this->InputHandle = vtkm::cont::make_ArrayHandle(this->input); - this->IsoValue = generator(); + this->IsoValue = generator.next(); } VTKM_CONT_EXPORT diff --git a/vtkm/exec/testing/UnitTestCellDerivative.cxx b/vtkm/exec/testing/UnitTestCellDerivative.cxx index 63bcc257b..c46614985 100644 --- a/vtkm/exec/testing/UnitTestCellDerivative.cxx +++ b/vtkm/exec/testing/UnitTestCellDerivative.cxx @@ -29,16 +29,12 @@ #include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -#include -VTKM_THIRDPARTY_POST_INCLUDE - -#include +#include +#include namespace { -boost::mt19937 g_RandomGenerator; +std::mt19937 g_RandomGenerator; // Establish simple mapping between world and parametric coordinates. // Actuall world/parametric coordinates are in a different test. @@ -118,7 +114,7 @@ struct TestDerivativeFunctor std::cout << " Expected: " << expectedGradient << std::endl; - boost::random::uniform_real_distribution randomDist; + std::uniform_real_distribution randomDist; for (vtkm::IdComponent trial = 0; trial < 5; trial++) { @@ -230,7 +226,7 @@ struct TestDerivativeFunctor this->DoTest(shape, numPoints, field, expectedGradient); std::cout << "Random linear field, " << numPoints << " points" << std::endl; - boost::random::uniform_real_distribution randomDist(-20.0, 20.0); + std::uniform_real_distribution randomDist(-20.0, 20.0); field.OriginValue = randomDist(g_RandomGenerator); field.Gradient = vtkm::make_Vec(randomDist(g_RandomGenerator), randomDist(g_RandomGenerator), @@ -281,7 +277,7 @@ struct TestDerivativeFunctor void TestDerivative() { - vtkm::UInt32 seed = static_cast(time(NULL)); + vtkm::UInt32 seed = static_cast(std::time(NULL)); std::cout << "Seed: " << seed << std::endl; g_RandomGenerator.seed(seed); @@ -290,7 +286,7 @@ void TestDerivative() std::cout << "======== Float64 ==========================" << std::endl; vtkm::testing::Testing::TryAllCellShapes(TestDerivativeFunctor()); - boost::random::uniform_real_distribution randomDist(-20.0, 20.0); + std::uniform_real_distribution randomDist(-20.0, 20.0); LinearField field; field.OriginValue = randomDist(g_RandomGenerator); field.Gradient = vtkm::make_Vec(randomDist(g_RandomGenerator), diff --git a/vtkm/exec/testing/UnitTestParametricCoordinates.cxx b/vtkm/exec/testing/UnitTestParametricCoordinates.cxx index 0cb29ec4a..06fce4cc3 100644 --- a/vtkm/exec/testing/UnitTestParametricCoordinates.cxx +++ b/vtkm/exec/testing/UnitTestParametricCoordinates.cxx @@ -27,16 +27,12 @@ #include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -#include -VTKM_THIRDPARTY_POST_INCLUDE - #include +#include namespace { -boost::mt19937 g_RandomGenerator; +std::mt19937 g_RandomGenerator; static const vtkm::IdComponent MAX_POINTS = 8; @@ -156,7 +152,7 @@ void TestPCoordsSample(const PointWCoordsType &pointWCoords, const vtkm::IdComponent numPoints = pointWCoords.GetNumberOfComponents(); - boost::random::uniform_real_distribution randomDist; + std::uniform_real_distribution randomDist; for (vtkm::IdComponent trial = 0; trial < 5; trial++) { @@ -226,7 +222,7 @@ struct TestPCoordsFunctor vtkm::exec::FunctorBase workletProxy; workletProxy.SetErrorMessageBuffer(errorMessage); - boost::random::uniform_real_distribution randomDist(-1,1); + std::uniform_real_distribution randomDist(-1,1); Vector3 sheerVec(randomDist(g_RandomGenerator), randomDist(g_RandomGenerator), @@ -297,7 +293,7 @@ void TestAllPCoords() vtkm::testing::Testing::TryAllCellShapes(TestPCoordsFunctor()); std::cout << "======== Rectilinear Shapes ===============" << std::endl; - boost::random::uniform_real_distribution randomDist(0.01f,1.0f); + std::uniform_real_distribution randomDist(0.01f,1.0f); vtkm::Vec origin(randomDist(g_RandomGenerator), randomDist(g_RandomGenerator), randomDist(g_RandomGenerator)); diff --git a/vtkm/testing/TestingImplicitFunctions.h b/vtkm/testing/TestingImplicitFunctions.h index d4c7171b3..6b479a80e 100644 --- a/vtkm/testing/TestingImplicitFunctions.h +++ b/vtkm/testing/TestingImplicitFunctions.h @@ -30,11 +30,7 @@ #include #include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -#include -VTKM_THIRDPARTY_POST_INCLUDE - +#include namespace vtkm { namespace testing { @@ -43,8 +39,8 @@ namespace { inline vtkm::FloatDefault GetRandomValue() { - static boost::random::mt19937 gen; - boost::random::uniform_real_distribution dist(-7.0, 7.0); + static std::mt19937 gen; + std::uniform_real_distribution dist(-7.0, 7.0); return dist(gen); } diff --git a/vtkm/testing/UnitTestTransform3D.cxx b/vtkm/testing/UnitTestTransform3D.cxx index bcede2ad8..cf1abf627 100644 --- a/vtkm/testing/UnitTestTransform3D.cxx +++ b/vtkm/testing/UnitTestTransform3D.cxx @@ -24,36 +24,32 @@ #include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -#include -VTKM_THIRDPARTY_POST_INCLUDE - #include +#include namespace { -boost::mt19937 g_RandomGenerator; +std::mt19937 g_RandomGenerator; template struct TransformTests { - boost::random::uniform_real_distribution RandomDistribution; + std::uniform_real_distribution RandomDistribution; TransformTests() : RandomDistribution(0.0f, 1.0f) { } - T RandomNum() const { return this->RandomDistribution(g_RandomGenerator); } + T RandomNum() { return this->RandomDistribution(g_RandomGenerator); } typedef vtkm::Vec Vec; typedef vtkm::Matrix Transform; - Vec RandomVector() const + Vec RandomVector() { Vec vec(this->RandomNum(), this->RandomNum(), this->RandomNum()); return T(2)*vec - Vec(1); } - void CheckTranslate() const + void CheckTranslate() { std::cout << "--- Checking translate" << std::endl; @@ -81,7 +77,7 @@ struct TransformTests VTKM_TEST_ASSERT(test_equal(translated1, startPoint), "Bad translation."); } - void CheckScale() const + void CheckScale() { std::cout << "--- Checking scale" << std::endl; @@ -110,7 +106,7 @@ struct TransformTests "Bad scale."); } - void CheckRotate() const + void CheckRotate() { std::cout << "--- Checking rotate" << std::endl;