Vocabulary
math.vectors

Inputs
maska sequence of booleans
true-quota quotation with stack effect ( -- vector )
false-quota quotation with stack effect ( -- vector )


Outputs
resulta sequence


Word description
If all of the elements of mask are true, true-quot is called and its output value returned. If all of the elements of mask are false, false-quot is called and its output value returned. Otherwise, both quotations are called and mask is used to select elements from each output as with v?.

Notes
See Componentwise logic with SIMD vectors for notes on dealing with vector boolean inputs and results when using SIMD types.

For most conditional SIMD code, unless a case is exceptionally expensive to compute, it is usually most efficient to just compute all cases and blend them with v? instead of using vif.

Definition


: vif
( mask true-quot: ( -- vector ) false-quot: ( -- vector ) -- result )
{
{ [ pick vall? ] [ drop nip call ] }
{ [ pick vnone? ] [ 2nip call ] }
[ [ call ] dip call v? ]
} cond ; inline