<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 difference between cdef and cpdef
Step1:  f1 is not visible since defined via "cdef"
Step2:  filling an numpy array
Step3:  basic 
Step4:  distance function (pure python and cython)
<ASSISTANT_TASK:>
Python Code:
%%cython
cdef f1(int x):
    return x*x
cpdef f2(int x):
    return x*x
cpdef f3(int x):
    return f1(x)
#dir()
f2(3)
Explanation: difference between cdef and cpdef
End of explanation
f1(3)
f3(3)
Explanation: f1 is not visible since defined via "cdef"
End of explanation
%%cython
cpdef fibseq(float[:] x):
    cdef int n
    cdef int i
    n = len(x)
    
    x[0] = 1.
    x[1] = 1.
    for i in range(2,n):
        x[i] = x[i-1]+x[i-2]   
    
x = np.zeros((43,), np.float32)
fibseq(x)
x
ratio = x[0:-1]/x[1:]
plt.plot(ratio,'.');
(np.sqrt(5)-1)/2.
plt.semilogy(ratio-(np.sqrt(5)-1)/2,'.');
ratio
import seaborn as sbs
sbs.plt.plot(ratio)
Explanation: filling an numpy array
End of explanation
def pyfib(n):
    a,b = 1,1
    for i in range(n):
        a,b = a+b, a
    return a
pyfib(5)
%%cython
def fib(int n):
    cdef int i,a,b
    a,b = 1,1
    for i in range(n):
        a,b = a+b, a
    return a
fib(10)
[fib(i) for i in range(10)]
pyfib(10)
%timeit fib(10)
%timeit pyfib(10)
Explanation: basic : fibonacchi example (pure python and cython)
End of explanation
%%cython
cpdef float distance(float[:] x, float[:] y):
    cdef int i
    cdef int n = x.shape[0]
    cdef float d = 0.0
    for i in range(n):
        d += (x[i]-y[i])**2
    return d
import numpy as np
x = np.array([1,2,3], np.float32)
y = np.array([7,6,5], np.float32)
dist = distance(x,y)
print dist
def pydistance(x, y, n):
    d = 0.0
    for i in range(n):
        d += (x[i]-y[i])**2
    return d
%timeit distance(x,y)
%timeit pydistance(x,y,3)
Explanation: distance function (pure python and cython)
End of explanation
<END_TASK>