2020-10-19 21:08:55

This commit is contained in:
wizardforcel
2020-10-19 21:08:55 +08:00
parent 7f63048035
commit ab0caba1f0
140 changed files with 3982 additions and 3982 deletions

View File

@@ -6,7 +6,7 @@
In [1]:
```
```py
%%file cython_sum.pyx
def cython_sum(double[::1] a):
cdef double s = 0.0
@@ -17,14 +17,14 @@ def cython_sum(double[::1] a):
```
```
```py
Writing cython_sum.pyx
```
In [2]:
```
```py
%%file setup.py
from distutils.core import setup
from distutils.extension import Extension
@@ -39,19 +39,19 @@ setup(
```
```
```py
Writing setup.py
```
In [3]:
```
```py
!python setup.py build_ext -i
```
```
```py
running build_ext
cythoning cython_sum.pyx to cython_sum.c
building 'cython_sum' extension
@@ -64,7 +64,7 @@ C:\Anaconda\Scripts\gcc.bat -DMS_WIN64 -shared -s build\temp.win-amd64-2.7\Relea
```
```
```py
cython_sum.c: In function '__Pyx_BufFmt_ProcessTypeChunk':
cython_sum.c:13561:26: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum.c:13561:26: warning: unknown conversion type character 'z' in format [-Wformat]
@@ -103,7 +103,7 @@ cython_sum.c:15253:22: warning: too many arguments for format [-Wformat-extra-ar
In [4]:
```
```py
from cython_sum import cython_sum
from numpy import *
@@ -111,7 +111,7 @@ from numpy import *
In [5]:
```
```py
a = arange(1e6)
```
@@ -120,27 +120,27 @@ a = arange(1e6)
In [6]:
```
```py
cython_sum(a)
```
Out[6]:
```
```py
499999500000.0
```
In [7]:
```
```py
a.sum()
```
Out[7]:
```
```py
499999500000.0
```
@@ -148,31 +148,31 @@ Out[7]:
In [8]:
```
```py
%timeit cython_sum(a)
```
```
```py
100 loops, best of 3: 2.14 ms per loop
```
In [9]:
```
```py
%timeit a.sum()
```
```
```py
100 loops, best of 3: 2.38 ms per loop
```
In [10]:
```
```py
import zipfile
f = zipfile.ZipFile('07-06-cython-sum.zip','w',zipfile.ZIP_DEFLATED)