Coverage Report

Created: 2021-09-30 21:42

/home/liu/buildslave/linux-x64-runtests/build/test/unit/nnc/upsample.tests.c
Line
Count
Source
1
#include "ccv.h"
2
#include "nnc/ccv_nnc.h"
3
#include "nnc/ccv_nnc_easy.h"
4
#include "case.h"
5
#include "ccv_case.h"
6
7
TEST_SETUP()
8
{
9
  ccv_nnc_init();
10
}
11
12
TEST_CASE("upsample chessbox")
13
1
{
14
1
  ccv_dense_matrix_t* image = 0;
15
1
  ccv_read("../../../samples/chessbox.png", &image, CCV_IO_ANY_FILE | CCV_IO_RGB_COLOR);
16
1
  ccv_dense_matrix_t* fimage = 0;
17
1
  ccv_shift(image, (ccv_matrix_t**)&fimage, CCV_32F, 0, 0);
18
1
  ccv_nnc_tensor_t* const a = (ccv_nnc_tensor_t*)fimage;
19
1
  ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32F, image->rows * 2, image->cols * 2, 3), 0);
20
1
  ccv_nnc_cmd_exec(CMD_UPSAMPLE_BILINEAR_FORWARD(2, 2), ccv_nnc_no_hint, 0, TENSOR_LIST(a), TENSOR_LIST(b), 0);
21
1
  REQUIRE_MATRIX_FILE_EQ((ccv_matrix_t*)b, "data/upsample.forward.bin", "the forward of upsample should be equal");
22
1
  ccv_nnc_tensor_free(b);
23
1
  ccv_matrix_free(image);
24
1
  ccv_matrix_free(fimage);
25
1
}
26
27
TEST_CASE("downsample chessbox")
28
1
{
29
1
  ccv_dense_matrix_t* image = 0;
30
1
  ccv_read("../../../samples/chessbox.png", &image, CCV_IO_ANY_FILE | CCV_IO_RGB_COLOR);
31
1
  ccv_dense_matrix_t* fimage = 0;
32
1
  ccv_shift(image, (ccv_matrix_t**)&fimage, CCV_32F, 0, 0);
33
1
  ccv_nnc_tensor_t* const a = (ccv_nnc_tensor_t*)fimage;
34
1
  ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32F, image->rows / 2, image->cols / 2, 3), 0);
35
1
  ccv_nnc_cmd_exec(CMD_UPSAMPLE_BILINEAR_BACKWARD(2, 2), ccv_nnc_no_hint, 0, TENSOR_LIST(a), TENSOR_LIST(b), 0);
36
1
  REQUIRE_MATRIX_FILE_EQ((ccv_matrix_t*)b, "data/upsample.backward.bin", "the backward of upsample should be equal");
37
1
  ccv_nnc_tensor_free(b);
38
1
  ccv_matrix_free(image);
39
1
  ccv_matrix_free(fimage);
40
1
}
41
42
TEST_CASE("upsample chessbox in NCHW")
43
1
{
44
1
  ccv_dense_matrix_t* image = 0;
45
1
  ccv_read("../../../samples/chessbox.png", &image, CCV_IO_ANY_FILE | CCV_IO_RGB_COLOR);
46
1
  ccv_dense_matrix_t* fimage = 0;
47
1
  ccv_shift(image, (ccv_matrix_t**)&fimage, CCV_32F, 0, 0);
48
1
  ccv_nnc_tensor_t* const a = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32F, 3, image->rows, image->cols), 0);
49
1
  ccv_nnc_cmd_exec(CMD_FORMAT_TRANSFORM_FORWARD(), ccv_nnc_no_hint, 0, TENSOR_LIST((ccv_nnc_tensor_t*)fimage), TENSOR_LIST(a), 0);
50
1
  ccv_matrix_free(fimage);
51
1
  ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32F, 3, image->rows * 2, image->cols * 2), 0);
52
1
  ccv_nnc_cmd_exec(CMD_UPSAMPLE_BILINEAR_FORWARD(2, 2), ccv_nnc_no_hint, 0, TENSOR_LIST(a), TENSOR_LIST(b), 0);
53
1
  ccv_nnc_tensor_free(a);
54
1
  ccv_nnc_tensor_t* const bt = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32F, image->rows * 2, image->cols * 2, 3), 0);
55
1
  ccv_nnc_cmd_exec(CMD_FORMAT_TRANSFORM_FORWARD(), ccv_nnc_no_hint, 0, TENSOR_LIST(b), TENSOR_LIST(bt), 0);
56
1
  ccv_nnc_tensor_free(b);
57
1
  REQUIRE_MATRIX_FILE_EQ((ccv_matrix_t*)bt, "data/upsample.forward.bin", "the forward of upsample should be equal");
58
1
  ccv_matrix_free(image);
59
1
  ccv_nnc_tensor_free(bt);
60
1
}
61
62
TEST_CASE("downsample chessbox in NCHW")
63
1
{
64
1
  ccv_dense_matrix_t* image = 0;
65
1
  ccv_read("../../../samples/chessbox.png", &image, CCV_IO_ANY_FILE | CCV_IO_RGB_COLOR);
66
1
  ccv_dense_matrix_t* fimage = 0;
67
1
  ccv_shift(image, (ccv_matrix_t**)&fimage, CCV_32F, 0, 0);
68
1
  ccv_nnc_tensor_t* const a = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32F, 3, image->rows, image->cols), 0);
69
1
  ccv_nnc_cmd_exec(CMD_FORMAT_TRANSFORM_FORWARD(), ccv_nnc_no_hint, 0, TENSOR_LIST((ccv_nnc_tensor_t*)fimage), TENSOR_LIST(a), 0);
70
1
  ccv_matrix_free(fimage);
71
1
  ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32F, 3, image->rows / 2, image->cols / 2), 0);
72
1
  ccv_nnc_cmd_exec(CMD_UPSAMPLE_BILINEAR_BACKWARD(2, 2), ccv_nnc_no_hint, 0, TENSOR_LIST(a), TENSOR_LIST(b), 0);
73
1
  ccv_nnc_tensor_free(a);
74
1
  ccv_nnc_tensor_t* const bt = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32F, image->rows / 2, image->cols / 2, 3), 0);
75
1
  ccv_nnc_cmd_exec(CMD_FORMAT_TRANSFORM_FORWARD(), ccv_nnc_no_hint, 0, TENSOR_LIST(b), TENSOR_LIST(bt), 0);
76
1
  ccv_nnc_tensor_free(b);
77
1
  REQUIRE_MATRIX_FILE_EQ((ccv_matrix_t*)bt, "data/upsample.backward.bin", "the backward of upsample should be equal");
78
1
  ccv_matrix_free(image);
79
1
  ccv_nnc_tensor_free(bt);
80
1
}
81
82
#include "case_main.h"