From 48387498ada155bee955225cc0eeb70b57648302 Mon Sep 17 00:00:00 2001 From: mcDandy Date: Mon, 28 Jul 2025 00:45:16 +0200 Subject: [PATCH] Forgot to rename things. Removed copy of example node. --- src/more_math/ImageMathNode.py | 10 +-- src/more_math/LatentMathNode.py | 8 +-- src/more_math/nodes - kopie.py | 118 -------------------------------- src/more_math/nodes.py | 2 + 4 files changed, 11 insertions(+), 127 deletions(-) delete mode 100644 src/more_math/nodes - kopie.py diff --git a/src/more_math/ImageMathNode.py b/src/more_math/ImageMathNode.py index e78f205..bd3755b 100644 --- a/src/more_math/ImageMathNode.py +++ b/src/more_math/ImageMathNode.py @@ -15,8 +15,8 @@ class ImageMathNode: Latent, bound to variables with the same name. Defaults to zero latent if not provided. w, x, y, z: Floats, bound to variables of the expression. Defaults to 0.0 if not provided. - Tensor expression: - String, describing expression to mix latents. Valid functions are sin, cos, tan, abs, sqrt, min, max, norm. Valid operators are +, -, *, /, ^, %. + Image expression: + String, describing expression to mix images. Valid functions are sin, cos, tan, abs, sqrt, min, max, norm. Valid operators are +, -, *, /, ^, %. Usable constants are e and pi. OUTPUTS: LATENT: @@ -35,7 +35,7 @@ class ImageMathNode: }), - "Tensor": ("STRING", { + "Image": ("STRING", { "multiline": False, #True if you want the field to look like the one on the ClipTextEncode node "default": "a*(1-w)+b*w", "description": "Describes composition of the image. Valid functions are sin,cos,tan,abs,sqrt,min,max. Valid operators are +,-,*,/,^,%" @@ -85,12 +85,12 @@ class ImageMathNode: CATEGORY = "More math" - def imgMathNode(self, Tensor, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0): + def imgMathNode(self, Image, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0): b = torch.zeros_like(a) if b is None else b c = torch.zeros_like(a) if c is None else c d = torch.zeros_like(a) if d is None else d - tokens = tokenize_expression(Tensor) + tokens = tokenize_expression(Image) parser = Parser(tokens) ast = parser.parse_expression() print(a.shape) diff --git a/src/more_math/LatentMathNode.py b/src/more_math/LatentMathNode.py index 3b1e765..6d3d243 100644 --- a/src/more_math/LatentMathNode.py +++ b/src/more_math/LatentMathNode.py @@ -15,7 +15,7 @@ class LatentMathNode: Latent, bound to variables with the same name. Defaults to zero latent if not provided. w, x, y, z: Floats, bound to variables of the expression. Defaults to 0.0 if not provided. - Tensor expression: + Latent expression: String, describing expression to mix latents. Valid functions are sin, cos, tan, abs, sqrt, min, max, norm. Valid operators are +, -, *, /, ^, %. Usable constants are e and pi. OUTPUTS: @@ -35,7 +35,7 @@ class LatentMathNode: }), - "Tensor": ("STRING", { + "Latent": ("STRING", { "multiline": False, #True if you want the field to look like the one on the ClipTextEncode node "default": "a*(1-w)+b*w", "description": "Describes composition of the image. Valid functions are sin,cos,tan,abs,sqrt,min,max. Valid operators are +,-,*,/,^,%" @@ -85,13 +85,13 @@ class LatentMathNode: CATEGORY = "More math" - def latMathNode(self, Tensor, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0): + def latMathNode(self, Latent, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0): a = a["samples"] b = torch.zeros_like(a) if b is None else b["samples"] c = torch.zeros_like(a) if c is None else c["samples"] d = torch.zeros_like(a) if d is None else d["samples"] - tokens = tokenize_expression(Tensor) + tokens = tokenize_expression(Latent) parser = Parser(tokens) ast = parser.parse_expression() print(a.shape) diff --git a/src/more_math/nodes - kopie.py b/src/more_math/nodes - kopie.py deleted file mode 100644 index fab5cff..0000000 --- a/src/more_math/nodes - kopie.py +++ /dev/null @@ -1,118 +0,0 @@ -from inspect import cleandoc -class Example: - """ - A example node - - Class methods - ------------- - INPUT_TYPES (dict): - Tell the main program input parameters of nodes. - IS_CHANGED: - optional method to control when the node is re executed. - - Attributes - ---------- - RETURN_TYPES (`tuple`): - The type of each element in the output tulple. - RETURN_NAMES (`tuple`): - Optional: The name of each output in the output tulple. - FUNCTION (`str`): - The name of the entry-point method. For example, if `FUNCTION = "execute"` then it will run Example().execute() - OUTPUT_NODE ([`bool`]): - If this node is an output node that outputs a result/image from the graph. The SaveImage node is an example. - The backend iterates on these output nodes and tries to execute all their parents if their parent graph is properly connected. - Assumed to be False if not present. - CATEGORY (`str`): - The category the node should appear in the UI. - execute(s) -> tuple || None: - The entry point method. The name of this method must be the same as the value of property `FUNCTION`. - For example, if `FUNCTION = "execute"` then this method's name must be `execute`, if `FUNCTION = "foo"` then it must be `foo`. - """ - def __init__(self): - pass - - @classmethod - def INPUT_TYPES(s): - """ - Return a dictionary which contains config for all input fields. - Some types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT". - Input types "INT", "STRING" or "FLOAT" are special values for fields on the node. - The type can be a list for selection. - - Returns: `dict`: - - Key input_fields_group (`string`): Can be either required, hidden or optional. A node class must have property `required` - - Value input_fields (`dict`): Contains input fields config: - * Key field_name (`string`): Name of a entry-point method's argument - * Value field_config (`tuple`): - + First value is a string indicate the type of field or a list for selection. - + Secound value is a config for type "INT", "STRING" or "FLOAT". - """ - return { - "required": { - "image": ("Image", { "tooltip": "This is an image"}), - "int_field": ("INT", { - "default": 0, - "min": 0, #Minimum value - "max": 4096, #Maximum value - "step": 64, #Slider's step - "display": "number" # Cosmetic only: display as "number" or "slider" - }), - "float_field": ("FLOAT", { - "default": 1.0, - "min": 0.0, - "max": 10.0, - "step": 0.01, - "round": 0.001, #The value represeting the precision to round to, will be set to the step value by default. Can be set to False to disable rounding. - "display": "number"}), - "print_to_screen": (["enable", "disable"],), - "string_field": ("STRING", { - "multiline": False, #True if you want the field to look like the one on the ClipTextEncode node - "default": "Hello World!" - }), - }, - } - - RETURN_TYPES = ("IMAGE",) - #RETURN_NAMES = ("image_output_name",) - DESCRIPTION = cleandoc(__doc__) - FUNCTION = "test" - - #OUTPUT_NODE = False - #OUTPUT_TOOLTIPS = ("",) # Tooltips for the output node - - CATEGORY = "Example" - - def test(self, image, string_field, int_field, float_field, print_to_screen): - if print_to_screen == "enable": - print(f"""Your input contains: - string_field aka input text: {string_field} - int_field: {int_field} - float_field: {float_field} - """) - #do some processing on the image, in this example I just invert it - image = 1.0 - image - return (image,) - - """ - The node will always be re executed if any of the inputs change but - this method can be used to force the node to execute again even when the inputs don't change. - You can make this node return a number or a string. This value will be compared to the one returned the last time the node was - executed, if it is different the node will be executed again. - This method is used in the core repo for the LoadImage node where they return the image hash as a string, if the image hash - changes between executions the LoadImage node is executed again. - """ - #@classmethod - #def IS_CHANGED(s, image, string_field, int_field, float_field, print_to_screen): - # return "" - - -# A dictionary that contains all nodes you want to export with their names -# NOTE: names should be globally unique -NODE_CLASS_MAPPINGS = { - "Example": Example -} - -# A dictionary that contains the friendly/humanly readable titles for the nodes -NODE_DISPLAY_NAME_MAPPINGS = { - "Example": "Example Node" -} diff --git a/src/more_math/nodes.py b/src/more_math/nodes.py index c989113..d0ab2a3 100644 --- a/src/more_math/nodes.py +++ b/src/more_math/nodes.py @@ -13,5 +13,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { "mrmth_LatentMathNode": "Latent math node", "mrmth_ImageMathNode": "Image math node", "Tensor": "Tensor expression", + "Latent": "Latent expression", + "Image": "Image expression", "pooled_output": "Pooled output tensor expression" }