-
Notifications
You must be signed in to change notification settings - Fork 11
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
handle interp for integers by casting and rounding (#71) #142
Conversation
1. We add a `r::Union{RoundingMode, Nothing}=nothing` to `Interpolate`, avoiding any breaking changes. 2. Added unit tests for unsigned integers and cases with and without the RoundingMode. 3. Increment calculation: - Still using `(next - prev) / n` in the default case - If a rounding mode is specified then `div` is used with the corresponding mode (avoids `InexactError`) - If we're given unsigned ints then we convert them to integers for the increment calculation (avoids integer overflow)
I hope you don't mind. I opted to add the commit to your PR to retain the commit history. The force push was to trigger the CI as it was disabled. Adding a rounding mode and dispatching on the increment calculation mostly resolves #71 without introducing a breaking change. Feel free to check the new tests in case I missed something. |
Nope, I don't mind. Thanks! Looks good, I'll have a chance to test it later. I don't think I'll have anything to add. |
I found what looks to be a problem with interpolate going past a lower boundary, here are some cases:
Making the gap between the top and bottom value smaller (in this example, it was 5 or lower) makes it not go past the bottom value, but gives RoundUp instead of RoundNearest:
|
Right, forgot rounding would violate the increment assumption from before. I've added a fix:
|
Alright if there aren’t any comments I’m gonna go ahead and merge/tag this. |
I don't mind if you merge it. This is for future reference (maybe another issue), but my only problem is that the code doesn't handle partial increments as expected. For example:
The user can always cast their data to floats, but then it would be the same as before. For discrete types that might require a variable increment between values in gaps (e.g. integers), maybe we can dispatch This would allocate intermediate vectors but it would be better than having to cast the entire input to floats. Any ideas or thoughts? |
Using a generator and setting the gap slices doesn't allocate and gives results that are more even over larger gaps
|
Sure. If we don't care about the increment type, then I think just rounding/clamping on the insert could make sense. |
…cations + some tests
Well I have something here that might work. It does the interpolation in floating point space, but uses a generator for to avoid allocation. |
The second commit is just to ignore RoundingMode for floats, probably don't want to have the same RoundingMode apply to different vectors in a mixed dataset. Anyway, we usually don't want to round floats. |
…ger values to integers on insertion.
Sure, makes sense to me 👍🏻 I just added a commit to minimize the changes. Rather than creating a generator with duplicated logic to insert values, we can just dispatch on two special cases:
|
I pushed what I had now (based on your feedback + some benchmarking) in case I can't get back to you quick enough. I don't know if you're interested, but I figure sharing what I have is better. |
1. We just need a kernel function barrier to avoid type inner loop type instability with integers 2. The generator caused overhead for the default floats case 3. Simplified some of the indexing logic since the kernel function can handle most of it. 4. Add some comments about why all these extra internal functions exist.
This is a simple solution for #71.