class DataArrayTemplate : public DataArray
{
public:
- static MCAuto< typename Traits<T>::ArrayTypeCh > NewFromStdVector(const typename std::vector<T>& v);
+ MEDCOUPLING_EXPORT static MCAuto< typename Traits<T>::ArrayTypeCh > NewFromStdVector(const typename std::vector<T>& v);
+ MEDCOUPLING_EXPORT std::vector< MCAuto< typename Traits<T>::ArrayTypeCh > > explodeComponents() const;
//
std::size_t getHeapMemorySizeWithoutChildren() const;
//
return ret;
}
+ template<class T>
+ std::vector< MCAuto< typename Traits<T>::ArrayTypeCh > > DataArrayTemplate<T>::explodeComponents() const
+ {
+ checkAllocated();
+ std::size_t sz(getNumberOfComponents());
+ int nbTuples(getNumberOfTuples());
+ std::string name(getName());
+ std::vector<std::string> compNames(getInfoOnComponents());
+ std::vector< MCAuto< typename Traits<T>::ArrayTypeCh > > ret(sz);
+ const T *thisPt(begin());
+ for(std::size_t i=0;i<sz;i++)
+ {
+ MCAuto< typename Traits<T>::ArrayTypeCh > part(Traits<T>::ArrayTypeCh::New());
+ part->alloc(nbTuples,1);
+ part->setName(name);
+ part->setInfoOnComponent(0,compNames[i]);
+ T *otherPt(part->getPointer());
+ for(int j=0;j<nbTuples;j++)
+ otherPt[j]=thisPt[sz*j+i];
+ ret[i]=part;
+ }
+ return ret;
+ }
+
template<class T>
std::size_t DataArrayTemplate<T>::getHeapMemorySizeWithoutChildren() const
{
d3Exp=DataArrayInt([3,2,1,6,5,4],2,3) ; d3Exp.setInfoOnComponents(["c","b","a"])
self.assertTrue(d3Exp.isEqual(d2))
pass
+
+ def testDAExplodeComponents1(self):
+ d=DataArrayDouble([(1,2),(3,4),(5,6)])
+ d.setName("toto")
+ d.setInfoOnComponents(["a","b"])
+ d2=d.explodeComponents()
+ self.assertEqual(len(d2),2)
+ #
+ d3=DataArrayDouble([1,3,5]) ; d3.setName("toto") ; d3.setInfoOnComponents(["a"])
+ self.assertTrue(d3.isEqual(d2[0],1e-14))
+ d4=DataArrayDouble([2,4,6]) ; d4.setName("toto") ; d4.setInfoOnComponents(["b"])
+ self.assertTrue(d4.isEqual(d2[1],1e-14))
+ #
+ d=DataArrayInt([(1,2),(3,4),(5,6)])
+ d.setName("toto")
+ d.setInfoOnComponents(["a","b"])
+ d2=d.explodeComponents()
+ self.assertEqual(len(d2),2)
+ #
+ d3=DataArrayInt([1,3,5]) ; d3.setName("toto") ; d3.setInfoOnComponents(["a"])
+ self.assertTrue(d3.isEqual(d2[0]))
+ d4=DataArrayInt([2,4,6]) ; d4.setName("toto") ; d4.setInfoOnComponents(["b"])
+ self.assertTrue(d4.isEqual(d2[1]))
+ pass
pass
convertPyToNewIntArr3(li,tmp);
self->setSelectedComponents(a,tmp);
}
+
+ PyObject *explodeComponents() const throw(INTERP_KERNEL::Exception)
+ {
+ std::vector< MCAuto<DataArrayDouble> > retCpp(self->explodeComponents());
+ std::size_t sz(retCpp.size());
+ PyObject *res(PyList_New(sz));
+ for(std::size_t i=0;i<sz;i++)
+ PyList_SetItem(res,i,SWIG_NewPointerObj(SWIG_as_voidptr(retCpp[i].retn()),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
+ return res;
+ }
PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception)
{
self->setSelectedComponents(a,tmp);
}
+ PyObject *explodeComponents() const throw(INTERP_KERNEL::Exception)
+ {
+ std::vector< MCAuto<DataArrayInt> > retCpp(self->explodeComponents());
+ std::size_t sz(retCpp.size());
+ PyObject *res(PyList_New(sz));
+ for(std::size_t i=0;i<sz;i++)
+ PyList_SetItem(res,i,SWIG_NewPointerObj(SWIG_as_voidptr(retCpp[i].retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ return res;
+ }
+
PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception)
{
int sz=self->getNumberOfComponents();