Skip to content

Commit

Permalink
Merge pull request #458 from v923z/sum-fix
Browse files Browse the repository at this point in the history
Sum fix
  • Loading branch information
v923z authored Nov 30, 2021
2 parents cd70c91 + e655c94 commit c03990c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion code/numpy/numerical.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion code/ulab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 @@
Tue, 30 Nov 2021

version 3.3.7

fix sum() for integer/Boolean types

Sat, 20 Nov 2021

version 3.3.6
Expand Down
21 changes: 21 additions & 0 deletions tests/1d/numpy/sum.py
Original file line number Diff line number Diff line change
@@ -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))
6 changes: 6 additions & 0 deletions tests/1d/numpy/sum.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
105
105
105
105
105.0
15

0 comments on commit c03990c

Please sign in to comment.