return new DataArrayInt32(*this);
}
+MCAuto<DataArrayInt64> DataArrayInt32::convertToInt64Arr() const
+{
+ this->checkAllocated();
+ MCAuto<DataArrayInt64> ret(DataArrayInt64::New());
+ ret->alloc(this->getNumberOfTuples(),this->getNumberOfComponents());
+ ret->copyStringInfoFrom(*this);
+ const std::int32_t *pt(this->begin());
+ std::for_each(ret->getPointer(),ret->getPointer()+ret->getNbOfElems(),[&pt](std::int64_t& val) { val = std::int64_t(*pt++); });
+ return ret;
+}
+
DataArrayInt32Iterator *DataArrayInt32::iterator()
{
return new DataArrayInt32Iterator(this);
return this->buildDA(nbOfTuples,nbOfCompo);
}
+MCAuto<DataArrayInt32> DataArrayInt64::convertToInt32Arr() const
+{
+ this->checkAllocated();
+ MCAuto<DataArrayInt32> ret(DataArrayInt32::New());
+ ret->alloc(this->getNumberOfTuples(),this->getNumberOfComponents());
+ ret->copyStringInfoFrom(*this);
+ const std::int64_t *pt(this->begin());
+ std::for_each(ret->getPointer(),ret->getPointer()+ret->getNbOfElems(),[&pt](std::int32_t& val) { val = std::int32_t(*pt++); });
+ return ret;
+}
+
DataArrayInt64Iterator *DataArrayInt64::iterator()
{
return new DataArrayInt64Iterator(this);
DataArrayInt32 *deepCopy() const;
DataArrayInt32 *copySorted(bool asc=true) const override { return this->copySortedImpl(asc); }
DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }
+ MCAuto<DataArrayInt64> convertToInt64Arr() const;
public:
DataArrayInt32 *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); }
DataArrayInt32 *selectByTupleId(const DataArrayIdType& di) const { return this->mySelectByTupleId(di); }
DataArrayInt64 *deepCopy() const;
DataArrayInt64 *copySorted(bool asc=true) const override { return this->copySortedImpl(asc); }
DataArrayInt64 *buildNewEmptyInstance() const { return DataArrayInt64::New(); }//ok
+ MCAuto<DataArrayInt32> convertToInt32Arr() const;
public:
DataArrayInt64 *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); }
DataArrayInt64 *selectByTupleId(const DataArrayIdType& di) const { return this->mySelectByTupleId(di); }
ARRAYDEF( DataArrayInt32, Int32 )
};
%extend DataArrayInt32 {
+ DataArrayInt64 *convertToInt64Arr() const
+ {
+ MCAuto<DataArrayInt64> ret(self->convertToInt64Arr());
+ return ret.retn();
+ }
#ifdef WITH_NUMPY
PyObject *toNumPyArray() // not const. It is not a bug !
{
ARRAYDEF( DataArrayInt64, Int64 )
};
%extend DataArrayInt64 {
+ DataArrayInt32 *convertToInt32Arr() const
+ {
+ MCAuto<DataArrayInt32> ret(self->convertToInt32Arr());
+ return ret.retn();
+ }
#ifdef WITH_NUMPY
PyObject *toNumPyArray() // not const. It is not a bug !
{
m.checkConsistency()
m.checkGeomConsistency() # now m is OK
+ def testInt32Int64Arr0(self):
+ n = 30
+ arr = DataArrayInt32(n)
+ arr.iota() ; arr.rearrange(3)
+ comps = ["a","bb","ccc"]
+ name = "aaa"
+ arr.setName(name) ; arr.setInfoOnComponents(comps)
+ self.assertEqual(arr.accumulate(),[135, 145, 155])
+ arr2 = arr.convertToInt64Arr() # test is here
+ self.assertEqual(arr2.accumulate(),[135, 145, 155])
+ self.assertTrue(isinstance(arr2,DataArrayInt64))
+ self.assertEqual(arr2.getName(),name)
+ self.assertEqual(arr2.getInfoOnComponents(),comps)
+ arr3 = arr2.convertToInt32Arr() # test is here
+ self.assertEqual(arr3.accumulate(),[135, 145, 155])
+ self.assertTrue(isinstance(arr3,DataArrayInt32))
+ self.assertEqual(arr3.getName(),name)
+ self.assertEqual(arr3.getInfoOnComponents(),comps)
+ self.assertTrue(arr3.isEqual(arr))
+
pass
if __name__ == '__main__':
%newobject MEDCoupling::DataArrayInt32::__rmod__;
%newobject MEDCoupling::DataArrayInt32::__pow__;
%newobject MEDCoupling::DataArrayInt32::__rpow__;
+%newobject MEDCoupling::DataArrayInt32::convertToInt64Arr;
%newobject MEDCoupling::DataArrayInt32Tuple::buildDAInt;
%newobject MEDCoupling::DataArrayInt64::New;
%newobject MEDCoupling::DataArrayInt64::__iter__;
%newobject MEDCoupling::DataArrayInt64::__rmod__;
%newobject MEDCoupling::DataArrayInt64::__pow__;
%newobject MEDCoupling::DataArrayInt64::__rpow__;
+%newobject MEDCoupling::DataArrayInt64::convertToInt32Arr;
%newobject MEDCoupling::DataArrayInt64Tuple::buildDAInt;
%newobject MEDCoupling::DataArrayChar::convertToIntArr;
%newobject MEDCoupling::DataArrayChar::renumber;