It should be fine even without root_2ps:
julia> x = 1:20;
julia> @. x + √(2x[3])
20-element Array{Float64,1}:
3.44949
4.44949
5.44949
6.44949
7.44949
8.44949
9.44949
10.4495
11.4495
12.4495
13.4495
14.4495
15.4495
16.4495
17.4495
18.4495
19.4495
20.4495
21.4495
22.4495
julia> versioninfo()
Julia Version 0.6.2
Commit d386e40* (2017-12-13 18:08 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: AMD Ryzen Threadripper 1950X 16-Core Processor
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT NO_LAPACK NO_LAPACKE ZEN)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.9.1 (ORCJIT, generic)
Yes, I saw u0
is read from a file.
But I would recommend you add a line like I had to randomly generate it to the code you posted, so everyone reading the thread can easily copy and paste your code to test it.
Because I couldn’t, I just looked at it and guessed, without actually being able to / bothering to test anything.
EDIT:
nE = 2
eMax = 3.0
epsilon = linspace(0, eMax, nE)
const nx = 2^12
const dx = 0.2
const dp = 2pi/ (nx * dx)
u0 = @. randn(nx,nx) + im*randn(nx,nx)
function xpgrid(nx::Int , dx::Float64, dp::Float64)
x = Array((-nx/2+1 : nx/2) * dx)
p = Array((-nx/2+1 : nx/2) * dp)
p = circshift(p, round(Int, nx/2))
x, p
end
function transition_momentum(nE, nx, dx, dp, eMax, epsilon, u0)
D = zeros(Complex{Float64}, nE, nE) #change because Complex128 will soon be deprecated
root_2eps = @. √(2epsilon)
x, p = xpgrid(nx, dx, dp) #what is this?
@inbounds for jE in 1:nE
for iE in 1:nE, jx in 1:nx
temp = zero(Complex{Float64})
for i ∈ eachindex(x)
temp += cis( x[i] * root_2eps[iE] + x[jx] * root_2eps[jE] ) * (x[i] + x[jx]) * conj(u0[i, jx])
end
D[iE, jE] += temp
end
println("jE=", jE)
end
#save("data/d.jld", "D", D)
D
end
@time transition_momentum(nE, nx, dx, dp, eMax, epsilon, u0)
@time transition_momentum(nE, nx, dx, dp, eMax, epsilon, u0)
The second run results in:
julia> @time transition_momentum(nE, nx, dx, dp, eMax, epsilon, u0)
jE=1
jE=2
1.586719 seconds (31 allocations: 97.219 KiB)
2×2 Array{Complex{Float64},2}:
5.33832e5-1.51294e6im 1.93597e6+2.96262e5im
-5.82017e5-1.36504e6im -4.47849e5-2.37888e5im