Skip to content
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

Why does Dual inherit from Real but not Number? #156

Closed
xukai92 opened this issue Nov 8, 2016 · 3 comments
Closed

Why does Dual inherit from Real but not Number? #156

xukai92 opened this issue Nov 8, 2016 · 3 comments

Comments

@xukai92
Copy link

xukai92 commented Nov 8, 2016

I thinks the definition should be Dual{N,T<:Real} <: Number.

@jrevels
Copy link
Member

jrevels commented Nov 8, 2016

There was a long discussion about this in a previous issue. It's tempting to think that Dual <: Number in order to mirror the dual number set's mathematical relationship to the set of reals, but the Julia type hierarchy needn't reflect the relationship between these sets. We ultimately decided it would be most practical for Dual <: Real because Dual should programmatically support all Real operations, and be insertable wherever a Real is allowed.

@jrevels jrevels closed this as completed Nov 8, 2016
@xukai92
Copy link
Author

xukai92 commented Nov 8, 2016

Actually I came up with this issue when I was trying to use Dual with Distributions.jl package, where they import functions from Rmath.jl, which replies on external R library. As these functions supports floats and ints, so the define the type with Real in their wrapper. This lead to the fact that I can pass them to the wrapper but it will give error.

@jrevels
Copy link
Member

jrevels commented Nov 17, 2016

Yeah, unfortunately ForwardDiff's Dual cannot be used where generic Real types are not allowed (such as in calls to external libraries). It's an inherent limitation of language-specific AD - the code that's getting differentiated has to be Julia code "all the way down."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants