haskell-numerics / hmatrix

Linear algebra and numerical computation
381 stars 104 forks source link

Crash from usage of static diagR with <> #251

Closed mstksg closed 4 years ago

mstksg commented 6 years ago

I'll be looking into this myself, just filing an issue to have this be recorded.

> x = diagR 0 (vec 1 2 3) :: L 5 3
> y = x <> (1 :: L 3 3)
> :t y
y :: L 5 3
> z = (1 :: L 5 5) <> y
> :t z
z :: L 5 3
> z
*** Exception: inconsistent dimensions in matrix product (5, 5) x (3, 3)

It seems to come from y being treated internally as a 3x3 matrix, despite its type indicating it should be 5x3.

HuwCampbell commented 4 years ago

The issue is here.

When we call toDiag

mulR (isDiag -> Just (0,a,_)) (extract -> b) = mkL (asColumn a * takeRows (LA.size a) b)

The wildcard pattern contains the true number of rows; and asColumn and takeRows don't get it right.