Math Expression Node Documentation
Overview
The Math Expression node, known as "MathExpression|pysssss" within the ComfyUI-Custom-Scripts repository, is a versatile tool designed for evaluating complex mathematical expressions using values from a ComfyUI graph. This node provides users the ability to perform various mathematical operations on multiple input types, enriching the functionality and flexibility of workflows in ComfyUI.
Features
- Expression Evaluation: This node evaluates mathematical expressions using an array of arithmetic operators and functions.
- Input Type Support: It supports diverse input types, including integers, floats, images, and latent values.
- Output: The output of this node is provided as both integer and float data types.
- Referencing Values: Users can reference values from other nodes by their name, making this component highly integrative within complex workflows.
- Supported Operations and Functions: A range of operations and functions, such as addition, subtraction, multiplication, division, and others like power, random integer generation, and ceiling/floor operations, are supported.
Inputs
The Math Expression node accepts the following inputs:
-
Expression: A string input where users can define the mathematical expression they wish to evaluate. This input supports multiline expressions and includes an autocomplete feature for quicker function insertion.
-
Optional Inputs:
a
, b
, c
: These inputs are placeholders for various data types (like integers, floats, images, and latents) that can be used in the defined expression. Users may choose which values to input based on their specific needs and graph setup.
-
Hidden Inputs:
- This node uses hidden data from ComfyUI concerning PNG metadata (
extra_pnginfo
) and prompt descriptions, which help in advanced expression evaluation by referencing other nodes.
Outputs
The Math Expression node generates the following outputs:
- Integer: The evaluated result of the expression as an integer.
- Float: The evaluated result of the expression as a float.
These outputs can be leveraged in further processing within the ComfyUI workflow, allowing the results of mathematical computations to influence subsequent operations.
Usage in ComfyUI Workflows
The Math Expression node can be used in a variety of scenarios within ComfyUI workflows:
- Dynamic Processing: Users can compute dynamic values based on input parameters, which can be passed to other nodes in the graph for further processing.
- Image and Latent Manipulation: By evaluating expressions that rely on image or latent dimensions (e.g., width and height), users gain fine control over how images are manipulated or resized in later stages.
- Conditional Workflows: Through the use of functions like
iif
(if-then-else), the node can drive logic-based decision-making processes directly in the workflow.
- Randomized Output: Incorporating random functions allows the creation of workflows with variability, potentially useful in generating randomized artistic outputs or conducting probabilistic analyses.
Special Features and Considerations
- Autocomplete and Syntax Highlighting: The expression input field supports autocomplete to aid in writing complex expressions and includes syntax hints for functions.
- Operator and Function Support: It supports a wide array of operators (
+
, -
, *
, /
, etc.) and functions including round
, ceil
, floor
, sqrt
, random
, and comparison operations.
- Referencing Other Nodes: Users can dynamically reference and incorporate values from other nodes, providing flexibility and interconnectivity within the workflow.
- Handling Complex Types: When dealing with complex types like images or latents, dimensions can be explicitly referenced using
.width
and .height
.
- Random and Conditional Expressions: The inclusion of random and conditional functions allows users to create highly dynamic and adaptive workflows.
It's important for users to carefully craft expressions and verify node interconnections to ensure intended outcomes, especially when manipulating or referencing diverse data types and nodes from within the workflow.