code: protected double computeDCovar(double[] dVarMatrixA, double[] dVarMatrixB, int n) {
      double result = 0.;
      for(int i = 0, c = 0; i < n; i++) {
        for(int j = 0; j < i; j++) {
          result += 2. * dVarMatrixA[c] * dVarMatrixB[c];
          c++;
        }
        // Diagonal entry.
        result += dVarMatrixA[c] * dVarMatrixB[c];
        c++;
      }
      return result / (n * n);
    }
docs: Computes the distance covariance for two axis. Can also be used to compute
  the distance variance of one axis (dVarMatrixA = dVarMatrixB).
  
  @param dVarMatrixA distance variance matrix of the first axis
  @param dVarMatrixB distance variance matrix of the second axis
  @param n number of points
  @return distance covariance