Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-1530

Spline interpolation : Avoid recomputing indexes when possible

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Done
    • None
    • 4.0
    • None
    • None

    Description

      In org.apache.commons.math4.analysis.interpolation.SplineInterpolator and in org.apache.commons.math4.analysis.interpolation.AkimaSplineInterpolator, many indices are recomputed many times.

      Example :

      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;
      }

      can be replaced by :

      
      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;
      }
      

      In my tests, I saved almost 2% of processing time with this optimization.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ydamerdj Yassine Damerdji
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: