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
the data type constraint extending DType
the actual value type that will be stored and accessed