JuliaApproximation / DomainSets.jl

A Julia package for describing domains as continuous sets of elements
MIT License
72 stars 12 forks source link

Error using broadcast in setdiff #35

Closed daanhb closed 5 years ago

daanhb commented 5 years ago

The problem is the use of broadcast in setdiff for a UnionDomain and a Domain:

julia> UnionDomain(Interval(0.0, 0.5), Interval(1.0,1.5)) \ Interval(0.0, 1.5)
ERROR: MethodError: no method matching iterate(::Interval{:closed,:closed,Float64})
Closest candidates are:
  iterate(::Core.SimpleVector) at essentials.jl:589
  iterate(::Core.SimpleVector, ::Any) at essentials.jl:589
  iterate(::ExponentialBackOff) at error.jl:171
  ...

The offending line is this one: broadcast is not appropriate here.

dlfivefifty commented 5 years ago

I think we just need to add a Ref to stop it broadcasting over the domain: UnionDomain(setdiff.(elements(d1), Ref(d2)))

daanhb commented 5 years ago

I had a different fix, but using Ref is nicer and I could use it elsewhere too. I'll submit.

daanhb commented 5 years ago

Elsewhere, I was broadcasting over in: in.(xs, domain) gives a similar error. I suppose I could do in.(xs, Ref(domain)) there as well. At first I had disabled broadcasting for domains, but we may want to use it like you mentioned elsewhere to conveniently create maps as in d .* 2.

daanhb commented 5 years ago

Fixed by 9dd60ff