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: tf.function working with set item #28481

Merged
merged 4 commits into from
Mar 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ivy/functional/backends/tensorflow/data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,16 @@ def broadcast_arrays(
) -> List[Union[tf.Tensor, tf.Variable]]:
if len(arrays) > 1:
try:
desired_shape = tf.broadcast_dynamic_shape(arrays[0].shape, arrays[1].shape)
desired_shape = tf.broadcast_dynamic_shape(
tf.shape(arrays[0]), tf.shape(arrays[1])
)
except tf.errors.InvalidArgumentError as e:
raise ivy.utils.exceptions.IvyBroadcastShapeError(e) from e
if len(arrays) > 2:
for i in range(2, len(arrays)):
try:
desired_shape = tf.broadcast_dynamic_shape(
desired_shape, arrays[i].shape
desired_shape, tf.shape(arrays[i])
)
except tf.errors.InvalidArgumentError as e:
raise ivy.utils.exceptions.IvyBroadcastShapeError(e) from e
Expand Down
4 changes: 2 additions & 2 deletions ivy/functional/backends/tensorflow/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ def scatter_nd(
)

expected_shape = (
list(indices.shape[:-1]) + list(out.shape[indices.shape[-1] :])
list(tf.shape(indices)[:-1]) + list(out.shape[tf.shape(indices)[-1] :])
if ivy.exists(out)
else list(indices.shape[:-1]) + list(shape[indices.shape[-1] :])
else list(tf.shape(indices)[:-1]) + list(shape[tf.shape(indices)[-1] :])
)
updates = _broadcast_to(updates, expected_shape)._data
if len(updates.shape) == 0:
Expand Down
2 changes: 1 addition & 1 deletion ivy/functional/backends/tensorflow/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def expand_dims(
out: Optional[Union[tf.Tensor, tf.Variable]] = None,
) -> Union[tf.Tensor, tf.Variable]:
try:
out_shape = _calculate_out_shape(axis, x.shape)
out_shape = _calculate_out_shape(axis, tf.shape(x))
ret = tf.reshape(x, shape=out_shape)
return ret
except (tf.errors.InvalidArgumentError, np.AxisError) as error:
Expand Down
5 changes: 2 additions & 3 deletions ivy/functional/ivy/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2887,15 +2887,14 @@ def set_item(
if ivy.is_array(query) and ivy.is_bool_dtype(query):
if not len(query.shape):
query = ivy.tile(query, (x.shape[0],))
target_shape = ivy.get_item(x, query).shape
indices = ivy.nonzero(query, as_tuple=False)
else:
indices, target_shape, _ = _parse_query(
query, ivy.shape(x, as_array=True), scatter=True
)
if indices is None:
return x
val = _broadcast_to(val, target_shape).astype(x.dtype)
val = val.astype(x.dtype)
ret = ivy.scatter_nd(indices, val, reduction="replace", out=x)
return ret

Expand Down Expand Up @@ -2977,7 +2976,7 @@ def _parse_query(query, x_shape, scatter=False):
elif len(array_inds):
target_shape = (
[list(query[i].shape) for i in range(0, array_inds[0])]
+ [list(array_queries[0].shape)]
+ [list(ivy.shape(array_queries[0], as_array=True))]
+ [[] for _ in range(len(array_inds) - 1)]
+ [list(query[i].shape) for i in range(array_inds[-1] + 1, len(query))]
)
Expand Down
Loading