math icon indicating copy to clipboard operation
math copied to clipboard

Vectorise ternary functions

Open andrjohns opened this issue 4 years ago • 4 comments

Description

As with the unary and binary functions, it would useful to add a framework for vectorising ternary functions (like fma, inc_beta, and if_else).

Eigen has a framework CwiseTernaryOp which we can use in combination with the existing apply_scalar_binary framework to cover the various combinations

Current Version:

v4.2.1

andrjohns avatar Jan 03 '22 08:01 andrjohns

Great! if_else() is deprecated and will not be supported as of Stan 2.32, so there is probably no need to bother with that one?

rok-cesnovar avatar Jan 03 '22 08:01 rok-cesnovar

Ah cool. How does stanc3 handle the ternary operator? I was thinking that the vectorised if_else would allow us to have vectorised ternary expressions as well

andrjohns avatar Jan 03 '22 08:01 andrjohns

With the ternary C++ operator:

real a = k > 0 ? 5 : 10;

is generated as:

a = (logical_gt(k, 0) ? 5 : 10);

Maybe we should think about using if_elsefor that case though. So the ternary operator in Stan is generated to if_else. Maybe open an issue in stanc3 so we discuss it?

rok-cesnovar avatar Jan 03 '22 09:01 rok-cesnovar

Sounds good, will do!

andrjohns avatar Jan 03 '22 09:01 andrjohns