Skip to content

Commit 66e9eb3

Browse files
authored
add ndim property (#725)
1 parent 844f6e5 commit 66e9eb3

File tree

6 files changed

+27
-3
lines changed

6 files changed

+27
-3
lines changed

code/ndarray.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,13 @@ mp_obj_t ndarray_itemsize(mp_obj_t self_in) {
13981398
}
13991399
#endif
14001400

1401+
#if NDARRAY_HAS_NDIM
1402+
mp_obj_t ndarray_ndim(mp_obj_t self_in) {
1403+
ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);
1404+
return MP_OBJ_NEW_SMALL_INT(self->ndim);
1405+
}
1406+
#endif
1407+
14011408
#if NDARRAY_HAS_SHAPE
14021409
mp_obj_t ndarray_shape(mp_obj_t self_in) {
14031410
ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);

code/ndarray.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ mp_obj_t ndarray_dtype(mp_obj_t );
232232
mp_obj_t ndarray_itemsize(mp_obj_t );
233233
#endif
234234

235+
#if NDARRAY_HAS_NDIM
236+
mp_obj_t ndarray_ndim(mp_obj_t );
237+
#endif
238+
235239
#if NDARRAY_HAS_SIZE
236240
mp_obj_t ndarray_size(mp_obj_t );
237241
#endif

code/ndarray_properties.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* The MIT License (MIT)
88
*
9-
* Copyright (c) 2021 Zoltán Vörös
9+
* Copyright (c) 2021-2025 Zoltán Vörös
1010
*
1111
*/
1212

@@ -42,6 +42,11 @@ void ndarray_properties_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
4242
dest[0] = ndarray_itemsize(self_in);
4343
break;
4444
#endif
45+
#if NDARRAY_HAS_NDIM
46+
case MP_QSTR_ndim:
47+
dest[0] = ndarray_ndim(self_in);
48+
break;
49+
#endif
4550
#if NDARRAY_HAS_SHAPE
4651
case MP_QSTR_shape:
4752
dest[0] = ndarray_shape(self_in);

code/ndarray_properties.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* The MIT License (MIT)
88
*
99
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
10-
* 2020-2021 Zoltán Vörös
10+
* 2020-2025 Zoltán Vörös
1111
*/
1212

1313
#ifndef _NDARRAY_PROPERTIES_
@@ -36,6 +36,10 @@ MP_DEFINE_CONST_FUN_OBJ_1(ndarray_flatiter_make_new_obj, ndarray_flatiter_make_n
3636
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_itemsize_obj, ndarray_itemsize);
3737
#endif
3838

39+
#if NDARRAY_HAS_NDIM
40+
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_ndim_obj, ndarray_ndim);
41+
#endif
42+
3943
#if NDARRAY_HAS_SHAPE
4044
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_shape_obj, ndarray_shape);
4145
#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 6.7.7
36+
#define ULAB_VERSION 6.8.0
3737
#define xstr(s) str(s)
3838
#define str(s) #s
3939

code/ulab.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@
245245
#define NDARRAY_HAS_ITEMSIZE (1)
246246
#endif
247247

248+
#ifndef NDARRAY_HAS_NDIM
249+
#define NDARRAY_HAS_NDIM (1)
250+
#endif
251+
248252
#ifndef NDARRAY_HAS_RESHAPE
249253
#define NDARRAY_HAS_RESHAPE (1)
250254
#endif

0 commit comments

Comments
 (0)