Skip to content

Commit a726c1d

Browse files
authored
Merge pull request #310 from v923z/init-fix
len fix
2 parents 0e0956b + dc4ae42 commit a726c1d

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

code/ndarray.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ void ndarray_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki
503503
ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);
504504
uint8_t *array = (uint8_t *)self->array;
505505
mp_print_str(print, "array(");
506-
if(self->ndim == 0) {
506+
if(self->len == 0) {
507507
mp_print_str(print, "[]");
508508
}
509509
#if ULAB_MAX_DIMS > 3
@@ -1759,13 +1759,11 @@ mp_obj_t ndarray_binary_op(mp_binary_op_t _op, mp_obj_t lobj, mp_obj_t robj) {
17591759
#if NDARRAY_HAS_UNARY_OPS
17601760
mp_obj_t ndarray_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
17611761
ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);
1762-
uint8_t itemsize = mp_binary_get_size('@', self->dtype, NULL);
17631762
ndarray_obj_t *ndarray = NULL;
17641763

17651764
switch (op) {
17661765
#if NDARRAY_HAS_UNARY_OP_ABS
17671766
case MP_UNARY_OP_ABS:
1768-
(void)itemsize;
17691767
ndarray = ndarray_copy_view(self);
17701768
// if Booleam, NDARRAY_UINT8, or NDARRAY_UINT16, there is nothing to do
17711769
if(self->dtype == NDARRAY_INT8) {
@@ -1798,18 +1796,15 @@ mp_obj_t ndarray_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
17981796
if(ndarray->boolean) {
17991797
for(size_t i=0; i < ndarray->len; i++, array++) *array = *array ^ 0x01;
18001798
} else {
1799+
uint8_t itemsize = mp_binary_get_size('@', self->dtype, NULL);
18011800
for(size_t i=0; i < ndarray->len*itemsize; i++, array++) *array ^= 0xFF;
18021801
}
18031802
return MP_OBJ_FROM_PTR(ndarray);
18041803
break;
18051804
#endif
18061805
#if NDARRAY_HAS_UNARY_OP_LEN
18071806
case MP_UNARY_OP_LEN:
1808-
if(self->ndim > 1) {
1809-
return mp_obj_new_int(self->ndim);
1810-
} else {
1811-
return mp_obj_new_int(self->len);
1812-
}
1807+
return mp_obj_new_int(self->shape[ULAB_MAX_DIMS - self->ndim]);
18131808
break;
18141809
#endif
18151810
#if NDARRAY_HAS_UNARY_OP_NEGATIVE

code/ulab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#include "user/user.h"
3535

36-
#define ULAB_VERSION 2.3.0
36+
#define ULAB_VERSION 2.3.1
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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Mon, 8 Feb 2021
22

3+
version 2.3.1
4+
5+
partially fix https://github.com/v923z/micropython-ulab/issues/304, and len unary operator
6+
7+
Mon, 8 Feb 2021
8+
39
version 2.3.0
410

511
added any and all functions

0 commit comments

Comments
 (0)