Salome HOME
OK for DataArrayInt
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingDataArrayTypemaps.i
index 31c881f06459984973d24815de3e93139cfc2174..66cb1d33caf1e155cc596ea44cf13d8837738c7a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2017  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -108,6 +108,7 @@ int InterpreteNegativeInt(int val, int nbelem)
     return val;
 }
 
+#ifdef WITH_NUMPY
 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
 // in input when an another DataArray is already client of this.
 template<class MCData>
@@ -235,27 +236,27 @@ int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
 
     /*
      * Don't allow infinite chains of views, always set the base
-     * to the first owner of the data.  
-     * That is, either the first object which isn't an array, 
+     * to the first owner of the data.
+     * That is, either the first object which isn't an array,
      * or the first object which owns its own data.
      */
 
     while (PyArray_Check(obj) && (PyObject *)arr != obj) {
         PyArrayObject *obj_arr = (PyArrayObject *)obj;
         PyObject *tmp;
+
 
         /* If this array owns its own data, stop collapsing */
-        if (PyArray_CHKFLAGS(obj_arr, MED_NUMPY_OWNDATA )) { 
+        if (PyArray_CHKFLAGS(obj_arr, MED_NUMPY_OWNDATA )) {
             break;
-        }   
+        }
 
         tmp = PyArray_BASE(obj_arr);
         /* If there's no base, stop collapsing */
         if (tmp == NULL) {
             break;
         }
-        /* Stop the collapse new base when the would not be of the same 
+        /* Stop the collapse new base when the would not be of the same
          * type (i.e. different subclass).
          */
         if (Py_TYPE(tmp) != Py_TYPE(arr)) {
@@ -292,7 +293,7 @@ PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *M
   MEDCoupling::MemArray<T>& mem=self->accessToMemArray();
   if(nbComp==0)
     {
-      std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !"; 
+      std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
       throw INTERP_KERNEL::Exception(oss.str().c_str());
     }
   int nbDims=nbComp==1?1:2;
@@ -342,6 +343,9 @@ PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
 SWIGINTERN PyObject *MEDCoupling_DataArrayInt_toNumPyArray(MEDCoupling::DataArrayInt *self);
 SWIGINTERN PyObject *MEDCoupling_DataArrayDouble_toNumPyArray(MEDCoupling::DataArrayDouble *self);
 
+#endif
+
+#ifdef WITH_SCIPY
 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols)
 {
   int nbRows((int)m.size());
@@ -384,6 +388,8 @@ PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols)
   return ret;
 }
 
+#endif
+
 static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner)
 {
   PyObject *ret=0;
@@ -483,7 +489,7 @@ static std::string convertPyObjectToStr(PyObject *obj, const char *msg=NULL)
       if(msg)
         oss << msg;
       else
-        oss << "PyWrap convertPyObjectToStr : expect a sting like py object !";
+        oss << "PyWrap convertPyObjectToStr : expect a string like py object !";
       throw INTERP_KERNEL::Exception(oss.str());
     }
   return ret;
@@ -1388,7 +1394,7 @@ static void convertIntStarLikePyObjToCpp(PyObject *value, int& sw, int& iTyypp,
     }
   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
   if(SWIG_IsOK(status))
