Hi all,

I have this code with two types, one is an observation with a name, a time, 
and a vector of observed values.
Another is a system where observations are stored, it comprises a list of 
names nl which is an index of all the observation names, an observation 
list ol which is a vector of tuples (t,v) where t is the time of an 
observation and v is a vector of observed values. I also define a function 
set to add the observation in the correct place in ol, i.e. at the index of 
the name of this observation.

Maybe it will be clearer with some code:

type obs
    n
    t
    v
end

type system
    nl::Array{AbstractString}
    ol::Array{Array{Tuple{Int64, Array{Float64}}}}
    set::Function
    function system(nl)
        instance = new()
        instance.nl = nl
        instance.ol = Array(Array{Tuple{Int64, Array{Float64}}}, 
length(instance.nl))
        fill!(instance.ol, Tuple{Int64, Array{Float64}}[])
        instance.set = function(o)
            push!(instance.ol[findfirst(instance.nl, o.n)], (o.t, o.v))
        end
        return instance
    end
end

So now, if I try this very simple example:

o1 = obs("b",4,[1.0,3.0])
o2 = obs("c",6,[2.0,4.0])
nl = ["a","b","c"]
s = system(nl)
s.set(o1)
println(s.ol[1])
println(s.ol[2])
s.set(o2)
println(s.ol[1])
println(s.ol[2])

where I defined two observations, a system with a name list, and if I set 
the two observations in my system, it puts each observation to everywhere 
in ol, see the output:

Tuple{Int64,Array{Float64,N}}[(4,[1.0,3.0])]
Tuple{Int64,Array{Float64,N}}[(4,[1.0,3.0])]
Tuple{Int64,Array{Float64,N}}[(4,[1.0,3.0]),(6,[2.0,4.0])]
Tuple{Int64,Array{Float64,N}}[(4,[1.0,3.0]),(6,[2.0,4.0])]

where I was expecting something like:

Tuple{Int64,Array{Float64,N}}[(4,[1.0,3.0])]
Tuple{Int64,Array{Float64,N}}[]
Tuple{Int64,Array{Float64,N}}[(4,[1.0,3.0])]
Tuple{Int64,Array{Float64,N}}[(6,[2.0,4.0])]

Why is an observation pushed everywhere?

I should mention the fact that this code was working perfectly fine under 
0.3.11 and I modified it so that it run under 0.4. (I mainly had to change 
the Tuple syntax.)

Any idea would be welcome, thanks!

Reply via email to