DefaultTensorViewStrategy

Default implementation of TensorViewStrategy that prefers views when possible.

This strategy implements a conservative approach that favors zero-copy views for most operations while falling back to copying only in specific cases where views would be significantly inefficient.

Decision Logic

The strategy creates views when:

  • Slices are contiguous or have reasonable stride patterns

  • The parent tensor is not excessively large relative to the view

  • The slice doesn't result in highly scattered memory access

The strategy falls back to copying when:

  • Slices would result in very inefficient strided access patterns

  • Memory pressure is detected (not implemented in this basic version)

  • The view would be much smaller than the parent (preventing GC)

Inheritors

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

Maximum stride factor before preferring copy over view. If any dimension has a stride larger than this factor times the base dimension size, copying is preferred.

Link copied to clipboard

Threshold for view size relative to parent size. If the view is smaller than this fraction of the parent, copying might be preferred to allow parent GC.

Functions

Link copied to clipboard
open override 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
open override fun shouldCreateView(tensor: Tensor<T, V>, slices: List<Slice<T, V>>): Boolean

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