Commit 2a956c9b authored by Yong Tang's avatar Yong Tang
Browse files

Support string tensors for tf.count_nonzero



This fix tries to address the issue raised in 18712 where
`tf.count_nonzero` does not support string tensors.

The implementation of `tf.count_nonzero` relies on `tf.not_equal`
which actually support string tensors. The reason the string
tensor does not work is because `tf.count_nonzero` created
a numpy type `zero` which uses `input_tensor.dtype.as_numpy_dtype()`.
The numpy type `zero` is then passed to `tf.not_equal (which converts
numpy `zero` into a tensor zero). However,
`input_tensor.dtype.as_numpy_dtype()` will converts tf.string to
numpy.object thus the exception.

But that is not necessary as `zero` could be created
with `tf.zeros` directly without back and forth conversion
to numpy.

This fix fixes the issue.

This fix fixes 18712.

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>
parent 4475bb71
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment