mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Move over from boost/random to c++11 random.
This commit is contained in:
parent
e5967cfca8
commit
c2769b81e6
@ -33,17 +33,12 @@
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/benchmarking/Benchmarker.h>
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/random.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#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<Value, StorageTag> ValueArrayHandle;
|
||||
|
||||
ValueArrayHandle ValueHandle;
|
||||
boost::mt19937 Rng;
|
||||
std::mt19937 Rng;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
BenchSort(){
|
||||
@ -392,7 +387,7 @@ private:
|
||||
struct BenchSortByKey {
|
||||
typedef vtkm::cont::ArrayHandle<Value, StorageTag> ValueArrayHandle;
|
||||
|
||||
boost::mt19937 Rng;
|
||||
std::mt19937 Rng;
|
||||
vtkm::Id N_KEYS;
|
||||
ValueArrayHandle ValueHandle;
|
||||
IdArrayHandle KeyHandle;
|
||||
|
@ -34,10 +34,7 @@
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/benchmarking/Benchmarker.h>
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/random.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
namespace vtkm {
|
||||
@ -276,28 +273,19 @@ private:
|
||||
VTKM_CONT_EXPORT
|
||||
BenchBlackScholes()
|
||||
{
|
||||
typedef boost::uniform_real<Value> ValueRange;
|
||||
typedef boost::mt19937 MTGenerator;
|
||||
typedef boost::variate_generator<MTGenerator&, ValueRange> Generator;
|
||||
|
||||
boost::mt19937 rng;
|
||||
|
||||
boost::uniform_real<Value> price_range(Value(5.0f),Value(30.0f));
|
||||
boost::uniform_real<Value> strike_range(Value(1.0f),Value(100.0f));
|
||||
boost::uniform_real<Value> 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<Value> price_range(Value(5.0f),Value(30.0f));
|
||||
std::uniform_real_distribution<Value> strike_range(Value(1.0f),Value(100.0f));
|
||||
std::uniform_real_distribution<Value> 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<Value> ValueRange;
|
||||
typedef boost::mt19937 MTGenerator;
|
||||
typedef boost::variate_generator<MTGenerator&, ValueRange> Generator;
|
||||
|
||||
boost::mt19937 rng;
|
||||
boost::uniform_real<Value> range;
|
||||
Generator generator(rng, range);
|
||||
std::mt19937 rng;
|
||||
std::uniform_real_distribution<Value> range;
|
||||
|
||||
this->input.resize(ARRAY_SIZE);
|
||||
for(std::size_t i=0; i < ARRAY_SIZE; ++i )
|
||||
{
|
||||
this->input[i] = vtkm::Vec<Value, 3>(generator(),
|
||||
generator(),
|
||||
generator());
|
||||
this->input[i] = vtkm::Vec<Value, 3>(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<Value> ValueRange;
|
||||
typedef boost::mt19937 MTGenerator;
|
||||
typedef boost::variate_generator<MTGenerator&, ValueRange> Generator;
|
||||
|
||||
boost::mt19937 rng;
|
||||
boost::uniform_real<Value> range;
|
||||
Generator generator(rng, range);
|
||||
std::mt19937 rng;
|
||||
std::uniform_real_distribution<Value> range;
|
||||
|
||||
this->input.resize(ARRAY_SIZE);
|
||||
for(std::size_t i=0; i < ARRAY_SIZE; ++i )
|
||||
{
|
||||
this->input[i] = vtkm::Vec<Value, 3>(generator(),
|
||||
generator(),
|
||||
generator());
|
||||
this->input[i] = vtkm::Vec<Value, 3>(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<MTGenerator&, boost::uniform_real<Value> > Generator;
|
||||
typedef boost::variate_generator<MTGenerator&, boost::uniform_real<vtkm::Float32> > WGenerator;
|
||||
|
||||
boost::mt19937 rng;
|
||||
boost::uniform_real<vtkm::Float32> weight_range(0.0f,1.0f);
|
||||
WGenerator wgenerator(rng, weight_range);
|
||||
|
||||
boost::uniform_real<Value> field_range;
|
||||
Generator fgenerator(rng, field_range);
|
||||
std::mt19937 rng;
|
||||
std::uniform_real_distribution<vtkm::Float32> weight_range(0.0f,1.0f);
|
||||
std::uniform_real_distribution<Value> 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);
|
||||
|
@ -32,18 +32,7 @@
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/benchmarking/Benchmarker.h>
|
||||
|
||||
#ifdef VTKM_MSVC
|
||||
#pragma warning(disable:4723)
|
||||
#endif
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/random.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
#ifdef VTKM_MSVC
|
||||
#pragma warning(default:4723)
|
||||
#endif
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
namespace vtkm {
|
||||
@ -166,6 +155,35 @@ class BenchmarkTopologyAlgorithms {
|
||||
|
||||
private:
|
||||
|
||||
template<typename T, typename Enable= void> struct NumberGenerator {};
|
||||
|
||||
template<typename T>
|
||||
struct NumberGenerator<T,
|
||||
typename std::enable_if<
|
||||
std::is_floating_point<T>::value
|
||||
>::type
|
||||
>
|
||||
{
|
||||
std::mt19937 rng;
|
||||
std::uniform_real_distribution<T> distribution;
|
||||
NumberGenerator(T low, T high): rng(), distribution(low,high) {}
|
||||
T next() { return distribution(rng); }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct NumberGenerator<T,
|
||||
typename std::enable_if<
|
||||
!std::is_floating_point<T>::value
|
||||
>::type
|
||||
>
|
||||
{
|
||||
std::mt19937 rng;
|
||||
std::uniform_int_distribution<T> distribution;
|
||||
|
||||
NumberGenerator(T low, T high): rng(), distribution(low,high) {}
|
||||
T next() { return distribution(rng); }
|
||||
};
|
||||
|
||||
template<typename Value>
|
||||
struct BenchCellToPointAvg {
|
||||
std::vector< Value > input;
|
||||
@ -174,21 +192,14 @@ private:
|
||||
VTKM_CONT_EXPORT
|
||||
BenchCellToPointAvg()
|
||||
{
|
||||
typedef boost::uniform_real<Value> ValueRange;
|
||||
typedef boost::mt19937 MTGenerator;
|
||||
typedef boost::variate_generator<MTGenerator&, ValueRange> Generator;
|
||||
|
||||
boost::mt19937 rng;
|
||||
boost::uniform_real<Value> range(static_cast<Value>(1.0),
|
||||
NumberGenerator<Value> generator(static_cast<Value>(1.0),
|
||||
static_cast<Value>(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<Value> ValueRange;
|
||||
typedef boost::mt19937 MTGenerator;
|
||||
typedef boost::variate_generator<MTGenerator&, ValueRange> Generator;
|
||||
|
||||
boost::mt19937 rng;
|
||||
boost::uniform_real<Value> range(static_cast<Value>(1.0),
|
||||
NumberGenerator<Value> generator(static_cast<Value>(1.0),
|
||||
static_cast<Value>(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<Value> ValueRange;
|
||||
typedef boost::mt19937 MTGenerator;
|
||||
typedef boost::variate_generator<MTGenerator&, ValueRange> Generator;
|
||||
|
||||
boost::mt19937 rng;
|
||||
boost::uniform_real<Value> range(static_cast<Value>(1.0),
|
||||
NumberGenerator<Value> generator(static_cast<Value>(1.0),
|
||||
static_cast<Value>(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
|
||||
|
@ -29,16 +29,12 @@
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/random/mersenne_twister.hpp>
|
||||
#include <boost/random/uniform_real_distribution.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
#include <time.h>
|
||||
#include <ctime>
|
||||
#include <random>
|
||||
|
||||
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<vtkm::FloatDefault> randomDist;
|
||||
std::uniform_real_distribution<vtkm::FloatDefault> 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<vtkm::Float64> randomDist(-20.0, 20.0);
|
||||
std::uniform_real_distribution<vtkm::Float64> 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<vtkm::UInt32>(time(NULL));
|
||||
vtkm::UInt32 seed = static_cast<vtkm::UInt32>(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<vtkm::Float64>());
|
||||
|
||||
boost::random::uniform_real_distribution<vtkm::Float64> randomDist(-20.0, 20.0);
|
||||
std::uniform_real_distribution<vtkm::Float64> randomDist(-20.0, 20.0);
|
||||
LinearField field;
|
||||
field.OriginValue = randomDist(g_RandomGenerator);
|
||||
field.Gradient = vtkm::make_Vec(randomDist(g_RandomGenerator),
|
||||
|
@ -27,16 +27,12 @@
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/random/mersenne_twister.hpp>
|
||||
#include <boost/random/uniform_real_distribution.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
#include <ctime>
|
||||
#include <random>
|
||||
|
||||
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<vtkm::FloatDefault> randomDist;
|
||||
std::uniform_real_distribution<vtkm::FloatDefault> 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<T> randomDist(-1,1);
|
||||
std::uniform_real_distribution<T> randomDist(-1,1);
|
||||
|
||||
Vector3 sheerVec(randomDist(g_RandomGenerator),
|
||||
randomDist(g_RandomGenerator),
|
||||
@ -297,7 +293,7 @@ void TestAllPCoords()
|
||||
vtkm::testing::Testing::TryAllCellShapes(TestPCoordsFunctor<vtkm::Float64>());
|
||||
|
||||
std::cout << "======== Rectilinear Shapes ===============" << std::endl;
|
||||
boost::random::uniform_real_distribution<vtkm::FloatDefault> randomDist(0.01f,1.0f);
|
||||
std::uniform_real_distribution<vtkm::FloatDefault> randomDist(0.01f,1.0f);
|
||||
vtkm::Vec<vtkm::FloatDefault,3> origin(randomDist(g_RandomGenerator),
|
||||
randomDist(g_RandomGenerator),
|
||||
randomDist(g_RandomGenerator));
|
||||
|
@ -30,11 +30,7 @@
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/random/mersenne_twister.hpp>
|
||||
#include <boost/random/uniform_real_distribution.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
#include <random>
|
||||
|
||||
namespace vtkm {
|
||||
namespace testing {
|
||||
@ -43,8 +39,8 @@ namespace {
|
||||
|
||||
inline vtkm::FloatDefault GetRandomValue()
|
||||
{
|
||||
static boost::random::mt19937 gen;
|
||||
boost::random::uniform_real_distribution<vtkm::FloatDefault> dist(-7.0, 7.0);
|
||||
static std::mt19937 gen;
|
||||
std::uniform_real_distribution<vtkm::FloatDefault> dist(-7.0, 7.0);
|
||||
return dist(gen);
|
||||
}
|
||||
|
||||
|
@ -24,36 +24,32 @@
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/random/mersenne_twister.hpp>
|
||||
#include <boost/random/uniform_real_distribution.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
#include <ctime>
|
||||
#include <random>
|
||||
|
||||
namespace {
|
||||
|
||||
boost::mt19937 g_RandomGenerator;
|
||||
std::mt19937 g_RandomGenerator;
|
||||
|
||||
template<typename T>
|
||||
struct TransformTests
|
||||
{
|
||||
boost::random::uniform_real_distribution<T> RandomDistribution;
|
||||
std::uniform_real_distribution<T> 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<T,3> Vec;
|
||||
typedef vtkm::Matrix<T,4,4> 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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user