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
191
202@doc Markdown. doc"""
213 _convert_to_msolve(
@@ -111,13 +93,14 @@ function _convert_finite_field_array_to_abstract_algebra(
11193 nr_vars = nvars (R)
11294 CR = coefficient_ring (R)
11395
114- len = 0
115- ctr = 0
96+ basis = (typeof (R (0 )))[]
97+ #= basis = Vector{MPolyRingElem}(undef, bld) =#
98+
99+ len = 0
116100
117101 if eliminate > 0
118102 z = zeros (Int, eliminate)
119103 end
120- g = [zero (R) for j in 1 : nr_gens]
121104 for i in 1 : nr_gens
122105 #= check if element is part of the eliminated basis =#
123106 if eliminate > 0
@@ -127,21 +110,18 @@ function _convert_finite_field_array_to_abstract_algebra(
127110 end
128111 end
129112 if bcf[len+ 1 ] == 0
130- g[i] = R (0 )
113+ push! (basis, R (0 ) )
131114 else
132- _resize_ff! (g[i], Int (blen[i]) )
115+ g = MPolyBuildCtx (R )
133116 for j in 1 : blen[i]
134- Nemo. setcoeff! (g[i], j, CR (bcf[len+ j]))
135- end
136- for j in 1 : blen[i]
137- Nemo. set_exponent_vector! (g[i], j, convert (Vector{Int}, bexp[(len+ j- 1 )* nr_vars+ 1 : (len+ j)* nr_vars]))
117+ push_term! (g, CR (bcf[len+ j]),
118+ convert (Vector{Int}, bexp[(len+ j- 1 )* nr_vars+ 1 : (len+ j)* nr_vars]))
138119 end
120+ push! (basis, finish (g))
139121 end
140- ctr += 1
141122 len += blen[i]
142123 end
143- basis = g[1 : ctr]
144- sort_terms! .(basis)
124+
145125 return basis
146126end
147127
@@ -166,32 +146,32 @@ function _convert_rational_array_to_abstract_algebra(
166146 nr_vars = nvars (R)
167147 CR = coefficient_ring (R)
168148
149+ basis = (typeof (R (0 )))[]
150+
169151 len = 0
170152
171- g = [zero (R) for j in 1 : nr_gens]
172153 for i in 1 : nr_gens
173154 if bcf[len+ 1 ] == 0
174- g[i] = R (0 )
155+ push! (basis, R (0 ) )
175156 else
176- _resize_qq! (g[i], Int (blen[i]) )
157+ g = MPolyBuildCtx (R )
177158 lc = bcf[len+ 1 ]
178159
179160 if normalize && lc != 1
180161 for j in 1 : blen[i]
181- Nemo. setcoeff! (g[i], j, bcf[len+ j]/ lc)
162+ push_term! (g, bcf[len+ j]/ lc,
163+ convert (Vector{Int}, bexp[(len+ j- 1 )* nr_vars+ 1 : (len+ j)* nr_vars]))
182164 end
183165 else
184166 for j in 1 : blen[i]
185- Nemo. setcoeff! (g[i], j, bcf[len+ j])
167+ push_term! (g, bcf[len+ j],
168+ convert (Vector{Int}, bexp[(len+ j- 1 )* nr_vars+ 1 : (len+ j)* nr_vars]))
186169 end
187170 end
188- for j in 1 : blen[i]
189- Nemo. set_exponent_vector! (g[i], j, convert (Vector{Int}, bexp[(len+ j- 1 )* nr_vars+ 1 : (len+ j)* nr_vars]))
190- end
171+ push! (basis, finish (g))
191172 end
192173 len += blen[i]
193174 end
194175
195- sort_terms! .(g)
196- return g
176+ return basis
197177end
0 commit comments