I’m getting some really strange behavior, and I’m not sure what to make of it. Essentially the values in an array change based on making a call to println
elsewhere in the script. I can’t figure out how to reproduce it in a smaller example, but basically the code structure goes like
# Do lots of things
println(inconsequential_value)
# Do lots of things
ao = parseseries("ao.txt") # Function to read in data
println(cor(ao, pc)) # Gives correct value
# Plot ao and pc
for the correct case and
# Do lots of things
ao = parseseries("ao.txt") # Function to read in data
println(cor(ao, pc)) # Gives incorrect value
# Plot ao and pc incorrectly
for the bad case, where the difference is making a call to println
earlier in the code. Here are images of the two arrays. I can’t give the actual bad values because calling println
corrects the data (but passing it on to PyCall does not). What’s interesting is it gives the same wrong values every time. What I would like is some guidance on how to go about debugging this error. I went through my script commenting things out until the error went away, and I was left with a lot of unrelated stuff that has to execute before the error will appear. I’m not sure how to narrow it down further.
The bad data:
The correct data:
For the record the
parseseries
function looks like:
normalize(series) = (series .- mean(series)) / std(series)
function parseseries(filename)
open(filename) do f
data = Vector{Vector{Float64}}()
for line in eachline(f)
tokens = filter(x -> length(x) > 1, split(line, " "))
year = parse(Int, tokens[1])
!(year in 1979:2010) && continue
jan = parse(Float64, tokens[2])
feb = parse(Float64, tokens[3])
dec = parse(Float64, tokens[end])
push!(data, [jan, feb, dec])
end
results = Vector{Float64}(undef, 31)
for year in 1:30
results[year] = mean([data[year][3], data[year+1][1], data[year+1][2]])
end
return normalize(results)
end
end
but I don’t think that’s the issue. Maybe it’s a GC issue or something.
Edited to fix typo.