Skip to content

Commit

Permalink
fixed undefined name ivy_container
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeetech authored Oct 12, 2023
1 parent a2ad18d commit 24629a3
Showing 1 changed file with 60 additions and 60 deletions.
120 changes: 60 additions & 60 deletions ivy/data_classes/container/experimental/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3956,63 +3956,63 @@ def concat_from_sequence(


def sequence_insert(
data: ivy_container.Container,
indices: Union[ivy_container.Container, ivy.Array],
values: Union[ivy_container.Container, ivy.Array],
axis: Optional[int] = None,
/,
*,
out: None = None,
) -> ivy_container.Container:
"""Inserts values into a sequence at the specified indices.
Parameters
----------
data
The sequence to insert into.
indices
The indices to insert at.
values
The values to insert.
axis
The axis along which to insert. If None, the last axis is used.
out
The output sequence.
Returns
-------
ret
The returned container has the same shape as `data`, but with the values inserted
at the specified indices.
Examples
--------
>>> data = ivy_container.Container(ivy.ones((4,)), (4,))
>>> indices = ivy_container.Container(ivy.tensor([1, 3]), (2,))
>>> values = ivy_container.Container(ivy.tensor([5, 6]), (2,))
>>> print(sequence_insert(data, indices, values))
Container([1. 5. 2. 6. 4.], (5,))
>>> print(sequence_insert(data, indices, values, axis=0))
Container([[1. 5.]
[2. 6.]
[4.]], (3, 2))
"""

if axis is None:
axis = -1

indices = ivy_container.asarray(indices, dtype=ivy.int64)
values = ivy_container.asarray(values, dtype=data.dtype)

# Flatten the indices and values tensors.
indices = indices.ravel()
values = values.ravel()

# Create a new tensor with the values inserted at the specified indices.
new_tensor = ivy.concatenate(
[data[: indices[0]], values, data[indices[-1:] + 1]], axis=axis
)

return ivy_container.Container(new_tensor, data.shape)
  data: ivy.Array,
  indices: Union[ivy.Array, int],
  values: ivy.Array,
  axis: Optional[int] = None,
  /,
  *,
  out: None = None,
) -> ivy.Array:
  """Inserts values into a sequence at the specified indices.
  Parameters
  ----------
  data
    The sequence to insert into.
  indices
    The indices to insert at.
  values
    The values to insert.
  axis
    The axis along which to insert. If None, the last axis is used.
  out
    The output sequence.
  Returns
  -------
  ret
    The returned array has the same shape as `data`, but with the values inserted
    at the specified indices.
  Examples
  --------
  >>> data = ivy.array([1, 2, 3, 4])
  >>> indices = ivy.array([1, 3])
  >>> values = ivy.array([5, 6])
  >>> print(sequence_insert(data, indices, values))
  ivy.array([1, 5, 2, 6, 4])
  >>> print(sequence_insert(data, indices, values, axis=0))
  ivy.array([[1, 5],
   [2, 6],
   [4]])
  """

  if axis is None:
    axis = -1

  indices = ivy.asarray(indices, dtype=ivy.int64)
  values = ivy.asarray(values, dtype=data.dtype)

  # Flatten the indices and values tensors.
  indices = indices.ravel()
  values = values.ravel()

  # Create a new tensor with the values inserted at the specified indices.
  new_tensor = ivy.concatenate(
    [data[: indices[0]], values, data[indices[-1:] + 1]], axis=axis
  )

  return new_tensor

0 comments on commit 24629a3

Please sign in to comment.