Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def sample_std_normal(thread_id, shape, dtype):
# create a thread-specifc RNG
rng = randomgen.RandomGenerator(
randomgen.Xoroshiro128(seed=20 + thread_id)
)
t = threading.currentThread()
while getattr(t, "do_run", True):
rnd_normal = rng.standard_normal(size=shape, dtype=dtype)
rnd_normal_queue.put(rnd_normal)
"ThreeFry",
]
if prng not in allowed_prngs:
raise ValueError(f"prng={prng} is not in {allowed_prngs}")
arr = np.zeros((size, size))
for i in range(size):
if prng == "python":
random.seed(i)
elif prng == "numpy":
np.random.seed(i)
elif prng == "java":
rnd = javarandom.Random(i)
elif prng == "Xoroshiro128":
rnd = RandomGenerator(Xoroshiro128())
elif prng == "Xorshift1024":
rnd = RandomGenerator(Xorshift1024())
elif prng == "ThreeFry":
rnd = RandomGenerator(ThreeFry())
elif prng == "MT19937":
rnd = Generator(MT19937())
elif prng == "Philox":
rnd = Generator(Philox())
elif prng == "SFC64":
rnd = Generator(SFC64())
for j in range(size):
if prng == "python":
random_number = random.random()
elif prng == "numpy":
random_number = np.random.random()
elif prng == "java":
random_number = rnd.nextDouble()
spherical_step,
source_step,
internal_dtype,
rng=None,
):
if rng is None:
try:
import randomgen
except ImportError: # pragma: no cover
raise ImportError(
"To use the BoundaryAttack,"
" please install the randomgen"
" module (e.g. pip install randomgen)"
)
rng = randomgen.RandomGenerator()
# ===========================================================
# perform initial work
# ===========================================================
assert original.dtype == internal_dtype
assert perturbed.dtype == internal_dtype
shape = original.shape
min_, max_ = bounds
# ===========================================================
# draw a random direction
# ===========================================================
spherical_step,
source_step,
internal_dtype,
rng=None,
):
if rng is None:
try:
import randomgen
except ImportError: # pragma: no cover
raise ImportError(
"To use the BoundaryAttack,"
" please install the randomgen"
" module (e.g. pip install randomgen)"
)
rng = randomgen.RandomGenerator()
# ===========================================================
# perform initial work
# ===========================================================
assert original.dtype == internal_dtype
assert perturbed.dtype == internal_dtype
shape = original.shape
min_, max_ = bounds
# ===========================================================
# draw a random direction
# ===========================================================
spherical_step,
source_step,
internal_dtype,
rng=None,
):
if rng is None:
try:
import randomgen
except ImportError: # pragma: no cover
raise ImportError(
"To use the BoundaryAttack,"
" please install the randomgen"
" module (e.g. pip install randomgen)"
)
rng = randomgen.RandomGenerator()
# ===========================================================
# perform initial work
# ===========================================================
assert original.dtype == internal_dtype
assert perturbed.dtype == internal_dtype
shape = original.shape
min_, max_ = bounds
# ===========================================================
# draw a random direction
# ===========================================================
spherical_step,
source_step,
internal_dtype,
rng=None,
):
if rng is None:
try:
import randomgen
except ImportError: # pragma: no cover
raise ImportError(
"To use the BoundaryAttack,"
" please install the randomgen"
" module (e.g. pip install randomgen)"
)
rng = randomgen.RandomGenerator()
# ===========================================================
# perform initial work
# ===========================================================
assert original.dtype == internal_dtype
assert perturbed.dtype == internal_dtype
shape = original.shape
min_, max_ = bounds
# ===========================================================
# draw a random direction
# ===========================================================