[lisplab-cvs] r39 - in src: core linalg matrix
Jørn Inge Vestgården
jivestgarden at common-lisp.net
Sat May 23 09:46:26 UTC 2009
Author: jivestgarden
Date: Sat May 23 05:46:23 2009
New Revision: 39
Log:
added new matrix types
Modified:
src/core/level0-functions.lisp
src/core/level0-interface.lisp
src/linalg/level3-linalg-blas-real.lisp
src/linalg/level3-linalg-generic.lisp
src/linalg/level3-linalg-interface.lisp
src/matrix/level1-classes.lisp
src/matrix/level1-constructors.lisp
src/matrix/level1-matrix.lisp
src/matrix/level2-generic.lisp
src/matrix/level2-matrix-dge.lisp
Modified: src/core/level0-functions.lisp
==============================================================================
--- src/core/level0-functions.lisp (original)
+++ src/core/level0-functions.lisp Sat May 23 05:46:23 2009
@@ -27,6 +27,9 @@
(defmethod .imagpart ((a number))
(imagpart a))
+(defmethod .conj ((a number))
+ (conjugate a))
+
(defmethod .= ((a number) (b number) &optional (accuracy))
(if accuracy
(< (abs (- a b)) accuracy)
Modified: src/core/level0-interface.lisp
==============================================================================
--- src/core/level0-interface.lisp (original)
+++ src/core/level0-interface.lisp Sat May 23 05:46:23 2009
@@ -31,6 +31,7 @@
.sub .sub!
.expt .expt!
+ .conj
.sin .cos .tan
.sinh .cosh .tanh
.log .exp
@@ -56,13 +57,16 @@
(:documentation "Generalized coerce."))
(defgeneric .abs (a)
- (:documentation "Generialized abs"))
+ (:documentation "Generialized abs."))
(defgeneric .realpart (a)
- (:documentation "Generialized realpart"))
+ (:documentation "Generialized realpart."))
(defgeneric .imagpart (a)
- (:documentation "Generialized abs"))
+ (:documentation "Generialized abs."))
+
+(defgeneric .conj (a)
+ (:documentation "Generalized conjugate."))
;;; Binary boolean operators
Modified: src/linalg/level3-linalg-blas-real.lisp
==============================================================================
--- src/linalg/level3-linalg-blas-real.lisp (original)
+++ src/linalg/level3-linalg-blas-real.lisp Sat May 23 05:46:23 2009
@@ -32,9 +32,6 @@
(setf (mref b i j) (mref a j i))))
b))
-(defmethod mconj ((a matrix-lisp-dge))
- (copy a))
-
(defmethod mct ((a matrix-lisp-dge))
(mtp a))
Modified: src/linalg/level3-linalg-generic.lisp
==============================================================================
--- src/linalg/level3-linalg-generic.lisp (original)
+++ src/linalg/level3-linalg-generic.lisp Sat May 23 05:46:23 2009
@@ -35,13 +35,6 @@
(setf (mref b i j) (mref a j i))))
b))
-(defmethod mconj ((a matrix-base))
- ;; TODO this should be .conj and be level0
- (let ((b (mcreate a #C(0 0) (list (rows a) (cols a)) )))
- (dotimes (i (size b))
- (setf (vref b i) (conjugate (vref a i))))
- b))
-
(defmethod mct ((a matrix-base))
(mconj (mtp a)))
Modified: src/linalg/level3-linalg-interface.lisp
==============================================================================
--- src/linalg/level3-linalg-interface.lisp (original)
+++ src/linalg/level3-linalg-interface.lisp Sat May 23 05:46:23 2009
@@ -19,7 +19,7 @@
(in-package :lisplab)
-(export '(mtp mtp! mconj mconj! mct mct!
+(export '(mtp mtp! mct mct!
mtr mdet minv! minv
m* m*! m/ m/!
LU-factor LU-factor!
@@ -33,12 +33,6 @@
(defgeneric mtp! (matrix)
(:documentation "Matrix transpose. Destructive."))
-(defgeneric mconj (matrix)
- (:documentation "Matrix conjugate."))
-
-(defgeneric mconj! (matrix)
- (:documentation "Matrix conjugate. Destructive."))
-
(defgeneric mct (matrix)
(:documentation "Matrix conjugate transpose."))
Modified: src/matrix/level1-classes.lisp
==============================================================================
--- src/matrix/level1-classes.lisp (original)
+++ src/matrix/level1-classes.lisp Sat May 23 05:46:23 2009
@@ -42,13 +42,31 @@
:initform t
:reader element-type)))
-(defclass matrix-element-complex-double-float (matrix-element-base)
+(defclass matrix-element-number (matrix-element-base)
+ ((element-type
+ :allocation :class
+ :initform 'number
+ :reader element-type)))
+
+(defclass matrix-element-complex (matrix-element-number)
+ ((element-type
+ :allocation :class
+ :initform 'complex
+ :reader element-type)))
+
+(defclass matrix-element-complex-double-float (matrix-element-complex)
((element-type
:allocation :class
:initform '(complex double-float)
:reader element-type)))
-(defclass matrix-element-double-float (matrix-element-complex-double-float)
+(defclass matrix-element-real (matrix-element-number)
+ ((element-type
+ :allocation :class
+ :initform 'real
+ :reader element-type)))
+
+(defclass matrix-element-double-float (matrix-element-real)
((element-type
:allocation :class
:initform 'double-float
@@ -88,9 +106,22 @@
:accessor size
:type type-blas-idx)))
-
;;; The actual classes ment for instantiation
+(defclass matrix-ge
+ (matrix-structure-general matrix-element-base matrix-implementation-lisp)
+ ((matrix-store
+ :initarg :store
+ :initform nil
+ :reader matrix-store
+ :type (array t (*))))
+ (:documentation "A full matrix (rows x cols) with unspecified matrix element types."))
+
+(defmethod initialize-instance :after ((m matrix-ge) &key (value 0))
+ (with-slots (rows cols size matrix-store) m
+ (setf size (* rows cols))
+ (unless matrix-store
+ (setf matrix-store (make-array size :initial-element value)))))
;;; Double float general matrices
@@ -108,12 +139,17 @@
(unless matrix-store
(setf matrix-store (allocate-real-store size value)))))
-(defclass matrix-lisp-dge (matrix-implementation-lisp matrix-base-dge) ())
-
-(defclass matrix-blas-dge (matrix-implementation-blas matrix-lisp-dge) ())
+(defclass matrix-lisp-dge (matrix-implementation-lisp matrix-base-dge) ()
+ (:documentation "A full matrix (rows x cols) with double float elements.
+Executes in lisp only."))
+
+(defclass matrix-blas-dge (matrix-implementation-blas matrix-lisp-dge) ()
+ (:documentation "A full matrix (rows x cols) with double float elements.
+Executes in alien blas/lapack only."))
(defclass matrix-dge (matrix-blas-dge) ()
- (:documentation "General matrix with double float elements."))
+ (:documentation "A full matrix (rows x cols) with double float matrix elements.
+Executes first in alien blas/lapack if possible. If not it executes in lisp."))
;;; Complex double float general matrices
@@ -131,12 +167,17 @@
(unless matrix-store
(setf matrix-store (allocate-complex-store size value)))))
-(defclass matrix-lisp-zge (matrix-implementation-lisp matrix-base-zge) ())
-
-(defclass matrix-blas-zge (matrix-implementation-blas matrix-lisp-zge) ())
+(defclass matrix-lisp-zge (matrix-implementation-lisp matrix-base-zge) ()
+ (:documentation "A full matrix (rows x cols) with complex double float elements.
+Executes in lisp only."))
+
+(defclass matrix-blas-zge (matrix-implementation-blas matrix-lisp-zge) ()
+ (:documentation "A full matrix (rows x cols) with complex double float elements.
+Executes in alien blas/lapack only."))
(defclass matrix-zge (matrix-blas-zge) ()
- (:documentation "General matrix with complex double float elements."))
+ (:documentation "A full matrix (rows x cols) with complex double float matrix elements.
+Executes first in alien blas/lapack if possible. If not it executes in lisp."))
;;; Double float diagonal matrices
Modified: src/matrix/level1-constructors.lisp
==============================================================================
--- src/matrix/level1-constructors.lisp (original)
+++ src/matrix/level1-constructors.lisp Sat May 23 05:46:23 2009
@@ -61,6 +61,8 @@
;;; Adding all the matrix descriptions
+(add-matrix-class 'matrix-ge :any :ge :lisp)
+
(add-matrix-class 'matrix-base-dge :d :ge :base)
(add-matrix-class 'matrix-lisp-dge :d :ge :lisp)
(add-matrix-class 'matrix-blas-dge :d :ge :blas)
Modified: src/matrix/level1-matrix.lisp
==============================================================================
--- src/matrix/level1-matrix.lisp (original)
+++ src/matrix/level1-matrix.lisp Sat May 23 05:46:23 2009
@@ -61,7 +61,22 @@
(defmethod make-matrix-instance ((description list) dim value)
(make-matrix-instance (find-matrix-class description) dim value))
-
+
+;;; The general matrix
+
+(defmethod mref ((matrix matrix-ge) row col)
+ (aref (matrix-store matrix) (column-major-idx row col (rows matrix))))
+
+(defmethod (setf mref) (value (matrix matrix-ge) row col)
+ (setf (aref (matrix-store matrix) (column-major-idx row col (rows matrix)))
+ value))
+
+(defmethod vref ((matrix matrix-ge) idx)
+ (aref (matrix-store matrix) idx))
+
+(defmethod (setf vref) (value (matrix matrix-ge) idx)
+ (setf (aref (matrix-store matrix) idx)
+ value))
;;; Spcialized for blas-dge
Modified: src/matrix/level2-generic.lisp
==============================================================================
--- src/matrix/level2-generic.lisp (original)
+++ src/matrix/level2-generic.lisp Sat May 23 05:46:23 2009
@@ -24,6 +24,14 @@
(in-package :lisplab)
+(defmethod .conj ((a matrix-element-complex-double-float))
+ (let ((b (mcreate a)))
+ (dotimes (i (size b))
+ (setf (vref b i) (conjugate (vref a i))))
+ b))
+
+
+
;; Helper function.
#+nil (defun convert-list-to-matrix (list type)
(let* ((rows (length list))
Modified: src/matrix/level2-matrix-dge.lisp
==============================================================================
--- src/matrix/level2-matrix-dge.lisp (original)
+++ src/matrix/level2-matrix-dge.lisp Sat May 23 05:46:23 2009
@@ -51,6 +51,9 @@
(copy-contents a b #'abs)
b))
+(defmethod .conj ((a matrix-lisp-dge))
+ (copy a))
+
(defmethod .some (pred (a matrix-lisp-dge) &rest args)
(let ((stores (mapcar #'matrix-store (cons a args))))
(apply #'some pred stores)))
More information about the lisplab-cvs
mailing list