TensorViewStrategy

Strategy interface for deciding between view creation and tensor copying.

This interface provides the foundation for implementing fallback mechanisms when tensor views are not suitable or efficient for particular slicing operations. The strategy helps balance memory efficiency with performance considerations.

Use Cases

  • Complex Non-Contiguous Slices: When slice patterns result in very inefficient memory access patterns

  • Memory Pressure: When system memory is under pressure and views might prevent garbage collection of large parent tensors

  • Backend Limitations: When the underlying compute backend doesn't support efficient view operations

Parameters

T

the data type constraint extending DType

V

the actual value type

Inheritors

Functions

Link copied to clipboard
abstract fun getDecisionReason(tensor: Tensor<T, V>, slices: List<Slice<T, V>>): String

Provides a reason code for the view vs copy decision.

Link copied to clipboard
abstract fun shouldCreateView(tensor: Tensor<T, V>, slices: List<Slice<T, V>>): Boolean

Determines whether a view should be created for the given slices.