If / Else Merge
Shippingcond_mergeWhole-branch If/Else select: forward the then or else input based on one boolean condition
Signature
Inputs
conditionBoolean|Integer|Scalar|Signal— Reduced to ONE boolean for the whole branch (≠ 0 is truthy; a Signal is 'any sample non-zero' with a warning; absent ⇒ false).thenAny— Value forwarded verbatim when the condition is true.elseAny— Value forwarded verbatim when the condition is false.
Outputs
resultAny— The taken branch, forwarded unchanged (type, unit and ±σ all carry through).
Description
If / Else Merge (cond_merge) is the single interior node that makes an If/Else conditional compound work. It has three inputs — condition, then, else — and one output: .
One node, two contexts. Inside a Conditional compound (execution_mode = Conditional) the engine evaluates the condition first, prunes the untaken branch's exclusive sub-region from the graph, and only then runs the rest — so when this node executes, only the taken input is present and it simply forwards it. The untaken branch's nodes never run at all: an expensive computation or a would-divide-by-zero path is skipped, not computed-then-discarded (Simulink If-Action-style lazy pruning). Anywhere else (plain dataflow) both branches were already computed eagerly upstream and this node still forwards the taken one — so a bare drop on the canvas degrades gracefully into a scalar select. (For per-sample routing, use the switch node instead.)
The condition is reduced to exactly one boolean for the whole branch, by a single shared rule so the engine's prune decision and this node's runtime select can never disagree: a Boolean uses its value; an Integer or Scalar is truthy when (a NaN counts as false); a Signal is reduced to true iff any sample is non-zero, with a warning that per-sample conditions belong on Switch; an absent or non-numeric condition is false (take the else branch, with a warning for the non-numeric case).
The taken value is forwarded verbatim — its type, unit and uncertainty () all carry through unchanged; the merge adds no physics of its own. An empty or absent taken branch emits a scalar and a warning. Every port is optional, precisely because the engine intentionally leaves one of then/else absent after pruning.
Mathematics
Examples
Boolean condition, unit and σ preserved
Condition true, then = 10 V (σ²=4), else = -1 V. The output is 10 V with variance 4 carried verbatim — the merge is a pure passthrough of the taken branch.
Skipping an expensive branch
Inside a Conditional compound, wrap a heavy FFT chain in the then branch and a cheap constant in else. When the condition is false the entire FFT sub-region is pruned — it never executes — so the compound stays fast and avoids any NaN a divide-by-zero in the untaken path would have produced.
Signal condition reduces with a warning
Feeding a Signal [0, 1] into condition yields true (any sample non-zero) and emits a warning pointing you to the switch node for real per-sample routing.
Applications
- The core of an If/Else conditional subsystem where only the taken branch is allowed to run (lazy pruning of the untaken path).
- Guarding an expensive or numerically fragile computation behind a condition so it is skipped rather than computed and thrown away.
- Selecting between two whole processing pipelines (e.g. calibrated vs. raw) on a single mode flag.
- A drop-in whole-branch select on a plain canvas when per-sample routing is not needed.
Neat
The condition-reduction rule lives in one function (`evaluate_condition`) shared by both the engine's compile-time prune decision and the node's runtime select — the two are guaranteed to agree by construction.
Every port is optional by design: after the engine prunes the untaken branch, one of then/else is *intentionally* absent, so requiring it would hard-fail a correctly running compound.
It carries the taken value with zero transformation — units and uncertainty survive a merge untouched, unlike the `switch` router whose non-affine gate re-enters σ-lineage.
Known issues
A Signal condition is collapsed to a single boolean ('any sample non-zero') with a warning; it does NOT route per-sample — reach for `switch` when you need element-wise selection.
If the taken branch produced no value (empty or pruned to nothing) the node emits a bare `0` scalar and a warning rather than propagating an error.
Outside a Conditional compound both branches are computed eagerly upstream, so the pruning cost-savings only apply inside the conditional execution mode.