Skip to content

Commit 36c369c

Browse files
committed
RunningStatistics Combine Method Must Always Return a New Instance
Breaking: RunningStatistics is now sealed Closes #1021
1 parent 306fb06 commit 36c369c

File tree

8 files changed

+22
-11
lines changed

8 files changed

+22
-11
lines changed

src/Data.Matlab/Data.Matlab.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Random: NextBigIngegerSequence ~Silver-Fang
2525
Random: xoshiro256StarStar fix out of range exception ~Charlie Turndorf
2626
Precision: Perf: pre-compute negative powers ~Febin
2727
Optimizations: Remove static properties in LevenbergMarquardtMinimizer ~Jong Hyun Kim
28-
Root Finding: Newton-Raphson better handling of zero-evaluations
28+
Root Finding: Newton-Raphson better handling of zero-evaluations ~jkalias
2929
Fit.Curve and FindMinimum extended to accept two more parameters
3030
Fixed an index out of bounds issue when calculating BFGS minimizer with one variable ~Shiney
3131
Fixed Sparse COO NormalizeDuplicates ~Mohamed Moussa

src/Data.Text/Data.Text.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Random: NextBigIngegerSequence ~Silver-Fang
2525
Random: xoshiro256StarStar fix out of range exception ~Charlie Turndorf
2626
Precision: Perf: pre-compute negative powers ~Febin
2727
Optimizations: Remove static properties in LevenbergMarquardtMinimizer ~Jong Hyun Kim
28-
Root Finding: Newton-Raphson better handling of zero-evaluations
28+
Root Finding: Newton-Raphson better handling of zero-evaluations ~jkalias
2929
Fit.Curve and FindMinimum extended to accept two more parameters
3030
Fixed an index out of bounds issue when calculating BFGS minimizer with one variable ~Shiney
3131
Fixed Sparse COO NormalizeDuplicates ~Mohamed Moussa

src/FSharp/FSharp.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Random: NextBigIngegerSequence ~Silver-Fang
2424
Random: xoshiro256StarStar fix out of range exception ~Charlie Turndorf
2525
Precision: Perf: pre-compute negative powers ~Febin
2626
Optimizations: Remove static properties in LevenbergMarquardtMinimizer ~Jong Hyun Kim
27-
Root Finding: Newton-Raphson better handling of zero-evaluations
27+
Root Finding: Newton-Raphson better handling of zero-evaluations ~jkalias
2828
Fit.Curve and FindMinimum extended to accept two more parameters
2929
Fixed an index out of bounds issue when calculating BFGS minimizer with one variable ~Shiney
3030
Fixed Sparse COO NormalizeDuplicates ~Mohamed Moussa

src/Numerics/Numerics.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Random: NextBigIngegerSequence ~Silver-Fang
2525
Random: xoshiro256StarStar fix out of range exception ~Charlie Turndorf
2626
Precision: Perf: pre-compute negative powers ~Febin
2727
Optimizations: Remove static properties in LevenbergMarquardtMinimizer ~Jong Hyun Kim
28-
Root Finding: Newton-Raphson better handling of zero-evaluations
28+
Root Finding: Newton-Raphson better handling of zero-evaluations ~jkalias
2929
Fit.Curve and FindMinimum extended to accept two more parameters
3030
Fixed an index out of bounds issue when calculating BFGS minimizer with one variable ~Shiney
3131
Fixed Sparse COO NormalizeDuplicates ~Mohamed Moussa

src/Numerics/Statistics/RunningStatistics.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace MathNet.Numerics.Statistics
4747
/// It is not recommended to rely on this mechanism for durable persistence.
4848
/// </remarks>
4949
[DataContract(Namespace = "urn:MathNet/Numerics")]
50-
public class RunningStatistics
50+
public sealed class RunningStatistics
5151
{
5252
[DataMember(Order = 1)]
5353
long _n;
@@ -73,6 +73,17 @@ public class RunningStatistics
7373
public RunningStatistics()
7474
{
7575
}
76+
77+
public RunningStatistics(RunningStatistics runningStatistics)
78+
{
79+
_n = runningStatistics._n;
80+
_min = runningStatistics._min;
81+
_max = runningStatistics._max;
82+
_m1 = runningStatistics._m1;
83+
_m2 = runningStatistics._m2;
84+
_m3 = runningStatistics._m3;
85+
_m4 = runningStatistics._m4;
86+
}
7687

7788
public RunningStatistics(IEnumerable<double> values)
7889
{
@@ -203,11 +214,11 @@ public static RunningStatistics Combine(RunningStatistics a, RunningStatistics b
203214
{
204215
if (a._n == 0)
205216
{
206-
return b;
217+
return new RunningStatistics(b);
207218
}
208-
else if (b._n == 0)
219+
if (b._n == 0)
209220
{
210-
return a;
221+
return new RunningStatistics(a);
211222
}
212223

213224
long n = a._n + b._n;

src/Providers.CUDA/Providers.CUDA.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Random: NextBigIngegerSequence ~Silver-Fang
2525
Random: xoshiro256StarStar fix out of range exception ~Charlie Turndorf
2626
Precision: Perf: pre-compute negative powers ~Febin
2727
Optimizations: Remove static properties in LevenbergMarquardtMinimizer ~Jong Hyun Kim
28-
Root Finding: Newton-Raphson better handling of zero-evaluations
28+
Root Finding: Newton-Raphson better handling of zero-evaluations ~jkalias
2929
Fit.Curve and FindMinimum extended to accept two more parameters
3030
Fixed an index out of bounds issue when calculating BFGS minimizer with one variable ~Shiney
3131
Fixed Sparse COO NormalizeDuplicates ~Mohamed Moussa

src/Providers.MKL/Providers.MKL.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Random: NextBigIngegerSequence ~Silver-Fang
2525
Random: xoshiro256StarStar fix out of range exception ~Charlie Turndorf
2626
Precision: Perf: pre-compute negative powers ~Febin
2727
Optimizations: Remove static properties in LevenbergMarquardtMinimizer ~Jong Hyun Kim
28-
Root Finding: Newton-Raphson better handling of zero-evaluations
28+
Root Finding: Newton-Raphson better handling of zero-evaluations ~jkalias
2929
Fit.Curve and FindMinimum extended to accept two more parameters
3030
Fixed an index out of bounds issue when calculating BFGS minimizer with one variable ~Shiney
3131
Fixed Sparse COO NormalizeDuplicates ~Mohamed Moussa

src/Providers.OpenBLAS/Providers.OpenBLAS.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Random: NextBigIngegerSequence ~Silver-Fang
2525
Random: xoshiro256StarStar fix out of range exception ~Charlie Turndorf
2626
Precision: Perf: pre-compute negative powers ~Febin
2727
Optimizations: Remove static properties in LevenbergMarquardtMinimizer ~Jong Hyun Kim
28-
Root Finding: Newton-Raphson better handling of zero-evaluations
28+
Root Finding: Newton-Raphson better handling of zero-evaluations ~jkalias
2929
Fit.Curve and FindMinimum extended to accept two more parameters
3030
Fixed an index out of bounds issue when calculating BFGS minimizer with one variable ~Shiney
3131
Fixed Sparse COO NormalizeDuplicates ~Mohamed Moussa

0 commit comments

Comments
 (0)