Skip to content

Commit 7184550

Browse files
committed
add DoubleFloat to benchmark
1 parent 463fd84 commit 7184550

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

‎benchmark/Project.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
22
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
33
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
4+
DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78"
45
GenericLinearAlgebra = "14197337-ba66-59df-a3e3-ca00e7dcff7a"
56
GenericSchur = "c145ed77-6b09-5dd9-b285-bf645a82121e"
67
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

‎benchmark/README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
`bench_exponential.jl` times and accuracy-tests every applicable `MatrixAlgebraKit.exponential`
44
algorithm (`MatrixFunctionViaTaylor`, `MatrixFunctionViaLA`, `MatrixFunctionViaEig`,
5-
`MatrixFunctionViaEigh`) for `Float64`, `ComplexF64`, `BigFloat` and `Complex{BigFloat}`.
5+
`MatrixFunctionViaEigh`) for `Float64`, `ComplexF64`, `Double64`, `Complex{Double64}`,
6+
`BigFloat` and `Complex{BigFloat}`.
7+
The `Double64` (double-double, ~106-bit) types sit between the hardware BLAS floats and
8+
arbitrary-precision `BigFloat`, and exercise the `Eig`/`Eigh` paths through the generic
9+
GenericSchur / GenericLinearAlgebra drivers (the `LA` LAPACK path applies to BLAS types only).
610

711
Accuracy inputs are built from a *known* spectrum as `A = V · Diag(λ) · V⁻¹`, so the exact
812
`exp(A) = V · Diag(exp λ) · V⁻¹` is available analytically (computed at high precision).

‎benchmark/bench_exponential.jl‎

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ using Printf
2323
using DelimitedFiles
2424
using StableRNGs
2525
using BenchmarkTools
26+
using DoubleFloats
2627
using MatrixAlgebraKit
2728
using MatrixAlgebraKit: MatrixFunctionViaTaylor, MatrixFunctionViaLA,
28-
MatrixFunctionViaEig, MatrixFunctionViaEigh
29-
# Loading these makes the generic (BigFloat) eig / eigh drivers available.
29+
MatrixFunctionViaEig, MatrixFunctionViaEigh, QRIteration, GS, GLA
30+
# Loading these makes the generic (BigFloat / Double64) eig / eigh drivers available.
3031
using GenericSchur
3132
using GenericLinearAlgebra
3233

@@ -38,18 +39,28 @@ const CSV_PATH = let i = findfirst(==("--csv"), ARGS)
3839
i === nothing ? joinpath(@__DIR__, "results.csv") : ARGS[i + 1]
3940
end
4041

41-
const ELTYPES = (Float64, ComplexF64, BigFloat, Complex{BigFloat})
42+
# Ordered by increasing precision: hardware BLAS floats, then double-double (~106 bits,
43+
# software but fast), then arbitrary-precision BigFloat.
44+
const ELTYPES = (
45+
Float64, ComplexF64, Double64, Complex{Double64}, BigFloat, Complex{BigFloat},
46+
)
47+
48+
_isblas(::Type{T}) where {T} = T <: Union{Float32, Float64, ComplexF32, ComplexF64}
49+
_isdouble(::Type{T}) where {T} = T <: Union{Double64, Complex{Double64}}
4250

4351
# Sizes for the timing sweep (generic types are far slower, so use fewer / smaller).
52+
# Double64 is software but only ~10-30× slower than BLAS, so it gets an intermediate range;
53+
# BigFloat is far slower still.
4454
blas_sizes() = QUICK ? [8, 16, 32] : [8, 16, 32, 64, 128, 256]
55+
double_sizes() = QUICK ? [8, 16] : [8, 16, 32, 64, 128]
4556
generic_sizes() = QUICK ? [8, 16] : [8, 16, 32, 64]
46-
perf_sizes(T) = (T <: Union{Float32, Float64, ComplexF32, ComplexF64}) ? blas_sizes() : generic_sizes()
57+
perf_sizes(T) = _isblas(T) ? blas_sizes() : (_isdouble(T) ? double_sizes() : generic_sizes())
4758

4859
# Sizes for the accuracy sweep (kept small: high-precision reference is expensive).
4960
acc_sizes() = QUICK ? [12] : [16, 48]
5061

5162
# Timing budget per (matrix, algorithm), in seconds.
52-
perf_seconds(T) = QUICK ? 0.1 : (T <: Union{Float32, Float64, ComplexF32, ComplexF64} ? 0.3 : 0.8)
63+
perf_seconds(T) = QUICK ? 0.1 : (_isblas(T) ? 0.3 : 0.8)
5364

5465
# Precision of the analytic reference and its tolerance (must beat the tested precision).
5566
const HIGH_BITS = QUICK ? 512 : 1024
@@ -217,16 +228,29 @@ catch
217228
nothing
218229
end
219230

231+
# The library only registers default eig / eigh algorithms for BLAS and BigFloat element
232+
# types, but GenericSchur / GenericLinearAlgebra actually drive any `AbstractFloat`. For
233+
# types without a registered default (e.g. Double64) fall back to those drivers directly,
234+
# using the same `QRIteration` the BigFloat default resolves to.
235+
function eig_algorithm_for(A)
236+
eig = _trydefault(MatrixAlgebraKit.default_eig_algorithm, A)
237+
return eig !== nothing ? eig : QRIteration(; driver = GS())
238+
end
239+
function eigh_algorithm_for(A)
240+
eigh = _trydefault(MatrixAlgebraKit.default_eigh_algorithm, A)
241+
return eigh !== nothing ? eigh : QRIteration(; driver = GLA())
242+
end
243+
220244
function algorithms_for(A, hermitian::Bool)
221245
T = eltype(A)
222246
algs = Tuple{String, Any}[("Taylor", MatrixFunctionViaTaylor())]
223247
if T <: LinearAlgebra.BlasFloat
224248
push!(algs, ("LA", MatrixFunctionViaLA()))
225249
end
226-
eig = _trydefault(MatrixAlgebraKit.default_eig_algorithm, A)
250+
eig = eig_algorithm_for(A)
227251
eig !== nothing && push!(algs, ("Eig", MatrixFunctionViaEig(eig)))
228252
if hermitian
229-
eigh = _trydefault(MatrixAlgebraKit.default_eigh_algorithm, A)
253+
eigh = eigh_algorithm_for(A)
230254
eigh !== nothing && push!(algs, ("Eigh", MatrixFunctionViaEigh(eigh)))
231255
end
232256
return algs

0 commit comments

Comments
 (0)