no inverse in aljabr

67 views
Skip to first unread message

Mars0i

unread,
Oct 8, 2016, 1:16:03 AM10/8/16
to Numerical Clojure
After experimenting a bit and checking various sources, it looks like aljabr lacks an inverse function, because the underlying Javascript ndarray implementation doesn't have it.  core.matrix provides a default implementation of inverse by using vectorz's inverse, so this won't work in inverse in Clojurescript.  No complaints, and maybe I will investigate adding inverse to aljabr at some point (not now).  I just wanted to check that I wasn't missing something obvious.  If anything I wrote sounds wrong, please let me know.


(Not important--feel free to stop reading, of course--but in case anyone's interested: In an earlier post I mentioned that I wanted to have two versions of an application; one version would use raw Clojure arithmetic operators for speed with scalars only, and the other would use core.matrix for matrices instead of scalars.  The raw speed difference between scalars and matrices seemed worth having two versions that shared code.  Recently I got to the point  where I could do real tests of the full application, and the scalar version is only 25% faster!  (You're not surprised??)  For a mere 25% slowdown, I could have just written one version, using core.matrix.  But I'm glad that I have the scalar version:  I need inverse, so now I can at least run the application with scalars in Clojurescript, which will be fine for my immediate needs.)

Mike Anderson

unread,
Oct 24, 2016, 2:21:01 AM10/24/16
to Numerical Clojure
Hmmm we should probably write a generic inverse function in core.matrix that works for both Clojure and Clojurescript implementations. Shouldn't be too hard, although catching the corner cases for this kind of thing in a generic way can be a bit tricky.

Mars0i

unread,
Oct 26, 2016, 11:38:44 AM10/26/16
to Numerical Clojure
On Monday, October 24, 2016 at 1:21:01 AM UTC-5, Mike Anderson wrote:
Hmmm we should probably write a generic inverse function in core.matrix that works for both Clojure and Clojurescript implementations. Shouldn't be too hard, although catching the corner cases for this kind of thing in a generic way can be a bit tricky.

I guess that probably makes more sense, at least as a first step, rather than adding it to aljabr.  If I ever find time, I would love to do a little bit of research and write an initial implementation, but I don't know whether this will happen.

Mars0i

unread,
Nov 25, 2016, 1:29:58 PM11/25/16
to Numerical Clojure
On Monday, October 24, 2016 at 1:21:01 AM UTC-5, Mike Anderson wrote:
Hmmm we should probably write a generic inverse function in core.matrix that works for both Clojure and Clojurescript implementations. Shouldn't be too hard, although catching the corner cases for this kind of thing in a generic way can be a bit tricky.

There's an invert function for ndarray in ndarray.clj, which generates an invert-double function (but not any other version?).  invert-double seems to work, and it looks like inverse calls it when given an ndarray-double matrix, but there's not an invert<no-suffix> for an ndarray matrix.  (I don't understand why not, but I don't understand the ndarray magic macros very well.)

The discussion in issue #136 suggests that there used to be a default implementation of inverse, though now we use vectorz as a fallback instead because there was a bug in the default implementation.  However, in issue #251, edwastone says that #136 was fixed by a fix to lu-decompose! in ndarray.clj.  So maybe there was only an ndarray implementation, not a default implementation, and that's what the discussion in #136 was really about?

Do you (Mike, anyone else) think it could make sense for me to use the ndarray lu-* and invert definitions as a model for default implementations of the same functions, and determinant, too, I suppose.  i.e. the idea wouled be to copy code from ndarray and then go through and revise the ndarray-specific pieces?  I don't really have expertise in matrix algorithms, but willing to take a starting point and try to work through problems.  I hope.

(No time, shouldn't work on this but ....  partly inspired as result of looking at docs on GHC Haskell's matrix libs.  They're there, but seeing the difference between what Haskell has and core.matrix makes core.matrix all the more impressive.  Grateful.)
Reply all
Reply to author
Forward
0 new messages