|
1 | 1 | # Constructors. |
2 | 2 | """ |
3 | | - LinearOperator(M::AbstractMatrix{T}; symmetric=false, hermitian=false, S = Vector{T}) where {T} |
4 | | -Construct a linear operator from a dense or sparse matrix. |
5 | | -Use the optional keyword arguments to indicate whether the operator |
6 | | -is symmetric and/or hermitian. |
7 | | -Change `S` to use LinearOperators on GPU. |
| 3 | + LinearOperator(M::AbstractMatrix{T}; symmetric=defaultsymmetric(M), hermitian=defaulthermitian(M), S = Vector{T}) where {T} |
| 4 | +Construct a linear operator from a dense or sparse matrix. Use the optional |
| 5 | +keyword arguments to indicate whether the operator is symmetric and/or |
| 6 | +hermitian. Change `S` to use LinearOperators on GPU. |
| 7 | +
|
| 8 | +!!! tip |
| 9 | + In performance-sensitive applications, it may be advisable to use |
| 10 | +
|
| 11 | + LinearOperator{T, S}(M; kwargs...) |
| 12 | +
|
| 13 | + instead. |
8 | 14 | """ |
9 | 15 | function LinearOperator( |
10 | 16 | M::AbstractMatrix{T}; |
11 | | - symmetric = false, |
12 | | - hermitian = false, |
13 | 17 | S = storage_type(M), |
| 18 | + kwargs..., |
14 | 19 | ) where {T} |
| 20 | + return LinearOperator{T, S}(M; kwargs...) |
| 21 | +end |
| 22 | + |
| 23 | +function LinearOperator{T, S}(M::AbstractMatrix{T}; symmetric = defaultsymmetric(M), hermitian = defaulthermitian(M)) where {T, S} |
15 | 24 | nrow, ncol = size(M) |
16 | 25 | prod! = @closure (res, v, α, β) -> mul!(res, M, v, α, β) |
17 | 26 | tprod! = @closure (res, u, α, β) -> mul!(res, transpose(M), u, α, β) |
18 | 27 | ctprod! = @closure (res, w, α, β) -> mul!(res, adjoint(M), w, α, β) |
19 | 28 | LinearOperator{T, S}(nrow, ncol, symmetric, hermitian, prod!, tprod!, ctprod!) |
20 | 29 | end |
21 | 30 |
|
22 | | -""" |
23 | | - LinearOperator(M::Symmetric{T}, S = Vector{T}) where {T <: Real} = |
24 | | -
|
25 | | -Construct a linear operator from a symmetric real square matrix `M`. |
26 | | -Change `S` to use LinearOperators on GPU. |
27 | | -""" |
28 | | -LinearOperator(M::Symmetric{T}, S = Vector{T}) where {T <: Real} = |
29 | | - LinearOperator(M, symmetric = true, hermitian = true, S = S) |
30 | | - |
31 | | -""" |
32 | | - LinearOperator(M::SymTridiagonal{T}, S = Vector{T}) where {T} |
33 | | -
|
34 | | -Constructs a linear operator from a symmetric tridiagonal matrix. If |
35 | | -its elements are real, it is also Hermitian, otherwise complex |
36 | | -symmetric. |
37 | | -Change `S` to use LinearOperators on GPU. |
38 | | -""" |
39 | | -function LinearOperator(M::SymTridiagonal{T}, S = Vector{T}) where {T} |
40 | | - hermitian = eltype(M) <: Real |
41 | | - LinearOperator(M, symmetric = true, hermitian = hermitian, S = S) |
42 | | -end |
43 | | - |
44 | | -""" |
45 | | - LinearOperator(M::Hermitian{T}, S = Vector{T}) where {T} |
46 | | -
|
47 | | -Constructs a linear operator from a Hermitian matrix. If |
48 | | -its elements are real, it is also symmetric. |
49 | | -Change `S` to use LinearOperators on GPU. |
50 | | -""" |
51 | | -function LinearOperator(M::Hermitian{T}, S = Vector{T}) where {T} |
52 | | - symmetric = eltype(M) <: Real |
53 | | - LinearOperator(M, symmetric = symmetric, hermitian = true, S = S) |
54 | | -end |
| 31 | +defaultsymmetric(M) = false |
| 32 | +defaulthermitian(M) = false |
| 33 | +defaultsymmetric(M::Symmetric) = true |
| 34 | +defaulthermitian(M::Symmetric{<:Real}) = true |
| 35 | +defaultsymmetric(M::Hermitian) = eltype(M) <: Real |
| 36 | +defaulthermitian(M::Hermitian) = true |
| 37 | +defaultsymmetric(M::SymTridiagonal) = true |
| 38 | +defaulthermitian(M::SymTridiagonal{<:Real}) = true |
55 | 39 |
|
56 | 40 | """ |
57 | 41 | LinearOperator(type::Type{T}, nrow, ncol, symmetric, hermitian, prod!, |
@@ -104,6 +88,13 @@ op = LinearOperator(Float64, 2, 2, false, false, |
104 | 88 | ``` |
105 | 89 |
|
106 | 90 | The 3-args `mul!` also works when applying the operator on a matrix. |
| 91 | +
|
| 92 | +!!! tip |
| 93 | + In performance-sensitive applications, it may be advisable to use |
| 94 | +
|
| 95 | + LinearOperator{T, S}(nrow, ncol, symmetric, hermitian, prod!, tprod!=nothing, ctprod!=nothing) |
| 96 | +
|
| 97 | + instead. |
107 | 98 | """ |
108 | 99 | function LinearOperator( |
109 | 100 | ::Type{T}, |
|
0 commit comments