Skip to content
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

dataset_to_point_list fails when chain, draw are not the leading dims #7178

Closed
ricardoV94 opened this issue Feb 29, 2024 · 1 comment · Fixed by #7180
Closed

dataset_to_point_list fails when chain, draw are not the leading dims #7178

ricardoV94 opened this issue Feb 29, 2024 · 1 comment · Fixed by #7180
Labels
bug samplers trace-backend Traces and ArviZ stuff

Comments

@ricardoV94
Copy link
Member

Description

import pymc as pm

with pm.Model(coords={"trial": [0]}) as m:
    x = pm.Normal("x", shape=(1,), dims="trial")
    y = pm.Normal("y", x, observed=[5], dims="trial")
    
    idata = pm.sample(tune=0, draws=10)
    idata = idata.posterior.transpose("chain", "trial", "draw")
    pm.sample_posterior_predictive(idata)  # IndexError: index 2 is out of bounds for axis 0 with size 2

CC @OriolAbril

@ricardoV94 ricardoV94 added bug trace-backend Traces and ArviZ stuff samplers labels Feb 29, 2024
@OriolAbril
Copy link
Member

I am actually surprised it breaks there and not in the reshaping part. The culprit is clearly this line:

vn: da.transpose(*sample_dims, ...).values.reshape((-1, *da.shape[num_sample_dims:]))

we transpose the dataarray to have everything work independently of the dimension order, but then the reshape uses the yet-to-be-transposed dataarray to get the shape of the final array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug samplers trace-backend Traces and ArviZ stuff
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants