Skip to content

Commit

Permalink
When creating new arrays, infer chunksize from schunk
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescAlted committed Mar 29, 2024
1 parent fb22511 commit 1483050
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions blosc/b2nd.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ int array_new(b2nd_context_t *ctx, int special_value, b2nd_array_t **array) {
BLOSC_TRACE_ERROR("Pointer is NULL");
return BLOSC2_ERROR_FAILURE;
}
// Set the chunksize for the schunk, as it cannot be derived from storage
int32_t chunksize = (int32_t) (*array)->extchunknitems * sc->typesize;
sc->chunksize = chunksize;

// Serialize the dimension info
if (sc->nmetalayers >= BLOSC2_MAX_METALAYERS) {
Expand Down Expand Up @@ -274,7 +277,6 @@ int array_new(b2nd_context_t *ctx, int special_value, b2nd_array_t **array) {
}
// Fill schunk with uninit values
if ((*array)->nitems != 0) {
int32_t chunksize = (int32_t) (*array)->extchunknitems * sc->typesize;
int64_t nchunks = (*array)->extnitems / (*array)->chunknitems;
int64_t nitems = nchunks * (*array)->extchunknitems;
// blosc2_schunk_fill_special(sc, nitems, BLOSC2_SPECIAL_ZERO, chunksize);
Expand Down Expand Up @@ -621,8 +623,6 @@ int get_set_slice(void *buffer, int64_t buffersize, const int64_t *start, const
}

int32_t nblocks = (int32_t) array->extchunknitems / array->blocknitems;


if (set_slice) {
// Check if all the chunk is going to be updated and avoid the decompression
bool decompress_chunk = false;
Expand Down Expand Up @@ -1223,8 +1223,8 @@ int extend_shape(b2nd_array_t *array, const int64_t *new_shape, const int64_t *s
BLOSC_TRACE_ERROR("The new shape must be greater than the old one");
BLOSC_ERROR(BLOSC2_ERROR_INVALID_PARAM);
}
if (array->shape[i] == 0) {
BLOSC_TRACE_ERROR("Cannot extend array with shape[%d] = 0", i);
if (array->shape[i] == INT64_MAX) {
BLOSC_TRACE_ERROR("Cannot extend array with shape[%d] = %lld", i, INT64_MAX);
BLOSC_ERROR(BLOSC2_ERROR_INVALID_PARAM);
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/b2nd.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ typedef struct {
* @param chunkshape The chunk shape.
* @param blockshape The block shape.
* @param dtype The data type expressed as a string version.
* @param dtype_format The data type format; default is DTYPE_NUMPY_FORMAT.
* @param dtype_format The data type format; DTYPE_NUMPY_FORMAT should be chosen for NumPy compatibility.
* @param metalayers The memory pointer to the list of the metalayers desired.
* @param nmetalayers The number of metalayers.
*
Expand Down Expand Up @@ -364,10 +364,10 @@ BLOSC_EXPORT int b2nd_get_slice_cbuffer(const b2nd_array_t *array, const int64_t
* @brief Set a slice in a b2nd array using a C buffer.
*
* @param buffer The buffer where the slice data is.
* @param buffershape The shape of the buffer.
* @param buffersize The size (in bytes) of the buffer.
* @param start The coordinates where the slice will begin.
* @param stop The coordinates where the slice will end.
* @param buffershape The shape of the buffer.
* @param array The b2nd array where the slice will be set
*
* @return An error code.
Expand Down
2 changes: 1 addition & 1 deletion include/blosc2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ BLOSC_EXPORT int64_t blosc2_schunk_frame_len(blosc2_schunk* schunk);
* If there is an error, a negative value is returned.
*/
BLOSC_EXPORT int64_t blosc2_schunk_fill_special(blosc2_schunk* schunk, int64_t nitems,
int special_value, int32_t chunksize);
int special_value, int32_t chunksize);


/*********************************************************************
Expand Down

0 comments on commit 1483050

Please sign in to comment.