-
Notifications
You must be signed in to change notification settings - Fork 9
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
Use similar
in creation of DiffResults buffer
#95
Changes from 2 commits
3d14e53
01d2745
00af713
9634308
39dd7c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ Allocate a DiffResults buffer for a gradient, taking the element type of `x` int | |
function _diffresults_buffer(ℓ, x) | ||
T = eltype(x) | ||
S = T <: Real ? float(Real) : Float64 # heuristic | ||
DiffResults.MutableDiffResult(zero(S), (Vector{S}(undef, dimension(ℓ)), )) | ||
DiffResults.MutableDiffResult(zero(S), (similar(x, S), )) | ||
end | ||
|
||
""" | ||
|
@@ -25,5 +25,6 @@ constructed with [`diffresults_buffer`](@ref). Gradient is not copied as caller | |
vector. | ||
""" | ||
function _diffresults_extract(diffresult::DiffResults.DiffResult) | ||
# NOTE: Is this still needed? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not affected by the change above, is it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also don't understand why it would not be needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah, it was a note by me so we I could ask why it's there:) As in, can we just remove it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would you use instead? The purpose was to collect everything related to extraction in a single function. I am open to suggestions, but simply removing it would break the package (the function is used). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I thought the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I no longer recall the case for Please also remove the comment, and then I am happy to merge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done:) |
||
DiffResults.value(diffresult)::Real, DiffResults.gradient(diffresult) | ||
end |
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.
Should this still take into account
dimension
? I'm not sure but I assume there was a reason why it was used instead ofx
?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.
Currently all it uses from
x
is its element type, and it takes the dimension from the first argument.I think it could be done differently, using the dimension from
x
, and then maybeℓ
would not need to be an argument at all.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.
So
similar
basically does this. And AFAIK this is only called from thelogdensity_and_gradient
method, meaning thatx
should always have the correct dimensions.Using
dimension
fromℓ
instead will sometimes result in loss of structure of the original type forx
, e.g.ComponentArrays
.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 would recommend something like
with the caller modified accordingly.
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.
This is what I've impleented, right? Or are my eyes deceiving me?
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 think @tpapp's point is that the first argument of the function should be dropped if we do not use it anymore.