8.6.2. LAPACK: Linear Algebra Package |

Author(s): Fu Jie Huang, Yann LeCun

This is a full interface to the popular LAPACK library (written in FORTRAN). Most functions have a single precision and a double precision form for real and complex numbers. A complex number is represented in Lush as an -idx1- with two elements.

8.6.2.0. Requirements/Installation |

Most GNU/Linux distributions include LAPACK as part of the

If you are on a system without a LAPACK package, you can download the FORTRAN source code from http://www.netlib.org/lapack and install the resulting library (e.g. lapack_LINUX.a) in /usr/local/lib. If you put lapack_XXX.a in a non-standard location, you must tell Lush where you put it by doing:

(defparameter lapack-liblapack "yourlapacklibrary.a")

before loading any of the LAPACK files into Lush.

8.6.2.1. A Short (and incomplete) Tutorial |

Author(s): Fu Jie Huang

A typical LAPACK function takes several types of arguments:

- character, to indicate options

- array, as the vector/matrix

- integer, to provide informations (such as dimention) of
vector/matrix

The correponding Lush types are:

- string, (-str-), a one character string

- vector/matrix, (-idx1-, or -idx2-)

- scalar (-idx0-)

An example LAPACK function interface (in Fortran) and its Lush interface:

SUBROUTINE DGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO ) INTEGER INFO, LDA, LDB, N, NRHS INTEGER IPIV( * ) DOUBLE PRECISION A( LDA, * ), B( LDB, * ) (de dgesv (n nrhs a lda ipiv b ldb info ) ((-idx0- (-int-)) info lda ldb n nrhs) ((-idx1- (-int-)) ipiv ) ((-idx2- (-double-)) a b)

Note that:

- Fortran assumes a 2D matrix is stored column-wise, while C and
Lush store it row-wise. Make sure you feed the correct stuff to LAPACK.

- All Fortran arguments are pointers (there's only call-by-reference
in Fortran, no call-by-value). Therefore for those integer arguments
**info**,**lda**,**ldb**etc. in the above example, we pass a Lush scalar (-idx0-) whose value can be changed by the LAPACK function

Here's one example use of the above function. (you can find it in the "demos" directory)

;; use the routine "dgesv" to solve a linear equation Ax=b ;; [ 2 -1 1] [-1] ;; [ 3 3 9]*x=[ 0] ;; [ 3 3 5] [ 4] ;; obviously, ;; [ 1] ;; x=[ 2] ;; [-1] (libload "lapack/lapack-d") ;; use the double precision functions (setq A [d [2 3 3][-1 3 3][1 9 5]]) ;; row-wise storage (setq b [d [-1 0 4]]) ;; row-wise storage (let ((ipiv (int-matrix 3)) (n ((int-matrix) 3)) (nrhs ((int-matrix) 1)) (lda ((int-matrix) 3)) (ldb ((int-matrix) 3)) (info ((int-matrix) 0))) (dgesv n nrhs A lda ipiv b ldb info)) (pretty b) ;; the output "x" is stored in "b"

Note that, A is initialized in the way that LAPACK can interpret its content correctly. The syntax to create a scalar (-idx0-) is a little weird: you need to cast a regular number into a scalar. As a syntax sugar, you can also do (if you have a updated Lush):

(setq x [i@ 3])