-
Notifications
You must be signed in to change notification settings - Fork 19.6k
[Keras Ops] view_as_complex() and view_as_real() #21221
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
[Keras Ops] view_as_complex() and view_as_real() #21221
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #21221 +/- ##
==========================================
- Coverage 82.61% 82.60% -0.02%
==========================================
Files 564 564
Lines 54476 54581 +105
Branches 8470 8476 +6
==========================================
+ Hits 45005 45084 +79
- Misses 7395 7412 +17
- Partials 2076 2085 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The torch tests don't like the
Is there a Keras-preferred way to handle this case or should I just find a reasonable way to do the comparison instead? |
Please use |
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.
Thanks for the PR!
These functions do not appear to be NumPy operations, so at least they should not go in the keras.ops.numpy
API (and should not be part of numpy.py
).
Is there a standard name we can use? Maybe something in NumPy?
Strictly speaking, not Numpy operations, but they make use of
Numpy offers We could name it something like |
Sounds good, let's move them to math.py. numpy.py is strictly for actual numpy APIs. |
Thanks for weighing in! Moved it to |
keras/src/ops/math.py
Outdated
) | ||
|
||
|
||
@keras_export(["keras.ops.view_as_real", "keras.ops.math.view_as_real"]) |
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.
There is not math
namespace -- just export to ops
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.
Whoops - good point. Accidentally left it in due to the original keras.ops.numpy
location.
Removed!
Convenience operation, used to convert between complex and real tensors.
Useful for doing operations in architectures like DeepSeek V3/R1 (keras-team/keras-hub#2171).
Equivalent to PyTorch's:
Usage:
view_as_real()
converts a complex-type tensor into a real tensor:view_as_complex()
does the opposite:/cc @fchollet for review