diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2020-03-17 15:33:08 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-17 15:33:08 -0700 |
| commit | 4603c6ddd7aaccc5674db135fe3951e475ea05d8 (patch) | |
| tree | 238adb6865105638b47fa6a21b4be5d8afbf74df /py | |
| parent | 9453e10c57deee12f895466d872e3e9198c73f7d (diff) | |
| parent | 38a718ff5558c2286172091615aaeb2ded5f70f5 (diff) | |
Merge pull request #2711 from jepler/update-ulab5.1.0-rc.05.1.0
update ulab
Diffstat (limited to 'py')
| -rw-r--r-- | py/circuitpy_defns.mk | 2 | ||||
| -rw-r--r-- | py/circuitpy_mpconfig.h | 2 | ||||
| -rw-r--r-- | py/circuitpy_mpconfig.mk | 4 | ||||
| -rwxr-xr-x | py/mpconfig.h | 4 | ||||
| -rw-r--r-- | py/obj.h | 1 | ||||
| -rw-r--r-- | py/objmodule.c | 2 | ||||
| -rw-r--r-- | py/objslice.c | 65 | ||||
| -rw-r--r-- | py/py.mk | 5 |
8 files changed, 76 insertions, 9 deletions
diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 92021d0d0..f84d0b5b1 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -431,7 +431,7 @@ $(addprefix lib/,\ libm/atanf.c \ libm/atan2f.c \ ) -ifeq ($(MICROPY_PY_ULAB),1) +ifeq ($(CIRCUITPY_ULAB),1) SRC_LIBM += \ $(addprefix lib/,\ libm/acoshf.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index acff27bcf..04e191264 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -581,7 +581,7 @@ extern const struct _mp_obj_module_t ustack_module; #define JSON_MODULE #endif -#if defined(MICROPY_PY_ULAB) && MICROPY_PY_ULAB +#if defined(CIRCUITPY_ULAB) && CIRCUITPY_ULAB #define ULAB_MODULE \ { MP_ROM_QSTR(MP_QSTR_ulab), MP_ROM_PTR(&ulab_user_cmodule) }, #else diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 21b1abd9b..1a375efc6 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -340,8 +340,8 @@ endif CFLAGS += -DCIRCUITPY_SERIAL_UART=$(CIRCUITPY_SERIAL_UART) # ulab numerics library -ifndef MICROPY_PY_ULAB -MICROPY_PY_ULAB = $(CIRCUITPY_FULL_BUILD) +ifndef CIRCUITPY_ULAB +CIRCUITPY_ULAB = $(CIRCUITPY_FULL_BUILD) endif # Enabled micropython.native decorator (experimental) diff --git a/py/mpconfig.h b/py/mpconfig.h index 01572f546..513f04f6e 100755 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1178,8 +1178,8 @@ typedef double mp_float_t; #define MICROPY_PY_UJSON (0) #endif -#ifndef MICROPY_PY_ULAB -#define MICROPY_PY_ULAB (0) +#ifndef CIRCUITPY_ULAB +#define CIRCUITPY_ULAB (0) #endif #ifndef MICROPY_PY_URE @@ -858,6 +858,7 @@ typedef struct { mp_uint_t stop; mp_int_t step; } mp_bound_slice_t; +void mp_obj_slice_indices(mp_obj_t self_in, mp_int_t length, mp_bound_slice_t *result); // Compute the new length of a sequence and ensure an exception is thrown on overflow. size_t mp_seq_multiply_len(size_t item_sz, size_t len); diff --git a/py/objmodule.c b/py/objmodule.c index 7405a6919..b6a8a084e 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -213,7 +213,7 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { { MP_ROM_QSTR(MP_QSTR_ujson), MP_ROM_PTR(&mp_module_ujson) }, #endif #endif -#if MICROPY_PY_ULAB +#if CIRCUITPY_ULAB #if CIRCUITPY // CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here. // TODO: move to shared-bindings/ diff --git a/py/objslice.c b/py/objslice.c index 5a15be55a..cbbee326e 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -152,6 +152,71 @@ mp_obj_t mp_obj_new_slice(mp_obj_t ostart, mp_obj_t ostop, mp_obj_t ostep) { return MP_OBJ_FROM_PTR(o); } +// Return the real index and step values for a slice when applied to a sequence of +// the given length, resolving missing components, negative values and values off +// the end of the sequence. +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 cannot 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; +} + #if MICROPY_PY_BUILTINS_SLICE_ATTRS STATIC mp_obj_t slice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { @@ -105,9 +105,10 @@ $(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare $(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS) endif -ifeq ($(MICROPY_PY_ULAB),1) +ifeq ($(CIRCUITPY_ULAB),1) SRC_MOD += $(addprefix extmod/ulab/code/, \ create.c \ +extras.c \ fft.c \ filter.c \ linalg.c \ @@ -117,7 +118,7 @@ poly.c \ ulab.c \ vectorise.c \ ) -CFLAGS_MOD += -DMICROPY_PY_ULAB=1 -DMODULE_ULAB_ENABLED=1 +CFLAGS_MOD += -DCIRCUITPY_ULAB=1 -DMODULE_ULAB_ENABLED=1 $(BUILD)/extmod/ulab/code/%.o: CFLAGS += -Wno-sign-compare -Wno-missing-prototypes -Wno-unused-parameter -Wno-missing-declarations -Wno-error -Wno-shadow -Wno-maybe-uninitialized -DCIRCUITPY endif |
