You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suggest the following fairly simple performance improvements. They should be fully backwards compatible.
Special handling of nx=2
This is a small change that avoids the entire double iteration to find an index.
This case is quite common.
Default iLast calculated using linear interpolation.
If iLast is not specified by the caller, then we do a linear search from the start. This is very inefficient for all but the smallest tables.
Calculating an initial guess value by linear interpolation is a a reasonable alternative.
As far as I can tell, there is very little active use of iLast so we often fall back to the inefficient default.
Remove assertion x2>x1.
The test is not very useful because it just tests the two points where our index search stopped. It does not test the input requirement that x is non-decreasing.
The test clutters the code.
I also considered two more extensive changes, but do not propose them.
Replace the linear search by binary search. This has big potential, but the implementation is complicated because the abscissa may contain several identical values. The documentation even defines what should happen.
Remove the iLast argument and the return value iNew. This would be a significant simplification, especially because the function would just return a single number, not a pair of numbers, Also, almost nobody seems to use iLast/iNew. This would obviously be a non-compatible change.
The text was updated successfully, but these errors were encountered:
Just a minor note regarding binary search:
If we decide to implement binary search and keep iLast there is a common doubling up variant that achieves logarithmic complexity in terms distance between the elements (commonly called searching in infinite array).
However, for many common cases interpolation to find the starting point should be good enough.
I suggest the following fairly simple performance improvements. They should be fully backwards compatible.
nx=2
iLast
calculated using linear interpolation.iLast
is not specified by the caller, then we do a linear search from the start. This is very inefficient for all but the smallest tables.iLast
so we often fall back to the inefficient default.I also considered two more extensive changes, but do not propose them.
The text was updated successfully, but these errors were encountered: