alloc(nbOfTuple,nbOfCompo);
}
-void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo)
+void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
{
+ if(nbOfTuple<0 || nbOfCompo<0)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::alloc : request for negative length of data !");
_nb_of_tuples=nbOfTuple;
_info_on_compo.resize(nbOfCompo);
_mem.alloc(nbOfCompo*_nb_of_tuples);
declareAsNew();
}
+/*!
+ * This method returns a newly allocated array containing the application of negate on \b this.
+ * This method throws an INTERP_KERNEL::Exception if \b this is not allocated.
+ */
+DataArrayDouble *DataArrayDouble::negate() const throw(INTERP_KERNEL::Exception)
+{
+ checkAllocated();
+ DataArrayDouble *newArr=DataArrayDouble::New();
+ int nbOfTuples=getNumberOfTuples();
+ int nbOfComp=getNumberOfComponents();
+ newArr->alloc(nbOfTuples,nbOfComp);
+ const double *cptr=getConstPointer();
+ std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<double>());
+ newArr->copyStringInfoFrom(*this);
+ return newArr;
+}
+
DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, FunctionToEvaluate func) const throw(INTERP_KERNEL::Exception)
{
checkAllocated();
alloc(nbOfTuple,nbOfCompo);
}
-void DataArrayInt::alloc(int nbOfTuple, int nbOfCompo)
+void DataArrayInt::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
{
+ if(nbOfTuple<0 || nbOfCompo<0)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::alloc : request for negative length of data !");
_nb_of_tuples=nbOfTuple;
_info_on_compo.resize(nbOfCompo);
_mem.alloc(nbOfCompo*_nb_of_tuples);
declareAsNew();
}
+/*!
+ * This method returns a newly allocated array containing the application of negate on \b this.
+ * This method throws an INTERP_KERNEL::Exception if \b this is not allocated.
+ */
+DataArrayInt *DataArrayInt::negate() const throw(INTERP_KERNEL::Exception)
+{
+ checkAllocated();
+ DataArrayInt *newArr=DataArrayInt::New();
+ int nbOfTuples=getNumberOfTuples();
+ int nbOfComp=getNumberOfComponents();
+ newArr->alloc(nbOfTuples,nbOfComp);
+ const int *cptr=getConstPointer();
+ std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<int>());
+ newArr->copyStringInfoFrom(*this);
+ return newArr;
+}
+
/*!
* This method applies the operation 'numerator/x' for each element 'x' in 'this'.
* If there is a value in 'this' exactly equal to 0. an exception is thrown.
T *toNoInterlace(int nbOfComp) const;
void sort();
void reverse();
- void alloc(int nbOfElements);
- void reAlloc(int newNbOfElements);
+ void alloc(int nbOfElements) throw(INTERP_KERNEL::Exception);
+ void reAlloc(int newNbOfElements) throw(INTERP_KERNEL::Exception);
void useArray(const T *array, bool ownership, DeallocType type, int nbOfElem);
void writeOnPlace(int id, T element0, const T *others, int sizeOfOthers);
~MemArray() { destroy(); }
MEDCOUPLING_EXPORT DataArrayDouble *deepCpy() const;
MEDCOUPLING_EXPORT DataArrayDouble *performCpy(bool deepCpy) const;
MEDCOUPLING_EXPORT void cpyFrom(const DataArrayDouble& other) throw(INTERP_KERNEL::Exception);
- MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo);
+ MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void allocIfNecessary(int nbOfTuple, int nbOfCompo);
MEDCOUPLING_EXPORT void fillWithZero() throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void fillWithValue(double val) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void applyLin(double a, double b) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void applyInv(double numerator) throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT DataArrayDouble *negate() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayDouble *applyFunc(int nbOfComp, FunctionToEvaluate func) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayDouble *applyFunc(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayDouble *applyFunc(const char *func) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *deepCpy() const;
MEDCOUPLING_EXPORT DataArrayInt *performCpy(bool deepCpy) const;
MEDCOUPLING_EXPORT void cpyFrom(const DataArrayInt& other) throw(INTERP_KERNEL::Exception);
- MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo);
+ MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void allocIfNecessary(int nbOfTuple, int nbOfCompo);
MEDCOUPLING_EXPORT bool isEqual(const DataArrayInt& other) const;
MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayInt& other) const;
MEDCOUPLING_EXPORT void applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void applyLin(int a, int b) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void applyInv(int numerator) throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT DataArrayInt *negate() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void applyDivideBy(int val) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void applyModulus(int val) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void applyRModulus(int val) throw(INTERP_KERNEL::Exception);
}
template<class T>
- void MemArray<T>::alloc(int nbOfElements)
+ void MemArray<T>::alloc(int nbOfElements) throw(INTERP_KERNEL::Exception)
{
destroy();
+ if(nbOfElements<0)
+ throw INTERP_KERNEL::Exception("MemArray::alloc : request for negative length of data !");
_nb_of_elem=nbOfElements;
_pointer.setInternal(new T[_nb_of_elem]);
_ownership=true;
}
template<class T>
- void MemArray<T>::reAlloc(int newNbOfElements)
+ void MemArray<T>::reAlloc(int newNbOfElements) throw(INTERP_KERNEL::Exception)
{
+ if(newNbOfElements<0)
+ throw INTERP_KERNEL::Exception("MemArray::reAlloc : request for negative length of data !");
T *pointer=new T[newNbOfElements];
std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min<int>(_nb_of_elem,newNbOfElements),pointer);
if(_ownership)
%newobject ParaMEDMEM::DataArrayInt::getIdsNotEqual;
%newobject ParaMEDMEM::DataArrayInt::getIdsEqualList;
%newobject ParaMEDMEM::DataArrayInt::getIdsNotEqualList;
+%newobject ParaMEDMEM::DataArrayInt::negate;
%newobject ParaMEDMEM::DataArrayInt::Aggregate;
%newobject ParaMEDMEM::DataArrayInt::Meld;
%newobject ParaMEDMEM::DataArrayInt::Add;
%newobject ParaMEDMEM::DataArrayInt::buildPermutationArr;
%newobject ParaMEDMEM::DataArrayInt::buildPermArrPerLevel;
%newobject ParaMEDMEM::DataArrayInt::__getitem__;
+%newobject ParaMEDMEM::DataArrayInt::__neg__;
%newobject ParaMEDMEM::DataArrayInt::__add__;
%newobject ParaMEDMEM::DataArrayInt::__radd__;
%newobject ParaMEDMEM::DataArrayInt::__sub__;
%newobject ParaMEDMEM::DataArrayDouble::selectByTupleIdSafe;
%newobject ParaMEDMEM::DataArrayDouble::selectByTupleId2;
%newobject ParaMEDMEM::DataArrayDouble::selectByTupleRanges;
+%newobject ParaMEDMEM::DataArrayDouble::negate;
%newobject ParaMEDMEM::DataArrayDouble::applyFunc;
%newobject ParaMEDMEM::DataArrayDouble::applyFunc2;
%newobject ParaMEDMEM::DataArrayDouble::applyFunc3;
%newobject ParaMEDMEM::DataArrayDouble::fromSpherToCart;
%newobject ParaMEDMEM::DataArrayDouble::getDifferentValues;
%newobject ParaMEDMEM::DataArrayDouble::__getitem__;
+%newobject ParaMEDMEM::DataArrayDouble::__neg__;
%newobject ParaMEDMEM::DataArrayDouble::__add__;
%newobject ParaMEDMEM::DataArrayDouble::__radd__;
%newobject ParaMEDMEM::DataArrayDouble::__sub__;
%extend ParaMEDMEM::DataArrayDouble
{
+ static DataArrayDouble *New(int nbOfTuples, int nbOfComp) throw(INTERP_KERNEL::Exception)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
+ ret->alloc(nbOfTuples,nbOfComp);
+ ret->incrRef();
+ return ret;
+ }
+
+ static DataArrayDouble *New(PyObject *li, int nbOfTuples, int nbOfComp) throw(INTERP_KERNEL::Exception)
+ {
+ if(nbOfTuples<0 || nbOfComp<0)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::New(PyList,nbOfTuples,nbOfComponents) : should be a positive set of allocated memory !");
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
+ double *tmp=new double[nbOfTuples*nbOfComp];
+ try
+ {
+ fillArrayWithPyListDbl(li,tmp,nbOfTuples*nbOfComp,0.);
+ }
+ catch(INTERP_KERNEL::Exception& e)
+ {
+ delete [] tmp;
+ throw e;
+ }
+ ret->useArray(tmp,true,CPP_DEALLOC,nbOfTuples,nbOfComp);
+ ret->incrRef();
+ return ret;
+ }
+
std::string __str__() const
{
return self->repr();
return self;
}
+ DataArrayDouble *__neg__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->negate();
+ }
+
DataArrayDouble *__add__(PyObject *obj) throw(INTERP_KERNEL::Exception)
{
const char msg[]="Unexpected situation in __add__ !";
%extend ParaMEDMEM::DataArrayInt
{
+ static DataArrayInt *New(int nbOfTuples, int nbOfComp) throw(INTERP_KERNEL::Exception)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
+ ret->alloc(nbOfTuples,nbOfComp);
+ ret->incrRef();
+ return ret;
+ }
+
+ static DataArrayInt *New(PyObject *li, int nbOfTuples, int nbOfComp) throw(INTERP_KERNEL::Exception)
+ {
+ if(nbOfTuples<0 || nbOfComp<0)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::New(PyList,nbOfTuples,nbOfComponents) : should be a positive set of allocated memory !");
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
+ int *tmp=new int[nbOfTuples*nbOfComp];
+ try
+ {
+ fillArrayWithPyListInt(li,tmp,nbOfTuples*nbOfComp,0);
+ }
+ catch(INTERP_KERNEL::Exception& e)
+ {
+ delete [] tmp;
+ throw e;
+ }
+ ret->useArray(tmp,true,CPP_DEALLOC,nbOfTuples,nbOfComp);
+ ret->incrRef();
+ return ret;
+ }
+
std::string __str__() const
{
return self->repr();
return self;
}
+ DataArrayInt *__neg__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->negate();
+ }
+
DataArrayInt *__add__(PyObject *obj) throw(INTERP_KERNEL::Exception)
{
const char msg[]="Unexpected situation in __add__ !";