1
1
module LinearMaps
2
2
3
- export LinearMap
3
+ export LinearMap, FunctionMap, FillMap, InverseMap
4
4
export ⊗ , squarekron, kronsum, ⊕ , sumkronsum, khatrirao, facesplitting
5
- export FillMap
6
- export InverseMap
7
5
8
6
using LinearAlgebra
7
+ using LinearAlgebra: AbstractQ
9
8
import LinearAlgebra: mul!
10
9
using SparseArrays
11
10
@@ -18,8 +17,9 @@ using Base: require_one_based_indexing
18
17
19
18
abstract type LinearMap{T} end
20
19
21
- const MapOrVecOrMat{T} = Union{LinearMap{T}, AbstractVecOrMat{T}}
22
- const MapOrMatrix{T} = Union{LinearMap{T}, AbstractMatrix{T}}
20
+ const AbstractVecOrMatOrQ{T} = Union{AbstractVecOrMat{T}, AbstractQ{T}}
21
+ const MapOrVecOrMat{T} = Union{LinearMap{T}, AbstractVecOrMatOrQ{T}}
22
+ const MapOrMatrix{T} = Union{LinearMap{T}, AbstractMatrix{T}, AbstractQ{T}}
23
23
const TransposeAbsVecOrMat{T} = Transpose{T,<: AbstractVecOrMat }
24
24
const RealOrComplex = Union{Real, Complex}
25
25
@@ -31,7 +31,7 @@ Base.eltype(::LinearMap{T}) where {T} = T
31
31
32
32
# conversion to LinearMap
33
33
Base. convert (:: Type{LinearMap} , A:: LinearMap ) = A
34
- Base. convert (:: Type{LinearMap} , A:: AbstractVecOrMat ) = LinearMap (A)
34
+ Base. convert (:: Type{LinearMap} , A:: AbstractVecOrMatOrQ ) = LinearMap (A)
35
35
36
36
convert_to_lmaps () = ()
37
37
convert_to_lmaps (A) = (convert (LinearMap, A),)
@@ -49,6 +49,7 @@ MulStyle(::FiveArg, ::ThreeArg) = ThreeArg()
49
49
MulStyle (:: ThreeArg , :: ThreeArg ) = ThreeArg ()
50
50
MulStyle (:: LinearMap ) = ThreeArg () # default
51
51
MulStyle (:: AbstractVecOrMat ) = FiveArg ()
52
+ MulStyle (:: AbstractQ ) = ThreeArg ()
52
53
MulStyle (A:: LinearMap , As:: LinearMap... ) = MulStyle (MulStyle (A), MulStyle (As... ))
53
54
54
55
Base. isreal (A:: LinearMap ) = eltype (A) <: Real
@@ -337,11 +338,11 @@ end
337
338
include (" transpose.jl" ) # transposing linear maps
338
339
include (" wrappedmap.jl" ) # wrap a matrix of linear map in a new type, thereby allowing to alter its properties
339
340
include (" left.jl" ) # left multiplication by a matrix/transpose or adjoint vector
341
+ include (" functionmap.jl" ) # using a function as linear map
340
342
include (" uniformscalingmap.jl" ) # the uniform scaling map, to be able to make linear combinations of LinearMap objects and multiples of I
341
343
include (" linearcombination.jl" ) # defining linear combinations of linear maps
342
344
include (" scaledmap.jl" ) # multiply by a (real or complex) scalar
343
345
include (" composition.jl" ) # composition of linear maps
344
- include (" functionmap.jl" ) # using a function as linear map
345
346
include (" blockmap.jl" ) # block linear maps
346
347
include (" kronecker.jl" ) # Kronecker product of linear maps
347
348
include (" khatrirao.jl" ) # Khatri-Rao and face-splitting products
@@ -355,34 +356,36 @@ include("chainrules.jl") # AD rules through ChainRulesCore
355
356
356
357
"""
357
358
LinearMap(A::LinearMap; kwargs...)::WrappedMap
358
- LinearMap(A::AbstractVecOrMat ; kwargs...)::WrappedMap
359
+ LinearMap(A::AbstractVecOrMatOrQ ; kwargs...)::WrappedMap
359
360
LinearMap(J::UniformScaling, M::Int)::UniformScalingMap
360
361
LinearMap{T=Float64}(f, [fc,], M::Int, N::Int = M; kwargs...)::FunctionMap
361
362
LinearMap(A::MapOrVecOrMat, dims::Dims{2}, index::NTuple{2, AbstractVector{Int}})::EmbeddedMap
362
363
LinearMap(A::MapOrVecOrMat, dims::Dims{2}; offset::Dims{2})::EmbeddedMap
363
364
364
365
Construct a linear map object, either
365
366
366
- 1. from an existing `LinearMap` or `AbstractVecOrMat` `A`, with the purpose of redefining
367
- its properties via the keyword arguments `kwargs`;
367
+ 1. from an existing `LinearMap` or `AbstractVecOrMat`/`AbstractQ` `A`, with the purpose of
368
+ redefining its properties via the keyword arguments `kwargs`, see below ;
368
369
2. a `UniformScaling` object `J` with specified (square) dimension `M`;
369
370
3. from a function or callable object `f`;
370
- 4. from an existing `LinearMap` or `AbstractVecOrMat` `A`, embedded in a larger zero map.
371
+ 4. from an existing `LinearMap` or `AbstractVecOrMat`/`AbstractQ` `A`, embedded in a larger
372
+ zero map.
371
373
372
374
In the case of item 3, one also needs to specify the size of the equivalent matrix
373
- representation `(M, N)`, i.e., for functions `f` acting
374
- on length `N` vectors and producing length `M` vectors (with default value `N=M`).
375
- Preferably, also the `eltype` `T` of the corresponding matrix representation needs to be
376
- specified, i.e., whether the action of `f` on a vector will be similar to, e.g., multiplying
377
- by numbers of type `T`. If not specified, the devault value `T=Float64` will be assumed.
378
- Optionally, a corresponding function `fc` can be specified that implements the adjoint
379
- (=transpose in the real case) of `f`.
380
-
381
- The keyword arguments and their default values for the function-based constructor are:
382
- * `issymmetric::Bool = false` : whether `A` or `f` act as a symmetric matrix
383
- * `ishermitian::Bool = issymmetric & T<:Real` : whether `A` or `f` act as a Hermitian
384
- matrix
385
- * `isposdef::Bool = false` : whether `A` or `f` act as a positive definite matrix.
375
+ representation `(M, N)`, i.e., for functions `f` acting on length `N` vectors and producing
376
+ length `M` vectors (with default value `N=M`). Preferably, also the `eltype` `T` of the
377
+ corresponding matrix representation needs to be specified, i.e., whether the action of `f`
378
+ on a vector will be similar to, e.g., multiplying by numbers of type `T`. If not specified,
379
+ the devault value `T=Float64` will be assumed. Optionally, a corresponding function `fc`
380
+ can be specified that implements the adjoint (or transpose in the real case) of `f`.
381
+
382
+ The keyword arguments and their default values are:
383
+
384
+ * `issymmetric::Bool = false` : whether `A` or `f` act as a symmetric matrix
385
+ * `ishermitian::Bool = issymmetric & T<:Real` : whether `A` or `f` act as a Hermitian
386
+ matrix
387
+ * `isposdef::Bool = false` : whether `A` or `f` act as a positive definite matrix.
388
+
386
389
For existing linear maps or matrices `A`, the default values will be taken by calling
387
390
internal functions `_issymmetric`, `_ishermitian` and `_isposdef` on the existing object `A`.
388
391
These in turn dispatch to (overloads of) `LinearAlgebra`'s `issymmetric`, `ishermitian`,
@@ -391,11 +394,11 @@ known at compile time as for certain structured matrices, but return `false` for
391
394
`AbstractMatrix` types.
392
395
393
396
For the function-based constructor, there is one more keyword argument:
394
- * `ismutating::Bool` : flags whether the function acts as a mutating matrix multiplication
395
- `f(y,x)` where the result vector `y` is the first argument (in case of `true`),
396
- or as a normal matrix multiplication that is called as `y=f(x)` (in case of `false`).
397
- The default value is guessed by looking at the number of arguments of the first
398
- occurrence of `f` in the method table.
397
+ * `ismutating::Bool` : flags whether the function acts as a mutating matrix multiplication
398
+ `f(y,x)` where the result vector `y` is the first argument (in case of `true`),
399
+ or as a normal matrix multiplication that is called as `y=f(x)` (in case of `false`).
400
+ The default value is guessed by looking at the number of arguments of the first
401
+ occurrence of `f` in the method table.
399
402
400
403
For the `EmbeddedMap` constructors, `dims` specifies the total dimensions of the map. The
401
404
`index` argument specifies two collections of indices `inds1` and `inds2`, such that for
0 commit comments