Closed noklam closed 4 years ago
@parrt I try run through the test, it seems working fine for the torch example. The downside of using type(v.shape).name is it doesn't handle the inheritance problem. But I am not aware of any other method to get rid of checking the object without actually importing
Hi @noklam thanks very much for your help! Maybe instead of if isinstance(v.shape, torch.Size)
, we ask for v.shape.__class__.__name__=='Size'
or whatever?
I don't know if there is any difference between type(v.shape).__name__
versus v.shape.__class__.__name__
https://stackoverflow.com/questions/510972/getting-the-class-name-of-an-instance Some suggesting it is a bit different in Python 2, both are fine!
@parrt
Yeah, I guess you're right. I wonder if we need to check if module is torch and name is Shape.
Re inheritance: likely most people are not subclassing torch tensors. if so, though, wouldn't Shape get inherited into subclass and our test would work?
@parrt Yes, I think it should still work. I think you mean name is Size ?
p.s. I know fastai is subclassing torch tensor. :) https://github.com/fastai/fastai/blob/e34fee816f5dcbf05a9bc9b44e617902a52549fc/fastai/torch_core.py#L300
Btw the test1.py
is failing
with dbg():
z = torch.sigmoid(self.Whz @ h + self.Uxz @ x + self.bz)
b = W @ b + np.abs(x)
I am getting
NameError: name 'self' is not defined
Added the checking for module and name
yeah test?.py are just junk drawers. deleted test1.py
yep, Shape=>Size
Looks great! Merging.
Done! Does it look right? Ter
On Oct 10, 2020, at 11:25 AM, noklam notifications@github.com wrote:
hacktoberfest-accepted
Thanks it works! Can you add it to #3 too?
Done!
On Sat, Oct 10, 2020 at 9:07 PM noklam notifications@github.com wrote:
Thanks it works! Can you add it to #3 https://github.com/parrt/tensor-sensor/pull/3 too?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/parrt/tensor-sensor/pull/10#issuecomment-706646765, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABLUWNOL4IVCMI7AJSG2DLSKEVP7ANCNFSM4SLE25OA .
-- Dictation in use. Please excuse homophones, malapropisms, and nonsense.
@parrt Thanks!
9
Get rid of importing torch.Size by using type(v.shape).name instead/