Skip to content

Commit 7852360

Browse files
authored
Fix mapexponents! (#86)
1 parent 0371365 commit 7852360

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/cmult.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,25 @@ end
2626
function multdivmono!(output_variables::Vector{PolyVar{true}},
2727
v::Vector{PolyVar{true}}, x::Monomial{true}, op)
2828
if v == x.vars
29-
updatez! = (output, z) -> @. output = op(z, x.z)
29+
if output_variables == v
30+
updatez! = (output, z) -> begin
31+
@. output = op(z, x.z)
32+
return
33+
end
34+
else
35+
resize!(output_variables, length(v))
36+
copyto!(output_variables, v)
37+
updatez! = (output, z) -> begin
38+
resize!(output, length(output_variables))
39+
@. output = op(z, x.z)
40+
return
41+
end
42+
end
3043
else
31-
w, maps = mergevars([v, x.vars])
44+
maps = mergevars_to!(output_variables, [v, x.vars])
3245
n = length(v)
33-
resize!(output_variables, length(w))
34-
output_variables[maps[1]] = v[1:n]
3546
updatez! = (output, z) -> begin
36-
resize!(output, length(w))
37-
z[maps[1]] = z[1:n]
47+
resize!(output, length(output_variables))
3848
I = maps[1]; i = 1; lI = length(I)
3949
J = maps[2]; j = 1; lJ = length(J)
4050
while i <= lI || j <= lJ

src/var.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ _vars(v::PolyVar) = [v]
7171

7272
iscomm(::Type{PolyVar{C}}) where {C} = C
7373

74-
function mergevars(varsvec::Vector{Vector{PV}}) where {PV<:PolyVar}
74+
function mergevars_to!(vars::Vector{PV}, varsvec::Vector{Vector{PV}}) where {PV<:PolyVar}
75+
empty!(vars)
7576
n = length(varsvec)
7677
is = ones(Int, n)
7778
maps = zeros.(Int, length.(varsvec))
7879
nonempty = BitSet(findall(!isempty, varsvec))
79-
vars = Vector{PV}()
8080
while !isempty(nonempty)
8181
imin = 0
8282
for i in nonempty
@@ -97,5 +97,10 @@ function mergevars(varsvec::Vector{Vector{PV}}) where {PV<:PolyVar}
9797
end
9898
end
9999
end
100-
vars, maps
100+
return maps
101+
end
102+
function mergevars(varsvec::Vector{Vector{PV}}) where {PV<:PolyVar}
103+
vars = PV[]
104+
maps = mergevars_to!(vars, varsvec)
105+
return vars, maps
101106
end

0 commit comments

Comments
 (0)