Skip to content

Commit eb33480

Browse files
authored
Merge pull request #298 from v923z/std-fix
Std fix
2 parents e5961ec + 685ec61 commit eb33480

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

code/numpy/numerical/numerical.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,10 @@ static mp_obj_t numerical_sum_mean_std_iterable(mp_obj_t oin, uint8_t optype, si
6767
size_t count = 0;
6868
mp_obj_iter_buf_t iter_buf;
6969
mp_obj_t item, iterable = mp_getiter(oin, &iter_buf);
70-
if((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
71-
value = mp_obj_get_float(item);
72-
sum += value;
73-
M = m = value;
74-
count++;
75-
}
7670
while((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
7771
value = mp_obj_get_float(item);
7872
sum += value;
79-
m = M + (value - M) / count;
73+
m = M + (value - M) / (count + 1);
8074
s = S + (value - M) * (value - m);
8175
M = m;
8276
S = s;
@@ -87,7 +81,7 @@ static mp_obj_t numerical_sum_mean_std_iterable(mp_obj_t oin, uint8_t optype, si
8781
} else if(optype == NUMERICAL_MEAN) {
8882
return count > 0 ? mp_obj_new_float(m) : mp_obj_new_float(MICROPY_FLOAT_CONST(0.0));
8983
} else { // this should be the case of the standard deviation
90-
return count > ddof ? mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(count * s / (count - ddof))) : mp_obj_new_float(MICROPY_FLOAT_CONST(0.0));
84+
return count > ddof ? mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(s / (count - ddof))) : mp_obj_new_float(MICROPY_FLOAT_CONST(0.0));
9185
}
9286
}
9387

code/ulab.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@
2424
#include "ndarray.h"
2525
#include "ndarray_properties.h"
2626

27-
#if CIRCUITPY
28-
#include "circuitpy/vector/vector.h"
29-
#else
3027
#include "numpy/numpy.h"
3128
#include "scipy/scipy.h"
3229
#include "numpy/fft/fft.h"
3330
#include "numpy/linalg/linalg.h"
3431
// TODO: we should get rid of this; array.sort depends on it
3532
#include "numpy/numerical/numerical.h"
36-
#endif
3733

3834
#include "user/user.h"
3935

40-
#define ULAB_VERSION 2.1.4
36+
#define ULAB_VERSION 2.1.5
4137
#define xstr(s) str(s)
4238
#define str(s) #s
4339
#define ULAB_VERSION_STRING xstr(ULAB_VERSION) xstr(-) xstr(ULAB_MAX_DIMS) xstr(D)

docs/ulab-change-log.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Fri, 29 Jan 2021
2+
3+
version 2.1.5
4+
5+
fixed error, when calculating standard deviation of iterables
6+
17
wed, 27 Jan 2021
28

39
version 2.1.4

0 commit comments

Comments
 (0)