MatLisp is intended to be a base library for scientific computation in Lisp. This is the development branch of Matlisp.
Lisp is a wonderful language for explorative computing, but lacks general tools for numerical computing, whilst MATLAB/Numpy are excellent for certain tasks but are less well adopted for other tasks. Lisp however allows interesting new constructs without being tied down to a particular language vendor, for instance we use ‘/’ as both a binary and unary operator (like ‘-‘), so that,
MATLISP> #i(/A * b)
solves the matrix equation
> (defun mm (A B C)
(einstein-sum real-tensor (j k i) (ref C i j) (* (ref A i j) (ref B j k))))
basically generates an extremely tight naive 3-loop version of GEMM (exercise: why ‘j k i’ ?), which is only about 10 times as slow the optimized version of GEMM in OpenBLAS, and about 20% slower than the naive 3-loop version in C.
Matlisp also switches dynamically between BLAS routines (when available) and native lisp code to avoid FFI overheads. This also means that, BLAS functionality of Matlisp can be used (with minimal tweaking) either without a BLAS library, or for commutative-rings which don’t have a BLAS version available.
Matlisp uses CFFI for callng foreign functions. That said, the FFI capabilities of different lisps are quite different. So if your Lisp implementation supports callbacks and calling plain C functions and maps float simple-arrays into C-type arrays in memory, it shouldn’t be too hard to get it working (if it doesn’t work already). We’ve tested Matlisp on CCL and SBCL. The build system is cranky with all the new changes.
- Install quicklisp http://www.quicklisp.org/beta/.
- Download matlisp source:
> git clone git@github.com:matlisp/matlisp.git
> ln -s $PWD/matlisp <quicklisp-directory>/local-projects
Fire up your lisp implementation and load as usual with quicklisp:
CL-USER> (ql:quickload :matlisp)
CL-USER> (in-package :matlisp)
MATLISP> (in-readtable :infix-dispatch-table)
The fortran libraries provided by matlisp earlier are now part of matlisp-packages.
More documentation will be added as things reach a nicer stage of development.
;;Creation
MATLISP> (copy! (randn '(2 2)) (zeros '(2 2) 'complex-tensor))
#<COMPLEX-TENSOR #(2 2)
-1.5330 -1.67578E-2
-.62578 -.63278
>
;;gemv
MATLISP> (let ((a (randn '(2 2)))
(b (randn 2)))
#i(a * b))
#<REAL-TENSOR #(2)
1.1885 0.95746
>
;;Tensor contraction
MATLISP> (let ((H (randn '(2 2 2)))
(b (randn 2))
(c (randn 2))
(f (zeros 2)))
(einstein-sum real-tensor (i j k) (ref f i) (* (ref H i j k) (ref b j) (ref c k))))
#<REAL-TENSOR #(2)
0.62586 -1.1128
>
- Generic template structure.
- Double real, complex tensor structures in place.
- Templates for optimized BLAS methods in Lisp.
- Automatic switching between Lisp routines and BLAS.
- Inplace slicing, real - imag views for complex tensors.
- copy, scal, dot, swap, axpy, gemv, gemm, getrf/getrs (lu), geev(eig), potrf/potrs(chol), geqr
- permutation class, sorting, conversion between action and cycle representations.
- mod-loop works, can produce very quick multi-index loops.
- einstein macro works, can produce optimized loops.
- Negative stride support, ala Python.
- Tensor contraction: Hard to do very quickly; uses einstein-sum.
- co-ordinate sparse tensor, compressed sparse matrix support exists, but in a shaky state. There’s also a fib-heap implementation for graph algorithms.
Things are currently done using the iter slice macro (and mapslice*’s), mod-dotimes, and einstein-loop generator. The more elegant course to take would be unify these with a nice syntactic glue; sadly as far I know this hasn’t been done before. This will require quite a bit of prototyping.
- Make everything in src/old/ compatible with new datastrutures.
- LAPACK: Add interfaces to remaining functions.
- DFFTPACK: computing FFTs
- QUADPACK: Move from f2cl-ed version to the Fortran one.
- MINPACK: Move from f2cl-ed version to the Fortran one.
- ODEPACK: Add abstraction for DLSODE, and DLSODAR may others too.
- Make gnuplot interface more usable.
(C)Python has far too many things, that we cannot even begin to hope to replicate. Burgled-batteries has a lot of things which could be useful in talking to CPython.
Getting standard-tensor <-> numpy tranlation should be enough. Mostly care about matplotlib at the moment.
Parse header files with cffi-grovel.
- Write documentation. Fix the formatting for docstrings. Maybe move to TeXinfo (like femlisp).
- Write tests Use cl-rt stuff to write more tests. Probably even add benchmarks.
- Use things like macrofy to work with Maxima
- Provide seamless AD, Symbolic differentiation and numerical function calls, ala scmutils.
- Symbolic stuff tends to fit in easily with the lisp-based BLAS routines. Port code from src/classes/symbolic-tensor.lisp