Skip to content

Conversation

jerrymhuang
Copy link
Collaborator

Related to #508 .

Example usage:

sim = {"x": np.arange(6)}

adapter = (
    bf.adapters.Adapter()
    # ...
    .reshape("x", to=(3, 2))
    # ...
)

For this to be stateless, the original shape of data should not be stored. Therefore, the forward and inverse operations are identical.

@jerrymhuang jerrymhuang requested review from LarsKue and vpratz August 19, 2025 22:54
Copy link

codecov bot commented Aug 19, 2025

Codecov Report

❌ Patch coverage is 48.00000% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
bayesflow/adapters/transforms/reshape.py 58.82% 7 Missing ⚠️
bayesflow/adapters/adapter.py 14.28% 6 Missing ⚠️
Files with missing lines Coverage Δ
bayesflow/adapters/transforms/__init__.py 100.00% <100.00%> (ø)
bayesflow/adapters/adapter.py 83.87% <14.28%> (-2.03%) ⬇️
bayesflow/adapters/transforms/reshape.py 58.82% <58.82%> (ø)

@stefanradev93
Copy link
Contributor

Thanks Jerry! The current operation can potentially break an inference pipeline. One alternative compatible with varying shape sizes) is to store and update the shape of the most recent array after each forward transform. This renders the adapter "semi-stateful", since it needs to be called at least once in a forward manner to be able to go in reverse, but this is a given for both the training and the inference phases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this uv.lock file slipped into the PR by accident.

@vpratz
Copy link
Collaborator

vpratz commented Aug 20, 2025

I agree with Stefan that storing a state is fine here.
In my opinion, the functionality should also be able to handle batches of data of varying size. I'm not sure what the best interface for this would be. Maybe we can in/exclude axis and only reshape over the specified dimensions, keeping the others fixed? So for example to reshape over the last dimension, we could do .reshape("key", (2,4), include_axis=[-1]) to reshape a batch of shape (batch_size, set_size, 8) into a shape of (batch_size, set_size, 2, 4).

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