Input dimension checking when evaluating surrogates #376
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.
Fixes #337. Adds a new utility function
_check_input_dimension
which is called for all surrogates before evaluating a point. Provides a helpful error message if there's a dimension mismatch.Example
Benchmarking reveals this to come at a very small cost:
Before
julia> @benchmark my_rad([1.5])
BenchmarkTools.Trial: 10000 samples with 855 evaluations.
Range (min … max): 143.392 ns … 10.876 μs ┊ GC (min … max): 0.00% … 97.94%
Time (median): 146.784 ns ┊ GC (median): 0.00%
Time (mean ± σ): 175.408 ns ± 332.221 ns ┊ GC (mean ± σ): 7.69% ± 4.01%
▆█▆▅▄▂▁ ▁ ▂▄▄▂ ▁ ▁
████████▆▆▇▅▅▅▆▅▅▅▄▅▆▅▄▄▃▅▅▅▅▅▅▅▅▄▄▅▅▅▅▄▇█████████▇▆██▇▆▅▄▅▄▄ █
143 ns Histogram: log(frequency) by time 247 ns <
Memory estimate: 144 bytes, allocs estimate: 3.
After
julia> @benchmark my_rad([1.5])
BenchmarkTools.Trial: 10000 samples with 825 evaluations.
Range (min … max): 151.394 ns … 10.147 μs ┊ GC (min … max): 0.00% … 97.38%
Time (median): 155.394 ns ┊ GC (median): 0.00%
Time (mean ± σ): 196.150 ns ± 340.000 ns ┊ GC (mean ± σ): 6.83% ± 3.89%
▇█▄▃▂▂ ▁▁▁ ▂▄▅▅▂▁▁▂ ▁
████████▇▆▅▆▇▇▇▆▆▇▆▇▆▆▆▆▆▅▅▅▇██████████████▆▄▅▅▄▅▆▅▅▆▆▅▆▄▃▅▄▄ █
151 ns Histogram: log(frequency) by time 302 ns <
Memory estimate: 144 bytes, allocs estimate: 3.