Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork11.9k
Closed
Description
When I run this:
importnumpyasnpclassMyThing(object):def__init__(self,shape):self.shape=shapedef__len__(self):returnself.shape[0]def__getitem__(self,i):ifnotisinstance(i,tuple):i= (i,)iflen(i)>len(self.shape):raiseIndexError("boo")returnMyThing(self.shape[len(i):])def__rmul__(self,other):print"RMUL"returnselfprintnp.float64(5)*MyThing((3,3))
I get this:
RMULRMULRMULRMULRMULRMULRMULRMULRMUL[[<__main__.MyThing object at 0x2298b90> <__main__.MyThing object at 0x2298bd0> <__main__.MyThing object at 0x2298c10>] [<__main__.MyThing object at 0x2298c50> <__main__.MyThing object at 0x2298c90> <__main__.MyThing object at 0x2298cd0>] [<__main__.MyThing object at 0x2298d10> <__main__.MyThing object at 0x2298d50> <__main__.MyThing object at 0x2298d90>]]Is there a way to tellnumpy, "no, don't worry about it, just call__rmul__ on the whole thing, instead of picking it apart?"
In my specific case,MyThing is an array-like object that lives on a GPU, and while it's possible (and not necessarily incorrect) to pick the array apart in this way, it's unexpected and hasreally terrible performance.
(sorry about the many edits)
Metadata
Metadata
Assignees
Labels
No labels