- int nbOfTuples=getNumberOfTuples();
- const int *pt=getConstPointer();
- for(int i=0;i<nbOfTuples;i++,pt++)
- if(*pt!=i)
- return false;
- return true;
-}
-
-/*!
- * Checks if all values in \a this array are equal to \a val.
- * \param [in] val - value to check equality of array values to.
- * \return bool - \a true if all values are \a val.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1
- */
-bool DataArrayInt::isUniform(int val) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::isUniform : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
- int nbOfTuples=getNumberOfTuples();
- const int *w=getConstPointer();
- const int *end2=w+nbOfTuples;
- for(;w!=end2;w++)
- if(*w!=val)
- return false;
- return true;
-}
-
-/*!
- * Creates a new DataArrayDouble and assigns all (textual and numerical) data of \a this
- * array to the new one.
- * \return DataArrayDouble * - the new instance of DataArrayInt.
- */
-DataArrayDouble *DataArrayInt::convertToDblArr() const
-{
- checkAllocated();
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(getNumberOfTuples(),getNumberOfComponents());
- std::size_t nbOfVals=getNbOfElems();
- const int *src=getConstPointer();
- double *dest=ret->getPointer();
- std::copy(src,src+nbOfVals,dest);
- ret->copyStringInfoFrom(*this);
- return ret;
-}
-
-/*!
- * Returns a shorten copy of \a this array. The new DataArrayInt contains all
- * tuples starting from the \a tupleIdBg-th tuple and including all tuples located before
- * the \a tupleIdEnd-th one. This methods has a similar behavior as std::string::substr().
- * This method is a specialization of selectByTupleId2().
- * \param [in] tupleIdBg - index of the first tuple to copy from \a this array.
- * \param [in] tupleIdEnd - index of the tuple before which the tuples to copy are located.
- * If \a tupleIdEnd == -1, all the tuples till the end of \a this array are copied.
- * \return DataArrayInt * - the new instance of DataArrayInt that the caller
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a tupleIdBg < 0.
- * \throw If \a tupleIdBg > \a this->getNumberOfTuples().
- \throw If \a tupleIdEnd != -1 && \a tupleIdEnd < \a this->getNumberOfTuples().
- * \sa DataArrayInt::selectByTupleId2
- */
-DataArrayInt *DataArrayInt::substr(int tupleIdBg, int tupleIdEnd) const
-{
- checkAllocated();
- int nbt=getNumberOfTuples();
- if(tupleIdBg<0)
- throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter must be greater than 0 !");
- if(tupleIdBg>nbt)
- throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater than number of tuples !");
- int trueEnd=tupleIdEnd;
- if(tupleIdEnd!=-1)
- {
- if(tupleIdEnd>nbt)
- throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater or equal than number of tuples !");
- }
- else
- trueEnd=nbt;
- int nbComp=getNumberOfComponents();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(trueEnd-tupleIdBg,nbComp);
- ret->copyStringInfoFrom(*this);
- std::copy(getConstPointer()+tupleIdBg*nbComp,getConstPointer()+trueEnd*nbComp,ret->getPointer());
- return ret.retn();
-}
-
-/*!
- * 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.
- * \throw If \a newNbOfCompo is lower than 1.
- * \throw If the rearrange method would lead to a number of tuples higher than 2147483647 (maximal capacity of int32 !).
- * \warning This method erases all (name and unit) component info set before!
- */
-void DataArrayInt::rearrange(int newNbOfCompo)
-{
- checkAllocated();
- if(newNbOfCompo<1)
- throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : input newNbOfCompo must be > 0 !");
- std::size_t nbOfElems=getNbOfElems();
- if(nbOfElems%newNbOfCompo!=0)
- throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : nbOfElems%newNbOfCompo!=0 !");
- if(nbOfElems/newNbOfCompo>(std::size_t)std::numeric_limits<int>::max())
- throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : the rearrangement leads to too high number of tuples (> 2147483647) !");
- _info_on_compo.clear();
- _info_on_compo.resize(newNbOfCompo);
- declareAsNew();
-}
-
-/*!
- * Changes the number of components within \a this array to be equal to its number
- * 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.
- * \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()
-{
- checkAllocated();
- int nbOfTuples=getNumberOfTuples();
- rearrange(nbOfTuples);
-}
-
-/*!
- * Returns a shorten or extended copy of \a this array. If \a newNbOfComp is less
- * than \a this->getNumberOfComponents() then the result array is shorten as each tuple
- * is truncated to have \a newNbOfComp components, keeping first components. If \a
- * newNbOfComp is more than \a this->getNumberOfComponents() then the result array is
- * expanded as each tuple is populated with \a dftValue to have \a newNbOfComp
- * 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
- * is to delete using decrRef() as it is no more needed.
- * \throw If \a this is not allocated.
- */
-DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) const
-{
- checkAllocated();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
- ret->alloc(getNumberOfTuples(),newNbOfComp);
- const int *oldc=getConstPointer();
- int *nc=ret->getPointer();
- int nbOfTuples=getNumberOfTuples();
- int oldNbOfComp=getNumberOfComponents();
- int dim=std::min(oldNbOfComp,newNbOfComp);
- for(int i=0;i<nbOfTuples;i++)
- {
- int j=0;
- for(;j<dim;j++)
- nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
- for(;j<newNbOfComp;j++)
- nc[newNbOfComp*i+j]=dftValue;
- }
- ret->setName(getName());
- for(int i=0;i<dim;i++)
- ret->setInfoOnComponent(i,getInfoOnComponent(i));
- ret->setName(getName());
- return ret.retn();
-}
-
-/*!
- * Changes number of tuples in the array. If the new number of tuples is smaller
- * than the current number the array is truncated, otherwise the array is extended.
- * \param [in] nbOfTuples - new number of tuples.
- * \throw If \a this is not allocated.
- * \throw If \a nbOfTuples is negative.
- */
-void DataArrayInt::reAlloc(int nbOfTuples)
-{
- if(nbOfTuples<0)
- throw INTERP_KERNEL::Exception("DataArrayInt::reAlloc : input new number of tuples should be >=0 !");
- checkAllocated();
- _mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples);
- declareAsNew();
-}
-
-
-/*!
- * Returns a copy of \a this array composed of selected components.
- * The new DataArrayInt has the same number of tuples but includes components
- * specified by \a compoIds parameter. So that getNbOfElems() of the result array
- * can be either less, same or more than \a this->getNbOfElems().
- * \param [in] compoIds - sequence of zero based indices of components to include
- * into the new array.
- * \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.
- * \throw If a component index (\a i) is not valid:
- * \a i < 0 || \a i >= \a this->getNumberOfComponents().
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_keepselectedcomponents "Here is a Python example".
- * \endif
- */
-DataArray *DataArrayInt::keepSelectedComponents(const std::vector<int>& compoIds) const
-{
- checkAllocated();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
- int newNbOfCompo=(int)compoIds.size();
- int oldNbOfCompo=getNumberOfComponents();
- for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
- DataArray::CheckValueInRange(oldNbOfCompo,(*it),"keepSelectedComponents invalid requested component");
- int nbOfTuples=getNumberOfTuples();
- ret->alloc(nbOfTuples,newNbOfCompo);
- ret->copyPartOfStringInfoFrom(*this,compoIds);
- const int *oldc=getConstPointer();
- int *nc=ret->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- for(int j=0;j<newNbOfCompo;j++,nc++)
- *nc=oldc[i*oldNbOfCompo+compoIds[j]];
- return ret.retn();
-}
-
-/*!
- * Appends components of another array to components of \a this one, tuple by tuple.
- * So that the number of tuples of \a this array remains the same and the number of
- * components increases.
- * \param [in] other - the DataArrayInt to append to \a this one.
- * \throw If \a this is not allocated.
- * \throw If \a this and \a other arrays have different number of tuples.
- *
- * \if ENABLE_EXAMPLES
- * \ref cpp_mcdataarrayint_meldwith "Here is a C++ example".
- *
- * \ref py_mcdataarrayint_meldwith "Here is a Python example".
- * \endif
- */
-void DataArrayInt::meldWith(const DataArrayInt *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : DataArrayInt pointer in input is NULL !");
- checkAllocated();
- other->checkAllocated();
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples!=other->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : mismatch of number of tuples !");
- int nbOfComp1=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- int *newArr=(int *)malloc(nbOfTuples*(nbOfComp1+nbOfComp2)*sizeof(int));
- int *w=newArr;
- const int *inp1=getConstPointer();
- const int *inp2=other->getConstPointer();
- for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
- {
- w=std::copy(inp1,inp1+nbOfComp1,w);
- w=std::copy(inp2,inp2+nbOfComp2,w);
- }
- 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);
-}
-
-/*!
- * Copy all components in a specified order from another DataArrayInt.
- * 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.
- * \param [in] compoIds - sequence of zero based indices of components, data of which is
- * to be copied.
- * \throw If \a a is NULL.
- * \throw If \a compoIds.size() != \a a->getNumberOfComponents().
- * \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setselectedcomponents "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setSelectedComponents(const DataArrayInt *a, const std::vector<int>& compoIds)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayInt::setSelectedComponents : input DataArrayInt is NULL !");
- checkAllocated();
- a->checkAllocated();
- copyPartOfStringInfoFrom2(compoIds,*a);
- std::size_t partOfCompoSz=compoIds.size();
- int nbOfCompo=getNumberOfComponents();
- int nbOfTuples=std::min(getNumberOfTuples(),a->getNumberOfTuples());
- const int *ac=a->getConstPointer();
- int *nc=getPointer();
- for(int i=0;i<nbOfTuples;i++)
- for(std::size_t j=0;j<partOfCompoSz;j++,ac++)
- nc[nbOfCompo*i+compoIds[j]]=*ac;
-}
-
-/*!
- * Copy all values from another DataArrayInt into specified tuples and components
- * of \a this array. Textual data is not copied.
- * The tree parameters defining set of indices of tuples and components are similar to
- * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
- * \param [in] a - the array to copy values from.
- * \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
- * \param [in] endTuples - index of the tuple before which the tuples to assign to
- * are located.
- * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
- * \param [in] bgComp - index of the first component of \a this array to assign values to.
- * \param [in] endComp - index of the component before which the components to assign
- * to are located.
- * \param [in] stepComp - index increment to get index of the next component to assign to.
- * \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents()
- * must be equal to the number of columns to assign to, else an
- * exception is thrown; if \a false, then it is only required that \a
- * a->getNbOfElems() equals to number of values to assign to (this condition
- * must be respected even if \a strictCompoCompare is \a true). The number of
- * values to assign to is given by following Python expression:
- * \a nbTargetValues =
- * \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
- * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a this is not allocated.
- * \throw If parameters specifying tuples and components to assign to do not give a
- * non-empty range of increasing indices.
- * \throw If \a a->getNbOfElems() != \a nbTargetValues.
- * \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
- * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setpartofvalues1 "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setPartOfValues1(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues1 : DataArrayInt pointer in input is NULL !");
- const char msg[]="DataArrayInt::setPartOfValues1";
- checkAllocated();
- a->checkAllocated();
- int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
- int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
- DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
- bool assignTech=true;
- if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
- {
- if(strictCompoCompare)
- a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
- }
- else
- {
- a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
- assignTech=false;
- }
- int *pt=getPointer()+bgTuples*nbComp+bgComp;
- const int *srcPt=a->getConstPointer();
- if(assignTech)
- {
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- for(int j=0;j<newNbOfComp;j++,srcPt++)
- pt[j*stepComp]=*srcPt;
- }
- else
- {
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- {
- const int *srcPt2=srcPt;
- for(int j=0;j<newNbOfComp;j++,srcPt2++)
- pt[j*stepComp]=*srcPt2;
- }
- }
-}
-
-/*!
- * Assign a given value to values at specified tuples and components of \a this array.
- * The tree parameters defining set of indices of tuples and components are similar to
- * the tree parameters of the Python function \c range(\c start,\c stop,\c step)..
- * \param [in] a - the value to assign.
- * \param [in] bgTuples - index of the first tuple of \a this array to assign to.
- * \param [in] endTuples - index of the tuple before which the tuples to assign to
- * are located.
- * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
- * \param [in] bgComp - index of the first component of \a this array to assign to.
- * \param [in] endComp - index of the component before which the components to assign
- * to are located.
- * \param [in] stepComp - index increment to get index of the next component to assign to.
- * \throw If \a this is not allocated.
- * \throw If parameters specifying tuples and components to assign to, do not give a
- * non-empty range of increasing indices or indices are out of a valid range
- * for \this array.
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setpartofvaluessimple1 "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setPartOfValuesSimple1(int a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp)
-{
- const char msg[]="DataArrayInt::setPartOfValuesSimple1";
- checkAllocated();
- int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
- int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
- DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
- int *pt=getPointer()+bgTuples*nbComp+bgComp;
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- for(int j=0;j<newNbOfComp;j++)
- pt[j*stepComp]=a;
-}
-
-
-/*!
- * Copy all values from another DataArrayInt (\a a) into specified tuples and
- * components of \a this array. Textual data is not copied.
- * The tuples and components to assign to are defined by C arrays of indices.
- * There are two *modes of usage*:
- * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
- * of \a a is assigned to its own location within \a this array.
- * - If \a a includes one tuple, then all values of \a a are assigned to the specified
- * components of every specified tuple of \a this array. In this mode it is required
- * that \a a->getNumberOfComponents() equals to the number of specified components.
- *
- * \param [in] a - the array to copy values from.
- * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
- * assign values of \a a to.
- * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
- * pointer to a tuple index <em>(pi)</em> varies as this:
- * \a bgTuples <= \a pi < \a endTuples.
- * \param [in] bgComp - pointer to an array of component indices of \a this array to
- * assign values of \a a to.
- * \param [in] endComp - specifies the end of the array \a bgTuples, so that
- * pointer to a component index <em>(pi)</em> varies as this:
- * \a bgComp <= \a pi < \a endComp.
- * \param [in] strictCompoCompare - this parameter is checked only if the
- * *mode of usage* is the first; if it is \a true (default),
- * then \a a->getNumberOfComponents() must be equal
- * to the number of specified columns, else this is not required.
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a this is not allocated.
- * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
- * out of a valid range for \a this array.
- * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
- * if <em> a->getNumberOfComponents() != (endComp - bgComp) </em>.
- * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
- * <em> a->getNumberOfComponents() != (endComp - bgComp)</em>.
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setpartofvalues2 "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setPartOfValues2(const DataArrayInt *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues2 : DataArrayInt pointer in input is NULL !");
- const char msg[]="DataArrayInt::setPartOfValues2";
- checkAllocated();
- a->checkAllocated();
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- for(const int *z=bgComp;z!=endComp;z++)
- DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
- int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
- int newNbOfComp=(int)std::distance(bgComp,endComp);
- bool assignTech=true;
- if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
- {
- if(strictCompoCompare)
- a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
- }
- else
- {
- a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
- assignTech=false;
- }
- int *pt=getPointer();
- const int *srcPt=a->getConstPointer();
- if(assignTech)
- {
- for(const int *w=bgTuples;w!=endTuples;w++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- for(const int *z=bgComp;z!=endComp;z++,srcPt++)
- {
- pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt;
- }
- }
- }
- else
- {
- for(const int *w=bgTuples;w!=endTuples;w++)
- {
- const int *srcPt2=srcPt;
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
- {
- pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt2;
- }
- }
- }
-}
-
-/*!
- * Assign a given value to values at specified tuples and components of \a this array.
- * The tuples and components to assign to are defined by C arrays of indices.
- * \param [in] a - the value to assign.
- * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
- * assign \a a to.
- * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
- * pointer to a tuple index (\a pi) varies as this:
- * \a bgTuples <= \a pi < \a endTuples.
- * \param [in] bgComp - pointer to an array of component indices of \a this array to
- * assign \a a to.
- * \param [in] endComp - specifies the end of the array \a bgTuples, so that
- * pointer to a component index (\a pi) varies as this:
- * \a bgComp <= \a pi < \a endComp.
- * \throw If \a this is not allocated.
- * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
- * out of a valid range for \a this array.
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setpartofvaluessimple2 "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setPartOfValuesSimple2(int a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp)
-{
- checkAllocated();
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- for(const int *z=bgComp;z!=endComp;z++)
- DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
- int *pt=getPointer();
- for(const int *w=bgTuples;w!=endTuples;w++)
- for(const int *z=bgComp;z!=endComp;z++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- pt[(std::size_t)(*w)*nbComp+(*z)]=a;
- }
-}
-
-/*!
- * Copy all values from another DataArrayInt (\a a) into specified tuples and
- * components of \a this array. Textual data is not copied.
- * The tuples to assign to are defined by a C array of indices.
- * The components to assign to are defined by three values similar to parameters of
- * the Python function \c range(\c start,\c stop,\c step).
- * There are two *modes of usage*:
- * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
- * of \a a is assigned to its own location within \a this array.
- * - If \a a includes one tuple, then all values of \a a are assigned to the specified
- * components of every specified tuple of \a this array. In this mode it is required
- * that \a a->getNumberOfComponents() equals to the number of specified components.
- *
- * \param [in] a - the array to copy values from.
- * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
- * assign values of \a a to.
- * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
- * pointer to a tuple index <em>(pi)</em> varies as this:
- * \a bgTuples <= \a pi < \a endTuples.
- * \param [in] bgComp - index of the first component of \a this array to assign to.
- * \param [in] endComp - index of the component before which the components to assign
- * to are located.
- * \param [in] stepComp - index increment to get index of the next component to assign to.
- * \param [in] strictCompoCompare - this parameter is checked only in the first
- * *mode of usage*; if \a strictCompoCompare is \a true (default),
- * then \a a->getNumberOfComponents() must be equal
- * to the number of specified columns, else this is not required.
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a this is not allocated.
- * \throw If any index of tuple given by \a bgTuples is out of a valid range for
- * \a this array.
- * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
- * if <em> a->getNumberOfComponents()</em> is unequal to the number of components
- * defined by <em>(bgComp,endComp,stepComp)</em>.
- * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
- * <em> a->getNumberOfComponents()</em> is unequal to the number of components
- * defined by <em>(bgComp,endComp,stepComp)</em>.
- * \throw If parameters specifying components to assign to, do not give a
- * non-empty range of increasing indices or indices are out of a valid range
- * for \this array.
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setpartofvalues3 "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setPartOfValues3(const DataArrayInt *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues3 : DataArrayInt pointer in input is NULL !");
- const char msg[]="DataArrayInt::setPartOfValues3";
- checkAllocated();
- a->checkAllocated();
- int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
- int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
- bool assignTech=true;
- if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
- {
- if(strictCompoCompare)
- a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
- }
- else
- {
- a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
- assignTech=false;
- }
- int *pt=getPointer()+bgComp;
- const int *srcPt=a->getConstPointer();
- if(assignTech)
- {
- for(const int *w=bgTuples;w!=endTuples;w++)
- for(int j=0;j<newNbOfComp;j++,srcPt++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt;
- }
- }
- else
- {
- for(const int *w=bgTuples;w!=endTuples;w++)
- {
- const int *srcPt2=srcPt;
- for(int j=0;j<newNbOfComp;j++,srcPt2++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt2;
- }
- }
- }
-}
-
-/*!
- * Assign a given value to values at specified tuples and components of \a this array.
- * The tuples to assign to are defined by a C array of indices.
- * The components to assign to are defined by three values similar to parameters of
- * the Python function \c range(\c start,\c stop,\c step).
- * \param [in] a - the value to assign.
- * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
- * assign \a a to.
- * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
- * pointer to a tuple index <em>(pi)</em> varies as this:
- * \a bgTuples <= \a pi < \a endTuples.
- * \param [in] bgComp - index of the first component of \a this array to assign to.
- * \param [in] endComp - index of the component before which the components to assign
- * to are located.
- * \param [in] stepComp - index increment to get index of the next component to assign to.
- * \throw If \a this is not allocated.
- * \throw If any index of tuple given by \a bgTuples is out of a valid range for
- * \a this array.
- * \throw If parameters specifying components to assign to, do not give a
- * non-empty range of increasing indices or indices are out of a valid range
- * for \this array.
- *
- * \if ENABLE_EXAMPLES
- * \ref py_mcdataarrayint_setpartofvaluessimple3 "Here is a Python example".
- * \endif
- */
-void DataArrayInt::setPartOfValuesSimple3(int a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp)
-{
- const char msg[]="DataArrayInt::setPartOfValuesSimple3";
- checkAllocated();
- int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
- int *pt=getPointer()+bgComp;
- for(const int *w=bgTuples;w!=endTuples;w++)
- for(int j=0;j<newNbOfComp;j++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- pt[(std::size_t)(*w)*nbComp+j*stepComp]=a;
- }
-}
-
-void DataArrayInt::setPartOfValues4(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues4 : input DataArrayInt is NULL !");
- const char msg[]="DataArrayInt::setPartOfValues4";
- checkAllocated();
- a->checkAllocated();
- int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
- int newNbOfComp=(int)std::distance(bgComp,endComp);
- int nbComp=getNumberOfComponents();
- for(const int *z=bgComp;z!=endComp;z++)
- DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
- bool assignTech=true;
- if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
- {
- if(strictCompoCompare)
- a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
- }
- else
- {
- a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
- assignTech=false;
- }
- const int *srcPt=a->getConstPointer();
- int *pt=getPointer()+bgTuples*nbComp;
- if(assignTech)
- {
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- for(const int *z=bgComp;z!=endComp;z++,srcPt++)
- pt[*z]=*srcPt;
- }
- else
- {
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- {
- const int *srcPt2=srcPt;
- for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
- pt[*z]=*srcPt2;
- }
- }
-}
-
-void DataArrayInt::setPartOfValuesSimple4(int a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp)
-{
- const char msg[]="DataArrayInt::setPartOfValuesSimple4";
- checkAllocated();
- int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
- int nbComp=getNumberOfComponents();
- for(const int *z=bgComp;z!=endComp;z++)
- DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
- int *pt=getPointer()+bgTuples*nbComp;
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- for(const int *z=bgComp;z!=endComp;z++)
- pt[*z]=a;
-}
-
-/*!
- * Copy some tuples from another DataArrayInt into specified tuples
- * of \a this array. Textual data is not copied. Both arrays must have equal number of
- * components.
- * Both the tuples to assign and the tuples to assign to are defined by a DataArrayInt.
- * All components of selected tuples are copied.
- * \param [in] a - the array to copy values from.
- * \param [in] tuplesSelec - the array specifying both source tuples of \a a and
- * target tuples of \a this. \a tuplesSelec has two components, and the
- * first component specifies index of the source tuple and the second
- * one specifies index of the target tuple.
- * \throw If \a this is not allocated.
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a tuplesSelec is NULL.
- * \throw If \a tuplesSelec is not allocated.
- * \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
- * \throw If \a tuplesSelec->getNumberOfComponents() != 2.
- * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
- * the corresponding (\a this or \a a) array.
- */
-void DataArrayInt::setPartOfValuesAdv(const DataArrayInt *a, const DataArrayInt *tuplesSelec)
-{
- if(!a || !tuplesSelec)
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : DataArrayInt pointer in input is NULL !");
- checkAllocated();
- a->checkAllocated();
- tuplesSelec->checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=a->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : This and a do not have the same number of components !");
- if(tuplesSelec->getNumberOfComponents()!=2)
- throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
- int thisNt=getNumberOfTuples();
- int aNt=a->getNumberOfTuples();
- int *valsToSet=getPointer();
- const int *valsSrc=a->getConstPointer();
- for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
- {
- if(tuple[1]>=0 && tuple[1]<aNt)
- {
- if(tuple[0]>=0 && tuple[0]<thisNt)
- std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
- oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
- oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }