Commit add07a4f authored by Liam Healy's avatar Liam Healy

Eliminate 'marray; replace make-marray with grid:make-foreign-array

parent eebc5a48
;; Basis splines.
;; Liam Healy 2008-02-18 14:43:20EST basis-splines.lisp
;; Time-stamp: <2010-01-17 10:41:03EST basis-splines.lisp>
;; Time-stamp: <2010-06-29 22:15:23EDT basis-splines.lisp>
;;
;; Copyright 2008, 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -56,7 +56,7 @@
(defmfun evaluate
((workspace basis-spline) x
&key (B (make-marray 'double-float
&key (B (grid:make-foreign-array 'double-float
:dimensions (number-of-coefficients workspace))))
"gsl_bspline_eval"
((x :double) ((mpointer B) :pointer) ((mpointer workspace) :pointer))
......@@ -112,13 +112,13 @@
(bw (make-basis-spline order nbreak))
(mw (make-fit-workspace ndata ncoeffs))
(rng (make-random-number-generator +mt19937+ 0))
(B (make-marray 'double-float :dimensions ncoeffs))
(c (make-marray 'double-float :dimensions ncoeffs))
(cov (make-marray 'double-float :dimensions (list ncoeffs ncoeffs)))
(w (make-marray 'double-float :dimensions ndata))
(x (make-marray 'double-float :dimensions ndata))
(y (make-marray 'double-float :dimensions ndata))
(Xmatrix (make-marray 'double-float :dimensions (list ndata ncoeffs)))
(B (grid:make-foreign-array 'double-float :dimensions ncoeffs))
(c (grid:make-foreign-array 'double-float :dimensions ncoeffs))
(cov (grid:make-foreign-array 'double-float :dimensions (list ncoeffs ncoeffs)))
(w (grid:make-foreign-array 'double-float :dimensions ndata))
(x (grid:make-foreign-array 'double-float :dimensions ndata))
(y (grid:make-foreign-array 'double-float :dimensions ndata))
(Xmatrix (grid:make-foreign-array 'double-float :dimensions (list ndata ncoeffs)))
(sigma 0.1d0))
;; The data to be fitted.
(dotimes (i ndata)
......
;; Monte Carlo Integration
;; Liam Healy Sat Feb 3 2007 - 17:42
;; Time-stamp: <2010-06-27 18:13:57EDT monte-carlo.lisp>
;; Time-stamp: <2010-06-29 22:15:24EDT monte-carlo.lisp>
;;
;; Copyright 2007, 2008, 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -211,7 +211,7 @@
(defparameter *mc-lower* #m(0.0d0 0.0d0 0.0d0))
(defparameter *mc-upper*
(make-marray 'double-float :initial-contents (list pi pi pi)))
(grid:make-foreign-array 'double-float :initial-contents (list pi pi pi)))
(defun random-walk-plain-example (&optional (nsamples 500000))
(monte-carlo-integrate-plain 'mcrw *mc-lower* *mc-upper* nsamples))
......
;; Functions for both vectors and matrices.
;; Liam Healy 2008-04-26 20:48:44EDT both.lisp
;; Time-stamp: <2010-06-27 21:31:00EDT both.lisp>
;; Time-stamp: <2010-06-29 22:12:07EDT both.lisp>
;;
;; Copyright 2008, 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -81,7 +81,7 @@
(defmfun grid:copy-making-destination
((source both) &aux
(destination
(make-marray element-type :dimensions (dimensions source))))
(grid:make-foreign-array element-type :dimensions (dimensions source))))
("gsl_" :category :type "_memcpy")
(((mpointer destination) :pointer) ((mpointer source) :pointer))
:definition :methods
......
;; Copy marrays to/from CL arrays
;; Copy grid:foreign-arrays to/from CL arrays
;; Liam Healy 2009-02-11 19:28:44EST copy-cl.lisp
;; Time-stamp: <2010-06-27 18:03:25EDT copy-cl.lisp>
;; Time-stamp: <2010-06-29 22:51:21EDT copy-cl.lisp>
;;
;; Copyright 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -20,17 +20,17 @@
;;; The function #'copy can be used to copy the contents to or from a
;;; CL array. If the destination isn't literally supplied, it can be
;;; a symbol 'array indicating that the marray is to be copied to a CL
;;; a symbol 'array indicating that the grid:foreign-array is to be copied to a CL
;;; array, or an element type like 'double-float, indicating the
;;; contents of the CL array is to be copied to a new marray with the
;;; contents of the CL array is to be copied to a new grid:foreign-array with the
;;; given element type.
;;; Contrast this with the function #'cl-array or the initarg
;;; :cl-array to #'make-marray. The function returns the cl-array
;;; :cl-array to #'grid:make-foreign-array. The function returns the cl-array
;;; without copying, and so might be faster but also makes the
;;; original marray object vulnerable if an element is changed, which
;;; original grid:foreign-array object vulnerable if an element is changed, which
;;; officially has unpredictable results. Likewise, the initarg will
;;; use the given CL array directly in the created marray without
;;; use the given CL array directly in the created grid:foreign-array without
;;; copying.
(in-package :gsl)
......@@ -68,21 +68,21 @@
(setf (maref destination i j) (aref source i j))))
destination)
(defmethod grid:copy-to-destination ((source marray) (destclass (eql 'array)))
(defmethod grid:copy-to-destination ((source grid:foreign-array) (destclass (eql 'array)))
(let ((destination
(grid:make-ffa (element-type source) :dimensions (dimensions source))))
(grid:copy-to-destination source destination)))
;;; Copy to a named marray element-type, where the type is a symbol
;;; Copy to a named grid:foreign-array element-type, where the type is a symbol
(defmethod grid:copy-to-destination ((source array) (destclass symbol))
(let ((destination
(make-marray destclass :dimensions (array-dimensions source))))
(grid:make-foreign-array destclass :dimensions (array-dimensions source))))
(grid:copy-to-destination source destination)))
;;; Copy to a named marray element-type, where the type is a list
;;; Copy to a named grid:foreign-array element-type, where the type is a list
(defmethod grid:copy-to-destination ((source array) (destclass list))
(let ((destination
(make-marray destclass :dimensions (array-dimensions source))))
(grid:make-foreign-array destclass :dimensions (array-dimensions source))))
(grid:copy-to-destination source destination)))
;;; Examples and tests
......
;; A grid:foreign-array with added metadata for GSL.
;; Liam Healy 2008-04-06 21:23:41EDT
;; Time-stamp: <2010-06-29 21:41:40EDT foreign-array.lisp>
;; Time-stamp: <2010-06-29 22:08:52EDT foreign-array.lisp>
;;
;; Copyright 2008, 2009, 2010 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -69,36 +69,6 @@
(metadata-slot object 'mpointer)
(make-gsl-metadata object)))
;;;;****************************************************************************
;;;; Make data from either the dimensions provided or from the initial values
;;;;****************************************************************************
;;;;;;; There are >1400 calls to make-marray, write an emulation?
;;; This should probably be moved/renamed grid:make-foreign-array.
(export 'make-marray)
(defun make-marray (element-type &rest keys &key dimensions &allow-other-keys)
"Make a GSLL array with the given element type,
:dimensions, and :initial-contents, :initial-element or :data."
(when (subtypep element-type 'grid:foreign-array)
(error "Can't take a class name here anymore, sorry."))
(apply
'grid:make-grid
`((grid:foreign-array ,@(alexandria:ensure-list dimensions)) ,element-type)
keys))
(defun make-marray-or-default
(default dimensions
&optional dont-make-if-nil (element-type 'double-float) initial-element)
"If default is T or dont-make-if-nil, make a marray and
returned with the dimensions and element-type. If default is a
marray, it is returned."
(if (member default (list t dont-make-if-nil))
(if initial-element
(make-marray
element-type :dimensions dimensions :initial-element initial-element)
(make-marray element-type :dimensions dimensions))
default))
;;;;****************************************************************************
;;;; Make from GSL mpointers
;;;;****************************************************************************
......
;; Matrices
;; Liam Healy 2008-04-15 21:57:52EDT matrix.lisp
;; Time-stamp: <2010-06-28 11:03:21EDT matrix.lisp>
;; Time-stamp: <2010-06-29 22:10:48EDT matrix.lisp>
;;
;; Copyright 2008, 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -45,7 +45,7 @@
(defmfun row
((matrix matrix) i
&optional (vector (make-marray element-type :dimensions (dim1 matrix))))
&optional (vector (grid:make-foreign-array element-type :dimensions (dim1 matrix))))
("gsl_matrix" :type "_get_row")
(((mpointer vector) :pointer) ((mpointer matrix) :pointer) (i sizet))
:definition :generic
......@@ -70,7 +70,7 @@
(defmfun column
((matrix matrix) i
&optional (vector (make-marray element-type :dimensions (dim0 matrix))))
&optional (vector (grid:make-foreign-array element-type :dimensions (dim0 matrix))))
("gsl_matrix" :type "_get_col")
(((mpointer vector) :pointer) ((mpointer matrix) :pointer) (i sizet))
:definition :generic
......@@ -145,7 +145,7 @@
((source matrix)
&optional
(destination
(make-marray element-type :dimensions (reverse (dimensions source)))))
(grid:make-foreign-array element-type :dimensions (reverse (dimensions source)))))
("gsl_matrix" :type "_transpose_memcpy")
(((mpointer destination) :pointer) ((mpointer source) :pointer))
:definition :generic
......
......@@ -290,12 +290,12 @@ area of memory.</p>
<p>
The <a href="http://repo.or.cz/w/gsd.git">GSD</a> suite provides
many functions for construction, transformation, and composition of
GSL marrays. When using grid functions for this purpose,
GSL grid:foreign-arrays. When using grid functions for this purpose,
the <code>grid:specification</code> will
contain <code>gsl:marray</code> as the type; for example,
contain <code>grid:foreign-array</code> as the type; for example,
</p>
<pre>
(grid:make-grid '((gsl:marray 3 3) double-float) :initial-element 0)
(grid:make-grid '((grid:foreign-array 3 3) double-float) :initial-element 0)
</pre>
<p>
will make a 3x3 <code>matrix-double-float</code>.
......@@ -304,7 +304,7 @@ area of memory.</p>
in that collection.
</p>
<p>
Common Lisp arrays should be created with <code>make-marray</code> or
Common Lisp arrays should be created with <code>grid:make-foreign-array</code> or
<code>#m</code>:
The #m reader macro in the default form creates a vector or matrix of
element type double-float, which is the most common type needed for
......@@ -348,8 +348,8 @@ area of memory.</p>
with <code>setf maref</code>. A complete CL array may
be extracted with the function <code>#'cl-array</code>.
</p>
<p>Copying marrays is performed with the function <code>copy</code>.
This works between marrays, pointers, and CL arrays. It is useful
<p>Copying grid:foreign-arrays is performed with the function <code>copy</code>.
This works between grid:foreign-arrays, pointers, and CL arrays. It is useful
for functions intended to be passed to GSL functions (for
e.g. solving, minimizing or fitting) that need to set a GSL vector
or matrix, because one can simply copy into the passed-in pointer.
......@@ -361,7 +361,7 @@ area of memory.</p>
<p>If you
use <a href="http://common-lisp.net/project/iterate/">iterate</a>,
there are extensions defined that make it easier to iterate over
marrays. These are:
grid:foreign-arrays. These are:
<ul>
<li><code>matrix-row</code>, <code>matrix-row-index</code></li>
<li><code>matrix-column</code>, <code>matrix-column-index</code></li>
......@@ -472,7 +472,7 @@ and arrays used internally or for function return.
<!-- Created: Feb 25 2005 -->
<!-- hhmts start -->
<small>
Time-stamp: <2010-06-27 18:05:50EDT index.html>
Time-stamp: <2010-06-29 22:51:17EDT index.html>
</small>
<!-- hhmts end -->
</div>
......
;; Real generalized eigensystems
;; Liam Healy 2009-02-16 12:55:04EST real-generalized.lisp
;; Time-stamp: <2009-12-27 09:45:35EST generalized.lisp>
;; Time-stamp: <2010-06-29 22:15:24EDT generalized.lisp>
;;
;; Copyright 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -59,7 +59,7 @@
(defmfun eigenvalues-gensymm
((A matrix) (B matrix)
&optional
(eigenvalues (make-marray element-type :dimensions (dim0 A)))
(eigenvalues (grid:make-foreign-array element-type :dimensions (dim0 A)))
(ws (eltcase complex (make-eigen-genherm (dim0 A))
t (make-eigen-gensymm (dim0 A)))))
(double-float "gsl_eigen_gensymm"
......@@ -81,8 +81,8 @@
(defmfun eigenvalues-eigenvectors-gensymm
((A matrix) (B matrix)
&optional
(eigenvalues (make-marray element-type :dimensions (dim0 A)))
(eigenvectors (make-marray element-type :dimensions (dimensions A)))
(eigenvalues (grid:make-foreign-array element-type :dimensions (dim0 A)))
(eigenvectors (grid:make-foreign-array element-type :dimensions (dimensions A)))
(ws (eltcase complex (make-eigen-hermv (dim0 A))
t (make-eigen-symmv (dim0 A)))))
(double-float "gsl_eigen_gensymmv"
......
;; Generalized eigensystems for nonsymmetric real matrices
;; Liam Healy 2009-02-16 14:27:20EST nonsymmetric-generalized.lisp
;; Time-stamp: <2009-12-27 09:45:35EST nonsymmetric-generalized.lisp>
;; Time-stamp: <2010-06-29 22:15:24EDT nonsymmetric-generalized.lisp>
;;
;; Copyright 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -54,20 +54,20 @@
(A B
&optional
(alpha
(make-marray '(complex double-float) :dimensions (dim0 A)))
(grid:make-foreign-array '(complex double-float) :dimensions (dim0 A)))
(beta
(make-marray 'double-float :dimensions (dim0 A)))
(grid:make-foreign-array 'double-float :dimensions (dim0 A)))
(ws (make-eigen-gen (dim0 A)))
compute-shur-form-s compute-shur-form-t shur-vectors
&aux
(balance nil) ; unused by GSL
(Q
(if (eql shur-vectors t)
(make-marray 'double-float :dimensions (dimensions A))
(grid:make-foreign-array 'double-float :dimensions (dimensions A))
shur-vectors))
(Z
(if (eql shur-vectors t)
(make-marray 'double-float :dimensions (dimensions A))
(grid:make-foreign-array 'double-float :dimensions (dimensions A))
shur-vectors)))
("gsl_eigen_gen" "gsl_eigen_gen_QZ")
((((mpointer A) :pointer) ((mpointer B) :pointer)
......@@ -114,22 +114,22 @@
(A B
&optional
(alpha
(make-marray '(complex double-float) :dimensions (dim0 A)))
(grid:make-foreign-array '(complex double-float) :dimensions (dim0 A)))
(beta
(make-marray 'double-float :dimensions (dim0 A)))
(grid:make-foreign-array 'double-float :dimensions (dim0 A)))
(eigenvectors
(make-marray 'double-float :dimensions (dimensions A)))
(grid:make-foreign-array 'double-float :dimensions (dimensions A)))
(ws (make-eigen-genv (dim0 A)))
compute-shur-form-s compute-shur-form-t shur-vectors
&aux
(balance nil) ; unused by GSL
(Q
(if (eql shur-vectors t)
(make-marray 'double-float :dimensions (dimensions A))
(grid:make-foreign-array 'double-float :dimensions (dimensions A))
shur-vectors))
(Z
(if (eql shur-vectors t)
(make-marray 'double-float :dimensions (dimensions A))
(grid:make-foreign-array 'double-float :dimensions (dimensions A))
shur-vectors)))
("gsl_eigen_genv" "gsl_eigen_genv_QZ")
((((mpointer A) :pointer) ((mpointer B) :pointer)
......
;; Eigensystems for nonsymmetric real matrices
;; Liam Healy 2009-02-16 12:51:18EST nonsymmetric.lisp
;; Time-stamp: <2009-12-27 09:45:34EST nonsymmetric.lisp>
;; Time-stamp: <2010-06-29 22:15:24EDT nonsymmetric.lisp>
;;
;; Copyright 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -52,13 +52,13 @@
(A
&optional
(eigenvalues
(make-marray '(complex double-float) :dimensions (dim0 A)))
(grid:make-foreign-array '(complex double-float) :dimensions (dim0 A)))
(ws (make-eigen-nonsymm (dim0 A)))
compute-shur-form balance shur-vectors
&aux
(sv
(if (eql shur-vectors t)
(make-marray 'double-float :dimensions (dimensions A))
(grid:make-foreign-array 'double-float :dimensions (dimensions A))
shur-vectors)))
("gsl_eigen_nonsymm" "gsl_eigen_nonsymm_Z")
((((mpointer A) :pointer)
......@@ -117,15 +117,15 @@
(A
&optional
(eigenvalues
(make-marray '(complex double-float) :dimensions (dim0 A)))
(grid:make-foreign-array '(complex double-float) :dimensions (dim0 A)))
(eigenvectors
(make-marray '(complex double-float) :dimensions (dimensions A)))
(grid:make-foreign-array '(complex double-float) :dimensions (dimensions A)))
(ws (make-eigen-nonsymmv (dim0 A)))
shur-vectors
&aux
(sv
(if (eql shur-vectors t)
(make-marray 'double-float :dimensions (dimensions A))
(grid:make-foreign-array 'double-float :dimensions (dimensions A))
shur-vectors)))
("gsl_eigen_nonsymmv" "gsl_eigen_nonsymmv_Z")
((((mpointer A) :pointer)
......
;; Eigenvectors and eigenvalues
;; Liam Healy, Sun May 21 2006 - 19:52
;; Time-stamp: <2009-12-27 09:43:47EST symmetric-hermitian.lisp>
;; Time-stamp: <2010-06-29 22:15:24EDT symmetric-hermitian.lisp>
;;
;; Copyright 2006, 2007, 2008, 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -69,7 +69,7 @@
(defmfun eigenvalues
((A matrix)
&optional
(eigenvalues (make-marray element-type :dimensions (dim0 A)))
(eigenvalues (grid:make-foreign-array element-type :dimensions (dim0 A)))
(ws (eltcase complex (make-eigen-herm (dim0 A))
t (make-eigen-symm (dim0 A)))))
(double-float "gsl_eigen_symm"
......@@ -94,8 +94,8 @@
(defmfun eigenvalues-eigenvectors
((A matrix)
&optional
(eigenvalues (make-marray element-type :dimensions (dim0 A)))
(eigenvectors (make-marray element-type :dimensions (dimensions A)))
(eigenvalues (grid:make-foreign-array element-type :dimensions (dim0 A)))
(eigenvectors (grid:make-foreign-array element-type :dimensions (dimensions A)))
(ws (eltcase complex (make-eigen-hermv (dim0 A))
t (make-eigen-symmv (dim0 A)))))
(double-float "gsl_eigen_symmv"
......@@ -159,8 +159,8 @@
|#
(defun eigenvalue-eigenvectors-example ()
(let ((evecs (make-marray 'double-float :dimensions '(3 3)))
(evals (make-marray 'double-float :dimensions 3))
(let ((evecs (grid:make-foreign-array 'double-float :dimensions '(3 3)))
(evals (grid:make-foreign-array 'double-float :dimensions 3))
(mat #m(20.0d0 -10.0d0 0.0d0 ^
-10.0d0 30.0d0 0.0d0 ^
0.0d0 0.0d0 40.0d0)))
......
;; Discrete Fourier Transforms
;; Liam Healy 2009-11-07 14:24:07EST
;; Time-stamp: <2010-06-27 18:13:59EDT discrete.lisp>
;; Time-stamp: <2010-06-29 22:15:25EDT discrete.lisp>
;;
;; Copyright 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -29,7 +29,7 @@
(defmfun forward-discrete-fourier-transform
((vector vector)
&key (stride 1)
(result (make-marray element-type :dimensions (dimensions vector))))
(result (grid:make-foreign-array element-type :dimensions (dimensions vector))))
("gsl_dft" :type "_forward")
(((foreign-pointer vector) :pointer) (stride sizet) ((floor (size vector) stride) sizet)
((foreign-pointer result) :pointer))
......@@ -45,7 +45,7 @@
(defmfun backward-discrete-fourier-transform
((vector vector)
&key (stride 1)
(result (make-marray element-type :dimensions (dimensions vector))))
(result (grid:make-foreign-array element-type :dimensions (dimensions vector))))
("gsl_dft" :type "_backward")
(((foreign-pointer vector) :pointer) (stride sizet) ((floor (size vector) stride) sizet)
((foreign-pointer result) :pointer))
......@@ -61,7 +61,7 @@
(defmfun inverse-discrete-fourier-transform
((vector vector)
&key (stride 1)
(result (make-marray element-type :dimensions (dimensions vector))))
(result (grid:make-foreign-array element-type :dimensions (dimensions vector))))
("gsl_dft" :type "_inverse")
(((foreign-pointer vector) :pointer) (stride sizet) ((floor (size vector) stride) sizet)
((foreign-pointer result) :pointer))
......@@ -77,7 +77,7 @@
(defmfun discrete-fourier-transform
((vector vector)
&key (stride 1)
(result (make-marray element-type :dimensions (dimensions vector))))
(result (grid:make-foreign-array element-type :dimensions (dimensions vector))))
("gsl_dft" :type "_transform")
(((foreign-pointer vector) :pointer) (stride sizet) ((floor (size vector) stride) sizet)
((foreign-pointer result) :pointer))
......
;; Example FFT: transform a pulse (using the "clean" fft interface)
;; Sumant Oemrawsingh, Sat Oct 31 2009 - 00:24
;; Time-stamp: <2010-06-27 18:03:24EDT example.lisp>
;; Time-stamp: <2010-06-29 22:15:25EDT example.lisp>
;;
;; Copyright 2009 Sumant Oemrawsingh, Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -40,7 +40,7 @@
(defun fft-pulse-test (element-type dimension)
(assert (and (integerp dimension) (> dimension 20)))
(let ((pulse (make-marray element-type :dimensions dimension))
(let ((pulse (grid:make-foreign-array element-type :dimensions dimension))
(init-value (coerce 1 element-type)))
(setf (maref pulse 0) init-value)
(loop for i from 1 to 10
......@@ -76,7 +76,7 @@
;; (make-urand-vector '(complex double-float) 5)
(defun make-urand-vector (element-type dimension &key (stride 1))
"Make a vector with random elements."
(let ((vec (make-marray `(complex ,(grid:component-float-type element-type))
(let ((vec (grid:make-foreign-array `(complex ,(grid:component-float-type element-type))
:dimensions (list (* stride dimension)))))
(loop for i from 0 below (* stride dimension) by stride
do
......@@ -89,7 +89,7 @@
(defun realpart-vector (complex-vector)
"The real vector consisting of the real part of the complex vector."
(let ((real-vector
(make-marray
(grid:make-foreign-array
(grid:component-float-type (element-type complex-vector))
:dimensions (dimensions complex-vector))))
(loop for i below (total-size complex-vector) do
......@@ -141,7 +141,7 @@
(if (and (have-at-least-gsl-version '(1 12)) #+fsbv t #-fsbv nil)
(elt/ (copy backward) (size-vector-real backward :stride stride))
;; Hack for old GSL version without complex vector math
(make-marray
(grid:make-foreign-array
(element-type backward)
:dimensions (dimensions backward)
:initial-contents
......
......@@ -59,7 +59,7 @@
neg-f
(loop for i from min-f-index below 0
collect (coerce (* i df) element-type)))
(make-marray element-type
(grid:make-foreign-array element-type
:initial-contents (if shifted
(nconc neg-f pos-f)
(nconc pos-f neg-f))))))
......
;; Unpack functions for FFT vectors.
;; Sumant Oemrawsingh, Sun Oct 25 2009 - 16:35
;; Time-stamp: <2010-06-27 18:14:00EDT unpack.lisp>
;; Time-stamp: <2010-06-29 22:12:06EDT unpack.lisp>
;;
;; Copyright 2009 Sumant Oemrawsingh, Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -30,9 +30,9 @@
&key (stride 1)
(output
(eltcase single-float
(make-marray '(complex single-float) :dimensions (size vector))
(grid:make-foreign-array '(complex single-float) :dimensions (size vector))
t
(make-marray '(complex double-float) :dimensions (size vector)))))
(grid:make-foreign-array '(complex double-float) :dimensions (size vector)))))
("gsl_fft_real" :type "_unpack")
(((foreign-pointer vector) :pointer)
((foreign-pointer output) :pointer)
......@@ -54,9 +54,9 @@
&key (stride 1)
(output
(eltcase single-float
(make-marray '(complex single-float) :dimensions (size vector))
(grid:make-foreign-array '(complex single-float) :dimensions (size vector))
t
(make-marray '(complex double-float) :dimensions (size vector)))))
(grid:make-foreign-array '(complex double-float) :dimensions (size vector)))))
("gsl_fft_halfcomplex" :type "_radix2_unpack")
(((foreign-pointer vector) :pointer)
((foreign-pointer output) :pointer)
......@@ -77,9 +77,9 @@
&key (stride 1)
(output
(eltcase single-float
(make-marray '(complex single-float) :dimensions (size vector))
(grid:make-foreign-array '(complex single-float) :dimensions (size vector))
t
(make-marray '(complex double-float) :dimensions (size vector)))))
(grid:make-foreign-array '(complex double-float) :dimensions (size vector)))))
("gsl_fft_halfcomplex" :type "_unpack")
(((foreign-pointer vector) :pointer)
((foreign-pointer output) :pointer)
......
;; Discrete Hankel Transforms.
;; Liam Healy, Sat Dec 8 2007 - 16:50
;; Time-stamp: <2010-06-27 18:13:50EDT hankel.lisp>
;; Time-stamp: <2010-06-29 22:15:22EDT hankel.lisp>
;;
;; Copyright 2007, 2008, 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -39,7 +39,7 @@
(defmfun apply-hankel
(hankel array-in
&optional
(array-out (make-marray 'double-float :dimensions (dimensions array-in))))
(array-out (grid:make-foreign-array 'double-float :dimensions (dimensions array-in))))
"gsl_dht_apply"
(((mpointer hankel) :pointer) ((foreign-pointer array-in) :pointer)
((foreign-pointer array-out) :pointer))
......@@ -79,7 +79,7 @@
'array))
;; Simple
(let ((hank (make-hankel 128 0.0d0 100.0d0))
(in (make-marray 'double-float :dimensions 128)))
(in (grid:make-foreign-array 'double-float :dimensions 128)))
(loop for n from 0 below 128
do (setf (maref in n)
(/ (1+ (expt (sample-x-hankel hank n) 2)))))
......@@ -87,13 +87,13 @@
;; Integrate[ x exp(-x) J_1(a x), {x,0,Inf}] = a F(3/2, 2; 2; -a^2)
;; expected accuracy only about 2%
(let ((hank (make-hankel 128 1.0d0 20.0d0))
(in (make-marray 'double-float :dimensions 128)))
(in (grid:make-foreign-array 'double-float :dimensions 128)))
(loop for n from 0 below 128
do (setf (maref in n) (exp (- (sample-x-hankel hank n)))))
(copy (apply-hankel hank in) 'array))
;; Integrate[ x^2 (1-x^2) J_1(a x), {x,0,1}] = 2/a^2 J_3(a)
(let ((hank (make-hankel 128 1.0d0 1.0d0))
(in (make-marray 'double-float :dimensions 128)))
(in (grid:make-foreign-array 'double-float :dimensions 128)))
(loop for n from 0 below 128
do (setf (maref in n)
(let ((x (sample-x-hankel hank n)))
......
;; Foreign callback functions.
;; Liam Healy
;; Time-stamp: <2010-06-27 18:03:22EDT callback.lisp>
;; Time-stamp: <2010-06-29 22:51:19EDT callback.lisp>
;;
;; Copyright 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -37,13 +37,13 @@
;;; they are defined with those tasks. The macro #'defmcallback can
;;; specify that the CL function is to expect in arglist and return as
;;; multiple values scalar quantities that come from and will be bound
;;; to either marrays or C vectors. This is done with a list of the
;;; to either grid:foreign-arrays or C vectors. This is done with a list of the
;;; type and size, e.g. (:double 3), and for setting :set, type size,
;;; e.g. (:set :double 3). If the 'marray argument is nil, it will
;;; e.g. (:set :double 3). If the 'grid:foreign-array argument is nil, it will
;;; expand to read or set a C vector; if it is T, it will expand to
;;; read or set a marray. This allows the user to define ordinary CL
;;; read or set a grid:foreign-array. This allows the user to define ordinary CL
;;; functions with scalars as input and output. However, it may be
;;; desirable to read and set marrays, in which case :pointer is the
;;; desirable to read and set grid:foreign-arrays, in which case :pointer is the
;;; right specification.
;;;;****************************************************************************
......@@ -125,7 +125,7 @@
(ecase component
(io (first argspec)) ; :input or :output
(element-type (second argspec)) ; :double
(array-type (third argspec)) ; :marray or :cvector
(array-type (third argspec)) ; :foreign-array or :cvector
(dimensions (nthcdr 3 argspec))))
;;;;****************************************************************************
......
;; Generate a lambda that calls the user function; will be called by callback.
;; Liam Healy
;; Time-stamp: <2010-06-27 18:03:18EDT funcallable.lisp>
;; Time-stamp: <2010-06-29 22:49:08EDT funcallable.lisp>
;;
;; Copyright 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -70,7 +70,7 @@
"Form to reference, for getting or setting, the element of a foreign
array, or a scalar."
(if (parse-callback-argspec argspec 'dimensions)
(if (eql (parse-callback-argspec argspec 'array-type) :marray)
(if (eql (parse-callback-argspec argspec 'array-type) :foreign-array)
`(maref
,foreign-variable-name
,@(let ((dims (value-from-dimensions argspec dimension-values)))
......
;; Define examples.
;; Liam Healy 2008-09-07 21:00:48EDT generate-tests.lisp