Skip to content

ARROW-12814: [C++][Gandiva] Implements ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL, TRUNC, LN and LOG2 functions - #10350

Closed
anthonylouisbsb wants to merge 2 commits into
apache:mainfrom
s1mbi0se:feature/add-new-math-functions
Closed

ARROW-12814: [C++][Gandiva] Implements ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL, TRUNC, LN and LOG2 functions#10350
anthonylouisbsb wants to merge 2 commits into
apache:mainfrom
s1mbi0se:feature/add-new-math-functions

Conversation

@anthonylouisbsb

@anthonylouisbsbanthonylouisbsb commented May 17, 2021

Copy link
Copy Markdown
Contributor

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 Markdown

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

Comment threadcpp/src/gandiva/precompiled/extended_math_ops_test.cc Outdated
Comment threadcpp/src/gandiva/precompiled/extended_math_ops.cc Outdated

Copy link
Copy Markdown
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 >>?

@anthonylouisbsbanthonylouisbsbMay 24, 2021

Copy link
Copy Markdown
ContributorAuthor

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?

Comment threadcpp/src/gandiva/precompiled/extended_math_ops_test.cc Outdated
@kiszk

Copy link
Copy Markdown
Member

#10274 handles abs operation well.

@jpedroantunes
jpedroantunesforce-pushed the feature/add-new-math-functions branch from 70399da to 124a58dCompareMay 20, 2021 12:43
@anthonylouisbsbanthonylouisbsb changed the title ARROW-12814: [C++][Gandiva] Implements the ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT and TRUNC functionsARROW-12814: [C++][Gandiva] Implements the ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL and TRUNC functionsMay 20, 2021
@anthonylouisbsb

anthonylouisbsb commented May 20, 2021

Copy link
Copy Markdown
ContributorAuthor

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

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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?

@anthonylouisbsbanthonylouisbsbMay 25, 2021

Copy link
Copy Markdown
ContributorAuthor

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
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch 3 times, most recently from 6b7a038 to 1b0747bCompareMay 25, 2021 02:04
@anthonylouisbsb

anthonylouisbsb commented May 25, 2021

Copy link
Copy Markdown
ContributorAuthor

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

@anthonylouisbsb
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch 4 times, most recently from 198a993 to aeea171CompareMay 25, 2021 23:22
@jpedroantunes
jpedroantunesforce-pushed the feature/add-new-math-functions branch from aeea171 to 5d186beCompareMay 26, 2021 12:50
@anthonylouisbsb
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch 2 times, most recently from 9d4f95c to 1ac8f04CompareMay 31, 2021 18:54
@jpedroantunes
jpedroantunesforce-pushed the feature/add-new-math-functions branch from 1ac8f04 to a1f2aadCompareJune 1, 2021 13:18
@anthonylouisbsbanthonylouisbsb changed the title ARROW-12814: [C++][Gandiva] Implements the ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL and TRUNC functionsARROW-12814: [C++][Gandiva] Implements the ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL, TRUNC and LN functionsJun 1, 2021
@anthonylouisbsb

Copy link
Copy Markdown
ContributorAuthor

The LN function was added in this PR too.

@anthonylouisbsb
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch from a1f2aad to 098861cCompareJune 1, 2021 20:07
@anthonylouisbsbanthonylouisbsb changed the title ARROW-12814: [C++][Gandiva] Implements the ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL, TRUNC and LN functionsARROW-12814: [C++][Gandiva] Implements ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL, TRUNC, LN and LOG2 functionsJun 1, 2021
@jpedroantunes

Copy link
Copy Markdown
Contributor

The LOG2 function was added to the Pull Request

@anthonylouisbsb
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch from 33e97d9 to c242520CompareJuly 15, 2021 16:41
Comment threadcpp/src/gandiva/precompiled/extended_math_ops.cc Outdated

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

@anthonylouisbsbanthonylouisbsbJul 16, 2021

Copy link
Copy Markdown
ContributorAuthor

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
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch 2 times, most recently from 9173083 to 848fe4eCompareJuly 21, 2021 21:38
@anthonylouisbsb
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch from 848fe4e to 0a521efCompareAugust 6, 2021 20:52
@anthonylouisbsb

Copy link
Copy Markdown
ContributorAuthor

@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?

Comment threadcpp/src/gandiva/function_registry_math_ops.cc Outdated
@anthonylouisbsb
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch from 7c74202 to a66a367CompareOctober 5, 2021 13:38
@kiszk

Copy link
Copy Markdown
Member

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

@anthonylouisbsb
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch from a66a367 to b94b1a1CompareOctober 19, 2021 14:11
@anthonylouisbsb
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch from b94b1a1 to cc0e9faCompareNovember 23, 2021 17:26
@anthonylouisbsb

Copy link
Copy Markdown
ContributorAuthor

@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
Copy Markdown
Member

ping @pitrou

@anthonylouisbsb
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch from e6a1c05 to cb9ce06CompareDecember 8, 2021 22:10
@anthonylouisbsb
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch from cb9ce06 to 59778bfCompareDecember 23, 2021 11:47
@anthonylouisbsb

Copy link
Copy Markdown
ContributorAuthor

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

@anthonylouisbsb

Copy link
Copy Markdown
ContributorAuthor

@pitrou can you take a look at it?

@pitrou

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch from 59778bf to 879a346CompareFebruary 2, 2022 22:21
@anthonylouisbsb
anthonylouisbsbforce-pushed the feature/add-new-math-functions branch from d25a630 to 9f450bfCompareFebruary 10, 2022 00:03
@amol-

Copy link
Copy Markdown
Member

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

Sign up for freeto 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

@anthonylouisbsb@kiszk@jpedroantunes@pitrou@lidavidm@kszucs@amol-@vvellanki@augustoasilva