コード例 #1
0
def test_matrix_inv():
    A = D.array([
        [-1.0, 3 / 2],
        [1.0, -1.0],
    ], dtype=D.float64)
    Ainv = D.matrix_inv(A)
    assert (D.max(D.abs(D.to_float(Ainv @ A - D.eye(2)))) <= 8 * D.epsilon())
コード例 #2
0
def test_matrix_inv_bigger():
    for diag_size in range(2, 101):
        np.random.seed(15)
        for trial in range(3):
            A = np.random.normal(size=(diag_size, diag_size))
            while np.abs(np.linalg.det(D.to_float(A))) <= 1e-5:
                A = np.random.normal(size=(diag_size, diag_size), std=250.0)
            A = D.array(D.cast_to_float_fmt(A))
            Ainv = D.matrix_inv(A)
            assert (
                D.max(D.abs(D.to_float(Ainv @ A - D.eye(diag_size)))) <=
                4 * D.epsilon()**0.5
            ), "Matrix inversion failed for diagonal with size: " + str(
                diag_size)
コード例 #3
0
 def do(self, A):
     Ainv = D.matrix_inv(A)
     assert (D.max(D.abs(D.to_float(Ainv @ A - D.eye(A.shape[0])))) <=
             256 * D.epsilon())
コード例 #4
0
 def do(self, A):
     with pytest.raises(np.linalg.LinAlgError):
         D.matrix_inv(D.zeros((2, 3)))
     with pytest.raises(np.linalg.LinAlgError):
         D.matrix_inv(D.zeros((5, 2, 3)))
コード例 #5
0
def test_matrix_inv_exceptions():
    with pytest.raises(np.linalg.LinAlgError):
        D.matrix_inv(D.zeros((2, 3), dtype=D.float64))
    with pytest.raises(np.linalg.LinAlgError):
        D.matrix_inv(D.zeros((5, 2, 3), dtype=D.float64))