Commit 27d461f5 authored by Liam Healy's avatar Liam Healy

Use #'gsl:size to call #'grid:total-size for foreign arrays

Use #'gsl:size to call #'grid:total-size for foreign arrays, and use
the former function exclusively in GSLL.  Fix some more tests.
parent 00af1f83
;; Functions for both vectors and matrices.
;; Liam Healy 2008-04-26 20:48:44EDT both.lisp
;; Time-stamp: <2010-06-29 22:12:07EDT both.lisp>
;; Time-stamp: <2010-07-01 19:38:01EDT both.lisp>
;;
;; Copyright 2008, 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -28,7 +28,7 @@
("gsl_" :category :type "_alloc_from_block")
((blockptr :pointer)
(0 sizet) ; offset
((total-size object) sizet) ; number of elements
((size object) sizet) ; number of elements
(1 sizet)) ; stride
:definition :generic
:c-return :pointer
......
;; A grid:foreign-array with added metadata for GSL.
;; Liam Healy 2008-04-06 21:23:41EDT
;; Time-stamp: <2010-06-30 18:03:10EDT foreign-array.lisp>
;; Time-stamp: <2010-07-01 19:38:35EDT foreign-array.lisp>
;;
;; Copyright 2008, 2009, 2010 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -21,7 +21,7 @@
(in-package :gsl)
;;;;****************************************************************************
;;;; Make the mpointer, block-pointer, total-size metadata
;;;; Make the mpointer, block-pointer, size metadata
;;;;****************************************************************************
;;; We don't allocate or free the C array data, because that is
......@@ -38,11 +38,11 @@
it is called on a particular foreign-array."
;; Don't do anything if mpointer has already been assigned.
(unless (grid:metadata-slot object 'mpointer)
(when (zerop (total-size object))
(when (zerop (size object))
(error "Object ~a has zero total dimension." object))
(let ((blockptr (cffi:foreign-alloc 'gsl-block-c)))
(setf (cffi:foreign-slot-value blockptr 'gsl-block-c 'size)
(grid:total-size object)
(size object)
(cffi:foreign-slot-value blockptr 'gsl-block-c 'data)
(foreign-pointer object)
(grid:metadata-slot object 'block-pointer) blockptr)
......
;; Example FFT: transform a pulse (using the "clean" fft interface)
;; Sumant Oemrawsingh, Sat Oct 31 2009 - 00:24
;; Time-stamp: <2010-06-30 19:57:28EDT example.lisp>
;; Time-stamp: <2010-07-01 19:38:50EDT example.lisp>
;;
;; Copyright 2009 Sumant Oemrawsingh, Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -92,7 +92,7 @@
(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
(loop for i below (size complex-vector) do
(setf (grid:gref real-vector i)
(realpart (grid:gref complex-vector i))))
real-vector))
......
;; Load GSL
;; Liam Healy Sat Mar 4 2006 - 18:53
;; Time-stamp: <2010-06-29 21:09:24EDT init.lisp>
;; Time-stamp: <2010-07-01 19:36:05EDT init.lisp>
;;
;; Copyright 2006, 2007, 2008, 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -23,13 +23,13 @@
(:use :common-lisp :cffi)
(:import-from
:grid
#:cl-array #:dimensions #:total-size #:element-type
#:cl-array #:dimensions #:element-type
#:foreign-array #:matrix #:dim0 #:dim1 #:^
; #:copy #:clone
)
(:shadowing-import-from :grid #:foreign-pointer)
(:export
#:cl-array #:dimensions #:total-size #:element-type #:dim0 #:dim1
#:cl-array #:dimensions #:element-type #:dim0 #:dim1
#:copy #:clone))
(cffi:define-foreign-library libgslcblas
......
;; Definition of GSL objects and ways to use them.
;; Liam Healy, Sun Dec 3 2006 - 10:21
;; Time-stamp: <2010-06-29 22:51:18EDT mobject.lisp>
;; Time-stamp: <2010-07-01 19:37:25EDT mobject.lisp>
;;
;; Copyright 2006, 2007, 2008, 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -309,7 +309,9 @@
(defgeneric size (object)
(:documentation "The size of the GSL object.")
(:method ((object array))
(array-total-size object)))
(array-total-size object))
(:method ((object grid:foreign-array))
(grid:total-size object)))
(export 'evaluate)
(defgeneric evaluate (object point &key #+sbcl &allow-other-keys)
......
......@@ -30,10 +30,9 @@
(GRID:MAKE-FOREIGN-ARRAY
'(COMPLEX SINGLE-FLOAT)
:INITIAL-CONTENTS
'(-34.5 8.24 3.29 -8.93 34.12
-6.15 49.27 -13.49 32.5 42.73
-17.24 43.31 -16.12 -8.25 21.44
-49.08)))
'(#C(-34.5 8.24) #C(3.29 -8.93) #C(34.12 -6.15)
#C(49.27 -13.49) #C(32.5 42.73)
#C(-17.24 43.31) #C(-16.12 -8.25) #C(21.44 -49.08))))
(SCALAR 32.5))
(CL-ARRAY (SCALE SCALAR V1)))))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
......@@ -61,7 +60,7 @@
(GRID:MAKE-FOREIGN-ARRAY
'SINGLE-FLOAT
:INITIAL-CONTENTS
'(#C(-34.5 8.24) #C(3.29 -8.93) #C(34.12 -6.15) #C(49.27 -13.49))))
'(-34.5 8.24 3.29 -8.93 34.12 -6.15 49.27 -13.49)))
(SCALAR 32.5))
(CL-ARRAY (SCALE SCALAR V1)))))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
......@@ -73,8 +72,8 @@
(LET ((V1
(GRID:MAKE-FOREIGN-ARRAY
'DOUBLE-FLOAT :INITIAL-CONTENTS
'(#C(-34.5d0 8.24d0) #C(3.29d0 -8.93d0)
#C(34.12d0 -6.15d0) #C(49.27d0 -13.49d0))))
'(-34.5d0 8.24d0 3.29d0 -8.93d0
34.12d0 -6.15d0 49.27d0 -13.49d0)))
(SCALAR 32.5d0))
(CL-ARRAY (SCALE SCALAR V1)))))
#+fsbv
......
......@@ -93,7 +93,8 @@
(ROW
(GRID:MAKE-FOREIGN-ARRAY
'(COMPLEX DOUBLE-FLOAT)
:INITIAL-CONTENTS '(42.73d0 -17.24d0 43.31d0 -16.12d0 -8.25d0 21.44d0))))
:INITIAL-CONTENTS
'(#C(42.73d0 -17.24d0) #C(43.31d0 -16.12d0) #C(-8.25d0 21.44d0)))))
(SETF (ROW M1 2) ROW)
(CL-ARRAY M1))))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
......
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