void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const
{
const double *coordsPtr=getConstPointer();
- BBTree<SPACEDIM,int> myTree(bbox,0,0,nbNodes,prec/10);
+ BBTreePts<SPACEDIM,int> myTree(bbox,0,0,nbNodes,prec);
std::vector<bool> isDone(nbNodes);
for(int i=0;i<nbNodes;i++)
{
}
template<int SPACEDIM>
-void DataArrayDouble::FindTupleIdsNearTuplesAlg(const BBTree<SPACEDIM,int>& myTree, const double *pos, int nbOfTuples, double eps,
+void DataArrayDouble::FindTupleIdsNearTuplesAlg(const BBTreePts<SPACEDIM,int>& myTree, const double *pos, int nbOfTuples, double eps,
DataArrayInt *c, DataArrayInt *cI)
{
for(int i=0;i<nbOfTuples;i++)
* Sets information on a component specified by an index.
* To know more on format of this information
* see \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
+ * \warning Don't pass NULL as \a info!
* \param [in] i - the index (zero based) of the component of interest.
* \param [in] info - the string containing the information.
* \throw If \a i is not a valid component index.
- * \warning Don't pass NULL as \a info!
*/
void DataArray::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception)
{
}
}
+/*!
+ * Sets information on all components. This method can change number of components
+ * at certain conditions; if the conditions are not respected, an exception is thrown.
+ * The number of components can be changed in \a this only if \a this is not allocated.
+ * The condition of number of components must not be changed.
+ *
+ * To know more on format of the component information see
+ * \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
+ * \param [in] info - a vector of component infos.
+ * \throw If \a this->getNumberOfComponents() != \a info.size() && \a this->isAllocated()
+ */
+void DataArray::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
+{
+ if(getNumberOfComponents()!=(int)info.size())
+ {
+ if(!isAllocated())
+ _info_on_compo=info;
+ else
+ {
+ std::ostringstream oss; oss << "DataArray::setInfoAndChangeNbOfCompo : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << " and this is already allocated !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ else
+ _info_on_compo=info;
+}
+
void DataArray::checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception)
{
if(getNumberOfTuples()!=nbOfTuples)
}
}
+/*!
+ * This method is useful to slice work among a pool of threads or processes. \a begin, \a end \a step is the input whole slice of work to perform,
+ * typically it is a whole slice of tuples of DataArray or cells, nodes of a mesh...
+ *
+ * The input \a sliceId should be an id in [0, \a nbOfSlices) that specifies the slice of work.
+ *
+ * \param [in] start - the start of the input slice of the whole work to perform splitted into slices.
+ * \param [in] stop - the stop of the input slice of the whole work to perform splitted into slices.
+ * \param [in] step - the step (that can be <0) of the input slice of the whole work to perform splitted into slices.
+ * \param [in] sliceId - the slice id considered
+ * \param [in] nbOfSlices - the number of slices (typically the number of cores on which the work is expected to be sliced)
+ * \param [out] startSlice - the start of the slice considered
+ * \param [out] stopSlice - the stop of the slice consided
+ *
+ * \throw If \a step == 0
+ * \throw If \a nbOfSlices not > 0
+ * \throw If \a sliceId not in [0,nbOfSlices)
+ */
+void DataArray::GetSlice(int start, int stop, int step, int sliceId, int nbOfSlices, int& startSlice, int& stopSlice) throw(INTERP_KERNEL::Exception)
+{
+ if(nbOfSlices<=0)
+ {
+ std::ostringstream oss; oss << "DataArray::GetSlice : nbOfSlices (" << nbOfSlices << ") must be > 0 !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ if(sliceId<0 || sliceId>=nbOfSlices)
+ {
+ std::ostringstream oss; oss << "DataArray::GetSlice : sliceId (" << nbOfSlices << ") must be in [0 , nbOfSlices (" << nbOfSlices << ") ) !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ int nbElems=GetNumberOfItemGivenBESRelative(start,stop,step,"DataArray::GetSlice");
+ int minNbOfElemsPerSlice=nbElems/nbOfSlices;
+ startSlice=start+minNbOfElemsPerSlice*step*sliceId;
+ if(sliceId<nbOfSlices-1)
+ stopSlice=start+minNbOfElemsPerSlice*step*(sliceId+1);
+ else
+ stopSlice=stop;
+}
+
int DataArray::GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception)
{
if(end<begin)
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() throw(INTERP_KERNEL::Exception)
+{
+ _mem.destroy();
+}
+
std::size_t DataArrayDouble::getHeapMemorySize() const
{
std::size_t sz=_mem.getNbOfElemAllocated();
return DataArray::getHeapMemorySize()+sz;
}
-/*!
- * Sets information on all components. This method can change number of components
- * at certain conditions; if the conditions are not respected, an exception is thrown.
- * The number of components can be changed provided that \a this is not allocated.
- *
- * To know more on format of the component information see
- * \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
- * \param [in] info - a vector of component infos.
- * \throw If \a this->getNumberOfComponents() != \a info.size() && \a this->isAllocated()
- */
-void DataArrayDouble::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
-{
- if(getNumberOfComponents()!=(int)info.size())
- {
- if(!isAllocated())
- _info_on_compo=info;
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::setInfoAndChangeNbOfCompo : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << " and this is already allocated !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- _info_on_compo=info;
-}
-
/*!
* 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.
/*!
* Returns a full copy of \a this. For more info on copying data arrays see
* \ref MEDCouplingArrayBasicsCopyDeep.
- * \return DataArrayDouble * - a new instance of DataArrayDouble.
+ * \return DataArrayDouble * - a new instance of DataArrayDouble. The caller is to
+ * delete this array using decrRef() as it is no more needed.
*/
DataArrayDouble *DataArrayDouble::deepCpy() const throw(INTERP_KERNEL::Exception)
{
{
int nbOfTuples=getNumberOfTuples();
stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
- const double *data=begin();
- std::ostringstream oss2; oss2 << "[";
- oss2.precision(17);
- std::string oss2Str(oss2.str());
- bool isFinished=true;
- for(int i=0;i<nbOfTuples && isFinished;i++)
- {
- if(nbOfCompo>1)
- {
- oss2 << "(";
- for(int j=0;j<nbOfCompo;j++,data++)
- {
- oss2 << *data;
- if(j!=nbOfCompo-1) oss2 << ", ";
- }
- oss2 << ")";
- }
- else
- oss2 << *data++;
- if(i!=nbOfTuples-1) oss2 << ", ";
- std::string oss3Str(oss2.str());
- if(oss3Str.length()<MAX_NB_OF_BYTE_IN_REPR)
- oss2Str=oss3Str;
- else
- isFinished=false;
- }
- stream << oss2Str;
- if(!isFinished)
- stream << "... ";
- stream << "]";
+ reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
}
else
stream << "Number of components : 0.";
stream << "*** No data allocated ****";
}
+void DataArrayDouble::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const throw(INTERP_KERNEL::Exception)
+{
+ const double *data=begin();
+ int nbOfTuples=getNumberOfTuples();
+ int nbOfCompo=(int)_info_on_compo.size();
+ std::ostringstream oss2; oss2 << "[";
+ oss2.precision(17);
+ std::string oss2Str(oss2.str());
+ bool isFinished=true;
+ for(int i=0;i<nbOfTuples && isFinished;i++)
+ {
+ if(nbOfCompo>1)
+ {
+ oss2 << "(";
+ for(int j=0;j<nbOfCompo;j++,data++)
+ {
+ oss2 << *data;
+ if(j!=nbOfCompo-1) oss2 << ", ";
+ }
+ oss2 << ")";
+ }
+ else
+ oss2 << *data++;
+ if(i!=nbOfTuples-1) oss2 << ", ";
+ std::string oss3Str(oss2.str());
+ if(oss3Str.length()<maxNbOfByteInRepr)
+ oss2Str=oss3Str;
+ else
+ isFinished=false;
+ }
+ stream << oss2Str;
+ if(!isFinished)
+ stream << "... ";
+ stream << "]";
+}
+
/*!
* Equivalent to DataArrayDouble::isEqual except that if false the reason of
* mismatch is given.
* 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) throw(INTERP_KERNEL::Exception)
{
+ 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();
* 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.
- * \warning Do not confuse this method with transpose()!
*/
DataArrayDouble *DataArrayDouble::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
{
throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !");
double *tab=_mem.fromNoInterlace(getNumberOfComponents());
DataArrayDouble *ret=DataArrayDouble::New();
- ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
+ ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
return ret;
}
* 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.
- * \warning Do not confuse this method with transpose()!
*/
DataArrayDouble *DataArrayDouble::toNoInterlace() const throw(INTERP_KERNEL::Exception)
{
throw INTERP_KERNEL::Exception("DataArrayDouble::toNoInterlace : Not defined array !");
double *tab=_mem.toNoInterlace(getNumberOfComponents());
DataArrayDouble *ret=DataArrayDouble::New();
- ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
+ ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
return ret;
}
double *tmp=new double[nbTuples*nbOfCompo];
const double *iptr=getConstPointer();
for(int i=0;i<nbTuples;i++)
- std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*old2New[i]);
+ {
+ int v=old2New[i];
+ if(v>=0 && v<nbTuples)
+ std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*v);
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayDouble::renumberInPlace : At place #" << i << " value is " << v << " ! Should be in [0," << nbTuples << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
delete [] tmp;
declareAsNew();
double *tmp=new double[nbTuples*nbOfCompo];
const double *iptr=getConstPointer();
for(int i=0;i<nbTuples;i++)
- std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),tmp+nbOfCompo*i);
+ {
+ int v=new2Old[i];
+ if(v>=0 && v<nbTuples)
+ std::copy(iptr+nbOfCompo*v,iptr+nbOfCompo*(v+1),tmp+nbOfCompo*i);
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayDouble::renumberInPlaceR : At place #" << i << " value is " << v << " ! Should be in [0," << nbTuples << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
delete [] tmp;
declareAsNew();
if(*w>=0 && *w<oldNbOfTuples)
std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
else
- throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
+ throw INTERP_KERNEL::Exception("DataArrayDouble::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
ret->copyStringInfoFrom(*this);
return ret.retn();
}
* \param [in] step - index increment to get index of the next tuple to copy.
* \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
* is to delete using decrRef() as it is no more needed.
- * \throw If (\a end2 < \a bg) or (\a step <= 0).
* \sa DataArrayDouble::substr.
*/
DataArrayDouble *DataArrayDouble::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception)
checkAllocated();
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
int nbComp=getNumberOfComponents();
- int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayDouble::selectByTupleId2 : ");
+ int newNbOfTuples=GetNumberOfItemGivenBESRelative(bg,end2,step,"DataArrayDouble::selectByTupleId2 : ");
ret->alloc(newNbOfTuples,nbComp);
double *pt=ret->getPointer();
const double *srcPt=getConstPointer()+bg*nbComp;
* \throw If \a end > \a this->getNumberOfTuples().
* \throw If \a this is not allocated.
*/
-DataArrayDouble *DataArrayDouble::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
+DataArray *DataArrayDouble::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
{
checkAllocated();
int nbOfComp=getNumberOfComponents();
/*!
* 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.
* \throw If \a this is not allocated
* \throw If getNbOfElems() % \a newNbOfCompo != 0.
* of tuples, and inversely its number of tuples to become equal to its number of
* components. So that its raw data **does not** change, instead splitting this
* data into tuples changes.
- * \throw If \a this is not allocated.
* \warning This method erases all (name and unit) component info set before!
* \warning Do not confuse this method with fromNoInterlace() and toNoInterlace()!
+ * \throw If \a this is not allocated.
* \sa rearrange()
*/
void DataArrayDouble::transpose() throw(INTERP_KERNEL::Exception)
* \throw If a component index (\a i) is not valid:
* \a i < 0 || \a i >= \a this->getNumberOfComponents().
*
- * \ref cpp_mcdataarraydouble_keepselectedcomponents "Here is a Python example".
+ * \ref py_mcdataarraydouble_KeepSelectedComponents "Here is a Python example".
*/
-DataArrayDouble *DataArrayDouble::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
+DataArray *DataArrayDouble::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
{
checkAllocated();
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New());
throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !");
int nbOfComp1=getNumberOfComponents();
int nbOfComp2=other->getNumberOfComponents();
- double *newArr=new double[nbOfTuples*(nbOfComp1+nbOfComp2)];
+ double *newArr=(double *)malloc((nbOfTuples*(nbOfComp1+nbOfComp2))*sizeof(double));
double *w=newArr;
const double *inp1=getConstPointer();
const double *inp2=other->getConstPointer();
w=std::copy(inp1,inp1+nbOfComp1,w);
w=std::copy(inp2,inp2+nbOfComp2,w);
}
- useArray(newArr,true,CPP_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
+ useArray(newArr,true,C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
std::vector<int> compIds(nbOfComp2);
for(int i=0;i<nbOfComp2;i++)
compIds[i]=nbOfComp1+i;
copyPartOfStringInfoFrom2(compIds,*other);
}
+/*!
+ * This method checks that all tuples in \a other are in \a this.
+ * If true, the output param \a tupleIds contains the tuples ids of \a this that correspond to tupes in \a this.
+ * For each i in [ 0 , other->getNumberOfTuples() ) tuple #i in \a other is equal ( regarding input precision \a prec ) to tuple tupleIds[i] in \a this.
+ *
+ * \param [in] other - the array having the same number of components than \a this.
+ * \param [out] tupleIds - the tuple ids containing the same number of tuples than \a other has.
+ * \sa DataArrayDouble::findCommonTuples
+ */
+bool DataArrayDouble::areIncludedInMe(const DataArrayDouble *other, double prec, DataArrayInt *&tupleIds) const throw(INTERP_KERNEL::Exception)
+{
+ if(!other)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::areIncludedInMe : input array is NULL !");
+ checkAllocated(); other->checkAllocated();
+ if(getNumberOfComponents()!=other->getNumberOfComponents())
+ throw INTERP_KERNEL::Exception("DataArrayDouble::areIncludedInMe : the number of components does not match !");
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a=DataArrayDouble::Aggregate(this,other);
+ DataArrayInt *c=0,*ci=0;
+ a->findCommonTuples(prec,getNumberOfTuples(),c,ci);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cSafe(c),ciSafe(ci);
+ int newNbOfTuples=-1;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(a->getNumberOfTuples(),c->begin(),ci->begin(),ci->end(),newNbOfTuples);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=ids->selectByTupleId2(getNumberOfTuples(),a->getNumberOfTuples(),1);
+ tupleIds=ret1.retn();
+ return newNbOfTuples==getNumberOfTuples();
+}
+
/*!
* Searches for tuples coincident within \a prec tolerance. Each tuple is considered
* as coordinates of a point in getNumberOfComponents()-dimensional space. The
- * distance is computed using norm2.
+ * distance separating two points is computed with the infinite norm.
*
* Indices of coincident tuples are stored in output arrays.
* A pair of arrays (\a comm, \a commIndex) is called "Surjective Format 2".
*
* This method is typically used by MEDCouplingPointSet::findCommonNodes() and
* MEDCouplingUMesh::mergeNodes().
- * \param [in] prec - minimal absolute distance between two tuples at which they are
+ * \param [in] prec - minimal absolute distance between two tuples (infinite norm) at which they are
* considered not coincident.
- * \param [in] limitTupleId - limit tuple id. Tuples with id strictly lower than \a
- * limitTupleId are not considered.
+ * \param [in] limitTupleId - limit tuple id. If all tuples within a group of coincident
+ * tuples have id strictly lower than \a limitTupleId then they are not returned.
* \param [out] comm - the array holding ids (== indices) of coincident tuples.
* \a comm->getNumberOfComponents() == 1.
* \a comm->getNumberOfTuples() == \a commIndex->back().
* \ref cpp_mcdataarraydouble_findcommontuples "Here is a C++ example".
*
* \ref py_mcdataarraydouble_findcommontuples "Here is a Python example".
- * \sa DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2().
+ * \sa DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(), DataArrayDouble::areIncludedInMe
*/
void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const throw(INTERP_KERNEL::Exception)
{
int nbOfTuples=getNumberOfTuples();
//
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=computeBBoxPerTuple(prec);
- //
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(DataArrayInt::New()),cI(DataArrayInt::New()); c->alloc(0,1); cI->pushBackSilent(0);
switch(nbOfCompo)
{
case 3:
- findCommonTuplesAlg<3>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI);
+ findCommonTuplesAlg<3>(begin(),nbOfTuples,limitTupleId,prec,c,cI);
break;
case 2:
- findCommonTuplesAlg<2>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI);
+ findCommonTuplesAlg<2>(begin(),nbOfTuples,limitTupleId,prec,c,cI);
break;
case 1:
- findCommonTuplesAlg<1>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI);
+ findCommonTuplesAlg<1>(begin(),nbOfTuples,limitTupleId,prec,c,cI);
break;
default:
throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : nb of components managed are 1,2 and 3 ! not implemented for other number of components !");
* that coincident tuples are excluded.
* \param [in] prec - minimal absolute distance between two tuples at which they are
* considered not coincident.
- * \param [in] limitTupleId - limit tuple id. Tuples with id strictly lower than \a
- * limiTupleId are not considered and thus not excluded.
+ * \param [in] limitTupleId - limit tuple id. If all tuples within a group of coincident
+ * tuples have id strictly lower than \a limitTupleId then they are not excluded.
* \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.
* \throw If the number of components is not in [1,2,3].
*
- * \ref cpp_mcdataarraydouble_getdifferentvalues "Here is a Python example".
+ * \ref py_mcdataarraydouble_getdifferentvalues "Here is a Python example".
*/
DataArrayDouble *DataArrayDouble::getDifferentValues(double prec, int limitTupleId) const throw(INTERP_KERNEL::Exception)
{
/*!
* Copy all components in a specified order from another DataArrayDouble.
- * The specified components become the first ones in \a this array.
* Both numerical and textual data is copied. The number of tuples in \a this and
* the other array can be different.
* \param [in] a - the array to copy data from.
* \throw If \a compoIds.size() != \a a->getNumberOfComponents().
* \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
*
- * \ref cpp_mcdataarraydouble_setselectedcomponents "Here is a Python example".
+ * \ref py_mcdataarraydouble_setselectedcomponents "Here is a Python example".
*/
void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
{
* \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
* \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
*
- * \ref cpp_mcdataarraydouble_setpartofvalues1 "Here is a Python example".
+ * \ref py_mcdataarraydouble_setpartofvalues1 "Here is a Python example".
*/
void DataArrayDouble::setPartOfValues1(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
{
* non-empty range of increasing indices or indices are out of a valid range
* for \this array.
*
- * \ref cpp_mcdataarraydouble_setpartofvaluessimple1 "Here is a Python example".
+ * \ref py_mcdataarraydouble_setpartofvaluessimple1 "Here is a Python example".
*/
void DataArrayDouble::setPartOfValuesSimple1(double a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
{
* \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
* <em> a->getNumberOfComponents() != (endComp - bgComp)</em>.
*
- * \ref cpp_mcdataarraydouble_setpartofvalues2 "Here is a Python example".
+ * \ref py_mcdataarraydouble_setpartofvalues2 "Here is a Python example".
*/
void DataArrayDouble::setPartOfValues2(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
{
* \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
* out of a valid range for \a this array.
*
- * \ref cpp_mcdataarraydouble_setpartofvaluessimple2 "Here is a Python example".
+ * \ref py_mcdataarraydouble_setpartofvaluessimple2 "Here is a Python example".
*/
void DataArrayDouble::setPartOfValuesSimple2(double a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
{
* non-empty range of increasing indices or indices are out of a valid range
* for \this array.
*
- * \ref cpp_mcdataarraydouble_setpartofvalues3 "Here is a Python example".
+ * \ref py_mcdataarraydouble_setpartofvalues3 "Here is a Python example".
*/
void DataArrayDouble::setPartOfValues3(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
{
* non-empty range of increasing indices or indices are out of a valid range
* for \this array.
*
- * \ref cpp_mcdataarraydouble_setpartofvaluessimple3 "Here is a Python example".
+ * \ref py_mcdataarraydouble_setpartofvaluessimple3 "Here is a Python example".
*/
void DataArrayDouble::setPartOfValuesSimple3(double a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
{
* \throw If any tuple index given by \a tuplesSelec is out of a valid range for
* \a a array.
*/
-void DataArrayDouble::setContigPartOfSelectedValues(int tupleIdStart, const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
+void DataArrayDouble::setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
{
- if(!a || !tuplesSelec)
+ if(!aBase || !tuplesSelec)
throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : input DataArray is NULL !");
+ const DataArrayDouble *a=dynamic_cast<const DataArrayDouble *>(aBase);
+ if(!a)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : input DataArray aBase is not a DataArrayDouble !");
checkAllocated();
a->checkAllocated();
tuplesSelec->checkAllocated();
* non-empty range of increasing indices or indices are out of a valid range
* for the array \a a.
*/
-void DataArrayDouble::setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayDouble *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
+void DataArrayDouble::setContigPartOfSelectedValues2(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
{
+ if(!aBase)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : input DataArray is NULL !");
+ const DataArrayDouble *a=dynamic_cast<const DataArrayDouble *>(aBase);
if(!a)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : input DataArrayDouble is NULL !");
+ throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : input DataArray aBase is not a DataArrayDouble !");
checkAllocated();
a->checkAllocated();
int nbOfComp=getNumberOfComponents();
return _mem[tupleId*_info_on_compo.size()+compoId];
}
+/*!
+ * Returns the first value of \a this.
+ * \return double - the last value of \a this array.
+ * \throw If \a this is not allocated.
+ * \throw If \a this->getNumberOfComponents() != 1.
+ * \throw If \a this->getNumberOfTuples() < 1.
+ */
+double DataArrayDouble::front() const throw(INTERP_KERNEL::Exception)
+{
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::front : number of components not equal to one !");
+ int nbOfTuples=getNumberOfTuples();
+ if(nbOfTuples<1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::front : number of tuples must be >= 1 !");
+ return *(getConstPointer());
+}
+
/*!
* Returns the last value of \a this.
* \return double - the last value of \a this array.
* Two tuples are considered equal if the euclidian distance between the two tuples is lower than \a eps.
*
* \param [in] other a DataArrayDouble having same number of components than \a this.
- * \param [in] eps absolute precision representing euclidian distance between 2 tuples behind which 2 tuples are considered equal.
+ * \param [in] eps absolute precision representing distance (using infinite norm) between 2 tuples behind which 2 tuples are considered equal.
* \param [out] c will contain the set of tuple ids in \a this that are equal to to the tuple ids in \a other contiguously.
* \a cI allows to extract information in \a c.
* \param [out] cI is an indirection array that allows to extract the data contained in \a c.
if(!other)
throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : input pointer other is null !");
checkAllocated();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=computeBBoxPerTuple(eps);
other->checkAllocated();
int nbOfCompo=getNumberOfComponents();
int otherNbOfCompo=other->getNumberOfComponents();
{
case 3:
{
- BBTree<3,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10);
+ BBTreePts<3,int> myTree(begin(),0,0,getNumberOfTuples(),eps);
FindTupleIdsNearTuplesAlg<3>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
break;
}
case 2:
{
- BBTree<2,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10);
+ BBTreePts<2,int> myTree(begin(),0,0,getNumberOfTuples(),eps);
FindTupleIdsNearTuplesAlg<2>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
break;
}
case 1:
{
- BBTree<1,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10);
+ BBTreePts<1,int> myTree(begin(),0,0,getNumberOfTuples(),eps);
FindTupleIdsNearTuplesAlg<1>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
break;
}
return ret;
}
+/*!
+ * This method returns the number of values in \a this that are equals ( within an absolute precision of \a eps ) to input parameter \a value.
+ * This method only works for single component array.
+ *
+ * \return a value in [ 0, \c this->getNumberOfTuples() )
+ *
+ * \throw If \a this is not allocated
+ *
+ */
+int DataArrayDouble::count(double value, double eps) const throw(INTERP_KERNEL::Exception)
+{
+ int ret=0;
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::count : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
+ const double *vals=begin();
+ int nbOfTuples=getNumberOfTuples();
+ for(int i=0;i<nbOfTuples;i++,vals++)
+ if(fabs(*vals-value)<=eps)
+ ret++;
+ return ret;
+}
+
/*!
* Returns the average value of \a this one-dimensional array.
* \return double - the average value over all values of \a this array.
return ret;
}
+/*!
+ * This method accumulate using addition tuples in \a this using input index array [ \a bgOfIndex, \a endOfIndex ).
+ * The returned array will have same number of components than \a this and number of tuples equal to
+ * \c std::distance(bgOfIndex,endOfIndex) \b minus \b one.
+ *
+ * The input index array is expected to be ascendingly sorted in which the all referenced ids should be in [0, \c this->getNumberOfTuples).
+ * This method is quite useful for users that need to put a field on cells to field on nodes on the same mesh without a need of conservation.
+ *
+ * \param [in] bgOfIndex - begin (included) of the input index array.
+ * \param [in] endOfIndex - end (excluded) of the input index array.
+ * \return DataArrayDouble * - the new instance having the same number of components than \a this.
+ *
+ * \throw If bgOfIndex or end is NULL.
+ * \throw If input index array is not ascendingly sorted.
+ * \throw If there is an id in [ \a bgOfIndex, \a endOfIndex ) not in [0, \c this->getNumberOfTuples).
+ * \throw If std::distance(bgOfIndex,endOfIndex)==0.
+ */
+DataArrayDouble *DataArrayDouble::accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const throw(INTERP_KERNEL::Exception)
+{
+ if(!bgOfIndex || !endOfIndex)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::accumulatePerChunck : input pointer NULL !");
+ checkAllocated();
+ int nbCompo=getNumberOfComponents();
+ int nbOfTuples=getNumberOfTuples();
+ int sz=(int)std::distance(bgOfIndex,endOfIndex);
+ if(sz<1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::accumulatePerChunck : invalid size of input index array !");
+ sz--;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(sz,nbCompo);
+ const int *w=bgOfIndex;
+ if(*w<0 || *w>=nbOfTuples)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::accumulatePerChunck : The first element of the input index not in [0,nbOfTuples) !");
+ const double *srcPt=begin()+(*w)*nbCompo;
+ double *tmp=ret->getPointer();
+ for(int i=0;i<sz;i++,tmp+=nbCompo,w++)
+ {
+ std::fill(tmp,tmp+nbCompo,0.);
+ if(w[1]>=w[0])
+ {
+ for(int j=w[0];j<w[1];j++,srcPt+=nbCompo)
+ {
+ if(j>=0 && j<nbOfTuples)
+ std::transform(srcPt,srcPt+nbCompo,tmp,tmp,std::plus<double>());
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayDouble::accumulatePerChunck : At rank #" << i << " the input index array points to id " << j << " should be in [0," << nbOfTuples << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ }
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayDouble::accumulatePerChunck : At rank #" << i << " the input index array is not in ascendingly sorted.";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ ret->copyStringInfoFrom(*this);
+ return ret.retn();
+}
+
/*!
* Converts each 2D point defined by the tuple of \a this array from the Polar to the
* Cartesian coordinate system. The two components of the tuple of \a this array are
* The caller is to delete this result array using decrRef() as it is no more
* needed.
* \throw If \a this is not allocated.
+ * \sa DataArrayDouble::maxPerTupleWithCompoId
*/
DataArrayDouble *DataArrayDouble::maxPerTuple() const throw(INTERP_KERNEL::Exception)
{
checkAllocated();
int nbOfComp=getNumberOfComponents();
- DataArrayDouble *ret=DataArrayDouble::New();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
int nbOfTuple=getNumberOfTuples();
ret->alloc(nbOfTuple,1);
const double *src=getConstPointer();
double *dest=ret->getPointer();
for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
*dest=*std::max_element(src,src+nbOfComp);
- return ret;
+ return ret.retn();
+}
+
+/*!
+ * Computes the maximal value within every tuple of \a this array and it returns the first component
+ * id for each tuple that corresponds to the maximal value within the tuple.
+ *
+ * \param [out] compoIdOfMaxPerTuple - the new new instance of DataArrayInt containing the
+ * same number of tuples and only one component.
+ * \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.
+ * \sa DataArrayDouble::maxPerTuple
+ */
+DataArrayDouble *DataArrayDouble::maxPerTupleWithCompoId(DataArrayInt* &compoIdOfMaxPerTuple) const throw(INTERP_KERNEL::Exception)
+{
+ checkAllocated();
+ int nbOfComp=getNumberOfComponents();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret0=DataArrayDouble::New();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=DataArrayInt::New();
+ int nbOfTuple=getNumberOfTuples();
+ ret0->alloc(nbOfTuple,1); ret1->alloc(nbOfTuple,1);
+ const double *src=getConstPointer();
+ double *dest=ret0->getPointer(); int *dest1=ret1->getPointer();
+ for(int i=0;i<nbOfTuple;i++,dest++,dest1++,src+=nbOfComp)
+ {
+ const double *loc=std::max_element(src,src+nbOfComp);
+ *dest=*loc;
+ *dest1=(int)std::distance(src,loc);
+ }
+ compoIdOfMaxPerTuple=ret1.retn();
+ return ret0.retn();
}
/*!
/*!
* Modify all elements of \a this array, so that
* an element _x_ becomes \f$ numerator / x \f$.
- * \param [in] numerator - the numerator used to modify array elements.
- * \throw If \a this is not allocated.
- * \throw If there is an element equal to 0.0 in \a this array.
* \warning If an exception is thrown because of presence of 0.0 element in \a this
* array, all elements processed before detection of the zero element remain
* modified.
+ * \param [in] numerator - the numerator used to modify array elements.
+ * \throw If \a this is not allocated.
+ * \throw If there is an element equal to 0.0 in \a this array.
*/
void DataArrayDouble::applyInv(double numerator) throw(INTERP_KERNEL::Exception)
{
/*!
* Returns a new DataArrayInt contating indices of tuples of \a this one-dimensional
* array whose values are within a given range. Textual data is not copied.
- * \param [in] vmin - a lowest acceptable value.
- * \param [in] vmax - a greatest acceptable value.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
+ * \param [in] vmin - a lowest acceptable value (included).
+ * \param [in] vmax - a greatest acceptable value (included).
+ * \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
- *
- * \ref cpp_mcdataarraydouble_getidsinrange "Here is a C++ example".
+ * \throw If \a this->getNumberOfComponents() != 1.
*
+ * \ref cpp_mcdataarraydouble_getidsinrange "Here is a C++ example".<br>
* \ref py_mcdataarraydouble_getidsinrange "Here is a Python example".
*/
DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception)
* valid cases.
* 1. The arrays have same number of tuples and components. Then each value of
* the result array (_a_) is a product of the corresponding values of \a a1 and
- * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ].
+ * \a a2, i.e. _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ].
* 2. The arrays have same number of tuples and one array, say _a2_, has one
* component. Then
* _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, 0 ].
* Multiply values of another DataArrayDouble to values of \a this one. There are 3
* valid cases.
* 1. The arrays have same number of tuples and components. Then each value of
- * \a other array is multiplied to the corresponding value of \a this array, i.e.:
- * _a_ [ i, j ] *= _other_ [ i, j ].
+ * \a other array is multiplied to the corresponding value of \a this array, i.e.
+ * _this_ [ i, j ] *= _other_ [ i, j ].
* 2. The arrays have same number of tuples and \a other array has one component. Then
- * _a_ [ i, j ] *= _other_ [ i, 0 ].
+ * _this_ [ i, j ] *= _other_ [ i, 0 ].
* 3. The arrays have same number of components and \a other array has one tuple. Then
- * _a_ [ i, j ] *= _a2_ [ 0, j ].
+ * _this_ [ i, j ] *= _a2_ [ 0, j ].
*
* \param [in] other - an array to multiply to \a this one.
* \throw If \a other is NULL.
*
* Info on components is copied either from the first array (in the first case) or from
* the array with maximal number of elements (getNbOfElems()).
+ * \warning No check of division by zero is performed!
* \param [in] a1 - a numerator array.
* \param [in] a2 - a denominator array.
* \return DataArrayDouble * - the new instance of DataArrayDouble.
* \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
* \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
* none of them has number of tuples or components equal to 1.
- * \warning No check of division by zero is performed!
*/
DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
{
* 3. The arrays have same number of components and \a other array has one tuple. Then
* _a_ [ i, j ] /= _a2_ [ 0, j ].
*
+ * \warning No check of division by zero is performed!
* \param [in] other - an array to divide \a this one by.
* \throw If \a other is NULL.
* \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
* \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
* \a other has number of both tuples and components not equal to 1.
- * \warning No check of division by zero is performed!
*/
void DataArrayDouble::divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
{
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() throw(INTERP_KERNEL::Exception)
+{
+ _mem.destroy();
+}
+
std::size_t DataArrayInt::getHeapMemorySize() const
{
std::size_t sz=_mem.getNbOfElemAllocated();
return DataArray::getHeapMemorySize()+sz;
}
-/*!
- * Sets information on all components. This method can change number of components
- * at certain conditions; if the conditions are not respected, an exception is thrown.
- * The number of components can be changed provided that \a this is not allocated.
- *
- * To know more on format of the component information see
- * \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
- * \param [in] info - a vector of component infos.
- * \throw If \a this->getNumberOfComponents() != \a info.size() && \a this->isAllocated()
- */
-void DataArrayInt::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
-{
- if(getNumberOfComponents()!=(int)info.size())
- {
- if(!isAllocated())
- _info_on_compo=info;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::setInfoAndChangeNbOfCompo : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << " and this is already allocated !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- _info_on_compo=info;
-}
-
/*!
* 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.
{
int nbOfTuples=getNumberOfTuples();
stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
- const int *data=begin();
- std::ostringstream oss2; oss2 << "[";
- std::string oss2Str(oss2.str());
- bool isFinished=true;
- for(int i=0;i<nbOfTuples && isFinished;i++)
- {
- if(nbOfCompo>1)
- {
- oss2 << "(";
- for(int j=0;j<nbOfCompo;j++,data++)
- {
- oss2 << *data;
- if(j!=nbOfCompo-1) oss2 << ", ";
- }
- oss2 << ")";
- }
- else
- oss2 << *data++;
- if(i!=nbOfTuples-1) oss2 << ", ";
- std::string oss3Str(oss2.str());
- if(oss3Str.length()<MAX_NB_OF_BYTE_IN_REPR)
- oss2Str=oss3Str;
- else
- isFinished=false;
- }
- stream << oss2Str;
- if(!isFinished)
- stream << "... ";
- stream << "]";
+ reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
}
else
stream << "Number of components : 0.";
stream << "*** No data allocated ****";
}
+void DataArrayInt::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const throw(INTERP_KERNEL::Exception)
+{
+ const int *data=begin();
+ int nbOfTuples=getNumberOfTuples();
+ int nbOfCompo=(int)_info_on_compo.size();
+ std::ostringstream oss2; oss2 << "[";
+ std::string oss2Str(oss2.str());
+ bool isFinished=true;
+ for(int i=0;i<nbOfTuples && isFinished;i++)
+ {
+ if(nbOfCompo>1)
+ {
+ oss2 << "(";
+ for(int j=0;j<nbOfCompo;j++,data++)
+ {
+ oss2 << *data;
+ if(j!=nbOfCompo-1) oss2 << ", ";
+ }
+ oss2 << ")";
+ }
+ else
+ oss2 << *data++;
+ if(i!=nbOfTuples-1) oss2 << ", ";
+ std::string oss3Str(oss2.str());
+ if(oss3Str.length()<maxNbOfByteInRepr)
+ oss2Str=oss3Str;
+ else
+ isFinished=false;
+ }
+ stream << oss2Str;
+ if(!isFinished)
+ stream << "... ";
+ stream << "]";
+}
+
/*!
* Modifies \a this one-dimensional array so that each value \a v = \a indArrBg[ \a v ],
* i.e. a current value is used as in index to get a new value from \a indArrBg.
*pt=indArrBg[*pt];
else
{
- std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn;
+ std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << ", should be in [0," << nbElemsIn << ") !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
* Computes distribution of values of \a this one-dimensional array between given value
* ranges (casts). This method is typically useful for entity number spliting by types,
* for example.
+ * \warning The values contained in \a arrBg should be sorted ascendently. No
+ * check of this is be done. If not, the result is not warranted.
* \param [in] arrBg - the array of ascending values defining the value ranges. The i-th
* value of \a arrBg (\a arrBg[ i ]) gives the lowest value of the i-th range,
* and the greatest value of the i-th range equals to \a arrBg[ i+1 ] - 1. \a
* \throw If \a this->getNumberOfComponents() != 1.
* \throw If \a arrEnd - arrBg < 2.
* \throw If any value of \a this is not less than \a arrEnd[-1].
- * \warning The values contained in \a arrBg should be sorted ascendently. No
- * check of this is be done. If not, the result is not warranted.
- *
*/
void DataArrayInt::splitByValueRange(const int *arrBg, const int *arrEnd,
DataArrayInt *& castArr, DataArrayInt *& rankInsideCast, DataArrayInt *& castsPresent) const throw(INTERP_KERNEL::Exception)
}
else
{
- std::ostringstream oss; oss << "DataArrayInt::splitByValueRange : At rank #" << i << " the value is " << work[i] << " whereas the last value is " << *bg;
+ std::ostringstream oss; oss << "DataArrayInt::splitByValueRange : At rank #" << i << " the value is " << work[i] << " should be in [0," << *bg << ") !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
* 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.
- * \warning Do not confuse this method with transpose()!
*/
DataArrayInt *DataArrayInt::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
{
throw INTERP_KERNEL::Exception("DataArrayInt::fromNoInterlace : Not defined array !");
int *tab=_mem.fromNoInterlace(getNumberOfComponents());
DataArrayInt *ret=DataArrayInt::New();
- ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
+ ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
return ret;
}
* 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.
- * \warning Do not confuse this method with transpose()!
*/
DataArrayInt *DataArrayInt::toNoInterlace() const throw(INTERP_KERNEL::Exception)
{
throw INTERP_KERNEL::Exception("DataArrayInt::toNoInterlace : Not defined array !");
int *tab=_mem.toNoInterlace(getNumberOfComponents());
DataArrayInt *ret=DataArrayInt::New();
- ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
+ ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
return ret;
}
int *tmp=new int[nbTuples*nbOfCompo];
const int *iptr=getConstPointer();
for(int i=0;i<nbTuples;i++)
- std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*old2New[i]);
+ {
+ int v=old2New[i];
+ if(v>=0 && v<nbTuples)
+ std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*v);
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::renumberInPlace : At place #" << i << " value is " << v << " ! Should be in [0," << nbTuples << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
delete [] tmp;
declareAsNew();
int *tmp=new int[nbTuples*nbOfCompo];
const int *iptr=getConstPointer();
for(int i=0;i<nbTuples;i++)
- std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),tmp+nbOfCompo*i);
+ {
+ int v=new2Old[i];
+ if(v>=0 && v<nbTuples)
+ std::copy(iptr+nbOfCompo*v,iptr+nbOfCompo*(v+1),tmp+nbOfCompo*i);
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::renumberInPlaceR : At place #" << i << " value is " << v << " ! Should be in [0," << nbTuples << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
delete [] tmp;
declareAsNew();
* \param [in] step - index increment to get index of the next tuple to copy.
* \return DataArrayInt * - the new instance of DataArrayInt that the caller
* is to delete using decrRef() as it is no more needed.
- * \throw If (\a end2 < \a bg) or (\a step <= 0).
* \sa DataArrayInt::substr.
*/
DataArrayInt *DataArrayInt::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception)
checkAllocated();
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
int nbComp=getNumberOfComponents();
- int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayInt::selectByTupleId2 : ");
+ int newNbOfTuples=GetNumberOfItemGivenBESRelative(bg,end2,step,"DataArrayInt::selectByTupleId2 : ");
ret->alloc(newNbOfTuples,nbComp);
int *pt=ret->getPointer();
const int *srcPt=getConstPointer()+bg*nbComp;
* \throw If \a end > \a this->getNumberOfTuples().
* \throw If \a this is not allocated.
*/
-DataArrayInt *DataArrayInt::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
+DataArray *DataArrayInt::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
{
checkAllocated();
int nbOfComp=getNumberOfComponents();
const int *pt=getConstPointer();
int *pt2=CheckAndPreparePermutation(pt,pt+nbTuples);
DataArrayInt *ret=DataArrayInt::New();
- ret->useArray(pt2,true,CPP_DEALLOC,nbTuples,1);
+ ret->useArray(pt2,true,C_DEALLOC,nbTuples,1);
return ret;
}
/*!
* 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.
* \throw If \a this is not allocated
* \throw If getNbOfElems() % \a newNbOfCompo != 0.
* of tuples, and inversely its number of tuples to become equal to its number of
* components. So that its raw data **does not** change, instead splitting this
* data into tuples changes.
- * \throw If \a this is not allocated.
* \warning This method erases all (name and unit) component info set before!
* \warning Do not confuse this method with fromNoInterlace() and toNoInterlace()!
+ * \throw If \a this is not allocated.
* \sa rearrange()
*/
void DataArrayInt::transpose() throw(INTERP_KERNEL::Exception)
* 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) throw(INTERP_KERNEL::Exception)
{
+ 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();
* \throw If a component index (\a i) is not valid:
* \a i < 0 || \a i >= \a this->getNumberOfComponents().
*
- * \ref cpp_mcdataarrayint_keepselectedcomponents "Here is a Python example".
+ * \ref py_mcdataarrayint_keepselectedcomponents "Here is a Python example".
*/
-DataArrayInt *DataArrayInt::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
+DataArray *DataArrayInt::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
{
checkAllocated();
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : mismatch of number of tuples !");
int nbOfComp1=getNumberOfComponents();
int nbOfComp2=other->getNumberOfComponents();
- int *newArr=new int[nbOfTuples*(nbOfComp1+nbOfComp2)];
+ int *newArr=(int *)malloc(nbOfTuples*(nbOfComp1+nbOfComp2)*sizeof(int));
int *w=newArr;
const int *inp1=getConstPointer();
const int *inp2=other->getConstPointer();
w=std::copy(inp1,inp1+nbOfComp1,w);
w=std::copy(inp2,inp2+nbOfComp2,w);
}
- useArray(newArr,true,CPP_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
+ useArray(newArr,true,C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
std::vector<int> compIds(nbOfComp2);
for(int i=0;i<nbOfComp2;i++)
compIds[i]=nbOfComp1+i;
* \throw If \a compoIds.size() != \a a->getNumberOfComponents().
* \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
*
- * \ref cpp_mcdataarrayint_setselectedcomponents "Here is a Python example".
+ * \ref py_mcdataarrayint_setselectedcomponents "Here is a Python example".
*/
void DataArrayInt::setSelectedComponents(const DataArrayInt *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
{
* \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
* \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
*
- * \ref cpp_mcdataarrayint_setpartofvalues1 "Here is a Python example".
+ * \ref py_mcdataarrayint_setpartofvalues1 "Here is a Python example".
*/
void DataArrayInt::setPartOfValues1(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
{
* non-empty range of increasing indices or indices are out of a valid range
* for \this array.
*
- * \ref cpp_mcdataarrayint_setpartofvaluessimple1 "Here is a Python example".
+ * \ref py_mcdataarrayint_setpartofvaluessimple1 "Here is a Python example".
*/
void DataArrayInt::setPartOfValuesSimple1(int a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
{
* \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
* <em> a->getNumberOfComponents() != (endComp - bgComp)</em>.
*
- * \ref cpp_mcdataarrayint_setpartofvalues2 "Here is a Python example".
+ * \ref py_mcdataarrayint_setpartofvalues2 "Here is a Python example".
*/
void DataArrayInt::setPartOfValues2(const DataArrayInt *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
{
* \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
* out of a valid range for \a this array.
*
- * \ref cpp_mcdataarrayint_setpartofvaluessimple2 "Here is a Python example".
+ * \ref py_mcdataarrayint_setpartofvaluessimple2 "Here is a Python example".
*/
void DataArrayInt::setPartOfValuesSimple2(int a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
{
* non-empty range of increasing indices or indices are out of a valid range
* for \this array.
*
- * \ref cpp_mcdataarrayint_setpartofvalues3 "Here is a Python example".
+ * \ref py_mcdataarrayint_setpartofvalues3 "Here is a Python example".
*/
void DataArrayInt::setPartOfValues3(const DataArrayInt *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
{
* non-empty range of increasing indices or indices are out of a valid range
* for \this array.
*
- * \ref cpp_mcdataarrayint_setpartofvaluessimple3 "Here is a Python example".
+ * \ref py_mcdataarrayint_setpartofvaluessimple3 "Here is a Python example".
*/
void DataArrayInt::setPartOfValuesSimple3(int a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
{
* \throw If any tuple index given by \a tuplesSelec is out of a valid range for
* \a a array.
*/
-void DataArrayInt::setContigPartOfSelectedValues(int tupleIdStart, const DataArrayInt*a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
+void DataArrayInt::setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
{
+ if(!aBase || !tuplesSelec)
+ throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : input DataArray is NULL !");
+ const DataArrayInt *a=dynamic_cast<const DataArrayInt *>(aBase);
+ if(!a)
+ throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : input DataArray aBase is not a DataArrayInt !");
checkAllocated();
a->checkAllocated();
tuplesSelec->checkAllocated();
* non-empty range of increasing indices or indices are out of a valid range
* for the array \a a.
*/
-void DataArrayInt::setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayInt *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
+void DataArrayInt::setContigPartOfSelectedValues2(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
{
+ if(!aBase)
+ throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : input DataArray is NULL !");
+ const DataArrayInt *a=dynamic_cast<const DataArrayInt *>(aBase);
+ if(!a)
+ throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : input DataArray aBase is not a DataArrayInt !");
checkAllocated();
a->checkAllocated();
int nbOfComp=getNumberOfComponents();
return _mem[tupleId*_info_on_compo.size()+compoId];
}
+/*!
+ * Returns the first value of \a this.
+ * \return int - the last value of \a this array.
+ * \throw If \a this is not allocated.
+ * \throw If \a this->getNumberOfComponents() != 1.
+ * \throw If \a this->getNumberOfTuples() < 1.
+ */
+int DataArrayInt::front() const throw(INTERP_KERNEL::Exception)
+{
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::front : number of components not equal to one !");
+ int nbOfTuples=getNumberOfTuples();
+ if(nbOfTuples<1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::front : number of tuples must be >= 1 !");
+ return *(getConstPointer());
+}
+
/*!
* Returns the last value of \a this.
- * \return double - the last value of \a this array.
+ * \return int - the last value of \a this array.
* \throw If \a this is not allocated.
* \throw If \a this->getNumberOfComponents() != 1.
* \throw If \a this->getNumberOfTuples() < 1.
return -1;
}
+/*!
+ * This method returns the number of values in \a this that are equals to input parameter \a value.
+ * This method only works for single component array.
+ *
+ * \return a value in [ 0, \c this->getNumberOfTuples() )
+ *
+ * \throw If \a this is not allocated
+ *
+ */
+int DataArrayInt::count(int value) const throw(INTERP_KERNEL::Exception)
+{
+ int ret=0;
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::count : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
+ const int *vals=begin();
+ int nbOfTuples=getNumberOfTuples();
+ for(int i=0;i<nbOfTuples;i++,vals++)
+ if(*vals==value)
+ ret++;
+ return ret;
+}
+
/*!
* This method is an extension of DataArrayInt::presenceOfValue method because this method works for DataArrayInt with
* any number of components excepted 0 (an INTERP_KERNEL::Exception is thrown in this case).
return ret;
}
+/*!
+ * This method accumulate using addition tuples in \a this using input index array [ \a bgOfIndex, \a endOfIndex ).
+ * The returned array will have same number of components than \a this and number of tuples equal to
+ * \c std::distance(bgOfIndex,endOfIndex) \b minus \b one.
+ *
+ * The input index array is expected to be ascendingly sorted in which the all referenced ids should be in [0, \c this->getNumberOfTuples).
+ *
+ * \param [in] bgOfIndex - begin (included) of the input index array.
+ * \param [in] endOfIndex - end (excluded) of the input index array.
+ * \return DataArrayInt * - the new instance having the same number of components than \a this.
+ *
+ * \throw If bgOfIndex or end is NULL.
+ * \throw If input index array is not ascendingly sorted.
+ * \throw If there is an id in [ \a bgOfIndex, \a endOfIndex ) not in [0, \c this->getNumberOfTuples).
+ * \throw If std::distance(bgOfIndex,endOfIndex)==0.
+ */
+DataArrayInt *DataArrayInt::accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const throw(INTERP_KERNEL::Exception)
+{
+ if(!bgOfIndex || !endOfIndex)
+ throw INTERP_KERNEL::Exception("DataArrayInt::accumulatePerChunck : input pointer NULL !");
+ checkAllocated();
+ int nbCompo=getNumberOfComponents();
+ int nbOfTuples=getNumberOfTuples();
+ int sz=(int)std::distance(bgOfIndex,endOfIndex);
+ if(sz<1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::accumulatePerChunck : invalid size of input index array !");
+ sz--;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(sz,nbCompo);
+ const int *w=bgOfIndex;
+ if(*w<0 || *w>=nbOfTuples)
+ throw INTERP_KERNEL::Exception("DataArrayInt::accumulatePerChunck : The first element of the input index not in [0,nbOfTuples) !");
+ const int *srcPt=begin()+(*w)*nbCompo;
+ int *tmp=ret->getPointer();
+ for(int i=0;i<sz;i++,tmp+=nbCompo,w++)
+ {
+ std::fill(tmp,tmp+nbCompo,0.);
+ if(w[1]>=w[0])
+ {
+ for(int j=w[0];j<w[1];j++,srcPt+=nbCompo)
+ {
+ if(j>=0 && j<nbOfTuples)
+ std::transform(srcPt,srcPt+nbCompo,tmp,tmp,std::plus<int>());
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::accumulatePerChunck : At rank #" << i << " the input index array points to id " << j << " should be in [0," << nbOfTuples << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ }
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::accumulatePerChunck : At rank #" << i << " the input index array is not in ascendingly sorted.";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ ret->copyStringInfoFrom(*this);
+ return ret.retn();
+}
+
/*!
* Returns a new DataArrayInt by concatenating two given arrays, so that (1) the number
* of tuples in the result array is <em> a1->getNumberOfTuples() + a2->getNumberOfTuples() -
return ret.retn();
}
+/*!
+ * This method takes as input a list of DataArrayInt instances \a arrs that represent each a packed index arrays.
+ * A packed index array is an allocated array with one component, and at least one tuple. The first element
+ * of each array in \a arrs must be 0. Each array in \a arrs is expected to be increasingly monotonic.
+ * This method is useful for users that want to aggregate a pair of DataArrayInt representing an indexed data (typically nodal connectivity index in unstructured meshes.
+ *
+ * \return DataArrayInt * - a new object to be managed by the caller.
+ */
+DataArrayInt *DataArrayInt::AggregateIndexes(const std::vector<const DataArrayInt *>& arrs) throw(INTERP_KERNEL::Exception)
+{
+ int retSz=1;
+ for(std::vector<const DataArrayInt *>::const_iterator it4=arrs.begin();it4!=arrs.end();it4++)
+ {
+ if(*it4)
+ {
+ (*it4)->checkAllocated();
+ if((*it4)->getNumberOfComponents()!=1)
+ {
+ std::ostringstream oss; oss << "DataArrayInt::AggregateIndexes : presence of a DataArrayInt instance with nb of compo != 1 at pos " << std::distance(arrs.begin(),it4) << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ int nbTupl=(*it4)->getNumberOfTuples();
+ if(nbTupl<1)
+ {
+ std::ostringstream oss; oss << "DataArrayInt::AggregateIndexes : presence of a DataArrayInt instance with nb of tuples < 1 at pos " << std::distance(arrs.begin(),it4) << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ if((*it4)->front()!=0)
+ {
+ std::ostringstream oss; oss << "DataArrayInt::AggregateIndexes : presence of a DataArrayInt instance with front value != 0 at pos " << std::distance(arrs.begin(),it4) << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ retSz+=nbTupl-1;
+ }
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::AggregateIndexes : presence of a null instance at pos " << std::distance(arrs.begin(),it4) << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ if(arrs.empty())
+ throw INTERP_KERNEL::Exception("DataArrayInt::AggregateIndexes : input list must be NON EMPTY !");
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
+ ret->alloc(retSz,1);
+ int *pt=ret->getPointer(); *pt++=0;
+ for(std::vector<const DataArrayInt *>::const_iterator it=arrs.begin();it!=arrs.end();it++)
+ pt=std::transform((*it)->begin()+1,(*it)->end(),pt,std::bind2nd(std::plus<int>(),pt[-1]));
+ ret->copyStringInfoFrom(*(arrs[0]));
+ return ret.retn();
+}
+
/*!
* 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 int - the maximal value among all values of \a this array.
* \throw If \a this->getNumberOfComponents() != 1
* \throw If \a this->getNumberOfTuples() < 1
*/
/*!
* Modify all elements of \a this array, so that
* an element _x_ becomes \f$ numerator / x \f$.
- * \param [in] numerator - the numerator used to modify array elements.
- * \throw If \a this is not allocated.
- * \throw If there is an element equal to 0 in \a this array.
* \warning If an exception is thrown because of presence of 0 element in \a this
* array, all elements processed before detection of the zero element remain
* modified.
+ * \param [in] numerator - the numerator used to modify array elements.
+ * \throw If \a this is not allocated.
+ * \throw If there is an element equal to 0 in \a this array.
*/
void DataArrayInt::applyInv(int numerator) throw(INTERP_KERNEL::Exception)
{
* This method returns a newly allocated array storing stored ascendantly tuple ids in \b this so that
* this[*id] in [\b vmin,\b vmax)
*
- * \param [in] vmin begin of range. This value is included in range.
- * \param [out] vmax end of range. This value is \b not included in range.
+ * \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.
*/
DataArrayInt *DataArrayInt::getIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception)
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() ).
+ */
+bool DataArrayInt::checkAllIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception)
+{
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::checkAllIdsInRange : this must have exactly one component !");
+ int nbOfTuples=getNumberOfTuples();
+ bool ret=true;
+ const int *cptr=getConstPointer();
+ for(int i=0;i<nbOfTuples;i++,cptr++)
+ {
+ if(*cptr>=vmin && *cptr<vmax)
+ { ret=ret && *cptr==i; }
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::checkAllIdsInRange : tuple #" << i << " has value " << *cptr << " should be in [" << vmin << "," << vmax << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ return ret;
+}
+
/*!
* Modify all elements of \a this array, so that
* an element _x_ becomes <em> val % x </em>.
- * \param [in] val - the divident used to modify array elements.
- * \throw If \a this is not allocated.
- * \throw If there is an element equal to or less than 0 in \a this array.
* \warning If an exception is thrown because of presence of an element <= 0 in \a this
* array, all elements processed before detection of the zero element remain
* modified.
+ * \param [in] val - the divident used to modify array elements.
+ * \throw If \a this is not allocated.
+ * \throw If there is an element equal to or less than 0 in \a this array.
*/
void DataArrayInt::applyRModulus(int val) throw(INTERP_KERNEL::Exception)
{
/*!
* Returns a new DataArrayInt which contains all elements of given one-dimensional
- * not negative arrays. The result array does not contain any duplicates and its values
+ * arrays. The result array does not contain any duplicates and its values
* are sorted in ascending order.
* \param [in] arr - sequence of DataArrayInt's to unite.
* \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
* array using decrRef() as it is no more needed.
* \throw If any \a arr[i] is not allocated.
* \throw If \a arr[i]->getNumberOfComponents() != 1.
- * \throw If any value of \a arr[i] is negative.
*/
DataArrayInt *DataArrayInt::BuildUnion(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
{
for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
if(*it4)
a.push_back(*it4);
- int valm=std::numeric_limits<int>::max();
for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
{
(*it)->checkAllocated();
if((*it)->getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : only single component allowed !");
- int tmp1;
- valm=std::min((*it)->getMinValue(tmp1),valm);
}
- if(valm<0)
- throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : a negative value has been detected !");
//
std::set<int> r;
for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
/*!
* Returns a new DataArrayInt which contains elements present in each of given one-dimensional
- * not negative arrays. The result array does not contain any duplicates and its values
+ * arrays. The result array does not contain any duplicates and its values
* are sorted in ascending order.
* \param [in] arr - sequence of DataArrayInt's to intersect.
* \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
* array using decrRef() as it is no more needed.
* \throw If any \a arr[i] is not allocated.
* \throw If \a arr[i]->getNumberOfComponents() != 1.
- * \throw If any value of \a arr[i] < 0.
*/
DataArrayInt *DataArrayInt::BuildIntersection(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
{
for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
if(*it4)
a.push_back(*it4);
- int valm=std::numeric_limits<int>::max();
for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
{
(*it)->checkAllocated();
if((*it)->getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayInt::BuildIntersection : only single component allowed !");
- int tmp1;
- valm=std::min((*it)->getMinValue(tmp1),valm);
}
- if(valm<0)
- throw INTERP_KERNEL::Exception("DataArrayInt::BuildIntersection : a negative value has been detected !");
//
std::set<int> r;
for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
/*!
* Returns a new DataArrayInt which contains all elements of \a this and a given
- * one-dimensional not negative arrays. The result array does not contain any duplicates
+ * one-dimensional arrays. The result array does not contain any duplicates
* and its values are sorted in ascending order.
* \param [in] other - an array to unite with \a this one.
* \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
* \throw If \a this or \a other is not allocated.
* \throw If \a this->getNumberOfComponents() != 1.
* \throw If \a other->getNumberOfComponents() != 1.
- * \throw If any value of \a this or \a other is negative.
*/
DataArrayInt *DataArrayInt::buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
{
/*!
* Returns a new DataArrayInt which contains elements present in both \a this and a given
- * one-dimensional not negative arrays. The result array does not contain any duplicates
+ * one-dimensional arrays. The result array does not contain any duplicates
* and its values are sorted in ascending order.
* \param [in] other - an array to intersect with \a this one.
* \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
* \throw If \a this or \a other is not allocated.
* \throw If \a this->getNumberOfComponents() != 1.
* \throw If \a other->getNumberOfComponents() != 1.
- * \throw If any value of \a this or \a other is negative.
*/
DataArrayInt *DataArrayInt::buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
{
* "MEDCouplingUMesh::buildDescendingConnectivity" and
* \ref ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivityIndex
* "MEDCouplingUMesh::getNodalConnectivityIndex" etc.
+ * This method preforms the reverse operation of DataArrayInt::computeOffsets2.
* \return DataArrayInt * - a new instance of DataArrayInt, whose number of tuples
* equals to \a this->getNumberOfComponents() - 1, and number of components is 1.
* The caller is to delete this array using decrRef() as it is no more needed.
* - this contains [1,3,6,7,7,9,15]
* - result array contains [2,3,1,0,2,6],
* where 2 = 3 - 1, 3 = 6 - 3, 1 = 7 - 6 etc.
+ *
+ * \sa DataArrayInt::computeOffsets2
*/
DataArrayInt *DataArrayInt::deltaShiftIndex() const throw(INTERP_KERNEL::Exception)
{
* components remains the same and number of tuples is inceamented by one.<br>
* This method is useful for allToAllV in MPI with contiguous policy. This method
* differs from computeOffsets() in that the number of tuples is changed by this one.
+ * This method preforms the reverse operation of DataArrayInt::deltaShiftIndex.
* \throw If \a this is not allocated.
* \throw If \a this->getNumberOfComponents() != 1.
*
* \b Example: <br>
* - Before \a this contains [3,5,1,2,0,8]
* - After \a this contains [0,3,8,9,11,11,19]<br>
+ * \sa DataArrayInt::deltaShiftIndex
*/
void DataArrayInt::computeOffsets2() throw(INTERP_KERNEL::Exception)
{
if(getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets2 : only single component allowed !");
int nbOfTuples=getNumberOfTuples();
- int *ret=new int[nbOfTuples+1];
+ int *ret=(int *)malloc((nbOfTuples+1)*sizeof(int));
if(nbOfTuples==0)
return ;
const int *work=getConstPointer();
ret[0]=0;
for(int i=0;i<nbOfTuples;i++)
ret[i+1]=work[i]+ret[i];
- useArray(ret,true,CPP_DEALLOC,nbOfTuples+1,1);
+ useArray(ret,true,C_DEALLOC,nbOfTuples+1,1);
declareAsNew();
}
*
* Info on components is copied either from the first array (in the first case) or from
* the array with maximal number of elements (getNbOfElems()).
+ * \warning No check of division by zero is performed!
* \param [in] a1 - a numerator array.
* \param [in] a2 - a denominator array.
* \return DataArrayInt * - the new instance of DataArrayInt.
* \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
* \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
* none of them has number of tuples or components equal to 1.
- * \warning No check of division by zero is performed!
*/
DataArrayInt *DataArrayInt::Divide(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
{
* 3. The arrays have same number of components and \a other array has one tuple. Then
* _a_ [ i, j ] /= _a2_ [ 0, j ].
*
+ * \warning No check of division by zero is performed!
* \param [in] other - an array to divide \a this one by.
* \throw If \a other is NULL.
* \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
* \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
* \a other has number of both tuples and components not equal to 1.
- * \warning No check of division by zero is performed!
*/
void DataArrayInt::divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
{
*
* Info on components is copied either from the first array (in the first case) or from
* the array with maximal number of elements (getNbOfElems()).
+ * \warning No check of division by zero is performed!
* \param [in] a1 - a dividend array.
* \param [in] a2 - a divisor array.
* \return DataArrayInt * - the new instance of DataArrayInt.
* \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
* \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
* none of them has number of tuples or components equal to 1.
- * \warning No check of division by zero is performed!
*/
DataArrayInt *DataArrayInt::Modulus(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
{
* 3. The arrays have same number of components and \a other array has one tuple. Then
* _a_ [ i, j ] %= _a2_ [ 0, j ].
*
+ * \warning No check of division by zero is performed!
* \param [in] other - a divisor array.
* \throw If \a other is NULL.
* \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
* \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
* \a other has number of both tuples and components not equal to 1.
- * \warning No check of division by zero is performed!
*/
void DataArrayInt::modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
{
int *DataArrayInt::CheckAndPreparePermutation(const int *start, const int *end)
{
std::size_t sz=std::distance(start,end);
- int *ret=new int[sz];
+ int *ret=(int *)malloc(sz*sizeof(int));
int *work=new int[sz];
std::copy(start,end,work);
std::sort(work,work+sz);
if(std::unique(work,work+sz)!=work+sz)
{
delete [] work;
- delete [] ret;
+ free(ret);
throw INTERP_KERNEL::Exception("Some elements are equals in the specified array !");
}
+ std::map<int,int> m;
+ for(int *workPt=work;workPt!=work+sz;workPt++)
+ m[*workPt]=(int)std::distance(work,workPt);
int *iter2=ret;
for(const int *iter=start;iter!=end;iter++,iter2++)
- *iter2=(int)std::distance(work,std::find(work,work+sz,*iter));
+ *iter2=m[*iter];
delete [] work;
return ret;
}