MCPcopy Create free account
hub / github.com/pytorch/pytorch / test_splits_generator

Method test_splits_generator

test/test_dataloader.py:238–253  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

236 random_split([1, 2, 3, 4], [1.1])
237
238 def test_splits_generator(self):
239 # A random_split without a specific generator should affect the default one
240 state = torch.get_rng_state()
241 a = torch.rand(10)
242 torch.set_rng_state(state)
243 random_split(range(10), [5, 5])
244 b = torch.rand(10)
245 self.assertNotEqual(a, b)
246
247 # A random_split with a specific generator should not affect the default one
248 state = torch.get_rng_state()
249 a = torch.rand(10)
250 torch.set_rng_state(state)
251 random_split(range(10), [5, 5], generator=torch.Generator().manual_seed(42))
252 b = torch.rand(10)
253 self.assertEqual(a, b)
254
255 def test_slicing_of_subset_of_dataset(self):
256 # Testing slicing a subset initialized with a dataset

Callers

nothing calls this directly

Calls 7

random_splitFunction · 0.90
get_rng_stateMethod · 0.80
set_rng_stateMethod · 0.80
assertNotEqualMethod · 0.80
rangeFunction · 0.50
randMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected