Nodes/WAS Node Suite v3/Tensor Index Switch
ComfyUI Node Runs on cloud

Tensor Index Switch

Pick one picture from a stack by number

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Tensor Index Switch
  • index
  • input_a
  • input_b
  • input_c
  • input_d
  • input_e
  • input_f
  • input_g
  • input_h
  • input_i
  • input_j
  • input_k
  • input_l
  • input_m
  • input_n
  • input_o
  • input_p
  • input_q
  • input_r
  • input_s
  • input_t
  • input_u
  • input_v
  • input_w
  • input_x
  • input_y
  • input_z
  • output
  • resolved_index
  • count
out_of_rangewrap

If a boolean switch is a fork in the road, this is a railway turntable: up to 26 candidate pictures in, one number in, and exactly the picture you pointed at comes out. It's the node you reach for when the choice isn't a clean true/false but "which of these many images do I process this run?"

What it is

"Tensor image" is WAS Node Suite's slightly formal way of saying an image, a mask or a latent - the three things that live on the wire as tensors. The switch accepts all three, and here's the neat part: the first connection fixes the type. Plug an IMAGE into slot A and every other slot and the output lock to IMAGE, so you can't quietly mix a latent into an image chain. Anything else gets refused at the socket, which catches the mistake while you're drawing the wire instead of at run time.

You drive it with the index input (INT, NUMBER or FLOAT all accepted; decimals just get truncated). Feed it a Number Counter or a loop's index and you can step through a stack of images one per run. Two niceties make it genuinely useful in loops:

  • Negative indices count from the end. -1 is the last connected slot, so you don't need to know the count to grab the final picture.
  • Out-of-range handling is your choice. wrap cycles round again (index 4 of 3 slots gives slot 1 - perfect for a counter that only climbs), clamp sticks at the first or last slot, and error stops the prompt. If a missing entry means something's broken upstream, error is the honest setting.

What comes out

The obvious output is output - the selected image/mask/latent. But it also reports resolved_index (the slot actually read, after wrap or clamp - genuinely useful when a counter drives the index and you want to know which frame you got) and count (how many slots are actually connected, since an unconnected slot isn't counted and index 0 is the first slot wired).

That last detail trips people up once: this is not a "connected slots a–z all counted" node. If you leave input_d empty, index 3 selects nothing useful, because only connected slots count. Wire them up in order and the indices line up with the letters.

Lazy, and why that matters

The unselected inputs aren't evaluated. If slot A runs a whole img2img pass and you pick slot B, the work behind A is simply skipped - no wasted VRAM or time. That's the difference between this and a "collect everything then pick" approach, and it's why these typed switches are the right tool for branching heavy pipelines.

It's a sibling of the two-way Tensor Image Switch (boolean, A/B) and the Any Switch / Any Input Switch family for untyped values. If your stack is a handful of pictures and a loop index, this is the one you want.

Installing it

Part of WAS Node Suite v3 (WASasquatch's was-node-suite-comfyui, MIT). Search "WAS Node Suite v3" in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui.git

Restart ComfyUI afterward. Requires ComfyUI 0.14.0+ and Python 3.10+; no extra packages to install for this node.

CategoryWAS Suite/Logic/Switch

Inputs (28)

NameTypeDefaultDescription
indexINT,NUMBER,FLOAT0-99999999–99999999Slot to pass on, from 0. Negative counts from the end: -1 = last. A decimal is truncated: 2.7 = 2.
out_of_rangeCOMBOwrapIndex outside 0..count-1. With 3 slots and index 4: `wrap` = slot 1, `clamp` = slot 2, `error` stops the prompt.
input_aoptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_boptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_coptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_doptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_eoptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_foptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_goptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_hoptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_ioptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_joptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_koptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_loptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_moptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_noptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_ooptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_poptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_qoptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_roptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_soptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_toptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_uoptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_voptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_woptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_xoptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_yoptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_zoptCOMFY_MATCHTYPE_V3One candidate for the index. Takes IMAGE, MASK or LATENT. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.

Outputs (3)

NameTypeDescription
outputCOMFY_MATCHTYPE_V3The selected input, typed to whatever was connected.
resolved_indexINTSlot actually read, from 0, after wrap or clamp.
countINTConnected slots. The index runs 0..count-1.