@danielsimonjr/mathts-parallel 0.6.4 → 0.6.5
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/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 +58 -58
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EACR,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAM/F,OAAO,EAEL,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,WAAW,EAGX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,WAAW,EACX,cAAc,EACd,cAAc,EACd,YAAY,EACZ,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,aAAa,EAGb,WAAW,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EAGd,WAAW,EACX,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,aAAa,EACb,aAAa,GACd,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,UAAU,GACX,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EACL,MAAM,EACN,KAAK,EACL,MAAM,EACN,MAAM,EACN,SAAS,EACT,eAAe,EACf,aAAa,GACd,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAMxD,OAAO,EAEL,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,WAAW,EAGX,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,QAAQ,EACR,eAAe,EACf,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EACV,YAAY,EACZ,WAAW,EACX,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC;AAU/B,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC"}
|
package/dist/matrix.worker.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Matrix Worker for parallel computation
|
|
3
|
+
* Handles matrix operations in a separate thread.
|
|
4
|
+
*
|
|
5
|
+
* Each task computes a contiguous slice of the output and returns it. The
|
|
6
|
+
* parent ({@link ParallelMatrix}) copies returned slices back into the result
|
|
7
|
+
* buffer. Returning the data (rather than relying on in-place mutation of a
|
|
8
|
+
* shared buffer) keeps the worker correct whether or not the caller is using
|
|
9
|
+
* SharedArrayBuffer — a structured-clone copy of a non-shared `resultData`
|
|
10
|
+
* would otherwise be discarded and the caller would observe all zeros.
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=matrix.worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix.worker.d.ts","sourceRoot":"","sources":["../src/matrix.worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAmQH,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel Element-wise Operations
|
|
3
|
+
*
|
|
4
|
+
* High-performance parallel element-wise operations on arrays.
|
|
5
|
+
* Automatically chunks data for distribution across workers.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { ComputePool } from '../ComputePool.js';
|
|
10
|
+
import type { ParallelResult } from '../ComputePool.js';
|
|
11
|
+
/**
|
|
12
|
+
* Options for parallel element-wise operations
|
|
13
|
+
*/
|
|
14
|
+
export interface ElementwiseOptions {
|
|
15
|
+
/** Custom pool to use (defaults to global computePool) */
|
|
16
|
+
pool?: ComputePool;
|
|
17
|
+
/** Force parallel execution regardless of threshold */
|
|
18
|
+
forceParallel?: boolean;
|
|
19
|
+
/** Force sequential execution regardless of threshold */
|
|
20
|
+
forceSequential?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parallel element-wise addition (c[i] = a[i] + b[i])
|
|
24
|
+
*/
|
|
25
|
+
export declare function parallelAdd(a: Float64Array, b: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
26
|
+
/**
|
|
27
|
+
* Parallel element-wise subtraction (c[i] = a[i] - b[i])
|
|
28
|
+
*/
|
|
29
|
+
export declare function parallelSubtract(a: Float64Array, b: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
30
|
+
/**
|
|
31
|
+
* Parallel element-wise multiplication (c[i] = a[i] * b[i])
|
|
32
|
+
*/
|
|
33
|
+
export declare function parallelMultiply(a: Float64Array, b: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
34
|
+
/**
|
|
35
|
+
* Parallel element-wise division (c[i] = a[i] / b[i])
|
|
36
|
+
*/
|
|
37
|
+
export declare function parallelDivide(a: Float64Array, b: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
38
|
+
/**
|
|
39
|
+
* Parallel scalar multiplication (b[i] = a[i] * scalar)
|
|
40
|
+
*/
|
|
41
|
+
export declare function parallelScale(data: Float64Array, scalar: number, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
42
|
+
/**
|
|
43
|
+
* Parallel absolute value (b[i] = |a[i]|)
|
|
44
|
+
*/
|
|
45
|
+
export declare function parallelAbs(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
46
|
+
/**
|
|
47
|
+
* Parallel negation (b[i] = -a[i])
|
|
48
|
+
*/
|
|
49
|
+
export declare function parallelNegate(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
50
|
+
/**
|
|
51
|
+
* Parallel square (b[i] = a[i]²)
|
|
52
|
+
*/
|
|
53
|
+
export declare function parallelSquare(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
54
|
+
/**
|
|
55
|
+
* Parallel square root (b[i] = √a[i])
|
|
56
|
+
*/
|
|
57
|
+
export declare function parallelSqrt(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
58
|
+
/**
|
|
59
|
+
* Parallel exponential (b[i] = e^a[i])
|
|
60
|
+
*/
|
|
61
|
+
export declare function parallelExp(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
62
|
+
/**
|
|
63
|
+
* Parallel natural logarithm (b[i] = ln(a[i]))
|
|
64
|
+
*/
|
|
65
|
+
export declare function parallelLog(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
66
|
+
/**
|
|
67
|
+
* Parallel sine (b[i] = sin(a[i]))
|
|
68
|
+
*/
|
|
69
|
+
export declare function parallelSin(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
70
|
+
/**
|
|
71
|
+
* Parallel cosine (b[i] = cos(a[i]))
|
|
72
|
+
*/
|
|
73
|
+
export declare function parallelCos(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
74
|
+
/**
|
|
75
|
+
* Parallel tangent (b[i] = tan(a[i]))
|
|
76
|
+
*/
|
|
77
|
+
export declare function parallelTan(data: Float64Array, options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
78
|
+
/**
|
|
79
|
+
* Generic parallel element-wise operation
|
|
80
|
+
*/
|
|
81
|
+
export declare function parallelElementwise(a: Float64Array, b: Float64Array, op: 'add' | 'subtract' | 'multiply' | 'divide', options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
82
|
+
/**
|
|
83
|
+
* Generic parallel unary operation
|
|
84
|
+
*/
|
|
85
|
+
export declare function parallelUnary(data: Float64Array, fn: 'abs' | 'sqrt' | 'exp' | 'log' | 'sin' | 'cos' | 'tan' | 'negate' | 'square', options?: ElementwiseOptions): Promise<ParallelResult<Float64Array>>;
|
|
86
|
+
//# sourceMappingURL=elementwise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elementwise.d.ts","sourceRoot":"","sources":["../../src/operations/elementwise.ts"],"names":[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AAE,YAAY,EACf,EAAE,EAAE,KAAK,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,EAC9C,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAGvC;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,YAAY,EAClB,EAAE,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,EAChF,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAGvC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel Operations
|
|
3
|
+
*
|
|
4
|
+
* High-level parallel operations for matrix and array computations.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export { parallelMatmul, parallelMatvec, parallelTranspose, parallelOuter, parallelDot, type MatmulOptions, } from './matmul.js';
|
|
9
|
+
export { parallelAdd, parallelSubtract, parallelMultiply, parallelDivide, parallelScale, parallelAbs, parallelNegate, parallelSquare, parallelSqrt, parallelExp, parallelLog, parallelSin, parallelCos, parallelTan, parallelElementwise, parallelUnary, type ElementwiseOptions, } from './elementwise.js';
|
|
10
|
+
export { parallelSum, parallelMean, parallelMin, parallelMax, parallelMinMax, parallelVariance, parallelStd, parallelNorm, parallelDistance, parallelHistogram, parallelReduce, type ReduceOptions, } from './reduce.js';
|
|
11
|
+
export { parallelMap, parallelFilter, parallelFind, parallelSort, parallelForEach, parallelSome, parallelEvery, parallelCount, type MapOptions, } from './map.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/operations/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,KAAK,aAAa,GACnB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,WAAW,EACX,cAAc,EACd,cAAc,EACd,YAAY,EACZ,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,KAAK,kBAAkB,GACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,KAAK,aAAa,GACnB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,WAAW,EACX,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,aAAa,EACb,aAAa,EACb,KAAK,UAAU,GAChB,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel Map and Transform Operations
|
|
3
|
+
*
|
|
4
|
+
* High-performance parallel map, filter, find, and sort operations.
|
|
5
|
+
* Automatically chunks data for distribution across workers.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { ComputePool } from '../ComputePool.js';
|
|
10
|
+
import type { ParallelResult } from '../ComputePool.js';
|
|
11
|
+
/**
|
|
12
|
+
* Options for parallel map operations
|
|
13
|
+
*/
|
|
14
|
+
export interface MapOptions {
|
|
15
|
+
/** Custom pool to use (defaults to global computePool) */
|
|
16
|
+
pool?: ComputePool;
|
|
17
|
+
/** Force parallel execution regardless of threshold */
|
|
18
|
+
forceParallel?: boolean;
|
|
19
|
+
/** Force sequential execution regardless of threshold */
|
|
20
|
+
forceSequential?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parallel map operation
|
|
24
|
+
*
|
|
25
|
+
* Applies a function to each element in parallel.
|
|
26
|
+
*
|
|
27
|
+
* @param data - Array to map over
|
|
28
|
+
* @param fn - Function to apply to each element
|
|
29
|
+
* @param options - Optional configuration
|
|
30
|
+
* @returns Mapped array
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const data = [1, 2, 3, 4, 5];
|
|
35
|
+
* const result = await parallelMap(data, x => x * x);
|
|
36
|
+
* console.log(result.result); // [1, 4, 9, 16, 25]
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function parallelMap<T, R>(data: T[], fn: (item: T) => R, options?: MapOptions): Promise<ParallelResult<R[]>>;
|
|
40
|
+
/**
|
|
41
|
+
* Parallel filter operation
|
|
42
|
+
*
|
|
43
|
+
* Filters elements based on a predicate in parallel.
|
|
44
|
+
*
|
|
45
|
+
* @param data - Array to filter
|
|
46
|
+
* @param predicate - Function that returns true for elements to keep
|
|
47
|
+
* @param options - Optional configuration
|
|
48
|
+
* @returns Filtered array
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const data = [1, 2, 3, 4, 5, 6];
|
|
53
|
+
* const result = await parallelFilter(data, x => x % 2 === 0);
|
|
54
|
+
* console.log(result.result); // [2, 4, 6]
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function parallelFilter<T>(data: T[], predicate: (item: T) => boolean, options?: MapOptions): Promise<ParallelResult<T[]>>;
|
|
58
|
+
/**
|
|
59
|
+
* Parallel find operation
|
|
60
|
+
*
|
|
61
|
+
* Finds the first element matching a predicate.
|
|
62
|
+
* Searches chunks in parallel for early termination.
|
|
63
|
+
*
|
|
64
|
+
* @param data - Array to search
|
|
65
|
+
* @param predicate - Function that returns true for the target element
|
|
66
|
+
* @param options - Optional configuration
|
|
67
|
+
* @returns Object with found status, value, and index
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const data = [1, 2, 3, 4, 5];
|
|
72
|
+
* const result = await parallelFind(data, x => x > 3);
|
|
73
|
+
* console.log(result.result); // { found: true, value: 4, index: 3 }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function parallelFind<T>(data: T[], predicate: (item: T) => boolean, options?: MapOptions): Promise<ParallelResult<{
|
|
77
|
+
found: boolean;
|
|
78
|
+
value?: T;
|
|
79
|
+
index?: number;
|
|
80
|
+
}>>;
|
|
81
|
+
/**
|
|
82
|
+
* Parallel sort operation
|
|
83
|
+
*
|
|
84
|
+
* Sorts an array using parallel merge sort.
|
|
85
|
+
* Each chunk is sorted in parallel, then merged.
|
|
86
|
+
*
|
|
87
|
+
* @param data - Array to sort
|
|
88
|
+
* @param compare - Optional comparison function (default: ascending)
|
|
89
|
+
* @param options - Optional configuration
|
|
90
|
+
* @returns Sorted array
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const data = [3, 1, 4, 1, 5, 9, 2, 6];
|
|
95
|
+
* const result = await parallelSort(data);
|
|
96
|
+
* console.log(result.result); // [1, 1, 2, 3, 4, 5, 6, 9]
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function parallelSort<T>(data: T[], compare?: (a: T, b: T) => number, options?: MapOptions): Promise<ParallelResult<T[]>>;
|
|
100
|
+
/**
|
|
101
|
+
* Parallel forEach (for side effects)
|
|
102
|
+
*
|
|
103
|
+
* Note: This executes the function for side effects only.
|
|
104
|
+
* The function is serialized to workers, so it cannot access
|
|
105
|
+
* closures or external state.
|
|
106
|
+
*
|
|
107
|
+
* @param data - Array to iterate
|
|
108
|
+
* @param fn - Function to apply to each element
|
|
109
|
+
* @param options - Optional configuration
|
|
110
|
+
*/
|
|
111
|
+
export declare function parallelForEach<T>(data: T[], fn: (item: T) => void, options?: MapOptions): Promise<ParallelResult<void[]>>;
|
|
112
|
+
/**
|
|
113
|
+
* Parallel some operation
|
|
114
|
+
*
|
|
115
|
+
* Tests whether at least one element passes the predicate.
|
|
116
|
+
*
|
|
117
|
+
* @param data - Array to test
|
|
118
|
+
* @param predicate - Test function
|
|
119
|
+
* @param options - Optional configuration
|
|
120
|
+
* @returns true if any element passes
|
|
121
|
+
*/
|
|
122
|
+
export declare function parallelSome<T>(data: T[], predicate: (item: T) => boolean, options?: MapOptions): Promise<ParallelResult<boolean>>;
|
|
123
|
+
/**
|
|
124
|
+
* Parallel every operation
|
|
125
|
+
*
|
|
126
|
+
* Tests whether all elements pass the predicate.
|
|
127
|
+
*
|
|
128
|
+
* @param data - Array to test
|
|
129
|
+
* @param predicate - Test function
|
|
130
|
+
* @param options - Optional configuration
|
|
131
|
+
* @returns true if all elements pass
|
|
132
|
+
*/
|
|
133
|
+
export declare function parallelEvery<T>(data: T[], predicate: (item: T) => boolean, options?: MapOptions): Promise<ParallelResult<boolean>>;
|
|
134
|
+
/**
|
|
135
|
+
* Parallel count operation
|
|
136
|
+
*
|
|
137
|
+
* Counts elements matching a predicate.
|
|
138
|
+
*
|
|
139
|
+
* @param data - Array to count
|
|
140
|
+
* @param predicate - Optional predicate (counts all if not provided)
|
|
141
|
+
* @param options - Optional configuration
|
|
142
|
+
* @returns Count of matching elements
|
|
143
|
+
*/
|
|
144
|
+
export declare function parallelCount<T>(data: T[], predicate?: (item: T) => boolean, options?: MapOptions): Promise<ParallelResult<number>>;
|
|
145
|
+
//# sourceMappingURL=map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/operations/map.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,UAA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;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,IAAI,EAAE,CAAC,EAAE,EACT,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,EACrB,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,CAUjC;AAED;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAClC,IAAI,EAAE,CAAC,EAAE,EACT,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,EAC/B,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAOlC;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,IAAI,EAAE,CAAC,EAAE,EACT,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,EAC/B,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAQlC;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,IAAI,EAAE,CAAC,EAAE,EACT,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,EAChC,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAkBjC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel Matrix Multiplication
|
|
3
|
+
*
|
|
4
|
+
* High-performance parallel matrix multiplication with automatic chunking.
|
|
5
|
+
* Distributes rows across workers for parallel computation.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { ComputePool } from '../ComputePool.js';
|
|
10
|
+
import type { ParallelResult } from '../ComputePool.js';
|
|
11
|
+
/**
|
|
12
|
+
* Options for parallel matrix multiplication
|
|
13
|
+
*/
|
|
14
|
+
export interface MatmulOptions {
|
|
15
|
+
/** Custom pool to use (defaults to global computePool) */
|
|
16
|
+
pool?: ComputePool;
|
|
17
|
+
/** Force parallel execution regardless of threshold */
|
|
18
|
+
forceParallel?: boolean;
|
|
19
|
+
/** Force sequential execution regardless of threshold */
|
|
20
|
+
forceSequential?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parallel matrix multiplication (C = A × B)
|
|
24
|
+
*
|
|
25
|
+
* Multiplies two matrices using parallel workers. The computation
|
|
26
|
+
* distributes rows of matrix A across available workers.
|
|
27
|
+
*
|
|
28
|
+
* @param a - First matrix as flat Float64Array (row-major order)
|
|
29
|
+
* @param aRows - Number of rows in matrix A
|
|
30
|
+
* @param aCols - Number of columns in matrix A (must equal bRows)
|
|
31
|
+
* @param b - Second matrix as flat Float64Array (row-major order)
|
|
32
|
+
* @param bCols - Number of columns in matrix B
|
|
33
|
+
* @param options - Optional configuration
|
|
34
|
+
* @returns Result matrix C (aRows × bCols) with parallel execution metadata
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // 2x3 matrix * 3x2 matrix = 2x2 matrix
|
|
39
|
+
* const A = new Float64Array([1, 2, 3, 4, 5, 6]);
|
|
40
|
+
* const B = new Float64Array([7, 8, 9, 10, 11, 12]);
|
|
41
|
+
*
|
|
42
|
+
* const result = await parallelMatmul(A, 2, 3, B, 2);
|
|
43
|
+
* console.log(result.result); // 2x2 result matrix
|
|
44
|
+
* console.log(result.parallelized); // true if workers were used
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function parallelMatmul(a: Float64Array, aRows: number, aCols: number, b: Float64Array, bCols: number, options?: MatmulOptions): Promise<ParallelResult<Float64Array>>;
|
|
48
|
+
/**
|
|
49
|
+
* Parallel matrix-vector multiplication (y = A × x)
|
|
50
|
+
*
|
|
51
|
+
* Multiplies a matrix by a vector using parallel workers.
|
|
52
|
+
*
|
|
53
|
+
* @param matrix - Matrix as flat Float64Array (row-major order)
|
|
54
|
+
* @param rows - Number of rows in the matrix
|
|
55
|
+
* @param cols - Number of columns in the matrix (must equal vector length)
|
|
56
|
+
* @param vector - Vector as Float64Array
|
|
57
|
+
* @param options - Optional configuration
|
|
58
|
+
* @returns Result vector with parallel execution metadata
|
|
59
|
+
*/
|
|
60
|
+
export declare function parallelMatvec(matrix: Float64Array, rows: number, cols: number, vector: Float64Array, options?: MatmulOptions): Promise<ParallelResult<Float64Array>>;
|
|
61
|
+
/**
|
|
62
|
+
* Parallel matrix transpose
|
|
63
|
+
*
|
|
64
|
+
* Transposes a matrix using parallel workers.
|
|
65
|
+
*
|
|
66
|
+
* @param data - Matrix as flat Float64Array (row-major order)
|
|
67
|
+
* @param rows - Number of rows in the original matrix
|
|
68
|
+
* @param cols - Number of columns in the original matrix
|
|
69
|
+
* @param options - Optional configuration
|
|
70
|
+
* @returns Transposed matrix (cols × rows) with parallel execution metadata
|
|
71
|
+
*/
|
|
72
|
+
export declare function parallelTranspose(data: Float64Array, rows: number, cols: number, options?: MatmulOptions): Promise<ParallelResult<Float64Array>>;
|
|
73
|
+
/**
|
|
74
|
+
* Parallel outer product (C = a ⊗ b)
|
|
75
|
+
*
|
|
76
|
+
* Computes the outer product of two vectors.
|
|
77
|
+
*
|
|
78
|
+
* @param a - First vector
|
|
79
|
+
* @param b - Second vector
|
|
80
|
+
* @param options - Optional configuration
|
|
81
|
+
* @returns Outer product matrix (a.length × b.length)
|
|
82
|
+
*/
|
|
83
|
+
export declare function parallelOuter(a: Float64Array, b: Float64Array, options?: MatmulOptions): Promise<ParallelResult<Float64Array>>;
|
|
84
|
+
/**
|
|
85
|
+
* Parallel dot product (scalar = a · b)
|
|
86
|
+
*
|
|
87
|
+
* Computes the dot product of two vectors.
|
|
88
|
+
*
|
|
89
|
+
* @param a - First vector
|
|
90
|
+
* @param b - Second vector (must have same length as a)
|
|
91
|
+
* @param options - Optional configuration
|
|
92
|
+
* @returns Dot product scalar
|
|
93
|
+
*/
|
|
94
|
+
export declare function parallelDot(a: Float64Array, b: Float64Array, options?: MatmulOptions): Promise<ParallelResult<number>>;
|
|
95
|
+
//# sourceMappingURL=matmul.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matmul.d.ts","sourceRoot":"","sources":["../../src/operations/matmul.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,0DAA0D;IAC1D,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,uDAAuD;IACvD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,yDAAyD;IACzD,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,cAAc,CAClC,CAAC,EAAE,YAAY,EACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,CAAC,EAAE,YAAY,EACf,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAGvC;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAGvC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAGvC;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAGvC;AAED;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAC/B,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAGjC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel Reduction Operations
|
|
3
|
+
*
|
|
4
|
+
* High-performance parallel reduction operations (sum, min, max, etc.).
|
|
5
|
+
* Uses parallel aggregation with sequential final reduction.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { ComputePool } from '../ComputePool.js';
|
|
10
|
+
import type { ParallelResult } from '../ComputePool.js';
|
|
11
|
+
/**
|
|
12
|
+
* Options for parallel reduction operations
|
|
13
|
+
*/
|
|
14
|
+
export interface ReduceOptions {
|
|
15
|
+
/** Custom pool to use (defaults to global computePool) */
|
|
16
|
+
pool?: ComputePool;
|
|
17
|
+
/** Force parallel execution regardless of threshold */
|
|
18
|
+
forceParallel?: boolean;
|
|
19
|
+
/** Force sequential execution regardless of threshold */
|
|
20
|
+
forceSequential?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parallel sum reduction
|
|
24
|
+
*
|
|
25
|
+
* Computes the sum of all elements using parallel partial sums.
|
|
26
|
+
*
|
|
27
|
+
* @param data - Array to sum
|
|
28
|
+
* @param options - Optional configuration
|
|
29
|
+
* @returns Sum of all elements
|
|
30
|
+
*/
|
|
31
|
+
export declare function parallelSum(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
32
|
+
/**
|
|
33
|
+
* Parallel mean computation
|
|
34
|
+
*
|
|
35
|
+
* @param data - Array to compute mean of
|
|
36
|
+
* @param options - Optional configuration
|
|
37
|
+
* @returns Mean value
|
|
38
|
+
*/
|
|
39
|
+
export declare function parallelMean(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
40
|
+
/**
|
|
41
|
+
* Parallel minimum value
|
|
42
|
+
*
|
|
43
|
+
* @param data - Array to find minimum of
|
|
44
|
+
* @param options - Optional configuration
|
|
45
|
+
* @returns Minimum value
|
|
46
|
+
*/
|
|
47
|
+
export declare function parallelMin(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
48
|
+
/**
|
|
49
|
+
* Parallel maximum value
|
|
50
|
+
*
|
|
51
|
+
* @param data - Array to find maximum of
|
|
52
|
+
* @param options - Optional configuration
|
|
53
|
+
* @returns Maximum value
|
|
54
|
+
*/
|
|
55
|
+
export declare function parallelMax(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
56
|
+
/**
|
|
57
|
+
* Parallel min/max with indices
|
|
58
|
+
*
|
|
59
|
+
* @param data - Array to analyze
|
|
60
|
+
* @param options - Optional configuration
|
|
61
|
+
* @returns Object with min, max, minIdx, maxIdx
|
|
62
|
+
*/
|
|
63
|
+
export declare function parallelMinMax(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<{
|
|
64
|
+
min: number;
|
|
65
|
+
max: number;
|
|
66
|
+
minIdx: number;
|
|
67
|
+
maxIdx: number;
|
|
68
|
+
}>>;
|
|
69
|
+
/**
|
|
70
|
+
* Parallel variance computation
|
|
71
|
+
*
|
|
72
|
+
* Uses Welford's algorithm for numerically stable variance calculation.
|
|
73
|
+
*
|
|
74
|
+
* @param data - Array to compute variance of
|
|
75
|
+
* @param options - Optional configuration
|
|
76
|
+
* @returns Object with mean, variance, and std (standard deviation)
|
|
77
|
+
*/
|
|
78
|
+
export declare function parallelVariance(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<{
|
|
79
|
+
mean: number;
|
|
80
|
+
variance: number;
|
|
81
|
+
std: number;
|
|
82
|
+
}>>;
|
|
83
|
+
/**
|
|
84
|
+
* Parallel standard deviation
|
|
85
|
+
*
|
|
86
|
+
* @param data - Array to compute std of
|
|
87
|
+
* @param options - Optional configuration
|
|
88
|
+
* @returns Standard deviation
|
|
89
|
+
*/
|
|
90
|
+
export declare function parallelStd(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
91
|
+
/**
|
|
92
|
+
* Parallel Euclidean norm (L2 norm)
|
|
93
|
+
*
|
|
94
|
+
* Computes √(Σx²) using parallel partial sums of squares.
|
|
95
|
+
*
|
|
96
|
+
* @param data - Vector to compute norm of
|
|
97
|
+
* @param options - Optional configuration
|
|
98
|
+
* @returns Euclidean norm
|
|
99
|
+
*/
|
|
100
|
+
export declare function parallelNorm(data: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
101
|
+
/**
|
|
102
|
+
* Parallel Euclidean distance
|
|
103
|
+
*
|
|
104
|
+
* Computes the Euclidean distance between two vectors.
|
|
105
|
+
*
|
|
106
|
+
* @param a - First vector
|
|
107
|
+
* @param b - Second vector
|
|
108
|
+
* @param options - Optional configuration
|
|
109
|
+
* @returns Euclidean distance
|
|
110
|
+
*/
|
|
111
|
+
export declare function parallelDistance(a: Float64Array, b: Float64Array, options?: ReduceOptions): Promise<ParallelResult<number>>;
|
|
112
|
+
/**
|
|
113
|
+
* Parallel histogram computation
|
|
114
|
+
*
|
|
115
|
+
* Bins data into histogram using parallel counting.
|
|
116
|
+
*
|
|
117
|
+
* @param data - Array to bin
|
|
118
|
+
* @param bins - Number of bins
|
|
119
|
+
* @param min - Minimum value (auto-detected if not provided)
|
|
120
|
+
* @param max - Maximum value (auto-detected if not provided)
|
|
121
|
+
* @param options - Optional configuration
|
|
122
|
+
* @returns Array of bin counts
|
|
123
|
+
*/
|
|
124
|
+
export declare function parallelHistogram(data: Float64Array, bins: number, min?: number, max?: number, options?: ReduceOptions): Promise<ParallelResult<number[]>>;
|
|
125
|
+
/**
|
|
126
|
+
* Generic parallel reduce operation
|
|
127
|
+
*
|
|
128
|
+
* Reduces an array using a custom function. Note that for truly
|
|
129
|
+
* associative operations, consider using specialized functions
|
|
130
|
+
* (parallelSum, parallelMin, etc.) for better performance.
|
|
131
|
+
*
|
|
132
|
+
* @param data - Array to reduce
|
|
133
|
+
* @param fn - Reduction function (acc, item) => newAcc
|
|
134
|
+
* @param initial - Initial accumulator value
|
|
135
|
+
* @param options - Optional configuration
|
|
136
|
+
* @returns Reduced value
|
|
137
|
+
*/
|
|
138
|
+
export declare function parallelReduce<T, R>(data: T[], fn: (acc: R, item: T) => R, initial: R, options?: ReduceOptions): Promise<ParallelResult<R>>;
|
|
139
|
+
//# sourceMappingURL=reduce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reduce.d.ts","sourceRoot":"","sources":["../../src/operations/reduce.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,0DAA0D;IAC1D,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,uDAAuD;IACvD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,yDAAyD;IACzD,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,YAAY,EAClB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAGjC;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,YAAY,EAClB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAGjC;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,C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,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,CAGnC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,CAAC,EACvC,IAAI,EAAE,CAAC,EAAE,EACT,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAC1B,OAAO,EAAE,CAAC,EACV,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAG5B"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel Bitwise Operations
|
|
3
|
+
*
|
|
4
|
+
* Element-wise bitwise operations on Int32Array buffers. Operations are
|
|
5
|
+
* applied in a chunked fashion so the work pattern mirrors the other
|
|
6
|
+
* parallel ops (`elementwise`, `scale`, etc.). The actual chunk kernel
|
|
7
|
+
* runs in-process: the MathWorkerPool kernel registry in
|
|
8
|
+
* `@danielsimonjr/mathts-workerpool` is keyed on `Float64Array` buffers,
|
|
9
|
+
* so cross-thread bitwise dispatch is intentionally out of scope here.
|
|
10
|
+
*
|
|
11
|
+
* The chunking still matters: it bounds peak-allocation pressure for
|
|
12
|
+
* very large arrays and keeps the call shape uniform with the rest of
|
|
13
|
+
* the parallel API, so the typed-function `Int32Array, Int32Array`
|
|
14
|
+
* signatures look identical to the `Float64Array, Float64Array` ones.
|
|
15
|
+
*
|
|
16
|
+
* Semantics follow JavaScript bitwise semantics on 32-bit signed
|
|
17
|
+
* integers (two's complement). For shift counts JavaScript itself
|
|
18
|
+
* masks to the low 5 bits — we preserve that behavior.
|
|
19
|
+
*
|
|
20
|
+
* @packageDocumentation
|
|
21
|
+
*/
|
|
22
|
+
import { type ChunkOptions } from '../strategies/chunk.js';
|
|
23
|
+
/**
|
|
24
|
+
* The set of supported binary bitwise op codes.
|
|
25
|
+
*
|
|
26
|
+
* - `bitAnd` : `a & b`
|
|
27
|
+
* - `bitOr` : `a | b`
|
|
28
|
+
* - `bitXor` : `a ^ b`
|
|
29
|
+
* - `leftShift` : `a << b`
|
|
30
|
+
* - `rightArithShift` : `a >> b` (sign-extending)
|
|
31
|
+
* - `rightLogShift` : `a >>> b` (zero-filling, returned as Int32 — values
|
|
32
|
+
* above 2^31 wrap into negative range, as in `(x >>> n) | 0`)
|
|
33
|
+
*/
|
|
34
|
+
export type BitwiseBinaryOp = 'bitAnd' | 'bitOr' | 'bitXor' | 'leftShift' | 'rightArithShift' | 'rightLogShift';
|
|
35
|
+
/**
|
|
36
|
+
* Bitwise AND on two equal-length `Int32Array`s.
|
|
37
|
+
*/
|
|
38
|
+
export declare function bitAnd(a: Int32Array, b: Int32Array, options?: ChunkOptions): Int32Array;
|
|
39
|
+
/**
|
|
40
|
+
* Bitwise OR on two equal-length `Int32Array`s.
|
|
41
|
+
*/
|
|
42
|
+
export declare function bitOr(a: Int32Array, b: Int32Array, options?: ChunkOptions): Int32Array;
|
|
43
|
+
/**
|
|
44
|
+
* Bitwise XOR on two equal-length `Int32Array`s.
|
|
45
|
+
*/
|
|
46
|
+
export declare function bitXor(a: Int32Array, b: Int32Array, options?: ChunkOptions): Int32Array;
|
|
47
|
+
/**
|
|
48
|
+
* Element-wise left shift: `a[i] << b[i]`.
|
|
49
|
+
*
|
|
50
|
+
* `b` may be either an `Int32Array` of per-element shift counts or a
|
|
51
|
+
* single scalar `number` (applied uniformly). Shift counts are masked
|
|
52
|
+
* to the low 5 bits by JavaScript itself — values ≥ 32 fold back into
|
|
53
|
+
* `[0, 31]`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function leftShift(a: Int32Array, b: Int32Array | number, options?: ChunkOptions): Int32Array;
|
|
56
|
+
/**
|
|
57
|
+
* Element-wise arithmetic (sign-preserving) right shift: `a[i] >> b[i]`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function rightArithShift(a: Int32Array, b: Int32Array | number, options?: ChunkOptions): Int32Array;
|
|
60
|
+
/**
|
|
61
|
+
* Element-wise logical (zero-filling) right shift: `a[i] >>> b[i]`.
|
|
62
|
+
*
|
|
63
|
+
* Result is stored as `Int32Array`, so values ≥ 2^31 wrap into the
|
|
64
|
+
* negative range — equivalent to `(x >>> n) | 0`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function rightLogShift(a: Int32Array, b: Int32Array | number, options?: ChunkOptions): Int32Array;
|
|
67
|
+
/**
|
|
68
|
+
* Unary bitwise NOT: `~a[i]`. Returns a fresh `Int32Array`.
|
|
69
|
+
*/
|
|
70
|
+
export declare function bitNot(a: Int32Array, options?: ChunkOptions): Int32Array;
|
|
71
|
+
//# sourceMappingURL=bitwise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitwise.d.ts","sourceRoot":"","sources":["../../src/ops/bitwise.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAA0B,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEnF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,WAAW,GACX,iBAAiB,GACjB,eAAe,CAAC;AAwEpB;;GAEG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,UAAU,CAEvF;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,UAAU,CAEtF;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,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