select_batch

Tensor.select_batch(batch: List[int])

Selects a batch of elements along the batch dimension from the original Tensor object, and returns a new Tensor object that shares the underlying memory with the original Tensor object.

Both the returned tensor and the original tensor reference the same memory address.

Note

The returned tensor becomes invalid if the original tensor is destroyed. Accessing the returned tensor after the original tensor has been destroyed may result in undefined behavior due to a dangling pointer.

Parameters:

batch (List[int]) -- A list of batch indices specifying the batch elements to select.

Returns:

A new object that referencing the selected batch of elements form the original tensor.

Return type:

Tensor

Raises:

RuntimeError -- If the batch selection operation fails.