Skip to content

Commit f09dbb7

Browse files
committed
Add a new bunch of tests
1 parent e022963 commit f09dbb7

File tree

4 files changed

+61
-41
lines changed

4 files changed

+61
-41
lines changed

blosc/b2nd.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,11 +1342,10 @@ int b2nd_concatenate(b2nd_context_t *ctx, const b2nd_array_t *src1, const b2nd_a
13421342
src1_shape[i] = src1->shape[i];
13431343
}
13441344

1345-
if (copy) {
1346-
BLOSC_ERROR(b2nd_copy(ctx, src1, array));
1347-
} else
1348-
{
1349-
*array = src1;
1345+
// Support for 0-dim arrays is not implemented
1346+
if (src1->ndim == 0 || src2->ndim == 0) {
1347+
BLOSC_TRACE_ERROR("Concatenation of 0-dim arrays is not supported");
1348+
BLOSC_ERROR(BLOSC2_ERROR_INVALID_PARAM);
13501349
}
13511350

13521351
// Check that the shapes are compatible for concatenation
@@ -1368,6 +1367,13 @@ int b2nd_concatenate(b2nd_context_t *ctx, const b2nd_array_t *src1, const b2nd_a
13681367
}
13691368
}
13701369

1370+
if (copy) {
1371+
BLOSC_ERROR(b2nd_copy(ctx, src1, array));
1372+
}
1373+
else {
1374+
*array = (b2nd_array_t *)src1;
1375+
}
1376+
13711377
// Extend the array, we don't need to specify the start in resize, as we are extending the shape from the end
13721378
BLOSC_ERROR(b2nd_resize(*array, newshape, NULL));
13731379

blosc/blosc2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4307,7 +4307,7 @@ int blosc2_chunk_zeros(blosc2_cparams cparams, const int32_t nbytes, void* dest,
43074307
return BLOSC2_ERROR_DATA;
43084308
}
43094309

4310-
if (nbytes % cparams.typesize) {
4310+
if ((nbytes > 0) && (nbytes % cparams.typesize)) {
43114311
BLOSC_TRACE_ERROR("nbytes must be a multiple of typesize");
43124312
return BLOSC2_ERROR_DATA;
43134313
}

blosc/frame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,7 @@ int frame_get_chunk(blosc2_frame_s *frame, int64_t nchunk, uint8_t **chunk, bool
21462146
return rc;
21472147
}
21482148

2149-
if (nchunk >= nchunks) {
2149+
if ((nchunks > 0) && (nchunk >= nchunks)) {
21502150
BLOSC_TRACE_ERROR("nchunk ('%" PRId64 "') exceeds the number of chunks "
21512151
"('%" PRId64 "') in frame.", nchunk, nchunks);
21522152
return BLOSC2_ERROR_INVALID_PARAM;

tests/b2nd/test_b2nd_concatenate.c

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212

1313
typedef struct {
1414
int8_t ndim;
15-
int64_t shape1[B2ND_MAX_DIM];
16-
int32_t chunkshape1[B2ND_MAX_DIM];
17-
int32_t blockshape1[B2ND_MAX_DIM];
18-
int64_t shape2[B2ND_MAX_DIM];
19-
int32_t chunkshape2[B2ND_MAX_DIM];
20-
int32_t blockshape2[B2ND_MAX_DIM];
15+
int8_t axis;
16+
int64_t shape1[B2ND_MAX_DIM];
17+
int32_t chunkshape1[B2ND_MAX_DIM];
18+
int32_t blockshape1[B2ND_MAX_DIM];
19+
int64_t shape2[B2ND_MAX_DIM];
20+
int32_t chunkshape2[B2ND_MAX_DIM];
21+
int32_t blockshape2[B2ND_MAX_DIM];
2122
} test_shapes_t;
2223

2324

@@ -78,44 +79,56 @@ CUTEST_TEST_SETUP(concatenate) {
7879
// Add parametrization
7980
CUTEST_PARAMETRIZE(typesize, uint8_t, CUTEST_DATA(
8081
1,
81-
// 2,
82-
// 4,
83-
// 8,
82+
// 2,
83+
// 4,
84+
8,
85+
13,
8486
));
8587

8688
CUTEST_PARAMETRIZE(backend, _test_backend, CUTEST_DATA(
8789
{false, false},
88-
// {true, false},
89-
// {true, true},
90-
// {false, true},
90+
{true, false},
91+
{true, true},
92+
{false, true},
9193
));
9294

9395

9496
CUTEST_PARAMETRIZE(shapes, test_shapes_t, CUTEST_DATA(
95-
// {0, {0}, {0}, {0}, {0}, {0}}, // 0-dim
96-
// {1, {5}, {3}, {2}, {2}, {5}}, // 1-idim
97-
// {2, {20, 0}, {7, 0}, {3, 0}, {2, 0}, {8, 0}}, // 0-shape
98-
// {2, {20, 10}, {7, 5}, {3, 5}, {2, 0}, {18, 0}}, // 0-shape
99-
// {2, {14, 10}, {8, 5}, {2, 2}, {5, 3}, {9, 10}},
100-
// {3, {12, 10, 14}, {3, 5, 9}, {3, 4, 4}, {3, 0, 3}, {6, 7, 10}},
101-
// {4, {10, 21, 30, 5}, {8, 7, 15, 3}, {5, 5, 10, 1}, {5, 4, 3, 3}, {10, 8, 8, 4}},
102-
{2, {50, 50}, {25, 13}, {5, 8}, {50, 50}, {25, 13}, {5, 8}},
103-
// {2, {150, 45}, {15, 15}, {7, 7}, {4, 2}, {6, 5}},
104-
// {2, {10, 10}, {5, 7}, {2, 2}, {0, 0}, {5, 5}},
105-
// // Checks for fast path in setting a single chunk that is C contiguous
106-
// {2, {20, 20}, {10, 10}, {5, 10}, {10, 10}, {20, 20}},
107-
// {3, {3, 4, 5}, {1, 4, 5}, {1, 2, 5}, {1, 0, 0}, {2, 4, 5}},
108-
// {3, {3, 8, 5}, {1, 4, 5}, {1, 2, 5}, {1, 4, 0}, {2, 8, 5}},
97+
// 0-dim is not supported in concatenate
98+
// {0, 0, {0}, {0}, {0}, {0}, {0}, {0}},
99+
// 1-dim
100+
{1, 0, {50}, {25}, {5}, {20}, {25}, {5}},
101+
{1, 0, {2}, {25}, {5}, {49}, {25}, {5}},
102+
// 2-dim
103+
{2, 0, {50, 50}, {25, 13}, {5, 8}, {50, 50}, {25, 13}, {5, 8}},
104+
{2, 1, {50, 50}, {25, 13}, {5, 8}, {50, 50}, {25, 13}, {5, 8}},
105+
{2, 0, {25, 50}, {25, 25}, {5, 5}, {2, 50}, {25, 25}, {5, 5}},
106+
{2, 1, {25, 50}, {25, 25}, {5, 5}, {25, 5}, {25, 25}, {5, 5}},
107+
// 3-dim
108+
{3, 0, {50, 5, 50}, {25, 13, 10}, {5, 8, 5}, {50, 5, 50}, {25, 13, 10}, {5, 8, 5}},
109+
{3, 1, {50, 5, 50}, {25, 13, 10}, {5, 8, 5}, {50, 5, 50}, {25, 13, 10}, {5, 8, 5}},
110+
{3, 2, {50, 5, 50}, {25, 13, 10}, {5, 8, 5}, {50, 5, 50}, {25, 13, 10}, {5, 8, 5}},
111+
{3, 0, {5, 5, 50}, {25, 13, 10}, {5, 8, 5}, {51, 5, 50}, {25, 13, 10}, {5, 8, 5}},
112+
// Inner 0-dims are supported
113+
{3, 1, {50, 1, 50}, {25, 13, 10}, {5, 8, 5}, {50, 0, 50}, {25, 13, 10}, {5, 8, 5}},
114+
// TODO: the next is not working yet
115+
// {3, 2, {50, 50, 0}, {25, 13, 10}, {5, 8, 5}, {50, 50, 49}, {25, 13, 10}, {5, 8, 5}},
116+
// 4-dim
117+
{4, 0, {5, 5, 5, 5}, {2, 5, 10, 5}, {5, 2, 5, 2}, {5, 5, 5, 5}, {5, 5, 10, 5}, {5, 2, 5, 2}},
118+
{4, 1, {5, 5, 5, 5}, {2, 5, 10, 5}, {5, 2, 5, 2}, {5, 5, 5, 5}, {5, 5, 10, 5}, {5, 2, 5, 2}},
119+
{4, 2, {5, 5, 5, 5}, {2, 13, 10, 5}, {5, 8, 5, 2}, {5, 5, 5, 5}, {5, 13, 10, 5}, {5, 8, 5, 2}},
120+
{4, 3, {5, 5, 5, 5}, {2, 13, 10, 5}, {5, 8, 5, 2}, {5, 5, 5, 5}, {5, 13, 10, 5}, {5, 8, 5, 2}},
121+
{4, 0, {5, 5, 5, 5}, {2, 13, 10, 5}, {5, 8, 5, 2}, {6, 5, 5, 5}, {15, 13, 10, 5}, {5, 8, 5, 2}},
122+
{4, 1, {5, 5, 5, 5}, {2, 13, 10, 5}, {5, 8, 5, 2}, {5, 6, 5, 5}, {15, 13, 10, 5}, {5, 8, 5, 2}},
123+
{4, 2, {5, 5, 5, 5}, {2, 13, 10, 5}, {5, 8, 5, 2}, {5, 5, 6, 5}, {15, 13, 10, 5}, {5, 8, 5, 2}},
124+
{4, 3, {5, 5, 5, 5}, {2, 13, 10, 5}, {5, 8, 5, 2}, {5, 5, 5, 6}, {15, 13, 10, 5}, {5, 8, 5, 2}},
125+
109126
));
110127
CUTEST_PARAMETRIZE(fill_value, int8_t, CUTEST_DATA(
111128
3,
129+
-5,
112130
// 113,
113131
// 33,
114-
// -5
115-
));
116-
CUTEST_PARAMETRIZE(axis, int8_t, CUTEST_DATA(
117-
0,
118-
1,
119132
));
120133
CUTEST_PARAMETRIZE(copy, bool, CUTEST_DATA(
121134
true,
@@ -129,9 +142,9 @@ CUTEST_TEST_TEST(concatenate) {
129142
CUTEST_GET_PARAMETER(shapes, test_shapes_t);
130143
CUTEST_GET_PARAMETER(typesize, uint8_t);
131144
CUTEST_GET_PARAMETER(fill_value, int8_t);
132-
CUTEST_GET_PARAMETER(axis, int8_t);
133145
CUTEST_GET_PARAMETER(copy, bool);
134146

147+
int axis = shapes.axis;
135148
char *urlpath = "test_concatenate.b2frame";
136149
char *urlpath1 = "test_concatenate1.b2frame";
137150
char *urlpath2 = "test_concatenate2.b2frame";
@@ -258,8 +271,9 @@ CUTEST_TEST_TEST(concatenate) {
258271
}
259272

260273
// Check the data in the concatenated array
261-
printf("Array shapes: %d x %d\n", (int)array->shape[0], (int)array->shape[1]);
262-
printf("Helperbuffer shapes: %d x %d\n", (int)helpershape[0], (int)helpershape[1]);
274+
printf("Array ndim: %d\n", array->ndim);
275+
printf("Array shapes: %d x %d x %d x %d\n", (int)array->shape[0], (int)array->shape[1], (int)array->shape[2], (int)array->shape[3]);
276+
printf("Helperbuffer shapes: %d x %d x %d x %d\n", (int)helpershape[0], (int)helpershape[1], (int)helpershape[2], (int)helpershape[3]);
263277
printf("Axis: %d\n", axis);
264278

265279
int64_t start[B2ND_MAX_DIM] = {0};

0 commit comments

Comments
 (0)