-
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
Ind2x mvec #32
base: master
Are you sure you want to change the base?
Ind2x mvec #32
Conversation
Could potentially be a breaking change if users were relying on the return type of |
@MaximeBouton shall we merge this? |
I like using StaticArrays! Shouldn't you be able to get it down to 0 allocs though? You have only reduced it to 1000000 from 2000000 |
ndims = dimensions(grid) | ||
x = Array{Float64}(undef, ndims) | ||
x::MVector{D, Float64} = @MVector zeros(D) |
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.
if we want to reduce allocation to zero, adding a container for x
in grid might do it. @zsunberg @mattuntergassmair
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.
You mean adding a MVector{D, Float64}
as a field to the RectangleGrid
struct, so we can simply use that to store the result instead of allocating - did I understand the suggestion correctly?
It would help with the allocations, but I think what would happen is that if you call ind2x()
twice, and you are still holding on to the result computed in the first call, then it gets overwritten in the second call without the user noticing, right?
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 guess in that case users should just pre-allocate memory on their side and use ind2x!()
rather than ind2x()
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.
x is typically pretty low-dimensional, right? I think ind2x should return an SVector. I think that should get rid of all the allocations and save a large amount of time.
In fact, I think the calls between ind2x and ind2x! should be switched, i.e. ind2x should contain the logic, and ind2x! should be implemented as
function ind2x!(grid, ind, x)
x[:] = ind2x(grid, ind)
end
src/GridInterpolations.jl
Outdated
ind2x!(grid, ind, x) | ||
x::Array{Float64} | ||
x::MVector{D, Float64} |
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.
why do you need the type annotation here? I would check with @code_warntype
that this is type stable.
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 just kept the type annotation that was already present in the form of ::Array{Float64}
, but should not be necessarry, agreed. My understanding was that it's more explicit than required, but also doesn't harm, right?
As for the allocations, I'm running the function |
I think this is fine. If people are relying on a concrete array type, I will not feel sorry if their code gets broken :) |
Shouldn't we expect a similar speed up by replacing those: |
True, we could probly fix the size of most vectors that are part of the |
Those allocations are in the constructor, so I don't think it will make too
much difference because they are only done once when the object is
constructed.
…On Fri, Mar 6, 2020 at 4:29 PM Maxime ***@***.***> wrote:
Shouldn't we expect a similar speed up by replacing those:
https://github.com/sisl/GridInterpolations.jl/blob/master/src/GridInterpolations.jl#L36
by mutable statically sized arrays?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#32?email_source=notifications&email_token=ABALI26NZBQ4T2K4OVNV5OTRGGBODA5CNFSM4LCUEXH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEODFVIY#issuecomment-596007587>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABALI27K3ONJYOXWJJKLJTLRGGBODANCNFSM4LCUEXHQ>
.
|
Agreed that it may not make a difference in the constructor itself, but we could make the member variables static in size, maybe the fixed size helps with memory optimization. I can give it a shot and report back. |
|
For a broader utilization of |
What is the status of this PR? |
It seems that pre-specifying the vector size using
MVector
fromStaticArrays
helps to significantly improve the performance ofind2x