mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-15 13:02:35 +08:00
Add Boolean support to math expressions
This commit is contained in:
parent
d113d1cc32
commit
43f2440972
@ -63,7 +63,7 @@ class MathExpressionNode(io.ComfyNode):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def define_schema(cls) -> io.Schema:
|
def define_schema(cls) -> io.Schema:
|
||||||
autogrow = io.Autogrow.TemplateNames(
|
autogrow = io.Autogrow.TemplateNames(
|
||||||
input=io.MultiType.Input("value", [io.Float, io.Int]),
|
input=io.MultiType.Input("value", [io.Float, io.Int, io.Boolean]),
|
||||||
names=list(string.ascii_lowercase),
|
names=list(string.ascii_lowercase),
|
||||||
min=1,
|
min=1,
|
||||||
)
|
)
|
||||||
@ -82,6 +82,7 @@ class MathExpressionNode(io.ComfyNode):
|
|||||||
outputs=[
|
outputs=[
|
||||||
io.Float.Output(display_name="FLOAT"),
|
io.Float.Output(display_name="FLOAT"),
|
||||||
io.Int.Output(display_name="INT"),
|
io.Int.Output(display_name="INT"),
|
||||||
|
io.Boolean.Output(display_name="BOOL"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ class MathExpressionNode(io.ComfyNode):
|
|||||||
|
|
||||||
result = simple_eval(expression, names=context, functions=MATH_FUNCTIONS)
|
result = simple_eval(expression, names=context, functions=MATH_FUNCTIONS)
|
||||||
# bool check must come first because bool is a subclass of int in Python
|
# bool check must come first because bool is a subclass of int in Python
|
||||||
if isinstance(result, bool) or not isinstance(result, (int, float)):
|
if not isinstance(result, (int, float)):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Math Expression '{expression}' must evaluate to a numeric result, "
|
f"Math Expression '{expression}' must evaluate to a numeric result, "
|
||||||
f"got {type(result).__name__}: {result!r}"
|
f"got {type(result).__name__}: {result!r}"
|
||||||
@ -106,7 +107,7 @@ class MathExpressionNode(io.ComfyNode):
|
|||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Math Expression '{expression}' produced a non-finite result: {result}"
|
f"Math Expression '{expression}' produced a non-finite result: {result}"
|
||||||
)
|
)
|
||||||
return io.NodeOutput(float(result), int(result))
|
return io.NodeOutput(float(result), int(result), bool(result))
|
||||||
|
|
||||||
|
|
||||||
class MathExtension(ComfyExtension):
|
class MathExtension(ComfyExtension):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user