code: @Override
      public Cholesky cholesky() {
          if (nrows() != ncols()) {
              throw new UnsupportedOperationException("Cholesky decomposition on non-square matrix");
          }
  
          int n = nrows();
  
          // Main loop.
          for (int j = 0; j < n; j++) {
              double d = 0.0;
              for (int k = 0; k < j; k++) {
                  double s = 0.0;
                  for (int i = 0; i < k; i++) {
                      s += get(k, i) * get(j, i);
                  }
                  s = (get(j, k) - s) / get(k, k);
                  set(j, k, s);
                  d = d + s * s;
              }
              d = get(j, j) - d;
  
              if (d < 0.0) {
                  throw new IllegalArgumentException("The matrix is not positive definite.");
              }
  
              set(j, j, Math.sqrt(d));
          }
  
          return new Cholesky(this);
      }
docs: Cholesky decomposition for symmetric and positive definite matrix.
  Only the lower triangular part will be used in the decomposition.
  
  @throws IllegalArgumentException if the matrix is not positive definite.