mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 23:20:29 -05:00
#12489 Improve robustness of mean calculators
Replace asserts with early-return guards so zero or negative weights are silently skipped instead of crashing. Add unit tests for zero-weight and zero-value edge cases in all three calculator classes. Fixes #12489.
This commit is contained in:
1 parent
ba1055fbc4
commit
394bc6c3df
6 files changed
+122
-13
No files matched your search
@@ -18,8 +18,6 @@
|
||||
|
||||
#include "RiaWeightedGeometricMeanCalculator.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -36,7 +34,7 @@ RiaWeightedGeometricMeanCalculator::RiaWeightedGeometricMeanCalculator()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaWeightedGeometricMeanCalculator::addValueAndWeight( double value, double weight )
|
||||
{
|
||||
CVF_ASSERT( weight >= 0.0 );
|
||||
if ( weight <= 0.0 ) return;
|
||||
|
||||
// This can be a very big number, consider other algorithms if that becomes a problem
|
||||
m_aggregatedWeightedValue += ( std::log( value ) * weight );
|
||||
|
||||
Reference in new issue
Block a user