## Coverage Report

#### Created: 2026-04-14 11:10

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

    /home/liu/actions-runner/_work/ccv/ccv/lib/nnc/cmd/histogram/ccv_nnc_histogram.c

    Line
    Count
    Source
    1
    #include "ccv.h"
    2
    #include "nnc/ccv_nnc.h"
    3
    #include "nnc/ccv_nnc_easy.h"
    4
    #include "nnc/ccv_nnc_internal.h"
    5
    6
    static int _ccv_nnc_histogram_forw_bitmask(const ccv_nnc_cmd_param_t cmd, const int input_size, const int output_size, const uint64_t* const input_bitmasks, const int input_bitmask_size, const uint64_t* const output_bitmasks, const int output_bitmask_size)
    7
    0
    {
    8
      // input, [bins]
    9
      // output, [stats] (stats contains scalar in order of: min, max, sum, sum of squares).
    10
    0
      if (((input_bitmasks[0] & 1u) == 1u || (input_bitmasks[0] & 3u) == 3u) && (output_bitmasks[0] == 1u || output_bitmasks[0] == 3u))
    11
    0
        return 1;
    12
    0
      return 0;
    13
    0
    }
    14
    15
    static int _ccv_nnc_histogram_back_bitmask(const ccv_nnc_cmd_param_t cmd, const int input_size, const int output_size, const uint64_t* const input_bitmasks, const int input_bitmask_size, const uint64_t* const output_bitmasks, const int output_bitmask_size)
    16
    0
    {
    17
    0
      return 0;
    18
    0
    }
    19
    20
    static void _ccv_nnc_histogram_tensor_auto_forw(const ccv_nnc_cmd_param_t cmd, const ccv_nnc_tensor_param_t* const inputs, const int input_size, const ccv_nnc_hint_t hint, ccv_nnc_tensor_param_t* const outputs, const int output_size)
    21
    0
    {
    22
    0
      outputs[0] = inputs[0];
    23
    0
      outputs[0].datatype = CCV_32S;
    24
    0
      memset(outputs[0].dim, 0, sizeof(outputs[0].dim));
    25
    0
      switch (cmd.histogram.type)
    26
    0
      {
    27
    0
        case CCV_NNC_HISTOGRAM_BINS:
    28
    0
        {
    29
    0
          assert(input_size >= 2);
    30
    0
          outputs[0].dim[0] = ccv_nnc_tensor_count(inputs[1]) + 2;
    31
    0
          break;
    32
    0
        }
    33
    0
        case CCV_NNC_HISTOGRAM_EVEN:
    34
    0
        {
    35
    0
          outputs[0].dim[0] = cmd.histogram.bins + 3;
    36
    0
          break;
    37
    0
        }
    38
    0
        case CCV_NNC_HISTOGRAM_LOGARITHMIC:
    39
    0
        {
    40
    0
          const float log_base = 1.0 / logf(cmd.histogram.rate);
    41
    0
          const int upper_range = ceilf(logf(cmd.histogram.max / cmd.histogram.min) * log_base);
    42
    0
          outputs[0].dim[0] = upper_range * 2 + 2;
    43
    0
          break;
    44
    0
        }
    45
    0
      }
    46
    0
      if (output_size >= 2)
    47
    0
      {
    48
        // These for stats, min, max, sum, sum of squares).
    49
    0
        outputs[1] = inputs[0];
    50
    0
        memset(outputs[1].dim, 0, sizeof(outputs[1].dim));
    51
    0
        outputs[1].dim[0] = 4;
    52
    0
      }
    53
    0
    }
    54
    55
    static void _ccv_nnc_histogram_tensor_auto_back(const ccv_nnc_cmd_param_t cmd, const ccv_nnc_tensor_param_t* const inputs, const int input_size, const ccv_nnc_hint_t hint, ccv_nnc_tensor_param_t* const outputs, const int output_size)
    56
    0
    {
    57
      // Doesn't support.
    58
    0
    }
    59
    60
    REGISTER_COMMAND(CCV_NNC_HISTOGRAM_FORWARD)(ccv_nnc_cmd_registry_t* const registry)
    61
      FIND_BACKEND(ccv_nnc_histogram_cpu_ref.c)
    62
    1
    {
    63
    1
      registry->bitmask = _ccv_nnc_histogram_forw_bitmask;
    64
    1
      registry->tensor_auto = _ccv_nnc_histogram_tensor_auto_forw;
    65
    1
    }
    66
    67
    REGISTER_COMMAND(CCV_NNC_HISTOGRAM_BACKWARD)(ccv_nnc_cmd_registry_t* const registry)
    68
      FIND_BACKEND(ccv_nnc_histogram_cpu_ref.c)
    69
    1
    {
    70
    1
      registry->bitmask = _ccv_nnc_histogram_back_bitmask;
    71
    1
      registry->tensor_auto = _ccv_nnc_histogram_tensor_auto_back;
    72
    1
    }
    73
    74
    //@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_HISTOGRAM_FORWARD)
    75
    #define CMD_HISTOGRAM_EVEN(_bins, _min, _max) ccv_nnc_cmd(CCV_NNC_HISTOGRAM_FORWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={1,1,1}},.histogram={.type=CCV_NNC_HISTOGRAM_EVEN,.bins=_bins,.min=_min,.max=_max}}), 0)
    76
    //@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_HISTOGRAM_FORWARD)
    77
    #define CMD_HISTOGRAM_LOG_X_0() ccv_nnc_cmd(CCV_NNC_HISTOGRAM_FORWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={1,1,1}},.histogram={.type=CCV_NNC_HISTOGRAM_LOGARITHMIC,.min=1e-12,.max=1e20,.rate=1.1}}), 0)
    78
    #define CMD_HISTOGRAM_LOG_X_F(...) ("This should not be used, you should have either 0 parameter or 3 parameters for CMD_HISTOGRAM_LOG")
    79
    #define CMD_HISTOGRAM_LOG_X_2(_min, _max, _rate) ccv_nnc_cmd(CCV_NNC_HISTOGRAM_FORWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={1,1,1}},.histogram={.type=CCV_NNC_HISTOGRAM_LOGARITHMIC,.min=_min,.max=_max,.rate=_rate}}), 0)
    80
    #define CMD_HISTOGRAM_LOG_X_SEL(_0, _1, _2, _3, _FX, ...) _FX
    81
    #define CMD_HISTOGRAM_LOG(...) CMD_HISTOGRAM_LOG_X_SEL(CMD_HISTOGRAM_LOG_X_F, ##__VA_ARGS__, CMD_HISTOGRAM_LOG_X_3, CMD_HISTOGRAM_LOG_X_F, CMD_HISTOGRAM_LOG_X_F, CMD_HISTOGRAM_LOG_X_0)(__VA_ARGS__)
    82
    //@REGISTER_EASY_COMMAND_MACRO(CCV_NNC_HISTOGRAM_FORWARD)
    83
    #define CMD_HISTOGRAM_BINS() ccv_nnc_cmd(CCV_NNC_HISTOGRAM_FORWARD, 0, ((ccv_nnc_cmd_param_t){.size={.dim={1,1,1}},.histogram={.type=CCV_NNC_HISTOGRAM_BINS}}), 0)