# --- Gaussian kernel between two sets (rows = observations) -------------
# Returns an n_new x n_train matrix with K_ij = exp(-0.5 * ||x_new_i - x_train_j||^2 / h^2)
ARCHmX_kernel_between_iso <- function(Xnew, Xtrain, h) {
  Sa <- rowSums(Xnew^2)                 # length n_new
  Sb <- rowSums(Xtrain^2)               # length n_train
  D2 <- outer(Sa, Sb, "+") - 2 * tcrossprod(Xnew, Xtrain)
  exp(-0.5 * D2 / (h^2))
}