Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vectorise ternary functions #2638

Open
andrjohns opened this issue Jan 3, 2022 · 4 comments
Open

Vectorise ternary functions #2638

andrjohns opened this issue Jan 3, 2022 · 4 comments

Comments

@andrjohns
Copy link
Collaborator

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

@rok-cesnovar
Copy link
Member

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?

@andrjohns
Copy link
Collaborator Author

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

@rok-cesnovar
Copy link
Member

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?

@andrjohns
Copy link
Collaborator Author

Sounds good, will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants