Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix method ambiguity for * between Adjoint or Transpose and BlockDiagonal with different eltype #122

Merged
merged 7 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BlockDiagonals"
uuid = "0a1fb500-61f7-11e9-3c65-f5ef3456f9f0"
authors = ["Invenia Technical Computing Corporation"]
version = "0.1.39"
version = "0.1.40"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
4 changes: 2 additions & 2 deletions src/base_maths.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ function Base.:*(M::Diagonal{T}, B::BlockDiagonal{T2})::BlockDiagonal where {T,
return A
end

function Base.:*(vt::Adjoint{T,<: AbstractVector}, B::BlockDiagonal{T}) where {T}
function Base.:*(vt::Adjoint{T,<: AbstractVector}, B::BlockDiagonal{T2, V}) where V<:AbstractMatrix{T2} where {T, T2}
mjp98 marked this conversation as resolved.
Show resolved Hide resolved
return (B' * parent(vt))'
end

function Base.:*(vt::Transpose{T,<: AbstractVector}, B::BlockDiagonal{T}) where {T}
function Base.:*(vt::Transpose{T,<: AbstractVector}, B::BlockDiagonal{T2, V}) where V<:AbstractMatrix{T2} where {T, T2}
return transpose(transpose(B) * parent(vt))
end

Expand Down
4 changes: 4 additions & 0 deletions test/base_maths.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ using Test
b64 = BlockDiagonal([rand(rng, 2, 2), rand(rng, 2, 2)])
b32 = BlockDiagonal([rand(rng, Float32, 2, 2), rand(rng, Float32, 2, 2)])

bi = BlockDiagonal([zeros(Int, N1, N1), zeros(Int, N2, N2), zeros(Int, N3, N3)])

bns = BlockDiagonal([rand(rng, N1, N2), rand(rng, N2, N3), rand(rng, N3, N1)])

@testset "Addition" begin
Expand Down Expand Up @@ -120,6 +122,8 @@ using Test
@test transpose(a) * b1 isa Transpose{<:Number, <:Vector}
@test a' * b1 ≈ a' * Matrix(b1)
@test transpose(a) * b1 ≈ transpose(a) * Matrix(b1)
# Method ambiguity bug https://github.com/invenia/BlockDiagonals.jl/issues/91
mjp98 marked this conversation as resolved.
Show resolved Hide resolved
@test a' * bi isa Adjoint{<:Number, <:Vector}
end

@testset "BlockDiagonal * Matrix" begin
Expand Down