I want to find find a reduced a row echelon form (in field F_q) of a big matrix. I tried the following code. Although I used gmpy2 library to speed up, the program was still out of memory. because my input matrix is very large (100 x 2^15) and p is also very large (|p|=256 bits). Can someone suggest how to reduce the complexity of this alg.
Thank you
def invmodp(a, p):
return gmpy2.invert(a,p)
def division_mod(a, b, p): #a/b mod p
invert = invmodp(b, p)
return (a * invert) %p
def row_echelon_form(M, p):
lead = 0
rowCount = len(M)
columnCount = len(M[0])
for r in range(rowCount):
if lead >= columnCount:
return
i = r
while M[i][lead] == 0:
i += 1
if i == rowCount:
i = r
lead += 1
if columnCount == lead:
return
M[i],M[r] = M[r],M[i]
lv = M[r][lead]
M[r] = [ division_mod(mrx, lv, p) for mrx in M[r]]
for i in range(rowCount):
if i != r:
lv = M[i][lead]
M[i] = [ (iv - lv*rv)%p for rv,iv in zip(M[r],M[i])]
lead += 1
return M