# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1179643788 25200
# Node ID 1689c401658b21d07579911a283d2f6850f6a483
# Parent  7995bb6c1e25565c68de2497fee50ec3f74b7896
Fixed rank bug that Nick Alexander found.

When we switched to linbox the linbox rank algorithm got called and
didn't raise an error.  I've changed SAGE to now only call that linbox
routine when the base ring is a field.  Otherwise it calls a generic
routine, which, in this case, properly raises a NotImplementedError.
See attached patch.

diff -r 7995bb6c1e25 -r 1689c401658b sage/matrix/matrix_modn_dense.pyx
--- a/sage/matrix/matrix_modn_dense.pyx	Sat May 19 23:41:11 2007 -0700
+++ b/sage/matrix/matrix_modn_dense.pyx	Sat May 19 23:49:48 2007 -0700
@@ -851,7 +851,22 @@ cdef class Matrix_modn_dense(matrix_dens
         return R(v)
 
     def rank(self):
-        if self.p > 2:
+        """
+        Return the rank of this matrix.
+        
+        EXAMPLES:
+            sage: m = matrix(GF(7),5,range(25))
+            sage: m.rank()
+            2
+
+        Rank is not implemented over the integers modulo a composite yet. 
+            sage: m = matrix(Integers(4), 2, [2,2,2,2])
+            sage: m.rank()
+            Traceback (most recent call last):
+            ...
+            NotImplementedError: Echelon form not implemented over 'Ring of integers modulo 4'.
+        """
+        if self.p > 2 and is_prime(self.p):
             x = self.fetch('rank')
             if not x is None:
                 return x
