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

Function PyArray_NewFromDescr_int

numpy/core/src/multiarray/ctors.c:627–970  ·  view source on GitHub ↗

* Generic new array creation routine. * Internal variant with calloc argument for PyArray_Zeros. * * steals a reference to descr. On failure or descr->subarray, descr will * be decrefed. */

Source from the content-addressed store, hash-verified

625 * be decrefed.
626 */
627NPY_NO_EXPORT PyObject *
628PyArray_NewFromDescr_int(
629 PyTypeObject *subtype, PyArray_Descr *descr, int nd,
630 npy_intp const *dims, npy_intp const *strides, void *data,
631 int flags, PyObject *obj, PyObject *base, _NPY_CREATION_FLAGS cflags)
632{
633 PyArrayObject_fields *fa;
634 npy_intp nbytes;
635
636 if (descr == NULL) {
637 return NULL;
638 }
639 if (nd > NPY_MAXDIMS || nd < 0) {
640 PyErr_Format(PyExc_ValueError,
641 "number of dimensions must be within [0, %d]", NPY_MAXDIMS);
642 Py_DECREF(descr);
643 return NULL;
644 }
645
646 nbytes = descr->elsize;
647 /*
648 * Unless explicitly asked not to, we do replace dtypes in some cases.
649 * This mainly means that we never create arrays with a subarray dtype
650 * (unless for internal use when requested). And neither do we create
651 * S0/U0 arrays in most cases (unless data == NULL so this is probably
652 * a view where growing the dtype would be presumable wrong).
653 */
654 if (!(cflags & _NPY_ARRAY_ENSURE_DTYPE_IDENTITY)) {
655 if (descr->subarray) {
656 PyObject *ret;
657 npy_intp newdims[2*NPY_MAXDIMS];
658 npy_intp *newstrides = NULL;
659 memcpy(newdims, dims, nd*sizeof(npy_intp));
660 if (strides) {
661 newstrides = newdims + NPY_MAXDIMS;
662 memcpy(newstrides, strides, nd*sizeof(npy_intp));
663 }
664 nd =_update_descr_and_dimensions(&descr, newdims,
665 newstrides, nd);
666 ret = PyArray_NewFromDescr_int(
667 subtype, descr,
668 nd, newdims, newstrides, data,
669 flags, obj, base, cflags);
670 return ret;
671 }
672
673 /* Check datatype element size */
674 if (PyDataType_ISUNSIZED(descr)) {
675 if (!PyDataType_ISFLEXIBLE(descr) &&
676 NPY_DT_is_legacy(NPY_DTYPE(descr))) {
677 PyErr_SetString(PyExc_TypeError, "Empty data-type");
678 Py_DECREF(descr);
679 return NULL;
680 }
681 else if (PyDataType_ISSTRING(descr)
682 && !(cflags & _NPY_ARRAY_ALLOW_EMPTY_STRING)
683 && data == NULL) {
684 PyArray_DESCR_REPLACE(descr);

Callers 15

array_imag_getFunction · 0.85
PyArray_GetFieldFunction · 0.85
PyArray_ZerosFunction · 0.85
PyArray_FromFileFunction · 0.85
PyArray_NewshapeFunction · 0.85
PyArray_ViewFunction · 0.85
get_view_from_indexFunction · 0.85
_get_field_viewFunction · 0.85
wrap_copy_swap_functionFunction · 0.85

Calls 13

NPY_traverse_info_initFunction · 0.85
npy_alloc_cache_dimFunction · 0.85
_array_fill_stridesFunction · 0.85
PyArray_UpdateFlagsFunction · 0.85
PyDataMem_GetHandlerFunction · 0.85
PyDataMem_UserNEW_ZEROEDFunction · 0.85
PyDataMem_UserNEWFunction · 0.85
raise_memory_errorFunction · 0.85
PyArray_MultiplyListFunction · 0.85
PyArray_SetBaseObjectFunction · 0.85
NPY_traverse_info_xfreeFunction · 0.85

Tested by

no test coverage detected