From: ageay Date: Wed, 8 Dec 2010 09:36:34 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: MEDPartitioner_first_compilable_version~44 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2bdea19467a0e4b43bd8950e569998802140161d;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index f06df5ee8..0a2710e78 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -2099,6 +2099,30 @@ DataArrayInt *DataArrayInt::buildIntersection(const DataArrayInt *other) const t 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()); + return ret; +} + int *DataArrayInt::checkAndPreparePermutation(const int *start, const int *end) { int sz=std::distance(start,end); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 29a9c01fa..2a3427540 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -267,6 +267,7 @@ namespace ParaMEDMEM 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. diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index e522b1462..830150dcd 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -164,6 +164,10 @@ namespace ParaMEDMEM 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 ); @@ -356,6 +360,10 @@ namespace ParaMEDMEM void testFieldMeld1(); void testMergeNodes2(); void testMergeField2(); + void testDAIBuildComplement1(); + void testDAIBuildUnion1(); + void testDAIBuildIntersection1(); + void testDAIDeltaShiftIndex1(); //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx index 883f79f8c..5937dbca4 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx @@ -3822,3 +3822,78 @@ void MEDCouplingBasicsTest::testMergeField2() 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(); +} + diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index ef04e2afe..4e138445e 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -113,6 +113,7 @@ using namespace INTERP_KERNEL; %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; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index a8b023fa3..7b0b63bb8 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -5338,6 +5338,64 @@ class MEDCouplingBasicsTest(unittest.TestCase): 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