From: H. Tunc Simsek
Subject: [linear algebra] lapack
Date: 
Message-ID: <38572912.E299491D@EECS.Berkeley.Edu>
I'll ask here a question of feasability.  Lapack is a linear algebra
package written in fortran then translated to C.
I believe many commercial packages are based on lapack due to its
powerful toolbox of linear algebra and efficient
computational capabilities.  

Would it be possible to port lapack to cmucl by means of foreign
functions?  I've been using cmucl as a number
cruncing platform for slightly over a year now and have often found need
for linear algebra, specifically matrix
manipulation.  I've actually vectorized 50% of the ansi cl math
functions and written macro dispatchers for
easier matrix expressions but the resulting code is quite inefficient
and conses too much. 

Perhaps the question I should be asking is whether there is a
comprehensive math toolbox for lisp.  I've found
that clmath, sapaclisp, clasp and clmusic provide a good batch, although
somewhat incompatible.

Also, I've recently tried to install the free version of CLIM (CLINC) in
hope to run CLASP without success.  Is there
any promise in the development of CLINC?

Thanks,
Tunc

From: Christopher R. Barry
Subject: Re: [linear algebra] lapack
Date: 
Message-ID: <87u2lku3oo.fsf@2xtreme.net>
"H. Tunc Simsek" <······@EECS.Berkeley.Edu> writes:

[...]

> I've been using cmucl as a number cruncing platform for slightly
> over a year now and have often found need for linear algebra,
> specifically matrix manipulation.  I've actually vectorized 50% of
> the ansi cl math functions and written macro dispatchers for easier
> matrix expressions but the resulting code is quite inefficient and
> conses too much.

Unless you have to code all this stuff yourself as a school project or
something, I think you would be best of with a "real" symbolic
mathematics package like Mathematica or Maple. Try telling the people
at sci.math.symbolic what you want to do and what your performance and
price requirements are and see if you get a good lead.

Christopher
From: H. Tunc Simsek
Subject: Re: [linear algebra] lapack
Date: 
Message-ID: <38573C0B.53DF3EF1@EECS.Berkeley.Edu>
I don't think the comparable toolset would be maple, mathematica.  
Matlab would be more suitable.

The problem is not of symbolic computation.  The projects we deal
with involve a great deal of data flow and hence lisp is a good
choice for programming.  The numerics is only part of the problem.
e.g. smartAHS: www.path.berkeley.edu/shift



"Christopher R. Barry" wrote:
> 
> "H. Tunc Simsek" <······@EECS.Berkeley.Edu> writes:
> 
> [...]
> 
> > I've been using cmucl as a number cruncing platform for slightly
> > over a year now and have often found need for linear algebra,
> > specifically matrix manipulation.  I've actually vectorized 50% of
> > the ansi cl math functions and written macro dispatchers for easier
> > matrix expressions but the resulting code is quite inefficient and
> > conses too much.
> 
> Unless you have to code all this stuff yourself as a school project or
> something, I think you would be best of with a "real" symbolic
> mathematics package like Mathematica or Maple. Try telling the people
> at sci.math.symbolic what you want to do and what your performance and
> price requirements are and see if you get a good lead.
> 
> Christopher
From: Marco Antoniotti
Subject: Re: [linear algebra] lapack
Date: 
Message-ID: <lwhfhk71hg.fsf@parades.rm.cnr.it>
······@2xtreme.net (Christopher R. Barry) writes:

> "H. Tunc Simsek" <······@EECS.Berkeley.Edu> writes:
> 
> [...]
> 
> > I've been using cmucl as a number cruncing platform for slightly
> > over a year now and have often found need for linear algebra,
> > specifically matrix manipulation.  I've actually vectorized 50% of
> > the ansi cl math functions and written macro dispatchers for easier
> > matrix expressions but the resulting code is quite inefficient and
> > conses too much.
> 
> Unless you have to code all this stuff yourself as a school project or
> something, I think you would be best of with a "real" symbolic
> mathematics package like Mathematica or Maple.

You forgot Macsyma.  Unlike Mathematica it tells you that it is
implemented in Lisp and does not rebuild a Lisp interpreter in its
guts :)  I don't know Maple.

BTW. Tunc, Macsyma is installed in the PATH network. Sergio used it to
do some Hybrid Automata verification work.

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Christopher C Stacy
Subject: Re: [linear algebra] lapack
Date: 
Message-ID: <x8lr9gom0s2.fsf@world.std.com>
MACSYMA includes LAPACK.
From: Raymond Toy
Subject: Re: [linear algebra] lapack
Date: 
Message-ID: <4n7liggwas.fsf@rtp.ericsson.se>
>>>>> "Tunc" == H Tunc Simsek <······@EECS.Berkeley.Edu> writes:

    Tunc> Would it be possible to port lapack to cmucl by means of foreign
    Tunc> functions?  I've been using cmucl as a number

