Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7b81180

Browse files
committedMay 3, 2025·
Use cmp instead of compare
1 parent 469c47c commit 7b81180

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed
 

‎src/monomial_vector.jl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
export MonomialVector
22

3+
struct AllMonomials{V,M} <: AbstractVector{Monomial{V,M}}
4+
vars::Vector{Variable{V,M}}
5+
end
6+
Base.IteratorSize(::Type{<:AllMonomials}) = Base.IsInfinite()
7+
38
# Invariant: Always sorted and no zero vector
49
struct MonomialVector{V,M} <: AbstractVector{Monomial{V,M}}
510
vars::Vector{Variable{V,M}}
@@ -148,14 +153,14 @@ function _error_for_negative_degree(deg)
148153
end
149154
end
150155

151-
const _Lex = Union{MP.LexOrder,MP.InverseLexOrder}
152-
153-
_last_lex_index(n, ::Type{MP.LexOrder}) = n
154-
_prev_lex_index(i, ::Type{MP.LexOrder}) = i - 1
155-
_not_first_indices(n, ::Type{MP.LexOrder}) = n:-1:2
156-
_last_lex_index(_, ::Type{MP.InverseLexOrder}) = 1
157-
_prev_lex_index(i, ::Type{MP.InverseLexOrder}) = i + 1
158-
_not_first_indices(n, ::Type{MP.InverseLexOrder}) = 1:(n-1)
156+
I = _not_first_indices(n, M)
157+
if state == 0
158+
return (zeros(Int, it.num_vars), 1)
159+
end
160+
z = zeros(Int, it.num_vars)
161+
z[_last_lex_index(it.num_vars, M)] = state
162+
return (z, state + 1)
163+
end
159164

160165
function _fill_exponents!(Z, n, degs, ::Type{Commutative}, M::Type{<:_Lex}, filter::Function)
161166
_error_for_negative_degree.(degs)
@@ -266,7 +271,7 @@ function _all_exponents(
266271
::Type{M},
267272
filter::Function,
268273
) where {V,M}
269-
Z = Vector{Vector{Int}}()
274+
Z = Vector{Int}[]
270275
_fill_exponents!(Z, n, degs, V, M, filter)
271276
_isless = let M = M
272277
(a, b) -> MP.compare(a, b, M) < 0
@@ -390,7 +395,7 @@ end
390395
function MonomialVector{V,M}(X::DMonoVec{V,M}) where {V,M}
391396
allvars, Z = buildZvarsvec(Variable{V,M}, X)
392397
_isless = let M = M
393-
(a, b) -> MP.compare(a, b, M) < 0
398+
(a, b) -> cmp(M(), a, b) < 0
394399
end
395400
sort!(Z, lt = _isless)
396401
dups = findall(i -> Z[i] == Z[i-1], 2:length(Z))

‎src/operators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function MA.operate!(
115115
end
116116

117117
function _exponents_compare(q::Polynomial{V,M}, j, e) where {V,M}
118-
return MP.compare(q.x.Z[j], e, M)
118+
return cmp(M(), q.x.Z[j], e)
119119
end
120120

121121
# TODO need to check that this also works for non-commutative

‎src/poly.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function removedups_to!(
227227
::Type{M},
228228
) where {T,M}
229229
_isless = let M = M
230-
(a, b) -> MP.compare(a, b, M) < 0
230+
(a, b) -> cmp(M(), a, b) < 0
231231
end
232232
σ = sortperm(Zdup, lt = _isless)
233233
i = 0

‎test/comp.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ end
1313
function _less(a, b)
1414
@test a < b
1515
@test b > a
16-
@test compare(monomial(a), b) < 0
17-
@test compare(b, monomial(a)) > 0
16+
@test cmp(monomial(a), b) < 0
17+
@test cmp(b, monomial(a)) > 0
1818
end
1919
@testset "Issue 152" begin
2020
@polyvar x y monomial_order=LexOrder

0 commit comments

Comments
 (0)
Please sign in to comment.