You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Yassine Damerdji (Jira)" <ji...@apache.org> on 2020/04/06 03:07:00 UTC
[jira] [Created] (MATH-1530) Spline interpolation : Avoid
recomputing indexes when possible
Yassine Damerdji created MATH-1530:
--------------------------------------
Summary: Spline interpolation : Avoid recomputing indexes when possible
Key: MATH-1530
URL: https://issues.apache.org/jira/browse/MATH-1530
Project: Commons Math
Issue Type: Improvement
Reporter: Yassine Damerdji
In org.apache.commons.math4.analysis.interpolation.SplineInterpolator and in org.apache.commons.math4.analysis.interpolation.AkimaSplineInterpolator, many indices are recomputed many times.
Example :
{code:java}
for (int i = 1; i < n; i++) {
g = 2d * (x[i+1] - x[i - 1]) - h[i - 1] * mu[i -1];
mu[i] = h[i] / g;
z[i] = (3d * (y[i + 1] * h[i - 1] - y[i] * (x[i + 1] - x[i - 1])+ y[i - 1] * h[i]) / (h[i - 1] * h[i]) - h[i - 1] * z[i - 1]) / g;
}{code}
can be replaced by :
{code:java}
int i = 1;
int iPlusOne = 2;
int iMinusOne = 0;
while (i < n) {
g[i] = 2d * (x[iPlusOne] - x[iMinusOne]) - h[iMinusOne] * mu[iMinusOne];
mu[i] = h[i] / g[i];
iMinusOne = i;
i = iPlusOne;
iPlusOne = iPlusOne + 1;
}
{code}
In my tests, I saved almost 2% of processing time with this optimization.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)