# Path: nlpy/tools/norms.py
# def norm1(x):
# def norm2(x):
# def normp(x,p):
# def norm_infty(x):
# def normest(A, tol=1.0e-6, maxits=100):
#         A = np.random.randn(n,m)
#         A = np.random.rand(n,n)
#         A = .5*(A.T + A)


from nlpy.linalg.pyma27 import PyMa27Context as LBLContext
from pysparse import spmatrix
from nlpy.tools import norms
from nlpy.tools.timing import cputime
import numpy
    import sys
    import os
    A[4,1] = 6
    A[4,4] = 1

    rhs = numpy.ones(5, 'd')
    rhs[0] = 8
    rhs[1] = 45
    rhs[2] = 31
    rhs[3] = 15
    rhs[4] = 17

    return (A, rhs)

def SolveSystem(A, rhs, itref_threshold=1.0e-6, nitrefmax=5, **kwargs):

    # Obtain Sils context object
    t = cputime()
    LBL = LBLContext(A, **kwargs)
    t_analyze = cputime() - t

    # Solve system and compute residual
    t = cputime()
    LBL.solve(rhs)
    t_solve = cputime() - t_analyze

    # Compute residual norm
    nrhsp1 = norms.norm_infty(rhs) + 1
    nr = norms.norm2(LBL.residual)/nrhsp1

    # If residual not small, perform iterative refinement
    LBL.refine(rhs, tol = itref_threshold, nitref=nitrefmax)

# Path: nlpy/tools/norms.py
# def norm1(x):
# def norm2(x):
# def normp(x,p):
# def norm_infty(x):
# def normest(A, tol=1.0e-6, maxits=100):
#         A = np.random.randn(n,m)
#         A = np.random.rand(n,n)
#         A = .5*(A.T + A)


# Path: examples/demo_sils.py
from nlpy.linalg.pyma27 import PyMa27Context as LBLContext
from pysparse import spmatrix
from nlpy.tools import norms
from nlpy.tools.timing import cputime
import numpy
    import sys
    import os

    A[4,1] = 6
    A[4,4] = 1

    rhs = numpy.ones(5, 'd')
    rhs[0] = 8
    rhs[1] = 45
    rhs[2] = 31
    rhs[3] = 15
    rhs[4] = 17

    return (A, rhs)

def SolveSystem(A, rhs, itref_threshold=1.0e-6, nitrefmax=5, **kwargs):

    # Obtain Sils context object
    t = cputime()
    LBL = LBLContext(A, **kwargs)
    t_analyze = cputime() - t

    # Solve system and compute residual
    t = cputime()
    LBL.solve(rhs)
    t_solve = cputime() - t_analyze

    # Compute residual norm
    nrhsp1 = norms.norm_infty(rhs) + 1
    nr = norms.norm2(LBL.residual)/nrhsp1

    # If residual not small, perform iterative refinement
    LBL.refine(rhs, tol = itref_threshold, nitref=nitrefmax)

    nr1 = norms.norm_infty(LBL.residual)/nrhsp1