quil-lang / magicl

Matrix Algebra proGrams In Common Lisp.
BSD 3-Clause "New" or "Revised" License
230 stars 44 forks source link

MAGICL:EXPM doesn't work on SINGLE-FLOAT or (COMPLEX SINGLE-FLOAT) matrices #135

Open danikino opened 3 years ago

danikino commented 3 years ago

After installing magicl from git : in emacs with sbcl and sly : (ql:quickload :magicl) (magicl.backends:active-backends) --> (:EXPOKIT :LAPACK :BLAS :LISP) (defparameter a (magicl:from-list '(1.0 0.0 0.0 0.0 2.0 0.0 0.0 0.0 3.0) '(3 3))) a -->

<MAGICL:MATRIX/DOUBLE-FLOAT (3x3):

1.000 0.000 0.000 0.000 2.000 0.000 0.000 0.000 3.000>

(magicl:logm a) -->

<MAGICL:MATRIX/DOUBLE-FLOAT (3x3):

0.000 0.000 0.000 0.000 0.693 0.000 0.000 0.000 1.099> now ,if i do : (magicl:expm a) --> MAGICL:EXPM is not implemented in any of the current active backends: EXPOKIT, LAPACK, BLAS, LISP. [Condition of type MAGICL.BACKENDS:NO-APPLICABLE-IMPLEMENTATION] the question is how to calculate the exponential of a matrix ? What am I doing wrong ? I am trying to use magicl to learn robotics :) :)

stylewarning commented 2 years ago

HI @danikino, sorry for the late response.

The issue is that expm only works on complex double-float matrices.

CL-USER> (defparameter *a (magicl:from-list '(1.0 0.0 0.0 0.0 2.0 0.0 0.0 0.0 3.0) '(3 3) :type '(complex double-float)))
*A
CL-USER> (magicl:expm *a)
#<MAGICL:MATRIX/COMPLEX-DOUBLE-FLOAT (3x3):
   2.718 + 0.000j     0.000 + 0.000j     0.000 + 0.000j
   0.000 + 0.000j     7.389 + 0.000j     0.000 + 0.000j
   0.000 + 0.000j     0.000 + 0.000j    20.086 + 0.000j>

We haven't extended it to get it to work on just double or single float matrices, but shouldn't be too hard!

stylewarning commented 2 years ago

I merged support for double-float, now you can do:

CL-USER> (setf *read-default-float-format* 'double-float)
DOUBLE-FLOAT
CL-USER> (defparameter *a (magicl:from-list '(1.0 0.0 0.0 0.0 2.0 0.0 0.0 0.0 3.0) '(3 3)))
*A
CL-USER> *a
#<MAGICL:MATRIX/DOUBLE-FLOAT (3x3):
   1.000     0.000     0.000
   0.000     2.000     0.000
   0.000     0.000     3.000>
CL-USER> (magicl:expm *a)
#<MAGICL:MATRIX/DOUBLE-FLOAT (3x3):
   2.718     0.000     0.000
   0.000     7.389     0.000
   0.000     0.000    20.086>

Still no implementation for single-floats though.