@cooljapan/scirs2 0.3.4

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.
@@ -0,0 +1,2490 @@
1
+ /**
2
+ * Performance timing utilities for benchmarking WASM operations
3
+ */
4
+ export class PerformanceTimer {
5
+ __destroy_into_raw() {
6
+ const ptr = this.__wbg_ptr;
7
+ this.__wbg_ptr = 0;
8
+ PerformanceTimerFinalization.unregister(this);
9
+ return ptr;
10
+ }
11
+ free() {
12
+ const ptr = this.__destroy_into_raw();
13
+ wasm.__wbg_performancetimer_free(ptr, 0);
14
+ }
15
+ /**
16
+ * Get elapsed time in milliseconds
17
+ * @returns {number}
18
+ */
19
+ elapsed() {
20
+ const ret = wasm.performancetimer_elapsed(this.__wbg_ptr);
21
+ if (ret[2]) {
22
+ throw takeFromExternrefTable0(ret[1]);
23
+ }
24
+ return ret[0];
25
+ }
26
+ /**
27
+ * Log the elapsed time to console
28
+ */
29
+ log_elapsed() {
30
+ const ret = wasm.performancetimer_log_elapsed(this.__wbg_ptr);
31
+ if (ret[1]) {
32
+ throw takeFromExternrefTable0(ret[0]);
33
+ }
34
+ }
35
+ /**
36
+ * Create a new performance timer with a label
37
+ * @param {string} label
38
+ */
39
+ constructor(label) {
40
+ const ptr0 = passStringToWasm0(label, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
41
+ const len0 = WASM_VECTOR_LEN;
42
+ const ret = wasm.performancetimer_new(ptr0, len0);
43
+ if (ret[2]) {
44
+ throw takeFromExternrefTable0(ret[1]);
45
+ }
46
+ this.__wbg_ptr = ret[0] >>> 0;
47
+ PerformanceTimerFinalization.register(this, this.__wbg_ptr, this);
48
+ return this;
49
+ }
50
+ }
51
+ if (Symbol.dispose) PerformanceTimer.prototype[Symbol.dispose] = PerformanceTimer.prototype.free;
52
+
53
+ /**
54
+ * A wrapper around ndarray for JavaScript interop
55
+ */
56
+ export class WasmArray {
57
+ static __wrap(ptr) {
58
+ ptr = ptr >>> 0;
59
+ const obj = Object.create(WasmArray.prototype);
60
+ obj.__wbg_ptr = ptr;
61
+ WasmArrayFinalization.register(obj, obj.__wbg_ptr, obj);
62
+ return obj;
63
+ }
64
+ __destroy_into_raw() {
65
+ const ptr = this.__wbg_ptr;
66
+ this.__wbg_ptr = 0;
67
+ WasmArrayFinalization.unregister(this);
68
+ return ptr;
69
+ }
70
+ free() {
71
+ const ptr = this.__destroy_into_raw();
72
+ wasm.__wbg_wasmarray_free(ptr, 0);
73
+ }
74
+ /**
75
+ * Create an array with evenly spaced values (like numpy.arange)
76
+ * @param {number} start
77
+ * @param {number} end
78
+ * @param {number} step
79
+ * @returns {WasmArray}
80
+ */
81
+ static arange(start, end, step) {
82
+ const ret = wasm.wasmarray_arange(start, end, step);
83
+ if (ret[2]) {
84
+ throw takeFromExternrefTable0(ret[1]);
85
+ }
86
+ return WasmArray.__wrap(ret[0]);
87
+ }
88
+ /**
89
+ * Clone the array
90
+ * @returns {WasmArray}
91
+ */
92
+ clone() {
93
+ const ret = wasm.wasmarray_clone(this.__wbg_ptr);
94
+ return WasmArray.__wrap(ret);
95
+ }
96
+ /**
97
+ * Create an array with a specific shape from flat data
98
+ * @param {any} shape
99
+ * @param {any} data
100
+ * @returns {WasmArray}
101
+ */
102
+ static from_shape(shape, data) {
103
+ const ret = wasm.wasmarray_from_shape(shape, data);
104
+ if (ret[2]) {
105
+ throw takeFromExternrefTable0(ret[1]);
106
+ }
107
+ return WasmArray.__wrap(ret[0]);
108
+ }
109
+ /**
110
+ * Create an array filled with a constant value
111
+ * @param {any} shape
112
+ * @param {number} value
113
+ * @returns {WasmArray}
114
+ */
115
+ static full(shape, value) {
116
+ const ret = wasm.wasmarray_full(shape, value);
117
+ if (ret[2]) {
118
+ throw takeFromExternrefTable0(ret[1]);
119
+ }
120
+ return WasmArray.__wrap(ret[0]);
121
+ }
122
+ /**
123
+ * Get a value at the specified index (flat indexing)
124
+ * @param {number} index
125
+ * @returns {number}
126
+ */
127
+ get(index) {
128
+ const ret = wasm.wasmarray_get(this.__wbg_ptr, index);
129
+ if (ret[2]) {
130
+ throw takeFromExternrefTable0(ret[1]);
131
+ }
132
+ return ret[0];
133
+ }
134
+ /**
135
+ * Check if the array is empty
136
+ * @returns {boolean}
137
+ */
138
+ is_empty() {
139
+ const ret = wasm.wasmarray_is_empty(this.__wbg_ptr);
140
+ return ret !== 0;
141
+ }
142
+ /**
143
+ * Get the total number of elements
144
+ * @returns {number}
145
+ */
146
+ len() {
147
+ const ret = wasm.wasmarray_len(this.__wbg_ptr);
148
+ return ret >>> 0;
149
+ }
150
+ /**
151
+ * Create an evenly spaced array (like numpy.linspace)
152
+ * @param {number} start
153
+ * @param {number} end
154
+ * @param {number} num
155
+ * @returns {WasmArray}
156
+ */
157
+ static linspace(start, end, num) {
158
+ const ret = wasm.wasmarray_linspace(start, end, num);
159
+ if (ret[2]) {
160
+ throw takeFromExternrefTable0(ret[1]);
161
+ }
162
+ return WasmArray.__wrap(ret[0]);
163
+ }
164
+ /**
165
+ * Get the number of dimensions
166
+ * @returns {number}
167
+ */
168
+ ndim() {
169
+ const ret = wasm.wasmarray_ndim(this.__wbg_ptr);
170
+ return ret >>> 0;
171
+ }
172
+ /**
173
+ * Create a 1D array from a JavaScript array or typed array
174
+ * @param {any} data
175
+ */
176
+ constructor(data) {
177
+ const ret = wasm.wasmarray_new(data);
178
+ if (ret[2]) {
179
+ throw takeFromExternrefTable0(ret[1]);
180
+ }
181
+ this.__wbg_ptr = ret[0] >>> 0;
182
+ WasmArrayFinalization.register(this, this.__wbg_ptr, this);
183
+ return this;
184
+ }
185
+ /**
186
+ * Create an array of ones with the given shape
187
+ * @param {any} shape
188
+ * @returns {WasmArray}
189
+ */
190
+ static ones(shape) {
191
+ const ret = wasm.wasmarray_ones(shape);
192
+ if (ret[2]) {
193
+ throw takeFromExternrefTable0(ret[1]);
194
+ }
195
+ return WasmArray.__wrap(ret[0]);
196
+ }
197
+ /**
198
+ * Reshape the array
199
+ * @param {any} new_shape
200
+ * @returns {WasmArray}
201
+ */
202
+ reshape(new_shape) {
203
+ const ret = wasm.wasmarray_reshape(this.__wbg_ptr, new_shape);
204
+ if (ret[2]) {
205
+ throw takeFromExternrefTable0(ret[1]);
206
+ }
207
+ return WasmArray.__wrap(ret[0]);
208
+ }
209
+ /**
210
+ * Set a value at the specified index (flat indexing)
211
+ * @param {number} index
212
+ * @param {number} value
213
+ */
214
+ set(index, value) {
215
+ const ret = wasm.wasmarray_set(this.__wbg_ptr, index, value);
216
+ if (ret[1]) {
217
+ throw takeFromExternrefTable0(ret[0]);
218
+ }
219
+ }
220
+ /**
221
+ * Get the shape of the array
222
+ * @returns {Array<any>}
223
+ */
224
+ shape() {
225
+ const ret = wasm.wasmarray_shape(this.__wbg_ptr);
226
+ return ret;
227
+ }
228
+ /**
229
+ * Convert to a flat JavaScript Float64Array
230
+ * @returns {Float64Array}
231
+ */
232
+ to_array() {
233
+ const ret = wasm.wasmarray_to_array(this.__wbg_ptr);
234
+ return ret;
235
+ }
236
+ /**
237
+ * Convert to a JavaScript array (nested for multi-dimensional arrays)
238
+ * @returns {any}
239
+ */
240
+ to_nested_array() {
241
+ const ret = wasm.wasmarray_to_nested_array(this.__wbg_ptr);
242
+ return ret;
243
+ }
244
+ /**
245
+ * Transpose the array (2D only for now)
246
+ * @returns {WasmArray}
247
+ */
248
+ transpose() {
249
+ const ret = wasm.wasmarray_transpose(this.__wbg_ptr);
250
+ if (ret[2]) {
251
+ throw takeFromExternrefTable0(ret[1]);
252
+ }
253
+ return WasmArray.__wrap(ret[0]);
254
+ }
255
+ /**
256
+ * Create an array of zeros with the given shape
257
+ * @param {any} shape
258
+ * @returns {WasmArray}
259
+ */
260
+ static zeros(shape) {
261
+ const ret = wasm.wasmarray_zeros(shape);
262
+ if (ret[2]) {
263
+ throw takeFromExternrefTable0(ret[1]);
264
+ }
265
+ return WasmArray.__wrap(ret[0]);
266
+ }
267
+ }
268
+ if (Symbol.dispose) WasmArray.prototype[Symbol.dispose] = WasmArray.prototype.free;
269
+
270
+ /**
271
+ * Add two arrays element-wise
272
+ * @param {WasmArray} a
273
+ * @param {WasmArray} b
274
+ * @returns {WasmArray}
275
+ */
276
+ export function add(a, b) {
277
+ _assertClass(a, WasmArray);
278
+ _assertClass(b, WasmArray);
279
+ const ret = wasm.add(a.__wbg_ptr, b.__wbg_ptr);
280
+ if (ret[2]) {
281
+ throw takeFromExternrefTable0(ret[1]);
282
+ }
283
+ return WasmArray.__wrap(ret[0]);
284
+ }
285
+
286
+ /**
287
+ * Perform Akima interpolation.
288
+ *
289
+ * Akima interpolation is a piecewise cubic method that is designed to be
290
+ * robust against outliers. Unlike standard cubic splines, Akima interpolation
291
+ * uses a local scheme for computing derivatives, making it less prone to
292
+ * oscillations near outliers or abrupt changes in the data.
293
+ *
294
+ * # Arguments
295
+ *
296
+ * * `x` - Known x-coordinates (must be sorted in strictly ascending order, at least 5 points)
297
+ * * `y` - Known y-coordinates (same length as x)
298
+ * * `x_new` - x-coordinates at which to evaluate the interpolation
299
+ *
300
+ * # Returns
301
+ *
302
+ * A `Vec<f64>` containing the interpolated values at each point in `x_new`.
303
+ *
304
+ * # Errors
305
+ *
306
+ * Returns an error if:
307
+ * - Input arrays are empty or have mismatched lengths
308
+ * - Fewer than 5 data points are provided (Akima requires at least 5)
309
+ * - x values are not sorted in strictly ascending order
310
+ * - Evaluation points are outside the data range
311
+ * @param {Float64Array} x
312
+ * @param {Float64Array} y
313
+ * @param {Float64Array} x_new
314
+ * @returns {Float64Array}
315
+ */
316
+ export function akima(x, y, x_new) {
317
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_malloc);
318
+ const len0 = WASM_VECTOR_LEN;
319
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_malloc);
320
+ const len1 = WASM_VECTOR_LEN;
321
+ const ptr2 = passArrayF64ToWasm0(x_new, wasm.__wbindgen_malloc);
322
+ const len2 = WASM_VECTOR_LEN;
323
+ const ret = wasm.akima(ptr0, len0, ptr1, len1, ptr2, len2);
324
+ if (ret[3]) {
325
+ throw takeFromExternrefTable0(ret[2]);
326
+ }
327
+ var v4 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
328
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
329
+ return v4;
330
+ }
331
+
332
+ /**
333
+ * Find a root of a function using the bisection method.
334
+ *
335
+ * Given an interval [a, b] where the function changes sign, repeatedly halves
336
+ * the interval to converge on the root.
337
+ *
338
+ * # Arguments
339
+ * * `a` - Lower bracket endpoint
340
+ * * `b` - Upper bracket endpoint
341
+ * * `fa` - Function value at a: f(a)
342
+ * * `fb` - Function value at b: f(b)
343
+ * * `tol` - Convergence tolerance on the interval width
344
+ * * `max_iter` - Maximum number of iterations
345
+ *
346
+ * # Returns
347
+ * Estimated root location as f64
348
+ * @param {number} a
349
+ * @param {number} b
350
+ * @param {number} fa
351
+ * @param {number} fb
352
+ * @param {number} tol
353
+ * @param {number} max_iter
354
+ * @returns {number}
355
+ */
356
+ export function bisect_root(a, b, fa, fb, tol, max_iter) {
357
+ const ret = wasm.bisect_root(a, b, fa, fb, tol, max_iter);
358
+ if (ret[2]) {
359
+ throw takeFromExternrefTable0(ret[1]);
360
+ }
361
+ return ret[0];
362
+ }
363
+
364
+ /**
365
+ * Iterative bisection step: given bracket [a, b] with opposite-sign function values,
366
+ * and the function value at the midpoint, returns the narrowed bracket.
367
+ *
368
+ * # Arguments
369
+ * * `a` - Lower bracket
370
+ * * `b` - Upper bracket
371
+ * * `fa` - f(a)
372
+ * * `fb` - f(b)
373
+ * * `f_mid` - f((a+b)/2)
374
+ *
375
+ * # Returns
376
+ * JsValue with:
377
+ * - `a`, `b`: new bracket bounds
378
+ * - `fa`, `fb`: function values at new bounds
379
+ * - `mid`: current midpoint
380
+ * - `converged`: whether |b - a| < given tol (caller can check)
381
+ * @param {number} a
382
+ * @param {number} b
383
+ * @param {number} fa
384
+ * @param {number} fb
385
+ * @param {number} f_mid
386
+ * @returns {any}
387
+ */
388
+ export function bisection_step(a, b, fa, fb, f_mid) {
389
+ const ret = wasm.bisection_step(a, b, fa, fb, f_mid);
390
+ if (ret[2]) {
391
+ throw takeFromExternrefTable0(ret[1]);
392
+ }
393
+ return takeFromExternrefTable0(ret[0]);
394
+ }
395
+
396
+ /**
397
+ * Generate a Blackman window of length `n`.
398
+ *
399
+ * The Blackman window is a three-term cosine series window providing
400
+ * excellent sidelobe suppression at the cost of wider main lobe.
401
+ *
402
+ * # Arguments
403
+ *
404
+ * * `n` - Number of points in the window
405
+ *
406
+ * # Returns
407
+ *
408
+ * A `Vec<f64>` containing the window coefficients.
409
+ * @param {number} n
410
+ * @returns {Float64Array}
411
+ */
412
+ export function blackman(n) {
413
+ const ret = wasm.blackman(n);
414
+ if (ret[3]) {
415
+ throw takeFromExternrefTable0(ret[2]);
416
+ }
417
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
418
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
419
+ return v1;
420
+ }
421
+
422
+ /**
423
+ * Find a root of a function using Brent's method.
424
+ *
425
+ * Given an interval [a, b] where the function changes sign, finds x such that f(x) ~ 0.
426
+ * The caller provides the function values at the endpoints.
427
+ *
428
+ * # Arguments
429
+ * * `a` - Lower bracket endpoint
430
+ * * `b` - Upper bracket endpoint
431
+ * * `fa` - Function value at a: f(a)
432
+ * * `fb` - Function value at b: f(b)
433
+ * * `tol` - Convergence tolerance on the root position
434
+ * * `max_iter` - Maximum number of iterations
435
+ *
436
+ * # Returns
437
+ * Estimated root location as f64
438
+ * @param {number} a
439
+ * @param {number} b
440
+ * @param {number} fa
441
+ * @param {number} fb
442
+ * @param {number} tol
443
+ * @param {number} max_iter
444
+ * @returns {number}
445
+ */
446
+ export function brent_root(a, b, fa, fb, tol, max_iter) {
447
+ const ret = wasm.brent_root(a, b, fa, fb, tol, max_iter);
448
+ if (ret[2]) {
449
+ throw takeFromExternrefTable0(ret[1]);
450
+ }
451
+ return ret[0];
452
+ }
453
+
454
+ /**
455
+ * Design a Butterworth digital filter.
456
+ *
457
+ * Returns a JSON object with `b` (numerator) and `a` (denominator) coefficients.
458
+ *
459
+ * # Arguments
460
+ *
461
+ * * `order` - Filter order (positive integer)
462
+ * * `cutoff` - Cutoff frequency, normalized 0..1 where 1 is Nyquist
463
+ * * `btype` - Filter type: "lowpass", "highpass", "bandpass", or "bandstop"
464
+ * * `fs` - Sampling frequency in Hz (cutoff will be normalized by fs/2)
465
+ *
466
+ * # Returns
467
+ *
468
+ * A JsValue containing a JSON object `{ b: number[], a: number[] }`.
469
+ * @param {number} order
470
+ * @param {number} cutoff
471
+ * @param {string} btype
472
+ * @param {number} fs
473
+ * @returns {any}
474
+ */
475
+ export function butter(order, cutoff, btype, fs) {
476
+ const ptr0 = passStringToWasm0(btype, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
477
+ const len0 = WASM_VECTOR_LEN;
478
+ const ret = wasm.butter(order, cutoff, ptr0, len0, fs);
479
+ if (ret[2]) {
480
+ throw takeFromExternrefTable0(ret[1]);
481
+ }
482
+ return takeFromExternrefTable0(ret[0]);
483
+ }
484
+
485
+ /**
486
+ * Get system capabilities and features available in this build
487
+ * @returns {any}
488
+ */
489
+ export function capabilities() {
490
+ const ret = wasm.capabilities();
491
+ return ret;
492
+ }
493
+
494
+ /**
495
+ * Perform 1D convolution of two arrays.
496
+ *
497
+ * # Arguments
498
+ *
499
+ * * `a` - First input array
500
+ * * `b` - Second input array
501
+ * * `mode` - Output mode: "full", "same", or "valid"
502
+ *
503
+ * # Returns
504
+ *
505
+ * A `Vec<f64>` containing the convolution result.
506
+ * @param {Float64Array} a
507
+ * @param {Float64Array} b
508
+ * @param {string} mode
509
+ * @returns {Float64Array}
510
+ */
511
+ export function convolve(a, b, mode) {
512
+ const ptr0 = passArrayF64ToWasm0(a, wasm.__wbindgen_malloc);
513
+ const len0 = WASM_VECTOR_LEN;
514
+ const ptr1 = passArrayF64ToWasm0(b, wasm.__wbindgen_malloc);
515
+ const len1 = WASM_VECTOR_LEN;
516
+ const ptr2 = passStringToWasm0(mode, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
517
+ const len2 = WASM_VECTOR_LEN;
518
+ const ret = wasm.convolve(ptr0, len0, ptr1, len1, ptr2, len2);
519
+ if (ret[3]) {
520
+ throw takeFromExternrefTable0(ret[2]);
521
+ }
522
+ var v4 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
523
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
524
+ return v4;
525
+ }
526
+
527
+ /**
528
+ * Compute correlation coefficient between two arrays
529
+ * @param {WasmArray} x
530
+ * @param {WasmArray} y
531
+ * @returns {number}
532
+ */
533
+ export function corrcoef(x, y) {
534
+ _assertClass(x, WasmArray);
535
+ _assertClass(y, WasmArray);
536
+ const ret = wasm.corrcoef(x.__wbg_ptr, y.__wbg_ptr);
537
+ if (ret[2]) {
538
+ throw takeFromExternrefTable0(ret[1]);
539
+ }
540
+ return ret[0];
541
+ }
542
+
543
+ /**
544
+ * Perform 1D cross-correlation of two arrays.
545
+ *
546
+ * Cross-correlation is equivalent to convolution with the second array reversed.
547
+ *
548
+ * # Arguments
549
+ *
550
+ * * `a` - First input array
551
+ * * `b` - Second input array
552
+ * * `mode` - Output mode: "full", "same", or "valid"
553
+ *
554
+ * # Returns
555
+ *
556
+ * A `Vec<f64>` containing the correlation result.
557
+ * @param {Float64Array} a
558
+ * @param {Float64Array} b
559
+ * @param {string} mode
560
+ * @returns {Float64Array}
561
+ */
562
+ export function correlate(a, b, mode) {
563
+ const ptr0 = passArrayF64ToWasm0(a, wasm.__wbindgen_malloc);
564
+ const len0 = WASM_VECTOR_LEN;
565
+ const ptr1 = passArrayF64ToWasm0(b, wasm.__wbindgen_malloc);
566
+ const len1 = WASM_VECTOR_LEN;
567
+ const ptr2 = passStringToWasm0(mode, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
568
+ const len2 = WASM_VECTOR_LEN;
569
+ const ret = wasm.correlate(ptr0, len0, ptr1, len1, ptr2, len2);
570
+ if (ret[3]) {
571
+ throw takeFromExternrefTable0(ret[2]);
572
+ }
573
+ var v4 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
574
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
575
+ return v4;
576
+ }
577
+
578
+ /**
579
+ * Perform natural cubic spline interpolation.
580
+ *
581
+ * Constructs a natural cubic spline (zero second derivative at boundaries)
582
+ * through the given data points and evaluates it at the specified x coordinates.
583
+ * Provides C2 continuity (continuous second derivatives).
584
+ *
585
+ * # Arguments
586
+ *
587
+ * * `x` - Known x-coordinates (must be sorted in ascending order, at least 3 points)
588
+ * * `y` - Known y-coordinates (same length as x)
589
+ * * `x_new` - x-coordinates at which to evaluate the spline
590
+ *
591
+ * # Returns
592
+ *
593
+ * A `Vec<f64>` containing the interpolated values at each point in `x_new`.
594
+ *
595
+ * # Errors
596
+ *
597
+ * Returns an error if:
598
+ * - Input arrays are empty or have mismatched lengths
599
+ * - Fewer than 3 data points are provided
600
+ * - x values are not sorted in ascending order
601
+ * - Evaluation points are outside the data range
602
+ * @param {Float64Array} x
603
+ * @param {Float64Array} y
604
+ * @param {Float64Array} x_new
605
+ * @returns {Float64Array}
606
+ */
607
+ export function cubic_spline(x, y, x_new) {
608
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_malloc);
609
+ const len0 = WASM_VECTOR_LEN;
610
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_malloc);
611
+ const len1 = WASM_VECTOR_LEN;
612
+ const ptr2 = passArrayF64ToWasm0(x_new, wasm.__wbindgen_malloc);
613
+ const len2 = WASM_VECTOR_LEN;
614
+ const ret = wasm.cubic_spline(ptr0, len0, ptr1, len1, ptr2, len2);
615
+ if (ret[3]) {
616
+ throw takeFromExternrefTable0(ret[2]);
617
+ }
618
+ var v4 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
619
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
620
+ return v4;
621
+ }
622
+
623
+ /**
624
+ * Compute cumulative product of an array
625
+ * @param {WasmArray} arr
626
+ * @returns {WasmArray}
627
+ */
628
+ export function cumprod(arr) {
629
+ _assertClass(arr, WasmArray);
630
+ const ret = wasm.cumprod(arr.__wbg_ptr);
631
+ return WasmArray.__wrap(ret);
632
+ }
633
+
634
+ /**
635
+ * Compute cumulative sum of an array
636
+ * @param {WasmArray} arr
637
+ * @returns {WasmArray}
638
+ */
639
+ export function cumsum(arr) {
640
+ _assertClass(arr, WasmArray);
641
+ const ret = wasm.cumsum(arr.__wbg_ptr);
642
+ return WasmArray.__wrap(ret);
643
+ }
644
+
645
+ /**
646
+ * Compute the cumulative integral of `y` over `x` using the trapezoidal
647
+ * rule.
648
+ *
649
+ * Returns a `Float64Array` of length `n - 1` where `n = y.len()`, with
650
+ * each element being the integral from `x[0]` to `x[i+1]`.
651
+ *
652
+ * # Errors
653
+ * Returns a `JsValue` error on mismatched lengths or fewer than 2 points.
654
+ * @param {any} y_js
655
+ * @param {any} x_js
656
+ * @returns {Float64Array}
657
+ */
658
+ export function cumulative_trapezoid(y_js, x_js) {
659
+ const ret = wasm.cumulative_trapezoid(y_js, x_js);
660
+ if (ret[2]) {
661
+ throw takeFromExternrefTable0(ret[1]);
662
+ }
663
+ return takeFromExternrefTable0(ret[0]);
664
+ }
665
+
666
+ /**
667
+ * Compute the determinant of a square matrix
668
+ * @param {WasmArray} arr
669
+ * @returns {number}
670
+ */
671
+ export function det(arr) {
672
+ _assertClass(arr, WasmArray);
673
+ const ret = wasm.det(arr.__wbg_ptr);
674
+ if (ret[2]) {
675
+ throw takeFromExternrefTable0(ret[1]);
676
+ }
677
+ return ret[0];
678
+ }
679
+
680
+ /**
681
+ * Divide two arrays element-wise
682
+ * @param {WasmArray} a
683
+ * @param {WasmArray} b
684
+ * @returns {WasmArray}
685
+ */
686
+ export function divide(a, b) {
687
+ _assertClass(a, WasmArray);
688
+ _assertClass(b, WasmArray);
689
+ const ret = wasm.divide(a.__wbg_ptr, b.__wbg_ptr);
690
+ if (ret[2]) {
691
+ throw takeFromExternrefTable0(ret[1]);
692
+ }
693
+ return WasmArray.__wrap(ret[0]);
694
+ }
695
+
696
+ /**
697
+ * Compute dot product (1D) or matrix multiplication (2D)
698
+ * @param {WasmArray} a
699
+ * @param {WasmArray} b
700
+ * @returns {WasmArray}
701
+ */
702
+ export function dot(a, b) {
703
+ _assertClass(a, WasmArray);
704
+ _assertClass(b, WasmArray);
705
+ const ret = wasm.dot(a.__wbg_ptr, b.__wbg_ptr);
706
+ if (ret[2]) {
707
+ throw takeFromExternrefTable0(ret[1]);
708
+ }
709
+ return WasmArray.__wrap(ret[0]);
710
+ }
711
+
712
+ /**
713
+ * Compute the forward Fast Fourier Transform (FFT) of complex input data.
714
+ *
715
+ * # Arguments
716
+ *
717
+ * * `data` - Interleaved real/imaginary pairs: `[re_0, im_0, re_1, im_1, ...]`
718
+ *
719
+ * # Returns
720
+ *
721
+ * Interleaved real/imaginary pairs of the FFT result.
722
+ * The output length equals the input length (same number of interleaved pairs).
723
+ *
724
+ * # Errors
725
+ *
726
+ * Returns a `JsValue` error if:
727
+ * - The input length is not even (not valid interleaved complex data)
728
+ * - The input is empty
729
+ * - The FFT computation fails
730
+ *
731
+ * # Example (JavaScript)
732
+ *
733
+ * ```javascript
734
+ * // Signal: [1+0i, 2+0i, 3+0i, 4+0i] as interleaved
735
+ * const input = new Float64Array([1, 0, 2, 0, 3, 0, 4, 0]);
736
+ * const result = fft(input);
737
+ * // result contains interleaved [re, im, re, im, ...]
738
+ * ```
739
+ * @param {Float64Array} data
740
+ * @returns {Float64Array}
741
+ */
742
+ export function fft(data) {
743
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
744
+ const len0 = WASM_VECTOR_LEN;
745
+ const ret = wasm.fft(ptr0, len0);
746
+ if (ret[3]) {
747
+ throw takeFromExternrefTable0(ret[2]);
748
+ }
749
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
750
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
751
+ return v2;
752
+ }
753
+
754
+ /**
755
+ * Compute the magnitude (absolute value) of complex interleaved data.
756
+ *
757
+ * For each complex value `(re, im)`, computes `sqrt(re^2 + im^2)`.
758
+ *
759
+ * # Arguments
760
+ *
761
+ * * `data` - Interleaved real/imaginary pairs: `[re_0, im_0, re_1, im_1, ...]`
762
+ *
763
+ * # Returns
764
+ *
765
+ * A vector of magnitudes, one per complex value. Length is `data.len() / 2`.
766
+ *
767
+ * # Errors
768
+ *
769
+ * Returns a `JsValue` error if the input length is not even.
770
+ *
771
+ * # Example (JavaScript)
772
+ *
773
+ * ```javascript
774
+ * // Complex values: [3+4i, 0+1i] => magnitudes: [5.0, 1.0]
775
+ * const data = new Float64Array([3, 4, 0, 1]);
776
+ * const mags = fft_magnitude(data);
777
+ * ```
778
+ * @param {Float64Array} data
779
+ * @returns {Float64Array}
780
+ */
781
+ export function fft_magnitude(data) {
782
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
783
+ const len0 = WASM_VECTOR_LEN;
784
+ const ret = wasm.fft_magnitude(ptr0, len0);
785
+ if (ret[3]) {
786
+ throw takeFromExternrefTable0(ret[2]);
787
+ }
788
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
789
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
790
+ return v2;
791
+ }
792
+
793
+ /**
794
+ * Compute the phase angle of complex interleaved data (in radians).
795
+ *
796
+ * For each complex value `(re, im)`, computes `atan2(im, re)`.
797
+ *
798
+ * # Arguments
799
+ *
800
+ * * `data` - Interleaved real/imaginary pairs: `[re_0, im_0, re_1, im_1, ...]`
801
+ *
802
+ * # Returns
803
+ *
804
+ * A vector of phase angles in radians `[-pi, pi]`, one per complex value.
805
+ * Length is `data.len() / 2`.
806
+ *
807
+ * # Errors
808
+ *
809
+ * Returns a `JsValue` error if the input length is not even.
810
+ *
811
+ * # Example (JavaScript)
812
+ *
813
+ * ```javascript
814
+ * // Complex value: [1+1i] => phase: pi/4 (~0.785)
815
+ * const data = new Float64Array([1, 1]);
816
+ * const phases = fft_phase(data);
817
+ * ```
818
+ * @param {Float64Array} data
819
+ * @returns {Float64Array}
820
+ */
821
+ export function fft_phase(data) {
822
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
823
+ const len0 = WASM_VECTOR_LEN;
824
+ const ret = wasm.fft_phase(ptr0, len0);
825
+ if (ret[3]) {
826
+ throw takeFromExternrefTable0(ret[2]);
827
+ }
828
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
829
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
830
+ return v2;
831
+ }
832
+
833
+ /**
834
+ * Compute the FFT sample frequencies.
835
+ *
836
+ * Returns the frequency bin centers in cycles per unit of the sample spacing,
837
+ * following the same convention as NumPy/SciPy.
838
+ *
839
+ * # Arguments
840
+ *
841
+ * * `n` - Number of samples in the signal (window length).
842
+ * * `d` - Sample spacing (inverse of the sampling rate). Must be positive.
843
+ *
844
+ * # Returns
845
+ *
846
+ * A vector of length `n` containing the sample frequencies.
847
+ * For even `n`: `[0, 1, ..., n/2-1, -n/2, ..., -1] / (d*n)`
848
+ * For odd `n`: `[0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (d*n)`
849
+ *
850
+ * # Errors
851
+ *
852
+ * Returns a `JsValue` error if:
853
+ * - `n` is 0
854
+ * - `d` is not positive
855
+ * - The computation fails
856
+ *
857
+ * # Example (JavaScript)
858
+ *
859
+ * ```javascript
860
+ * const freqs = fftfreq(8, 0.1);
861
+ * // freqs = [0.0, 1.25, 2.5, 3.75, -5.0, -3.75, -2.5, -1.25]
862
+ * ```
863
+ * @param {number} n
864
+ * @param {number} d
865
+ * @returns {Float64Array}
866
+ */
867
+ export function fftfreq(n, d) {
868
+ const ret = wasm.fftfreq(n, d);
869
+ if (ret[3]) {
870
+ throw takeFromExternrefTable0(ret[2]);
871
+ }
872
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
873
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
874
+ return v1;
875
+ }
876
+
877
+ /**
878
+ * Shift the zero-frequency component to the center of the spectrum.
879
+ *
880
+ * Rearranges the FFT output so that the zero-frequency component is at
881
+ * the center, with negative frequencies on the left and positive on the right.
882
+ *
883
+ * # Arguments
884
+ *
885
+ * * `data` - FFT output as a flat f64 array (real-valued, e.g. from `power_spectrum`
886
+ * or magnitude array).
887
+ *
888
+ * # Returns
889
+ *
890
+ * The shifted array with zero-frequency at the center.
891
+ *
892
+ * # Errors
893
+ *
894
+ * Returns a `JsValue` error if the input is empty.
895
+ *
896
+ * # Example (JavaScript)
897
+ *
898
+ * ```javascript
899
+ * const data = new Float64Array([0, 1, 2, 3, 4, -4, -3, -2, -1]);
900
+ * const shifted = fftshift(data);
901
+ * // shifted = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
902
+ * ```
903
+ * @param {Float64Array} data
904
+ * @returns {Float64Array}
905
+ */
906
+ export function fftshift(data) {
907
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
908
+ const len0 = WASM_VECTOR_LEN;
909
+ const ret = wasm.fftshift(ptr0, len0);
910
+ if (ret[3]) {
911
+ throw takeFromExternrefTable0(ret[2]);
912
+ }
913
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
914
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
915
+ return v2;
916
+ }
917
+
918
+ /**
919
+ * Design an FIR (Finite Impulse Response) lowpass filter using the window method.
920
+ *
921
+ * Designs a linear-phase FIR lowpass filter with the specified number of taps
922
+ * and cutoff frequency, using a Hamming window.
923
+ *
924
+ * # Arguments
925
+ *
926
+ * * `n` - Number of filter taps (must be >= 3)
927
+ * * `cutoff` - Cutoff frequency in Hz
928
+ * * `fs` - Sampling frequency in Hz
929
+ *
930
+ * # Returns
931
+ *
932
+ * A `Vec<f64>` containing the FIR filter coefficients.
933
+ * @param {number} n
934
+ * @param {number} cutoff
935
+ * @param {number} fs
936
+ * @returns {Float64Array}
937
+ */
938
+ export function firwin(n, cutoff, fs) {
939
+ const ret = wasm.firwin(n, cutoff, fs);
940
+ if (ret[3]) {
941
+ throw takeFromExternrefTable0(ret[2]);
942
+ }
943
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
944
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
945
+ return v1;
946
+ }
947
+
948
+ /**
949
+ * Step-wise golden section search: given bracket [a, b] and two interior
950
+ * function evaluations, returns the narrowed bracket and next evaluation points.
951
+ *
952
+ * # Arguments
953
+ * * `a` - Current lower bound
954
+ * * `b` - Current upper bound
955
+ * * `f_x1` - Function value at interior point x1
956
+ * * `f_x2` - Function value at interior point x2
957
+ * * `tol` - Convergence tolerance
958
+ *
959
+ * # Returns
960
+ * JsValue with:
961
+ * - `a`, `b`: new bracket bounds
962
+ * - `x1`, `x2`: new interior evaluation points
963
+ * - `converged`: whether |b - a| < tol
964
+ * - `x_min`: current best estimate of the minimizer
965
+ * @param {number} a
966
+ * @param {number} b
967
+ * @param {number} f_x1
968
+ * @param {number} f_x2
969
+ * @param {number} tol
970
+ * @returns {any}
971
+ */
972
+ export function golden_section_step(a, b, f_x1, f_x2, tol) {
973
+ const ret = wasm.golden_section_step(a, b, f_x1, f_x2, tol);
974
+ if (ret[2]) {
975
+ throw takeFromExternrefTable0(ret[1]);
976
+ }
977
+ return takeFromExternrefTable0(ret[0]);
978
+ }
979
+
980
+ /**
981
+ * Generate a Hamming window of length `n`.
982
+ *
983
+ * The Hamming window is a raised cosine window with non-zero endpoints,
984
+ * providing better sidelobe suppression than the Hann window.
985
+ *
986
+ * # Arguments
987
+ *
988
+ * * `n` - Number of points in the window
989
+ *
990
+ * # Returns
991
+ *
992
+ * A `Vec<f64>` containing the window coefficients.
993
+ * @param {number} n
994
+ * @returns {Float64Array}
995
+ */
996
+ export function hamming(n) {
997
+ const ret = wasm.hamming(n);
998
+ if (ret[3]) {
999
+ throw takeFromExternrefTable0(ret[2]);
1000
+ }
1001
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1002
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1003
+ return v1;
1004
+ }
1005
+
1006
+ /**
1007
+ * Generate a Hanning (Hann) window of length `n`.
1008
+ *
1009
+ * The Hann window is a raised cosine window with zero values at both endpoints,
1010
+ * providing good frequency resolution and moderate sidelobe suppression.
1011
+ *
1012
+ * # Arguments
1013
+ *
1014
+ * * `n` - Number of points in the window
1015
+ *
1016
+ * # Returns
1017
+ *
1018
+ * A `Vec<f64>` containing the window coefficients.
1019
+ * @param {number} n
1020
+ * @returns {Float64Array}
1021
+ */
1022
+ export function hanning(n) {
1023
+ const ret = wasm.hanning(n);
1024
+ if (ret[3]) {
1025
+ throw takeFromExternrefTable0(ret[2]);
1026
+ }
1027
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1028
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1029
+ return v1;
1030
+ }
1031
+
1032
+ /**
1033
+ * Check if WASM SIMD is supported in the current environment
1034
+ * @returns {boolean}
1035
+ */
1036
+ export function has_simd_support() {
1037
+ const ret = wasm.has_simd_support();
1038
+ return ret !== 0;
1039
+ }
1040
+
1041
+ /**
1042
+ * Compute the inverse Fast Fourier Transform (IFFT) of complex input data.
1043
+ *
1044
+ * # Arguments
1045
+ *
1046
+ * * `data` - Interleaved real/imaginary pairs: `[re_0, im_0, re_1, im_1, ...]`
1047
+ *
1048
+ * # Returns
1049
+ *
1050
+ * Interleaved real/imaginary pairs of the IFFT result.
1051
+ * The output length equals the input length (same number of interleaved pairs).
1052
+ *
1053
+ * # Errors
1054
+ *
1055
+ * Returns a `JsValue` error if:
1056
+ * - The input length is not even
1057
+ * - The input is empty
1058
+ * - The IFFT computation fails
1059
+ *
1060
+ * # Example (JavaScript)
1061
+ *
1062
+ * ```javascript
1063
+ * const spectrum = new Float64Array([10, 0, -2, 2, -2, 0, -2, -2]);
1064
+ * const signal = ifft(spectrum);
1065
+ * ```
1066
+ * @param {Float64Array} data
1067
+ * @returns {Float64Array}
1068
+ */
1069
+ export function ifft(data) {
1070
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
1071
+ const len0 = WASM_VECTOR_LEN;
1072
+ const ret = wasm.ifft(ptr0, len0);
1073
+ if (ret[3]) {
1074
+ throw takeFromExternrefTable0(ret[2]);
1075
+ }
1076
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1077
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1078
+ return v2;
1079
+ }
1080
+
1081
+ /**
1082
+ * Inverse of `fftshift`: shift zero-frequency component back to the beginning.
1083
+ *
1084
+ * This undoes the effect of `fftshift`.
1085
+ *
1086
+ * # Arguments
1087
+ *
1088
+ * * `data` - Shifted spectrum (with zero-frequency at center).
1089
+ *
1090
+ * # Returns
1091
+ *
1092
+ * The unshifted array with zero-frequency at the beginning.
1093
+ *
1094
+ * # Errors
1095
+ *
1096
+ * Returns a `JsValue` error if the input is empty.
1097
+ *
1098
+ * # Example (JavaScript)
1099
+ *
1100
+ * ```javascript
1101
+ * const shifted = new Float64Array([-4, -3, -2, -1, 0, 1, 2, 3, 4]);
1102
+ * const unshifted = ifftshift(shifted);
1103
+ * // unshifted = [0, 1, 2, 3, 4, -4, -3, -2, -1]
1104
+ * ```
1105
+ * @param {Float64Array} data
1106
+ * @returns {Float64Array}
1107
+ */
1108
+ export function ifftshift(data) {
1109
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
1110
+ const len0 = WASM_VECTOR_LEN;
1111
+ const ret = wasm.ifftshift(ptr0, len0);
1112
+ if (ret[3]) {
1113
+ throw takeFromExternrefTable0(ret[2]);
1114
+ }
1115
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1116
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1117
+ return v2;
1118
+ }
1119
+
1120
+ /**
1121
+ * Initialize the WASM module with panic hooks and logging
1122
+ */
1123
+ export function init() {
1124
+ wasm.init();
1125
+ }
1126
+
1127
+ /**
1128
+ * Perform 1D interpolation with a specified method.
1129
+ *
1130
+ * Interpolates between the given (x, y) data points and evaluates the
1131
+ * interpolation at the new x coordinates.
1132
+ *
1133
+ * # Arguments
1134
+ *
1135
+ * * `x` - Known x-coordinates (must be sorted in ascending order)
1136
+ * * `y` - Known y-coordinates (same length as x)
1137
+ * * `x_new` - x-coordinates at which to evaluate the interpolation
1138
+ * * `kind` - Interpolation method: "linear", "nearest", or "quadratic" (uses cubic/Catmull-Rom)
1139
+ *
1140
+ * # Returns
1141
+ *
1142
+ * A `Vec<f64>` containing the interpolated values at each point in `x_new`.
1143
+ *
1144
+ * # Errors
1145
+ *
1146
+ * Returns an error if:
1147
+ * - Input arrays are empty or have mismatched lengths
1148
+ * - x values are not sorted in ascending order
1149
+ * - An unknown interpolation kind is specified
1150
+ * - Insufficient points for the requested method
1151
+ * @param {Float64Array} x
1152
+ * @param {Float64Array} y
1153
+ * @param {Float64Array} x_new
1154
+ * @param {string} kind
1155
+ * @returns {Float64Array}
1156
+ */
1157
+ export function interp1d(x, y, x_new, kind) {
1158
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_malloc);
1159
+ const len0 = WASM_VECTOR_LEN;
1160
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_malloc);
1161
+ const len1 = WASM_VECTOR_LEN;
1162
+ const ptr2 = passArrayF64ToWasm0(x_new, wasm.__wbindgen_malloc);
1163
+ const len2 = WASM_VECTOR_LEN;
1164
+ const ptr3 = passStringToWasm0(kind, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1165
+ const len3 = WASM_VECTOR_LEN;
1166
+ const ret = wasm.interp1d(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
1167
+ if (ret[3]) {
1168
+ throw takeFromExternrefTable0(ret[2]);
1169
+ }
1170
+ var v5 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1171
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1172
+ return v5;
1173
+ }
1174
+
1175
+ /**
1176
+ * Compute matrix inverse
1177
+ * @param {WasmArray} arr
1178
+ * @returns {WasmArray}
1179
+ */
1180
+ export function inv(arr) {
1181
+ _assertClass(arr, WasmArray);
1182
+ const ret = wasm.inv(arr.__wbg_ptr);
1183
+ if (ret[2]) {
1184
+ throw takeFromExternrefTable0(ret[1]);
1185
+ }
1186
+ return WasmArray.__wrap(ret[0]);
1187
+ }
1188
+
1189
+ /**
1190
+ * Compute the inverse FFT for real-valued output (IRFFT).
1191
+ *
1192
+ * This is the inverse of `rfft`. It takes the positive-frequency half-spectrum
1193
+ * and reconstructs the original real-valued signal.
1194
+ *
1195
+ * # Arguments
1196
+ *
1197
+ * * `data` - Interleaved real/imaginary pairs of the half-spectrum:
1198
+ * `[re_0, im_0, re_1, im_1, ...]`. The length must be even.
1199
+ * * `n` - Length of the output real signal. If 0, it is computed as
1200
+ * `2 * (num_complex - 1)` where `num_complex` is the number of complex values.
1201
+ *
1202
+ * # Returns
1203
+ *
1204
+ * Real-valued output signal as `f64` array.
1205
+ *
1206
+ * # Errors
1207
+ *
1208
+ * Returns a `JsValue` error if:
1209
+ * - The input length is not even
1210
+ * - The input is empty
1211
+ * - The IRFFT computation fails
1212
+ *
1213
+ * # Example (JavaScript)
1214
+ *
1215
+ * ```javascript
1216
+ * const spectrum = rfft(new Float64Array([1, 2, 3, 4]));
1217
+ * const signal = irfft(spectrum, 4); // Recover original 4-element signal
1218
+ * ```
1219
+ * @param {Float64Array} data
1220
+ * @param {number} n
1221
+ * @returns {Float64Array}
1222
+ */
1223
+ export function irfft(data, n) {
1224
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
1225
+ const len0 = WASM_VECTOR_LEN;
1226
+ const ret = wasm.irfft(ptr0, len0, n);
1227
+ if (ret[3]) {
1228
+ throw takeFromExternrefTable0(ret[2]);
1229
+ }
1230
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1231
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1232
+ return v2;
1233
+ }
1234
+
1235
+ /**
1236
+ * Perform Lagrange polynomial interpolation.
1237
+ *
1238
+ * Uses barycentric Lagrange interpolation, which is numerically more stable
1239
+ * than the naive Lagrange formula. The order of the polynomial equals
1240
+ * the number of data points minus one.
1241
+ *
1242
+ * # Arguments
1243
+ *
1244
+ * * `x` - Known x-coordinates (must have distinct values)
1245
+ * * `y` - Known y-coordinates (same length as x)
1246
+ * * `x_new` - x-coordinates at which to evaluate the polynomial
1247
+ *
1248
+ * # Returns
1249
+ *
1250
+ * A `Vec<f64>` containing the interpolated values at each point in `x_new`.
1251
+ *
1252
+ * # Errors
1253
+ *
1254
+ * Returns an error if:
1255
+ * - Input arrays are empty or have mismatched lengths
1256
+ * - Fewer than 2 data points are provided
1257
+ * - x values contain duplicates
1258
+ * @param {Float64Array} x
1259
+ * @param {Float64Array} y
1260
+ * @param {Float64Array} x_new
1261
+ * @returns {Float64Array}
1262
+ */
1263
+ export function lagrange(x, y, x_new) {
1264
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_malloc);
1265
+ const len0 = WASM_VECTOR_LEN;
1266
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_malloc);
1267
+ const len1 = WASM_VECTOR_LEN;
1268
+ const ptr2 = passArrayF64ToWasm0(x_new, wasm.__wbindgen_malloc);
1269
+ const len2 = WASM_VECTOR_LEN;
1270
+ const ret = wasm.lagrange(ptr0, len0, ptr1, len1, ptr2, len2);
1271
+ if (ret[3]) {
1272
+ throw takeFromExternrefTable0(ret[2]);
1273
+ }
1274
+ var v4 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1275
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1276
+ return v4;
1277
+ }
1278
+
1279
+ /**
1280
+ * Apply a digital filter to a signal using direct form II transposed structure.
1281
+ *
1282
+ * Implements causal filtering with the inherent group delay of the filter.
1283
+ * Both IIR and FIR filters are supported.
1284
+ *
1285
+ * # Arguments
1286
+ *
1287
+ * * `b` - Numerator (feedforward) coefficients
1288
+ * * `a` - Denominator (feedback) coefficients. For FIR filters, use `[1.0]`.
1289
+ * * `x` - Input signal
1290
+ *
1291
+ * # Returns
1292
+ *
1293
+ * A `Vec<f64>` containing the filtered signal (same length as input).
1294
+ * @param {Float64Array} b
1295
+ * @param {Float64Array} a
1296
+ * @param {Float64Array} x
1297
+ * @returns {Float64Array}
1298
+ */
1299
+ export function lfilter(b, a, x) {
1300
+ const ptr0 = passArrayF64ToWasm0(b, wasm.__wbindgen_malloc);
1301
+ const len0 = WASM_VECTOR_LEN;
1302
+ const ptr1 = passArrayF64ToWasm0(a, wasm.__wbindgen_malloc);
1303
+ const len1 = WASM_VECTOR_LEN;
1304
+ const ptr2 = passArrayF64ToWasm0(x, wasm.__wbindgen_malloc);
1305
+ const len2 = WASM_VECTOR_LEN;
1306
+ const ret = wasm.lfilter(ptr0, len0, ptr1, len1, ptr2, len2);
1307
+ if (ret[3]) {
1308
+ throw takeFromExternrefTable0(ret[2]);
1309
+ }
1310
+ var v4 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1311
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1312
+ return v4;
1313
+ }
1314
+
1315
+ /**
1316
+ * Perform simple linear regression: y = slope * x + intercept.
1317
+ *
1318
+ * # Arguments
1319
+ * * `x` - Independent variable values
1320
+ * * `y` - Dependent variable values
1321
+ *
1322
+ * # Returns
1323
+ * JsValue containing:
1324
+ * - `slope`: regression slope
1325
+ * - `intercept`: regression intercept
1326
+ * - `r_squared`: coefficient of determination (R^2)
1327
+ * - `std_err_slope`: standard error of the slope
1328
+ * - `std_err_intercept`: standard error of the intercept
1329
+ * - `n`: number of data points
1330
+ * @param {Float64Array} x
1331
+ * @param {Float64Array} y
1332
+ * @returns {any}
1333
+ */
1334
+ export function linear_regression(x, y) {
1335
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_malloc);
1336
+ const len0 = WASM_VECTOR_LEN;
1337
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_malloc);
1338
+ const len1 = WASM_VECTOR_LEN;
1339
+ const ret = wasm.linear_regression(ptr0, len0, ptr1, len1);
1340
+ if (ret[2]) {
1341
+ throw takeFromExternrefTable0(ret[1]);
1342
+ }
1343
+ return takeFromExternrefTable0(ret[0]);
1344
+ }
1345
+
1346
+ /**
1347
+ * Log a message to the browser console
1348
+ * @param {string} message
1349
+ */
1350
+ export function log(message) {
1351
+ const ptr0 = passStringToWasm0(message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1352
+ const len0 = WASM_VECTOR_LEN;
1353
+ wasm.log(ptr0, len0);
1354
+ }
1355
+
1356
+ /**
1357
+ * Find the maximum value
1358
+ * @param {WasmArray} arr
1359
+ * @returns {number}
1360
+ */
1361
+ export function max(arr) {
1362
+ _assertClass(arr, WasmArray);
1363
+ const ret = wasm.max(arr.__wbg_ptr);
1364
+ return ret;
1365
+ }
1366
+
1367
+ /**
1368
+ * Compute the mean of all elements
1369
+ * @param {WasmArray} arr
1370
+ * @returns {number}
1371
+ */
1372
+ export function mean(arr) {
1373
+ _assertClass(arr, WasmArray);
1374
+ const ret = wasm.mean(arr.__wbg_ptr);
1375
+ return ret;
1376
+ }
1377
+
1378
+ /**
1379
+ * Compute the median of an array
1380
+ * @param {WasmArray} arr
1381
+ * @returns {number}
1382
+ */
1383
+ export function median(arr) {
1384
+ _assertClass(arr, WasmArray);
1385
+ const ret = wasm.median(arr.__wbg_ptr);
1386
+ return ret;
1387
+ }
1388
+
1389
+ /**
1390
+ * Memory usage information for the WASM module
1391
+ * @returns {any}
1392
+ */
1393
+ export function memory_usage() {
1394
+ const ret = wasm.memory_usage();
1395
+ return ret;
1396
+ }
1397
+
1398
+ /**
1399
+ * Find the minimum value
1400
+ * @param {WasmArray} arr
1401
+ * @returns {number}
1402
+ */
1403
+ export function min(arr) {
1404
+ _assertClass(arr, WasmArray);
1405
+ const ret = wasm.min(arr.__wbg_ptr);
1406
+ return ret;
1407
+ }
1408
+
1409
+ /**
1410
+ * Minimize a scalar function over a bracketed interval using golden section search.
1411
+ *
1412
+ * This is a derivative-free 1D optimization method. Since WASM cannot pass
1413
+ * function closures, this method works on a tabulated function: the caller provides
1414
+ * sample points and their values, and the algorithm interpolates.
1415
+ *
1416
+ * # Arguments
1417
+ * * `a` - Lower bound of the search interval
1418
+ * * `b` - Upper bound of the search interval
1419
+ * * `tol` - Convergence tolerance on the interval width
1420
+ * * `max_iter` - Maximum number of iterations
1421
+ *
1422
+ * # Returns
1423
+ * A JsValue containing:
1424
+ * - `x`: estimated minimizer
1425
+ * - `fun`: estimated function value at minimizer (NaN if unknown)
1426
+ * - `a`: final bracket lower bound
1427
+ * - `b`: final bracket upper bound
1428
+ * - `nit`: number of iterations
1429
+ * - `success`: whether tolerance was achieved
1430
+ * @param {number} a
1431
+ * @param {number} b
1432
+ * @param {number} tol
1433
+ * @param {number} max_iter
1434
+ * @returns {any}
1435
+ */
1436
+ export function minimize_golden(a, b, tol, max_iter) {
1437
+ const ret = wasm.minimize_golden(a, b, tol, max_iter);
1438
+ if (ret[2]) {
1439
+ throw takeFromExternrefTable0(ret[1]);
1440
+ }
1441
+ return takeFromExternrefTable0(ret[0]);
1442
+ }
1443
+
1444
+ /**
1445
+ * Minimize a function using the Nelder-Mead simplex algorithm.
1446
+ *
1447
+ * Since WASM cannot pass function closures from JS, this performs the Nelder-Mead
1448
+ * optimization using pre-evaluated simplex vertices and their function values.
1449
+ *
1450
+ * # Arguments
1451
+ * * `f_values` - Function values at the initial simplex vertices (n+1 values for n dimensions)
1452
+ * * `x0` - Flat array of initial simplex vertex coordinates, row-major layout:
1453
+ * each vertex has `n` coordinates, so total length is `(n+1) * n`
1454
+ * * `tol` - Convergence tolerance (standard deviation of simplex values)
1455
+ * * `max_iter` - Maximum number of iterations
1456
+ *
1457
+ * # Returns
1458
+ * A JsValue containing an object with fields:
1459
+ * - `x`: best point found (as array)
1460
+ * - `fun`: function value at best point
1461
+ * - `nit`: number of iterations performed
1462
+ * - `success`: whether convergence was achieved
1463
+ * - `simplex`: final simplex vertices (flat array)
1464
+ * - `simplex_values`: function values at final simplex vertices
1465
+ *
1466
+ * Note: With pre-evaluated data, this performs a single Nelder-Mead step cycle.
1467
+ * For iterative optimization, call repeatedly from JS, re-evaluating the function
1468
+ * at the new simplex points each iteration.
1469
+ * @param {Float64Array} f_values
1470
+ * @param {Float64Array} x0
1471
+ * @param {number} tol
1472
+ * @param {number} max_iter
1473
+ * @returns {any}
1474
+ */
1475
+ export function minimize_nelder_mead(f_values, x0, tol, max_iter) {
1476
+ const ptr0 = passArrayF64ToWasm0(f_values, wasm.__wbindgen_malloc);
1477
+ const len0 = WASM_VECTOR_LEN;
1478
+ const ptr1 = passArrayF64ToWasm0(x0, wasm.__wbindgen_malloc);
1479
+ const len1 = WASM_VECTOR_LEN;
1480
+ const ret = wasm.minimize_nelder_mead(ptr0, len0, ptr1, len1, tol, max_iter);
1481
+ if (ret[2]) {
1482
+ throw takeFromExternrefTable0(ret[1]);
1483
+ }
1484
+ return takeFromExternrefTable0(ret[0]);
1485
+ }
1486
+
1487
+ /**
1488
+ * Multiply two arrays element-wise
1489
+ * @param {WasmArray} a
1490
+ * @param {WasmArray} b
1491
+ * @returns {WasmArray}
1492
+ */
1493
+ export function multiply(a, b) {
1494
+ _assertClass(a, WasmArray);
1495
+ _assertClass(b, WasmArray);
1496
+ const ret = wasm.multiply(a.__wbg_ptr, b.__wbg_ptr);
1497
+ if (ret[2]) {
1498
+ throw takeFromExternrefTable0(ret[1]);
1499
+ }
1500
+ return WasmArray.__wrap(ret[0]);
1501
+ }
1502
+
1503
+ /**
1504
+ * Compute the Frobenius norm of a matrix
1505
+ * @param {WasmArray} arr
1506
+ * @returns {number}
1507
+ */
1508
+ export function norm_frobenius(arr) {
1509
+ _assertClass(arr, WasmArray);
1510
+ const ret = wasm.norm_frobenius(arr.__wbg_ptr);
1511
+ return ret;
1512
+ }
1513
+
1514
+ /**
1515
+ * Solve the ODE dy/dt = -y (exponential decay) using the classic RK4
1516
+ * method.
1517
+ *
1518
+ * Since JavaScript cannot pass function pointers to WASM, this solver uses
1519
+ * a built-in right-hand side (exponential decay, dy_i/dt = -y_i for every
1520
+ * component).
1521
+ *
1522
+ * * `y0_js` -- initial state vector (1-D array).
1523
+ * * `t_span_js` -- two-element array `[t_start, t_end]`.
1524
+ * * `n_steps` -- number of integration steps.
1525
+ *
1526
+ * Returns a serialised JSON object (via `JsValue`) with fields:
1527
+ * * `t` -- array of time values.
1528
+ * * `y` -- array of arrays, one per time point (each inner array has the
1529
+ * same length as `y0`).
1530
+ *
1531
+ * # Errors
1532
+ * Returns a `JsValue` error when inputs are invalid.
1533
+ * @param {any} y0_js
1534
+ * @param {any} t_span_js
1535
+ * @param {number} n_steps
1536
+ * @returns {any}
1537
+ */
1538
+ export function ode_solve(y0_js, t_span_js, n_steps) {
1539
+ const ret = wasm.ode_solve(y0_js, t_span_js, n_steps);
1540
+ if (ret[2]) {
1541
+ throw takeFromExternrefTable0(ret[1]);
1542
+ }
1543
+ return takeFromExternrefTable0(ret[0]);
1544
+ }
1545
+
1546
+ /**
1547
+ * Perform PCHIP (Piecewise Cubic Hermite Interpolating Polynomial) interpolation.
1548
+ *
1549
+ * PCHIP produces a monotonicity-preserving interpolant: if the input data is
1550
+ * monotonically increasing (or decreasing) in an interval, the interpolation
1551
+ * will be too. The first derivatives are continuous, but the second derivatives
1552
+ * may have jumps at the knot points.
1553
+ *
1554
+ * # Arguments
1555
+ *
1556
+ * * `x` - Known x-coordinates (must be sorted in ascending order, at least 2 points)
1557
+ * * `y` - Known y-coordinates (same length as x)
1558
+ * * `x_new` - x-coordinates at which to evaluate the interpolation
1559
+ *
1560
+ * # Returns
1561
+ *
1562
+ * A `Vec<f64>` containing the interpolated values at each point in `x_new`.
1563
+ *
1564
+ * # Errors
1565
+ *
1566
+ * Returns an error if:
1567
+ * - Input arrays are empty or have mismatched lengths
1568
+ * - Fewer than 2 data points are provided
1569
+ * - x values are not sorted in ascending order
1570
+ * @param {Float64Array} x
1571
+ * @param {Float64Array} y
1572
+ * @param {Float64Array} x_new
1573
+ * @returns {Float64Array}
1574
+ */
1575
+ export function pchip(x, y, x_new) {
1576
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_malloc);
1577
+ const len0 = WASM_VECTOR_LEN;
1578
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_malloc);
1579
+ const len1 = WASM_VECTOR_LEN;
1580
+ const ptr2 = passArrayF64ToWasm0(x_new, wasm.__wbindgen_malloc);
1581
+ const len2 = WASM_VECTOR_LEN;
1582
+ const ret = wasm.pchip(ptr0, len0, ptr1, len1, ptr2, len2);
1583
+ if (ret[3]) {
1584
+ throw takeFromExternrefTable0(ret[2]);
1585
+ }
1586
+ var v4 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1587
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1588
+ return v4;
1589
+ }
1590
+
1591
+ /**
1592
+ * Compute a percentile of an array
1593
+ * @param {WasmArray} arr
1594
+ * @param {number} q
1595
+ * @returns {number}
1596
+ */
1597
+ export function percentile(arr, q) {
1598
+ _assertClass(arr, WasmArray);
1599
+ const ret = wasm.percentile(arr.__wbg_ptr, q);
1600
+ if (ret[2]) {
1601
+ throw takeFromExternrefTable0(ret[1]);
1602
+ }
1603
+ return ret[0];
1604
+ }
1605
+
1606
+ /**
1607
+ * Evaluate a fitted polynomial at given points.
1608
+ *
1609
+ * # Arguments
1610
+ * * `coeffs` - Polynomial coefficients in ascending power order [c_0, c_1, ..., c_d]
1611
+ * * `x` - Points at which to evaluate the polynomial
1612
+ *
1613
+ * # Returns
1614
+ * Evaluated values as `Vec<f64>`
1615
+ * @param {Float64Array} coeffs
1616
+ * @param {Float64Array} x
1617
+ * @returns {Float64Array}
1618
+ */
1619
+ export function polynomial_eval(coeffs, x) {
1620
+ const ptr0 = passArrayF64ToWasm0(coeffs, wasm.__wbindgen_malloc);
1621
+ const len0 = WASM_VECTOR_LEN;
1622
+ const ptr1 = passArrayF64ToWasm0(x, wasm.__wbindgen_malloc);
1623
+ const len1 = WASM_VECTOR_LEN;
1624
+ const ret = wasm.polynomial_eval(ptr0, len0, ptr1, len1);
1625
+ var v3 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1626
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1627
+ return v3;
1628
+ }
1629
+
1630
+ /**
1631
+ * Fit a polynomial of given degree to data points using least squares.
1632
+ *
1633
+ * Finds coefficients c_0, c_1, ..., c_d such that:
1634
+ * y ~ c_0 + c_1*x + c_2*x^2 + ... + c_d*x^d
1635
+ *
1636
+ * # Arguments
1637
+ * * `x` - Independent variable values
1638
+ * * `y` - Dependent variable values
1639
+ * * `degree` - Degree of the polynomial to fit
1640
+ *
1641
+ * # Returns
1642
+ * Coefficients as a `Vec<f64>` in ascending power order: `[c_0, c_1, ..., c_d]`
1643
+ * @param {Float64Array} x
1644
+ * @param {Float64Array} y
1645
+ * @param {number} degree
1646
+ * @returns {Float64Array}
1647
+ */
1648
+ export function polynomial_fit(x, y, degree) {
1649
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_malloc);
1650
+ const len0 = WASM_VECTOR_LEN;
1651
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_malloc);
1652
+ const len1 = WASM_VECTOR_LEN;
1653
+ const ret = wasm.polynomial_fit(ptr0, len0, ptr1, len1, degree);
1654
+ if (ret[3]) {
1655
+ throw takeFromExternrefTable0(ret[2]);
1656
+ }
1657
+ var v3 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1658
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1659
+ return v3;
1660
+ }
1661
+
1662
+ /**
1663
+ * Compute the power spectrum (power spectral density) of a real-valued signal.
1664
+ *
1665
+ * Computes `|FFT(signal)|^2` for each frequency bin. The result represents
1666
+ * the distribution of signal power across frequencies.
1667
+ *
1668
+ * # Arguments
1669
+ *
1670
+ * * `data` - Real-valued input signal as `f64` array.
1671
+ *
1672
+ * # Returns
1673
+ *
1674
+ * A vector of length `n/2 + 1` containing the power at each frequency bin
1675
+ * (only positive frequencies, since the input is real-valued).
1676
+ *
1677
+ * # Errors
1678
+ *
1679
+ * Returns a `JsValue` error if:
1680
+ * - The input is empty
1681
+ * - The FFT computation fails
1682
+ *
1683
+ * # Example (JavaScript)
1684
+ *
1685
+ * ```javascript
1686
+ * const signal = new Float64Array([1, 0, -1, 0, 1, 0, -1, 0]);
1687
+ * const psd = power_spectrum(signal);
1688
+ * // psd[2] should have the dominant peak (frequency = 2 cycles per 8 samples)
1689
+ * ```
1690
+ * @param {Float64Array} data
1691
+ * @returns {Float64Array}
1692
+ */
1693
+ export function power_spectrum(data) {
1694
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
1695
+ const len0 = WASM_VECTOR_LEN;
1696
+ const ret = wasm.power_spectrum(ptr0, len0);
1697
+ if (ret[3]) {
1698
+ throw takeFromExternrefTable0(ret[2]);
1699
+ }
1700
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1701
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1702
+ return v2;
1703
+ }
1704
+
1705
+ /**
1706
+ * Generate random numbers from an exponential distribution
1707
+ * @param {any} shape
1708
+ * @param {number} lambda
1709
+ * @returns {WasmArray}
1710
+ */
1711
+ export function random_exponential(shape, lambda) {
1712
+ const ret = wasm.random_exponential(shape, lambda);
1713
+ if (ret[2]) {
1714
+ throw takeFromExternrefTable0(ret[1]);
1715
+ }
1716
+ return WasmArray.__wrap(ret[0]);
1717
+ }
1718
+
1719
+ /**
1720
+ * Generate random integers in the range [low, high)
1721
+ * @param {any} shape
1722
+ * @param {number} low
1723
+ * @param {number} high
1724
+ * @returns {WasmArray}
1725
+ */
1726
+ export function random_integers(shape, low, high) {
1727
+ const ret = wasm.random_integers(shape, low, high);
1728
+ if (ret[2]) {
1729
+ throw takeFromExternrefTable0(ret[1]);
1730
+ }
1731
+ return WasmArray.__wrap(ret[0]);
1732
+ }
1733
+
1734
+ /**
1735
+ * Generate random numbers from a normal (Gaussian) distribution
1736
+ * @param {any} shape
1737
+ * @param {number} mean
1738
+ * @param {number} std_dev
1739
+ * @returns {WasmArray}
1740
+ */
1741
+ export function random_normal(shape, mean, std_dev) {
1742
+ const ret = wasm.random_normal(shape, mean, std_dev);
1743
+ if (ret[2]) {
1744
+ throw takeFromExternrefTable0(ret[1]);
1745
+ }
1746
+ return WasmArray.__wrap(ret[0]);
1747
+ }
1748
+
1749
+ /**
1750
+ * Generate random numbers from a uniform distribution [0, 1)
1751
+ * @param {any} shape
1752
+ * @returns {WasmArray}
1753
+ */
1754
+ export function random_uniform(shape) {
1755
+ const ret = wasm.random_uniform(shape);
1756
+ if (ret[2]) {
1757
+ throw takeFromExternrefTable0(ret[1]);
1758
+ }
1759
+ return WasmArray.__wrap(ret[0]);
1760
+ }
1761
+
1762
+ /**
1763
+ * Compute the matrix rank
1764
+ * @param {WasmArray} arr
1765
+ * @param {number | null} [tolerance]
1766
+ * @returns {number}
1767
+ */
1768
+ export function rank(arr, tolerance) {
1769
+ _assertClass(arr, WasmArray);
1770
+ const ret = wasm.rank(arr.__wbg_ptr, !isLikeNone(tolerance), isLikeNone(tolerance) ? 0 : tolerance);
1771
+ if (ret[2]) {
1772
+ throw takeFromExternrefTable0(ret[1]);
1773
+ }
1774
+ return ret[0] >>> 0;
1775
+ }
1776
+
1777
+ /**
1778
+ * Compute the FFT of real-valued input data (RFFT).
1779
+ *
1780
+ * This is optimized for real-valued signals. The output contains only the
1781
+ * positive-frequency half of the spectrum (plus the DC and Nyquist components),
1782
+ * since the negative frequencies are redundant for real input.
1783
+ *
1784
+ * # Arguments
1785
+ *
1786
+ * * `data` - Real-valued input signal as `f64` array.
1787
+ *
1788
+ * # Returns
1789
+ *
1790
+ * Interleaved real/imaginary pairs of the half-spectrum.
1791
+ * Output length is `2 * (n/2 + 1)` where `n` is the input length, because
1792
+ * the result contains `n/2 + 1` complex values stored as interleaved pairs.
1793
+ *
1794
+ * # Errors
1795
+ *
1796
+ * Returns a `JsValue` error if:
1797
+ * - The input is empty
1798
+ * - The RFFT computation fails
1799
+ *
1800
+ * # Example (JavaScript)
1801
+ *
1802
+ * ```javascript
1803
+ * const signal = new Float64Array([1.0, 2.0, 3.0, 4.0]);
1804
+ * const spectrum = rfft(signal);
1805
+ * // spectrum has (4/2 + 1) * 2 = 6 elements: 3 complex values as interleaved pairs
1806
+ * ```
1807
+ * @param {Float64Array} data
1808
+ * @returns {Float64Array}
1809
+ */
1810
+ export function rfft(data) {
1811
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
1812
+ const len0 = WASM_VECTOR_LEN;
1813
+ const ret = wasm.rfft(ptr0, len0);
1814
+ if (ret[3]) {
1815
+ throw takeFromExternrefTable0(ret[2]);
1816
+ }
1817
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1818
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1819
+ return v2;
1820
+ }
1821
+
1822
+ /**
1823
+ * Compute the FFT sample frequencies for real-valued FFT (RFFT).
1824
+ *
1825
+ * Returns the frequency bin centers for the positive-frequency half of the
1826
+ * spectrum, which is the output of `rfft`.
1827
+ *
1828
+ * # Arguments
1829
+ *
1830
+ * * `n` - Number of samples in the original signal (window length).
1831
+ * * `d` - Sample spacing (inverse of the sampling rate). Must be positive.
1832
+ *
1833
+ * # Returns
1834
+ *
1835
+ * A vector of length `n/2 + 1` containing the sample frequencies for
1836
+ * the positive half of the spectrum.
1837
+ *
1838
+ * # Errors
1839
+ *
1840
+ * Returns a `JsValue` error if:
1841
+ * - `n` is 0
1842
+ * - `d` is not positive
1843
+ * - The computation fails
1844
+ *
1845
+ * # Example (JavaScript)
1846
+ *
1847
+ * ```javascript
1848
+ * const freqs = rfftfreq(8, 0.1);
1849
+ * // freqs = [0.0, 1.25, 2.5, 3.75, 5.0]
1850
+ * ```
1851
+ * @param {number} n
1852
+ * @param {number} d
1853
+ * @returns {Float64Array}
1854
+ */
1855
+ export function rfftfreq(n, d) {
1856
+ const ret = wasm.rfftfreq(n, d);
1857
+ if (ret[3]) {
1858
+ throw takeFromExternrefTable0(ret[2]);
1859
+ }
1860
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1861
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1862
+ return v1;
1863
+ }
1864
+
1865
+ /**
1866
+ * Perform a single explicit Runge-Kutta 4th order (RK4) step.
1867
+ *
1868
+ * Because JavaScript cannot pass function pointers, the caller must supply
1869
+ * the derivative values pre-computed at the current state.
1870
+ *
1871
+ * * `f_vals_js` -- derivative values dy/dt evaluated at (t, y), one per
1872
+ * component.
1873
+ * * `t` -- current time.
1874
+ * * `y_js` -- current state vector.
1875
+ * * `h` -- step size.
1876
+ *
1877
+ * The function approximates the next state assuming a *constant* derivative
1878
+ * (i.e. Euler) combined with the classical RK4 weighting using the provided
1879
+ * derivative. For a full multi-stage RK4 the caller would need to evaluate
1880
+ * the derivative at the intermediate stages; this helper is therefore best
1881
+ * suited for demonstration / simple cases.
1882
+ *
1883
+ * Returns the new state vector `y_{n+1}` as a `Float64Array`.
1884
+ *
1885
+ * # Errors
1886
+ * Returns a `JsValue` error when `f_vals` and `y` have different lengths.
1887
+ * @param {any} f_vals_js
1888
+ * @param {number} _t
1889
+ * @param {any} y_js
1890
+ * @param {number} h
1891
+ * @returns {Float64Array}
1892
+ */
1893
+ export function rk4_step(f_vals_js, _t, y_js, h) {
1894
+ const ret = wasm.rk4_step(f_vals_js, _t, y_js, h);
1895
+ if (ret[2]) {
1896
+ throw takeFromExternrefTable0(ret[1]);
1897
+ }
1898
+ return takeFromExternrefTable0(ret[0]);
1899
+ }
1900
+
1901
+ /**
1902
+ * Compute the integral of tabulated data `y` with uniform spacing `dx`
1903
+ * using Romberg integration (Richardson extrapolation of the trapezoidal
1904
+ * rule).
1905
+ *
1906
+ * The number of data points must be of the form `2^k + 1` for some
1907
+ * non-negative integer `k` (e.g. 2, 3, 5, 9, 17, 33, ...). If the length
1908
+ * does not satisfy this requirement an error is returned.
1909
+ *
1910
+ * # Arguments
1911
+ * * `y_js` -- ordinate values (array of `f64`).
1912
+ * * `dx` -- uniform spacing between consecutive x-values.
1913
+ *
1914
+ * # Errors
1915
+ * Returns a `JsValue` error when the input length is not `2^k + 1` or when
1916
+ * fewer than 2 points are given.
1917
+ * @param {any} y_js
1918
+ * @param {number} dx
1919
+ * @returns {number}
1920
+ */
1921
+ export function romberg(y_js, dx) {
1922
+ const ret = wasm.romberg(y_js, dx);
1923
+ if (ret[2]) {
1924
+ throw takeFromExternrefTable0(ret[1]);
1925
+ }
1926
+ return ret[0];
1927
+ }
1928
+
1929
+ /**
1930
+ * Set the random seed for reproducibility
1931
+ * @param {bigint} seed
1932
+ * @returns {string}
1933
+ */
1934
+ export function set_random_seed(seed) {
1935
+ let deferred1_0;
1936
+ let deferred1_1;
1937
+ try {
1938
+ const ret = wasm.set_random_seed(seed);
1939
+ deferred1_0 = ret[0];
1940
+ deferred1_1 = ret[1];
1941
+ return getStringFromWasm0(ret[0], ret[1]);
1942
+ } finally {
1943
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1944
+ }
1945
+ }
1946
+
1947
+ /**
1948
+ * Compute the definite integral of `y` over `x` using Simpson's rule.
1949
+ *
1950
+ * For segments where three consecutive points are available the classic
1951
+ * Simpson 1/3 rule is used. A final trapezoidal panel is added when the
1952
+ * number of intervals is odd.
1953
+ *
1954
+ * # Errors
1955
+ * Returns a `JsValue` error on mismatched lengths or fewer than 2 points.
1956
+ * @param {any} y_js
1957
+ * @param {any} x_js
1958
+ * @returns {number}
1959
+ */
1960
+ export function simpson(y_js, x_js) {
1961
+ const ret = wasm.simpson(y_js, x_js);
1962
+ if (ret[2]) {
1963
+ throw takeFromExternrefTable0(ret[1]);
1964
+ }
1965
+ return ret[0];
1966
+ }
1967
+
1968
+ /**
1969
+ * Solve a system of linear equations Ax = b
1970
+ * @param {WasmArray} a
1971
+ * @param {WasmArray} b
1972
+ * @returns {WasmArray}
1973
+ */
1974
+ export function solve(a, b) {
1975
+ _assertClass(a, WasmArray);
1976
+ _assertClass(b, WasmArray);
1977
+ const ret = wasm.solve(a.__wbg_ptr, b.__wbg_ptr);
1978
+ if (ret[2]) {
1979
+ throw takeFromExternrefTable0(ret[1]);
1980
+ }
1981
+ return WasmArray.__wrap(ret[0]);
1982
+ }
1983
+
1984
+ /**
1985
+ * Compute the standard deviation of an array
1986
+ * @param {WasmArray} arr
1987
+ * @returns {number}
1988
+ */
1989
+ export function std(arr) {
1990
+ _assertClass(arr, WasmArray);
1991
+ const ret = wasm.std(arr.__wbg_ptr);
1992
+ return ret;
1993
+ }
1994
+
1995
+ /**
1996
+ * Compute the standard deviation with specified degrees of freedom
1997
+ * @param {WasmArray} arr
1998
+ * @param {number} ddof
1999
+ * @returns {number}
2000
+ */
2001
+ export function std_with_ddof(arr, ddof) {
2002
+ _assertClass(arr, WasmArray);
2003
+ const ret = wasm.std_with_ddof(arr.__wbg_ptr, ddof);
2004
+ return ret;
2005
+ }
2006
+
2007
+ /**
2008
+ * Subtract two arrays element-wise
2009
+ * @param {WasmArray} a
2010
+ * @param {WasmArray} b
2011
+ * @returns {WasmArray}
2012
+ */
2013
+ export function subtract(a, b) {
2014
+ _assertClass(a, WasmArray);
2015
+ _assertClass(b, WasmArray);
2016
+ const ret = wasm.subtract(a.__wbg_ptr, b.__wbg_ptr);
2017
+ if (ret[2]) {
2018
+ throw takeFromExternrefTable0(ret[1]);
2019
+ }
2020
+ return WasmArray.__wrap(ret[0]);
2021
+ }
2022
+
2023
+ /**
2024
+ * Sum all elements in the array
2025
+ * @param {WasmArray} arr
2026
+ * @returns {number}
2027
+ */
2028
+ export function sum(arr) {
2029
+ _assertClass(arr, WasmArray);
2030
+ const ret = wasm.sum(arr.__wbg_ptr);
2031
+ return ret;
2032
+ }
2033
+
2034
+ /**
2035
+ * Compute the trace of a matrix (sum of diagonal elements)
2036
+ * @param {WasmArray} arr
2037
+ * @returns {number}
2038
+ */
2039
+ export function trace(arr) {
2040
+ _assertClass(arr, WasmArray);
2041
+ const ret = wasm.trace(arr.__wbg_ptr);
2042
+ if (ret[2]) {
2043
+ throw takeFromExternrefTable0(ret[1]);
2044
+ }
2045
+ return ret[0];
2046
+ }
2047
+
2048
+ /**
2049
+ * Compute the definite integral of `y` over `x` using the composite
2050
+ * trapezoidal rule.
2051
+ *
2052
+ * Both `y_js` and `x_js` must be arrays of the same length (>= 2).
2053
+ *
2054
+ * # Errors
2055
+ * Returns a `JsValue` error when the inputs have mismatched lengths or
2056
+ * contain fewer than 2 points.
2057
+ * @param {any} y_js
2058
+ * @param {any} x_js
2059
+ * @returns {number}
2060
+ */
2061
+ export function trapezoid(y_js, x_js) {
2062
+ const ret = wasm.trapezoid(y_js, x_js);
2063
+ if (ret[2]) {
2064
+ throw takeFromExternrefTable0(ret[1]);
2065
+ }
2066
+ return ret[0];
2067
+ }
2068
+
2069
+ /**
2070
+ * Compute the variance of an array
2071
+ * @param {WasmArray} arr
2072
+ * @returns {number}
2073
+ */
2074
+ export function variance(arr) {
2075
+ _assertClass(arr, WasmArray);
2076
+ const ret = wasm.variance(arr.__wbg_ptr);
2077
+ return ret;
2078
+ }
2079
+
2080
+ /**
2081
+ * Compute the variance with specified degrees of freedom
2082
+ * @param {WasmArray} arr
2083
+ * @param {number} ddof
2084
+ * @returns {number}
2085
+ */
2086
+ export function variance_with_ddof(arr, ddof) {
2087
+ _assertClass(arr, WasmArray);
2088
+ const ret = wasm.variance_with_ddof(arr.__wbg_ptr, ddof);
2089
+ return ret;
2090
+ }
2091
+
2092
+ /**
2093
+ * Get the version of SciRS2-WASM
2094
+ * @returns {string}
2095
+ */
2096
+ export function version() {
2097
+ let deferred1_0;
2098
+ let deferred1_1;
2099
+ try {
2100
+ const ret = wasm.version();
2101
+ deferred1_0 = ret[0];
2102
+ deferred1_1 = ret[1];
2103
+ return getStringFromWasm0(ret[0], ret[1]);
2104
+ } finally {
2105
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
2106
+ }
2107
+ }
2108
+ export function __wbg_Error_83742b46f01ce22d(arg0, arg1) {
2109
+ const ret = Error(getStringFromWasm0(arg0, arg1));
2110
+ return ret;
2111
+ }
2112
+ export function __wbg_String_8564e559799eccda(arg0, arg1) {
2113
+ const ret = String(arg1);
2114
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2115
+ const len1 = WASM_VECTOR_LEN;
2116
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
2117
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
2118
+ }
2119
+ export function __wbg___wbindgen_is_object_781bc9f159099513(arg0) {
2120
+ const val = arg0;
2121
+ const ret = typeof(val) === 'object' && val !== null;
2122
+ return ret;
2123
+ }
2124
+ export function __wbg___wbindgen_is_string_7ef6b97b02428fae(arg0) {
2125
+ const ret = typeof(arg0) === 'string';
2126
+ return ret;
2127
+ }
2128
+ export function __wbg___wbindgen_is_undefined_52709e72fb9f179c(arg0) {
2129
+ const ret = arg0 === undefined;
2130
+ return ret;
2131
+ }
2132
+ export function __wbg___wbindgen_number_get_34bb9d9dcfa21373(arg0, arg1) {
2133
+ const obj = arg1;
2134
+ const ret = typeof(obj) === 'number' ? obj : undefined;
2135
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
2136
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
2137
+ }
2138
+ export function __wbg___wbindgen_throw_6ddd609b62940d55(arg0, arg1) {
2139
+ throw new Error(getStringFromWasm0(arg0, arg1));
2140
+ }
2141
+ export function __wbg_error_a6fa202b58aa1cd3(arg0, arg1) {
2142
+ let deferred0_0;
2143
+ let deferred0_1;
2144
+ try {
2145
+ deferred0_0 = arg0;
2146
+ deferred0_1 = arg1;
2147
+ console.error(getStringFromWasm0(arg0, arg1));
2148
+ } finally {
2149
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
2150
+ }
2151
+ }
2152
+ export function __wbg_from_4bdf88943703fd48(arg0) {
2153
+ const ret = Array.from(arg0);
2154
+ return ret;
2155
+ }
2156
+ export function __wbg_getRandomValues_76dfc69825c9c552() { return handleError(function (arg0, arg1) {
2157
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
2158
+ }, arguments); }
2159
+ export function __wbg_get_a8ee5c45dabc1b3b(arg0, arg1) {
2160
+ const ret = arg0[arg1 >>> 0];
2161
+ return ret;
2162
+ }
2163
+ export function __wbg_instanceof_Float32Array_6f3d6ec9510b72a8(arg0) {
2164
+ let result;
2165
+ try {
2166
+ result = arg0 instanceof Float32Array;
2167
+ } catch (_) {
2168
+ result = false;
2169
+ }
2170
+ const ret = result;
2171
+ return ret;
2172
+ }
2173
+ export function __wbg_instanceof_Float64Array_2d1021bf5466d4cb(arg0) {
2174
+ let result;
2175
+ try {
2176
+ result = arg0 instanceof Float64Array;
2177
+ } catch (_) {
2178
+ result = false;
2179
+ }
2180
+ const ret = result;
2181
+ return ret;
2182
+ }
2183
+ export function __wbg_instanceof_Window_23e677d2c6843922(arg0) {
2184
+ let result;
2185
+ try {
2186
+ result = arg0 instanceof Window;
2187
+ } catch (_) {
2188
+ result = false;
2189
+ }
2190
+ const ret = result;
2191
+ return ret;
2192
+ }
2193
+ export function __wbg_isArray_42f3245bcac28e65(arg0) {
2194
+ const ret = Array.isArray(arg0);
2195
+ return ret;
2196
+ }
2197
+ export function __wbg_length_259ee9d041e381ad(arg0) {
2198
+ const ret = arg0.length;
2199
+ return ret;
2200
+ }
2201
+ export function __wbg_length_550d8a396009cd38(arg0) {
2202
+ const ret = arg0.length;
2203
+ return ret;
2204
+ }
2205
+ export function __wbg_length_b3416cf66a5452c8(arg0) {
2206
+ const ret = arg0.length;
2207
+ return ret;
2208
+ }
2209
+ export function __wbg_log_524eedafa26daa59(arg0) {
2210
+ console.log(arg0);
2211
+ }
2212
+ export function __wbg_new_1db9947b8e01b15f(arg0) {
2213
+ const ret = new Float64Array(arg0);
2214
+ return ret;
2215
+ }
2216
+ export function __wbg_new_227d7c05414eb861() {
2217
+ const ret = new Error();
2218
+ return ret;
2219
+ }
2220
+ export function __wbg_new_2cb6f455748a4e89(arg0) {
2221
+ const ret = new Float32Array(arg0);
2222
+ return ret;
2223
+ }
2224
+ export function __wbg_new_49d5571bd3f0c4d4() {
2225
+ const ret = new Map();
2226
+ return ret;
2227
+ }
2228
+ export function __wbg_new_a70fbab9066b301f() {
2229
+ const ret = new Array();
2230
+ return ret;
2231
+ }
2232
+ export function __wbg_new_ab79df5bd7c26067() {
2233
+ const ret = new Object();
2234
+ return ret;
2235
+ }
2236
+ export function __wbg_new_with_length_3259a525196bd8cc(arg0) {
2237
+ const ret = new Array(arg0 >>> 0);
2238
+ return ret;
2239
+ }
2240
+ export function __wbg_new_with_length_eae667475c36c4e4(arg0) {
2241
+ const ret = new Float64Array(arg0 >>> 0);
2242
+ return ret;
2243
+ }
2244
+ export function __wbg_now_c6d7a7d35f74f6f1(arg0) {
2245
+ const ret = arg0.now();
2246
+ return ret;
2247
+ }
2248
+ export function __wbg_performance_28be169151161678(arg0) {
2249
+ const ret = arg0.performance;
2250
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
2251
+ }
2252
+ export function __wbg_prototypesetcall_247ac4333d4d3cb4(arg0, arg1, arg2) {
2253
+ Float32Array.prototype.set.call(getArrayF32FromWasm0(arg0, arg1), arg2);
2254
+ }
2255
+ export function __wbg_prototypesetcall_79daf97fb14c7a19(arg0, arg1, arg2) {
2256
+ Float64Array.prototype.set.call(getArrayF64FromWasm0(arg0, arg1), arg2);
2257
+ }
2258
+ export function __wbg_set_282384002438957f(arg0, arg1, arg2) {
2259
+ arg0[arg1 >>> 0] = arg2;
2260
+ }
2261
+ export function __wbg_set_636d1e3e4286e068(arg0, arg1, arg2) {
2262
+ arg0.set(getArrayF64FromWasm0(arg1, arg2));
2263
+ }
2264
+ export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
2265
+ arg0[arg1] = arg2;
2266
+ }
2267
+ export function __wbg_set_bf7251625df30a02(arg0, arg1, arg2) {
2268
+ const ret = arg0.set(arg1, arg2);
2269
+ return ret;
2270
+ }
2271
+ export function __wbg_stack_3b0d974bbf31e44f(arg0, arg1) {
2272
+ const ret = arg1.stack;
2273
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2274
+ const len1 = WASM_VECTOR_LEN;
2275
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
2276
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
2277
+ }
2278
+ export function __wbg_static_accessor_GLOBAL_8adb955bd33fac2f() {
2279
+ const ret = typeof global === 'undefined' ? null : global;
2280
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
2281
+ }
2282
+ export function __wbg_static_accessor_GLOBAL_THIS_ad356e0db91c7913() {
2283
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
2284
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
2285
+ }
2286
+ export function __wbg_static_accessor_SELF_f207c857566db248() {
2287
+ const ret = typeof self === 'undefined' ? null : self;
2288
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
2289
+ }
2290
+ export function __wbg_static_accessor_WINDOW_bb9f1ba69d61b386() {
2291
+ const ret = typeof window === 'undefined' ? null : window;
2292
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
2293
+ }
2294
+ export function __wbindgen_cast_0000000000000001(arg0) {
2295
+ // Cast intrinsic for `F64 -> Externref`.
2296
+ const ret = arg0;
2297
+ return ret;
2298
+ }
2299
+ export function __wbindgen_cast_0000000000000002(arg0) {
2300
+ // Cast intrinsic for `I64 -> Externref`.
2301
+ const ret = arg0;
2302
+ return ret;
2303
+ }
2304
+ export function __wbindgen_cast_0000000000000003(arg0, arg1) {
2305
+ // Cast intrinsic for `Ref(String) -> Externref`.
2306
+ const ret = getStringFromWasm0(arg0, arg1);
2307
+ return ret;
2308
+ }
2309
+ export function __wbindgen_cast_0000000000000004(arg0) {
2310
+ // Cast intrinsic for `U64 -> Externref`.
2311
+ const ret = BigInt.asUintN(64, arg0);
2312
+ return ret;
2313
+ }
2314
+ export function __wbindgen_init_externref_table() {
2315
+ const table = wasm.__wbindgen_externrefs;
2316
+ const offset = table.grow(4);
2317
+ table.set(0, undefined);
2318
+ table.set(offset + 0, undefined);
2319
+ table.set(offset + 1, null);
2320
+ table.set(offset + 2, true);
2321
+ table.set(offset + 3, false);
2322
+ }
2323
+ const PerformanceTimerFinalization = (typeof FinalizationRegistry === 'undefined')
2324
+ ? { register: () => {}, unregister: () => {} }
2325
+ : new FinalizationRegistry(ptr => wasm.__wbg_performancetimer_free(ptr >>> 0, 1));
2326
+ const WasmArrayFinalization = (typeof FinalizationRegistry === 'undefined')
2327
+ ? { register: () => {}, unregister: () => {} }
2328
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmarray_free(ptr >>> 0, 1));
2329
+
2330
+ function addToExternrefTable0(obj) {
2331
+ const idx = wasm.__externref_table_alloc();
2332
+ wasm.__wbindgen_externrefs.set(idx, obj);
2333
+ return idx;
2334
+ }
2335
+
2336
+ function _assertClass(instance, klass) {
2337
+ if (!(instance instanceof klass)) {
2338
+ throw new Error(`expected instance of ${klass.name}`);
2339
+ }
2340
+ }
2341
+
2342
+ function getArrayF32FromWasm0(ptr, len) {
2343
+ ptr = ptr >>> 0;
2344
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
2345
+ }
2346
+
2347
+ function getArrayF64FromWasm0(ptr, len) {
2348
+ ptr = ptr >>> 0;
2349
+ return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
2350
+ }
2351
+
2352
+ function getArrayU8FromWasm0(ptr, len) {
2353
+ ptr = ptr >>> 0;
2354
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
2355
+ }
2356
+
2357
+ let cachedDataViewMemory0 = null;
2358
+ function getDataViewMemory0() {
2359
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
2360
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
2361
+ }
2362
+ return cachedDataViewMemory0;
2363
+ }
2364
+
2365
+ let cachedFloat32ArrayMemory0 = null;
2366
+ function getFloat32ArrayMemory0() {
2367
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
2368
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
2369
+ }
2370
+ return cachedFloat32ArrayMemory0;
2371
+ }
2372
+
2373
+ let cachedFloat64ArrayMemory0 = null;
2374
+ function getFloat64ArrayMemory0() {
2375
+ if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
2376
+ cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
2377
+ }
2378
+ return cachedFloat64ArrayMemory0;
2379
+ }
2380
+
2381
+ function getStringFromWasm0(ptr, len) {
2382
+ ptr = ptr >>> 0;
2383
+ return decodeText(ptr, len);
2384
+ }
2385
+
2386
+ let cachedUint8ArrayMemory0 = null;
2387
+ function getUint8ArrayMemory0() {
2388
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
2389
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
2390
+ }
2391
+ return cachedUint8ArrayMemory0;
2392
+ }
2393
+
2394
+ function handleError(f, args) {
2395
+ try {
2396
+ return f.apply(this, args);
2397
+ } catch (e) {
2398
+ const idx = addToExternrefTable0(e);
2399
+ wasm.__wbindgen_exn_store(idx);
2400
+ }
2401
+ }
2402
+
2403
+ function isLikeNone(x) {
2404
+ return x === undefined || x === null;
2405
+ }
2406
+
2407
+ function passArrayF64ToWasm0(arg, malloc) {
2408
+ const ptr = malloc(arg.length * 8, 8) >>> 0;
2409
+ getFloat64ArrayMemory0().set(arg, ptr / 8);
2410
+ WASM_VECTOR_LEN = arg.length;
2411
+ return ptr;
2412
+ }
2413
+
2414
+ function passStringToWasm0(arg, malloc, realloc) {
2415
+ if (realloc === undefined) {
2416
+ const buf = cachedTextEncoder.encode(arg);
2417
+ const ptr = malloc(buf.length, 1) >>> 0;
2418
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
2419
+ WASM_VECTOR_LEN = buf.length;
2420
+ return ptr;
2421
+ }
2422
+
2423
+ let len = arg.length;
2424
+ let ptr = malloc(len, 1) >>> 0;
2425
+
2426
+ const mem = getUint8ArrayMemory0();
2427
+
2428
+ let offset = 0;
2429
+
2430
+ for (; offset < len; offset++) {
2431
+ const code = arg.charCodeAt(offset);
2432
+ if (code > 0x7F) break;
2433
+ mem[ptr + offset] = code;
2434
+ }
2435
+ if (offset !== len) {
2436
+ if (offset !== 0) {
2437
+ arg = arg.slice(offset);
2438
+ }
2439
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
2440
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
2441
+ const ret = cachedTextEncoder.encodeInto(arg, view);
2442
+
2443
+ offset += ret.written;
2444
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
2445
+ }
2446
+
2447
+ WASM_VECTOR_LEN = offset;
2448
+ return ptr;
2449
+ }
2450
+
2451
+ function takeFromExternrefTable0(idx) {
2452
+ const value = wasm.__wbindgen_externrefs.get(idx);
2453
+ wasm.__externref_table_dealloc(idx);
2454
+ return value;
2455
+ }
2456
+
2457
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
2458
+ cachedTextDecoder.decode();
2459
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
2460
+ let numBytesDecoded = 0;
2461
+ function decodeText(ptr, len) {
2462
+ numBytesDecoded += len;
2463
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
2464
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
2465
+ cachedTextDecoder.decode();
2466
+ numBytesDecoded = len;
2467
+ }
2468
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
2469
+ }
2470
+
2471
+ const cachedTextEncoder = new TextEncoder();
2472
+
2473
+ if (!('encodeInto' in cachedTextEncoder)) {
2474
+ cachedTextEncoder.encodeInto = function (arg, view) {
2475
+ const buf = cachedTextEncoder.encode(arg);
2476
+ view.set(buf);
2477
+ return {
2478
+ read: arg.length,
2479
+ written: buf.length
2480
+ };
2481
+ };
2482
+ }
2483
+
2484
+ let WASM_VECTOR_LEN = 0;
2485
+
2486
+
2487
+ let wasm;
2488
+ export function __wbg_set_wasm(val) {
2489
+ wasm = val;
2490
+ }