From 41213e45761fc1dd795d462ad7bc719533efd09e Mon Sep 17 00:00:00 2001 From: Sam Nystrom Date: Fri, 8 Mar 2024 14:52:06 +0000 Subject: Add Unzip node --- src/nodes/Unzip.tsx | 30 ++++++++++++++++++++++++++++++ src/nodes/index.ts | 4 ++++ src/wasm.ts | 1 + 3 files changed, 35 insertions(+) create mode 100644 src/nodes/Unzip.tsx (limited to 'src') diff --git a/src/nodes/Unzip.tsx b/src/nodes/Unzip.tsx new file mode 100644 index 0000000..ff5832d --- /dev/null +++ b/src/nodes/Unzip.tsx @@ -0,0 +1,30 @@ +import { NodeShell, InputArray, OutputNumber, NodeComponentProps, NodeInfo } from '../node.tsx'; +import { unzip } from '../wasm.ts'; + +export interface UnzipInputs { + data: Float32Array, +} + +export interface UnzipOutputs { + a: Float32Array, + b: Float32Array, +} + +export const Unzip = ({ id, x, y, inputs }: NodeComponentProps) => { + return ( + + + + + + ); +}; + +export const UnzipNode: NodeInfo = { + component: Unzip, + func: ({ data }) => { + const out = data ? unzip(data) : null; + return { a: out?.slice(0, out.length/2), b: out?.slice(out.length/2) }; + }, + inputs: { data: null }, +}; \ No newline at end of file diff --git a/src/nodes/index.ts b/src/nodes/index.ts index a5678fa..09310bb 100644 --- a/src/nodes/index.ts +++ b/src/nodes/index.ts @@ -5,9 +5,12 @@ import { ViewerNode } from './Viewer.tsx'; import { FourierNode } from './Fourier.tsx'; import { LinspaceNode } from './Linspace.tsx'; import { IntersperseNode } from './Intersperse.tsx'; +import { UnzipNode } from './Unzip.tsx'; import { MathNode } from './Math.tsx'; import { PlotNode } from './Plot.tsx'; +// TODO: ComplexMath + const nodeRegistry: Record> = { 'Combine XYZ': CombineXYZNode, 'Separate XYZ': SeparateXYZNode, @@ -15,6 +18,7 @@ const nodeRegistry: Record> = { 'Fourier Transform': FourierNode, 'Linspace': LinspaceNode, 'Intersperse': IntersperseNode, + 'Unzip': UnzipNode, 'Math': MathNode, 'Plot': PlotNode, } diff --git a/src/wasm.ts b/src/wasm.ts index 311a088..a62a8fc 100644 --- a/src/wasm.ts +++ b/src/wasm.ts @@ -5,6 +5,7 @@ export const { mathS, mathV, mathSS, mathSV, mathVS, mathVV, linspace, intersperse, + unzip, dft, fft, } = await instantiate(await WebAssembly.compileStreaming(fetch(url)), {}); \ No newline at end of file -- cgit v1.2.3