X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMemArray.cxx;h=ed638f94e3525cf58840b1b9c7cfc3d79d86ab07;hb=6d5395f87bc7849551f78e3ebed3c0c468bdcb2d;hp=ed5371df95b8e9aa6fb010fd5ceea85a5597c7a8;hpb=62d18e09efe179d5bb72d21c0b359ab489d4aa0e;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index ed5371df9..ed638f94e 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -1164,7 +1164,7 @@ void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const char *nameIn float *pt(tmp); // to make Visual C++ happy : instead of std::copy(begin(),end(),(float *)tmp); for(const double *src=begin();src!=end();src++,pt++) - *pt=int(*src); + *pt=float(*src); const char *data(reinterpret_cast((float *)tmp)); std::size_t sz(getNbOfElems()*sizeof(float)); byteArr->insertAtTheEnd(data,data+sz); @@ -3818,6 +3818,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;igetNumberOfComponents() != 1. * + * \sa DataArrayDouble::getIdsNotInRange + * * \ref cpp_mcdataarraydouble_getidsinrange "Here is a C++ example".
* \ref py_mcdataarraydouble_getidsinrange "Here is a Python example". */ @@ -4455,15 +4479,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) @@ -6456,6 +6506,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. @@ -8972,29 +9044,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();