isContiguous
Determines if this tensor view represents a contiguous memory layout.
A contiguous view is one where the elements can be accessed in a linear fashion without gaps or stride adjustments. Contiguous views offer significant performance advantages for:
Bulk memory operations (copy, fill, etc.)
Vectorized computations
Cache-friendly access patterns
Direct memory mapping to external libraries
Contiguity Analysis
A view is considered contiguous when:
Sequential element access follows natural memory layout
No gaps exist between accessed elements
Stride patterns match expected row-major or column-major order
View boundaries align with natural tensor structure
Performance Implications
Contiguous Views:
Enable bulk memory operations
Support vectorized SIMD instructions
Provide optimal cache locality
Allow direct interfacing with BLAS/LAPACK libraries
Non-Contiguous Views:
Require element-by-element access
May have poor cache performance
Need coordinate transformation for each access
Cannot use optimized bulk operations
Usage Examples
val tensor = tensorOf(Shape(4, 4)) { /* data */}
// Contiguous slice (full rows)
val contiguousView = tensor.sliceView { range(1, 3) }
println(contiguousView.isContiguous()) // true
// Non-contiguous slice (columns)
val nonContiguousView = tensor.sliceView { at(0); range(1, 3) }
println(nonContiguousView.isContiguous()) // falseReturn
true if the view represents contiguous memory layout, false otherwise
Parameters
the data type constraint extending DType
the actual value type that will be stored and accessed