# 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')
[((228, 257), 'numpy.matrix', 'np.matrix', (['"""1  1;1 -1"""', 'float'], {}), "('1  1;1 -1', float)\n", (237, 257), True, 'import numpy as np\n'), ((320, 337), 'numpy.matrix', 'np.matrix', (['"""2; 3"""'], {}), "('2; 3')\n", (329, 337), True, 'import numpy as np\n'), ((361, 380), 'orthogonal.orthogonal', 'orthogonal', (['A', 'b', '(1)'], {}), '(A, b, 1)\n', (371, 380), False, 'from orthogonal import orthogonal\n'), ((580, 623), 'numpy.matrix', 'np.matrix', (['"""2 -2  1;1  2  2;2  1 -2"""', 'float'], {}), "('2 -2  1;1  2  2;2  1 -2', float)\n", (589, 623), True, 'import numpy as np\n'), ((697, 717), 'numpy.matrix', 'np.matrix', (['"""2; 3; 4"""'], {}), "('2; 3; 4')\n", (706, 717), True, 'import numpy as np\n'), ((741, 757), 'orthogonal.orthogonal', 'orthogonal', (['A', 'b'], {}), '(A, b)\n', (751, 757), False, 'from orthogonal import orthogonal\n'), ((285, 294), 'math.sqrt', 'sqrt', (['(2.0)'], {}), '(2.0)\n', (289, 294), False, 'from math import sqrt\n'), ((392, 413), 'numpy.allclose', 'np.allclose', (['b', '(A * x)'], {}), '(b, A * x)\n', (403, 413), True, 'import numpy as np\n'), ((769, 790), 'numpy.allclose', 'np.allclose', (['b', '(A * x)'], {}), '(b, A * x)\n', (780, 790), True, 'import numpy as np\n')]