* Assigns the scalar value to every element of the destination raw array. * * Returns 0 on success, -1 on failure. */
| 35 | * Returns 0 on success, -1 on failure. |
| 36 | */ |
| 37 | NPY_NO_EXPORT int |
| 38 | raw_array_assign_scalar(int ndim, npy_intp const *shape, |
| 39 | PyArray_Descr *dst_dtype, char *dst_data, npy_intp const *dst_strides, |
| 40 | PyArray_Descr *src_dtype, char *src_data) |
| 41 | { |
| 42 | int idim; |
| 43 | npy_intp shape_it[NPY_MAXDIMS], dst_strides_it[NPY_MAXDIMS]; |
| 44 | npy_intp coord[NPY_MAXDIMS]; |
| 45 | |
| 46 | int aligned; |
| 47 | |
| 48 | NPY_BEGIN_THREADS_DEF; |
| 49 | |
| 50 | /* Check both uint and true alignment */ |
| 51 | aligned = raw_array_is_aligned(ndim, shape, dst_data, dst_strides, |
| 52 | npy_uint_alignment(dst_dtype->elsize)) && |
| 53 | raw_array_is_aligned(ndim, shape, dst_data, dst_strides, |
| 54 | dst_dtype->alignment) && |
| 55 | npy_is_aligned(src_data, npy_uint_alignment(src_dtype->elsize) && |
| 56 | npy_is_aligned(src_data, src_dtype->alignment)); |
| 57 | |
| 58 | /* Use raw iteration with no heap allocation */ |
| 59 | if (PyArray_PrepareOneRawArrayIter( |
| 60 | ndim, shape, |
| 61 | dst_data, dst_strides, |
| 62 | &ndim, shape_it, |
| 63 | &dst_data, dst_strides_it) < 0) { |
| 64 | return -1; |
| 65 | } |
| 66 | |
| 67 | /* Get the function to do the casting */ |
| 68 | NPY_cast_info cast_info; |
| 69 | NPY_ARRAYMETHOD_FLAGS flags; |
| 70 | if (PyArray_GetDTypeTransferFunction(aligned, |
| 71 | 0, dst_strides_it[0], |
| 72 | src_dtype, dst_dtype, |
| 73 | 0, |
| 74 | &cast_info, &flags) != NPY_SUCCEED) { |
| 75 | return -1; |
| 76 | } |
| 77 | |
| 78 | if (!(flags & NPY_METH_NO_FLOATINGPOINT_ERRORS)) { |
| 79 | npy_clear_floatstatus_barrier(src_data); |
| 80 | } |
| 81 | if (!(flags & NPY_METH_REQUIRES_PYAPI)) { |
| 82 | npy_intp nitems = 1, i; |
| 83 | for (i = 0; i < ndim; i++) { |
| 84 | nitems *= shape_it[i]; |
| 85 | } |
| 86 | NPY_BEGIN_THREADS_THRESHOLDED(nitems); |
| 87 | } |
| 88 | |
| 89 | npy_intp strides[2] = {0, dst_strides_it[0]}; |
| 90 | |
| 91 | NPY_RAW_ITER_START(idim, ndim, coord, shape_it) { |
| 92 | /* Process the innermost dimension */ |
| 93 | char *args[2] = {src_data, dst_data}; |
| 94 | if (cast_info.func(&cast_info.context, |
no test coverage detected