-    {  
+    {
       daIntTuple=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
       sw=4;
       return ;
@@ -1468,7 +1474,7 @@ static const int *convertIntStarLikePyObjToCppIntStar(PyObject *value, int& sw,
     }
   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
   if(SWIG_IsOK(status))
-    {  
+    {
       MEDCoupling::DataArrayIntTuple *daIntTuple=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
       sw=4; sz=daIntTuple->getNumberOfCompo();
       return daIntTuple->getConstPointer();
@@ -1684,14 +1690,14 @@ void convertFPStarLikePyObjToCpp_2(PyObject *value, int& sw, T& val, typename ME
   void *argp;
   int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0);
   if(SWIG_IsOK(status))
-    {  
+    {
       d=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
       sw=2;
       return ;
     }
   status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0);
   if(SWIG_IsOK(status))
-    {  
+    {
       e=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayTuple * >(argp);
       sw=3;
       return ;
@@ -1712,6 +1718,19 @@ static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double&
   convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
 }
 
+/*!
+ * if value int -> cpp val sw=1
+ * if value double -> cpp val sw=1
+ * if value DataArrayDouble -> cpp DataArrayDouble sw=2
+ * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
+ * if value list[int,double] -> cpp std::vector<double> sw=4
+ * if value tuple[int,double] -> cpp std::vector<double> sw=4
+ */
+static void convertFloatStarLikePyObjToCpp_2(PyObject *value, int& sw, float& val, MEDCoupling::DataArrayFloat *&d, MEDCoupling::DataArrayFloatTuple *&e, std::vector<float>& f)
+{
+  convertFPStarLikePyObjToCpp_2<float>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayFloat,SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple);
+}
+
 /*!
  * if python int -> cpp int sw=1
  * if python list[int] -> cpp vector<int> sw=2
@@ -2062,7 +2081,7 @@ static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, dou
       sw=1;
       if(nbTuplesExpected*nbCompExpected!=1)
         {
-          std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
+          std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
           throw INTERP_KERNEL::Exception(oss.str().c_str());
         }
       return &val;
@@ -2073,7 +2092,7 @@ static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, dou
       sw=1;
       if(nbTuplesExpected*nbCompExpected!=1)
         {
-          std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
+          std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
           throw INTERP_KERNEL::Exception(oss.str().c_str());
         }
       return &val;
@@ -2093,7 +2112,7 @@ static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, dou
   void *argp;
   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
   if(SWIG_IsOK(status))
-    {  
+    {
       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
       sw=2;
       if(d)
@@ -2129,7 +2148,7 @@ static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, dou
     }
   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
   if(SWIG_IsOK(status))
-    {  
+    {
       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
       sw=3;
       if(e->getNumberOfCompo()==nbCompExpected)
@@ -2169,7 +2188,7 @@ static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, do
       sw=1;
       if(nbCompExpected!=1)
         {
-          std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
+          std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
           throw INTERP_KERNEL::Exception(oss.str().c_str());
         }
       nbTuples=1;
@@ -2181,7 +2200,7 @@ static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, do
       sw=1;
       if(nbCompExpected!=1)
         {
-          std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
+          std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
           throw INTERP_KERNEL::Exception(oss.str().c_str());
         }
       nbTuples=1;
@@ -2207,7 +2226,7 @@ static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, do
       sw=4;
       if(size%nbCompExpected!=0)
         {
-          std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
+          std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
           throw INTERP_KERNEL::Exception(oss.str().c_str());
         }
       nbTuples=size/nbCompExpected;
@@ -2233,7 +2252,7 @@ static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, do
       sw=4;
       if(size%nbCompExpected!=0)
         {
-          std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
+          std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
           throw INTERP_KERNEL::Exception(oss.str().c_str());
         }
       nbTuples=size/nbCompExpected;
@@ -2242,7 +2261,7 @@ static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, do
   void *argp;
   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
   if(SWIG_IsOK(status))
-    {  
+    {
       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
       sw=2;
       if(d)
@@ -2271,7 +2290,7 @@ static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, do
     }
   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
   if(SWIG_IsOK(status))
-    {  
+    {
       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
       sw=3;
       if(e)
@@ -2374,7 +2393,7 @@ static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int&
   void *argp;
   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
   if(SWIG_IsOK(status))
-    {  
+    {
       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
       sw=2;
       if(d)
@@ -2403,7 +2422,7 @@ static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int&
     }
   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
   if(SWIG_IsOK(status))
-    {  
+    {
       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
       sw=3;
       if(e)
@@ -3251,7 +3270,7 @@ PyObject *DataArrayT_iadd__internal(PyObject *trueSelf, PyObject *obj, typename
       throw INTERP_KERNEL::Exception(msg);
     }
 }
-  
+
 template<class T>
 PyObject *DataArrayT_isub__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
 {
@@ -3318,9 +3337,11 @@ swig_type_info *SWIGTITraits<double>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_M
 swig_type_info *SWIGTITraits<float>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
 swig_type_info *SWIGTITraits<int>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
 
+#ifdef WITH_NUMPY
 PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
 
 PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
+#endif
 
 template<class T>
 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
@@ -3358,4 +3379,37 @@ PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCouplin
   return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
 }
 
+template<class T>
+typename MEDCoupling::Traits<T>::ArrayType *DataArrayFPT_rmul(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
+{
+  const char msg[]="Unexpected situation in __rmul__ !";
+  T val;
+  typename MEDCoupling::Traits<T>::ArrayType *a;
+  typename MEDCoupling::Traits<T>::ArrayTuple *aa;
+  std::vector<T> bb;
+  int sw;
+  convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
+  switch(sw)
+    {
+    case 1:
+      {
+        typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> ret(self->deepCopy());
+        ret->applyLin(val,0.);
+        return ret.retn();
+      }
+    case 3:
+      {
+        typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(aa->buildDA(1,self->getNumberOfComponents()));
+        return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
+      }
+    case 4:
+      {
+        typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
+        return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
+      }
+    default:
+      throw INTERP_KERNEL::Exception(msg);
+    }
+}
+
 #endif