SlicedTensorView

class SlicedTensorView<T : DType, V>(val parentTensor: Tensor<T, V>, slices: List<Slice<T, V>>) : TensorView<T, V> (source)

A concrete implementation of TensorView that provides zero-copy sliced access to parent tensors.

SlicedTensorView creates a view of a parent tensor by applying a list of slice operations, one for each dimension. The view appears as a regular tensor but delegates all data access through coordinate transformation to the parent tensor's storage.

Key Features

  • Zero-Copy Operations: No data duplication, only metadata storage

  • Lazy Evaluation: Shape and index mapping computed on construction

  • Efficient Access: Optimized coordinate transformation for common patterns

  • Type Safety: Maintains type constraints from parent tensor

Memory Layout Considerations

The view maintains minimal memory overhead:

  • Reference to parent tensor

  • Computed view shape

  • Index mapper instance

  • Slice list (for potential reuse/optimization)

Performance Characteristics

Access performance depends on slice patterns:

  • Contiguous slices: Near-native performance

  • Strided slices: Moderate overhead from coordinate calculation

  • Complex patterns: Higher overhead but still zero-copy

Parameters

T

the data type constraint extending DType

V

the actual value type

parentTensor

the parent tensor to create a view of

slices

list of slice operations, one per dimension

Constructors

Link copied to clipboard
constructor(parentTensor: Tensor<T, V>, slices: List<Slice<T, V>>)

Properties

Link copied to clipboard
open override val data: TensorData<T, V>

Delegate data access to a wrapper that handles coordinate transformation.

Link copied to clipboard
open override val dtype: KClass<T>

Inherit data type from parent tensor.

Link copied to clipboard
open override val gradState: GradState<T, V>

Gradient state tied to this tensor instance.

Link copied to clipboard
open override val indexMapping: IndexMapper

The index mapper for coordinate transformation between view and parent space.

Link copied to clipboard
open override val ops: TensorOps

Inherit operations component from parent tensor.

Link copied to clipboard
open override val parentTensor: Tensor<T, V>
Link copied to clipboard

The slice operations applied to create this view.

Link copied to clipboard
open override val viewShape: Shape

The computed shape of this view after applying all slice operations.