Skip to content

Wrong answers for Tropical{Float32} #19

Open
@chriselrod

Description

@chriselrod

e.g.

julia> using TropicalNumbers, Octavian, TropicalGEMM, BenchmarkTools, Tullio

julia> v2!(r, d) = @tullio (max) r[j, i] = d[k, j] + d[i, k]
v2! (generic function with 1 method)

julia> d = rand(Float32, 4000, 4000); r = similar(d); td = Tropical.(d); tr = similar(td);

julia> typeof(tr)
Matrix{TropicalF32} (alias for Array{Tropical{Float32}, 2})

julia> typeof(td)
Matrix{TropicalF32} (alias for Array{Tropical{Float32}, 2})

julia> @time(Octavian.matmul!(tr, td', td'));
 11.552436 seconds (28.39 M allocations: 1.414 GiB, 7.06% gc time, 198.04% compilation time)

julia> @time(v2!(r,d));
  2.761347 seconds (439.87 k allocations: 27.319 MiB, 20.82% compilation time)

julia> r[1:10,1:10]
10×10 Matrix{Float32}:
 1.98815  1.98032  1.96756  1.97688  1.98138  1.99293  1.99121  1.99046  1.98951  1.99046
 1.98347  1.97355  1.98345  1.96617  1.98862  1.97611  1.98876  1.98316  1.98376  1.98263
 1.98005  1.98607  1.94482  1.99388  1.97896  1.98763  1.97235  1.95483  1.98607  1.97469
 1.97811  1.96782  1.96914  1.99468  1.9638   1.96488  1.99281  1.96719  1.99046  1.99007
 1.97995  1.99206  1.96033  1.99925  1.97888  1.99531  1.98424  1.97277  1.96929  1.99149
 1.98175  1.97349  1.98187  1.96846  1.97438  1.99013  1.98184  1.96848  1.97482  1.99134
 1.97559  1.99141  1.97511  1.98494  1.98186  1.97386  1.95691  1.95286  1.97816  1.98359
 1.96895  1.95868  1.96969  1.98323  1.98321  1.96809  1.96434  1.9723   1.97961  1.9598
 1.97215  1.98366  1.97773  1.98742  1.98507  1.95414  1.96615  1.98585  1.97801  1.97805
 1.98135  1.98764  1.98053  1.96926  1.97798  1.988    1.94989  1.97951  1.98827  1.99674

julia> tr[1:10,1:10]
10×10 Matrix{TropicalF32}:
 1.98814691.95458511.98138091.95968991.98950671.95050241.96699621.93183421.95988131.99388581.96013331.94265151.97896031.97234961.9721921.94187591.99367791.98928671.98162581.94386641.92675451.95174861.97590951.98424391.9692921.99472741.9677511.98547051.95490261.97862031.94665151.97511231.98186451.95691251.97815561.98606591.95999981.97991221.97201981.97014051.9721521.97772861.96719291.95840641.97800831.97739081.9583331.98297021.97573351.95704831.98525641.9765431.99437451.9657731.98231511.98879561.98412291.97844141.96145531.98014281.97676751.97536371.97929221.97165371.98090051.98721621.97940671.95653741.98025821.9635571.98244761.96387931.97121521.98196891.98593021.98826841.97884891.98573581.9794561.96087811.97121751.97730141.97136571.9852411.97949151.95112221.9590551.98356031.95176981.97244861.95613971.97146371.97765361.97380661.98543191.96935741.96785321.98948171.97197481.9628868

while it works for Float64:

julia> d = rand(4000, 4000); r = similar(d); td = Tropical.(d); tr = similar(td);

julia> @time(v2!(r,d));
  2.539927 seconds (261.82 k allocations: 16.076 MiB, 16.36% compilation time)

julia> @time(Octavian.matmul!(tr, td', td'));
  9.220967 seconds (25.62 M allocations: 1.240 GiB, 3.42% gc time, 192.78% compilation time)

julia> tr == Tropical.(r)
true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions