Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove MICROPY_GC_CONSERVATIVE_CLEAR guards
  • Loading branch information
v923z committed Apr 22, 2022
commit 341e1bbb6a04a4939e60d67f860a0efec28b66c3
26 changes: 3 additions & 23 deletions code/ndarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ void ndarray_fill_array_iterable(mp_float_t *array, mp_obj_t iterable) {
#if ULAB_HAS_FUNCTION_ITERATOR
size_t *ndarray_new_coords(uint8_t ndim) {
size_t *coords = m_new0(size_t, ndim);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(coords, 0, ndim*sizeof(size_t));
#endif
return coords;
}

Expand Down Expand Up @@ -623,9 +620,6 @@ ndarray_obj_t *ndarray_new_ndarray(uint8_t ndim, size_t *shape, int32_t *strides
uint8_t *array = m_new0(byte, len);
// this should set all elements to 0, irrespective of the of the dtype (all bits are zero)
// we could, perhaps, leave this step out, and initialise the array only, when needed
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(array, 0, len);
#endif
ndarray->array = array;
ndarray->origin = array;
return ndarray;
Expand Down Expand Up @@ -1064,10 +1058,6 @@ bool ndarray_can_broadcast(ndarray_obj_t *lhs, ndarray_obj_t *rhs, uint8_t *ndim
//
// 1. the two shapes are either equal
// 2. one of the shapes is 1
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(lstrides, 0, sizeof(size_t)*ULAB_MAX_DIMS);
memset(rstrides, 0, sizeof(size_t)*ULAB_MAX_DIMS);
#endif

lstrides[ULAB_MAX_DIMS - 1] = lhs->strides[ULAB_MAX_DIMS - 1];
rstrides[ULAB_MAX_DIMS - 1] = rhs->strides[ULAB_MAX_DIMS - 1];
Expand Down Expand Up @@ -1101,9 +1091,6 @@ bool ndarray_can_broadcast_inplace(ndarray_obj_t *lhs, ndarray_obj_t *rhs, int32
//
// 1. the two shapes are either equal
// 2. the shapes on the right hand side is 1
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(rstrides, 0, sizeof(size_t)*ULAB_MAX_DIMS);
#endif

rstrides[ULAB_MAX_DIMS - 1] = rhs->strides[ULAB_MAX_DIMS - 1];
for(uint8_t i=ULAB_MAX_DIMS; i > 0; i--) {
Expand Down Expand Up @@ -1154,10 +1141,6 @@ static mp_bound_slice_t generate_slice(mp_int_t n, mp_obj_t index) {
static ndarray_obj_t *ndarray_view_from_slices(ndarray_obj_t *ndarray, mp_obj_tuple_t *tuple) {
size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
int32_t *strides = m_new0(int32_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(shape, 0, sizeof(size_t)*ULAB_MAX_DIMS);
memset(strides, 0, sizeof(size_t)*ULAB_MAX_DIMS);
#endif

uint8_t ndim = ndarray->ndim;

Expand Down Expand Up @@ -1199,9 +1182,9 @@ void ndarray_assign_view(ndarray_obj_t *view, ndarray_obj_t *values) {
return;
}
uint8_t ndim = 0;
size_t *shape = m_new(size_t, ULAB_MAX_DIMS);
int32_t *lstrides = m_new(int32_t, ULAB_MAX_DIMS);
int32_t *rstrides = m_new(int32_t, ULAB_MAX_DIMS);
size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
int32_t *lstrides = m_new0(int32_t, ULAB_MAX_DIMS);
int32_t *rstrides = m_new0(int32_t, ULAB_MAX_DIMS);
if(!ndarray_can_broadcast(view, values, &ndim, shape, lstrides, rstrides)) {
mp_raise_ValueError(translate("operands could not be broadcast together"));
m_del(size_t, shape, ULAB_MAX_DIMS);
Expand Down Expand Up @@ -2170,9 +2153,6 @@ mp_obj_t ndarray_reshape_core(mp_obj_t oin, mp_obj_t _shape, bool inplace) {
mp_raise_ValueError(translate("maximum number of dimensions is 4"));
}
size_t *new_shape = m_new0(size_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(new_shape, 0, sizeof(size_t)*ULAB_MAX_DIMS);
#endif

size_t new_length = 1;
for(uint8_t i=0; i < shape->len; i++) {
Expand Down
6 changes: 0 additions & 6 deletions code/numpy/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ static mp_obj_t create_zeros_ones_full(mp_obj_t oshape, uint8_t dtype, mp_obj_t
mp_raise_TypeError(translate("too many dimensions"));
}
size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(shape, 0, ULAB_MAX_DIMS * sizeof(size_t));
#endif

size_t i = 0;
mp_obj_iter_buf_t iter_buf;
Expand Down Expand Up @@ -249,9 +246,6 @@ mp_obj_t create_concatenate(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
}
int8_t axis = (int8_t)args[1].u_int;
size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(shape, 0, sizeof(size_t)*ULAB_MAX_DIMS);
#endif
mp_obj_tuple_t *ndarrays = MP_OBJ_TO_PTR(args[0].u_obj);

// first check, whether the arrays are compatible
Expand Down
6 changes: 0 additions & 6 deletions code/numpy/io/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ static mp_obj_t io_load(mp_obj_t file) {
io_read_(stream, stream_p, buffer, "', 'fortran_order': False, 'shape': (", 37, &error);

size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(shape, 0, sizeof(size_t) * ULAB_MAX_DIMS);
#endif

uint16_t bytes_to_read = MIN(ULAB_IO_BUFFER_SIZE, header_length - 51);
// bytes_to_read is 128 at most. This should be enough to contain a
Expand Down Expand Up @@ -389,9 +386,6 @@ static mp_obj_t io_loadtxt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
}

size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(shape, 0, sizeof(size_t) * ULAB_MAX_DIMS);
#endif

#if ULAB_MAX_DIMS == 1
shape[0] = rows;
Expand Down
4 changes: 0 additions & 4 deletions code/numpy/linalg/linalg_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ bool linalg_invert_matrix(mp_float_t *data, size_t N) {
// will be returned after all the transformations
mp_float_t *unit = m_new0(mp_float_t, N*N);
mp_float_t elem = 1.0;
// initialise the unit matrix
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(unit, 0, sizeof(mp_float_t)*N*N);
#endif

for(size_t m=0; m < N; m++) {
memcpy(&unit[m * (N+1)], &elem, sizeof(mp_float_t));
Expand Down
27 changes: 0 additions & 27 deletions code/numpy/numerical.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,6 @@ static mp_obj_t numerical_argmin_argmax_ndarray(ndarray_obj_t *ndarray, mp_obj_t
uint8_t *array = (uint8_t *)ndarray->array;
size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
int32_t *strides = m_new0(int32_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(strides, 0, sizeof(uint32_t)*ULAB_MAX_DIMS);
memset(shape, 0, sizeof(size_t)*ULAB_MAX_DIMS);
#endif

numerical_reduce_axes(ndarray, ax, shape, strides);
uint8_t index = ULAB_MAX_DIMS - ndarray->ndim + ax;
Expand Down Expand Up @@ -641,10 +637,6 @@ static mp_obj_t numerical_sort_helper(mp_obj_t oin, mp_obj_t axis, uint8_t inpla

size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
int32_t *strides = m_new0(int32_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(shape, 0, sizeof(size_t)*ULAB_MAX_DIMS);
memset(strides, 0, sizeof(uint32_t)*ULAB_MAX_DIMS);
#endif

numerical_reduce_axes(ndarray, ax, shape, strides);
ax = ULAB_MAX_DIMS - ndarray->ndim + ax;
Expand Down Expand Up @@ -741,10 +733,6 @@ mp_obj_t numerical_argsort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw

size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
int32_t *strides = m_new0(int32_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(shape, 0, sizeof(size_t)*ULAB_MAX_DIMS);
memset(strides, 0, sizeof(uint32_t)*ULAB_MAX_DIMS);
#endif
numerical_reduce_axes(ndarray, ax, shape, strides);

// We could return an NDARRAY_UINT8 array, if all lengths are shorter than 256
Expand Down Expand Up @@ -956,9 +944,6 @@ mp_obj_t numerical_diff(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar

memset(shape, 0, sizeof(size_t)*ULAB_MAX_DIMS);
int32_t *strides = m_new0(int32_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(strides, 0, sizeof(int32_t)*ULAB_MAX_DIMS);
#endif
numerical_reduce_axes(ndarray, ax, shape, strides);

if(ndarray->dtype == NDARRAY_UINT8) {
Expand Down Expand Up @@ -1094,10 +1079,6 @@ mp_obj_t numerical_median(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_

size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
int32_t *strides = m_new0(int32_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(shape, 0, sizeof(size_t)*ULAB_MAX_DIMS);
memset(strides, 0, sizeof(uint32_t)*ULAB_MAX_DIMS);
#endif
numerical_reduce_axes(ndarray, ax, shape, strides);

ax = ULAB_MAX_DIMS - ndarray->ndim + ax;
Expand Down Expand Up @@ -1251,18 +1232,10 @@ mp_obj_t numerical_roll(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar

size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
int32_t *strides = m_new0(int32_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(shape, 0, sizeof(size_t)*ULAB_MAX_DIMS);
memset(strides, 0, sizeof(int32_t)*ULAB_MAX_DIMS);
#endif
numerical_reduce_axes(ndarray, ax, shape, strides);

size_t *rshape = m_new0(size_t, ULAB_MAX_DIMS);
int32_t *rstrides = m_new0(int32_t, ULAB_MAX_DIMS);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(rshape, 0, sizeof(size_t)*ULAB_MAX_DIMS);
memset(rstrides, 0, sizeof(int32_t)*ULAB_MAX_DIMS);
#endif
numerical_reduce_axes(results, ax, rshape, rstrides);

ax = ULAB_MAX_DIMS - ndarray->ndim + ax;
Expand Down
6 changes: 0 additions & 6 deletions code/numpy/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ static mp_obj_t transform_compress(size_t n_args, const mp_obj_t *pos_args, mp_m

if(axis == mp_const_none) {
result = ndarray_new_linear_array(true_count, ndarray->dtype);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(rstrides, 0, ndarray->ndim * sizeof(int32_t));
#endif

rstrides[ULAB_MAX_DIMS - 1] = ndarray->itemsize;
rshape[ULAB_MAX_DIMS - 1] = 0;
Expand Down Expand Up @@ -254,9 +251,6 @@ static mp_obj_t transform_delete(size_t n_args, const mp_obj_t *pos_args, mp_map

if(axis == mp_const_none) {
result = ndarray_new_linear_array(ndarray->len - index_len, ndarray->dtype);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(rstrides, 0, ndarray->ndim * sizeof(int32_t));
#endif
rstrides[ULAB_MAX_DIMS - 1] = ndarray->itemsize;
memset(rshape, 0, sizeof(size_t) * ULAB_MAX_DIMS);
// rshape[ULAB_MAX_DIMS - 1] = 0;
Expand Down