1+ function _resize_ff! (a:: FqMPolyRingElem , n:: Int )
2+ if a. data isa Generic. MPoly
3+ fit! (a, n)
4+ elseif a. data isa fqPolyRepMPolyRingElem
5+ ccall ((:fq_nmod_mpoly_resize , Nemo. libflint), Nothing,
6+ (Ref{fqPolyRepMPolyRingElem}, Int, Ref{fqPolyRepMPolyRing}), a. data,
7+ n, a. parent. data)
8+ else
9+ @assert a. data isa Nemo. fpMPolyRingElem
10+ ccall ((:nmod_mpoly_resize , Nemo. libflint), Nothing,
11+ (Ref{fpMPolyRingElem}, Int, Ref{fpMPolyRing}), a. data, n,
12+ a. parent. data)
13+ end
14+ end
15+
16+ function _resize_qq! (a:: QQMPolyRingElem , n:: Int )
17+ ccall ((:fmpq_mpoly_resize , Nemo. libflint), Cvoid, (Ref{QQMPolyRingElem}, Int, Ref{QQMPolyRing}), a, n, parent (a))
18+ end
119
220@doc Markdown. doc"""
321 _convert_to_msolve(
@@ -93,39 +111,41 @@ function _convert_finite_field_array_to_abstract_algebra(
93111 nr_vars = nvars (R)
94112 CR = coefficient_ring (R)
95113
96- basis = (typeof (R (0 )))[]
97- #= basis = Vector{MPolyRingElem}(undef, bld) =#
98-
99114 len = 0
100115
116+ @show eliminate
101117 if eliminate > 0
102118 z = zeros (Int, eliminate)
103119 end
120+ g = [zero (R) for j in 1 : nr_gens]
104121 for i in 1 : nr_gens
105122 #= check if element is part of the eliminated basis =#
106123 if eliminate > 0
107124 cmp = convert (Vector{Int}, bexp[(len)* nr_vars+ 1 : (len+ 1 )* nr_vars])
125+ @show i
126+ @show cmp[1 : eliminate]
127+ @show z
128+ @show cmp[1 : eliminate] > z
108129 if cmp[1 : eliminate] > z
109130 continue
110131 end
111132 end
112133 if bcf[len+ 1 ] == 0
113- push! (basis, R (0 ) )
134+ g[i] = R (0 )
114135 else
115- g = zero (R)
116- ccall ((:fq_nmod_mpoly_resize , Nemo. libflint), Cvoid, (Ref{FqMPolyRingElem}, Int, Ref{FqMPolyRing}), g, blen[i], parent (g))
136+ _resize_ff! (g[i], Int (blen[i]))
117137 for j in 1 : blen[i]
118- Nemo. setcoeff! (g, j, CR (bcf[len+ j]))
138+ Nemo. setcoeff! (g[i] , j, CR (bcf[len+ j]))
119139 end
120140 for j in 1 : blen[i]
121- Nemo. set_exponent_vector! (g, j, convert (Vector{Int}, bexp[(len+ j- 1 )* nr_vars+ 1 : (len+ j)* nr_vars]))
141+ Nemo. set_exponent_vector! (g[i] , j, convert (Vector{Int}, bexp[(len+ j- 1 )* nr_vars+ 1 : (len+ j)* nr_vars]))
122142 end
123- push! (basis, g)
124143 end
125144 len += blen[i]
126145 end
127146
128- return basis
147+ sort_terms! .(g)
148+ return g
129149end
130150
131151function _convert_rational_array_to_abstract_algebra (
@@ -149,33 +169,32 @@ function _convert_rational_array_to_abstract_algebra(
149169 nr_vars = nvars (R)
150170 CR = coefficient_ring (R)
151171
152- basis = (typeof (R (0 )))[]
153-
154172 len = 0
155173
174+ g = [zero (R) for j in 1 : nr_gens]
156175 for i in 1 : nr_gens
157176 if bcf[len+ 1 ] == 0
158- push! (basis, R (0 ) )
177+ g[i] = R (0 )
159178 else
160- g = zero (R )
179+ _resize_qq! (g[i], Int (blen[i]) )
161180 lc = bcf[len+ 1 ]
162181
163182 if normalize && lc != 1
164183 for j in 1 : blen[i]
165- Nemo. setcoeff! (g, j, bcf[len+ j]/ lc)
184+ Nemo. setcoeff! (g[i] , j, bcf[len+ j]/ lc)
166185 end
167186 else
168187 for j in 1 : blen[i]
169- Nemo. setcoeff! (g, j, bcf[len+ j])
188+ Nemo. setcoeff! (g[i] , j, bcf[len+ j])
170189 end
171190 end
172191 for j in 1 : blen[i]
173- Nemo. set_exponent_vector! (g, j, convert (Vector{Int}, bexp[(len+ j- 1 )* nr_vars+ 1 : (len+ j)* nr_vars]))
192+ Nemo. set_exponent_vector! (g[i] , j, convert (Vector{Int}, bexp[(len+ j- 1 )* nr_vars+ 1 : (len+ j)* nr_vars]))
174193 end
175- push! (basis, g)
176194 end
177195 len += blen[i]
178196 end
179197
180- return basis
198+ sort_terms! .(g)
199+ return g
181200end
0 commit comments