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

Implement custom getindex for UntypedVarInfo #704

Merged
merged 2 commits into from
Oct 31, 2024

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Oct 29, 2024

Closes #705.

Note that CI on 1.11 will still fail because of #702. However, the test/turing/varinfo.jl tests pass now. Specifically, this test:

vi = VarInfo()
test_varinfo!(vi)

Copy link

codecov bot commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 77.73%. Comparing base (18af48a) to head (1384fa5).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/varinfo.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #704      +/-   ##
==========================================
- Coverage   79.23%   77.73%   -1.50%     
==========================================
  Files          30       30              
  Lines        4214     3926     -288     
==========================================
- Hits         3339     3052     -287     
+ Misses        875      874       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@coveralls
Copy link

coveralls commented Oct 30, 2024

Pull Request Test Coverage Report for Build 11584766197

Details

  • 0 of 1 (0.0%) changed or added relevant line in 1 file are covered.
  • 32 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-2.2%) to 77.404%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/varinfo.jl 0 1 0.0%
Files with Coverage Reduction New Missed Lines %
src/contexts.jl 1 74.44%
src/varinfo.jl 1 80.24%
src/model.jl 2 92.47%
src/abstract_varinfo.jl 3 74.63%
src/context_implementations.jl 9 57.79%
src/threadsafe.jl 16 48.6%
Totals Coverage Status
Change from base Build 11518673522: -2.2%
Covered Lines: 3035
Relevant Lines: 3921

💛 - Coveralls

@penelopeysm penelopeysm marked this pull request as ready for review October 30, 2024 00:11
@penelopeysm penelopeysm force-pushed the py/untyped-varinfo-getindex branch from 83d5b65 to 35e3c34 Compare October 30, 2024 00:35
src/varinfo.jl Outdated
Comment on lines 1697 to 1699
getindex(vi::UntypedVarInfo, spl::Sampler) = copy(getindex(vi.metadata.vals, _getranges(vi, spl)))
getindex(vi::VarInfo, spl::Sampler) = copy(getindex_internal(vi, _getranges(vi, spl)))
function getindex(vi::TypedVarInfo, spl::Sampler)
Copy link
Member Author

@penelopeysm penelopeysm Oct 30, 2024

Choose a reason for hiding this comment

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

Not 100% sure whether we still need this method on L1698 (the one with vi::VarInfo), although I think we do as it would still catch VectorVarInfo. I think you all are best placed to comment since you've worked on it :)

FWIW, I removed L1698 and tests still passed locally, so as far as our test suite is concerned it isn't needed. But I don't think that's necessarily the best indication.

I did also consider, instead of implementing getindex, implementing getindex_internal for the appropriate combination of inputs. I didn't entirely like that because the second argument would be Vector{Int64}, which seemed out of place compared to the other implementations of getindex_internal. It seemed 'simpler' to me to directly overload getindex. But totally happy to do otherwise, if there is a semantic difference between the two.

Copy link
Member

Choose a reason for hiding this comment

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

There is a semantic difference, namely that getindex should get the value transformed back to original space whereas getindex_internal accesses the internal storage directly, but the existing getindex(vi::VarInfo, spl::Sampler) already violates that so I don't think it matters. All the indexing by samplers is on its way out anyway.

I would keep the existing method to catch VectorVarInfo, as you said.

Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

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

LGTM

src/varinfo.jl Outdated
Comment on lines 1697 to 1699
getindex(vi::UntypedVarInfo, spl::Sampler) = copy(getindex(vi.metadata.vals, _getranges(vi, spl)))
getindex(vi::VarInfo, spl::Sampler) = copy(getindex_internal(vi, _getranges(vi, spl)))
function getindex(vi::TypedVarInfo, spl::Sampler)
Copy link
Member

Choose a reason for hiding this comment

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

There is a semantic difference, namely that getindex should get the value transformed back to original space whereas getindex_internal accesses the internal storage directly, but the existing getindex(vi::VarInfo, spl::Sampler) already violates that so I don't think it matters. All the indexing by samplers is on its way out anyway.

I would keep the existing method to catch VectorVarInfo, as you said.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@penelopeysm penelopeysm merged commit 99def88 into master Oct 31, 2024
4 of 10 checks passed
@penelopeysm penelopeysm deleted the py/untyped-varinfo-getindex branch October 31, 2024 19:57
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.

getindex(vi::UntypedVarInfo, spl::AbstractSampler) fails
3 participants