gonum / plot

A repository for plotting and visualizing data
BSD 3-Clause "New" or "Revised" License
2.73k stars 202 forks source link

plotter/palette/moreland: TestRgb_sRGBA and TestCreateLuminance are failing in Go >=1.10 #448

Closed sbinet closed 6 years ago

sbinet commented 6 years ago

quite recently, TestRgb_sRGBA and TestCreateLuminance started to fail with Go >= 1.10:

--- FAIL: TestRgb_sRGBA (0.00s)
    convert_test.go:28: case 0: have {R:0.12987167010866837 G:0.12987167010866837 B:0.12987167010866837 A:0}, want {R:0.1298716701086684 G:0.1298716701086684 B:0.1298716701086684 A:0}
&moreland.luminance{colors:[]moreland.cieLAB{moreland.cieLAB{L:0, A:0, B:0}, moreland.cieLAB{L:21.873483862751876, A:50.19882295659109, B:-74.66982659778303}, moreland.cieLAB{L:34.5065425137759, A:75.41302687474064, B:-88.73807072507788}, moreland.cieLAB{L:47.02980511087303, A:70.93217189227919, B:33.59880053746508}, moreland.cieLAB{L:65.17482203230537, A:49.14591409658836, B:56.86480950937553}, moreland.cieLAB{L:84.13253643355525, A:-6.459770854468639, B:82.41994470228775}, moreland.cieLAB{L:100, A:0, B:0}}, scalars:[]float64{0, 0.21873483862751875, 0.34506542513775895, 0.4702980511087303, 0.6517482203230537, 0.8413253643355525, 1}, alpha:1, min:0, max:0}
&moreland.luminance{colors:[]moreland.cieLAB{moreland.cieLAB{L:0, A:0, B:0}, moreland.cieLAB{L:10.479520542426698, A:34.055579589022045, B:-34.219348771708084}, moreland.cieLAB{L:21.03011379005111, A:52.30473571100955, B:-61.852601228346536}, moreland.cieLAB{L:31.030989279784933, A:23.814976212074455, B:-57.73419358300512}, moreland.cieLAB{L:40.21480513626115, A:-24.858012706049536, B:-7.322176588219942}, moreland.cieLAB{L:52.73108089333358, A:-19.064976357731634, B:-25.558178073848147}, moreland.cieLAB{L:60.007326812392634, A:-61.75624590074591, B:56.43522875191319}, moreland.cieLAB{L:69.81578343076002, A:-58.33353084882392, B:68.37457857626646}, moreland.cieLAB{L:79.55703752324776, A:-22.50477758899383, B:78.57946686200843}, moreland.cieLAB{L:89.818961593653, A:7.586705160677109, B:15.375961528833981}, moreland.cieLAB{L:100, A:0, B:0}}, scalars:[]float64{0, 0.10479520542426699, 0.2103011379005111, 0.3103098927978493, 0.4021480513626115, 0.5273108089333358, 0.6000732681239264, 0.6981578343076003, 0.7955703752324775, 0.89818961593653, 1}, alpha:1, min:0, max:0}
&moreland.luminance{colors:[]moreland.cieLAB{moreland.cieLAB{L:0, A:0, B:0}, moreland.cieLAB{L:13.371291966477482, A:40.39368469479174, B:-47.73239449160565}, moreland.cieLAB{L:25.072421338587567, A:-18.014410537408406, B:-5.313556572210187}, moreland.cieLAB{L:37.411516363056116, A:-43.058336774976055, B:39.30203907343062}, moreland.cieLAB{L:49.75026355291354, A:-15.774050138318895, B:53.507917567416094}, moreland.cieLAB{L:61.643756252245225, A:52.67703578954919, B:43.82595336046358}, moreland.cieLAB{L:74.93187540089826, A:50.92061741619158, B:-30.23541169796622}, moreland.cieLAB{L:87.64732748562544, A:14.355163639545697, B:-17.471161313826332}, moreland.cieLAB{L:100, A:0, B:0}}, scalars:[]float64{0, 0.13371291966477483, 0.2507242133858757, 0.37411516363056113, 0.4975026355291354, 0.6164375625224523, 0.7493187540089826, 0.8764732748562544, 1}, alpha:1, min:0, max:0}
--- FAIL: TestCreateLuminance (0.00s)
    luminance_test.go:86: ExtendedBlackBody: have &moreland.luminance{colors:[]moreland.cieLAB{moreland.cieLAB{L:0, A:0, B:0}, moreland.cieLAB{L:21.873483862751876, A:50.19882295659109, B:-74.66982659778303}, moreland.cieLAB{L:34.5065425137759, A:75.41302687474064, B:-88.73807072507788}, moreland.cieLAB{L:47.02980511087303, A:70.93217189227919, B:33.59880053746508}, moreland.cieLAB{L:65.17482203230537, A:49.14591409658836, B:56.86480950937553}, moreland.cieLAB{L:84.13253643355525, A:-6.459770854468639, B:82.41994470228775}, moreland.cieLAB{L:100, A:0, B:0}}, scalars:[]float64{0, 0.21873483862751875, 0.34506542513775895, 0.4702980511087303, 0.6517482203230537, 0.8413253643355525, 1}, alpha:1, min:0, max:0}, want &moreland.luminance{colors:[]moreland.cieLAB{moreland.cieLAB{L:0, A:0, B:0}, moreland.cieLAB{L:21.873483862751876, A:50.19882295659109, B:-74.66982659778306}, moreland.cieLAB{L:34.506542513775905, A:75.41302687474061, B:-88.73807072507786}, moreland.cieLAB{L:47.02980511087303, A:70.93217189227919, B:33.59880053746508}, moreland.cieLAB{L:65.17482203230537, A:49.14591409658836, B:56.86480950937553}, moreland.cieLAB{L:84.13253643355525, A:-6.459770854468639, B:82.41994470228775}, moreland.cieLAB{L:100, A:0, B:0}}, scalars:[]float64{0, 0.21873483862751875, 0.34506542513775906, 0.4702980511087303, 0.6517482203230537, 0.8413253643355525, 1}, alpha:1, min:0, max:0}
    luminance_test.go:86: Kindlmann: have &moreland.luminance{colors:[]moreland.cieLAB{moreland.cieLAB{L:0, A:0, B:0}, moreland.cieLAB{L:10.479520542426698, A:34.055579589022045, B:-34.219348771708084}, moreland.cieLAB{L:21.03011379005111, A:52.30473571100955, B:-61.852601228346536}, moreland.cieLAB{L:31.030989279784933, A:23.814976212074455, B:-57.73419358300512}, moreland.cieLAB{L:40.21480513626115, A:-24.858012706049536, B:-7.322176588219942}, moreland.cieLAB{L:52.73108089333358, A:-19.064976357731634, B:-25.558178073848147}, moreland.cieLAB{L:60.007326812392634, A:-61.75624590074591, B:56.43522875191319}, moreland.cieLAB{L:69.81578343076002, A:-58.33353084882392, B:68.37457857626646}, moreland.cieLAB{L:79.55703752324776, A:-22.50477758899383, B:78.57946686200843}, moreland.cieLAB{L:89.818961593653, A:7.586705160677109, B:15.375961528833981}, moreland.cieLAB{L:100, A:0, B:0}}, scalars:[]float64{0, 0.10479520542426699, 0.2103011379005111, 0.3103098927978493, 0.4021480513626115, 0.5273108089333358, 0.6000732681239264, 0.6981578343076003, 0.7955703752324775, 0.89818961593653, 1}, alpha:1, min:0, max:0}, want &moreland.luminance{colors:[]moreland.cieLAB{moreland.cieLAB{L:0, A:0, B:0}, moreland.cieLAB{L:10.479520542426698, A:34.05557958902206, B:-34.21934877170809}, moreland.cieLAB{L:21.03011379005111, A:52.30473571100955, B:-61.852601228346536}, moreland.cieLAB{L:31.03098927978494, A:23.814976212074402, B:-57.73419358300511}, moreland.cieLAB{L:40.21480513626115, A:-24.858012706049536, B:-7.322176588219942}, moreland.cieLAB{L:52.73108089333358, A:-19.064976357731634, B:-25.558178073848147}, moreland.cieLAB{L:60.007326812392634, A:-61.75624590074585, B:56.43522875191319}, moreland.cieLAB{L:69.81578343076002, A:-58.33353084882392, B:68.37457857626646}, moreland.cieLAB{L:79.55703752324776, A:-22.50477758899383, B:78.57946686200843}, moreland.cieLAB{L:89.818961593653, A:7.586705160677109, B:15.375961528833981}, moreland.cieLAB{L:100, A:0, B:0}}, scalars:[]float64{0, 0.10479520542426699, 0.2103011379005111, 0.3103098927978494, 0.4021480513626115, 0.5273108089333358, 0.6000732681239264, 0.6981578343076003, 0.7955703752324775, 0.89818961593653, 1}, alpha:1, min:0, max:0}
    luminance_test.go:86: ExtendedKindlmann: have &moreland.luminance{colors:[]moreland.cieLAB{moreland.cieLAB{L:0, A:0, B:0}, moreland.cieLAB{L:13.371291966477482, A:40.39368469479174, B:-47.73239449160565}, moreland.cieLAB{L:25.072421338587567, A:-18.014410537408406, B:-5.313556572210187}, moreland.cieLAB{L:37.411516363056116, A:-43.058336774976055, B:39.30203907343062}, moreland.cieLAB{L:49.75026355291354, A:-15.774050138318895, B:53.507917567416094}, moreland.cieLAB{L:61.643756252245225, A:52.67703578954919, B:43.82595336046358}, moreland.cieLAB{L:74.93187540089826, A:50.92061741619158, B:-30.23541169796622}, moreland.cieLAB{L:87.64732748562544, A:14.355163639545697, B:-17.471161313826332}, moreland.cieLAB{L:100, A:0, B:0}}, scalars:[]float64{0, 0.13371291966477483, 0.2507242133858757, 0.37411516363056113, 0.4975026355291354, 0.6164375625224523, 0.7493187540089826, 0.8764732748562544, 1}, alpha:1, min:0, max:0}, want &moreland.luminance{colors:[]moreland.cieLAB{moreland.cieLAB{L:0, A:0, B:0}, moreland.cieLAB{L:13.371291966477482, A:40.39368469479174, B:-47.73239449160565}, moreland.cieLAB{L:25.072421338587574, A:-18.01441053740843, B:-5.313556572210176}, moreland.cieLAB{L:37.411516363056116, A:-43.058336774976055, B:39.30203907343062}, moreland.cieLAB{L:49.75026355291354, A:-15.774050138318895, B:53.507917567416094}, moreland.cieLAB{L:61.643756252245225, A:52.67703578954919, B:43.82595336046358}, moreland.cieLAB{L:74.93187540089825, A:50.92061741619164, B:-30.235411697966242}, moreland.cieLAB{L:87.64732748562544, A:14.355163639545697, B:-17.471161313826332}, moreland.cieLAB{L:100, A:0, B:0}}, scalars:[]float64{0, 0.13371291966477483, 0.25072421338587575, 0.37411516363056113, 0.4975026355291354, 0.6164375625224523, 0.7493187540089825, 0.8764732748562544, 1}, alpha:1, min:0, max:0}
