Skip to content

Commit 5483c0e

Browse files
authored
Fix for disappearing Around (#663)
## Changes * Due to a weed in Wolfram Language, `MeanAround` sometimes returns a single number instead of `Around`: ```wl In[] := MeanAround[{1, 1}] Out[] = 1 ``` * This [sometimes breaks](https://app.circleci.com/pipelines/github/maxitg/SetReplace/2018/workflows/77fc408b-d297-4efd-a01c-517ad52ccb54/jobs/4997) `./performanceTest.wls`, which assumes `Around` objects. * This PR implements a workaround for this case. ## Examples * This case happens rarely, but manually assigning `magnitude = 1` in `differenceString` does work: ```console $ ./performanceTest.wls master HEAD 2 Testing 811551c Testing 19264e2884d6d3cc6831c1fcce2941225f7d217c Single-input rule 1 ± 0 % Medium rule 1 ± 0 % Sequential rule 1 ± 0 % Large rule 1 ± 0 % Exponential-match-count rule 1 ± 0 % CA emulator 1 ± 0 % Multiset addition 1 ± 0 % ```
1 parent 811551c commit 5483c0e

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

performanceTest.wls

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Check[
106106
result
107107
];
108108

109+
speedupDelta[0, new_] := Infinity;
109110
speedupDelta[old_, new_] := (old - new) / old;
110111

111112
$gitRepo = GitOpen[$SetReplaceRoot];
@@ -151,10 +152,13 @@ Check[
151152

152153
differenceString[meanAround_] := With[{
153154
magnitude = QuantityMagnitude[meanAround, "Percent"]},
154-
If[5 * magnitude[[2]] < Abs[magnitude[[1]]], If[magnitude[[1]] > 0, $greenColor, $redColor], $whiteColor] <>
155-
FirstCase[
156-
MakeBoxes[magnitude, StandardForm],
157-
TemplateBox[{value_, error_}, "Around", ___] :> value <> " \[PlusMinus] " <> error <> " %"] <>
155+
(* Due to a weed in WL, MeanAround does not return Around if all values in the list are the same. *)
156+
magnitudeMean = If[Head[magnitude] === Around, magnitude["Value"], magnitude];
157+
magnitudeUncertainty = If[Head[magnitude] === Around, magnitude["Uncertainty"], 0];
158+
If[5 * magnitudeUncertainty < Abs[magnitudeMean], If[magnitudeMean > 0, $greenColor, $redColor], $whiteColor] <>
159+
FirstCase[MakeBoxes[magnitude, StandardForm],
160+
TemplateBox[{value_, error_}, "Around", ___] :> value <> " \[PlusMinus] " <> error <> " %",
161+
ToString[magnitudeMean] <> " \[PlusMinus] 0 %"] <>
158162
$endColor
159163
];
160164

0 commit comments

Comments
 (0)