diff options
| author | Sam Nystrom <sam@samnystrom.dev> | 2024-03-08 14:52:06 +0000 |
|---|---|---|
| committer | Sam Nystrom <sam@samnystrom.dev> | 2024-03-09 02:05:58 -0500 |
| commit | 41213e45761fc1dd795d462ad7bc719533efd09e (patch) | |
| tree | 3de488d0360175fe1f399aecd3131691a02cc5ef /assembly | |
| parent | 8099b08dfb2f140d527df684044da3274106e787 (diff) | |
Add Unzip node
Diffstat (limited to 'assembly')
| -rw-r--r-- | assembly/index.ts | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/assembly/index.ts b/assembly/index.ts index fd4fdd5..7af2896 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -285,6 +285,15 @@ export function intersperse(a: StaticArray<f32>, b: StaticArray<f32>): StaticArr return out; } +export function unzip(x: StaticArray<f32>): StaticArray<f32> { + const out = new StaticArray<f32>(x.length); + for (let i = 0; i < x.length/2; i++) { + out[i] = x[i*2]; + out[i + x.length/2] = x[i*2+1]; + } + return out; +} + export function dft(x: StaticArray<f32>): StaticArray<f32> { const out = new StaticArray<f32>(x.length); for (let k = 0; k < out.length - out.length % 2; k += 2) { @@ -292,8 +301,8 @@ export function dft(x: StaticArray<f32>): StaticArray<f32> { const y = -<f32>2.0 * Mathf.PI * <f32>k / <f32>x.length * <f32>n; const u = Mathf.cos(y); const v = Mathf.sin(y); - out[k] = x[n] * u - x[n+1] * v; - out[k+1] = x[n] * v + x[n+1] * u; + out[k] += x[n] * u - x[n+1] * v; + out[k+1] += x[n] * v + x[n+1] * u; } } return out; |
