I am wondering whether there is any efficient way of vectorizing the power function in Stan. I have read some documentation of pow(vector, vector), pow(real, vector) and pow(vector, real) but not sure how they are applied in the practical setting. Is there any detailed numerical examples about them?
That’s actually discussing an older framework that never made it to release, the binary vectorisation currently in Stan is a bit different to that. But yeah, there’s no speed-up in using the vectorised versions of the binary functions it’s just more concise.
Even though there is currently no speed gain from vectorised elementwise operations like pow, as @andrjohns notes, there are changes in the development pipeline that will speed up vectorised code by a non-negligible factor so we would advise you write your models in a vectorized way wherever possible.
So after rstan has been upgraded, do you mean that I could use either pow(real, vector), pow(vector, real) and pow(vector, vector)?
Also I found that this reference 5.4 Elementwise functions | Stan Functions Reference might suggest that ‘vector .^ real’ is equivalent to pow(vector, real), but this elementwise operation ‘.^’ also did not work for me? Is this still a rstan version issue or they are actually not equivalent?