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

Function handle_scalar

numpy/core/src/multiarray/array_coercion.c:730–759  ·  view source on GitHub ↗

* Handle a leave node (known scalar) during dtype and shape discovery. * * @param obj The python object or nested sequence to convert * @param curr_dims The current number of dimensions (depth in the recursion) * @param max_dims The maximum number of dimensions. * @param out_shape The discovered output shape, will be filled * @param fixed_DType The user provided (fixed) DType or NULL * @par

Source from the content-addressed store, hash-verified

728 * @return 0 on success -1 on error
729 */
730static inline int
731handle_scalar(
732 PyObject *obj, int curr_dims, int *max_dims,
733 PyArray_Descr **out_descr, npy_intp *out_shape,
734 PyArray_DTypeMeta *fixed_DType,
735 enum _dtype_discovery_flags *flags, PyArray_DTypeMeta *DType)
736{
737 PyArray_Descr *descr;
738
739 if (update_shape(curr_dims, max_dims, out_shape,
740 0, NULL, NPY_FALSE, flags) < 0) {
741 *flags |= FOUND_RAGGED_ARRAY;
742 return *max_dims;
743 }
744 if (*flags & DESCRIPTOR_WAS_SET) {
745 /* no need to do any promotion */
746 return *max_dims;
747 }
748 /* This is a scalar, so find the descriptor */
749 descr = find_scalar_descriptor(fixed_DType, DType, obj);
750 if (descr == NULL) {
751 return -1;
752 }
753 if (handle_promotion(out_descr, descr, fixed_DType, flags) < 0) {
754 Py_DECREF(descr);
755 return -1;
756 }
757 Py_DECREF(descr);
758 return *max_dims;
759}
760
761
762/**

Calls 3

update_shapeFunction · 0.85
find_scalar_descriptorFunction · 0.85
handle_promotionFunction · 0.85

Tested by

no test coverage detected