0x0-matrices

Nicolas Neuss <[email protected]> 28 Feb 2003 16:36:00 +0100
Newsgroups gmane.lisp.matlisp.user
Organization IWR
Message-ID <[email protected]>
Hello,

at the moment matlisp can't handle 0x0-, nx0- or 0xn-matrices.  This is
annoying because these may arise in some border situations (of course,
without elements being referenced).

Below is a patch which should make this possible (it corrects also a
remaining :type 'fixnum).  Sourceforge CVS was partially down, so I diffed
against a local file for print.lisp (which should be same as CVS, though).

Yours, Nicolas.


neuss@ortler:~/CL-HOME/matlisp/src$ cvs diff -u matrix.lisp
Index: matrix.lisp
===================================================================
RCS file: /cvsroot/matlisp/matlisp/src/matrix.lisp,v
retrieving revision 1.11
diff -u -r1.11 matrix.lisp
--- matrix.lisp	19 Feb 2003 21:59:52 -0000	1.11
+++ matrix.lisp	28 Feb 2003 15:20:19 -0000
@@ -256,7 +256,7 @@
     :initarg :store-size
     :initform 0
     :accessor store-size
-    :type 'fixnum
+    :type fixnum
     :documentation "Total number of elements needed to store the matrix.  (Usually
 the same as nels, but not necessarily so!")
    (store
@@ -665,7 +665,7 @@
        (let ((arg (first args)))
 	 (typecase arg
 	   (integer
-	    (assert (plusp arg) nil
+	    (assert (not (minusp arg)) nil
 		    "matrix dimension must be positive, not ~A" arg)
 	    (make-real-matrix-dim arg arg))
 	   (sequence
@@ -676,8 +676,8 @@
       (2
        (destructuring-bind (n m)
 	   args
-	 (assert (and (typep n '(integer 1))
-		      (typep n '(integer 1)))
+	 (assert (and (typep n '(integer 0))
+		      (typep n '(integer 0)))
 		 nil
 		 "cannot make a ~A x ~A matrix" n m)
 	 (make-real-matrix-dim n m)))
@@ -850,8 +850,8 @@
        (let ((arg (first args)))
 	 (typecase arg
 	   (integer
-	    (assert (plusp arg) nil
-		    "matrix dimension must be positive, not ~A" arg)
+	    (assert (not (minusp arg)) nil
+		    "matrix dimension must be non-negative, not ~A" arg)
 	    (make-complex-matrix-dim arg arg))
 	   (sequence
 	    (make-complex-matrix-sequence arg))
@@ -861,8 +861,8 @@
       (2
        (destructuring-bind (n m)
 	   args
-	 (assert (and (typep n '(integer 1))
-		      (typep n '(integer 1)))
+	 (assert (and (typep n '(integer 0))
+		      (typep n '(integer 0)))
 		 nil
 		 "cannot make a ~A x ~A matrix" n m)
 	 (make-complex-matrix-dim n m)))

neuss@ortler:~/CL-HOME/matlisp/src$ diff -u print.lisp print.lisp.~1.7~
--- print.lisp	Fri Feb 28 16:30:46 2003
+++ print.lisp.~1.7~	Fri Feb 28 16:32:20 2003
@@ -154,35 +154,36 @@
 		  (dotimes (i *matrix-indent*)
 		    (format stream " "))
 		  (dotimes (j max-m)
+		    (declare (type fixnum j))
 		    (print-element matrix 
 				   (matrix-ref matrix i j)
 				   stream)
 		    (format stream " "))
-		  (when (plusp number-of-cols)
-		    (if (< max-m (1- number-of-cols))
+		  (if (< max-m (1- number-of-cols))
+		      (progn
+			(format stream "... ")
+			(print-element matrix 
+				       (matrix-ref matrix i (1- number-of-cols))
+				       stream)
+			(format stream " "))
+		    (if (< max-m number-of-cols)
 			(progn
-			  (format stream "... ")
 			  (print-element matrix 
 					 (matrix-ref matrix i (1- number-of-cols))
 					 stream)
-			  (format stream " "))
-			(if (< max-m number-of-cols)
-			    (progn
-			      (print-element matrix 
-					     (matrix-ref matrix i (1- number-of-cols))
-					     stream)
-			      (format stream " ")))))))
+			  (format stream " "))))))
 	   
 	   (dotimes (i max-n)
+	     (declare (type fixnum i))
 	     (print-row i))
+	   
+	   (if (< max-n (1- number-of-rows))
+	       (progn
+		 (format stream "~%     :")
+		 (print-row (1- number-of-rows)))
+	     (if (< max-n number-of-rows)
+		 (print-row (1- number-of-rows))))))))
 
-	   (when (plusp number-of-rows)
-	     (if (< max-n (1- number-of-rows))
-		 (progn
-		   (format stream "~%     :")
-		   (print-row (1- number-of-rows)))
-		 (if (< max-n number-of-rows)
-		     (print-row (1- number-of-rows)))))))))
 
 (defmethod print-object ((matrix standard-matrix) stream)
   (print-unreadable-object (matrix stream :type t :identity (not *print-matrix*))