Skip to content

Commit 2fa68ef

Browse files
authored
Relax signatures in interlace functions (#257)
* Relax signatures in interlace functions * simplify convert
1 parent f9865dc commit 2fa68ef

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/Operators/general/InterlaceOperator.jl

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ const VectorInterlaceOperator = InterlaceOperator{T,1,DS,RS} where {T,DS,RS<:Spa
8787
const MatrixInterlaceOperator = InterlaceOperator{T,2,DS,RS} where {T,DS,RS<:Space{D,R}} where {D,R<:AbstractVector}
8888

8989

90-
InterlaceOperator(ops::Array{T,p},ds,rs,di,ri,bi) where {T,p} =
91-
InterlaceOperator{T,p,typeof(ds),typeof(rs),
92-
typeof(di),typeof(ri),typeof(bi)}(ops,ds,rs,di,ri,bi)
93-
94-
function InterlaceOperator(ops::AbstractMatrix{Operator{T}},ds::Space,rs::Space) where T
90+
function InterlaceOperator(ops::AbstractMatrix{<:Operator},ds::Space,rs::Space)
9591
# calculate bandwidths TODO: generalize
9692
p=size(ops,1)
9793
dsi = interlacer(ds)
@@ -122,7 +118,7 @@ function InterlaceOperator(ops::AbstractMatrix{Operator{T}},ds::Space,rs::Space)
122118
end
123119

124120

125-
function InterlaceOperator(ops::Vector{Operator{T}},ds::Space,rs::Space) where T
121+
function InterlaceOperator(ops::Vector{<:Operator},ds::Space,rs::Space)
126122
# calculate bandwidths
127123
p=size(ops,1)
128124
if all(isbanded,ops)
@@ -145,27 +141,27 @@ function InterlaceOperator(ops::Vector{Operator{T}},ds::Space,rs::Space) where T
145141
(l,u))
146142
end
147143

148-
function InterlaceOperator(opsin::AbstractMatrix{Operator{T}}) where {T}
144+
function InterlaceOperator(opsin::AbstractMatrix{<:Operator})
149145
isempty(opsin) && throw(ArgumentError("Cannot create InterlaceOperator from empty Matrix"))
150146
ops=promotespaces(opsin)
151147
InterlaceOperator(ops,domainspace(ops),rangespace(ops[:,1]))
152148
end
153149

154-
function InterlaceOperator(opsin::AbstractMatrix{Operator{T}},::Type{DS},::Type{RS}) where {T,DS<:Space,RS<:Space}
150+
function InterlaceOperator(opsin::AbstractMatrix{<:Operator},::Type{DS},::Type{RS}) where {DS<:Space,RS<:Space}
155151
isempty(opsin) && throw(ArgumentError("Cannot create InterlaceOperator from empty Matrix"))
156152
ops=promotespaces(opsin)
157153
InterlaceOperator(ops,DS(components(domainspace(ops))),RS(rangespace(ops[:,1]).spaces))
158154
end
159155

160156

161-
function InterlaceOperator(opsin::RowVector{Operator{T}}) where {T}
157+
function InterlaceOperator(opsin::RowVector{<:Operator})
162158
isempty(opsin) && throw(ArgumentError("Cannot create InterlaceOperator from empty Matrix"))
163159

164160
ops=promotespaces(opsin)
165161
InterlaceOperator(ops,domainspace(ops),rangespace(ops[1]))
166162
end
167163

168-
function InterlaceOperator(opsin::RowVector{Operator{T}},::Type{DS},::Type{RS}) where {T,DS<:Space,RS<:Space}
164+
function InterlaceOperator(opsin::RowVector{<:Operator},::Type{DS},::Type{RS}) where {DS<:Space,RS<:Space}
169165
isempty(opsin) && throw(ArgumentError("Cannot create InterlaceOperator from empty Matrix"))
170166
ops=promotespaces(opsin)
171167
InterlaceOperator(ops,DS(components(domainspace(ops))),rangespace(ops[1]))
@@ -174,13 +170,13 @@ end
174170

175171

176172

177-
InterlaceOperator(opsin::AbstractMatrix{Operator{T}},::Type{DS}) where {T,DS<:Space} =
173+
InterlaceOperator(opsin::AbstractMatrix{<:Operator},::Type{DS}) where {DS<:Space} =
178174
InterlaceOperator(opsin,DS,DS)
179175

180176
InterlaceOperator(opsin::AbstractMatrix,S...) =
181177
InterlaceOperator(Matrix{Operator{mapreduce(eltype,promote_type,opsin)}}(promotespaces(opsin)),S...)
182178

183-
function InterlaceOperator(opsin::Vector{Operator{T}}) where T
179+
function InterlaceOperator(opsin::Union{Vector{<:Operator}, Tuple{Operator, Vararg{Operator}}})
184180
ops=promotedomainspace(opsin)
185181
InterlaceOperator(ops,domainspace(first(ops)),rangespace(ops))
186182
end
@@ -193,10 +189,7 @@ function convert(::Type{Operator{T}},S::InterlaceOperator) where T
193189
if T == eltype(S)
194190
S
195191
else
196-
ops=Array{Operator{T}}(undef, size(S.ops)...)
197-
for j=1:size(S.ops,2),k=1:size(S.ops,1)
198-
ops[k,j]=S.ops[k,j]
199-
end
192+
ops = convert(AbstractArray{Operator{T}}, S.ops)
200193
InterlaceOperator(ops,domainspace(S),rangespace(S),
201194
S.domaininterlacer,S.rangeinterlacer,S.bandwidths)
202195
end
@@ -223,7 +216,7 @@ end
223216

224217

225218

226-
function colstop(M::InterlaceOperator{T},j::Integer) where T
219+
function colstop(M::InterlaceOperator, j::Integer)
227220
# b=bandwidth(M,1)
228221
if isbandedbelow(M)
229222
min(j+bandwidth(M,1)::Int,size(M,1))::Int
@@ -260,7 +253,7 @@ function getindex(op::InterlaceOperator{T,1},k::Integer,j::Integer) where T
260253
op.ops[N][K,j]::T
261254
end
262255

263-
function getindex(op::InterlaceOperator{T},k::Integer) where T
256+
function getindex(op::InterlaceOperator, k::Integer)
264257
if size(op,1) == 1
265258
op[1,k]
266259
elseif size(op,2) == 1
@@ -439,7 +432,7 @@ promotedomainspace(A::InterlaceOperator{T,1},sp::Space) where {T} =
439432
InterlaceOperator(map(op->promotedomainspace(op,sp),A.ops))
440433

441434

442-
interlace(A::AbstractArray{T}) where {T<:Operator} = InterlaceOperator(A)
435+
interlace(A::AbstractArray{<:Operator}) = InterlaceOperator(A)
443436

444437
const OperatorTypes = Union{Operator,Fun,Number,UniformScaling}
445438

@@ -495,7 +488,7 @@ Base.hvcat(rows::Tuple{Vararg{Int}}, D::Union{Fun,Number,UniformScaling}, C::Uni
495488

496489
## Convert Matrix operator to operators
497490

498-
Operator(M::AbstractArray{OO}) where {OO<:Operator} = InterlaceOperator(M)
491+
Operator(M::AbstractArray{<:Operator}) = InterlaceOperator(M)
499492

500493

501494

0 commit comments

Comments
 (0)