Nodes/Nilor Nodes by Nilor Corp/๐Ÿ‘บ n Fractions of Int
ComfyUI Node

๐Ÿ‘บ n Fractions of Int

Split an integer into N evenly-spaced indices, four different ways

By nilor-corpยทCreated 2 years agoยทUpdated 6 months agoยท 6
๐Ÿ‘บ n Fractions of Int
    • fractions
    โ—„numerator10โ–บ
    โ—„denominator2โ–บ
    โ—„typeโ–พโ–บ

    When you have 100 frames and want to sample 5 evenly-spaced ones, you could compute 0, 25, 50, 75, 100 by hand. Or you could let a node do it. Nilor n Fractions of Int takes a numerator (your total, default 10), a denominator (how many fractions to produce, default 2), and a type that controls exactly where the split points land, then returns that many integers. It's a small arithmetic node, but it's the backbone of "sample evenly across a batch" workflows.

    The four modes

    • starts - the start of each fraction: i * numerator // denominator. For 10/2: [0, 5]. For 10/4: [0, 2, 5, 7] (integer division rounds down).
    • ends - the end of each fraction: (i+1) * numerator // denominator. For 10/2: [5, 10].
    • centres - the midpoint of each fraction, computed as (i*numerator + numerator//2) // denominator. For 10/2: [2, 7]. Note the //2 is applied before division, so the "centres" are only approximately centered on odd totals - a mild quirk, not a bug.
    • start + end - every fraction's start and the final end, i.e. i * numerator // (denominator - 1). For 10/2: [0, 10]. For 10/3: [0, 5, 10]. This is the "N evenly spaced points including both ends" mode.

    Output is fractions, always a list (marked OUTPUT_IS_LIST), with exactly denominator entries.

    Where it fits

    This is a sampling node for batch pipelines. You have numerator frames/images and want to grab denominator of them spread across the range - feed the resulting list into ๐Ÿ‘บ Select Index From List or ๐Ÿ‘บ Load Image By Index (whose seed input doubles as an index) to actually pick them. The start + end mode is the classic keyframe sampler: N evenly spaced frames including both endpoints, which is exactly what you want for previews, contact sheets, or extracting a storyboard from a video. starts/ends/centres are the variants you'd want when the endpoints shouldn't be included or you want midpoints instead.

    The quirks

    Integer division truncates. 10/4 in starts gives [0, 2, 5, 7], not [0, 2.5, 5, 7.5] - it's integer arithmetic throughout, so "evenly spaced" is only approximate when the total doesn't divide cleanly. For most sampling that's fine; for precision you'd want float output, and this isn't the node for it.

    denominator of 1. In start + end mode, dividing by denominator - 1 means a denominator of 1 causes a division by zero - Python will raise. The other modes with denominator 1 produce a single-element list. Set it to at least 2 for start + end.

    Unknown type raises. The four strings are the whole menu; anything else errors with a descriptive message. There's no validation of numerator/denominator ranges otherwise, so keep them positive and sane.

    Install

    ComfyUI Manager (search "Nilor Nodes") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/nilor-corp/nilor-nodes
    cd nilor-nodes && pip install -r requirements.txt
    

    Restart ComfyUI; it's under Nilor Nodes ๐Ÿ‘บ โ†’ Utilities. No dependencies.

    Bottom line

    A tiny but surprisingly central utility: "give me N evenly spaced index points across a range" in four flavors, delivered as a proper list. Learn the four modes once and you'll stop hand-computing keyframe indexes forever. Just remember the integer truncation and the denominator of 1 in start + end mode, and it'll behave.

    CategoryNilor Nodes ๐Ÿ‘บ/Utilities

    Inputs (3)

    NameTypeDefaultDescription
    numeratorINT10โ€”
    denominatorINT2โ€”
    typeCOMBO4 options: starts, ends, centres, start + end

    Outputs (1)

    NameTypeDescription
    fractionsINTโ€”