-
Notifications
You must be signed in to change notification settings - Fork 1
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
Reimplement linear methods using recursive method #12
Merged
Merged
Changes from 7 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a57b84d
replace cuboid method with recursive
jlogan03 03030dd
backfill changelog
jlogan03 eda24b4
touch up docs. implement convenience functions that allocate for the…
jlogan03 ead1c08
format
jlogan03 c9743a8
use interpn_alloc functions in doctests to get coverage
jlogan03 6a9e2d6
update changelog
jlogan03 f19bb41
update changelog
jlogan03 dae90e8
remove all inlining annotations
jlogan03 63e9312
update changelog
jlogan03 03cc7ec
sprinkle some #[inline] on the leaves
jlogan03 563500e
fix typo
jlogan03 d985fa4
update changelog
jlogan03 5e4e2bb
add tests of grid cell alignment and fix grid cell alignment issues
jlogan03 8ed4ecb
format
jlogan03 218377b
update changelog
jlogan03 dd79495
changelog formatting
jlogan03 8c7abad
update readme
jlogan03 39cbcd7
test more points in hat func tests
jlogan03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,60 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
## 0.4.3 - 2024-08-03 | ||
|
||
## [Unreleased] | ||
## Added | ||
|
||
## [0.1.0](https://github.com/jlogan03/interpn/releases/tag/v0.1.0) - 2023-11-22 | ||
* Implement `interpn_alloc` function for each method, which allocates a Vec for the output | ||
|
||
### Other | ||
- Squash early development | ||
## Changed | ||
|
||
* Use recursive method to evaluate multilinear interpolation instead of hypercube method | ||
* This makes extrapolation cost consistent with interpolation cost, and reduces nominal perf scaling | ||
* Shows about 2x slower perf in micro-benchmarks, but about 2x faster in end-to-end benchmarks after the Python bindings | ||
* Need to improve benchmarking strategy to better capture perf in real-life usage | ||
* Reduce repeated documentation | ||
|
||
## 0.4.2 - 2024-05-12 | ||
|
||
## Added | ||
|
||
* Implement cubic rectilinear method | ||
|
||
## 0.4.1 - 2024-05-06 | ||
|
||
## Fixed | ||
|
||
* Fix grid cell index selection to properly center the grid cell s.t. t=0 corresponds to index 1 | ||
|
||
## Added | ||
|
||
* Add test of cubic method against sine function to capture potential problems not visible when testing against linear and quadratic functions | ||
|
||
## 0.4.0 - 2024-05-05 | ||
|
||
## Changes | ||
|
||
* Implement cubic interpolation for regular grid | ||
* Continuous first derivative everywhere | ||
* Option to clamp to linear extrapolation to prevent unwanted extrapolation of local curvature | ||
* Test linearized method against linear function in both interpolation and extrapolation | ||
* Test un-linearized method against quadratic function in both interpolation and extrapolation | ||
|
||
## 0.3.0 - 2023-12-17 | ||
|
||
## Changed | ||
|
||
* Remove initial guess for cell index from rectilinear method | ||
* Collapse some loops | ||
* Remove support for negative step sizes for regular grid in favor of reducing number of abs() calls | ||
* Remove some saturating sub calls that are not needed now that degenerate grids are not supported | ||
* Get indexing dimension product in the same way for rectilinear method as for regular grid method | ||
* Use better initial value for folds | ||
* Update docs | ||
* Use optimizations for tests because it's faster overall | ||
|
||
## 0.2.0 - 2023-12-06 | ||
|
||
## Changed | ||
|
||
* Propagate Result everywhere that unwrap or assert! was being used |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably don't want
inline(always)
here. In factinline(always)
is probably best avoided pretty much always.Inlining in LLVM happens "leaves-first", which is backwards from how most of our intuition would expect it to happen. The LLVM inliner on its own would probably decide to inline the
::new()
call and the.interp()
call into this function.Then the
#[inline(always)]
will force it to inline this function into all call sites, and you'll end up with the contents ofMulticubicRectilinear::new()
andMulticubicRectilinear::interp()
inlined all over the place separately. That's probably not desirable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - each instance of inlining directives in here was originally checked in criterion benchmarks, but I'm finding lately that the benchmarks end up compiled somewhat differently from downstream usages. I'll check how it looks in end-to-end benchmarks via the python bindings with more reasonable inlining annotations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The perf gains from gratuitous inlining do appear to be an artifact of benchmarking. This snip (benchmarks running after switching from less-inlined version of both linear calcs back to unmodified) would indicate a significant perf regression for the specific case of evaluating one point at a time, which is an important case for differentiation:
However, end-to-end benchmarks through the python bindings do not show any significant degradation for the case of 1 observation point:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rectilinear method doesn't show any significant change here, possibly because the core library bisection search is fairly low in the inlining tree, and is marked
inline(never)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No identifiable change in end-to-end benchmarks in python after removing all inlining annotations, even for the single-observation-point cases that see 2x slowdown in rust benchmarks. This should help embedded usages as well, since opt-level=s builds will behave more as expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: monomorphization bloat - definitely a thing that I think about. In this case, the only generics are on the data type and max dimensionality. The only types in common use that implement Float are f32 and f64 in core, plus f16 and f128 available in crates, and I don't anticipate seeing many uses of MAXDIMS other than the default of 8 since that's already an unreasonably large number of dimensions and doesn't affect perf noticeably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
#[inline]
is fine if you have leaf code you expect to be hot. It's really just#[inline(always)]
especially on large non-leaf functions that ends up being problematic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed - in this case, having just #[inline] doesn't produce any change in performance (even in the hypersensitive micro benchmarks), probably because the hot leaf functions are already small enough that they get inlined without adjusting the weights. So, might as well remove the manual annotations and just leave it to the compiler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this a little more - even in an opt-level=s build, you'd still want those functions to inline because they're tiny and the effect on perf would be really punishing if they didn't get inlined. So I'll sprinkle a few #[inline] back in there just in case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sprinkled some #[inline] on the chain of functions at the very bottom of the recursion for each interpolator type. No effect on benchmarks at all at opt-level=3, but might help keep something silly from happening in a different build someday