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

feat: added the tensor operations for slicing, mutations, joinings and indexing #26558

Closed
wants to merge 15 commits into from
Closed
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
193 changes: 0 additions & 193 deletions determine_tests.py

This file was deleted.

26 changes: 26 additions & 0 deletions ivy/data_classes/array/experimental/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,3 +1080,29 @@ def fill_diagonal(
ivy.fill_diag also applies to this method with minimal changes.
"""
return ivy.fill_diagonal(self._data, v, wrap=wrap)


def tensor_ops(tensor, operation_type, *args):
if operation_type == "index":
if len(args) != 1:
raise ValueError
index = args[0]
return tensor[index]
elif operation_type == "slice":
if len(args) != 2:
raise ValueError
start, end = args
return tensor[start:end]
elif operation_type == "join":
if len(args) != 1:
raise ValueError
other_tensor = args[0]
return ivy.cat((tensor, other_tensor), dim=0)
elif operation_type == "mutate":
if len(args) != 1:
raise ValueError
factor = args[0]
tensor.mul_(factor)
return tensor
else:
raise ValueError
27 changes: 27 additions & 0 deletions ivy/data_classes/container/experimental/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2996,3 +2996,30 @@ def fill_diagonal(
v,
wrap=wrap,
)


@staticmethod
def tensor_ops(tensor, operation_type, *args):
if operation_type == "index":
if len(args) != 1:
raise ValueError
index = args[0]
return tensor[index]
elif operation_type == "slice":
if len(args) != 2:
raise ValueError
start, end = args
return tensor[start:end]
elif operation_type == "join":
if len(args) != 1:
raise ValueError
other_tensor = args[0]
return ivy.cat((tensor, other_tensor), dim=0)
elif operation_type == "mutate":
if len(args) != 1:
raise ValueError
factor = args[0]
tensor.mul_(factor)
return tensor
else:
raise ValueError
26 changes: 26 additions & 0 deletions ivy/functional/backends/jax/experimental/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,29 @@ def fill_diagonal(
a = a.at[:end:step].set(jnp.array(v).astype(a.dtype))
a = jnp.reshape(a, shape)
return a


def tensor_ops(tensor, operation_type, *args):
if operation_type == "index":
if len(args) != 1:
raise ValueError
index = args[0]
return tensor[index]
elif operation_type == "slice":
if len(args) != 2:
raise ValueError
start, end = args
return tensor[start:end]
elif operation_type == "join":
if len(args) != 1:
raise ValueError
other_tensor = args[0]
return ivy.cat((tensor, other_tensor), dim=0)
elif operation_type == "mutate":
if len(args) != 1:
raise ValueError
factor = args[0]
tensor.mul_(factor)
return tensor
else:
raise ValueError
26 changes: 26 additions & 0 deletions ivy/functional/backends/numpy/experimental/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,29 @@ def fill_diagonal(
) -> np.ndarray:
np.fill_diagonal(a, v, wrap=wrap)
return a


def tensor_ops(tensor, operation_type, *args):
if operation_type == "index":
if len(args) != 1:
raise ValueError
index = args[0]
return tensor[index]
elif operation_type == "slice":
if len(args) != 2:
raise ValueError
start, end = args
return tensor[start:end]
elif operation_type == "join":
if len(args) != 1:
raise ValueError
other_tensor = args[0]
return ivy.cat((tensor, other_tensor), dim=0)
elif operation_type == "mutate":
if len(args) != 1:
raise ValueError
factor = args[0]
tensor.mul_(factor)
return tensor
else:
raise ValueError
26 changes: 26 additions & 0 deletions ivy/functional/backends/tensorflow/experimental/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,29 @@ def fill_diagonal(
a = tf.tensor_scatter_nd_update(a, indices, ups)
a = tf.reshape(a, shape)
return a


def tensor_ops(tensor, operation_type, *args):
if operation_type == "index":
if len(args) != 1:
raise ValueError
index = args[0]
return tensor[index]
elif operation_type == "slice":
if len(args) != 2:
raise ValueError
start, end = args
return tensor[start:end]
elif operation_type == "join":
if len(args) != 1:
raise ValueError
other_tensor = args[0]
return ivy.cat((tensor, other_tensor), dim=0)
elif operation_type == "mutate":
if len(args) != 1:
raise ValueError
factor = args[0]
tensor.mul_(factor)
return tensor
else:
raise ValueError
26 changes: 26 additions & 0 deletions ivy/functional/backends/torch/experimental/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,29 @@ def fill_diagonal(
a = torch.where(w, v, a)
a = torch.reshape(a, shape)
return a


def tensor_ops(tensor, operation_type, *args):
if operation_type == "index":
if len(args) != 1:
raise ValueError
index = args[0]
return tensor[index]
elif operation_type == "slice":
if len(args) != 2:
raise ValueError
start, end = args
return tensor[start:end]
elif operation_type == "join":
if len(args) != 1:
raise ValueError
other_tensor = args[0]
return ivy.cat((tensor, other_tensor), dim=0)
elif operation_type == "mutate":
if len(args) != 1:
raise ValueError
factor = args[0]
tensor.mul_(factor)
return tensor
else:
raise ValueError
10 changes: 0 additions & 10 deletions ivy/functional/frontends/paddle/nn/functional/norm.py

This file was deleted.

Loading
Loading