Skip to content

Commit 7ff2598

Browse files
committed
general edits
1 parent d1e1c73 commit 7ff2598

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/LinearMaps.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ include("composition.jl") # composition of linear maps
243243
include("functionmap.jl") # using a function as linear map
244244
include("blockmap.jl") # block linear maps
245245
include("kronecker.jl") # Kronecker product of linear maps
246+
include("fillmap.jl") # linear maps representing constantly filled matrices
246247
include("conversion.jl") # conversion of linear maps to matrices
247248
include("show.jl") # show methods for LinearMap objects
248249

@@ -283,6 +284,8 @@ LinearMap(f, M::Int; kwargs...) = LinearMap{Float64}(f, M; kwargs...)
283284
LinearMap(f, M::Int, N::Int; kwargs...) = LinearMap{Float64}(f, M, N; kwargs...)
284285
LinearMap(f, fc, M::Int; kwargs...) = LinearMap{Float64}(f, fc, M; kwargs...)
285286
LinearMap(f, fc, M::Int, N::Int; kwargs...) = LinearMap{Float64}(f, fc, M, N; kwargs...)
287+
LinearMap::Number, M::Int, N::Int) = LinearMap(λ, (M, N))
288+
LinearMap::Number, dims::Dims{2}) = FillMap(λ, dims)
286289

287290
LinearMap{T}(A::MapOrMatrix; kwargs...) where {T} = WrappedMap{T}(A; kwargs...)
288291
LinearMap{T}(f, args...; kwargs...) where {T} = FunctionMap{T}(f, args...; kwargs...)

src/fillmap.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
struct FillMap{T} <: LinearMaps.LinearMap{T}
22
λ::T
33
size::Dims{2}
4+
function FillMap::T, dims) where {T}
5+
all(d -> d >= 0, dims) || throw(ArgumentError("dims of FillMap must be non-negative"))
6+
promote_type(T, typeof(λ)) == T || throw(InexactError())
7+
return new{T}(λ, dims)
8+
end
49
end
510

611
# properties
712
Base.size(A::FillMap) = A.size
813
MulStyle(A::FillMap) = FiveArg()
914
LinearAlgebra.issymmetric(A::FillMap) = A.size[1] == A.size[2]
1015
LinearAlgebra.ishermitian(A::FillMap) = isreal(A) && A.size[1] == A.size[2]
11-
LinearAlgebra.isposdef(A::FillMap) = false
16+
LinearAlgebra.isposdef(A::FillMap) = (size(A, 1) == size(A, 2) == 1 && isposdef(A.λ))
1217
Base.:(==)(A::FillMap, B::FillMap) = A.λ == B.λ && A.size == B.size
1318

14-
LinearAlgebra.adjoint(A::FillMap) = FillMap(adjoint(A.λ), revert(A.size))
15-
LinearAlgebra.transpose(A::FillMap) = FillMap(transpose(A.λ), revert(A.size))
19+
LinearAlgebra.adjoint(A::FillMap) = FillMap(adjoint(A.λ), reverse(A.size))
20+
LinearAlgebra.transpose(A::FillMap) = FillMap(transpose(A.λ), reverse(A.size))
21+
22+
function Base.:(*)(A::FillMap, x::AbstractVector)
23+
T = typeof(oneunit(eltype(A)) * (zero(eltype(x)) + zero(eltype(x))))
24+
return fill(iszero(A.λ) ? zero(T) : A.λ*sum(x), A.size[1])
25+
end
1626

1727
function _unsafe_mul!(y::AbstractVecOrMat, A::FillMap, x::AbstractVector)
1828
return fill!(y, iszero(A.λ) ? zero(eltype(y)) : A.λ*sum(x))
@@ -31,13 +41,16 @@ function _unsafe_mul!(y::AbstractVecOrMat, A::FillMap, x::AbstractVector, α::Nu
3141
else
3242
y .= y .* β .+ temp
3343
end
44+
end
3445
return y
3546
end
3647

3748
Base.:(+)(A::FillMap, B::FillMap) = A.size == B.size ? FillMap(A.λ + B.λ, A.size) : throw(DimensionMismatch())
3849
Base.:(-)(A::FillMap) = FillMap(-A.λ, A.size)
3950
Base.:(*)(λ::Number, A::FillMap) = FillMap* A.λ, size(A))
4051
Base.:(*)(A::FillMap, λ::Number) = FillMap(A.λ * λ, size(A))
52+
Base.:(*)(λ::RealOrComplex, A::FillMap) = FillMap* A.λ, size(A))
53+
Base.:(*)(A::FillMap, λ::RealOrComplex) = FillMap(A.λ * λ, size(A))
4154

4255
function Base.:(*)(A::FillMap, B::FillMap)
4356
mA, nA = size(A)

0 commit comments

Comments
 (0)