|
| 1 | +using Base.FastMath: mul_fast, add_fast, div_fast |
| 2 | + |
1 | 3 | function test_semiring(a::T, b::T, c::T) where {T <: AbstractSemiring} |
2 | 4 | # 1 is the multiplicative identity |
3 | 5 | @test one(T) * a ≈ a * one(T) ≈ a |
@@ -56,6 +58,18 @@ function test_quantale(a::T, b::T, c::T) where {T <: AbstractSemiring} |
56 | 58 | @test (a < b) == (a != b && a <= b) |
57 | 59 | end |
58 | 60 |
|
| 61 | +function test_fast(a::T, b::T, c::T) where {T <: AbstractSemiring} |
| 62 | + @test a + b ≈ add_fast(a, b) |
| 63 | + @test a * b ≈ mul_fast(a, b) |
| 64 | + @test a ∧ b ≈ inf_fast(a, b) |
| 65 | + @test a / b ≈ div_fast(a, b) |
| 66 | + @test a \ b ≈ ldiv_fast(a, b) |
| 67 | + |
| 68 | + @test (a * b) + c ≈ fma(a, b, c) |
| 69 | + @test (a \ b) ∧ c ≈ fli(a, b, c) |
| 70 | + @test (a / b) ∧ c ≈ fri(a, b, c) |
| 71 | +end |
| 72 | + |
59 | 73 | @testset "interface" begin |
60 | 74 | types = ( |
61 | 75 | TropicalMinPlusF64, |
|
71 | 85 | b = rand(T) |
72 | 86 | c = rand(T) |
73 | 87 |
|
| 88 | + test_fast(a, b, c) |
74 | 89 | test_quantale(a, b, c) |
75 | 90 | test_quantale(zero(T), b, c) |
76 | 91 | end |
|
86 | 101 | c = 3 // 4 |
87 | 102 |
|
88 | 103 | for T in types |
| 104 | + test_fast(T(a), T(b), T(c)) |
89 | 105 | test_quantale(T(a), T(b), T(c)) |
90 | 106 | test_quantale(zero(T), T(b), T(c)) |
91 | 107 | test_quantale(typemax(T), T(b), T(c)) |
|
0 commit comments