MCPcopy Create free account
hub / github.com/numpy/numpy / PyInit__rational_tests

Function PyInit__rational_tests

numpy/core/src/umath/_rational_tests.c:1116–1369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1114};
1115
1116PyMODINIT_FUNC PyInit__rational_tests(void) {
1117 PyObject *m = NULL;
1118 PyObject* numpy_str;
1119 PyObject* numpy;
1120 int npy_rational;
1121
1122 import_array();
1123 if (PyErr_Occurred()) {
1124 goto fail;
1125 }
1126 import_umath();
1127 if (PyErr_Occurred()) {
1128 goto fail;
1129 }
1130 numpy_str = PyUnicode_FromString("numpy");
1131 if (!numpy_str) {
1132 goto fail;
1133 }
1134 numpy = PyImport_Import(numpy_str);
1135 Py_DECREF(numpy_str);
1136 if (!numpy) {
1137 goto fail;
1138 }
1139
1140 /* Can't set this until we import numpy */
1141 PyRational_Type.tp_base = &PyGenericArrType_Type;
1142
1143 /* Initialize rational type object */
1144 if (PyType_Ready(&PyRational_Type) < 0) {
1145 goto fail;
1146 }
1147
1148 /* Initialize rational descriptor */
1149 PyArray_InitArrFuncs(&npyrational_arrfuncs);
1150 npyrational_arrfuncs.getitem = npyrational_getitem;
1151 npyrational_arrfuncs.setitem = npyrational_setitem;
1152 npyrational_arrfuncs.copyswapn = npyrational_copyswapn;
1153 npyrational_arrfuncs.copyswap = npyrational_copyswap;
1154 npyrational_arrfuncs.compare = npyrational_compare;
1155 npyrational_arrfuncs.argmin = npyrational_argmin;
1156 npyrational_arrfuncs.argmax = npyrational_argmax;
1157 npyrational_arrfuncs.dotfunc = npyrational_dot;
1158 npyrational_arrfuncs.nonzero = npyrational_nonzero;
1159 npyrational_arrfuncs.fill = npyrational_fill;
1160 npyrational_arrfuncs.fillwithscalar = npyrational_fillwithscalar;
1161 /* Left undefined: scanfunc, fromstr, sort, argsort */
1162 Py_SET_TYPE(&npyrational_descr, &PyArrayDescr_Type);
1163 npy_rational = PyArray_RegisterDataType(&npyrational_descr);
1164 if (npy_rational<0) {
1165 goto fail;
1166 }
1167
1168 /* Support dtype(rational) syntax */
1169 if (PyDict_SetItemString(PyRational_Type.tp_dict, "dtype",
1170 (PyObject*)&npyrational_descr) < 0) {
1171 goto fail;
1172 }
1173

Callers

nothing calls this directly

Tested by

no test coverage detected