doc: set seed

This commit is contained in:
lzhengning 2021-07-02 12:09:17 +08:00
parent 7a253e4a4a
commit 3a5a78544f
2 changed files with 20 additions and 0 deletions

View File

@ -1044,6 +1044,13 @@ def randperm(n, dtype="int32"):
return index.cast(dtype)
def set_global_seed(seed):
''' Sets the seeds of the random number generators of Python, numpy and jittor,
simultaneously.
.. note::
Jittor also gurantees each worker of jittor.dataset.Dataset to hold a different seed,
which is global_seed ^ worker_id ^ 1234.
'''
import random
random.seed(seed)
jt.set_seed(seed)

View File

@ -13,8 +13,21 @@ namespace jittor {
typedef void (*set_seed_callback)(int);
void init();
/**
Sets the seed of jittor random number generator. Also see @jittor.set_global_seed.
----------------
* [in] seed: a python number.
*/
// @pyjt(set_seed, seed)
void set_seed(int seed);
/**
Returns the seed of jittor random number generator.
*/
// @pyjt(get_seed)
int get_seed();