Skip to content

Instantly share code, notes, and snippets.

@shelajev
Created July 23, 2021 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shelajev/76067722ac9e1a781a141187e687d714 to your computer and use it in GitHub Desktop.
Save shelajev/76067722ac9e1a781a141187e687d714 to your computer and use it in GitHub Desktop.
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