Skip to content

Commit ba78acd

Browse files
committed
Support repeated values larger than 8-bit, also for n-dim arrays
1 parent ec9009d commit ba78acd

File tree

3 files changed

+34
-42
lines changed

3 files changed

+34
-42
lines changed

bench/b2nd/bench_get_slice.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main() {
2020
int nslices = 10;
2121

2222
int8_t ndim = 3;
23-
uint8_t itemsize = sizeof(DATA_TYPE);
23+
int32_t itemsize = sizeof(DATA_TYPE);
2424

2525
int64_t shape[] = {1250, 745, 400};
2626

blosc/b2nd_utils.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// copyNdim where N = {2-8} - specializations of copy loops to be used by b2nd_copy_buffer
1616
// since we don't have c++ templates, substitute manual specializations for up to known B2ND_MAX_DIM (8)
1717
// it's not pretty, but it substantially reduces overhead vs. the generic method
18-
void copy8dim(const uint8_t itemsize,
18+
void copy8dim(const int32_t itemsize,
1919
const int64_t *copy_shape,
2020
const uint8_t *bsrc, const int64_t *src_strides,
2121
uint8_t *bdst, const int64_t *dst_strides) {
@@ -57,7 +57,7 @@ void copy8dim(const uint8_t itemsize,
5757
} while (copy_start[0] < copy_shape[0]);
5858
}
5959

60-
void copy7dim(const uint8_t itemsize,
60+
void copy7dim(const int32_t itemsize,
6161
const int64_t *copy_shape,
6262
const uint8_t *bsrc, const int64_t *src_strides,
6363
uint8_t *bdst, const int64_t *dst_strides) {
@@ -95,7 +95,7 @@ void copy7dim(const uint8_t itemsize,
9595
} while (copy_start[0] < copy_shape[0]);
9696
}
9797

98-
void copy6dim(const uint8_t itemsize,
98+
void copy6dim(const int32_t itemsize,
9999
const int64_t *copy_shape,
100100
const uint8_t *bsrc, const int64_t *src_strides,
101101
uint8_t *bdst, const int64_t *dst_strides) {
@@ -129,7 +129,7 @@ void copy6dim(const uint8_t itemsize,
129129
} while (copy_start[0] < copy_shape[0]);
130130
}
131131

132-
void copy5dim(const uint8_t itemsize,
132+
void copy5dim(const int32_t itemsize,
133133
const int64_t *copy_shape,
134134
const uint8_t *bsrc, const int64_t *src_strides,
135135
uint8_t *bdst, const int64_t *dst_strides) {
@@ -159,7 +159,7 @@ void copy5dim(const uint8_t itemsize,
159159
} while (copy_start[0] < copy_shape[0]);
160160
}
161161

162-
void copy4dim(const uint8_t itemsize,
162+
void copy4dim(const int32_t itemsize,
163163
const int64_t *copy_shape,
164164
const uint8_t *bsrc, const int64_t *src_strides,
165165
uint8_t *bdst, const int64_t *dst_strides) {
@@ -185,7 +185,7 @@ void copy4dim(const uint8_t itemsize,
185185
} while (copy_start[0] < copy_shape[0]);
186186
}
187187

188-
void copy3dim(const uint8_t itemsize,
188+
void copy3dim(const int32_t itemsize,
189189
const int64_t *copy_shape,
190190
const uint8_t *bsrc, const int64_t *src_strides,
191191
uint8_t *bdst, const int64_t *dst_strides) {
@@ -207,7 +207,7 @@ void copy3dim(const uint8_t itemsize,
207207
} while (copy_start[0] < copy_shape[0]);
208208
}
209209

210-
void copy2dim(const uint8_t itemsize,
210+
void copy2dim(const int32_t itemsize,
211211
const int64_t *copy_shape,
212212
const uint8_t *bsrc, const int64_t *src_strides,
213213
uint8_t *bdst, const int64_t *dst_strides) {
@@ -223,7 +223,7 @@ void copy2dim(const uint8_t itemsize,
223223

224224

225225
void copy_ndim_fallback(const int8_t ndim,
226-
const uint8_t itemsize,
226+
const int32_t itemsize,
227227
int64_t *copy_shape,
228228
const uint8_t *bsrc, int64_t *src_strides,
229229
uint8_t *bdst, int64_t *dst_strides) {
@@ -268,13 +268,13 @@ int b2nd_copy_buffer2(int8_t ndim,
268268
}
269269

270270
// Compute the strides
271-
int64_t src_strides[B2ND_MAX_DIM];
271+
int64_t src_strides[B2ND_MAX_DIM] = {0};
272272
src_strides[ndim - 1] = 1;
273273
for (int i = ndim - 2; i >= 0; --i) {
274274
src_strides[i] = src_strides[i + 1] * src_pad_shape[i + 1];
275275
}
276276

277-
int64_t dst_strides[B2ND_MAX_DIM];
277+
int64_t dst_strides[B2ND_MAX_DIM] = {0};
278278
dst_strides[ndim - 1] = 1;
279279
for (int i = ndim - 2; i >= 0; --i) {
280280
dst_strides[i] = dst_strides[i + 1] * dst_pad_shape[i + 1];
@@ -332,14 +332,7 @@ int b2nd_copy_buffer(int8_t ndim,
332332
const void *src, const int64_t *src_pad_shape,
333333
const int64_t *src_start, const int64_t *src_stop,
334334
void *dst, const int64_t *dst_pad_shape,
335-
const int64_t *dst_start) __attribute__((deprecated("Use b2nd_copy_buffer2 instead")));
336-
337-
int b2nd_copy_buffer(int8_t ndim,
338-
uint8_t itemsize,
339-
const void *src, const int64_t *src_pad_shape,
340-
const int64_t *src_start, const int64_t *src_stop,
341-
void *dst, const int64_t *dst_pad_shape,
342-
const int64_t *dst_start) {
335+
const int64_t *dst_start) __attribute__((deprecated("Use b2nd_copy_buffer2 instead"))) {
343336
// Simply cast itemsize to int32_t and delegate
344337
return b2nd_copy_buffer2(ndim, (int32_t)itemsize, src, src_pad_shape,
345338
src_start, src_stop, dst, dst_pad_shape, dst_start);

tests/b2nd/test_b2nd_full.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,33 @@ CUTEST_TEST_SETUP(full) {
1717

1818
// Add parametrizations
1919
CUTEST_PARAMETRIZE(typesize, int32_t, CUTEST_DATA(
20-
//1, 2, 4, 8,
21-
256, //257, 256 * 256,
22-
// 256*256*256, 256*256*256*8, // these should work for small shapes as well, but are too slow
20+
1, 2, 4, 8, 16,
21+
255, 256, 257, // useful to testing typesizes equal or larger than 255
22+
// 256 * 256, // this should work for all shapes as well, but is too slow
23+
// 256*256*256, 256*256*256*8, // this should for work small shapes, but is way sloooower
2324
));
2425
CUTEST_PARAMETRIZE(shapes, _test_shapes, CUTEST_DATA(
25-
// {0, {0}, {0}, {0}}, // 0-dim
26-
// {1, {5}, {3}, {2}}, // 1-idim
27-
// {2, {20, 0}, {7, 0}, {3, 0}}, // 0-shape
28-
//{2, {20, 10}, {20, 10}, {10, 10}}, // funciona sempre
29-
//{2, {20, 10}, {10, 5}, {10, 5}}, // falla
30-
//{2, {4, 1}, {2, 1}, {2, 1}}, // falla
31-
{2, {1, 3}, {1, 2}, {1, 2}}, // falla
32-
//{1, {4}, {2}, {2}}, // funciona sempre
33-
//{2, {20, 10}, {8, 6}, {7, 5}}, // falla
34-
//{2, {20, 10}, {7, 5}, {3, 5}}, // falla
35-
//{2, {14, 10}, {8, 5}, {2, 2}}, // general,
36-
//{3, {12, 10, 14}, {3, 5, 9}, {3, 4, 4}}, // general
37-
//{3, {10, 21, 20, 5}, {8, 7, 15, 3}, {5, 5, 10, 1}}, // general,
26+
{0, {0}, {0}, {0}}, // 0-dim
27+
{1, {5}, {3}, {2}}, // 1-idim
28+
{2, {20, 0}, {7, 0}, {3, 0}}, // 0-shape
29+
{2, {20, 10}, {20, 10}, {10, 10}}, // simple 2-dim
30+
{2, {20, 10}, {10, 5}, {10, 5}}, // non-contiguous
31+
{2, {4, 1}, {2, 1}, {2, 1}},
32+
{2, {1, 3}, {1, 2}, {1, 2}},
33+
{2, {20, 10}, {8, 6}, {7, 5}},
34+
{2, {20, 10}, {7, 5}, {3, 5}},
35+
{2, {14, 10}, {8, 5}, {2, 2}},
36+
{3, {12, 10, 14}, {3, 5, 9}, {3, 4, 4}}, // 3-dim
37+
{4, {10, 21, 20, 5}, {8, 7, 15, 3}, {5, 5, 10, 1}}, // 4-dim
3838
));
3939
CUTEST_PARAMETRIZE(backend, _test_backend, CUTEST_DATA(
4040
{false, false},
41-
// {true, false},
42-
// {true, true},
43-
// {false, true},
41+
{true, false},
42+
{true, true},
43+
{false, true},
4444
));
4545
CUTEST_PARAMETRIZE(fill_value, int8_t, CUTEST_DATA(
46-
//3, 113, 33, -5
47-
3
46+
3, 113, 33, -5
4847
));
4948
}
5049

@@ -131,9 +130,9 @@ CUTEST_TEST_TEST(full) {
131130
}
132131
// Compare buffer_fill with buffer_dest
133132
is_true = memcmp(buffer_fill, buffer_dest, typesize) == 0;
134-
// print the 10 first bytes of buffer_fill and buffer_dest
133+
// print the N first bytes of buffer_fill and buffer_dest
135134
// printf("buffer_fill: ");
136-
// for (int j = 0; j < 10; ++j) {
135+
// for (int j = 0; j < 3; ++j) {
137136
// printf("%d vs %d ", buffer_fill[j], buffer_dest[j]);
138137
// }
139138
free(buffer_fill);

0 commit comments

Comments
 (0)