#if NPY_BITSOF_LONGDOUBLE > NPY_BITSOF_DOUBLE template <> struct builtin_float_dtype< NPY_BITSOF_LONGDOUBLE > { static dtype get() { return DTYPE_FROM_CODE(NPY_LONGDOUBLE); } }; template dtype get_float_dtype< NPY_BITSOF_LONGDOUBLE >(); template <> struct builtin_complex_dtype< 2 * NPY_BITSOF_LONGDOUBLE > { static dtype get() { return DTYPE_FROM_CODE(NPY_CLONGDOUBLE); } }; template dtype get_complex_dtype< 2 * NPY_BITSOF_LONGDOUBLE >(); #endif
因爲numpy將NPY_BITSOF_LONGDOUBLE 和NPY_BITSOF_DOUBLE定義爲相同長度,因此沒有建立該函數,但在test/dtype_mod.cpp中出現了:python
// floats and complex p::def("accept_float32", accept<float>); p::def("accept_complex64", accept< std::complex<float> >); p::def("accept_float64", accept<double>); p::def("accept_complex128", accept< std::complex<double> >); if (sizeof(long double) > sizeof(double)) { p::def("accept_longdouble", accept<long double>); p::def("accept_clongdouble", accept< std::complex<long double> >); }
可將它註銷掉:git
// floats and complex p::def("accept_float32", accept<float>); p::def("accept_complex64", accept< std::complex<float> >); p::def("accept_float64", accept<double>); p::def("accept_complex128", accept< std::complex<double> >); /*if (sizeof(long double) > sizeof(double)) { p::def("accept_longdouble", accept<long double>); p::def("accept_clongdouble", accept< std::complex<long double> >); }*/
利用cmake編譯boost.numpy時將LIBRARY_TYPE設置爲SHARED,注意必須爲大寫github
如何利用boot.python和boost.numpy編譯文件? (1) 建立boost-build.jam 內容:ide
boost-build "d:/boost_1_59_0/tools/build/src" ;
上面路徑對應boost的tools庫 (2) 建立Jamroot文件 內容:函數
# Copyright David Abrahams 2006. Distributed under the Boost # Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) import python ; if ! [ python.configured ] { ECHO "notice: no Python configured in user-config.jam" ; ECHO "notice: will use default configuration" ; using python ; } # Specify the path to the Boost project. If you move this project, # adjust this path to refer to the Boost root directory. use-project boost : D:/boost_1_59_0/ ; lib boost_numpy : : <name>boost_numpy <search>. ; # Set up the project-wide requirements that everything uses the # boost_python library from the project whose global ID is # /boost/python. project : requirements <library>/boost/python//boost_python <library>boost_numpy <implicit-dependency>/boost//headers : usage-requirements <implicit-dependency>/boost//headers ; # Declare the three extension modules. You can specify multiple # source files after the colon separated by spaces. python-extension wakeModel : main.cpp wakeModel.cpp ; # Put the extension and Boost.Python DLL in the current directory, so # that running script by hand works. install convenient_copy : wakeModel : <install-dependencies>on <install-type>SHARED_LIB <install-type>PYTHON_EXTENSION <location>. ; # A little "rule" (function) to clean up the syntax of declaring tests # of these extension modules. local rule run-test ( test-name : sources + ) { import testing ; testing.make-test run-pyd : $(sources) : : $(test-name) ; } # Declare test targets #run-test wakeModel : wakeModel_ext wakeModel.py ;
(3) 運行命令:ui
bjam toolset=gcc release threading=multi
(4) 將libboost_python-mgw51-mt-1_59.dll和libboost_numpy.dll拷貝到當前目錄,注意libboost_numpy.dll的依賴庫要與libboost_python-mgw51-mt1_59.dll同名this