]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
mjo/ldlt.py: avoid some intermediate variables in ldlt_fast().
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 28 Sep 2020 18:41:12 +0000 (14:41 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 28 Sep 2020 18:41:12 +0000 (14:41 -0400)
mjo/ldlt.py

index d113df36476e49e244a23ec906cef2ba1453a266..45615288085764c5bf59b3241343da030c948b6e 100644 (file)
@@ -195,18 +195,15 @@ def ldlt_fast(A):
             # Update the "next" block of A that we'll work on during
             # the following iteration. I think it's faster to get the
             # entries of a row than a column here?
-            v = vector(ring, A[k,k+1:n].list())
-            b = v.column()*v.row()/alpha
             for i in range(n-k-1):
                 for j in range(i+1):
-                    # Something goes wrong if I try to access the kth row/column
-                    # of A to save the intermediate "b" here...
-                    A[k+1+i,k+1+j] = A[k+1+i,k+1+j] - b[i,j]
+                    A[k+1+i,k+1+j] = A[k+1+i,k+1+j] - A[k,k+1+i]*A[k,k+1+j]/alpha
                     A[k+1+j,k+1+i] = A[k+1+i,k+1+j] # keep it symmetric!
 
             # Store the "new" (kth) column of L.
             for i in range(n-k-1):
-                L[k+i+1,k] = v[i]/alpha
+                # Set the lower-left "half" from the upper-right "half"...
+                L[k+i+1,k] = A[k,k+1+i]/alpha
 
     I = A.matrix_space().identity_matrix()
     P = matrix.column( I.row(p[j]) for j in range(n) )