-
Notifications
You must be signed in to change notification settings - Fork 174
Labels
L: MathIssue addresses Modelica.MathIssue addresses Modelica.MathenhancementNew feature or enhancementNew feature or enhancement
Milestone
Description
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.
- If
- 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.
Metadata
Metadata
Assignees
Labels
L: MathIssue addresses Modelica.MathIssue addresses Modelica.MathenhancementNew feature or enhancementNew feature or enhancement