return ret;
}
+/*!
+ * This method could be usefull for returned DataArrayInt marked as index. Some methods that generate such DataArrayInt instances:
+ * - ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity
+ * - ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivityIndex
+ * This method makes the assumption that 'this' is allocated and has exactly one component and 2 or more tuples. If not an exception is thrown.
+ * This method retrives a newly created DataArrayInt instance with 1 component and this->getNumberOfTuples()-1 tuples.
+ * If this contains [1,3,6,7,7,9,15] -> returned array will contain [2,3,1,0,2,6].
+ */
+DataArrayInt *DataArrayInt::deltaShiftIndex() const throw(INTERP_KERNEL::Exception)
+{
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : only single component allowed !");
+ int nbOfTuples=getNumberOfTuples();
+ if(nbOfTuples<2)
+ throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : 1 tuple at least must be present in 'this' !");
+ const int *ptr=getPointer();
+ DataArrayInt *ret=DataArrayInt::New();
+ ret->alloc(nbOfTuples-1,1);
+ int *out=ret->getPointer();
+ std::transform(ptr+1,ptr+nbOfTuples,ptr,out,std::minus<int>());
+ return ret;
+}
+
int *DataArrayInt::checkAndPreparePermutation(const int *start, const int *end)
{
int sz=std::distance(start,end);
MEDCOUPLING_EXPORT DataArrayInt *buildComplement(int nbOfElement) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT DataArrayInt *deltaShiftIndex() 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); }
//! nothing to do here because this class does not aggregate any TimeLabel instance.
CPPUNIT_TEST( testFieldMeld1 );
CPPUNIT_TEST( testMergeNodes2 );
CPPUNIT_TEST( testMergeField2 );
+ CPPUNIT_TEST( testDAIBuildComplement1 );
+ CPPUNIT_TEST( testDAIBuildUnion1 );
+ CPPUNIT_TEST( testDAIBuildIntersection1 );
+ CPPUNIT_TEST( testDAIDeltaShiftIndex1 );
//MEDCouplingBasicsTestInterp.cxx
CPPUNIT_TEST( test2DInterpP0P0_1 );
CPPUNIT_TEST( test2DInterpP0P0PL_1 );
void testFieldMeld1();
void testMergeNodes2();
void testMergeField2();
+ void testDAIBuildComplement1();
+ void testDAIBuildUnion1();
+ void testDAIBuildIntersection1();
+ void testDAIDeltaShiftIndex1();
//MEDCouplingBasicsTestInterp.cxx
void test2DInterpP0P0_1();
void test2DInterpP0P0PL_1();
f3->decrRef();
m->decrRef();
}
+
+void MEDCouplingBasicsTest::testDAIBuildComplement1()
+{
+ DataArrayInt *a=DataArrayInt::New();
+ const int tab[4]={3,1,7,8};
+ a->alloc(4,1);
+ std::copy(tab,tab+4,a->getPointer());
+ DataArrayInt *b=a->buildComplement(12);
+ CPPUNIT_ASSERT_EQUAL(8,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
+ const int expected1[8]={0,2,4,5,6,9,10,11};
+ for(int i=0;i<8;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
+ b->decrRef();
+ a->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIBuildUnion1()
+{
+ DataArrayInt *a=DataArrayInt::New();
+ const int tab1[4]={3,1,7,8};
+ a->alloc(4,1);
+ std::copy(tab1,tab1+4,a->getPointer());
+ DataArrayInt *c=DataArrayInt::New();
+ const int tab2[5]={5,3,0,18,8};
+ c->alloc(5,1);
+ std::copy(tab2,tab2+5,c->getPointer());
+ DataArrayInt *b=a->buildUnion(c);
+ CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
+ const int expected1[7]={0,1,3,5,7,8,18};
+ for(int i=0;i<7;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
+ c->decrRef();
+ b->decrRef();
+ a->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIBuildIntersection1()
+{
+ DataArrayInt *a=DataArrayInt::New();
+ const int tab1[4]={3,1,7,8};
+ a->alloc(4,1);
+ std::copy(tab1,tab1+4,a->getPointer());
+ DataArrayInt *c=DataArrayInt::New();
+ const int tab2[5]={5,3,0,18,8};
+ c->alloc(5,1);
+ std::copy(tab2,tab2+5,c->getPointer());
+ DataArrayInt *b=a->buildIntersection(c);
+ CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
+ const int expected1[2]={3,8};
+ for(int i=0;i<2;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
+ c->decrRef();
+ b->decrRef();
+ a->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDAIDeltaShiftIndex1()
+{
+ DataArrayInt *a=DataArrayInt::New();
+ const int tab[7]={1,3,6,7,7,9,15};
+ a->alloc(7,1);
+ std::copy(tab,tab+7,a->getPointer());
+ DataArrayInt *b=a->deltaShiftIndex();
+ CPPUNIT_ASSERT_EQUAL(6,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
+ const int expected1[6]={2,3,1,0,2,6};
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
+ b->decrRef();
+ a->decrRef();
+}
+
%newobject ParaMEDMEM::DataArrayInt::buildComplement;
%newobject ParaMEDMEM::DataArrayInt::buildUnion;
%newobject ParaMEDMEM::DataArrayInt::buildIntersection;
+%newobject ParaMEDMEM::DataArrayInt::deltaShiftIndex;
%newobject ParaMEDMEM::DataArrayDouble::New;
%newobject ParaMEDMEM::DataArrayDouble::convertToIntArr;
%newobject ParaMEDMEM::DataArrayDouble::deepCpy;
pass
#
pass
+
+ def testDAIBuildComplement1(self):
+ a=DataArrayInt.New();
+ tab=[3,1,7,8]
+ a.setValues(tab,4,1);
+ b=a.buildComplement(12);
+ self.assertEqual(8,b.getNumberOfTuples());
+ self.assertEqual(1,b.getNumberOfComponents());
+ expected1=[0,2,4,5,6,9,10,11]
+ for i in xrange(8):
+ self.assertEqual(expected1[i],b.getIJ(0,i));
+ pass
+ pass
+
+ def testDAIBuildUnion1(self):
+ a=DataArrayInt.New();
+ tab1=[3,1,7,8]
+ a.setValues(tab1,4,1);
+ c=DataArrayInt.New();
+ tab2=[5,3,0,18,8]
+ c.setValues(tab2,5,1);
+ b=a.buildUnion(c);
+ self.assertEqual(7,b.getNumberOfTuples());
+ self.assertEqual(1,b.getNumberOfComponents());
+ expected1=[0,1,3,5,7,8,18]
+ for i in xrange(7):
+ self.assertEqual(expected1[i],b.getIJ(0,i));
+ pass
+ pass
+
+ def testDAIBuildIntersection1(self):
+ a=DataArrayInt.New();
+ tab1=[3,1,7,8]
+ a.setValues(tab1,4,1);
+ c=DataArrayInt.New();
+ tab2=[5,3,0,18,8]
+ c.setValues(tab2,5,1);
+ b=a.buildIntersection(c);
+ self.assertEqual(2,b.getNumberOfTuples());
+ self.assertEqual(1,b.getNumberOfComponents());
+ expected1=[3,8]
+ for i in xrange(2):
+ self.assertEqual(expected1[i],b.getIJ(0,i));
+ pass
+ pass
+
+ def testDAIDeltaShiftIndex1(self):
+ a=DataArrayInt.New();
+ tab=[1,3,6,7,7,9,15]
+ a.setValues(tab,7,1);
+ b=a.deltaShiftIndex();
+ self.assertEqual(6,b.getNumberOfTuples());
+ self.assertEqual(1,b.getNumberOfComponents());
+ expected1=[2,3,1,0,2,6]
+ for i in xrange(6):
+ self.assertEqual(expected1[i],b.getIJ(0,i));
+ pass
+ pass
def setUp(self):
pass