Skip to content

Instantly share code, notes, and snippets.

View beam2d's full-sized avatar

Seiya Tokui beam2d

View GitHub Profile
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)
$ nosetests -s test_foo.py
foo 140123586741304
.foo2 140123497640736
.
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
del 140123586741304
del 140123497640736
@beam2d
beam2d / ensure_init.py
Created January 7, 2019 09:25
Ensure super __init__ is called
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})
@beam2d
beam2d / pyfinal.py
Created March 7, 2019 02:54
pyfinal
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: