예제 #1
0
def test_shape_tuple():
    tensor = np.ones([3, 5, 2])
    np_result = numpy_backend.NumPyBackend().shape_tuple(tensor)
    sh_result = shell_backend.ShellBackend().shape_tuple(tensor)
    assert np_result == sh_result
예제 #2
0
def test_eye_dtype(dtype):
    backend = numpy_backend.NumPyBackend()
    a = backend.eye(N=4, M=4, dtype=dtype)
    assert a.dtype == dtype
예제 #3
0
def test_random_uniform_dtype(dtype):
    backend = numpy_backend.NumPyBackend()
    a = backend.random_uniform((4, 4), dtype=dtype, seed=10)
    assert a.dtype == dtype
예제 #4
0
def test_eye(dtype):
    backend = numpy_backend.NumPyBackend()
    a = backend.eye(N=4, M=5, dtype=dtype)
    np.testing.assert_allclose(np.eye(N=4, M=5, dtype=dtype), a)
예제 #5
0
def test_randn(dtype):
    backend = numpy_backend.NumPyBackend()
    a = backend.randn((4, 4), dtype=dtype, seed=10)
    assert a.shape == (4, 4)
def test_trace():
  backend = numpy_backend.NumPyBackend()
  a = backend.convert_to_tensor(np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]))
  actual = backend.trace(a)
  np.testing.assert_allclose(actual, 6)
예제 #7
0
def test_convert_bad_test():
    backend = numpy_backend.NumPyBackend()
    with pytest.raises(TypeError):
        backend.convert_to_tensor(tf.ones((2, 2)))
예제 #8
0
def test_zeros_dtype(dtype):
    backend = numpy_backend.NumPyBackend(dtype=dtype)
    dtype_2 = np.float32
    a = backend.zeros((4, 4), dtype=dtype_2)
    assert a.dtype == dtype_2
예제 #9
0
def test_randn_dtype(dtype):
    backend = numpy_backend.NumPyBackend(dtype=dtype)
    dtype_2 = np.float32
    a = backend.randn((4, 4), dtype=dtype_2)
    assert a.dtype == dtype_2
예제 #10
0
def test_randn_non_zero_imag(dtype):
    backend = numpy_backend.NumPyBackend(dtype=dtype)
    a = backend.randn((4, 4))
    assert np.linalg.norm(np.imag(a)) != 0.0
예제 #11
0
def test_eye_dtype(dtype):
    backend = numpy_backend.NumPyBackend(dtype=dtype)
    dtype_2 = np.float32
    a = backend.eye(N=4, M=4, dtype=dtype_2)
    assert a.dtype == dtype_2
예제 #12
0
def test_randn(dtype):
    backend = numpy_backend.NumPyBackend(dtype=dtype)
    a = backend.randn((4, 4))
    assert a.shape == (4, 4)
예제 #13
0
def test_ones(dtype):
    backend = numpy_backend.NumPyBackend(dtype=dtype)
    a = backend.ones((4, 4))
    np.testing.assert_allclose(np.ones((4, 4), dtype=dtype), a)
예제 #14
0
def test_zeros_dtype_2(dtype):
    dtype = np.float32
    backend = numpy_backend.NumPyBackend(dtype=dtype)
    a = backend.zeros((4, 4))
    assert a.dtype == dtype
def test_shape_tuple():
  backend = numpy_backend.NumPyBackend()
  a = backend.convert_to_tensor(np.ones([2, 3, 4]))
  actual = backend.shape_tuple(a)
  assert actual == (2, 3, 4)
예제 #16
0
def test_ones_dtype_2(dtype):
    backend = numpy_backend.NumPyBackend(dtype=dtype)
    a = backend.ones((4, 4))
    assert a.dtype == dtype
def test_prod():
  backend = numpy_backend.NumPyBackend()
  a = backend.convert_to_tensor(2 * np.ones([1, 2, 3, 4]))
  actual = np.array(backend.prod(a))
  assert actual == 2**24
예제 #18
0
def test_randn_dtype_2(dtype):
    backend = numpy_backend.NumPyBackend(dtype=dtype)
    a = backend.randn((4, 4))
    assert a.dtype == dtype
예제 #19
0
def test_sqrt():
    backend = numpy_backend.NumPyBackend()
    a = backend.convert_to_tensor(np.array([4., 9.]))
    actual = backend.sqrt(a)
    expected = np.array([2, 3])
    np.testing.assert_allclose(expected, actual)
예제 #20
0
def test_backend_dtype_exception():
    backend = numpy_backend.NumPyBackend(dtype=np.float32)
    tensor = np.random.rand(2, 2, 2)
    with pytest.raises(TypeError):
        _ = backend.convert_to_tensor(tensor)
예제 #21
0
def test_norm():
    backend = numpy_backend.NumPyBackend()
    a = backend.convert_to_tensor(np.ones((2, 2)))
    assert backend.norm(a) == 2
def test_reshape():
  backend = numpy_backend.NumPyBackend()
  a = backend.convert_to_tensor(np.ones((2, 3, 4)))
  actual = backend.shape_tuple(backend.reshape(a, np.array((6, 4, 1))))
  assert actual == (6, 4, 1)
예제 #23
0
def test_zeros(dtype):
    backend = numpy_backend.NumPyBackend()
    a = backend.zeros((4, 4), dtype=dtype)
    np.testing.assert_allclose(np.zeros((4, 4), dtype=dtype), a)
def test_multiply(a, b, expected):
  backend = numpy_backend.NumPyBackend()
  tensor1 = backend.convert_to_tensor(a)
  tensor2 = backend.convert_to_tensor(b)

  np.testing.assert_allclose(backend.multiply(tensor1, tensor2), expected)
예제 #25
0
def test_random_uniform_non_zero_imag(dtype):
    backend = numpy_backend.NumPyBackend()
    a = backend.random_uniform((4, 4), dtype=dtype, seed=10)
    assert np.linalg.norm(np.imag(a)) != 0.0
def test_index_update(dtype):
  backend = numpy_backend.NumPyBackend()
  tensor = backend.randn((4, 2, 3), dtype=dtype, seed=10)
  out = backend.index_update(tensor, tensor > 0.1, 0)
  tensor[tensor > 0.1] = 0.0
  np.testing.assert_allclose(tensor, out)
예제 #27
0
def test_zeros_dtype(dtype):
    backend = numpy_backend.NumPyBackend()
    a = backend.zeros((4, 4), dtype=dtype)
    assert a.dtype == dtype
def test_matrix_inv_raises(dtype):
  backend = numpy_backend.NumPyBackend()
  matrix = backend.randn((4, 4, 4), dtype=dtype, seed=10)
  with pytest.raises(ValueError):
    backend.inv(matrix)
예제 #29
0
def test_randn_seed(dtype):
    backend = numpy_backend.NumPyBackend()
    a = backend.randn((4, 4), seed=10, dtype=dtype)
    b = backend.randn((4, 4), seed=10, dtype=dtype)
    np.testing.assert_allclose(a, b)
예제 #30
0
def test_svd_decomposition():
    tensor = np.ones([2, 3, 4, 5, 6])
    np_res = numpy_backend.NumPyBackend().svd_decomposition(tensor, 3)
    sh_res = shell_backend.ShellBackend().svd_decomposition(tensor, 3)
    for x, y in zip(np_res, sh_res):
        assert x.shape == y.shape