diff --git a/code/numerical/numerical.c b/code/numerical/numerical.c index 3c1e5ca9..4f43f85d 100644 --- a/code/numerical/numerical.c +++ b/code/numerical/numerical.c @@ -68,16 +68,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; @@ -88,7 +82,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)); } } diff --git a/code/ulab.c b/code/ulab.c index eec70c1f..2a34eb6d 100644 --- a/code/ulab.c +++ b/code/ulab.c @@ -32,7 +32,7 @@ #include "user/user.h" #include "vector/vectorise.h" -#define ULAB_VERSION 1.7.1 +#define ULAB_VERSION 1.7.2 #define xstr(s) str(s) #define str(s) #s #if ULAB_NUMPY_COMPATIBILITY diff --git a/code/ulab.h b/code/ulab.h index 7f8fdfe0..b64bfbd4 100644 --- a/code/ulab.h +++ b/code/ulab.h @@ -74,8 +74,8 @@ // the ndarray binary operators #define NDARRAY_HAS_BINARY_OPS (1) -// Firmware size can be reduced at the expense of speed by using function -// pointers in iterations. For each operator, he function pointer saves around +// Firmware size can be reduced at the expense of speed by using function +// pointers in iterations. For each operator, he function pointer saves around // 2 kB in the two-dimensional case, and around 4 kB in the four-dimensional case. #define NDARRAY_BINARY_USES_FUN_POINTER (0) @@ -209,7 +209,7 @@ #ifndef ULAB_VECTORISE_MODULE #define ULAB_VECTORISE_MODULE (1) -// Firmware size can be reduced at the expense of speed by using a function +// Firmware size can be reduced at the expense of speed by using a function // pointer in iterations. Setting ULAB_VECTORISE_USES_FUNCPOINTER to 1 saves // around 800 bytes in the four-dimensional case, and around 200 in two dimensions. #define ULAB_VECTORISE_USES_FUN_POINTER (1) diff --git a/docs/ulab-change-log.md b/docs/ulab-change-log.md index 8589de56..1e71feeb 100644 --- a/docs/ulab-change-log.md +++ b/docs/ulab-change-log.md @@ -1,3 +1,9 @@ +Fri, 29 Jan 2021 + +version 1.7.2 + + fixed code calculating the standard deviation of iterables + Fri, 15 Jan 2021 version 1.7.1