X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMemArray.txx;h=2f06690734ec66e0b3341d58176442e1988b3c70;hb=2ae2dc6fcedbf241c7637284b3c7bde12aded04a;hp=373e9201b1e7ca1975973ea5c66e4a720d19d31a;hpb=1c9761aeac9192f62f324ad7a04430f2482bc843;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 373e9201b..2f0669073 100755 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -593,7 +593,7 @@ namespace MEDCoupling std::ostringstream oss; oss << "DataArray::GetSlice : sliceId (" << nbOfSlices << ") must be in [0 , nbOfSlices (" << nbOfSlices << ") ) !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - mcIdType nbElems=DataArrayTemplate::GetNumberOfItemGivenBESRelative(start,stop,step,"DataArray::GetSlice"); + mcIdType nbElems=DataArrayTools::GetNumberOfItemGivenBESRelative(start,stop,step,"DataArray::GetSlice"); mcIdType minNbOfElemsPerSlice=nbElems/nbOfSlices; startSlice=start+minNbOfElemsPerSlice*step*sliceId; if(sliceId + MCAuto< typename Traits::ArrayTypeCh > DataArrayTemplate::NewFromArray(const T *arrBegin, const T *arrEnd) + { + using DataArrayT = typename Traits::ArrayTypeCh; + MCAuto< DataArrayT > ret(DataArrayT::New()); + std::size_t nbElts(std::distance(arrBegin,arrEnd)); + ret->alloc(nbElts,1); + std::copy(arrBegin,arrEnd,ret->getPointer()); + return ret; + } template std::vector< MCAuto< typename Traits::ArrayTypeCh > > DataArrayTemplate::explodeComponents() const @@ -826,7 +840,7 @@ namespace MEDCoupling } /*! - * This method reserve nbOfElems elements in memory ( nbOfElems*8 bytes ) \b without impacting the number of tuples in \a this. + * This method reserve nbOfElems elements in memory ( nbOfElems*sizeof(T) ) \b without impacting the number of tuples in \a this. * If \a this has already been allocated, this method checks that \a this has only one component. If not an INTERP_KERNEL::Exception will be thrown. * If \a this has not already been allocated, number of components is set to one. * This method allows to reduce number of reallocations on invocation of DataArrayDouble::pushBackSilent and DataArrayDouble::pushBackValsSilent on \a this. @@ -1059,8 +1073,6 @@ namespace MEDCoupling * 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 DataArrayDouble * - the new instance of DataArrayDouble that the caller - * is to delete using decrRef() as it is no more needed. */ template void DataArrayTemplate::renumberInPlaceR(const mcIdType *new2Old) @@ -1087,10 +1099,12 @@ namespace MEDCoupling } /*! - * Sorts values of the array. + * Sorts values of the array. \b Warning, this method is not const, it alterates \a this content. + * * \param [in] asc - \a true means ascending order, \a false, descending. * \throw If \a this is not allocated. * \throw If \a this->getNumberOfComponents() != 1. + * \sa copySorted */ template void DataArrayTemplate::sort(bool asc) @@ -1105,6 +1119,23 @@ namespace MEDCoupling declareAsNew(); } + /*! + * Sorts values of the array and put the result in a newly allocated returned array. + * This method does not alterate \a this content. + * + * \param [in] asc - \a true means ascending order, \a false, descending. + * \throw If \a this is not allocated. + * \throw If \a this->getNumberOfComponents() != 1. + * \sa sort + */ + template + typename Traits::ArrayTypeCh *DataArrayTemplate::copySortedImpl(bool asc) const + { + MCAuto::ArrayTypeCh> ret(static_cast::ArrayTypeCh *>(this->deepCopy())); + ret->sort(asc); + return ret.retn(); + } + /*! * Returns a copy of \a this array with values permuted as required by \a old2New array. * The values are permuted so that \c new[ \a old2New[ i ]] = \c old[ i ]. @@ -1321,7 +1352,7 @@ namespace MEDCoupling * 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. + * \param [in] newNbOfCompo - 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. @@ -1436,7 +1467,7 @@ namespace MEDCoupling std::size_t newNbOfCompo=compoIds.size(); std::size_t oldNbOfCompo=getNumberOfComponents(); for(std::vector::const_iterator it=compoIds.begin();it!=compoIds.end();it++) - if((*it)<0 || (*it)>=oldNbOfCompo) + if((*it)>=oldNbOfCompo) // (*it) >= 0 (it is a size_t) { std::ostringstream oss; oss << Traits::ArrayTypeName << "::keepSelectedComponents : invalid requested component : " << *it << " whereas it should be in [0," << oldNbOfCompo << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); @@ -2680,7 +2711,7 @@ namespace MEDCoupling T *ptr(this->getPointer()); const T *ptrc(other->begin()); for(mcIdType i=0;ibegin()),*a1Ptr(a1->begin()); T *res(ret->getPointer()); for(mcIdType i=0;icopyStringInfoFrom(*a1); return ret.retn(); } @@ -2954,7 +2985,7 @@ namespace MEDCoupling const T *aMaxPtr(aMax->begin()); T *res=ret->getPointer(); for(mcIdType i=0;icopyStringInfoFrom(*aMax); } else @@ -3370,7 +3401,7 @@ struct NotInRange this->checkAllocated(); T *ptr(this->getPointer()); std::size_t nbOfElems(this->getNbOfElems()); - std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun(std::abs)); + std::transform(ptr,ptr+nbOfElems,ptr,[](T c){return std::abs(c);}); this->declareAsNew(); } @@ -3393,7 +3424,7 @@ struct NotInRange mcIdType nbOfTuples(this->getNumberOfTuples()); std::size_t nbOfComp(this->getNumberOfComponents()); newArr->alloc(nbOfTuples,nbOfComp); - std::transform(this->begin(),this->end(),newArr->getPointer(),std::ptr_fun(std::abs)); + std::transform(this->begin(),this->end(),newArr->getPointer(),[](T c){return std::abs(c);}); newArr->copyStringInfoFrom(*this); return newArr.retn(); } @@ -3634,19 +3665,6 @@ struct NotInRange return new typename Traits::ArrayType; } - /*! - * Returns a newly created array containing a copy of the input array defined by [ \a arrBegin, \a arrEnd ) - */ - template - MCAuto< typename Traits::ArrayType > DataArrayDiscrete::NewFromArray(const T *arrBegin, const T *arrEnd) - { - MCAuto< typename Traits::ArrayType > ret(DataArrayDiscrete::New()); - std::size_t nbElts(std::distance(arrBegin,arrEnd)); - ret->alloc(nbElts,1); - std::copy(arrBegin,arrEnd,ret->getPointer()); - return ret; - } - /*! * Checks if values of \a this and another DataArrayInt are equal. For more info see * \ref MEDCouplingArrayBasicsCompare. @@ -4322,7 +4340,7 @@ struct NotInRange std::set castsDetected; for(mcIdType i=0;i(), work[i])); + rintstart res=std::find_if(bg,end2,std::bind(std::less_equal(),std::placeholders::_1,work[i])); std::size_t pos=std::distance(bg,res); std::size_t pos2=nbOfCast-pos; if(pos2getConstPointer(); mcIdType nbTuple(this->getNumberOfTuples()); std::size_t nbComps(this->getNumberOfComponents()); - if(compId<0 || compId>=nbComps) + if(compId>=nbComps) // compId >= 0 (it is a size_t) throw INTERP_KERNEL::Exception("DataArrayInt::accumulate : Invalid compId specified : No such nb of components !"); T ret=0; for(mcIdType i=0;icheckAllocated(); T *ptr=this->getPointer(); std::size_t nbOfElems=this->getNbOfElems(); - std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::divides(),val)); + std::transform(ptr,ptr+nbOfElems,ptr,std::bind(std::divides(),std::placeholders::_1,val)); this->declareAsNew(); } @@ -5396,7 +5413,7 @@ struct NotInRange this->checkAllocated(); T *ptr=this->getPointer(); std::size_t nbOfElems=this->getNbOfElems(); - std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::modulus(),val)); + std::transform(ptr,ptr+nbOfElems,ptr,std::bind(std::modulus(),std::placeholders::_1,val)); this->declareAsNew(); } @@ -5715,8 +5732,8 @@ struct NotInRange * - \a this : [0, 1, 1, 2, 2, 3, 4, 4, 5, 5, 5, 11] * - \a return is : [0, 1, 3, 5, 6, 8, 11, 12] * - * \return a newly allocated array containing the indexed array of - * \throw if \a this is not allocated or if \a this has not exactly one component or if number of tuples is equal to 0. + * \return a newly allocated array containing the indexed array format of groups by same consecutive value. + * \throw if \a this is not allocated or if \a this has not exactly one component. * \sa DataArrayInt::buildUnique, MEDCouplingSkyLineArray::groupPacks */ template @@ -5725,11 +5742,8 @@ struct NotInRange this->checkAllocated(); if(this->getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::indexOfSameConsecutiveValueGroups : only single component allowed !"); - if(this->getNumberOfTuples()==0) - throw INTERP_KERNEL::Exception("DataArrayInt::indexOfSameConsecutiveValueGroups : number of tuples must be > 0 !"); const T *pt(this->begin()); const T *const ptEnd(this->end()) , * const ptBg(this->begin()); - const T *oldPt(pt); // first find nb of different values in this std::size_t nbOfTuplesOut(0); while( pt != ptEnd ) @@ -6447,7 +6461,7 @@ struct NotInRange T *ptr=this->getPointer(); const T *ptrc=other->getConstPointer(); for(mcIdType i=0;i(),*ptrc++)); + std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind(std::modulus(),std::placeholders::_1,*ptrc++)); } else throw INTERP_KERNEL::Exception(msg); @@ -6688,7 +6702,7 @@ struct NotInRange const T *a1Ptr=a1->getConstPointer(); T *res=ret->getPointer(); for(mcIdType i=0;i(),a2Ptr[i])); + res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind(std::modulus(),std::placeholders::_1,a2Ptr[i])); ret->copyStringInfoFrom(*a1); return ret.retn(); } @@ -7002,7 +7016,7 @@ struct NotInRange ret->alloc(retSz,1); T *pt=ret->getPointer(); *pt++=0; for(typename std::vector::const_iterator it=arrs.begin();it!=arrs.end();it++) - pt=std::transform((*it)->begin()+1,(*it)->end(),pt,std::bind2nd(std::plus(),pt[-1])); + pt=std::transform((*it)->begin()+1,(*it)->end(),pt,std::bind(std::plus(),std::placeholders::_1,pt[-1])); ret->copyStringInfoFrom(*(arrs[0])); return ret.retn(); } @@ -7198,7 +7212,7 @@ struct NotInRange * * \param [in] idsOfSelectStart begin of set of ids of the input extraction (included) * \param [in] idsOfSelectStop end of set of ids of the input extraction (excluded) - * \param [in] idsOfSelectStep + * \param [in] idsOfSelectStep step of set of ids of the input extraction * \param [in] arrIn arr origin array from which the extraction will be done. * \param [in] arrIndxIn is the input index array allowing to walk into \b arrIn * \param [out] arrOut the resulting array