CopyMaterializationStrategy

A materialization strategy that immediately copies all data from a tensor view into a new, standalone tensor with contiguous memory layout.

This strategy provides immediate materialization by iterating through all elements in the view and copying them to a new tensor with the view's shape. The resulting tensor is completely independent of the parent tensor and can be used even after the parent tensor is garbage collected.

Characteristics

  • Immediate Execution: Materialization happens synchronously when called

  • Memory Independent: Result tensor has no dependencies on parent tensor

  • Contiguous Layout: Output data is stored in standard row-major order

  • Type Preservation: Maintains the same data type and value type as the view

Trade-offs

Benefits:

  • Predictable memory usage and performance

  • No ongoing computational overhead for element access

  • Enables garbage collection of parent tensors

  • Compatible with all downstream operations

Costs:

  • Immediate memory allocation for full tensor size

  • Computational cost of copying all elements

  • Temporary memory pressure during materialization

Usage Scenarios

This strategy is optimal when:

  • The materialized tensor will be accessed frequently

  • Memory usage is predictable and acceptable

  • The parent tensor can be released after materialization

  • Compatibility with external libraries is required

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
open override fun materialize(view: TensorView<T, V>): Tensor<T, V>

Materializes the given tensor view into a concrete tensor.