math icon indicating copy to clipboard operation
math copied to clipboard

Add `where`/`select` functions

Open WardBrian opened this issue 1 month ago • 0 comments

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 in T1 is 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)

WardBrian avatar Nov 14 '25 15:11 WardBrian