Skip to content

Conversation

@ricardoV94
Copy link
Member

Showed up in pymc-devs/pymc-extras#615

I don't actually know how to define such a Scan naturally, but there's no reason why it shouldn't be handled correctly.

if trace.shape[0] > buffer_size:
# Trace is longer than buffer, keep just the last `buffer.shape[0]` entries
partial_trace = trace[-buffer_size:]
elif trace.shape[0] == buffer_size:
Copy link
Member Author

@ricardoV94 ricardoV94 Jan 5, 2026

Choose a reason for hiding this comment

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

The else branch would end up doing [-0:] slice (which selects everything ... yay Python). I suppose when I wrote this code I found no test failing, and in the cases where I could trigger it it always did the right thing, so I removed it. This is more readable anyway

trace[-buffer_size:] if trace.shape[0] > buffer else trace
)

assert partial_trace.shape[0] == buffer_size
Copy link
Member Author

@ricardoV94 ricardoV94 Jan 5, 2026

Choose a reason for hiding this comment

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

This is a case where assert does the right thing. Signals a bug to the developer that a user should never find :)

@ricardoV94 ricardoV94 added scan bug Something isn't working labels Jan 5, 2026
@ricardoV94 ricardoV94 merged commit 10e5c92 into pymc-devs:main Jan 5, 2026
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working scan

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants