Component wise operations


I recently had some hard time to find a function, rows_dot_product, to do a component wise product of two vectors:

A[ k ]=B[ k ]*C[ k ], k=1,…,N

and still do not know if a specialized function exists for:

A[ k ]=B[ k ]*B[ k ], k=1,…,N

Maybe I have missed something in the doc, but as a suggestion for future Stan language extensions I wanted to suggest a syntax like:



and, if useful, things like:


IMHO this syntax (compared to a loop or row_dot_product)

  • can be easier to learn and remember
  • can be easily vectorized.



There are operators:

  • A .* B for elementwise multiplication

  • A ./ B for elementwise divison

The rows_dot_product operation isn’t meant to be elementwise. It operates on two matrices and returns a vector consisting of the dot-product of the rows. Somebody was being thorough and added the vector and row-vector versions—not sure we need those versions. I agree that rows_dot_product makes no sense for those function other than the obvious generalization of the matrix version.


So sorry to have missed this syntax from the doc.
Thank you for the clarification.


It’s easy to mix things because there’s so much doc. The question is how we can organize it so the most useful stuff is most prominent. As it is, it’s just this 100 page wall of function definitions!