Skip to content

Commit

Permalink
Merge pull request #125 from v923z/openmv-fix
Browse files Browse the repository at this point in the history
fixes compilation error in openmv
  • Loading branch information
v923z authored Jun 16, 2020
2 parents 4a3c12e + 37140d5 commit a223de9
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
64 changes: 64 additions & 0 deletions code/ndarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
14 changes: 14 additions & 0 deletions code/ndarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
8 changes: 6 additions & 2 deletions code/ulab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
};
Expand Down
6 changes: 6 additions & 0 deletions docs/ulab-change-log.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit a223de9

Please sign in to comment.