code: def solve_qp(
      P, q, G=None, h=None, A=None, b=None, solver=None, initvals=None
  ):
      """
      Solve a Quadratic Program defined as:
          minimize
              (1/2) * x.T * P * x + q.T * x
          subject to
              G * x <= h
              A * x == b
      using CVXOPT <http://cvxopt.org/>.
      Parameters
      ----------
      P : numpy.array, cvxopt.matrix or cvxopt.spmatrix
          Symmetric quadratic-cost matrix.
      q : numpy.array, cvxopt.matrix or cvxopt.spmatrix
          Quadratic-cost vector.
      G : numpy.array, cvxopt.matrix or cvxopt.spmatrix
          Linear inequality matrix.
      h : numpy.array, cvxopt.matrix or cvxopt.spmatrix
          Linear inequality vector.
      A : numpy.array, cvxopt.matrix or cvxopt.spmatrix
          Linear equality constraint matrix.
      b : numpy.array, cvxopt.matrix or cvxopt.spmatrix
          Linear equality constraint vector.
      solver : string, optional
          Set to 'mosek' to run MOSEK rather than CVXOPT.
      initvals : numpy.array, optional
          Warm-start guess vector.
      Returns
      -------
      x : array, shape=(n,)
          Solution to the QP, if found, otherwise ``None``.
      Note
      ----
      CVXOPT only considers the lower entries of `P`, therefore it will use a
      wrong cost function if a non-symmetric matrix is provided.
      """
      args = [cvxopt_matrix(P), cvxopt_matrix(q)]
      if G is not None:
          args.extend([cvxopt_matrix(G), cvxopt_matrix(h)])
          if A is not None:
              if type(A) is ndarray and A.ndim == 1:
                  A = A.reshape((1, A.shape[0]))
              args.extend([cvxopt_matrix(A), cvxopt_matrix(b)])
      sol = qp(*args, solver=solver, initvals=initvals)
      if "optimal" not in sol["status"]:
          return (None, None)
      return (
          array(sol["x"]).reshape((q.shape[0],)),
          sol["primal objective"],
      )
  
file_path: explainx/lib/PDASH_utils.py
imports: from __future__ import print_function
  import numpy
  from sklearn.preprocessing import OneHotEncoder
  from cvxopt.solvers import qp
  from cvxopt import matrix, spmatrix
  from numpy import array, ndarray
  from scipy.spatial.distance import cdist
label_desc: Use image node_id 2 for calling a global function with example usage: solve_qp(P, q, G, h, A, b, solver, initvals) and returns: array,  sol, None,  None