Bug Summary

File:numpy/core/src/multiarray/multiarraymodule.c
Warning:line 4673, column 9
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 multiarraymodule.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/multiarraymodule.c

numpy/core/src/multiarray/multiarraymodule.c

1/*
2 Python Multiarray Module -- A useful collection of functions for creating and
3 using ndarrays
4
5 Original file
6 Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu
7
8 Modified for numpy in 2005
9
10 Travis E. Oliphant
11 oliphant@ee.byu.edu
12 Brigham Young University
13*/
14
15/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */
16
17#define PY_SSIZE_T_CLEAN
18#include "Python.h"
19#include "structmember.h"
20
21#define NPY_NO_DEPRECATED_API0x0000000E NPY_API_VERSION0x0000000E
22#define _UMATHMODULE
23#define _MULTIARRAYMODULE
24#include <numpy/npy_common.h>
25#include "numpy/arrayobject.h"
26#include "numpy/arrayscalars.h"
27
28#include "numpy/npy_math.h"
29#include "npy_argparse.h"
30#include "npy_config.h"
31#include "npy_pycompat.h"
32#include "npy_import.h"
33#include "convert_datatype.h"
34#include "legacy_dtype_implementation.h"
35
36NPY_NO_EXPORT__attribute__((visibility("hidden"))) int NPY_NUMUSERTYPES = 0;
37
38/* Internal APIs */
39#include "alloc.h"
40#include "abstractdtypes.h"
41#include "array_coercion.h"
42#include "arrayfunction_override.h"
43#include "arraytypes.h"
44#include "arrayobject.h"
45#include "hashdescr.h"
46#include "descriptor.h"
47#include "dragon4.h"
48#include "calculation.h"
49#include "number.h"
50#include "scalartypes.h"
51#include "convert_datatype.h"
52#include "conversion_utils.h"
53#include "nditer_pywrap.h"
54#include "methods.h"
55#include "_datetime.h"
56#include "datetime_strings.h"
57#include "datetime_busday.h"
58#include "datetime_busdaycal.h"
59#include "item_selection.h"
60#include "shape.h"
61#include "ctors.h"
62#include "array_assign.h"
63#include "common.h"
64#include "multiarraymodule.h"
65#include "cblasfuncs.h"
66#include "vdot.h"
67#include "templ_common.h" /* for npy_mul_with_overflow_intp */
68#include "compiled_base.h"
69#include "mem_overlap.h"
70#include "typeinfo.h"
71
72#include "get_attr_string.h"
73
74/*
75 *****************************************************************************
76 ** INCLUDE GENERATED CODE **
77 *****************************************************************************
78 */
79#include "funcs.inc"
80#include "umathmodule.h"
81
82NPY_NO_EXPORT__attribute__((visibility("hidden"))) int initscalarmath(PyObject *);
83NPY_NO_EXPORT__attribute__((visibility("hidden"))) int set_matmul_flags(PyObject *d); /* in ufunc_object.c */
84
85/*
86 * global variable to determine if legacy printing is enabled, accessible from
87 * C. For simplicity the mode is encoded as an integer where '0' means no
88 * legacy mode, and '113' means 1.13 legacy mode. We can upgrade this if we
89 * have more complex requirements in the future.
90 */
91int npy_legacy_print_mode = 0;
92
93static PyObject *
94set_legacy_print_mode(PyObject *NPY_UNUSED(self)(__NPY_UNUSED_TAGGEDself) __attribute__ ((__unused__)), PyObject *args)
95{
96 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "i", &npy_legacy_print_mode)) {
97 return NULL((void*)0);
98 }
99 Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (&
_Py_NoneStruct)
;
100}
101
102
103/* Only here for API compatibility */
104NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyTypeObject PyBigArray_Type;
105
106
107/*NUMPY_API
108 * Get Priority from object
109 */
110NPY_NO_EXPORT__attribute__((visibility("hidden"))) double
111PyArray_GetPriority(PyObject *obj, double default_)
112{
113 PyObject *ret;
114 double priority = NPY_PRIORITY0.0;
115
116 if (PyArray_CheckExact(obj)(((PyObject*)(obj))->ob_type == &PyArray_Type)) {
117 return priority;
118 }
119 else if (PyArray_CheckAnyScalarExact(obj)) {
120 return NPY_SCALAR_PRIORITY-1000000.0;
121 }
122
123 ret = PyArray_LookupSpecial_OnInstance(obj, "__array_priority__");
124 if (ret == NULL((void*)0)) {
125 if (PyErr_Occurred()) {
126 PyErr_Clear(); /* TODO[gh-14801]: propagate crashes during attribute access? */
127 }
128 return default_;
129 }
130
131 priority = PyFloat_AsDouble(ret);
132 Py_DECREF(ret)_Py_DECREF(((PyObject*)(ret)));
133 return priority;
134}
135
136/*NUMPY_API
137 * Multiply a List of ints
138 */
139NPY_NO_EXPORT__attribute__((visibility("hidden"))) int
140PyArray_MultiplyIntList(int const *l1, int n)
141{
142 int s = 1;
143
144 while (n--) {
145 s *= (*l1++);
146 }
147 return s;
148}
149
150/*NUMPY_API
151 * Multiply a List
152 */
153NPY_NO_EXPORT__attribute__((visibility("hidden"))) npy_intp
154PyArray_MultiplyList(npy_intp const *l1, int n)
155{
156 npy_intp s = 1;
157
158 while (n--) {
159 s *= (*l1++);
160 }
161 return s;
162}
163
164/*NUMPY_API
165 * Multiply a List of Non-negative numbers with over-flow detection.
166 */
167NPY_NO_EXPORT__attribute__((visibility("hidden"))) npy_intp
168PyArray_OverflowMultiplyList(npy_intp const *l1, int n)
169{
170 npy_intp prod = 1;
171 int i;
172
173 for (i = 0; i < n; i++) {
174 npy_intp dim = l1[i];
175
176 if (dim == 0) {
177 return 0;
178 }
179 if (npy_mul_with_overflow_intp(&prod, prod, dim)) {
180 return -1;
181 }
182 }
183 return prod;
184}
185
186/*NUMPY_API
187 * Produce a pointer into array
188 */
189NPY_NO_EXPORT__attribute__((visibility("hidden"))) void *
190PyArray_GetPtr(PyArrayObject *obj, npy_intp const* ind)
191{
192 int n = PyArray_NDIM(obj);
193 npy_intp *strides = PyArray_STRIDES(obj);
194 char *dptr = PyArray_DATA(obj);
195
196 while (n--) {
197 dptr += (*strides++) * (*ind++);
198 }
199 return (void *)dptr;
200}
201
202/*NUMPY_API
203 * Compare Lists
204 */
205NPY_NO_EXPORT__attribute__((visibility("hidden"))) int
206PyArray_CompareLists(npy_intp const *l1, npy_intp const *l2, int n)
207{
208 int i;
209
210 for (i = 0; i < n; i++) {
211 if (l1[i] != l2[i]) {
212 return 0;
213 }
214 }
215 return 1;
216}
217
218/*
219 * simulates a C-style 1-3 dimensional array which can be accessed using
220 * ptr[i] or ptr[i][j] or ptr[i][j][k] -- requires pointer allocation
221 * for 2-d and 3-d.
222 *
223 * For 2-d and up, ptr is NOT equivalent to a statically defined
224 * 2-d or 3-d array. In particular, it cannot be passed into a
225 * function that requires a true pointer to a fixed-size array.
226 */
227
228/*NUMPY_API
229 * Simulate a C-array
230 * steals a reference to typedescr -- can be NULL
231 */
232NPY_NO_EXPORT__attribute__((visibility("hidden"))) int
233PyArray_AsCArray(PyObject **op, void *ptr, npy_intp *dims, int nd,
234 PyArray_Descr* typedescr)
235{
236 PyArrayObject *ap;
237 npy_intp n, m, i, j;
238 char **ptr2;
239 char ***ptr3;
240
241 if ((nd < 1) || (nd > 3)) {
242 PyErr_SetString(PyExc_ValueError,
243 "C arrays of only 1-3 dimensions available");
244 Py_XDECREF(typedescr)_Py_XDECREF(((PyObject*)(typedescr)));
245 return -1;
246 }
247 if ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,
248 NPY_ARRAY_CARRAY(0x0001 | (0x0100 | 0x0400)), NULL((void*)0))) == NULL((void*)0)) {
249 return -1;
250 }
251 switch(nd) {
252 case 1:
253 *((char **)ptr) = PyArray_DATA(ap);
254 break;
255 case 2:
256 n = PyArray_DIMS(ap)[0];
257 ptr2 = (char **)PyArray_mallocPyMem_RawMalloc(n * sizeof(char *));
258 if (!ptr2) {
259 PyErr_NoMemory();
260 return -1;
261 }
262 for (i = 0; i < n; i++) {
263 ptr2[i] = PyArray_BYTES(ap) + i*PyArray_STRIDES(ap)[0];
264 }
265 *((char ***)ptr) = ptr2;
266 break;
267 case 3:
268 n = PyArray_DIMS(ap)[0];
269 m = PyArray_DIMS(ap)[1];
270 ptr3 = (char ***)PyArray_mallocPyMem_RawMalloc(n*(m+1) * sizeof(char *));
271 if (!ptr3) {
272 PyErr_NoMemory();
273 return -1;
274 }
275 for (i = 0; i < n; i++) {
276 ptr3[i] = (char **) &ptr3[n + m * i];
277 for (j = 0; j < m; j++) {
278 ptr3[i][j] = PyArray_BYTES(ap) + i*PyArray_STRIDES(ap)[0] + j*PyArray_STRIDES(ap)[1];
279 }
280 }
281 *((char ****)ptr) = ptr3;
282 }
283 if (nd) {
284 memcpy(dims, PyArray_DIMS(ap), nd*sizeof(npy_intp));
285 }
286 *op = (PyObject *)ap;
287 return 0;
288}
289
290/* Deprecated --- Use PyArray_AsCArray instead */
291
292/*NUMPY_API
293 * Convert to a 1D C-array
294 */
295NPY_NO_EXPORT__attribute__((visibility("hidden"))) int
296PyArray_As1D(PyObject **NPY_UNUSED(op)(__NPY_UNUSED_TAGGEDop) __attribute__ ((__unused__)), char **NPY_UNUSED(ptr)(__NPY_UNUSED_TAGGEDptr) __attribute__ ((__unused__)),
297 int *NPY_UNUSED(d1)(__NPY_UNUSED_TAGGEDd1) __attribute__ ((__unused__)), int NPY_UNUSED(typecode)(__NPY_UNUSED_TAGGEDtypecode) __attribute__ ((__unused__)))
298{
299 /* 2008-07-14, 1.5 */
300 PyErr_SetString(PyExc_NotImplementedError,
301 "PyArray_As1D: use PyArray_AsCArray.");
302 return -1;
303}
304
305/*NUMPY_API
306 * Convert to a 2D C-array
307 */
308NPY_NO_EXPORT__attribute__((visibility("hidden"))) int
309PyArray_As2D(PyObject **NPY_UNUSED(op)(__NPY_UNUSED_TAGGEDop) __attribute__ ((__unused__)), char ***NPY_UNUSED(ptr)(__NPY_UNUSED_TAGGEDptr) __attribute__ ((__unused__)),
310 int *NPY_UNUSED(d1)(__NPY_UNUSED_TAGGEDd1) __attribute__ ((__unused__)), int *NPY_UNUSED(d2)(__NPY_UNUSED_TAGGEDd2) __attribute__ ((__unused__)), int NPY_UNUSED(typecode)(__NPY_UNUSED_TAGGEDtypecode) __attribute__ ((__unused__)))
311{
312 /* 2008-07-14, 1.5 */
313 PyErr_SetString(PyExc_NotImplementedError,
314 "PyArray_As2D: use PyArray_AsCArray.");
315 return -1;
316}
317
318/* End Deprecated */
319
320/*NUMPY_API
321 * Free pointers created if As2D is called
322 */
323NPY_NO_EXPORT__attribute__((visibility("hidden"))) int
324PyArray_Free(PyObject *op, void *ptr)
325{
326 PyArrayObject *ap = (PyArrayObject *)op;
327
328 if ((PyArray_NDIM(ap) < 1) || (PyArray_NDIM(ap) > 3)) {
329 return -1;
330 }
331 if (PyArray_NDIM(ap) >= 2) {
332 PyArray_freePyMem_RawFree(ptr);
333 }
334 Py_DECREF(ap)_Py_DECREF(((PyObject*)(ap)));
335 return 0;
336}
337
338/*
339 * Get the ndarray subclass with the highest priority
340 */
341NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyTypeObject *
342PyArray_GetSubType(int narrays, PyArrayObject **arrays) {
343 PyTypeObject *subtype = &PyArray_Type;
344 double priority = NPY_PRIORITY0.0;
345 int i;
346
347 /* Get the priority subtype for the array */
348 for (i = 0; i < narrays; ++i) {
349 if (Py_TYPE(arrays[i])(((PyObject*)(arrays[i]))->ob_type) != subtype) {
350 double pr = PyArray_GetPriority((PyObject *)(arrays[i]), 0.0);
351 if (pr > priority) {
352 priority = pr;
353 subtype = Py_TYPE(arrays[i])(((PyObject*)(arrays[i]))->ob_type);
354 }
355 }
356 }
357
358 return subtype;
359}
360
361
362/*
363 * Concatenates a list of ndarrays.
364 */
365NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyArrayObject *
366PyArray_ConcatenateArrays(int narrays, PyArrayObject **arrays, int axis,
367 PyArrayObject* ret, PyArray_Descr *dtype,
368 NPY_CASTING casting)
369{
370 int iarrays, idim, ndim;
371 npy_intp shape[NPY_MAXDIMS32];
372 PyArrayObject_fields *sliding_view = NULL((void*)0);
373
374 if (narrays <= 0) {
375 PyErr_SetString(PyExc_ValueError,
376 "need at least one array to concatenate");
377 return NULL((void*)0);
378 }
379
380 /* All the arrays must have the same 'ndim' */
381 ndim = PyArray_NDIM(arrays[0]);
382
383 if (ndim == 0) {
384 PyErr_SetString(PyExc_ValueError,
385 "zero-dimensional arrays cannot be concatenated");
386 return NULL((void*)0);
387 }
388
389 /* Handle standard Python negative indexing */
390 if (check_and_adjust_axis(&axis, ndim) < 0) {
391 return NULL((void*)0);
392 }
393
394 /*
395 * Figure out the final concatenated shape starting from the first
396 * array's shape.
397 */
398 memcpy(shape, PyArray_SHAPE(arrays[0]), ndim * sizeof(shape[0]));
399 for (iarrays = 1; iarrays < narrays; ++iarrays) {
400 npy_intp *arr_shape;
401
402 if (PyArray_NDIM(arrays[iarrays]) != ndim) {
403 PyErr_Format(PyExc_ValueError,
404 "all the input arrays must have same number of "
405 "dimensions, but the array at index %d has %d "
406 "dimension(s) and the array at index %d has %d "
407 "dimension(s)",
408 0, ndim, iarrays, PyArray_NDIM(arrays[iarrays]));
409 return NULL((void*)0);
410 }
411 arr_shape = PyArray_SHAPE(arrays[iarrays]);
412
413 for (idim = 0; idim < ndim; ++idim) {
414 /* Build up the size of the concatenation axis */
415 if (idim == axis) {
416 shape[idim] += arr_shape[idim];
417 }
418 /* Validate that the rest of the dimensions match */
419 else if (shape[idim] != arr_shape[idim]) {
420 PyErr_Format(PyExc_ValueError,
421 "all the input array dimensions for the "
422 "concatenation axis must match exactly, but "
423 "along dimension %d, the array at index %d has "
424 "size %d and the array at index %d has size %d",
425 idim, 0, shape[idim], iarrays, arr_shape[idim]);
426 return NULL((void*)0);
427 }
428 }
429 }
430
431 if (ret != NULL((void*)0)) {
432 assert(dtype == NULL)((void) (0));
433 if (PyArray_NDIM(ret) != ndim) {
434 PyErr_SetString(PyExc_ValueError,
435 "Output array has wrong dimensionality");
436 return NULL((void*)0);
437 }
438 if (!PyArray_CompareLists(shape, PyArray_SHAPE(ret), ndim)) {
439 PyErr_SetString(PyExc_ValueError,
440 "Output array is the wrong shape");
441 return NULL((void*)0);
442 }
443 Py_INCREF(ret)_Py_INCREF(((PyObject*)(ret)));
444 }
445 else {
446 npy_intp s, strides[NPY_MAXDIMS32];
447 int strideperm[NPY_MAXDIMS32];
448
449 /* Get the priority subtype for the array */
450 PyTypeObject *subtype = PyArray_GetSubType(narrays, arrays);
451 PyArray_Descr *descr = PyArray_FindConcatenationDescriptor(
452 narrays, arrays, (PyObject *)dtype);
453 if (descr == NULL((void*)0)) {
454 return NULL((void*)0);
455 }
456
457 /*
458 * Figure out the permutation to apply to the strides to match
459 * the memory layout of the input arrays, using ambiguity
460 * resolution rules matching that of the NpyIter.
461 */
462 PyArray_CreateMultiSortedStridePerm(narrays, arrays, ndim, strideperm);
463 s = descr->elsize;
464 for (idim = ndim-1; idim >= 0; --idim) {
465 int iperm = strideperm[idim];
466 strides[iperm] = s;
467 s *= shape[iperm];
468 }
469
470 /* Allocate the array for the result. This steals the 'dtype' reference. */
471 ret = (PyArrayObject *)PyArray_NewFromDescr_int(
472 subtype, descr, ndim, shape, strides, NULL((void*)0), 0, NULL((void*)0),
473 NULL((void*)0), 0, 1);
474 if (ret == NULL((void*)0)) {
475 return NULL((void*)0);
476 }
477 assert(PyArray_DESCR(ret) == descr)((void) (0));
478 }
479
480 /*
481 * Create a view which slides through ret for assigning the
482 * successive input arrays.
483 */
484 sliding_view = (PyArrayObject_fields *)PyArray_View(ret,
485 NULL((void*)0), &PyArray_Type);
486 if (sliding_view == NULL((void*)0)) {
487 Py_DECREF(ret)_Py_DECREF(((PyObject*)(ret)));
488 return NULL((void*)0);
489 }
490 for (iarrays = 0; iarrays < narrays; ++iarrays) {
491 /* Set the dimension to match the input array's */
492 sliding_view->dimensions[axis] = PyArray_SHAPE(arrays[iarrays])[axis];
493
494 /* Copy the data for this array */
495 if (PyArray_AssignArray((PyArrayObject *)sliding_view, arrays[iarrays],
496 NULL((void*)0), casting) < 0) {
497 Py_DECREF(sliding_view)_Py_DECREF(((PyObject*)(sliding_view)));
498 Py_DECREF(ret)_Py_DECREF(((PyObject*)(ret)));
499 return NULL((void*)0);
500 }
501
502 /* Slide to the start of the next window */
503 sliding_view->data += sliding_view->dimensions[axis] *
504 sliding_view->strides[axis];
505 }
506
507 Py_DECREF(sliding_view)_Py_DECREF(((PyObject*)(sliding_view)));
508 return ret;
509}
510
511/*
512 * Concatenates a list of ndarrays, flattening each in the specified order.
513 */
514NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyArrayObject *
515PyArray_ConcatenateFlattenedArrays(int narrays, PyArrayObject **arrays,
516 NPY_ORDER order, PyArrayObject *ret,
517 PyArray_Descr *dtype, NPY_CASTING casting,
518 npy_bool casting_not_passed)
519{
520 int iarrays;
521 npy_intp shape = 0;
522 PyArrayObject_fields *sliding_view = NULL((void*)0);
523
524 if (narrays <= 0) {
525 PyErr_SetString(PyExc_ValueError,
526 "need at least one array to concatenate");
527 return NULL((void*)0);
528 }
529
530 /*
531 * Figure out the final concatenated shape starting from the first
532 * array's shape.
533 */
534 for (iarrays = 0; iarrays < narrays; ++iarrays) {
535 shape += PyArray_SIZE(arrays[iarrays])PyArray_MultiplyList(PyArray_DIMS(arrays[iarrays]), PyArray_NDIM
(arrays[iarrays]))
;
536 /* Check for overflow */
537 if (shape < 0) {
538 PyErr_SetString(PyExc_ValueError,
539 "total number of elements "
540 "too large to concatenate");
541 return NULL((void*)0);
542 }
543 }
544
545 int out_passed = 0;
546 if (ret != NULL((void*)0)) {
547 assert(dtype == NULL)((void) (0));
548 out_passed = 1;
549 if (PyArray_NDIM(ret) != 1) {
550 PyErr_SetString(PyExc_ValueError,
551 "Output array must be 1D");
552 return NULL((void*)0);
553 }
554 if (shape != PyArray_SIZE(ret)PyArray_MultiplyList(PyArray_DIMS(ret), PyArray_NDIM(ret))) {
555 PyErr_SetString(PyExc_ValueError,
556 "Output array is the wrong size");
557 return NULL((void*)0);
558 }
559 Py_INCREF(ret)_Py_INCREF(((PyObject*)(ret)));
560 }
561 else {
562 npy_intp stride;
563
564 /* Get the priority subtype for the array */
565 PyTypeObject *subtype = PyArray_GetSubType(narrays, arrays);
566
567 PyArray_Descr *descr = PyArray_FindConcatenationDescriptor(
568 narrays, arrays, (PyObject *)dtype);
569 if (descr == NULL((void*)0)) {
570 return NULL((void*)0);
571 }
572
573 stride = descr->elsize;
574
575 /* Allocate the array for the result. This steals the 'dtype' reference. */
576 ret = (PyArrayObject *)PyArray_NewFromDescr_int(
577 subtype, descr, 1, &shape, &stride, NULL((void*)0), 0, NULL((void*)0),
578 NULL((void*)0), 0, 1);
579 if (ret == NULL((void*)0)) {
580 return NULL((void*)0);
581 }
582 assert(PyArray_DESCR(ret) == descr)((void) (0));
583 }
584
585 /*
586 * Create a view which slides through ret for assigning the
587 * successive input arrays.
588 */
589 sliding_view = (PyArrayObject_fields *)PyArray_View(ret,
590 NULL((void*)0), &PyArray_Type);
591 if (sliding_view == NULL((void*)0)) {
592 Py_DECREF(ret)_Py_DECREF(((PyObject*)(ret)));
593 return NULL((void*)0);
594 }
595
596 int give_deprecation_warning = 1; /* To give warning for just one input array. */
597 for (iarrays = 0; iarrays < narrays; ++iarrays) {
598 /* Adjust the window dimensions for this array */
599 sliding_view->dimensions[0] = PyArray_SIZE(arrays[iarrays])PyArray_MultiplyList(PyArray_DIMS(arrays[iarrays]), PyArray_NDIM
(arrays[iarrays]))
;
600
601 if (!PyArray_CanCastArrayTo(
602 arrays[iarrays], PyArray_DESCR(ret), casting)) {
603 /* This should be an error, but was previously allowed here. */
604 if (casting_not_passed && out_passed) {
605 /* NumPy 1.20, 2020-09-03 */
606 if (give_deprecation_warning && DEPRECATE(PyErr_WarnEx(PyExc_DeprecationWarning,"concatenate() with `axis=None` will use same-kind "
"casting by default in the future. Please use " "`casting='unsafe'` to retain the old behaviour. "
"In the future this will be a TypeError.",1)
607 "concatenate() with `axis=None` will use same-kind "PyErr_WarnEx(PyExc_DeprecationWarning,"concatenate() with `axis=None` will use same-kind "
"casting by default in the future. Please use " "`casting='unsafe'` to retain the old behaviour. "
"In the future this will be a TypeError.",1)
608 "casting by default in the future. Please use "PyErr_WarnEx(PyExc_DeprecationWarning,"concatenate() with `axis=None` will use same-kind "
"casting by default in the future. Please use " "`casting='unsafe'` to retain the old behaviour. "
"In the future this will be a TypeError.",1)
609 "`casting='unsafe'` to retain the old behaviour. "PyErr_WarnEx(PyExc_DeprecationWarning,"concatenate() with `axis=None` will use same-kind "
"casting by default in the future. Please use " "`casting='unsafe'` to retain the old behaviour. "
"In the future this will be a TypeError.",1)
610 "In the future this will be a TypeError.")PyErr_WarnEx(PyExc_DeprecationWarning,"concatenate() with `axis=None` will use same-kind "
"casting by default in the future. Please use " "`casting='unsafe'` to retain the old behaviour. "
"In the future this will be a TypeError.",1)
< 0) {
611 Py_DECREF(sliding_view)_Py_DECREF(((PyObject*)(sliding_view)));
612 Py_DECREF(ret)_Py_DECREF(((PyObject*)(ret)));
613 return NULL((void*)0);
614 }
615 give_deprecation_warning = 0;
616 }
617 else {
618 npy_set_invalid_cast_error(
619 PyArray_DESCR(arrays[iarrays]), PyArray_DESCR(ret),
620 casting, PyArray_NDIM(arrays[iarrays]) == 0);
621 Py_DECREF(sliding_view)_Py_DECREF(((PyObject*)(sliding_view)));
622 Py_DECREF(ret)_Py_DECREF(((PyObject*)(ret)));
623 return NULL((void*)0);
624 }
625 }
626
627 /* Copy the data for this array */
628 if (PyArray_CopyAsFlat((PyArrayObject *)sliding_view, arrays[iarrays],
629 order) < 0) {
630 Py_DECREF(sliding_view)_Py_DECREF(((PyObject*)(sliding_view)));
631 Py_DECREF(ret)_Py_DECREF(((PyObject*)(ret)));
632 return NULL((void*)0);
633 }
634
635 /* Slide to the start of the next window */
636 sliding_view->data +=
637 sliding_view->strides[0] * PyArray_SIZE(arrays[iarrays])PyArray_MultiplyList(PyArray_DIMS(arrays[iarrays]), PyArray_NDIM
(arrays[iarrays]))
;
638 }
639
640 Py_DECREF(sliding_view)_Py_DECREF(((PyObject*)(sliding_view)));
641 return ret;
642}
643
644
645/**
646 * Implementation for np.concatenate
647 *
648 * @param op Sequence of arrays to concatenate
649 * @param axis Axis to concatenate along
650 * @param ret output array to fill
651 * @param dtype Forced output array dtype (cannot be combined with ret)
652 * @param casting Casting mode used
653 * @param casting_not_passed Deprecation helper
654 */
655NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
656PyArray_ConcatenateInto(PyObject *op,
657 int axis, PyArrayObject *ret, PyArray_Descr *dtype,
658 NPY_CASTING casting, npy_bool casting_not_passed)
659{
660 int iarrays, narrays;
661 PyArrayObject **arrays;
662
663 if (!PySequence_Check(op)) {
664 PyErr_SetString(PyExc_TypeError,
665 "The first input argument needs to be a sequence");
666 return NULL((void*)0);
667 }
668 if (ret != NULL((void*)0) && dtype != NULL((void*)0)) {
669 PyErr_SetString(PyExc_TypeError,
670 "concatenate() only takes `out` or `dtype` as an "
671 "argument, but both were provided.");
672 return NULL((void*)0);
673 }
674
675 /* Convert the input list into arrays */
676 narrays = PySequence_Size(op);
677 if (narrays < 0) {
678 return NULL((void*)0);
679 }
680 arrays = PyArray_mallocPyMem_RawMalloc(narrays * sizeof(arrays[0]));
681 if (arrays == NULL((void*)0)) {
682 PyErr_NoMemory();
683 return NULL((void*)0);
684 }
685 for (iarrays = 0; iarrays < narrays; ++iarrays) {
686 PyObject *item = PySequence_GetItem(op, iarrays);
687 if (item == NULL((void*)0)) {
688 narrays = iarrays;
689 goto fail;
690 }
691 arrays[iarrays] = (PyArrayObject *)PyArray_FROM_O(item)PyArray_FromAny(item, ((void*)0), 0, 0, 0, ((void*)0));
692 Py_DECREF(item)_Py_DECREF(((PyObject*)(item)));
693 if (arrays[iarrays] == NULL((void*)0)) {
694 narrays = iarrays;
695 goto fail;
696 }
697 }
698
699 if (axis >= NPY_MAXDIMS32) {
700 ret = PyArray_ConcatenateFlattenedArrays(
701 narrays, arrays, NPY_CORDER, ret, dtype,
702 casting, casting_not_passed);
703 }
704 else {
705 ret = PyArray_ConcatenateArrays(
706 narrays, arrays, axis, ret, dtype, casting);
707 }
708
709 for (iarrays = 0; iarrays < narrays; ++iarrays) {
710 Py_DECREF(arrays[iarrays])_Py_DECREF(((PyObject*)(arrays[iarrays])));
711 }
712 PyArray_freePyMem_RawFree(arrays);
713
714 return (PyObject *)ret;
715
716fail:
717 /* 'narrays' was set to how far we got in the conversion */
718 for (iarrays = 0; iarrays < narrays; ++iarrays) {
719 Py_DECREF(arrays[iarrays])_Py_DECREF(((PyObject*)(arrays[iarrays])));
720 }
721 PyArray_freePyMem_RawFree(arrays);
722
723 return NULL((void*)0);
724}
725
726/*NUMPY_API
727 * Concatenate
728 *
729 * Concatenate an arbitrary Python sequence into an array.
730 * op is a python object supporting the sequence interface.
731 * Its elements will be concatenated together to form a single
732 * multidimensional array. If axis is NPY_MAXDIMS or bigger, then
733 * each sequence object will be flattened before concatenation
734*/
735NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
736PyArray_Concatenate(PyObject *op, int axis)
737{
738 /* retain legacy behaviour for casting */
739 NPY_CASTING casting;
740 if (axis >= NPY_MAXDIMS32) {
741 casting = NPY_UNSAFE_CASTING;
742 }
743 else {
744 casting = NPY_SAME_KIND_CASTING;
745 }
746 return PyArray_ConcatenateInto(
747 op, axis, NULL((void*)0), NULL((void*)0), casting, 0);
748}
749
750static int
751_signbit_set(PyArrayObject *arr)
752{
753 static char bitmask = (char) 0x80;
754 char *ptr; /* points to the npy_byte to test */
755 char byteorder;
756 int elsize;
757
758 elsize = PyArray_DESCR(arr)->elsize;
759 byteorder = PyArray_DESCR(arr)->byteorder;
760 ptr = PyArray_DATA(arr);
761 if (elsize > 1 &&
762 (byteorder == NPY_LITTLE'<' ||
763 (byteorder == NPY_NATIVE'=' &&
764 PyArray_ISNBO(NPY_LITTLE)(('<') != '>')))) {
765 ptr += elsize - 1;
766 }
767 return ((*ptr & bitmask) != 0);
768}
769
770
771/*NUMPY_API
772 * ScalarKind
773 *
774 * Returns the scalar kind of a type number, with an
775 * optional tweak based on the scalar value itself.
776 * If no scalar is provided, it returns INTPOS_SCALAR
777 * for both signed and unsigned integers, otherwise
778 * it checks the sign of any signed integer to choose
779 * INTNEG_SCALAR when appropriate.
780 */
781NPY_NO_EXPORT__attribute__((visibility("hidden"))) NPY_SCALARKIND
782PyArray_ScalarKind(int typenum, PyArrayObject **arr)
783{
784 NPY_SCALARKIND ret = NPY_NOSCALAR;
785
786 if ((unsigned int)typenum < NPY_NTYPES) {
787 ret = _npy_scalar_kinds_table[typenum];
788 /* Signed integer types are INTNEG in the table */
789 if (ret == NPY_INTNEG_SCALAR) {
790 if (!arr || !_signbit_set(*arr)) {
791 ret = NPY_INTPOS_SCALAR;
792 }
793 }
794 } else if (PyTypeNum_ISUSERDEF(typenum)(((typenum) >= NPY_USERDEF) && ((typenum) < NPY_USERDEF
+ NPY_NUMUSERTYPES))
) {
795 PyArray_Descr* descr = PyArray_DescrFromType(typenum);
796
797 if (descr->f->scalarkind) {
798 ret = descr->f->scalarkind((arr ? *arr : NULL((void*)0)));
799 }
800 Py_DECREF(descr)_Py_DECREF(((PyObject*)(descr)));
801 }
802
803 return ret;
804}
805
806/*NUMPY_API
807 *
808 * Determines whether the data type 'thistype', with
809 * scalar kind 'scalar', can be coerced into 'neededtype'.
810 */
811NPY_NO_EXPORT__attribute__((visibility("hidden"))) int
812PyArray_CanCoerceScalar(int thistype, int neededtype,
813 NPY_SCALARKIND scalar)
814{
815 PyArray_Descr* from;
816 int *castlist;
817
818 /* If 'thistype' is not a scalar, it must be safely castable */
819 if (scalar == NPY_NOSCALAR) {
820 return PyArray_CanCastSafely(thistype, neededtype);
821 }
822 if ((unsigned int)neededtype < NPY_NTYPES) {
823 NPY_SCALARKIND neededscalar;
824
825 if (scalar == NPY_OBJECT_SCALAR) {
826 return PyArray_CanCastSafely(thistype, neededtype);
827 }
828
829 /*
830 * The lookup table gives us exactly what we need for
831 * this comparison, which PyArray_ScalarKind would not.
832 *
833 * The rule is that positive scalars can be coerced
834 * to a signed ints, but negative scalars cannot be coerced
835 * to unsigned ints.
836 * _npy_scalar_kinds_table[int]==NEGINT > POSINT,
837 * so 1 is returned, but
838 * _npy_scalar_kinds_table[uint]==POSINT < NEGINT,
839 * so 0 is returned, as required.
840 *
841 */
842 neededscalar = _npy_scalar_kinds_table[neededtype];
843 if (neededscalar >= scalar) {
844 return 1;
845 }
846 if (!PyTypeNum_ISUSERDEF(thistype)(((thistype) >= NPY_USERDEF) && ((thistype) < NPY_USERDEF
+ NPY_NUMUSERTYPES))
) {
847 return 0;
848 }
849 }
850
851 from = PyArray_DescrFromType(thistype);
852 if (from->f->cancastscalarkindto
853 && (castlist = from->f->cancastscalarkindto[scalar])) {
854 while (*castlist != NPY_NOTYPE) {
855 if (*castlist++ == neededtype) {
856 Py_DECREF(from)_Py_DECREF(((PyObject*)(from)));
857 return 1;
858 }
859 }
860 }
861 Py_DECREF(from)_Py_DECREF(((PyObject*)(from)));
862
863 return 0;
864}
865
866/* Could perhaps be redone to not make contiguous arrays */
867
868/*NUMPY_API
869 * Numeric.innerproduct(a,v)
870 */
871NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
872PyArray_InnerProduct(PyObject *op1, PyObject *op2)
873{
874 PyArrayObject *ap1 = NULL((void*)0);
875 PyArrayObject *ap2 = NULL((void*)0);
876 int typenum;
877 PyArray_Descr *typec = NULL((void*)0);
878 PyObject* ap2t = NULL((void*)0);
879 npy_intp dims[NPY_MAXDIMS32];
880 PyArray_Dims newaxes = {dims, 0};
881 int i;
882 PyObject* ret = NULL((void*)0);
883
884 typenum = PyArray_ObjectType(op1, 0);
885 if (typenum == NPY_NOTYPE && PyErr_Occurred()) {
886 return NULL((void*)0);
887 }
888 typenum = PyArray_ObjectType(op2, typenum);
889 typec = PyArray_DescrFromType(typenum);
890 if (typec == NULL((void*)0)) {
891 if (!PyErr_Occurred()) {
892 PyErr_SetString(PyExc_TypeError,
893 "Cannot find a common data type.");
894 }
895 goto fail;
896 }
897
898 Py_INCREF(typec)_Py_INCREF(((PyObject*)(typec)));
899 ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0,
900 NPY_ARRAY_ALIGNED0x0100, NULL((void*)0));
901 if (ap1 == NULL((void*)0)) {
902 Py_DECREF(typec)_Py_DECREF(((PyObject*)(typec)));
903 goto fail;
904 }
905 ap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,
906 NPY_ARRAY_ALIGNED0x0100, NULL((void*)0));
907 if (ap2 == NULL((void*)0)) {
908 goto fail;
909 }
910
911 newaxes.len = PyArray_NDIM(ap2);
912 if ((PyArray_NDIM(ap1) >= 1) && (newaxes.len >= 2)) {
913 for (i = 0; i < newaxes.len - 2; i++) {
914 dims[i] = (npy_intp)i;
915 }
916 dims[newaxes.len - 2] = newaxes.len - 1;
917 dims[newaxes.len - 1] = newaxes.len - 2;
918
919 ap2t = PyArray_Transpose(ap2, &newaxes);
920 if (ap2t == NULL((void*)0)) {
921 goto fail;
922 }
923 }
924 else {
925 ap2t = (PyObject *)ap2;
926 Py_INCREF(ap2)_Py_INCREF(((PyObject*)(ap2)));
927 }
928
929 ret = PyArray_MatrixProduct2((PyObject *)ap1, ap2t, NULL((void*)0));
930 if (ret == NULL((void*)0)) {
931 goto fail;
932 }
933
934
935 Py_DECREF(ap1)_Py_DECREF(((PyObject*)(ap1)));
936 Py_DECREF(ap2)_Py_DECREF(((PyObject*)(ap2)));
937 Py_DECREF(ap2t)_Py_DECREF(((PyObject*)(ap2t)));
938 return ret;
939
940fail:
941 Py_XDECREF(ap1)_Py_XDECREF(((PyObject*)(ap1)));
942 Py_XDECREF(ap2)_Py_XDECREF(((PyObject*)(ap2)));
943 Py_XDECREF(ap2t)_Py_XDECREF(((PyObject*)(ap2t)));
944 Py_XDECREF(ret)_Py_XDECREF(((PyObject*)(ret)));
945 return NULL((void*)0);
946}
947
948/*NUMPY_API
949 * Numeric.matrixproduct(a,v)
950 * just like inner product but does the swapaxes stuff on the fly
951 */
952NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
953PyArray_MatrixProduct(PyObject *op1, PyObject *op2)
954{
955 return PyArray_MatrixProduct2(op1, op2, NULL((void*)0));
956}
957
958/*NUMPY_API
959 * Numeric.matrixproduct2(a,v,out)
960 * just like inner product but does the swapaxes stuff on the fly
961 */
962NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
963PyArray_MatrixProduct2(PyObject *op1, PyObject *op2, PyArrayObject* out)
964{
965 PyArrayObject *ap1, *ap2, *out_buf = NULL((void*)0), *result = NULL((void*)0);
966 PyArrayIterObject *it1, *it2;
967 npy_intp i, j, l;
968 int typenum, nd, axis, matchDim;
969 npy_intp is1, is2, os;
970 char *op;
971 npy_intp dimensions[NPY_MAXDIMS32];
972 PyArray_DotFunc *dot;
973 PyArray_Descr *typec = NULL((void*)0);
974 NPY_BEGIN_THREADS_DEFPyThreadState *_save=((void*)0);;
975
976 typenum = PyArray_ObjectType(op1, 0);
977 if (typenum == NPY_NOTYPE && PyErr_Occurred()) {
978 return NULL((void*)0);
979 }
980 typenum = PyArray_ObjectType(op2, typenum);
981 typec = PyArray_DescrFromType(typenum);
982 if (typec == NULL((void*)0)) {
983 if (!PyErr_Occurred()) {
984 PyErr_SetString(PyExc_TypeError,
985 "Cannot find a common data type.");
986 }
987 return NULL((void*)0);
988 }
989
990 Py_INCREF(typec)_Py_INCREF(((PyObject*)(typec)));
991 ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0,
992 NPY_ARRAY_ALIGNED0x0100, NULL((void*)0));
993 if (ap1 == NULL((void*)0)) {
994 Py_DECREF(typec)_Py_DECREF(((PyObject*)(typec)));
995 return NULL((void*)0);
996 }
997 ap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,
998 NPY_ARRAY_ALIGNED0x0100, NULL((void*)0));
999 if (ap2 == NULL((void*)0)) {
1000 Py_DECREF(ap1)_Py_DECREF(((PyObject*)(ap1)));
1001 return NULL((void*)0);
1002 }
1003
1004#if defined(HAVE_CBLAS)
1005 if (PyArray_NDIM(ap1) <= 2 && PyArray_NDIM(ap2) <= 2 &&
1006 (NPY_DOUBLE == typenum || NPY_CDOUBLE == typenum ||
1007 NPY_FLOAT == typenum || NPY_CFLOAT == typenum)) {
1008 return cblas_matrixproduct(typenum, ap1, ap2, out);
1009 }
1010#endif
1011
1012 if (PyArray_NDIM(ap1) == 0 || PyArray_NDIM(ap2) == 0) {
1013 result = (PyArray_NDIM(ap1) == 0 ? ap1 : ap2);
1014 result = (PyArrayObject *)Py_TYPE(result)(((PyObject*)(result))->ob_type)->tp_as_number->nb_multiply(
1015 (PyObject *)ap1, (PyObject *)ap2);
1016 Py_DECREF(ap1)_Py_DECREF(((PyObject*)(ap1)));
1017 Py_DECREF(ap2)_Py_DECREF(((PyObject*)(ap2)));
1018 return (PyObject *)result;
1019 }
1020 l = PyArray_DIMS(ap1)[PyArray_NDIM(ap1) - 1];
1021 if (PyArray_NDIM(ap2) > 1) {
1022 matchDim = PyArray_NDIM(ap2) - 2;
1023 }
1024 else {
1025 matchDim = 0;
1026 }
1027 if (PyArray_DIMS(ap2)[matchDim] != l) {
1028 dot_alignment_error(ap1, PyArray_NDIM(ap1) - 1, ap2, matchDim);
1029 goto fail;
1030 }
1031 nd = PyArray_NDIM(ap1) + PyArray_NDIM(ap2) - 2;
1032 if (nd > NPY_MAXDIMS32) {
1033 PyErr_SetString(PyExc_ValueError, "dot: too many dimensions in result");
1034 goto fail;
1035 }
1036 j = 0;
1037 for (i = 0; i < PyArray_NDIM(ap1) - 1; i++) {
1038 dimensions[j++] = PyArray_DIMS(ap1)[i];
1039 }
1040 for (i = 0; i < PyArray_NDIM(ap2) - 2; i++) {
1041 dimensions[j++] = PyArray_DIMS(ap2)[i];
1042 }
1043 if (PyArray_NDIM(ap2) > 1) {
1044 dimensions[j++] = PyArray_DIMS(ap2)[PyArray_NDIM(ap2)-1];
1045 }
1046
1047 is1 = PyArray_STRIDES(ap1)[PyArray_NDIM(ap1)-1];
1048 is2 = PyArray_STRIDES(ap2)[matchDim];
1049 /* Choose which subtype to return */
1050 out_buf = new_array_for_sum(ap1, ap2, out, nd, dimensions, typenum, &result);
1051 if (out_buf == NULL((void*)0)) {
1052 goto fail;
1053 }
1054 /* Ensure that multiarray.dot(<Nx0>,<0xM>) -> zeros((N,M)) */
1055 if (PyArray_SIZE(ap1)PyArray_MultiplyList(PyArray_DIMS(ap1), PyArray_NDIM(ap1)) == 0 && PyArray_SIZE(ap2)PyArray_MultiplyList(PyArray_DIMS(ap2), PyArray_NDIM(ap2)) == 0) {
1056 memset(PyArray_DATA(out_buf), 0, PyArray_NBYTES(out_buf)(PyArray_ITEMSIZE(out_buf) * PyArray_MultiplyList(PyArray_DIMS
(out_buf), PyArray_NDIM(out_buf)))
);
1057 }
1058
1059 dot = PyArray_DESCR(out_buf)->f->dotfunc;
1060 if (dot == NULL((void*)0)) {
1061 PyErr_SetString(PyExc_ValueError,
1062 "dot not available for this type");
1063 goto fail;
1064 }
1065
1066 op = PyArray_DATA(out_buf);
1067 os = PyArray_DESCR(out_buf)->elsize;
1068 axis = PyArray_NDIM(ap1)-1;
1069 it1 = (PyArrayIterObject *)
1070 PyArray_IterAllButAxis((PyObject *)ap1, &axis);
1071 if (it1 == NULL((void*)0)) {
1072 goto fail;
1073 }
1074 it2 = (PyArrayIterObject *)
1075 PyArray_IterAllButAxis((PyObject *)ap2, &matchDim);
1076 if (it2 == NULL((void*)0)) {
1077 Py_DECREF(it1)_Py_DECREF(((PyObject*)(it1)));
1078 goto fail;
1079 }
1080 NPY_BEGIN_THREADS_DESCR(PyArray_DESCR(ap2))do {if (!(((((PyArray_DESCR(ap2)))->flags & (0x10)) ==
(0x10)))) do {_save = PyEval_SaveThread();} while (0);;} while
(0);
;
1081 while (it1->index < it1->size) {
1082 while (it2->index < it2->size) {
1083 dot(it1->dataptr, is1, it2->dataptr, is2, op, l, NULL((void*)0));
1084 op += os;
1085 PyArray_ITER_NEXT(it2)do { ((PyArrayIterObject *)(it2))->index++; if (((PyArrayIterObject
*)(it2))->nd_m1 == 0) { do { (((PyArrayIterObject *)(it2)
))->dataptr += ((PyArrayIterObject *)(((PyArrayIterObject *
)(it2))))->strides[0]; (((PyArrayIterObject *)(it2)))->
coordinates[0]++; } while (0); } else if (((PyArrayIterObject
*)(it2))->contiguous) ((PyArrayIterObject *)(it2))->dataptr
+= PyArray_DESCR(((PyArrayIterObject *)(it2))->ao)->elsize
; else if (((PyArrayIterObject *)(it2))->nd_m1 == 1) { do {
if ((((PyArrayIterObject *)(it2)))->coordinates[1] < (
((PyArrayIterObject *)(it2)))->dims_m1[1]) { (((PyArrayIterObject
*)(it2)))->coordinates[1]++; (((PyArrayIterObject *)(it2)
))->dataptr += (((PyArrayIterObject *)(it2)))->strides[
1]; } else { (((PyArrayIterObject *)(it2)))->coordinates[1
] = 0; (((PyArrayIterObject *)(it2)))->coordinates[0]++; (
((PyArrayIterObject *)(it2)))->dataptr += (((PyArrayIterObject
*)(it2)))->strides[0] - (((PyArrayIterObject *)(it2)))->
backstrides[1]; } } while (0); } else { int __npy_i; for (__npy_i
=((PyArrayIterObject *)(it2))->nd_m1; __npy_i >= 0; __npy_i
--) { if (((PyArrayIterObject *)(it2))->coordinates[__npy_i
] < ((PyArrayIterObject *)(it2))->dims_m1[__npy_i]) { (
(PyArrayIterObject *)(it2))->coordinates[__npy_i]++; ((PyArrayIterObject
*)(it2))->dataptr += ((PyArrayIterObject *)(it2))->strides
[__npy_i]; break; } else { ((PyArrayIterObject *)(it2))->coordinates
[__npy_i] = 0; ((PyArrayIterObject *)(it2))->dataptr -= ((
PyArrayIterObject *)(it2))->backstrides[__npy_i]; } } } } while
(0)
;
1086 }
1087 PyArray_ITER_NEXT(it1)do { ((PyArrayIterObject *)(it1))->index++; if (((PyArrayIterObject
*)(it1))->nd_m1 == 0) { do { (((PyArrayIterObject *)(it1)
))->dataptr += ((PyArrayIterObject *)(((PyArrayIterObject *
)(it1))))->strides[0]; (((PyArrayIterObject *)(it1)))->
coordinates[0]++; } while (0); } else if (((PyArrayIterObject
*)(it1))->contiguous) ((PyArrayIterObject *)(it1))->dataptr
+= PyArray_DESCR(((PyArrayIterObject *)(it1))->ao)->elsize
; else if (((PyArrayIterObject *)(it1))->nd_m1 == 1) { do {
if ((((PyArrayIterObject *)(it1)))->coordinates[1] < (
((PyArrayIterObject *)(it1)))->dims_m1[1]) { (((PyArrayIterObject
*)(it1)))->coordinates[1]++; (((PyArrayIterObject *)(it1)
))->dataptr += (((PyArrayIterObject *)(it1)))->strides[
1]; } else { (((PyArrayIterObject *)(it1)))->coordinates[1
] = 0; (((PyArrayIterObject *)(it1)))->coordinates[0]++; (
((PyArrayIterObject *)(it1)))->dataptr += (((PyArrayIterObject
*)(it1)))->strides[0] - (((PyArrayIterObject *)(it1)))->
backstrides[1]; } } while (0); } else { int __npy_i; for (__npy_i
=((PyArrayIterObject *)(it1))->nd_m1; __npy_i >= 0; __npy_i
--) { if (((PyArrayIterObject *)(it1))->coordinates[__npy_i
] < ((PyArrayIterObject *)(it1))->dims_m1[__npy_i]) { (
(PyArrayIterObject *)(it1))->coordinates[__npy_i]++; ((PyArrayIterObject
*)(it1))->dataptr += ((PyArrayIterObject *)(it1))->strides
[__npy_i]; break; } else { ((PyArrayIterObject *)(it1))->coordinates
[__npy_i] = 0; ((PyArrayIterObject *)(it1))->dataptr -= ((
PyArrayIterObject *)(it1))->backstrides[__npy_i]; } } } } while
(0)
;
1088 PyArray_ITER_RESET(it2)do { ((PyArrayIterObject *)(it2))->index = 0; ((PyArrayIterObject
*)(it2))->dataptr = PyArray_BYTES(((PyArrayIterObject *)(
it2))->ao); memset(((PyArrayIterObject *)(it2))->coordinates
, 0, (((PyArrayIterObject *)(it2))->nd_m1+1)*sizeof(npy_intp
)); } while (0)
;
1089 }
1090 NPY_END_THREADS_DESCR(PyArray_DESCR(ap2))do {if (!(((((PyArray_DESCR(ap2)))->flags & (0x10)) ==
(0x10)))) do { if (_save) { PyEval_RestoreThread(_save); _save
= ((void*)0);} } while (0);; } while (0);
;
1091 Py_DECREF(it1)_Py_DECREF(((PyObject*)(it1)));
1092 Py_DECREF(it2)_Py_DECREF(((PyObject*)(it2)));
1093 if (PyErr_Occurred()) {
1094 /* only for OBJECT arrays */
1095 goto fail;
1096 }
1097 Py_DECREF(ap1)_Py_DECREF(((PyObject*)(ap1)));
1098 Py_DECREF(ap2)_Py_DECREF(((PyObject*)(ap2)));
1099
1100 /* Trigger possible copy-back into `result` */
1101 PyArray_ResolveWritebackIfCopy(out_buf);
1102 Py_DECREF(out_buf)_Py_DECREF(((PyObject*)(out_buf)));
1103
1104 return (PyObject *)result;
1105
1106fail:
1107 Py_XDECREF(ap1)_Py_XDECREF(((PyObject*)(ap1)));
1108 Py_XDECREF(ap2)_Py_XDECREF(((PyObject*)(ap2)));
1109 Py_XDECREF(out_buf)_Py_XDECREF(((PyObject*)(out_buf)));
1110 Py_XDECREF(result)_Py_XDECREF(((PyObject*)(result)));
1111 return NULL((void*)0);
1112}
1113
1114
1115/*NUMPY_API
1116 * Copy and Transpose
1117 *
1118 * Could deprecate this function, as there isn't a speed benefit over
1119 * calling Transpose and then Copy.
1120 */
1121NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
1122PyArray_CopyAndTranspose(PyObject *op)
1123{
1124 PyArrayObject *arr, *tmp, *ret;
1125 int i;
1126 npy_intp new_axes_values[NPY_MAXDIMS32];
1127 PyArray_Dims new_axes;
1128
1129 /* Make sure we have an array */
1130 arr = (PyArrayObject *)PyArray_FROM_O(op)PyArray_FromAny(op, ((void*)0), 0, 0, 0, ((void*)0));
1131 if (arr == NULL((void*)0)) {
1132 return NULL((void*)0);
1133 }
1134
1135 if (PyArray_NDIM(arr) > 1) {
1136 /* Set up the transpose operation */
1137 new_axes.len = PyArray_NDIM(arr);
1138 for (i = 0; i < new_axes.len; ++i) {
1139 new_axes_values[i] = new_axes.len - i - 1;
1140 }
1141 new_axes.ptr = new_axes_values;
1142
1143 /* Do the transpose (always returns a view) */
1144 tmp = (PyArrayObject *)PyArray_Transpose(arr, &new_axes);
1145 if (tmp == NULL((void*)0)) {
1146 Py_DECREF(arr)_Py_DECREF(((PyObject*)(arr)));
1147 return NULL((void*)0);
1148 }
1149 }
1150 else {
1151 tmp = arr;
1152 arr = NULL((void*)0);
1153 }
1154
1155 /* TODO: Change this to NPY_KEEPORDER for NumPy 2.0 */
1156 ret = (PyArrayObject *)PyArray_NewCopy(tmp, NPY_CORDER);
1157
1158 Py_XDECREF(arr)_Py_XDECREF(((PyObject*)(arr)));
1159 Py_DECREF(tmp)_Py_DECREF(((PyObject*)(tmp)));
1160 return (PyObject *)ret;
1161}
1162
1163/*
1164 * Implementation which is common between PyArray_Correlate
1165 * and PyArray_Correlate2.
1166 *
1167 * inverted is set to 1 if computed correlate(ap2, ap1), 0 otherwise
1168 */
1169static PyArrayObject*
1170_pyarray_correlate(PyArrayObject *ap1, PyArrayObject *ap2, int typenum,
1171 int mode, int *inverted)
1172{
1173 PyArrayObject *ret;
1174 npy_intp length;
1175 npy_intp i, n1, n2, n, n_left, n_right;
1176 npy_intp is1, is2, os;
1177 char *ip1, *ip2, *op;
1178 PyArray_DotFunc *dot;
1179
1180 NPY_BEGIN_THREADS_DEFPyThreadState *_save=((void*)0);;
1181
1182 n1 = PyArray_DIMS(ap1)[0];
1183 n2 = PyArray_DIMS(ap2)[0];
1184 if (n1 == 0) {
1185 PyErr_SetString(PyExc_ValueError, "first array argument cannot be empty");
1186 return NULL((void*)0);
1187 }
1188 if (n2 == 0) {
1189 PyErr_SetString(PyExc_ValueError, "second array argument cannot be empty");
1190 return NULL((void*)0);
1191 }
1192 if (n1 < n2) {
1193 ret = ap1;
1194 ap1 = ap2;
1195 ap2 = ret;
1196 ret = NULL((void*)0);
1197 i = n1;
1198 n1 = n2;
1199 n2 = i;
1200 *inverted = 1;
1201 } else {
1202 *inverted = 0;
1203 }
1204
1205 length = n1;
1206 n = n2;
1207 switch(mode) {
1208 case 0:
1209 length = length - n + 1;
1210 n_left = n_right = 0;
1211 break;
1212 case 1:
1213 n_left = (npy_intp)(n/2);
1214 n_right = n - n_left - 1;
1215 break;
1216 case 2:
1217 n_right = n - 1;
1218 n_left = n - 1;
1219 length = length + n - 1;
1220 break;
1221 default:
1222 PyErr_SetString(PyExc_ValueError, "mode must be 0, 1, or 2");
1223 return NULL((void*)0);
1224 }
1225
1226 /*
1227 * Need to choose an output array that can hold a sum
1228 * -- use priority to determine which subtype.
1229 */
1230 ret = new_array_for_sum(ap1, ap2, NULL((void*)0), 1, &length, typenum, NULL((void*)0));
1231 if (ret == NULL((void*)0)) {
1232 return NULL((void*)0);
1233 }
1234 dot = PyArray_DESCR(ret)->f->dotfunc;
1235 if (dot == NULL((void*)0)) {
1236 PyErr_SetString(PyExc_ValueError,
1237 "function not available for this data type");
1238 goto clean_ret;
1239 }
1240
1241 NPY_BEGIN_THREADS_DESCR(PyArray_DESCR(ret))do {if (!(((((PyArray_DESCR(ret)))->flags & (0x10)) ==
(0x10)))) do {_save = PyEval_SaveThread();} while (0);;} while
(0);
;
1242 is1 = PyArray_STRIDES(ap1)[0];
1243 is2 = PyArray_STRIDES(ap2)[0];
1244 op = PyArray_DATA(ret);
1245 os = PyArray_DESCR(ret)->elsize;
1246 ip1 = PyArray_DATA(ap1);
1247 ip2 = PyArray_BYTES(ap2) + n_left*is2;
1248 n = n - n_left;
1249 for (i = 0; i < n_left; i++) {
1250 dot(ip1, is1, ip2, is2, op, n, ret);
1251 n++;
1252 ip2 -= is2;
1253 op += os;
1254 }
1255 if (small_correlate(ip1, is1, n1 - n2 + 1, PyArray_TYPE(ap1),
1256 ip2, is2, n, PyArray_TYPE(ap2),
1257 op, os)) {
1258 ip1 += is1 * (n1 - n2 + 1);
1259 op += os * (n1 - n2 + 1);
1260 }
1261 else {
1262 for (i = 0; i < (n1 - n2 + 1); i++) {
1263 dot(ip1, is1, ip2, is2, op, n, ret);
1264 ip1 += is1;
1265 op += os;
1266 }
1267 }
1268 for (i = 0; i < n_right; i++) {
1269 n--;
1270 dot(ip1, is1, ip2, is2, op, n, ret);
1271 ip1 += is1;
1272 op += os;
1273 }
1274
1275 NPY_END_THREADS_DESCR(PyArray_DESCR(ret))do {if (!(((((PyArray_DESCR(ret)))->flags & (0x10)) ==
(0x10)))) do { if (_save) { PyEval_RestoreThread(_save); _save
= ((void*)0);} } while (0);; } while (0);
;
1276 if (PyErr_Occurred()) {
1277 goto clean_ret;
1278 }
1279
1280 return ret;
1281
1282clean_ret:
1283 Py_DECREF(ret)_Py_DECREF(((PyObject*)(ret)));
1284 return NULL((void*)0);
1285}
1286
1287/*
1288 * Revert a one dimensional array in-place
1289 *
1290 * Return 0 on success, other value on failure
1291 */
1292static int
1293_pyarray_revert(PyArrayObject *ret)
1294{
1295 npy_intp length = PyArray_DIM(ret, 0);
1296 npy_intp os = PyArray_DESCR(ret)->elsize;
1297 char *op = PyArray_DATA(ret);
1298 char *sw1 = op;
1299 char *sw2;
1300
1301 if (PyArray_ISNUMBER(ret)(((PyArray_TYPE(ret)) <= NPY_CLONGDOUBLE) || ((PyArray_TYPE
(ret)) == NPY_HALF))
&& !PyArray_ISCOMPLEX(ret)(((PyArray_TYPE(ret)) >= NPY_CFLOAT) && ((PyArray_TYPE
(ret)) <= NPY_CLONGDOUBLE))
) {
1302 /* Optimization for unstructured dtypes */
1303 PyArray_CopySwapNFunc *copyswapn = PyArray_DESCR(ret)->f->copyswapn;
1304 sw2 = op + length * os - 1;
1305 /* First reverse the whole array byte by byte... */
1306 while(sw1 < sw2) {
1307 const char tmp = *sw1;
1308 *sw1++ = *sw2;
1309 *sw2-- = tmp;
1310 }
1311 /* ...then swap in place every item */
1312 copyswapn(op, os, NULL((void*)0), 0, length, 1, NULL((void*)0));
1313 }
1314 else {
1315 char *tmp = PyArray_mallocPyMem_RawMalloc(PyArray_DESCR(ret)->elsize);
1316 if (tmp == NULL((void*)0)) {
1317 PyErr_NoMemory();
1318 return -1;
1319 }
1320 sw2 = op + (length - 1) * os;
1321 while (sw1 < sw2) {
1322 memcpy(tmp, sw1, os);
1323 memcpy(sw1, sw2, os);
1324 memcpy(sw2, tmp, os);
1325 sw1 += os;
1326 sw2 -= os;
1327 }
1328 PyArray_freePyMem_RawFree(tmp);
1329 }
1330
1331 return 0;
1332}
1333
1334/*NUMPY_API
1335 * correlate(a1,a2,mode)
1336 *
1337 * This function computes the usual correlation (correlate(a1, a2) !=
1338 * correlate(a2, a1), and conjugate the second argument for complex inputs
1339 */
1340NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
1341PyArray_Correlate2(PyObject *op1, PyObject *op2, int mode)
1342{
1343 PyArrayObject *ap1, *ap2, *ret = NULL((void*)0);
1344 int typenum;
1345 PyArray_Descr *typec;
1346 int inverted;
1347 int st;
1348
1349 typenum = PyArray_ObjectType(op1, 0);
1350 typenum = PyArray_ObjectType(op2, typenum);
1351
1352 typec = PyArray_DescrFromType(typenum);
1353 Py_INCREF(typec)_Py_INCREF(((PyObject*)(typec)));
1354 ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 1, 1,
1355 NPY_ARRAY_DEFAULT((0x0001 | (0x0100 | 0x0400))), NULL((void*)0));
1356 if (ap1 == NULL((void*)0)) {
1357 Py_DECREF(typec)_Py_DECREF(((PyObject*)(typec)));
1358 return NULL((void*)0);
1359 }
1360 ap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 1, 1,
1361 NPY_ARRAY_DEFAULT((0x0001 | (0x0100 | 0x0400))), NULL((void*)0));
1362 if (ap2 == NULL((void*)0)) {
1363 goto clean_ap1;
1364 }
1365
1366 if (PyArray_ISCOMPLEX(ap2)(((PyArray_TYPE(ap2)) >= NPY_CFLOAT) && ((PyArray_TYPE
(ap2)) <= NPY_CLONGDOUBLE))
) {
1367 PyArrayObject *cap2;
1368 cap2 = (PyArrayObject *)PyArray_Conjugate(ap2, NULL((void*)0));
1369 if (cap2 == NULL((void*)0)) {
1370 goto clean_ap2;
1371 }
1372 Py_DECREF(ap2)_Py_DECREF(((PyObject*)(ap2)));
1373 ap2 = cap2;
1374 }
1375
1376 ret = _pyarray_correlate(ap1, ap2, typenum, mode, &inverted);
1377 if (ret == NULL((void*)0)) {
1378 goto clean_ap2;
1379 }
1380
1381 /*
1382 * If we inverted input orders, we need to reverse the output array (i.e.
1383 * ret = ret[::-1])
1384 */
1385 if (inverted) {
1386 st = _pyarray_revert(ret);
1387 if (st) {
1388 goto clean_ret;
1389 }
1390 }
1391
1392 Py_DECREF(ap1)_Py_DECREF(((PyObject*)(ap1)));
1393 Py_DECREF(ap2)_Py_DECREF(((PyObject*)(ap2)));
1394 return (PyObject *)ret;
1395
1396clean_ret:
1397 Py_DECREF(ret)_Py_DECREF(((PyObject*)(ret)));
1398clean_ap2:
1399 Py_DECREF(ap2)_Py_DECREF(((PyObject*)(ap2)));
1400clean_ap1:
1401 Py_DECREF(ap1)_Py_DECREF(((PyObject*)(ap1)));
1402 return NULL((void*)0);
1403}
1404
1405/*NUMPY_API
1406 * Numeric.correlate(a1,a2,mode)
1407 */
1408NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
1409PyArray_Correlate(PyObject *op1, PyObject *op2, int mode)
1410{
1411 PyArrayObject *ap1, *ap2, *ret = NULL((void*)0);
1412 int typenum;
1413 int unused;
1414 PyArray_Descr *typec;
1415
1416 typenum = PyArray_ObjectType(op1, 0);
1417 typenum = PyArray_ObjectType(op2, typenum);
1418
1419 typec = PyArray_DescrFromType(typenum);
1420 Py_INCREF(typec)_Py_INCREF(((PyObject*)(typec)));
1421 ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 1, 1,
1422 NPY_ARRAY_DEFAULT((0x0001 | (0x0100 | 0x0400))), NULL((void*)0));
1423 if (ap1 == NULL((void*)0)) {
1424 Py_DECREF(typec)_Py_DECREF(((PyObject*)(typec)));
1425 return NULL((void*)0);
1426 }
1427 ap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 1, 1,
1428 NPY_ARRAY_DEFAULT((0x0001 | (0x0100 | 0x0400))), NULL((void*)0));
1429 if (ap2 == NULL((void*)0)) {
1430 goto fail;
1431 }
1432
1433 ret = _pyarray_correlate(ap1, ap2, typenum, mode, &unused);
1434 if (ret == NULL((void*)0)) {
1435 goto fail;
1436 }
1437 Py_DECREF(ap1)_Py_DECREF(((PyObject*)(ap1)));
1438 Py_DECREF(ap2)_Py_DECREF(((PyObject*)(ap2)));
1439 return (PyObject *)ret;
1440
1441fail:
1442 Py_XDECREF(ap1)_Py_XDECREF(((PyObject*)(ap1)));
1443 Py_XDECREF(ap2)_Py_XDECREF(((PyObject*)(ap2)));
1444 Py_XDECREF(ret)_Py_XDECREF(((PyObject*)(ret)));
1445 return NULL((void*)0);
1446}
1447
1448
1449static PyObject *
1450array_putmask(PyObject *NPY_UNUSED(module)(__NPY_UNUSED_TAGGEDmodule) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
1451{
1452 PyObject *mask, *values;
1453 PyObject *array;
1454
1455 static char *kwlist[] = {"arr", "mask", "values", NULL((void*)0)};
1456
1457 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "O!OO:putmask", kwlist,
1458 &PyArray_Type, &array, &mask, &values)) {
1459 return NULL((void*)0);
1460 }
1461 return PyArray_PutMask((PyArrayObject *)array, values, mask);
1462}
1463
1464
1465/*NUMPY_API
1466 *
1467 * This function returns true if the two typecodes are
1468 * equivalent (same basic kind and same itemsize).
1469 */
1470NPY_NO_EXPORT__attribute__((visibility("hidden"))) unsigned char
1471PyArray_EquivTypes(PyArray_Descr *type1, PyArray_Descr *type2)
1472{
1473 if (type1 == type2) {
1474 return 1;
1475 }
1476 /*
1477 * Do not use PyArray_CanCastTypeTo because it supports legacy flexible
1478 * dtypes as input.
1479 */
1480 NPY_CASTING safety = PyArray_GetCastSafety(type1, type2, NULL((void*)0));
1481 if (safety < 0) {
1482 PyErr_Clear();
1483 return 0;
1484 }
1485 /* If casting is "no casting" this dtypes are considered equivalent. */
1486 return PyArray_MinCastSafety(safety, NPY_NO_CASTING) == NPY_NO_CASTING;
1487}
1488
1489
1490/*NUMPY_API*/
1491NPY_NO_EXPORT__attribute__((visibility("hidden"))) unsigned char
1492PyArray_EquivTypenums(int typenum1, int typenum2)
1493{
1494 PyArray_Descr *d1, *d2;
1495 npy_bool ret;
1496
1497 if (typenum1 == typenum2) {
1498 return NPY_SUCCEED1;
1499 }
1500
1501 d1 = PyArray_DescrFromType(typenum1);
1502 d2 = PyArray_DescrFromType(typenum2);
1503 ret = PyArray_EquivTypes(d1, d2);
1504 Py_DECREF(d1)_Py_DECREF(((PyObject*)(d1)));
1505 Py_DECREF(d2)_Py_DECREF(((PyObject*)(d2)));
1506 return ret;
1507}
1508
1509/*** END C-API FUNCTIONS **/
1510/*
1511 * NPY_RELAXED_STRIDES_CHECKING: If the strides logic is changed, the
1512 * order specific stride setting is not necessary.
1513 */
1514static NPY_STEALS_REF_TO_ARG(1) PyObject *
1515_prepend_ones(PyArrayObject *arr, int nd, int ndmin, NPY_ORDER order)
1516{
1517 npy_intp newdims[NPY_MAXDIMS32];
1518 npy_intp newstrides[NPY_MAXDIMS32];
1519 npy_intp newstride;
1520 int i, k, num;
1521 PyObject *ret;
1522 PyArray_Descr *dtype;
1523
1524 if (order == NPY_FORTRANORDER || PyArray_ISFORTRAN(arr)(PyArray_CHKFLAGS(arr, 0x0002) && (!PyArray_CHKFLAGS(
arr, 0x0001)))
|| PyArray_NDIM(arr) == 0) {
1525 newstride = PyArray_DESCR(arr)->elsize;
1526 }
1527 else {
1528 newstride = PyArray_STRIDES(arr)[0] * PyArray_DIMS(arr)[0];
1529 }
1530
1531 num = ndmin - nd;
1532 for (i = 0; i < num; i++) {
1533 newdims[i] = 1;
1534 newstrides[i] = newstride;
1535 }
1536 for (i = num; i < ndmin; i++) {
1537 k = i - num;
1538 newdims[i] = PyArray_DIMS(arr)[k];
1539 newstrides[i] = PyArray_STRIDES(arr)[k];
1540 }
1541 dtype = PyArray_DESCR(arr);
1542 Py_INCREF(dtype)_Py_INCREF(((PyObject*)(dtype)));
1543 ret = PyArray_NewFromDescrAndBase(
1544 Py_TYPE(arr)(((PyObject*)(arr))->ob_type), dtype,
1545 ndmin, newdims, newstrides, PyArray_DATA(arr),
1546 PyArray_FLAGS(arr), (PyObject *)arr, (PyObject *)arr);
1547 Py_DECREF(arr)_Py_DECREF(((PyObject*)(arr)));
1548
1549 return ret;
1550}
1551
1552#define STRIDING_OK(op, order) \
1553 ((order) == NPY_ANYORDER || \
1554 (order) == NPY_KEEPORDER || \
1555 ((order) == NPY_CORDER && PyArray_IS_C_CONTIGUOUS(op)PyArray_CHKFLAGS((op), 0x0001)) || \
1556 ((order) == NPY_FORTRANORDER && PyArray_IS_F_CONTIGUOUS(op)PyArray_CHKFLAGS((op), 0x0002)))
1557
1558static NPY_INLINEinline PyObject *
1559_array_fromobject_generic(
1560 PyObject *op, PyArray_Descr *type, npy_bool copy, NPY_ORDER order,
1561 npy_bool subok, int ndmin)
1562{
1563 PyArrayObject *oparr = NULL((void*)0), *ret = NULL((void*)0);
1564 PyArray_Descr *oldtype = NULL((void*)0);
1565 int nd, flags = 0;
1566
1567 if (ndmin > NPY_MAXDIMS32) {
1568 PyErr_Format(PyExc_ValueError,
1569 "ndmin bigger than allowable number of dimensions "
1570 "NPY_MAXDIMS (=%d)", NPY_MAXDIMS32);
1571 return NULL((void*)0);
1572 }
1573 /* fast exit if simple call */
1574 if (PyArray_CheckExact(op)(((PyObject*)(op))->ob_type == &PyArray_Type) || (subok && PyArray_Check(op)((((PyObject*)(op))->ob_type) == (&PyArray_Type) || PyType_IsSubtype
((((PyObject*)(op))->ob_type), (&PyArray_Type)))
)) {
1575 oparr = (PyArrayObject *)op;
1576 if (type == NULL((void*)0)) {
1577 if (!copy && STRIDING_OK(oparr, order)) {
1578 ret = oparr;
1579 Py_INCREF(ret)_Py_INCREF(((PyObject*)(ret)));
1580 goto finish;
1581 }
1582 else {
1583 ret = (PyArrayObject *)PyArray_NewCopy(oparr, order);
1584 goto finish;
1585 }
1586 }
1587 /* One more chance */
1588 oldtype = PyArray_DESCR(oparr);
1589 if (PyArray_EquivTypes(oldtype, type)) {
1590 if (!copy && STRIDING_OK(oparr, order)) {
1591 Py_INCREF(op)_Py_INCREF(((PyObject*)(op)));
1592 ret = oparr;
1593 goto finish;
1594 }
1595 else {
1596 ret = (PyArrayObject *)PyArray_NewCopy(oparr, order);
1597 if (oldtype == type || ret == NULL((void*)0)) {
1598 goto finish;
1599 }
1600 Py_INCREF(oldtype)_Py_INCREF(((PyObject*)(oldtype)));
1601 Py_DECREF(PyArray_DESCR(ret))_Py_DECREF(((PyObject*)(PyArray_DESCR(ret))));
1602 ((PyArrayObject_fields *)ret)->descr = oldtype;
1603 goto finish;
1604 }
1605 }
1606 }
1607
1608 if (copy) {
1609 flags = NPY_ARRAY_ENSURECOPY0x0020;
1610 }
1611 if (order == NPY_CORDER) {
1612 flags |= NPY_ARRAY_C_CONTIGUOUS0x0001;
1613 }
1614 else if ((order == NPY_FORTRANORDER)
1615 /* order == NPY_ANYORDER && */
1616 || (PyArray_Check(op)((((PyObject*)(op))->ob_type) == (&PyArray_Type) || PyType_IsSubtype
((((PyObject*)(op))->ob_type), (&PyArray_Type)))
&&
1617 PyArray_ISFORTRAN((PyArrayObject *)op)(PyArray_CHKFLAGS((PyArrayObject *)op, 0x0002) && (!PyArray_CHKFLAGS
((PyArrayObject *)op, 0x0001)))
)) {
1618 flags |= NPY_ARRAY_F_CONTIGUOUS0x0002;
1619 }
1620 if (!subok) {
1621 flags |= NPY_ARRAY_ENSUREARRAY0x0040;
1622 }
1623
1624 flags |= NPY_ARRAY_FORCECAST0x0010;
1625 Py_XINCREF(type)_Py_XINCREF(((PyObject*)(type)));
1626 ret = (PyArrayObject *)PyArray_CheckFromAny(op, type,
1627 0, 0, flags, NULL((void*)0));
1628
1629finish:
1630 if (ret == NULL((void*)0)) {
1631 return NULL((void*)0);
1632 }
1633
1634 nd = PyArray_NDIM(ret);
1635 if (nd >= ndmin) {
1636 return (PyObject *)ret;
1637 }
1638 /*
1639 * create a new array from the same data with ones in the shape
1640 * steals a reference to ret
1641 */
1642 return _prepend_ones(ret, nd, ndmin, order);
1643}
1644
1645#undef STRIDING_OK
1646
1647
1648static PyObject *
1649array_array(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)),
1650 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
1651{
1652 PyObject *op;
1653 npy_bool subok = NPY_FALSE0;
1654 npy_bool copy = NPY_TRUE1;
1655 int ndmin = 0;
1656 PyArray_Descr *type = NULL((void*)0);
1657 NPY_ORDER order = NPY_KEEPORDER;
1658 PyObject *like = NULL((void*)0);
1659 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
1660
1661 if (len_args != 1 || (kwnames != NULL((void*)0))) {
1662 if (npy_parse_arguments("array", args, len_args, kwnames,_npy_parse_arguments("array", &__argparse_cache, args, len_args
, kwnames, "object", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "$copy", &PyArray_BoolConverter, &copy, "$order"
, &PyArray_OrderConverter, &order, "$subok", &PyArray_BoolConverter
, &subok, "$ndmin", &PyArray_PythonPyIntFromInt, &
ndmin, "$like", ((void*)0), &like, ((void*)0), ((void*)0)
, ((void*)0))
1663 "object", NULL, &op,_npy_parse_arguments("array", &__argparse_cache, args, len_args
, kwnames, "object", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "$copy", &PyArray_BoolConverter, &copy, "$order"
, &PyArray_OrderConverter, &order, "$subok", &PyArray_BoolConverter
, &subok, "$ndmin", &PyArray_PythonPyIntFromInt, &
ndmin, "$like", ((void*)0), &like, ((void*)0), ((void*)0)
, ((void*)0))
1664 "|dtype", &PyArray_DescrConverter2, &type,_npy_parse_arguments("array", &__argparse_cache, args, len_args
, kwnames, "object", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "$copy", &PyArray_BoolConverter, &copy, "$order"
, &PyArray_OrderConverter, &order, "$subok", &PyArray_BoolConverter
, &subok, "$ndmin", &PyArray_PythonPyIntFromInt, &
ndmin, "$like", ((void*)0), &like, ((void*)0), ((void*)0)
, ((void*)0))
1665 "$copy", &PyArray_BoolConverter, &copy,_npy_parse_arguments("array", &__argparse_cache, args, len_args
, kwnames, "object", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "$copy", &PyArray_BoolConverter, &copy, "$order"
, &PyArray_OrderConverter, &order, "$subok", &PyArray_BoolConverter
, &subok, "$ndmin", &PyArray_PythonPyIntFromInt, &
ndmin, "$like", ((void*)0), &like, ((void*)0), ((void*)0)
, ((void*)0))
1666 "$order", &PyArray_OrderConverter, &order,_npy_parse_arguments("array", &__argparse_cache, args, len_args
, kwnames, "object", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "$copy", &PyArray_BoolConverter, &copy, "$order"
, &PyArray_OrderConverter, &order, "$subok", &PyArray_BoolConverter
, &subok, "$ndmin", &PyArray_PythonPyIntFromInt, &
ndmin, "$like", ((void*)0), &like, ((void*)0), ((void*)0)
, ((void*)0))
1667 "$subok", &PyArray_BoolConverter, &subok,_npy_parse_arguments("array", &__argparse_cache, args, len_args
, kwnames, "object", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "$copy", &PyArray_BoolConverter, &copy, "$order"
, &PyArray_OrderConverter, &order, "$subok", &PyArray_BoolConverter
, &subok, "$ndmin", &PyArray_PythonPyIntFromInt, &
ndmin, "$like", ((void*)0), &like, ((void*)0), ((void*)0)
, ((void*)0))
1668 "$ndmin", &PyArray_PythonPyIntFromInt, &ndmin,_npy_parse_arguments("array", &__argparse_cache, args, len_args
, kwnames, "object", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "$copy", &PyArray_BoolConverter, &copy, "$order"
, &PyArray_OrderConverter, &order, "$subok", &PyArray_BoolConverter
, &subok, "$ndmin", &PyArray_PythonPyIntFromInt, &
ndmin, "$like", ((void*)0), &like, ((void*)0), ((void*)0)
, ((void*)0))
1669 "$like", NULL, &like,_npy_parse_arguments("array", &__argparse_cache, args, len_args
, kwnames, "object", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "$copy", &PyArray_BoolConverter, &copy, "$order"
, &PyArray_OrderConverter, &order, "$subok", &PyArray_BoolConverter
, &subok, "$ndmin", &PyArray_PythonPyIntFromInt, &
ndmin, "$like", ((void*)0), &like, ((void*)0), ((void*)0)
, ((void*)0))
1670 NULL, NULL, NULL)_npy_parse_arguments("array", &__argparse_cache, args, len_args
, kwnames, "object", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "$copy", &PyArray_BoolConverter, &copy, "$order"
, &PyArray_OrderConverter, &order, "$subok", &PyArray_BoolConverter
, &subok, "$ndmin", &PyArray_PythonPyIntFromInt, &
ndmin, "$like", ((void*)0), &like, ((void*)0), ((void*)0)
, ((void*)0))
< 0) {
1671 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1672 return NULL((void*)0);
1673 }
1674 if (like != NULL((void*)0)) {
1675 PyObject *deferred = array_implement_c_array_function_creation(
1676 "array", like, NULL((void*)0), NULL((void*)0), args, len_args, kwnames);
1677 if (deferred != Py_NotImplemented(&_Py_NotImplementedStruct)) {
1678 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1679 return deferred;
1680 }
1681 }
1682 }
1683 else {
1684 /* Fast path for symmetry (we copy by default which is slow) */
1685 op = args[0];
1686 }
1687
1688 PyObject *res = _array_fromobject_generic(
1689 op, type, copy, order, subok, ndmin);
1690 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1691 return res;
1692}
1693
1694static PyObject *
1695array_asarray(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)),
1696 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
1697{
1698 PyObject *op;
1699 PyArray_Descr *type = NULL((void*)0);
1700 NPY_ORDER order = NPY_KEEPORDER;
1701 PyObject *like = NULL((void*)0);
1702 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
1703
1704 if (len_args != 1 || (kwnames != NULL((void*)0))) {
1705 if (npy_parse_arguments("asarray", args, len_args, kwnames,_npy_parse_arguments("asarray", &__argparse_cache, args, len_args
, kwnames, "a", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "|order", &PyArray_OrderConverter, &order
, "$like", ((void*)0), &like, ((void*)0), ((void*)0), ((void
*)0))
1706 "a", NULL, &op,_npy_parse_arguments("asarray", &__argparse_cache, args, len_args
, kwnames, "a", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "|order", &PyArray_OrderConverter, &order
, "$like", ((void*)0), &like, ((void*)0), ((void*)0), ((void
*)0))
1707 "|dtype", &PyArray_DescrConverter2, &type,_npy_parse_arguments("asarray", &__argparse_cache, args, len_args
, kwnames, "a", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "|order", &PyArray_OrderConverter, &order
, "$like", ((void*)0), &like, ((void*)0), ((void*)0), ((void
*)0))
1708 "|order", &PyArray_OrderConverter, &order,_npy_parse_arguments("asarray", &__argparse_cache, args, len_args
, kwnames, "a", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "|order", &PyArray_OrderConverter, &order
, "$like", ((void*)0), &like, ((void*)0), ((void*)0), ((void
*)0))
1709 "$like", NULL, &like,_npy_parse_arguments("asarray", &__argparse_cache, args, len_args
, kwnames, "a", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "|order", &PyArray_OrderConverter, &order
, "$like", ((void*)0), &like, ((void*)0), ((void*)0), ((void
*)0))
1710 NULL, NULL, NULL)_npy_parse_arguments("asarray", &__argparse_cache, args, len_args
, kwnames, "a", ((void*)0), &op, "|dtype", &PyArray_DescrConverter2
, &type, "|order", &PyArray_OrderConverter, &order
, "$like", ((void*)0), &like, ((void*)0), ((void*)0), ((void
*)0))
< 0) {
1711 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1712 return NULL((void*)0);
1713 }
1714 if (like != NULL((void*)0)) {
1715 PyObject *deferred = array_implement_c_array_function_creation(
1716 "asarray", like, NULL((void*)0), NULL((void*)0), args, len_args, kwnames);
1717 if (deferred != Py_NotImplemented(&_Py_NotImplementedStruct)) {
1718 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1719 return deferred;
1720 }
1721 }
1722 }
1723 else {
1724 op = args[0];
1725 }
1726
1727 PyObject *res = _array_fromobject_generic(
1728 op, type, NPY_FALSE0, order, NPY_FALSE0, 0);
1729 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1730 return res;
1731}
1732
1733static PyObject *
1734array_asanyarray(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)),
1735 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
1736{
1737 PyObject *op;
1738 PyArray_Descr *type = NULL((void*)0);
1739 NPY_ORDER order = NPY_KEEPORDER;
1740 PyObject *like = NULL((void*)0);
1741 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
1742
1743 if (len_args != 1 || (kwnames != NULL((void*)0))) {
1744 if (npy_parse_arguments("asanyarray", args, len_args, kwnames,_npy_parse_arguments("asanyarray", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &op, "|dtype", &
PyArray_DescrConverter2, &type, "|order", &PyArray_OrderConverter
, &order, "$like", ((void*)0), &like, ((void*)0), ((void
*)0), ((void*)0))
1745 "a", NULL, &op,_npy_parse_arguments("asanyarray", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &op, "|dtype", &
PyArray_DescrConverter2, &type, "|order", &PyArray_OrderConverter
, &order, "$like", ((void*)0), &like, ((void*)0), ((void
*)0), ((void*)0))
1746 "|dtype", &PyArray_DescrConverter2, &type,_npy_parse_arguments("asanyarray", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &op, "|dtype", &
PyArray_DescrConverter2, &type, "|order", &PyArray_OrderConverter
, &order, "$like", ((void*)0), &like, ((void*)0), ((void
*)0), ((void*)0))
1747 "|order", &PyArray_OrderConverter, &order,_npy_parse_arguments("asanyarray", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &op, "|dtype", &
PyArray_DescrConverter2, &type, "|order", &PyArray_OrderConverter
, &order, "$like", ((void*)0), &like, ((void*)0), ((void
*)0), ((void*)0))
1748 "$like", NULL, &like,_npy_parse_arguments("asanyarray", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &op, "|dtype", &
PyArray_DescrConverter2, &type, "|order", &PyArray_OrderConverter
, &order, "$like", ((void*)0), &like, ((void*)0), ((void
*)0), ((void*)0))
1749 NULL, NULL, NULL)_npy_parse_arguments("asanyarray", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &op, "|dtype", &
PyArray_DescrConverter2, &type, "|order", &PyArray_OrderConverter
, &order, "$like", ((void*)0), &like, ((void*)0), ((void
*)0), ((void*)0))
< 0) {
1750 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1751 return NULL((void*)0);
1752 }
1753 if (like != NULL((void*)0)) {
1754 PyObject *deferred = array_implement_c_array_function_creation(
1755 "asanyarray", like, NULL((void*)0), NULL((void*)0), args, len_args, kwnames);
1756 if (deferred != Py_NotImplemented(&_Py_NotImplementedStruct)) {
1757 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1758 return deferred;
1759 }
1760 }
1761 }
1762 else {
1763 op = args[0];
1764 }
1765
1766 PyObject *res = _array_fromobject_generic(
1767 op, type, NPY_FALSE0, order, NPY_TRUE1, 0);
1768 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1769 return res;
1770}
1771
1772
1773static PyObject *
1774array_ascontiguousarray(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)),
1775 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
1776{
1777 PyObject *op;
1778 PyArray_Descr *type = NULL((void*)0);
1779 PyObject *like = NULL((void*)0);
1780 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
1781
1782 if (len_args != 1 || (kwnames != NULL((void*)0))) {
1783 if (npy_parse_arguments("ascontiguousarray", args, len_args, kwnames,_npy_parse_arguments("ascontiguousarray", &__argparse_cache
, args, len_args, kwnames, "a", ((void*)0), &op, "|dtype"
, &PyArray_DescrConverter2, &type, "$like", ((void*)0
), &like, ((void*)0), ((void*)0), ((void*)0))
1784 "a", NULL, &op,_npy_parse_arguments("ascontiguousarray", &__argparse_cache
, args, len_args, kwnames, "a", ((void*)0), &op, "|dtype"
, &PyArray_DescrConverter2, &type, "$like", ((void*)0
), &like, ((void*)0), ((void*)0), ((void*)0))
1785 "|dtype", &PyArray_DescrConverter2, &type,_npy_parse_arguments("ascontiguousarray", &__argparse_cache
, args, len_args, kwnames, "a", ((void*)0), &op, "|dtype"
, &PyArray_DescrConverter2, &type, "$like", ((void*)0
), &like, ((void*)0), ((void*)0), ((void*)0))
1786 "$like", NULL, &like,_npy_parse_arguments("ascontiguousarray", &__argparse_cache
, args, len_args, kwnames, "a", ((void*)0), &op, "|dtype"
, &PyArray_DescrConverter2, &type, "$like", ((void*)0
), &like, ((void*)0), ((void*)0), ((void*)0))
1787 NULL, NULL, NULL)_npy_parse_arguments("ascontiguousarray", &__argparse_cache
, args, len_args, kwnames, "a", ((void*)0), &op, "|dtype"
, &PyArray_DescrConverter2, &type, "$like", ((void*)0
), &like, ((void*)0), ((void*)0), ((void*)0))
< 0) {
1788 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1789 return NULL((void*)0);
1790 }
1791 if (like != NULL((void*)0)) {
1792 PyObject *deferred = array_implement_c_array_function_creation(
1793 "ascontiguousarray", like, NULL((void*)0), NULL((void*)0), args, len_args, kwnames);
1794 if (deferred != Py_NotImplemented(&_Py_NotImplementedStruct)) {
1795 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1796 return deferred;
1797 }
1798 }
1799 }
1800 else {
1801 op = args[0];
1802 }
1803
1804 PyObject *res = _array_fromobject_generic(
1805 op, type, NPY_FALSE0, NPY_CORDER, NPY_FALSE0, 1);
1806 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1807 return res;
1808}
1809
1810
1811static PyObject *
1812array_asfortranarray(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)),
1813 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
1814{
1815 PyObject *op;
1816 PyArray_Descr *type = NULL((void*)0);
1817 PyObject *like = NULL((void*)0);
1818 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
1819
1820 if (len_args != 1 || (kwnames != NULL((void*)0))) {
1821 if (npy_parse_arguments("asfortranarray", args, len_args, kwnames,_npy_parse_arguments("asfortranarray", &__argparse_cache,
args, len_args, kwnames, "a", ((void*)0), &op, "|dtype",
&PyArray_DescrConverter2, &type, "$like", ((void*)0)
, &like, ((void*)0), ((void*)0), ((void*)0))
1822 "a", NULL, &op,_npy_parse_arguments("asfortranarray", &__argparse_cache,
args, len_args, kwnames, "a", ((void*)0), &op, "|dtype",
&PyArray_DescrConverter2, &type, "$like", ((void*)0)
, &like, ((void*)0), ((void*)0), ((void*)0))
1823 "|dtype", &PyArray_DescrConverter2, &type,_npy_parse_arguments("asfortranarray", &__argparse_cache,
args, len_args, kwnames, "a", ((void*)0), &op, "|dtype",
&PyArray_DescrConverter2, &type, "$like", ((void*)0)
, &like, ((void*)0), ((void*)0), ((void*)0))
1824 "$like", NULL, &like,_npy_parse_arguments("asfortranarray", &__argparse_cache,
args, len_args, kwnames, "a", ((void*)0), &op, "|dtype",
&PyArray_DescrConverter2, &type, "$like", ((void*)0)
, &like, ((void*)0), ((void*)0), ((void*)0))
1825 NULL, NULL, NULL)_npy_parse_arguments("asfortranarray", &__argparse_cache,
args, len_args, kwnames, "a", ((void*)0), &op, "|dtype",
&PyArray_DescrConverter2, &type, "$like", ((void*)0)
, &like, ((void*)0), ((void*)0), ((void*)0))
< 0) {
1826 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1827 return NULL((void*)0);
1828 }
1829 if (like != NULL((void*)0)) {
1830 PyObject *deferred = array_implement_c_array_function_creation(
1831 "asfortranarray", like, NULL((void*)0), NULL((void*)0), args, len_args, kwnames);
1832 if (deferred != Py_NotImplemented(&_Py_NotImplementedStruct)) {
1833 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1834 return deferred;
1835 }
1836 }
1837 }
1838 else {
1839 op = args[0];
1840 }
1841
1842 PyObject *res = _array_fromobject_generic(
1843 op, type, NPY_FALSE0, NPY_FORTRANORDER, NPY_FALSE0, 1);
1844 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
1845 return res;
1846}
1847
1848
1849static PyObject *
1850array_copyto(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
1851{
1852 static char *kwlist[] = {"dst", "src", "casting", "where", NULL((void*)0)};
1853 PyObject *wheremask_in = NULL((void*)0);
1854 PyArrayObject *dst = NULL((void*)0), *src = NULL((void*)0), *wheremask = NULL((void*)0);
1855 NPY_CASTING casting = NPY_SAME_KIND_CASTING;
1856
1857 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "O!O&|O&O:copyto", kwlist,
1858 &PyArray_Type, &dst,
1859 &PyArray_Converter, &src,
1860 &PyArray_CastingConverter, &casting,
1861 &wheremask_in)) {
1862 goto fail;
1863 }
1864
1865 if (wheremask_in != NULL((void*)0)) {
1866 /* Get the boolean where mask */
1867 PyArray_Descr *dtype = PyArray_DescrFromType(NPY_BOOL);
1868 if (dtype == NULL((void*)0)) {
1869 goto fail;
1870 }
1871 wheremask = (PyArrayObject *)PyArray_FromAny(wheremask_in,
1872 dtype, 0, 0, 0, NULL((void*)0));
1873 if (wheremask == NULL((void*)0)) {
1874 goto fail;
1875 }
1876 }
1877
1878 if (PyArray_AssignArray(dst, src, wheremask, casting) < 0) {
1879 goto fail;
1880 }
1881
1882 Py_XDECREF(src)_Py_XDECREF(((PyObject*)(src)));
1883 Py_XDECREF(wheremask)_Py_XDECREF(((PyObject*)(wheremask)));
1884
1885 Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (&
_Py_NoneStruct)
;
1886
1887fail:
1888 Py_XDECREF(src)_Py_XDECREF(((PyObject*)(src)));
1889 Py_XDECREF(wheremask)_Py_XDECREF(((PyObject*)(wheremask)));
1890 return NULL((void*)0);
1891}
1892
1893static PyObject *
1894array_empty(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)),
1895 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
1896{
1897 PyArray_Descr *typecode = NULL((void*)0);
1898 PyArray_Dims shape = {NULL((void*)0), 0};
1899 NPY_ORDER order = NPY_CORDER;
1900 npy_bool is_f_order;
1901 PyArrayObject *ret = NULL((void*)0);
1902 PyObject *like = NULL((void*)0);
1903 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
1904
1905 if (npy_parse_arguments("empty", args, len_args, kwnames,_npy_parse_arguments("empty", &__argparse_cache, args, len_args
, kwnames, "shape", &PyArray_IntpConverter, &shape, "|dtype"
, &PyArray_DescrConverter, &typecode, "|order", &
PyArray_OrderConverter, &order, "$like", ((void*)0), &
like, ((void*)0), ((void*)0), ((void*)0))
1906 "shape", &PyArray_IntpConverter, &shape,_npy_parse_arguments("empty", &__argparse_cache, args, len_args
, kwnames, "shape", &PyArray_IntpConverter, &shape, "|dtype"
, &PyArray_DescrConverter, &typecode, "|order", &
PyArray_OrderConverter, &order, "$like", ((void*)0), &
like, ((void*)0), ((void*)0), ((void*)0))
1907 "|dtype", &PyArray_DescrConverter, &typecode,_npy_parse_arguments("empty", &__argparse_cache, args, len_args
, kwnames, "shape", &PyArray_IntpConverter, &shape, "|dtype"
, &PyArray_DescrConverter, &typecode, "|order", &
PyArray_OrderConverter, &order, "$like", ((void*)0), &
like, ((void*)0), ((void*)0), ((void*)0))
1908 "|order", &PyArray_OrderConverter, &order,_npy_parse_arguments("empty", &__argparse_cache, args, len_args
, kwnames, "shape", &PyArray_IntpConverter, &shape, "|dtype"
, &PyArray_DescrConverter, &typecode, "|order", &
PyArray_OrderConverter, &order, "$like", ((void*)0), &
like, ((void*)0), ((void*)0), ((void*)0))
1909 "$like", NULL, &like,_npy_parse_arguments("empty", &__argparse_cache, args, len_args
, kwnames, "shape", &PyArray_IntpConverter, &shape, "|dtype"
, &PyArray_DescrConverter, &typecode, "|order", &
PyArray_OrderConverter, &order, "$like", ((void*)0), &
like, ((void*)0), ((void*)0), ((void*)0))
1910 NULL, NULL, NULL)_npy_parse_arguments("empty", &__argparse_cache, args, len_args
, kwnames, "shape", &PyArray_IntpConverter, &shape, "|dtype"
, &PyArray_DescrConverter, &typecode, "|order", &
PyArray_OrderConverter, &order, "$like", ((void*)0), &
like, ((void*)0), ((void*)0), ((void*)0))
< 0) {
1911 goto fail;
1912 }
1913
1914 if (like != NULL((void*)0)) {
1915 PyObject *deferred = array_implement_c_array_function_creation(
1916 "empty", like, NULL((void*)0), NULL((void*)0), args, len_args, kwnames);
1917 if (deferred != Py_NotImplemented(&_Py_NotImplementedStruct)) {
1918 Py_XDECREF(typecode)_Py_XDECREF(((PyObject*)(typecode)));
1919 npy_free_cache_dim_obj(shape);
1920 return deferred;
1921 }
1922 }
1923
1924 switch (order) {
1925 case NPY_CORDER:
1926 is_f_order = NPY_FALSE0;
1927 break;
1928 case NPY_FORTRANORDER:
1929 is_f_order = NPY_TRUE1;
1930 break;
1931 default:
1932 PyErr_SetString(PyExc_ValueError,
1933 "only 'C' or 'F' order is permitted");
1934 goto fail;
1935 }
1936
1937 ret = (PyArrayObject *)PyArray_Empty(shape.len, shape.ptr,
1938 typecode, is_f_order);
1939
1940 npy_free_cache_dim_obj(shape);
1941 return (PyObject *)ret;
1942
1943fail:
1944 Py_XDECREF(typecode)_Py_XDECREF(((PyObject*)(typecode)));
1945 npy_free_cache_dim_obj(shape);
1946 return NULL((void*)0);
1947}
1948
1949static PyObject *
1950array_empty_like(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
1951{
1952
1953 static char *kwlist[] = {"prototype", "dtype", "order", "subok", "shape", NULL((void*)0)};
1954 PyArrayObject *prototype = NULL((void*)0);
1955 PyArray_Descr *dtype = NULL((void*)0);
1956 NPY_ORDER order = NPY_KEEPORDER;
1957 PyArrayObject *ret = NULL((void*)0);
1958 int subok = 1;
1959 /* -1 is a special value meaning "not specified" */
1960 PyArray_Dims shape = {NULL((void*)0), -1};
1961
1962 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "O&|O&O&iO&:empty_like", kwlist,
1963 &PyArray_Converter, &prototype,
1964 &PyArray_DescrConverter2, &dtype,
1965 &PyArray_OrderConverter, &order,
1966 &subok,
1967 &PyArray_OptionalIntpConverter, &shape)) {
1968 goto fail;
1969 }
1970 /* steals the reference to dtype if it's not NULL */
1971 ret = (PyArrayObject *)PyArray_NewLikeArrayWithShape(prototype, order, dtype,
1972 shape.len, shape.ptr, subok);
1973 npy_free_cache_dim_obj(shape);
1974 if (!ret) {
1975 goto fail;
1976 }
1977 Py_DECREF(prototype)_Py_DECREF(((PyObject*)(prototype)));
1978
1979 return (PyObject *)ret;
1980
1981fail:
1982 Py_XDECREF(prototype)_Py_XDECREF(((PyObject*)(prototype)));
1983 Py_XDECREF(dtype)_Py_XDECREF(((PyObject*)(dtype)));
1984 return NULL((void*)0);
1985}
1986
1987/*
1988 * This function is needed for supporting Pickles of
1989 * numpy scalar objects.
1990 */
1991static PyObject *
1992array_scalar(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
1993{
1994
1995 static char *kwlist[] = {"dtype", "obj", NULL((void*)0)};
1996 PyArray_Descr *typecode;
1997 PyObject *obj = NULL((void*)0), *tmpobj = NULL((void*)0);
1998 int alloc = 0;
1999 void *dptr;
2000 PyObject *ret;
2001 PyObject *base = NULL((void*)0);
2002
2003 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "O!|O:scalar", kwlist,
2004 &PyArrayDescr_Type(*(PyTypeObject *)(&PyArrayDescr_TypeFull)), &typecode, &obj)) {
2005 return NULL((void*)0);
2006 }
2007 if (PyDataType_FLAGCHK(typecode, NPY_LIST_PICKLE)(((typecode)->flags & (0x02)) == (0x02))) {
2008 if (typecode->type_num == NPY_OBJECT) {
2009 /* Deprecated 2020-11-24, NumPy 1.20 */
2010 if (DEPRECATE(PyErr_WarnEx(PyExc_DeprecationWarning,"Unpickling a scalar with object dtype is deprecated. "
"Object scalars should never be created. If this was a " "properly created pickle, please open a NumPy issue. In "
"a best effort this returns the original object.",1)
2011 "Unpickling a scalar with object dtype is deprecated. "PyErr_WarnEx(PyExc_DeprecationWarning,"Unpickling a scalar with object dtype is deprecated. "
"Object scalars should never be created. If this was a " "properly created pickle, please open a NumPy issue. In "
"a best effort this returns the original object.",1)
2012 "Object scalars should never be created. If this was a "PyErr_WarnEx(PyExc_DeprecationWarning,"Unpickling a scalar with object dtype is deprecated. "
"Object scalars should never be created. If this was a " "properly created pickle, please open a NumPy issue. In "
"a best effort this returns the original object.",1)
2013 "properly created pickle, please open a NumPy issue. In "PyErr_WarnEx(PyExc_DeprecationWarning,"Unpickling a scalar with object dtype is deprecated. "
"Object scalars should never be created. If this was a " "properly created pickle, please open a NumPy issue. In "
"a best effort this returns the original object.",1)
2014 "a best effort this returns the original object.")PyErr_WarnEx(PyExc_DeprecationWarning,"Unpickling a scalar with object dtype is deprecated. "
"Object scalars should never be created. If this was a " "properly created pickle, please open a NumPy issue. In "
"a best effort this returns the original object.",1)
< 0) {
2015 return NULL((void*)0);
2016 }
2017 Py_INCREF(obj)_Py_INCREF(((PyObject*)(obj)));
2018 return obj;
2019 }
2020 /* We store the full array to unpack it here: */
2021 if (!PyArray_CheckExact(obj)(((PyObject*)(obj))->ob_type == &PyArray_Type)) {
2022 /* We pickle structured voids as arrays currently */
2023 PyErr_SetString(PyExc_RuntimeError,
2024 "Unpickling NPY_LIST_PICKLE (structured void) scalar "
2025 "requires an array. The pickle file may be corrupted?");
2026 return NULL((void*)0);
2027 }
2028 if (!PyArray_EquivTypes(PyArray_DESCR((PyArrayObject *)obj), typecode)) {
2029 PyErr_SetString(PyExc_RuntimeError,
2030 "Pickled array is not compatible with requested scalar "
2031 "dtype. The pickle file may be corrupted?");
2032 return NULL((void*)0);
2033 }
2034 base = obj;
2035 dptr = PyArray_BYTES((PyArrayObject *)obj);
2036 }
2037
2038 else if (PyDataType_FLAGCHK(typecode, NPY_ITEM_IS_POINTER)(((typecode)->flags & (0x04)) == (0x04))) {
2039 if (obj == NULL((void*)0)) {
2040 obj = Py_None(&_Py_NoneStruct);
2041 }
2042 dptr = &obj;
2043 }
2044 else {
2045 if (obj == NULL((void*)0)) {
2046 if (typecode->elsize == 0) {
2047 typecode->elsize = 1;
2048 }
2049 dptr = PyArray_mallocPyMem_RawMalloc(typecode->elsize);
2050 if (dptr == NULL((void*)0)) {
2051 return PyErr_NoMemory();
2052 }
2053 memset(dptr, '\0', typecode->elsize);
2054 alloc = 1;
2055 }
2056 else {
2057 /* Backward compatibility with Python 2 NumPy pickles */
2058 if (PyUnicode_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL
<< 28))) != 0)
) {
2059 tmpobj = PyUnicode_AsLatin1String(obj);
2060 obj = tmpobj;
2061 if (tmpobj == NULL((void*)0)) {
2062 /* More informative error message */
2063 PyErr_SetString(PyExc_ValueError,
2064 "Failed to encode Numpy scalar data string to "
2065 "latin1,\npickle.load(a, encoding='latin1') is "
2066 "assumed if unpickling.");
2067 return NULL((void*)0);
2068 }
2069 }
2070 if (!PyBytes_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL
<< 27))) != 0)
) {
2071 PyErr_SetString(PyExc_TypeError,
2072 "initializing object must be a bytes object");
2073 Py_XDECREF(tmpobj)_Py_XDECREF(((PyObject*)(tmpobj)));
2074 return NULL((void*)0);
2075 }
2076 if (PyBytes_GET_SIZE(obj)(((void) (0)),(((PyVarObject*)(obj))->ob_size)) < typecode->elsize) {
2077 PyErr_SetString(PyExc_ValueError,
2078 "initialization string is too small");
2079 Py_XDECREF(tmpobj)_Py_XDECREF(((PyObject*)(tmpobj)));
2080 return NULL((void*)0);
2081 }
2082 dptr = PyBytes_AS_STRING(obj)(((void) (0)), (((PyBytesObject *)(obj))->ob_sval));
2083 }
2084 }
2085 ret = PyArray_Scalar(dptr, typecode, base);
2086
2087 /* free dptr which contains zeros */
2088 if (alloc) {
2089 PyArray_freePyMem_RawFree(dptr);
2090 }
2091 Py_XDECREF(tmpobj)_Py_XDECREF(((PyObject*)(tmpobj)));
2092 return ret;
2093}
2094
2095static PyObject *
2096array_zeros(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)),
2097 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
2098{
2099 PyArray_Descr *typecode = NULL((void*)0);
2100 PyArray_Dims shape = {NULL((void*)0), 0};
2101 NPY_ORDER order = NPY_CORDER;
2102 npy_bool is_f_order = NPY_FALSE0;
2103 PyArrayObject *ret = NULL((void*)0);
2104 PyObject *like = NULL((void*)0);
2105 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
2106
2107 if (npy_parse_arguments("zeros", args, len_args, kwnames,_npy_parse_arguments("zeros", &__argparse_cache, args, len_args
, kwnames, "shape", &PyArray_IntpConverter, &shape, "|dtype"
, &PyArray_DescrConverter, &typecode, "|order", &
PyArray_OrderConverter, &order, "$like", ((void*)0), &
like, ((void*)0), ((void*)0), ((void*)0))
2108 "shape", &PyArray_IntpConverter, &shape,_npy_parse_arguments("zeros", &__argparse_cache, args, len_args
, kwnames, "shape", &PyArray_IntpConverter, &shape, "|dtype"
, &PyArray_DescrConverter, &typecode, "|order", &
PyArray_OrderConverter, &order, "$like", ((void*)0), &
like, ((void*)0), ((void*)0), ((void*)0))
2109 "|dtype", &PyArray_DescrConverter, &typecode,_npy_parse_arguments("zeros", &__argparse_cache, args, len_args
, kwnames, "shape", &PyArray_IntpConverter, &shape, "|dtype"
, &PyArray_DescrConverter, &typecode, "|order", &
PyArray_OrderConverter, &order, "$like", ((void*)0), &
like, ((void*)0), ((void*)0), ((void*)0))
2110 "|order", &PyArray_OrderConverter, &order,_npy_parse_arguments("zeros", &__argparse_cache, args, len_args
, kwnames, "shape", &PyArray_IntpConverter, &shape, "|dtype"
, &PyArray_DescrConverter, &typecode, "|order", &
PyArray_OrderConverter, &order, "$like", ((void*)0), &
like, ((void*)0), ((void*)0), ((void*)0))
2111 "$like", NULL, &like,_npy_parse_arguments("zeros", &__argparse_cache, args, len_args
, kwnames, "shape", &PyArray_IntpConverter, &shape, "|dtype"
, &PyArray_DescrConverter, &typecode, "|order", &
PyArray_OrderConverter, &order, "$like", ((void*)0), &
like, ((void*)0), ((void*)0), ((void*)0))
2112 NULL, NULL, NULL)_npy_parse_arguments("zeros", &__argparse_cache, args, len_args
, kwnames, "shape", &PyArray_IntpConverter, &shape, "|dtype"
, &PyArray_DescrConverter, &typecode, "|order", &
PyArray_OrderConverter, &order, "$like", ((void*)0), &
like, ((void*)0), ((void*)0), ((void*)0))
< 0) {
2113 goto fail;
2114 }
2115
2116
2117 if (like != NULL((void*)0)) {
2118 PyObject *deferred = array_implement_c_array_function_creation(
2119 "zeros", like, NULL((void*)0), NULL((void*)0), args, len_args, kwnames);
2120 if (deferred != Py_NotImplemented(&_Py_NotImplementedStruct)) {
2121 Py_XDECREF(typecode)_Py_XDECREF(((PyObject*)(typecode)));
2122 npy_free_cache_dim_obj(shape);
2123 return deferred;
2124 }
2125 }
2126
2127 switch (order) {
2128 case NPY_CORDER:
2129 is_f_order = NPY_FALSE0;
2130 break;
2131 case NPY_FORTRANORDER:
2132 is_f_order = NPY_TRUE1;
2133 break;
2134 default:
2135 PyErr_SetString(PyExc_ValueError,
2136 "only 'C' or 'F' order is permitted");
2137 goto fail;
2138 }
2139
2140 ret = (PyArrayObject *)PyArray_Zeros(shape.len, shape.ptr,
2141 typecode, (int) is_f_order);
2142
2143 npy_free_cache_dim_obj(shape);
2144 return (PyObject *)ret;
2145
2146fail:
2147 Py_XDECREF(typecode)_Py_XDECREF(((PyObject*)(typecode)));
2148 npy_free_cache_dim_obj(shape);
2149 return (PyObject *)ret;
2150}
2151
2152static PyObject *
2153array_count_nonzero(PyObject *NPY_UNUSED(self)(__NPY_UNUSED_TAGGEDself) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
2154{
2155 PyArrayObject *array;
2156 npy_intp count;
2157
2158 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O&:count_nonzero", PyArray_Converter, &array)) {
2159 return NULL((void*)0);
2160 }
2161
2162 count = PyArray_CountNonzero(array);
2163
2164 Py_DECREF(array)_Py_DECREF(((PyObject*)(array)));
2165
2166 if (count == -1) {
2167 return NULL((void*)0);
2168 }
2169 return PyLong_FromSsize_t(count);
2170}
2171
2172static PyObject *
2173array_fromstring(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)), PyObject *args, PyObject *keywds)
2174{
2175 char *data;
2176 Py_ssize_t nin = -1;
2177 char *sep = NULL((void*)0);
2178 Py_ssize_t s;
2179 static char *kwlist[] = {"string", "dtype", "count", "sep", "like", NULL((void*)0)};
2180 PyObject *like = NULL((void*)0);
2181 PyArray_Descr *descr = NULL((void*)0);
2182
2183 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, keywds,
2184 "s#|O&" NPY_SSIZE_T_PYFMT"n" "s$O:fromstring", kwlist,
2185 &data, &s, PyArray_DescrConverter, &descr, &nin, &sep, &like)) {
2186 Py_XDECREF(descr)_Py_XDECREF(((PyObject*)(descr)));
2187 return NULL((void*)0);
2188 }
2189 if (like != NULL((void*)0)) {
2190 PyObject *deferred = array_implement_c_array_function_creation(
2191 "fromstring", like, args, keywds, NULL((void*)0), 0, NULL((void*)0));
2192 if (deferred != Py_NotImplemented(&_Py_NotImplementedStruct)) {
2193 Py_XDECREF(descr)_Py_XDECREF(((PyObject*)(descr)));
2194 return deferred;
2195 }
2196 }
2197
2198 /* binary mode, condition copied from PyArray_FromString */
2199 if (sep == NULL((void*)0) || strlen(sep) == 0) {
2200 /* Numpy 1.14, 2017-10-19 */
2201 if (DEPRECATE(PyErr_WarnEx(PyExc_DeprecationWarning,"The binary mode of fromstring is deprecated, as it behaves "
"surprisingly on unicode inputs. Use frombuffer instead",1)
2202 "The binary mode of fromstring is deprecated, as it behaves "PyErr_WarnEx(PyExc_DeprecationWarning,"The binary mode of fromstring is deprecated, as it behaves "
"surprisingly on unicode inputs. Use frombuffer instead",1)
2203 "surprisingly on unicode inputs. Use frombuffer instead")PyErr_WarnEx(PyExc_DeprecationWarning,"The binary mode of fromstring is deprecated, as it behaves "
"surprisingly on unicode inputs. Use frombuffer instead",1)
< 0) {
2204 Py_XDECREF(descr)_Py_XDECREF(((PyObject*)(descr)));
2205 return NULL((void*)0);
2206 }
2207 }
2208 return PyArray_FromString(data, (npy_intp)s, descr, (npy_intp)nin, sep);
2209}
2210
2211
2212
2213static PyObject *
2214array_fromfile(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)), PyObject *args, PyObject *keywds)
2215{
2216 PyObject *file = NULL((void*)0), *ret = NULL((void*)0);
2217 PyObject *err_type = NULL((void*)0), *err_value = NULL((void*)0), *err_traceback = NULL((void*)0);
2218 char *sep = "";
2219 Py_ssize_t nin = -1;
2220 static char *kwlist[] = {"file", "dtype", "count", "sep", "offset", "like", NULL((void*)0)};
2221 PyObject *like = NULL((void*)0);
2222 PyArray_Descr *type = NULL((void*)0);
2223 int own;
2224 npy_off_toff_t orig_pos = 0, offset = 0;
2225 FILE *fp;
2226
2227 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, keywds,
2228 "O|O&" NPY_SSIZE_T_PYFMT"n" "s" NPY_OFF_T_PYFMT"l" "$O:fromfile", kwlist,
2229 &file, PyArray_DescrConverter, &type, &nin, &sep, &offset, &like)) {
2230 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
2231 return NULL((void*)0);
2232 }
2233
2234 if (like != NULL((void*)0)) {
2235 PyObject *deferred = array_implement_c_array_function_creation(
2236 "fromfile", like, args, keywds, NULL((void*)0), 0, NULL((void*)0));
2237 if (deferred != Py_NotImplemented(&_Py_NotImplementedStruct)) {
2238 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
2239 return deferred;
2240 }
2241 }
2242
2243 file = NpyPath_PathlikeToFspath(file);
2244 if (file == NULL((void*)0)) {
2245 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
2246 return NULL((void*)0);
2247 }
2248
2249 if (offset != 0 && strcmp(sep, "") != 0) {
2250 PyErr_SetString(PyExc_TypeError, "'offset' argument only permitted for binary files");
2251 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
2252 Py_DECREF(file)_Py_DECREF(((PyObject*)(file)));
2253 return NULL((void*)0);
2254 }
2255 if (PyBytes_Check(file)((((((PyObject*)(file))->ob_type))->tp_flags & ((1UL
<< 27))) != 0)
|| PyUnicode_Check(file)((((((PyObject*)(file))->ob_type))->tp_flags & ((1UL
<< 28))) != 0)
) {
2256 Py_SETREF(file, npy_PyFile_OpenFile(file, "rb"))do { PyObject *_py_tmp = ((PyObject*)(file)); (file) = (npy_PyFile_OpenFile
(file, "rb")); _Py_DECREF(((PyObject*)(_py_tmp))); } while (0
)
;
2257 if (file == NULL((void*)0)) {
2258 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
2259 return NULL((void*)0);
2260 }
2261 own = 1;
2262 }
2263 else {
2264 own = 0;
2265 }
2266 fp = npy_PyFile_Dup2(file, "rb", &orig_pos);
2267 if (fp == NULL((void*)0)) {
2268 Py_DECREF(file)_Py_DECREF(((PyObject*)(file)));
2269 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
2270 return NULL((void*)0);
2271 }
2272 if (npy_fseekfseeko(fp, offset, SEEK_CUR1) != 0) {
2273 PyErr_SetFromErrno(PyExc_IOError);
2274 goto cleanup;
2275 }
2276 if (type == NULL((void*)0)) {
2277 type = PyArray_DescrFromType(NPY_DEFAULT_TYPENPY_DOUBLE);
2278 }
2279 ret = PyArray_FromFile(fp, type, (npy_intp) nin, sep);
2280
2281 /* If an exception is thrown in the call to PyArray_FromFile
2282 * we need to clear it, and restore it later to ensure that
2283 * we can cleanup the duplicated file descriptor properly.
2284 */
2285cleanup:
2286 PyErr_Fetch(&err_type, &err_value, &err_traceback);
2287 if (npy_PyFile_DupClose2(file, fp, orig_pos) < 0) {
2288 npy_PyErr_ChainExceptions(err_type, err_value, err_traceback);
2289 goto fail;
2290 }
2291 if (own && npy_PyFile_CloseFile(file) < 0) {
2292 npy_PyErr_ChainExceptions(err_type, err_value, err_traceback);
2293 goto fail;
2294 }
2295 PyErr_Restore(err_type, err_value, err_traceback);
2296 Py_DECREF(file)_Py_DECREF(((PyObject*)(file)));
2297 return ret;
2298
2299fail:
2300 Py_DECREF(file)_Py_DECREF(((PyObject*)(file)));
2301 Py_XDECREF(ret)_Py_XDECREF(((PyObject*)(ret)));
2302 return NULL((void*)0);
2303}
2304
2305static PyObject *
2306array_fromiter(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)), PyObject *args, PyObject *keywds)
2307{
2308 PyObject *iter;
2309 Py_ssize_t nin = -1;
2310 static char *kwlist[] = {"iter", "dtype", "count", "like", NULL((void*)0)};
2311 PyObject *like = NULL((void*)0);
2312 PyArray_Descr *descr = NULL((void*)0);
2313
2314 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, keywds,
2315 "OO&|" NPY_SSIZE_T_PYFMT"n" "$O:fromiter", kwlist,
2316 &iter, PyArray_DescrConverter, &descr, &nin, &like)) {
2317 Py_XDECREF(descr)_Py_XDECREF(((PyObject*)(descr)));
2318 return NULL((void*)0);
2319 }
2320 if (like != NULL((void*)0)) {
2321 PyObject *deferred = array_implement_c_array_function_creation(
2322 "fromiter", like, args, keywds, NULL((void*)0), 0, NULL((void*)0));
2323 if (deferred != Py_NotImplemented(&_Py_NotImplementedStruct)) {
2324 Py_XDECREF(descr)_Py_XDECREF(((PyObject*)(descr)));
2325 return deferred;
2326 }
2327 }
2328
2329 return PyArray_FromIter(iter, descr, (npy_intp)nin);
2330}
2331
2332static PyObject *
2333array_frombuffer(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)), PyObject *args, PyObject *keywds)
2334{
2335 PyObject *obj = NULL((void*)0);
2336 Py_ssize_t nin = -1, offset = 0;
2337 static char *kwlist[] = {"buffer", "dtype", "count", "offset", "like", NULL((void*)0)};
2338 PyObject *like = NULL((void*)0);
2339 PyArray_Descr *type = NULL((void*)0);
2340
2341 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, keywds,
2342 "O|O&" NPY_SSIZE_T_PYFMT"n" NPY_SSIZE_T_PYFMT"n" "$O:frombuffer", kwlist,
2343 &obj, PyArray_DescrConverter, &type, &nin, &offset, &like)) {
2344 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
2345 return NULL((void*)0);
2346 }
2347
2348 if (like != NULL((void*)0)) {
2349 PyObject *deferred = array_implement_c_array_function_creation(
2350 "frombuffer", like, args, keywds, NULL((void*)0), 0, NULL((void*)0));
2351 if (deferred != Py_NotImplemented(&_Py_NotImplementedStruct)) {
2352 Py_XDECREF(type)_Py_XDECREF(((PyObject*)(type)));
2353 return deferred;
2354 }
2355 }
2356
2357 if (type == NULL((void*)0)) {
2358 type = PyArray_DescrFromType(NPY_DEFAULT_TYPENPY_DOUBLE);
2359 }
2360 return PyArray_FromBuffer(obj, type, (npy_intp)nin, (npy_intp)offset);
2361}
2362
2363static PyObject *
2364array_concatenate(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
2365{
2366 PyObject *a0;
2367 PyObject *out = NULL((void*)0);
2368 PyArray_Descr *dtype = NULL((void*)0);
2369 NPY_CASTING casting = NPY_SAME_KIND_CASTING;
2370 PyObject *casting_obj = NULL((void*)0);
2371 PyObject *res;
2372 int axis = 0;
2373 static char *kwlist[] = {"seq", "axis", "out", "dtype", "casting", NULL((void*)0)};
2374 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "O|O&O$O&O:concatenate", kwlist,
2375 &a0, PyArray_AxisConverter, &axis, &out,
2376 PyArray_DescrConverter2, &dtype, &casting_obj)) {
2377 return NULL((void*)0);
2378 }
2379 int casting_not_passed = 0;
2380 if (casting_obj == NULL((void*)0)) {
2381 /*
2382 * Casting was not passed in, needed for deprecation only.
2383 * This should be simplified once the deprecation is finished.
2384 */
2385 casting_not_passed = 1;
2386 }
2387 else if (!PyArray_CastingConverter(casting_obj, &casting)) {
2388 Py_XDECREF(dtype)_Py_XDECREF(((PyObject*)(dtype)));
2389 return NULL((void*)0);
2390 }
2391 if (out != NULL((void*)0)) {
2392 if (out == Py_None(&_Py_NoneStruct)) {
2393 out = NULL((void*)0);
2394 }
2395 else if (!PyArray_Check(out)((((PyObject*)(out))->ob_type) == (&PyArray_Type) || PyType_IsSubtype
((((PyObject*)(out))->ob_type), (&PyArray_Type)))
) {
2396 PyErr_SetString(PyExc_TypeError, "'out' must be an array");
2397 Py_XDECREF(dtype)_Py_XDECREF(((PyObject*)(dtype)));
2398 return NULL((void*)0);
2399 }
2400 }
2401 res = PyArray_ConcatenateInto(a0, axis, (PyArrayObject *)out, dtype,
2402 casting, casting_not_passed);
2403 Py_XDECREF(dtype)_Py_XDECREF(((PyObject*)(dtype)));
2404 return res;
2405}
2406
2407static PyObject *
2408array_innerproduct(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args)
2409{
2410 PyObject *b0, *a0;
2411
2412 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "OO:innerproduct", &a0, &b0)) {
2413 return NULL((void*)0);
2414 }
2415 return PyArray_Return((PyArrayObject *)PyArray_InnerProduct(a0, b0));
2416}
2417
2418static PyObject *
2419array_matrixproduct(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args, PyObject* kwds)
2420{
2421 PyObject *v, *a, *o = NULL((void*)0);
2422 PyArrayObject *ret;
2423 static char* kwlist[] = {"a", "b", "out", NULL((void*)0)};
2424
2425 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "OO|O:matrixproduct",
2426 kwlist, &a, &v, &o)) {
2427 return NULL((void*)0);
2428 }
2429 if (o != NULL((void*)0)) {
2430 if (o == Py_None(&_Py_NoneStruct)) {
2431 o = NULL((void*)0);
2432 }
2433 else if (!PyArray_Check(o)((((PyObject*)(o))->ob_type) == (&PyArray_Type) || PyType_IsSubtype
((((PyObject*)(o))->ob_type), (&PyArray_Type)))
) {
2434 PyErr_SetString(PyExc_TypeError, "'out' must be an array");
2435 return NULL((void*)0);
2436 }
2437 }
2438 ret = (PyArrayObject *)PyArray_MatrixProduct2(a, v, (PyArrayObject *)o);
2439 return PyArray_Return(ret);
2440}
2441
2442
2443static PyObject *
2444array_vdot(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args)
2445{
2446 int typenum;
2447 char *ip1, *ip2, *op;
2448 npy_intp n, stride1, stride2;
2449 PyObject *op1, *op2;
2450 npy_intp newdimptr[1] = {-1};
2451 PyArray_Dims newdims = {newdimptr, 1};
2452 PyArrayObject *ap1 = NULL((void*)0), *ap2 = NULL((void*)0), *ret = NULL((void*)0);
2453 PyArray_Descr *type;
2454 PyArray_DotFunc *vdot;
2455 NPY_BEGIN_THREADS_DEFPyThreadState *_save=((void*)0);;
2456
2457 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "OO:vdot", &op1, &op2)) {
2458 return NULL((void*)0);
2459 }
2460
2461 /*
2462 * Conjugating dot product using the BLAS for vectors.
2463 * Flattens both op1 and op2 before dotting.
2464 */
2465 typenum = PyArray_ObjectType(op1, 0);
2466 typenum = PyArray_ObjectType(op2, typenum);
2467
2468 type = PyArray_DescrFromType(typenum);
2469 Py_INCREF(type)_Py_INCREF(((PyObject*)(type)));
2470 ap1 = (PyArrayObject *)PyArray_FromAny(op1, type, 0, 0, 0, NULL((void*)0));
2471 if (ap1 == NULL((void*)0)) {
2472 Py_DECREF(type)_Py_DECREF(((PyObject*)(type)));
2473 goto fail;
2474 }
2475
2476 op1 = PyArray_Newshape(ap1, &newdims, NPY_CORDER);
2477 if (op1 == NULL((void*)0)) {
2478 Py_DECREF(type)_Py_DECREF(((PyObject*)(type)));
2479 goto fail;
2480 }
2481 Py_DECREF(ap1)_Py_DECREF(((PyObject*)(ap1)));
2482 ap1 = (PyArrayObject *)op1;
2483
2484 ap2 = (PyArrayObject *)PyArray_FromAny(op2, type, 0, 0, 0, NULL((void*)0));
2485 if (ap2 == NULL((void*)0)) {
2486 goto fail;
2487 }
2488 op2 = PyArray_Newshape(ap2, &newdims, NPY_CORDER);
2489 if (op2 == NULL((void*)0)) {
2490 goto fail;
2491 }
2492 Py_DECREF(ap2)_Py_DECREF(((PyObject*)(ap2)));
2493 ap2 = (PyArrayObject *)op2;
2494
2495 if (PyArray_DIM(ap2, 0) != PyArray_DIM(ap1, 0)) {
2496 PyErr_SetString(PyExc_ValueError,
2497 "vectors have different lengths");
2498 goto fail;
2499 }
2500
2501 /* array scalar output */
2502 ret = new_array_for_sum(ap1, ap2, NULL((void*)0), 0, (npy_intp *)NULL((void*)0), typenum, NULL((void*)0));
2503 if (ret == NULL((void*)0)) {
2504 goto fail;
2505 }
2506
2507 n = PyArray_DIM(ap1, 0);
2508 stride1 = PyArray_STRIDE(ap1, 0);
2509 stride2 = PyArray_STRIDE(ap2, 0);
2510 ip1 = PyArray_DATA(ap1);
2511 ip2 = PyArray_DATA(ap2);
2512 op = PyArray_DATA(ret);
2513
2514 switch (typenum) {
2515 case NPY_CFLOAT:
2516 vdot = (PyArray_DotFunc *)CFLOAT_vdot;
2517 break;
2518 case NPY_CDOUBLE:
2519 vdot = (PyArray_DotFunc *)CDOUBLE_vdot;
2520 break;
2521 case NPY_CLONGDOUBLE:
2522 vdot = (PyArray_DotFunc *)CLONGDOUBLE_vdot;
2523 break;
2524 case NPY_OBJECT:
2525 vdot = (PyArray_DotFunc *)OBJECT_vdot;
2526 break;
2527 default:
2528 vdot = type->f->dotfunc;
2529 if (vdot == NULL((void*)0)) {
2530 PyErr_SetString(PyExc_ValueError,
2531 "function not available for this data type");
2532 goto fail;
2533 }
2534 }
2535
2536 if (n < 500) {
2537 vdot(ip1, stride1, ip2, stride2, op, n, NULL((void*)0));
2538 }
2539 else {
2540 NPY_BEGIN_THREADS_DESCR(type)do {if (!(((((type))->flags & (0x10)) == (0x10)))) do {
_save = PyEval_SaveThread();} while (0);;} while (0);
;
2541 vdot(ip1, stride1, ip2, stride2, op, n, NULL((void*)0));
2542 NPY_END_THREADS_DESCR(type)do {if (!(((((type))->flags & (0x10)) == (0x10)))) do {
if (_save) { PyEval_RestoreThread(_save); _save = ((void*)0)
;} } while (0);; } while (0);
;
2543 }
2544
2545 Py_XDECREF(ap1)_Py_XDECREF(((PyObject*)(ap1)));
2546 Py_XDECREF(ap2)_Py_XDECREF(((PyObject*)(ap2)));
2547 return PyArray_Return(ret);
2548fail:
2549 Py_XDECREF(ap1)_Py_XDECREF(((PyObject*)(ap1)));
2550 Py_XDECREF(ap2)_Py_XDECREF(((PyObject*)(ap2)));
2551 Py_XDECREF(ret)_Py_XDECREF(((PyObject*)(ret)));
2552 return NULL((void*)0);
2553}
2554
2555static int
2556einsum_sub_op_from_str(PyObject *args, PyObject **str_obj, char **subscripts,
2557 PyArrayObject **op)
2558{
2559 int i, nop;
2560 PyObject *subscripts_str;
2561
2562 nop = PyTuple_GET_SIZE(args)(((PyVarObject*)((((void) (0)), (PyTupleObject *)(args))))->
ob_size)
- 1;
2563 if (nop <= 0) {
2564 PyErr_SetString(PyExc_ValueError,
2565 "must specify the einstein sum subscripts string "
2566 "and at least one operand");
2567 return -1;
2568 }
2569 else if (nop >= NPY_MAXARGS32) {
2570 PyErr_SetString(PyExc_ValueError, "too many operands");
2571 return -1;
2572 }
2573
2574 /* Get the subscripts string */
2575 subscripts_str = PyTuple_GET_ITEM(args, 0)((((void) (0)), (PyTupleObject *)(args))->ob_item[0]);
2576 if (PyUnicode_Check(subscripts_str)((((((PyObject*)(subscripts_str))->ob_type))->tp_flags &
((1UL << 28))) != 0)
) {
2577 *str_obj = PyUnicode_AsASCIIString(subscripts_str);
2578 if (*str_obj == NULL((void*)0)) {
2579 return -1;
2580 }
2581 subscripts_str = *str_obj;
2582 }
2583
2584 *subscripts = PyBytes_AsString(subscripts_str);
2585 if (*subscripts == NULL((void*)0)) {
2586 Py_XDECREF(*str_obj)_Py_XDECREF(((PyObject*)(*str_obj)));
2587 *str_obj = NULL((void*)0);
2588 return -1;
2589 }
2590
2591 /* Set the operands to NULL */
2592 for (i = 0; i < nop; ++i) {
2593 op[i] = NULL((void*)0);
2594 }
2595
2596 /* Get the operands */
2597 for (i = 0; i < nop; ++i) {
2598 PyObject *obj = PyTuple_GET_ITEM(args, i+1)((((void) (0)), (PyTupleObject *)(args))->ob_item[i+1]);
2599
2600 op[i] = (PyArrayObject *)PyArray_FROM_OF(obj, NPY_ARRAY_ENSUREARRAY)PyArray_CheckFromAny(obj, ((void*)0), 0, 0, 0x0040, ((void*)0
))
;
2601 if (op[i] == NULL((void*)0)) {
2602 goto fail;
2603 }
2604 }
2605
2606 return nop;
2607
2608fail:
2609 for (i = 0; i < nop; ++i) {
2610 Py_XDECREF(op[i])_Py_XDECREF(((PyObject*)(op[i])));
2611 op[i] = NULL((void*)0);
2612 }
2613
2614 return -1;
2615}
2616
2617/*
2618 * Converts a list of subscripts to a string.
2619 *
2620 * Returns -1 on error, the number of characters placed in subscripts
2621 * otherwise.
2622 */
2623static int
2624einsum_list_to_subscripts(PyObject *obj, char *subscripts, int subsize)
2625{
2626 int ellipsis = 0, subindex = 0;
2627 npy_intp i, size;
2628 PyObject *item;
2629
2630 obj = PySequence_Fast(obj, "the subscripts for each operand must "
2631 "be a list or a tuple");
2632 if (obj == NULL((void*)0)) {
2633 return -1;
2634 }
2635 size = PySequence_Size(obj);
2636
2637 for (i = 0; i < size; ++i) {
2638 item = PySequence_Fast_GET_ITEM(obj, i)(((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL
<< 25))) != 0) ? (((PyListObject *)(obj))->ob_item[
i]) : ((((void) (0)), (PyTupleObject *)(obj))->ob_item[i])
)
;
2639 /* Ellipsis */
2640 if (item == Py_Ellipsis(&_Py_EllipsisObject)) {
2641 if (ellipsis) {
2642 PyErr_SetString(PyExc_ValueError,
2643 "each subscripts list may have only one ellipsis");
2644 Py_DECREF(obj)_Py_DECREF(((PyObject*)(obj)));
2645 return -1;
2646 }
2647 if (subindex + 3 >= subsize) {
2648 PyErr_SetString(PyExc_ValueError,
2649 "subscripts list is too long");
2650 Py_DECREF(obj)_Py_DECREF(((PyObject*)(obj)));
2651 return -1;
2652 }
2653 subscripts[subindex++] = '.';
2654 subscripts[subindex++] = '.';
2655 subscripts[subindex++] = '.';
2656 ellipsis = 1;
2657 }
2658 /* Subscript */
2659 else {
2660 npy_intp s = PyArray_PyIntAsIntp(item);
2661 /* Invalid */
2662 if (error_converting(s)(((s) == -1) && PyErr_Occurred())) {
2663 PyErr_SetString(PyExc_TypeError,
2664 "each subscript must be either an integer "
2665 "or an ellipsis");
2666 Py_DECREF(obj)_Py_DECREF(((PyObject*)(obj)));
2667 return -1;
2668 }
2669 npy_bool bad_input = 0;
2670
2671 if (subindex + 1 >= subsize) {
2672 PyErr_SetString(PyExc_ValueError,
2673 "subscripts list is too long");
2674 Py_DECREF(obj)_Py_DECREF(((PyObject*)(obj)));
2675 return -1;
2676 }
2677
2678 if (s < 0) {
2679 bad_input = 1;
2680 }
2681 else if (s < 26) {
2682 subscripts[subindex++] = 'A' + (char)s;
2683 }
2684 else if (s < 2*26) {
2685 subscripts[subindex++] = 'a' + (char)s - 26;
2686 }
2687 else {
2688 bad_input = 1;
2689 }
2690
2691 if (bad_input) {
2692 PyErr_SetString(PyExc_ValueError,
2693 "subscript is not within the valid range [0, 52)");
2694 Py_DECREF(obj)_Py_DECREF(((PyObject*)(obj)));
2695 return -1;
2696 }
2697 }
2698
2699 }
2700
2701 Py_DECREF(obj)_Py_DECREF(((PyObject*)(obj)));
2702
2703 return subindex;
2704}
2705
2706/*
2707 * Fills in the subscripts, with maximum size subsize, and op,
2708 * with the values in the tuple 'args'.
2709 *
2710 * Returns -1 on error, number of operands placed in op otherwise.
2711 */
2712static int
2713einsum_sub_op_from_lists(PyObject *args,
2714 char *subscripts, int subsize, PyArrayObject **op)
2715{
2716 int subindex = 0;
2717 npy_intp i, nop;
2718
2719 nop = PyTuple_Size(args)/2;
2720
2721 if (nop == 0) {
2722 PyErr_SetString(PyExc_ValueError, "must provide at least an "
2723 "operand and a subscripts list to einsum");
2724 return -1;
2725 }
2726 else if (nop >= NPY_MAXARGS32) {
2727 PyErr_SetString(PyExc_ValueError, "too many operands");
2728 return -1;
2729 }
2730
2731 /* Set the operands to NULL */
2732 for (i = 0; i < nop; ++i) {
2733 op[i] = NULL((void*)0);
2734 }
2735
2736 /* Get the operands and build the subscript string */
2737 for (i = 0; i < nop; ++i) {
2738 PyObject *obj = PyTuple_GET_ITEM(args, 2*i)((((void) (0)), (PyTupleObject *)(args))->ob_item[2*i]);
2739 int n;
2740
2741 /* Comma between the subscripts for each operand */
2742 if (i != 0) {
2743 subscripts[subindex++] = ',';
2744 if (subindex >= subsize) {
2745 PyErr_SetString(PyExc_ValueError,
2746 "subscripts list is too long");
2747 goto fail;
2748 }
2749 }
2750
2751 op[i] = (PyArrayObject *)PyArray_FROM_OF(obj, NPY_ARRAY_ENSUREARRAY)PyArray_CheckFromAny(obj, ((void*)0), 0, 0, 0x0040, ((void*)0
))
;
2752 if (op[i] == NULL((void*)0)) {
2753 goto fail;
2754 }
2755
2756 obj = PyTuple_GET_ITEM(args, 2*i+1)((((void) (0)), (PyTupleObject *)(args))->ob_item[2*i+1]);
2757 n = einsum_list_to_subscripts(obj, subscripts+subindex,
2758 subsize-subindex);
2759 if (n < 0) {
2760 goto fail;
2761 }
2762 subindex += n;
2763 }
2764
2765 /* Add the '->' to the string if provided */
2766 if (PyTuple_Size(args) == 2*nop+1) {
2767 PyObject *obj;
2768 int n;
2769
2770 if (subindex + 2 >= subsize) {
2771 PyErr_SetString(PyExc_ValueError,
2772 "subscripts list is too long");
2773 goto fail;
2774 }
2775 subscripts[subindex++] = '-';
2776 subscripts[subindex++] = '>';
2777
2778 obj = PyTuple_GET_ITEM(args, 2*nop)((((void) (0)), (PyTupleObject *)(args))->ob_item[2*nop]);
2779 n = einsum_list_to_subscripts(obj, subscripts+subindex,
2780 subsize-subindex);
2781 if (n < 0) {
2782 goto fail;
2783 }
2784 subindex += n;
2785 }
2786
2787 /* NULL-terminate the subscripts string */
2788 subscripts[subindex] = '\0';
2789
2790 return nop;
2791
2792fail:
2793 for (i = 0; i < nop; ++i) {
2794 Py_XDECREF(op[i])_Py_XDECREF(((PyObject*)(op[i])));
2795 op[i] = NULL((void*)0);
2796 }
2797
2798 return -1;
2799}
2800
2801static PyObject *
2802array_einsum(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
2803{
2804 char *subscripts = NULL((void*)0), subscripts_buffer[256];
2805 PyObject *str_obj = NULL((void*)0), *str_key_obj = NULL((void*)0);
2806 PyObject *arg0;
2807 int i, nop;
2808 PyArrayObject *op[NPY_MAXARGS32];
2809 NPY_ORDER order = NPY_KEEPORDER;
2810 NPY_CASTING casting = NPY_SAFE_CASTING;
2811 PyArrayObject *out = NULL((void*)0);
2812 PyArray_Descr *dtype = NULL((void*)0);
2813 PyObject *ret = NULL((void*)0);
2814
2815 if (PyTuple_GET_SIZE(args)(((PyVarObject*)((((void) (0)), (PyTupleObject *)(args))))->
ob_size)
< 1) {
2816 PyErr_SetString(PyExc_ValueError,
2817 "must specify the einstein sum subscripts string "
2818 "and at least one operand, or at least one operand "
2819 "and its corresponding subscripts list");
2820 return NULL((void*)0);
2821 }
2822 arg0 = PyTuple_GET_ITEM(args, 0)((((void) (0)), (PyTupleObject *)(args))->ob_item[0]);
2823
2824 /* einsum('i,j', a, b), einsum('i,j->ij', a, b) */
2825 if (PyBytes_Check(arg0)((((((PyObject*)(arg0))->ob_type))->tp_flags & ((1UL
<< 27))) != 0)
|| PyUnicode_Check(arg0)((((((PyObject*)(arg0))->ob_type))->tp_flags & ((1UL
<< 28))) != 0)
) {
2826 nop = einsum_sub_op_from_str(args, &str_obj, &subscripts, op);
2827 }
2828 /* einsum(a, [0], b, [1]), einsum(a, [0], b, [1], [0,1]) */
2829 else {
2830 nop = einsum_sub_op_from_lists(args, subscripts_buffer,
2831 sizeof(subscripts_buffer), op);
2832 subscripts = subscripts_buffer;
2833 }
2834 if (nop <= 0) {
2835 goto finish;
2836 }
2837
2838 /* Get the keyword arguments */
2839 if (kwds != NULL((void*)0)) {
2840 PyObject *key, *value;
2841 Py_ssize_t pos = 0;
2842 while (PyDict_Next(kwds, &pos, &key, &value)) {
2843 char *str = NULL((void*)0);
2844
2845 Py_XDECREF(str_key_obj)_Py_XDECREF(((PyObject*)(str_key_obj)));
2846 str_key_obj = PyUnicode_AsASCIIString(key);
2847 if (str_key_obj != NULL((void*)0)) {
2848 key = str_key_obj;
2849 }
2850
2851 str = PyBytes_AsString(key);
2852
2853 if (str == NULL((void*)0)) {
2854 PyErr_Clear();
2855 PyErr_SetString(PyExc_TypeError, "invalid keyword");
2856 goto finish;
2857 }
2858
2859 if (strcmp(str,"out") == 0) {
2860 if (PyArray_Check(value)((((PyObject*)(value))->ob_type) == (&PyArray_Type) ||
PyType_IsSubtype((((PyObject*)(value))->ob_type), (&PyArray_Type
)))
) {
2861 out = (PyArrayObject *)value;
2862 }
2863 else {
2864 PyErr_SetString(PyExc_TypeError,
2865 "keyword parameter out must be an "
2866 "array for einsum");
2867 goto finish;
2868 }
2869 }
2870 else if (strcmp(str,"order") == 0) {
2871 if (!PyArray_OrderConverter(value, &order)) {
2872 goto finish;
2873 }
2874 }
2875 else if (strcmp(str,"casting") == 0) {
2876 if (!PyArray_CastingConverter(value, &casting)) {
2877 goto finish;
2878 }
2879 }
2880 else if (strcmp(str,"dtype") == 0) {
2881 if (!PyArray_DescrConverter2(value, &dtype)) {
2882 goto finish;
2883 }
2884 }
2885 else {
2886 PyErr_Format(PyExc_TypeError,
2887 "'%s' is an invalid keyword for einsum",
2888 str);
2889 goto finish;
2890 }
2891 }
2892 }
2893
2894 ret = (PyObject *)PyArray_EinsteinSum(subscripts, nop, op, dtype,
2895 order, casting, out);
2896
2897 /* If no output was supplied, possibly convert to a scalar */
2898 if (ret != NULL((void*)0) && out == NULL((void*)0)) {
2899 ret = PyArray_Return((PyArrayObject *)ret);
2900 }
2901
2902finish:
2903 for (i = 0; i < nop; ++i) {
2904 Py_XDECREF(op[i])_Py_XDECREF(((PyObject*)(op[i])));
2905 }
2906 Py_XDECREF(dtype)_Py_XDECREF(((PyObject*)(dtype)));
2907 Py_XDECREF(str_obj)_Py_XDECREF(((PyObject*)(str_obj)));
2908 Py_XDECREF(str_key_obj)_Py_XDECREF(((PyObject*)(str_key_obj)));
2909 /* out is a borrowed reference */
2910
2911 return ret;
2912}
2913
2914static PyObject *
2915array_fastCopyAndTranspose(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args)
2916{
2917 PyObject *a0;
2918
2919 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O:_fastCopyAndTranspose", &a0)) {
2920 return NULL((void*)0);
2921 }
2922 return PyArray_Return((PyArrayObject *)PyArray_CopyAndTranspose(a0));
2923}
2924
2925static PyObject *
2926array_correlate(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)),
2927 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
2928{
2929 PyObject *shape, *a0;
2930 int mode = 0;
2931 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
2932
2933 if (npy_parse_arguments("correlate", args, len_args, kwnames,_npy_parse_arguments("correlate", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &a0, "v", ((void*)0
), &shape, "|mode", &PyArray_CorrelatemodeConverter, &
mode, ((void*)0), ((void*)0), ((void*)0))
2934 "a", NULL, &a0,_npy_parse_arguments("correlate", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &a0, "v", ((void*)0
), &shape, "|mode", &PyArray_CorrelatemodeConverter, &
mode, ((void*)0), ((void*)0), ((void*)0))
2935 "v", NULL, &shape,_npy_parse_arguments("correlate", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &a0, "v", ((void*)0
), &shape, "|mode", &PyArray_CorrelatemodeConverter, &
mode, ((void*)0), ((void*)0), ((void*)0))
2936 "|mode", &PyArray_CorrelatemodeConverter, &mode,_npy_parse_arguments("correlate", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &a0, "v", ((void*)0
), &shape, "|mode", &PyArray_CorrelatemodeConverter, &
mode, ((void*)0), ((void*)0), ((void*)0))
2937 NULL, NULL, NULL)_npy_parse_arguments("correlate", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &a0, "v", ((void*)0
), &shape, "|mode", &PyArray_CorrelatemodeConverter, &
mode, ((void*)0), ((void*)0), ((void*)0))
< 0) {
2938 return NULL((void*)0);
2939 }
2940 return PyArray_Correlate(a0, shape, mode);
2941}
2942
2943static PyObject*
2944array_correlate2(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)),
2945 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
2946{
2947 PyObject *shape, *a0;
2948 int mode = 0;
2949 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
2950
2951 if (npy_parse_arguments("correlate2", args, len_args, kwnames,_npy_parse_arguments("correlate2", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &a0, "v", ((void*)0
), &shape, "|mode", &PyArray_CorrelatemodeConverter, &
mode, ((void*)0), ((void*)0), ((void*)0))
2952 "a", NULL, &a0,_npy_parse_arguments("correlate2", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &a0, "v", ((void*)0
), &shape, "|mode", &PyArray_CorrelatemodeConverter, &
mode, ((void*)0), ((void*)0), ((void*)0))
2953 "v", NULL, &shape,_npy_parse_arguments("correlate2", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &a0, "v", ((void*)0
), &shape, "|mode", &PyArray_CorrelatemodeConverter, &
mode, ((void*)0), ((void*)0), ((void*)0))
2954 "|mode", &PyArray_CorrelatemodeConverter, &mode,_npy_parse_arguments("correlate2", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &a0, "v", ((void*)0
), &shape, "|mode", &PyArray_CorrelatemodeConverter, &
mode, ((void*)0), ((void*)0), ((void*)0))
2955 NULL, NULL, NULL)_npy_parse_arguments("correlate2", &__argparse_cache, args
, len_args, kwnames, "a", ((void*)0), &a0, "v", ((void*)0
), &shape, "|mode", &PyArray_CorrelatemodeConverter, &
mode, ((void*)0), ((void*)0), ((void*)0))
< 0) {
2956 return NULL((void*)0);
2957 }
2958 return PyArray_Correlate2(a0, shape, mode);
2959}
2960
2961static PyObject *
2962array_arange(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)),
2963 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
2964{
2965 PyObject *o_start = NULL((void*)0), *o_stop = NULL((void*)0), *o_step = NULL((void*)0), *range=NULL((void*)0);
2966 PyArray_Descr *typecode = NULL((void*)0);
2967 PyObject *like = NULL((void*)0);
2968 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
2969
2970 if (npy_parse_arguments("arange", args, len_args, kwnames,_npy_parse_arguments("arange", &__argparse_cache, args, len_args
, kwnames, "|start", ((void*)0), &o_start, "|stop", ((void
*)0), &o_stop, "|step", ((void*)0), &o_step, "|dtype"
, &PyArray_DescrConverter2, &typecode, "$like", ((void
*)0), &like, ((void*)0), ((void*)0), ((void*)0))
2971 "|start", NULL, &o_start,_npy_parse_arguments("arange", &__argparse_cache, args, len_args
, kwnames, "|start", ((void*)0), &o_start, "|stop", ((void
*)0), &o_stop, "|step", ((void*)0), &o_step, "|dtype"
, &PyArray_DescrConverter2, &typecode, "$like", ((void
*)0), &like, ((void*)0), ((void*)0), ((void*)0))
2972 "|stop", NULL, &o_stop,_npy_parse_arguments("arange", &__argparse_cache, args, len_args
, kwnames, "|start", ((void*)0), &o_start, "|stop", ((void
*)0), &o_stop, "|step", ((void*)0), &o_step, "|dtype"
, &PyArray_DescrConverter2, &typecode, "$like", ((void
*)0), &like, ((void*)0), ((void*)0), ((void*)0))
2973 "|step", NULL, &o_step,_npy_parse_arguments("arange", &__argparse_cache, args, len_args
, kwnames, "|start", ((void*)0), &o_start, "|stop", ((void
*)0), &o_stop, "|step", ((void*)0), &o_step, "|dtype"
, &PyArray_DescrConverter2, &typecode, "$like", ((void
*)0), &like, ((void*)0), ((void*)0), ((void*)0))
2974 "|dtype", &PyArray_DescrConverter2, &typecode,_npy_parse_arguments("arange", &__argparse_cache, args, len_args
, kwnames, "|start", ((void*)0), &o_start, "|stop", ((void
*)0), &o_stop, "|step", ((void*)0), &o_step, "|dtype"
, &PyArray_DescrConverter2, &typecode, "$like", ((void
*)0), &like, ((void*)0), ((void*)0), ((void*)0))
2975 "$like", NULL, &like,_npy_parse_arguments("arange", &__argparse_cache, args, len_args
, kwnames, "|start", ((void*)0), &o_start, "|stop", ((void
*)0), &o_stop, "|step", ((void*)0), &o_step, "|dtype"
, &PyArray_DescrConverter2, &typecode, "$like", ((void
*)0), &like, ((void*)0), ((void*)0), ((void*)0))
2976 NULL, NULL, NULL)_npy_parse_arguments("arange", &__argparse_cache, args, len_args
, kwnames, "|start", ((void*)0), &o_start, "|stop", ((void
*)0), &o_stop, "|step", ((void*)0), &o_step, "|dtype"
, &PyArray_DescrConverter2, &typecode, "$like", ((void
*)0), &like, ((void*)0), ((void*)0), ((void*)0))
< 0) {
2977 Py_XDECREF(typecode)_Py_XDECREF(((PyObject*)(typecode)));
2978 return NULL((void*)0);
2979 }
2980 if (like != NULL((void*)0)) {
2981 PyObject *deferred = array_implement_c_array_function_creation(
2982 "arange", like, NULL((void*)0), NULL((void*)0), args, len_args, kwnames);
2983 if (deferred != Py_NotImplemented(&_Py_NotImplementedStruct)) {
2984 Py_XDECREF(typecode)_Py_XDECREF(((PyObject*)(typecode)));
2985 return deferred;
2986 }
2987 }
2988
2989 if (o_stop == NULL((void*)0)) {
2990 if (len_args == 0){
2991 PyErr_SetString(PyExc_TypeError,
2992 "arange() requires stop to be specified.");
2993 Py_XDECREF(typecode)_Py_XDECREF(((PyObject*)(typecode)));
2994 return NULL((void*)0);
2995 }
2996 }
2997 else if (o_start == NULL((void*)0)) {
2998 o_start = o_stop;
2999 o_stop = NULL((void*)0);
3000 }
3001
3002 range = PyArray_ArangeObj(o_start, o_stop, o_step, typecode);
3003 Py_XDECREF(typecode)_Py_XDECREF(((PyObject*)(typecode)));
3004
3005 return range;
3006}
3007
3008/*NUMPY_API
3009 *
3010 * Included at the very first so not auto-grabbed and thus not labeled.
3011 */
3012NPY_NO_EXPORT__attribute__((visibility("hidden"))) unsigned int
3013PyArray_GetNDArrayCVersion(void)
3014{
3015 return (unsigned int)NPY_ABI_VERSION0x01000009;
3016}
3017
3018/*NUMPY_API
3019 * Returns the built-in (at compilation time) C API version
3020 */
3021NPY_NO_EXPORT__attribute__((visibility("hidden"))) unsigned int
3022PyArray_GetNDArrayCFeatureVersion(void)
3023{
3024 return (unsigned int)NPY_API_VERSION0x0000000E;
3025}
3026
3027static PyObject *
3028array__get_ndarray_c_version(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
3029{
3030 static char *kwlist[] = {NULL((void*)0)};
3031
3032 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "", kwlist )) {
3033 return NULL((void*)0);
3034 }
3035 return PyLong_FromLong( (long) PyArray_GetNDArrayCVersion() );
3036}
3037
3038/*NUMPY_API
3039*/
3040NPY_NO_EXPORT__attribute__((visibility("hidden"))) int
3041PyArray_GetEndianness(void)
3042{
3043 const union {
3044 npy_uint32 i;
3045 char c[4];
3046 } bint = {0x01020304};
3047
3048 if (bint.c[0] == 1) {
3049 return NPY_CPU_BIG;
3050 }
3051 else if (bint.c[0] == 4) {
3052 return NPY_CPU_LITTLE;
3053 }
3054 else {
3055 return NPY_CPU_UNKNOWN_ENDIAN;
3056 }
3057}
3058
3059static PyObject *
3060array__reconstruct(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args)
3061{
3062
3063 PyObject *ret;
3064 PyTypeObject *subtype;
3065 PyArray_Dims shape = {NULL((void*)0), 0};
3066 PyArray_Descr *dtype = NULL((void*)0);
3067
3068 evil_global_disable_warn_O4O8_flag = 1;
3069
3070 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O!O&O&:_reconstruct",
3071 &PyType_Type, &subtype,
3072 PyArray_IntpConverter, &shape,
3073 PyArray_DescrConverter, &dtype)) {
3074 goto fail;
3075 }
3076 if (!PyType_IsSubtype(subtype, &PyArray_Type)) {
3077 PyErr_SetString(PyExc_TypeError,
3078 "_reconstruct: First argument must be a sub-type of ndarray");
3079 goto fail;
3080 }
3081 ret = PyArray_NewFromDescr(subtype, dtype,
3082 (int)shape.len, shape.ptr, NULL((void*)0), NULL((void*)0), 0, NULL((void*)0));
3083 npy_free_cache_dim_obj(shape);
3084
3085 evil_global_disable_warn_O4O8_flag = 0;
3086
3087 return ret;
3088
3089fail:
3090 evil_global_disable_warn_O4O8_flag = 0;
3091
3092 Py_XDECREF(dtype)_Py_XDECREF(((PyObject*)(dtype)));
3093 npy_free_cache_dim_obj(shape);
3094 return NULL((void*)0);
3095}
3096
3097static PyObject *
3098array_set_string_function(PyObject *NPY_UNUSED(self)(__NPY_UNUSED_TAGGEDself) __attribute__ ((__unused__)), PyObject *args,
3099 PyObject *kwds)
3100{
3101 PyObject *op = NULL((void*)0);
3102 int repr = 1;
3103 static char *kwlist[] = {"f", "repr", NULL((void*)0)};
3104
3105 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "|Oi:set_string_function", kwlist, &op, &repr)) {
3106 return NULL((void*)0);
3107 }
3108 /* reset the array_repr function to built-in */
3109 if (op == Py_None(&_Py_NoneStruct)) {
3110 op = NULL((void*)0);
3111 }
3112 if (op != NULL((void*)0) && !PyCallable_Check(op)) {
3113 PyErr_SetString(PyExc_TypeError,
3114 "Argument must be callable.");
3115 return NULL((void*)0);
3116 }
3117 PyArray_SetStringFunction(op, repr);
3118 Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (&
_Py_NoneStruct)
;
3119}
3120
3121static PyObject *
3122array_set_ops_function(PyObject *NPY_UNUSED(self)(__NPY_UNUSED_TAGGEDself) __attribute__ ((__unused__)), PyObject *NPY_UNUSED(args)(__NPY_UNUSED_TAGGEDargs) __attribute__ ((__unused__)),
3123 PyObject *kwds)
3124{
3125 PyObject *oldops = NULL((void*)0);
3126
3127 if ((oldops = _PyArray_GetNumericOps()) == NULL((void*)0)) {
3128 return NULL((void*)0);
3129 }
3130 /*
3131 * Should probably ensure that objects are at least callable
3132 * Leave this to the caller for now --- error will be raised
3133 * later when use is attempted
3134 */
3135 if (kwds && PyArray_SetNumericOps(kwds) == -1) {
3136 Py_DECREF(oldops)_Py_DECREF(((PyObject*)(oldops)));
3137 if (PyErr_Occurred() == NULL((void*)0)) {
3138 PyErr_SetString(PyExc_ValueError,
3139 "one or more objects not callable");
3140 }
3141 return NULL((void*)0);
3142 }
3143 return oldops;
3144}
3145
3146static PyObject *
3147array_set_datetimeparse_function(PyObject *NPY_UNUSED(self)(__NPY_UNUSED_TAGGEDself) __attribute__ ((__unused__)),
3148 PyObject *NPY_UNUSED(args)(__NPY_UNUSED_TAGGEDargs) __attribute__ ((__unused__)), PyObject *NPY_UNUSED(kwds)(__NPY_UNUSED_TAGGEDkwds) __attribute__ ((__unused__)))
3149{
3150 PyErr_SetString(PyExc_RuntimeError, "This function has been removed");
3151 return NULL((void*)0);
3152}
3153
3154/*
3155 * inner loop with constant size memcpy arguments
3156 * this allows the compiler to replace function calls while still handling the
3157 * alignment requirements of the platform.
3158 */
3159#define INNER_WHERE_LOOP(size) \
3160 do { \
3161 npy_intp i; \
3162 for (i = 0; i < n; i++) { \
3163 if (*csrc) { \
3164 memcpy(dst, xsrc, size); \
3165 } \
3166 else { \
3167 memcpy(dst, ysrc, size); \
3168 } \
3169 dst += size; \
3170 xsrc += xstride; \
3171 ysrc += ystride; \
3172 csrc += cstride; \
3173 } \
3174 } while(0)
3175
3176
3177/*NUMPY_API
3178 * Where
3179 */
3180NPY_NO_EXPORT__attribute__((visibility("hidden"))) PyObject *
3181PyArray_Where(PyObject *condition, PyObject *x, PyObject *y)
3182{
3183 PyArrayObject *arr, *ax, *ay;
3184 PyObject *ret = NULL((void*)0);
3185
3186 arr = (PyArrayObject *)PyArray_FROM_O(condition)PyArray_FromAny(condition, ((void*)0), 0, 0, 0, ((void*)0));
3187 if (arr == NULL((void*)0)) {
3188 return NULL((void*)0);
3189 }
3190 if ((x == NULL((void*)0)) && (y == NULL((void*)0))) {
3191 ret = PyArray_Nonzero(arr);
3192 Py_DECREF(arr)_Py_DECREF(((PyObject*)(arr)));
3193 return ret;
3194 }
3195 if ((x == NULL((void*)0)) || (y == NULL((void*)0))) {
3196 Py_DECREF(arr)_Py_DECREF(((PyObject*)(arr)));
3197 PyErr_SetString(PyExc_ValueError,
3198 "either both or neither of x and y should be given");
3199 return NULL((void*)0);
3200 }
3201
3202 ax = (PyArrayObject*)PyArray_FROM_O(x)PyArray_FromAny(x, ((void*)0), 0, 0, 0, ((void*)0));
3203 ay = (PyArrayObject*)PyArray_FROM_O(y)PyArray_FromAny(y, ((void*)0), 0, 0, 0, ((void*)0));
3204 if (ax == NULL((void*)0) || ay == NULL((void*)0)) {
3205 goto fail;
3206 }
3207 else {
3208 npy_uint32 flags = NPY_ITER_EXTERNAL_LOOP0x00000008 | NPY_ITER_BUFFERED0x00000200 |
3209 NPY_ITER_REFS_OK0x00000020 | NPY_ITER_ZEROSIZE_OK0x00000040;
3210 PyArrayObject * op_in[4] = {
3211 NULL((void*)0), arr, ax, ay
3212 };
3213 npy_uint32 op_flags[4] = {
3214 NPY_ITER_WRITEONLY0x00040000 | NPY_ITER_ALLOCATE0x01000000 | NPY_ITER_NO_SUBTYPE0x02000000,
3215 NPY_ITER_READONLY0x00020000, NPY_ITER_READONLY0x00020000, NPY_ITER_READONLY0x00020000
3216 };
3217 PyArray_Descr * common_dt = PyArray_ResultType(2, &op_in[0] + 2,
3218 0, NULL((void*)0));
3219 PyArray_Descr * op_dt[4] = {common_dt, PyArray_DescrFromType(NPY_BOOL),
3220 common_dt, common_dt};
3221 NpyIter * iter;
3222 int needs_api;
3223 NPY_BEGIN_THREADS_DEFPyThreadState *_save=((void*)0);;
3224
3225 if (common_dt == NULL((void*)0) || op_dt[1] == NULL((void*)0)) {
3226 Py_XDECREF(op_dt[1])_Py_XDECREF(((PyObject*)(op_dt[1])));
3227 Py_XDECREF(common_dt)_Py_XDECREF(((PyObject*)(common_dt)));
3228 goto fail;
3229 }
3230 iter = NpyIter_MultiNew(4, op_in, flags,
3231 NPY_KEEPORDER, NPY_UNSAFE_CASTING,
3232 op_flags, op_dt);
3233 Py_DECREF(op_dt[1])_Py_DECREF(((PyObject*)(op_dt[1])));
3234 Py_DECREF(common_dt)_Py_DECREF(((PyObject*)(common_dt)));
3235 if (iter == NULL((void*)0)) {
3236 goto fail;
3237 }
3238
3239 needs_api = NpyIter_IterationNeedsAPI(iter);
3240
3241 /* Get the result from the iterator object array */
3242 ret = (PyObject*)NpyIter_GetOperandArray(iter)[0];
3243
3244 NPY_BEGIN_THREADS_NDITER(iter)do { if (!NpyIter_IterationNeedsAPI(iter)) { do { if ((NpyIter_GetIterSize
(iter)) > 500) { _save = PyEval_SaveThread();} } while (0)
;; } } while(0)
;
3245
3246 if (NpyIter_GetIterSize(iter) != 0) {
3247 NpyIter_IterNextFunc *iternext = NpyIter_GetIterNext(iter, NULL((void*)0));
3248 npy_intp * innersizeptr = NpyIter_GetInnerLoopSizePtr(iter);
3249 char **dataptrarray = NpyIter_GetDataPtrArray(iter);
3250
3251 do {
3252 PyArray_Descr * dtx = NpyIter_GetDescrArray(iter)[2];
3253 PyArray_Descr * dty = NpyIter_GetDescrArray(iter)[3];
3254 int axswap = PyDataType_ISBYTESWAPPED(dtx)(!((((PyArray_Descr *)(dtx))->byteorder) != '>'));
3255 int ayswap = PyDataType_ISBYTESWAPPED(dty)(!((((PyArray_Descr *)(dty))->byteorder) != '>'));
3256 PyArray_CopySwapFunc *copyswapx = dtx->f->copyswap;
3257 PyArray_CopySwapFunc *copyswapy = dty->f->copyswap;
3258 int native = (axswap == ayswap) && (axswap == 0) && !needs_api;
3259 npy_intp n = (*innersizeptr);
3260 npy_intp itemsize = NpyIter_GetDescrArray(iter)[0]->elsize;
3261 npy_intp cstride = NpyIter_GetInnerStrideArray(iter)[1];
3262 npy_intp xstride = NpyIter_GetInnerStrideArray(iter)[2];
3263 npy_intp ystride = NpyIter_GetInnerStrideArray(iter)[3];
3264 char * dst = dataptrarray[0];
3265 char * csrc = dataptrarray[1];
3266 char * xsrc = dataptrarray[2];
3267 char * ysrc = dataptrarray[3];
3268
3269 /* constant sizes so compiler replaces memcpy */
3270 if (native && itemsize == 16) {
3271 INNER_WHERE_LOOP(16);
3272 }
3273 else if (native && itemsize == 8) {
3274 INNER_WHERE_LOOP(8);
3275 }
3276 else if (native && itemsize == 4) {
3277 INNER_WHERE_LOOP(4);
3278 }
3279 else if (native && itemsize == 2) {
3280 INNER_WHERE_LOOP(2);
3281 }
3282 else if (native && itemsize == 1) {
3283 INNER_WHERE_LOOP(1);
3284 }
3285 else {
3286 /* copyswap is faster than memcpy even if we are native */
3287 npy_intp i;
3288 for (i = 0; i < n; i++) {
3289 if (*csrc) {
3290 copyswapx(dst, xsrc, axswap, ret);
3291 }
3292 else {
3293 copyswapy(dst, ysrc, ayswap, ret);
3294 }
3295 dst += itemsize;
3296 xsrc += xstride;
3297 ysrc += ystride;
3298 csrc += cstride;
3299 }
3300 }
3301 } while (iternext(iter));
3302 }
3303
3304 NPY_END_THREADSdo { if (_save) { PyEval_RestoreThread(_save); _save = ((void
*)0);} } while (0);
;
3305
3306 Py_INCREF(ret)_Py_INCREF(((PyObject*)(ret)));
3307 Py_DECREF(arr)_Py_DECREF(((PyObject*)(arr)));
3308 Py_DECREF(ax)_Py_DECREF(((PyObject*)(ax)));
3309 Py_DECREF(ay)_Py_DECREF(((PyObject*)(ay)));
3310
3311 if (NpyIter_Deallocate(iter) != NPY_SUCCEED1) {
3312 Py_DECREF(ret)_Py_DECREF(((PyObject*)(ret)));
3313 return NULL((void*)0);
3314 }
3315
3316 return ret;
3317 }
3318
3319fail:
3320 Py_DECREF(arr)_Py_DECREF(((PyObject*)(arr)));
3321 Py_XDECREF(ax)_Py_XDECREF(((PyObject*)(ax)));
3322 Py_XDECREF(ay)_Py_XDECREF(((PyObject*)(ay)));
3323 return NULL((void*)0);
3324}
3325
3326#undef INNER_WHERE_LOOP
3327
3328static PyObject *
3329array_where(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)), PyObject *args)
3330{
3331 PyObject *obj = NULL((void*)0), *x = NULL((void*)0), *y = NULL((void*)0);
3332
3333 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O|OO:where", &obj, &x, &y)) {
3334 return NULL((void*)0);
3335 }
3336 return PyArray_Where(obj, x, y);
3337}
3338
3339static PyObject *
3340array_lexsort(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
3341{
3342 int axis = -1;
3343 PyObject *obj;
3344 static char *kwlist[] = {"keys", "axis", NULL((void*)0)};
3345
3346 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "O|i:lexsort", kwlist, &obj, &axis)) {
3347 return NULL((void*)0);
3348 }
3349 return PyArray_Return((PyArrayObject *)PyArray_LexSort(obj, axis));
3350}
3351
3352static PyObject *
3353array_can_cast_safely(PyObject *NPY_UNUSED(self)(__NPY_UNUSED_TAGGEDself) __attribute__ ((__unused__)), PyObject *args,
3354 PyObject *kwds)
3355{
3356 PyObject *from_obj = NULL((void*)0);
3357 PyArray_Descr *d1 = NULL((void*)0);
3358 PyArray_Descr *d2 = NULL((void*)0);
3359 int ret;
3360 PyObject *retobj = NULL((void*)0);
3361 NPY_CASTING casting = NPY_SAFE_CASTING;
3362 static char *kwlist[] = {"from_", "to", "casting", NULL((void*)0)};
3363
3364 if(!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "OO&|O&:can_cast", kwlist,
3365 &from_obj,
3366 PyArray_DescrConverter2, &d2,
3367 PyArray_CastingConverter, &casting)) {
3368 goto finish;
3369 }
3370 if (d2 == NULL((void*)0)) {
3371 PyErr_SetString(PyExc_TypeError,
3372 "did not understand one of the types; 'None' not accepted");
3373 goto finish;
3374 }
3375
3376 /* If the first parameter is an object or scalar, use CanCastArrayTo */
3377 if (PyArray_Check(from_obj)((((PyObject*)(from_obj))->ob_type) == (&PyArray_Type)
|| PyType_IsSubtype((((PyObject*)(from_obj))->ob_type), (
&PyArray_Type)))
) {
3378 ret = PyArray_CanCastArrayTo((PyArrayObject *)from_obj, d2, casting);
3379 }
3380 else if (PyArray_IsScalar(from_obj, Generic)(((((PyObject*)(from_obj))->ob_type) == (&PyGenericArrType_Type
) || PyType_IsSubtype((((PyObject*)(from_obj))->ob_type), (
&PyGenericArrType_Type))))
||
3381 PyArray_IsPythonNumber(from_obj)(((((PyObject*)(from_obj))->ob_type) == (&PyFloat_Type
) || PyType_IsSubtype((((PyObject*)(from_obj))->ob_type), (
&PyFloat_Type))) || ((((PyObject*)(from_obj))->ob_type
) == (&PyComplex_Type) || PyType_IsSubtype((((PyObject*)(
from_obj))->ob_type), (&PyComplex_Type))) || ((((((PyObject
*)(from_obj))->ob_type))->tp_flags & ((1UL <<
24))) != 0) || ((((PyObject*)(from_obj))->ob_type) == &
PyBool_Type))
) {
3382 PyArrayObject *arr;
3383 arr = (PyArrayObject *)PyArray_FROM_O(from_obj)PyArray_FromAny(from_obj, ((void*)0), 0, 0, 0, ((void*)0));
3384 if (arr == NULL((void*)0)) {
3385 goto finish;
3386 }
3387 ret = PyArray_CanCastArrayTo(arr, d2, casting);
3388 Py_DECREF(arr)_Py_DECREF(((PyObject*)(arr)));
3389 }
3390 /* Otherwise use CanCastTypeTo */
3391 else {
3392 if (!PyArray_DescrConverter2(from_obj, &d1) || d1 == NULL((void*)0)) {
3393 PyErr_SetString(PyExc_TypeError,
3394 "did not understand one of the types; 'None' not accepted");
3395 goto finish;
3396 }
3397 ret = PyArray_CanCastTypeTo(d1, d2, casting);
3398 }
3399
3400 retobj = ret ? Py_True((PyObject *) &_Py_TrueStruct) : Py_False((PyObject *) &_Py_FalseStruct);
3401 Py_INCREF(retobj)_Py_INCREF(((PyObject*)(retobj)));
3402
3403 finish:
3404 Py_XDECREF(d1)_Py_XDECREF(((PyObject*)(d1)));
3405 Py_XDECREF(d2)_Py_XDECREF(((PyObject*)(d2)));
3406 return retobj;
3407}
3408
3409static PyObject *
3410array_promote_types(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args)
3411{
3412 PyArray_Descr *d1 = NULL((void*)0);
3413 PyArray_Descr *d2 = NULL((void*)0);
3414 PyObject *ret = NULL((void*)0);
3415 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O&O&:promote_types",
3416 PyArray_DescrConverter2, &d1, PyArray_DescrConverter2, &d2)) {
3417 goto finish;
3418 }
3419
3420 if (d1 == NULL((void*)0) || d2 == NULL((void*)0)) {
3421 PyErr_SetString(PyExc_TypeError,
3422 "did not understand one of the types");
3423 goto finish;
3424 }
3425
3426 ret = (PyObject *)PyArray_PromoteTypes(d1, d2);
3427
3428 finish:
3429 Py_XDECREF(d1)_Py_XDECREF(((PyObject*)(d1)));
3430 Py_XDECREF(d2)_Py_XDECREF(((PyObject*)(d2)));
3431 return ret;
3432}
3433
3434static PyObject *
3435array_min_scalar_type(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args)
3436{
3437 PyObject *array_in = NULL((void*)0);
3438 PyArrayObject *array;
3439 PyObject *ret = NULL((void*)0);
3440
3441 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O:min_scalar_type", &array_in)) {
3442 return NULL((void*)0);
3443 }
3444
3445 array = (PyArrayObject *)PyArray_FROM_O(array_in)PyArray_FromAny(array_in, ((void*)0), 0, 0, 0, ((void*)0));
3446 if (array == NULL((void*)0)) {
3447 return NULL((void*)0);
3448 }
3449
3450 ret = (PyObject *)PyArray_MinScalarType(array);
3451 Py_DECREF(array)_Py_DECREF(((PyObject*)(array)));
3452 return ret;
3453}
3454
3455static PyObject *
3456array_result_type(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args)
3457{
3458 npy_intp i, len, narr = 0, ndtypes = 0;
3459 PyArrayObject **arr = NULL((void*)0);
3460 PyArray_Descr **dtypes = NULL((void*)0);
3461 PyObject *ret = NULL((void*)0);
3462
3463 len = PyTuple_GET_SIZE(args)(((PyVarObject*)((((void) (0)), (PyTupleObject *)(args))))->
ob_size)
;
3464 if (len == 0) {
3465 PyErr_SetString(PyExc_ValueError,
3466 "at least one array or dtype is required");
3467 goto finish;
3468 }
3469
3470 arr = PyArray_mallocPyMem_RawMalloc(2 * len * sizeof(void *));
3471 if (arr == NULL((void*)0)) {
3472 return PyErr_NoMemory();
3473 }
3474 dtypes = (PyArray_Descr**)&arr[len];
3475
3476 for (i = 0; i < len; ++i) {
3477 PyObject *obj = PyTuple_GET_ITEM(args, i)((((void) (0)), (PyTupleObject *)(args))->ob_item[i]);
3478 if (PyArray_Check(obj)((((PyObject*)(obj))->ob_type) == (&PyArray_Type) || PyType_IsSubtype
((((PyObject*)(obj))->ob_type), (&PyArray_Type)))
) {
3479 Py_INCREF(obj)_Py_INCREF(((PyObject*)(obj)));
3480 arr[narr] = (PyArrayObject *)obj;
3481 ++narr;
3482 }
3483 else if (PyArray_IsScalar(obj, Generic)(((((PyObject*)(obj))->ob_type) == (&PyGenericArrType_Type
) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (&
PyGenericArrType_Type))))
||
3484 PyArray_IsPythonNumber(obj)(((((PyObject*)(obj))->ob_type) == (&PyFloat_Type) || PyType_IsSubtype
((((PyObject*)(obj))->ob_type), (&PyFloat_Type))) || (
(((PyObject*)(obj))->ob_type) == (&PyComplex_Type) || PyType_IsSubtype
((((PyObject*)(obj))->ob_type), (&PyComplex_Type))) ||
((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL
<< 24))) != 0) || ((((PyObject*)(obj))->ob_type) ==
&PyBool_Type))
) {
3485 arr[narr] = (PyArrayObject *)PyArray_FROM_O(obj)PyArray_FromAny(obj, ((void*)0), 0, 0, 0, ((void*)0));
3486 if (arr[narr] == NULL((void*)0)) {
3487 goto finish;
3488 }
3489 if (PyLong_CheckExact(obj)((((PyObject*)(obj))->ob_type) == &PyLong_Type) || PyFloat_CheckExact(obj)((((PyObject*)(obj))->ob_type) == &PyFloat_Type) ||
3490 PyComplex_CheckExact(obj)((((PyObject*)(obj))->ob_type) == &PyComplex_Type)) {
3491 ((PyArrayObject_fields *)arr[narr])->flags |= _NPY_ARRAY_WAS_PYSCALAR0x0040;
3492 }
3493 ++narr;
3494 }
3495 else {
3496 if (!PyArray_DescrConverter(obj, &dtypes[ndtypes])) {
3497 goto finish;
3498 }
3499 ++ndtypes;
3500 }
3501 }
3502
3503 ret = (PyObject *)PyArray_ResultType(narr, arr, ndtypes, dtypes);
3504
3505finish:
3506 for (i = 0; i < narr; ++i) {
3507 Py_DECREF(arr[i])_Py_DECREF(((PyObject*)(arr[i])));
3508 }
3509 for (i = 0; i < ndtypes; ++i) {
3510 Py_DECREF(dtypes[i])_Py_DECREF(((PyObject*)(dtypes[i])));
3511 }
3512 PyArray_freePyMem_RawFree(arr);
3513 return ret;
3514}
3515
3516static PyObject *
3517array_datetime_data(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args)
3518{
3519 PyArray_Descr *dtype;
3520 PyArray_DatetimeMetaData *meta;
3521
3522 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O&:datetime_data",
3523 PyArray_DescrConverter, &dtype)) {
3524 return NULL((void*)0);
3525 }
3526
3527 meta = get_datetime_metadata_from_dtype(dtype);
3528 if (meta == NULL((void*)0)) {
3529 Py_DECREF(dtype)_Py_DECREF(((PyObject*)(dtype)));
3530 return NULL((void*)0);
3531 }
3532
3533 PyObject *res = convert_datetime_metadata_to_tuple(meta);
3534 Py_DECREF(dtype)_Py_DECREF(((PyObject*)(dtype)));
3535 return res;
3536}
3537
3538
3539static int
3540trimmode_converter(PyObject *obj, TrimMode *trim)
3541{
3542 if (!PyUnicode_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL
<< 28))) != 0)
|| PyUnicode_GetLength(obj) != 1) {
3543 goto error;
3544 }
3545 const char *trimstr = PyUnicode_AsUTF8AndSize(obj, NULL((void*)0));
3546
3547 if (trimstr != NULL((void*)0)) {
3548 if (trimstr[0] == 'k') {
3549 *trim = TrimMode_None;
3550 }
3551 else if (trimstr[0] == '.') {
3552 *trim = TrimMode_Zeros;
3553 }
3554 else if (trimstr[0] == '0') {
3555 *trim = TrimMode_LeaveOneZero;
3556 }
3557 else if (trimstr[0] == '-') {
3558 *trim = TrimMode_DptZeros;
3559 }
3560 else {
3561 goto error;
3562 }
3563 }
3564 return NPY_SUCCEED1;
3565
3566error:
3567 PyErr_Format(PyExc_TypeError,
3568 "if supplied, trim must be 'k', '.', '0' or '-' found `%100S`",
3569 obj);
3570 return NPY_FAIL0;
3571}
3572
3573
3574/*
3575 * Prints floating-point scalars using the Dragon4 algorithm, scientific mode.
3576 * See docstring of `np.format_float_scientific` for description of arguments.
3577 * The differences is that a value of -1 is valid for pad_left, exp_digits,
3578 * precision, which is equivalent to `None`.
3579 */
3580static PyObject *
3581dragon4_scientific(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)),
3582 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
3583{
3584 PyObject *obj;
3585 int precision=-1, pad_left=-1, exp_digits=-1, min_digits=-1;
3586 DigitMode digit_mode;
3587 TrimMode trim = TrimMode_None;
3588 int sign=0, unique=1;
3589 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
3590
3591 if (npy_parse_arguments("dragon4_scientific", args, len_args, kwnames,_npy_parse_arguments("dragon4_scientific", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|exp_digits", &PyArray_PythonPyIntFromInt, &
exp_digits, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3592 "x", NULL , &obj,_npy_parse_arguments("dragon4_scientific", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|exp_digits", &PyArray_PythonPyIntFromInt, &
exp_digits, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3593 "|precision", &PyArray_PythonPyIntFromInt, &precision,_npy_parse_arguments("dragon4_scientific", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|exp_digits", &PyArray_PythonPyIntFromInt, &
exp_digits, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3594 "|unique", &PyArray_PythonPyIntFromInt, &unique,_npy_parse_arguments("dragon4_scientific", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|exp_digits", &PyArray_PythonPyIntFromInt, &
exp_digits, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3595 "|sign", &PyArray_PythonPyIntFromInt, &sign,_npy_parse_arguments("dragon4_scientific", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|exp_digits", &PyArray_PythonPyIntFromInt, &
exp_digits, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3596 "|trim", &trimmode_converter, &trim,_npy_parse_arguments("dragon4_scientific", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|exp_digits", &PyArray_PythonPyIntFromInt, &
exp_digits, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3597 "|pad_left", &PyArray_PythonPyIntFromInt, &pad_left,_npy_parse_arguments("dragon4_scientific", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|exp_digits", &PyArray_PythonPyIntFromInt, &
exp_digits, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3598 "|exp_digits", &PyArray_PythonPyIntFromInt, &exp_digits,_npy_parse_arguments("dragon4_scientific", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|exp_digits", &PyArray_PythonPyIntFromInt, &
exp_digits, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3599 "|min_digits", &PyArray_PythonPyIntFromInt, &min_digits,_npy_parse_arguments("dragon4_scientific", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|exp_digits", &PyArray_PythonPyIntFromInt, &
exp_digits, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3600 NULL, NULL, NULL)_npy_parse_arguments("dragon4_scientific", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|exp_digits", &PyArray_PythonPyIntFromInt, &
exp_digits, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
< 0) {
3601 return NULL((void*)0);
3602 }
3603
3604 digit_mode = unique ? DigitMode_Unique : DigitMode_Exact;
3605
3606 if (unique == 0 && precision < 0) {
3607 PyErr_SetString(PyExc_TypeError,
3608 "in non-unique mode `precision` must be supplied");
3609 return NULL((void*)0);
3610 }
3611
3612 return Dragon4_Scientific(obj, digit_mode, precision, min_digits, sign, trim,
3613 pad_left, exp_digits);
3614}
3615
3616/*
3617 * Prints floating-point scalars using the Dragon4 algorithm, positional mode.
3618 * See docstring of `np.format_float_positional` for description of arguments.
3619 * The differences is that a value of -1 is valid for pad_left, pad_right,
3620 * precision, which is equivalent to `None`.
3621 */
3622static PyObject *
3623dragon4_positional(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)),
3624 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
3625{
3626 PyObject *obj;
3627 int precision=-1, pad_left=-1, pad_right=-1, min_digits=-1;
3628 CutoffMode cutoff_mode;
3629 DigitMode digit_mode;
3630 TrimMode trim = TrimMode_None;
3631 int sign=0, unique=1, fractional=0;
3632 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
3633
3634 if (npy_parse_arguments("dragon4_positional", args, len_args, kwnames,_npy_parse_arguments("dragon4_positional", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|fractional",
&PyArray_PythonPyIntFromInt, &fractional, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|pad_right", &PyArray_PythonPyIntFromInt, &
pad_right, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3635 "x", NULL , &obj,_npy_parse_arguments("dragon4_positional", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|fractional",
&PyArray_PythonPyIntFromInt, &fractional, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|pad_right", &PyArray_PythonPyIntFromInt, &
pad_right, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3636 "|precision", &PyArray_PythonPyIntFromInt, &precision,_npy_parse_arguments("dragon4_positional", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|fractional",
&PyArray_PythonPyIntFromInt, &fractional, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|pad_right", &PyArray_PythonPyIntFromInt, &
pad_right, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3637 "|unique", &PyArray_PythonPyIntFromInt, &unique,_npy_parse_arguments("dragon4_positional", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|fractional",
&PyArray_PythonPyIntFromInt, &fractional, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|pad_right", &PyArray_PythonPyIntFromInt, &
pad_right, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3638 "|fractional", &PyArray_PythonPyIntFromInt, &fractional,_npy_parse_arguments("dragon4_positional", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|fractional",
&PyArray_PythonPyIntFromInt, &fractional, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|pad_right", &PyArray_PythonPyIntFromInt, &
pad_right, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3639 "|sign", &PyArray_PythonPyIntFromInt, &sign,_npy_parse_arguments("dragon4_positional", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|fractional",
&PyArray_PythonPyIntFromInt, &fractional, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|pad_right", &PyArray_PythonPyIntFromInt, &
pad_right, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3640 "|trim", &trimmode_converter, &trim,_npy_parse_arguments("dragon4_positional", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|fractional",
&PyArray_PythonPyIntFromInt, &fractional, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|pad_right", &PyArray_PythonPyIntFromInt, &
pad_right, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3641 "|pad_left", &PyArray_PythonPyIntFromInt, &pad_left,_npy_parse_arguments("dragon4_positional", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|fractional",
&PyArray_PythonPyIntFromInt, &fractional, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|pad_right", &PyArray_PythonPyIntFromInt, &
pad_right, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3642 "|pad_right", &PyArray_PythonPyIntFromInt, &pad_right,_npy_parse_arguments("dragon4_positional", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|fractional",
&PyArray_PythonPyIntFromInt, &fractional, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|pad_right", &PyArray_PythonPyIntFromInt, &
pad_right, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3643 "|min_digits", &PyArray_PythonPyIntFromInt, &min_digits,_npy_parse_arguments("dragon4_positional", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|fractional",
&PyArray_PythonPyIntFromInt, &fractional, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|pad_right", &PyArray_PythonPyIntFromInt, &
pad_right, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
3644 NULL, NULL, NULL)_npy_parse_arguments("dragon4_positional", &__argparse_cache
, args, len_args, kwnames, "x", ((void*)0) , &obj, "|precision"
, &PyArray_PythonPyIntFromInt, &precision, "|unique",
&PyArray_PythonPyIntFromInt, &unique, "|fractional",
&PyArray_PythonPyIntFromInt, &fractional, "|sign", &
PyArray_PythonPyIntFromInt, &sign, "|trim", &trimmode_converter
, &trim, "|pad_left", &PyArray_PythonPyIntFromInt, &
pad_left, "|pad_right", &PyArray_PythonPyIntFromInt, &
pad_right, "|min_digits", &PyArray_PythonPyIntFromInt, &
min_digits, ((void*)0), ((void*)0), ((void*)0))
< 0) {
3645 return NULL((void*)0);
3646 }
3647
3648 digit_mode = unique ? DigitMode_Unique : DigitMode_Exact;
3649 cutoff_mode = fractional ? CutoffMode_FractionLength :
3650 CutoffMode_TotalLength;
3651
3652 if (unique == 0 && precision < 0) {
3653 PyErr_SetString(PyExc_TypeError,
3654 "in non-unique mode `precision` must be supplied");
3655 return NULL((void*)0);
3656 }
3657
3658 return Dragon4_Positional(obj, digit_mode, cutoff_mode, precision,
3659 min_digits, sign, trim, pad_left, pad_right);
3660}
3661
3662static PyObject *
3663format_longfloat(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
3664{
3665 PyObject *obj;
3666 unsigned int precision;
3667 static char *kwlist[] = {"x", "precision", NULL((void*)0)};
3668
3669 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "OI:format_longfloat", kwlist,
3670 &obj, &precision)) {
3671 return NULL((void*)0);
3672 }
3673 if (!PyArray_IsScalar(obj, LongDouble)(((((PyObject*)(obj))->ob_type) == (&PyLongDoubleArrType_Type
) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (&
PyLongDoubleArrType_Type))))
) {
3674 PyErr_SetString(PyExc_TypeError,
3675 "not a longfloat");
3676 return NULL((void*)0);
3677 }
3678 return Dragon4_Scientific(obj, DigitMode_Unique, precision, -1, 0,
3679 TrimMode_LeaveOneZero, -1, -1);
3680}
3681
3682static PyObject *
3683compare_chararrays(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
3684{
3685 PyObject *array;
3686 PyObject *other;
3687 PyArrayObject *newarr, *newoth;
3688 int cmp_op;
3689 npy_bool rstrip;
3690 char *cmp_str;
3691 Py_ssize_t strlength;
3692 PyObject *res = NULL((void*)0);
3693 static char msg[] = "comparison must be '==', '!=', '<', '>', '<=', '>='";
3694 static char *kwlist[] = {"a1", "a2", "cmp", "rstrip", NULL((void*)0)};
3695
3696 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "OOs#O&:compare_chararrays",
3697 kwlist,
3698 &array, &other, &cmp_str, &strlength,
3699 PyArray_BoolConverter, &rstrip)) {
3700 return NULL((void*)0);
3701 }
3702 if (strlength < 1 || strlength > 2) {
3703 goto err;
3704 }
3705 if (strlength > 1) {
3706 if (cmp_str[1] != '=') {
3707 goto err;
3708 }
3709 if (cmp_str[0] == '=') {
3710 cmp_op = Py_EQ2;
3711 }
3712 else if (cmp_str[0] == '!') {
3713 cmp_op = Py_NE3;
3714 }
3715 else if (cmp_str[0] == '<') {
3716 cmp_op = Py_LE1;
3717 }
3718 else if (cmp_str[0] == '>') {
3719 cmp_op = Py_GE5;
3720 }
3721 else {
3722 goto err;
3723 }
3724 }
3725 else {
3726 if (cmp_str[0] == '<') {
3727 cmp_op = Py_LT0;
3728 }
3729 else if (cmp_str[0] == '>') {
3730 cmp_op = Py_GT4;
3731 }
3732 else {
3733 goto err;
3734 }
3735 }
3736
3737 newarr = (PyArrayObject *)PyArray_FROM_O(array)PyArray_FromAny(array, ((void*)0), 0, 0, 0, ((void*)0));
3738 if (newarr == NULL((void*)0)) {
3739 return NULL((void*)0);
3740 }
3741 newoth = (PyArrayObject *)PyArray_FROM_O(other)PyArray_FromAny(other, ((void*)0), 0, 0, 0, ((void*)0));
3742 if (newoth == NULL((void*)0)) {
3743 Py_DECREF(newarr)_Py_DECREF(((PyObject*)(newarr)));
3744 return NULL((void*)0);
3745 }
3746 if (PyArray_ISSTRING(newarr)(((PyArray_TYPE(newarr)) == NPY_STRING) || ((PyArray_TYPE(newarr
)) == NPY_UNICODE))
&& PyArray_ISSTRING(newoth)(((PyArray_TYPE(newoth)) == NPY_STRING) || ((PyArray_TYPE(newoth
)) == NPY_UNICODE))
) {
3747 res = _strings_richcompare(newarr, newoth, cmp_op, rstrip != 0);
3748 }
3749 else {
3750 PyErr_SetString(PyExc_TypeError,
3751 "comparison of non-string arrays");
3752 }
3753 Py_DECREF(newarr)_Py_DECREF(((PyObject*)(newarr)));
3754 Py_DECREF(newoth)_Py_DECREF(((PyObject*)(newoth)));
3755 return res;
3756
3757 err:
3758 PyErr_SetString(PyExc_ValueError, msg);
3759 return NULL((void*)0);
3760}
3761
3762static PyObject *
3763_vec_string_with_args(PyArrayObject* char_array, PyArray_Descr* type,
3764 PyObject* method, PyObject* args)
3765{
3766 PyObject* broadcast_args[NPY_MAXARGS32];
3767 PyArrayMultiIterObject* in_iter = NULL((void*)0);
3768 PyArrayObject* result = NULL((void*)0);
3769 PyArrayIterObject* out_iter = NULL((void*)0);
3770 Py_ssize_t i, n, nargs;
3771
3772 nargs = PySequence_Size(args) + 1;
3773 if (nargs == -1 || nargs > NPY_MAXARGS32) {
3774 PyErr_Format(PyExc_ValueError,
3775 "len(args) must be < %d", NPY_MAXARGS32 - 1);
3776 Py_DECREF(type)_Py_DECREF(((PyObject*)(type)));
3777 goto err;
3778 }
3779
3780 broadcast_args[0] = (PyObject*)char_array;
3781 for (i = 1; i < nargs; i++) {
3782 PyObject* item = PySequence_GetItem(args, i-1);
3783 if (item == NULL((void*)0)) {
3784 Py_DECREF(type)_Py_DECREF(((PyObject*)(type)));
3785 goto err;
3786 }
3787 broadcast_args[i] = item;
3788 Py_DECREF(item)_Py_DECREF(((PyObject*)(item)));
3789 }
3790 in_iter = (PyArrayMultiIterObject*)PyArray_MultiIterFromObjects
3791 (broadcast_args, nargs, 0);
3792 if (in_iter == NULL((void*)0)) {
3793 Py_DECREF(type)_Py_DECREF(((PyObject*)(type)));
3794 goto err;
3795 }
3796 n = in_iter->numiter;
3797
3798 result = (PyArrayObject*)PyArray_SimpleNewFromDescr(in_iter->nd,PyArray_NewFromDescr(&PyArray_Type, type, in_iter->nd,
in_iter->dimensions, ((void*)0), ((void*)0), 0, ((void*)0
))
3799 in_iter->dimensions, type)PyArray_NewFromDescr(&PyArray_Type, type, in_iter->nd,
in_iter->dimensions, ((void*)0), ((void*)0), 0, ((void*)0
))
;
3800 if (result == NULL((void*)0)) {
3801 goto err;
3802 }
3803
3804 out_iter = (PyArrayIterObject*)PyArray_IterNew((PyObject*)result);
3805 if (out_iter == NULL((void*)0)) {
3806 goto err;
3807 }
3808
3809 while (PyArray_MultiIter_NOTDONE(in_iter)(((PyArrayMultiIterObject *)(in_iter))->index < ((PyArrayMultiIterObject
*)(in_iter))->size)
) {
3810 PyObject* item_result;
3811 PyObject* args_tuple = PyTuple_New(n);
3812 if (args_tuple == NULL((void*)0)) {
3813 goto err;
3814 }
3815
3816 for (i = 0; i < n; i++) {
3817 PyArrayIterObject* it = in_iter->iters[i];
3818 PyObject* arg = PyArray_ToScalar(PyArray_ITER_DATA(it), it->ao)PyArray_Scalar(((void *)(((PyArrayIterObject *)(it))->dataptr
)), PyArray_DESCR(it->ao), (PyObject *)it->ao)
;
3819 if (arg == NULL((void*)0)) {
3820 Py_DECREF(args_tuple)_Py_DECREF(((PyObject*)(args_tuple)));
3821 goto err;
3822 }
3823 /* Steals ref to arg */
3824 PyTuple_SetItem(args_tuple, i, arg);
3825 }
3826
3827 item_result = PyObject_CallObject(method, args_tuple);
3828 Py_DECREF(args_tuple)_Py_DECREF(((PyObject*)(args_tuple)));
3829 if (item_result == NULL((void*)0)) {
3830 goto err;
3831 }
3832
3833 if (PyArray_SETITEM(result, PyArray_ITER_DATA(out_iter)((void *)(((PyArrayIterObject *)(out_iter))->dataptr)), item_result)) {
3834 Py_DECREF(item_result)_Py_DECREF(((PyObject*)(item_result)));
3835 PyErr_SetString( PyExc_TypeError,
3836 "result array type does not match underlying function");
3837 goto err;
3838 }
3839 Py_DECREF(item_result)_Py_DECREF(((PyObject*)(item_result)));
3840
3841 PyArray_MultiIter_NEXT(in_iter)do { int __npy_mi; ((PyArrayMultiIterObject *)(in_iter))->
index++; for (__npy_mi=0; __npy_mi < ((PyArrayMultiIterObject
*)(in_iter))->numiter; __npy_mi++) { do { ((PyArrayIterObject
*)(((PyArrayMultiIterObject *)(in_iter))->iters[__npy_mi]
))->index++; if (((PyArrayIterObject *)(((PyArrayMultiIterObject
*)(in_iter))->iters[__npy_mi]))->nd_m1 == 0) { do { ((
(PyArrayIterObject *)(((PyArrayMultiIterObject *)(in_iter))->
iters[__npy_mi])))->dataptr += ((PyArrayIterObject *)(((PyArrayIterObject
*)(((PyArrayMultiIterObject *)(in_iter))->iters[__npy_mi]
))))->strides[0]; (((PyArrayIterObject *)(((PyArrayMultiIterObject
*)(in_iter))->iters[__npy_mi])))->coordinates[0]++; } while
(0); } else if (((PyArrayIterObject *)(((PyArrayMultiIterObject
*)(in_iter))->iters[__npy_mi]))->contiguous) ((PyArrayIterObject
*)(((PyArrayMultiIterObject *)(in_iter))->iters[__npy_mi]
))->dataptr += PyArray_DESCR(((PyArrayIterObject *)(((PyArrayMultiIterObject
*)(in_iter))->iters[__npy_mi]))->ao)->elsize; else if
(((PyArrayIterObject *)(((PyArrayMultiIterObject *)(in_iter)
)->iters[__npy_mi]))->nd_m1 == 1) { do { if ((((PyArrayIterObject
*)(((PyArrayMultiIterObject *)(in_iter))->iters[__npy_mi]
)))->coordinates[1] < (((PyArrayIterObject *)(((PyArrayMultiIterObject
*)(in_iter))->iters[__npy_mi])))->dims_m1[1]) { (((PyArrayIterObject
*)(((PyArrayMultiIterObject *)(in_iter))->iters[__npy_mi]
)))->coordinates[1]++; (((PyArrayIterObject *)(((PyArrayMultiIterObject
*)(in_iter))->iters[__npy_mi])))->dataptr += (((PyArrayIterObject
*)(((PyArrayMultiIterObject *)(in_iter))->iters[__npy_mi]
)))->strides[1]; } else { (((PyArrayIterObject *)(((PyArrayMultiIterObject
*)(in_iter))->iters[__npy_mi])))->coordinates[1] = 0; (
((PyArrayIterObject *)(((PyArrayMultiIterObject *)(in_iter))->
iters[__npy_mi])))->coordinates[0]++; (((PyArrayIterObject
*)(((PyArrayMultiIterObject *)(in_iter))->iters[__npy_mi]
)))->dataptr += (((PyArrayIterObject *)(((PyArrayMultiIterObject
*)(in_iter))->iters[__npy_mi])))->strides[0] - (((PyArrayIterObject
*)(((PyArrayMultiIterObject *)(in_iter))->iters[__npy_mi]
)))->backstrides[1]; } } while (0); } else { int __npy_i; for
(__npy_i=((PyArrayIterObject *)(((PyArrayMultiIterObject *)(
in_iter))->iters[__npy_mi]))->nd_m1; __npy_i >= 0; __npy_i
--) { if (((PyArrayIterObject *)(((PyArrayMultiIterObject *)(
in_iter))->iters[__npy_mi]))->coordinates[__npy_i] <
((PyArrayIterObject *)(((PyArrayMultiIterObject *)(in_iter))
->iters[__npy_mi]))->dims_m1[__npy_i]) { ((PyArrayIterObject
*)(((PyArrayMultiIterObject *)(in_iter))->iters[__npy_mi]
))->coordinates[__npy_i]++; ((PyArrayIterObject *)(((PyArrayMultiIterObject
*)(in_iter))->iters[__npy_mi]))->dataptr += ((PyArrayIterObject
*)(((PyArrayMultiIterObject *)(in_iter))->iters[__npy_mi]
))->strides[__npy_i]; break; } else { ((PyArrayIterObject *
)(((PyArrayMultiIterObject *)(in_iter))->iters[__npy_mi]))
->coordinates[__npy_i] = 0; ((PyArrayIterObject *)(((PyArrayMultiIterObject
*)(in_iter))->iters[__npy_mi]))->dataptr -= ((PyArrayIterObject
*)(((PyArrayMultiIterObject *)(in_iter))->iters[__npy_mi]
))->backstrides[__npy_i]; } } } } while (0); } } while (0)
;
3842 PyArray_ITER_NEXT(out_iter)do { ((PyArrayIterObject *)(out_iter))->index++; if (((PyArrayIterObject
*)(out_iter))->nd_m1 == 0) { do { (((PyArrayIterObject *)
(out_iter)))->dataptr += ((PyArrayIterObject *)(((PyArrayIterObject
*)(out_iter))))->strides[0]; (((PyArrayIterObject *)(out_iter
)))->coordinates[0]++; } while (0); } else if (((PyArrayIterObject
*)(out_iter))->contiguous) ((PyArrayIterObject *)(out_iter
))->dataptr += PyArray_DESCR(((PyArrayIterObject *)(out_iter
))->ao)->elsize; else if (((PyArrayIterObject *)(out_iter
))->nd_m1 == 1) { do { if ((((PyArrayIterObject *)(out_iter
)))->coordinates[1] < (((PyArrayIterObject *)(out_iter)
))->dims_m1[1]) { (((PyArrayIterObject *)(out_iter)))->
coordinates[1]++; (((PyArrayIterObject *)(out_iter)))->dataptr
+= (((PyArrayIterObject *)(out_iter)))->strides[1]; } else
{ (((PyArrayIterObject *)(out_iter)))->coordinates[1] = 0
; (((PyArrayIterObject *)(out_iter)))->coordinates[0]++; (
((PyArrayIterObject *)(out_iter)))->dataptr += (((PyArrayIterObject
*)(out_iter)))->strides[0] - (((PyArrayIterObject *)(out_iter
)))->backstrides[1]; } } while (0); } else { int __npy_i; for
(__npy_i=((PyArrayIterObject *)(out_iter))->nd_m1; __npy_i
>= 0; __npy_i--) { if (((PyArrayIterObject *)(out_iter))->
coordinates[__npy_i] < ((PyArrayIterObject *)(out_iter))->
dims_m1[__npy_i]) { ((PyArrayIterObject *)(out_iter))->coordinates
[__npy_i]++; ((PyArrayIterObject *)(out_iter))->dataptr +=
((PyArrayIterObject *)(out_iter))->strides[__npy_i]; break
; } else { ((PyArrayIterObject *)(out_iter))->coordinates[
__npy_i] = 0; ((PyArrayIterObject *)(out_iter))->dataptr -=
((PyArrayIterObject *)(out_iter))->backstrides[__npy_i]; }
} } } while (0)
;
3843 }
3844
3845 Py_DECREF(in_iter)_Py_DECREF(((PyObject*)(in_iter)));
3846 Py_DECREF(out_iter)_Py_DECREF(((PyObject*)(out_iter)));
3847
3848 return (PyObject*)result;
3849
3850 err:
3851 Py_XDECREF(in_iter)_Py_XDECREF(((PyObject*)(in_iter)));
3852 Py_XDECREF(out_iter)_Py_XDECREF(((PyObject*)(out_iter)));
3853 Py_XDECREF(result)_Py_XDECREF(((PyObject*)(result)));
3854
3855 return 0;
3856}
3857
3858static PyObject *
3859_vec_string_no_args(PyArrayObject* char_array,
3860 PyArray_Descr* type, PyObject* method)
3861{
3862 /*
3863 * This is a faster version of _vec_string_args to use when there
3864 * are no additional arguments to the string method. This doesn't
3865 * require a broadcast iterator (and broadcast iterators don't work
3866 * with 1 argument anyway).
3867 */
3868 PyArrayIterObject* in_iter = NULL((void*)0);
3869 PyArrayObject* result = NULL((void*)0);
3870 PyArrayIterObject* out_iter = NULL((void*)0);
3871
3872 in_iter = (PyArrayIterObject*)PyArray_IterNew((PyObject*)char_array);
3873 if (in_iter == NULL((void*)0)) {
3874 Py_DECREF(type)_Py_DECREF(((PyObject*)(type)));
3875 goto err;
3876 }
3877
3878 result = (PyArrayObject*)PyArray_SimpleNewFromDescr(PyArray_NewFromDescr(&PyArray_Type, type, PyArray_NDIM(char_array
), PyArray_DIMS(char_array), ((void*)0), ((void*)0), 0, ((void
*)0))
3879 PyArray_NDIM(char_array), PyArray_DIMS(char_array), type)PyArray_NewFromDescr(&PyArray_Type, type, PyArray_NDIM(char_array
), PyArray_DIMS(char_array), ((void*)0), ((void*)0), 0, ((void
*)0))
;
3880 if (result == NULL((void*)0)) {
3881 goto err;
3882 }
3883
3884 out_iter = (PyArrayIterObject*)PyArray_IterNew((PyObject*)result);
3885 if (out_iter == NULL((void*)0)) {
3886 goto err;
3887 }
3888
3889 while (PyArray_ITER_NOTDONE(in_iter)(((PyArrayIterObject *)(in_iter))->index < ((PyArrayIterObject
*)(in_iter))->size)
) {
3890 PyObject* item_result;
3891 PyObject* item = PyArray_ToScalar(in_iter->dataptr, in_iter->ao)PyArray_Scalar(in_iter->dataptr, PyArray_DESCR(in_iter->
ao), (PyObject *)in_iter->ao)
;
3892 if (item == NULL((void*)0)) {
3893 goto err;
3894 }
3895
3896 item_result = PyObject_CallFunctionObjArgs(method, item, NULL((void*)0));
3897 Py_DECREF(item)_Py_DECREF(((PyObject*)(item)));
3898 if (item_result == NULL((void*)0)) {
3899 goto err;
3900 }
3901
3902 if (PyArray_SETITEM(result, PyArray_ITER_DATA(out_iter)((void *)(((PyArrayIterObject *)(out_iter))->dataptr)), item_result)) {
3903 Py_DECREF(item_result)_Py_DECREF(((PyObject*)(item_result)));
3904 PyErr_SetString( PyExc_TypeError,
3905 "result array type does not match underlying function");
3906 goto err;
3907 }
3908 Py_DECREF(item_result)_Py_DECREF(((PyObject*)(item_result)));
3909
3910 PyArray_ITER_NEXT(in_iter)do { ((PyArrayIterObject *)(in_iter))->index++; if (((PyArrayIterObject
*)(in_iter))->nd_m1 == 0) { do { (((PyArrayIterObject *)(
in_iter)))->dataptr += ((PyArrayIterObject *)(((PyArrayIterObject
*)(in_iter))))->strides[0]; (((PyArrayIterObject *)(in_iter
)))->coordinates[0]++; } while (0); } else if (((PyArrayIterObject
*)(in_iter))->contiguous) ((PyArrayIterObject *)(in_iter)
)->dataptr += PyArray_DESCR(((PyArrayIterObject *)(in_iter
))->ao)->elsize; else if (((PyArrayIterObject *)(in_iter
))->nd_m1 == 1) { do { if ((((PyArrayIterObject *)(in_iter
)))->coordinates[1] < (((PyArrayIterObject *)(in_iter))
)->dims_m1[1]) { (((PyArrayIterObject *)(in_iter)))->coordinates
[1]++; (((PyArrayIterObject *)(in_iter)))->dataptr += (((PyArrayIterObject
*)(in_iter)))->strides[1]; } else { (((PyArrayIterObject *
)(in_iter)))->coordinates[1] = 0; (((PyArrayIterObject *)(
in_iter)))->coordinates[0]++; (((PyArrayIterObject *)(in_iter
)))->dataptr += (((PyArrayIterObject *)(in_iter)))->strides
[0] - (((PyArrayIterObject *)(in_iter)))->backstrides[1]; }
} while (0); } else { int __npy_i; for (__npy_i=((PyArrayIterObject
*)(in_iter))->nd_m1; __npy_i >= 0; __npy_i--) { if (((
PyArrayIterObject *)(in_iter))->coordinates[__npy_i] < (
(PyArrayIterObject *)(in_iter))->dims_m1[__npy_i]) { ((PyArrayIterObject
*)(in_iter))->coordinates[__npy_i]++; ((PyArrayIterObject
*)(in_iter))->dataptr += ((PyArrayIterObject *)(in_iter))
->strides[__npy_i]; break; } else { ((PyArrayIterObject *)
(in_iter))->coordinates[__npy_i] = 0; ((PyArrayIterObject *
)(in_iter))->dataptr -= ((PyArrayIterObject *)(in_iter))->
backstrides[__npy_i]; } } } } while (0)
;
3911 PyArray_ITER_NEXT(out_iter)do { ((PyArrayIterObject *)(out_iter))->index++; if (((PyArrayIterObject
*)(out_iter))->nd_m1 == 0) { do { (((PyArrayIterObject *)
(out_iter)))->dataptr += ((PyArrayIterObject *)(((PyArrayIterObject
*)(out_iter))))->strides[0]; (((PyArrayIterObject *)(out_iter
)))->coordinates[0]++; } while (0); } else if (((PyArrayIterObject
*)(out_iter))->contiguous) ((PyArrayIterObject *)(out_iter
))->dataptr += PyArray_DESCR(((PyArrayIterObject *)(out_iter
))->ao)->elsize; else if (((PyArrayIterObject *)(out_iter
))->nd_m1 == 1) { do { if ((((PyArrayIterObject *)(out_iter
)))->coordinates[1] < (((PyArrayIterObject *)(out_iter)
))->dims_m1[1]) { (((PyArrayIterObject *)(out_iter)))->
coordinates[1]++; (((PyArrayIterObject *)(out_iter)))->dataptr
+= (((PyArrayIterObject *)(out_iter)))->strides[1]; } else
{ (((PyArrayIterObject *)(out_iter)))->coordinates[1] = 0
; (((PyArrayIterObject *)(out_iter)))->coordinates[0]++; (
((PyArrayIterObject *)(out_iter)))->dataptr += (((PyArrayIterObject
*)(out_iter)))->strides[0] - (((PyArrayIterObject *)(out_iter
)))->backstrides[1]; } } while (0); } else { int __npy_i; for
(__npy_i=((PyArrayIterObject *)(out_iter))->nd_m1; __npy_i
>= 0; __npy_i--) { if (((PyArrayIterObject *)(out_iter))->
coordinates[__npy_i] < ((PyArrayIterObject *)(out_iter))->
dims_m1[__npy_i]) { ((PyArrayIterObject *)(out_iter))->coordinates
[__npy_i]++; ((PyArrayIterObject *)(out_iter))->dataptr +=
((PyArrayIterObject *)(out_iter))->strides[__npy_i]; break
; } else { ((PyArrayIterObject *)(out_iter))->coordinates[
__npy_i] = 0; ((PyArrayIterObject *)(out_iter))->dataptr -=
((PyArrayIterObject *)(out_iter))->backstrides[__npy_i]; }
} } } while (0)
;
3912 }
3913
3914 Py_DECREF(in_iter)_Py_DECREF(((PyObject*)(in_iter)));
3915 Py_DECREF(out_iter)_Py_DECREF(((PyObject*)(out_iter)));
3916
3917 return (PyObject*)result;
3918
3919 err:
3920 Py_XDECREF(in_iter)_Py_XDECREF(((PyObject*)(in_iter)));
3921 Py_XDECREF(out_iter)_Py_XDECREF(((PyObject*)(out_iter)));
3922 Py_XDECREF(result)_Py_XDECREF(((PyObject*)(result)));
3923
3924 return 0;
3925}
3926
3927static PyObject *
3928_vec_string(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args, PyObject *NPY_UNUSED(kwds)(__NPY_UNUSED_TAGGEDkwds) __attribute__ ((__unused__)))
3929{
3930 PyArrayObject* char_array = NULL((void*)0);
3931 PyArray_Descr *type;
3932 PyObject* method_name;
3933 PyObject* args_seq = NULL((void*)0);
3934
3935 PyObject* method = NULL((void*)0);
3936 PyObject* result = NULL((void*)0);
3937
3938 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O&O&O|O",
3939 PyArray_Converter, &char_array,
3940 PyArray_DescrConverter, &type,
3941 &method_name, &args_seq)) {
3942 goto err;
3943 }
3944
3945 if (PyArray_TYPE(char_array) == NPY_STRING) {
3946 method = PyObject_GetAttr((PyObject *)&PyBytes_Type, method_name);
3947 }
3948 else if (PyArray_TYPE(char_array) == NPY_UNICODE) {
3949 method = PyObject_GetAttr((PyObject *)&PyUnicode_Type, method_name);
3950 }
3951 else {
3952 PyErr_SetString(PyExc_TypeError,
3953 "string operation on non-string array");
3954 Py_DECREF(type)_Py_DECREF(((PyObject*)(type)));
3955 goto err;
3956 }
3957 if (method == NULL((void*)0)) {
3958 Py_DECREF(type)_Py_DECREF(((PyObject*)(type)));
3959 goto err;
3960 }
3961
3962 if (args_seq == NULL((void*)0)
3963 || (PySequence_Check(args_seq) && PySequence_Size(args_seq) == 0)) {
3964 result = _vec_string_no_args(char_array, type, method);
3965 }
3966 else if (PySequence_Check(args_seq)) {
3967 result = _vec_string_with_args(char_array, type, method, args_seq);
3968 }
3969 else {
3970 Py_DECREF(type)_Py_DECREF(((PyObject*)(type)));
3971 PyErr_SetString(PyExc_TypeError,
3972 "'args' must be a sequence of arguments");
3973 goto err;
3974 }
3975 if (result == NULL((void*)0)) {
3976 goto err;
3977 }
3978
3979 Py_DECREF(char_array)_Py_DECREF(((PyObject*)(char_array)));
3980 Py_DECREF(method)_Py_DECREF(((PyObject*)(method)));
3981
3982 return (PyObject*)result;
3983
3984 err:
3985 Py_XDECREF(char_array)_Py_XDECREF(((PyObject*)(char_array)));
3986 Py_XDECREF(method)_Py_XDECREF(((PyObject*)(method)));
3987
3988 return 0;
3989}
3990
3991#ifndef __NPY_PRIVATE_NO_SIGNAL
3992
3993static NPY_TLS__thread int sigint_buf_init = 0;
3994static NPY_TLS__thread NPY_SIGJMP_BUFsigjmp_buf _NPY_SIGINT_BUF;
3995
3996/*NUMPY_API
3997 */
3998NPY_NO_EXPORT__attribute__((visibility("hidden"))) void
3999_PyArray_SigintHandler(int signum)
4000{
4001 PyOS_setsig(signum, SIG_IGN((__sighandler_t) 1));
4002 /*
4003 * jump buffer may be uninitialized as SIGINT allowing functions are usually
4004 * run in other threads than the master thread that receives the signal
4005 */
4006 if (sigint_buf_init > 0) {
4007 NPY_SIGLONGJMP(_NPY_SIGINT_BUF, signum)siglongjmp(_NPY_SIGINT_BUF, signum);
4008 }
4009 /*
4010 * sending SIGINT to the worker threads to cancel them is job of the
4011 * application
4012 */
4013}
4014
4015/*NUMPY_API
4016 */
4017NPY_NO_EXPORT__attribute__((visibility("hidden"))) void*
4018_PyArray_GetSigintBuf(void)
4019{
4020 sigint_buf_init = 1;
4021 return (void *)&_NPY_SIGINT_BUF;
4022}
4023
4024#else
4025
4026NPY_NO_EXPORT__attribute__((visibility("hidden"))) void
4027_PyArray_SigintHandler(int signum)
4028{
4029 return;
4030}
4031
4032NPY_NO_EXPORT__attribute__((visibility("hidden"))) void*
4033_PyArray_GetSigintBuf(void)
4034{
4035 return NULL((void*)0);
4036}
4037
4038#endif
4039
4040
4041static PyObject *
4042array_shares_memory_impl(PyObject *args, PyObject *kwds, Py_ssize_t default_max_work,
4043 int raise_exceptions)
4044{
4045 PyObject * self_obj = NULL((void*)0);
4046 PyObject * other_obj = NULL((void*)0);
4047 PyArrayObject * self = NULL((void*)0);
4048 PyArrayObject * other = NULL((void*)0);
4049 PyObject *max_work_obj = NULL((void*)0);
4050 static char *kwlist[] = {"self", "other", "max_work", NULL((void*)0)};
4051
4052 mem_overlap_t result;
4053 static PyObject *too_hard_cls = NULL((void*)0);
4054 Py_ssize_t max_work;
4055 NPY_BEGIN_THREADS_DEFPyThreadState *_save=((void*)0);;
4056
4057 max_work = default_max_work;
4058
4059 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "OO|O:shares_memory_impl", kwlist,
4060 &self_obj, &other_obj, &max_work_obj)) {
4061 return NULL((void*)0);
4062 }
4063
4064 if (PyArray_Check(self_obj)((((PyObject*)(self_obj))->ob_type) == (&PyArray_Type)
|| PyType_IsSubtype((((PyObject*)(self_obj))->ob_type), (
&PyArray_Type)))
) {
4065 self = (PyArrayObject*)self_obj;
4066 Py_INCREF(self)_Py_INCREF(((PyObject*)(self)));
4067 }
4068 else {
4069 /* Use FromAny to enable checking overlap for objects exposing array
4070 interfaces etc. */
4071 self = (PyArrayObject*)PyArray_FROM_O(self_obj)PyArray_FromAny(self_obj, ((void*)0), 0, 0, 0, ((void*)0));
4072 if (self == NULL((void*)0)) {
4073 goto fail;
4074 }
4075 }
4076
4077 if (PyArray_Check(other_obj)((((PyObject*)(other_obj))->ob_type) == (&PyArray_Type
) || PyType_IsSubtype((((PyObject*)(other_obj))->ob_type),
(&PyArray_Type)))
) {
4078 other = (PyArrayObject*)other_obj;
4079 Py_INCREF(other)_Py_INCREF(((PyObject*)(other)));
4080 }
4081 else {
4082 other = (PyArrayObject*)PyArray_FROM_O(other_obj)PyArray_FromAny(other_obj, ((void*)0), 0, 0, 0, ((void*)0));
4083 if (other == NULL((void*)0)) {
4084 goto fail;
4085 }
4086 }
4087
4088 if (max_work_obj == NULL((void*)0) || max_work_obj == Py_None(&_Py_NoneStruct)) {
4089 /* noop */
4090 }
4091 else if (PyLong_Check(max_work_obj)((((((PyObject*)(max_work_obj))->ob_type))->tp_flags &
((1UL << 24))) != 0)
) {
4092 max_work = PyLong_AsSsize_t(max_work_obj);
4093 if (PyErr_Occurred()) {
4094 goto fail;
4095 }
4096 }
4097 else {
4098 PyErr_SetString(PyExc_ValueError, "max_work must be an integer");
4099 goto fail;
4100 }
4101
4102 if (max_work < -2) {
4103 PyErr_SetString(PyExc_ValueError, "Invalid value for max_work");
4104 goto fail;
4105 }
4106
4107 NPY_BEGIN_THREADSdo {_save = PyEval_SaveThread();} while (0);;
4108 result = solve_may_share_memory(self, other, max_work);
4109 NPY_END_THREADSdo { if (_save) { PyEval_RestoreThread(_save); _save = ((void
*)0);} } while (0);
;
4110
4111 Py_XDECREF(self)_Py_XDECREF(((PyObject*)(self)));
4112 Py_XDECREF(other)_Py_XDECREF(((PyObject*)(other)));
4113
4114 if (result == MEM_OVERLAP_NO) {
4115 Py_RETURN_FALSEreturn _Py_INCREF(((PyObject*)(((PyObject *) &_Py_FalseStruct
)))), ((PyObject *) &_Py_FalseStruct)
;
4116 }
4117 else if (result == MEM_OVERLAP_YES) {
4118 Py_RETURN_TRUEreturn _Py_INCREF(((PyObject*)(((PyObject *) &_Py_TrueStruct
)))), ((PyObject *) &_Py_TrueStruct)
;
4119 }
4120 else if (result == MEM_OVERLAP_OVERFLOW) {
4121 if (raise_exceptions) {
4122 PyErr_SetString(PyExc_OverflowError,
4123 "Integer overflow in computing overlap");
4124 return NULL((void*)0);
4125 }
4126 else {
4127 /* Don't know, so say yes */
4128 Py_RETURN_TRUEreturn _Py_INCREF(((PyObject*)(((PyObject *) &_Py_TrueStruct
)))), ((PyObject *) &_Py_TrueStruct)
;
4129 }
4130 }
4131 else if (result == MEM_OVERLAP_TOO_HARD) {
4132 if (raise_exceptions) {
4133 npy_cache_import("numpy.core._exceptions", "TooHardError",
4134 &too_hard_cls);
4135 if (too_hard_cls) {
4136 PyErr_SetString(too_hard_cls, "Exceeded max_work");
4137 }
4138 return NULL((void*)0);
4139 }
4140 else {
4141 /* Don't know, so say yes */
4142 Py_RETURN_TRUEreturn _Py_INCREF(((PyObject*)(((PyObject *) &_Py_TrueStruct
)))), ((PyObject *) &_Py_TrueStruct)
;
4143 }
4144 }
4145 else {
4146 /* Doesn't happen usually */
4147 PyErr_SetString(PyExc_RuntimeError,
4148 "Error in computing overlap");
4149 return NULL((void*)0);
4150 }
4151
4152fail:
4153 Py_XDECREF(self)_Py_XDECREF(((PyObject*)(self)));
4154 Py_XDECREF(other)_Py_XDECREF(((PyObject*)(other)));
4155 return NULL((void*)0);
4156}
4157
4158
4159static PyObject *
4160array_shares_memory(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
4161{
4162 return array_shares_memory_impl(args, kwds, NPY_MAY_SHARE_EXACT-1, 1);
4163}
4164
4165
4166static PyObject *
4167array_may_share_memory(PyObject *NPY_UNUSED(ignored)(__NPY_UNUSED_TAGGEDignored) __attribute__ ((__unused__)), PyObject *args, PyObject *kwds)
4168{
4169 return array_shares_memory_impl(args, kwds, NPY_MAY_SHARE_BOUNDS0, 0);
4170}
4171
4172static PyObject *
4173normalize_axis_index(PyObject *NPY_UNUSED(self)(__NPY_UNUSED_TAGGEDself) __attribute__ ((__unused__)),
4174 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
4175{
4176 int axis;
4177 int ndim;
4178 PyObject *msg_prefix = Py_None(&_Py_NoneStruct);
4179 NPY_PREPARE_ARGPARSERstatic _NpyArgParserCache __argparse_cache = {-1};
4180
4181 if (npy_parse_arguments("normalize_axis_index", args, len_args, kwnames,_npy_parse_arguments("normalize_axis_index", &__argparse_cache
, args, len_args, kwnames, "axis", &PyArray_PythonPyIntFromInt
, &axis, "ndim", &PyArray_PythonPyIntFromInt, &ndim
, "|msg_prefix", ((void*)0), &msg_prefix, ((void*)0), ((void
*)0), ((void*)0))
4182 "axis", &PyArray_PythonPyIntFromInt, &axis,_npy_parse_arguments("normalize_axis_index", &__argparse_cache
, args, len_args, kwnames, "axis", &PyArray_PythonPyIntFromInt
, &axis, "ndim", &PyArray_PythonPyIntFromInt, &ndim
, "|msg_prefix", ((void*)0), &msg_prefix, ((void*)0), ((void
*)0), ((void*)0))
4183 "ndim", &PyArray_PythonPyIntFromInt, &ndim,_npy_parse_arguments("normalize_axis_index", &__argparse_cache
, args, len_args, kwnames, "axis", &PyArray_PythonPyIntFromInt
, &axis, "ndim", &PyArray_PythonPyIntFromInt, &ndim
, "|msg_prefix", ((void*)0), &msg_prefix, ((void*)0), ((void
*)0), ((void*)0))
4184 "|msg_prefix", NULL, &msg_prefix,_npy_parse_arguments("normalize_axis_index", &__argparse_cache
, args, len_args, kwnames, "axis", &PyArray_PythonPyIntFromInt
, &axis, "ndim", &PyArray_PythonPyIntFromInt, &ndim
, "|msg_prefix", ((void*)0), &msg_prefix, ((void*)0), ((void
*)0), ((void*)0))
4185 NULL, NULL, NULL)_npy_parse_arguments("normalize_axis_index", &__argparse_cache
, args, len_args, kwnames, "axis", &PyArray_PythonPyIntFromInt
, &axis, "ndim", &PyArray_PythonPyIntFromInt, &ndim
, "|msg_prefix", ((void*)0), &msg_prefix, ((void*)0), ((void
*)0), ((void*)0))
< 0) {
4186 return NULL((void*)0);
4187 }
4188 if (check_and_adjust_axis_msg(&axis, ndim, msg_prefix) < 0) {
4189 return NULL((void*)0);
4190 }
4191
4192 return PyLong_FromLong(axis);
4193}
4194
4195
4196static PyObject *
4197_reload_guard(PyObject *NPY_UNUSED(self)(__NPY_UNUSED_TAGGEDself) __attribute__ ((__unused__))) {
4198 static int initialized = 0;
4199
4200#if !defined(PYPY_VERSION)
4201 if (PyThreadState_Get()->interp != PyInterpreterState_Main()) {
4202 if (PyErr_WarnEx(PyExc_UserWarning,
4203 "NumPy was imported from a Python sub-interpreter but "
4204 "NumPy does not properly support sub-interpreters. "
4205 "This will likely work for most users but might cause hard to "
4206 "track down issues or subtle bugs. "
4207 "A common user of the rare sub-interpreter feature is wsgi "
4208 "which also allows single-interpreter mode.\n"
4209 "Improvements in the case of bugs are welcome, but is not "
4210 "on the NumPy roadmap, and full support may require "
4211 "significant effort to achieve.", 2) < 0) {
4212 return NULL((void*)0);
4213 }
4214 /* No need to give the other warning in a sub-interpreter as well... */
4215 initialized = 1;
4216 Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (&
_Py_NoneStruct)
;
4217 }
4218#endif
4219 if (initialized) {
4220 if (PyErr_WarnEx(PyExc_UserWarning,
4221 "The NumPy module was reloaded (imported a second time). "
4222 "This can in some cases result in small but subtle issues "
4223 "and is discouraged.", 2) < 0) {
4224 return NULL((void*)0);
4225 }
4226 }
4227 initialized = 1;
4228 Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (&
_Py_NoneStruct)
;
4229}
4230
4231
4232static struct PyMethodDef array_module_methods[] = {
4233 {"_get_implementing_args",
4234 (PyCFunction)array__get_implementing_args,
4235 METH_VARARGS0x0001, NULL((void*)0)},
4236 {"_get_ndarray_c_version",
4237 (PyCFunction)array__get_ndarray_c_version,
4238 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4239 {"_reconstruct",
4240 (PyCFunction)array__reconstruct,
4241 METH_VARARGS0x0001, NULL((void*)0)},
4242 {"set_string_function",
4243 (PyCFunction)array_set_string_function,
4244 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4245 {"set_numeric_ops",
4246 (PyCFunction)array_set_ops_function,
4247 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4248 {"set_datetimeparse_function",
4249 (PyCFunction)array_set_datetimeparse_function,
4250 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4251 {"set_typeDict",
4252 (PyCFunction)array_set_typeDict,
4253 METH_VARARGS0x0001, NULL((void*)0)},
4254 {"array",
4255 (PyCFunction)array_array,
4256 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4257 {"asarray",
4258 (PyCFunction)array_asarray,
4259 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4260 {"asanyarray",
4261 (PyCFunction)array_asanyarray,
4262 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4263 {"ascontiguousarray",
4264 (PyCFunction)array_ascontiguousarray,
4265 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4266 {"asfortranarray",
4267 (PyCFunction)array_asfortranarray,
4268 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4269 {"copyto",
4270 (PyCFunction)array_copyto,
4271 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4272 {"nested_iters",
4273 (PyCFunction)NpyIter_NestedIters,
4274 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4275 {"arange",
4276 (PyCFunction)array_arange,
4277 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4278 {"zeros",
4279 (PyCFunction)array_zeros,
4280 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4281 {"count_nonzero",
4282 (PyCFunction)array_count_nonzero,
4283 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4284 {"empty",
4285 (PyCFunction)array_empty,
4286 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4287 {"empty_like",
4288 (PyCFunction)array_empty_like,
4289 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4290 {"scalar",
4291 (PyCFunction)array_scalar,
4292 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4293 {"where",
4294 (PyCFunction)array_where,
4295 METH_VARARGS0x0001, NULL((void*)0)},
4296 {"lexsort",
4297 (PyCFunction)array_lexsort,
4298 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4299 {"putmask",
4300 (PyCFunction)array_putmask,
4301 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4302 {"fromstring",
4303 (PyCFunction)array_fromstring,
4304 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4305 {"fromiter",
4306 (PyCFunction)array_fromiter,
4307 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4308 {"concatenate",
4309 (PyCFunction)array_concatenate,
4310 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4311 {"inner",
4312 (PyCFunction)array_innerproduct,
4313 METH_VARARGS0x0001, NULL((void*)0)},
4314 {"dot",
4315 (PyCFunction)array_matrixproduct,
4316 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4317 {"vdot",
4318 (PyCFunction)array_vdot,
4319 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4320 {"c_einsum",
4321 (PyCFunction)array_einsum,
4322 METH_VARARGS0x0001|METH_KEYWORDS0x0002, NULL((void*)0)},
4323 {"_fastCopyAndTranspose",
4324 (PyCFunction)array_fastCopyAndTranspose,
4325 METH_VARARGS0x0001, NULL((void*)0)},
4326 {"correlate",
4327 (PyCFunction)array_correlate,
4328 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4329 {"correlate2",
4330 (PyCFunction)array_correlate2,
4331 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4332 {"frombuffer",
4333 (PyCFunction)array_frombuffer,
4334 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4335 {"fromfile",
4336 (PyCFunction)array_fromfile,
4337 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4338 {"can_cast",
4339 (PyCFunction)array_can_cast_safely,
4340 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4341 {"promote_types",
4342 (PyCFunction)array_promote_types,
4343 METH_VARARGS0x0001, NULL((void*)0)},
4344 {"min_scalar_type",
4345 (PyCFunction)array_min_scalar_type,
4346 METH_VARARGS0x0001, NULL((void*)0)},
4347 {"result_type",
4348 (PyCFunction)array_result_type,
4349 METH_VARARGS0x0001, NULL((void*)0)},
4350 {"shares_memory",
4351 (PyCFunction)array_shares_memory,
4352 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4353 {"may_share_memory",
4354 (PyCFunction)array_may_share_memory,
4355 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4356 /* Datetime-related functions */
4357 {"datetime_data",
4358 (PyCFunction)array_datetime_data,
4359 METH_VARARGS0x0001, NULL((void*)0)},
4360 {"datetime_as_string",
4361 (PyCFunction)array_datetime_as_string,
4362 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4363 /* Datetime business-day API */
4364 {"busday_offset",
4365 (PyCFunction)array_busday_offset,
4366 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4367 {"busday_count",
4368 (PyCFunction)array_busday_count,
4369 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4370 {"is_busday",
4371 (PyCFunction)array_is_busday,
4372 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4373 {"format_longfloat",
4374 (PyCFunction)format_longfloat,
4375 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4376 {"dragon4_positional",
4377 (PyCFunction)dragon4_positional,
4378 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4379 {"dragon4_scientific",
4380 (PyCFunction)dragon4_scientific,
4381 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4382 {"compare_chararrays",
4383 (PyCFunction)compare_chararrays,
4384 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4385 {"_vec_string",
4386 (PyCFunction)_vec_string,
4387 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4388 {"_insert", (PyCFunction)arr_insert,
4389 METH_VARARGS0x0001 | METH_KEYWORDS0x0002,
4390 "Insert vals sequentially into equivalent 1-d positions "
4391 "indicated by mask."},
4392 {"bincount", (PyCFunction)arr_bincount,
4393 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4394 {"_monotonicity", (PyCFunction)arr__monotonicity,
4395 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4396 {"implement_array_function",
4397 (PyCFunction)array_implement_array_function,
4398 METH_VARARGS0x0001, NULL((void*)0)},
4399 {"interp", (PyCFunction)arr_interp,
4400 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4401 {"interp_complex", (PyCFunction)arr_interp_complex,
4402 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4403 {"ravel_multi_index", (PyCFunction)arr_ravel_multi_index,
4404 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4405 {"unravel_index", (PyCFunction)arr_unravel_index,
4406 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4407 {"add_docstring", (PyCFunction)arr_add_docstring,
4408 METH_VARARGS0x0001, NULL((void*)0)},
4409 {"packbits", (PyCFunction)io_pack,
4410 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4411 {"unpackbits", (PyCFunction)io_unpack,
4412 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4413 {"normalize_axis_index", (PyCFunction)normalize_axis_index,
4414 METH_FASTCALL0x0080 | METH_KEYWORDS0x0002, NULL((void*)0)},
4415 {"set_legacy_print_mode", (PyCFunction)set_legacy_print_mode,
4416 METH_VARARGS0x0001, NULL((void*)0)},
4417 {"_discover_array_parameters", (PyCFunction)_discover_array_parameters,
4418 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4419 {"_get_castingimpl", (PyCFunction)_get_castingimpl,
4420 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4421 /* from umath */
4422 {"frompyfunc",
4423 (PyCFunction) ufunc_frompyfunc,
4424 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
4425 {"seterrobj",
4426 (PyCFunction) ufunc_seterr,
4427 METH_VARARGS0x0001, NULL((void*)0)},
4428 {"geterrobj",
4429 (PyCFunction) ufunc_geterr,
4430 METH_VARARGS0x0001, NULL((void*)0)},
4431 {"_add_newdoc_ufunc", (PyCFunction)add_newdoc_ufunc,
4432 METH_VARARGS0x0001, NULL((void*)0)},
4433 {"_set_madvise_hugepage", (PyCFunction)_set_madvise_hugepage,
4434 METH_O0x0008, NULL((void*)0)},
4435 {"_reload_guard", (PyCFunction)_reload_guard,
4436 METH_NOARGS0x0004,
4437 "Give a warning on reload and big warning in sub-interpreters."},
4438 {NULL((void*)0), NULL((void*)0), 0, NULL((void*)0)} /* sentinel */
4439};
4440
4441#include "__multiarray_api.c"
4442#include "array_method.h"
4443
4444/* Establish scalar-type hierarchy
4445 *
4446 * For dual inheritance we need to make sure that the objects being
4447 * inherited from have the tp->mro object initialized. This is
4448 * not necessarily true for the basic type objects of Python (it is
4449 * checked for single inheritance but not dual in PyType_Ready).
4450 *
4451 * Thus, we call PyType_Ready on the standard Python Types, here.
4452 */
4453static int
4454setup_scalartypes(PyObject *NPY_UNUSED(dict)(__NPY_UNUSED_TAGGEDdict) __attribute__ ((__unused__)))
4455{
4456 if (PyType_Ready(&PyBool_Type) < 0) {
4457 return -1;
4458 }
4459 if (PyType_Ready(&PyFloat_Type) < 0) {
4460 return -1;
4461 }
4462 if (PyType_Ready(&PyComplex_Type) < 0) {
4463 return -1;
4464 }
4465 if (PyType_Ready(&PyBytes_Type) < 0) {
4466 return -1;
4467 }
4468 if (PyType_Ready(&PyUnicode_Type) < 0) {
4469 return -1;
4470 }
4471
4472#define SINGLE_INHERIT(child, parent) \
4473 Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type; \
4474 if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \
4475 PyErr_Print(); \
4476 PyErr_Format(PyExc_SystemError, \
4477 "could not initialize Py%sArrType_Type", \
4478 #child); \
4479 return -1; \
4480 }
4481
4482 if (PyType_Ready(&PyGenericArrType_Type) < 0) {
4483 return -1;
4484 }
4485 SINGLE_INHERIT(Number, Generic);
4486 SINGLE_INHERIT(Integer, Number);
4487 SINGLE_INHERIT(Inexact, Number);
4488 SINGLE_INHERIT(SignedInteger, Integer);
4489 SINGLE_INHERIT(UnsignedInteger, Integer);
4490 SINGLE_INHERIT(Floating, Inexact);
4491 SINGLE_INHERIT(ComplexFloating, Inexact);
4492 SINGLE_INHERIT(Flexible, Generic);
4493 SINGLE_INHERIT(Character, Flexible);
4494
4495#define DUAL_INHERIT(child, parent1, parent2) \
4496 Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type; \
4497 Py##child##ArrType_Type.tp_bases = \
4498 Py_BuildValue_Py_BuildValue_SizeT("(OO)", &Py##parent2##ArrType_Type, \
4499 &Py##parent1##_Type); \
4500 Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash; \
4501 if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \
4502 PyErr_Print(); \
4503 PyErr_Format(PyExc_SystemError, \
4504 "could not initialize Py%sArrType_Type", \
4505 #child); \
4506 return -1; \
4507 }
4508
4509#define DUAL_INHERIT2(child, parent1, parent2) \
4510 Py##child##ArrType_Type.tp_base = &Py##parent1##_Type; \
4511 Py##child##ArrType_Type.tp_bases = \
4512 Py_BuildValue_Py_BuildValue_SizeT("(OO)", &Py##parent1##_Type, \
4513 &Py##parent2##ArrType_Type); \
4514 Py##child##ArrType_Type.tp_richcompare = \
4515 Py##parent1##_Type.tp_richcompare; \
4516 Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash; \
4517 if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \
4518 PyErr_Print(); \
4519 PyErr_Format(PyExc_SystemError, \
4520 "could not initialize Py%sArrType_Type", \
4521 #child); \
4522 return -1; \
4523 }
4524
4525 SINGLE_INHERIT(Bool, Generic);
4526 SINGLE_INHERIT(Byte, SignedInteger);
4527 SINGLE_INHERIT(Short, SignedInteger);
4528 SINGLE_INHERIT(Int, SignedInteger);
4529 SINGLE_INHERIT(Long, SignedInteger);
4530 SINGLE_INHERIT(LongLong, SignedInteger);
4531
4532 /* Datetime doesn't fit in any category */
4533 SINGLE_INHERIT(Datetime, Generic);
4534 /* Timedelta is an integer with an associated unit */
4535 SINGLE_INHERIT(Timedelta, SignedInteger);
4536
4537 SINGLE_INHERIT(UByte, UnsignedInteger);
4538 SINGLE_INHERIT(UShort, UnsignedInteger);
4539 SINGLE_INHERIT(UInt, UnsignedInteger);
4540 SINGLE_INHERIT(ULong, UnsignedInteger);
4541 SINGLE_INHERIT(ULongLong, UnsignedInteger);
4542
4543 SINGLE_INHERIT(Half, Floating);
4544 SINGLE_INHERIT(Float, Floating);
4545 DUAL_INHERIT(Double, Float, Floating);
4546 SINGLE_INHERIT(LongDouble, Floating);
4547
4548 SINGLE_INHERIT(CFloat, ComplexFloating);
4549 DUAL_INHERIT(CDouble, Complex, ComplexFloating);
4550 SINGLE_INHERIT(CLongDouble, ComplexFloating);
4551
4552 DUAL_INHERIT2(String, String, Character);
4553 DUAL_INHERIT2(Unicode, Unicode, Character);
4554
4555 SINGLE_INHERIT(Void, Flexible);
4556
4557 SINGLE_INHERIT(Object, Generic);
4558
4559 return 0;
4560
4561#undef SINGLE_INHERIT
4562#undef DUAL_INHERIT
4563#undef DUAL_INHERIT2
4564
4565 /*
4566 * Clean up string and unicode array types so they act more like
4567 * strings -- get their tables from the standard types.
4568 */
4569}
4570
4571/* place a flag dictionary in d */
4572
4573static void
4574set_flaginfo(PyObject *d)
4575{
4576 PyObject *s;
4577 PyObject *newd;
4578
4579 newd = PyDict_New();
4580
4581#define _addnew(key, val, one) \
4582 PyDict_SetItemString(newd, #key, s=PyLong_FromLong(val)); \
4583 Py_DECREF(s)_Py_DECREF(((PyObject*)(s))); \
4584 PyDict_SetItemString(newd, #one, s=PyLong_FromLong(val)); \
4585 Py_DECREF(s)_Py_DECREF(((PyObject*)(s)))
4586
4587#define _addone(key, val) \
4588 PyDict_SetItemString(newd, #key, s=PyLong_FromLong(val)); \
4589 Py_DECREF(s)_Py_DECREF(((PyObject*)(s)))
4590
4591 _addnew(OWNDATA, NPY_ARRAY_OWNDATA0x0004, O);
4592 _addnew(FORTRAN, NPY_ARRAY_F_CONTIGUOUS0x0002, F);
4593 _addnew(CONTIGUOUS, NPY_ARRAY_C_CONTIGUOUS0x0001, C);
4594 _addnew(ALIGNED, NPY_ARRAY_ALIGNED0x0100, A);
4595 _addnew(UPDATEIFCOPY, NPY_ARRAY_UPDATEIFCOPY0x1000, U);
4596 _addnew(WRITEBACKIFCOPY, NPY_ARRAY_WRITEBACKIFCOPY0x2000, X);
4597 _addnew(WRITEABLE, NPY_ARRAY_WRITEABLE0x0400, W);
4598 _addone(C_CONTIGUOUS, NPY_ARRAY_C_CONTIGUOUS0x0001);
4599 _addone(F_CONTIGUOUS, NPY_ARRAY_F_CONTIGUOUS0x0002);
4600
4601#undef _addone
4602#undef _addnew
4603
4604 PyDict_SetItemString(d, "_flagdict", newd);
4605 Py_DECREF(newd)_Py_DECREF(((PyObject*)(newd)));
4606 return;
4607}
4608
4609NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_array = NULL((void*)0);
4610NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_array_prepare = NULL((void*)0);
4611NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_array_wrap = NULL((void*)0);
4612NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_array_finalize = NULL((void*)0);
4613NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_ufunc = NULL((void*)0);
4614NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_implementation = NULL((void*)0);
4615NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_order = NULL((void*)0);
4616NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_copy = NULL((void*)0);
4617NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_dtype = NULL((void*)0);
4618NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_ndmin = NULL((void*)0);
4619NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_axis1 = NULL((void*)0);
4620NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_axis2 = NULL((void*)0);
4621NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_like = NULL((void*)0);
4622NPY_VISIBILITY_HIDDEN__attribute__((visibility("hidden"))) PyObject * npy_ma_str_numpy = NULL((void*)0);
4623
4624static int
4625intern_strings(void)
4626{
4627 npy_ma_str_array = PyUnicode_InternFromString("__array__");
4628 npy_ma_str_array_prepare = PyUnicode_InternFromString("__array_prepare__");
4629 npy_ma_str_array_wrap = PyUnicode_InternFromString("__array_wrap__");
4630 npy_ma_str_array_finalize = PyUnicode_InternFromString("__array_finalize__");
4631 npy_ma_str_ufunc = PyUnicode_InternFromString("__array_ufunc__");
4632 npy_ma_str_implementation = PyUnicode_InternFromString("_implementation");
4633 npy_ma_str_order = PyUnicode_InternFromString("order");
4634 npy_ma_str_copy = PyUnicode_InternFromString("copy");
4635 npy_ma_str_dtype = PyUnicode_InternFromString("dtype");
4636 npy_ma_str_ndmin = PyUnicode_InternFromString("ndmin");
4637 npy_ma_str_axis1 = PyUnicode_InternFromString("axis1");
4638 npy_ma_str_axis2 = PyUnicode_InternFromString("axis2");
4639 npy_ma_str_like = PyUnicode_InternFromString("like");
4640 npy_ma_str_numpy = PyUnicode_InternFromString("numpy");
4641
4642 return npy_ma_str_array && npy_ma_str_array_prepare &&
4643 npy_ma_str_array_wrap && npy_ma_str_array_finalize &&
4644 npy_ma_str_ufunc && npy_ma_str_implementation &&
4645 npy_ma_str_order && npy_ma_str_copy && npy_ma_str_dtype &&
4646 npy_ma_str_ndmin && npy_ma_str_axis1 && npy_ma_str_axis2 &&
4647 npy_ma_str_like && npy_ma_str_numpy;
4648}
4649
4650static struct PyModuleDef moduledef = {
4651 PyModuleDef_HEAD_INIT{ { 1, ((void*)0) }, ((void*)0), 0, ((void*)0), },
4652 "_multiarray_umath",
4653 NULL((void*)0),
4654 -1,
4655 array_module_methods,
4656 NULL((void*)0),
4657 NULL((void*)0),
4658 NULL((void*)0),
4659 NULL((void*)0)
4660};
4661
4662/* Initialization function for the module */
4663PyMODINIT_FUNCPyObject* PyInit__multiarray_umath(void) {
4664 PyObject *m, *d, *s;
4665 PyObject *c_api;
4666
4667 /* Initialize CPU features */
4668 if (npy_cpu_init() < 0) {
1
Taking false branch
4669 goto err;
4670 }
4671
4672 /* Create the module and add the functions */
4673 m = PyModule_Create(&moduledef)PyModule_Create2(&moduledef, 1013);
2
Calling 'PyModule_Create2'
4
Returning from 'PyModule_Create2'
10
PyObject ownership leak with reference count of 1
4674 if (!m) {
5
Assuming 'm' is non-null
6
Taking false branch
4675 goto err;
4676 }
4677
4678#if defined(MS_WIN64) && defined(__GNUC__4)
4679 PyErr_WarnEx(PyExc_Warning,
4680 "Numpy built with MINGW-W64 on Windows 64 bits is experimental, " \
4681 "and only available for \n" \
4682 "testing. You are advised not to use it for production. \n\n" \
4683 "CRASHES ARE TO BE EXPECTED - PLEASE REPORT THEM TO NUMPY DEVELOPERS",
4684 1);
4685#endif
4686
4687 /* Initialize access to the PyDateTime API */
4688 numpy_pydatetime_import();
4689
4690 if (PyErr_Occurred()) {
7
Assuming the condition is true
8
Taking true branch
4691 goto err;
9
Control jumps to line 4906
4692 }
4693
4694 /* Add some symbolic constants to the module */
4695 d = PyModule_GetDict(m);
4696 if (!d) {
4697 goto err;
4698 }
4699
4700 if (PyType_Ready(&PyUFunc_Type) < 0) {
4701 goto err;
4702 }
4703
4704 /* Load the ufunc operators into the array module's namespace */
4705 if (InitOperators(d) < 0) {
4706 goto err;
4707 }
4708
4709 if (set_matmul_flags(d) < 0) {
4710 goto err;
4711 }
4712
4713 PyArrayDTypeMeta_Type.tp_base = &PyType_Type;
4714 if (PyType_Ready(&PyArrayDTypeMeta_Type) < 0) {
4715 goto err;
4716 }
4717
4718 PyArrayDescr_Type(*(PyTypeObject *)(&PyArrayDescr_TypeFull)).tp_hash = PyArray_DescrHash;
4719 Py_SET_TYPE(&PyArrayDescr_Type, &PyArrayDTypeMeta_Type)(((((PyObject*)(&(*(PyTypeObject *)(&PyArrayDescr_TypeFull
))))->ob_type) = (&PyArrayDTypeMeta_Type)), (void)0)
;
4720 if (PyType_Ready(&PyArrayDescr_Type(*(PyTypeObject *)(&PyArrayDescr_TypeFull))) < 0) {
4721 goto err;
4722 }
4723
4724 initialize_casting_tables();
4725 initialize_numeric_types();
4726 if (initscalarmath(m) < 0) {
4727 goto err;
4728 }
4729
4730 if (PyType_Ready(&PyArray_Type) < 0) {
4731 goto err;
4732 }
4733 if (setup_scalartypes(d) < 0) {
4734 goto err;
4735 }
4736 PyArrayIter_Type.tp_iter = PyObject_SelfIter;
4737 NpyIter_Type.tp_iter = PyObject_SelfIter;
4738 PyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;
4739 PyArrayMultiIter_Type.tp_free = PyArray_freePyMem_RawFree;
4740 if (PyType_Ready(&PyArrayIter_Type) < 0) {
4741 goto err;
4742 }
4743 if (PyType_Ready(&PyArrayMapIter_Type) < 0) {
4744 goto err;
4745 }
4746 if (PyType_Ready(&PyArrayMultiIter_Type) < 0) {
4747 goto err;
4748 }
4749 PyArrayNeighborhoodIter_Type.tp_new = PyType_GenericNew;
4750 if (PyType_Ready(&PyArrayNeighborhoodIter_Type) < 0) {
4751 goto err;
4752 }
4753 if (PyType_Ready(&NpyIter_Type) < 0) {
4754 goto err;
4755 }
4756
4757 if (PyType_Ready(&PyArrayFlags_Type) < 0) {
4758 goto err;
4759 }
4760 NpyBusDayCalendar_Type.tp_new = PyType_GenericNew;
4761 if (PyType_Ready(&NpyBusDayCalendar_Type) < 0) {
4762 goto err;
4763 }
4764
4765 c_api = PyCapsule_New((void *)PyArray_API, NULL((void*)0), NULL((void*)0));
4766 if (c_api == NULL((void*)0)) {
4767 goto err;
4768 }
4769 PyDict_SetItemString(d, "_ARRAY_API", c_api);
4770 Py_DECREF(c_api)_Py_DECREF(((PyObject*)(c_api)));
4771
4772 c_api = PyCapsule_New((void *)PyUFunc_API, NULL((void*)0), NULL((void*)0));
4773 if (c_api == NULL((void*)0)) {
4774 goto err;
4775 }
4776 PyDict_SetItemString(d, "_UFUNC_API", c_api);
4777 Py_DECREF(c_api)_Py_DECREF(((PyObject*)(c_api)));
4778 if (PyErr_Occurred()) {
4779 goto err;
4780 }
4781
4782 /*
4783 * PyExc_Exception should catch all the standard errors that are
4784 * now raised instead of the string exception "multiarray.error"
4785
4786 * This is for backward compatibility with existing code.
4787 */
4788 PyDict_SetItemString (d, "error", PyExc_Exception);
4789
4790 s = PyLong_FromLong(NPY_TRACE_DOMAIN389047);
4791 PyDict_SetItemString(d, "tracemalloc_domain", s);
4792 Py_DECREF(s)_Py_DECREF(((PyObject*)(s)));
4793
4794 s = PyUnicode_FromString("3.1");
4795 PyDict_SetItemString(d, "__version__", s);
4796 Py_DECREF(s)_Py_DECREF(((PyObject*)(s)));
4797
4798 s = npy_cpu_features_dict();
4799 if (s == NULL((void*)0)) {
4800 goto err;
4801 }
4802 if (PyDict_SetItemString(d, "__cpu_features__", s) < 0) {
4803 Py_DECREF(s)_Py_DECREF(((PyObject*)(s)));
4804 goto err;
4805 }
4806 Py_DECREF(s)_Py_DECREF(((PyObject*)(s)));
4807
4808 s = npy_cpu_baseline_list();
4809 if (s == NULL((void*)0)) {
4810 goto err;
4811 }
4812 if (PyDict_SetItemString(d, "__cpu_baseline__", s) < 0) {
4813 Py_DECREF(s)_Py_DECREF(((PyObject*)(s)));
4814 goto err;
4815 }
4816 Py_DECREF(s)_Py_DECREF(((PyObject*)(s)));
4817
4818 s = npy_cpu_dispatch_list();
4819 if (s == NULL((void*)0)) {
4820 goto err;
4821 }
4822 if (PyDict_SetItemString(d, "__cpu_dispatch__", s) < 0) {
4823 Py_DECREF(s)_Py_DECREF(((PyObject*)(s)));
4824 goto err;
4825 }
4826 Py_DECREF(s)_Py_DECREF(((PyObject*)(s)));
4827
4828 s = PyCapsule_New((void *)_datetime_strings, NULL((void*)0), NULL((void*)0));
4829 if (s == NULL((void*)0)) {
4830 goto err;
4831 }
4832 PyDict_SetItemString(d, "DATETIMEUNITS", s);
4833 Py_DECREF(s)_Py_DECREF(((PyObject*)(s)));
4834
4835#define ADDCONST(NAME) \
4836 s = PyLong_FromLong(NPY_##NAME); \
4837 PyDict_SetItemString(d, #NAME, s); \
4838 Py_DECREF(s)_Py_DECREF(((PyObject*)(s)))
4839
4840
4841 ADDCONST(ALLOW_THREADS);
4842 ADDCONST(BUFSIZE);
4843 ADDCONST(CLIP);
4844
4845 ADDCONST(ITEM_HASOBJECT);
4846 ADDCONST(LIST_PICKLE);
4847 ADDCONST(ITEM_IS_POINTER);
4848 ADDCONST(NEEDS_INIT);
4849 ADDCONST(NEEDS_PYAPI);
4850 ADDCONST(USE_GETITEM);
4851 ADDCONST(USE_SETITEM);
4852
4853 ADDCONST(RAISE);
4854 ADDCONST(WRAP);
4855 ADDCONST(MAXDIMS);
4856
4857 ADDCONST(MAY_SHARE_BOUNDS);
4858 ADDCONST(MAY_SHARE_EXACT);
4859#undef ADDCONST
4860
4861 PyDict_SetItemString(d, "ndarray", (PyObject *)&PyArray_Type);
4862 PyDict_SetItemString(d, "flatiter", (PyObject *)&PyArrayIter_Type);
4863 PyDict_SetItemString(d, "nditer", (PyObject *)&NpyIter_Type);
4864 PyDict_SetItemString(d, "broadcast",
4865 (PyObject *)&PyArrayMultiIter_Type);
4866 PyDict_SetItemString(d, "dtype", (PyObject *)&PyArrayDescr_Type(*(PyTypeObject *)(&PyArrayDescr_TypeFull)));
4867 PyDict_SetItemString(d, "flagsobj", (PyObject *)&PyArrayFlags_Type);
4868
4869 /* Business day calendar object */
4870 PyDict_SetItemString(d, "busdaycalendar",
4871 (PyObject *)&NpyBusDayCalendar_Type);
4872 set_flaginfo(d);
4873
4874 /* Create the typeinfo types */
4875 if (typeinfo_init_structsequences(d) < 0) {
4876 goto err;
4877 }
4878
4879 if (!intern_strings()) {
4880 goto err;
4881 }
4882
4883 if (set_typeinfo(d) != 0) {
4884 goto err;
4885 }
4886 if (PyType_Ready(&PyArrayMethod_Type) < 0) {
4887 goto err;
4888 }
4889 if (PyType_Ready(&PyBoundArrayMethod_Type) < 0) {
4890 goto err;
4891 }
4892 if (initialize_and_map_pytypes_to_dtypes() < 0) {
4893 goto err;
4894 }
4895
4896 if (PyArray_InitializeCasts() < 0) {
4897 goto err;
4898 }
4899
4900 if (initumath(m) != 0) {
4901 goto err;
4902 }
4903 return m;
4904
4905 err:
4906 if (!PyErr_Occurred()) {
4907 PyErr_SetString(PyExc_RuntimeError,
4908 "cannot load multiarray module.");
4909 }
4910 return NULL((void*)0);
4911}

/opt/pyrefcon/lib/pyrefcon/models/models/PyModule_Create2.model

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