From e29a810f29c2458f0450f8100e81e6a898f60e74 Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Tue, 3 Oct 2023 21:51:07 +0200 Subject: [PATCH] Fix some method signatures related AbstractQ's (#211) --- src/blockmap.jl | 9 +++------ src/fillmap.jl | 2 +- src/getindex.jl | 2 +- src/left.jl | 2 +- src/uniformscalingmap.jl | 4 ++-- src/wrappedmap.jl | 16 ++++++++-------- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/blockmap.jl b/src/blockmap.jl index 11430249..1c53db57 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) @@ -162,10 +162,7 @@ julia> L * ones(Int, 6) 6 ``` """ -Base.hvcat - -function Base.hvcat(rows::Tuple{Vararg{Int}}, - As::Union{LinearMap, UniformScaling, AbstractVecOrMatOrQ}...) +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) || 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/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 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₂)