This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import inspect | |
import cupy as cp | |
import numpy as np | |
def cupify(f): | |
cp_f = None | |
def wrapped(*args, **kw): | |
xp = cp.get_array_module(*args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ nosetests -s test_foo.py | |
foo 140123586741304 | |
.foo2 140123497640736 | |
. | |
---------------------------------------------------------------------- | |
Ran 2 tests in 0.000s | |
OK | |
del 140123586741304 | |
del 140123497640736 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ensure_init(cls): | |
def __new__(cls, *args, **kwargs): | |
def magic_init(self): | |
self.__class__ = cls | |
self.__init__(*args, **kwargs) | |
if not self.__ensure_init: | |
raise TypeError('super __init__ not called') | |
# magic to use custom init while pretending a cls instance | |
t = type('', (cls,), {'__init__': magic_init}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import six | |
def final(f): | |
f.__is_final = True | |
return f | |
class enable_final(type): | |
def __new__(cls, name, bases, d): | |
for k in d: | |
for base in bases: |
OlderNewer