Skip to content

Instantly share code, notes, and snippets.

View beam2d's full-sized avatar

Seiya Tokui beam2d

View GitHub Profile
@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:
@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})
$ nosetests -s test_foo.py
foo 140123586741304
.foo2 140123497640736
.
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
del 140123586741304
del 140123497640736
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)
@beam2d
beam2d / new-style-func-guideline.md
Last active February 23, 2018 01:20
New-Style Function Implementation Guideline

New-Style Function Implementation Guideline

This is a guideline to give the standard way of implementing a new-style function in Chainer. Different developers can align the coding style by writing implementations based on this document.

Basics

A new-style function implementation consists of at least two elements: an implementation of FunctionNode and a user interface function.

@beam2d
beam2d / chainer-v2-api-change.md
Last active December 22, 2016 06:37
Candidate API changes for Chainer v2

Candidate API changes for Chainer v2

In this gist, I list up the possible changes on existing APIs for Chainer v2. It also includes some ideas of adding new APIs related to existing ones. Note that this is not a complete list of future changes for v2.

Core features

Variable

  • __len__ should return the length of the first axis.
@beam2d
beam2d / invidx.py
Last active October 28, 2021 21:34
Inverted index in NumPy
import numpy as np
class InvertedIndex(object):
def __init__(self, x):
self.J = np.argsort(x)
D = np.ediff1d(x[self.J], to_begin=1, to_end=1)
self.I = np.repeat(np.arange(len(D)), D)
def __getitem__(self, k):
@beam2d
beam2d / open_prs.txt
Created September 2, 2016 05:48
Open PRs of Chainer
1582 2016-09-02 04:29:18 not commented gwtnb not assigned
1580 2016-09-01 00:50:57 2016-09-01 08:04:40 motootom bkvogel
1578 2016-08-31 15:20:16 2016-09-01 02:35:12 unnonouno not assigned
1570 2016-08-30 03:12:58 not commented gwtnb not assigned
1556 2016-08-26 14:23:08 2016-09-01 14:46:38 takagi delta2323
1553 2016-08-24 16:55:14 2016-08-25 08:05:08 unnonouno not assigned
1551 2016-08-24 14:48:08 2016-09-02 05:31:01 okuta not assigned
1543 2016-08-22 13:20:26 2016-08-24 02:26:46 boeddeker not assigned
1541 2016-08-22 08:34:24 2016-08-29 07:17:07 unnonouno delta2323
1537 2016-08-21 15:33:46 2016-08-25 06:28:49 fukatani delta2323
import maf
def configure(conf): pass
def build(exp):
exp(target='a', rule='date >> ${TGT}')
exp(source='a', target='b', rule='cp ${SRC} ${TGT}')
@beam2d
beam2d / 547.rst
Last active January 2, 2016 10:59

Parameter constraints of jubaclustering

Constraints for all methods