Add overloaded [] operator to tensor_view
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 333
- Forks
- 150
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 54
Description
This originates from a comment by @pfultz2 in PR #1124:
add overloads to tensor_view to take a range:
template<class Range, MIGRAPHX_REQUIRES(not std::is_integral<Range>{})>
T& operator[](Range&& r)
{
return (*this)(r.begin(), r.end());
}
template<class Range, MIGRAPHX_REQUIRES(not std::is_integral<Range>{})>
const T& operator[](Range&& r) const
{
return (*this)(r.begin(), r.end());
}
Then you could just write indices[idx] instead.
The goal is to overload index references within tensor views to use the stride-based logic needed to reference positions for nonstandard-shaped tensors. The overloads ultimately wrap a method in the shape class:
std::size_t shape::index(std::size_t i) const
All reference implementations of pointwise operators should support nonstandard shapes, including the scatter op which currently checks for a standard shape (not necessarily so for GPU and other targets).
The above code snippet didn't compile when simply pasted in, but should be very close to the right thing.
Verify that we can then remove the standard requirement in src/include/migraphx/op/scatter.hpp and other ops that may have it.
There aren't currently any tests for nonstandard input shapes for the reference ops; should be added when we create GPU implementations of these ops.
Contributor guide
No contributing guide indexed for this repository
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 by locating tensor_view and shape::index(std::size_t i) const, then inspect how index references are used by the reference pointwise operators. Review src/include/migraphx/op/scatter.hpp and other operations for standard-shape requirements. Done means range-based [] access uses stride-aware indexing and applicable standard-shape restrictions are removed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend, machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100