Skip to content

Commit 07e17e8

Browse files
authored
orthogonalize conversion_type, maxspace, union_rule (#325)
* orthogonalize conversion_type, maxspace, union_rule * fix inference in any * simplify any condition
1 parent ba0c997 commit 07e17e8

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/Space.jl

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,9 @@ for FUNC in (:conversion_rule,:maxspace_rule,:union_rule)
191191
@eval $FUNC(a, b) = _conversion_rule(a, b)
192192
end
193193

194-
195-
196-
for FUNC in (:conversion_type,:maxspace)
197-
@eval begin
198-
$FUNC(a::UnsetSpace,b::UnsetSpace) = a
199-
$FUNC(a::UnsetSpace,b::Space) = b
200-
$FUNC(a::Space,b::UnsetSpace) = a
201-
end
202-
end
203-
194+
pick_maybe_nonambiguous_space(a::Space, b...) = a
195+
pick_maybe_nonambiguous_space(a::AmbiguousSpace, b) = pick_maybe_nonambiguous_space(b)
196+
pick_maybe_nonambiguous_space(a::NoSpace, b...) = a
204197

205198
"""
206199
conversion_type(a::Space, b::Space)
@@ -210,7 +203,10 @@ Override `ApproxFun.conversion_rule` when adding new `Conversion` operators.
210203
211204
See also [`maxspace`](@ref)
212205
"""
213-
function conversion_type(a,b)
206+
function conversion_type(a, b)
207+
if a isa UnsetSpace || b isa UnsetSpace
208+
return pick_maybe_nonambiguous_space(a, b)
209+
end
214210
if spacescompatible(a,b)
215211
a
216212
elseif !domainscompatible(a,b)
@@ -235,6 +231,10 @@ See also [`conversion_type`](@ref)
235231
"""
236232
maxspace(a,b) = NoSpace() # TODO: this fixes weird bug with Nothing
237233
function maxspace(a::Space, b::Space)
234+
if a isa UnsetSpace || b isa UnsetSpace
235+
return pick_maybe_nonambiguous_space(a, b)
236+
end
237+
238238
if spacescompatible(a,b)
239239
return a
240240
elseif !domainscompatible(a,b)
@@ -290,11 +290,11 @@ end
290290
# this is used primarily for addition of two funs
291291
# that may be incompatible
292292
union(a::AmbiguousSpace, b::AmbiguousSpace) = b
293-
union_by_union_rule(a::AmbiguousSpace, b::Space) = b
294-
union_by_union_rule(a::Space, b::AmbiguousSpace) = a
295-
296293

297294
function union_by_union_rule(@nospecialize(a::Space), @nospecialize(b::Space))
295+
if a isa AmbiguousSpace || b isa AmbiguousSpace
296+
return pick_maybe_nonambiguous_space(a, b)
297+
end
298298
if spacescompatible(a,b)
299299
if isambiguous(domain(a))
300300
return b
@@ -319,7 +319,7 @@ function union(@nospecialize(a::Space), @nospecialize(b::Space))
319319
crc = union_by_union_rule(cspa,cspb)
320320
crc isa NoSpace || return crc
321321
end
322-
# TODO: Uncomment when Julia bug is fixed
322+
323323
cr2=maxspace(a,b) #Max space since we can convert both to it
324324
cr2 isa NoSpace || return cr2
325325

@@ -591,12 +591,9 @@ domain(S::ZeroSpace) = S.domain
591591
dimension(::ZeroSpace) = 0
592592

593593
spacescompatible(::ZeroSpace,::ZeroSpace) = true
594-
for FUNC in (:conversion_type,:maxspace)
595-
@eval begin
596-
$FUNC(::ZeroSpace,::UnsetSpace) = UnsetSpace()
597-
$FUNC(::UnsetSpace,::ZeroSpace) = UnsetSpace()
598-
end
599-
end
594+
595+
pick_maybe_nonambiguous_space(a::UnsetSpace, b::ZeroSpace) = a
596+
pick_maybe_nonambiguous_space(a::ZeroSpace, b::UnsetSpace) = b
600597

601598

602599
"""

0 commit comments

Comments
 (0)