Add boolean-based indexing (e.g., `Y[Z == 1]`)
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 2.8k
- Forks
- 388
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 15
Description
Summary:
A useful addition for simpler expressions with more complex indexing/subsetting would be to support logical indices. On the backend, this could just be syntactic sugar which first constructs an array of indices of the true values before passing to the existing indexing implementations.
C++ example:
template <typename EigVec>
inline auto rvalue(EigVec&& v, const char* name, std::vector<bool> lgl_idx) {
std::vector<int> idx;
for (int i = 0; i < lgl_idx.size(); i++) {
if (lgl_idx[i]) {
idx.push_back(i);
}
}
return rvalue(std::forward<EigVec>(v), name, index_multi(idx));
}
A simpler alternative, we could add an std::vector<bool> constructor for index_multi which performs the same logic above.
This also has a bit of overlap with the use of bool-ish types in the Stan languages, so there might be some edge-case/interaction that I'm not thinking of. Thoughts?
Current Version:
v2.35.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/stan/model/indexing/index.hpp and the existing indexing implementations, then trace how rvalue handles index_multi. Compare the proposed rvalue overload with an index_multi constructor, including interactions with bool-like Stan types. Done means boolean indices such as Y[Z == 1] follow the existing indexing behavior, including relevant edge cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100