Closed tomasaschan closed 9 years ago
Oh, I should add a couple of tests. Brb... Tests added and squashed.
Could you give an example where mod
of a dual number makes sense?
Sure: right here.
It might not be so straightforward just from the code, but the application is interpolation of data, in this case with periodic extrapolation (we use mod
for reflecting extrapolation too). We've taken care to allow for indexing with anything that isa(x, Number)
, and dual numbers as indices have a very real use case for evaluating both the interpolant and its approximate derivative (i.e. if the interpolant is a quadratic spline, the derivative is a piece-wise linear function) simultaneously.
Right before we actually forward the indices to the wrapped arrays, we use convert real(x)
to an integer to avoid InexactError
s, but there can be quite a few things happening before we reach that point. DualNumbers
have been sort-of our guinea pig for trying out that this all works (mainly because we can then also use it to test our implementation of the gradient
function...) so there might be lots of other Number
types that we think we support but don't - currently, the spec for what works is this:
Number
+
, -
, *
and /
mod
(which is needed specifically for periodic and reflecting extrapolation)@mlubin Any further comments on this?
Squashing would be appreciated
Done.
Thanks a lot for merging! It would be extra awesome if you were able to tag a new version as well, to allow the tests in tlycken/Interpolations.jl#50 to pass without me having to modify my build script to check out the master
branch of DualNumbers.jl :)
Done. CC @jrevels for port to ForwardDiff
I just made this work on the real part and leave the dual part as-is, because that's what I need in my application. I guess that should be OK at least in some aspect, since anywhere
mod
is applicable, periodicity is implied which should make the derivative the same, but if you have better ideas, let me know :)