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<DataArrayDouble> 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<double>());
- 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<nbOfTuple;i++)
- res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<double>(),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<nbOfTupleMax;i++)
- res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::plus<double>());
- 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<double>());
- }
- else if(nbOfComp2==1)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<double>(),*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<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<double>());
- }
- 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<double>());
- }
- else if(nbOfComp2==1)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<double>(),*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<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<double>());
- }
- 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<double>());
- }
- else if(nbOfComp2==1)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<double>(),*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<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<double>());
- }
- 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.
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<DataArrayInt> 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<int>());
- 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<nbOfTuple;i++)
- res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<int>(),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<nbOfTupleMax;i++)
- res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::plus<int>());
- 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<int>());
- }
- else if(nbOfComp2==1)
- {
- int *ptr=getPointer();
- const int *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<int>(),*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<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<int>());
- }
- 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<int>());
- }
- else if(nbOfComp2==1)
- {
- int *ptr=getPointer();
- const int *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<int>(),*ptrc++));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else if(nbOfTuple2==1)
- {
- int *ptr=getPointer();
- const int *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<int>());
- }
- 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<int>());
- }
- else if(nbOfComp2==1)
- {
- int *ptr=getPointer();
- const int *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<int>(),*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<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<int>());
- }
- 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.
MEDCOUPLING_EXPORT void applyLin(T a, T b, int compoId);
MEDCOUPLING_EXPORT void applyLin(T a, T b);
MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *negate() const;
+ MEDCOUPLING_EXPORT void addEqual(const typename Traits<T>::ArrayType *other);
+ MEDCOUPLING_EXPORT void substractEqual(const typename Traits<T>::ArrayType *other);
MEDCOUPLING_EXPORT void multiplyEqual(const typename Traits<T>::ArrayType *other);
+ MEDCOUPLING_EXPORT void divideEqual(const typename Traits<T>::ArrayType *other);
MEDCOUPLING_EXPORT static typename Traits<T>::ArrayType *Substract(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
MEDCOUPLING_EXPORT static typename Traits<T>::ArrayType *Divide(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
+ MEDCOUPLING_EXPORT static typename Traits<T>::ArrayType *Add(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
MEDCOUPLING_EXPORT static typename Traits<T>::ArrayType *Multiply(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
protected:
static typename Traits<T>::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits<T>::ArrayType& self);
private:
template<class U>
MCAuto< typename Traits<U>::ArrayType > convertToOtherTypeOfArr() const;
+ template<class FCT>
+ void somethingEqual(const typename Traits<T>::ArrayType *other);
};
template<class T>
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<bool> toVectorOfBool(double eps) const;
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);
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<class T>
- void DataArrayTemplateClassic<T>::multiplyEqual(const typename Traits<T>::ArrayType *other)
+ template<class FCT>
+ void DataArrayTemplateClassic<T>::somethingEqual(const typename Traits<T>::ArrayType *other)
{
if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::multiplyEqual : input DataArrayDouble instance is NULL !");
+ throw INTERP_KERNEL::Exception("DataArray<T>::SomethingEqual : input DataArray<T> instance is NULL !");
const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !";
this->checkAllocated();
other->checkAllocated();
{
if(nbOfComp==nbOfComp2)
{
- std::transform(this->begin(),this->end(),other->begin(),this->getPointer(),std::multiplies<T>());
+ 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<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::multiplies<T>(),*ptrc++));
+ std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(FCT(),*ptrc++));
}
else
throw INTERP_KERNEL::Exception(msg);
T *ptr(this->getPointer());
const T *ptrc(other->begin());
for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::multiplies<T>());
+ std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,FCT());
}
else
throw INTERP_KERNEL::Exception(msg);
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<class T>
+ void DataArrayTemplateClassic<T>::addEqual(const typename Traits<T>::ArrayType *other)
+ {
+ this->somethingEqual< std::plus<T> >(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<class T>
- typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Substract(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ void DataArrayTemplateClassic<T>::substractEqual(const typename Traits<T>::ArrayType *other)
+ {
+ this->somethingEqual< std::minus<T> >(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<class T>
+ void DataArrayTemplateClassic<T>::multiplyEqual(const typename Traits<T>::ArrayType *other)
+ {
+ this->somethingEqual< std::multiplies<T> >(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<class T>
+ void DataArrayTemplateClassic<T>::divideEqual(const typename Traits<T>::ArrayType *other)
+ {
+ this->somethingEqual< std::divides<T> >(other);
+ }
+
+ template<class T, class FCT>
+ typename Traits<T>::ArrayType *DivSub(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::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)
{
MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
ret->alloc(nbOfTuple2,nbOfComp1);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<T>());
+ std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),FCT());
ret->copyStringInfoFrom(*a1);
return ret.retn();
}
{
MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::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<nbOfTuple1;i++)
- res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::minus<T>(),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<typename Traits<T>::ArrayType> ret(Traits<T>::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<nbOfTuple1;i++)
- pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::minus<T>());
+ 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.
* none of them has number of tuples or components equal to 1.
*/
template<class T>
- typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Divide(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Substract(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::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<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
- ret->alloc(nbOfTuple2,nbOfComp1);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<T>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else if(nbOfComp2==1)
- {
- MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
- ret->alloc(nbOfTuple1,nbOfComp1);
- const T *a2Ptr(a2->begin()),*a1Ptr(a1->begin());
- T *res(ret->getPointer());
- for(int i=0;i<nbOfTuple1;i++)
- res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::divides<T>(),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<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
- ret->alloc(nbOfTuple1,nbOfComp1);
- const T *a1ptr=a1->begin(),*a2ptr(a2->begin());
- T *pt(ret->getPointer());
- for(int i=0;i<nbOfTuple1;i++)
- pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::divides<T>());
- 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<T> >(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.
* none of them has number of tuples or components equal to 1.
*/
template<class T>
- typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Multiply(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Divide(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ {
+ return DivSub< T,std::divides<T> >(a1,a2);
+ }
+
+ template<class T, class FCT>
+ typename Traits<T>::ArrayType *MulAdd(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::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<typename Traits<T>::ArrayType> ret=0;
{
ret=Traits<T>::ArrayType::New();
ret->alloc(nbOfTuple,nbOfComp);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<T>());
+ std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),FCT());
ret->copyStringInfoFrom(*a1);
}
else
const T *aMaxPtr(aMax->begin());
T *res=ret->getPointer();
for(int i=0;i<nbOfTuple;i++)
- res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<T>(),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))
ret->alloc(nbOfTupleMax,nbOfComp);
T *res(ret->getPointer());
for(int i=0;i<nbOfTupleMax;i++)
- res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::multiplies<T>());
+ 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<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Multiply(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ {
+ return MulAdd< T , std::multiplies<T> >(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<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Add(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
+ {
+ return MulAdd< T , std::plus<T> >(a1,a2);
+ }
+
/*!
* Returns either a \a deep or \a shallow copy of this array. For more info see
* \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
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)
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]))
}
}
+template<class T>
+PyObject *DataArrayT_idiv__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
+{
+ const char msg[]="Unexpected situation in __idiv__ !";
+ 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,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<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
+ self->divideEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 4:
+ {
+ 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());
+ self->divideEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+}
+
+template<class T>
+PyObject *DataArrayT_iadd__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
+{
+ const char msg[]="Unexpected situation in __iadd__ !";
+ 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,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<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
+ self->addEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 4:
+ {
+ 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());
+ self->addEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ default:
+ 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)
+{
+ const char msg[]="Unexpected situation in __isub__ !";
+ 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,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<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
+ self->substractEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 4:
+ {
+ 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());
+ self->substractEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+}
+
template<class T>
struct SWIGTITraits
{ };
return DataArrayT_imul__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
}
+template<class T>
+PyObject *DataArrayT_idiv(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
+{
+ return DataArrayT_idiv__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
+}
+
+template<class T>
+PyObject *DataArrayT_iadd(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
+{
+ return DataArrayT_iadd__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
+}
+
+template<class T>
+PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
+{
+ return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
+}
+
#endif
DataArrayByte.__new__=classmethod(MEDCouplingDataArrayBytenew)
+DataArrayFloat.__iadd__=MEDCouplingDataArrayFloatIadd
+DataArrayFloat.__isub__=MEDCouplingDataArrayFloatIsub
DataArrayFloat.__imul__=MEDCouplingDataArrayFloatImul
+DataArrayFloat.__idiv__=MEDCouplingDataArrayFloatIdiv
MEDCouplingFieldDouble.__iadd__=MEDCouplingFieldDoubleIadd
MEDCouplingFieldDouble.__isub__=MEDCouplingFieldDoubleIsub
del MEDCouplingDataArrayIntIdiv
del MEDCouplingDataArrayIntImod
del MEDCouplingDataArrayBytenew
+del MEDCouplingDataArrayFloatIadd
+del MEDCouplingDataArrayFloatIsub
+del MEDCouplingDataArrayFloatImul
+del MEDCouplingDataArrayFloatIdiv
del MEDCouplingDataArrayDoubleTupleIadd
del MEDCouplingDataArrayDoubleTupleIsub
del MEDCouplingDataArrayDoubleTupleImul
{
return DataArrayT__setitem__<float>(self,obj,value);
}
+
+ PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT_iadd<float>(trueSelf,obj,self);
+ }
+
+ PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT_isub<float>(trueSelf,obj,self);
+ }
PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
{
return DataArrayT_imul<float>(trueSelf,obj,self);
}
+
+ PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT_idiv<float>(trueSelf,obj,self);
+ }
#ifdef WITH_NUMPY
PyObject *toNumPyArray() throw(INTERP_KERNEL::Exception) // not const. It is not a bug !
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<double> 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<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
- self->addEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 4:
- {
- MCAuto<DataArrayDouble> 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<double>(trueSelf,obj,self);
}
PyObject *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception)
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<double> 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<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
- self->substractEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 4:
- {
- MCAuto<DataArrayDouble> 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<double>(trueSelf,obj,self);
}
PyObject *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception)
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<double> 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<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
- self->divideEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 4:
- {
- MCAuto<DataArrayDouble> 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<double>(trueSelf,obj,self);
}
DataArrayDouble *__pow__(PyObject *obj) throw(INTERP_KERNEL::Exception)
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)
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)
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)