Skip to content
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

Fix <unknown> shape issue for sparse.transpose #38142

Merged
merged 3 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions tensorflow/python/framework/sparse_tensor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import numpy as np

from tensorflow.python.eager import context
from tensorflow.python.eager import def_function
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.framework import sparse_tensor
Expand Down Expand Up @@ -59,6 +60,16 @@ def testPythonConstruction(self):
self.assertAllEqual(sess_run_value.values, value.values)
self.assertAllEqual(sess_run_value.dense_shape, value.dense_shape)

def testShape(self):
@def_function.function
def test_fn(tensor):
tensor = sparse_ops.sparse_transpose(tensor)
self.assertEqual(tensor.shape.rank, 2)
return tensor
tensor = sparse_tensor.SparseTensor(
indices=[[0, 0], [1, 2]], values=[1., 2], dense_shape=[3, 4])
test_fn(tensor)

def testIsSparse(self):
self.assertFalse(sparse_tensor.is_sparse(3))
self.assertFalse(sparse_tensor.is_sparse("foo"))
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/python/ops/sparse_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2594,8 +2594,8 @@ def sparse_transpose(sp_input, perm=None, name=None):
"""
with ops.name_scope(name, "SparseTranspose", [sp_input]) as name:
if perm is None:
if sp_input.shape.is_fully_defined():
rank = len(sp_input.shape)
if sp_input.shape.rank is not None:
rank = sp_input.shape.rank
perm = (rank - 1) - np.arange(0, rank, 1)
else:
rank = array_ops.rank(sp_input)
Expand Down