Advertisement
Guest User

Untitled

a guest
Jan 15th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.04 KB | None | 0 0
  1. --- LHAPDF-6.2.3/src/LogBicubicInterpolator.cc  2019-05-09 09:04:24.000000001 +0200
  2. +++ LHAPDF-6.2.3-patched/src/LogBicubicInterpolator.cc  2020-01-15 13:41:53.000000001 +0100
  3. @@ -56,9 +56,25 @@
  4.  
  5.    }
  6.  
  7. +  static struct {
  8. +    bool isSet = false;
  9. +    // params to check
  10. +    double x;
  11. +    size_t ix;
  12. +    double q2;
  13. +    size_t iq2;
  14. +    // end params
  15. +    double logx;
  16. +    double logq2;
  17. +    double dlogx_1;
  18. +    double tlogx;
  19. +    double dlogq_0;
  20. +    double dlogq_1;
  21. +    double dlogq_2;
  22. +    double tlogq;
  23. +  } _interpolateXQ2_cache;
  24.  
  25. -
  26. -  double LogBicubicInterpolator::_interpolateXQ2(const KnotArray1F& subgrid, double x, size_t ix, double q2, size_t iq2) const {
  27. +    double LogBicubicInterpolator::_interpolateXQ2(const KnotArray1F& subgrid, double x, size_t ix, double q2, size_t iq2) const {
  28.      // Raise an error if there are too few knots even for a linear fall-back
  29.      const size_t nxknots = subgrid.logxs().size();
  30.      const size_t nq2knots = subgrid.logq2s().size();
  31. @@ -75,8 +91,31 @@
  32.      if (iq2+1 > iq2max) // also true if iq2 is off the end
  33.        throw GridError("Attempting to access an Q-knot index past the end of the array, in linear fallback mode");
  34.  
  35. -    const double logx = log(x);
  36. -    const double logq2 = log(q2);
  37. +    if (
  38. +       !_interpolateXQ2_cache.isSet ||
  39. +        _interpolateXQ2_cache.x != x ||
  40. +        _interpolateXQ2_cache.q2 != q2 ||
  41. +        _interpolateXQ2_cache.ix != ix ||
  42. +        _interpolateXQ2_cache.iq2 != iq2
  43. +        )
  44. +    {
  45. +      // set
  46. +      _interpolateXQ2_cache.x = x;
  47. +      _interpolateXQ2_cache.q2 = q2;
  48. +      _interpolateXQ2_cache.ix = ix;
  49. +      _interpolateXQ2_cache.iq2 = iq2;
  50. +      _interpolateXQ2_cache.logx = log(x);
  51. +      _interpolateXQ2_cache.logq2 = log(q2);
  52. +      _interpolateXQ2_cache.dlogx_1 = subgrid.logxs()[ix+1] - subgrid.logxs()[ix];
  53. +      _interpolateXQ2_cache.tlogx = (_interpolateXQ2_cache.logx - subgrid.logxs()[ix]) / _interpolateXQ2_cache.dlogx_1;
  54. +      _interpolateXQ2_cache.dlogq_0 = (iq2 != 0) ? subgrid.logq2s()[iq2] - subgrid.logq2s()[iq2-1] : -1; //< Don't evaluate (or use) if iq2-1 < 0
  55. +      _interpolateXQ2_cache.dlogq_1 = subgrid.logq2s()[iq2+1] - subgrid.logq2s()[iq2];
  56. +      _interpolateXQ2_cache.dlogq_2 = (iq2+1 != iq2max  ) ? subgrid.logq2s()[iq2+2] - subgrid.logq2s()[iq2+1] : -1; //< Don't evaluate (or use) if iq2+2 > iq2max
  57. +      _interpolateXQ2_cache.tlogq = (_interpolateXQ2_cache.logq2 - subgrid.logq2s()[iq2]) / _interpolateXQ2_cache.dlogq_1;
  58. +      _interpolateXQ2_cache.isSet = true;
  59. +    }
  60. +    const double logx = _interpolateXQ2_cache.logx;
  61. +    const double logq2 = _interpolateXQ2_cache.logq2;
  62.  
  63.      // Fall back to LogBilinearInterpolator if either 2 or 3 Q-knots
  64.      if (nq2knots < 4) {
  65. @@ -92,12 +131,12 @@
  66.  
  67.      // Pre-calculate parameters
  68.      /// @todo Cache these between calls, re-using if x == x_prev and Q2 == Q2_prev
  69. -    const double dlogx_1 = subgrid.logxs()[ix+1] - subgrid.logxs()[ix];
  70. -    const double tlogx = (logx - subgrid.logxs()[ix]) / dlogx_1;
  71. -    const double dlogq_0 = (iq2 != 0) ? subgrid.logq2s()[iq2] - subgrid.logq2s()[iq2-1] : -1; //< Don't evaluate (or use) if iq2-1 < 0
  72. -    const double dlogq_1 = subgrid.logq2s()[iq2+1] - subgrid.logq2s()[iq2];
  73. -    const double dlogq_2 = (iq2+1 != iq2max) ? subgrid.logq2s()[iq2+2] - subgrid.logq2s()[iq2+1] : -1; //< Don't evaluate (or use) if iq2+2 > iq2max
  74. -    const double tlogq = (logq2 - subgrid.logq2s()[iq2]) / dlogq_1;
  75. +    const double dlogx_1 = _interpolateXQ2_cache.dlogx_1;
  76. +    const double tlogx = _interpolateXQ2_cache.tlogx;
  77. +    const double dlogq_0 = _interpolateXQ2_cache.dlogq_0; //< Don't evaluate (or use) if iq2-1 < 0
  78. +    const double dlogq_1 = _interpolateXQ2_cache.dlogq_1;
  79. +    const double dlogq_2 = _interpolateXQ2_cache.dlogq_2; //< Don't evaluate (or use) if iq2+2 > iq2max
  80. +    const double tlogq = _interpolateXQ2_cache.tlogq;
  81.  
  82.      /// @todo Statically pre-compute the whole nx * nq gradiant array? I.e. _dxf_dlogx for all points in all subgrids. Memory ~doubling :-/ Could cache them as they are used...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement