TensorView

interface TensorView<T : DType, V> : Tensor<T, V> (source)

A tensor view interface that represents a zero-copy slice or subset of a parent tensor.

TensorView extends the base Tensor interface while adding view-specific functionality for efficient tensor slicing operations. Views provide memory-efficient access to portions of larger tensors without copying the underlying data.

Key Characteristics

  • Zero-Copy: Views reference the parent tensor's data without duplication

  • Shape Transformation: Views can have different shapes than their parent

  • Index Mapping: Coordinate transformation between view space and parent space

  • Memory Efficiency: Multiple views can reference the same underlying data

Usage Patterns

Views are particularly useful for:

  • Batch processing (extracting mini-batches from larger datasets)

  • Channel extraction (accessing specific feature maps in NCHW tensors)

  • Spatial regions (selecting rectangular areas in image tensors)

  • Sequence windows (sliding window operations on temporal data)

Parameters

T

the data type constraint extending DType, defining the numerical precision

V

the actual value type that will be stored and accessed

Inheritors

Properties

Link copied to clipboard

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

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

The parent tensor that this view references.

Link copied to clipboard
open override val shape: Shape

Override the shape property to return the view-specific shape.

Link copied to clipboard
abstract val viewShape: Shape

The shape of this view, which may differ from the parent tensor's shape.

Functions

Link copied to clipboard

Provides a more detailed contiguity analysis with diagnostic information.

Link copied to clipboard

Checks if this tensor view can be materialized using the default strategy.

Checks if this tensor view can be materialized using a specific strategy.

Link copied to clipboard

Estimates the memory overhead of materializing this tensor view.

Estimates the memory overhead of materializing this tensor view with a specific strategy.

Link copied to clipboard

Determines if this tensor view represents a contiguous memory layout.

Link copied to clipboard

Materializes this tensor view into a standalone tensor using the default strategy.

Materializes this tensor view using a specific materialization strategy.

Link copied to clipboard
fun <T : DType, V> TensorView<T, V>.sliceView(builder: TensorSliceBuilder<T, V>.() -> Unit): TensorView<T, V>

Creates a view of an existing tensor view, enabling view chaining.