def test_get_random_args(self, args, num, bounds): """Tests the utility ``_get_random_args`` using a fixed seed.""" torch = pytest.importorskip("torch") seed = 921 rnd_args = _get_random_args(args, self.interface, num, seed, bounds) assert len(rnd_args) == num torch.random.manual_seed(seed) for _rnd_args in rnd_args: expected = tuple( torch.rand(np.shape(arg)) * (bounds[1] - bounds[0]) + bounds[0] for arg in args ) assert all(np.allclose(_exp, _rnd) for _exp, _rnd in zip(expected, _rnd_args))
def test_get_random_args(self, args, num, bounds): """Tests the utility ``_get_random_args`` using a fixed seed.""" tf = pytest.importorskip("tensorflow") seed = 921 rnd_args = _get_random_args(args, self.interface, num, seed, bounds) assert len(rnd_args) == num tf.random.set_seed(seed) for _rnd_args in rnd_args: expected = tuple( tf.random.uniform(tf.shape(arg)) * (bounds[1] - bounds[0]) + bounds[0] for arg in args ) expected = tuple( tf.Variable(_exp) if isinstance(_arg, tf.Variable) else _exp for _arg, _exp in zip(args, expected) ) assert all(np.allclose(_exp, _rnd) for _exp, _rnd in zip(expected, _rnd_args))