batchMaterialize

Materializes a list of tensor views into a list of standalone tensors efficiently.

This method provides batch materialization of multiple tensor views, which can offer performance benefits over materializing views individually. The batch operation can optimize for:

  • Memory allocation patterns

  • CPU cache efficiency

  • Parallel processing opportunities

  • Reduced overhead from repeated strategy initialization

Batch Processing Benefits

Memory Optimization:

  • Pre-allocates memory for all materialized tensors

  • Reduces memory fragmentation

  • Enables memory pool optimizations

Performance Optimization:

  • Amortizes strategy setup costs across multiple views

  • Enables vectorized operations when possible

  • Reduces system call overhead

Resource Management:

  • Coordinates garbage collection timing

  • Manages memory pressure more effectively

  • Provides better resource utilization monitoring

Usage Examples

val parentTensor = tensorOf(Shape(100, 100)) { /* data */}
val views = listOf(
parentTensor.sliceView { range(0, 25) },
parentTensor.sliceView { range(25, 50) },
parentTensor.sliceView { range(50, 75) },
parentTensor.sliceView { range(75, 100) }
)

// Batch materialize all views efficiently
val materialized = views.batchMaterialize()

Performance Considerations

Batch materialization is most beneficial when:

  • Processing multiple views from the same parent tensor

  • Views have similar complexity and size characteristics

  • Memory allocation overhead is significant compared to data copying

  • The system benefits from predictable memory allocation patterns

Return

a List of materialized Tensor objects corresponding to the input views

Parameters

T

the data type constraint extending DType

V

the actual value type that will be stored and accessed

Throws

if any view cannot be materialized


Materializes a list of tensor views using a specific materialization strategy.

This overload allows explicit control over the materialization strategy used for the entire batch operation, enabling optimization for specific use cases or resource constraints.

Return

a List of materialized Tensor objects using the specified strategy

Parameters

T

the data type constraint extending DType

V

the actual value type that will be stored and accessed

strategy

the MaterializationStrategy to use for all views in the batch

Throws

if the strategy cannot materialize any view