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,14 +111,13 @@ 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-
99- len = 0
114+ len = 0
115+ ctr = 0
100116
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
@@ -110,18 +127,21 @@ function _convert_finite_field_array_to_abstract_algebra(
110127 end
111128 end
112129 if bcf[len+ 1 ] == 0
113- push! (basis, R (0 ) )
130+ g[i] = R (0 )
114131 else
115- g = MPolyBuildCtx (R )
132+ _resize_ff! (g[i], Int (blen[i]) )
116133 for j in 1 : blen[i]
117- push_term! (g, CR (bcf[len+ j]),
118- convert (Vector{Int}, bexp[(len+ j- 1 )* nr_vars+ 1 : (len+ j)* nr_vars]))
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]))
119138 end
120- push! (basis, finish (g))
121139 end
140+ ctr += 1
122141 len += blen[i]
123142 end
124-
143+ basis = g[1 : ctr]
144+ sort_terms! .(basis)
125145 return basis
126146end
127147
@@ -146,32 +166,32 @@ function _convert_rational_array_to_abstract_algebra(
146166 nr_vars = nvars (R)
147167 CR = coefficient_ring (R)
148168
149- basis = (typeof (R (0 )))[]
150-
151169 len = 0
152170
171+ g = [zero (R) for j in 1 : nr_gens]
153172 for i in 1 : nr_gens
154173 if bcf[len+ 1 ] == 0
155- push! (basis, R (0 ) )
174+ g[i] = R (0 )
156175 else
157- g = MPolyBuildCtx (R )
176+ _resize_qq! (g[i], Int (blen[i]) )
158177 lc = bcf[len+ 1 ]
159178
160179 if normalize && lc != 1
161180 for j in 1 : blen[i]
162- push_term! (g, bcf[len+ j]/ lc,
163- convert (Vector{Int}, bexp[(len+ j- 1 )* nr_vars+ 1 : (len+ j)* nr_vars]))
181+ Nemo. setcoeff! (g[i], j, bcf[len+ j]/ lc)
164182 end
165183 else
166184 for j in 1 : blen[i]
167- push_term! (g, bcf[len+ j],
168- convert (Vector{Int}, bexp[(len+ j- 1 )* nr_vars+ 1 : (len+ j)* nr_vars]))
185+ Nemo. setcoeff! (g[i], j, bcf[len+ j])
169186 end
170187 end
171- push! (basis, finish (g))
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
172191 end
173192 len += blen[i]
174193 end
175194
176- return basis
195+ sort_terms! .(g)
196+ return g
177197end
0 commit comments