Subject: [clisp-list] Re: FFI with complex numbers?

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Thu May 13 09:19:08 2004

Hi,

Sam wrote:
>Maybe you could record your experiences putting together your
>module which could be later turned into <clisp.h> documentation?
>Here is a start:
Suggestions:
 o mention begin/end_call()
 o briefly mention callbacks is a little more complicated
 o refer to the GC section of the doc, IIRC it talks about keeping OBJECTS on STACK.

Michael wrote:
>3) the LISP wrapper should behave as the foreign function, namely it should 
>modify its argument (destructive behavior) 

You CAN use the FFI, using the malloc' code you provided yourself. The FFI supports arrays of floats, simple or double. It's just not fast.
But you MUST use CL:REPLACE afterwards, to overwrite the original Lisp array with possibly modified contents. There's no way around this. The Lisp wrapper you showed did not perform this final step.

You CAN use Sam's code. It must be faster than using the FFI. But it also does not overwrite the results, you'll have a two line loop.

I wouldn't count on memcpy() for giving you speed improvements in this application, unless you copy a few thousand objects.

I hope the situation is clear from now on.

>4) the wrapper should be *generic*: the input array can have any length, there 
>can be more than one input argument that could be modified by the foreign 
>function.
I think you already know how to deal with any length. I'm not sure whether you want a function that can process a variable (unknown) number of parameters, some of which maybe arrays, which all would require :in-out semantics??

That could be done using the FFI as well, but then I'd use memoization on parse-c-type to keep one c-type per function signature. Sam's C code obviously only deals with one kind of signature: (double*,int size).

Or is there a rather limited set of different signatures in Matlisp, like max. 2 arrays as :in-out parameters, e.g. (double*1,int size1, double*2,int size2) beside the other one?
Are semantics always :in-out? I'd bet there's pure :in as well.
Then it would be more reasonable to provide a fixed set of wrappers.

Regards,
	Jorg Hohle.

---

From: Sam Steingold <[email-masked]>
Date: Thu May 13 10:28:02 2004

> * Hoehle, Joerg-Cyril <[email-masked]> [2004-05-13 18:17:51 +0200]:
>
> You CAN use Sam's code. It must be faster than using the FFI. But it
> also does not overwrite the results, you'll have a two line loop.

it _DOES_ overwrite the results!!!
please look at the code again!

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
cogito cogito ergo cogito sum