我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用torch.DoubleStorage()。
def __init__(self, ): super(MultiCriterion, self).__init__() self.criterions = [] self.weights = torch.DoubleStorage()
def add(self, criterion, weight=1): self.criterions.append(criterion) new_weights = torch.DoubleStorage(len(self.criterions)) for i, v in enumerate(self.weights): new_weights[i] = v new_weights[len(self.criterions)-1] = weight self.weights = new_weights return self
def test_fs(self): with fs_sharing(), leak_checker(self) as lc: x = torch.DoubleStorage(4) q = mp.Queue() self.assertFalse(lc.has_shm_files()) q.put(x) self.assertTrue(lc.has_shm_files(wait=False)) q.get() del x del q # We have to clean up fds for leak_checker
def test_element_size(self): byte = torch.ByteStorage().element_size() char = torch.CharStorage().element_size() short = torch.ShortStorage().element_size() int = torch.IntStorage().element_size() long = torch.LongStorage().element_size() float = torch.FloatStorage().element_size() double = torch.DoubleStorage().element_size() self.assertEqual(byte, torch.ByteTensor().element_size()) self.assertEqual(char, torch.CharTensor().element_size()) self.assertEqual(short, torch.ShortTensor().element_size()) self.assertEqual(int, torch.IntTensor().element_size()) self.assertEqual(long, torch.LongTensor().element_size()) self.assertEqual(float, torch.FloatTensor().element_size()) self.assertEqual(double, torch.DoubleTensor().element_size()) self.assertGreater(byte, 0) self.assertGreater(char, 0) self.assertGreater(short, 0) self.assertGreater(int, 0) self.assertGreater(long, 0) self.assertGreater(float, 0) self.assertGreater(double, 0) # These tests are portable, not necessarily strict for your system. self.assertEqual(byte, 1) self.assertEqual(char, 1) self.assertGreaterEqual(short, 2) self.assertGreaterEqual(int, 2) self.assertGreaterEqual(int, short) self.assertGreaterEqual(long, 4) self.assertGreaterEqual(long, int) self.assertGreaterEqual(double, float)
def add(self, criterion, weight=1): self.criterions.append(criterion) new_weights = torch.DoubleStorage(len(self.criterions)) for i, v in enumerate(self.weights): new_weights[i] = v new_weights[len(self.criterions) - 1] = weight self.weights = new_weights return self
def test_fs(self): def queue_put(): x = torch.DoubleStorage(4) q = mp.Queue() self.assertFalse(lc.has_shm_files()) q.put(x) time.sleep(0.05) # queue serializes asynchronously self.assertTrue(lc.has_shm_files(wait=False)) q.get() with fs_sharing(), leak_checker(self) as lc: for _ in range(TEST_REPEATS): queue_put()