LazyMaterializationStrategy

A materialization strategy that defers copying of tensor view data until individual elements are actually accessed.

This strategy creates a materialized tensor that maintains a reference to the original view but caches accessed elements in a sparse data structure. Elements are copied from the view only when first accessed, providing memory efficiency for cases where only a subset of the tensor data is used.

Characteristics

  • Deferred Execution: Elements are copied only when accessed

  • Sparse Caching: Only accessed elements consume additional memory

  • Lazy Evaluation: Computation overhead is distributed over access time

  • Memory Efficient: Optimal for partial access patterns

Trade-offs

Benefits:

  • Lower initial memory allocation

  • Efficient for sparse access patterns

  • Allows partial materialization of large views

  • Maintains parent reference efficiency for unaccessed elements

Costs:

  • Per-access overhead for coordinate transformation

  • Additional memory overhead for caching metadata

  • Potential synchronization complexity in multi-threaded access

  • Parent tensor cannot be garbage collected until full materialization

Usage Scenarios

This strategy is optimal when:

  • Only a subset of tensor elements will be accessed

  • Memory is constrained and immediate full copying is not feasible

  • Access patterns are sparse or unknown at materialization time

  • The parent tensor should remain available for other operations

Parameters

T

the data type constraint extending DType

V

the actual value type that will be stored and accessed

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
open override val name: String

Gets a human-readable name for this materialization strategy.

Functions

Link copied to clipboard
open override fun canMaterialize(view: TensorView<T, V>): Boolean

Checks if this strategy can materialize the given view.

Link copied to clipboard
open override fun estimateMemoryOverhead(view: TensorView<T, V>): Long

Estimates the memory overhead of materializing the given view.

Link copied to clipboard
fun forceMaterialize(tensor: Tensor<T, V>): Tensor<T, V>

Provides access to force materialization of a lazy tensor. This is useful for debugging or when full materialization is eventually needed.

Link copied to clipboard
open override fun materialize(view: TensorView<T, V>): Tensor<T, V>

Materializes the given tensor view into a concrete tensor.