From fc9a3f1461a2de3a5e0adcecc08381ac417dfbdd Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Sun, 3 Sep 2023 17:42:46 +0200 Subject: [PATCH 1/5] Fix some method signatures related AbstractQ's --- Project.toml | 2 +- src/blockmap.jl | 6 +++--- src/fillmap.jl | 2 +- src/getindex.jl | 2 +- src/uniformscalingmap.jl | 4 ++-- src/wrappedmap.jl | 16 ++++++++-------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Project.toml b/Project.toml index e5047262..5f295ea9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "LinearMaps" uuid = "7a12625a-238d-50fd-b39a-03d52299707e" -version = "3.11.0" +version = "3.11.1" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" diff --git a/src/blockmap.jl b/src/blockmap.jl index 874ee543..4d68d9ab 100644 --- a/src/blockmap.jl +++ b/src/blockmap.jl @@ -81,7 +81,7 @@ julia> L * ones(Int, 6) 6 ``` """ -function Base.hcat(As::Union{LinearMap, UniformScaling, AbstractVecOrMatOrQ}...) +function Base.hcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) T = promote_type(map(eltype, As)...) nbc = length(As) @@ -119,7 +119,7 @@ julia> L * ones(Int, 3) 3 ``` """ -function Base.vcat(As::Union{LinearMap,UniformScaling,AbstractVecOrMatOrQ}...) +function Base.vcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) T = promote_type(map(eltype, As)...) nbr = length(As) @@ -165,7 +165,7 @@ julia> L * ones(Int, 6) Base.hvcat function Base.hvcat(rows::Tuple{Vararg{Int}}, - As::Union{LinearMap, UniformScaling, AbstractVecOrMatOrQ}...) + As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) nr = length(rows) T = promote_type(map(eltype, As)...) sum(rows) == length(As) || diff --git a/src/fillmap.jl b/src/fillmap.jl index a527850b..2903cc6f 100644 --- a/src/fillmap.jl +++ b/src/fillmap.jl @@ -18,7 +18,7 @@ FillMap(λ, m::Int, n::Int) = FillMap(λ, (m, n)) # properties Base.size(A::FillMap) = A.size -MulStyle(A::FillMap) = FiveArg() +MulStyle(::FillMap) = FiveArg() LinearAlgebra.issymmetric(A::FillMap) = A.size[1] == A.size[2] LinearAlgebra.ishermitian(A::FillMap) = isreal(A.λ) && A.size[1] == A.size[2] LinearAlgebra.isposdef(A::FillMap) = (size(A, 1) == size(A, 2) == 1 && isposdef(A.λ)) diff --git a/src/getindex.jl b/src/getindex.jl index bffacc45..f88535a2 100644 --- a/src/getindex.jl +++ b/src/getindex.jl @@ -47,7 +47,7 @@ _getindex(A::LinearMap, I::Indexer, J::Indexer) = error("partial two-dimensional slicing of LinearMaps is not supported, consider using A[:,J][I] or A[I,:][J] instead") _getindex(A::LinearMap, ::Base.Slice, j::Integer) = A*unitvec(A, 2, j) -function _getindex(A::LinearMap, i::Integer, J::Base.Slice) +function _getindex(A::LinearMap, i::Integer, ::Base.Slice) try # requires adjoint action to be defined return vec(unitvec(A, 1, i)'A) diff --git a/src/uniformscalingmap.jl b/src/uniformscalingmap.jl index 86d6ba2a..d162c840 100644 --- a/src/uniformscalingmap.jl +++ b/src/uniformscalingmap.jl @@ -42,9 +42,9 @@ Base.:(*)(J::UniformScalingMap, α::RealOrComplex) = UniformScalingMap(J.λ * α Base.:(*)(J::UniformScalingMap, x::AbstractVector) = length(x) == J.M ? J.λ * x : throw(DimensionMismatch("*")) # multiplication with matrix -Base.:(*)(J::UniformScalingMap, B::AbstractMatrix) = +Base.:(*)(J::UniformScalingMap, B::Union{AbstractMatrix,AbstractQ}) = size(B, 1) == J.M ? J.λ * LinearMap(B) : throw(DimensionMismatch("*")) -Base.:(*)(A::AbstractMatrix, J::UniformScalingMap) = +Base.:(*)(A::Union{AbstractMatrix,AbstractQ}, J::UniformScalingMap) = size(A, 2) == J.M ? LinearMap(A) * J.λ : throw(DimensionMismatch("*")) # disambiguation Base.:(*)(xc::LinearAlgebra.AdjointAbsVec, J::UniformScalingMap) = xc * J.λ diff --git a/src/wrappedmap.jl b/src/wrappedmap.jl index abe9bafa..e5f2d220 100644 --- a/src/wrappedmap.jl +++ b/src/wrappedmap.jl @@ -108,13 +108,13 @@ _unsafe_mul!(Y, A::VecOrMatMap, s::Number) = _unsafe_mul!(Y, A.lmap, s) _unsafe_mul!(Y, A::VecOrMatMap, s::Number, α, β) = _unsafe_mul!(Y, A.lmap, s, α, β) # combine LinearMap and Matrix objects: linear combinations and map composition -Base.:(+)(A₁::LinearMap, A₂::AbstractMatrix) = +(A₁, WrappedMap(A₂)) -Base.:(+)(A₁::AbstractMatrix, A₂::LinearMap) = +(WrappedMap(A₁), A₂) -Base.:(-)(A₁::LinearMap, A₂::AbstractMatrix) = -(A₁, WrappedMap(A₂)) -Base.:(-)(A₁::AbstractMatrix, A₂::LinearMap) = -(WrappedMap(A₁), A₂) +Base.:(+)(A₁::LinearMap, A₂::Union{AbstractMatrix,AbstractQ}) = +(A₁, WrappedMap(A₂)) +Base.:(+)(A₁::Union{AbstractMatrix,AbstractQ}, A₂::LinearMap) = +(WrappedMap(A₁), A₂) +Base.:(-)(A₁::LinearMap, A₂::Union{AbstractMatrix,AbstractQ}) = -(A₁, WrappedMap(A₂)) +Base.:(-)(A₁::Union{AbstractMatrix,AbstractQ}, A₂::LinearMap) = -(WrappedMap(A₁), A₂) """ - *(A::LinearMap, X::AbstractMatrix)::CompositeMap + *(A::LinearMap, X::Union{AbstractMatrix,AbstractQ})::CompositeMap Return the `CompositeMap` `A*LinearMap(X)`, interpreting the matrix `X` as a linear operator, rather than a collection of column vectors. To compute the action of `A` on each @@ -129,10 +129,10 @@ julia> A*X isa LinearMaps.CompositeMap true ``` """ -Base.:(*)(A₁::LinearMap, A₂::AbstractMatrix) = *(A₁, WrappedMap(A₂)) +Base.:(*)(A₁::LinearMap, A₂::Union{AbstractMatrix,AbstractQ}) = *(A₁, WrappedMap(A₂)) """ - *(X::AbstractMatrix, A::LinearMap)::CompositeMap + *(X::Union{AbstractMatrix,AbstractQ}, A::LinearMap)::CompositeMap Return the `CompositeMap` `LinearMap(X)*A`, interpreting the matrix `X` as a linear operator. To compute the right-action of `A` on each row of `X`, call `Matrix(X*A)` @@ -146,4 +146,4 @@ julia> X*A isa LinearMaps.CompositeMap true ``` """ -Base.:(*)(A₁::AbstractMatrix, A₂::LinearMap) = *(WrappedMap(A₁), A₂) +Base.:(*)(A₁::Union{AbstractMatrix,AbstractQ}, A₂::LinearMap) = *(WrappedMap(A₁), A₂) From bef3019dcc77e755e29cdd0d077e0b35c85bf8df Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Tue, 5 Sep 2023 13:03:08 +0200 Subject: [PATCH 2/5] bump compat bound for Aqua.jl in tests --- test/Project.toml | 2 +- test/runtests.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Project.toml b/test/Project.toml index c3704248..0c247860 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -13,7 +13,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] -Aqua = "0.5, 0.6" +Aqua = "0.5, 0.6, 0.7" BlockArrays = "0.16" ChainRulesCore = "1" ChainRulesTestUtils = "1.9" diff --git a/test/runtests.jl b/test/runtests.jl index bde3fd94..28a43d47 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,7 +1,7 @@ using Test, LinearMaps, Aqua @testset "code quality" begin - Aqua.test_all(LinearMaps, project_toml_formatting=VERSION≥v"1.7") + Aqua.test_all(LinearMaps, project_toml_formatting = VERSION≥v"1.7", piracy = VERSION≥v"1.9") end include("linearmaps.jl") From 4c46abb88aacd1ad548c993463d4bd4658591a3d Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Thu, 7 Sep 2023 13:27:58 +0200 Subject: [PATCH 3/5] keep old signatures for v1.9-, have new signatures on v.10+ --- src/blockmap.jl | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/blockmap.jl b/src/blockmap.jl index 4d68d9ab..767240a5 100644 --- a/src/blockmap.jl +++ b/src/blockmap.jl @@ -81,7 +81,14 @@ julia> L * ones(Int, 6) 6 ``` """ -function Base.hcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) +Base.hcat + +if VERSION < v"1.10-" + Base.hcat(As::Union{LinearMap, UniformScaling, AbstractVecOrMatOrQ}...) = _hcat(As...) +else + Base.hcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) = _hcat(As...) +end +function _hcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) T = promote_type(map(eltype, As)...) nbc = length(As) @@ -119,7 +126,15 @@ julia> L * ones(Int, 3) 3 ``` """ -function Base.vcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) +Base.vcat + +if VERSION < v"1.10-" + Base.vcat(As::Union{LinearMap, UniformScaling, AbstractVecOrMatOrQ}...) = _vcat(As...) +else + Base.vcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) = _vcat(As...) +end + +function _vcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) T = promote_type(map(eltype, As)...) nbr = length(As) @@ -164,7 +179,15 @@ julia> L * ones(Int, 6) """ Base.hvcat -function Base.hvcat(rows::Tuple{Vararg{Int}}, +if VERSION < v"1.10-" + Base.hvcat(rows::Tuple{Vararg{Int}}, As::Union{LinearMap, UniformScaling, AbstractVecOrMatOrQ}...) = + _hvcat(rows, As...) +else + Base.hvcat(rows::Tuple{Vararg{Int}}, As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) = + _hvcat(rows, As...) +end + +function _hvcat(rows::Tuple{Vararg{Int}}, As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) nr = length(rows) T = promote_type(map(eltype, As)...) From 454e4f24d6f597198ef681994f6df870601d7e4c Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Wed, 27 Sep 2023 19:33:16 +0200 Subject: [PATCH 4/5] fix signature --- src/left.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/left.jl b/src/left.jl index 90159efa..f2bf2ea0 100644 --- a/src/left.jl +++ b/src/left.jl @@ -92,7 +92,7 @@ julia> mul!(C, A, B, 1, 1) 5.0 7.0 ``` """ -function mul!(X::AbstractMatrix, Y::AbstractMatrix, A::LinearMap, α, β) +function mul!(X::AbstractMatrix, Y::AbstractMatrix, A::LinearMap, α::Number, β::Number) check_dim_mul(X, Y, A) _unsafe_mul!(X, Y, A, α, β) end From 715bee678032ca187de4f1e30d30555289401b5a Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Thu, 28 Sep 2023 11:22:17 +0200 Subject: [PATCH 5/5] simplify again --- src/blockmap.jl | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/src/blockmap.jl b/src/blockmap.jl index a95e8d23..1c53db57 100644 --- a/src/blockmap.jl +++ b/src/blockmap.jl @@ -81,14 +81,7 @@ julia> L * ones(Int, 6) 6 ``` """ -Base.hcat - -if VERSION < v"1.10-" - Base.hcat(As::Union{LinearMap, UniformScaling, AbstractVecOrMatOrQ}...) = _hcat(As...) -else - Base.hcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) = _hcat(As...) -end -function _hcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) +function Base.hcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) T = promote_type(map(eltype, As)...) nbc = length(As) @@ -126,15 +119,7 @@ julia> L * ones(Int, 3) 3 ``` """ -Base.vcat - -if VERSION < v"1.10-" - Base.vcat(As::Union{LinearMap, UniformScaling, AbstractVecOrMatOrQ}...) = _vcat(As...) -else - Base.vcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) = _vcat(As...) -end - -function _vcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) +function Base.vcat(As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) T = promote_type(map(eltype, As)...) nbr = length(As) @@ -177,18 +162,7 @@ julia> L * ones(Int, 6) 6 ``` """ -Base.hvcat - -if VERSION < v"1.10-" - Base.hvcat(rows::Tuple{Vararg{Int}}, As::Union{LinearMap, UniformScaling, AbstractVecOrMatOrQ}...) = - _hvcat(rows, As...) -else - Base.hvcat(rows::Tuple{Vararg{Int}}, As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) = - _hvcat(rows, As...) -end - -function _hvcat(rows::Tuple{Vararg{Int}}, - As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) +function Base.hvcat(rows::Tuple{Vararg{Int}}, As::Union{LinearMap, UniformScaling, AbstractArray, AbstractQ}...) nr = length(rows) T = promote_type(map(eltype, As)...) sum(rows) == length(As) ||