Yotsuba Games
Back to Node List

Cartesian Product

cartesian_product

Builds every combination between list or palette A and B

Reviewed
Guide available
The node name and summary are available in English. Port, parameter, and article details are currently shown in Japanese.

Input Ports

NameTypeDescription
A
a
Any
Required
1ใค็›ฎใฎๅ…ƒใƒชใ‚นใƒˆใพใŸใฏใƒ‘ใƒฌใƒƒใƒˆใงใ™
B
b
Any
Required
2ใค็›ฎใฎๅ…ƒใƒชใ‚นใƒˆใพใŸใฏใƒ‘ใƒฌใƒƒใƒˆใงใ™

Output Ports

NameTypeDescription
็ต„ใฟๅˆใ‚ใ›
entries
List<Map>
ๅ…จใฆใฎ { a, b } ็ต„ใฟๅˆใ‚ใ›ใงใ™
่ฆ็ด ๆ•ฐ
count
Int
็”Ÿๆˆใ—ใŸ็ต„ใฟๅˆใ‚ใ›ๆ•ฐใงใ™

Overview

Creates every combination of two lists. It mechanically expands multiple axes of variation, such as "2 sizes ร— 3 colors = 6 combinations." A typical use is directly before batch production with batch_render.

Usage tips

  • The go-to batch-production chain is variant_range (strength) + seed_range (seed) โ†’ cartesian_product โ†’ batch_render. It produces "5 strength levels ร— 4 seeds = 20 images" in one pass.
  • The number of entries grows multiplicatively (a.len() ร— b.len()). To add a third axis, pass the output through another Cartesian Product, but watch for a combinatorial explosion.
  • If you only need corresponding pairs, use list_zip to avoid increasing the number of entries.

Related nodes

  • list_zip โ€” corresponding pairs instead of every combination
  • variant_range / seed_range โ€” generate candidates for each axis
  • batch_render โ€” batch-produce the expanded results
  • list_map โ€” post-process the combination table

Read this first

  • ListZip combines items at the same index, while CartesianProduct creates every combination.
  • 2 entries ร— 3 entries produces 6 entries.

Start with this example

Provide these two lists:

a = ["small", "large"]
b = ["red", "blue", "green"]

The resulting entries value is:

[
  { "index": 0, "a_index": 0, "b_index": 0, "a": "small", "b": "red" },
  { "index": 1, "a_index": 0, "b_index": 1, "a": "small", "b": "blue" },
  { "index": 2, "a_index": 0, "b_index": 2, "a": "small", "b": "green" },
  { "index": 3, "a_index": 1, "b_index": 0, "a": "large", "b": "red" },
  { "index": 4, "a_index": 1, "b_index": 1, "a": "large", "b": "blue" },
  { "index": 5, "a_index": 1, "b_index": 2, "a": "large", "b": "green" }
]
count = 6

How downstream nodes see it

When you feed these entries to ListMap or ListFilter, you can use the following fields directly in expressions:

  • index
  • a_index
  • b_index
  • a
  • b

For example:

a_index == 0
a + b

Working with Variant nodes

If a and b contain lists of VariantRecord values, a downstream BatchRender automatically collects and uses the snapshots inside a and b. This makes the node useful before multi-axis batch production, such as "strength candidates ร— seed candidates."

When to use it

  • To create every combination of seed candidates and candidates for another parameter
  • To represent a two-axis candidate space as explicit data
  • To build a batch candidate table before generating variant candidates

Notes

  • The result contains a.len() * b.len() entries, so the number of candidates can grow very quickly.
  • A Palette is treated as List<Color>.
Back to Node List
Cartesian Product โ€” PixPipeline Node Reference