return ret.retn();
}
+/*!
+ * This method is close to numpy cumSum except that number of element is equal to \a this->getNumberOfTuples()+1. First element of DataArray returned is equal to 0.
+ * This method expects that \a this as only one component. The returned array will have \a this->getNumberOfTuples()+1 tuple with also one component.
+ * The ith element of returned array is equal to the sum of elements in \a this with rank strictly lower than i.
+ *
+ * \return DataArrayDouble - A newly built array containing cum sum of \a this.
+ */
+MCAuto<DataArrayDouble> DataArrayDouble::cumSum() const
+{
+ checkAllocated();
+ checkNbOfComps(1,"DataArrayDouble::cumSum : this is expected to be single component");
+ int nbOfTuple(getNumberOfTuples());
+ MCAuto<DataArrayDouble> ret(DataArrayDouble::New()); ret->alloc(nbOfTuple+1,1);
+ double *ptr(ret->getPointer());
+ ptr[0]=0.;
+ const double *thisPtr(begin());
+ for(int i=0;i<nbOfTuple;i++)
+ ptr[i+1]=ptr[i]+thisPtr[i];
+ return ret;
+}
+
/*!
* 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
*
* This method is useful for users having an unstructured mesh having only SEG2 to rearrange internaly the connectibity without any coordinates consideration.
*
- * \sa MEDCouplingUMesh::orderConsecutiveCells1D
+ * \sa MEDCouplingUMesh::orderConsecutiveCells1D, DataArrayInt::fromLinkedListOfPairToList
*/
void DataArrayInt::sortEachPairToMakeALinkedList()
{
}
}
+/*!
+ * \a this is expected to be a correctly linked list of pairs.
+ *
+ * \sa DataArrayInt::sortEachPairToMakeALinkedList
+ */
+MCAuto<DataArrayInt> DataArrayInt::fromLinkedListOfPairToList() const
+{
+ checkAllocated();
+ checkNbOfComps(2,"DataArrayInt::fromLinkedListOfPairToList : this is expected to have 2 components");
+ int nbTuples(getNumberOfTuples());
+ if(nbTuples<1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::fromLinkedListOfPairToList : no tuples in this ! Not a linked list !");
+ MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(nbTuples+1,1);
+ const int *thisPtr(begin());
+ int *retPtr(ret->getPointer());
+ retPtr[0]=thisPtr[0];
+ for(int i=0;i<nbTuples;i++)
+ {
+ retPtr[i+1]=thisPtr[2*i+1];
+ if(i<nbTuples-1)
+ if(thisPtr[2*i+1]!=thisPtr[2*(i+1)+0])
+ {
+ std::ostringstream oss; oss << "DataArrayInt::fromLinkedListOfPairToList : this is not a proper linked list of pair. The link is broken between tuple #" << i << " and tuple #" << i+1 << " ! Call sortEachPairToMakeALinkedList ?";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+ return ret;
+}
+
/*!
*
* \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayInt instance.
void accumulate(double *res) const;
double accumulate(int compId) const;
DataArrayDouble *accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const;
+ MCAuto<DataArrayDouble> cumSum() const;
double distanceToTuple(const double *tupleBg, const double *tupleEnd, int& tupleId) const;
DataArrayDouble *fromPolarToCart() const;
DataArrayDouble *fromCylToCart() const;
DataArrayInt *findRangeIdForEachTuple(const DataArrayInt *ranges) const;
DataArrayInt *findIdInRangeForEachTuple(const DataArrayInt *ranges) const;
void sortEachPairToMakeALinkedList();
+ MCAuto<DataArrayInt> fromLinkedListOfPairToList() const;
DataArrayInt *duplicateEachTupleNTimes(int nbTimes) const;
DataArrayInt *getDifferentValues() const;
std::vector<DataArrayInt *> partitionByDifferentValues(std::vector<int>& differentIds) const;
from math import pi,e,sqrt,cos,sin
from datetime import datetime
from MEDCouplingDataForTest import MEDCouplingDataForTest
-import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@cea.fr
+import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@edf.fr
class MEDCouplingBasicsTest5(unittest.TestCase):
def testSwig2FieldDoubleBuildSubPartRange1(self):
self.assertEqual(f2.getName(),"field")
self.assertEqual(f2.getTime(),[1.,2,3])
pass
+
+ def testDADCumSum1(self):
+ d=DataArrayDouble([3.,2.,4.,5.])
+ self.assertTrue(d.cumSum().isEqual(DataArrayDouble([0.,3.,5.,9.,14.]),1e-12))
+ d2=DataArrayDouble([])
+ self.assertTrue(d2.cumSum().isEqual(DataArrayDouble([0.]),1e-12))
+ d.rearrange(2)
+ self.assertRaises(InterpKernelException,d.cumSum)
+ pass
+
+ def testDAIFromLinkedListOfPairToList1(self):
+ d=DataArrayInt([(5,7),(7,3),(3,12),(12,17)])
+ zeRes=DataArrayInt([5,7,3,12,17])
+ self.assertTrue(d.fromLinkedListOfPairToList().isEqual(zeRes))
+ d.rearrange(1)
+ self.assertRaises(InterpKernelException,d.fromLinkedListOfPairToList)
+ d.rearrange(2)
+ self.assertTrue(d.fromLinkedListOfPairToList().isEqual(zeRes))
+ d2=DataArrayInt([(5,7)])
+ self.assertTrue(d2.fromLinkedListOfPairToList().isEqual(DataArrayInt([5,7])))
+ d3=DataArrayInt([(5,7),(7,3),(4,12),(12,17)])
+ self.assertRaises(InterpKernelException,d3.fromLinkedListOfPairToList) # not a linked list of pair
+ d4=DataArrayInt([(5,7),(7,3),(12,3),(12,17)])
+ self.assertRaises(InterpKernelException,d4.fromLinkedListOfPairToList) # not a linked list of pair, but can be repaired !
+ d4.sortEachPairToMakeALinkedList()
+ self.assertTrue(d4.fromLinkedListOfPairToList().isEqual(zeRes))
+ pass
pass
%newobject MEDCoupling::DataArrayInt::buildIntersection;
%newobject MEDCoupling::DataArrayInt::buildUnique;
%newobject MEDCoupling::DataArrayInt::buildUniqueNotSorted;
+%newobject MEDCoupling::DataArrayInt::fromLinkedListOfPairToList;
%newobject MEDCoupling::DataArrayInt::deltaShiftIndex;
%newobject MEDCoupling::DataArrayInt::buildExplicitArrByRanges;
%newobject MEDCoupling::DataArrayInt::buildExplicitArrOfSliceOnScaledArr;
%newobject MEDCoupling::DataArrayDouble::subArray;
%newobject MEDCoupling::DataArrayDouble::changeNbOfComponents;
%newobject MEDCoupling::DataArrayDouble::accumulatePerChunck;
+%newobject MEDCoupling::DataArrayDouble::cumSum;
%newobject MEDCoupling::DataArrayDouble::findIdsInRange;
%newobject MEDCoupling::DataArrayDouble::findIdsNotInRange;
%newobject MEDCoupling::DataArrayDouble::negate;
return ret.retn();
}
+ DataArrayDouble *cumSum() const throw(INTERP_KERNEL::Exception)
+ {
+ MCAuto<DataArrayDouble> ret(self->cumSum());
+ return ret.retn();
+ }
+
void pushBackValsSilent(PyObject *li) throw(INTERP_KERNEL::Exception)
{
double val;
return self->iterator();
}
+ DataArrayInt *fromLinkedListOfPairToList() const throw(INTERP_KERNEL::Exception)
+ {
+ MCAuto<DataArrayInt> ret(self->fromLinkedListOfPairToList());
+ return ret.retn();
+ }
+
DataArrayInt *selectPartDef(const PartDefinition* pd) const throw(INTERP_KERNEL::Exception)
{
MCAuto<DataArrayInt> ret(self->selectPartDef(pd));