declareAsNew();
}
+/*!
+ * This method works on array with number of component equal to one and allocated. If not an exception is thrown.
+ * 'offsets' should be monotic ascendently. If not, an exception will be thrown.
+ * This method retrives a newly created DataArrayInt instance with 1 component and this->getNumberOfTuples()-1 tuples.
+ * If 'this' contains [0,2,3] and 'offsets' [0,3,6,10,14,20] the returned array will contain [0,1,2,6,7,8,9,10,11,12,13]
+ */
+DataArrayInt *DataArrayInt::buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception)
+{
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : only single component allowed !");
+ offsets->checkAllocated();
+ if(offsets->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : input array should have only single component !");
+ int othNbTuples=offsets->getNumberOfTuples()-1;
+ int nbOfTuples=getNumberOfTuples();
+ int retNbOftuples=0;
+ const int *work=getConstPointer();
+ const int *offPtr=offsets->getConstPointer();
+ for(int i=0;i<nbOfTuples;i++)
+ {
+ int val=work[i];
+ if(val>=0 && val<othNbTuples)
+ {
+ int delta=offPtr[val+1]-offPtr[val];
+ if(delta>=0)
+ retNbOftuples+=delta;
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << val << " of offset array has a delta < 0 !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << i << " in this contains " << val;
+ oss << " whereas offsets array is of size " << othNbTuples+1 << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
+ ret->alloc(retNbOftuples,1);
+ int *retPtr=ret->getPointer();
+ for(int i=0;i<nbOfTuples;i++)
+ {
+ int val=work[i];
+ int start=offPtr[val];
+ int off=offPtr[val+1]-start;
+ for(int j=0;j<off;j++,retPtr++)
+ *retPtr=start+j;
+ }
+ ret->incrRef();
+ return ret;
+}
+
/*!
* This method returns all different values found in 'this'.
*/
MEDCOUPLING_EXPORT DataArrayInt *buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *deltaShiftIndex() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void computeOffsets() throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT DataArrayInt *buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT std::set<int> getDifferentValues() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo);
MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
CPPUNIT_TEST( testDAITransformWithIndArrR1 );
CPPUNIT_TEST( testDAISplitByValueRange1 );
CPPUNIT_TEST( testUMeshSplitProfilePerType1 );
+ CPPUNIT_TEST( testDAIBuildExplicitArrByRanges1 );
//MEDCouplingBasicsTestInterp.cxx
CPPUNIT_TEST( test2DInterpP0P0_1 );
CPPUNIT_TEST( test2DInterpP0P0PL_1 );
void testDAITransformWithIndArrR1();
void testDAISplitByValueRange1();
void testUMeshSplitProfilePerType1();
+ void testDAIBuildExplicitArrByRanges1();
//MEDCouplingBasicsTestInterp.cxx
void test2DInterpP0P0_1();
void test2DInterpP0P0PL_1();
//
m->decrRef();
}
+
+void MEDCouplingBasicsTest::testDAIBuildExplicitArrByRanges1()
+{
+ DataArrayInt *d=DataArrayInt::New();
+ d->alloc(3,1);
+ const int vals1[3]={0,2,3};
+ std::copy(vals1,vals1+3,d->getPointer());
+ DataArrayInt *e=DataArrayInt::New();
+ e->alloc(6,1);
+ const int vals2[6]={0,3,6,10,14,20};
+ std::copy(vals2,vals2+6,e->getPointer());
+ //
+ DataArrayInt *f=d->buildExplicitArrByRanges(e);
+ CPPUNIT_ASSERT_EQUAL(11,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
+ const int expected1[11]={0,1,2,6,7,8,9,10,11,12,13};
+ for(int i=0;i<11;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],f->getIJ(i,0));
+ //
+ f->decrRef();
+ e->decrRef();
+ d->decrRef();
+}