X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMemArray.cxx;h=0d5d059a04685eb0884cd269f8348c7107558110;hb=0c9d48870957c4a9f6f82fc8e2c569780a5f886b;hp=ca8343508e47afbb028b5ee5e479200e2b84917b;hpb=698aa42b2e85a3fc48e61fd1a628e6a23e22370e;p=modules%2Fmed.git diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index ca8343508..0d5d059a0 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -130,7 +130,7 @@ std::vector DataArray::getDirectChildren() const * See \ref MEDCouplingArrayBasicsName "DataArrays infos" for more information. * \param [in] name - new array name */ -void DataArray::setName(const char *name) +void DataArray::setName(const std::string& name) { _name=name; } @@ -164,7 +164,7 @@ void DataArray::copyPartOfStringInfoFrom(const DataArray& other, const std::vect throw INTERP_KERNEL::Exception(oss.str().c_str()); } for(std::size_t i=0;i& compoIds, const DataArray& other) @@ -180,7 +180,7 @@ void DataArray::copyPartOfStringInfoFrom2(const std::vector& compoIds, cons throw INTERP_KERNEL::Exception(oss.str().c_str()); } for(std::size_t i=0;i& arrs) * \param [in] info - the string containing the information. * \throw If \a i is not a valid component index. */ -void DataArray::setInfoOnComponent(int i, const char *info) +void DataArray::setInfoOnComponent(int i, const std::string& info) { if(i<(int)_info_on_compo.size() && i>=0) _info_on_compo[i]=info; @@ -516,7 +516,7 @@ void DataArray::setInfoAndChangeNbOfCompo(const std::vector& info) _info_on_compo=info; } -void DataArray::checkNbOfTuples(int nbOfTuples, const char *msg) const +void DataArray::checkNbOfTuples(int nbOfTuples, const std::string& msg) const { if(getNumberOfTuples()!=nbOfTuples) { @@ -525,7 +525,7 @@ void DataArray::checkNbOfTuples(int nbOfTuples, const char *msg) const } } -void DataArray::checkNbOfComps(int nbOfCompo, const char *msg) const +void DataArray::checkNbOfComps(int nbOfCompo, const std::string& msg) const { if(getNumberOfComponents()!=nbOfCompo) { @@ -534,7 +534,7 @@ void DataArray::checkNbOfComps(int nbOfCompo, const char *msg) const } } -void DataArray::checkNbOfElems(std::size_t nbOfElems, const char *msg) const +void DataArray::checkNbOfElems(std::size_t nbOfElems, const std::string& msg) const { if(getNbOfElems()!=nbOfElems) { @@ -543,7 +543,7 @@ void DataArray::checkNbOfElems(std::size_t nbOfElems, const char *msg) const } } -void DataArray::checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const +void DataArray::checkNbOfTuplesAndComp(const DataArray& other, const std::string& msg) const { if(getNumberOfTuples()!=other.getNumberOfTuples()) { @@ -557,7 +557,7 @@ void DataArray::checkNbOfTuplesAndComp(const DataArray& other, const char *msg) } } -void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const +void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const std::string& msg) const { checkNbOfTuples(nbOfTuples,msg); checkNbOfComps(nbOfCompo,msg); @@ -566,7 +566,7 @@ void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char /*! * Simply this method checks that \b value is in [0,\b ref). */ -void DataArray::CheckValueInRange(int ref, int value, const char *msg) +void DataArray::CheckValueInRange(int ref, int value, const std::string& msg) { if(value<0 || value>=ref) { @@ -579,7 +579,7 @@ void DataArray::CheckValueInRange(int ref, int value, const char *msg) * This method checks that [\b start, \b end) is compliant with ref length \b value. * typicaly start in [0,\b value) and end in [0,\b value). If value==start and start==end, it is supported. */ -void DataArray::CheckValueInRangeEx(int value, int start, int end, const char *msg) +void DataArray::CheckValueInRangeEx(int value, int start, int end, const std::string& msg) { if(start<0 || start>=value) { @@ -596,7 +596,7 @@ void DataArray::CheckValueInRangeEx(int value, int start, int end, const char *m } } -void DataArray::CheckClosingParInRange(int ref, int value, const char *msg) +void DataArray::CheckClosingParInRange(int ref, int value, const std::string& msg) { if(value<0 || value>ref) { @@ -644,7 +644,7 @@ void DataArray::GetSlice(int start, int stop, int step, int sliceId, int nbOfSli stopSlice=stop; } -int DataArray::GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) +int DataArray::GetNumberOfItemGivenBES(int begin, int end, int step, const std::string& msg) { if(endalloc(getNumberOfTuples(),getNumberOfComponents()); - std::size_t nbOfVals=getNbOfElems(); int *dest=ret->getPointer(); - // to make Visual C++ happy : instead of std::copy(src,src+nbOfVals,dest); + // to make Visual C++ happy : instead of std::size_t nbOfVals=getNbOfElems(); std::copy(src,src+nbOfVals,dest); for(const double *src=begin();src!=end();src++,dest++) *dest=(int)*src; ret->copyStringInfoFrom(*this); @@ -1784,10 +1783,10 @@ DataArrayDouble *DataArrayDouble::changeNbOfComponents(int newNbOfComp, double d for(;jsetName(getName().c_str()); + ret->setName(getName()); for(int i=0;isetInfoOnComponent(i,getInfoOnComponent(i).c_str()); - ret->setName(getName().c_str()); + ret->setInfoOnComponent(i,getInfoOnComponent(i)); + ret->setName(getName()); return ret.retn(); } @@ -1960,7 +1959,7 @@ bool DataArrayDouble::areIncludedInMe(const DataArrayDouble *other, double prec, * [ \a commIndex[1], \a commIndex[2] ). \a commIndex->getNumberOfTuples()-1 * gives the number of groups of coincident tuples. * \throw If \a this is not allocated. - * \throw If the number of components is not in [1,2,3]. + * \throw If the number of components is not in [1,2,3,4]. * * \ref cpp_mcdataarraydouble_findcommontuples "Here is a C++ example". * @@ -1971,14 +1970,17 @@ void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayI { checkAllocated(); int nbOfCompo=getNumberOfComponents(); - if ((nbOfCompo<1) || (nbOfCompo>3)) //test before work - throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : Unexpected spacedim of coords. Must be 1, 2 or 3."); + if ((nbOfCompo<1) || (nbOfCompo>4)) //test before work + throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : Unexpected spacedim of coords. Must be 1, 2, 3 or 4."); int nbOfTuples=getNumberOfTuples(); // MEDCouplingAutoRefCountObjectPtr c(DataArrayInt::New()),cI(DataArrayInt::New()); c->alloc(0,1); cI->pushBackSilent(0); switch(nbOfCompo) { + case 4: + findCommonTuplesAlg<4>(begin(),nbOfTuples,limitTupleId,prec,c,cI); + break; case 3: findCommonTuplesAlg<3>(begin(),nbOfTuples,limitTupleId,prec,c,cI); break; @@ -1989,7 +1991,7 @@ void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayI findCommonTuplesAlg<1>(begin(),nbOfTuples,limitTupleId,prec,c,cI); break; default: - throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : nb of components managed are 1,2 and 3 ! not implemented for other number of components !"); + throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : nb of components managed are 1,2,3 and 4 ! not implemented for other number of components !"); } comm=c.retn(); commIndex=cI.retn(); @@ -2186,7 +2188,7 @@ DataArrayInt *DataArrayDouble::computeNbOfInteractionsWith(const DataArrayDouble * \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. - * \throw If the number of components is not in [1,2,3]. + * \throw If the number of components is not in [1,2,3,4]. * * \ref py_mcdataarraydouble_getdifferentvalues "Here is a Python example". */ @@ -3294,25 +3296,50 @@ double DataArrayDouble::norm2() const /*! * Returns the maximum norm of the vector defined by \a this array. + * This method works even if the number of components is diferent from one. + * If the number of elements in \a this is 0, -1. is returned. * \return double - the value of the maximum norm, i.e. - * the maximal absolute value among values of \a this array. + * the maximal absolute value among values of \a this array (whatever its number of components). * \throw If \a this is not allocated. */ double DataArrayDouble::normMax() const { checkAllocated(); - double ret=-1.; - std::size_t nbOfElems=getNbOfElems(); - const double *pt=getConstPointer(); + double ret(-1.); + std::size_t nbOfElems(getNbOfElems()); + const double *pt(getConstPointer()); for(std::size_t i=0;iret) ret=val; } return ret; } +/*! + * Returns the minimum norm (absolute value) of the vector defined by \a this array. + * This method works even if the number of components is diferent from one. + * If the number of elements in \a this is 0, std::numeric_limits::max() is returned. + * \return double - the value of the minimum norm, i.e. + * the minimal absolute value among values of \a this array (whatever its number of components). + * \throw If \a this is not allocated. + */ +double DataArrayDouble::normMin() const +{ + checkAllocated(); + double ret(std::numeric_limits::max()); + std::size_t nbOfElems(getNbOfElems()); + const double *pt(getConstPointer()); + for(std::size_t i=0;igetNumberOfComponents(), allocated @@ -3509,7 +3536,7 @@ DataArrayDouble *DataArrayDouble::fromCylToCart() const w[1]=wIn[0]*sin(wIn[1]); w[2]=wIn[2]; } - ret->setInfoOnComponent(2,getInfoOnComponent(2).c_str()); + ret->setInfoOnComponent(2,getInfoOnComponent(2)); return ret; } @@ -3818,6 +3845,28 @@ DataArrayDouble *DataArrayDouble::magnitude() const return ret; } +/*! + * Computes for each tuple the sum of number of components values in the tuple and return it. + * + * \return DataArrayDouble * - the new instance of DataArrayDouble containing the + * same number of tuples as \a this array and one component. + * The caller is to delete this result array using decrRef() as it is no more + * needed. + * \throw If \a this is not allocated. + */ +DataArrayDouble *DataArrayDouble::sumPerTuple() const +{ + checkAllocated(); + int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples()); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); + ret->alloc(nbOfTuple,1); + const double *src(getConstPointer()); + double *dest(ret->getPointer()); + for(int i=0;i(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(fabs)); + newArr->copyStringInfoFrom(*this); + return newArr; +} + /*! * Apply a liner function to a given component of \a this array, so that * an array element (x) becomes \f$ a * x + b \f$. @@ -4200,7 +4276,7 @@ DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, FunctionToEvaluate fun * \throw If \a this is not allocated. * \throw If computing \a func fails. */ -DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const char *func) const +DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const std::string& func) const { checkAllocated(); INTERP_KERNEL::ExprParser expr(func); @@ -4254,7 +4330,7 @@ DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const char *func) cons * \throw If \a this is not allocated. * \throw If computing \a func fails. */ -DataArrayDouble *DataArrayDouble::applyFunc(const char *func) const +DataArrayDouble *DataArrayDouble::applyFunc(const std::string& func) const { checkAllocated(); INTERP_KERNEL::ExprParser expr(func); @@ -4300,7 +4376,7 @@ DataArrayDouble *DataArrayDouble::applyFunc(const char *func) const * \throw If \a func contains vars that are not in \a this->getInfoOnComponent(). * \throw If computing \a func fails. */ -DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const char *func) const +DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const std::string& func) const { checkAllocated(); INTERP_KERNEL::ExprParser expr(func); @@ -4356,7 +4432,7 @@ DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const char *func) con * \throw If \a func contains vars not in \a varsOrder. * \throw If computing \a func fails. */ -DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vector& varsOrder, const char *func) const +DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vector& varsOrder, const std::string& func) const { checkAllocated(); INTERP_KERNEL::ExprParser expr(func); @@ -4396,7 +4472,7 @@ DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vectorgetNumberOfComponents() != 1. * + * \sa DataArrayDouble::getIdsNotInRange + * * \ref cpp_mcdataarraydouble_getidsinrange "Here is a C++ example".
* \ref py_mcdataarraydouble_getidsinrange "Here is a Python example". */ @@ -4455,15 +4533,41 @@ DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayDouble::getIdsInRange : this must have exactly one component !"); - const double *cptr=getConstPointer(); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(0,1); - int nbOfTuples=getNumberOfTuples(); + const double *cptr(begin()); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(0,1); + int nbOfTuples(getNumberOfTuples()); for(int i=0;i=vmin && *cptr<=vmax) ret->pushBackSilent(i); return ret.retn(); } +/*! + * Returns a new DataArrayInt contating indices of tuples of \a this one-dimensional + * array whose values are not within a given range. Textual data is not copied. + * \param [in] vmin - a lowest not acceptable value (excluded). + * \param [in] vmax - a greatest not acceptable value (excluded). + * \return DataArrayInt * - the new instance of DataArrayInt. + * The caller is to delete this result array using decrRef() as it is no more + * needed. + * \throw If \a this->getNumberOfComponents() != 1. + * + * \sa DataArrayDouble::getIdsInRange + */ +DataArrayInt *DataArrayDouble::getIdsNotInRange(double vmin, double vmax) const +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayDouble::getIdsNotInRange : this must have exactly one component !"); + const double *cptr(begin()); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(0,1); + int nbOfTuples(getNumberOfTuples()); + for(int i=0;ivmax) + 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) @@ -4491,6 +4595,8 @@ DataArrayDouble *DataArrayDouble::Aggregate(const DataArrayDouble *a1, const Dat * 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 @@ -4599,7 +4705,7 @@ DataArrayDouble *DataArrayDouble::Meld(const std::vectorsetInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str()); + ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j)); return ret; } @@ -4643,8 +4749,8 @@ DataArrayDouble *DataArrayDouble::Dot(const DataArrayDouble *a1, const DataArray sum+=a1Ptr[i*nbOfComp+j]*a2Ptr[i*nbOfComp+j]; retPtr[i]=sum; } - ret->setInfoOnComponent(0,a1->getInfoOnComponent(0).c_str()); - ret->setName(a1->getName().c_str()); + ret->setInfoOnComponent(0,a1->getInfoOnComponent(0)); + ret->setName(a1->getName()); return ret; } @@ -5499,12 +5605,12 @@ bool DataArrayDouble::resizeForUnserialization(const std::vector& tinyInfoI */ void DataArrayDouble::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoS) { - setName(tinyInfoS[0].c_str()); + setName(tinyInfoS[0]); if(isAllocated()) { int nbOfCompo=getNumberOfComponents(); for(int i=0;i& v) const checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::isFittingWith : number of components of this should be equal to one !"); - int nbOfTuples(getNumberOfTuples()); const int *w(begin()),*end2(end()); int refVal=-std::numeric_limits::max(); int i=0; @@ -6456,6 +6561,28 @@ void DataArrayInt::sort(bool asc) declareAsNew(); } +/*! + * 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()); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); + ret->alloc(nbOfTuple,1); + const int *src(getConstPointer()); + int *dest(ret->getPointer()); + for(int i=0;igetNumberOfComponents() < 1. @@ -7441,10 +7568,10 @@ DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) for(;jsetName(getName().c_str()); + ret->setName(getName()); for(int i=0;isetInfoOnComponent(i,getInfoOnComponent(i).c_str()); - ret->setName(getName().c_str()); + ret->setInfoOnComponent(i,getInfoOnComponent(i)); + ret->setName(getName()); return ret.retn(); } @@ -8268,13 +8395,14 @@ DataArrayIntIterator *DataArrayInt::iterator() * array using decrRef() as it is no more needed. * \throw If \a this is not allocated. * \throw If \a this->getNumberOfComponents() != 1. + * \sa DataArrayInt::getIdsEqualTuple */ DataArrayInt *DataArrayInt::getIdsEqual(int val) const { checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqual : the array must have only one component, you can call 'rearrange' method before !"); - const int *cptr=getConstPointer(); + const int *cptr(getConstPointer()); MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(0,1); int nbOfTuples=getNumberOfTuples(); for(int i=0;i ret(DataArrayInt::New()); ret->alloc(0,1); int nbOfTuples=getNumberOfTuples(); for(int i=0;igetNumberOfComponents() != std::distance(tupleBg,tupleEnd). + * \throw If \a this->getNumberOfComponents() is equal to 0. + * \sa DataArrayInt::getIdsEqual + */ +DataArrayInt *DataArrayInt::getIdsEqualTuple(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::getIdsEqualTuple : 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::getIdsEqualTuple : number of components should be > 0 !"); + MEDCouplingAutoRefCountObjectPtr 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 @@ -8675,6 +8842,8 @@ DataArrayInt *DataArrayInt::Aggregate(const DataArrayInt *a1, const DataArrayInt * 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 @@ -8829,17 +8998,44 @@ int DataArrayInt::getMinValueInArray() const /*! * Converts every value of \a this array to its absolute value. - * \throw If \a this is not allocated. + * \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(); + int *ptr(getPointer()); + std::size_t nbOfElems(getNbOfElems()); std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun(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(std::abs)); + newArr->copyStringInfoFrom(*this); + return newArr; +} + /*! * Apply a liner function to a given component of \a this array, so that * an array element (x) becomes \f$ a * x + b \f$. @@ -8972,29 +9168,55 @@ void DataArrayInt::applyModulus(int val) * \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::getIdsNotInRange */ DataArrayInt *DataArrayInt::getIdsInRange(int vmin, int vmax) const { checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::getIdsInRange : this must have exactly one component !"); - const int *cptr=getConstPointer(); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(0,1); - int nbOfTuples=getNumberOfTuples(); + const int *cptr(begin()); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(0,1); + int nbOfTuples(getNumberOfTuples()); for(int i=0;i=vmin && *cptrpushBackSilent(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::getIdsInRange + */ +DataArrayInt *DataArrayInt::getIdsNotInRange(int vmin, int vmax) const +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotInRange : this must have exactly one component !"); + const int *cptr(getConstPointer()); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(0,1); + int nbOfTuples(getNumberOfTuples()); + for(int i=0;i=vmax) + 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() ). - */ + * \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(); @@ -9185,7 +9407,7 @@ DataArrayInt *DataArrayInt::Meld(const std::vector& arr) int k=0; for(int i=0;i<(int)a.size();i++) for(int j=0;jsetInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str()); + ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j)); return ret; } @@ -9759,14 +9981,14 @@ from that of \a this and \a * \throw If \a this->getNumberOfComponents() != 1. * \throw If \a this->getNumberOfTuples() == 0. * \throw If \a this is not monotonically increasing. - * \throw If any element of ids in ( \a gb \a end \a step ) points outside the scale in \a this. + * \throw If any element of ids in ( \a bg \a stop \a step ) points outside the scale in \a this. * * \b Example:
- * - \a bg , \a end and \a step : (0,5,2) + * - \a bg , \a stop and \a step : (0,5,2) * - \a this: [0,3,6,10,14,20] * - result array: [0,0,0, 2,2,2,2, 4,4,4,4,4,4] ==
*/ -DataArrayInt *DataArrayInt::buildExplicitArrOfSliceOnScaledArr(int bg, int end, int step) const +DataArrayInt *DataArrayInt::buildExplicitArrOfSliceOnScaledArr(int bg, int stop, int step) const { if(!isAllocated()) throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr : not allocated array !"); @@ -9776,7 +9998,7 @@ DataArrayInt *DataArrayInt::buildExplicitArrOfSliceOnScaledArr(int bg, int end, if(nbOfTuples==0) throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr : number of tuples must be != 0 !"); const int *ids(begin()); - int nbOfEltsInSlc(GetNumberOfItemGivenBESRelative(bg,end,step,"DataArrayInt::buildExplicitArrOfSliceOnScaledArr")),sz(0),pos(bg); + int nbOfEltsInSlc(GetNumberOfItemGivenBESRelative(bg,stop,step,"DataArrayInt::buildExplicitArrOfSliceOnScaledArr")),sz(0),pos(bg); for(int i=0;i=0 && pos& tinyInfoI) */ void DataArrayInt::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoS) { - setName(tinyInfoS[0].c_str()); + setName(tinyInfoS[0]); if(isAllocated()) { int nbOfCompo=tinyInfoI[1]; for(int i=0;i