3

My Cython (.pyx) file contains assert and I would like to remove it when I compile the file. I found this post and edited my setup.py as follows.

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

# Before edit
compiler_args = ["-O3", "-ffast-math"]

# Both did not work
# compiler_args = ["-O3", "-ffast-math", "-DPYREX_WITHOUT_ASSERTIONS"]
# compiler_args = ["-O3", "-ffast-math", "-CYTHON_WITHOUT_ASSERTIONS"]

ext_modules = [
               Extension("mycython", sources=["mycython.pyx"],
               extra_compile_args=compiler_args)
              ]

setup(
      name="Test",
      cmdclass={'build_ext': build_ext},
      ext_modules=ext_modules
     )

The error says:

clang: error: unknown argument: '-CYTHON_WITHOUT_ASSERTIONS'

How can I fix it?

user51966
  • 967
  • 3
  • 9
  • 21

1 Answers1

3

CYTHON_WITHOUT_ASSERTIONS is a preprocessor macro, so you have to pass it to clang with the -D flag (just like gcc). The first variable's name is actually PYREX_WITHOUT_ASSERTIONS, but to pass it to the preprocessor as a macro (i.e. a part of your clang compiler) you need to add a -D in front of the variable name.

Try compiler_args = ["-O3", "-ffast-math", "-DCYTHON_WITHOUT_ASSERTIONS"] instead (note the D in front of CYTHON_WITHOUT_ASSERTIONS).

HTH.

Matt Messersmith
  • 12,939
  • 6
  • 51
  • 52