Created
July 23, 2021 20:45
-
-
Save shelajev/73c893c69127044d207e2a53e33aeea5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static double correlate(double[] a, double[] b) { | |
if (a.length != b.length) { | |
return Double.NaN; | |
} | |
double partial[] = new double[4]; | |
int i = 0; | |
for ( ; i + 3 < a.length; i += 4) { | |
partial[0] += a[i+0] * b[i+0]; | |
partial[1] += a[i+1] * b[i+1]; | |
partial[2] += a[i+2] * b[i+2]; | |
partial[3] += a[i+3] * b[i+3]; | |
} | |
double correlation = partial[0] + partial[1] + partial[2] + partial[3]; | |
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