diff options
| author | Sam Nystrom <sam@samnystrom.dev> | 2024-03-06 20:52:45 +0000 |
|---|---|---|
| committer | Sam Nystrom <15555332-SamNystrom1@users.noreply.replit.com> | 2024-03-06 20:52:45 +0000 |
| commit | ac83dd4a08bdbab6df270d6dae8d9e2d6d619342 (patch) | |
| tree | d928f552d7fb89a96b757b00899d4dbc0639cacd /assembly | |
init
Diffstat (limited to 'assembly')
| -rw-r--r-- | assembly/index.ts | 41 | ||||
| -rw-r--r-- | assembly/tsconfig.json | 6 |
2 files changed, 47 insertions, 0 deletions
diff --git a/assembly/index.ts b/assembly/index.ts new file mode 100644 index 0000000..cba8926 --- /dev/null +++ b/assembly/index.ts @@ -0,0 +1,41 @@ + +export function linspace(start: f64, stop: f64, n: i32): Float64Array { + const out = new Float64Array(n); + for (let i = 0; i < n; i++) { + out[i] = start + (stop - start) * <f64>i / <f64>(n-1); + } + return out; +} + +export function intersperse(a: Float64Array, b: Float64Array): Float64Array { + const len = a.length < b.length ? a.length : b.length; + const out = new Float64Array(len * 2); + for (let i = 0; i < out.length / 2; i++) { + out[i*2] = a[i]; + out[i*2+1] = b[i]; + } + return out; +} + +export function dft(x: Float64Array): Float64Array { + const out = new Float64Array(x.length); + for (let k = 0; k < out.length - out.length % 2; k += 2) { + for (let n = 0; n < x.length - x.length % 2; n += 2) { + const y = -2.0 * Math.PI * <f64>k / <f64>x.length * <f64>n; + const u = Math.cos(y); + const v = Math.sin(y); + out[k] = x[n] * u - x[n+1] * v; + out[k+1] = x[n] * v + x[n+1] * u; + } + } + return out; +} + +export function fft(x: Float64Array): Float64Array { + //const out = new Float64Array(x.length); + return dft(x); +} + +export function add(a: i32, b: i32): i32 { + return a + b; +} diff --git a/assembly/tsconfig.json b/assembly/tsconfig.json new file mode 100644 index 0000000..e28fcf2 --- /dev/null +++ b/assembly/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "assemblyscript/std/assembly.json", + "include": [ + "./**/*.ts" + ] +}
\ No newline at end of file |
