|
@@ -58,17 +58,6 @@
|
|
|
#include <iomanip>
|
|
|
#include <vector>
|
|
|
|
|
|
-#include <pybind11/pybind11.h>
|
|
|
-#include <pybind11/numpy.h>
|
|
|
-#include <pybind11/complex.h>
|
|
|
-
|
|
|
-
|
|
|
-namespace py = pybind11;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
namespace nmie {
|
|
|
|
|
|
//**********************************************************************************//
|
|
@@ -358,120 +347,3 @@ namespace nmie {
|
|
|
return 0;
|
|
|
}
|
|
|
} // end of namespace nmie
|
|
|
-
|
|
|
-// // -------------
|
|
|
-// // pure C++ code
|
|
|
-// // -------------
|
|
|
-
|
|
|
-// std::vector<double> length(const std::vector<double>& pos)
|
|
|
-// {
|
|
|
-// size_t N = pos.size() / 2;
|
|
|
-
|
|
|
-// std::vector<double> output(N*3);
|
|
|
-
|
|
|
-// for ( size_t i = 0 ; i < N ; ++i ) {
|
|
|
-// output[i*3+0] = pos[i*2+0];
|
|
|
-// output[i*3+1] = pos[i*2+1];
|
|
|
-// output[i*3+2] = std::pow(pos[i*2+0]*pos[i*2+1],.5);
|
|
|
-// }
|
|
|
-
|
|
|
-// return output;
|
|
|
-// }
|
|
|
-
|
|
|
-// // ----------------
|
|
|
-// // Python interface
|
|
|
-// // ----------------
|
|
|
-
|
|
|
-// namespace py = pybind11;
|
|
|
-
|
|
|
-// // wrap C++ function with NumPy array IO
|
|
|
-// py::array py_length(py::array_t<double, py::array::c_style | py::array::forcecast> array)
|
|
|
-// {
|
|
|
-// // check input dimensions
|
|
|
-// if ( array.ndim() != 2 )
|
|
|
-// throw std::runtime_error("Input should be 2-D NumPy array");
|
|
|
-// if ( array.shape()[1] != 2 )
|
|
|
-// throw std::runtime_error("Input should have size [N,2]");
|
|
|
-
|
|
|
-// // allocate std::vector (to pass to the C++ function)
|
|
|
-// std::vector<double> pos(array.size());
|
|
|
-
|
|
|
-// // copy py::array -> std::vector
|
|
|
-// std::memcpy(pos.data(),array.data(),array.size()*sizeof(double));
|
|
|
-
|
|
|
-// // call pure C++ function
|
|
|
-// std::vector<double> result = length(pos);
|
|
|
-
|
|
|
-// ssize_t ndim = 2;
|
|
|
-// std::vector<ssize_t> shape = { array.shape()[0] , 3 };
|
|
|
-// std::vector<ssize_t> strides = { sizeof(double)*3 , sizeof(double) };
|
|
|
-
|
|
|
-// // return 2-D NumPy array
|
|
|
-// return py::array(py::buffer_info(
|
|
|
-// result.data(), /* data as contiguous array */
|
|
|
-// sizeof(double), /* size of one scalar */
|
|
|
-// py::format_descriptor<double>::format(), /* data type */
|
|
|
-// ndim, /* number of dimensions */
|
|
|
-// shape, /* shape of the matrix */
|
|
|
-// strides /* strides for each axis */
|
|
|
-// ));
|
|
|
-// }
|
|
|
-
|
|
|
-// // wrap as Python module
|
|
|
-// PYBIND11_MODULE(example,m)
|
|
|
-// {
|
|
|
-// m.doc() = "pybind11 example plugin";
|
|
|
-
|
|
|
-// m.def("length", &py_length, "Calculate the length of an array of vectors");
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // int ScattCoeffs(const unsigned int L, const int pl, std::vector<double>& x, std::vector<std::complex<double> >& m,
|
|
|
- // const int nmax, std::vector<std::complex<double> >& an, std::vector<std::complex<double> >& bn) {
|
|
|
-
|
|
|
-
|
|
|
-// std::tuple<
|
|
|
-// int, // used terms
|
|
|
-// py::array_t< std::complex<double>, py::array::c_style | py::array::forcecast>, //an
|
|
|
-// py::array_t< std::complex<double>, py::array::c_style | py::array::forcecast> //bn
|
|
|
-// >
|
|
|
-
|
|
|
-py::tuple py_ScattCoeffs(
|
|
|
- py::array_t<double, py::array::c_style | py::array::forcecast> py_x,
|
|
|
- py::array_t< std::complex<double>, py::array::c_style | py::array::forcecast> py_m// ,
|
|
|
- // const int nmax=-1, const int pl=-1
|
|
|
- ) {
|
|
|
-
|
|
|
- std::vector<double> c_x(py_x.size());
|
|
|
- std::vector< std::complex<double> > c_m(py_m.size());
|
|
|
- int L = py_x.size();
|
|
|
- int nmax = -1, pl = -1;
|
|
|
-
|
|
|
- std::memcpy(c_x.data(), py_x.data(), py_x.size()*sizeof(double));
|
|
|
- std::memcpy(c_m.data(), py_m.data(), py_m.size()*sizeof( std::complex<double>));
|
|
|
-
|
|
|
- int terms = 0;
|
|
|
- std::vector<std::complex<double> > c_an, c_bn;
|
|
|
- terms = nmie::ScattCoeffs( L, pl, c_x, c_m, nmax, c_an, c_bn);
|
|
|
-
|
|
|
- auto py_an = py::array_t< std::complex<double>>(c_an.size());
|
|
|
- auto py_bn = py::array_t< std::complex<double>>(c_bn.size());
|
|
|
- auto py_an_buffer = py_an.request();
|
|
|
- auto py_bn_buffer = py_bn.request();
|
|
|
- std::complex<double> *py_an_ptr = ( std::complex<double> *) py_an_buffer.ptr;
|
|
|
- std::complex<double> *py_bn_ptr = ( std::complex<double> *) py_bn_buffer.ptr;
|
|
|
-
|
|
|
- std::memcpy(py_an_ptr,c_an.data(),c_an.size()*sizeof( std::complex<double>));
|
|
|
- std::memcpy(py_bn_ptr,c_bn.data(),c_bn.size()*sizeof( std::complex<double>));
|
|
|
-
|
|
|
- return py::make_tuple(terms, py_an, py_bn);
|
|
|
-}
|
|
|
-
|
|
|
-PYBIND11_MODULE(example, m) {
|
|
|
- m.doc() = "pybind11 example plugin"; // optional module docstring
|
|
|
-
|
|
|
- m.def("scattcoeffs", &py_ScattCoeffs, "test");
|
|
|
- m.def("scattcoeffs", py::vectorize(&py_ScattCoeffs), "test");
|
|
|
-}
|