if(X==NULL)TRIQS_RUNTIME_ERROR<<"numpy interface : the python object is NULL !";
if(_import_array()!=0)TRIQS_RUNTIME_ERROR<<"Internal Error in importing numpy";
staticconstchar*error_msg=" A deep copy of the object would be necessary while views are supposed to guarantee to present a *view* of the python data.\n";
if(!allow_copy){
if(!PyArray_Check(X))throwcopy_exception()<<error_msg<<" Indeed the object was not even an array !\n";
if(elementsType!=PyArray_TYPE((PyArrayObject*)X))
throwcopy_exception()<<error_msg<<" The deep copy is caused by a type mismatch of the elements. Expected "<<type_name<<" and found XXX \n";
PyArrayObject*arr=(PyArrayObject*)X;
#ifdef TRIQS_NUMPY_VERSION_LT_17
if(arr->nd!=rank)throwcopy_exception()<<error_msg<<" Rank mismatch . numpy array is of rank "<<arr->nd<<"while you ask for rank "<<rank<<". \n";
#else
if(PyArray_NDIM(arr)!=rank)throwcopy_exception()<<error_msg<<" Rank mismatch . numpy array is of rank "<<PyArray_NDIM(arr)<<"while you ask for rank "<<rank<<". \n";
#endif
numpy_obj=X;Py_INCREF(X);
}
else{
// From X, we ask the numpy library to make a numpy, and of the correct type.
// This handles automatically the cases where :
// - we have list, or list of list/tuple
// - the numpy type is not the one we want.
// - adjust the dimension if needed
// If X is an array :
// - if Order is same, don't change it
// - else impose it (may provoque a copy).
// if X is not array :
// - Order = FortranOrder or SameOrder - > Fortran order otherwise C
//bool ForceCast = false;// Unless FORCECAST is present in flags, this call will generate an error if the data type cannot be safely obtained from the object.
intflags=0;//(ForceCast ? NPY_FORCECAST : 0) ;// do NOT force a copy | (make_copy ? NPY_ENSURECOPY : 0);
if(!(PyArray_Check(X)))
//flags |= ( IndexMapType::traversal_order == indexmaps::mem_layout::c_order(rank) ? NPY_C_CONTIGUOUS : NPY_F_CONTIGUOUS); //impose mem order
#ifdef TRIQS_NUMPY_VERSION_LT_17
flags|=(NPY_C_CONTIGUOUS);//impose mem order
#else
flags|=(NPY_ARRAY_C_CONTIGUOUS);//impose mem order