16
16
17
17
abstract type LinearMap{T} end
18
18
19
- const MapOrMatrix{T} = Union{LinearMap{T},AbstractMatrix{T}}
20
- const RealOrComplex = Union{Real,Complex}
19
+ const MapOrVecOrMat{T} = Union{LinearMap{T}, AbstractVecOrMat{T}}
20
+ const MapOrMatrix{T} = Union{LinearMap{T}, AbstractMatrix{T}}
21
+ const RealOrComplex = Union{Real, Complex}
21
22
22
23
Base. eltype (:: LinearMap{T} ) where {T} = T
23
24
@@ -45,18 +46,10 @@ LinearAlgebra.ishermitian(::LinearMap) = false # default assumptions
45
46
LinearAlgebra. isposdef (:: LinearMap ) = false # default assumptions
46
47
47
48
Base. ndims (:: LinearMap ) = 2
48
- Base. size (A:: LinearMap , n) = (n== 1 || n== 2 ? size (A)[n] : error (" LinearMap objects have only 2 dimensions" ))
49
+ Base. size (A:: LinearMap , n) =
50
+ (n== 1 || n== 2 ? size (A)[n] : error (" LinearMap objects have only 2 dimensions" ))
49
51
Base. length (A:: LinearMap ) = size (A)[1 ] * size (A)[2 ]
50
52
51
- """
52
- parent(A::LinearMap)
53
-
54
- Return the underlying "parent map". This parent map is what was passed as an argument to
55
- the specific `LinearMap` constructor, including implicit constructors and up to implicit
56
- promotion to a `LinearMap` subtype. The fallback is to return the input itself.
57
- """
58
- Base. parent (A:: LinearMap ) = A
59
-
60
53
# check dimension consistency for multiplication A*B
61
54
_iscompatible ((A, B)) = size (A, 2 ) == size (B, 1 )
62
55
function check_dim_mul (A, B)
115
108
mul!(Y::AbstractVecOrMat, A::LinearMap, B::AbstractVector) -> Y
116
109
mul!(Y::AbstractMatrix, A::LinearMap, B::AbstractMatrix) -> Y
117
110
118
- Calculates the action of the linear map `A` on the vector or matrix `B` and stores the result in `Y`,
119
- overwriting the existing value of `Y`. Note that `Y` must not be aliased with either `A` or `B`.
111
+ Calculates the action of the linear map `A` on the vector or matrix `B` and stores the
112
+ result in `Y`, overwriting the existing value of `Y`. Note that `Y` must not be aliased
113
+ with either `A` or `B`.
120
114
121
115
## Examples
122
116
```jldoctest; setup=(using LinearAlgebra, LinearMaps)
@@ -144,26 +138,26 @@ end
144
138
mul!(C::AbstractVecOrMat, A::LinearMap, B::AbstractVector, α, β) -> C
145
139
mul!(C::AbstractMatrix, A::LinearMap, B::AbstractMatrix, α, β) -> C
146
140
147
- Combined inplace multiply-add ``A B α + C β``. The result is stored in `C` by overwriting it.
148
- Note that `C` must not be aliased with either `A` or `B`.
141
+ Combined inplace multiply-add ``A B α + C β``. The result is stored in `C` by overwriting
142
+ it. Note that `C` must not be aliased with either `A` or `B`.
149
143
150
144
## Examples
151
145
```jldoctest; setup=(using LinearAlgebra, LinearMaps)
152
146
julia> A=LinearMap([1.0 2.0; 3.0 4.0]); B=[1.0, 1.0]; C=[1.0, 3.0];
153
-
147
+
154
148
julia> mul!(C, A, B, 100.0, 10.0) === C
155
149
true
156
-
150
+
157
151
julia> C
158
152
2-element Array{Float64,1}:
159
153
310.0
160
154
730.0
161
155
162
156
julia> A=LinearMap([1.0 2.0; 3.0 4.0]); B=[1.0 1.0; 1.0 1.0]; C=[1.0 2.0; 3.0 4.0];
163
-
157
+
164
158
julia> mul!(C, A, B, 100.0, 10.0) === C
165
159
true
166
-
160
+
167
161
julia> C
168
162
2×2 Array{Float64,2}:
169
163
310.0 320.0
@@ -233,6 +227,8 @@ function _unsafe_mul!(y::AbstractMatrix, A::LinearMap, x::AbstractMatrix, α, β
233
227
return _generic_mapmat_mul! (y, A, x, α, β)
234
228
end
235
229
230
+ const LinearMapTuple = Tuple{Vararg{LinearMap}}
231
+
236
232
include (" left.jl" ) # left multiplication by a transpose or adjoint vector
237
233
include (" transpose.jl" ) # transposing linear maps
238
234
include (" wrappedmap.jl" ) # wrap a matrix of linear map in a new type, thereby allowing to alter its properties
@@ -257,15 +253,17 @@ with the purpose of redefining its properties via the keyword arguments `kwargs`
257
253
a `UniformScaling` object `J` with specified (square) dimension `M`; or
258
254
from a function or callable object `f`. In the latter case, one also needs to specify
259
255
the size of the equivalent matrix representation `(M, N)`, i.e., for functions `f` acting
260
- on length `N` vectors and producing length `M` vectors (with default value `N=M`). Preferably,
261
- also the `eltype` `T` of the corresponding matrix representation needs to be specified, i.e.
262
- whether the action of `f` on a vector will be similar to, e.g., multiplying by numbers of type `T`.
263
- If not specified, the devault value `T=Float64` will be assumed. Optionally, a corresponding
264
- function `fc` can be specified that implements the adjoint (=transpose in the real case) of `f`.
256
+ on length `N` vectors and producing length `M` vectors (with default value `N=M`).
257
+ Preferably, also the `eltype` `T` of the corresponding matrix representation needs to be
258
+ specified, i.e. whether the action of `f` on a vector will be similar to, e.g., multiplying
259
+ by numbers of type `T`. If not specified, the devault value `T=Float64` will be assumed.
260
+ Optionally, a corresponding function `fc` can be specified that implements the adjoint
261
+ (=transpose in the real case) of `f`.
265
262
266
263
The keyword arguments and their default values for the function-based constructor are:
267
264
* `issymmetric::Bool = false` : whether `A` or `f` acts as a symmetric matrix
268
- * `ishermitian::Bool = issymmetric & T<:Real` : whether `A` or `f` acts as a Hermitian matrix
265
+ * `ishermitian::Bool = issymmetric & T<:Real` : whether `A` or `f` acts as a Hermitian
266
+ matrix
269
267
* `isposdef::Bool = false` : whether `A` or `f` acts as a positive definite matrix.
270
268
For existing linear maps or matrices `A`, the default values will be taken by calling
271
269
`issymmetric`, `ishermitian` and `isposdef` on the existing object `A`.
@@ -274,8 +272,8 @@ For the function-based constructor, there is one more keyword argument:
274
272
* `ismutating::Bool` : flags whether the function acts as a mutating matrix multiplication
275
273
`f(y,x)` where the result vector `y` is the first argument (in case of `true`),
276
274
or as a normal matrix multiplication that is called as `y=f(x)` (in case of `false`).
277
- The default value is guessed by looking at the number of arguments of the first occurrence
278
- of `f` in the method table.
275
+ The default value is guessed by looking at the number of arguments of the first
276
+ occurrence of `f` in the method table.
279
277
"""
280
278
LinearMap (A:: MapOrMatrix ; kwargs... ) = WrappedMap (A; kwargs... )
281
279
LinearMap (J:: UniformScaling , M:: Int ) = UniformScalingMap (J. λ, M)
0 commit comments