From: Akshay S. <ak...@us...> - 2012-03-20 06:47:12
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "matlisp". The branch, matlisp-cffi has been updated via fd41f88aefad9d87a8c9183f946ac14c3b564de8 (commit) via eee93ce6980e4a07c4f7d3ccb4604666691c529d (commit) from 83c3111d290cc5994b05dcc32e2ee51cb1529f1a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit fd41f88aefad9d87a8c9183f946ac14c3b564de8 Author: Akshay Srinivasan <aks...@gm...> Date: Tue Mar 20 12:11:57 2012 +0530 -> Changed standard-matrix class defaults. diff --git a/src/standard-matrix.lisp b/src/standard-matrix.lisp index 1d168e9..4c918b8 100644 --- a/src/standard-matrix.lisp +++ b/src/standard-matrix.lisp @@ -3,6 +3,12 @@ ;; (declaim (inline allocate-integer4-store)) + +(eval-when (load eval compile) + (deftype integer4-matrix-element-type () + '(signed-byte 32)) + ) + (defun allocate-integer4-store (size &optional (initial-element 0)) "(ALLOCATE-INTEGER-STORE SIZE [INITIAL-ELEMENT]). Allocates integer storage. Default INITIAL-ELEMENT = 0." @@ -73,25 +79,26 @@ that way.")) (let* ((n (nrows matrix)) (m (ncols matrix)) (h (head matrix)) - (rs (row-stride matrix)) - (cs (col-stride matrix)) (ss (store-size matrix)) (nxm (* n m))) - (declare (type fixnum n m h rs cs nxm)) - ;;Error checking is good if we use foreign-pointers as store types. - (cond - ((<= n 0) (error "Number of rows must be > 0. Initialized with ~A." n)) - ((<= m 0) (error "Number of columns must be > 0. Initialized with ~A." m)) - ;; - ((< h 0) (error "Head of the store must be >= 0. Initialized with ~A." h)) - ((< rs 0) (error "Row-stride of the store must be > 0. Initialized with ~A." rs)) - ((< cs 0) (error "Column-stride of the store must be > 0. Initialized with ~A." cs)) - ((<= ss 0) (error "Store-size must be > 0. Initialized with ~A." ss))) + (declare (type fixnum n m h nxm)) ;;Row-ordered by default. - (when (or (= rs 0) (= cs 0)) + (unless (and (slot-boundp matrix 'row-stride) (slot-boundp matrix 'col-stride)) (setf (row-stride matrix) m) (setf (col-stride matrix) 1)) - + (let ((rs (row-stride matrix)) + (cs (row-stride matrix))) + (declare (type fixnum rs cs)) + ;;Error checking is good if we use foreign-pointers as store types. + (cond + ((<= n 0) (error "Number of rows must be > 0. Initialized with ~A." n)) + ((<= m 0) (error "Number of columns must be > 0. Initialized with ~A." m)) + ;; + ((< h 0) (error "Head of the store must be >= 0. Initialized with ~A." h)) + ((< rs 0) (error "Row-stride of the store must be >= 0. Initialized with ~A." rs)) + ((< cs 0) (error "Column-stride of the store must be >= 0. Initialized with ~A." cs)) + ((<= ss 0) (error "Store-size must be > 0. Initialized with ~A." ss)))) + ;; (setf (number-of-elements matrix) nxm))) ;; commit eee93ce6980e4a07c4f7d3ccb4604666691c529d Author: Akshay Srinivasan <aks...@gm...> Date: Tue Mar 20 11:40:32 2012 +0530 -> Modified def-fortran-routine to handle things like: (def-fortran-routine ("daxpy_" daxpy) ..) This will help when adding foreign interfaces to C functions. diff --git a/src/ffi-cffi.lisp b/src/ffi-cffi.lisp index dc72abd..b1d8bcc 100644 --- a/src/ffi-cffi.lisp +++ b/src/ffi-cffi.lisp @@ -213,40 +213,40 @@ Example: ;; Call defcfun to define the foreign function. ;; Also creates a nice lisp helper function. -(defmacro def-fortran-routine (name return-type &rest body) - (let ((fortran-name (make-fortran-name `,name)) - (lisp-name (make-fortran-ffi-name `,name)) - (hack-return-type `,return-type) - (hack-body `(,@body)) - (hidden-var-name nil)) - - (multiple-value-bind (doc pars) - (parse-doc-&-parameters `(,@body)) - (when (member hack-return-type '(:complex-single-float :complex-double-float)) - ;; The return type is complex. Since this is a "structure", - ;; Fortran inserts a "hidden" first parameter before all - ;; others. This is used to store the resulting complex - ;; number. Then there is no "return" value, so set the return - ;; type to :void. - ;; - (setq hidden-var-name (gensym "HIDDEN-COMPLEX-RETURN-")) - (setq hack-body `(,@doc - (,hidden-var-name ,hack-return-type :output) - ,@pars)) - (setq hack-return-type :void))) - - `(eval-when (load eval compile) - (progn - - ;; Removing 'inlines' It seems that CMUCL has a problem with - ;; inlines of FFI's when a lisp image is saved. Until the - ;; matter is clarified we leave out 'inline's - - ;(declaim (inline ,lisp-name)) ;sbcl 0.8.5 has problems with - ;inlining - (cffi:defcfun (,fortran-name ,lisp-name) ,@(get-return-type hack-return-type) - ,@(parse-fortran-parameters hack-body)) - ,@(def-fortran-interface name hack-return-type hack-body hidden-var-name))))) +(defmacro def-fortran-routine (func-name return-type &rest body) + (multiple-value-bind (name fortran-name) (if (listp func-name) + (values (cadr func-name) (car func-name)) + (values func-name (make-fortran-name func-name))) + (let* ((lisp-name (make-fortran-ffi-name `,name)) + (hack-return-type `,return-type) + (hack-body `(,@body)) + (hidden-var-name nil)) + + (multiple-value-bind (doc pars) + (parse-doc-&-parameters `(,@body)) + (when (member hack-return-type '(:complex-single-float :complex-double-float)) + ;; The return type is complex. Since this is a "structure", + ;; Fortran inserts a "hidden" first parameter before all + ;; others. This is used to store the resulting complex + ;; number. Then there is no "return" value, so set the return + ;; type to :void. + ;; + (setq hidden-var-name (gensym "HIDDEN-COMPLEX-RETURN-")) + (setq hack-body `(,@doc + (,hidden-var-name ,hack-return-type :output) + ,@pars)) + (setq hack-return-type :void))) + + `(eval-when (load eval compile) + (progn + ;; Removing 'inlines' It seems that CMUCL has a problem with + ;; inlines of FFI's when a lisp image is saved. Until the + ;; matter is clarified we leave out 'inline's + + ;; (declaim (inline ,lisp-name)) ;sbcl 0.8.5 has problems with + (cffi:defcfun (,fortran-name ,lisp-name) ,@(get-return-type hack-return-type) + ,@(parse-fortran-parameters hack-body)) + ,@(def-fortran-interface name hack-return-type hack-body hidden-var-name)))))) ;; Create a form specifying a simple Lisp function that calls the ;; underlying Fortran routine of the same name. ----------------------------------------------------------------------- Summary of changes: src/ffi-cffi.lisp | 66 +++++++++++++++++++++++----------------------- src/standard-matrix.lisp | 35 ++++++++++++++---------- 2 files changed, 54 insertions(+), 47 deletions(-) hooks/post-receive -- matlisp |