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

Add linear_interpolate to math functions (#15798) #15829

Closed
wants to merge 3 commits into from

Conversation

nickstanisha
Copy link

Test plan
Built with Maven and confirmed all of the tests in TestMathFunctions complete successfully. The signature and edge case handling for this function was based off the numpy utility numpy.interp.

== RELEASE NOTES ==

General Changes
* Added linear_interpolate to math functions 

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 12, 2021

CLA Signed

The committers are authorized under a signed CLA.

for (int i = 0; i < xCount; i++) {
Double xValue = DOUBLE.getDouble(xArray, i);
Double yValue = DOUBLE.getDouble(yArray, i);
checkCondition(!xArray.isNull(i), INVALID_FUNCTION_ARGUMENT, "x array must be strictly increasing");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How big these arrays tend to be? There are way too many conditionals in the for loop. It would probably be more efficient if you take the conditional checks out. For example, do the null check before processing the data.

checkCondition(IntStream.range(0, xCount).noneMatch(i -> xArray.isNull(i)), "....");

}
xPrimitiveArray[i] = xValue;
yPrimitiveArray[i] = yValue;
yIsNull = yIsNull || yArray.isNull(i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execute this logic first before the for loop. Handle all special cases that could terminate the logic early first to you don't waste cpu.

boolean yIsNull = IntStream.range(0, yCount).anyMatch(i -> yArray.isNull(i));

checkCondition(!xArray.isNull(i), INVALID_FUNCTION_ARGUMENT, "x array must be strictly increasing");
checkCondition(!Double.isNaN(xValue) && !Double.isInfinite(xValue), INVALID_FUNCTION_ARGUMENT, "NaNs not supported");
checkCondition(!Double.isNaN(yValue) && !Double.isInfinite(yValue), INVALID_FUNCTION_ARGUMENT, "NaNs not supported");
if (i < xCount - 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this if:

Double previousX = Double.getDouble(xArray, 0);
for (i = 1; i < xCount; i++) {
....
checkCondition(xValue > previousX);
previousX = xValue;
}

@ajaygeorge
Copy link
Contributor

@nickstanisha Can you please take a look at @rongrong 's comments.
cc @jbapple

@stale
Copy link

stale bot commented Apr 16, 2022

This pull request has been automatically marked as stale because it has not had recent activity. If you'd still like this PR merged, please comment on the task, make sure you've addressed reviewer comments, and rebase on the latest master. Thank you for your contributions!

@stale stale bot added the stale label Apr 16, 2022
@stale stale bot closed this Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants