11
22"""
3+ AbstractAffineMap{T} <: Map{T}
4+
35An affine map has the general form `y = A*x + b`.
46
5- We use `affinematrix(m)` and `affinevector(m)` to denote `A` and `b` respectively. Concrete
6- subtypes include linear maps of the form `y = A*x` and translations of the
7- form `y = x + b`.
7+ We use `affinematrix(m)` and `affinevector(m)` to denote `A` and `b`
8+ respectively. Concrete subtypes include linear maps of the form `y = A*x`
9+ and translations of the form `y = x + b`.
10+
11+ See also: [`affinematrix`](@ref), [`affinevector`](@ref).
812"""
913abstract type AbstractAffineMap{T} <: Map{T} end
1014
@@ -27,11 +31,8 @@ function _affine_applymap!(y, m, x, A, b)
2731 y
2832end
2933
30- _affine_A_isreal (A) = isreal (A)
31- _affine_A_isreal (:: UniformScaling{T} ) where T = isrealtype (T)
32-
3334isrealmap (m:: AbstractAffineMap ) = _affine_isrealmap (m, unsafe_matrix (m), unsafe_vector (m))
34- _affine_isrealmap (m, A, b) = _affine_A_isreal (A) && isreal (b)
35+ _affine_isrealmap (m, A, b) = isrealmap (A) && isreal (b)
3536
3637jacobian (m:: AbstractAffineMap{T} ) where {T} = ConstantMap {T} (affinematrix (m))
3738jacobian (m:: AbstractAffineMap , x) = affinematrix (m)
@@ -48,10 +49,24 @@ function diffvolume(m::AbstractAffineMap{T}) where T
4849 ConstantMap {T} (c)
4950end
5051
51- islinearmap (m:: Map ) = false
52+ """
53+ islinearmap(m)
54+
55+ Is `m` a linear map?
56+ """
57+ islinearmap (m) = false
5258islinearmap (m:: AbstractAffineMap ) = _affine_islinearmap (m, unsafe_vector (m))
5359_affine_islinearmap (m, b) = all (b .== 0 )
5460
61+ """
62+ isaffinemap(m)
63+
64+ Is `m` an affine map?
65+
66+ If `m` is affine, then it has the form `m(x) = A*x+b`.
67+
68+ See also: [`affinematrix`](@ref), [`affinevector`](@ref).
69+ """
5570isaffinemap (m) = false
5671isaffinemap (m:: Map ) = islinearmap (m) || isconstantmap (m)
5772isaffinemap (m:: AbstractAffineMap ) = true
@@ -94,7 +109,10 @@ map_stencil_parentheses(m::AbstractAffineMap) = true
94109# #######################
95110
96111"""
112+ LinearMap{T} <: AbstractAffineMap{T}
113+
97114The supertype of all linear maps `y = A*x`.
115+
98116Concrete subtypes may differ in how `A` is represented.
99117"""
100118abstract type LinearMap{T} <: AbstractAffineMap{T} end
@@ -233,9 +251,6 @@ leftinverse(m::GenericLinearMap{T,AA}) where {T<:AbstractVector,AA<:Number} =
233251rightinverse (m:: GenericLinearMap{T,AA} ) where {T<: AbstractVector ,AA<: Number } =
234252 LinearMap {T} (inv (m. A))
235253
236- convert (:: Type{Map} , A:: UniformScaling ) = GenericLinearMap {Vector{Any}} (A)
237- convert (:: Type{Map{T}} , A:: UniformScaling ) where {T} = GenericLinearMap {T} (A)
238-
239254" A `ScalarLinearMap` is a linear map `y = A*x` for scalars."
240255struct ScalarLinearMap{T} <: LinearMap{T}
241256 A :: T
@@ -409,11 +424,25 @@ GenericTranslation{T}(b::Number) where {T<:Number} =
409424
410425
411426"""
412- The supertype of all affine maps that store `A` and `b`.
427+ AffineMap{T} <: AbstractAffineMap{T}
428+
429+ The supertype of all affine maps that store `A` and `b`.
413430Concrete subtypes differ in how `A` and `b` are represented.
414431"""
415432abstract type AffineMap{T} <: AbstractAffineMap{T} end
416433
434+ """
435+ AffineMap(A, b)
436+
437+ Return an affine map with an appropriate concrete type depending on the arguments
438+ `A` and `b`.
439+
440+ # Examples
441+ ```julia
442+ julia> AffineMap(2, 3)
443+ x -> 2 * x + 3
444+ ```
445+ """
417446AffineMap (A:: Number , b:: Number ) = ScalarAffineMap (A, b)
418447AffineMap (A:: StaticMatrix , b:: StaticVector ) = StaticAffineMap (A, b)
419448AffineMap (A:: Matrix , b:: Vector ) = VectorAffineMap (A, b)
@@ -587,3 +616,18 @@ StaticAffineMap{T,N,M}(A::AbstractMatrix, b::AbstractVector) where {T,N,M} =
587616
588617convert (:: Type{Map{SVector{N,T}}} , m:: VectorAffineMap ) where {N,T} =
589618 StaticAffineMap {T,N} (m. A, m. b)
619+
620+
621+ # ##########################
622+ # Uniform scaling as a map
623+ # ##########################
624+
625+ convert (:: Type{Map} , A:: UniformScaling ) = GenericLinearMap {Vector{Any}} (A)
626+ convert (:: Type{Map{T}} , A:: UniformScaling ) where {T} = GenericLinearMap {T} (A)
627+
628+ # I(4) returns a diagonal matrix: the action of I is multiplication
629+ applymap (I:: UniformScaling , x) = I* x
630+ domaintype (:: UniformScaling{T} ) where T = T
631+ islinearmap (:: UniformScaling ) = true
632+ affinematrix (I:: UniformScaling ) = I
633+ affinevector (I:: UniformScaling ) = zerovector (I)
0 commit comments