[STABLE ABI] Stable Accessor shim #4052
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Although Accessors will eventually be ported to the stable ABI, this may take some time (as Array Refs need to have a representation in the stable ABI first). This PR offers an independent Accessor functionality we can use for the time being. This allows us to make progress on the stable ABI porting (which requires accessor functionality). Especially when it comes to 3 dimensional tensors and higher, writing the stride multiplication logic manually and indexing into the flat array produces code that is not particularly readable and makes it easy to make mistakes. I think using a simple Accessor abstraction is a better way forward. This PR includes tests for the abstraction. The tests are only defined for integer tensors, but as the accessor is templated, the index calculation logic does not depend on the underlying datatype, and we should not need to test other datatypes.