]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Wed, 8 Dec 2010 09:36:34 +0000 (09:36 +0000)
committerageay <ageay>
Wed, 8 Dec 2010 09:36:34 +0000 (09:36 +0000)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx
src/MEDCoupling_Swig/MEDCoupling.i
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index f06df5ee8c874414483501d8e25e2f541d74c276..0a2710e785e46a99d1d40f5679c56aa3e370cc09 100644 (file)
@@ -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<int>());
+  return ret;
+}
+
 int *DataArrayInt::checkAndPreparePermutation(const int *start, const int *end)
 {
   int sz=std::distance(start,end);
index 29a9c01fa075001b068eda837c081ee3beae15ac..2a3427540273b0170700903a584dcb1caadeecee 100644 (file)
@@ -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.
index e522b1462668204245822f9f1bfcd664e10a1e16..830150dcd44350c604d2e7d71a24fc9e3a56ba30 100644 (file)
@@ -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();
index 883f79f8c8957dfe7527d88d191fb260ae45fa79..5937dbca4f3048440a874d160bb7ede7d6256e79 100644 (file)
@@ -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();
+}
+
index ef04e2afefba0f2537bb8ed14c9a31f0f031e0c3..4e138445e16251d10d5cb9e02f98be0fcdecbbb7 100644 (file)
@@ -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;
index a8b023fa30c0b7a11fc12a1633d9853d3d269bb3..7b0b63bb8370d3ea30e4dac53e4f46084559aa72 100644 (file)
@@ -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