1

I am currently looking into Cython, and I am trying to implement it in the following way using the cythonmagic command:

%load_ext cythonmagic
%%cython
def fib(int n):
    cdef int a, b, i
    a, b = 1, 1
    for i in range(n):
        a, b = a+b, a
    return a

The code is written on a .ipy file, so on a Ipython file. However, I will make clear that I am running the code on Python from the Spyder terminal.

After writing the %%cython command, I should expect the function to be compiled like it is written in Cython, but an "invalid syntax" error occurs. How do I correct this?

0 Answers0