Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Checks: >
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-unchecked-optional-access,
-clang-analyzer-security.insecureAPI.rand,

WarningsAsErrors: "*"

Expand Down
12 changes: 8 additions & 4 deletions test/benchmarking/test_accuracy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ TEST(accuracy, bad_accuracy_test_L) {
size_t n = 5000;
double a[5000];
double b[5000];
std::mt19937 rng(42);
std::uniform_real_distribution<double> dist(-100.0, 100.0);
for (size_t i = 0; i < n; i++) {
a[i] = (static_cast<double>(rand()) / RAND_MAX - 1.0) * 100; // [-100;100]
a[i] = dist(rng);
}
for (size_t i = 0; i < n; i++) {
b[i] = (static_cast<double>(rand()) / RAND_MAX - 1.0) * 100; // [-100;100]
b[i] = dist(rng);
}
double actual_acc = 0.0;
for (size_t i = 0; i < n; i++) {
Expand Down Expand Up @@ -67,11 +69,13 @@ TEST(accuracy, bad_accuracy_norm_test_L) {
size_t n = 5000;
double a[5000];
double b[5000];
std::mt19937 rng2(42);
std::uniform_real_distribution<double> dist2(-100.0, 100.0);
for (size_t i = 0; i < n; i++) {
a[i] = (static_cast<double>(rand()) / RAND_MAX - 1.0) * 100; // [-100;100]
a[i] = dist2(rng2);
}
for (size_t i = 0; i < n; i++) {
b[i] = (static_cast<double>(rand()) / RAND_MAX - 1.0) * 100; // [-100;100]
b[i] = dist2(rng2);
}
double actual_acc = 0.0;
for (size_t i = 0; i < n; i++) {
Expand Down
10 changes: 7 additions & 3 deletions test/benchmarking/test_layers_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ TEST(pooling_test, is_pooling_tbb_ok) {
size_t w = 224;
Shape test_shape = {n, c, h, w};
std::vector<int> a1(n * c * h * w);
std::mt19937 rng(42);
std::uniform_int_distribution<int> dist(0, std::numeric_limits<int>::max());
for (size_t i = 0; i < n * c * h * w; i++) {
a1[i] = rand();
a1[i] = dist(rng);
}
Tensor input = make_tensor(a1, test_shape);
Tensor output;
Expand All @@ -45,11 +47,13 @@ TEST(conv_test, is_conv_stl_ok) {
Shape test_shape = {n, c, h, w};
std::vector<int> a1(n * c * h * w);
std::vector<int> a2(3 * 25 * 16);
std::mt19937 rng2(42);
std::uniform_int_distribution<int> dist2(0, std::numeric_limits<int>::max());
for (size_t i = 0; i < n * c * h * w; i++) {
a1[i] = rand();
a1[i] = dist2(rng2);
}
for (size_t i = 0; i < 3 * 25 * 16; i++) {
a2[i] = rand();
a2[i] = dist2(rng2);
}
Tensor input = make_tensor(a1, test_shape);
Tensor kernel = make_tensor(a2, Shape({5, 5, 3, 16}));
Expand Down
7 changes: 5 additions & 2 deletions test/graph/test_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,12 @@ TEST(graph_transformations, check_subgraphs_big_random) {
}

graph.setInput(layers[0], input);
std::mt19937 rng(42);
std::uniform_int_distribution<int> first_dist(0, num_vertices - 2);
std::uniform_int_distribution<int> second_dist(1, num_vertices - 1);
for (int i = 0; i < num_vertices; i++) {
int rFirst = rand() % (num_vertices - 1);
int rSecond = 1 + rand() % (num_vertices - 1);
int rFirst = first_dist(rng);
int rSecond = second_dist(rng);
if ((rFirst == rSecond) ||
((layers[rFirst]->getID() == layers[rSecond]->getID()) &&
(layers[rFirst]->getID() != 0))) {
Expand Down
31 changes: 23 additions & 8 deletions test/single_layer/test_outputlayer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <random>
#include <string>

#include "gtest/gtest.h"
Expand Down Expand Up @@ -62,8 +62,10 @@ TEST(OutputLayer, can_get_topk_with_vector) {
labels);
std::vector<double> input;
// get random nums
std::mt19937 rng(42);
std::uniform_real_distribution<double> dist01(0.0, 1.0);
for (size_t i = 0; i < labels.size(); i++) {
input.push_back(static_cast<double>(std::rand()) / RAND_MAX);
input.push_back(dist01(rng));
}
ASSERT_NO_THROW(auto topk1 = top_k_vec(input, labels, k));
}
Expand All @@ -75,9 +77,10 @@ TEST(OutputLayer, can_get_topk_with_layer_float) {
labels);
std::vector<float> input;
// get random nums
std::mt19937 rng2(42);
std::uniform_real_distribution<float> dist01f(0.0F, 1.0F);
for (size_t i = 0; i < labels.size(); i++) {
input.push_back(
static_cast<float>(static_cast<double>(std::rand()) / RAND_MAX));
input.push_back(dist01f(rng2));
}
Tensor input_tensor = make_tensor(input);
OutputLayer layer(labels);
Expand All @@ -91,8 +94,11 @@ TEST(OutputLayer, can_get_topk_with_layer_int) {
labels);
std::vector<int> input;
// get random nums
std::mt19937 rng3(42);
std::uniform_int_distribution<int> dist_int(0,
std::numeric_limits<int>::max());
for (size_t i = 0; i < labels.size(); i++) {
input.push_back(std::rand());
input.push_back(dist_int(rng3));
}
Tensor input_tensor = make_tensor(input);
OutputLayer layer(labels);
Expand All @@ -106,8 +112,11 @@ TEST(OutputLayer, topk_throws_when_not_1d_input) {
labels);
std::vector<int> input;
// get random nums
std::mt19937 rng4(42);
std::uniform_int_distribution<int> dist_int2(0,
std::numeric_limits<int>::max());
for (size_t i = 0; i < labels.size(); i++) {
input.push_back(std::rand());
input.push_back(dist_int2(rng4));
}
Tensor input_tensor = make_tensor(input, {5, 200});
OutputLayer layer(labels);
Expand All @@ -121,8 +130,11 @@ TEST(OutputLayer, topk_throws_when_incorrect_input_size) {
labels);
std::vector<int> input;
// get random nums
std::mt19937 rng5(42);
std::uniform_int_distribution<int> dist_int3(0,
std::numeric_limits<int>::max());
for (size_t i = 0; i < 20; i++) {
input.push_back(std::rand());
input.push_back(dist_int3(rng5));
}
Tensor input_tensor = make_tensor(input);
OutputLayer layer(labels);
Expand All @@ -136,8 +148,11 @@ TEST(OutputLayer, topk_throws_when_too_big_k) {
labels);
std::vector<int> input;
// get random nums
std::mt19937 rng6(42);
std::uniform_int_distribution<int> dist_int4(0,
std::numeric_limits<int>::max());
for (size_t i = 0; i < labels.size(); i++) {
input.push_back(std::rand());
input.push_back(dist_int4(rng6));
}
Tensor input_tensor = make_tensor(input);
OutputLayer layer(labels);
Expand Down
13 changes: 8 additions & 5 deletions test/single_layer/test_poolinglayer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <vector>
#include <random>
#include <vector>

#include "gtest/gtest.h"
#include "layers/PoolingLayer.hpp"
Expand Down Expand Up @@ -365,9 +366,10 @@ TEST(poolinglayer, maxpool_onnx_example) {
EXPECT_EQ(impl.get_output_shape(), expected_output_shape);

std::vector<float> input(input_shape.count());
std::mt19937 rng(42);
std::uniform_real_distribution<float> dist(0.0F, 10.0F);
for (size_t i = 0; i < input.size(); i++) {
input[i] =
static_cast<float>(rand()) / static_cast<float>(RAND_MAX) * 10.0f;
input[i] = dist(rng);
}

std::vector<float> output = impl.run(input);
Expand Down Expand Up @@ -403,9 +405,10 @@ TEST(poolinglayer, maxpool_onnx_with_pooling_layer) {
PoolingLayer layer(poolshape, strides, pads, dilations, ceil_mode, "max");

std::vector<float> input(input_shape.count());
std::mt19937 rng2(42);
std::uniform_real_distribution<float> dist2(0.0F, 10.0F);
for (size_t i = 0; i < input.size(); i++) {
input[i] =
static_cast<float>(rand()) / static_cast<float>(RAND_MAX) * 10.0f;
input[i] = dist2(rng2);
}

Tensor input_tensor = make_tensor(input, input_shape);
Expand Down
Loading