Yes.  I've done this using CMUCL FFI and it works.  I didn't include
access to every lapack function (not enough time, don't need them, or
too lazy), but you get lisp access to BLAS level 1, some of BLAS level
2 and 3, Gaussian elimination and some eigenvalue problems.  (Can't
remember since I haven't used it in a while.)  It would be relatively
easy to add all of the functions, but it's quite tedious because I had
to do it by hand.  Some automatic means of parsing the actual Fortran
code to get the function call would help a lot.  (A hacked up f2cl
perhaps?)

I also wrote a hack matrix class that used LAPACK.

All of this code is pretty ugly because I was learning lots of stuff
at the time.

But you can have it if you want.

Ray
From: H. Tunc Simsek
Subject: Re: [linear algebra] lapack
Date: 
Message-ID: <385AF6A0.A221973@EECS.Berkeley.Edu>
I'd like to give your code a try, please mail it to me.
I hope that you can put a note on which version of lapack
you were using so I can repeat the compilation process.

Thanks,
Tunc

Raymond Toy wrote:
> 
> >>>>> "Tunc" == H Tunc Simsek <······@EECS.Berkeley.Edu> writes:
> 
>     Tunc> Would it be possible to port lapack to cmucl by means of foreign
>     Tunc> functions?  I've been using cmucl as a number
> 
> Yes.  I've done this using CMUCL FFI and it works.  I didn't include
> access to every lapack function (not enough time, don't need them, or
> too lazy), but you get lisp access to BLAS level 1, some of BLAS level
> 2 and 3, Gaussian elimination and some eigenvalue problems.  (Can't
> remember since I haven't used it in a while.)  It would be relatively
> easy to add all of the functions, but it's quite tedious because I had
> to do it by hand.  Some automatic means of parsing the actual Fortran
> code to get the function call would help a lot.  (A hacked up f2cl
> perhaps?)
> 
> I also wrote a hack matrix class that used LAPACK.
> 
> All of this code is pretty ugly because I was learning lots of stuff
> at the time.
> 
> But you can have it if you want.
> 
> Ray
From: Robert Monfera
Subject: Re: [linear algebra] lapack
Date: 
Message-ID: <3858720C.3F5834C2@fisec.com>
Hi Tunc,

"H. Tunc Simsek" wrote:

> I've actually vectorized 50% of the ansi cl math
> functions and written macro dispatchers for
> easier matrix expressions but the resulting code is quite inefficient
> and conses too much.

Maybe it is not avoidable to cons in your case, but here's one of my
experiences:

I was looking at some relatively simple operation like sorting a
matrix.  After recognizing that it's best to sort the row index based on
array values rather than the array itself, I was quick to use the
built-in STABLE-SORT function of LispWorks.  Initially, no matter what I
did, it consed up an amazing 50-60 megabytes just to sort about 1
million fixnums - it also took about 45 seconds.  Spending some time
with declarations, I learned that declaring (fixnum-safety 0) brings
consing down to about 12 megs.  This is LW-specific, but if you
represent your numbers (even bignums) as fixnums or (unsigned-byte 32)
on CMUCL, it may make a huge difference (disregard this if you are
already doing this).

Still unsatisfied, I tortured the built-in MERGE-SORT algorithm with
DISSASSEMBLE and learned that the core sorting algorithm is implemented
for lists, and my vector gets converted to a list first!  I changed the
input vector to a list.

These two steps, and using SVREF instead of AREF brought down run-time
from 45s to 9s, and consing from 60M to 12M.

Still unsatisfied with the run-time, I tried a not particularly
optimized merge-sort algorithm (which works with a vector), bringing
down consing to 0 (except the swap array, which could be resourced) and
run-time to 2.9s, and now it looks entirely possible to bring it down to
0.5s or less with quicksort or bucket-sort, without resorting to
platform-dependent settings except overall FIXNUM optimization.  I
stopped optimizing when sorting discontinued to be a major contributor
of response time.

What I learned from this is that algorithmic and declaration
optimizations inside 99% portable Lisp can lead to amazing results, and
if I need the last drop of performance, I can still hack the compiler
output.  But it's better to defer making platform- or
processor-dependent optimizations, as they require significant time, and
it may become garbage if you make a change to your yet unfinalized
algorithm.

If you post some isolated snippets that you feel causes unnecessary
consing, someone may help.

If you are beyond all these, just disregard my mail.  Do you have a
reference to benchmark figures for sorting and other common matrix
operations of optimized C libraries on stock hardware?

Robert
From: Reini Urban
Subject: Re: [linear algebra] lapack
Date: 
Message-ID: <385976f3.50915622@judy>
I would give simlab (with weyl) a try.
It's pure CL instead of FORTRAN and has probably more than you will ever
need.
(i.e. not only "linear" algebra)

--
Reini Urban
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html