Matrix multiply exception

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?

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.

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

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).

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

1 Like