Skip to content

Commit e8fb103

Browse files
authored
tuples in promoterangespace and friends (#214)
* tuples in promoterangespace and friends * stricter type inference in _maybetypedmap Co-authored-by: Jishnu Bhattacharya <[email protected]>
1 parent cd4b755 commit e8fb103

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/Operators/general/InterlaceOperator.jl

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ function InterlaceOperator(ops::AbstractMatrix{<:Operator},ds::Space,rs::Space)
110110
l,u = (1-dimension(rs),dimension(ds)-1) # not banded
111111
end
112112

113-
114-
InterlaceOperator(ops,ds,rs,
113+
opsm = convert(Matrix{Operator{mapreduce(eltype, promote_type, ops)}}, ops)
114+
InterlaceOperator(opsm,ds,rs,
115115
cache(dsi),
116116
cache(rsi),
117117
(l,u))
@@ -134,8 +134,8 @@ function InterlaceOperator(ops::Vector{<:Operator},ds::Space,rs::Space)
134134
l,u = (1-dimension(rs),dimension(ds)-1) # not banded
135135
end
136136

137-
138-
InterlaceOperator(ops,ds,rs,
137+
opsv = convert(Vector{Operator{mapreduce(eltype, promote_type, ops)}}, ops)
138+
InterlaceOperator(opsv,ds,rs,
139139
cache(BlockInterlacer(tuple(blocklengths(ds)))),
140140
cache(interlacer(rs)),
141141
(l,u))
@@ -176,13 +176,22 @@ InterlaceOperator(opsin::AbstractMatrix{<:Operator},::Type{DS}) where {DS<:Space
176176
InterlaceOperator(opsin::AbstractMatrix,S...) =
177177
InterlaceOperator(Matrix{Operator{mapreduce(eltype,promote_type,opsin)}}(promotespaces(opsin)),S...)
178178

179-
function InterlaceOperator(opsin::Union{Vector{<:Operator}, Tuple{Operator, Vararg{Operator}}})
180-
ops=promotedomainspace(opsin)
181-
InterlaceOperator(ops,domainspace(first(ops)),rangespace(ops))
179+
_convertVector(v::AbstractVector) = convert(Vector, v)
180+
_convertVector(t::Tuple) = [t...]
181+
182+
function InterlaceOperator(opsin::AbstractVector{<:Operator})
183+
ops = promotedomainspace(opsin)
184+
opsv = _convertVector(ops)
185+
InterlaceOperator(opsv, domainspace(first(ops)), rangespace(opsv))
186+
end
187+
function InterlaceOperator(opsin::Tuple{Operator, Vararg{Operator}})
188+
ops = promotedomainspace(opsin)
189+
opsv = _convertVector(ops)
190+
InterlaceOperator(opsv, domainspace(first(ops)), rangespace(opsv))
182191
end
183192

184-
InterlaceOperator(ops::AbstractArray{T,p}) where {T,p} =
185-
InterlaceOperator(Array{Operator{mapreduce(eltype,promote_type,ops)},p}(ops))
193+
InterlaceOperator(ops::AbstractArray) =
194+
InterlaceOperator(Array{Operator{mapreduce(eltype,promote_type,ops)}, ndims(ops)}(ops))
186195

187196

188197
function convert(::Type{Operator{T}},S::InterlaceOperator) where T
@@ -450,7 +459,7 @@ __vcat(a::OperatorTypes, b::OperatorTypes...) = (a, __vcat(b...)...)
450459
__vcat() = ()
451460
function _vcat(A::OperatorTypes...)
452461
Av = __vcat(A...)
453-
InterlaceOperator(vnocat(Av...))
462+
InterlaceOperator(map(x -> convert(Operator, x), Av))
454463
end
455464

456465

src/Operators/spacepromotion.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,37 @@ promotedomainspace(P::Operator,sp::Space,cursp::Space) =
8888

8989
const VectorOrTupleOfOp{O<:Operator} = Union{AbstractVector{O}, Tuple{O, Vararg{O}}}
9090

91+
__maybetypedmap(f, k, ops) = map(op->f(op,k), ops)
92+
_maybetypedmap(f, k, O, ops::AbstractVector) =
93+
strictconvert(Vector{O}, __maybetypedmap(f, k, ops))
94+
_maybetypedmap(f, k, O, ops) = __maybetypedmap(f, k, ops)
95+
9196
function promoterangespace(ops::VectorOrTupleOfOp{O}) where O<:Operator
9297
isempty(ops) && return strictconvert(Vector{Operator{eltype(O)}}, ops)
9398
k=findmaxrangespace(ops)
9499
#TODO: T might be incorrect
95100
T=mapreduce(eltype,promote_type,ops)
96-
Operator{T}[promoterangespace(op,k) for op in ops]
101+
_maybetypedmap(promoterangespace, k, Operator{T}, ops)
97102
end
98103
function promotedomainspace(ops::VectorOrTupleOfOp{O}) where O<:Operator
99104
isempty(ops) && return strictconvert(Vector{Operator{eltype(O)}}, ops)
100105
k=findmindomainspace(ops)
101106
#TODO: T might be incorrect
102107
T=mapreduce(eltype,promote_type,ops)
103-
Operator{T}[promotedomainspace(op,k) for op in ops]
108+
_maybetypedmap(promotedomainspace, k, Operator{T}, ops)
104109
end
105110
function promotedomainspace(ops::VectorOrTupleOfOp{O}, S::Space) where O<:Operator
106111
isempty(ops) && return strictconvert(Vector{Operator{eltype(O)}}, ops)
107112
k=conversion_type(findmindomainspace(ops),S)
108113
#TODO: T might be incorrect
109114
T=promote_type(mapreduce(eltype,promote_type,ops),prectype(S))
110-
Operator{T}[promotedomainspace(op,k) for op in ops]
115+
_maybetypedmap(promotedomainspace, k, Operator{T}, ops)
111116
end
112117

113118

114119

115120
####
116-
# choosedomainspace returns a potental domainspace
121+
# choosedomainspace returns a potential domainspace
117122
# where the second argument is a target rangespace
118123
# it defaults to the true domainspace, but if this is ambiguous
119124
# it tries to decide a space.

0 commit comments

Comments
 (0)