mindspore.hal.contiguous_tensors_handle.ContiguousTensorsHandle
- class mindspore.hal.contiguous_tensors_handle.ContiguousTensorsHandle(tensor_list, enable_mem_align=True)[source]
ContiguousTensorsHandle is a handle manage continuous memory.
- Parameters
- Returns
ContiguousTensorsHandle, a manager with contiguous memory.
Examples
>>> import numpy as np >>> import mindspore as ms >>> from mindspore import Tensor >>> from mindspore.hal.contiguous_tensors_handle import ContiguousTensorsHandle >>> x = Tensor(np.array([1, 2, 3]).astype(np.float32)) >>> y = Tensor(np.array([4, 5, 6]).astype(np.float32)) >>> handle = ContiguousTensorsHandle([x, y], True) >>> print(handle[0].shape) [1] >>> print(handle[1: 3].asnumpy()) [2, 3]
- slice_by_tensor_index(start=None, end=None)[source]
Return the tensor which is sliced by tensor index.
- Parameters
- Returns
Tensor,is sliced by tensor index.
- Raises
TypeError – If start or end, is neither an 'int' nor a 'none'.
ValueError – If values of start or end are negative, or out of the list range, or start >= end.
Examples
>>> import numpy as np >>> import mindspore as ms >>> from mindspore import Tensor >>> from mindspore.hal.contiguous_tensors_handle import ContiguousTensorsHandle >>> x = Tensor(np.array([1, 2, 3]).astype(np.float32)) >>> y = Tensor(np.array([4, 5, 6]).astype(np.float32)) >>> handle = ContiguousTensorsHandle([x, y], True) >>> print(output.slice_by_tensor_index(0, 1).asnumpy()) [1, 2, 3]