From 4d3cc9d6ee2772489edd8cf9565d1b61ce0e1f1a Mon Sep 17 00:00:00 2001 From: mcDandy Date: Mon, 12 Jan 2026 14:56:37 +0100 Subject: [PATCH] fix commonLazy missing w,x,y,z and remove MathNodeBase --- more_math/AudioMathNode.py | 12 +++---- more_math/ClipMathNode.py | 4 +-- more_math/ConditioningMathNode.py | 12 +++---- more_math/FloatMathNode.py | 4 +-- more_math/ImageMathNode.py | 13 ++++--- more_math/LatentMathNode.py | 8 +++-- more_math/MaskMathNode.py | 11 +++--- more_math/MathNodeBase.py | 58 ------------------------------- more_math/ModelMathNode.py | 4 +-- more_math/NoiseMathNode.py | 4 +-- more_math/VaeMathNode.py | 4 +-- more_math/VideoMathNode.py | 14 ++++---- more_math/helper_functions.py | 12 ++++++- 13 files changed, 57 insertions(+), 103 deletions(-) delete mode 100644 more_math/MathNodeBase.py diff --git a/more_math/AudioMathNode.py b/more_math/AudioMathNode.py index e810bcb..41169cf 100644 --- a/more_math/AudioMathNode.py +++ b/more_math/AudioMathNode.py @@ -1,13 +1,10 @@ import torch -from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, as_tensor +from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, as_tensor, prepare_inputs, commonLazy from comfy_api.latest import io -from .MathNodeBase import MathNodeBase - - -class AudioMathNode(MathNodeBase): +class AudioMathNode(io.ComfyNode): """ Enables math expressions on Audio tensors. @@ -41,13 +38,16 @@ class AudioMathNode(MathNodeBase): io.Audio.Output(), ], ) + @classmethod + def check_lazy_status(cls, AudioExpr, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0): + return commonLazy(AudioExpr, a, b, c, d, w, x, y, z) @classmethod def execute(cls, AudioExpr, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0): av = a["waveform"] sample_rate = a["sample_rate"] - a, b, c, d = cls.prepare_inputs(a, b, c, d) + a, b, c, d = prepare_inputs(a, b, c, d) bv, cv, dv = b["waveform"], c["waveform"], d["waveform"] diff --git a/more_math/ClipMathNode.py b/more_math/ClipMathNode.py index 7803cb3..075da58 100644 --- a/more_math/ClipMathNode.py +++ b/more_math/ClipMathNode.py @@ -1,7 +1,7 @@ from comfy_api.latest import io from .modelLikeCommon import calculate_patches from inspect import cleandoc -from .helper_functions import comonLazy +from .helper_functions import commonLazy class CLIPMathNode(io.ComfyNode): @@ -35,7 +35,7 @@ class CLIPMathNode(io.ComfyNode): @classmethod def check_lazy_status(cls, Model, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0): - return comonLazy(Model, a, b, c, d, w, x, y, z) + return commonLazy(Model, a, b, c, d, w, x, y, z) @classmethod def execute(cls, Model, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0) -> io.NodeOutput: diff --git a/more_math/ConditioningMathNode.py b/more_math/ConditioningMathNode.py index cbfccf4..5082d3e 100644 --- a/more_math/ConditioningMathNode.py +++ b/more_math/ConditioningMathNode.py @@ -1,14 +1,12 @@ from inspect import cleandoc -from .helper_functions import comonLazy, eval_tensor_expr, generate_dim_variables, as_tensor +from .helper_functions import commonLazy, eval_tensor_expr, generate_dim_variables, as_tensor, prepare_inputs from comfy_api.latest import io -from .MathNodeBase import MathNodeBase - -class ConditioningMathNode(MathNodeBase): +class ConditioningMathNode(io.ComfyNode): """ Enables math operations on conditionings. @@ -51,14 +49,14 @@ class ConditioningMathNode(MathNodeBase): @classmethod def check_lazy_status(cls, Tensor, pooled_output, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0): - tensor_needs = set(comonLazy(Tensor, a, b, c, d)) - pooled_needs = set(comonLazy(pooled_output, a, b, c, d)) + tensor_needs = set(commonLazy(Tensor, a, b, c, d, w, x, y, z)) + pooled_needs = set(commonLazy(pooled_output, a, b, c, d, w, x, y, z)) return list(tensor_needs.union(pooled_needs)) @classmethod def execute(cls, Tensor, pooled_output, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0): # Default missing conditionings to zero - a, b, c, d = cls.prepare_inputs(a, b, c, d) + a, b, c, d = prepare_inputs(a, b, c, d) # Extract tensors ta, tb, tc, td = a[0][0], b[0][0], c[0][0], d[0][0] diff --git a/more_math/FloatMathNode.py b/more_math/FloatMathNode.py index ceab24f..bfd1584 100644 --- a/more_math/FloatMathNode.py +++ b/more_math/FloatMathNode.py @@ -1,6 +1,6 @@ from inspect import cleandoc -from .helper_functions import comonLazy, eval_float_expr +from .helper_functions import commonLazy, eval_float_expr from comfy_api.latest import io @@ -46,7 +46,7 @@ class FloatMathNode(io.ComfyNode): @classmethod def check_lazy_status(cls, FloatFunc, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0): - return comonLazy(FloatFunc, a, b, c, d) + return commonLazy(FloatFunc, a, b, c, d, w, x, y, z) @classmethod def execute(cls, FloatFunc, a, b=0.0, c=0.0, d=0.0, w=0.0, x=0.0, y=0.0, z=0.0): diff --git a/more_math/ImageMathNode.py b/more_math/ImageMathNode.py index 688ec20..4586028 100644 --- a/more_math/ImageMathNode.py +++ b/more_math/ImageMathNode.py @@ -1,12 +1,9 @@ -from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, as_tensor +from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, as_tensor,prepare_inputs,commonLazy from comfy_api.latest import io -from .MathNodeBase import MathNodeBase - - -class ImageMathNode(MathNodeBase): +class ImageMathNode(io.ComfyNode): """ Enables math expressions on Images. @@ -40,10 +37,12 @@ class ImageMathNode(MathNodeBase): io.Image.Output(), ], ) - + @classmethod + def check_lazy_status(cls, Image, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0): + return commonLazy(Image, a, b, c, d, w, x, y, z) @classmethod def execute(cls, Image, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0): - a, b, c, d = cls.prepare_inputs(a, b, c, d) + a, b, c, d = prepare_inputs(a, b, c, d) variables = { "a": a, diff --git a/more_math/LatentMathNode.py b/more_math/LatentMathNode.py index 08327a1..126e09e 100644 --- a/more_math/LatentMathNode.py +++ b/more_math/LatentMathNode.py @@ -10,10 +10,10 @@ from .helper_functions import ( make_zero_like, as_tensor, ) -from .MathNodeBase import MathNodeBase +from .helper_functions import commonLazy -class LatentMathNode(MathNodeBase): +class LatentMathNode(io.ComfyNode): """ This node enables the use of math expressions on Latents. inputs: @@ -58,6 +58,10 @@ class LatentMathNode(MathNodeBase): # RETURN_NAMES = ("image_output_name",) tooltip = cleandoc(__doc__) + @classmethod + def check_lazy_status(cls, Latent, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0): + return commonLazy(Latent, a, b, c, d, w, x, y, z) + # OUTPUT_NODE = False # OUTPUT_TOOLTIPS = ("",) # Tooltips for the output node @classmethod diff --git a/more_math/MaskMathNode.py b/more_math/MaskMathNode.py index 808c61c..7adb278 100644 --- a/more_math/MaskMathNode.py +++ b/more_math/MaskMathNode.py @@ -1,12 +1,9 @@ -from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, as_tensor +from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, as_tensor,commonLazy from comfy_api.latest import io -from .MathNodeBase import MathNodeBase - - -class MaskMathNode(MathNodeBase): +class MaskMathNode(io.ComfyNode): """ Enables math expressions on Images. @@ -40,7 +37,9 @@ class MaskMathNode(MathNodeBase): io.Mask.Output(), ], ) - + @classmethod + def check_lazy_status(cls, Mask, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0): + return commonLazy(Mask, a, b, c, d, w, x, y, z) @classmethod def execute(cls, Mask, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0): a, b, c, d = cls.prepare_inputs(a, b, c, d) diff --git a/more_math/MathNodeBase.py b/more_math/MathNodeBase.py deleted file mode 100644 index ff10267..0000000 --- a/more_math/MathNodeBase.py +++ /dev/null @@ -1,58 +0,0 @@ -from comfy_api.latest import io -from .helper_functions import comonLazy, make_zero_like - - -class MathNodeBase(io.ComfyNode): - """ - Base class for More Math nodes providing common utilities. - """ - - @classmethod - def check_lazy_status(cls, **kwargs): - """ - Generic check_lazy_status implementation. - Finds the first argument name that isn't a known variable (a-d, w-z) and assumes it's the expression. - """ - # Known variable inputs (and internal ones we might ignore) - known_vars = {"a", "b", "c", "d", "w", "x", "y", "z", "pooled_output"} - - # Heuristic: The expression is usually the first argument that is not a known variable. - # But `comonLazy` takes (expr, a, b, c, d, w, x, y, z). - # We need to extract the values from kwargs correctly. - - expr_key = None - # Try finding the expression key - for k in kwargs: - if k not in known_vars and isinstance(kwargs[k], str): - expr_key = k - break - - # If we can't find it heuristically (e.g. standard naming), fallback or error? - # Let's try to be safe. If we can't find it, we might be in a node with custom logic like ConditioningMathNode. - # ConditioningMathNode has 'Tensor' and 'pooled_output' as expressions. - - if expr_key: - expr = kwargs[expr_key] - a = kwargs.get("a", None) - b = kwargs.get("b", []) - c = kwargs.get("c", []) - d = kwargs.get("d", []) - w = kwargs.get("w", 0) - x = kwargs.get("x", 0) - y = kwargs.get("y", 0) - z = kwargs.get("z", 0) - return comonLazy(expr, a, b, c, d, w, x, y, z) - - # Fallback/Empty return if we can't determine dependencies automatically - return [] - - @staticmethod - def prepare_inputs(a, b, c, d): - """ - Ensures optional inputs b, c, d are zero-initialized like a if None. - Returns the prepared (a, b, c, d). - """ - b = b if b is not None else make_zero_like(a) - c = c if c is not None else make_zero_like(a) - d = d if d is not None else make_zero_like(a) - return a, b, c, d diff --git a/more_math/ModelMathNode.py b/more_math/ModelMathNode.py index abe76fa..cb54a30 100644 --- a/more_math/ModelMathNode.py +++ b/more_math/ModelMathNode.py @@ -1,6 +1,6 @@ from inspect import cleandoc from comfy_api.latest import io -from .helper_functions import comonLazy +from .helper_functions import commonLazy from .modelLikeCommon import calculate_patches @@ -36,7 +36,7 @@ class ModelMathNode(io.ComfyNode): @classmethod def check_lazy_status(cls, Model, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0): - return comonLazy(Model, a, b, c, d, w, x, y, z) + return commonLazy(Model, a, b, c, d, w, x, y, z) @classmethod def execute(cls, Model, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0) -> io.NodeOutput: diff --git a/more_math/NoiseMathNode.py b/more_math/NoiseMathNode.py index 453e97e..2aac9ea 100644 --- a/more_math/NoiseMathNode.py +++ b/more_math/NoiseMathNode.py @@ -5,7 +5,7 @@ import torch from .helper_functions import ( generate_dim_variables, getIndexTensorAlongDim, - comonLazy, + commonLazy, parse_expr, eval_tensor_expr_with_tree, make_zero_like, @@ -68,7 +68,7 @@ class NoiseMathNode(io.ComfyNode): @classmethod def check_lazy_status(cls, Noise, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0): - return comonLazy(Noise, a, b, c, d, w, x, y, z) + return commonLazy(Noise, a, b, c, d, w, x, y, z) @classmethod def execute(cls, Noise, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0): diff --git a/more_math/VaeMathNode.py b/more_math/VaeMathNode.py index a84670d..abb4e75 100644 --- a/more_math/VaeMathNode.py +++ b/more_math/VaeMathNode.py @@ -2,7 +2,7 @@ from inspect import cleandoc from comfy_api.latest import io import copy from .modelLikeCommon import calculate_patches -from .helper_functions import comonLazy +from .helper_functions import commonLazy class VAEMathNode(io.ComfyNode): @@ -36,7 +36,7 @@ class VAEMathNode(io.ComfyNode): @classmethod def check_lazy_status(cls, Model, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0): - return comonLazy(Model, a, b, c, d, w, x, y, z) + return commonLazy(Model, a, b, c, d, w, x, y, z) @classmethod def execute(cls, Model, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0) -> io.NodeOutput: diff --git a/more_math/VideoMathNode.py b/more_math/VideoMathNode.py index 4479458..70529c0 100644 --- a/more_math/VideoMathNode.py +++ b/more_math/VideoMathNode.py @@ -5,13 +5,9 @@ from comfy_api.input_impl import VideoFromComponents from comfy_api.util import VideoComponents -from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, make_zero_like +from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, make_zero_like, commonLazy - -from .MathNodeBase import MathNodeBase - - -class VideoMathNode(MathNodeBase): +class VideoMathNode(io.ComfyNode): """ Enables math expressions on Video (images + audio). @@ -50,6 +46,12 @@ class VideoMathNode(MathNodeBase): tooltip = cleandoc(__doc__) + @classmethod + def check_lazy_status(cls, Audio, Images, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0): + tensor_needs = set(commonLazy(Audio, a, b, c, d, w, x, y, z)) + pooled_needs = set(commonLazy(Images, a, b, c, d, w, x, y, z)) + return list(tensor_needs.union(pooled_needs)) + @classmethod def execute(cls, Audio, Images, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0) -> io.NodeOutput: ac = a.get_components() diff --git a/more_math/helper_functions.py b/more_math/helper_functions.py index 128dbba..9c7347f 100644 --- a/more_math/helper_functions.py +++ b/more_math/helper_functions.py @@ -77,7 +77,7 @@ def getIndexTensorAlongDim(tensor, dim): return values.expand(*shape) -def comonLazy(expr, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0): +def commonLazy(expr, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0): """Determine which lazy inputs are needed based on expression variables.""" variables = {"a": a, "b": b, "c": c, "d": d, "w": w, "x": x, "y": y, "z": z} need_eval = [] @@ -99,6 +99,16 @@ def generate_dim_variables(tensor: torch.Tensor): variables[f"S{dim}"] = torch.full(tensor.shape, fill_value=size, dtype=torch.float32, device=tensor.device) return variables +@staticmethod +def prepare_inputs(a, b, c, d): + """ + Ensures optional inputs b, c, d are zero-initialized like a if None. + Returns the prepared (a, b, c, d). + """ + b = b if b is not None else make_zero_like(a) + c = c if c is not None else make_zero_like(a) + d = d if d is not None else make_zero_like(a) + return a, b, c, d def make_zero_like(ref): """