From a0977444559ab024cc8134cbf0981269f4c21178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20V=C3=B6r=C3=B6s?= Date: Tue, 30 Nov 2021 20:29:22 +0100 Subject: [PATCH 1/2] fix sum() for integer/Boolean types --- code/numpy/numerical.c | 2 +- code/ulab.c | 2 +- docs/ulab-change-log.md | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/code/numpy/numerical.c b/code/numpy/numerical.c index 34a35a3d..9dae02f5 100644 --- a/code/numpy/numerical.c +++ b/code/numpy/numerical.c @@ -293,7 +293,7 @@ static mp_obj_t numerical_sum_mean_std_ndarray(ndarray_obj_t *ndarray, mp_obj_t if(ndarray->dtype == NDARRAY_FLOAT) { return mp_obj_new_float(M * ndarray->len); } else { - return mp_obj_new_int((int32_t)(M * ndarray->len)); + return mp_obj_new_int((int32_t)MICROPY_FLOAT_C_FUN(round)(M * ndarray->len)); } } else if(optype == NUMERICAL_MEAN) { return mp_obj_new_float(M); diff --git a/code/ulab.c b/code/ulab.c index 3315f028..82a6d01d 100644 --- a/code/ulab.c +++ b/code/ulab.c @@ -33,7 +33,7 @@ #include "user/user.h" #include "utils/utils.h" -#define ULAB_VERSION 3.3.6 +#define ULAB_VERSION 3.3.7 #define xstr(s) str(s) #define str(s) #s #define ULAB_VERSION_STRING xstr(ULAB_VERSION) xstr(-) xstr(ULAB_MAX_DIMS) xstr(D) diff --git a/docs/ulab-change-log.md b/docs/ulab-change-log.md index 7467cd5a..a61b81c6 100644 --- a/docs/ulab-change-log.md +++ b/docs/ulab-change-log.md @@ -1,3 +1,9 @@ +Tue, 30 Nov 2021 + +version 3.3.7 + + fix sum() for integer/Boolean types + Sat, 20 Nov 2021 version 3.3.6 From e655c9410812c0dfa3685dff118ae84cb17b26e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20V=C3=B6r=C3=B6s?= Date: Tue, 30 Nov 2021 20:38:43 +0100 Subject: [PATCH 2/2] add simple test for sum() --- tests/1d/numpy/sum.py | 21 +++++++++++++++++++++ tests/1d/numpy/sum.py.exp | 6 ++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/1d/numpy/sum.py create mode 100644 tests/1d/numpy/sum.py.exp diff --git a/tests/1d/numpy/sum.py b/tests/1d/numpy/sum.py new file mode 100644 index 00000000..a0293136 --- /dev/null +++ b/tests/1d/numpy/sum.py @@ -0,0 +1,21 @@ +from ulab import numpy as np + +r = range(15) + +a = np.array(r, dtype=np.uint8) +print(np.sum(a)) + +a = np.array(r, dtype=np.int8) +print(np.sum(a)) + +a = np.array(r, dtype=np.uint16) +print(np.sum(a)) + +a = np.array(r, dtype=np.int16) +print(np.sum(a)) + +a = np.array(r, dtype=np.float) +print(np.sum(a)) + +a = np.array([False] + [True]*15, dtype=np.bool) +print(np.sum(a)) diff --git a/tests/1d/numpy/sum.py.exp b/tests/1d/numpy/sum.py.exp new file mode 100644 index 00000000..7f1b8014 --- /dev/null +++ b/tests/1d/numpy/sum.py.exp @@ -0,0 +1,6 @@ +105 +105 +105 +105 +105.0 +15