uncomplicate / neanderthal

Fast Clojure Matrix Library
http://neanderthal.uncomplicate.org
Eclipse Public License 1.0
1.06k stars 56 forks source link

uncomplicate.neanderthal.linalg/org error in 0.25.3 #66

Closed sparkofreason closed 5 years ago

sparkofreason commented 5 years ago

The following code worked in 0.24.0:

  (require '[uncomplicate.neanderthal.linalg :as linear-algebra]
           '[uncomplicate.neanderthal.native :as native]
           `[uncomplicate.neanderthal.core :as neanderthal])
  (let [a (native/dge [[1.0 2.0] [3.0 2.0] [6.0 2.0] [5.0 3.0]])
        qr (linear-algebra/qrf a)
        q (linear-algebra/org qr)]
    q)

Updating to 0.25.3 gives the following error:

Intel MKL ERROR: Parameter 2 was incorrect on entry to DORGQR.
Syntax error compiling at (/home/davedixon/Projects/Compute/math/src/provisdom/math/neanderthal_matrix.clj:249:3).
There has been an illegal argument in the native function call.
    at clojure.lang.Compiler.load(Compiler.java:7648)
clojure.lang.ExceptionInfo: There has been an illegal argument in the native function call. {:arg-index 3}
    at uncomplicate.neanderthal.internal.host.mkl.DoubleGEEngine.gqr(mkl.clj:904)
    at uncomplicate.neanderthal.internal.api$eval13429$fn__13654$G__13403__13658.invoke(api.clj:59)
    at uncomplicate.neanderthal.internal.api$eval13429$fn__13654$G__13402__13663.invoke(api.clj:59)
    at uncomplicate.neanderthal.internal.common.OrthogonalFactorization.org(common.clj:288)
    at uncomplicate.neanderthal.linalg$org.invokeStatic(linalg.clj:419)
    at uncomplicate.neanderthal.linalg$org.invoke(linalg.clj:409)
    at provisdom.math.neanderthal_matrix$eval31890.invokeStatic(neanderthal_matrix.clj:251)
...

Looking at the commits from 0.24.0 to 0.25.3, I guessed that native/dge as used above would return the transpose of what it did previously, and indeed the following works as before:

(let [a (neanderthal/trans (native/dge [[1.0 2.0] [3.0 2.0] [6.0 2.0] [5.0 3.0]]))
        qr (linear-algebra/qrf a)
        q (linear-algebra/org qr)]
    q)

Not sure why linear-algebra/org fails in the first case, when linear-algebra/qrf runs, perhaps something I'm misunderstanding about the underlying implementation.

blueberry commented 5 years ago

This is caused by the intended change in the transfer! multimethod implementation between nested sequences and matrices. Previously, the nested sequence was always considered to consist of the rows of a matrix, and now it depends of the :layout. Since the default layout in ge constructors is :column, in your example the values are transposed. The solution is to either rearrange the values in the source sequence, or add {:layout :row} optional argument to the dge call.

sparkofreason commented 5 years ago

Why does org throw an error while qrf seems to return an answer?