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(ops): sizes == -1 was interpreted incorrectly #218

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion tf2jax/_src/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ def _func(
sizes: jnp.ndarray,
) -> jnp.ndarray:
"""`begins` and `sizes` must be concrete arrays."""
slices = [slice(b, b + s) for b, s in safe_zip(begins, sizes)]
slices = [slice(b, b + s if slice != -1 else None) for b, s in safe_zip(begins, sizes)]
return x[tuple(slices)]

return _func
Expand Down
2 changes: 1 addition & 1 deletion tf2jax/_src/ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ def size_static():

@chex.variants(with_jit=True, without_jit=True)
def test_slice(self):
inputs, begins, sizes = [np.array([[1, 2], [3, 4], [5, 6]]), [1, 1], [2, 1]]
inputs, begins, sizes = [np.array([[1, 2], [3, 4], [5, 6]]), [1, 1], [2, -1]]

def slice_fn(xs):
return tf.raw_ops.Slice(input=xs, begin=begins, size=sizes)
Expand Down
Loading