Skip to content

Commit 5432555

Browse files
authored
Merge pull request #82 from algebraic-solving/revert-78-faster-nemo-interface
Revert "Faster nemo interface"
2 parents 44c7b8c + b646abe commit 5432555

File tree

2 files changed

+23
-42
lines changed

2 files changed

+23
-42
lines changed

src/interfaces/nemo.jl

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
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
146126
end
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
197177
end

test/interfaces/nemo.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
cmp = (Int32[1], BigInt[1], Int32[1, 0], 1)
1010
@test AlgebraicSolving._convert_to_msolve(I.gens) == cmp
1111
for _GF in [GF, AlgebraicSolving.Nemo.Native.GF]
12-
R, (x,y,z) = polynomial_ring(GF(2147483659),["x","y","z"], internal_ordering=:degrevlex)
12+
R, (x,y,z) = polynomial_ring(_GF(2147483659),["x","y","z"], internal_ordering=:degrevlex)
1313
F = [x^2+1-3, x*y-z, x*z^2-3*y^2]
1414
# prime is bigger than 2^31, should throw an error
1515
@test_throws ErrorException AlgebraicSolving._convert_to_msolve(F)
16-
R, (x,y,z) = polynomial_ring(GF(101),["x","y","z"], internal_ordering=:degrevlex)
16+
R, (x,y,z) = polynomial_ring(_GF(101),["x","y","z"], internal_ordering=:degrevlex)
1717
F = [x^2+1-3, x*y-z, x*z^2-3*y^2]
18+
@show F
1819
res = AlgebraicSolving._convert_to_msolve(F)
1920
@test AlgebraicSolving._convert_finite_field_array_to_abstract_algebra(Int32(3), res[1], res[2], res[3], R) == F
2021
end

0 commit comments

Comments
 (0)