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
Does tf.math.equal supports tf.sparse.SparseTensor? #50189
Comments
@Saduf2019 |
Hey I'm new to contributing to open source, can I work on this issue? |
Thanks for working on the issue. I'm using this temporary hack as a workaround atm. import tensorflow as tf
from tensorflow.sparse import SparseTensor
def sparse_tensor_not_equal(a: SparseTensor, b: SparseTensor) -> SparseTensor:
diff = tf.math.abs(tf.sparse.add(tf.math.negative(a), b))
diff = tf.cast(diff, bool)
return diff
def sparse_tensor_equal(a: SparseTensor, b: SparseTensor) -> SparseTensor:
diff = sparse_tensor_not_equal(a, b)
is_equal = tf.sparse.map_values(tf.math.logical_not, diff)
return is_equal
a = tf.sparse.SparseTensor(indices=[[0, 0], [0, 1], [1, 2]], values=[1, 1, 1], dense_shape=[2, 3])
b = tf.sparse.SparseTensor(indices=[[0, 1], [0, 2], [1, 1], [1, 2]], values=[1, 1, 1, 1], dense_shape=[2, 3])
print(sparse_tensor_equal(a, b)) |
Looking at the code, it looks to me like It would certainly be possible to extend As for other ops in |
@HongtaoYang |
Thanks, the comment helps, thanks @edloper ! I'll close this issue. |
…ly claimed to support SparseTensor inputs. Github issue: #50189 PiperOrigin-RevId: 444931142
Fixed the documentation in 011e57d. |
URL with the issue:
https://www.tensorflow.org/api_docs/python/tf/math/equal
Description of issue (what needs changing):
The doc says
tf.math.equal
supports sparse tensor as inputs, but it is actually not supported at the moment. See the example below. I haven't checked all math operations that claims to support sparse tensors, maybe there are other similar doc errors like this.I'm using tf
2.6.0-dev20210601
.Usage example
I think making
equal
operation supports sparse tensor is needed.The text was updated successfully, but these errors were encountered: