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

Deprecate ScalarSharedVariable #629

Merged

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Feb 5, 2024

Description

As explained in the related issue this class is messy because it internally upcasts the values to 0d arrays, so that shared(shared(5).get_value()) belongs to a different class than shared(5) but are exactly the same objects otherwise!

This was a source of bugs in PyMC. The way you create an object shouldn't matter for type checks, only what you actually ended up creating!

There is a proper ScalarSharedVariable if someone really wants to work with scalar types

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

Comment on lines 12 to 23
def __getattr__(name):
if name == "ScalarSharedVariable":
warnings.warn(
"The class `ScalarSharedVariable` has been deprecated. "
"Use `TensorSharedVariable` instead and check for `ndim==0`.",
FutureWarning,
)
return TensorSharedVariable


Copy link
Member

Choose a reason for hiding this comment

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

very clever!

Copy link
Member Author

@ricardoV94 ricardoV94 Feb 5, 2024

Choose a reason for hiding this comment

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

Oops not clever enough, have to fallback to AttributeError

@ricardoV94 ricardoV94 marked this pull request as draft February 5, 2024 23:22
@ricardoV94 ricardoV94 force-pushed the deprecate_scalar_shared_variable branch from ae4fe70 to e82d86c Compare February 6, 2024 09:12
@ricardoV94 ricardoV94 marked this pull request as ready for review February 6, 2024 09:13
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1091b44) 80.82% compared to head (e82d86c) 80.83%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #629   +/-   ##
=======================================
  Coverage   80.82%   80.83%           
=======================================
  Files         162      162           
  Lines       46744    46743    -1     
  Branches    11418    11417    -1     
=======================================
+ Hits        37783    37786    +3     
+ Misses       6716     6714    -2     
+ Partials     2245     2243    -2     
Files Coverage Δ
pytensor/tensor/sharedvar.py 91.48% <100.00%> (+8.15%) ⬆️

@ricardoV94 ricardoV94 merged commit dffad9a into pymc-devs:main Feb 6, 2024
53 checks passed
@ricardoV94 ricardoV94 deleted the deprecate_scalar_shared_variable branch February 6, 2024 10:20
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.

Remove tensor.ScalarSharedVariable
3 participants