X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMemArray.cxx;h=8459ce8fe5dfac6a83b8e40f4f9c6fd73227f62f;hb=6b29741613e4edeb511ea88701218f90044bc078;hp=8f90e1e173f81d343685c9d84edcc9e023611727;hpb=b902cd4e7cede38e98e714c88980ccb7e9d4ed17;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 8f90e1e17..8459ce8fe 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -37,6 +37,9 @@ typedef double (*MYFUNCPTR)(double); using namespace MEDCoupling; +template class DataArrayTemplate; +template class DataArrayTemplate; + template void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const { @@ -750,43 +753,6 @@ DataArrayDouble *DataArrayDouble::New() return new DataArrayDouble; } -/*! - * Checks if raw data is allocated. Read more on the raw data - * in \ref MEDCouplingArrayBasicsTuplesAndCompo "DataArrays infos" for more information. - * \return bool - \a true if the raw data is allocated, \a false else. - */ -bool DataArrayDouble::isAllocated() const -{ - return getConstPointer()!=0; -} - -/*! - * Checks if raw data is allocated and throws an exception if it is not the case. - * \throw If the raw data is not allocated. - */ -void DataArrayDouble::checkAllocated() const -{ - if(!isAllocated()) - throw INTERP_KERNEL::Exception("DataArrayDouble::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !"); -} - -/*! - * This method desallocated \a this without modification of informations relative to the components. - * After call of this method, DataArrayDouble::isAllocated will return false. - * If \a this is already not allocated, \a this is let unchanged. - */ -void DataArrayDouble::desallocate() -{ - _mem.destroy(); -} - -std::size_t DataArrayDouble::getHeapMemorySizeWithoutChildren() const -{ - std::size_t sz(_mem.getNbOfElemAllocated()); - sz*=sizeof(double); - return DataArray::getHeapMemorySizeWithoutChildren()+sz; -} - /*! * 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. @@ -808,17 +774,6 @@ double DataArrayDouble::doubleValue() const throw INTERP_KERNEL::Exception("DataArrayDouble::doubleValue : DataArrayDouble instance is not allocated !"); } -/*! - * Checks the number of tuples. - * \return bool - \a true if getNumberOfTuples() == 0, \a false else. - * \throw If \a this is not allocated. - */ -bool DataArrayDouble::empty() const -{ - checkAllocated(); - return getNumberOfTuples()==0; -} - /*! * Returns a full copy of \a this. For more info on copying data arrays see * \ref MEDCouplingArrayBasicsCopyDeep. @@ -848,154 +803,6 @@ DataArrayDouble *DataArrayDouble::performCopyOrIncrRef(bool dCpy) const } } -/*! - * Copies all the data from another DataArrayDouble. For more info see - * \ref MEDCouplingArrayBasicsCopyDeepAssign. - * \param [in] other - another instance of DataArrayDouble to copy data from. - * \throw If the \a other is not allocated. - */ -void DataArrayDouble::deepCopyFrom(const DataArrayDouble& other) -{ - other.checkAllocated(); - int nbOfTuples=other.getNumberOfTuples(); - int nbOfComp=other.getNumberOfComponents(); - allocIfNecessary(nbOfTuples,nbOfComp); - std::size_t nbOfElems=(std::size_t)nbOfTuples*nbOfComp; - double *pt=getPointer(); - const double *ptI=other.getConstPointer(); - for(std::size_t i=0;igetNumberOfComponents() != 1. - */ -void DataArrayDouble::sort(bool asc) -{ - checkAllocated(); - if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayDouble::sort : only supported with 'this' array with ONE component !"); - _mem.sort(asc); - declareAsNew(); -} - -/*! - * Reverse the array values. - * \throw If \a this->getNumberOfComponents() < 1. - * \throw If \a this is not allocated. - */ -void DataArrayDouble::reverse() -{ - checkAllocated(); - _mem.reverse(getNumberOfComponents()); - declareAsNew(); -} - /*! * Checks that \a this array is consistently **increasing** or **decreasing** in value, * with at least absolute difference value of |\a eps| at each step. @@ -1386,22 +1151,6 @@ bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other, return _mem.isEqual(other._mem,prec,tmp); } -/*! - * Changes number of tuples in the array. If the new number of tuples is smaller - * than the current number the array is truncated, otherwise the array is extended. - * \param [in] nbOfTuples - new number of tuples. - * \throw If \a this is not allocated. - * \throw If \a nbOfTuples is negative. - */ -void DataArrayDouble::reAlloc(int nbOfTuples) -{ - if(nbOfTuples<0) - throw INTERP_KERNEL::Exception("DataArrayDouble::reAlloc : input new number of tuples should be >=0 !"); - checkAllocated(); - _mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples); - declareAsNew(); -} - /*! * Creates a new DataArrayInt and assigns all (textual and numerical) data of \a this * array to the new one. @@ -1459,99 +1208,6 @@ DataArrayDouble *DataArrayDouble::toNoInterlace() const return ret; } -/*! - * Permutes values of \a this array as required by \a old2New array. The values are - * permuted so that \c new[ \a old2New[ i ]] = \c old[ i ]. Number of tuples 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] old2New - C array of length equal to \a this->getNumberOfTuples() - * giving a new position for i-th old value. - */ -void DataArrayDouble::renumberInPlace(const int *old2New) -{ - checkAllocated(); - int nbTuples=getNumberOfTuples(); - int nbOfCompo=getNumberOfComponents(); - double *tmp=new double[nbTuples*nbOfCompo]; - const double *iptr=getConstPointer(); - for(int i=0;i=0 && vgetNumberOfTuples() - * 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. - */ -void DataArrayDouble::renumberInPlaceR(const int *new2Old) -{ - checkAllocated(); - int nbTuples=getNumberOfTuples(); - int nbOfCompo=getNumberOfComponents(); - double *tmp=new double[nbTuples*nbOfCompo]; - const double *iptr=getConstPointer(); - for(int i=0;i=0 && vgetNumberOfTuples() - * giving a new position for i-th old value. - * \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::renumber(const int *old2New) const -{ - checkAllocated(); - int nbTuples=getNumberOfTuples(); - int nbOfCompo=getNumberOfComponents(); - MCAuto ret=DataArrayDouble::New(); - ret->alloc(nbTuples,nbOfCompo); - ret->copyStringInfoFrom(*this); - const double *iptr=getConstPointer(); - double *optr=ret->getPointer(); - for(int i=0;icopyStringInfoFrom(*this); - return ret.retn(); -} - /*! * 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 @@ -2959,34 +2615,6 @@ void DataArrayDouble::setContigPartOfSelectedValuesSlice(int tupleIdStart, const } } -/*! - * Returns a value located at specified tuple and component. - * This method is equivalent to DataArrayDouble::getIJ() except that validity of - * parameters is checked. So this method is safe but expensive if used to go through - * all values of \a this. - * \param [in] tupleId - index of tuple of interest. - * \param [in] compoId - index of component of interest. - * \return double - value located by \a tupleId and \a compoId. - * \throw If \a this is not allocated. - * \throw If condition ( 0 <= tupleId < this->getNumberOfTuples() ) is violated. - * \throw If condition ( 0 <= compoId < this->getNumberOfComponents() ) is violated. - */ -double DataArrayDouble::getIJSafe(int tupleId, int compoId) const -{ - checkAllocated(); - if(tupleId<0 || tupleId>=getNumberOfTuples()) - { - std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - if(compoId<0 || compoId>=getNumberOfComponents()) - { - std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - return _mem[tupleId*_info_on_compo.size()+compoId]; -} - /*! * Returns the first value of \a this. * \return double - the last value of \a this array. @@ -3035,30 +2663,13 @@ void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &ar } } -/*! - * Sets a C array to be used as raw data of \a this. The previously set info - * of components is retained and re-sized. - * For more info see \ref MEDCouplingArraySteps1. - * \param [in] array - the C array to be used as raw data of \a this. - * \param [in] ownership - if \a true, \a array will be deallocated at destruction of \a this. - * \param [in] type - specifies how to deallocate \a array. If \a type == MEDCoupling::CPP_DEALLOC, - * \c delete [] \c array; will be called. If \a type == MEDCoupling::C_DEALLOC, - * \c free(\c array ) will be called. - * \param [in] nbOfTuple - new number of tuples in \a this. - * \param [in] nbOfCompo - new number of components in \a this. - */ -void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) +void DataArrayDouble::aggregate(const DataArrayDouble *other) { - _info_on_compo.resize(nbOfCompo); - _mem.useArray(array,ownership,type,(std::size_t)nbOfTuple*nbOfCompo); - declareAsNew(); -} - -void DataArrayDouble::useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo) -{ - _info_on_compo.resize(nbOfCompo); - _mem.useExternalArrayWithRWAccess(array,(std::size_t)nbOfTuple*nbOfCompo); - declareAsNew(); + 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()); } /*! @@ -5972,43 +5583,6 @@ DataArrayInt *DataArrayInt::New() return new DataArrayInt; } -/*! - * Checks if raw data is allocated. Read more on the raw data - * in \ref MEDCouplingArrayBasicsTuplesAndCompo "DataArrays infos" for more information. - * \return bool - \a true if the raw data is allocated, \a false else. - */ -bool DataArrayInt::isAllocated() const -{ - return getConstPointer()!=0; -} - -/*! - * Checks if raw data is allocated and throws an exception if it is not the case. - * \throw If the raw data is not allocated. - */ -void DataArrayInt::checkAllocated() const -{ - if(!isAllocated()) - throw INTERP_KERNEL::Exception("DataArrayInt::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !"); -} - -/*! - * This method desallocated \a this without modification of informations relative to the components. - * After call of this method, DataArrayInt::isAllocated will return false. - * If \a this is already not allocated, \a this is let unchanged. - */ -void DataArrayInt::desallocate() -{ - _mem.destroy(); -} - -std::size_t DataArrayInt::getHeapMemorySizeWithoutChildren() const -{ - std::size_t sz(_mem.getNbOfElemAllocated()); - sz*=sizeof(int); - return DataArray::getHeapMemorySizeWithoutChildren()+sz; -} - /*! * 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. @@ -6051,17 +5625,6 @@ int DataArrayInt::getHashCode() const return ret+ret0; } -/*! - * Checks the number of tuples. - * \return bool - \a true if getNumberOfTuples() == 0, \a false else. - * \throw If \a this is not allocated. - */ -bool DataArrayInt::empty() const -{ - checkAllocated(); - return getNumberOfTuples()==0; -} - /*! * Returns a full copy of \a this. For more info on copying data arrays see * \ref MEDCouplingArrayBasicsCopyDeep. @@ -6090,154 +5653,6 @@ DataArrayInt *DataArrayInt::performCopyOrIncrRef(bool dCpy) const } } -/*! - * Copies all the data from another DataArrayInt. For more info see - * \ref MEDCouplingArrayBasicsCopyDeepAssign. - * \param [in] other - another instance of DataArrayInt to copy data from. - * \throw If the \a other is not allocated. - */ -void DataArrayInt::deepCopyFrom(const DataArrayInt& other) -{ - other.checkAllocated(); - int nbOfTuples=other.getNumberOfTuples(); - int nbOfComp=other.getNumberOfComponents(); - allocIfNecessary(nbOfTuples,nbOfComp); - std::size_t nbOfElems=(std::size_t)nbOfTuples*nbOfComp; - int *pt=getPointer(); - const int *ptI=other.getConstPointer(); - for(std::size_t i=0;i& v) const * 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& vec) const { @@ -6923,18 +6325,24 @@ void DataArrayInt::switchOnTupleEqualTo(int val, std::vector& vec) const } /*! - * Sorts values of the array. - * \param [in] asc - \a true means ascending order, \a false, descending. - * \throw If \a this is not allocated. - * \throw If \a this->getNumberOfComponents() != 1. + * 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::sort(bool asc) +void DataArrayInt::switchOnTupleNotEqualTo(int val, std::vector& vec) const { checkAllocated(); if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::sort : only supported with 'this' array with ONE component !"); - _mem.sort(asc); - declareAsNew(); + 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;igetNumberOfComponents() < 1. - * \throw If \a this is not allocated. - */ -void DataArrayInt::reverse() -{ - checkAllocated(); - _mem.reverse(getNumberOfComponents()); - declareAsNew(); -} - /*! * Checks that \a this array is consistently **increasing** or **decreasing** in value. * If not an exception is thrown. @@ -7133,30 +6529,13 @@ DataArrayInt *DataArrayInt::buildPermutationArr(const DataArrayInt& other) const return ret.retn(); } -/*! - * Sets a C array to be used as raw data of \a this. The previously set info - * of components is retained and re-sized. - * For more info see \ref MEDCouplingArraySteps1. - * \param [in] array - the C array to be used as raw data of \a this. - * \param [in] ownership - if \a true, \a array will be deallocated at destruction of \a this. - * \param [in] type - specifies how to deallocate \a array. If \a type == MEDCoupling::CPP_DEALLOC, - * \c delete [] \c array; will be called. If \a type == MEDCoupling::C_DEALLOC, - * \c free(\c array ) will be called. - * \param [in] nbOfTuple - new number of tuples in \a this. - * \param [in] nbOfCompo - new number of components in \a this. - */ -void DataArrayInt::useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) -{ - _info_on_compo.resize(nbOfCompo); - _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo); - declareAsNew(); -} - -void DataArrayInt::useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo) +void DataArrayInt::aggregate(const DataArrayInt *other) { - _info_on_compo.resize(nbOfCompo); - _mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo); - declareAsNew(); + 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()); } /*! @@ -7201,99 +6580,6 @@ DataArrayInt *DataArrayInt::toNoInterlace() const return ret; } -/*! - * Permutes values of \a this array as required by \a old2New array. The values are - * permuted so that \c new[ \a old2New[ i ]] = \c old[ i ]. Number of tuples 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] old2New - C array of length equal to \a this->getNumberOfTuples() - * giving a new position for i-th old value. - */ -void DataArrayInt::renumberInPlace(const int *old2New) -{ - checkAllocated(); - int nbTuples=getNumberOfTuples(); - int nbOfCompo=getNumberOfComponents(); - int *tmp=new int[nbTuples*nbOfCompo]; - const int *iptr=getConstPointer(); - for(int i=0;i=0 && vgetNumberOfTuples() - * 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. - */ -void DataArrayInt::renumberInPlaceR(const int *new2Old) -{ - checkAllocated(); - int nbTuples=getNumberOfTuples(); - int nbOfCompo=getNumberOfComponents(); - int *tmp=new int[nbTuples*nbOfCompo]; - const int *iptr=getConstPointer(); - for(int i=0;i=0 && vgetNumberOfTuples() - * giving a new position for i-th old value. - * \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::renumber(const int *old2New) const -{ - checkAllocated(); - int nbTuples=getNumberOfTuples(); - int nbOfCompo=getNumberOfComponents(); - MCAuto ret=DataArrayInt::New(); - ret->alloc(nbTuples,nbOfCompo); - ret->copyStringInfoFrom(*this); - const int *iptr=getConstPointer(); - int *optr=ret->getPointer(); - for(int i=0;icopyStringInfoFrom(*this); - return ret.retn(); -} - /*! * 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 @@ -7976,23 +7262,6 @@ DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) return ret.retn(); } -/*! - * Changes number of tuples in the array. If the new number of tuples is smaller - * than the current number the array is truncated, otherwise the array is extended. - * \param [in] nbOfTuples - new number of tuples. - * \throw If \a this is not allocated. - * \throw If \a nbOfTuples is negative. - */ -void DataArrayInt::reAlloc(int nbOfTuples) -{ - if(nbOfTuples<0) - throw INTERP_KERNEL::Exception("DataArrayInt::reAlloc : input new number of tuples should be >=0 !"); - checkAllocated(); - _mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples); - declareAsNew(); -} - - /*! * Returns a copy of \a this array composed of selected components. * The new DataArrayInt has the same number of tuples but includes components @@ -8719,34 +7988,6 @@ void DataArrayInt::setContigPartOfSelectedValuesSlice(int tupleIdStart, const Da } } -/*! - * Returns a value located at specified tuple and component. - * This method is equivalent to DataArrayInt::getIJ() except that validity of - * parameters is checked. So this method is safe but expensive if used to go through - * all values of \a this. - * \param [in] tupleId - index of tuple of interest. - * \param [in] compoId - index of component of interest. - * \return double - value located by \a tupleId and \a compoId. - * \throw If \a this is not allocated. - * \throw If condition ( 0 <= tupleId < this->getNumberOfTuples() ) is violated. - * \throw If condition ( 0 <= compoId < this->getNumberOfComponents() ) is violated. - */ -int DataArrayInt::getIJSafe(int tupleId, int compoId) const -{ - checkAllocated(); - if(tupleId<0 || tupleId>=getNumberOfTuples()) - { - std::ostringstream oss; oss << "DataArrayInt::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - if(compoId<0 || compoId>=getNumberOfComponents()) - { - std::ostringstream oss; oss << "DataArrayInt::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - return _mem[tupleId*_info_on_compo.size()+compoId]; -} - /*! * Returns the first value of \a this. * \return int - the last value of \a this array. @@ -10757,7 +9998,8 @@ void DataArrayInt::sortEachPairToMakeALinkedList() } else {//here we are sure to have (std::count(conn,conn+4,conn[1])==2) - std::swap(conn[2],conn[3]); + if(conn[1]==conn[3]) + std::swap(conn[2],conn[3]); } } }