Hello list,
sorry if this has been asked before.
I've been trying to interface sbcl to the gsl library especially passing vectors and/or matrices.
The docs state that there is no :array type.
Is it somehow possible to interface to the gsl library to do e.g. spline or matrix ops ? If it is possible it would be nice to have one or two examples in the docs.
Thanks and Regards Heiko Schroeter
I've been trying to interface sbcl to the gsl library especially passing vectors and/or matrices.
The docs state that there is no :array type.
Is it somehow possible to interface to the gsl library to do e.g. spline or matrix ops ? If it is possible it would be nice to have one or two examples in the docs.
Here are a few projects that perform similar tasks; they might be what you want. http://www.nlisp.info/ http://matlisp.sourceforge.net/ http://common-lisp.net/project/cl-gsl/
That said, I think the CFFI side goes something like this.
; C and C++ pass pointers to arrays... ; For C's "int x[4][5]", use (setq x (foreign-alloc :int :count 20))
Then its up to you to remember the dimensions...
(defun x-aref (x r c) (mem-aref x :int (+ (* r 5) c)))
- Daniel
On 27/02/07, Heiko Schröter schroete@iup.physik.uni-bremen.de wrote:
The docs state that there is no :array type.
Not yet, no.
If it is possible it would be nice to have one or two examples in the docs.
This should help: http://article.gmane.org/gmane.lisp.cffi.devel/283/
Also I've attached a patch that incorporates the code above into CFFI. Largely untested and it's a patch against the cffi-newtypes branch located at http://common-lisp.net/~loliveira/darcs/cffi-newtypes/
Not much documentation, sorry. Here's a silly example. Couldn't think of a stdc function that returns an array (other than strings):
CFFI> (foreign-funcall "strdup" :string "hello" (:auto-array :char 5)) #(104 101 108 108 111)
;; couldn't miss the opportunity to use the mostly useless :wrapper type CFFI> (foreign-funcall "strdup" :string "hello" (:auto-array (:wrapper :char :from-c code-char) 5)) #(#\h #\e #\l #\l #\o)