template class MEDCoupling::DataArrayTemplateClassic<double>;
template class MEDCoupling::DataArrayTemplateFP<double>;
template class MEDCoupling::DataArrayIterator<double>;
+template class MEDCoupling::DataArrayIterator<int>;
template<int SPACEDIM>
void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const
double DataArrayDoubleTuple::doubleValue() const
{
- if(_nb_of_compo==1)
- return *_pt;
- throw INTERP_KERNEL::Exception("DataArrayDoubleTuple::doubleValue : DataArrayDoubleTuple instance has not exactly 1 component -> Not possible to convert it into a double precision float !");
+ return this->zeValue();
}
/*!
*/
DataArrayDouble *DataArrayDoubleTuple::buildDADouble(int nbOfTuples, int nbOfCompo) const
{
- if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
- {
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
- return ret;
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayDoubleTuple::buildDADouble : unable to build a requested DataArrayDouble instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
- oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
+ return this->buildDA(nbOfTuples,nbOfCompo);
}
/*!
int DataArrayIntTuple::intValue() const
{
- if(_nb_of_compo==1)
- return *_pt;
- throw INTERP_KERNEL::Exception("DataArrayIntTuple::intValue : DataArrayIntTuple instance has not exactly 1 component -> Not possible to convert it into an integer !");
+ return this->zeValue();
}
/*!
*/
DataArrayInt *DataArrayIntTuple::buildDAInt(int nbOfTuples, int nbOfCompo) const
{
- if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
- {
- DataArrayInt *ret=DataArrayInt::New();
- ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
- return ret;
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayIntTuple::buildDAInt : unable to build a requested DataArrayInt instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
- oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
+ return this->buildDA(nbOfTuples,nbOfCompo);
}
namespace MEDCoupling
{
+ class DataArrayFloatIterator;
class DataArrayFloat : public DataArrayTemplateFP<float>
{
public:
MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const;
MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const;
MEDCOUPLING_EXPORT DataArrayFloat *performCopyOrIncrRef(bool deepCopy) const;
+ public:
+ MEDCOUPLING_EXPORT DataArrayFloatIterator *iterator();
private:
~DataArrayFloat() { }
DataArrayFloat() { }
MEDCOUPLING_EXPORT int getNumberOfCompo() const { return _nb_of_compo; }
MEDCOUPLING_EXPORT const T *getConstPointer() const { return _pt; }
MEDCOUPLING_EXPORT T *getPointer() { return _pt; }
+ MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *buildDA(int nbOfTuples, int nbOfCompo) const;
+ protected:
+ T zeValue() const;
protected:
T *_pt;
int _nb_of_compo;
MEDCOUPLING_EXPORT double doubleValue() const;
MEDCOUPLING_EXPORT DataArrayDouble *buildDADouble(int nbOfTuples, int nbOfCompo) const;
};
+
+ class DataArrayFloatTuple;
+
+ class DataArrayFloatIterator : public DataArrayIterator<float>
+ {
+ public:
+ MEDCOUPLING_EXPORT DataArrayFloatIterator(DataArrayFloat *da);
+ MEDCOUPLING_EXPORT ~DataArrayFloatIterator() { }
+ };
+
+ class DataArrayFloatTuple : public DataArrayTuple<float>
+ {
+ public:
+ MEDCOUPLING_EXPORT DataArrayFloatTuple(float *pt, int nbOfComp);
+ MEDCOUPLING_EXPORT std::string repr() const;
+ MEDCOUPLING_EXPORT float floatValue() const;
+ MEDCOUPLING_EXPORT DataArrayFloat *buildDAFloat(int nbOfTuples, int nbOfCompo) const;
+ };
class DataArrayIntTuple;
{
}
+ template<class T>
+ T DataArrayTuple<T>::zeValue() const
+ {
+ if(_nb_of_compo==1)
+ return *_pt;
+ throw INTERP_KERNEL::Exception("DataArrayTuple<T>::zeValue : DataArrayTuple instance has not exactly 1 component -> Not possible to convert it into a single value !");
+ }
+
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayTuple<T>::buildDA(int nbOfTuples, int nbOfCompo) const
+ {
+ if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
+ {
+ typename Traits<T>::ArrayType *ret=Traits<T>::ArrayType::New();
+ ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
+ return ret;
+ }
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayTuple<T>::buildDA : unable to build a requested DataArrayDouble instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
+ oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+
//////////////////////////////////
template<class T>
template class MEDCoupling::DataArrayTemplate<float>;
template class MEDCoupling::DataArrayTemplateClassic<float>;
template class MEDCoupling::DataArrayTemplateFP<float>;
+template class MEDCoupling::DataArrayIterator<float>;
DataArrayFloat *DataArrayFloat::New()
{
{
return DataArrayTemplateClassic<float>::PerformCopyOrIncrRef(dCpy,*this);
}
+
+DataArrayFloatIterator *DataArrayFloat::iterator()
+{
+ return new DataArrayFloatIterator(this);
+}
+
+DataArrayFloatIterator::DataArrayFloatIterator(DataArrayFloat *da):DataArrayIterator<float>(da)
+{
+}
+
+DataArrayFloatTuple::DataArrayFloatTuple(float *pt, int nbOfComp):DataArrayTuple<float>(pt,nbOfComp)
+{
+}
+
+std::string DataArrayFloatTuple::repr() const
+{
+ std::ostringstream oss; oss.precision(7); oss << "(";
+ for(int i=0;i<_nb_of_compo-1;i++)
+ oss << _pt[i] << ", ";
+ oss << _pt[_nb_of_compo-1] << ")";
+ return oss.str();
+}
+
+float DataArrayFloatTuple::floatValue() const
+{
+ return this->zeValue();
+}
+
+/*!
+ * This method returns a newly allocated instance the caller should dealed with by a MEDCoupling::DataArrayFloat::decrRef.
+ * This method performs \b no copy of data. The content is only referenced using MEDCoupling::DataArrayFloat::useArray with ownership set to \b false.
+ * This method throws an INTERP_KERNEL::Exception is it is impossible to match sizes of \b this that is too say \b nbOfCompo=this->_nb_of_elem and \bnbOfTuples==1 or
+ * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem.
+ */
+DataArrayFloat *DataArrayFloatTuple::buildDAFloat(int nbOfTuples, int nbOfCompo) const
+{
+ return this->buildDA(nbOfTuples,nbOfCompo);
+}
class MEDCouplingFieldFloat;
class MEDCouplingFieldInt;
class DataArrayIntTuple;
+ class DataArrayFloatTuple;
class DataArrayDoubleTuple;
template<>
typedef DataArrayFloat ArrayType;
typedef DataArrayFloat ArrayTypeCh;
typedef MEDCouplingFieldFloat FieldType;
+ typedef DataArrayFloatTuple ArrayTuple;
};
template<>
def MEDCouplingDataArrayBytenew(cls,*args):
import _MEDCoupling
return _MEDCoupling.DataArrayByte____new___(cls,args)
+def MEDCouplingDataArrayFloatImul(self,*args):
+ import _MEDCoupling
+ return _MEDCoupling.DataArrayFloat____imul___(self, self, *args)
def MEDCouplingDataArrayDoubleTupleIadd(self,*args):
import _MEDCoupling
return _MEDCoupling.DataArrayDoubleTuple____iadd___(self, self, *args)
{// AGY : here initialization of C++ traits in MEDCouplingDataArrayTypemaps.i for code factorization. Awful, I know, but no other solutions.
SWIGTITraits<double>::TI=SWIGTYPE_p_MEDCoupling__DataArrayDouble;
SWIGTITraits<float>::TI=SWIGTYPE_p_MEDCoupling__DataArrayFloat;
+ SWIGTITraits<int>::TI=SWIGTYPE_p_MEDCoupling__DataArrayInt;
SWIGTITraits<double>::TI_TUPLE=SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple;
+ SWIGTITraits<float>::TI_TUPLE=SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple;
SWIGTITraits<int>::TI_TUPLE=SWIGTYPE_p_MEDCoupling__DataArrayIntTuple;
}
%}
sw=3;
}
-/*!
- * if value int -> cpp val sw=1
- * if value double -> cpp val sw=1
- * if value DataArrayDouble -> cpp DataArrayDouble sw=2
- * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
- * if value list[int,double] -> cpp std::vector<double> sw=4
- * if value tuple[int,double] -> cpp std::vector<double> sw=4
- */
-static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
+template<class T>
+void convertFPStarLikePyObjToCpp_2(PyObject *value, int& sw, T& val, typename MEDCoupling::Traits<T>::ArrayType *&d, typename MEDCoupling::Traits<T>::ArrayTuple *&e, std::vector<T>& f, swig_type_info *ti_da, swig_type_info *ti_tuple)
{
sw=-1;
if(PyFloat_Check(value))
}
if(PyInt_Check(value))
{
- val=(double)PyInt_AS_LONG(value);
+ val=(T)PyInt_AS_LONG(value);
sw=1;
return;
}
if(PyFloat_Check(o))
f[i]=PyFloat_AS_DOUBLE(o);
else if(PyInt_Check(o))
- f[i]=(double)PyInt_AS_LONG(o);
+ f[i]=(T)PyInt_AS_LONG(o);
else
{
std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
if(PyFloat_Check(o))
f[i]=PyFloat_AS_DOUBLE(o);
else if(PyInt_Check(o))
- f[i]=(double)PyInt_AS_LONG(o);
+ f[i]=(T)PyInt_AS_LONG(o);
else
{
std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
return;
}
void *argp;
- int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
+ int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0);
if(SWIG_IsOK(status))
{
- d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
+ d=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
sw=2;
return ;
}
- status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
+ status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0);
if(SWIG_IsOK(status))
{
- e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
+ e=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayTuple * >(argp);
sw=3;
return ;
}
throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
}
+/*!
+ * if value int -> cpp val sw=1
+ * if value double -> cpp val sw=1
+ * if value DataArrayDouble -> cpp DataArrayDouble sw=2
+ * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
+ * if value list[int,double] -> cpp std::vector<double> sw=4
+ * if value tuple[int,double] -> cpp std::vector<double> sw=4
+ */
+static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
+{
+ convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
+}
+
/*!
* if python int -> cpp int sw=1
* if python list[int] -> cpp vector<int> sw=2
}
}
+template<class T>
+PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
+{
+ const char msg[]="Unexpected situation in __imul__ !";
+ T val;
+ typename MEDCoupling::Traits<T>::ArrayType *a;
+ typename MEDCoupling::Traits<T>::ArrayTuple *aa;
+ std::vector<T> bb;
+ int sw;
+ convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
+ convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
+ switch(sw)
+ {
+ case 1:
+ {
+ self->applyLin(val,0.);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 2:
+ {
+ self->multiplyEqual(a);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 3:
+ {
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
+ self->multiplyEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ case 4:
+ {
+ MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
+ self->multiplyEqual(aaa);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+}
+
template<class T>
struct SWIGTITraits
{ };
return DataArrayT__getitem__internal<T>(self,obj,SWIGTITraits<T>::TI);
}
+template<class T>
+PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
+{
+ return DataArrayT_imul__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
+}
+
#endif
DataArrayByte.__new__=classmethod(MEDCouplingDataArrayBytenew)
+DataArrayFloat.__imul__=MEDCouplingDataArrayFloatImul
+
MEDCouplingFieldDouble.__iadd__=MEDCouplingFieldDoubleIadd
MEDCouplingFieldDouble.__isub__=MEDCouplingFieldDoubleIsub
MEDCouplingFieldDouble.__imul__=MEDCouplingFieldDoubleImul
%newobject MEDCoupling::DataArray::selectByTupleIdSafeSlice;
%newobject MEDCoupling::DataArray::Aggregate;
%newobject MEDCoupling::DataArrayFloat::New;
+%newobject MEDCoupling::DataArrayFloat::iterator;
+%newobject MEDCoupling::DataArrayFloat::__iter__;
%newobject MEDCoupling::DataArrayInt::New;
%newobject MEDCoupling::DataArrayInt::__iter__;
%newobject MEDCoupling::DataArrayInt::selectPartDef;
bool isUniform(float val, float eps) const throw(INTERP_KERNEL::Exception);
void pushBackSilent(float val) throw(INTERP_KERNEL::Exception);
void iota(float init=0.) throw(INTERP_KERNEL::Exception);
+ DataArrayFloatIterator *iterator() throw(INTERP_KERNEL::Exception);
%extend
{
DataArrayFloat() throw(INTERP_KERNEL::Exception)
{
return MEDCoupling_DataArrayFloat_New__SWIG_1(elt0,nbOfTuples,elt2);
}
+
+ DataArrayFloatIterator *__iter__() throw(INTERP_KERNEL::Exception)
+ {
+ return self->iterator();
+ }
std::string __repr__() const throw(INTERP_KERNEL::Exception)
{
{
return DataArrayT__setitem__<float>(self,obj,value);
}
+
+ PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayT_imul<float>(trueSelf,obj,self);
+ }
#ifdef WITH_NUMPY
PyObject *toNumPyArray() throw(INTERP_KERNEL::Exception) // not const. It is not a bug !
}
};
+
+ class DataArrayFloatTuple;
+
+ class DataArrayFloatIterator
+ {
+ public:
+ DataArrayFloatIterator(DataArrayFloat *da);
+ ~DataArrayFloatIterator();
+ %extend
+ {
+ PyObject *next()
+ {
+ DataArrayFloatTuple *ret=self->nextt();
+ if(ret)
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple,SWIG_POINTER_OWN|0);
+ else
+ {
+ PyErr_SetString(PyExc_StopIteration,"No more data.");
+ return 0;
+ }
+ }
+ }
+ };
+
+ class DataArrayFloatTuple
+ {
+ public:
+ int getNumberOfCompo() const throw(INTERP_KERNEL::Exception);
+ DataArrayFloat *buildDAFloat(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception);
+ %extend
+ {
+ std::string __str__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->repr();
+ }
+
+ float __float__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->floatValue();
+ }
+
+ DataArrayFloat *buildDAFloat() throw(INTERP_KERNEL::Exception)
+ {
+ return self->buildDAFloat(1,self->getNumberOfCompo());
+ }
+
+ /*PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ MCAuto<DataArrayFloat> ret=self->buildDAFloat(1,self->getNumberOfCompo());
+ MEDCoupling_DataArrayFloat____imul___(ret,0,obj);
+ Py_XINCREF(trueSelf);
+ return trueSelf;
+ }*/
+
+ PyObject *__len__() throw(INTERP_KERNEL::Exception)
+ {
+ return PyInt_FromLong(self->getNumberOfCompo());
+ }
+ }
+ };
class DataArrayInt;
class DataArrayDoubleIterator;
PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
{
- const char msg[]="Unexpected situation in __imul__ !";
- double val;
- DataArrayDouble *a;
- DataArrayDoubleTuple *aa;
- std::vector<double> bb;
- int sw;
- convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
- switch(sw)
- {
- case 1:
- {
- self->applyLin(val,0.);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 2:
- {
- self->multiplyEqual(a);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 3:
- {
- MCAuto<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
- self->multiplyEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- case 4:
- {
- MCAuto<DataArrayDouble> aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size());
- self->multiplyEqual(aaa);
- Py_XINCREF(trueSelf);
- return trueSelf;
- }
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
+ return DataArrayT_imul<double>(trueSelf,obj,self);
}
PyObject *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception)