Skip to content

Commit 874797d

Browse files
authored
Diagonal ambiguities (#172)
* Diagonal ambiguities * add tests * add Sub * Diagonal
1 parent 60ae8dd commit 874797d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-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 = "ArrayLayouts"
22
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "1.3.0"
4+
version = "1.3.1"
55

66
[deps]
77
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"

src/mul.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,17 @@ end
321321
# mul! for subarray of layout matrix
322322
const SubLayoutMatrix = Union{SubArray{<:Any,2,<:LayoutMatrix}, SubArray{<:Any,2,<:AdjOrTrans{<:Any,<:LayoutMatrix}}}
323323

324+
*(A::Diagonal, B::SubLayoutMatrix) = mul(A, B)
325+
*(A::SubLayoutMatrix, B::Diagonal) = mul(A, B)
326+
324327
LinearAlgebra.mul!(C::AbstractMatrix, A::SubLayoutMatrix, B::AbstractMatrix, α::Number, β::Number) =
325328
ArrayLayouts.mul!(C, A, B, α, β)
326329
LinearAlgebra.mul!(C::AbstractMatrix, A::AbstractMatrix, B::SubLayoutMatrix, α::Number, β::Number) =
327330
ArrayLayouts.mul!(C, A, B, α, β)
331+
LinearAlgebra.mul!(C::AbstractMatrix, A::Diagonal, B::SubLayoutMatrix, α::Number, β::Number) =
332+
ArrayLayouts.mul!(C, A, B, α, β)
333+
LinearAlgebra.mul!(C::AbstractMatrix, A::SubLayoutMatrix, B::Diagonal, α::Number, β::Number) =
334+
ArrayLayouts.mul!(C, A, B, α, β)
328335
LinearAlgebra.mul!(C::AbstractMatrix, A::SubLayoutMatrix, B::LayoutMatrix, α::Number, β::Number) =
329336
ArrayLayouts.mul!(C, A, B, α, β)
330337
LinearAlgebra.mul!(C::AbstractMatrix, A::LayoutMatrix, B::SubLayoutMatrix, α::Number, β::Number) =

test/test_layoutarray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ MemoryLayout(::Type{MyVector}) = DenseColumnMajor()
508508
V = view(A, 1:3, 1:3)
509509
B = randn(3,3)
510510
x = randn(3)
511+
D = Diagonal(1:3)
512+
511513
@test mul!(similar(B), V, B) A * B
512514
@test mul!(similar(B), B, V) B * A
513515
@test mul!(similar(B), V, V) A^2
@@ -524,6 +526,10 @@ MemoryLayout(::Type{MyVector}) = DenseColumnMajor()
524526
@test mul!(MyMatrix(copy(B)), A, V, 2.0, 3.0) 2A * A + 3B
525527
@test mul!(copy(x), V, x, 2.0, 3.0) 2A * x + 3x
526528

529+
@test D * V == D * A == D * A.A
530+
@test V * D == A * D == A.A * D
531+
@test mul!(copy(B), D, A, 2.0, 3.0) mul!(copy(B), D, V, 2.0, 3.0) 2D * A + 3B
532+
@test mul!(copy(B), A, D, 2.0, 3.0) mul!(copy(B), V, D, 2.0, 3.0) 2A * D + 3B
527533
end
528534
end
529535

0 commit comments

Comments
 (0)