* array using decrRef() as it is no more needed.
* \throw If \a this is not allocated.
* \throw If \a this->getNumberOfComponents() != 1.
+ * \sa DataArrayInt::getIdsEqualTuple
*/
DataArrayInt *DataArrayInt::getIdsEqual(int val) const
{
checkAllocated();
if(getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqual : the array must have only one component, you can call 'rearrange' method before !");
- const int *cptr=getConstPointer();
+ const int *cptr(getConstPointer());
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
int nbOfTuples=getNumberOfTuples();
for(int i=0;i<nbOfTuples;i++,cptr++)
checkAllocated();
if(getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqual : the array must have only one component, you can call 'rearrange' method before !");
- const int *cptr=getConstPointer();
+ const int *cptr(getConstPointer());
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
int nbOfTuples=getNumberOfTuples();
for(int i=0;i<nbOfTuples;i++,cptr++)
return ret.retn();
}
+/*!
+ * Creates a new DataArrayInt containing IDs (indices) of tuples holding tuple equal to those defined by [ \a tupleBg , \a tupleEnd )
+ * This method is an extension of DataArrayInt::getIdsEqual method.
+ *
+ * \param [in] tupleBg - the begin (included) of the input tuple to find within \a this.
+ * \param [in] tupleEnd - the end (excluded) of the input tuple to find within \a this.
+ * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
+ * array using decrRef() as it is no more needed.
+ * \throw If \a this is not allocated.
+ * \throw If \a this->getNumberOfComponents() != std::distance(tupleBg,tupleEnd).
+ * \throw If \a this->getNumberOfComponents() is equal to 0.
+ * \sa DataArrayInt::getIdsEqual
+ */
+DataArrayInt *DataArrayInt::getIdsEqualTuple(const int *tupleBg, const int *tupleEnd) const
+{
+ std::size_t nbOfCompoExp(std::distance(tupleBg,tupleEnd));
+ checkAllocated();
+ if(getNumberOfComponents()!=(int)nbOfCompoExp)
+ {
+ std::ostringstream oss; oss << "DataArrayInt::getIdsEqualTuple : mismatch of number of components. Input tuple has " << nbOfCompoExp << " whereas this array has " << getNumberOfComponents() << " components !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ if(nbOfCompoExp==0)
+ throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqualTuple : number of components should be > 0 !");
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
+ const int *bg(begin()),*end2(end()),*work(begin());
+ while(work!=end2)
+ {
+ work=std::search(work,end2,tupleBg,tupleEnd);
+ if(work!=end2)
+ {
+ std::size_t pos(std::distance(bg,work));
+ if(pos%nbOfCompoExp==0)
+ ret->pushBackSilent(pos/nbOfCompoExp);
+ work++;
+ }
+ }
+ return ret.retn();
+}
/*!
* Assigns \a newValue to all elements holding \a oldValue within \a this
self.assertTrue(m.getCellsContainingPoint([0.,0.27],1e-12).isEqual(DataArrayInt([2])))
pass
+ def testSwig2DAIGetIdsEqualTuple1(self):
+ da=DataArrayInt([0,7,1,2,4,1,2,1,1,2,0,1,2,1,5,1,1,2],9,2)
+ self.assertTrue(da.getIdsEqualTuple([1,2]).isEqual(DataArrayInt([1,4,8])))
+ self.assertTrue(da.getIdsEqualTuple((1,2)).isEqual(DataArrayInt([1,4,8])))
+ self.assertTrue(da.getIdsEqualTuple(DataArrayInt([1,2])).isEqual(DataArrayInt([1,4,8])))
+ da.rearrange(3)
+ self.assertRaises(InterpKernelException,da.getIdsEqualTuple,[1,2])# mismatch nb of compo (3) and nb of elts in input tuple (2)
+ self.assertTrue(da.getIdsEqualTuple([2,0,1]).isEqual(DataArrayInt([3])))
+ self.assertTrue(da.getIdsEqualTuple([2,0,7]).isEqual(DataArrayInt([])))
+ da.rearrange(1)
+ self.assertTrue(da.getIdsEqualTuple(2).isEqual(DataArrayInt([3,6,9,12,17])))
+ self.assertTrue(da.getIdsEqualTuple(2).isEqual(da.getIdsEqual(2)))
+ pass
+
def setUp(self):
pass
pass
%newobject ParaMEDMEM::DataArrayInt::getIdsNotEqual;
%newobject ParaMEDMEM::DataArrayInt::getIdsEqualList;
%newobject ParaMEDMEM::DataArrayInt::getIdsNotEqualList;
+%newobject ParaMEDMEM::DataArrayInt::getIdsEqualTuple;
%newobject ParaMEDMEM::DataArrayInt::sumPerTuple;
%newobject ParaMEDMEM::DataArrayInt::negate;
%newobject ParaMEDMEM::DataArrayInt::computeAbs;
return self->accumulatePerChunck(bg,bg+sz);
}
+ DataArrayInt *getIdsEqualTuple(PyObject *inputTuple) const throw(INTERP_KERNEL::Exception)
+ {
+ int sw,sz,val;
+ std::vector<int> val2;
+ const int *bg(convertObjToPossibleCpp1_Safe(inputTuple,sw,sz,val,val2));
+ return self->getIdsEqualTuple(bg,bg+sz);
+ }
+
PyObject *splitInBalancedSlices(int nbOfSlices) const throw(INTERP_KERNEL::Exception)
{
std::vector< std::pair<int,int> > slcs(self->splitInBalancedSlices(nbOfSlices));