Search code examples
pythonipythoncython

How to specify -march=native with %%cython


In ipython I can do the following:

%%cython --compile-args=-Ofast
def f(x):
    return 2.0*x

But how can I add -march=native as well?


Solution

  • The --compile-args flag can be passed several times, as can be seen in the help by running %%cython? in a notebook cell:

    -c COMPILE_ARGS, --compile-args COMPILE_ARGS
                        Extra flags to pass to compiler via the
                        `extra_compile_args` Extension flag (can be specified
                        multiple times).
    

    The final answer would therefore be:

    %%cython --compile-args=-Ofast --compile-args=-march=native
    
    def f(x):
        return 2.0*x