final long[] collSums = new long[observed1.length];
final long[][] k = new long[2][observed1.length];
for (int i = 0; i < observed1.length; i++) {
if (observed1[i] == 0 && observed2[i] == 0) {
throw new ZeroException(LocalizedFormats.OBSERVED_COUNTS_BOTTH_ZERO_FOR_ENTRY, i);
} else {
countSum1 += observed1[i];
countSum2 += observed2[i];
collSums[i] = observed1[i] + observed2[i];
k[0][i] = observed1[i];
k[1][i] = observed2[i];
}
}
// Ensure neither sample is uniformly 0
if (countSum1 == 0 || countSum2 == 0) {
throw new ZeroException();
}
final long[] rowSums = {countSum1, countSum2};
final double sum = (double) countSum1 + (double) countSum2;
return 2 * sum * (entropy(rowSums) + entropy(collSums) - entropy(k));
}