From: Anthony Geay Date: Tue, 2 May 2017 15:12:20 +0000 (+0200) Subject: On the road X-Git-Tag: V8_4_0a1~66 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7993ad46aa1b33253c97499712bc21e4c41c506c;p=tools%2Fmedcoupling.git On the road --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index bd33d0785..31c26f45d 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -44,6 +44,7 @@ template class MEDCoupling::DataArrayTemplateClassic; template class MEDCoupling::DataArrayTemplateClassic; template class MEDCoupling::DataArrayTemplateFP; template class MEDCoupling::DataArrayIterator; +template class MEDCoupling::DataArrayIterator; template void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const @@ -4585,9 +4586,7 @@ std::string DataArrayDoubleTuple::repr() const double DataArrayDoubleTuple::doubleValue() const { - if(_nb_of_compo==1) - return *_pt; - throw INTERP_KERNEL::Exception("DataArrayDoubleTuple::doubleValue : DataArrayDoubleTuple instance has not exactly 1 component -> Not possible to convert it into a double precision float !"); + return this->zeValue(); } /*! @@ -4598,18 +4597,7 @@ double DataArrayDoubleTuple::doubleValue() const */ DataArrayDouble *DataArrayDoubleTuple::buildDADouble(int nbOfTuples, int nbOfCompo) const { - if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1)) - { - DataArrayDouble *ret=DataArrayDouble::New(); - ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo); - return ret; - } - else - { - std::ostringstream oss; oss << "DataArrayDoubleTuple::buildDADouble : unable to build a requested DataArrayDouble instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo; - oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } + return this->buildDA(nbOfTuples,nbOfCompo); } /*! @@ -9129,9 +9117,7 @@ std::string DataArrayIntTuple::repr() const int DataArrayIntTuple::intValue() const { - if(_nb_of_compo==1) - return *_pt; - throw INTERP_KERNEL::Exception("DataArrayIntTuple::intValue : DataArrayIntTuple instance has not exactly 1 component -> Not possible to convert it into an integer !"); + return this->zeValue(); } /*! @@ -9142,16 +9128,5 @@ int DataArrayIntTuple::intValue() const */ DataArrayInt *DataArrayIntTuple::buildDAInt(int nbOfTuples, int nbOfCompo) const { - if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1)) - { - DataArrayInt *ret=DataArrayInt::New(); - ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo); - return ret; - } - else - { - std::ostringstream oss; oss << "DataArrayIntTuple::buildDAInt : unable to build a requested DataArrayInt instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo; - oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } + return this->buildDA(nbOfTuples,nbOfCompo); } diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index a2dac270c..343859c42 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -322,6 +322,7 @@ namespace MEDCoupling namespace MEDCoupling { + class DataArrayFloatIterator; class DataArrayFloat : public DataArrayTemplateFP { public: @@ -348,6 +349,8 @@ namespace MEDCoupling MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const; MEDCOUPLING_EXPORT DataArrayFloat *performCopyOrIncrRef(bool deepCopy) const; + public: + MEDCOUPLING_EXPORT DataArrayFloatIterator *iterator(); private: ~DataArrayFloat() { } DataArrayFloat() { } @@ -821,6 +824,9 @@ namespace MEDCoupling MEDCOUPLING_EXPORT int getNumberOfCompo() const { return _nb_of_compo; } MEDCOUPLING_EXPORT const T *getConstPointer() const { return _pt; } MEDCOUPLING_EXPORT T *getPointer() { return _pt; } + MEDCOUPLING_EXPORT typename Traits::ArrayType *buildDA(int nbOfTuples, int nbOfCompo) const; + protected: + T zeValue() const; protected: T *_pt; int _nb_of_compo; @@ -843,6 +849,24 @@ namespace MEDCoupling MEDCOUPLING_EXPORT double doubleValue() const; MEDCOUPLING_EXPORT DataArrayDouble *buildDADouble(int nbOfTuples, int nbOfCompo) const; }; + + class DataArrayFloatTuple; + + class DataArrayFloatIterator : public DataArrayIterator + { + public: + MEDCOUPLING_EXPORT DataArrayFloatIterator(DataArrayFloat *da); + MEDCOUPLING_EXPORT ~DataArrayFloatIterator() { } + }; + + class DataArrayFloatTuple : public DataArrayTuple + { + public: + MEDCOUPLING_EXPORT DataArrayFloatTuple(float *pt, int nbOfComp); + MEDCOUPLING_EXPORT std::string repr() const; + MEDCOUPLING_EXPORT float floatValue() const; + MEDCOUPLING_EXPORT DataArrayFloat *buildDAFloat(int nbOfTuples, int nbOfCompo) const; + }; class DataArrayIntTuple; diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index f5267f8de..9e804bc6a 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -523,6 +523,31 @@ namespace MEDCoupling { } + template + T DataArrayTuple::zeValue() const + { + if(_nb_of_compo==1) + return *_pt; + throw INTERP_KERNEL::Exception("DataArrayTuple::zeValue : DataArrayTuple instance has not exactly 1 component -> Not possible to convert it into a single value !"); + } + + template + typename Traits::ArrayType *DataArrayTuple::buildDA(int nbOfTuples, int nbOfCompo) const + { + if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1)) + { + typename Traits::ArrayType *ret=Traits::ArrayType::New(); + ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo); + return ret; + } + else + { + std::ostringstream oss; oss << "DataArrayTuple::buildDA : unable to build a requested DataArrayDouble instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo; + oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + ////////////////////////////////// template diff --git a/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx b/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx index 36f4de3bb..dd2f3c5aa 100644 --- a/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx +++ b/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx @@ -26,6 +26,7 @@ template class MEDCoupling::MemArray; template class MEDCoupling::DataArrayTemplate; template class MEDCoupling::DataArrayTemplateClassic; template class MEDCoupling::DataArrayTemplateFP; +template class MEDCoupling::DataArrayIterator; DataArrayFloat *DataArrayFloat::New() { @@ -180,3 +181,41 @@ DataArrayFloat *DataArrayFloat::performCopyOrIncrRef(bool dCpy) const { return DataArrayTemplateClassic::PerformCopyOrIncrRef(dCpy,*this); } + +DataArrayFloatIterator *DataArrayFloat::iterator() +{ + return new DataArrayFloatIterator(this); +} + +DataArrayFloatIterator::DataArrayFloatIterator(DataArrayFloat *da):DataArrayIterator(da) +{ +} + +DataArrayFloatTuple::DataArrayFloatTuple(float *pt, int nbOfComp):DataArrayTuple(pt,nbOfComp) +{ +} + +std::string DataArrayFloatTuple::repr() const +{ + std::ostringstream oss; oss.precision(7); oss << "("; + for(int i=0;i<_nb_of_compo-1;i++) + oss << _pt[i] << ", "; + oss << _pt[_nb_of_compo-1] << ")"; + return oss.str(); +} + +float DataArrayFloatTuple::floatValue() const +{ + return this->zeValue(); +} + +/*! + * This method returns a newly allocated instance the caller should dealed with by a MEDCoupling::DataArrayFloat::decrRef. + * This method performs \b no copy of data. The content is only referenced using MEDCoupling::DataArrayFloat::useArray with ownership set to \b false. + * This method throws an INTERP_KERNEL::Exception is it is impossible to match sizes of \b this that is too say \b nbOfCompo=this->_nb_of_elem and \bnbOfTuples==1 or + * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem. + */ +DataArrayFloat *DataArrayFloatTuple::buildDAFloat(int nbOfTuples, int nbOfCompo) const +{ + return this->buildDA(nbOfTuples,nbOfCompo); +} diff --git a/src/MEDCoupling/MEDCouplingTraits.hxx b/src/MEDCoupling/MEDCouplingTraits.hxx index bb22dbe06..11e62f87d 100644 --- a/src/MEDCoupling/MEDCouplingTraits.hxx +++ b/src/MEDCoupling/MEDCouplingTraits.hxx @@ -40,6 +40,7 @@ namespace MEDCoupling class MEDCouplingFieldFloat; class MEDCouplingFieldInt; class DataArrayIntTuple; + class DataArrayFloatTuple; class DataArrayDoubleTuple; template<> @@ -63,6 +64,7 @@ namespace MEDCoupling typedef DataArrayFloat ArrayType; typedef DataArrayFloat ArrayTypeCh; typedef MEDCouplingFieldFloat FieldType; + typedef DataArrayFloatTuple ArrayTuple; }; template<> diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index c96a45ad1..36df75802 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -80,6 +80,9 @@ def MEDCouplingDataArrayIntIpow(self,*args): def MEDCouplingDataArrayBytenew(cls,*args): import _MEDCoupling return _MEDCoupling.DataArrayByte____new___(cls,args) +def MEDCouplingDataArrayFloatImul(self,*args): + import _MEDCoupling + return _MEDCoupling.DataArrayFloat____imul___(self, self, *args) def MEDCouplingDataArrayDoubleTupleIadd(self,*args): import _MEDCoupling return _MEDCoupling.DataArrayDoubleTuple____iadd___(self, self, *args) diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 04512d14d..7d31929f3 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -477,7 +477,9 @@ using namespace INTERP_KERNEL; {// AGY : here initialization of C++ traits in MEDCouplingDataArrayTypemaps.i for code factorization. Awful, I know, but no other solutions. SWIGTITraits::TI=SWIGTYPE_p_MEDCoupling__DataArrayDouble; SWIGTITraits::TI=SWIGTYPE_p_MEDCoupling__DataArrayFloat; + SWIGTITraits::TI=SWIGTYPE_p_MEDCoupling__DataArrayInt; SWIGTITraits::TI_TUPLE=SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple; + SWIGTITraits::TI_TUPLE=SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple; SWIGTITraits::TI_TUPLE=SWIGTYPE_p_MEDCoupling__DataArrayIntTuple; } %} diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i index 93c2f8cf2..0d1783231 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i @@ -1564,15 +1564,8 @@ static void convertDoubleStarLikePyObjToCpp(PyObject *value, int& sw, double& iT sw=3; } -/*! - * 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 sw=4 - * if value tuple[int,double] -> cpp std::vector sw=4 - */ -static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector& f) +template +void convertFPStarLikePyObjToCpp_2(PyObject *value, int& sw, T& val, typename MEDCoupling::Traits::ArrayType *&d, typename MEDCoupling::Traits::ArrayTuple *&e, std::vector& f, swig_type_info *ti_da, swig_type_info *ti_tuple) { sw=-1; if(PyFloat_Check(value)) @@ -1583,7 +1576,7 @@ static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& } if(PyInt_Check(value)) { - val=(double)PyInt_AS_LONG(value); + val=(T)PyInt_AS_LONG(value); sw=1; return; } @@ -1597,7 +1590,7 @@ static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& if(PyFloat_Check(o)) f[i]=PyFloat_AS_DOUBLE(o); else if(PyInt_Check(o)) - f[i]=(double)PyInt_AS_LONG(o); + f[i]=(T)PyInt_AS_LONG(o); else { std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !"; @@ -1617,7 +1610,7 @@ static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& if(PyFloat_Check(o)) f[i]=PyFloat_AS_DOUBLE(o); else if(PyInt_Check(o)) - f[i]=(double)PyInt_AS_LONG(o); + f[i]=(T)PyInt_AS_LONG(o); else { std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !"; @@ -1628,23 +1621,36 @@ static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& return; } void *argp; - int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0); + int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0); if(SWIG_IsOK(status)) { - d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp); + d=reinterpret_cast< typename MEDCoupling::Traits::ArrayType * >(argp); sw=2; return ; } - status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0); + status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0); if(SWIG_IsOK(status)) { - e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp); + e=reinterpret_cast< typename MEDCoupling::Traits::ArrayTuple * >(argp); sw=3; return ; } throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, 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 sw=4 + * if value tuple[int,double] -> cpp std::vector sw=4 + */ +static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector& f) +{ + convertFPStarLikePyObjToCpp_2(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple); +} + /*! * if python int -> cpp int sw=1 * if python list[int] -> cpp vector sw=2 @@ -2990,6 +2996,50 @@ PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits::A } } +template +PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple) +{ + const char msg[]="Unexpected situation in __imul__ !"; + T val; + typename MEDCoupling::Traits::ArrayType *a; + typename MEDCoupling::Traits::ArrayTuple *aa; + std::vector bb; + int sw; + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); + convertFPStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb,ti_da,ti_tuple); + switch(sw) + { + case 1: + { + self->applyLin(val,0.); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + self->multiplyEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCoupling::MCAuto< typename MEDCoupling::Traits::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents())); + self->multiplyEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCoupling::MCAuto< typename MEDCoupling::Traits::ArrayType > aaa(MEDCoupling::Traits::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size()); + self->multiplyEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } +} + template struct SWIGTITraits { }; @@ -3029,4 +3079,10 @@ PyObject *DataArrayT__getitem(const typename MEDCoupling::Traits::ArrayType * return DataArrayT__getitem__internal(self,obj,SWIGTITraits::TI); } +template +PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits::ArrayType *self) +{ + return DataArrayT_imul__internal(trueSelf,obj,self,SWIGTITraits::TI,SWIGTITraits::TI_TUPLE); +} + #endif diff --git a/src/MEDCoupling_Swig/MEDCouplingFinalize.i b/src/MEDCoupling_Swig/MEDCouplingFinalize.i index 1640bc63b..eef6598ad 100644 --- a/src/MEDCoupling_Swig/MEDCouplingFinalize.i +++ b/src/MEDCoupling_Swig/MEDCouplingFinalize.i @@ -36,6 +36,8 @@ DataArrayInt.__ipow__=MEDCouplingDataArrayIntIpow DataArrayByte.__new__=classmethod(MEDCouplingDataArrayBytenew) +DataArrayFloat.__imul__=MEDCouplingDataArrayFloatImul + MEDCouplingFieldDouble.__iadd__=MEDCouplingFieldDoubleIadd MEDCouplingFieldDouble.__isub__=MEDCouplingFieldDoubleIsub MEDCouplingFieldDouble.__imul__=MEDCouplingFieldDoubleImul diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 5c863dccd..2228e73dc 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -50,6 +50,8 @@ %newobject MEDCoupling::DataArray::selectByTupleIdSafeSlice; %newobject MEDCoupling::DataArray::Aggregate; %newobject MEDCoupling::DataArrayFloat::New; +%newobject MEDCoupling::DataArrayFloat::iterator; +%newobject MEDCoupling::DataArrayFloat::__iter__; %newobject MEDCoupling::DataArrayInt::New; %newobject MEDCoupling::DataArrayInt::__iter__; %newobject MEDCoupling::DataArrayInt::selectPartDef; @@ -671,6 +673,7 @@ namespace MEDCoupling bool isUniform(float val, float eps) const throw(INTERP_KERNEL::Exception); void pushBackSilent(float val) throw(INTERP_KERNEL::Exception); void iota(float init=0.) throw(INTERP_KERNEL::Exception); + DataArrayFloatIterator *iterator() throw(INTERP_KERNEL::Exception); %extend { DataArrayFloat() throw(INTERP_KERNEL::Exception) @@ -687,6 +690,11 @@ namespace MEDCoupling { return MEDCoupling_DataArrayFloat_New__SWIG_1(elt0,nbOfTuples,elt2); } + + DataArrayFloatIterator *__iter__() throw(INTERP_KERNEL::Exception) + { + return self->iterator(); + } std::string __repr__() const throw(INTERP_KERNEL::Exception) { @@ -734,6 +742,11 @@ namespace MEDCoupling { return DataArrayT__setitem__(self,obj,value); } + + PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return DataArrayT_imul(trueSelf,obj,self); + } #ifdef WITH_NUMPY PyObject *toNumPyArray() throw(INTERP_KERNEL::Exception) // not const. It is not a bug ! @@ -744,6 +757,66 @@ namespace MEDCoupling } }; + + class DataArrayFloatTuple; + + class DataArrayFloatIterator + { + public: + DataArrayFloatIterator(DataArrayFloat *da); + ~DataArrayFloatIterator(); + %extend + { + PyObject *next() + { + DataArrayFloatTuple *ret=self->nextt(); + if(ret) + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple,SWIG_POINTER_OWN|0); + else + { + PyErr_SetString(PyExc_StopIteration,"No more data."); + return 0; + } + } + } + }; + + class DataArrayFloatTuple + { + public: + int getNumberOfCompo() const throw(INTERP_KERNEL::Exception); + DataArrayFloat *buildDAFloat(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception); + %extend + { + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->repr(); + } + + float __float__() const throw(INTERP_KERNEL::Exception) + { + return self->floatValue(); + } + + DataArrayFloat *buildDAFloat() throw(INTERP_KERNEL::Exception) + { + return self->buildDAFloat(1,self->getNumberOfCompo()); + } + + /*PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + MCAuto ret=self->buildDAFloat(1,self->getNumberOfCompo()); + MEDCoupling_DataArrayFloat____imul___(ret,0,obj); + Py_XINCREF(trueSelf); + return trueSelf; + }*/ + + PyObject *__len__() throw(INTERP_KERNEL::Exception) + { + return PyInt_FromLong(self->getNumberOfCompo()); + } + } + }; class DataArrayInt; class DataArrayDoubleIterator; @@ -1685,44 +1758,7 @@ namespace MEDCoupling PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in __imul__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - self->applyLin(val,0.); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->multiplyEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->multiplyEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MCAuto aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->multiplyEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } + return DataArrayT_imul(trueSelf,obj,self); } PyObject *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception)