Exemple #1
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
Exemple #2
0
def test_concat_shape():
    shapes = [(5, 2), (3, ), (4, 6)]
    result = shell_backend.ShellBackend().concat_shape(shapes)
    assert result == (5, 2, 3, 4, 6)
Exemple #3
0
def test_prod():
    result = shell_backend.ShellBackend().prod(np.ones([3, 5, 2]))
    assert result == 30
Exemple #4
0
def assertBackendsAgree(f, args):
    np_result = getattr(numpy_backend.NumPyBackend(), f)(**args)
    sh_result = getattr(shell_backend.ShellBackend(), f)(**args)
    assert np_result.shape == sh_result.shape
def test_sparse_shape():
    backend = shell_backend.ShellBackend()
    tensor = backend.randn((2, 3, 4), seed=10)
    np.testing.assert_allclose(backend.sparse_shape(tensor), tensor.shape)
Exemple #6
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
def test_broadcast_left_multiplication():
    backend = shell_backend.ShellBackend()
    tensor1 = backend.randn((3, ))
    tensor2 = backend.randn((3, 4, 2))
    out = backend.broadcast_left_multiplication(tensor1, tensor2)
    np.testing.assert_allclose(out.shape, [3, 4, 2])
def test_broadcast_left_multiplication_raises():
    backend = shell_backend.ShellBackend()
    tensor1 = backend.randn((3, 3))
    tensor2 = backend.randn((3, 4, 2))
    with pytest.raises(ValueError):
        backend.broadcast_left_multiplication(tensor1, tensor2)
def test_matrix_inv_raises():
    backend = shell_backend.ShellBackend()
    matrix = backend.randn((4, 4, 4), seed=10)
    with pytest.raises(ValueError):
        backend.inv(matrix)
def test_matrix_inv():
    backend = shell_backend.ShellBackend()
    matrix = backend.randn((4, 4), seed=10)
    inverse = backend.inv(matrix)
    assert inverse.shape == matrix.shape
def index_update():
    backend = shell_backend.ShellBackend()
    tensor_1 = np.ones([2, 3, 4])
    tensor_2 = backend.index_update(tensor_1, tensor_1 > 0.1, 0)
    assert tensor_1.shape == tensor_2.shape
def test_eigh():
    matrix = np.ones([3, 3])
    vals, vecs = shell_backend.ShellBackend().eigh(matrix)
    assert vals.shape == (3, )
    assert vecs.shape == (3, 3)
def test_einsum():
  expression = "ab,bc->ac"
  tensor1, tensor2 = np.ones([5, 3]), np.ones([3, 6])
  np_result = numpy_backend.NumPyBackend().einsum(expression, tensor1, tensor2)
  sh_result = shell_backend.ShellBackend().einsum(expression, tensor1, tensor2)
  assert np_result.shape == sh_result.shape