* 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
| 728 | * @return 0 on success -1 on error |
| 729 | */ |
| 730 | static inline int |
| 731 | handle_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 | /** |
no test coverage detected