def gram(self):
        """Generate the gram matrix (lazy loading).

        Only access this function after a `.fit()` (otherwise
        `self.signal` is not defined).
        """
        if self._gram is None:
            K = pdist(self.signal, metric="sqeuclidean")
            if self.gamma is None:
                self.gamma = 1.0
                # median heuristics
                K_median = np.median(K)
                if K_median != 0:
                    # K /= K_median
                    self.gamma = 1 / K_median
            K *= self.gamma
            np.clip(K, 1e-2, 1e2, K)  # clipping to avoid exponential under/overflow
            self._gram = np.exp(squareform(-K))
        return self._gram
Generate the gram matrix (lazy loading).

        Only access this function after a `.fit()` (otherwise
        `self.signal` is not defined).
        
src/ruptures/costs/costrbf.py