Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove N^2 uniqueness checks in interpolators #2031

Merged
merged 9 commits into from Jul 29, 2019

Conversation

@wjnicholson
Copy link
Member

commented Jul 19, 2019

Not sure this is the best implementation - still seems a little boilerplatey.
Could definitely be streamlined with more ArgChecker methods, potentially ones that assert that a double array is sorted, unique, and doesn't contain NaN or infinity, but maybe that's overstepping what ArgChecker is responsible for.

*/
public static double[] noDuplicates(double[] argument, String name) {
notNull(argument, name);
if (argument.length > 0 && DoubleStream.of(argument).distinct().count() != argument.length) {

This comment has been minimized.

Copy link
@jodastephen

jodastephen Jul 22, 2019

Member

I wouldn't have thought DoubleStream.of(argument).distinct().count() was that fast?

@@ -476,6 +562,10 @@ private static void swap(double[] keys, double[] values, int first, int second)

/**
* Return the array lengths if they are the same, otherwise throws an {@code IllegalArgumentException}.
*

This comment has been minimized.

Copy link
@jodastephen

jodastephen Jul 22, 2019

Member

I would have just changed this to a // comment

double[] yValuesSrt = new double[nDataPts];

xValuesSrt = Arrays.copyOf(xValues, nDataPts);
double[] xValuesSrt = Arrays.copyOf(xValues, nDataPts);

This comment has been minimized.

Copy link
@jodastephen

jodastephen Jul 22, 2019

Member

I suspect xValues.clone() might be quicker in cases like this.

This comment has been minimized.

Copy link
@wjnicholson

wjnicholson Jul 23, 2019

Author Member

Apparently .clone() may add a cast (since it's implicitly overriden from the Object::clone() method)
Arrays.copyOf() delegates to System.arrayCopy which is native, and doesn't involve a cast.
I'd have to benchmark to be sure.

Although https://stackoverflow.com/questions/12157300/clone-or-arrays-copyof says they are equivalent post JIT

for (int j = i + 1; j < nDataPts; ++j) {
ArgChecker.isFalse(xValues[i] == xValues[j], "Data should be distinct");
}
if (DoubleStream.of(xValues).distinct().count() != xValues.length) {

This comment has been minimized.

Copy link
@jodastephen

jodastephen Jul 22, 2019

Member

ArgChecker?

@jodastephen jodastephen force-pushed the topic/faster-duplication-checks branch from 8391972 to c618d63 Jul 29, 2019

@jodastephen jodastephen merged commit c79144e into master Jul 29, 2019

13 checks passed

build Workflow: build
Details
security/snyk - examples/pom.xml (OpenGamma) No new issues
Details
security/snyk - modules/calc/pom.xml (OpenGamma) No new issues
Details
security/snyk - modules/collect/pom.xml (OpenGamma) No new issues
Details
security/snyk - modules/data/pom.xml (OpenGamma) No new issues
Details
security/snyk - modules/loader/pom.xml (OpenGamma) No new issues
Details
security/snyk - modules/market/pom.xml (OpenGamma) No new issues
Details
security/snyk - modules/math/pom.xml (OpenGamma) No new issues
Details
security/snyk - modules/measure/pom.xml (OpenGamma) No new issues
Details
security/snyk - modules/pom.xml (OpenGamma) No new issues
Details
security/snyk - modules/product/pom.xml (OpenGamma) No new issues
Details
security/snyk - modules/report/pom.xml (OpenGamma) No new issues
Details
security/snyk - pom.xml (OpenGamma) No new issues
Details

@delete-merged-branch delete-merged-branch bot deleted the topic/faster-duplication-checks branch Jul 29, 2019

@jodastephen jodastephen added this to the v2.6 milestone Jul 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.