Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naïve endomorphism_algebra implementation gets slow for large dimensions #1083

Open
mgkurtz opened this issue May 25, 2023 · 2 comments
Open

Comments

@mgkurtz
Copy link
Contributor

mgkurtz commented May 25, 2023

For an algebra generated by several 50×50 matrices, say 40, computing the endomorphism_algebra consumes lots of memory and time. Precisely, time and memory goes into vcat and right_kernel (and there into rref) in the code snippet below:

linind = transpose(LinearIndices((n,m)))
zz = zero_matrix(FlintQQ, 0, n*m)
for (A, B) in zip(As, Bs)
z = zero_matrix(FlintQQ, n*m, n*m)
for i in 1:m
for j in 1:n
for k in 1:n
z[linind[i, j], linind[i, k]] += A[k, j]
end
for k in 1:m
z[linind[i, j], linind[k, j]] -= B[i, k]
end
end
end
zz = vcat(zz, z)
end
r, K = right_kernel(zz)

This code builds a 40⋅50²×50² “dense” matrix with only two 50+50 non-zero entries per row. Using sparse matrices instead of dense ones, and adding the rows iteratively to a rref instead of building a giant matrix, should reduce memory and time consumption by a lot, I guess.

Additionally a comment, to explain the code, could help. I guess, the lines

for i in 1:length(As)
M * As[i] == Bs[i] * M
end

should be assertions, which (if they were assertions) already helped explaining the code.

@thofma
Copy link
Owner

thofma commented May 25, 2023

Yes and yes. I only used it for toying around so far, but your suggestions sound good.

@mgkurtz
Copy link
Contributor Author

mgkurtz commented May 30, 2023

Seems, like I am bad at counting. There are actually n+m (here 100) entries per row. So, even with sparse matrices that can take some time. Anyway, there are more efficient algorithms out there. I will see, how far I come, with the tools Hecke or Oscar already include.

@mgkurtz mgkurtz changed the title endomorphism_algebra uses extremely sparse “dense“ matrices internally Naïve endomorphism_algebra implementation gets slow for large dimensions May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants