Skip to content

Commit edc74eb

Browse files
authored
Fix promotion with polynomial coefficient (#266)
* Fix promotion with polynomial coefficient * Fix * Fix tests
1 parent 07e7f8f commit edc74eb

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/promote.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function MA.promote_operation(
241241
) where {S,T}
242242
UT = MA.promote_operation(*, monomial_type(TT), monomial_type(ST))
243243
U = MA.promote_operation(*, S, T)
244-
return promote_operation_constant(*, U, UT)
244+
return promote_operation_left_constant(*, U, UT)
245245
end
246246
function MA.promote_operation(
247247
::typeof(*),
@@ -250,34 +250,34 @@ function MA.promote_operation(
250250
) where {S,T}
251251
UP = MA.promote_operation(*, monomial_type(PT), monomial_type(QT))
252252
U = MA.promote_sum_mul(S, T)
253-
return polynomial_type(promote_operation_constant(*, U, UP))
253+
return polynomial_type(promote_operation_left_constant(*, U, UP))
254254
end
255255

256-
function promote_operation_constant(
256+
function promote_operation_left_constant(
257257
::typeof(*),
258258
::Type{T},
259259
::Type{M},
260260
) where {T,M<:AbstractMonomialLike}
261261
return term_type(M, T)
262262
end
263263

264-
function promote_operation_constant(
264+
function promote_operation_right_constant(
265265
::typeof(*),
266266
::Type{M},
267267
::Type{T},
268268
) where {T,M<:AbstractMonomialLike}
269269
return term_type(M, T)
270270
end
271271

272-
function promote_operation_constant(
272+
function promote_operation_left_constant(
273273
::typeof(*),
274274
::Type{T},
275275
::Type{P},
276276
) where {T,U,P<:_APL{U}}
277277
return similar_type(P, MA.promote_operation(*, T, U))
278278
end
279279

280-
function promote_operation_constant(
280+
function promote_operation_right_constant(
281281
::typeof(*),
282282
::Type{P},
283283
::Type{T},
@@ -290,15 +290,15 @@ function MA.promote_operation(
290290
::Type{T},
291291
::Type{P},
292292
) where {T,P<:_APL}
293-
return promote_operation_constant(*, T, P)
293+
return promote_operation_left_constant(*, T, P)
294294
end
295295

296296
function MA.promote_operation(
297297
::typeof(*),
298298
::Type{P},
299299
::Type{T},
300300
) where {T,P<:_APL}
301-
return promote_operation_constant(*, P, T)
301+
return promote_operation_right_constant(*, P, T)
302302
end
303303

304304
function MA.promote_operation(

test/promote.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,25 @@ end
149149
_promote_prod(U, P, P)
150150
end
151151
end
152+
153+
@testset "promote_operation with polynomial coefficient" begin
154+
Mod.@polyvar x
155+
Mod.@polyvar y
156+
X = typeof(x)
157+
MX = monomial_type(X)
158+
TX = term_type(X, Int)
159+
PX = polynomial_type(X, Int)
160+
Y = typeof(y)
161+
TXY = term_type(Y, PX)
162+
PXY = polynomial_type(Y, PX)
163+
TY = term_type(Y, Int)
164+
PY = polynomial_type(Y, Int)
165+
for T in [X, MX, TX, PX]
166+
__promote_prod(TY, TY, TY)
167+
__promote_prod(TXY, TY, TXY)
168+
__promote_prod(TXY, TXY, TXY)
169+
__promote_prod(PY, PY, PY)
170+
__promote_prod(PXY, PY, PXY)
171+
__promote_prod(PXY, PXY, PXY)
172+
end
173+
end

0 commit comments

Comments
 (0)