Skip to content

Conversation

@anthonylouisbsb
Copy link
Contributor

@anthonylouisbsb anthonylouisbsb commented May 17, 2021

Implements the ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL and TRUNC.

The RANDOM functions are already implemented in Gandiva.

@github-actions
Copy link

Copy link
Member

Choose a reason for hiding this comment

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

I am curious whether all platforms can convert 64-bit integer to long double without loss of digits. (i.e. size(long double) > size(int64)).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kiszk I checked that by the IEE-754 convention, the numbers in double precision should use at least 8 bytes to construct their representation, so I think that there would not have any digit loss in conversion.

Copy link
Member

Choose a reason for hiding this comment

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

Can we ensure that the same semantics (shift logical or shift arithmetic) on all platforms using just >>?

Copy link
Contributor Author

@anthonylouisbsb anthonylouisbsb May 24, 2021

Choose a reason for hiding this comment

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

@kiszk Thanks for your revision, I checked the C++ reference, and I noticed that the shift operators have undefined or implementation-choice behavior for signed and negative numbers.

So as in this Pull Request, we are implementing the Arithmetical Shift, we can cast the input parameters to their respective unsigned types and then apply the shift operators and they will have the same behavior in all platforms. Do you agree with the solution?

@kiszk
Copy link
Member

kiszk commented May 19, 2021

#10274 handles abs operation well.

@jpedroantunes jpedroantunes force-pushed the feature/add-new-math-functions branch from 70399da to 124a58d Compare May 20, 2021 12:43
@anthonylouisbsb anthonylouisbsb changed the title ARROW-12814: [C++][Gandiva] Implements the ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT and TRUNC functions ARROW-12814: [C++][Gandiva] Implements the ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL and TRUNC functions May 20, 2021
@anthonylouisbsb
Copy link
Contributor Author

anthonylouisbsb commented May 20, 2021

I included the CEIL function in the title because it was implemented too in Pull Request

Copy link
Member

Choose a reason for hiding this comment

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

Does it mean that we will accept the loss of digits in INT64?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kiszk Thanks for your revision! Please, could you explain how would occur digit loss here? I did not understand what you said.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I thought the previous version of abs is to cast int64 to double long. But, now, gdv_fn_abs_int64 handles as int64. Correct?

Copy link
Contributor Author

@anthonylouisbsb anthonylouisbsb May 25, 2021

Choose a reason for hiding this comment

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

@kiszk Yes, this line has the changes I made in the function. I handle the number as int64 and I add a check similar to the compute kernel to avoid overflow when getting the absolute value for the INT64_MIN value.

@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch 3 times, most recently from 6b7a038 to 1b0747b Compare May 25, 2021 02:04
@anthonylouisbsb
Copy link
Contributor Author

anthonylouisbsb commented May 25, 2021

@kiszk I applied all suggestions you proposed, could you check if the corrections are fine? Thanks in advance for the review!

@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch 4 times, most recently from 198a993 to aeea171 Compare May 25, 2021 23:22
@jpedroantunes jpedroantunes force-pushed the feature/add-new-math-functions branch from aeea171 to 5d186be Compare May 26, 2021 12:50
@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch 2 times, most recently from 9d4f95c to 1ac8f04 Compare May 31, 2021 18:54
@jpedroantunes jpedroantunes force-pushed the feature/add-new-math-functions branch from 1ac8f04 to a1f2aad Compare June 1, 2021 13:18
@anthonylouisbsb anthonylouisbsb changed the title ARROW-12814: [C++][Gandiva] Implements the ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL and TRUNC functions ARROW-12814: [C++][Gandiva] Implements the ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL, TRUNC and LN functions Jun 1, 2021
@anthonylouisbsb
Copy link
Contributor Author

The LN function was added in this PR too.

@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch from a1f2aad to 098861c Compare June 1, 2021 20:07
@anthonylouisbsb anthonylouisbsb changed the title ARROW-12814: [C++][Gandiva] Implements the ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL, TRUNC and LN functions ARROW-12814: [C++][Gandiva] Implements ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL, TRUNC, LN and LOG2 functions Jun 1, 2021
@jpedroantunes
Copy link
Contributor

The LOG2 function was added to the Pull Request

@anthonylouisbsb
Copy link
Contributor Author

@kiszk @pitrou and @lidavidm I follow your suggestions and I changed the shift functions to have the same behavior as the Compute module. Thanks for your help!

@kiszk I also applied your suggestions to add more cases in the tests, when you be available, could you take another look in the changes?

@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch from 33e97d9 to c242520 Compare July 15, 2021 16:41
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you choose this threshold? On fabs documentation it uses 6 places for decimal part, shouldn't it be 0.000005 a better value for AlmostEquals threshold?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think choosing an adequate does not have a simple and unique answer like is shown in these articles:

I choose that number because it is the value defined in the float header as default threshold . For huge and small numbers, I think the developer should set the threshold manually when he is calling the method.

Copy link
Contributor Author

@anthonylouisbsb anthonylouisbsb Jul 16, 2021

Choose a reason for hiding this comment

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

I will change the method to use the FLT_EPSILON from the macro

@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch 2 times, most recently from 9173083 to 848fe4e Compare July 21, 2021 21:38
@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch from 848fe4e to 0a521ef Compare August 6, 2021 20:52
@anthonylouisbsb
Copy link
Contributor Author

@kiszk I applied all suggestions you made in the PR. Could you take another look at the PR and see if it is ready to be merged?

@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch from 0a521ef to 7c74202 Compare September 28, 2021 17:45
@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch from 7c74202 to a66a367 Compare October 5, 2021 13:38
@anthonylouisbsb anthonylouisbsb requested a review from kiszk October 6, 2021 17:42
@kiszk
Copy link
Member

kiszk commented Oct 15, 2021

Sorry for late review. It looks good to me. I would like to ask another review.
@pitrou Could you please review this?

@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch from a66a367 to b94b1a1 Compare October 19, 2021 14:11
@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch from b94b1a1 to cc0e9fa Compare November 23, 2021 17:26
@anthonylouisbsb
Copy link
Contributor Author

@pitrou When you be free, could you take a look at this PR? I applied all changes that you and @kiszk suggested.

@kszucs
Copy link
Member

kszucs commented Dec 6, 2021

ping @pitrou

@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch from e6a1c05 to cb9ce06 Compare December 8, 2021 22:10
@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch from cb9ce06 to 59778bf Compare December 23, 2021 11:47
@anthonylouisbsb
Copy link
Contributor Author

@pitrou can you take a look at this PR? Because I want to close it as soon as possible

@anthonylouisbsb
Copy link
Contributor Author

@pitrou can you take a look at it?

@pitrou
Copy link
Member

pitrou commented Jan 25, 2022

I would rather if a Gandiva developer vetted this PR. @pravindra perhaps?

Copy link
Contributor

Choose a reason for hiding this comment

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

What should happen if there is overflow?

overflow is an in-out parameter.. for some of the later calls overflow could be false - will that cause an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vvellanki I add a check for that case and it will throw an error if that situation occurs, check that commit: d25a630

@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch from 59778bf to 879a346 Compare February 2, 2022 22:21
@anthonylouisbsb anthonylouisbsb force-pushed the feature/add-new-math-functions branch from d25a630 to 9f450bf Compare February 10, 2022 00:03
@amol-
Copy link
Member

amol- commented Mar 30, 2023

Closing because it has been untouched for a while, in case it's still relevant feel free to reopen and move it forward 👍

@amol- amol- closed this Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants