# HG changeset patch
# User Robert Bradshaw <robertwb@math.washington.edu>
# Date 1201215838 28800
# Node ID 05d8b24d15581b8d2d3b483b0617172c814b4505
# Parent  445d8780bc5d0e7ede8865d051d8cc2875a0907e
Reverse loop order in modn multiplication, 2x speedup

diff -r 445d8780bc5d -r 05d8b24d1558 sage/matrix/matrix_window_modn_dense.pyx
--- a/sage/matrix/matrix_window_modn_dense.pyx	Fri Jan 18 23:40:12 2008 -0800
+++ b/sage/matrix/matrix_window_modn_dense.pyx	Thu Jan 24 15:03:58 2008 -0800
@@ -124,6 +124,9 @@ cdef class MatrixWindow_modn_dense(matri
         p = ( <Matrix_modn_dense> self._matrix ).p
         gather = ( <Matrix_modn_dense> self._matrix ).gather
         A_ncols = A._ncols
+
+        cdef mod_int A_row_k, 
+        cdef mod_int* B_row_k
         
         if gather <= 1:
             for i from 0 <= i < A._nrows:
@@ -138,18 +141,20 @@ cdef class MatrixWindow_modn_dense(matri
             for i from 0 <= i < A._nrows:
                 self_row = ( <Matrix_modn_dense> self._matrix )._matrix[i + self._row] + self._col
                 A_row    = ( <Matrix_modn_dense>    A._matrix )._matrix[i +    A._row] + A._col
-                for j from 0 <= j < B._ncols:
-                    s = 0
-                    k = 0
-                    while k < A_ncols:
-                        top = k + gather
-                        if top > A_ncols:
-                            top = A_ncols
-                        for k from k <= k < top: # = min(k+gather, A._ncols)
-                            pass
-                            s += A_row[k] * B_matrix_off[k][j+B._col]
-                        s %= p
-                    self_row[j] = s
+                s = 0
+                k = 0
+                while k < A_ncols:
+                    top = k + gather
+                    if top > A_ncols:
+                        top = A_ncols
+                    self_row[j] = 0
+                    for k from k <= k < top: # = min(k+gather, A._ncols)
+                        A_row_k = A_row[k]
+                        B_row_k = B_matrix_off[k] + B._col
+                        for j from 0 <= j < B._ncols:
+                            self_row[j] += A_row_k * B_row_k[j]
+                    for j from 0 <= j < B._ncols:
+                        self_row[j] %= p
                             
     cdef add_prod(self, MatrixWindow A, MatrixWindow B):
         cdef Py_ssize_t i, j, k, gather, top, A_ncols
