ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

[Feature Request] Ability to do basic math functions; math nodes

Open jhancuff opened this issue 1 year ago • 4 comments

Would like nodes that enable some basic math functions as well as exponential and square root functions. Additionally, a float slider would not go unnoticed. :)

jhancuff avatar Jul 11 '23 16:07 jhancuff

I posted this https://github.com/comfyanonymous/ComfyUI/discussions/853 a few days ago too as it would be useful.

Other nodes like conditional loops would be nice. I was currently attempting to create such node but can't seem to get something to work.

class LoopLatentTest:
    def __init__(self):
        self.int_loop = 1000000
    
    @classmethod
    def INPUT_TYPES(s):
        return {
            "optional": {
                "latent1": ("LATENT",),
                "latent2": ("LATENT",)
            },
            "required": {
                "int_field": ("INT", {
                    "default": 20, 
                    "min": 0,
                    "max": 100,
                    "step": 1
                }),
            },
        }

    RETURN_TYPES = ("LATENT", "LATENT")
    RETURN_NAMES = ("latent_output_1", "latent_output_2")

    FUNCTION = "split_latent"

    CATEGORY = "Latent Processing"

    def split_latent(self, int_field, latent1=False, latent2=False):
        if self.int_loop == 1000000:
            self.int_loop = int_field
        
        latent = latent1 if latent1 else latent2

        if self.int_loop > 0:
            return (latent, None)
        else:
            return (None, latent)
        self.int_loop-=1
        
        
NODE_CLASS_MAPPINGS = {
    "SplitLatent": SplitLatent
}

NODE_DISPLAY_NAME_MAPPINGS = {
    "SplitLatent": "Split Latent Node"
}

Extraltodeus avatar Jul 11 '23 17:07 Extraltodeus

Some of this functionality exists in custom nodes, no loop nodes tho i dont think.

Ferniclestix avatar Jul 12 '23 05:07 Ferniclestix

You actually can not have a simple INT input as far as I have tested. INT is used to create sliders with the custom nodes.

And as for loops it seems that somethings tests the workflow at the beginning and does not take any potential variable into account which throws an error about too many loops or something (I'm not in front of it right now).

Extraltodeus avatar Jul 12 '23 18:07 Extraltodeus

Derfuu has some Math nodes: https://github.com/Derfuu/Derfuu_ComfyUI_ModdedNodes I don't personally use it, so I don't know much about the state of the project.

I'm also working on a custom node library that will be focused on math nodes, but it's not ready for release yet.

evanspearman avatar Jul 12 '23 21:07 evanspearman