Skip to content

Commit

Permalink
Only add inplace methods for UpperOrLowerTriangular (#196)
Browse files Browse the repository at this point in the history
* Only add inplace methods for UpperOrLowerTriangular

* Don't test against LazyArrays

* Set fail fast to false

* Disambiguate triangular multiplication

* Add missing tests
  • Loading branch information
jishnub authored Jan 9, 2024
1 parent cc0de6e commit d79c989
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
name: ${{ matrix.package.group }}/${{ matrix.package.repo }}/${{ matrix.julia-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
fail-fast: false
matrix:
julia-version: ['1']
os: [ubuntu-latest]
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ArrayLayouts"
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
authors = ["Sheehan Olver <[email protected]>"]
version = "1.5.1"
version = "1.5.2"

[deps]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand Down
34 changes: 33 additions & 1 deletion src/mul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ macro layoutmul(Typ)
(*)(A::$Typ, B::LinearAlgebra.$Struc) = ArrayLayouts.mul(A,B)
end
end
for Mod in (:Adjoint, :Transpose, :Symmetric, :Hermitian, :UpperOrLowerTriangular)
for Mod in (:Adjoint, :Transpose, :Symmetric, :Hermitian)
ret = quote
$ret

Expand Down Expand Up @@ -297,6 +297,37 @@ macro layoutmul(Typ)
end
end

ret = quote
$ret

LinearAlgebra.mul!(dest::AbstractMatrix, A::$Typ, b::UpperOrLowerTriangular) =
ArrayLayouts.mul!(dest,A,b)
LinearAlgebra.mul!(dest::AbstractMatrix, A::UpperOrLowerTriangular, b::$Typ) =
ArrayLayouts.mul!(dest,A,b)
LinearAlgebra.mul!(dest::AbstractVector, A::UpperOrLowerTriangular{<:Any,<:$Typ}, b::AbstractVector) =
ArrayLayouts.mul!(dest,A,b)
LinearAlgebra.mul!(dest::AbstractVector, A::UpperOrLowerTriangular{<:Any,<:$Typ}, b::AbstractVector, α::Number, β::Number) =
ArrayLayouts.mul!(dest,A,b,α,β)
LinearAlgebra.mul!(dest::AbstractMatrix, A::UpperOrLowerTriangular{<:Any,<:$Typ}, B::AbstractMatrix, α::Number, β::Number) =
ArrayLayouts.mul!(dest,A,B,α,β)
LinearAlgebra.mul!(dest::AbstractMatrix, A::UpperOrLowerTriangular{<:Any,<:$Typ}, B::UpperOrLowerTriangular, α::Number, β::Number) =
ArrayLayouts.mul!(dest,A,B,α,β)
LinearAlgebra.mul!(dest::AbstractMatrix, A::AbstractMatrix, B::UpperOrLowerTriangular{<:Any,<:$Typ}, α::Number, β::Number) =
ArrayLayouts.mul!(dest,A,B,α,β)
LinearAlgebra.mul!(dest::AbstractMatrix, A::UpperOrLowerTriangular, B::UpperOrLowerTriangular{<:Any,<:$Typ}, α::Number, β::Number) =
ArrayLayouts.mul!(dest,A,B,α,β)
LinearAlgebra.mul!(dest::AbstractMatrix, A::UpperOrLowerTriangular{<:Any,<:$Typ}, B::$Typ, α::Number, β::Number) =
ArrayLayouts.mul!(dest,A,B,α,β)
LinearAlgebra.mul!(dest::AbstractMatrix, A::$Typ, B::UpperOrLowerTriangular{<:Any,<:$Typ}, α::Number, β::Number) =
ArrayLayouts.mul!(dest,A,B,α,β)
LinearAlgebra.mul!(dest::AbstractMatrix, A::UpperOrLowerTriangular, B::$Typ, α::Number, β::Number) =
ArrayLayouts.mul!(dest,A,B,α,β)
LinearAlgebra.mul!(dest::AbstractMatrix, A::$Typ, B::UpperOrLowerTriangular, α::Number, β::Number) =
ArrayLayouts.mul!(dest,A,B,α,β)
LinearAlgebra.mul!(dest::AbstractMatrix, A::UpperOrLowerTriangular{<:Any,<:$Typ}, B::UpperOrLowerTriangular{<:Any,<:$Typ}, α::Number, β::Number) =
ArrayLayouts.mul!(dest,A,B,α,β)

end
esc(ret)
end

Expand All @@ -316,6 +347,7 @@ end
*(x::TransposeAbsVec{<:Any,<:Zeros{<:Any,1}}, D::Diagonal, y::LayoutVector) = FillArrays._triple_zeromul(x, D, y)


*(A::UpperOrLowerTriangular{<:Any,<:LayoutMatrix}, B::UpperOrLowerTriangular{<:Any,<:LayoutMatrix}) = mul(A, B)
*(A::UpperOrLowerTriangular{<:Any,<:AdjOrTrans{<:Any,<:LayoutMatrix}}, B::UpperOrLowerTriangular{<:Any,<:LayoutMatrix}) = mul(A, B)
*(A::UpperOrLowerTriangular{<:Any,<:LayoutMatrix}, B::UpperOrLowerTriangular{<:Any,<:AdjOrTrans{<:Any,<:LayoutMatrix}}) = mul(A, B)
*(A::UpperOrLowerTriangular{<:Any,<:AdjOrTrans{<:Any,<:LayoutMatrix}}, B::UpperOrLowerTriangular{<:Any,<:AdjOrTrans{<:Any,<:LayoutMatrix}}) = mul(A, B)
Expand Down
32 changes: 32 additions & 0 deletions test/test_layoutarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,38 @@ MemoryLayout(::Type{MyVector}) = DenseColumnMajor()
end
end

@testset "mul involving a triangular" begin
A = MyMatrix(rand(4,4))
UA = UpperTriangular(A)
MA = Matrix(A)
MUA = Matrix(UA)
B = rand(4,4)
UB = UpperTriangular(B)
@test mul!(zeros(4,4), A, UB) MA * UB
@test mul!(ones(4,4), A, UB, 2, 2) 2 * MA * UB .+ 2
@test mul!(zeros(4,4), UA, B) MUA * B
@test mul!(ones(4,4), UA, B, 2, 2) 2 * MUA * B .+ 2
@test mul!(zeros(4,4), UA, UB) MUA * UB
@test mul!(ones(4,4), UA, UB, 2, 2) 2 * MUA * UB .+ 2
@test mul!(zeros(4,4), UB, A) UB * MA
@test mul!(ones(4,4), UB, A, 2, 2) 2 * UB * MA .+ 2
@test mul!(zeros(4,4), UB, UA) UB * MUA
@test mul!(ones(4,4), UB, UA, 2, 2) 2 * UB * MUA .+ 2
@test mul!(zeros(4,4), B, UA) B * MUA
@test mul!(ones(4,4), B, UA, 2, 2) 2 * B * MUA .+ 2
@test mul!(zeros(4,4), A, UA) MA * MUA
@test mul!(ones(4,4), A, UA, 2, 2) 2 * MA * MUA .+ 2
@test mul!(zeros(4,4), UA, A) MUA * MA
@test mul!(ones(4,4), UA, A, 2, 2) 2 * MUA * MA .+ 2
@test mul!(zeros(4,4), UA, UA) MUA * MUA
@test mul!(ones(4,4), UA, UA, 2, 2) 2 * MUA * MUA .+ 2


v = rand(4)
@test mul!(zeros(4), UA, v) MUA * v
@test mul!(ones(4), UA, v, 2, 2) 2 * MUA * v .+ 2
end

struct MyUpperTriangular{T} <: AbstractMatrix{T}
A::UpperTriangular{T,Matrix{T}}
end
Expand Down
1 change: 0 additions & 1 deletion test/test_muladd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,6 @@ Random.seed!(0)
x :: T
sz :: NTuple{2,Int}
end
MFillMat(x::T, sz::NTuple{2,Int}) where {T} = MFillMat{T}(x, sz)
MFillMat(x::T, sz::Vararg{Int,2}) where {T} = MFillMat{T}(x, sz)
Base.size(M::MFillMat) = M.sz
FillArrays.getindex_value(M::MFillMat) = M.x
Expand Down

2 comments on commit d79c989

@jishnub
Copy link
Member Author

@jishnub jishnub commented on d79c989 Jan 9, 2024

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/98516

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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 v1.5.2 -m "<description of version>" d79c989c33416b14203bd108dd7f0db7a52ff162
git push origin v1.5.2

Please sign in to comment.