return newArr;
}
-/*!
- * Apply a linear function to a given component of \a this array, so that
- * an array element <em>(x)</em> becomes \f$ a * x + b \f$.
- * \param [in] a - the first coefficient of the function.
- * \param [in] b - the second coefficient of the function.
- * \param [in] compoId - the index of component to modify.
- * \throw If \a this is not allocated, or \a compoId is not in [0,\c this->getNumberOfComponents() ).
- */
-void DataArrayDouble::applyLin(double a, double b, int compoId)
-{
- checkAllocated();
- double *ptr(getPointer()+compoId);
- int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples());
- if(compoId<0 || compoId>=nbOfComp)
- {
- std::ostringstream oss; oss << "DataArrayDouble::applyLin : The compoId requested (" << compoId << ") is not valid ! Must be in [0," << nbOfComp << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
- *ptr=a*(*ptr)+b;
- declareAsNew();
-}
-
-/*!
- * Apply a linear function to all elements of \a this array, so that
- * an element _x_ becomes \f$ a * x + b \f$.
- * \param [in] a - the first coefficient of the function.
- * \param [in] b - the second coefficient of the function.
- * \throw If \a this is not allocated.
- */
-void DataArrayDouble::applyLin(double a, double b)
-{
- checkAllocated();
- double *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- *ptr=a*(*ptr)+b;
- declareAsNew();
-}
-
/*!
* Modify all elements of \a this array, so that
* an element _x_ becomes \f$ numerator / x \f$.
declareAsNew();
}
-/*!
- * Returns a full copy of \a this array except that sign of all elements is reversed.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples and component as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- */
-DataArrayDouble *DataArrayDouble::negate() const
-{
- checkAllocated();
- DataArrayDouble *newArr=DataArrayDouble::New();
- int nbOfTuples=getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- newArr->alloc(nbOfTuples,nbOfComp);
- const double *cptr=getConstPointer();
- std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<double>());
- newArr->copyStringInfoFrom(*this);
- return newArr;
-}
-
/*!
* Modify all elements of \a this array, so that
* an element _x_ becomes <em> val ^ x </em>. Contrary to DataArrayInt::applyPow
declareAsNew();
}
-/*!
- * 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 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 ].
- *
- * 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.
- */
-DataArrayDouble *DataArrayDouble::Substract(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Substract : input DataArrayDouble instance is NULL !");
- int nbOfTuple1=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp1=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple2==nbOfTuple1)
- {
- if(nbOfComp1==nbOfComp2)
- {
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple2,nbOfComp1);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<double>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else if(nbOfComp2==1)
- {
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const double *a2Ptr=a2->getConstPointer();
- const double *a1Ptr=a1->getConstPointer();
- double *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<double>(),a2Ptr[i]));
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
- return 0;
- }
- }
- else if(nbOfTuple2==1)
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const double *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
- double *pt=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::minus<double>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
- return 0;
- }
-}
-
/*!
* Subtract values of another DataArrayDouble from values of \a this one. There are 3
* valid cases.
}
/*!
- * 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.
- */
-DataArrayDouble *DataArrayDouble::Multiply(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Multiply : 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::multiplies<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::multiplies<double>(),aMinPtr[i]));
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
- }
- }
- 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::multiplies<double>());
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
- }
- else
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
- return ret.retn();
-}
-
-/*!
- * Multiply values of another DataArrayDouble to values of \a this one. There are 3
+ * 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 other array is multiplied to the corresponding value of \a this array, i.e.
- * _this_ [ i, j ] *= _other_ [ i, j ].
+ * \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
- * _this_ [ i, j ] *= _other_ [ i, 0 ].
+ * _a_ [ 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 ].
+ * _a_ [ i, j ] /= _a2_ [ 0, j ].
*
- * \param [in] other - an array to multiply to \a this one.
+ * \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::multiplyEqual(const DataArrayDouble *other)
+void DataArrayDouble::divideEqual(const DataArrayDouble *other)
{
if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::multiplyEqual : input DataArrayDouble instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !";
+ 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();
{
if(nbOfComp==nbOfComp2)
{
- std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<double>());
+ 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::multiplies<double>(),*ptrc++));
+ std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<double>(),*ptrc++));
}
else
throw INTERP_KERNEL::Exception(msg);
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::multiplies<double>());
+ std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<double>());
}
else
throw INTERP_KERNEL::Exception(msg);
}
/*!
- * Returns a new DataArrayDouble that is a division of two given arrays. There are 3
+ * Returns a new DataArrayDouble that is the result of pow 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 ].
- * 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()).
- * \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 pow 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.
+ * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
+ * \throw If \a a1->getNumberOfComponents() != 1 or \a a2->getNumberOfComponents() != 1.
+ * \throw If there is a negative value in \a a1.
*/
-DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataArrayDouble *a2)
+DataArrayDouble *DataArrayDouble::Pow(const DataArrayDouble *a1, const DataArrayDouble *a2)
{
if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Divide : input DataArrayDouble instance is NULL !");
- int nbOfTuple1=a1->getNumberOfTuples();
+ throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : at least one of input instances is null !");
+ int nbOfTuple=a1->getNumberOfTuples();
int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp1=a1->getNumberOfComponents();
+ int nbOfComp=a1->getNumberOfComponents();
int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple2==nbOfTuple1)
+ if(nbOfTuple!=nbOfTuple2)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of tuples mismatches !");
+ if(nbOfComp!=1 || nbOfComp2!=1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of components of both arrays must be equal to 1 !");
+ MCAuto<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbOfTuple,1);
+ const double *ptr1(a1->begin()),*ptr2(a2->begin());
+ double *ptr=ret->getPointer();
+ for(int i=0;i<nbOfTuple;i++,ptr1++,ptr2++,ptr++)
{
- if(nbOfComp1==nbOfComp2)
- {
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple2,nbOfComp1);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<double>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else if(nbOfComp2==1)
+ if(*ptr1>=0)
{
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const double *a2Ptr=a2->getConstPointer();
- const double *a1Ptr=a1->getConstPointer();
- double *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<double>(),a2Ptr[i]));
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
+ *ptr=pow(*ptr1,*ptr2);
}
else
{
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
- return 0;
+ std::ostringstream oss; oss << "DataArrayDouble::Pow : on tuple #" << i << " of a1 value is < 0 (" << *ptr1 << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
- else if(nbOfTuple2==1)
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const double *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
- double *pt=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::divides<double>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
- return 0;
- }
-}
-
-/*!
- * 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.
- *
- * \param [in] a1 - an array to pow 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()
- * \throw If \a a1->getNumberOfComponents() != 1 or \a a2->getNumberOfComponents() != 1.
- * \throw If there is a negative value in \a a1.
- */
-DataArrayDouble *DataArrayDouble::Pow(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : at least one of input instances is null !");
- int nbOfTuple=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple!=nbOfTuple2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of tuples mismatches !");
- if(nbOfComp!=1 || nbOfComp2!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of components of both arrays must be equal to 1 !");
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbOfTuple,1);
- const double *ptr1(a1->begin()),*ptr2(a2->begin());
- double *ptr=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,ptr1++,ptr2++,ptr++)
- {
- if(*ptr1>=0)
- {
- *ptr=pow(*ptr1,*ptr2);
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::Pow : on tuple #" << i << " of a1 value is < 0 (" << *ptr1 << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return ret.retn();
+ return ret.retn();
}
/*!
return newArr;
}
-/*!
- * Apply a liner function to a given component of \a this array, so that
- * an array element <em>(x)</em> becomes \f$ a * x + b \f$.
- * \param [in] a - the first coefficient of the function.
- * \param [in] b - the second coefficient of the function.
- * \param [in] compoId - the index of component to modify.
- * \throw If \a this is not allocated.
- */
-void DataArrayInt::applyLin(int a, int b, int compoId)
-{
- checkAllocated();
- int *ptr=getPointer()+compoId;
- int nbOfComp=getNumberOfComponents();
- int nbOfTuple=getNumberOfTuples();
- for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
- *ptr=a*(*ptr)+b;
- declareAsNew();
-}
-
-/*!
- * Apply a liner function to all elements of \a this array, so that
- * an element _x_ becomes \f$ a * x + b \f$.
- * \param [in] a - the first coefficient of the function.
- * \param [in] b - the second coefficient of the function.
- * \throw If \a this is not allocated.
- */
-void DataArrayInt::applyLin(int a, int b)
-{
- checkAllocated();
- int *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- *ptr=a*(*ptr)+b;
- declareAsNew();
-}
-
-/*!
- * Returns a full copy of \a this array except that sign of all elements is reversed.
- * \return DataArrayInt * - the new instance of DataArrayInt containing the
- * same number of tuples and component as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- */
-DataArrayInt *DataArrayInt::negate() const
-{
- checkAllocated();
- DataArrayInt *newArr=DataArrayInt::New();
- int nbOfTuples=getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- newArr->alloc(nbOfTuples,nbOfComp);
- const int *cptr=getConstPointer();
- std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<int>());
- newArr->copyStringInfoFrom(*this);
- return newArr;
-}
-
/*!
* Modify all elements of \a this array, so that
* an element _x_ becomes \f$ numerator / x \f$.
declareAsNew();
}
-/*!
- * Returns a new DataArrayInt 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 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 ].
- *
- * 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 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::Substract(const DataArrayInt *a1, const DataArrayInt *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayInt::Substract : input DataArrayInt instance is NULL !");
- int nbOfTuple1=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp1=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple2==nbOfTuple1)
- {
- if(nbOfComp1==nbOfComp2)
- {
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuple2,nbOfComp1);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<int>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else if(nbOfComp2==1)
- {
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const int *a2Ptr=a2->getConstPointer();
- const int *a1Ptr=a1->getConstPointer();
- int *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<int>(),a2Ptr[i]));
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
- return 0;
- }
- }
- else if(nbOfTuple2==1)
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
- int *pt=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::minus<int>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
- return 0;
- }
-}
-
/*!
* Subtract values of another DataArrayInt from values of \a this one. There are 3
* valid cases.
declareAsNew();
}
-/*!
- * Returns a new DataArrayInt 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 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::Multiply(const DataArrayInt *a1, const DataArrayInt *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayInt::Multiply : 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::multiplies<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::multiplies<int>(),aMinPtr[i]));
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
- }
- }
- 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::multiplies<int>());
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
- }
- else
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
- return ret.retn();
-}
-
-
-/*!
- * Multiply 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 multiplied 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 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.
- */
-void DataArrayInt::multiplyEqual(const DataArrayInt *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayInt::multiplyEqual : input DataArrayInt instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayInt::multiplyEqual !";
- 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::multiplies<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::multiplies<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::multiplies<int>());
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
-}
-
-
-/*!
- * Returns a new DataArrayInt 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 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 ].
- * 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()).
- * \warning No check of division by zero is performed!
- * \param [in] a1 - a numerator array.
- * \param [in] a2 - a denominator array.
- * \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::Divide(const DataArrayInt *a1, const DataArrayInt *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayInt::Divide : input DataArrayInt instance is NULL !");
- int nbOfTuple1=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp1=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple2==nbOfTuple1)
- {
- if(nbOfComp1==nbOfComp2)
- {
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuple2,nbOfComp1);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<int>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else if(nbOfComp2==1)
- {
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const int *a2Ptr=a2->getConstPointer();
- const int *a1Ptr=a1->getConstPointer();
- int *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<int>(),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<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
- int *pt=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::divides<int>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
- return 0;
- }
-}
-
/*!
* Divide values of \a this array by values of another DataArrayInt. There are 3
* valid cases.
{
return convertToOtherTypeOfArr<float>();
}
+
+ /*!
+ * Apply a linear function to a given component of \a this array, so that
+ * an array element <em>(x)</em> becomes \f$ a * x + b \f$.
+ * \param [in] a - the first coefficient of the function.
+ * \param [in] b - the second coefficient of the function.
+ * \param [in] compoId - the index of component to modify.
+ * \throw If \a this is not allocated, or \a compoId is not in [0,\c this->getNumberOfComponents() ).
+ */
+ template<class T>
+ void DataArrayTemplateClassic<T>::applyLin(T a, T b, int compoId)
+ {
+ this->checkAllocated();
+ T *ptr(this->getPointer()+compoId);
+ int nbOfComp(this->getNumberOfComponents()),nbOfTuple(this->getNumberOfTuples());
+ if(compoId<0 || compoId>=nbOfComp)
+ {
+ std::ostringstream oss; oss << "DataArrayDouble::applyLin : The compoId requested (" << compoId << ") is not valid ! Must be in [0," << nbOfComp << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
+ *ptr=a*(*ptr)+b;
+ this->declareAsNew();
+ }
+
+ /*!
+ * Apply a linear function to all elements of \a this array, so that
+ * an element _x_ becomes \f$ a * x + b \f$.
+ * \param [in] a - the first coefficient of the function.
+ * \param [in] b - the second coefficient of the function.
+ * \throw If \a this is not allocated.
+ */
+ template<class T>
+ void DataArrayTemplateClassic<T>::applyLin(T a, T b)
+ {
+ this->checkAllocated();
+ T *ptr(this->getPointer());
+ std::size_t nbOfElems(this->getNbOfElems());
+ for(std::size_t i=0;i<nbOfElems;i++,ptr++)
+ *ptr=a*(*ptr)+b;
+ this->declareAsNew();
+ }
+
+ /*!
+ * Returns a full copy of \a this array except that sign of all elements is reversed.
+ * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
+ * same number of tuples and component as \a this array.
+ * The caller is to delete this result array using decrRef() as it is no more
+ * needed.
+ * \throw If \a this is not allocated.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::negate() const
+ {
+ this->checkAllocated();
+ MCAuto<typename Traits<T>::ArrayType> newArr(Traits<T>::ArrayType::New());
+ int nbOfTuples(this->getNumberOfTuples()),nbOfComp(this->getNumberOfComponents());
+ newArr->alloc(nbOfTuples,nbOfComp);
+ const T *cptr(this->begin());
+ std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<T>());
+ newArr->copyStringInfoFrom(*this);
+ 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)
+ {
+ if(!other)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::multiplyEqual : input DataArrayDouble instance is NULL !");
+ const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !";
+ this->checkAllocated();
+ other->checkAllocated();
+ int nbOfTuple(this->getNumberOfTuples()),nbOfTuple2(other->getNumberOfTuples());
+ int nbOfComp(this->getNumberOfComponents()),nbOfComp2(other->getNumberOfComponents());
+ if(nbOfTuple==nbOfTuple2)
+ {
+ if(nbOfComp==nbOfComp2)
+ {
+ std::transform(this->begin(),this->end(),other->begin(),this->getPointer(),std::multiplies<T>());
+ }
+ 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++));
+ }
+ else
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ else if(nbOfTuple2==1)
+ {
+ if(nbOfComp2==nbOfComp)
+ {
+ 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>());
+ }
+ else
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ else
+ throw INTERP_KERNEL::Exception(msg);
+ this->declareAsNew();
+ }
+
+ /*!
+ * 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 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 ].
+ *
+ * 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.
+ */
+ template<class T>
+ 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::Substract : 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::minus<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());
+ const T *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]));
+ ret->copyStringInfoFrom(*a1);
+ return ret.retn();
+ }
+ else
+ {
+ a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
+ return 0;
+ }
+ }
+ else if(nbOfTuple2==1)
+ {
+ a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
+ 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::minus<T>());
+ ret->copyStringInfoFrom(*a1);
+ return ret.retn();
+ }
+ else
+ {
+ a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
+ return 0;
+ }
+ }
+
+ /*!
+ * 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 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 ].
+ * 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()).
+ * \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.
+ * \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>::Divide(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;
+ }
+ }
+
+ /*!
+ * 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)
+ {
+ if(!a1 || !a2)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::Multiply : 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;
+ if(nbOfTuple==nbOfTuple2)
+ {
+ if(nbOfComp==nbOfComp2)
+ {
+ ret=Traits<T>::ArrayType::New();
+ ret->alloc(nbOfTuple,nbOfComp);
+ std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<T>());
+ ret->copyStringInfoFrom(*a1);
+ }
+ else
+ {
+ int nbOfCompMin,nbOfCompMax;
+ const typename Traits<T>::ArrayType *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=Traits<T>::ArrayType::New();
+ ret->alloc(nbOfTuple,nbOfCompMax);
+ const T *aMinPtr(aMin->begin());
+ 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]));
+ ret->copyStringInfoFrom(*aMax);
+ }
+ else
+ throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
+ }
+ }
+ else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
+ {
+ if(nbOfComp==nbOfComp2)
+ {
+ int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
+ const typename Traits<T>::ArrayType *aMin(nbOfTuple>nbOfTuple2?a2:a1);
+ const typename Traits<T>::ArrayType *aMax(nbOfTuple>nbOfTuple2?a1:a2);
+ const T *aMinPtr(aMin->begin()),*aMaxPtr(aMax->begin());
+ ret=Traits<T>::ArrayType::New();
+ 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>());
+ ret->copyStringInfoFrom(*aMax);
+ }
+ else
+ throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
+ }
+ else
+ throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
+ return ret.retn();
+ }
/*!
* Returns either a \a deep or \a shallow copy of this array. For more info see