Coverage Report

Created: 2019-07-03 22:50

/home/liu/buildslave/linux-x64-runtests/build/test/unit/nnc/rand.tests.c
Line
Count
Source
1
#include "case.h"
2
#include "ccv_case.h"
3
#include "ccv_nnc_case.h"
4
#include <ccv.h>
5
#include <nnc/ccv_nnc.h>
6
#include <nnc/ccv_nnc_easy.h>
7
#include "3rdparty/dsfmt/dSFMT.h"
8
9
TEST_SETUP()
10
{
11
  ccv_nnc_init();
12
}
13
14
TEST_CASE("random uniform distribution")
15
1
{
16
1
  ccv_nnc_symbolic_graph_t* symbolic_graph = ccv_nnc_symbolic_graph_new();
17
1
  const ccv_nnc_tensor_symbol_t x = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 100000), "x");
18
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_RANDOM_UNIFORM_FORWARD(-8, 4), TENSOR_SYMBOL_LIST(), TENSOR_SYMBOL_LIST(x), "random uniform");
19
1
  ccv_nnc_graph_exec_symbol_autogen(symbolic_graph, 0, 0, CCV_NNC_AUTOGEN_ALL_EXECS | CCV_NNC_AUTOGEN_SOURCES_AND_DESTINATIONS);
20
1
  SYMBOLIC_GRAPH_GEN(symbolic_graph, CCV_NNC_LONG_DOT_GRAPH);
21
1
  ccv_nnc_graph_t* graph = 0;
22
1
  ccv_nnc_tensor_arena_t* tensor_arena = 0;
23
1
  ccv_nnc_graph_exec_arena_t* graph_exec_arena = 0;
24
1
  ccv_nnc_symbolic_graph_compile(symbolic_graph, 0, 0, 0, 0, SYMBOLIC_GRAPH_SOURCES(symbolic_graph), SYMBOLIC_GRAPH_DESTINATIONS(symbolic_graph), &graph, &tensor_arena, &graph_exec_arena);
25
1
  GRAPH_GEN(graph, CCV_NNC_LONG_DOT_GRAPH);
26
1
  ccv_nnc_graph_run(graph, 0, 0, 0, TRAVERSE_FULL);
27
1
  ccv_nnc_tensor_t* const x_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, x);
28
1
  int i;
29
1
  int h[4 + 8] = {};
30
100k
  for (i = 0; i < 100000; 
i++100k
)
31
100k
  {
32
100k
    REQUIRE(x_tensor->data.f32[i] > -8 - 1e-5, "it must be bigger than lower bound");
33
100k
    REQUIRE(x_tensor->data.f32[i] < 4 + 1e-5, "and smaller than upper bound");
34
100k
    int b = (int)roundf(x_tensor->data.f32[i] - 0.5) + 8;
35
100k
    b = ccv_max(ccv_min(b, 11), 0);
36
100k
    ++h[b];
37
100k
  }
38
1
  const int count = (int)roundf(100000. / (4 + 8));
39
13
  for (i = 0; i < 12; 
i++12
)
40
12
    { REQUIRE(h[i] >= count - 1000 && h[i] <= count + 1000, "uniform distribution"); }
41
1
  ccv_nnc_graph_free(graph);
42
1
  ccv_nnc_tensor_arena_free(tensor_arena);
43
1
  ccv_nnc_graph_exec_arena_free(graph_exec_arena);
44
1
  ccv_nnc_symbolic_graph_free(symbolic_graph);
45
1
}
46
47
#include "case_main.h"