|
1 | 1 |
|
2 | | -"An `AbstractMap` represents a function `y=f(x)` of a single variable." |
3 | | -abstract type AbstractMap end |
4 | | - |
5 | | -"A `Map{T}` is a map of a single variable of type `T`." |
6 | | -abstract type Map{T} <: AbstractMap end |
| 2 | +""" |
| 3 | +A `Map{T}` is a map of a single variable of type `T`. |
| 4 | +""" |
| 5 | +abstract type Map{T} end |
7 | 6 |
|
8 | 7 | Map(m) = convert(Map, m) |
9 | 8 | Map{T}(m) where {T} = convert(Map{T}, m) |
10 | 9 |
|
11 | | -"A `TypedMap{T,U}` maps a variable of type `T` to a variable of type `U`." |
| 10 | +""" |
| 11 | +Any instance of `TypedMap{T,U}` maps a variable of type `T` to a variable |
| 12 | +of type `U`. |
| 13 | +""" |
12 | 14 | abstract type TypedMap{T,U} <: Map{T} end |
13 | 15 |
|
14 | 16 | const EuclideanMap{N,T} = Map{<:StaticVector{N,T}} |
@@ -43,7 +45,6 @@ numtype(::Type{<:Map{T}}) where T = numtype(T) |
43 | 45 | isrealmap(m) = isrealtype(domaintype(m)) && isrealtype(codomaintype(m)) |
44 | 46 | isrealmap(::UniformScaling{T}) where {T} = isrealtype(T) |
45 | 47 |
|
46 | | -convert(::Type{AbstractMap}, m::AbstractMap) = m |
47 | 48 | convert(::Type{Map{T}}, m::Map{T}) where {T} = m |
48 | 49 | convert(::Type{Map{T}}, m::Map{S}) where {S,T} = similarmap(m, T) |
49 | 50 | convert(::Type{TypedMap{T,U}}, m::TypedMap{T,U}) where {T,U} = m |
@@ -83,10 +84,10 @@ convert_codomaintype(::Type{Any}, map) = map |
83 | 84 |
|
84 | 85 |
|
85 | 86 | # Users may call a map, concrete subtypes specialize the `applymap` function |
86 | | -(m::AbstractMap)(x) = applymap(m, x) |
87 | | - |
88 | | -# For Map{T}, we allow invocation with multiple arguments by conversion to T |
| 87 | +# Some effort is spent at this generic level to convert the argument to something |
| 88 | +# of type `T`. |
89 | 89 | (m::Map{T})(x) where {T} = promote_and_apply(m, x) |
| 90 | +# For convenience we allow invocation with multiple arguments by conversion to T |
90 | 91 | (m::Map{T})(x...) where {T} = promote_and_apply(m, convert(T, x)) |
91 | 92 |
|
92 | 93 | "Promote map and point to compatible types." |
@@ -115,9 +116,8 @@ promote_and_apply(m::Map, x) = applymap(promote_map_point_pair(m,x)...) |
115 | 116 |
|
116 | 117 | applymap!(y, m, x) = y .= m(x) |
117 | 118 |
|
118 | | -# Fallback for functions that are not of type AbstractMap |
| 119 | +# Fallback for functions that are not of type Map |
119 | 120 | applymap(m, x) = m(x) |
120 | | -applymap(m::AbstractMap, x) = error("Please implement applymap for map $(m)") |
121 | 121 |
|
122 | 122 |
|
123 | 123 | "Can the maps be promoted to a common domain type without throwing an error?" |
|
0 commit comments