@@ -28,7 +28,7 @@ julia> MatrixOp(randn(20,10),4)
2828
2929"""
3030
31- struct MatrixOp{T, M <: AbstractMatrix{T} } <: LinearOperator
31+ struct MatrixOp{D, T, M <: AbstractMatrix{T} } <: LinearOperator
3232 A:: M
3333 n_col_in:: Integer
3434end
3737
3838# #TODO decide what to do when domainType is given, with conversion one loses pointer to data...
3939# ##standard constructor Operator{N}(DomainType::Type, DomainDim::NTuple{N,Int})
40- function MatrixOp (DomainType:: Type , DomainDim:: NTuple{N,Int} , A:: M ) where {N, M <: AbstractMatrix }
40+ function MatrixOp (DomainType:: Type , DomainDim:: NTuple{N,Int} , A:: M ) where {N, T, M <: AbstractMatrix{T} }
4141 N > 2 && error (" cannot multiply a Matrix by a n-dimensional Variable with n > 2" )
4242 size (A,2 ) != DomainDim[1 ] && error (" wrong input dimensions" )
4343 if N == 1
44- MatrixOp {DomainType, M} (A, 1 )
44+ MatrixOp {DomainType, T, M} (A, 1 )
4545 else
46- MatrixOp {DomainType, M} (A, DomainDim[2 ])
46+ MatrixOp {DomainType, T, M} (A, DomainDim[2 ])
4747 end
4848end
4949# ##
5050
51- MatrixOp (A:: M ) where {M <: AbstractMatrix } = MatrixOp { eltype(A), M} (A, 1 )
52- MatrixOp (T :: Type , A:: M ) where {M <: AbstractMatrix } = MatrixOp {T, M} (A, 1 )
53- MatrixOp (A:: M , n:: Integer ) where {M <: AbstractMatrix } = MatrixOp { eltype(A), M} (A, n )
54- MatrixOp (T :: Type , A:: M , n:: Integer ) where {M <: AbstractMatrix } = MatrixOp {T, M} (A, n )
51+ MatrixOp (A:: M ) where {M <: AbstractMatrix } = MatrixOp ( eltype (A), ( size (A, 2 ),), A )
52+ MatrixOp (D :: Type , A:: M ) where {M <: AbstractMatrix } = MatrixOp (D, ( size (A, 2 ),), A )
53+ MatrixOp (A:: M , n:: Integer ) where {M <: AbstractMatrix } = MatrixOp ( eltype (A), ( size (A, 2 ), n), A )
54+ MatrixOp (D :: Type , A:: M , n:: Integer ) where {M <: AbstractMatrix } = MatrixOp (D, ( size (A, 2 ), n), A )
5555
5656import Base: convert
57- convert (:: Type{LinearOperator} , L:: M ) where {T,M<: AbstractMatrix{T} } = MatrixOp {T,M} (L,1 )
58- convert (:: Type{LinearOperator} , L:: M , n:: Integer ) where {T,M<: AbstractMatrix{T} } = MatrixOp {T,M} (L, n)
57+ convert (:: Type{LinearOperator} , L:: M ) where {T, M<: AbstractMatrix{T} } = MatrixOp {T, T, M} (L,1 )
58+ convert (:: Type{LinearOperator} , L:: M , n:: Integer ) where {T, M<: AbstractMatrix{T} } = MatrixOp {T, T, M} (L, n)
59+ convert (:: Type{LinearOperator} , dom:: Type , dim_in:: Tuple , L:: AbstractMatrix ) = MatrixOp (dom, dim_in, L)
5960
6061# Mappings
6162
62- A_mul_B! (y:: AbstractArray , L:: MatrixOp{M, T} , b:: AbstractArray ) where {M, T} = A_mul_B! (y, L. A, b)
63- Ac_mul_B! (y:: AbstractArray , L:: MatrixOp{M, T} , b:: AbstractArray ) where {M, T} = Ac_mul_B! (y, L. A, b)
63+ A_mul_B! (y:: AbstractArray , L:: MatrixOp{D, T, M} , b:: AbstractArray ) where {D, T, M} = A_mul_B! (y, L. A, b)
64+ Ac_mul_B! (y:: AbstractArray , L:: MatrixOp{D, T, M} , b:: AbstractArray ) where {D, T, M} = Ac_mul_B! (y, L. A, b)
65+
66+ # Special Case, real b, complex matrix
67+ function Ac_mul_B! (y:: AbstractArray , L:: MatrixOp{D, T} , b:: AbstractArray ) where {D <: Real , T <: Complex }
68+ yc = zeros (T,size (y))
69+ Ac_mul_B! (yc, L. A, b)
70+ y .= real .(yc)
71+ end
6472
6573# Properties
6674
67- domainType (L:: MatrixOp{T, M } ) where {T, M } = T
68- codomainType (L:: MatrixOp{T, M } ) where {T, M } = T
75+ domainType (L:: MatrixOp{D, T } ) where {D, T } = D
76+ codomainType (L:: MatrixOp{D, T } ) where {D, T } = D <: Real && T <: Complex ? T : D
6977
7078function size (L:: MatrixOp )
7179 if L. n_col_in == 1
0 commit comments