Skip to content

Commit cd70c91

Browse files
authored
Merge pull request #455 from v923z/shape-fix
fix ndarray_shape for arrays of zero length
2 parents bf15ede + 175c733 commit cd70c91

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

code/ndarray.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,12 +1479,13 @@ mp_obj_t ndarray_itemsize(mp_obj_t self_in) {
14791479
#if NDARRAY_HAS_SHAPE
14801480
mp_obj_t ndarray_shape(mp_obj_t self_in) {
14811481
ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);
1482-
mp_obj_t *items = m_new(mp_obj_t, self->ndim);
1483-
for(uint8_t i=0; i < self->ndim; i++) {
1484-
items[self->ndim - i - 1] = mp_obj_new_int(self->shape[ULAB_MAX_DIMS - i - 1]);
1482+
uint8_t nitems = MAX(1, self->ndim);
1483+
mp_obj_t *items = m_new(mp_obj_t, nitems);
1484+
for(uint8_t i = 0; i < nitems; i++) {
1485+
items[nitems - i - 1] = mp_obj_new_int(self->shape[ULAB_MAX_DIMS - i - 1]);
14851486
}
1486-
mp_obj_t tuple = mp_obj_new_tuple(self->ndim, items);
1487-
m_del(mp_obj_t, items, self->ndim);
1487+
mp_obj_t tuple = mp_obj_new_tuple(nitems, items);
1488+
m_del(mp_obj_t, items, nitems);
14881489
return tuple;
14891490
}
14901491
#endif

code/ulab.c

Lines changed: 1 addition & 1 deletion
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.5
36+
#define ULAB_VERSION 3.3.6
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,3 +1,9 @@
1+
Sat, 20 Nov 2021
2+
3+
version 3.3.6
4+
5+
fix .shape for arrays of zero length (#454)
6+
17
Sun, 07 Nov 2021
28

39
version 3.3.5

0 commit comments

Comments
 (0)