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

Function prepare_input_arguments_for_outer

numpy/core/src/umath/ufunc_object.c:5792–5890  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5790
5791
5792static PyObject *
5793prepare_input_arguments_for_outer(PyObject *args, PyUFuncObject *ufunc)
5794{
5795 PyArrayObject *ap1 = NULL;
5796 PyObject *tmp;
5797 static PyObject *_numpy_matrix;
5798 npy_cache_import("numpy", "matrix", &_numpy_matrix);
5799
5800 const char *matrix_deprecation_msg = (
5801 "%s.outer() was passed a numpy matrix as %s argument. "
5802 "Special handling of matrix is deprecated and will result in an "
5803 "error in most cases. Please convert the matrix to a NumPy "
5804 "array to retain the old behaviour. You can use `matrix.A` "
5805 "to achieve this.");
5806
5807 tmp = PyTuple_GET_ITEM(args, 0);
5808
5809 if (PyObject_IsInstance(tmp, _numpy_matrix)) {
5810 /* DEPRECATED 2020-05-13, NumPy 1.20 */
5811 if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
5812 matrix_deprecation_msg, ufunc->name, "first") < 0) {
5813 return NULL;
5814 }
5815 ap1 = (PyArrayObject *) PyArray_FromObject(tmp, NPY_NOTYPE, 0, 0);
5816 }
5817 else {
5818 ap1 = (PyArrayObject *) PyArray_FROM_O(tmp);
5819 }
5820 if (ap1 == NULL) {
5821 return NULL;
5822 }
5823
5824 PyArrayObject *ap2 = NULL;
5825 tmp = PyTuple_GET_ITEM(args, 1);
5826 if (PyObject_IsInstance(tmp, _numpy_matrix)) {
5827 /* DEPRECATED 2020-05-13, NumPy 1.20 */
5828 if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
5829 matrix_deprecation_msg, ufunc->name, "second") < 0) {
5830 Py_DECREF(ap1);
5831 return NULL;
5832 }
5833 ap2 = (PyArrayObject *) PyArray_FromObject(tmp, NPY_NOTYPE, 0, 0);
5834 }
5835 else {
5836 ap2 = (PyArrayObject *) PyArray_FROM_O(tmp);
5837 }
5838 if (ap2 == NULL) {
5839 Py_DECREF(ap1);
5840 return NULL;
5841 }
5842 /* Construct new shape from ap1 and ap2 and then reshape */
5843 PyArray_Dims newdims;
5844 npy_intp newshape[NPY_MAXDIMS];
5845 newdims.len = PyArray_NDIM(ap1) + PyArray_NDIM(ap2);
5846 newdims.ptr = newshape;
5847
5848 if (newdims.len > NPY_MAXDIMS) {
5849 PyErr_Format(PyExc_ValueError,

Callers 1

ufunc_generic_fastcallFunction · 0.85

Calls 5

npy_cache_importFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_DIMSFunction · 0.85
PyArray_NewshapeFunction · 0.85
PyArray_CompareListsFunction · 0.85

Tested by

no test coverage detected