- DataArrayInt *c0=0,*cI0=0;
- findCommonTuples(prec,limitTupleId,c0,cI0);
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(c0),cI(cI0);
- int newNbOfTuples=-1;
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(getNumberOfTuples(),c0->begin(),cI0->begin(),cI0->end(),newNbOfTuples);
- return renumberAndReduce(o2n->getConstPointer(),newNbOfTuples);
-}
-
-/*!
- * Copy all components in a specified order from another DataArrayDouble.
- * Both numerical and textual data is copied. The number of tuples in \a this and
- * the other array can be different.
- * \param [in] a - the array to copy data from.
- * \param [in] compoIds - sequence of zero based indices of components, data of which is
- * to be copied.
- * \throw If \a a is NULL.
- * \throw If \a compoIds.size() != \a a->getNumberOfComponents().
- * \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
- *
- * \ref py_mcdataarraydouble_setselectedcomponents "Here is a Python example".
- */
-void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& compoIds)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setSelectedComponents : input DataArrayDouble is NULL !");
- checkAllocated();
- copyPartOfStringInfoFrom2(compoIds,*a);
- std::size_t partOfCompoSz=compoIds.size();
- int nbOfCompo=getNumberOfComponents();
- int nbOfTuples=std::min(getNumberOfTuples(),a->getNumberOfTuples());
- const double *ac=a->getConstPointer();
- double *nc=getPointer();
- for(int i=0;i<nbOfTuples;i++)
- for(std::size_t j=0;j<partOfCompoSz;j++,ac++)
- nc[nbOfCompo*i+compoIds[j]]=*ac;
-}
-
-/*!
- * Copy all values from another DataArrayDouble into specified tuples and components
- * of \a this array. Textual data is not copied.
- * The tree parameters defining set of indices of tuples and components are similar to
- * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
- * \param [in] a - the array to copy values from.
- * \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
- * \param [in] endTuples - index of the tuple before which the tuples to assign to
- * are located.
- * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
- * \param [in] bgComp - index of the first component of \a this array to assign values to.
- * \param [in] endComp - index of the component before which the components to assign
- * to are located.
- * \param [in] stepComp - index increment to get index of the next component to assign to.
- * \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents()
- * must be equal to the number of columns to assign to, else an
- * exception is thrown; if \a false, then it is only required that \a
- * a->getNbOfElems() equals to number of values to assign to (this condition
- * must be respected even if \a strictCompoCompare is \a true). The number of
- * values to assign to is given by following Python expression:
- * \a nbTargetValues =
- * \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
- * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a this is not allocated.
- * \throw If parameters specifying tuples and components to assign to do not give a
- * non-empty range of increasing indices.
- * \throw If \a a->getNbOfElems() != \a nbTargetValues.
- * \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
- * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
- *
- * \ref py_mcdataarraydouble_setpartofvalues1 "Here is a Python example".
- */
-void DataArrayDouble::setPartOfValues1(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues1 : input DataArrayDouble is NULL !");
- const char msg[]="DataArrayDouble::setPartOfValues1";
- checkAllocated();
- a->checkAllocated();
- int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
- int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
- DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
- bool assignTech=true;
- if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
- {
- if(strictCompoCompare)
- a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
- }
- else
- {
- a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
- assignTech=false;
- }
- const double *srcPt=a->getConstPointer();
- double *pt=getPointer()+bgTuples*nbComp+bgComp;
- if(assignTech)
- {
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- for(int j=0;j<newNbOfComp;j++,srcPt++)
- pt[j*stepComp]=*srcPt;
- }
- else
- {
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- {
- const double *srcPt2=srcPt;
- for(int j=0;j<newNbOfComp;j++,srcPt2++)
- pt[j*stepComp]=*srcPt2;
- }
- }
-}
-
-/*!
- * Assign a given value to values at specified tuples and components of \a this array.
- * The tree parameters defining set of indices of tuples and components are similar to
- * the tree parameters of the Python function \c range(\c start,\c stop,\c step)..
- * \param [in] a - the value to assign.
- * \param [in] bgTuples - index of the first tuple of \a this array to assign to.
- * \param [in] endTuples - index of the tuple before which the tuples to assign to
- * are located.
- * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
- * \param [in] bgComp - index of the first component of \a this array to assign to.
- * \param [in] endComp - index of the component before which the components to assign
- * to are located.
- * \param [in] stepComp - index increment to get index of the next component to assign to.
- * \throw If \a this is not allocated.
- * \throw If parameters specifying tuples and components to assign to, do not give a
- * non-empty range of increasing indices or indices are out of a valid range
- * for \this array.
- *
- * \ref py_mcdataarraydouble_setpartofvaluessimple1 "Here is a Python example".
- */
-void DataArrayDouble::setPartOfValuesSimple1(double a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp)
-{
- const char msg[]="DataArrayDouble::setPartOfValuesSimple1";
- checkAllocated();
- int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
- int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
- DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
- double *pt=getPointer()+bgTuples*nbComp+bgComp;
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- for(int j=0;j<newNbOfComp;j++)
- pt[j*stepComp]=a;
-}
-
-/*!
- * Copy all values from another DataArrayDouble (\a a) into specified tuples and
- * components of \a this array. Textual data is not copied.
- * The tuples and components to assign to are defined by C arrays of indices.
- * There are two *modes of usage*:
- * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
- * of \a a is assigned to its own location within \a this array.
- * - If \a a includes one tuple, then all values of \a a are assigned to the specified
- * components of every specified tuple of \a this array. In this mode it is required
- * that \a a->getNumberOfComponents() equals to the number of specified components.
- *
- * \param [in] a - the array to copy values from.
- * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
- * assign values of \a a to.
- * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
- * pointer to a tuple index <em>(pi)</em> varies as this:
- * \a bgTuples <= \a pi < \a endTuples.
- * \param [in] bgComp - pointer to an array of component indices of \a this array to
- * assign values of \a a to.
- * \param [in] endComp - specifies the end of the array \a bgTuples, so that
- * pointer to a component index <em>(pi)</em> varies as this:
- * \a bgComp <= \a pi < \a endComp.
- * \param [in] strictCompoCompare - this parameter is checked only if the
- * *mode of usage* is the first; if it is \a true (default),
- * then \a a->getNumberOfComponents() must be equal
- * to the number of specified columns, else this is not required.
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a this is not allocated.
- * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
- * out of a valid range for \a this array.
- * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
- * if <em> a->getNumberOfComponents() != (endComp - bgComp) </em>.
- * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
- * <em> a->getNumberOfComponents() != (endComp - bgComp)</em>.
- *
- * \ref py_mcdataarraydouble_setpartofvalues2 "Here is a Python example".
- */
-void DataArrayDouble::setPartOfValues2(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues2 : input DataArrayDouble is NULL !");
- const char msg[]="DataArrayDouble::setPartOfValues2";
- checkAllocated();
- a->checkAllocated();
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- for(const int *z=bgComp;z!=endComp;z++)
- DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
- int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
- int newNbOfComp=(int)std::distance(bgComp,endComp);
- bool assignTech=true;
- if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
- {
- if(strictCompoCompare)
- a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
- }
- else
- {
- a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
- assignTech=false;
- }
- double *pt=getPointer();
- const double *srcPt=a->getConstPointer();
- if(assignTech)
- {
- for(const int *w=bgTuples;w!=endTuples;w++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- for(const int *z=bgComp;z!=endComp;z++,srcPt++)
- {
- pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt;
- }
- }
- }
- else
- {
- for(const int *w=bgTuples;w!=endTuples;w++)
- {
- const double *srcPt2=srcPt;
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
- {
- pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt2;
- }
- }
- }
-}
-
-/*!
- * Assign a given value to values at specified tuples and components of \a this array.
- * The tuples and components to assign to are defined by C arrays of indices.
- * \param [in] a - the value to assign.
- * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
- * assign \a a to.
- * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
- * pointer to a tuple index (\a pi) varies as this:
- * \a bgTuples <= \a pi < \a endTuples.
- * \param [in] bgComp - pointer to an array of component indices of \a this array to
- * assign \a a to.
- * \param [in] endComp - specifies the end of the array \a bgTuples, so that
- * pointer to a component index (\a pi) varies as this:
- * \a bgComp <= \a pi < \a endComp.
- * \throw If \a this is not allocated.
- * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
- * out of a valid range for \a this array.
- *
- * \ref py_mcdataarraydouble_setpartofvaluessimple2 "Here is a Python example".
- */
-void DataArrayDouble::setPartOfValuesSimple2(double a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp)
-{
- checkAllocated();
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- for(const int *z=bgComp;z!=endComp;z++)
- DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
- double *pt=getPointer();
- for(const int *w=bgTuples;w!=endTuples;w++)
- for(const int *z=bgComp;z!=endComp;z++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- pt[(std::size_t)(*w)*nbComp+(*z)]=a;
- }
-}
-
-/*!
- * Copy all values from another DataArrayDouble (\a a) into specified tuples and
- * components of \a this array. Textual data is not copied.
- * The tuples to assign to are defined by a C array of indices.
- * The components to assign to are defined by three values similar to parameters of
- * the Python function \c range(\c start,\c stop,\c step).
- * There are two *modes of usage*:
- * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
- * of \a a is assigned to its own location within \a this array.
- * - If \a a includes one tuple, then all values of \a a are assigned to the specified
- * components of every specified tuple of \a this array. In this mode it is required
- * that \a a->getNumberOfComponents() equals to the number of specified components.
- *
- * \param [in] a - the array to copy values from.
- * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
- * assign values of \a a to.
- * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
- * pointer to a tuple index <em>(pi)</em> varies as this:
- * \a bgTuples <= \a pi < \a endTuples.
- * \param [in] bgComp - index of the first component of \a this array to assign to.
- * \param [in] endComp - index of the component before which the components to assign
- * to are located.
- * \param [in] stepComp - index increment to get index of the next component to assign to.
- * \param [in] strictCompoCompare - this parameter is checked only in the first
- * *mode of usage*; if \a strictCompoCompare is \a true (default),
- * then \a a->getNumberOfComponents() must be equal
- * to the number of specified columns, else this is not required.
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a this is not allocated.
- * \throw If any index of tuple given by \a bgTuples is out of a valid range for
- * \a this array.
- * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
- * if <em> a->getNumberOfComponents()</em> is unequal to the number of components
- * defined by <em>(bgComp,endComp,stepComp)</em>.
- * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
- * <em> a->getNumberOfComponents()</em> is unequal to the number of components
- * defined by <em>(bgComp,endComp,stepComp)</em>.
- * \throw If parameters specifying components to assign to, do not give a
- * non-empty range of increasing indices or indices are out of a valid range
- * for \this array.
- *
- * \ref py_mcdataarraydouble_setpartofvalues3 "Here is a Python example".
- */
-void DataArrayDouble::setPartOfValues3(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues3 : input DataArrayDouble is NULL !");
- const char msg[]="DataArrayDouble::setPartOfValues3";
- checkAllocated();
- a->checkAllocated();
- int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
- int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
- bool assignTech=true;
- if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
- {
- if(strictCompoCompare)
- a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
- }
- else
- {
- a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
- assignTech=false;
- }
- double *pt=getPointer()+bgComp;
- const double *srcPt=a->getConstPointer();
- if(assignTech)
- {
- for(const int *w=bgTuples;w!=endTuples;w++)
- for(int j=0;j<newNbOfComp;j++,srcPt++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt;
- }
- }
- else
- {
- for(const int *w=bgTuples;w!=endTuples;w++)
- {
- const double *srcPt2=srcPt;
- for(int j=0;j<newNbOfComp;j++,srcPt2++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt2;
- }
- }
- }
-}
-
-/*!
- * Assign a given value to values at specified tuples and components of \a this array.
- * The tuples to assign to are defined by a C array of indices.
- * The components to assign to are defined by three values similar to parameters of
- * the Python function \c range(\c start,\c stop,\c step).
- * \param [in] a - the value to assign.
- * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
- * assign \a a to.
- * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
- * pointer to a tuple index <em>(pi)</em> varies as this:
- * \a bgTuples <= \a pi < \a endTuples.
- * \param [in] bgComp - index of the first component of \a this array to assign to.
- * \param [in] endComp - index of the component before which the components to assign
- * to are located.
- * \param [in] stepComp - index increment to get index of the next component to assign to.
- * \throw If \a this is not allocated.
- * \throw If any index of tuple given by \a bgTuples is out of a valid range for
- * \a this array.
- * \throw If parameters specifying components to assign to, do not give a
- * non-empty range of increasing indices or indices are out of a valid range
- * for \this array.
- *
- * \ref py_mcdataarraydouble_setpartofvaluessimple3 "Here is a Python example".
- */
-void DataArrayDouble::setPartOfValuesSimple3(double a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp)
-{
- const char msg[]="DataArrayDouble::setPartOfValuesSimple3";
- checkAllocated();
- int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
- int nbComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
- double *pt=getPointer()+bgComp;
- for(const int *w=bgTuples;w!=endTuples;w++)
- for(int j=0;j<newNbOfComp;j++)
- {
- DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
- pt[(std::size_t)(*w)*nbComp+j*stepComp]=a;
- }
-}
-
-/*!
- * Copy all values from another DataArrayDouble into specified tuples and components
- * of \a this array. Textual data is not copied.
- * The tree parameters defining set of indices of tuples and components are similar to
- * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
- * \param [in] a - the array to copy values from.
- * \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
- * \param [in] endTuples - index of the tuple before which the tuples to assign to
- * are located.
- * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
- * \param [in] bgComp - pointer to an array of component indices of \a this array to
- * assign \a a to.
- * \param [in] endComp - specifies the end of the array \a bgTuples, so that
- * pointer to a component index (\a pi) varies as this:
- * \a bgComp <= \a pi < \a endComp.
- * \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents()
- * must be equal to the number of columns to assign to, else an
- * exception is thrown; if \a false, then it is only required that \a
- * a->getNbOfElems() equals to number of values to assign to (this condition
- * must be respected even if \a strictCompoCompare is \a true). The number of
- * values to assign to is given by following Python expression:
- * \a nbTargetValues =
- * \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
- * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a this is not allocated.
- * \throw If parameters specifying tuples and components to assign to do not give a
- * non-empty range of increasing indices.
- * \throw If \a a->getNbOfElems() != \a nbTargetValues.
- * \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
- * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
- *
- */
-void DataArrayDouble::setPartOfValues4(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare)
-{
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues4 : input DataArrayDouble is NULL !");
- const char msg[]="DataArrayDouble::setPartOfValues4";
- checkAllocated();
- a->checkAllocated();
- int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
- int newNbOfComp=(int)std::distance(bgComp,endComp);
- int nbComp=getNumberOfComponents();
- for(const int *z=bgComp;z!=endComp;z++)
- DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
- bool assignTech=true;
- if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
- {
- if(strictCompoCompare)
- a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
- }
- else
- {
- a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
- assignTech=false;
- }
- const double *srcPt=a->getConstPointer();
- double *pt=getPointer()+bgTuples*nbComp;
- if(assignTech)
- {
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- for(const int *z=bgComp;z!=endComp;z++,srcPt++)
- pt[*z]=*srcPt;
- }
- else
- {
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- {
- const double *srcPt2=srcPt;
- for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
- pt[*z]=*srcPt2;
- }
- }
-}
-
-void DataArrayDouble::setPartOfValuesSimple4(double a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp)
-{
- const char msg[]="DataArrayDouble::setPartOfValuesSimple4";
- checkAllocated();
- int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
- int nbComp=getNumberOfComponents();
- for(const int *z=bgComp;z!=endComp;z++)
- DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
- int nbOfTuples=getNumberOfTuples();
- DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
- double *pt=getPointer()+bgTuples*nbComp;
- for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
- for(const int *z=bgComp;z!=endComp;z++)
- pt[*z]=a;
-}
-
-/*!
- * Copy some tuples from another DataArrayDouble into specified tuples
- * of \a this array. Textual data is not copied. Both arrays must have equal number of
- * components.
- * Both the tuples to assign and the tuples to assign to are defined by a DataArrayInt.
- * All components of selected tuples are copied.
- * \param [in] a - the array to copy values from.
- * \param [in] tuplesSelec - the array specifying both source tuples of \a a and
- * target tuples of \a this. \a tuplesSelec has two components, and the
- * first component specifies index of the source tuple and the second
- * one specifies index of the target tuple.
- * \throw If \a this is not allocated.
- * \throw If \a a is NULL.
- * \throw If \a a is not allocated.
- * \throw If \a tuplesSelec is NULL.
- * \throw If \a tuplesSelec is not allocated.
- * \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
- * \throw If \a tuplesSelec->getNumberOfComponents() != 2.
- * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
- * the corresponding (\a this or \a a) array.
- */
-void DataArrayDouble::setPartOfValuesAdv(const DataArrayDouble *a, const DataArrayInt *tuplesSelec)
-{
- if(!a || !tuplesSelec)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : input DataArrayDouble is NULL !");
- checkAllocated();
- a->checkAllocated();
- tuplesSelec->checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=a->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : This and a do not have the same number of components !");
- if(tuplesSelec->getNumberOfComponents()!=2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
- int thisNt=getNumberOfTuples();
- int aNt=a->getNumberOfTuples();
- double *valsToSet=getPointer();
- const double *valsSrc=a->getConstPointer();
- for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
- {
- if(tuple[1]>=0 && tuple[1]<aNt)
- {
- if(tuple[0]>=0 && tuple[0]<thisNt)
- std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
- oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
- oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
-}
-
-/*!
- * Copy some tuples from another DataArrayDouble (\a aBase) into contiguous tuples
- * of \a this array. Textual data is not copied. Both arrays must have equal number of
- * components.
- * The tuples to assign to are defined by index of the first tuple, and
- * their number is defined by \a tuplesSelec->getNumberOfTuples().
- * The tuples to copy are defined by values of a DataArrayInt.
- * All components of selected tuples are copied.
- * \param [in] tupleIdStart - index of the first tuple of \a this array to assign
- * values to.
- * \param [in] aBase - the array to copy values from.
- * \param [in] tuplesSelec - the array specifying tuples of \a a to copy.
- * \throw If \a this is not allocated.
- * \throw If \a aBase is NULL.
- * \throw If \a aBase is not allocated.
- * \throw If \a tuplesSelec is NULL.
- * \throw If \a tuplesSelec is not allocated.
- * \throw If <em>this->getNumberOfComponents() != aBase->getNumberOfComponents()</em>.
- * \throw If \a tuplesSelec->getNumberOfComponents() != 1.
- * \throw If <em>tupleIdStart + tuplesSelec->getNumberOfTuples() > this->getNumberOfTuples().</em>
- * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
- * \a aBase array.
- */
-void DataArrayDouble::setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt *tuplesSelec)
-{
- if(!aBase || !tuplesSelec)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : input DataArray is NULL !");
- const DataArrayDouble *a=dynamic_cast<const DataArrayDouble *>(aBase);
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : input DataArray aBase is not a DataArrayDouble !");
- checkAllocated();
- a->checkAllocated();
- tuplesSelec->checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=a->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : This and a do not have the same number of components !");
- if(tuplesSelec->getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : Expecting to have a tuple selector DataArrayInt instance with exactly 1 component !");
- int thisNt=getNumberOfTuples();
- int aNt=a->getNumberOfTuples();
- int nbOfTupleToWrite=tuplesSelec->getNumberOfTuples();
- double *valsToSet=getPointer()+tupleIdStart*nbOfComp;
- if(tupleIdStart+nbOfTupleToWrite>thisNt)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : invalid number range of values to write !");
- const double *valsSrc=a->getConstPointer();
- for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple++,valsToSet+=nbOfComp)
- {
- if(*tuple>=0 && *tuple<aNt)
- {
- std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::setContigPartOfSelectedValues : Tuple #" << std::distance(tuplesSelec->begin(),tuple);
- oss << " of 'tuplesSelec' request of tuple id #" << *tuple << " in 'a' ! It should be in [0," << aNt << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
-}
-
-/*!
- * Copy some tuples from another DataArrayDouble (\a aBase) into contiguous tuples
- * of \a this array. Textual data is not copied. Both arrays must have equal number of
- * components.
- * The tuples to copy are defined by three values similar to parameters of
- * the Python function \c range(\c start,\c stop,\c step).
- * The tuples to assign to are defined by index of the first tuple, and
- * their number is defined by number of tuples to copy.
- * All components of selected tuples are copied.
- * \param [in] tupleIdStart - index of the first tuple of \a this array to assign
- * values to.
- * \param [in] aBase - the array to copy values from.
- * \param [in] bg - index of the first tuple to copy of the array \a aBase.
- * \param [in] end2 - index of the tuple of \a aBase before which the tuples to copy
- * are located.
- * \param [in] step - index increment to get index of the next tuple to copy.
- * \throw If \a this is not allocated.
- * \throw If \a aBase is NULL.
- * \throw If \a aBase is not allocated.
- * \throw If <em>this->getNumberOfComponents() != aBase->getNumberOfComponents()</em>.
- * \throw If <em>tupleIdStart + len(range(bg,end2,step)) > this->getNumberOfTuples().</em>
- * \throw If parameters specifying tuples to copy, do not give a
- * non-empty range of increasing indices or indices are out of a valid range
- * for the array \a aBase.
- */
-void DataArrayDouble::setContigPartOfSelectedValues2(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step)
-{
- if(!aBase)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : input DataArray is NULL !");
- const DataArrayDouble *a=dynamic_cast<const DataArrayDouble *>(aBase);
- if(!a)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : input DataArray aBase is not a DataArrayDouble !");
- checkAllocated();
- a->checkAllocated();
- int nbOfComp=getNumberOfComponents();
- const char msg[]="DataArrayDouble::setContigPartOfSelectedValues2";
- int nbOfTupleToWrite=DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg);
- if(nbOfComp!=a->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : This and a do not have the same number of components !");
- int thisNt=getNumberOfTuples();
- int aNt=a->getNumberOfTuples();
- double *valsToSet=getPointer()+tupleIdStart*nbOfComp;
- if(tupleIdStart+nbOfTupleToWrite>thisNt)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : invalid number range of values to write !");
- if(end2>aNt)
- throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : invalid range of values to read !");
- const double *valsSrc=a->getConstPointer()+bg*nbOfComp;
- for(int i=0;i<nbOfTupleToWrite;i++,valsToSet+=nbOfComp,valsSrc+=step*nbOfComp)
- {
- std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
- }
-}
-
-/*!
- * Returns a value located at specified tuple and component.
- * This method is equivalent to DataArrayDouble::getIJ() except that validity of
- * parameters is checked. So this method is safe but expensive if used to go through
- * all values of \a this.
- * \param [in] tupleId - index of tuple of interest.
- * \param [in] compoId - index of component of interest.
- * \return double - value located by \a tupleId and \a compoId.
- * \throw If \a this is not allocated.
- * \throw If condition <em>( 0 <= tupleId < this->getNumberOfTuples() )</em> is violated.
- * \throw If condition <em>( 0 <= compoId < this->getNumberOfComponents() )</em> is violated.
- */
-double DataArrayDouble::getIJSafe(int tupleId, int compoId) const
-{
- checkAllocated();
- if(tupleId<0 || tupleId>=getNumberOfTuples())
- {
- std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- if(compoId<0 || compoId>=getNumberOfComponents())
- {
- std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- return _mem[tupleId*_info_on_compo.size()+compoId];
-}
-
-/*!
- * Returns the first value of \a this.
- * \return double - the last value of \a this array.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If \a this->getNumberOfTuples() < 1.
- */
-double DataArrayDouble::front() const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::front : number of components not equal to one !");
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples<1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::front : number of tuples must be >= 1 !");
- return *(getConstPointer());
-}
-
-/*!
- * Returns the last value of \a this.
- * \return double - the last value of \a this array.
- * \throw If \a this is not allocated.
- * \throw If \a this->getNumberOfComponents() != 1.
- * \throw If \a this->getNumberOfTuples() < 1.
- */
-double DataArrayDouble::back() const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::back : number of components not equal to one !");
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples<1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::back : number of tuples must be >= 1 !");
- return *(getConstPointer()+nbOfTuples-1);
-}
-
-void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet)
-{
- if(newArray!=arrayToSet)
- {
- if(arrayToSet)
- arrayToSet->decrRef();
- arrayToSet=newArray;
- if(arrayToSet)
- arrayToSet->incrRef();
- }
-}
-
-/*!
- * Sets a C array to be used as raw data of \a this. The previously set info
- * of components is retained and re-sized.
- * For more info see \ref MEDCouplingArraySteps1.
- * \param [in] array - the C array to be used as raw data of \a this.
- * \param [in] ownership - if \a true, \a array will be deallocated at destruction of \a this.
- * \param [in] type - specifies how to deallocate \a array. If \a type == ParaMEDMEM::CPP_DEALLOC,
- * \c delete [] \c array; will be called. If \a type == ParaMEDMEM::C_DEALLOC,
- * \c free(\c array ) will be called.
- * \param [in] nbOfTuple - new number of tuples in \a this.
- * \param [in] nbOfCompo - new number of components in \a this.
- */
-void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo)
-{
- _info_on_compo.resize(nbOfCompo);
- _mem.useArray(array,ownership,type,(std::size_t)nbOfTuple*nbOfCompo);
- declareAsNew();
-}
-
-void DataArrayDouble::useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo)
-{
- _info_on_compo.resize(nbOfCompo);
- _mem.useExternalArrayWithRWAccess(array,(std::size_t)nbOfTuple*nbOfCompo);
- declareAsNew();
-}
-
-/*!
- * Checks if 0.0 value is present in \a this array. If it is the case, an exception
- * is thrown.
- * \throw If zero is found in \a this array.
- */
-void DataArrayDouble::checkNoNullValues() const
-{
- const double *tmp=getConstPointer();
- std::size_t nbOfElems=getNbOfElems();
- const double *where=std::find(tmp,tmp+nbOfElems,0.);
- if(where!=tmp+nbOfElems)
- throw INTERP_KERNEL::Exception("A value 0.0 have been detected !");
-}
-
-/*!
- * Computes minimal and maximal value in each component. An output array is filled
- * with \c 2 * \a this->getNumberOfComponents() values, so the caller is to allocate
- * enough memory before calling this method.
- * \param [out] bounds - array of size at least 2 *\a this->getNumberOfComponents().
- * It is filled as follows:<br>
- * \a bounds[0] = \c min_of_component_0 <br>
- * \a bounds[1] = \c max_of_component_0 <br>
- * \a bounds[2] = \c min_of_component_1 <br>
- * \a bounds[3] = \c max_of_component_1 <br>
- * ...
- */
-void DataArrayDouble::getMinMaxPerComponent(double *bounds) const
-{
- checkAllocated();
- int dim=getNumberOfComponents();
- for (int idim=0; idim<dim; idim++)
- {
- bounds[idim*2]=std::numeric_limits<double>::max();
- bounds[idim*2+1]=-std::numeric_limits<double>::max();
- }
- const double *ptr=getConstPointer();
- int nbOfTuples=getNumberOfTuples();
- for(int i=0;i<nbOfTuples;i++)
- {
- for(int idim=0;idim<dim;idim++)
- {
- if(bounds[idim*2]>ptr[i*dim+idim])
- {
- bounds[idim*2]=ptr[i*dim+idim];
- }
- if(bounds[idim*2+1]<ptr[i*dim+idim])
- {
- bounds[idim*2+1]=ptr[i*dim+idim];
- }
- }
- }
-}
-
-/*!
- * This method retrieves a newly allocated DataArrayDouble instance having same number of tuples than \a this and twice number of components than \a this
- * to store both the min and max per component of each tuples.
- * \param [in] epsilon the width of the bbox (identical in each direction) - 0.0 by default
- *
- * \return a newly created DataArrayDouble instance having \c this->getNumberOfTuples() tuples and 2 * \c this->getNumberOfComponent() components
- *
- * \throw If \a this is not allocated yet.
- */
-DataArrayDouble *DataArrayDouble::computeBBoxPerTuple(double epsilon) const
-{
- checkAllocated();
- const double *dataPtr=getConstPointer();
- int nbOfCompo=getNumberOfComponents();
- int nbTuples=getNumberOfTuples();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=DataArrayDouble::New();
- bbox->alloc(nbTuples,2*nbOfCompo);
- double *bboxPtr=bbox->getPointer();
- for(int i=0;i<nbTuples;i++)
- {
- for(int j=0;j<nbOfCompo;j++)
- {
- bboxPtr[2*nbOfCompo*i+2*j]=dataPtr[nbOfCompo*i+j]-epsilon;
- bboxPtr[2*nbOfCompo*i+2*j+1]=dataPtr[nbOfCompo*i+j]+epsilon;
- }
- }
- return bbox.retn();
-}
-
-/*!
- * For each tuples **t** in \a other, this method retrieves tuples in \a this that are equal to **t**.
- * Two tuples are considered equal if the euclidian distance between the two tuples is lower than \a eps.
- *
- * \param [in] other a DataArrayDouble having same number of components than \a this.
- * \param [in] eps absolute precision representing distance (using infinite norm) between 2 tuples behind which 2 tuples are considered equal.
- * \param [out] c will contain the set of tuple ids in \a this that are equal to to the tuple ids in \a other contiguously.
- * \a cI allows to extract information in \a c.
- * \param [out] cI is an indirection array that allows to extract the data contained in \a c.
- *
- * \throw In case of:
- * - \a this is not allocated
- * - \a other is not allocated or null
- * - \a this and \a other do not have the same number of components
- * - if number of components of \a this is not in [1,2,3]
- *
- * \sa MEDCouplingPointSet::getNodeIdsNearPoints, DataArrayDouble::getDifferentValues
- */
-void DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble *other, double eps, DataArrayInt *& c, DataArrayInt *& cI) const
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : input pointer other is null !");
- checkAllocated();
- other->checkAllocated();
- int nbOfCompo=getNumberOfComponents();
- int otherNbOfCompo=other->getNumberOfComponents();
- if(nbOfCompo!=otherNbOfCompo)
- throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : number of components should be equal between this and other !");
- int nbOfTuplesOther=other->getNumberOfTuples();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cArr(DataArrayInt::New()),cIArr(DataArrayInt::New()); cArr->alloc(0,1); cIArr->pushBackSilent(0);
- switch(nbOfCompo)
- {
- case 3:
- {
- BBTreePts<3,int> myTree(begin(),0,0,getNumberOfTuples(),eps);
- FindTupleIdsNearTuplesAlg<3>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
- break;
- }
- case 2:
- {
- BBTreePts<2,int> myTree(begin(),0,0,getNumberOfTuples(),eps);
- FindTupleIdsNearTuplesAlg<2>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
- break;
- }
- case 1:
- {
- BBTreePts<1,int> myTree(begin(),0,0,getNumberOfTuples(),eps);
- FindTupleIdsNearTuplesAlg<1>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
- break;
- }
- default:
- throw INTERP_KERNEL::Exception("Unexpected spacedim of coords for computeTupleIdsNearTuples. Must be 1, 2 or 3.");
- }
- c=cArr.retn(); cI=cIArr.retn();
-}
-
-/*!
- * This method recenter tuples in \b this in order to be centered at the origin to benefit about the advantages of maximal precision to be around the box
- * around origin of 'radius' 1.
- *
- * \param [in] eps absolute epsilon. under that value of delta between max and min no scale is performed.
- */
-void DataArrayDouble::recenterForMaxPrecision(double eps)
-{
- checkAllocated();
- int dim=getNumberOfComponents();
- std::vector<double> bounds(2*dim);
- getMinMaxPerComponent(&bounds[0]);
- for(int i=0;i<dim;i++)
- {
- double delta=bounds[2*i+1]-bounds[2*i];
- double offset=(bounds[2*i]+bounds[2*i+1])/2.;
- if(delta>eps)
- applyLin(1./delta,-offset/delta,i);
- else
- applyLin(1.,-offset,i);
- }
-}
-
-/*!
- * Returns the maximal value and its location within \a this one-dimensional array.
- * \param [out] tupleId - index of the tuple holding the maximal value.
- * \return double - the maximal value among all values of \a this array.
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If \a this->getNumberOfTuples() < 1
- */
-double DataArrayDouble::getMaxValue(int& tupleId) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before or call 'getMaxValueInArray' method !");
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples<=0)
- throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : array exists but number of tuples must be > 0 !");
- const double *vals=getConstPointer();
- const double *loc=std::max_element(vals,vals+nbOfTuples);
- tupleId=(int)std::distance(vals,loc);
- return *loc;
-}
-
-/*!
- * Returns the maximal value within \a this array that is allowed to have more than
- * one component.
- * \return double - the maximal value among all values of \a this array.
- * \throw If \a this is not allocated.
- */
-double DataArrayDouble::getMaxValueInArray() const
-{
- checkAllocated();
- const double *loc=std::max_element(begin(),end());
- return *loc;
-}
-
-/*!
- * Returns the maximal value and all its locations within \a this one-dimensional array.
- * \param [out] tupleIds - a new instance of DataArrayInt containg indices of
- * tuples holding the maximal value. The caller is to delete it using
- * decrRef() as it is no more needed.
- * \return double - the maximal value among all values of \a this array.
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If \a this->getNumberOfTuples() < 1
- */
-double DataArrayDouble::getMaxValue2(DataArrayInt*& tupleIds) const
-{
- int tmp;
- tupleIds=0;
- double ret=getMaxValue(tmp);
- tupleIds=getIdsInRange(ret,ret);
- return ret;
-}
-
-/*!
- * Returns the minimal value and its location within \a this one-dimensional array.
- * \param [out] tupleId - index of the tuple holding the minimal value.
- * \return double - the minimal value among all values of \a this array.
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If \a this->getNumberOfTuples() < 1
- */
-double DataArrayDouble::getMinValue(int& tupleId) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before call 'getMinValueInArray' method !");
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples<=0)
- throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : array exists but number of tuples must be > 0 !");
- const double *vals=getConstPointer();
- const double *loc=std::min_element(vals,vals+nbOfTuples);
- tupleId=(int)std::distance(vals,loc);
- return *loc;
-}
-
-/*!
- * Returns the minimal value within \a this array that is allowed to have more than
- * one component.
- * \return double - the minimal value among all values of \a this array.
- * \throw If \a this is not allocated.
- */
-double DataArrayDouble::getMinValueInArray() const
-{
- checkAllocated();
- const double *loc=std::min_element(begin(),end());
- return *loc;
-}
-
-/*!
- * Returns the minimal value and all its locations within \a this one-dimensional array.
- * \param [out] tupleIds - a new instance of DataArrayInt containg indices of
- * tuples holding the minimal value. The caller is to delete it using
- * decrRef() as it is no more needed.
- * \return double - the minimal value among all values of \a this array.
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If \a this->getNumberOfTuples() < 1
- */
-double DataArrayDouble::getMinValue2(DataArrayInt*& tupleIds) const
-{
- int tmp;
- tupleIds=0;
- double ret=getMinValue(tmp);
- tupleIds=getIdsInRange(ret,ret);
- return ret;
-}
-
-/*!
- * This method returns the number of values in \a this that are equals ( within an absolute precision of \a eps ) to input parameter \a value.
- * This method only works for single component array.
- *
- * \return a value in [ 0, \c this->getNumberOfTuples() )
- *
- * \throw If \a this is not allocated
- *
- */
-int DataArrayDouble::count(double value, double eps) const
-{
- int ret=0;
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::count : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
- const double *vals=begin();
- int nbOfTuples=getNumberOfTuples();
- for(int i=0;i<nbOfTuples;i++,vals++)
- if(fabs(*vals-value)<=eps)
- ret++;
- return ret;
-}
-
-/*!
- * Returns the average value of \a this one-dimensional array.
- * \return double - the average value over all values of \a this array.
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If \a this->getNumberOfTuples() < 1
- */
-double DataArrayDouble::getAverageValue() const
-{
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
- int nbOfTuples=getNumberOfTuples();
- if(nbOfTuples<=0)
- throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : array exists but number of tuples must be > 0 !");
- const double *vals=getConstPointer();
- double ret=std::accumulate(vals,vals+nbOfTuples,0.);
- return ret/nbOfTuples;
-}
-
-/*!
- * Returns the Euclidean norm of the vector defined by \a this array.
- * \return double - the value of the Euclidean norm, i.e.
- * the square root of the inner product of vector.
- * \throw If \a this is not allocated.
- */
-double DataArrayDouble::norm2() const
-{
- checkAllocated();
- double ret=0.;
- std::size_t nbOfElems=getNbOfElems();
- const double *pt=getConstPointer();
- for(std::size_t i=0;i<nbOfElems;i++,pt++)
- ret+=(*pt)*(*pt);
- return sqrt(ret);
-}
-
-/*!
- * Returns the maximum norm of the vector defined by \a this array.
- * This method works even if the number of components is diferent from one.
- * If the number of elements in \a this is 0, -1. is returned.
- * \return double - the value of the maximum norm, i.e.
- * the maximal absolute value among values of \a this array (whatever its number of components).
- * \throw If \a this is not allocated.
- */
-double DataArrayDouble::normMax() const
-{
- checkAllocated();
- double ret(-1.);
- std::size_t nbOfElems(getNbOfElems());
- const double *pt(getConstPointer());
- for(std::size_t i=0;i<nbOfElems;i++,pt++)
- {
- double val(std::abs(*pt));
- if(val>ret)
- ret=val;
- }
- return ret;
-}
-
-/*!
- * Returns the minimum norm (absolute value) of the vector defined by \a this array.
- * This method works even if the number of components is diferent from one.
- * If the number of elements in \a this is 0, std::numeric_limits<double>::max() is returned.
- * \return double - the value of the minimum norm, i.e.
- * the minimal absolute value among values of \a this array (whatever its number of components).
- * \throw If \a this is not allocated.
- */
-double DataArrayDouble::normMin() const
-{
- checkAllocated();
- double ret(std::numeric_limits<double>::max());
- std::size_t nbOfElems(getNbOfElems());
- const double *pt(getConstPointer());
- for(std::size_t i=0;i<nbOfElems;i++,pt++)
- {
- double val(std::abs(*pt));
- if(val<ret)
- ret=val;
- }
- return ret;
-}
-
-/*!
- * Accumulates values of each component of \a this array.
- * \param [out] res - an array of length \a this->getNumberOfComponents(), allocated
- * by the caller, that is filled by this method with sum value for each
- * component.
- * \throw If \a this is not allocated.
- */
-void DataArrayDouble::accumulate(double *res) const
-{
- checkAllocated();
- const double *ptr=getConstPointer();
- int nbTuple=getNumberOfTuples();
- int nbComps=getNumberOfComponents();
- std::fill(res,res+nbComps,0.);
- for(int i=0;i<nbTuple;i++)
- std::transform(ptr+i*nbComps,ptr+(i+1)*nbComps,res,res,std::plus<double>());
-}
-
-/*!
- * This method returns the min distance from an external tuple defined by [ \a tupleBg , \a tupleEnd ) to \a this and
- * the first tuple in \a this that matches the returned distance. If there is no tuples in \a this an exception will be thrown.
- *
- *
- * \a this is expected to be allocated and expected to have a number of components equal to the distance from \a tupleBg to
- * \a tupleEnd. If not an exception will be thrown.
- *
- * \param [in] tupleBg start pointer (included) of input external tuple
- * \param [in] tupleEnd end pointer (not included) of input external tuple
- * \param [out] tupleId the tuple id in \a this that matches the min of distance between \a this and input external tuple
- * \return the min distance.
- * \sa MEDCouplingUMesh::distanceToPoint
- */
-double DataArrayDouble::distanceToTuple(const double *tupleBg, const double *tupleEnd, int& tupleId) const
-{
- checkAllocated();
- int nbTuple=getNumberOfTuples();
- int nbComps=getNumberOfComponents();
- if(nbComps!=(int)std::distance(tupleBg,tupleEnd))
- { std::ostringstream oss; oss << "DataArrayDouble::distanceToTuple : size of input tuple is " << std::distance(tupleBg,tupleEnd) << " should be equal to the number of components in this : " << nbComps << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
- if(nbTuple==0)
- throw INTERP_KERNEL::Exception("DataArrayDouble::distanceToTuple : no tuple in this ! No distance to compute !");
- double ret0=std::numeric_limits<double>::max();
- tupleId=-1;
- const double *work=getConstPointer();
- for(int i=0;i<nbTuple;i++)
- {
- double val=0.;
- for(int j=0;j<nbComps;j++,work++)
- val+=(*work-tupleBg[j])*((*work-tupleBg[j]));
- if(val>=ret0)
- continue;
- else
- { ret0=val; tupleId=i; }
- }
- return sqrt(ret0);
-}
-
-/*!
- * Accumulate values of the given component of \a this array.
- * \param [in] compId - the index of the component of interest.
- * \return double - a sum value of \a compId-th component.
- * \throw If \a this is not allocated.
- * \throw If \a the condition ( 0 <= \a compId < \a this->getNumberOfComponents() ) is
- * not respected.
- */
-double DataArrayDouble::accumulate(int compId) const
-{
- checkAllocated();
- const double *ptr=getConstPointer();
- int nbTuple=getNumberOfTuples();
- int nbComps=getNumberOfComponents();
- if(compId<0 || compId>=nbComps)
- throw INTERP_KERNEL::Exception("DataArrayDouble::accumulate : Invalid compId specified : No such nb of components !");
- double ret=0.;
- for(int i=0;i<nbTuple;i++)
- ret+=ptr[i*nbComps+compId];
- return ret;
-}
-
-/*!
- * This method accumulate using addition tuples in \a this using input index array [ \a bgOfIndex, \a endOfIndex ).
- * The returned array will have same number of components than \a this and number of tuples equal to
- * \c std::distance(bgOfIndex,endOfIndex) \b minus \b one.
- *
- * The input index array is expected to be ascendingly sorted in which the all referenced ids should be in [0, \c this->getNumberOfTuples).
- * This method is quite useful for users that need to put a field on cells to field on nodes on the same mesh without a need of conservation.
- *
- * \param [in] bgOfIndex - begin (included) of the input index array.
- * \param [in] endOfIndex - end (excluded) of the input index array.
- * \return DataArrayDouble * - the new instance having the same number of components than \a this.
- *
- * \throw If bgOfIndex or end is NULL.
- * \throw If input index array is not ascendingly sorted.
- * \throw If there is an id in [ \a bgOfIndex, \a endOfIndex ) not in [0, \c this->getNumberOfTuples).
- * \throw If std::distance(bgOfIndex,endOfIndex)==0.
- */
-DataArrayDouble *DataArrayDouble::accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const
-{
- if(!bgOfIndex || !endOfIndex)
- throw INTERP_KERNEL::Exception("DataArrayDouble::accumulatePerChunck : input pointer NULL !");
- checkAllocated();
- int nbCompo=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- int sz=(int)std::distance(bgOfIndex,endOfIndex);
- if(sz<1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::accumulatePerChunck : invalid size of input index array !");
- sz--;
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(sz,nbCompo);
- const int *w=bgOfIndex;
- if(*w<0 || *w>=nbOfTuples)
- throw INTERP_KERNEL::Exception("DataArrayDouble::accumulatePerChunck : The first element of the input index not in [0,nbOfTuples) !");
- const double *srcPt=begin()+(*w)*nbCompo;
- double *tmp=ret->getPointer();
- for(int i=0;i<sz;i++,tmp+=nbCompo,w++)
- {
- std::fill(tmp,tmp+nbCompo,0.);
- if(w[1]>=w[0])
- {
- for(int j=w[0];j<w[1];j++,srcPt+=nbCompo)
- {
- if(j>=0 && j<nbOfTuples)
- std::transform(srcPt,srcPt+nbCompo,tmp,tmp,std::plus<double>());
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::accumulatePerChunck : At rank #" << i << " the input index array points to id " << j << " should be in [0," << nbOfTuples << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::accumulatePerChunck : At rank #" << i << " the input index array is not in ascendingly sorted.";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- ret->copyStringInfoFrom(*this);
- return ret.retn();
-}
-
-/*!
- * Converts each 2D point defined by the tuple of \a this array from the Polar to the
- * Cartesian coordinate system. The two components of the tuple of \a this array are
- * considered to contain (1) radius and (2) angle of the point in the Polar CS.
- * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
- * contains X and Y coordinates of the point in the Cartesian CS. The caller
- * is to delete this array using decrRef() as it is no more needed. The array
- * does not contain any textual info on components.
- * \throw If \a this->getNumberOfComponents() != 2.
- */
-DataArrayDouble *DataArrayDouble::fromPolarToCart() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::fromPolarToCart : must be an array with exactly 2 components !");
- int nbOfTuple=getNumberOfTuples();
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,2);
- double *w=ret->getPointer();
- const double *wIn=getConstPointer();
- for(int i=0;i<nbOfTuple;i++,w+=2,wIn+=2)
- {
- w[0]=wIn[0]*cos(wIn[1]);
- w[1]=wIn[0]*sin(wIn[1]);
- }
- return ret;
-}
-
-/*!
- * Converts each 3D point defined by the tuple of \a this array from the Cylindrical to
- * the Cartesian coordinate system. The three components of the tuple of \a this array
- * are considered to contain (1) radius, (2) azimuth and (3) altitude of the point in
- * the Cylindrical CS.
- * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
- * contains X, Y and Z coordinates of the point in the Cartesian CS. The info
- * on the third component is copied from \a this array. The caller
- * is to delete this array using decrRef() as it is no more needed.
- * \throw If \a this->getNumberOfComponents() != 3.
- */
-DataArrayDouble *DataArrayDouble::fromCylToCart() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=3)
- throw INTERP_KERNEL::Exception("DataArrayDouble::fromCylToCart : must be an array with exactly 3 components !");
- int nbOfTuple=getNumberOfTuples();
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(getNumberOfTuples(),3);
- double *w=ret->getPointer();
- const double *wIn=getConstPointer();
- for(int i=0;i<nbOfTuple;i++,w+=3,wIn+=3)
- {
- w[0]=wIn[0]*cos(wIn[1]);
- w[1]=wIn[0]*sin(wIn[1]);
- w[2]=wIn[2];
- }
- ret->setInfoOnComponent(2,getInfoOnComponent(2));
- return ret;
-}
-
-/*!
- * Converts each 3D point defined by the tuple of \a this array from the Spherical to
- * the Cartesian coordinate system. The three components of the tuple of \a this array
- * are considered to contain (1) radius, (2) polar angle and (3) azimuthal angle of the
- * point in the Cylindrical CS.
- * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
- * contains X, Y and Z coordinates of the point in the Cartesian CS. The info
- * on the third component is copied from \a this array. The caller
- * is to delete this array using decrRef() as it is no more needed.
- * \throw If \a this->getNumberOfComponents() != 3.
- */
-DataArrayDouble *DataArrayDouble::fromSpherToCart() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=3)
- throw INTERP_KERNEL::Exception("DataArrayDouble::fromSpherToCart : must be an array with exactly 3 components !");
- int nbOfTuple=getNumberOfTuples();
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(getNumberOfTuples(),3);
- double *w=ret->getPointer();
- const double *wIn=getConstPointer();
- for(int i=0;i<nbOfTuple;i++,w+=3,wIn+=3)
- {
- w[0]=wIn[0]*cos(wIn[2])*sin(wIn[1]);
- w[1]=wIn[0]*sin(wIn[2])*sin(wIn[1]);
- w[2]=wIn[0]*cos(wIn[1]);
- }
- return ret;
-}
-
-/*!
- * Computes the doubly contracted product of every tensor defined by the tuple of \a this
- * array contating 6 components.
- * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
- * is calculated from the tuple <em>(t)</em> of \a this array as follows:
- * \f$ t[0]^2+t[1]^2+t[2]^2+2*t[3]^2+2*t[4]^2+2*t[5]^2\f$.
- * The caller is to delete this result array using decrRef() as it is no more needed.
- * \throw If \a this->getNumberOfComponents() != 6.
- */
-DataArrayDouble *DataArrayDouble::doublyContractedProduct() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=6)
- throw INTERP_KERNEL::Exception("DataArrayDouble::doublyContractedProduct : must be an array with exactly 6 components !");
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,1);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
- *dest=src[0]*src[0]+src[1]*src[1]+src[2]*src[2]+2.*src[3]*src[3]+2.*src[4]*src[4]+2.*src[5]*src[5];
- return ret;
-}
-
-/*!
- * Computes the determinant of every square matrix defined by the tuple of \a this
- * array, which contains either 4, 6 or 9 components. The case of 6 components
- * corresponds to that of the upper triangular matrix.
- * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
- * is the determinant of matrix of the corresponding tuple of \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
- */
-DataArrayDouble *DataArrayDouble::determinant() const
-{
- checkAllocated();
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,1);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- switch(getNumberOfComponents())
- {
- case 6:
- for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
- *dest=src[0]*src[1]*src[2]+2.*src[4]*src[5]*src[3]-src[0]*src[4]*src[4]-src[2]*src[3]*src[3]-src[1]*src[5]*src[5];
- return ret;
- case 4:
- for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
- *dest=src[0]*src[3]-src[1]*src[2];
- return ret;
- case 9:
- for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
- *dest=src[0]*src[4]*src[8]+src[1]*src[5]*src[6]+src[2]*src[3]*src[7]-src[0]*src[5]*src[7]-src[1]*src[3]*src[8]-src[2]*src[4]*src[6];
- return ret;
- default:
- ret->decrRef();
- throw INTERP_KERNEL::Exception("DataArrayDouble::determinant : Invalid number of components ! must be in 4,6,9 !");
- }
-}
-
-/*!
- * Computes 3 eigenvalues of every upper triangular matrix defined by the tuple of
- * \a this array, which contains 6 components.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing 3
- * components, whose each tuple contains the eigenvalues of the matrix of
- * corresponding tuple of \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() != 6.
- */
-DataArrayDouble *DataArrayDouble::eigenValues() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=6)
- throw INTERP_KERNEL::Exception("DataArrayDouble::eigenValues : must be an array with exactly 6 components !");
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,3);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,dest+=3,src+=6)
- INTERP_KERNEL::computeEigenValues6(src,dest);
- return ret;
-}
-
-/*!
- * Computes 3 eigenvectors of every upper triangular matrix defined by the tuple of
- * \a this array, which contains 6 components.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing 9
- * components, whose each tuple contains 3 eigenvectors of the matrix of
- * corresponding tuple of \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() != 6.
- */
-DataArrayDouble *DataArrayDouble::eigenVectors() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=6)
- throw INTERP_KERNEL::Exception("DataArrayDouble::eigenVectors : must be an array with exactly 6 components !");
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,9);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,src+=6)
- {
- double tmp[3];
- INTERP_KERNEL::computeEigenValues6(src,tmp);
- for(int j=0;j<3;j++,dest+=3)
- INTERP_KERNEL::computeEigenVectorForEigenValue6(src,tmp[j],1e-12,dest);
- }
- return ret;
-}
-
-/*!
- * Computes the inverse matrix of every matrix defined by the tuple of \a this
- * array, which contains either 4, 6 or 9 components. The case of 6 components
- * corresponds to that of the upper triangular matrix.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of components as \a this one, whose each tuple is the inverse
- * matrix of the matrix of corresponding tuple of \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
- */
-DataArrayDouble *DataArrayDouble::inverse() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=6 && nbOfComp!=9 && nbOfComp!=4)
- throw INTERP_KERNEL::Exception("DataArrayDouble::inversion : must be an array with 4,6 or 9 components !");
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,nbOfComp);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
-if(nbOfComp==6)
- for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
- {
- double det=src[0]*src[1]*src[2]+2.*src[4]*src[5]*src[3]-src[0]*src[4]*src[4]-src[2]*src[3]*src[3]-src[1]*src[5]*src[5];
- dest[0]=(src[1]*src[2]-src[4]*src[4])/det;
- dest[1]=(src[0]*src[2]-src[5]*src[5])/det;
- dest[2]=(src[0]*src[1]-src[3]*src[3])/det;
- dest[3]=(src[5]*src[4]-src[3]*src[2])/det;
- dest[4]=(src[5]*src[3]-src[0]*src[4])/det;
- dest[5]=(src[3]*src[4]-src[1]*src[5])/det;
- }
- else if(nbOfComp==4)
- for(int i=0;i<nbOfTuple;i++,dest+=4,src+=4)
- {
- double det=src[0]*src[3]-src[1]*src[2];
- dest[0]=src[3]/det;
- dest[1]=-src[1]/det;
- dest[2]=-src[2]/det;
- dest[3]=src[0]/det;
- }
- else
- for(int i=0;i<nbOfTuple;i++,dest+=9,src+=9)
- {
- double det=src[0]*src[4]*src[8]+src[1]*src[5]*src[6]+src[2]*src[3]*src[7]-src[0]*src[5]*src[7]-src[1]*src[3]*src[8]-src[2]*src[4]*src[6];
- dest[0]=(src[4]*src[8]-src[7]*src[5])/det;
- dest[1]=(src[7]*src[2]-src[1]*src[8])/det;
- dest[2]=(src[1]*src[5]-src[4]*src[2])/det;
- dest[3]=(src[6]*src[5]-src[3]*src[8])/det;
- dest[4]=(src[0]*src[8]-src[6]*src[2])/det;
- dest[5]=(src[2]*src[3]-src[0]*src[5])/det;
- dest[6]=(src[3]*src[7]-src[6]*src[4])/det;
- dest[7]=(src[6]*src[1]-src[0]*src[7])/det;
- dest[8]=(src[0]*src[4]-src[1]*src[3])/det;
- }
- return ret;
-}
-
-/*!
- * Computes the trace of every matrix defined by the tuple of \a this
- * array, which contains either 4, 6 or 9 components. The case of 6 components
- * corresponds to that of the upper triangular matrix.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing
- * 1 component, whose each tuple is the trace of
- * the matrix of corresponding tuple of \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
- */
-DataArrayDouble *DataArrayDouble::trace() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=6 && nbOfComp!=9 && nbOfComp!=4)
- throw INTERP_KERNEL::Exception("DataArrayDouble::trace : must be an array with 4,6 or 9 components !");
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,1);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- if(nbOfComp==6)
- for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
- *dest=src[0]+src[1]+src[2];
- else if(nbOfComp==4)
- for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
- *dest=src[0]+src[3];
- else
- for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
- *dest=src[0]+src[4]+src[8];
- return ret;
-}
-
-/*!
- * Computes the stress deviator tensor of every stress tensor defined by the tuple of
- * \a this array, which contains 6 components.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of components and tuples as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() != 6.
- */
-DataArrayDouble *DataArrayDouble::deviator() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- if(nbOfComp!=6)
- throw INTERP_KERNEL::Exception("DataArrayDouble::deviator : must be an array with exactly 6 components !");
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,6);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
- {
- double tr=(src[0]+src[1]+src[2])/3.;
- dest[0]=src[0]-tr;
- dest[1]=src[1]-tr;
- dest[2]=src[2]-tr;
- dest[3]=src[3];
- dest[4]=src[4];
- dest[5]=src[5];
- }
- return ret;
-}
-
-/*!
- * Computes the magnitude of every vector defined by the tuple of
- * \a this array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array and one component.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- */
-DataArrayDouble *DataArrayDouble::magnitude() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,1);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,dest++)
- {
- double sum=0.;
- for(int j=0;j<nbOfComp;j++,src++)
- sum+=(*src)*(*src);
- *dest=sqrt(sum);
- }
- return ret;
-}
-
-/*!
- * Computes for each tuple the sum of number of components values in the tuple and return it.
- *
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array and one component.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- */
-DataArrayDouble *DataArrayDouble::sumPerTuple() const
-{
- checkAllocated();
- int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples());
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New());
- ret->alloc(nbOfTuple,1);
- const double *src(getConstPointer());
- double *dest(ret->getPointer());
- for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
- *dest=std::accumulate(src,src+nbOfComp,0.);
- return ret.retn();
-}
-
-/*!
- * Computes the maximal value within every tuple of \a this array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array and one component.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \sa DataArrayDouble::maxPerTupleWithCompoId
- */
-DataArrayDouble *DataArrayDouble::maxPerTuple() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- int nbOfTuple=getNumberOfTuples();
- ret->alloc(nbOfTuple,1);
- const double *src=getConstPointer();
- double *dest=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
- *dest=*std::max_element(src,src+nbOfComp);
- return ret.retn();
-}
-
-/*!
- * Computes the maximal value within every tuple of \a this array and it returns the first component
- * id for each tuple that corresponds to the maximal value within the tuple.
- *
- * \param [out] compoIdOfMaxPerTuple - the new new instance of DataArrayInt containing the
- * same number of tuples and only one component.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array and one component.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \sa DataArrayDouble::maxPerTuple
- */
-DataArrayDouble *DataArrayDouble::maxPerTupleWithCompoId(DataArrayInt* &compoIdOfMaxPerTuple) const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret0=DataArrayDouble::New();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=DataArrayInt::New();
- int nbOfTuple=getNumberOfTuples();
- ret0->alloc(nbOfTuple,1); ret1->alloc(nbOfTuple,1);
- const double *src=getConstPointer();
- double *dest=ret0->getPointer(); int *dest1=ret1->getPointer();
- for(int i=0;i<nbOfTuple;i++,dest++,dest1++,src+=nbOfComp)
- {
- const double *loc=std::max_element(src,src+nbOfComp);
- *dest=*loc;
- *dest1=(int)std::distance(src,loc);
- }
- compoIdOfMaxPerTuple=ret1.retn();
- return ret0.retn();
-}
-
-/*!
- * This method returns a newly allocated DataArrayDouble instance having one component and \c this->getNumberOfTuples() * \c this->getNumberOfTuples() tuples.
- * \n This returned array contains the euclidian distance for each tuple in \a this.
- * \n So the returned array can be seen as a dense symmetrical matrix whose diagonal elements are equal to 0.
- * \n The returned array has only one component (and **not** \c this->getNumberOfTuples() components to avoid the useless memory consumption due to components info in returned DataArrayDouble)
- *
- * \warning use this method with care because it can leads to big amount of consumed memory !
- *
- * \return A newly allocated (huge) ParaMEDMEM::DataArrayDouble instance that the caller should deal with.
- *
- * \throw If \a this is not allocated.
- *
- * \sa DataArrayDouble::buildEuclidianDistanceDenseMatrixWith
- */
-DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrix() const
-{
- checkAllocated();
- int nbOfComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- const double *inData=getConstPointer();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuples*nbOfTuples,1);
- double *outData=ret->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- outData[i*nbOfTuples+i]=0.;
- for(int j=i+1;j<nbOfTuples;j++)
- {
- double dist=0.;
- for(int k=0;k<nbOfComp;k++)
- { double delta=inData[i*nbOfComp+k]-inData[j*nbOfComp+k]; dist+=delta*delta; }
- dist=sqrt(dist);
- outData[i*nbOfTuples+j]=dist;
- outData[j*nbOfTuples+i]=dist;
- }
- }
- return ret.retn();
-}
-
-/*!
- * This method returns a newly allocated DataArrayDouble instance having one component and \c this->getNumberOfTuples() * \c other->getNumberOfTuples() tuples.
- * \n This returned array contains the euclidian distance for each tuple in \a other with each tuple in \a this.
- * \n So the returned array can be seen as a dense rectangular matrix with \c other->getNumberOfTuples() rows and \c this->getNumberOfTuples() columns.
- * \n Output rectangular matrix is sorted along rows.
- * \n The returned array has only one component (and **not** \c this->getNumberOfTuples() components to avoid the useless memory consumption due to components info in returned DataArrayDouble)
- *
- * \warning use this method with care because it can leads to big amount of consumed memory !
- *
- * \param [in] other DataArrayDouble instance having same number of components than \a this.
- * \return A newly allocated (huge) ParaMEDMEM::DataArrayDouble instance that the caller should deal with.
- *
- * \throw If \a this is not allocated, or if \a other is null or if \a other is not allocated, or if number of components of \a other and \a this differs.
- *
- * \sa DataArrayDouble::buildEuclidianDistanceDenseMatrix
- */
-DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::buildEuclidianDistanceDenseMatrixWith : input parameter is null !");
- checkAllocated();
- other->checkAllocated();
- int nbOfComp=getNumberOfComponents();
- int otherNbOfComp=other->getNumberOfComponents();
- if(nbOfComp!=otherNbOfComp)
- {
- std::ostringstream oss; oss << "DataArrayDouble::buildEuclidianDistanceDenseMatrixWith : this nb of compo=" << nbOfComp << " and other nb of compo=" << otherNbOfComp << ". It should match !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- int nbOfTuples=getNumberOfTuples();
- int otherNbOfTuples=other->getNumberOfTuples();
- const double *inData=getConstPointer();
- const double *inDataOther=other->getConstPointer();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(otherNbOfTuples*nbOfTuples,1);
- double *outData=ret->getPointer();
- for(int i=0;i<otherNbOfTuples;i++,inDataOther+=nbOfComp)
- {
- for(int j=0;j<nbOfTuples;j++)
- {
- double dist=0.;
- for(int k=0;k<nbOfComp;k++)
- { double delta=inDataOther[k]-inData[j*nbOfComp+k]; dist+=delta*delta; }
- dist=sqrt(dist);
- outData[i*nbOfTuples+j]=dist;
- }
- }
- return ret.retn();
-}
-
-/*!
- * Sorts value within every tuple of \a this array.
- * \param [in] asc - if \a true, the values are sorted in ascending order, else,
- * in descending order.
- * \throw If \a this is not allocated.
- */
-void DataArrayDouble::sortPerTuple(bool asc)
-{
- checkAllocated();
- double *pt=getPointer();
- int nbOfTuple=getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- if(asc)
- for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
- std::sort(pt,pt+nbOfComp);
- else
- for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
- std::sort(pt,pt+nbOfComp,std::greater<double>());
- declareAsNew();
-}
-
-/*!
- * Converts every value of \a this array to its absolute value.
- * \b WARNING this method is non const. If a new DataArrayDouble instance should be built containing the result of abs DataArrayDouble::computeAbs
- * should be called instead.
- *
- * \throw If \a this is not allocated.
- * \sa DataArrayDouble::computeAbs
- */
-void DataArrayDouble::abs()
-{
- checkAllocated();
- double *ptr(getPointer());
- std::size_t nbOfElems(getNbOfElems());
- std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<double,double>(fabs));
- declareAsNew();
-}
-
-/*!
- * This method builds a new instance of \a this object containing the result of std::abs applied of all elements in \a this.
- * This method is a const method (that do not change any values in \a this) contrary to DataArrayDouble::abs method.
- *
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples and component as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \sa DataArrayDouble::abs
- */
-DataArrayDouble *DataArrayDouble::computeAbs() const
-{
- checkAllocated();
- DataArrayDouble *newArr(DataArrayDouble::New());
- int nbOfTuples(getNumberOfTuples());
- int nbOfComp(getNumberOfComponents());
- newArr->alloc(nbOfTuples,nbOfComp);
- std::transform(begin(),end(),newArr->getPointer(),std::ptr_fun<double,double>(fabs));
- newArr->copyStringInfoFrom(*this);
- return newArr;
-}
-
-/*!
- * Apply a liner function to a given component of \a this array, so that
- * an array element <em>(x)</em> becomes \f$ a * x + b \f$.
- * \param [in] a - the first coefficient of the function.
- * \param [in] b - the second coefficient of the function.
- * \param [in] compoId - the index of component to modify.
- * \throw If \a this is not allocated.
- */
-void DataArrayDouble::applyLin(double a, double b, int compoId)
-{
- checkAllocated();
- double *ptr=getPointer()+compoId;
- int nbOfComp=getNumberOfComponents();
- int nbOfTuple=getNumberOfTuples();
- for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
- *ptr=a*(*ptr)+b;
- declareAsNew();
-}
-
-/*!
- * Apply a liner function to all elements of \a this array, so that
- * an element _x_ becomes \f$ a * x + b \f$.
- * \param [in] a - the first coefficient of the function.
- * \param [in] b - the second coefficient of the function.
- * \throw If \a this is not allocated.
- */
-void DataArrayDouble::applyLin(double a, double b)
-{
- checkAllocated();
- double *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- *ptr=a*(*ptr)+b;
- declareAsNew();
-}
-
-/*!
- * Modify all elements of \a this array, so that
- * an element _x_ becomes \f$ numerator / x \f$.
- * \warning If an exception is thrown because of presence of 0.0 element in \a this
- * array, all elements processed before detection of the zero element remain
- * modified.
- * \param [in] numerator - the numerator used to modify array elements.
- * \throw If \a this is not allocated.
- * \throw If there is an element equal to 0.0 in \a this array.
- */
-void DataArrayDouble::applyInv(double numerator)
-{
- checkAllocated();
- double *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- {
- if(std::abs(*ptr)>std::numeric_limits<double>::min())
- {
- *ptr=numerator/(*ptr);
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
- oss << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- declareAsNew();
-}
-
-/*!
- * Returns a full copy of \a this array except that sign of all elements is reversed.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples and component as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- */
-DataArrayDouble *DataArrayDouble::negate() const
-{
- 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;
-}
-
-/*!
- * Modify all elements of \a this array, so that
- * an element _x_ becomes <em> val ^ x </em>. Contrary to DataArrayInt::applyPow
- * all values in \a this have to be >= 0 if val is \b not integer.
- * \param [in] val - the value used to apply pow on all array elements.
- * \throw If \a this is not allocated.
- * \warning If an exception is thrown because of presence of 0 element in \a this
- * array and \a val is \b not integer, all elements processed before detection of the zero element remain
- * modified.
- */
-void DataArrayDouble::applyPow(double val)
-{
- checkAllocated();
- double *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- int val2=(int)val;
- bool isInt=((double)val2)==val;
- if(!isInt)
- {
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- {
- if(*ptr>=0)
- *ptr=pow(*ptr,val);
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::applyPow (double) : At elem # " << i << " value is " << *ptr << " ! must be >=0. !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- }
- else
- {
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- *ptr=pow(*ptr,val2);
- }
- declareAsNew();
-}
-
-/*!
- * Modify all elements of \a this array, so that
- * an element _x_ becomes \f$ val ^ x \f$.
- * \param [in] val - the value used to apply pow on all array elements.
- * \throw If \a this is not allocated.
- * \throw If \a val < 0.
- * \warning If an exception is thrown because of presence of 0 element in \a this
- * array, all elements processed before detection of the zero element remain
- * modified.
- */
-void DataArrayDouble::applyRPow(double val)
-{
- checkAllocated();
- if(val<0.)
- throw INTERP_KERNEL::Exception("DataArrayDouble::applyRPow : the input value has to be >= 0 !");
- double *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
- for(std::size_t i=0;i<nbOfElems;i++,ptr++)
- *ptr=pow(val,*ptr);
- declareAsNew();
-}
-
-/*!
- * Returns a new DataArrayDouble created from \a this one by applying \a
- * FunctionToEvaluate to every tuple of \a this array. Textual data is not copied.
- * For more info see \ref MEDCouplingArrayApplyFunc
- * \param [in] nbOfComp - number of components in the result array.
- * \param [in] func - the \a FunctionToEvaluate declared as
- * \c bool (*\a func)(\c const \c double *\a pos, \c double *\a res),
- * where \a pos points to the first component of a tuple of \a this array
- * and \a res points to the first component of a tuple of the result array.
- * Note that length (number of components) of \a pos can differ from
- * that of \a res.
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \throw If \a func returns \a false.
- */
-DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, FunctionToEvaluate func) const
-{
- checkAllocated();
- DataArrayDouble *newArr=DataArrayDouble::New();
- int nbOfTuples=getNumberOfTuples();
- int oldNbOfComp=getNumberOfComponents();
- newArr->alloc(nbOfTuples,nbOfComp);
- const double *ptr=getConstPointer();
- double *ptrToFill=newArr->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- if(!func(ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp))
- {
- std::ostringstream oss; oss << "For tuple # " << i << " with value (";
- std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
- oss << ") : Evaluation of function failed !";
- newArr->decrRef();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return newArr;
-}
-
-/*!
- * Returns a new DataArrayDouble created from \a this one by applying a function to every
- * tuple of \a this array. Textual data is not copied.
- * For more info see \ref MEDCouplingArrayApplyFunc1.
- * \param [in] nbOfComp - number of components in the result array.
- * \param [in] func - the expression defining how to transform a tuple of \a this array.
- * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array and \a nbOfComp components.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \throw If computing \a func fails.
- */
-DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const std::string& func) const
-{
- checkAllocated();
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- std::set<std::string> vars;
- expr.getTrueSetOfVars(vars);
- int oldNbOfComp=getNumberOfComponents();
- if((int)vars.size()>oldNbOfComp)
- {
- std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
- oss << vars.size() << " variables : ";
- std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- std::vector<std::string> varsV(vars.begin(),vars.end());
- expr.prepareExprEvaluation(varsV,oldNbOfComp,nbOfComp);
- //
- DataArrayDouble *newArr=DataArrayDouble::New();
- int nbOfTuples=getNumberOfTuples();
- newArr->alloc(nbOfTuples,nbOfComp);
- const double *ptr=getConstPointer();
- double *ptrToFill=newArr->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- try
- {
- expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
- }
- catch(INTERP_KERNEL::Exception& e)
- {
- std::ostringstream oss; oss << "For tuple # " << i << " with value (";
- std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
- oss << ") : Evaluation of function failed !" << e.what();
- newArr->decrRef();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return newArr;
-}
-
-/*!
- * Returns a new DataArrayDouble created from \a this one by applying a function to every
- * tuple of \a this array. Textual data is not copied.
- * For more info see \ref MEDCouplingArrayApplyFunc0.
- * \param [in] func - the expression defining how to transform a tuple of \a this array.
- * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples and components as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \throw If computing \a func fails.
- */
-DataArrayDouble *DataArrayDouble::applyFunc(const std::string& func) const
-{
- checkAllocated();
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- expr.prepareExprEvaluationVec();
- //
- DataArrayDouble *newArr=DataArrayDouble::New();
- int nbOfTuples=getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- newArr->alloc(nbOfTuples,nbOfComp);
- const double *ptr=getConstPointer();
- double *ptrToFill=newArr->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- try
- {
- expr.evaluateExpr(nbOfComp,ptr+i*nbOfComp,ptrToFill+i*nbOfComp);
- }
- catch(INTERP_KERNEL::Exception& e)
- {
- std::ostringstream oss; oss << "For tuple # " << i << " with value (";
- std::copy(ptr+nbOfComp*i,ptr+nbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
- oss << ") : Evaluation of function failed ! " << e.what();
- newArr->decrRef();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return newArr;
-}
-
-/*!
- * Returns a new DataArrayDouble created from \a this one by applying a function to every
- * tuple of \a this array. Textual data is not copied.
- * For more info see \ref MEDCouplingArrayApplyFunc2.
- * \param [in] nbOfComp - number of components in the result array.
- * \param [in] func - the expression defining how to transform a tuple of \a this array.
- * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \throw If \a func contains vars that are not in \a this->getInfoOnComponent().
- * \throw If computing \a func fails.
- */
-DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const std::string& func) const
-{
- checkAllocated();
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- std::set<std::string> vars;
- expr.getTrueSetOfVars(vars);
- int oldNbOfComp=getNumberOfComponents();
- if((int)vars.size()>oldNbOfComp)
- {
- std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
- oss << vars.size() << " variables : ";
- std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- expr.prepareExprEvaluation(getVarsOnComponent(),oldNbOfComp,nbOfComp);
- //
- DataArrayDouble *newArr=DataArrayDouble::New();
- int nbOfTuples=getNumberOfTuples();
- newArr->alloc(nbOfTuples,nbOfComp);
- const double *ptr=getConstPointer();
- double *ptrToFill=newArr->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- try
- {
- expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
- }
- catch(INTERP_KERNEL::Exception& e)
- {
- std::ostringstream oss; oss << "For tuple # " << i << " with value (";
- std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
- oss << ") : Evaluation of function failed !" << e.what();
- newArr->decrRef();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return newArr;
-}
-
-/*!
- * Returns a new DataArrayDouble created from \a this one by applying a function to every
- * tuple of \a this array. Textual data is not copied.
- * For more info see \ref MEDCouplingArrayApplyFunc3.
- * \param [in] nbOfComp - number of components in the result array.
- * \param [in] varsOrder - sequence of vars defining their order.
- * \param [in] func - the expression defining how to transform a tuple of \a this array.
- * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- * same number of tuples as \a this array.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this is not allocated.
- * \throw If \a func contains vars not in \a varsOrder.
- * \throw If computing \a func fails.
- */
-DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func) const
-{
- checkAllocated();
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- std::set<std::string> vars;
- expr.getTrueSetOfVars(vars);
- int oldNbOfComp=getNumberOfComponents();
- if((int)vars.size()>oldNbOfComp)
- {
- std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
- oss << vars.size() << " variables : ";
- std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- expr.prepareExprEvaluation(varsOrder,oldNbOfComp,nbOfComp);
- //
- DataArrayDouble *newArr=DataArrayDouble::New();
- int nbOfTuples=getNumberOfTuples();
- newArr->alloc(nbOfTuples,nbOfComp);
- const double *ptr=getConstPointer();
- double *ptrToFill=newArr->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- try
- {
- expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
- }
- catch(INTERP_KERNEL::Exception& e)
- {
- std::ostringstream oss; oss << "For tuple # " << i << " with value (";
- std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
- oss << ") : Evaluation of function failed !" << e.what();
- newArr->decrRef();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return newArr;
-}
-
-void DataArrayDouble::applyFuncFast32(const std::string& func)
-{
- checkAllocated();
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- char *funcStr=expr.compileX86();
- MYFUNCPTR funcPtr;
- *((void **)&funcPtr)=funcStr;//he he...
- //
- double *ptr=getPointer();
- int nbOfComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- int nbOfElems=nbOfTuples*nbOfComp;
- for(int i=0;i<nbOfElems;i++,ptr++)
- *ptr=funcPtr(*ptr);
- declareAsNew();
-}
-
-void DataArrayDouble::applyFuncFast64(const std::string& func)
-{
- checkAllocated();
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- char *funcStr=expr.compileX86_64();
- MYFUNCPTR funcPtr;
- *((void **)&funcPtr)=funcStr;//he he...
- //
- double *ptr=getPointer();
- int nbOfComp=getNumberOfComponents();
- int nbOfTuples=getNumberOfTuples();
- int nbOfElems=nbOfTuples*nbOfComp;
- for(int i=0;i<nbOfElems;i++,ptr++)
- *ptr=funcPtr(*ptr);
- declareAsNew();
-}
-
-DataArrayDoubleIterator *DataArrayDouble::iterator()
-{
- return new DataArrayDoubleIterator(this);
-}
-
-/*!
- * Returns a new DataArrayInt contating indices of tuples of \a this one-dimensional
- * array whose values are within a given range. Textual data is not copied.
- * \param [in] vmin - a lowest acceptable value (included).
- * \param [in] vmax - a greatest acceptable value (included).
- * \return DataArrayInt * - the new instance of DataArrayInt.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() != 1.
- *
- * \sa DataArrayDouble::getIdsNotInRange
- *
- * \ref cpp_mcdataarraydouble_getidsinrange "Here is a C++ example".<br>
- * \ref py_mcdataarraydouble_getidsinrange "Here is a Python example".
- */
-DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::getIdsInRange : this must have exactly one component !");
- const double *cptr(begin());
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- int nbOfTuples(getNumberOfTuples());
- for(int i=0;i<nbOfTuples;i++,cptr++)
- if(*cptr>=vmin && *cptr<=vmax)
- ret->pushBackSilent(i);
- return ret.retn();
-}
-
-/*!
- * Returns a new DataArrayInt contating indices of tuples of \a this one-dimensional
- * array whose values are not within a given range. Textual data is not copied.
- * \param [in] vmin - a lowest not acceptable value (excluded).
- * \param [in] vmax - a greatest not acceptable value (excluded).
- * \return DataArrayInt * - the new instance of DataArrayInt.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If \a this->getNumberOfComponents() != 1.
- *
- * \sa DataArrayDouble::getIdsInRange
- */
-DataArrayInt *DataArrayDouble::getIdsNotInRange(double vmin, double vmax) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::getIdsNotInRange : this must have exactly one component !");
- const double *cptr(begin());
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
- int nbOfTuples(getNumberOfTuples());
- for(int i=0;i<nbOfTuples;i++,cptr++)
- if(*cptr<vmin || *cptr>vmax)
- ret->pushBackSilent(i);
- return ret.retn();
-}
-
-/*!
- * Returns a new DataArrayDouble by concatenating two given arrays, so that (1) the number
- * of tuples in the result array is a sum of the number of tuples of given arrays and (2)
- * the number of component in the result array is same as that of each of given arrays.
- * Info on components is copied from the first of the given arrays. Number of components
- * in the given arrays must be the same.
- * \param [in] a1 - an array to include in the result array.
- * \param [in] a2 - another array to include in the result array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If both \a a1 and \a a2 are NULL.
- * \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents().
- */
-DataArrayDouble *DataArrayDouble::Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- std::vector<const DataArrayDouble *> tmp(2);
- tmp[0]=a1; tmp[1]=a2;
- return Aggregate(tmp);
-}
-
-/*!
- * Returns a new DataArrayDouble by concatenating all given arrays, so that (1) the number
- * of tuples in the result array is a sum of the number of tuples of given arrays and (2)
- * the number of component in the result array is same as that of each of given arrays.
- * Info on components is copied from the first of the given arrays. Number of components
- * in the given arrays must be the same.
- * If the number of non null of elements in \a arr is equal to one the returned object is a copy of it
- * not the object itself.
- * \param [in] arr - a sequence of arrays to include in the result array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If all arrays within \a arr are NULL.
- * \throw If getNumberOfComponents() of arrays within \a arr.
- */
-DataArrayDouble *DataArrayDouble::Aggregate(const std::vector<const DataArrayDouble *>& arr)
-{
- std::vector<const DataArrayDouble *> a;
- for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
- if(*it4)
- a.push_back(*it4);
- if(a.empty())
- throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : input list must contain at least one NON EMPTY DataArrayDouble !");
- std::vector<const DataArrayDouble *>::const_iterator it=a.begin();
- int nbOfComp=(*it)->getNumberOfComponents();
- int nbt=(*it++)->getNumberOfTuples();
- for(int i=1;it!=a.end();it++,i++)
- {
- if((*it)->getNumberOfComponents()!=nbOfComp)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : Nb of components mismatch for array aggregation !");
- nbt+=(*it)->getNumberOfTuples();
- }
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbt,nbOfComp);
- double *pt=ret->getPointer();
- for(it=a.begin();it!=a.end();it++)
- pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt);
- ret->copyStringInfoFrom(*(a[0]));
- return ret.retn();
-}
-
-/*!
- * Returns a new DataArrayDouble by aggregating two given arrays, so that (1) the number
- * of components in the result array is a sum of the number of components of given arrays
- * and (2) the number of tuples in the result array is same as that of each of given
- * arrays. In other words the i-th tuple of result array includes all components of
- * i-th tuples of all given arrays.
- * Number of tuples in the given arrays must be the same.
- * \param [in] a1 - an array to include in the result array.
- * \param [in] a2 - another array to include in the result array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If both \a a1 and \a a2 are NULL.
- * \throw If any given array is not allocated.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
- */
-DataArrayDouble *DataArrayDouble::Meld(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- std::vector<const DataArrayDouble *> arr(2);
- arr[0]=a1; arr[1]=a2;
- return Meld(arr);
-}
-
-/*!
- * Returns a new DataArrayDouble by aggregating all given arrays, so that (1) the number
- * of components in the result array is a sum of the number of components of given arrays
- * and (2) the number of tuples in the result array is same as that of each of given
- * arrays. In other words the i-th tuple of result array includes all components of
- * i-th tuples of all given arrays.
- * Number of tuples in the given arrays must be the same.
- * \param [in] arr - a sequence of arrays to include in the result array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If all arrays within \a arr are NULL.
- * \throw If any given array is not allocated.
- * \throw If getNumberOfTuples() of arrays within \a arr is different.
- */
-DataArrayDouble *DataArrayDouble::Meld(const std::vector<const DataArrayDouble *>& arr)
-{
- std::vector<const DataArrayDouble *> a;
- for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
- if(*it4)
- a.push_back(*it4);
- if(a.empty())
- throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : input list must contain at least one NON EMPTY DataArrayDouble !");
- std::vector<const DataArrayDouble *>::const_iterator it;
- for(it=a.begin();it!=a.end();it++)
- (*it)->checkAllocated();
- it=a.begin();
- int nbOfTuples=(*it)->getNumberOfTuples();
- std::vector<int> nbc(a.size());
- std::vector<const double *> pts(a.size());
- nbc[0]=(*it)->getNumberOfComponents();
- pts[0]=(*it++)->getConstPointer();
- for(int i=1;it!=a.end();it++,i++)
- {
- if(nbOfTuples!=(*it)->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : mismatch of number of tuples !");
- nbc[i]=(*it)->getNumberOfComponents();
- pts[i]=(*it)->getConstPointer();
- }
- int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuples,totalNbOfComp);
- double *retPtr=ret->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- for(int j=0;j<(int)a.size();j++)
- {
- retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
- pts[j]+=nbc[j];
- }
- int k=0;
- for(int i=0;i<(int)a.size();i++)
- for(int j=0;j<nbc[i];j++,k++)
- ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j));
- return ret;
-}
-
-/*!
- * Returns a new DataArrayDouble containing a dot product of two given arrays, so that
- * the i-th tuple of the result array is a sum of products of j-th components of i-th
- * tuples of given arrays (\f$ a_i = \sum_{j=1}^n a1_j * a2_j \f$).
- * Info on components and name is copied from the first of the given arrays.
- * Number of tuples and components in the given arrays must be the same.
- * \param [in] a1 - a given array.
- * \param [in] a2 - another given array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If any given array is not allocated.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
- * \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents()
- */
-DataArrayDouble *DataArrayDouble::Dot(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Dot : input DataArrayDouble instance is NULL !");
- a1->checkAllocated();
- a2->checkAllocated();
- int nbOfComp=a1->getNumberOfComponents();
- if(nbOfComp!=a2->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Dot !");
- int nbOfTuple=a1->getNumberOfTuples();
- if(nbOfTuple!=a2->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Dot !");
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,1);
- double *retPtr=ret->getPointer();
- const double *a1Ptr=a1->getConstPointer();
- const double *a2Ptr=a2->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- {
- double sum=0.;
- for(int j=0;j<nbOfComp;j++)
- sum+=a1Ptr[i*nbOfComp+j]*a2Ptr[i*nbOfComp+j];
- retPtr[i]=sum;
- }
- ret->setInfoOnComponent(0,a1->getInfoOnComponent(0));
- ret->setName(a1->getName());
- return ret;
-}
-
-/*!
- * Returns a new DataArrayDouble containing a cross product of two given arrays, so that
- * the i-th tuple of the result array contains 3 components of a vector which is a cross
- * product of two vectors defined by the i-th tuples of given arrays.
- * Info on components is copied from the first of the given arrays.
- * Number of tuples in the given arrays must be the same.
- * Number of components in the given arrays must be 3.
- * \param [in] a1 - a given array.
- * \param [in] a2 - another given array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
- * \throw If \a a1->getNumberOfComponents() != 3
- * \throw If \a a2->getNumberOfComponents() != 3
- */
-DataArrayDouble *DataArrayDouble::CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::CrossProduct : input DataArrayDouble instance is NULL !");
- int nbOfComp=a1->getNumberOfComponents();
- if(nbOfComp!=a2->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array crossProduct !");
- if(nbOfComp!=3)
- throw INTERP_KERNEL::Exception("Nb of components must be equal to 3 for array crossProduct !");
- int nbOfTuple=a1->getNumberOfTuples();
- if(nbOfTuple!=a2->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array crossProduct !");
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,3);
- double *retPtr=ret->getPointer();
- const double *a1Ptr=a1->getConstPointer();
- const double *a2Ptr=a2->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- {
- retPtr[3*i]=a1Ptr[3*i+1]*a2Ptr[3*i+2]-a1Ptr[3*i+2]*a2Ptr[3*i+1];
- retPtr[3*i+1]=a1Ptr[3*i+2]*a2Ptr[3*i]-a1Ptr[3*i]*a2Ptr[3*i+2];
- retPtr[3*i+2]=a1Ptr[3*i]*a2Ptr[3*i+1]-a1Ptr[3*i+1]*a2Ptr[3*i];
- }
- ret->copyStringInfoFrom(*a1);
- return ret;
-}
-
-/*!
- * Returns a new DataArrayDouble containing maximal values of two given arrays.
- * Info on components is copied from the first of the given arrays.
- * Number of tuples and components in the given arrays must be the same.
- * \param [in] a1 - an array to compare values with another one.
- * \param [in] a2 - another array to compare values with the first one.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
- * \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents()
- */
-DataArrayDouble *DataArrayDouble::Max(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Max : input DataArrayDouble instance is NULL !");
- int nbOfComp=a1->getNumberOfComponents();
- if(nbOfComp!=a2->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Max !");
- int nbOfTuple=a1->getNumberOfTuples();
- if(nbOfTuple!=a2->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Max !");
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfComp);
- double *retPtr=ret->getPointer();
- const double *a1Ptr=a1->getConstPointer();
- const double *a2Ptr=a2->getConstPointer();
- int nbElem=nbOfTuple*nbOfComp;
- for(int i=0;i<nbElem;i++)
- retPtr[i]=std::max(a1Ptr[i],a2Ptr[i]);
- ret->copyStringInfoFrom(*a1);
- return ret;
-}
-
-/*!
- * Returns a new DataArrayDouble containing minimal values of two given arrays.
- * Info on components is copied from the first of the given arrays.
- * Number of tuples and components in the given arrays must be the same.
- * \param [in] a1 - an array to compare values with another one.
- * \param [in] a2 - another array to compare values with the first one.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
- * \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents()
- */
-DataArrayDouble *DataArrayDouble::Min(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Min : input DataArrayDouble instance is NULL !");
- int nbOfComp=a1->getNumberOfComponents();
- if(nbOfComp!=a2->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array min !");
- int nbOfTuple=a1->getNumberOfTuples();
- if(nbOfTuple!=a2->getNumberOfTuples())
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array min !");
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfComp);
- double *retPtr=ret->getPointer();
- const double *a1Ptr=a1->getConstPointer();
- const double *a2Ptr=a2->getConstPointer();
- int nbElem=nbOfTuple*nbOfComp;
- for(int i=0;i<nbElem;i++)
- retPtr[i]=std::min(a1Ptr[i],a2Ptr[i]);
- ret->copyStringInfoFrom(*a1);
- return ret;
-}
-
-/*!
- * Returns a new DataArrayDouble that is a sum of two given arrays. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * the result array (_a_) is a sum of the corresponding values of \a a1 and \a a2,
- * i.e.: _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, j ].
- * 2. The arrays have same number of tuples and one array, say _a2_, has one
- * component. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, 0 ].
- * 3. The arrays have same number of components and one array, say _a2_, has one
- * tuple. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ].
- *
- * Info on components is copied either from the first array (in the first case) or from
- * the array with maximal number of elements (getNbOfElems()).
- * \param [in] a1 - an array to sum up.
- * \param [in] a2 - another array to sum up.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
- * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
- * none of them has number of tuples or components equal to 1.
- */
-DataArrayDouble *DataArrayDouble::Add(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Add : input DataArrayDouble instance is NULL !");
- int nbOfTuple=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=0;
- if(nbOfTuple==nbOfTuple2)
- {
- if(nbOfComp==nbOfComp2)
- {
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfComp);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus<double>());
- ret->copyStringInfoFrom(*a1);
- }
- else
- {
- int nbOfCompMin,nbOfCompMax;
- const DataArrayDouble *aMin, *aMax;
- if(nbOfComp>nbOfComp2)
- {
- nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
- aMin=a2; aMax=a1;
- }
- else
- {
- nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
- aMin=a1; aMax=a2;
- }
- if(nbOfCompMin==1)
- {
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfCompMax);
- const double *aMinPtr=aMin->getConstPointer();
- const double *aMaxPtr=aMax->getConstPointer();
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++)
- res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<double>(),aMinPtr[i]));
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
- }
- }
- else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
- {
- if(nbOfComp==nbOfComp2)
- {
- int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
- const DataArrayDouble *aMin=nbOfTuple>nbOfTuple2?a2:a1;
- const DataArrayDouble *aMax=nbOfTuple>nbOfTuple2?a1:a2;
- const double *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTupleMax,nbOfComp);
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTupleMax;i++)
- res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::plus<double>());
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
- }
- else
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
- return ret.retn();
-}
-
-/*!
- * Adds values of another DataArrayDouble to values of \a this one. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a other array is added to the corresponding value of \a this array, i.e.:
- * _a_ [ i, j ] += _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _a_ [ i, j ] += _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _a_ [ i, j ] += _a2_ [ 0, j ].
- *
- * \param [in] other - an array to add to \a this one.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
- */
-void DataArrayDouble::addEqual(const DataArrayDouble *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::addEqual : input DataArrayDouble instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayDouble::addEqual !";
- checkAllocated();
- other->checkAllocated();
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
- {
- if(nbOfComp==nbOfComp2)
- {
- std::transform(begin(),end(),other->begin(),getPointer(),std::plus<double>());
- }
- else if(nbOfComp2==1)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<double>(),*ptrc++));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else if(nbOfTuple2==1)
- {
- if(nbOfComp2==nbOfComp)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<double>());
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
-}
-
-/*!
- * Returns a new DataArrayDouble that is a subtraction of two given arrays. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * the result array (_a_) is a subtraction of the corresponding values of \a a1 and
- * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, j ].
- * 2. The arrays have same number of tuples and one array, say _a2_, has one
- * component. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, 0 ].
- * 3. The arrays have same number of components and one array, say _a2_, has one
- * tuple. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ].
- *
- * Info on components is copied either from the first array (in the first case) or from
- * the array with maximal number of elements (getNbOfElems()).
- * \param [in] a1 - an array to subtract from.
- * \param [in] a2 - an array to subtract.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
- * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
- * none of them has number of tuples or components equal to 1.
- */
-DataArrayDouble *DataArrayDouble::Substract(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Substract : input DataArrayDouble instance is NULL !");
- int nbOfTuple1=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp1=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple2==nbOfTuple1)
- {
- if(nbOfComp1==nbOfComp2)
- {
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple2,nbOfComp1);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<double>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else if(nbOfComp2==1)
- {
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const double *a2Ptr=a2->getConstPointer();
- const double *a1Ptr=a1->getConstPointer();
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::minus<double>(),a2Ptr[i]));
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
- return 0;
- }
- }
- else if(nbOfTuple2==1)
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const double *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
- double *pt=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::minus<double>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
- return 0;
- }
-}
-
-/*!
- * Subtract values of another DataArrayDouble from values of \a this one. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a other array is subtracted from the corresponding value of \a this array, i.e.:
- * _a_ [ i, j ] -= _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _a_ [ i, j ] -= _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _a_ [ i, j ] -= _a2_ [ 0, j ].
- *
- * \param [in] other - an array to subtract from \a this one.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
- */
-void DataArrayDouble::substractEqual(const DataArrayDouble *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::substractEqual : input DataArrayDouble instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayDouble::substractEqual !";
- checkAllocated();
- other->checkAllocated();
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
- {
- if(nbOfComp==nbOfComp2)
- {
- std::transform(begin(),end(),other->begin(),getPointer(),std::minus<double>());
- }
- else if(nbOfComp2==1)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<double>(),*ptrc++));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else if(nbOfTuple2==1)
- {
- if(nbOfComp2==nbOfComp)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<double>());
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
-}
-
-/*!
- * Returns a new DataArrayDouble that is a product of two given arrays. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * the result array (_a_) is a product of the corresponding values of \a a1 and
- * \a a2, i.e. _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ].
- * 2. The arrays have same number of tuples and one array, say _a2_, has one
- * component. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, 0 ].
- * 3. The arrays have same number of components and one array, say _a2_, has one
- * tuple. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ].
- *
- * Info on components is copied either from the first array (in the first case) or from
- * the array with maximal number of elements (getNbOfElems()).
- * \param [in] a1 - a factor array.
- * \param [in] a2 - another factor array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
- * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
- * none of them has number of tuples or components equal to 1.
- */
-DataArrayDouble *DataArrayDouble::Multiply(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Multiply : input DataArrayDouble instance is NULL !");
- int nbOfTuple=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=0;
- if(nbOfTuple==nbOfTuple2)
- {
- if(nbOfComp==nbOfComp2)
- {
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfComp);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<double>());
- ret->copyStringInfoFrom(*a1);
- }
- else
- {
- int nbOfCompMin,nbOfCompMax;
- const DataArrayDouble *aMin, *aMax;
- if(nbOfComp>nbOfComp2)
- {
- nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
- aMin=a2; aMax=a1;
- }
- else
- {
- nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
- aMin=a1; aMax=a2;
- }
- if(nbOfCompMin==1)
- {
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfCompMax);
- const double *aMinPtr=aMin->getConstPointer();
- const double *aMaxPtr=aMax->getConstPointer();
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++)
- res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<double>(),aMinPtr[i]));
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
- }
- }
- else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
- {
- if(nbOfComp==nbOfComp2)
- {
- int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
- const DataArrayDouble *aMin=nbOfTuple>nbOfTuple2?a2:a1;
- const DataArrayDouble *aMax=nbOfTuple>nbOfTuple2?a1:a2;
- const double *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
- ret=DataArrayDouble::New();
- ret->alloc(nbOfTupleMax,nbOfComp);
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTupleMax;i++)
- res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::multiplies<double>());
- ret->copyStringInfoFrom(*aMax);
- }
- else
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
- }
- else
- throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
- return ret.retn();
-}
-
-/*!
- * Multiply values of another DataArrayDouble to values of \a this one. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a other array is multiplied to the corresponding value of \a this array, i.e.
- * _this_ [ i, j ] *= _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _this_ [ i, j ] *= _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _this_ [ i, j ] *= _a2_ [ 0, j ].
- *
- * \param [in] other - an array to multiply to \a this one.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
- */
-void DataArrayDouble::multiplyEqual(const DataArrayDouble *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::multiplyEqual : input DataArrayDouble instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !";
- checkAllocated();
- other->checkAllocated();
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
- {
- if(nbOfComp==nbOfComp2)
- {
- std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<double>());
- }
- else if(nbOfComp2==1)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::multiplies<double>(),*ptrc++));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else if(nbOfTuple2==1)
- {
- if(nbOfComp2==nbOfComp)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::multiplies<double>());
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
-}
-
-/*!
- * Returns a new DataArrayDouble that is a division of two given arrays. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * the result array (_a_) is a division of the corresponding values of \a a1 and
- * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, j ].
- * 2. The arrays have same number of tuples and one array, say _a2_, has one
- * component. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, 0 ].
- * 3. The arrays have same number of components and one array, say _a2_, has one
- * tuple. Then
- * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ].
- *
- * Info on components is copied either from the first array (in the first case) or from
- * the array with maximal number of elements (getNbOfElems()).
- * \warning No check of division by zero is performed!
- * \param [in] a1 - a numerator array.
- * \param [in] a2 - a denominator array.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
- * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
- * none of them has number of tuples or components equal to 1.
- */
-DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Divide : input DataArrayDouble instance is NULL !");
- int nbOfTuple1=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp1=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple2==nbOfTuple1)
- {
- if(nbOfComp1==nbOfComp2)
- {
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple2,nbOfComp1);
- std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<double>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else if(nbOfComp2==1)
- {
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const double *a2Ptr=a2->getConstPointer();
- const double *a1Ptr=a1->getConstPointer();
- double *res=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::divides<double>(),a2Ptr[i]));
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
- return 0;
- }
- }
- else if(nbOfTuple2==1)
- {
- a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple1,nbOfComp1);
- const double *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
- double *pt=ret->getPointer();
- for(int i=0;i<nbOfTuple1;i++)
- pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::divides<double>());
- ret->copyStringInfoFrom(*a1);
- return ret.retn();
- }
- else
- {
- a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
- return 0;
- }
-}
-
-/*!
- * Divide values of \a this array by values of another DataArrayDouble. There are 3
- * valid cases.
- * 1. The arrays have same number of tuples and components. Then each value of
- * \a this array is divided by the corresponding value of \a other one, i.e.:
- * _a_ [ i, j ] /= _other_ [ i, j ].
- * 2. The arrays have same number of tuples and \a other array has one component. Then
- * _a_ [ i, j ] /= _other_ [ i, 0 ].
- * 3. The arrays have same number of components and \a other array has one tuple. Then
- * _a_ [ i, j ] /= _a2_ [ 0, j ].
- *
- * \warning No check of division by zero is performed!
- * \param [in] other - an array to divide \a this one by.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
- * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
- * \a other has number of both tuples and components not equal to 1.
- */
-void DataArrayDouble::divideEqual(const DataArrayDouble *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::divideEqual : input DataArrayDouble instance is NULL !");
- const char *msg="Nb of tuples mismatch for DataArrayDouble::divideEqual !";
- checkAllocated();
- other->checkAllocated();
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple==nbOfTuple2)
- {
- if(nbOfComp==nbOfComp2)
- {
- std::transform(begin(),end(),other->begin(),getPointer(),std::divides<double>());
- }
- else if(nbOfComp2==1)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<double>(),*ptrc++));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else if(nbOfTuple2==1)
- {
- if(nbOfComp2==nbOfComp)
- {
- double *ptr=getPointer();
- const double *ptrc=other->getConstPointer();
- for(int i=0;i<nbOfTuple;i++)
- std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<double>());
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- }
- else
- throw INTERP_KERNEL::Exception(msg);
- declareAsNew();
-}
-
-/*!
- * Returns a new DataArrayDouble that is the result of pow of two given arrays. There are 3
- * valid cases.
- *
- * \param [in] a1 - an array to pow up.
- * \param [in] a2 - another array to sum up.
- * \return DataArrayDouble * - the new instance of DataArrayDouble.
- * The caller is to delete this result array using decrRef() as it is no more
- * needed.
- * \throw If either \a a1 or \a a2 is NULL.
- * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
- * \throw If \a a1->getNumberOfComponents() != 1 or \a a2->getNumberOfComponents() != 1.
- * \throw If there is a negative value in \a a1.
- */
-DataArrayDouble *DataArrayDouble::Pow(const DataArrayDouble *a1, const DataArrayDouble *a2)
-{
- if(!a1 || !a2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : at least one of input instances is null !");
- int nbOfTuple=a1->getNumberOfTuples();
- int nbOfTuple2=a2->getNumberOfTuples();
- int nbOfComp=a1->getNumberOfComponents();
- int nbOfComp2=a2->getNumberOfComponents();
- if(nbOfTuple!=nbOfTuple2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of tuples mismatches !");
- if(nbOfComp!=1 || nbOfComp2!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of components of both arrays must be equal to 1 !");
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbOfTuple,1);
- const double *ptr1(a1->begin()),*ptr2(a2->begin());
- double *ptr=ret->getPointer();
- for(int i=0;i<nbOfTuple;i++,ptr1++,ptr2++,ptr++)
- {
- if(*ptr1>=0)
- {
- *ptr=pow(*ptr1,*ptr2);
- }
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::Pow : on tuple #" << i << " of a1 value is < 0 (" << *ptr1 << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- return ret.retn();
-}
-
-/*!
- * Apply pow on values of another DataArrayDouble to values of \a this one.
- *
- * \param [in] other - an array to pow to \a this one.
- * \throw If \a other is NULL.
- * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples()
- * \throw If \a this->getNumberOfComponents() != 1 or \a other->getNumberOfComponents() != 1
- * \throw If there is a negative value in \a this.
- */
-void DataArrayDouble::powEqual(const DataArrayDouble *other)
-{
- if(!other)
- throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : input instance is null !");
- int nbOfTuple=getNumberOfTuples();
- int nbOfTuple2=other->getNumberOfTuples();
- int nbOfComp=getNumberOfComponents();
- int nbOfComp2=other->getNumberOfComponents();
- if(nbOfTuple!=nbOfTuple2)
- throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : number of tuples mismatches !");
- if(nbOfComp!=1 || nbOfComp2!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : number of components of both arrays must be equal to 1 !");
- double *ptr=getPointer();
- const double *ptrc=other->begin();
- for(int i=0;i<nbOfTuple;i++,ptrc++,ptr++)
- {
- if(*ptr>=0)
- *ptr=pow(*ptr,*ptrc);
- else
- {
- std::ostringstream oss; oss << "DataArrayDouble::powEqual : on tuple #" << i << " of this value is < 0 (" << *ptr << ") !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- declareAsNew();
-}
-
-/*!
- * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
- * Server side.
- */
-void DataArrayDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
-{
- tinyInfo.resize(2);
- if(isAllocated())
- {
- tinyInfo[0]=getNumberOfTuples();
- tinyInfo[1]=getNumberOfComponents();
- }
- else
- {
- tinyInfo[0]=-1;
- tinyInfo[1]=-1;
- }
-}
-
-/*!
- * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
- * Server side.
- */
-void DataArrayDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
-{
- if(isAllocated())
- {
- int nbOfCompo=getNumberOfComponents();
- tinyInfo.resize(nbOfCompo+1);
- tinyInfo[0]=getName();
- for(int i=0;i<nbOfCompo;i++)
- tinyInfo[i+1]=getInfoOnComponent(i);
- }
- else
- {
- tinyInfo.resize(1);
- tinyInfo[0]=getName();
- }
-}
-
-/*!
- * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
- * This method returns if a feeding is needed.
- */
-bool DataArrayDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI)
-{
- int nbOfTuple=tinyInfoI[0];
- int nbOfComp=tinyInfoI[1];
- if(nbOfTuple!=-1 || nbOfComp!=-1)
- {
- alloc(nbOfTuple,nbOfComp);
- return true;
- }
- return false;
-}
-
-/*!
- * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
- */
-void DataArrayDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
-{
- setName(tinyInfoS[0]);
- if(isAllocated())