Skip to content

Commit

Permalink
further cleanup of functionmap
Browse files Browse the repository at this point in the history
  • Loading branch information
Jutho committed May 3, 2017
1 parent db6b905 commit 3b2ffe1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
13 changes: 10 additions & 3 deletions src/LinearMaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,22 @@ include("identitymap.jl") # the identity map, to be able to make linear combinat
include("functionmap.jl") # using a function as linear map

LinearMap(A::Union{AbstractMatrix,LinearMap}; kwargs...) = WrappedMap(A; kwargs...)
LinearMap(f, M::Int) = LinearMap{Float64}(f, M)
LinearMap(f, M::Int, N::Int) = LinearMap{Float64}(f, M, N)
LinearMap(f, fc, M::Int) = LinearMap{Float64}(f, fc, M)
LinearMap(f, fc, M::Int, N::Int) = LinearMap{Float64}(f, fc, M, N)

(::Type{LinearMap{T}})(A::Union{AbstractMatrix,LinearMap}; kwargs...) where {T} = WrappedMap{T}(A; kwargs...)
(::Type{LinearMap{T}})(f, args...; kwargs...) where {T} = FunctionMap{T}(f, args...; kwargs...)

@deprecate LinearMap(f, T::Type, args...; kwargs...) LinearMap{T}(f, args...; kwargs...)
@deprecate LinearMap(f, fc, T::Type, args...; kwargs...) LinearMap{T}(f, fc, args...; kwargs...)
@deprecate LinearMap(f, M::Int, T::Type, args...; kwargs...) LinearMap{T}(f, M; kwargs...)
@deprecate LinearMap(f, M::Int, N::Int, T::Type, args...; kwargs...) LinearMap{T}(f, M, N; kwargs...)

@deprecate LinearMap(f, M::Int, T::Type; kwargs...) LinearMap{T}(f, M; kwargs...)
@deprecate LinearMap(f, M::Int, N::Int, T::Type; kwargs...) LinearMap{T}(f, M, N; kwargs...)
@deprecate LinearMap(f, fc, M::Int, T::Type; kwargs...) LinearMap{T}(f, fc, M; kwargs...)
@deprecate LinearMap(f, fc, M::Int, N::Int, T::Type; kwargs...) LinearMap{T}(f, fc, M, N; kwargs...)

(::Type{LinearMap{T}})(args...; kwargs...) where {T} = FunctionMap{T}(args...; kwargs...)


end # module
20 changes: 5 additions & 15 deletions src/functionmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,17 @@ immutable FunctionMap{T,F1,F2}<:LinearMap{T}
_ishermitian::Bool
_isposdef::Bool
end

# additional constructor
FunctionMap(f, M::Int, ::Type{T} = Float64; kwargs...) where {T} = FunctionMap{T}(f, M; kwargs...)
FunctionMap(f, M::Int, N::Int, ::Type{T} = Float64; kwargs...) where {T} = FunctionMap{T}(f, M, N; kwargs...)
FunctionMap(f, ::Type{T}, M::Int; kwargs...) where {T} = FunctionMap{T}(f, M; kwargs...)
FunctionMap(f, ::Type{T}, M::Int, N::Int; kwargs...) where {T} = FunctionMap{T}(f, M, N; kwargs...)
FunctionMap(f, fc, M::Int, ::Type{T} = Float64; kwargs...) where {T} = FunctionMap{T}(f, fc, M; kwargs...)
FunctionMap(f, fc, M::Int, N::Int, ::Type{T} = Float64; kwargs...) where {T} = FunctionMap{T}(f, fc, M, N; kwargs...)
FunctionMap(f, fc, ::Type{T}, M::Int; kwargs...) where {T} = FunctionMap{T}(f, fc, M; kwargs...)
FunctionMap(f, fc, ::Type{T}, M::Int, N::Int; kwargs...) where {T} = FunctionMap{T}(f, fc, M, N; kwargs...)

(::Type{FunctionMap{T}})(f, M::Int; kwargs...) where {T} = FunctionMap{T}(f, nothing, M, M; kwargs...)
(::Type{FunctionMap{T}})(f, M::Int, N::Int; kwargs...) where {T} = FunctionMap{T}(f, nothing, M, N; kwargs...)
(::Type{FunctionMap{T}})(f, fc, M::Int; kwargs...) where {T} = FunctionMap{T}(f, fc, M, M; kwargs...)

