-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove need for valtype of Dual to be <: Real #216
Comments
I know we had discussed some of this offline, but remind me again why Note that whether intervals are mathematically a subset of the reals is irrelevant, since Julia subtype relations are nominal and only have meaning insofar as they organize dispatch rules. Dual numbers don't even constitute a field, but it's still the right decision to have An example where the |
cc @timholy |
This is a case where we suffer from the lack of traits. Thinking of an Now, folks like @dpsanders want to endow them with extra properties. So what we'd like to do is have a multiple-inheritance diagram: abstract type AbstractInterval end
struct IntervalReallike <: (AbstractInterval | Real)
fields
end But we can't do that. We could fake it using the infamous THTT, though. But without a nice syntax for traits, I recognize this might make certain things difficult for |
My previous statement was my attempt at preemptively responding to this kind of argument:
Addressing your ordering example, it seems to me that the question isn't really "how could we mathematically define ordering on a set of intervals", but rather "how are Base comparators actually defined on this implementation of a number type that propagates metadata through user code"? Do these control flow definitions cause I'm not necessarily against removing this restriction - I can enforce things like |
Ditching the mathematical meaning is not quite so simple. The issue is that some of us want intervals that hew to the mathematical meaning, for purposes other than estimating computational error. The name That's not a complete tragedy, of course; if it can't be shared, at least IntervalSets its a pretty small package. It sure would be nice to share some functionality (because it increases composability), but we do have to weigh that against other needs. If we do decide that we simply can't share, it might be worth writing this example up briefly as a julia issue, as one example of how important traits will be some day. |
I need to sit on this some more (I'm still somewhat uneasy about it), but I think I'd be fine with restricting the struct DualValid end
dualvalidity(::DataType) = nothing
dualvalidity(::Type{<:Real}) = DualValid()
struct Dual{T,V,N} <: Real
value::V
partials::Partials{N,V}
Dual{T,V,N}(value::V, partials::Partials{N,V}, ::DualValid) where {V,N} = new{T,V,N}(value, partials)
Dual{T,V,N}(value::V, partials::Partials{N,V}, ::Void) where {V,N} = error("ya done goofed!")
end
(::Type{Dual{T}})(value::V, partials::Partials{N,V}) where {T,N,V} = Dual{T,V,N}(value, partials, dualvalidity(T)) cc @mlubin @KristofferC (interested to hear if you guys have any opinions on this) |
No objections to traits here. |
👍 I'd like the trait version of this as well |
Instead, use an extensible function that the constructor uses to check whether a type is valid to be used as `Dual`'s scalar type. Fixes JuliaDiff#216
Instead, use an extensible function that the constructor uses to check whether a type is valid to be used as `Dual`'s scalar type. Fixes #216
It would be useful to remove the need for the eltype of
Dual.value
to be<:Real
.Cf. the discussion at JuliaIntervals/IntervalArithmetic.jl#2
The text was updated successfully, but these errors were encountered: