Code Snippets Cython

Short texts Cython 🧑‍💻 Code snippets Cython ✍️ Reading lists Cython 👀

std::vector to numpy array coercion via Cython

# distutils : language = c++ # cython: language_level = 3 # distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION import numpy as np cimport numpy as np from libcpp.vector cimport vector cdef extern from *: “”” #include #include std::vector vec_of_same_length_vecs() { // A vector of 3 vectors of identical shape. std::vector vec_of_vecs(3); vec_of_vecs[0].push_back(1); vec_of_vecs[0].push_back(2); vec_of_vecs[1].push_back(3); vec_of_vecs[1].push_back(4); vec_of_vecs[2].push_back(5); vec_of_vecs[2].push_back(6); return vec_of_vecs; […]

Using Cython (C and C++) with godot and godot-python

For these notes, I’m assuming the reader is reasonably familiar with how cython, python and godot works. ### Basic steps to use cython in your godot project: * Download and install godot-python and make sure python scripts are working in your project: * * Install Cython in your python environment: * `cd myproject` * […]