# 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)


import numpy
import sys
from pysparse.sparse import spmatrix   # To assemble the projection matrix
from pysparse.sparse.pysparseMatrix import PysparseMatrix
    from nlpy.linalg.pyma57 import PyMa57Context as LBLContext
    from nlpy.linalg.pyma27 import PyMa27Context as LBLContext
from nlpy.tools import norms
from nlpy.tools.timing import cputime
            P.put(1, r, r)
            #for i in range(self.n):
            #    P[i,i] = 1
        P[self.n:,:self.n] = self.A

        # Add regularization if requested.
        if self.dreg > 0.0:
            r = range(self.n, self.n + self.m)
            P.put(-self.dreg, r, r)

        if self.debug:
                msg = 'Factorizing projection matrix '
                msg += '(size %-d, nnz = %-d)...\n' %  (P.shape[0],P.nnz)
                self._write(msg)
        self.t_fact = cputime()
        self.Proj = LBLContext(P)
        self.t_fact = cputime() - self.t_fact
        if self.debug:
                msg = ' done (%-5.2fs)\n' % self.t_fact
                self._write(msg)
        self.factorized = True
        return


    def CheckAccurate(self):
        """
        Make sure constraints are consistent and residual is satisfactory
        """
        scale_factor = norms.norm_infty(self.Proj.x[:self.n])
        if self.b is not None:

# 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: nlpy/krylov/projKrylov.py
import numpy
import sys
from pysparse.sparse import spmatrix   # To assemble the projection matrix
from pysparse.sparse.pysparseMatrix import PysparseMatrix
    from nlpy.linalg.pyma57 import PyMa57Context as LBLContext
    from nlpy.linalg.pyma27 import PyMa27Context as LBLContext
from nlpy.tools import norms
from nlpy.tools.timing import cputime

            P.put(1, r, r)
            #for i in range(self.n):
            #    P[i,i] = 1
        P[self.n:,:self.n] = self.A

        # Add regularization if requested.
        if self.dreg > 0.0:
            r = range(self.n, self.n + self.m)
            P.put(-self.dreg, r, r)

        if self.debug:
                msg = 'Factorizing projection matrix '
                msg += '(size %-d, nnz = %-d)...\n' %  (P.shape[0],P.nnz)
                self._write(msg)
        self.t_fact = cputime()
        self.Proj = LBLContext(P)
        self.t_fact = cputime() - self.t_fact
        if self.debug:
                msg = ' done (%-5.2fs)\n' % self.t_fact
                self._write(msg)
        self.factorized = True
        return


    def CheckAccurate(self):
        """
        Make sure constraints are consistent and residual is satisfactory
        """
        scale_factor = norms.norm_infty(self.Proj.x[:self.n])
        if self.b is not None:

            scale_factor = max(scale_factor, norms.norm_infty(self.b))