ComfyUI Extension: More Math

Authored by mcDandy

Created

Updated

0 stars

Adds math nodes for numbers and types which do not need it.

Custom Nodes (0)

    README

    More Math

    Adds math nodes for numbers and types which do not need it. I got inspired by was_extras node.

    #WARNING This node is not compatible to ComfyUI-Impact-Pack which forces older antlr version.

    Quickstart

    1. Install ComfyUI.
    2. Clone this repository into ComfyUI/custom_nodes.
    3. Restart ComfyUI.

    Features

    • expression parsing with support for functions and variables:
      • functions:
        • run expressions on both components of CONDITIONING (not that I know what they do), LATENT, IMAGE, NOISE and FLOAT
        • math operators (binary and unary +,- and ^,*,/,%)
        • sin, cos, tan
        • asin, acos, atan (can produce NaN outside range -1...1)
        • atan2 (x,y)
        • sinh, cosh, tanh (can produce NaN outside range -1...1)
        • asinh, acosh, atanh
        • abs, sqrt (produces NaN on negative numbers), ln (log with base e), log (base 10), exp, pow
        • smin, tmin, smax, tmax, tnorm, snorm (norm and t prefixed are not applicable on float math node)
          • s prefixed return one number
          • t prefixed work element-wise
        • floor, ceil, round, gamma, clamp, sigm (sigmoid)
      • variables
        • a, b, c, d : inputs of type based on node
        • w, x, y, z : each node allows use of 4 additional floats
        • W : Width of tensor - does not work on FLOAT and CONDITIONING
        • H : Height of tensor - does not work on FLOAT and CONDITIONING
        • C : Channel of tensor - used as color chanel in IMAGE or as information channel in others. does not work on FLOAT and CONDITIONING
        • B : Batch - does not work on FLOAT and CONDITIONING
        • X : X position in tensor - does not work on FLOAT and CONDITIONING
        • Y : Y position in tensor - does not work on FLOAT and CONDITIONING
        • I : Tensor used to initalise sampler before noise injection - usually zeroed out and generated by Empty Latent Image node - Exclusive for NOISE
      • use constant e a pi

    Develop

    To install the dev dependencies and pre-commit (will run the ruff hook), do:

    cd more_math
    pip install -e .[dev]
    pre-commit install
    

    The -e flag above will result in a "live" install, in the sense that any changes you make to your node extension will automatically be picked up the next time you run ComfyUI.

    Publish to Github

    Tests

    This repo contains unit tests written in Pytest in the tests/ directory. It is recommended to unit test your custom node.

    Publishing to Registry

    If you wish to share this custom node with others in the community, you can publish it to the registry. We've already auto-populated some fields in pyproject.toml under tool.comfy, but please double-check that they are correct.

    You need to make an account on https://registry.comfy.org and create an API key token.

    • [ ] Go to the registry. Login and create a publisher id (everything after the @ sign on your registry profile).
    • [ ] Add the publisher id into the pyproject.toml file.
    • [ ] Create an api key on the Registry for publishing from Github. Instructions.
    • [ ] Add it to your Github Repository Secrets as REGISTRY_ACCESS_TOKEN.

    A Github action will run on every git push. You can also run the Github action manually. Full instructions here. Join our discord if you have any questions!