mirror of
https://github.com/triqs/dft_tools
synced 2024-12-25 05:43:40 +01:00
Fix import array in extensions.
- import arrays in extensions (mako file). - put import_arrays in converter, along the lines of our own objects (numpy and triqs uses the same capsule technique, i.e. the standard technique from python doc.)
This commit is contained in:
parent
cbf6092956
commit
842274003f
@ -1001,6 +1001,9 @@ ${f.code};
|
||||
PyMODINIT_FUNC
|
||||
init${module.name}(void)
|
||||
{
|
||||
// import numpy
|
||||
import_array();
|
||||
|
||||
PyObject* m;
|
||||
|
||||
%for c in module.classes.values() :
|
||||
|
@ -31,7 +31,7 @@ namespace triqs { namespace arrays { namespace numpy_interface {
|
||||
|
||||
template<typename ArrayViewType >
|
||||
PyObject * array_view_to_python ( ArrayViewType const & A, bool copy=false) {
|
||||
_import_array();
|
||||
//_import_array();
|
||||
typedef typename ArrayViewType::value_type value_type;
|
||||
static const int rank = ArrayViewType::rank;
|
||||
const int elementsType (numpy_to_C_type<typename boost::remove_const<value_type>::type>::arraytype);
|
||||
|
@ -130,7 +130,7 @@ namespace triqs { namespace arrays { namespace storages { //namespace details {
|
||||
static_assert(!std::is_const<ValueType>::value, "internal error");
|
||||
|
||||
#ifdef TRIQS_WITH_PYTHON_SUPPORT
|
||||
static void import_numpy_array() { if (_import_array()!=0) TRIQS_RUNTIME_ERROR <<"Internal Error in importing numpy";}
|
||||
static void import_numpy_array() {}// if (_import_array()!=0) TRIQS_RUNTIME_ERROR <<"Internal Error in importing numpy";}
|
||||
#endif
|
||||
|
||||
//Construct to state 0
|
||||
|
@ -368,12 +368,25 @@ template <typename T, int N> struct py_converter<triqs::utility::mini_vector<T,N
|
||||
|
||||
// --- array
|
||||
|
||||
inline void import_numpy() {
|
||||
static bool init = false;
|
||||
if (!init) {
|
||||
_import_array();
|
||||
std::cerr << "importing array"<<std::endl;
|
||||
init = true;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ArrayType> struct py_converter_array {
|
||||
static PyObject *c2py(ArrayType const &x) { return x.to_python(); }
|
||||
static PyObject *c2py(ArrayType const &x) {
|
||||
import_numpy();
|
||||
return x.to_python();
|
||||
}
|
||||
static ArrayType py2c(PyObject *ob) {
|
||||
return ArrayType (ob);
|
||||
}
|
||||
static bool is_convertible(PyObject *ob, bool raise_exception) {
|
||||
import_numpy();
|
||||
try {
|
||||
py2c(ob);
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user