@@ -2,10 +2,10 @@ struct CompositeMap{T, As<:Tuple{Vararg{LinearMap}}} <: LinearMap{T}
2
2
maps:: As # stored in order of application to vector
3
3
function CompositeMap {T, As} (maps:: As ) where {T, As}
4
4
N = length (maps)
5
- for n = 2 : N
5
+ for n in 2 : N
6
6
size (maps[n], 2 ) == size (maps[n- 1 ], 1 ) || throw (DimensionMismatch (" CompositeMap" ))
7
7
end
8
- for n = 1 : N
8
+ for n in 1 : N
9
9
promote_type (T, eltype (maps[n])) == T || throw (InexactError ())
10
10
end
11
11
new {T, As} (maps)
40
40
41
41
# scalar multiplication and division
42
42
function Base.:(* )(α:: Number , A:: LinearMap )
43
- T = promote_type (eltype (α), eltype (A))
43
+ T = promote_type (typeof (α), eltype (A))
44
44
return CompositeMap {T} (tuple (A, UniformScalingMap (α, size (A, 1 ))))
45
45
end
46
46
function Base.:(* )(α:: Number , A:: CompositeMap )
47
- T = promote_type (eltype (α), eltype (A))
47
+ T = promote_type (typeof (α), eltype (A))
48
48
Alast = last (A. maps)
49
49
if Alast isa UniformScalingMap
50
50
return CompositeMap {T} (tuple (Base. front (A. maps)... , UniformScalingMap (α * Alast. λ, size (Alast, 1 ))))
@@ -53,11 +53,11 @@ function Base.:(*)(α::Number, A::CompositeMap)
53
53
end
54
54
end
55
55
function Base.:(* )(A:: LinearMap , α:: Number )
56
- T = promote_type (eltype (α), eltype (A))
56
+ T = promote_type (typeof (α), eltype (A))
57
57
return CompositeMap {T} (tuple (UniformScalingMap (α, size (A, 2 )), A))
58
58
end
59
59
function Base.:(* )(A:: CompositeMap , α:: Number )
60
- T = promote_type (eltype (α), eltype (A))
60
+ T = promote_type (typeof (α), eltype (A))
61
61
Afirst = first (A. maps)
62
62
if Afirst isa UniformScalingMap
63
63
return CompositeMap {T} (tuple (UniformScalingMap (Afirst. λ * α, size (Afirst, 1 )), Base. tail (A. maps)... ))
@@ -70,28 +70,28 @@ Base.:(/)(A::LinearMap, α::Number) = A * inv(α)
70
70
Base.:(- )(A:: LinearMap ) = - 1 * A
71
71
72
72
# composition of linear maps
73
- function Base.:(* )(A1 :: CompositeMap , A2 :: CompositeMap )
74
- size (A1 , 2 ) == size (A2 , 1 ) || throw (DimensionMismatch (" *" ))
75
- T = promote_type (eltype (A1 ), eltype (A2 ))
76
- return CompositeMap {T} (tuple (A2 . maps... , A1 . maps... ))
73
+ function Base.:(* )(A₁ :: CompositeMap , A₂ :: CompositeMap )
74
+ size (A₁ , 2 ) == size (A₂ , 1 ) || throw (DimensionMismatch (" *" ))
75
+ T = promote_type (eltype (A₁ ), eltype (A₂ ))
76
+ return CompositeMap {T} (tuple (A₂ . maps... , A₁ . maps... ))
77
77
end
78
- function Base.:(* )(A1 :: LinearMap , A2 :: CompositeMap )
79
- size (A1 , 2 ) == size (A2 , 1 ) || throw (DimensionMismatch (" *" ))
80
- T = promote_type (eltype (A1 ), eltype (A2 ))
81
- return CompositeMap {T} (tuple (A2 . maps... , A1 ))
78
+ function Base.:(* )(A₁ :: LinearMap , A₂ :: CompositeMap )
79
+ size (A₁ , 2 ) == size (A₂ , 1 ) || throw (DimensionMismatch (" *" ))
80
+ T = promote_type (eltype (A₁ ), eltype (A₂ ))
81
+ return CompositeMap {T} (tuple (A₂ . maps... , A₁ ))
82
82
end
83
- function Base.:(* )(A1 :: CompositeMap , A2 :: LinearMap )
84
- size (A1 , 2 ) == size (A2 , 1 ) || throw (DimensionMismatch (" *" ))
85
- T = promote_type (eltype (A1 ), eltype (A2 ))
86
- return CompositeMap {T} (tuple (A2, A1 . maps... ))
83
+ function Base.:(* )(A₁ :: CompositeMap , A₂ :: LinearMap )
84
+ size (A₁ , 2 ) == size (A₂ , 1 ) || throw (DimensionMismatch (" *" ))
85
+ T = promote_type (eltype (A₁ ), eltype (A₂ ))
86
+ return CompositeMap {T} (tuple (A₂, A₁ . maps... ))
87
87
end
88
- function Base.:(* )(A1 :: LinearMap , A2 :: LinearMap )
89
- size (A1 , 2 ) == size (A2 , 1 ) || throw (DimensionMismatch (" *" ))
90
- T = promote_type (eltype (A1), eltype (A2 ))
91
- return CompositeMap {T} (tuple (A2, A1 ))
88
+ function Base.:(* )(A₁ :: LinearMap , A₂ :: LinearMap )
89
+ size (A₁ , 2 ) == size (A₂ , 1 ) || throw (DimensionMismatch (" *" ))
90
+ T = promote_type (eltype (A₁), eltype (A₂ ))
91
+ return CompositeMap {T} (tuple (A₂, A₁ ))
92
92
end
93
- Base.:(* )(A1 :: LinearMap , A2 :: UniformScaling{T} ) where {T} = A1 * A2[ 1 , 1 ]
94
- Base.:(* )(A1 :: UniformScaling{T} , A2 :: LinearMap ) where {T} = A1[ 1 , 1 ] * A2
93
+ Base.:(* )(A₁ :: LinearMap , A₂ :: UniformScaling ) = A₁ * A₂ . λ
94
+ Base.:(* )(A₁ :: UniformScaling , A₂ :: LinearMap ) = A₁ . λ * A₂
95
95
96
96
# special transposition behavior
97
97
LinearAlgebra. transpose (A:: CompositeMap{T} ) where {T} = CompositeMap {T} (map (transpose, reverse (A. maps)))
@@ -114,7 +114,7 @@ function A_mul_B!(y::AbstractVector, A::CompositeMap, x::AbstractVector)
114
114
if N> 2
115
115
dest = Array {T} (undef, size (A. maps[2 ], 1 ))
116
116
end
117
- for n= 2 : N- 1
117
+ for n in 2 : N- 1
118
118
try
119
119
resize! (dest, size (A. maps[n], 1 ))
120
120
catch err
0 commit comments