You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 18, 2023. It is now read-only.
I was a bit surprised that a matrix that isn't invertable didn't result in a Left:
λ> a
┌ ┐
│ 1.0 1.0 │
│ 2.0 2.0 │
└ ┘
λ> inverse a
Right ┌ *** Exception: getElem: Trying to get the (2,1) element from a 1x3 matrix.
CallStack (from HasCallStack):
error, called at ./Data/Matrix.hs:434:16 in matrix-0.3.5.1-4UERfYC1lvKBLaK5oxpBHX:Data.Matrix
λ>
Boom.
λ> detLU a
0.0
λ>
Oh.
I realize that large matrices don't suffer from this problem statistically, but smaller ones can bork pretty easily. So can we check? Calculating the determinant isn't free, but in the way you have a few different cases for matrix multiplication, can we have a safer inverse function that checks? You've already got the type signature to support it.
(I note in passing that there seem to be inverse methods that use the determinant in the calculation; Cayley–Hamilton and Cramer's Rule so if either of those were suitable for the implementation of inverse then the safety check calculating the determinant would contribute to the overall computation)
Anyway, I'd like inverse to not blow up if handed a non-invertable matrix. The other approach is to catch errors being thrown, but that's a bit ugly.
AfC
The text was updated successfully, but these errors were encountered:
istathar
added a commit
to istathar/matrix
that referenced
this issue
Sep 11, 2016
Yes, I do think the inverse needs a review, or even a rewrite. It is not intentional that inverse is partial. It should always return a result. So this is a bug. However, I am not sure that calculating the determinant before calculating the inverse is a good approach. While calculating the inverse, it should become apparent at some step that the inverse can't be calculated, and therefore the input matrix was not invertible. If this is the case, the computation should stop there and return a Left value.
Given that the type signature of
inverse
isI was a bit surprised that a matrix that isn't invertable didn't result in a
Left
:Boom.
Oh.
I realize that large matrices don't suffer from this problem statistically, but smaller ones can bork pretty easily. So can we check? Calculating the determinant isn't free, but in the way you have a few different cases for matrix multiplication, can we have a safer
inverse
function that checks? You've already got the type signature to support it.(I note in passing that there seem to be inverse methods that use the determinant in the calculation; Cayley–Hamilton and Cramer's Rule so if either of those were suitable for the implementation of
inverse
then the safety check calculating the determinant would contribute to the overall computation)Anyway, I'd like inverse to not blow up if handed a non-invertable matrix. The other approach is to
catch
errors being thrown, but that's a bit ugly.AfC
The text was updated successfully, but these errors were encountered: