From d1f1a4a709dd5aae239783b0961a8e3721993ff5 Mon Sep 17 00:00:00 2001 From: liam <liam@a3d8a0fb-c1db-0310-ace7-a616afeb9e30> Date: Thu, 30 Mar 2006 04:53:01 +0000 Subject: [PATCH] Swap first two arguments of with-data so that symbol is first. Make a separate gsl-vector-c type. #'subvector still gets "memory fault". git-svn-id: svn+ssh://pop/opt/space/mathematics/gsl/trunk@3010 a3d8a0fb-c1db-0310-ace7-a616afeb9e30 --- data/data.lisp | 4 ++-- data/vector.lisp | 46 +++++++++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/data/data.lisp b/data/data.lisp index e19c68d4..2e26fbf6 100644 --- a/data/data.lisp +++ b/data/data.lisp @@ -3,7 +3,7 @@ ; description: Using GSL storage. ; date: Sun Mar 26 2006 - 16:32 ; author: Liam M. Healy -; modified: Mon Mar 27 2006 - 00:03 +; modified: Wed Mar 29 2006 - 23:35 ;******************************************************** ;;; $Id: $ @@ -82,7 +82,7 @@ (export 'with-data) -(defmacro with-data ((type symbol size &optional zero) &body body) +(defmacro with-data ((symbol type size &optional zero) &body body) "Allocate GSL data, bind to pointer, and then deallocated it when done. If zero is T, zero the contents when allocating." diff --git a/data/vector.lisp b/data/vector.lisp index 1dcbb254..9e45fb32 100644 --- a/data/vector.lisp +++ b/data/vector.lisp @@ -3,7 +3,7 @@ ; description: Vectors and matrices ; date: Sun Mar 26 2006 - 11:51 ; author: Liam M. Healy -; modified: Wed Mar 29 2006 - 17:39 +; modified: Wed Mar 29 2006 - 23:35 ;******************************************************** ;;; $Id: $ @@ -52,7 +52,7 @@ deallocated with the vector. ;;; Allocation, freeing, reading and writing (gsl-data-functions "vector") -(setf *wrap-types* (acons 'gsl-vector (lambda (x) `(pointer ,x)) *wrap-types*)) +(setf *wrap-types* (acons 'gsl-vector-c (lambda (x) `(pointer ,x)) *wrap-types*)) ;;;;**************************************************************************** ;;;; Accessing elements @@ -116,22 +116,21 @@ deallocated with the vector. ;;;;**************************************************************************** (cffi:defcstruct gsl-vector-view - (vector gsl-vector)) + (vector gsl-vector-c)) (setf *wrap-types* (acons 'gsl-vector-view (lambda (x) - x + ;;x #+no `(cffi:foreign-slot-value ,x 'gsl-vector-view 'vector) - #+no `(make-instance 'gsl-vector :pointer (cffi:foreign-slot-value ,x 'gsl-vector-view 'vector))) *wrap-types*)) ;;; improve documentation -(defun-gsl subvector ((vector gsl-vector) (offset :size) (size :size)) +(defun-gsl subvector ((vector gsl-vector-c) (offset :size) (size :size)) "gsl_vector_subvector" :c-return-value :return :return (gsl-vector-view) @@ -166,7 +165,7 @@ elements.") ;;;;**************************************************************************** #| -(with-data (vector vec 3) +(with-data (vec vector 3) (setf (gsl-aref vec 0) -3.21d0 (gsl-aref vec 1) 1.0d0 (gsl-aref vec 2) 12.8d0) @@ -174,7 +173,7 @@ elements.") (print (gsl-aref vec 1)) (print (gsl-aref vec 0))) -(with-data (vector vec 3) +(with-data (vec vector 3) (set-all vec 77.8d0) (print (gsl-aref vec 2)) (print (gsl-aref vec 1)) @@ -184,12 +183,12 @@ elements.") (print (gsl-aref vec 1)) (print (gsl-aref vec 0))) -(with-data (vector vec 3) (set-basis vec 1) +(with-data (vec vector 3) (set-basis vec 1) (format t "~&~a ~a ~a" (gsl-aref vec 0) (gsl-aref vec 1) (gsl-aref vec 2))) ;;; broken -(with-data (vector vec 3) +(with-data (vec vector 3) (setf (gsl-aref vec 0) -3.21d0 (gsl-aref vec 1) 1.0d0 (gsl-aref vec 2) 12.8d0) @@ -197,13 +196,26 @@ elements.") (DEFUN SUBVECTOR (VECTOR OFFSET SIZE) (FOREIGN-FUNCALL "gsl_vector_subvector" - GSL-VECTOR-c - (POINTER VECTOR) - :SIZE - OFFSET - :SIZE - SIZE - GSL-VECTOR-VIEW)) + :pointer + (POINTER VECTOR) + :SIZE + OFFSET + :SIZE + SIZE + GSL-VECTOR-VIEW)) + +(with-data (vec vector 3) + (setf (gsl-aref vec 0) -3.21d0 + (gsl-aref vec 1) 1.0d0 + (gsl-aref vec 2) 12.8d0) + (FOREIGN-FUNCALL "gsl_vector_subvector" + :pointer + (POINTER VEC) + :SIZE + 1 + :SIZE + 2 + GSL-VECTOR-VIEW)) |# -- GitLab