]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Fri, 26 Nov 2010 14:47:28 +0000 (14:47 +0000)
committerageay <ageay>
Fri, 26 Nov 2010 14:47:28 +0000 (14:47 +0000)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/libMEDCoupling_Swig.i

index 61483953fc14e96ac3033f26a0326ee378ced96b..463012e9dc2263e97731b5b4db6bb72e1ba8764c 100644 (file)
@@ -1539,7 +1539,7 @@ void DataArrayInt::setArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet)
 DataArrayInt *DataArrayInt::getIdsEqual(int val) const throw(INTERP_KERNEL::Exception)
 {
   if(getNumberOfComponents()!=1)
-    throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqual : the default array must have only one component !");
+    throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqual : the array must have only one component !");
   const int *cptr=getConstPointer();
   std::vector<int> res;
   int nbOfTuples=getNumberOfTuples();
@@ -1552,6 +1552,23 @@ DataArrayInt *DataArrayInt::getIdsEqual(int val) const throw(INTERP_KERNEL::Exce
   return ret;
 }
 
+DataArrayInt *DataArrayInt::getIdsEqualList(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
+{
+  if(getNumberOfComponents()!=1)
+    throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqualList : the array must have only one component !");
+  std::set<int> vals2(vals.begin(),vals.end());
+  const int *cptr=getConstPointer();
+  std::vector<int> res;
+  int nbOfTuples=getNumberOfTuples();
+  for(int i=0;i<nbOfTuples;i++,cptr++)
+    if(vals2.find(*cptr)!=vals2.end())
+      res.push_back(i);
+  DataArrayInt *ret=DataArrayInt::New();
+  ret->alloc(res.size(),1);
+  std::copy(res.begin(),res.end(),ret->getPointer());
+  return ret;
+}
+
 DataArrayInt *DataArrayInt::aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2)
 {
   int nbOfComp=a1->getNumberOfComponents();
index eadec983a870a0a84ac3dbc6ebece91f62dcaa22..c6cd1410b1b9de058b103e37620bccd2d76d6321 100644 (file)
@@ -234,6 +234,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT static void setArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet);
     MEDCOUPLING_EXPORT const int *getConstPointer() const { return _mem.getConstPointer(); }
     MEDCOUPLING_EXPORT DataArrayInt *getIdsEqual(int val) const throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT DataArrayInt *getIdsEqualList(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT static DataArrayInt *aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2);
     MEDCOUPLING_EXPORT static DataArrayInt *makePartition(const std::vector<DataArrayInt *>& groups, int newNb, std::vector< std::vector<int> >& fidsOfGroups);
     MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo);
index e3761c56d5546ff88d5019d9cfff0ad20a944a38..b6238f08402a875a4f1301c035720ff71746f972 100644 (file)
@@ -144,6 +144,7 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( testKeepSetSelectedComponent1 );
     CPPUNIT_TEST( testKeepSetSelectedComponent2 );
     CPPUNIT_TEST( testDAIGetIdsEqual1 );
+    CPPUNIT_TEST( testDAIGetIdsEqualList1 );
     //MEDCouplingBasicsTestInterp.cxx
     CPPUNIT_TEST( test2DInterpP0P0_1 );
     CPPUNIT_TEST( test2DInterpP0P0PL_1 );
@@ -316,6 +317,7 @@ namespace ParaMEDMEM
     void testKeepSetSelectedComponent1();
     void testKeepSetSelectedComponent2();
     void testDAIGetIdsEqual1();
+    void testDAIGetIdsEqualList1();
     //MEDCouplingBasicsTestInterp.cxx
     void test2DInterpP0P0_1();
     void test2DInterpP0P0PL_1();
index fcbdee6ba195e5bbed00253e5b80dd2cf7bebad2..e706ac14de70228bde836f028616698582484e05 100644 (file)
@@ -3020,3 +3020,20 @@ void MEDCouplingBasicsTest::testDAIGetIdsEqual1()
   da2->decrRef();
   da->decrRef();
 }
+
+void MEDCouplingBasicsTest::testDAIGetIdsEqualList1()
+{
+  const int tab1[7]={5,-2,-4,-2,3,2,-2};
+  DataArrayInt *da=DataArrayInt::New();
+  da->alloc(7,1);
+  std::copy(tab1,tab1+7,da->getPointer());
+  const int tab2[3]={3,-2,0};
+  std::vector<int> tab2V(tab2,tab2+3);
+  DataArrayInt *da2=da->getIdsEqualList(tab2V);
+  CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
+  const int expected1[4]={1,3,4,6};
+  CPPUNIT_ASSERT(std::equal(expected1,expected1+4,da2->getConstPointer()));
+  da2->decrRef();
+  da->decrRef();
+}
index ab7b459f0b169f422cbfd492dad6480e064d9b14..9516227c19abdf15f5726d04a34495c3510cb841 100644 (file)
@@ -4689,6 +4689,17 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         expected1=[1,3,6];
         self.assertEqual(expected1,da2.getValues());
         pass
+
+    def testDAIGetIdsEqualList1(self):
+        tab1=[5,-2,-4,-2,3,2,-2];
+        da=DataArrayInt.New();
+        da.setValues(tab1,7,1);
+        da2=da.getIdsEqualList([3,-2,0]);
+        self.assertEqual(4,da2.getNumberOfTuples());
+        self.assertEqual(1,da2.getNumberOfComponents());
+        expected1=[1,3,4,6];
+        self.assertEqual(expected1,da2.getValues());
+        pass
     
     def setUp(self):
         pass
index 447790b2e27f1f10bda9da353ee618dad29d0426..4d979d2cb2300ed89f022822161df3b00aebf9a2 100644 (file)
@@ -106,6 +106,7 @@ using namespace INTERP_KERNEL;
 %newobject ParaMEDMEM::DataArrayInt::invertArrayO2N2N2O;
 %newobject ParaMEDMEM::DataArrayInt::invertArrayN2O2O2N;
 %newobject ParaMEDMEM::DataArrayInt::getIdsEqual;
+%newobject ParaMEDMEM::DataArrayInt::getIdsEqualList;
 %newobject ParaMEDMEM::DataArrayInt::aggregate;
 %newobject ParaMEDMEM::DataArrayDouble::aggregate;
 %newobject ParaMEDMEM::DataArrayDouble::dot;