math
math copied to clipboard
Add `where`/`select` functions
Another part of https://github.com/stan-dev/stan/issues/3300#issuecomment-3188755711
Two useful functions:
select(ints, T)takes in a container container of integers in {0, 1} and a same-sized other container and returns a new container with those elements picked out (size is sum(first arg))where(ints, T1, T2)takes in two containers and essentially does an element wise version of the ternary operator. Where ints is 1, the corresponding index inT1is used, where it is 0,T2
These can be treated as two functions, or they could be both be called where and be overloads (this is what numpy does)