Skip to content

Commit

Permalink
Fix dot product between Rational{Int} and Rational{BigInt} (#322)
Browse files Browse the repository at this point in the history
* Add promotion on gcd and lcm for BigInt

* Fix dot product between Rational{Int} and Rational{BigInt}

* Fix

* Fix format
  • Loading branch information
blegat authored Jan 15, 2025
1 parent b38696f commit 96a1c48
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/implementations/BigInt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,14 @@ _scaling_to_bigint(x) = _scaling_to(BigInt, x)

function operate_to!(
output::BigInt,
op::Union{typeof(+),typeof(-),typeof(*)},
op::Union{
typeof(+),
typeof(-),
typeof(*),
typeof(div),
typeof(gcd),
typeof(lcm),
},
args::Vararg{Scaling,N},
) where {N}
return operate_to!(output, op, _scaling_to_bigint.(args)...)
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/Rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function buffer_for(
::Type{Rational{T}},
) where {S,T}
U = promote_operation(gcd, S, T)
return zero(Rational{S}), zero(Rational{T}), zero(U)
return zero(Rational{U}), zero(Rational{U}), zero(U)
end

function buffered_operate_to!(
Expand Down
14 changes: 14 additions & 0 deletions test/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ end
@test a !== b
end
end
@testset "dot" for U in (Int, BigInt, Rational{Int}, Rational{BigInt})
y = U(5)
a = LinearAlgebra.dot(x, y)
b = MA.operate(LinearAlgebra.dot, [x], [y])
@test a == b
if MA.mutability(
promote_type(T, U),
LinearAlgebra.dot,
Vector{T},
Vector{U},
) == MA.IsMutable()
@test a !== b
end
end
end
end

Expand Down

0 comments on commit 96a1c48

Please sign in to comment.