Browse Source

small speedup

Konstantin Ladutenko 10 years ago
parent
commit
190e03aa31
2 changed files with 4 additions and 3 deletions
  1. 1 1
      go.sh
  2. 3 2
      nmie-wrapper.cc

+ 1 - 1
go.sh

@@ -33,7 +33,7 @@ PROGRAM='../../../scattnlay-g'
 rm -rf oprofiletmp
 rm -rf oprofile_data
 time operf $PROGRAM -l 5 0.4642 1.8000 1.7000 0.7114 0.8000 0.7000 0.7393 1.2000 0.0900 0.9168 2.8000 0.2000 1.0000 1.5000 0.4000  -t 0.0 90.0 5 -c test01
-opreport --symbols > opreport.log
+#opreport --symbols > opreport.log
 mkdir oprofiletmp
 opannotate --source --output-dir=./oprofiletmp/
 

+ 3 - 2
nmie-wrapper.cc

@@ -543,14 +543,15 @@ namespace nmie {
 			       std::vector<std::complex<double> >& D3) {
     // Downward recurrence for D1 - equations (16a) and (16b)
     D1[nmax_] = std::complex<double>(0.0, 0.0);
+    const std::complex<double> zinv = 1.0/z;
     for (int n = nmax_; n > 0; n--) {
-      D1[n - 1] = double(n)/z - 1.0/(D1[n] + double(n)/z);
+      D1[n - 1] = double(n)*zinv - 1.0/(D1[n] + double(n)*zinv);
     }
     // Upward recurrence for PsiZeta and D3 - equations (18a) - (18d)
     PsiZeta_[0] = 0.5*(1.0 - std::complex<double>(cos(2.0*z.real()), sin(2.0*z.real()))*exp(-2.0*z.imag()));
     D3[0] = std::complex<double>(0.0, 1.0);
     for (int n = 1; n <= nmax_; n++) {
-      PsiZeta_[n] = PsiZeta_[n - 1]*(static_cast<double>(n)/z - D1[n - 1])*(static_cast<double>(n)/z- D3[n - 1]);
+      PsiZeta_[n] = PsiZeta_[n - 1]*(static_cast<double>(n)*zinv - D1[n - 1])*(static_cast<double>(n)*zinv- D3[n - 1]);
       D3[n] = D1[n] + std::complex<double>(0.0, 1.0)/PsiZeta_[n];
     }
   }