@jisutich please evaluate these two replacements for your rand_haar2:
using
LinearAlgebra,
StatsBase,
Statistics,
Random,
StaticArrays,
Future,
DoubleFloats,
Dates
static_array_dims_product(::Type{Dims}) where {Dims <: Tuple} =
prod(Tuple(Dims.types))
random_static_array(rand::F, ::Type{Out}, ::Type{Source}, ::Type{Dims}) where
{F <: Function, Out <: Number, Source <: Number, Dims <: Tuple} =
SArray{Dims}(ntuple(
i -> Out(rand(Source)),
Val{static_array_dims_product(Dims)}()))
random_static_array(rand::F, ::Type{Out}, ::Type{Out}, ::Type{Dims}) where
{F <: Function, Out <: Number, Dims <: Tuple} =
SArray{Dims}(ntuple(
i -> rand(Out),
Val{static_array_dims_product(Dims)}()))
function rand_haar2(
::Val{n},
::Type{Src1},
::Type{Src2}) where {n, Src1 <: Number, Src2 <: Number}
M = random_static_array(Base.randn, ComplexDF64, Src1, Tuple{n, n})
q = qr(M).Q
L = map(
x -> cispi(2 * ComplexDF64(x)),
random_static_array(Base.rand, Double64, Src2, Tuple{n}))
q * diagm(L)
end
rand_haar2_fast(::Val{n}) where {n} =
rand_haar2(Val{n}(), ComplexF64, Float64)
rand_haar2_slower(::Val{n}) where {n} =
rand_haar2(Val{n}(), ComplexDF64, Double64)
Furthermore, I think that both DoubleFloats and (possibly) StaticArrays have some performance bugs. Will make a PR to DoubleFloats now.