Commit 4670733d authored by Liam Healy's avatar Liam Healy

Make marray using CL arrays generated with make-ffa

In #'make-marray, :cl-array argument will build that marray out of a
CL array.  This CL array should have been generated with #'make-ffa;
this symbol 'make-ffa is now exported for users.
parent cbcc15dd
;; Foreign arrays (usually in C)
;; Liam Healy 2008-12-28 10:44:22EST foreign-array.lisp
;; Time-stamp: <2009-01-04 21:42:09EST foreign-array.lisp>
;; Time-stamp: <2009-02-10 23:05:32EST foreign-array.lisp>
;; $Id: $
(in-package :gsl)
......@@ -12,12 +12,12 @@
(export '(dimensions total-size element-type))
(defclass foreign-array ()
((cl-array :documentation "The Lisp array.")
((cl-array :initarg :cl-array :documentation "The Lisp array.")
(c-pointer :accessor c-pointer :documentation "A pointer to the C array.")
(dimensions :reader dimensions)
(total-size :reader total-size)
(element-type :reader element-type)
(element-type :initarg :element-type :reader element-type)
(original-array :reader original-array)
(offset :reader offset)
......@@ -46,14 +46,14 @@
&key dimensions initial-contents initial-element)
(declare (ignore dimensions initial-contents initial-element))
(with-slots (cl-array dimensions original-array offset total-size) object
(let ((ffa (apply #'make-ffa (element-type object) initargs)))
(setf cl-array ffa
dimensions (array-dimensions ffa)
total-size (array-total-size ffa)))
(unless (and (slot-boundp object 'cl-array) cl-array)
(setf cl-array (apply #'make-ffa (element-type object) initargs)))
(setf dimensions (array-dimensions cl-array)
total-size (array-total-size cl-array))
(let ((cptr (cffi:foreign-alloc
(cl-cffi (element-type object))
:count (total-size object))))
(cl-cffi (element-type object))
:count (total-size object))))
(setf (c-pointer object) cptr)
(tg:finalize object (lambda () (cffi:foreign-free cptr))))
#-native (setf (cl-invalid object) nil)
;; Use the foreign-friendly arrays package.
;; Liam Healy 2008-03-22 15:40:08EDT
;; Time-stamp: <2009-01-10 12:47:53EST foreign-friendly.lisp>
;; Time-stamp: <2009-02-10 22:40:05EST foreign-friendly.lisp>
;; $Id$
;;; Foreign-friendly arrays (original implementation by Tamas Papp)
......@@ -14,6 +14,7 @@
;;;; Make arrays for possible foreign use
(export 'make-ffa)
(defun make-ffa
&key dimensions (initial-element nil initial-element-p)
;; A "marray" is an array in both GSL and CL
;; Liam Healy 2008-04-06 21:23:41EDT
;; Time-stamp: <2008-12-28 18:54:20EST marray.lisp>
;; Time-stamp: <2009-02-10 22:39:58EST marray.lisp>
;; $Id$
(in-package :gsl)
......@@ -92,10 +92,11 @@
(export 'make-marray)
(defun make-marray
(element-type &rest keys &key dimensions initial-contents from-pointer
(element-type &rest keys &key dimensions initial-contents from-pointer cl-array
"Make a GSLL array with the given element type,
:dimensions, :initial-contents and/or :initial-element.
:dimensions, and :initial-contents, :initial-element or :cl-array.
If the :cl-array is supplied, it should be a CL array generated with #'make-ffa.
If a pointer to a GSL object is given in :from-pointer, create
an object with duplicate contents; if a matrix, :dimensions must be set to 2."
;; Some functions in solve-minimize-fit return a pointer to a GSL
......@@ -116,7 +117,8 @@
(and dimensions (listp dimensions) (eql (length dimensions) 2))
(and initial-contents (listp (first initial-contents))))
(and initial-contents (listp (first initial-contents)))
(and cl-array (eql (length (array-dimensions cl-array)) 2)))
'matrix 'vector)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment