From 8035b267508333a18622a2a20a1c269c573b2287 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Fri, 5 Apr 2024 16:46:51 +0200 Subject: [PATCH] remove flatten array tests --- app/src/lib/node-registry.ts | 41 +++------------ app/src/lib/runtime-executor.ts | 89 --------------------------------- 2 files changed, 7 insertions(+), 123 deletions(-) diff --git a/app/src/lib/node-registry.ts b/app/src/lib/node-registry.ts index 0b9f4be..ded44c1 100644 --- a/app/src/lib/node-registry.ts +++ b/app/src/lib/node-registry.ts @@ -1,12 +1,6 @@ import type { NodeRegistry, NodeType } from "@nodes/types"; -function binaryArrayToNumber(binaryArray: number[]): number { - let result = 0; - for (let i = 0; i < binaryArray.length; i++) { - result = (result << 1) + binaryArray[i]; - } - return result; -} +import * as d from "plantarium-nodes-math"; const nodeTypes: NodeType[] = [ { @@ -15,7 +9,7 @@ const nodeTypes: NodeType[] = [ "value": { type: "float", value: 0.1, internal: true }, }, outputs: ["float"], - execute: ({ value }) => { return [0, 1, 0, value] } + execute: ({ value }) => { return [0, value] } }, { id: "max/plantarium/math", @@ -26,33 +20,12 @@ const nodeTypes: NodeType[] = [ }, outputs: ["float"], execute: ({ op_type, a, b }: { op_type: number, a: number, b: number }) => { - - const res = [1, 3, -1, op_type, 0, 0]; - - const bitmask = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - - console.log({ a, b }); - - if (Array.isArray(a)) { - res[4] = res.length; - res.push(...a); - bitmask[1] = 1; - console.log("A", res.length, a.length); - } else { - res[4] = a; + switch (op_type) { + case 0: return a + b; + case 1: return a - b; + case 2: return a * b; + case 3: return a / b; } - - if (Array.isArray(b)) { - res[5] = res.length; - res.push(...b); - bitmask[2] = 1; - } else { - res[5] = b; - } - - res[2] = binaryArrayToNumber(bitmask); - - return res } }, { diff --git a/app/src/lib/runtime-executor.ts b/app/src/lib/runtime-executor.ts index 1aad0f4..d61a653 100644 --- a/app/src/lib/runtime-executor.ts +++ b/app/src/lib/runtime-executor.ts @@ -1,93 +1,6 @@ import type { Graph, NodeRegistry, NodeType, RuntimeExecutor } from "@nodes/types"; -function numberToBinaryArray(number: number): number[] { - const binaryArray: number[] = []; - for (let i = 31; i >= 0; i--) { - const bit = (number >> i) & 1; - binaryArray.push(bit); - } - return binaryArray; -} - -function evaluate_node([node_type, ...args]: number[]) { - - // Float node - if (node_type === 0) { - return args[0]; - } - - console.log(args); - - // Math node - if (node_type === 1) { - if (args[0] === 0) { - return args[1] + args[2]; - } else if (args[0] === 1) { - return args[1] - args[2]; - } else if (args[0] === 2) { - return args[1] * args[1]; - } else { - return args[1] / args[2]; - } - } -} - - -function read_node(index: number, params: number[], depth = 0) { - if (depth > 20) { - throw new Error("Max depth reached"); - } - - const node_type = params[index]; - const amount_of_args = params[index + 1]; - const bitmask = params[index + 2]; - console.log("READ_NODE", index, { node_type, bitmask, amount_of_args }); - - const mask = numberToBinaryArray(bitmask); - - // there are not nodes connected to this node, lets evaluate - if (bitmask === 0) { - console.log("EVALUATE", index, params); - } - - const args = []; - - for (let i = 0; i < amount_of_args; i++) { - const isNode = mask[i] === 1; - if (isNode) { - console.log("NODE", index + 3 + i, params.slice(index + 3 + i, index + 3 + i + 5)); - args[i] = read_node(params[index + 3 + i], params, depth + 1); - } else { - args[i] = params[index + 3 + i]; - } - } - - console.log({ node_type, amount_of_args, args, bitmask }); - return evaluate_node([node_type, ...args]); - -} - -function split_params(params: number[]) { - const result = []; - let index = 0; - while (index < params.length) { - const amount_of_args = params[index + 1]; - const node_size = 3 + amount_of_args; - result.push(params.slice(index, index + node_size)); - index += node_size; - } - return result; -} - -function evaluate(params: number[]) { - console.log("PARAMS", split_params(params)); - const node = read_node(0, params); - - console.log("RESULT: ", node); - -} - export class MemoryRuntimeExecutor implements RuntimeExecutor { constructor(private registry: NodeRegistry) { } @@ -220,8 +133,6 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { // return the result of the parent of the output node const res = results[outputNode.tmp?.parents?.[0].id as number] as string - evaluate(res); - return res;