sliceCopy

fun <T : DType, V> Tensor<T, V>.sliceCopy(builder: TensorSliceBuilder<T, V>.() -> Unit): Tensor<T, V>(source)

Creates a new tensor by copying data from the sliced region of this tensor.

This method provides backward compatibility with existing tensor operations that expect independent tensor instances. Unlike sliceView(), this creates a completely separate tensor with copied data.

Usage Example

val copy = tensor.sliceCopy {
segment { range(0, 10) }
segment { all() }
}
// `copy` is an independent tensor with copied data

Performance Characteristics

  • Data copy: Duplicates selected data into new tensor

  • Independent: No shared memory with parent tensor

  • Compatible: Works with all existing tensor operations

Return

a new Tensor containing copied data from the sliced region

Parameters

builder

the DSL block that configures the slicing operation

Throws

if slice configuration is invalid