# Orthogonal linear system solver tests

from math import sqrt

import numpy as np
from orthogonal import orthogonal


################################################################################
# 2x2 orthogonal matrix
A = np.matrix('1  1;'
              '1 -1', float)
A = A*1.0/sqrt(2.0)
# Known terms vector
b = np.matrix('2; 3')
# Solve the system
x = orthogonal(A, b, 1)
# Check
if np.allclose(b, A*x) == False:
    raise Exception('Orthogonal test failure')

################################################################################

# 2x2 orthogonal matrix
A = np.matrix('2 -2  1;'
              '1  2  2;'
              '2  1 -2', float)
A = A*1.0/3.0
# Known terms vector
b = np.matrix('2; 3; 4')
# Solve the system
x = orthogonal(A, b)
# Check
if np.allclose(b, A*x) == False:
    raise Exception('Orthogonal test failure')
[((11, 4, 12, 28), 'numpy.matrix', 'np.matrix', ({(11, 14, 12, 20): '"""1  1;1 -1"""', (12, 22, 12, 27): 'float'}, {}), "('1  1;1 -1', float)", True, 'import numpy as np\n'), ((15, 4, 15, 21), 'numpy.matrix', 'np.matrix', ({(15, 14, 15, 20): '"""2; 3"""'}, {}), "('2; 3')", True, 'import numpy as np\n'), ((17, 4, 17, 23), 'orthogonal.orthogonal', 'orthogonal', ({(17, 15, 17, 16): 'A', (17, 18, 17, 19): 'b', (17, 21, 17, 22): '1'}, {}), '(A, b, 1)', False, 'from orthogonal import orthogonal\n'), ((25, 4, 27, 31), 'numpy.matrix', 'np.matrix', ({(25, 14, 27, 23): '"""2 -2  1;1  2  2;2  1 -2"""', (27, 25, 27, 30): 'float'}, {}), "('2 -2  1;1  2  2;2  1 -2', float)", True, 'import numpy as np\n'), ((30, 4, 30, 24), 'numpy.matrix', 'np.matrix', ({(30, 14, 30, 23): '"""2; 3; 4"""'}, {}), "('2; 3; 4')", True, 'import numpy as np\n'), ((32, 4, 32, 20), 'orthogonal.orthogonal', 'orthogonal', ({(32, 15, 32, 16): 'A', (32, 18, 32, 19): 'b'}, {}), '(A, b)', False, 'from orthogonal import orthogonal\n'), ((13, 10, 13, 19), 'math.sqrt', 'sqrt', ({(13, 15, 13, 18): '(2.0)'}, {}), '(2.0)', False, 'from math import sqrt\n'), ((19, 3, 19, 22), 'numpy.allclose', 'np.allclose', ({(19, 15, 19, 16): 'b', (19, 18, 19, 21): '(A * x)'}, {}), '(b, A * x)', True, 'import numpy as np\n'), ((34, 3, 34, 22), 'numpy.allclose', 'np.allclose', ({(34, 15, 34, 16): 'b', (34, 18, 34, 21): '(A * x)'}, {}), '(b, A * x)', True, 'import numpy as np\n')]