[lisplab-cvs] r112 - src/core src/matrix
Jørn Inge Vestgården
jivestgarden at common-lisp.net
Sat Nov 14 19:58:39 UTC 2009
Author: jivestgarden
Date: Sat Nov 14 14:58:38 2009
New Revision: 112
Log:
cleaned up more
Modified:
package.lisp
src/core/level0-default.lisp
src/core/level0-functions.lisp
src/core/level0-interface.lisp
src/matrix/level2-function.lisp
src/matrix/level2-matrix-dge.lisp
src/matrix/level2-matrix-zge.lisp
src/matrix/level2-operator.lisp
Modified: package.lisp
==============================================================================
--- package.lisp (original)
+++ package.lisp Sat Nov 14 14:58:38 2009
@@ -74,8 +74,10 @@
".MAX"
".MIN"
".ABS"
- ".IMAGPART"
- ".REALPART"
+ ".IM"
+ ".RE"
+ ".CONJ"
+ ".COMPLEX"
".="
"./="
".<"
@@ -87,7 +89,8 @@
".DIV"
".SUB"
".EXPT"
- ".CONJ"
+
+ ;; Elementary functions
".SIN"
".COS"
".TAN"
@@ -101,9 +104,12 @@
".ACOSH"
".ATANH"
".LOG"
+ ".LN"
".EXP"
".SQR"
".SQRT"
+
+ ;; Special functions
".AI"
".BESJ"
".BESY"
Modified: src/core/level0-default.lisp
==============================================================================
--- src/core/level0-default.lisp (original)
+++ src/core/level0-default.lisp Sat Nov 14 14:58:38 2009
@@ -58,10 +58,10 @@
:z)
-(defmethod function-output-type-spec ((fun (eql '.realpart)) (input-spec (eql :z)))
+(defmethod function-output-type-spec ((fun (eql '.re)) (input-spec (eql :z)))
:d)
-(defmethod function-output-type-spec ((fun (eql '.imagpart)) (input-spec (eql :z)))
+(defmethod function-output-type-spec ((fun (eql '.im)) (input-spec (eql :z)))
:d)
(defmethod function-output-type-spec ((fun (eql '.abs)) (input-spec (eql :z)))
Modified: src/core/level0-functions.lisp
==============================================================================
--- src/core/level0-functions.lisp (original)
+++ src/core/level0-functions.lisp Sat Nov 14 14:58:38 2009
@@ -65,12 +65,15 @@
(defmethod .abs ((a number))
(abs a))
-(defmethod .realpart ((a number))
+(defmethod .re ((a number))
(realpart a))
-(defmethod .imagpart ((a number))
+(defmethod .im ((a number))
(imagpart a))
+(defmethod .complex ((a number) (b number))
+ (complex a b))
+
(defmethod .max ((a number) (b number))
(max a b))
@@ -123,7 +126,7 @@
(.asinh . asinh) (.acosh . acosh) (.atanh . atanh)
(.exp . exp) (.ln . log)
(.sqrt . sqrt) (.sqr . sqr)
- (.realpart . realpart)(.imagpart . imagpart) (.abs . abs)
+ (.re . realpart)(.im . imagpart) (.abs . abs)
(.conj . conjugate)))
(defmacro expand-num-num ()
Modified: src/core/level0-interface.lisp
==============================================================================
--- src/core/level0-interface.lisp (original)
+++ src/core/level0-interface.lisp Sat Nov 14 14:58:38 2009
@@ -63,15 +63,18 @@
(defgeneric .abs (a)
(:documentation "Generialized abs."))
-(defgeneric .realpart (a)
+(defgeneric .re (a)
(:documentation "Generialized realpart."))
-(defgeneric .imagpart (a)
+(defgeneric .im (a)
(:documentation "Generialized abs."))
(defgeneric .conj (a)
(:documentation "Generalized conjugate."))
+(defgeneric .complex (a b)
+ (:documentation "Generalized complex."))
+
;;; Binary boolean operators
(defgeneric .= (a b &optional (accuracy))
Modified: src/matrix/level2-function.lisp
==============================================================================
--- src/matrix/level2-function.lisp (original)
+++ src/matrix/level2-function.lisp Sat Nov 14 14:58:38 2009
@@ -31,7 +31,7 @@
.asin .acos .atan
.sinh .cosh .tanh
.asinh .acosh .atanh
- .realpart .imagpart .abs
+ .re .im .abs
.exp .ln .sqr .sqrt .conj ))
(defmacro expand-each-element-ordinary-functions ()
Modified: src/matrix/level2-matrix-dge.lisp
==============================================================================
--- src/matrix/level2-matrix-dge.lisp (original)
+++ src/matrix/level2-matrix-dge.lisp Sat Nov 14 14:58:38 2009
@@ -164,7 +164,7 @@
(.sinh . sinh_dfa) (.cosh . cosh_dfa) (.tanh . tanh_dfa)
(.asinh . asinh_dfa) (.acosh . acosh_dfa)
(.exp . exp_dfa) (.ln . log_dfa) (.sqrt . sqrt_dfat) (.conjugate . conjugate_dfa)
- (.realpart . realpart_dfa) (.imagpart . imagpart_dfa) (.abs . abs_dfa)))
+ (.re . realpart_dfa) (.im . imagpart_dfa) (.abs . abs_dfa)))
(defmacro defmethod-dfa-to-dfa (name underlying-function)
(let ((a (gensym "a"))
Modified: src/matrix/level2-matrix-zge.lisp
==============================================================================
--- src/matrix/level2-matrix-zge.lisp (original)
+++ src/matrix/level2-matrix-zge.lisp Sat Nov 14 14:58:38 2009
@@ -1,7 +1,6 @@
;;; Lisplab, level2-matrix-zge.lisp
;;; Optimizations for complex matrices.
-
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
@@ -148,6 +147,39 @@
(expand-generic-function-cdfa-cdfa-map)
+;;;; The cross terms, where one input is real, the other complex
+
+(defmacro def-cross-complex-real-method (name type1 type2)
+ ;; Assumes output type same as input
+ ;; Note will crash if input is not converted properly!!!!!!
+ (let ((a (gensym))
+ (b (gensym))
+ (spec (gensym)))
+ `(defmethod ,name ((,a ,type1) (,b ,type2))
+ ;; This is not the fastest possible, but rather fast
+ (let ((,spec (operator-output-type-spec ',name
+ (type-spec ,a)
+ (type-spec ,b))))
+ ;; Assumes that input is something with a well-defined spec
+ (,name (if (matrix? ,a) (convert ,a ,spec) ,a)
+ (if (matrix? ,b) (convert ,b ,spec) ,b))))))
+
+(defmacro def-all-cross-complex-real-methods (name)
+ `(progn
+ (def-cross-complex-real-method ,name complex matrix-base-dge)
+ (def-cross-complex-real-method ,name matrix-base-dge complex)
+ (def-cross-complex-real-method ,name matrix-base-zge matrix-base-dge)
+ (def-cross-complex-real-method ,name matrix-base-dge matrix-base-zge)
+ 'done))
+
+(def-all-cross-complex-real-methods .add)
+(def-all-cross-complex-real-methods .sub)
+(def-all-cross-complex-real-methods .mul)
+(def-all-cross-complex-real-methods .div)
+(def-all-cross-complex-real-methods .expt)
+
+
+
;;;; Ordinary functions
(define-constant +generic-function-cdfa-to-cdfa-map+ ;really bad name
@@ -173,19 +205,19 @@
(expand-generic-function-cdfa-to-cdfa-map)
-;;;; Exceptions
+;;;; Exceptions, in that output is real for complex input
-(defmethod .imagpart ((a matrix-base-zge))
+(defmethod .im ((a matrix-base-zge))
(let ((out (make-matrix-instance
- (function-output-type-spec '.imagpart (type-spec a))
+ (function-output-type-spec '.im (type-spec a))
(dim a)
0)))
(imagpart_cdfa (matrix-store a) (matrix-store out))
out))
-(defmethod .realpart ((a matrix-base-zge))
+(defmethod .re ((a matrix-base-zge))
(let ((out (make-matrix-instance
- (function-output-type-spec '.realpart (type-spec a))
+ (function-output-type-spec '.re (type-spec a))
(dim a)
0)))
(realpart_cdfa (matrix-store a) (matrix-store out))
Modified: src/matrix/level2-operator.lisp
==============================================================================
--- src/matrix/level2-operator.lisp (original)
+++ src/matrix/level2-operator.lisp Sat Nov 14 14:58:38 2009
@@ -19,6 +19,13 @@
(in-package :lisplab)
+(defmethod .complex ((a matrix-base) (b matrix-base))
+ (.+ a (.* %i b)))
+(defmethod .complex ((a matrix-base) b)
+ (.+ a (.* %i b)))
+(defmethod .complex (a (b matrix-base))
+ (.+ a (.* %i b)))
+
;;;; Basic boolean operators
(defmethod .= ((a matrix-base) (b matrix-base) &optional acc)
More information about the lisplab-cvs
mailing list