Skip to content

Remove shape functions #6556

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

Merged
merged 3 commits into from
Mar 17, 2023
Merged

Conversation

symeneses
Copy link
Contributor

@symeneses symeneses commented Mar 2, 2023

What is this PR about?
It solves #6107

Checklist

Major / Breaking Changes

  • ...

New features

  • ...

Bugfixes

  • ...

Documentation

  • Functions deleted from the API docs.

Maintenance

  • ...

@symeneses symeneses requested review from ricardoV94 and Armavica March 2, 2023 16:02
@codecov
Copy link

codecov bot commented Mar 2, 2023

Codecov Report

Merging #6556 (c937001) into main (bae121a) will increase coverage by 48.03%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #6556       +/-   ##
===========================================
+ Coverage   41.29%   89.33%   +48.03%     
===========================================
  Files          93       93               
  Lines       15717    15684       -33     
===========================================
+ Hits         6491    14011     +7520     
+ Misses       9226     1673     -7553     
Impacted Files Coverage Δ
pymc/distributions/multivariate.py 92.21% <100.00%> (+59.57%) ⬆️
pymc/distributions/shape_utils.py 94.94% <100.00%> (+63.46%) ⬆️

... and 73 files with indirect coverage changes

Copy link
Member

@michaelosthege michaelosthege left a comment

Choose a reason for hiding this comment

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

Wow, this must be a record ratio of lines deleted vs. lines added. Awesome!

@@ -1651,7 +1650,9 @@ def rng_fn(cls, rng, mu, rowchol, colchol, size=None):
output_shape = size + dist_shape

# Broadcasting all parameters
(mu,) = broadcast_dist_samples_to(to_shape=output_shape, samples=[mu], size=size)
shapes = [mu.shape, output_shape]
sp_shapes = [s[len(size) :] if size == s[: min([len(size), len(s)])] else s for s in shapes]
Copy link
Member

Choose a reason for hiding this comment

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

Did you test this by hand?
I'd feel better it this line was covered by tests, or refactored to be easier to comprehend (or both)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To test that we are getting the correct broadcastable shape, I think the best option is to keep the function broadcast_dist_samples_shape and its tests. shapes_broadcasting is replaced by np.broadcast_shapes. PR updated.
Also, more tests may be needed, using only what I added here was not correct but all tests were passing.

@ricardoV94
Copy link
Member

You may be able to use this utility to broadcast everything: https://github.com/pymc-devs/pytensor/blob/63f8d6e732cd19e7f8940e25e4c44231e7765f96/pytensor/tensor/random/utils.py#L24

Although I think this RV was never properly implemented as a RandomVariable. For instance if size=None, the size should be given by the batch dimensions of the parameters. Also dist_shape should use rowcol.shape[-1] or [-2] not [0]

Copy link
Member

@michaelosthege michaelosthege left a comment

Choose a reason for hiding this comment

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

LGTM

@ricardoV94
Copy link
Member

This PR may need a rebase before we can merge

@symeneses
Copy link
Contributor Author

You may be able to use this utility to broadcast everything: https://github.com/pymc-devs/pytensor/blob/63f8d6e732cd19e7f8940e25e4c44231e7765f96/pytensor/tensor/random/utils.py#L24

Although I think this RV was never properly implemented as a RandomVariable. For instance if size=None, the size should be given by the batch dimensions of the parameters. Also dist_shape should use rowcol.shape[-1] or [-2] not [0]

I haven't had the time to review this ☝🏽
Should I rebase and merge this PR? or should I check these two topics first?

@ricardoV94
Copy link
Member

ricardoV94 commented Mar 15, 2023

We can rebase and merge this one as is if it's working and keep cleaning it up in future PRs

@symeneses symeneses force-pushed the remove-shape-functions branch from c13206d to c937001 Compare March 16, 2023 10:50
@michaelosthege michaelosthege added this to the v5.2.0 milestone Mar 16, 2023
@ricardoV94
Copy link
Member

ricardoV94 commented Mar 17, 2023

Opened an issue for the MatrixNormal, #6606 which I am not very confident is (or was) working correctly. Would have to check what actual tests there are. Otherwise the changes seem sensible.

Thanks @symeneses

@ricardoV94 ricardoV94 merged commit c7279b5 into pymc-devs:main Mar 17, 2023
@symeneses
Copy link
Contributor Author

Opened an issue for the MatrixNormal, #6066 which I am not very confident is (or was) working correctly. Would have to check what actual tests there are. Otherwise the changes seem sensible.

Thanks @symeneses

#6066 is a PR not an issue. I could have a look to the tests based on your previous comment and in the new issue.

@symeneses symeneses deleted the remove-shape-functions branch March 23, 2023 09:27
@ricardoV94
Copy link
Member

Thanks, it was a typo. The issue is #6606

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants