- * Converts each 2D point defined by the tuple of \a this array from the Polar to the
- * Cartesian coordinate system. The two components of the tuple of \a this array are
- * considered to contain (1) radius and (2) angle of the point in the Polar CS.
- * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
- * contains X and Y coordinates of the point in the Cartesian CS. The caller
- * is to delete this array using decrRef() as it is no more needed. The array
- * does not contain any textual info on components.
- * \throw If \a this->getNumberOfComponents() != 2.
- */
-DataArrayDouble *DataArrayDouble::fromPolarToCart() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::fromPolarToCart : must be an array with exactly 2 components !");
- int nbOfTuple=getNumberOfTuples();
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,2);
- double *w=ret->getPointer();
- const double *wIn=getConstPointer();
- for(int i=0;i<nbOfTuple;i++,w+=2,wIn+=2)
- {
- w[0]=wIn[0]*cos(wIn[1]);
- w[1]=wIn[0]*sin(wIn[1]);
- }
- return ret;
-}
-
-/*!
- * Converts each 3D point defined by the tuple of \a this array from the Cylindrical to
- * the Cartesian coordinate system. The three components of the tuple of \a this array
- * are considered to contain (1) radius, (2) azimuth and (3) altitude of the point in
- * the Cylindrical CS.
- * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
- * contains X, Y and Z coordinates of the point in the Cartesian CS. The info
- * on the third component is copied from \a this array. The caller
- * is to delete this array using decrRef() as it is no more needed.
- * \throw If \a this->getNumberOfComponents() != 3.
- */
-DataArrayDouble *DataArrayDouble::fromCylToCart() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=3)
- throw INTERP_KERNEL::Exception("DataArrayDouble::fromCylToCart : must be an array with exactly 3 components !");
- int nbOfTuple=getNumberOfTuples();
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(getNumberOfTuples(),3);
- double *w=ret->getPointer();
- const double *wIn=getConstPointer();
- for(int i=0;i<nbOfTuple;i++,w+=3,wIn+=3)
- {
- w[0]=wIn[0]*cos(wIn[1]);
- w[1]=wIn[0]*sin(wIn[1]);
- w[2]=wIn[2];
- }
- ret->setInfoOnComponent(2,getInfoOnComponent(2));
- return ret;
-}
-
-/*!
- * Converts each 3D point defined by the tuple of \a this array from the Spherical to
- * the Cartesian coordinate system. The three components of the tuple of \a this array
- * are considered to contain (1) radius, (2) polar angle and (3) azimuthal angle of the
- * point in the Cylindrical CS.
- * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
- * contains X, Y and Z coordinates of the point in the Cartesian CS. The info
- * on the third component is copied from \a this array. The caller
- * is to delete this array using decrRef() as it is no more needed.
- * \throw If \a this->getNumberOfComponents() != 3.
- */
-DataArrayDouble *DataArrayDouble::fromSpherToCart() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=3)
- throw INTERP_KERNEL::Exception("DataArrayDouble::fromSpherToCart : must be an array with exactly 3 components !");
- int nbOfTuple=getNumberOfTuples();
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(getNumberOfTuples(),3);
- double *w=ret->getPointer();
- const double *wIn=getConstPointer();
- for(int i=0;i<nbOfTuple;i++,w+=3,wIn+=3)
- {
- w[0]=wIn[0]*cos(wIn[2])*sin(wIn[1]);
- w[1]=wIn[0]*sin(wIn[2])*sin(wIn[1]);
- w[2]=wIn[0]*cos(wIn[1]);
- }
- return ret;
-}
-
-/*!
- * Computes the doubly contracted product of every tensor defined by the tuple of \a this
- * array contating 6 components.
- * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
- * is calculated from the tuple <em>(t)</em> of \a this array as follows:
- * \f$ t[0]^2+t[1]^2+t[2]^2+2*t[3]^2+2*t[4]^2+2*t[5]^2\f$.
- * The caller is to delete this result array using decrRef() as it is no more needed.
- * \throw If \a this->getNumberOfComponents() != 6.
- */
-DataArrayDouble *DataArrayDouble::doublyContractedProduct() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=6)
- throw INTERP_KERNEL::Exception("DataArrayDouble::doublyContractedProduct : must be an array with exactly 6 components !");
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,1);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
- *dest=src[0]*src[0]+src[1]*src[1]+src[2]*src[2]+2.*src[3]*src[3]+2.*src[4]*src[4]+2.*src[5]*src[5];
- return ret;
-}
-
-/*!
- * Computes the determinant of every square matrix defined by the tuple of \a this
- * array, which contains either 4, 6 or 9 components. The case of 6 components
- * corresponds to that of the upper triangular matrix.
- * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
- * is the determinant of matrix of the corresponding tuple of \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
- */
-DataArrayDouble *DataArrayDouble::determinant() const
-{
- checkAllocated();
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,1);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- switch(getNumberOfComponents())
- {
- case 6:
- for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
- *dest=src[0]*src[1]*src[2]+2.*src[4]*src[5]*src[3]-src[0]*src[4]*src[4]-src[2]*src[3]*src[3]-src[1]*src[5]*src[5];
- return ret;
- case 4:
- for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
- *dest=src[0]*src[3]-src[1]*src[2];
- return ret;
- case 9:
- for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
- *dest=src[0]*src[4]*src[8]+src[1]*src[5]*src[6]+src[2]*src[3]*src[7]-src[0]*src[5]*src[7]-src[1]*src[3]*src[8]-src[2]*src[4]*src[6];
- return ret;
- default:
- ret->decrRef();
- throw INTERP_KERNEL::Exception("DataArrayDouble::determinant : Invalid number of components ! must be in 4,6,9 !");
- }
-}
-
-/*!
- * Computes 3 eigenvalues of every upper triangular matrix defined by the tuple of
- * \a this array, which contains 6 components.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing 3
- * components, whose each tuple contains the eigenvalues of the matrix of
- * corresponding tuple of \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() != 6.
- */
-DataArrayDouble *DataArrayDouble::eigenValues() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=6)
- throw INTERP_KERNEL::Exception("DataArrayDouble::eigenValues : must be an array with exactly 6 components !");
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,3);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,dest+=3,src+=6)
- INTERP_KERNEL::computeEigenValues6(src,dest);
- return ret;
-}
-
-/*!
- * Computes 3 eigenvectors of every upper triangular matrix defined by the tuple of
- * \a this array, which contains 6 components.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing 9
- * components, whose each tuple contains 3 eigenvectors of the matrix of
- * corresponding tuple of \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() != 6.
- */
-DataArrayDouble *DataArrayDouble::eigenVectors() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=6)
- throw INTERP_KERNEL::Exception("DataArrayDouble::eigenVectors : must be an array with exactly 6 components !");
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,9);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,src+=6)
- {
- double tmp[3];
- INTERP_KERNEL::computeEigenValues6(src,tmp);
- for(int j=0;j<3;j++,dest+=3)
- INTERP_KERNEL::computeEigenVectorForEigenValue6(src,tmp[j],1e-12,dest);
- }
- return ret;
-}
-
-/*!
- * Computes the inverse matrix of every matrix defined by the tuple of \a this
- * array, which contains either 4, 6 or 9 components. The case of 6 components
- * corresponds to that of the upper triangular matrix.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of components as \a this one, whose each tuple is the inverse
- * matrix of the matrix of corresponding tuple of \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
- */
-DataArrayDouble *DataArrayDouble::inverse() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=6 && nbOfComp!=9 && nbOfComp!=4)
- throw INTERP_KERNEL::Exception("DataArrayDouble::inversion : must be an array with 4,6 or 9 components !");
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,nbOfComp);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- if(nbOfComp==6)
- for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
- {
- double det=src[0]*src[1]*src[2]+2.*src[4]*src[5]*src[3]-src[0]*src[4]*src[4]-src[2]*src[3]*src[3]-src[1]*src[5]*src[5];
- dest[0]=(src[1]*src[2]-src[4]*src[4])/det;
- dest[1]=(src[0]*src[2]-src[5]*src[5])/det;
- dest[2]=(src[0]*src[1]-src[3]*src[3])/det;
- dest[3]=(src[5]*src[4]-src[3]*src[2])/det;
- dest[4]=(src[5]*src[3]-src[0]*src[4])/det;
- dest[5]=(src[3]*src[4]-src[1]*src[5])/det;
- }
- else if(nbOfComp==4)
- for(int i=0;i<nbOfTuple;i++,dest+=4,src+=4)
- {
- double det=src[0]*src[3]-src[1]*src[2];
- dest[0]=src[3]/det;
- dest[1]=-src[1]/det;
- dest[2]=-src[2]/det;
- dest[3]=src[0]/det;
- }
- else
- for(int i=0;i<nbOfTuple;i++,dest+=9,src+=9)
- {
- double det=src[0]*src[4]*src[8]+src[1]*src[5]*src[6]+src[2]*src[3]*src[7]-src[0]*src[5]*src[7]-src[1]*src[3]*src[8]-src[2]*src[4]*src[6];
- dest[0]=(src[4]*src[8]-src[7]*src[5])/det;
- dest[1]=(src[7]*src[2]-src[1]*src[8])/det;
- dest[2]=(src[1]*src[5]-src[4]*src[2])/det;
- dest[3]=(src[6]*src[5]-src[3]*src[8])/det;
- dest[4]=(src[0]*src[8]-src[6]*src[2])/det;
- dest[5]=(src[2]*src[3]-src[0]*src[5])/det;
- dest[6]=(src[3]*src[7]-src[6]*src[4])/det;
- dest[7]=(src[6]*src[1]-src[0]*src[7])/det;
- dest[8]=(src[0]*src[4]-src[1]*src[3])/det;
- }
- return ret;
-}
-
-/*!
- * Computes the trace of every matrix defined by the tuple of \a this
- * array, which contains either 4, 6 or 9 components. The case of 6 components
- * corresponds to that of the upper triangular matrix.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing
- * 1 component, whose each tuple is the trace of
- * the matrix of corresponding tuple of \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
- */
-DataArrayDouble *DataArrayDouble::trace() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=6 && nbOfComp!=9 && nbOfComp!=4)
- throw INTERP_KERNEL::Exception("DataArrayDouble::trace : must be an array with 4,6 or 9 components !");
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,1);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- if(nbOfComp==6)
- for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
- *dest=src[0]+src[1]+src[2];
- else if(nbOfComp==4)
- for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
- *dest=src[0]+src[3];
- else
- for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
- *dest=src[0]+src[4]+src[8];
- return ret;
-}
-
-/*!
- * Computes the stress deviator tensor of every stress tensor defined by the tuple of
- * \a this array, which contains 6 components.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of components and tuples as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() != 6.
- */
-DataArrayDouble *DataArrayDouble::deviator() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=6)
- throw INTERP_KERNEL::Exception("DataArrayDouble::deviator : must be an array with exactly 6 components !");
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,6);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
- {
- double tr=(src[0]+src[1]+src[2])/3.;
- dest[0]=src[0]-tr;
- dest[1]=src[1]-tr;
- dest[2]=src[2]-tr;
- dest[3]=src[3];
- dest[4]=src[4];
- dest[5]=src[5];
- }
- return ret;
-}
-
-/*!
- * Computes the magnitude of every vector defined by the tuple of
- * \a this array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array and one component.
- * 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::magnitude() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,1);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,dest++)
- {
- double sum=0.;
- for(int j=0;j<nbOfComp;j++,src++)
- sum+=(*src)*(*src);
- *dest=sqrt(sum);
- }
- return ret;
-}
-
-/*!
- * Computes for each tuple the sum of number of components values in the tuple and return it.
- *
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array and one component.
- * 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::sumPerTuple() const
-{
- checkAllocated();
- int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples());
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New());
- ret->alloc(nbOfTuple,1);
- const double *src(getConstPointer());
- double *dest(ret->getPointer());
- for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
- *dest=std::accumulate(src,src+nbOfComp,0.);
- return ret.retn();
-}
-
-/*!
- * Computes the maximal value within every tuple of \a this array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array and one component.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \sa DataArrayDouble::maxPerTupleWithCompoId
- */
-DataArrayDouble *DataArrayDouble::maxPerTuple() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,1);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
- *dest=*std::max_element(src,src+nbOfComp);
- return ret.retn();
-}
-
-/*!
- * Computes the maximal value within every tuple of \a this array and it returns the first component
- * id for each tuple that corresponds to the maximal value within the tuple.
- *
- * \param [out] compoIdOfMaxPerTuple - the new new instance of DataArrayInt containing the
- * same number of tuples and only one component.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array and one component.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \sa DataArrayDouble::maxPerTuple
- */
-DataArrayDouble *DataArrayDouble::maxPerTupleWithCompoId(DataArrayInt* &compoIdOfMaxPerTuple) const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret0=DataArrayDouble::New();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=DataArrayInt::New();
- int nbOfTuple=getNumberOfTuples();
- ret0->alloc(nbOfTuple,1); ret1->alloc(nbOfTuple,1);
- const double *src=getConstPointer();
- double *dest=ret0->getPointer(); int *dest1=ret1->getPointer();
- for(int i=0;i<nbOfTuple;i++,dest++,dest1++,src+=nbOfComp)
- {
- const double *loc=std::max_element(src,src+nbOfComp);
- *dest=*loc;
- *dest1=(int)std::distance(src,loc);
- }
- compoIdOfMaxPerTuple=ret1.retn();
- return ret0.retn();
-}
-
-/*!
- * This method returns a newly allocated DataArrayDouble instance having one component and \c this->getNumberOfTuples() * \c this->getNumberOfTuples() tuples.
- * \n This returned array contains the euclidian distance for each tuple in \a this.
- * \n So the returned array can be seen as a dense symmetrical matrix whose diagonal elements are equal to 0.
- * \n The returned array has only one component (and **not** \c this->getNumberOfTuples() components to avoid the useless memory consumption due to components info in returned DataArrayDouble)
- *
- * \warning use this method with care because it can leads to big amount of consumed memory !
- *
- * \return A newly allocated (huge) ParaMEDMEM::DataArrayDouble instance that the caller should deal with.
- *
- * \throw If \a this is not allocated.
- *
- * \sa DataArrayDouble::buildEuclidianDistanceDenseMatrixWith
- */
-DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrix() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- const double *inData=getConstPointer();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuples*nbOfTuples,1);
- double *outData=ret->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- outData[i*nbOfTuples+i]=0.;
- for(int j=i+1;j<nbOfTuples;j++)
- {
- double dist=0.;
- for(int k=0;k<nbOfComp;k++)
- { double delta=inData[i*nbOfComp+k]-inData[j*nbOfComp+k]; dist+=delta*delta; }
- dist=sqrt(dist);
- outData[i*nbOfTuples+j]=dist;
- outData[j*nbOfTuples+i]=dist;
- }
- }
- return ret.retn();
-}
-
-/*!
- * This method returns a newly allocated DataArrayDouble instance having one component and \c this->getNumberOfTuples() * \c other->getNumberOfTuples() tuples.
- * \n This returned array contains the euclidian distance for each tuple in \a other with each tuple in \a this.
- * \n So the returned array can be seen as a dense rectangular matrix with \c other->getNumberOfTuples() rows and \c this->getNumberOfTuples() columns.
- * \n Output rectangular matrix is sorted along rows.
- * \n The returned array has only one component (and **not** \c this->getNumberOfTuples() components to avoid the useless memory consumption due to components info in returned DataArrayDouble)
- *
- * \warning use this method with care because it can leads to big amount of consumed memory !
- *
- * \param [in] other DataArrayDouble instance having same number of components than \a this.
- * \return A newly allocated (huge) ParaMEDMEM::DataArrayDouble instance that the caller should deal with.
- *
- * \throw If \a this is not allocated, or if \a other is null or if \a other is not allocated, or if number of components of \a other and \a this differs.
- *
- * \sa DataArrayDouble::buildEuclidianDistanceDenseMatrix
- */
-DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::buildEuclidianDistanceDenseMatrixWith : input parameter is null !");
- checkAllocated();
- other->checkAllocated();
- int nbOfComp=getNumberOfComponents();
- int otherNbOfComp=other->getNumberOfComponents();
- if(nbOfComp!=otherNbOfComp)
- {
- std::ostringstream oss; oss << "DataArrayDouble::buildEuclidianDistanceDenseMatrixWith : this nb of compo=" << nbOfComp << " and other nb of compo=" << otherNbOfComp << ". It should match !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- int nbOfTuples=getNumberOfTuples();
- int otherNbOfTuples=other->getNumberOfTuples();
- const double *inData=getConstPointer();
- const double *inDataOther=other->getConstPointer();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(otherNbOfTuples*nbOfTuples,1);
- double *outData=ret->getPointer();
- for(int i=0;i<otherNbOfTuples;i++,inDataOther+=nbOfComp)
- {
- for(int j=0;j<nbOfTuples;j++)
- {
- double dist=0.;
- for(int k=0;k<nbOfComp;k++)
- { double delta=inDataOther[k]-inData[j*nbOfComp+k]; dist+=delta*delta; }
- dist=sqrt(dist);
- outData[i*nbOfTuples+j]=dist;
- }
- }
- return ret.retn();
-}
-
-/*!
- * Sorts value within every tuple of \a this array.
- * \param [in] asc - if \a true, the values are sorted in ascending order, else,
- * in descending order.
- * \throw If \a this is not allocated.
- */
-void DataArrayDouble::sortPerTuple(bool asc)
-{
- checkAllocated();
- double *pt=getPointer();
- int nbOfTuple=getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- if(asc)
- for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
- std::sort(pt,pt+nbOfComp);
- else
- for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
- std::sort(pt,pt+nbOfComp,std::greater<double>());
- declareAsNew();
-}
-
-/*!
- * Converts every value of \a this array to its absolute value.
- * \b WARNING this method is non const. If a new DataArrayDouble instance should be built containing the result of abs DataArrayDouble::computeAbs
- * should be called instead.
- *
- * \throw If \a this is not allocated.
- * \sa DataArrayDouble::computeAbs
- */
-void DataArrayDouble::abs()
-{
- checkAllocated();
- double *ptr(getPointer());
- std::size_t nbOfElems(getNbOfElems());
- std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<double,double>(fabs));
- declareAsNew();
-}
-
-/*!
- * This method builds a new instance of \a this object containing the result of std::abs applied of all elements in \a this.
- * This method is a const method (that do not change any values in \a this) contrary to DataArrayDouble::abs method.
- *
- * \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.
- * \sa DataArrayDouble::abs
- */
-DataArrayDouble *DataArrayDouble::computeAbs() const
-{
- checkAllocated();
- DataArrayDouble *newArr(DataArrayDouble::New());
- int nbOfTuples(getNumberOfTuples());
- int nbOfComp(getNumberOfComponents());
- newArr->alloc(nbOfTuples,nbOfComp);
- std::transform(begin(),end(),newArr->getPointer(),std::ptr_fun<double,double>(fabs));
- newArr->copyStringInfoFrom(*this);
- 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$.
- * \warning If an exception is thrown because of presence of 0.0 element in \a this
- * array, all elements processed before detection of the zero element remain
- * modified.
- * \param [in] numerator - the numerator used to modify array elements.
- * \throw If \a this is not allocated.
- * \throw If there is an element equal to 0.0 in \a this array.
- */
-void DataArrayDouble::applyInv(double numerator)
-{
- checkAllocated();
- double *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- {
- if(std::abs(*ptr)>std::numeric_limits<double>::min())
- {
- *ptr=numerator/(*ptr);
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
- oss << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- 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
- * all values in \a this have to be >= 0 if val is \b not integer.
- * \param [in] val - the value used to apply pow on all array elements.
- * \throw If \a this is not allocated.
- * \warning If an exception is thrown because of presence of 0 element in \a this
- * array and \a val is \b not integer, all elements processed before detection of the zero element remain
- * modified.
- */
-void DataArrayDouble::applyPow(double val)
-{
- checkAllocated();
- double *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- int val2=(int)val;
- bool isInt=((double)val2)==val;
- if(!isInt)
- {
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- {
- if(*ptr>=0)
- *ptr=pow(*ptr,val);
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::applyPow (double) : At elem # " << i << " value is " << *ptr << " ! must be >=0. !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- }
- else
- {
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- *ptr=pow(*ptr,val2);
- }
- declareAsNew();
-}
-
-/*!
- * Modify all elements of \a this array, so that
- * an element _x_ becomes \f$ val ^ x \f$.
- * \param [in] val - the value used to apply pow on all array elements.
- * \throw If \a this is not allocated.
- * \throw If \a val < 0.
- * \warning If an exception is thrown because of presence of 0 element in \a this
- * array, all elements processed before detection of the zero element remain
- * modified.
- */
-void DataArrayDouble::applyRPow(double val)
-{
- checkAllocated();
- if(val<0.)
- throw INTERP_KERNEL::Exception("DataArrayDouble::applyRPow : the input value has to be >= 0 !");
- double *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- *ptr=pow(val,*ptr);
- declareAsNew();
-}
-
-/*!
- * Returns a new DataArrayDouble created from \a this one by applying \a
- * FunctionToEvaluate to every tuple of \a this array. Textual data is not copied.
- * For more info see \ref MEDCouplingArrayApplyFunc
- * \param [in] nbOfComp - number of components in the result array.
- * \param [in] func - the \a FunctionToEvaluate declared as
- * \c bool (*\a func)(\c const \c double *\a pos, \c double *\a res),
- * where \a pos points to the first component of a tuple of \a this array
- * and \a res points to the first component of a tuple of the result array.
- * Note that length (number of components) of \a pos can differ from
- * that of \a res.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples 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.
- * \throw If \a func returns \a false.
- */
-DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, FunctionToEvaluate func) const
-{
- checkAllocated();
- DataArrayDouble *newArr=DataArrayDouble::New();
- int nbOfTuples=getNumberOfTuples();
- int oldNbOfComp=getNumberOfComponents();
- newArr->alloc(nbOfTuples,nbOfComp);
- const double *ptr=getConstPointer();
- double *ptrToFill=newArr->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- if(!func(ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp))
- {
- std::ostringstream oss; oss << "For tuple # " << i << " with value (";
- std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
- oss << ") : Evaluation of function failed !";
- newArr->decrRef();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return newArr;
-}
-
-/*!
- * Returns a new DataArrayDouble created from \a this one by applying a function to every
- * tuple of \a this array. Textual data is not copied.
- * For more info see \ref MEDCouplingArrayApplyFunc1.
- * \param [in] nbOfComp - number of components in the result array.
- * \param [in] func - the expression defining how to transform a tuple of \a this array.
- * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
- * \param [in] isSafe - By default true. If true invalid operation (division by 0. acos of value > 1. ...) leads to a throw of an exception.
- * If false the computation is carried on without any notification. When false the evaluation is a little faster.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array and \a nbOfComp components.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \throw If computing \a func fails.
- */
-DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const std::string& func, bool isSafe) const
-{
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- std::set<std::string> vars;
- expr.getTrueSetOfVars(vars);
- std::vector<std::string> varsV(vars.begin(),vars.end());
- return applyFunc3(nbOfComp,varsV,func,isSafe);
-}
-
-/*!
- * Returns a new DataArrayDouble created from \a this one by applying a function to every
- * tuple of \a this array. Textual data is not copied. This method works by tuples (whatever its size).
- * If \a this is a one component array, call applyFuncOnThis instead that performs the same work faster.
- *
- * For more info see \ref MEDCouplingArrayApplyFunc0.
- * \param [in] func - the expression defining how to transform a tuple of \a this array.
- * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
- * \param [in] isSafe - By default true. If true invalid operation (division by 0. acos of value > 1. ...) leads to a throw of an exception.
- * If false the computation is carried on without any notification. When false the evaluation is a little faster.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples and components as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \sa applyFuncOnThis
- * \throw If \a this is not allocated.
- * \throw If computing \a func fails.
- */
-DataArrayDouble *DataArrayDouble::applyFunc(const std::string& func, bool isSafe) const
-{
- int nbOfComp(getNumberOfComponents());
- if(nbOfComp<=0)
- throw INTERP_KERNEL::Exception("DataArrayDouble::applyFunc : output number of component must be > 0 !");
- checkAllocated();
- int nbOfTuples(getNumberOfTuples());
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> newArr(DataArrayDouble::New());
- newArr->alloc(nbOfTuples,nbOfComp);
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- std::set<std::string> vars;
- expr.getTrueSetOfVars(vars);
- if((int)vars.size()>1)
- {
- std::ostringstream oss; oss << "DataArrayDouble::applyFunc : this method works only with at most one var func expression ! If you need to map comps on variables please use applyFunc2 or applyFunc3 instead ! Vars in expr are : ";
- std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- if(vars.empty())
- {
- expr.prepareFastEvaluator();
- newArr->rearrange(1);
- newArr->fillWithValue(expr.evaluateDouble());
- newArr->rearrange(nbOfComp);
- return newArr.retn();
- }
- std::vector<std::string> vars2(vars.begin(),vars.end());
- double buff,*ptrToFill(newArr->getPointer());
- const double *ptr(begin());
- std::vector<double> stck;
- expr.prepareExprEvaluationDouble(vars2,1,1,0,&buff,&buff+1);
- expr.prepareFastEvaluator();
- if(!isSafe)
- {
- for(int i=0;i<nbOfTuples;i++)
- {
- for(int iComp=0;iComp<nbOfComp;iComp++,ptr++,ptrToFill++)
- {
- buff=*ptr;
- expr.evaluateDoubleInternal(stck);
- *ptrToFill=stck.back();
- stck.pop_back();
- }
- }
- }
- else
- {
- for(int i=0;i<nbOfTuples;i++)
- {
- for(int iComp=0;iComp<nbOfComp;iComp++,ptr++,ptrToFill++)
- {
- buff=*ptr;
- try
- {
- expr.evaluateDoubleInternalSafe(stck);
- }
- catch(INTERP_KERNEL::Exception& e)
- {
- std::ostringstream oss; oss << "For tuple # " << i << " component # " << iComp << " with value (";
- oss << buff;
- oss << ") : Evaluation of function failed !" << e.what();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- *ptrToFill=stck.back();
- stck.pop_back();
- }
- }
- }
- return newArr.retn();
-}
-
-/*!
- * This method is a non const method that modify the array in \a this.
- * This method only works on one component array. It means that function \a func must
- * contain at most one variable.
- * This method is a specialization of applyFunc method with one parameter on one component array.
- *
- * \param [in] func - the expression defining how to transform a tuple of \a this array.
- * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
- * \param [in] isSafe - By default true. If true invalid operation (division by 0. acos of value > 1. ...) leads to a throw of an exception.
- * If false the computation is carried on without any notification. When false the evaluation is a little faster.
- *
- * \sa applyFunc
- */
-void DataArrayDouble::applyFuncOnThis(const std::string& func, bool isSafe)
-{
- int nbOfComp(getNumberOfComponents());
- if(nbOfComp<=0)
- throw INTERP_KERNEL::Exception("DataArrayDouble::applyFuncOnThis : output number of component must be > 0 !");
- checkAllocated();
- int nbOfTuples(getNumberOfTuples());
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- std::set<std::string> vars;
- expr.getTrueSetOfVars(vars);
- if((int)vars.size()>1)
- {
- std::ostringstream oss; oss << "DataArrayDouble::applyFuncOnThis : this method works only with at most one var func expression ! If you need to map comps on variables please use applyFunc2 or applyFunc3 instead ! Vars in expr are : ";
- std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- if(vars.empty())
- {
- expr.prepareFastEvaluator();
- std::vector<std::string> compInfo(getInfoOnComponents());
- rearrange(1);
- fillWithValue(expr.evaluateDouble());
- rearrange(nbOfComp);
- setInfoOnComponents(compInfo);
- return ;
- }
- std::vector<std::string> vars2(vars.begin(),vars.end());
- double buff,*ptrToFill(getPointer());
- const double *ptr(begin());
- std::vector<double> stck;
- expr.prepareExprEvaluationDouble(vars2,1,1,0,&buff,&buff+1);
- expr.prepareFastEvaluator();
- if(!isSafe)
- {
- for(int i=0;i<nbOfTuples;i++)
- {
- for(int iComp=0;iComp<nbOfComp;iComp++,ptr++,ptrToFill++)
- {
- buff=*ptr;
- expr.evaluateDoubleInternal(stck);
- *ptrToFill=stck.back();
- stck.pop_back();
- }
- }
- }
- else
- {
- for(int i=0;i<nbOfTuples;i++)
- {
- for(int iComp=0;iComp<nbOfComp;iComp++,ptr++,ptrToFill++)
- {
- buff=*ptr;
- try
- {
- expr.evaluateDoubleInternalSafe(stck);
- }
- catch(INTERP_KERNEL::Exception& e)
- {
- std::ostringstream oss; oss << "For tuple # " << i << " component # " << iComp << " with value (";
- oss << buff;
- oss << ") : Evaluation of function failed !" << e.what();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- *ptrToFill=stck.back();
- stck.pop_back();
- }
- }
- }
-}
-
-/*!
- * Returns a new DataArrayDouble created from \a this one by applying a function to every
- * tuple of \a this array. Textual data is not copied.
- * For more info see \ref MEDCouplingArrayApplyFunc2.
- * \param [in] nbOfComp - number of components in the result array.
- * \param [in] func - the expression defining how to transform a tuple of \a this array.
- * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
- * \param [in] isSafe - By default true. If true invalid operation (division by 0. acos of value > 1. ...) leads to a throw of an exception.
- * If false the computation is carried on without any notification. When false the evaluation is a little faster.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples 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.
- * \throw If \a func contains vars that are not in \a this->getInfoOnComponent().
- * \throw If computing \a func fails.
- */
-DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const std::string& func, bool isSafe) const
-{
- return applyFunc3(nbOfComp,getVarsOnComponent(),func,isSafe);
-}
-
-/*!
- * Returns a new DataArrayDouble created from \a this one by applying a function to every
- * tuple of \a this array. Textual data is not copied.
- * For more info see \ref MEDCouplingArrayApplyFunc3.
- * \param [in] nbOfComp - number of components in the result array.
- * \param [in] varsOrder - sequence of vars defining their order.
- * \param [in] func - the expression defining how to transform a tuple of \a this array.
- * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
- * \param [in] isSafe - By default true. If true invalid operation (division by 0. acos of value > 1. ...) leads to a throw of an exception.
- * If false the computation is carried on without any notification. When false the evaluation is a little faster.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples 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.
- * \throw If \a func contains vars not in \a varsOrder.
- * \throw If computing \a func fails.
- */
-DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func, bool isSafe) const
-{
- if(nbOfComp<=0)
- throw INTERP_KERNEL::Exception("DataArrayDouble::applyFunc3 : output number of component must be > 0 !");
- std::vector<std::string> varsOrder2(varsOrder);
- int oldNbOfComp(getNumberOfComponents());
- for(int i=(int)varsOrder.size();i<oldNbOfComp;i++)
- varsOrder2.push_back(std::string());
- checkAllocated();
- int nbOfTuples(getNumberOfTuples());
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- std::set<std::string> vars;
- expr.getTrueSetOfVars(vars);
- if((int)vars.size()>oldNbOfComp)
- {
- std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
- oss << vars.size() << " variables : ";
- std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> newArr(DataArrayDouble::New());
- newArr->alloc(nbOfTuples,nbOfComp);
- INTERP_KERNEL::AutoPtr<double> buff(new double[oldNbOfComp]);
- double *buffPtr(buff),*ptrToFill;
- std::vector<double> stck;
- for(int iComp=0;iComp<nbOfComp;iComp++)
- {
- expr.prepareExprEvaluationDouble(varsOrder2,oldNbOfComp,nbOfComp,iComp,buffPtr,buffPtr+oldNbOfComp);
- expr.prepareFastEvaluator();
- const double *ptr(getConstPointer());
- ptrToFill=newArr->getPointer()+iComp;
- if(!isSafe)
- {
- for(int i=0;i<nbOfTuples;i++,ptrToFill+=nbOfComp,ptr+=oldNbOfComp)
- {
- std::copy(ptr,ptr+oldNbOfComp,buffPtr);
- expr.evaluateDoubleInternal(stck);
- *ptrToFill=stck.back();
- stck.pop_back();
- }
- }
- else
- {
- for(int i=0;i<nbOfTuples;i++,ptrToFill+=nbOfComp,ptr+=oldNbOfComp)
- {
- std::copy(ptr,ptr+oldNbOfComp,buffPtr);
- try
- {
- expr.evaluateDoubleInternalSafe(stck);
- *ptrToFill=stck.back();
- stck.pop_back();
- }
- catch(INTERP_KERNEL::Exception& e)
- {
- std::ostringstream oss; oss << "For tuple # " << i << " with value (";
- std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
- oss << ") : Evaluation of function failed !" << e.what();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- }
- }
- return newArr.retn();
-}
-
-void DataArrayDouble::applyFuncFast32(const std::string& func)
-{
- checkAllocated();
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- char *funcStr=expr.compileX86();
- MYFUNCPTR funcPtr;
- *((void **)&funcPtr)=funcStr;//he he...
- //
- double *ptr=getPointer();
- int nbOfComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- int nbOfElems=nbOfTuples*nbOfComp;
- for(int i=0;i<nbOfElems;i++,ptr++)
- *ptr=funcPtr(*ptr);
- declareAsNew();
-}
-
-void DataArrayDouble::applyFuncFast64(const std::string& func)
-{
- checkAllocated();
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- char *funcStr=expr.compileX86_64();
- MYFUNCPTR funcPtr;
- *((void **)&funcPtr)=funcStr;//he he...
- //
- double *ptr=getPointer();
- int nbOfComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- int nbOfElems=nbOfTuples*nbOfComp;
- for(int i=0;i<nbOfElems;i++,ptr++)
- *ptr=funcPtr(*ptr);
- declareAsNew();
-}
-
-DataArrayDoubleIterator *DataArrayDouble::iterator()
-{
- return new DataArrayDoubleIterator(this);
-}
-
-/*!
- * Returns a new DataArrayInt contating indices of tuples of \a this one-dimensional
- * array whose values are within a given range. Textual data is not copied.
- * \param [in] vmin - a lowest acceptable value (included).
- * \param [in] vmax - a greatest acceptable value (included).
- * \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 \a this->getNumberOfComponents() != 1.
- *
- * \sa DataArrayDouble::getIdsNotInRange
- *
- * \if ENABLE_EXAMPLES
- * \ref cpp_mcdataarraydouble_getidsinrange "Here is a C++ example".<br>
- * \ref py_mcdataarraydouble_getidsinrange "Here is a Python example".
- * \endif
- */
-DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::getIdsInRange : this must have exactly one component !");
- const double *cptr(begin());
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- int nbOfTuples(getNumberOfTuples());
- for(int i=0;i<nbOfTuples;i++,cptr++)
- if(*cptr>=vmin && *cptr<=vmax)
- ret->pushBackSilent(i);
- return ret.retn();
-}
-
-/*!
- * Returns a new DataArrayInt contating indices of tuples of \a this one-dimensional
- * array whose values are not within a given range. Textual data is not copied.
- * \param [in] vmin - a lowest not acceptable value (excluded).
- * \param [in] vmax - a greatest not acceptable value (excluded).
- * \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 \a this->getNumberOfComponents() != 1.
- *
- * \sa DataArrayDouble::getIdsInRange
- */
-DataArrayInt *DataArrayDouble::getIdsNotInRange(double vmin, double vmax) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::getIdsNotInRange : this must have exactly one component !");
- const double *cptr(begin());
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- int nbOfTuples(getNumberOfTuples());
- for(int i=0;i<nbOfTuples;i++,cptr++)
- if(*cptr<vmin || *cptr>vmax)
- ret->pushBackSilent(i);
- return ret.retn();
-}
-
-/*!
- * Returns a new DataArrayDouble by concatenating two given arrays, so that (1) the number
- * of tuples in the result array is a sum of the number of tuples of given arrays and (2)
- * the number of component in the result array is same as that of each of given arrays.
- * Info on components is copied from the first of the given arrays. Number of components
- * in the given arrays must be the same.
- * \param [in] a1 - an array to include in the result array.
- * \param [in] a2 - another array to include in the result 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 both \a a1 and \a a2 are NULL.
- * \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents().
- */
-DataArrayDouble *DataArrayDouble::Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- std::vector<const DataArrayDouble *> tmp(2);
- tmp[0]=a1; tmp[1]=a2;
- return Aggregate(tmp);
-}
-
-/*!
- * Returns a new DataArrayDouble by concatenating all given arrays, so that (1) the number
- * of tuples in the result array is a sum of the number of tuples of given arrays and (2)
- * the number of component in the result array is same as that of each of given arrays.
- * Info on components is copied from the first of the given arrays. Number of components
- * in the given arrays must be the same.
- * If the number of non null of elements in \a arr is equal to one the returned object is a copy of it
- * not the object itself.
- * \param [in] arr - a sequence of arrays to include in the result 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 all arrays within \a arr are NULL.
- * \throw If getNumberOfComponents() of arrays within \a arr.
- */
-DataArrayDouble *DataArrayDouble::Aggregate(const std::vector<const DataArrayDouble *>& arr)
-{
- std::vector<const DataArrayDouble *> a;
- for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
- if(*it4)
- a.push_back(*it4);
- if(a.empty())
- throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : input list must contain at least one NON EMPTY DataArrayDouble !");
- std::vector<const DataArrayDouble *>::const_iterator it=a.begin();
- int nbOfComp=(*it)->getNumberOfComponents();
- int nbt=(*it++)->getNumberOfTuples();
- for(int i=1;it!=a.end();it++,i++)
- {
- if((*it)->getNumberOfComponents()!=nbOfComp)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : Nb of components mismatch for array aggregation !");
- nbt+=(*it)->getNumberOfTuples();
- }
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbt,nbOfComp);
- double *pt=ret->getPointer();
- for(it=a.begin();it!=a.end();it++)
- pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt);
- ret->copyStringInfoFrom(*(a[0]));
- return ret.retn();
-}
-
-/*!
- * Returns a new DataArrayDouble by aggregating two given arrays, so that (1) the number
- * of components in the result array is a sum of the number of components of given arrays
- * and (2) the number of tuples in the result array is same as that of each of given
- * arrays. In other words the i-th tuple of result array includes all components of
- * i-th tuples of all given arrays.
- * Number of tuples in the given arrays must be the same.
- * \param [in] a1 - an array to include in the result array.
- * \param [in] a2 - another array to include in the result 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 both \a a1 and \a a2 are NULL.
- * \throw If any given array is not allocated.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
- */
-DataArrayDouble *DataArrayDouble::Meld(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- std::vector<const DataArrayDouble *> arr(2);
- arr[0]=a1; arr[1]=a2;
- return Meld(arr);
-}
-
-/*!
- * Returns a new DataArrayDouble by aggregating all given arrays, so that (1) the number
- * of components in the result array is a sum of the number of components of given arrays
- * and (2) the number of tuples in the result array is same as that of each of given
- * arrays. In other words the i-th tuple of result array includes all components of
- * i-th tuples of all given arrays.
- * Number of tuples in the given arrays must be the same.
- * \param [in] arr - a sequence of arrays to include in the result 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 all arrays within \a arr are NULL.
- * \throw If any given array is not allocated.
- * \throw If getNumberOfTuples() of arrays within \a arr is different.
- */
-DataArrayDouble *DataArrayDouble::Meld(const std::vector<const DataArrayDouble *>& arr)
-{
- std::vector<const DataArrayDouble *> a;
- for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
- if(*it4)
- a.push_back(*it4);
- if(a.empty())
- throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : input list must contain at least one NON EMPTY DataArrayDouble !");
- std::vector<const DataArrayDouble *>::const_iterator it;
- for(it=a.begin();it!=a.end();it++)
- (*it)->checkAllocated();
- it=a.begin();
- int nbOfTuples=(*it)->getNumberOfTuples();
- std::vector<int> nbc(a.size());
- std::vector<const double *> pts(a.size());
- nbc[0]=(*it)->getNumberOfComponents();
- pts[0]=(*it++)->getConstPointer();
- for(int i=1;it!=a.end();it++,i++)
- {
- if(nbOfTuples!=(*it)->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : mismatch of number of tuples !");
- nbc[i]=(*it)->getNumberOfComponents();
- pts[i]=(*it)->getConstPointer();
- }
- int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuples,totalNbOfComp);
- double *retPtr=ret->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- for(int j=0;j<(int)a.size();j++)
- {
- retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
- pts[j]+=nbc[j];
- }
- int k=0;
- for(int i=0;i<(int)a.size();i++)
- for(int j=0;j<nbc[i];j++,k++)
- ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j));
- return ret;
-}
-
-/*!
- * Returns a new DataArrayDouble containing a dot product of two given arrays, so that
- * the i-th tuple of the result array is a sum of products of j-th components of i-th
- * tuples of given arrays (\f$ a_i = \sum_{j=1}^n a1_j * a2_j \f$).
- * Info on components and name is copied from the first of the given arrays.
- * Number of tuples and components in the given arrays must be the same.
- * \param [in] a1 - a given array.
- * \param [in] a2 - another given 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 any given array is not allocated.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
- * \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents()
- */
-DataArrayDouble *DataArrayDouble::Dot(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Dot : input DataArrayDouble instance is NULL !");
- a1->checkAllocated();
- a2->checkAllocated();
- int nbOfComp=a1->getNumberOfComponents();
- if(nbOfComp!=a2->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Dot !");
- int nbOfTuple=a1->getNumberOfTuples();
- if(nbOfTuple!=a2->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Dot !");
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,1);
- double *retPtr=ret->getPointer();
- const double *a1Ptr=a1->getConstPointer();
- const double *a2Ptr=a2->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- {
- double sum=0.;
- for(int j=0;j<nbOfComp;j++)
- sum+=a1Ptr[i*nbOfComp+j]*a2Ptr[i*nbOfComp+j];
- retPtr[i]=sum;
- }
- ret->setInfoOnComponent(0,a1->getInfoOnComponent(0));
- ret->setName(a1->getName());
- return ret;
-}
-
-/*!
- * Returns a new DataArrayDouble containing a cross product of two given arrays, so that
- * the i-th tuple of the result array contains 3 components of a vector which is a cross
- * product of two vectors defined by the i-th tuples of given arrays.
- * Info on components is copied from the first of the given arrays.
- * Number of tuples in the given arrays must be the same.
- * Number of components in the given arrays must be 3.
- * \param [in] a1 - a given array.
- * \param [in] a2 - another given 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()
- * \throw If \a a1->getNumberOfComponents() != 3
- * \throw If \a a2->getNumberOfComponents() != 3
- */
-DataArrayDouble *DataArrayDouble::CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::CrossProduct : input DataArrayDouble instance is NULL !");
- int nbOfComp=a1->getNumberOfComponents();
- if(nbOfComp!=a2->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array crossProduct !");
- if(nbOfComp!=3)
- throw INTERP_KERNEL::Exception("Nb of components must be equal to 3 for array crossProduct !");
- int nbOfTuple=a1->getNumberOfTuples();
- if(nbOfTuple!=a2->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array crossProduct !");
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,3);
- double *retPtr=ret->getPointer();
- const double *a1Ptr=a1->getConstPointer();
- const double *a2Ptr=a2->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- {
- retPtr[3*i]=a1Ptr[3*i+1]*a2Ptr[3*i+2]-a1Ptr[3*i+2]*a2Ptr[3*i+1];
- retPtr[3*i+1]=a1Ptr[3*i+2]*a2Ptr[3*i]-a1Ptr[3*i]*a2Ptr[3*i+2];
- retPtr[3*i+2]=a1Ptr[3*i]*a2Ptr[3*i+1]-a1Ptr[3*i+1]*a2Ptr[3*i];
- }
- ret->copyStringInfoFrom(*a1);
- return ret;
-}
-
-/*!
- * Returns a new DataArrayDouble containing maximal values of two given arrays.
- * Info on components is copied from the first of the given arrays.
- * Number of tuples and components in the given arrays must be the same.
- * \param [in] a1 - an array to compare values with another one.
- * \param [in] a2 - another array to compare values with the first one.
- * \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() != \a a2->getNumberOfComponents()
- */
-DataArrayDouble *DataArrayDouble::Max(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Max : input DataArrayDouble instance is NULL !");
- int nbOfComp=a1->getNumberOfComponents();
- if(nbOfComp!=a2->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Max !");
- int nbOfTuple=a1->getNumberOfTuples();
- if(nbOfTuple!=a2->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Max !");
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfComp);
- double *retPtr=ret->getPointer();
- const double *a1Ptr=a1->getConstPointer();
- const double *a2Ptr=a2->getConstPointer();
- int nbElem=nbOfTuple*nbOfComp;
- for(int i=0;i<nbElem;i++)
- retPtr[i]=std::max(a1Ptr[i],a2Ptr[i]);
- ret->copyStringInfoFrom(*a1);
- return ret;
-}
-
-/*!
- * Returns a new DataArrayDouble containing minimal values of two given arrays.
- * Info on components is copied from the first of the given arrays.
- * Number of tuples and components in the given arrays must be the same.
- * \param [in] a1 - an array to compare values with another one.
- * \param [in] a2 - another array to compare values with the first one.
- * \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() != \a a2->getNumberOfComponents()
- */
-DataArrayDouble *DataArrayDouble::Min(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Min : input DataArrayDouble instance is NULL !");
- int nbOfComp=a1->getNumberOfComponents();
- if(nbOfComp!=a2->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array min !");
- int nbOfTuple=a1->getNumberOfTuples();
- if(nbOfTuple!=a2->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array min !");
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfComp);
- double *retPtr=ret->getPointer();
- const double *a1Ptr=a1->getConstPointer();
- const double *a2Ptr=a2->getConstPointer();
- int nbElem=nbOfTuple*nbOfComp;
- for(int i=0;i<nbElem;i++)
- retPtr[i]=std::min(a1Ptr[i],a2Ptr[i]);
- ret->copyStringInfoFrom(*a1);
- 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();
- MEDCouplingAutoRefCountObjectPtr<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();
-}
-
-/*!
- * 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)
- {
- MEDCouplingAutoRefCountObjectPtr<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)
- {
- MEDCouplingAutoRefCountObjectPtr<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 !");
- MEDCouplingAutoRefCountObjectPtr<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.
- * 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();
-}
-
-/*!
- * 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();
- MEDCouplingAutoRefCountObjectPtr<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
- * 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.
- */
-void DataArrayDouble::multiplyEqual(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 !";
- 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<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++));
- }
- 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::multiplies<double>());
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
-}
-
-/*!
- * 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.
- */
-DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Divide : 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)
- {
- MEDCouplingAutoRefCountObjectPtr<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)
- {
- MEDCouplingAutoRefCountObjectPtr<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();
- }
- 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 !");
- MEDCouplingAutoRefCountObjectPtr<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 !");
- MEDCouplingAutoRefCountObjectPtr<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();
-}
-
-/*!
- * Apply pow on values of another DataArrayDouble to values of \a this one.
- *
- * \param [in] other - an array to pow to \a this one.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples()
- * \throw If \a this->getNumberOfComponents() != 1 or \a other->getNumberOfComponents() != 1
- * \throw If there is a negative value in \a this.