Hi, I am new to Julia and I am writing a program that makes a random matrix drawn from the Haar distribution. It works fine for small matrices ~200x200 but when I try for 1000x1000 the program takes a very long time to run. I am not sure what the issue is here.
using Random, LinearAlgebra
using Plots
function mkHaar(dimMat)
#initialize random number generatore and create complex 4x4 normal random matrix
rng = MersenneTwister()
rndMat = randn(rng, ComplexF64, (dimMat, dimMat))
Z = qr(rndMat)
L = Diagonal(Z.R)/abs.(Diagonal(Z.R))
rndHaar = Z.Q*L
#We can check to see that rndHaar is Unitary
#println(adjoint(rndHaar)*rndHaar)
#and that the eigenvalue phases are uniformly distributed
EV = eigvals(rndHaar)
phaseEV = angle.(EV)
#Make histogram
gr(size = (300,300), legend = false)
#create binning breaks
binbrks = range(-pi, stop = pi, length = 25)
p = histogram(phaseEV,bins=binbrks)
display(p)
end
To avoid having an explosion of the number of *(...) methods we need, it might be nice to have some kind of ExpensiveIndexing trait that generic methods can check to see if they need to make a Matrix copy before executing indexing-heavy algorithms.
Thanks for all the replies they were very helpful. For now I think I will just add the Matrix() since it is the simplest but Iāll do some performance checks and see whatās the best way to handle this in the future.