Skip to content

Commit 2df210f

Browse files
committed
Drop certain CircuitPython workarounds that are no longer needed
* ndarray_set_value: in CircuitPython 9 * mp_obj_slice_indices: ditto * Use modern MP_REGISTER_MODULE calls: ditto * use MP_OBJ_SENTINEL to forward to locals dict (was never necessary?)
1 parent 84f99f1 commit 2df210f

File tree

15 files changed

+3
-259
lines changed

15 files changed

+3
-259
lines changed

code/ndarray.c

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -61,98 +61,6 @@ void ndarray_set_complex_value(void *p, size_t index, mp_obj_t value) {
6161
}
6262
}
6363

64-
#ifdef CIRCUITPY
65-
void ndarray_set_value(char typecode, void *p, size_t index, mp_obj_t val_in) {
66-
switch (typecode) {
67-
case NDARRAY_INT8:
68-
((signed char *)p)[index] = mp_obj_get_int(val_in);
69-
break;
70-
case NDARRAY_UINT8:
71-
((unsigned char *)p)[index] = mp_obj_get_int(val_in);
72-
break;
73-
case NDARRAY_INT16:
74-
((short *)p)[index] = mp_obj_get_int(val_in);
75-
break;
76-
case NDARRAY_UINT16:
77-
((unsigned short *)p)[index] = mp_obj_get_int(val_in);
78-
break;
79-
case NDARRAY_FLOAT:
80-
((mp_float_t *)p)[index] = mp_obj_get_float(val_in);
81-
break;
82-
#if ULAB_SUPPORTS_COMPLEX
83-
case NDARRAY_COMPLEX:
84-
ndarray_set_complex_value(p, index, val_in);
85-
break;
86-
#endif
87-
}
88-
}
89-
#endif
90-
91-
#if defined(MICROPY_VERSION_MAJOR) && MICROPY_VERSION_MAJOR == 1 && MICROPY_VERSION_MINOR == 11
92-
93-
void mp_obj_slice_indices(mp_obj_t self_in, mp_int_t length, mp_bound_slice_t *result) {
94-
mp_obj_slice_t *self = MP_OBJ_TO_PTR(self_in);
95-
mp_int_t start, stop, step;
96-
97-
if (self->step == mp_const_none) {
98-
step = 1;
99-
} else {
100-
step = mp_obj_get_int(self->step);
101-
if (step == 0) {
102-
mp_raise_ValueError(translate("slice step can't be zero"));
103-
}
104-
}
105-
106-
if (step > 0) {
107-
// Positive step
108-
if (self->start == mp_const_none) {
109-
start = 0;
110-
} else {
111-
start = mp_obj_get_int(self->start);
112-
if (start < 0) {
113-
start += length;
114-
}
115-
start = MIN(length, MAX(start, 0));
116-
}
117-
118-
if (self->stop == mp_const_none) {
119-
stop = length;
120-
} else {
121-
stop = mp_obj_get_int(self->stop);
122-
if (stop < 0) {
123-
stop += length;
124-
}
125-
stop = MIN(length, MAX(stop, 0));
126-
}
127-
} else {
128-
// Negative step
129-
if (self->start == mp_const_none) {
130-
start = length - 1;
131-
} else {
132-
start = mp_obj_get_int(self->start);
133-
if (start < 0) {
134-
start += length;
135-
}
136-
start = MIN(length - 1, MAX(start, -1));
137-
}
138-
139-
if (self->stop == mp_const_none) {
140-
stop = -1;
141-
} else {
142-
stop = mp_obj_get_int(self->stop);
143-
if (stop < 0) {
144-
stop += length;
145-
}
146-
stop = MIN(length - 1, MAX(stop, -1));
147-
}
148-
}
149-
150-
result->start = start;
151-
result->stop = stop;
152-
result->step = step;
153-
}
154-
#endif /* MICROPY_VERSION v1.11 */
155-
15664
void ndarray_fill_array_iterable(mp_float_t *array, mp_obj_t iterable) {
15765
mp_obj_iter_buf_t x_buf;
15866
mp_obj_t x_item, x_iterable = mp_getiter(iterable, &x_buf);

code/ndarray.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ typedef struct _mp_obj_slice_t {
113113

114114
#if !CIRCUITPY
115115
#define translate(x) MP_ERROR_TEXT(x)
116-
#define ndarray_set_value(a, b, c, d) mp_binary_set_val_array(a, b, c, d)
117-
#else
118-
void ndarray_set_value(char , void *, size_t , mp_obj_t );
119116
#endif
120117

118+
#define ndarray_set_value(a, b, c, d) mp_binary_set_val_array(a, b, c, d)
121119
void ndarray_set_complex_value(void *, size_t , mp_obj_t );
122120

123121
#define NDARRAY_NUMERIC 0

code/ndarray_properties.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,6 @@
2424
#include "numpy/carray/carray.h"
2525
#endif
2626

27-
#ifndef CIRCUITPY
28-
29-
// a somewhat hackish implementation of property getters/setters;
30-
// this functions is hooked into the attr member of ndarray
31-
32-
STATIC void call_local_method(mp_obj_t obj, qstr attr, mp_obj_t *dest) {
33-
const mp_obj_type_t *type = mp_obj_get_type(obj);
34-
while (MP_OBJ_TYPE_HAS_SLOT(type, locals_dict)) {
35-
assert(MP_OBJ_TYPE_GET_SLOT(type, locals_dict)->base.type == &mp_type_dict); // MicroPython restriction, for now
36-
mp_map_t *locals_map = &MP_OBJ_TYPE_GET_SLOT(type, locals_dict)->map;
37-
mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP);
38-
if (elem != NULL) {
39-
mp_convert_member_lookup(obj, type, elem->value, dest);
40-
break;
41-
}
42-
if (!MP_OBJ_TYPE_HAS_SLOT(type, parent)) {
43-
break;
44-
}
45-
type = MP_OBJ_TYPE_GET_SLOT(type, parent);
46-
}
47-
}
48-
49-
5027
void ndarray_properties_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
5128
if (dest[0] == MP_OBJ_NULL) {
5229
switch(attr) {
@@ -98,7 +75,8 @@ void ndarray_properties_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
9875
#endif
9976
#endif /* ULAB_SUPPORTS_COMPLEX */
10077
default:
101-
call_local_method(self_in, attr, dest);
78+
// forward to locals dict
79+
dest[1] = MP_OBJ_SENTINEL;
10280
break;
10381
}
10482
} else {
@@ -119,5 +97,3 @@ void ndarray_properties_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
11997
}
12098
}
12199
}
122-
123-
#endif /* CIRCUITPY */

