From 461df7547e21b4b39faf16a0705192a04c30ccf3 Mon Sep 17 00:00:00 2001 From: geay Date: Wed, 9 Apr 2014 16:09:21 +0200 Subject: [PATCH] Py binding of static method DataArrayInt.CheckAndPreparePermutation. --- src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 9 +++++++++ src/MEDCoupling_Swig/MEDCouplingMemArray.i | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 1f58aec18..5ae3883ea 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -14724,6 +14724,15 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,5]))) pass + def testSwig2CheckAndPreparePermutation2(self): + a=DataArrayInt([10003,9999999,5,67]) + self.assertTrue(DataArrayInt.CheckAndPreparePermutation(a).isEqual(DataArrayInt([2,3,0,1]))) + a=DataArrayInt([10003,-9999999,5,67]) + self.assertTrue(DataArrayInt.CheckAndPreparePermutation(a).isEqual(DataArrayInt([3,0,1,2]))) + a=DataArrayInt([]) + self.assertTrue(DataArrayInt.checkAndPreparePermutation(a).isEqual(DataArrayInt([]))) + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index c17ed322b..a47188a90 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -102,6 +102,7 @@ %newobject ParaMEDMEM::DataArrayInt::buildPermArrPerLevel; %newobject ParaMEDMEM::DataArrayInt::getDifferentValues; %newobject ParaMEDMEM::DataArrayInt::FindPermutationFromFirstToSecond; +%newobject ParaMEDMEM::DataArrayInt::CheckAndPreparePermutation; %newobject ParaMEDMEM::DataArrayInt::__neg__; %newobject ParaMEDMEM::DataArrayInt::__add__; %newobject ParaMEDMEM::DataArrayInt::__radd__; @@ -2787,6 +2788,17 @@ namespace ParaMEDMEM return ret; } + static DataArrayInt *CheckAndPreparePermutation(PyObject *arr) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *arrPtr(convertObjToPossibleCpp1_Safe(arr,sw,szArr,iTypppArr,stdvecTyyppArr)); + int *pt(ParaMEDMEM::DataArrayInt::CheckAndPreparePermutation(arrPtr,arrPtr+szArr)); + ret->useArray(pt,true,ParaMEDMEM::C_DEALLOC,szArr,1); + return ret.retn(); + } + void setValues(PyObject *li, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) { const char *msg="ParaMEDMEM::DataArrayInt::setValues : Available API are : \n-DataArrayInt.setValues([1,3,4])\n-DataArrayInt.setValues([1,3,4],3)\n-DataArrayInt.setValues([1,3,4,5],2,2)\n-DataArrayInt.New(5)\n !"; -- 2.39.2