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

Function new_array_for_sum

numpy/core/src/multiarray/common.c:357–442  ·  view source on GitHub ↗

* Make a new empty array, of the passed size, of a type that takes the * priority of ap1 and ap2 into account. * * If `out` is non-NULL, memory overlap is checked with ap1 and ap2, and an * updateifcopy temporary array may be returned. If `result` is non-NULL, the * output array to be returned (`out` if non-NULL and the newly allocated array * otherwise) is incref'd and put to *result. */

Source from the content-addressed store, hash-verified

355 * otherwise) is incref'd and put to *result.
356 */
357NPY_NO_EXPORT PyArrayObject *
358new_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2, PyArrayObject* out,
359 int nd, npy_intp dimensions[], int typenum, PyArrayObject **result)
360{
361 PyArrayObject *out_buf;
362
363 if (out) {
364 int d;
365
366 /* verify that out is usable */
367 if (PyArray_NDIM(out) != nd ||
368 PyArray_TYPE(out) != typenum ||
369 !PyArray_ISCARRAY(out)) {
370 PyErr_SetString(PyExc_ValueError,
371 "output array is not acceptable (must have the right datatype, "
372 "number of dimensions, and be a C-Array)");
373 return 0;
374 }
375 for (d = 0; d < nd; ++d) {
376 if (dimensions[d] != PyArray_DIM(out, d)) {
377 PyErr_SetString(PyExc_ValueError,
378 "output array has wrong dimensions");
379 return 0;
380 }
381 }
382
383 /* check for memory overlap */
384 if (!(solve_may_share_memory(out, ap1, 1) == 0 &&
385 solve_may_share_memory(out, ap2, 1) == 0)) {
386 /* allocate temporary output array */
387 out_buf = (PyArrayObject *)PyArray_NewLikeArray(out, NPY_CORDER,
388 NULL, 0);
389 if (out_buf == NULL) {
390 return NULL;
391 }
392
393 /* set copy-back */
394 Py_INCREF(out);
395 if (PyArray_SetWritebackIfCopyBase(out_buf, out) < 0) {
396 Py_DECREF(out);
397 Py_DECREF(out_buf);
398 return NULL;
399 }
400 }
401 else {
402 Py_INCREF(out);
403 out_buf = out;
404 }
405
406 if (result) {
407 Py_INCREF(out);
408 *result = out;
409 }
410
411 return out_buf;
412 }
413 else {
414 PyTypeObject *subtype;

Callers 4

PyArray_MatrixProduct2Function · 0.85
_pyarray_correlateFunction · 0.85
array_vdotFunction · 0.85
cblas_matrixproductFunction · 0.85

Calls 8

PyArray_NDIMFunction · 0.85
PyArray_TYPEFunction · 0.85
PyArray_DIMFunction · 0.85
solve_may_share_memoryFunction · 0.85
PyArray_NewLikeArrayFunction · 0.85
PyArray_GetPriorityFunction · 0.85
PyArray_NewFunction · 0.85

Tested by

no test coverage detected