X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling_Swig%2FMEDCouplingDataArrayTypemaps.i;h=6fd671e1be40c9ea81ced51d3e08a54e10be02f8;hb=a019ec6e72f540d3378f3e869c2b19bf4886459c;hp=f06995ce70285e13a3c550743d93a1624b94f9aa;hpb=68291f2f5498143761e7d2b37e4113fc976517d3;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i index f06995ce7..6fd671e1b 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i @@ -3032,6 +3032,83 @@ PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits::A } } +bool isCSRMatrix(PyObject *m) +{ +#if defined(WITH_NUMPY) && defined(WITH_SCIPY) + PyObject* pdict(PyDict_New()); + PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins()); + PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict)); + if(!tmp) + throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?"); + PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix"); + if(!csrMatrixCls) + throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?"); + bool ret(PyObject_IsInstance(m,csrMatrixCls)); + Py_DECREF(pdict); Py_XDECREF(tmp); + return ret; +#else + return false; +#endif +} + +void convertCSR_MCDataToVectMapIntDouble(const MEDCoupling::DataArrayInt *indptrPtr, const MEDCoupling::DataArrayInt *indicesPtr, const MEDCoupling::DataArrayDouble *dataPtr, std::vector >& mCpp) +{ +#if __cplusplus >= 201103L + auto nbOfRows(indptrPtr->getNumberOfTuples()-1); + if(nbOfRows<0) + throw INTERP_KERNEL::Exception("pywrap of MEDCouplingRemapper::setMatrix : input CSR matrix looks bad regarding indptr array !"); + mCpp.resize(nbOfRows); + auto indPtrCPtr(indptrPtr->begin()); + auto indicesCPtr(indicesPtr->begin()); + auto dataCPtr(dataPtr->begin()); + for(auto i=0;i >& mCpp) +{ + if(!PyList_Check(pyobj)) + throw INTERP_KERNEL::Exception("convertToVectMapIntDouble : input is not a python list !"); + mCpp.clear(); + Py_ssize_t sz(PyList_Size(pyobj)); + mCpp.resize(sz); + for(Py_ssize_t i=0;i& mapCpp(mCpp[i]); + while(PyDict_Next(elt,&pos,&key,&value)) + { + if(!PyInt_Check(key)) + { + std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " a key not mappable to pyint !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + if(!PyFloat_Check(value)) + { + std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " the value not mappable to pyfloat !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + mapCpp[(int)PyInt_AS_LONG(key)]=PyFloat_AS_DOUBLE(value); + } + } +} + template PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple) {