Salome HOME
Merge branch 'master' of ssh://git.salome-platform.org/tools/medcoupling
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingMemArray.cxx
index 743e7dd7a9aec2e61036f5e2c3a6111101d6d817..53213b741d529f377d1525d69a924f4e14631e14 100644 (file)
@@ -36,6 +36,8 @@ typedef double (*MYFUNCPTR)(double);
 
 using namespace MEDCoupling;
 
+template class MemArray<int>;
+template class MemArray<double>;
 template class DataArrayTemplate<int>;
 template class DataArrayTemplate<double>;
 
@@ -112,6 +114,22 @@ void DataArrayDouble::FindClosestTupleIdAlg(const BBTreePts<SPACEDIM,int>& myTre
     }
 }
 
+int DataArray::EffectiveCircPerm(int nbOfShift, int nbOfTuples)
+{
+  if(nbOfTuples<=0)
+    throw INTERP_KERNEL::Exception("DataArray::EffectiveCircPerm : number of tuples is expected to be > 0 !");
+  if(nbOfShift>=0)
+    {
+      return nbOfShift%nbOfTuples;
+    }
+  else
+    {
+      int tmp(-nbOfShift);
+      tmp=tmp%nbOfTuples;
+      return nbOfTuples-tmp;
+    }
+}
+
 std::size_t DataArray::getHeapMemorySizeWithoutChildren() const
 {
   std::size_t sz1=_name.capacity();
@@ -5620,6 +5638,48 @@ DataArrayInt *DataArrayInt::buildPermutationArr(const DataArrayInt& other) const
   return ret.retn();
 }
 
+/*!
+ * Elements of \a partOfThis are expected to be included in \a this.
+ * The returned array \a ret is so that this[ret]==partOfThis
+ *
+ * For example, if \a this array contents are [9,10,0,6,4,11,3,8] and if \a partOfThis contains [6,0,11,8]
+ * the return array will contain [3,2,5,7].
+ *
+ * \a this is expected to be a 1 compo allocated array.
+ * \param [in] partOfThis - A 1 compo allocated array
+ * \return - A newly allocated array to be dealed by caller having the same number of tuples than \a partOfThis.
+ * \throw if two same element is present twice in \a this
+ * \throw if an element in \a partOfThis is \b NOT in \a this.
+ */
+DataArrayInt *DataArrayInt::indicesOfSubPart(const DataArrayInt& partOfThis) const
+{
+  if(getNumberOfComponents()!=1 || partOfThis.getNumberOfComponents()!=1)
+    throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : this and input array must be one component array !");
+  checkAllocated(); partOfThis.checkAllocated();
+  int thisNbTuples(getNumberOfTuples()),nbTuples(partOfThis.getNumberOfTuples());
+  const int *thisPt(begin()),*pt(partOfThis.begin());
+  MCAuto<DataArrayInt> ret(DataArrayInt::New());
+  ret->alloc(nbTuples,1);
+  int *retPt(ret->getPointer());
+  std::map<int,int> m;
+  for(int i=0;i<thisNbTuples;i++,thisPt++)
+    m[*thisPt]=i;
+  if(m.size()!=thisNbTuples)
+    throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : some elements appears more than once !");
+  for(int i=0;i<nbTuples;i++,retPt++,pt++)
+    {
+      std::map<int,int>::const_iterator it(m.find(*pt));
+      if(it!=m.end())
+        *retPt=(*it).second;
+      else
+        {
+          std::ostringstream oss; oss << "DataArrayInt::indicesOfSubPart : At pos #" << i << " of input array value is " << *pt << " not in this !";
+          throw INTERP_KERNEL::Exception(oss.str());
+        }
+    }
+  return ret.retn();
+}
+
 void DataArrayInt::aggregate(const DataArrayInt *other)
 {
   if(!other)