Merge pull request #647 from v923z/circuitpython9
Drop certain CircuitPython workarounds that are no longer needed
This commit is contained in:
commit
4bde4efa9d
30 changed files with 186 additions and 446 deletions
144
code/ndarray.c
144
code/ndarray.c
|
|
@ -61,98 +61,6 @@ void ndarray_set_complex_value(void *p, size_t index, mp_obj_t value) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef CIRCUITPY
|
||||
void ndarray_set_value(char typecode, void *p, size_t index, mp_obj_t val_in) {
|
||||
switch (typecode) {
|
||||
case NDARRAY_INT8:
|
||||
((signed char *)p)[index] = mp_obj_get_int(val_in);
|
||||
break;
|
||||
case NDARRAY_UINT8:
|
||||
((unsigned char *)p)[index] = mp_obj_get_int(val_in);
|
||||
break;
|
||||
case NDARRAY_INT16:
|
||||
((short *)p)[index] = mp_obj_get_int(val_in);
|
||||
break;
|
||||
case NDARRAY_UINT16:
|
||||
((unsigned short *)p)[index] = mp_obj_get_int(val_in);
|
||||
break;
|
||||
case NDARRAY_FLOAT:
|
||||
((mp_float_t *)p)[index] = mp_obj_get_float(val_in);
|
||||
break;
|
||||
#if ULAB_SUPPORTS_COMPLEX
|
||||
case NDARRAY_COMPLEX:
|
||||
ndarray_set_complex_value(p, index, val_in);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_VERSION_MAJOR) && MICROPY_VERSION_MAJOR == 1 && MICROPY_VERSION_MINOR == 11
|
||||
|
||||
void mp_obj_slice_indices(mp_obj_t self_in, mp_int_t length, mp_bound_slice_t *result) {
|
||||
mp_obj_slice_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_int_t start, stop, step;
|
||||
|
||||
if (self->step == mp_const_none) {
|
||||
step = 1;
|
||||
} else {
|
||||
step = mp_obj_get_int(self->step);
|
||||
if (step == 0) {
|
||||
mp_raise_ValueError(translate("slice step can't be zero"));
|
||||
}
|
||||
}
|
||||
|
||||
if (step > 0) {
|
||||
// Positive step
|
||||
if (self->start == mp_const_none) {
|
||||
start = 0;
|
||||
} else {
|
||||
start = mp_obj_get_int(self->start);
|
||||
if (start < 0) {
|
||||
start += length;
|
||||
}
|
||||
start = MIN(length, MAX(start, 0));
|
||||
}
|
||||
|
||||
if (self->stop == mp_const_none) {
|
||||
stop = length;
|
||||
} else {
|
||||
stop = mp_obj_get_int(self->stop);
|
||||
if (stop < 0) {
|
||||
stop += length;
|
||||
}
|
||||
stop = MIN(length, MAX(stop, 0));
|
||||
}
|
||||
} else {
|
||||
// Negative step
|
||||
if (self->start == mp_const_none) {
|
||||
start = length - 1;
|
||||
} else {
|
||||
start = mp_obj_get_int(self->start);
|
||||
if (start < 0) {
|
||||
start += length;
|
||||
}
|
||||
start = MIN(length - 1, MAX(start, -1));
|
||||
}
|
||||
|
||||
if (self->stop == mp_const_none) {
|
||||
stop = -1;
|
||||
} else {
|
||||
stop = mp_obj_get_int(self->stop);
|
||||
if (stop < 0) {
|
||||
stop += length;
|
||||
}
|
||||
stop = MIN(length - 1, MAX(stop, -1));
|
||||
}
|
||||
}
|
||||
|
||||
result->start = start;
|
||||
result->stop = stop;
|
||||
result->step = step;
|
||||
}
|
||||
#endif /* MICROPY_VERSION v1.11 */
|
||||
|
||||
void ndarray_fill_array_iterable(mp_float_t *array, mp_obj_t iterable) {
|
||||
mp_obj_iter_buf_t x_buf;
|
||||
mp_obj_t x_item, x_iterable = mp_getiter(iterable, &x_buf);
|
||||
|
|
@ -291,7 +199,7 @@ mp_obj_t ndarray_dtype_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
|||
if((_dtype != NDARRAY_BOOL) && (_dtype != NDARRAY_UINT8)
|
||||
&& (_dtype != NDARRAY_INT8) && (_dtype != NDARRAY_UINT16)
|
||||
&& (_dtype != NDARRAY_INT16) && (_dtype != NDARRAY_FLOAT)) {
|
||||
mp_raise_TypeError(translate("data type not understood"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("data type not understood"));
|
||||
}
|
||||
} else {
|
||||
GET_STR_DATA_LEN(_args[0].u_obj, _dtype_, len);
|
||||
|
|
@ -312,7 +220,7 @@ mp_obj_t ndarray_dtype_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
|||
}
|
||||
#endif
|
||||
else {
|
||||
mp_raise_TypeError(translate("data type not understood"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("data type not understood"));
|
||||
}
|
||||
}
|
||||
dtype->dtype = _dtype;
|
||||
|
|
@ -344,7 +252,7 @@ mp_obj_t ndarray_dtype(mp_obj_t self_in) {
|
|||
&& (*_dtype != NDARRAY_COMPLEX)
|
||||
#endif
|
||||
)) {
|
||||
mp_raise_TypeError(translate("data type not understood"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("data type not understood"));
|
||||
}
|
||||
dtype = *_dtype;
|
||||
}
|
||||
|
|
@ -596,7 +504,7 @@ bool ndarray_is_dense(ndarray_obj_t *ndarray) {
|
|||
static size_t multiply_size(size_t a, size_t b) {
|
||||
size_t result;
|
||||
if (__builtin_mul_overflow(a, b, &result)) {
|
||||
mp_raise_ValueError(translate("array is too big"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("array is too big"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -623,7 +531,7 @@ ndarray_obj_t *ndarray_new_ndarray(uint8_t ndim, size_t *shape, int32_t *strides
|
|||
}
|
||||
|
||||
if (SIZE_MAX / ndarray->itemsize <= ndarray->len) {
|
||||
mp_raise_ValueError(translate("ndarray length overflows"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("ndarray length overflows"));
|
||||
}
|
||||
|
||||
// if the length is 0, still allocate a single item, so that contractions can be handled
|
||||
|
|
@ -782,7 +690,7 @@ ndarray_obj_t *ndarray_copy_view_convert_type(ndarray_obj_t *source, uint8_t dty
|
|||
#if ULAB_SUPPORTS_COMPLEX
|
||||
if(source->dtype == NDARRAY_COMPLEX) {
|
||||
if(dtype != NDARRAY_COMPLEX) {
|
||||
mp_raise_TypeError(translate("cannot convert complex type"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("cannot convert complex type"));
|
||||
} else {
|
||||
memcpy(array, sarray, complex_size);
|
||||
}
|
||||
|
|
@ -948,7 +856,7 @@ ndarray_obj_t *ndarray_from_iterable(mp_obj_t obj, uint8_t dtype) {
|
|||
break;
|
||||
}
|
||||
if(ndim == ULAB_MAX_DIMS) {
|
||||
mp_raise_ValueError(translate("too many dimensions"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("too many dimensions"));
|
||||
}
|
||||
shape[ndim] = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(item));
|
||||
if(shape[ndim] == 0) {
|
||||
|
|
@ -1138,13 +1046,13 @@ static mp_bound_slice_t generate_slice(mp_int_t n, mp_obj_t index) {
|
|||
_index += n;
|
||||
}
|
||||
if((_index >= n) || (_index < 0)) {
|
||||
mp_raise_msg(&mp_type_IndexError, translate("index is out of bounds"));
|
||||
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("index is out of bounds"));
|
||||
}
|
||||
slice.start = _index;
|
||||
slice.stop = _index + 1;
|
||||
slice.step = 1;
|
||||
} else {
|
||||
mp_raise_msg(&mp_type_IndexError, translate("indices must be integers, slices, or Boolean lists"));
|
||||
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("indices must be integers, slices, or Boolean lists"));
|
||||
}
|
||||
return slice;
|
||||
}
|
||||
|
|
@ -1170,7 +1078,7 @@ static ndarray_obj_t *ndarray_view_from_slices(ndarray_obj_t *ndarray, mp_obj_tu
|
|||
k += ndarray->shape[ULAB_MAX_DIMS - ndarray->ndim + i];
|
||||
}
|
||||
if((k >= (int32_t)ndarray->shape[ULAB_MAX_DIMS - ndarray->ndim + i]) || (k < 0)) {
|
||||
mp_raise_msg(&mp_type_IndexError, translate("index is out of bounds"));
|
||||
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("index is out of bounds"));
|
||||
}
|
||||
offset += ndarray->strides[ULAB_MAX_DIMS - ndarray->ndim + i] * k;
|
||||
// ... and then we have to shift the shapes to the right
|
||||
|
|
@ -1197,7 +1105,7 @@ void ndarray_assign_view(ndarray_obj_t *view, ndarray_obj_t *values) {
|
|||
int32_t *lstrides = m_new0(int32_t, ULAB_MAX_DIMS);
|
||||
int32_t *rstrides = m_new0(int32_t, ULAB_MAX_DIMS);
|
||||
if(!ndarray_can_broadcast(view, values, &ndim, shape, lstrides, rstrides)) {
|
||||
mp_raise_ValueError(translate("operands could not be broadcast together"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("operands could not be broadcast together"));
|
||||
} else {
|
||||
|
||||
ndarray_obj_t *ndarray = ndarray_copy_view_convert_type(values, view->dtype);
|
||||
|
|
@ -1263,7 +1171,7 @@ void ndarray_assign_view(ndarray_obj_t *view, ndarray_obj_t *values) {
|
|||
static mp_obj_t ndarray_from_boolean_index(ndarray_obj_t *ndarray, ndarray_obj_t *index) {
|
||||
// returns a 1D array, indexed by a Boolean array
|
||||
if(ndarray->len != index->len) {
|
||||
mp_raise_ValueError(translate("array and index length must be equal"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("array and index length must be equal"));
|
||||
}
|
||||
uint8_t *iarray = (uint8_t *)index->array;
|
||||
// first we have to find out how many trues there are
|
||||
|
|
@ -1315,7 +1223,7 @@ static mp_obj_t ndarray_assign_from_boolean_index(ndarray_obj_t *ndarray, ndarra
|
|||
#if ULAB_SUPPORTS_COMPLEX
|
||||
if(values->dtype == NDARRAY_COMPLEX) {
|
||||
if(ndarray->dtype != NDARRAY_COMPLEX) {
|
||||
mp_raise_TypeError(translate("cannot convert complex to dtype"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("cannot convert complex to dtype"));
|
||||
} else {
|
||||
uint8_t *array = (uint8_t *)ndarray->array;
|
||||
for(size_t i = 0; i < ndarray->len; i++) {
|
||||
|
|
@ -1406,7 +1314,7 @@ static mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarra
|
|||
if(mp_obj_is_type(index, &ulab_ndarray_type)) {
|
||||
ndarray_obj_t *nindex = MP_OBJ_TO_PTR(index);
|
||||
if((nindex->ndim > 1) || (nindex->boolean == false)) {
|
||||
mp_raise_NotImplementedError(translate("operation is implemented for 1D Boolean arrays only"));
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("operation is implemented for 1D Boolean arrays only"));
|
||||
}
|
||||
if(values == NULL) { // return value(s)
|
||||
return ndarray_from_boolean_index(ndarray, nindex);
|
||||
|
|
@ -1419,7 +1327,7 @@ static mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarra
|
|||
if(mp_obj_is_type(index, &mp_type_tuple)) {
|
||||
tuple = MP_OBJ_TO_PTR(index);
|
||||
if(tuple->len > ndarray->ndim) {
|
||||
mp_raise_msg(&mp_type_IndexError, translate("too many indices"));
|
||||
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("too many indices"));
|
||||
}
|
||||
} else {
|
||||
mp_obj_t *items = m_new(mp_obj_t, 1);
|
||||
|
|
@ -1443,7 +1351,7 @@ static mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarra
|
|||
|
||||
mp_obj_t ndarray_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
||||
if(value == MP_OBJ_NULL) {
|
||||
mp_raise_ValueError(translate("cannot delete array elements"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("cannot delete array elements"));
|
||||
}
|
||||
ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
|
|
@ -1521,7 +1429,7 @@ mp_obj_t ndarray_flatten(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
|||
ndarray_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
GET_STR_DATA_LEN(args[0].u_obj, order, len);
|
||||
if((len != 1) || ((memcmp(order, "C", 1) != 0) && (memcmp(order, "F", 1) != 0))) {
|
||||
mp_raise_ValueError(translate("flattening order must be either 'C', or 'F'"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("flattening order must be either 'C', or 'F'"));
|
||||
}
|
||||
|
||||
uint8_t *sarray = (uint8_t *)self->array;
|
||||
|
|
@ -1659,7 +1567,7 @@ mp_obj_t ndarray_tobytes(mp_obj_t self_in) {
|
|||
// Piping into a bytearray makes sense for dense arrays only,
|
||||
// so bail out, if that is not the case
|
||||
if(!ndarray_is_dense(self)) {
|
||||
mp_raise_ValueError(translate("tobytes can be invoked for dense arrays only"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("tobytes can be invoked for dense arrays only"));
|
||||
}
|
||||
return mp_obj_new_bytearray_by_ref(self->itemsize * self->len, self->array);
|
||||
}
|
||||
|
|
@ -1799,7 +1707,7 @@ mp_obj_t ndarray_binary_op(mp_binary_op_t _op, mp_obj_t lobj, mp_obj_t robj) {
|
|||
broadcastable = ndarray_can_broadcast(lhs, rhs, &ndim, shape, lstrides, rstrides);
|
||||
}
|
||||
if(!broadcastable) {
|
||||
mp_raise_ValueError(translate("operands could not be broadcast together"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("operands could not be broadcast together"));
|
||||
m_del(size_t, shape, ULAB_MAX_DIMS);
|
||||
m_del(int32_t, lstrides, ULAB_MAX_DIMS);
|
||||
m_del(int32_t, rstrides, ULAB_MAX_DIMS);
|
||||
|
|
@ -2015,7 +1923,7 @@ mp_obj_t ndarray_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
|||
#else
|
||||
if(self->dtype == NDARRAY_FLOAT) {
|
||||
#endif
|
||||
mp_raise_ValueError(translate("operation is not supported for given type"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("operation is not supported for given type"));
|
||||
}
|
||||
// we can invert the content byte by byte, no need to distinguish between different dtypes
|
||||
ndarray = ndarray_copy_view(self); // from this point, this is a dense copy
|
||||
|
|
@ -2104,7 +2012,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(ndarray_transpose_obj, ndarray_transpose);
|
|||
mp_obj_t ndarray_reshape_core(mp_obj_t oin, mp_obj_t _shape, bool inplace) {
|
||||
ndarray_obj_t *source = MP_OBJ_TO_PTR(oin);
|
||||
if(!mp_obj_is_type(_shape, &mp_type_tuple) && !mp_obj_is_int(_shape)) {
|
||||
mp_raise_TypeError(translate("shape must be integer or tuple of integers"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("shape must be integer or tuple of integers"));
|
||||
}
|
||||
|
||||
mp_obj_tuple_t *shape;
|
||||
|
|
@ -2118,7 +2026,7 @@ mp_obj_t ndarray_reshape_core(mp_obj_t oin, mp_obj_t _shape, bool inplace) {
|
|||
}
|
||||
|
||||
if(shape->len > ULAB_MAX_DIMS) {
|
||||
mp_raise_ValueError(translate("maximum number of dimensions is " MP_STRINGIFY(ULAB_MAX_DIMS)));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("maximum number of dimensions is " MP_STRINGIFY(ULAB_MAX_DIMS)));
|
||||
}
|
||||
|
||||
size_t new_length = 1;
|
||||
|
|
@ -2138,14 +2046,14 @@ mp_obj_t ndarray_reshape_core(mp_obj_t oin, mp_obj_t _shape, bool inplace) {
|
|||
}
|
||||
|
||||
if(unknown_dim > 1) {
|
||||
mp_raise_ValueError(translate("can only specify one unknown dimension"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("can only specify one unknown dimension"));
|
||||
} else if(unknown_dim == 1) {
|
||||
new_shape[unknown_index] = source->len / new_length;
|
||||
new_length = source->len;
|
||||
}
|
||||
|
||||
if(source->len != new_length) {
|
||||
mp_raise_ValueError(translate("cannot reshape array"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("cannot reshape array"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *ndarray;
|
||||
|
|
@ -2162,7 +2070,7 @@ mp_obj_t ndarray_reshape_core(mp_obj_t oin, mp_obj_t _shape, bool inplace) {
|
|||
}
|
||||
} else {
|
||||
if(inplace) {
|
||||
mp_raise_ValueError(translate("cannot assign new shape"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("cannot assign new shape"));
|
||||
}
|
||||
if(mp_obj_is_type(_shape, &mp_type_tuple)) {
|
||||
ndarray = ndarray_new_ndarray_from_tuple(shape, source->dtype);
|
||||
|
|
@ -2185,7 +2093,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(ndarray_reshape_obj, ndarray_reshape);
|
|||
#if ULAB_NUMPY_HAS_NDINFO
|
||||
mp_obj_t ndarray_info(mp_obj_t obj_in) {
|
||||
if(!mp_obj_is_type(obj_in, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("function is defined for ndarrays only"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("function is defined for ndarrays only"));
|
||||
}
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(obj_in);
|
||||
mp_printf(MP_PYTHON_PRINTER, "class: ndarray\n");
|
||||
|
|
|
|||
|
|
@ -111,13 +111,7 @@ typedef struct _mp_obj_slice_t {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if !CIRCUITPY
|
||||
#define translate(x) MP_ERROR_TEXT(x)
|
||||
#define ndarray_set_value(a, b, c, d) mp_binary_set_val_array(a, b, c, d)
|
||||
#else
|
||||
void ndarray_set_value(char , void *, size_t , mp_obj_t );
|
||||
#endif
|
||||
|
||||
void ndarray_set_complex_value(void *, size_t , mp_obj_t );
|
||||
|
||||
#define NDARRAY_NUMERIC 0
|
||||
|
|
|
|||
|
|
@ -863,11 +863,11 @@ mp_obj_t ndarray_binary_logical(ndarray_obj_t *lhs, ndarray_obj_t *rhs,
|
|||
|
||||
#if ULAB_SUPPORTS_COMPLEX
|
||||
if((lhs->dtype == NDARRAY_COMPLEX) || (rhs->dtype == NDARRAY_COMPLEX) || (lhs->dtype == NDARRAY_FLOAT) || (rhs->dtype == NDARRAY_FLOAT)) {
|
||||
mp_raise_TypeError(translate("operation not supported for the input types"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("operation not supported for the input types"));
|
||||
}
|
||||
#else
|
||||
if((lhs->dtype == NDARRAY_FLOAT) || (rhs->dtype == NDARRAY_FLOAT)) {
|
||||
mp_raise_TypeError(translate("operation not supported for the input types"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("operation not supported for the input types"));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -875,7 +875,7 @@ mp_obj_t ndarray_binary_logical(ndarray_obj_t *lhs, ndarray_obj_t *rhs,
|
|||
// numpy promotes the result to int32
|
||||
if(((lhs->dtype == NDARRAY_INT16) && (rhs->dtype == NDARRAY_UINT16)) ||
|
||||
((lhs->dtype == NDARRAY_UINT16) && (rhs->dtype == NDARRAY_INT16))) {
|
||||
mp_raise_TypeError(translate("dtype of int32 is not supported"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("dtype of int32 is not supported"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *results = NULL;
|
||||
|
|
@ -1049,7 +1049,7 @@ mp_obj_t ndarray_binary_logical(ndarray_obj_t *lhs, ndarray_obj_t *rhs,
|
|||
mp_obj_t ndarray_inplace_ams(ndarray_obj_t *lhs, ndarray_obj_t *rhs, int32_t *rstrides, uint8_t optype) {
|
||||
|
||||
if((lhs->dtype != NDARRAY_FLOAT) && (rhs->dtype == NDARRAY_FLOAT)) {
|
||||
mp_raise_TypeError(translate("cannot cast output with casting rule"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("cannot cast output with casting rule"));
|
||||
}
|
||||
uint8_t *larray = (uint8_t *)lhs->array;
|
||||
uint8_t *rarray = (uint8_t *)rhs->array;
|
||||
|
|
@ -1078,7 +1078,7 @@ mp_obj_t ndarray_inplace_ams(ndarray_obj_t *lhs, ndarray_obj_t *rhs, int32_t *rs
|
|||
mp_obj_t ndarray_inplace_divide(ndarray_obj_t *lhs, ndarray_obj_t *rhs, int32_t *rstrides) {
|
||||
|
||||
if((lhs->dtype != NDARRAY_FLOAT)) {
|
||||
mp_raise_TypeError(translate("results cannot be cast to specified type"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("results cannot be cast to specified type"));
|
||||
}
|
||||
uint8_t *larray = (uint8_t *)lhs->array;
|
||||
uint8_t *rarray = (uint8_t *)rhs->array;
|
||||
|
|
@ -1102,7 +1102,7 @@ mp_obj_t ndarray_inplace_divide(ndarray_obj_t *lhs, ndarray_obj_t *rhs, int32_t
|
|||
mp_obj_t ndarray_inplace_power(ndarray_obj_t *lhs, ndarray_obj_t *rhs, int32_t *rstrides) {
|
||||
|
||||
if((lhs->dtype != NDARRAY_FLOAT)) {
|
||||
mp_raise_TypeError(translate("results cannot be cast to specified type"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("results cannot be cast to specified type"));
|
||||
}
|
||||
uint8_t *larray = (uint8_t *)lhs->array;
|
||||
uint8_t *rarray = (uint8_t *)rhs->array;
|
||||
|
|
|
|||
|
|
@ -24,29 +24,6 @@
|
|||
#include "numpy/carray/carray.h"
|
||||
#endif
|
||||
|
||||
#ifndef CIRCUITPY
|
||||
|
||||
// a somewhat hackish implementation of property getters/setters;
|
||||
// this functions is hooked into the attr member of ndarray
|
||||
|
||||
STATIC void call_local_method(mp_obj_t obj, qstr attr, mp_obj_t *dest) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(obj);
|
||||
while (MP_OBJ_TYPE_HAS_SLOT(type, locals_dict)) {
|
||||
assert(MP_OBJ_TYPE_GET_SLOT(type, locals_dict)->base.type == &mp_type_dict); // MicroPython restriction, for now
|
||||
mp_map_t *locals_map = &MP_OBJ_TYPE_GET_SLOT(type, locals_dict)->map;
|
||||
mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP);
|
||||
if (elem != NULL) {
|
||||
mp_convert_member_lookup(obj, type, elem->value, dest);
|
||||
break;
|
||||
}
|
||||
if (!MP_OBJ_TYPE_HAS_SLOT(type, parent)) {
|
||||
break;
|
||||
}
|
||||
type = MP_OBJ_TYPE_GET_SLOT(type, parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ndarray_properties_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
if (dest[0] == MP_OBJ_NULL) {
|
||||
switch(attr) {
|
||||
|
|
@ -98,7 +75,8 @@ void ndarray_properties_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
|||
#endif
|
||||
#endif /* ULAB_SUPPORTS_COMPLEX */
|
||||
default:
|
||||
call_local_method(self_in, attr, dest);
|
||||
// forward to locals dict
|
||||
dest[1] = MP_OBJ_SENTINEL;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -119,5 +97,3 @@ void ndarray_properties_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CIRCUITPY */
|
||||
|
|
|
|||
|
|
@ -22,74 +22,6 @@
|
|||
#include "ndarray.h"
|
||||
#include "numpy/ndarray/ndarray_iter.h"
|
||||
|
||||
#if CIRCUITPY
|
||||
typedef struct _mp_obj_property_t {
|
||||
mp_obj_base_t base;
|
||||
mp_obj_t proxy[3]; // getter, setter, deleter
|
||||
} mp_obj_property_t;
|
||||
|
||||
#if NDARRAY_HAS_DTYPE
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_dtype_obj, ndarray_dtype);
|
||||
STATIC const mp_obj_property_t ndarray_dtype_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&ndarray_get_dtype_obj,
|
||||
mp_const_none,
|
||||
mp_const_none },
|
||||
};
|
||||
#endif /* NDARRAY_HAS_DTYPE */
|
||||
|
||||
#if NDARRAY_HAS_FLATITER
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_flatiter_make_new_obj, ndarray_flatiter_make_new);
|
||||
STATIC const mp_obj_property_t ndarray_flat_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&ndarray_flatiter_make_new_obj,
|
||||
mp_const_none,
|
||||
mp_const_none },
|
||||
};
|
||||
#endif /* NDARRAY_HAS_FLATITER */
|
||||
|
||||
#if NDARRAY_HAS_ITEMSIZE
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_itemsize_obj, ndarray_itemsize);
|
||||
STATIC const mp_obj_property_t ndarray_itemsize_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&ndarray_get_itemsize_obj,
|
||||
mp_const_none,
|
||||
mp_const_none },
|
||||
};
|
||||
#endif /* NDARRAY_HAS_ITEMSIZE */
|
||||
|
||||
#if NDARRAY_HAS_SHAPE
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_shape_obj, ndarray_shape);
|
||||
STATIC const mp_obj_property_t ndarray_shape_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&ndarray_get_shape_obj,
|
||||
mp_const_none,
|
||||
mp_const_none },
|
||||
};
|
||||
#endif /* NDARRAY_HAS_SHAPE */
|
||||
|
||||
#if NDARRAY_HAS_SIZE
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_size_obj, ndarray_size);
|
||||
STATIC const mp_obj_property_t ndarray_size_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&ndarray_get_size_obj,
|
||||
mp_const_none,
|
||||
mp_const_none },
|
||||
};
|
||||
#endif /* NDARRAY_HAS_SIZE */
|
||||
|
||||
#if NDARRAY_HAS_STRIDES
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_get_strides_obj, ndarray_strides);
|
||||
STATIC const mp_obj_property_t ndarray_strides_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&ndarray_get_strides_obj,
|
||||
mp_const_none,
|
||||
mp_const_none },
|
||||
};
|
||||
#endif /* NDARRAY_HAS_STRIDES */
|
||||
|
||||
#else
|
||||
|
||||
void ndarray_properties_attr(mp_obj_t , qstr , mp_obj_t *);
|
||||
|
||||
#if NDARRAY_HAS_DTYPE
|
||||
|
|
@ -116,6 +48,4 @@ MP_DEFINE_CONST_FUN_OBJ_1(ndarray_size_obj, ndarray_size);
|
|||
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_strides_obj, ndarray_strides);
|
||||
#endif
|
||||
|
||||
#endif /* CIRCUITPY */
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ STATIC mp_obj_t approx_interp(size_t n_args, const mp_obj_t *pos_args, mp_map_t
|
|||
COMPLEX_DTYPE_NOT_IMPLEMENTED(xp->dtype)
|
||||
COMPLEX_DTYPE_NOT_IMPLEMENTED(fp->dtype)
|
||||
if((xp->ndim != 1) || (fp->ndim != 1) || (xp->len < 2) || (fp->len < 2) || (xp->len != fp->len)) {
|
||||
mp_raise_ValueError(translate("interp is defined for 1D iterables of equal length"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("interp is defined for 1D iterables of equal length"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *y = ndarray_new_linear_array(x->len, NDARRAY_FLOAT);
|
||||
|
|
@ -168,7 +168,7 @@ STATIC mp_obj_t approx_trapz(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
|||
return mp_obj_new_float(mean);
|
||||
}
|
||||
if((y->ndim != 1)) {
|
||||
mp_raise_ValueError(translate("trapz is defined for 1D iterables"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("trapz is defined for 1D iterables"));
|
||||
}
|
||||
|
||||
mp_float_t (*funcy)(void *) = ndarray_get_float_function(y->dtype);
|
||||
|
|
@ -181,7 +181,7 @@ STATIC mp_obj_t approx_trapz(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
|||
x = ndarray_from_mp_obj(args[1].u_obj, 0); // x must hold an increasing sequence of independent values
|
||||
COMPLEX_DTYPE_NOT_IMPLEMENTED(x->dtype)
|
||||
if((x->ndim != 1) || (y->len != x->len)) {
|
||||
mp_raise_ValueError(translate("trapz is defined for 1D arrays of equal length"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("trapz is defined for 1D arrays of equal length"));
|
||||
}
|
||||
|
||||
mp_float_t (*funcx)(void *) = ndarray_get_float_function(x->dtype);
|
||||
|
|
|
|||
|
|
@ -331,11 +331,11 @@ mp_obj_t *bitwise_binary_operators(mp_obj_t x1, mp_obj_t x2, uint8_t optype) {
|
|||
|
||||
#if ULAB_SUPPORTS_COMPLEX
|
||||
if((lhs->dtype == NDARRAY_FLOAT) || (rhs->dtype == NDARRAY_FLOAT) || (lhs->dtype == NDARRAY_COMPLEX) || (rhs->dtype == NDARRAY_COMPLEX)) {
|
||||
mp_raise_ValueError(translate("not supported for input types"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("not supported for input types"));
|
||||
}
|
||||
#else
|
||||
if((lhs->dtype == NDARRAY_FLOAT) || (rhs->dtype == NDARRAY_FLOAT)) {
|
||||
mp_raise_ValueError(translate("not supported for input types"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("not supported for input types"));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -348,7 +348,7 @@ mp_obj_t *bitwise_binary_operators(mp_obj_t x1, mp_obj_t x2, uint8_t optype) {
|
|||
m_del(size_t, shape, ULAB_MAX_DIMS);
|
||||
m_del(int32_t, lstrides, ULAB_MAX_DIMS);
|
||||
m_del(int32_t, rstrides, ULAB_MAX_DIMS);
|
||||
mp_raise_ValueError(translate("operands could not be broadcast together"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("operands could not be broadcast together"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *results = NULL;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ mp_obj_t carray_real(mp_obj_t _source) {
|
|||
return MP_OBJ_FROM_PTR(target);
|
||||
}
|
||||
} else {
|
||||
mp_raise_NotImplementedError(translate("function is implemented for ndarrays only"));
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("function is implemented for ndarrays only"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ mp_obj_t carray_imag(mp_obj_t _source) {
|
|||
return MP_OBJ_FROM_PTR(target);
|
||||
}
|
||||
} else {
|
||||
mp_raise_NotImplementedError(translate("function is implemented for ndarrays only"));
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("function is implemented for ndarrays only"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ mp_obj_t carray_conjugate(mp_obj_t _source) {
|
|||
} else if(mp_obj_is_int(_source) || mp_obj_is_float(_source)) {
|
||||
return _source;
|
||||
} else {
|
||||
mp_raise_TypeError(translate("input must be an ndarray, or a scalar"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("input must be an ndarray, or a scalar"));
|
||||
}
|
||||
}
|
||||
// this should never happen
|
||||
|
|
@ -183,11 +183,11 @@ static void carray_sort_complex_(mp_float_t *array, size_t len) {
|
|||
|
||||
mp_obj_t carray_sort_complex(mp_obj_t _source) {
|
||||
if(!mp_obj_is_type(_source, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("input must be a 1D ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("input must be a 1D ndarray"));
|
||||
}
|
||||
ndarray_obj_t *source = MP_OBJ_TO_PTR(_source);
|
||||
if(source->ndim != 1) {
|
||||
mp_raise_TypeError(translate("input must be a 1D ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("input must be a 1D ndarray"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *ndarray = ndarray_copy_view_convert_type(source, NDARRAY_COMPLEX);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
#if ULAB_SUPPORTS_COMPLEX
|
||||
|
||||
void raise_complex_NotImplementedError(void) {
|
||||
mp_raise_NotImplementedError(translate("not implemented for complex dtype"));
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("not implemented for complex dtype"));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ static mp_obj_t compare_function(mp_obj_t x1, mp_obj_t x2, uint8_t op) {
|
|||
int32_t *lstrides = m_new(int32_t, ULAB_MAX_DIMS);
|
||||
int32_t *rstrides = m_new(int32_t, ULAB_MAX_DIMS);
|
||||
if(!ndarray_can_broadcast(lhs, rhs, &ndim, shape, lstrides, rstrides)) {
|
||||
mp_raise_ValueError(translate("operands could not be broadcast together"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("operands could not be broadcast together"));
|
||||
m_del(size_t, shape, ULAB_MAX_DIMS);
|
||||
m_del(int32_t, lstrides, ULAB_MAX_DIMS);
|
||||
m_del(int32_t, rstrides, ULAB_MAX_DIMS);
|
||||
|
|
@ -263,7 +263,7 @@ static mp_obj_t compare_isinf_isfinite(mp_obj_t _x, uint8_t mask) {
|
|||
|
||||
return MP_OBJ_FROM_PTR(results);
|
||||
} else {
|
||||
mp_raise_TypeError(translate("wrong input type"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("wrong input type"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
|
@ -470,7 +470,7 @@ mp_obj_t compare_where(mp_obj_t _condition, mp_obj_t _x, mp_obj_t _y) {
|
|||
if(!ndarray_can_broadcast(c, x, &ndim, oshape, cstrides, ystrides) ||
|
||||
!ndarray_can_broadcast(c, y, &ndim, oshape, cstrides, ystrides) ||
|
||||
!ndarray_can_broadcast(x, y, &ndim, oshape, xstrides, ystrides)) {
|
||||
mp_raise_ValueError(translate("operands could not be broadcast together"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("operands could not be broadcast together"));
|
||||
}
|
||||
|
||||
ndim = MAX(MAX(c->ndim, x->ndim), y->ndim);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#if ULAB_NUMPY_HAS_ONES | ULAB_NUMPY_HAS_ZEROS | ULAB_NUMPY_HAS_FULL | ULAB_NUMPY_HAS_EMPTY
|
||||
static mp_obj_t create_zeros_ones_full(mp_obj_t oshape, uint8_t dtype, mp_obj_t value) {
|
||||
if(!mp_obj_is_int(oshape) && !mp_obj_is_type(oshape, &mp_type_tuple) && !mp_obj_is_type(oshape, &mp_type_list)) {
|
||||
mp_raise_TypeError(translate("input argument must be an integer, a tuple, or a list"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("input argument must be an integer, a tuple, or a list"));
|
||||
}
|
||||
ndarray_obj_t *ndarray = NULL;
|
||||
if(mp_obj_is_int(oshape)) {
|
||||
|
|
@ -33,7 +33,7 @@ static mp_obj_t create_zeros_ones_full(mp_obj_t oshape, uint8_t dtype, mp_obj_t
|
|||
} else if(mp_obj_is_type(oshape, &mp_type_tuple) || mp_obj_is_type(oshape, &mp_type_list)) {
|
||||
uint8_t len = (uint8_t)mp_obj_get_int(mp_obj_len_maybe(oshape));
|
||||
if(len > ULAB_MAX_DIMS) {
|
||||
mp_raise_TypeError(translate("too many dimensions"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("too many dimensions"));
|
||||
}
|
||||
size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ mp_obj_t create_arange(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
|
|||
step = mp_obj_get_float(args[2].u_obj);
|
||||
if(mp_obj_is_int(args[0].u_obj) && mp_obj_is_int(args[1].u_obj) && mp_obj_is_int(args[2].u_obj)) dtype = NDARRAY_INT16;
|
||||
} else {
|
||||
mp_raise_TypeError(translate("wrong number of arguments"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("wrong number of arguments"));
|
||||
}
|
||||
if((MICROPY_FLOAT_C_FUN(fabs)(stop) > 32768) || (MICROPY_FLOAT_C_FUN(fabs)(start) > 32768) || (MICROPY_FLOAT_C_FUN(fabs)(step) > 32768)) {
|
||||
dtype = NDARRAY_FLOAT;
|
||||
|
|
@ -159,7 +159,7 @@ mp_obj_t create_arange(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
|
|||
}
|
||||
|
||||
if(!isfinite(start) || !isfinite(stop) || !isfinite(step)) {
|
||||
mp_raise_ValueError(translate("arange: cannot compute length"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("arange: cannot compute length"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *ndarray;
|
||||
|
|
@ -222,7 +222,7 @@ mp_obj_t create_asarray(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
}
|
||||
return MP_OBJ_FROM_PTR(ndarray_from_iterable(args[0].u_obj, _dtype));
|
||||
} else {
|
||||
mp_raise_TypeError(translate("wrong input type"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("wrong input type"));
|
||||
}
|
||||
return mp_const_none; // this should never happen
|
||||
}
|
||||
|
|
@ -252,7 +252,7 @@ mp_obj_t create_concatenate(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &mp_type_tuple)) {
|
||||
mp_raise_TypeError(translate("first argument must be a tuple of ndarrays"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("first argument must be a tuple of ndarrays"));
|
||||
}
|
||||
int8_t axis = (int8_t)args[1].u_int;
|
||||
size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
|
||||
|
|
@ -260,7 +260,7 @@ mp_obj_t create_concatenate(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
|||
|
||||
for(uint8_t i = 0; i < ndarrays->len; i++) {
|
||||
if(!mp_obj_is_type(ndarrays->items[i], &ulab_ndarray_type)) {
|
||||
mp_raise_ValueError(translate("only ndarrays can be concatenated"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("only ndarrays can be concatenated"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -272,7 +272,7 @@ mp_obj_t create_concatenate(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
|||
axis += ndim;
|
||||
}
|
||||
if((axis < 0) || (axis >= ndim)) {
|
||||
mp_raise_ValueError(translate("wrong axis specified"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("wrong axis specified"));
|
||||
}
|
||||
// shift axis
|
||||
axis = ULAB_MAX_DIMS - ndim + axis;
|
||||
|
|
@ -284,14 +284,14 @@ mp_obj_t create_concatenate(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
|||
_ndarray = MP_OBJ_TO_PTR(ndarrays->items[i]);
|
||||
// check, whether the arrays are compatible
|
||||
if((dtype != _ndarray->dtype) || (ndim != _ndarray->ndim)) {
|
||||
mp_raise_ValueError(translate("input arrays are not compatible"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input arrays are not compatible"));
|
||||
}
|
||||
for(uint8_t j=0; j < ULAB_MAX_DIMS; j++) {
|
||||
if(j == axis) {
|
||||
shape[j] += _ndarray->shape[j];
|
||||
} else {
|
||||
if(shape[j] != _ndarray->shape[j]) {
|
||||
mp_raise_ValueError(translate("input arrays are not compatible"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input arrays are not compatible"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -431,7 +431,7 @@ mp_obj_t create_diag(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
|
|||
}
|
||||
#if ULAB_MAX_DIMS > 2
|
||||
else {
|
||||
mp_raise_ValueError(translate("input must be 1- or 2-d"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input must be 1- or 2-d"));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -585,7 +585,7 @@ mp_obj_t create_linspace(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(args[2].u_int < 2) {
|
||||
mp_raise_ValueError(translate("number of points must be at least 2"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("number of points must be at least 2"));
|
||||
}
|
||||
size_t len = (size_t)args[2].u_int;
|
||||
mp_float_t start, step, stop;
|
||||
|
|
@ -708,7 +708,7 @@ mp_obj_t create_logspace(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(args[2].u_int < 2) {
|
||||
mp_raise_ValueError(translate("number of points must be at least 2"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("number of points must be at least 2"));
|
||||
}
|
||||
size_t len = (size_t)args[2].u_int;
|
||||
mp_float_t start, step, quotient;
|
||||
|
|
@ -824,16 +824,16 @@ mp_obj_t create_frombuffer(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
|
|||
size_t sz = ulab_binary_get_size(dtype);
|
||||
|
||||
if(bufinfo.len < offset) {
|
||||
mp_raise_ValueError(translate("offset must be non-negative and no greater than buffer length"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("offset must be non-negative and no greater than buffer length"));
|
||||
}
|
||||
size_t len = (bufinfo.len - offset) / sz;
|
||||
if((len * sz) != (bufinfo.len - offset)) {
|
||||
mp_raise_ValueError(translate("buffer size must be a multiple of element size"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("buffer size must be a multiple of element size"));
|
||||
}
|
||||
if(mp_obj_get_int(args[2].u_obj) > 0) {
|
||||
size_t count = mp_obj_get_int(args[2].u_obj);
|
||||
if(len < count) {
|
||||
mp_raise_ValueError(translate("buffer is smaller than requested size"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("buffer is smaller than requested size"));
|
||||
} else {
|
||||
len = count;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,9 +101,5 @@ const mp_obj_module_t ulab_fft_module = {
|
|||
.globals = (mp_obj_dict_t*)&mp_module_ulab_fft_globals,
|
||||
};
|
||||
#if CIRCUITPY_ULAB
|
||||
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy_dot_fft, ulab_fft_module, MODULE_ULAB_ENABLED);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy_dot_fft, ulab_fft_module);
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -98,18 +98,18 @@ void fft_kernel_complex(mp_float_t *data, size_t n, int isign) {
|
|||
*/
|
||||
mp_obj_t fft_fft_ifft_spectrogram(mp_obj_t data_in, uint8_t type) {
|
||||
if(!mp_obj_is_type(data_in, &ulab_ndarray_type)) {
|
||||
mp_raise_NotImplementedError(translate("FFT is defined for ndarrays only"));
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("FFT is defined for ndarrays only"));
|
||||
}
|
||||
ndarray_obj_t *in = MP_OBJ_TO_PTR(data_in);
|
||||
#if ULAB_MAX_DIMS > 1
|
||||
if(in->ndim != 1) {
|
||||
mp_raise_TypeError(translate("FFT is implemented for linear arrays only"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("FFT is implemented for linear arrays only"));
|
||||
}
|
||||
#endif
|
||||
size_t len = in->len;
|
||||
// Check if input is of length of power of 2
|
||||
if((len & (len-1)) != 0) {
|
||||
mp_raise_ValueError(translate("input array length must be power of 2"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input array length must be power of 2"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *out = ndarray_new_linear_array(len, NDARRAY_COMPLEX);
|
||||
|
|
@ -204,24 +204,24 @@ void fft_kernel(mp_float_t *real, mp_float_t *imag, size_t n, int isign) {
|
|||
|
||||
mp_obj_t fft_fft_ifft_spectrogram(size_t n_args, mp_obj_t arg_re, mp_obj_t arg_im, uint8_t type) {
|
||||
if(!mp_obj_is_type(arg_re, &ulab_ndarray_type)) {
|
||||
mp_raise_NotImplementedError(translate("FFT is defined for ndarrays only"));
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("FFT is defined for ndarrays only"));
|
||||
}
|
||||
if(n_args == 2) {
|
||||
if(!mp_obj_is_type(arg_im, &ulab_ndarray_type)) {
|
||||
mp_raise_NotImplementedError(translate("FFT is defined for ndarrays only"));
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("FFT is defined for ndarrays only"));
|
||||
}
|
||||
}
|
||||
ndarray_obj_t *re = MP_OBJ_TO_PTR(arg_re);
|
||||
#if ULAB_MAX_DIMS > 1
|
||||
if(re->ndim != 1) {
|
||||
COMPLEX_DTYPE_NOT_IMPLEMENTED(re->dtype)
|
||||
mp_raise_TypeError(translate("FFT is implemented for linear arrays only"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("FFT is implemented for linear arrays only"));
|
||||
}
|
||||
#endif
|
||||
size_t len = re->len;
|
||||
// Check if input is of length of power of 2
|
||||
if((len & (len-1)) != 0) {
|
||||
mp_raise_ValueError(translate("input array length must be power of 2"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input array length must be power of 2"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *out_re = ndarray_new_linear_array(len, NDARRAY_FLOAT);
|
||||
|
|
@ -243,11 +243,11 @@ mp_obj_t fft_fft_ifft_spectrogram(size_t n_args, mp_obj_t arg_re, mp_obj_t arg_i
|
|||
#if ULAB_MAX_DIMS > 1
|
||||
if(im->ndim != 1) {
|
||||
COMPLEX_DTYPE_NOT_IMPLEMENTED(im->dtype)
|
||||
mp_raise_TypeError(translate("FFT is implemented for linear arrays only"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("FFT is implemented for linear arrays only"));
|
||||
}
|
||||
#endif
|
||||
if (re->len != im->len) {
|
||||
mp_raise_ValueError(translate("real and imaginary parts must be of equal length"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("real and imaginary parts must be of equal length"));
|
||||
}
|
||||
array = (uint8_t *)im->array;
|
||||
func = ndarray_get_float_function(im->dtype);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ mp_obj_t filter_convolve(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type) || !mp_obj_is_type(args[1].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("convolve arguments must be ndarrays"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("convolve arguments must be ndarrays"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *a = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
|
|
@ -44,13 +44,13 @@ mp_obj_t filter_convolve(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
|||
// deal with linear arrays only
|
||||
#if ULAB_MAX_DIMS > 1
|
||||
if((a->ndim != 1) || (c->ndim != 1)) {
|
||||
mp_raise_TypeError(translate("convolve arguments must be linear arrays"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("convolve arguments must be linear arrays"));
|
||||
}
|
||||
#endif
|
||||
size_t len_a = a->len;
|
||||
size_t len_c = c->len;
|
||||
if(len_a == 0 || len_c == 0) {
|
||||
mp_raise_TypeError(translate("convolve arguments must not be empty"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("convolve arguments must not be empty"));
|
||||
}
|
||||
|
||||
int len = len_a + len_c - 1; // convolve mode "full"
|
||||
|
|
|
|||
|
|
@ -46,13 +46,13 @@ static void io_read_(mp_obj_t stream, const mp_stream_p_t *stream_p, char *buffe
|
|||
}
|
||||
if(fail) {
|
||||
stream_p->ioctl(stream, MP_STREAM_CLOSE, 0, error);
|
||||
mp_raise_msg(&mp_type_RuntimeError, translate("corrupted file"));
|
||||
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("corrupted file"));
|
||||
}
|
||||
}
|
||||
|
||||
static mp_obj_t io_load(mp_obj_t file) {
|
||||
if(!mp_obj_is_str(file)) {
|
||||
mp_raise_TypeError(translate("wrong input type"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("wrong input type"));
|
||||
}
|
||||
|
||||
int error;
|
||||
|
|
@ -126,7 +126,7 @@ static mp_obj_t io_load(mp_obj_t file) {
|
|||
#endif /* ULAB_SUPPORT_COPMLEX */
|
||||
else {
|
||||
stream_p->ioctl(stream, MP_STREAM_CLOSE, 0, &error);
|
||||
mp_raise_TypeError(translate("wrong dtype"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("wrong dtype"));
|
||||
}
|
||||
|
||||
io_read_(stream, stream_p, buffer, "', 'fortran_order': False, 'shape': (", 37, &error);
|
||||
|
|
@ -169,7 +169,7 @@ static mp_obj_t io_load(mp_obj_t file) {
|
|||
}
|
||||
else {
|
||||
stream_p->ioctl(stream, MP_STREAM_CLOSE, 0, &error);
|
||||
mp_raise_msg(&mp_type_RuntimeError, translate("corrupted file"));
|
||||
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("corrupted file"));
|
||||
}
|
||||
needle++;
|
||||
}
|
||||
|
|
@ -188,7 +188,7 @@ static mp_obj_t io_load(mp_obj_t file) {
|
|||
size_t read = stream_p->read(stream, array, ndarray->len * ndarray->itemsize, &error);
|
||||
if(read != ndarray->len * ndarray->itemsize) {
|
||||
stream_p->ioctl(stream, MP_STREAM_CLOSE, 0, &error);
|
||||
mp_raise_msg(&mp_type_RuntimeError, translate("corrupted file"));
|
||||
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("corrupted file"));
|
||||
}
|
||||
|
||||
stream_p->ioctl(stream, MP_STREAM_CLOSE, 0, &error);
|
||||
|
|
@ -303,7 +303,7 @@ static mp_obj_t io_loadtxt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
|
|||
cols[0] = (uint16_t)mp_obj_get_int(args[4].u_obj);
|
||||
} else {
|
||||
#if ULAB_MAX_DIMS == 1
|
||||
mp_raise_ValueError(translate("usecols keyword must be specified"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("usecols keyword must be specified"));
|
||||
#else
|
||||
// assume that the argument is an iterable
|
||||
used_columns = (uint16_t)mp_obj_get_int(mp_obj_len(args[4].u_obj));
|
||||
|
|
@ -379,12 +379,12 @@ static mp_obj_t io_loadtxt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
|
|||
} while((read > 0) && (all_rows < max_rows));
|
||||
|
||||
if(rows == 0) {
|
||||
mp_raise_ValueError(translate("empty file"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("empty file"));
|
||||
}
|
||||
uint16_t columns = items / rows;
|
||||
|
||||
if(columns < used_columns) {
|
||||
mp_raise_ValueError(translate("usecols is too high"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("usecols is too high"));
|
||||
}
|
||||
|
||||
size_t *shape = m_new0(size_t, ULAB_MAX_DIMS);
|
||||
|
|
@ -526,7 +526,7 @@ static uint8_t io_sprintf(char *buffer, const char *comma, size_t x) {
|
|||
|
||||
static mp_obj_t io_save(mp_obj_t file, mp_obj_t ndarray_) {
|
||||
if(!mp_obj_is_str(file) || !mp_obj_is_type(ndarray_, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("wrong input type"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("wrong input type"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(ndarray_);
|
||||
|
|
@ -725,14 +725,14 @@ static mp_obj_t io_savetxt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_str(args[0].u_obj) || !mp_obj_is_type(args[1].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("wrong input type"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("wrong input type"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[1].u_obj);
|
||||
|
||||
#if ULAB_MAX_DIMS > 2
|
||||
if(ndarray->ndim > 2) {
|
||||
mp_raise_ValueError(translate("array has too many dimensions"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("array has too many dimensions"));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ static mp_obj_t linalg_cholesky(mp_obj_t oin) {
|
|||
for(size_t n=m+1; n < N; n++) { // columns
|
||||
// compare entry (m, n) to (n, m)
|
||||
if(LINALG_EPSILON < MICROPY_FLOAT_C_FUN(fabs)(Larray[m * N + n] - Larray[n * N + m])) {
|
||||
mp_raise_ValueError(translate("input matrix is asymmetric"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input matrix is asymmetric"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ static mp_obj_t linalg_cholesky(mp_obj_t oin) {
|
|||
}
|
||||
if(i == j) {
|
||||
if(sum <= MICROPY_FLOAT_CONST(0.0)) {
|
||||
mp_raise_ValueError(translate("matrix is not positive definite"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("matrix is not positive definite"));
|
||||
} else {
|
||||
Larray[i * N + i] = MICROPY_FLOAT_C_FUN(sqrt)(sum);
|
||||
}
|
||||
|
|
@ -204,7 +204,7 @@ static mp_obj_t linalg_eig(mp_obj_t oin) {
|
|||
// compare entry (m, n) to (n, m)
|
||||
// TODO: this must probably be scaled!
|
||||
if(LINALG_EPSILON < MICROPY_FLOAT_C_FUN(fabs)(array[m * S + n] - array[n * S + m])) {
|
||||
mp_raise_ValueError(translate("input matrix is asymmetric"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input matrix is asymmetric"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -219,7 +219,7 @@ static mp_obj_t linalg_eig(mp_obj_t oin) {
|
|||
if(iterations == 0) {
|
||||
// the computation did not converge; numpy raises LinAlgError
|
||||
m_del(mp_float_t, array, in->len);
|
||||
mp_raise_ValueError(translate("iterations did not converge"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("iterations did not converge"));
|
||||
}
|
||||
ndarray_obj_t *eigenvalues = ndarray_new_linear_array(S, NDARRAY_FLOAT);
|
||||
mp_float_t *eigvalues = (mp_float_t *)eigenvalues->array;
|
||||
|
|
@ -267,7 +267,7 @@ static mp_obj_t linalg_inv(mp_obj_t o_in) {
|
|||
iarray -= N*N;
|
||||
|
||||
if(!linalg_invert_matrix(iarray, N)) {
|
||||
mp_raise_ValueError(translate("input matrix is singular"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input matrix is singular"));
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(inverted);
|
||||
}
|
||||
|
|
@ -393,11 +393,11 @@ static mp_obj_t linalg_qr(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_
|
|||
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("operation is defined for ndarrays only"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("operation is defined for ndarrays only"));
|
||||
}
|
||||
ndarray_obj_t *source = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
if(source->ndim != 2) {
|
||||
mp_raise_ValueError(translate("operation is defined for 2D arrays only"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("operation is defined for 2D arrays only"));
|
||||
}
|
||||
|
||||
size_t m = source->shape[ULAB_MAX_DIMS - 2]; // rows
|
||||
|
|
@ -498,7 +498,7 @@ static mp_obj_t linalg_qr(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_
|
|||
tuple->items[0] = MP_OBJ_FROM_PTR(q);
|
||||
tuple->items[1] = MP_OBJ_FROM_PTR(r);
|
||||
} else {
|
||||
mp_raise_ValueError(translate("mode must be complete, or reduced"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("mode must be complete, or reduced"));
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(tuple);
|
||||
}
|
||||
|
|
@ -537,10 +537,6 @@ const mp_obj_module_t ulab_linalg_module = {
|
|||
.globals = (mp_obj_dict_t*)&mp_module_ulab_linalg_globals,
|
||||
};
|
||||
#if CIRCUITPY_ULAB
|
||||
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy_dot_linalg, ulab_linalg_module, MODULE_ULAB_ENABLED);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy_dot_linalg, ulab_linalg_module);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -407,7 +407,7 @@ static mp_obj_t numerical_sum_mean_std_ndarray(ndarray_obj_t *ndarray, mp_obj_t
|
|||
#if ULAB_NUMPY_HAS_ARGMINMAX
|
||||
static mp_obj_t numerical_argmin_argmax_iterable(mp_obj_t oin, uint8_t optype) {
|
||||
if(MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(oin)) == 0) {
|
||||
mp_raise_ValueError(translate("attempt to get argmin/argmax of an empty sequence"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("attempt to get argmin/argmax of an empty sequence"));
|
||||
}
|
||||
size_t idx = 0, best_idx = 0;
|
||||
mp_obj_iter_buf_t iter_buf;
|
||||
|
|
@ -442,7 +442,7 @@ static mp_obj_t numerical_argmin_argmax_iterable(mp_obj_t oin, uint8_t optype) {
|
|||
static mp_obj_t numerical_argmin_argmax_ndarray(ndarray_obj_t *ndarray, mp_obj_t axis, uint8_t optype) {
|
||||
// TODO: treat the flattened array
|
||||
if(ndarray->len == 0) {
|
||||
mp_raise_ValueError(translate("attempt to get (arg)min/(arg)max of empty sequence"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("attempt to get (arg)min/(arg)max of empty sequence"));
|
||||
}
|
||||
|
||||
if(axis == mp_const_none) {
|
||||
|
|
@ -566,7 +566,7 @@ static mp_obj_t numerical_function(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
mp_obj_t oin = args[0].u_obj;
|
||||
mp_obj_t axis = args[1].u_obj;
|
||||
if((axis != mp_const_none) && (!mp_obj_is_int(axis))) {
|
||||
mp_raise_TypeError(translate("axis must be None, or an integer"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("axis must be None, or an integer"));
|
||||
}
|
||||
|
||||
#if ULAB_NUMPY_HAS_ALL | ULAB_NUMPY_HAS_ANY
|
||||
|
|
@ -602,10 +602,10 @@ static mp_obj_t numerical_function(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
COMPLEX_DTYPE_NOT_IMPLEMENTED(ndarray->dtype)
|
||||
return numerical_sum_mean_std_ndarray(ndarray, axis, optype, 0);
|
||||
default:
|
||||
mp_raise_NotImplementedError(translate("operation is not implemented on ndarrays"));
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("operation is not implemented on ndarrays"));
|
||||
}
|
||||
} else {
|
||||
mp_raise_TypeError(translate("input must be tuple, list, range, or ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("input must be tuple, list, range, or ndarray"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
|
@ -613,7 +613,7 @@ static mp_obj_t numerical_function(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
#if ULAB_NUMPY_HAS_SORT | NDARRAY_HAS_SORT
|
||||
static mp_obj_t numerical_sort_helper(mp_obj_t oin, mp_obj_t axis, uint8_t inplace) {
|
||||
if(!mp_obj_is_type(oin, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("sort argument must be an ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("sort argument must be an ndarray"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *ndarray;
|
||||
|
|
@ -721,20 +721,20 @@ mp_obj_t numerical_argsort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
|
|||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("argsort argument must be an ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("argsort argument must be an ndarray"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
COMPLEX_DTYPE_NOT_IMPLEMENTED(ndarray->dtype)
|
||||
if(args[1].u_obj == mp_const_none) {
|
||||
// bail out, though dense arrays could still be sorted
|
||||
mp_raise_NotImplementedError(translate("argsort is not implemented for flattened arrays"));
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("argsort is not implemented for flattened arrays"));
|
||||
}
|
||||
// Since we are returning an NDARRAY_UINT16 array, bail out,
|
||||
// if the axis is longer than what we can hold
|
||||
for(uint8_t i=0; i < ULAB_MAX_DIMS; i++) {
|
||||
if(ndarray->shape[i] > 65535) {
|
||||
mp_raise_ValueError(translate("axis too long"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("axis too long"));
|
||||
}
|
||||
}
|
||||
int8_t ax = tools_get_axis(args[1].u_obj, ndarray->ndim);
|
||||
|
|
@ -827,14 +827,14 @@ MP_DEFINE_CONST_FUN_OBJ_KW(numerical_argsort_obj, 1, numerical_argsort);
|
|||
|
||||
static mp_obj_t numerical_cross(mp_obj_t _a, mp_obj_t _b) {
|
||||
if (!mp_obj_is_type(_a, &ulab_ndarray_type) || !mp_obj_is_type(_b, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("arguments must be ndarrays"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("arguments must be ndarrays"));
|
||||
}
|
||||
ndarray_obj_t *a = MP_OBJ_TO_PTR(_a);
|
||||
ndarray_obj_t *b = MP_OBJ_TO_PTR(_b);
|
||||
COMPLEX_DTYPE_NOT_IMPLEMENTED(a->dtype)
|
||||
COMPLEX_DTYPE_NOT_IMPLEMENTED(b->dtype)
|
||||
if((a->ndim != 1) || (b->ndim != 1) || (a->len != b->len) || (a->len != 3)) {
|
||||
mp_raise_ValueError(translate("cross is defined for 1D arrays of length 3"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("cross is defined for 1D arrays of length 3"));
|
||||
}
|
||||
|
||||
mp_float_t *results = m_new(mp_float_t, 3);
|
||||
|
|
@ -917,7 +917,7 @@ mp_obj_t numerical_diff(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("diff argument must be an ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("diff argument must be an ndarray"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
|
|
@ -926,16 +926,16 @@ mp_obj_t numerical_diff(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
if(ax < 0) ax += ndarray->ndim;
|
||||
|
||||
if((ax < 0) || (ax > ndarray->ndim - 1)) {
|
||||
mp_raise_ValueError(translate("index out of range"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("index out of range"));
|
||||
}
|
||||
|
||||
if((args[1].u_int < 0) || (args[1].u_int > 9)) {
|
||||
mp_raise_ValueError(translate("differentiation order out of range"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("differentiation order out of range"));
|
||||
}
|
||||
uint8_t N = (uint8_t)args[1].u_int;
|
||||
uint8_t index = ULAB_MAX_DIMS - ndarray->ndim + ax;
|
||||
if(N > ndarray->shape[index]) {
|
||||
mp_raise_ValueError(translate("differentiation order out of range"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("differentiation order out of range"));
|
||||
}
|
||||
|
||||
int8_t *stencil = m_new(int8_t, N+1);
|
||||
|
|
@ -996,7 +996,7 @@ mp_obj_t numerical_flip(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("flip argument must be an ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("flip argument must be an ndarray"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *results = NULL;
|
||||
|
|
@ -1016,7 +1016,7 @@ mp_obj_t numerical_flip(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
results = ndarray_new_view(ndarray, ndarray->ndim, ndarray->shape, ndarray->strides, offset);
|
||||
results->strides[ax] = -results->strides[ax];
|
||||
} else {
|
||||
mp_raise_TypeError(translate("wrong axis index"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("wrong axis index"));
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(results);
|
||||
}
|
||||
|
|
@ -1065,7 +1065,7 @@ mp_obj_t numerical_median(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_
|
|||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("median argument must be an ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("median argument must be an ndarray"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
|
|
@ -1181,7 +1181,7 @@ mp_obj_t numerical_roll(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("roll argument must be an ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("roll argument must be an ndarray"));
|
||||
}
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
uint8_t *array = ndarray->array;
|
||||
|
|
@ -1318,7 +1318,7 @@ mp_obj_t numerical_roll(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
m_del(int32_t, rstrides, ULAB_MAX_DIMS);
|
||||
|
||||
} else {
|
||||
mp_raise_TypeError(translate("wrong axis index"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("wrong axis index"));
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(results);
|
||||
|
|
@ -1387,7 +1387,7 @@ mp_obj_t numerical_std(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
|
|||
size_t ddof = args[2].u_int;
|
||||
if((axis != mp_const_none) && (mp_obj_get_int(axis) != 0) && (mp_obj_get_int(axis) != 1)) {
|
||||
// this seems to pass with False, and True...
|
||||
mp_raise_ValueError(translate("axis must be None, or an integer"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("axis must be None, or an integer"));
|
||||
}
|
||||
if(mp_obj_is_type(oin, &mp_type_tuple) || mp_obj_is_type(oin, &mp_type_list) || mp_obj_is_type(oin, &mp_type_range)) {
|
||||
return numerical_sum_mean_std_iterable(oin, NUMERICAL_STD, ddof);
|
||||
|
|
@ -1395,7 +1395,7 @@ mp_obj_t numerical_std(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
|
|||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(oin);
|
||||
return numerical_sum_mean_std_ndarray(ndarray, axis, NUMERICAL_STD, ddof);
|
||||
} else {
|
||||
mp_raise_TypeError(translate("input must be tuple, list, range, or ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("input must be tuple, list, range, or ndarray"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -397,9 +397,5 @@ const mp_obj_module_t ulab_numpy_module = {
|
|||
};
|
||||
|
||||
#if CIRCUITPY_ULAB
|
||||
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy, ulab_numpy_module, MODULE_ULAB_ENABLED);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_numpy, ulab_numpy_module);
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
mp_obj_t poly_polyfit(size_t n_args, const mp_obj_t *args) {
|
||||
if(!ndarray_object_is_array_like(args[0])) {
|
||||
mp_raise_ValueError(translate("input data must be an iterable"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input data must be an iterable"));
|
||||
}
|
||||
#if ULAB_SUPPORTS_COMPLEX
|
||||
if(mp_obj_is_type(args[0], &ulab_ndarray_type)) {
|
||||
|
|
@ -44,7 +44,7 @@ mp_obj_t poly_polyfit(size_t n_args, const mp_obj_t *args) {
|
|||
leny = (size_t)mp_obj_get_int(mp_obj_len_maybe(args[0]));
|
||||
deg = (uint8_t)mp_obj_get_int(args[1]);
|
||||
if(leny < deg) {
|
||||
mp_raise_ValueError(translate("more degrees of freedom than data points"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("more degrees of freedom than data points"));
|
||||
}
|
||||
lenx = leny;
|
||||
x = m_new(mp_float_t, lenx); // assume uniformly spaced data points
|
||||
|
|
@ -55,16 +55,16 @@ mp_obj_t poly_polyfit(size_t n_args, const mp_obj_t *args) {
|
|||
fill_array_iterable(y, args[0]);
|
||||
} else /* n_args == 3 */ {
|
||||
if(!ndarray_object_is_array_like(args[1])) {
|
||||
mp_raise_ValueError(translate("input data must be an iterable"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input data must be an iterable"));
|
||||
}
|
||||
lenx = (size_t)mp_obj_get_int(mp_obj_len_maybe(args[0]));
|
||||
leny = (size_t)mp_obj_get_int(mp_obj_len_maybe(args[1]));
|
||||
if(lenx != leny) {
|
||||
mp_raise_ValueError(translate("input vectors must be of equal length"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input vectors must be of equal length"));
|
||||
}
|
||||
deg = (uint8_t)mp_obj_get_int(args[2]);
|
||||
if(leny < deg) {
|
||||
mp_raise_ValueError(translate("more degrees of freedom than data points"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("more degrees of freedom than data points"));
|
||||
}
|
||||
x = m_new(mp_float_t, lenx);
|
||||
fill_array_iterable(x, args[0]);
|
||||
|
|
@ -104,7 +104,7 @@ mp_obj_t poly_polyfit(size_t n_args, const mp_obj_t *args) {
|
|||
m_del(mp_float_t, x, lenx);
|
||||
m_del(mp_float_t, y, lenx);
|
||||
m_del(mp_float_t, prod, (deg+1)*(deg+1));
|
||||
mp_raise_ValueError(translate("could not invert Vandermonde matrix"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("could not invert Vandermonde matrix"));
|
||||
}
|
||||
// at this point, we have the inverse of X^T * X
|
||||
// y is a column vector; x is free now, we can use it for storing intermediate values
|
||||
|
|
@ -156,7 +156,7 @@ static mp_float_t poly_eval(mp_float_t x, mp_float_t *p, uint8_t plen) {
|
|||
|
||||
mp_obj_t poly_polyval(mp_obj_t o_p, mp_obj_t o_x) {
|
||||
if(!ndarray_object_is_array_like(o_p)) {
|
||||
mp_raise_TypeError(translate("input is not iterable"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("input is not iterable"));
|
||||
}
|
||||
#if ULAB_SUPPORTS_COMPLEX
|
||||
ndarray_obj_t *input;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ static mp_obj_t transform_compress(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
mp_obj_t condition = args[0].u_obj;
|
||||
|
||||
if(!mp_obj_is_type(args[1].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("wrong input type"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("wrong input type"));
|
||||
}
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[1].u_obj);
|
||||
uint8_t *array = (uint8_t *)ndarray->array;
|
||||
|
|
@ -55,7 +55,7 @@ static mp_obj_t transform_compress(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
|
||||
if(((axis == mp_const_none) && (len != ndarray->len)) ||
|
||||
((axis != mp_const_none) && (len != ndarray->shape[shift_ax]))) {
|
||||
mp_raise_ValueError(translate("wrong length of condition array"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("wrong length of condition array"));
|
||||
}
|
||||
|
||||
size_t true_count = 0;
|
||||
|
|
@ -175,7 +175,7 @@ static mp_obj_t transform_delete(size_t n_args, const mp_obj_t *pos_args, mp_map
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("first argument must be an ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("first argument must be an ndarray"));
|
||||
}
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
uint8_t *array = (uint8_t *)ndarray->array;
|
||||
|
|
@ -201,13 +201,13 @@ static mp_obj_t transform_delete(size_t n_args, const mp_obj_t *pos_args, mp_map
|
|||
index_len = 1;
|
||||
} else {
|
||||
if(mp_obj_len_maybe(indices) == MP_OBJ_NULL) {
|
||||
mp_raise_TypeError(translate("wrong index type"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("wrong index type"));
|
||||
}
|
||||
index_len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(indices));
|
||||
}
|
||||
|
||||
if(index_len > axis_len) {
|
||||
mp_raise_ValueError(translate("wrong length of index array"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("wrong length of index array"));
|
||||
}
|
||||
|
||||
size_t *index_array = m_new(size_t, index_len);
|
||||
|
|
@ -218,7 +218,7 @@ static mp_obj_t transform_delete(size_t n_args, const mp_obj_t *pos_args, mp_map
|
|||
value += axis_len;
|
||||
}
|
||||
if((value < 0) || (value > (ssize_t)axis_len)) {
|
||||
mp_raise_ValueError(translate("index is out of bounds"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("index is out of bounds"));
|
||||
} else {
|
||||
*index_array++ = (size_t)value;
|
||||
}
|
||||
|
|
@ -231,7 +231,7 @@ static mp_obj_t transform_delete(size_t n_args, const mp_obj_t *pos_args, mp_map
|
|||
value += axis_len;
|
||||
}
|
||||
if((value < 0) || (value > (ssize_t)axis_len)) {
|
||||
mp_raise_ValueError(translate("index is out of bounds"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("index is out of bounds"));
|
||||
} else {
|
||||
*index_array++ = (size_t)value;
|
||||
}
|
||||
|
|
@ -356,7 +356,7 @@ mp_obj_t transform_dot(mp_obj_t _m1, mp_obj_t _m2) {
|
|||
// TODO: should the results be upcast?
|
||||
// This implements 2D operations only!
|
||||
if(!mp_obj_is_type(_m1, &ulab_ndarray_type) || !mp_obj_is_type(_m2, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("arguments must be ndarrays"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("arguments must be ndarrays"));
|
||||
}
|
||||
ndarray_obj_t *m1 = MP_OBJ_TO_PTR(_m1);
|
||||
ndarray_obj_t *m2 = MP_OBJ_TO_PTR(_m2);
|
||||
|
|
@ -370,7 +370,7 @@ mp_obj_t transform_dot(mp_obj_t _m1, mp_obj_t _m2) {
|
|||
mp_float_t (*func2)(void *) = ndarray_get_float_function(m2->dtype);
|
||||
|
||||
if(m1->shape[ULAB_MAX_DIMS - 1] != m2->shape[ULAB_MAX_DIMS - m2->ndim]) {
|
||||
mp_raise_ValueError(translate("dimensions do not match"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("dimensions do not match"));
|
||||
}
|
||||
uint8_t ndim = MIN(m1->ndim, m2->ndim);
|
||||
size_t shape1 = m1->ndim == 2 ? m1->shape[ULAB_MAX_DIMS - m1->ndim] : 1;
|
||||
|
|
@ -428,7 +428,7 @@ static mp_obj_t transform_size(size_t n_args, const mp_obj_t *pos_args, mp_map_t
|
|||
}
|
||||
|
||||
if(!ndarray_object_is_array_like(args[0].u_obj)) {
|
||||
mp_raise_TypeError(translate("first argument must be an ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("first argument must be an ndarray"));
|
||||
}
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
return mp_obj_len_maybe(args[0].u_obj);
|
||||
|
|
|
|||
|
|
@ -64,18 +64,18 @@ static mp_obj_t vector_generic_vector(size_t n_args, const mp_obj_t *pos_args, m
|
|||
target = ndarray_new_dense_ndarray(source->ndim, source->shape, NDARRAY_FLOAT);
|
||||
} else {
|
||||
if(!mp_obj_is_type(out, &ulab_ndarray_type)) {
|
||||
mp_raise_ValueError(translate("out must be an ndarray"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("out must be an ndarray"));
|
||||
}
|
||||
target = MP_OBJ_TO_PTR(out);
|
||||
if(target->dtype != NDARRAY_FLOAT) {
|
||||
mp_raise_ValueError(translate("out must be of float dtype"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("out must be of float dtype"));
|
||||
}
|
||||
if(target->ndim != source->ndim) {
|
||||
mp_raise_ValueError(translate("input and output dimensions differ"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input and output dimensions differ"));
|
||||
}
|
||||
for(uint8_t d = 0; d < target->ndim; d++) {
|
||||
if(target->shape[ULAB_MAX_DIMS - 1 - d] != source->shape[ULAB_MAX_DIMS - 1 - d]) {
|
||||
mp_raise_ValueError(translate("input and output shapes differ"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input and output shapes differ"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -309,7 +309,7 @@ mp_obj_t vector_around(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
|
|||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("first argument must be an ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("first argument must be an ndarray"));
|
||||
}
|
||||
int8_t n = args[1].u_int;
|
||||
mp_float_t mul = MICROPY_FLOAT_C_FUN(pow)(10.0, n);
|
||||
|
|
@ -318,7 +318,7 @@ mp_obj_t vector_around(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
|
|||
#if ULAB_MATH_FUNCTIONS_OUT_KEYWORD
|
||||
mp_obj_t out = args[2].u_obj;
|
||||
if(out != mp_const_none) {
|
||||
mp_raise_ValueError(translate("out keyword is not supported for function"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("out keyword is not supported for function"));
|
||||
}
|
||||
#endif /* ULAB_MATH_FUNCTIONS_OUT_KEYWORD */
|
||||
ndarray_obj_t *ndarray = ndarray_new_dense_ndarray(source->ndim, source->shape, NDARRAY_FLOAT);
|
||||
|
|
@ -426,7 +426,7 @@ mp_obj_t vector_arctan2(mp_obj_t y, mp_obj_t x) {
|
|||
int32_t *xstrides = m_new(int32_t, ULAB_MAX_DIMS);
|
||||
int32_t *ystrides = m_new(int32_t, ULAB_MAX_DIMS);
|
||||
if(!ndarray_can_broadcast(ndarray_x, ndarray_y, &ndim, shape, xstrides, ystrides)) {
|
||||
mp_raise_ValueError(translate("operands could not be broadcast together"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("operands could not be broadcast together"));
|
||||
m_del(size_t, shape, ULAB_MAX_DIMS);
|
||||
m_del(int32_t, xstrides, ULAB_MAX_DIMS);
|
||||
m_del(int32_t, ystrides, ULAB_MAX_DIMS);
|
||||
|
|
@ -610,7 +610,7 @@ static mp_obj_t vector_exp(mp_obj_t o_in) {
|
|||
mp_obj_t o_in = args[0].u_obj;
|
||||
mp_obj_t out = args[1].u_obj;
|
||||
if(out != mp_const_none) {
|
||||
mp_raise_ValueError(translate("out keyword is not supported for complex dtype"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("out keyword is not supported for complex dtype"));
|
||||
}
|
||||
#endif /* ULAB_MATH_FUNCTIONS_OUT_KEYWORD */
|
||||
|
||||
|
|
@ -888,7 +888,7 @@ mp_obj_t vector_sqrt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
|
|||
mp_obj_t o_in = args[0].u_obj;
|
||||
uint8_t dtype = mp_obj_get_int(args[2].u_obj);
|
||||
if((dtype != NDARRAY_FLOAT) && (dtype != NDARRAY_COMPLEX)) {
|
||||
mp_raise_TypeError(translate("dtype must be float, or complex"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("dtype must be float, or complex"));
|
||||
}
|
||||
|
||||
if(mp_obj_is_type(o_in, &mp_type_complex)) {
|
||||
|
|
@ -901,14 +901,14 @@ mp_obj_t vector_sqrt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
|
|||
} else if(mp_obj_is_type(o_in, &ulab_ndarray_type)) {
|
||||
ndarray_obj_t *source = MP_OBJ_TO_PTR(o_in);
|
||||
if((source->dtype == NDARRAY_COMPLEX) && (dtype == NDARRAY_FLOAT)) {
|
||||
mp_raise_TypeError(translate("can't convert complex to float"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("can't convert complex to float"));
|
||||
}
|
||||
|
||||
if(dtype == NDARRAY_COMPLEX) {
|
||||
#if ULAB_MATH_FUNCTIONS_OUT_KEYWORD
|
||||
mp_obj_t out = args[1].u_obj;
|
||||
if(out != mp_const_none) {
|
||||
mp_raise_ValueError(translate("out keyword is not supported for complex dtype"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("out keyword is not supported for complex dtype"));
|
||||
}
|
||||
#endif
|
||||
if(source->dtype == NDARRAY_COMPLEX) {
|
||||
|
|
@ -1010,7 +1010,7 @@ mp_obj_t vector_sqrt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
|
|||
#endif /* ULAB_MAX_DIMS > 3 */
|
||||
return MP_OBJ_FROM_PTR(ndarray);
|
||||
} else {
|
||||
mp_raise_TypeError(translate("input dtype must be float or complex"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("input dtype must be float or complex"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1127,7 +1127,7 @@ static mp_obj_t vector_vectorized_function_call(mp_obj_t self_in, size_t n_args,
|
|||
ndarray_set_value(self->otypes, ndarray->array, 0, fvalue);
|
||||
return MP_OBJ_FROM_PTR(ndarray);
|
||||
} else {
|
||||
mp_raise_ValueError(translate("wrong input type"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("wrong input type"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
|
@ -1173,7 +1173,7 @@ static mp_obj_t vector_vectorize(size_t n_args, const mp_obj_t *pos_args, mp_map
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
const mp_obj_type_t *type = mp_obj_get_type(args[0].u_obj);
|
||||
if(!MP_OBJ_TYPE_HAS_SLOT(type, call)) {
|
||||
mp_raise_TypeError(translate("first argument must be a callable"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("first argument must be a callable"));
|
||||
}
|
||||
mp_obj_t _otypes = args[1].u_obj;
|
||||
uint8_t otypes = NDARRAY_FLOAT;
|
||||
|
|
@ -1184,11 +1184,11 @@ static mp_obj_t vector_vectorize(size_t n_args, const mp_obj_t *pos_args, mp_map
|
|||
otypes = mp_obj_get_int(_otypes);
|
||||
if(otypes != NDARRAY_FLOAT && otypes != NDARRAY_UINT8 && otypes != NDARRAY_INT8 &&
|
||||
otypes != NDARRAY_UINT16 && otypes != NDARRAY_INT16) {
|
||||
mp_raise_ValueError(translate("wrong output type"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("wrong output type"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
mp_raise_ValueError(translate("wrong output type"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("wrong output type"));
|
||||
}
|
||||
vectorized_function_obj_t *function = m_new_obj(vectorized_function_obj_t);
|
||||
function->base.type = &vector_function_type;
|
||||
|
|
|
|||
|
|
@ -59,14 +59,14 @@ static mp_obj_t solve_triangular(size_t n_args, const mp_obj_t *pos_args, mp_map
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type) || !mp_obj_is_type(args[1].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("first two arguments must be ndarrays"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("first two arguments must be ndarrays"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *A = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
ndarray_obj_t *b = MP_OBJ_TO_PTR(args[1].u_obj);
|
||||
|
||||
if(!ndarray_is_dense(A) || !ndarray_is_dense(b)) {
|
||||
mp_raise_TypeError(translate("input must be a dense ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("input must be a dense ndarray"));
|
||||
}
|
||||
|
||||
size_t A_rows = A->shape[ULAB_MAX_DIMS - 2];
|
||||
|
|
@ -83,7 +83,7 @@ static mp_obj_t solve_triangular(size_t n_args, const mp_obj_t *pos_args, mp_map
|
|||
// check if input matrix A is singular
|
||||
for (i = 0; i < A_rows; i++) {
|
||||
if (MICROPY_FLOAT_C_FUN(fabs)(get_A_ele(A_arr)) < LINALG_EPSILON)
|
||||
mp_raise_ValueError(translate("input matrix is singular"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input matrix is singular"));
|
||||
A_arr += A->strides[ULAB_MAX_DIMS - 2];
|
||||
A_arr += A->strides[ULAB_MAX_DIMS - 1];
|
||||
}
|
||||
|
|
@ -161,14 +161,14 @@ MP_DEFINE_CONST_FUN_OBJ_KW(linalg_solve_triangular_obj, 2, solve_triangular);
|
|||
static mp_obj_t cho_solve(mp_obj_t _L, mp_obj_t _b) {
|
||||
|
||||
if(!mp_obj_is_type(_L, &ulab_ndarray_type) || !mp_obj_is_type(_b, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("first two arguments must be ndarrays"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("first two arguments must be ndarrays"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *L = MP_OBJ_TO_PTR(_L);
|
||||
ndarray_obj_t *b = MP_OBJ_TO_PTR(_b);
|
||||
|
||||
if(!ndarray_is_dense(L) || !ndarray_is_dense(b)) {
|
||||
mp_raise_TypeError(translate("input must be a dense ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("input must be a dense ndarray"));
|
||||
}
|
||||
|
||||
mp_float_t (*get_L_ele)(void *) = ndarray_get_float_function(L->dtype);
|
||||
|
|
@ -276,10 +276,6 @@ const mp_obj_module_t ulab_scipy_linalg_module = {
|
|||
.globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_linalg_globals,
|
||||
};
|
||||
#if CIRCUITPY_ULAB
|
||||
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_linalg, ulab_scipy_linalg_module, MODULE_ULAB_ENABLED);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_linalg, ulab_scipy_linalg_module);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ STATIC mp_obj_t optimize_bisect(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
|||
mp_obj_t fun = args[0].u_obj;
|
||||
const mp_obj_type_t *type = mp_obj_get_type(fun);
|
||||
if(!MP_OBJ_TYPE_HAS_SLOT(type, call)) {
|
||||
mp_raise_TypeError(translate("first argument must be a function"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("first argument must be a function"));
|
||||
}
|
||||
mp_float_t xtol = mp_obj_get_float(args[3].u_obj);
|
||||
mp_obj_t fargs[1];
|
||||
|
|
@ -82,12 +82,12 @@ STATIC mp_obj_t optimize_bisect(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
|||
left = optimize_python_call(type, fun, a, fargs, 0);
|
||||
right = optimize_python_call(type, fun, b, fargs, 0);
|
||||
if(left * right > 0) {
|
||||
mp_raise_ValueError(translate("function has the same sign at the ends of interval"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("function has the same sign at the ends of interval"));
|
||||
}
|
||||
mp_float_t rtb = left < MICROPY_FLOAT_CONST(0.0) ? a : b;
|
||||
mp_float_t dx = left < MICROPY_FLOAT_CONST(0.0) ? b - a : a - b;
|
||||
if(args[4].u_int < 0) {
|
||||
mp_raise_ValueError(translate("maxiter should be > 0"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("maxiter should be > 0"));
|
||||
}
|
||||
for(uint16_t i=0; i < args[4].u_int; i++) {
|
||||
dx *= MICROPY_FLOAT_CONST(0.5);
|
||||
|
|
@ -141,14 +141,14 @@ STATIC mp_obj_t optimize_fmin(size_t n_args, const mp_obj_t *pos_args, mp_map_t
|
|||
mp_obj_t fun = args[0].u_obj;
|
||||
const mp_obj_type_t *type = mp_obj_get_type(fun);
|
||||
if(!MP_OBJ_TYPE_HAS_SLOT(type, call)) {
|
||||
mp_raise_TypeError(translate("first argument must be a function"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("first argument must be a function"));
|
||||
}
|
||||
|
||||
// parameters controlling convergence conditions
|
||||
mp_float_t xatol = mp_obj_get_float(args[2].u_obj);
|
||||
mp_float_t fatol = mp_obj_get_float(args[3].u_obj);
|
||||
if(args[4].u_int <= 0) {
|
||||
mp_raise_ValueError(translate("maxiter must be > 0"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("maxiter must be > 0"));
|
||||
}
|
||||
uint16_t maxiter = (uint16_t)args[4].u_int;
|
||||
|
||||
|
|
@ -277,22 +277,22 @@ mp_obj_t optimize_curve_fit(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
|||
mp_obj_t fun = args[0].u_obj;
|
||||
const mp_obj_type_t *type = mp_obj_get_type(fun);
|
||||
if(!MP_OBJ_TYPE_HAS_SLOT(type, call)) {
|
||||
mp_raise_TypeError(translate("first argument must be a function"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("first argument must be a function"));
|
||||
}
|
||||
|
||||
mp_obj_t x_obj = args[1].u_obj;
|
||||
mp_obj_t y_obj = args[2].u_obj;
|
||||
mp_obj_t p0_obj = args[3].u_obj;
|
||||
if(!ndarray_object_is_array_like(x_obj) || !ndarray_object_is_array_like(y_obj)) {
|
||||
mp_raise_TypeError(translate("data must be iterable"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("data must be iterable"));
|
||||
}
|
||||
if(!ndarray_object_is_nditerable(p0_obj)) {
|
||||
mp_raise_TypeError(translate("initial values must be iterable"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("initial values must be iterable"));
|
||||
}
|
||||
size_t len = (size_t)mp_obj_get_int(mp_obj_len_maybe(x_obj));
|
||||
uint8_t lenp = (uint8_t)mp_obj_get_int(mp_obj_len_maybe(p0_obj));
|
||||
if(len != (uint16_t)mp_obj_get_int(mp_obj_len_maybe(y_obj))) {
|
||||
mp_raise_ValueError(translate("data must be of equal length"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("data must be of equal length"));
|
||||
}
|
||||
|
||||
mp_float_t *x = m_new(mp_float_t, len);
|
||||
|
|
@ -366,7 +366,7 @@ static mp_obj_t optimize_newton(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
|||
mp_obj_t fun = args[0].u_obj;
|
||||
const mp_obj_type_t *type = mp_obj_get_type(fun);
|
||||
if(!MP_OBJ_TYPE_HAS_SLOT(type, call)) {
|
||||
mp_raise_TypeError(translate("first argument must be a function"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("first argument must be a function"));
|
||||
}
|
||||
mp_float_t x = mp_obj_get_float(args[1].u_obj);
|
||||
mp_float_t tol = mp_obj_get_float(args[2].u_obj);
|
||||
|
|
@ -375,7 +375,7 @@ static mp_obj_t optimize_newton(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
|||
dx = x > MICROPY_FLOAT_CONST(0.0) ? OPTIMIZE_EPS * x : -OPTIMIZE_EPS * x;
|
||||
mp_obj_t fargs[1];
|
||||
if(args[4].u_int <= 0) {
|
||||
mp_raise_ValueError(translate("maxiter must be > 0"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("maxiter must be > 0"));
|
||||
}
|
||||
for(uint16_t i=0; i < args[4].u_int; i++) {
|
||||
fx = optimize_python_call(type, fun, x, fargs, 0);
|
||||
|
|
@ -413,9 +413,5 @@ const mp_obj_module_t ulab_scipy_optimize_module = {
|
|||
.globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_optimize_globals,
|
||||
};
|
||||
#if CIRCUITPY_ULAB
|
||||
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_optimize, ulab_scipy_optimize_module, MODULE_ULAB_ENABLED);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_optimize, ulab_scipy_optimize_module);
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -49,10 +49,6 @@ const mp_obj_module_t ulab_scipy_module = {
|
|||
.globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_globals,
|
||||
};
|
||||
#if CIRCUITPY_ULAB
|
||||
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy, ulab_scipy_module, MODULE_ULAB_ENABLED);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy, ulab_scipy_module);
|
||||
#endif
|
||||
#endif
|
||||
#endif /* ULAB_HAS_SCIPY */
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ mp_obj_t signal_sosfilt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!ndarray_object_is_array_like(args[0].u_obj) || !ndarray_object_is_array_like(args[1].u_obj)) {
|
||||
mp_raise_TypeError(translate("sosfilt requires iterable arguments"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("sosfilt requires iterable arguments"));
|
||||
}
|
||||
#if ULAB_SUPPORTS_COMPLEX
|
||||
if(mp_obj_is_type(args[1].u_obj, &ulab_ndarray_type)) {
|
||||
|
|
@ -59,7 +59,7 @@ mp_obj_t signal_sosfilt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
ndarray_obj_t *inarray = MP_OBJ_TO_PTR(args[1].u_obj);
|
||||
#if ULAB_MAX_DIMS > 1
|
||||
if(inarray->ndim > 1) {
|
||||
mp_raise_ValueError(translate("input must be one-dimensional"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input must be one-dimensional"));
|
||||
}
|
||||
#endif
|
||||
uint8_t *iarray = (uint8_t *)inarray->array;
|
||||
|
|
@ -82,14 +82,14 @@ mp_obj_t signal_sosfilt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
|
||||
if(args[2].u_obj != mp_const_none) {
|
||||
if(!mp_obj_is_type(args[2].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("zi must be an ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("zi must be an ndarray"));
|
||||
} else {
|
||||
ndarray_obj_t *zi = MP_OBJ_TO_PTR(args[2].u_obj);
|
||||
if((zi->shape[ULAB_MAX_DIMS - 2] != lensos) || (zi->shape[ULAB_MAX_DIMS - 1] != 2)) {
|
||||
mp_raise_ValueError(translate("zi must be of shape (n_section, 2)"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("zi must be of shape (n_section, 2)"));
|
||||
}
|
||||
if(zi->dtype != NDARRAY_FLOAT) {
|
||||
mp_raise_ValueError(translate("zi must be of float type"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("zi must be of float type"));
|
||||
}
|
||||
// TODO: this won't work with sparse arrays
|
||||
memcpy(zf_array, zi->array, 2*lensos*sizeof(mp_float_t));
|
||||
|
|
@ -97,11 +97,11 @@ mp_obj_t signal_sosfilt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
}
|
||||
while((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
|
||||
if(mp_obj_get_int(mp_obj_len_maybe(item)) != 6) {
|
||||
mp_raise_ValueError(translate("sos array must be of shape (n_section, 6)"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("sos array must be of shape (n_section, 6)"));
|
||||
} else {
|
||||
fill_array_iterable(coeffs, item);
|
||||
if(coeffs[3] != MICROPY_FLOAT_CONST(1.0)) {
|
||||
mp_raise_ValueError(translate("sos[:, 3] should be all ones"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("sos[:, 3] should be all ones"));
|
||||
}
|
||||
signal_sosfilt_array(yarray, coeffs, zf_array, lenx);
|
||||
zf_array += 2;
|
||||
|
|
@ -134,9 +134,5 @@ const mp_obj_module_t ulab_scipy_signal_module = {
|
|||
.globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_signal_globals,
|
||||
};
|
||||
#if CIRCUITPY_ULAB
|
||||
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_signal, ulab_scipy_signal_module, MODULE_ULAB_ENABLED);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_signal, ulab_scipy_signal_module);
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -41,9 +41,5 @@ const mp_obj_module_t ulab_scipy_special_module = {
|
|||
.globals = (mp_obj_dict_t*)&mp_module_ulab_scipy_special_globals,
|
||||
};
|
||||
#if CIRCUITPY_ULAB
|
||||
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_special, ulab_scipy_special_module, MODULE_ULAB_ENABLED);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_scipy_dot_special, ulab_scipy_special_module);
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
28
code/ulab.c
28
code/ulab.c
|
|
@ -76,26 +76,6 @@ STATIC const mp_rom_map_elem_t ulab_ndarray_locals_dict_table[] = {
|
|||
#if NDARRAY_HAS_SORT
|
||||
{ MP_ROM_QSTR(MP_QSTR_sort), MP_ROM_PTR(&numerical_sort_inplace_obj) },
|
||||
#endif
|
||||
#ifdef CIRCUITPY
|
||||
#if NDARRAY_HAS_DTYPE
|
||||
{ MP_ROM_QSTR(MP_QSTR_dtype), MP_ROM_PTR(&ndarray_dtype_obj) },
|
||||
#endif
|
||||
#if NDARRAY_HAS_FLATITER
|
||||
{ MP_ROM_QSTR(MP_QSTR_flat), MP_ROM_PTR(&ndarray_flat_obj) },
|
||||
#endif
|
||||
#if NDARRAY_HAS_ITEMSIZE
|
||||
{ MP_ROM_QSTR(MP_QSTR_itemsize), MP_ROM_PTR(&ndarray_itemsize_obj) },
|
||||
#endif
|
||||
#if NDARRAY_HAS_SHAPE
|
||||
{ MP_ROM_QSTR(MP_QSTR_shape), MP_ROM_PTR(&ndarray_shape_obj) },
|
||||
#endif
|
||||
#if NDARRAY_HAS_SIZE
|
||||
{ MP_ROM_QSTR(MP_QSTR_size), MP_ROM_PTR(&ndarray_size_obj) },
|
||||
#endif
|
||||
#if NDARRAY_HAS_STRIDES
|
||||
{ MP_ROM_QSTR(MP_QSTR_strides), MP_ROM_PTR(&ndarray_strides_obj) },
|
||||
#endif
|
||||
#endif /* CIRCUITPY */
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ulab_ndarray_locals_dict, ulab_ndarray_locals_dict_table);
|
||||
|
|
@ -167,9 +147,7 @@ const mp_obj_type_t ulab_ndarray_type = {
|
|||
#if NDARRAY_HAS_BINARY_OPS
|
||||
.binary_op = ndarray_binary_op,
|
||||
#endif
|
||||
#ifndef CIRCUITPY
|
||||
.attr = ndarray_properties_attr,
|
||||
#endif
|
||||
.buffer_p = { .get_buffer = ndarray_get_buffer, },
|
||||
)
|
||||
};
|
||||
|
|
@ -253,10 +231,4 @@ const mp_obj_module_t ulab_user_cmodule = {
|
|||
.globals = (mp_obj_dict_t*)&mp_module_ulab_globals,
|
||||
};
|
||||
|
||||
// Use old three-argument MP_REGISTER_MODULE for
|
||||
// MicroPython <= v1.18.0: (1 << 16) | (18 << 8) | 0
|
||||
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab, ulab_user_cmodule, MODULE_ULAB_ENABLED);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab, ulab_user_cmodule);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ shape_strides tools_reduce_axes(ndarray_obj_t *ndarray, mp_obj_t axis) {
|
|||
// The shape and strides at `axis` are moved to the zeroth position,
|
||||
// everything else is aligned to the right
|
||||
if(!mp_obj_is_int(axis) & (axis != mp_const_none)) {
|
||||
mp_raise_TypeError(translate("axis must be None, or an integer"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("axis must be None, or an integer"));
|
||||
}
|
||||
shape_strides _shape_strides;
|
||||
|
||||
|
|
@ -194,7 +194,7 @@ shape_strides tools_reduce_axes(ndarray_obj_t *ndarray, mp_obj_t axis) {
|
|||
int8_t ax = mp_obj_get_int(axis);
|
||||
if(ax < 0) ax += ndarray->ndim;
|
||||
if((ax < 0) || (ax > ndarray->ndim - 1)) {
|
||||
mp_raise_ValueError(translate("index out of range"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("index out of range"));
|
||||
}
|
||||
index = ULAB_MAX_DIMS - ndarray->ndim + ax;
|
||||
_shape_strides.ndim = ndarray->ndim - 1;
|
||||
|
|
@ -220,7 +220,7 @@ int8_t tools_get_axis(mp_obj_t axis, uint8_t ndim) {
|
|||
int8_t ax = mp_obj_get_int(axis);
|
||||
if(ax < 0) ax += ndim;
|
||||
if((ax < 0) || (ax > ndim - 1)) {
|
||||
mp_raise_ValueError(translate("axis is out of bounds"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("axis is out of bounds"));
|
||||
}
|
||||
return ax;
|
||||
}
|
||||
|
|
@ -230,11 +230,11 @@ ndarray_obj_t *tools_object_is_square(mp_obj_t obj) {
|
|||
// Returns an ndarray, if the object is a square ndarray,
|
||||
// raises the appropriate exception otherwise
|
||||
if(!mp_obj_is_type(obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("size is defined for ndarrays only"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("size is defined for ndarrays only"));
|
||||
}
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(obj);
|
||||
if((ndarray->shape[ULAB_MAX_DIMS - 1] != ndarray->shape[ULAB_MAX_DIMS - 2]) || (ndarray->ndim != 2)) {
|
||||
mp_raise_ValueError(translate("input must be square matrix"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("input must be square matrix"));
|
||||
}
|
||||
return ndarray;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ static mp_obj_t user_square(mp_obj_t arg) {
|
|||
|
||||
// raise a TypeError exception, if the input is not an ndarray
|
||||
if(!mp_obj_is_type(arg, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("input must be an ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("input must be an ndarray"));
|
||||
}
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(arg);
|
||||
|
||||
// make sure that the input is a dense array
|
||||
if(!ndarray_is_dense(ndarray)) {
|
||||
mp_raise_TypeError(translate("input must be a dense ndarray"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("input must be a dense ndarray"));
|
||||
}
|
||||
|
||||
// if the input is a dense array, create `results` with the same number of
|
||||
|
|
@ -92,11 +92,7 @@ const mp_obj_module_t ulab_user_module = {
|
|||
.globals = (mp_obj_dict_t*)&mp_module_ulab_user_globals,
|
||||
};
|
||||
#if CIRCUITPY_ULAB
|
||||
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_user, ulab_user_module, ULAB_HAS_USER_MODULE);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_user, ulab_user_module);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ static mp_obj_t utils_from_intbuffer_helper(size_t n_args, const mp_obj_t *pos_a
|
|||
if(args[3].u_obj != mp_const_none) {
|
||||
ndarray = MP_OBJ_TO_PTR(args[3].u_obj);
|
||||
if((ndarray->dtype != NDARRAY_FLOAT) || !ndarray_is_dense(ndarray)) {
|
||||
mp_raise_TypeError(translate("out must be a float dense array"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("out must be a float dense array"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ static mp_obj_t utils_from_intbuffer_helper(size_t n_args, const mp_obj_t *pos_a
|
|||
mp_buffer_info_t bufinfo;
|
||||
if(mp_get_buffer(args[0].u_obj, &bufinfo, MP_BUFFER_READ)) {
|
||||
if(bufinfo.len < offset) {
|
||||
mp_raise_ValueError(translate("offset is too large"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("offset is too large"));
|
||||
}
|
||||
uint8_t sz = sizeof(int16_t);
|
||||
#if ULAB_UTILS_HAS_FROM_INT32_BUFFER | ULAB_UTILS_HAS_FROM_UINT32_BUFFER
|
||||
|
|
@ -65,12 +65,12 @@ static mp_obj_t utils_from_intbuffer_helper(size_t n_args, const mp_obj_t *pos_a
|
|||
|
||||
size_t len = (bufinfo.len - offset) / sz;
|
||||
if((len * sz) != (bufinfo.len - offset)) {
|
||||
mp_raise_ValueError(translate("buffer size must be a multiple of element size"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("buffer size must be a multiple of element size"));
|
||||
}
|
||||
if(mp_obj_get_int(args[1].u_obj) > 0) {
|
||||
size_t count = mp_obj_get_int(args[1].u_obj);
|
||||
if(len < count) {
|
||||
mp_raise_ValueError(translate("buffer is smaller than requested size"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("buffer is smaller than requested size"));
|
||||
} else {
|
||||
len = count;
|
||||
}
|
||||
|
|
@ -79,7 +79,7 @@ static mp_obj_t utils_from_intbuffer_helper(size_t n_args, const mp_obj_t *pos_a
|
|||
ndarray = ndarray_new_linear_array(len, NDARRAY_FLOAT);
|
||||
} else {
|
||||
if(ndarray->len < len) {
|
||||
mp_raise_ValueError(translate("out array is too small"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("out array is too small"));
|
||||
}
|
||||
}
|
||||
uint8_t *buffer = bufinfo.buf;
|
||||
|
|
@ -250,11 +250,7 @@ const mp_obj_module_t ulab_utils_module = {
|
|||
.globals = (mp_obj_dict_t*)&mp_module_ulab_utils_globals,
|
||||
};
|
||||
#if CIRCUITPY_ULAB
|
||||
#if !defined(MICROPY_VERSION) || MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_utils, ulab_utils_module, MODULE_ULAB_ENABLED);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_ulab_dot_utils, ulab_utils_module);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* ULAB_HAS_UTILS_MODULE */
|
||||
|
|
|
|||
Loading…
Reference in a new issue