-
-
Notifications
You must be signed in to change notification settings - Fork 94
Open
Description
Describe the bug
Output of b2nd_get_slice_cbuffer is incorrect, values are from the array, but wrong indices.
To Reproduce
To reproduce the error, run this program:
#include <b2nd.h>
int main()
{
blosc2_init();
int32_t typesize = 8;
int8_t ndim = 4;
int64_t shape[4] = {2, 4, 2, 3};
uint64_t data[48] = {0}; // all zeros
data[0] = 5; // expected the first element at [0,0,0,0] to be 5
blosc2_cparams cparams = BLOSC2_CPARAMS_DEFAULTS;
cparams.typesize = typesize;
cparams.compcode = BLOSC_LZ4;
cparams.filters[0] = BLOSC_DELTA;
blosc2_storage b2_storage = BLOSC2_STORAGE_DEFAULTS;
b2_storage.cparams = &cparams;
int32_t chunkshape[4] = {2, 2, 1, 2};
int32_t blockshape[4] = {2, 1, 1, 2};
b2nd_context_t *ctx = b2nd_create_ctx(&b2_storage, ndim, shape, chunkshape, blockshape, NULL, 0, NULL, 0);
b2nd_array_t *array;
BLOSC_ERROR(b2nd_from_cbuffer(ctx, &array, data, sizeof(data)));
// Access [0, 1, 0, 0] [0:1, 1:2, 0:1, 0:1]
const int64_t slice1_start[] = {0, 1, 0, 0};
const int64_t slice1_stop[] = {1, 2, 1, 1};
uint64_t slice1_data[] = {0};
const int64_t slice1_data_shape[] = {1, 1, 1, 1};
BLOSC_ERROR(b2nd_get_slice_cbuffer(array, slice1_start, slice1_stop, slice1_data, slice1_data_shape, sizeof(slice1_data)));
printf("Reading arr[0,1,0,0], expected 0 actual %d (looks like arr[0,0,0,0])\n", slice1_data[0]);
BLOSC_ERROR(b2nd_free(array));
BLOSC_ERROR(b2nd_free_ctx(ctx));
blosc2_destroy();
}Output:
Reading arr[0,1,0,0], expected 0 actual 5 (looks like arr[0,0,0,0])Expected behavior
In the above example, we create an array of uint64 of shape [2, 4, 2, 3] with all zeros except the element at arr[0,0,0,0] which we initialize to 5.
When using b2nd_get_slice_cbuffer with a slice of [0:1, 1:2, 0:1, 0:1], trying to access a single element at index [0, 1, 0, 0] we expect to read 0, but we read 5.
System information:
- OS: Macos
- Compiler: clang
- Version: 2.21.3
Additional context
The issue is also reproducible with BLOSC_LZ4HC but not with BLOSC_BLOSCLZ.
The issue is not reproducible when removing the delta filter.
Thanks for the support ❤️
Metadata
Metadata
Assignees
Labels
No labels