Skip to content

Conversation

alexrosen45
Copy link
Contributor

Fix for tf.math.real so that it only accepts tensors with numeric entries as input. This makes it consistent with its documentation at https://www.tensorflow.org/api_docs/python/tf/math/real and raises a TypeError saying input must have numeric entries when called incorrectly. For more details, see issue #60526.

Fix for tf.math.real so that it only accepts tensors with numeric entries as input. This makes it consistent with its documentation at https://www.tensorflow.org/api_docs/python/tf/math/real and raises a TypeError saying input must have numeric entries when called incorrectly.
@google-ml-butler google-ml-butler bot added the size:XS CL Change Size: Extra Small label May 8, 2023
@google-ml-butler google-ml-butler bot requested a review from cantonios May 8, 2023 20:25
real_dtype = input.dtype.real_dtype
return gen_math_ops.real(input, Tout=real_dtype, name=name)
else:
elif tf.debugging.is_numeric_tensor(input):
Copy link
Contributor

Choose a reason for hiding this comment

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

We can't use tf. from within here, since it's not imported (and can't be, since that would be a circular dependency).

You can import the function itself from check_ops.py where it actually lives. Or, we could add a property to dtype itself for is_numeric, which is probably the most general solution. Those properties are defined in dtypes.cc, and we already have a kNumberTypes set in types.h that can be leveraged (see DataTypeIsComplex(...) in that file as an example).

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 just implemented these changes. Does it look fine now? Also, is there any specific ordering to functions in dtypes.cc or types.h to keep it consistent with other files? For the time being, I placed the code for is_numeric and IsNumericDataType right above the code for is_complex and IsComplexDataType.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, looks good now. No special ordering, as long as its somewhat consistent.

Will run through further testing now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi. I'm still waiting on Py+CPP Test Suite - Ubuntu CPU, Python 3.9 and Code Check - Changed Files workflows to be run and approved. It seems odd that it's taking this long. Any ideas why?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, sorry, it broke our API compatibility tests. It shouldn't be a big issue because you only added a read-only attribute, but I'll need to go in and update the API checks, and do some more testing to make sure save/load models doesn't break.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, thanks. Let me know if I need to change anything else.

@gbaned gbaned added the comp:ops OPs related issues label May 9, 2023
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels May 9, 2023
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label May 9, 2023
@google-ml-butler google-ml-butler bot added the kokoro:force-run Tests on submitted change label May 13, 2023
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label May 13, 2023
@google-ml-butler google-ml-butler bot removed the ready to pull PR ready for merge process label May 13, 2023
Copy link
Contributor

@cantonios cantonios left a comment

Choose a reason for hiding this comment

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

Can you add some tests in tensorflow/python/kernel_tests/math_ops/cwise_ops_test.py?

@gbaned gbaned requested a review from cantonios June 1, 2023 05:23
@google-ml-butler google-ml-butler bot added the awaiting review Pull request awaiting review label Jun 1, 2023
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Jun 2, 2023
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jun 2, 2023
@google-ml-butler google-ml-butler bot removed the ready to pull PR ready for merge process label Jun 2, 2023
@gbaned gbaned requested a review from cantonios June 5, 2023 03:55
@gbaned gbaned requested review from cantonios and removed request for cantonios June 12, 2023 06:34
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Jun 12, 2023
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jun 12, 2023
@copybara-service copybara-service bot merged commit 66c34ec into tensorflow:master Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review Pull request awaiting review comp:ops OPs related issues ready to pull PR ready for merge process size:XS CL Change Size: Extra Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants