Skip to content

Commit

Permalink
Fix method ambiguity for * between Adjoint or Transpose and `Bl…
Browse files Browse the repository at this point in the history
…ockDiagonal` with different eltype (#122)

* Add erroring test

* Edit comment

* Add fix

* Bump version

* Avoid specifying type parameters where possible

Co-authored-by: Daniel Karrasch <Daniel.Karrasch@gmx.de>

* Avoid specifying type parameters for `*Transpose`

* Make issue description in comment more specific

Co-authored-by: Miha Zgubic <mzgubic@users.noreply.github.com>

Co-authored-by: Daniel Karrasch <Daniel.Karrasch@gmx.de>
Co-authored-by: Miha Zgubic <mzgubic@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 15, 2022
1 parent 86c57e3 commit 3ac9c89
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
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{<:Any,<:AbstractVector}, B::BlockDiagonal)
return (B' * parent(vt))'
end

function Base.:*(vt::Transpose{T,<: AbstractVector}, B::BlockDiagonal{T}) where {T}
function Base.:*(vt::Transpose{<:Any,<:AbstractVector}, B::BlockDiagonal)
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 with different eltypes https://github.com/invenia/BlockDiagonals.jl/issues/91
@test a' * bi isa Adjoint{<:Number, <:Vector}
end

@testset "BlockDiagonal * Matrix" begin
Expand Down

2 comments on commit 3ac9c89

@mjp98
Copy link
Contributor Author

@mjp98 mjp98 commented on 3ac9c89 Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/72235

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.40 -m "<description of version>" 3ac9c89ea9e81eda00fc8fcbc8710713d960b1c2
git push origin v0.1.40

Please sign in to comment.