コード例 #1
0
    def test_torch_tensor(self):

        log("Testing: torch_tensor")
        self.s.x = pymm.torch_tensor((10, ))
        n = torch.Tensor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

        # shelf type S
        self.assertTrue(
            str(type(self.s.x)) ==
            "<class 'pymm.torch_tensor.shelved_torch_tensor'>")

        self.s.x.fill(1)
        self.assertTrue(self.s.x[0] == 1)

        # shelf type S after in-place operation
        self.assertTrue(
            str(type(self.s.x)) ==
            "<class 'pymm.torch_tensor.shelved_torch_tensor'>")

        # shelf type S * NS (non-shelf type)
        self.assertTrue(str(type(self.s.x * n)) == "<class 'torch.Tensor'>")

        # shelf type NS * S
        self.assertTrue(str(type(n * self.s.x)) == "<class 'torch.Tensor'>")

        # shelf type S * shelf type S
        self.assertTrue(
            str(type(self.s.x * self.s.x)) == "<class 'torch.Tensor'>")

        self.s.x += 1
        self.s.x *= 2
        self.s.x -= 0.4
        self.s.x /= 2

        self.s.erase('x')
        log("Testing: torch_tensor OK")
コード例 #2
0
    def test_torch_tensor(self):
        log("Testing: torch.tensor RHS ...")
        self.s.w = torch.tensor((100, 100, 100), dtype=torch.uint8)
        self.s.w = torch.tensor([2, 2, 2], dtype=torch.uint8)
        w = torch.tensor([2, 2, 2], dtype=torch.uint8)
        self.s.w.fill_(9)
        w.fill_(9)
        print("self.s.w = {}".format(self.s.w))
        print("w = {}".format(w))
        self.assertTrue(torch.equal(self.s.w, w))

        log("Testing: pymm.ndarray RHS ...")
        #self.s.x = pymm.torch_tensor((100,100,100),dtype=torch.uint8)

        self.s.x = pymm.torch_tensor([[1, 1, 1, 1], [2, 2, 2, 2]],
                                     dtype=torch.uint8)
        x = torch.tensor([[1, 1, 1, 1], [2, 2, 2, 2]], dtype=torch.uint8)

        print("self.s.x =\n {}".format(self.s.x))
        print("x =\n {}".format(x))

        self.assertTrue(torch.equal(self.s.x, x))

        log("Testing: ndarray OK!")
コード例 #3
0
ファイル: tensors.py プロジェクト: IBM/mcas
 def test_torch_tensor_shadow_ndarray_B(self):
     log("Testing: tensor ctor")
     print(shelf.y)
     shelf.y = pymm.torch_tensor(np.arange(0,10))
     shelf.y.fill(-1.3)
     print(shelf.y)
コード例 #4
0
ファイル: tensors.py プロジェクト: IBM/mcas
 def test_torch_zerodim_shadow(self):
     log("Testing: zero dim shadow")
     shelf.x = pymm.torch_tensor(1.0)
     self.assertTrue(shelf.x.dim() == 0)
     print(type(shelf.x))
     self.assertTrue(str(type(shelf.x)) == "<class 'pymm.torch_tensor.shelved_torch_tensor'>")
コード例 #5
0
ファイル: tensors.py プロジェクト: IBM/mcas
 def test_torch_tensor_shadow_list(self):
     log("Testing: tensor ctor")
     shelf.x = pymm.torch_tensor([1,1,1,1,1])
     print(shelf.x)