Does Stan has a function similar to the Apply function in R?


#1

Do we have a Stan function that works similar to the R Apply functions (https://www.rdocumentation.org/packages/base/versions/3.5.2/topics/apply)?


#2

map_rect in Stan is somewhat similar to sapply but less so to apply unless you write your two-dimensional structure as an array or row_vectors or column vectors.


#3

Thank you very much!
I’m a little confused about the parallelization of map_rect in Stan. Is it doing things like MPI via multi-thread or CPU? Or using a single thread with all arrays of data and parameters loaded together to reduce the communication cost from memory to caches?


#4

You can do MPI, it is easier to get threading to work, or you could use it serially. I was just saying that conceptually it is like sapply in that you are applying a function to each element of an array (which is like a homogenous R list).