Skip to content

Commit 96a1c48

Browse files
authored
Fix dot product between Rational{Int} and Rational{BigInt} (#322)
* Add promotion on gcd and lcm for BigInt * Fix dot product between Rational{Int} and Rational{BigInt} * Fix * Fix format
1 parent b38696f commit 96a1c48

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/implementations/BigInt.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,14 @@ _scaling_to_bigint(x) = _scaling_to(BigInt, x)
182182

183183
function operate_to!(
184184
output::BigInt,
185-
op::Union{typeof(+),typeof(-),typeof(*)},
185+
op::Union{
186+
typeof(+),
187+
typeof(-),
188+
typeof(*),
189+
typeof(div),
190+
typeof(gcd),
191+
typeof(lcm),
192+
},
186193
args::Vararg{Scaling,N},
187194
) where {N}
188195
return operate_to!(output, op, _scaling_to_bigint.(args)...)

src/implementations/Rational.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function buffer_for(
178178
::Type{Rational{T}},
179179
) where {S,T}
180180
U = promote_operation(gcd, S, T)
181-
return zero(Rational{S}), zero(Rational{T}), zero(U)
181+
return zero(Rational{U}), zero(Rational{U}), zero(U)
182182
end
183183

184184
function buffered_operate_to!(

test/interface.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ end
123123
@test a !== b
124124
end
125125
end
126+
@testset "dot" for U in (Int, BigInt, Rational{Int}, Rational{BigInt})
127+
y = U(5)
128+
a = LinearAlgebra.dot(x, y)
129+
b = MA.operate(LinearAlgebra.dot, [x], [y])
130+
@test a == b
131+
if MA.mutability(
132+
promote_type(T, U),
133+
LinearAlgebra.dot,
134+
Vector{T},
135+
Vector{U},
136+
) == MA.IsMutable()
137+
@test a !== b
138+
end
139+
end
126140
end
127141
end
128142

0 commit comments

Comments
 (0)