From 01262f44f4310f19adf0b37db8be94736cda0efe Mon Sep 17 00:00:00 2001 From: alexkowa Date: Mon, 22 Jan 2024 07:35:35 +0100 Subject: [PATCH] fix ForLoop indentation and missing brackets --- src/Mdav.h | 175 +++++++++++++++++++++++------------------------------ 1 file changed, 76 insertions(+), 99 deletions(-) diff --git a/src/Mdav.h b/src/Mdav.h index 73bb1ba2..3f47e0fb 100644 --- a/src/Mdav.h +++ b/src/Mdav.h @@ -32,16 +32,14 @@ TDist *g_pMissingValueDist = NULL; TDist DistXX(TData *Valuevs, TData *pT) { TDist Dist = 0.0; - ForLoopD (i, g_NbVar) - { + ForLoopD (i, g_NbVar){ TData Value = Valuevs[i];//GetValue(i, s); - if ((Value == g_MissingValue) ^ (pT[i] == g_MissingValue)) - { + if ((Value == g_MissingValue) ^ (pT[i] == g_MissingValue)){ Dist += g_pMissingValueDist[i]; - } - else + }else{ Dist += (TDist) (Squared(Value - pT[i]) * g_pWeight[i]); + } } return Dist; } @@ -50,29 +48,25 @@ TDist DistXX(TData *Valuevs, TData *pT) TDist Dist(TData *Value1v, TData *Value2v) { TDist Dist = 0.0; - ForLoopD (i,g_NbVar) - { + ForLoopD (i,g_NbVar){ TData Value1 = Value1v[i], Value2 = Value2v[i]; - if ((Value1 == g_MissingValue) ^ (Value2 == g_MissingValue)) - { + if ((Value1 == g_MissingValue) ^ (Value2 == g_MissingValue)){ Dist += g_pMissingValueDist[i]; - } - else + }else{ Dist += (TDist) (Squared(Value1 - Value2) * g_pWeight[i]); + } } return Dist; } void AddRow(TData *pTotal, TData *Value1v, int *pNbNonMissingValue) { - ForLoopD (j, g_NbVar) - { + ForLoopD (j, g_NbVar){ TData Value = Value1v[j];//GetValue(j, Row); - if (Value != g_MissingValue) - { + if (Value != g_MissingValue){ pTotal[j] += Value; ++pNbNonMissingValue[j]; } @@ -110,61 +104,57 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S g_pMissingValueDist = new TDist[g_NbVar]; float g_MissingValue_temp=Rcpp::as(g_MissingValue_R); g_MissingValue=g_MissingValue_temp; - ForLoop (i, g_NbVar) + ForLoop (i, g_NbVar){ g_pWeight[i] = 1; - //=== Compute Var Variances & Divide Weight by them - ForLoop (i, g_NbVar) - { - //=== Compute Average & Squared Sum - double Avr = 0.0, - SquaredSum = 0.0; - int NbNonMissingRow = 0; - TData MinV = 0.0, MaxV = 0.0; - BOOL First = TRUE; - - ForLoop (j, g_NbRow) - { - TData Value = Mat(j, i); - - if (Value == g_MissingValue) + } + //=== Compute Var Variances & Divide Weight by them + ForLoop (i, g_NbVar){ + //=== Compute Average & Squared Sum + double Avr = 0.0, + SquaredSum = 0.0; + int NbNonMissingRow = 0; + TData MinV = 0.0, MaxV = 0.0; + BOOL First = TRUE; + + ForLoop (j, g_NbRow){ + TData Value = Mat(j, i); + + if (Value == g_MissingValue){ continue; - - if (First) - { - MinV = MaxV = Value; - First = FALSE; - } - else - { - MinV = Min(MinV, Value); - MaxV = Max(MaxV, Value); - } - - ++NbNonMissingRow; - Avr += Value; - SquaredSum += Squared(Value); - } - - if (NbNonMissingRow) - { - Avr /= NbNonMissingRow; - SquaredSum /= NbNonMissingRow; - } - double Variance = SquaredSum - Squared(Avr); - if (Variance) - g_pWeight[i] /= Variance; - - g_pMissingValueDist[i] = (TDist) (Squared(MaxV - MinV) * g_pWeight[i]); } + if (First){ + MinV = MaxV = Value; + First = FALSE; + }else{ + MinV = Min(MinV, Value); + MaxV = Max(MaxV, Value); + } + ++NbNonMissingRow; + Avr += Value; + SquaredSum += Squared(Value); + } + + if (NbNonMissingRow){ + Avr /= NbNonMissingRow; + SquaredSum /= NbNonMissingRow; + } + double Variance = SquaredSum - Squared(Avr); + if (Variance){ + g_pWeight[i] /= Variance; + } + g_pMissingValueDist[i] = (TDist) (Squared(MaxV - MinV) * g_pWeight[i]); + } //=== Build list of active Rows - ForLoop (i, g_NbRow-1) + ForLoop (i, g_NbRow-1){ pNextIndex[i] = i + 1; + } pNextIndex[g_NbRow-1] = -1; - ForLoop (i, g_NbRow-1) + ForLoop (i, g_NbRow-1){ pPrevIndex[i+1] = i; + } pPrevIndex[0] = -1; //=== Core Loop: It always removes to groups of observations of size k therefore it has to stop, when only NbRowLeft-g_K*2>=g_K @@ -192,8 +182,7 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S AddRow(pCenter, pVar1, pNbNonMissingValue); } - ForLoop (j, g_NbVar) - { + ForLoop (j, g_NbVar){ if (pNbNonMissingValue[j]) pCenter[j] /= pNbNonMissingValue[j]; else @@ -206,8 +195,7 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S // k = 0; - for (i = FirstIndex; i >= 0; i = pNextIndex[i]) - { + for (i = FirstIndex; i >= 0; i = pNextIndex[i]){ ForLoop (ii, g_NbVar){ pVar1[ii]=Mat(i,ii); } @@ -221,13 +209,11 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S // ASSERT(k == NbRowLeft); // Find the K closest rows & average them, both from Farthest Row & Opposite Farthest Row - ForLoop (l, ngroups) - { + ForLoop (l, ngroups){ //=== Calculate Distances from Farthest Row int Farthest = FirstIndex, Closest = FirstIndex; - for (i = FirstIndex; i >= 0; i = pNextIndex[i]) - { + for (i = FirstIndex; i >= 0; i = pNextIndex[i]){ ForLoop (ii, g_NbVar){ pVar1[ii]=Mat(i,ii); pVar2[ii]=Mat(CurrentFarthest,ii); @@ -252,24 +238,21 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S ClearMemV(HashList, -1); - for (i = FirstIndex; i >= 0; i = pNextIndex[i]) - { + for (i = FirstIndex; i >= 0; i = pNextIndex[i]){ TDist Dist = pDist[i]; int HashIndex = (int) (es_NbHashListXX * (Dist - MinD) / DeltaD); int Index = HashList[HashIndex]; - if (Index >= 0 && pDist[Index] < Dist) - { - while (pNextInHash[Index] >= 0 && pDist[pNextInHash[Index]] < Dist) + if (Index >= 0 && pDist[Index] < Dist){ + while (pNextInHash[Index] >= 0 && pDist[pNextInHash[Index]] < Dist){ Index = pNextInHash[Index]; + } int NextIndex = pNextInHash[Index]; pNextInHash[Index] = i; pNextInHash[i] = NextIndex; - } - else - { + }else{ pNextInHash[i] = Index; HashList[HashIndex] = i; } @@ -280,19 +263,16 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S ClearMemT(pNbNonMissingValue, g_NbVar); k = 0; - ForLoop (i, es_NbHashListXX) - { + ForLoop (i, es_NbHashListXX){ int Index = HashList[i]; - while (Index >= 0) - { + while (Index >= 0){ ForLoop (ii, g_NbVar){ pVar1[ii]=Mat(Index,ii); } AddRow(pCenter, pVar1, pNbNonMissingValue); ++k; - if (k >= g_K) - { + if (k >= g_K){ i = es_NbHashListXX; break; } @@ -301,8 +281,7 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S } } - ForLoop (j, g_NbVar) - { + ForLoop (j, g_NbVar){ if (pNbNonMissingValue[j]) pCenter[j] /= pNbNonMissingValue[j]; else @@ -311,16 +290,14 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S k = 0; - ForLoop (i, es_NbHashListXX) - { + ForLoop (i, es_NbHashListXX){ int Index = HashList[i]; - while (Index >= 0) - { - - ForLoop (j, g_NbVar) - Res(Index,j)=pCenter[j]; + while (Index >= 0){ + ForLoop (j, g_NbVar){ + Res(Index,j)=pCenter[j]; + } //=== Remove from List if (FirstIndex == Index) @@ -365,18 +342,18 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S ++k; } - ForLoop (j, g_NbVar) - { - if (pNbNonMissingValue[j]) + ForLoop (j, g_NbVar){ + if (pNbNonMissingValue[j]){ pCenter[j] /= NbRowLeft; - else + }else{ pCenter[j] = g_MissingValue; + } } - for (i = FirstIndex; i >= 0; i = pNextIndex[i]) - { - ForLoop (j, g_NbVar) + for (i = FirstIndex; i >= 0; i = pNextIndex[i]){ + ForLoop (j, g_NbVar){ Res(i, j )=pCenter[j]; + } } } // /*funktionieren distanzen?!??!*/