Skip to content

Commit

Permalink
Merge pull request #455 from v923z/shape-fix
Browse files Browse the repository at this point in the history
fix ndarray_shape for arrays of zero length
  • Loading branch information
v923z authored Nov 24, 2021
2 parents bf15ede + 175c733 commit cd70c91
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
11 changes: 6 additions & 5 deletions code/ndarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,12 +1479,13 @@ mp_obj_t ndarray_itemsize(mp_obj_t self_in) {
#if NDARRAY_HAS_SHAPE
mp_obj_t ndarray_shape(mp_obj_t self_in) {
ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t *items = m_new(mp_obj_t, self->ndim);
for(uint8_t i=0; i < self->ndim; i++) {
items[self->ndim - i - 1] = mp_obj_new_int(self->shape[ULAB_MAX_DIMS - i - 1]);
uint8_t nitems = MAX(1, self->ndim);
mp_obj_t *items = m_new(mp_obj_t, nitems);
for(uint8_t i = 0; i < nitems; i++) {
items[nitems - i - 1] = mp_obj_new_int(self->shape[ULAB_MAX_DIMS - i - 1]);
}
mp_obj_t tuple = mp_obj_new_tuple(self->ndim, items);
m_del(mp_obj_t, items, self->ndim);
mp_obj_t tuple = mp_obj_new_tuple(nitems, items);
m_del(mp_obj_t, items, nitems);
return tuple;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion code/ulab.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "user/user.h"
#include "utils/utils.h"

#define ULAB_VERSION 3.3.5
#define ULAB_VERSION 3.3.6
#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 @@
Sat, 20 Nov 2021

version 3.3.6

fix .shape for arrays of zero length (#454)

Sun, 07 Nov 2021

version 3.3.5
Expand Down

0 comments on commit cd70c91

Please sign in to comment.