Skip to content

Commit 38f37bc

Browse files
Speed up is_homogeneous (#4119)
Some measurements taking the example from the `is_homogeneous` docstring: R, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"], [1, 2, 3]) f = x^2+y*z W = [1 2 1 0; 3 4 0 1] S, (w, x, y, z) = graded_polynomial_ring(QQ, ["w", "x", "y", "z"], W) F = w^3*y^3*z^3 + w^2*x*y^2*z^2 + w*x^2*y*z + x^3 Before: julia> @Btime is_homogeneous(f); 1.533 μs (62 allocations: 2.28 KiB) julia> @Btime is_homogeneous(F); 3.932 μs (152 allocations: 5.53 KiB) After: julia> @Btime is_homogeneous(f); 334.071 ns (10 allocations: 416 bytes) julia> @Btime is_homogeneous(F); 556.150 ns (12 allocations: 656 bytes) --------- Co-authored-by: Lars Göttgens <lars.goettgens@rwth-aachen.de>
1 parent 55ea957 commit 38f37bc

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ AbstractAlgebra = "0.43.1"
2929
AlgebraicSolving = "0.7.0"
3030
Distributed = "1.6"
3131
GAP = "0.11.3"
32-
Hecke = "0.34.1"
32+
Hecke = "0.34.3"
3333
JSON = "^0.20, ^0.21"
3434
JSON3 = "1.13.2"
3535
LazyArtifacts = "1.6"

src/Rings/mpoly-graded.jl

+8-5
Original file line numberDiff line numberDiff line change
@@ -970,14 +970,17 @@ true
970970
function is_homogeneous(F::MPolyDecRingElem)
971971
D = parent(F).D
972972
d = parent(F).d
973-
S = Set{elem_type(D)}()
973+
S = nothing
974+
u = zero(D)
974975
for c = MPolyExponentVectors(forget_decoration(F))
975-
u = parent(F).D[0]
976+
u = zero!(u)
976977
for i=1:length(c)
977-
u += c[i]*d[i]
978+
u = addmul_delayed_reduction!(u, d[i], c[i])
978979
end
979-
push!(S, u)
980-
if length(S) > 1
980+
u = reduce!(u)
981+
if S === nothing
982+
S = deepcopy(u)
983+
elseif S != u
981984
return false
982985
end
983986
end

0 commit comments

Comments
 (0)