# Path: sksurv/base.py
# class SurvivalAnalysisMixin:
# 
#     def score(self, X, y):
#         """Returns the concordance index of the prediction.
# 
#         Parameters
#         ----------
#         X : array-like, shape = (n_samples, n_features)
#             Test samples.
# 
#         y : structured array, shape = (n_samples,)
#             A structured array containing the binary event indicator
#             as first field, and time of event or time of censoring as
#             second field.
# 
#         Returns
#         -------
#         cindex : float
#             Estimated concordance index.
#         """
#         from .metrics import concordance_index_censored
#         name_event, name_time = y.dtype.names
# 
#         risk_score = self.predict(X)
#         if not getattr(self, "_predict_risk_score", True):
#             risk_score *= -1  # convert prediction on time scale to risk scale
# 
#         result = concordance_index_censored(y[name_event], y[name_time], risk_score)
#         return result[0]
# 
# Path: sksurv/exceptions.py
# class NoComparablePairException(ValueError):
#     """An error indicating that data of censored event times
#     does not contain one or more comparable pairs.
#     """
# 
# Path: sksurv/util.py
# def check_array_survival(X, y):
#     """Check that all arrays have consistent first dimensions.
# 
#     Parameters
#     ----------
#     X : array-like
#         Data matrix containing feature vectors.
# 
#     y : structured array with two fields
#         A structured array containing the binary event indicator
#         as first field, and time of event or time of censoring as
#         second field.
# 
#     kwargs : dict
#         Additional arguments passed to :func:`sklearn.utils.check_array`.
# 
#     Returns
#     -------
#     event : array, shape=[n_samples,], dtype=bool
#         Binary event indicator.
# 
#     time : array, shape=[n_samples,], dtype=float
#         Time of event or censoring.
#     """
#     event, time = check_y_survival(y)
#     check_consistent_length(X, event, time)
#     return event, time


from abc import ABCMeta, abstractmethod
from scipy import linalg, sparse
from sklearn.base import BaseEstimator
from sklearn.exceptions import ConvergenceWarning
from sklearn.metrics.pairwise import pairwise_kernels
from ..base import SurvivalAnalysisMixin
from ..exceptions import NoComparablePairException
from ..util import check_array_survival
from ._minlip import create_difference_matrix
import warnings
import numpy
        import osqp
        import ecos
            import timeit
        else:
            params = {"gamma": self.gamma,
                      "degree": self.degree,
                      "coef0": self.coef0}
        return pairwise_kernels(X, Y, metric=self.kernel,
                                filter_params=True, **params)

    def _setup_qp(self, K, D, time):
        n_pairs = D.shape[0]
        P = D.dot(D.dot(K).T).T
        q = -D.dot(time)

        Dt = D.T.astype(P.dtype)  # cast constraints to correct type
        G = sparse.vstack((
            Dt,  # upper bound
            - Dt,  # lower bound
            - sparse.eye(n_pairs, dtype=P.dtype),  # lower bound >= 0
        ),
            format="csc"
        )
        n_constraints = Dt.shape[0]
        h = numpy.empty(G.shape[0], dtype=float)
        h[:2 * n_constraints] = self.alpha
        h[-n_pairs:] = 0.0

        return {"P": P, "q": q, "G": G, "h": h}

    def _fit(self, x, event, time):
        D = create_difference_matrix(event.astype(numpy.uint8), time, kind=self.pairs)
        if D.shape[0] == 0:

# Path: sksurv/base.py
# class SurvivalAnalysisMixin:
# 
#     def score(self, X, y):
#         """Returns the concordance index of the prediction.
# 
#         Parameters
#         ----------
#         X : array-like, shape = (n_samples, n_features)
#             Test samples.
# 
#         y : structured array, shape = (n_samples,)
#             A structured array containing the binary event indicator
#             as first field, and time of event or time of censoring as
#             second field.
# 
#         Returns
#         -------
#         cindex : float
#             Estimated concordance index.
#         """
#         from .metrics import concordance_index_censored
#         name_event, name_time = y.dtype.names
# 
#         risk_score = self.predict(X)
#         if not getattr(self, "_predict_risk_score", True):
#             risk_score *= -1  # convert prediction on time scale to risk scale
# 
#         result = concordance_index_censored(y[name_event], y[name_time], risk_score)
#         return result[0]
# 
# Path: sksurv/exceptions.py
# class NoComparablePairException(ValueError):
#     """An error indicating that data of censored event times
#     does not contain one or more comparable pairs.
#     """
# 
# Path: sksurv/util.py
# def check_array_survival(X, y):
#     """Check that all arrays have consistent first dimensions.
# 
#     Parameters
#     ----------
#     X : array-like
#         Data matrix containing feature vectors.
# 
#     y : structured array with two fields
#         A structured array containing the binary event indicator
#         as first field, and time of event or time of censoring as
#         second field.
# 
#     kwargs : dict
#         Additional arguments passed to :func:`sklearn.utils.check_array`.
# 
#     Returns
#     -------
#     event : array, shape=[n_samples,], dtype=bool
#         Binary event indicator.
# 
#     time : array, shape=[n_samples,], dtype=float
#         Time of event or censoring.
#     """
#     event, time = check_y_survival(y)
#     check_consistent_length(X, event, time)
#     return event, time


# Path: sksurv/svm/minlip.py
from abc import ABCMeta, abstractmethod
from scipy import linalg, sparse
from sklearn.base import BaseEstimator
from sklearn.exceptions import ConvergenceWarning
from sklearn.metrics.pairwise import pairwise_kernels
from ..base import SurvivalAnalysisMixin
from ..exceptions import NoComparablePairException
from ..util import check_array_survival
from ._minlip import create_difference_matrix
import warnings
import numpy
        import osqp
        import ecos
            import timeit

        else:
            params = {"gamma": self.gamma,
                      "degree": self.degree,
                      "coef0": self.coef0}
        return pairwise_kernels(X, Y, metric=self.kernel,
                                filter_params=True, **params)

    def _setup_qp(self, K, D, time):
        n_pairs = D.shape[0]
        P = D.dot(D.dot(K).T).T
        q = -D.dot(time)

        Dt = D.T.astype(P.dtype)  # cast constraints to correct type
        G = sparse.vstack((
            Dt,  # upper bound
            - Dt,  # lower bound
            - sparse.eye(n_pairs, dtype=P.dtype),  # lower bound >= 0
        ),
            format="csc"
        )
        n_constraints = Dt.shape[0]
        h = numpy.empty(G.shape[0], dtype=float)
        h[:2 * n_constraints] = self.alpha
        h[-n_pairs:] = 0.0

        return {"P": P, "q": q, "G": G, "h": h}

    def _fit(self, x, event, time):
        D = create_difference_matrix(event.astype(numpy.uint8), time, kind=self.pairs)
        if D.shape[0] == 0:

            raise NoComparablePairException("Data has no comparable pairs, cannot fit model.")