소스 검색

add vectorized scattcoeffs

Konstantin Ladutenko 6 년 전
부모
커밋
387df4bd2a
4개의 변경된 파일27개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 0
      Makefile
  2. 1 0
      scattnlay2/__init__.py
  3. 22 0
      scattnlay2/main.py
  4. 3 3
      src/nmie-pybind11.cc

+ 1 - 0
Makefile

@@ -67,6 +67,7 @@ fieldnlay-mp: $(SRCDIR)/nearfield.cc $(SRCDIR)/nmie.cc $(CXX_NMIE_HEADERS)
 
 lib:
 	c++ -O3 -Wall -shared -std=c++11 -fPIC `python3 -m pybind11 --includes` $(SRCDIR)/nmie.cc $(SRCDIR)/nmie-pybind11.cc  -lm -o example`python3-config --extension-suffix`
+	mv example`python3-config --extension-suffix` scattnlay2
 clean:
 	$(PYTHON) setup.py clean
 	$(MAKE) -f $(CURDIR)/debian/rules clean

+ 1 - 0
scattnlay2/__init__.py

@@ -0,0 +1 @@
+# import main

+ 22 - 0
scattnlay2/main.py

@@ -0,0 +1,22 @@
+from scattnlay2.example import scattcoeffs_, scattnlay_,  fieldnlay_
+import numpy as np
+def scattcoeffs(x, m, nmax=-1, pl=-1, nstore=1000):
+    if len(x.shape) != 2:
+        raise ValueError('The size parameter (x) should be 2-D NumPy array.')
+    if len(m.shape) != 2:
+        raise ValueError('The relative refractive index (m) should be 2-D NumPy array.')
+    if nmax != -1: nstore = nmax
+    total_evaluations = len(x)
+    terms = np.zeros((total_evaluations), dtype=int)
+    an = np.zeros((total_evaluations, nstore), dtype =complex)
+    bn = np.zeros((total_evaluations, nstore), dtype =complex)
+    for i in range(total_evaluations):
+        terms[i], a, b = scattcoeffs_(x[i], m[i], nmax=nmax, pl=pl)
+        if terms[i] > nstore:
+            raise ValueError('Not enougth storage was allocated to keep all terms.\n'
+                             'Increase value of "nstore" argument in "scattcoeffs" function!')
+        an[i,:terms[i]] = a
+        bn[i,:terms[i]] = b
+    return terms, an, bn
+        
+#scattcoeffs()

+ 3 - 3
src/nmie-pybind11.cc

@@ -165,14 +165,14 @@ py::tuple py_fieldnlay(const py::array_t<double, py::array::c_style | py::array:
 PYBIND11_MODULE(example, m) {
     m.doc() = "pybind11 example plugin"; // optional module docstring
 
-    m.def("scattcoeffs", &py_ScattCoeffs, "test",
+    m.def("scattcoeffs_", &py_ScattCoeffs, "test",
           py::arg("x"), py::arg("m"),
           py::arg("nmax")=-1, py::arg("pl")=-1);
-    m.def("scattnlay", &py_scattnlay, "test",
+    m.def("scattnlay_", &py_scattnlay, "test",
           py::arg("x"), py::arg("m"),
           py::arg("theta")=py::array_t<double>(0),
           py::arg("nmax")=-1, py::arg("pl")=-1);
-    m.def("fieldnlay", &py_fieldnlay, "test",
+    m.def("fieldnlay_", &py_fieldnlay, "test",
           py::arg("x"), py::arg("m"),
           py::arg("xp"),py::arg("yp"),py::arg("zp"),
           py::arg("nmax")=-1, py::arg("pl")=-1);