-
Notifications
You must be signed in to change notification settings - Fork 10
/
MultiFloatsBenchmark.jl
64 lines (56 loc) · 1.71 KB
/
MultiFloatsBenchmark.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Printf
using Random
using LinearAlgebra
using GenericLinearAlgebra
using MultiFloats # Float64x2
using DoubleFloats # Double64
using Quadmath # Float128
using DecFP # Dec128
using ArbNumerics # ArbFloat
setextrabits(0)
setprecision(BigFloat, 106)
setprecision(ArbFloat, 106)
function test_qr(::Type{T}, n::Int) where {T}
Random.seed!(0)
A = T.(rand(Float64, n, n))
result = @timed qr(A)
num_correct_digits = setprecision(BigFloat, 256) do
A_big = BigFloat.(A)
Q_big = BigFloat.(result.value.Q)
R_big = BigFloat.(result.value.R)
return -log10(Float64(sum(abs.(Q_big * R_big - A_big))))
end
@printf("%s | qr | %.1f | %.6f | %.6f | %d\n", rpad(T, 24),
num_correct_digits, result.time, result.gctime, result.bytes)
end
function test_pinv(::Type{T}, m::Int, n::Int) where {T}
Random.seed!(0)
A = T.(rand(Float64, m, n))
result = @timed pinv(A)
num_correct_digits = setprecision(BigFloat, 256) do
A_big = BigFloat.(A)
Apinv = BigFloat.(result.value)
return -log10(Float64(sum(abs.(A_big * Apinv * A_big - A_big))))
end
@printf("%s | pinv | %.1f | %.6f | %.6f | %d\n", rpad(T, 24),
num_correct_digits, result.time, result.gctime, result.bytes)
end
const N = 400
const M = 250
function main()
while true
test_qr(Float64x2, N)
test_qr(Double64, N)
test_qr(Float128, N)
# test_qr(Dec128, N)
test_qr(BigFloat, N)
# test_qr(ArbFloat, N)
test_pinv(Float64x2, N, M)
test_pinv(Double64, N, M)
test_pinv(Float128, N, M)
# test_pinv(Dec128, N, M)
test_pinv(BigFloat, N, M)
# test_pinv(ArbFloat, N, M)
end
end
main()