From c314609174e8e4376af3dd9e4698e2a4814f38bb Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 24 Jul 2013 14:14:40 +0000 Subject: [PATCH] Target MEDReader --- src/MEDCoupling/MEDCouplingMemArray.hxx | 4 + src/MEDCoupling/MEDCouplingMemArrayChar.cxx | 31 ++++- src/MEDCoupling_Swig/MEDCouplingCommon.i | 13 +- src/MEDCoupling_Swig/MEDCouplingMemArray.i | 144 ++++++-------------- 4 files changed, 75 insertions(+), 117 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index a789c9631..fdf534775 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -149,6 +149,9 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT virtual void setContigPartOfSelectedValues2(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step) throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT virtual DataArray *selectByTupleRanges(const std::vector >& ranges) const throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT virtual DataArray *keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception) = 0; + MEDCOUPLING_EXPORT virtual DataArray *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const = 0; + MEDCOUPLING_EXPORT virtual DataArray *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception) = 0; + MEDCOUPLING_EXPORT virtual DataArray *selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT void checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception); @@ -673,6 +676,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayChar *renumber(const int *old2New) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayChar *renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayChar *renumberAndReduce(const int *old2NewBg, int newNbOfTuple) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayChar *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const; MEDCOUPLING_EXPORT DataArrayChar *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayChar *selectByTupleId2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isUniform(char val) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingMemArrayChar.cxx b/src/MEDCoupling/MEDCouplingMemArrayChar.cxx index c718b3a51..5c827bf8b 100644 --- a/src/MEDCoupling/MEDCouplingMemArrayChar.cxx +++ b/src/MEDCoupling/MEDCouplingMemArrayChar.cxx @@ -507,6 +507,27 @@ DataArrayChar *DataArrayChar::renumberAndReduce(const int *old2New, int newNbOfT return ret.retn(); } +/*! + * Returns a shorten and permuted copy of \a this array. The new DataArrayChar 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 MEDCouplingArrayRenumbering. + * \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 DataArrayChar * - the new instance of DataArrayChar that the caller + * is to delete using decrRef() as it is no more needed. + */ +DataArrayChar *DataArrayChar::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const +{ + return selectByTupleIdSafe(new2OldBg,new2OldEnd); +} + /*! * Returns a shorten and permuted copy of \a this array. The new DataArrayChar is * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by @@ -671,7 +692,7 @@ DataArrayChar *DataArrayChar::substr(int tupleIdBg, int tupleIdEnd) const throw( * 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 + * \return DataArrayChar * - the new instance of DataArrayChar that the caller * is to delete using decrRef() as it is no more needed. * \throw If \a this is not allocated. */ @@ -1448,7 +1469,7 @@ DataArray *DataArrayChar::selectByTupleRanges(const std::vector( 0 <= tupleId < this->getNumberOfTuples() ) is violated. * \throw If condition ( 0 <= compoId < this->getNumberOfComponents() ) is violated. @@ -1689,7 +1710,7 @@ int DataArrayChar::locateValue(const std::vector& vals) const throw(INTERP /*! * 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 double - the maximal value among all values of \a this array. + * \return char - the maximal value among all values of \a this array. * \throw If \a this->getNumberOfComponents() != 1 * \throw If \a this->getNumberOfTuples() < 1 */ @@ -1991,7 +2012,7 @@ DataArrayByte *DataArrayByte::performCpy(bool dCpy) const /*! * 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. + * \return char - the sole value stored in \a this array. * \throw If at least one of conditions stated above is not fulfilled. */ char DataArrayByte::byteValue() const throw(INTERP_KERNEL::Exception) @@ -2324,7 +2345,7 @@ DataArrayAsciiChar *DataArrayAsciiChar::performCpy(bool dCpy) const /*! * 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. + * \return char - the sole value stored in \a this array. * \throw If at least one of conditions stated above is not fulfilled. */ char DataArrayAsciiChar::asciiCharValue() const throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index bb82ad21c..b1609b42e 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -221,8 +221,11 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingFieldDouble::buildNewTimeReprFromThis; %newobject ParaMEDMEM::MEDCouplingFieldDouble::getValueOnMulti; %newobject ParaMEDMEM::MEDCouplingFieldTemplate::New; -%newobject ParaMEDMEM::DataArray::selectByTupleRanges; %newobject ParaMEDMEM::DataArray::deepCpy; +%newobject ParaMEDMEM::DataArray::selectByTupleRanges; +%newobject ParaMEDMEM::DataArray::selectByTupleId; +%newobject ParaMEDMEM::DataArray::selectByTupleIdSafe; +%newobject ParaMEDMEM::DataArray::selectByTupleId2; %newobject ParaMEDMEM::DataArrayInt::New; %newobject ParaMEDMEM::DataArrayInt::__iter__; %newobject ParaMEDMEM::DataArrayInt::convertToDblArr; @@ -230,9 +233,6 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::substr; %newobject ParaMEDMEM::DataArrayInt::changeNbOfComponents; %newobject ParaMEDMEM::DataArrayInt::accumulatePerChunck; -%newobject ParaMEDMEM::DataArrayInt::selectByTupleId; -%newobject ParaMEDMEM::DataArrayInt::selectByTupleIdSafe; -%newobject ParaMEDMEM::DataArrayInt::selectByTupleId2; %newobject ParaMEDMEM::DataArrayInt::checkAndPreparePermutation; %newobject ParaMEDMEM::DataArrayInt::transformWithIndArrR; %newobject ParaMEDMEM::DataArrayInt::renumber; @@ -292,8 +292,6 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayChar::renumber; %newobject ParaMEDMEM::DataArrayChar::renumberR; %newobject ParaMEDMEM::DataArrayChar::renumberAndReduce; -%newobject ParaMEDMEM::DataArrayChar::selectByTupleIdSafe; -%newobject ParaMEDMEM::DataArrayChar::selectByTupleId2; %newobject ParaMEDMEM::DataArrayChar::changeNbOfComponents; %newobject ParaMEDMEM::DataArrayChar::getIdsEqual; %newobject ParaMEDMEM::DataArrayChar::getIdsNotEqual; @@ -325,9 +323,6 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayDouble::changeNbOfComponents; %newobject ParaMEDMEM::DataArrayDouble::accumulatePerChunck; %newobject ParaMEDMEM::DataArrayDouble::getIdsInRange; -%newobject ParaMEDMEM::DataArrayDouble::selectByTupleId; -%newobject ParaMEDMEM::DataArrayDouble::selectByTupleIdSafe; -%newobject ParaMEDMEM::DataArrayDouble::selectByTupleId2; %newobject ParaMEDMEM::DataArrayDouble::negate; %newobject ParaMEDMEM::DataArrayDouble::applyFunc; %newobject ParaMEDMEM::DataArrayDouble::applyFunc2; diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 9fb9baad8..51b1f148f 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -49,6 +49,7 @@ namespace ParaMEDMEM virtual std::size_t getNbOfElems() const throw(INTERP_KERNEL::Exception); virtual std::size_t getNbOfElemAllocated() const throw(INTERP_KERNEL::Exception); virtual DataArray *deepCpy() const throw(INTERP_KERNEL::Exception); + virtual DataArray *selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception); void checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception); void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); void checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception); @@ -172,6 +173,46 @@ namespace ParaMEDMEM return self->selectByTupleRanges(ranges); } + virtual DataArray *selectByTupleId(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + return self->selectByTupleId(tmp,tmp+size); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + return self->selectByTupleId(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); + } + } + + virtual DataArray *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + return self->selectByTupleIdSafe(tmp,tmp+size); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); + } + } + virtual PyObject *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception) { std::vector tmp; @@ -290,7 +331,6 @@ namespace ParaMEDMEM DataArrayInt *convertToIntArr() const throw(INTERP_KERNEL::Exception); DataArrayDouble *fromNoInterlace() const throw(INTERP_KERNEL::Exception); DataArrayDouble *toNoInterlace() const throw(INTERP_KERNEL::Exception); - DataArrayDouble *selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception); DataArrayDouble *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); void transpose() throw(INTERP_KERNEL::Exception); @@ -683,46 +723,6 @@ namespace ParaMEDMEM } } - DataArrayDouble *selectByTupleId(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleId(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleId(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - - DataArrayDouble *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleIdSafe(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - PyObject *minimalDistanceTo(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception) { int thisTupleId,otherTupleId; @@ -2851,46 +2851,6 @@ namespace ParaMEDMEM } } - DataArrayInt *selectByTupleId(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleId(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleId(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - - DataArrayInt *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleIdSafe(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - void setSelectedComponents(const DataArrayInt *a, PyObject *li) throw(INTERP_KERNEL::Exception) { std::vector tmp; @@ -4574,8 +4534,6 @@ namespace ParaMEDMEM DataArrayChar *renumber(const int *old2New) const throw(INTERP_KERNEL::Exception); DataArrayChar *renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception); DataArrayChar *renumberAndReduce(const int *old2NewBg, int newNbOfTuple) const throw(INTERP_KERNEL::Exception); - DataArrayChar *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception); - DataArrayChar *selectByTupleId2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception); bool isUniform(char val) const throw(INTERP_KERNEL::Exception); void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); DataArrayChar *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); @@ -4711,26 +4669,6 @@ namespace ParaMEDMEM } } - DataArrayChar *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleIdSafe(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - static DataArrayChar *Aggregate(PyObject *dachs) throw(INTERP_KERNEL::Exception) { std::vector tmp; -- 2.39.2