@@ -199,7 +199,7 @@ mp_obj_t ndarray_dtype_make_new(const mp_obj_type_t *type, size_t n_args, size_t
199
199
if ((_dtype != NDARRAY_BOOL ) && (_dtype != NDARRAY_UINT8 )
200
200
&& (_dtype != NDARRAY_INT8 ) && (_dtype != NDARRAY_UINT16 )
201
201
&& (_dtype != NDARRAY_INT16 ) && (_dtype != NDARRAY_FLOAT )) {
202
- mp_raise_TypeError (translate ("data type not understood" ));
202
+ mp_raise_TypeError (MP_ERROR_TEXT ("data type not understood" ));
203
203
}
204
204
} else {
205
205
GET_STR_DATA_LEN (_args [0 ].u_obj , _dtype_ , len );
@@ -220,7 +220,7 @@ mp_obj_t ndarray_dtype_make_new(const mp_obj_type_t *type, size_t n_args, size_t
220
220
}
221
221
#endif
222
222
else {
223
- mp_raise_TypeError (translate ("data type not understood" ));
223
+ mp_raise_TypeError (MP_ERROR_TEXT ("data type not understood" ));
224
224
}
225
225
}
226
226
dtype -> dtype = _dtype ;
@@ -252,7 +252,7 @@ mp_obj_t ndarray_dtype(mp_obj_t self_in) {
252
252
&& (* _dtype != NDARRAY_COMPLEX )
253
253
#endif
254
254
)) {
255
- mp_raise_TypeError (translate ("data type not understood" ));
255
+ mp_raise_TypeError (MP_ERROR_TEXT ("data type not understood" ));
256
256
}
257
257
dtype = * _dtype ;
258
258
}
@@ -504,7 +504,7 @@ bool ndarray_is_dense(ndarray_obj_t *ndarray) {
504
504
static size_t multiply_size (size_t a , size_t b ) {
505
505
size_t result ;
506
506
if (__builtin_mul_overflow (a , b , & result )) {
507
- mp_raise_ValueError (translate ("array is too big" ));
507
+ mp_raise_ValueError (MP_ERROR_TEXT ("array is too big" ));
508
508
}
509
509
return result ;
510
510
}
@@ -531,7 +531,7 @@ ndarray_obj_t *ndarray_new_ndarray(uint8_t ndim, size_t *shape, int32_t *strides
531
531
}
532
532
533
533
if (SIZE_MAX / ndarray -> itemsize <= ndarray -> len ) {
534
- mp_raise_ValueError (translate ("ndarray length overflows" ));
534
+ mp_raise_ValueError (MP_ERROR_TEXT ("ndarray length overflows" ));
535
535
}
536
536
537
537
// if the length is 0, still allocate a single item, so that contractions can be handled
@@ -690,7 +690,7 @@ ndarray_obj_t *ndarray_copy_view_convert_type(ndarray_obj_t *source, uint8_t dty
690
690
#if ULAB_SUPPORTS_COMPLEX
691
691
if (source -> dtype == NDARRAY_COMPLEX ) {
692
692
if (dtype != NDARRAY_COMPLEX ) {
693
- mp_raise_TypeError (translate ("cannot convert complex type" ));
693
+ mp_raise_TypeError (MP_ERROR_TEXT ("cannot convert complex type" ));
694
694
} else {
695
695
memcpy (array , sarray , complex_size );
696
696
}
@@ -856,7 +856,7 @@ ndarray_obj_t *ndarray_from_iterable(mp_obj_t obj, uint8_t dtype) {
856
856
break ;
857
857
}
858
858
if (ndim == ULAB_MAX_DIMS ) {
859
- mp_raise_ValueError (translate ("too many dimensions" ));
859
+ mp_raise_ValueError (MP_ERROR_TEXT ("too many dimensions" ));
860
860
}
861
861
shape [ndim ] = MP_OBJ_SMALL_INT_VALUE (mp_obj_len_maybe (item ));
862
862
if (shape [ndim ] == 0 ) {
@@ -1046,13 +1046,13 @@ static mp_bound_slice_t generate_slice(mp_int_t n, mp_obj_t index) {
1046
1046
_index += n ;
1047
1047
}
1048
1048
if ((_index >= n ) || (_index < 0 )) {
1049
- mp_raise_msg (& mp_type_IndexError , translate ("index is out of bounds" ));
1049
+ mp_raise_msg (& mp_type_IndexError , MP_ERROR_TEXT ("index is out of bounds" ));
1050
1050
}
1051
1051
slice .start = _index ;
1052
1052
slice .stop = _index + 1 ;
1053
1053
slice .step = 1 ;
1054
1054
} else {
1055
- mp_raise_msg (& mp_type_IndexError , translate ("indices must be integers, slices, or Boolean lists" ));
1055
+ mp_raise_msg (& mp_type_IndexError , MP_ERROR_TEXT ("indices must be integers, slices, or Boolean lists" ));
1056
1056
}
1057
1057
return slice ;
1058
1058
}
@@ -1078,7 +1078,7 @@ static ndarray_obj_t *ndarray_view_from_slices(ndarray_obj_t *ndarray, mp_obj_tu
1078
1078
k += ndarray -> shape [ULAB_MAX_DIMS - ndarray -> ndim + i ];
1079
1079
}
1080
1080
if ((k >= (int32_t )ndarray -> shape [ULAB_MAX_DIMS - ndarray -> ndim + i ]) || (k < 0 )) {
1081
- mp_raise_msg (& mp_type_IndexError , translate ("index is out of bounds" ));
1081
+ mp_raise_msg (& mp_type_IndexError , MP_ERROR_TEXT ("index is out of bounds" ));
1082
1082
}
1083
1083
offset += ndarray -> strides [ULAB_MAX_DIMS - ndarray -> ndim + i ] * k ;
1084
1084
// ... and then we have to shift the shapes to the right
@@ -1105,7 +1105,7 @@ void ndarray_assign_view(ndarray_obj_t *view, ndarray_obj_t *values) {
1105
1105
int32_t * lstrides = m_new0 (int32_t , ULAB_MAX_DIMS );
1106
1106
int32_t * rstrides = m_new0 (int32_t , ULAB_MAX_DIMS );
1107
1107
if (!ndarray_can_broadcast (view , values , & ndim , shape , lstrides , rstrides )) {
1108
- mp_raise_ValueError (translate ("operands could not be broadcast together" ));
1108
+ mp_raise_ValueError (MP_ERROR_TEXT ("operands could not be broadcast together" ));
1109
1109
} else {
1110
1110
1111
1111
ndarray_obj_t * ndarray = ndarray_copy_view_convert_type (values , view -> dtype );
@@ -1171,7 +1171,7 @@ void ndarray_assign_view(ndarray_obj_t *view, ndarray_obj_t *values) {
1171
1171
static mp_obj_t ndarray_from_boolean_index (ndarray_obj_t * ndarray , ndarray_obj_t * index ) {
1172
1172
// returns a 1D array, indexed by a Boolean array
1173
1173
if (ndarray -> len != index -> len ) {
1174
- mp_raise_ValueError (translate ("array and index length must be equal" ));
1174
+ mp_raise_ValueError (MP_ERROR_TEXT ("array and index length must be equal" ));
1175
1175
}
1176
1176
uint8_t * iarray = (uint8_t * )index -> array ;
1177
1177
// first we have to find out how many trues there are
@@ -1223,7 +1223,7 @@ static mp_obj_t ndarray_assign_from_boolean_index(ndarray_obj_t *ndarray, ndarra
1223
1223
#if ULAB_SUPPORTS_COMPLEX
1224
1224
if (values -> dtype == NDARRAY_COMPLEX ) {
1225
1225
if (ndarray -> dtype != NDARRAY_COMPLEX ) {
1226
- mp_raise_TypeError (translate ("cannot convert complex to dtype" ));
1226
+ mp_raise_TypeError (MP_ERROR_TEXT ("cannot convert complex to dtype" ));
1227
1227
} else {
1228
1228
uint8_t * array = (uint8_t * )ndarray -> array ;
1229
1229
for (size_t i = 0 ; i < ndarray -> len ; i ++ ) {
@@ -1314,7 +1314,7 @@ static mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarra
1314
1314
if (mp_obj_is_type (index , & ulab_ndarray_type )) {
1315
1315
ndarray_obj_t * nindex = MP_OBJ_TO_PTR (index );
1316
1316
if ((nindex -> ndim > 1 ) || (nindex -> boolean == false)) {
1317
- mp_raise_NotImplementedError (translate ("operation is implemented for 1D Boolean arrays only" ));
1317
+ mp_raise_NotImplementedError (MP_ERROR_TEXT ("operation is implemented for 1D Boolean arrays only" ));
1318
1318
}
1319
1319
if (values == NULL ) { // return value(s)
1320
1320
return ndarray_from_boolean_index (ndarray , nindex );
@@ -1327,7 +1327,7 @@ static mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarra
1327
1327
if (mp_obj_is_type (index , & mp_type_tuple )) {
1328
1328
tuple = MP_OBJ_TO_PTR (index );
1329
1329
if (tuple -> len > ndarray -> ndim ) {
1330
- mp_raise_msg (& mp_type_IndexError , translate ("too many indices" ));
1330
+ mp_raise_msg (& mp_type_IndexError , MP_ERROR_TEXT ("too many indices" ));
1331
1331
}
1332
1332
} else {
1333
1333
mp_obj_t * items = m_new (mp_obj_t , 1 );
@@ -1351,7 +1351,7 @@ static mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarra
1351
1351
1352
1352
mp_obj_t ndarray_subscr (mp_obj_t self_in , mp_obj_t index , mp_obj_t value ) {
1353
1353
if (value == MP_OBJ_NULL ) {
1354
- mp_raise_ValueError (translate ("cannot delete array elements" ));
1354
+ mp_raise_ValueError (MP_ERROR_TEXT ("cannot delete array elements" ));
1355
1355
}
1356
1356
ndarray_obj_t * self = MP_OBJ_TO_PTR (self_in );
1357
1357
@@ -1429,7 +1429,7 @@ mp_obj_t ndarray_flatten(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
1429
1429
ndarray_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
1430
1430
GET_STR_DATA_LEN (args [0 ].u_obj , order , len );
1431
1431
if ((len != 1 ) || ((memcmp (order , "C" , 1 ) != 0 ) && (memcmp (order , "F" , 1 ) != 0 ))) {
1432
- mp_raise_ValueError (translate ("flattening order must be either 'C', or 'F'" ));
1432
+ mp_raise_ValueError (MP_ERROR_TEXT ("flattening order must be either 'C', or 'F'" ));
1433
1433
}
1434
1434
1435
1435
uint8_t * sarray = (uint8_t * )self -> array ;
@@ -1567,7 +1567,7 @@ mp_obj_t ndarray_tobytes(mp_obj_t self_in) {
1567
1567
// Piping into a bytearray makes sense for dense arrays only,
1568
1568
// so bail out, if that is not the case
1569
1569
if (!ndarray_is_dense (self )) {
1570
- mp_raise_ValueError (translate ("tobytes can be invoked for dense arrays only" ));
1570
+ mp_raise_ValueError (MP_ERROR_TEXT ("tobytes can be invoked for dense arrays only" ));
1571
1571
}
1572
1572
return mp_obj_new_bytearray_by_ref (self -> itemsize * self -> len , self -> array );
1573
1573
}
@@ -1707,7 +1707,7 @@ mp_obj_t ndarray_binary_op(mp_binary_op_t _op, mp_obj_t lobj, mp_obj_t robj) {
1707
1707
broadcastable = ndarray_can_broadcast (lhs , rhs , & ndim , shape , lstrides , rstrides );
1708
1708
}
1709
1709
if (!broadcastable ) {
1710
- mp_raise_ValueError (translate ("operands could not be broadcast together" ));
1710
+ mp_raise_ValueError (MP_ERROR_TEXT ("operands could not be broadcast together" ));
1711
1711
m_del (size_t , shape , ULAB_MAX_DIMS );
1712
1712
m_del (int32_t , lstrides , ULAB_MAX_DIMS );
1713
1713
m_del (int32_t , rstrides , ULAB_MAX_DIMS );
@@ -1917,7 +1917,7 @@ mp_obj_t ndarray_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
1917
1917
#else
1918
1918
if (self -> dtype == NDARRAY_FLOAT ) {
1919
1919
#endif
1920
- mp_raise_ValueError (translate ("operation is not supported for given type" ));
1920
+ mp_raise_ValueError (MP_ERROR_TEXT ("operation is not supported for given type" ));
1921
1921
}
1922
1922
// we can invert the content byte by byte, no need to distinguish between different dtypes
1923
1923
ndarray = ndarray_copy_view (self ); // from this point, this is a dense copy
@@ -2006,7 +2006,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(ndarray_transpose_obj, ndarray_transpose);
2006
2006
mp_obj_t ndarray_reshape_core (mp_obj_t oin , mp_obj_t _shape , bool inplace ) {
2007
2007
ndarray_obj_t * source = MP_OBJ_TO_PTR (oin );
2008
2008
if (!mp_obj_is_type (_shape , & mp_type_tuple ) && !mp_obj_is_int (_shape )) {
2009
- mp_raise_TypeError (translate ("shape must be integer or tuple of integers" ));
2009
+ mp_raise_TypeError (MP_ERROR_TEXT ("shape must be integer or tuple of integers" ));
2010
2010
}
2011
2011
2012
2012
mp_obj_tuple_t * shape ;
@@ -2020,7 +2020,7 @@ mp_obj_t ndarray_reshape_core(mp_obj_t oin, mp_obj_t _shape, bool inplace) {
2020
2020
}
2021
2021
2022
2022
if (shape -> len > ULAB_MAX_DIMS ) {
2023
- mp_raise_ValueError (translate ("maximum number of dimensions is " MP_STRINGIFY (ULAB_MAX_DIMS )));
2023
+ mp_raise_ValueError (MP_ERROR_TEXT ("maximum number of dimensions is " MP_STRINGIFY (ULAB_MAX_DIMS )));
2024
2024
}
2025
2025
2026
2026
size_t new_length = 1 ;
@@ -2040,14 +2040,14 @@ mp_obj_t ndarray_reshape_core(mp_obj_t oin, mp_obj_t _shape, bool inplace) {
2040
2040
}
2041
2041
2042
2042
if (unknown_dim > 1 ) {
2043
- mp_raise_ValueError (translate ("can only specify one unknown dimension" ));
2043
+ mp_raise_ValueError (MP_ERROR_TEXT ("can only specify one unknown dimension" ));
2044
2044
} else if (unknown_dim == 1 ) {
2045
2045
new_shape [unknown_index ] = source -> len / new_length ;
2046
2046
new_length = source -> len ;
2047
2047
}
2048
2048
2049
2049
if (source -> len != new_length ) {
2050
- mp_raise_ValueError (translate ("cannot reshape array" ));
2050
+ mp_raise_ValueError (MP_ERROR_TEXT ("cannot reshape array" ));
2051
2051
}
2052
2052
2053
2053
ndarray_obj_t * ndarray ;
@@ -2064,7 +2064,7 @@ mp_obj_t ndarray_reshape_core(mp_obj_t oin, mp_obj_t _shape, bool inplace) {
2064
2064
}
2065
2065
} else {
2066
2066
if (inplace ) {
2067
- mp_raise_ValueError (translate ("cannot assign new shape" ));
2067
+ mp_raise_ValueError (MP_ERROR_TEXT ("cannot assign new shape" ));
2068
2068
}
2069
2069
if (mp_obj_is_type (_shape , & mp_type_tuple )) {
2070
2070
ndarray = ndarray_new_ndarray_from_tuple (shape , source -> dtype );
@@ -2087,7 +2087,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(ndarray_reshape_obj, ndarray_reshape);
2087
2087
#if ULAB_NUMPY_HAS_NDINFO
2088
2088
mp_obj_t ndarray_info (mp_obj_t obj_in ) {
2089
2089
if (!mp_obj_is_type (obj_in , & ulab_ndarray_type )) {
2090
- mp_raise_TypeError (translate ("function is defined for ndarrays only" ));
2090
+ mp_raise_TypeError (MP_ERROR_TEXT ("function is defined for ndarrays only" ));
2091
2091
}
2092
2092
ndarray_obj_t * ndarray = MP_OBJ_TO_PTR (obj_in );
2093
2093
mp_printf (MP_PYTHON_PRINTER , "class: ndarray\n" );
0 commit comments