diff --git a/code/ndarray.c b/code/ndarray.c index 45418be2..1d60ef87 100644 --- a/code/ndarray.c +++ b/code/ndarray.c @@ -61,98 +61,6 @@ void ndarray_set_complex_value(void *p, size_t index, mp_obj_t value) { } } -#ifdef CIRCUITPY -void ndarray_set_value(char typecode, void *p, size_t index, mp_obj_t val_in) { - switch (typecode) { - case NDARRAY_INT8: - ((signed char *)p)[index] = mp_obj_get_int(val_in); - break; - case NDARRAY_UINT8: - ((unsigned char *)p)[index] = mp_obj_get_int(val_in); - break; - case NDARRAY_INT16: - ((short *)p)[index] = mp_obj_get_int(val_in); - break; - case NDARRAY_UINT16: - ((unsigned short *)p)[index] = mp_obj_get_int(val_in); - break; - case NDARRAY_FLOAT: - ((mp_float_t *)p)[index] = mp_obj_get_float(val_in); - break; - #if ULAB_SUPPORTS_COMPLEX - case NDARRAY_COMPLEX: - ndarray_set_complex_value(p, index, val_in); - break; - #endif - } -} -#endif - -#if defined(MICROPY_VERSION_MAJOR) && MICROPY_VERSION_MAJOR == 1 && MICROPY_VERSION_MINOR == 11 - -void mp_obj_slice_indices(mp_obj_t self_in, mp_int_t length, mp_bound_slice_t *result) { - mp_obj_slice_t *self = MP_OBJ_TO_PTR(self_in); - mp_int_t start, stop, step; - - if (self->step == mp_const_none) { - step = 1; - } else { - step = mp_obj_get_int(self->step); - if (step == 0) { - mp_raise_ValueError(translate("slice step can't be zero")); - } - } - - if (step > 0) { - // Positive step - if (self->start == mp_const_none) { - start = 0; - } else { - start = mp_obj_get_int(self->start); - if (start < 0) { - start += length; - } - start = MIN(length, MAX(start, 0)); - } - - if (self->stop == mp_const_none) { - stop = length; - } else { - stop = mp_obj_get_int(self->stop); - if (stop < 0) { - stop += length; - } - stop = MIN(length, MAX(stop, 0)); - } - } else { - // Negative step - if (self->start == mp_const_none) { - start = length - 1; - } else { - start = mp_obj_get_int(self->start); - if (start < 0) { - start += length; - } - start = MIN(length - 1, MAX(start, -1)); - } - - if (self->stop == mp_const_none) { - stop = -1; - } else { - stop = mp_obj_get_int(self->stop); - if (stop < 0) { - stop += length; - } - stop = MIN(length - 1, MAX(stop, -1)); - } - } - - result->start = start; - result->stop = stop; - result->step = step; -} -#endif /* MICROPY_VERSION v1.11 */ - void ndarray_fill_array_iterable(mp_float_t *array, mp_obj_t iterable) { mp_obj_iter_buf_t x_buf; mp_obj_t x_item, x_iterable = mp_getiter(iterable, &x_buf); diff --git a/code/ndarray.h b/code/ndarray.h index 4564f772..3025c051 100644 --- a/code/ndarray.h +++ b/code/ndarray.h @@ -113,11 +113,9 @@ typedef struct _mp_obj_slice_t { #if !CIRCUITPY #define translate(x) MP_ERROR_TEXT(x) -#define ndarray_set_value(a, b, c, d) mp_binary_set_val_array(a, b, c, d) -#else -void ndarray_set_value(char , void *, size_t , mp_obj_t ); #endif +#define ndarray_set_value(a, b, c, d) mp_binary_set_val_array(a, b, c, d) void ndarray_set_complex_value(void *, size_t , mp_obj_t ); #define NDARRAY_NUMERIC 0 diff --git a/code/ndarray_properties.c b/code/ndarray_properties.c index 547b1912..aa297158 100644 --- a/code/ndarray_properties.c +++ b/code/ndarray_properties.c @@ -24,29 +24,6 @@ #include "numpy/carray/carray.h" #endif -#ifndef CIRCUITPY - -// a somewhat hackish implementation of property getters/setters; -// this functions is hooked into the attr member of ndarray - -STATIC void call_local_method(mp_obj_t obj, qstr attr, mp_obj_t *dest) { - const mp_obj_type_t *type = mp_obj_get_type(obj); - while (MP_OBJ_TYPE_HAS_SLOT(type, locals_dict)) { - assert(MP_OBJ_TYPE_GET_SLOT(type, locals_dict)->base.type == &mp_type_dict); // MicroPython restriction, for now - mp_map_t *locals_map = &MP_OBJ_TYPE_GET_SLOT(type, locals_dict)->map; - mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP); - if (elem != NULL) { - mp_convert_member_lookup(obj, type, elem->value, dest); - break; - } - if (!MP_OBJ_TYPE_HAS_SLOT(type, parent)) { - break; - } - type = MP_OBJ_TYPE_GET_SLOT(type, parent); - } -} - - void ndarray_properties_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] == MP_OBJ_NULL) { switch(attr) { @@ -98,7 +75,8 @@ void ndarray_properties_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { #endif #endif /* ULAB_SUPPORTS_COMPLEX */ default: - call_local_method(self_in, attr, dest); + // forward to locals dict + dest[1] = MP_OBJ_SENTINEL; break; } } else { @@ -119,5 +97,3 @@ void ndarray_properties_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } } - -#endif /* CIRCUITPY */ diff --git a/code/ndarray_properties.h b/code/ndarray_properties.h index a074ec1f..3e0b9a40 100644 --- a/code/ndarray_properties.h +++ b/code/ndarray_properties.h @@ -22,74 +22,6 @@ #include "ndarray.h" #include "numpy/ndarray/ndarray_iter.h" -#if CIRCUITPY -typedef struct _mp_obj_property_t { - mp_obj_base_t base; - mp_obj_t proxy[3]; // getter, setter, deleter -} mp_obj_property_t; - -#if NDARRAY_HAS_DTYPE -MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_dtype_obj, ndarray_dtype); -STATIC const mp_obj_property_t ndarray_dtype_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&ndarray_get_dtype_obj, - mp_const_none, - mp_const_none }, -}; -#endif /* NDARRAY_HAS_DTYPE */ - -#if NDARRAY_HAS_FLATITER -MP_DEFINE_CONST_FUN_OBJ_1(ndarray_flatiter_make_new_obj, ndarray_flatiter_make_new); -STATIC const mp_obj_property_t ndarray_flat_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&ndarray_flatiter_make_new_obj, - mp_const_none, - mp_const_none }, -}; -#endif /* NDARRAY_HAS_FLATITER */ - -#if NDARRAY_HAS_ITEMSIZE -MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_itemsize_obj, ndarray_itemsize); -STATIC const mp_obj_property_t ndarray_itemsize_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&ndarray_get_itemsize_obj, - mp_const_none, - mp_const_none }, -}; -#endif /* NDARRAY_HAS_ITEMSIZE */ - -#if NDARRAY_HAS_SHAPE -MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_shape_obj, ndarray_shape); -STATIC const mp_obj_property_t ndarray_shape_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&ndarray_get_shape_obj, - mp_const_none, - mp_const_none }, -}; -#endif /* NDARRAY_HAS_SHAPE */ - -#if NDARRAY_HAS_SIZE -MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_size_obj, ndarray_size); -STATIC const mp_obj_property_t ndarray_size_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&ndarray_get_size_obj, - mp_const_none, - mp_const_none }, -}; -#endif /* NDARRAY_HAS_SIZE */ - -#if NDARRAY_HAS_STRIDES -MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_strides_obj, ndarray_strides); -STATIC const mp_obj_property_t ndarray_strides_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&ndarray_get_strides_obj, - mp_const_none, - mp_const_none }, -}; -#endif /* NDARRAY_HAS_STRIDES */ - -#else - void ndarray_properties_attr(mp_obj_t , qstr , mp_obj_t *); #if NDARRAY_HAS_DTYPE @@ -116,6 +48,4 @@ MP_DEFINE_CONST_FUN_OBJ_1(ndarray_size_obj, ndarray_size); MP_DEFINE_CONST_FUN_OBJ_1(ndarray_strides_obj, ndarray_strides); #endif -#endif /* CIRCUITPY */ - #endif diff --git a/code/numpy/fft/fft.c b/code/numpy/fft/fft.c index ad4996e3..42621f52 100644 --- a/code/numpy/fft/fft.c +++ b/code/numpy/fft/fft.c @@ -101,9 +101,5 @@ const mp_obj_module_t ulab_fft_module = { .globals = (mp_obj_dict_t*)&mp_module_ulab_fft_globals, }; #if CIRCUITPY_ULAB -#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144 -MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy_dot_fft, ulab_fft_module, MODULE_ULAB_ENABLED); -#else MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy_dot_fft, ulab_fft_module); #endif -#endif diff --git a/code/numpy/linalg/linalg.c b/code/numpy/linalg/linalg.c index 0243a5d9..55ac4752 100644 --- a/code/numpy/linalg/linalg.c +++ b/code/numpy/linalg/linalg.c @@ -537,10 +537,6 @@ const mp_obj_module_t ulab_linalg_module = { .globals = (mp_obj_dict_t*)&mp_module_ulab_linalg_globals, }; #if CIRCUITPY_ULAB -#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144 -MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy_dot_linalg, ulab_linalg_module, MODULE_ULAB_ENABLED); -#else MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy_dot_linalg, ulab_linalg_module); #endif #endif -#endif diff --git a/code/numpy/numpy.c b/code/numpy/numpy.c index d530638e..74de9088 100644 --- a/code/numpy/numpy.c +++ b/code/numpy/numpy.c @@ -397,9 +397,5 @@ const mp_obj_module_t ulab_numpy_module = { }; #if CIRCUITPY_ULAB -#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144 -MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy, ulab_numpy_module, MODULE_ULAB_ENABLED); -#else MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy, ulab_numpy_module); #endif -#endif diff --git a/code/scipy/linalg/linalg.c b/code/scipy/linalg/linalg.c index 52c04afe..a42392ce 100644 --- a/code/scipy/linalg/linalg.c +++ b/code/scipy/linalg/linalg.c @@ -276,10 +276,6 @@ const mp_obj_module_t ulab_scipy_linalg_module = { .globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_linalg_globals, }; #if CIRCUITPY_ULAB -#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144 -MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_linalg, ulab_scipy_linalg_module, MODULE_ULAB_ENABLED); -#else MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_linalg, ulab_scipy_linalg_module); #endif #endif -#endif diff --git a/code/scipy/optimize/optimize.c b/code/scipy/optimize/optimize.c index 7fc6b670..ef10288d 100644 --- a/code/scipy/optimize/optimize.c +++ b/code/scipy/optimize/optimize.c @@ -413,9 +413,5 @@ const mp_obj_module_t ulab_scipy_optimize_module = { .globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_optimize_globals, }; #if CIRCUITPY_ULAB -#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144 -MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_optimize, ulab_scipy_optimize_module, MODULE_ULAB_ENABLED); -#else MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_optimize, ulab_scipy_optimize_module); #endif -#endif diff --git a/code/scipy/scipy.c b/code/scipy/scipy.c index c9f51df5..6895127b 100644 --- a/code/scipy/scipy.c +++ b/code/scipy/scipy.c @@ -49,10 +49,6 @@ const mp_obj_module_t ulab_scipy_module = { .globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_globals, }; #if CIRCUITPY_ULAB -#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144 -MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy, ulab_scipy_module, MODULE_ULAB_ENABLED); -#else MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy, ulab_scipy_module); #endif -#endif #endif /* ULAB_HAS_SCIPY */ diff --git a/code/scipy/signal/signal.c b/code/scipy/signal/signal.c index 6afa05f6..db8d3cc5 100644 --- a/code/scipy/signal/signal.c +++ b/code/scipy/signal/signal.c @@ -134,9 +134,5 @@ const mp_obj_module_t ulab_scipy_signal_module = { .globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_signal_globals, }; #if CIRCUITPY_ULAB -#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144 -MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_signal, ulab_scipy_signal_module, MODULE_ULAB_ENABLED); -#else MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_signal, ulab_scipy_signal_module); #endif -#endif diff --git a/code/scipy/special/special.c b/code/scipy/special/special.c index 9d5ca629..0e561b6f 100644 --- a/code/scipy/special/special.c +++ b/code/scipy/special/special.c @@ -41,9 +41,5 @@ const mp_obj_module_t ulab_scipy_special_module = { .globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_special_globals, }; #if CIRCUITPY_ULAB -#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144 -MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_special, ulab_scipy_special_module, MODULE_ULAB_ENABLED); -#else MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_special, ulab_scipy_special_module); #endif -#endif diff --git a/code/ulab.c b/code/ulab.c index d731aac4..bb0f8758 100644 --- a/code/ulab.c +++ b/code/ulab.c @@ -76,26 +76,6 @@ STATIC const mp_rom_map_elem_t ulab_ndarray_locals_dict_table[] = { #if NDARRAY_HAS_SORT { MP_ROM_QSTR(MP_QSTR_sort), MP_ROM_PTR(&numerical_sort_inplace_obj) }, #endif - #ifdef CIRCUITPY - #if NDARRAY_HAS_DTYPE - { MP_ROM_QSTR(MP_QSTR_dtype), MP_ROM_PTR(&ndarray_dtype_obj) }, - #endif - #if NDARRAY_HAS_FLATITER - { MP_ROM_QSTR(MP_QSTR_flat), MP_ROM_PTR(&ndarray_flat_obj) }, - #endif - #if NDARRAY_HAS_ITEMSIZE - { MP_ROM_QSTR(MP_QSTR_itemsize), MP_ROM_PTR(&ndarray_itemsize_obj) }, - #endif - #if NDARRAY_HAS_SHAPE - { MP_ROM_QSTR(MP_QSTR_shape), MP_ROM_PTR(&ndarray_shape_obj) }, - #endif - #if NDARRAY_HAS_SIZE - { MP_ROM_QSTR(MP_QSTR_size), MP_ROM_PTR(&ndarray_size_obj) }, - #endif - #if NDARRAY_HAS_STRIDES - { MP_ROM_QSTR(MP_QSTR_strides), MP_ROM_PTR(&ndarray_strides_obj) }, - #endif - #endif /* CIRCUITPY */ }; STATIC MP_DEFINE_CONST_DICT(ulab_ndarray_locals_dict, ulab_ndarray_locals_dict_table); @@ -167,9 +147,7 @@ const mp_obj_type_t ulab_ndarray_type = { #if NDARRAY_HAS_BINARY_OPS .binary_op = ndarray_binary_op, #endif - #ifndef CIRCUITPY .attr = ndarray_properties_attr, - #endif .buffer_p = { .get_buffer = ndarray_get_buffer, }, ) }; @@ -253,10 +231,4 @@ const mp_obj_module_t ulab_user_cmodule = { .globals = (mp_obj_dict_t*)&mp_module_ulab_globals, }; -// Use old three-argument MP_REGISTER_MODULE for -// MicroPython <= v1.18.0: (1 << 16) | (18 << 8) | 0 -#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144 -MP_REGISTER_MODULE(MP_QSTR_ulab, ulab_user_cmodule, MODULE_ULAB_ENABLED); -#else MP_REGISTER_MODULE(MP_QSTR_ulab, ulab_user_cmodule); -#endif diff --git a/code/user/user.c b/code/user/user.c index dfc3fcde..88775fda 100644 --- a/code/user/user.c +++ b/code/user/user.c @@ -92,11 +92,7 @@ const mp_obj_module_t ulab_user_module = { .globals = (mp_obj_dict_t*)&mp_module_ulab_user_globals, }; #if CIRCUITPY_ULAB -#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144 -MP_REGISTER_MODULE(MP_QSTR_ulab_dot_user, ulab_user_module, ULAB_HAS_USER_MODULE); -#else MP_REGISTER_MODULE(MP_QSTR_ulab_dot_user, ulab_user_module); #endif #endif -#endif diff --git a/code/utils/utils.c b/code/utils/utils.c index fee67d47..6a59baf3 100644 --- a/code/utils/utils.c +++ b/code/utils/utils.c @@ -250,11 +250,7 @@ const mp_obj_module_t ulab_utils_module = { .globals = (mp_obj_dict_t*)&mp_module_ulab_utils_globals, }; #if CIRCUITPY_ULAB -#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144 -MP_REGISTER_MODULE(MP_QSTR_ulab_dot_utils, ulab_utils_module, MODULE_ULAB_ENABLED); -#else MP_REGISTER_MODULE(MP_QSTR_ulab_dot_utils, ulab_utils_module); #endif -#endif #endif /* ULAB_HAS_UTILS_MODULE */