/*******************************************************************************
*
* 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 .
*
******************************************************************************/
#ifndef TRIQS_ARRAYS_TO_PYTHON_H
#define TRIQS_ARRAYS_TO_PYTHON_H
#ifndef TRIQS_WITH_PYTHON_SUPPORT
#error "You must define the macro TRIQS_WITH_PYTHON_SUPPORT to use Python interface"
#endif
#include
#include "../impl/indexmap_storage_pair.hpp"
//#include "../array.hpp"
namespace triqs { namespace arrays { namespace numpy_interface {
template
PyObject * array_view_to_python ( ArrayViewType const & A, bool copy=false) {
//_import_array();
typedef typename ArrayViewType::value_type value_type;
static const int rank = ArrayViewType::rank;
const int elementsType (numpy_to_C_type::type>::arraytype);
npy_intp dims[rank], strides[rank];
for(size_t i =0; ibase = A.storage().new_python_ref();
assert( arr->flags == (arr->flags & ~NPY_OWNDATA));
#else
int r = PyArray_SetBaseObject(arr,A.storage().new_python_ref());
if (r!=0) TRIQS_RUNTIME_ERROR << "Internal Error setting the guard in numpy !!!!";
assert( PyArray_FLAGS(arr) == (PyArray_FLAGS(arr) & ~NPY_ARRAY_OWNDATA));
#endif
if (copy) {
PyObject * na = PyObject_CallMethod(res,(char*)"copy",NULL);
Py_DECREF(res);
// POrt this for 1.7
//assert(((PyArrayObject *)na)->base ==NULL);
res = na;
}
return res;
}
}}}
#endif