]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Fri, 26 Nov 2010 14:30:51 +0000 (14:30 +0000)
committerageay <ageay>
Fri, 26 Nov 2010 14:30:51 +0000 (14:30 +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 5365cb97c1b0d61a762e6551b8d4add3a9cfa499..61483953fc14e96ac3033f26a0326ee378ced96b 100644 (file)
@@ -1536,6 +1536,22 @@ 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 !");
+  const int *cptr=getConstPointer();
+  std::vector<int> res;
+  int nbOfTuples=getNumberOfTuples();
+  for(int i=0;i<nbOfTuples;i++,cptr++)
+    if(*cptr==val)
+      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 0f5d600d9de142b7fa7b61bea548bf5afe22d6c7..eadec983a870a0a84ac3dbc6ebece91f62dcaa22 100644 (file)
@@ -233,6 +233,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT int *getPointer() const { return _mem.getPointer(); }
     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 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 569560584be281df96e24bb42f92de136ea06917..e3761c56d5546ff88d5019d9cfff0ad20a944a38 100644 (file)
@@ -143,6 +143,7 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( testDataArrayIntInvertO2NNO21 );
     CPPUNIT_TEST( testKeepSetSelectedComponent1 );
     CPPUNIT_TEST( testKeepSetSelectedComponent2 );
+    CPPUNIT_TEST( testDAIGetIdsEqual1 );
     //MEDCouplingBasicsTestInterp.cxx
     CPPUNIT_TEST( test2DInterpP0P0_1 );
     CPPUNIT_TEST( test2DInterpP0P0PL_1 );
@@ -314,6 +315,7 @@ namespace ParaMEDMEM
     void testDataArrayIntInvertO2NNO21();
     void testKeepSetSelectedComponent1();
     void testKeepSetSelectedComponent2();
+    void testDAIGetIdsEqual1();
     //MEDCouplingBasicsTestInterp.cxx
     void test2DInterpP0P0_1();
     void test2DInterpP0P0PL_1();
index 0c36bdbad96163ac3618e6a8d92c71934d5a37cd..fcbdee6ba195e5bbed00253e5b80dd2cf7bebad2 100644 (file)
@@ -3005,3 +3005,18 @@ void MEDCouplingBasicsTest::testKeepSetSelectedComponent2()
   a1->decrRef();
   m1->decrRef();
 }
+
+void MEDCouplingBasicsTest::testDAIGetIdsEqual1()
+{
+  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());
+  DataArrayInt *da2=da->getIdsEqual(-2);
+  CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
+  const int expected1[3]={1,3,6};
+  CPPUNIT_ASSERT(std::equal(expected1,expected1+3,da2->getConstPointer()));
+  da2->decrRef();
+  da->decrRef();
+}
index a8e328c08d23e39c6be0583c955f109a6cf72a54..8baec9b80a97493bb47aac04edb116d0a81d6084 100644 (file)
@@ -4678,6 +4678,17 @@ class MEDCouplingBasicsTest(unittest.TestCase):
             pass
         #
         pass
+
+    def testDAIGetIdsEqual1(self):
+        tab1=[5,-2,-4,-2,3,2,-2];
+        da=DataArrayInt.New();
+        da.setValues(tab1,7,1);
+        da2=da.getIdsEqual(-2);
+        self.assertEqual(3,da2.getNumberOfTuples());
+        self.assertEqual(1,da2.getNumberOfComponents());
+        expected1=[1,3,6];
+        self.assertEqual(expected1,da2.getValues());
+        pass
     
     def setUp(self):
         pass
index d6b35f44750b7f27179c2b58fcab0f300337dc12..447790b2e27f1f10bda9da353ee618dad29d0426 100644 (file)
@@ -105,6 +105,8 @@ using namespace INTERP_KERNEL;
 %newobject ParaMEDMEM::DataArrayInt::renumberAndReduce;
 %newobject ParaMEDMEM::DataArrayInt::invertArrayO2N2N2O;
 %newobject ParaMEDMEM::DataArrayInt::invertArrayN2O2O2N;
+%newobject ParaMEDMEM::DataArrayInt::getIdsEqual;
+%newobject ParaMEDMEM::DataArrayInt::aggregate;
 %newobject ParaMEDMEM::DataArrayDouble::aggregate;
 %newobject ParaMEDMEM::DataArrayDouble::dot;
 %newobject ParaMEDMEM::DataArrayDouble::crossProduct;