-
Notifications
You must be signed in to change notification settings - Fork 12
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
Attempt to improve type stability #47
Conversation
Thanks for the PR! It looks like some of the tests are not passing? |
I'll try to fix it. I will also add some additional tests. |
As described here (https://discourse.julialang.org/t/staticarrays-and-allocations/62123) @Marrays will sometimes be allocated to the heap and sometimes to the stack
OK, the tests are passing now. I also attempted to reduce the allocations in the |
It seems to break on Julia 1.0. We don't necessarily have to provide backward support to 1.0, but it might be nice if it is not too complicated.
|
Sure, I think just removing the test for allocations might fix that. (I don't have julia 1.0 installed to check) Does it work now? |
Got it. I think we can merge this after @zsunberg gives us a thumbs up! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ctessum ! This is a huge help. The only thing I am concerned about is replacing zeros
/ones
with undef
. Can you respond to that before we merge?
index = MVector{num_points, Int}(undef) | ||
index2 = MVector{num_points, Int}(undef) | ||
weight = MVector{num_points, eltype(x)}(undef) | ||
weight2 = MVector{num_points, eltype(x)}(undef) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit concerned about this change. How can we be completely sure that it does not change the code logic to initialize these to undef
rather than ones or zeros? (note that the tests may pass most of the time even if the code relies on zeros since memory is often initialized to zeros or small numbers.)
I think we should either leave this as is (with ones or zeros) or carefully go through the code below looking at all of the assignments to these variables and write out a brief proof that the initialization does not matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Zeroing memory typically does not have an impact on runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original goal for that change was to reduce allocations, because the ones()
and zeros()
calls would theoretically be allocating arrays, although I guess the compiler could be factoring that out. From looking at the code I don't believe the arrays need to be explicitly initialized, but just in case I've added it back in, just using broadcasting instead of allocating new arrays for the initialization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ctessum ! Yeah, If I remember correctly, we verified that @MVector zeros(...)
etc. does not allocate as long as the MVector does not leave the scope of the function. I added an explanatory note.
If we wanted to avoid this and be explicit about proving that the initialization doesn't matter, we could use PushVector
s backed with MVector
s, but that might require some work.
Cool. I think we can merge once @zsunberg concerns are addressed in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now
@ctessum Thanks again! One note for the future: this PR was a bit hard to read because it included both substantive changes to the code and a bunch of minor style changes (e.g. adding spaces). The style changes are nice, but it is better to make separate PRs, just so that it is easy to see and deal with the important changes 😄 |
BTW I tried to add allocation tests in #50, but they are failing :/ It seems like we didn't quite prevent all the allocations. The results were the same before this PR though. |
Sorry about the style changes, they were just added automatically and I didn't notice until later. |
Fixes #38