Cryptic shape issue with 1x1 matrix #978
Replies: 1 comment 2 replies
-
This looks like a genuine bug. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I am trying to hunt down the cause of a shape issue in my code and I am really stumped. Here's a minimal example that reproduces the error:
The error seems to be a confluence of several things, because I found several ways to make it go away. None of them, however, give me a general solution to my problem, so here I am.
The first is that if I just set up everything with symbolic objects rather than using
at.zeros
, it works fine. For example:Does not throw an error. As an aside, I have run into a lot of shape issues trying to use
at.zeros
andat.zeros_like
in general. Should these be avoided? I am using them here because of that's how I've written my API. These tend to be sparse matrices, and I wanted users to be able to assign only the relevant elements when they set up their problem.Anyway, given the zeros/set_subtensor setup, the proximate cause of the error is the final matrix_dot inside the function. Removing this, I can get back all the intermediate computations and confirm that shapes conform. In particular, confirm that H_masked isn't being cast to a scalar. This is important because the ultimate cause seems to have something to do with the matrix H being 1 x 1. Changing the input variables so that H is 2 x 2 fixes the problem, for example:
Does not throw an error. H being 1x1 is an important special case to my problem (one observed time series), so I really want to figure this out.
In addition, removing the first four lines that zero out columns of H and Z associated with missing data also fixes the problem. That is, this
step_func
works fine:But then I lose the ability to interpolate missing data.
My favorite fix, however, is changing
F = matrix_dot(Z_masked, P, Z_masked.T) + H_masked
toF = matrix_dot(Z_masked, P, Z_masked.T)
. I have no idea why that particular addition (pun intended) would cause a shape error in a matrix multiplication down-stream.I hope I'm missing something obvious as usual. Also as usual, your help and time are greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions