]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
__getitem__ & __setitem__ on DataArray.
authorageay <ageay>
Thu, 7 Apr 2011 15:12:42 +0000 (15:12 +0000)
committerageay <ageay>
Thu, 7 Apr 2011 15:12:42 +0000 (15:12 +0000)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling_Swig/MEDCoupling.i
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/MEDCouplingTypemaps.i

index 75c857862730e0957f32ffde38a98f3fd36b7bff..bbf6bca676c6c156522224ded39a04b715ed34a9 100644 (file)
@@ -185,6 +185,62 @@ void DataArray::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL:
     }
 }
 
+void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception)
+{
+  if(getNumberOfTuples()!=nbOfTuples)
+    {
+      std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " <<  nbOfTuples << " having " << getNumberOfTuples() << " !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  if(getNumberOfComponents()!=nbOfCompo)
+    {
+      std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << nbOfCompo << " having " << getNumberOfComponents() << " !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+}
+
+void DataArray::checkNbOfElems(int nbOfElems, const char *msg) const throw(INTERP_KERNEL::Exception)
+{
+  if(getNbOfElems()!=nbOfElems)
+    {
+      std::ostringstream oss; oss << msg << " : mismatch number of elems : Expected " << nbOfElems << " having " << getNbOfElems() << " !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+}
+
+void DataArray::CheckValueInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception)
+{
+  if(value<0 || value>=ref)
+    {
+      std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg  << " ! Expected in range [0," << ref << ") having " << value << " !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+}
+
+void DataArray::CheckClosingParInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception)
+{
+  if(value<0 || value>ref)
+    {
+      std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg  << " ! Expected a range in [0," << ref << ") having closing open parenthesis " << value << " !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+}
+
+int DataArray::GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception)
+{
+  if(end<begin)
+    {
+      std::ostringstream oss; oss << msg << " : end before begin !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  if(step<=0)
+    {
+      std::ostringstream oss; oss << msg << " : invalid step should be > 0 !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  return (end-1-begin)/step+1;
+}
+
 DataArrayDouble *DataArrayDouble::New()
 {
   return new DataArrayDouble;
@@ -542,7 +598,7 @@ DataArrayDouble *DataArrayDouble::selectByTupleId2(int bg, int end, int step) co
     throw INTERP_KERNEL::Exception("DataArrayDouble::selectByTupleId2 : invalid step should > 0 !");
   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
   int nbComp=getNumberOfComponents();
-  int newNbOfTuples=(end-bg)/step;
+  int newNbOfTuples=(end-1-bg)/step+1;
   ret->alloc(newNbOfTuples,nbComp);
   double *pt=ret->getPointer();
   const double *srcPt=getConstPointer()+bg*nbComp;
@@ -698,6 +754,153 @@ void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std:
       nc[nbOfCompo*i+compoIds[j]]=*ac;
 }
 
+/*!
+ * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
+ * 'strictCompoCompare' specifies if DataArray 'a' should have exactly same number of components and tuples than 'this' (true) or not (false). By default set to true with maximal test.
+ */
+void DataArrayDouble::setPartOfValues1(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
+{
+  const char msg[]="DataArrayDouble::setPartOfValues1";
+  checkAllocated();
+  a->checkAllocated();
+  int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
+  int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
+  int nbComp=getNumberOfComponents();
+  int nbOfTuples=getNumberOfTuples();
+  DataArray::CheckValueInRange(nbOfTuples,bgTuples,"invalid begin tuple value");
+  DataArray::CheckClosingParInRange(nbOfTuples,endTuples,"invalid end tuple value");
+  DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
+  DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
+  a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
+  if(strictCompoCompare)
+    a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+  double *pt=getPointer()+bgTuples*nbComp+bgComp;
+  const double *srcPt=a->getConstPointer();
+  for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
+    for(int j=0;j<newNbOfComp;j++,srcPt++)
+      pt[j*stepComp]=*srcPt;
+}
+
+/*!
+ * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
+ */
+void DataArrayDouble::setPartOfValuesSimple1(double a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
+{
+  const char msg[]="DataArrayDouble::setPartOfValuesSimple1";
+  checkAllocated();
+  int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
+  int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
+  int nbComp=getNumberOfComponents();
+  int nbOfTuples=getNumberOfTuples();
+  DataArray::CheckValueInRange(nbOfTuples,bgTuples,"invalid begin tuple value");
+  DataArray::CheckClosingParInRange(nbOfTuples,endTuples,"invalid end tuple value");
+  DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
+  DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
+  double *pt=getPointer()+bgTuples*nbComp+bgComp;
+  for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
+    for(int j=0;j<newNbOfComp;j++)
+      pt[j*stepComp]=a;
+}
+
+/*!
+ * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
+ * 'strictCompoCompare' specifies if DataArray 'a' should have exactly same number of components and tuples than 'this' (true) or not (false). By default set to true with maximal test.
+ */
+void DataArrayDouble::setPartOfValues2(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
+{
+  const char msg[]="DataArrayDouble::setPartOfValues2";
+  checkAllocated();
+  a->checkAllocated();
+  int nbComp=getNumberOfComponents();
+  int nbOfTuples=getNumberOfTuples();
+  for(const int *z=bgComp;z!=endComp;z++)
+    DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
+  int newNbOfTuples=std::distance(bgTuples,endTuples);
+  int newNbOfComp=std::distance(bgComp,endComp);
+  a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
+  if(strictCompoCompare)
+    a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+  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;
+      }
+}
+
+/*!
+ * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
+ */
+void DataArrayDouble::setPartOfValuesSimple2(double a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
+{
+  checkAllocated();
+  int nbComp=getNumberOfComponents();
+  int nbOfTuples=getNumberOfTuples();
+  for(const int *z=bgComp;z!=endComp;z++)
+    DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
+  int newNbOfTuples=std::distance(bgTuples,endTuples);
+  int newNbOfComp=std::distance(bgComp,endComp);
+  double *pt=getPointer();
+  for(const int *w=bgTuples;w!=endTuples;w++)
+    for(const int *z=bgComp;z!=endComp;z++)
+      {
+        DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
+        pt[(*w)*nbComp+(*z)]=a;
+      }
+}
+
+/*!
+ * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
+ * 'strictCompoCompare' specifies if DataArray 'a' should have exactly same number of components and tuples than 'this' (true) or not (false). By default set to true with maximal test.
+ */
+void DataArrayDouble::setPartOfValues3(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
+{
+  const char msg[]="DataArrayDouble::setPartOfValues3";
+  checkAllocated();
+  a->checkAllocated();
+  int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
+  int nbComp=getNumberOfComponents();
+  int nbOfTuples=getNumberOfTuples();
+  DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
+  DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
+  int newNbOfTuples=std::distance(bgTuples,endTuples);
+  a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
+  if(strictCompoCompare)
+    a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+  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;
+      }
+}
+
+/*!
+ * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
+ */
+void DataArrayDouble::setPartOfValuesSimple3(double a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
+{
+  const char msg[]="DataArrayDouble::setPartOfValuesSimple3";
+  checkAllocated();
+  int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
+  int nbComp=getNumberOfComponents();
+  int nbOfTuples=getNumberOfTuples();
+  DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
+  DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
+  int newNbOfTuples=std::distance(bgTuples,endTuples);
+  double *pt=getPointer()+bgComp;
+  for(const int *w=bgTuples;w!=endTuples;w++)
+    for(int j=0;j<newNbOfComp;j++)
+      {
+        DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
+        pt[(*w)*nbComp+j*stepComp]=a;
+      }
+}
+
 void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet)
 {
   if(newArray!=arrayToSet)
@@ -2126,7 +2329,7 @@ DataArrayInt *DataArrayInt::selectByTupleId2(int bg, int end, int step) const th
     throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleId2 : invalid step should > 0 !");
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
   int nbComp=getNumberOfComponents();
-  int newNbOfTuples=(end-bg)/step;
+  int newNbOfTuples=(end+1-bg)/step-1;
   ret->alloc(newNbOfTuples,nbComp);
   int *pt=ret->getPointer();
   const int *srcPt=getConstPointer()+bg*nbComp;
@@ -2340,11 +2543,7 @@ DataArrayInt *DataArrayInt::keepSelectedComponents(const std::vector<int>& compo
   int newNbOfCompo=compoIds.size();
   int oldNbOfCompo=getNumberOfComponents();
   for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
-    if((*it)<0 || (*it)>=oldNbOfCompo)
-      {
-        std::ostringstream oss; oss << "DataArrayDouble::keepSelectedComponents : invalid requested component : " << *it << " whereas it should be in [0," << oldNbOfCompo << ") !";
-        throw INTERP_KERNEL::Exception(oss.str().c_str());
-      }
+    DataArray::CheckValueInRange(oldNbOfCompo,(*it),"keepSelectedComponents invalid requested component");
   int nbOfTuples=getNumberOfTuples();
   ret->alloc(nbOfTuples,newNbOfCompo);
   ret->copyPartOfStringInfoFrom(*this,compoIds);
@@ -2401,6 +2600,153 @@ void DataArrayInt::setSelectedComponents(const DataArrayInt *a, const std::vecto
       nc[nbOfCompo*i+compoIds[j]]=*ac;
 }
 
+/*!
+ * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
+ * 'strictCompoCompare' specifies if DataArray 'a' should have exactly same number of components and tuples than 'this' (true) or not (false). By default set to true with maximal test.
+ */
+void DataArrayInt::setPartOfValues1(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
+{
+  const char msg[]="DataArrayInt::setPartOfValues1";
+  checkAllocated();
+  a->checkAllocated();
+  int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
+  int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
+  int nbComp=getNumberOfComponents();
+  int nbOfTuples=getNumberOfTuples();
+  DataArray::CheckValueInRange(nbOfTuples,bgTuples,"invalid begin tuple value");
+  DataArray::CheckClosingParInRange(nbOfTuples,endTuples,"invalid end tuple value");
+  DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
+  DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
+  a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
+  if(strictCompoCompare)
+    a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+  int *pt=getPointer()+bgTuples*nbComp+bgComp;
+  const int *srcPt=a->getConstPointer();
+  for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
+    for(int j=0;j<newNbOfComp;j++,srcPt++)
+      pt[j*stepComp]=*srcPt;
+}
+
+/*!
+ * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
+ */
+void DataArrayInt::setPartOfValuesSimple1(int a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
+{
+  const char msg[]="DataArrayInt::setPartOfValuesSimple1";
+  checkAllocated();
+  int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
+  int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
+  int nbComp=getNumberOfComponents();
+  int nbOfTuples=getNumberOfTuples();
+  DataArray::CheckValueInRange(nbOfTuples,bgTuples,"invalid begin tuple value");
+  DataArray::CheckClosingParInRange(nbOfTuples,endTuples,"invalid end tuple value");
+  DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
+  DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
+  int *pt=getPointer()+bgTuples*nbComp+bgComp;
+  for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
+    for(int j=0;j<newNbOfComp;j++)
+      pt[j*stepComp]=a;
+}
+
+/*!
+ * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
+ * 'strictCompoCompare' specifies if DataArray 'a' should have exactly same number of components and tuples than 'this' (true) or not (false). By default set to true with maximal test.
+ */
+void DataArrayInt::setPartOfValues2(const DataArrayInt *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
+{
+  const char msg[]="DataArrayInt::setPartOfValues2";
+  checkAllocated();
+  a->checkAllocated();
+  int nbComp=getNumberOfComponents();
+  int nbOfTuples=getNumberOfTuples();
+  for(const int *z=bgComp;z!=endComp;z++)
+    DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
+  int newNbOfTuples=std::distance(bgTuples,endTuples);
+  int newNbOfComp=std::distance(bgComp,endComp);
+  a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
+  if(strictCompoCompare)
+    a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+  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;
+      }
+}
+
+/*!
+ * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
+ */
+void DataArrayInt::setPartOfValuesSimple2(int a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
+{
+  checkAllocated();
+  int nbComp=getNumberOfComponents();
+  int nbOfTuples=getNumberOfTuples();
+  for(const int *z=bgComp;z!=endComp;z++)
+    DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
+  int newNbOfTuples=std::distance(bgTuples,endTuples);
+  int newNbOfComp=std::distance(bgComp,endComp);
+  int *pt=getPointer();
+  for(const int *w=bgTuples;w!=endTuples;w++)
+    for(const int *z=bgComp;z!=endComp;z++)
+      {
+        DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
+        pt[(*w)*nbComp+(*z)]=a;
+      }
+}
+
+/*!
+ * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
+ * 'strictCompoCompare' specifies if DataArray 'a' should have exactly same number of components and tuples than 'this' (true) or not (false). By default set to true with maximal test.
+ */
+void DataArrayInt::setPartOfValues3(const DataArrayInt *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
+{
+  const char msg[]="DataArrayInt::setPartOfValues3";
+  checkAllocated();
+  a->checkAllocated();
+  int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
+  int nbComp=getNumberOfComponents();
+  int nbOfTuples=getNumberOfTuples();
+  DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
+  DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
+  int newNbOfTuples=std::distance(bgTuples,endTuples);
+  a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
+  if(strictCompoCompare)
+    a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
+  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;
+      }
+}
+
+/*!
+ * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
+ */
+void DataArrayInt::setPartOfValuesSimple3(int a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
+{
+  const char msg[]="DataArrayInt::setPartOfValuesSimple3";
+  checkAllocated();
+  int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
+  int nbComp=getNumberOfComponents();
+  int nbOfTuples=getNumberOfTuples();
+  DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
+  DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
+  int newNbOfTuples=std::distance(bgTuples,endTuples);
+  int *pt=getPointer()+bgComp;
+  for(const int *w=bgTuples;w!=endTuples;w++)
+    for(int j=0;j<newNbOfComp;j++)
+      {
+        DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
+        pt[(*w)*nbComp+j*stepComp]=a;
+      }
+}
+
 void DataArrayInt::SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet)
 {
   if(newArray!=arrayToSet)
index 64d50d6c86ae496d32eb20c1b81d366c63f61b84..474ec6ec7d711914a7e1416273e66e4cf9df0ea8 100644 (file)
@@ -104,8 +104,14 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT int getNumberOfComponents() const { return _info_on_compo.size(); }
     MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _nb_of_tuples; }
     MEDCOUPLING_EXPORT int getNbOfElems() const { return _info_on_compo.size()*_nb_of_tuples; }
+    MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void checkNbOfElems(int nbOfElems, const char *msg) const throw(INTERP_KERNEL::Exception);
   protected:
     DataArray():_nb_of_tuples(-1) { }
+  protected:
+    static void CheckValueInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception);
+    static void CheckClosingParInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception);
+    static int GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception);
   protected:
     int _nb_of_tuples;
     std::string _name;
@@ -161,6 +167,12 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT DataArrayDouble *keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void setPartOfValues1(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void setPartOfValuesSimple1(double a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void setPartOfValues2(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void setPartOfValuesSimple2(double a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void setPartOfValues3(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void setPartOfValuesSimple3(double a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void getTuple(int tupleId, double *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); }
     MEDCOUPLING_EXPORT double getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; }
     MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, double newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; declareAsNew(); }
@@ -278,6 +290,12 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT DataArrayInt *keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void meldWith(const DataArrayInt *other) throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayInt *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void setPartOfValues1(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void setPartOfValuesSimple1(int a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void setPartOfValues2(const DataArrayInt *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void setPartOfValuesSimple2(int a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void setPartOfValues3(const DataArrayInt *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void setPartOfValuesSimple3(int a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void getTuple(int tupleId, int *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); }
     MEDCOUPLING_EXPORT int getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; }
     MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, int newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; declareAsNew(); }
index 2a68c9612952bfcccbfd12d5e22b46e00fa3bbe8..e983cd85d9b3fadc9a1d118784119350cf5b5dbe 100644 (file)
@@ -1589,6 +1589,359 @@ namespace ParaMEDMEM
          return ret->keepSelectedComponents(v);
        }
    }
+
+   DataArrayDouble *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception)
+   {
+     self->checkAllocated();
+     const char msg[]="Unexpected situation in __setitem__ !";
+     int nbOfTuples=self->getNumberOfTuples();
+     int nbOfComponents=self->getNumberOfComponents();
+     int sw1,sw2;
+     double i1;
+     std::vector<double> v1;
+     DataArrayDouble *d1=0;
+     convertObjToPossibleCpp4(value,sw1,i1,v1,d1);
+     int it1,ic1;
+     std::vector<int> vt1,vc1;
+     std::pair<int, std::pair<int,int> > pt1,pc1;
+     DataArrayInt *dt1=0,*dc1=0;
+     convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
+     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp;
+     switch(sw2)
+       {
+       case 1:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 2:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 3:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 4:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 5:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 6:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 7:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 8:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 9:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
+               return self;
+             case 3:
+               self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 10:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
+               return self;
+             case 3:
+               self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 11:
+         {
+           int bb=pt1.first;
+           int ee=pt1.second.first;
+           int ss=pt1.second.second;
+           if(ee<bb || ss<=0)
+             throw INTERP_KERNEL::Exception("Invalid slice in tuple selection");
+           int nbOfE=(ee-bb)/ss;
+           std::vector<int> nv(nbOfE);
+           for(int jj=0;jj<nbOfE;jj++)
+             nv[jj]=bb+jj*ss;
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple2(i1,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues2(tmp,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size(),false);
+               return self;
+             case 3:
+               self->setPartOfValues2(d1,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 12:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
+               return self;
+             case 3:
+               self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 13:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
+               return self;
+             case 3:
+               self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 14:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
+               return self;
+             case 3:
+               self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 15:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             case 2:
+                 tmp=DataArrayDouble::New();
+                 tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+                 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
+                 return self;
+             case 3:
+               self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 16:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             case 2:
+               tmp=DataArrayDouble::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
+               return self;
+             case 3:
+               self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       default:
+         throw INTERP_KERNEL::Exception(msg);
+       }
+   }
  };
 
 %extend ParaMEDMEM::DataArrayInt
@@ -1915,81 +2268,464 @@ namespace ParaMEDMEM
      return ret;
    }
 
-   DataArrayInt *__getitem__(PyObject *ob) throw(INTERP_KERNEL::Exception)
+   DataArrayInt *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
    {
+     const char msg[]="Unexpected situation in __getitem__ !";
      self->checkAllocated();
      int nbOfTuples=self->getNumberOfTuples();
-     bool isTuple=PyTuple_Check(ob);
-     PyObject *obj=0;
-     if(!isTuple)
-       obj=ob;
-     else
-       {
-         int sz=PyTuple_Size(ob);
-         if(sz!=2)
-           throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
-         obj=PyTuple_GetItem(ob,0);
-       }
+     int nbOfComponents=self->getNumberOfComponents();
+     int it1,ic1;
+     std::vector<int> vt1,vc1;
+     std::pair<int, std::pair<int,int> > pt1,pc1;
+     DataArrayInt *dt1=0,*dc1=0;
+     int sw;
+     convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret;
+     switch(sw)
        {
-         if(PyInt_Check(obj))
-           {
-             int val=(int)PyInt_AS_LONG(obj);
-             ret=self->selectByTupleIdSafe(&val,&val+1);
-           }
-         else
-           {
-             if(!PySlice_Check(obj))
-               {
-                 std::ostringstream oss;
-                 oss << "Expecting a slice or an integer for subscriptable object DataArrayInt on tuples !";
-                 throw INTERP_KERNEL::Exception(oss.str().c_str());
-               }
-             Py_ssize_t strt,stp,step;
-             PySliceObject *oC=reinterpret_cast<PySliceObject *>(obj);
-             if(PySlice_GetIndices(oC,nbOfTuples,&strt,&stp,&step)!=0)
-               {
-                 std::ostringstream oss; oss << "Slice in subscriptable object DataArrayInt invalid : number of tuples is : " << nbOfTuples << " : check with your 1st slice !";
-                 throw INTERP_KERNEL::Exception(oss.str().c_str());
-               }
-             ret=self->selectByTupleId2(strt,stp,step);
-           }
-       }
-     if(!isTuple)
-       {
-         ret->incrRef();
-         return ret;
+       case 1:
+         return self->selectByTupleIdSafe(&it1,&it1+1);
+       case 2:
+         return self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
+       case 3:
+         return self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second);
+       case 4:
+         return self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
+       case 5:
+         {
+           ret=self->selectByTupleIdSafe(&it1,&it1+1);
+           std::vector<int> v2(1,ic1);
+           return ret->keepSelectedComponents(v2);
+         }
+       case 6:
+         {
+           ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
+           std::vector<int> v2(1,ic1);
+           return ret->keepSelectedComponents(v2);
+         }
+       case 7:
+         {
+           ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second);
+           std::vector<int> v2(1,ic1);
+           return ret->keepSelectedComponents(v2);
+         }
+       case 8:
+         {
+           ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
+           std::vector<int> v2(1,ic1);
+           return ret->keepSelectedComponents(v2);
+         }
+       case 9:
+         {
+           ret=self->selectByTupleIdSafe(&it1,&it1+1);
+           return ret->keepSelectedComponents(vc1);
+         }
+       case 10:
+         {
+           ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
+           return ret->keepSelectedComponents(vc1);
+         }
+       case 11:
+         {
+           ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second);
+           return ret->keepSelectedComponents(vc1);
+         }
+       case 12:
+         {
+           ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
+           return ret->keepSelectedComponents(vc1);
+         }
+       case 13:
+         {
+           ret=self->selectByTupleIdSafe(&it1,&it1+1);
+           int nbOfComp=(pc1.second.first-1-pc1.first)/pc1.second.second+1;
+           std::vector<int> v2(nbOfComp);
+           for(int i=0;i<nbOfComp;i++)
+             v2[i]=pc1.first+i*pc1.second.second;
+           return ret->keepSelectedComponents(v2);
+         }
+       case 14:
+         {
+           ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
+           int nbOfComp=(pc1.second.first-1-pc1.first)/pc1.second.second+1;
+           std::vector<int> v2(nbOfComp);
+           for(int i=0;i<nbOfComp;i++)
+             v2[i]=pc1.first+i*pc1.second.second;
+           return ret->keepSelectedComponents(v2);
+         }
+       case 15:
+         {
+           ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second);
+           int nbOfComp=(pc1.second.first-1-pc1.first)/pc1.second.second+1;
+           std::vector<int> v2(nbOfComp);
+           for(int i=0;i<nbOfComp;i++)
+             v2[i]=pc1.first+i*pc1.second.second;
+           return ret->keepSelectedComponents(v2);
+         }
+       case 16:
+         {
+           ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
+           int nbOfComp=(pc1.second.first-1-pc1.first)/pc1.second.second+1;
+           std::vector<int> v2(nbOfComp);
+           for(int i=0;i<nbOfComp;i++)
+             v2[i]=pc1.first+i*pc1.second.second;
+           return ret->keepSelectedComponents(v2);
+         }
+       default:
+         throw INTERP_KERNEL::Exception(msg);
        }
+   }
+
+   DataArrayInt *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception)
+   {
+     self->checkAllocated();
+     const char msg[]="Unexpected situation in __setitem__ !";
+     int nbOfTuples=self->getNumberOfTuples();
      int nbOfComponents=self->getNumberOfComponents();
-     PyObject *obj1=PyTuple_GetItem(ob,1);
-     if(PyInt_Check(obj1))
+     int sw1,sw2;
+     int i1;
+     std::vector<int> v1;
+     DataArrayInt *d1=0;
+     convertObjToPossibleCpp1(value,sw1,i1,v1,d1);
+     int it1,ic1;
+     std::vector<int> vt1,vc1;
+     std::pair<int, std::pair<int,int> > pt1,pc1;
+     DataArrayInt *dt1=0,*dc1=0;
+     convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
+     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp;
+     switch(sw2)
        {
-         int val=(int)PyInt_AS_LONG(obj1);
-         std::vector<int> v(1,val);
-         return ret->keepSelectedComponents(v);
-       }
-     else
-       {
-         if(!PySlice_Check(obj1))
-           {
-             std::ostringstream oss;
-             oss << "Expecting a slice or an integer for subscriptable object DataArrayInt on components !";
-             throw INTERP_KERNEL::Exception(oss.str().c_str());
-           }
-         Py_ssize_t strt,stp,step;
-         PySliceObject *oC=reinterpret_cast<PySliceObject *>(obj1);
-         if(PySlice_GetIndices(oC,nbOfComponents,&strt,&stp,&step)!=0)
-           {
-             std::ostringstream oss; oss << "Slice in subscriptable object DataArrayInt invalid : number of components is : " << nbOfComponents << " : check with your 2nd slice !";
-             throw INTERP_KERNEL::Exception(oss.str().c_str());
-           }
-         if(step<=0)
-           throw INTERP_KERNEL::Exception("2nd Slice in subscriptable object DataArrayInt invalid : should be > 0 !");
-         Py_ssize_t newNbOfComp=(stp-strt)/step;
-         std::vector<int> v(newNbOfComp);
-         for(int i=0;i<newNbOfComp;i++)
-           v[i]=strt+i*step;
-         return ret->keepSelectedComponents(v);
+       case 1:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 2:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 3:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 4:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 5:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 6:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 7:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 8:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
+               return self;
+             case 3:
+               self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 9:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
+               return self;
+             case 3:
+               self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 10:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
+               return self;
+             case 3:
+               self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 11:
+         {
+           int bb=pt1.first;
+           int ee=pt1.second.first;
+           int ss=pt1.second.second;
+           if(ee<bb || ss<=0)
+             throw INTERP_KERNEL::Exception("Invalid slice in tuple selection");
+           int nbOfE=(ee-bb)/ss;
+           std::vector<int> nv(nbOfE);
+           for(int jj=0;jj<nbOfE;jj++)
+             nv[jj]=bb+jj*ss;
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple2(i1,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues2(tmp,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size(),false);
+               return self;
+             case 3:
+               self->setPartOfValues2(d1,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 12:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
+               return self;
+             case 3:
+               self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 13:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
+               return self;
+             case 3:
+               self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 14:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
+               return self;
+             case 3:
+               self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 15:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             case 2:
+                 tmp=DataArrayInt::New();
+                 tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+                 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
+                 return self;
+             case 3:
+               self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       case 16:
+         {
+           switch(sw1)
+             {
+             case 1:
+               self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             case 2:
+               tmp=DataArrayInt::New();
+               tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1);
+               self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
+               return self;
+             case 3:
+               self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
+               return self;
+             default:
+               throw INTERP_KERNEL::Exception(msg);
+             }
+           break;
+         }
+       default:
+         throw INTERP_KERNEL::Exception(msg);
        }
    }
  };
index 2cf25a4d8aa1b44931fc8a4ad0421d3f00ab3c33..663e4e5f9b78490ea9e0fc1f3cc1038944d451bd 100644 (file)
@@ -6006,6 +6006,118 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         self.assertEqual([],da2.getValues())
         pass
 
+    def testSwigSetItem1(self):
+        da=DataArrayInt.New()
+        da.alloc(20,1)
+        da.iota(7)
+        da.rearrange(5)
+        da.setInfoOnComponent(0,"X [m]") ; da.setInfoOnComponent(1,"Y [km]") ; da.setInfoOnComponent(2,"Y [m]")
+        da.setInfoOnComponent(3,"Z [W]") ; da.setInfoOnComponent(4,"ZZ [km]") ; 
+        da[:,2]=3
+        self.assertEqual([7, 8, 3, 10, 11, 12, 13, 3, 15, 16, 17, 18, 3, 20, 21, 22, 23, 3, 25, 26],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[2]=3
+        self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 3, 3, 3, 3, 3, 22, 23, 24, 25, 26],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[[0,3]]=-1
+        self.assertEqual([-1, -1, -1, -1, -1, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[:,[1,3,4]]=-3
+        self.assertEqual([7, -3, 9, -3, -3, 12, -3, 14, -3, -3, 17, -3, 19, -3, -3, 22, -3, 24, -3, -3],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da2=DataArrayInt.New() ; da2.setValues([0,2,3],3,1)
+        da[da2]=-7
+        self.assertEqual([-7, -7, -7, -7, -7, 12, 13, 14, 15, 16, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[da2,-2:]=-7
+        self.assertEqual([7, 8, 9, -7, -7, 12, 13, 14, 15, 16, 17, 18, 19, -7, -7, 22, 23, 24, -7, -7],da.getValues())
+        # Let's test with DAI right hand side
+        da1=DataArrayInt.New()
+        da1.setValues([25,26,27,125,126,127],2,3)
+        #
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[-2:,1:4]=da1
+        self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 25, 26, 27, 21, 22, 125, 126, 127, 26],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[1:,3]=[225,226,227]
+        self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 225, 16, 17, 18, 19, 226, 21, 22, 23, 24, 227, 26],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[1,2:]=[225,226,227]
+        self.assertEqual([7, 8, 9, 10, 11, 12, 13, 225, 226, 227, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[da2,-2:]=[88,99,1010,1111,1212,1313]
+        self.assertEqual([7, 8, 9, 88, 99, 12, 13, 14, 15, 16, 17, 18, 19, 1010, 1111, 22, 23, 24, 1212, 1313],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da3=DataArrayInt.New(); da3.setValues([88,99,1010,1111,1212,1313],3,2)
+        da[da2,-2:]=da3
+        self.assertEqual([7, 8, 9, 88, 99, 12, 13, 14, 15, 16, 17, 18, 19, 1010, 1111, 22, 23, 24, 1212, 1313],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[da2,[0,2]]=da3
+        self.assertEqual([88, 8, 99, 10, 11, 12, 13, 14, 15, 16, 1010, 18, 1111, 20, 21, 1212, 23, 1313, 25, 26],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[da2,0:3:2]=da3
+        self.assertEqual([88, 8, 99, 10, 11, 12, 13, 14, 15, 16, 1010, 18, 1111, 20, 21, 1212, 23, 1313, 25, 26],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[da2,0:3:2]=-8
+        self.assertEqual([-8, 8, -8, 10, 11, 12, 13, 14, 15, 16, -8, 18, -8, 20, 21, -8, 23, -8, 25, 26],da.getValues())
+        pass
+
+    def testSwigSetItem2(self):
+        da=DataArrayDouble.New()
+        da.alloc(20,1)
+        da.iota(7)
+        da.rearrange(5)
+        da.setInfoOnComponent(0,"X [m]") ; da.setInfoOnComponent(1,"Y [km]") ; da.setInfoOnComponent(2,"Y [m]")
+        da.setInfoOnComponent(3,"Z [W]") ; da.setInfoOnComponent(4,"ZZ [km]") ; 
+        da[:,2]=3.
+        self.assertEqual([7., 8., 3., 10., 11., 12., 13., 3., 15., 16., 17., 18., 3., 20., 21., 22., 23., 3., 25., 26.],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[2]=3.
+        self.assertEqual([7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 3., 3., 3., 3., 3., 22., 23., 24., 25., 26.],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[[0,3]]=-1.
+        self.assertEqual([-1., -1., -1., -1., -1., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., -1., -1., -1., -1., -1.],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[:,[1,3,4]]=-3.
+        self.assertEqual([7., -3., 9., -3., -3., 12., -3., 14., -3., -3., 17., -3., 19., -3., -3., 22., -3., 24., -3., -3.],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da2=DataArrayInt.New() ; da2.setValues([0,2,3],3,1)
+        da[da2]=-7.
+        self.assertEqual([-7., -7., -7., -7., -7., 12., 13., 14., 15., 16., -7., -7., -7., -7., -7., -7., -7., -7., -7., -7.],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[da2,-2:]=-7
+        self.assertEqual([7., 8., 9., -7., -7., 12., 13., 14., 15., 16., 17., 18., 19., -7., -7., 22., 23., 24., -7., -7.],da.getValues())
+        # Let's test with DAI right hand side
+        da1=DataArrayDouble.New()
+        da1.setValues([25,26,27,125,126,127],2,3)
+        #
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[-2:,1:4]=da1
+        self.assertEqual([7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 25., 26., 27., 21., 22., 125., 126., 127., 26.],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[1:,3]=[225.,226.,227.]
+        self.assertEqual([7., 8., 9., 10., 11., 12., 13., 14., 225., 16., 17., 18., 19., 226., 21., 22., 23., 24., 227., 26.],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[1,2:]=[225,226,227]
+        self.assertEqual([7., 8., 9., 10., 11., 12., 13., 225., 226., 227., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26.],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[da2,-2:]=[88,99,1010,1111,1212,1313]
+        self.assertEqual([7., 8., 9., 88., 99., 12., 13., 14., 15., 16., 17., 18., 19., 1010., 1111., 22., 23., 24., 1212., 1313.],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da3=DataArrayDouble.New(); da3.setValues([88,99,1010,1111,1212,1313],3,2)
+        da[da2,-2:]=da3
+        self.assertEqual([7., 8., 9., 88., 99., 12., 13., 14., 15., 16., 17., 18., 19., 1010., 1111., 22., 23., 24., 1212., 1313.],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[da2,[0,2]]=da3
+        self.assertEqual([88., 8., 99., 10., 11., 12., 13., 14., 15., 16., 1010., 18., 1111., 20., 21., 1212., 23., 1313., 25., 26.],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[da2,0:3:2]=da3
+        self.assertEqual([88., 8., 99., 10., 11., 12., 13., 14., 15., 16., 1010., 18., 1111., 20., 21., 1212., 23., 1313., 25., 26.],da.getValues())
+        da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
+        da[da2,0:3:2]=-8.
+        self.assertEqual([-8., 8., -8., 10., 11., 12., 13., 14., 15., 16., -8., 18., -8., 20., 21., -8., 23., -8., 25., 26.],da.getValues())
+        pass
+
     def testDAIAggregateMulti1(self):
         a=DataArrayInt.New()
         a.setValues(range(4),2,2)
index 7dfc7fa100e6be5645bb65972bf47dbfaed6455d..0c1d62ca9b6b3a8bcc84add25830d62603679f73 100644 (file)
@@ -576,3 +576,267 @@ void convertPyObjToVecDataArrayIntCst(PyObject *ms, std::vector<const ParaMEDMEM
       throw INTERP_KERNEL::Exception(msg);
     }
 }
+
+/*!
+ * if python int -> cpp int sw=1
+ * if python list[int] -> cpp vector<int> sw=2
+ * if python tuple[int] -> cpp vector<int> sw=2
+ * if python DataArrayInt -> cpp DataArrayInt sw=3
+ *
+ * switch between (int,vector<int>,DataArrayInt)
+ */
+static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp) throw(INTERP_KERNEL::Exception)
+{
+  sw=-1;
+  if(PyInt_Check(value))
+    {
+      iTyypp=(int)PyInt_AS_LONG(value);
+      sw=1;
+      return;
+    }
+  if(PyTuple_Check(value))
+    {
+      int size=PyTuple_Size(value);
+      stdvecTyypp.resize(size);
+      for(int i=0;i<size;i++)
+        {
+          PyObject *o=PyTuple_GetItem(value,i);
+          if(PyInt_Check(o))
+            stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
+          else
+            {
+              std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
+              throw INTERP_KERNEL::Exception(oss.str().c_str());
+            }
+        }
+      sw=2;
+      return;
+    }
+  if(PyList_Check(value))
+    {
+      int size=PyList_Size(value);
+      stdvecTyypp.resize(size);
+      for(int i=0;i<size;i++)
+        {
+          PyObject *o=PyList_GetItem(value,i);
+          if(PyInt_Check(o))
+            stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
+          else
+            {
+              std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
+              throw INTERP_KERNEL::Exception(oss.str().c_str());
+            }
+        }
+      sw=2;
+      return;
+    }
+  void *argp;
+  int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
+  if(!SWIG_IsOK(status))
+    throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, DataArrayInt");
+  daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
+  sw=3;
+}
+
+/*!
+ * if python double -> cpp double sw=1
+ * if python int -> cpp double sw=1
+ * if python list[double] -> cpp vector<double> sw=2
+ * if python list[int] -> cpp vector<double> sw=2
+ * if python tuple[double] -> cpp vector<double> sw=2
+ * if python tuple[int] -> cpp vector<double> sw=2
+ * if python DataArrayDouble -> cpp DataArrayDouble sw=3
+ *
+ * switch between (int,vector<int>,DataArrayInt)
+ */
+static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
+{
+  sw=-1;
+  if(PyFloat_Check(value))
+    {
+      iTyypp=PyFloat_AS_DOUBLE(value);
+      sw=1;
+      return;
+    }
+  if(PyInt_Check(value))
+    {
+      iTyypp=(double)PyInt_AS_LONG(value);
+      sw=1;
+      return;
+    }
+  if(PyTuple_Check(value))
+    {
+      int size=PyTuple_Size(value);
+      stdvecTyypp.resize(size);
+      for(int i=0;i<size;i++)
+        {
+          PyObject *o=PyTuple_GetItem(value,i);
+          if(PyFloat_Check(o))
+            stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
+          else if(PyInt_Check(o))
+            stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
+          else
+            {
+              std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
+              throw INTERP_KERNEL::Exception(oss.str().c_str());
+            }
+        }
+      sw=2;
+      return;
+    }
+  if(PyList_Check(value))
+    {
+      int size=PyList_Size(value);
+      stdvecTyypp.resize(size);
+      for(int i=0;i<size;i++)
+        {
+          PyObject *o=PyList_GetItem(value,i);
+          if(PyFloat_Check(o))
+            stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
+          else if(PyInt_Check(o))
+            stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
+          else
+            {
+              std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
+              throw INTERP_KERNEL::Exception(oss.str().c_str());
+            }
+        }
+      sw=2;
+      return;
+    }
+  void *argp;
+  int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
+  if(!SWIG_IsOK(status))
+    throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
+  daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
+  sw=3;
+}
+
+/*!
+ * if python int -> cpp int sw=1
+ * if python list[int] -> cpp vector<int> sw=2
+ * if python tuple[int] -> cpp vector<int> sw=2
+ * if python slicp -> cpp pair sw=3
+ * if python DataArrayInt -> cpp DataArrayInt sw=4
+ *
+ * switch between (int,vector<int>,DataArrayInt)
+ */
+static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, ParaMEDMEM::DataArrayInt *& daIntTyypp) throw(INTERP_KERNEL::Exception)
+{
+  sw=-1;
+  if(PyInt_Check(value))
+    {
+      iTyypp=(int)PyInt_AS_LONG(value);
+      sw=1;
+      return;
+    }
+  if(PyTuple_Check(value))
+    {
+      int size=PyTuple_Size(value);
+      stdvecTyypp.resize(size);
+      for(int i=0;i<size;i++)
+        {
+          PyObject *o=PyTuple_GetItem(value,i);
+          if(PyInt_Check(o))
+            stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
+          else
+            {
+              std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
+              throw INTERP_KERNEL::Exception(oss.str().c_str());
+            }
+        }
+      sw=2;
+      return;
+    }
+  if(PyList_Check(value))
+    {
+      int size=PyList_Size(value);
+      stdvecTyypp.resize(size);
+      for(int i=0;i<size;i++)
+        {
+          PyObject *o=PyList_GetItem(value,i);
+          if(PyInt_Check(o))
+            stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
+          else
+            {
+              std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
+              throw INTERP_KERNEL::Exception(oss.str().c_str());
+            }
+        }
+      sw=2;
+      return;
+    }
+  if(PySlice_Check(value))
+    {
+      Py_ssize_t strt,stp,step;
+      PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
+      if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
+        {
+          std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elemnts is : " << nbelem;
+          throw INTERP_KERNEL::Exception(oss.str().c_str());
+        }
+      p.first=strt;
+      p.second.first=stp;
+      p.second.second=step;
+      sw=3;
+      return ;
+    }
+  void *argp;
+  int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
+  if(!SWIG_IsOK(status))
+    throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt");
+  daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
+  sw=4;
+}
+
+/*!
+ * if value int -> cpp it sw=1
+ * if value list[int] -> vt sw=2
+ * if value tuple[int] -> vt sw=2
+ * if value slice -> pt sw=3
+ * if value DataArrayInt -> dt sw=4
+ * if value tuple [int,int] -> cpp it,ip sw=5
+ * if value tuple [list[int],int] -> cpp vt,ip sw=6
+ * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
+ * if value tuple [slice,int] -> cpp pt,ip sw=7
+ * if value tuple [DaI,int] -> cpp dt,ip sw=8
+ * if value tuple [int,list[int]] -> cpp it,vc sw=9
+ * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
+ * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
+ * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
+ * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
+ * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
+ * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
+ * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
+ * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
+ * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
+ * if value tuple [int,slice] -> cpp it,pc sw=13
+ * if value tuple [list[int],slice] -> cpp vt,pc sw=14
+ * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
+ * if value tuple [slice,slice] -> cpp pt,pc sw=15
+ * if value tuple [DaI,slice] -> cpp dt,pc sw=16
+ *
+ * switch between (int,vector<int>,DataArrayInt)
+ */
+static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
+                                     std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
+                                     ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
+{
+  if(!PyTuple_Check(value))
+    {
+      convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
+      return ;
+    }
+  else
+    {
+      int sz=PyTuple_Size(value);
+      if(sz!=2)
+        throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
+      PyObject *ob0=PyTuple_GetItem(value,0);
+      int sw1,sw2;
+      convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
+      PyObject *ob1=PyTuple_GetItem(value,1);
+      convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
+      sw=4*sw2+sw1;
+    }
+}