@danielsimonjr/mathts-parallel 0.6.4 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -21
- package/dist/ComputePool.d.ts +548 -0
- package/dist/ComputePool.d.ts.map +1 -0
- package/dist/index.d.ts +13 -1281
- package/dist/index.d.ts.map +1 -0
- package/dist/matrix.worker.d.ts +13 -2
- package/dist/matrix.worker.d.ts.map +1 -0
- package/dist/operations/elementwise.d.ts +86 -0
- package/dist/operations/elementwise.d.ts.map +1 -0
- package/dist/operations/index.d.ts +12 -0
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/map.d.ts +145 -0
- package/dist/operations/map.d.ts.map +1 -0
- package/dist/operations/matmul.d.ts +95 -0
- package/dist/operations/matmul.d.ts.map +1 -0
- package/dist/operations/reduce.d.ts +139 -0
- package/dist/operations/reduce.d.ts.map +1 -0
- package/dist/ops/bitwise.d.ts +71 -0
- package/dist/ops/bitwise.d.ts.map +1 -0
- package/dist/strategies/chunk.d.ts +119 -0
- package/dist/strategies/chunk.d.ts.map +1 -0
- package/dist/strategies/index.d.ts +10 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/threshold.d.ts +112 -0
- package/dist/strategies/threshold.d.ts.map +1 -0
- package/package.json +11 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,1286 +1,18 @@
|
|
|
1
|
-
import { TaskOptions, PoolStats, MathWorkerPool } from '@danielsimonjr/mathts-workerpool';
|
|
2
|
-
export { ExecOptions, PoolOptions, PoolStats, Transfer } from '@danielsimonjr/mathts-workerpool';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
2
|
+
* @danielsimonjr/mathts-parallel
|
|
6
3
|
*
|
|
7
|
-
*
|
|
8
|
-
* Provides automatic parallelization
|
|
4
|
+
* WebWorker parallelization for MathTS computations.
|
|
5
|
+
* Provides automatic parallelization based on data size thresholds.
|
|
9
6
|
*
|
|
10
7
|
* @packageDocumentation
|
|
11
8
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* - Signal-processing ops (`parallelFFT`, `parallelConv`, `spectrogram`, `fft2d`)
|
|
23
|
-
* - Geometry ops (`distanceMatrix`)
|
|
24
|
-
* - Special / distribution functions (`erfc`, `besselJ`, `normalCDF`)
|
|
25
|
-
* - Additional ops exposed via the typed functions layer
|
|
26
|
-
*/
|
|
27
|
-
type OpName = 'add' | 'subtract' | 'multiply' | 'divide' | 'pow' | 'scale' | 'abs' | 'negate' | 'sqrt' | 'square' | 'bitAnd' | 'bitOr' | 'bitXor' | 'bitNot' | 'leftShift' | 'rightArithShift' | 'rightLogShift' | 'exp' | 'log' | 'sin' | 'cos' | 'tan' | 'sign' | 'tensordot' | 'sum' | 'mean' | 'min' | 'max' | 'minMax' | 'variance' | 'std' | 'norm' | 'histogram' | 'dot' | 'prod' | 'distance' | 'parallelStatProd' | 'matmul' | 'outer' | 'matvec' | 'transpose' | 'matrixPower' | 'characteristicPolynomial' | 'parallelFFT' | 'parallelConv' | 'spectrogram' | 'fft2d' | 'distanceMatrix' | 'erfc' | 'besselJ' | 'normalCDF' | 'chiSquareTest' | 'kolmogorovSmirnovTest' | 'mannWhitneyTest' | 'shapiroWilkTest' | 'integrateChunk' | 'sampleChunk';
|
|
28
|
-
/**
|
|
29
|
-
* Per-op threshold override. The value is the minimum element count required
|
|
30
|
-
* before parallelizing the named operation. Special string aliases:
|
|
31
|
-
*
|
|
32
|
-
* - `'never'` → `Number.MAX_SAFE_INTEGER` (never parallelize)
|
|
33
|
-
* - `'always'` → `0` (always parallelize when pool is ready)
|
|
34
|
-
*/
|
|
35
|
-
type OpThreshold = number | 'never' | 'always';
|
|
36
|
-
/**
|
|
37
|
-
* Resolve an `OpThreshold` alias to its numeric equivalent.
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
declare function resolveOpThreshold(t: OpThreshold): number;
|
|
41
|
-
/**
|
|
42
|
-
* Configuration for ComputePool
|
|
43
|
-
* Extends the base WorkerPoolConfig with MathTS-specific options
|
|
44
|
-
*/
|
|
45
|
-
interface ComputePoolConfig {
|
|
46
|
-
/** Enable parallel processing */
|
|
47
|
-
enabled: boolean;
|
|
48
|
-
/** Minimum number of workers to maintain */
|
|
49
|
-
minWorkers: number;
|
|
50
|
-
/** Maximum number of workers */
|
|
51
|
-
maxWorkers: number;
|
|
52
|
-
/**
|
|
53
|
-
* Global minimum element count before parallelizing.
|
|
54
|
-
* Acts as the fallback for ops not listed in `thresholdByOp`.
|
|
55
|
-
*/
|
|
56
|
-
thresholdElements: number;
|
|
57
|
-
/**
|
|
58
|
-
* Per-operation parallelization thresholds.
|
|
59
|
-
*
|
|
60
|
-
* Values measured on a noisy CI container (2026-05-23) — re-run on target
|
|
61
|
-
* hardware to retune. Source: tools/benchmark/parallel/run.ts
|
|
62
|
-
*
|
|
63
|
-
* Ops absent from this map fall back to `thresholdElements`.
|
|
64
|
-
*/
|
|
65
|
-
thresholdByOp?: Partial<Record<OpName, OpThreshold>>;
|
|
66
|
-
/** Elements per chunk for parallel operations */
|
|
67
|
-
chunkSize: number;
|
|
68
|
-
/** Worker type: 'auto' | 'web' | 'thread' */
|
|
69
|
-
workerType: 'auto' | 'web' | 'thread';
|
|
70
|
-
/** Worker idle timeout in milliseconds */
|
|
71
|
-
workerIdleTimeout: number;
|
|
72
|
-
/** Default task timeout in milliseconds */
|
|
73
|
-
taskTimeout: number;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Default per-op thresholds derived from benchmark data (tools/benchmark/parallel/run.ts,
|
|
77
|
-
* 2026-05-23). Values measured on a noisy CI container — re-run on target hardware to retune.
|
|
78
|
-
*
|
|
79
|
-
* 'never' → Number.MAX_SAFE_INTEGER (benchmark showed no reliable speedup)
|
|
80
|
-
* 'always' → 0 (always parallelize when pool is ready)
|
|
81
|
-
* number → minimum element count before dispatching to workers
|
|
82
|
-
*/
|
|
83
|
-
/**
|
|
84
|
-
* Canonical, benchmark-tuned per-op parallelization thresholds. This is the
|
|
85
|
-
* single source of truth consulted by `ComputePool.shouldParallelize` — the
|
|
86
|
-
* authority the typed functions actually dispatch through. The coarser
|
|
87
|
-
* category-level {@link ThresholdDispatcher} derives its overlapping values
|
|
88
|
-
* (e.g. matmul) from here so the two cannot silently diverge.
|
|
89
|
-
*/
|
|
90
|
-
declare const DEFAULT_THRESHOLD_BY_OP: Partial<Record<OpName, OpThreshold>>;
|
|
91
|
-
/**
|
|
92
|
-
* Default ComputePool configuration
|
|
93
|
-
*/
|
|
94
|
-
declare const DEFAULT_POOL_CONFIG: ComputePoolConfig;
|
|
95
|
-
/**
|
|
96
|
-
* Result of a parallel operation
|
|
97
|
-
*/
|
|
98
|
-
interface ParallelResult<T> {
|
|
99
|
-
/** The computed result */
|
|
100
|
-
result: T;
|
|
101
|
-
/** Time taken in milliseconds */
|
|
102
|
-
duration: number;
|
|
103
|
-
/** Number of chunks processed */
|
|
104
|
-
chunks: number;
|
|
105
|
-
/** Whether parallelization was used */
|
|
106
|
-
parallelized: boolean;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* ComputePool for parallel MathTS operations
|
|
110
|
-
*
|
|
111
|
-
* Wraps the @danielsimonjr/mathts-workerpool MathWorkerPool with a MathTS-specific API.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* import { ComputePool } from '@danielsimonjr/mathts-parallel';
|
|
116
|
-
*
|
|
117
|
-
* const pool = new ComputePool({ maxWorkers: 8 });
|
|
118
|
-
* await pool.initialize();
|
|
119
|
-
*
|
|
120
|
-
* // Parallel matrix multiplication
|
|
121
|
-
* const result = await pool.matmul(matrixA, aRows, aCols, matrixB, bCols);
|
|
122
|
-
*
|
|
123
|
-
* // Parallel element-wise operation
|
|
124
|
-
* const sum = await pool.elementwise(a, b, 'add');
|
|
125
|
-
*
|
|
126
|
-
* // Cleanup
|
|
127
|
-
* await pool.terminate();
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
declare class ComputePool {
|
|
131
|
-
private workerPool;
|
|
132
|
-
private config;
|
|
133
|
-
constructor(config?: Partial<ComputePoolConfig>);
|
|
134
|
-
/**
|
|
135
|
-
* Initialize the worker pool
|
|
136
|
-
*/
|
|
137
|
-
initialize(): Promise<void>;
|
|
138
|
-
/**
|
|
139
|
-
* Check if pool is ready
|
|
140
|
-
*/
|
|
141
|
-
isReady(): boolean;
|
|
142
|
-
/**
|
|
143
|
-
* Determine if operation should be parallelized.
|
|
144
|
-
*
|
|
145
|
-
* When `op` is supplied the per-op threshold map is consulted first;
|
|
146
|
-
* if the op is absent from the map the global `thresholdElements` fallback
|
|
147
|
-
* is used. When `op` is omitted the global threshold is always used (for
|
|
148
|
-
* backward-compatibility with existing callers that don't know the op name).
|
|
149
|
-
*/
|
|
150
|
-
shouldParallelize(elementCount: number, op?: OpName): boolean;
|
|
151
|
-
/**
|
|
152
|
-
* Wrap a sequentially-computed reduction result in the `ParallelResult`
|
|
153
|
-
* envelope. Used by the reduction methods below so that ops whose threshold
|
|
154
|
-
* says "don't parallelize at this size" (notably the memory-bound reductions
|
|
155
|
-
* pinned to `'never'`) compute inline instead of paying a worker round-trip —
|
|
156
|
-
* previously every reduction dispatched to the pool unconditionally, ignoring
|
|
157
|
-
* its threshold.
|
|
158
|
-
*/
|
|
159
|
-
private seqResult;
|
|
160
|
-
/**
|
|
161
|
-
* Execute a method in the worker pool
|
|
162
|
-
*/
|
|
163
|
-
exec<T>(method: string, params: unknown[], options?: TaskOptions): Promise<T>;
|
|
164
|
-
/**
|
|
165
|
-
* Get pool statistics
|
|
166
|
-
*/
|
|
167
|
-
stats(): PoolStats;
|
|
168
|
-
/**
|
|
169
|
-
* Parallel sum of array elements
|
|
170
|
-
*/
|
|
171
|
-
sum(data: Float64Array): Promise<ParallelResult<number>>;
|
|
172
|
-
/**
|
|
173
|
-
* Parallel product of array elements
|
|
174
|
-
*/
|
|
175
|
-
prod(data: Float64Array): Promise<ParallelResult<number>>;
|
|
176
|
-
/**
|
|
177
|
-
* Parallel dot product
|
|
178
|
-
*/
|
|
179
|
-
dot(a: Float64Array, b: Float64Array): Promise<ParallelResult<number>>;
|
|
180
|
-
/**
|
|
181
|
-
* Parallel element-wise operation
|
|
182
|
-
*/
|
|
183
|
-
elementwise(a: Float64Array, b: Float64Array, op: 'add' | 'subtract' | 'multiply' | 'divide'): Promise<ParallelResult<Float64Array>>;
|
|
184
|
-
/**
|
|
185
|
-
* Parallel scale operation
|
|
186
|
-
*/
|
|
187
|
-
scale(data: Float64Array, scalar: number): Promise<ParallelResult<Float64Array>>;
|
|
188
|
-
/**
|
|
189
|
-
* Parallel matrix multiplication
|
|
190
|
-
*
|
|
191
|
-
* @param a - First matrix as flat Float64Array (row-major)
|
|
192
|
-
* @param aRows - Number of rows in A
|
|
193
|
-
* @param aCols - Number of columns in A
|
|
194
|
-
* @param b - Second matrix as flat Float64Array (row-major)
|
|
195
|
-
* @param bCols - Number of columns in B
|
|
196
|
-
*/
|
|
197
|
-
matmul(a: Float64Array, aRows: number, aCols: number, b: Float64Array, bCols: number): Promise<ParallelResult<Float64Array>>;
|
|
198
|
-
/**
|
|
199
|
-
* Parallel matrix transpose
|
|
200
|
-
*/
|
|
201
|
-
transpose(data: Float64Array, rows: number, cols: number): Promise<ParallelResult<Float64Array>>;
|
|
202
|
-
/**
|
|
203
|
-
* Parallel map operation
|
|
204
|
-
*/
|
|
205
|
-
map<T, R>(data: T[], fn: (item: T) => R): Promise<ParallelResult<R[]>>;
|
|
206
|
-
/**
|
|
207
|
-
* Parallel reduce operation
|
|
208
|
-
*/
|
|
209
|
-
reduce<T, R>(data: T[], fn: (acc: R, item: T) => R, initial: R): Promise<ParallelResult<R>>;
|
|
210
|
-
/**
|
|
211
|
-
* Parallel filter operation
|
|
212
|
-
*/
|
|
213
|
-
filter<T>(data: T[], predicate: (item: T) => boolean): Promise<ParallelResult<T[]>>;
|
|
214
|
-
/**
|
|
215
|
-
* Find min and max values in parallel
|
|
216
|
-
*/
|
|
217
|
-
minMax(data: Float64Array): Promise<ParallelResult<{
|
|
218
|
-
min: number;
|
|
219
|
-
max: number;
|
|
220
|
-
minIdx: number;
|
|
221
|
-
maxIdx: number;
|
|
222
|
-
}>>;
|
|
223
|
-
/**
|
|
224
|
-
* Compute variance, mean, and standard deviation in parallel
|
|
225
|
-
*/
|
|
226
|
-
variance(data: Float64Array): Promise<ParallelResult<{
|
|
227
|
-
mean: number;
|
|
228
|
-
variance: number;
|
|
229
|
-
std: number;
|
|
230
|
-
}>>;
|
|
231
|
-
/**
|
|
232
|
-
* Compute norm (Euclidean length) in parallel
|
|
233
|
-
*/
|
|
234
|
-
norm(data: Float64Array): Promise<ParallelResult<number>>;
|
|
235
|
-
/**
|
|
236
|
-
* Compute Euclidean distance in parallel
|
|
237
|
-
*/
|
|
238
|
-
distance(a: Float64Array, b: Float64Array): Promise<ParallelResult<number>>;
|
|
239
|
-
/**
|
|
240
|
-
* Compute histogram in parallel
|
|
241
|
-
*/
|
|
242
|
-
histogram(data: Float64Array, bins: number, min?: number, max?: number): Promise<ParallelResult<number[]>>;
|
|
243
|
-
/**
|
|
244
|
-
* Apply unary function in parallel
|
|
245
|
-
*/
|
|
246
|
-
unary(data: Float64Array, fn: 'abs' | 'sqrt' | 'exp' | 'log' | 'sin' | 'cos' | 'tan' | 'negate' | 'square'): Promise<ParallelResult<Float64Array>>;
|
|
247
|
-
/**
|
|
248
|
-
* Apply a caller-supplied unary numeric function in parallel.
|
|
249
|
-
*
|
|
250
|
-
* @param data - Input values
|
|
251
|
-
* @param fnSource - Source of a self-contained `(x: number) => number`
|
|
252
|
-
* expression. It must not reference free variables / closures, since it
|
|
253
|
-
* is eval'd in an isolated worker context. Used to parallelize element-wise
|
|
254
|
-
* math (special functions, distribution PDFs/CDFs).
|
|
255
|
-
*/
|
|
256
|
-
applyKernel(data: Float64Array, fnSource: string): Promise<ParallelResult<Float64Array>>;
|
|
257
|
-
/**
|
|
258
|
-
* Apply a caller-supplied binary numeric function in parallel.
|
|
259
|
-
*
|
|
260
|
-
* @param a - First operand array
|
|
261
|
-
* @param b - Second operand array (must match the length of `a`)
|
|
262
|
-
* @param fnSource - Source of a self-contained `(a: number, b: number) =>
|
|
263
|
-
* number` expression (no free variables / closures).
|
|
264
|
-
*/
|
|
265
|
-
applyKernel2(a: Float64Array, b: Float64Array, fnSource: string): Promise<ParallelResult<Float64Array>>;
|
|
266
|
-
/**
|
|
267
|
-
* Fan-out Gauss-Legendre quadrature over `workerCount` sub-intervals.
|
|
268
|
-
*
|
|
269
|
-
* Partitions `[a, b]` into `workerCount` equal sub-domains and dispatches one
|
|
270
|
-
* `integrateChunk` worker task per sub-domain. Each task evaluates the
|
|
271
|
-
* integrand (supplied as a stringified closure) with the given GL nodes and
|
|
272
|
-
* weights and returns its partial integral. The partial sums are aggregated
|
|
273
|
-
* on the main thread.
|
|
274
|
-
*
|
|
275
|
-
* **Closure contract:** `fnSource` must be a self-contained `(x: number) =>
|
|
276
|
-
* number` expression — no free variables referencing outer scope, because it
|
|
277
|
-
* is eval'd inside an isolated worker context. Call-site validation (via
|
|
278
|
-
* `validateClosureSource`) should have already rejected unsafe closures before
|
|
279
|
-
* reaching this method.
|
|
280
|
-
*
|
|
281
|
-
* @param fnSource - Stringified integrand, e.g. `"(x) => Math.sin(x)"`
|
|
282
|
-
* @param a - Lower integration bound
|
|
283
|
-
* @param b - Upper integration bound
|
|
284
|
-
* @param workerCount - Number of sub-intervals / worker tasks
|
|
285
|
-
* @param nodes - GL nodes on [-1, 1]
|
|
286
|
-
* @param weights - Corresponding GL weights
|
|
287
|
-
* @returns Sum of partial integrals = approximate value of ∫ₐᵇ f(x) dx
|
|
288
|
-
*/
|
|
289
|
-
integrateFanOut(fnSource: string, a: number, b: number, workerCount: number, nodes: number[], weights: number[]): Promise<number>;
|
|
290
|
-
/**
|
|
291
|
-
* Fan-out distribution batch sampling across `workerCount` workers.
|
|
292
|
-
*
|
|
293
|
-
* Partitions `n` samples into `workerCount` equal chunks (last chunk absorbs
|
|
294
|
-
* the remainder) and dispatches one `sampleChunk` task per chunk. Each chunk
|
|
295
|
-
* uses an independent seed derived from `baseSeed` via SplitMix64-style
|
|
296
|
-
* hashing:
|
|
297
|
-
*
|
|
298
|
-
* `chunkSeed = (baseSeed ^ (chunkIdx * 0x9E3779B97F4A7C15)) >>> 0`
|
|
299
|
-
*
|
|
300
|
-
* This Fibonacci-hashing multiplier gives good avalanche: even baseSeed=0
|
|
301
|
-
* produces K distinct seeds, and adjacent chunk indices produce uncorrelated
|
|
302
|
-
* sequences. See the `sampleChunk` worker kernel for the full rationale.
|
|
303
|
-
*
|
|
304
|
-
* @param distName - One of 'normal', 'gamma', 'beta', 'studentT', 'exponential'
|
|
305
|
-
* @param params - Distribution parameters (order matches factory functions)
|
|
306
|
-
* @param n - Total number of samples to generate
|
|
307
|
-
* @param baseSeed - Base seed for reproducible output
|
|
308
|
-
* @param workerCount - Number of parallel worker tasks
|
|
309
|
-
* @returns Concatenated Float64Array of `n` samples
|
|
310
|
-
*/
|
|
311
|
-
distributionSampleFanOut(distName: string, params: number[], n: number, baseSeed: number, workerCount: number): Promise<Float64Array>;
|
|
312
|
-
/**
|
|
313
|
-
* Compute a batch of independent radix-2 FFTs in parallel.
|
|
314
|
-
*
|
|
315
|
-
* `real` and `imag` each hold `frameCount` concatenated frames of
|
|
316
|
-
* `frameLength` samples (`frameLength` must be a power of two). Each frame
|
|
317
|
-
* is FFT'd independently and the frames are distributed across workers.
|
|
318
|
-
*
|
|
319
|
-
* Used to parallelize the embarrassingly-parallel FFT batches in
|
|
320
|
-
* `spectrogram` (one FFT per windowed frame) and `fft2d` (rows then columns).
|
|
321
|
-
*
|
|
322
|
-
* @param real - Concatenated real parts (`frameCount * frameLength` values)
|
|
323
|
-
* @param imag - Concatenated imaginary parts (same layout as `real`)
|
|
324
|
-
* @param frameCount - Number of independent frames
|
|
325
|
-
* @param frameLength - Samples per frame (power of two)
|
|
326
|
-
* @param inverse - Compute the inverse FFT when true
|
|
327
|
-
*/
|
|
328
|
-
fftBatch(real: Float64Array, imag: Float64Array, frameCount: number, frameLength: number, inverse?: boolean): Promise<ParallelResult<{
|
|
329
|
-
real: Float64Array;
|
|
330
|
-
imag: Float64Array;
|
|
331
|
-
}>>;
|
|
332
|
-
/**
|
|
333
|
-
* Compute an all-pairs Euclidean distance matrix in parallel.
|
|
334
|
-
*
|
|
335
|
-
* @param points - Flattened `n * dim` coordinate array (row-major)
|
|
336
|
-
* @param n - Number of points
|
|
337
|
-
* @param dim - Coordinate dimension
|
|
338
|
-
* @returns Flat row-major `n * n` distance matrix
|
|
339
|
-
*/
|
|
340
|
-
distanceMatrix(points: Float64Array, n: number, dim: number): Promise<ParallelResult<Float64Array>>;
|
|
341
|
-
/**
|
|
342
|
-
* Parallel absolute value
|
|
343
|
-
*/
|
|
344
|
-
abs(data: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
345
|
-
/**
|
|
346
|
-
* Parallel square root
|
|
347
|
-
*/
|
|
348
|
-
sqrt(data: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
349
|
-
/**
|
|
350
|
-
* Parallel exponential
|
|
351
|
-
*/
|
|
352
|
-
exp(data: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
353
|
-
/**
|
|
354
|
-
* Parallel natural log
|
|
355
|
-
*/
|
|
356
|
-
log(data: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
357
|
-
/**
|
|
358
|
-
* Parallel sine
|
|
359
|
-
*/
|
|
360
|
-
sin(data: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
361
|
-
/**
|
|
362
|
-
* Parallel cosine
|
|
363
|
-
*/
|
|
364
|
-
cos(data: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
365
|
-
/**
|
|
366
|
-
* Parallel tangent
|
|
367
|
-
*/
|
|
368
|
-
tan(data: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
369
|
-
/**
|
|
370
|
-
* Parallel negation
|
|
371
|
-
*/
|
|
372
|
-
negate(data: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
373
|
-
/**
|
|
374
|
-
* Parallel square
|
|
375
|
-
*/
|
|
376
|
-
square(data: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
377
|
-
/**
|
|
378
|
-
* Parallel matrix-vector multiplication
|
|
379
|
-
*/
|
|
380
|
-
matvec(matrix: Float64Array, rows: number, cols: number, vector: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
381
|
-
/**
|
|
382
|
-
* Parallel outer product
|
|
383
|
-
*/
|
|
384
|
-
outer(a: Float64Array, b: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
385
|
-
/**
|
|
386
|
-
* Parallel find operation
|
|
387
|
-
*/
|
|
388
|
-
find<T>(data: T[], predicate: (item: T) => boolean): Promise<ParallelResult<{
|
|
389
|
-
found: boolean;
|
|
390
|
-
value?: T;
|
|
391
|
-
index?: number;
|
|
392
|
-
}>>;
|
|
393
|
-
/**
|
|
394
|
-
* Parallel sort operation
|
|
395
|
-
*/
|
|
396
|
-
sort<T>(data: T[], compare?: (a: T, b: T) => number): Promise<ParallelResult<T[]>>;
|
|
397
|
-
/**
|
|
398
|
-
* Parallel addition of two arrays
|
|
399
|
-
*/
|
|
400
|
-
add(a: Float64Array, b: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
401
|
-
/**
|
|
402
|
-
* Parallel subtraction of two arrays
|
|
403
|
-
*/
|
|
404
|
-
subtract(a: Float64Array, b: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
405
|
-
/**
|
|
406
|
-
* Parallel element-wise multiplication
|
|
407
|
-
*/
|
|
408
|
-
multiply(a: Float64Array, b: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
409
|
-
/**
|
|
410
|
-
* Parallel element-wise division
|
|
411
|
-
*/
|
|
412
|
-
divide(a: Float64Array, b: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
413
|
-
/**
|
|
414
|
-
* Parallel element-wise exponentiation.
|
|
415
|
-
*
|
|
416
|
-
* `out[i] = a[i] ** b[i]`
|
|
417
|
-
*
|
|
418
|
-
* Delegates to `applyKernel2` with the `Math.pow` kernel. The default
|
|
419
|
-
* per-op threshold for `pow` is `'never'` (overhead dominates); the
|
|
420
|
-
* sequential path is taken unless the caller overrides `thresholdByOp.pow`.
|
|
421
|
-
*/
|
|
422
|
-
pow(a: Float64Array, b: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
423
|
-
/**
|
|
424
|
-
* Parallel element-wise sign function.
|
|
425
|
-
*
|
|
426
|
-
* `out[i] = Math.sign(data[i])` → -1 | 0 | 1, with NaN → NaN (IEEE 754).
|
|
427
|
-
*
|
|
428
|
-
* Delegates to `applyKernel` with the `Math.sign` kernel. The default
|
|
429
|
-
* per-op threshold for `sign` is `'never'` (overhead dominates); the
|
|
430
|
-
* sequential path is taken unless the caller overrides `thresholdByOp.sign`.
|
|
431
|
-
*/
|
|
432
|
-
sign(data: Float64Array): Promise<ParallelResult<Float64Array>>;
|
|
433
|
-
/**
|
|
434
|
-
* General tensor contraction (tensordot) over specified axis pairs.
|
|
435
|
-
*
|
|
436
|
-
* Contracts axis `axesA[i]` of `a` with axis `axesB[i]` of `b` for each
|
|
437
|
-
* pair index `i`. The result shape is the non-contracted axes of `a` followed
|
|
438
|
-
* by the non-contracted axes of `b` (NumPy convention).
|
|
439
|
-
*
|
|
440
|
-
* Parallelization threshold: contracted-axis volume (product of contracted
|
|
441
|
-
* dimensions) >= 8 192. When parallelized, output elements are distributed
|
|
442
|
-
* in contiguous slices across workers via the `tensordotChunk` kernel.
|
|
443
|
-
*
|
|
444
|
-
* @param a - Flat row-major Float64Array for tensor A
|
|
445
|
-
* @param aShape - Shape of tensor A
|
|
446
|
-
* @param b - Flat row-major Float64Array for tensor B
|
|
447
|
-
* @param bShape - Shape of tensor B
|
|
448
|
-
* @param axesA - Axes of A to contract (same length as axesB)
|
|
449
|
-
* @param axesB - Axes of B to contract (same length as axesA)
|
|
450
|
-
* @returns `{ data: Float64Array; shape: number[] }` — flat result + result shape
|
|
451
|
-
*/
|
|
452
|
-
tensordot(a: Float64Array, aShape: readonly number[], b: Float64Array, bShape: readonly number[], axesA: readonly number[], axesB: readonly number[]): Promise<ParallelResult<{
|
|
453
|
-
data: Float64Array;
|
|
454
|
-
shape: number[];
|
|
455
|
-
}>>;
|
|
456
|
-
/**
|
|
457
|
-
* Compute mean in parallel (uses variance internally)
|
|
458
|
-
*/
|
|
459
|
-
mean(data: Float64Array): Promise<ParallelResult<number>>;
|
|
460
|
-
/**
|
|
461
|
-
* Compute standard deviation in parallel
|
|
462
|
-
*/
|
|
463
|
-
std(data: Float64Array): Promise<ParallelResult<number>>;
|
|
464
|
-
/**
|
|
465
|
-
* Find minimum value in parallel
|
|
466
|
-
*/
|
|
467
|
-
min(data: Float64Array): Promise<ParallelResult<number>>;
|
|
468
|
-
/**
|
|
469
|
-
* Find maximum value in parallel
|
|
470
|
-
*/
|
|
471
|
-
max(data: Float64Array): Promise<ParallelResult<number>>;
|
|
472
|
-
/**
|
|
473
|
-
* Element-wise bitwise AND on two `Int32Array`s.
|
|
474
|
-
*/
|
|
475
|
-
bitAnd(a: Int32Array, b: Int32Array): Promise<ParallelResult<Int32Array>>;
|
|
476
|
-
/**
|
|
477
|
-
* Element-wise bitwise OR on two `Int32Array`s.
|
|
478
|
-
*/
|
|
479
|
-
bitOr(a: Int32Array, b: Int32Array): Promise<ParallelResult<Int32Array>>;
|
|
480
|
-
/**
|
|
481
|
-
* Element-wise bitwise XOR on two `Int32Array`s.
|
|
482
|
-
*/
|
|
483
|
-
bitXor(a: Int32Array, b: Int32Array): Promise<ParallelResult<Int32Array>>;
|
|
484
|
-
/**
|
|
485
|
-
* Unary bitwise NOT on an `Int32Array`.
|
|
486
|
-
*/
|
|
487
|
-
bitNot(a: Int32Array): Promise<ParallelResult<Int32Array>>;
|
|
488
|
-
/**
|
|
489
|
-
* Element-wise left shift. `b` may be a per-element `Int32Array` of
|
|
490
|
-
* shift counts or a single scalar `number` applied uniformly.
|
|
491
|
-
*/
|
|
492
|
-
leftShift(a: Int32Array, b: Int32Array | number): Promise<ParallelResult<Int32Array>>;
|
|
493
|
-
/**
|
|
494
|
-
* Element-wise arithmetic (sign-preserving) right shift.
|
|
495
|
-
*/
|
|
496
|
-
rightArithShift(a: Int32Array, b: Int32Array | number): Promise<ParallelResult<Int32Array>>;
|
|
497
|
-
/**
|
|
498
|
-
* Element-wise logical (zero-filling) right shift. Results are stored
|
|
499
|
-
* as `Int32Array`, so values ≥ 2^31 wrap into the negative range —
|
|
500
|
-
* matching `(x >>> n) | 0` JavaScript semantics.
|
|
501
|
-
*/
|
|
502
|
-
rightLogShift(a: Int32Array, b: Int32Array | number): Promise<ParallelResult<Int32Array>>;
|
|
503
|
-
/**
|
|
504
|
-
* Terminate the worker pool
|
|
505
|
-
*/
|
|
506
|
-
terminate(force?: boolean): Promise<void>;
|
|
507
|
-
/**
|
|
508
|
-
* Update configuration
|
|
509
|
-
*/
|
|
510
|
-
updateConfig(config: Partial<ComputePoolConfig>): void;
|
|
511
|
-
/**
|
|
512
|
-
* Get current configuration
|
|
513
|
-
*/
|
|
514
|
-
getConfig(): ComputePoolConfig;
|
|
515
|
-
/**
|
|
516
|
-
* Maximum number of workers configured for this pool.
|
|
517
|
-
* Used by distribution sampling fan-out to determine chunk count.
|
|
518
|
-
*/
|
|
519
|
-
get workerCount(): number;
|
|
520
|
-
/**
|
|
521
|
-
* Get the underlying MathWorkerPool for advanced operations
|
|
522
|
-
*/
|
|
523
|
-
getWorkerPool(): MathWorkerPool;
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Global compute pool instance
|
|
527
|
-
*/
|
|
528
|
-
declare const computePool: ComputePool;
|
|
529
|
-
|
|
530
|
-
/**
|
|
531
|
-
* Parallel Matrix Multiplication
|
|
532
|
-
*
|
|
533
|
-
* High-performance parallel matrix multiplication with automatic chunking.
|
|
534
|
-
* Distributes rows across workers for parallel computation.
|
|
535
|
-
*
|
|
536
|
-
* @packageDocumentation
|
|
537
|
-
*/
|
|
538
|
-
|
|
539
|
-
/**
|
|
540
|
-
* Options for parallel matrix multiplication
|
|
541
|
-
*/
|
|
542
|
-
interface MatmulOptions {
|
|
543
|
-
/** Custom pool to use (defaults to global computePool) */
|
|
544
|
-
pool?: ComputePool;
|
|
545
|
-
/** Force parallel execution regardless of threshold */
|
|
546
|
-
forceParallel?: boolean;
|
|
547
|
-
/** Force sequential execution regardless of threshold */
|
|
548
|
-
forceSequential?: boolean;
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* Parallel matrix multiplication (C = A × B)
|
|
552
|
-
*
|
|
553
|
-
* Multiplies two matrices using parallel workers. The computation
|
|
554
|
-
* distributes rows of matrix A across available workers.
|
|
555
|
-
*
|
|
556
|
-
* @param a - First matrix as flat Float64Array (row-major order)
|
|
557
|
-
* @param aRows - Number of rows in matrix A
|
|
558
|
-
* @param aCols - Number of columns in matrix A (must equal bRows)
|
|
559
|
-
* @param b - Second matrix as flat Float64Array (row-major order)
|
|
560
|
-
* @param bCols - Number of columns in matrix B
|
|
561
|
-
* @param options - Optional configuration
|
|
562
|
-
* @returns Result matrix C (aRows × bCols) with parallel execution metadata
|
|
563
|
-
*
|
|
564
|
-
* @example
|
|
565
|
-
* ```typescript
|
|
566
|
-
* // 2x3 matrix * 3x2 matrix = 2x2 matrix
|
|
567
|
-
* const A = new Float64Array([1, 2, 3, 4, 5, 6]);
|
|
568
|
-
* const B = new Float64Array([7, 8, 9, 10, 11, 12]);
|
|
569
|
-
*
|
|
570
|
-
* const result = await parallelMatmul(A, 2, 3, B, 2);
|
|
571
|
-
* console.log(result.result); // 2x2 result matrix
|
|
572
|
-
* console.log(result.parallelized); // true if workers were used
|
|
573
|
-
* ```
|
|
574
|
-
*/
|
|
575
|
-
declare function parallelMatmul(a: Float64Array, aRows: number, aCols: number, b: Float64Array, bCols: number, options?: MatmulOptions): Promise<ParallelResult<Float64Array>>;
|
|
576
|
-
/**
|
|
577
|
-
* Parallel matrix-vector multiplication (y = A × x)
|
|
578
|
-
*
|
|
579
|
-
* Multiplies a matrix by a vector using parallel workers.
|
|
580
|
-
*
|
|
581
|
-
* @param matrix - Matrix as flat Float64Array (row-major order)
|
|
582
|
-
* @param rows - Number of rows in the matrix
|
|
583
|
-
* @param cols - Number of columns in the matrix (must equal vector length)
|
|
584
|
-
* @param vector - Vector as Float64Array
|
|
585
|
-
* @param options - Optional configuration
|
|
586
|
-
* @returns Result vector with parallel execution metadata
|
|
587
|
-
*/
|
|
588
|
-
declare function parallelMatvec(matrix: Float64Array, rows: number, cols: number, vector: Float64Array, options?: MatmulOptions): Promise<ParallelResult<Float64Array>>;
|
|
589
|
-
/**
|
|
590
|
-
* Parallel matrix transpose
|
|
591
|
-
*
|
|
592
|
-
* Transposes a matrix using parallel workers.
|
|
593
|
-
*
|
|
594
|
-
* @param data - Matrix as flat Float64Array (row-major order)
|
|
595
|
-
* @param rows - Number of rows in the original matrix
|
|
596
|
-
* @param cols - Number of columns in the original matrix
|
|
597
|
-
* @param options - Optional configuration
|
|
598
|
-
* @returns Transposed matrix (cols × rows) with parallel execution metadata
|
|
599
|
-
*/
|
|
600
|
-
declare function parallelTranspose(data: Float64Array, rows: number, cols: number, options?: MatmulOptions): Promise<ParallelResult<Float64Array>>;
|
|
601
|
-
/**
|
|
602
|
-
* Parallel outer product (C = a ⊗ b)
|
|
603
|
-
*
|
|
604
|
-
* Computes the outer product of two vectors.
|
|
605
|
-
*
|
|
606
|
-
* @param a - First vector
|
|
607
|
-
* @param b - Second vector
|
|
608
|
-
* @param options - Optional configuration
|
|
609
|
-
* @returns Outer product matrix (a.length × b.length)
|
|
610
|
-
*/
|
|
611
|
-
declare function parallelOuter(a: Float64Array, b: Float64Array, options?: MatmulOptions): Promise<ParallelResult<Float64Array>>;
|
|
612
|
-
/**
|
|
613
|
-
* Parallel dot product (scalar = a · b)
|
|
614
|
-
*
|
|
615
|
-
* Computes the dot product of two vectors.
|
|
616
|
-
*
|
|
617
|
-
* @param a - First vector
|
|
618
|
-
* @param b - Second vector (must have same length as a)
|
|
619
|
-
* @param options - Optional configuration
|
|
620
|
-
* @returns Dot product scalar
|
|
621
|
-
*/
|
|
622
|
-
declare function parallelDot(a: Float64Array, b: Float64Array, options?: MatmulOptions): Promise<ParallelResult<number>>;
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* Parallel Element-wise Operations
|
|
626
|
-
*
|
|
627
|
-
* High-performance parallel element-wise operations on arrays.
|
|
628
|
-
* Automatically chunks data for distribution across workers.
|
|
629
|
-
*
|
|
630
|
-
* @packageDocumentation
|
|
631
|
-
*/
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* Options for parallel element-wise operations
|
|
635
|
-
*/
|
|
636
|
-
interface ElementwiseOptions {
|
|
637
|
-
/** Custom pool to use (defaults to global computePool) */
|
|
638
|
-
pool?: ComputePool;
|
|
639
|
-
/** Force parallel execution regardless of threshold */
|
|
640
|
-
forceParallel?: boolean;
|
|
641
|
-
/** Force sequential execution regardless of threshold */
|
|
642
|
-
forceSequential?: boolean;
|
|
643
|
-
}
|
|
644
|
-
/**
|
|
645
|
-
* Parallel element-wise addition (c[i] = a[i] + b[i])
|
|
646
|
-
*/
|
|
647
|
-
declare function parallelAdd(a: Float64Array, b: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
648
|
-
/**
|
|
649
|
-
* Parallel element-wise subtraction (c[i] = a[i] - b[i])
|
|
650
|
-
*/
|
|
651
|
-
declare function parallelSubtract(a: Float64Array, b: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
652
|
-
/**
|
|
653
|
-
* Parallel element-wise multiplication (c[i] = a[i] * b[i])
|
|
654
|
-
*/
|
|
655
|
-
declare function parallelMultiply(a: Float64Array, b: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
656
|
-
/**
|
|
657
|
-
* Parallel element-wise division (c[i] = a[i] / b[i])
|
|
658
|
-
*/
|
|
659
|
-
declare function parallelDivide(a: Float64Array, b: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
660
|
-
/**
|
|
661
|
-
* Parallel scalar multiplication (b[i] = a[i] * scalar)
|
|
662
|
-
*/
|
|
663
|
-
declare function parallelScale(data: Float64Array, scalar: number, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
664
|
-
/**
|
|
665
|
-
* Parallel absolute value (b[i] = |a[i]|)
|
|
666
|
-
*/
|
|
667
|
-
declare function parallelAbs(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
668
|
-
/**
|
|
669
|
-
* Parallel negation (b[i] = -a[i])
|
|
670
|
-
*/
|
|
671
|
-
declare function parallelNegate(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
672
|
-
/**
|
|
673
|
-
* Parallel square (b[i] = a[i]²)
|
|
674
|
-
*/
|
|
675
|
-
declare function parallelSquare(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
676
|
-
/**
|
|
677
|
-
* Parallel square root (b[i] = √a[i])
|
|
678
|
-
*/
|
|
679
|
-
declare function parallelSqrt(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
680
|
-
/**
|
|
681
|
-
* Parallel exponential (b[i] = e^a[i])
|
|
682
|
-
*/
|
|
683
|
-
declare function parallelExp(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
684
|
-
/**
|
|
685
|
-
* Parallel natural logarithm (b[i] = ln(a[i]))
|
|
686
|
-
*/
|
|
687
|
-
declare function parallelLog(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
688
|
-
/**
|
|
689
|
-
* Parallel sine (b[i] = sin(a[i]))
|
|
690
|
-
*/
|
|
691
|
-
declare function parallelSin(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
692
|
-
/**
|
|
693
|
-
* Parallel cosine (b[i] = cos(a[i]))
|
|
694
|
-
*/
|
|
695
|
-
declare function parallelCos(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
696
|
-
/**
|
|
697
|
-
* Parallel tangent (b[i] = tan(a[i]))
|
|
698
|
-
*/
|
|
699
|
-
declare function parallelTan(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
700
|
-
/**
|
|
701
|
-
* Generic parallel element-wise operation
|
|
702
|
-
*/
|
|
703
|
-
declare function parallelElementwise(a: Float64Array, b: Float64Array, op: 'add' | 'subtract' | 'multiply' | 'divide', options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
704
|
-
/**
|
|
705
|
-
* Generic parallel unary operation
|
|
706
|
-
*/
|
|
707
|
-
declare function parallelUnary(data: Float64Array, fn: 'abs' | 'sqrt' | 'exp' | 'log' | 'sin' | 'cos' | 'tan' | 'negate' | 'square', options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
708
|
-
|
|
709
|
-
/**
|
|
710
|
-
* Parallel Reduction Operations
|
|
711
|
-
*
|
|
712
|
-
* High-performance parallel reduction operations (sum, min, max, etc.).
|
|
713
|
-
* Uses parallel aggregation with sequential final reduction.
|
|
714
|
-
*
|
|
715
|
-
* @packageDocumentation
|
|
716
|
-
*/
|
|
717
|
-
|
|
718
|
-
/**
|
|
719
|
-
* Options for parallel reduction operations
|
|
720
|
-
*/
|
|
721
|
-
interface ReduceOptions {
|
|
722
|
-
/** Custom pool to use (defaults to global computePool) */
|
|
723
|
-
pool?: ComputePool;
|
|
724
|
-
/** Force parallel execution regardless of threshold */
|
|
725
|
-
forceParallel?: boolean;
|
|
726
|
-
/** Force sequential execution regardless of threshold */
|
|
727
|
-
forceSequential?: boolean;
|
|
728
|
-
}
|
|
729
|
-
/**
|
|
730
|
-
* Parallel sum reduction
|
|
731
|
-
*
|
|
732
|
-
* Computes the sum of all elements using parallel partial sums.
|
|
733
|
-
*
|
|
734
|
-
* @param data - Array to sum
|
|
735
|
-
* @param options - Optional configuration
|
|
736
|
-
* @returns Sum of all elements
|
|
737
|
-
*/
|
|
738
|
-
declare function parallelSum(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
739
|
-
/**
|
|
740
|
-
* Parallel mean computation
|
|
741
|
-
*
|
|
742
|
-
* @param data - Array to compute mean of
|
|
743
|
-
* @param options - Optional configuration
|
|
744
|
-
* @returns Mean value
|
|
745
|
-
*/
|
|
746
|
-
declare function parallelMean(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
747
|
-
/**
|
|
748
|
-
* Parallel minimum value
|
|
749
|
-
*
|
|
750
|
-
* @param data - Array to find minimum of
|
|
751
|
-
* @param options - Optional configuration
|
|
752
|
-
* @returns Minimum value
|
|
753
|
-
*/
|
|
754
|
-
declare function parallelMin(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
755
|
-
/**
|
|
756
|
-
* Parallel maximum value
|
|
757
|
-
*
|
|
758
|
-
* @param data - Array to find maximum of
|
|
759
|
-
* @param options - Optional configuration
|
|
760
|
-
* @returns Maximum value
|
|
761
|
-
*/
|
|
762
|
-
declare function parallelMax(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
763
|
-
/**
|
|
764
|
-
* Parallel min/max with indices
|
|
765
|
-
*
|
|
766
|
-
* @param data - Array to analyze
|
|
767
|
-
* @param options - Optional configuration
|
|
768
|
-
* @returns Object with min, max, minIdx, maxIdx
|
|
769
|
-
*/
|
|
770
|
-
declare function parallelMinMax(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<{
|
|
771
|
-
min: number;
|
|
772
|
-
max: number;
|
|
773
|
-
minIdx: number;
|
|
774
|
-
maxIdx: number;
|
|
775
|
-
}>>;
|
|
776
|
-
/**
|
|
777
|
-
* Parallel variance computation
|
|
778
|
-
*
|
|
779
|
-
* Uses Welford's algorithm for numerically stable variance calculation.
|
|
780
|
-
*
|
|
781
|
-
* @param data - Array to compute variance of
|
|
782
|
-
* @param options - Optional configuration
|
|
783
|
-
* @returns Object with mean, variance, and std (standard deviation)
|
|
784
|
-
*/
|
|
785
|
-
declare function parallelVariance(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<{
|
|
786
|
-
mean: number;
|
|
787
|
-
variance: number;
|
|
788
|
-
std: number;
|
|
789
|
-
}>>;
|
|
790
|
-
/**
|
|
791
|
-
* Parallel standard deviation
|
|
792
|
-
*
|
|
793
|
-
* @param data - Array to compute std of
|
|
794
|
-
* @param options - Optional configuration
|
|
795
|
-
* @returns Standard deviation
|
|
796
|
-
*/
|
|
797
|
-
declare function parallelStd(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
798
|
-
/**
|
|
799
|
-
* Parallel Euclidean norm (L2 norm)
|
|
800
|
-
*
|
|
801
|
-
* Computes √(Σx²) using parallel partial sums of squares.
|
|
802
|
-
*
|
|
803
|
-
* @param data - Vector to compute norm of
|
|
804
|
-
* @param options - Optional configuration
|
|
805
|
-
* @returns Euclidean norm
|
|
806
|
-
*/
|
|
807
|
-
declare function parallelNorm(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
808
|
-
/**
|
|
809
|
-
* Parallel Euclidean distance
|
|
810
|
-
*
|
|
811
|
-
* Computes the Euclidean distance between two vectors.
|
|
812
|
-
*
|
|
813
|
-
* @param a - First vector
|
|
814
|
-
* @param b - Second vector
|
|
815
|
-
* @param options - Optional configuration
|
|
816
|
-
* @returns Euclidean distance
|
|
817
|
-
*/
|
|
818
|
-
declare function parallelDistance(a: Float64Array, b: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
819
|
-
/**
|
|
820
|
-
* Parallel histogram computation
|
|
821
|
-
*
|
|
822
|
-
* Bins data into histogram using parallel counting.
|
|
823
|
-
*
|
|
824
|
-
* @param data - Array to bin
|
|
825
|
-
* @param bins - Number of bins
|
|
826
|
-
* @param min - Minimum value (auto-detected if not provided)
|
|
827
|
-
* @param max - Maximum value (auto-detected if not provided)
|
|
828
|
-
* @param options - Optional configuration
|
|
829
|
-
* @returns Array of bin counts
|
|
830
|
-
*/
|
|
831
|
-
declare function parallelHistogram(data: Float64Array, bins: number, min?: number, max?: number, options?: ReduceOptions): Promise<ParallelResult<number[]>>;
|
|
832
|
-
/**
|
|
833
|
-
* Generic parallel reduce operation
|
|
834
|
-
*
|
|
835
|
-
* Reduces an array using a custom function. Note that for truly
|
|
836
|
-
* associative operations, consider using specialized functions
|
|
837
|
-
* (parallelSum, parallelMin, etc.) for better performance.
|
|
838
|
-
*
|
|
839
|
-
* @param data - Array to reduce
|
|
840
|
-
* @param fn - Reduction function (acc, item) => newAcc
|
|
841
|
-
* @param initial - Initial accumulator value
|
|
842
|
-
* @param options - Optional configuration
|
|
843
|
-
* @returns Reduced value
|
|
844
|
-
*/
|
|
845
|
-
declare function parallelReduce<T, R>(data: T[], fn: (acc: R, item: T) => R, initial: R, options?: ReduceOptions): Promise<ParallelResult<R>>;
|
|
846
|
-
|
|
847
|
-
/**
|
|
848
|
-
* Parallel Map and Transform Operations
|
|
849
|
-
*
|
|
850
|
-
* High-performance parallel map, filter, find, and sort operations.
|
|
851
|
-
* Automatically chunks data for distribution across workers.
|
|
852
|
-
*
|
|
853
|
-
* @packageDocumentation
|
|
854
|
-
*/
|
|
855
|
-
|
|
856
|
-
/**
|
|
857
|
-
* Options for parallel map operations
|
|
858
|
-
*/
|
|
859
|
-
interface MapOptions {
|
|
860
|
-
/** Custom pool to use (defaults to global computePool) */
|
|
861
|
-
pool?: ComputePool;
|
|
862
|
-
/** Force parallel execution regardless of threshold */
|
|
863
|
-
forceParallel?: boolean;
|
|
864
|
-
/** Force sequential execution regardless of threshold */
|
|
865
|
-
forceSequential?: boolean;
|
|
866
|
-
}
|
|
867
|
-
/**
|
|
868
|
-
* Parallel map operation
|
|
869
|
-
*
|
|
870
|
-
* Applies a function to each element in parallel.
|
|
871
|
-
*
|
|
872
|
-
* @param data - Array to map over
|
|
873
|
-
* @param fn - Function to apply to each element
|
|
874
|
-
* @param options - Optional configuration
|
|
875
|
-
* @returns Mapped array
|
|
876
|
-
*
|
|
877
|
-
* @example
|
|
878
|
-
* ```typescript
|
|
879
|
-
* const data = [1, 2, 3, 4, 5];
|
|
880
|
-
* const result = await parallelMap(data, x => x * x);
|
|
881
|
-
* console.log(result.result); // [1, 4, 9, 16, 25]
|
|
882
|
-
* ```
|
|
883
|
-
*/
|
|
884
|
-
declare function parallelMap<T, R>(data: T[], fn: (item: T) => R, options?: MapOptions): Promise<ParallelResult<R[]>>;
|
|
885
|
-
/**
|
|
886
|
-
* Parallel filter operation
|
|
887
|
-
*
|
|
888
|
-
* Filters elements based on a predicate in parallel.
|
|
889
|
-
*
|
|
890
|
-
* @param data - Array to filter
|
|
891
|
-
* @param predicate - Function that returns true for elements to keep
|
|
892
|
-
* @param options - Optional configuration
|
|
893
|
-
* @returns Filtered array
|
|
894
|
-
*
|
|
895
|
-
* @example
|
|
896
|
-
* ```typescript
|
|
897
|
-
* const data = [1, 2, 3, 4, 5, 6];
|
|
898
|
-
* const result = await parallelFilter(data, x => x % 2 === 0);
|
|
899
|
-
* console.log(result.result); // [2, 4, 6]
|
|
900
|
-
* ```
|
|
901
|
-
*/
|
|
902
|
-
declare function parallelFilter<T>(data: T[], predicate: (item: T) => boolean, options?: MapOptions): Promise<ParallelResult<T[]>>;
|
|
903
|
-
/**
|
|
904
|
-
* Parallel find operation
|
|
905
|
-
*
|
|
906
|
-
* Finds the first element matching a predicate.
|
|
907
|
-
* Searches chunks in parallel for early termination.
|
|
908
|
-
*
|
|
909
|
-
* @param data - Array to search
|
|
910
|
-
* @param predicate - Function that returns true for the target element
|
|
911
|
-
* @param options - Optional configuration
|
|
912
|
-
* @returns Object with found status, value, and index
|
|
913
|
-
*
|
|
914
|
-
* @example
|
|
915
|
-
* ```typescript
|
|
916
|
-
* const data = [1, 2, 3, 4, 5];
|
|
917
|
-
* const result = await parallelFind(data, x => x > 3);
|
|
918
|
-
* console.log(result.result); // { found: true, value: 4, index: 3 }
|
|
919
|
-
* ```
|
|
920
|
-
*/
|
|
921
|
-
declare function parallelFind<T>(data: T[], predicate: (item: T) => boolean, options?: MapOptions): Promise<ParallelResult<{
|
|
922
|
-
found: boolean;
|
|
923
|
-
value?: T;
|
|
924
|
-
index?: number;
|
|
925
|
-
}>>;
|
|
926
|
-
/**
|
|
927
|
-
* Parallel sort operation
|
|
928
|
-
*
|
|
929
|
-
* Sorts an array using parallel merge sort.
|
|
930
|
-
* Each chunk is sorted in parallel, then merged.
|
|
931
|
-
*
|
|
932
|
-
* @param data - Array to sort
|
|
933
|
-
* @param compare - Optional comparison function (default: ascending)
|
|
934
|
-
* @param options - Optional configuration
|
|
935
|
-
* @returns Sorted array
|
|
936
|
-
*
|
|
937
|
-
* @example
|
|
938
|
-
* ```typescript
|
|
939
|
-
* const data = [3, 1, 4, 1, 5, 9, 2, 6];
|
|
940
|
-
* const result = await parallelSort(data);
|
|
941
|
-
* console.log(result.result); // [1, 1, 2, 3, 4, 5, 6, 9]
|
|
942
|
-
* ```
|
|
943
|
-
*/
|
|
944
|
-
declare function parallelSort<T>(data: T[], compare?: (a: T, b: T) => number, options?: MapOptions): Promise<ParallelResult<T[]>>;
|
|
945
|
-
/**
|
|
946
|
-
* Parallel forEach (for side effects)
|
|
947
|
-
*
|
|
948
|
-
* Note: This executes the function for side effects only.
|
|
949
|
-
* The function is serialized to workers, so it cannot access
|
|
950
|
-
* closures or external state.
|
|
951
|
-
*
|
|
952
|
-
* @param data - Array to iterate
|
|
953
|
-
* @param fn - Function to apply to each element
|
|
954
|
-
* @param options - Optional configuration
|
|
955
|
-
*/
|
|
956
|
-
declare function parallelForEach<T>(data: T[], fn: (item: T) => void, options?: MapOptions): Promise<ParallelResult<void[]>>;
|
|
957
|
-
/**
|
|
958
|
-
* Parallel some operation
|
|
959
|
-
*
|
|
960
|
-
* Tests whether at least one element passes the predicate.
|
|
961
|
-
*
|
|
962
|
-
* @param data - Array to test
|
|
963
|
-
* @param predicate - Test function
|
|
964
|
-
* @param options - Optional configuration
|
|
965
|
-
* @returns true if any element passes
|
|
966
|
-
*/
|
|
967
|
-
declare function parallelSome<T>(data: T[], predicate: (item: T) => boolean, options?: MapOptions): Promise<ParallelResult<boolean>>;
|
|
968
|
-
/**
|
|
969
|
-
* Parallel every operation
|
|
970
|
-
*
|
|
971
|
-
* Tests whether all elements pass the predicate.
|
|
972
|
-
*
|
|
973
|
-
* @param data - Array to test
|
|
974
|
-
* @param predicate - Test function
|
|
975
|
-
* @param options - Optional configuration
|
|
976
|
-
* @returns true if all elements pass
|
|
977
|
-
*/
|
|
978
|
-
declare function parallelEvery<T>(data: T[], predicate: (item: T) => boolean, options?: MapOptions): Promise<ParallelResult<boolean>>;
|
|
979
|
-
/**
|
|
980
|
-
* Parallel count operation
|
|
981
|
-
*
|
|
982
|
-
* Counts elements matching a predicate.
|
|
983
|
-
*
|
|
984
|
-
* @param data - Array to count
|
|
985
|
-
* @param predicate - Optional predicate (counts all if not provided)
|
|
986
|
-
* @param options - Optional configuration
|
|
987
|
-
* @returns Count of matching elements
|
|
988
|
-
*/
|
|
989
|
-
declare function parallelCount<T>(data: T[], predicate?: (item: T) => boolean, options?: MapOptions): Promise<ParallelResult<number>>;
|
|
990
|
-
|
|
991
|
-
/**
|
|
992
|
-
* Chunking Strategies for Parallel Operations
|
|
993
|
-
*
|
|
994
|
-
* Provides utilities for dividing large arrays into chunks
|
|
995
|
-
* for parallel processing across multiple workers.
|
|
996
|
-
*
|
|
997
|
-
* @packageDocumentation
|
|
998
|
-
*/
|
|
999
|
-
/**
|
|
1000
|
-
* Result of a chunking operation
|
|
1001
|
-
*/
|
|
1002
|
-
interface ChunkResult<T> {
|
|
1003
|
-
/** The chunked data */
|
|
1004
|
-
chunks: T[];
|
|
1005
|
-
/** Metadata about each chunk */
|
|
1006
|
-
chunkInfo: ChunkInfo[];
|
|
1007
|
-
/** Total number of elements */
|
|
1008
|
-
totalElements: number;
|
|
1009
|
-
/** Number of workers/chunks */
|
|
1010
|
-
numChunks: number;
|
|
1011
|
-
}
|
|
1012
|
-
/**
|
|
1013
|
-
* Information about a single chunk
|
|
1014
|
-
*/
|
|
1015
|
-
interface ChunkInfo {
|
|
1016
|
-
/** Start index in the original array */
|
|
1017
|
-
startIndex: number;
|
|
1018
|
-
/** End index (exclusive) in the original array */
|
|
1019
|
-
endIndex: number;
|
|
1020
|
-
/** Length of this chunk */
|
|
1021
|
-
length: number;
|
|
1022
|
-
/** Chunk index */
|
|
1023
|
-
chunkIndex: number;
|
|
1024
|
-
}
|
|
1025
|
-
/**
|
|
1026
|
-
* Options for chunking operations
|
|
1027
|
-
*/
|
|
1028
|
-
interface ChunkOptions {
|
|
1029
|
-
/** Minimum elements per chunk (default: 1000) */
|
|
1030
|
-
minChunkSize?: number;
|
|
1031
|
-
/** Maximum number of chunks (default: number of CPUs) */
|
|
1032
|
-
maxChunks?: number;
|
|
1033
|
-
/** Target chunk size (default: auto-calculated) */
|
|
1034
|
-
targetChunkSize?: number;
|
|
1035
|
-
/** Whether to balance chunk sizes evenly (default: true) */
|
|
1036
|
-
balanced?: boolean;
|
|
1037
|
-
}
|
|
1038
|
-
/**
|
|
1039
|
-
* Calculate optimal number of chunks for a given array size
|
|
1040
|
-
*
|
|
1041
|
-
* @param totalElements - Total number of elements
|
|
1042
|
-
* @param options - Chunking options
|
|
1043
|
-
* @returns Optimal number of chunks
|
|
1044
|
-
*/
|
|
1045
|
-
declare function calculateOptimalChunks(totalElements: number, options?: ChunkOptions): number;
|
|
1046
|
-
/**
|
|
1047
|
-
* Chunk a Float64Array into multiple smaller arrays
|
|
1048
|
-
*
|
|
1049
|
-
* @param data - The array to chunk
|
|
1050
|
-
* @param options - Chunking options
|
|
1051
|
-
* @returns Chunked data with metadata
|
|
1052
|
-
*/
|
|
1053
|
-
declare function chunkFloat64Array(data: Float64Array, options?: ChunkOptions): ChunkResult<Float64Array>;
|
|
1054
|
-
/**
|
|
1055
|
-
* Chunk a generic array into multiple smaller arrays
|
|
1056
|
-
*
|
|
1057
|
-
* @param data - The array to chunk
|
|
1058
|
-
* @param options - Chunking options
|
|
1059
|
-
* @returns Chunked data with metadata
|
|
1060
|
-
*/
|
|
1061
|
-
declare function chunkArray<T>(data: T[], options?: ChunkOptions): ChunkResult<T[]>;
|
|
1062
|
-
/**
|
|
1063
|
-
* Merge chunked results back into a single array
|
|
1064
|
-
*
|
|
1065
|
-
* @param chunks - Array of chunk results
|
|
1066
|
-
* @returns Merged array
|
|
1067
|
-
*/
|
|
1068
|
-
declare function mergeFloat64Chunks(chunks: Float64Array[]): Float64Array;
|
|
1069
|
-
/**
|
|
1070
|
-
* Merge generic array chunks
|
|
1071
|
-
*
|
|
1072
|
-
* @param chunks - Array of chunk results
|
|
1073
|
-
* @returns Merged array
|
|
1074
|
-
*/
|
|
1075
|
-
declare function mergeArrayChunks<T>(chunks: T[][]): T[];
|
|
1076
|
-
/**
|
|
1077
|
-
* Determine if an array should be parallelized based on size
|
|
1078
|
-
*
|
|
1079
|
-
* @param elementCount - Number of elements
|
|
1080
|
-
* @param threshold - Minimum elements for parallelization (default: 10000)
|
|
1081
|
-
* @returns Whether parallelization is recommended
|
|
1082
|
-
*/
|
|
1083
|
-
declare function shouldParallelize$1(elementCount: number, threshold?: number): boolean;
|
|
1084
|
-
/**
|
|
1085
|
-
* Create a range partitioner for parallel iteration
|
|
1086
|
-
*
|
|
1087
|
-
* @param start - Start of range (inclusive)
|
|
1088
|
-
* @param end - End of range (exclusive)
|
|
1089
|
-
* @param options - Chunking options
|
|
1090
|
-
* @returns Array of [start, end] pairs for each chunk
|
|
1091
|
-
*/
|
|
1092
|
-
declare function partitionRange(start: number, end: number, options?: ChunkOptions): Array<[number, number]>;
|
|
1093
|
-
/**
|
|
1094
|
-
* Create a 2D partition for matrix operations
|
|
1095
|
-
*
|
|
1096
|
-
* @param rows - Number of rows
|
|
1097
|
-
* @param cols - Number of columns
|
|
1098
|
-
* @param options - Chunking options
|
|
1099
|
-
* @returns Array of [rowStart, rowEnd, colStart, colEnd] tuples
|
|
1100
|
-
*/
|
|
1101
|
-
declare function partition2D(rows: number, cols: number, options?: ChunkOptions): Array<[number, number, number, number]>;
|
|
1102
|
-
|
|
1103
|
-
/**
|
|
1104
|
-
* Parallel Bitwise Operations
|
|
1105
|
-
*
|
|
1106
|
-
* Element-wise bitwise operations on Int32Array buffers. Operations are
|
|
1107
|
-
* applied in a chunked fashion so the work pattern mirrors the other
|
|
1108
|
-
* parallel ops (`elementwise`, `scale`, etc.). The actual chunk kernel
|
|
1109
|
-
* runs in-process: the MathWorkerPool kernel registry in
|
|
1110
|
-
* `@danielsimonjr/mathts-workerpool` is keyed on `Float64Array` buffers,
|
|
1111
|
-
* so cross-thread bitwise dispatch is intentionally out of scope here.
|
|
1112
|
-
*
|
|
1113
|
-
* The chunking still matters: it bounds peak-allocation pressure for
|
|
1114
|
-
* very large arrays and keeps the call shape uniform with the rest of
|
|
1115
|
-
* the parallel API, so the typed-function `Int32Array, Int32Array`
|
|
1116
|
-
* signatures look identical to the `Float64Array, Float64Array` ones.
|
|
1117
|
-
*
|
|
1118
|
-
* Semantics follow JavaScript bitwise semantics on 32-bit signed
|
|
1119
|
-
* integers (two's complement). For shift counts JavaScript itself
|
|
1120
|
-
* masks to the low 5 bits — we preserve that behavior.
|
|
1121
|
-
*
|
|
1122
|
-
* @packageDocumentation
|
|
1123
|
-
*/
|
|
1124
|
-
|
|
1125
|
-
/**
|
|
1126
|
-
* The set of supported binary bitwise op codes.
|
|
1127
|
-
*
|
|
1128
|
-
* - `bitAnd` : `a & b`
|
|
1129
|
-
* - `bitOr` : `a | b`
|
|
1130
|
-
* - `bitXor` : `a ^ b`
|
|
1131
|
-
* - `leftShift` : `a << b`
|
|
1132
|
-
* - `rightArithShift` : `a >> b` (sign-extending)
|
|
1133
|
-
* - `rightLogShift` : `a >>> b` (zero-filling, returned as Int32 — values
|
|
1134
|
-
* above 2^31 wrap into negative range, as in `(x >>> n) | 0`)
|
|
1135
|
-
*/
|
|
1136
|
-
type BitwiseBinaryOp = 'bitAnd' | 'bitOr' | 'bitXor' | 'leftShift' | 'rightArithShift' | 'rightLogShift';
|
|
1137
|
-
/**
|
|
1138
|
-
* Bitwise AND on two equal-length `Int32Array`s.
|
|
1139
|
-
*/
|
|
1140
|
-
declare function bitAnd(a: Int32Array, b: Int32Array, options?: ChunkOptions): Int32Array;
|
|
1141
|
-
/**
|
|
1142
|
-
* Bitwise OR on two equal-length `Int32Array`s.
|
|
1143
|
-
*/
|
|
1144
|
-
declare function bitOr(a: Int32Array, b: Int32Array, options?: ChunkOptions): Int32Array;
|
|
1145
|
-
/**
|
|
1146
|
-
* Bitwise XOR on two equal-length `Int32Array`s.
|
|
1147
|
-
*/
|
|
1148
|
-
declare function bitXor(a: Int32Array, b: Int32Array, options?: ChunkOptions): Int32Array;
|
|
1149
|
-
/**
|
|
1150
|
-
* Element-wise left shift: `a[i] << b[i]`.
|
|
1151
|
-
*
|
|
1152
|
-
* `b` may be either an `Int32Array` of per-element shift counts or a
|
|
1153
|
-
* single scalar `number` (applied uniformly). Shift counts are masked
|
|
1154
|
-
* to the low 5 bits by JavaScript itself — values ≥ 32 fold back into
|
|
1155
|
-
* `[0, 31]`.
|
|
1156
|
-
*/
|
|
1157
|
-
declare function leftShift(a: Int32Array, b: Int32Array | number, options?: ChunkOptions): Int32Array;
|
|
1158
|
-
/**
|
|
1159
|
-
* Element-wise arithmetic (sign-preserving) right shift: `a[i] >> b[i]`.
|
|
1160
|
-
*/
|
|
1161
|
-
declare function rightArithShift(a: Int32Array, b: Int32Array | number, options?: ChunkOptions): Int32Array;
|
|
1162
|
-
/**
|
|
1163
|
-
* Element-wise logical (zero-filling) right shift: `a[i] >>> b[i]`.
|
|
1164
|
-
*
|
|
1165
|
-
* Result is stored as `Int32Array`, so values ≥ 2^31 wrap into the
|
|
1166
|
-
* negative range — equivalent to `(x >>> n) | 0`.
|
|
1167
|
-
*/
|
|
1168
|
-
declare function rightLogShift(a: Int32Array, b: Int32Array | number, options?: ChunkOptions): Int32Array;
|
|
1169
|
-
/**
|
|
1170
|
-
* Unary bitwise NOT: `~a[i]`. Returns a fresh `Int32Array`.
|
|
1171
|
-
*/
|
|
1172
|
-
declare function bitNot(a: Int32Array, options?: ChunkOptions): Int32Array;
|
|
1173
|
-
|
|
1174
|
-
/**
|
|
1175
|
-
* Threshold-based Dispatch Strategy
|
|
1176
|
-
*
|
|
1177
|
-
* Automatically decides whether to use parallel or sequential execution
|
|
1178
|
-
* based on data size, operation type, and system capabilities.
|
|
1179
|
-
*
|
|
1180
|
-
* @packageDocumentation
|
|
1181
|
-
*/
|
|
1182
|
-
|
|
1183
|
-
/**
|
|
1184
|
-
* Operation categories for threshold selection
|
|
1185
|
-
*/
|
|
1186
|
-
type OperationCategory = 'matmul' | 'elementwise' | 'reduce' | 'map' | 'sort' | 'decomposition' | 'general';
|
|
1187
|
-
/**
|
|
1188
|
-
* Threshold configuration for different operation types
|
|
1189
|
-
*/
|
|
1190
|
-
interface ThresholdConfig {
|
|
1191
|
-
/** Minimum elements for parallel matmul */
|
|
1192
|
-
matmul: number;
|
|
1193
|
-
/** Minimum elements for parallel elementwise ops */
|
|
1194
|
-
elementwise: number;
|
|
1195
|
-
/** Minimum elements for parallel reductions */
|
|
1196
|
-
reduce: number;
|
|
1197
|
-
/** Minimum elements for parallel map */
|
|
1198
|
-
map: number;
|
|
1199
|
-
/** Minimum elements for parallel sort */
|
|
1200
|
-
sort: number;
|
|
1201
|
-
/** Minimum elements for parallel decomposition */
|
|
1202
|
-
decomposition: number;
|
|
1203
|
-
/** Default threshold for other operations */
|
|
1204
|
-
general: number;
|
|
1205
|
-
}
|
|
1206
|
-
/**
|
|
1207
|
-
* Default category-level thresholds.
|
|
1208
|
-
*
|
|
1209
|
-
* NOTE: `ComputePool.shouldParallelize` (op-level, {@link DEFAULT_THRESHOLD_BY_OP})
|
|
1210
|
-
* is the authority the typed functions dispatch through. This category map is a
|
|
1211
|
-
* coarser helper; where a category overlaps a tuned op (matmul) its value is
|
|
1212
|
-
* derived from the canonical const so the two cannot diverge. The remaining
|
|
1213
|
-
* categories (no single ComputePool op equivalent — many are 'never') keep
|
|
1214
|
-
* heuristic defaults for compute-vs-memory-bound work.
|
|
1215
|
-
*/
|
|
1216
|
-
declare const DEFAULT_THRESHOLDS: ThresholdConfig;
|
|
1217
|
-
/**
|
|
1218
|
-
* Execution mode returned by threshold dispatch
|
|
1219
|
-
*/
|
|
1220
|
-
type ExecutionMode = 'parallel' | 'sequential';
|
|
1221
|
-
/**
|
|
1222
|
-
* Result of threshold dispatch decision
|
|
1223
|
-
*/
|
|
1224
|
-
interface DispatchResult {
|
|
1225
|
-
/** Recommended execution mode */
|
|
1226
|
-
mode: ExecutionMode;
|
|
1227
|
-
/** Reason for the decision */
|
|
1228
|
-
reason: string;
|
|
1229
|
-
/** Threshold used for comparison */
|
|
1230
|
-
threshold: number;
|
|
1231
|
-
/** Actual element count */
|
|
1232
|
-
elementCount: number;
|
|
1233
|
-
}
|
|
1234
|
-
/**
|
|
1235
|
-
* Threshold-based Dispatch Manager
|
|
1236
|
-
*
|
|
1237
|
-
* Provides intelligent parallel vs sequential dispatch based on
|
|
1238
|
-
* operation type, data size, and system state.
|
|
1239
|
-
*/
|
|
1240
|
-
declare class ThresholdDispatcher {
|
|
1241
|
-
private thresholds;
|
|
1242
|
-
private pool;
|
|
1243
|
-
constructor(thresholds?: Partial<ThresholdConfig>, pool?: ComputePool);
|
|
1244
|
-
/**
|
|
1245
|
-
* Get threshold for a specific operation category
|
|
1246
|
-
*/
|
|
1247
|
-
getThreshold(category: OperationCategory): number;
|
|
1248
|
-
/**
|
|
1249
|
-
* Update thresholds
|
|
1250
|
-
*/
|
|
1251
|
-
setThresholds(thresholds: Partial<ThresholdConfig>): void;
|
|
1252
|
-
/**
|
|
1253
|
-
* Get current threshold configuration
|
|
1254
|
-
*/
|
|
1255
|
-
getThresholds(): ThresholdConfig;
|
|
1256
|
-
/**
|
|
1257
|
-
* Determine execution mode based on operation and data size
|
|
1258
|
-
*/
|
|
1259
|
-
dispatch(elementCount: number, category?: OperationCategory): DispatchResult;
|
|
1260
|
-
/**
|
|
1261
|
-
* Simple boolean check for parallel execution
|
|
1262
|
-
*/
|
|
1263
|
-
shouldParallelize(elementCount: number, category?: OperationCategory): boolean;
|
|
1264
|
-
/**
|
|
1265
|
-
* Calculate optimal chunk count based on operation and data size
|
|
1266
|
-
*/
|
|
1267
|
-
calculateChunks(elementCount: number, category?: OperationCategory): number;
|
|
1268
|
-
}
|
|
1269
|
-
/**
|
|
1270
|
-
* Global threshold dispatcher instance
|
|
1271
|
-
*/
|
|
1272
|
-
declare const thresholdDispatcher: ThresholdDispatcher;
|
|
1273
|
-
/**
|
|
1274
|
-
* Convenience function to check if operation should be parallelized
|
|
1275
|
-
*/
|
|
1276
|
-
declare function shouldParallelize(elementCount: number, category?: OperationCategory): boolean;
|
|
1277
|
-
/**
|
|
1278
|
-
* Convenience function to get dispatch decision
|
|
1279
|
-
*/
|
|
1280
|
-
declare function dispatch(elementCount: number, category?: OperationCategory): DispatchResult;
|
|
1281
|
-
/**
|
|
1282
|
-
* Convenience function to calculate optimal chunk count
|
|
1283
|
-
*/
|
|
1284
|
-
declare function calculateChunks(elementCount: number, category?: OperationCategory): number;
|
|
1285
|
-
|
|
1286
|
-
export { type BitwiseBinaryOp, type ChunkInfo, type ChunkOptions, type ChunkResult, ComputePool, type ComputePoolConfig, DEFAULT_POOL_CONFIG, DEFAULT_THRESHOLDS, DEFAULT_THRESHOLD_BY_OP, type DispatchResult, type ElementwiseOptions, type ExecutionMode, type MapOptions, type MatmulOptions, type OpName, type OpThreshold, type OperationCategory, type ParallelResult, type ReduceOptions, type ThresholdConfig, ThresholdDispatcher, bitAnd, bitNot, bitOr, bitXor, calculateChunks, calculateOptimalChunks, chunkArray, chunkFloat64Array, computePool, dispatch, leftShift, mergeArrayChunks, mergeFloat64Chunks, parallelAbs, parallelAdd, parallelCos, parallelCount, parallelDistance, parallelDivide, parallelDot, parallelElementwise, parallelEvery, parallelExp, parallelFilter, parallelFind, parallelForEach, parallelHistogram, parallelLog, parallelMap, parallelMatmul, parallelMatvec, parallelMax, parallelMean, parallelMin, parallelMinMax, parallelMultiply, parallelNegate, parallelNorm, parallelOuter, parallelReduce, parallelScale, parallelSin, parallelSome, parallelSort, parallelSqrt, parallelSquare, parallelStd, parallelSubtract, parallelSum, parallelTan, parallelTranspose, parallelUnary, parallelVariance, partition2D, partitionRange, resolveOpThreshold, rightArithShift, rightLogShift, shouldParallelize$1 as shouldChunkParallelize, shouldParallelize, thresholdDispatcher };
|
|
9
|
+
export { ComputePool, computePool, Transfer, DEFAULT_POOL_CONFIG, DEFAULT_THRESHOLD_BY_OP, resolveOpThreshold, } from './ComputePool.js';
|
|
10
|
+
export type { ComputePoolConfig, ParallelResult, OpName, OpThreshold } from './ComputePool.js';
|
|
11
|
+
export { parallelMatmul, parallelMatvec, parallelTranspose, parallelOuter, parallelDot, parallelAdd, parallelSubtract, parallelMultiply, parallelDivide, parallelScale, parallelAbs, parallelNegate, parallelSquare, parallelSqrt, parallelExp, parallelLog, parallelSin, parallelCos, parallelTan, parallelElementwise, parallelUnary, parallelSum, parallelMean, parallelMin, parallelMax, parallelMinMax, parallelVariance, parallelStd, parallelNorm, parallelDistance, parallelHistogram, parallelReduce, parallelMap, parallelFilter, parallelFind, parallelSort, parallelForEach, parallelSome, parallelEvery, parallelCount, } from './operations/index.js';
|
|
12
|
+
export type { MatmulOptions, ElementwiseOptions, ReduceOptions, MapOptions, } from './operations/index.js';
|
|
13
|
+
export { bitAnd, bitOr, bitXor, bitNot, leftShift, rightArithShift, rightLogShift, } from './ops/bitwise.js';
|
|
14
|
+
export type { BitwiseBinaryOp } from './ops/bitwise.js';
|
|
15
|
+
export { calculateOptimalChunks, chunkFloat64Array, chunkArray, mergeFloat64Chunks, mergeArrayChunks, shouldChunkParallelize, partitionRange, partition2D, ThresholdDispatcher, thresholdDispatcher, shouldParallelize, dispatch, calculateChunks, DEFAULT_THRESHOLDS, } from './strategies/index.js';
|
|
16
|
+
export type { ChunkOptions, ChunkResult, ChunkInfo, ThresholdConfig, OperationCategory, ExecutionMode, DispatchResult, } from './strategies/index.js';
|
|
17
|
+
export type { PoolOptions, ExecOptions, PoolStats } from '@danielsimonjr/mathts-workerpool';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|