Bug in default inverse?
$ lein try net.mikera/core.matrix net.mikera/vectorz-clj
user=> (require '[clojure.core.matrix :as m])
user=> (def a (m/matrix [[0 1 0] [1 1 0] [1 -1 -1]]))
user=> (m/inverse a)
#<NDArrayDouble [[0.0 0.0 0.0] [-0.0 1.0 -0.0] [-0.0 -1.0 -1.0]]>
user=> (m/mmul a (m/inverse a))
[[0.0 1.0 0.0] [0.0 1.0 0.0] [0.0 0.0 1.0]]
user=> (m/set-current-implementation :vectorz)
user=> (def a (m/matrix [[0 1 0] [1 1 0] [1 -1 -1]]))
user=> (m/inverse a)
#<Matrix33 [[-1.0,1.0,0.0],[1.0,-0.0,0.0],[-2.0,1.0,-1.0]]>
user=> (m/mmul a (m/inverse a))
#<Matrix33 [[1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,1.0]]>
Yeah that looks like an NDArray bug. Thanks for the report!
Any progress on this? I also have a case where the inverse matrix becomes singular:
(def a m/matrix [[1 0 0 0.0 0 0.0]
[1 0 1 0.0 0 1.0]
[1 1 0 1.0 0 0.0]
[1 0 1/2 0.0 0N 0.25]
[1 1/2 1/2 0.25 1/4 0.25]
[1 1/2 0 0.25 0N 0.0]])
(det a) ; => 0.015625
(det (inverse a)) ; => IllegalArgumentException lu-decompose can't decompose singular matrix ...
I tested it on both 0.34 and 0.35. Vectorz works fine, as above.
Don't have time to look at this myself right now. I use Vectorz basically all the time.... might just disable this functionality in case it hurts someone.
I'd vote for that option then, I was pretty confused and lost quite a bit of time figuring out what the problem was. It is the default implementation after all.
Hmmm I found a better option I think. Try to use Vectorz if available, throw an error otherwise. Sound sensible?
Yes, even better, unless the transparent conversion introduces a problem elsewhere. The documentation for inverse should mention it too.
OK, pushed some changes. Should all be available in next release.
Leaving open in case anyone wants to take on fixing / rewriting the default implementation.