- * This method accumulate using addition tuples in \a this using input index array [ \a bgOfIndex, \a endOfIndex ).
- * The returned array will have same number of components than \a this and number of tuples equal to
- * \c std::distance(bgOfIndex,endOfIndex) \b minus \b one.
- *
- * The input index array is expected to be ascendingly sorted in which the all referenced ids should be in [0, \c this->getNumberOfTuples).
- * This method is quite useful for users that need to put a field on cells to field on nodes on the same mesh without a need of conservation.
- *
- * \param [in] bgOfIndex - begin (included) of the input index array.
- * \param [in] endOfIndex - end (excluded) of the input index array.
- * \return DataArrayDouble * - the new instance having the same number of components than \a this.
- *
- * \throw If bgOfIndex or end is NULL.
- * \throw If input index array is not ascendingly sorted.
- * \throw If there is an id in [ \a bgOfIndex, \a endOfIndex ) not in [0, \c this->getNumberOfTuples).
- * \throw If std::distance(bgOfIndex,endOfIndex)==0.
- */
-DataArrayDouble *DataArrayDouble::accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const
-{
- if(!bgOfIndex || !endOfIndex)
- throw INTERP_KERNEL::Exception("DataArrayDouble::accumulatePerChunck : input pointer NULL !");
- checkAllocated();
- int nbCompo=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- int sz=(int)std::distance(bgOfIndex,endOfIndex);
- if(sz<1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::accumulatePerChunck : invalid size of input index array !");
- sz--;
- MCAuto<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(sz,nbCompo);
- const int *w=bgOfIndex;
- if(*w<0 || *w>=nbOfTuples)
- throw INTERP_KERNEL::Exception("DataArrayDouble::accumulatePerChunck : The first element of the input index not in [0,nbOfTuples) !");
- const double *srcPt=begin()+(*w)*nbCompo;
- double *tmp=ret->getPointer();
- for(int i=0;i<sz;i++,tmp+=nbCompo,w++)
- {
- std::fill(tmp,tmp+nbCompo,0.);
- if(w[1]>=w[0])
- {
- for(int j=w[0];j<w[1];j++,srcPt+=nbCompo)
- {
- if(j>=0 && j<nbOfTuples)
- std::transform(srcPt,srcPt+nbCompo,tmp,tmp,std::plus<double>());
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::accumulatePerChunck : At rank #" << i << " the input index array points to id " << j << " should be in [0," << nbOfTuples << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::accumulatePerChunck : At rank #" << i << " the input index array is not in ascendingly sorted.";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- ret->copyStringInfoFrom(*this);
- return ret.retn();
-}
-
-/*!
- * 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;
-}
-
-/*!
- * This method returns a new array containing the same number of tuples than \a this. To do this, this method needs \a at parameter to specify the convention of \a this.
- * All the tuples of the returned array will be in cartesian sense. So if \a at equals to AX_CART the returned array is basically a deep copy of \a this.
- * If \a at equals to AX_CYL the returned array will be the result of operation cylindric to cartesian of \a this...
- *
- * \param [in] atOfThis - The axis type of \a this.
- * \return DataArrayDouble * - the new instance of DataArrayDouble (that must be dealed by caller) containing the result of the cartesianizification of \a this.
- */
-DataArrayDouble *DataArrayDouble::cartesianize(MEDCouplingAxisType atOfThis) const
-{
- checkAllocated();
- int nbOfComp(getNumberOfComponents());
- MCAuto<DataArrayDouble> ret;
- switch(atOfThis)
- {
- case AX_CART:
- ret=deepCopy();
- case AX_CYL:
- if(nbOfComp==3)
- {
- ret=fromCylToCart();
- break;
- }
- if(nbOfComp==2)
- {
- ret=fromPolarToCart();
- break;
- }
- else
- throw INTERP_KERNEL::Exception("DataArrayDouble::cartesianize : For AX_CYL, number of components must be in [2,3] !");
- case AX_SPHER:
- if(nbOfComp==3)
- {
- ret=fromSpherToCart();
- break;
- }
- if(nbOfComp==2)
- {
- ret=fromPolarToCart();
- break;
- }
- else
- throw INTERP_KERNEL::Exception("DataArrayDouble::cartesianize : For AX_CYL, number of components must be in [2,3] !");
- default:
- throw INTERP_KERNEL::Exception("DataArrayDouble::cartesianize : not recognized axis type ! Only AX_CART, AX_CYL and AX_SPHER supported !");
- }
- ret->copyStringInfoFrom(*this);
- return ret.retn();
-}
-
-/*!
- * 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());
- MCAuto<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();
- MCAuto<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();
- MCAuto<DataArrayDouble> ret0=DataArrayDouble::New();
- MCAuto<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) MEDCoupling::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();
- MCAuto<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) MEDCoupling::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();
- MCAuto<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 applyFuncNamedCompo(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());
- MCAuto<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 applyFuncCompo or applyFuncNamedCompo 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 applyFuncCompo or applyFuncNamedCompo 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::applyFuncCompo(int nbOfComp, const std::string& func, bool isSafe) const
-{
- return applyFuncNamedCompo(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::applyFuncNamedCompo(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func, bool isSafe) const
-{
- if(nbOfComp<=0)
- throw INTERP_KERNEL::Exception("DataArrayDouble::applyFuncNamedCompo : 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());
- }
- MCAuto<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::findIdsNotInRange
- *
- * \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::findIdsInRange(double vmin, double vmax) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::findIdsInRange : this must have exactly one component !");
- const double *cptr(begin());
- MCAuto<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::findIdsInRange
- */
-DataArrayInt *DataArrayDouble::findIdsNotInRange(double vmin, double vmax) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::findIdsNotInRange : this must have exactly one component !");
- const double *cptr(begin());
- MCAuto<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();
- }
- MCAuto<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();
- MCAuto<DataArrayDouble> ret=0;
- if(nbOfTuple==nbOfTuple2)
- {
- if(nbOfComp==nbOfComp2)
- {
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfComp);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus<double>());
- ret->copyStringInfoFrom(*a1);
- }
- else
- {
- int nbOfCompMin,nbOfCompMax;
- const DataArrayDouble *aMin, *aMax;
- if(nbOfComp>nbOfComp2)
- {
- nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
- aMin=a2; aMax=a1;
- }
- else
- {
- nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
- aMin=a1; aMax=a2;
- }
- if(nbOfCompMin==1)
- {
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfCompMax);
- const double *aMinPtr=aMin->getConstPointer();
- const double *aMaxPtr=aMax->getConstPointer();
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++)
- res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<double>(),aMinPtr[i]));
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
- }
- }
- else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
- {
- if(nbOfComp==nbOfComp2)
- {
- int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
- const DataArrayDouble *aMin=nbOfTuple>nbOfTuple2?a2:a1;
- const DataArrayDouble *aMax=nbOfTuple>nbOfTuple2?a1:a2;
- const double *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTupleMax,nbOfComp);
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTupleMax;i++)
- res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::plus<double>());
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
- }
- else
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
- return ret.retn();
-}
-
-/*!
- * Adds values of another DataArrayDouble to values of \a this one. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a other array is added to the corresponding value of \a this array, i.e.:
- * _a_ [ i, j ] += _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _a_ [ i, j ] += _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _a_ [ i, j ] += _a2_ [ 0, j ].
- *
- * \param [in] other - an array to add to \a this one.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
- */
-void DataArrayDouble::addEqual(const DataArrayDouble *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::addEqual : input DataArrayDouble instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayDouble::addEqual !";
- checkAllocated();
- other->checkAllocated();
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
- {
- if(nbOfComp==nbOfComp2)
- {
- std::transform(begin(),end(),other->begin(),getPointer(),std::plus<double>());
- }
- else if(nbOfComp2==1)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<double>(),*ptrc++));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else if(nbOfTuple2==1)
- {
- if(nbOfComp2==nbOfComp)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<double>());
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
-}
-
-/*!
- * 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.
- * 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();
- 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
- * 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)
- {
- 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)
- {
- 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();
- }
- 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<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();
-}
-
-/*!
- * 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.
- */
-void DataArrayDouble::powEqual(const DataArrayDouble *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : input instance is null !");
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple!=nbOfTuple2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : number of tuples mismatches !");
- if(nbOfComp!=1 || nbOfComp2!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : number of components of both arrays must be equal to 1 !");
- double *ptr=getPointer();
- const double *ptrc=other->begin();
- for(int i=0;i<nbOfTuple;i++,ptrc++,ptr++)
- {
- if(*ptr>=0)
- *ptr=pow(*ptr,*ptrc);
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::powEqual : on tuple #" << i << " of this value is < 0 (" << *ptr << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- declareAsNew();
-}
-
-/*!
- * This method is \b NOT wrapped into python because it can be useful only for performance reasons in C++ context.
- * All values in \a this must be 0. or 1. within eps error. 0 means false, 1 means true.
- * If an another value than 0 or 1 appear (within eps precision) an INTERP_KERNEL::Exception will be thrown.
- *
- * \throw if \a this is not allocated.
- * \throw if \a this has not exactly one component.
- */
-std::vector<bool> DataArrayDouble::toVectorOfBool(double eps) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::toVectorOfBool : must be applied on single component array !");
- int nbt(getNumberOfTuples());
- std::vector<bool> ret(nbt);
- const double *pt(begin());
- for(int i=0;i<nbt;i++)
- {
- if(fabs(pt[i])<eps)
- ret[i]=false;
- else if(fabs(pt[i]-1.)<eps)
- ret[i]=true;
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::toVectorOfBool : the tuple #" << i << " has value " << pt[i] << " is invalid ! must be 0. or 1. !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return ret;
-}
-
-/*!
- * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
- * Server side.
- */
-void DataArrayDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
-{
- tinyInfo.resize(2);
- if(isAllocated())
- {
- tinyInfo[0]=getNumberOfTuples();
- tinyInfo[1]=getNumberOfComponents();
- }
- else
- {
- tinyInfo[0]=-1;
- tinyInfo[1]=-1;
- }
-}
-
-/*!
- * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
- * Server side.
- */
-void DataArrayDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
-{
- if(isAllocated())
- {
- int nbOfCompo=getNumberOfComponents();
- tinyInfo.resize(nbOfCompo+1);
- tinyInfo[0]=getName();
- for(int i=0;i<nbOfCompo;i++)
- tinyInfo[i+1]=getInfoOnComponent(i);
- }
- else
- {
- tinyInfo.resize(1);
- tinyInfo[0]=getName();
- }
-}
-
-/*!
- * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
- * This method returns if a feeding is needed.
- */
-bool DataArrayDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI)
-{
- int nbOfTuple=tinyInfoI[0];
- int nbOfComp=tinyInfoI[1];
- if(nbOfTuple!=-1 || nbOfComp!=-1)
- {
- alloc(nbOfTuple,nbOfComp);
- return true;
- }
- return false;
-}
-
-/*!
- * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
- */
-void DataArrayDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
-{
- setName(tinyInfoS[0]);
- if(isAllocated())
- {
- int nbOfCompo=getNumberOfComponents();
- for(int i=0;i<nbOfCompo;i++)
- setInfoOnComponent(i,tinyInfoS[i+1]);
- }
-}
-
-DataArrayDoubleIterator::DataArrayDoubleIterator(DataArrayDouble *da):_da(da),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
-{
- if(_da)
- {
- _da->incrRef();
- if(_da->isAllocated())
- {
- _nb_comp=da->getNumberOfComponents();
- _nb_tuple=da->getNumberOfTuples();
- _pt=da->getPointer();
- }
- }
-}
-
-DataArrayDoubleIterator::~DataArrayDoubleIterator()
-{
- if(_da)
- _da->decrRef();
-}
-
-DataArrayDoubleTuple *DataArrayDoubleIterator::nextt()
-{
- if(_tuple_id<_nb_tuple)
- {
- _tuple_id++;
- DataArrayDoubleTuple *ret=new DataArrayDoubleTuple(_pt,_nb_comp);
- _pt+=_nb_comp;
- return ret;
- }
- else
- return 0;
-}
-
-DataArrayDoubleTuple::DataArrayDoubleTuple(double *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
-{
-}
-
-
-std::string DataArrayDoubleTuple::repr() const
-{
- std::ostringstream oss; oss.precision(17); oss << "(";
- for(int i=0;i<_nb_of_compo-1;i++)
- oss << _pt[i] << ", ";
- oss << _pt[_nb_of_compo-1] << ")";
- return oss.str();
-}
-
-double DataArrayDoubleTuple::doubleValue() const
-{
- if(_nb_of_compo==1)
- return *_pt;
- throw INTERP_KERNEL::Exception("DataArrayDoubleTuple::doubleValue : DataArrayDoubleTuple instance has not exactly 1 component -> Not possible to convert it into a double precision float !");
-}
-
-/*!
- * This method returns a newly allocated instance the caller should dealed with by a MEDCoupling::DataArrayDouble::decrRef.
- * This method performs \b no copy of data. The content is only referenced using MEDCoupling::DataArrayDouble::useArray with ownership set to \b false.
- * This method throws an INTERP_KERNEL::Exception is it is impossible to match sizes of \b this that is too say \b nbOfCompo=this->_nb_of_elem and \bnbOfTuples==1 or
- * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem.
- */
-DataArrayDouble *DataArrayDoubleTuple::buildDADouble(int nbOfTuples, int nbOfCompo) const
-{
- if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
- {
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
- return ret;
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayDoubleTuple::buildDADouble : unable to build a requested DataArrayDouble instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
- oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
-}
-
-/*!
- * Returns a new instance of DataArrayInt. The caller is to delete this array
- * using decrRef() as it is no more needed.
- */
-DataArrayInt *DataArrayInt::New()
-{
- return new DataArrayInt;
-}
-
-/*!
- * Returns the only one value in \a this, if and only if number of elements
- * (nb of tuples * nb of components) is equal to 1, and that \a this is allocated.
- * \return double - the sole value stored in \a this array.
- * \throw If at least one of conditions stated above is not fulfilled.
- */
-int DataArrayInt::intValue() const
-{
- if(isAllocated())
- {
- if(getNbOfElems()==1)
- {
- return *getConstPointer();
- }
- else
- throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is allocated but number of elements is not equal to 1 !");
- }
- else
- throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is not allocated !");
-}
-
-/*!
- * Returns an integer value characterizing \a this array, which is useful for a quick
- * comparison of many instances of DataArrayInt.
- * \return int - the hash value.
- * \throw If \a this is not allocated.
- */
-int DataArrayInt::getHashCode() const
-{
- checkAllocated();
- std::size_t nbOfElems=getNbOfElems();
- int ret=nbOfElems*65536;
- int delta=3;
- if(nbOfElems>48)
- delta=nbOfElems/8;
- int ret0=0;
- const int *pt=begin();
- for(std::size_t i=0;i<nbOfElems;i+=delta)
- ret0+=pt[i] & 0x1FFF;
- return ret+ret0;
-}
-
-/*!
- * Returns a full copy of \a this. For more info on copying data arrays see
- * \ref MEDCouplingArrayBasicsCopyDeep.
- * \return DataArrayInt * - a new instance of DataArrayInt.
- */
-DataArrayInt *DataArrayInt::deepCopy() const
-{
- return new DataArrayInt(*this);
-}
-
-/*!
- * Returns either a \a deep or \a shallow copy of this array. For more info see
- * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
- * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
- * \return DataArrayInt * - either a new instance of DataArrayInt (if \a dCpy
- * == \a true) or \a this instance (if \a dCpy == \a false).
- */
-DataArrayInt *DataArrayInt::performCopyOrIncrRef(bool dCpy) const
-{
- if(dCpy)
- return deepCopy();
- else
- {
- incrRef();
- return const_cast<DataArrayInt *>(this);
- }
-}
-
-/*!
- * Assign zero to all values in \a this array. To know more on filling arrays see
- * \ref MEDCouplingArrayFill.
- * \throw If \a this is not allocated.
- */
-void DataArrayInt::fillWithZero()
-{
- fillWithValue(0);
-}
-
-/*!
- * Set all values in \a this array so that the i-th element equals to \a init + i
- * (i starts from zero). To know more on filling arrays see \ref MEDCouplingArrayFill.
- * \param [in] init - value to assign to the first element of array.
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If \a this is not allocated.
- */
-void DataArrayInt::iota(int init)
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
- int *ptr=getPointer();
- int ntuples=getNumberOfTuples();
- for(int i=0;i<ntuples;i++)
- ptr[i]=init+i;
- declareAsNew();
-}
-
-/*!
- * Returns a textual and human readable representation of \a this instance of
- * DataArrayInt. This text is shown when a DataArrayInt is printed in Python.
- * \return std::string - text describing \a this DataArrayInt.
- *
- * \sa reprNotTooLong, reprZip
- */
-std::string DataArrayInt::repr() const
-{
- std::ostringstream ret;
- reprStream(ret);
- return ret.str();
-}
-
-std::string DataArrayInt::reprZip() const
-{
- std::ostringstream ret;
- reprZipStream(ret);
- return ret.str();
-}
-
-/*!
- * This method is close to repr method except that when \a this has more than 1000 tuples, all tuples are not
- * printed out to avoid to consume too much space in interpretor.
- * \sa repr
- */
-std::string DataArrayInt::reprNotTooLong() const
-{
- std::ostringstream ret;
- reprNotTooLongStream(ret);
- return ret.str();
-}
-
-void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const
-{
- static const char SPACE[4]={' ',' ',' ',' '};
- checkAllocated();
- std::string idt(indent,' ');
- ofs << idt << "<DataArray type=\"" << type << "\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << getNumberOfComponents() << "\"";
- if(byteArr)
- {
- ofs << " format=\"appended\" offset=\"" << byteArr->getNumberOfTuples() << "\">";
- if(std::string(type)=="Int32")
- {
- const char *data(reinterpret_cast<const char *>(begin()));
- std::size_t sz(getNbOfElems()*sizeof(int));
- byteArr->insertAtTheEnd(data,data+sz);
- byteArr->insertAtTheEnd(SPACE,SPACE+4);
- }
- else if(std::string(type)=="Int8")
- {
- INTERP_KERNEL::AutoPtr<char> tmp(new char[getNbOfElems()]);
- std::copy(begin(),end(),(char *)tmp);
- byteArr->insertAtTheEnd((char *)tmp,(char *)tmp+getNbOfElems());
- byteArr->insertAtTheEnd(SPACE,SPACE+4);
- }
- else if(std::string(type)=="UInt8")
- {
- INTERP_KERNEL::AutoPtr<unsigned char> tmp(new unsigned char[getNbOfElems()]);
- std::copy(begin(),end(),(unsigned char *)tmp);
- byteArr->insertAtTheEnd((unsigned char *)tmp,(unsigned char *)tmp+getNbOfElems());
- byteArr->insertAtTheEnd(SPACE,SPACE+4);
- }
- else
- throw INTERP_KERNEL::Exception("DataArrayInt::writeVTK : Only Int32, Int8 and UInt8 supported !");
- }
- else
- {
- ofs << " RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\" format=\"ascii\">\n" << idt;
- std::copy(begin(),end(),std::ostream_iterator<int>(ofs," "));
- }
- ofs << std::endl << idt << "</DataArray>\n";
-}
-
-void DataArrayInt::reprStream(std::ostream& stream) const
-{
- stream << "Name of int array : \"" << _name << "\"\n";
- reprWithoutNameStream(stream);
-}
-
-void DataArrayInt::reprZipStream(std::ostream& stream) const
-{
- stream << "Name of int array : \"" << _name << "\"\n";
- reprZipWithoutNameStream(stream);
-}
-
-void DataArrayInt::reprNotTooLongStream(std::ostream& stream) const
-{
- stream << "Name of int array : \"" << _name << "\"\n";
- reprNotTooLongWithoutNameStream(stream);
-}
-
-void DataArrayInt::reprWithoutNameStream(std::ostream& stream) const
-{
- DataArray::reprWithoutNameStream(stream);
- _mem.repr(getNumberOfComponents(),stream);
-}
-
-void DataArrayInt::reprZipWithoutNameStream(std::ostream& stream) const
-{
- DataArray::reprWithoutNameStream(stream);
- _mem.reprZip(getNumberOfComponents(),stream);
-}
-
-void DataArrayInt::reprNotTooLongWithoutNameStream(std::ostream& stream) const
-{
- DataArray::reprWithoutNameStream(stream);
- stream.precision(17);
- _mem.reprNotTooLong(getNumberOfComponents(),stream);
-}
-
-void DataArrayInt::reprCppStream(const std::string& varName, std::ostream& stream) const
-{
- int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
- const int *data=getConstPointer();
- stream << "DataArrayInt *" << varName << "=DataArrayInt::New();" << std::endl;
- if(nbTuples*nbComp>=1)
- {
- stream << "const int " << varName << "Data[" << nbTuples*nbComp << "]={";
- std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<int>(stream,","));
- stream << data[nbTuples*nbComp-1] << "};" << std::endl;
- stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
- }
- else
- stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
- stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
-}
-
-/*!
- * Method that gives a quick overvien of \a this for python.
- */
-void DataArrayInt::reprQuickOverview(std::ostream& stream) const
-{
- static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
- stream << "DataArrayInt C++ instance at " << this << ". ";
- if(isAllocated())
- {
- int nbOfCompo=(int)_info_on_compo.size();
- if(nbOfCompo>=1)
- {
- int nbOfTuples=getNumberOfTuples();
- stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
- reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
- }
- else
- stream << "Number of components : 0.";
- }
- else
- stream << "*** No data allocated ****";
-}
-
-void DataArrayInt::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const
-{
- const int *data=begin();
- int nbOfTuples=getNumberOfTuples();
- int nbOfCompo=(int)_info_on_compo.size();
- std::ostringstream oss2; oss2 << "[";
- std::string oss2Str(oss2.str());
- bool isFinished=true;
- for(int i=0;i<nbOfTuples && isFinished;i++)
- {
- if(nbOfCompo>1)
- {
- oss2 << "(";
- for(int j=0;j<nbOfCompo;j++,data++)
- {
- oss2 << *data;
- if(j!=nbOfCompo-1) oss2 << ", ";
- }
- oss2 << ")";
- }
- else
- oss2 << *data++;
- if(i!=nbOfTuples-1) oss2 << ", ";
- std::string oss3Str(oss2.str());
- if(oss3Str.length()<maxNbOfByteInRepr)
- oss2Str=oss3Str;
- else
- isFinished=false;
- }
- stream << oss2Str;
- if(!isFinished)
- stream << "... ";
- stream << "]";
-}
-
-/*!
- * Modifies in place \a this one-dimensional array so that each value \a v = \a indArrBg[ \a v ],
- * i.e. a current value is used as in index to get a new value from \a indArrBg.
- * \param [in] indArrBg - pointer to the first element of array of new values to assign
- * to \a this array.
- * \param [in] indArrEnd - specifies the end of the array \a indArrBg, so that
- * the last value of \a indArrBg is \a indArrEnd[ -1 ].
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If any value of \a this can't be used as a valid index for
- * [\a indArrBg, \a indArrEnd).
- *
- * \sa changeValue
- */
-void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd)
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
- int nbElemsIn((int)std::distance(indArrBg,indArrEnd)),nbOfTuples(getNumberOfTuples()),*pt(getPointer());
- for(int i=0;i<nbOfTuples;i++,pt++)
- {
- if(*pt>=0 && *pt<nbElemsIn)
- *pt=indArrBg[*pt];
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << ", should be in [0," << nbElemsIn << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- declareAsNew();
-}
-
-/*!
- * Computes distribution of values of \a this one-dimensional array between given value
- * ranges (casts). This method is typically useful for entity number spliting by types,
- * for example.
- * \warning The values contained in \a arrBg should be sorted ascendently. No
- * check of this is be done. If not, the result is not warranted.
- * \param [in] arrBg - the array of ascending values defining the value ranges. The i-th
- * value of \a arrBg (\a arrBg[ i ]) gives the lowest value of the i-th range,
- * and the greatest value of the i-th range equals to \a arrBg[ i+1 ] - 1. \a
- * arrBg containing \a n values defines \a n-1 ranges. The last value of \a arrBg
- * should be more than every value in \a this array.
- * \param [in] arrEnd - specifies the end of the array \a arrBg, so that
- * the last value of \a arrBg is \a arrEnd[ -1 ].
- * \param [out] castArr - a new instance of DataArrayInt, of same size as \a this array
- * (same number of tuples and components), the caller is to delete
- * using decrRef() as it is no more needed.
- * This array contains indices of ranges for every value of \a this array. I.e.
- * the i-th value of \a castArr gives the index of range the i-th value of \a this
- * belongs to. Or, in other words, this parameter contains for each tuple in \a
- * this in which cast it holds.
- * \param [out] rankInsideCast - a new instance of DataArrayInt, of same size as \a this
- * array, the caller is to delete using decrRef() as it is no more needed.
- * This array contains ranks of values of \a this array within ranges
- * they belongs to. I.e. the i-th value of \a rankInsideCast gives the rank of
- * the i-th value of \a this array within the \a castArr[ i ]-th range, to which
- * the i-th value of \a this belongs to. Or, in other words, this param contains
- * for each tuple its rank inside its cast. The rank is computed as difference
- * between the value and the lowest value of range.
- * \param [out] castsPresent - a new instance of DataArrayInt, containing indices of
- * ranges (casts) to which at least one value of \a this array belongs.
- * Or, in other words, this param contains the casts that \a this contains.
- * The caller is to delete this array using decrRef() as it is no more needed.
- *
- * \b Example: If \a this contains [6,5,0,3,2,7,8,1,4] and \a arrBg contains [0,4,9] then
- * the output of this method will be :
- * - \a castArr : [1,1,0,0,0,1,1,0,1]
- * - \a rankInsideCast: [2,1,0,3,2,3,4,1,0]
- * - \a castsPresent : [0,1]
- *
- * I.e. values of \a this array belong to 2 ranges: #0 and #1. Value 6 belongs to the
- * range #1 and its rank within this range is 2; etc.
- *
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If \a arrEnd - arrBg < 2.
- * \throw If any value of \a this is not less than \a arrEnd[-1].
- */
-void DataArrayInt::splitByValueRange(const int *arrBg, const int *arrEnd,
- DataArrayInt *& castArr, DataArrayInt *& rankInsideCast, DataArrayInt *& castsPresent) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("Call splitByValueRange method on DataArrayInt with only one component, you can call 'rearrange' method before !");
- int nbOfTuples=getNumberOfTuples();
- std::size_t nbOfCast=std::distance(arrBg,arrEnd);
- if(nbOfCast<2)
- throw INTERP_KERNEL::Exception("DataArrayInt::splitByValueRange : The input array giving the cast range values should be of size >=2 !");
- nbOfCast--;
- const int *work=getConstPointer();
- typedef std::reverse_iterator<const int *> rintstart;
- rintstart bg(arrEnd);//OK no problem because size of 'arr' is greater or equal 2
- rintstart end2(arrBg);
- MCAuto<DataArrayInt> ret1=DataArrayInt::New();
- MCAuto<DataArrayInt> ret2=DataArrayInt::New();
- MCAuto<DataArrayInt> ret3=DataArrayInt::New();
- ret1->alloc(nbOfTuples,1);
- ret2->alloc(nbOfTuples,1);
- int *ret1Ptr=ret1->getPointer();
- int *ret2Ptr=ret2->getPointer();
- std::set<std::size_t> castsDetected;
- for(int i=0;i<nbOfTuples;i++)
- {
- rintstart res=std::find_if(bg,end2,std::bind2nd(std::less_equal<int>(), work[i]));
- std::size_t pos=std::distance(bg,res);
- std::size_t pos2=nbOfCast-pos;
- if(pos2<nbOfCast)
- {
- ret1Ptr[i]=(int)pos2;
- ret2Ptr[i]=work[i]-arrBg[pos2];
- castsDetected.insert(pos2);
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::splitByValueRange : At rank #" << i << " the value is " << work[i] << " should be in [0," << *bg << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- ret3->alloc((int)castsDetected.size(),1);
- std::copy(castsDetected.begin(),castsDetected.end(),ret3->getPointer());
- castArr=ret1.retn();
- rankInsideCast=ret2.retn();
- castsPresent=ret3.retn();
-}
-
-/*!
- * This method look at \a this if it can be considered as a range defined by the 3-tuple ( \a strt , \a sttoopp , \a stteepp ).
- * If false is returned the tuple must be ignored. If true is returned \a this can be considered by a range( \a strt , \a sttoopp , \a stteepp ).
- * This method works only if \a this is allocated and single component. If not an exception will be thrown.
- *
- * \param [out] strt - the start of the range (included) if true is returned.
- * \param [out] sttoopp - the end of the range (not included) if true is returned.
- * \param [out] stteepp - the step of the range if true is returned.
- * \return the verdict of the check.
- *
- * \sa DataArray::GetNumberOfItemGivenBES
- */
-bool DataArrayInt::isRange(int& strt, int& sttoopp, int& stteepp) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::isRange : this must be single component array !");
- int nbTuples(getNumberOfTuples());
- if(nbTuples==0)
- { strt=0; sttoopp=0; stteepp=1; return true; }
- const int *pt(begin());
- strt=*pt;
- if(nbTuples==1)
- { sttoopp=strt+1; stteepp=1; return true; }
- strt=*pt; sttoopp=pt[nbTuples-1];
- if(strt==sttoopp)
- return false;
- if(sttoopp>strt)
- {
- sttoopp++;
- int a(sttoopp-1-strt),tmp(strt);
- if(a%(nbTuples-1)!=0)
- return false;
- stteepp=a/(nbTuples-1);
- for(int i=0;i<nbTuples;i++,tmp+=stteepp)
- if(pt[i]!=tmp)
- return false;
- return true;
- }
- else
- {
- sttoopp--;
- int a(strt-sttoopp-1),tmp(strt);
- if(a%(nbTuples-1)!=0)
- return false;
- stteepp=-(a/(nbTuples-1));
- for(int i=0;i<nbTuples;i++,tmp+=stteepp)
- if(pt[i]!=tmp)
- return false;
- return true;
- }
-}
-
-/*!
- * Creates a one-dimensional DataArrayInt (\a res) whose contents are computed from
- * values of \a this (\a a) and the given (\a indArr) arrays as follows:
- * \a res[ \a indArr[ \a a[ i ]]] = i. I.e. for each value in place i \a v = \a a[ i ],
- * new value in place \a indArr[ \a v ] is i.
- * \param [in] indArrBg - the array holding indices within the result array to assign
- * indices of values of \a this array pointing to values of \a indArrBg.
- * \param [in] indArrEnd - specifies the end of the array \a indArrBg, so that
- * the last value of \a indArrBg is \a indArrEnd[ -1 ].
- * \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.
- * \throw If any value of \a this array is not a valid index for \a indArrBg array.
- * \throw If any value of \a indArrBg is not a valid index for \a this array.
- */
-DataArrayInt *DataArrayInt::transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("Call transformWithIndArrR method on DataArrayInt with only one component, you can call 'rearrange' method before !");
- int nbElemsIn=(int)std::distance(indArrBg,indArrEnd);
- int nbOfTuples=getNumberOfTuples();
- const int *pt=getConstPointer();
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuples,1);
- ret->fillWithValue(-1);
- int *tmp=ret->getPointer();
- for(int i=0;i<nbOfTuples;i++,pt++)
- {
- if(*pt>=0 && *pt<nbElemsIn)
- {
- int pos=indArrBg[*pt];
- if(pos>=0 && pos<nbOfTuples)
- tmp[pos]=i;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::transformWithIndArrR : error on tuple #" << i << " value of new pos is " << pos << " ( indArrBg[" << *pt << "]) ! Should be in [0," << nbOfTuples << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::transformWithIndArrR : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return ret.retn();
-}
-
-/*!
- * Creates a one-dimensional DataArrayInt of given length, whose contents are computed
- * from values of \a this array, which is supposed to contain a renumbering map in
- * "Old to New" mode. The result array contains a renumbering map in "New to Old" mode.
- * To know how to use the renumbering maps see \ref numbering.
- * \param [in] newNbOfElem - the number of tuples in the result array.
- * \return DataArrayInt * - the new instance of DataArrayInt.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- *
- * \if ENABLE_EXAMPLES
- * \ref cpp_mcdataarrayint_invertarrayo2n2n2o "Here is a C++ example".<br>
- * \ref py_mcdataarrayint_invertarrayo2n2n2o "Here is a Python example".
- * \endif
- */
-DataArrayInt *DataArrayInt::invertArrayO2N2N2O(int newNbOfElem) const
-{
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(newNbOfElem,1);
- int nbOfOldNodes=getNumberOfTuples();
- const int *old2New=getConstPointer();
- int *pt=ret->getPointer();
- for(int i=0;i!=nbOfOldNodes;i++)
- {
- int newp(old2New[i]);
- if(newp!=-1)
- {
- if(newp>=0 && newp<newNbOfElem)
- pt[newp]=i;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::invertArrayO2N2N2O : At place #" << i << " the newplace is " << newp << " must be in [0," << newNbOfElem << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- }
- return ret.retn();
-}
-
-/*!
- * This method is similar to DataArrayInt::invertArrayO2N2N2O except that
- * Example : If \a this contains [0,1,2,0,3,4,5,4,6,4] this method will return [0,1,2,4,5,6,8] whereas DataArrayInt::invertArrayO2N2N2O returns [3,1,2,4,9,6,8]
- */
-DataArrayInt *DataArrayInt::invertArrayO2N2N2OBis(int newNbOfElem) const
-{
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(newNbOfElem,1);
- int nbOfOldNodes=getNumberOfTuples();
- const int *old2New=getConstPointer();
- int *pt=ret->getPointer();
- for(int i=nbOfOldNodes-1;i>=0;i--)
- {
- int newp(old2New[i]);
- if(newp!=-1)
- {
- if(newp>=0 && newp<newNbOfElem)
- pt[newp]=i;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::invertArrayO2N2N2OBis : At place #" << i << " the newplace is " << newp << " must be in [0," << newNbOfElem << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- }
- return ret.retn();
-}
-
-/*!
- * Creates a one-dimensional DataArrayInt of given length, whose contents are computed
- * from values of \a this array, which is supposed to contain a renumbering map in
- * "New to Old" mode. The result array contains a renumbering map in "Old to New" mode.
- * To know how to use the renumbering maps see \ref numbering.
- * \param [in] newNbOfElem - the number of tuples in the result array.
- * \return DataArrayInt * - the new instance of DataArrayInt.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- *
- * \if ENABLE_EXAMPLES
- * \ref cpp_mcdataarrayint_invertarrayn2o2o2n "Here is a C++ example".
- *
- * \ref py_mcdataarrayint_invertarrayn2o2o2n "Here is a Python example".
- * \endif
- */
-DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const
-{
- checkAllocated();
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(oldNbOfElem,1);
- const int *new2Old=getConstPointer();
- int *pt=ret->getPointer();
- std::fill(pt,pt+oldNbOfElem,-1);
- int nbOfNewElems=getNumberOfTuples();
- for(int i=0;i<nbOfNewElems;i++)
- {
- int v(new2Old[i]);
- if(v>=0 && v<oldNbOfElem)
- pt[v]=i;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::invertArrayN2O2O2N : in new id #" << i << " old value is " << v << " expected to be in [0," << oldNbOfElem << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return ret.retn();
-}
-
-/*!
- * Equivalent to DataArrayInt::isEqual except that if false the reason of
- * mismatch is given.
- *
- * \param [in] other the instance to be compared with \a this
- * \param [out] reason In case of inequality returns the reason.
- * \sa DataArrayInt::isEqual
- */
-bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const
-{
- if(!areInfoEqualsIfNotWhy(other,reason))
- return false;
- return _mem.isEqual(other._mem,0,reason);
-}
-
-/*!
- * Checks if \a this and another DataArrayInt are fully equal. For more info see
- * \ref MEDCouplingArrayBasicsCompare.
- * \param [in] other - an instance of DataArrayInt to compare with \a this one.
- * \return bool - \a true if the two arrays are equal, \a false else.
- */
-bool DataArrayInt::isEqual(const DataArrayInt& other) const
-{
- std::string tmp;
- return isEqualIfNotWhy(other,tmp);
-}
-
-/*!
- * Checks if values of \a this and another DataArrayInt are equal. For more info see
- * \ref MEDCouplingArrayBasicsCompare.
- * \param [in] other - an instance of DataArrayInt to compare with \a this one.
- * \return bool - \a true if the values of two arrays are equal, \a false else.
- */
-bool DataArrayInt::isEqualWithoutConsideringStr(const DataArrayInt& other) const
-{
- std::string tmp;
- return _mem.isEqual(other._mem,0,tmp);
-}
-
-/*!
- * Checks if values of \a this and another DataArrayInt are equal. Comparison is
- * performed on sorted value sequences.
- * For more info see\ref MEDCouplingArrayBasicsCompare.
- * \param [in] other - an instance of DataArrayInt to compare with \a this one.
- * \return bool - \a true if the sorted values of two arrays are equal, \a false else.
- */
-bool DataArrayInt::isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const
-{
- MCAuto<DataArrayInt> a=deepCopy();
- MCAuto<DataArrayInt> b=other.deepCopy();
- a->sort();
- b->sort();
- return a->isEqualWithoutConsideringStr(*b);
-}
-
-/*!
- * This method compares content of input vector \a v and \a this.
- * If for each id in \a this v[id]==True and for all other ids id2 not in \a this v[id2]==False, true is returned.
- * For performance reasons \a this is expected to be sorted ascendingly. If not an exception will be thrown.
- *
- * \param [in] v - the vector of 'flags' to be compared with \a this.
- *
- * \throw If \a this is not sorted ascendingly.
- * \throw If \a this has not exactly one component.
- * \throw If \a this is not allocated.
- */
-bool DataArrayInt::isFittingWith(const std::vector<bool>& v) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::isFittingWith : number of components of this should be equal to one !");
- const int *w(begin()),*end2(end());
- int refVal=-std::numeric_limits<int>::max();
- int i=0;
- std::vector<bool>::const_iterator it(v.begin());
- for(;it!=v.end();it++,i++)
- {
- if(*it)
- {
- if(w!=end2)
- {
- if(*w++==i)
- {
- if(i>refVal)
- refVal=i;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::isFittingWith : At pos #" << std::distance(begin(),w-1) << " this is not sorted ascendingly !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- return false;
- }
- else
- return false;
- }
- }
- return w==end2;
-}
-
-/*!
- * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple equal to \a val
- * put True to the corresponding entry in \a vec.
- * \a vec is expected to be with the same size than the number of tuples of \a this.
- *
- * \sa DataArrayInt::switchOnTupleNotEqualTo.
- */
-void DataArrayInt::switchOnTupleEqualTo(int val, std::vector<bool>& vec) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of components of this should be equal to one !");
- int nbOfTuples(getNumberOfTuples());
- if(nbOfTuples!=(int)vec.size())
- throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of tuples of this should be equal to size of input vector of bool !");
- const int *pt(begin());
- for(int i=0;i<nbOfTuples;i++)
- if(pt[i]==val)
- vec[i]=true;
-}
-
-/*!
- * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple different from \a val
- * put True to the corresponding entry in \a vec.
- * \a vec is expected to be with the same size than the number of tuples of \a this.
- *
- * \sa DataArrayInt::switchOnTupleEqualTo.
- */
-void DataArrayInt::switchOnTupleNotEqualTo(int val, std::vector<bool>& vec) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of components of this should be equal to one !");
- int nbOfTuples(getNumberOfTuples());
- if(nbOfTuples!=(int)vec.size())
- throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of tuples of this should be equal to size of input vector of bool !");
- const int *pt(begin());
- for(int i=0;i<nbOfTuples;i++)
- if(pt[i]!=val)
- vec[i]=true;
-}
-
-/*!
- * Computes for each tuple the sum of number of components values in the tuple and return it.
- *
- * \return DataArrayInt * - the new instance of DataArrayInt 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.
- */
-DataArrayInt *DataArrayInt::sumPerTuple() const
-{
- checkAllocated();
- int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples());
- MCAuto<DataArrayInt> ret(DataArrayInt::New());
- ret->alloc(nbOfTuple,1);
- const int *src(getConstPointer());
- int *dest(ret->getPointer());
- for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
- *dest=std::accumulate(src,src+nbOfComp,0);
- return ret.retn();
-}
-
-/*!
- * Checks that \a this array is consistently **increasing** or **decreasing** in value.
- * If not an exception is thrown.
- * \param [in] increasing - if \a true, the array values should be increasing.
- * \throw If sequence of values is not strictly monotonic in agreement with \a
- * increasing arg.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If \a this is not allocated.
- */
-void DataArrayInt::checkMonotonic(bool increasing) const
-{
- if(!isMonotonic(increasing))
- {
- if (increasing)
- throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not INCREASING monotonic !");
- else
- throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not DECREASING monotonic !");
- }
-}
-
-/*!
- * Checks that \a this array is consistently **increasing** or **decreasing** in value.
- * \param [in] increasing - if \a true, array values should be increasing.
- * \return bool - \a true if values change in accordance with \a increasing arg.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If \a this is not allocated.
- */
-bool DataArrayInt::isMonotonic(bool increasing) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::isMonotonic : only supported with 'this' array with ONE component !");
- int nbOfElements=getNumberOfTuples();
- const int *ptr=getConstPointer();
- if(nbOfElements==0)
- return true;
- int ref=ptr[0];
- if(increasing)
- {
- for(int i=1;i<nbOfElements;i++)
- {
- if(ptr[i]>=ref)
- ref=ptr[i];
- else
- return false;
- }
- }
- else
- {
- for(int i=1;i<nbOfElements;i++)
- {
- if(ptr[i]<=ref)
- ref=ptr[i];
- else
- return false;
- }
- }
- return true;
-}
-
-/*!
- * This method check that array consistently INCREASING or DECREASING in value.
- */
-bool DataArrayInt::isStrictlyMonotonic(bool increasing) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::isStrictlyMonotonic : only supported with 'this' array with ONE component !");
- int nbOfElements=getNumberOfTuples();
- const int *ptr=getConstPointer();
- if(nbOfElements==0)
- return true;
- int ref=ptr[0];
- if(increasing)
- {
- for(int i=1;i<nbOfElements;i++)
- {
- if(ptr[i]>ref)
- ref=ptr[i];
- else
- return false;
- }
- }
- else
- {
- for(int i=1;i<nbOfElements;i++)
- {
- if(ptr[i]<ref)
- ref=ptr[i];
- else
- return false;
- }
- }
- return true;
-}
-
-/*!
- * This method check that array consistently INCREASING or DECREASING in value.
- */
-void DataArrayInt::checkStrictlyMonotonic(bool increasing) const
-{
- if(!isStrictlyMonotonic(increasing))
- {
- if (increasing)
- throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly INCREASING monotonic !");
- else
- throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly DECREASING monotonic !");
- }
-}
-
-/*!
- * Creates a new one-dimensional DataArrayInt of the same size as \a this and a given
- * one-dimensional arrays that must be of the same length. The result array describes
- * correspondence between \a this and \a other arrays, so that
- * <em> other.getIJ(i,0) == this->getIJ(ret->getIJ(i),0)</em>. If such a permutation is
- * not possible because some element in \a other is not in \a this, an exception is thrown.
- * \param [in] other - an array to compute permutation to.
- * \return DataArrayInt * - a new instance of DataArrayInt, which is a permutation array
- * from \a this to \a other. The caller is to delete this array using decrRef() as it is
- * no more needed.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If \a other->getNumberOfComponents() != 1.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples().
- * \throw If \a other includes a value which is not in \a this array.
- *
- * \if ENABLE_EXAMPLES
- * \ref cpp_mcdataarrayint_buildpermutationarr "Here is a C++ example".
- *
- * \ref py_mcdataarrayint_buildpermutationarr "Here is a Python example".
- * \endif
- */
-DataArrayInt *DataArrayInt::buildPermutationArr(const DataArrayInt& other) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1 || other.getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::buildPermutationArr : 'this' and 'other' have to have exactly ONE component !");
- int nbTuple=getNumberOfTuples();
- other.checkAllocated();
- if(nbTuple!=other.getNumberOfTuples())
- throw INTERP_KERNEL::Exception("DataArrayInt::buildPermutationArr : 'this' and 'other' must have the same number of tuple !");
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbTuple,1);
- ret->fillWithValue(-1);
- const int *pt=getConstPointer();
- std::map<int,int> mm;
- for(int i=0;i<nbTuple;i++)
- mm[pt[i]]=i;
- pt=other.getConstPointer();
- int *retToFill=ret->getPointer();
- for(int i=0;i<nbTuple;i++)
- {
- std::map<int,int>::const_iterator it=mm.find(pt[i]);
- if(it==mm.end())
- {
- std::ostringstream oss; oss << "DataArrayInt::buildPermutationArr : Arrays mismatch : element (" << pt[i] << ") in 'other' not findable in 'this' !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- retToFill[i]=(*it).second;
- }
- return ret.retn();
-}
-
-void DataArrayInt::aggregate(const DataArrayInt *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayInt::aggregate : null pointer !");
- if(getNumberOfComponents()!=other->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("DataArrayInt::aggregate : mismatch number of components !");
- _mem.insertAtTheEnd(other->begin(),other->end());
-}
-
-/*!
- * Returns a new DataArrayInt holding the same values as \a this array but differently
- * arranged in memory. If \a this array holds 2 components of 3 values:
- * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged
- * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$.
- * \warning Do not confuse this method with transpose()!
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- */
-DataArrayInt *DataArrayInt::fromNoInterlace() const
-{
- checkAllocated();
- if(_mem.isNull())
- throw INTERP_KERNEL::Exception("DataArrayInt::fromNoInterlace : Not defined array !");
- int *tab=_mem.fromNoInterlace(getNumberOfComponents());
- DataArrayInt *ret=DataArrayInt::New();
- ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
- return ret;
-}
-
-/*!
- * Returns a new DataArrayInt holding the same values as \a this array but differently
- * arranged in memory. If \a this array holds 2 components of 3 values:
- * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged
- * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$.
- * \warning Do not confuse this method with transpose()!
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- */
-DataArrayInt *DataArrayInt::toNoInterlace() const
-{
- checkAllocated();
- if(_mem.isNull())
- throw INTERP_KERNEL::Exception("DataArrayInt::toNoInterlace : Not defined array !");
- int *tab=_mem.toNoInterlace(getNumberOfComponents());
- DataArrayInt *ret=DataArrayInt::New();
- ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
- return ret;
-}
-
-/*!
- * Returns a copy of \a this array with values permuted as required by \a new2Old array.
- * The values are permuted so that \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of
- * tuples in the result array remains the same as in \c this one.
- * If a permutation reduction is needed, subArray() or selectByTupleId() should be used.
- * For more info on renumbering see \ref numbering.
- * \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
- * giving a previous position of i-th new value.
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- */
-DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const
-{
- checkAllocated();
- int nbTuples=getNumberOfTuples();
- int nbOfCompo=getNumberOfComponents();
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbTuples,nbOfCompo);
- ret->copyStringInfoFrom(*this);
- const int *iptr=getConstPointer();
- int *optr=ret->getPointer();
- for(int i=0;i<nbTuples;i++)
- std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+nbOfCompo*i);
- ret->copyStringInfoFrom(*this);
- return ret.retn();
-}
-
-/*!
- * Returns a shorten and permuted copy of \a this array. The new DataArrayInt is
- * of size \a newNbOfTuple and it's values are permuted as required by \a old2New array.
- * The values are permuted so that \c new[ \a old2New[ i ]] = \c old[ i ] for all
- * \a old2New[ i ] >= 0. In other words every i-th tuple in \a this array, for which
- * \a old2New[ i ] is negative, is missing from the result array.
- * For more info on renumbering see \ref numbering.
- * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
- * giving a new position for i-th old tuple and giving negative position for
- * for i-th old tuple that should be omitted.
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- */
-DataArrayInt *DataArrayInt::renumberAndReduce(const int *old2New, int newNbOfTuple) const
-{
- checkAllocated();
- int nbTuples=getNumberOfTuples();
- int nbOfCompo=getNumberOfComponents();
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(newNbOfTuple,nbOfCompo);
- const int *iptr=getConstPointer();
- int *optr=ret->getPointer();
- for(int i=0;i<nbTuples;i++)
- {
- int w=old2New[i];
- if(w>=0)
- std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
- }
- ret->copyStringInfoFrom(*this);
- return ret.retn();
-}
-
-/*!
- * Returns a shorten and permuted copy of \a this array. The new DataArrayInt is
- * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
- * \a new2OldBg array.
- * The values are permuted so that \c new[ i ] = \c old[ \a new2OldBg[ i ]].
- * This method is equivalent to renumberAndReduce() except that convention in input is
- * \c new2old and \b not \c old2new.
- * For more info on renumbering see \ref numbering.
- * \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
- * tuple index in \a this array to fill the i-th tuple in the new array.
- * \param [in] new2OldEnd - specifies the end of the permutation array that starts at
- * \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
- * \a new2OldBg <= \a pi < \a new2OldEnd.
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- */
-DataArrayInt *DataArrayInt::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
-{
- checkAllocated();
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- int nbComp=getNumberOfComponents();
- ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
- ret->copyStringInfoFrom(*this);
- int *pt=ret->getPointer();
- const int *srcPt=getConstPointer();
- int i=0;
- for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
- std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
- ret->copyStringInfoFrom(*this);
- return ret.retn();
-}
-
-/*!
- * Returns a shorten and permuted copy of \a this array. The new DataArrayInt is
- * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
- * \a new2OldBg array.
- * The values are permuted so that \c new[ i ] = \c old[ \a new2OldBg[ i ]].
- * This method is equivalent to renumberAndReduce() except that convention in input is
- * \c new2old and \b not \c old2new.
- * This method is equivalent to selectByTupleId() except that it prevents coping data
- * from behind the end of \a this array.
- * For more info on renumbering see \ref numbering.
- * \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
- * tuple index in \a this array to fill the i-th tuple in the new array.
- * \param [in] new2OldEnd - specifies the end of the permutation array that starts at
- * \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
- * \a new2OldBg <= \a pi < \a new2OldEnd.
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a new2OldEnd - \a new2OldBg > \a this->getNumberOfTuples().
- */
-DataArrayInt *DataArrayInt::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const
-{
- checkAllocated();
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- int nbComp=getNumberOfComponents();
- int oldNbOfTuples=getNumberOfTuples();
- ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
- ret->copyStringInfoFrom(*this);
- int *pt=ret->getPointer();
- const int *srcPt=getConstPointer();
- int i=0;
- for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
- if(*w>=0 && *w<oldNbOfTuples)
- std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
- else
- throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
- ret->copyStringInfoFrom(*this);
- return ret.retn();
-}
-
-/*!
- * Returns a shorten copy of \a this array. The new DataArrayInt contains every
- * (\a bg + \c i * \a step)-th tuple of \a this array located before the \a end2-th
- * tuple. Indices of the selected tuples are the same as ones returned by the Python
- * command \c range( \a bg, \a end2, \a step ).
- * This method is equivalent to selectByTupleIdSafe() except that the input array is
- * not constructed explicitly.
- * For more info on renumbering see \ref numbering.
- * \param [in] bg - index of the first tuple to copy from \a this array.
- * \param [in] end2 - index of the tuple before which the tuples to copy are located.
- * \param [in] step - index increment to get index of the next tuple to copy.
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- * \sa DataArrayInt::subArray.
- */
-DataArrayInt *DataArrayInt::selectByTupleIdSafeSlice(int bg, int end2, int step) const
-{
- checkAllocated();
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- int nbComp=getNumberOfComponents();
- int newNbOfTuples=GetNumberOfItemGivenBESRelative(bg,end2,step,"DataArrayInt::selectByTupleIdSafeSlice : ");
- ret->alloc(newNbOfTuples,nbComp);
- int *pt=ret->getPointer();
- const int *srcPt=getConstPointer()+bg*nbComp;
- for(int i=0;i<newNbOfTuples;i++,srcPt+=step*nbComp)
- std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
- ret->copyStringInfoFrom(*this);
- return ret.retn();
-}
-
-/*!
- * Returns a shorten copy of \a this array. The new DataArrayInt contains ranges
- * of tuples specified by \a ranges parameter.
- * For more info on renumbering see \ref numbering.
- * \param [in] ranges - std::vector of std::pair's each of which defines a range
- * of tuples in [\c begin,\c end) format.
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a end < \a begin.
- * \throw If \a end > \a this->getNumberOfTuples().
- * \throw If \a this is not allocated.
- */
-DataArray *DataArrayInt::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- int nbOfTuplesThis=getNumberOfTuples();
- if(ranges.empty())
- {
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(0,nbOfComp);
- ret->copyStringInfoFrom(*this);
- return ret.retn();
- }
- int ref=ranges.front().first;
- int nbOfTuples=0;
- bool isIncreasing=true;
- for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
- {
- if((*it).first<=(*it).second)
- {
- if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
- {
- nbOfTuples+=(*it).second-(*it).first;
- if(isIncreasing)
- isIncreasing=ref<=(*it).first;
- ref=(*it).second;
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
- oss << " (" << (*it).first << "," << (*it).second << ") is greater than number of tuples of this :" << nbOfTuples << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
- oss << " (" << (*it).first << "," << (*it).second << ") end is before begin !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- if(isIncreasing && nbOfTuplesThis==nbOfTuples)
- return deepCopy();
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuples,nbOfComp);
- ret->copyStringInfoFrom(*this);
- const int *src=getConstPointer();
- int *work=ret->getPointer();
- for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
- work=std::copy(src+(*it).first*nbOfComp,src+(*it).second*nbOfComp,work);
- return ret.retn();
-}
-
-/*!
- * Returns a new DataArrayInt containing a renumbering map in "Old to New" mode.
- * This map, if applied to \a this array, would make it sorted. For example, if
- * \a this array contents are [9,10,0,6,4,11,3,7] then the contents of the result array
- * are [5,6,0,3,2,7,1,4]; if this result array (\a res) is used as an argument in call
- * \a this->renumber(\a res) then the returned array contains [0,3,4,6,7,9,10,11].
- * This method is useful for renumbering (in MED file for example). For more info
- * on renumbering see \ref numbering.
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If there are equal values in \a this array.
- */
-DataArrayInt *DataArrayInt::checkAndPreparePermutation() const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::checkAndPreparePermutation : number of components must == 1 !");
- int nbTuples=getNumberOfTuples();
- const int *pt=getConstPointer();
- int *pt2=CheckAndPreparePermutation(pt,pt+nbTuples);
- DataArrayInt *ret=DataArrayInt::New();
- ret->useArray(pt2,true,C_DEALLOC,nbTuples,1);
- return ret;
-}
-
-/*!
- * This method tries to find the permutation to apply to the first input \a ids1 to obtain the same array (without considering strings informations) the second
- * input array \a ids2.
- * \a ids1 and \a ids2 are expected to be both a list of ids (both with number of components equal to one) not sorted and with values that can be negative.
- * This method will throw an exception is no such permutation array can be obtained. It is typically the case if there is some ids in \a ids1 not in \a ids2 or
- * inversely.
- * In case of success (no throw) : \c ids1->renumber(ret)->isEqual(ids2) where \a ret is the return of this method.
- *
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If either ids1 or ids2 is null not allocated or not with one components.
- *
- */
-DataArrayInt *DataArrayInt::FindPermutationFromFirstToSecond(const DataArrayInt *ids1, const DataArrayInt *ids2)
-{
- if(!ids1 || !ids2)
- throw INTERP_KERNEL::Exception("DataArrayInt::FindPermutationFromFirstToSecond : the two input arrays must be not null !");
- if(!ids1->isAllocated() || !ids2->isAllocated())
- throw INTERP_KERNEL::Exception("DataArrayInt::FindPermutationFromFirstToSecond : the two input arrays must be allocated !");
- if(ids1->getNumberOfComponents()!=1 || ids2->getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::FindPermutationFromFirstToSecond : the two input arrays have exactly one component !");
- if(ids1->getNumberOfTuples()!=ids2->getNumberOfTuples())
- {
- std::ostringstream oss; oss << "DataArrayInt::FindPermutationFromFirstToSecond : first array has " << ids1->getNumberOfTuples() << " tuples and the second one " << ids2->getNumberOfTuples() << " tuples ! No chance to find a permutation between the 2 arrays !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- MCAuto<DataArrayInt> p1(ids1->deepCopy());
- MCAuto<DataArrayInt> p2(ids2->deepCopy());
- p1->sort(true); p2->sort(true);
- if(!p1->isEqualWithoutConsideringStr(*p2))
- throw INTERP_KERNEL::Exception("DataArrayInt::FindPermutationFromFirstToSecond : the two arrays are not lying on same ids ! Impossible to find a permutation between the 2 arrays !");
- p1=ids1->checkAndPreparePermutation();
- p2=ids2->checkAndPreparePermutation();
- p2=p2->invertArrayO2N2N2O(p2->getNumberOfTuples());
- p2=p2->selectByTupleIdSafe(p1->begin(),p1->end());
- return p2.retn();
-}
-
-/*!
- * Returns two arrays describing a surjective mapping from \a this set of values (\a A)
- * onto a set of values of size \a targetNb (\a B). The surjective function is
- * \a B[ \a A[ i ]] = i. That is to say that for each \a id in [0,\a targetNb), where \a
- * targetNb < \a this->getNumberOfTuples(), there exists at least one tupleId (\a tid) so
- * that <em> this->getIJ( tid, 0 ) == id</em>. <br>
- * The first of out arrays returns indices of elements of \a this array, grouped by their
- * place in the set \a B. The second out array is the index of the first one; it shows how
- * many elements of \a A are mapped into each element of \a B. <br>
- * For more info on
- * mapping and its usage in renumbering see \ref numbering. <br>
- * \b Example:
- * - \a this: [0,3,2,3,2,2,1,2]
- * - \a targetNb: 4
- * - \a arr: [0, 6, 2,4,5,7, 1,3]
- * - \a arrI: [0,1,2,6,8]
- *
- * This result means: <br>
- * the element of \a B 0 encounters within \a A once (\a arrI[ 0+1 ] - \a arrI[ 0 ]) and
- * its index within \a A is 0 ( \a arr[ 0:1 ] == \a arr[ \a arrI[ 0 ] : \a arrI[ 0+1 ]]);<br>
- * the element of \a B 2 encounters within \a A 4 times (\a arrI[ 2+1 ] - \a arrI[ 2 ]) and
- * its indices within \a A are [2,4,5,7] ( \a arr[ 2:6 ] == \a arr[ \a arrI[ 2 ] :
- * \a arrI[ 2+1 ]]); <br> etc.
- * \param [in] targetNb - the size of the set \a B. \a targetNb must be equal or more
- * than the maximal value of \a A.
- * \param [out] arr - a new instance of DataArrayInt returning indices of
- * elements of \a this, grouped by their place in the set \a B. The caller is to delete
- * this array using decrRef() as it is no more needed.
- * \param [out] arrI - a new instance of DataArrayInt returning size of groups of equal
- * elements of \a this. The caller is to delete this array using decrRef() as it
- * is no more needed.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If any value in \a this is more or equal to \a targetNb.
- */
-void DataArrayInt::changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, DataArrayInt *&arrI) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::changeSurjectiveFormat : number of components must == 1 !");
- int nbOfTuples=getNumberOfTuples();
- MCAuto<DataArrayInt> ret(DataArrayInt::New());
- MCAuto<DataArrayInt> retI(DataArrayInt::New());
- retI->alloc(targetNb+1,1);
- const int *input=getConstPointer();
- std::vector< std::vector<int> > tmp(targetNb);
- for(int i=0;i<nbOfTuples;i++)
- {
- int tmp2=input[i];
- if(tmp2>=0 && tmp2<targetNb)
- tmp[tmp2].push_back(i);
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::changeSurjectiveFormat : At pos " << i << " presence of element " << tmp2 << " ! should be in [0," << targetNb << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- int *retIPtr=retI->getPointer();
- *retIPtr=0;
- for(std::vector< std::vector<int> >::const_iterator it1=tmp.begin();it1!=tmp.end();it1++,retIPtr++)
- retIPtr[1]=retIPtr[0]+(int)((*it1).size());
- if(nbOfTuples!=retI->getIJ(targetNb,0))
- throw INTERP_KERNEL::Exception("DataArrayInt::changeSurjectiveFormat : big problem should never happen !");
- ret->alloc(nbOfTuples,1);
- int *retPtr=ret->getPointer();
- for(std::vector< std::vector<int> >::const_iterator it1=tmp.begin();it1!=tmp.end();it1++)
- retPtr=std::copy((*it1).begin(),(*it1).end(),retPtr);
- arr=ret.retn();
- arrI=retI.retn();
-}
-
-
-/*!
- * Returns a new DataArrayInt containing a renumbering map in "Old to New" mode computed
- * from a zip representation of a surjective format (returned e.g. by
- * \ref MEDCoupling::DataArrayDouble::findCommonTuples() "DataArrayDouble::findCommonTuples()"
- * for example). The result array minimizes the permutation. <br>
- * For more info on renumbering see \ref numbering. <br>
- * \b Example: <br>
- * - \a nbOfOldTuples: 10
- * - \a arr : [0,3, 5,7,9]
- * - \a arrIBg : [0,2,5]
- * - \a newNbOfTuples: 7
- * - result array : [0,1,2,0,3,4,5,4,6,4]
- *
- * \param [in] nbOfOldTuples - number of tuples in the initial array \a arr.
- * \param [in] arr - the array of tuple indices grouped by \a arrIBg array.
- * \param [in] arrIBg - the array dividing all indices stored in \a arr into groups of
- * (indices of) equal values. Its every element (except the last one) points to
- * the first element of a group of equal values.
- * \param [in] arrIEnd - specifies the end of \a arrIBg, so that the last element of \a
- * arrIBg is \a arrIEnd[ -1 ].
- * \param [out] newNbOfTuples - number of tuples after surjection application.
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If any value of \a arr breaks condition ( 0 <= \a arr[ i ] < \a nbOfOldTuples ).
- */
-DataArrayInt *DataArrayInt::ConvertIndexArrayToO2N(int nbOfOldTuples, const int *arr, const int *arrIBg, const int *arrIEnd, int &newNbOfTuples)
-{
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfOldTuples,1);
- int *pt=ret->getPointer();
- std::fill(pt,pt+nbOfOldTuples,-1);
- int nbOfGrps=((int)std::distance(arrIBg,arrIEnd))-1;
- const int *cIPtr=arrIBg;
- for(int i=0;i<nbOfGrps;i++)
- pt[arr[cIPtr[i]]]=-(i+2);
- int newNb=0;
- for(int iNode=0;iNode<nbOfOldTuples;iNode++)
- {
- if(pt[iNode]<0)
- {
- if(pt[iNode]==-1)
- pt[iNode]=newNb++;
- else
- {
- int grpId=-(pt[iNode]+2);
- for(int j=cIPtr[grpId];j<cIPtr[grpId+1];j++)
- {
- if(arr[j]>=0 && arr[j]<nbOfOldTuples)
- pt[arr[j]]=newNb;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::ConvertIndexArrayToO2N : With element #" << j << " value is " << arr[j] << " should be in [0," << nbOfOldTuples << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- newNb++;
- }
- }
- }
- newNbOfTuples=newNb;
- return ret.retn();
-}
-
-/*!
- * Returns a new DataArrayInt containing a renumbering map in "New to Old" mode,
- * which if applied to \a this array would make it sorted ascendingly.
- * For more info on renumbering see \ref numbering. <br>
- * \b Example: <br>
- * - \a this: [2,0,1,1,0,1,2,0,1,1,0,0]
- * - result: [10,0,5,6,1,7,11,2,8,9,3,4]
- * - after applying result to \a this: [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2]
- *
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- */
-DataArrayInt *DataArrayInt::buildPermArrPerLevel() const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::buildPermArrPerLevel : number of components must == 1 !");
- int nbOfTuples=getNumberOfTuples();
- const int *pt=getConstPointer();
- std::map<int,int> m;
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbOfTuples,1);
- int *opt=ret->getPointer();
- for(int i=0;i<nbOfTuples;i++,pt++,opt++)
- {
- int val=*pt;
- std::map<int,int>::iterator it=m.find(val);
- if(it!=m.end())
- {
- *opt=(*it).second;
- (*it).second++;
- }
- else
- {
- *opt=0;
- m.insert(std::pair<int,int>(val,1));
- }
- }
- int sum=0;
- for(std::map<int,int>::iterator it=m.begin();it!=m.end();it++)
- {
- int vt=(*it).second;
- (*it).second=sum;
- sum+=vt;
- }
- pt=getConstPointer();
- opt=ret->getPointer();
- for(int i=0;i<nbOfTuples;i++,pt++,opt++)
- *opt+=m[*pt];
- //
- return ret.retn();
-}
-
-/*!
- * Checks if contents of \a this array are equal to that of an array filled with
- * iota(). This method is particularly useful for DataArrayInt instances that represent
- * a renumbering array to check the real need in renumbering. This method checks than \a this can be considered as an identity function
- * of a set having \a sizeExpected elements into itself.
- *
- * \param [in] sizeExpected - The number of elements expected.
- * \return bool - \a true if \a this array contents == \a range( \a this->getNumberOfTuples())
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- */
-bool DataArrayInt::isIota(int sizeExpected) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- return false;
- int nbOfTuples(getNumberOfTuples());
- if(nbOfTuples!=sizeExpected)
- return false;
- const int *pt=getConstPointer();
- for(int i=0;i<nbOfTuples;i++,pt++)
- if(*pt!=i)
- return false;
- return true;
-}
-
-/*!
- * Checks if all values in \a this array are equal to \a val.
- * \param [in] val - value to check equality of array values to.
- * \return bool - \a true if all values are \a val.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1
- */
-bool DataArrayInt::isUniform(int val) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::isUniform : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
- int nbOfTuples=getNumberOfTuples();
- const int *w=getConstPointer();
- const int *end2=w+nbOfTuples;
- for(;w!=end2;w++)
- if(*w!=val)
- return false;
- return true;
-}
-
-/*!
- * Checks if all values in \a this array are unique.
- * \return bool - \a true if condition above is true
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1
- */
-bool DataArrayInt::hasUniqueValues() const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::hasOnlyUniqueValues: must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
- int nbOfTuples(getNumberOfTuples());
- std::set<int> s(begin(),end()); // in C++11, should use unordered_set (O(1) complexity)
- if (s.size() != nbOfTuples)
- return false;
- return true;
-}
-
-/*!
- * Creates a new DataArrayDouble and assigns all (textual and numerical) data of \a this
- * array to the new one.
- * \return DataArrayDouble * - the new instance of DataArrayInt.
- */
-DataArrayDouble *DataArrayInt::convertToDblArr() const
-{
- checkAllocated();
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(getNumberOfTuples(),getNumberOfComponents());
- std::size_t nbOfVals=getNbOfElems();
- const int *src=getConstPointer();
- double *dest=ret->getPointer();
- std::copy(src,src+nbOfVals,dest);
- ret->copyStringInfoFrom(*this);
- return ret;
-}
-
-/*!
- * Returns a shorten copy of \a this array. The new DataArrayInt contains all
- * tuples starting from the \a tupleIdBg-th tuple and including all tuples located before
- * the \a tupleIdEnd-th one. This methods has a similar behavior as std::string::substr().
- * This method is a specialization of selectByTupleIdSafeSlice().
- * \param [in] tupleIdBg - index of the first tuple to copy from \a this array.
- * \param [in] tupleIdEnd - index of the tuple before which the tuples to copy are located.
- * If \a tupleIdEnd == -1, all the tuples till the end of \a this array are copied.
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a tupleIdBg < 0.
- * \throw If \a tupleIdBg > \a this->getNumberOfTuples().
- \throw If \a tupleIdEnd != -1 && \a tupleIdEnd < \a this->getNumberOfTuples().
- * \sa DataArrayInt::selectByTupleIdSafeSlice
- */
-DataArrayInt *DataArrayInt::subArray(int tupleIdBg, int tupleIdEnd) const
-{
- checkAllocated();
- int nbt=getNumberOfTuples();
- if(tupleIdBg<0)
- throw INTERP_KERNEL::Exception("DataArrayInt::subArray : The tupleIdBg parameter must be greater than 0 !");
- if(tupleIdBg>nbt)
- throw INTERP_KERNEL::Exception("DataArrayInt::subArray : The tupleIdBg parameter is greater than number of tuples !");
- int trueEnd=tupleIdEnd;
- if(tupleIdEnd!=-1)
- {
- if(tupleIdEnd>nbt)
- throw INTERP_KERNEL::Exception("DataArrayInt::subArray : The tupleIdBg parameter is greater or equal than number of tuples !");
- }
- else
- trueEnd=nbt;
- int nbComp=getNumberOfComponents();
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(trueEnd-tupleIdBg,nbComp);
- ret->copyStringInfoFrom(*this);
- std::copy(getConstPointer()+tupleIdBg*nbComp,getConstPointer()+trueEnd*nbComp,ret->getPointer());
- return ret.retn();
-}
-
-/*!
- * Changes the number of components within \a this array so that its raw data **does
- * not** change, instead splitting this data into tuples changes.
- * \warning This method erases all (name and unit) component info set before!
- * \param [in] newNbOfComp - number of components for \a this array to have.
- * \throw If \a this is not allocated
- * \throw If getNbOfElems() % \a newNbOfCompo != 0.
- * \throw If \a newNbOfCompo is lower than 1.
- * \throw If the rearrange method would lead to a number of tuples higher than 2147483647 (maximal capacity of int32 !).
- * \warning This method erases all (name and unit) component info set before!
- */
-void DataArrayInt::rearrange(int newNbOfCompo)
-{
- checkAllocated();
- if(newNbOfCompo<1)
- throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : input newNbOfCompo must be > 0 !");
- std::size_t nbOfElems=getNbOfElems();
- if(nbOfElems%newNbOfCompo!=0)
- throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : nbOfElems%newNbOfCompo!=0 !");
- if(nbOfElems/newNbOfCompo>(std::size_t)std::numeric_limits<int>::max())
- throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : the rearrangement leads to too high number of tuples (> 2147483647) !");
- _info_on_compo.clear();
- _info_on_compo.resize(newNbOfCompo);
- declareAsNew();
-}
-
-/*!
- * Changes the number of components within \a this array to be equal to its number
- * of tuples, and inversely its number of tuples to become equal to its number of
- * components. So that its raw data **does not** change, instead splitting this
- * data into tuples changes.
- * \warning This method erases all (name and unit) component info set before!
- * \warning Do not confuse this method with fromNoInterlace() and toNoInterlace()!
- * \throw If \a this is not allocated.
- * \sa rearrange()
- */
-void DataArrayInt::transpose()
-{
- checkAllocated();
- int nbOfTuples=getNumberOfTuples();
- rearrange(nbOfTuples);
-}
-
-/*!
- * Returns a shorten or extended copy of \a this array. If \a newNbOfComp is less
- * than \a this->getNumberOfComponents() then the result array is shorten as each tuple
- * is truncated to have \a newNbOfComp components, keeping first components. If \a
- * newNbOfComp is more than \a this->getNumberOfComponents() then the result array is
- * expanded as each tuple is populated with \a dftValue to have \a newNbOfComp
- * components.
- * \param [in] newNbOfComp - number of components for the new array to have.
- * \param [in] dftValue - value assigned to new values added to the new array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- */
-DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) const
-{
- checkAllocated();
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(getNumberOfTuples(),newNbOfComp);
- const int *oldc=getConstPointer();
- int *nc=ret->getPointer();
- int nbOfTuples=getNumberOfTuples();
- int oldNbOfComp=getNumberOfComponents();
- int dim=std::min(oldNbOfComp,newNbOfComp);
- for(int i=0;i<nbOfTuples;i++)
- {
- int j=0;
- for(;j<dim;j++)
- nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
- for(;j<newNbOfComp;j++)
- nc[newNbOfComp*i+j]=dftValue;
- }
- ret->setName(getName());
- for(int i=0;i<dim;i++)
- ret->setInfoOnComponent(i,getInfoOnComponent(i));
- ret->setName(getName());
- return ret.retn();
-}
-
-/*!
- * Returns a copy of \a this array composed of selected components.
- * The new DataArrayInt has the same number of tuples but includes components
- * specified by \a compoIds parameter. So that getNbOfElems() of the result array
- * can be either less, same or more than \a this->getNbOfElems().
- * \param [in] compoIds - sequence of zero based indices of components to include
- * into the new array.
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- * \throw If a component index (\a i) is not valid:
- * \a i < 0 || \a i >= \a this->getNumberOfComponents().
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_keepselectedcomponents "Here is a Python example".
- * \endif
- */
-DataArrayInt *DataArrayInt::keepSelectedComponents(const std::vector<int>& compoIds) const
-{
- checkAllocated();
- MCAuto<DataArrayInt> ret(DataArrayInt::New());
- int newNbOfCompo=(int)compoIds.size();
- int oldNbOfCompo=getNumberOfComponents();
- for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
- DataArray::CheckValueInRange(oldNbOfCompo,(*it),"keepSelectedComponents invalid requested component");
- int nbOfTuples=getNumberOfTuples();
- ret->alloc(nbOfTuples,newNbOfCompo);
- ret->copyPartOfStringInfoFrom(*this,compoIds);
- const int *oldc=getConstPointer();
- int *nc=ret->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- for(int j=0;j<newNbOfCompo;j++,nc++)
- *nc=oldc[i*oldNbOfCompo+compoIds[j]];
- return ret.retn();
-}
-
-/*!
- * Appends components of another array to components of \a this one, tuple by tuple.
- * So that the number of tuples of \a this array remains the same and the number of
- * components increases.
- * \param [in] other - the DataArrayInt to append to \a this one.
- * \throw If \a this is not allocated.
- * \throw If \a this and \a other arrays have different number of tuples.
- *
- * \if ENABLE_EXAMPLES
- * \ref cpp_mcdataarrayint_meldwith "Here is a C++ example".
- *
- * \ref py_mcdataarrayint_meldwith "Here is a Python example".
- * \endif
- */
-void DataArrayInt::meldWith(const DataArrayInt *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : DataArrayInt pointer in input is NULL !");
- checkAllocated();
- other->checkAllocated();
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples!=other->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : mismatch of number of tuples !");
- int nbOfComp1=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- int *newArr=(int *)malloc(nbOfTuples*(nbOfComp1+nbOfComp2)*sizeof(int));
- int *w=newArr;
- const int *inp1=getConstPointer();
- const int *inp2=other->getConstPointer();
- for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
- {
- w=std::copy(inp1,inp1+nbOfComp1,w);
- w=std::copy(inp2,inp2+nbOfComp2,w);
- }
- useArray(newArr,true,C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
- std::vector<int> compIds(nbOfComp2);
- for(int i=0;i<nbOfComp2;i++)
- compIds[i]=nbOfComp1+i;
- copyPartOfStringInfoFrom2(compIds,*other);
-}
-
-/*!
- * Copy all components in a specified order from another DataArrayInt.
- * The specified components become the first ones in \a this array.
- * Both numerical and textual data is copied. The number of tuples in \a this and
- * the other array can be different.
- * \param [in] a - the array to copy data from.
- * \param [in] compoIds - sequence of zero based indices of components, data of which is
- * to be copied.
- * \throw If \a a is NULL.
- * \throw If \a compoIds.size() != \a a->getNumberOfComponents().
- * \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setselectedcomponents "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setSelectedComponents(const DataArrayInt *a, const std::vector<int>& compoIds)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayInt::setSelectedComponents : input DataArrayInt is NULL !");
- checkAllocated();
- a->checkAllocated();
- copyPartOfStringInfoFrom2(compoIds,*a);
- std::size_t partOfCompoSz=compoIds.size();
- int nbOfCompo=getNumberOfComponents();
- int nbOfTuples=std::min(getNumberOfTuples(),a->getNumberOfTuples());
- const int *ac=a->getConstPointer();
- int *nc=getPointer();
- for(int i=0;i<nbOfTuples;i++)
- for(std::size_t j=0;j<partOfCompoSz;j++,ac++)
- nc[nbOfCompo*i+compoIds[j]]=*ac;
-}
-
-/*!
- * Copy all values from another DataArrayInt into specified tuples and components
- * of \a this array. Textual data is not copied.
- * The tree parameters defining set of indices of tuples and components are similar to
- * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
- * \param [in] a - the array to copy values from.
- * \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
- * \param [in] endTuples - index of the tuple before which the tuples to assign to
- * are located.
- * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
- * \param [in] bgComp - index of the first component of \a this array to assign values to.
- * \param [in] endComp - index of the component before which the components to assign
- * to are located.
- * \param [in] stepComp - index increment to get index of the next component to assign to.
- * \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents()
- * must be equal to the number of columns to assign to, else an
- * exception is thrown; if \a false, then it is only required that \a
- * a->getNbOfElems() equals to number of values to assign to (this condition
- * must be respected even if \a strictCompoCompare is \a true). The number of
- * values to assign to is given by following Python expression:
- * \a nbTargetValues =
- * \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
- * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a this is not allocated.
- * \throw If parameters specifying tuples and components to assign to do not give a
- * non-empty range of increasing indices.
- * \throw If \a a->getNbOfElems() != \a nbTargetValues.
- * \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
- * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setpartofvalues1 "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setPartOfValues1(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues1 : DataArrayInt pointer in input is NULL !");
- const char msg[]="DataArrayInt::setPartOfValues1";
- checkAllocated();
- a->checkAllocated();
- int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
- int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
- DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
- bool assignTech=true;
- if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
- {
- if(strictCompoCompare)
- a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
- }
- else
- {
- a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
- assignTech=false;
- }
- int *pt=getPointer()+bgTuples*nbComp+bgComp;
- const int *srcPt=a->getConstPointer();
- if(assignTech)
- {
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- for(int j=0;j<newNbOfComp;j++,srcPt++)
- pt[j*stepComp]=*srcPt;
- }
- else
- {
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- {
- const int *srcPt2=srcPt;
- for(int j=0;j<newNbOfComp;j++,srcPt2++)
- pt[j*stepComp]=*srcPt2;
- }
- }
-}
-
-/*!
- * Assign a given value to values at specified tuples and components of \a this array.
- * The tree parameters defining set of indices of tuples and components are similar to
- * the tree parameters of the Python function \c range(\c start,\c stop,\c step)..
- * \param [in] a - the value to assign.
- * \param [in] bgTuples - index of the first tuple of \a this array to assign to.
- * \param [in] endTuples - index of the tuple before which the tuples to assign to
- * are located.
- * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
- * \param [in] bgComp - index of the first component of \a this array to assign to.
- * \param [in] endComp - index of the component before which the components to assign
- * to are located.
- * \param [in] stepComp - index increment to get index of the next component to assign to.
- * \throw If \a this is not allocated.
- * \throw If parameters specifying tuples and components to assign to, do not give a
- * non-empty range of increasing indices or indices are out of a valid range
- * for \c this array.
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setpartofvaluessimple1 "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setPartOfValuesSimple1(int a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp)
-{
- const char msg[]="DataArrayInt::setPartOfValuesSimple1";
- checkAllocated();
- int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
- int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
- DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
- int *pt=getPointer()+bgTuples*nbComp+bgComp;
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- for(int j=0;j<newNbOfComp;j++)
- pt[j*stepComp]=a;
-}
-
-
-/*!
- * Copy all values from another DataArrayInt (\a a) into specified tuples and
- * components of \a this array. Textual data is not copied.
- * The tuples and components to assign to are defined by C arrays of indices.
- * There are two *modes of usage*:
- * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
- * of \a a is assigned to its own location within \a this array.
- * - If \a a includes one tuple, then all values of \a a are assigned to the specified
- * components of every specified tuple of \a this array. In this mode it is required
- * that \a a->getNumberOfComponents() equals to the number of specified components.
- *
- * \param [in] a - the array to copy values from.
- * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
- * assign values of \a a to.
- * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
- * pointer to a tuple index <em>(pi)</em> varies as this:
- * \a bgTuples <= \a pi < \a endTuples.
- * \param [in] bgComp - pointer to an array of component indices of \a this array to
- * assign values of \a a to.
- * \param [in] endComp - specifies the end of the array \a bgTuples, so that
- * pointer to a component index <em>(pi)</em> varies as this:
- * \a bgComp <= \a pi < \a endComp.
- * \param [in] strictCompoCompare - this parameter is checked only if the
- * *mode of usage* is the first; if it is \a true (default),
- * then \a a->getNumberOfComponents() must be equal
- * to the number of specified columns, else this is not required.
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a this is not allocated.
- * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
- * out of a valid range for \a this array.
- * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
- * if <em> a->getNumberOfComponents() != (endComp - bgComp) </em>.
- * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
- * <em> a->getNumberOfComponents() != (endComp - bgComp)</em>.
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setpartofvalues2 "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setPartOfValues2(const DataArrayInt *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues2 : DataArrayInt pointer in input is NULL !");
- const char msg[]="DataArrayInt::setPartOfValues2";
- checkAllocated();
- a->checkAllocated();
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- for(const int *z=bgComp;z!=endComp;z++)
- DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
- int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
- int newNbOfComp=(int)std::distance(bgComp,endComp);
- bool assignTech=true;
- if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
- {
- if(strictCompoCompare)
- a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
- }
- else
- {
- a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
- assignTech=false;
- }
- int *pt=getPointer();
- const int *srcPt=a->getConstPointer();
- if(assignTech)
- {
- for(const int *w=bgTuples;w!=endTuples;w++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- for(const int *z=bgComp;z!=endComp;z++,srcPt++)
- {
- pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt;
- }
- }
- }
- else
- {
- for(const int *w=bgTuples;w!=endTuples;w++)
- {
- const int *srcPt2=srcPt;
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
- {
- pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt2;
- }
- }
- }
-}
-
-/*!
- * Assign a given value to values at specified tuples and components of \a this array.
- * The tuples and components to assign to are defined by C arrays of indices.
- * \param [in] a - the value to assign.
- * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
- * assign \a a to.
- * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
- * pointer to a tuple index (\a pi) varies as this:
- * \a bgTuples <= \a pi < \a endTuples.
- * \param [in] bgComp - pointer to an array of component indices of \a this array to
- * assign \a a to.
- * \param [in] endComp - specifies the end of the array \a bgTuples, so that
- * pointer to a component index (\a pi) varies as this:
- * \a bgComp <= \a pi < \a endComp.
- * \throw If \a this is not allocated.
- * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
- * out of a valid range for \a this array.
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setpartofvaluessimple2 "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setPartOfValuesSimple2(int a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp)
-{
- checkAllocated();
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- for(const int *z=bgComp;z!=endComp;z++)
- DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
- int *pt=getPointer();
- for(const int *w=bgTuples;w!=endTuples;w++)
- for(const int *z=bgComp;z!=endComp;z++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- pt[(std::size_t)(*w)*nbComp+(*z)]=a;
- }
-}
-
-/*!
- * Copy all values from another DataArrayInt (\a a) into specified tuples and
- * components of \a this array. Textual data is not copied.
- * The tuples to assign to are defined by a C array of indices.
- * The components to assign to are defined by three values similar to parameters of
- * the Python function \c range(\c start,\c stop,\c step).
- * There are two *modes of usage*:
- * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
- * of \a a is assigned to its own location within \a this array.
- * - If \a a includes one tuple, then all values of \a a are assigned to the specified
- * components of every specified tuple of \a this array. In this mode it is required
- * that \a a->getNumberOfComponents() equals to the number of specified components.
- *
- * \param [in] a - the array to copy values from.
- * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
- * assign values of \a a to.
- * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
- * pointer to a tuple index <em>(pi)</em> varies as this:
- * \a bgTuples <= \a pi < \a endTuples.
- * \param [in] bgComp - index of the first component of \a this array to assign to.
- * \param [in] endComp - index of the component before which the components to assign
- * to are located.
- * \param [in] stepComp - index increment to get index of the next component to assign to.
- * \param [in] strictCompoCompare - this parameter is checked only in the first
- * *mode of usage*; if \a strictCompoCompare is \a true (default),
- * then \a a->getNumberOfComponents() must be equal
- * to the number of specified columns, else this is not required.
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a this is not allocated.
- * \throw If any index of tuple given by \a bgTuples is out of a valid range for
- * \a this array.
- * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
- * if <em> a->getNumberOfComponents()</em> is unequal to the number of components
- * defined by <em>(bgComp,endComp,stepComp)</em>.
- * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
- * <em> a->getNumberOfComponents()</em> is unequal to the number of components
- * defined by <em>(bgComp,endComp,stepComp)</em>.
- * \throw If parameters specifying components to assign to, do not give a
- * non-empty range of increasing indices or indices are out of a valid range
- * for \c this array.
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setpartofvalues3 "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setPartOfValues3(const DataArrayInt *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues3 : DataArrayInt pointer in input is NULL !");
- const char msg[]="DataArrayInt::setPartOfValues3";
- checkAllocated();
- a->checkAllocated();
- int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
- int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
- bool assignTech=true;
- if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
- {
- if(strictCompoCompare)
- a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
- }
- else
- {
- a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
- assignTech=false;
- }
- int *pt=getPointer()+bgComp;
- const int *srcPt=a->getConstPointer();
- if(assignTech)
- {
- for(const int *w=bgTuples;w!=endTuples;w++)
- for(int j=0;j<newNbOfComp;j++,srcPt++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt;
- }
- }
- else
- {
- for(const int *w=bgTuples;w!=endTuples;w++)
- {
- const int *srcPt2=srcPt;
- for(int j=0;j<newNbOfComp;j++,srcPt2++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt2;
- }
- }
- }
-}
-
-/*!
- * Assign a given value to values at specified tuples and components of \a this array.
- * The tuples to assign to are defined by a C array of indices.
- * The components to assign to are defined by three values similar to parameters of
- * the Python function \c range(\c start,\c stop,\c step).
- * \param [in] a - the value to assign.
- * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
- * assign \a a to.
- * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
- * pointer to a tuple index <em>(pi)</em> varies as this:
- * \a bgTuples <= \a pi < \a endTuples.
- * \param [in] bgComp - index of the first component of \a this array to assign to.
- * \param [in] endComp - index of the component before which the components to assign
- * to are located.
- * \param [in] stepComp - index increment to get index of the next component to assign to.
- * \throw If \a this is not allocated.
- * \throw If any index of tuple given by \a bgTuples is out of a valid range for
- * \a this array.
- * \throw If parameters specifying components to assign to, do not give a
- * non-empty range of increasing indices or indices are out of a valid range
- * for \c this array.
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setpartofvaluessimple3 "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setPartOfValuesSimple3(int a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp)
-{
- const char msg[]="DataArrayInt::setPartOfValuesSimple3";
- checkAllocated();
- int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
- int *pt=getPointer()+bgComp;
- for(const int *w=bgTuples;w!=endTuples;w++)
- for(int j=0;j<newNbOfComp;j++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- pt[(std::size_t)(*w)*nbComp+j*stepComp]=a;
- }
-}
-
-void DataArrayInt::setPartOfValues4(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues4 : input DataArrayInt is NULL !");
- const char msg[]="DataArrayInt::setPartOfValues4";
- checkAllocated();
- a->checkAllocated();
- int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
- int newNbOfComp=(int)std::distance(bgComp,endComp);
- int nbComp=getNumberOfComponents();
- for(const int *z=bgComp;z!=endComp;z++)
- DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
- bool assignTech=true;
- if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
- {
- if(strictCompoCompare)
- a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
- }
- else
- {
- a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
- assignTech=false;
- }
- const int *srcPt=a->getConstPointer();
- int *pt=getPointer()+bgTuples*nbComp;
- if(assignTech)
- {
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- for(const int *z=bgComp;z!=endComp;z++,srcPt++)
- pt[*z]=*srcPt;
- }
- else
- {
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- {
- const int *srcPt2=srcPt;
- for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
- pt[*z]=*srcPt2;
- }
- }
-}
-
-void DataArrayInt::setPartOfValuesSimple4(int a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp)
-{
- const char msg[]="DataArrayInt::setPartOfValuesSimple4";
- checkAllocated();
- int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
- int nbComp=getNumberOfComponents();
- for(const int *z=bgComp;z!=endComp;z++)
- DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
- int *pt=getPointer()+bgTuples*nbComp;
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- for(const int *z=bgComp;z!=endComp;z++)
- pt[*z]=a;
-}
-
-/*!
- * Copy some tuples from another DataArrayInt into specified tuples
- * of \a this array. Textual data is not copied. Both arrays must have equal number of
- * components.
- * Both the tuples to assign and the tuples to assign to are defined by a DataArrayInt.
- * All components of selected tuples are copied.
- * \param [in] a - the array to copy values from.
- * \param [in] tuplesSelec - the array specifying both source tuples of \a a and
- * target tuples of \a this. \a tuplesSelec has two components, and the
- * first component specifies index of the source tuple and the second
- * one specifies index of the target tuple.
- * \throw If \a this is not allocated.
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a tuplesSelec is NULL.
- * \throw If \a tuplesSelec is not allocated.
- * \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
- * \throw If \a tuplesSelec->getNumberOfComponents() != 2.
- * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
- * the corresponding (\a this or \a a) array.
- */
-void DataArrayInt::setPartOfValuesAdv(const DataArrayInt *a, const DataArrayInt *tuplesSelec)
-{
- if(!a || !tuplesSelec)
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : DataArrayInt pointer in input is NULL !");
- checkAllocated();
- a->checkAllocated();
- tuplesSelec->checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=a->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : This and a do not have the same number of components !");
- if(tuplesSelec->getNumberOfComponents()!=2)
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
- int thisNt=getNumberOfTuples();
- int aNt=a->getNumberOfTuples();
- int *valsToSet=getPointer();
- const int *valsSrc=a->getConstPointer();
- for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
- {
- if(tuple[1]>=0 && tuple[1]<aNt)
- {
- if(tuple[0]>=0 && tuple[0]<thisNt)
- std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
- oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
- oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
-}
-
-/*!
- * Copy some tuples from another DataArrayInt (\a aBase) into contiguous tuples
- * of \a this array. Textual data is not copied. Both arrays must have equal number of
- * components.
- * The tuples to assign to are defined by index of the first tuple, and
- * their number is defined by \a tuplesSelec->getNumberOfTuples().
- * The tuples to copy are defined by values of a DataArrayInt.
- * All components of selected tuples are copied.
- * \param [in] tupleIdStart - index of the first tuple of \a this array to assign
- * values to.
- * \param [in] aBase - the array to copy values from.
- * \param [in] tuplesSelec - the array specifying tuples of \a aBase to copy.
- * \throw If \a this is not allocated.
- * \throw If \a aBase is NULL.
- * \throw If \a aBase is not allocated.
- * \throw If \a tuplesSelec is NULL.
- * \throw If \a tuplesSelec is not allocated.
- * \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
- * \throw If \a tuplesSelec->getNumberOfComponents() != 1.
- * \throw If <em>tupleIdStart + tuplesSelec->getNumberOfTuples() > this->getNumberOfTuples().</em>
- * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
- * \a aBase array.
- */
-void DataArrayInt::setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt *tuplesSelec)
-{
- if(!aBase || !tuplesSelec)
- throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : input DataArray is NULL !");
- const DataArrayInt *a=dynamic_cast<const DataArrayInt *>(aBase);
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : input DataArray aBase is not a DataArrayInt !");
- checkAllocated();
- a->checkAllocated();
- tuplesSelec->checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=a->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : This and a do not have the same number of components !");
- if(tuplesSelec->getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : Expecting to have a tuple selector DataArrayInt instance with exactly 1 component !");
- int thisNt=getNumberOfTuples();
- int aNt=a->getNumberOfTuples();
- int nbOfTupleToWrite=tuplesSelec->getNumberOfTuples();
- int *valsToSet=getPointer()+tupleIdStart*nbOfComp;
- if(tupleIdStart+nbOfTupleToWrite>thisNt)
- throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : invalid number range of values to write !");
- const int *valsSrc=a->getConstPointer();
- for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple++,valsToSet+=nbOfComp)
- {
- if(*tuple>=0 && *tuple<aNt)
- {
- std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::setContigPartOfSelectedValues : Tuple #" << std::distance(tuplesSelec->begin(),tuple);
- oss << " of 'tuplesSelec' request of tuple id #" << *tuple << " in 'a' ! It should be in [0," << aNt << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
-}
-
-/*!
- * Copy some tuples from another DataArrayInt (\a aBase) into contiguous tuples
- * of \a this array. Textual data is not copied. Both arrays must have equal number of
- * components.
- * The tuples to copy are defined by three values similar to parameters of
- * the Python function \c range(\c start,\c stop,\c step).
- * The tuples to assign to are defined by index of the first tuple, and
- * their number is defined by number of tuples to copy.
- * All components of selected tuples are copied.
- * \param [in] tupleIdStart - index of the first tuple of \a this array to assign
- * values to.
- * \param [in] aBase - the array to copy values from.
- * \param [in] bg - index of the first tuple to copy of the array \a aBase.
- * \param [in] end2 - index of the tuple of \a aBase before which the tuples to copy
- * are located.
- * \param [in] step - index increment to get index of the next tuple to copy.
- * \throw If \a this is not allocated.
- * \throw If \a aBase is NULL.
- * \throw If \a aBase is not allocated.
- * \throw If <em>this->getNumberOfComponents() != aBase->getNumberOfComponents()</em>.
- * \throw If <em>tupleIdStart + len(range(bg,end2,step)) > this->getNumberOfTuples().</em>
- * \throw If parameters specifying tuples to copy, do not give a
- * non-empty range of increasing indices or indices are out of a valid range
- * for the array \a aBase.
- */
-void DataArrayInt::setContigPartOfSelectedValuesSlice(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step)
-{
- if(!aBase)
- throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValuesSlice : input DataArray is NULL !");
- const DataArrayInt *a=dynamic_cast<const DataArrayInt *>(aBase);
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValuesSlice : input DataArray aBase is not a DataArrayInt !");
- checkAllocated();
- a->checkAllocated();
- int nbOfComp=getNumberOfComponents();
- const char msg[]="DataArrayInt::setContigPartOfSelectedValuesSlice";
- int nbOfTupleToWrite=DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg);
- if(nbOfComp!=a->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValuesSlice : This and a do not have the same number of components !");
- int thisNt=getNumberOfTuples();
- int aNt=a->getNumberOfTuples();
- int *valsToSet=getPointer()+tupleIdStart*nbOfComp;
- if(tupleIdStart+nbOfTupleToWrite>thisNt)
- throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValuesSlice : invalid number range of values to write !");
- if(end2>aNt)
- throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValuesSlice : invalid range of values to read !");
- const int *valsSrc=a->getConstPointer()+bg*nbOfComp;
- for(int i=0;i<nbOfTupleToWrite;i++,valsToSet+=nbOfComp,valsSrc+=step*nbOfComp)
- {
- std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
- }
-}
-
-/*!
- * Returns the first value of \a this.
- * \return int - the last value of \a this array.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If \a this->getNumberOfTuples() < 1.
- */
-int DataArrayInt::front() const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::front : number of components not equal to one !");
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples<1)
- throw INTERP_KERNEL::Exception("DataArrayInt::front : number of tuples must be >= 1 !");
- return *(getConstPointer());
-}
-
-/*!
- * Returns the last value of \a this.
- * \return int - the last value of \a this array.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If \a this->getNumberOfTuples() < 1.
- */
-int DataArrayInt::back() const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::back : number of components not equal to one !");
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples<1)
- throw INTERP_KERNEL::Exception("DataArrayInt::back : number of tuples must be >= 1 !");
- return *(getConstPointer()+nbOfTuples-1);
-}
-
-/*!
- * Assign pointer to one array to a pointer to another appay. Reference counter of
- * \a arrayToSet is incremented / decremented.
- * \param [in] newArray - the pointer to array to assign to \a arrayToSet.
- * \param [in,out] arrayToSet - the pointer to array to assign to.
- */
-void DataArrayInt::SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet)
-{
- if(newArray!=arrayToSet)
- {
- if(arrayToSet)
- arrayToSet->decrRef();
- arrayToSet=newArray;
- if(arrayToSet)
- arrayToSet->incrRef();
- }
-}
-
-DataArrayIntIterator *DataArrayInt::iterator()
-{
- return new DataArrayIntIterator(this);
-}
-
-/*!
- * Creates a new DataArrayInt containing IDs (indices) of tuples holding value equal to a
- * given one. The ids are sorted in the ascending order.
- * \param [in] val - the value to find within \a this.
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \sa DataArrayInt::findIdsEqualTuple
- */
-DataArrayInt *DataArrayInt::findIdsEqual(int val) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsEqual : the array must have only one component, you can call 'rearrange' method before !");
- const int *cptr(getConstPointer());
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- int nbOfTuples=getNumberOfTuples();
- for(int i=0;i<nbOfTuples;i++,cptr++)
- if(*cptr==val)
- ret->pushBackSilent(i);
- return ret.retn();
-}
-
-/*!
- * Creates a new DataArrayInt containing IDs (indices) of tuples holding value \b not
- * equal to a given one.
- * \param [in] val - the value to ignore within \a this.
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- */
-DataArrayInt *DataArrayInt::findIdsNotEqual(int val) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsNotEqual : the array must have only one component, you can call 'rearrange' method before !");
- const int *cptr(getConstPointer());
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- int nbOfTuples=getNumberOfTuples();
- for(int i=0;i<nbOfTuples;i++,cptr++)
- if(*cptr!=val)
- ret->pushBackSilent(i);
- return ret.retn();
-}
-
-/*!
- * Creates a new DataArrayInt containing IDs (indices) of tuples holding tuple equal to those defined by [ \a tupleBg , \a tupleEnd )
- * This method is an extension of DataArrayInt::findIdsEqual method.
- *
- * \param [in] tupleBg - the begin (included) of the input tuple to find within \a this.
- * \param [in] tupleEnd - the end (excluded) of the input tuple to find within \a this.
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != std::distance(tupleBg,tupleEnd).
- * \throw If \a this->getNumberOfComponents() is equal to 0.
- * \sa DataArrayInt::findIdsEqual
- */
-DataArrayInt *DataArrayInt::findIdsEqualTuple(const int *tupleBg, const int *tupleEnd) const
-{
- std::size_t nbOfCompoExp(std::distance(tupleBg,tupleEnd));
- checkAllocated();
- if(getNumberOfComponents()!=(int)nbOfCompoExp)
- {
- std::ostringstream oss; oss << "DataArrayInt::findIdsEqualTuple : mismatch of number of components. Input tuple has " << nbOfCompoExp << " whereas this array has " << getNumberOfComponents() << " components !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- if(nbOfCompoExp==0)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsEqualTuple : number of components should be > 0 !");
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- const int *bg(begin()),*end2(end()),*work(begin());
- while(work!=end2)
- {
- work=std::search(work,end2,tupleBg,tupleEnd);
- if(work!=end2)
- {
- std::size_t pos(std::distance(bg,work));
- if(pos%nbOfCompoExp==0)
- ret->pushBackSilent(pos/nbOfCompoExp);
- work++;
- }
- }
- return ret.retn();
-}
-
-/*!
- * Assigns \a newValue to all elements holding \a oldValue within \a this
- * one-dimensional array.
- * \param [in] oldValue - the value to replace.
- * \param [in] newValue - the value to assign.
- * \return int - number of replacements performed.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- */
-int DataArrayInt::changeValue(int oldValue, int newValue)
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::changeValue : the array must have only one component, you can call 'rearrange' method before !");
- if(oldValue==newValue)
- return 0;
- int *start(getPointer()),*end2(start+getNbOfElems());
- int ret(0);
- for(int *val=start;val!=end2;val++)
- {
- if(*val==oldValue)
- {
- *val=newValue;
- ret++;
- }
- }
- if(ret>0)
- declareAsNew();
- return ret;
-}
-
-/*!
- * Creates a new DataArrayInt containing IDs (indices) of tuples holding value equal to
- * one of given values.
- * \param [in] valsBg - an array of values to find within \a this array.
- * \param [in] valsEnd - specifies the end of the array \a valsBg, so that
- * the last value of \a valsBg is \a valsEnd[ -1 ].
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If \a this->getNumberOfComponents() != 1.
- */
-DataArrayInt *DataArrayInt::findIdsEqualList(const int *valsBg, const int *valsEnd) const
-{
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsEqualList : the array must have only one component, you can call 'rearrange' method before !");
- std::set<int> vals2(valsBg,valsEnd);
- const int *cptr(getConstPointer());
- std::vector<int> res;
- int nbOfTuples(getNumberOfTuples());
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- for(int i=0;i<nbOfTuples;i++,cptr++)
- if(vals2.find(*cptr)!=vals2.end())
- ret->pushBackSilent(i);
- return ret.retn();
-}
-
-/*!
- * Creates a new DataArrayInt containing IDs (indices) of tuples holding values \b not
- * equal to any of given values.
- * \param [in] valsBg - an array of values to ignore within \a this array.
- * \param [in] valsEnd - specifies the end of the array \a valsBg, so that
- * the last value of \a valsBg is \a valsEnd[ -1 ].
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If \a this->getNumberOfComponents() != 1.
- */
-DataArrayInt *DataArrayInt::findIdsNotEqualList(const int *valsBg, const int *valsEnd) const
-{
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsNotEqualList : the array must have only one component, you can call 'rearrange' method before !");
- std::set<int> vals2(valsBg,valsEnd);
- const int *cptr=getConstPointer();
- std::vector<int> res;
- int nbOfTuples=getNumberOfTuples();
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- for(int i=0;i<nbOfTuples;i++,cptr++)
- if(vals2.find(*cptr)==vals2.end())
- ret->pushBackSilent(i);
- return ret.retn();
-}
-
-/*!
- * This method is an extension of DataArrayInt::findIdFirstEqual method because this method works for DataArrayInt with
- * any number of components excepted 0 (an INTERP_KERNEL::Exception is thrown in this case).
- * This method searches in \b this is there is a tuple that matched the input parameter \b tupl.
- * If any the tuple id is returned. If not -1 is returned.
- *
- * This method throws an INTERP_KERNEL::Exception if the number of components in \b this mismatches with the size of
- * the input vector. An INTERP_KERNEL::Exception is thrown too if \b this is not allocated.
- *
- * \return tuple id where \b tupl is. -1 if no such tuple exists in \b this.
- * \sa DataArrayInt::findIdSequence, DataArrayInt::presenceOfTuple.
- */
-int DataArrayInt::findIdFirstEqualTuple(const std::vector<int>& tupl) const
-{
- checkAllocated();
- int nbOfCompo=getNumberOfComponents();
- if(nbOfCompo==0)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdFirstEqualTuple : 0 components in 'this' !");
- if(nbOfCompo!=(int)tupl.size())
- {
- std::ostringstream oss; oss << "DataArrayInt::findIdFirstEqualTuple : 'this' contains " << nbOfCompo << " components and searching for a tuple of length " << tupl.size() << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- const int *cptr=getConstPointer();
- std::size_t nbOfVals=getNbOfElems();
- for(const int *work=cptr;work!=cptr+nbOfVals;)
- {
- work=std::search(work,cptr+nbOfVals,tupl.begin(),tupl.end());
- if(work!=cptr+nbOfVals)
- {
- if(std::distance(cptr,work)%nbOfCompo!=0)
- work++;
- else
- return std::distance(cptr,work)/nbOfCompo;
- }
- }
- return -1;
-}
-
-/*!
- * This method searches the sequence specified in input parameter \b vals in \b this.
- * This works only for DataArrayInt having number of components equal to one (if not an INTERP_KERNEL::Exception will be thrown).
- * This method differs from DataArrayInt::findIdFirstEqualTuple in that the position is internal raw data is not considered here contrary to DataArrayInt::findIdFirstEqualTuple.
- * \sa DataArrayInt::findIdFirstEqualTuple
- */
-int DataArrayInt::findIdSequence(const std::vector<int>& vals) const
-{
- checkAllocated();
- int nbOfCompo=getNumberOfComponents();
- if(nbOfCompo!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdSequence : works only for DataArrayInt instance with one component !");
- const int *cptr=getConstPointer();
- std::size_t nbOfVals=getNbOfElems();
- const int *loc=std::search(cptr,cptr+nbOfVals,vals.begin(),vals.end());
- if(loc!=cptr+nbOfVals)
- return std::distance(cptr,loc);
- return -1;
-}
-
-/*!
- * This method expects to be called when number of components of this is equal to one.
- * This method returns the tuple id, if it exists, of the first tuple equal to \b value.
- * If not any tuple contains \b value -1 is returned.
- * \sa DataArrayInt::presenceOfValue
- */
-int DataArrayInt::findIdFirstEqual(int value) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !");
- const int *cptr=getConstPointer();
- int nbOfTuples=getNumberOfTuples();
- const int *ret=std::find(cptr,cptr+nbOfTuples,value);
- if(ret!=cptr+nbOfTuples)
- return std::distance(cptr,ret);
- return -1;
-}
-
-/*!
- * This method expects to be called when number of components of this is equal to one.
- * This method returns the tuple id, if it exists, of the first tuple so that the value is contained in \b vals.
- * If not any tuple contains one of the values contained in 'vals' -1 is returned.
- * \sa DataArrayInt::presenceOfValue
- */
-int DataArrayInt::findIdFirstEqual(const std::vector<int>& vals) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !");
- std::set<int> vals2(vals.begin(),vals.end());
- const int *cptr=getConstPointer();
- int nbOfTuples=getNumberOfTuples();
- for(const int *w=cptr;w!=cptr+nbOfTuples;w++)
- if(vals2.find(*w)!=vals2.end())
- return std::distance(cptr,w);
- return -1;
-}
-
-/*!
- * This method returns the number of values in \a this that are equals to input parameter \a value.
- * This method only works for single component array.
- *
- * \return a value in [ 0, \c this->getNumberOfTuples() )
- *
- * \throw If \a this is not allocated
- *
- */
-int DataArrayInt::count(int value) const
-{
- int ret=0;
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::count : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
- const int *vals=begin();
- int nbOfTuples=getNumberOfTuples();
- for(int i=0;i<nbOfTuples;i++,vals++)
- if(*vals==value)
- ret++;
- return ret;
-}
-
-/*!
- * This method is an extension of DataArrayInt::presenceOfValue method because this method works for DataArrayInt with
- * any number of components excepted 0 (an INTERP_KERNEL::Exception is thrown in this case).
- * This method searches in \b this is there is a tuple that matched the input parameter \b tupl.
- * This method throws an INTERP_KERNEL::Exception if the number of components in \b this mismatches with the size of
- * the input vector. An INTERP_KERNEL::Exception is thrown too if \b this is not allocated.
- * \sa DataArrayInt::findIdFirstEqualTuple
- */
-bool DataArrayInt::presenceOfTuple(const std::vector<int>& tupl) const
-{
- return findIdFirstEqualTuple(tupl)!=-1;
-}
-
-
-/*!
- * Returns \a true if a given value is present within \a this one-dimensional array.
- * \param [in] value - the value to find within \a this array.
- * \return bool - \a true in case if \a value is present within \a this array.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \sa findIdFirstEqual()
- */
-bool DataArrayInt::presenceOfValue(int value) const
-{
- return findIdFirstEqual(value)!=-1;
-}
-
-/*!
- * This method expects to be called when number of components of this is equal to one.
- * This method returns true if it exists a tuple so that the value is contained in \b vals.
- * If not any tuple contains one of the values contained in 'vals' false is returned.
- * \sa DataArrayInt::findIdFirstEqual
- */
-bool DataArrayInt::presenceOfValue(const std::vector<int>& vals) const
-{
- return findIdFirstEqual(vals)!=-1;
-}
-
-/*!
- * Accumulates values of each component of \a this array.
- * \param [out] res - an array of length \a this->getNumberOfComponents(), allocated
- * by the caller, that is filled by this method with sum value for each
- * component.
- * \throw If \a this is not allocated.
- */
-void DataArrayInt::accumulate(int *res) const
-{
- checkAllocated();
- const int *ptr=getConstPointer();
- int nbTuple=getNumberOfTuples();
- int nbComps=getNumberOfComponents();
- std::fill(res,res+nbComps,0);
- for(int i=0;i<nbTuple;i++)
- std::transform(ptr+i*nbComps,ptr+(i+1)*nbComps,res,res,std::plus<int>());
-}
-
-int DataArrayInt::accumulate(int compId) const
-{
- checkAllocated();
- const int *ptr=getConstPointer();
- int nbTuple=getNumberOfTuples();
- int nbComps=getNumberOfComponents();
- if(compId<0 || compId>=nbComps)
- throw INTERP_KERNEL::Exception("DataArrayInt::accumulate : Invalid compId specified : No such nb of components !");
- int ret=0;
- for(int i=0;i<nbTuple;i++)
- ret+=ptr[i*nbComps+compId];
- return ret;
-}
-
-/*!
- * This method accumulate using addition tuples in \a this using input index array [ \a bgOfIndex, \a endOfIndex ).
- * The returned array will have same number of components than \a this and number of tuples equal to
- * \c std::distance(bgOfIndex,endOfIndex) \b minus \b one.
- *
- * The input index array is expected to be ascendingly sorted in which the all referenced ids should be in [0, \c this->getNumberOfTuples).
- *
- * \param [in] bgOfIndex - begin (included) of the input index array.
- * \param [in] endOfIndex - end (excluded) of the input index array.
- * \return DataArrayInt * - the new instance having the same number of components than \a this.
- *
- * \throw If bgOfIndex or end is NULL.
- * \throw If input index array is not ascendingly sorted.
- * \throw If there is an id in [ \a bgOfIndex, \a endOfIndex ) not in [0, \c this->getNumberOfTuples).
- * \throw If std::distance(bgOfIndex,endOfIndex)==0.
- */
-DataArrayInt *DataArrayInt::accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const
-{
- if(!bgOfIndex || !endOfIndex)
- throw INTERP_KERNEL::Exception("DataArrayInt::accumulatePerChunck : input pointer NULL !");
- checkAllocated();
- int nbCompo=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- int sz=(int)std::distance(bgOfIndex,endOfIndex);
- if(sz<1)
- throw INTERP_KERNEL::Exception("DataArrayInt::accumulatePerChunck : invalid size of input index array !");
- sz--;
- MCAuto<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(sz,nbCompo);
- const int *w=bgOfIndex;
- if(*w<0 || *w>=nbOfTuples)
- throw INTERP_KERNEL::Exception("DataArrayInt::accumulatePerChunck : The first element of the input index not in [0,nbOfTuples) !");
- const int *srcPt=begin()+(*w)*nbCompo;
- int *tmp=ret->getPointer();
- for(int i=0;i<sz;i++,tmp+=nbCompo,w++)
- {
- std::fill(tmp,tmp+nbCompo,0);
- if(w[1]>=w[0])
- {
- for(int j=w[0];j<w[1];j++,srcPt+=nbCompo)
- {
- if(j>=0 && j<nbOfTuples)
- std::transform(srcPt,srcPt+nbCompo,tmp,tmp,std::plus<int>());
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::accumulatePerChunck : At rank #" << i << " the input index array points to id " << j << " should be in [0," << nbOfTuples << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::accumulatePerChunck : At rank #" << i << " the input index array is not in ascendingly sorted.";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- ret->copyStringInfoFrom(*this);
- return ret.retn();
-}
-
-/*!
- * Returns a new DataArrayInt by concatenating two given arrays, so that (1) the number
- * of tuples in the result array is <em> a1->getNumberOfTuples() + a2->getNumberOfTuples() -
- * offsetA2</em> and (2)
- * the number of component in the result array is same as that of each of given arrays.
- * First \a offsetA2 tuples of \a a2 are skipped and thus are missing from the result array.
- * 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.
- * \param [in] offsetA2 - number of tuples of \a a2 to skip.
- * \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->getNumberOfComponents() != \a a2->getNumberOfComponents().
- */
-DataArrayInt *DataArrayInt::Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input DataArrayInt instance is NULL !");
- int nbOfComp=a1->getNumberOfComponents();
- if(nbOfComp!=a2->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Aggregation !");
- int nbOfTuple1=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- DataArrayInt *ret=DataArrayInt::New();
- ret->alloc(nbOfTuple1+nbOfTuple2-offsetA2,nbOfComp);
- int *pt=std::copy(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple1*nbOfComp,ret->getPointer());
- std::copy(a2->getConstPointer()+offsetA2*nbOfComp,a2->getConstPointer()+nbOfTuple2*nbOfComp,pt);
- ret->copyStringInfoFrom(*a1);
- return ret;
-}
-
-/*!
- * Returns a new DataArrayInt 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 DataArrayInt * - the new instance of DataArrayInt.
- * 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.
- */
-DataArrayInt *DataArrayInt::Aggregate(const std::vector<const DataArrayInt *>& arr)
-{
- std::vector<const DataArrayInt *> a;
- for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
- if(*it4)
- a.push_back(*it4);
- if(a.empty())
- throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input list must be NON EMPTY !");
- std::vector<const DataArrayInt *>::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("DataArrayInt::Aggregate : Nb of components mismatch for array aggregation !");
- nbt+=(*it)->getNumberOfTuples();
- }
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(nbt,nbOfComp);
- int *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();
-}
-
-/*!
- * This method takes as input a list of DataArrayInt instances \a arrs that represent each a packed index arrays.
- * A packed index array is an allocated array with one component, and at least one tuple. The first element
- * of each array in \a arrs must be 0. Each array in \a arrs is expected to be increasingly monotonic.
- * This method is useful for users that want to aggregate a pair of DataArrayInt representing an indexed data (typically nodal connectivity index in unstructured meshes.
- *
- * \return DataArrayInt * - a new object to be managed by the caller.
- */
-DataArrayInt *DataArrayInt::AggregateIndexes(const std::vector<const DataArrayInt *>& arrs)
-{
- int retSz=1;
- for(std::vector<const DataArrayInt *>::const_iterator it4=arrs.begin();it4!=arrs.end();it4++)
- {
- if(*it4)
- {
- (*it4)->checkAllocated();
- if((*it4)->getNumberOfComponents()!=1)
- {
- std::ostringstream oss; oss << "DataArrayInt::AggregateIndexes : presence of a DataArrayInt instance with nb of compo != 1 at pos " << std::distance(arrs.begin(),it4) << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- int nbTupl=(*it4)->getNumberOfTuples();
- if(nbTupl<1)
- {
- std::ostringstream oss; oss << "DataArrayInt::AggregateIndexes : presence of a DataArrayInt instance with nb of tuples < 1 at pos " << std::distance(arrs.begin(),it4) << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- if((*it4)->front()!=0)
- {
- std::ostringstream oss; oss << "DataArrayInt::AggregateIndexes : presence of a DataArrayInt instance with front value != 0 at pos " << std::distance(arrs.begin(),it4) << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- retSz+=nbTupl-1;
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::AggregateIndexes : presence of a null instance at pos " << std::distance(arrs.begin(),it4) << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- if(arrs.empty())
- throw INTERP_KERNEL::Exception("DataArrayInt::AggregateIndexes : input list must be NON EMPTY !");
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(retSz,1);
- int *pt=ret->getPointer(); *pt++=0;
- for(std::vector<const DataArrayInt *>::const_iterator it=arrs.begin();it!=arrs.end();it++)
- pt=std::transform((*it)->begin()+1,(*it)->end(),pt,std::bind2nd(std::plus<int>(),pt[-1]));
- ret->copyStringInfoFrom(*(arrs[0]));
- return ret.retn();
-}
-
-/*!
- * Returns the maximal value and its location within \a this one-dimensional array.
- * \param [out] tupleId - index of the tuple holding the maximal value.
- * \return int - the maximal value among all values of \a this array.
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If \a this->getNumberOfTuples() < 1
- */
-int DataArrayInt::getMaxValue(int& tupleId) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !");
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples<=0)
- throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : array exists but number of tuples must be > 0 !");
- const int *vals=getConstPointer();
- const int *loc=std::max_element(vals,vals+nbOfTuples);
- tupleId=(int)std::distance(vals,loc);
- return *loc;
-}
-
-/*!
- * Returns the maximal value within \a this array that is allowed to have more than
- * one component.
- * \return int - the maximal value among all values of \a this array.
- * \throw If \a this is not allocated.
- */
-int DataArrayInt::getMaxValueInArray() const
-{
- checkAllocated();
- const int *loc=std::max_element(begin(),end());
- return *loc;
-}
-
-/*!
- * Returns the minimal value and its location within \a this one-dimensional array.
- * \param [out] tupleId - index of the tuple holding the minimal value.
- * \return int - the minimal value among all values of \a this array.
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If \a this->getNumberOfTuples() < 1
- */
-int DataArrayInt::getMinValue(int& tupleId) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !");
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples<=0)
- throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : array exists but number of tuples must be > 0 !");
- const int *vals=getConstPointer();
- const int *loc=std::min_element(vals,vals+nbOfTuples);
- tupleId=(int)std::distance(vals,loc);
- return *loc;
-}
-
-/*!
- * Returns the minimal value within \a this array that is allowed to have more than
- * one component.
- * \return int - the minimal value among all values of \a this array.
- * \throw If \a this is not allocated.
- */
-int DataArrayInt::getMinValueInArray() const
-{
- checkAllocated();
- const int *loc=std::min_element(begin(),end());
- return *loc;
-}
-
-/*!
- * Returns in a single walk in \a this the min value and the max value in \a this.
- * \a this is expected to be single component array.
- *
- * \param [out] minValue - the min value in \a this.
- * \param [out] maxValue - the max value in \a this.
- *
- * \sa getMinValueInArray, getMinValue, getMaxValueInArray, getMaxValue
- */
-void DataArrayInt::getMinMaxValues(int& minValue, int& maxValue) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::getMinMaxValues : must be applied on DataArrayInt with only one component !");
- int nbTuples(getNumberOfTuples());
- const int *pt(begin());
- minValue=std::numeric_limits<int>::max(); maxValue=-std::numeric_limits<int>::max();
- for(int i=0;i<nbTuples;i++,pt++)
- {
- if(*pt<minValue)
- minValue=*pt;
- if(*pt>maxValue)
- maxValue=*pt;
- }
-}
-
-/*!
- * Converts every value of \a this array to its absolute value.
- * \b WARNING this method is non const. If a new DataArrayInt instance should be built containing the result of abs DataArrayInt::computeAbs
- * should be called instead.
- *
- * \throw If \a this is not allocated.
- * \sa DataArrayInt::computeAbs
- */
-void DataArrayInt::abs()
-{
- checkAllocated();
- int *ptr(getPointer());
- std::size_t nbOfElems(getNbOfElems());
- std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<int,int>(std::abs));
- 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 DataArrayInt::abs method.
- *
- * \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.
- * \sa DataArrayInt::abs
- */
-DataArrayInt *DataArrayInt::computeAbs() const
-{
- checkAllocated();
- DataArrayInt *newArr(DataArrayInt::New());
- int nbOfTuples(getNumberOfTuples());
- int nbOfComp(getNumberOfComponents());
- newArr->alloc(nbOfTuples,nbOfComp);
- std::transform(begin(),end(),newArr->getPointer(),std::ptr_fun<int,int>(std::abs));
- newArr->copyStringInfoFrom(*this);
- 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$.
- * \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.
- * \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 in \a this array.
- */
-void DataArrayInt::applyInv(int numerator)
-{
- checkAllocated();
- int *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- {
- if(*ptr!=0)
- {
- *ptr=numerator/(*ptr);
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
- oss << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- declareAsNew();
-}
-
-/*!
- * Modify all elements of \a this array, so that
- * an element _x_ becomes \f$ x / val \f$.
- * \param [in] val - the denominator used to modify array elements.
- * \throw If \a this is not allocated.
- * \throw If \a val == 0.
- */
-void DataArrayInt::applyDivideBy(int val)
-{
- if(val==0)
- throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to divide by 0 !");
- checkAllocated();
- int *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::divides<int>(),val));
- declareAsNew();
-}
-
-/*!
- * Modify all elements of \a this array, so that
- * an element _x_ becomes <em> x % val </em>.
- * \param [in] val - the divisor used to modify array elements.
- * \throw If \a this is not allocated.
- * \throw If \a val <= 0.
- */
-void DataArrayInt::applyModulus(int val)
-{
- if(val<=0)
- throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to operate modulus on value <= 0 !");
- checkAllocated();
- int *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::modulus<int>(),val));
- declareAsNew();
-}
-
-/*!
- * This method works only on data array with one component.
- * This method returns a newly allocated array storing stored ascendantly tuple ids in \b this so that
- * this[*id] in [\b vmin,\b vmax)
- *
- * \param [in] vmin begin of range. This value is included in range (included).
- * \param [in] vmax end of range. This value is \b not included in range (excluded).
- * \return a newly allocated data array that the caller should deal with.
- *
- * \sa DataArrayInt::findIdsNotInRange , DataArrayInt::findIdsStricltyNegative
- */
-DataArrayInt *DataArrayInt::findIdsInRange(int vmin, int vmax) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsInRange : this must have exactly one component !");
- const int *cptr(begin());
- MCAuto<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();
-}
-
-/*!
- * This method works only on data array with one component.
- * This method returns a newly allocated array storing stored ascendantly tuple ids in \b this so that
- * this[*id] \b not in [\b vmin,\b vmax)
- *
- * \param [in] vmin begin of range. This value is \b not included in range (excluded).
- * \param [in] vmax end of range. This value is included in range (included).
- * \return a newly allocated data array that the caller should deal with.
- *
- * \sa DataArrayInt::findIdsInRange , DataArrayInt::findIdsStricltyNegative
- */
-DataArrayInt *DataArrayInt::findIdsNotInRange(int vmin, int vmax) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsNotInRange : this must have exactly one component !");
- const int *cptr(getConstPointer());
- MCAuto<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();
-}
-
-/*!
- * This method works only on data array with one component. This method returns a newly allocated array storing stored ascendantly of tuple ids in \a this so that this[id]<0.
- *
- * \return a newly allocated data array that the caller should deal with.
- * \sa DataArrayInt::findIdsInRange
- */
-DataArrayInt *DataArrayInt::findIdsStricltyNegative() const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::findIdsStricltyNegative : this must have exactly one component !");
- const int *cptr(getConstPointer());
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- int nbOfTuples(getNumberOfTuples());
- for(int i=0;i<nbOfTuples;i++,cptr++)
- if(*cptr<0)
- ret->pushBackSilent(i);
- return ret.retn();
-}
-
-/*!
- * This method works only on data array with one component.
- * This method checks that all ids in \b this are in [ \b vmin, \b vmax ). If there is at least one element in \a this not in [ \b vmin, \b vmax ) an exception will be thrown.
- *
- * \param [in] vmin begin of range. This value is included in range (included).
- * \param [in] vmax end of range. This value is \b not included in range (excluded).
- * \return if all ids in \a this are so that (*this)[i]==i for all i in [ 0, \c this->getNumberOfTuples() ). */
-bool DataArrayInt::checkAllIdsInRange(int vmin, int vmax) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::checkAllIdsInRange : this must have exactly one component !");
- int nbOfTuples=getNumberOfTuples();
- bool ret=true;
- const int *cptr=getConstPointer();
- for(int i=0;i<nbOfTuples;i++,cptr++)
- {
- if(*cptr>=vmin && *cptr<vmax)
- { ret=ret && *cptr==i; }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::checkAllIdsInRange : tuple #" << i << " has value " << *cptr << " should be in [" << vmin << "," << vmax << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return ret;
-}
-
-/*!
- * Modify all elements of \a this array, so that
- * an element _x_ becomes <em> val % x </em>.
- * \warning If an exception is thrown because of presence of an element <= 0 in \a this
- * array, all elements processed before detection of the zero element remain
- * modified.
- * \param [in] val - the divident used to modify array elements.
- * \throw If \a this is not allocated.
- * \throw If there is an element equal to or less than 0 in \a this array.
- */
-void DataArrayInt::applyRModulus(int val)
-{
- checkAllocated();
- int *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- {
- if(*ptr>0)
- {
- *ptr=val%(*ptr);
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::applyRModulus : presence of value <=0 in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
- oss << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- declareAsNew();
-}
-
-/*!
- * Modify all elements of \a this array, so that
- * an element _x_ becomes <em> val ^ x </em>.
- * \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.
- */
-void DataArrayInt::applyPow(int val)
-{
- checkAllocated();
- if(val<0)
- throw INTERP_KERNEL::Exception("DataArrayInt::applyPow : input pow in < 0 !");
- int *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- if(val==0)
- {
- std::fill(ptr,ptr+nbOfElems,1);
- return ;
- }
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- {
- int tmp=1;
- for(int j=0;j<val;j++)
- tmp*=*ptr;
- *ptr=tmp;
- }
- 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 there is an element < 0 in \a this array.
- * \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 DataArrayInt::applyRPow(int val)
-{
- checkAllocated();
- int *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- {
- if(*ptr>=0)
- {
- int tmp=1;
- for(int j=0;j<*ptr;j++)
- tmp*=val;
- *ptr=tmp;
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::applyRPow : presence of negative value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
- oss << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- declareAsNew();
-}
-
-/*!
- * Returns a new DataArrayInt 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 DataArrayInt * - the new instance of DataArrayInt.
- * 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()
- */
-DataArrayInt *DataArrayInt::Meld(const DataArrayInt *a1, const DataArrayInt *a2)
-{
- std::vector<const DataArrayInt *> arr(2);
- arr[0]=a1; arr[1]=a2;
- return Meld(arr);
-}
-
-/*!
- * Returns a new DataArrayInt 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 DataArrayInt * - the new instance of DataArrayInt.
- * 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.
- */
-DataArrayInt *DataArrayInt::Meld(const std::vector<const DataArrayInt *>& arr)
-{
- std::vector<const DataArrayInt *> a;
- for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
- if(*it4)
- a.push_back(*it4);
- if(a.empty())
- throw INTERP_KERNEL::Exception("DataArrayInt::Meld : array must be NON empty !");
- std::vector<const DataArrayInt *>::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 int *> 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("DataArrayInt::meld : mismatch of number of tuples !");
- nbc[i]=(*it)->getNumberOfComponents();
- pts[i]=(*it)->getConstPointer();
- }
- int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
- DataArrayInt *ret=DataArrayInt::New();
- ret->alloc(nbOfTuples,totalNbOfComp);
- int *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 DataArrayInt which is a minimal partition of elements of \a groups.
- * The i-th item of the result array is an ID of a set of elements belonging to a
- * unique set of groups, which the i-th element is a part of. This set of elements
- * belonging to a unique set of groups is called \a family, so the result array contains
- * IDs of families each element belongs to.
- *
- * \b Example: if we have two groups of elements: \a group1 [0,4] and \a group2 [ 0,1,2 ],
- * then there are 3 families:
- * - \a family1 (with ID 1) contains element [0] belonging to ( \a group1 + \a group2 ),
- * - \a family2 (with ID 2) contains elements [4] belonging to ( \a group1 ),
- * - \a family3 (with ID 3) contains element [1,2] belonging to ( \a group2 ), <br>
- * and the result array contains IDs of families [ 1,3,3,0,2 ]. <br> Note a family ID 0 which
- * stands for the element #3 which is in none of groups.
- *
- * \param [in] groups - sequence of groups of element IDs.
- * \param [in] newNb - total number of elements; it must be more than max ID of element
- * in \a groups.
- * \param [out] fidsOfGroups - IDs of families the elements of each group belong to.
- * \return DataArrayInt * - a new instance of DataArrayInt containing IDs of families
- * each element with ID from range [0, \a newNb ) belongs to. The caller is to
- * delete this array using decrRef() as it is no more needed.
- * \throw If any element ID in \a groups violates condition ( 0 <= ID < \a newNb ).
- */
-DataArrayInt *DataArrayInt::MakePartition(const std::vector<const DataArrayInt *>& groups, int newNb, std::vector< std::vector<int> >& fidsOfGroups)
-{
- std::vector<const DataArrayInt *> groups2;
- for(std::vector<const DataArrayInt *>::const_iterator it4=groups.begin();it4!=groups.end();it4++)
- if(*it4)
- groups2.push_back(*it4);
- MCAuto<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(newNb,1);
- int *retPtr=ret->getPointer();
- std::fill(retPtr,retPtr+newNb,0);
- int fid=1;
- for(std::vector<const DataArrayInt *>::const_iterator iter=groups2.begin();iter!=groups2.end();iter++)
- {
- const int *ptr=(*iter)->getConstPointer();
- std::size_t nbOfElem=(*iter)->getNbOfElems();
- int sfid=fid;
- for(int j=0;j<sfid;j++)
- {
- bool found=false;
- for(std::size_t i=0;i<nbOfElem;i++)
- {
- if(ptr[i]>=0 && ptr[i]<newNb)
- {
- if(retPtr[ptr[i]]==j)
- {
- retPtr[ptr[i]]=fid;
- found=true;
- }
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::MakePartition : In group \"" << (*iter)->getName() << "\" in tuple #" << i << " value = " << ptr[i] << " ! Should be in [0," << newNb;
- oss << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- if(found)
- fid++;
- }
- }
- fidsOfGroups.clear();
- fidsOfGroups.resize(groups2.size());
- int grId=0;
- for(std::vector<const DataArrayInt *>::const_iterator iter=groups2.begin();iter!=groups2.end();iter++,grId++)
- {
- std::set<int> tmp;
- const int *ptr=(*iter)->getConstPointer();
- std::size_t nbOfElem=(*iter)->getNbOfElems();
- for(const int *p=ptr;p!=ptr+nbOfElem;p++)
- tmp.insert(retPtr[*p]);
- fidsOfGroups[grId].insert(fidsOfGroups[grId].end(),tmp.begin(),tmp.end());
- }
- return ret.retn();
-}
-
-/*!
- * Returns a new DataArrayInt which contains all elements of given one-dimensional
- * arrays. The result array does not contain any duplicates and its values
- * are sorted in ascending order.
- * \param [in] arr - sequence of DataArrayInt's to unite.
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If any \a arr[i] is not allocated.
- * \throw If \a arr[i]->getNumberOfComponents() != 1.
- */
-DataArrayInt *DataArrayInt::BuildUnion(const std::vector<const DataArrayInt *>& arr)
-{
- std::vector<const DataArrayInt *> a;
- for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
- if(*it4)
- a.push_back(*it4);
- for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
- {
- (*it)->checkAllocated();
- if((*it)->getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : only single component allowed !");
- }
- //
- std::set<int> r;
- for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
- {
- const int *pt=(*it)->getConstPointer();
- int nbOfTuples=(*it)->getNumberOfTuples();
- r.insert(pt,pt+nbOfTuples);
- }
- DataArrayInt *ret=DataArrayInt::New();
- ret->alloc((int)r.size(),1);
- std::copy(r.begin(),r.end(),ret->getPointer());
- return ret;
-}
-
-/*!
- * Returns a new DataArrayInt which contains elements present in each of given one-dimensional
- * arrays. The result array does not contain any duplicates and its values
- * are sorted in ascending order.
- * \param [in] arr - sequence of DataArrayInt's to intersect.
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.
- * \throw If any \a arr[i] is not allocated.
- * \throw If \a arr[i]->getNumberOfComponents() != 1.
- */
-DataArrayInt *DataArrayInt::BuildIntersection(const std::vector<const DataArrayInt *>& arr)
-{
- std::vector<const DataArrayInt *> a;
- for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
- if(*it4)
- a.push_back(*it4);
- for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
- {
- (*it)->checkAllocated();
- if((*it)->getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::BuildIntersection : only single component allowed !");
- }
- //
- std::set<int> r;
- for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
- {
- const int *pt=(*it)->getConstPointer();
- int nbOfTuples=(*it)->getNumberOfTuples();
- std::set<int> s1(pt,pt+nbOfTuples);
- if(it!=a.begin())
- {
- std::set<int> r2;
- std::set_intersection(r.begin(),r.end(),s1.begin(),s1.end(),inserter(r2,r2.end()));
- r=r2;
- }
- else
- r=s1;
- }
- DataArrayInt *ret(DataArrayInt::New());
- ret->alloc((int)r.size(),1);
- std::copy(r.begin(),r.end(),ret->getPointer());
- return ret;
-}
-
-/// @cond INTERNAL
-namespace MEDCouplingImpl
-{
- class OpSwitchedOn
- {
- public:
- OpSwitchedOn(int *pt):_pt(pt),_cnt(0) { }
- void operator()(const bool& b) { if(b) *_pt++=_cnt; _cnt++; }
- private:
- int *_pt;
- int _cnt;
- };
-
- class OpSwitchedOff
- {
- public:
- OpSwitchedOff(int *pt):_pt(pt),_cnt(0) { }
- void operator()(const bool& b) { if(!b) *_pt++=_cnt; _cnt++; }
- private:
- int *_pt;
- int _cnt;
- };
-}
-/// @endcond
-
-/*!
- * This method returns the list of ids in ascending mode so that v[id]==true.
- */
-DataArrayInt *DataArrayInt::BuildListOfSwitchedOn(const std::vector<bool>& v)
-{
- int sz((int)std::count(v.begin(),v.end(),true));
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(sz,1);
- std::for_each(v.begin(),v.end(),MEDCouplingImpl::OpSwitchedOn(ret->getPointer()));
- return ret.retn();
-}
-
-/*!
- * This method returns the list of ids in ascending mode so that v[id]==false.
- */
-DataArrayInt *DataArrayInt::BuildListOfSwitchedOff(const std::vector<bool>& v)
-{
- int sz((int)std::count(v.begin(),v.end(),false));
- MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(sz,1);
- std::for_each(v.begin(),v.end(),MEDCouplingImpl::OpSwitchedOff(ret->getPointer()));
- return ret.retn();
-}
-
-/*!
- * This method allows to put a vector of vector of integer into a more compact data stucture (skyline).
- * This method is not available into python because no available optimized data structure available to map std::vector< std::vector<int> >.
- *
- * \param [in] v the input data structure to be translate into skyline format.
- * \param [out] data the first element of the skyline format. The user is expected to deal with newly allocated array.
- * \param [out] dataIndex the second element of the skyline format.
- */
-void DataArrayInt::PutIntoToSkylineFrmt(const std::vector< std::vector<int> >& v, DataArrayInt *& data, DataArrayInt *& dataIndex)
-{
- int sz((int)v.size());
- MCAuto<DataArrayInt> ret0(DataArrayInt::New()),ret1(DataArrayInt::New());
- ret1->alloc(sz+1,1);
- int *pt(ret1->getPointer()); *pt=0;
- for(int i=0;i<sz;i++,pt++)
- pt[1]=pt[0]+(int)v[i].size();
- ret0->alloc(ret1->back(),1);
- pt=ret0->getPointer();
- for(int i=0;i<sz;i++)
- pt=std::copy(v[i].begin(),v[i].end(),pt);
- data=ret0.retn(); dataIndex=ret1.retn();
-}
-
-/*!
- * Returns a new DataArrayInt which contains a complement of elements of \a this
- * one-dimensional array. I.e. the result array contains all elements from the range [0,
- * \a nbOfElement) not present in \a this array.
- * \param [in] nbOfElement - maximal size of the result array.
- * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
- * array using decrRef() as it is no more needed.