function (::Type{FunctionMap{T}})(f::F1, fc::F2, M::Int, N::Int;
ismutating::Bool = _ismutating(f), issymmetric::Bool = false, ishermitian::Bool=(T<:Real && issymmetric),
isposdef::Bool = false) where {T,F1,F2}
FunctionMap{T,F1,F2}(f, fc, M, N, ismutating, issymmetric, ishermitian, isposdef)
end

# additional constructors
(::Type{FunctionMap{T}})(f, M::Int; kwargs...) where {T} = FunctionMap{T}(f, nothing, M, M; kwargs...)
(::Type{FunctionMap{T}})(f, M::Int, N::Int; kwargs...) where {T} = FunctionMap{T}(f, nothing, M, N; kwargs...)
(::Type{FunctionMap{T}})(f, fc, M::Int; kwargs...) where {T} = FunctionMap{T}(f, fc, M, M; kwargs...)

# show
function Base.show(io::IO,A::FunctionMap{T}) where {T}
print(io,"LinearMaps.FunctionMap{$T}($(A.f), $(A.fc), $(A.M), $(A.N); ismutating=$(A._ismutating), issymmetric=$(A._issymmetric), ishermitian=$(A._ishermitian), isposdef=$(A._isposdef))")
Expand Down
4 changes: 2 additions & 2 deletions src/transpose.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
immutable TransposeMap{T, A<:LinearMap} <: LinearMap{T}
immutable TransposeMap{T, A<:LinearMap{T}} <: LinearMap{T}
lmap::A
end
immutable CTransposeMap{T, A<:LinearMap} <: LinearMap{T}
immutable CTransposeMap{T, A<:LinearMap{T}} <: LinearMap{T}
lmap::A
end
(::Type{TransposeMap}){T}(lmap::LinearMap{T}) = TransposeMap{T, typeof(lmap)}(lmap)
Expand Down
9 changes: 7 additions & 2 deletions src/wrappedmap.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
immutable WrappedMap{T, A<:Union{AbstractMatrix{T}, LinearMap{T}}} <: LinearMap{T}
immutable WrappedMap{T, A<:Union{AbstractMatrix, LinearMap}} <: LinearMap{T}
lmap::A
_isreal::Bool
_issymmetric::Bool
Expand All @@ -10,6 +10,11 @@ function (::Type{WrappedMap})(lmap::Union{AbstractMatrix{T}, LinearMap{T}};
ishermitian::Bool = Base.ishermitian(lmap), isposdef::Bool = Base.isposdef(lmap)) where {T}
WrappedMap{T,typeof(lmap)}(lmap, isreal, issymmetric, ishermitian, isposdef)
end
function (::Type{WrappedMap{T}})(lmap::Union{AbstractMatrix, LinearMap};
isreal::Bool = Base.isreal(lmap), issymmetric::Bool = Base.issymmetric(lmap),
ishermitian::Bool = Base.ishermitian(lmap), isposdef::Bool = Base.isposdef(lmap)) where {T}
WrappedMap{T,typeof(lmap)}(lmap, isreal, issymmetric, ishermitian, isposdef)
end

# properties
Base.size(A::WrappedMap) = size(A.lmap)
Expand All @@ -19,7 +24,7 @@ Base.ishermitian(A::WrappedMap) = A._ishermitian
Base.isposdef(A::WrappedMap) = A._isposdef

# comparison
==(A::WrappedMap,B::WrappedMap) = (A.lmap == B.lmap && isreal(A) == isreal(B) &&
==(A::WrappedMap, B::WrappedMap) = (A.lmap == B.lmap && eltype(A) == eltype(B) && isreal(A) == isreal(B) &&
issymmetric(A) == issymmetric(B) && ishermitian(A) == ishermitian(B) && isposdef(A) == isposdef(B))

# multiplication with vector
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ F = LinearMap(cumsum,2)
@test full(F) == [1. 0.;1. 1.]

N = 100
F = LinearMap(fft, N, Complex128)/sqrt(N)
F = LinearMap{Complex128}(fft, N)/sqrt(N)
U = full(F) # will be a unitary matrix
@test U'*U eye(N)

Expand Down

0 comments on commit 3b2ffe1

Please sign in to comment.