Re: speeding up wrapper for "new" datatype
 From: gugamilare <gugamilare@xxxxxxxxx>
 Date: Sun, 12 Apr 2009 18:35:56 0700 (PDT)
On 12 abr, 11:44, Tamas K Papp <tkp...@xxxxxxxxx> wrote:
Hi,
I was cleaning up code that interfaces to BLAS/LAPACK/UMFPack
libraries, and it occured to me that I could unify the interface for
various special matrices using CLOS. The idea is that I create a
matrix class, and specialize that as needed, including dense matrices
which are really just wrappers around 2d arrays.
If possible, I would like densematrix element access to be (nearly)
as fast as aref, but I don't know how. I thought of compiler macros,
but I can't think of an advantageous transformation. As a general
issue, I am wondering if it is possible to make "new" datatypes as
fast as "native" ones.
I don't know if this is a great idea and to what extent this would
work, but you can do something more or less the way CFFI does it:
(definecompilermacro mref (&whole whole matrix i j)
(or (mrefexpand (getdeclaredtypeoforgiveup matrix) matrix i
j)
whole))
(defgeneric mrefexpand (matrixtype matrix i j)
(:method ((matrixtype t) matrix i j)
nil))
(defmethod mrefexpand ((matrixtype (eql 'densematrix)) matrix i j)
`(aref (elements ,matrix) ,i ,j))
The problem would be to get the declared type of some element. There
is http://commonlisp.net/project/parsedeclarations/ , but some outer
macro will need to get these declarations and pass them along.
An alternative is to use some implementationdependant feature (SBCL's
deftransform seems to fit very well for this purpose, just look at a
couple of them from SBCL's source code and you would see how they
work).
.
I include some code snippets and benchmarks below, help is
appreciated, I am using SBCL but I am also interested in general
techniques  when I package this up as a library (eventually), I would
prefer if it was general to all implementations.
Thanks,
Tamas
 References:
 speeding up wrapper for "new" datatype
 From: Tamas K Papp
 speeding up wrapper for "new" datatype
 Prev by Date: Re: open and :supersede
 Next by Date: Labirint in LISP please help me
 Previous by thread: Re: speeding up wrapper for "new" datatype
 Next by thread: Re: speeding up wrapper for "new" datatype
 Index(es):
Relevant Pages
