Skip to content

Commit a1eda83

Browse files
authored
Fix promote_operation for * with rationals (#261)
* Fix promote_operation for * with rationals * Fix format
1 parent bac5c24 commit a1eda83

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/promote.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,30 @@ function MA.promote_operation(
300300
) where {T,P<:_APL}
301301
return promote_operation_constant(*, P, T)
302302
end
303+
304+
function MA.promote_operation(
305+
::typeof(*),
306+
::Type{P},
307+
::Type{RationalPoly{NT,DT}},
308+
) where {P<:APL,NT,DT}
309+
return RationalPoly{MA.promote_operation(*, P, NT),DT}
310+
end
311+
312+
function MA.promote_operation(
313+
::typeof(*),
314+
::Type{RationalPoly{NT,DT}},
315+
::Type{P},
316+
) where {P<:APL,NT,DT}
317+
return RationalPoly{MA.promote_operation(*, NT, P),DT}
318+
end
319+
320+
function MA.promote_operation(
321+
::typeof(*),
322+
::Type{RationalPoly{NS,DS}},
323+
::Type{RationalPoly{NT,DT}},
324+
) where {NS,DS,NT,DT}
325+
return RationalPoly{
326+
MA.promote_operation(*, NS, NT),
327+
MA.promote_operation(*, DS, DT),
328+
}
329+
end

test/promote.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,34 @@ Base.:+(::C, ::C) = C()
118118
@test MA.promote_operation(*, A, polynomial_type(x, A)) ==
119119
polynomial_type(x, B)
120120
end
121+
122+
function __promote_prod(::Type{A}, ::Type{B}, ::Type{C}) where {A,B,C}
123+
@test MA.promote_operation(*, A, B) == C
124+
@test MA.promote_operation(*, B, A) == C
125+
end
126+
127+
@testset "promote_operation with Rational" begin
128+
Mod.@polyvar x
129+
V = typeof(x)
130+
M = monomial_type(V)
131+
T = term_type(V, Int)
132+
P = polynomial_type(V, Float64)
133+
function _promote_prod(::Type{A}, ::Type{B}, ::Type{C}) where {A,B,C}
134+
__promote_prod(A, B, C)
135+
__promote_prod(RationalPoly{A,B}, RationalPoly{B,A}, RationalPoly{C,C})
136+
__promote_prod(RationalPoly{A,A}, RationalPoly{B,B}, RationalPoly{C,C})
137+
for U in [V, M, T, P]
138+
__promote_prod(A, RationalPoly{B,U}, RationalPoly{C,U})
139+
end
140+
end
141+
_promote_prod(V, V, M)
142+
for U in [V, M]
143+
_promote_prod(U, M, M)
144+
end
145+
for U in [V, M, T]
146+
_promote_prod(U, T, T)
147+
end
148+
for U in [V, M, T, P]
149+
_promote_prod(U, P, P)
150+
end
151+
end

0 commit comments

Comments
 (0)