Skip to content

Commit

Permalink
Update MultiFloatsBenchmark.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhang314 committed Sep 30, 2024
1 parent 222874a commit 2438063
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions scripts/MultiFloatsBenchmark.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Printf
using Random
using LinearAlgebra
using GenericLinearAlgebra
Expand All @@ -15,17 +16,28 @@ setprecision(ArbFloat, 106)
function test_qr(::Type{T}, n::Int) where {T}
Random.seed!(0)
A = T.(rand(Float64, n, n))
result, elapsed_time, _, _, _ = @timed qr(A)
num_correct_digits = -log10(Float64(sum(abs.(result.Q * result.R - A))))
println(rpad(T, 30), " | qr | ", round(num_correct_digits, digits=1), " | ", elapsed_time)
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))
Apinv, elapsed_time, _, _, _ = @timed pinv(A)
num_correct_digits = -log10(Float64(sum(abs.(A * Apinv * A - A))))
println(rpad(T, 30), " | pinv | ", round(num_correct_digits, digits=1), " | ", elapsed_time)
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
Expand All @@ -36,9 +48,9 @@ function main()
test_qr(Float64x2, N)
test_qr(Double64, N)
test_qr(Float128, N)
test_qr(Dec128, N)
# test_qr(Dec128, N)
test_qr(BigFloat, N)
test_qr(ArbFloat, N)
# test_qr(ArbFloat, N)

test_pinv(Float64x2, N, M)
test_pinv(Double64, N, M)
Expand Down

0 comments on commit 2438063

Please sign in to comment.