Browse Source

Reorganized source code.

Ovidio Peña Rodríguez 6 years ago
parent
commit
f5a3b67573
4 changed files with 46 additions and 48 deletions
  1. 3 38
      src/nmie-impl.cc
  2. 42 8
      src/nmie-precision.hpp
  3. 0 1
      src/nmie-pybind11.cc
  4. 1 1
      src/nmie.cc

+ 3 - 38
src/nmie-impl.hpp → src/nmie-impl.cc

@@ -59,10 +59,9 @@
 #include <vector>
 
 namespace nmie {  
-  //helpers
+  //helper functions
+
 
-  
-  
   template<class T> inline T pow2(const T value) {return value*value;}
 
   template<class T> inline T cabs(const std::complex<T> value)
@@ -80,42 +79,8 @@ namespace nmie {
     return std::polar(r, x.imag()); 
   }  
 
-  template <typename ToFloatType, typename FromFloatType>
-  std::vector<ToFloatType> ConvertVector(const std::vector<FromFloatType> x) {
-    std::vector<ToFloatType> new_x;
-    for (auto element : x) {
-      new_x.push_back(static_cast<ToFloatType>(element));
-    }
-    return new_x;
-  }
-
-  template <typename ToFloatType, typename FromFloatType>
-  std::vector<std::complex<ToFloatType> > ConvertComplexVector(std::vector<std::complex<FromFloatType> > x) {
-    std::vector<std::complex<ToFloatType> > new_x;
-    for (auto element : x) {
-      new_x.push_back(std::complex<ToFloatType>(static_cast<ToFloatType>(element.real()),
-                                                static_cast<ToFloatType>(element.imag()) ) );
-    }
-    return new_x;
-  }
-
-  template <typename ToFloatType, typename FromFloatType>
-  std::vector<std::vector<std::complex<ToFloatType> > > ConvertComplexVectorVector(std::vector<std::vector<std::complex<FromFloatType> > > x) {
-    std::vector<std::vector<std::complex<ToFloatType> > > new_x;
-    std::vector<std::complex<ToFloatType> >  new_y;
-    for (auto y : x) {
-      new_y.clear();
-      for (auto element : y) {
-        new_y.push_back(std::complex<ToFloatType>(static_cast<ToFloatType>(element.real()),
-                                                  static_cast<ToFloatType>(element.imag()) ) );
-      }
-      new_x.push_back(new_y);
-    }
-    return new_x;
-  }
-  
-  
 
+  //class implementation
 
   // ********************************************************************** //
   // Returns previously calculated Qext                                     //

+ 42 - 8
src/nmie-precision.hpp

@@ -49,14 +49,48 @@
 #endif  // MULTI_PRECISION
 
 namespace nmie {
-    #ifdef MULTI_PRECISION
-	namespace nmm = boost::multiprecision;
-	typedef nmm::number<nmm::cpp_bin_float<MULTI_PRECISION> > FloatType;
-    #else
-	namespace nmm = std;
-	typedef double FloatType;
-	//typedef float FloatType;
-    #endif  // MULTI_PRECISION
+  #ifdef MULTI_PRECISION
+  namespace nmm = boost::multiprecision;
+  typedef nmm::number<nmm::cpp_bin_float<MULTI_PRECISION> > FloatType;
+  #else
+  namespace nmm = std;
+  typedef double FloatType;
+  //typedef float FloatType;
+  #endif  // MULTI_PRECISION
+
+  template <typename ToFloatType, typename FromFloatType>
+  std::vector<ToFloatType> ConvertVector(const std::vector<FromFloatType> x) {
+    std::vector<ToFloatType> new_x;
+    for (auto element : x) {
+      new_x.push_back(static_cast<ToFloatType>(element));
+    }
+    return new_x;
+  }
+
+  template <typename ToFloatType, typename FromFloatType>
+  std::vector<std::complex<ToFloatType> > ConvertComplexVector(std::vector<std::complex<FromFloatType> > x) {
+    std::vector<std::complex<ToFloatType> > new_x;
+    for (auto element : x) {
+      new_x.push_back(std::complex<ToFloatType>(static_cast<ToFloatType>(element.real()),
+                                                static_cast<ToFloatType>(element.imag()) ) );
+    }
+    return new_x;
+  }
+
+  template <typename ToFloatType, typename FromFloatType>
+  std::vector<std::vector<std::complex<ToFloatType> > > ConvertComplexVectorVector(std::vector<std::vector<std::complex<FromFloatType> > > x) {
+    std::vector<std::vector<std::complex<ToFloatType> > > new_x;
+    std::vector<std::complex<ToFloatType> >  new_y;
+    for (auto y : x) {
+      new_y.clear();
+      for (auto element : y) {
+        new_y.push_back(std::complex<ToFloatType>(static_cast<ToFloatType>(element.real()),
+                                                  static_cast<ToFloatType>(element.imag()) ) );
+      }
+      new_x.push_back(new_y);
+    }
+    return new_x;
+  }
 
 }  // end of namespace nmie
 #endif  // SRC_NMIE_PRECISION_H_

+ 0 - 1
src/nmie-pybind11.cc

@@ -29,7 +29,6 @@
 //    along with this program.  If not, see <http://www.gnu.org/licenses/>.         //
 //**********************************************************************************//
 #include "nmie.hpp"
-#include "nmie-impl.hpp"
 #include "nmie-precision.hpp"
 #include <array>
 #include <tuple>

+ 1 - 1
src/nmie.cc

@@ -46,8 +46,8 @@
 // Hereinafter all equations numbers refer to [2]                                   //
 //**********************************************************************************//
 #include "nmie.hpp"
-#include "nmie-impl.hpp"
 #include "nmie-precision.hpp"
+#include "nmie-impl.cc"
 #include <array>
 #include <algorithm>
 #include <cstdio>