Skip to content

Commit 81a2efc

Browse files
committed
Fixes
1 parent 0175d69 commit 81a2efc

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/cmult.jl

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,19 @@ function _operate_exponents_to!(output::Vector{Int}, op::F, z1::Vector{Int}, z2:
2828
@. output = op(z1, z2)
2929
return
3030
end
31-
function _operate_exponents_to!(output::Vector{Int}, op::F, z1::Vector{Int}, z2::Vector{Int}, n) where {F<:Function}
32-
resize!(output, n)
33-
@. output = op(z1, z2)
34-
return
35-
end
36-
function _operate_exponents_to!(output::Vector{Int}, op::F, z1::Vector{Int}, z2::Vector{Int}, n, maps) where {F<:Function}
37-
resize!(output, n)
31+
function _operate_exponents_to!(output::Vector{Int}, op::F, z1::Vector{Int}, z2::Vector{Int}, maps) where {F<:Function}
3832
I = maps[1]; i = 1; lI = length(I)
3933
J = maps[2]; j = 1; lJ = length(J)
4034
while i <= lI || j <= lJ
4135
if i > lI || (j <= lJ && J[j] < I[i])
4236
output[J[j]] = op(0, z2[j])
4337
j += 1
4438
elseif j > lJ || (i <= lI && I[i] < J[j])
45-
output[I[i]] = op(z1[I[i]], 0)
39+
output[I[i]] = op(z1[i], 0)
4640
i += 1
4741
else
4842
@assert I[i] == J[j]
49-
output[I[i]] = op(z1[I[i]], z2[j])
43+
output[I[i]] = op(z1[i], z2[j])
5044
i += 1
5145
j += 1
5246
end
@@ -57,19 +51,19 @@ end
5751
#function _operate_exponents!(op::F, Z::Vector{Vector{Int}}, z2::Vector{Int}, args::Vararg{Any,N}) where {F<:Function,N}
5852
# return Vector{Int}[_operate_exponents!(op, z, z2, args...) for z in Z]
5953
#end
60-
function multdivmono!(output, output_variables::Vector{PolyVar{true}},
54+
function _multdivmono!(output, output_variables::Vector{PolyVar{true}},
6155
v::Vector{PolyVar{true}}, x::Monomial{true}, op, z)
6256
if v == x.vars
63-
if output_variables == v
64-
_operate_exponents_to!(output, op, z, x.z)
65-
else
57+
if output_variables != v
6658
resize!(output_variables, length(v))
6759
copyto!(output_variables, v)
68-
_operate_exponents_to!(output, op, z, x.z, length(output_variables))
60+
resize!(output, length(output_variables))
6961
end
62+
_operate_exponents_to!(output, op, z, x.z)
7063
else
7164
maps = mergevars_to!(output_variables, [v, x.vars])
72-
_operate_exponents_to!(output, op, z, x.z, length(output_variables), maps)
65+
resize!(output, length(output_variables))
66+
_operate_exponents_to!(output, op, z, x.z, maps)
7367
end
7468
return
7569
end
@@ -110,11 +104,25 @@ function multdivmono(v::Vector{PolyVar{true}}, x::Monomial{true}, op, z)
110104
return w, z_new
111105
end
112106
function MP.mapexponents_to!(output::Monomial{true}, f::Function, x::Monomial{true}, y::Monomial{true})
113-
multdivmono!(output.z, output.vars, x.vars, y, f, x.z)
107+
if x.vars == y.vars
108+
if output.vars != x.vars
109+
n = length(x.vars)
110+
resize!(output.vars, n)
111+
copyto!(output.vars, x.vars)
112+
resize!(output.z, n)
113+
end
114+
_operate_exponents_to!(x.z, f, x.z, y.z)
115+
else
116+
_multdivmono!(output.z, output.vars, x.vars, y, f, x.z)
117+
end
114118
return output
115119
end
116120
function MP.mapexponents!(f::Function, x::Monomial{true}, y::Monomial{true})
117-
multdivmono!(x.z, x.vars, copy(x.vars), y, f, x.z)
121+
if x.vars == y.vars
122+
_operate_exponents_to!(x.z, f, x.z, y.z)
123+
else
124+
_multdivmono!(x.z, x.vars, copy(x.vars), y, f, copy(x.z))
125+
end
118126
return x
119127
end
120128
function MP.mapexponents(f::Function, x::Monomial{true}, y::Monomial{true})

0 commit comments

Comments
 (0)