[lisplab-cvs] r30 - src/matrix

Jørn Inge Vestgården jivestgarden at common-lisp.net
Thu May 21 14:18:39 UTC 2009


Author: jivestgarden
Date: Thu May 21 10:18:38 2009
New Revision: 30

Log:
Cleaned up further

Modified:
   src/matrix/level2-constructors.lisp
   src/matrix/level2-generic.lisp
   src/matrix/level2-interface.lisp

Modified: src/matrix/level2-constructors.lisp
==============================================================================
--- src/matrix/level2-constructors.lisp	(original)
+++ src/matrix/level2-constructors.lisp	Thu May 21 10:18:38 2009
@@ -25,23 +25,6 @@
 	  dmat dnew dcol drow
 	  zmat znew zcol zrow))
 
-;; Helper function.       
-(defun convert-list-to-matrix (list type)
-  (let* ((rows (length list))
-	 (cols (length (car list)))
-	 (m (make-matrix-instance type (list rows cols) 0)))
-    (fill-matrix-with-list m list))) 
-
-;; Helper function.
-(defun convert-matrix-to-matrix (m0 type)
-  (let* ((rows (rows m0))
-	 (cols (cols m0))
-	 (m (make-matrix-instance type (dim m0) 0)))
-    (dotimes (i rows)
-      (dotimes (j cols)
-	(setf (mref m i j) (mref m0 i j))))
-    m))
-
 (defmethod mcreate ((a matrix-base) &optional (value 0) dim)
   (unless dim
     (setf dim (dim a)))
@@ -56,31 +39,20 @@
       (make-matrix-instance 'matrix-zge dim value)     
       (make-matrix-instance 'matrix-dge dim value)))
 
-;; Should this be specialized to subclasses of matrix-base?
-;; This question also holds for other methds in this file
-(defmethod convert (x type)
+(defmethod convert ((x matrix-base) type)
   (let ((y (make-matrix-instance type (dim x) 0)))
-    ;; Note that I cannot use vref, since some matrix implmentations 
-    ;; have different ordering.
-    (dotimes (i (rows x))
-      (dotimes (j (cols x))
-	(setf (mref y i j) (mref x i j))))
+    (copy-contents x y)
     y))
 
 (defmethod convert ((x cons) type)
+  ;; Should it be moved to some other file?
   ;; TODO some better way ... some more general guessing routine 
   ;; like guess-best-element-type
   (if (consp (car x))
       (let* ((cols (length (car x)))
 	     (rows (length x))
 	     (m (make-matrix-instance type (list rows cols) 0)))
-	(do ((xx x (cdr xx))
-	     (i 0 (1+ i)))
-	    ((= i rows))
-	  (do ((yy (car xx) (cdr yy))
-	       (j 0 (1+ j)))
-	      ((= j cols))
-	    (setf (mref m i j) (car yy))))
+	(fill-matrix-with-list m x)
 	m)
       ;; else make a row vector
       (convert (list x) type))) 

Modified: src/matrix/level2-generic.lisp
==============================================================================
--- src/matrix/level2-generic.lisp	(original)
+++ src/matrix/level2-generic.lisp	Thu May 21 10:18:38 2009
@@ -24,6 +24,27 @@
 
 (in-package :lisplab) 
 
+;; Helper function.       
+#+nil (defun convert-list-to-matrix (list type)
+  (let* ((rows (length list))
+	 (cols (length (car list)))
+	 (m (make-matrix-instance type (list rows cols) 0)))
+    (fill-matrix-with-list m list))) 
+
+;; Helper function.
+#+nil (defun convert-matrix-to-matrix (m0 type)
+  (let* ((rows (rows m0))
+	 (cols (cols m0))
+	 (m (make-matrix-instance type (dim m0) 0)))
+    (dotimes (i rows)
+      (dotimes (j cols)
+	(setf (mref m i j) (mref m0 i j))))
+    m))
+
+(defmethod square-matrix? ((x matrix-base))
+  (= (rows x) (cols x)))
+
+
 ;;; This is OK, but could be optimzied!
 (defmacro w/mat (a args &body body)
   (let ((a2 (gensym))
@@ -75,9 +96,6 @@
 (defmethod .map (f (a matrix-base) &rest args)
   (apply #'mmap (class-name (class-of a)) f a args))
 
-(defmethod square-matrix? ((x matrix-base))
-  (= (rows x) (cols x)))
-
 #+todo-remove (defmethod diag (v)
   (let* ((n (size v))
 	 (a (mcreate v 0 (list n n))))

Modified: src/matrix/level2-interface.lisp
==============================================================================
--- src/matrix/level2-interface.lisp	(original)
+++ src/matrix/level2-interface.lisp	Thu May 21 10:18:38 2009
@@ -22,13 +22,14 @@
 ;;; TODO sort and possibly move to other levels
 
 (export '(
-	  .every .some ; to level0 ?
-	  
+	  .every .some ; to level0 ?	  
 	  square-matrix?
-	  new mnew 
-	  create mcreate
+	  ; new 
+	  mnew 
+	  ; create 
+	  mcreate
 	  copy-contents 
-	  diag
+	  ; diag
 	  .map mmap fill!	   
 	  dlmwrite dlmread 
 	  to-vector! to-vector




More information about the lisplab-cvs mailing list