diff --git a/code/ndarray.c b/code/ndarray.c index 36c523a8..bd622718 100644 --- a/code/ndarray.c +++ b/code/ndarray.c @@ -42,6 +42,70 @@ STATIC mp_obj_array_t *array_new(char typecode, size_t n) { return o; } +#ifdef OPENMV +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 + mp_float_t ndarray_get_float_value(void *data, uint8_t typecode, size_t index) { if(typecode == NDARRAY_UINT8) { return (mp_float_t)((uint8_t *)data)[index]; diff --git a/code/ndarray.h b/code/ndarray.h index 285db971..bd0c9325 100644 --- a/code/ndarray.h +++ b/code/ndarray.h @@ -26,12 +26,26 @@ #define FLOAT_TYPECODE 'd' #endif +#ifdef OPENMV +#define mp_obj_is_bool(o) (MP_OBJ_IS_TYPE((o), &mp_type_bool)) +#define translate(x) x + +typedef struct _mp_obj_slice_t { + mp_obj_base_t base; + mp_obj_t start; + mp_obj_t stop; + mp_obj_t step; +} mp_obj_slice_t; + +void mp_obj_slice_get(mp_obj_t self_in, mp_obj_t *, mp_obj_t *, mp_obj_t *); +#else #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 #define translate(x) MP_ERROR_TEXT(x) #endif +#endif #define SWAP(t, a, b) { t tmp = a; a = b; b = tmp; } diff --git a/code/ulab.c b/code/ulab.c index 49260c53..504e8dbf 100644 --- a/code/ulab.c +++ b/code/ulab.c @@ -32,7 +32,7 @@ #include "approx.h" #include "extras.h" -STATIC MP_DEFINE_STR_OBJ(ulab_version_obj, "0.50.1"); +STATIC MP_DEFINE_STR_OBJ(ulab_version_obj, "0.50.2"); MP_DEFINE_CONST_FUN_OBJ_KW(ndarray_flatten_obj, 1, ndarray_flatten); @@ -116,7 +116,11 @@ STATIC MP_DEFINE_CONST_DICT ( ulab_globals_table ); -mp_obj_module_t ulab_user_cmodule = { +#ifdef OPENMV +const struct _mp_obj_module_t ulab_user_cmodule = { +#else +const mp_obj_module_t ulab_user_cmodule = { +#endif .base = { &mp_type_module }, .globals = (mp_obj_dict_t*)&mp_module_ulab_globals, }; diff --git a/docs/ulab-change-log.md b/docs/ulab-change-log.md index ed4cc06c..4bb3392f 100644 --- a/docs/ulab-change-log.md +++ b/docs/ulab-change-log.md @@ -1,3 +1,9 @@ +Fri, 12 Jun 2020 + +version 0.50.2 + + fixes compilation error in openmv + Mon, 1 Jun 2020 version 0.50.1