From: Anthony Geay Date: Wed, 3 May 2017 07:53:01 +0000 (+0200) Subject: OK MEDCouplingFieldFloat is usable X-Git-Tag: V8_4_0a1~64 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4ad5cbc849666c76b440b3541e1a7684466b8955;p=tools%2Fmedcoupling.git OK MEDCouplingFieldFloat is usable --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index a2eaa57e3..52b1788ad 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -3622,285 +3622,6 @@ DataArrayDouble *DataArrayDouble::Min(const DataArrayDouble *a1, const DataArray return ret; } -/*! - * Returns a new DataArrayDouble that is a sum of two given arrays. There are 3 - * valid cases. - * 1. The arrays have same number of tuples and components. Then each value of - * the result array (_a_) is a sum of the corresponding values of \a a1 and \a a2, - * i.e.: _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, j ]. - * 2. The arrays have same number of tuples and one array, say _a2_, has one - * component. Then - * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, 0 ]. - * 3. The arrays have same number of components and one array, say _a2_, has one - * tuple. Then - * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ]. - * - * Info on components is copied either from the first array (in the first case) or from - * the array with maximal number of elements (getNbOfElems()). - * \param [in] a1 - an array to sum up. - * \param [in] a2 - another array to sum up. - * \return DataArrayDouble * - the new instance of DataArrayDouble. - * The caller is to delete this result array using decrRef() as it is no more - * needed. - * \throw If either \a a1 or \a a2 is NULL. - * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and - * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and - * none of them has number of tuples or components equal to 1. - */ -DataArrayDouble *DataArrayDouble::Add(const DataArrayDouble *a1, const DataArrayDouble *a2) -{ - if(!a1 || !a2) - throw INTERP_KERNEL::Exception("DataArrayDouble::Add : input DataArrayDouble instance is NULL !"); - int nbOfTuple=a1->getNumberOfTuples(); - int nbOfTuple2=a2->getNumberOfTuples(); - int nbOfComp=a1->getNumberOfComponents(); - int nbOfComp2=a2->getNumberOfComponents(); - MCAuto ret=0; - if(nbOfTuple==nbOfTuple2) - { - if(nbOfComp==nbOfComp2) - { - ret=DataArrayDouble::New(); - ret->alloc(nbOfTuple,nbOfComp); - std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus()); - ret->copyStringInfoFrom(*a1); - } - else - { - int nbOfCompMin,nbOfCompMax; - const DataArrayDouble *aMin, *aMax; - if(nbOfComp>nbOfComp2) - { - nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp; - aMin=a2; aMax=a1; - } - else - { - nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2; - aMin=a1; aMax=a2; - } - if(nbOfCompMin==1) - { - ret=DataArrayDouble::New(); - ret->alloc(nbOfTuple,nbOfCompMax); - const double *aMinPtr=aMin->getConstPointer(); - const double *aMaxPtr=aMax->getConstPointer(); - double *res=ret->getPointer(); - for(int i=0;i(),aMinPtr[i])); - ret->copyStringInfoFrom(*aMax); - } - else - throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !"); - } - } - else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1)) - { - if(nbOfComp==nbOfComp2) - { - int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2); - const DataArrayDouble *aMin=nbOfTuple>nbOfTuple2?a2:a1; - const DataArrayDouble *aMax=nbOfTuple>nbOfTuple2?a1:a2; - const double *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer(); - ret=DataArrayDouble::New(); - ret->alloc(nbOfTupleMax,nbOfComp); - double *res=ret->getPointer(); - for(int i=0;i()); - ret->copyStringInfoFrom(*aMax); - } - else - throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !"); - } - else - throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !"); - return ret.retn(); -} - -/*! - * Adds values of another DataArrayDouble to values of \a this one. There are 3 - * valid cases. - * 1. The arrays have same number of tuples and components. Then each value of - * \a other array is added to the corresponding value of \a this array, i.e.: - * _a_ [ i, j ] += _other_ [ i, j ]. - * 2. The arrays have same number of tuples and \a other array has one component. Then - * _a_ [ i, j ] += _other_ [ i, 0 ]. - * 3. The arrays have same number of components and \a other array has one tuple. Then - * _a_ [ i, j ] += _a2_ [ 0, j ]. - * - * \param [in] other - an array to add to \a this one. - * \throw If \a other is NULL. - * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and - * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and - * \a other has number of both tuples and components not equal to 1. - */ -void DataArrayDouble::addEqual(const DataArrayDouble *other) -{ - if(!other) - throw INTERP_KERNEL::Exception("DataArrayDouble::addEqual : input DataArrayDouble instance is NULL !"); - const char *msg="Nb of tuples mismatch for DataArrayDouble::addEqual !"; - checkAllocated(); - other->checkAllocated(); - int nbOfTuple=getNumberOfTuples(); - int nbOfTuple2=other->getNumberOfTuples(); - int nbOfComp=getNumberOfComponents(); - int nbOfComp2=other->getNumberOfComponents(); - if(nbOfTuple==nbOfTuple2) - { - if(nbOfComp==nbOfComp2) - { - std::transform(begin(),end(),other->begin(),getPointer(),std::plus()); - } - else if(nbOfComp2==1) - { - double *ptr=getPointer(); - const double *ptrc=other->getConstPointer(); - for(int i=0;i(),*ptrc++)); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else if(nbOfTuple2==1) - { - if(nbOfComp2==nbOfComp) - { - double *ptr=getPointer(); - const double *ptrc=other->getConstPointer(); - for(int i=0;i()); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - throw INTERP_KERNEL::Exception(msg); - declareAsNew(); -} - -/*! - * Subtract values of another DataArrayDouble from values of \a this one. There are 3 - * valid cases. - * 1. The arrays have same number of tuples and components. Then each value of - * \a other array is subtracted from the corresponding value of \a this array, i.e.: - * _a_ [ i, j ] -= _other_ [ i, j ]. - * 2. The arrays have same number of tuples and \a other array has one component. Then - * _a_ [ i, j ] -= _other_ [ i, 0 ]. - * 3. The arrays have same number of components and \a other array has one tuple. Then - * _a_ [ i, j ] -= _a2_ [ 0, j ]. - * - * \param [in] other - an array to subtract from \a this one. - * \throw If \a other is NULL. - * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and - * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and - * \a other has number of both tuples and components not equal to 1. - */ -void DataArrayDouble::substractEqual(const DataArrayDouble *other) -{ - if(!other) - throw INTERP_KERNEL::Exception("DataArrayDouble::substractEqual : input DataArrayDouble instance is NULL !"); - const char *msg="Nb of tuples mismatch for DataArrayDouble::substractEqual !"; - checkAllocated(); - other->checkAllocated(); - int nbOfTuple=getNumberOfTuples(); - int nbOfTuple2=other->getNumberOfTuples(); - int nbOfComp=getNumberOfComponents(); - int nbOfComp2=other->getNumberOfComponents(); - if(nbOfTuple==nbOfTuple2) - { - if(nbOfComp==nbOfComp2) - { - std::transform(begin(),end(),other->begin(),getPointer(),std::minus()); - } - else if(nbOfComp2==1) - { - double *ptr=getPointer(); - const double *ptrc=other->getConstPointer(); - for(int i=0;i(),*ptrc++)); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else if(nbOfTuple2==1) - { - if(nbOfComp2==nbOfComp) - { - double *ptr=getPointer(); - const double *ptrc=other->getConstPointer(); - for(int i=0;i()); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - throw INTERP_KERNEL::Exception(msg); - declareAsNew(); -} - -/*! - * Divide values of \a this array by values of another DataArrayDouble. There are 3 - * valid cases. - * 1. The arrays have same number of tuples and components. Then each value of - * \a this array is divided by the corresponding value of \a other one, i.e.: - * _a_ [ i, j ] /= _other_ [ i, j ]. - * 2. The arrays have same number of tuples and \a other array has one component. Then - * _a_ [ i, j ] /= _other_ [ i, 0 ]. - * 3. The arrays have same number of components and \a other array has one tuple. Then - * _a_ [ i, j ] /= _a2_ [ 0, j ]. - * - * \warning No check of division by zero is performed! - * \param [in] other - an array to divide \a this one by. - * \throw If \a other is NULL. - * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and - * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and - * \a other has number of both tuples and components not equal to 1. - */ -void DataArrayDouble::divideEqual(const DataArrayDouble *other) -{ - if(!other) - throw INTERP_KERNEL::Exception("DataArrayDouble::divideEqual : input DataArrayDouble instance is NULL !"); - const char *msg="Nb of tuples mismatch for DataArrayDouble::divideEqual !"; - checkAllocated(); - other->checkAllocated(); - int nbOfTuple=getNumberOfTuples(); - int nbOfTuple2=other->getNumberOfTuples(); - int nbOfComp=getNumberOfComponents(); - int nbOfComp2=other->getNumberOfComponents(); - if(nbOfTuple==nbOfTuple2) - { - if(nbOfComp==nbOfComp2) - { - std::transform(begin(),end(),other->begin(),getPointer(),std::divides()); - } - else if(nbOfComp2==1) - { - double *ptr=getPointer(); - const double *ptrc=other->getConstPointer(); - for(int i=0;i(),*ptrc++)); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else if(nbOfTuple2==1) - { - if(nbOfComp2==nbOfComp) - { - double *ptr=getPointer(); - const double *ptrc=other->getConstPointer(); - for(int i=0;i()); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - throw INTERP_KERNEL::Exception(msg); - declareAsNew(); -} - /*! * Returns a new DataArrayDouble that is the result of pow of two given arrays. There are 3 * valid cases. @@ -7703,278 +7424,6 @@ std::vector< std::pair > DataArrayInt::splitInBalancedSlices(int nbOfSl return ret; } -/*! - * Returns a new DataArrayInt that is a sum of two given arrays. There are 3 - * valid cases. - * 1. The arrays have same number of tuples and components. Then each value of - * the result array (_a_) is a sum of the corresponding values of \a a1 and \a a2, - * i.e.: _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, j ]. - * 2. The arrays have same number of tuples and one array, say _a2_, has one - * component. Then - * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, 0 ]. - * 3. The arrays have same number of components and one array, say _a2_, has one - * tuple. Then - * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ]. - * - * Info on components is copied either from the first array (in the first case) or from - * the array with maximal number of elements (getNbOfElems()). - * \param [in] a1 - an array to sum up. - * \param [in] a2 - another array to sum up. - * \return DataArrayInt * - the new instance of DataArrayInt. - * The caller is to delete this result array using decrRef() as it is no more - * needed. - * \throw If either \a a1 or \a a2 is NULL. - * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and - * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and - * none of them has number of tuples or components equal to 1. - */ -DataArrayInt *DataArrayInt::Add(const DataArrayInt *a1, const DataArrayInt *a2) -{ - if(!a1 || !a2) - throw INTERP_KERNEL::Exception("DataArrayInt::Add : input DataArrayInt instance is NULL !"); - int nbOfTuple=a1->getNumberOfTuples(); - int nbOfTuple2=a2->getNumberOfTuples(); - int nbOfComp=a1->getNumberOfComponents(); - int nbOfComp2=a2->getNumberOfComponents(); - MCAuto ret=0; - if(nbOfTuple==nbOfTuple2) - { - if(nbOfComp==nbOfComp2) - { - ret=DataArrayInt::New(); - ret->alloc(nbOfTuple,nbOfComp); - std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus()); - ret->copyStringInfoFrom(*a1); - } - else - { - int nbOfCompMin,nbOfCompMax; - const DataArrayInt *aMin, *aMax; - if(nbOfComp>nbOfComp2) - { - nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp; - aMin=a2; aMax=a1; - } - else - { - nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2; - aMin=a1; aMax=a2; - } - if(nbOfCompMin==1) - { - ret=DataArrayInt::New(); - ret->alloc(nbOfTuple,nbOfCompMax); - const int *aMinPtr=aMin->getConstPointer(); - const int *aMaxPtr=aMax->getConstPointer(); - int *res=ret->getPointer(); - for(int i=0;i(),aMinPtr[i])); - ret->copyStringInfoFrom(*aMax); - } - else - throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !"); - } - } - else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1)) - { - if(nbOfComp==nbOfComp2) - { - int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2); - const DataArrayInt *aMin=nbOfTuple>nbOfTuple2?a2:a1; - const DataArrayInt *aMax=nbOfTuple>nbOfTuple2?a1:a2; - const int *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer(); - ret=DataArrayInt::New(); - ret->alloc(nbOfTupleMax,nbOfComp); - int *res=ret->getPointer(); - for(int i=0;i()); - ret->copyStringInfoFrom(*aMax); - } - else - throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !"); - } - else - throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !"); - return ret.retn(); -} - -/*! - * Adds values of another DataArrayInt to values of \a this one. There are 3 - * valid cases. - * 1. The arrays have same number of tuples and components. Then each value of - * \a other array is added to the corresponding value of \a this array, i.e.: - * _a_ [ i, j ] += _other_ [ i, j ]. - * 2. The arrays have same number of tuples and \a other array has one component. Then - * _a_ [ i, j ] += _other_ [ i, 0 ]. - * 3. The arrays have same number of components and \a other array has one tuple. Then - * _a_ [ i, j ] += _a2_ [ 0, j ]. - * - * \param [in] other - an array to add to \a this one. - * \throw If \a other is NULL. - * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and - * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and - * \a other has number of both tuples and components not equal to 1. - */ -void DataArrayInt::addEqual(const DataArrayInt *other) -{ - if(!other) - throw INTERP_KERNEL::Exception("DataArrayInt::addEqual : input DataArrayInt instance is NULL !"); - const char *msg="Nb of tuples mismatch for DataArrayInt::addEqual !"; - checkAllocated(); other->checkAllocated(); - int nbOfTuple=getNumberOfTuples(); - int nbOfTuple2=other->getNumberOfTuples(); - int nbOfComp=getNumberOfComponents(); - int nbOfComp2=other->getNumberOfComponents(); - if(nbOfTuple==nbOfTuple2) - { - if(nbOfComp==nbOfComp2) - { - std::transform(begin(),end(),other->begin(),getPointer(),std::plus()); - } - else if(nbOfComp2==1) - { - int *ptr=getPointer(); - const int *ptrc=other->getConstPointer(); - for(int i=0;i(),*ptrc++)); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else if(nbOfTuple2==1) - { - if(nbOfComp2==nbOfComp) - { - int *ptr=getPointer(); - const int *ptrc=other->getConstPointer(); - for(int i=0;i()); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - throw INTERP_KERNEL::Exception(msg); - declareAsNew(); -} - -/*! - * Subtract values of another DataArrayInt from values of \a this one. There are 3 - * valid cases. - * 1. The arrays have same number of tuples and components. Then each value of - * \a other array is subtracted from the corresponding value of \a this array, i.e.: - * _a_ [ i, j ] -= _other_ [ i, j ]. - * 2. The arrays have same number of tuples and \a other array has one component. Then - * _a_ [ i, j ] -= _other_ [ i, 0 ]. - * 3. The arrays have same number of components and \a other array has one tuple. Then - * _a_ [ i, j ] -= _a2_ [ 0, j ]. - * - * \param [in] other - an array to subtract from \a this one. - * \throw If \a other is NULL. - * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and - * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and - * \a other has number of both tuples and components not equal to 1. - */ -void DataArrayInt::substractEqual(const DataArrayInt *other) -{ - if(!other) - throw INTERP_KERNEL::Exception("DataArrayInt::substractEqual : input DataArrayInt instance is NULL !"); - const char *msg="Nb of tuples mismatch for DataArrayInt::substractEqual !"; - checkAllocated(); other->checkAllocated(); - int nbOfTuple=getNumberOfTuples(); - int nbOfTuple2=other->getNumberOfTuples(); - int nbOfComp=getNumberOfComponents(); - int nbOfComp2=other->getNumberOfComponents(); - if(nbOfTuple==nbOfTuple2) - { - if(nbOfComp==nbOfComp2) - { - std::transform(begin(),end(),other->begin(),getPointer(),std::minus()); - } - else if(nbOfComp2==1) - { - int *ptr=getPointer(); - const int *ptrc=other->getConstPointer(); - for(int i=0;i(),*ptrc++)); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else if(nbOfTuple2==1) - { - int *ptr=getPointer(); - const int *ptrc=other->getConstPointer(); - for(int i=0;i()); - } - else - throw INTERP_KERNEL::Exception(msg); - declareAsNew(); -} - -/*! - * Divide values of \a this array by values of another DataArrayInt. There are 3 - * valid cases. - * 1. The arrays have same number of tuples and components. Then each value of - * \a this array is divided by the corresponding value of \a other one, i.e.: - * _a_ [ i, j ] /= _other_ [ i, j ]. - * 2. The arrays have same number of tuples and \a other array has one component. Then - * _a_ [ i, j ] /= _other_ [ i, 0 ]. - * 3. The arrays have same number of components and \a other array has one tuple. Then - * _a_ [ i, j ] /= _a2_ [ 0, j ]. - * - * \warning No check of division by zero is performed! - * \param [in] other - an array to divide \a this one by. - * \throw If \a other is NULL. - * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and - * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and - * \a other has number of both tuples and components not equal to 1. - */ -void DataArrayInt::divideEqual(const DataArrayInt *other) -{ - if(!other) - throw INTERP_KERNEL::Exception("DataArrayInt::divideEqual : input DataArrayInt instance is NULL !"); - const char *msg="Nb of tuples mismatch for DataArrayInt::divideEqual !"; - checkAllocated(); other->checkAllocated(); - int nbOfTuple=getNumberOfTuples(); - int nbOfTuple2=other->getNumberOfTuples(); - int nbOfComp=getNumberOfComponents(); - int nbOfComp2=other->getNumberOfComponents(); - if(nbOfTuple==nbOfTuple2) - { - if(nbOfComp==nbOfComp2) - { - std::transform(begin(),end(),other->begin(),getPointer(),std::divides()); - } - else if(nbOfComp2==1) - { - int *ptr=getPointer(); - const int *ptrc=other->getConstPointer(); - for(int i=0;i(),*ptrc++)); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else if(nbOfTuple2==1) - { - if(nbOfComp2==nbOfComp) - { - int *ptr=getPointer(); - const int *ptrc=other->getConstPointer(); - for(int i=0;i()); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - throw INTERP_KERNEL::Exception(msg); - declareAsNew(); -} - - /*! * Returns a new DataArrayInt that is a modulus of two given arrays. There are 3 * valid cases. diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index a3aac9bfc..59fd39043 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -307,15 +307,21 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void applyLin(T a, T b, int compoId); MEDCOUPLING_EXPORT void applyLin(T a, T b); MEDCOUPLING_EXPORT typename Traits::ArrayType *negate() const; + MEDCOUPLING_EXPORT void addEqual(const typename Traits::ArrayType *other); + MEDCOUPLING_EXPORT void substractEqual(const typename Traits::ArrayType *other); MEDCOUPLING_EXPORT void multiplyEqual(const typename Traits::ArrayType *other); + MEDCOUPLING_EXPORT void divideEqual(const typename Traits::ArrayType *other); MEDCOUPLING_EXPORT static typename Traits::ArrayType *Substract(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2); MEDCOUPLING_EXPORT static typename Traits::ArrayType *Divide(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2); + MEDCOUPLING_EXPORT static typename Traits::ArrayType *Add(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2); MEDCOUPLING_EXPORT static typename Traits::ArrayType *Multiply(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2); protected: static typename Traits::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits::ArrayType& self); private: template MCAuto< typename Traits::ArrayType > convertToOtherTypeOfArr() const; + template + void somethingEqual(const typename Traits::ArrayType *other); }; template @@ -481,10 +487,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT static DataArrayDouble *CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2); MEDCOUPLING_EXPORT static DataArrayDouble *Max(const DataArrayDouble *a1, const DataArrayDouble *a2); MEDCOUPLING_EXPORT static DataArrayDouble *Min(const DataArrayDouble *a1, const DataArrayDouble *a2); - MEDCOUPLING_EXPORT static DataArrayDouble *Add(const DataArrayDouble *a1, const DataArrayDouble *a2); - MEDCOUPLING_EXPORT void addEqual(const DataArrayDouble *other); - MEDCOUPLING_EXPORT void substractEqual(const DataArrayDouble *other); - MEDCOUPLING_EXPORT void divideEqual(const DataArrayDouble *other); MEDCOUPLING_EXPORT static DataArrayDouble *Pow(const DataArrayDouble *a1, const DataArrayDouble *a2); MEDCOUPLING_EXPORT void powEqual(const DataArrayDouble *other); MEDCOUPLING_EXPORT std::vector toVectorOfBool(double eps) const; @@ -649,10 +651,6 @@ namespace MEDCoupling void insertAtTheEnd(InputIterator first, InputIterator last); MEDCOUPLING_EXPORT void aggregate(const DataArrayInt *other); MEDCOUPLING_EXPORT void writeOnPlace(std::size_t id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } - MEDCOUPLING_EXPORT static DataArrayInt *Add(const DataArrayInt *a1, const DataArrayInt *a2); - MEDCOUPLING_EXPORT void addEqual(const DataArrayInt *other); - MEDCOUPLING_EXPORT void substractEqual(const DataArrayInt *other); - MEDCOUPLING_EXPORT void divideEqual(const DataArrayInt *other); MEDCOUPLING_EXPORT static DataArrayInt *Modulus(const DataArrayInt *a1, const DataArrayInt *a2); MEDCOUPLING_EXPORT void modulusEqual(const DataArrayInt *other); MEDCOUPLING_EXPORT static DataArrayInt *Pow(const DataArrayInt *a1, const DataArrayInt *a2); diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index fdde67307..944b6bced 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -2437,28 +2437,12 @@ namespace MEDCoupling return newArr.retn(); } - /*! - * Multiply values of another DataArrayDouble to values of \a this one. There are 3 - * valid cases. - * 1. The arrays have same number of tuples and components. Then each value of - * \a other array is multiplied to the corresponding value of \a this array, i.e. - * _this_ [ i, j ] *= _other_ [ i, j ]. - * 2. The arrays have same number of tuples and \a other array has one component. Then - * _this_ [ i, j ] *= _other_ [ i, 0 ]. - * 3. The arrays have same number of components and \a other array has one tuple. Then - * _this_ [ i, j ] *= _a2_ [ 0, j ]. - * - * \param [in] other - an array to multiply to \a this one. - * \throw If \a other is NULL. - * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and - * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and - * \a other has number of both tuples and components not equal to 1. - */ template - void DataArrayTemplateClassic::multiplyEqual(const typename Traits::ArrayType *other) + template + void DataArrayTemplateClassic::somethingEqual(const typename Traits::ArrayType *other) { if(!other) - throw INTERP_KERNEL::Exception("DataArrayDouble::multiplyEqual : input DataArrayDouble instance is NULL !"); + throw INTERP_KERNEL::Exception("DataArray::SomethingEqual : input DataArray instance is NULL !"); const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !"; this->checkAllocated(); other->checkAllocated(); @@ -2468,14 +2452,14 @@ namespace MEDCoupling { if(nbOfComp==nbOfComp2) { - std::transform(this->begin(),this->end(),other->begin(),this->getPointer(),std::multiplies()); + std::transform(this->begin(),this->end(),other->begin(),this->getPointer(),FCT()); } else if(nbOfComp2==1) { T *ptr(this->getPointer()); const T *ptrc(other->begin()); for(int i=0;i(),*ptrc++)); + std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(FCT(),*ptrc++)); } else throw INTERP_KERNEL::Exception(msg); @@ -2487,7 +2471,7 @@ namespace MEDCoupling T *ptr(this->getPointer()); const T *ptrc(other->begin()); for(int i=0;i()); + std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,FCT()); } else throw INTERP_KERNEL::Exception(msg); @@ -2496,37 +2480,105 @@ namespace MEDCoupling throw INTERP_KERNEL::Exception(msg); this->declareAsNew(); } + + /*! + * Adds values of another DataArrayDouble to values of \a this one. There are 3 + * valid cases. + * 1. The arrays have same number of tuples and components. Then each value of + * \a other array is added to the corresponding value of \a this array, i.e.: + * _a_ [ i, j ] += _other_ [ i, j ]. + * 2. The arrays have same number of tuples and \a other array has one component. Then + * _a_ [ i, j ] += _other_ [ i, 0 ]. + * 3. The arrays have same number of components and \a other array has one tuple. Then + * _a_ [ i, j ] += _a2_ [ 0, j ]. + * + * \param [in] other - an array to add to \a this one. + * \throw If \a other is NULL. + * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and + * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and + * \a other has number of both tuples and components not equal to 1. + */ + template + void DataArrayTemplateClassic::addEqual(const typename Traits::ArrayType *other) + { + this->somethingEqual< std::plus >(other); + } /*! - * Returns a new DataArrayDouble that is a subtraction of two given arrays. There are 3 + * Subtract values of another DataArrayDouble from values of \a this one. There are 3 * valid cases. * 1. The arrays have same number of tuples and components. Then each value of - * the result array (_a_) is a subtraction of the corresponding values of \a a1 and - * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, j ]. - * 2. The arrays have same number of tuples and one array, say _a2_, has one - * component. Then - * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, 0 ]. - * 3. The arrays have same number of components and one array, say _a2_, has one - * tuple. Then - * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ]. + * \a other array is subtracted from the corresponding value of \a this array, i.e.: + * _a_ [ i, j ] -= _other_ [ i, j ]. + * 2. The arrays have same number of tuples and \a other array has one component. Then + * _a_ [ i, j ] -= _other_ [ i, 0 ]. + * 3. The arrays have same number of components and \a other array has one tuple. Then + * _a_ [ i, j ] -= _a2_ [ 0, j ]. * - * Info on components is copied either from the first array (in the first case) or from - * the array with maximal number of elements (getNbOfElems()). - * \param [in] a1 - an array to subtract from. - * \param [in] a2 - an array to subtract. - * \return DataArrayDouble * - the new instance of DataArrayDouble. - * The caller is to delete this result array using decrRef() as it is no more - * needed. - * \throw If either \a a1 or \a a2 is NULL. - * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and - * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and - * none of them has number of tuples or components equal to 1. + * \param [in] other - an array to subtract from \a this one. + * \throw If \a other is NULL. + * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and + * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and + * \a other has number of both tuples and components not equal to 1. */ template - typename Traits::ArrayType *DataArrayTemplateClassic::Substract(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2) + void DataArrayTemplateClassic::substractEqual(const typename Traits::ArrayType *other) + { + this->somethingEqual< std::minus >(other); + } + + /*! + * Multiply values of another DataArrayDouble to values of \a this one. There are 3 + * valid cases. + * 1. The arrays have same number of tuples and components. Then each value of + * \a other array is multiplied to the corresponding value of \a this array, i.e. + * _this_ [ i, j ] *= _other_ [ i, j ]. + * 2. The arrays have same number of tuples and \a other array has one component. Then + * _this_ [ i, j ] *= _other_ [ i, 0 ]. + * 3. The arrays have same number of components and \a other array has one tuple. Then + * _this_ [ i, j ] *= _a2_ [ 0, j ]. + * + * \param [in] other - an array to multiply to \a this one. + * \throw If \a other is NULL. + * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and + * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and + * \a other has number of both tuples and components not equal to 1. + */ + template + void DataArrayTemplateClassic::multiplyEqual(const typename Traits::ArrayType *other) + { + this->somethingEqual< std::multiplies >(other); + } + + /*! + * Divide values of \a this array by values of another DataArrayDouble. There are 3 + * valid cases. + * 1. The arrays have same number of tuples and components. Then each value of + * \a this array is divided by the corresponding value of \a other one, i.e.: + * _a_ [ i, j ] /= _other_ [ i, j ]. + * 2. The arrays have same number of tuples and \a other array has one component. Then + * _a_ [ i, j ] /= _other_ [ i, 0 ]. + * 3. The arrays have same number of components and \a other array has one tuple. Then + * _a_ [ i, j ] /= _a2_ [ 0, j ]. + * + * \warning No check of division by zero is performed! + * \param [in] other - an array to divide \a this one by. + * \throw If \a other is NULL. + * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and + * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and + * \a other has number of both tuples and components not equal to 1. + */ + template + void DataArrayTemplateClassic::divideEqual(const typename Traits::ArrayType *other) + { + this->somethingEqual< std::divides >(other); + } + + template + typename Traits::ArrayType *DivSub(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2) { if(!a1 || !a2) - throw INTERP_KERNEL::Exception("DataArrayDouble::Substract : input DataArrayDouble instance is NULL !"); + throw INTERP_KERNEL::Exception("DivSub : input DataArrayDouble instance is NULL !"); int nbOfTuple1(a1->getNumberOfTuples()),nbOfTuple2(a2->getNumberOfTuples()); int nbOfComp1(a1->getNumberOfComponents()),nbOfComp2(a2->getNumberOfComponents()); if(nbOfTuple2==nbOfTuple1) @@ -2535,7 +2587,7 @@ namespace MEDCoupling { MCAuto::ArrayType> ret(Traits::ArrayType::New()); ret->alloc(nbOfTuple2,nbOfComp1); - std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus()); + std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),FCT()); ret->copyStringInfoFrom(*a1); return ret.retn(); } @@ -2543,57 +2595,55 @@ namespace MEDCoupling { MCAuto::ArrayType> ret(Traits::ArrayType::New()); ret->alloc(nbOfTuple1,nbOfComp1); - const T *a2Ptr(a2->begin()); - const T *a1Ptr(a1->begin()); + const T *a2Ptr(a2->begin()),*a1Ptr(a1->begin()); T *res(ret->getPointer()); for(int i=0;i(),a2Ptr[i])); + res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(FCT(),a2Ptr[i])); ret->copyStringInfoFrom(*a1); return ret.retn(); } else { - a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !"); + a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !"); return 0; } } else if(nbOfTuple2==1) { - a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !"); + a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !"); MCAuto::ArrayType> ret(Traits::ArrayType::New()); ret->alloc(nbOfTuple1,nbOfComp1); - const T *a1ptr(a1->begin()),*a2ptr(a2->begin()); + const T *a1ptr=a1->begin(),*a2ptr(a2->begin()); T *pt(ret->getPointer()); for(int i=0;i()); + pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,FCT()); ret->copyStringInfoFrom(*a1); - return ret.retn(); + return ret.retn(); } else { - a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception + a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception return 0; - } + } } /*! - * Returns a new DataArrayDouble that is a division of two given arrays. There are 3 + * Returns a new DataArrayDouble that is a subtraction of two given arrays. There are 3 * valid cases. * 1. The arrays have same number of tuples and components. Then each value of - * the result array (_a_) is a division of the corresponding values of \a a1 and - * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, j ]. + * the result array (_a_) is a subtraction of the corresponding values of \a a1 and + * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, j ]. * 2. The arrays have same number of tuples and one array, say _a2_, has one * component. Then - * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, 0 ]. + * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, 0 ]. * 3. The arrays have same number of components and one array, say _a2_, has one * tuple. Then - * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ]. + * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ]. * * Info on components is copied either from the first array (in the first case) or from * the array with maximal number of elements (getNbOfElems()). - * \warning No check of division by zero is performed! - * \param [in] a1 - a numerator array. - * \param [in] a2 - a denominator array. + * \param [in] a1 - an array to subtract from. + * \param [in] a2 - an array to subtract. * \return DataArrayDouble * - the new instance of DataArrayDouble. * The caller is to delete this result array using decrRef() as it is no more * needed. @@ -2603,75 +2653,29 @@ namespace MEDCoupling * none of them has number of tuples or components equal to 1. */ template - typename Traits::ArrayType *DataArrayTemplateClassic::Divide(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2) + typename Traits::ArrayType *DataArrayTemplateClassic::Substract(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2) { - if(!a1 || !a2) - throw INTERP_KERNEL::Exception("DataArrayDouble::Divide : input DataArrayDouble instance is NULL !"); - int nbOfTuple1(a1->getNumberOfTuples()),nbOfTuple2(a2->getNumberOfTuples()); - int nbOfComp1(a1->getNumberOfComponents()),nbOfComp2(a2->getNumberOfComponents()); - if(nbOfTuple2==nbOfTuple1) - { - if(nbOfComp1==nbOfComp2) - { - MCAuto::ArrayType> ret(Traits::ArrayType::New()); - ret->alloc(nbOfTuple2,nbOfComp1); - std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides()); - ret->copyStringInfoFrom(*a1); - return ret.retn(); - } - else if(nbOfComp2==1) - { - MCAuto::ArrayType> ret(Traits::ArrayType::New()); - ret->alloc(nbOfTuple1,nbOfComp1); - const T *a2Ptr(a2->begin()),*a1Ptr(a1->begin()); - T *res(ret->getPointer()); - for(int i=0;i(),a2Ptr[i])); - ret->copyStringInfoFrom(*a1); - return ret.retn(); - } - else - { - a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !"); - return 0; - } - } - else if(nbOfTuple2==1) - { - a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !"); - MCAuto::ArrayType> ret(Traits::ArrayType::New()); - ret->alloc(nbOfTuple1,nbOfComp1); - const T *a1ptr=a1->begin(),*a2ptr(a2->begin()); - T *pt(ret->getPointer()); - for(int i=0;i()); - ret->copyStringInfoFrom(*a1); - return ret.retn(); - } - else - { - a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception - return 0; - } + return DivSub< T,std::minus >(a1,a2); } /*! - * Returns a new DataArrayDouble that is a product of two given arrays. There are 3 + * Returns a new DataArrayDouble that is a division of two given arrays. There are 3 * valid cases. * 1. The arrays have same number of tuples and components. Then each value of - * the result array (_a_) is a product of the corresponding values of \a a1 and - * \a a2, i.e. _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ]. + * the result array (_a_) is a division of the corresponding values of \a a1 and + * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, j ]. * 2. The arrays have same number of tuples and one array, say _a2_, has one * component. Then - * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, 0 ]. + * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, 0 ]. * 3. The arrays have same number of components and one array, say _a2_, has one * tuple. Then - * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ]. + * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ]. * * Info on components is copied either from the first array (in the first case) or from * the array with maximal number of elements (getNbOfElems()). - * \param [in] a1 - a factor array. - * \param [in] a2 - another factor array. + * \warning No check of division by zero is performed! + * \param [in] a1 - a numerator array. + * \param [in] a2 - a denominator array. * \return DataArrayDouble * - the new instance of DataArrayDouble. * The caller is to delete this result array using decrRef() as it is no more * needed. @@ -2681,10 +2685,16 @@ namespace MEDCoupling * none of them has number of tuples or components equal to 1. */ template - typename Traits::ArrayType *DataArrayTemplateClassic::Multiply(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2) + typename Traits::ArrayType *DataArrayTemplateClassic::Divide(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2) + { + return DivSub< T,std::divides >(a1,a2); + } + + template + typename Traits::ArrayType *MulAdd(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2) { if(!a1 || !a2) - throw INTERP_KERNEL::Exception("DataArrayDouble::Multiply : input DataArrayDouble instance is NULL !"); + throw INTERP_KERNEL::Exception("DataArrayDouble::MulAdd : input DataArrayDouble instance is NULL !"); int nbOfTuple(a1->getNumberOfTuples()),nbOfTuple2(a2->getNumberOfTuples()); int nbOfComp(a1->getNumberOfComponents()),nbOfComp2(a2->getNumberOfComponents()); MCAuto::ArrayType> ret=0; @@ -2694,7 +2704,7 @@ namespace MEDCoupling { ret=Traits::ArrayType::New(); ret->alloc(nbOfTuple,nbOfComp); - std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies()); + std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),FCT()); ret->copyStringInfoFrom(*a1); } else @@ -2719,11 +2729,11 @@ namespace MEDCoupling const T *aMaxPtr(aMax->begin()); T *res=ret->getPointer(); for(int i=0;i(),aMinPtr[i])); + res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(FCT(),aMinPtr[i])); ret->copyStringInfoFrom(*aMax); } else - throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !"); + throw INTERP_KERNEL::Exception("Nb of components mismatch for array MulAdd !"); } } else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1)) @@ -2738,17 +2748,79 @@ namespace MEDCoupling ret->alloc(nbOfTupleMax,nbOfComp); T *res(ret->getPointer()); for(int i=0;i()); + res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,FCT()); ret->copyStringInfoFrom(*aMax); } else - throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !"); + throw INTERP_KERNEL::Exception("Nb of components mismatch for array MulAdd !"); } else - throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !"); + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array MulAdd !"); return ret.retn(); } + /*! + * Returns a new DataArrayDouble that is a product of two given arrays. There are 3 + * valid cases. + * 1. The arrays have same number of tuples and components. Then each value of + * the result array (_a_) is a product of the corresponding values of \a a1 and + * \a a2, i.e. _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ]. + * 2. The arrays have same number of tuples and one array, say _a2_, has one + * component. Then + * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, 0 ]. + * 3. The arrays have same number of components and one array, say _a2_, has one + * tuple. Then + * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ]. + * + * Info on components is copied either from the first array (in the first case) or from + * the array with maximal number of elements (getNbOfElems()). + * \param [in] a1 - a factor array. + * \param [in] a2 - another factor array. + * \return DataArrayDouble * - the new instance of DataArrayDouble. + * The caller is to delete this result array using decrRef() as it is no more + * needed. + * \throw If either \a a1 or \a a2 is NULL. + * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and + * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and + * none of them has number of tuples or components equal to 1. + */ + template + typename Traits::ArrayType *DataArrayTemplateClassic::Multiply(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2) + { + return MulAdd< T , std::multiplies >(a1,a2); + } + + /*! + * Returns a new DataArrayDouble that is a sum of two given arrays. There are 3 + * valid cases. + * 1. The arrays have same number of tuples and components. Then each value of + * the result array (_a_) is a sum of the corresponding values of \a a1 and \a a2, + * i.e.: _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, j ]. + * 2. The arrays have same number of tuples and one array, say _a2_, has one + * component. Then + * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, 0 ]. + * 3. The arrays have same number of components and one array, say _a2_, has one + * tuple. Then + * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ]. + * + * Info on components is copied either from the first array (in the first case) or from + * the array with maximal number of elements (getNbOfElems()). + * \param [in] a1 - an array to sum up. + * \param [in] a2 - another array to sum up. + * \return DataArrayDouble * - the new instance of DataArrayDouble. + * The caller is to delete this result array using decrRef() as it is no more + * needed. + * \throw If either \a a1 or \a a2 is NULL. + * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and + * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and + * none of them has number of tuples or components equal to 1. + */ + template + typename Traits::ArrayType *DataArrayTemplateClassic::Add(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2) + { + return MulAdd< T , std::plus >(a1,a2); + } + /*! * Returns either a \a deep or \a shallow copy of this array. For more info see * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow. diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 36df75802..1b97cd31d 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -80,9 +80,18 @@ def MEDCouplingDataArrayIntIpow(self,*args): def MEDCouplingDataArrayBytenew(cls,*args): import _MEDCoupling return _MEDCoupling.DataArrayByte____new___(cls,args) +def MEDCouplingDataArrayFloatIadd(self,*args): + import _MEDCoupling + return _MEDCoupling.DataArrayFloat____iadd___(self, self, *args) +def MEDCouplingDataArrayFloatIsub(self,*args): + import _MEDCoupling + return _MEDCoupling.DataArrayFloat____isub___(self, self, *args) def MEDCouplingDataArrayFloatImul(self,*args): import _MEDCoupling return _MEDCoupling.DataArrayFloat____imul___(self, self, *args) +def MEDCouplingDataArrayFloatIdiv(self,*args): + import _MEDCoupling + return _MEDCoupling.DataArrayFloat____idiv___(self, self, *args) def MEDCouplingDataArrayDoubleTupleIadd(self,*args): import _MEDCoupling return _MEDCoupling.DataArrayDoubleTuple____iadd___(self, self, *args) diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py index 0dafaef97..ca606bac7 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py @@ -4587,7 +4587,6 @@ class MEDCouplingBasicsTest5(unittest.TestCase): self.assertEqual(a,3.2,12) pass -class MEDCouplingBasicsTest6:#5(unittest.TestCase): def testFieldFloatIsOnStage2(self): """ Very important test to check that isEqual of MEDCouplingFieldFloat is OK !""" m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1,2,3,4])) diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i index e9c066880..cc56b4775 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i @@ -3039,6 +3039,137 @@ PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename } } +template +PyObject *DataArrayT_idiv__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 __idiv__ !"; + T val; + typename MEDCoupling::Traits::ArrayType *a; + typename MEDCoupling::Traits::ArrayTuple *aa; + std::vector bb; + int sw; + convertFPStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb,ti_da,ti_tuple); + switch(sw) + { + case 1: + { + if(val==0.) + throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !"); + self->applyLin(1./val,0.); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + self->divideEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCoupling::MCAuto< typename MEDCoupling::Traits::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents())); + self->divideEqual(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->divideEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } +} + +template +PyObject *DataArrayT_iadd__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 __iadd__ !"; + T val; + typename MEDCoupling::Traits::ArrayType *a; + typename MEDCoupling::Traits::ArrayTuple *aa; + std::vector bb; + int sw; + convertFPStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb,ti_da,ti_tuple); + switch(sw) + { + case 1: + { + self->applyLin(1.,val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + self->addEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCoupling::MCAuto< typename MEDCoupling::Traits::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents())); + self->addEqual(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->addEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } +} + +template +PyObject *DataArrayT_isub__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 __isub__ !"; + T val; + typename MEDCoupling::Traits::ArrayType *a; + typename MEDCoupling::Traits::ArrayTuple *aa; + std::vector bb; + int sw; + convertFPStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb,ti_da,ti_tuple); + switch(sw) + { + case 1: + { + self->applyLin(1.,-val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + self->substractEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCoupling::MCAuto< typename MEDCoupling::Traits::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents())); + self->substractEqual(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->substractEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } +} + template struct SWIGTITraits { }; @@ -3084,4 +3215,22 @@ PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCouplin return DataArrayT_imul__internal(trueSelf,obj,self,SWIGTITraits::TI,SWIGTITraits::TI_TUPLE); } +template +PyObject *DataArrayT_idiv(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits::ArrayType *self) +{ + return DataArrayT_idiv__internal(trueSelf,obj,self,SWIGTITraits::TI,SWIGTITraits::TI_TUPLE); +} + +template +PyObject *DataArrayT_iadd(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits::ArrayType *self) +{ + return DataArrayT_iadd__internal(trueSelf,obj,self,SWIGTITraits::TI,SWIGTITraits::TI_TUPLE); +} + +template +PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits::ArrayType *self) +{ + return DataArrayT_isub__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 eef6598ad..467597ee4 100644 --- a/src/MEDCoupling_Swig/MEDCouplingFinalize.i +++ b/src/MEDCoupling_Swig/MEDCouplingFinalize.i @@ -36,7 +36,10 @@ DataArrayInt.__ipow__=MEDCouplingDataArrayIntIpow DataArrayByte.__new__=classmethod(MEDCouplingDataArrayBytenew) +DataArrayFloat.__iadd__=MEDCouplingDataArrayFloatIadd +DataArrayFloat.__isub__=MEDCouplingDataArrayFloatIsub DataArrayFloat.__imul__=MEDCouplingDataArrayFloatImul +DataArrayFloat.__idiv__=MEDCouplingDataArrayFloatIdiv MEDCouplingFieldDouble.__iadd__=MEDCouplingFieldDoubleIadd MEDCouplingFieldDouble.__isub__=MEDCouplingFieldDoubleIsub @@ -85,6 +88,10 @@ del MEDCouplingDataArrayIntImul del MEDCouplingDataArrayIntIdiv del MEDCouplingDataArrayIntImod del MEDCouplingDataArrayBytenew +del MEDCouplingDataArrayFloatIadd +del MEDCouplingDataArrayFloatIsub +del MEDCouplingDataArrayFloatImul +del MEDCouplingDataArrayFloatIdiv del MEDCouplingDataArrayDoubleTupleIadd del MEDCouplingDataArrayDoubleTupleIsub del MEDCouplingDataArrayDoubleTupleImul diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 2228e73dc..4b60cc0d9 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -742,11 +742,26 @@ namespace MEDCoupling { return DataArrayT__setitem__(self,obj,value); } + + PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return DataArrayT_iadd(trueSelf,obj,self); + } + + PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return DataArrayT_isub(trueSelf,obj,self); + } PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { return DataArrayT_imul(trueSelf,obj,self); } + + PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return DataArrayT_idiv(trueSelf,obj,self); + } #ifdef WITH_NUMPY PyObject *toNumPyArray() throw(INTERP_KERNEL::Exception) // not const. It is not a bug ! @@ -1502,44 +1517,7 @@ namespace MEDCoupling PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in __iadd__ !"; - 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(1.,val); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->addEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->addEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MCAuto aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->addEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } + return DataArrayT_iadd(trueSelf,obj,self); } PyObject *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception) @@ -1630,44 +1608,7 @@ namespace MEDCoupling PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in __isub__ !"; - 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(1,-val); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->substractEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->substractEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MCAuto aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->substractEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } + return DataArrayT_isub(trueSelf,obj,self); } PyObject *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception) @@ -1851,46 +1792,7 @@ namespace MEDCoupling PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in __idiv__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - if(val==0.) - throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !"); - self->applyLin(1./val,0.); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->divideEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->divideEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MCAuto aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->divideEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } + return DataArrayT_idiv(trueSelf,obj,self); } DataArrayDouble *__pow__(PyObject *obj) throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling_Swig/MEDCouplingRemapper.i b/src/MEDCoupling_Swig/MEDCouplingRemapper.i index 642aeb43c..71d4ad564 100644 --- a/src/MEDCoupling_Swig/MEDCouplingRemapper.i +++ b/src/MEDCoupling_Swig/MEDCouplingRemapper.i @@ -142,9 +142,18 @@ def MEDCouplingFieldDoubleIpow(self,*args): def MEDCouplingDataArrayBytenew(cls,*args): import _MEDCouplingRemapper return _MEDCouplingRemapper.DataArrayByte____new___(cls,args) +def MEDCouplingDataArrayFloatIadd(self,*args): + import _MEDCouplingRemapper + return _MEDCouplingRemapper.DataArrayFloat____iadd___(self, self, *args) +def MEDCouplingDataArrayFloatIsub(self,*args): + import _MEDCouplingRemapper + return _MEDCouplingRemapper.DataArrayFloat____isub___(self, self, *args) def MEDCouplingDataArrayFloatImul(self,*args): import _MEDCouplingRemapper return _MEDCouplingRemapper.DataArrayFloat____imul___(self, self, *args) +def MEDCouplingDataArrayFloatIdiv(self,*args): + import _MEDCouplingRemapper + return _MEDCouplingRemapper.DataArrayFloat____idiv___(self, self, *args) def MEDCouplingDataArrayIntnew(cls,*args): import _MEDCouplingRemapper return _MEDCouplingRemapper.DataArrayInt____new___(cls,args) diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index e14a804f0..c00b24538 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -60,9 +60,18 @@ def MEDCouplingFieldDoubleIpow(self,*args): def MEDCouplingDataArrayBytenew(cls,*args): import _MEDLoader return _MEDLoader.DataArrayByte____new___(cls,args) +def MEDCouplingDataArrayFloatIadd(self,*args): + import _MEDLoader + return _MEDLoader.DataArrayFloat____iadd___(self, self, *args) +def MEDCouplingDataArrayFloatIsub(self,*args): + import _MEDLoader + return _MEDLoader.DataArrayFloat____isub___(self, self, *args) def MEDCouplingDataArrayFloatImul(self,*args): import _MEDLoader return _MEDLoader.DataArrayFloat____imul___(self, self, *args) +def MEDCouplingDataArrayFloatIdiv(self,*args): + import _MEDLoader + return _MEDLoader.DataArrayFloat____idiv___(self, self, *args) def MEDCouplingDataArrayIntnew(cls,*args): import _MEDLoader return _MEDLoader.DataArrayInt____new___(cls,args) diff --git a/src/RENUMBER_Swig/MEDRenumber.i b/src/RENUMBER_Swig/MEDRenumber.i index 8cac841ce..54ab2c996 100644 --- a/src/RENUMBER_Swig/MEDRenumber.i +++ b/src/RENUMBER_Swig/MEDRenumber.i @@ -62,9 +62,18 @@ def MEDCouplingDataArrayIntIpow(self,*args): def MEDCouplingDataArrayBytenew(cls,*args): import _MEDRenumber return _MEDRenumber.DataArrayByte____new___(cls,args) +def MEDCouplingDataArrayFloatIadd(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayFloat____iadd___(self, self, *args) +def MEDCouplingDataArrayFloatIsub(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayFloat____isub___(self, self, *args) def MEDCouplingDataArrayFloatImul(self,*args): import _MEDRenumber return _MEDRenumber.DataArrayFloat____imul___(self, self, *args) +def MEDCouplingDataArrayFloatIdiv(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayFloat____idiv___(self, self, *args) def MEDCouplingDataArrayDoubleTupleIadd(self,*args): import _MEDRenumber return _MEDRenumber.DataArrayDoubleTuple____iadd___(self, self, *args)