@iyulab/u-numflow 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,6 +19,7 @@ u-numflow provides foundational mathematical, statistical, and probabilistic bui
19
19
  | `distributions` | Probability distributions: Uniform, Triangular, PERT, Normal, LogNormal |
20
20
  | `special` | Special functions: normal/t/F/chi² CDF, inverse normal CDF, regularized incomplete beta/gamma, erf |
21
21
  | `transforms` | Data transformations: Box-Cox (λ via MLE golden-section search), inverse Box-Cox |
22
+ | `fourier` | Discrete Fourier transform of any length (radix-2 for powers of two, Bluestein otherwise): `fft`, `ifft`, `rfft`, `Complex` |
22
23
  | `matrix` | Dense matrix operations: determinant, inverse, Cholesky decomposition, Jacobi eigenvalue decomposition |
23
24
  | `random` | Seeded RNG, Fisher-Yates shuffle, weighted sampling, random subset selection |
24
25
  | `collections` | Specialized data structures: Union-Find with path compression and union-by-rank |
@@ -62,6 +63,12 @@ use u_numflow::transforms::{estimate_lambda, box_cox};
62
63
  let data = [1.0, 2.0, 4.0, 8.0, 16.0];
63
64
  let lambda = estimate_lambda(&data, -2.0, 2.0).unwrap(); // MLE via golden-section
64
65
  let transformed = box_cox(&data, lambda).unwrap();
66
+
67
+ // Discrete Fourier transform of any length
68
+ use u_numflow::fourier::rfft;
69
+ let signal: Vec<f64> = (0..30).map(|j| (2.0 * std::f64::consts::PI * 3.0 * j as f64 / 30.0).sin()).collect();
70
+ let spectrum = rfft(&signal); // 30 complex bins; bin 3 carries the energy
71
+ assert!(spectrum[3].norm() > 14.0);
65
72
  ```
66
73
 
67
74
  ## Build & Test
@@ -93,6 +100,10 @@ The package resolves per environment via a conditional `exports` map:
93
100
  | Bundlers (webpack, Vite, …) | ESM + WebAssembly ESM-integration (`default` condition) |
94
101
  | Node.js — `require()`, ESM `import`, CJS TS runners (`tsx`, `ts-node`) | CJS glue loading the wasm from the filesystem (`node` condition) — no loader hooks or flags |
95
102
 
103
+ Exported functions: `mean`, `std_dev`, `variance`, `normal_cdf`, `box_cox`, `estimate_lambda`, and
104
+ `rfft(data) -> Float64Array` — the DFT of a real sequence of any length, interleaved as
105
+ `[re0, im0, re1, im1, …]` (bins `k` and `n − k` are conjugates, so `0..=n/2` describes the spectrum).
106
+
96
107
  ## Related
97
108
 
98
109
  - [u-metaheur](https://github.com/iyulab/u-metaheur) — Metaheuristic optimization (GA, SA, ALNS, CP)
@@ -79,6 +79,25 @@ function normal_cdf(x) {
79
79
  }
80
80
  exports.normal_cdf = normal_cdf;
81
81
 
82
+ /**
83
+ * Forward DFT of a real sequence of any length.
84
+ *
85
+ * Returns the `n` complex bins interleaved as `[re0, im0, re1, im1, …]`
86
+ * (length `2n`). Bins `k` and `n − k` are conjugates, so the spectrum of a
87
+ * real signal is fully described by bins `0..=n/2`.
88
+ * @param {Float64Array} data
89
+ * @returns {Float64Array}
90
+ */
91
+ function rfft(data) {
92
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
93
+ const len0 = WASM_VECTOR_LEN;
94
+ const ret = wasm.rfft(ptr0, len0);
95
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
96
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
97
+ return v2;
98
+ }
99
+ exports.rfft = rfft;
100
+
82
101
  /**
83
102
  * Sample standard deviation of `data` (Bessel-corrected, denominator n−1).
84
103
  *
@@ -39,6 +39,15 @@ export function mean(data: Float64Array): number;
39
39
  */
40
40
  export function normal_cdf(x: number): number;
41
41
 
42
+ /**
43
+ * Forward DFT of a real sequence of any length.
44
+ *
45
+ * Returns the `n` complex bins interleaved as `[re0, im0, re1, im1, …]`
46
+ * (length `2n`). Bins `k` and `n − k` are conjugates, so the spectrum of a
47
+ * real signal is fully described by bins `0..=n/2`.
48
+ */
49
+ export function rfft(data: Float64Array): Float64Array;
50
+
42
51
  /**
43
52
  * Sample standard deviation of `data` (Bessel-corrected, denominator n−1).
44
53
  *
Binary file
package/package.json CHANGED
@@ -4,8 +4,8 @@
4
4
  "collaborators": [
5
5
  "iyulab"
6
6
  ],
7
- "description": "Mathematical primitives for the U-Engine ecosystem: statistics, probability, random sampling, and collections.",
8
- "version": "0.4.0",
7
+ "description": "Foundational mathematical primitives: statistics, probability distributions, random sampling, and collections.",
8
+ "version": "0.5.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
package/u_numflow.d.ts CHANGED
@@ -39,6 +39,15 @@ export function mean(data: Float64Array): number;
39
39
  */
40
40
  export function normal_cdf(x: number): number;
41
41
 
42
+ /**
43
+ * Forward DFT of a real sequence of any length.
44
+ *
45
+ * Returns the `n` complex bins interleaved as `[re0, im0, re1, im1, …]`
46
+ * (length `2n`). Bins `k` and `n − k` are conjugates, so the spectrum of a
47
+ * real signal is fully described by bins `0..=n/2`.
48
+ */
49
+ export function rfft(data: Float64Array): Float64Array;
50
+
42
51
  /**
43
52
  * Sample standard deviation of `data` (Bessel-corrected, denominator n−1).
44
53
  *
package/u_numflow.js CHANGED
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./u_numflow_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
  wasm.__wbindgen_start();
7
7
  export {
8
- box_cox, estimate_lambda, mean, normal_cdf, std_dev, variance
8
+ box_cox, estimate_lambda, mean, normal_cdf, rfft, std_dev, variance
9
9
  } from "./u_numflow_bg.js";
package/u_numflow_bg.js CHANGED
@@ -73,6 +73,24 @@ export function normal_cdf(x) {
73
73
  return ret;
74
74
  }
75
75
 
76
+ /**
77
+ * Forward DFT of a real sequence of any length.
78
+ *
79
+ * Returns the `n` complex bins interleaved as `[re0, im0, re1, im1, …]`
80
+ * (length `2n`). Bins `k` and `n − k` are conjugates, so the spectrum of a
81
+ * real signal is fully described by bins `0..=n/2`.
82
+ * @param {Float64Array} data
83
+ * @returns {Float64Array}
84
+ */
85
+ export function rfft(data) {
86
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
87
+ const len0 = WASM_VECTOR_LEN;
88
+ const ret = wasm.rfft(ptr0, len0);
89
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
90
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
91
+ return v2;
92
+ }
93
+
76
94
  /**
77
95
  * Sample standard deviation of `data` (Bessel-corrected, denominator n−1).
78
96
  *
package/u_numflow_bg.wasm CHANGED
Binary file