@@ -57,7 +57,7 @@ const mp_obj_type_t random_generator_type = {
57
57
void random_generator_print (const mp_print_t * print , mp_obj_t self_in , mp_print_kind_t kind ) {
58
58
(void )kind ;
59
59
random_generator_obj_t * self = MP_OBJ_TO_PTR (self_in );
60
- mp_printf (MP_PYTHON_PRINTER , "Gnerator () at 0x%p" , self );
60
+ mp_printf (MP_PYTHON_PRINTER , "Generator () at 0x%p" , self );
61
61
}
62
62
63
63
mp_obj_t random_generator_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * args ) {
@@ -149,12 +149,9 @@ static mp_obj_t random_normal(size_t n_args, const mp_obj_t *pos_args, mp_map_t
149
149
ndarray = ndarray_new_linear_array ((size_t )mp_obj_get_int (size ), NDARRAY_FLOAT );
150
150
} else if (mp_obj_is_type (size , & mp_type_tuple )) {
151
151
mp_obj_tuple_t * _shape = MP_OBJ_TO_PTR (size );
152
- if (_shape -> len > ULAB_MAX_DIMS ) {
153
- mp_raise_ValueError (MP_ERROR_TEXT ("maximum number of dimensions is " MP_STRINGIFY (ULAB_MAX_DIMS )));
154
- }
155
152
ndarray = ndarray_new_ndarray_from_tuple (_shape , NDARRAY_FLOAT );
156
153
} else { // input type not supported
157
- mp_raise_TypeError (MP_ERROR_TEXT ("shape must be None, and integer or a tuple of integers" ));
154
+ mp_raise_TypeError (MP_ERROR_TEXT ("shape must be None, an integer or a tuple of integers" ));
158
155
}
159
156
} else {
160
157
// return single value
@@ -221,27 +218,16 @@ static mp_obj_t random_random(size_t n_args, const mp_obj_t *pos_args, mp_map_t
221
218
mp_obj_t out = args [2 ].u_obj ;
222
219
223
220
ndarray_obj_t * ndarray = NULL ;
224
- size_t * shape = m_new (size_t , ULAB_MAX_DIMS );
225
- uint8_t ndim = 1 ;
221
+ size_t * shape = m_new0 (size_t , ULAB_MAX_DIMS );
226
222
227
223
if (size != mp_const_none ) {
228
224
if (mp_obj_is_int (size )) {
229
225
shape [ULAB_MAX_DIMS - 1 ] = (size_t )mp_obj_get_int (size );
230
226
} else if (mp_obj_is_type (size , & mp_type_tuple )) {
231
227
mp_obj_tuple_t * _shape = MP_OBJ_TO_PTR (size );
232
- if (_shape -> len > ULAB_MAX_DIMS ) {
233
- mp_raise_ValueError (MP_ERROR_TEXT ("maximum number of dimensions is " MP_STRINGIFY (ULAB_MAX_DIMS )));
234
- }
235
- ndim = _shape -> len ;
236
- for (size_t i = 0 ; i < ULAB_MAX_DIMS ; i ++ ) {
237
- if (i >= ndim ) {
238
- shape [ULAB_MAX_DIMS - 1 - i ] = 0 ;
239
- } else {
240
- shape [ULAB_MAX_DIMS - 1 - i ] = mp_obj_get_int (_shape -> items [i ]);
241
- }
242
- }
228
+ ndarray = ndarray_new_ndarray_from_tuple (_shape , NDARRAY_FLOAT );
243
229
} else { // input type not supported
244
- mp_raise_TypeError (MP_ERROR_TEXT ("shape must be None, and integer or a tuple of integers" ));
230
+ mp_raise_TypeError (MP_ERROR_TEXT ("shape must be None, an integer or a tuple of integers" ));
245
231
}
246
232
}
247
233
@@ -267,7 +253,8 @@ static mp_obj_t random_random(size_t n_args, const mp_obj_t *pos_args, mp_map_t
267
253
}
268
254
} else { // out == None
269
255
if (size != mp_const_none ) {
270
- ndarray = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
256
+ mp_obj_tuple_t * _shape = MP_OBJ_TO_PTR (size );
257
+ ndarray = ndarray_new_ndarray_from_tuple (_shape , NDARRAY_FLOAT );
271
258
} else {
272
259
// return single value
273
260
mp_float_t value ;
@@ -336,13 +323,9 @@ static mp_obj_t random_uniform(size_t n_args, const mp_obj_t *pos_args, mp_map_t
336
323
return mp_obj_new_float (value );
337
324
} else if (mp_obj_is_type (size , & mp_type_tuple )) {
338
325
mp_obj_tuple_t * _shape = MP_OBJ_TO_PTR (size );
339
- // TODO: this could be reduced, if the inspection was in the ndarray_new_ndarray_from_tuple function
340
- if (_shape -> len > ULAB_MAX_DIMS ) {
341
- mp_raise_ValueError (MP_ERROR_TEXT ("maximum number of dimensions is " MP_STRINGIFY (ULAB_MAX_DIMS )));
342
- }
343
326
ndarray = ndarray_new_ndarray_from_tuple (_shape , NDARRAY_FLOAT );
344
327
} else { // input type not supported
345
- mp_raise_TypeError (MP_ERROR_TEXT ("shape must be None, and integer or a tuple of integers" ));
328
+ mp_raise_TypeError (MP_ERROR_TEXT ("shape must be None, an integer or a tuple of integers" ));
346
329
}
347
330
348
331
mp_float_t * array = (mp_float_t * )ndarray -> array ;
0 commit comments