mirror of
https://github.com/triqs/dft_tools
synced 2024-12-26 06:14:14 +01:00
Remove Cython & prepare wrapper for applis.
- removed cython : macro, detection, pxd, etc... - adapt wrapper tools for external applis. - cleaned doc for cython
This commit is contained in:
parent
a920697e78
commit
2d071bb74b
15
ChangeLog
15
ChangeLog
@ -1,10 +1,25 @@
|
|||||||
|
|
||||||
From version 1.0 to 1.2
|
From version 1.0 to 1.2
|
||||||
|
|
||||||
|
C++
|
||||||
|
----
|
||||||
|
|
||||||
|
* new wrapping of boost random generators. No effect on API.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Python
|
Python
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* New wrapper tool to glue C++ and python. Cython is gone.
|
||||||
|
|
||||||
gf:
|
gf:
|
||||||
|
|
||||||
* transpose method now returns a NEW green function, like conjugate, etc...
|
* transpose method now returns a NEW green function, like conjugate, etc...
|
||||||
|
|
||||||
|
tail :
|
||||||
|
|
||||||
|
* Suppress the possibility to save/load in h5 for a tail alone (must be part
|
||||||
|
of a gf). [ok ?]
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
|
|
||||||
# Compile and link with python
|
|
||||||
#link_libraries(${PYTHON_LIBRARY} ${PYTHON_EXTRA_LIBS} )
|
|
||||||
include_directories(${PYTHON_INCLUDE_DIRS} ${PYTHON_NUMPY_INCLUDE_DIR})
|
|
||||||
|
|
||||||
function (python_register_dynamic_module NickName)
|
|
||||||
set_property (GLOBAL APPEND PROPERTY DEPENDANCE_TO_ADD triqs_${NickName} )
|
|
||||||
set_property (GLOBAL APPEND PROPERTY Modules_actually_compiled ${NickName} )
|
|
||||||
endfunction (python_register_dynamic_module NickName)
|
|
||||||
|
|
||||||
# This function add the target to build a python module
|
|
||||||
#
|
|
||||||
# NickName =
|
|
||||||
# ModuleName = the python name of the module
|
|
||||||
# ModuleDest = path in the pytriqs tree [ FOR INSTALLATION ONLY] IMPROVE MAKE THIS OPTIONAL (for test)
|
|
||||||
macro (cython_module NickName ModuleName)
|
|
||||||
MESSAGE(STATUS "Preparing cython module ${NickName} ")
|
|
||||||
get_filename_component(CYTHON_EXECUTABLE_PATH ${PYTHON_INTERPRETER} PATH)
|
|
||||||
SET(CYTHON_EXECUTABLE ${CYTHON_EXECUTABLE_PATH}/cython CACHE STRING "Path to the cython executable")
|
|
||||||
SET(cython_src ${CMAKE_CURRENT_SOURCE_DIR}/${ModuleName}.pyx )
|
|
||||||
FILE(GLOB all_pyx_src RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.pyx *.pxd )
|
|
||||||
SET(cython_wrap ${CMAKE_CURRENT_BINARY_DIR}/wrap_${NickName}_by_cython.cpp)
|
|
||||||
add_custom_command (OUTPUT ${cython_wrap} DEPENDS ${all_pyx_src} COMMAND ${CYTHON_EXECUTABLE} ${cython_src} -I ${CMAKE_CURRENT_SOURCE_DIR}/ -I${CMAKE_SOURCE_DIR}/pytriqs/pxd -X embedsignature=True --cplus -o ${cython_wrap} )
|
|
||||||
add_custom_target(cython_${NickName} ALL DEPENDS ${cython_wrap})
|
|
||||||
|
|
||||||
add_library(${ModuleName} MODULE ${cython_wrap} )
|
|
||||||
set_target_properties(${ModuleName} PROPERTIES PREFIX "") #eliminate the lib in front of the module name
|
|
||||||
target_link_libraries(${ModuleName} ${TRIQS_LINK_LIBS} triqs)
|
|
||||||
if (${ARGN} MATCHES "")
|
|
||||||
install (TARGETS ${ModuleName} DESTINATION ${TRIQS_PYTHON_LIB_DEST}/${ARGN} )
|
|
||||||
endif (${ARGN} MATCHES "")
|
|
||||||
set_property (GLOBAL APPEND PROPERTY DEPENDANCE_TO_ADD triqs_${NickName} )
|
|
||||||
|
|
||||||
endmacro (cython_module)
|
|
||||||
|
|
@ -112,13 +112,6 @@ mark_as_advanced(PYTHON_SITE_PKG)
|
|||||||
MESSAGE(STATUS "PYTHON_LIBRARY = ${PYTHON_LIBRARY}" )
|
MESSAGE(STATUS "PYTHON_LIBRARY = ${PYTHON_LIBRARY}" )
|
||||||
mark_as_advanced(PYTHON_LIBRARY)
|
mark_as_advanced(PYTHON_LIBRARY)
|
||||||
|
|
||||||
#
|
|
||||||
# Cython
|
|
||||||
#
|
|
||||||
EXEC_PYTHON_SCRIPT("from Cython.Compiler import Version as V;print V.version.split('.')[1]" PYTHON_CYTHON_VERSION )
|
|
||||||
MESSAGE(STATUS "Found cython 0.${PYTHON_CYTHON_VERSION}.xxx")
|
|
||||||
# check version here
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# libraries which must be linked in when embedding
|
# libraries which must be linked in when embedding
|
||||||
#
|
#
|
||||||
|
@ -77,31 +77,43 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|||||||
endif ()
|
endif ()
|
||||||
endif( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
endif( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
|
|
||||||
|
################################################################
|
||||||
# This function add the target to build a python module
|
# This function add the target to build a python module
|
||||||
#
|
macro (triqs_python_extension ModuleName)
|
||||||
# NickName =
|
message(STATUS "Preparing extension module ${ModuleName}")
|
||||||
# ModuleName = the python name of the module
|
|
||||||
# ModuleDest = path in the pytriqs tree [ FOR INSTALLATION ONLY] IMPROVE MAKE THIS OPTIONAL (for test)
|
|
||||||
macro (triqs_cython_module NickName ModuleName)
|
|
||||||
message(STATUS "TRIQS: Preparing cython module ${NickName} with the interpreter ${TRIQS_PYTHON_INTERPRETER} ")
|
|
||||||
get_filename_component(CYTHON_EXECUTABLE_PATH ${TRIQS_PYTHON_INTERPRETER} PATH)
|
|
||||||
set(CYTHON_EXECUTABLE ${CYTHON_EXECUTABLE_PATH}/cython CACHE STRING "Path to the cython executable")
|
|
||||||
set(cython_src ${CMAKE_CURRENT_SOURCE_DIR}/${ModuleName}.pyx )
|
|
||||||
FILE(GLOB all_pyx_src RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.pyx *.pxd )
|
|
||||||
set(cython_wrap ${CMAKE_CURRENT_BINARY_DIR}/wrap_${NickName}_by_cython.cpp)
|
|
||||||
add_custom_command (OUTPUT ${cython_wrap} DEPENDS ${all_pyx_src} COMMAND ${CYTHON_EXECUTABLE} ${cython_src} -I ${CMAKE_CURRENT_SOURCE_DIR}/ -I@CMAKE_INSTALL_PREFIX@/include/pytriqs/ -I@CMAKE_INSTALL_PREFIX@/include/ -X embedsignature=True --cplus -o ${cython_wrap} )
|
|
||||||
add_custom_target(cython_${NickName} ALL DEPENDS ${cython_wrap})
|
|
||||||
|
|
||||||
add_library(${ModuleName} MODULE ${cython_wrap} )
|
EXECUTE_PROCESS(COMMAND mkdir -p ${CMAKE_BINARY_DIR}/include/pytriqs/converters/)
|
||||||
set_target_properties(${ModuleName} PROPERTIES PREFIX "") #eliminate the lib in front of the module name
|
|
||||||
|
SET(wrap_name ${CMAKE_CURRENT_BINARY_DIR}/${ModuleName}_wrap.cpp)
|
||||||
|
SET(converter_name ${CMAKE_BINARY_DIR}/include/pytriqs/converters/${ModuleName}.hpp)
|
||||||
|
|
||||||
|
# Adjust pythonpath so that pytriqs is visible and the wrap_generator too...
|
||||||
|
# pytriqs needed since we import modules with pure python method to extract the doc..
|
||||||
|
add_custom_command(OUTPUT ${wrap_name} ${converter_name} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${ModuleName}_desc.py
|
||||||
|
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/${ModuleName}_desc.py ${CMAKE_CURRENT_BINARY_DIR} &&
|
||||||
|
PYTHONPATH=@CMAKE_INSTALL_PREFIX@/share/triqs/wrap_generator:${CMAKE_BINARY_DIR}/ ${TRIQS_PYTHON_INTERPRETER} ${CMAKE_CURRENT_BINARY_DIR}/${ModuleName}_desc.py
|
||||||
|
@CMAKE_INSTALL_PREFIX@/share/triqs/wrap_generator/wrapper.mako.cpp
|
||||||
|
${wrap_name}
|
||||||
|
@CMAKE_INSTALL_PREFIX@/share/triqs/wrap_generator/py_converter_wrapper.mako.hpp
|
||||||
|
${converter_name} )
|
||||||
|
|
||||||
|
#set_property (GLOBAL APPEND PROPERTY TRIQS_PY_CONVERTERS_TARGETS "python_wrap_${ModuleName}")
|
||||||
|
|
||||||
|
add_custom_target(python_wrap_${ModuleName} ALL DEPENDS ${wrap_name} ${converter_name})
|
||||||
|
add_dependencies(python_wrap_${ModuleName} py_copy ${CMAKE_CURRENT_BINARY_DIR}/${ModuleName}_desc.py )
|
||||||
|
|
||||||
|
add_library(${ModuleName} MODULE ${wrap_name})
|
||||||
|
set_target_properties(${ModuleName} PROPERTIES PREFIX "") #eliminate the lib in front of the module name
|
||||||
target_link_libraries(${ModuleName} ${TRIQS_LINK_LIBS} triqs)
|
target_link_libraries(${ModuleName} ${TRIQS_LINK_LIBS} triqs)
|
||||||
|
|
||||||
if (${ARGN} MATCHES "")
|
if (${ARGN} MATCHES "")
|
||||||
|
install (FILES ${converter_name} DESTINATION @TRIQS_PYTHON_LIB_DEST@/include/pytriqs/converters)
|
||||||
install (TARGETS ${ModuleName} DESTINATION @TRIQS_PYTHON_LIB_DEST@/${ARGN} )
|
install (TARGETS ${ModuleName} DESTINATION @TRIQS_PYTHON_LIB_DEST@/${ARGN} )
|
||||||
endif (${ARGN} MATCHES "")
|
endif (${ARGN} MATCHES "")
|
||||||
set_property (GLOBAL APPEND PROPERTY DEPENDANCE_TO_ADD triqs_${NickName} )
|
|
||||||
|
|
||||||
endmacro (triqs_cython_module)
|
endmacro (triqs_python_extension)
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
|
||||||
# Also duplicate from the FindTriqsMacro.... ? Include ?
|
# Also duplicate from the FindTriqsMacro.... ? Include ?
|
||||||
macro (triqs_add_all_subdirectories_with_cmakelist)
|
macro (triqs_add_all_subdirectories_with_cmakelist)
|
||||||
|
@ -83,9 +83,6 @@ on 10.8 and 10.9, (at least on the Mac of one of the developer !).
|
|||||||
pip install pyzmq
|
pip install pyzmq
|
||||||
pip install jinja2
|
pip install jinja2
|
||||||
pip install ipython
|
pip install ipython
|
||||||
pip install cython
|
|
||||||
# strangely, cython is not in bin, hence not in the path...
|
|
||||||
pushd /usr/local/bin && ln -s /usr/local/share/python/cython . && popd
|
|
||||||
|
|
||||||
6. If you wish to compile the documentation locally, install sphinx, its dependencies and mathjax: ::
|
6. If you wish to compile the documentation locally, install sphinx, its dependencies and mathjax: ::
|
||||||
|
|
||||||
|
@ -60,8 +60,7 @@ Usage
|
|||||||
* You can install any python package for this local python installation, e.g. ::
|
* You can install any python package for this local python installation, e.g. ::
|
||||||
|
|
||||||
easy_install --upgrade ipython
|
easy_install --upgrade ipython
|
||||||
easy_install --upgrade cython
|
|
||||||
|
|
||||||
and you have the latest ipython notebook, and cython
|
and you have the latest ipython notebook.
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,8 +73,6 @@ Libraries
|
|||||||
+------------------------+----------+------------------------------------------------------------------------+
|
+------------------------+----------+------------------------------------------------------------------------+
|
||||||
| matplotlib | >= 0.99 | Python 2D plotting library |
|
| matplotlib | >= 0.99 | Python 2D plotting library |
|
||||||
+------------------------+----------+------------------------------------------------------------------------+
|
+------------------------+----------+------------------------------------------------------------------------+
|
||||||
| cython | >=0.17 | A language that allows to write C extensions for the Python language |
|
|
||||||
+------------------------+----------+------------------------------------------------------------------------+
|
|
||||||
|
|
||||||
(1) Since standard linux distributions (and macports on OS X) now provides openmpi, even on laptops, we avoid the unnecessary complication of maintaining a non-parallel version of TRIQS
|
(1) Since standard linux distributions (and macports on OS X) now provides openmpi, even on laptops, we avoid the unnecessary complication of maintaining a non-parallel version of TRIQS
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ Install the following packages which are necessary to build TRIQS and use it::
|
|||||||
|
|
||||||
Optionally, you may be interested in:
|
Optionally, you may be interested in:
|
||||||
|
|
||||||
* How to *simply* upgrade the ipython notebook and Cython with :ref:`virtualenv <virtualenv>` to the latest version?
|
* How to *simply* upgrade the ipython notebook with :ref:`virtualenv <virtualenv>` to the latest version?
|
||||||
|
|
||||||
* How to use the nice and recommended :ref:`clang <install_clang>` C++ compiler?
|
* How to use the nice and recommended :ref:`clang <install_clang>` C++ compiler?
|
||||||
|
|
||||||
@ -33,5 +33,3 @@ If you wish to compile the documentation locally, you additionally need to insta
|
|||||||
|
|
||||||
pip install sphinxcontrib-doxylink
|
pip install sphinxcontrib-doxylink
|
||||||
|
|
||||||
|
|
||||||
.. warning:: you need the latest version of Cython (>=.17, downloadable on Cython.org). If Cython is not found, specify the location of the executable with the option -DCYTHON_EXECUTABLE.
|
|
||||||
|
@ -7,7 +7,7 @@ The array, matrix, vector and their views are fully interoperable with the numpy
|
|||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
Doc need to be largely improved here...
|
TO BE FULLY REWRITTEN
|
||||||
|
|
||||||
|
|
||||||
From Python to C++
|
From Python to C++
|
||||||
@ -55,31 +55,11 @@ To be more precise, two cases must be distinguished.
|
|||||||
Python will *automatically* release the memory allocated by the C++ routine
|
Python will *automatically* release the memory allocated by the C++ routine
|
||||||
when the array in no longer needed.
|
when the array in no longer needed.
|
||||||
|
|
||||||
Cython
|
|
||||||
------------
|
|
||||||
|
|
||||||
TRIQS main tool for interacing python/C++ code is Cython.
|
|
||||||
We provide in pytriqs/pxd the cython interface arrays.pxd for the array classes.
|
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
Split in several files. --> also the theory above.
|
Split in several files. --> also the theory above.
|
||||||
|
|
||||||
Put here the array_cython example
|
|
||||||
|
|
||||||
- a routine that take a view
|
|
||||||
- a routine that take an array (beware to the copy).
|
|
||||||
- a wrapped class.
|
|
||||||
- a function that returns a new array from C++. Check references....
|
|
||||||
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
import numpy,_testarray
|
|
||||||
a=numpy.array([[1.0,2],[3,4]])
|
|
||||||
_testarray.f(a)
|
|
||||||
|
|
||||||
|
|
||||||
Memory management
|
Memory management
|
||||||
-----------------
|
-----------------
|
||||||
|
@ -27,7 +27,7 @@ for numerical computations with the following characteristics/goals :
|
|||||||
|
|
||||||
* work on a view of a numpy,
|
* work on a view of a numpy,
|
||||||
* create a array in C++, and return it as a numpy.
|
* create a array in C++, and return it as a numpy.
|
||||||
* mix the various kind of arrays transparently in C++ expressions and in cython code.
|
* mix the various kind of arrays transparently in C++ expressions.
|
||||||
|
|
||||||
* **HDF5** : simple interface to hdf5 library to ease storing/retrieving into/from HDF5 files.
|
* **HDF5** : simple interface to hdf5 library to ease storing/retrieving into/from HDF5 files.
|
||||||
|
|
||||||
|
@ -66,6 +66,3 @@ useful links to learn python, ipython, scipy.
|
|||||||
|
|
||||||
* `SymPy <http://sympy.org/>`_ provides some formal computing capabilities.
|
* `SymPy <http://sympy.org/>`_ provides some formal computing capabilities.
|
||||||
|
|
||||||
* `Cython <http://cython.org/>`_ is a quick way to build simple `C` modules in
|
|
||||||
computationally intense case.
|
|
||||||
|
|
||||||
|
@ -12,9 +12,6 @@ add_custom_command (OUTPUT ${py_copy_tar} DEPENDS ${all_py_files}
|
|||||||
COMMAND cd ${CMAKE_SOURCE_DIR}/pytriqs && tar cf ${py_copy_tar} ${all_py_files} && cd ${CMAKE_BINARY_DIR}/pytriqs && tar xf ${py_copy_tar} )
|
COMMAND cd ${CMAKE_SOURCE_DIR}/pytriqs && tar cf ${py_copy_tar} ${all_py_files} && cd ${CMAKE_BINARY_DIR}/pytriqs && tar xf ${py_copy_tar} )
|
||||||
add_custom_target(py_copy ALL DEPENDS ${py_copy_tar})
|
add_custom_target(py_copy ALL DEPENDS ${py_copy_tar})
|
||||||
|
|
||||||
# To be removed
|
|
||||||
find_package(CythonModuleMacro)
|
|
||||||
|
|
||||||
find_package(PythonWrapperMacro)
|
find_package(PythonWrapperMacro)
|
||||||
|
|
||||||
SET(PYTHON_SOURCES
|
SET(PYTHON_SOURCES
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
FILE(GLOB all_pxd_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.pxd )
|
|
||||||
install (FILES ${all_pxd_files} DESTINATION "include/pytriqs")
|
|
||||||
install (FILES ${CMAKE_SOURCE_DIR}/pytriqs/__init__.py.template DESTINATION "include/pytriqs" RENAME __init__.py)
|
|
@ -1,73 +0,0 @@
|
|||||||
from clef cimport *
|
|
||||||
cdef extern from "<triqs/python_tools/array_interface.hpp>" namespace "triqs::arrays" :
|
|
||||||
|
|
||||||
cdef cppclass array "triqs::arrays::array" [T,R] :
|
|
||||||
array()
|
|
||||||
array(object) except +
|
|
||||||
array operator +( array_view &)
|
|
||||||
array operator -( array_view &)
|
|
||||||
array operator *( array_view &)
|
|
||||||
array operator /( array_view &)
|
|
||||||
object to_python() except +
|
|
||||||
|
|
||||||
cdef cppclass array_view "triqs::arrays::array_c" [T,R] :
|
|
||||||
array_view()
|
|
||||||
array_view(object) except +
|
|
||||||
array_view operator +( array_view &)
|
|
||||||
array_view operator -( array_view &)
|
|
||||||
array_view operator *( array_view &)
|
|
||||||
array_view operator /( array_view &)
|
|
||||||
void operator << (array_view &)
|
|
||||||
object to_python() except +
|
|
||||||
int shape(int)
|
|
||||||
# bug in cython
|
|
||||||
#_lazy_expr operator()(_lazy_expr&)
|
|
||||||
#_lazy_expr operator()(_lazy_expr&, _lazy_expr&)
|
|
||||||
#_lazy_expr operator()(_lazy_expr&, _lazy_expr&, _lazy_expr&)
|
|
||||||
#_lazy_expr operator()(_lazy_expr&, _lazy_expr&, _lazy_expr&, _lazy_expr&)
|
|
||||||
_lazy_expr call "operator()" (_lazy_expr&)
|
|
||||||
_lazy_expr call "operator()" (_lazy_expr&, _lazy_expr&)
|
|
||||||
_lazy_expr call "operator()" (_lazy_expr&, _lazy_expr&, _lazy_expr&)
|
|
||||||
_lazy_expr call "operator()" (_lazy_expr&, _lazy_expr&, _lazy_expr&, _lazy_expr&)
|
|
||||||
_lazy_expr call "operator()" (_lazy_expr&, _lazy_expr&, _lazy_expr&, _lazy_expr&, _lazy_expr&)
|
|
||||||
|
|
||||||
cdef cppclass matrix_view "triqs::arrays::matrix_c" [T] :
|
|
||||||
matrix_view()
|
|
||||||
matrix_view(matrix)
|
|
||||||
matrix_view(object) except +
|
|
||||||
void operator << (matrix_view &)
|
|
||||||
object to_python() except +
|
|
||||||
|
|
||||||
cdef cppclass matrix "triqs::arrays::matrix" [T] :
|
|
||||||
matrix()
|
|
||||||
matrix(object) except +
|
|
||||||
matrix(matrix_view) except +
|
|
||||||
matrix operator +( matrix_view &)
|
|
||||||
matrix operator -( matrix_view &)
|
|
||||||
matrix operator /( matrix_view &)
|
|
||||||
object to_python() except +
|
|
||||||
|
|
||||||
cdef matrix_view operator +( matrix_view & , matrix_view &)
|
|
||||||
cdef matrix_view operator -( matrix_view & , matrix_view &)
|
|
||||||
cdef matrix_view operator *( matrix_view & , matrix_view &)
|
|
||||||
cdef matrix_view operator /( matrix_view & , matrix_view &)
|
|
||||||
|
|
||||||
cdef cppclass tqa_vector "triqs::arrays::vector" [T] :
|
|
||||||
tqa_vector()
|
|
||||||
tqa_vector(object) except +
|
|
||||||
tqa_vector operator +( tqa_vector_view &)
|
|
||||||
tqa_vector operator -( tqa_vector_view &)
|
|
||||||
tqa_vector operator *( tqa_vector_view &)
|
|
||||||
tqa_vector operator /( tqa_vector_view &)
|
|
||||||
object to_python() except +
|
|
||||||
|
|
||||||
cdef cppclass tqa_vector_view "triqs::arrays::vector_c" [T] :
|
|
||||||
tqa_vector_view()
|
|
||||||
tqa_vector_view(object) except +
|
|
||||||
tqa_vector_view operator +(tqa_vector_view &)
|
|
||||||
tqa_vector_view operator -(tqa_vector_view &)
|
|
||||||
tqa_vector_view operator *(tqa_vector_view &)
|
|
||||||
tqa_vector_view operator /(tqa_vector_view &)
|
|
||||||
void operator << (tqa_vector_view &)
|
|
||||||
object to_python() except +
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
cdef extern from "triqs/python_tools/boost_object.hpp" namespace "triqs::python_tools":
|
|
||||||
|
|
||||||
cdef cppclass boost_object "triqs::python_tools::boost_object":
|
|
||||||
boost_object(object ob)
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
|||||||
cdef extern from "<triqs/clef.hpp>" namespace "triqs::clef" :
|
|
||||||
ctypedef int ZERO "0"
|
|
||||||
ctypedef int ONE "1"
|
|
||||||
ctypedef int TWO "2"
|
|
||||||
ctypedef int THREE "3"
|
|
||||||
ctypedef int FOUR "4"
|
|
||||||
ctypedef int FIVE "5"
|
|
||||||
ctypedef int SIX "6"
|
|
||||||
|
|
||||||
cdef cppclass placeholder "triqs::clef::placeholder" [T] :
|
|
||||||
placeholder()
|
|
||||||
#_lazy_expr operator []()
|
|
||||||
|
|
||||||
cdef _lazy_expr ph "triqs::clef::placeholder<0>" (placeholder[ZERO] &)
|
|
||||||
cdef _lazy_expr ph "triqs::clef::placeholder<1>" (placeholder[ONE] &)
|
|
||||||
cdef _lazy_expr ph "triqs::clef::placeholder<2>" (placeholder[TWO] &)
|
|
||||||
cdef _lazy_expr ph "triqs::clef::placeholder<3>" (placeholder[THREE] &)
|
|
||||||
cdef _lazy_expr ph "triqs::clef::placeholder<4>" (placeholder[FOUR] &)
|
|
||||||
cdef _lazy_expr ph "triqs::clef::placeholder<5>" (placeholder[FIVE] &)
|
|
||||||
cdef _lazy_expr ph "triqs::clef::placeholder<6>" (placeholder[SIX] &)
|
|
||||||
|
|
||||||
cdef _lazy_expr ph0 "triqs::clef::placeholder<0>" ()
|
|
||||||
cdef _lazy_expr ph1 "triqs::clef::placeholder<1>" ()
|
|
||||||
cdef _lazy_expr ph2 "triqs::clef::placeholder<2>" ()
|
|
||||||
cdef _lazy_expr ph3 "triqs::clef::placeholder<3>" ()
|
|
||||||
cdef _lazy_expr ph4 "triqs::clef::placeholder<4>" ()
|
|
||||||
cdef _lazy_expr ph5 "triqs::clef::placeholder<5>" ()
|
|
||||||
|
|
||||||
cdef _lazy_expr _i "triqs::clef::placeholder<0>" ()
|
|
||||||
cdef _lazy_expr _j "triqs::clef::placeholder<1>" ()
|
|
||||||
cdef _lazy_expr _k "triqs::clef::placeholder<2>" ()
|
|
||||||
cdef _lazy_expr _l "triqs::clef::placeholder<3>" ()
|
|
||||||
cdef _lazy_expr _m "triqs::clef::placeholder<4>" ()
|
|
||||||
cdef _lazy_expr _n "triqs::clef::placeholder<5>" ()
|
|
||||||
|
|
||||||
cdef cppclass _lazy_expr :
|
|
||||||
void operator << (_lazy_expr &)
|
|
||||||
_lazy_expr operator()(_lazy_expr&)
|
|
||||||
_lazy_expr operator()(_lazy_expr&, _lazy_expr&)
|
|
||||||
_lazy_expr operator()(_lazy_expr&, _lazy_expr&, _lazy_expr&)
|
|
||||||
_lazy_expr operator()(_lazy_expr&, _lazy_expr&, _lazy_expr&, _lazy_expr&)
|
|
||||||
|
|
||||||
cdef _lazy_expr operator +(_lazy_expr, _lazy_expr )
|
|
||||||
cdef _lazy_expr operator -(_lazy_expr , _lazy_expr)
|
|
||||||
cdef _lazy_expr operator *(_lazy_expr, _lazy_expr )
|
|
||||||
cdef _lazy_expr operator /(_lazy_expr, _lazy_expr)
|
|
||||||
|
|
||||||
cdef _lazy_expr operator +(long, _lazy_expr )
|
|
||||||
cdef _lazy_expr operator +(_lazy_expr , long)
|
|
||||||
cdef _lazy_expr operator -(long, _lazy_expr &)
|
|
||||||
cdef _lazy_expr operator -(_lazy_expr &, long)
|
|
||||||
cdef _lazy_expr operator *(long, _lazy_expr &)
|
|
||||||
cdef _lazy_expr operator *(_lazy_expr &, long)
|
|
||||||
cdef _lazy_expr operator /(long, _lazy_expr &)
|
|
||||||
cdef _lazy_expr operator /(_lazy_expr &, long)
|
|
||||||
|
|
||||||
cdef _lazy_expr operator +(double, _lazy_expr )
|
|
||||||
cdef _lazy_expr operator +(_lazy_expr , double)
|
|
||||||
cdef _lazy_expr operator -(double, _lazy_expr &)
|
|
||||||
cdef _lazy_expr operator -(_lazy_expr &, double)
|
|
||||||
cdef _lazy_expr operator *(double, _lazy_expr &)
|
|
||||||
cdef _lazy_expr operator *(_lazy_expr &, double)
|
|
||||||
cdef _lazy_expr operator /(double, _lazy_expr &)
|
|
||||||
cdef _lazy_expr operator /(_lazy_expr &, double)
|
|
||||||
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
|||||||
cdef extern from "<complex>" namespace "std":
|
|
||||||
cdef cppclass dcomplex "std::complex<double>":
|
|
||||||
dcomplex()
|
|
||||||
dcomplex(dcomplex &)
|
|
||||||
dcomplex(double,double)
|
|
||||||
double real()
|
|
||||||
double imag()
|
|
||||||
|
|
||||||
# Python -> C
|
|
||||||
cdef inline dcomplex as_dcomplex (a) :
|
|
||||||
x = complex(a)
|
|
||||||
return dcomplex(a.real, a.imag)
|
|
||||||
|
|
||||||
# C -> Python
|
|
||||||
cdef inline make_dcomplex (dcomplex z) :
|
|
||||||
return complex(z.real(), z.imag())
|
|
||||||
|
|
||||||
# Python -> C
|
|
||||||
cdef inline float as_float (a) :
|
|
||||||
return float (a)
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
|||||||
cdef extern from * :
|
|
||||||
object PyCObject_FromVoidPtr(void* cobj, void *)
|
|
||||||
void* PyCObject_AsVoidPtr(object self)
|
|
||||||
|
|
||||||
cdef inline encapsulate (void * p) :
|
|
||||||
return PyCObject_FromVoidPtr(p, NULL)
|
|
||||||
|
|
||||||
cdef extern from "triqs/utility/python/extractor.hpp" :
|
|
||||||
|
|
||||||
cdef cppclass extractor "triqs::utility::python::extractor" [T] :
|
|
||||||
extractor (object)
|
|
||||||
T & operator()()
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
|||||||
from libcpp.string cimport string as std_string
|
|
||||||
cdef extern from "<triqs/h5.hpp>" namespace "triqs::h5" :
|
|
||||||
#cdef extern from "<triqs/arrays/h5/group_or_file.hpp>" : #namespace "triqs::arrays::h5" :
|
|
||||||
|
|
||||||
cdef cppclass h5_group "triqs::h5::group" :
|
|
||||||
h5_group (int, bint)
|
|
||||||
h5_group ()
|
|
||||||
|
|
||||||
cdef extern from "<triqs/h5/h5_extractor.hpp>" namespace "triqs::h5" :
|
|
||||||
|
|
||||||
cdef cppclass h5_extractor "triqs::h5::h5_extractor" [T] :
|
|
||||||
h5_extractor()
|
|
||||||
T & operator()( h5_group &, std_string)
|
|
||||||
|
|
||||||
cdef inline h5_group make_h5_group (gr) :
|
|
||||||
import h5py
|
|
||||||
return h5_group (gr.id.id, type(gr) == h5py.highlevel.Group)
|
|
@ -1,15 +0,0 @@
|
|||||||
from libcpp.string cimport string as std_string
|
|
||||||
cdef extern from "<triqs/python_tools/inserter_in_map.hpp>" namespace "triqs::python_tools" :
|
|
||||||
|
|
||||||
cdef cppclass inserter_in_map "triqs::python_tools::inserter_in_map" [T,U] :
|
|
||||||
inserter_in_map(T &)
|
|
||||||
void operator()(std_string &, U&)
|
|
||||||
|
|
||||||
cdef cppclass inserter_in_map2 "triqs::python_tools::inserter_in_map2" [T,U] :
|
|
||||||
inserter_in_map(T &)
|
|
||||||
void operator()(std_string &, object)
|
|
||||||
|
|
||||||
cdef cppclass printer "triqs::python_tools::printer" [T] :
|
|
||||||
printer()
|
|
||||||
std_string operator()(T &)
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
|||||||
cdef extern from "<memory>" namespace "std" :
|
|
||||||
cdef cppclass shared_ptr "std::shared_ptr" [T] :
|
|
||||||
shared_ptr(T*)
|
|
||||||
shared_ptr()
|
|
||||||
T* get()
|
|
||||||
void reset (T*)
|
|
||||||
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
|||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
cython_module( array_cython array_cython )
|
#cython_module( array_cython array_cython )
|
||||||
|
|
||||||
add_triqs_test_txt( array_cython )
|
#add_triqs_test_txt( array_cython )
|
||||||
|
|
||||||
cython_module( expr_cython expr )
|
|
||||||
|
|
||||||
cython_module( bug bug )
|
|
||||||
|
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
#include <vector>
|
|
||||||
|
|
||||||
struct Obj1 {
|
|
||||||
std::vector<double> V;
|
|
||||||
Obj1() : V(10000){}
|
|
||||||
};
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
|||||||
#!python
|
|
||||||
cimport cython
|
|
||||||
|
|
||||||
cdef extern from "./bug.hpp" :
|
|
||||||
cdef cppclass Obj1 :
|
|
||||||
Obj1()
|
|
||||||
|
|
||||||
cdef class G_generic :
|
|
||||||
def __init__(self) :
|
|
||||||
pass
|
|
||||||
|
|
||||||
cdef class G_cython (G_generic) :
|
|
||||||
cdef Obj1 co
|
|
||||||
def __init__(self, A):
|
|
||||||
G_generic.__init__(self)
|
|
||||||
self.co = Obj1()
|
|
||||||
|
|
||||||
# Comment this and there is a memory leak
|
|
||||||
def __dealloc__(self) :
|
|
||||||
pass
|
|
||||||
|
|
||||||
class G (G_cython) :
|
|
||||||
def __init__(self, A):
|
|
||||||
G_cython.__init__(self,A)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
|||||||
import numpy as np
|
|
||||||
from expr import f
|
|
||||||
|
|
||||||
a = np.array( [[1,2], [3,4]])
|
|
||||||
|
|
||||||
print f(a)
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
|||||||
#!python
|
|
||||||
#cython: embedsignature=True
|
|
||||||
from cython.operator cimport dereference as deref, preincrement as inc #dereference and increment operators
|
|
||||||
#cimport cython
|
|
||||||
import numpy
|
|
||||||
import string
|
|
||||||
import warnings
|
|
||||||
|
|
||||||
from arrays cimport *
|
|
||||||
|
|
||||||
def f(A) :
|
|
||||||
|
|
||||||
# Solution 1
|
|
||||||
cdef array_view[long,TWO] a = array_view[long,TWO](A)
|
|
||||||
# ....
|
|
||||||
a.call ( _i(), _j()) << ( _i() + 3*_j() + 2 )
|
|
||||||
# can not do this ... unless with preprocessing the cython files...
|
|
||||||
# indeed _i is placeholder[ONE], not lazy_expr, I need to erase its type for
|
|
||||||
# cython compiler...
|
|
||||||
#a.call ( _i, _j) << ( _i + 3*_j + 2 )
|
|
||||||
#....
|
|
||||||
return A
|
|
||||||
|
|
||||||
#Solution 2
|
|
||||||
#cdef placeholder[ONE] i_
|
|
||||||
#cdef placeholder[TWO] j_
|
|
||||||
#array_view[long,TWO] (A).call ( ph(i_), ph(j_)) << ph(i_) + ph(j_)
|
|
||||||
|
|
||||||
#Solution 3 ?
|
|
||||||
#array_view[long,TWO] (A).call ( ph0(), ph1()) << ph0() + ph1()
|
|
||||||
|
|
||||||
#array_view[long,TWO] (A).call ( _i(), _j()) << 3*_i() + _j()*2
|
|
||||||
|
|
||||||
#array_view[long,TWO] (A)( ph(i_), ph(j_)) << ph(i_) + ph(j_)
|
|
||||||
|
|
||||||
#return A
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
|||||||
#include <triqs/gfs/block.hpp>
|
#include <triqs/gfs/block.hpp>
|
||||||
#include <triqs/gfs/local/tail.hpp>
|
#include <triqs/gfs/local/tail.hpp>
|
||||||
#include <triqs/arrays/blas_lapack/gelss.hpp>
|
#include <triqs/arrays/blas_lapack/gelss.hpp>
|
||||||
#include <triqs/python_tools/cython_proxy.hpp>
|
|
||||||
|
|
||||||
namespace triqs { namespace gfs { namespace local {
|
namespace triqs { namespace gfs { namespace local {
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
#include <triqs/arrays.hpp>
|
#include <triqs/arrays.hpp>
|
||||||
#include <triqs/arrays/algorithms.hpp>
|
#include <triqs/arrays/algorithms.hpp>
|
||||||
#include <triqs/gfs/tools.hpp>
|
#include <triqs/gfs/tools.hpp>
|
||||||
#include <triqs/python_tools/cython_proxy.hpp>
|
|
||||||
|
|
||||||
namespace triqs { namespace gfs { namespace local {
|
namespace triqs { namespace gfs { namespace local {
|
||||||
|
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
*
|
|
||||||
* TRIQS: a Toolbox for Research in Interacting Quantum Systems
|
|
||||||
*
|
|
||||||
* Copyright (C) 2011 by O. Parcollet
|
|
||||||
*
|
|
||||||
* TRIQS is free software: you can redistribute it and/or modify it under the
|
|
||||||
* terms of the GNU General Public License as published by the Free Software
|
|
||||||
* Foundation, either version 3 of the License, or (at your option) any later
|
|
||||||
* version.
|
|
||||||
*
|
|
||||||
* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* TRIQS. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
#ifndef TRIQS_H5_H5_EXTRACTOR_GROUP_H
|
|
||||||
#define TRIQS_H5_H5_EXTRACTOR_GROUP_H
|
|
||||||
#include "./group.hpp"
|
|
||||||
#include <triqs/utility/view_tools.hpp>
|
|
||||||
|
|
||||||
namespace triqs { namespace h5 {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Extractor for cython usage only
|
|
||||||
*/
|
|
||||||
template<typename T>
|
|
||||||
struct h5_extractor {
|
|
||||||
typename view_type_if_exists_else_type<T>::type operator() (group fg, std::string const & subgroup_name) const {
|
|
||||||
typename regular_type_if_exists_else_type<T>::type r;
|
|
||||||
h5_read(fg,subgroup_name,r);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}}
|
|
||||||
#endif
|
|
@ -1,65 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
*
|
|
||||||
* TRIQS: a Toolbox for Research in Interacting Quantum Systems
|
|
||||||
*
|
|
||||||
* Copyright (C) 2011 by O. Parcollet
|
|
||||||
*
|
|
||||||
* TRIQS is free software: you can redistribute it and/or modify it under the
|
|
||||||
* terms of the GNU General Public License as published by the Free Software
|
|
||||||
* Foundation, either version 3 of the License, or (at your option) any later
|
|
||||||
* version.
|
|
||||||
*
|
|
||||||
* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* TRIQS. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
#ifndef TRIQS_ARRAY_INTERFACE_H
|
|
||||||
#define TRIQS_ARRAY_INTERFACE_H
|
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
#include <triqs/python_tools/cython_proxy.hpp>
|
|
||||||
|
|
||||||
namespace triqs { namespace arrays {
|
|
||||||
|
|
||||||
template<class T, int R, ull_t Opt=0, ull_t To=0>
|
|
||||||
struct array_c: public triqs::python_tools::cython_proxy<array_view<T,R,Opt,To> > {
|
|
||||||
|
|
||||||
typedef triqs::python_tools::cython_proxy<array_view<T,R,Opt,To>> B;
|
|
||||||
array_c(): B() {}
|
|
||||||
array_c(array_c const &a): B(a) {};
|
|
||||||
array_c(array_view<T,R,Opt,To> const &a): B(a) {};
|
|
||||||
template<typename ... Args> explicit array_c(Args && ... args): B(std::forward<Args>(args)...) {}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T, ull_t Opt=0, ull_t To=0>
|
|
||||||
struct matrix_c: public triqs::python_tools::cython_proxy<matrix_view<T,Opt,To>> {
|
|
||||||
|
|
||||||
typedef triqs::python_tools::cython_proxy<matrix_view<T,Opt,To>> B;
|
|
||||||
matrix_c(): B() {}
|
|
||||||
matrix_c(matrix_c const &a): B(a) {};
|
|
||||||
matrix_c(matrix_view<T,Opt,To> const &a): B(a) {};
|
|
||||||
template<typename ... Args> explicit matrix_c(Args && ... args): B(std::forward<Args>(args)...) {}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T, ull_t Opt=0>
|
|
||||||
struct vector_c: public triqs::python_tools::cython_proxy<vector_view<T,Opt>> {
|
|
||||||
|
|
||||||
typedef triqs::python_tools::cython_proxy<vector_view<T,Opt>> B;
|
|
||||||
vector_c(): B() {}
|
|
||||||
vector_c(vector_c const &a): B(a) {};
|
|
||||||
vector_c(vector_view<T,Opt> const &a): B(a) {};
|
|
||||||
template<typename ... Args> explicit vector_c(Args && ... args): B(std::forward<Args>(args)...) {}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}}//namespace triqs
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
|||||||
#include <Python.h>
|
|
||||||
#include <boost/python.hpp>
|
|
||||||
|
|
||||||
namespace triqs { namespace python_tools {
|
|
||||||
|
|
||||||
// A simple wrapper
|
|
||||||
class boost_object {
|
|
||||||
|
|
||||||
boost::python::handle<> hdl;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
boost_object(PyObject * py_ob) : hdl(boost::python::borrowed(py_ob)) {}
|
|
||||||
|
|
||||||
operator boost::python::object () { return boost::python::object(hdl); }
|
|
||||||
operator boost::python::list () { return boost::python::list(hdl); }
|
|
||||||
operator boost::python::dict () { return boost::python::dict(hdl); }
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}}
|
|
@ -1,44 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
*
|
|
||||||
* TRIQS: a Toolbox for Research in Interacting Quantum Systems
|
|
||||||
*
|
|
||||||
* Copyright (C) 2011 by O. Parcollet
|
|
||||||
*
|
|
||||||
* TRIQS is free software: you can redistribute it and/or modify it under the
|
|
||||||
* terms of the GNU General Public License as published by the Free Software
|
|
||||||
* Foundation, either version 3 of the License, or (at your option) any later
|
|
||||||
* version.
|
|
||||||
*
|
|
||||||
* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* TRIQS. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
#ifndef TRIQS_PYTHON_CYTHON_PROXY_H
|
|
||||||
#define TRIQS_PYTHON_CYTHON_PROXY_H
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
namespace triqs { namespace python_tools {
|
|
||||||
|
|
||||||
// Wrap a C++ view into an object which has *value* semantics
|
|
||||||
// operator = remapped to <<=
|
|
||||||
// This class must be friend of V, to use the private default constructor.
|
|
||||||
template<typename V> class cython_proxy : public V {
|
|
||||||
public:
|
|
||||||
cython_proxy() : V(typename V::regular_type()) {}
|
|
||||||
cython_proxy(V const &v) : V(v){};
|
|
||||||
cython_proxy(cython_proxy const & cp) : V(cp) {};
|
|
||||||
template<typename ... Args> explicit cython_proxy(Args && ... args) : V (std::forward<Args>(args)...){}
|
|
||||||
cython_proxy & operator = ( cython_proxy const & cp ) { this->rebind(cp); return *this;}
|
|
||||||
cython_proxy & operator = ( V const & v ) { this->rebind(v); return *this;}
|
|
||||||
template<typename V2> void operator << ( V2 && v) { V::operator=( std::forward<V2>(v) );}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}}//namespace triqs
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
*
|
|
||||||
* TRIQS: a Toolbox for Research in Interacting Quantum Systems
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013 by H. Hafermann, O. Parcollet
|
|
||||||
*
|
|
||||||
* TRIQS is free software: you can redistribute it and/or modify it under the
|
|
||||||
* terms of the GNU General Public License as published by the Free Software
|
|
||||||
* Foundation, either version 3 of the License, or (at your option) any later
|
|
||||||
* version.
|
|
||||||
*
|
|
||||||
* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* TRIQS. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
#ifndef TRIQS_PYTHON_TOOLS_INSERTER_MAP_H
|
|
||||||
#define TRIQS_PYTHON_TOOLS_INSERTER_MAP_H
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace triqs { namespace python_tools {
|
|
||||||
|
|
||||||
template<typename T, typename U> struct inserter_in_map {
|
|
||||||
T * p;
|
|
||||||
inserter_in_map(T & x) : p(&x) {}
|
|
||||||
void operator()(std::string const & key, U const & x) { (*p)[key] = x; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T, typename U> struct inserter_in_map2 {
|
|
||||||
T * p;
|
|
||||||
inserter_in_map2(T & x) : p(&x) {}
|
|
||||||
void operator()(std::string const & key, PyObject * ob) { (*p)[key] = U(ob); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T> struct printer {
|
|
||||||
std::string operator()(T const & x) { std::stringstream fs; fs<<x; return fs.str();}
|
|
||||||
};
|
|
||||||
|
|
||||||
}}
|
|
||||||
#endif
|
|
@ -478,7 +478,7 @@ template <typename Variable, typename Opt> struct py_converter<triqs::gfs::gf_vi
|
|||||||
static bool is_convertible(PyObject *ob, bool raise_exception) {
|
static bool is_convertible(PyObject *ob, bool raise_exception) {
|
||||||
if (!conv::is_convertible(ob,raise_exception)) return false;
|
if (!conv::is_convertible(ob,raise_exception)) return false;
|
||||||
auto g = conv::py2c(ob); // matrix view
|
auto g = conv::py2c(ob); // matrix view
|
||||||
if (get_target_shape(g) == make_shape(1,1)) return true;
|
if (get_target_shape(g) == triqs::arrays::make_shape(1,1)) return true;
|
||||||
if (raise_exception) PyErr_SetString(PyExc_RuntimeError,"The green function is not of dimension 1x1 : can not be reinterpreted as a scalar_valued Green function");
|
if (raise_exception) PyErr_SetString(PyExc_RuntimeError,"The green function is not of dimension 1x1 : can not be reinterpreted as a scalar_valued Green function");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user