Expand description
Cache-optimized kernels for strided multidimensional array operations.
This crate is a Rust port of Julia’s Strided.jl and StridedViews.jl libraries, providing efficient operations on strided multidimensional array views.
§Core Types
StridedView/StridedViewMut: Dynamic-rank strided views over existing dataStridedArray: Owned strided multidimensional arrayElementOptrait and implementations (Identity,Conj,Transpose,Adjoint): Type-level element operations applied lazily on access
§Primary API (view-based, Julia-compatible)
§Map Operations
map_into: Apply a function element-wise from source to destinationzip_map2_into,zip_map3_into,zip_map4_into: Multi-array element-wise operations
§Reduce Operations
reduce: Full reduction with map functionreduce_axis: Reduce along a single axis
§Basic Operations
copy_into: Copy array contentsadd,mul: Element-wise arithmeticaxpy: y = alpha*x + y (array version)sum,dot: Reductionssymmetrize_into,symmetrize_conj_into: Matrix symmetrization
§Example
use strided_kernel::{StridedView, StridedViewMut, StridedArray, Identity, map_into};
// Create a column-major array (Julia default)
let src = StridedArray::<f64>::from_fn_col_major(&[2, 3], |idx| {
(idx[0] * 10 + idx[1]) as f64
});
let mut dest = StridedArray::<f64>::col_major(&[2, 3]);
// Map with view-based API
map_into(&mut dest.view_mut(), &src.view(), |x| x * 2.0).unwrap();
assert_eq!(dest.get(&[1, 2]), 24.0); // (1*10 + 2) * 2§Cache Optimization
The library uses Julia’s blocking strategy for cache efficiency:
- Dimensions are sorted by stride magnitude for optimal memory access
- Operations are blocked into tiles fitting L1 cache (
BLOCK_MEMORY_SIZE= 32KB) - Contiguous arrays use fast paths bypassing the blocking machinery
Modules§
- view
- Julia-like dynamic-rank strided view types.
Structs§
- Adjoint
- Adjoint operation: f(x) = adjoint(x) = conj(transpose(x)) For scalar numbers, this is conj.
- Conj
- Complex conjugate operation: f(x) = conj(x)
- Identity
- Identity operation: f(x) = x
- Strided
Array - Owned strided multidimensional array.
- Strided
View - Dynamic-rank immutable strided view with lazy element operations.
- Strided
View Mut - Dynamic-rank mutable strided view.
- Transpose
- Transpose operation: f(x) = transpose(x) For scalar numbers, this is identity. For matrix elements, this would transpose each element.
Enums§
- Strided
Error - Errors that can occur during strided array operations.
Constants§
- BLOCK_
MEMORY_ SIZE - Block memory size for cache-optimized iteration (L1 cache target).
- CACHE_
LINE_ SIZE - Cache line size in bytes.
Traits§
- Composable
Element Op - Trait for element operations that support type-level composition.
- Compose
- Helper trait for composing two ElementOp types.
- Element
Op - Trait for element-wise operations applied to strided views.
- Element
OpApply - Trait for types that support element operations (conj, transpose, adjoint).
- Maybe
Send - Equivalent to
Sendwhenparallelis enabled; blanket-impl otherwise. - Maybe
Send Sync - Equivalent to
Send+Syncwhenparallelis enabled; blanket-impl otherwise. - Maybe
Simd Ops - Trait for types that may have SIMD-accelerated sum/dot operations.
- Maybe
Sync - Equivalent to
Syncwhenparallelis enabled; blanket-impl otherwise.
Functions§
- add
- Element-wise addition:
dest[i] += src[i]. - axpy
- AXPY:
dest[i] = alpha * src[i] + dest[i]. - col_
major_ strides - Compute column-major strides (Julia default: first index varies fastest).
- copy_
conj - Copy with complex conjugation:
dest[i] = conj(src[i]). - copy_
into - Copy elements from source to destination:
dest[i] = src[i]. - copy_
scale - Copy with scaling:
dest[i] = scale * src[i]. - copy_
transpose_ scale_ into - Copy with transpose and scaling:
dest[j,i] = scale * src[i,j]. - dot
- Dot product:
sum(OpA::apply(a[i]) * OpB::apply(b[i])). - fma
- Fused multiply-add:
dest[i] += OpA::apply(a[i]) * OpB::apply(b[i]). - map_
into - Apply a function element-wise from source to destination.
- mul
- Element-wise multiplication:
dest[i] *= src[i]. - reduce
- Full reduction with map function:
reduce(init, op, map.(src)). - reduce_
axis - Reduce along a single axis, returning a new StridedArray.
- row_
major_ strides - Compute row-major strides (C default: last index varies fastest).
- sum
- Sum all elements:
sum(src). - symmetrize_
conj_ into - Conjugate-symmetrize a square matrix:
dest = (src + conj(src^T)) / 2. - symmetrize_
into - Symmetrize a square matrix:
dest = (src + src^T) / 2. - zip_
map2_ into - Binary element-wise operation:
dest[i] = f(a[i], b[i]). - zip_
map3_ into - Ternary element-wise operation:
dest[i] = f(a[i], b[i], c[i]). - zip_
map4_ into - Quaternary element-wise operation:
dest[i] = f(a[i], b[i], c[i], e[i]).
Type Aliases§
- Result
- Result type for strided array operations.