recode kl_divergence using iterators