harvardnlp / namedtensor

Named Tensor implementation for Torch
http://nlp.seas.harvard.edu/NamedTensor
MIT License
441 stars 42 forks source link

Addition isn't commutative (if dimensions are ordered) #56

Open zou3519 opened 5 years ago

zou3519 commented 5 years ago

It feels a little weird, but I guess it is fine if the dimensions aren't supposed to be ordered

y = ntorch.randn(1, 1, 1, 1, names=['n', 'c', 'h', 'w'])
x = ntorch.randn(1, 1, names=['h', 'c'])

(x + y).shape
OrderedDict([('n', 1), ('w', 1), ('h', 1), ('c', 1)])

(y + x).shape
OrderedDict([('n', 1), ('c', 1), ('h', 1), ('w', 1)])
srush commented 5 years ago

Yes, we've been debating this point. The current aggressive proposal is to change shape to not be an ordereddict at all, and remove the transpose function or have it return a non-named tensor.