From 27d461f5ffe119f5061115f9c9e4c10f1a2b6663 Mon Sep 17 00:00:00 2001 From: Liam Healy <liam@thinkpad.local> Date: Thu, 1 Jul 2010 19:47:03 -0400 Subject: [PATCH] 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. --- data/both.lisp | 4 ++-- data/foreign-array.lisp | 8 ++++---- fast-fourier-transforms/example.lisp | 4 ++-- init/init.lisp | 6 +++--- init/mobject.lisp | 6 ++++-- tests/scale.lisp | 13 ++++++------- tests/setf-row.lisp | 3 ++- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/data/both.lisp b/data/both.lisp index 3afc593c..e65f4dec 100644 --- a/data/both.lisp +++ b/data/both.lisp @@ -1,6 +1,6 @@ ;; 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 diff --git a/data/foreign-array.lisp b/data/foreign-array.lisp index c16e3155..b59ae3a4 100644 --- a/data/foreign-array.lisp +++ b/data/foreign-array.lisp @@ -1,6 +1,6 @@ ;; 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) diff --git a/fast-fourier-transforms/example.lisp b/fast-fourier-transforms/example.lisp index b7584859..7cbfce3e 100644 --- a/fast-fourier-transforms/example.lisp +++ b/fast-fourier-transforms/example.lisp @@ -1,6 +1,6 @@ ;; 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)) diff --git a/init/init.lisp b/init/init.lisp index c933199d..bb91c11b 100644 --- a/init/init.lisp +++ b/init/init.lisp @@ -1,6 +1,6 @@ ;; 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 diff --git a/init/mobject.lisp b/init/mobject.lisp index f675a2da..f21c7f41 100644 --- a/init/mobject.lisp +++ b/init/mobject.lisp @@ -1,6 +1,6 @@ ;; 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) diff --git a/tests/scale.lisp b/tests/scale.lisp index 5b071308..d015c20e 100644 --- a/tests/scale.lisp +++ b/tests/scale.lisp @@ -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 diff --git a/tests/setf-row.lisp b/tests/setf-row.lisp index fb487d45..6c6e332d 100644 --- a/tests/setf-row.lisp +++ b/tests/setf-row.lisp @@ -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 -- GitLab