Skip to content

Commit 932b020

Browse files
authored
Merge pull request #113 from invenia/mz/subtraction
implement faster subtraction
2 parents 6223d3f + e754c0f commit 932b020

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BlockDiagonals"
22
uuid = "0a1fb500-61f7-11e9-3c65-f5ef3456f9f0"
33
authors = ["Invenia Technical Computing Corporation"]
4-
version = "0.1.35"
4+
version = "0.1.36"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/base_maths.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ end
6666
## Subtraction
6767
Base.:-(B::BlockDiagonal) = BlockDiagonal(.-(blocks(B)))
6868
Base.:-(M::AbstractMatrix, B::BlockDiagonal) = M + -B
69+
Base.:-(B::BlockDiagonal, M::AbstractMatrix) = -M + B
70+
Base.:-(B::BlockDiagonal, B2::BlockDiagonal) = B + (-B2)
6971

7072
## Multiplication
7173
Base.:*(n::Number, B::BlockDiagonal) = B * n

test/base_maths.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ using Test
7676

7777
@test -b1 == -Matrix(b1)
7878
@test b1 - b1 == Matrix(b1) - Matrix(b1)
79+
@test Matrix(b1) - b2 == Matrix(b1) - Matrix(b2)
80+
@test b1 - Matrix(b2) == Matrix(b1) - Matrix(b2)
7981
end
8082

8183
@testset "Multiplication" begin

0 commit comments

Comments
 (0)