add ndim property (#725)
This commit is contained in:
parent
844f6e5e1e
commit
66e9eb3ed3
6 changed files with 27 additions and 3 deletions
|
|
@ -1398,6 +1398,13 @@ mp_obj_t ndarray_itemsize(mp_obj_t self_in) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if NDARRAY_HAS_NDIM
|
||||||
|
mp_obj_t ndarray_ndim(mp_obj_t self_in) {
|
||||||
|
ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(self->ndim);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if NDARRAY_HAS_SHAPE
|
#if NDARRAY_HAS_SHAPE
|
||||||
mp_obj_t ndarray_shape(mp_obj_t self_in) {
|
mp_obj_t ndarray_shape(mp_obj_t self_in) {
|
||||||
ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
|
|
||||||
|
|
@ -232,6 +232,10 @@ mp_obj_t ndarray_dtype(mp_obj_t );
|
||||||
mp_obj_t ndarray_itemsize(mp_obj_t );
|
mp_obj_t ndarray_itemsize(mp_obj_t );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if NDARRAY_HAS_NDIM
|
||||||
|
mp_obj_t ndarray_ndim(mp_obj_t );
|
||||||
|
#endif
|
||||||
|
|
||||||
#if NDARRAY_HAS_SIZE
|
#if NDARRAY_HAS_SIZE
|
||||||
mp_obj_t ndarray_size(mp_obj_t );
|
mp_obj_t ndarray_size(mp_obj_t );
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
*
|
*
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2021 Zoltán Vörös
|
* Copyright (c) 2021-2025 Zoltán Vörös
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -42,6 +42,11 @@ void ndarray_properties_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||||
dest[0] = ndarray_itemsize(self_in);
|
dest[0] = ndarray_itemsize(self_in);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
#if NDARRAY_HAS_NDIM
|
||||||
|
case MP_QSTR_ndim:
|
||||||
|
dest[0] = ndarray_ndim(self_in);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
#if NDARRAY_HAS_SHAPE
|
#if NDARRAY_HAS_SHAPE
|
||||||
case MP_QSTR_shape:
|
case MP_QSTR_shape:
|
||||||
dest[0] = ndarray_shape(self_in);
|
dest[0] = ndarray_shape(self_in);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
|
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
|
||||||
* 2020-2021 Zoltán Vörös
|
* 2020-2025 Zoltán Vörös
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _NDARRAY_PROPERTIES_
|
#ifndef _NDARRAY_PROPERTIES_
|
||||||
|
|
@ -36,6 +36,10 @@ MP_DEFINE_CONST_FUN_OBJ_1(ndarray_flatiter_make_new_obj, ndarray_flatiter_make_n
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_itemsize_obj, ndarray_itemsize);
|
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_itemsize_obj, ndarray_itemsize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if NDARRAY_HAS_NDIM
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_ndim_obj, ndarray_ndim);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if NDARRAY_HAS_SHAPE
|
#if NDARRAY_HAS_SHAPE
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_shape_obj, ndarray_shape);
|
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_shape_obj, ndarray_shape);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
#include "user/user.h"
|
#include "user/user.h"
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
|
|
||||||
#define ULAB_VERSION 6.7.7
|
#define ULAB_VERSION 6.8.0
|
||||||
#define xstr(s) str(s)
|
#define xstr(s) str(s)
|
||||||
#define str(s) #s
|
#define str(s) #s
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -245,6 +245,10 @@
|
||||||
#define NDARRAY_HAS_ITEMSIZE (1)
|
#define NDARRAY_HAS_ITEMSIZE (1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NDARRAY_HAS_NDIM
|
||||||
|
#define NDARRAY_HAS_NDIM (1)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef NDARRAY_HAS_RESHAPE
|
#ifndef NDARRAY_HAS_RESHAPE
|
||||||
#define NDARRAY_HAS_RESHAPE (1)
|
#define NDARRAY_HAS_RESHAPE (1)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue