tokyo webmining 2017-10-28
TRANSCRIPT
2017 10 28 Web
Twitter: @hamukazu
Python 5
EC ASP
• Scipy/Numpy
•
•
•
•
•
•
•
scikit-learn TensorFlow
•
•
•
•
•
Python
•Numpy
• Cython
s = 0 for i in range(1, 100000001):
s += i print(s)
1 1
s = sum(range(1, 100000001)) print(s)
import numpy as np a = np.arange(1, 100000001, dtype=np.int64) print(a.sum())
s = 0 for i in range(1, 100000001):
s += i print(s)
s = sum(range(1, 100000001)) print(s)
import numpy as np a = np.arange(1, 100000001, dtype=np.int64) print(a.sum())
30.21
12.33
0.38
Numpy
• Numpy
• Numpy
•
Cython
• Python C
•
• Numpy
Cythondef prime(n): p = [True] * (n + 1) m = 2 while m < n + 1: if p[m]: i = m * 2 while i < n + 1: p[i] = False i += m m += 1 i = n while not p[i]: i -= 1 return i
n
p(10000000)
Python 4.75 Cython 3.04
def prime(n): p = [True] * (n + 1) m = 2 while m < n + 1: if p[m]: i = m * 2 while i < n + 1: p[i] = False i += m m += 1 i = n while not p[i]: i -= 1 return i
def prime(int n): cdef int i, m p = [True] * (n + 1) m = 2 while m < n + 1: if p[m]: i = m * 2 while i < n + 1: p[i] = False i += m m += 1 i = n while not p[i]: i -= 1 return i
3.04 3.04
def prime(int n): cdef int m, i cdef int * p = <int * >malloc((n + 1) * sizeof(int)) for i in range(n + 1): p[i] = 1 m = 2 while m < n + 1: if p[m]: i = m * 2 while i < n + 1: p[i] = 0 i += m m += 1 i = n while not p[i]: i -= 1 free(p) return i
3.04 0.17
C
Cython
•
•
•
http://bit.ly/kimikazu20140913 http://bit.ly/kimikazu20160204
Python
PyCon JP 2014 2016
…
•
•
Premature optimization is the root of all evil.— Donald Knuth
•
•
•
• XP
•
•
•
•
•
•
•
XP
•
• ☓ ○
•
•
•
•
•
•
•
•
•
Scikit-learn
SpectralClustering
•
•
•
•
XTX
•
•
•
•
•
•
•
•
x
Softplus f(x) = log(1 + e
x
)
f(x) ⇡ x
f(1000)
•
•
•
•
•
• Python
•
•
•
•
•