FAIL
FAIL    gonum.org/v1/plot/palette/moreland  1.417s

it seems to be some float64 precision issue (at least for the first one). here is a tentative fix for the first one:

diff --git a/palette/moreland/convert_test.go b/palette/moreland/convert_test.go
index 35e2f95..f085cf0 100644
--- a/palette/moreland/convert_test.go
+++ b/palette/moreland/convert_test.go
@@ -6,9 +6,27 @@ package moreland

 import (
        "image/color"
+       "math"
        "testing"
 )

+func eqRGBA(a, b sRGBA) bool {
+       const eps = 1e-16
+       if math.Abs(a.R-b.R) > eps {
+               return false
+       }
+       if math.Abs(a.G-b.G) > eps {
+               return false
+       }
+       if math.Abs(a.B-b.B) > eps {
+               return false
+       }
+       if math.Abs(a.A-b.A) > eps {
+               return false
+       }
+       return true
+}
+
 // TestRgb_sRGBA tests the conversion from linear RGB space to sRGB space.
 // The expected output value is from
 // http://www.kennethmoreland.com/color-maps/DivergingColorMapWorkshop.xls
@@ -24,7 +42,7 @@ func TestRgb_sRGBA(t *testing.T) {
        }
        for i, tc := range testCases {
                result := tc.l.sRGBA(0)
-               if result != tc.s {
+               if !eqRGBA(result, tc.s) {
                        t.Errorf("case %d: have %+v, want %+v", i, result, tc.s)
                }
        }
sbinet commented 6 years ago

hum... the failure seems to be intermittent...

kortschak commented 6 years ago

Yes, I've noticed that. I suspect it is more of Travis' flaky numerical hardware.

sbinet commented 6 years ago

I can reproduce it quite repeatedly on my laptop.

$> uname -a 
Linux zoidberg 4.16.7-1-ARCH #1 SMP PREEMPT Wed May 2 21:12:36 UTC 2018 x86_64 GNU/Linux

$> go version
go version devel +d2c7dec183 Sat Apr 14 05:36:36 2018 +0000 linux/amd64
kortschak commented 6 years ago

Odd.

sbinet commented 6 years ago

FYI:

$> head /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 61
model name      : Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
stepping        : 4
microcode       : 0x1d
cpu MHz         : 997.918
cache size      : 4096 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 20
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap intel_pt xsaveopt dtherm ida arat pln pts
bugs            : cpu_meltdown spectre_v1 spectre_v2
bogomips        : 5190.37
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

just updated to:

$> go version
go version devel +65c365bf0f Wed May 23 23:51:30 2018 +0000 linux/amd64

still there:

$> cd palette/moreland
$> go test -run=TestRgb_sRGBA
--- FAIL: TestRgb_sRGBA (0.00s)
    convert_test.go:28: case 0: have {R:0.12987167010866837 G:0.12987167010866837 B:0.12987167010866837 A:0}, want {R:0.1298716701086684 G:0.1298716701086684 B:0.1298716701086684 A:0}
FAIL
exit status 1
kortschak commented 6 years ago

At a guess, I'd say it was golang/go@5305bdd86bbe31d61c72e62f4e6729e3562ae178, but the addition of an epsilon in the tests is fine.