Skip to content

Commit

Permalink
feat: make _canonical_matrix faster
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Sep 19, 2024
1 parent b5d0b43 commit 6e9fb5a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Rings/orderings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,35 @@ struct MatrixOrdering <: AbsGenOrdering
end

function _canonical_matrix(w)
ww = matrix(ZZ, 0, ncols(w), [])
# we store the results in ww and keep track of the "real" number of rows
# in k
ww = zero_matrix(ZZ, nrows(w), ncols(w))
k = 0
for i in 1:nrows(w)
if is_zero_row(w, i)
continue
end
nw = w[i:i, :]
nw = view(w, i:i, :)
c = content(nw)
if !isone(c)
nw = divexact(nw, c)
nw = divexact!(nw, nw, c)
end
for j in 1:nrows(ww)
h = findfirst(x->ww[j, x] != 0, 1:ncols(w))
if !iszero(nw[1, h])
nw = abs(ww[j, h])*nw - sign(ww[j, h])*nw[1, h]*ww[j:j, :]
for j in 1:k
h = findfirst(x-> is_zero_entry(ww, j, x), 1:ncols(w))
if !is_zero_entry(nw, 1, h)
nw = abs(ww[j, h])*nw - sign(ww[j, h])*nw[1, h]*view(ww, j:j, :)
end
end
if !iszero(nw)
c = content(nw)
if !isone(c)
nw = divexact(nw, c)
nw = divexact!(nw, nw, c)
end
ww = vcat(ww, nw)
ww[(k + 1):(k + 1), :] = nw
k += 1
end
end
ww = view(ww, 1:k, :)
@assert nrows(ww) <= ncols(ww)
return ww
end
Expand Down

0 comments on commit 6e9fb5a

Please sign in to comment.