Bug Summary

File:numpy/core/src/multiarray/number.c
Warning:line 423, column 27
PyObject ownership leak with reference count of 1

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name number.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -analyzer-output=html -analyzer-checker=python -analyzer-disable-checker=deadcode -analyzer-config prune-paths=true,suppress-c++-stdlib=true,suppress-null-return-paths=false,crosscheck-with-z3=true,model-path=/opt/pyrefcon/lib/pyrefcon/models/models -analyzer-config experimental-enable-naive-ctu-analysis=true,ctu-dir=/tmp/pyrefcon/numpy/csa-scan,ctu-index-name=/tmp/pyrefcon/numpy/csa-scan/externalDefMap.txt,ctu-invocation-list=/tmp/pyrefcon/numpy/csa-scan/invocations.yaml,display-ctu-progress=false -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +sse -target-feature +sse2 -target-feature +sse3 -tune-cpu generic -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -fcoverage-compilation-dir=/tmp/pyrefcon/numpy -resource-dir /opt/pyrefcon/lib/clang/13.0.0 -isystem /opt/pyrefcon/lib/pyrefcon/models/python3.8 -D NDEBUG -D _FORTIFY_SOURCE=2 -D NPY_INTERNAL_BUILD=1 -D HAVE_NPY_CONFIG_H=1 -D _FILE_OFFSET_BITS=64 -D _LARGEFILE_SOURCE=1 -D _LARGEFILE64_SOURCE=1 -I build/src.linux-x86_64-3.8/numpy/core/src/common -I build/src.linux-x86_64-3.8/numpy/core/src/umath -I numpy/core/include -I build/src.linux-x86_64-3.8/numpy/core/include/numpy -I build/src.linux-x86_64-3.8/numpy/distutils/include -I numpy/core/src/common -I numpy/core/src -I numpy/core -I numpy/core/src/npymath -I numpy/core/src/multiarray -I numpy/core/src/umath -I numpy/core/src/npysort -I numpy/core/src/_simd -I build/src.linux-x86_64-3.8/numpy/core/src/common -I build/src.linux-x86_64-3.8/numpy/core/src/npymath -internal-isystem /opt/pyrefcon/lib/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-result -Wsign-compare -Wall -Wformat -Werror=format-security -Wformat -Werror=format-security -Wdate-time -fdebug-compilation-dir=/tmp/pyrefcon/numpy -ferror-limit 19 -fwrapv -pthread -stack-protector 2 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/pyrefcon/numpy/csa-scan/reports -x c numpy/core/src/multiarray/number.c

numpy/core/src/multiarray/number.c

