numpy  2.0.0
src/multiarray/array_assign_scalar.c File Reference
#include <Python.h>
#include <numpy/ndarraytypes.h>
#include "npy_config.h"
#include "npy_pycompat.h"
#include "convert_datatype.h"
#include "methods.h"
#include "shape.h"
#include "lowlevel_strided_loops.h"
#include "array_assign.h"

Defines

#define PY_SSIZE_T_CLEAN
#define NPY_NO_DEPRECATED_API   NPY_API_VERSION
#define _MULTIARRAYMODULE

Functions

NPY_NO_EXPORT int raw_array_assign_scalar (int ndim, npy_intp *shape, PyArray_Descr *dst_dtype, char *dst_data, npy_intp *dst_strides, PyArray_Descr *src_dtype, char *src_data)
NPY_NO_EXPORT int raw_array_wheremasked_assign_scalar (int ndim, npy_intp *shape, PyArray_Descr *dst_dtype, char *dst_data, npy_intp *dst_strides, PyArray_Descr *src_dtype, char *src_data, PyArray_Descr *wheremask_dtype, char *wheremask_data, npy_intp *wheremask_strides)
NPY_NO_EXPORT int PyArray_AssignRawScalar (PyArrayObject *dst, PyArray_Descr *src_dtype, char *src_data, PyArrayObject *wheremask, NPY_CASTING casting)

Define Documentation

#define NPY_NO_DEPRECATED_API   NPY_API_VERSION

Function Documentation

NPY_NO_EXPORT int PyArray_AssignRawScalar ( PyArrayObject dst,
PyArray_Descr src_dtype,
char *  src_data,
PyArrayObject wheremask,
NPY_CASTING  casting 
)
Assigns a scalar value specified by 'src_dtype' and 'src_data' to elements of 'dst'.
dst: The destination array. src_dtype: The data type of the source scalar. src_data: The memory element of the source scalar. wheremask: If non-NULL, a boolean mask specifying where to copy. casting: An exception is raised if the assignment violates this

System Message: ERROR/3 (<string>, line 9) Unexpected indentation.

<blockquote> casting rule.</blockquote>

This function is implemented in array_assign_scalar.c.
Returns 0 on success, -1 on failure.
Check the casting rule
Make a copy of the src data if it's a different dtype than 'dst' or isn't aligned, and the destination we're copying to has more than one element. To avoid having to manage object lifetimes, we also skip this if 'dst' has an object dtype.
Use a static buffer to store the aligned/cast version, or allocate some memory if more space is needed.
Replace src_data/src_dtype
A straightforward value assignment
Do the assignment with raw array iteration
Broadcast the wheremask to 'dst' for raw iteration
Do the masked assignment with raw array iteration
NPY_NO_EXPORT int raw_array_assign_scalar ( int  ndim,
npy_intp shape,
PyArray_Descr dst_dtype,
char *  dst_data,
npy_intp dst_strides,
PyArray_Descr src_dtype,
char *  src_data 
)
Assigns the scalar value to every element of the destination raw array.
Returns 0 on success, -1 on failure.
Check alignment
Use raw iteration with no heap allocation
Get the function to do the casting
Process the innermost dimension

References _PyArray_Descr::alignment, _PyArray_Descr::elsize, NPY_AUXDATA_FREE, NPY_BEGIN_THREADS_DEF, NPY_BEGIN_THREADS_THRESHOLDED, NPY_END_THREADS, npy_is_aligned(), NPY_MAXDIMS, NPY_RAW_ITER_ONE_NEXT, NPY_RAW_ITER_START, NPY_SUCCEED, PyArray_GetDTypeTransferFunction(), PyArray_PrepareOneRawArrayIter(), and raw_array_is_aligned().

NPY_NO_EXPORT int raw_array_wheremasked_assign_scalar ( int  ndim,
npy_intp shape,
PyArray_Descr dst_dtype,
char *  dst_data,
npy_intp dst_strides,
PyArray_Descr src_dtype,
char *  src_data,
PyArray_Descr wheremask_dtype,
char *  wheremask_data,
npy_intp wheremask_strides 
)
Assigns the scalar value to every element of the destination raw array where the 'wheremask' value is True.
Returns 0 on success, -1 on failure.
Check alignment
Use raw iteration with no heap allocation
Get the function to do the casting
Process the innermost dimension