def _update_cache(self, X, Y, Y_hat):
        if self.inference_cache == 0:
            return
        if (not hasattr(self, "inference_cache_")
                or self.inference_cache_ is None):
            self.inference_cache_ = [[] for y in Y_hat]

        def constraint_equal(y_1, y_2):
            if isinstance(y_1, tuple):
                return np.all(y_1[0] == y_2[0]) and np.all(y_1[1] == y_2[1])
            return np.all(y_1 == y_2)

        for sample, x, y, y_hat in zip(self.inference_cache_, X, Y, Y_hat):
            already_there = [constraint_equal(y_hat, cache[2])
                             for cache in sample]
            if np.any(already_there):
                continue
            if len(sample) > self.inference_cache:
                sample.pop(0)
            # we computed both of these before, but summed them up immediately
            # this makes it a little less efficient in the caching case.
            # the idea is that if we cache, inference is way more expensive
            # and this doesn't matter much.
            sample.append((self.model.joint_feature(x, y_hat),
                           self.model.loss(y, y_hat), y_hat))
Updated cached constraints.
dataset/ETHPy150Open pystruct/pystruct/pystruct/learners/one_slack_ssvm.py/OneSlackSSVM._update_cache