-
Notifications
You must be signed in to change notification settings - Fork 37
Introduce vector_getrange and vector_getranges for VarInfo
#738
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
Conversation
refers to the dictionary-like length impl, not vector-like
representaiton rather than the internal representaiton into `vector_getrange` to make its function explicit
|
Technically the metadata containers should themselves implement |
getrange and getranges for VarInfovector_getrange and vector_getranges for VarInfo
Pull Request Test Coverage Report for Build 12194504389Details
💛 - Coveralls |
mhauru
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like sensible functionality to have since we support converting VarInfos to Vectors. I'm wondering about the naming. I like getrange_internal for being explicit about its use. Even if we do that, I'm not sure I would call vector_getrange just getrange, since the vector nature of a VarInfo isn't so prominent that one would immediately think of it when one sees a function called getrange. I would be happy with vector_getrange and getrange_internal. Could also consider getrange_vector or vector_range, but not sure if they are any better.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #738 +/- ##
==========================================
- Coverage 86.48% 86.32% -0.16%
==========================================
Files 35 35
Lines 4209 4249 +40
==========================================
+ Hits 3640 3668 +28
- Misses 569 581 +12 ☔ View full report in Codecov by Sentry. |
I agree with you here 👍 I think for now I'll just leave it as |
|
This is now passing in all cases except the current faililing x86 one. |
mhauru
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you here 👍 I think for now I'll just leave it as vector_getrange, and further renamings / consistency work can be done in a separate PR I'm thinking.
Happy with that since it's not exported.
Thanks @torfjelde!
Problem
At the moment, this just defers to
getrange(getmetadata(varinfo, varname), varname), which extracts the range forvarnamein the correspondingmetadata.However, there are two notions of "range" going around here:
varname.varinfo/metadatacorresponding tovarname, e.g. as obtained byvalues_to(varinfo, Vector).Currently,
getrangeeffectively corresponds to (1) in some loose sense (becausegetrange(::TypedVarInfo, ::VarName)actually returns the range used to access the vector representation inside the corresponding metadata).Specifically, consider the following
Now, this is all fine and good, however, there are cases where we actually want access to the "index that corresponds to
varnamewhen we convert the containe to a vector". In the above case, we would instead "want" thegetrangecall to return 2.Examples of functionality that depends on this: TuringLang/Turing.jl#2421, and general things such as knowing which entry to use for which varname in
initial_paramstosamplecalls.Solution
In this PR, I've added
vector_lengthandvector_getrangeforVarInfo, which implements (2) behavior rather than (1) behavior.One laternative would be to make the current
getrangefunctionality have behavior (2), and instead call the existing implgetrange_internal, which is arguably more inline with how it is used (+ this should not be implemented forAbstractVarInfoitself, only for the metadata containers).@mhauru This feelsl like one you should have a look at:)