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
Implementation of relational operator for complex numbers in XLA #39133
Conversation
Matching numpy semantics makes sense to me, could we add tests? |
@joschkabraun Can you please check @cheshire's comments and keep us posted. Thanks! |
Okay, perfect! I’m currently working on it and will finish this weekend! |
I have been looking through the code. Am I correct in assuming the tests for that should be placed into the file elemental_ir_emitter_test.cc? |
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.
Yes, adding tests to elemental_ir_emitter_test
would make sense.
@@ -1292,6 +1292,16 @@ StatusOr<llvm::Value*> ElementalIrEmitter::EmitComplexBinaryOp( | |||
llvm_ir::EmitComparison(llvm::CmpInst::FCMP_UNE, | |||
EmitExtractImag(lhs_value), | |||
EmitExtractImag(rhs_value), b_)); | |||
case ComparisonDirection::kGt: | |||
return Or(llvm_ir::EmitComparison(llvm::CmpInst::FCMP_OGT, |
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.
Could you add a comment that we are using lexicographical comparison which is consistent with numpy behavior?
@@ -1292,6 +1292,16 @@ StatusOr<llvm::Value*> ElementalIrEmitter::EmitComplexBinaryOp( | |||
llvm_ir::EmitComparison(llvm::CmpInst::FCMP_UNE, | |||
EmitExtractImag(lhs_value), | |||
EmitExtractImag(rhs_value), b_)); | |||
case ComparisonDirection::kGt: |
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.
What happens to other cases? kLt? Less-or-equal? You could also support this by implementing a normalization pass in algebraic_simplifier
@joschkabraun Can you please check @cheshire's comments and keep us posted. Thanks! |
It has been 20 days with no activity and the |
@joschkabraun, Any update on this PR? Please. Thanks! |
Unfortunately, I am currently very busy and seems advisable if someone else could take this over. I am sorry for answering so late! |
@joschkabraun Thanks for the confirmation. Closing the PR. |
This is the suggestion to implement relational operators for complex numbers (<, <=, >, >=) as in numpy, i.e., the lexicographical order. In this PR only the ">" relation was implemented as feedback from the community is important to evaluate if this functionality is wished for and makes sense.
This could be leveraged for the implementation of np.unique in JAX as comparison and sorting of complex arrays is not supported by XLA but possible with numpy. Another usage could be an implementation of complex QR decomposition in JAX.
The remaining comparisons for complex numbers and tests for it, will be added if this functionality makes sense.