vif ( mask true-quot: ( -- vector ) false-quot: ( -- vector ) -- result )

Factor handbook » The language » Numbers » Vector operations » Vector component- and bit-wise logic

Factor handbook » The language » Numbers » Vector operations » Vector component- and bit-wise logic

Prev: | v? ( mask true false -- result ) |

Next: | vall? ( v -- ? ) |

Vocabulary

math.vectors

Inputs

Outputs

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

math.vectors

Inputs

mask | a sequence of booleans |

true-quot | a quotation with stack effect ( -- vector ) |

false-quot | a quotation with stack effect ( -- vector ) |

Outputs

result | a 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