-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Conversation
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"); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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;
}
@nickstanisha Can you please take a look at @rongrong 's comments. |
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! |
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.