# X: n x d matrix (each row = x_i)
# h: scalar bandwidth
# returns a matrix of kernels K_ij for each entry (xi-xj)
ARCHmX_kernel_matrix_iso <- function(X, h) {
  s  <- rowSums(X^2)                         # length-n
  D2 <- outer(s, s, "+") - 2 * tcrossprod(X) # pairwise ||x_i - x_j||^2
  exp(-0.5 * D2 / (h^2))                     # unnormalized Gaussian kernel
  # If you want the normalized density kernel, multiply by:
  # 1 / ((2*pi)^(ncol(X)/2) * h^ncol(X))
}