Skip to content

Commit

Permalink
optimize varianceFromCellValues()
Browse files Browse the repository at this point in the history
  • Loading branch information
root676 authored and nyalldawson committed Jul 2, 2020
1 parent cf6e634 commit 294ad08
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/analysis/processing/qgsrasteranalysisutils.cpp
Expand Up @@ -348,7 +348,13 @@ double QgsRasterAnalysisUtils::stddevFromCellValues( std::vector<double> cellVal

double QgsRasterAnalysisUtils::varianceFromCellValues( std::vector<double> cellValues, int stackSize )
{
double variance = std::pow( stddevFromCellValues( cellValues, stackSize ), 2.0 );
double mean = meanFromCellValues( cellValues, stackSize );
double accum = 0.0;
for ( int i = 0; i < stackSize; i++ )
{
accum += std::pow( ( cellValues.at( i ) - mean ), 2.0 );
}
double variance = accum / static_cast<double>( stackSize );
return variance;
}

Expand Down

0 comments on commit 294ad08

Please sign in to comment.