Skip to content

Commit c03990c

Browse files
authored
Merge pull request #458 from v923z/sum-fix
Sum fix
2 parents cd70c91 + e655c94 commit c03990c

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

code/numpy/numerical.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static mp_obj_t numerical_sum_mean_std_ndarray(ndarray_obj_t *ndarray, mp_obj_t
293293
if(ndarray->dtype == NDARRAY_FLOAT) {
294294
return mp_obj_new_float(M * ndarray->len);
295295
} else {
296-
return mp_obj_new_int((int32_t)(M * ndarray->len));
296+
return mp_obj_new_int((int32_t)MICROPY_FLOAT_C_FUN(round)(M * ndarray->len));
297297
}
298298
} else if(optype == NUMERICAL_MEAN) {
299299
return mp_obj_new_float(M);

code/ulab.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "user/user.h"
3434
#include "utils/utils.h"
3535

36-
#define ULAB_VERSION 3.3.6
36+
#define ULAB_VERSION 3.3.7
3737
#define xstr(s) str(s)
3838
#define str(s) #s
3939
#define ULAB_VERSION_STRING xstr(ULAB_VERSION) xstr(-) xstr(ULAB_MAX_DIMS) xstr(D)

docs/ulab-change-log.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Tue, 30 Nov 2021
2+
3+
version 3.3.7
4+
5+
fix sum() for integer/Boolean types
6+
17
Sat, 20 Nov 2021
28

39
version 3.3.6

tests/1d/numpy/sum.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from ulab import numpy as np
2+
3+
r = range(15)
4+
5+
a = np.array(r, dtype=np.uint8)
6+
print(np.sum(a))
7+
8+
a = np.array(r, dtype=np.int8)
9+
print(np.sum(a))
10+
11+
a = np.array(r, dtype=np.uint16)
12+
print(np.sum(a))
13+
14+
a = np.array(r, dtype=np.int16)
15+
print(np.sum(a))
16+
17+
a = np.array(r, dtype=np.float)
18+
print(np.sum(a))
19+
20+
a = np.array([False] + [True]*15, dtype=np.bool)
21+
print(np.sum(a))

tests/1d/numpy/sum.py.exp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
105
2+
105
3+
105
4+
105
5+
105.0
6+
15

0 commit comments

Comments
 (0)