]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - JETAN/AliKMeansClustering.cxx
Update from Sandun
[u/mrichter/AliRoot.git] / JETAN / AliKMeansClustering.cxx
old mode 100755 (executable)
new mode 100644 (file)
index f23ec64..618b676
@@ -32,7 +32,7 @@ ClassImp(AliKMeansClustering)
 Double_t AliKMeansClustering::fBeta = 10.;
 
  
-Int_t AliKMeansClustering::SoftKMeans(Int_t k, Int_t n, Double_t* x, Double_t* y, Double_t* mx, Double_t* my , Double_t* rk )
+Int_t AliKMeansClustering::SoftKMeans(Int_t k, Int_t n, const Double_t* x, const Double_t* y, Double_t* mx, Double_t* my , Double_t* rk )
 {
     //
     // The soft K-means algorithm
@@ -397,7 +397,7 @@ Double_t AliKMeansClustering::d(Double_t mx, Double_t my, Double_t x, Double_t y
 
 
 
-void AliKMeansClustering::OptimalInit(Int_t k, Int_t n, Double_t* x, Double_t* y, Double_t* mx, Double_t* my)
+void AliKMeansClustering::OptimalInit(Int_t k, Int_t n, const Double_t* x, const Double_t* y, Double_t* mx, Double_t* my)
 {
   //  
   // Optimal initialisation using the k-means++ algorithm
@@ -481,15 +481,30 @@ AliKMeansResult& AliKMeansResult::operator=(const AliKMeansResult& res)
   //
   // Assignment operator
   if (this != &res) {
-    fK = res.GetK();
-    for (Int_t i = 0; i <fK; i++) {
-      fMx[i]     = (res.GetMx())    [i];
-      fMy[i]     = (res.GetMy())    [i];
-      fSigma2[i] = (res.GetSigma2())[i];
-      fRk[i]     = (res.GetRk())    [i];
-      fTarget[i] = (res.GetTarget())[i];
-      fInd[i]    = (res.GetInd())   [i];
+    TObject::operator=(res);
+    if (fK != res.fK) {
+       delete [] fMx;
+       delete [] fMy;
+       delete [] fSigma2;
+       delete [] fRk;
+       delete [] fTarget;
+       delete [] fInd;
+       fK = res.fK;
+       fMx     = new Double_t[fK];
+       fMy     = new Double_t[fK];
+       fSigma2 = new Double_t[fK];
+       fRk     = new Double_t[fK];
+       fTarget = new Double_t[fK];
+       fInd    = new    Int_t[fK];
     }
+    
+    fK = res.fK;
+    memcpy(fMx,     res.fMx,     fK*sizeof(Double_t));
+    memcpy(fMy,     res.fMy,     fK*sizeof(Double_t));
+    memcpy(fSigma2, res.fSigma2, fK*sizeof(Double_t));
+    memcpy(fRk,     res.fRk,     fK*sizeof(Double_t));
+    memcpy(fTarget, res.fTarget, fK*sizeof(Double_t));
+    memcpy(fInd,    res.fInd,    fK*sizeof(Int_t));
   }
   return *this;
 }
@@ -520,7 +535,7 @@ void AliKMeansResult::Sort()
   TMath::Sort(fK, fTarget, fInd);
 }
 
-void AliKMeansResult::Sort(Int_t n, Double_t* x, Double_t* y)
+void AliKMeansResult::Sort(Int_t n, const Double_t* x, const Double_t* y)
 {
   // Build target array and sort
   for (Int_t i = 0; i < fK; i++)
@@ -541,7 +556,7 @@ void AliKMeansResult::Sort(Int_t n, Double_t* x, Double_t* y)
   TMath::Sort(fK, fTarget, fInd);
 }
 
-void AliKMeansResult::CopyResults(AliKMeansResult* res)
+void AliKMeansResult::CopyResults(const AliKMeansResult* res)
 {
   fK = res->GetK();
   for (Int_t i = 0; i <fK; i++) {