From 982c865fce3e3df0b9e74753fddf6664235b898a Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 19 Mar 2018 18:01:44 +0800 Subject: [PATCH] srand delete srand(time(NULL)); add rand_r(time(NULL)) --- mace/ops/addn_test.cc | 3 +-- mace/ops/batch_norm_test.cc | 15 ++++----------- mace/ops/bias_add_test.cc | 8 ++------ mace/ops/concat_test.cc | 3 +-- mace/ops/conv_2d_test.cc | 5 ++--- mace/ops/depthwise_conv2d_test.cc | 4 +--- mace/ops/folded_batch_norm_test.cc | 14 ++++---------- mace/ops/fused_conv_2d_test.cc | 10 ++++------ mace/ops/resize_bilinear_test.cc | 4 ++-- mace/ops/slice_test.cc | 4 ++-- 10 files changed, 23 insertions(+), 47 deletions(-) diff --git a/mace/ops/addn_test.cc b/mace/ops/addn_test.cc index 779d930b..94d3dd91 100644 --- a/mace/ops/addn_test.cc +++ b/mace/ops/addn_test.cc @@ -64,11 +64,10 @@ TEST_F(AddnOpTest, CPUSimpleAdd3) { SimpleAdd3(); } template void RandomTest() { testing::internal::LogToStderr(); - srand(time(NULL)); + static unsigned int seed = time(NULL); for (int round = 0; round < 10; ++round) { // generate random input - static unsigned int seed = 123; index_t n = 1 + (rand_r(&seed) % 5); index_t h = 1 + (rand_r(&seed) % 100); index_t w = 1 + (rand_r(&seed) % 100); diff --git a/mace/ops/batch_norm_test.cc b/mace/ops/batch_norm_test.cc index 9f88afaf..909722d7 100644 --- a/mace/ops/batch_norm_test.cc +++ b/mace/ops/batch_norm_test.cc @@ -77,10 +77,9 @@ TEST_F(BatchNormOpTest, SimpleCPU) { Simple(); } TEST_F(BatchNormOpTest, SimpleOPENCL) { Simple(); } TEST_F(BatchNormOpTest, SimpleRandomOPENCL) { - // srand(time(NULL)); // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 1 + rand_r(&seed) % 10; index_t channels = 3 + rand_r(&seed) % 50; index_t height = 64; @@ -150,10 +149,8 @@ TEST_F(BatchNormOpTest, SimpleRandomOPENCL) { } TEST_F(BatchNormOpTest, SimpleRandomHalfOPENCL) { - // srand(time(NULL)); - // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 1 + rand_r(&seed) % 10; index_t channels = 3 + rand_r(&seed) % 50; index_t height = 64; @@ -224,10 +221,8 @@ TEST_F(BatchNormOpTest, SimpleRandomHalfOPENCL) { } TEST_F(BatchNormOpTest, ComplexRandomOPENCL) { - // srand(time(NULL)); - // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 1 + rand_r(&seed) % 10; index_t channels = 3 + rand_r(&seed) % 50; index_t height = 103; @@ -297,10 +292,8 @@ TEST_F(BatchNormOpTest, ComplexRandomOPENCL) { } TEST_F(BatchNormOpTest, ComplexRandomHalfOPENCL) { - // srand(time(NULL)); - // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 1 + rand_r(&seed) % 10; index_t channels = 3 + rand_r(&seed) % 50; index_t height = 103; diff --git a/mace/ops/bias_add_test.cc b/mace/ops/bias_add_test.cc index e3645114..4803bcd2 100644 --- a/mace/ops/bias_add_test.cc +++ b/mace/ops/bias_add_test.cc @@ -62,10 +62,8 @@ TEST_F(BiasAddOpTest, BiasAddSimpleOPENCL) { } TEST_F(BiasAddOpTest, SimpleRandomOPENCL) { - // srand(time(NULL)); - // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 1 + rand_r(&seed) % 10; index_t channels = 3 + rand_r(&seed) % 50; index_t height = 64 + rand_r(&seed) % 50; @@ -113,10 +111,8 @@ TEST_F(BiasAddOpTest, SimpleRandomOPENCL) { } TEST_F(BiasAddOpTest, ComplexRandomOPENCL) { - // srand(time(NULL)); - // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 1 + rand_r(&seed) % 10; index_t channels = 3 + rand_r(&seed) % 50; index_t height = 103 + rand_r(&seed) % 100; diff --git a/mace/ops/concat_test.cc b/mace/ops/concat_test.cc index f48a25b3..4a34e598 100644 --- a/mace/ops/concat_test.cc +++ b/mace/ops/concat_test.cc @@ -92,8 +92,7 @@ TEST_F(ConcatOpTest, CPUSimpleVertical) { } TEST_F(ConcatOpTest, CPURandom) { - // srand(time(nullptr)); - static unsigned int seed = 123; + static unsigned int seed = time(nullptr); int dim = 5; int num_inputs = 2 + rand_r(&seed) % 10; int axis = rand_r(&seed) % dim; diff --git a/mace/ops/conv_2d_test.cc b/mace/ops/conv_2d_test.cc index ee344d71..457c9caa 100644 --- a/mace/ops/conv_2d_test.cc +++ b/mace/ops/conv_2d_test.cc @@ -351,10 +351,9 @@ static void TestComplexConvNxNS12(const std::vector &shape, testing::internal::LogToStderr(); auto func = [&](int kernel_h, int kernel_w, int stride_h, int stride_w, Padding type) { - // srand(time(NULL)); - + // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 3 + (rand_r(&seed) % 10); index_t height = shape[0]; index_t width = shape[1]; diff --git a/mace/ops/depthwise_conv2d_test.cc b/mace/ops/depthwise_conv2d_test.cc index 9b621910..6c841c75 100644 --- a/mace/ops/depthwise_conv2d_test.cc +++ b/mace/ops/depthwise_conv2d_test.cc @@ -207,10 +207,8 @@ void TestNxNS12(const index_t height, const index_t width) { testing::internal::LogToStderr(); auto func = [&](int kernel_h, int kernel_w, int stride_h, int stride_w, Padding type) { - // srand(time(NULL)); - // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 1 + rand_r(&seed) % 5; index_t input_channels = 3 + rand_r(&seed) % 16; index_t multiplier = 1; diff --git a/mace/ops/folded_batch_norm_test.cc b/mace/ops/folded_batch_norm_test.cc index a786dfef..416e6ad8 100644 --- a/mace/ops/folded_batch_norm_test.cc +++ b/mace/ops/folded_batch_norm_test.cc @@ -174,10 +174,8 @@ width}); */ TEST_F(FoldedBatchNormOpTest, SimpleRandomOPENCL) { - // srand(time(NULL)); - // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 1 + rand_r(&seed) % 10; index_t channels = 3 + rand_r(&seed) % 50; index_t height = 64; @@ -230,9 +228,8 @@ TEST_F(FoldedBatchNormOpTest, SimpleRandomOPENCL) { } TEST_F(FoldedBatchNormOpTest, SimpleRandomHalfOPENCL) { - // srand(time(NULL)); // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 1 + rand_r(&seed) % 10; index_t channels = 3 + rand_r(&seed) % 50; index_t height = 64; @@ -286,9 +283,8 @@ TEST_F(FoldedBatchNormOpTest, SimpleRandomHalfOPENCL) { } TEST_F(FoldedBatchNormOpTest, ComplexRandomOPENCL) { - // srand(time(NULL)); - static unsigned int seed = 123; // generate random input + static unsigned int seed = time(NULL); index_t batch = 1 + rand_r(&seed) % 10; index_t channels = 3 + rand_r(&seed) % 50; index_t height = 103; @@ -340,10 +336,8 @@ TEST_F(FoldedBatchNormOpTest, ComplexRandomOPENCL) { } TEST_F(FoldedBatchNormOpTest, ComplexRandomHalfOPENCL) { - // srand(time(NULL)); - // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 1 + rand_r(&seed) % 10; index_t channels = 3 + rand_r(&seed) % 50; index_t height = 103; diff --git a/mace/ops/fused_conv_2d_test.cc b/mace/ops/fused_conv_2d_test.cc index 1d46679a..a30d09f9 100644 --- a/mace/ops/fused_conv_2d_test.cc +++ b/mace/ops/fused_conv_2d_test.cc @@ -278,10 +278,9 @@ static void TestComplexConvNxNS12(const std::vector &shape) { testing::internal::LogToStderr(); auto func = [&](int kernel_h, int kernel_w, int stride_h, int stride_w, Padding type) { - // srand(time(NULL)); - + // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 3 + (rand_r(&seed) % 10); index_t height = shape[0]; index_t width = shape[1]; @@ -355,10 +354,9 @@ static void TestHalfComplexConvNxNS12(const std::vector &shape) { testing::internal::LogToStderr(); auto func = [&](int kernel_h, int kernel_w, int stride_h, int stride_w, Padding type) { - // srand(time(NULL)); - + // generate random input - static unsigned int seed = 123; + static unsigned int seed = time(NULL); index_t batch = 3 + (rand_r(&seed) % 10); index_t height = shape[0]; index_t width = shape[1]; diff --git a/mace/ops/resize_bilinear_test.cc b/mace/ops/resize_bilinear_test.cc index ae87a2f8..7956503f 100644 --- a/mace/ops/resize_bilinear_test.cc +++ b/mace/ops/resize_bilinear_test.cc @@ -65,9 +65,9 @@ TEST_F(ResizeBilinearTest, ResizeBilinearWAlignCorners) { template void TestRandomResizeBilinear() { - // srand(time(nullptr)); + testing::internal::LogToStderr(); - static unsigned int seed = 123; + static unsigned int seed = time(NULL); for (int round = 0; round < 10; ++round) { int batch = 1 + rand_r(&seed) % 5; int channels = 1 + rand_r(&seed) % 100; diff --git a/mace/ops/slice_test.cc b/mace/ops/slice_test.cc index 0958ed95..8290a862 100644 --- a/mace/ops/slice_test.cc +++ b/mace/ops/slice_test.cc @@ -16,8 +16,8 @@ class SliceOpTest : public OpsTestBase {}; template void RandomTest(const int num_outputs) { - // srand(time(nullptr)); - static unsigned int seed = 123; + + static unsigned int seed = time(NULL); const index_t output_channels = 4 * (1 + rand_r(&seed) % 10); const index_t input_channels = num_outputs * output_channels; const index_t batch = 3 + (rand_r(&seed) % 10); -- GitLab