## Coverage Report

#### Created: 2026-05-04 15:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)

    /home/liu/actions-runner/_work/ccv/ccv/test/unit/nnc/unique_consecutive.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
    8
    TEST_SETUP()
    9
    {
    10
      ccv_nnc_init();
    11
    }
    12
    13
    TEST_CASE("unique consecutive a 1d tensor")
    14
    1
    {
    15
    1
      float ap[] = {
    16
    1
        2, 2, 2, 0, 0, 2, 2, 1, 1, 2, 3
    17
    1
      };
    18
    1
      ccv_nnc_tensor_t* const a = ccv_nnc_tensor_new(ap, CPU_TENSOR_NHWC(32F, 11), 0);
    19
    1
      ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32F, 7), 0);
    20
    1
      ccv_nnc_tensor_t* const indices = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 7), 0);
    21
    1
      ccv_nnc_cmd_exec(CMD_UNIQUE_CONSECUTIVE_FORWARD(7), ccv_nnc_no_hint, 0, TENSOR_LIST(a), TENSOR_LIST(b, indices), 0);
    22
    1
      float btp[] = {
    23
    1
        2, 0, 2, 1, 2, 3, -1
    24
    1
      };
    25
    1
      ccv_nnc_tensor_t const bt = ccv_nnc_tensor(btp, CPU_TENSOR_NHWC(32F, 7), 0);
    26
    1
      REQUIRE_TENSOR_EQ(b, &bt, "should be equal");
    27
    1
      int indicestp[] = {
    28
    1
        3, 2, 2, 2, 1, 1, 0
    29
    1
      };
    30
    1
      ccv_nnc_tensor_t const indicest = ccv_nnc_tensor(indicestp, CPU_TENSOR_NHWC(32S, 7), 0);
    31
    1
      REQUIRE_TENSOR_EQ(indices, &indicest, "should be equal");
    32
    1
      ccv_nnc_tensor_free(a);
    33
    1
      ccv_nnc_tensor_free(b);
    34
    1
      ccv_nnc_tensor_free(indices);
    35
    1
    }
    36
    37
    TEST_CASE("unique consecutive a 1d tensor, smaller container")
    38
    1
    {
    39
    1
      float ap[] = {
    40
    1
        2, 2, 2, 0, 0, 2, 2, 1, 1, 2, 3
    41
    1
      };
    42
    1
      ccv_nnc_tensor_t* const a = ccv_nnc_tensor_new(ap, CPU_TENSOR_NHWC(32F, 11), 0);
    43
    1
      ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32F, 5), 0);
    44
    1
      ccv_nnc_tensor_t* const indices = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 5), 0);
    45
    1
      ccv_nnc_cmd_exec(CMD_UNIQUE_CONSECUTIVE_FORWARD(7), ccv_nnc_no_hint, 0, TENSOR_LIST(a), TENSOR_LIST(b, indices), 0);
    46
    1
      float btp[] = {
    47
    1
        2, 0, 2, 1, 2
    48
    1
      };
    49
    1
      ccv_nnc_tensor_t const bt = ccv_nnc_tensor(btp, CPU_TENSOR_NHWC(32F, 5), 0);
    50
    1
      REQUIRE_TENSOR_EQ(b, &bt, "should be equal");
    51
    1
      int indicestp[] = {
    52
    1
        3, 2, 2, 2, 1
    53
    1
      };
    54
    1
      ccv_nnc_tensor_t const indicest = ccv_nnc_tensor(indicestp, CPU_TENSOR_NHWC(32S, 5), 0);
    55
    1
      REQUIRE_TENSOR_EQ(indices, &indicest, "should be equal");
    56
    1
      ccv_nnc_tensor_free(a);
    57
    1
      ccv_nnc_tensor_free(b);
    58
    1
      ccv_nnc_tensor_free(indices);
    59
    1
    }
    60
    61
    TEST_CASE("unique consecutive a 1d tensor, int")
    62
    1
    {
    63
    1
      int ap[] = {
    64
    1
        2, 2, 2, 0, 0, 2, 2, 1, 1, 2, 3
    65
    1
      };
    66
    1
      ccv_nnc_tensor_t* const a = ccv_nnc_tensor_new(ap, CPU_TENSOR_NHWC(32S, 11), 0);
    67
    1
      ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 7), 0);
    68
    1
      ccv_nnc_tensor_t* const indices = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 7), 0);
    69
    1
      ccv_nnc_cmd_exec(CMD_UNIQUE_CONSECUTIVE_FORWARD(7), ccv_nnc_no_hint, 0, TENSOR_LIST(a), TENSOR_LIST(b, indices), 0);
    70
    1
      int btp[] = {
    71
    1
        2, 0, 2, 1, 2, 3, -1
    72
    1
      };
    73
    1
      ccv_nnc_tensor_t const bt = ccv_nnc_tensor(btp, CPU_TENSOR_NHWC(32S, 7), 0);
    74
    1
      REQUIRE_TENSOR_EQ(b, &bt, "should be equal");
    75
    1
      int indicestp[] = {
    76
    1
        3, 2, 2, 2, 1, 1, 0
    77
    1
      };
    78
    1
      ccv_nnc_tensor_t const indicest = ccv_nnc_tensor(indicestp, CPU_TENSOR_NHWC(32S, 7), 0);
    79
    1
      REQUIRE_TENSOR_EQ(indices, &indicest, "should be equal");
    80
    1
      ccv_nnc_tensor_free(a);
    81
    1
      ccv_nnc_tensor_free(b);
    82
    1
      ccv_nnc_tensor_free(indices);
    83
    1
    }
    84
    85
    TEST_CASE("unique consecutive a 1d tensor, int, smaller container")
    86
    1
    {
    87
    1
      int ap[] = {
    88
    1
        2, 2, 2, 0, 0, 2, 2, 1, 1, 2, 3
    89
    1
      };
    90
    1
      ccv_nnc_tensor_t* const a = ccv_nnc_tensor_new(ap, CPU_TENSOR_NHWC(32S, 11), 0);
    91
    1
      ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 5), 0);
    92
    1
      ccv_nnc_tensor_t* const indices = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 5), 0);
    93
    1
      ccv_nnc_cmd_exec(CMD_UNIQUE_CONSECUTIVE_FORWARD(7), ccv_nnc_no_hint, 0, TENSOR_LIST(a), TENSOR_LIST(b, indices), 0);
    94
    1
      int btp[] = {
    95
    1
        2, 0, 2, 1, 2
    96
    1
      };
    97
    1
      ccv_nnc_tensor_t const bt = ccv_nnc_tensor(btp, CPU_TENSOR_NHWC(32S, 5), 0);
    98
    1
      REQUIRE_TENSOR_EQ(b, &bt, "should be equal");
    99
    1
      int indicestp[] = {
    100
    1
        3, 2, 2, 2, 1
    101
    1
      };
    102
    1
      ccv_nnc_tensor_t const indicest = ccv_nnc_tensor(indicestp, CPU_TENSOR_NHWC(32S, 5), 0);
    103
    1
      REQUIRE_TENSOR_EQ(indices, &indicest, "should be equal");
    104
    1
      ccv_nnc_tensor_free(a);
    105
    1
      ccv_nnc_tensor_free(b);
    106
    1
      ccv_nnc_tensor_free(indices);
    107
    1
    }
    108
    109
    TEST_CASE("unique consecutive a 1d tensor with model")
    110
    1
    {
    111
    1
      float ap[] = {
    112
    1
        2, 2, 2, 0, 0, 2, 2, 1, 1, 2, 3
    113
    1
      };
    114
    1
      ccv_nnc_tensor_t* const a = ccv_nnc_tensor_new(ap, CPU_TENSOR_NHWC(32F, 11), 0);
    115
    1
      ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32F, 7), 0);
    116
    1
      ccv_nnc_tensor_t* const indices = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 7), 0);
    117
    1
      ccv_cnnp_model_t* const unique_consecutive = ccv_cnnp_unique_consecutive(7, "unique_consecutive");
    118
    1
      ccv_cnnp_model_compile(unique_consecutive, TENSOR_PARAM_LIST(a->info), CMD_NOOP(), CMD_NOOP());
    119
    1
      ccv_cnnp_model_evaluate(unique_consecutive, (ccv_cnnp_evaluate_param_t){
    120
    1
        .requires_grad = 0,
    121
    1
      }, TENSOR_LIST(a), TENSOR_LIST(b, indices), 0, 0);
    122
    1
      float btp[] = {
    123
    1
        2, 0, 2, 1, 2, 3, -1
    124
    1
      };
    125
    1
      ccv_nnc_tensor_t const bt = ccv_nnc_tensor(btp, CPU_TENSOR_NHWC(32F, 7), 0);
    126
    1
      REQUIRE_TENSOR_EQ(b, &bt, "should be equal");
    127
    1
      int indicestp[] = {
    128
    1
        3, 2, 2, 2, 1, 1, 0
    129
    1
      };
    130
    1
      ccv_nnc_tensor_t const indicest = ccv_nnc_tensor(indicestp, CPU_TENSOR_NHWC(32S, 7), 0);
    131
    1
      REQUIRE_TENSOR_EQ(indices, &indicest, "should be equal");
    132
    1
      ccv_nnc_tensor_free(a);
    133
    1
      ccv_nnc_tensor_free(b);
    134
    1
      ccv_nnc_tensor_free(indices);
    135
    1
      ccv_cnnp_model_free(unique_consecutive);
    136
    1
    }
    137
    138
    TEST_CASE("unique consecutive a 1d tensor, int, same elements at end")
    139
    1
    {
    140
    1
      int ap[] = {
    141
    1
        2, 2, 2, 0, 0, 2, 2, 1, 3, 3, 3
    142
    1
      };
    143
    1
      ccv_nnc_tensor_t* const a = ccv_nnc_tensor_new(ap, CPU_TENSOR_NHWC(32S, 11), 0);
    144
    1
      ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 7), 0);
    145
    1
      ccv_nnc_tensor_t* const indices = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 7), 0);
    146
    1
      ccv_nnc_cmd_exec(CMD_UNIQUE_CONSECUTIVE_FORWARD(7), ccv_nnc_no_hint, 0, TENSOR_LIST(a), TENSOR_LIST(b, indices), 0);
    147
    1
      int btp[] = {
    148
    1
        2, 0, 2, 1, 3, -1, -1
    149
    1
      };
    150
    1
      ccv_nnc_tensor_t const bt = ccv_nnc_tensor(btp, CPU_TENSOR_NHWC(32S, 7), 0);
    151
    1
      REQUIRE_TENSOR_EQ(b, &bt, "should be equal");
    152
    1
      int indicestp[] = {
    153
    1
        3, 2, 2, 1, 3, 0, 0
    154
    1
      };
    155
    1
      ccv_nnc_tensor_t const indicest = ccv_nnc_tensor(indicestp, CPU_TENSOR_NHWC(32S, 7), 0);
    156
    1
      REQUIRE_TENSOR_EQ(indices, &indicest, "should be equal");
    157
    1
      ccv_nnc_tensor_free(a);
    158
    1
      ccv_nnc_tensor_free(b);
    159
    1
      ccv_nnc_tensor_free(indices);
    160
    1
    }
    161
    162
    #include "case_main.h"