Skip to content

Commit

Permalink
Merge pull request #298 from v923z/std-fix
Browse files Browse the repository at this point in the history
Std fix
  • Loading branch information
v923z authored Jan 29, 2021
2 parents e5961ec + 685ec61 commit eb33480
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
10 changes: 2 additions & 8 deletions code/numpy/numerical/numerical.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,10 @@ static mp_obj_t numerical_sum_mean_std_iterable(mp_obj_t oin, uint8_t optype, si
size_t count = 0;
mp_obj_iter_buf_t iter_buf;
mp_obj_t item, iterable = mp_getiter(oin, &iter_buf);
if((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
value = mp_obj_get_float(item);
sum += value;
M = m = value;
count++;
}
while((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
value = mp_obj_get_float(item);
sum += value;
m = M + (value - M) / count;
m = M + (value - M) / (count + 1);
s = S + (value - M) * (value - m);
M = m;
S = s;
Expand All @@ -87,7 +81,7 @@ static mp_obj_t numerical_sum_mean_std_iterable(mp_obj_t oin, uint8_t optype, si
} else if(optype == NUMERICAL_MEAN) {
return count > 0 ? mp_obj_new_float(m) : mp_obj_new_float(MICROPY_FLOAT_CONST(0.0));
} else { // this should be the case of the standard deviation
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));
return count > ddof ? mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(s / (count - ddof))) : mp_obj_new_float(MICROPY_FLOAT_CONST(0.0));
}
}

Expand Down
6 changes: 1 addition & 5 deletions code/ulab.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,16 @@
#include "ndarray.h"
#include "ndarray_properties.h"

#if CIRCUITPY
#include "circuitpy/vector/vector.h"
#else
#include "numpy/numpy.h"
#include "scipy/scipy.h"
#include "numpy/fft/fft.h"
#include "numpy/linalg/linalg.h"
// TODO: we should get rid of this; array.sort depends on it
#include "numpy/numerical/numerical.h"
#endif

#include "user/user.h"

#define ULAB_VERSION 2.1.4
#define ULAB_VERSION 2.1.5
#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 @@
Fri, 29 Jan 2021

version 2.1.5

fixed error, when calculating standard deviation of iterables

wed, 27 Jan 2021

version 2.1.4
Expand Down

0 comments on commit eb33480

Please sign in to comment.