From jivestgarden at common-lisp.net Fri Jul 10 19:31:26 2009 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Fri, 10 Jul 2009 15:31:26 -0400 Subject: [lisplab-cvs] r56 - doc/manual Message-ID: Author: jivestgarden Date: Fri Jul 10 15:31:25 2009 New Revision: 56 Log: A lot more writing on the manual Modified: doc/manual/lisplab.texi Modified: doc/manual/lisplab.texi ============================================================================== --- doc/manual/lisplab.texi (original) +++ doc/manual/lisplab.texi Fri Jul 10 15:31:25 2009 @@ -27,8 +27,7 @@ @menu * Introduction:: -* Dependencies:: -* Installing:: +* Getting started:: * Tutorial:: * Structure:: * Index:: @@ -38,98 +37,93 @@ @node Introduction @chapter Introduction -Lisplab is a mathematics library in Common Lisp. Common Lisp -is a general purpose programming. The purpose -of Lisplab is to specialize Common Lisp towards mathematics. +Lisplab is a mathematics library in Common Lisp and offers +an easy-to-use and rich programming framework with linear algebra, +Fast Fourier Transform, Special functions, Runge-Kutta solver, +infix notation, and general matrix utility functions. The name Lisplab is inspired by Matlab and Lisplab offers much of the same kind of programming style as Matlab, with high level manipulation of matrices. Contrary to Matlab, Lisplab can do a -lot other than just matrix manipulation because Lisplab is +lot more than just matrix manipulation because Lisplab is based on Common Lisp. Hence, you get all -the benefits of programming in a lexically scoped, dynamic, and fast -general purpose programming language, not bound to the idiom -of @i{everything's a matrix}. +the benefits of lexical scope, dynamic scope, macros, CLOS, fast execution, +and working in an free general purpose programming language. And +best of all: you can enjoy you favorite data-types in addition +to the matrices: functions, hash tables, structures, +classes, arbitrary precision +integers, rationals, and lists. Note that Lisplab is not unique in building Matlab-like -syntax on top of Common Lisp. Lisplab contains much code from +syntax on top of Common Lisp. Lisplab contains code from Matlisp, but has also a lot of new code, refactored -code and rewritten code. Other libraries of similar nature +code and rewritten code. Other Common Lisp matrix libraries are FEMLLISP and NLISP. - at node Dependencies - at chapter Dependencies + at node Getting started + at chapter Getting started + + at section Dependencies Lisplab has been developed with SBCL, SLIME and ASDF on Linux, and there are yet unnecessary bindings to these platforms. @enumerate - at item -Some of the optimized lisp code uses the SBCL macro - at code{truly-the}. This must be dealt with. - - at item -The FFTW FFI is only for SBCL. - - at item -The Matlisp FFI should be portable to other lisps and + at item Some of the optimized lisp code uses the +SBCL macro @code{truly-the}. This must be dealt with. + at item The FFTW FFI is only for SBCL. + at item The Matlisp FFI should be portable to other lisps and Windows, but it has not been tested. - + at item The @code{*READ-DEFAULT-FLOAT-FORMAT*} must be @code{double-float}. @end enumerate In order to enjoy the full power of Lisplab you must install some foreign libraries. These are @enumerate @item -BLAS -- Basic Linear Algebra Subprograms. Preferably the Atlas build +BLAS -- Basic Linear Algebra Subprograms. Preferably the Atlas build. @item -LAPACK -- Matrix library. Preferably the Atlas build - +LAPACK -- Matrix library. Preferably the Atlas build. @item FFTW -- The fastest Fast Fourier Transform available. @end enumerate + at section Installing +Lisplab is ASDF installable, but before you come so far you need to +specify the location of the foreign libraries. +You specify these in three special variables, + at itemize + at item *lisplab-libblas-path* + at item *lisplab-liblapack-path* + at item *lisplab-libfftw-path* + at end itemize +that live their lives in the Common-Lisp-User package. +You can either assign them on the top-level, in you Common Lisp +installation file, in @code{start.lisp}, or +probably the easiest: directly in @code{lisplab.asd}. - at node Installing - at chapter Installing -Lisplab is ASDF installable, but the installations is -more complicated than most Common Lisp libraries because of -the external dependencies. Lisplab has of the following -ASDF systems - at enumerate +ASDF sub-systems + at itemize @item @emph{Lisplab} -- the full Lisplab installation. - @item @emph{Lisplab-base} -- -the part of Lisplab without external dependencies. It should run -on all platforms. - +the part of Lisplab without external dependencies. @item @emph{Lisplab-matlisp} -- FFIs to BLAS and LAPACK. These are modified version from Matlisp. - @item @emph{Lisplab-fftw} -- FFI to FFTW for Fast Fourier Transform. - @item Slatec -- special functions, generated from Fortran by f2cl. Originally made for Maxima. - @item Quadpack -- integration routines, generated from Fortran by f2cl. - at end enumerate + at end itemize -The simplest way to install Lisplab is to load @code{start.lisp}. +The simplest way to test Lisplab is to load @code{start.lisp}. If you have problems loading, first look at @code{start.lisp} -and see if you can hack it. -The foreign libraries are also loaded by ASDF and it takes -the file pathnames from the file @code{libs.lisp}. +and see if you can hack it. Then look at @code{lisplab.asd}. - at node Tutorial - at chapter Tutorial -The main package of Lisplab is @i{lisplab}, with nickname @i{ll}. -The tutorial assues that you are in the @i{lisplab} package or -use it. @section Naming conventions The matrix classes and constructors follow the naming convention @@ -145,21 +139,193 @@ @xref{Structure}, for more about the naming conventions of matrix structure. There you also see the naming conventions for -files. +files, with level0 to level3. + + + at section Status - past and future +The purpose of Lisplab +is to provide a complete mathematics programming environment, +not just linear algebra. Currently it contains a fairly +large matrix manipulation basis and linear algebra, +as well as fast Fourier transform and special functions. +It lacks special matrices, such as diagonal, tridiagonal, +and sparse matrices. + +Lisplab started as a refactoring of Matlisp, but +I ended up by reimplementing most of it, keeping +only the interfaces to Blas and Lapack. Currently, +Lisplab and Matlisp have more or less the same functionality. +Lisplab differ from Matlisp in the following ways + at itemize + at item Layered structure (@xref{Structure}.) + at item Shorter names. + at item Using the standard Lapack and Blas libraries, not a special build. + at item Native Common Lisp linear algebra implementations. + at end itemize + +The future I will mainly do minor changes and bug-fixes, +since it now covers my basic needs. I will only add new +modules when needed. + + +However, there are many exiting extensions that can be made, +such as + at itemize + at item Parallel computation, e.g. using MPI. + at item More native linear algebra routines, e.g. with eigenvalues. + at item New non-matrix algebra items, e.g. quaternions, polynomes or +arbitrary precision floats. + at item Symbolic manipulation. Could make something like + at i{ginac} in @code{c++}. + at item Other Common Lisp libraries, e.g. image processing libraries. + at end itemize + +Please contact if you want to contribute. + + + at node Tutorial + at chapter Tutorial + + at section Starting +To test Lisplab open Emacs and Slime in the lisplab directory. + at example +CL-USER> (load "start.lisp") +CL-USER> (in-package :ll) + at end example +The main package of Lisplab is @i{lisplab}, with nickname @i{ll}. +The tutorial assues that you are in the @i{lisplab} package or +use it. + + @section Basic algebra +Central in Lisplab is an algebra with the functions + at code{.+}, @code{.-}, @code{.*}, @code{./}, and @code{.^}. +These are generalization of + at code{+}, @code{-}, @code{*}, @code{/}, and @code{^}. +For numbers they work the same, + at example +LL> (.+ 1 2) +3 + at end example +The functions @code{.+}, @code{.-}, @code{.*}, @code{./}, and @code{.^} +are mainly wrappers that call @code{reduce} on its arguments with the +generic functions + at code{.add}, @code{.sub}, @code{.mul}, @code{.div}, and @code{.expt}. +If you want to extend the algebra, e.g. with polynomials, +you should add specializing methods to these generic functions. @section Matrix classes +The matrix classes hierarchy has three lines of inheritance. The +first is on structure, the second is on element type, and +the third is on implementation. This hierarchy is similar +to the stream example in Object-Oriented Programming in Common Lisp, +by Sonya E. Keene. + +The most common classes are @code{matrix-dge} which +is a general, double-float matrix with any implementation +and @code{matrix-zge} which is a +general, complex double-float matrix with any implementation. + +The best way to inspect the class structure is to play +with the low level constructor @code{make-matrix-instance}, +for example, + at example +LL> (make-matrix-instance '(:z :ge :any) '(2 2) 1) +# + at end example +where types are :d, :z, or :any, structure is :ge or :d, +and implementation is :any, :lisp, :blas. Not all combinations +have a class, since not all combinations are usefull. More types +and structures will be added in the future. + +Note that with these three lines of inheritance there +are potentially incredibly many potential class. Let's +say we have 10 structures, 10 types and 4 implementations, giving +400 classes. Not all of these are useful and not all are created +by default. To add new classes in a structured way, + at xref{Structure}. @section Matrix construction -Lisplab offers a very many ways to create a matrix. - +The constructor @code{make-matrix-instance} is not +the primary choice to create a matrix. Its better to use a special +constructor. Try + at example +LL> (dnew 0 2 2) +# + +LL>(drow 1 2) +# + +LL> (dcol 1 2) +# + +LL> (dmat (1 2) (3 4)) +# + at end example +where @code{dnew}, @code{dcol}, and @code{drow} are functions, +while @code{dmat} is a macro. Similarly, there are + at code{znew}, @code{zcol}, @code{zrow}, and @code{zmat} +for double float matrices and + at code{mnew}, @code{mcol}, @code{mrow}, and @code{mmat} +for any matrices. The latter take matrix class as first argument. + +Often you want to create a matrix of the same type as a input +matrix. Then you can use @code{mcreate}. It's mainly useful when +creating methods that should operate on many matrix types. + +To create matrices from something else, use @code{convert} + at example +LL> (convert '((1 2) (3 4)) '(:d :ge :any)) +# + at end example + at code{Convert} also converts between matrix types. If the +matrix contents cannot be converted directly (e.g., conversion +from complex to real), use @code{copy-contents} instead. + + at section Matrix element reference +To access a matrix element use the generic function @code{mref} + at example +LL> (mref (dmat (1 2) (3 4)) 0 1) +2.0 + at end example +Matrix references are zero based. The @code{mref} is settable. + +Furthermore, all matrices can also list their elements as vectors +(similar to row-major-aref for arrays). To access a matrix as vector +use the generic function @code{vref} + at example +LL> (vref (dmat (1 2) (3 4)) 1) +3.0 + at end example +whcih is also settable. Note that the matrices are column major order. @section Matrix manipulation + at section Matrices without store + @section Ordinary functions @section Special functions + at section Infix notation + @node Structure @chapter Structure From jivestgarden at common-lisp.net Sat Jul 11 08:28:33 2009 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Sat, 11 Jul 2009 04:28:33 -0400 Subject: [lisplab-cvs] r57 - src/matrix Message-ID: Author: jivestgarden Date: Sat Jul 11 04:28:32 2009 New Revision: 57 Log: matrix-ge Modified: src/matrix/level1-constructors.lisp Modified: src/matrix/level1-constructors.lisp ============================================================================== --- src/matrix/level1-constructors.lisp (original) +++ src/matrix/level1-constructors.lisp Sat Jul 11 04:28:32 2009 @@ -61,7 +61,8 @@ ;;; Adding all the matrix descriptions -(add-matrix-class 'matrix-ge :any :ge :lisp) +(add-matrix-class 'matrix-base-ge :any :ge :base) +(add-matrix-class 'matrix-ge :any :ge :any) (add-matrix-class 'matrix-base-dge :d :ge :base) (add-matrix-class 'matrix-lisp-dge :d :ge :lisp) From jivestgarden at common-lisp.net Sat Jul 11 09:33:39 2009 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Sat, 11 Jul 2009 05:33:39 -0400 Subject: [lisplab-cvs] r58 - doc/manual Message-ID: Author: jivestgarden Date: Sat Jul 11 05:33:38 2009 New Revision: 58 Log: backup Modified: doc/manual/lisplab.texi Modified: doc/manual/lisplab.texi ============================================================================== --- doc/manual/lisplab.texi (original) +++ doc/manual/lisplab.texi Sat Jul 11 05:33:38 2009 @@ -66,18 +66,18 @@ @section Dependencies Lisplab has been developed with SBCL, SLIME and ASDF on Linux, and there are yet unnecessary bindings to these platforms. - at enumerate + at itemize @item Some of the optimized lisp code uses the SBCL macro @code{truly-the}. This must be dealt with. @item The FFTW FFI is only for SBCL. @item The Matlisp FFI should be portable to other lisps and Windows, but it has not been tested. @item The @code{*READ-DEFAULT-FLOAT-FORMAT*} must be @code{double-float}. - at end enumerate + at end itemize In order to enjoy the full power of Lisplab you must install some foreign libraries. These are - at enumerate + at itemize @item BLAS -- Basic Linear Algebra Subprograms. Preferably the Atlas build. @@ -87,7 +87,7 @@ @item FFTW -- The fastest Fast Fourier Transform available. - at end enumerate + at end itemize @section Installing Lisplab is ASDF installable, but before you come so far you need to @@ -103,7 +103,7 @@ installation file, in @code{start.lisp}, or probably the easiest: directly in @code{lisplab.asd}. -ASDF sub-systems +ASDF sub-systems: @itemize @item @emph{Lisplab} -- the full Lisplab installation. @@ -124,23 +124,43 @@ If you have problems loading, first look at @code{start.lisp} and see if you can hack it. Then look at @code{lisplab.asd}. +To install Blas, Lapack, and FFTW, if you are lazy, and lucky +enough to administer a Debian or Ubuntu machine, +you typically do + at example +# aptitude install libatlas3gf-base +# aptitude install libfftw3-3 + at end example @section Naming conventions + at itemize + at item The matrix classes and constructors follow the naming convention from BLAS where you give names based on element type and matrix structure. - The most used types are @i{f - float}, @i{d - double}, @i{c - complex float}, @i{z - complex double float}, while for matrix structure @i{ge - general}, @i{di - diagonal}, and many more. So @i{matrix-dge} is a general matrix with double float elements, while @i{matrix-zge} is a general matrix with complex double float elements. - + at item +The generic functions of the basic algebra start with period: + at code{.+}, @code{.-}, @code{.*}, @code{./}, @code{.^}, @code{.sin} + at code{.cos}, @code{.tan}, @code{.besj}, @code{.realpart}, etc. +These functions work on numbers as the non-dotted Common Lisp functions +and work element-vise on matrices. + at item +Linear algebra functions tend to start with @i{m}: + at code{m*}, @code{minv}, @code{mmax}, @code{mtp}, etc., +but this conventions is followed only to low degree. + at item +The naming convention of files follow the layered structure of +Lisplab, with level0 to level3. + at item @xref{Structure}, for more about the naming conventions -of matrix structure. There you also see the naming conventions for -files, with level0 to level3. - +of matrix classes. + at end itemize @section Status - past and future The purpose of Lisplab @@ -172,12 +192,14 @@ such as @itemize @item Parallel computation, e.g. using MPI. - at item More native linear algebra routines, e.g. with eigenvalues. + at item More native linear algebra routines, e.g. eigenvalue computation. @item New non-matrix algebra items, e.g. quaternions, polynomes or arbitrary precision floats. @item Symbolic manipulation. Could make something like @i{ginac} in @code{c++}. - at item Other Common Lisp libraries, e.g. image processing libraries. + at item New matrix optimization for new usage, e.g. integer matrices for +image processing or cryptography. + at item Interface to new foreign libraries, e.g. GSL. @end itemize Please contact if you want to contribute. @@ -244,7 +266,7 @@ Note that with these three lines of inheritance there are potentially incredibly many potential class. Let's say we have 10 structures, 10 types and 4 implementations, giving -400 classes. Not all of these are useful and not all are created +400 classes. Not all of these are useful and only few are created by default. To add new classes in a structured way, @xref{Structure}. @@ -314,10 +336,14 @@ LL> (vref (dmat (1 2) (3 4)) 1) 3.0 @end example -whcih is also settable. Note that the matrices are column major order. +which is also settable. Note that the matrices are column major order. @section Matrix manipulation + at section Linear algebra + + at section Matrix IO + @section Matrices without store @section Ordinary functions From jivestgarden at common-lisp.net Mon Jul 20 07:54:51 2009 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Mon, 20 Jul 2009 03:54:51 -0400 Subject: [lisplab-cvs] r59 - doc/manual Message-ID: Author: jivestgarden Date: Mon Jul 20 03:54:44 2009 New Revision: 59 Log: manual Added: doc/manual/Makefile Modified: doc/manual/lisplab.texi Added: doc/manual/Makefile ============================================================================== --- (empty file) +++ doc/manual/Makefile Mon Jul 20 03:54:44 2009 @@ -0,0 +1,9 @@ +source=lisplab.texi + +all: html + +html: $(source) + makeinfo --html $(source) + +pdf: $(source) + texi2pdf $(source) \ No newline at end of file Modified: doc/manual/lisplab.texi ============================================================================== --- doc/manual/lisplab.texi (original) +++ doc/manual/lisplab.texi Mon Jul 20 03:54:44 2009 @@ -338,9 +338,111 @@ @end example which is also settable. Note that the matrices are column major order. - at section Matrix manipulation + at section The dotted algebra +The element-vise functions by conventions have names starting +with a dot (period). The dotted algebra works on the single elements and +is structure agnostic. The functions of the dotted algebra +introduce a programming style +much the same as for Matlab, and combined with the linear algebra +functions, you can write compact programs, without the slower +single element references. + at example +LL> (.sin (drow 0 1)) +# + at end example +And so also for the algebraic operations + at example +LL> (let ((a (drow 0 1)) + (b (dcol 0.1 0.2))) + (.+ a (.* b 2))) +# + at end example +Note here that the @code{.+}, @code{.*}, etc. ignore the structure +so that it is completely valid to add a row and a column matrix. Note +also that the scalar is multiplied element-vise. + +The dotted algebra is to some extent also implemented for +general element matrices + at example +LL> (.+ (row 'matrix-ge 1/2 3/2) 1) +# + at end example + @section Linear algebra +The linear algebra functions (unlike the dotted algebra) +The linear algebra functions often start with @i{m}, although this +conventions is not strictly enforced. Currently there is no a wide +spectrum of linear algebra function, but you find matrix multiplication, +matrix inversion, transpose, conjugate transpose and eigenvalues. + +Matrix multiplications + at example +LL>(let ((a (dmat (1 0) (0 -1))) + (b (dcol 0.1 0.2))) + (m* a b)) +# + at end example +Matrix inversion + at example +LL> (minv (dmat (1 2) (-2 1))) +# + at end example +Transpose + at example +LL> (mtp (dmat (1 2) (-2 1))) +# + at end example +Conjugate transpose + at example +LL> (mct (zmat (1 (* 2 %i)) (-2 1))) +# + at end example +Eigenvalues + at example +LL> (eigenvalues (dmat (1 2) (0 0.5))) +# + at end example +Eigenvectors + at example +LL> (eigenvectors (dmat (1 2) (0 0.5))) +(# + #) + at end example + +Some of the linear algebra functions also work for +general element matrices + at example + + at end example + @section Matrix IO From jivestgarden at common-lisp.net Mon Jul 20 10:47:37 2009 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Mon, 20 Jul 2009 06:47:37 -0400 Subject: [lisplab-cvs] r60 - src/matrix Message-ID: Author: jivestgarden Date: Mon Jul 20 06:47:34 2009 New Revision: 60 Log: remove unused Removed: src/matrix/level1-funmat.lisp Modified: src/matrix/level2-funmat.lisp Modified: src/matrix/level2-funmat.lisp ============================================================================== --- src/matrix/level2-funmat.lisp (original) +++ src/matrix/level2-funmat.lisp Mon Jul 20 06:47:34 2009 @@ -64,7 +64,7 @@ (defmethod view-col (matrix col) "Outputs a function matrix" - (make-instance 'function-matrix + (make-instance 'function-matrix :rows (rows matrix) :cols 1 :size (rows matrix) From jivestgarden at common-lisp.net Mon Jul 20 10:55:01 2009 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Mon, 20 Jul 2009 06:55:01 -0400 Subject: [lisplab-cvs] r61 - src/matrix Message-ID: Author: jivestgarden Date: Mon Jul 20 06:54:56 2009 New Revision: 61 Log: matrix views Modified: lisplab.asd src/matrix/level2-funmat.lisp Modified: lisplab.asd ============================================================================== --- lisplab.asd (original) +++ lisplab.asd Mon Jul 20 06:54:56 2009 @@ -68,7 +68,9 @@ (:file "level2-generic") (:file "level2-matrix-dge") (:file "level2-matrix-zge") - (:file "level2-array-functions"))) + (:file "level2-array-functions") + (:file "level2-funmat") + )) ;; ;; IO (level 3) Modified: src/matrix/level2-funmat.lisp ============================================================================== --- src/matrix/level2-funmat.lisp (original) +++ src/matrix/level2-funmat.lisp Mon Jul 20 06:54:56 2009 @@ -28,8 +28,6 @@ (make-instance 'function-matrix :rows rows :cols cols - :size size - :element-type (element-type matrix) :mref #'(lambda (x i j) (declare (ignore x)) (vref matrix (column-major-idx i j rows))) @@ -47,8 +45,6 @@ (make-instance 'function-matrix :rows (cols matrix) :cols 1 - :size (cols matrix) - :element-type (element-type matrix) :mref #'(lambda (x i j) (declare (ignore x j)) (mref matrix row i)) @@ -67,8 +63,6 @@ (make-instance 'function-matrix :rows (rows matrix) :cols 1 - :size (rows matrix) - :element-type (element-type matrix) :mref #'(lambda (x i j) (declare (ignore x j)) (mref matrix i col)) From jivestgarden at common-lisp.net Mon Jul 20 19:23:18 2009 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Mon, 20 Jul 2009 15:23:18 -0400 Subject: [lisplab-cvs] r62 - in doc: html manual Message-ID: Author: jivestgarden Date: Mon Jul 20 15:23:09 2009 New Revision: 62 Log: manual and html Added: doc/html/ doc/html/index.html Modified: doc/manual/lisplab.texi Added: doc/html/index.html ============================================================================== --- (empty file) +++ doc/html/index.html Mon Jul 20 15:23:09 2009 @@ -0,0 +1,86 @@ + + + + + LISPLAB project + + + + + +
+

LISPLAB

+

Mathematics library for Common Lisp

+
+ +

Introduction

+

+ Lisplab is a mathematics library in common lisp + released under the GNU General Public License (GPL). + Lisplab is based on code from Matlisp + to interface Blas/Lapack for computations, but has also a lots + of code written natively in Common Lisp in addition. The main purpose + of the library is to integration various sources + of mathematical software to a convenient platform for computations. + The sources of software include +

    +
  • Interfaces to BLAS and LAPACK. +
  • Interface to FFTW. +
  • Numerical integration from QUADPACK and F2CL. +
  • Special functions from SLATEC and F2CL. +
  • A lot of additional routines, for linear algebra, IO, fft, etc. +
+

+

+ The part of Lisplab which is most mature is the matrix and linear algebra, + and these should provide a good basis for matrix based modelling. + The interfaces to Blas/Matlisp are only to low degree finished. + However, new methods here should be quite easily added. +

+ +

Documentation

+ Module documentation with Tinaa +is here. + +

Mailing Lists

+ + +

Download

+

+ This project has no stable releases. For latest unstable + code please checkout from Subversion. +

+ +

Subversion

+

+ You can get the latest version of the source code from subversion +

+   svn checkout svn://common-lisp.net/project/lisplab/svn lisplab
+ 
+ or browse it + here. +

+ + + + + Modified: doc/manual/lisplab.texi ============================================================================== --- doc/manual/lisplab.texi (original) +++ doc/manual/lisplab.texi Mon Jul 20 15:23:09 2009 @@ -440,19 +440,74 @@ Some of the linear algebra functions also work for general element matrices @example - +LL> (let ((a (mat 'matrix-ge (1 0) (0 -1))) + (b (col 'matrix-ge 1/2 2/3))) + (m* a b)) +# +LL> (minv (mat 'matrix-ge (1 2)(-2 1))) +# @end example @section Matrix IO +Delimited files are read with @code{dlmread}. Delimited files +are written with @code{dlmwrite}. You can also write matrices +as images with @code{pgmwrite} and @code{pswrite}, writing +portable graymap and postscript respectively. + +Note that the IO functions are currently in a poor state. @section Matrices without store +The class @code{function-matrix} implements matrices with +functions and has no store. + +The contents can for example be given directly by a rule, +using the macro funmat + at example +LL> (funmat '(2 2) (i j) (if (= i j) 1 0)) +# + at end example +The funmat (and its generalization @code{fmat} that creates any matrix type) +it also useful to create grids. + +Function matrices are also used to view a part or restructured other matrix +with @code{view-matrix}, @code{view-col}, or @code{view-row}. @section Ordinary functions +These are: + at code{.sin}, @code{.cos}, @code{.sin}, @code{.tan}, + at code{.sinh}, @code{.cosh}, @code{.sinh}, @code{.tanh}, + at code{.conj}, + at code{.realpart}, @code{.imagpart}, @code{.exp}, @code{.abs}. + +TODO: add the inverse functions. @section Special functions +These are: + at code{.besj}, @code{.besy}, + at code{.besi}, @code{.besk}, + at code{.besh1}, @code{.besh2}, + at code{.ai}. @section Infix notation +Infix input is with the macro @code{w/infix}. + at example +(w/infix + (let ((x 3)) + (1 .+ 2 .* x))) + at end example +The @code{w/infix} messes as little as possible with the Lisp +semantics, so that if you have a lot of formulas just wrap all +of it inside the macro. @node Structure From jivestgarden at common-lisp.net Mon Jul 20 19:30:11 2009 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Mon, 20 Jul 2009 15:30:11 -0400 Subject: [lisplab-cvs] r63 - in src: core matrix Message-ID: Author: jivestgarden Date: Mon Jul 20 15:30:10 2009 New Revision: 63 Log: More ordinary functions Modified: src/core/level0-functions.lisp src/core/level0-interface.lisp src/matrix/level2-array-functions.lisp src/matrix/level2-generic.lisp src/matrix/level2-interface.lisp src/matrix/level2-matrix-dge.lisp src/matrix/level2-matrix-zge.lisp Modified: src/core/level0-functions.lisp ============================================================================== --- src/core/level0-functions.lisp (original) +++ src/core/level0-functions.lisp Mon Jul 20 15:30:10 2009 @@ -56,6 +56,12 @@ "Generlized expt. Reduces the arguments with .expt." (reduce #'.expt args)) +(defmethod .max ((a number) (b number)) + (max a b)) + +(defmethod .min ((a number) (b number)) + (min a b)) + (defmethod .abs ((a number)) (abs a)) @@ -100,8 +106,6 @@ (defmethod .sub ((a number) (b number)) (- a b)) - - (defmethod .expt ((a number) (b number)) (expt a b)) @@ -126,6 +130,21 @@ (defmethod .tan ((x real)) (tan (to-df x))) +(defmethod .asin ((x real)) + (asin (to-df x))) + +(defmethod .acos ((x number)) + (acos x)) + +(defmethod .acos ((x real)) + (acos (to-df x))) + +(defmethod .atan ((x number)) + (atan x)) + +(defmethod .atan ((x real)) + (atan (to-df x))) + (defmethod .log ((x number) &optional (base nil)) (if base (log x base) @@ -142,6 +161,19 @@ (defmethod .exp ((x real)) (exp (to-df x))) +(defmethod .sqr ((x number)) + (* x x)) + +(defmethod .sqr ((x real)) + (let ((x (to-df x))) + (* x x))) + +(defmethod .sqrt ((x number)) + (sqrt x)) + +(defmethod .sqrt ((x real)) + (sqrt (to-df x))) + (defmethod .sinh ((x number)) (sinh x)) @@ -160,6 +192,24 @@ (defmethod .tanh ((x real)) (tanh (to-df x))) +(defmethod .asinh ((x number)) + (asinh x)) + +(defmethod .asinh ((x real)) + (asinh (to-df x))) + +(defmethod .acosh ((x number)) + (acosh x)) + +(defmethod .acosh ((x real)) + (acosh (to-df x))) + +(defmethod .atanh ((x number)) + (atanh x)) + +(defmethod .atanh ((x real)) + (atanh (to-df x))) + Modified: src/core/level0-interface.lisp ============================================================================== --- src/core/level0-interface.lisp (original) +++ src/core/level0-interface.lisp Mon Jul 20 15:30:10 2009 @@ -23,6 +23,7 @@ (export '(copy convert scalar? vector? matrix? + .max .min .abs .imagpart .realpart .= ./= .< .<= .> .>= .add .add! @@ -30,11 +31,13 @@ .div .div! .sub .sub! .expt .expt! - .conj .sin .cos .tan + .asin .acos .atan .sinh .cosh .tanh + .asinh .acosh .atanh .log .exp + .sqr .sqrt .Ai .besj .besy .besi .besk .besh1 .besh2 .erf .erfc @@ -56,6 +59,13 @@ (defgeneric convert (x type) (:documentation "Converts the object to the specified type. Non-destructive.")) + +(defgeneric .max (a b) + (:documentation "Generialized max.")) + +(defgeneric .min (a b) + (:documentation "Generialized min.")) + (defgeneric .abs (a) (:documentation "Generialized abs.")) @@ -118,6 +128,7 @@ ;;; Ordinary functions + (defgeneric .sin (x) (:documentation "Sine function : sin(x).")) @@ -127,12 +138,27 @@ (defgeneric .tan (x) (:documentation "Tangent function : tan(x).")) +(defgeneric .asin (x) + (:documentation "Inverse sine function : asin(x).")) + +(defgeneric .acos (x) + (:documentation "Inverse cosine function : acos(x).")) + +(defgeneric .atan (x) + (:documentation "Inverse tangent function : atan(x).")) + (defgeneric .log (x &optional base) (:documentation "Logarithm function")) (defgeneric .exp (x) (:documentation "Exponential function : exp(x).")) +(defgeneric .sqr (x) + (:documentation "Square.")) + +(defgeneric .sqrt (x) + (:documentation "Square root.")) + (defgeneric .sinh (x) (:documentation "Hyperbolic sine function : sinh(x).")) @@ -142,6 +168,15 @@ (defgeneric .tanh (x) (:documentation "Hyperbolic tangent function : tanh(x).")) +(defgeneric .asinh (x) + (:documentation "Inverse hyperbolic sine function : asinh(x).")) + +(defgeneric .acosh (x) + (:documentation "Inverse hyperbolic cosine function : acosh(x).")) + +(defgeneric .atanh (x) + (:documentation "Inverse hyperbolic tangent function : atanh(x).")) + ;;; Special functions Modified: src/matrix/level2-array-functions.lisp ============================================================================== --- src/matrix/level2-array-functions.lisp (original) +++ src/matrix/level2-array-functions.lisp Mon Jul 20 15:30:10 2009 @@ -153,6 +153,16 @@ (defmethod .tan ((x array)) (each-array-element-df-to-df x (.tan x))) +(defmethod .asin ((x array)) + (each-array-element-df-to-df x (.asin x))) + +(defmethod .acos ((x array)) + (each-array-element-df-to-df x (.acos x))) + +(defmethod .atan ((x array)) + (each-array-element-df-to-df x (.atan x))) + + ;;; Hyperbolic functions (defmethod .sinh ((x array)) @@ -164,6 +174,17 @@ (defmethod .tanh ((x array)) (each-array-element-df-to-df x (.tanh x))) +(defmethod .asinh ((x array)) + (each-array-element-df-to-df x (.asinh x))) + +(defmethod .acosh ((x array)) + (each-array-element-df-to-df x (.acosh x))) + +(defmethod .atanh ((x array)) + (each-array-element-df-to-df x (.atanh x))) + +;;; Log and exponent + (defmethod .log ((x array) &optional base) (each-array-element-df-to-df x (.log x base))) @@ -192,243 +213,3 @@ (defmethod .besh2 (n (x array)) (each-array-element-df-to-complex-df x (.besh2 n x))) - - - -#| - - - -(defmacro define-array-binary-bool-operator (new old) - (let ((a (gensym)) - (b (gensym)) - (i (gensym))) - `(progn - - ;; two arrays - (defmethod ,new ((,a array) (,b array)) - (if (and (eql (element-type ,a) 'double-float) - (subtypep (type-of ,a) 'simple-array) - (eql (element-type ,b) 'double-float) - (subtypep (type-of ,b) 'simple-array)) - (let () - (declare (type (simple-array double-float) ,a ,b)) - (dotimes (,i (min (size ,a) (size ,b)) t) - (unless (,old (row-major-aref ,a ,i) - (row-major-aref ,b ,i)) - (return-from ,new nil)))) - (dotimes (,i (min (size ,a) (size ,b)) t) - (unless (,new (vref ,a ,i) - (vref ,b ,i)) - (return-from ,new nil))))) - - ;; array and number - (defmethod ,new ((,a array) (,b number)) - (if (and (eql (element-type ,a) 'double-float) - (subtypep (type-of ,a) 'simple-array) - (eql (element-type ,b) 'double-float) - (subtypep (type-of ,b) 'simple-array)) - (let () - (declare (type (simple-array double-float) ,a ,b)) - (dotimes (,i (min (size ,a) (size ,b)) t) - (unless (,old (row-major-aref ,a ,i) - (row-major-aref ,b ,i)) - (return-from ,new nil)))) - (dotimes (,i (min (size ,a) (size ,b)) t) - (unless (,new (vref ,a ,i) - (vref ,b ,i)) - (return-from ,new nil))))) - - ;; number and array - (defmethod ,new ((,a number) (,b array)))))) - -(define-array-binary-bool-operator .< <) - - -#+nil (defun combine-types (a b) - (typecase a - (double-float - (typecase b - ((complex double-float) '(complex double-float)) - (complex 'complex) - (t 'double-float))) - ((complex double-float) - (typecase b - ((complex double-float) '(complex double-float)) - (complex 'complex) - (t '(complex double-float)))) - (t t))) - - -(defmethod .add ((a array) (b array)) - (if (and (eql (element-type a) 'double-float) - (subtypep (type-of a) 'simple-array) - (eql (element-type b) 'double-float) - (subtypep (type-of b) 'simple-array)) - (let ((c (copy a))) - (declare ((simple-array double-float) b c)) - (dotimes (i (min (size c) (size a))) - (setf (row-major-aref c i) - (+ (row-major-aref c i) (row-major-aref a i)))) - c) - (let ((c (create a t))) - (dotimes (i (min (size c) (size a))) - (setf (vref c i) - (.+ (vref c i) (vref a i)))) - c))) - -(defmethod .add ((a array) (b number)) - (if (and (eql (element-type a) 'double-float) - (subtypep (type-of a) 'simple-array) - (realp b)) - (let ((b (coerce b 'double-float)) - (c (copy a))) - (declare ((simple-array double-float) c)) - (dotimes (i (size c)) - (setf (row-major-aref c i) - (+ (row-major-aref c i) b))) - c) - (let ((c (create a t))) - (dotimes (i (size c)) - (setf (vref c i) - (.+ (vref c i) b))) - c))) - -(defmethod .add ((a number) (b array)) - (if (and (eql (element-type b) 'double-float) - (subtypep (type-of b) 'simple-array) - (realp a)) - (let ((b (coerce a 'double-float)) - (c (copy b))) - (declare ((simple-array double-float) c)) - (dotimes (i (size c)) - (setf (row-major-aref c i) - (+ b (row-major-aref c i)))) - c) - (let ((c (create a t))) - (dotimes (i (min (size c) (size a))) - (setf (vref c i) - (.+ b (vref c i)))) - c))) - - - - - -(defmethod .add ((a array) (b number)) - (if (and (eql (element-type a) 'double-float) - (subtypep (type-of a) 'simple-array) - (realp - (subtypep (type-of b) 'simple-array)) - (let ((c (copy a))) - (declare ((simple-array double-float) a c)) - (dotimes (i (min (size c) (size a))) - (incf (row-major-aref c i) (row-major-aref a i)))) - (let ((c (copy a))) - (dotimes (i (min (size c) (size a))) - (setf (vref c i) - (.+ (vref c i) (vref a i)))) - c))) - - - - -(defmethod .= (a b &optional (acc LEAST-POSITIVE-NORMALIZED-DOUBLE-FLOAT )) - (cond ((scalar? b) - (dotimes (i (size a)) - (when (>= (abs (- (vref a i) b)) acc) - (return-from .= nil))) - t) - ((scalar? a) - (dotimes (i (size b)) - (when (>= (abs (- a (vref b i))) acc) - (return-from .= nil))) - t) - ((= (size a) (size b)) - (dotimes (i (size a)) - (when (>= (abs (- (vref a i) (vref b i))) acc) - (return-from .= nil))) - t) - (t nil))) - -(defmacro def-bin-bool-op-default (op) - "Makes a non-specialized binary method with op which applies op on all elements -and returns true if it holds for all elements, nil otherwise." - (let ((a (gensym)) - (b (gensym)) - (i (gensym))) - `(defmethod ,op (,a ,b) - (cond ((scalar? ,b) - (dotimes (,i (size ,a)) - (unless (,op (vref ,a ,i) ,b) - (return-from ,op nil))) - t) - ((scalar? ,a) - (dotimes (,i (size ,b)) - (unless(,op ,a (vref ,b ,i)) - (return-from ,op nil))) - t) - ((= (size ,a) (size ,b)) - (dotimes (,i (size ,a)) - (unless (,op (vref ,a ,i) (vref ,b ,i)) - (return-from ,op nil))) - t) - (t nil))))) - -(def-bin-bool-op-default .<) - -(def-bin-bool-op-default .<=) - -(def-bin-bool-op-default .>) - -(def-bin-bool-op-default .>=) - -(defmacro def-function-default (fun) - (let ((a (gensym)) - (b (gensym)) - (i (gensym))) - `(defmethod ,fun (,a) - (let ((,b (copy ,a))) - (dotimes (,i (size ,b)) - (setf (vref ,b ,i) (,fun (vref ,b ,i)))) - ,b)))) - -(def-function-default .imagpart) - -(def-function-default .realpart) - -(def-function-default .abs) - -(defmacro def-bin-op-default (new) - (let ((i (gensym "i")) - (a (gensym "a")) - (b (gensym "b"))) - `(defmethod ,new (,a ,b) - (cond ((scalar? ,a) - (let ((,b (copy ,b))) - (dotimes (,i (size ,b)) - (setf (vref ,b ,i) (,new ,a (vref ,b ,i)))) - ,b)) - ((scalar? ,b) - (let ((,a (copy ,a))) - (dotimes (,i (size ,a)) - (setf (vref ,a ,i) (,new (vref ,a ,i) ,b))) - ,a)) - (t - (let ((,a (copy ,a))) - (dotimes (,i (size ,a)) - (setf (vref ,a ,i) (,new (vref ,a ,i) (vref ,b ,i)))) - ,a)))))) - -(def-bin-op-default .add) - -(def-bin-op-default .mul) - -(def-bin-op-default .sub) - -(def-bin-op-default .div) - -(def-bin-op-default .expt) - - -|# \ No newline at end of file Modified: src/matrix/level2-generic.lisp ============================================================================== --- src/matrix/level2-generic.lisp (original) +++ src/matrix/level2-generic.lisp Mon Jul 20 15:30:10 2009 @@ -47,6 +47,26 @@ (setf (mref b i j) (funcall converter (mref a i j)))) b)) +(defmethod sub-matrix (m rr cc) + (unless (cddr rr) + (setf rr (cons (car rr) (cons 1 (cdr rr))))) + (unless (cddr cc) + (setf cc (cons (car cc) (cons 1 (cdr cc))))) + (destructuring-bind (r0 r-step r1) rr + (destructuring-bind (c0 c-step c1) cc + (when (>= r1 (rows m)) + (setf r1 (1- (rows m)))) + (when (>= c1 (cols m)) + (setf c1 (1- (cols m)))) + (let* ((rows (1+ (floor (- r1 r0) r-step))) + (cols (1+ (floor (- c1 c0) c-step))) + (m1 (mcreate m 0 (list rows cols)))) + (dotimes (i rows) + (dotimes (j cols) + (setf (mref m1 i j) + (mref m (+ r0 (* r-step i)) (+ c0 (* c-step j)))))) + m1)))) + (defmethod .some (pred (a matrix-base) &rest args) (dotimes (i (size a)) (when (apply pred (mapcar (lambda (x) (vref x i)) (cons a args))) @@ -292,12 +312,21 @@ (defmethod .tanh ((x matrix-ge)) (each-element-function-matrix-ge x (.tanh x))) +;;; Logarithms and exponents + (defmethod .log ((x matrix-ge) &optional base) (each-element-function-matrix-ge x (.log x base))) (defmethod .exp ((x matrix-ge)) (each-element-function-matrix-ge x (.exp x))) +(defmethod .sqr ((x matrix-ge)) + (each-element-function-matrix-ge x (.sqr x))) + +(defmethod .sqrt ((x matrix-ge)) + (each-element-function-matrix-ge x (.sqrt x))) + + ;;; Bessel functions (defmethod .besj (n (x matrix-ge)) Modified: src/matrix/level2-interface.lisp ============================================================================== --- src/matrix/level2-interface.lisp (original) +++ src/matrix/level2-interface.lisp Mon Jul 20 15:30:10 2009 @@ -40,6 +40,7 @@ view-vector-as-matrix view-transpose msum mmin mmax mabsmin mabsmax + sub-matrix ; To level3 ? circ-shift pad-shift)) @@ -49,6 +50,10 @@ (defgeneric .every (pred a &rest matrices) (:documentation "Generalizes every.")) +(defgeneric sub-matrix (m rr cc) + (:documentation "Copies a sub matrix of m. The format of rr = (start stop) or rr = (start step stop) +and the same for the coulumns.")) + (defgeneric copy-contents (a b &optional converter) (:documentation "Copies all elements from a to b.")) Modified: src/matrix/level2-matrix-dge.lisp ============================================================================== --- src/matrix/level2-matrix-dge.lisp (original) +++ src/matrix/level2-matrix-dge.lisp Mon Jul 20 15:30:10 2009 @@ -40,6 +40,16 @@ (matrix-store a) (mapcar #'matrix-store args)) b)) +(defmethod msum ((m matrix-base-dge)) + (let ((sum 0.0) + (m0 (matrix-store m))) + (declare (type double-float sum) + (type type-blas-store m0)) + (dotimes (i (length m0)) + (incf sum (aref m0 i))) + sum)) + + (defmethod .imagpart ((a matrix-base-dge)) (mcreate a 0)) @@ -114,6 +124,10 @@ (def-binary-op-matrix-base-dge .expt expt) +(def-binary-op-matrix-base-dge .max max) + +(def-binary-op-matrix-base-dge .min min) + (defmacro each-matrix-element-df-to-df (x form) "Applies a form on each element of an matrix-dge. The form must make real output for real arguments" @@ -155,6 +169,15 @@ (defmethod .tan ((x matrix-base-dge)) (each-matrix-element-df-to-df x (tan x))) +(defmethod .asin ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (asin x))) + +(defmethod .acos ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (acos x))) + +(defmethod .atan ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (atan x))) + ;;; Hyperbolic functions (defmethod .sinh ((x matrix-base-dge)) @@ -166,6 +189,17 @@ (defmethod .tanh ((x matrix-base-dge)) (each-matrix-element-df-to-df x (tanh x))) +(defmethod .asinh ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (asinh x))) + +(defmethod .acosh ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (acosh x))) + +(defmethod .atanh ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (atanh x))) + +;;; Logarithm and exponent + (defmethod .log ((x matrix-base-dge) &optional base) (if base (each-matrix-element-df-to-df x (log x base)) @@ -174,6 +208,12 @@ (defmethod .exp ((x matrix-base-dge)) (each-matrix-element-df-to-df x (exp x))) +(defmethod .sqr ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (* x x))) + +(defmethod .sqrt ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (sqrt x))) + ;;; Bessel functions (defmethod .besj (n (x matrix-base-dge)) @@ -192,4 +232,16 @@ (each-matrix-element-df-to-complex-df x (.besh1 n x))) (defmethod .besh2 (n (x matrix-base-dge)) - (each-matrix-element-df-to-complex-df x (.besh2 n x))) \ No newline at end of file + (each-matrix-element-df-to-complex-df x (.besh2 n x))) + +;;; Other spacial functions + +(defmethod .erf ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (.erf x))) + +(defmethod .erfc ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (.erfc x))) + +(defmethod .gamma ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (.gamma x))) + Modified: src/matrix/level2-matrix-zge.lisp ============================================================================== --- src/matrix/level2-matrix-zge.lisp (original) +++ src/matrix/level2-matrix-zge.lisp Mon Jul 20 15:30:10 2009 @@ -32,6 +32,17 @@ :rows (rows matrix) :cols (cols matrix))) +(defmethod msum ((m matrix-base-zge)) + (let ((sum-r 0.0) + (sum-i 0.0) + (m0 (matrix-store m))) + (declare (type double-float sum-r sum-i) + (type type-blas-store m0)) + (loop for i from 0 below (length m0) by 2 do + (incf sum-r (aref m0 i)) + (incf sum-i (aref m0 (1+ i)))) + (complex sum-r sum-i))) + (defmethod .imagpart ((a matrix-base-zge)) (let* ((description (create-matrix-description a :et :d)) (b (make-matrix-instance description (dim a) 0))) @@ -161,6 +172,15 @@ (defmethod .tan ((x matrix-base-zge)) (each-element-function-matrix-base-zge x (tan x))) +(defmethod .asin ((x matrix-base-zge)) + (each-element-function-matrix-base-zge x (asin x))) + +(defmethod .acos ((x matrix-base-zge)) + (each-element-function-matrix-base-zge x (acos x))) + +(defmethod .atan ((x matrix-base-zge)) + (each-element-function-matrix-base-zge x (atan x))) + ;;; Hyperbolic functions (defmethod .sinh ((x matrix-base-zge)) @@ -172,6 +192,17 @@ (defmethod .tanh ((x matrix-base-zge)) (each-element-function-matrix-base-zge x (tanh x))) +(defmethod .asinh ((x matrix-base-zge)) + (each-element-function-matrix-base-zge x (asinh x))) + +(defmethod .acosh ((x matrix-base-zge)) + (each-element-function-matrix-base-zge x (acosh x))) + +(defmethod .atanh ((x matrix-base-zge)) + (each-element-function-matrix-base-zge x (atanh x))) + +;;; Logarithm and exponent + (defmethod .log ((x matrix-base-zge) &optional base) (if base (each-element-function-matrix-base-zge x (log x base)) @@ -180,6 +211,12 @@ (defmethod .exp ((x matrix-base-zge)) (each-element-function-matrix-base-zge x (exp x))) +(defmethod .sqr ((x matrix-base-zge)) + (each-element-function-matrix-base-zge x (* x x))) + +(defmethod .sqrt ((x matrix-base-zge)) + (each-element-function-matrix-base-zge x (sqrt x))) + ;;; Bessel functions (defmethod .besj (n (x matrix-base-zge)) From jivestgarden at common-lisp.net Mon Jul 20 19:37:01 2009 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Mon, 20 Jul 2009 15:37:01 -0400 Subject: [lisplab-cvs] r64 - Message-ID: Author: jivestgarden Date: Mon Jul 20 15:36:54 2009 New Revision: 64 Log: basic algebra on lists. yes. Modified: lisplab.asd Modified: lisplab.asd ============================================================================== --- lisplab.asd (original) +++ lisplab.asd Mon Jul 20 15:36:54 2009 @@ -70,6 +70,7 @@ (:file "level2-matrix-zge") (:file "level2-array-functions") (:file "level2-funmat") + (:file "level2-list") )) ;; From jivestgarden at common-lisp.net Mon Jul 20 19:37:39 2009 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Mon, 20 Jul 2009 15:37:39 -0400 Subject: [lisplab-cvs] r65 - src/matrix Message-ID: Author: jivestgarden Date: Mon Jul 20 15:37:39 2009 New Revision: 65 Log: basic algebra on lists. Here it comes. Added: src/matrix/level2-list.lisp Added: src/matrix/level2-list.lisp ============================================================================== --- (empty file) +++ src/matrix/level2-list.lisp Mon Jul 20 15:37:39 2009 @@ -0,0 +1,67 @@ +;;; Lisplab, level2-list.lisp +;;; Basic algebra stuff for lists + +;;; Copyright (C) 2009 Joern Inge Vestgaarden +;;; +;;; This program is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 2 of the License, or +;;; (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License along +;;; with this program; if not, write to the Free Software Foundation, Inc., +;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +;;; Should it be somewhere else. It has nothing to do with matrices really. + +(in-package :lisplab) + +(defmethod .mul ((x cons) (y cons)) + (mapcar #'.mul x y)) + +(defmethod .mul ((x cons) (y number)) + (mapcar (lambda (x) (.mul x y)) x)) + +(defmethod .mul ((x number) (y cons)) + (mapcar (lambda (y) (.mul x y)) y)) + +(defmethod .add ((x cons) (y cons)) + (mapcar #'.add x y)) + +(defmethod .add ((x cons) (y number)) + (mapcar (lambda (x) (.add x y)) x)) + +(defmethod .add ((x number) (y cons)) + (mapcar (lambda (y) (.add x y)) y)) + +(defmethod .sub ((x cons) (y cons)) + (mapcar #'.sub x y)) + +(defmethod .sub ((x cons) (y number)) + (mapcar (lambda (x) (.sub x y)) x)) + +(defmethod .sub ((x number) (y cons)) + (mapcar (lambda (y) (.sub x y)) y)) + +(defmethod .div ((x cons) (y cons)) + (mapcar #'.div x y)) + +(defmethod .div ((x cons) (y number)) + (mapcar (lambda (x) (.div x y)) x)) + +(defmethod .div ((x number) (y cons)) + (mapcar (lambda (y) (.div x y)) y)) + +(defmethod .expt ((x cons) (y cons)) + (mapcar #'.expt x y)) + +(defmethod .expt ((x cons) (y number)) + (mapcar (lambda (x) (.expt x y)) x)) + +(defmethod .expt ((x number) (y cons)) + (mapcar (lambda (y) (.expt x y)) y)) From jivestgarden at common-lisp.net Tue Jul 28 19:37:30 2009 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Tue, 28 Jul 2009 15:37:30 -0400 Subject: [lisplab-cvs] r66 - doc/manual Message-ID: Author: jivestgarden Date: Tue Jul 28 15:37:25 2009 New Revision: 66 Log: more on structure Modified: doc/manual/lisplab.texi Modified: doc/manual/lisplab.texi ============================================================================== --- doc/manual/lisplab.texi (original) +++ doc/manual/lisplab.texi Tue Jul 28 15:37:25 2009 @@ -57,13 +57,21 @@ syntax on top of Common Lisp. Lisplab contains code from Matlisp, but has also a lot of new code, refactored code and rewritten code. Other Common Lisp matrix libraries -are FEMLLISP and NLISP. +are Matlisp, Femlisp and NLISP. @node Getting started @chapter Getting started @section Dependencies +In order to enjoy the full power of Lisplab you +must install some foreign libraries. These are + at itemize + at item BLAS -- Basic Linear Algebra Subprograms. Preferably the Atlas build. + at item LAPACK -- Matrix library. Preferably the Atlas build. + at item FFTW -- The fastest Fast Fourier Transform available. + at end itemize + Lisplab has been developed with SBCL, SLIME and ASDF on Linux, and there are yet unnecessary bindings to these platforms. @itemize @@ -75,20 +83,6 @@ @item The @code{*READ-DEFAULT-FLOAT-FORMAT*} must be @code{double-float}. @end itemize -In order to enjoy the full power of Lisplab you -must install some foreign libraries. These are - at itemize - at item -BLAS -- Basic Linear Algebra Subprograms. Preferably the Atlas build. - - at item -LAPACK -- Matrix library. Preferably the Atlas build. - - at item -FFTW -- The fastest Fast Fourier Transform available. - - at end itemize - @section Installing Lisplab is ASDF installable, but before you come so far you need to specify the location of the foreign libraries. @@ -302,7 +296,7 @@ while @code{dmat} is a macro. Similarly, there are @code{znew}, @code{zcol}, @code{zrow}, and @code{zmat} for double float matrices and - at code{mnew}, @code{mcol}, @code{mrow}, and @code{mmat} + at code{new}, @code{col}, @code{row}, and @code{mat} for any matrices. The latter take matrix class as first argument. Often you want to create a matrix of the same type as a input @@ -318,8 +312,9 @@ @{B0998B1@}> @end example @code{Convert} also converts between matrix types. If the -matrix contents cannot be converted directly (e.g., conversion -from complex to real), use @code{copy-contents} instead. +matrix contents cannot be converted directly +(e.g., conversion from complex to real), +use @code{copy-contents} instead. @section Matrix element reference To access a matrix element use the generic function @code{mref} @@ -344,7 +339,7 @@ is structure agnostic. The functions of the dotted algebra introduce a programming style much the same as for Matlab, and combined with the linear algebra -functions, you can write compact programs, without the slower +functions, you can write compact programs, without the slow single element references. @example LL> (.sin (drow 0 1)) @@ -355,8 +350,8 @@ And so also for the algebraic operations @example LL> (let ((a (drow 0 1)) - (b (dcol 0.1 0.2))) - (.+ a (.* b 2))) + (b (dcol 0.1 0.2))) + (.+ a (.* b 2))) # @@ -366,7 +361,8 @@ also that the scalar is multiplied element-vise. The dotted algebra is to some extent also implemented for -general element matrices +general element matrices, so that you can work with fractions and +integers rather than floats @example LL> (.+ (row 'matrix-ge 1/2 3/2) 1) #(let ((a (dmat (1 0) (0 -1))) - (b (dcol 0.1 0.2))) + (b (dcol 0.1 0.2))) (m* a b)) # (let ((a (mat 'matrix-ge (1 0) (0 -1))) - (b (col 'matrix-ge 1/2 2/3))) + (b (col 'matrix-ge 1/2 2/3))) (m* a b)) # + LL> (minv (mat 'matrix-ge (1 2)(-2 1))) # (w/infix + (let ((x 3)) + (1 .+ 2 .* x))) +7 @end example The @code{w/infix} messes as little as possible with the Lisp semantics, so that if you have a lot of formulas just wrap all -of it inside the macro. +of it inside the macro. @node Structure @chapter Structure @section Package structure +So far, there is only one main package, called, you might guess it: + at i{lisplab}. Except from that there are only a few special packages +for generated code and FFIs: slatec, blas, and FFTW. @section The four levels, 0 -- 3. +Lisplab has a layered structure with four levels, 0 -- 3, +where + at itemize + at item @b{Level 0} is matrix independent and contains +the dotted algebra generic functions, +the dotted algebra methods specialized for numbers, and +helper functions and macros. + at item @b{Level 1} defines matrices and defines and implements + at code{mref}, @code{vref}, at code{cols}, @code{rows}, @code{size} +and @code{make-matrix-instance}. + at item @b{Level 2} defines and core functionality related +to matrices, such as the dotted algebra methods, +matrix constructors (@code{dnew}, @code{dcol}, etc.) +and other matrix helper functions, such as + at code{mmax}, @code{mmin}, @code{circ-shift}, etc. + at item @b{Level 3} is everything else that uses matrices, +including linear algebra, FFTs, solvers, etc. + at end itemize +The levels are unequal in size: level 0 is fairly large, +level 1 is extremely small, level 2 is fairly small, and +level 3 is large and I hope it will never stop to grow. + +The intention with the structure are the following + at itemize + at item To minimize the work needed to add new matrices implementations. +Actually, you need only to implement level 1, +provided you inherit from matrix base. Otherwise you need also +to implement level 2. + at item To encourage code reuse. For example, if you add +a new type to the dotted algebra, such as polynomials, symbolic +expressions, or arbitrary precision floats, you can immediately +perform matrix operations on them without write one single extra line +of code. + at item To manage optimizations and special implementations by +overloading for specialized matrix types, mainly at level 2, +but also at level 3. + at item To make foreign libraries available in Common Lisp. + at item To create a closed, constant and extensible system of operations. + at end itemize +The filenames often also denote the levels. If a filename does not +denote the level, it is most probably level 3, or outside the level system +(non matrix code). @section Class structure From jivestgarden at common-lisp.net Fri Jul 31 18:53:13 2009 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Fri, 31 Jul 2009 14:53:13 -0400 Subject: [lisplab-cvs] r67 - in src: core matrix Message-ID: Author: jivestgarden Date: Fri Jul 31 14:53:10 2009 New Revision: 67 Log: cleaned functions. Not tested Modified: src/core/level0-functions.lisp src/core/level0-interface.lisp src/matrix/level2-generic.lisp src/matrix/level2-matrix-dge.lisp src/matrix/level2-matrix-zge.lisp Modified: src/core/level0-functions.lisp ============================================================================== --- src/core/level0-functions.lisp (original) +++ src/core/level0-functions.lisp Fri Jul 31 14:53:10 2009 @@ -1,4 +1,5 @@ ;;; Lisplab, level0-functions.lisp +;;; Contains ordinary functions and lisplab wrappers for common lisp functions. ;;; Copyright (C) 2009 Joern Inge Vestgaarden ;;; @@ -56,12 +57,6 @@ "Generlized expt. Reduces the arguments with .expt." (reduce #'.expt args)) -(defmethod .max ((a number) (b number)) - (max a b)) - -(defmethod .min ((a number) (b number)) - (min a b)) - (defmethod .abs ((a number)) (abs a)) @@ -71,8 +66,11 @@ (defmethod .imagpart ((a number)) (imagpart a)) -(defmethod .conj ((a number)) - (conjugate a)) +(defmethod .max ((a number) (b number)) + (max a b)) + +(defmethod .min ((a number) (b number)) + (min a b)) (defmethod .= ((a number) (b number) &optional (accuracy)) (if accuracy @@ -94,6 +92,53 @@ (defmethod .>= ((a number) (b number)) (>= a b)) +(defmacro expand-on-numbers-lisplab-two-argument-functions-alist () + ;; TODO: optimize? why? + (cons 'progn + (mapcar (lambda (name) + `(defmethod ,(car name) ((a number) (b number)) + (,(cdr name) a b))) + +lisplab-two-argument-functions-alist+))) + +(expand-on-numbers-lisplab-two-argument-functions-alist) + +#+why-did-I-do-this?(defmethod .expt ((a real) (b real)) + (expt (to-df a) b)) + +(defmacro expand-on-numbers-lisplab-one-argument-functions-alist () + ;; TODO: optimize? why? + (cons 'progn + (mapcar (lambda (name) + `(progn + (defmethod ,(car name) ((a number)) + (,(cdr name) a)) + (defmethod ,(car name) ((a real)) + (,(cdr name) (to-df a))))) + +lisplab-one-argument-functions-alist+))) + +(expand-on-numbers-lisplab-one-argument-functions-alist) + +(defmethod .log ((x number) &optional (base nil)) + (if base + (log x base) + (log x))) + +(defmethod .log ((x real) &optional (base nil)) + (if base + (log (to-df x) base) + (log (to-df x)))) + +(defmethod .sqr ((x number)) + (* x x)) + +(defmethod .sqr ((x real)) + (let ((x (to-df x))) + (* x x))) + + +#| + + (defmethod .add ((a number) (b number)) (+ a b)) @@ -109,9 +154,12 @@ (defmethod .expt ((a number) (b number)) (expt a b)) + (defmethod .expt ((a real) (b real)) (expt (to-df a) b)) +|# +#| (defmethod .sin ((x number)) (sin x)) @@ -145,28 +193,12 @@ (defmethod .atan ((x real)) (atan (to-df x))) -(defmethod .log ((x number) &optional (base nil)) - (if base - (log x base) - (log x))) - -(defmethod .log ((x real) &optional (base nil)) - (if base - (log (to-df x) base) - (log (to-df x)))) - (defmethod .exp ((x number)) (exp x)) (defmethod .exp ((x real)) (exp (to-df x))) -(defmethod .sqr ((x number)) - (* x x)) - -(defmethod .sqr ((x real)) - (let ((x (to-df x))) - (* x x))) (defmethod .sqrt ((x number)) (sqrt x)) @@ -210,6 +242,6 @@ (defmethod .atanh ((x real)) (atanh (to-df x))) - +|# Modified: src/core/level0-interface.lisp ============================================================================== --- src/core/level0-interface.lisp (original) +++ src/core/level0-interface.lisp Fri Jul 31 14:53:10 2009 @@ -43,6 +43,33 @@ .erf .erfc .gamma)) +(define-constant +lisplab-one-argument-functions+ + '(.sin .cos .tan .asin .acos .atan + .sinh .cosh .tanh .asinh .acosh .atanh + .exp .sqr .sqrt .conj) + ;; List of "nice" functions that output real to real, have one argument. + ;; Not part of the list: .log, .conj, .realpart, .imagpart and most special functions + "Functions functions that takes exactly one argument and preserve type.") + +(define-constant +lisplab-one-argument-functions-alist+ + '((.sin . sin) (.cos . cos) (.tan . tan) + (.asin . asin) (.acos . acos) (.atan . atan) + (.sinh . sinh) (.cosh . cosh) (.tanh . tanh) + (.asinh . asinh) (.acosh . acosh) (.atanh . atanh) + (exp. . exp) (.sqrt . sqrt) (.conj . conjugate)) + ;; List of "nice" functions that output real to real, have one argument, + ;; and a analogy in the Common Lisp package. + ;; Note part of the list: .log, .sq, and all special functions + "A map between lisplab and common lisp functions that take exactly one argument.") + +(define-constant +lisplab-two-argument-functions+ + '(.add .sub .mul .div .expt) + "Functions functions that takes exactly one argument and preserve type.") + +(define-constant +lisplab-two-argument-functions-alist+ + '((.add . +) (.sub . -) (.mul . *) (.div . /) (.expt . expt)) + "A map between lisplab and common lisp functions that take exactly two arguments.") + (defgeneric scalar? (x) (:documentation "A scalar is a object with ignored internal structure.")) Modified: src/matrix/level2-generic.lisp ============================================================================== --- src/matrix/level2-generic.lisp (original) +++ src/matrix/level2-generic.lisp Fri Jul 31 14:53:10 2009 @@ -255,6 +255,15 @@ (setf (vref ,a ,i) (,op (vref ,a ,i) (vref ,b ,i)))) ,a))))) +(defmacro expand-on-matrix-ge-lisplab-two-argument-functions-alist () + (cons 'progn + (mapcar (lambda (name) + `(def-binary-op-matrix-ge ,(car name))) + +lisplab-two-argument-functions-alist+))) + +(expand-on-matrix-ge-lisplab-two-argument-functions-alist) + +#| (def-binary-op-matrix-ge .add) (def-binary-op-matrix-ge .mul) @@ -264,6 +273,7 @@ (def-binary-op-matrix-ge .div) (def-binary-op-matrix-ge .expt) +|# (defmacro each-element-function-matrix-ge (x form) "Applies a form on each element of an matrix-ge." @@ -276,6 +286,15 @@ ,form))) ,y))) +(defmacro expand-on-matrix-ge-lisplab-one-argument-functions-alist () + (cons 'progn + (mapcar (lambda (name) + `(defmethod ,(car name) ((x matrix-ge)) + (each-element-function-matrix-ge x (,(car name) x)))) + +lisplab-one-argument-functions-alist+))) + +(expand-on-matrix-ge-lisplab-one-argument-functions-alist) + (defmethod .imagpart ((x matrix-ge)) @@ -287,6 +306,39 @@ (defmethod .abs ((x matrix-ge)) (each-element-function-matrix-ge x (.abs x))) + +(defmethod .log ((x matrix-ge) &optional base) + (each-element-function-matrix-ge x (.log x base))) + +(defmethod .sqr ((x matrix-ge)) + (each-element-function-matrix-ge x (.sqr x))) + + +;;; Bessel functions + +(defmethod .besj (n (x matrix-ge)) + (each-element-function-matrix-ge x (.besj n x))) + +(defmethod .besy (n (x matrix-ge)) + (each-element-function-matrix-ge x (.besy n x))) + +(defmethod .besi (n (x matrix-ge)) + (each-element-function-matrix-ge x (.besi n x))) + +(defmethod .besk (n (x matrix-ge)) + (each-element-function-matrix-ge x (.besk n x))) + +(defmethod .besh1 (n (x matrix-ge)) + (each-element-function-matrix-ge x (.besh1 n x))) + +(defmethod .besh2 (n (x matrix-ge)) + (each-element-function-matrix-ge x (.besh2 n x))) + + +;;; TRASH + +#| + (defmethod .conj ((x matrix-ge)) (each-element-function-matrix-ge x (.conj x))) @@ -314,39 +366,11 @@ ;;; Logarithms and exponents -(defmethod .log ((x matrix-ge) &optional base) - (each-element-function-matrix-ge x (.log x base))) - (defmethod .exp ((x matrix-ge)) (each-element-function-matrix-ge x (.exp x))) -(defmethod .sqr ((x matrix-ge)) - (each-element-function-matrix-ge x (.sqr x))) (defmethod .sqrt ((x matrix-ge)) (each-element-function-matrix-ge x (.sqrt x))) - -;;; Bessel functions - -(defmethod .besj (n (x matrix-ge)) - (each-element-function-matrix-ge x (.besj n x))) - -(defmethod .besy (n (x matrix-ge)) - (each-element-function-matrix-ge x (.besy n x))) - -(defmethod .besi (n (x matrix-ge)) - (each-element-function-matrix-ge x (.besi n x))) - -(defmethod .besk (n (x matrix-ge)) - (each-element-function-matrix-ge x (.besk n x))) - -(defmethod .besh1 (n (x matrix-ge)) - (each-element-function-matrix-ge x (.besh1 n x))) - -(defmethod .besh2 (n (x matrix-ge)) - (each-element-function-matrix-ge x (.besh2 n x))) - - -;;; TRASH - +|# Modified: src/matrix/level2-matrix-dge.lisp ============================================================================== --- src/matrix/level2-matrix-dge.lisp (original) +++ src/matrix/level2-matrix-dge.lisp Fri Jul 31 14:53:10 2009 @@ -61,9 +61,6 @@ (copy-contents a b #'abs) b)) -(defmethod .conj ((a matrix-base-dge)) - (copy a)) - (defmethod .some (pred (a matrix-base-dge) &rest args) (let ((stores (mapcar #'matrix-store (cons a args)))) (apply #'some pred stores))) @@ -114,19 +111,13 @@ (setf (aref ,store ,i) (,old (aref ,store ,i) (aref ,store2 ,i)))) ,a))))) -(def-binary-op-matrix-base-dge .add +) - -(def-binary-op-matrix-base-dge .mul *) - -(def-binary-op-matrix-base-dge .sub -) +(defmacro expand-on-matrix-dge-lisplab-two-argument-functions-alist () + (cons 'progn + (mapcar (lambda (name) + `(def-binary-op-matrix-base-dge ,(car name) ,(cdr name))) + +lisplab-two-argument-functions-alist+))) -(def-binary-op-matrix-base-dge .div /) - -(def-binary-op-matrix-base-dge .expt expt) - -(def-binary-op-matrix-base-dge .max max) - -(def-binary-op-matrix-base-dge .min min) +(expand-on-matrix-dge-lisplab-two-argument-functions-alist) (defmacro each-matrix-element-df-to-df (x form) "Applies a form on each element of an matrix-dge. The form must @@ -144,6 +135,48 @@ ,form))) ,x))) +(defmacro expand-on-matrix-dge-lisplab-one-argument-functions-alist () + (cons 'progn + (mapcar (lambda (name) + `(defmethod ,(car name) ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (,(cdr name) x)))) + +lisplab-one-argument-functions-alist+))) + +(expand-on-matrix-dge-lisplab-one-argument-functions-alist) + +(defmethod .log ((x matrix-base-dge) &optional base) + (if base + (each-matrix-element-df-to-df x (log x base)) + (each-matrix-element-df-to-df x (log x)))) + +(defmethod .sqr ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (* x x))) + +;;; Other spacial functions + +(defmethod .erf ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (.erf x))) + +(defmethod .erfc ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (.erfc x))) + +(defmethod .gamma ((x matrix-base-dge)) + (each-matrix-element-df-to-df x (.gamma x))) + +;;; Bessel functions + +(defmethod .besj (n (x matrix-base-dge)) + (each-matrix-element-df-to-df x (.besj n x))) + +(defmethod .besy (n (x matrix-base-dge)) + (each-matrix-element-df-to-df x (.besy n x))) + +(defmethod .besi (n (x matrix-base-dge)) + (each-matrix-element-df-to-df x (.besi n x))) + +(defmethod .besk (n (x matrix-base-dge)) + (each-matrix-element-df-to-df x (.besk n x))) + (defmacro each-matrix-element-df-to-complex-df (x form) "Applies a form on each element of an matrix-dge. The form must make complex output for real arguments. TODO optimize? Probably no need. The @@ -158,8 +191,36 @@ (setf (vref ,b ,i) ,form))) ,b))) -;;; Trignometric functions +(defmethod .besh1 (n (x matrix-base-dge)) + (each-matrix-element-df-to-complex-df x (.besh1 n x))) + +(defmethod .besh2 (n (x matrix-base-dge)) + (each-matrix-element-df-to-complex-df x (.besh2 n x))) + +;;;;;;;;;;;;;;; TRASH + +#| +(def-binary-op-matrix-base-dge .add +) + +(def-binary-op-matrix-base-dge .mul *) + +(def-binary-op-matrix-base-dge .sub -) + +(def-binary-op-matrix-base-dge .div /) + +(def-binary-op-matrix-base-dge .expt expt) + +(def-binary-op-matrix-base-dge .max max) + +(def-binary-op-matrix-base-dge .min min) + +|# + + + +#| +;;; Trignometric functions (defmethod .sin ((x matrix-base-dge)) (each-matrix-element-df-to-df x (sin x))) @@ -198,50 +259,11 @@ (defmethod .atanh ((x matrix-base-dge)) (each-matrix-element-df-to-df x (atanh x))) -;;; Logarithm and exponent - -(defmethod .log ((x matrix-base-dge) &optional base) - (if base - (each-matrix-element-df-to-df x (log x base)) - (each-matrix-element-df-to-df x (log x)))) - (defmethod .exp ((x matrix-base-dge)) (each-matrix-element-df-to-df x (exp x))) -(defmethod .sqr ((x matrix-base-dge)) - (each-matrix-element-df-to-df x (* x x))) - (defmethod .sqrt ((x matrix-base-dge)) (each-matrix-element-df-to-df x (sqrt x))) -;;; Bessel functions - -(defmethod .besj (n (x matrix-base-dge)) - (each-matrix-element-df-to-df x (.besj n x))) - -(defmethod .besy (n (x matrix-base-dge)) - (each-matrix-element-df-to-df x (.besy n x))) - -(defmethod .besi (n (x matrix-base-dge)) - (each-matrix-element-df-to-df x (.besi n x))) - -(defmethod .besk (n (x matrix-base-dge)) - (each-matrix-element-df-to-df x (.besk n x))) - -(defmethod .besh1 (n (x matrix-base-dge)) - (each-matrix-element-df-to-complex-df x (.besh1 n x))) - -(defmethod .besh2 (n (x matrix-base-dge)) - (each-matrix-element-df-to-complex-df x (.besh2 n x))) - -;;; Other spacial functions - -(defmethod .erf ((x matrix-base-dge)) - (each-matrix-element-df-to-df x (.erf x))) - -(defmethod .erfc ((x matrix-base-dge)) - (each-matrix-element-df-to-df x (.erfc x))) - -(defmethod .gamma ((x matrix-base-dge)) - (each-matrix-element-df-to-df x (.gamma x))) +|# Modified: src/matrix/level2-matrix-zge.lisp ============================================================================== --- src/matrix/level2-matrix-zge.lisp (original) +++ src/matrix/level2-matrix-zge.lisp Fri Jul 31 14:53:10 2009 @@ -61,7 +61,7 @@ (copy-contents a b #'abs) b)) -(defmacro def-binary-op-blas-complex (new old) +(defmacro def-binary-op-matrix-base-zge (new old) ;;; TODO speed up for real numbers. Is it worth the work? (let ((a (gensym "a")) (b (gensym "b")) @@ -135,15 +135,13 @@ (ref-blas-complex-store ,store2 ,i 0 ,len)))) ,b))))) -(def-binary-op-blas-complex .add +) - -(def-binary-op-blas-complex .mul *) - -(def-binary-op-blas-complex .sub -) - -(def-binary-op-blas-complex .div /) +(defmacro expand-on-matrix-zge-lisplab-two-argument-functions-alist () + (cons 'progn + (mapcar (lambda (name) + `(def-binary-op-matrix-base-zge ,(car name) ,(cdr name))) + +lisplab-two-argument-functions-alist+))) -(def-binary-op-blas-complex .expt expt) +(expand-on-matrix-zge-lisplab-two-argument-functions-alist) (defmacro each-element-function-matrix-base-zge (x form) "Applies a form on each element of an matrix-base-zge." @@ -158,6 +156,70 @@ ,form))) ,y))) +(defmacro expand-on-matrix-zge-lisplab-one-argument-functions-alist () + (cons 'progn + (mapcar (lambda (name) + `(defmethod ,(car name) ((x matrix-base-zge)) + (each-element-function-matrix-base-zge x (,(cdr name) x)))) + +lisplab-one-argument-functions-alist+))) + +(expand-on-matrix-zge-lisplab-one-argument-functions-alist) + +(defmethod .log ((x matrix-base-zge) &optional base) + (if base + (each-element-function-matrix-base-zge x (log x base)) + (each-element-function-matrix-base-zge x (log x)))) + +(defmethod .sqr ((x matrix-base-zge)) + (each-element-function-matrix-base-zge x (* x x))) + +;;; Bessel functions + +(defmethod .besj (n (x matrix-base-zge)) + (each-element-function-matrix-base-zge x (.besj n x))) + +(defmethod .besy (n (x matrix-base-zge)) + (each-element-function-matrix-base-zge x (.besy n x))) + +(defmethod .besi (n (x matrix-base-zge)) + (each-element-function-matrix-base-zge x (.besi n x))) + +(defmethod .besk (n (x matrix-base-zge)) + (each-element-function-matrix-base-zge x (.besk n x))) + +(defmethod .besh1 (n (x matrix-base-zge)) + (each-element-function-matrix-base-zge x (.besh1 n x))) + +(defmethod .besh2 (n (x matrix-base-zge)) + (each-element-function-matrix-base-zge x (.besh2 n x))) + + + +;;; TRASH + + +#| +(def-binary-op-blas-complex .add +) + +(def-binary-op-blas-complex .mul *) + +(def-binary-op-blas-complex .sub -) + +(def-binary-op-blas-complex .div /) + +(def-binary-op-blas-complex .expt expt) +|# + + +#| +(defmethod .exp ((x matrix-base-zge)) + (each-element-function-matrix-base-zge x (exp x))) + +(defmethod .sqrt ((x matrix-base-zge)) + (each-element-function-matrix-base-zge x (sqrt x))) + + + (defmethod .conj ((x matrix-base-zge)) (each-element-function-matrix-base-zge x (conjugate x))) @@ -202,37 +264,4 @@ (each-element-function-matrix-base-zge x (atanh x))) ;;; Logarithm and exponent - -(defmethod .log ((x matrix-base-zge) &optional base) - (if base - (each-element-function-matrix-base-zge x (log x base)) - (each-element-function-matrix-base-zge x (log x)))) - -(defmethod .exp ((x matrix-base-zge)) - (each-element-function-matrix-base-zge x (exp x))) - -(defmethod .sqr ((x matrix-base-zge)) - (each-element-function-matrix-base-zge x (* x x))) - -(defmethod .sqrt ((x matrix-base-zge)) - (each-element-function-matrix-base-zge x (sqrt x))) - -;;; Bessel functions - -(defmethod .besj (n (x matrix-base-zge)) - (each-element-function-matrix-base-zge x (.besj n x))) - -(defmethod .besy (n (x matrix-base-zge)) - (each-element-function-matrix-base-zge x (.besy n x))) - -(defmethod .besi (n (x matrix-base-zge)) - (each-element-function-matrix-base-zge x (.besi n x))) - -(defmethod .besk (n (x matrix-base-zge)) - (each-element-function-matrix-base-zge x (.besk n x))) - -(defmethod .besh1 (n (x matrix-base-zge)) - (each-element-function-matrix-base-zge x (.besh1 n x))) - -(defmethod .besh2 (n (x matrix-base-zge)) - (each-element-function-matrix-base-zge x (.besh2 n x))) +|# \ No newline at end of file