Skip to content

Commit 4ac582c

Browse files
committed
fix + node conversion
Fix conditioning not knowing about Float inputs; Convert VideoMathNode to new format
1 parent 5a801ec commit 4ac582c

File tree

8 files changed

+338
-166
lines changed

8 files changed

+338
-166
lines changed

more_math/ConditioningMathNode.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def check_lazy_status(cls, Expression,Expression_pi, V, F, length_mismatch="tile
4848
stream = CommonTokenStream(lexer)
4949
stream.fill()
5050

51-
input_stream = InputStream(Expression)
51+
input_stream = InputStream(Expression_pi)
5252
lexer = MathExprLexer(input_stream)
5353
stream1 = CommonTokenStream(lexer)
5454
stream1.fill()
@@ -131,6 +131,9 @@ def execute(cls, V, F, Expression, Expression_pi, length_mismatch="tile"):
131131
"batch_count": a.shape[0],
132132
} | generate_dim_variables(a) | V_norm_tensors
133133

134+
for k, val in F.items():
135+
variables[k] = val if val is not None else 0.0
136+
134137
# Execute Expression (Main Tensor)
135138
tree = parse_expr(Expression)
136139
visitor = UnifiedMathVisitor(variables, a.shape, state_storage=ss)

more_math/ImageMathNode.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ class ImageMathNode(io.ComfyNode):
1919
@classmethod
2020
def define_schema(cls) -> io.Schema:
2121
return io.Schema(
22-
node_id="mrmth_ag_ImageMathNode", # New ID to avoid collision if necessary, or keep standard and user migrates? User asked to "switch", likely implies replacing functionality but maybe keeping ID? Usually replacing ID breaks workflows.
23-
# Strategy: Use a NEW ID for the autogrow version if we want to allow side-by-side, but typically "Autogrow switch" implies replacing the main node.
24-
# However, standard ComfyUI practice for breaking changes is often a new node or careful migration.
25-
# Looking at AudioMathNode in step 6, it used "mrmth_ag_AudioMathNode".
26-
# I will follow that pattern: mrmth_ag_ImageMathNode.
22+
node_id="mrmth_ag_ImageMathNode",
2723
category="More math",
2824
display_name="Image math",
2925
inputs=[
@@ -75,7 +71,7 @@ def check_lazy_status(cls, Expression, V, F, length_mismatch="tile"):
7571
return needed1
7672

7773
@classmethod
78-
def execute(cls, V, F, Expression, length_mismatch="tile"):
74+
def execute(cls, V, F, Expression, length_mismatch="error"):
7975
# I and F are Autogrow.Type which is dict[str, Any]
8076

8177
# Identify all present tensors and their keys

more_math/ModelMathNode.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,9 @@ def execute(cls, V, F, Expression, length_mismatch="tile") -> io.NodeOutput:
8181
if a is None:
8282
raise ValueError("At least one input model is required.")
8383

84-
# Prepare variables
85-
# V0..V3 map to a..d for backward compatibility in calculate_patches
86-
87-
# Note: calculate_patches usually takes specific args. We might need to update it to support dynamic V/F or just pass everything.
88-
# Looking at Step 34, calculate_patches signature: (Model, a, b, c, d, w, x, y, z)
89-
# We need to verify if calculate_patches handles V/F. It probably doesn't.
90-
# We should check 'modelLikeCommon.py' to see if update is needed.
91-
92-
# Assume for now we pass a,b,c,d,w,x,y,z as standard.
93-
# But for full autogrow support (more than 4 inputs), calculate_patches needs update.
94-
# The prompt didn't explicitly ask to update modelLikeCommon, but "switch to Autogrow" implies full functionality.
95-
# I'll check modelLikeCommon.py after this block.
96-
# For now, I will pass V and F to calculate_patches if I modify it, or I will stick to legacy args if I don't modify it.
97-
# However, to support V4+, I MUST modify calculate_patches.
98-
99-
# Let's pass the V and F dicts to a modified calculate_patches, or overload it.
100-
# I will update modelLikeCommon.py as part of this task.
10184

10285
from .modelLikeCommon import calculate_patches_autogrow
10386

104-
# Map inputs to patchers if needed (Model.Input gives Model wrapper, need state_dict source?)
105-
# ModelMathNode inputs are Model wrappers (comfy.model_patcher.ModelPatcher).
106-
# So V items are ready to be used.
10787

10888
aliases = {"a": "V0", "b": "V1", "c": "V2", "d": "V3", "w": "F0", "x": "F1", "y": "F2", "z": "F3"}
10989
patches = calculate_patches_autogrow(Expression, V=V, F=F, mapping=aliases)

more_math/Parser/UnifiedMathVisitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def visitVariableExp(self, ctx):
162162
return float(self.depth)
163163
if var_name in self.variables:
164164
return self.variables[var_name]
165-
raise ValueError(f"Variable '{var_name}' not found")
165+
raise ValueError(f"line {ctx.VARIABLE().getPayload().line}:{ctx.VARIABLE().getPayload().column}: Variable '{var_name}' not found")
166166

167167
def visitListExp(self, ctx):
168168
res = []

0 commit comments

Comments
 (0)