Skip to content

Commit fe99ce7

Browse files
authored
Adjoint left-multiply (#55)
* test first * fix ambiguity on transpose adjoint * Update Project.toml
1 parent 0f91205 commit fe99ce7

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
name = "BlockDiagonals"
22
uuid = "0a1fb500-61f7-11e9-3c65-f5ef3456f9f0"
33
authors = ["Invenia Technical Computing Corporation"]
4-
version = "0.1.10"
4+
version = "0.1.11"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
88
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010

1111
[compat]
12-
ChainRulesTestUtils = "0.5.8"
1312
ChainRulesCore = "0.9"
13+
ChainRulesTestUtils = "0.5.8"
1414
FillArrays = "0.6, 0.7, 0.8, 0.9, 0.10"
1515
julia = "1"
1616

src/base_maths.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,13 @@ function Base.:*(M::Diagonal, B::BlockDiagonal)::BlockDiagonal
152152
return A
153153
end
154154

155+
function Base.:*(vt::Adjoint{T,<: AbstractVector}, B::BlockDiagonal{T}) where {T}
156+
return (B' * parent(vt))'
157+
end
158+
159+
function Base.:*(vt::Transpose{T,<: AbstractVector}, B::BlockDiagonal{T}) where {T}
160+
return transpose(transpose(B) * parent(vt))
161+
end
162+
155163
## Division
156164
Base.:/(B::BlockDiagonal, n::Number) = BlockDiagonal(blocks(B) ./ n)

test/base_maths.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ using Test
8787
@test b1 * a Matrix(b1) * a
8888
@test_throws DimensionMismatch b1 * b
8989
end
90+
@testset "Vector^T * BlockDiagonal" begin
91+
@test a' * b1 isa Adjoint{<:Number, <:Vector}
92+
@test transpose(a) * b1 isa Transpose{<:Number, <:Vector}
93+
@test a' * b1 a' * Matrix(b1)
94+
@test transpose(a) * b1 transpose(a) * Matrix(b1)
95+
end
9096

9197
@testset "BlockDiagonal * Matrix" begin
9298
@test b1 * A isa Matrix

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using ChainRulesTestUtils
44
using Documenter
55
using FiniteDifferences # For overloading to_vec
66
using Test
7+
using LinearAlgebra
78

89
@testset "BlockDiagonals" begin
910
# The doctests fail on x86, so only run them on 64-bit hardware

0 commit comments

Comments
 (0)