/* A file to test imorting C modules for handling arrays to Python */ #include "Python.h" #include "arrayobject.h" #include "kcardgame.hpp" #include /* #### Globals #################################### */ /* ==== Set up the methods table ====================== */ static struct PyMethodDef _kcardgameMethods[] = { {"np_kcardgame", np_kcardgame, METH_VARARGS, "kcardgame"}, {NULL, NULL, 0, NULL} /* Sentinel - marks the end of this structure */ }; static struct PyModuleDef _kcardgame_mod = { PyModuleDef_HEAD_INIT, "_kcardgame", NULL, -1, _kcardgameMethods }; /* ==== Initialize the C_test functions ====================== */ // Module name must be _kcardgame in compile and linked PyMODINIT_FUNC PyInit_kcardgame() { PyObject* ret = PyModule_Create(&_kcardgame_mod); import_array(); // Must be present for NumPy. Called first after above line. return ret; } /* ==== Create 1D Carray from PyArray ====================== Assumes PyArray is contiguous in memory. */ static inline uint64_t *pyvector_to_Carrayptrs(PyArrayObject *arrayin) { return (uint64_t *) arrayin->data; /* pointer to arrayin data as double */ } int my_kcardgame( const uint64_t *const cin, const size_t n) { unsigned __int128 sum = 0; /* Operate on the vectors */ for ( size_t i=0; idescr->type_num != NPY_UINT64 || vec->nd != 1) { PyErr_SetString(PyExc_ValueError, "In not_doublevector: array must be of type uint644 and 1 dimensional (n)."); return 1; } return 0; } /* #### Matrix Extensions ############################## */