From: Akshay S. <ak...@us...> - 2012-04-20 18:39:45
|
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 40f4fcf5947519a52340322a27aeaeca4275fd29 (commit) from 20c39c7a913544c3f542fd338568aec439fbd838 (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 40f4fcf5947519a52340322a27aeaeca4275fd29 Author: Akshay Srinivasan <aks...@gm...> Date: Sat Apr 21 00:04:53 2012 +0530 Added apy! for scalar, matrix addition. Uses {d, z}axpy underneath to do this with a 0 strided vector. diff --git a/packages.lisp b/packages.lisp index 94f67e0..c79b02d 100644 --- a/packages.lisp +++ b/packages.lisp @@ -304,6 +304,7 @@ (:export #:*print-matrix* ;;Level 1 BLAS #:axpy! #:axpy + #:apy! #:apy #:copy! #:copy #:scal! #:scal ;;Level 2 BLAS diff --git a/src/axpy.lisp b/src/axpy.lisp index 0891c60..097d7f3 100644 --- a/src/axpy.lisp +++ b/src/axpy.lisp @@ -72,7 +72,7 @@ ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(in-package "MATLISP") +(in-package #:matlisp) (defmacro generate-typed-axpy!-func (func element-type store-type matrix-type blas-func) `(defun ,func (alpha mat-a mat-b) @@ -98,6 +98,33 @@ do (,blas-func nc-a alpha st-a cs-a st-b cs-b :head-x (+ hd-a (* i rs-a)) :head-y (+ hd-b (* i rs-b))))))) mat-b)) +(defmacro generate-typed-apy!-func (func + element-type store-type matrix-type + blas-func id-decl) + ;;Be very careful when using functions generated by this macro. + ;;Indexes can be tricky and this has no safety net + ;;(you don't see a matrix-ref do you ?) + ;;Use only after checking the arguments for compatibility. + (destructuring-bind (id-maker id-type) id-decl + `(mlet* ((id (,@id-maker) :type ,id-type)) + (defun ,func (alpha mat-b) + (declare (type ,element-type alpha) + (type ,matrix-type mat-b) + (optimize (safety 0) (speed 3))) + (mlet* (((cp-b inc-b sz-b) (blas-copyable-p mat-b) :type (boolean fixnum fixnum)) + ((hd-b st-b) (slot-values mat-b '(head store)) :type (fixnum (,store-type *)))) + (if cp-b + (,blas-func sz-b alpha id 0 st-b inc-b :head-y hd-b) + (mlet* (((nr-b nc-b rs-b cs-b) (slot-values mat-b '(number-of-rows number-of-cols row-stride col-stride)) + :type (fixnum fixnum fixnum fixnum))) + ;;Choose the smaller of the loops + (when (> nr-b nc-b) + (rotatef nr-b nc-b) + (rotatef rs-b cs-b)) + (loop for i from 0 below nr-b + do (,blas-func nc-b alpha id 0 st-b cs-b :head-y (+ hd-b (* i rs-b))))))) + mat-b)))) + ;; (defgeneric axpy! (alpha x y) (:documentation @@ -121,7 +148,9 @@ (error "Arguments X,Y to AXPY! are of different dimensions.")))) ;; -(generate-typed-axpy!-func real-double-axpy!-typed double-float real-matrix-store-type real-matrix blas:daxpy) +(generate-typed-axpy!-func real-double-axpy!-typed + double-float real-matrix-store-type real-matrix + blas:daxpy) (defmethod axpy! ((alpha number) (x complex-matrix) (y real-matrix)) (error "cannot AXPY! a complex X to a real Y, @@ -131,7 +160,9 @@ don't know how to coerce COMPLEX to REAL")) (real-double-axpy!-typed (coerce alpha 'double-float) x y)) ;; -(generate-typed-axpy!-func complex-double-axpy!-typed complex-double-float complex-matrix-store-type complex-matrix blas:zaxpy) +(generate-typed-axpy!-func complex-double-axpy!-typed + complex-double-float complex-matrix-store-type complex-matrix + blas:zaxpy) (defmethod axpy! ((alpha cl:real) (x real-matrix) (y complex-matrix)) (real-double-axpy!-typed (coerce alpha 'double-float) x (mrealpart~ y))) @@ -198,4 +229,77 @@ don't know how to coerce COMPLEX to REAL")) (defmethod axpy ((alpha number) (x complex-matrix) (y complex-matrix)) (let ((result (copy y))) - (axpy! alpha x result))) \ No newline at end of file + (axpy! alpha x result))) + +;;;; +(defgeneric apy! (alpha y) + (:documentation + " + Syntax + ====== + (APY! alpha y) + + Y <- alpha + y + + Purpose + ======= + Same as APY except that the result + is stored in Y and Y is returned. + +")) + +(generate-typed-apy!-func real-double-apy!-typed + double-float real-matrix-store-type real-matrix + blas:daxpy + ((let ((ret (allocate-real-store 1))) + (setf (aref ret 0) 1d0) + ret) + (real-matrix-store-type 1))) + +(defmethod apy! ((alpha cl:real) (y real-matrix)) + (real-double-apy!-typed (coerce alpha 'double-float) y)) + +;; + +(generate-typed-apy!-func complex-double-apy!-typed + complex-double-float complex-matrix-store-type complex-matrix + blas:zaxpy + ((let ((ret (allocate-complex-store 1))) + (setf (aref ret 0) 1d0 + (aref ret 1) 0d0) + ret) + (complex-matrix-store-type 2))) + +(defmethod apy! ((alpha number) (y complex-matrix)) + ;;Should this be split to handle real,complex alpha + ;;by making use of real-double-apy!-typed + (complex-double-apy!-typed (complex-coerce alpha) y)) + +;; + +(defgeneric apy (alpha y) + (:documentation + " + Syntax + ====== + (APY! alpha y) + + Y <- alpha + y + + Purpose + ======= + Computes + + ALPHA + Y + + where ALPHA is a scalar and Y is a + matrix. + + The result is stored in a new matrix + that has the same dimensions as Y. + +")) + +(defmethod apy ((alpha number) (y standard-matrix)) + (let ((ret (copy y))) + (apy! alpha y))) \ No newline at end of file diff --git a/src/copy.lisp b/src/copy.lisp index aa3cbda..8389e3c 100644 --- a/src/copy.lisp +++ b/src/copy.lisp @@ -76,7 +76,7 @@ ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(in-package "MATLISP") +(in-package #:matlisp) ;; (defmacro generate-typed-copy!-func (func store-type matrix-type blas-func) ----------------------------------------------------------------------- Summary of changes: packages.lisp | 1 + src/axpy.lisp | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/copy.lisp | 2 +- 3 files changed, 110 insertions(+), 5 deletions(-) hooks/post-receive -- matlisp |