Unfortunately I wasn’t able to create a minimal working example  I was able to get around the issue by making a special case when N = 1,  by just doing elementwise multiplication in that case using * instead (and relying on broadcasting).