# Path: nlpy/tools/utils.py
# def identical(a,b):
#     """
#     Check that two arrays or lists are identical. Must be cautious because
#     of Numpy's strange behavior:
#     >>> a = np.array([]) ; b = np.array([0])
#     >>> np.all(a==b)
#     True
#     """
#     if a.shape == b.shape:
#         return np.all(a==b)
#     return False
# 
# def where(cond):
#     "Bypass Numpy's annoyances. Gee does someone need to write a proper Numpy!"
#     return np.where(cond)[0]
# 
# Path: nlpy/tools/exceptions.py
# class InfeasibleError(Exception):
#     """
#     Error that can be raised to signal an infeasible iterate.
#     """
#     def __init__(self):
#         pass
# 
# class UserExitRequest(Exception):
#     """
#     Exception that the caller can use to request clean exit.
#     """
#     def __init__(self):
#         pass


from nlpy.krylov.pcg   import TruncatedCG
from nlpy.krylov.linop import SimpleLinearOperator
from nlpy.krylov.linop import SymmetricallyReducedLinearOperator as ReducedHessian
from nlpy.tools.utils import identical, where
from nlpy.tools.exceptions import InfeasibleError, UserExitRequest
    from nlpy.model import AmplModel
import numpy as np
import logging
import pdb
    import sys

        if g is None: g = self.qp.grad(x)

        if active_set is None:
            active_set = self.get_active_set(x)
        lower, upper = active_set

        pg = g.copy()
        pg[lower] = np.minimum(g[lower],0)
        pg[upper] = np.maximum(g[upper],0)
        return pg


    def project(self, x):
        "Project a given x into the bounds in Euclidian norm."
        return np.minimum(self.qp.Uvar,
                          np.maximum(self.qp.Lvar, x))


    def get_active_set(self, x, check_feasible=True):
        """
        Return the set of active constraints at x.
        Optionally, check that x is feasible.

        Returns the couple (lower,upper) containing the indices of variables
        that are at their lower and upper bound, respectively.
        """
        if check_feasible: self.check_feasible(x)

        lower_active = where(x==self.Lvar)

# Path: nlpy/tools/utils.py
# def identical(a,b):
#     """
#     Check that two arrays or lists are identical. Must be cautious because
#     of Numpy's strange behavior:
#     >>> a = np.array([]) ; b = np.array([0])
#     >>> np.all(a==b)
#     True
#     """
#     if a.shape == b.shape:
#         return np.all(a==b)
#     return False
# 
# def where(cond):
#     "Bypass Numpy's annoyances. Gee does someone need to write a proper Numpy!"
#     return np.where(cond)[0]
# 
# Path: nlpy/tools/exceptions.py
# class InfeasibleError(Exception):
#     """
#     Error that can be raised to signal an infeasible iterate.
#     """
#     def __init__(self):
#         pass
# 
# class UserExitRequest(Exception):
#     """
#     Exception that the caller can use to request clean exit.
#     """
#     def __init__(self):
#         pass


# Path: nlpy/optimize/solvers/bqp.py
from nlpy.krylov.pcg   import TruncatedCG
from nlpy.krylov.linop import SimpleLinearOperator
from nlpy.krylov.linop import SymmetricallyReducedLinearOperator as ReducedHessian
from nlpy.tools.utils import identical, where
from nlpy.tools.exceptions import InfeasibleError, UserExitRequest
    from nlpy.model import AmplModel
import numpy as np
import logging
import pdb
    import sys


        if g is None: g = self.qp.grad(x)

        if active_set is None:
            active_set = self.get_active_set(x)
        lower, upper = active_set

        pg = g.copy()
        pg[lower] = np.minimum(g[lower],0)
        pg[upper] = np.maximum(g[upper],0)
        return pg


    def project(self, x):
        "Project a given x into the bounds in Euclidian norm."
        return np.minimum(self.qp.Uvar,
                          np.maximum(self.qp.Lvar, x))


    def get_active_set(self, x, check_feasible=True):
        """
        Return the set of active constraints at x.
        Optionally, check that x is feasible.

        Returns the couple (lower,upper) containing the indices of variables
        that are at their lower and upper bound, respectively.
        """
        if check_feasible: self.check_feasible(x)

        lower_active = where(x==self.Lvar)

        upper_active = where(x==self.Uvar)