Skip to content

Conversation

@devmotion
Copy link
Member

Fixes the unnecessary allocation introduced in #431 (see https://github.com/TuringLang/AdvancedHMC.jl/pull/431/files#r2128763944). I could have just reverted to the state prior to #431 but I felt that it would be cleaner to just not use res at all in the case fullTraj = false.

# Remove undef
if FullTraj
res = res[isassigned.(Ref(res), 1:n_steps)]
resize!(res, i)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed a bit useless to compute the not-undefed entries if we already know that exactly entries 1 to i are assigned some value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! The resize is better than the previous one.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2025

AdvancedHMC.jl documentation for PR #454 is available at:
https://TuringLang.github.io/AdvancedHMC.jl/previews/PR454/

@devmotion devmotion merged commit 81443d8 into main Jun 9, 2025
15 of 19 checks passed
@devmotion devmotion deleted the dw/step_allocations branch June 9, 2025 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants