Skip to content

Commit 77f538d

Browse files
authored
WIP: review before version 3 (#119)
1 parent b38c1ac commit 77f538d

23 files changed

+384
-355
lines changed

docs/src/types.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ Abstract supertype
1414
LinearMaps.LinearMap
1515
```
1616

17-
Unwrapping function
18-
19-
```@docs
20-
Base.parent
21-
```
22-
2317
### `FunctionMap`
2418

2519
Type for wrapping an arbitrary function that is supposed to implement the

src/LinearMaps.jl

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ end
1616

1717
abstract type LinearMap{T} end
1818

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}
2122

2223
Base.eltype(::LinearMap{T}) where {T} = T
2324

@@ -45,18 +46,10 @@ LinearAlgebra.ishermitian(::LinearMap) = false # default assumptions
4546
LinearAlgebra.isposdef(::LinearMap) = false # default assumptions
4647

4748
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"))
4951
Base.length(A::LinearMap) = size(A)[1] * size(A)[2]
5052

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-
6053
# check dimension consistency for multiplication A*B
6154
_iscompatible((A, B)) = size(A, 2) == size(B, 1)
6255
function check_dim_mul(A, B)
@@ -115,8 +108,9 @@ end
115108
mul!(Y::AbstractVecOrMat, A::LinearMap, B::AbstractVector) -> Y
116109
mul!(Y::AbstractMatrix, A::LinearMap, B::AbstractMatrix) -> Y
117110
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`.
120114
121115
## Examples
122116
```jldoctest; setup=(using LinearAlgebra, LinearMaps)
@@ -144,26 +138,26 @@ end
144138
mul!(C::AbstractVecOrMat, A::LinearMap, B::AbstractVector, α, β) -> C
145139
mul!(C::AbstractMatrix, A::LinearMap, B::AbstractMatrix, α, β) -> C
146140
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`.
149143
150144
## Examples
151145
```jldoctest; setup=(using LinearAlgebra, LinearMaps)
152146
julia> A=LinearMap([1.0 2.0; 3.0 4.0]); B=[1.0, 1.0]; C=[1.0, 3.0];
153-
147+
154148
julia> mul!(C, A, B, 100.0, 10.0) === C
155149
true
156-
150+
157151
julia> C
158152
2-element Array{Float64,1}:
159153
310.0
160154
730.0
161155
162156
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+
164158
julia> mul!(C, A, B, 100.0, 10.0) === C
165159
true
166-
160+
167161
julia> C
168162
2×2 Array{Float64,2}:
169163
310.0 320.0
@@ -233,6 +227,8 @@ function _unsafe_mul!(y::AbstractMatrix, A::LinearMap, x::AbstractMatrix, α, β
233227
return _generic_mapmat_mul!(y, A, x, α, β)
234228
end
235229

230+
const LinearMapTuple = Tuple{Vararg{LinearMap}}
231+
236232
include("left.jl") # left multiplication by a transpose or adjoint vector
237233
include("transpose.jl") # transposing linear maps
238234
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`
257253
a `UniformScaling` object `J` with specified (square) dimension `M`; or
258254
from a function or callable object `f`. In the latter case, one also needs to specify
259255
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`.
265262
266263
The keyword arguments and their default values for the function-based constructor are:
267264
* `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
269267
* `isposdef::Bool = false` : whether `A` or `f` acts as a positive definite matrix.
270268
For existing linear maps or matrices `A`, the default values will be taken by calling
271269
`issymmetric`, `ishermitian` and `isposdef` on the existing object `A`.
@@ -274,8 +272,8 @@ For the function-based constructor, there is one more keyword argument:
274272
* `ismutating::Bool` : flags whether the function acts as a mutating matrix multiplication
275273
`f(y,x)` where the result vector `y` is the first argument (in case of `true`),
276274
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.
279277
"""
280278
LinearMap(A::MapOrMatrix; kwargs...) = WrappedMap(A; kwargs...)
281279
LinearMap(J::UniformScaling, M::Int) = UniformScalingMap(J.λ, M)

0 commit comments

Comments
 (0)