* \return bool - \a true if all values are \a val.
* \throw If \a this is not allocated.
* \throw If \a this->getNumberOfComponents() != 1
+ * \sa DataArrayInt::checkUniformAndGuess
*/
bool DataArrayInt::isUniform(int val) const
{
checkAllocated();
if(getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayInt::isUniform : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
- int nbOfTuples=getNumberOfTuples();
- const int *w=getConstPointer();
- const int *end2=w+nbOfTuples;
+ const int *w(begin()),*end2(end());
for(;w!=end2;w++)
if(*w!=val)
return false;
return true;
}
+/*!
+ * This method checks that \a this is uniform. If not and exception will be thrown.
+ * In case of uniformity the corresponding value is returned.
+ *
+ * \return int - the unique value contained in this
+ * \throw If \a this is not allocated.
+ * \throw If \a this->getNumberOfComponents() != 1
+ * \throw If \a this is not uniform.
+ * \sa DataArrayInt::isUniform
+ */
+int DataArrayInt::checkUniformAndGuess() const
+{
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::checkUniformAndGuess : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
+ if(empty())
+ throw INTERP_KERNEL::Exception("DataArrayInt::checkUniformAndGuess : this is empty !");
+ const int *w(begin()),*end2(end());
+ int ret(*w);
+ for(;w!=end2;w++)
+ if(*w!=ret)
+ throw INTERP_KERNEL::Exception("DataArrayInt::checkUniformAndGuess : this is not uniform !");
+ return ret;
+}
+
/*!
* Checks if all values in \a this array are unique.
* \return bool - \a true if condition above is true
MEDCOUPLING_EXPORT DataArrayInt *buildPermArrPerLevel() const;
MEDCOUPLING_EXPORT bool isIota(int sizeExpected) const;
MEDCOUPLING_EXPORT bool isUniform(int val) const;
+ MEDCOUPLING_EXPORT int checkUniformAndGuess() const;
MEDCOUPLING_EXPORT bool hasUniqueValues() const;
MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayInt *a, const std::vector<int>& compoIds);
MEDCOUPLING_EXPORT DataArrayIntIterator *iterator();
d2.transformWithIndArr(m)
self.assertTrue(d2.isEqual(DataArrayInt([0,0,1,0,1])))
pass
+
+ def testDAICheckUniformAndGuess1(self):
+ d=DataArrayInt([3,3],1,2)
+ self.assertRaises(InterpKernelException,d.checkUniformAndGuess)# non single compo
+ d=DataArrayInt([])
+ self.assertRaises(InterpKernelException,d.checkUniformAndGuess)# empty
+ d=DataArrayInt()
+ self.assertRaises(InterpKernelException,d.checkUniformAndGuess)# non allocated
+ d=DataArrayInt([3,3,3])
+ self.assertEqual(3,d.checkUniformAndGuess())
+ d=DataArrayInt([7])
+ self.assertEqual(7,d.checkUniformAndGuess())
+ d=DataArrayInt([3,4,3])
+ self.assertRaises(InterpKernelException,d.checkUniformAndGuess)# non uniform
+ pass
pass
DataArrayInt *buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception);
bool isIota(int sizeExpected) const throw(INTERP_KERNEL::Exception);
bool isUniform(int val) const throw(INTERP_KERNEL::Exception);
+ int checkUniformAndGuess() const throw(INTERP_KERNEL::Exception);
bool hasUniqueValues() const throw(INTERP_KERNEL::Exception);
DataArrayInt *subArray(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception);
void transpose() throw(INTERP_KERNEL::Exception);