Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public static double correlate(double[] a, double[] b) {
if (a.length != b.length) {
return Double.NaN;
}
double <w,x,y,z> = <0,0,0,0>;
int i = 0;
for ( ; i + 3 < a.length; i += 4) {
<w,x,y,z> += a[<i,i+1,i+2,i+3>] * b[<i,i+1,i+2,i+3>];
}
double correlation = w + x + y + z;
for ( ; i < a.length; i++) {
correlation += a[i] * b[i];
}
return correlation;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment