You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sparse tensor construction given repeated indices #371
TensorFlow behaves differently (and surprisingly) to SciPy when converting sparse matrices to dense matrices.
importtensorflowastfimportscipyasspimportscipy.sparsei= [0, 0]
j= [0, 0]
values= [1, 2]
sp_answer=sp.sparse.coo_matrix((values, (i, j))).todense()
print("SciPy's answer is "+str(sp_answer)) # prints [[3]]tf_answer=tf.sparse_to_dense([i, j], [1, 1], values, 0)
print("TF's answer is "+str(tf.Session().run(tf_answer))) # prints [[2]]
Specifically, if an index pair is repeated, then SciPy will sum the corresponding values, while TF just keeps the last value.
Is this behaviour intentional or accidental? If it's intentional, I'll make a pull request to add a mention of it to the docs. If it's accidental, I'll make a pull request to fix it.
It's intentional. The C++ SparseTensor code has a IndicesValid method for checking validity of a SparseTensor; and this check would fail on repeated indices. However most of the ops that use STs don't run it for efficiency.
Please note our current contributions flow is not through GitHub; see contributing.
Activity
ebrevdo commentedon Nov 29, 2015
It's intentional. The C++ SparseTensor code has a IndicesValid method for checking validity of a SparseTensor; and this check would fail on repeated indices. However most of the ops that use STs don't run it for efficiency.
Please note our current contributions flow is not through GitHub; see contributing.
vrv commentedon Dec 1, 2015
So @ebrevdo, the answer is to document this difference in behavior?
vrv commentedon Dec 23, 2015
@andyljones: we now accept PRs, so if you want to fix the docs, please send it!
Update XNNPACK in XLA