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

Function npyrational_setitem

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

Source from the content-addressed store, hash-verified

721}
722
723static int
724npyrational_setitem(PyObject* item, void* data, void* arr) {
725 rational r;
726 if (PyRational_Check(item)) {
727 r = ((PyRational*)item)->r;
728 }
729 else {
730 long long n = PyLong_AsLongLong(item);
731 PyObject* y;
732 int eq;
733 if (error_converting(n)) {
734 return -1;
735 }
736 y = PyLong_FromLongLong(n);
737 if (!y) {
738 return -1;
739 }
740 eq = PyObject_RichCompareBool(item, y, Py_EQ);
741 Py_DECREF(y);
742 if (eq<0) {
743 return -1;
744 }
745 if (!eq) {
746 PyErr_Format(PyExc_TypeError,
747 "expected rational, got %s", item->ob_type->tp_name);
748 return -1;
749 }
750 r = make_rational_int(n);
751 }
752 memcpy(data, &r, sizeof(rational));
753 return 0;
754}
755
756static inline void
757byteswap(npy_int32* x) {

Callers

nothing calls this directly

Calls 2

PyRational_CheckFunction · 0.85
make_rational_intFunction · 0.85

Tested by

no test coverage detected