1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//! Cache-optimized kernels for strided multidimensional array operations.
//!
//! This crate is a Rust port of Julia's [Strided.jl](https://github.com/Jutho/Strided.jl)
//! and [StridedViews.jl](https://github.com/Jutho/StridedViews.jl) libraries, providing
//! efficient operations on strided multidimensional array views.
//!
//! # Core Types
//!
//! - [`StridedView`] / [`StridedViewMut`]: Dynamic-rank strided views over existing data
//! - [`StridedArray`]: Owned strided multidimensional array
//! - [`ElementOp`] trait and implementations ([`Identity`], [`Conj`], [`Transpose`], [`Adjoint`]):
//! Type-level element operations applied lazily on access
//! - [`Exec`] / [`Pool`]: the placement token every fan-out entry takes as its
//! last parameter (re-exported from `threadteam`)
//!
//! # Primary API (view-based, Julia-compatible)
//!
//! ## Map Operations
//!
//! - [`map_into`]: Apply a function element-wise from source to destination
//! - [`zip_map2_into`], [`zip_map3_into`], [`zip_map4_into`]: Multi-array element-wise operations
//!
//! ## In-place Update Operations
//!
//! - [`map_update_into`], [`zip_update2_into`], [`zip_update3_into`]: `dest[i] = f(dest[i], inputs...)`,
//! reading the old destination without a second view of it
//!
//! ## Reduce Operations
//!
//! - [`reduce`]: Full reduction with map function
//! - [`zip_reduce`]: Two-input full reduction with a map function (the
//! widening route, e.g. `f32` operands accumulated in `f64`)
//! - [`reduce_axis`]: Reduce along a single axis
//!
//! A reduction that can fan out (`reduce`, `zip_reduce`, `sum`) gives a result
//! that is independent of the token's budget only for a serial token; `dot`
//! never enters a parallel branch, so its result does not depend on the token at
//! all. See each entry's evaluation-order section.
//!
//! # Threading
//!
//! Every operation that can fan out takes `exec: Exec<'_>` by value as its last
//! parameter. [`Exec::serial`] runs on the calling thread; a token minted from a
//! [`Pool`] with [`Exec::new`] splits the work within its budget. Whether and how
//! wide is decided by the token: the serial time of the region (elements times the
//! throughput of its `execution::KernelClass`) against the dispatch cost of the
//! sections it opens (`Exec::pays`, `Exec::width_for`), so a region too small to
//! repay a fork stays on the calling thread whatever the budget. Without the
//! `parallel` feature every token runs inline.
//!
//! ## Suffix Vocabulary
//!
//! Accumulation is `*_acc`, overwrite is `*_into`, and `*_view` returns metadata
//! only; the table and the names still outside it are in `REPOSITORY_RULES.md`
//! ("Suffix Vocabulary"). `*_into` never reads the previous `dest[i]`, except
//! the update family ([`map_update_into`], [`zip_update2_into`],
//! [`zip_update3_into`]), which updates `dest[i]` in place from its old value.
//!
//! ## Basic Operations
//!
//! - [`copy_into`]: Copy array contents
//! - [`add_acc`], [`mul_acc`]: Accumulating element-wise arithmetic (`dest[i] += src[i]`,
//! `dest[i] *= src[i]`)
//! - [`axpy_acc`]: y = alpha*x + y (array version)
//! - [`fma_acc`]: `dest[i] += a[i] * b[i]`
//! - [`sum`], [`dot`]: Reductions
//! - [`symmetrize_into`], [`symmetrize_conj_into`]: Matrix symmetrization
//!
//! ## Raw Strided Copies
//!
//! Over borrowed [`RawStridedRef`] / [`RawStridedMut`] layouts:
//!
//! - [`CopyPlan`], [`UpdatePlan`]: compile a layout pair once, replay it on
//! exactly that layout
//! - [`replay_copy_raw`], [`replay_map_raw`] and their `_uninit` forms: replay
//! already-fused dims and strides as given, compiling nothing, serially or
//! across the token's budget
//! - [`copy_scale_raw`], [`axpy_raw`] and their `conj` forms: serial copies
//! that fuse the layout on every call
//!
//! # Example
//!
//! ```rust
//! use strided_basic::{StridedView, StridedViewMut, StridedArray, Identity, Exec, 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, Exec::serial()).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
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use MaybeSimdOps;
pub use view;
pub use *;
pub use ;
pub use ;
/// Block memory size for cache-optimized iteration (L1 cache target).
///
/// Operations are blocked into tiles that fit within this size to maximize cache hits.
/// Default: 32KB (typical L1 data cache size).
pub const BLOCK_MEMORY_SIZE: usize = 32 * 1024;
/// Cache line size in bytes.
///
/// Used for memory region calculations in block size computation.
pub const CACHE_LINE_SIZE: usize = 64;
pub use ;
pub use ;
pub use ;