From: Anthony Geay Date: Thu, 4 May 2017 21:33:35 +0000 (+0200) Subject: Code Factorization X-Git-Tag: V8_4_0a1~58 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5d735f30f7338e7784fbe27497c48f4c628ed9b6;p=tools%2Fmedcoupling.git Code Factorization --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 968656cfb..a6e0f23e7 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -1123,85 +1123,6 @@ bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other, return _mem.isEqual(other._mem,prec,tmp); } -/*! - * Returns a new DataArrayDouble 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 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. - */ -DataArrayDouble *DataArrayDouble::fromNoInterlace() const -{ - if(_mem.isNull()) - throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !"); - double *tab=_mem.fromNoInterlace(getNumberOfComponents()); - DataArrayDouble *ret=DataArrayDouble::New(); - ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents()); - return ret; -} - -/*! - * Returns a new DataArrayDouble 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 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. - */ -DataArrayDouble *DataArrayDouble::toNoInterlace() const -{ - if(_mem.isNull()) - throw INTERP_KERNEL::Exception("DataArrayDouble::toNoInterlace : Not defined array !"); - double *tab=_mem.toNoInterlace(getNumberOfComponents()); - DataArrayDouble *ret=DataArrayDouble::New(); - ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents()); - return ret; -} - -/*! - * 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 DataArrayDouble 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_mcdataarraydouble_meldwith "Here is a C++ example". - * - * \ref py_mcdataarraydouble_meldwith "Here is a Python example". - * \endif - */ -void DataArrayDouble::meldWith(const DataArrayDouble *other) -{ - checkAllocated(); - other->checkAllocated(); - int nbOfTuples=getNumberOfTuples(); - if(nbOfTuples!=other->getNumberOfTuples()) - throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !"); - int nbOfComp1=getNumberOfComponents(); - int nbOfComp2=other->getNumberOfComponents(); - double *newArr=(double *)malloc((nbOfTuples*(nbOfComp1+nbOfComp2))*sizeof(double)); - double *w=newArr; - const double *inp1=getConstPointer(); - const double *inp2=other->getConstPointer(); - for(int i=0;i compIds(nbOfComp2); - for(int i=0;igetNumberOfTuples. - * \throw if \a this is not allocated or if \a this has not number of components set to one or if \a nbTimes is lower than 1. - */ -DataArrayDouble *DataArrayDouble::duplicateEachTupleNTimes(int nbTimes) const -{ - checkAllocated(); - if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : this should have only one component !"); - if(nbTimes<1) - throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : nb times should be >= 1 !"); - int nbTuples=getNumberOfTuples(); - const double *inPtr=getConstPointer(); - MCAuto ret=DataArrayDouble::New(); ret->alloc(nbTimes*nbTuples,1); - double *retPtr=ret->getPointer(); - for(int i=0;icopyStringInfoFrom(*this); - return ret.retn(); -} - /*! * This methods returns the minimal distance between the two set of points \a this and \a other. * So \a this and \a other have to have the same number of components. If not an INTERP_KERNEL::Exception will be thrown. @@ -1532,27 +1425,6 @@ void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std: nc[nbOfCompo*i+compoIds[j]]=*ac; } -void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet) -{ - if(newArray!=arrayToSet) - { - if(arrayToSet) - arrayToSet->decrRef(); - arrayToSet=newArray; - if(arrayToSet) - arrayToSet->incrRef(); - } -} - -void DataArrayDouble::aggregate(const DataArrayDouble *other) -{ - if(!other) - throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : null pointer !"); - if(getNumberOfComponents()!=other->getNumberOfComponents()) - throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : mismatch number of components !"); - _mem.insertAtTheEnd(other->begin(),other->end()); -} - /*! * Checks if 0.0 value is present in \a this array. If it is the case, an exception * is thrown. @@ -4855,57 +4727,6 @@ DataArrayInt *DataArrayInt::indicesOfSubPart(const DataArrayInt& partOfThis) con 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 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 @@ -5227,47 +5048,6 @@ bool DataArrayInt::hasUniqueValues() const return true; } -/*! - * 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 compIds(nbOfComp2); - for(int i=0;idecrRef(); - arrayToSet=newArray; - if(arrayToSet) - arrayToSet->incrRef(); - } -} - DataArrayIntIterator *DataArrayInt::iterator() { return new DataArrayIntIterator(this); @@ -7073,34 +6835,6 @@ MCAuto DataArrayInt::fromLinkedListOfPairToList() const return ret; } -/*! - * - * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayInt instance. - * \a nbTimes should be at least equal to 1. - * \return a newly allocated DataArrayInt having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples. - * \throw if \a this is not allocated or if \a this has not number of components set to one or if \a nbTimes is lower than 1. - */ -DataArrayInt *DataArrayInt::duplicateEachTupleNTimes(int nbTimes) const -{ - checkAllocated(); - if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : this should have only one component !"); - if(nbTimes<1) - throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : nb times should be >= 1 !"); - int nbTuples=getNumberOfTuples(); - const int *inPtr=getConstPointer(); - MCAuto ret=DataArrayInt::New(); ret->alloc(nbTimes*nbTuples,1); - int *retPtr=ret->getPointer(); - for(int i=0;icopyStringInfoFrom(*this); - return ret.retn(); -} - /*! * This method returns all different values found in \a this. This method throws if \a this has not been allocated. * But the number of components can be different from one. diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 77ba020ec..81b5784c3 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -283,6 +283,11 @@ namespace MEDCoupling T getMaxValueInArray() const; T getMinValue(int& tupleId) const; T getMinValueInArray() const; + MEDCOUPLING_EXPORT void getTuple(int tupleId, T *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } + template + void insertAtTheEnd(InputIterator first, InputIterator last); + MEDCOUPLING_EXPORT static void SetArrayIn(typename Traits::ArrayType *newArray, typename Traits::ArrayType* &arrayToSet); + MEDCOUPLING_EXPORT void writeOnPlace(std::size_t id, T element0, const T *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } public: MEDCOUPLING_EXPORT MemArray& accessToMemArray() { return _mem; } MEDCOUPLING_EXPORT const MemArray& accessToMemArray() const { return _mem; } @@ -322,6 +327,11 @@ namespace MEDCoupling MEDCOUPLING_EXPORT MCAuto findIdsLowerOrEqualTo(T val) const; MEDCOUPLING_EXPORT MCAuto findIdsLowerThan(T val) const; MEDCOUPLING_EXPORT DataArrayInt *findIdsStrictlyNegative() const; + MEDCOUPLING_EXPORT typename Traits::ArrayType *fromNoInterlace() const; + MEDCOUPLING_EXPORT typename Traits::ArrayType *toNoInterlace() const; + MEDCOUPLING_EXPORT void meldWith(const typename Traits::ArrayType *other); + MEDCOUPLING_EXPORT typename Traits::ArrayType *duplicateEachTupleNTimes(int nbTimes) const; + MEDCOUPLING_EXPORT void aggregate(const typename Traits::ArrayType *other); protected: static typename Traits::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits::ArrayType& self); template @@ -409,30 +419,20 @@ namespace MEDCoupling MEDCOUPLING_EXPORT bool isEqual(const DataArrayDouble& other, double prec) const; MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const; - MEDCOUPLING_EXPORT DataArrayDouble *fromNoInterlace() const; - MEDCOUPLING_EXPORT DataArrayDouble *toNoInterlace() const; MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP::mySelectByTupleId(new2OldBg,new2OldEnd); } MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const DataArrayInt& di) const { return DataArrayTemplateFP::mySelectByTupleId(di); } MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); } MEDCOUPLING_EXPORT DataArrayDouble *keepSelectedComponents(const std::vector& compoIds) const { return DataArrayTemplateFP::myKeepSelectedComponents(compoIds); } MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplateFP::mySelectByTupleIdSafeSlice(bg,end2,step); } MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleRanges(const std::vector >& ranges) const { return DataArrayTemplateFP::mySelectByTupleRanges(ranges); } - MEDCOUPLING_EXPORT void meldWith(const DataArrayDouble *other); MEDCOUPLING_EXPORT bool areIncludedInMe(const DataArrayDouble *other, double prec, DataArrayInt *&tupleIds) const; MEDCOUPLING_EXPORT void findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const; MEDCOUPLING_EXPORT double minimalDistanceTo(const DataArrayDouble *other, int& thisTupleId, int& otherTupleId) const; - MEDCOUPLING_EXPORT DataArrayDouble *duplicateEachTupleNTimes(int nbTimes) const; MEDCOUPLING_EXPORT DataArrayDouble *getDifferentValues(double prec, int limitTupleId=-1) const; MEDCOUPLING_EXPORT DataArrayInt *findClosestTupleId(const DataArrayDouble *other) const; MEDCOUPLING_EXPORT DataArrayInt *computeNbOfInteractionsWith(const DataArrayDouble *otherBBoxFrmt, double eps) const; MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayDouble *a, const std::vector& compoIds); - MEDCOUPLING_EXPORT void getTuple(int tupleId, double *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } - MEDCOUPLING_EXPORT static void SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet); MEDCOUPLING_EXPORT DataArrayDoubleIterator *iterator(); - template - void insertAtTheEnd(InputIterator first, InputIterator last); - MEDCOUPLING_EXPORT void aggregate(const DataArrayDouble *other); - MEDCOUPLING_EXPORT void writeOnPlace(std::size_t id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } MEDCOUPLING_EXPORT void checkNoNullValues() const; MEDCOUPLING_EXPORT void getMinMaxPerComponent(double *bounds) const; MEDCOUPLING_EXPORT DataArrayDouble *computeBBoxPerTuple(double epsilon=0.0) const; @@ -567,8 +567,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const; MEDCOUPLING_EXPORT DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const; MEDCOUPLING_EXPORT DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const; - MEDCOUPLING_EXPORT DataArrayInt *fromNoInterlace() const; - MEDCOUPLING_EXPORT DataArrayInt *toNoInterlace() const; MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate::mySelectByTupleId(new2OldBg,new2OldEnd); } MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId(const DataArrayInt& di) const { return DataArrayTemplate::mySelectByTupleId(di); } MEDCOUPLING_EXPORT DataArrayInt *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); } @@ -583,10 +581,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT bool isIota(int sizeExpected) const; MEDCOUPLING_EXPORT bool isUniform(int val) const; MEDCOUPLING_EXPORT bool hasUniqueValues() const; - MEDCOUPLING_EXPORT void meldWith(const DataArrayInt *other); MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayInt *a, const std::vector& compoIds); - MEDCOUPLING_EXPORT void getTuple(int tupleId, int *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } - MEDCOUPLING_EXPORT static void SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet); MEDCOUPLING_EXPORT DataArrayIntIterator *iterator(); MEDCOUPLING_EXPORT DataArrayInt *findIdsEqual(int val) const; MEDCOUPLING_EXPORT DataArrayInt *findIdsNotEqual(int val) const; @@ -643,14 +638,9 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayInt *findIdInRangeForEachTuple(const DataArrayInt *ranges) const; MEDCOUPLING_EXPORT void sortEachPairToMakeALinkedList(); MEDCOUPLING_EXPORT MCAuto fromLinkedListOfPairToList() const; - MEDCOUPLING_EXPORT DataArrayInt *duplicateEachTupleNTimes(int nbTimes) const; MEDCOUPLING_EXPORT DataArrayInt *getDifferentValues() const; MEDCOUPLING_EXPORT std::vector partitionByDifferentValues(std::vector& differentIds) const; MEDCOUPLING_EXPORT std::vector< std::pair > splitInBalancedSlices(int nbOfSlices) const; - template - void insertAtTheEnd(InputIterator first, InputIterator last); - MEDCOUPLING_EXPORT void aggregate(const DataArrayInt *other); - MEDCOUPLING_EXPORT void writeOnPlace(std::size_t id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } MEDCOUPLING_EXPORT static DataArrayInt *Modulus(const DataArrayInt *a1, const DataArrayInt *a2); MEDCOUPLING_EXPORT void modulusEqual(const DataArrayInt *other); MEDCOUPLING_EXPORT static DataArrayInt *Pow(const DataArrayInt *a1, const DataArrayInt *a2); @@ -706,7 +696,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT bool isUniform(char val) const; MEDCOUPLING_EXPORT void meldWith(const DataArrayChar *other); MEDCOUPLING_EXPORT DataArray *selectByTupleRanges(const std::vector >& ranges) const { return DataArrayTemplate::mySelectByTupleRanges(ranges); } - MEDCOUPLING_EXPORT void getTuple(int tupleId, char *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } MEDCOUPLING_EXPORT DataArrayInt *findIdsEqual(char val) const; MEDCOUPLING_EXPORT DataArrayInt *findIdsNotEqual(char val) const; MEDCOUPLING_EXPORT int findIdSequence(const std::vector& vals) const; @@ -721,8 +710,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT static DataArrayChar *Aggregate(const std::vector& arr); MEDCOUPLING_EXPORT static DataArrayChar *Meld(const DataArrayChar *a1, const DataArrayChar *a2); MEDCOUPLING_EXPORT static DataArrayChar *Meld(const std::vector& arr); - template - void insertAtTheEnd(InputIterator first, InputIterator last); MEDCOUPLING_EXPORT MemArray& accessToMemArray() { return _mem; } MEDCOUPLING_EXPORT const MemArray& accessToMemArray() const { return _mem; } public: @@ -955,50 +942,21 @@ namespace MEDCoupling pointer[_nb_of_elem++]=*first++; } } - - template - void DataArrayDouble::insertAtTheEnd(InputIterator first, InputIterator last) - { - int nbCompo(getNumberOfComponents()); - if(nbCompo==1) - _mem.insertAtTheEnd(first,last); - else if(nbCompo==0) - { - _info_on_compo.resize(1); - _mem.insertAtTheEnd(first,last); - } - else - throw INTERP_KERNEL::Exception("DataArrayDouble::insertAtTheEnd : not available for DataArrayDouble with number of components different than 1 !"); - } - - template - void DataArrayInt::insertAtTheEnd(InputIterator first, InputIterator last) - { - int nbCompo(getNumberOfComponents()); - if(nbCompo==1) - _mem.insertAtTheEnd(first,last); - else if(nbCompo==0) - { - _info_on_compo.resize(1); - _mem.insertAtTheEnd(first,last); - } - else - throw INTERP_KERNEL::Exception("DataArrayInt::insertAtTheEnd : not available for DataArrayInt with number of components different than 1 !"); - } + template template - void DataArrayChar::insertAtTheEnd(InputIterator first, InputIterator last) + void DataArrayTemplate::insertAtTheEnd(InputIterator first, InputIterator last) { - int nbCompo(getNumberOfComponents()); + int nbCompo(this->getNumberOfComponents()); if(nbCompo==1) - _mem.insertAtTheEnd(first,last); + this->_mem.insertAtTheEnd(first,last); else if(nbCompo==0) { - _info_on_compo.resize(1); - _mem.insertAtTheEnd(first,last); + this->_info_on_compo.resize(1); + this->_mem.insertAtTheEnd(first,last); } else - throw INTERP_KERNEL::Exception("DataArrayChar::insertAtTheEnd : not available for DataArrayChar with number of components different than 1 !"); + throw INTERP_KERNEL::Exception("DataArrayDouble::insertAtTheEnd : not available for DataArrayDouble with number of components different than 1 !"); } } diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 7643ad169..1f45f1325 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -2323,6 +2323,25 @@ namespace MEDCoupling std::reverse(_info_on_compo.begin(),_info_on_compo.end()); } + /*! + * 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. + */ + template + void DataArrayTemplate::SetArrayIn(typename Traits::ArrayType *newArray, typename Traits::ArrayType* &arrayToSet) + { + if(newArray!=arrayToSet) + { + if(arrayToSet) + arrayToSet->decrRef(); + arrayToSet=newArray; + if(arrayToSet) + arrayToSet->incrRef(); + } + } + template template MCAuto< typename Traits::ArrayType > DataArrayTemplateClassic::convertToOtherTypeOfArr() const @@ -3010,6 +3029,125 @@ struct NotInRange ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j)); return ret; } + + /*! + * Returns a new DataArrayDouble 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 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. + */ + template + typename Traits::ArrayType *DataArrayTemplateClassic::fromNoInterlace() const + { + if(this->_mem.isNull()) + throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !"); + T *tab(this->_mem.fromNoInterlace(this->getNumberOfComponents())); + MCAuto::ArrayType> ret(Traits::ArrayType::New()); + ret->useArray(tab,true,C_DEALLOC,this->getNumberOfTuples(),this->getNumberOfComponents()); + return ret.retn(); + } + + /*! + * Returns a new DataArrayDouble 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 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. + */ + template + typename Traits::ArrayType *DataArrayTemplateClassic::toNoInterlace() const + { + if(this->_mem.isNull()) + throw INTERP_KERNEL::Exception("DataArrayDouble::toNoInterlace : Not defined array !"); + T *tab(this->_mem.toNoInterlace(this->getNumberOfComponents())); + MCAuto::ArrayType> ret(Traits::ArrayType::New()); + ret->useArray(tab,true,C_DEALLOC,this->getNumberOfTuples(),this->getNumberOfComponents()); + 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 DataArrayDouble 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_mcdataarraydouble_meldwith "Here is a C++ example". + * + * \ref py_mcdataarraydouble_meldwith "Here is a Python example". + * \endif + */ + template + void DataArrayTemplateClassic::meldWith(const typename Traits::ArrayType *other) + { + this->checkAllocated(); + other->checkAllocated(); + int nbOfTuples(this->getNumberOfTuples()); + if(nbOfTuples!=other->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !"); + int nbOfComp1(this->getNumberOfComponents()),nbOfComp2(other->getNumberOfComponents()); + T *newArr=(T *)malloc((nbOfTuples*(nbOfComp1+nbOfComp2))*sizeof(T)); + T *w=newArr; + const T *inp1(this->begin()),*inp2(other->begin()); + for(int i=0;iuseArray(newArr,true,C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2); + std::vector compIds(nbOfComp2); + for(int i=0;icopyPartOfStringInfoFrom2(compIds,*other); + } + + /*! + * + * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayDouble instance. + * \a nbTimes should be at least equal to 1. + * \return a newly allocated DataArrayDouble having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples. + * \throw if \a this is not allocated or if \a this has not number of components set to one or if \a nbTimes is lower than 1. + */ + template + typename Traits::ArrayType *DataArrayTemplateClassic::duplicateEachTupleNTimes(int nbTimes) const + { + this->checkAllocated(); + if(this->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : this should have only one component !"); + if(nbTimes<1) + throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : nb times should be >= 1 !"); + int nbTuples(this->getNumberOfTuples()); + const T *inPtr(this->begin()); + MCAuto::ArrayType> ret(Traits::ArrayType::New()); ret->alloc(nbTimes*nbTuples,1); + T *retPtr(ret->getPointer()); + for(int i=0;icopyStringInfoFrom(*this); + return ret.retn(); + } + + template + void DataArrayTemplateClassic::aggregate(const typename Traits::ArrayType *other) + { + if(!other) + throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : null pointer !"); + if(this->getNumberOfComponents()!=other->getNumberOfComponents()) + throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : mismatch number of components !"); + this->_mem.insertAtTheEnd(other->begin(),other->end()); + } /*! * Checks if all values in \a this array are equal to \a val at precision \a eps. diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 558a8f3a9..55fd117f1 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -3078,7 +3078,7 @@ class MEDLoaderTest3(unittest.TestCase): self.assertTrue(not ff0.getUndergroundDataArray().isAllocated()) self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]']) heap_memory_ref=ff0.getHeapMemorySize() - self.assertIn(heap_memory_ref,xrange(182,465+2*strMulFac)) + self.assertIn(heap_memory_ref,xrange(182,481+2*strMulFac)) ff0.loadArrays() ## arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2) self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14)) @@ -3087,7 +3087,7 @@ class MEDLoaderTest3(unittest.TestCase): ff0=MEDFileField1TS(fname,"FieldCellPfl",False) self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"]) heap_memory_ref=ff0.getHeapMemorySize() - self.assertIn(heap_memory_ref,xrange(350,520+6*strMulFac)) + self.assertIn(heap_memory_ref,xrange(350,536+6*strMulFac)) ff0.loadArrays() ## arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2) self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14)) @@ -3105,7 +3105,7 @@ class MEDLoaderTest3(unittest.TestCase): self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5) self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14)) heap_memory_ref=ff0.getHeapMemorySize() - self.assertIn(heap_memory_ref,xrange(1100,1384+2*strMulFac)) + self.assertIn(heap_memory_ref,xrange(1100,1400+2*strMulFac)) ff0.unloadArrays() hmd=ff0.getHeapMemorySize()-heap_memory_ref self.assertEqual(hmd,-800) # -50*8*2 @@ -3114,7 +3114,7 @@ class MEDLoaderTest3(unittest.TestCase): # ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False) heap_memory_ref=ff0.getHeapMemorySize() - self.assertIn(heap_memory_ref,xrange(299,520+6*strMulFac)) + self.assertIn(heap_memory_ref,xrange(299,536+6*strMulFac)) ff0.loadArrays() ## self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14)) self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2) @@ -3131,14 +3131,14 @@ class MEDLoaderTest3(unittest.TestCase): # ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False) heap_memory_ref=ff0.getHeapMemorySize() - self.assertIn(heap_memory_ref,xrange(5536,8212+(80+26+1)*strMulFac)) + self.assertIn(heap_memory_ref,xrange(5536,10242+(80+26+1)*strMulFac)) ff0.loadArrays() self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2) del ff0 # ffs=MEDFileFields(fname,False) heap_memory_ref=ffs.getHeapMemorySize() - self.assertIn(heap_memory_ref,xrange(5335,9031+(80+50+len(ffs))*strMulFac)) + self.assertIn(heap_memory_ref,xrange(5335,11507+(80+50+len(ffs))*strMulFac)) ffs.loadArrays() self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2) pass