You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is actually more of a discussion thread since I have an implementation here, but I wanted to discuss the general idea before submitting a PR.
Essentially, I propose that we allow to access a tensor dimension by a one-character abbreviation as well as its name. This would make working with namedtensors a lot less verbose, however this might go against the general principles of namedtensor as ensuring greater safety.
Example:
Given tensor t = ntorch.ones(2, 3, 5, names=('batch', 'width', 'height')) then we can refer to these dimensions just by their first letter sot[{'b': 0}] is equivalent to t[{'batch': 0}]
If there's ambiguity in abbreviations, we allow creation of the tensor:
t = ntorch.ones(2, 3, 5, names=('axis1', 'axis2', 'axis3')) #valid
But we throw an ambiguity error if we try to access in an ambiguous fashion:
t = ntorch.ones(2, 3, 5, names=('axis1', 'b:axis2', 'c:axis3')) #valid
t[{'a': 0}] # now valid as only one axis has abbreviation 'a'
Unfortunately this required a lot of code rewriting and adds a little bit more complexity,although the result is arguably more elegant, see the comparison. However I believe this is worthwhile, especially as it makes it easier to add in other features such as dimension labels.
The text was updated successfully, but these errors were encountered:
This is actually more of a discussion thread since I have an implementation here, but I wanted to discuss the general idea before submitting a PR.
Essentially, I propose that we allow to access a tensor dimension by a one-character abbreviation as well as its name. This would make working with namedtensors a lot less verbose, however this might go against the general principles of namedtensor as ensuring greater safety.
Example:
Given tensor
t = ntorch.ones(2, 3, 5, names=('batch', 'width', 'height'))
then we can refer to these dimensions just by their first letter sot[{'b': 0}]
is equivalent tot[{'batch': 0}]
If there's ambiguity in abbreviations, we allow creation of the tensor:
But we throw an ambiguity error if we try to access in an ambiguous fashion:
To enable abbreviations to still be used with ambiguous names, we allow setting the abbreviation manually with
a:name
:Unfortunately this required a lot of code rewriting and adds a little bit more complexity,although the result is arguably more elegant, see the comparison. However I believe this is worthwhile, especially as it makes it easier to add in other features such as dimension labels.
The text was updated successfully, but these errors were encountered: