return ret.retn();
}
+/*!
+ * Elements of \a partOfThis are expected to be included in \a this.
+ * The returned array \a ret is so that this[ret]==partOfThis
+ *
+ * For example, if \a this array contents are [9,10,0,6,4,11,3,8] and if \a partOfThis contains [6,0,11,8]
+ * the return array will contain [3,2,5,7].
+ *
+ * \a this is expected to be a 1 compo allocated array.
+ * \param [in] partOfThis - A 1 compo allocated array
+ * \return - A newly allocated array to be dealed by caller having the same number of tuples than \a partOfThis.
+ * \throw if two same element is present twice in \a this
+ * \throw if an element in \a partOfThis is \b NOT in \a this.
+ */
+DataArrayInt *DataArrayInt::indicesOfSubPart(const DataArrayInt& partOfThis) const
+{
+ if(getNumberOfComponents()!=1 || partOfThis.getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : this and input array must be one component array !");
+ checkAllocated(); partOfThis.checkAllocated();
+ int thisNbTuples(getNumberOfTuples()),nbTuples(partOfThis.getNumberOfTuples());
+ const int *thisPt(begin()),*pt(partOfThis.begin());
+ MCAuto<DataArrayInt> ret(DataArrayInt::New());
+ ret->alloc(nbTuples,1);
+ int *retPt(ret->getPointer());
+ std::map<int,int> m;
+ for(int i=0;i<thisNbTuples;i++,thisPt++)
+ m[*thisPt]=i;
+ if(m.size()!=thisNbTuples)
+ throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : some elements appears more than once !");
+ for(int i=0;i<nbTuples;i++,retPt++,pt++)
+ {
+ std::map<int,int>::const_iterator it(m.find(*pt));
+ if(it!=m.end())
+ *retPt=(*it).second;
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::indicesOfSubPart : At pos #" << i << " of input array value is " << *pt << " not in this !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+ return ret.retn();
+}
+
void DataArrayInt::aggregate(const DataArrayInt *other)
{
if(!other)
MEDCOUPLING_EXPORT void switchOnTupleEqualTo(int val, std::vector<bool>& vec) const;
MEDCOUPLING_EXPORT void switchOnTupleNotEqualTo(int val, std::vector<bool>& vec) const;
MEDCOUPLING_EXPORT DataArrayInt *buildPermutationArr(const DataArrayInt& other) const;
+ MEDCOUPLING_EXPORT DataArrayInt *indicesOfSubPart(const DataArrayInt& partOfThis) const;
MEDCOUPLING_EXPORT DataArrayInt *sumPerTuple() const;
MEDCOUPLING_EXPORT void checkMonotonic(bool increasing) const;
MEDCOUPLING_EXPORT bool isMonotonic(bool increasing) const;
self.assertEqual(f.getMesh().getHiddenCppPointer(),m.getHiddenCppPointer())
self.assertTrue(f.getArray().isEqual(expected,1e-12))
pass
+
+ def testDAIIndicesOfSubPart(self):
+ a=DataArrayInt([9,10,0,6,4,11,3,8])
+ b=DataArrayInt([6,0,11,8])
+ c=a.indicesOfSubPart(b)
+ self.assertTrue(c.isEqual(DataArrayInt([3,2,5,7])))
+ #
+ d=DataArrayInt([9,10,0,6,4,11,0,8])
+ self.assertRaises(InterpKernelException,d.indicesOfSubPart,b) # 0 appears twice in the d array
+ f=DataArrayInt([6,0,11,8,12])
+ self.assertRaises(InterpKernelException,a.indicesOfSubPart,f) # 12 in f does not exist in a
+ pass
pass
%newobject MEDCoupling::DataArrayInt::BuildUnion;
%newobject MEDCoupling::DataArrayInt::BuildIntersection;
%newobject MEDCoupling::DataArrayInt::Range;
+%newobject MEDCoupling::DataArrayInt::indicesOfSubPart;
%newobject MEDCoupling::DataArrayInt::fromNoInterlace;
%newobject MEDCoupling::DataArrayInt::toNoInterlace;
%newobject MEDCoupling::DataArrayInt::buildComplement;
DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const throw(INTERP_KERNEL::Exception);
DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception);
DataArrayDouble *convertToDblArr() const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *indicesOfSubPart(const DataArrayInt& partOfThis) const throw(INTERP_KERNEL::Exception);
DataArrayInt *fromNoInterlace() const throw(INTERP_KERNEL::Exception);
DataArrayInt *toNoInterlace() const throw(INTERP_KERNEL::Exception);
DataArrayInt *selectByTupleIdSafeSlice(int bg, int end, int step) const throw(INTERP_KERNEL::Exception);