-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Surprising behavior of append!(..) #113
Comments
I found a work around: Base.append!(v::Vector{T}, s::T) where {T<:MonteCarloMeasurements.Particles} = Base.push!(v,s) but I hope this can be fixed in a better way. |
Hello Martin, I assume you mean that your expect v2 (not v3) to have only three particle elements? First note that
is incorrect usage of
The usage above leads to the incorrect result due to a fallback in Base that iterates the argument to be appended and since particles are iterable, you get unexpected results. It can be debated whether or not particles should be iterable, perhaps they should not, in which case the problem would go away. |
Yes, I meant v2. In my application, code is generated and when generating code it is not known whether the variable to be appended is a scalar or a vector. Its not critical, since I have a workaround. It would be nice, if there would be no exception in such a corner case. Maybe its related: When developing code and then switch the type (using MonteCarloMeasurements), its annoying that length(s3) returns 3 and not 1 (although length(s1) returns 1). I had therefore to introduce at various places checks whether the type is MonteCarloMeasurements or not and then implement different code. |
I agree, these differences between a regular |
@MartinOtter On master I know have julia> append!(v2,s4)
3-element Vector{Particles{Float64, 3}}:
0.0 ± 0.967
0.0 ± 0.967
0.0 ± 1.93 which I hope is what you expected? julia> s3
0.0 ± 0.967
julia> length(s3)
1 So to conclude, |
Thanks very much. Yes, this is the expected behavior |
Version 1.0 of MCM is now released |
append!(..) seems to be not working correctly with MonteCarloMeasurements (I am using Julia 1.6.2, MonteCarloMeasurements 0.10.4). The code
produces the following output
I would have expected that
v3
has three Particles and not three Float64 values and two particles.The text was updated successfully, but these errors were encountered: