| 
1 | 1 | export MonomialVector  | 
2 | 2 | 
 
  | 
 | 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 | + | 
3 | 8 | # Invariant: Always sorted and no zero vector  | 
4 | 9 | struct MonomialVector{V,M} <: AbstractVector{Monomial{V,M}}  | 
5 | 10 |     vars::Vector{Variable{V,M}}  | 
@@ -148,14 +153,14 @@ function _error_for_negative_degree(deg)  | 
148 | 153 |     end  | 
149 | 154 | end  | 
150 | 155 | 
 
  | 
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  | 
159 | 164 | 
 
  | 
160 | 165 | function _fill_exponents!(Z, n, degs, ::Type{Commutative}, M::Type{<:_Lex}, filter::Function)  | 
161 | 166 |     _error_for_negative_degree.(degs)  | 
@@ -266,7 +271,7 @@ function _all_exponents(  | 
266 | 271 |     ::Type{M},  | 
267 | 272 |     filter::Function,  | 
268 | 273 | ) where {V,M}  | 
269 |  | -    Z = Vector{Vector{Int}}()  | 
 | 274 | +    Z = Vector{Int}[]  | 
270 | 275 |     _fill_exponents!(Z, n, degs, V, M, filter)  | 
271 | 276 |     _isless = let M = M  | 
272 | 277 |         (a, b) -> MP.compare(a, b, M) < 0  | 
 | 
390 | 395 | function MonomialVector{V,M}(X::DMonoVec{V,M}) where {V,M}  | 
391 | 396 |     allvars, Z = buildZvarsvec(Variable{V,M}, X)  | 
392 | 397 |     _isless = let M = M  | 
393 |  | -        (a, b) -> MP.compare(a, b, M) < 0  | 
 | 398 | +        (a, b) -> cmp(M(), a, b) < 0  | 
394 | 399 |     end  | 
395 | 400 |     sort!(Z, lt = _isless)  | 
396 | 401 |     dups = findall(i -> Z[i] == Z[i-1], 2:length(Z))  | 
 | 
0 commit comments