]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Implementation of subtuple assignation in python.
authorageay <ageay>
Tue, 28 Feb 2012 07:44:44 +0000 (07:44 +0000)
committerageay <ageay>
Tue, 28 Feb 2012 07:44:44 +0000 (07:44 +0000)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling_Swig/MEDCoupling.i
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index 393c5b4a3679e50152478a4431c281172a106985..55c685872211c858528f6b335ee75843fd036d2d 100644 (file)
@@ -1131,17 +1131,42 @@ void DataArrayDouble::setPartOfValues2(const DataArrayDouble *a, const int *bgTu
     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
   int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
   int newNbOfComp=(int)std::distance(bgComp,endComp);
-  a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
-  if(strictCompoCompare)
-    a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+  bool assignTech=true;
+  if(a->getNbOfElems()==newNbOfTuples*newNbOfComp)
+    {
+      if(strictCompoCompare)
+        a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+    }
+  else
+    {
+      a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
+      assignTech=false;
+    }
   double *pt=getPointer();
   const double *srcPt=a->getConstPointer();
-  for(const int *w=bgTuples;w!=endTuples;w++)
-    for(const int *z=bgComp;z!=endComp;z++,srcPt++)
-      {
-        DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
-        pt[(*w)*nbComp+(*z)]=*srcPt;
-      }
+  if(assignTech)
+    {    
+      for(const int *w=bgTuples;w!=endTuples;w++)
+        {
+          DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
+          for(const int *z=bgComp;z!=endComp;z++,srcPt++)
+            {    
+              pt[(*w)*nbComp+(*z)]=*srcPt;
+            }
+        }
+    }
+  else
+    {
+      for(const int *w=bgTuples;w!=endTuples;w++)
+        {
+          const double *srcPt2=srcPt;
+          DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
+          for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
+            {    
+              pt[(*w)*nbComp+(*z)]=*srcPt2;
+            }
+        }
+    }
 }
 
 /*!
@@ -1178,17 +1203,40 @@ void DataArrayDouble::setPartOfValues3(const DataArrayDouble *a, const int *bgTu
   DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
   DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
   int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
-  a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
-  if(strictCompoCompare)
-    a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+  bool assignTech=true;
+  if(a->getNbOfElems()==newNbOfTuples*newNbOfComp)
+    {
+      if(strictCompoCompare)
+        a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+    }
+  else
+    {
+      a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
+      assignTech=false;
+    }
   double *pt=getPointer()+bgComp;
   const double *srcPt=a->getConstPointer();
-  for(const int *w=bgTuples;w!=endTuples;w++)
-    for(int j=0;j<newNbOfComp;j++,srcPt++)
-      {
-        DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
-        pt[(*w)*nbComp+j*stepComp]=*srcPt;
-      }
+  if(assignTech)
+    {
+      for(const int *w=bgTuples;w!=endTuples;w++)
+        for(int j=0;j<newNbOfComp;j++,srcPt++)
+          {
+            DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
+            pt[(*w)*nbComp+j*stepComp]=*srcPt;
+          }
+    }
+  else
+    {
+      for(const int *w=bgTuples;w!=endTuples;w++)
+        {
+          const double *srcPt2=srcPt;
+          for(int j=0;j<newNbOfComp;j++,srcPt2++)
+            {
+              DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
+              pt[(*w)*nbComp+j*stepComp]=*srcPt2;
+            }
+        }
+    }
 }
 
 /*!
@@ -3582,17 +3630,42 @@ void DataArrayInt::setPartOfValues2(const DataArrayInt *a, const int *bgTuples,
     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
   int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
   int newNbOfComp=(int)std::distance(bgComp,endComp);
-  a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
-  if(strictCompoCompare)
-    a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+  bool assignTech=true;
+  if(a->getNbOfElems()==newNbOfTuples*newNbOfComp)
+    {
+      if(strictCompoCompare)
+        a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+    }
+  else
+    {
+      a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
+      assignTech=false;
+    }
   int *pt=getPointer();
   const int *srcPt=a->getConstPointer();
-  for(const int *w=bgTuples;w!=endTuples;w++)
-    for(const int *z=bgComp;z!=endComp;z++,srcPt++)
-      {
-        DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
-        pt[(*w)*nbComp+(*z)]=*srcPt;
-      }
+  if(assignTech)
+    {    
+      for(const int *w=bgTuples;w!=endTuples;w++)
+        {
+          DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
+          for(const int *z=bgComp;z!=endComp;z++,srcPt++)
+            {    
+              pt[(*w)*nbComp+(*z)]=*srcPt;
+            }
+        }
+    }
+  else
+    {
+      for(const int *w=bgTuples;w!=endTuples;w++)
+        {
+          const int *srcPt2=srcPt;
+          DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
+          for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
+            {    
+              pt[(*w)*nbComp+(*z)]=*srcPt2;
+            }
+        }
+    }
 }
 
 /*!
@@ -3629,17 +3702,40 @@ void DataArrayInt::setPartOfValues3(const DataArrayInt *a, const int *bgTuples,
   DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
   DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
   int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
-  a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
-  if(strictCompoCompare)
-    a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+  bool assignTech=true;
+  if(a->getNbOfElems()==newNbOfTuples*newNbOfComp)
+    {
+      if(strictCompoCompare)
+        a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+    }
+  else
+    {
+      a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
+      assignTech=false;
+    }
   int *pt=getPointer()+bgComp;
   const int *srcPt=a->getConstPointer();
-  for(const int *w=bgTuples;w!=endTuples;w++)
-    for(int j=0;j<newNbOfComp;j++,srcPt++)
-      {
-        DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
-        pt[(*w)*nbComp+j*stepComp]=*srcPt;
-      }
+  if(assignTech)
+    {
+      for(const int *w=bgTuples;w!=endTuples;w++)
+        for(int j=0;j<newNbOfComp;j++,srcPt++)
+          {
+            DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
+            pt[(*w)*nbComp+j*stepComp]=*srcPt;
+          }
+    }
+  else
+    {
+      for(const int *w=bgTuples;w!=endTuples;w++)
+        {
+          const int *srcPt2=srcPt;
+          for(int j=0;j<newNbOfComp;j++,srcPt2++)
+            {
+              DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
+              pt[(*w)*nbComp+j*stepComp]=*srcPt2;
+            }
+        }
+    }
 }
 
 /*!
index 74c752b46ed9f2dd634cf51fff8aa3eeb1f22206..366fe721c0781fedc433b61c6f5a1b9d40f275b8 100644 (file)
@@ -2290,7 +2290,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayDouble::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
                return self;
              case 3:
@@ -2330,7 +2330,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayDouble::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
                return self;
              case 3:
@@ -2370,7 +2370,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayDouble::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
                return self;
              case 3:
@@ -2410,7 +2410,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayDouble::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
                return self;
              case 3:
@@ -2430,7 +2430,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayDouble::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
                return self;
              case 3:
@@ -2450,7 +2450,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayDouble::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
                return self;
              case 3:
@@ -2479,7 +2479,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayDouble::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues2(tmp,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size(),false);
                return self;
              case 3:
@@ -2499,7 +2499,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayDouble::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
                return self;
              case 3:
@@ -2539,7 +2539,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayDouble::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
                return self;
              case 3:
@@ -2579,7 +2579,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayDouble::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
                return self;
              case 3:
@@ -3683,7 +3683,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayInt::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
                return self;
              case 3:
@@ -3723,7 +3723,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayInt::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
                return self;
              case 3:
@@ -3763,7 +3763,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayInt::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
                return self;
              case 3:
@@ -3803,7 +3803,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayInt::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
                return self;
              case 3:
@@ -3823,7 +3823,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayInt::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
                return self;
              case 3:
@@ -3843,7 +3843,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayInt::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
                return self;
              case 3:
@@ -3872,7 +3872,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayInt::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues2(tmp,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size(),false);
                return self;
              case 3:
@@ -3892,7 +3892,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayInt::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
                return self;
              case 3:
@@ -3932,7 +3932,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayInt::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
                return self;
              case 3:
@@ -3972,7 +3972,7 @@ namespace ParaMEDMEM
                return self;
              case 2:
                tmp=DataArrayInt::New();
-               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
                self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
                return self;
              case 3:
index 539c57775321b970f6eb990a5f54d060ba602e84..5f0fd796ac76f524e755cf8de2cc209c5af37e05 100644 (file)
@@ -6419,6 +6419,18 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         st2=da.getHiddenCppPointer()
         self.assertEqual(st1,st2)
         self.assertEqual([10.0, 12.5, 15.0, 14.0, 16.0, 18.0, 15.0, 16.5, 18.0, 13.0, 14.0, 15.0],da.getValues())
+        #
+        da.alloc(30,1)
+        da.iota(7.)
+        da.rearrange(3)
+        ids=DataArrayInt.New()
+        ids.setValues([3,4,7],3,1)
+        da[ids,:]=[5.,8.,9.]
+        self.assertEqual([7.,8.,9.,10.,11.,12.,13.,14.,15.,5.,8.,9.,5.,8.,9.,22.,23.,24.,25.,26.,27.,5.,8.,9.,31.,32.,33.,34.,35.,36.0],da.getValues())
+        #
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(3)
+        da[ids,[1,2]]=[5,8]
+        self.assertEqual([7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,5.,8.,19.,5.,8.,22.,23.,24.,25.,26.,27.,28.,5.,8.,31.,32.,33.,34.,35.,36.],da.getValues())
         pass
 
     def testSwigDAIOp(self):
@@ -6487,6 +6499,18 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         st2=da.getHiddenCppPointer()
         self.assertEqual(st1,st2)
         self.assertEqual([4,4,3,0,4,4,3,3,0,0,2,2],da.getValues())
+        #
+        da.alloc(30,1)
+        da.iota(7)
+        da.rearrange(3)
+        ids=DataArrayInt.New()
+        ids.setValues([3,4,7],3,1)
+        da[ids,:]=[5,8,9]
+        self.assertEqual([7,8,9,10,11,12,13,14,15,5,8,9,5,8,9,22,23,24,25,26,27,5,8,9,31,32,33,34,35,36],da.getValues())
+        #
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(3)
+        da[ids,[1,2]]=[5,8]
+        self.assertEqual([7,8,9,10,11,12,13,14,15,16,5,8,19,5,8,22,23,24,25,26,27,28,5,8,31,32,33,34,35,36],da.getValues())
         pass
 
     def testSwigDAIOp2(self):