From e3bf07cabb728ecfa2b78ea5e468179f94dbf933 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 22 Apr 2021 17:54:02 -0700 Subject: [PATCH] Lowercase MP macros --- code/ndarray.c | 38 ++++++++++++------------- code/ndarray.h | 5 +--- code/numpy/compare/compare.c | 10 +++---- code/numpy/fft/fft_tools.c | 4 +-- code/numpy/filter/filter.c | 2 +- code/numpy/linalg/linalg.c | 4 +-- code/numpy/numerical/numerical.c | 32 ++++++++++----------- code/numpy/poly/poly.c | 2 +- code/numpy/transform/transform.c | 2 +- code/numpy/vector/vector.c | 16 +++++------ code/scipy/signal/signal.c | 4 +-- code/ulab_create.c | 10 +++---- code/ulab_tools.c | 2 +- code/user/user.c | 2 +- docs/manual/source/ulab-programming.rst | 4 +-- docs/ulab-programming.ipynb | 4 +-- 16 files changed, 69 insertions(+), 72 deletions(-) diff --git a/code/ndarray.c b/code/ndarray.c index 957a7272..7199986f 100644 --- a/code/ndarray.c +++ b/code/ndarray.c @@ -361,10 +361,10 @@ size_t *ndarray_shape_vector(size_t a, size_t b, size_t c, size_t d) { } bool ndarray_object_is_array_like(mp_obj_t o_in) { - if(MP_OBJ_IS_TYPE(o_in, &ulab_ndarray_type) || - MP_OBJ_IS_TYPE(o_in, &mp_type_tuple) || - MP_OBJ_IS_TYPE(o_in, &mp_type_list) || - MP_OBJ_IS_TYPE(o_in, &mp_type_range)) { + if(mp_obj_is_type(o_in, &ulab_ndarray_type) || + mp_obj_is_type(o_in, &mp_type_tuple) || + mp_obj_is_type(o_in, &mp_type_list) || + mp_obj_is_type(o_in, &mp_type_range)) { return true; } return false; @@ -420,13 +420,13 @@ mp_obj_t ndarray_dtype_make_new(const mp_obj_type_t *type, size_t n_args, size_t dtype_obj_t *dtype = m_new_obj(dtype_obj_t); dtype->base.type = &ulab_dtype_type; - if(MP_OBJ_IS_TYPE(args[0], &ulab_ndarray_type)) { + if(mp_obj_is_type(args[0], &ulab_ndarray_type)) { // return the dtype of the array ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[0]); dtype->dtype = ndarray->dtype; } else { uint8_t _dtype; - if(MP_OBJ_IS_INT(_args[0].u_obj)) { + if(mp_obj_is_int(_args[0].u_obj)) { _dtype = mp_obj_get_int(_args[0].u_obj); if((_dtype != NDARRAY_BOOL) && (_dtype != NDARRAY_UINT8) && (_dtype != NDARRAY_INT8) && (_dtype != NDARRAY_UINT16) @@ -466,7 +466,7 @@ mp_obj_t ndarray_dtype(mp_obj_t self_in) { // this is the cheap implementation of tbe dtype mp_obj_t ndarray_dtype(mp_obj_t self_in) { uint8_t dtype; - if(MP_OBJ_IS_TYPE(self_in, &ulab_ndarray_type)) { + if(mp_obj_is_type(self_in, &ulab_ndarray_type)) { ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in); dtype = self->dtype; } else { // we assume here that the input is a single character @@ -908,7 +908,7 @@ STATIC uint8_t ndarray_init_helper(size_t n_args, const mp_obj_t *pos_args, mp_m uint8_t _dtype; #if ULAB_HAS_DTYPE_OBJECT - if(MP_OBJ_IS_TYPE(args[1].u_obj, &ulab_dtype_type)) { + if(mp_obj_is_type(args[1].u_obj, &ulab_dtype_type)) { dtype_obj_t *dtype = MP_OBJ_TO_PTR(args[1].u_obj); _dtype = dtype->dtype; } else { // this must be an integer defined as a class constant (ulba.uint8 etc.) @@ -923,7 +923,7 @@ STATIC uint8_t ndarray_init_helper(size_t n_args, const mp_obj_t *pos_args, mp_m STATIC mp_obj_t ndarray_make_new_core(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args, mp_map_t *kw_args) { uint8_t dtype = ndarray_init_helper(n_args, args, kw_args); - if(MP_OBJ_IS_TYPE(args[0], &ulab_ndarray_type)) { + if(mp_obj_is_type(args[0], &ulab_ndarray_type)) { ndarray_obj_t *source = MP_OBJ_TO_PTR(args[0]); if(dtype == source->dtype) { return ndarray_copy_view(source); @@ -1151,9 +1151,9 @@ static size_t slice_length(mp_bound_slice_t slice) { static mp_bound_slice_t generate_slice(mp_int_t n, mp_obj_t index) { mp_bound_slice_t slice; - if(MP_OBJ_IS_TYPE(index, &mp_type_slice)) { + if(mp_obj_is_type(index, &mp_type_slice)) { mp_obj_slice_indices(index, n, &slice); - } else if(MP_OBJ_IS_INT(index)) { + } else if(mp_obj_is_int(index)) { mp_int_t _index = mp_obj_get_int(index); if(_index < 0) { _index += n; @@ -1185,7 +1185,7 @@ static ndarray_obj_t *ndarray_view_from_slices(ndarray_obj_t *ndarray, mp_obj_tu } int32_t offset = 0; for(uint8_t i=0; i < tuple->len; i++) { - if(MP_OBJ_IS_INT(tuple->items[i])) { + if(mp_obj_is_int(tuple->items[i])) { // if item is an int, the dimension will first be reduced ... ndim--; int32_t k = mp_obj_get_int(tuple->items[i]); @@ -1411,7 +1411,7 @@ static mp_obj_t ndarray_assign_from_boolean_index(ndarray_obj_t *ndarray, ndarra } static mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarray_obj_t *values) { - if(MP_OBJ_IS_TYPE(index, &ulab_ndarray_type)) { + if(mp_obj_is_type(index, &ulab_ndarray_type)) { ndarray_obj_t *nindex = MP_OBJ_TO_PTR(index); if((nindex->ndim > 1) || (nindex->boolean == false)) { mp_raise_NotImplementedError(translate("operation is implemented for 1D Boolean arrays only")); @@ -1422,9 +1422,9 @@ static mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarra ndarray_assign_from_boolean_index(ndarray, index, values); } } - if(MP_OBJ_IS_TYPE(index, &mp_type_tuple) || MP_OBJ_IS_INT(index) || MP_OBJ_IS_TYPE(index, &mp_type_slice)) { + if(mp_obj_is_type(index, &mp_type_tuple) || mp_obj_is_int(index) || mp_obj_is_type(index, &mp_type_slice)) { mp_obj_tuple_t *tuple; - if(MP_OBJ_IS_TYPE(index, &mp_type_tuple)) { + if(mp_obj_is_type(index, &mp_type_tuple)) { tuple = MP_OBJ_TO_PTR(index); if(tuple->len > ndarray->ndim) { mp_raise_msg(&mp_type_IndexError, translate("too many indices")); @@ -1676,7 +1676,7 @@ ndarray_obj_t *ndarray_from_mp_obj(mp_obj_t obj) { // creates an ndarray from a micropython int or float // if the input is an ndarray, it is returned ndarray_obj_t *ndarray; - if(MP_OBJ_IS_INT(obj)) { + if(mp_obj_is_int(obj)) { int32_t ivalue = mp_obj_get_int(obj); if((ivalue >= 0) && (ivalue < 256)) { ndarray = ndarray_new_linear_array(1, NDARRAY_UINT8); @@ -1704,7 +1704,7 @@ ndarray_obj_t *ndarray_from_mp_obj(mp_obj_t obj) { ndarray = ndarray_new_linear_array(1, NDARRAY_FLOAT); mp_float_t *array = (mp_float_t *)ndarray->array; array[0] = (mp_float_t)fvalue; - } else if(MP_OBJ_IS_TYPE(obj, &ulab_ndarray_type)){ + } else if(mp_obj_is_type(obj, &ulab_ndarray_type)){ return obj; } else { mp_raise_TypeError(translate("wrong operand type")); @@ -2013,7 +2013,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(ndarray_transpose_obj, ndarray_transpose); #if NDARRAY_HAS_RESHAPE mp_obj_t ndarray_reshape(mp_obj_t oin, mp_obj_t _shape) { ndarray_obj_t *source = MP_OBJ_TO_PTR(oin); - if(!MP_OBJ_IS_TYPE(_shape, &mp_type_tuple)) { + if(!mp_obj_is_type(_shape, &mp_type_tuple)) { mp_raise_TypeError(translate("shape must be a tuple")); } @@ -2050,7 +2050,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(ndarray_reshape_obj, ndarray_reshape); #if ULAB_NUMPY_HAS_NDINFO mp_obj_t ndarray_info(mp_obj_t obj_in) { ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(obj_in); - if(!MP_OBJ_IS_TYPE(ndarray, &ulab_ndarray_type)) { + if(!mp_obj_is_type(ndarray, &ulab_ndarray_type)) { mp_raise_TypeError(translate("function is defined for ndarrays only")); } mp_printf(MP_PYTHON_PRINTER, "class: ndarray\n"); diff --git a/code/ndarray.h b/code/ndarray.h index 2921a8d7..b634f617 100644 --- a/code/ndarray.h +++ b/code/ndarray.h @@ -49,10 +49,7 @@ typedef struct _mp_obj_slice_t { #define MP_ERROR_TEXT(x) x #endif -#if CIRCUITPY -#define mp_obj_is_bool(o) (MP_OBJ_IS_TYPE((o), &mp_type_bool)) -#define mp_obj_is_int(x) (MP_OBJ_IS_INT((x))) -#else +#if !CIRCUITPY #define translate(x) MP_ERROR_TEXT(x) #endif diff --git a/code/numpy/compare/compare.c b/code/numpy/compare/compare.c index af2af0fc..22b702b0 100644 --- a/code/numpy/compare/compare.c +++ b/code/numpy/compare/compare.c @@ -122,7 +122,7 @@ static mp_obj_t compare_function(mp_obj_t x1, mp_obj_t x2, uint8_t op) { static mp_obj_t compare_equal_helper(mp_obj_t x1, mp_obj_t x2, uint8_t comptype) { // scalar comparisons should return a single object of mp_obj_t type mp_obj_t result = compare_function(x1, x2, comptype); - if((MP_OBJ_IS_INT(x1) || mp_obj_is_float(x1)) && (MP_OBJ_IS_INT(x2) || mp_obj_is_float(x2))) { + if((mp_obj_is_int(x1) || mp_obj_is_float(x1)) && (mp_obj_is_int(x2) || mp_obj_is_float(x2))) { mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(result, &iter_buf); mp_obj_t item = mp_iternext(iterable); @@ -179,7 +179,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(compare_not_equal_obj, compare_not_equal); static mp_obj_t compare_isinf_isfinite(mp_obj_t _x, uint8_t mask) { // mask should signify, whether the function is called from isinf (mask = 1), // or from isfinite (mask = 0) - if(MP_OBJ_IS_INT(_x)) { + if(mp_obj_is_int(_x)) { if(mask) { return mp_const_false; } else { @@ -195,7 +195,7 @@ static mp_obj_t compare_isinf_isfinite(mp_obj_t _x, uint8_t mask) { } else { // called from isfinite return isinf(x) ? mp_const_false : mp_const_true; } - } else if(MP_OBJ_IS_TYPE(_x, &ulab_ndarray_type)) { + } else if(mp_obj_is_type(_x, &ulab_ndarray_type)) { ndarray_obj_t *x = MP_OBJ_TO_PTR(_x); ndarray_obj_t *results = ndarray_new_dense_ndarray(x->ndim, x->shape, NDARRAY_BOOL); // At this point, results is all False @@ -280,7 +280,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(compare_isinf_obj, compare_isinf); mp_obj_t compare_maximum(mp_obj_t x1, mp_obj_t x2) { // extra round, so that we can return maximum(3, 4) properly mp_obj_t result = compare_function(x1, x2, COMPARE_MAXIMUM); - if((MP_OBJ_IS_INT(x1) || mp_obj_is_float(x1)) && (MP_OBJ_IS_INT(x2) || mp_obj_is_float(x2))) { + if((mp_obj_is_int(x1) || mp_obj_is_float(x1)) && (mp_obj_is_int(x2) || mp_obj_is_float(x2))) { ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(result); return mp_binary_get_val_array(ndarray->dtype, ndarray->array, 0); } @@ -295,7 +295,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(compare_maximum_obj, compare_maximum); mp_obj_t compare_minimum(mp_obj_t x1, mp_obj_t x2) { // extra round, so that we can return minimum(3, 4) properly mp_obj_t result = compare_function(x1, x2, COMPARE_MINIMUM); - if((MP_OBJ_IS_INT(x1) || mp_obj_is_float(x1)) && (MP_OBJ_IS_INT(x2) || mp_obj_is_float(x2))) { + if((mp_obj_is_int(x1) || mp_obj_is_float(x1)) && (mp_obj_is_int(x2) || mp_obj_is_float(x2))) { ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(result); return mp_binary_get_val_array(ndarray->dtype, ndarray->array, 0); } diff --git a/code/numpy/fft/fft_tools.c b/code/numpy/fft/fft_tools.c index e527f22d..6dd2ca47 100644 --- a/code/numpy/fft/fft_tools.c +++ b/code/numpy/fft/fft_tools.c @@ -84,11 +84,11 @@ void fft_kernel(mp_float_t *real, mp_float_t *imag, size_t n, int isign) { */ mp_obj_t fft_fft_ifft_spectrogram(size_t n_args, mp_obj_t arg_re, mp_obj_t arg_im, uint8_t type) { - if(!MP_OBJ_IS_TYPE(arg_re, &ulab_ndarray_type)) { + if(!mp_obj_is_type(arg_re, &ulab_ndarray_type)) { mp_raise_NotImplementedError(translate("FFT is defined for ndarrays only")); } if(n_args == 2) { - if(!MP_OBJ_IS_TYPE(arg_im, &ulab_ndarray_type)) { + if(!mp_obj_is_type(arg_im, &ulab_ndarray_type)) { mp_raise_NotImplementedError(translate("FFT is defined for ndarrays only")); } } diff --git a/code/numpy/filter/filter.c b/code/numpy/filter/filter.c index 280efd0e..2f9ff79b 100644 --- a/code/numpy/filter/filter.c +++ b/code/numpy/filter/filter.c @@ -34,7 +34,7 @@ mp_obj_t filter_convolve(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - if(!MP_OBJ_IS_TYPE(args[0].u_obj, &ulab_ndarray_type) || !MP_OBJ_IS_TYPE(args[1].u_obj, &ulab_ndarray_type)) { + if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type) || !mp_obj_is_type(args[1].u_obj, &ulab_ndarray_type)) { mp_raise_TypeError(translate("convolve arguments must be ndarrays")); } diff --git a/code/numpy/linalg/linalg.c b/code/numpy/linalg/linalg.c index 10cc0af9..697c5e44 100644 --- a/code/numpy/linalg/linalg.c +++ b/code/numpy/linalg/linalg.c @@ -293,7 +293,7 @@ static mp_obj_t linalg_norm(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k mp_float_t dot = 0.0, value; size_t count = 1; - if(MP_OBJ_IS_TYPE(x, &mp_type_tuple) || MP_OBJ_IS_TYPE(x, &mp_type_list) || MP_OBJ_IS_TYPE(x, &mp_type_range)) { + if(mp_obj_is_type(x, &mp_type_tuple) || mp_obj_is_type(x, &mp_type_list) || mp_obj_is_type(x, &mp_type_range)) { mp_obj_iter_buf_t iter_buf; mp_obj_t item, iterable = mp_getiter(x, &iter_buf); while((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { @@ -303,7 +303,7 @@ static mp_obj_t linalg_norm(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k dot = dot + (value * value - dot) / count++; } return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(dot * (count - 1))); - } else if(MP_OBJ_IS_TYPE(x, &ulab_ndarray_type)) { + } else if(mp_obj_is_type(x, &ulab_ndarray_type)) { ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(x); uint8_t *array = (uint8_t *)ndarray->array; // always get a float, so that we don't have to resolve the dtype later diff --git a/code/numpy/numerical/numerical.c b/code/numpy/numerical/numerical.c index 241eefa8..da0913d1 100644 --- a/code/numpy/numerical/numerical.c +++ b/code/numpy/numerical/numerical.c @@ -66,7 +66,7 @@ static void numerical_reduce_axes(ndarray_obj_t *ndarray, int8_t axis, size_t *s #if ULAB_NUMPY_HAS_ALL | ULAB_NUMPY_HAS_ANY static mp_obj_t numerical_all_any(mp_obj_t oin, mp_obj_t axis, uint8_t optype) { bool anytype = optype == NUMERICAL_ALL ? 1 : 0; - if(MP_OBJ_IS_TYPE(oin, &ulab_ndarray_type)) { + if(mp_obj_is_type(oin, &ulab_ndarray_type)) { ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(oin); uint8_t *array = (uint8_t *)ndarray->array; // always get a float, so that we don't have to resolve the dtype later @@ -486,15 +486,15 @@ static mp_obj_t numerical_function(size_t n_args, const mp_obj_t *pos_args, mp_m mp_obj_t oin = args[0].u_obj; mp_obj_t axis = args[1].u_obj; - if((axis != mp_const_none) && (!MP_OBJ_IS_INT(axis))) { + if((axis != mp_const_none) && (!mp_obj_is_int(axis))) { mp_raise_TypeError(translate("axis must be None, or an integer")); } if((optype == NUMERICAL_ALL) || (optype == NUMERICAL_ANY)) { return numerical_all_any(oin, axis, optype); } - if(MP_OBJ_IS_TYPE(oin, &mp_type_tuple) || MP_OBJ_IS_TYPE(oin, &mp_type_list) || - MP_OBJ_IS_TYPE(oin, &mp_type_range)) { + if(mp_obj_is_type(oin, &mp_type_tuple) || mp_obj_is_type(oin, &mp_type_list) || + mp_obj_is_type(oin, &mp_type_range)) { switch(optype) { case NUMERICAL_MIN: case NUMERICAL_ARGMIN: @@ -507,7 +507,7 @@ static mp_obj_t numerical_function(size_t n_args, const mp_obj_t *pos_args, mp_m default: // we should never reach this point, but whatever return mp_const_none; } - } else if(MP_OBJ_IS_TYPE(oin, &ulab_ndarray_type)) { + } else if(mp_obj_is_type(oin, &ulab_ndarray_type)) { ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(oin); switch(optype) { case NUMERICAL_MIN: @@ -529,7 +529,7 @@ static mp_obj_t numerical_function(size_t n_args, const mp_obj_t *pos_args, mp_m #if ULAB_NUMPY_HAS_SORT | NDARRAY_HAS_SORT static mp_obj_t numerical_sort_helper(mp_obj_t oin, mp_obj_t axis, uint8_t inplace) { - if(!MP_OBJ_IS_TYPE(oin, &ulab_ndarray_type)) { + if(!mp_obj_is_type(oin, &ulab_ndarray_type)) { mp_raise_TypeError(translate("sort argument must be an ndarray")); } @@ -634,7 +634,7 @@ mp_obj_t numerical_argsort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - if(!MP_OBJ_IS_TYPE(args[0].u_obj, &ulab_ndarray_type)) { + if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) { mp_raise_TypeError(translate("argsort argument must be an ndarray")); } @@ -737,7 +737,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(numerical_argsort_obj, 1, numerical_argsort); //| static mp_obj_t numerical_cross(mp_obj_t _a, mp_obj_t _b) { - if (!MP_OBJ_IS_TYPE(_a, &ulab_ndarray_type) || !MP_OBJ_IS_TYPE(_b, &ulab_ndarray_type)) { + if (!mp_obj_is_type(_a, &ulab_ndarray_type) || !mp_obj_is_type(_b, &ulab_ndarray_type)) { mp_raise_TypeError(translate("arguments must be ndarrays")); } ndarray_obj_t *a = MP_OBJ_TO_PTR(_a); @@ -825,7 +825,7 @@ mp_obj_t numerical_diff(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - if(!MP_OBJ_IS_TYPE(args[0].u_obj, &ulab_ndarray_type)) { + if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) { mp_raise_TypeError(translate("diff argument must be an ndarray")); } @@ -905,7 +905,7 @@ mp_obj_t numerical_flip(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - if(!MP_OBJ_IS_TYPE(args[0].u_obj, &ulab_ndarray_type)) { + if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) { mp_raise_TypeError(translate("flip argument must be an ndarray")); } @@ -918,7 +918,7 @@ mp_obj_t numerical_flip(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar rarray += (results->len - 1) * results->itemsize; results->array = rarray; results->strides[ULAB_MAX_DIMS - 1] = -results->strides[ULAB_MAX_DIMS - 1]; - } else if(MP_OBJ_IS_INT(args[1].u_obj)){ + } else if(mp_obj_is_int(args[1].u_obj)){ int8_t ax = mp_obj_get_int(args[1].u_obj); if(ax < 0) ax += ndarray->ndim; if((ax < 0) || (ax > ndarray->ndim - 1)) { @@ -977,7 +977,7 @@ mp_obj_t numerical_median(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - if(!MP_OBJ_IS_TYPE(args[0].u_obj, &ulab_ndarray_type)) { + if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) { mp_raise_TypeError(translate("median argument must be an ndarray")); } @@ -1089,7 +1089,7 @@ mp_obj_t numerical_roll(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - if(!MP_OBJ_IS_TYPE(args[0].u_obj, &ulab_ndarray_type)) { + if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) { mp_raise_TypeError(translate("roll argument must be an ndarray")); } ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[0].u_obj); @@ -1151,7 +1151,7 @@ mp_obj_t numerical_roll(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar i++; } while(i < ndarray->shape[ULAB_MAX_DIMS - 4]); #endif - } else if(MP_OBJ_IS_INT(args[2].u_obj)){ + } else if(mp_obj_is_int(args[2].u_obj)){ int8_t ax = mp_obj_get_int(args[2].u_obj); if(ax < 0) ax += ndarray->ndim; if((ax < 0) || (ax > ndarray->ndim - 1)) { @@ -1298,9 +1298,9 @@ mp_obj_t numerical_std(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg // this seems to pass with False, and True... mp_raise_ValueError(translate("axis must be None, or an integer")); } - if(MP_OBJ_IS_TYPE(oin, &mp_type_tuple) || MP_OBJ_IS_TYPE(oin, &mp_type_list) || MP_OBJ_IS_TYPE(oin, &mp_type_range)) { + if(mp_obj_is_type(oin, &mp_type_tuple) || mp_obj_is_type(oin, &mp_type_list) || mp_obj_is_type(oin, &mp_type_range)) { return numerical_sum_mean_std_iterable(oin, NUMERICAL_STD, ddof); - } else if(MP_OBJ_IS_TYPE(oin, &ulab_ndarray_type)) { + } else if(mp_obj_is_type(oin, &ulab_ndarray_type)) { ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(oin); return numerical_sum_mean_std_ndarray(ndarray, axis, NUMERICAL_STD, ddof); } else { diff --git a/code/numpy/poly/poly.c b/code/numpy/poly/poly.c index 6c1ed816..d13746ae 100644 --- a/code/numpy/poly/poly.c +++ b/code/numpy/poly/poly.c @@ -156,7 +156,7 @@ mp_obj_t poly_polyval(mp_obj_t o_p, mp_obj_t o_x) { // polynomials are going to be of type float, except, when both // the coefficients and the independent variable are integers ndarray_obj_t *ndarray; - if(MP_OBJ_IS_TYPE(o_x, &ulab_ndarray_type)) { + if(mp_obj_is_type(o_x, &ulab_ndarray_type)) { ndarray_obj_t *source = MP_OBJ_TO_PTR(o_x); uint8_t *sarray = (uint8_t *)source->array; ndarray = ndarray_new_dense_ndarray(source->ndim, source->shape, NDARRAY_FLOAT); diff --git a/code/numpy/transform/transform.c b/code/numpy/transform/transform.c index fc48d1be..e87163f5 100644 --- a/code/numpy/transform/transform.c +++ b/code/numpy/transform/transform.c @@ -34,7 +34,7 @@ mp_obj_t transform_dot(mp_obj_t _m1, mp_obj_t _m2) { // TODO: should the results be upcast? // This implements 2D operations only! - if(!MP_OBJ_IS_TYPE(_m1, &ulab_ndarray_type) || !MP_OBJ_IS_TYPE(_m2, &ulab_ndarray_type)) { + if(!mp_obj_is_type(_m1, &ulab_ndarray_type) || !mp_obj_is_type(_m2, &ulab_ndarray_type)) { mp_raise_TypeError(translate("arguments must be ndarrays")); } ndarray_obj_t *m1 = MP_OBJ_TO_PTR(_m1); diff --git a/code/numpy/vector/vector.c b/code/numpy/vector/vector.c index 8246d685..033f2184 100644 --- a/code/numpy/vector/vector.c +++ b/code/numpy/vector/vector.c @@ -35,10 +35,10 @@ static mp_obj_t vectorise_generic_vector(mp_obj_t o_in, mp_float_t (*f)(mp_float_t)) { // Return a single value, if o_in is not iterable - if(mp_obj_is_float(o_in) || MP_OBJ_IS_INT(o_in)) { + if(mp_obj_is_float(o_in) || mp_obj_is_int(o_in)) { return mp_obj_new_float(f(mp_obj_get_float(o_in))); } - if(MP_OBJ_IS_TYPE(o_in, &ulab_ndarray_type)) { + if(mp_obj_is_type(o_in, &ulab_ndarray_type)) { ndarray_obj_t *source = MP_OBJ_TO_PTR(o_in); uint8_t *sarray = (uint8_t *)source->array; ndarray_obj_t *ndarray = ndarray_new_dense_ndarray(source->ndim, source->shape, NDARRAY_FLOAT); @@ -100,8 +100,8 @@ static mp_obj_t vectorise_generic_vector(mp_obj_t o_in, mp_float_t (*f)(mp_float #endif /* ULAB_VECTORISE_USES_FUN_POINTER */ return MP_OBJ_FROM_PTR(ndarray); - } else if(MP_OBJ_IS_TYPE(o_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(o_in, &mp_type_list) || - MP_OBJ_IS_TYPE(o_in, &mp_type_range)) { // i.e., the input is a generic iterable + } else if(mp_obj_is_type(o_in, &mp_type_tuple) || mp_obj_is_type(o_in, &mp_type_list) || + mp_obj_is_type(o_in, &mp_type_range)) { // i.e., the input is a generic iterable mp_obj_array_t *o = MP_OBJ_TO_PTR(o_in); ndarray_obj_t *out = ndarray_new_linear_array(o->len, NDARRAY_FLOAT); mp_float_t *array = (mp_float_t *)out->array; @@ -173,7 +173,7 @@ mp_obj_t vectorise_around(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - if(!MP_OBJ_IS_TYPE(args[0].u_obj, &ulab_ndarray_type)) { + if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) { mp_raise_TypeError(translate("first argument must be an ndarray")); } int8_t n = args[1].u_int; @@ -552,7 +552,7 @@ static mp_obj_t vectorise_vectorized_function_call(mp_obj_t self_in, size_t n_ar vectorized_function_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t avalue[1]; mp_obj_t fvalue; - if(MP_OBJ_IS_TYPE(args[0], &ulab_ndarray_type)) { + if(mp_obj_is_type(args[0], &ulab_ndarray_type)) { ndarray_obj_t *source = MP_OBJ_TO_PTR(args[0]); ndarray_obj_t *ndarray = ndarray_new_dense_ndarray(source->ndim, source->shape, self->otypes); for(size_t i=0; i < source->len; i++) { @@ -561,8 +561,8 @@ static mp_obj_t vectorise_vectorized_function_call(mp_obj_t self_in, size_t n_ar mp_binary_set_val_array(self->otypes, ndarray->array, i, fvalue); } return MP_OBJ_FROM_PTR(ndarray); - } else if(MP_OBJ_IS_TYPE(args[0], &mp_type_tuple) || MP_OBJ_IS_TYPE(args[0], &mp_type_list) || - MP_OBJ_IS_TYPE(args[0], &mp_type_range)) { // i.e., the input is a generic iterable + } else if(mp_obj_is_type(args[0], &mp_type_tuple) || mp_obj_is_type(args[0], &mp_type_list) || + mp_obj_is_type(args[0], &mp_type_range)) { // i.e., the input is a generic iterable size_t len = (size_t)mp_obj_get_int(mp_obj_len_maybe(args[0])); ndarray_obj_t *ndarray = ndarray_new_linear_array(len, self->otypes); mp_obj_iter_buf_t iter_buf; diff --git a/code/scipy/signal/signal.c b/code/scipy/signal/signal.c index 0c2d9168..93e944f1 100644 --- a/code/scipy/signal/signal.c +++ b/code/scipy/signal/signal.c @@ -70,7 +70,7 @@ mp_obj_t signal_sosfilt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar ndarray_obj_t *y = ndarray_new_linear_array(lenx, NDARRAY_FLOAT); mp_float_t *yarray = (mp_float_t *)y->array; mp_float_t coeffs[6]; - if(MP_OBJ_IS_TYPE(args[1].u_obj, &ulab_ndarray_type)) { + if(mp_obj_is_type(args[1].u_obj, &ulab_ndarray_type)) { ndarray_obj_t *inarray = MP_OBJ_TO_PTR(args[1].u_obj); #if ULAB_MAX_DIMS > 1 if(inarray->ndim > 1) { @@ -96,7 +96,7 @@ mp_obj_t signal_sosfilt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar mp_float_t *zf_array = (mp_float_t *)zf->array; if(args[2].u_obj != mp_const_none) { - if(!MP_OBJ_IS_TYPE(args[2].u_obj, &ulab_ndarray_type)) { + if(!mp_obj_is_type(args[2].u_obj, &ulab_ndarray_type)) { mp_raise_TypeError(translate("zi must be an ndarray")); } else { ndarray_obj_t *zi = MP_OBJ_TO_PTR(args[2].u_obj); diff --git a/code/ulab_create.c b/code/ulab_create.c index 1bbe7a01..7c6aa43b 100644 --- a/code/ulab_create.c +++ b/code/ulab_create.c @@ -22,14 +22,14 @@ #if ULAB_NUMPY_HAS_ONES | ULAB_NUMPY_HAS_ZEROS | ULAB_NUMPY_HAS_FULL static mp_obj_t create_zeros_ones_full(mp_obj_t oshape, uint8_t dtype, mp_obj_t value) { - if(!MP_OBJ_IS_INT(oshape) && !MP_OBJ_IS_TYPE(oshape, &mp_type_tuple) && !MP_OBJ_IS_TYPE(oshape, &mp_type_list)) { + if(!mp_obj_is_int(oshape) && !mp_obj_is_type(oshape, &mp_type_tuple) && !mp_obj_is_type(oshape, &mp_type_list)) { mp_raise_TypeError(translate("input argument must be an integer, a tuple, or a list")); } ndarray_obj_t *ndarray = NULL; - if(MP_OBJ_IS_INT(oshape)) { + if(mp_obj_is_int(oshape)) { size_t n = mp_obj_get_int(oshape); ndarray = ndarray_new_linear_array(n, dtype); - } else if(MP_OBJ_IS_TYPE(oshape, &mp_type_tuple) || MP_OBJ_IS_TYPE(oshape, &mp_type_list)) { + } else if(mp_obj_is_type(oshape, &mp_type_tuple) || mp_obj_is_type(oshape, &mp_type_list)) { uint8_t len = (uint8_t)mp_obj_get_int(mp_obj_len_maybe(oshape)); if(len > ULAB_MAX_DIMS) { mp_raise_TypeError(translate("too many dimensions")); @@ -182,7 +182,7 @@ mp_obj_t create_concatenate(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - if(!MP_OBJ_IS_TYPE(args[0].u_obj, &mp_type_tuple)) { + if(!mp_obj_is_type(args[0].u_obj, &mp_type_tuple)) { mp_raise_TypeError(translate("first argument must be a tuple of ndarrays")); } int8_t axis = (int8_t)args[1].u_int; @@ -306,7 +306,7 @@ mp_obj_t create_diag(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - if(!MP_OBJ_IS_TYPE(args[0].u_obj, &ulab_ndarray_type)) { + if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) { mp_raise_TypeError(translate("input must be an ndarray")); } ndarray_obj_t *source = MP_OBJ_TO_PTR(args[0].u_obj); diff --git a/code/ulab_tools.c b/code/ulab_tools.c index e8415c33..acd3d8a5 100644 --- a/code/ulab_tools.c +++ b/code/ulab_tools.c @@ -221,7 +221,7 @@ shape_strides tools_reduce_axes(ndarray_obj_t *ndarray, mp_obj_t axis) { ndarray_obj_t *tools_object_is_square(mp_obj_t obj) { // Returns an ndarray, if the object is a square ndarray, // raises the appropriate exception otherwise - if(!MP_OBJ_IS_TYPE(obj, &ulab_ndarray_type)) { + if(!mp_obj_is_type(obj, &ulab_ndarray_type)) { mp_raise_TypeError(translate("size is defined for ndarrays only")); } ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(obj); diff --git a/code/user/user.c b/code/user/user.c index fa5e660e..835c091c 100644 --- a/code/user/user.c +++ b/code/user/user.c @@ -27,7 +27,7 @@ static mp_obj_t user_square(mp_obj_t arg) { // element-wise square of its entries // raise a TypeError exception, if the input is not an ndarray - if(!MP_OBJ_IS_TYPE(arg, &ulab_ndarray_type)) { + if(!mp_obj_is_type(arg, &ulab_ndarray_type)) { mp_raise_TypeError(translate("input must be an ndarray")); } ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(arg); diff --git a/docs/manual/source/ulab-programming.rst b/docs/manual/source/ulab-programming.rst index 5d4bbd69..ff1788b0 100644 --- a/docs/manual/source/ulab-programming.rst +++ b/docs/manual/source/ulab-programming.rst @@ -733,7 +733,7 @@ iterables as its argument), we find this out by evaluating .. code:: c - MP_OBJ_IS_TYPE(object_in, &ulab_ndarray_type) + mp_obj_is_type(object_in, &ulab_ndarray_type) which should return ``true``. Once the pointer is at our disposal, we can get a pointer to the underlying numerical array as discussed @@ -813,7 +813,7 @@ And now the function: // element-wise square of its entries // raise a TypeError exception, if the input is not an ndarray - if(!MP_OBJ_IS_TYPE(arg, &ulab_ndarray_type)) { + if(!mp_obj_is_type(arg, &ulab_ndarray_type)) { mp_raise_TypeError(translate("input must be an ndarray")); } ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(arg); diff --git a/docs/ulab-programming.ipynb b/docs/ulab-programming.ipynb index 0776981f..32f12271 100644 --- a/docs/ulab-programming.ipynb +++ b/docs/ulab-programming.ipynb @@ -586,7 +586,7 @@ "If it is not clear, whether the object is an `ndarray` (e.g., if we want to write a function that can take `ndarray`s, and other iterables as its argument), we find this out by evaluating \n", "\n", "```c\n", - "MP_OBJ_IS_TYPE(object_in, &ulab_ndarray_type)\n", + "mp_obj_is_type(object_in, &ulab_ndarray_type)\n", "```\n", "which should return `true`. Once the pointer is at our disposal, we can get a pointer to the underlying numerical array as discussed earlier, i.e., \n", "\n", @@ -645,7 +645,7 @@ " // element-wise square of its entries\n", " \n", " // raise a TypeError exception, if the input is not an ndarray\n", - " if(!MP_OBJ_IS_TYPE(arg, &ulab_ndarray_type)) {\n", + " if(!mp_obj_is_type(arg, &ulab_ndarray_type)) {\n", " mp_raise_TypeError(translate(\"input must be an ndarray\"));\n", " }\n", " ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(arg);\n",