@@ -28,71 +28,58 @@ LinearOperators.storage_type(op::DiagOp) = typeof(op.Mv5)
28
28
29
29
30
30
"""
31
- DiagOp(ops::AbstractLinearOperator ...)
32
- DiagOp(ops::Vector{AbstractLinearOperator })
33
- DiagOp(ops::NTuple{N,AbstractLinearOperator })
31
+ DiagOp(ops...)
32
+ DiagOp(ops::Vector{... })
33
+ DiagOp(ops::NTuple{N,... })
34
34
35
- create a bloc-diagonal operator out of the `LinearOperator`s contained in ops
35
+ create a bloc-diagonal operator out of the `LinearOperator`s or `Array`s contained in ops
36
36
"""
37
- DiagOp (ops:: AbstractLinearOperator... ) = DiagOp (ops)
38
-
39
37
function DiagOp (ops)
40
38
nrow = 0
41
39
ncol = 0
42
40
S = LinearOperators. storage_type (first (ops))
43
41
for i = 1 : length (ops)
44
- nrow += ops[i]. nrow
45
- ncol += ops[i]. ncol
42
+ nrow += size ( ops[i], 1 )
43
+ ncol += size ( ops[i], 2 )
46
44
S = promote_type (S, LinearOperators. storage_type (ops[i]))
47
45
end
48
46
49
- xIdx = cumsum (vcat (1 ,[ops[i]. ncol for i= 1 : length (ops)]))
50
- yIdx = cumsum (vcat (1 ,[ops[i]. nrow for i= 1 : length (ops)]))
47
+ xIdx = cumsum (vcat (1 ,[size ( ops[i], 2 ) for i= 1 : length (ops)]))
48
+ yIdx = cumsum (vcat (1 ,[size ( ops[i], 1 ) for i= 1 : length (ops)]))
51
49
52
50
Op = DiagOp {eltype(first(ops)), S, typeof(ops)} ( nrow, ncol, false , false ,
53
- (res,x) -> (diagOpProd (res,x,nrow,xIdx,yIdx,ops... )),
54
- (res,y) -> (diagOpTProd (res,y,ncol,yIdx,xIdx,ops... )),
55
- (res,y) -> (diagOpCTProd (res,y,ncol,yIdx,xIdx,ops... )),
51
+ (res,x) -> (diagOpProd (res,x,nrow,xIdx,yIdx,ops)),
52
+ (res,y) -> (diagOpTProd (res,y,ncol,yIdx,xIdx,ops)),
53
+ (res,y) -> (diagOpCTProd (res,y,ncol,yIdx,xIdx,ops)),
56
54
0 , 0 , 0 , false , false , false , S (undef, 0 ), S (undef, 0 ),
57
55
[ops... ], false , xIdx, yIdx)
58
56
59
57
return Op
60
58
end
59
+ DiagOp (ops... ) = DiagOp (collect (ops))
61
60
62
- function DiagOp (op:: AbstractLinearOperator , N= 1 ; copyOpsFn = copy)
63
- nrow = N* op. nrow
64
- ncol = N* op. ncol
61
+ function DiagOp (op:: Union{AbstractLinearOperator{T}, AbstractArray{T}} , N:: Int64 = 1 ; copyOpsFn = copy) where T <: Number
65
62
ops = [copyOpsFn (op) for n= 1 : N]
66
- S = LinearOperators. storage_type (first (ops))
67
-
68
- xIdx = cumsum (vcat (1 ,[ops[i]. ncol for i= 1 : length (ops)]))
69
- yIdx = cumsum (vcat (1 ,[ops[i]. nrow for i= 1 : length (ops)]))
70
-
71
- Op = DiagOp {eltype(op), S, typeof(ops)} ( nrow, ncol, false , false ,
72
- (res,x) -> (diagOpProd (res,x,nrow,xIdx,yIdx,ops... )),
73
- (res,y) -> (diagOpTProd (res,y,ncol,yIdx,xIdx,ops... )),
74
- (res,y) -> (diagOpCTProd (res,y,ncol,yIdx,xIdx,ops... )),
75
- 0 , 0 , 0 , false , false , false , S (undef, 0 ), S (undef, 0 ),
76
- ops, true , xIdx, yIdx )
77
-
78
- return Op
63
+ op = DiagOp (ops)
64
+ op. equalOps = true
65
+ return op
79
66
end
80
67
81
- function diagOpProd (y:: AbstractVector{T} , x:: AbstractVector{T} , nrow:: Int , xIdx, yIdx, ops :: AbstractLinearOperator... ) where T
68
+ function diagOpProd (y:: AbstractVector{T} , x:: AbstractVector{T} , nrow:: Int , xIdx, yIdx, ops) where T
82
69
for i= 1 : length (ops)
83
70
mul! (view (y,yIdx[i]: yIdx[i+ 1 ]- 1 ), ops[i], view (x,xIdx[i]: xIdx[i+ 1 ]- 1 ))
84
71
end
85
72
return y
86
73
end
87
74
88
- function diagOpTProd (y:: AbstractVector{T} , x:: AbstractVector{T} , ncol:: Int , xIdx, yIdx, ops :: AbstractLinearOperator... ) where T
75
+ function diagOpTProd (y:: AbstractVector{T} , x:: AbstractVector{T} , ncol:: Int , xIdx, yIdx, ops) where T
89
76
for i= 1 : length (ops)
90
77
mul! (view (y,yIdx[i]: yIdx[i+ 1 ]- 1 ), transpose (ops[i]), view (x,xIdx[i]: xIdx[i+ 1 ]- 1 ))
91
78
end
92
79
return y
93
80
end
94
81
95
- function diagOpCTProd (y:: AbstractVector{T} , x:: AbstractVector{T} , ncol:: Int , xIdx, yIdx, ops :: AbstractLinearOperator... ) where T
82
+ function diagOpCTProd (y:: AbstractVector{T} , x:: AbstractVector{T} , ncol:: Int , xIdx, yIdx, ops) where T
96
83
for i= 1 : length (ops)
97
84
mul! (view (y,yIdx[i]: yIdx[i+ 1 ]- 1 ), adjoint (ops[i]), view (x,xIdx[i]: xIdx[i+ 1 ]- 1 ))
98
85
end
0 commit comments