Download custom_nodes/ComfyUI-Math/src/comfymath/number.py from vidfom/LTX-5: direct link, hf CLI and curl.
- Browser
- Download file 2.45 kB
-
https://huggingface.co/vidfom/LTX-5/resolve/main/custom_nodes/ComfyUI-Math/src/comfymath/number.py
- Command line
-
hf download hf://vidfom/LTX-5/custom_nodes/ComfyUI-Math/src/comfymath/number.py
-
curl -L -o number.py https://huggingface.co/vidfom/LTX-5/resolve/main/custom_nodes/ComfyUI-Math/src/comfymath/number.py
2.45 kB
| from dataclasses import dataclass | |
| from typing import Any, Callable, Mapping | |
| from .float import ( | |
| FLOAT_UNARY_OPERATIONS, | |
| FLOAT_UNARY_CONDITIONS, | |
| FLOAT_BINARY_OPERATIONS, | |
| FLOAT_BINARY_CONDITIONS, | |
| ) | |
| from .types import Number | |
| DEFAULT_NUMBER = ("NUMBER", {"default": 0.0}) | |
| class NumberUnaryOperation: | |
| def INPUT_TYPES(cls) -> Mapping[str, Any]: | |
| return { | |
| "required": { | |
| "op": (list(FLOAT_UNARY_OPERATIONS.keys()),), | |
| "a": DEFAULT_NUMBER, | |
| } | |
| } | |
| RETURN_TYPES = ("NUMBER",) | |
| FUNCTION = "op" | |
| CATEGORY = "math/number" | |
| def op(self, op: str, a: Number) -> tuple[float]: | |
| return (FLOAT_UNARY_OPERATIONS[op](float(a)),) | |
| class NumberUnaryCondition: | |
| def INPUT_TYPES(cls) -> Mapping[str, Any]: | |
| return { | |
| "required": { | |
| "op": (list(FLOAT_UNARY_CONDITIONS.keys()),), | |
| "a": DEFAULT_NUMBER, | |
| } | |
| } | |
| RETURN_TYPES = ("BOOL",) | |
| FUNCTION = "op" | |
| CATEGORY = "math/Number" | |
| def op(self, op: str, a: Number) -> tuple[bool]: | |
| return (FLOAT_UNARY_CONDITIONS[op](float(a)),) | |
| class NumberBinaryOperation: | |
| def INPUT_TYPES(cls) -> Mapping[str, Any]: | |
| return { | |
| "required": { | |
| "op": (list(FLOAT_BINARY_OPERATIONS.keys()),), | |
| "a": DEFAULT_NUMBER, | |
| "b": DEFAULT_NUMBER, | |
| } | |
| } | |
| RETURN_TYPES = ("NUMBER",) | |
| FUNCTION = "op" | |
| CATEGORY = "math/number" | |
| def op(self, op: str, a: Number, b: Number) -> tuple[float]: | |
| return (FLOAT_BINARY_OPERATIONS[op](float(a), float(b)),) | |
| class NumberBinaryCondition: | |
| def INPUT_TYPES(cls) -> Mapping[str, Any]: | |
| return { | |
| "required": { | |
| "op": (list(FLOAT_BINARY_CONDITIONS.keys()),), | |
| "a": DEFAULT_NUMBER, | |
| "b": DEFAULT_NUMBER, | |
| } | |
| } | |
| RETURN_TYPES = ("BOOL",) | |
| FUNCTION = "op" | |
| CATEGORY = "math/float" | |
| def op(self, op: str, a: Number, b: Number) -> tuple[bool]: | |
| return (FLOAT_BINARY_CONDITIONS[op](float(a), float(b)),) | |
| NODE_CLASS_MAPPINGS = { | |
| "CM_NumberUnaryOperation": NumberUnaryOperation, | |
| "CM_NumberUnaryCondition": NumberUnaryCondition, | |
| "CM_NumberBinaryOperation": NumberBinaryOperation, | |
| "CM_NumberBinaryCondition": NumberBinaryCondition, | |
| } | |