## 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/dataframe.addons.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("derive one-hot tensor from label")
    15
    1
    {
    16
    1
      int int_array[8] = {
    17
    1
        2, 3, 4, 5, 6, 7, 8, 9
    18
    1
      };
    19
    1
      ccv_array_t* const array = ccv_array_new(sizeof(int), 8, 0);
    20
    1
      ccv_array_resize(array, 8);
    21
    1
      memcpy(ccv_array_get(array, 0), int_array, sizeof(int) * 8);
    22
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_array_new(array);
    23
    1
      const int oh = ccv_cnnp_dataframe_one_hot(dataframe, 0, 0, 10, 1, 0, CCV_32F, CCV_TENSOR_FORMAT_NCHW, 0);
    24
    1
      assert(oh > 0);
    25
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(dataframe, COLUMN_ID_LIST(oh));
    26
    1
      ccv_nnc_tensor_t* const one_hot = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32F, 10), 0);
    27
    1
      void* data;
    28
    1
      int i = 0, j;
    29
    9
      while (0 == ccv_cnnp_dataframe_iter_next(iter, &data, 1, 0))
    30
    8
      {
    31
    88
        for (j = 0; j < 10; j++80)
    32
    80
          one_hot->data.f32[j] = 0;
    33
    8
        one_hot->data.f32[int_array[i]] = 1;
    34
    8
        REQUIRE_TENSOR_EQ(one_hot, (ccv_nnc_tensor_t*)data, "The one-hot tensor should be the same");
    35
    8
        ++i;
    36
    8
      }
    37
    1
      ccv_cnnp_dataframe_iter_free(iter);
    38
    1
      ccv_cnnp_dataframe_free(dataframe);
    39
    1
      ccv_nnc_tensor_free(one_hot);
    40
    1
      ccv_array_free(array);
    41
    1
    }
    42
    43
    TEST_CASE("derive a scalar tensor from a struct")
    44
    1
    {
    45
    1
      int int_array[8] = {
    46
    1
        2, 3, 4, 5, 6, 7, 8, 9
    47
    1
      };
    48
    1
      ccv_array_t* const array = ccv_array_new(sizeof(int), 8, 0);
    49
    1
      ccv_array_resize(array, 8);
    50
    1
      memcpy(ccv_array_get(array, 0), int_array, sizeof(int) * 8);
    51
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_array_new(array);
    52
    1
      const int st = ccv_cnnp_dataframe_copy_scalar(dataframe, 0, 0, CCV_32S, CCV_32F, CCV_TENSOR_FORMAT_NCHW, 0);
    53
    1
      assert(st > 0);
    54
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(dataframe, COLUMN_ID_LIST(st));
    55
    1
      ccv_nnc_tensor_t* const scalar = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32F, 1), 0);
    56
    1
      void* data;
    57
    1
      int i = 0;
    58
    9
      while (0 == ccv_cnnp_dataframe_iter_next(iter, &data, 1, 0))
    59
    8
      {
    60
    8
        scalar->data.f32[0] = int_array[i];
    61
    8
        REQUIRE_TENSOR_EQ(scalar, (ccv_nnc_tensor_t*)data, "The scalar tensor should be the same");
    62
    8
        ++i;
    63
    8
      }
    64
    1
      ccv_cnnp_dataframe_iter_free(iter);
    65
    1
      ccv_cnnp_dataframe_free(dataframe);
    66
    1
      ccv_nnc_tensor_free(scalar);
    67
    1
      ccv_array_free(array);
    68
    1
    }
    69
    70
    TEST_CASE("combine tensors")
    71
    1
    {
    72
    1
      int int_array[8] = {
    73
    1
        2, 3, 4, 5, 6, 7, 8, 9
    74
    1
      };
    75
    1
      ccv_array_t* const array = ccv_array_new(sizeof(int), 8, 0);
    76
    1
      ccv_array_resize(array, 8);
    77
    1
      memcpy(ccv_array_get(array, 0), int_array, sizeof(int) * 8);
    78
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_array_new(array);
    79
    1
      const int oh = ccv_cnnp_dataframe_one_hot(dataframe, 0, 0, 10, 1, 0, CCV_32F, CCV_TENSOR_FORMAT_NCHW, 0);
    80
    1
      assert(oh > 0);
    81
    1
      ccv_cnnp_dataframe_t* const batch = ccv_cnnp_dataframe_combine_new(dataframe, COLUMN_ID_LIST(oh), 3, 2, CCV_TENSOR_FORMAT_NCHW);
    82
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(batch, COLUMN_ID_LIST(0));
    83
    1
      ccv_nnc_tensor_t* const one_hot = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32F, 3, 10), 0);
    84
    1
      void* data;
    85
    1
      int i = 0, j;
    86
    1
      ccv_cnnp_dataframe_iter_next(iter, &data, 1, 0);
    87
    4
      for (i = 0; i < 3; i++3)
    88
    3
      {
    89
    33
        for (j = 0; j < 10; j++30)
    90
    30
          one_hot->data.f32[i * 10 + j] = 0;
    91
    3
        one_hot->data.f32[i * 10 + int_array[i]] = 1;
    92
    3
      }
    93
    1
      REQUIRE_TENSOR_EQ(one_hot, ((ccv_nnc_tensor_t**)data)[0], "The one-hot tensor should be the same");
    94
    4
      for (i = 0; i < 3; i++3)
    95
    3
      {
    96
    33
        for (j = 0; j < 10; j++30)
    97
    30
          one_hot->data.f32[i * 10 + j] = 0;
    98
    3
        one_hot->data.f32[i * 10 + int_array[i + 3]] = 1;
    99
    3
      }
    100
    1
      REQUIRE_TENSOR_EQ(one_hot, ((ccv_nnc_tensor_t**)data)[1], "The one-hot tensor should be the same");
    101
    1
      ccv_cnnp_dataframe_iter_free(iter);
    102
    1
      ccv_cnnp_dataframe_free(batch);
    103
    1
      ccv_cnnp_dataframe_free(dataframe);
    104
    1
      ccv_nnc_tensor_free(one_hot);
    105
    1
      ccv_array_free(array);
    106
    1
    }
    107
    108
    #ifdef HAVE_LIBPNG
    109
    TEST_CASE("read image and add random jitter")
    110
    1
    {
    111
    1
      ccv_dense_matrix_t* image = 0;
    112
    1
      ccv_read("../../../samples/nature.png", &image, CCV_IO_RGB_COLOR | CCV_IO_ANY_FILE);
    113
    1
      ccv_array_t* const array = ccv_array_new(sizeof(ccv_dense_matrix_t), 1, 0);
    114
    1
      ccv_array_push(array, image);
    115
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_array_new(array);
    116
    1
      const ccv_cnnp_random_jitter_t random_jitter = {
    117
    1
        .resize = {
    118
    1
          .min = 200,
    119
    1
          .max = 200,
    120
    1
        },
    121
    1
        .size = {
    122
    1
          .rows = 224,
    123
    1
          .cols = 224,
    124
    1
        },
    125
    1
        .normalize = {
    126
    1
          .mean = {
    127
    1
            123.68, 116.779, 103.939
    128
    1
          },
    129
    1
          .std = {
    130
    1
            58.393, 57.12, 57.375
    131
    1
          },
    132
    1
        },
    133
    1
        .offset = {
    134
    1
          .x = 10,
    135
    1
          .y = 10,
    136
    1
        },
    137
    1
        .aspect_ratio = 0.33,
    138
    1
        .contrast = 0.4,
    139
    1
        .saturation = 0.4,
    140
    1
        .brightness = 0.4,
    141
    1
        .lighting = 0.1,
    142
    1
        .seed = 1,
    143
    1
      };
    144
    1
      const int im = ccv_cnnp_dataframe_image_random_jitter(dataframe, 0, CCV_32F, random_jitter, 0);
    145
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(dataframe, COLUMN_ID_LIST(im));
    146
    1
      ccv_dense_matrix_t* data;
    147
    1
      ccv_cnnp_dataframe_iter_next(iter, (void**)&data, 1, 0);
    148
    1
      ccv_dense_matrix_t* gt = 0;
    149
    1
      ccv_read("data/nature.random-jitter.bin", &gt, CCV_IO_ANY_FILE);
    150
      // I cannot use REQUIRE_MATRIX_FILE_EQ here because ccv_matrix_eq is too strict.
    151
    1
      REQUIRE_ARRAY_EQ_WITH_TOLERANCE(float, data->data.f32, gt->data.f32, 224 * 224 * 3, 1e-6, "should be the same random jitter image.");
    152
    1
      ccv_matrix_free(gt);
    153
    1
      ccv_matrix_free(image);
    154
    1
      ccv_array_free(array);
    155
    1
      ccv_cnnp_dataframe_iter_free(iter);
    156
    1
      ccv_cnnp_dataframe_free(dataframe);
    157
    1
    }
    158
    #endif
    159
    160
    TEST_CASE("execute command from dataframe addons API")
    161
    1
    {
    162
    1
      ccv_nnc_tensor_t* input = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32F, 1), 0);
    163
    1
      input->data.f32[0] = 183;
    164
    1
      ccv_array_t* const array = ccv_array_new(sizeof(ccv_nnc_tensor_t), 1, 0);
    165
    1
      ccv_array_push(array, input);
    166
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_array_new(array);
    167
    1
      const int tuple_idx = ccv_cnnp_dataframe_make_tuple(dataframe, COLUMN_ID_LIST(0), 0);
    168
    1
      const ccv_nnc_tensor_param_t output_param = CPU_TENSOR_NCHW(32F, 1);
    169
    1
      const int log_idx = ccv_cnnp_dataframe_cmd_exec(dataframe, tuple_idx, CMD_EWLOG_FORWARD(), ccv_nnc_no_hint, 0, 0, 1, &output_param, 1, CCV_STREAM_CONTEXT_CPU, 0);
    170
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(dataframe, COLUMN_ID_LIST(log_idx));
    171
    1
      ccv_nnc_tensor_t** data = 0;
    172
    1
      ccv_cnnp_dataframe_iter_next(iter, (void**)&data, 1, 0);
    173
    1
      REQUIRE_EQ_WITH_TOLERANCE(data[0]->data.f32[0], log(183), 1e-6, "should be equal to the log(183)");
    174
    1
      ccv_nnc_tensor_free(input);
    175
    1
      ccv_array_free(array);
    176
    1
      ccv_cnnp_dataframe_iter_free(iter);
    177
    1
      ccv_cnnp_dataframe_free(dataframe);
    178
    1
    }
    179
    180
    TEST_CASE("sequence mask generation")
    181
    1
    {
    182
    1
      ccv_nnc_tensor_t* input = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32S, 2), 0);
    183
    1
      input->data.i32[0] = 2;
    184
    1
      input->data.i32[1] = 3;
    185
    1
      ccv_array_t* const array = ccv_array_new(sizeof(ccv_nnc_tensor_t), 1, 0);
    186
    1
      ccv_array_push(array, input);
    187
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_array_new(array);
    188
    1
      const int one_idx = ccv_cnnp_dataframe_one_squared(dataframe, COLUMN_ID_LIST(0), 0, 4, 0);
    189
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(dataframe, COLUMN_ID_LIST(one_idx));
    190
    1
      ccv_nnc_tensor_t** data = 0;
    191
    1
      ccv_cnnp_dataframe_iter_next(iter, (void**)&data, 1, 0);
    192
    1
      REQUIRE_EQ(data[0]->info.dim[0], 2, "batch size is 2");
    193
    1
      REQUIRE_EQ(data[0]->info.dim[1], 4, "4 is the row number");
    194
    1
      REQUIRE_EQ(data[0]->info.dim[2], 4, "4 is the column number");
    195
    1
      int b[2 * 4 * 4] = {
    196
    1
        1, 1, 0, 0,
    197
    1
        1, 1, 0, 0,
    198
    1
        0, 0, 0, 0,
    199
    1
        0, 0, 0, 0,
    200
    1
        1, 1, 1, 0,
    201
    1
        1, 1, 1, 0,
    202
    1
        1, 1, 1, 0,
    203
    1
        0, 0, 0, 0,
    204
    1
      };
    205
    1
      REQUIRE_ARRAY_EQ(int, data[0]->data.i32, b, 2 * 4 * 4, "should match the mask");
    206
    1
      ccv_nnc_tensor_free(input);
    207
    1
      ccv_array_free(array);
    208
    1
      ccv_cnnp_dataframe_iter_free(iter);
    209
    1
      ccv_cnnp_dataframe_free(dataframe);
    210
    1
    }
    211
    212
    TEST_CASE("sequence mask generation with variable size")
    213
    1
    {
    214
    1
      ccv_nnc_tensor_t* input = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32S, 2), 0);
    215
    1
      input->data.i32[0] = 2;
    216
    1
      input->data.i32[1] = 3;
    217
    1
      ccv_array_t* const array = ccv_array_new(sizeof(ccv_nnc_tensor_t), 1, 0);
    218
    1
      ccv_array_push(array, input);
    219
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_array_new(array);
    220
    1
      const int one_idx = ccv_cnnp_dataframe_one_squared(dataframe, COLUMN_ID_LIST(0), 1, 4, 0);
    221
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(dataframe, COLUMN_ID_LIST(one_idx));
    222
    1
      ccv_nnc_tensor_t** data = 0;
    223
    1
      ccv_cnnp_dataframe_iter_next(iter, (void**)&data, 1, 0);
    224
    1
      REQUIRE_EQ(data[0]->info.dim[0], 2, "batch size is 2");
    225
    1
      REQUIRE_EQ(data[0]->info.dim[1], 3, "3 is the row number");
    226
    1
      REQUIRE_EQ(data[0]->info.dim[2], 3, "3 is the column number");
    227
    1
      int b[2 * 3 * 3] = {
    228
    1
        1, 1, 0,
    229
    1
        1, 1, 0,
    230
    1
        0, 0, 0,
    231
    1
        1, 1, 1,
    232
    1
        1, 1, 1,
    233
    1
        1, 1, 1,
    234
    1
      };
    235
    1
      REQUIRE_ARRAY_EQ(int, data[0]->data.i32, b, 2 * 3 * 3, "should match the mask");
    236
    1
      ccv_nnc_tensor_free(input);
    237
    1
      ccv_array_free(array);
    238
    1
      ccv_cnnp_dataframe_iter_free(iter);
    239
    1
      ccv_cnnp_dataframe_free(dataframe);
    240
    1
    }
    241
    242
    TEST_CASE("truncate a sequence")
    243
    1
    {
    244
    1
      ccv_nnc_tensor_t* input = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32F, 2, 4), 0);
    245
    1
      int i;
    246
    9
      for (i = 0; i < 2 * 4; i++8)
    247
    8
        input->data.f32[i] = i + 1;
    248
    1
      ccv_nnc_tensor_t* len = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32S, 2), 0);
    249
    1
      len->data.i32[0] = 2;
    250
    1
      len->data.i32[1] = 3;
    251
    1
      ccv_array_t* const array = ccv_array_new(sizeof(ccv_nnc_tensor_t *[2]), 1, 0);
    252
    1
      ccv_nnc_tensor_t* pair[2] = { input, len };
    253
    1
      ccv_array_push(array, pair);
    254
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_array_new(array);
    255
    1
      const int input_idx = ccv_cnnp_dataframe_extract_tuple(dataframe, 0, 0, 0);
    256
    1
      const int len_idx = ccv_cnnp_dataframe_extract_tuple(dataframe, 0, 1, 0);
    257
    1
      const int trunc_idx = ccv_cnnp_dataframe_truncate(dataframe, COLUMN_ID_LIST(input_idx), COLUMN_ID_LIST(len_idx), 0);
    258
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(dataframe, COLUMN_ID_LIST(trunc_idx));
    259
    1
      ccv_nnc_tensor_t** data = 0;
    260
    1
      ccv_cnnp_dataframe_iter_next(iter, (void**)&data, 1, 0);
    261
    1
      REQUIRE_EQ(data[0]->info.dim[0], 2, "batch size is 2");
    262
    1
      REQUIRE_EQ(data[0]->info.dim[1], 3, "3 is the row number");
    263
    1
      float b[2 * 3] = {
    264
    1
        1, 2, 3, // 4,
    265
    1
        5, 6, 7, // 8,
    266
    1
      };
    267
    1
      REQUIRE_ARRAY_EQ_WITH_TOLERANCE(float, data[0]->data.f32, b, 2 * 3, 1e-5, "should match the mask");
    268
    1
      ccv_nnc_tensor_free(input);
    269
    1
      ccv_nnc_tensor_free(len);
    270
    1
      ccv_array_free(array);
    271
    1
      ccv_cnnp_dataframe_iter_free(iter);
    272
    1
      ccv_cnnp_dataframe_free(dataframe);
    273
    1
    }
    274
    275
    TEST_CASE("read a csv file")
    276
    1
    {
    277
    1
      FILE* f = fopen("data/quote.csv", "r");
    278
    1
      int column_size = 0;
    279
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_csv_new(f, CCV_CNNP_DATAFRAME_CSV_FILE, 0, ',', '"', 0, &column_size);
    280
    1
      fclose(f);
    281
    1
      REQUIRE_EQ(column_size, 4, "has 4 columns based on header");
    282
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(dataframe, COLUMN_ID_LIST(1));
    283
    1
      void* data = 0;
    284
    1
      ccv_cnnp_dataframe_iter_next(iter, &data, 1, 0);
    285
    1
      REQUIRE(strcmp(data, "\"header\" 2") == 0, "first line is header");
    286
    1
      ccv_cnnp_dataframe_iter_next(iter, &data, 1, 0);
    287
    1
      REQUIRE(strcmp(data, "b") == 0, "b");
    288
    1
      ccv_cnnp_dataframe_iter_next(iter, &data, 1, 0);
    289
    1
      REQUIRE(strcmp(data, "d") == 0, "d");
    290
    1
      ccv_cnnp_dataframe_iter_next(iter, &data, 1, 0);
    291
    1
      REQUIRE(strcmp(data, "f") == 0, "f");
    292
    1
      ccv_cnnp_dataframe_iter_next(iter, &data, 1, 0);
    293
    1
      REQUIRE(data == 0, "nullptr");
    294
    1
      ccv_cnnp_dataframe_iter_free(iter);
    295
    1
      ccv_cnnp_dataframe_free(dataframe);
    296
    1
    }
    297
    298
    TEST_CASE("read a larger csv file")
    299
    1
    {
    300
    1
      FILE* f = fopen("data/scaled_data.csv", "r");
    301
    1
      int column_size = 0;
    302
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_csv_new(f, CCV_CNNP_DATAFRAME_CSV_FILE, 0, ',', '"', 0, &column_size);
    303
    1
      fclose(f);
    304
    1
      REQUIRE_EQ(column_size, 3213, "has 3213 columns based on header");
    305
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(dataframe, COLUMN_ID_LIST(1));
    306
    1
      const char* gt[] = {
    307
    1
        "V0001",
    308
    1
        "0.0239389181223648",
    309
    1
        "0.128521802419456",
    310
    1
        "0.157117194502824",
    311
    1
        "0.255931328978371",
    312
    1
        "0.160808946156887",
    313
    1
        "0.129455089453963",
    314
    1
        "0.0944587345381377",
    315
    1
        "0.0619675688122819",
    316
    1
        "0.125194372114953",
    317
    1
        "0.114054752304399",
    318
    1
        "0.0331194635169463",
    319
    1
        "0.0796469310314676",
    320
    1
        "0.0971290536167178",
    321
    1
        "0.0576220663889997",
    322
    1
        "0.134768058679109",
    323
    1
        "0.0655047474218985",
    324
    1
        "0.189655655632105",
    325
    1
        "-0.019471558855501",
    326
    1
        "-0.0161545694780594",
    327
    1
        "0.131137326326646",
    328
    1
        "0.160254357051892",
    329
    1
        "0.0506895539858365",
    330
    1
        "-0.01033458071889",
    331
    1
        "-0.12347980825132"
    332
    1
      };
    333
    1
      int i;
    334
    26
      for (i = 0; i < 25; i++25)
    335
    25
      {
    336
    25
        void* data = 0;
    337
    25
        ccv_cnnp_dataframe_iter_next(iter, &data, 1, 0);
    338
    25
        REQUIRE(strcmp(data, gt[i]) == 0, "should match ground truth");
    339
    25
      }
    340
    1
      ccv_cnnp_dataframe_iter_free(iter);
    341
    1
      ccv_cnnp_dataframe_free(dataframe);
    342
    1
    }
    343
    344
    TEST_CASE("read csv include header")
    345
    1
    {
    346
    1
      FILE* f = fopen("data/scaled_data.csv", "r");
    347
    1
      int column_size = 0;
    348
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_csv_new(f, CCV_CNNP_DATAFRAME_CSV_FILE, 0, ',', '"', 1, &column_size);
    349
    1
      fclose(f);
    350
    1
      REQUIRE_EQ(column_size, 3213, "has 3213 columns based on header");
    351
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(dataframe, COLUMN_ID_LIST(1));
    352
    1
      const char* gt[] = {
    353
    1
        "0.0239389181223648",
    354
    1
        "0.128521802419456",
    355
    1
        "0.157117194502824",
    356
    1
        "0.255931328978371",
    357
    1
        "0.160808946156887",
    358
    1
        "0.129455089453963",
    359
    1
        "0.0944587345381377",
    360
    1
        "0.0619675688122819",
    361
    1
        "0.125194372114953",
    362
    1
        "0.114054752304399",
    363
    1
        "0.0331194635169463",
    364
    1
        "0.0796469310314676",
    365
    1
        "0.0971290536167178",
    366
    1
        "0.0576220663889997",
    367
    1
        "0.134768058679109",
    368
    1
        "0.0655047474218985",
    369
    1
        "0.189655655632105",
    370
    1
        "-0.019471558855501",
    371
    1
        "-0.0161545694780594",
    372
    1
        "0.131137326326646",
    373
    1
        "0.160254357051892",
    374
    1
        "0.0506895539858365",
    375
    1
        "-0.01033458071889",
    376
    1
        "-0.12347980825132"
    377
    1
      };
    378
    1
      ccv_cnnp_dataframe_iter_prefetch(iter, 10, 0);
    379
    1
      int i;
    380
    25
      for (i = 0; i < 24; i++24)
    381
    24
      {
    382
    24
        void* data = 0;
    383
    24
        ccv_cnnp_dataframe_iter_next(iter, &data, 1, 0);
    384
    24
        REQUIRE(strcmp(data, gt[i]) == 0, "should match the ground truth");
    385
    24
      }
    386
    1
      REQUIRE(strcmp(ccv_cnnp_dataframe_column_name(dataframe, 2), "V0002") == 0, "shoould match the column name");
    387
    1
      REQUIRE(strcmp(ccv_cnnp_dataframe_column_name(dataframe, 0), "V0000") == 0, "shoould match the column name");
    388
    1
      REQUIRE(strcmp(ccv_cnnp_dataframe_column_name(dataframe, 1), "V0001") == 0, "shoould match the column name");
    389
    1
      ccv_cnnp_dataframe_iter_free(iter);
    390
    1
      ccv_cnnp_dataframe_free(dataframe);
    391
    1
    }
    392
    393
    TEST_CASE("read Windows csv")
    394
    1
    {
    395
    1
      FILE* f = fopen("data/win.csv", "r");
    396
    1
      int column_size = 0;
    397
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_csv_new(f, CCV_CNNP_DATAFRAME_CSV_FILE, 0, ',', '"', 0, &column_size);
    398
    1
      fclose(f);
    399
    1
      REQUIRE_EQ(column_size, 2, "has 2 columns");
    400
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(dataframe, COLUMN_ID_LIST(1));
    401
    1
      void* data = 0;
    402
    1
      ccv_cnnp_dataframe_iter_next(iter, &data, 1, 0);
    403
    1
      REQUIRE(strcmp(data, "def") == 0, "should match");
    404
    1
      ccv_cnnp_dataframe_iter_next(iter, &data, 1, 0);
    405
    1
      REQUIRE(strcmp(data, "ab\r\nd") == 0, "should match");
    406
    1
      ccv_cnnp_dataframe_iter_free(iter);
    407
    1
      ccv_cnnp_dataframe_free(dataframe);
    408
    1
    }
    409
    410
    static const char* long_text_01;
    411
    static const char* long_text_02;
    412
    static const char* long_text_30;
    413
    414
    TEST_CASE("read long text from csv")
    415
    1
    {
    416
    1
      FILE* f = fopen("data/long_text.csv", "r");
    417
    1
      int column_size = 0;
    418
    1
      ccv_cnnp_dataframe_t* const dataframe = ccv_cnnp_dataframe_from_csv_new(f, CCV_CNNP_DATAFRAME_CSV_FILE, 0, ',', '"', 0, &column_size);
    419
    1
      fclose(f);
    420
    1
      REQUIRE_EQ(column_size, 2, "has 2 columns");
    421
    1
      ccv_cnnp_dataframe_iter_t* const iter = ccv_cnnp_dataframe_iter_new(dataframe, COLUMN_ID_LIST(0, 1));
    422
    1
      void* data[2] = {};
    423
    1
      ccv_cnnp_dataframe_iter_next(iter, data, 2, 0);
    424
    1
      REQUIRE(strcmp(data[0], "abcdabcdabcdabcd") == 0, "should match");
    425
    1
      REQUIRE(strcmp(data[1], long_text_01) == 0, "should match");
    426
    1
      ccv_cnnp_dataframe_iter_next(iter, data, 2, 0);
    427
    1
      REQUIRE(strcmp(data[0], "abcdabcdabcdabcd") == 0, "should match");
    428
    1
      REQUIRE(strcmp(data[1], long_text_02) == 0, "should match");
    429
    1
      ccv_cnnp_dataframe_iter_next(iter, data, 2, 0);
    430
    1
      REQUIRE(strcmp(data[0], long_text_30) == 0, "should match");
    431
    1
      REQUIRE(strcmp(data[1], "bcdabcd") == 0, "should match");
    432
    1
      ccv_cnnp_dataframe_iter_free(iter);
    433
    1
      ccv_cnnp_dataframe_free(dataframe);
    434
    1
    }
    435
    436
    #include "case_main.h"
    437
    438
    static const char* long_text_01 = "[encoded data, 5761272 characters]";
    439
    static const char* long_text_02 = "abcdabcdabcdabcd\nab\"[encoded data, 5761254 characters]";
    440
    static const char* long_text_30 = "[encoded data, 5761254 characters]";