Skip to content

Commit 1d3ddd8

Browse files
authored
numpy/random.c: fix use of MICROPY_PY_RANDOM_SEED_INIT_FUNC (#684)
1 parent a77022d commit 1d3ddd8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

code/numpy/random/random.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
4141
MP_QSTR_generator,
4242
MP_TYPE_FLAG_NONE,
4343
print, random_generator_print,
44-
make_new, random_generator_make_new,
44+
make_new, random_generator_make_new,
4545
locals_dict, &random_generator_locals_dict
4646
);
4747
#else
@@ -76,11 +76,12 @@ mp_obj_t random_generator_make_new(const mp_obj_type_t *type, size_t n_args, siz
7676
if(args[0] == mp_const_none) {
7777
#ifndef MICROPY_PY_RANDOM_SEED_INIT_FUNC
7878
mp_raise_ValueError(MP_ERROR_TEXT("no default seed"));
79-
#endif
79+
#else
8080
random_generator_obj_t *generator = m_new_obj(random_generator_obj_t);
8181
generator->base.type = &random_generator_type;
8282
generator->state = MICROPY_PY_RANDOM_SEED_INIT_FUNC;
8383
return MP_OBJ_FROM_PTR(generator);
84+
#endif
8485
} else if(mp_obj_is_int(args[0])) {
8586
random_generator_obj_t *generator = m_new_obj(random_generator_obj_t);
8687
generator->base.type = &random_generator_type;
@@ -89,7 +90,7 @@ mp_obj_t random_generator_make_new(const mp_obj_type_t *type, size_t n_args, siz
8990
} else if(mp_obj_is_type(args[0], &mp_type_tuple)){
9091
mp_obj_tuple_t *seeds = MP_OBJ_TO_PTR(args[0]);
9192
mp_obj_t *items = m_new(mp_obj_t, seeds->len);
92-
93+
9394
for(uint8_t i = 0; i < seeds->len; i++) {
9495
random_generator_obj_t *generator = m_new_obj(random_generator_obj_t);
9596
generator->base.type = &random_generator_type;
@@ -175,7 +176,7 @@ static mp_obj_t random_normal(size_t n_args, const mp_obj_t *pos_args, mp_map_t
175176

176177
mp_float_t *array = (mp_float_t *)ndarray->array;
177178

178-
// numpy's random supports only dense output arrays, so we can simply
179+
// numpy's random supports only dense output arrays, so we can simply
179180
// loop through the elements in a linear fashion
180181
for(size_t i = 0; i < ndarray->len; i = i + 2) {
181182
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
@@ -248,7 +249,7 @@ static mp_obj_t random_random(size_t n_args, const mp_obj_t *pos_args, mp_map_t
248249
if(!mp_obj_is_type(out, &ulab_ndarray_type)) {
249250
mp_raise_TypeError(MP_ERROR_TEXT("out has wrong type"));
250251
}
251-
252+
252253
ndarray = MP_OBJ_TO_PTR(out);
253254

254255
if(ndarray->dtype != NDARRAY_FLOAT) {
@@ -283,10 +284,10 @@ static mp_obj_t random_random(size_t n_args, const mp_obj_t *pos_args, mp_map_t
283284

284285
mp_float_t *array = (mp_float_t *)ndarray->array;
285286

286-
// numpy's random supports only dense output arrays, so we can simply
287+
// numpy's random supports only dense output arrays, so we can simply
287288
// loop through the elements in a linear fashion
288289
for(size_t i = 0; i < ndarray->len; i++) {
289-
290+
290291
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
291292
uint32_t x = pcg32_next(&self->state);
292293
*array = (float)(int32_t)(x >> 8) * 0x1.0p-24f;
@@ -375,4 +376,3 @@ const mp_obj_module_t ulab_numpy_random_module = {
375376
.base = { &mp_type_module },
376377
.globals = (mp_obj_dict_t*)&mp_module_ulab_numpy_random_globals,
377378
};
378-

0 commit comments

Comments
 (0)