#include <cmath>
#include <limits>
#include <numeric>
+#include <algorithm>
#include <functional>
typedef double (*MYFUNCPTR)(double);
return BuildIntersection(arrs);
}
+/*!
+ * This method can be applied on allocated with one component DataArrayInt instance.
+ * This method is typically relevant for sorted arrays. All consecutive duplicated items in \a this will appear only once in returned DataArrayInt instance.
+ * Example : if \a this contains [1,2,2,3,3,3,3,4,5,5,7,7,7,19] the returned array will contain [1,2,3,4,5,7,19]
+ *
+ * \return a newly allocated array that contain the result of the unique operation applied on \a this.
+ * \throw if \a this is not allocated or if \a this has not exactly one component.
+ */
+DataArrayInt *DataArrayInt::buildUnique() const throw(INTERP_KERNEL::Exception)
+{
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::buildUnique : only single component allowed !");
+ int nbOfTuples=getNumberOfTuples();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=deepCpy();
+ int *data=tmp->getPointer();
+ int *last=std::unique(data,data+nbOfTuples);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
+ ret->alloc(std::distance(data,last),1);
+ std::copy(data,last,ret->getPointer());
+ ret->incrRef();
+ return ret;
+}
+
/*!
* This method could be usefull for returned DataArrayInt marked as index. Some methods that generate such DataArrayInt instances:
* - ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity
MEDCOUPLING_EXPORT DataArrayInt *buildSubstraction(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT DataArrayInt *buildUnique() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *deltaShiftIndex() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void computeOffsets() throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void computeOffsets2() throw(INTERP_KERNEL::Exception);
m2->decrRef();
m1->decrRef();
}
+
+void MEDCouplingBasicsTest5::testDAIBuildUnique1()
+{
+ DataArrayInt *d=DataArrayInt::New();
+ const int dData[14]={1,2,2,3,3,3,3,4,5,5,7,7,7,19};
+ d->useArray(dData,false,CPP_DEALLOC,14,1);
+ const int expectedData[7]={1,2,3,4,5,7,19};
+ //
+ DataArrayInt *e=d->buildUnique();
+ CPPUNIT_ASSERT_EQUAL(7,e->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,e->getNumberOfComponents());
+ for(int i=0;i<7;i++)
+ CPPUNIT_ASSERT_EQUAL(expectedData[i],e->getIJ(i,0));
+ //
+ e->decrRef();
+ d->decrRef();
+}
+
CPPUNIT_TEST( testKrSpatialDiscretization1 );
CPPUNIT_TEST( testDuplicateEachTupleNTimes1 );
CPPUNIT_TEST( testIntersect2DMeshesTmp5 );
+ CPPUNIT_TEST( testDAIBuildUnique1 );
CPPUNIT_TEST_SUITE_END();
public:
void testUMeshTessellate2D1();
void testKrSpatialDiscretization1();
void testDuplicateEachTupleNTimes1();
void testIntersect2DMeshesTmp5();
+ void testDAIBuildUnique1();
};
}
self.assertEqual(expected2,d2.getValues())
pass
+ def testDAIBuildUnique1(self):
+ d=DataArrayInt([1,2,2,3,3,3,3,4,5,5,7,7,7,19])
+ e=d.buildUnique()
+ self.assertTrue(e.isEqual(DataArrayInt([1,2,3,4,5,7,19])))
+ pass
+
def setUp(self):
pass
pass
%newobject ParaMEDMEM::DataArrayInt::buildUnion;
%newobject ParaMEDMEM::DataArrayInt::buildSubstraction;
%newobject ParaMEDMEM::DataArrayInt::buildIntersection;
+%newobject ParaMEDMEM::DataArrayInt::buildUnique;
%newobject ParaMEDMEM::DataArrayInt::deltaShiftIndex;
%newobject ParaMEDMEM::DataArrayInt::buildExplicitArrByRanges;
%newobject ParaMEDMEM::DataArrayInt::findRangeIdForEachTuple;