コード例 #1
0
ファイル: test_functions.py プロジェクト: sphkthnch/pennylane
    def test_convert_tensor_like(self, t1, t2):
        """Test that converting t1 like t2 results in t1 being cast to the same tensor type as t2"""
        res = fn.convert_like(t1, t2)

        # if tensorflow or pytorch, extract view of underlying data
        if hasattr(res, "numpy"):
            res = res.numpy()

        if hasattr(t2, "numpy"):
            t2 = t2.numpy()

        assert fn.allequal(res, t1)
        assert isinstance(res, np.ndarray if isinstance(t2, (list, tuple)) else t2.__class__)
コード例 #2
0
 def test_convert_scalar(self, t_like):
     """Test that a python scalar is converted to a scalar tensor"""
     res = fn.convert_like(5, t_like)
     assert isinstance(res, t_like.__class__)
     assert res.ndim == 0
     assert fn.allequal(res, [5])