3 ms·
Using Jinja2 for macros is an interesting idea. You could try cog instead? https://www.python.org/about/success/cog/ https://www.python.org/about/success/cog/
by syllogism 11y ago
Using Jinja2 for macros is an interesting idea. You could try cog instead? https://www.python.org/about/success/cog/ https://www.python.org/about/success/cog/
Currently I don't do any macros at all, although the temptation is definitely strong. I have some code that could otherwise be more generic than it is.
I guess a quick tip/pattern would be to use structs as data containers, with a cdef class defined as a "shell", to provide access, but not actually hold the data.
Advantages of this over standard cdef class: Data is contiguous in memory; Data can be stack allocated; Data can be stored in C arrays or C++ containers; Data can be created without GIL.
Advantages of this over numpy array: More Pythonic syntax (i.e. data.attr, instead of data[column]; No fussing with memorybuffers, compiler declarations etc; Data can be created without GIL
Disadvantages: More code
(I wrote that cymem blog post -- I'll write up this pattern as a post when I get a chance.)