code/ndarray_properties.h

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -22,74 +22,6 @@
2222
#include "ndarray.h"
2323
#include "numpy/ndarray/ndarray_iter.h"
2424

25-
#if CIRCUITPY
26-
typedef struct _mp_obj_property_t {
27-
mp_obj_base_t base;
28-
mp_obj_t proxy[3]; // getter, setter, deleter
29-
} mp_obj_property_t;
30-
31-
#if NDARRAY_HAS_DTYPE
32-
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_dtype_obj, ndarray_dtype);
33-
STATIC const mp_obj_property_t ndarray_dtype_obj = {
34-
.base.type = &mp_type_property,
35-
.proxy = {(mp_obj_t)&ndarray_get_dtype_obj,
36-
mp_const_none,
37-
mp_const_none },
38-
};
39-
#endif /* NDARRAY_HAS_DTYPE */
40-
41-
#if NDARRAY_HAS_FLATITER
42-
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_flatiter_make_new_obj, ndarray_flatiter_make_new);
43-
STATIC const mp_obj_property_t ndarray_flat_obj = {
44-
.base.type = &mp_type_property,
45-
.proxy = {(mp_obj_t)&ndarray_flatiter_make_new_obj,
46-
mp_const_none,
47-
mp_const_none },
48-
};
49-
#endif /* NDARRAY_HAS_FLATITER */
50-
51-
#if NDARRAY_HAS_ITEMSIZE
52-
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_itemsize_obj, ndarray_itemsize);
53-
STATIC const mp_obj_property_t ndarray_itemsize_obj = {
54-
.base.type = &mp_type_property,
55-
.proxy = {(mp_obj_t)&ndarray_get_itemsize_obj,
56-
mp_const_none,
57-
mp_const_none },
58-
};
59-
#endif /* NDARRAY_HAS_ITEMSIZE */
60-
61-
#if NDARRAY_HAS_SHAPE
62-
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_shape_obj, ndarray_shape);
63-
STATIC const mp_obj_property_t ndarray_shape_obj = {
64-
.base.type = &mp_type_property,
65-
.proxy = {(mp_obj_t)&ndarray_get_shape_obj,
66-
mp_const_none,
67-
mp_const_none },
68-
};
69-
#endif /* NDARRAY_HAS_SHAPE */
70-
71-
#if NDARRAY_HAS_SIZE
72-
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_size_obj, ndarray_size);
73-
STATIC const mp_obj_property_t ndarray_size_obj = {
74-
.base.type = &mp_type_property,
75-
.proxy = {(mp_obj_t)&ndarray_get_size_obj,
76-
mp_const_none,
77-
mp_const_none },
78-
};
79-
#endif /* NDARRAY_HAS_SIZE */
80-
81-
#if NDARRAY_HAS_STRIDES
82-
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_strides_obj, ndarray_strides);
83-
STATIC const mp_obj_property_t ndarray_strides_obj = {
84-
.base.type = &mp_type_property,
85-
.proxy = {(mp_obj_t)&ndarray_get_strides_obj,
86-
mp_const_none,
87-
mp_const_none },
88-
};
89-
#endif /* NDARRAY_HAS_STRIDES */
90-
91-
#else
92-
9325
void ndarray_properties_attr(mp_obj_t , qstr , mp_obj_t *);
9426

