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

feat: make _canonical_matrix faster #4117

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/Rings/orderings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct MatrixOrdering <: AbsGenOrdering
end
end

function _canonical_matrix(w)
function __canonical_matrix(w)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is no longer used and should be removed (before merging this)

ww = matrix(ZZ, 0, ncols(w), [])
for i in 1:nrows(w)
if is_zero_row(w, i)
Expand Down Expand Up @@ -116,6 +116,43 @@ function _canonical_matrix(w)
return ww
end

function _canonical_matrix(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
piv = Int[]
# piv[i] stores the column index of the first non-zero entry in row i of ww
for i in 1:nrows(w)
if is_zero_row(w, i)
continue
end
nw = view(w, i:i, :)
c = content(nw)
if !isone(c)
nw = divexact!(nw, nw, c)
fingolfin marked this conversation as resolved.
Show resolved Hide resolved
end
for j in 1:k
h = piv[j]
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, nw, c)
end
ww[(k + 1):(k + 1), :] = nw
push!(piv, findfirst(x -> !is_zero_entry(nw, 1, x), 1:ncols(w)))
k += 1
end
end
ww = view(ww, 1:k, :)
@assert nrows(ww) <= ncols(ww)
return ww
end


# convert (y,x,z) => (2,1,3) and check uniqueness
function _unique_var_indices(a::AbstractVector{<:MPolyRingElem})
Expand Down
Loading