1#define PY_SSIZE_T_CLEAN
2#include <Python.h>
3#include "structmember.h"
4
5/*#include <stdio.h>*/
6#define NPY_NO_DEPRECATED_API0x0000000E NPY_API_VERSION0x0000000E
7#define _MULTIARRAYMODULE
8#include "numpy/arrayobject.h"
9
10#include "npy_config.h"
11#include "npy_pycompat.h"
12#include "npy_import.h"
13#include "common.h"
14#include "number.h"
15#include "temp_elide.h"
16
17#include "binop_override.h"
18#include "ufunc_override.h"
19#include "abstractdtypes.h"
20#include "common_dtype.h"
21#include "convert_datatype.h"
22
23/*************************************************************************
24 **************** Implement Number Protocol ****************************
25 *************************************************************************/
26
27NPY_NO_EXPORT__attribute__((visibility("hidden"))) NumericOps n_ops; /* NB: static objects initialized to zero */
28
29/*
30 * Forward declarations. Might want to move functions around instead
31 */
32static PyObject *
33array_inplace_add(PyArrayObject *m1, PyObject *m2);
34static PyObject *
35array_inplace_subtract(PyArrayObject *m1, PyObject *m2);
36static PyObject *
37array_inplace_multiply(PyArrayObject *m1, PyObject *m2);
38static PyObject *
39array_inplace_true_divide(PyArrayObject *m1, PyObject *m2);
40static PyObject *
41array_inplace_floor_divide(PyArrayObject *m1, PyObject *m2);
42static PyObject *
43array_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2);
44static PyObject *
45array_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2);
46static PyObject *
47array_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2);
48static PyObject *
49array_inplace_left_shift(PyArrayObject *m1, PyObject *m2);
50static PyObject *
51array_inplace_right_shift(PyArrayObject *m1, PyObject *m2);
52static PyObject *
53array_inplace_remainder(PyArrayObject *m1, PyObject *m2);
54static PyObject *
55array_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *NPY_UNUSED(modulo)(__NPY_UNUSED_TAGGEDmodulo) __attribute__ ((__unused__)));
56
57/*
58 * Dictionary can contain any of the numeric operations, by name.
59 * Those not present will not be changed
60 */
61
62/* FIXME - macro contains a return */
63#define SET(op)temp = _PyDict_GetItemStringWithError(dict, "op"); if (temp ==
((void*)0) && PyErr_Occurred()) { return -1; } else if
(temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.op))); n_ops.op = temp; }
temp = _PyDict_GetItemStringWithError(dict, #op); \
64 if (temp == NULL((void*)0) && PyErr_Occurred()) { \
65 return -1; \
66 } \
67 else if (temp != NULL((void*)0)) { \
68 if (!(PyCallable_Check(temp))) { \
69 return -1; \
70 } \
71 Py_INCREF(temp)_Py_INCREF(((PyObject*)(temp))); \
72 Py_XDECREF(n_ops.op)_Py_XDECREF(((PyObject*)(n_ops.op))); \
73 n_ops.op = temp; \
74 }
75
76NPY_NO_EXPORT__attribute__((visibility("hidden"))) int
77_PyArray_SetNumericOps(PyObject *dict)
78{
79 PyObject *temp = NULL((void*)0);
80 SET(add)temp = _PyDict_GetItemStringWithError(dict, "add"); if (temp ==
((void*)0) && PyErr_Occurred()) { return -1; } else if
(temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.add))); n_ops.add = temp; }
;
81 SET(subtract)temp = _PyDict_GetItemStringWithError(dict, "subtract"); if (
temp == ((void*)0) && PyErr_Occurred()) { return -1; }
else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))
) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.subtract))); n_ops.subtract = temp; }
;
82 SET(multiply)temp = _PyDict_GetItemStringWithError(dict, "multiply"); if (
temp == ((void*)0) && PyErr_Occurred()) { return -1; }
else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))
) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.multiply))); n_ops.multiply = temp; }
;
83 SET(divide)temp = _PyDict_GetItemStringWithError(dict, "divide"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.divide))); n_ops.divide = temp; }
;
84 SET(remainder)temp = _PyDict_GetItemStringWithError(dict, "remainder"); if (
temp == ((void*)0) && PyErr_Occurred()) { return -1; }
else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))
) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.remainder))); n_ops.remainder = temp; }
;
85 SET(divmod)temp = _PyDict_GetItemStringWithError(dict, "divmod"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.divmod))); n_ops.divmod = temp; }
;
86 SET(power)temp = _PyDict_GetItemStringWithError(dict, "power"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.power))); n_ops.power = temp; }
;
87 SET(square)temp = _PyDict_GetItemStringWithError(dict, "square"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.square))); n_ops.square = temp; }
;
88 SET(reciprocal)temp = _PyDict_GetItemStringWithError(dict, "reciprocal"); if
(temp == ((void*)0) && PyErr_Occurred()) { return -1
; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp
))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.reciprocal))); n_ops.reciprocal = temp; }
;
89 SET(_ones_like)temp = _PyDict_GetItemStringWithError(dict, "_ones_like"); if
(temp == ((void*)0) && PyErr_Occurred()) { return -1
; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp
))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops._ones_like))); n_ops._ones_like = temp; }
;
90 SET(sqrt)temp = _PyDict_GetItemStringWithError(dict, "sqrt"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.sqrt))); n_ops.sqrt = temp; }
;
91 SET(cbrt)temp = _PyDict_GetItemStringWithError(dict, "cbrt"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.cbrt))); n_ops.cbrt = temp; }
;
92 SET(negative)temp = _PyDict_GetItemStringWithError(dict, "negative"); if (
temp == ((void*)0) && PyErr_Occurred()) { return -1; }
else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))
) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.negative))); n_ops.negative = temp; }
;
93 SET(positive)temp = _PyDict_GetItemStringWithError(dict, "positive"); if (
temp == ((void*)0) && PyErr_Occurred()) { return -1; }
else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))
) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.positive))); n_ops.positive = temp; }
;
94 SET(absolute)temp = _PyDict_GetItemStringWithError(dict, "absolute"); if (
temp == ((void*)0) && PyErr_Occurred()) { return -1; }
else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))
) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.absolute))); n_ops.absolute = temp; }
;
95 SET(invert)temp = _PyDict_GetItemStringWithError(dict, "invert"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.invert))); n_ops.invert = temp; }
;
96 SET(left_shift)temp = _PyDict_GetItemStringWithError(dict, "left_shift"); if
(temp == ((void*)0) && PyErr_Occurred()) { return -1
; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp
))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.left_shift))); n_ops.left_shift = temp; }
;
97 SET(right_shift)temp = _PyDict_GetItemStringWithError(dict, "right_shift"); if
(temp == ((void*)0) && PyErr_Occurred()) { return -1
; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp
))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.right_shift))); n_ops.right_shift = temp;
}
;
98 SET(bitwise_and)temp = _PyDict_GetItemStringWithError(dict, "bitwise_and"); if
(temp == ((void*)0) && PyErr_Occurred()) { return -1
; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp
))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.bitwise_and))); n_ops.bitwise_and = temp;
}
;
99 SET(bitwise_or)temp = _PyDict_GetItemStringWithError(dict, "bitwise_or"); if
(temp == ((void*)0) && PyErr_Occurred()) { return -1
; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp
))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.bitwise_or))); n_ops.bitwise_or = temp; }
;
100 SET(bitwise_xor)temp = _PyDict_GetItemStringWithError(dict, "bitwise_xor"); if
(temp == ((void*)0) && PyErr_Occurred()) { return -1
; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp
))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.bitwise_xor))); n_ops.bitwise_xor = temp;
}
;
101 SET(less)temp = _PyDict_GetItemStringWithError(dict, "less"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.less))); n_ops.less = temp; }
;
102 SET(less_equal)temp = _PyDict_GetItemStringWithError(dict, "less_equal"); if
(temp == ((void*)0) && PyErr_Occurred()) { return -1
; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp
))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.less_equal))); n_ops.less_equal = temp; }
;
103 SET(equal)temp = _PyDict_GetItemStringWithError(dict, "equal"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.equal))); n_ops.equal = temp; }
;
104 SET(not_equal)temp = _PyDict_GetItemStringWithError(dict, "not_equal"); if (
temp == ((void*)0) && PyErr_Occurred()) { return -1; }
else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))
) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.not_equal))); n_ops.not_equal = temp; }
;
105 SET(greater)temp = _PyDict_GetItemStringWithError(dict, "greater"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.greater))); n_ops.greater = temp; }
;
106 SET(greater_equal)temp = _PyDict_GetItemStringWithError(dict, "greater_equal");
if (temp == ((void*)0) && PyErr_Occurred()) { return
-1; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(
temp))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.greater_equal))); n_ops.greater_equal = temp
; }
;
107 SET(floor_divide)temp = _PyDict_GetItemStringWithError(dict, "floor_divide"); if
(temp == ((void*)0) && PyErr_Occurred()) { return -1
; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp
))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.floor_divide))); n_ops.floor_divide = temp
; }
;
108 SET(true_divide)temp = _PyDict_GetItemStringWithError(dict, "true_divide"); if
(temp == ((void*)0) && PyErr_Occurred()) { return -1
; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp
))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.true_divide))); n_ops.true_divide = temp;
}
;
109 SET(logical_or)temp = _PyDict_GetItemStringWithError(dict, "logical_or"); if
(temp == ((void*)0) && PyErr_Occurred()) { return -1
; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp
))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.logical_or))); n_ops.logical_or = temp; }
;
110 SET(logical_and)temp = _PyDict_GetItemStringWithError(dict, "logical_and"); if
(temp == ((void*)0) && PyErr_Occurred()) { return -1
; } else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp
))) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.logical_and))); n_ops.logical_and = temp;
}
;
111 SET(floor)temp = _PyDict_GetItemStringWithError(dict, "floor"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.floor))); n_ops.floor = temp; }
;
112 SET(ceil)temp = _PyDict_GetItemStringWithError(dict, "ceil"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.ceil))); n_ops.ceil = temp; }
;
113 SET(maximum)temp = _PyDict_GetItemStringWithError(dict, "maximum"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.maximum))); n_ops.maximum = temp; }
;
114 SET(minimum)temp = _PyDict_GetItemStringWithError(dict, "minimum"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.minimum))); n_ops.minimum = temp; }
;
115 SET(rint)temp = _PyDict_GetItemStringWithError(dict, "rint"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.rint))); n_ops.rint = temp; }
;
116 SET(conjugate)temp = _PyDict_GetItemStringWithError(dict, "conjugate"); if (
temp == ((void*)0) && PyErr_Occurred()) { return -1; }
else if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))
) { return -1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF
(((PyObject*)(n_ops.conjugate))); n_ops.conjugate = temp; }
;
117 SET(matmul)temp = _PyDict_GetItemStringWithError(dict, "matmul"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.matmul))); n_ops.matmul = temp; }
;
118 SET(clip)temp = _PyDict_GetItemStringWithError(dict, "clip"); if (temp
== ((void*)0) && PyErr_Occurred()) { return -1; } else
if (temp != ((void*)0)) { if (!(PyCallable_Check(temp))) { return
-1; } _Py_INCREF(((PyObject*)(temp))); _Py_XDECREF(((PyObject
*)(n_ops.clip))); n_ops.clip = temp; }
;
119 return 0;
120}
121
122/*NUMPY_API
123 *Set internal structure with number functions that all arrays will use
124 */
125NPY_NO_EXPORT__attribute__((visibility("hidden"))) int
126PyArray_SetNumericOps(PyObject *dict)
127{
128 /* 2018-09-09, 1.16 */
129 if (DEPRECATE("PyArray_SetNumericOps is deprecated. Use "PyErr_WarnEx(PyExc_DeprecationWarning,"PyArray_SetNumericOps is deprecated. Use "
"PyUFunc_ReplaceLoopBySignature to replace ufunc inner loop functions "
"instead.",1)
130 "PyUFunc_ReplaceLoopBySignature to replace ufunc inner loop functions "PyErr_WarnEx(PyExc_DeprecationWarning,"PyArray_SetNumericOps is deprecated. Use "
"PyUFunc_ReplaceLoopBySignature to replace ufunc inner loop functions "
"instead.",1)
131 "instead.")PyErr_WarnEx(PyExc_DeprecationWarning,"PyArray_SetNumericOps is deprecated. Use "
"PyUFunc_ReplaceLoopBySignature to replace ufunc inner loop functions "
"instead.",1)
< 0) {
132 return -1;
133 }
134 return _PyArray_SetNumericOps(dict);
135}
136
137/* Note - macro contains goto */
138#define GET(op)if (n_ops.op && (PyDict_SetItemString(dict, "op", n_ops
.op)==-1)) goto fail;
if (n_ops.op && \
139 (PyDict_SetItemString(dict, #op, n_ops.op)==-1)) \
140 goto fail;
141
142NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
143_PyArray_GetNumericOps(void)
144{
145 PyObject *dict;
146 if ((dict = PyDict_New())==NULL((void*)0))
147 return NULL((void*)0);
148 GET(add)if (n_ops.add && (PyDict_SetItemString(dict, "add", n_ops
.add)==-1)) goto fail;
;
149 GET(subtract)if (n_ops.subtract && (PyDict_SetItemString(dict, "subtract"
, n_ops.subtract)==-1)) goto fail;
;
150 GET(multiply)if (n_ops.multiply && (PyDict_SetItemString(dict, "multiply"
, n_ops.multiply)==-1)) goto fail;
;
151 GET(divide)if (n_ops.divide && (PyDict_SetItemString(dict, "divide"
, n_ops.divide)==-1)) goto fail;
;
152 GET(remainder)if (n_ops.remainder && (PyDict_SetItemString(dict, "remainder"
, n_ops.remainder)==-1)) goto fail;
;
153 GET(divmod)if (n_ops.divmod && (PyDict_SetItemString(dict, "divmod"
, n_ops.divmod)==-1)) goto fail;
;
154 GET(power)if (n_ops.power && (PyDict_SetItemString(dict, "power"
, n_ops.power)==-1)) goto fail;
;
155 GET(square)if (n_ops.square && (PyDict_SetItemString(dict, "square"
, n_ops.square)==-1)) goto fail;
;
156 GET(reciprocal)if (n_ops.reciprocal && (PyDict_SetItemString(dict, "reciprocal"
, n_ops.reciprocal)==-1)) goto fail;
;
157 GET(_ones_like)if (n_ops._ones_like && (PyDict_SetItemString(dict, "_ones_like"
, n_ops._ones_like)==-1)) goto fail;
;
158 GET(sqrt)if (n_ops.sqrt && (PyDict_SetItemString(dict, "sqrt",
n_ops.sqrt)==-1)) goto fail;
;
159 GET(negative)if (n_ops.negative && (PyDict_SetItemString(dict, "negative"
, n_ops.negative)==-1)) goto fail;
;
160 GET(positive)if (n_ops.positive && (PyDict_SetItemString(dict, "positive"
, n_ops.positive)==-1)) goto fail;
;
161 GET(absolute)if (n_ops.absolute && (PyDict_SetItemString(dict, "absolute"
, n_ops.absolute)==-1)) goto fail;
;
162 GET(invert)if (n_ops.invert && (PyDict_SetItemString(dict, "invert"
, n_ops.invert)==-1)) goto fail;
;
163 GET(left_shift)if (n_ops.left_shift && (PyDict_SetItemString(dict, "left_shift"
, n_ops.left_shift)==-1)) goto fail;
;
164 GET(right_shift)if (n_ops.right_shift && (PyDict_SetItemString(dict, "right_shift"
, n_ops.right_shift)==-1)) goto fail;
;
165 GET(bitwise_and)if (n_ops.bitwise_and && (PyDict_SetItemString(dict, "bitwise_and"
, n_ops.bitwise_and)==-1)) goto fail;
;
166 GET(bitwise_or)if (n_ops.bitwise_or && (PyDict_SetItemString(dict, "bitwise_or"
, n_ops.bitwise_or)==-1)) goto fail;
;
167 GET(bitwise_xor)if (n_ops.bitwise_xor && (PyDict_SetItemString(dict, "bitwise_xor"
, n_ops.bitwise_xor)==-1)) goto fail;
;
168 GET(less)if (n_ops.less && (PyDict_SetItemString(dict, "less",
n_ops.less)==-1)) goto fail;
;
169 GET(less_equal)if (n_ops.less_equal && (PyDict_SetItemString(dict, "less_equal"
, n_ops.less_equal)==-1)) goto fail;
;
170 GET(equal)if (n_ops.equal && (PyDict_SetItemString(dict, "equal"
, n_ops.equal)==-1)) goto fail;
;
171 GET(not_equal)if (n_ops.not_equal && (PyDict_SetItemString(dict, "not_equal"
, n_ops.not_equal)==-1)) goto fail;
;
172 GET(greater)if (n_ops.greater && (PyDict_SetItemString(dict, "greater"
, n_ops.greater)==-1)) goto fail;
;
173 GET(greater_equal)if (n_ops.greater_equal && (PyDict_SetItemString(dict
, "greater_equal", n_ops.greater_equal)==-1)) goto fail;
;
174 GET(floor_divide)if (n_ops.floor_divide && (PyDict_SetItemString(dict,
"floor_divide", n_ops.floor_divide)==-1)) goto fail;
;
175 GET(true_divide)if (n_ops.true_divide && (PyDict_SetItemString(dict, "true_divide"
, n_ops.true_divide)==-1)) goto fail;
;
176 GET(logical_or)if (n_ops.logical_or && (PyDict_SetItemString(dict, "logical_or"
, n_ops.logical_or)==-1)) goto fail;
;
177 GET(logical_and)if (n_ops.logical_and && (PyDict_SetItemString(dict, "logical_and"
, n_ops.logical_and)==-1)) goto fail;
;
178 GET(floor)if (n_ops.floor && (PyDict_SetItemString(dict, "floor"
, n_ops.floor)==-1)) goto fail;
;
179 GET(ceil)if (n_ops.ceil && (PyDict_SetItemString(dict, "ceil",
n_ops.ceil)==-1)) goto fail;
;
180 GET(maximum)if (n_ops.maximum && (PyDict_SetItemString(dict, "maximum"
, n_ops.maximum)==-1)) goto fail;
;
181 GET(minimum)if (n_ops.minimum && (PyDict_SetItemString(dict, "minimum"
, n_ops.minimum)==-1)) goto fail;
;
182 GET(rint)if (n_ops.rint && (PyDict_SetItemString(dict, "rint",
n_ops.rint)==-1)) goto fail;
;
183 GET(conjugate)if (n_ops.conjugate && (PyDict_SetItemString(dict, "conjugate"
, n_ops.conjugate)==-1)) goto fail;
;
184 GET(matmul)if (n_ops.matmul && (PyDict_SetItemString(dict, "matmul"
, n_ops.matmul)==-1)) goto fail;
;
185 GET(clip)if (n_ops.clip && (PyDict_SetItemString(dict, "clip",
n_ops.clip)==-1)) goto fail;
;
186 return dict;
187
188 fail:
189 Py_DECREF(dict)_Py_DECREF(((PyObject*)(dict)));
190 return NULL((void*)0);
191}
192
193/*NUMPY_API
194 Get dictionary showing number functions that all arrays will use
195*/
196NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
197PyArray_GetNumericOps(void)
198{
199 /* 2018-09-09, 1.16 */
200 if (DEPRECATE("PyArray_GetNumericOps is deprecated.")PyErr_WarnEx(PyExc_DeprecationWarning,"PyArray_GetNumericOps is deprecated."
,1)
< 0) {
201 return NULL((void*)0);
202 }
203 return _PyArray_GetNumericOps();
204}
205
206static PyObject *
207_get_keywords(int rtype, PyArrayObject *out)
208{
209 PyObject *kwds = NULL((void*)0);
210 if (rtype != NPY_NOTYPE || out != NULL((void*)0)) {
211 kwds = PyDict_New();
212 if (rtype != NPY_NOTYPE) {
213 PyArray_Descr *descr;
214 descr = PyArray_DescrFromType(rtype);
215 if (descr) {
216 PyDict_SetItemString(kwds, "dtype", (PyObject *)descr);
217 Py_DECREF(descr)_Py_DECREF(((PyObject*)(descr)));
218 }
219 }
220 if (out != NULL((void*)0)) {
221 PyDict_SetItemString(kwds, "out", (PyObject *)out);
222 }
223 }
224 return kwds;
225}
226
227NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
228PyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,
229 int rtype, PyArrayObject *out)
230{
231 PyObject *args, *ret = NULL((void*)0), *meth;
232 PyObject *kwds;
233
234 args = Py_BuildValue_Py_BuildValue_SizeT("(Oi)", m1, axis);
235 kwds = _get_keywords(rtype, out);
236 meth = PyObject_GetAttrString(op, "reduce");
237 if (meth && PyCallable_Check(meth)) {
238 ret = PyObject_Call(meth, args, kwds);
239 }
240 Py_DECREF(args)_Py_DECREF(((PyObject*)(args)));
241 Py_DECREF(meth)_Py_DECREF(((PyObject*)(meth)));
242 Py_XDECREF(kwds)_Py_XDECREF(((PyObject*)(kwds)));
243 return ret;
244}
245
246
247NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
248PyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,
249 int rtype, PyArrayObject *out)
250{
251 PyObject *args, *ret = NULL((void*)0), *meth;
252 PyObject *kwds;
253
254 args = Py_BuildValue_Py_BuildValue_SizeT("(Oi)", m1, axis);
255 kwds = _get_keywords(rtype, out);
256 meth = PyObject_GetAttrString(op, "accumulate");
257 if (meth && PyCallable_Check(meth)) {
258 ret = PyObject_Call(meth, args, kwds);
259 }
260 Py_DECREF(args)_Py_DECREF(((PyObject*)(args)));
261 Py_DECREF(meth)_Py_DECREF(((PyObject*)(meth)));
262 Py_XDECREF(kwds)_Py_XDECREF(((PyObject*)(kwds)));
263 return ret;
264}
265
266
267NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
268PyArray_GenericBinaryFunction(PyObject *m1, PyObject *m2, PyObject *op)
269{
270 return PyObject_CallFunctionObjArgs(op, m1, m2, NULL((void*)0));
271}
272
273NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
274PyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)
275{
276 return PyObject_CallFunctionObjArgs(op, m1, NULL((void*)0));
277}
278
279static PyObject *
280PyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,
281 PyObject *m2, PyObject *op)
282{
283 return PyObject_CallFunctionObjArgs(op, m1, m2, m1, NULL((void*)0));
284}
285
286static PyObject *
287PyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)
288{
289 return PyObject_CallFunctionObjArgs(op, m1, m1, NULL((void*)0));
290}
291
292static PyObject *
293array_add(PyObject *m1, PyObject *m2)
294{
295 PyObject *res;
296
297 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_add, array_add)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_add) != (void*)(array_add)) &&
binop_should_defer((PyObject*)m1, (PyObject*)m2, 0)) { _Py_INCREF
(((PyObject*)((&_Py_NotImplementedStruct)))); return (&
_Py_NotImplementedStruct); } } while (0)
;
298 if (try_binary_elide(m1, m2, &array_inplace_add, &res, 1)) {
299 return res;
300 }
301 return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);
302}
303
304static PyObject *
305array_subtract(PyObject *m1, PyObject *m2)
306{
307 PyObject *res;
308
309 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_subtract, array_subtract)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_subtract) != (void*)(array_subtract
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 0)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
310 if (try_binary_elide(m1, m2, &array_inplace_subtract, &res, 0)) {
311 return res;
312 }
313 return PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);
314}
315
316static PyObject *
317array_multiply(PyObject *m1, PyObject *m2)
318{
319 PyObject *res;
320
321 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_multiply, array_multiply)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_multiply) != (void*)(array_multiply
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 0)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
322 if (try_binary_elide(m1, m2, &array_inplace_multiply, &res, 1)) {
323 return res;
324 }
325 return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);
326}
327
328static PyObject *
329array_remainder(PyObject *m1, PyObject *m2)
330{
331 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_remainder, array_remainder)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_remainder) != (void*)(array_remainder
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 0)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
332 return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);
333}
334
335static PyObject *
336array_divmod(PyObject *m1, PyObject *m2)
337{
338 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_divmod, array_divmod)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_divmod) != (void*)(array_divmod)) &&
binop_should_defer((PyObject*)m1, (PyObject*)m2, 0)) { _Py_INCREF
(((PyObject*)((&_Py_NotImplementedStruct)))); return (&
_Py_NotImplementedStruct); } } while (0)
;
339 return PyArray_GenericBinaryFunction(m1, m2, n_ops.divmod);
340}
341
342/* Need this to be version dependent on account of the slot check */
343static PyObject *
344array_matrix_multiply(PyObject *m1, PyObject *m2)
345{
346 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_matrix_multiply, array_matrix_multiply)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_matrix_multiply) != (void*)(array_matrix_multiply
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 0)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
347 return PyArray_GenericBinaryFunction(m1, m2, n_ops.matmul);
348}
349
350static PyObject *
351array_inplace_matrix_multiply(
352 PyArrayObject *NPY_UNUSED(m1)(__NPY_UNUSED_TAGGEDm1) __attribute__ ((__unused__)), PyObject *NPY_UNUSED(m2)(__NPY_UNUSED_TAGGEDm2) __attribute__ ((__unused__)))
353{
354 PyErr_SetString(PyExc_TypeError,
355 "In-place matrix multiplication is not (yet) supported. "
356 "Use 'a = a @ b' instead of 'a @= b'.");
357 return NULL((void*)0);
358}
359
360/*
361 * Determine if object is a scalar and if so, convert the object
362 * to a double and place it in the out_exponent argument
363 * and return the "scalar kind" as a result. If the object is
364 * not a scalar (or if there are other error conditions)
365 * return NPY_NOSCALAR, and out_exponent is undefined.
366 */
367static NPY_SCALARKIND
368is_scalar_with_conversion(PyObject *o2, double* out_exponent)
369{
370 PyObject *temp;
371 const int optimize_fpexps = 1;
372
373 if (PyLong_Check(o2)((((((PyObject*)(o2))->ob_type))->tp_flags & ((1UL <<
24))) != 0)
) {
7
Assuming the condition is false
8
Taking false branch
374 long tmp = PyLong_AsLong(o2);
375 if (error_converting(tmp)(((tmp) == -1) && PyErr_Occurred())) {
376 PyErr_Clear();
377 return NPY_NOSCALAR;
378 }
379 *out_exponent = (double)tmp;
380 return NPY_INTPOS_SCALAR;
381 }
382
383 if (optimize_fpexps
8.1
'optimize_fpexps' is 1
8.1
'optimize_fpexps' is 1
&& PyFloat_Check(o2)((((PyObject*)(o2))->ob_type) == (&PyFloat_Type) || PyType_IsSubtype
((((PyObject*)(o2))->ob_type), (&PyFloat_Type)))
) {
9
Assuming the condition is false
10
Assuming the condition is false
11
Taking false branch
384 *out_exponent = PyFloat_AsDouble(o2);
385 return NPY_FLOAT_SCALAR;
386 }
387
388 if (PyArray_Check(o2)((((PyObject*)(o2))->ob_type) == (&PyArray_Type) || PyType_IsSubtype
((((PyObject*)(o2))->ob_type), (&PyArray_Type)))
) {
12
Assuming the condition is false
13
Assuming the condition is false
14
Taking false branch
389 if ((PyArray_NDIM((PyArrayObject *)o2) == 0) &&
390 ((PyArray_ISINTEGER((PyArrayObject *)o2)(((PyArray_TYPE((PyArrayObject *)o2)) >= NPY_BYTE) &&
((PyArray_TYPE((PyArrayObject *)o2)) <= NPY_ULONGLONG))
||
391 (optimize_fpexps && PyArray_ISFLOAT((PyArrayObject *)o2)((((PyArray_TYPE((PyArrayObject *)o2)) >= NPY_FLOAT) &&
((PyArray_TYPE((PyArrayObject *)o2)) <= NPY_LONGDOUBLE)) ||
((PyArray_TYPE((PyArrayObject *)o2)) == NPY_HALF))
)))) {
392 temp = Py_TYPE(o2)(((PyObject*)(o2))->ob_type)->tp_as_number->nb_float(o2);
393 if (temp == NULL((void*)0)) {
394 return NPY_NOSCALAR;
395 }
396 *out_exponent = PyFloat_AsDouble(o2);
397 Py_DECREF(temp)_Py_DECREF(((PyObject*)(temp)));
398 if (PyArray_ISINTEGER((PyArrayObject *)o2)(((PyArray_TYPE((PyArrayObject *)o2)) >= NPY_BYTE) &&
((PyArray_TYPE((PyArrayObject *)o2)) <= NPY_ULONGLONG))
) {
399 return NPY_INTPOS_SCALAR;
400 }
401 else { /* ISFLOAT */
402 return NPY_FLOAT_SCALAR;
403 }
404 }
405 }
406 else if (PyArray_IsScalar(o2, Integer)(((((PyObject*)(o2))->ob_type) == (&PyIntegerArrType_Type
) || PyType_IsSubtype((((PyObject*)(o2))->ob_type), (&
PyIntegerArrType_Type))))
||
15
Assuming the condition is false
16
Assuming the condition is false
19
Taking false branch
407 (optimize_fpexps
16.1
'optimize_fpexps' is 1
16.1
'optimize_fpexps' is 1
&& PyArray_IsScalar(o2, Floating)(((((PyObject*)(o2))->ob_type) == (&PyFloatingArrType_Type
) || PyType_IsSubtype((((PyObject*)(o2))->ob_type), (&
PyFloatingArrType_Type))))
)) {
17
Assuming the condition is false
18
Assuming the condition is false
408 temp = Py_TYPE(o2)(((PyObject*)(o2))->ob_type)->tp_as_number->nb_float(o2);
409 if (temp == NULL((void*)0)) {
410 return NPY_NOSCALAR;
411 }
412 *out_exponent = PyFloat_AsDouble(o2);
413 Py_DECREF(temp)_Py_DECREF(((PyObject*)(temp)));
414
415 if (PyArray_IsScalar(o2, Integer)(((((PyObject*)(o2))->ob_type) == (&PyIntegerArrType_Type
) || PyType_IsSubtype((((PyObject*)(o2))->ob_type), (&
PyIntegerArrType_Type))))
) {
416 return NPY_INTPOS_SCALAR;
417 }
418 else { /* IsScalar(o2, Floating) */
419 return NPY_FLOAT_SCALAR;
420 }
421 }
422 else if (PyIndex_Check(o2)((o2)->ob_type->tp_as_number != ((void*)0) && (
o2)->ob_type->tp_as_number->nb_index != ((void*)0))
) {
20
Assuming field 'tp_as_number' is not equal to null
21
Assuming field 'nb_index' is not equal to null
22
Taking true branch
423 PyObject* value = PyNumber_Index(o2);
23
Calling 'PyNumber_Index'
25
Returning from 'PyNumber_Index'
28
PyObject ownership leak with reference count of 1
424 Py_ssize_t val;
425 if (value == NULL((void*)0)) {
26
Assuming 'value' is not equal to NULL
27
Taking false branch
426 if (PyErr_Occurred()) {
427 PyErr_Clear();
428 }
429 return NPY_NOSCALAR;
430 }
431 val = PyLong_AsSsize_t(value);
432 if (error_converting(val)(((val) == -1) && PyErr_Occurred())) {
433 PyErr_Clear();
434 return NPY_NOSCALAR;
435 }
436 *out_exponent = (double) val;
437 return NPY_INTPOS_SCALAR;
438 }
439 return NPY_NOSCALAR;
440}
441
442/*
443 * optimize float array or complex array to a scalar power
444 * returns 0 on success, -1 if no optimization is possible
445 * the result is in value (can be NULL if an error occurred)
446 */
447static int
448fast_scalar_power(PyObject *o1, PyObject *o2, int inplace,
449 PyObject **value)
450{
451 double exponent;
452 NPY_SCALARKIND kind; /* NPY_NOSCALAR is not scalar */
453
454 if (PyArray_Check(o1)((((PyObject*)(o1))->ob_type) == (&PyArray_Type) || PyType_IsSubtype
((((PyObject*)(o1))->ob_type), (&PyArray_Type)))
&&
4
Assuming the condition is true
455 !PyArray_ISOBJECT((PyArrayObject *)o1)((PyArray_TYPE((PyArrayObject *)o1)) == NPY_OBJECT) &&
5
Assuming the condition is false
456 ((kind=is_scalar_with_conversion(o2, &exponent))>0)) {
6
Calling 'is_scalar_with_conversion'
457 PyArrayObject *a1 = (PyArrayObject *)o1;
458 PyObject *fastop = NULL((void*)0);
459 if (PyArray_ISFLOAT(a1)((((PyArray_TYPE(a1)) >= NPY_FLOAT) && ((PyArray_TYPE
(a1)) <= NPY_LONGDOUBLE)) || ((PyArray_TYPE(a1)) == NPY_HALF
))
|| PyArray_ISCOMPLEX(a1)(((PyArray_TYPE(a1)) >= NPY_CFLOAT) && ((PyArray_TYPE
(a1)) <= NPY_CLONGDOUBLE))
) {
460 if (exponent == 1.0) {
461 fastop = n_ops.positive;
462 }
463 else if (exponent == -1.0) {
464 fastop = n_ops.reciprocal;
465 }
466 else if (exponent == 0.0) {
467 fastop = n_ops._ones_like;
468 }
469 else if (exponent == 0.5) {
470 fastop = n_ops.sqrt;
471 }
472 else if (exponent == 2.0) {
473 fastop = n_ops.square;
474 }
475 else {
476 return -1;
477 }
478
479 if (inplace || can_elide_temp_unary(a1)) {
480 *value = PyArray_GenericInplaceUnaryFunction(a1, fastop);
481 }
482 else {
483 *value = PyArray_GenericUnaryFunction(a1, fastop);
484 }
485 return 0;
486 }
487 /* Because this is called with all arrays, we need to
488 * change the output if the kind of the scalar is different
489 * than that of the input and inplace is not on ---
490 * (thus, the input should be up-cast)
491 */
492 else if (exponent == 2.0) {
493 fastop = n_ops.square;
494 if (inplace) {
495 *value = PyArray_GenericInplaceUnaryFunction(a1, fastop);
496 }
497 else {
498 /* We only special-case the FLOAT_SCALAR and integer types */
499 if (kind == NPY_FLOAT_SCALAR && PyArray_ISINTEGER(a1)(((PyArray_TYPE(a1)) >= NPY_BYTE) && ((PyArray_TYPE
(a1)) <= NPY_ULONGLONG))
) {
500 PyArray_Descr *dtype = PyArray_DescrFromType(NPY_DOUBLE);
501 a1 = (PyArrayObject *)PyArray_CastToType(a1, dtype,
502 PyArray_ISFORTRAN(a1)(PyArray_CHKFLAGS(a1, 0x0002) && (!PyArray_CHKFLAGS(a1
, 0x0001)))
);
503 if (a1 != NULL((void*)0)) {
504 /* cast always creates a new array */
505 *value = PyArray_GenericInplaceUnaryFunction(a1, fastop);
506 Py_DECREF(a1)_Py_DECREF(((PyObject*)(a1)));
507 }
508 }
509 else {
510 *value = PyArray_GenericUnaryFunction(a1, fastop);
511 }
512 }
513 return 0;
514 }
515 }
516 /* no fast operation found */
517 return -1;
518}
519
520static PyObject *
521array_power(PyObject *a1, PyObject *o2, PyObject *modulo)
522{
523 PyObject *value = NULL((void*)0);
524
525 if (modulo != Py_None(&_Py_NoneStruct)) {
526 /* modular exponentiation is not implemented (gh-8804) */
527 Py_INCREF(Py_NotImplemented)_Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct))));
528 return Py_NotImplemented(&_Py_NotImplementedStruct);
529 }
530
531 BINOP_GIVE_UP_IF_NEEDED(a1, o2, nb_power, array_power)do { if (((((PyObject*)(o2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(o2))->ob_type
)->tp_as_number->nb_power) != (void*)(array_power)) &&
binop_should_defer((PyObject*)a1, (PyObject*)o2, 0)) { _Py_INCREF
(((PyObject*)((&_Py_NotImplementedStruct)))); return (&
_Py_NotImplementedStruct); } } while (0)
;
532 if (fast_scalar_power(a1, o2, 0, &value) != 0) {
533 value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);
534 }
535 return value;
536}
537
538static PyObject *
539array_positive(PyArrayObject *m1)
540{
541 /*
542 * For backwards compatibility, where + just implied a copy,
543 * we cannot just call n_ops.positive. Instead, we do the following
544 * 1. Try n_ops.positive
545 * 2. If we get an exception, check whether __array_ufunc__ is
546 * overridden; if so, we live in the future and we allow the
547 * TypeError to be passed on.
548 * 3. If not, give a deprecation warning and return a copy.
549 */
550 PyObject *value;
551 if (can_elide_temp_unary(m1)) {
552 value = PyArray_GenericInplaceUnaryFunction(m1, n_ops.positive);
553 }
554 else {
555 value = PyArray_GenericUnaryFunction(m1, n_ops.positive);
556 }
557 if (value == NULL((void*)0)) {
558 /*
559 * We first fetch the error, as it needs to be clear to check
560 * for the override. When the deprecation is removed,
561 * this whole stanza can be deleted.
562 */
563 PyObject *exc, *val, *tb;
564 PyErr_Fetch(&exc, &val, &tb);
565 if (PyUFunc_HasOverride((PyObject *)m1)) {
566 PyErr_Restore(exc, val, tb);
567 return NULL((void*)0);
568 }
569 Py_XDECREF(exc)_Py_XDECREF(((PyObject*)(exc)));
570 Py_XDECREF(val)_Py_XDECREF(((PyObject*)(val)));
571 Py_XDECREF(tb)_Py_XDECREF(((PyObject*)(tb)));
572
573 /* 2018-06-28, 1.16.0 */
574 if (DEPRECATE("Applying '+' to a non-numerical array is "PyErr_WarnEx(PyExc_DeprecationWarning,"Applying '+' to a non-numerical array is "
"ill-defined. Returning a copy, but in the future " "this will error."
,1)
575 "ill-defined. Returning a copy, but in the future "PyErr_WarnEx(PyExc_DeprecationWarning,"Applying '+' to a non-numerical array is "
"ill-defined. Returning a copy, but in the future " "this will error."
,1)
576 "this will error.")PyErr_WarnEx(PyExc_DeprecationWarning,"Applying '+' to a non-numerical array is "
"ill-defined. Returning a copy, but in the future " "this will error."
,1)
< 0) {
577 return NULL((void*)0);
578 }
579 value = PyArray_Return((PyArrayObject *)PyArray_Copy(m1)PyArray_NewCopy(m1, NPY_CORDER));
580 }
581 return value;
582}
583
584static PyObject *
585array_negative(PyArrayObject *m1)
586{
587 if (can_elide_temp_unary(m1)) {
588 return PyArray_GenericInplaceUnaryFunction(m1, n_ops.negative);
589 }
590 return PyArray_GenericUnaryFunction(m1, n_ops.negative);
591}
592
593static PyObject *
594array_absolute(PyArrayObject *m1)
595{
596 if (can_elide_temp_unary(m1) && !PyArray_ISCOMPLEX(m1)(((PyArray_TYPE(m1)) >= NPY_CFLOAT) && ((PyArray_TYPE
(m1)) <= NPY_CLONGDOUBLE))
) {
597 return PyArray_GenericInplaceUnaryFunction(m1, n_ops.absolute);
598 }
599 return PyArray_GenericUnaryFunction(m1, n_ops.absolute);
600}
601
602static PyObject *
603array_invert(PyArrayObject *m1)
604{
605 if (can_elide_temp_unary(m1)) {
606 return PyArray_GenericInplaceUnaryFunction(m1, n_ops.invert);
607 }
608 return PyArray_GenericUnaryFunction(m1, n_ops.invert);
609}
610
611static PyObject *
612array_left_shift(PyObject *m1, PyObject *m2)
613{
614 PyObject *res;
615
616 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_lshift, array_left_shift)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_lshift) != (void*)(array_left_shift
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 0)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
617 if (try_binary_elide(m1, m2, &array_inplace_left_shift, &res, 0)) {
618 return res;
619 }
620 return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);
621}
622
623static PyObject *
624array_right_shift(PyObject *m1, PyObject *m2)
625{
626 PyObject *res;
627
628 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_rshift, array_right_shift)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_rshift) != (void*)(array_right_shift
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 0)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
629 if (try_binary_elide(m1, m2, &array_inplace_right_shift, &res, 0)) {
630 return res;
631 }
632 return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);
633}
634
635static PyObject *
636array_bitwise_and(PyObject *m1, PyObject *m2)
637{
638 PyObject *res;
639
640 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_and, array_bitwise_and)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_and) != (void*)(array_bitwise_and))
&& binop_should_defer((PyObject*)m1, (PyObject*)m2, 0
)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct))
)); return (&_Py_NotImplementedStruct); } } while (0)
;
641 if (try_binary_elide(m1, m2, &array_inplace_bitwise_and, &res, 1)) {
642 return res;
643 }
644 return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);
645}
646
647static PyObject *
648array_bitwise_or(PyObject *m1, PyObject *m2)
649{
650 PyObject *res;
651
652 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_or, array_bitwise_or)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_or) != (void*)(array_bitwise_or)) &&
binop_should_defer((PyObject*)m1, (PyObject*)m2, 0)) { _Py_INCREF
(((PyObject*)((&_Py_NotImplementedStruct)))); return (&
_Py_NotImplementedStruct); } } while (0)
;
653 if (try_binary_elide(m1, m2, &array_inplace_bitwise_or, &res, 1)) {
654 return res;
655 }
656 return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);
657}
658
659static PyObject *
660array_bitwise_xor(PyObject *m1, PyObject *m2)
661{
662 PyObject *res;
663
664 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_xor, array_bitwise_xor)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_xor) != (void*)(array_bitwise_xor))
&& binop_should_defer((PyObject*)m1, (PyObject*)m2, 0
)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct))
)); return (&_Py_NotImplementedStruct); } } while (0)
;
665 if (try_binary_elide(m1, m2, &array_inplace_bitwise_xor, &res, 1)) {
666 return res;
667 }
668 return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);
669}
670
671static PyObject *
672array_inplace_add(PyArrayObject *m1, PyObject *m2)
673{
674 INPLACE_GIVE_UP_IF_NEEDED(do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_add) != (void*)(array_inplace_add
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
675 m1, m2, nb_inplace_add, array_inplace_add)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_add) != (void*)(array_inplace_add
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
676 return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);
677}
678
679static PyObject *
680array_inplace_subtract(PyArrayObject *m1, PyObject *m2)
681{
682 INPLACE_GIVE_UP_IF_NEEDED(do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_subtract) != (void*)(array_inplace_subtract
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
683 m1, m2, nb_inplace_subtract, array_inplace_subtract)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_subtract) != (void*)(array_inplace_subtract
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
684 return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);
685}
686
687static PyObject *
688array_inplace_multiply(PyArrayObject *m1, PyObject *m2)
689{
690 INPLACE_GIVE_UP_IF_NEEDED(do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_multiply) != (void*)(array_inplace_multiply
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
691 m1, m2, nb_inplace_multiply, array_inplace_multiply)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_multiply) != (void*)(array_inplace_multiply
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
692 return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);
693}
694
695static PyObject *
696array_inplace_remainder(PyArrayObject *m1, PyObject *m2)
697{
698 INPLACE_GIVE_UP_IF_NEEDED(do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_remainder) != (void*)(array_inplace_remainder
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
699 m1, m2, nb_inplace_remainder, array_inplace_remainder)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_remainder) != (void*)(array_inplace_remainder
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
700 return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);
701}
702
703static PyObject *
704array_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *NPY_UNUSED(modulo)(__NPY_UNUSED_TAGGEDmodulo) __attribute__ ((__unused__)))
705{
706 /* modulo is ignored! */
707 PyObject *value = NULL((void*)0);
708
709 INPLACE_GIVE_UP_IF_NEEDED(do { if (((((PyObject*)(o2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(o2))->ob_type
)->tp_as_number->nb_inplace_power) != (void*)(array_inplace_power
)) && binop_should_defer((PyObject*)a1, (PyObject*)o2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
1
Assuming field 'tp_as_number' is equal to null
2
Loop condition is false. Exiting loop
710 a1, o2, nb_inplace_power, array_inplace_power)do { if (((((PyObject*)(o2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(o2))->ob_type
)->tp_as_number->nb_inplace_power) != (void*)(array_inplace_power
)) && binop_should_defer((PyObject*)a1, (PyObject*)o2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
711 if (fast_scalar_power((PyObject *)a1, o2, 1, &value) != 0) {
3
Calling 'fast_scalar_power'
712 value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);
713 }
714 return value;
715}
716
717static PyObject *
718array_inplace_left_shift(PyArrayObject *m1, PyObject *m2)
719{
720 INPLACE_GIVE_UP_IF_NEEDED(do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_lshift) != (void*)(array_inplace_left_shift
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
721 m1, m2, nb_inplace_lshift, array_inplace_left_shift)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_lshift) != (void*)(array_inplace_left_shift
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
722 return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);
723}
724
725static PyObject *
726array_inplace_right_shift(PyArrayObject *m1, PyObject *m2)
727{
728 INPLACE_GIVE_UP_IF_NEEDED(do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_rshift) != (void*)(array_inplace_right_shift
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
729 m1, m2, nb_inplace_rshift, array_inplace_right_shift)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_rshift) != (void*)(array_inplace_right_shift
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
730 return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);
731}
732
733static PyObject *
734array_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)
735{
736 INPLACE_GIVE_UP_IF_NEEDED(do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_and) != (void*)(array_inplace_bitwise_and
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
737 m1, m2, nb_inplace_and, array_inplace_bitwise_and)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_and) != (void*)(array_inplace_bitwise_and
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
738 return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);
739}
740
741static PyObject *
742array_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)
743{
744 INPLACE_GIVE_UP_IF_NEEDED(do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_or) != (void*)(array_inplace_bitwise_or
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
745 m1, m2, nb_inplace_or, array_inplace_bitwise_or)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_or) != (void*)(array_inplace_bitwise_or
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
746 return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);
747}
748
749static PyObject *
750array_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)
751{
752 INPLACE_GIVE_UP_IF_NEEDED(do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_xor) != (void*)(array_inplace_bitwise_xor
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
753 m1, m2, nb_inplace_xor, array_inplace_bitwise_xor)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_xor) != (void*)(array_inplace_bitwise_xor
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
754 return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);
755}
756
757static PyObject *
758array_floor_divide(PyObject *m1, PyObject *m2)
759{
760 PyObject *res;
761
762 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_floor_divide, array_floor_divide)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_floor_divide) != (void*)(array_floor_divide
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 0)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
763 if (try_binary_elide(m1, m2, &array_inplace_floor_divide, &res, 0)) {
764 return res;
765 }
766 return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);
767}
768
769static PyObject *
770array_true_divide(PyObject *m1, PyObject *m2)
771{
772 PyObject *res;
773 PyArrayObject *a1 = (PyArrayObject *)m1;
774
775 BINOP_GIVE_UP_IF_NEEDED(m1, m2, nb_true_divide, array_true_divide)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_true_divide) != (void*)(array_true_divide
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 0)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
776 if (PyArray_CheckExact(m1)(((PyObject*)(m1))->ob_type == &PyArray_Type) &&
777 (PyArray_ISFLOAT(a1)((((PyArray_TYPE(a1)) >= NPY_FLOAT) && ((PyArray_TYPE
(a1)) <= NPY_LONGDOUBLE)) || ((PyArray_TYPE(a1)) == NPY_HALF
))
|| PyArray_ISCOMPLEX(a1)(((PyArray_TYPE(a1)) >= NPY_CFLOAT) && ((PyArray_TYPE
(a1)) <= NPY_CLONGDOUBLE))
) &&
778 try_binary_elide(m1, m2, &array_inplace_true_divide, &res, 0)) {
779 return res;
780 }
781 return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);
782}
783
784static PyObject *
785array_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)
786{
787 INPLACE_GIVE_UP_IF_NEEDED(do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_floor_divide) != (void*)(array_inplace_floor_divide
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
788 m1, m2, nb_inplace_floor_divide, array_inplace_floor_divide)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_floor_divide) != (void*)(array_inplace_floor_divide
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
789 return PyArray_GenericInplaceBinaryFunction(m1, m2,
790 n_ops.floor_divide);
791}
792
793static PyObject *
794array_inplace_true_divide(PyArrayObject *m1, PyObject *m2)
795{
796 INPLACE_GIVE_UP_IF_NEEDED(do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_true_divide) != (void*)(array_inplace_true_divide
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
797 m1, m2, nb_inplace_true_divide, array_inplace_true_divide)do { if (((((PyObject*)(m2))->ob_type)->tp_as_number !=
((void*)0) && (void*)((((PyObject*)(m2))->ob_type
)->tp_as_number->nb_inplace_true_divide) != (void*)(array_inplace_true_divide
)) && binop_should_defer((PyObject*)m1, (PyObject*)m2
, 1)) { _Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct
)))); return (&_Py_NotImplementedStruct); } } while (0)
;
798 return PyArray_GenericInplaceBinaryFunction(m1, m2,
799 n_ops.true_divide);
800}
801
802
803static int
804_array_nonzero(PyArrayObject *mp)
805{
806 npy_intp n;
807
808 n = PyArray_SIZE(mp)PyArray_MultiplyList(PyArray_DIMS(mp), PyArray_NDIM(mp));
809 if (n == 1) {
810 int res;
811 if (Py_EnterRecursiveCall(" while converting array to bool")((++(PyThreadState_Get()->recursion_depth) > _Py_CheckRecursionLimit
) && _Py_CheckRecursiveCall(" while converting array to bool"
))
) {
812 return -1;
813 }
814 res = PyArray_DESCR(mp)->f->nonzero(PyArray_DATA(mp), mp);
815 /* nonzero has no way to indicate an error, but one can occur */
816 if (PyErr_Occurred()) {
817 res = -1;
818 }
819 Py_LeaveRecursiveCall()do{ if((--(PyThreadState_Get()->recursion_depth) < (((_Py_CheckRecursionLimit
) > 200) ? ((_Py_CheckRecursionLimit) - 50) : (3 * ((_Py_CheckRecursionLimit
) >> 2))))) PyThreadState_Get()->overflowed = 0; } while
(0)
;
820 return res;
821 }
822 else if (n == 0) {
823 /* 2017-09-25, 1.14 */
824 if (DEPRECATE("The truth value of an empty array is ambiguous. "PyErr_WarnEx(PyExc_DeprecationWarning,"The truth value of an empty array is ambiguous. "
"Returning False, but in future this will result in an error. "
"Use `array.size > 0` to check that an array is not empty."
,1)
825 "Returning False, but in future this will result in an error. "PyErr_WarnEx(PyExc_DeprecationWarning,"The truth value of an empty array is ambiguous. "
"Returning False, but in future this will result in an error. "
"Use `array.size > 0` to check that an array is not empty."
,1)
826 "Use `array.size > 0` to check that an array is not empty.")PyErr_WarnEx(PyExc_DeprecationWarning,"The truth value of an empty array is ambiguous. "
"Returning False, but in future this will result in an error. "
"Use `array.size > 0` to check that an array is not empty."
,1)
< 0) {
827 return -1;
828 }
829 return 0;
830 }
831 else {
832 PyErr_SetString(PyExc_ValueError,
833 "The truth value of an array "
834 "with more than one element is ambiguous. "
835 "Use a.any() or a.all()");
836 return -1;
837 }
838}
839
840/*
841 * Convert the array to a scalar if allowed, and apply the builtin function
842 * to it. The where argument is passed onto Py_EnterRecursiveCall when the
843 * array contains python objects.
844 */
845NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
846array_scalar_forward(PyArrayObject *v,
847 PyObject *(*builtin_func)(PyObject *),
848 const char *where)
849{
850 PyObject *scalar;
851 if (PyArray_SIZE(v)PyArray_MultiplyList(PyArray_DIMS(v), PyArray_NDIM(v)) != 1) {
852 PyErr_SetString(PyExc_TypeError, "only size-1 arrays can be"\
853 " converted to Python scalars");
854 return NULL((void*)0);
855 }
856
857 scalar = PyArray_GETITEM(v, PyArray_DATA(v));
858 if (scalar == NULL((void*)0)) {
859 return NULL((void*)0);
860 }
861
862 /* Need to guard against recursion if our array holds references */
863 if (PyDataType_REFCHK(PyArray_DESCR(v))(((PyArray_DESCR(v))->flags & (0x01)) == (0x01))) {
864 PyObject *res;
865 if (Py_EnterRecursiveCall(where)((++(PyThreadState_Get()->recursion_depth) > _Py_CheckRecursionLimit
) && _Py_CheckRecursiveCall(where))
!= 0) {
866 Py_DECREF(scalar)_Py_DECREF(((PyObject*)(scalar)));
867 return NULL((void*)0);
868 }
869 res = builtin_func(scalar);
870 Py_DECREF(scalar)_Py_DECREF(((PyObject*)(scalar)));
871 Py_LeaveRecursiveCall()do{ if((--(PyThreadState_Get()->recursion_depth) < (((_Py_CheckRecursionLimit
) > 200) ? ((_Py_CheckRecursionLimit) - 50) : (3 * ((_Py_CheckRecursionLimit
) >> 2))))) PyThreadState_Get()->overflowed = 0; } while
(0)
;
872 return res;
873 }
874 else {
875 PyObject *res;
876 res = builtin_func(scalar);
877 Py_DECREF(scalar)_Py_DECREF(((PyObject*)(scalar)));
878 return res;
879 }
880}
881
882
883NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
884array_float(PyArrayObject *v)
885{
886 return array_scalar_forward(v, &PyNumber_Float, " in ndarray.__float__");
887}
888
889NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
890array_int(PyArrayObject *v)
891{
892 return array_scalar_forward(v, &PyNumber_Long, " in ndarray.__int__");
893}
894
895static PyObject *
896array_index(PyArrayObject *v)
897{
898 if (!PyArray_ISINTEGER(v)(((PyArray_TYPE(v)) >= NPY_BYTE) && ((PyArray_TYPE
(v)) <= NPY_ULONGLONG))
|| PyArray_NDIM(v) != 0) {
899 PyErr_SetString(PyExc_TypeError,
900 "only integer scalar arrays can be converted to a scalar index");
901 return NULL((void*)0);
902 }
903 return PyArray_GETITEM(v, PyArray_DATA(v));
904}
905
906
907NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyNumberMethods array_as_number = {
908 .nb_add = array_add,
909 .nb_subtract = array_subtract,
910 .nb_multiply = array_multiply,
911 .nb_remainder = array_remainder,
912 .nb_divmod = array_divmod,
913 .nb_power = (ternaryfunc)array_power,
914 .nb_negative = (unaryfunc)array_negative,
915 .nb_positive = (unaryfunc)array_positive,
916 .nb_absolute = (unaryfunc)array_absolute,
917 .nb_bool = (inquiry)_array_nonzero,
918 .nb_invert = (unaryfunc)array_invert,
919 .nb_lshift = array_left_shift,
920 .nb_rshift = array_right_shift,
921 .nb_and = array_bitwise_and,
922 .nb_xor = array_bitwise_xor,
923 .nb_or = array_bitwise_or,
924
925 .nb_int = (unaryfunc)array_int,
926 .nb_float = (unaryfunc)array_float,
927 .nb_index = (unaryfunc)array_index,
928
929 .nb_inplace_add = (binaryfunc)array_inplace_add,
930 .nb_inplace_subtract = (binaryfunc)array_inplace_subtract,
931 .nb_inplace_multiply = (binaryfunc)array_inplace_multiply,
932 .nb_inplace_remainder = (binaryfunc)array_inplace_remainder,
933 .nb_inplace_power = (ternaryfunc)array_inplace_power,
934 .nb_inplace_lshift = (binaryfunc)array_inplace_left_shift,
935 .nb_inplace_rshift = (binaryfunc)array_inplace_right_shift,
936 .nb_inplace_and = (binaryfunc)array_inplace_bitwise_and,
937 .nb_inplace_xor = (binaryfunc)array_inplace_bitwise_xor,
938 .nb_inplace_or = (binaryfunc)array_inplace_bitwise_or,
939
940 .nb_floor_divide = array_floor_divide,
941 .nb_true_divide = array_true_divide,
942 .nb_inplace_floor_divide = (binaryfunc)array_inplace_floor_divide,
943 .nb_inplace_true_divide = (binaryfunc)array_inplace_true_divide,
944
945 .nb_matrix_multiply = array_matrix_multiply,
946 .nb_inplace_matrix_multiply = (binaryfunc)array_inplace_matrix_multiply,
947};

/opt/pyrefcon/lib/pyrefcon/models/models/PyNumber_Index.model

1#ifndef PyNumber_Index
2struct _object;
3typedef struct _object PyObject;
4PyObject* clang_analyzer_PyObject_New_Reference();
5PyObject* PyNumber_Index(PyObject *o) {
6 return clang_analyzer_PyObject_New_Reference();
24
Setting reference count to 1
7}
8#else
9#warning "API PyNumber_Index is defined as a macro."
10#endif