## 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/int/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
    #include <3rdparty/dsfmt/dSFMT.h>
    8
    9
    TEST_SETUP()
    10
    {
    11
      ccv_nnc_init();
    12
    }
    13
    14
    TEST_CASE("unique consecutive a 1d tensor")
    15
    1
    {
    16
    1
      GUARD_ELSE_RETURN(ccv_nnc_cmd_ok(CCV_NNC_UNIQUE_CONSECUTIVE_FORWARD, CCV_NNC_BACKEND_GPU_REF) || ccv_nnc_cmd_ok(CCV_NNC_UNIQUE_CONSECUTIVE_FORWARD, CCV_NNC_BACKEND_MPS));
    17
    1
      float ap[] = {
    18
    1
        2, 2, 2, 0, 0, 2, 2, 1, 1, 2, 3
    19
    1
      };
    20
    1
      ccv_nnc_tensor_t* const ha = ccv_nnc_tensor_new(ap, CPU_TENSOR_NHWC(32F, 11), 0);
    21
    1
      ccv_nnc_tensor_t* const hb = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32F, 7), 0);
    22
    1
      ccv_nnc_tensor_t* const hindices = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 7), 0);
    23
    1
      ccv_nnc_tensor_t* const a = ccv_nnc_tensor_new(0, GPU_TENSOR_NHWC(000, 32F, 11), 0);
    24
    1
      ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, GPU_TENSOR_NHWC(000, 32F, 7), 0);
    25
    1
      ccv_nnc_tensor_t* const indices = ccv_nnc_tensor_new(0, GPU_TENSOR_NHWC(000, 32S, 7), 0);
    26
    1
      ccv_nnc_cmd_exec(CMD_DATA_TRANSFER_FORWARD(), ccv_nnc_no_hint, 0, TENSOR_LIST(ha), TENSOR_LIST(a), 0);
    27
    1
      ccv_nnc_cmd_exec(CMD_UNIQUE_CONSECUTIVE_FORWARD(7), ccv_nnc_no_hint, 0, TENSOR_LIST(a), TENSOR_LIST(b, indices), 0);
    28
    1
      ccv_nnc_cmd_exec(CMD_DATA_TRANSFER_FORWARD(), ccv_nnc_no_hint, 0, TENSOR_LIST(b, indices), TENSOR_LIST(hb, hindices), 0);
    29
    1
      float btp[] = {
    30
    1
        2, 0, 2, 1, 2, 3, -1
    31
    1
      };
    32
    1
      ccv_nnc_tensor_t const bt = ccv_nnc_tensor(btp, CPU_TENSOR_NHWC(32F, 7), 0);
    33
    1
      REQUIRE_TENSOR_EQ(hb, &bt, "should be equal");
    34
    1
      int indicestp[] = {
    35
    1
        3, 2, 2, 2, 1, 1, 0
    36
    1
      };
    37
    1
      ccv_nnc_tensor_t const indicest = ccv_nnc_tensor(indicestp, CPU_TENSOR_NHWC(32S, 7), 0);
    38
    1
      REQUIRE_TENSOR_EQ(hindices, &indicest, "should be equal");
    39
    1
      ccv_nnc_tensor_free(a);
    40
    1
      ccv_nnc_tensor_free(b);
    41
    1
      ccv_nnc_tensor_free(indices);
    42
    1
      ccv_nnc_tensor_free(ha);
    43
    1
      ccv_nnc_tensor_free(hb);
    44
    1
      ccv_nnc_tensor_free(hindices);
    45
    1
    }
    46
    47
    TEST_CASE("unique consecutive a 1d tensor, int")
    48
    1
    {
    49
    1
      GUARD_ELSE_RETURN(ccv_nnc_cmd_ok(CCV_NNC_UNIQUE_CONSECUTIVE_FORWARD, CCV_NNC_BACKEND_GPU_REF) || ccv_nnc_cmd_ok(CCV_NNC_UNIQUE_CONSECUTIVE_FORWARD, CCV_NNC_BACKEND_MPS));
    50
    1
      int ap[] = {
    51
    1
        2, 2, 2, 0, 0, 2, 2, 1, 1, 2, 3
    52
    1
      };
    53
    1
      ccv_nnc_tensor_t* const ha = ccv_nnc_tensor_new(ap, CPU_TENSOR_NHWC(32S, 11), 0);
    54
    1
      ccv_nnc_tensor_t* const hb = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 7), 0);
    55
    1
      ccv_nnc_tensor_t* const hindices = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 7), 0);
    56
    1
      ccv_nnc_tensor_t* const a = ccv_nnc_tensor_new(0, GPU_TENSOR_NHWC(000, 32S, 11), 0);
    57
    1
      ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, GPU_TENSOR_NHWC(000, 32S, 7), 0);
    58
    1
      ccv_nnc_tensor_t* const indices = ccv_nnc_tensor_new(0, GPU_TENSOR_NHWC(000, 32S, 7), 0);
    59
    1
      ccv_nnc_cmd_exec(CMD_DATA_TRANSFER_FORWARD(), ccv_nnc_no_hint, 0, TENSOR_LIST(ha), TENSOR_LIST(a), 0);
    60
    1
      ccv_nnc_cmd_exec(CMD_UNIQUE_CONSECUTIVE_FORWARD(7), ccv_nnc_no_hint, 0, TENSOR_LIST(a), TENSOR_LIST(b, indices), 0);
    61
    1
      ccv_nnc_cmd_exec(CMD_DATA_TRANSFER_FORWARD(), ccv_nnc_no_hint, 0, TENSOR_LIST(b, indices), TENSOR_LIST(hb, hindices), 0);
    62
    1
      int btp[] = {
    63
    1
        2, 0, 2, 1, 2, 3, -1
    64
    1
      };
    65
    1
      ccv_nnc_tensor_t const bt = ccv_nnc_tensor(btp, CPU_TENSOR_NHWC(32S, 7), 0);
    66
    1
      REQUIRE_TENSOR_EQ(hb, &bt, "should be equal");
    67
    1
      int indicestp[] = {
    68
    1
        3, 2, 2, 2, 1, 1, 0
    69
    1
      };
    70
    1
      ccv_nnc_tensor_t const indicest = ccv_nnc_tensor(indicestp, CPU_TENSOR_NHWC(32S, 7), 0);
    71
    1
      REQUIRE_TENSOR_EQ(hindices, &indicest, "should be equal");
    72
    1
      ccv_nnc_tensor_free(a);
    73
    1
      ccv_nnc_tensor_free(b);
    74
    1
      ccv_nnc_tensor_free(indices);
    75
    1
      ccv_nnc_tensor_free(ha);
    76
    1
      ccv_nnc_tensor_free(hb);
    77
    1
      ccv_nnc_tensor_free(hindices);
    78
    1
    }
    79
    80
    TEST_CASE("unique consecutive a 1d tensor, int, same elements at end")
    81
    1
    {
    82
    1
      GUARD_ELSE_RETURN(ccv_nnc_cmd_ok(CCV_NNC_UNIQUE_CONSECUTIVE_FORWARD, CCV_NNC_BACKEND_GPU_REF) || ccv_nnc_cmd_ok(CCV_NNC_UNIQUE_CONSECUTIVE_FORWARD, CCV_NNC_BACKEND_MPS));
    83
    1
      int ap[] = {
    84
    1
        2, 2, 2, 0, 0, 2, 2, 1, 3, 3, 3
    85
    1
      };
    86
    1
      ccv_nnc_tensor_t* const ha = ccv_nnc_tensor_new(ap, CPU_TENSOR_NHWC(32S, 11), 0);
    87
    1
      ccv_nnc_tensor_t* const hb = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 7), 0);
    88
    1
      ccv_nnc_tensor_t* const hindices = ccv_nnc_tensor_new(0, CPU_TENSOR_NHWC(32S, 7), 0);
    89
    1
      ccv_nnc_tensor_t* const a = ccv_nnc_tensor_new(0, GPU_TENSOR_NHWC(000, 32S, 11), 0);
    90
    1
      ccv_nnc_tensor_t* const b = ccv_nnc_tensor_new(0, GPU_TENSOR_NHWC(000, 32S, 7), 0);
    91
    1
      ccv_nnc_tensor_t* const indices = ccv_nnc_tensor_new(0, GPU_TENSOR_NHWC(000, 32S, 7), 0);
    92
    1
      ccv_nnc_cmd_exec(CMD_DATA_TRANSFER_FORWARD(), ccv_nnc_no_hint, 0, TENSOR_LIST(ha), TENSOR_LIST(a), 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
      ccv_nnc_cmd_exec(CMD_DATA_TRANSFER_FORWARD(), ccv_nnc_no_hint, 0, TENSOR_LIST(b, indices), TENSOR_LIST(hb, hindices), 0);
    95
    1
      int btp[] = {
    96
    1
        2, 0, 2, 1, 3, -1, -1
    97
    1
      };
    98
    1
      ccv_nnc_tensor_t const bt = ccv_nnc_tensor(btp, CPU_TENSOR_NHWC(32S, 7), 0);
    99
    1
      REQUIRE_TENSOR_EQ(hb, &bt, "should be equal");
    100
    1
      int indicestp[] = {
    101
    1
        3, 2, 2, 1, 3, 0, 0
    102
    1
      };
    103
    1
      ccv_nnc_tensor_t const indicest = ccv_nnc_tensor(indicestp, CPU_TENSOR_NHWC(32S, 7), 0);
    104
    1
      REQUIRE_TENSOR_EQ(hindices, &indicest, "should be equal");
    105
    1
      ccv_nnc_tensor_free(a);
    106
    1
      ccv_nnc_tensor_free(b);
    107
    1
      ccv_nnc_tensor_free(indices);
    108
    1
      ccv_nnc_tensor_free(ha);
    109
    1
      ccv_nnc_tensor_free(hb);
    110
    1
      ccv_nnc_tensor_free(hindices);
    111
    1
    }
    112
    113
    #include "case_main.h"