Matrix multiply exception


#1

I have a model that is getting a few exceptions thrown, one of which is described simply as “multiply.” The source code line mentioned is a matrix multiplication. I can see why a matrix inversion might throw an exception, but what condition would cause a matrix multiplication to throw an exception?


#2

Size mismatch is the usual culprit—trying to multiply an M x N by an M x N for instance, rather than transposing the second one. We can’t catch that at compile time because sizes aren’t known, only number of dimensions.


#3

Size mismatch is highly unlikely here, as the sizes are static and the exception only happens a few times per chain.


#4

Can you post the model? Maybe it’s something near the multiply. It’s true there’s not a lot going on in multiply (https://github.com/stan-dev/math/blob/develop/stan/math/prim/mat/fun/multiply.hpp).


#5

@bbbales2 That’s just the primitive version. We specialize heavily for reverse-mode autodiff.