Created
July 8, 2014 20:46
-
-
Save ZGainsforth/1dc30e2126954f85cb9f to your computer and use it in GitHub Desktop.
Minimal Cython implementation (modeled from training.enthought.com example)
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 cyfib(int n): | |
cdef int a, b, i | |
a,b = 1,1 | |
for i in range(n): | |
a,b = a+b, a | |
return a |
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 pyximport | |
pyximport.install() | |
from cyfib import cyfib | |
def fib(n): | |
a,b = 1,1 | |
for i in range(n): | |
a,b = a+b, a | |
return a | |
print fib(5) | |
print cyfib(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment