numpy  2.0.0
src/multiarray/array_assign.h
Go to the documentation of this file.
00001 #ifndef _NPY_PRIVATE__ARRAY_ASSIGN_H_
00002 #define _NPY_PRIVATE__ARRAY_ASSIGN_H_
00003 
00004 /*
00005  * An array assignment function for copying arrays, treating the
00006  * arrays as flat according to their respective ordering rules.
00007  * This function makes a temporary copy of 'src' if 'src' and
00008  * 'dst' overlap, to be able to handle views of the same data with
00009  * different strides.
00010  *
00011  * dst: The destination array.
00012  * dst_order: The rule for how 'dst' is to be made flat.
00013  * src: The source array.
00014  * src_order: The rule for how 'src' is to be made flat.
00015  * casting: An exception is raised if the copy violates this
00016  *          casting rule.
00017  *
00018  * Returns 0 on success, -1 on failure.
00019  */
00020 /* Not yet implemented
00021 NPY_NO_EXPORT int
00022 PyArray_AssignArrayAsFlat(PyArrayObject *dst, NPY_ORDER dst_order,
00023                   PyArrayObject *src, NPY_ORDER src_order,
00024                   NPY_CASTING casting,
00025                   npy_bool preservena, npy_bool *preservewhichna);
00026 */
00027 
00028 NPY_NO_EXPORT int
00029 PyArray_AssignArray(PyArrayObject *dst, PyArrayObject *src,
00030                     PyArrayObject *wheremask,
00031                     NPY_CASTING casting);
00032 
00033 NPY_NO_EXPORT int
00034 PyArray_AssignRawScalar(PyArrayObject *dst,
00035                         PyArray_Descr *src_dtype, char *src_data,
00036                         PyArrayObject *wheremask,
00037                         NPY_CASTING casting);
00038 
00039 /******** LOW-LEVEL SCALAR TO ARRAY ASSIGNMENT ********/
00040 
00041 /*
00042  * Assigns the scalar value to every element of the destination raw array.
00043  *
00044  * Returns 0 on success, -1 on failure.
00045  */
00046 NPY_NO_EXPORT int
00047 raw_array_assign_scalar(int ndim, npy_intp *shape,
00048         PyArray_Descr *dst_dtype, char *dst_data, npy_intp *dst_strides,
00049         PyArray_Descr *src_dtype, char *src_data);
00050 
00051 /*
00052  * Assigns the scalar value to every element of the destination raw array
00053  * where the 'wheremask' value is True.
00054  *
00055  * Returns 0 on success, -1 on failure.
00056  */
00057 NPY_NO_EXPORT int
00058 raw_array_wheremasked_assign_scalar(int ndim, npy_intp *shape,
00059         PyArray_Descr *dst_dtype, char *dst_data, npy_intp *dst_strides,
00060         PyArray_Descr *src_dtype, char *src_data,
00061         PyArray_Descr *wheremask_dtype, char *wheremask_data,
00062         npy_intp *wheremask_strides);
00063 
00064 /******** LOW-LEVEL ARRAY MANIPULATION HELPERS ********/
00065 
00066 /*
00067  * Internal detail of how much to buffer during array assignments which
00068  * need it. This is for more complex NA masking operations where masks
00069  * need to be inverted or combined together.
00070  */
00071 #define NPY_ARRAY_ASSIGN_BUFFERSIZE 8192
00072 
00073 /*
00074  * Broadcasts strides to match the given dimensions. Can be used,
00075  * for instance, to set up a raw iteration.
00076  *
00077  * 'strides_name' is used to produce an error message if the strides
00078  * cannot be broadcast.
00079  *
00080  * Returns 0 on success, -1 on failure.
00081  */
00082 NPY_NO_EXPORT int
00083 broadcast_strides(int ndim, npy_intp *shape,
00084                 int strides_ndim, npy_intp *strides_shape, npy_intp *strides,
00085                 char *strides_name,
00086                 npy_intp *out_strides);
00087 
00088 /*
00089  * Checks whether a data pointer + set of strides refers to a raw
00090  * array which is fully aligned data.
00091  */
00092 NPY_NO_EXPORT int
00093 raw_array_is_aligned(int ndim, char *data, npy_intp *strides, int alignment);
00094 
00095 /* Returns 1 if the arrays have overlapping data, 0 otherwise */
00096 NPY_NO_EXPORT int
00097 arrays_overlap(PyArrayObject *arr1, PyArrayObject *arr2);
00098 
00099 
00100 #endif