
Cython in marimo
Compile Cython functions inside notebook cells with marimo-cython.
About this notebook
This notebook demonstrates marimo-cython, a package that compiles Cython code inside marimo cells. The package has three entry points: the @cy.compile decorator, cy.compile_module for a source string, and cy.compile_file for a .pyx file. The notebook shows the first two.
The first example compiles a Fibonacci function with typed Cython variables. The notebook calls the Python and the Cython versions 10,000 times each and shows the two run times and the speedup in a table. The second example imports sqrt from the C math library and uses it in a compiled hypotenuse function.
The third example uses cy.compile_module to compile full .pyx syntax, with cdef declarations, cimport, and typed memoryviews. It defines norm and l1_norm functions and calls them on NumPy arrays. The last cell calls the compiled module from a different cell, because marimo shares the module across cells as a usual Python object.











