Skip to content

Fix TensorFlowTensor.index_update by casting values to dtype of the raw tensor #59

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions eagerpy/tensor/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def index_update(
x = self.raw
if isinstance(indices, int):
if isinstance(values_, int) or isinstance(values_, float):
values_ = tf.fill(x.shape[-1:], values_)
values_ = tf.cast(tf.fill(x.shape[-1:], values_), x.dtype)
return type(self)(
tf.tensor_scatter_nd_update(x, [[indices]], values_[None])
)
Expand All @@ -350,7 +350,7 @@ def index_update(
):
x = tf.transpose(x)
if isinstance(values_, int) or isinstance(values_, float):
values_ = tf.fill(x.shape[-1:], values_)
values_ = tf.cast(tf.fill(x.shape[-1:], values_), x.dtype)
result = tf.tensor_scatter_nd_update(x, [[indices[-1]]], values_[None])
return type(self)(tf.transpose(result))
else:
Expand All @@ -363,7 +363,7 @@ def index_update(
]
indices = tf.stack(indices, axis=-1)
if isinstance(values_, int) or isinstance(values_, float):
values_ = tf.fill((indices.shape[0],), values_)
values_ = tf.cast(tf.fill((indices.shape[0],), values_), x.dtype)
return type(self)(tf.tensor_scatter_nd_update(x, indices, values_))
else:
raise ValueError # pragma: no cover
Expand Down