Nodes/Akatz Custom Nodes/Shrink Num Sequence | Akatz
ComfyUI Node

Shrink Num Sequence | Akatz

The schedule cleaner that keeps frame count intact

By akatz-ai·Created 2 years ago·Updated 9 months ago· 32
Shrink Num Sequence | Akatz
    • FLOAT
    float_list
    target_number1.00
    max_occurrences2
    use_epsilontrue

    Schedules love to get stuck. Keyframe interpolators, audio followers, and brightness extractors will happily produce long stretches where the value sits glued to one number - ten frames of 1.0, then a jump. Sometimes that's a genuine hold. Other times it's redundant bulk that makes a downstream controller behave oddly. AK_ShrinkNumSequence collapses those runs: it keeps the first few occurrences of a repeated target value and replaces the rest of the run with 0.0.

    Why you'd reach for it

    This is a cleanup node for the pack's float-list pipeline. After AK_BrightnessToFloatList, an audio schedule, or any list generator hands you a run of identical values, you can shrink each run down to max_occurrences copies. The clever bit is what happens to the extras: they become 0.0 rather than getting removed, so the list keeps its length. When a list must stay frame-aligned with a batch (which is almost always in animation), deleting entries would shift everything after them; zeroing them out doesn't.

    How it works

    It walks the list left to right, counting consecutive values that match target_number. As long as the count is under max_occurrences, the value passes through. Once the run exceeds that, subsequent matches in the same run become 0.0. Any non-target value resets the counter. Matching respects use_epsilon (default true), which compares with abs(value - target) < 1e-7 - the right call for floats that came out of arithmetic and might be off by a hair.

    Inputs and outputs

    • float_list (FLOAT) - the list to clean. A list, not a scalar.
    • target_number (FLOAT, default 1.0) - the value whose runs get shrunk. Only runs of this value are touched.
    • max_occurrences (INT, default 2, min 1) - how many copies of the target survive per run.
    • use_epsilon (BOOLEAN, default true) - epsilon matching for floats.
    • FLOAT output - the same-length list, with surplus target values zeroed.

    Installing the pack

    Part of Akatz Custom Nodes (akatz-ai/ComfyUI-AKatz-Nodes). ComfyUI Manager: search "Akatz" and install, or clone it:

    cd ComfyUI/custom_nodes
    git clone https://github.com/akatz-ai/ComfyUI-AKatz-Nodes
    

    Restart ComfyUI; it's under 💜Akatz Nodes. Pure Python here - no dependency beyond what ComfyUI ships; the pack's requirements.txt extras (opencv-python, pydub) serve other nodes. No models. The README is a stub that points to the author's Notion docs and a custom GPT.

    Gotchas

    • The extras become 0.0, they don't disappear. If you expected a shorter list, this node isn't that - and the length preservation is exactly why it's useful for frame-aligned work.
    • Only runs of target_number are touched. Runs of any other value, including near-zeros, pass through untouched.
    • With use_epsilon off, matching is exact equality, which is unreliable for computed floats - leave epsilon on unless you have a reason not to.
    Category💜Akatz Nodes/Utils

    Inputs (4)

    NameTypeDefaultDescription
    float_listFLOAT
    target_numberFLOAT1.00
    max_occurrencesINT2
    use_epsilonBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    FLOATFLOAT