Skip to content

Commit b3d9f3d

Browse files
committed
UniformScaling as a map and doc updates
1 parent 6ef0593 commit b3d9f3d

File tree

5 files changed

+76
-17
lines changed

5 files changed

+76
-17
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Documentation
33
on:
44
push:
55
branches:
6-
- master # update to match your development branch (master, main, dev, trunk, ...)
6+
- main
77
tags: '*'
88
pull_request:
99

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ makedocs(;
2222
)
2323

2424
deploydocs(;
25-
repo="github.com/JuliaApproximation/FunctionMaps.jl", devbranch="master",
25+
repo="github.com/JuliaApproximation/FunctionMaps.jl.git", devbranch="master",
2626
)

src/generic/jacobian.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ end
117117
const NumberLike = Union{Number,UniformScaling}
118118

119119
"""
120-
to_matrix(::Type{T}, A[, b])
120+
to_matrix(T, A[, b])
121121
122122
Convert the `A` in the affine map `A*x` or `A*x+b` with domaintype `T` to a matrix.
123123
"""

src/generic/map.jl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ domaintype(::Type{<:Map{T}}) where {T} = T
3030
"""
3131
codomaintype(m[, T])
3232
33-
What is the codomain type of the function map `m`, given that `T` is its domain type?
33+
What is the type of a point in the codomain of the function map `m`?
34+
35+
The second argument optionally specifies a domain type `T`.
3436
"""
3537
codomaintype(m) = codomaintype(m, domaintype(m))
3638
codomaintype(m, ::Type{T}) where {T} = _codomaintype(typeof(m), T)
@@ -42,14 +44,27 @@ _codomaintype(M::Type{<:TypedMap{T,U}}, ::Type{Any}) where {T,U} = U
4244
prectype(::Type{<:Map{T}}) where T = prectype(T)
4345
numtype(::Type{<:Map{T}}) where T = numtype(T)
4446

47+
"""
48+
isrealmap(m)
49+
50+
Is the map real-valued?
51+
52+
A map is real-valued if both its domain and codomain types are real.
53+
"""
4554
isrealmap(m) = isrealtype(domaintype(m)) && isrealtype(codomaintype(m))
46-
isrealmap(::UniformScaling{T}) where {T} = isrealtype(T)
4755

4856
convert(::Type{Map{T}}, m::Map{T}) where {T} = m
4957
convert(::Type{Map{T}}, m::Map{S}) where {S,T} = similarmap(m, T)
5058
convert(::Type{TypedMap{T,U}}, m::TypedMap{T,U}) where {T,U} = m
5159
convert(::Type{TypedMap{T,U}}, m::TypedMap) where {T,U} = similarmap(m, T, U)
5260

61+
"""
62+
convert_domaintype(T, m)
63+
64+
Convert the given map to a map such that its `domaintype` is `T`.
65+
66+
See also: [`domaintype`](@ref).
67+
"""
5368
convert_domaintype(::Type{T}, map::Map{T}) where {T} = map
5469
convert_domaintype(::Type{U}, map::Map{T}) where {T,U} = convert(Map{U}, map)
5570
convert_domaintype(::Type{Any}, map) = map

src/types/affine.jl

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11

22
"""
3+
AbstractAffineMap{T} <: Map{T}
4+
35
An 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
"""
913
abstract type AbstractAffineMap{T} <: Map{T} end
1014

@@ -27,11 +31,8 @@ function _affine_applymap!(y, m, x, A, b)
2731
y
2832
end
2933

30-
_affine_A_isreal(A) = isreal(A)
31-
_affine_A_isreal(::UniformScaling{T}) where T = isrealtype(T)
32-
3334
isrealmap(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

3637
jacobian(m::AbstractAffineMap{T}) where {T} = ConstantMap{T}(affinematrix(m))
3738
jacobian(m::AbstractAffineMap, x) = affinematrix(m)
@@ -48,10 +49,24 @@ function diffvolume(m::AbstractAffineMap{T}) where T
4849
ConstantMap{T}(c)
4950
end
5051

51-
islinearmap(m::Map) = false
52+
"""
53+
islinearmap(m)
54+
55+
Is `m` a linear map?
56+
"""
57+
islinearmap(m) = false
5258
islinearmap(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+
"""
5570
isaffinemap(m) = false
5671
isaffinemap(m::Map) = islinearmap(m) || isconstantmap(m)
5772
isaffinemap(m::AbstractAffineMap) = true
@@ -94,7 +109,10 @@ map_stencil_parentheses(m::AbstractAffineMap) = true
94109
########################
95110

96111
"""
112+
LinearMap{T} <: AbstractAffineMap{T}
113+
97114
The supertype of all linear maps `y = A*x`.
115+
98116
Concrete subtypes may differ in how `A` is represented.
99117
"""
100118
abstract type LinearMap{T} <: AbstractAffineMap{T} end
@@ -233,9 +251,6 @@ leftinverse(m::GenericLinearMap{T,AA}) where {T<:AbstractVector,AA<:Number} =
233251
rightinverse(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."
240255
struct 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`.
413430
Concrete subtypes differ in how `A` and `b` are represented.
414431
"""
415432
abstract 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+
"""
417446
AffineMap(A::Number, b::Number) = ScalarAffineMap(A, b)
418447
AffineMap(A::StaticMatrix, b::StaticVector) = StaticAffineMap(A, b)
419448
AffineMap(A::Matrix, b::Vector) = VectorAffineMap(A, b)
@@ -587,3 +616,18 @@ StaticAffineMap{T,N,M}(A::AbstractMatrix, b::AbstractVector) where {T,N,M} =
587616

588617
convert(::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

Comments
 (0)