2
2
#define __LOWLEVEL_STRIDED_LOOPS_H
3
3
#include "common.h"
4
4
#include <npy_config.h>
5
+ #include <array_method.h>
6
+ #include "dtype_transfer.h"
5
7
#include "mem_overlap.h"
6
8
7
9
/* For PyArray_ macros used below */
30
32
* Use NPY_AUXDATA_CLONE and NPY_AUXDATA_FREE to deal with this data.
31
33
*
32
34
*/
33
- typedef int (PyArray_StridedUnaryOp )(
34
- char * dst , npy_intp dst_stride , char * src , npy_intp src_stride ,
35
- npy_intp N , npy_intp src_itemsize , NpyAuxData * transferdata );
35
+ // TODO: FIX! That comment belongs to something now in array-method
36
36
37
37
/*
38
38
* This is for pointers to functions which behave exactly as
39
- * for PyArray_StridedUnaryOp , but with an additional mask controlling
39
+ * for PyArrayMethod_StridedLoop , but with an additional mask controlling
40
40
* which values are transformed.
41
41
*
42
+ * TODO: We should move this mask "capability" to the ArrayMethod itself
43
+ * probably. Although for NumPy internal things this works decently,
44
+ * and exposing it there should be well thought out to be useful beyond
45
+ * NumPy if possible.
46
+ *
42
47
* In particular, the 'i'-th element is operated on if and only if
43
48
* mask[i*mask_stride] is true.
44
49
*/
45
50
typedef int (PyArray_MaskedStridedUnaryOp )(
46
- char * dst , npy_intp dst_stride , char * src , npy_intp src_stride ,
51
+ PyArrayMethod_Context * context , char * const * args ,
52
+ const npy_intp * dimensions , const npy_intp * strides ,
47
53
npy_bool * mask , npy_intp mask_stride ,
48
- npy_intp N , npy_intp src_itemsize , NpyAuxData * transferdata );
54
+ NpyAuxData * auxdata );
49
55
50
56
/*
51
57
* Gives back a function pointer to a specialized function for copying
@@ -65,7 +71,7 @@ typedef int (PyArray_MaskedStridedUnaryOp)(
65
71
* Should be the item size if it will always be the same, 0 otherwise.
66
72
*
67
73
*/
68
- NPY_NO_EXPORT PyArray_StridedUnaryOp *
74
+ NPY_NO_EXPORT PyArrayMethod_StridedLoop *
69
75
PyArray_GetStridedCopyFn (int aligned ,
70
76
npy_intp src_stride , npy_intp dst_stride ,
71
77
npy_intp itemsize );
@@ -80,7 +86,7 @@ PyArray_GetStridedCopyFn(int aligned,
80
86
*
81
87
* Parameters are as for PyArray_GetStridedCopyFn.
82
88
*/
83
- NPY_NO_EXPORT PyArray_StridedUnaryOp *
89
+ NPY_NO_EXPORT PyArrayMethod_StridedLoop *
84
90
PyArray_GetStridedCopySwapFn (int aligned ,
85
91
npy_intp src_stride , npy_intp dst_stride ,
86
92
npy_intp itemsize );
@@ -95,7 +101,7 @@ PyArray_GetStridedCopySwapFn(int aligned,
95
101
*
96
102
* Parameters are as for PyArray_GetStridedCopyFn.
97
103
*/
98
- NPY_NO_EXPORT PyArray_StridedUnaryOp *
104
+ NPY_NO_EXPORT PyArrayMethod_StridedLoop *
99
105
PyArray_GetStridedCopySwapPairFn (int aligned ,
100
106
npy_intp src_stride , npy_intp dst_stride ,
101
107
npy_intp itemsize );
@@ -114,7 +120,7 @@ NPY_NO_EXPORT int
114
120
PyArray_GetStridedZeroPadCopyFn (int aligned , int unicode_swap ,
115
121
npy_intp src_stride , npy_intp dst_stride ,
116
122
npy_intp src_itemsize , npy_intp dst_itemsize ,
117
- PyArray_StridedUnaryOp * * outstransfer ,
123
+ PyArrayMethod_StridedLoop * * outstransfer ,
118
124
NpyAuxData * * outtransferdata );
119
125
120
126
/*
@@ -123,7 +129,7 @@ PyArray_GetStridedZeroPadCopyFn(int aligned, int unicode_swap,
123
129
* to dst_type_num. If a conversion is unsupported, returns NULL
124
130
* without setting a Python exception.
125
131
*/
126
- NPY_NO_EXPORT PyArray_StridedUnaryOp *
132
+ NPY_NO_EXPORT PyArrayMethod_StridedLoop *
127
133
PyArray_GetStridedNumericCastFn (int aligned ,
128
134
npy_intp src_stride , npy_intp dst_stride ,
129
135
int src_type_num , int dst_type_num );
@@ -138,7 +144,7 @@ NPY_NO_EXPORT int
138
144
PyArray_GetDTypeCopySwapFn (int aligned ,
139
145
npy_intp src_stride , npy_intp dst_stride ,
140
146
PyArray_Descr * dtype ,
141
- PyArray_StridedUnaryOp * * outstransfer ,
147
+ PyArrayMethod_StridedLoop * * outstransfer ,
142
148
NpyAuxData * * outtransferdata );
143
149
144
150
/*
@@ -168,12 +174,10 @@ PyArray_GetDTypeCopySwapFn(int aligned,
168
174
* If 0, the destination data gets new reference ownership.
169
175
* If 1, the references from the source data are moved to
170
176
* the destination data.
171
- * out_stransfer:
172
- * The resulting transfer function is placed here.
173
- * out_transferdata:
174
- * The auxiliary data for the transfer function is placed here.
175
- * When finished with the transfer function, the caller must call
176
- * NPY_AUXDATA_FREE on this data.
177
+ * cast_info:
178
+ * A pointer to an (uninitialized) `NPY_cast_info` struct, the caller
179
+ * must call `NPY_cast_info_xfree` on it (except on error) and handle
180
+ * its memory livespan.
177
181
* out_needs_api:
178
182
* If this is non-NULL, and the transfer function produced needs
179
183
* to call into the (Python) API, this gets set to 1. This
@@ -191,60 +195,15 @@ PyArray_GetDTypeTransferFunction(int aligned,
191
195
npy_intp src_stride , npy_intp dst_stride ,
192
196
PyArray_Descr * src_dtype , PyArray_Descr * dst_dtype ,
193
197
int move_references ,
194
- PyArray_StridedUnaryOp * * out_stransfer ,
195
- NpyAuxData * * out_transferdata ,
198
+ NPY_cast_info * cast_info ,
196
199
int * out_needs_api );
197
200
198
-
199
- /* Same as above, but only wraps copyswapn or legacy cast functions */
200
- NPY_NO_EXPORT int
201
- PyArray_GetLegacyDTypeTransferFunction (int aligned ,
202
- npy_intp src_stride , npy_intp dst_stride ,
203
- PyArray_Descr * src_dtype , PyArray_Descr * dst_dtype ,
204
- int move_references ,
205
- PyArray_StridedUnaryOp * * out_stransfer ,
206
- NpyAuxData * * out_transferdata ,
207
- int * out_needs_api , int wrap_if_unaligned );
208
-
209
- /* Specialized dtype transfer functions */
210
- NPY_NO_EXPORT int
211
- get_nbo_cast_datetime_transfer_function (int aligned ,
212
- PyArray_Descr * src_dtype , PyArray_Descr * dst_dtype ,
213
- PyArray_StridedUnaryOp * * out_stransfer ,
214
- NpyAuxData * * out_transferdata );
215
-
216
- NPY_NO_EXPORT int
217
- get_nbo_datetime_to_string_transfer_function (
218
- PyArray_Descr * src_dtype , PyArray_Descr * dst_dtype ,
219
- PyArray_StridedUnaryOp * * out_stransfer , NpyAuxData * * out_transferdata );
220
-
221
- NPY_NO_EXPORT int
222
- get_datetime_to_unicode_transfer_function (int aligned ,
223
- npy_intp src_stride , npy_intp dst_stride ,
224
- PyArray_Descr * src_dtype , PyArray_Descr * dst_dtype ,
225
- PyArray_StridedUnaryOp * * out_stransfer ,
226
- NpyAuxData * * out_transferdata ,
227
- int * out_needs_api );
228
-
229
- NPY_NO_EXPORT int
230
- get_nbo_string_to_datetime_transfer_function (
231
- PyArray_Descr * src_dtype , PyArray_Descr * dst_dtype ,
232
- PyArray_StridedUnaryOp * * out_stransfer , NpyAuxData * * out_transferdata );
233
-
234
- NPY_NO_EXPORT int
235
- get_unicode_to_datetime_transfer_function (int aligned ,
236
- npy_intp src_stride , npy_intp dst_stride ,
237
- PyArray_Descr * src_dtype , PyArray_Descr * dst_dtype ,
238
- PyArray_StridedUnaryOp * * out_stransfer ,
239
- NpyAuxData * * out_transferdata ,
240
- int * out_needs_api );
241
-
242
201
NPY_NO_EXPORT int
243
202
get_fields_transfer_function (int aligned ,
244
203
npy_intp src_stride , npy_intp dst_stride ,
245
204
PyArray_Descr * src_dtype , PyArray_Descr * dst_dtype ,
246
205
int move_references ,
247
- PyArray_StridedUnaryOp * * out_stransfer ,
206
+ PyArrayMethod_StridedLoop * * out_stransfer ,
248
207
NpyAuxData * * out_transferdata ,
249
208
int * out_needs_api );
250
209
@@ -253,30 +212,10 @@ get_subarray_transfer_function(int aligned,
253
212
npy_intp src_stride , npy_intp dst_stride ,
254
213
PyArray_Descr * src_dtype , PyArray_Descr * dst_dtype ,
255
214
int move_references ,
256
- PyArray_StridedUnaryOp * * out_stransfer ,
215
+ PyArrayMethod_StridedLoop * * out_stransfer ,
257
216
NpyAuxData * * out_transferdata ,
258
217
int * out_needs_api );
259
218
260
- NPY_NO_EXPORT int
261
- _strided_to_strided_move_references (char * dst , npy_intp dst_stride ,
262
- char * src , npy_intp src_stride ,
263
- npy_intp N , npy_intp src_itemsize ,
264
- NpyAuxData * data );
265
-
266
- NPY_NO_EXPORT int
267
- _strided_to_strided_copy_references (char * dst , npy_intp dst_stride ,
268
- char * src , npy_intp src_stride ,
269
- npy_intp N , npy_intp src_itemsize ,
270
- NpyAuxData * data );
271
-
272
- NPY_NO_EXPORT int
273
- wrap_aligned_contig_transfer_function_with_copyswapn (
274
- int aligned , npy_intp src_stride , npy_intp dst_stride ,
275
- PyArray_Descr * src_dtype , PyArray_Descr * dst_dtype ,
276
- PyArray_StridedUnaryOp * * out_stransfer , NpyAuxData * * out_transferdata ,
277
- int * out_needs_api ,
278
- PyArray_StridedUnaryOp * caststransfer , NpyAuxData * castdata );
279
-
280
219
/*
281
220
* This is identical to PyArray_GetDTypeTransferFunction, but returns a
282
221
* transfer function which also takes a mask as a parameter. The mask is used
@@ -301,8 +240,7 @@ PyArray_GetMaskedDTypeTransferFunction(int aligned,
301
240
PyArray_Descr * dst_dtype ,
302
241
PyArray_Descr * mask_dtype ,
303
242
int move_references ,
304
- PyArray_MaskedStridedUnaryOp * * out_stransfer ,
305
- NpyAuxData * * out_transferdata ,
243
+ NPY_cast_info * cast_info ,
306
244
int * out_needs_api );
307
245
308
246
/*
@@ -357,11 +295,9 @@ PyArray_CastRawArrays(npy_intp count,
357
295
* sizes, for example a casting operation, the 'stransfer' function
358
296
* should be specialized for that, in which case 'stransfer' will use
359
297
* this parameter as the source item size.
360
- * stransfer:
361
- * The strided transfer function.
362
- * transferdata:
363
- * An auxiliary data pointer passed to the strided transfer function.
364
- * This follows the conventions of NpyAuxData objects.
298
+ * cast_info:
299
+ * Pointer to the NPY_cast_info struct which summarizes all information
300
+ * necessary to perform a cast.
365
301
*/
366
302
NPY_NO_EXPORT npy_intp
367
303
PyArray_TransferNDimToStrided (npy_intp ndim ,
@@ -370,8 +306,7 @@ PyArray_TransferNDimToStrided(npy_intp ndim,
370
306
npy_intp const * coords , npy_intp coords_inc ,
371
307
npy_intp const * shape , npy_intp shape_inc ,
372
308
npy_intp count , npy_intp src_itemsize ,
373
- PyArray_StridedUnaryOp * stransfer ,
374
- NpyAuxData * transferdata );
309
+ NPY_cast_info * cast_info );
375
310
376
311
NPY_NO_EXPORT npy_intp
377
312
PyArray_TransferStridedToNDim (npy_intp ndim ,
@@ -380,8 +315,7 @@ PyArray_TransferStridedToNDim(npy_intp ndim,
380
315
npy_intp const * coords , npy_intp coords_inc ,
381
316
npy_intp const * shape , npy_intp shape_inc ,
382
317
npy_intp count , npy_intp src_itemsize ,
383
- PyArray_StridedUnaryOp * stransfer ,
384
- NpyAuxData * transferdata );
318
+ NPY_cast_info * cast_info );
385
319
386
320
NPY_NO_EXPORT npy_intp
387
321
PyArray_TransferMaskedStridedToNDim (npy_intp ndim ,
@@ -391,8 +325,7 @@ PyArray_TransferMaskedStridedToNDim(npy_intp ndim,
391
325
npy_intp const * coords , npy_intp coords_inc ,
392
326
npy_intp const * shape , npy_intp shape_inc ,
393
327
npy_intp count , npy_intp src_itemsize ,
394
- PyArray_MaskedStridedUnaryOp * stransfer ,
395
- NpyAuxData * data );
328
+ NPY_cast_info * cast_info );
396
329
397
330
NPY_NO_EXPORT int
398
331
mapiter_trivial_get (PyArrayObject * self , PyArrayObject * ind ,
0 commit comments