9527
#if NDARRAY_HAS_DTYPE
@@ -116,6 +48,4 @@ MP_DEFINE_CONST_FUN_OBJ_1(ndarray_size_obj, ndarray_size);
11648
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_strides_obj, ndarray_strides);
11749
#endif
11850

119-
#endif /* CIRCUITPY */
120-
12151
#endif

code/numpy/fft/fft.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,5 @@ const mp_obj_module_t ulab_fft_module = {
101101
.globals = (mp_obj_dict_t*)&mp_module_ulab_fft_globals,
102102
};
103103
#if CIRCUITPY_ULAB
104-
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
105-
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy_dot_fft, ulab_fft_module, MODULE_ULAB_ENABLED);
106-
#else
107104
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy_dot_fft, ulab_fft_module);
108105
#endif
109-
#endif

code/numpy/linalg/linalg.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,6 @@ const mp_obj_module_t ulab_linalg_module = {
537537
.globals = (mp_obj_dict_t*)&mp_module_ulab_linalg_globals,
538538
};
539539
#if CIRCUITPY_ULAB
540-
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
541-
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy_dot_linalg, ulab_linalg_module, MODULE_ULAB_ENABLED);
542-
#else
543540
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy_dot_linalg, ulab_linalg_module);
544541
#endif
545542
#endif
546-
#endif

code/numpy/numpy.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,5 @@ const mp_obj_module_t ulab_numpy_module = {
397397
};
398398

399399
#if CIRCUITPY_ULAB
400-
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
401-
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy, ulab_numpy_module, MODULE_ULAB_ENABLED);
402-
#else
403400
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy, ulab_numpy_module);
404401
#endif
405-
#endif

code/scipy/linalg/linalg.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,6 @@ const mp_obj_module_t ulab_scipy_linalg_module = {
276276
.globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_linalg_globals,
277277
};
278278
#if CIRCUITPY_ULAB
279-
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
280-
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_linalg, ulab_scipy_linalg_module, MODULE_ULAB_ENABLED);
281-
#else
282279
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_linalg, ulab_scipy_linalg_module);
283280
#endif
284281
#endif
285-
#endif

code/scipy/optimize/optimize.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,5 @@ const mp_obj_module_t ulab_scipy_optimize_module = {
413413
.globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_optimize_globals,
414414
};
415415
#if CIRCUITPY_ULAB
416-
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
417-
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_optimize, ulab_scipy_optimize_module, MODULE_ULAB_ENABLED);
418-
#else
419416
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_optimize, ulab_scipy_optimize_module);
420417
#endif
421-
#endif

code/scipy/scipy.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ const mp_obj_module_t ulab_scipy_module = {
4949
.globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_globals,
5050
};
5151
#if CIRCUITPY_ULAB
52-
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
53-
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy, ulab_scipy_module, MODULE_ULAB_ENABLED);
54-
#else
5552
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy, ulab_scipy_module);
5653
#endif
57-
#endif
5854
#endif /* ULAB_HAS_SCIPY */

0 commit comments

Comments
 (0)