Skip to content
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

setindex! in TimestepArrays with Colon doesn't work #471

Closed
corakingdon opened this issue May 3, 2019 · 5 comments
Closed

setindex! in TimestepArrays with Colon doesn't work #471

corakingdon opened this issue May 3, 2019 · 5 comments
Labels

Comments

@corakingdon
Copy link
Collaborator

I think the following is an internal bug. We have implemented setindex! functions for TimestepArrays with AnyIndex (line 268 in "src/core/time.jl" for vectors), but it appears that function is not getting used in the following code, and the values fail to be set. (I haven't tried out the debugger yet to be able to step through and see what function is actually being called in the second line)

julia> x=Mimi.TimestepVector{Mimi.FixedTimestep{2005,10}, Float64}(zeros(10))
Mimi.TimestepArray{Mimi.FixedTimestep{2005,10,LAST} where LAST,Float64,1}([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])

julia> x[:].=1
10-element Array{Float64,1}:
 1.0
 1.0
 1.0
 1.0
 1.0
 1.0
 1.0
 1.0
 1.0
 1.0

julia> x
Mimi.TimestepArray{Mimi.FixedTimestep{2005,10,LAST} where LAST,Float64,1}([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
@corakingdon corakingdon added the bug label May 3, 2019
@rjplevin
Copy link
Collaborator

rjplevin commented May 3, 2019

It appears that broadcasting .= doesn't result in calling setindex! as one would expect. I've been looking for the right method to override, but I haven't found it yet. I'm hoping @davidanthoff has run into this before.

I edited this after re-running the debugger. Stepping line by line did reveal that unsafe_copyto! is being called...

@rjplevin
Copy link
Collaborator

rjplevin commented May 3, 2019

I believe the answer is here, though it's buried pretty deep... still looking.

@rjplevin
Copy link
Collaborator

rjplevin commented May 3, 2019

The magic sauce:

Base.dotview(v::Mimi.TimestepArray, args...) = Base.dotview(v.data, args...).

@corakingdon
Copy link
Collaborator Author

amazing! thank you!

@corakingdon
Copy link
Collaborator Author

#472

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants