# 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, 'numpy.matrix', 'np.matrix', (['"""1  1;1 -1"""', 'float'], {}), True, 'import numpy as np\n'), (15, 'numpy.matrix', 'np.matrix', (['"""2; 3"""'], {}), True, 'import numpy as np\n'), (17, 'orthogonal.orthogonal', 'orthogonal', (['A', 'b', '(1)'], {}), False, 'from orthogonal import orthogonal\n'), (25, 'numpy.matrix', 'np.matrix', (['"""2 -2  1;1  2  2;2  1 -2"""', 'float'], {}), True, 'import numpy as np\n'), (30, 'numpy.matrix', 'np.matrix', (['"""2; 3; 4"""'], {}), True, 'import numpy as np\n'), (32, 'orthogonal.orthogonal', 'orthogonal', (['A', 'b'], {}), False, 'from orthogonal import orthogonal\n'), (13, 'math.sqrt', 'sqrt', (['(2.0)'], {}), False, 'from math import sqrt\n'), (19, 'numpy.allclose', 'np.allclose', (['b', '(A * x)'], {}), True, 'import numpy as np\n'), (34, 'numpy.allclose', 'np.allclose', (['b', '(A * x)'], {}), True, 'import numpy as np\n')]