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

[C++][Compute] Add sign function kernels #28594

Closed
asfimport opened this issue May 24, 2021 · 5 comments
Closed

[C++][Compute] Add sign function kernels #28594

asfimport opened this issue May 24, 2021 · 5 comments

Comments

@asfimport
Copy link
Collaborator

asfimport commented May 24, 2021

Add the sign function to the compute kernels.

sign(X) =

  • 1 if X > 0
  • 0 if X = 0
  • -1 if X < 0

Reporter: Eduardo Ponce / @edponce
Assignee: Eduardo Ponce / @edponce

Related issues:

PRs and other links:

Note: This issue was originally created as ARROW-12861. Please see the migration documentation for further details.

@asfimport
Copy link
Collaborator Author

Eduardo Ponce / @edponce:
IEEE 754 defines rules for +0.0 and -0.0, thus sign(+0.0) = 1 and sign(-0.0) = -1. On the other hand, integral zero results in sign(0) = 0. Is this behavior reasonable?

This approach will result in different behavior for floating-point and integral operands.

  1. Floating-point sign(X) =
    -1 if X <= -0.0
    1 if X >= 0.0
  2. Integral sign(X) =
    -1 if X < 0
    0 if X = 0
    1 if X > 0

@asfimport
Copy link
Collaborator Author

Ian Cook / @ianmcook:
@edponce  I think sign(0.0) should return 0 regardless of the sign of the floating point zero, for two reasons: (a) This is what Python, R, all SQL engines, etc. do and therefore it is what users will expect. (b) There is little practical use in knowing the sign of a floating point zero value; this sign kernel will be more consistent and more useful in more ways if it always returns sign zero for value zero.

@asfimport
Copy link
Collaborator Author

Eduardo Ponce / @edponce:
Thanks for the feedback @ianmcook, I agree and will make this change.

@asfimport
Copy link
Collaborator Author

Neal Richardson / @nealrichardson:
I definitely have seen applications that rely on the sign of 0. We may want a FunctionOption for that--but we can also defer that until someone reports it, which as Ian suggests, may never happen.

@asfimport
Copy link
Collaborator Author

Ben Kietzman / @bkietz:
Issue resolved by pull request 10395
#10395

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant