MCPcopy Create free account
hub / github.com/pydata/numexpr / PyInit_interpreter

Function PyInit_interpreter

numexpr3/module.cpp:400–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

398#define INITERROR return NULL
399
400PyObject*
401PyInit_interpreter(void)
402// #else // Python 2.7
403// #define INITERROR return
404
405// PyMODINIT_FUNC
406// initinterpreter()
407// #endif
408{
409 // PyObject *m, *d;
410 PyObject *m;
411
412 // WARNING: PyType_Ready MUST be called to finalize new Python types before
413 // a module is created. Official documentation is weak on this point.
414 if (PyType_Ready(&NumExprType) < 0)
415 INITERROR;
416
417// #if PY_MAJOR_VERSION >= 3
418 m = PyModule_Create(&moduledef);
419// #else
420 // m = Py_InitModule3("interpreter", module_methods, NULL);
421// #endif
422
423 if (m == NULL)
424 INITERROR;
425
426 Py_INCREF(&NumExprType);
427 PyModule_AddObject(m, "CompiledExec", (PyObject *)&NumExprType);
428
429 import_array();
430
431 // Let's export the block sizes to Python side for benchmarking comparisons
432 PyModule_AddIntConstant(m, "__BLOCK_SIZE1__", BLOCK_SIZE1 );
433 PyModule_AddIntConstant(m, "__BLOCK_SIZE2__", BLOCK_SIZE2 );
434
435 PyModule_AddIntConstant(m, "MAX_ARGS", NPY_MAXARGS );
436 PyModule_AddIntConstant(m, "MAX_DIMS", NPY_MAXDIMS );
437
438
439#ifdef BENCHMARKING
440 PyModule_AddIntConstant(m, "BENCHMARKING", 1 );
441 #if defined(_WIN32) // On Windows x64: LARGE_INTEGER is a union and LARGE_INTEGER.QuadPart is int64.
442 npy_intp dims = BCOUNT;
443 QueryPerformanceFrequency( &T_NOW );
444 PyModule_AddIntConstant(m, "cpu_freq", T_NOW.QuadPart );
445 PyObject* bench_times = PyArray_SimpleNewFromData( 1, &dims, NPY_INT64, TIMES );
446 #else // On Linux: struct timespec { long ts_sec; long ts_nsec };
447 // So the array is 2*BCOUNT long and will need to be sliced on the Python end
448 npy_intp dims = 2*BCOUNT;
449 PyObject* bench_times = PyArray_SimpleNewFromData( 1, &dims, NPY_INT64, TIMES );
450 #endif
451 PyModule_AddObject(m, "bench_times", bench_times ); // Make NumPy arrays from the timing arrays.
452#else // No BENCHMARKING
453 PyModule_AddIntConstant(m, "BENCHMARKING", 0 );
454#endif
455
456 // The OpTable is loaded via pickle now.
457 // d = PyDict_New();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…