ZTWHHH commited on
Commit
7c1395b
·
verified ·
1 Parent(s): b09c2d6

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/__init__.cpython-310.pyc +0 -0
  3. parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/_dtype.cpython-310.pyc +0 -0
  4. parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/_dtype_ctypes.cpython-310.pyc +0 -0
  5. parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/_exceptions.cpython-310.pyc +0 -0
  6. parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/_machar.cpython-310.pyc +0 -0
  7. parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/_methods.cpython-310.pyc +0 -0
  8. parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/_type_aliases.cpython-310.pyc +0 -0
  9. parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/arrayprint.cpython-310.pyc +0 -0
  10. parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/cversions.cpython-310.pyc +0 -0
  11. parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/overrides.cpython-310.pyc +0 -0
  12. parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/records.cpython-310.pyc +0 -0
  13. parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/umath.cpython-310.pyc +0 -0
  14. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/__multiarray_api.c +376 -0
  15. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/__multiarray_api.h +1613 -0
  16. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/__ufunc_api.c +54 -0
  17. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/__ufunc_api.h +340 -0
  18. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/_neighborhood_iterator_imp.h +90 -0
  19. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/_numpyconfig.h +33 -0
  20. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/_public_dtype_api_table.h +86 -0
  21. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/arrayscalars.h +196 -0
  22. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/dtype_api.h +479 -0
  23. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/halffloat.h +70 -0
  24. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/ndarrayobject.h +304 -0
  25. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/ndarraytypes.h +1925 -0
  26. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_1_7_deprecated_api.h +112 -0
  27. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_2_compat.h +249 -0
  28. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_2_complexcompat.h +28 -0
  29. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_3kcompat.h +374 -0
  30. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_common.h +1070 -0
  31. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_cpu.h +129 -0
  32. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_endian.h +77 -0
  33. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_math.h +602 -0
  34. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_no_deprecated_api.h +20 -0
  35. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_os.h +42 -0
  36. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/numpyconfig.h +171 -0
  37. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/random/LICENSE.txt +21 -0
  38. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/random/bitgen.h +20 -0
  39. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/random/distributions.h +209 -0
  40. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/random/libdivide.h +2079 -0
  41. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/ufuncobject.h +345 -0
  42. parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/utils.h +37 -0
  43. parrot/lib/python3.10/site-packages/numpy/polynomial/__init__.py +187 -0
  44. parrot/lib/python3.10/site-packages/numpy/polynomial/__init__.pyi +23 -0
  45. parrot/lib/python3.10/site-packages/numpy/polynomial/_polybase.py +1223 -0
  46. parrot/lib/python3.10/site-packages/numpy/polynomial/_polybase.pyi +297 -0
  47. parrot/lib/python3.10/site-packages/numpy/polynomial/_polytypes.pyi +912 -0
  48. parrot/lib/python3.10/site-packages/numpy/polynomial/chebyshev.py +2086 -0
  49. parrot/lib/python3.10/site-packages/numpy/polynomial/chebyshev.pyi +192 -0
  50. parrot/lib/python3.10/site-packages/numpy/polynomial/hermite.py +1793 -0
.gitattributes CHANGED
@@ -1420,3 +1420,4 @@ vllm/lib/python3.10/site-packages/yaml/_yaml.cpython-310-x86_64-linux-gnu.so fil
1420
  vllm/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_compute.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
1421
  vllm/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_pandas.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
1422
  vllm/lib/python3.10/site-packages/shapely.libs/libgeos-e4f0e0c1.so.3.11.4 filter=lfs diff=lfs merge=lfs -text
 
 
1420
  vllm/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_compute.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
1421
  vllm/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_pandas.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
1422
  vllm/lib/python3.10/site-packages/shapely.libs/libgeos-e4f0e0c1.so.3.11.4 filter=lfs diff=lfs merge=lfs -text
1423
+ vllm/lib/python3.10/site-packages/shapely.libs/libgeos_c-1e72bdae.so.1.17.4 filter=lfs diff=lfs merge=lfs -text
parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (4.12 kB). View file
 
parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/_dtype.cpython-310.pyc ADDED
Binary file (8.26 kB). View file
 
parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/_dtype_ctypes.cpython-310.pyc ADDED
Binary file (3.05 kB). View file
 
parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/_exceptions.cpython-310.pyc ADDED
Binary file (5.81 kB). View file
 
parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/_machar.cpython-310.pyc ADDED
Binary file (8.31 kB). View file
 
parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/_methods.cpython-310.pyc ADDED
Binary file (6.23 kB). View file
 
parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/_type_aliases.cpython-310.pyc ADDED
Binary file (2.58 kB). View file
 
parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/arrayprint.cpython-310.pyc ADDED
Binary file (52.8 kB). View file
 
parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/cversions.cpython-310.pyc ADDED
Binary file (545 Bytes). View file
 
parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/overrides.cpython-310.pyc ADDED
Binary file (6.19 kB). View file
 
parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/records.cpython-310.pyc ADDED
Binary file (29.2 kB). View file
 
parrot/lib/python3.10/site-packages/numpy/_core/__pycache__/umath.cpython-310.pyc ADDED
Binary file (1.91 kB). View file
 
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/__multiarray_api.c ADDED
@@ -0,0 +1,376 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ /* These pointers will be stored in the C-object for use in other
3
+ extension modules
4
+ */
5
+
6
+ void *PyArray_API[] = {
7
+ (void *) PyArray_GetNDArrayCVersion,
8
+ NULL,
9
+ (void *) &PyArray_Type,
10
+ (void *) &PyArrayDescr_Type,
11
+ NULL,
12
+ (void *) &PyArrayIter_Type,
13
+ (void *) &PyArrayMultiIter_Type,
14
+ (int *) &NPY_NUMUSERTYPES,
15
+ (void *) &PyBoolArrType_Type,
16
+ (void *) &_PyArrayScalar_BoolValues,
17
+ (void *) &PyGenericArrType_Type,
18
+ (void *) &PyNumberArrType_Type,
19
+ (void *) &PyIntegerArrType_Type,
20
+ (void *) &PySignedIntegerArrType_Type,
21
+ (void *) &PyUnsignedIntegerArrType_Type,
22
+ (void *) &PyInexactArrType_Type,
23
+ (void *) &PyFloatingArrType_Type,
24
+ (void *) &PyComplexFloatingArrType_Type,
25
+ (void *) &PyFlexibleArrType_Type,
26
+ (void *) &PyCharacterArrType_Type,
27
+ (void *) &PyByteArrType_Type,
28
+ (void *) &PyShortArrType_Type,
29
+ (void *) &PyIntArrType_Type,
30
+ (void *) &PyLongArrType_Type,
31
+ (void *) &PyLongLongArrType_Type,
32
+ (void *) &PyUByteArrType_Type,
33
+ (void *) &PyUShortArrType_Type,
34
+ (void *) &PyUIntArrType_Type,
35
+ (void *) &PyULongArrType_Type,
36
+ (void *) &PyULongLongArrType_Type,
37
+ (void *) &PyFloatArrType_Type,
38
+ (void *) &PyDoubleArrType_Type,
39
+ (void *) &PyLongDoubleArrType_Type,
40
+ (void *) &PyCFloatArrType_Type,
41
+ (void *) &PyCDoubleArrType_Type,
42
+ (void *) &PyCLongDoubleArrType_Type,
43
+ (void *) &PyObjectArrType_Type,
44
+ (void *) &PyStringArrType_Type,
45
+ (void *) &PyUnicodeArrType_Type,
46
+ (void *) &PyVoidArrType_Type,
47
+ NULL,
48
+ NULL,
49
+ (void *) PyArray_INCREF,
50
+ (void *) PyArray_XDECREF,
51
+ (void *) PyArray_SetStringFunction,
52
+ (void *) PyArray_DescrFromType,
53
+ (void *) PyArray_TypeObjectFromType,
54
+ (void *) PyArray_Zero,
55
+ (void *) PyArray_One,
56
+ (void *) PyArray_CastToType,
57
+ (void *) PyArray_CopyInto,
58
+ (void *) PyArray_CopyAnyInto,
59
+ (void *) PyArray_CanCastSafely,
60
+ (void *) PyArray_CanCastTo,
61
+ (void *) PyArray_ObjectType,
62
+ (void *) PyArray_DescrFromObject,
63
+ (void *) PyArray_ConvertToCommonType,
64
+ (void *) PyArray_DescrFromScalar,
65
+ (void *) PyArray_DescrFromTypeObject,
66
+ (void *) PyArray_Size,
67
+ (void *) PyArray_Scalar,
68
+ (void *) PyArray_FromScalar,
69
+ (void *) PyArray_ScalarAsCtype,
70
+ (void *) PyArray_CastScalarToCtype,
71
+ (void *) PyArray_CastScalarDirect,
72
+ (void *) PyArray_Pack,
73
+ NULL,
74
+ NULL,
75
+ NULL,
76
+ (void *) PyArray_FromAny,
77
+ (void *) PyArray_EnsureArray,
78
+ (void *) PyArray_EnsureAnyArray,
79
+ (void *) PyArray_FromFile,
80
+ (void *) PyArray_FromString,
81
+ (void *) PyArray_FromBuffer,
82
+ (void *) PyArray_FromIter,
83
+ (void *) PyArray_Return,
84
+ (void *) PyArray_GetField,
85
+ (void *) PyArray_SetField,
86
+ (void *) PyArray_Byteswap,
87
+ (void *) PyArray_Resize,
88
+ NULL,
89
+ NULL,
90
+ NULL,
91
+ (void *) PyArray_CopyObject,
92
+ (void *) PyArray_NewCopy,
93
+ (void *) PyArray_ToList,
94
+ (void *) PyArray_ToString,
95
+ (void *) PyArray_ToFile,
96
+ (void *) PyArray_Dump,
97
+ (void *) PyArray_Dumps,
98
+ (void *) PyArray_ValidType,
99
+ (void *) PyArray_UpdateFlags,
100
+ (void *) PyArray_New,
101
+ (void *) PyArray_NewFromDescr,
102
+ (void *) PyArray_DescrNew,
103
+ (void *) PyArray_DescrNewFromType,
104
+ (void *) PyArray_GetPriority,
105
+ (void *) PyArray_IterNew,
106
+ (void *) PyArray_MultiIterNew,
107
+ (void *) PyArray_PyIntAsInt,
108
+ (void *) PyArray_PyIntAsIntp,
109
+ (void *) PyArray_Broadcast,
110
+ NULL,
111
+ (void *) PyArray_FillWithScalar,
112
+ (void *) PyArray_CheckStrides,
113
+ (void *) PyArray_DescrNewByteorder,
114
+ (void *) PyArray_IterAllButAxis,
115
+ (void *) PyArray_CheckFromAny,
116
+ (void *) PyArray_FromArray,
117
+ (void *) PyArray_FromInterface,
118
+ (void *) PyArray_FromStructInterface,
119
+ (void *) PyArray_FromArrayAttr,
120
+ (void *) PyArray_ScalarKind,
121
+ (void *) PyArray_CanCoerceScalar,
122
+ NULL,
123
+ (void *) PyArray_CanCastScalar,
124
+ NULL,
125
+ (void *) PyArray_RemoveSmallest,
126
+ (void *) PyArray_ElementStrides,
127
+ (void *) PyArray_Item_INCREF,
128
+ (void *) PyArray_Item_XDECREF,
129
+ NULL,
130
+ (void *) PyArray_Transpose,
131
+ (void *) PyArray_TakeFrom,
132
+ (void *) PyArray_PutTo,
133
+ (void *) PyArray_PutMask,
134
+ (void *) PyArray_Repeat,
135
+ (void *) PyArray_Choose,
136
+ (void *) PyArray_Sort,
137
+ (void *) PyArray_ArgSort,
138
+ (void *) PyArray_SearchSorted,
139
+ (void *) PyArray_ArgMax,
140
+ (void *) PyArray_ArgMin,
141
+ (void *) PyArray_Reshape,
142
+ (void *) PyArray_Newshape,
143
+ (void *) PyArray_Squeeze,
144
+ (void *) PyArray_View,
145
+ (void *) PyArray_SwapAxes,
146
+ (void *) PyArray_Max,
147
+ (void *) PyArray_Min,
148
+ (void *) PyArray_Ptp,
149
+ (void *) PyArray_Mean,
150
+ (void *) PyArray_Trace,
151
+ (void *) PyArray_Diagonal,
152
+ (void *) PyArray_Clip,
153
+ (void *) PyArray_Conjugate,
154
+ (void *) PyArray_Nonzero,
155
+ (void *) PyArray_Std,
156
+ (void *) PyArray_Sum,
157
+ (void *) PyArray_CumSum,
158
+ (void *) PyArray_Prod,
159
+ (void *) PyArray_CumProd,
160
+ (void *) PyArray_All,
161
+ (void *) PyArray_Any,
162
+ (void *) PyArray_Compress,
163
+ (void *) PyArray_Flatten,
164
+ (void *) PyArray_Ravel,
165
+ (void *) PyArray_MultiplyList,
166
+ (void *) PyArray_MultiplyIntList,
167
+ (void *) PyArray_GetPtr,
168
+ (void *) PyArray_CompareLists,
169
+ (void *) PyArray_AsCArray,
170
+ NULL,
171
+ NULL,
172
+ (void *) PyArray_Free,
173
+ (void *) PyArray_Converter,
174
+ (void *) PyArray_IntpFromSequence,
175
+ (void *) PyArray_Concatenate,
176
+ (void *) PyArray_InnerProduct,
177
+ (void *) PyArray_MatrixProduct,
178
+ NULL,
179
+ (void *) PyArray_Correlate,
180
+ NULL,
181
+ (void *) PyArray_DescrConverter,
182
+ (void *) PyArray_DescrConverter2,
183
+ (void *) PyArray_IntpConverter,
184
+ (void *) PyArray_BufferConverter,
185
+ (void *) PyArray_AxisConverter,
186
+ (void *) PyArray_BoolConverter,
187
+ (void *) PyArray_ByteorderConverter,
188
+ (void *) PyArray_OrderConverter,
189
+ (void *) PyArray_EquivTypes,
190
+ (void *) PyArray_Zeros,
191
+ (void *) PyArray_Empty,
192
+ (void *) PyArray_Where,
193
+ (void *) PyArray_Arange,
194
+ (void *) PyArray_ArangeObj,
195
+ (void *) PyArray_SortkindConverter,
196
+ (void *) PyArray_LexSort,
197
+ (void *) PyArray_Round,
198
+ (void *) PyArray_EquivTypenums,
199
+ (void *) PyArray_RegisterDataType,
200
+ (void *) PyArray_RegisterCastFunc,
201
+ (void *) PyArray_RegisterCanCast,
202
+ (void *) PyArray_InitArrFuncs,
203
+ (void *) PyArray_IntTupleFromIntp,
204
+ NULL,
205
+ (void *) PyArray_ClipmodeConverter,
206
+ (void *) PyArray_OutputConverter,
207
+ (void *) PyArray_BroadcastToShape,
208
+ NULL,
209
+ NULL,
210
+ (void *) PyArray_DescrAlignConverter,
211
+ (void *) PyArray_DescrAlignConverter2,
212
+ (void *) PyArray_SearchsideConverter,
213
+ (void *) PyArray_CheckAxis,
214
+ (void *) PyArray_OverflowMultiplyList,
215
+ NULL,
216
+ (void *) PyArray_MultiIterFromObjects,
217
+ (void *) PyArray_GetEndianness,
218
+ (void *) PyArray_GetNDArrayCFeatureVersion,
219
+ (void *) PyArray_Correlate2,
220
+ (void *) PyArray_NeighborhoodIterNew,
221
+ (void *) &PyTimeIntegerArrType_Type,
222
+ (void *) &PyDatetimeArrType_Type,
223
+ (void *) &PyTimedeltaArrType_Type,
224
+ (void *) &PyHalfArrType_Type,
225
+ (void *) &NpyIter_Type,
226
+ NULL,
227
+ NULL,
228
+ NULL,
229
+ NULL,
230
+ NULL,
231
+ (void *) NpyIter_New,
232
+ (void *) NpyIter_MultiNew,
233
+ (void *) NpyIter_AdvancedNew,
234
+ (void *) NpyIter_Copy,
235
+ (void *) NpyIter_Deallocate,
236
+ (void *) NpyIter_HasDelayedBufAlloc,
237
+ (void *) NpyIter_HasExternalLoop,
238
+ (void *) NpyIter_EnableExternalLoop,
239
+ (void *) NpyIter_GetInnerStrideArray,
240
+ (void *) NpyIter_GetInnerLoopSizePtr,
241
+ (void *) NpyIter_Reset,
242
+ (void *) NpyIter_ResetBasePointers,
243
+ (void *) NpyIter_ResetToIterIndexRange,
244
+ (void *) NpyIter_GetNDim,
245
+ (void *) NpyIter_GetNOp,
246
+ (void *) NpyIter_GetIterNext,
247
+ (void *) NpyIter_GetIterSize,
248
+ (void *) NpyIter_GetIterIndexRange,
249
+ (void *) NpyIter_GetIterIndex,
250
+ (void *) NpyIter_GotoIterIndex,
251
+ (void *) NpyIter_HasMultiIndex,
252
+ (void *) NpyIter_GetShape,
253
+ (void *) NpyIter_GetGetMultiIndex,
254
+ (void *) NpyIter_GotoMultiIndex,
255
+ (void *) NpyIter_RemoveMultiIndex,
256
+ (void *) NpyIter_HasIndex,
257
+ (void *) NpyIter_IsBuffered,
258
+ (void *) NpyIter_IsGrowInner,
259
+ (void *) NpyIter_GetBufferSize,
260
+ (void *) NpyIter_GetIndexPtr,
261
+ (void *) NpyIter_GotoIndex,
262
+ (void *) NpyIter_GetDataPtrArray,
263
+ (void *) NpyIter_GetDescrArray,
264
+ (void *) NpyIter_GetOperandArray,
265
+ (void *) NpyIter_GetIterView,
266
+ (void *) NpyIter_GetReadFlags,
267
+ (void *) NpyIter_GetWriteFlags,
268
+ (void *) NpyIter_DebugPrint,
269
+ (void *) NpyIter_IterationNeedsAPI,
270
+ (void *) NpyIter_GetInnerFixedStrideArray,
271
+ (void *) NpyIter_RemoveAxis,
272
+ (void *) NpyIter_GetAxisStrideArray,
273
+ (void *) NpyIter_RequiresBuffering,
274
+ (void *) NpyIter_GetInitialDataPtrArray,
275
+ (void *) NpyIter_CreateCompatibleStrides,
276
+ (void *) PyArray_CastingConverter,
277
+ (void *) PyArray_CountNonzero,
278
+ (void *) PyArray_PromoteTypes,
279
+ (void *) PyArray_MinScalarType,
280
+ (void *) PyArray_ResultType,
281
+ (void *) PyArray_CanCastArrayTo,
282
+ (void *) PyArray_CanCastTypeTo,
283
+ (void *) PyArray_EinsteinSum,
284
+ (void *) PyArray_NewLikeArray,
285
+ NULL,
286
+ (void *) PyArray_ConvertClipmodeSequence,
287
+ (void *) PyArray_MatrixProduct2,
288
+ (void *) NpyIter_IsFirstVisit,
289
+ (void *) PyArray_SetBaseObject,
290
+ (void *) PyArray_CreateSortedStridePerm,
291
+ (void *) PyArray_RemoveAxesInPlace,
292
+ (void *) PyArray_DebugPrint,
293
+ (void *) PyArray_FailUnlessWriteable,
294
+ (void *) PyArray_SetUpdateIfCopyBase,
295
+ (void *) PyDataMem_NEW,
296
+ (void *) PyDataMem_FREE,
297
+ (void *) PyDataMem_RENEW,
298
+ NULL,
299
+ (NPY_CASTING *) &NPY_DEFAULT_ASSIGN_CASTING,
300
+ NULL,
301
+ NULL,
302
+ NULL,
303
+ (void *) PyArray_Partition,
304
+ (void *) PyArray_ArgPartition,
305
+ (void *) PyArray_SelectkindConverter,
306
+ (void *) PyDataMem_NEW_ZEROED,
307
+ (void *) PyArray_CheckAnyScalarExact,
308
+ NULL,
309
+ (void *) PyArray_ResolveWritebackIfCopy,
310
+ (void *) PyArray_SetWritebackIfCopyBase,
311
+ (void *) PyDataMem_SetHandler,
312
+ (void *) PyDataMem_GetHandler,
313
+ (PyObject* *) &PyDataMem_DefaultHandler,
314
+ (void *) NpyDatetime_ConvertDatetime64ToDatetimeStruct,
315
+ (void *) NpyDatetime_ConvertDatetimeStructToDatetime64,
316
+ (void *) NpyDatetime_ConvertPyDateTimeToDatetimeStruct,
317
+ (void *) NpyDatetime_GetDatetimeISO8601StrLen,
318
+ (void *) NpyDatetime_MakeISO8601Datetime,
319
+ (void *) NpyDatetime_ParseISO8601Datetime,
320
+ (void *) NpyString_load,
321
+ (void *) NpyString_pack,
322
+ (void *) NpyString_pack_null,
323
+ (void *) NpyString_acquire_allocator,
324
+ (void *) NpyString_acquire_allocators,
325
+ (void *) NpyString_release_allocator,
326
+ (void *) NpyString_release_allocators,
327
+ NULL,
328
+ NULL,
329
+ NULL,
330
+ NULL,
331
+ NULL,
332
+ NULL,
333
+ NULL,
334
+ NULL,
335
+ NULL,
336
+ NULL,
337
+ NULL,
338
+ NULL,
339
+ NULL,
340
+ NULL,
341
+ NULL,
342
+ NULL,
343
+ NULL,
344
+ NULL,
345
+ NULL,
346
+ NULL,
347
+ NULL,
348
+ NULL,
349
+ NULL,
350
+ NULL,
351
+ NULL,
352
+ NULL,
353
+ NULL,
354
+ NULL,
355
+ NULL,
356
+ NULL,
357
+ NULL,
358
+ NULL,
359
+ NULL,
360
+ NULL,
361
+ NULL,
362
+ NULL,
363
+ NULL,
364
+ NULL,
365
+ NULL,
366
+ NULL,
367
+ NULL,
368
+ (void *) PyArray_GetDefaultDescr,
369
+ (void *) PyArrayInitDTypeMeta_FromSpec,
370
+ (void *) PyArray_CommonDType,
371
+ (void *) PyArray_PromoteDTypeSequence,
372
+ (void *) _PyDataType_GetArrFuncs,
373
+ NULL,
374
+ NULL,
375
+ NULL
376
+ };
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/__multiarray_api.h ADDED
@@ -0,0 +1,1613 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #if defined(_MULTIARRAYMODULE) || defined(WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE)
3
+
4
+ typedef struct {
5
+ PyObject_HEAD
6
+ npy_bool obval;
7
+ } PyBoolScalarObject;
8
+
9
+ extern NPY_NO_EXPORT PyTypeObject PyArrayNeighborhoodIter_Type;
10
+ extern NPY_NO_EXPORT PyBoolScalarObject _PyArrayScalar_BoolValues[2];
11
+
12
+ NPY_NO_EXPORT unsigned int PyArray_GetNDArrayCVersion \
13
+ (void);
14
+ extern NPY_NO_EXPORT PyTypeObject PyArray_Type;
15
+
16
+ extern NPY_NO_EXPORT PyArray_DTypeMeta PyArrayDescr_TypeFull;
17
+ #define PyArrayDescr_Type (*(PyTypeObject *)(&PyArrayDescr_TypeFull))
18
+
19
+ extern NPY_NO_EXPORT PyTypeObject PyArrayIter_Type;
20
+
21
+ extern NPY_NO_EXPORT PyTypeObject PyArrayMultiIter_Type;
22
+
23
+ extern NPY_NO_EXPORT int NPY_NUMUSERTYPES;
24
+
25
+ extern NPY_NO_EXPORT PyTypeObject PyBoolArrType_Type;
26
+
27
+ extern NPY_NO_EXPORT PyBoolScalarObject _PyArrayScalar_BoolValues[2];
28
+
29
+ extern NPY_NO_EXPORT PyTypeObject PyGenericArrType_Type;
30
+
31
+ extern NPY_NO_EXPORT PyTypeObject PyNumberArrType_Type;
32
+
33
+ extern NPY_NO_EXPORT PyTypeObject PyIntegerArrType_Type;
34
+
35
+ extern NPY_NO_EXPORT PyTypeObject PySignedIntegerArrType_Type;
36
+
37
+ extern NPY_NO_EXPORT PyTypeObject PyUnsignedIntegerArrType_Type;
38
+
39
+ extern NPY_NO_EXPORT PyTypeObject PyInexactArrType_Type;
40
+
41
+ extern NPY_NO_EXPORT PyTypeObject PyFloatingArrType_Type;
42
+
43
+ extern NPY_NO_EXPORT PyTypeObject PyComplexFloatingArrType_Type;
44
+
45
+ extern NPY_NO_EXPORT PyTypeObject PyFlexibleArrType_Type;
46
+
47
+ extern NPY_NO_EXPORT PyTypeObject PyCharacterArrType_Type;
48
+
49
+ extern NPY_NO_EXPORT PyTypeObject PyByteArrType_Type;
50
+
51
+ extern NPY_NO_EXPORT PyTypeObject PyShortArrType_Type;
52
+
53
+ extern NPY_NO_EXPORT PyTypeObject PyIntArrType_Type;
54
+
55
+ extern NPY_NO_EXPORT PyTypeObject PyLongArrType_Type;
56
+
57
+ extern NPY_NO_EXPORT PyTypeObject PyLongLongArrType_Type;
58
+
59
+ extern NPY_NO_EXPORT PyTypeObject PyUByteArrType_Type;
60
+
61
+ extern NPY_NO_EXPORT PyTypeObject PyUShortArrType_Type;
62
+
63
+ extern NPY_NO_EXPORT PyTypeObject PyUIntArrType_Type;
64
+
65
+ extern NPY_NO_EXPORT PyTypeObject PyULongArrType_Type;
66
+
67
+ extern NPY_NO_EXPORT PyTypeObject PyULongLongArrType_Type;
68
+
69
+ extern NPY_NO_EXPORT PyTypeObject PyFloatArrType_Type;
70
+
71
+ extern NPY_NO_EXPORT PyTypeObject PyDoubleArrType_Type;
72
+
73
+ extern NPY_NO_EXPORT PyTypeObject PyLongDoubleArrType_Type;
74
+
75
+ extern NPY_NO_EXPORT PyTypeObject PyCFloatArrType_Type;
76
+
77
+ extern NPY_NO_EXPORT PyTypeObject PyCDoubleArrType_Type;
78
+
79
+ extern NPY_NO_EXPORT PyTypeObject PyCLongDoubleArrType_Type;
80
+
81
+ extern NPY_NO_EXPORT PyTypeObject PyObjectArrType_Type;
82
+
83
+ extern NPY_NO_EXPORT PyTypeObject PyStringArrType_Type;
84
+
85
+ extern NPY_NO_EXPORT PyTypeObject PyUnicodeArrType_Type;
86
+
87
+ extern NPY_NO_EXPORT PyTypeObject PyVoidArrType_Type;
88
+
89
+ NPY_NO_EXPORT int PyArray_INCREF \
90
+ (PyArrayObject *);
91
+ NPY_NO_EXPORT int PyArray_XDECREF \
92
+ (PyArrayObject *);
93
+ NPY_NO_EXPORT void PyArray_SetStringFunction \
94
+ (PyObject *, int);
95
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrFromType \
96
+ (int);
97
+ NPY_NO_EXPORT PyObject * PyArray_TypeObjectFromType \
98
+ (int);
99
+ NPY_NO_EXPORT char * PyArray_Zero \
100
+ (PyArrayObject *);
101
+ NPY_NO_EXPORT char * PyArray_One \
102
+ (PyArrayObject *);
103
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_CastToType \
104
+ (PyArrayObject *, PyArray_Descr *, int);
105
+ NPY_NO_EXPORT int PyArray_CopyInto \
106
+ (PyArrayObject *, PyArrayObject *);
107
+ NPY_NO_EXPORT int PyArray_CopyAnyInto \
108
+ (PyArrayObject *, PyArrayObject *);
109
+ NPY_NO_EXPORT int PyArray_CanCastSafely \
110
+ (int, int);
111
+ NPY_NO_EXPORT npy_bool PyArray_CanCastTo \
112
+ (PyArray_Descr *, PyArray_Descr *);
113
+ NPY_NO_EXPORT int PyArray_ObjectType \
114
+ (PyObject *, int);
115
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrFromObject \
116
+ (PyObject *, PyArray_Descr *);
117
+ NPY_NO_EXPORT PyArrayObject ** PyArray_ConvertToCommonType \
118
+ (PyObject *, int *);
119
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrFromScalar \
120
+ (PyObject *);
121
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrFromTypeObject \
122
+ (PyObject *);
123
+ NPY_NO_EXPORT npy_intp PyArray_Size \
124
+ (PyObject *);
125
+ NPY_NO_EXPORT PyObject * PyArray_Scalar \
126
+ (void *, PyArray_Descr *, PyObject *);
127
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromScalar \
128
+ (PyObject *, PyArray_Descr *);
129
+ NPY_NO_EXPORT void PyArray_ScalarAsCtype \
130
+ (PyObject *, void *);
131
+ NPY_NO_EXPORT int PyArray_CastScalarToCtype \
132
+ (PyObject *, void *, PyArray_Descr *);
133
+ NPY_NO_EXPORT int PyArray_CastScalarDirect \
134
+ (PyObject *, PyArray_Descr *, void *, int);
135
+ NPY_NO_EXPORT int PyArray_Pack \
136
+ (PyArray_Descr *, void *, PyObject *);
137
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromAny \
138
+ (PyObject *, PyArray_Descr *, int, int, int, PyObject *);
139
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(1) PyObject * PyArray_EnsureArray \
140
+ (PyObject *);
141
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(1) PyObject * PyArray_EnsureAnyArray \
142
+ (PyObject *);
143
+ NPY_NO_EXPORT PyObject * PyArray_FromFile \
144
+ (FILE *, PyArray_Descr *, npy_intp, char *);
145
+ NPY_NO_EXPORT PyObject * PyArray_FromString \
146
+ (char *, npy_intp, PyArray_Descr *, npy_intp, char *);
147
+ NPY_NO_EXPORT PyObject * PyArray_FromBuffer \
148
+ (PyObject *, PyArray_Descr *, npy_intp, npy_intp);
149
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromIter \
150
+ (PyObject *, PyArray_Descr *, npy_intp);
151
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(1) PyObject * PyArray_Return \
152
+ (PyArrayObject *);
153
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_GetField \
154
+ (PyArrayObject *, PyArray_Descr *, int);
155
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) int PyArray_SetField \
156
+ (PyArrayObject *, PyArray_Descr *, int, PyObject *);
157
+ NPY_NO_EXPORT PyObject * PyArray_Byteswap \
158
+ (PyArrayObject *, npy_bool);
159
+ NPY_NO_EXPORT PyObject * PyArray_Resize \
160
+ (PyArrayObject *, PyArray_Dims *, int, NPY_ORDER NPY_UNUSED(order));
161
+ NPY_NO_EXPORT int PyArray_CopyObject \
162
+ (PyArrayObject *, PyObject *);
163
+ NPY_NO_EXPORT PyObject * PyArray_NewCopy \
164
+ (PyArrayObject *, NPY_ORDER);
165
+ NPY_NO_EXPORT PyObject * PyArray_ToList \
166
+ (PyArrayObject *);
167
+ NPY_NO_EXPORT PyObject * PyArray_ToString \
168
+ (PyArrayObject *, NPY_ORDER);
169
+ NPY_NO_EXPORT int PyArray_ToFile \
170
+ (PyArrayObject *, FILE *, char *, char *);
171
+ NPY_NO_EXPORT int PyArray_Dump \
172
+ (PyObject *, PyObject *, int);
173
+ NPY_NO_EXPORT PyObject * PyArray_Dumps \
174
+ (PyObject *, int);
175
+ NPY_NO_EXPORT int PyArray_ValidType \
176
+ (int);
177
+ NPY_NO_EXPORT void PyArray_UpdateFlags \
178
+ (PyArrayObject *, int);
179
+ NPY_NO_EXPORT PyObject * PyArray_New \
180
+ (PyTypeObject *, int, npy_intp const *, int, npy_intp const *, void *, int, int, PyObject *);
181
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_NewFromDescr \
182
+ (PyTypeObject *, PyArray_Descr *, int, npy_intp const *, npy_intp const *, void *, int, PyObject *);
183
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrNew \
184
+ (PyArray_Descr *);
185
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrNewFromType \
186
+ (int);
187
+ NPY_NO_EXPORT double PyArray_GetPriority \
188
+ (PyObject *, double);
189
+ NPY_NO_EXPORT PyObject * PyArray_IterNew \
190
+ (PyObject *);
191
+ NPY_NO_EXPORT PyObject* PyArray_MultiIterNew \
192
+ (int, ...);
193
+ NPY_NO_EXPORT int PyArray_PyIntAsInt \
194
+ (PyObject *);
195
+ NPY_NO_EXPORT npy_intp PyArray_PyIntAsIntp \
196
+ (PyObject *);
197
+ NPY_NO_EXPORT int PyArray_Broadcast \
198
+ (PyArrayMultiIterObject *);
199
+ NPY_NO_EXPORT int PyArray_FillWithScalar \
200
+ (PyArrayObject *, PyObject *);
201
+ NPY_NO_EXPORT npy_bool PyArray_CheckStrides \
202
+ (int, int, npy_intp, npy_intp, npy_intp const *, npy_intp const *);
203
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrNewByteorder \
204
+ (PyArray_Descr *, char);
205
+ NPY_NO_EXPORT PyObject * PyArray_IterAllButAxis \
206
+ (PyObject *, int *);
207
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_CheckFromAny \
208
+ (PyObject *, PyArray_Descr *, int, int, int, PyObject *);
209
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromArray \
210
+ (PyArrayObject *, PyArray_Descr *, int);
211
+ NPY_NO_EXPORT PyObject * PyArray_FromInterface \
212
+ (PyObject *);
213
+ NPY_NO_EXPORT PyObject * PyArray_FromStructInterface \
214
+ (PyObject *);
215
+ NPY_NO_EXPORT PyObject * PyArray_FromArrayAttr \
216
+ (PyObject *, PyArray_Descr *, PyObject *);
217
+ NPY_NO_EXPORT NPY_SCALARKIND PyArray_ScalarKind \
218
+ (int, PyArrayObject **);
219
+ NPY_NO_EXPORT int PyArray_CanCoerceScalar \
220
+ (int, int, NPY_SCALARKIND);
221
+ NPY_NO_EXPORT npy_bool PyArray_CanCastScalar \
222
+ (PyTypeObject *, PyTypeObject *);
223
+ NPY_NO_EXPORT int PyArray_RemoveSmallest \
224
+ (PyArrayMultiIterObject *);
225
+ NPY_NO_EXPORT int PyArray_ElementStrides \
226
+ (PyObject *);
227
+ NPY_NO_EXPORT void PyArray_Item_INCREF \
228
+ (char *, PyArray_Descr *);
229
+ NPY_NO_EXPORT void PyArray_Item_XDECREF \
230
+ (char *, PyArray_Descr *);
231
+ NPY_NO_EXPORT PyObject * PyArray_Transpose \
232
+ (PyArrayObject *, PyArray_Dims *);
233
+ NPY_NO_EXPORT PyObject * PyArray_TakeFrom \
234
+ (PyArrayObject *, PyObject *, int, PyArrayObject *, NPY_CLIPMODE);
235
+ NPY_NO_EXPORT PyObject * PyArray_PutTo \
236
+ (PyArrayObject *, PyObject*, PyObject *, NPY_CLIPMODE);
237
+ NPY_NO_EXPORT PyObject * PyArray_PutMask \
238
+ (PyArrayObject *, PyObject*, PyObject*);
239
+ NPY_NO_EXPORT PyObject * PyArray_Repeat \
240
+ (PyArrayObject *, PyObject *, int);
241
+ NPY_NO_EXPORT PyObject * PyArray_Choose \
242
+ (PyArrayObject *, PyObject *, PyArrayObject *, NPY_CLIPMODE);
243
+ NPY_NO_EXPORT int PyArray_Sort \
244
+ (PyArrayObject *, int, NPY_SORTKIND);
245
+ NPY_NO_EXPORT PyObject * PyArray_ArgSort \
246
+ (PyArrayObject *, int, NPY_SORTKIND);
247
+ NPY_NO_EXPORT PyObject * PyArray_SearchSorted \
248
+ (PyArrayObject *, PyObject *, NPY_SEARCHSIDE, PyObject *);
249
+ NPY_NO_EXPORT PyObject * PyArray_ArgMax \
250
+ (PyArrayObject *, int, PyArrayObject *);
251
+ NPY_NO_EXPORT PyObject * PyArray_ArgMin \
252
+ (PyArrayObject *, int, PyArrayObject *);
253
+ NPY_NO_EXPORT PyObject * PyArray_Reshape \
254
+ (PyArrayObject *, PyObject *);
255
+ NPY_NO_EXPORT PyObject * PyArray_Newshape \
256
+ (PyArrayObject *, PyArray_Dims *, NPY_ORDER);
257
+ NPY_NO_EXPORT PyObject * PyArray_Squeeze \
258
+ (PyArrayObject *);
259
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_View \
260
+ (PyArrayObject *, PyArray_Descr *, PyTypeObject *);
261
+ NPY_NO_EXPORT PyObject * PyArray_SwapAxes \
262
+ (PyArrayObject *, int, int);
263
+ NPY_NO_EXPORT PyObject * PyArray_Max \
264
+ (PyArrayObject *, int, PyArrayObject *);
265
+ NPY_NO_EXPORT PyObject * PyArray_Min \
266
+ (PyArrayObject *, int, PyArrayObject *);
267
+ NPY_NO_EXPORT PyObject * PyArray_Ptp \
268
+ (PyArrayObject *, int, PyArrayObject *);
269
+ NPY_NO_EXPORT PyObject * PyArray_Mean \
270
+ (PyArrayObject *, int, int, PyArrayObject *);
271
+ NPY_NO_EXPORT PyObject * PyArray_Trace \
272
+ (PyArrayObject *, int, int, int, int, PyArrayObject *);
273
+ NPY_NO_EXPORT PyObject * PyArray_Diagonal \
274
+ (PyArrayObject *, int, int, int);
275
+ NPY_NO_EXPORT PyObject * PyArray_Clip \
276
+ (PyArrayObject *, PyObject *, PyObject *, PyArrayObject *);
277
+ NPY_NO_EXPORT PyObject * PyArray_Conjugate \
278
+ (PyArrayObject *, PyArrayObject *);
279
+ NPY_NO_EXPORT PyObject * PyArray_Nonzero \
280
+ (PyArrayObject *);
281
+ NPY_NO_EXPORT PyObject * PyArray_Std \
282
+ (PyArrayObject *, int, int, PyArrayObject *, int);
283
+ NPY_NO_EXPORT PyObject * PyArray_Sum \
284
+ (PyArrayObject *, int, int, PyArrayObject *);
285
+ NPY_NO_EXPORT PyObject * PyArray_CumSum \
286
+ (PyArrayObject *, int, int, PyArrayObject *);
287
+ NPY_NO_EXPORT PyObject * PyArray_Prod \
288
+ (PyArrayObject *, int, int, PyArrayObject *);
289
+ NPY_NO_EXPORT PyObject * PyArray_CumProd \
290
+ (PyArrayObject *, int, int, PyArrayObject *);
291
+ NPY_NO_EXPORT PyObject * PyArray_All \
292
+ (PyArrayObject *, int, PyArrayObject *);
293
+ NPY_NO_EXPORT PyObject * PyArray_Any \
294
+ (PyArrayObject *, int, PyArrayObject *);
295
+ NPY_NO_EXPORT PyObject * PyArray_Compress \
296
+ (PyArrayObject *, PyObject *, int, PyArrayObject *);
297
+ NPY_NO_EXPORT PyObject * PyArray_Flatten \
298
+ (PyArrayObject *, NPY_ORDER);
299
+ NPY_NO_EXPORT PyObject * PyArray_Ravel \
300
+ (PyArrayObject *, NPY_ORDER);
301
+ NPY_NO_EXPORT npy_intp PyArray_MultiplyList \
302
+ (npy_intp const *, int);
303
+ NPY_NO_EXPORT int PyArray_MultiplyIntList \
304
+ (int const *, int);
305
+ NPY_NO_EXPORT void * PyArray_GetPtr \
306
+ (PyArrayObject *, npy_intp const*);
307
+ NPY_NO_EXPORT int PyArray_CompareLists \
308
+ (npy_intp const *, npy_intp const *, int);
309
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(5) int PyArray_AsCArray \
310
+ (PyObject **, void *, npy_intp *, int, PyArray_Descr*);
311
+ NPY_NO_EXPORT int PyArray_Free \
312
+ (PyObject *, void *);
313
+ NPY_NO_EXPORT int PyArray_Converter \
314
+ (PyObject *, PyObject **);
315
+ NPY_NO_EXPORT int PyArray_IntpFromSequence \
316
+ (PyObject *, npy_intp *, int);
317
+ NPY_NO_EXPORT PyObject * PyArray_Concatenate \
318
+ (PyObject *, int);
319
+ NPY_NO_EXPORT PyObject * PyArray_InnerProduct \
320
+ (PyObject *, PyObject *);
321
+ NPY_NO_EXPORT PyObject * PyArray_MatrixProduct \
322
+ (PyObject *, PyObject *);
323
+ NPY_NO_EXPORT PyObject * PyArray_Correlate \
324
+ (PyObject *, PyObject *, int);
325
+ NPY_NO_EXPORT int PyArray_DescrConverter \
326
+ (PyObject *, PyArray_Descr **);
327
+ NPY_NO_EXPORT int PyArray_DescrConverter2 \
328
+ (PyObject *, PyArray_Descr **);
329
+ NPY_NO_EXPORT int PyArray_IntpConverter \
330
+ (PyObject *, PyArray_Dims *);
331
+ NPY_NO_EXPORT int PyArray_BufferConverter \
332
+ (PyObject *, PyArray_Chunk *);
333
+ NPY_NO_EXPORT int PyArray_AxisConverter \
334
+ (PyObject *, int *);
335
+ NPY_NO_EXPORT int PyArray_BoolConverter \
336
+ (PyObject *, npy_bool *);
337
+ NPY_NO_EXPORT int PyArray_ByteorderConverter \
338
+ (PyObject *, char *);
339
+ NPY_NO_EXPORT int PyArray_OrderConverter \
340
+ (PyObject *, NPY_ORDER *);
341
+ NPY_NO_EXPORT unsigned char PyArray_EquivTypes \
342
+ (PyArray_Descr *, PyArray_Descr *);
343
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_Zeros \
344
+ (int, npy_intp const *, PyArray_Descr *, int);
345
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_Empty \
346
+ (int, npy_intp const *, PyArray_Descr *, int);
347
+ NPY_NO_EXPORT PyObject * PyArray_Where \
348
+ (PyObject *, PyObject *, PyObject *);
349
+ NPY_NO_EXPORT PyObject * PyArray_Arange \
350
+ (double, double, double, int);
351
+ NPY_NO_EXPORT PyObject * PyArray_ArangeObj \
352
+ (PyObject *, PyObject *, PyObject *, PyArray_Descr *);
353
+ NPY_NO_EXPORT int PyArray_SortkindConverter \
354
+ (PyObject *, NPY_SORTKIND *);
355
+ NPY_NO_EXPORT PyObject * PyArray_LexSort \
356
+ (PyObject *, int);
357
+ NPY_NO_EXPORT PyObject * PyArray_Round \
358
+ (PyArrayObject *, int, PyArrayObject *);
359
+ NPY_NO_EXPORT unsigned char PyArray_EquivTypenums \
360
+ (int, int);
361
+ NPY_NO_EXPORT int PyArray_RegisterDataType \
362
+ (PyArray_DescrProto *);
363
+ NPY_NO_EXPORT int PyArray_RegisterCastFunc \
364
+ (PyArray_Descr *, int, PyArray_VectorUnaryFunc *);
365
+ NPY_NO_EXPORT int PyArray_RegisterCanCast \
366
+ (PyArray_Descr *, int, NPY_SCALARKIND);
367
+ NPY_NO_EXPORT void PyArray_InitArrFuncs \
368
+ (PyArray_ArrFuncs *);
369
+ NPY_NO_EXPORT PyObject * PyArray_IntTupleFromIntp \
370
+ (int, npy_intp const *);
371
+ NPY_NO_EXPORT int PyArray_ClipmodeConverter \
372
+ (PyObject *, NPY_CLIPMODE *);
373
+ NPY_NO_EXPORT int PyArray_OutputConverter \
374
+ (PyObject *, PyArrayObject **);
375
+ NPY_NO_EXPORT PyObject * PyArray_BroadcastToShape \
376
+ (PyObject *, npy_intp *, int);
377
+ NPY_NO_EXPORT int PyArray_DescrAlignConverter \
378
+ (PyObject *, PyArray_Descr **);
379
+ NPY_NO_EXPORT int PyArray_DescrAlignConverter2 \
380
+ (PyObject *, PyArray_Descr **);
381
+ NPY_NO_EXPORT int PyArray_SearchsideConverter \
382
+ (PyObject *, void *);
383
+ NPY_NO_EXPORT PyObject * PyArray_CheckAxis \
384
+ (PyArrayObject *, int *, int);
385
+ NPY_NO_EXPORT npy_intp PyArray_OverflowMultiplyList \
386
+ (npy_intp const *, int);
387
+ NPY_NO_EXPORT PyObject* PyArray_MultiIterFromObjects \
388
+ (PyObject **, int, int, ...);
389
+ NPY_NO_EXPORT int PyArray_GetEndianness \
390
+ (void);
391
+ NPY_NO_EXPORT unsigned int PyArray_GetNDArrayCFeatureVersion \
392
+ (void);
393
+ NPY_NO_EXPORT PyObject * PyArray_Correlate2 \
394
+ (PyObject *, PyObject *, int);
395
+ NPY_NO_EXPORT PyObject* PyArray_NeighborhoodIterNew \
396
+ (PyArrayIterObject *, const npy_intp *, int, PyArrayObject*);
397
+ extern NPY_NO_EXPORT PyTypeObject PyTimeIntegerArrType_Type;
398
+
399
+ extern NPY_NO_EXPORT PyTypeObject PyDatetimeArrType_Type;
400
+
401
+ extern NPY_NO_EXPORT PyTypeObject PyTimedeltaArrType_Type;
402
+
403
+ extern NPY_NO_EXPORT PyTypeObject PyHalfArrType_Type;
404
+
405
+ extern NPY_NO_EXPORT PyTypeObject NpyIter_Type;
406
+
407
+ NPY_NO_EXPORT NpyIter * NpyIter_New \
408
+ (PyArrayObject *, npy_uint32, NPY_ORDER, NPY_CASTING, PyArray_Descr*);
409
+ NPY_NO_EXPORT NpyIter * NpyIter_MultiNew \
410
+ (int, PyArrayObject **, npy_uint32, NPY_ORDER, NPY_CASTING, npy_uint32 *, PyArray_Descr **);
411
+ NPY_NO_EXPORT NpyIter * NpyIter_AdvancedNew \
412
+ (int, PyArrayObject **, npy_uint32, NPY_ORDER, NPY_CASTING, npy_uint32 *, PyArray_Descr **, int, int **, npy_intp *, npy_intp);
413
+ NPY_NO_EXPORT NpyIter * NpyIter_Copy \
414
+ (NpyIter *);
415
+ NPY_NO_EXPORT int NpyIter_Deallocate \
416
+ (NpyIter *);
417
+ NPY_NO_EXPORT npy_bool NpyIter_HasDelayedBufAlloc \
418
+ (NpyIter *);
419
+ NPY_NO_EXPORT npy_bool NpyIter_HasExternalLoop \
420
+ (NpyIter *);
421
+ NPY_NO_EXPORT int NpyIter_EnableExternalLoop \
422
+ (NpyIter *);
423
+ NPY_NO_EXPORT npy_intp * NpyIter_GetInnerStrideArray \
424
+ (NpyIter *);
425
+ NPY_NO_EXPORT npy_intp * NpyIter_GetInnerLoopSizePtr \
426
+ (NpyIter *);
427
+ NPY_NO_EXPORT int NpyIter_Reset \
428
+ (NpyIter *, char **);
429
+ NPY_NO_EXPORT int NpyIter_ResetBasePointers \
430
+ (NpyIter *, char **, char **);
431
+ NPY_NO_EXPORT int NpyIter_ResetToIterIndexRange \
432
+ (NpyIter *, npy_intp, npy_intp, char **);
433
+ NPY_NO_EXPORT int NpyIter_GetNDim \
434
+ (NpyIter *);
435
+ NPY_NO_EXPORT int NpyIter_GetNOp \
436
+ (NpyIter *);
437
+ NPY_NO_EXPORT NpyIter_IterNextFunc * NpyIter_GetIterNext \
438
+ (NpyIter *, char **);
439
+ NPY_NO_EXPORT npy_intp NpyIter_GetIterSize \
440
+ (NpyIter *);
441
+ NPY_NO_EXPORT void NpyIter_GetIterIndexRange \
442
+ (NpyIter *, npy_intp *, npy_intp *);
443
+ NPY_NO_EXPORT npy_intp NpyIter_GetIterIndex \
444
+ (NpyIter *);
445
+ NPY_NO_EXPORT int NpyIter_GotoIterIndex \
446
+ (NpyIter *, npy_intp);
447
+ NPY_NO_EXPORT npy_bool NpyIter_HasMultiIndex \
448
+ (NpyIter *);
449
+ NPY_NO_EXPORT int NpyIter_GetShape \
450
+ (NpyIter *, npy_intp *);
451
+ NPY_NO_EXPORT NpyIter_GetMultiIndexFunc * NpyIter_GetGetMultiIndex \
452
+ (NpyIter *, char **);
453
+ NPY_NO_EXPORT int NpyIter_GotoMultiIndex \
454
+ (NpyIter *, npy_intp const *);
455
+ NPY_NO_EXPORT int NpyIter_RemoveMultiIndex \
456
+ (NpyIter *);
457
+ NPY_NO_EXPORT npy_bool NpyIter_HasIndex \
458
+ (NpyIter *);
459
+ NPY_NO_EXPORT npy_bool NpyIter_IsBuffered \
460
+ (NpyIter *);
461
+ NPY_NO_EXPORT npy_bool NpyIter_IsGrowInner \
462
+ (NpyIter *);
463
+ NPY_NO_EXPORT npy_intp NpyIter_GetBufferSize \
464
+ (NpyIter *);
465
+ NPY_NO_EXPORT npy_intp * NpyIter_GetIndexPtr \
466
+ (NpyIter *);
467
+ NPY_NO_EXPORT int NpyIter_GotoIndex \
468
+ (NpyIter *, npy_intp);
469
+ NPY_NO_EXPORT char ** NpyIter_GetDataPtrArray \
470
+ (NpyIter *);
471
+ NPY_NO_EXPORT PyArray_Descr ** NpyIter_GetDescrArray \
472
+ (NpyIter *);
473
+ NPY_NO_EXPORT PyArrayObject ** NpyIter_GetOperandArray \
474
+ (NpyIter *);
475
+ NPY_NO_EXPORT PyArrayObject * NpyIter_GetIterView \
476
+ (NpyIter *, npy_intp);
477
+ NPY_NO_EXPORT void NpyIter_GetReadFlags \
478
+ (NpyIter *, char *);
479
+ NPY_NO_EXPORT void NpyIter_GetWriteFlags \
480
+ (NpyIter *, char *);
481
+ NPY_NO_EXPORT void NpyIter_DebugPrint \
482
+ (NpyIter *);
483
+ NPY_NO_EXPORT npy_bool NpyIter_IterationNeedsAPI \
484
+ (NpyIter *);
485
+ NPY_NO_EXPORT void NpyIter_GetInnerFixedStrideArray \
486
+ (NpyIter *, npy_intp *);
487
+ NPY_NO_EXPORT int NpyIter_RemoveAxis \
488
+ (NpyIter *, int);
489
+ NPY_NO_EXPORT npy_intp * NpyIter_GetAxisStrideArray \
490
+ (NpyIter *, int);
491
+ NPY_NO_EXPORT npy_bool NpyIter_RequiresBuffering \
492
+ (NpyIter *);
493
+ NPY_NO_EXPORT char ** NpyIter_GetInitialDataPtrArray \
494
+ (NpyIter *);
495
+ NPY_NO_EXPORT int NpyIter_CreateCompatibleStrides \
496
+ (NpyIter *, npy_intp, npy_intp *);
497
+ NPY_NO_EXPORT int PyArray_CastingConverter \
498
+ (PyObject *, NPY_CASTING *);
499
+ NPY_NO_EXPORT npy_intp PyArray_CountNonzero \
500
+ (PyArrayObject *);
501
+ NPY_NO_EXPORT PyArray_Descr * PyArray_PromoteTypes \
502
+ (PyArray_Descr *, PyArray_Descr *);
503
+ NPY_NO_EXPORT PyArray_Descr * PyArray_MinScalarType \
504
+ (PyArrayObject *);
505
+ NPY_NO_EXPORT PyArray_Descr * PyArray_ResultType \
506
+ (npy_intp, PyArrayObject *arrs[], npy_intp, PyArray_Descr *descrs[]);
507
+ NPY_NO_EXPORT npy_bool PyArray_CanCastArrayTo \
508
+ (PyArrayObject *, PyArray_Descr *, NPY_CASTING);
509
+ NPY_NO_EXPORT npy_bool PyArray_CanCastTypeTo \
510
+ (PyArray_Descr *, PyArray_Descr *, NPY_CASTING);
511
+ NPY_NO_EXPORT PyArrayObject * PyArray_EinsteinSum \
512
+ (char *, npy_intp, PyArrayObject **, PyArray_Descr *, NPY_ORDER, NPY_CASTING, PyArrayObject *);
513
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_NewLikeArray \
514
+ (PyArrayObject *, NPY_ORDER, PyArray_Descr *, int);
515
+ NPY_NO_EXPORT int PyArray_ConvertClipmodeSequence \
516
+ (PyObject *, NPY_CLIPMODE *, int);
517
+ NPY_NO_EXPORT PyObject * PyArray_MatrixProduct2 \
518
+ (PyObject *, PyObject *, PyArrayObject*);
519
+ NPY_NO_EXPORT npy_bool NpyIter_IsFirstVisit \
520
+ (NpyIter *, int);
521
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) int PyArray_SetBaseObject \
522
+ (PyArrayObject *, PyObject *);
523
+ NPY_NO_EXPORT void PyArray_CreateSortedStridePerm \
524
+ (int, npy_intp const *, npy_stride_sort_item *);
525
+ NPY_NO_EXPORT void PyArray_RemoveAxesInPlace \
526
+ (PyArrayObject *, const npy_bool *);
527
+ NPY_NO_EXPORT void PyArray_DebugPrint \
528
+ (PyArrayObject *);
529
+ NPY_NO_EXPORT int PyArray_FailUnlessWriteable \
530
+ (PyArrayObject *, const char *);
531
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) int PyArray_SetUpdateIfCopyBase \
532
+ (PyArrayObject *, PyArrayObject *);
533
+ NPY_NO_EXPORT void * PyDataMem_NEW \
534
+ (size_t);
535
+ NPY_NO_EXPORT void PyDataMem_FREE \
536
+ (void *);
537
+ NPY_NO_EXPORT void * PyDataMem_RENEW \
538
+ (void *, size_t);
539
+ extern NPY_NO_EXPORT NPY_CASTING NPY_DEFAULT_ASSIGN_CASTING;
540
+
541
+ NPY_NO_EXPORT int PyArray_Partition \
542
+ (PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND);
543
+ NPY_NO_EXPORT PyObject * PyArray_ArgPartition \
544
+ (PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND);
545
+ NPY_NO_EXPORT int PyArray_SelectkindConverter \
546
+ (PyObject *, NPY_SELECTKIND *);
547
+ NPY_NO_EXPORT void * PyDataMem_NEW_ZEROED \
548
+ (size_t, size_t);
549
+ NPY_NO_EXPORT int PyArray_CheckAnyScalarExact \
550
+ (PyObject *);
551
+ NPY_NO_EXPORT int PyArray_ResolveWritebackIfCopy \
552
+ (PyArrayObject *);
553
+ NPY_NO_EXPORT int PyArray_SetWritebackIfCopyBase \
554
+ (PyArrayObject *, PyArrayObject *);
555
+ NPY_NO_EXPORT PyObject * PyDataMem_SetHandler \
556
+ (PyObject *);
557
+ NPY_NO_EXPORT PyObject * PyDataMem_GetHandler \
558
+ (void);
559
+ extern NPY_NO_EXPORT PyObject* PyDataMem_DefaultHandler;
560
+
561
+ NPY_NO_EXPORT int NpyDatetime_ConvertDatetime64ToDatetimeStruct \
562
+ (PyArray_DatetimeMetaData *, npy_datetime, npy_datetimestruct *);
563
+ NPY_NO_EXPORT int NpyDatetime_ConvertDatetimeStructToDatetime64 \
564
+ (PyArray_DatetimeMetaData *, const npy_datetimestruct *, npy_datetime *);
565
+ NPY_NO_EXPORT int NpyDatetime_ConvertPyDateTimeToDatetimeStruct \
566
+ (PyObject *, npy_datetimestruct *, NPY_DATETIMEUNIT *, int);
567
+ NPY_NO_EXPORT int NpyDatetime_GetDatetimeISO8601StrLen \
568
+ (int, NPY_DATETIMEUNIT);
569
+ NPY_NO_EXPORT int NpyDatetime_MakeISO8601Datetime \
570
+ (npy_datetimestruct *, char *, npy_intp, int, int, NPY_DATETIMEUNIT, int, NPY_CASTING);
571
+ NPY_NO_EXPORT int NpyDatetime_ParseISO8601Datetime \
572
+ (char const *, Py_ssize_t, NPY_DATETIMEUNIT, NPY_CASTING, npy_datetimestruct *, NPY_DATETIMEUNIT *, npy_bool *);
573
+ NPY_NO_EXPORT int NpyString_load \
574
+ (npy_string_allocator *, const npy_packed_static_string *, npy_static_string *);
575
+ NPY_NO_EXPORT int NpyString_pack \
576
+ (npy_string_allocator *, npy_packed_static_string *, const char *, size_t);
577
+ NPY_NO_EXPORT int NpyString_pack_null \
578
+ (npy_string_allocator *, npy_packed_static_string *);
579
+ NPY_NO_EXPORT npy_string_allocator * NpyString_acquire_allocator \
580
+ (const PyArray_StringDTypeObject *);
581
+ NPY_NO_EXPORT void NpyString_acquire_allocators \
582
+ (size_t, PyArray_Descr *const descrs[], npy_string_allocator *allocators[]);
583
+ NPY_NO_EXPORT void NpyString_release_allocator \
584
+ (npy_string_allocator *);
585
+ NPY_NO_EXPORT void NpyString_release_allocators \
586
+ (size_t, npy_string_allocator *allocators[]);
587
+ NPY_NO_EXPORT PyArray_Descr * PyArray_GetDefaultDescr \
588
+ (PyArray_DTypeMeta *);
589
+ NPY_NO_EXPORT int PyArrayInitDTypeMeta_FromSpec \
590
+ (PyArray_DTypeMeta *, PyArrayDTypeMeta_Spec *);
591
+ NPY_NO_EXPORT PyArray_DTypeMeta * PyArray_CommonDType \
592
+ (PyArray_DTypeMeta *, PyArray_DTypeMeta *);
593
+ NPY_NO_EXPORT PyArray_DTypeMeta * PyArray_PromoteDTypeSequence \
594
+ (npy_intp, PyArray_DTypeMeta **);
595
+ NPY_NO_EXPORT PyArray_ArrFuncs * _PyDataType_GetArrFuncs \
596
+ (const PyArray_Descr *);
597
+
598
+ #else
599
+
600
+ #if defined(PY_ARRAY_UNIQUE_SYMBOL)
601
+ #define PyArray_API PY_ARRAY_UNIQUE_SYMBOL
602
+ #define _NPY_VERSION_CONCAT_HELPER2(x, y) x ## y
603
+ #define _NPY_VERSION_CONCAT_HELPER(arg) \
604
+ _NPY_VERSION_CONCAT_HELPER2(arg, PyArray_RUNTIME_VERSION)
605
+ #define PyArray_RUNTIME_VERSION \
606
+ _NPY_VERSION_CONCAT_HELPER(PY_ARRAY_UNIQUE_SYMBOL)
607
+ #endif
608
+
609
+ /* By default do not export API in an .so (was never the case on windows) */
610
+ #ifndef NPY_API_SYMBOL_ATTRIBUTE
611
+ #define NPY_API_SYMBOL_ATTRIBUTE NPY_VISIBILITY_HIDDEN
612
+ #endif
613
+
614
+ #if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
615
+ extern NPY_API_SYMBOL_ATTRIBUTE void **PyArray_API;
616
+ extern NPY_API_SYMBOL_ATTRIBUTE int PyArray_RUNTIME_VERSION;
617
+ #else
618
+ #if defined(PY_ARRAY_UNIQUE_SYMBOL)
619
+ NPY_API_SYMBOL_ATTRIBUTE void **PyArray_API;
620
+ NPY_API_SYMBOL_ATTRIBUTE int PyArray_RUNTIME_VERSION;
621
+ #else
622
+ static void **PyArray_API = NULL;
623
+ static int PyArray_RUNTIME_VERSION = 0;
624
+ #endif
625
+ #endif
626
+
627
+ #define PyArray_GetNDArrayCVersion \
628
+ (*(unsigned int (*)(void)) \
629
+ PyArray_API[0])
630
+ #define PyArray_Type (*(PyTypeObject *)PyArray_API[2])
631
+ #define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[3])
632
+ #define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[5])
633
+ #define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[6])
634
+ #define NPY_NUMUSERTYPES (*(int *)PyArray_API[7])
635
+ #define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[8])
636
+ #define _PyArrayScalar_BoolValues ((PyBoolScalarObject *)PyArray_API[9])
637
+ #define PyGenericArrType_Type (*(PyTypeObject *)PyArray_API[10])
638
+ #define PyNumberArrType_Type (*(PyTypeObject *)PyArray_API[11])
639
+ #define PyIntegerArrType_Type (*(PyTypeObject *)PyArray_API[12])
640
+ #define PySignedIntegerArrType_Type (*(PyTypeObject *)PyArray_API[13])
641
+ #define PyUnsignedIntegerArrType_Type (*(PyTypeObject *)PyArray_API[14])
642
+ #define PyInexactArrType_Type (*(PyTypeObject *)PyArray_API[15])
643
+ #define PyFloatingArrType_Type (*(PyTypeObject *)PyArray_API[16])
644
+ #define PyComplexFloatingArrType_Type (*(PyTypeObject *)PyArray_API[17])
645
+ #define PyFlexibleArrType_Type (*(PyTypeObject *)PyArray_API[18])
646
+ #define PyCharacterArrType_Type (*(PyTypeObject *)PyArray_API[19])
647
+ #define PyByteArrType_Type (*(PyTypeObject *)PyArray_API[20])
648
+ #define PyShortArrType_Type (*(PyTypeObject *)PyArray_API[21])
649
+ #define PyIntArrType_Type (*(PyTypeObject *)PyArray_API[22])
650
+ #define PyLongArrType_Type (*(PyTypeObject *)PyArray_API[23])
651
+ #define PyLongLongArrType_Type (*(PyTypeObject *)PyArray_API[24])
652
+ #define PyUByteArrType_Type (*(PyTypeObject *)PyArray_API[25])
653
+ #define PyUShortArrType_Type (*(PyTypeObject *)PyArray_API[26])
654
+ #define PyUIntArrType_Type (*(PyTypeObject *)PyArray_API[27])
655
+ #define PyULongArrType_Type (*(PyTypeObject *)PyArray_API[28])
656
+ #define PyULongLongArrType_Type (*(PyTypeObject *)PyArray_API[29])
657
+ #define PyFloatArrType_Type (*(PyTypeObject *)PyArray_API[30])
658
+ #define PyDoubleArrType_Type (*(PyTypeObject *)PyArray_API[31])
659
+ #define PyLongDoubleArrType_Type (*(PyTypeObject *)PyArray_API[32])
660
+ #define PyCFloatArrType_Type (*(PyTypeObject *)PyArray_API[33])
661
+ #define PyCDoubleArrType_Type (*(PyTypeObject *)PyArray_API[34])
662
+ #define PyCLongDoubleArrType_Type (*(PyTypeObject *)PyArray_API[35])
663
+ #define PyObjectArrType_Type (*(PyTypeObject *)PyArray_API[36])
664
+ #define PyStringArrType_Type (*(PyTypeObject *)PyArray_API[37])
665
+ #define PyUnicodeArrType_Type (*(PyTypeObject *)PyArray_API[38])
666
+ #define PyVoidArrType_Type (*(PyTypeObject *)PyArray_API[39])
667
+ #define PyArray_INCREF \
668
+ (*(int (*)(PyArrayObject *)) \
669
+ PyArray_API[42])
670
+ #define PyArray_XDECREF \
671
+ (*(int (*)(PyArrayObject *)) \
672
+ PyArray_API[43])
673
+ #define PyArray_SetStringFunction \
674
+ (*(void (*)(PyObject *, int)) \
675
+ PyArray_API[44])
676
+ #define PyArray_DescrFromType \
677
+ (*(PyArray_Descr * (*)(int)) \
678
+ PyArray_API[45])
679
+ #define PyArray_TypeObjectFromType \
680
+ (*(PyObject * (*)(int)) \
681
+ PyArray_API[46])
682
+ #define PyArray_Zero \
683
+ (*(char * (*)(PyArrayObject *)) \
684
+ PyArray_API[47])
685
+ #define PyArray_One \
686
+ (*(char * (*)(PyArrayObject *)) \
687
+ PyArray_API[48])
688
+ #define PyArray_CastToType \
689
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Descr *, int)) \
690
+ PyArray_API[49])
691
+ #define PyArray_CopyInto \
692
+ (*(int (*)(PyArrayObject *, PyArrayObject *)) \
693
+ PyArray_API[50])
694
+ #define PyArray_CopyAnyInto \
695
+ (*(int (*)(PyArrayObject *, PyArrayObject *)) \
696
+ PyArray_API[51])
697
+ #define PyArray_CanCastSafely \
698
+ (*(int (*)(int, int)) \
699
+ PyArray_API[52])
700
+ #define PyArray_CanCastTo \
701
+ (*(npy_bool (*)(PyArray_Descr *, PyArray_Descr *)) \
702
+ PyArray_API[53])
703
+ #define PyArray_ObjectType \
704
+ (*(int (*)(PyObject *, int)) \
705
+ PyArray_API[54])
706
+ #define PyArray_DescrFromObject \
707
+ (*(PyArray_Descr * (*)(PyObject *, PyArray_Descr *)) \
708
+ PyArray_API[55])
709
+ #define PyArray_ConvertToCommonType \
710
+ (*(PyArrayObject ** (*)(PyObject *, int *)) \
711
+ PyArray_API[56])
712
+ #define PyArray_DescrFromScalar \
713
+ (*(PyArray_Descr * (*)(PyObject *)) \
714
+ PyArray_API[57])
715
+ #define PyArray_DescrFromTypeObject \
716
+ (*(PyArray_Descr * (*)(PyObject *)) \
717
+ PyArray_API[58])
718
+ #define PyArray_Size \
719
+ (*(npy_intp (*)(PyObject *)) \
720
+ PyArray_API[59])
721
+ #define PyArray_Scalar \
722
+ (*(PyObject * (*)(void *, PyArray_Descr *, PyObject *)) \
723
+ PyArray_API[60])
724
+ #define PyArray_FromScalar \
725
+ (*(PyObject * (*)(PyObject *, PyArray_Descr *)) \
726
+ PyArray_API[61])
727
+ #define PyArray_ScalarAsCtype \
728
+ (*(void (*)(PyObject *, void *)) \
729
+ PyArray_API[62])
730
+ #define PyArray_CastScalarToCtype \
731
+ (*(int (*)(PyObject *, void *, PyArray_Descr *)) \
732
+ PyArray_API[63])
733
+ #define PyArray_CastScalarDirect \
734
+ (*(int (*)(PyObject *, PyArray_Descr *, void *, int)) \
735
+ PyArray_API[64])
736
+
737
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
738
+ #define PyArray_Pack \
739
+ (*(int (*)(PyArray_Descr *, void *, PyObject *)) \
740
+ PyArray_API[65])
741
+ #endif
742
+ #define PyArray_FromAny \
743
+ (*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) \
744
+ PyArray_API[69])
745
+ #define PyArray_EnsureArray \
746
+ (*(PyObject * (*)(PyObject *)) \
747
+ PyArray_API[70])
748
+ #define PyArray_EnsureAnyArray \
749
+ (*(PyObject * (*)(PyObject *)) \
750
+ PyArray_API[71])
751
+ #define PyArray_FromFile \
752
+ (*(PyObject * (*)(FILE *, PyArray_Descr *, npy_intp, char *)) \
753
+ PyArray_API[72])
754
+ #define PyArray_FromString \
755
+ (*(PyObject * (*)(char *, npy_intp, PyArray_Descr *, npy_intp, char *)) \
756
+ PyArray_API[73])
757
+ #define PyArray_FromBuffer \
758
+ (*(PyObject * (*)(PyObject *, PyArray_Descr *, npy_intp, npy_intp)) \
759
+ PyArray_API[74])
760
+ #define PyArray_FromIter \
761
+ (*(PyObject * (*)(PyObject *, PyArray_Descr *, npy_intp)) \
762
+ PyArray_API[75])
763
+ #define PyArray_Return \
764
+ (*(PyObject * (*)(PyArrayObject *)) \
765
+ PyArray_API[76])
766
+ #define PyArray_GetField \
767
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Descr *, int)) \
768
+ PyArray_API[77])
769
+ #define PyArray_SetField \
770
+ (*(int (*)(PyArrayObject *, PyArray_Descr *, int, PyObject *)) \
771
+ PyArray_API[78])
772
+ #define PyArray_Byteswap \
773
+ (*(PyObject * (*)(PyArrayObject *, npy_bool)) \
774
+ PyArray_API[79])
775
+ #define PyArray_Resize \
776
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Dims *, int, NPY_ORDER NPY_UNUSED(order))) \
777
+ PyArray_API[80])
778
+ #define PyArray_CopyObject \
779
+ (*(int (*)(PyArrayObject *, PyObject *)) \
780
+ PyArray_API[84])
781
+ #define PyArray_NewCopy \
782
+ (*(PyObject * (*)(PyArrayObject *, NPY_ORDER)) \
783
+ PyArray_API[85])
784
+ #define PyArray_ToList \
785
+ (*(PyObject * (*)(PyArrayObject *)) \
786
+ PyArray_API[86])
787
+ #define PyArray_ToString \
788
+ (*(PyObject * (*)(PyArrayObject *, NPY_ORDER)) \
789
+ PyArray_API[87])
790
+ #define PyArray_ToFile \
791
+ (*(int (*)(PyArrayObject *, FILE *, char *, char *)) \
792
+ PyArray_API[88])
793
+ #define PyArray_Dump \
794
+ (*(int (*)(PyObject *, PyObject *, int)) \
795
+ PyArray_API[89])
796
+ #define PyArray_Dumps \
797
+ (*(PyObject * (*)(PyObject *, int)) \
798
+ PyArray_API[90])
799
+ #define PyArray_ValidType \
800
+ (*(int (*)(int)) \
801
+ PyArray_API[91])
802
+ #define PyArray_UpdateFlags \
803
+ (*(void (*)(PyArrayObject *, int)) \
804
+ PyArray_API[92])
805
+ #define PyArray_New \
806
+ (*(PyObject * (*)(PyTypeObject *, int, npy_intp const *, int, npy_intp const *, void *, int, int, PyObject *)) \
807
+ PyArray_API[93])
808
+ #define PyArray_NewFromDescr \
809
+ (*(PyObject * (*)(PyTypeObject *, PyArray_Descr *, int, npy_intp const *, npy_intp const *, void *, int, PyObject *)) \
810
+ PyArray_API[94])
811
+ #define PyArray_DescrNew \
812
+ (*(PyArray_Descr * (*)(PyArray_Descr *)) \
813
+ PyArray_API[95])
814
+ #define PyArray_DescrNewFromType \
815
+ (*(PyArray_Descr * (*)(int)) \
816
+ PyArray_API[96])
817
+ #define PyArray_GetPriority \
818
+ (*(double (*)(PyObject *, double)) \
819
+ PyArray_API[97])
820
+ #define PyArray_IterNew \
821
+ (*(PyObject * (*)(PyObject *)) \
822
+ PyArray_API[98])
823
+ #define PyArray_MultiIterNew \
824
+ (*(PyObject* (*)(int, ...)) \
825
+ PyArray_API[99])
826
+ #define PyArray_PyIntAsInt \
827
+ (*(int (*)(PyObject *)) \
828
+ PyArray_API[100])
829
+ #define PyArray_PyIntAsIntp \
830
+ (*(npy_intp (*)(PyObject *)) \
831
+ PyArray_API[101])
832
+ #define PyArray_Broadcast \
833
+ (*(int (*)(PyArrayMultiIterObject *)) \
834
+ PyArray_API[102])
835
+ #define PyArray_FillWithScalar \
836
+ (*(int (*)(PyArrayObject *, PyObject *)) \
837
+ PyArray_API[104])
838
+ #define PyArray_CheckStrides \
839
+ (*(npy_bool (*)(int, int, npy_intp, npy_intp, npy_intp const *, npy_intp const *)) \
840
+ PyArray_API[105])
841
+ #define PyArray_DescrNewByteorder \
842
+ (*(PyArray_Descr * (*)(PyArray_Descr *, char)) \
843
+ PyArray_API[106])
844
+ #define PyArray_IterAllButAxis \
845
+ (*(PyObject * (*)(PyObject *, int *)) \
846
+ PyArray_API[107])
847
+ #define PyArray_CheckFromAny \
848
+ (*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) \
849
+ PyArray_API[108])
850
+ #define PyArray_FromArray \
851
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Descr *, int)) \
852
+ PyArray_API[109])
853
+ #define PyArray_FromInterface \
854
+ (*(PyObject * (*)(PyObject *)) \
855
+ PyArray_API[110])
856
+ #define PyArray_FromStructInterface \
857
+ (*(PyObject * (*)(PyObject *)) \
858
+ PyArray_API[111])
859
+ #define PyArray_FromArrayAttr \
860
+ (*(PyObject * (*)(PyObject *, PyArray_Descr *, PyObject *)) \
861
+ PyArray_API[112])
862
+ #define PyArray_ScalarKind \
863
+ (*(NPY_SCALARKIND (*)(int, PyArrayObject **)) \
864
+ PyArray_API[113])
865
+ #define PyArray_CanCoerceScalar \
866
+ (*(int (*)(int, int, NPY_SCALARKIND)) \
867
+ PyArray_API[114])
868
+ #define PyArray_CanCastScalar \
869
+ (*(npy_bool (*)(PyTypeObject *, PyTypeObject *)) \
870
+ PyArray_API[116])
871
+ #define PyArray_RemoveSmallest \
872
+ (*(int (*)(PyArrayMultiIterObject *)) \
873
+ PyArray_API[118])
874
+ #define PyArray_ElementStrides \
875
+ (*(int (*)(PyObject *)) \
876
+ PyArray_API[119])
877
+ #define PyArray_Item_INCREF \
878
+ (*(void (*)(char *, PyArray_Descr *)) \
879
+ PyArray_API[120])
880
+ #define PyArray_Item_XDECREF \
881
+ (*(void (*)(char *, PyArray_Descr *)) \
882
+ PyArray_API[121])
883
+ #define PyArray_Transpose \
884
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Dims *)) \
885
+ PyArray_API[123])
886
+ #define PyArray_TakeFrom \
887
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, int, PyArrayObject *, NPY_CLIPMODE)) \
888
+ PyArray_API[124])
889
+ #define PyArray_PutTo \
890
+ (*(PyObject * (*)(PyArrayObject *, PyObject*, PyObject *, NPY_CLIPMODE)) \
891
+ PyArray_API[125])
892
+ #define PyArray_PutMask \
893
+ (*(PyObject * (*)(PyArrayObject *, PyObject*, PyObject*)) \
894
+ PyArray_API[126])
895
+ #define PyArray_Repeat \
896
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, int)) \
897
+ PyArray_API[127])
898
+ #define PyArray_Choose \
899
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, PyArrayObject *, NPY_CLIPMODE)) \
900
+ PyArray_API[128])
901
+ #define PyArray_Sort \
902
+ (*(int (*)(PyArrayObject *, int, NPY_SORTKIND)) \
903
+ PyArray_API[129])
904
+ #define PyArray_ArgSort \
905
+ (*(PyObject * (*)(PyArrayObject *, int, NPY_SORTKIND)) \
906
+ PyArray_API[130])
907
+ #define PyArray_SearchSorted \
908
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, NPY_SEARCHSIDE, PyObject *)) \
909
+ PyArray_API[131])
910
+ #define PyArray_ArgMax \
911
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
912
+ PyArray_API[132])
913
+ #define PyArray_ArgMin \
914
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
915
+ PyArray_API[133])
916
+ #define PyArray_Reshape \
917
+ (*(PyObject * (*)(PyArrayObject *, PyObject *)) \
918
+ PyArray_API[134])
919
+ #define PyArray_Newshape \
920
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Dims *, NPY_ORDER)) \
921
+ PyArray_API[135])
922
+ #define PyArray_Squeeze \
923
+ (*(PyObject * (*)(PyArrayObject *)) \
924
+ PyArray_API[136])
925
+ #define PyArray_View \
926
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Descr *, PyTypeObject *)) \
927
+ PyArray_API[137])
928
+ #define PyArray_SwapAxes \
929
+ (*(PyObject * (*)(PyArrayObject *, int, int)) \
930
+ PyArray_API[138])
931
+ #define PyArray_Max \
932
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
933
+ PyArray_API[139])
934
+ #define PyArray_Min \
935
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
936
+ PyArray_API[140])
937
+ #define PyArray_Ptp \
938
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
939
+ PyArray_API[141])
940
+ #define PyArray_Mean \
941
+ (*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
942
+ PyArray_API[142])
943
+ #define PyArray_Trace \
944
+ (*(PyObject * (*)(PyArrayObject *, int, int, int, int, PyArrayObject *)) \
945
+ PyArray_API[143])
946
+ #define PyArray_Diagonal \
947
+ (*(PyObject * (*)(PyArrayObject *, int, int, int)) \
948
+ PyArray_API[144])
949
+ #define PyArray_Clip \
950
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, PyObject *, PyArrayObject *)) \
951
+ PyArray_API[145])
952
+ #define PyArray_Conjugate \
953
+ (*(PyObject * (*)(PyArrayObject *, PyArrayObject *)) \
954
+ PyArray_API[146])
955
+ #define PyArray_Nonzero \
956
+ (*(PyObject * (*)(PyArrayObject *)) \
957
+ PyArray_API[147])
958
+ #define PyArray_Std \
959
+ (*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *, int)) \
960
+ PyArray_API[148])
961
+ #define PyArray_Sum \
962
+ (*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
963
+ PyArray_API[149])
964
+ #define PyArray_CumSum \
965
+ (*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
966
+ PyArray_API[150])
967
+ #define PyArray_Prod \
968
+ (*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
969
+ PyArray_API[151])
970
+ #define PyArray_CumProd \
971
+ (*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
972
+ PyArray_API[152])
973
+ #define PyArray_All \
974
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
975
+ PyArray_API[153])
976
+ #define PyArray_Any \
977
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
978
+ PyArray_API[154])
979
+ #define PyArray_Compress \
980
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, int, PyArrayObject *)) \
981
+ PyArray_API[155])
982
+ #define PyArray_Flatten \
983
+ (*(PyObject * (*)(PyArrayObject *, NPY_ORDER)) \
984
+ PyArray_API[156])
985
+ #define PyArray_Ravel \
986
+ (*(PyObject * (*)(PyArrayObject *, NPY_ORDER)) \
987
+ PyArray_API[157])
988
+ #define PyArray_MultiplyList \
989
+ (*(npy_intp (*)(npy_intp const *, int)) \
990
+ PyArray_API[158])
991
+ #define PyArray_MultiplyIntList \
992
+ (*(int (*)(int const *, int)) \
993
+ PyArray_API[159])
994
+ #define PyArray_GetPtr \
995
+ (*(void * (*)(PyArrayObject *, npy_intp const*)) \
996
+ PyArray_API[160])
997
+ #define PyArray_CompareLists \
998
+ (*(int (*)(npy_intp const *, npy_intp const *, int)) \
999
+ PyArray_API[161])
1000
+ #define PyArray_AsCArray \
1001
+ (*(int (*)(PyObject **, void *, npy_intp *, int, PyArray_Descr*)) \
1002
+ PyArray_API[162])
1003
+ #define PyArray_Free \
1004
+ (*(int (*)(PyObject *, void *)) \
1005
+ PyArray_API[165])
1006
+ #define PyArray_Converter \
1007
+ (*(int (*)(PyObject *, PyObject **)) \
1008
+ PyArray_API[166])
1009
+ #define PyArray_IntpFromSequence \
1010
+ (*(int (*)(PyObject *, npy_intp *, int)) \
1011
+ PyArray_API[167])
1012
+ #define PyArray_Concatenate \
1013
+ (*(PyObject * (*)(PyObject *, int)) \
1014
+ PyArray_API[168])
1015
+ #define PyArray_InnerProduct \
1016
+ (*(PyObject * (*)(PyObject *, PyObject *)) \
1017
+ PyArray_API[169])
1018
+ #define PyArray_MatrixProduct \
1019
+ (*(PyObject * (*)(PyObject *, PyObject *)) \
1020
+ PyArray_API[170])
1021
+ #define PyArray_Correlate \
1022
+ (*(PyObject * (*)(PyObject *, PyObject *, int)) \
1023
+ PyArray_API[172])
1024
+ #define PyArray_DescrConverter \
1025
+ (*(int (*)(PyObject *, PyArray_Descr **)) \
1026
+ PyArray_API[174])
1027
+ #define PyArray_DescrConverter2 \
1028
+ (*(int (*)(PyObject *, PyArray_Descr **)) \
1029
+ PyArray_API[175])
1030
+ #define PyArray_IntpConverter \
1031
+ (*(int (*)(PyObject *, PyArray_Dims *)) \
1032
+ PyArray_API[176])
1033
+ #define PyArray_BufferConverter \
1034
+ (*(int (*)(PyObject *, PyArray_Chunk *)) \
1035
+ PyArray_API[177])
1036
+ #define PyArray_AxisConverter \
1037
+ (*(int (*)(PyObject *, int *)) \
1038
+ PyArray_API[178])
1039
+ #define PyArray_BoolConverter \
1040
+ (*(int (*)(PyObject *, npy_bool *)) \
1041
+ PyArray_API[179])
1042
+ #define PyArray_ByteorderConverter \
1043
+ (*(int (*)(PyObject *, char *)) \
1044
+ PyArray_API[180])
1045
+ #define PyArray_OrderConverter \
1046
+ (*(int (*)(PyObject *, NPY_ORDER *)) \
1047
+ PyArray_API[181])
1048
+ #define PyArray_EquivTypes \
1049
+ (*(unsigned char (*)(PyArray_Descr *, PyArray_Descr *)) \
1050
+ PyArray_API[182])
1051
+ #define PyArray_Zeros \
1052
+ (*(PyObject * (*)(int, npy_intp const *, PyArray_Descr *, int)) \
1053
+ PyArray_API[183])
1054
+ #define PyArray_Empty \
1055
+ (*(PyObject * (*)(int, npy_intp const *, PyArray_Descr *, int)) \
1056
+ PyArray_API[184])
1057
+ #define PyArray_Where \
1058
+ (*(PyObject * (*)(PyObject *, PyObject *, PyObject *)) \
1059
+ PyArray_API[185])
1060
+ #define PyArray_Arange \
1061
+ (*(PyObject * (*)(double, double, double, int)) \
1062
+ PyArray_API[186])
1063
+ #define PyArray_ArangeObj \
1064
+ (*(PyObject * (*)(PyObject *, PyObject *, PyObject *, PyArray_Descr *)) \
1065
+ PyArray_API[187])
1066
+ #define PyArray_SortkindConverter \
1067
+ (*(int (*)(PyObject *, NPY_SORTKIND *)) \
1068
+ PyArray_API[188])
1069
+ #define PyArray_LexSort \
1070
+ (*(PyObject * (*)(PyObject *, int)) \
1071
+ PyArray_API[189])
1072
+ #define PyArray_Round \
1073
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
1074
+ PyArray_API[190])
1075
+ #define PyArray_EquivTypenums \
1076
+ (*(unsigned char (*)(int, int)) \
1077
+ PyArray_API[191])
1078
+ #define PyArray_RegisterDataType \
1079
+ (*(int (*)(PyArray_DescrProto *)) \
1080
+ PyArray_API[192])
1081
+ #define PyArray_RegisterCastFunc \
1082
+ (*(int (*)(PyArray_Descr *, int, PyArray_VectorUnaryFunc *)) \
1083
+ PyArray_API[193])
1084
+ #define PyArray_RegisterCanCast \
1085
+ (*(int (*)(PyArray_Descr *, int, NPY_SCALARKIND)) \
1086
+ PyArray_API[194])
1087
+ #define PyArray_InitArrFuncs \
1088
+ (*(void (*)(PyArray_ArrFuncs *)) \
1089
+ PyArray_API[195])
1090
+ #define PyArray_IntTupleFromIntp \
1091
+ (*(PyObject * (*)(int, npy_intp const *)) \
1092
+ PyArray_API[196])
1093
+ #define PyArray_ClipmodeConverter \
1094
+ (*(int (*)(PyObject *, NPY_CLIPMODE *)) \
1095
+ PyArray_API[198])
1096
+ #define PyArray_OutputConverter \
1097
+ (*(int (*)(PyObject *, PyArrayObject **)) \
1098
+ PyArray_API[199])
1099
+ #define PyArray_BroadcastToShape \
1100
+ (*(PyObject * (*)(PyObject *, npy_intp *, int)) \
1101
+ PyArray_API[200])
1102
+ #define PyArray_DescrAlignConverter \
1103
+ (*(int (*)(PyObject *, PyArray_Descr **)) \
1104
+ PyArray_API[203])
1105
+ #define PyArray_DescrAlignConverter2 \
1106
+ (*(int (*)(PyObject *, PyArray_Descr **)) \
1107
+ PyArray_API[204])
1108
+ #define PyArray_SearchsideConverter \
1109
+ (*(int (*)(PyObject *, void *)) \
1110
+ PyArray_API[205])
1111
+ #define PyArray_CheckAxis \
1112
+ (*(PyObject * (*)(PyArrayObject *, int *, int)) \
1113
+ PyArray_API[206])
1114
+ #define PyArray_OverflowMultiplyList \
1115
+ (*(npy_intp (*)(npy_intp const *, int)) \
1116
+ PyArray_API[207])
1117
+ #define PyArray_MultiIterFromObjects \
1118
+ (*(PyObject* (*)(PyObject **, int, int, ...)) \
1119
+ PyArray_API[209])
1120
+ #define PyArray_GetEndianness \
1121
+ (*(int (*)(void)) \
1122
+ PyArray_API[210])
1123
+ #define PyArray_GetNDArrayCFeatureVersion \
1124
+ (*(unsigned int (*)(void)) \
1125
+ PyArray_API[211])
1126
+ #define PyArray_Correlate2 \
1127
+ (*(PyObject * (*)(PyObject *, PyObject *, int)) \
1128
+ PyArray_API[212])
1129
+ #define PyArray_NeighborhoodIterNew \
1130
+ (*(PyObject* (*)(PyArrayIterObject *, const npy_intp *, int, PyArrayObject*)) \
1131
+ PyArray_API[213])
1132
+ #define PyTimeIntegerArrType_Type (*(PyTypeObject *)PyArray_API[214])
1133
+ #define PyDatetimeArrType_Type (*(PyTypeObject *)PyArray_API[215])
1134
+ #define PyTimedeltaArrType_Type (*(PyTypeObject *)PyArray_API[216])
1135
+ #define PyHalfArrType_Type (*(PyTypeObject *)PyArray_API[217])
1136
+ #define NpyIter_Type (*(PyTypeObject *)PyArray_API[218])
1137
+ #define NpyIter_New \
1138
+ (*(NpyIter * (*)(PyArrayObject *, npy_uint32, NPY_ORDER, NPY_CASTING, PyArray_Descr*)) \
1139
+ PyArray_API[224])
1140
+ #define NpyIter_MultiNew \
1141
+ (*(NpyIter * (*)(int, PyArrayObject **, npy_uint32, NPY_ORDER, NPY_CASTING, npy_uint32 *, PyArray_Descr **)) \
1142
+ PyArray_API[225])
1143
+ #define NpyIter_AdvancedNew \
1144
+ (*(NpyIter * (*)(int, PyArrayObject **, npy_uint32, NPY_ORDER, NPY_CASTING, npy_uint32 *, PyArray_Descr **, int, int **, npy_intp *, npy_intp)) \
1145
+ PyArray_API[226])
1146
+ #define NpyIter_Copy \
1147
+ (*(NpyIter * (*)(NpyIter *)) \
1148
+ PyArray_API[227])
1149
+ #define NpyIter_Deallocate \
1150
+ (*(int (*)(NpyIter *)) \
1151
+ PyArray_API[228])
1152
+ #define NpyIter_HasDelayedBufAlloc \
1153
+ (*(npy_bool (*)(NpyIter *)) \
1154
+ PyArray_API[229])
1155
+ #define NpyIter_HasExternalLoop \
1156
+ (*(npy_bool (*)(NpyIter *)) \
1157
+ PyArray_API[230])
1158
+ #define NpyIter_EnableExternalLoop \
1159
+ (*(int (*)(NpyIter *)) \
1160
+ PyArray_API[231])
1161
+ #define NpyIter_GetInnerStrideArray \
1162
+ (*(npy_intp * (*)(NpyIter *)) \
1163
+ PyArray_API[232])
1164
+ #define NpyIter_GetInnerLoopSizePtr \
1165
+ (*(npy_intp * (*)(NpyIter *)) \
1166
+ PyArray_API[233])
1167
+ #define NpyIter_Reset \
1168
+ (*(int (*)(NpyIter *, char **)) \
1169
+ PyArray_API[234])
1170
+ #define NpyIter_ResetBasePointers \
1171
+ (*(int (*)(NpyIter *, char **, char **)) \
1172
+ PyArray_API[235])
1173
+ #define NpyIter_ResetToIterIndexRange \
1174
+ (*(int (*)(NpyIter *, npy_intp, npy_intp, char **)) \
1175
+ PyArray_API[236])
1176
+ #define NpyIter_GetNDim \
1177
+ (*(int (*)(NpyIter *)) \
1178
+ PyArray_API[237])
1179
+ #define NpyIter_GetNOp \
1180
+ (*(int (*)(NpyIter *)) \
1181
+ PyArray_API[238])
1182
+ #define NpyIter_GetIterNext \
1183
+ (*(NpyIter_IterNextFunc * (*)(NpyIter *, char **)) \
1184
+ PyArray_API[239])
1185
+ #define NpyIter_GetIterSize \
1186
+ (*(npy_intp (*)(NpyIter *)) \
1187
+ PyArray_API[240])
1188
+ #define NpyIter_GetIterIndexRange \
1189
+ (*(void (*)(NpyIter *, npy_intp *, npy_intp *)) \
1190
+ PyArray_API[241])
1191
+ #define NpyIter_GetIterIndex \
1192
+ (*(npy_intp (*)(NpyIter *)) \
1193
+ PyArray_API[242])
1194
+ #define NpyIter_GotoIterIndex \
1195
+ (*(int (*)(NpyIter *, npy_intp)) \
1196
+ PyArray_API[243])
1197
+ #define NpyIter_HasMultiIndex \
1198
+ (*(npy_bool (*)(NpyIter *)) \
1199
+ PyArray_API[244])
1200
+ #define NpyIter_GetShape \
1201
+ (*(int (*)(NpyIter *, npy_intp *)) \
1202
+ PyArray_API[245])
1203
+ #define NpyIter_GetGetMultiIndex \
1204
+ (*(NpyIter_GetMultiIndexFunc * (*)(NpyIter *, char **)) \
1205
+ PyArray_API[246])
1206
+ #define NpyIter_GotoMultiIndex \
1207
+ (*(int (*)(NpyIter *, npy_intp const *)) \
1208
+ PyArray_API[247])
1209
+ #define NpyIter_RemoveMultiIndex \
1210
+ (*(int (*)(NpyIter *)) \
1211
+ PyArray_API[248])
1212
+ #define NpyIter_HasIndex \
1213
+ (*(npy_bool (*)(NpyIter *)) \
1214
+ PyArray_API[249])
1215
+ #define NpyIter_IsBuffered \
1216
+ (*(npy_bool (*)(NpyIter *)) \
1217
+ PyArray_API[250])
1218
+ #define NpyIter_IsGrowInner \
1219
+ (*(npy_bool (*)(NpyIter *)) \
1220
+ PyArray_API[251])
1221
+ #define NpyIter_GetBufferSize \
1222
+ (*(npy_intp (*)(NpyIter *)) \
1223
+ PyArray_API[252])
1224
+ #define NpyIter_GetIndexPtr \
1225
+ (*(npy_intp * (*)(NpyIter *)) \
1226
+ PyArray_API[253])
1227
+ #define NpyIter_GotoIndex \
1228
+ (*(int (*)(NpyIter *, npy_intp)) \
1229
+ PyArray_API[254])
1230
+ #define NpyIter_GetDataPtrArray \
1231
+ (*(char ** (*)(NpyIter *)) \
1232
+ PyArray_API[255])
1233
+ #define NpyIter_GetDescrArray \
1234
+ (*(PyArray_Descr ** (*)(NpyIter *)) \
1235
+ PyArray_API[256])
1236
+ #define NpyIter_GetOperandArray \
1237
+ (*(PyArrayObject ** (*)(NpyIter *)) \
1238
+ PyArray_API[257])
1239
+ #define NpyIter_GetIterView \
1240
+ (*(PyArrayObject * (*)(NpyIter *, npy_intp)) \
1241
+ PyArray_API[258])
1242
+ #define NpyIter_GetReadFlags \
1243
+ (*(void (*)(NpyIter *, char *)) \
1244
+ PyArray_API[259])
1245
+ #define NpyIter_GetWriteFlags \
1246
+ (*(void (*)(NpyIter *, char *)) \
1247
+ PyArray_API[260])
1248
+ #define NpyIter_DebugPrint \
1249
+ (*(void (*)(NpyIter *)) \
1250
+ PyArray_API[261])
1251
+ #define NpyIter_IterationNeedsAPI \
1252
+ (*(npy_bool (*)(NpyIter *)) \
1253
+ PyArray_API[262])
1254
+ #define NpyIter_GetInnerFixedStrideArray \
1255
+ (*(void (*)(NpyIter *, npy_intp *)) \
1256
+ PyArray_API[263])
1257
+ #define NpyIter_RemoveAxis \
1258
+ (*(int (*)(NpyIter *, int)) \
1259
+ PyArray_API[264])
1260
+ #define NpyIter_GetAxisStrideArray \
1261
+ (*(npy_intp * (*)(NpyIter *, int)) \
1262
+ PyArray_API[265])
1263
+ #define NpyIter_RequiresBuffering \
1264
+ (*(npy_bool (*)(NpyIter *)) \
1265
+ PyArray_API[266])
1266
+ #define NpyIter_GetInitialDataPtrArray \
1267
+ (*(char ** (*)(NpyIter *)) \
1268
+ PyArray_API[267])
1269
+ #define NpyIter_CreateCompatibleStrides \
1270
+ (*(int (*)(NpyIter *, npy_intp, npy_intp *)) \
1271
+ PyArray_API[268])
1272
+ #define PyArray_CastingConverter \
1273
+ (*(int (*)(PyObject *, NPY_CASTING *)) \
1274
+ PyArray_API[269])
1275
+ #define PyArray_CountNonzero \
1276
+ (*(npy_intp (*)(PyArrayObject *)) \
1277
+ PyArray_API[270])
1278
+ #define PyArray_PromoteTypes \
1279
+ (*(PyArray_Descr * (*)(PyArray_Descr *, PyArray_Descr *)) \
1280
+ PyArray_API[271])
1281
+ #define PyArray_MinScalarType \
1282
+ (*(PyArray_Descr * (*)(PyArrayObject *)) \
1283
+ PyArray_API[272])
1284
+ #define PyArray_ResultType \
1285
+ (*(PyArray_Descr * (*)(npy_intp, PyArrayObject *arrs[], npy_intp, PyArray_Descr *descrs[])) \
1286
+ PyArray_API[273])
1287
+ #define PyArray_CanCastArrayTo \
1288
+ (*(npy_bool (*)(PyArrayObject *, PyArray_Descr *, NPY_CASTING)) \
1289
+ PyArray_API[274])
1290
+ #define PyArray_CanCastTypeTo \
1291
+ (*(npy_bool (*)(PyArray_Descr *, PyArray_Descr *, NPY_CASTING)) \
1292
+ PyArray_API[275])
1293
+ #define PyArray_EinsteinSum \
1294
+ (*(PyArrayObject * (*)(char *, npy_intp, PyArrayObject **, PyArray_Descr *, NPY_ORDER, NPY_CASTING, PyArrayObject *)) \
1295
+ PyArray_API[276])
1296
+ #define PyArray_NewLikeArray \
1297
+ (*(PyObject * (*)(PyArrayObject *, NPY_ORDER, PyArray_Descr *, int)) \
1298
+ PyArray_API[277])
1299
+ #define PyArray_ConvertClipmodeSequence \
1300
+ (*(int (*)(PyObject *, NPY_CLIPMODE *, int)) \
1301
+ PyArray_API[279])
1302
+ #define PyArray_MatrixProduct2 \
1303
+ (*(PyObject * (*)(PyObject *, PyObject *, PyArrayObject*)) \
1304
+ PyArray_API[280])
1305
+ #define NpyIter_IsFirstVisit \
1306
+ (*(npy_bool (*)(NpyIter *, int)) \
1307
+ PyArray_API[281])
1308
+ #define PyArray_SetBaseObject \
1309
+ (*(int (*)(PyArrayObject *, PyObject *)) \
1310
+ PyArray_API[282])
1311
+ #define PyArray_CreateSortedStridePerm \
1312
+ (*(void (*)(int, npy_intp const *, npy_stride_sort_item *)) \
1313
+ PyArray_API[283])
1314
+ #define PyArray_RemoveAxesInPlace \
1315
+ (*(void (*)(PyArrayObject *, const npy_bool *)) \
1316
+ PyArray_API[284])
1317
+ #define PyArray_DebugPrint \
1318
+ (*(void (*)(PyArrayObject *)) \
1319
+ PyArray_API[285])
1320
+ #define PyArray_FailUnlessWriteable \
1321
+ (*(int (*)(PyArrayObject *, const char *)) \
1322
+ PyArray_API[286])
1323
+ #define PyArray_SetUpdateIfCopyBase \
1324
+ (*(int (*)(PyArrayObject *, PyArrayObject *)) \
1325
+ PyArray_API[287])
1326
+ #define PyDataMem_NEW \
1327
+ (*(void * (*)(size_t)) \
1328
+ PyArray_API[288])
1329
+ #define PyDataMem_FREE \
1330
+ (*(void (*)(void *)) \
1331
+ PyArray_API[289])
1332
+ #define PyDataMem_RENEW \
1333
+ (*(void * (*)(void *, size_t)) \
1334
+ PyArray_API[290])
1335
+ #define NPY_DEFAULT_ASSIGN_CASTING (*(NPY_CASTING *)PyArray_API[292])
1336
+ #define PyArray_Partition \
1337
+ (*(int (*)(PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND)) \
1338
+ PyArray_API[296])
1339
+ #define PyArray_ArgPartition \
1340
+ (*(PyObject * (*)(PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND)) \
1341
+ PyArray_API[297])
1342
+ #define PyArray_SelectkindConverter \
1343
+ (*(int (*)(PyObject *, NPY_SELECTKIND *)) \
1344
+ PyArray_API[298])
1345
+ #define PyDataMem_NEW_ZEROED \
1346
+ (*(void * (*)(size_t, size_t)) \
1347
+ PyArray_API[299])
1348
+ #define PyArray_CheckAnyScalarExact \
1349
+ (*(int (*)(PyObject *)) \
1350
+ PyArray_API[300])
1351
+ #define PyArray_ResolveWritebackIfCopy \
1352
+ (*(int (*)(PyArrayObject *)) \
1353
+ PyArray_API[302])
1354
+ #define PyArray_SetWritebackIfCopyBase \
1355
+ (*(int (*)(PyArrayObject *, PyArrayObject *)) \
1356
+ PyArray_API[303])
1357
+
1358
+ #if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
1359
+ #define PyDataMem_SetHandler \
1360
+ (*(PyObject * (*)(PyObject *)) \
1361
+ PyArray_API[304])
1362
+ #endif
1363
+
1364
+ #if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
1365
+ #define PyDataMem_GetHandler \
1366
+ (*(PyObject * (*)(void)) \
1367
+ PyArray_API[305])
1368
+ #endif
1369
+ #define PyDataMem_DefaultHandler (*(PyObject* *)PyArray_API[306])
1370
+
1371
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1372
+ #define NpyDatetime_ConvertDatetime64ToDatetimeStruct \
1373
+ (*(int (*)(PyArray_DatetimeMetaData *, npy_datetime, npy_datetimestruct *)) \
1374
+ PyArray_API[307])
1375
+ #endif
1376
+
1377
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1378
+ #define NpyDatetime_ConvertDatetimeStructToDatetime64 \
1379
+ (*(int (*)(PyArray_DatetimeMetaData *, const npy_datetimestruct *, npy_datetime *)) \
1380
+ PyArray_API[308])
1381
+ #endif
1382
+
1383
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1384
+ #define NpyDatetime_ConvertPyDateTimeToDatetimeStruct \
1385
+ (*(int (*)(PyObject *, npy_datetimestruct *, NPY_DATETIMEUNIT *, int)) \
1386
+ PyArray_API[309])
1387
+ #endif
1388
+
1389
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1390
+ #define NpyDatetime_GetDatetimeISO8601StrLen \
1391
+ (*(int (*)(int, NPY_DATETIMEUNIT)) \
1392
+ PyArray_API[310])
1393
+ #endif
1394
+
1395
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1396
+ #define NpyDatetime_MakeISO8601Datetime \
1397
+ (*(int (*)(npy_datetimestruct *, char *, npy_intp, int, int, NPY_DATETIMEUNIT, int, NPY_CASTING)) \
1398
+ PyArray_API[311])
1399
+ #endif
1400
+
1401
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1402
+ #define NpyDatetime_ParseISO8601Datetime \
1403
+ (*(int (*)(char const *, Py_ssize_t, NPY_DATETIMEUNIT, NPY_CASTING, npy_datetimestruct *, NPY_DATETIMEUNIT *, npy_bool *)) \
1404
+ PyArray_API[312])
1405
+ #endif
1406
+
1407
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1408
+ #define NpyString_load \
1409
+ (*(int (*)(npy_string_allocator *, const npy_packed_static_string *, npy_static_string *)) \
1410
+ PyArray_API[313])
1411
+ #endif
1412
+
1413
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1414
+ #define NpyString_pack \
1415
+ (*(int (*)(npy_string_allocator *, npy_packed_static_string *, const char *, size_t)) \
1416
+ PyArray_API[314])
1417
+ #endif
1418
+
1419
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1420
+ #define NpyString_pack_null \
1421
+ (*(int (*)(npy_string_allocator *, npy_packed_static_string *)) \
1422
+ PyArray_API[315])
1423
+ #endif
1424
+
1425
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1426
+ #define NpyString_acquire_allocator \
1427
+ (*(npy_string_allocator * (*)(const PyArray_StringDTypeObject *)) \
1428
+ PyArray_API[316])
1429
+ #endif
1430
+
1431
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1432
+ #define NpyString_acquire_allocators \
1433
+ (*(void (*)(size_t, PyArray_Descr *const descrs[], npy_string_allocator *allocators[])) \
1434
+ PyArray_API[317])
1435
+ #endif
1436
+
1437
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1438
+ #define NpyString_release_allocator \
1439
+ (*(void (*)(npy_string_allocator *)) \
1440
+ PyArray_API[318])
1441
+ #endif
1442
+
1443
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1444
+ #define NpyString_release_allocators \
1445
+ (*(void (*)(size_t, npy_string_allocator *allocators[])) \
1446
+ PyArray_API[319])
1447
+ #endif
1448
+
1449
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1450
+ #define PyArray_GetDefaultDescr \
1451
+ (*(PyArray_Descr * (*)(PyArray_DTypeMeta *)) \
1452
+ PyArray_API[361])
1453
+ #endif
1454
+
1455
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1456
+ #define PyArrayInitDTypeMeta_FromSpec \
1457
+ (*(int (*)(PyArray_DTypeMeta *, PyArrayDTypeMeta_Spec *)) \
1458
+ PyArray_API[362])
1459
+ #endif
1460
+
1461
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1462
+ #define PyArray_CommonDType \
1463
+ (*(PyArray_DTypeMeta * (*)(PyArray_DTypeMeta *, PyArray_DTypeMeta *)) \
1464
+ PyArray_API[363])
1465
+ #endif
1466
+
1467
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
1468
+ #define PyArray_PromoteDTypeSequence \
1469
+ (*(PyArray_DTypeMeta * (*)(npy_intp, PyArray_DTypeMeta **)) \
1470
+ PyArray_API[364])
1471
+ #endif
1472
+ #define _PyDataType_GetArrFuncs \
1473
+ (*(PyArray_ArrFuncs * (*)(const PyArray_Descr *)) \
1474
+ PyArray_API[365])
1475
+
1476
+ /*
1477
+ * The DType classes are inconvenient for the Python generation so exposed
1478
+ * manually in the header below (may be moved).
1479
+ */
1480
+ #include "numpy/_public_dtype_api_table.h"
1481
+
1482
+ #if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)
1483
+ static int
1484
+ _import_array(void)
1485
+ {
1486
+ int st;
1487
+ PyObject *numpy = PyImport_ImportModule("numpy._core._multiarray_umath");
1488
+ if (numpy == NULL && PyErr_ExceptionMatches(PyExc_ModuleNotFoundError)) {
1489
+ PyErr_Clear();
1490
+ numpy = PyImport_ImportModule("numpy.core._multiarray_umath");
1491
+ }
1492
+
1493
+ if (numpy == NULL) {
1494
+ return -1;
1495
+ }
1496
+
1497
+ PyObject *c_api = PyObject_GetAttrString(numpy, "_ARRAY_API");
1498
+ Py_DECREF(numpy);
1499
+ if (c_api == NULL) {
1500
+ return -1;
1501
+ }
1502
+
1503
+ if (!PyCapsule_CheckExact(c_api)) {
1504
+ PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is not PyCapsule object");
1505
+ Py_DECREF(c_api);
1506
+ return -1;
1507
+ }
1508
+ PyArray_API = (void **)PyCapsule_GetPointer(c_api, NULL);
1509
+ Py_DECREF(c_api);
1510
+ if (PyArray_API == NULL) {
1511
+ PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is NULL pointer");
1512
+ return -1;
1513
+ }
1514
+
1515
+ /*
1516
+ * On exceedingly few platforms these sizes may not match, in which case
1517
+ * We do not support older NumPy versions at all.
1518
+ */
1519
+ if (sizeof(Py_ssize_t) != sizeof(Py_intptr_t) &&
1520
+ PyArray_RUNTIME_VERSION < NPY_2_0_API_VERSION) {
1521
+ PyErr_Format(PyExc_RuntimeError,
1522
+ "module compiled against NumPy 2.0 but running on NumPy 1.x. "
1523
+ "Unfortunately, this is not supported on niche platforms where "
1524
+ "`sizeof(size_t) != sizeof(inptr_t)`.");
1525
+ }
1526
+ /*
1527
+ * Perform runtime check of C API version. As of now NumPy 2.0 is ABI
1528
+ * backwards compatible (in the exposed feature subset!) for all practical
1529
+ * purposes.
1530
+ */
1531
+ if (NPY_VERSION < PyArray_GetNDArrayCVersion()) {
1532
+ PyErr_Format(PyExc_RuntimeError, "module compiled against "\
1533
+ "ABI version 0x%x but this version of numpy is 0x%x", \
1534
+ (int) NPY_VERSION, (int) PyArray_GetNDArrayCVersion());
1535
+ return -1;
1536
+ }
1537
+ PyArray_RUNTIME_VERSION = (int)PyArray_GetNDArrayCFeatureVersion();
1538
+ if (NPY_FEATURE_VERSION > PyArray_RUNTIME_VERSION) {
1539
+ PyErr_Format(PyExc_RuntimeError,
1540
+ "module was compiled against NumPy C-API version 0x%x "
1541
+ "(NumPy " NPY_FEATURE_VERSION_STRING ") "
1542
+ "but the running NumPy has C-API version 0x%x. "
1543
+ "Check the section C-API incompatibility at the "
1544
+ "Troubleshooting ImportError section at "
1545
+ "https://numpy.org/devdocs/user/troubleshooting-importerror.html"
1546
+ "#c-api-incompatibility "
1547
+ "for indications on how to solve this problem.",
1548
+ (int)NPY_FEATURE_VERSION, PyArray_RUNTIME_VERSION);
1549
+ return -1;
1550
+ }
1551
+
1552
+ /*
1553
+ * Perform runtime check of endianness and check it matches the one set by
1554
+ * the headers (npy_endian.h) as a safeguard
1555
+ */
1556
+ st = PyArray_GetEndianness();
1557
+ if (st == NPY_CPU_UNKNOWN_ENDIAN) {
1558
+ PyErr_SetString(PyExc_RuntimeError,
1559
+ "FATAL: module compiled as unknown endian");
1560
+ return -1;
1561
+ }
1562
+ #if NPY_BYTE_ORDER == NPY_BIG_ENDIAN
1563
+ if (st != NPY_CPU_BIG) {
1564
+ PyErr_SetString(PyExc_RuntimeError,
1565
+ "FATAL: module compiled as big endian, but "
1566
+ "detected different endianness at runtime");
1567
+ return -1;
1568
+ }
1569
+ #elif NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN
1570
+ if (st != NPY_CPU_LITTLE) {
1571
+ PyErr_SetString(PyExc_RuntimeError,
1572
+ "FATAL: module compiled as little endian, but "
1573
+ "detected different endianness at runtime");
1574
+ return -1;
1575
+ }
1576
+ #endif
1577
+
1578
+ return 0;
1579
+ }
1580
+
1581
+ #define import_array() { \
1582
+ if (_import_array() < 0) { \
1583
+ PyErr_Print(); \
1584
+ PyErr_SetString( \
1585
+ PyExc_ImportError, \
1586
+ "numpy._core.multiarray failed to import" \
1587
+ ); \
1588
+ return NULL; \
1589
+ } \
1590
+ }
1591
+
1592
+ #define import_array1(ret) { \
1593
+ if (_import_array() < 0) { \
1594
+ PyErr_Print(); \
1595
+ PyErr_SetString( \
1596
+ PyExc_ImportError, \
1597
+ "numpy._core.multiarray failed to import" \
1598
+ ); \
1599
+ return ret; \
1600
+ } \
1601
+ }
1602
+
1603
+ #define import_array2(msg, ret) { \
1604
+ if (_import_array() < 0) { \
1605
+ PyErr_Print(); \
1606
+ PyErr_SetString(PyExc_ImportError, msg); \
1607
+ return ret; \
1608
+ } \
1609
+ }
1610
+
1611
+ #endif
1612
+
1613
+ #endif
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/__ufunc_api.c ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ /* These pointers will be stored in the C-object for use in other
3
+ extension modules
4
+ */
5
+
6
+ void *PyUFunc_API[] = {
7
+ (void *) &PyUFunc_Type,
8
+ (void *) PyUFunc_FromFuncAndData,
9
+ (void *) PyUFunc_RegisterLoopForType,
10
+ NULL,
11
+ (void *) PyUFunc_f_f_As_d_d,
12
+ (void *) PyUFunc_d_d,
13
+ (void *) PyUFunc_f_f,
14
+ (void *) PyUFunc_g_g,
15
+ (void *) PyUFunc_F_F_As_D_D,
16
+ (void *) PyUFunc_F_F,
17
+ (void *) PyUFunc_D_D,
18
+ (void *) PyUFunc_G_G,
19
+ (void *) PyUFunc_O_O,
20
+ (void *) PyUFunc_ff_f_As_dd_d,
21
+ (void *) PyUFunc_ff_f,
22
+ (void *) PyUFunc_dd_d,
23
+ (void *) PyUFunc_gg_g,
24
+ (void *) PyUFunc_FF_F_As_DD_D,
25
+ (void *) PyUFunc_DD_D,
26
+ (void *) PyUFunc_FF_F,
27
+ (void *) PyUFunc_GG_G,
28
+ (void *) PyUFunc_OO_O,
29
+ (void *) PyUFunc_O_O_method,
30
+ (void *) PyUFunc_OO_O_method,
31
+ (void *) PyUFunc_On_Om,
32
+ NULL,
33
+ NULL,
34
+ (void *) PyUFunc_clearfperr,
35
+ (void *) PyUFunc_getfperr,
36
+ NULL,
37
+ (void *) PyUFunc_ReplaceLoopBySignature,
38
+ (void *) PyUFunc_FromFuncAndDataAndSignature,
39
+ NULL,
40
+ (void *) PyUFunc_e_e,
41
+ (void *) PyUFunc_e_e_As_f_f,
42
+ (void *) PyUFunc_e_e_As_d_d,
43
+ (void *) PyUFunc_ee_e,
44
+ (void *) PyUFunc_ee_e_As_ff_f,
45
+ (void *) PyUFunc_ee_e_As_dd_d,
46
+ (void *) PyUFunc_DefaultTypeResolver,
47
+ (void *) PyUFunc_ValidateCasting,
48
+ (void *) PyUFunc_RegisterLoopForDescr,
49
+ (void *) PyUFunc_FromFuncAndDataAndSignatureAndIdentity,
50
+ (void *) PyUFunc_AddLoopFromSpec,
51
+ (void *) PyUFunc_AddPromoter,
52
+ (void *) PyUFunc_AddWrappingLoop,
53
+ (void *) PyUFunc_GiveFloatingpointErrors
54
+ };
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/__ufunc_api.h ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #ifdef _UMATHMODULE
3
+
4
+ extern NPY_NO_EXPORT PyTypeObject PyUFunc_Type;
5
+
6
+ extern NPY_NO_EXPORT PyTypeObject PyUFunc_Type;
7
+
8
+ NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndData \
9
+ (PyUFuncGenericFunction *, void *const *, const char *, int, int, int, int, const char *, const char *, int);
10
+ NPY_NO_EXPORT int PyUFunc_RegisterLoopForType \
11
+ (PyUFuncObject *, int, PyUFuncGenericFunction, const int *, void *);
12
+ NPY_NO_EXPORT void PyUFunc_f_f_As_d_d \
13
+ (char **, npy_intp const *, npy_intp const *, void *);
14
+ NPY_NO_EXPORT void PyUFunc_d_d \
15
+ (char **, npy_intp const *, npy_intp const *, void *);
16
+ NPY_NO_EXPORT void PyUFunc_f_f \
17
+ (char **, npy_intp const *, npy_intp const *, void *);
18
+ NPY_NO_EXPORT void PyUFunc_g_g \
19
+ (char **, npy_intp const *, npy_intp const *, void *);
20
+ NPY_NO_EXPORT void PyUFunc_F_F_As_D_D \
21
+ (char **, npy_intp const *, npy_intp const *, void *);
22
+ NPY_NO_EXPORT void PyUFunc_F_F \
23
+ (char **, npy_intp const *, npy_intp const *, void *);
24
+ NPY_NO_EXPORT void PyUFunc_D_D \
25
+ (char **, npy_intp const *, npy_intp const *, void *);
26
+ NPY_NO_EXPORT void PyUFunc_G_G \
27
+ (char **, npy_intp const *, npy_intp const *, void *);
28
+ NPY_NO_EXPORT void PyUFunc_O_O \
29
+ (char **, npy_intp const *, npy_intp const *, void *);
30
+ NPY_NO_EXPORT void PyUFunc_ff_f_As_dd_d \
31
+ (char **, npy_intp const *, npy_intp const *, void *);
32
+ NPY_NO_EXPORT void PyUFunc_ff_f \
33
+ (char **, npy_intp const *, npy_intp const *, void *);
34
+ NPY_NO_EXPORT void PyUFunc_dd_d \
35
+ (char **, npy_intp const *, npy_intp const *, void *);
36
+ NPY_NO_EXPORT void PyUFunc_gg_g \
37
+ (char **, npy_intp const *, npy_intp const *, void *);
38
+ NPY_NO_EXPORT void PyUFunc_FF_F_As_DD_D \
39
+ (char **, npy_intp const *, npy_intp const *, void *);
40
+ NPY_NO_EXPORT void PyUFunc_DD_D \
41
+ (char **, npy_intp const *, npy_intp const *, void *);
42
+ NPY_NO_EXPORT void PyUFunc_FF_F \
43
+ (char **, npy_intp const *, npy_intp const *, void *);
44
+ NPY_NO_EXPORT void PyUFunc_GG_G \
45
+ (char **, npy_intp const *, npy_intp const *, void *);
46
+ NPY_NO_EXPORT void PyUFunc_OO_O \
47
+ (char **, npy_intp const *, npy_intp const *, void *);
48
+ NPY_NO_EXPORT void PyUFunc_O_O_method \
49
+ (char **, npy_intp const *, npy_intp const *, void *);
50
+ NPY_NO_EXPORT void PyUFunc_OO_O_method \
51
+ (char **, npy_intp const *, npy_intp const *, void *);
52
+ NPY_NO_EXPORT void PyUFunc_On_Om \
53
+ (char **, npy_intp const *, npy_intp const *, void *);
54
+ NPY_NO_EXPORT void PyUFunc_clearfperr \
55
+ (void);
56
+ NPY_NO_EXPORT int PyUFunc_getfperr \
57
+ (void);
58
+ NPY_NO_EXPORT int PyUFunc_ReplaceLoopBySignature \
59
+ (PyUFuncObject *, PyUFuncGenericFunction, const int *, PyUFuncGenericFunction *);
60
+ NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndDataAndSignature \
61
+ (PyUFuncGenericFunction *, void *const *, const char *, int, int, int, int, const char *, const char *, int, const char *);
62
+ NPY_NO_EXPORT void PyUFunc_e_e \
63
+ (char **, npy_intp const *, npy_intp const *, void *);
64
+ NPY_NO_EXPORT void PyUFunc_e_e_As_f_f \
65
+ (char **, npy_intp const *, npy_intp const *, void *);
66
+ NPY_NO_EXPORT void PyUFunc_e_e_As_d_d \
67
+ (char **, npy_intp const *, npy_intp const *, void *);
68
+ NPY_NO_EXPORT void PyUFunc_ee_e \
69
+ (char **, npy_intp const *, npy_intp const *, void *);
70
+ NPY_NO_EXPORT void PyUFunc_ee_e_As_ff_f \
71
+ (char **, npy_intp const *, npy_intp const *, void *);
72
+ NPY_NO_EXPORT void PyUFunc_ee_e_As_dd_d \
73
+ (char **, npy_intp const *, npy_intp const *, void *);
74
+ NPY_NO_EXPORT int PyUFunc_DefaultTypeResolver \
75
+ (PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyObject *, PyArray_Descr **);
76
+ NPY_NO_EXPORT int PyUFunc_ValidateCasting \
77
+ (PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyArray_Descr *const *);
78
+ NPY_NO_EXPORT int PyUFunc_RegisterLoopForDescr \
79
+ (PyUFuncObject *, PyArray_Descr *, PyUFuncGenericFunction, PyArray_Descr **, void *);
80
+ NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndDataAndSignatureAndIdentity \
81
+ (PyUFuncGenericFunction *, void *const *, const char *, int, int, int, int, const char *, const char *, const int, const char *, PyObject *);
82
+ NPY_NO_EXPORT int PyUFunc_AddLoopFromSpec \
83
+ (PyObject *, PyArrayMethod_Spec *);
84
+ NPY_NO_EXPORT int PyUFunc_AddPromoter \
85
+ (PyObject *, PyObject *, PyObject *);
86
+ NPY_NO_EXPORT int PyUFunc_AddWrappingLoop \
87
+ (PyObject *, PyArray_DTypeMeta *new_dtypes[], PyArray_DTypeMeta *wrapped_dtypes[], PyArrayMethod_TranslateGivenDescriptors *, PyArrayMethod_TranslateLoopDescriptors *);
88
+ NPY_NO_EXPORT int PyUFunc_GiveFloatingpointErrors \
89
+ (const char *, int);
90
+
91
+ #else
92
+
93
+ #if defined(PY_UFUNC_UNIQUE_SYMBOL)
94
+ #define PyUFunc_API PY_UFUNC_UNIQUE_SYMBOL
95
+ #endif
96
+
97
+ /* By default do not export API in an .so (was never the case on windows) */
98
+ #ifndef NPY_API_SYMBOL_ATTRIBUTE
99
+ #define NPY_API_SYMBOL_ATTRIBUTE NPY_VISIBILITY_HIDDEN
100
+ #endif
101
+
102
+ #if defined(NO_IMPORT) || defined(NO_IMPORT_UFUNC)
103
+ extern NPY_API_SYMBOL_ATTRIBUTE void **PyUFunc_API;
104
+ #else
105
+ #if defined(PY_UFUNC_UNIQUE_SYMBOL)
106
+ NPY_API_SYMBOL_ATTRIBUTE void **PyUFunc_API;
107
+ #else
108
+ static void **PyUFunc_API=NULL;
109
+ #endif
110
+ #endif
111
+
112
+ #define PyUFunc_Type (*(PyTypeObject *)PyUFunc_API[0])
113
+ #define PyUFunc_FromFuncAndData \
114
+ (*(PyObject * (*)(PyUFuncGenericFunction *, void *const *, const char *, int, int, int, int, const char *, const char *, int)) \
115
+ PyUFunc_API[1])
116
+ #define PyUFunc_RegisterLoopForType \
117
+ (*(int (*)(PyUFuncObject *, int, PyUFuncGenericFunction, const int *, void *)) \
118
+ PyUFunc_API[2])
119
+ #define PyUFunc_f_f_As_d_d \
120
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
121
+ PyUFunc_API[4])
122
+ #define PyUFunc_d_d \
123
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
124
+ PyUFunc_API[5])
125
+ #define PyUFunc_f_f \
126
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
127
+ PyUFunc_API[6])
128
+ #define PyUFunc_g_g \
129
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
130
+ PyUFunc_API[7])
131
+ #define PyUFunc_F_F_As_D_D \
132
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
133
+ PyUFunc_API[8])
134
+ #define PyUFunc_F_F \
135
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
136
+ PyUFunc_API[9])
137
+ #define PyUFunc_D_D \
138
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
139
+ PyUFunc_API[10])
140
+ #define PyUFunc_G_G \
141
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
142
+ PyUFunc_API[11])
143
+ #define PyUFunc_O_O \
144
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
145
+ PyUFunc_API[12])
146
+ #define PyUFunc_ff_f_As_dd_d \
147
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
148
+ PyUFunc_API[13])
149
+ #define PyUFunc_ff_f \
150
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
151
+ PyUFunc_API[14])
152
+ #define PyUFunc_dd_d \
153
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
154
+ PyUFunc_API[15])
155
+ #define PyUFunc_gg_g \
156
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
157
+ PyUFunc_API[16])
158
+ #define PyUFunc_FF_F_As_DD_D \
159
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
160
+ PyUFunc_API[17])
161
+ #define PyUFunc_DD_D \
162
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
163
+ PyUFunc_API[18])
164
+ #define PyUFunc_FF_F \
165
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
166
+ PyUFunc_API[19])
167
+ #define PyUFunc_GG_G \
168
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
169
+ PyUFunc_API[20])
170
+ #define PyUFunc_OO_O \
171
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
172
+ PyUFunc_API[21])
173
+ #define PyUFunc_O_O_method \
174
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
175
+ PyUFunc_API[22])
176
+ #define PyUFunc_OO_O_method \
177
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
178
+ PyUFunc_API[23])
179
+ #define PyUFunc_On_Om \
180
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
181
+ PyUFunc_API[24])
182
+ #define PyUFunc_clearfperr \
183
+ (*(void (*)(void)) \
184
+ PyUFunc_API[27])
185
+ #define PyUFunc_getfperr \
186
+ (*(int (*)(void)) \
187
+ PyUFunc_API[28])
188
+ #define PyUFunc_ReplaceLoopBySignature \
189
+ (*(int (*)(PyUFuncObject *, PyUFuncGenericFunction, const int *, PyUFuncGenericFunction *)) \
190
+ PyUFunc_API[30])
191
+ #define PyUFunc_FromFuncAndDataAndSignature \
192
+ (*(PyObject * (*)(PyUFuncGenericFunction *, void *const *, const char *, int, int, int, int, const char *, const char *, int, const char *)) \
193
+ PyUFunc_API[31])
194
+ #define PyUFunc_e_e \
195
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
196
+ PyUFunc_API[33])
197
+ #define PyUFunc_e_e_As_f_f \
198
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
199
+ PyUFunc_API[34])
200
+ #define PyUFunc_e_e_As_d_d \
201
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
202
+ PyUFunc_API[35])
203
+ #define PyUFunc_ee_e \
204
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
205
+ PyUFunc_API[36])
206
+ #define PyUFunc_ee_e_As_ff_f \
207
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
208
+ PyUFunc_API[37])
209
+ #define PyUFunc_ee_e_As_dd_d \
210
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
211
+ PyUFunc_API[38])
212
+ #define PyUFunc_DefaultTypeResolver \
213
+ (*(int (*)(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyObject *, PyArray_Descr **)) \
214
+ PyUFunc_API[39])
215
+ #define PyUFunc_ValidateCasting \
216
+ (*(int (*)(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyArray_Descr *const *)) \
217
+ PyUFunc_API[40])
218
+ #define PyUFunc_RegisterLoopForDescr \
219
+ (*(int (*)(PyUFuncObject *, PyArray_Descr *, PyUFuncGenericFunction, PyArray_Descr **, void *)) \
220
+ PyUFunc_API[41])
221
+
222
+ #if NPY_FEATURE_VERSION >= NPY_1_16_API_VERSION
223
+ #define PyUFunc_FromFuncAndDataAndSignatureAndIdentity \
224
+ (*(PyObject * (*)(PyUFuncGenericFunction *, void *const *, const char *, int, int, int, int, const char *, const char *, const int, const char *, PyObject *)) \
225
+ PyUFunc_API[42])
226
+ #endif
227
+
228
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
229
+ #define PyUFunc_AddLoopFromSpec \
230
+ (*(int (*)(PyObject *, PyArrayMethod_Spec *)) \
231
+ PyUFunc_API[43])
232
+ #endif
233
+
234
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
235
+ #define PyUFunc_AddPromoter \
236
+ (*(int (*)(PyObject *, PyObject *, PyObject *)) \
237
+ PyUFunc_API[44])
238
+ #endif
239
+
240
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
241
+ #define PyUFunc_AddWrappingLoop \
242
+ (*(int (*)(PyObject *, PyArray_DTypeMeta *new_dtypes[], PyArray_DTypeMeta *wrapped_dtypes[], PyArrayMethod_TranslateGivenDescriptors *, PyArrayMethod_TranslateLoopDescriptors *)) \
243
+ PyUFunc_API[45])
244
+ #endif
245
+
246
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
247
+ #define PyUFunc_GiveFloatingpointErrors \
248
+ (*(int (*)(const char *, int)) \
249
+ PyUFunc_API[46])
250
+ #endif
251
+
252
+ static inline int
253
+ _import_umath(void)
254
+ {
255
+ PyObject *numpy = PyImport_ImportModule("numpy._core._multiarray_umath");
256
+ if (numpy == NULL && PyErr_ExceptionMatches(PyExc_ModuleNotFoundError)) {
257
+ PyErr_Clear();
258
+ numpy = PyImport_ImportModule("numpy.core._multiarray_umath");
259
+ }
260
+
261
+ if (numpy == NULL) {
262
+ PyErr_SetString(PyExc_ImportError,
263
+ "_multiarray_umath failed to import");
264
+ return -1;
265
+ }
266
+
267
+ PyObject *c_api = PyObject_GetAttrString(numpy, "_UFUNC_API");
268
+ Py_DECREF(numpy);
269
+ if (c_api == NULL) {
270
+ PyErr_SetString(PyExc_AttributeError, "_UFUNC_API not found");
271
+ return -1;
272
+ }
273
+
274
+ if (!PyCapsule_CheckExact(c_api)) {
275
+ PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is not PyCapsule object");
276
+ Py_DECREF(c_api);
277
+ return -1;
278
+ }
279
+ PyUFunc_API = (void **)PyCapsule_GetPointer(c_api, NULL);
280
+ Py_DECREF(c_api);
281
+ if (PyUFunc_API == NULL) {
282
+ PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is NULL pointer");
283
+ return -1;
284
+ }
285
+ return 0;
286
+ }
287
+
288
+ #define import_umath() \
289
+ do {\
290
+ UFUNC_NOFPE\
291
+ if (_import_umath() < 0) {\
292
+ PyErr_Print();\
293
+ PyErr_SetString(PyExc_ImportError,\
294
+ "numpy._core.umath failed to import");\
295
+ return NULL;\
296
+ }\
297
+ } while(0)
298
+
299
+ #define import_umath1(ret) \
300
+ do {\
301
+ UFUNC_NOFPE\
302
+ if (_import_umath() < 0) {\
303
+ PyErr_Print();\
304
+ PyErr_SetString(PyExc_ImportError,\
305
+ "numpy._core.umath failed to import");\
306
+ return ret;\
307
+ }\
308
+ } while(0)
309
+
310
+ #define import_umath2(ret, msg) \
311
+ do {\
312
+ UFUNC_NOFPE\
313
+ if (_import_umath() < 0) {\
314
+ PyErr_Print();\
315
+ PyErr_SetString(PyExc_ImportError, msg);\
316
+ return ret;\
317
+ }\
318
+ } while(0)
319
+
320
+ #define import_ufunc() \
321
+ do {\
322
+ UFUNC_NOFPE\
323
+ if (_import_umath() < 0) {\
324
+ PyErr_Print();\
325
+ PyErr_SetString(PyExc_ImportError,\
326
+ "numpy._core.umath failed to import");\
327
+ }\
328
+ } while(0)
329
+
330
+
331
+ static inline int
332
+ PyUFunc_ImportUFuncAPI()
333
+ {
334
+ if (NPY_UNLIKELY(PyUFunc_API == NULL)) {
335
+ import_umath1(-1);
336
+ }
337
+ return 0;
338
+ }
339
+
340
+ #endif
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/_neighborhood_iterator_imp.h ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY__NEIGHBORHOOD_IMP_H_
2
+ #error You should not include this header directly
3
+ #endif
4
+ /*
5
+ * Private API (here for inline)
6
+ */
7
+ static inline int
8
+ _PyArrayNeighborhoodIter_IncrCoord(PyArrayNeighborhoodIterObject* iter);
9
+
10
+ /*
11
+ * Update to next item of the iterator
12
+ *
13
+ * Note: this simply increment the coordinates vector, last dimension
14
+ * incremented first , i.e, for dimension 3
15
+ * ...
16
+ * -1, -1, -1
17
+ * -1, -1, 0
18
+ * -1, -1, 1
19
+ * ....
20
+ * -1, 0, -1
21
+ * -1, 0, 0
22
+ * ....
23
+ * 0, -1, -1
24
+ * 0, -1, 0
25
+ * ....
26
+ */
27
+ #define _UPDATE_COORD_ITER(c) \
28
+ wb = iter->coordinates[c] < iter->bounds[c][1]; \
29
+ if (wb) { \
30
+ iter->coordinates[c] += 1; \
31
+ return 0; \
32
+ } \
33
+ else { \
34
+ iter->coordinates[c] = iter->bounds[c][0]; \
35
+ }
36
+
37
+ static inline int
38
+ _PyArrayNeighborhoodIter_IncrCoord(PyArrayNeighborhoodIterObject* iter)
39
+ {
40
+ npy_intp i, wb;
41
+
42
+ for (i = iter->nd - 1; i >= 0; --i) {
43
+ _UPDATE_COORD_ITER(i)
44
+ }
45
+
46
+ return 0;
47
+ }
48
+
49
+ /*
50
+ * Version optimized for 2d arrays, manual loop unrolling
51
+ */
52
+ static inline int
53
+ _PyArrayNeighborhoodIter_IncrCoord2D(PyArrayNeighborhoodIterObject* iter)
54
+ {
55
+ npy_intp wb;
56
+
57
+ _UPDATE_COORD_ITER(1)
58
+ _UPDATE_COORD_ITER(0)
59
+
60
+ return 0;
61
+ }
62
+ #undef _UPDATE_COORD_ITER
63
+
64
+ /*
65
+ * Advance to the next neighbour
66
+ */
67
+ static inline int
68
+ PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter)
69
+ {
70
+ _PyArrayNeighborhoodIter_IncrCoord (iter);
71
+ iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates);
72
+
73
+ return 0;
74
+ }
75
+
76
+ /*
77
+ * Reset functions
78
+ */
79
+ static inline int
80
+ PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter)
81
+ {
82
+ npy_intp i;
83
+
84
+ for (i = 0; i < iter->nd; ++i) {
85
+ iter->coordinates[i] = iter->bounds[i][0];
86
+ }
87
+ iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates);
88
+
89
+ return 0;
90
+ }
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/_numpyconfig.h ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #define NPY_HAVE_ENDIAN_H 1
2
+
3
+ #define NPY_SIZEOF_SHORT 2
4
+ #define NPY_SIZEOF_INT 4
5
+ #define NPY_SIZEOF_LONG 8
6
+ #define NPY_SIZEOF_FLOAT 4
7
+ #define NPY_SIZEOF_COMPLEX_FLOAT 8
8
+ #define NPY_SIZEOF_DOUBLE 8
9
+ #define NPY_SIZEOF_COMPLEX_DOUBLE 16
10
+ #define NPY_SIZEOF_LONGDOUBLE 16
11
+ #define NPY_SIZEOF_COMPLEX_LONGDOUBLE 32
12
+ #define NPY_SIZEOF_PY_INTPTR_T 8
13
+ #define NPY_SIZEOF_INTP 8
14
+ #define NPY_SIZEOF_UINTP 8
15
+ #define NPY_SIZEOF_WCHAR_T 4
16
+ #define NPY_SIZEOF_OFF_T 8
17
+ #define NPY_SIZEOF_PY_LONG_LONG 8
18
+ #define NPY_SIZEOF_LONGLONG 8
19
+
20
+ /*
21
+ * Defined to 1 or 0. Note that Pyodide hardcodes NPY_NO_SMP (and other defines
22
+ * in this header) for better cross-compilation, so don't rename them without a
23
+ * good reason.
24
+ */
25
+ #define NPY_NO_SMP 0
26
+
27
+ #define NPY_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
28
+ #define NPY_ABI_VERSION 0x02000000
29
+ #define NPY_API_VERSION 0x00000013
30
+
31
+ #ifndef __STDC_FORMAT_MACROS
32
+ #define __STDC_FORMAT_MACROS 1
33
+ #endif
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/_public_dtype_api_table.h ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Public exposure of the DType Classes. These are tricky to expose
3
+ * via the Python API, so they are exposed through this header for now.
4
+ *
5
+ * These definitions are only relevant for the public API and we reserve
6
+ * the slots 320-360 in the API table generation for this (currently).
7
+ *
8
+ * TODO: This file should be consolidated with the API table generation
9
+ * (although not sure the current generation is worth preserving).
10
+ */
11
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY__PUBLIC_DTYPE_API_TABLE_H_
12
+ #define NUMPY_CORE_INCLUDE_NUMPY__PUBLIC_DTYPE_API_TABLE_H_
13
+
14
+ #if !(defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD)
15
+
16
+ /* All of these require NumPy 2.0 support */
17
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
18
+
19
+ /*
20
+ * The type of the DType metaclass
21
+ */
22
+ #define PyArrayDTypeMeta_Type (*(PyTypeObject *)(PyArray_API + 320)[0])
23
+ /*
24
+ * NumPy's builtin DTypes:
25
+ */
26
+ #define PyArray_BoolDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[1])
27
+ /* Integers */
28
+ #define PyArray_ByteDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[2])
29
+ #define PyArray_UByteDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[3])
30
+ #define PyArray_ShortDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[4])
31
+ #define PyArray_UShortDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[5])
32
+ #define PyArray_IntDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[6])
33
+ #define PyArray_UIntDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[7])
34
+ #define PyArray_LongDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[8])
35
+ #define PyArray_ULongDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[9])
36
+ #define PyArray_LongLongDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[10])
37
+ #define PyArray_ULongLongDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[11])
38
+ /* Integer aliases */
39
+ #define PyArray_Int8DType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[12])
40
+ #define PyArray_UInt8DType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[13])
41
+ #define PyArray_Int16DType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[14])
42
+ #define PyArray_UInt16DType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[15])
43
+ #define PyArray_Int32DType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[16])
44
+ #define PyArray_UInt32DType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[17])
45
+ #define PyArray_Int64DType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[18])
46
+ #define PyArray_UInt64DType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[19])
47
+ #define PyArray_IntpDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[20])
48
+ #define PyArray_UIntpDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[21])
49
+ /* Floats */
50
+ #define PyArray_HalfDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[22])
51
+ #define PyArray_FloatDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[23])
52
+ #define PyArray_DoubleDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[24])
53
+ #define PyArray_LongDoubleDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[25])
54
+ /* Complex */
55
+ #define PyArray_CFloatDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[26])
56
+ #define PyArray_CDoubleDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[27])
57
+ #define PyArray_CLongDoubleDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[28])
58
+ /* String/Bytes */
59
+ #define PyArray_BytesDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[29])
60
+ #define PyArray_UnicodeDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[30])
61
+ /* Datetime/Timedelta */
62
+ #define PyArray_DatetimeDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[31])
63
+ #define PyArray_TimedeltaDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[32])
64
+ /* Object/Void */
65
+ #define PyArray_ObjectDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[33])
66
+ #define PyArray_VoidDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[34])
67
+ /* Python types (used as markers for scalars) */
68
+ #define PyArray_PyLongDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[35])
69
+ #define PyArray_PyFloatDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[36])
70
+ #define PyArray_PyComplexDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[37])
71
+ /* Default integer type */
72
+ #define PyArray_DefaultIntDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[38])
73
+ /* New non-legacy DTypes follow in the order they were added */
74
+ #define PyArray_StringDType (*(PyArray_DTypeMeta *)(PyArray_API + 320)[39])
75
+
76
+ /* NOTE: offset 40 is free */
77
+
78
+ /* Need to start with a larger offset again for the abstract classes: */
79
+ #define PyArray_IntAbstractDType (*(PyArray_DTypeMeta *)PyArray_API[366])
80
+ #define PyArray_FloatAbstractDType (*(PyArray_DTypeMeta *)PyArray_API[367])
81
+ #define PyArray_ComplexAbstractDType (*(PyArray_DTypeMeta *)PyArray_API[368])
82
+
83
+ #endif /* NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION */
84
+
85
+ #endif /* NPY_INTERNAL_BUILD */
86
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY__PUBLIC_DTYPE_API_TABLE_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/arrayscalars.h ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_ARRAYSCALARS_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_ARRAYSCALARS_H_
3
+
4
+ #ifndef _MULTIARRAYMODULE
5
+ typedef struct {
6
+ PyObject_HEAD
7
+ npy_bool obval;
8
+ } PyBoolScalarObject;
9
+ #endif
10
+
11
+
12
+ typedef struct {
13
+ PyObject_HEAD
14
+ signed char obval;
15
+ } PyByteScalarObject;
16
+
17
+
18
+ typedef struct {
19
+ PyObject_HEAD
20
+ short obval;
21
+ } PyShortScalarObject;
22
+
23
+
24
+ typedef struct {
25
+ PyObject_HEAD
26
+ int obval;
27
+ } PyIntScalarObject;
28
+
29
+
30
+ typedef struct {
31
+ PyObject_HEAD
32
+ long obval;
33
+ } PyLongScalarObject;
34
+
35
+
36
+ typedef struct {
37
+ PyObject_HEAD
38
+ npy_longlong obval;
39
+ } PyLongLongScalarObject;
40
+
41
+
42
+ typedef struct {
43
+ PyObject_HEAD
44
+ unsigned char obval;
45
+ } PyUByteScalarObject;
46
+
47
+
48
+ typedef struct {
49
+ PyObject_HEAD
50
+ unsigned short obval;
51
+ } PyUShortScalarObject;
52
+
53
+
54
+ typedef struct {
55
+ PyObject_HEAD
56
+ unsigned int obval;
57
+ } PyUIntScalarObject;
58
+
59
+
60
+ typedef struct {
61
+ PyObject_HEAD
62
+ unsigned long obval;
63
+ } PyULongScalarObject;
64
+
65
+
66
+ typedef struct {
67
+ PyObject_HEAD
68
+ npy_ulonglong obval;
69
+ } PyULongLongScalarObject;
70
+
71
+
72
+ typedef struct {
73
+ PyObject_HEAD
74
+ npy_half obval;
75
+ } PyHalfScalarObject;
76
+
77
+
78
+ typedef struct {
79
+ PyObject_HEAD
80
+ float obval;
81
+ } PyFloatScalarObject;
82
+
83
+
84
+ typedef struct {
85
+ PyObject_HEAD
86
+ double obval;
87
+ } PyDoubleScalarObject;
88
+
89
+
90
+ typedef struct {
91
+ PyObject_HEAD
92
+ npy_longdouble obval;
93
+ } PyLongDoubleScalarObject;
94
+
95
+
96
+ typedef struct {
97
+ PyObject_HEAD
98
+ npy_cfloat obval;
99
+ } PyCFloatScalarObject;
100
+
101
+
102
+ typedef struct {
103
+ PyObject_HEAD
104
+ npy_cdouble obval;
105
+ } PyCDoubleScalarObject;
106
+
107
+
108
+ typedef struct {
109
+ PyObject_HEAD
110
+ npy_clongdouble obval;
111
+ } PyCLongDoubleScalarObject;
112
+
113
+
114
+ typedef struct {
115
+ PyObject_HEAD
116
+ PyObject * obval;
117
+ } PyObjectScalarObject;
118
+
119
+ typedef struct {
120
+ PyObject_HEAD
121
+ npy_datetime obval;
122
+ PyArray_DatetimeMetaData obmeta;
123
+ } PyDatetimeScalarObject;
124
+
125
+ typedef struct {
126
+ PyObject_HEAD
127
+ npy_timedelta obval;
128
+ PyArray_DatetimeMetaData obmeta;
129
+ } PyTimedeltaScalarObject;
130
+
131
+
132
+ typedef struct {
133
+ PyObject_HEAD
134
+ char obval;
135
+ } PyScalarObject;
136
+
137
+ #define PyStringScalarObject PyBytesObject
138
+ #ifndef Py_LIMITED_API
139
+ typedef struct {
140
+ /* note that the PyObject_HEAD macro lives right here */
141
+ PyUnicodeObject base;
142
+ Py_UCS4 *obval;
143
+ #if NPY_FEATURE_VERSION >= NPY_1_20_API_VERSION
144
+ char *buffer_fmt;
145
+ #endif
146
+ } PyUnicodeScalarObject;
147
+ #endif
148
+
149
+
150
+ typedef struct {
151
+ PyObject_VAR_HEAD
152
+ char *obval;
153
+ #if defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD
154
+ /* Internally use the subclass to allow accessing names/fields */
155
+ _PyArray_LegacyDescr *descr;
156
+ #else
157
+ PyArray_Descr *descr;
158
+ #endif
159
+ int flags;
160
+ PyObject *base;
161
+ #if NPY_FEATURE_VERSION >= NPY_1_20_API_VERSION
162
+ void *_buffer_info; /* private buffer info, tagged to allow warning */
163
+ #endif
164
+ } PyVoidScalarObject;
165
+
166
+ /* Macros
167
+ Py<Cls><bitsize>ScalarObject
168
+ Py<Cls><bitsize>ArrType_Type
169
+ are defined in ndarrayobject.h
170
+ */
171
+
172
+ #define PyArrayScalar_False ((PyObject *)(&(_PyArrayScalar_BoolValues[0])))
173
+ #define PyArrayScalar_True ((PyObject *)(&(_PyArrayScalar_BoolValues[1])))
174
+ #define PyArrayScalar_FromLong(i) \
175
+ ((PyObject *)(&(_PyArrayScalar_BoolValues[((i)!=0)])))
176
+ #define PyArrayScalar_RETURN_BOOL_FROM_LONG(i) \
177
+ return Py_INCREF(PyArrayScalar_FromLong(i)), \
178
+ PyArrayScalar_FromLong(i)
179
+ #define PyArrayScalar_RETURN_FALSE \
180
+ return Py_INCREF(PyArrayScalar_False), \
181
+ PyArrayScalar_False
182
+ #define PyArrayScalar_RETURN_TRUE \
183
+ return Py_INCREF(PyArrayScalar_True), \
184
+ PyArrayScalar_True
185
+
186
+ #define PyArrayScalar_New(cls) \
187
+ Py##cls##ArrType_Type.tp_alloc(&Py##cls##ArrType_Type, 0)
188
+ #ifndef Py_LIMITED_API
189
+ /* For the limited API, use PyArray_ScalarAsCtype instead */
190
+ #define PyArrayScalar_VAL(obj, cls) \
191
+ ((Py##cls##ScalarObject *)obj)->obval
192
+ #define PyArrayScalar_ASSIGN(obj, cls, val) \
193
+ PyArrayScalar_VAL(obj, cls) = val
194
+ #endif
195
+
196
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_ARRAYSCALARS_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/dtype_api.h ADDED
@@ -0,0 +1,479 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * The public DType API
3
+ */
4
+
5
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY___DTYPE_API_H_
6
+ #define NUMPY_CORE_INCLUDE_NUMPY___DTYPE_API_H_
7
+
8
+ struct PyArrayMethodObject_tag;
9
+
10
+ /*
11
+ * Largely opaque struct for DType classes (i.e. metaclass instances).
12
+ * The internal definition is currently in `ndarraytypes.h` (export is a bit
13
+ * more complex because `PyArray_Descr` is a DTypeMeta internally but not
14
+ * externally).
15
+ */
16
+ #if !(defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD)
17
+
18
+ #ifndef Py_LIMITED_API
19
+
20
+ typedef struct PyArray_DTypeMeta_tag {
21
+ PyHeapTypeObject super;
22
+
23
+ /*
24
+ * Most DTypes will have a singleton default instance, for the
25
+ * parametric legacy DTypes (bytes, string, void, datetime) this
26
+ * may be a pointer to the *prototype* instance?
27
+ */
28
+ PyArray_Descr *singleton;
29
+ /* Copy of the legacy DTypes type number, usually invalid. */
30
+ int type_num;
31
+
32
+ /* The type object of the scalar instances (may be NULL?) */
33
+ PyTypeObject *scalar_type;
34
+ /*
35
+ * DType flags to signal legacy, parametric, or
36
+ * abstract. But plenty of space for additional information/flags.
37
+ */
38
+ npy_uint64 flags;
39
+
40
+ /*
41
+ * Use indirection in order to allow a fixed size for this struct.
42
+ * A stable ABI size makes creating a static DType less painful
43
+ * while also ensuring flexibility for all opaque API (with one
44
+ * indirection due the pointer lookup).
45
+ */
46
+ void *dt_slots;
47
+ /* Allow growing (at the moment also beyond this) */
48
+ void *reserved[3];
49
+ } PyArray_DTypeMeta;
50
+
51
+ #else
52
+
53
+ typedef PyTypeObject PyArray_DTypeMeta;
54
+
55
+ #endif /* Py_LIMITED_API */
56
+
57
+ #endif /* not internal build */
58
+
59
+ /*
60
+ * ******************************************************
61
+ * ArrayMethod API (Casting and UFuncs)
62
+ * ******************************************************
63
+ */
64
+
65
+
66
+ typedef enum {
67
+ /* Flag for whether the GIL is required */
68
+ NPY_METH_REQUIRES_PYAPI = 1 << 0,
69
+ /*
70
+ * Some functions cannot set floating point error flags, this flag
71
+ * gives us the option (not requirement) to skip floating point error
72
+ * setup/check. No function should set error flags and ignore them
73
+ * since it would interfere with chaining operations (e.g. casting).
74
+ */
75
+ NPY_METH_NO_FLOATINGPOINT_ERRORS = 1 << 1,
76
+ /* Whether the method supports unaligned access (not runtime) */
77
+ NPY_METH_SUPPORTS_UNALIGNED = 1 << 2,
78
+ /*
79
+ * Used for reductions to allow reordering the operation. At this point
80
+ * assume that if set, it also applies to normal operations though!
81
+ */
82
+ NPY_METH_IS_REORDERABLE = 1 << 3,
83
+ /*
84
+ * Private flag for now for *logic* functions. The logical functions
85
+ * `logical_or` and `logical_and` can always cast the inputs to booleans
86
+ * "safely" (because that is how the cast to bool is defined).
87
+ * @seberg: I am not sure this is the best way to handle this, so its
88
+ * private for now (also it is very limited anyway).
89
+ * There is one "exception". NA aware dtypes cannot cast to bool
90
+ * (hopefully), so the `??->?` loop should error even with this flag.
91
+ * But a second NA fallback loop will be necessary.
92
+ */
93
+ _NPY_METH_FORCE_CAST_INPUTS = 1 << 17,
94
+
95
+ /* All flags which can change at runtime */
96
+ NPY_METH_RUNTIME_FLAGS = (
97
+ NPY_METH_REQUIRES_PYAPI |
98
+ NPY_METH_NO_FLOATINGPOINT_ERRORS),
99
+ } NPY_ARRAYMETHOD_FLAGS;
100
+
101
+
102
+ typedef struct PyArrayMethod_Context_tag {
103
+ /* The caller, which is typically the original ufunc. May be NULL */
104
+ PyObject *caller;
105
+ /* The method "self". Currently an opaque object. */
106
+ struct PyArrayMethodObject_tag *method;
107
+
108
+ /* Operand descriptors, filled in by resolve_descriptors */
109
+ PyArray_Descr *const *descriptors;
110
+ /* Structure may grow (this is harmless for DType authors) */
111
+ } PyArrayMethod_Context;
112
+
113
+
114
+ /*
115
+ * The main object for creating a new ArrayMethod. We use the typical `slots`
116
+ * mechanism used by the Python limited API (see below for the slot defs).
117
+ */
118
+ typedef struct {
119
+ const char *name;
120
+ int nin, nout;
121
+ NPY_CASTING casting;
122
+ NPY_ARRAYMETHOD_FLAGS flags;
123
+ PyArray_DTypeMeta **dtypes;
124
+ PyType_Slot *slots;
125
+ } PyArrayMethod_Spec;
126
+
127
+
128
+ /*
129
+ * ArrayMethod slots
130
+ * -----------------
131
+ *
132
+ * SLOTS IDs For the ArrayMethod creation, once fully public, IDs are fixed
133
+ * but can be deprecated and arbitrarily extended.
134
+ */
135
+ #define _NPY_METH_resolve_descriptors_with_scalars 1
136
+ #define NPY_METH_resolve_descriptors 2
137
+ #define NPY_METH_get_loop 3
138
+ #define NPY_METH_get_reduction_initial 4
139
+ /* specific loops for constructions/default get_loop: */
140
+ #define NPY_METH_strided_loop 5
141
+ #define NPY_METH_contiguous_loop 6
142
+ #define NPY_METH_unaligned_strided_loop 7
143
+ #define NPY_METH_unaligned_contiguous_loop 8
144
+ #define NPY_METH_contiguous_indexed_loop 9
145
+ #define _NPY_METH_static_data 10
146
+
147
+
148
+ /*
149
+ * The resolve descriptors function, must be able to handle NULL values for
150
+ * all output (but not input) `given_descrs` and fill `loop_descrs`.
151
+ * Return -1 on error or 0 if the operation is not possible without an error
152
+ * set. (This may still be in flux.)
153
+ * Otherwise must return the "casting safety", for normal functions, this is
154
+ * almost always "safe" (or even "equivalent"?).
155
+ *
156
+ * `resolve_descriptors` is optional if all output DTypes are non-parametric.
157
+ */
158
+ typedef NPY_CASTING (PyArrayMethod_ResolveDescriptors)(
159
+ /* "method" is currently opaque (necessary e.g. to wrap Python) */
160
+ struct PyArrayMethodObject_tag *method,
161
+ /* DTypes the method was created for */
162
+ PyArray_DTypeMeta *const *dtypes,
163
+ /* Input descriptors (instances). Outputs may be NULL. */
164
+ PyArray_Descr *const *given_descrs,
165
+ /* Exact loop descriptors to use, must not hold references on error */
166
+ PyArray_Descr **loop_descrs,
167
+ npy_intp *view_offset);
168
+
169
+
170
+ /*
171
+ * Rarely needed, slightly more powerful version of `resolve_descriptors`.
172
+ * See also `PyArrayMethod_ResolveDescriptors` for details on shared arguments.
173
+ *
174
+ * NOTE: This function is private now as it is unclear how and what to pass
175
+ * exactly as additional information to allow dealing with the scalars.
176
+ * See also gh-24915.
177
+ */
178
+ typedef NPY_CASTING (PyArrayMethod_ResolveDescriptorsWithScalar)(
179
+ struct PyArrayMethodObject_tag *method,
180
+ PyArray_DTypeMeta *const *dtypes,
181
+ /* Unlike above, these can have any DType and we may allow NULL. */
182
+ PyArray_Descr *const *given_descrs,
183
+ /*
184
+ * Input scalars or NULL. Only ever passed for python scalars.
185
+ * WARNING: In some cases, a loop may be explicitly selected and the
186
+ * value passed is not available (NULL) or does not have the
187
+ * expected type.
188
+ */
189
+ PyObject *const *input_scalars,
190
+ PyArray_Descr **loop_descrs,
191
+ npy_intp *view_offset);
192
+
193
+
194
+
195
+ typedef int (PyArrayMethod_StridedLoop)(PyArrayMethod_Context *context,
196
+ char *const *data, const npy_intp *dimensions, const npy_intp *strides,
197
+ NpyAuxData *transferdata);
198
+
199
+
200
+ typedef int (PyArrayMethod_GetLoop)(
201
+ PyArrayMethod_Context *context,
202
+ int aligned, int move_references,
203
+ const npy_intp *strides,
204
+ PyArrayMethod_StridedLoop **out_loop,
205
+ NpyAuxData **out_transferdata,
206
+ NPY_ARRAYMETHOD_FLAGS *flags);
207
+
208
+ /**
209
+ * Query an ArrayMethod for the initial value for use in reduction.
210
+ *
211
+ * @param context The arraymethod context, mainly to access the descriptors.
212
+ * @param reduction_is_empty Whether the reduction is empty. When it is, the
213
+ * value returned may differ. In this case it is a "default" value that
214
+ * may differ from the "identity" value normally used. For example:
215
+ * - `0.0` is the default for `sum([])`. But `-0.0` is the correct
216
+ * identity otherwise as it preserves the sign for `sum([-0.0])`.
217
+ * - We use no identity for object, but return the default of `0` and `1`
218
+ * for the empty `sum([], dtype=object)` and `prod([], dtype=object)`.
219
+ * This allows `np.sum(np.array(["a", "b"], dtype=object))` to work.
220
+ * - `-inf` or `INT_MIN` for `max` is an identity, but at least `INT_MIN`
221
+ * not a good *default* when there are no items.
222
+ * @param initial Pointer to initial data to be filled (if possible)
223
+ *
224
+ * @returns -1, 0, or 1 indicating error, no initial value, and initial being
225
+ * successfully filled. Errors must not be given where 0 is correct, NumPy
226
+ * may call this even when not strictly necessary.
227
+ */
228
+ typedef int (PyArrayMethod_GetReductionInitial)(
229
+ PyArrayMethod_Context *context, npy_bool reduction_is_empty,
230
+ void *initial);
231
+
232
+ /*
233
+ * The following functions are only used by the wrapping array method defined
234
+ * in umath/wrapping_array_method.c
235
+ */
236
+
237
+
238
+ /*
239
+ * The function to convert the given descriptors (passed in to
240
+ * `resolve_descriptors`) and translates them for the wrapped loop.
241
+ * The new descriptors MUST be viewable with the old ones, `NULL` must be
242
+ * supported (for outputs) and should normally be forwarded.
243
+ *
244
+ * The function must clean up on error.
245
+ *
246
+ * NOTE: We currently assume that this translation gives "viewable" results.
247
+ * I.e. there is no additional casting related to the wrapping process.
248
+ * In principle that could be supported, but not sure it is useful.
249
+ * This currently also means that e.g. alignment must apply identically
250
+ * to the new dtypes.
251
+ *
252
+ * TODO: Due to the fact that `resolve_descriptors` is also used for `can_cast`
253
+ * there is no way to "pass out" the result of this function. This means
254
+ * it will be called twice for every ufunc call.
255
+ * (I am considering including `auxdata` as an "optional" parameter to
256
+ * `resolve_descriptors`, so that it can be filled there if not NULL.)
257
+ */
258
+ typedef int (PyArrayMethod_TranslateGivenDescriptors)(int nin, int nout,
259
+ PyArray_DTypeMeta *const wrapped_dtypes[],
260
+ PyArray_Descr *const given_descrs[], PyArray_Descr *new_descrs[]);
261
+
262
+ /**
263
+ * The function to convert the actual loop descriptors (as returned by the
264
+ * original `resolve_descriptors` function) to the ones the output array
265
+ * should use.
266
+ * This function must return "viewable" types, it must not mutate them in any
267
+ * form that would break the inner-loop logic. Does not need to support NULL.
268
+ *
269
+ * The function must clean up on error.
270
+ *
271
+ * @param nargs Number of arguments
272
+ * @param new_dtypes The DTypes of the output (usually probably not needed)
273
+ * @param given_descrs Original given_descrs to the resolver, necessary to
274
+ * fetch any information related to the new dtypes from the original.
275
+ * @param original_descrs The `loop_descrs` returned by the wrapped loop.
276
+ * @param loop_descrs The output descriptors, compatible to `original_descrs`.
277
+ *
278
+ * @returns 0 on success, -1 on failure.
279
+ */
280
+ typedef int (PyArrayMethod_TranslateLoopDescriptors)(int nin, int nout,
281
+ PyArray_DTypeMeta *const new_dtypes[], PyArray_Descr *const given_descrs[],
282
+ PyArray_Descr *original_descrs[], PyArray_Descr *loop_descrs[]);
283
+
284
+
285
+
286
+ /*
287
+ * A traverse loop working on a single array. This is similar to the general
288
+ * strided-loop function. This is designed for loops that need to visit every
289
+ * element of a single array.
290
+ *
291
+ * Currently this is used for array clearing, via the NPY_DT_get_clear_loop
292
+ * API hook, and zero-filling, via the NPY_DT_get_fill_zero_loop API hook.
293
+ * These are most useful for handling arrays storing embedded references to
294
+ * python objects or heap-allocated data.
295
+ *
296
+ * The `void *traverse_context` is passed in because we may need to pass in
297
+ * Interpreter state or similar in the future, but we don't want to pass in
298
+ * a full context (with pointers to dtypes, method, caller which all make
299
+ * no sense for a traverse function).
300
+ *
301
+ * We assume for now that this context can be just passed through in the
302
+ * the future (for structured dtypes).
303
+ *
304
+ */
305
+ typedef int (PyArrayMethod_TraverseLoop)(
306
+ void *traverse_context, const PyArray_Descr *descr, char *data,
307
+ npy_intp size, npy_intp stride, NpyAuxData *auxdata);
308
+
309
+
310
+ /*
311
+ * Simplified get_loop function specific to dtype traversal
312
+ *
313
+ * It should set the flags needed for the traversal loop and set out_loop to the
314
+ * loop function, which must be a valid PyArrayMethod_TraverseLoop
315
+ * pointer. Currently this is used for zero-filling and clearing arrays storing
316
+ * embedded references.
317
+ *
318
+ */
319
+ typedef int (PyArrayMethod_GetTraverseLoop)(
320
+ void *traverse_context, const PyArray_Descr *descr,
321
+ int aligned, npy_intp fixed_stride,
322
+ PyArrayMethod_TraverseLoop **out_loop, NpyAuxData **out_auxdata,
323
+ NPY_ARRAYMETHOD_FLAGS *flags);
324
+
325
+
326
+ /*
327
+ * Type of the C promoter function, which must be wrapped into a
328
+ * PyCapsule with name "numpy._ufunc_promoter".
329
+ *
330
+ * Note that currently the output dtypes are always NULL unless they are
331
+ * also part of the signature. This is an implementation detail and could
332
+ * change in the future. However, in general promoters should not have a
333
+ * need for output dtypes.
334
+ * (There are potential use-cases, these are currently unsupported.)
335
+ */
336
+ typedef int (PyArrayMethod_PromoterFunction)(PyObject *ufunc,
337
+ PyArray_DTypeMeta *const op_dtypes[], PyArray_DTypeMeta *const signature[],
338
+ PyArray_DTypeMeta *new_op_dtypes[]);
339
+
340
+ /*
341
+ * ****************************
342
+ * DTYPE API
343
+ * ****************************
344
+ */
345
+
346
+ #define NPY_DT_ABSTRACT 1 << 1
347
+ #define NPY_DT_PARAMETRIC 1 << 2
348
+ #define NPY_DT_NUMERIC 1 << 3
349
+
350
+ /*
351
+ * These correspond to slots in the NPY_DType_Slots struct and must
352
+ * be in the same order as the members of that struct. If new slots
353
+ * get added or old slots get removed NPY_NUM_DTYPE_SLOTS must also
354
+ * be updated
355
+ */
356
+
357
+ #define NPY_DT_discover_descr_from_pyobject 1
358
+ // this slot is considered private because its API hasn't been decided
359
+ #define _NPY_DT_is_known_scalar_type 2
360
+ #define NPY_DT_default_descr 3
361
+ #define NPY_DT_common_dtype 4
362
+ #define NPY_DT_common_instance 5
363
+ #define NPY_DT_ensure_canonical 6
364
+ #define NPY_DT_setitem 7
365
+ #define NPY_DT_getitem 8
366
+ #define NPY_DT_get_clear_loop 9
367
+ #define NPY_DT_get_fill_zero_loop 10
368
+ #define NPY_DT_finalize_descr 11
369
+
370
+ // These PyArray_ArrFunc slots will be deprecated and replaced eventually
371
+ // getitem and setitem can be defined as a performance optimization;
372
+ // by default the user dtypes call `legacy_getitem_using_DType` and
373
+ // `legacy_setitem_using_DType`, respectively. This functionality is
374
+ // only supported for basic NumPy DTypes.
375
+
376
+
377
+ // used to separate dtype slots from arrfuncs slots
378
+ // intended only for internal use but defined here for clarity
379
+ #define _NPY_DT_ARRFUNCS_OFFSET (1 << 10)
380
+
381
+ // Cast is disabled
382
+ // #define NPY_DT_PyArray_ArrFuncs_cast 0 + _NPY_DT_ARRFUNCS_OFFSET
383
+
384
+ #define NPY_DT_PyArray_ArrFuncs_getitem 1 + _NPY_DT_ARRFUNCS_OFFSET
385
+ #define NPY_DT_PyArray_ArrFuncs_setitem 2 + _NPY_DT_ARRFUNCS_OFFSET
386
+
387
+ // Copyswap is disabled
388
+ // #define NPY_DT_PyArray_ArrFuncs_copyswapn 3 + _NPY_DT_ARRFUNCS_OFFSET
389
+ // #define NPY_DT_PyArray_ArrFuncs_copyswap 4 + _NPY_DT_ARRFUNCS_OFFSET
390
+ #define NPY_DT_PyArray_ArrFuncs_compare 5 + _NPY_DT_ARRFUNCS_OFFSET
391
+ #define NPY_DT_PyArray_ArrFuncs_argmax 6 + _NPY_DT_ARRFUNCS_OFFSET
392
+ #define NPY_DT_PyArray_ArrFuncs_dotfunc 7 + _NPY_DT_ARRFUNCS_OFFSET
393
+ #define NPY_DT_PyArray_ArrFuncs_scanfunc 8 + _NPY_DT_ARRFUNCS_OFFSET
394
+ #define NPY_DT_PyArray_ArrFuncs_fromstr 9 + _NPY_DT_ARRFUNCS_OFFSET
395
+ #define NPY_DT_PyArray_ArrFuncs_nonzero 10 + _NPY_DT_ARRFUNCS_OFFSET
396
+ #define NPY_DT_PyArray_ArrFuncs_fill 11 + _NPY_DT_ARRFUNCS_OFFSET
397
+ #define NPY_DT_PyArray_ArrFuncs_fillwithscalar 12 + _NPY_DT_ARRFUNCS_OFFSET
398
+ #define NPY_DT_PyArray_ArrFuncs_sort 13 + _NPY_DT_ARRFUNCS_OFFSET
399
+ #define NPY_DT_PyArray_ArrFuncs_argsort 14 + _NPY_DT_ARRFUNCS_OFFSET
400
+
401
+ // Casting related slots are disabled. See
402
+ // https://github.com/numpy/numpy/pull/23173#discussion_r1101098163
403
+ // #define NPY_DT_PyArray_ArrFuncs_castdict 15 + _NPY_DT_ARRFUNCS_OFFSET
404
+ // #define NPY_DT_PyArray_ArrFuncs_scalarkind 16 + _NPY_DT_ARRFUNCS_OFFSET
405
+ // #define NPY_DT_PyArray_ArrFuncs_cancastscalarkindto 17 + _NPY_DT_ARRFUNCS_OFFSET
406
+ // #define NPY_DT_PyArray_ArrFuncs_cancastto 18 + _NPY_DT_ARRFUNCS_OFFSET
407
+
408
+ // These are deprecated in NumPy 1.19, so are disabled here.
409
+ // #define NPY_DT_PyArray_ArrFuncs_fastclip 19 + _NPY_DT_ARRFUNCS_OFFSET
410
+ // #define NPY_DT_PyArray_ArrFuncs_fastputmask 20 + _NPY_DT_ARRFUNCS_OFFSET
411
+ // #define NPY_DT_PyArray_ArrFuncs_fasttake 21 + _NPY_DT_ARRFUNCS_OFFSET
412
+ #define NPY_DT_PyArray_ArrFuncs_argmin 22 + _NPY_DT_ARRFUNCS_OFFSET
413
+
414
+
415
+ // TODO: These slots probably still need some thought, and/or a way to "grow"?
416
+ typedef struct {
417
+ PyTypeObject *typeobj; /* type of python scalar or NULL */
418
+ int flags; /* flags, including parametric and abstract */
419
+ /* NULL terminated cast definitions. Use NULL for the newly created DType */
420
+ PyArrayMethod_Spec **casts;
421
+ PyType_Slot *slots;
422
+ /* Baseclass or NULL (will always subclass `np.dtype`) */
423
+ PyTypeObject *baseclass;
424
+ } PyArrayDTypeMeta_Spec;
425
+
426
+
427
+ typedef PyArray_Descr *(PyArrayDTypeMeta_DiscoverDescrFromPyobject)(
428
+ PyArray_DTypeMeta *cls, PyObject *obj);
429
+
430
+ /*
431
+ * Before making this public, we should decide whether it should pass
432
+ * the type, or allow looking at the object. A possible use-case:
433
+ * `np.array(np.array([0]), dtype=np.ndarray)`
434
+ * Could consider arrays that are not `dtype=ndarray` "scalars".
435
+ */
436
+ typedef int (PyArrayDTypeMeta_IsKnownScalarType)(
437
+ PyArray_DTypeMeta *cls, PyTypeObject *obj);
438
+
439
+ typedef PyArray_Descr *(PyArrayDTypeMeta_DefaultDescriptor)(PyArray_DTypeMeta *cls);
440
+ typedef PyArray_DTypeMeta *(PyArrayDTypeMeta_CommonDType)(
441
+ PyArray_DTypeMeta *dtype1, PyArray_DTypeMeta *dtype2);
442
+
443
+
444
+ /*
445
+ * Convenience utility for getting a reference to the DType metaclass associated
446
+ * with a dtype instance.
447
+ */
448
+ #define NPY_DTYPE(descr) ((PyArray_DTypeMeta *)Py_TYPE(descr))
449
+
450
+ static inline PyArray_DTypeMeta *
451
+ NPY_DT_NewRef(PyArray_DTypeMeta *o) {
452
+ Py_INCREF((PyObject *)o);
453
+ return o;
454
+ }
455
+
456
+
457
+ typedef PyArray_Descr *(PyArrayDTypeMeta_CommonInstance)(
458
+ PyArray_Descr *dtype1, PyArray_Descr *dtype2);
459
+ typedef PyArray_Descr *(PyArrayDTypeMeta_EnsureCanonical)(PyArray_Descr *dtype);
460
+ /*
461
+ * Returns either a new reference to *dtype* or a new descriptor instance
462
+ * initialized with the same parameters as *dtype*. The caller cannot know
463
+ * which choice a dtype will make. This function is called just before the
464
+ * array buffer is created for a newly created array, it is not called for
465
+ * views and the descriptor returned by this function is attached to the array.
466
+ */
467
+ typedef PyArray_Descr *(PyArrayDTypeMeta_FinalizeDescriptor)(PyArray_Descr *dtype);
468
+
469
+ /*
470
+ * TODO: These two functions are currently only used for experimental DType
471
+ * API support. Their relation should be "reversed": NumPy should
472
+ * always use them internally.
473
+ * There are open points about "casting safety" though, e.g. setting
474
+ * elements is currently always unsafe.
475
+ */
476
+ typedef int(PyArrayDTypeMeta_SetItem)(PyArray_Descr *, PyObject *, char *);
477
+ typedef PyObject *(PyArrayDTypeMeta_GetItem)(PyArray_Descr *, char *);
478
+
479
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY___DTYPE_API_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/halffloat.h ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_HALFFLOAT_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_HALFFLOAT_H_
3
+
4
+ #include <Python.h>
5
+ #include <numpy/npy_math.h>
6
+
7
+ #ifdef __cplusplus
8
+ extern "C" {
9
+ #endif
10
+
11
+ /*
12
+ * Half-precision routines
13
+ */
14
+
15
+ /* Conversions */
16
+ float npy_half_to_float(npy_half h);
17
+ double npy_half_to_double(npy_half h);
18
+ npy_half npy_float_to_half(float f);
19
+ npy_half npy_double_to_half(double d);
20
+ /* Comparisons */
21
+ int npy_half_eq(npy_half h1, npy_half h2);
22
+ int npy_half_ne(npy_half h1, npy_half h2);
23
+ int npy_half_le(npy_half h1, npy_half h2);
24
+ int npy_half_lt(npy_half h1, npy_half h2);
25
+ int npy_half_ge(npy_half h1, npy_half h2);
26
+ int npy_half_gt(npy_half h1, npy_half h2);
27
+ /* faster *_nonan variants for when you know h1 and h2 are not NaN */
28
+ int npy_half_eq_nonan(npy_half h1, npy_half h2);
29
+ int npy_half_lt_nonan(npy_half h1, npy_half h2);
30
+ int npy_half_le_nonan(npy_half h1, npy_half h2);
31
+ /* Miscellaneous functions */
32
+ int npy_half_iszero(npy_half h);
33
+ int npy_half_isnan(npy_half h);
34
+ int npy_half_isinf(npy_half h);
35
+ int npy_half_isfinite(npy_half h);
36
+ int npy_half_signbit(npy_half h);
37
+ npy_half npy_half_copysign(npy_half x, npy_half y);
38
+ npy_half npy_half_spacing(npy_half h);
39
+ npy_half npy_half_nextafter(npy_half x, npy_half y);
40
+ npy_half npy_half_divmod(npy_half x, npy_half y, npy_half *modulus);
41
+
42
+ /*
43
+ * Half-precision constants
44
+ */
45
+
46
+ #define NPY_HALF_ZERO (0x0000u)
47
+ #define NPY_HALF_PZERO (0x0000u)
48
+ #define NPY_HALF_NZERO (0x8000u)
49
+ #define NPY_HALF_ONE (0x3c00u)
50
+ #define NPY_HALF_NEGONE (0xbc00u)
51
+ #define NPY_HALF_PINF (0x7c00u)
52
+ #define NPY_HALF_NINF (0xfc00u)
53
+ #define NPY_HALF_NAN (0x7e00u)
54
+
55
+ #define NPY_MAX_HALF (0x7bffu)
56
+
57
+ /*
58
+ * Bit-level conversions
59
+ */
60
+
61
+ npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f);
62
+ npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d);
63
+ npy_uint32 npy_halfbits_to_floatbits(npy_uint16 h);
64
+ npy_uint64 npy_halfbits_to_doublebits(npy_uint16 h);
65
+
66
+ #ifdef __cplusplus
67
+ }
68
+ #endif
69
+
70
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_HALFFLOAT_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/ndarrayobject.h ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * DON'T INCLUDE THIS DIRECTLY.
3
+ */
4
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NDARRAYOBJECT_H_
5
+ #define NUMPY_CORE_INCLUDE_NUMPY_NDARRAYOBJECT_H_
6
+
7
+ #ifdef __cplusplus
8
+ extern "C" {
9
+ #endif
10
+
11
+ #include <Python.h>
12
+ #include "ndarraytypes.h"
13
+ #include "dtype_api.h"
14
+
15
+ /* Includes the "function" C-API -- these are all stored in a
16
+ list of pointers --- one for each file
17
+ The two lists are concatenated into one in multiarray.
18
+
19
+ They are available as import_array()
20
+ */
21
+
22
+ #include "__multiarray_api.h"
23
+
24
+ /*
25
+ * Include any definitions which are defined differently for 1.x and 2.x
26
+ * (Symbols only available on 2.x are not there, but rather guarded.)
27
+ */
28
+ #include "npy_2_compat.h"
29
+
30
+ /* C-API that requires previous API to be defined */
31
+
32
+ #define PyArray_DescrCheck(op) PyObject_TypeCheck(op, &PyArrayDescr_Type)
33
+
34
+ #define PyArray_Check(op) PyObject_TypeCheck(op, &PyArray_Type)
35
+ #define PyArray_CheckExact(op) (((PyObject*)(op))->ob_type == &PyArray_Type)
36
+
37
+ #define PyArray_HasArrayInterfaceType(op, type, context, out) \
38
+ ((((out)=PyArray_FromStructInterface(op)) != Py_NotImplemented) || \
39
+ (((out)=PyArray_FromInterface(op)) != Py_NotImplemented) || \
40
+ (((out)=PyArray_FromArrayAttr(op, type, context)) != \
41
+ Py_NotImplemented))
42
+
43
+ #define PyArray_HasArrayInterface(op, out) \
44
+ PyArray_HasArrayInterfaceType(op, NULL, NULL, out)
45
+
46
+ #define PyArray_IsZeroDim(op) (PyArray_Check(op) && \
47
+ (PyArray_NDIM((PyArrayObject *)op) == 0))
48
+
49
+ #define PyArray_IsScalar(obj, cls) \
50
+ (PyObject_TypeCheck(obj, &Py##cls##ArrType_Type))
51
+
52
+ #define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \
53
+ PyArray_IsZeroDim(m))
54
+ #define PyArray_IsPythonNumber(obj) \
55
+ (PyFloat_Check(obj) || PyComplex_Check(obj) || \
56
+ PyLong_Check(obj) || PyBool_Check(obj))
57
+ #define PyArray_IsIntegerScalar(obj) (PyLong_Check(obj) \
58
+ || PyArray_IsScalar((obj), Integer))
59
+ #define PyArray_IsPythonScalar(obj) \
60
+ (PyArray_IsPythonNumber(obj) || PyBytes_Check(obj) || \
61
+ PyUnicode_Check(obj))
62
+
63
+ #define PyArray_IsAnyScalar(obj) \
64
+ (PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))
65
+
66
+ #define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \
67
+ PyArray_CheckScalar(obj))
68
+
69
+
70
+ #define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? \
71
+ Py_INCREF(m), (m) : \
72
+ (PyArrayObject *)(PyArray_Copy(m)))
73
+
74
+ #define PyArray_SAMESHAPE(a1,a2) ((PyArray_NDIM(a1) == PyArray_NDIM(a2)) && \
75
+ PyArray_CompareLists(PyArray_DIMS(a1), \
76
+ PyArray_DIMS(a2), \
77
+ PyArray_NDIM(a1)))
78
+
79
+ #define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))
80
+ #define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))
81
+ #define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)
82
+
83
+ #define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, \
84
+ NULL)
85
+
86
+ #define PyArray_FROM_OT(m,type) PyArray_FromAny(m, \
87
+ PyArray_DescrFromType(type), 0, 0, 0, NULL)
88
+
89
+ #define PyArray_FROM_OTF(m, type, flags) \
90
+ PyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \
91
+ (((flags) & NPY_ARRAY_ENSURECOPY) ? \
92
+ ((flags) | NPY_ARRAY_DEFAULT) : (flags)), NULL)
93
+
94
+ #define PyArray_FROMANY(m, type, min, max, flags) \
95
+ PyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \
96
+ (((flags) & NPY_ARRAY_ENSURECOPY) ? \
97
+ (flags) | NPY_ARRAY_DEFAULT : (flags)), NULL)
98
+
99
+ #define PyArray_ZEROS(m, dims, type, is_f_order) \
100
+ PyArray_Zeros(m, dims, PyArray_DescrFromType(type), is_f_order)
101
+
102
+ #define PyArray_EMPTY(m, dims, type, is_f_order) \
103
+ PyArray_Empty(m, dims, PyArray_DescrFromType(type), is_f_order)
104
+
105
+ #define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), val, \
106
+ PyArray_NBYTES(obj))
107
+
108
+ #define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \
109
+ PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
110
+ max_depth, NPY_ARRAY_DEFAULT, NULL)
111
+
112
+ #define PyArray_EquivArrTypes(a1, a2) \
113
+ PyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))
114
+
115
+ #define PyArray_EquivByteorders(b1, b2) \
116
+ (((b1) == (b2)) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))
117
+
118
+ #define PyArray_SimpleNew(nd, dims, typenum) \
119
+ PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)
120
+
121
+ #define PyArray_SimpleNewFromData(nd, dims, typenum, data) \
122
+ PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, \
123
+ data, 0, NPY_ARRAY_CARRAY, NULL)
124
+
125
+ #define PyArray_SimpleNewFromDescr(nd, dims, descr) \
126
+ PyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, \
127
+ NULL, NULL, 0, NULL)
128
+
129
+ #define PyArray_ToScalar(data, arr) \
130
+ PyArray_Scalar(data, PyArray_DESCR(arr), (PyObject *)arr)
131
+
132
+
133
+ /* These might be faster without the dereferencing of obj
134
+ going on inside -- of course an optimizing compiler should
135
+ inline the constants inside a for loop making it a moot point
136
+ */
137
+
138
+ #define PyArray_GETPTR1(obj, i) ((void *)(PyArray_BYTES(obj) + \
139
+ (i)*PyArray_STRIDES(obj)[0]))
140
+
141
+ #define PyArray_GETPTR2(obj, i, j) ((void *)(PyArray_BYTES(obj) + \
142
+ (i)*PyArray_STRIDES(obj)[0] + \
143
+ (j)*PyArray_STRIDES(obj)[1]))
144
+
145
+ #define PyArray_GETPTR3(obj, i, j, k) ((void *)(PyArray_BYTES(obj) + \
146
+ (i)*PyArray_STRIDES(obj)[0] + \
147
+ (j)*PyArray_STRIDES(obj)[1] + \
148
+ (k)*PyArray_STRIDES(obj)[2]))
149
+
150
+ #define PyArray_GETPTR4(obj, i, j, k, l) ((void *)(PyArray_BYTES(obj) + \
151
+ (i)*PyArray_STRIDES(obj)[0] + \
152
+ (j)*PyArray_STRIDES(obj)[1] + \
153
+ (k)*PyArray_STRIDES(obj)[2] + \
154
+ (l)*PyArray_STRIDES(obj)[3]))
155
+
156
+ static inline void
157
+ PyArray_DiscardWritebackIfCopy(PyArrayObject *arr)
158
+ {
159
+ PyArrayObject_fields *fa = (PyArrayObject_fields *)arr;
160
+ if (fa && fa->base) {
161
+ if (fa->flags & NPY_ARRAY_WRITEBACKIFCOPY) {
162
+ PyArray_ENABLEFLAGS((PyArrayObject*)fa->base, NPY_ARRAY_WRITEABLE);
163
+ Py_DECREF(fa->base);
164
+ fa->base = NULL;
165
+ PyArray_CLEARFLAGS(arr, NPY_ARRAY_WRITEBACKIFCOPY);
166
+ }
167
+ }
168
+ }
169
+
170
+ #define PyArray_DESCR_REPLACE(descr) do { \
171
+ PyArray_Descr *_new_; \
172
+ _new_ = PyArray_DescrNew(descr); \
173
+ Py_XDECREF(descr); \
174
+ descr = _new_; \
175
+ } while(0)
176
+
177
+ /* Copy should always return contiguous array */
178
+ #define PyArray_Copy(obj) PyArray_NewCopy(obj, NPY_CORDER)
179
+
180
+ #define PyArray_FromObject(op, type, min_depth, max_depth) \
181
+ PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
182
+ max_depth, NPY_ARRAY_BEHAVED | \
183
+ NPY_ARRAY_ENSUREARRAY, NULL)
184
+
185
+ #define PyArray_ContiguousFromObject(op, type, min_depth, max_depth) \
186
+ PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
187
+ max_depth, NPY_ARRAY_DEFAULT | \
188
+ NPY_ARRAY_ENSUREARRAY, NULL)
189
+
190
+ #define PyArray_CopyFromObject(op, type, min_depth, max_depth) \
191
+ PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
192
+ max_depth, NPY_ARRAY_ENSURECOPY | \
193
+ NPY_ARRAY_DEFAULT | \
194
+ NPY_ARRAY_ENSUREARRAY, NULL)
195
+
196
+ #define PyArray_Cast(mp, type_num) \
197
+ PyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)
198
+
199
+ #define PyArray_Take(ap, items, axis) \
200
+ PyArray_TakeFrom(ap, items, axis, NULL, NPY_RAISE)
201
+
202
+ #define PyArray_Put(ap, items, values) \
203
+ PyArray_PutTo(ap, items, values, NPY_RAISE)
204
+
205
+
206
+ /*
207
+ Check to see if this key in the dictionary is the "title"
208
+ entry of the tuple (i.e. a duplicate dictionary entry in the fields
209
+ dict).
210
+ */
211
+
212
+ static inline int
213
+ NPY_TITLE_KEY_check(PyObject *key, PyObject *value)
214
+ {
215
+ PyObject *title;
216
+ if (PyTuple_Size(value) != 3) {
217
+ return 0;
218
+ }
219
+ title = PyTuple_GetItem(value, 2);
220
+ if (key == title) {
221
+ return 1;
222
+ }
223
+ #ifdef PYPY_VERSION
224
+ /*
225
+ * On PyPy, dictionary keys do not always preserve object identity.
226
+ * Fall back to comparison by value.
227
+ */
228
+ if (PyUnicode_Check(title) && PyUnicode_Check(key)) {
229
+ return PyUnicode_Compare(title, key) == 0 ? 1 : 0;
230
+ }
231
+ #endif
232
+ return 0;
233
+ }
234
+
235
+ /* Macro, for backward compat with "if NPY_TITLE_KEY(key, value) { ..." */
236
+ #define NPY_TITLE_KEY(key, value) (NPY_TITLE_KEY_check((key), (value)))
237
+
238
+ #define DEPRECATE(msg) PyErr_WarnEx(PyExc_DeprecationWarning,msg,1)
239
+ #define DEPRECATE_FUTUREWARNING(msg) PyErr_WarnEx(PyExc_FutureWarning,msg,1)
240
+
241
+
242
+ /*
243
+ * These macros and functions unfortunately require runtime version checks
244
+ * that are only defined in `npy_2_compat.h`. For that reasons they cannot be
245
+ * part of `ndarraytypes.h` which tries to be self contained.
246
+ */
247
+
248
+ static inline npy_intp
249
+ PyArray_ITEMSIZE(const PyArrayObject *arr)
250
+ {
251
+ return PyDataType_ELSIZE(((PyArrayObject_fields *)arr)->descr);
252
+ }
253
+
254
+ #define PyDataType_HASFIELDS(obj) (PyDataType_ISLEGACY((PyArray_Descr*)(obj)) && PyDataType_NAMES((PyArray_Descr*)(obj)) != NULL)
255
+ #define PyDataType_HASSUBARRAY(dtype) (PyDataType_ISLEGACY(dtype) && PyDataType_SUBARRAY(dtype) != NULL)
256
+ #define PyDataType_ISUNSIZED(dtype) ((dtype)->elsize == 0 && \
257
+ !PyDataType_HASFIELDS(dtype))
258
+
259
+ #define PyDataType_FLAGCHK(dtype, flag) \
260
+ ((PyDataType_FLAGS(dtype) & (flag)) == (flag))
261
+
262
+ #define PyDataType_REFCHK(dtype) \
263
+ PyDataType_FLAGCHK(dtype, NPY_ITEM_REFCOUNT)
264
+
265
+ #define NPY_BEGIN_THREADS_DESCR(dtype) \
266
+ do {if (!(PyDataType_FLAGCHK((dtype), NPY_NEEDS_PYAPI))) \
267
+ NPY_BEGIN_THREADS;} while (0);
268
+
269
+ #define NPY_END_THREADS_DESCR(dtype) \
270
+ do {if (!(PyDataType_FLAGCHK((dtype), NPY_NEEDS_PYAPI))) \
271
+ NPY_END_THREADS; } while (0);
272
+
273
+ #if !(defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD)
274
+ /* The internal copy of this is now defined in `dtypemeta.h` */
275
+ /*
276
+ * `PyArray_Scalar` is the same as this function but converts will convert
277
+ * most NumPy types to Python scalars.
278
+ */
279
+ static inline PyObject *
280
+ PyArray_GETITEM(const PyArrayObject *arr, const char *itemptr)
281
+ {
282
+ return PyDataType_GetArrFuncs(((PyArrayObject_fields *)arr)->descr)->getitem(
283
+ (void *)itemptr, (PyArrayObject *)arr);
284
+ }
285
+
286
+ /*
287
+ * SETITEM should only be used if it is known that the value is a scalar
288
+ * and of a type understood by the arrays dtype.
289
+ * Use `PyArray_Pack` if the value may be of a different dtype.
290
+ */
291
+ static inline int
292
+ PyArray_SETITEM(PyArrayObject *arr, char *itemptr, PyObject *v)
293
+ {
294
+ return PyDataType_GetArrFuncs(((PyArrayObject_fields *)arr)->descr)->setitem(v, itemptr, arr);
295
+ }
296
+ #endif /* not internal */
297
+
298
+
299
+ #ifdef __cplusplus
300
+ }
301
+ #endif
302
+
303
+
304
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NDARRAYOBJECT_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/ndarraytypes.h ADDED
@@ -0,0 +1,1925 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NDARRAYTYPES_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_NDARRAYTYPES_H_
3
+
4
+ #include "npy_common.h"
5
+ #include "npy_endian.h"
6
+ #include "npy_cpu.h"
7
+ #include "utils.h"
8
+
9
+ #define NPY_NO_EXPORT NPY_VISIBILITY_HIDDEN
10
+
11
+ /* Always allow threading unless it was explicitly disabled at build time */
12
+ #if !NPY_NO_SMP
13
+ #define NPY_ALLOW_THREADS 1
14
+ #else
15
+ #define NPY_ALLOW_THREADS 0
16
+ #endif
17
+
18
+ #ifndef __has_extension
19
+ #define __has_extension(x) 0
20
+ #endif
21
+
22
+ /*
23
+ * There are several places in the code where an array of dimensions
24
+ * is allocated statically. This is the size of that static
25
+ * allocation.
26
+ *
27
+ * The array creation itself could have arbitrary dimensions but all
28
+ * the places where static allocation is used would need to be changed
29
+ * to dynamic (including inside of several structures)
30
+ *
31
+ * As of NumPy 2.0, we strongly discourage the downstream use of NPY_MAXDIMS,
32
+ * but since auditing everything seems a big ask, define it as 64.
33
+ * A future version could:
34
+ * - Increase or remove the limit and require recompilation (like 2.0 did)
35
+ * - Deprecate or remove the macro but keep the limit (at basically any time)
36
+ */
37
+ #define NPY_MAXDIMS 64
38
+ /* We cannot change this as it would break ABI: */
39
+ #define NPY_MAXDIMS_LEGACY_ITERS 32
40
+ /* NPY_MAXARGS is version dependent and defined in npy_2_compat.h */
41
+
42
+ /* Used for Converter Functions "O&" code in ParseTuple */
43
+ #define NPY_FAIL 0
44
+ #define NPY_SUCCEED 1
45
+
46
+
47
+ enum NPY_TYPES { NPY_BOOL=0,
48
+ NPY_BYTE, NPY_UBYTE,
49
+ NPY_SHORT, NPY_USHORT,
50
+ NPY_INT, NPY_UINT,
51
+ NPY_LONG, NPY_ULONG,
52
+ NPY_LONGLONG, NPY_ULONGLONG,
53
+ NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE,
54
+ NPY_CFLOAT, NPY_CDOUBLE, NPY_CLONGDOUBLE,
55
+ NPY_OBJECT=17,
56
+ NPY_STRING, NPY_UNICODE,
57
+ NPY_VOID,
58
+ /*
59
+ * New 1.6 types appended, may be integrated
60
+ * into the above in 2.0.
61
+ */
62
+ NPY_DATETIME, NPY_TIMEDELTA, NPY_HALF,
63
+
64
+ NPY_CHAR, /* Deprecated, will raise if used */
65
+
66
+ /* The number of *legacy* dtypes */
67
+ NPY_NTYPES_LEGACY=24,
68
+
69
+ /* assign a high value to avoid changing this in the
70
+ future when new dtypes are added */
71
+ NPY_NOTYPE=25,
72
+
73
+ NPY_USERDEF=256, /* leave room for characters */
74
+
75
+ /* The number of types not including the new 1.6 types */
76
+ NPY_NTYPES_ABI_COMPATIBLE=21,
77
+
78
+ /*
79
+ * New DTypes which do not share the legacy layout
80
+ * (added after NumPy 2.0). VSTRING is the first of these
81
+ * we may open up a block for user-defined dtypes in the
82
+ * future.
83
+ */
84
+ NPY_VSTRING=2056,
85
+ };
86
+
87
+
88
+ /* basetype array priority */
89
+ #define NPY_PRIORITY 0.0
90
+
91
+ /* default subtype priority */
92
+ #define NPY_SUBTYPE_PRIORITY 1.0
93
+
94
+ /* default scalar priority */
95
+ #define NPY_SCALAR_PRIORITY -1000000.0
96
+
97
+ /* How many floating point types are there (excluding half) */
98
+ #define NPY_NUM_FLOATTYPE 3
99
+
100
+ /*
101
+ * These characters correspond to the array type and the struct
102
+ * module
103
+ */
104
+
105
+ enum NPY_TYPECHAR {
106
+ NPY_BOOLLTR = '?',
107
+ NPY_BYTELTR = 'b',
108
+ NPY_UBYTELTR = 'B',
109
+ NPY_SHORTLTR = 'h',
110
+ NPY_USHORTLTR = 'H',
111
+ NPY_INTLTR = 'i',
112
+ NPY_UINTLTR = 'I',
113
+ NPY_LONGLTR = 'l',
114
+ NPY_ULONGLTR = 'L',
115
+ NPY_LONGLONGLTR = 'q',
116
+ NPY_ULONGLONGLTR = 'Q',
117
+ NPY_HALFLTR = 'e',
118
+ NPY_FLOATLTR = 'f',
119
+ NPY_DOUBLELTR = 'd',
120
+ NPY_LONGDOUBLELTR = 'g',
121
+ NPY_CFLOATLTR = 'F',
122
+ NPY_CDOUBLELTR = 'D',
123
+ NPY_CLONGDOUBLELTR = 'G',
124
+ NPY_OBJECTLTR = 'O',
125
+ NPY_STRINGLTR = 'S',
126
+ NPY_DEPRECATED_STRINGLTR2 = 'a',
127
+ NPY_UNICODELTR = 'U',
128
+ NPY_VOIDLTR = 'V',
129
+ NPY_DATETIMELTR = 'M',
130
+ NPY_TIMEDELTALTR = 'm',
131
+ NPY_CHARLTR = 'c',
132
+
133
+ /*
134
+ * New non-legacy DTypes
135
+ */
136
+ NPY_VSTRINGLTR = 'T',
137
+
138
+ /*
139
+ * Note, we removed `NPY_INTPLTR` due to changing its definition
140
+ * to 'n', rather than 'p'. On any typical platform this is the
141
+ * same integer. 'n' should be used for the `np.intp` with the same
142
+ * size as `size_t` while 'p' remains pointer sized.
143
+ *
144
+ * 'p', 'P', 'n', and 'N' are valid and defined explicitly
145
+ * in `arraytypes.c.src`.
146
+ */
147
+
148
+ /*
149
+ * These are for dtype 'kinds', not dtype 'typecodes'
150
+ * as the above are for.
151
+ */
152
+ NPY_GENBOOLLTR ='b',
153
+ NPY_SIGNEDLTR = 'i',
154
+ NPY_UNSIGNEDLTR = 'u',
155
+ NPY_FLOATINGLTR = 'f',
156
+ NPY_COMPLEXLTR = 'c',
157
+
158
+ };
159
+
160
+ /*
161
+ * Changing this may break Numpy API compatibility
162
+ * due to changing offsets in PyArray_ArrFuncs, so be
163
+ * careful. Here we have reused the mergesort slot for
164
+ * any kind of stable sort, the actual implementation will
165
+ * depend on the data type.
166
+ */
167
+ typedef enum {
168
+ _NPY_SORT_UNDEFINED=-1,
169
+ NPY_QUICKSORT=0,
170
+ NPY_HEAPSORT=1,
171
+ NPY_MERGESORT=2,
172
+ NPY_STABLESORT=2,
173
+ } NPY_SORTKIND;
174
+ #define NPY_NSORTS (NPY_STABLESORT + 1)
175
+
176
+
177
+ typedef enum {
178
+ NPY_INTROSELECT=0
179
+ } NPY_SELECTKIND;
180
+ #define NPY_NSELECTS (NPY_INTROSELECT + 1)
181
+
182
+
183
+ typedef enum {
184
+ NPY_SEARCHLEFT=0,
185
+ NPY_SEARCHRIGHT=1
186
+ } NPY_SEARCHSIDE;
187
+ #define NPY_NSEARCHSIDES (NPY_SEARCHRIGHT + 1)
188
+
189
+
190
+ typedef enum {
191
+ NPY_NOSCALAR=-1,
192
+ NPY_BOOL_SCALAR,
193
+ NPY_INTPOS_SCALAR,
194
+ NPY_INTNEG_SCALAR,
195
+ NPY_FLOAT_SCALAR,
196
+ NPY_COMPLEX_SCALAR,
197
+ NPY_OBJECT_SCALAR
198
+ } NPY_SCALARKIND;
199
+ #define NPY_NSCALARKINDS (NPY_OBJECT_SCALAR + 1)
200
+
201
+ /* For specifying array memory layout or iteration order */
202
+ typedef enum {
203
+ /* Fortran order if inputs are all Fortran, C otherwise */
204
+ NPY_ANYORDER=-1,
205
+ /* C order */
206
+ NPY_CORDER=0,
207
+ /* Fortran order */
208
+ NPY_FORTRANORDER=1,
209
+ /* An order as close to the inputs as possible */
210
+ NPY_KEEPORDER=2
211
+ } NPY_ORDER;
212
+
213
+ /* For specifying allowed casting in operations which support it */
214
+ typedef enum {
215
+ _NPY_ERROR_OCCURRED_IN_CAST = -1,
216
+ /* Only allow identical types */
217
+ NPY_NO_CASTING=0,
218
+ /* Allow identical and byte swapped types */
219
+ NPY_EQUIV_CASTING=1,
220
+ /* Only allow safe casts */
221
+ NPY_SAFE_CASTING=2,
222
+ /* Allow safe casts or casts within the same kind */
223
+ NPY_SAME_KIND_CASTING=3,
224
+ /* Allow any casts */
225
+ NPY_UNSAFE_CASTING=4,
226
+ } NPY_CASTING;
227
+
228
+ typedef enum {
229
+ NPY_CLIP=0,
230
+ NPY_WRAP=1,
231
+ NPY_RAISE=2
232
+ } NPY_CLIPMODE;
233
+
234
+ typedef enum {
235
+ NPY_VALID=0,
236
+ NPY_SAME=1,
237
+ NPY_FULL=2
238
+ } NPY_CORRELATEMODE;
239
+
240
+ /* The special not-a-time (NaT) value */
241
+ #define NPY_DATETIME_NAT NPY_MIN_INT64
242
+
243
+ /*
244
+ * Upper bound on the length of a DATETIME ISO 8601 string
245
+ * YEAR: 21 (64-bit year)
246
+ * MONTH: 3
247
+ * DAY: 3
248
+ * HOURS: 3
249
+ * MINUTES: 3
250
+ * SECONDS: 3
251
+ * ATTOSECONDS: 1 + 3*6
252
+ * TIMEZONE: 5
253
+ * NULL TERMINATOR: 1
254
+ */
255
+ #define NPY_DATETIME_MAX_ISO8601_STRLEN (21 + 3*5 + 1 + 3*6 + 6 + 1)
256
+
257
+ /* The FR in the unit names stands for frequency */
258
+ typedef enum {
259
+ /* Force signed enum type, must be -1 for code compatibility */
260
+ NPY_FR_ERROR = -1, /* error or undetermined */
261
+
262
+ /* Start of valid units */
263
+ NPY_FR_Y = 0, /* Years */
264
+ NPY_FR_M = 1, /* Months */
265
+ NPY_FR_W = 2, /* Weeks */
266
+ /* Gap where 1.6 NPY_FR_B (value 3) was */
267
+ NPY_FR_D = 4, /* Days */
268
+ NPY_FR_h = 5, /* hours */
269
+ NPY_FR_m = 6, /* minutes */
270
+ NPY_FR_s = 7, /* seconds */
271
+ NPY_FR_ms = 8, /* milliseconds */
272
+ NPY_FR_us = 9, /* microseconds */
273
+ NPY_FR_ns = 10, /* nanoseconds */
274
+ NPY_FR_ps = 11, /* picoseconds */
275
+ NPY_FR_fs = 12, /* femtoseconds */
276
+ NPY_FR_as = 13, /* attoseconds */
277
+ NPY_FR_GENERIC = 14 /* unbound units, can convert to anything */
278
+ } NPY_DATETIMEUNIT;
279
+
280
+ /*
281
+ * NOTE: With the NPY_FR_B gap for 1.6 ABI compatibility, NPY_DATETIME_NUMUNITS
282
+ * is technically one more than the actual number of units.
283
+ */
284
+ #define NPY_DATETIME_NUMUNITS (NPY_FR_GENERIC + 1)
285
+ #define NPY_DATETIME_DEFAULTUNIT NPY_FR_GENERIC
286
+
287
+ /*
288
+ * Business day conventions for mapping invalid business
289
+ * days to valid business days.
290
+ */
291
+ typedef enum {
292
+ /* Go forward in time to the following business day. */
293
+ NPY_BUSDAY_FORWARD,
294
+ NPY_BUSDAY_FOLLOWING = NPY_BUSDAY_FORWARD,
295
+ /* Go backward in time to the preceding business day. */
296
+ NPY_BUSDAY_BACKWARD,
297
+ NPY_BUSDAY_PRECEDING = NPY_BUSDAY_BACKWARD,
298
+ /*
299
+ * Go forward in time to the following business day, unless it
300
+ * crosses a month boundary, in which case go backward
301
+ */
302
+ NPY_BUSDAY_MODIFIEDFOLLOWING,
303
+ /*
304
+ * Go backward in time to the preceding business day, unless it
305
+ * crosses a month boundary, in which case go forward.
306
+ */
307
+ NPY_BUSDAY_MODIFIEDPRECEDING,
308
+ /* Produce a NaT for non-business days. */
309
+ NPY_BUSDAY_NAT,
310
+ /* Raise an exception for non-business days. */
311
+ NPY_BUSDAY_RAISE
312
+ } NPY_BUSDAY_ROLL;
313
+
314
+
315
+ /************************************************************
316
+ * NumPy Auxiliary Data for inner loops, sort functions, etc.
317
+ ************************************************************/
318
+
319
+ /*
320
+ * When creating an auxiliary data struct, this should always appear
321
+ * as the first member, like this:
322
+ *
323
+ * typedef struct {
324
+ * NpyAuxData base;
325
+ * double constant;
326
+ * } constant_multiplier_aux_data;
327
+ */
328
+ typedef struct NpyAuxData_tag NpyAuxData;
329
+
330
+ /* Function pointers for freeing or cloning auxiliary data */
331
+ typedef void (NpyAuxData_FreeFunc) (NpyAuxData *);
332
+ typedef NpyAuxData *(NpyAuxData_CloneFunc) (NpyAuxData *);
333
+
334
+ struct NpyAuxData_tag {
335
+ NpyAuxData_FreeFunc *free;
336
+ NpyAuxData_CloneFunc *clone;
337
+ /* To allow for a bit of expansion without breaking the ABI */
338
+ void *reserved[2];
339
+ };
340
+
341
+ /* Macros to use for freeing and cloning auxiliary data */
342
+ #define NPY_AUXDATA_FREE(auxdata) \
343
+ do { \
344
+ if ((auxdata) != NULL) { \
345
+ (auxdata)->free(auxdata); \
346
+ } \
347
+ } while(0)
348
+ #define NPY_AUXDATA_CLONE(auxdata) \
349
+ ((auxdata)->clone(auxdata))
350
+
351
+ #define NPY_ERR(str) fprintf(stderr, #str); fflush(stderr);
352
+ #define NPY_ERR2(str) fprintf(stderr, str); fflush(stderr);
353
+
354
+ /*
355
+ * Macros to define how array, and dimension/strides data is
356
+ * allocated. These should be made private
357
+ */
358
+
359
+ #define NPY_USE_PYMEM 1
360
+
361
+
362
+ #if NPY_USE_PYMEM == 1
363
+ /* use the Raw versions which are safe to call with the GIL released */
364
+ #define PyArray_malloc PyMem_RawMalloc
365
+ #define PyArray_free PyMem_RawFree
366
+ #define PyArray_realloc PyMem_RawRealloc
367
+ #else
368
+ #define PyArray_malloc malloc
369
+ #define PyArray_free free
370
+ #define PyArray_realloc realloc
371
+ #endif
372
+
373
+ /* Dimensions and strides */
374
+ #define PyDimMem_NEW(size) \
375
+ ((npy_intp *)PyArray_malloc(size*sizeof(npy_intp)))
376
+
377
+ #define PyDimMem_FREE(ptr) PyArray_free(ptr)
378
+
379
+ #define PyDimMem_RENEW(ptr,size) \
380
+ ((npy_intp *)PyArray_realloc(ptr,size*sizeof(npy_intp)))
381
+
382
+ /* forward declaration */
383
+ struct _PyArray_Descr;
384
+
385
+ /* These must deal with unaligned and swapped data if necessary */
386
+ typedef PyObject * (PyArray_GetItemFunc) (void *, void *);
387
+ typedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);
388
+
389
+ typedef void (PyArray_CopySwapNFunc)(void *, npy_intp, void *, npy_intp,
390
+ npy_intp, int, void *);
391
+
392
+ typedef void (PyArray_CopySwapFunc)(void *, void *, int, void *);
393
+ typedef npy_bool (PyArray_NonzeroFunc)(void *, void *);
394
+
395
+
396
+ /*
397
+ * These assume aligned and notswapped data -- a buffer will be used
398
+ * before or contiguous data will be obtained
399
+ */
400
+
401
+ typedef int (PyArray_CompareFunc)(const void *, const void *, void *);
402
+ typedef int (PyArray_ArgFunc)(void*, npy_intp, npy_intp*, void *);
403
+
404
+ typedef void (PyArray_DotFunc)(void *, npy_intp, void *, npy_intp, void *,
405
+ npy_intp, void *);
406
+
407
+ typedef void (PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *,
408
+ void *);
409
+
410
+ /*
411
+ * XXX the ignore argument should be removed next time the API version
412
+ * is bumped. It used to be the separator.
413
+ */
414
+ typedef int (PyArray_ScanFunc)(FILE *fp, void *dptr,
415
+ char *ignore, struct _PyArray_Descr *);
416
+ typedef int (PyArray_FromStrFunc)(char *s, void *dptr, char **endptr,
417
+ struct _PyArray_Descr *);
418
+
419
+ typedef int (PyArray_FillFunc)(void *, npy_intp, void *);
420
+
421
+ typedef int (PyArray_SortFunc)(void *, npy_intp, void *);
422
+ typedef int (PyArray_ArgSortFunc)(void *, npy_intp *, npy_intp, void *);
423
+
424
+ typedef int (PyArray_FillWithScalarFunc)(void *, npy_intp, void *, void *);
425
+
426
+ typedef int (PyArray_ScalarKindFunc)(void *);
427
+
428
+ typedef struct {
429
+ npy_intp *ptr;
430
+ int len;
431
+ } PyArray_Dims;
432
+
433
+ typedef struct {
434
+ /*
435
+ * Functions to cast to most other standard types
436
+ * Can have some NULL entries. The types
437
+ * DATETIME, TIMEDELTA, and HALF go into the castdict
438
+ * even though they are built-in.
439
+ */
440
+ PyArray_VectorUnaryFunc *cast[NPY_NTYPES_ABI_COMPATIBLE];
441
+
442
+ /* The next four functions *cannot* be NULL */
443
+
444
+ /*
445
+ * Functions to get and set items with standard Python types
446
+ * -- not array scalars
447
+ */
448
+ PyArray_GetItemFunc *getitem;
449
+ PyArray_SetItemFunc *setitem;
450
+
451
+ /*
452
+ * Copy and/or swap data. Memory areas may not overlap
453
+ * Use memmove first if they might
454
+ */
455
+ PyArray_CopySwapNFunc *copyswapn;
456
+ PyArray_CopySwapFunc *copyswap;
457
+
458
+ /*
459
+ * Function to compare items
460
+ * Can be NULL
461
+ */
462
+ PyArray_CompareFunc *compare;
463
+
464
+ /*
465
+ * Function to select largest
466
+ * Can be NULL
467
+ */
468
+ PyArray_ArgFunc *argmax;
469
+
470
+ /*
471
+ * Function to compute dot product
472
+ * Can be NULL
473
+ */
474
+ PyArray_DotFunc *dotfunc;
475
+
476
+ /*
477
+ * Function to scan an ASCII file and
478
+ * place a single value plus possible separator
479
+ * Can be NULL
480
+ */
481
+ PyArray_ScanFunc *scanfunc;
482
+
483
+ /*
484
+ * Function to read a single value from a string
485
+ * and adjust the pointer; Can be NULL
486
+ */
487
+ PyArray_FromStrFunc *fromstr;
488
+
489
+ /*
490
+ * Function to determine if data is zero or not
491
+ * If NULL a default version is
492
+ * used at Registration time.
493
+ */
494
+ PyArray_NonzeroFunc *nonzero;
495
+
496
+ /*
497
+ * Used for arange. Should return 0 on success
498
+ * and -1 on failure.
499
+ * Can be NULL.
500
+ */
501
+ PyArray_FillFunc *fill;
502
+
503
+ /*
504
+ * Function to fill arrays with scalar values
505
+ * Can be NULL
506
+ */
507
+ PyArray_FillWithScalarFunc *fillwithscalar;
508
+
509
+ /*
510
+ * Sorting functions
511
+ * Can be NULL
512
+ */
513
+ PyArray_SortFunc *sort[NPY_NSORTS];
514
+ PyArray_ArgSortFunc *argsort[NPY_NSORTS];
515
+
516
+ /*
517
+ * Dictionary of additional casting functions
518
+ * PyArray_VectorUnaryFuncs
519
+ * which can be populated to support casting
520
+ * to other registered types. Can be NULL
521
+ */
522
+ PyObject *castdict;
523
+
524
+ /*
525
+ * Functions useful for generalizing
526
+ * the casting rules.
527
+ * Can be NULL;
528
+ */
529
+ PyArray_ScalarKindFunc *scalarkind;
530
+ int **cancastscalarkindto;
531
+ int *cancastto;
532
+
533
+ void *_unused1;
534
+ void *_unused2;
535
+ void *_unused3;
536
+
537
+ /*
538
+ * Function to select smallest
539
+ * Can be NULL
540
+ */
541
+ PyArray_ArgFunc *argmin;
542
+
543
+ } PyArray_ArrFuncs;
544
+
545
+
546
+ /* The item must be reference counted when it is inserted or extracted. */
547
+ #define NPY_ITEM_REFCOUNT 0x01
548
+ /* Same as needing REFCOUNT */
549
+ #define NPY_ITEM_HASOBJECT 0x01
550
+ /* Convert to list for pickling */
551
+ #define NPY_LIST_PICKLE 0x02
552
+ /* The item is a POINTER */
553
+ #define NPY_ITEM_IS_POINTER 0x04
554
+ /* memory needs to be initialized for this data-type */
555
+ #define NPY_NEEDS_INIT 0x08
556
+ /* operations need Python C-API so don't give-up thread. */
557
+ #define NPY_NEEDS_PYAPI 0x10
558
+ /* Use f.getitem when extracting elements of this data-type */
559
+ #define NPY_USE_GETITEM 0x20
560
+ /* Use f.setitem when setting creating 0-d array from this data-type.*/
561
+ #define NPY_USE_SETITEM 0x40
562
+ /* A sticky flag specifically for structured arrays */
563
+ #define NPY_ALIGNED_STRUCT 0x80
564
+
565
+ /*
566
+ *These are inherited for global data-type if any data-types in the
567
+ * field have them
568
+ */
569
+ #define NPY_FROM_FIELDS (NPY_NEEDS_INIT | NPY_LIST_PICKLE | \
570
+ NPY_ITEM_REFCOUNT | NPY_NEEDS_PYAPI)
571
+
572
+ #define NPY_OBJECT_DTYPE_FLAGS (NPY_LIST_PICKLE | NPY_USE_GETITEM | \
573
+ NPY_ITEM_IS_POINTER | NPY_ITEM_REFCOUNT | \
574
+ NPY_NEEDS_INIT | NPY_NEEDS_PYAPI)
575
+
576
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
577
+ /*
578
+ * Public version of the Descriptor struct as of 2.x
579
+ */
580
+ typedef struct _PyArray_Descr {
581
+ PyObject_HEAD
582
+ /*
583
+ * the type object representing an
584
+ * instance of this type -- should not
585
+ * be two type_numbers with the same type
586
+ * object.
587
+ */
588
+ PyTypeObject *typeobj;
589
+ /* kind for this type */
590
+ char kind;
591
+ /* unique-character representing this type */
592
+ char type;
593
+ /*
594
+ * '>' (big), '<' (little), '|'
595
+ * (not-applicable), or '=' (native).
596
+ */
597
+ char byteorder;
598
+ /* Former flags flags space (unused) to ensure type_num is stable. */
599
+ char _former_flags;
600
+ /* number representing this type */
601
+ int type_num;
602
+ /* Space for dtype instance specific flags. */
603
+ npy_uint64 flags;
604
+ /* element size (itemsize) for this type */
605
+ npy_intp elsize;
606
+ /* alignment needed for this type */
607
+ npy_intp alignment;
608
+ /* metadata dict or NULL */
609
+ PyObject *metadata;
610
+ /* Cached hash value (-1 if not yet computed). */
611
+ npy_hash_t hash;
612
+ /* Unused slot (must be initialized to NULL) for future use */
613
+ void *reserved_null[2];
614
+ } PyArray_Descr;
615
+
616
+ #else /* 1.x and 2.x compatible version (only shared fields): */
617
+
618
+ typedef struct _PyArray_Descr {
619
+ PyObject_HEAD
620
+ PyTypeObject *typeobj;
621
+ char kind;
622
+ char type;
623
+ char byteorder;
624
+ char _former_flags;
625
+ int type_num;
626
+ } PyArray_Descr;
627
+
628
+ /* To access modified fields, define the full 2.0 struct: */
629
+ typedef struct {
630
+ PyObject_HEAD
631
+ PyTypeObject *typeobj;
632
+ char kind;
633
+ char type;
634
+ char byteorder;
635
+ char _former_flags;
636
+ int type_num;
637
+ npy_uint64 flags;
638
+ npy_intp elsize;
639
+ npy_intp alignment;
640
+ PyObject *metadata;
641
+ npy_hash_t hash;
642
+ void *reserved_null[2];
643
+ } _PyArray_DescrNumPy2;
644
+
645
+ #endif /* 1.x and 2.x compatible version */
646
+
647
+ /*
648
+ * Semi-private struct with additional field of legacy descriptors (must
649
+ * check NPY_DT_is_legacy before casting/accessing). The struct is also not
650
+ * valid when running on 1.x (i.e. in public API use).
651
+ */
652
+ typedef struct {
653
+ PyObject_HEAD
654
+ PyTypeObject *typeobj;
655
+ char kind;
656
+ char type;
657
+ char byteorder;
658
+ char _former_flags;
659
+ int type_num;
660
+ npy_uint64 flags;
661
+ npy_intp elsize;
662
+ npy_intp alignment;
663
+ PyObject *metadata;
664
+ npy_hash_t hash;
665
+ void *reserved_null[2];
666
+ struct _arr_descr *subarray;
667
+ PyObject *fields;
668
+ PyObject *names;
669
+ NpyAuxData *c_metadata;
670
+ } _PyArray_LegacyDescr;
671
+
672
+
673
+ /*
674
+ * Umodified PyArray_Descr struct identical to NumPy 1.x. This struct is
675
+ * used as a prototype for registering a new legacy DType.
676
+ * It is also used to access the fields in user code running on 1.x.
677
+ */
678
+ typedef struct {
679
+ PyObject_HEAD
680
+ PyTypeObject *typeobj;
681
+ char kind;
682
+ char type;
683
+ char byteorder;
684
+ char flags;
685
+ int type_num;
686
+ int elsize;
687
+ int alignment;
688
+ struct _arr_descr *subarray;
689
+ PyObject *fields;
690
+ PyObject *names;
691
+ PyArray_ArrFuncs *f;
692
+ PyObject *metadata;
693
+ NpyAuxData *c_metadata;
694
+ npy_hash_t hash;
695
+ } PyArray_DescrProto;
696
+
697
+
698
+ typedef struct _arr_descr {
699
+ PyArray_Descr *base;
700
+ PyObject *shape; /* a tuple */
701
+ } PyArray_ArrayDescr;
702
+
703
+ /*
704
+ * Memory handler structure for array data.
705
+ */
706
+ /* The declaration of free differs from PyMemAllocatorEx */
707
+ typedef struct {
708
+ void *ctx;
709
+ void* (*malloc) (void *ctx, size_t size);
710
+ void* (*calloc) (void *ctx, size_t nelem, size_t elsize);
711
+ void* (*realloc) (void *ctx, void *ptr, size_t new_size);
712
+ void (*free) (void *ctx, void *ptr, size_t size);
713
+ /*
714
+ * This is the end of the version=1 struct. Only add new fields after
715
+ * this line
716
+ */
717
+ } PyDataMemAllocator;
718
+
719
+ typedef struct {
720
+ char name[127]; /* multiple of 64 to keep the struct aligned */
721
+ uint8_t version; /* currently 1 */
722
+ PyDataMemAllocator allocator;
723
+ } PyDataMem_Handler;
724
+
725
+
726
+ /*
727
+ * The main array object structure.
728
+ *
729
+ * It has been recommended to use the inline functions defined below
730
+ * (PyArray_DATA and friends) to access fields here for a number of
731
+ * releases. Direct access to the members themselves is deprecated.
732
+ * To ensure that your code does not use deprecated access,
733
+ * #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
734
+ * (or NPY_1_8_API_VERSION or higher as required).
735
+ */
736
+ /* This struct will be moved to a private header in a future release */
737
+ typedef struct tagPyArrayObject_fields {
738
+ PyObject_HEAD
739
+ /* Pointer to the raw data buffer */
740
+ char *data;
741
+ /* The number of dimensions, also called 'ndim' */
742
+ int nd;
743
+ /* The size in each dimension, also called 'shape' */
744
+ npy_intp *dimensions;
745
+ /*
746
+ * Number of bytes to jump to get to the
747
+ * next element in each dimension
748
+ */
749
+ npy_intp *strides;
750
+ /*
751
+ * This object is decref'd upon
752
+ * deletion of array. Except in the
753
+ * case of WRITEBACKIFCOPY which has
754
+ * special handling.
755
+ *
756
+ * For views it points to the original
757
+ * array, collapsed so no chains of
758
+ * views occur.
759
+ *
760
+ * For creation from buffer object it
761
+ * points to an object that should be
762
+ * decref'd on deletion
763
+ *
764
+ * For WRITEBACKIFCOPY flag this is an
765
+ * array to-be-updated upon calling
766
+ * PyArray_ResolveWritebackIfCopy
767
+ */
768
+ PyObject *base;
769
+ /* Pointer to type structure */
770
+ PyArray_Descr *descr;
771
+ /* Flags describing array -- see below */
772
+ int flags;
773
+ /* For weak references */
774
+ PyObject *weakreflist;
775
+ #if NPY_FEATURE_VERSION >= NPY_1_20_API_VERSION
776
+ void *_buffer_info; /* private buffer info, tagged to allow warning */
777
+ #endif
778
+ /*
779
+ * For malloc/calloc/realloc/free per object
780
+ */
781
+ #if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
782
+ PyObject *mem_handler;
783
+ #endif
784
+ } PyArrayObject_fields;
785
+
786
+ /*
787
+ * To hide the implementation details, we only expose
788
+ * the Python struct HEAD.
789
+ */
790
+ #if !defined(NPY_NO_DEPRECATED_API) || \
791
+ (NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION)
792
+ /*
793
+ * Can't put this in npy_deprecated_api.h like the others.
794
+ * PyArrayObject field access is deprecated as of NumPy 1.7.
795
+ */
796
+ typedef PyArrayObject_fields PyArrayObject;
797
+ #else
798
+ typedef struct tagPyArrayObject {
799
+ PyObject_HEAD
800
+ } PyArrayObject;
801
+ #endif
802
+
803
+ /*
804
+ * Removed 2020-Nov-25, NumPy 1.20
805
+ * #define NPY_SIZEOF_PYARRAYOBJECT (sizeof(PyArrayObject_fields))
806
+ *
807
+ * The above macro was removed as it gave a false sense of a stable ABI
808
+ * with respect to the structures size. If you require a runtime constant,
809
+ * you can use `PyArray_Type.tp_basicsize` instead. Otherwise, please
810
+ * see the PyArrayObject documentation or ask the NumPy developers for
811
+ * information on how to correctly replace the macro in a way that is
812
+ * compatible with multiple NumPy versions.
813
+ */
814
+
815
+ /* Mirrors buffer object to ptr */
816
+
817
+ typedef struct {
818
+ PyObject_HEAD
819
+ PyObject *base;
820
+ void *ptr;
821
+ npy_intp len;
822
+ int flags;
823
+ } PyArray_Chunk;
824
+
825
+ typedef struct {
826
+ NPY_DATETIMEUNIT base;
827
+ int num;
828
+ } PyArray_DatetimeMetaData;
829
+
830
+ typedef struct {
831
+ NpyAuxData base;
832
+ PyArray_DatetimeMetaData meta;
833
+ } PyArray_DatetimeDTypeMetaData;
834
+
835
+ /*
836
+ * This structure contains an exploded view of a date-time value.
837
+ * NaT is represented by year == NPY_DATETIME_NAT.
838
+ */
839
+ typedef struct {
840
+ npy_int64 year;
841
+ npy_int32 month, day, hour, min, sec, us, ps, as;
842
+ } npy_datetimestruct;
843
+
844
+ /* This is not used internally. */
845
+ typedef struct {
846
+ npy_int64 day;
847
+ npy_int32 sec, us, ps, as;
848
+ } npy_timedeltastruct;
849
+
850
+ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
851
+
852
+ /*
853
+ * Means c-style contiguous (last index varies the fastest). The data
854
+ * elements right after each other.
855
+ *
856
+ * This flag may be requested in constructor functions.
857
+ * This flag may be tested for in PyArray_FLAGS(arr).
858
+ */
859
+ #define NPY_ARRAY_C_CONTIGUOUS 0x0001
860
+
861
+ /*
862
+ * Set if array is a contiguous Fortran array: the first index varies
863
+ * the fastest in memory (strides array is reverse of C-contiguous
864
+ * array)
865
+ *
866
+ * This flag may be requested in constructor functions.
867
+ * This flag may be tested for in PyArray_FLAGS(arr).
868
+ */
869
+ #define NPY_ARRAY_F_CONTIGUOUS 0x0002
870
+
871
+ /*
872
+ * Note: all 0-d arrays are C_CONTIGUOUS and F_CONTIGUOUS. If a
873
+ * 1-d array is C_CONTIGUOUS it is also F_CONTIGUOUS. Arrays with
874
+ * more then one dimension can be C_CONTIGUOUS and F_CONTIGUOUS
875
+ * at the same time if they have either zero or one element.
876
+ * A higher dimensional array always has the same contiguity flags as
877
+ * `array.squeeze()`; dimensions with `array.shape[dimension] == 1` are
878
+ * effectively ignored when checking for contiguity.
879
+ */
880
+
881
+ /*
882
+ * If set, the array owns the data: it will be free'd when the array
883
+ * is deleted.
884
+ *
885
+ * This flag may be tested for in PyArray_FLAGS(arr).
886
+ */
887
+ #define NPY_ARRAY_OWNDATA 0x0004
888
+
889
+ /*
890
+ * An array never has the next four set; they're only used as parameter
891
+ * flags to the various FromAny functions
892
+ *
893
+ * This flag may be requested in constructor functions.
894
+ */
895
+
896
+ /* Cause a cast to occur regardless of whether or not it is safe. */
897
+ #define NPY_ARRAY_FORCECAST 0x0010
898
+
899
+ /*
900
+ * Always copy the array. Returned arrays are always CONTIGUOUS,
901
+ * ALIGNED, and WRITEABLE. See also: NPY_ARRAY_ENSURENOCOPY = 0x4000.
902
+ *
903
+ * This flag may be requested in constructor functions.
904
+ */
905
+ #define NPY_ARRAY_ENSURECOPY 0x0020
906
+
907
+ /*
908
+ * Make sure the returned array is a base-class ndarray
909
+ *
910
+ * This flag may be requested in constructor functions.
911
+ */
912
+ #define NPY_ARRAY_ENSUREARRAY 0x0040
913
+
914
+ /*
915
+ * Make sure that the strides are in units of the element size Needed
916
+ * for some operations with record-arrays.
917
+ *
918
+ * This flag may be requested in constructor functions.
919
+ */
920
+ #define NPY_ARRAY_ELEMENTSTRIDES 0x0080
921
+
922
+ /*
923
+ * Array data is aligned on the appropriate memory address for the type
924
+ * stored according to how the compiler would align things (e.g., an
925
+ * array of integers (4 bytes each) starts on a memory address that's
926
+ * a multiple of 4)
927
+ *
928
+ * This flag may be requested in constructor functions.
929
+ * This flag may be tested for in PyArray_FLAGS(arr).
930
+ */
931
+ #define NPY_ARRAY_ALIGNED 0x0100
932
+
933
+ /*
934
+ * Array data has the native endianness
935
+ *
936
+ * This flag may be requested in constructor functions.
937
+ */
938
+ #define NPY_ARRAY_NOTSWAPPED 0x0200
939
+
940
+ /*
941
+ * Array data is writeable
942
+ *
943
+ * This flag may be requested in constructor functions.
944
+ * This flag may be tested for in PyArray_FLAGS(arr).
945
+ */
946
+ #define NPY_ARRAY_WRITEABLE 0x0400
947
+
948
+ /*
949
+ * If this flag is set, then base contains a pointer to an array of
950
+ * the same size that should be updated with the current contents of
951
+ * this array when PyArray_ResolveWritebackIfCopy is called.
952
+ *
953
+ * This flag may be requested in constructor functions.
954
+ * This flag may be tested for in PyArray_FLAGS(arr).
955
+ */
956
+ #define NPY_ARRAY_WRITEBACKIFCOPY 0x2000
957
+
958
+ /*
959
+ * No copy may be made while converting from an object/array (result is a view)
960
+ *
961
+ * This flag may be requested in constructor functions.
962
+ */
963
+ #define NPY_ARRAY_ENSURENOCOPY 0x4000
964
+
965
+ /*
966
+ * NOTE: there are also internal flags defined in multiarray/arrayobject.h,
967
+ * which start at bit 31 and work down.
968
+ */
969
+
970
+ #define NPY_ARRAY_BEHAVED (NPY_ARRAY_ALIGNED | \
971
+ NPY_ARRAY_WRITEABLE)
972
+ #define NPY_ARRAY_BEHAVED_NS (NPY_ARRAY_ALIGNED | \
973
+ NPY_ARRAY_WRITEABLE | \
974
+ NPY_ARRAY_NOTSWAPPED)
975
+ #define NPY_ARRAY_CARRAY (NPY_ARRAY_C_CONTIGUOUS | \
976
+ NPY_ARRAY_BEHAVED)
977
+ #define NPY_ARRAY_CARRAY_RO (NPY_ARRAY_C_CONTIGUOUS | \
978
+ NPY_ARRAY_ALIGNED)
979
+ #define NPY_ARRAY_FARRAY (NPY_ARRAY_F_CONTIGUOUS | \
980
+ NPY_ARRAY_BEHAVED)
981
+ #define NPY_ARRAY_FARRAY_RO (NPY_ARRAY_F_CONTIGUOUS | \
982
+ NPY_ARRAY_ALIGNED)
983
+ #define NPY_ARRAY_DEFAULT (NPY_ARRAY_CARRAY)
984
+ #define NPY_ARRAY_IN_ARRAY (NPY_ARRAY_CARRAY_RO)
985
+ #define NPY_ARRAY_OUT_ARRAY (NPY_ARRAY_CARRAY)
986
+ #define NPY_ARRAY_INOUT_ARRAY (NPY_ARRAY_CARRAY)
987
+ #define NPY_ARRAY_INOUT_ARRAY2 (NPY_ARRAY_CARRAY | \
988
+ NPY_ARRAY_WRITEBACKIFCOPY)
989
+ #define NPY_ARRAY_IN_FARRAY (NPY_ARRAY_FARRAY_RO)
990
+ #define NPY_ARRAY_OUT_FARRAY (NPY_ARRAY_FARRAY)
991
+ #define NPY_ARRAY_INOUT_FARRAY (NPY_ARRAY_FARRAY)
992
+ #define NPY_ARRAY_INOUT_FARRAY2 (NPY_ARRAY_FARRAY | \
993
+ NPY_ARRAY_WRITEBACKIFCOPY)
994
+
995
+ #define NPY_ARRAY_UPDATE_ALL (NPY_ARRAY_C_CONTIGUOUS | \
996
+ NPY_ARRAY_F_CONTIGUOUS | \
997
+ NPY_ARRAY_ALIGNED)
998
+
999
+ /* This flag is for the array interface, not PyArrayObject */
1000
+ #define NPY_ARR_HAS_DESCR 0x0800
1001
+
1002
+
1003
+
1004
+
1005
+ /*
1006
+ * Size of internal buffers used for alignment Make BUFSIZE a multiple
1007
+ * of sizeof(npy_cdouble) -- usually 16 so that ufunc buffers are aligned
1008
+ */
1009
+ #define NPY_MIN_BUFSIZE ((int)sizeof(npy_cdouble))
1010
+ #define NPY_MAX_BUFSIZE (((int)sizeof(npy_cdouble))*1000000)
1011
+ #define NPY_BUFSIZE 8192
1012
+ /* buffer stress test size: */
1013
+ /*#define NPY_BUFSIZE 17*/
1014
+
1015
+ /*
1016
+ * C API: consists of Macros and functions. The MACROS are defined
1017
+ * here.
1018
+ */
1019
+
1020
+
1021
+ #define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS((m), NPY_ARRAY_C_CONTIGUOUS)
1022
+ #define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS((m), NPY_ARRAY_WRITEABLE)
1023
+ #define PyArray_ISALIGNED(m) PyArray_CHKFLAGS((m), NPY_ARRAY_ALIGNED)
1024
+
1025
+ #define PyArray_IS_C_CONTIGUOUS(m) PyArray_CHKFLAGS((m), NPY_ARRAY_C_CONTIGUOUS)
1026
+ #define PyArray_IS_F_CONTIGUOUS(m) PyArray_CHKFLAGS((m), NPY_ARRAY_F_CONTIGUOUS)
1027
+
1028
+ /* the variable is used in some places, so always define it */
1029
+ #define NPY_BEGIN_THREADS_DEF PyThreadState *_save=NULL;
1030
+ #if NPY_ALLOW_THREADS
1031
+ #define NPY_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
1032
+ #define NPY_END_ALLOW_THREADS Py_END_ALLOW_THREADS
1033
+ #define NPY_BEGIN_THREADS do {_save = PyEval_SaveThread();} while (0);
1034
+ #define NPY_END_THREADS do { if (_save) \
1035
+ { PyEval_RestoreThread(_save); _save = NULL;} } while (0);
1036
+ #define NPY_BEGIN_THREADS_THRESHOLDED(loop_size) do { if ((loop_size) > 500) \
1037
+ { _save = PyEval_SaveThread();} } while (0);
1038
+
1039
+
1040
+ #define NPY_ALLOW_C_API_DEF PyGILState_STATE __save__;
1041
+ #define NPY_ALLOW_C_API do {__save__ = PyGILState_Ensure();} while (0);
1042
+ #define NPY_DISABLE_C_API do {PyGILState_Release(__save__);} while (0);
1043
+ #else
1044
+ #define NPY_BEGIN_ALLOW_THREADS
1045
+ #define NPY_END_ALLOW_THREADS
1046
+ #define NPY_BEGIN_THREADS
1047
+ #define NPY_END_THREADS
1048
+ #define NPY_BEGIN_THREADS_THRESHOLDED(loop_size)
1049
+ #define NPY_BEGIN_THREADS_DESCR(dtype)
1050
+ #define NPY_END_THREADS_DESCR(dtype)
1051
+ #define NPY_ALLOW_C_API_DEF
1052
+ #define NPY_ALLOW_C_API
1053
+ #define NPY_DISABLE_C_API
1054
+ #endif
1055
+
1056
+ /**********************************
1057
+ * The nditer object, added in 1.6
1058
+ **********************************/
1059
+
1060
+ /* The actual structure of the iterator is an internal detail */
1061
+ typedef struct NpyIter_InternalOnly NpyIter;
1062
+
1063
+ /* Iterator function pointers that may be specialized */
1064
+ typedef int (NpyIter_IterNextFunc)(NpyIter *iter);
1065
+ typedef void (NpyIter_GetMultiIndexFunc)(NpyIter *iter,
1066
+ npy_intp *outcoords);
1067
+
1068
+ /*** Global flags that may be passed to the iterator constructors ***/
1069
+
1070
+ /* Track an index representing C order */
1071
+ #define NPY_ITER_C_INDEX 0x00000001
1072
+ /* Track an index representing Fortran order */
1073
+ #define NPY_ITER_F_INDEX 0x00000002
1074
+ /* Track a multi-index */
1075
+ #define NPY_ITER_MULTI_INDEX 0x00000004
1076
+ /* User code external to the iterator does the 1-dimensional innermost loop */
1077
+ #define NPY_ITER_EXTERNAL_LOOP 0x00000008
1078
+ /* Convert all the operands to a common data type */
1079
+ #define NPY_ITER_COMMON_DTYPE 0x00000010
1080
+ /* Operands may hold references, requiring API access during iteration */
1081
+ #define NPY_ITER_REFS_OK 0x00000020
1082
+ /* Zero-sized operands should be permitted, iteration checks IterSize for 0 */
1083
+ #define NPY_ITER_ZEROSIZE_OK 0x00000040
1084
+ /* Permits reductions (size-0 stride with dimension size > 1) */
1085
+ #define NPY_ITER_REDUCE_OK 0x00000080
1086
+ /* Enables sub-range iteration */
1087
+ #define NPY_ITER_RANGED 0x00000100
1088
+ /* Enables buffering */
1089
+ #define NPY_ITER_BUFFERED 0x00000200
1090
+ /* When buffering is enabled, grows the inner loop if possible */
1091
+ #define NPY_ITER_GROWINNER 0x00000400
1092
+ /* Delay allocation of buffers until first Reset* call */
1093
+ #define NPY_ITER_DELAY_BUFALLOC 0x00000800
1094
+ /* When NPY_KEEPORDER is specified, disable reversing negative-stride axes */
1095
+ #define NPY_ITER_DONT_NEGATE_STRIDES 0x00001000
1096
+ /*
1097
+ * If output operands overlap with other operands (based on heuristics that
1098
+ * has false positives but no false negatives), make temporary copies to
1099
+ * eliminate overlap.
1100
+ */
1101
+ #define NPY_ITER_COPY_IF_OVERLAP 0x00002000
1102
+
1103
+ /*** Per-operand flags that may be passed to the iterator constructors ***/
1104
+
1105
+ /* The operand will be read from and written to */
1106
+ #define NPY_ITER_READWRITE 0x00010000
1107
+ /* The operand will only be read from */
1108
+ #define NPY_ITER_READONLY 0x00020000
1109
+ /* The operand will only be written to */
1110
+ #define NPY_ITER_WRITEONLY 0x00040000
1111
+ /* The operand's data must be in native byte order */
1112
+ #define NPY_ITER_NBO 0x00080000
1113
+ /* The operand's data must be aligned */
1114
+ #define NPY_ITER_ALIGNED 0x00100000
1115
+ /* The operand's data must be contiguous (within the inner loop) */
1116
+ #define NPY_ITER_CONTIG 0x00200000
1117
+ /* The operand may be copied to satisfy requirements */
1118
+ #define NPY_ITER_COPY 0x00400000
1119
+ /* The operand may be copied with WRITEBACKIFCOPY to satisfy requirements */
1120
+ #define NPY_ITER_UPDATEIFCOPY 0x00800000
1121
+ /* Allocate the operand if it is NULL */
1122
+ #define NPY_ITER_ALLOCATE 0x01000000
1123
+ /* If an operand is allocated, don't use any subtype */
1124
+ #define NPY_ITER_NO_SUBTYPE 0x02000000
1125
+ /* This is a virtual array slot, operand is NULL but temporary data is there */
1126
+ #define NPY_ITER_VIRTUAL 0x04000000
1127
+ /* Require that the dimension match the iterator dimensions exactly */
1128
+ #define NPY_ITER_NO_BROADCAST 0x08000000
1129
+ /* A mask is being used on this array, affects buffer -> array copy */
1130
+ #define NPY_ITER_WRITEMASKED 0x10000000
1131
+ /* This array is the mask for all WRITEMASKED operands */
1132
+ #define NPY_ITER_ARRAYMASK 0x20000000
1133
+ /* Assume iterator order data access for COPY_IF_OVERLAP */
1134
+ #define NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE 0x40000000
1135
+
1136
+ #define NPY_ITER_GLOBAL_FLAGS 0x0000ffff
1137
+ #define NPY_ITER_PER_OP_FLAGS 0xffff0000
1138
+
1139
+
1140
+ /*****************************
1141
+ * Basic iterator object
1142
+ *****************************/
1143
+
1144
+ /* FWD declaration */
1145
+ typedef struct PyArrayIterObject_tag PyArrayIterObject;
1146
+
1147
+ /*
1148
+ * type of the function which translates a set of coordinates to a
1149
+ * pointer to the data
1150
+ */
1151
+ typedef char* (*npy_iter_get_dataptr_t)(
1152
+ PyArrayIterObject* iter, const npy_intp*);
1153
+
1154
+ struct PyArrayIterObject_tag {
1155
+ PyObject_HEAD
1156
+ int nd_m1; /* number of dimensions - 1 */
1157
+ npy_intp index, size;
1158
+ npy_intp coordinates[NPY_MAXDIMS_LEGACY_ITERS];/* N-dimensional loop */
1159
+ npy_intp dims_m1[NPY_MAXDIMS_LEGACY_ITERS]; /* ao->dimensions - 1 */
1160
+ npy_intp strides[NPY_MAXDIMS_LEGACY_ITERS]; /* ao->strides or fake */
1161
+ npy_intp backstrides[NPY_MAXDIMS_LEGACY_ITERS];/* how far to jump back */
1162
+ npy_intp factors[NPY_MAXDIMS_LEGACY_ITERS]; /* shape factors */
1163
+ PyArrayObject *ao;
1164
+ char *dataptr; /* pointer to current item*/
1165
+ npy_bool contiguous;
1166
+
1167
+ npy_intp bounds[NPY_MAXDIMS_LEGACY_ITERS][2];
1168
+ npy_intp limits[NPY_MAXDIMS_LEGACY_ITERS][2];
1169
+ npy_intp limits_sizes[NPY_MAXDIMS_LEGACY_ITERS];
1170
+ npy_iter_get_dataptr_t translate;
1171
+ } ;
1172
+
1173
+
1174
+ /* Iterator API */
1175
+ #define PyArrayIter_Check(op) PyObject_TypeCheck((op), &PyArrayIter_Type)
1176
+
1177
+ #define _PyAIT(it) ((PyArrayIterObject *)(it))
1178
+ #define PyArray_ITER_RESET(it) do { \
1179
+ _PyAIT(it)->index = 0; \
1180
+ _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
1181
+ memset(_PyAIT(it)->coordinates, 0, \
1182
+ (_PyAIT(it)->nd_m1+1)*sizeof(npy_intp)); \
1183
+ } while (0)
1184
+
1185
+ #define _PyArray_ITER_NEXT1(it) do { \
1186
+ (it)->dataptr += _PyAIT(it)->strides[0]; \
1187
+ (it)->coordinates[0]++; \
1188
+ } while (0)
1189
+
1190
+ #define _PyArray_ITER_NEXT2(it) do { \
1191
+ if ((it)->coordinates[1] < (it)->dims_m1[1]) { \
1192
+ (it)->coordinates[1]++; \
1193
+ (it)->dataptr += (it)->strides[1]; \
1194
+ } \
1195
+ else { \
1196
+ (it)->coordinates[1] = 0; \
1197
+ (it)->coordinates[0]++; \
1198
+ (it)->dataptr += (it)->strides[0] - \
1199
+ (it)->backstrides[1]; \
1200
+ } \
1201
+ } while (0)
1202
+
1203
+ #define PyArray_ITER_NEXT(it) do { \
1204
+ _PyAIT(it)->index++; \
1205
+ if (_PyAIT(it)->nd_m1 == 0) { \
1206
+ _PyArray_ITER_NEXT1(_PyAIT(it)); \
1207
+ } \
1208
+ else if (_PyAIT(it)->contiguous) \
1209
+ _PyAIT(it)->dataptr += PyArray_ITEMSIZE(_PyAIT(it)->ao); \
1210
+ else if (_PyAIT(it)->nd_m1 == 1) { \
1211
+ _PyArray_ITER_NEXT2(_PyAIT(it)); \
1212
+ } \
1213
+ else { \
1214
+ int __npy_i; \
1215
+ for (__npy_i=_PyAIT(it)->nd_m1; __npy_i >= 0; __npy_i--) { \
1216
+ if (_PyAIT(it)->coordinates[__npy_i] < \
1217
+ _PyAIT(it)->dims_m1[__npy_i]) { \
1218
+ _PyAIT(it)->coordinates[__npy_i]++; \
1219
+ _PyAIT(it)->dataptr += \
1220
+ _PyAIT(it)->strides[__npy_i]; \
1221
+ break; \
1222
+ } \
1223
+ else { \
1224
+ _PyAIT(it)->coordinates[__npy_i] = 0; \
1225
+ _PyAIT(it)->dataptr -= \
1226
+ _PyAIT(it)->backstrides[__npy_i]; \
1227
+ } \
1228
+ } \
1229
+ } \
1230
+ } while (0)
1231
+
1232
+ #define PyArray_ITER_GOTO(it, destination) do { \
1233
+ int __npy_i; \
1234
+ _PyAIT(it)->index = 0; \
1235
+ _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
1236
+ for (__npy_i = _PyAIT(it)->nd_m1; __npy_i>=0; __npy_i--) { \
1237
+ if (destination[__npy_i] < 0) { \
1238
+ destination[__npy_i] += \
1239
+ _PyAIT(it)->dims_m1[__npy_i]+1; \
1240
+ } \
1241
+ _PyAIT(it)->dataptr += destination[__npy_i] * \
1242
+ _PyAIT(it)->strides[__npy_i]; \
1243
+ _PyAIT(it)->coordinates[__npy_i] = \
1244
+ destination[__npy_i]; \
1245
+ _PyAIT(it)->index += destination[__npy_i] * \
1246
+ ( __npy_i==_PyAIT(it)->nd_m1 ? 1 : \
1247
+ _PyAIT(it)->dims_m1[__npy_i+1]+1) ; \
1248
+ } \
1249
+ } while (0)
1250
+
1251
+ #define PyArray_ITER_GOTO1D(it, ind) do { \
1252
+ int __npy_i; \
1253
+ npy_intp __npy_ind = (npy_intp)(ind); \
1254
+ if (__npy_ind < 0) __npy_ind += _PyAIT(it)->size; \
1255
+ _PyAIT(it)->index = __npy_ind; \
1256
+ if (_PyAIT(it)->nd_m1 == 0) { \
1257
+ _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao) + \
1258
+ __npy_ind * _PyAIT(it)->strides[0]; \
1259
+ } \
1260
+ else if (_PyAIT(it)->contiguous) \
1261
+ _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao) + \
1262
+ __npy_ind * PyArray_ITEMSIZE(_PyAIT(it)->ao); \
1263
+ else { \
1264
+ _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
1265
+ for (__npy_i = 0; __npy_i<=_PyAIT(it)->nd_m1; \
1266
+ __npy_i++) { \
1267
+ _PyAIT(it)->coordinates[__npy_i] = \
1268
+ (__npy_ind / _PyAIT(it)->factors[__npy_i]); \
1269
+ _PyAIT(it)->dataptr += \
1270
+ (__npy_ind / _PyAIT(it)->factors[__npy_i]) \
1271
+ * _PyAIT(it)->strides[__npy_i]; \
1272
+ __npy_ind %= _PyAIT(it)->factors[__npy_i]; \
1273
+ } \
1274
+ } \
1275
+ } while (0)
1276
+
1277
+ #define PyArray_ITER_DATA(it) ((void *)(_PyAIT(it)->dataptr))
1278
+
1279
+ #define PyArray_ITER_NOTDONE(it) (_PyAIT(it)->index < _PyAIT(it)->size)
1280
+
1281
+
1282
+ /*
1283
+ * Any object passed to PyArray_Broadcast must be binary compatible
1284
+ * with this structure.
1285
+ */
1286
+
1287
+ typedef struct {
1288
+ PyObject_HEAD
1289
+ int numiter; /* number of iters */
1290
+ npy_intp size; /* broadcasted size */
1291
+ npy_intp index; /* current index */
1292
+ int nd; /* number of dims */
1293
+ npy_intp dimensions[NPY_MAXDIMS_LEGACY_ITERS]; /* dimensions */
1294
+ /*
1295
+ * Space for the individual iterators, do not specify size publicly
1296
+ * to allow changing it more easily.
1297
+ * One reason is that Cython uses this for checks and only allows
1298
+ * growing structs (as of Cython 3.0.6). It also allows NPY_MAXARGS
1299
+ * to be runtime dependent.
1300
+ */
1301
+ #if (defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD)
1302
+ PyArrayIterObject *iters[64];
1303
+ #elif defined(__cplusplus)
1304
+ /*
1305
+ * C++ doesn't strictly support flexible members and gives compilers
1306
+ * warnings (pedantic only), so we lie. We can't make it 64 because
1307
+ * then Cython is unhappy (larger struct at runtime is OK smaller not).
1308
+ */
1309
+ PyArrayIterObject *iters[32];
1310
+ #else
1311
+ PyArrayIterObject *iters[];
1312
+ #endif
1313
+ } PyArrayMultiIterObject;
1314
+
1315
+ #define _PyMIT(m) ((PyArrayMultiIterObject *)(m))
1316
+ #define PyArray_MultiIter_RESET(multi) do { \
1317
+ int __npy_mi; \
1318
+ _PyMIT(multi)->index = 0; \
1319
+ for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \
1320
+ PyArray_ITER_RESET(_PyMIT(multi)->iters[__npy_mi]); \
1321
+ } \
1322
+ } while (0)
1323
+
1324
+ #define PyArray_MultiIter_NEXT(multi) do { \
1325
+ int __npy_mi; \
1326
+ _PyMIT(multi)->index++; \
1327
+ for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \
1328
+ PyArray_ITER_NEXT(_PyMIT(multi)->iters[__npy_mi]); \
1329
+ } \
1330
+ } while (0)
1331
+
1332
+ #define PyArray_MultiIter_GOTO(multi, dest) do { \
1333
+ int __npy_mi; \
1334
+ for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \
1335
+ PyArray_ITER_GOTO(_PyMIT(multi)->iters[__npy_mi], dest); \
1336
+ } \
1337
+ _PyMIT(multi)->index = _PyMIT(multi)->iters[0]->index; \
1338
+ } while (0)
1339
+
1340
+ #define PyArray_MultiIter_GOTO1D(multi, ind) do { \
1341
+ int __npy_mi; \
1342
+ for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \
1343
+ PyArray_ITER_GOTO1D(_PyMIT(multi)->iters[__npy_mi], ind); \
1344
+ } \
1345
+ _PyMIT(multi)->index = _PyMIT(multi)->iters[0]->index; \
1346
+ } while (0)
1347
+
1348
+ #define PyArray_MultiIter_DATA(multi, i) \
1349
+ ((void *)(_PyMIT(multi)->iters[i]->dataptr))
1350
+
1351
+ #define PyArray_MultiIter_NEXTi(multi, i) \
1352
+ PyArray_ITER_NEXT(_PyMIT(multi)->iters[i])
1353
+
1354
+ #define PyArray_MultiIter_NOTDONE(multi) \
1355
+ (_PyMIT(multi)->index < _PyMIT(multi)->size)
1356
+
1357
+
1358
+ static NPY_INLINE int
1359
+ PyArray_MultiIter_NUMITER(PyArrayMultiIterObject *multi)
1360
+ {
1361
+ return multi->numiter;
1362
+ }
1363
+
1364
+
1365
+ static NPY_INLINE npy_intp
1366
+ PyArray_MultiIter_SIZE(PyArrayMultiIterObject *multi)
1367
+ {
1368
+ return multi->size;
1369
+ }
1370
+
1371
+
1372
+ static NPY_INLINE npy_intp
1373
+ PyArray_MultiIter_INDEX(PyArrayMultiIterObject *multi)
1374
+ {
1375
+ return multi->index;
1376
+ }
1377
+
1378
+
1379
+ static NPY_INLINE int
1380
+ PyArray_MultiIter_NDIM(PyArrayMultiIterObject *multi)
1381
+ {
1382
+ return multi->nd;
1383
+ }
1384
+
1385
+
1386
+ static NPY_INLINE npy_intp *
1387
+ PyArray_MultiIter_DIMS(PyArrayMultiIterObject *multi)
1388
+ {
1389
+ return multi->dimensions;
1390
+ }
1391
+
1392
+
1393
+ static NPY_INLINE void **
1394
+ PyArray_MultiIter_ITERS(PyArrayMultiIterObject *multi)
1395
+ {
1396
+ return (void**)multi->iters;
1397
+ }
1398
+
1399
+
1400
+ enum {
1401
+ NPY_NEIGHBORHOOD_ITER_ZERO_PADDING,
1402
+ NPY_NEIGHBORHOOD_ITER_ONE_PADDING,
1403
+ NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING,
1404
+ NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING,
1405
+ NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING
1406
+ };
1407
+
1408
+ typedef struct {
1409
+ PyObject_HEAD
1410
+
1411
+ /*
1412
+ * PyArrayIterObject part: keep this in this exact order
1413
+ */
1414
+ int nd_m1; /* number of dimensions - 1 */
1415
+ npy_intp index, size;
1416
+ npy_intp coordinates[NPY_MAXDIMS_LEGACY_ITERS];/* N-dimensional loop */
1417
+ npy_intp dims_m1[NPY_MAXDIMS_LEGACY_ITERS]; /* ao->dimensions - 1 */
1418
+ npy_intp strides[NPY_MAXDIMS_LEGACY_ITERS]; /* ao->strides or fake */
1419
+ npy_intp backstrides[NPY_MAXDIMS_LEGACY_ITERS];/* how far to jump back */
1420
+ npy_intp factors[NPY_MAXDIMS_LEGACY_ITERS]; /* shape factors */
1421
+ PyArrayObject *ao;
1422
+ char *dataptr; /* pointer to current item*/
1423
+ npy_bool contiguous;
1424
+
1425
+ npy_intp bounds[NPY_MAXDIMS_LEGACY_ITERS][2];
1426
+ npy_intp limits[NPY_MAXDIMS_LEGACY_ITERS][2];
1427
+ npy_intp limits_sizes[NPY_MAXDIMS_LEGACY_ITERS];
1428
+ npy_iter_get_dataptr_t translate;
1429
+
1430
+ /*
1431
+ * New members
1432
+ */
1433
+ npy_intp nd;
1434
+
1435
+ /* Dimensions is the dimension of the array */
1436
+ npy_intp dimensions[NPY_MAXDIMS_LEGACY_ITERS];
1437
+
1438
+ /*
1439
+ * Neighborhood points coordinates are computed relatively to the
1440
+ * point pointed by _internal_iter
1441
+ */
1442
+ PyArrayIterObject* _internal_iter;
1443
+ /*
1444
+ * To keep a reference to the representation of the constant value
1445
+ * for constant padding
1446
+ */
1447
+ char* constant;
1448
+
1449
+ int mode;
1450
+ } PyArrayNeighborhoodIterObject;
1451
+
1452
+ /*
1453
+ * Neighborhood iterator API
1454
+ */
1455
+
1456
+ /* General: those work for any mode */
1457
+ static inline int
1458
+ PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter);
1459
+ static inline int
1460
+ PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter);
1461
+ #if 0
1462
+ static inline int
1463
+ PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter);
1464
+ #endif
1465
+
1466
+ /*
1467
+ * Include inline implementations - functions defined there are not
1468
+ * considered public API
1469
+ */
1470
+ #define NUMPY_CORE_INCLUDE_NUMPY__NEIGHBORHOOD_IMP_H_
1471
+ #include "_neighborhood_iterator_imp.h"
1472
+ #undef NUMPY_CORE_INCLUDE_NUMPY__NEIGHBORHOOD_IMP_H_
1473
+
1474
+
1475
+
1476
+ /* The default array type */
1477
+ #define NPY_DEFAULT_TYPE NPY_DOUBLE
1478
+ /* default integer type defined in npy_2_compat header */
1479
+
1480
+ /*
1481
+ * All sorts of useful ways to look into a PyArrayObject. It is recommended
1482
+ * to use PyArrayObject * objects instead of always casting from PyObject *,
1483
+ * for improved type checking.
1484
+ *
1485
+ * In many cases here the macro versions of the accessors are deprecated,
1486
+ * but can't be immediately changed to inline functions because the
1487
+ * preexisting macros accept PyObject * and do automatic casts. Inline
1488
+ * functions accepting PyArrayObject * provides for some compile-time
1489
+ * checking of correctness when working with these objects in C.
1490
+ */
1491
+
1492
+ #define PyArray_ISONESEGMENT(m) (PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS) || \
1493
+ PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS))
1494
+
1495
+ #define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) && \
1496
+ (!PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS)))
1497
+
1498
+ #define PyArray_FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) ? \
1499
+ NPY_ARRAY_F_CONTIGUOUS : 0))
1500
+
1501
+ static inline int
1502
+ PyArray_NDIM(const PyArrayObject *arr)
1503
+ {
1504
+ return ((PyArrayObject_fields *)arr)->nd;
1505
+ }
1506
+
1507
+ static inline void *
1508
+ PyArray_DATA(const PyArrayObject *arr)
1509
+ {
1510
+ return ((PyArrayObject_fields *)arr)->data;
1511
+ }
1512
+
1513
+ static inline char *
1514
+ PyArray_BYTES(const PyArrayObject *arr)
1515
+ {
1516
+ return ((PyArrayObject_fields *)arr)->data;
1517
+ }
1518
+
1519
+ static inline npy_intp *
1520
+ PyArray_DIMS(const PyArrayObject *arr)
1521
+ {
1522
+ return ((PyArrayObject_fields *)arr)->dimensions;
1523
+ }
1524
+
1525
+ static inline npy_intp *
1526
+ PyArray_STRIDES(const PyArrayObject *arr)
1527
+ {
1528
+ return ((PyArrayObject_fields *)arr)->strides;
1529
+ }
1530
+
1531
+ static inline npy_intp
1532
+ PyArray_DIM(const PyArrayObject *arr, int idim)
1533
+ {
1534
+ return ((PyArrayObject_fields *)arr)->dimensions[idim];
1535
+ }
1536
+
1537
+ static inline npy_intp
1538
+ PyArray_STRIDE(const PyArrayObject *arr, int istride)
1539
+ {
1540
+ return ((PyArrayObject_fields *)arr)->strides[istride];
1541
+ }
1542
+
1543
+ static inline NPY_RETURNS_BORROWED_REF PyObject *
1544
+ PyArray_BASE(const PyArrayObject *arr)
1545
+ {
1546
+ return ((PyArrayObject_fields *)arr)->base;
1547
+ }
1548
+
1549
+ static inline NPY_RETURNS_BORROWED_REF PyArray_Descr *
1550
+ PyArray_DESCR(const PyArrayObject *arr)
1551
+ {
1552
+ return ((PyArrayObject_fields *)arr)->descr;
1553
+ }
1554
+
1555
+ static inline int
1556
+ PyArray_FLAGS(const PyArrayObject *arr)
1557
+ {
1558
+ return ((PyArrayObject_fields *)arr)->flags;
1559
+ }
1560
+
1561
+
1562
+ static inline int
1563
+ PyArray_TYPE(const PyArrayObject *arr)
1564
+ {
1565
+ return ((PyArrayObject_fields *)arr)->descr->type_num;
1566
+ }
1567
+
1568
+ static inline int
1569
+ PyArray_CHKFLAGS(const PyArrayObject *arr, int flags)
1570
+ {
1571
+ return (PyArray_FLAGS(arr) & flags) == flags;
1572
+ }
1573
+
1574
+ static inline PyArray_Descr *
1575
+ PyArray_DTYPE(const PyArrayObject *arr)
1576
+ {
1577
+ return ((PyArrayObject_fields *)arr)->descr;
1578
+ }
1579
+
1580
+ static inline npy_intp *
1581
+ PyArray_SHAPE(const PyArrayObject *arr)
1582
+ {
1583
+ return ((PyArrayObject_fields *)arr)->dimensions;
1584
+ }
1585
+
1586
+ /*
1587
+ * Enables the specified array flags. Does no checking,
1588
+ * assumes you know what you're doing.
1589
+ */
1590
+ static inline void
1591
+ PyArray_ENABLEFLAGS(PyArrayObject *arr, int flags)
1592
+ {
1593
+ ((PyArrayObject_fields *)arr)->flags |= flags;
1594
+ }
1595
+
1596
+ /*
1597
+ * Clears the specified array flags. Does no checking,
1598
+ * assumes you know what you're doing.
1599
+ */
1600
+ static inline void
1601
+ PyArray_CLEARFLAGS(PyArrayObject *arr, int flags)
1602
+ {
1603
+ ((PyArrayObject_fields *)arr)->flags &= ~flags;
1604
+ }
1605
+
1606
+ #if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
1607
+ static inline NPY_RETURNS_BORROWED_REF PyObject *
1608
+ PyArray_HANDLER(PyArrayObject *arr)
1609
+ {
1610
+ return ((PyArrayObject_fields *)arr)->mem_handler;
1611
+ }
1612
+ #endif
1613
+
1614
+ #define PyTypeNum_ISBOOL(type) ((type) == NPY_BOOL)
1615
+
1616
+ #define PyTypeNum_ISUNSIGNED(type) (((type) == NPY_UBYTE) || \
1617
+ ((type) == NPY_USHORT) || \
1618
+ ((type) == NPY_UINT) || \
1619
+ ((type) == NPY_ULONG) || \
1620
+ ((type) == NPY_ULONGLONG))
1621
+
1622
+ #define PyTypeNum_ISSIGNED(type) (((type) == NPY_BYTE) || \
1623
+ ((type) == NPY_SHORT) || \
1624
+ ((type) == NPY_INT) || \
1625
+ ((type) == NPY_LONG) || \
1626
+ ((type) == NPY_LONGLONG))
1627
+
1628
+ #define PyTypeNum_ISINTEGER(type) (((type) >= NPY_BYTE) && \
1629
+ ((type) <= NPY_ULONGLONG))
1630
+
1631
+ #define PyTypeNum_ISFLOAT(type) ((((type) >= NPY_FLOAT) && \
1632
+ ((type) <= NPY_LONGDOUBLE)) || \
1633
+ ((type) == NPY_HALF))
1634
+
1635
+ #define PyTypeNum_ISNUMBER(type) (((type) <= NPY_CLONGDOUBLE) || \
1636
+ ((type) == NPY_HALF))
1637
+
1638
+ #define PyTypeNum_ISSTRING(type) (((type) == NPY_STRING) || \
1639
+ ((type) == NPY_UNICODE))
1640
+
1641
+ #define PyTypeNum_ISCOMPLEX(type) (((type) >= NPY_CFLOAT) && \
1642
+ ((type) <= NPY_CLONGDOUBLE))
1643
+
1644
+ #define PyTypeNum_ISFLEXIBLE(type) (((type) >=NPY_STRING) && \
1645
+ ((type) <=NPY_VOID))
1646
+
1647
+ #define PyTypeNum_ISDATETIME(type) (((type) >=NPY_DATETIME) && \
1648
+ ((type) <=NPY_TIMEDELTA))
1649
+
1650
+ #define PyTypeNum_ISUSERDEF(type) (((type) >= NPY_USERDEF) && \
1651
+ ((type) < NPY_USERDEF+ \
1652
+ NPY_NUMUSERTYPES))
1653
+
1654
+ #define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \
1655
+ PyTypeNum_ISUSERDEF(type))
1656
+
1657
+ #define PyTypeNum_ISOBJECT(type) ((type) == NPY_OBJECT)
1658
+
1659
+
1660
+ #define PyDataType_ISLEGACY(dtype) ((dtype)->type_num < NPY_VSTRING && ((dtype)->type_num >= 0))
1661
+ #define PyDataType_ISBOOL(obj) PyTypeNum_ISBOOL(((PyArray_Descr*)(obj))->type_num)
1662
+ #define PyDataType_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(((PyArray_Descr*)(obj))->type_num)
1663
+ #define PyDataType_ISSIGNED(obj) PyTypeNum_ISSIGNED(((PyArray_Descr*)(obj))->type_num)
1664
+ #define PyDataType_ISINTEGER(obj) PyTypeNum_ISINTEGER(((PyArray_Descr*)(obj))->type_num )
1665
+ #define PyDataType_ISFLOAT(obj) PyTypeNum_ISFLOAT(((PyArray_Descr*)(obj))->type_num)
1666
+ #define PyDataType_ISNUMBER(obj) PyTypeNum_ISNUMBER(((PyArray_Descr*)(obj))->type_num)
1667
+ #define PyDataType_ISSTRING(obj) PyTypeNum_ISSTRING(((PyArray_Descr*)(obj))->type_num)
1668
+ #define PyDataType_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(((PyArray_Descr*)(obj))->type_num)
1669
+ #define PyDataType_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(((PyArray_Descr*)(obj))->type_num)
1670
+ #define PyDataType_ISDATETIME(obj) PyTypeNum_ISDATETIME(((PyArray_Descr*)(obj))->type_num)
1671
+ #define PyDataType_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(((PyArray_Descr*)(obj))->type_num)
1672
+ #define PyDataType_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(((PyArray_Descr*)(obj))->type_num)
1673
+ #define PyDataType_ISOBJECT(obj) PyTypeNum_ISOBJECT(((PyArray_Descr*)(obj))->type_num)
1674
+ #define PyDataType_MAKEUNSIZED(dtype) ((dtype)->elsize = 0)
1675
+ /*
1676
+ * PyDataType_* FLAGS, FLACHK, REFCHK, HASFIELDS, HASSUBARRAY, UNSIZED,
1677
+ * SUBARRAY, NAMES, FIELDS, C_METADATA, and METADATA require version specific
1678
+ * lookup and are defined in npy_2_compat.h.
1679
+ */
1680
+
1681
+
1682
+ #define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))
1683
+ #define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))
1684
+ #define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))
1685
+ #define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))
1686
+ #define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))
1687
+ #define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))
1688
+ #define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))
1689
+ #define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))
1690
+ #define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))
1691
+ #define PyArray_ISDATETIME(obj) PyTypeNum_ISDATETIME(PyArray_TYPE(obj))
1692
+ #define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))
1693
+ #define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))
1694
+ #define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))
1695
+ #define PyArray_HASFIELDS(obj) PyDataType_HASFIELDS(PyArray_DESCR(obj))
1696
+
1697
+ /*
1698
+ * FIXME: This should check for a flag on the data-type that
1699
+ * states whether or not it is variable length. Because the
1700
+ * ISFLEXIBLE check is hard-coded to the built-in data-types.
1701
+ */
1702
+ #define PyArray_ISVARIABLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))
1703
+
1704
+ #define PyArray_SAFEALIGNEDCOPY(obj) (PyArray_ISALIGNED(obj) && !PyArray_ISVARIABLE(obj))
1705
+
1706
+
1707
+ #define NPY_LITTLE '<'
1708
+ #define NPY_BIG '>'
1709
+ #define NPY_NATIVE '='
1710
+ #define NPY_SWAP 's'
1711
+ #define NPY_IGNORE '|'
1712
+
1713
+ #if NPY_BYTE_ORDER == NPY_BIG_ENDIAN
1714
+ #define NPY_NATBYTE NPY_BIG
1715
+ #define NPY_OPPBYTE NPY_LITTLE
1716
+ #else
1717
+ #define NPY_NATBYTE NPY_LITTLE
1718
+ #define NPY_OPPBYTE NPY_BIG
1719
+ #endif
1720
+
1721
+ #define PyArray_ISNBO(arg) ((arg) != NPY_OPPBYTE)
1722
+ #define PyArray_IsNativeByteOrder PyArray_ISNBO
1723
+ #define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)
1724
+ #define PyArray_ISBYTESWAPPED(m) (!PyArray_ISNOTSWAPPED(m))
1725
+
1726
+ #define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) && \
1727
+ PyArray_ISNOTSWAPPED(m))
1728
+
1729
+ #define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, NPY_ARRAY_CARRAY)
1730
+ #define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_CARRAY_RO)
1731
+ #define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, NPY_ARRAY_FARRAY)
1732
+ #define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_FARRAY_RO)
1733
+ #define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, NPY_ARRAY_BEHAVED)
1734
+ #define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_ALIGNED)
1735
+
1736
+
1737
+ #define PyDataType_ISNOTSWAPPED(d) PyArray_ISNBO(((PyArray_Descr *)(d))->byteorder)
1738
+ #define PyDataType_ISBYTESWAPPED(d) (!PyDataType_ISNOTSWAPPED(d))
1739
+
1740
+ /************************************************************
1741
+ * A struct used by PyArray_CreateSortedStridePerm, new in 1.7.
1742
+ ************************************************************/
1743
+
1744
+ typedef struct {
1745
+ npy_intp perm, stride;
1746
+ } npy_stride_sort_item;
1747
+
1748
+ /************************************************************
1749
+ * This is the form of the struct that's stored in the
1750
+ * PyCapsule returned by an array's __array_struct__ attribute. See
1751
+ * https://docs.scipy.org/doc/numpy/reference/arrays.interface.html for the full
1752
+ * documentation.
1753
+ ************************************************************/
1754
+ typedef struct {
1755
+ int two; /*
1756
+ * contains the integer 2 as a sanity
1757
+ * check
1758
+ */
1759
+
1760
+ int nd; /* number of dimensions */
1761
+
1762
+ char typekind; /*
1763
+ * kind in array --- character code of
1764
+ * typestr
1765
+ */
1766
+
1767
+ int itemsize; /* size of each element */
1768
+
1769
+ int flags; /*
1770
+ * how should be data interpreted. Valid
1771
+ * flags are CONTIGUOUS (1), F_CONTIGUOUS (2),
1772
+ * ALIGNED (0x100), NOTSWAPPED (0x200), and
1773
+ * WRITEABLE (0x400). ARR_HAS_DESCR (0x800)
1774
+ * states that arrdescr field is present in
1775
+ * structure
1776
+ */
1777
+
1778
+ npy_intp *shape; /*
1779
+ * A length-nd array of shape
1780
+ * information
1781
+ */
1782
+
1783
+ npy_intp *strides; /* A length-nd array of stride information */
1784
+
1785
+ void *data; /* A pointer to the first element of the array */
1786
+
1787
+ PyObject *descr; /*
1788
+ * A list of fields or NULL (ignored if flags
1789
+ * does not have ARR_HAS_DESCR flag set)
1790
+ */
1791
+ } PyArrayInterface;
1792
+
1793
+
1794
+ /****************************************
1795
+ * NpyString
1796
+ *
1797
+ * Types used by the NpyString API.
1798
+ ****************************************/
1799
+
1800
+ /*
1801
+ * A "packed" encoded string. The string data must be accessed by first unpacking the string.
1802
+ */
1803
+ typedef struct npy_packed_static_string npy_packed_static_string;
1804
+
1805
+ /*
1806
+ * An unpacked read-only view onto the data in a packed string
1807
+ */
1808
+ typedef struct npy_unpacked_static_string {
1809
+ size_t size;
1810
+ const char *buf;
1811
+ } npy_static_string;
1812
+
1813
+ /*
1814
+ * Handles heap allocations for static strings.
1815
+ */
1816
+ typedef struct npy_string_allocator npy_string_allocator;
1817
+
1818
+ typedef struct {
1819
+ PyArray_Descr base;
1820
+ // The object representing a null value
1821
+ PyObject *na_object;
1822
+ // Flag indicating whether or not to coerce arbitrary objects to strings
1823
+ char coerce;
1824
+ // Flag indicating the na object is NaN-like
1825
+ char has_nan_na;
1826
+ // Flag indicating the na object is a string
1827
+ char has_string_na;
1828
+ // If nonzero, indicates that this instance is owned by an array already
1829
+ char array_owned;
1830
+ // The string data to use when a default string is needed
1831
+ npy_static_string default_string;
1832
+ // The name of the missing data object, if any
1833
+ npy_static_string na_name;
1834
+ // the allocator should only be directly accessed after
1835
+ // acquiring the allocator_lock and the lock should
1836
+ // be released immediately after the allocator is
1837
+ // no longer needed
1838
+ npy_string_allocator *allocator;
1839
+ } PyArray_StringDTypeObject;
1840
+
1841
+ /*
1842
+ * PyArray_DTypeMeta related definitions.
1843
+ *
1844
+ * As of now, this API is preliminary and will be extended as necessary.
1845
+ */
1846
+ #if defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD
1847
+ /*
1848
+ * The Structures defined in this block are currently considered
1849
+ * private API and may change without warning!
1850
+ * Part of this (at least the size) is expected to be public API without
1851
+ * further modifications.
1852
+ */
1853
+ /* TODO: Make this definition public in the API, as soon as its settled */
1854
+ NPY_NO_EXPORT extern PyTypeObject PyArrayDTypeMeta_Type;
1855
+
1856
+ /*
1857
+ * While NumPy DTypes would not need to be heap types the plan is to
1858
+ * make DTypes available in Python at which point they will be heap types.
1859
+ * Since we also wish to add fields to the DType class, this looks like
1860
+ * a typical instance definition, but with PyHeapTypeObject instead of
1861
+ * only the PyObject_HEAD.
1862
+ * This must only be exposed very extremely careful consideration, since
1863
+ * it is a fairly complex construct which may be better to allow
1864
+ * refactoring of.
1865
+ */
1866
+ typedef struct {
1867
+ PyHeapTypeObject super;
1868
+
1869
+ /*
1870
+ * Most DTypes will have a singleton default instance, for the
1871
+ * parametric legacy DTypes (bytes, string, void, datetime) this
1872
+ * may be a pointer to the *prototype* instance?
1873
+ */
1874
+ PyArray_Descr *singleton;
1875
+ /* Copy of the legacy DTypes type number, usually invalid. */
1876
+ int type_num;
1877
+
1878
+ /* The type object of the scalar instances (may be NULL?) */
1879
+ PyTypeObject *scalar_type;
1880
+ /*
1881
+ * DType flags to signal legacy, parametric, or
1882
+ * abstract. But plenty of space for additional information/flags.
1883
+ */
1884
+ npy_uint64 flags;
1885
+
1886
+ /*
1887
+ * Use indirection in order to allow a fixed size for this struct.
1888
+ * A stable ABI size makes creating a static DType less painful
1889
+ * while also ensuring flexibility for all opaque API (with one
1890
+ * indirection due the pointer lookup).
1891
+ */
1892
+ void *dt_slots;
1893
+ void *reserved[3];
1894
+ } PyArray_DTypeMeta;
1895
+
1896
+ #endif /* NPY_INTERNAL_BUILD */
1897
+
1898
+
1899
+ /*
1900
+ * Use the keyword NPY_DEPRECATED_INCLUDES to ensure that the header files
1901
+ * npy_*_*_deprecated_api.h are only included from here and nowhere else.
1902
+ */
1903
+ #ifdef NPY_DEPRECATED_INCLUDES
1904
+ #error "Do not use the reserved keyword NPY_DEPRECATED_INCLUDES."
1905
+ #endif
1906
+ #define NPY_DEPRECATED_INCLUDES
1907
+ #if !defined(NPY_NO_DEPRECATED_API) || \
1908
+ (NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION)
1909
+ #include "npy_1_7_deprecated_api.h"
1910
+ #endif
1911
+ /*
1912
+ * There is no file npy_1_8_deprecated_api.h since there are no additional
1913
+ * deprecated API features in NumPy 1.8.
1914
+ *
1915
+ * Note to maintainers: insert code like the following in future NumPy
1916
+ * versions.
1917
+ *
1918
+ * #if !defined(NPY_NO_DEPRECATED_API) || \
1919
+ * (NPY_NO_DEPRECATED_API < NPY_1_9_API_VERSION)
1920
+ * #include "npy_1_9_deprecated_api.h"
1921
+ * #endif
1922
+ */
1923
+ #undef NPY_DEPRECATED_INCLUDES
1924
+
1925
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NDARRAYTYPES_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_1_7_deprecated_api.h ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NPY_DEPRECATED_INCLUDES
2
+ #error "Should never include npy_*_*_deprecated_api directly."
3
+ #endif
4
+
5
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_1_7_DEPRECATED_API_H_
6
+ #define NUMPY_CORE_INCLUDE_NUMPY_NPY_1_7_DEPRECATED_API_H_
7
+
8
+ /* Emit a warning if the user did not specifically request the old API */
9
+ #ifndef NPY_NO_DEPRECATED_API
10
+ #if defined(_WIN32)
11
+ #define _WARN___STR2__(x) #x
12
+ #define _WARN___STR1__(x) _WARN___STR2__(x)
13
+ #define _WARN___LOC__ __FILE__ "(" _WARN___STR1__(__LINE__) ") : Warning Msg: "
14
+ #pragma message(_WARN___LOC__"Using deprecated NumPy API, disable it with " \
15
+ "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION")
16
+ #else
17
+ #warning "Using deprecated NumPy API, disable it with " \
18
+ "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION"
19
+ #endif
20
+ #endif
21
+
22
+ /*
23
+ * This header exists to collect all dangerous/deprecated NumPy API
24
+ * as of NumPy 1.7.
25
+ *
26
+ * This is an attempt to remove bad API, the proliferation of macros,
27
+ * and namespace pollution currently produced by the NumPy headers.
28
+ */
29
+
30
+ /* These array flags are deprecated as of NumPy 1.7 */
31
+ #define NPY_CONTIGUOUS NPY_ARRAY_C_CONTIGUOUS
32
+ #define NPY_FORTRAN NPY_ARRAY_F_CONTIGUOUS
33
+
34
+ /*
35
+ * The consistent NPY_ARRAY_* names which don't pollute the NPY_*
36
+ * namespace were added in NumPy 1.7.
37
+ *
38
+ * These versions of the carray flags are deprecated, but
39
+ * probably should only be removed after two releases instead of one.
40
+ */
41
+ #define NPY_C_CONTIGUOUS NPY_ARRAY_C_CONTIGUOUS
42
+ #define NPY_F_CONTIGUOUS NPY_ARRAY_F_CONTIGUOUS
43
+ #define NPY_OWNDATA NPY_ARRAY_OWNDATA
44
+ #define NPY_FORCECAST NPY_ARRAY_FORCECAST
45
+ #define NPY_ENSURECOPY NPY_ARRAY_ENSURECOPY
46
+ #define NPY_ENSUREARRAY NPY_ARRAY_ENSUREARRAY
47
+ #define NPY_ELEMENTSTRIDES NPY_ARRAY_ELEMENTSTRIDES
48
+ #define NPY_ALIGNED NPY_ARRAY_ALIGNED
49
+ #define NPY_NOTSWAPPED NPY_ARRAY_NOTSWAPPED
50
+ #define NPY_WRITEABLE NPY_ARRAY_WRITEABLE
51
+ #define NPY_BEHAVED NPY_ARRAY_BEHAVED
52
+ #define NPY_BEHAVED_NS NPY_ARRAY_BEHAVED_NS
53
+ #define NPY_CARRAY NPY_ARRAY_CARRAY
54
+ #define NPY_CARRAY_RO NPY_ARRAY_CARRAY_RO
55
+ #define NPY_FARRAY NPY_ARRAY_FARRAY
56
+ #define NPY_FARRAY_RO NPY_ARRAY_FARRAY_RO
57
+ #define NPY_DEFAULT NPY_ARRAY_DEFAULT
58
+ #define NPY_IN_ARRAY NPY_ARRAY_IN_ARRAY
59
+ #define NPY_OUT_ARRAY NPY_ARRAY_OUT_ARRAY
60
+ #define NPY_INOUT_ARRAY NPY_ARRAY_INOUT_ARRAY
61
+ #define NPY_IN_FARRAY NPY_ARRAY_IN_FARRAY
62
+ #define NPY_OUT_FARRAY NPY_ARRAY_OUT_FARRAY
63
+ #define NPY_INOUT_FARRAY NPY_ARRAY_INOUT_FARRAY
64
+ #define NPY_UPDATE_ALL NPY_ARRAY_UPDATE_ALL
65
+
66
+ /* This way of accessing the default type is deprecated as of NumPy 1.7 */
67
+ #define PyArray_DEFAULT NPY_DEFAULT_TYPE
68
+
69
+ /*
70
+ * Deprecated as of NumPy 1.7, this kind of shortcut doesn't
71
+ * belong in the public API.
72
+ */
73
+ #define NPY_AO PyArrayObject
74
+
75
+ /*
76
+ * Deprecated as of NumPy 1.7, an all-lowercase macro doesn't
77
+ * belong in the public API.
78
+ */
79
+ #define fortran fortran_
80
+
81
+ /*
82
+ * Deprecated as of NumPy 1.7, as it is a namespace-polluting
83
+ * macro.
84
+ */
85
+ #define FORTRAN_IF PyArray_FORTRAN_IF
86
+
87
+ /* Deprecated as of NumPy 1.7, datetime64 uses c_metadata instead */
88
+ #define NPY_METADATA_DTSTR "__timeunit__"
89
+
90
+ /*
91
+ * Deprecated as of NumPy 1.7.
92
+ * The reasoning:
93
+ * - These are for datetime, but there's no datetime "namespace".
94
+ * - They just turn NPY_STR_<x> into "<x>", which is just
95
+ * making something simple be indirected.
96
+ */
97
+ #define NPY_STR_Y "Y"
98
+ #define NPY_STR_M "M"
99
+ #define NPY_STR_W "W"
100
+ #define NPY_STR_D "D"
101
+ #define NPY_STR_h "h"
102
+ #define NPY_STR_m "m"
103
+ #define NPY_STR_s "s"
104
+ #define NPY_STR_ms "ms"
105
+ #define NPY_STR_us "us"
106
+ #define NPY_STR_ns "ns"
107
+ #define NPY_STR_ps "ps"
108
+ #define NPY_STR_fs "fs"
109
+ #define NPY_STR_as "as"
110
+
111
+
112
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_1_7_DEPRECATED_API_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_2_compat.h ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * This header file defines relevant features which:
3
+ * - Require runtime inspection depending on the NumPy version.
4
+ * - May be needed when compiling with an older version of NumPy to allow
5
+ * a smooth transition.
6
+ *
7
+ * As such, it is shipped with NumPy 2.0, but designed to be vendored in full
8
+ * or parts by downstream projects.
9
+ *
10
+ * It must be included after any other includes. `import_array()` must have
11
+ * been called in the scope or version dependency will misbehave, even when
12
+ * only `PyUFunc_` API is used.
13
+ *
14
+ * If required complicated defs (with inline functions) should be written as:
15
+ *
16
+ * #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
17
+ * Simple definition when NumPy 2.0 API is guaranteed.
18
+ * #else
19
+ * static inline definition of a 1.x compatibility shim
20
+ * #if NPY_ABI_VERSION < 0x02000000
21
+ * Make 1.x compatibility shim the public API (1.x only branch)
22
+ * #else
23
+ * Runtime dispatched version (1.x or 2.x)
24
+ * #endif
25
+ * #endif
26
+ *
27
+ * An internal build always passes NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
28
+ */
29
+
30
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_2_COMPAT_H_
31
+ #define NUMPY_CORE_INCLUDE_NUMPY_NPY_2_COMPAT_H_
32
+
33
+ /*
34
+ * New macros for accessing real and complex part of a complex number can be
35
+ * found in "npy_2_complexcompat.h".
36
+ */
37
+
38
+
39
+ /*
40
+ * This header is meant to be included by downstream directly for 1.x compat.
41
+ * In that case we need to ensure that users first included the full headers
42
+ * and not just `ndarraytypes.h`.
43
+ */
44
+
45
+ #ifndef NPY_FEATURE_VERSION
46
+ #error "The NumPy 2 compat header requires `import_array()` for which " \
47
+ "the `ndarraytypes.h` header include is not sufficient. Please " \
48
+ "include it after `numpy/ndarrayobject.h` or similar.\n" \
49
+ "To simplify inclusion, you may use `PyArray_ImportNumPy()` " \
50
+ "which is defined in the compat header and is lightweight (can be)."
51
+ #endif
52
+
53
+ #if NPY_ABI_VERSION < 0x02000000
54
+ /*
55
+ * Define 2.0 feature version as it is needed below to decide whether we
56
+ * compile for both 1.x and 2.x (defining it guarantees 1.x only).
57
+ */
58
+ #define NPY_2_0_API_VERSION 0x00000012
59
+ /*
60
+ * If we are compiling with NumPy 1.x, PyArray_RUNTIME_VERSION so we
61
+ * pretend the `PyArray_RUNTIME_VERSION` is `NPY_FEATURE_VERSION`.
62
+ * This allows downstream to use `PyArray_RUNTIME_VERSION` if they need to.
63
+ */
64
+ #define PyArray_RUNTIME_VERSION NPY_FEATURE_VERSION
65
+ /* Compiling on NumPy 1.x where these are the same: */
66
+ #define PyArray_DescrProto PyArray_Descr
67
+ #endif
68
+
69
+
70
+ /*
71
+ * Define a better way to call `_import_array()` to simplify backporting as
72
+ * we now require imports more often (necessary to make ABI flexible).
73
+ */
74
+ #ifdef import_array1
75
+
76
+ static inline int
77
+ PyArray_ImportNumPyAPI(void)
78
+ {
79
+ if (NPY_UNLIKELY(PyArray_API == NULL)) {
80
+ import_array1(-1);
81
+ }
82
+ return 0;
83
+ }
84
+
85
+ #endif /* import_array1 */
86
+
87
+
88
+ /*
89
+ * NPY_DEFAULT_INT
90
+ *
91
+ * The default integer has changed, `NPY_DEFAULT_INT` is available at runtime
92
+ * for use as type number, e.g. `PyArray_DescrFromType(NPY_DEFAULT_INT)`.
93
+ *
94
+ * NPY_RAVEL_AXIS
95
+ *
96
+ * This was introduced in NumPy 2.0 to allow indicating that an axis should be
97
+ * raveled in an operation. Before NumPy 2.0, NPY_MAXDIMS was used for this purpose.
98
+ *
99
+ * NPY_MAXDIMS
100
+ *
101
+ * A constant indicating the maximum number dimensions allowed when creating
102
+ * an ndarray.
103
+ *
104
+ * NPY_NTYPES_LEGACY
105
+ *
106
+ * The number of built-in NumPy dtypes.
107
+ */
108
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
109
+ #define NPY_DEFAULT_INT NPY_INTP
110
+ #define NPY_RAVEL_AXIS NPY_MIN_INT
111
+ #define NPY_MAXARGS 64
112
+
113
+ #elif NPY_ABI_VERSION < 0x02000000
114
+ #define NPY_DEFAULT_INT NPY_LONG
115
+ #define NPY_RAVEL_AXIS 32
116
+ #define NPY_MAXARGS 32
117
+
118
+ /* Aliases of 2.x names to 1.x only equivalent names */
119
+ #define NPY_NTYPES NPY_NTYPES_LEGACY
120
+ #define PyArray_DescrProto PyArray_Descr
121
+ #define _PyArray_LegacyDescr PyArray_Descr
122
+ /* NumPy 2 definition always works, but add it for 1.x only */
123
+ #define PyDataType_ISLEGACY(dtype) (1)
124
+ #else
125
+ #define NPY_DEFAULT_INT \
126
+ (PyArray_RUNTIME_VERSION >= NPY_2_0_API_VERSION ? NPY_INTP : NPY_LONG)
127
+ #define NPY_RAVEL_AXIS \
128
+ (PyArray_RUNTIME_VERSION >= NPY_2_0_API_VERSION ? NPY_MIN_INT : 32)
129
+ #define NPY_MAXARGS \
130
+ (PyArray_RUNTIME_VERSION >= NPY_2_0_API_VERSION ? 64 : 32)
131
+ #endif
132
+
133
+
134
+ /*
135
+ * Access inline functions for descriptor fields. Except for the first
136
+ * few fields, these needed to be moved (elsize, alignment) for
137
+ * additional space. Or they are descriptor specific and are not generally
138
+ * available anymore (metadata, c_metadata, subarray, names, fields).
139
+ *
140
+ * Most of these are defined via the `DESCR_ACCESSOR` macro helper.
141
+ */
142
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION || NPY_ABI_VERSION < 0x02000000
143
+ /* Compiling for 1.x or 2.x only, direct field access is OK: */
144
+
145
+ static inline void
146
+ PyDataType_SET_ELSIZE(PyArray_Descr *dtype, npy_intp size)
147
+ {
148
+ dtype->elsize = size;
149
+ }
150
+
151
+ static inline npy_uint64
152
+ PyDataType_FLAGS(const PyArray_Descr *dtype)
153
+ {
154
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
155
+ return dtype->flags;
156
+ #else
157
+ return (unsigned char)dtype->flags; /* Need unsigned cast on 1.x */
158
+ #endif
159
+ }
160
+
161
+ #define DESCR_ACCESSOR(FIELD, field, type, legacy_only) \
162
+ static inline type \
163
+ PyDataType_##FIELD(const PyArray_Descr *dtype) { \
164
+ if (legacy_only && !PyDataType_ISLEGACY(dtype)) { \
165
+ return (type)0; \
166
+ } \
167
+ return ((_PyArray_LegacyDescr *)dtype)->field; \
168
+ }
169
+ #else /* compiling for both 1.x and 2.x */
170
+
171
+ static inline void
172
+ PyDataType_SET_ELSIZE(PyArray_Descr *dtype, npy_intp size)
173
+ {
174
+ if (PyArray_RUNTIME_VERSION >= NPY_2_0_API_VERSION) {
175
+ ((_PyArray_DescrNumPy2 *)dtype)->elsize = size;
176
+ }
177
+ else {
178
+ ((PyArray_DescrProto *)dtype)->elsize = (int)size;
179
+ }
180
+ }
181
+
182
+ static inline npy_uint64
183
+ PyDataType_FLAGS(const PyArray_Descr *dtype)
184
+ {
185
+ if (PyArray_RUNTIME_VERSION >= NPY_2_0_API_VERSION) {
186
+ return ((_PyArray_DescrNumPy2 *)dtype)->flags;
187
+ }
188
+ else {
189
+ return (unsigned char)((PyArray_DescrProto *)dtype)->flags;
190
+ }
191
+ }
192
+
193
+ /* Cast to LegacyDescr always fine but needed when `legacy_only` */
194
+ #define DESCR_ACCESSOR(FIELD, field, type, legacy_only) \
195
+ static inline type \
196
+ PyDataType_##FIELD(const PyArray_Descr *dtype) { \
197
+ if (legacy_only && !PyDataType_ISLEGACY(dtype)) { \
198
+ return (type)0; \
199
+ } \
200
+ if (PyArray_RUNTIME_VERSION >= NPY_2_0_API_VERSION) { \
201
+ return ((_PyArray_LegacyDescr *)dtype)->field; \
202
+ } \
203
+ else { \
204
+ return ((PyArray_DescrProto *)dtype)->field; \
205
+ } \
206
+ }
207
+ #endif
208
+
209
+ DESCR_ACCESSOR(ELSIZE, elsize, npy_intp, 0)
210
+ DESCR_ACCESSOR(ALIGNMENT, alignment, npy_intp, 0)
211
+ DESCR_ACCESSOR(METADATA, metadata, PyObject *, 1)
212
+ DESCR_ACCESSOR(SUBARRAY, subarray, PyArray_ArrayDescr *, 1)
213
+ DESCR_ACCESSOR(NAMES, names, PyObject *, 1)
214
+ DESCR_ACCESSOR(FIELDS, fields, PyObject *, 1)
215
+ DESCR_ACCESSOR(C_METADATA, c_metadata, NpyAuxData *, 1)
216
+
217
+ #undef DESCR_ACCESSOR
218
+
219
+
220
+ #if !(defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD)
221
+ #if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
222
+ static inline PyArray_ArrFuncs *
223
+ PyDataType_GetArrFuncs(const PyArray_Descr *descr)
224
+ {
225
+ return _PyDataType_GetArrFuncs(descr);
226
+ }
227
+ #elif NPY_ABI_VERSION < 0x02000000
228
+ static inline PyArray_ArrFuncs *
229
+ PyDataType_GetArrFuncs(const PyArray_Descr *descr)
230
+ {
231
+ return descr->f;
232
+ }
233
+ #else
234
+ static inline PyArray_ArrFuncs *
235
+ PyDataType_GetArrFuncs(const PyArray_Descr *descr)
236
+ {
237
+ if (PyArray_RUNTIME_VERSION >= NPY_2_0_API_VERSION) {
238
+ return _PyDataType_GetArrFuncs(descr);
239
+ }
240
+ else {
241
+ return ((PyArray_DescrProto *)descr)->f;
242
+ }
243
+ }
244
+ #endif
245
+
246
+
247
+ #endif /* not internal build */
248
+
249
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_2_COMPAT_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_2_complexcompat.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header is designed to be copy-pasted into downstream packages, since it provides
2
+ a compatibility layer between the old C struct complex types and the new native C99
3
+ complex types. The new macros are in numpy/npy_math.h, which is why it is included here. */
4
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_2_COMPLEXCOMPAT_H_
5
+ #define NUMPY_CORE_INCLUDE_NUMPY_NPY_2_COMPLEXCOMPAT_H_
6
+
7
+ #include <numpy/npy_math.h>
8
+
9
+ #ifndef NPY_CSETREALF
10
+ #define NPY_CSETREALF(c, r) (c)->real = (r)
11
+ #endif
12
+ #ifndef NPY_CSETIMAGF
13
+ #define NPY_CSETIMAGF(c, i) (c)->imag = (i)
14
+ #endif
15
+ #ifndef NPY_CSETREAL
16
+ #define NPY_CSETREAL(c, r) (c)->real = (r)
17
+ #endif
18
+ #ifndef NPY_CSETIMAG
19
+ #define NPY_CSETIMAG(c, i) (c)->imag = (i)
20
+ #endif
21
+ #ifndef NPY_CSETREALL
22
+ #define NPY_CSETREALL(c, r) (c)->real = (r)
23
+ #endif
24
+ #ifndef NPY_CSETIMAGL
25
+ #define NPY_CSETIMAGL(c, i) (c)->imag = (i)
26
+ #endif
27
+
28
+ #endif
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_3kcompat.h ADDED
@@ -0,0 +1,374 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * This is a convenience header file providing compatibility utilities
3
+ * for supporting different minor versions of Python 3.
4
+ * It was originally used to support the transition from Python 2,
5
+ * hence the "3k" naming.
6
+ *
7
+ * If you want to use this for your own projects, it's recommended to make a
8
+ * copy of it. We don't provide backwards compatibility guarantees.
9
+ */
10
+
11
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_3KCOMPAT_H_
12
+ #define NUMPY_CORE_INCLUDE_NUMPY_NPY_3KCOMPAT_H_
13
+
14
+ #include <Python.h>
15
+ #include <stdio.h>
16
+
17
+ #include "npy_common.h"
18
+
19
+ #ifdef __cplusplus
20
+ extern "C" {
21
+ #endif
22
+
23
+ /* Python13 removes _PyLong_AsInt */
24
+ static inline int
25
+ Npy__PyLong_AsInt(PyObject *obj)
26
+ {
27
+ int overflow;
28
+ long result = PyLong_AsLongAndOverflow(obj, &overflow);
29
+
30
+ /* INT_MAX and INT_MIN are defined in Python.h */
31
+ if (overflow || result > INT_MAX || result < INT_MIN) {
32
+ /* XXX: could be cute and give a different
33
+ message for overflow == -1 */
34
+ PyErr_SetString(PyExc_OverflowError,
35
+ "Python int too large to convert to C int");
36
+ return -1;
37
+ }
38
+ return (int)result;
39
+ }
40
+
41
+ #if defined _MSC_VER && _MSC_VER >= 1900
42
+
43
+ #include <stdlib.h>
44
+
45
+ /*
46
+ * Macros to protect CRT calls against instant termination when passed an
47
+ * invalid parameter (https://bugs.python.org/issue23524).
48
+ */
49
+ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
50
+ #define NPY_BEGIN_SUPPRESS_IPH { _invalid_parameter_handler _Py_old_handler = \
51
+ _set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
52
+ #define NPY_END_SUPPRESS_IPH _set_thread_local_invalid_parameter_handler(_Py_old_handler); }
53
+
54
+ #else
55
+
56
+ #define NPY_BEGIN_SUPPRESS_IPH
57
+ #define NPY_END_SUPPRESS_IPH
58
+
59
+ #endif /* _MSC_VER >= 1900 */
60
+
61
+ /*
62
+ * PyFile_* compatibility
63
+ */
64
+
65
+ /*
66
+ * Get a FILE* handle to the file represented by the Python object
67
+ */
68
+ static inline FILE*
69
+ npy_PyFile_Dup2(PyObject *file, char *mode, npy_off_t *orig_pos)
70
+ {
71
+ int fd, fd2, unbuf;
72
+ Py_ssize_t fd2_tmp;
73
+ PyObject *ret, *os, *io, *io_raw;
74
+ npy_off_t pos;
75
+ FILE *handle;
76
+
77
+ /* Flush first to ensure things end up in the file in the correct order */
78
+ ret = PyObject_CallMethod(file, "flush", "");
79
+ if (ret == NULL) {
80
+ return NULL;
81
+ }
82
+ Py_DECREF(ret);
83
+ fd = PyObject_AsFileDescriptor(file);
84
+ if (fd == -1) {
85
+ return NULL;
86
+ }
87
+
88
+ /*
89
+ * The handle needs to be dup'd because we have to call fclose
90
+ * at the end
91
+ */
92
+ os = PyImport_ImportModule("os");
93
+ if (os == NULL) {
94
+ return NULL;
95
+ }
96
+ ret = PyObject_CallMethod(os, "dup", "i", fd);
97
+ Py_DECREF(os);
98
+ if (ret == NULL) {
99
+ return NULL;
100
+ }
101
+ fd2_tmp = PyNumber_AsSsize_t(ret, PyExc_IOError);
102
+ Py_DECREF(ret);
103
+ if (fd2_tmp == -1 && PyErr_Occurred()) {
104
+ return NULL;
105
+ }
106
+ if (fd2_tmp < INT_MIN || fd2_tmp > INT_MAX) {
107
+ PyErr_SetString(PyExc_IOError,
108
+ "Getting an 'int' from os.dup() failed");
109
+ return NULL;
110
+ }
111
+ fd2 = (int)fd2_tmp;
112
+
113
+ /* Convert to FILE* handle */
114
+ #ifdef _WIN32
115
+ NPY_BEGIN_SUPPRESS_IPH
116
+ handle = _fdopen(fd2, mode);
117
+ NPY_END_SUPPRESS_IPH
118
+ #else
119
+ handle = fdopen(fd2, mode);
120
+ #endif
121
+ if (handle == NULL) {
122
+ PyErr_SetString(PyExc_IOError,
123
+ "Getting a FILE* from a Python file object via "
124
+ "_fdopen failed. If you built NumPy, you probably "
125
+ "linked with the wrong debug/release runtime");
126
+ return NULL;
127
+ }
128
+
129
+ /* Record the original raw file handle position */
130
+ *orig_pos = npy_ftell(handle);
131
+ if (*orig_pos == -1) {
132
+ /* The io module is needed to determine if buffering is used */
133
+ io = PyImport_ImportModule("io");
134
+ if (io == NULL) {
135
+ fclose(handle);
136
+ return NULL;
137
+ }
138
+ /* File object instances of RawIOBase are unbuffered */
139
+ io_raw = PyObject_GetAttrString(io, "RawIOBase");
140
+ Py_DECREF(io);
141
+ if (io_raw == NULL) {
142
+ fclose(handle);
143
+ return NULL;
144
+ }
145
+ unbuf = PyObject_IsInstance(file, io_raw);
146
+ Py_DECREF(io_raw);
147
+ if (unbuf == 1) {
148
+ /* Succeed if the IO is unbuffered */
149
+ return handle;
150
+ }
151
+ else {
152
+ PyErr_SetString(PyExc_IOError, "obtaining file position failed");
153
+ fclose(handle);
154
+ return NULL;
155
+ }
156
+ }
157
+
158
+ /* Seek raw handle to the Python-side position */
159
+ ret = PyObject_CallMethod(file, "tell", "");
160
+ if (ret == NULL) {
161
+ fclose(handle);
162
+ return NULL;
163
+ }
164
+ pos = PyLong_AsLongLong(ret);
165
+ Py_DECREF(ret);
166
+ if (PyErr_Occurred()) {
167
+ fclose(handle);
168
+ return NULL;
169
+ }
170
+ if (npy_fseek(handle, pos, SEEK_SET) == -1) {
171
+ PyErr_SetString(PyExc_IOError, "seeking file failed");
172
+ fclose(handle);
173
+ return NULL;
174
+ }
175
+ return handle;
176
+ }
177
+
178
+ /*
179
+ * Close the dup-ed file handle, and seek the Python one to the current position
180
+ */
181
+ static inline int
182
+ npy_PyFile_DupClose2(PyObject *file, FILE* handle, npy_off_t orig_pos)
183
+ {
184
+ int fd, unbuf;
185
+ PyObject *ret, *io, *io_raw;
186
+ npy_off_t position;
187
+
188
+ position = npy_ftell(handle);
189
+
190
+ /* Close the FILE* handle */
191
+ fclose(handle);
192
+
193
+ /*
194
+ * Restore original file handle position, in order to not confuse
195
+ * Python-side data structures
196
+ */
197
+ fd = PyObject_AsFileDescriptor(file);
198
+ if (fd == -1) {
199
+ return -1;
200
+ }
201
+
202
+ if (npy_lseek(fd, orig_pos, SEEK_SET) == -1) {
203
+
204
+ /* The io module is needed to determine if buffering is used */
205
+ io = PyImport_ImportModule("io");
206
+ if (io == NULL) {
207
+ return -1;
208
+ }
209
+ /* File object instances of RawIOBase are unbuffered */
210
+ io_raw = PyObject_GetAttrString(io, "RawIOBase");
211
+ Py_DECREF(io);
212
+ if (io_raw == NULL) {
213
+ return -1;
214
+ }
215
+ unbuf = PyObject_IsInstance(file, io_raw);
216
+ Py_DECREF(io_raw);
217
+ if (unbuf == 1) {
218
+ /* Succeed if the IO is unbuffered */
219
+ return 0;
220
+ }
221
+ else {
222
+ PyErr_SetString(PyExc_IOError, "seeking file failed");
223
+ return -1;
224
+ }
225
+ }
226
+
227
+ if (position == -1) {
228
+ PyErr_SetString(PyExc_IOError, "obtaining file position failed");
229
+ return -1;
230
+ }
231
+
232
+ /* Seek Python-side handle to the FILE* handle position */
233
+ ret = PyObject_CallMethod(file, "seek", NPY_OFF_T_PYFMT "i", position, 0);
234
+ if (ret == NULL) {
235
+ return -1;
236
+ }
237
+ Py_DECREF(ret);
238
+ return 0;
239
+ }
240
+
241
+ static inline PyObject*
242
+ npy_PyFile_OpenFile(PyObject *filename, const char *mode)
243
+ {
244
+ PyObject *open;
245
+ open = PyDict_GetItemString(PyEval_GetBuiltins(), "open");
246
+ if (open == NULL) {
247
+ return NULL;
248
+ }
249
+ return PyObject_CallFunction(open, "Os", filename, mode);
250
+ }
251
+
252
+ static inline int
253
+ npy_PyFile_CloseFile(PyObject *file)
254
+ {
255
+ PyObject *ret;
256
+
257
+ ret = PyObject_CallMethod(file, "close", NULL);
258
+ if (ret == NULL) {
259
+ return -1;
260
+ }
261
+ Py_DECREF(ret);
262
+ return 0;
263
+ }
264
+
265
+ /* This is a copy of _PyErr_ChainExceptions, which
266
+ * is no longer exported from Python3.12
267
+ */
268
+ static inline void
269
+ npy_PyErr_ChainExceptions(PyObject *exc, PyObject *val, PyObject *tb)
270
+ {
271
+ if (exc == NULL)
272
+ return;
273
+
274
+ if (PyErr_Occurred()) {
275
+ PyObject *exc2, *val2, *tb2;
276
+ PyErr_Fetch(&exc2, &val2, &tb2);
277
+ PyErr_NormalizeException(&exc, &val, &tb);
278
+ if (tb != NULL) {
279
+ PyException_SetTraceback(val, tb);
280
+ Py_DECREF(tb);
281
+ }
282
+ Py_DECREF(exc);
283
+ PyErr_NormalizeException(&exc2, &val2, &tb2);
284
+ PyException_SetContext(val2, val);
285
+ PyErr_Restore(exc2, val2, tb2);
286
+ }
287
+ else {
288
+ PyErr_Restore(exc, val, tb);
289
+ }
290
+ }
291
+
292
+ /* This is a copy of _PyErr_ChainExceptions, with:
293
+ * __cause__ used instead of __context__
294
+ */
295
+ static inline void
296
+ npy_PyErr_ChainExceptionsCause(PyObject *exc, PyObject *val, PyObject *tb)
297
+ {
298
+ if (exc == NULL)
299
+ return;
300
+
301
+ if (PyErr_Occurred()) {
302
+ PyObject *exc2, *val2, *tb2;
303
+ PyErr_Fetch(&exc2, &val2, &tb2);
304
+ PyErr_NormalizeException(&exc, &val, &tb);
305
+ if (tb != NULL) {
306
+ PyException_SetTraceback(val, tb);
307
+ Py_DECREF(tb);
308
+ }
309
+ Py_DECREF(exc);
310
+ PyErr_NormalizeException(&exc2, &val2, &tb2);
311
+ PyException_SetCause(val2, val);
312
+ PyErr_Restore(exc2, val2, tb2);
313
+ }
314
+ else {
315
+ PyErr_Restore(exc, val, tb);
316
+ }
317
+ }
318
+
319
+ /*
320
+ * PyCObject functions adapted to PyCapsules.
321
+ *
322
+ * The main job here is to get rid of the improved error handling
323
+ * of PyCapsules. It's a shame...
324
+ */
325
+ static inline PyObject *
326
+ NpyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *))
327
+ {
328
+ PyObject *ret = PyCapsule_New(ptr, NULL, dtor);
329
+ if (ret == NULL) {
330
+ PyErr_Clear();
331
+ }
332
+ return ret;
333
+ }
334
+
335
+ static inline PyObject *
336
+ NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, void (*dtor)(PyObject *))
337
+ {
338
+ PyObject *ret = NpyCapsule_FromVoidPtr(ptr, dtor);
339
+ if (ret != NULL && PyCapsule_SetContext(ret, context) != 0) {
340
+ PyErr_Clear();
341
+ Py_DECREF(ret);
342
+ ret = NULL;
343
+ }
344
+ return ret;
345
+ }
346
+
347
+ static inline void *
348
+ NpyCapsule_AsVoidPtr(PyObject *obj)
349
+ {
350
+ void *ret = PyCapsule_GetPointer(obj, NULL);
351
+ if (ret == NULL) {
352
+ PyErr_Clear();
353
+ }
354
+ return ret;
355
+ }
356
+
357
+ static inline void *
358
+ NpyCapsule_GetDesc(PyObject *obj)
359
+ {
360
+ return PyCapsule_GetContext(obj);
361
+ }
362
+
363
+ static inline int
364
+ NpyCapsule_Check(PyObject *ptr)
365
+ {
366
+ return PyCapsule_CheckExact(ptr);
367
+ }
368
+
369
+ #ifdef __cplusplus
370
+ }
371
+ #endif
372
+
373
+
374
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_3KCOMPAT_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_common.h ADDED
@@ -0,0 +1,1070 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_COMMON_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_NPY_COMMON_H_
3
+
4
+ /* need Python.h for npy_intp, npy_uintp */
5
+ #include <Python.h>
6
+
7
+ /* numpconfig.h is auto-generated */
8
+ #include "numpyconfig.h"
9
+ #ifdef HAVE_NPY_CONFIG_H
10
+ #include <npy_config.h>
11
+ #endif
12
+
13
+ /*
14
+ * using static inline modifiers when defining npy_math functions
15
+ * allows the compiler to make optimizations when possible
16
+ */
17
+ #ifndef NPY_INLINE_MATH
18
+ #if defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD
19
+ #define NPY_INLINE_MATH 1
20
+ #else
21
+ #define NPY_INLINE_MATH 0
22
+ #endif
23
+ #endif
24
+
25
+ /*
26
+ * gcc does not unroll even with -O3
27
+ * use with care, unrolling on modern cpus rarely speeds things up
28
+ */
29
+ #ifdef HAVE_ATTRIBUTE_OPTIMIZE_UNROLL_LOOPS
30
+ #define NPY_GCC_UNROLL_LOOPS \
31
+ __attribute__((optimize("unroll-loops")))
32
+ #else
33
+ #define NPY_GCC_UNROLL_LOOPS
34
+ #endif
35
+
36
+ /* highest gcc optimization level, enabled autovectorizer */
37
+ #ifdef HAVE_ATTRIBUTE_OPTIMIZE_OPT_3
38
+ #define NPY_GCC_OPT_3 __attribute__((optimize("O3")))
39
+ #else
40
+ #define NPY_GCC_OPT_3
41
+ #endif
42
+
43
+ /*
44
+ * mark an argument (starting from 1) that must not be NULL and is not checked
45
+ * DO NOT USE IF FUNCTION CHECKS FOR NULL!! the compiler will remove the check
46
+ */
47
+ #ifdef HAVE_ATTRIBUTE_NONNULL
48
+ #define NPY_GCC_NONNULL(n) __attribute__((nonnull(n)))
49
+ #else
50
+ #define NPY_GCC_NONNULL(n)
51
+ #endif
52
+
53
+ /*
54
+ * give a hint to the compiler which branch is more likely or unlikely
55
+ * to occur, e.g. rare error cases:
56
+ *
57
+ * if (NPY_UNLIKELY(failure == 0))
58
+ * return NULL;
59
+ *
60
+ * the double !! is to cast the expression (e.g. NULL) to a boolean required by
61
+ * the intrinsic
62
+ */
63
+ #ifdef HAVE___BUILTIN_EXPECT
64
+ #define NPY_LIKELY(x) __builtin_expect(!!(x), 1)
65
+ #define NPY_UNLIKELY(x) __builtin_expect(!!(x), 0)
66
+ #else
67
+ #define NPY_LIKELY(x) (x)
68
+ #define NPY_UNLIKELY(x) (x)
69
+ #endif
70
+
71
+ #ifdef HAVE___BUILTIN_PREFETCH
72
+ /* unlike _mm_prefetch also works on non-x86 */
73
+ #define NPY_PREFETCH(x, rw, loc) __builtin_prefetch((x), (rw), (loc))
74
+ #else
75
+ #ifdef NPY_HAVE_SSE
76
+ /* _MM_HINT_ET[01] (rw = 1) unsupported, only available in gcc >= 4.9 */
77
+ #define NPY_PREFETCH(x, rw, loc) _mm_prefetch((x), loc == 0 ? _MM_HINT_NTA : \
78
+ (loc == 1 ? _MM_HINT_T2 : \
79
+ (loc == 2 ? _MM_HINT_T1 : \
80
+ (loc == 3 ? _MM_HINT_T0 : -1))))
81
+ #else
82
+ #define NPY_PREFETCH(x, rw,loc)
83
+ #endif
84
+ #endif
85
+
86
+ /* `NPY_INLINE` kept for backwards compatibility; use `inline` instead */
87
+ #if defined(_MSC_VER) && !defined(__clang__)
88
+ #define NPY_INLINE __inline
89
+ /* clang included here to handle clang-cl on Windows */
90
+ #elif defined(__GNUC__) || defined(__clang__)
91
+ #if defined(__STRICT_ANSI__)
92
+ #define NPY_INLINE __inline__
93
+ #else
94
+ #define NPY_INLINE inline
95
+ #endif
96
+ #else
97
+ #define NPY_INLINE
98
+ #endif
99
+
100
+ #ifdef _MSC_VER
101
+ #define NPY_FINLINE static __forceinline
102
+ #elif defined(__GNUC__)
103
+ #define NPY_FINLINE static inline __attribute__((always_inline))
104
+ #else
105
+ #define NPY_FINLINE static
106
+ #endif
107
+
108
+ #if defined(_MSC_VER)
109
+ #define NPY_NOINLINE static __declspec(noinline)
110
+ #elif defined(__GNUC__) || defined(__clang__)
111
+ #define NPY_NOINLINE static __attribute__((noinline))
112
+ #else
113
+ #define NPY_NOINLINE static
114
+ #endif
115
+
116
+ #ifdef __cplusplus
117
+ #define NPY_TLS thread_local
118
+ #elif defined(HAVE_THREAD_LOCAL)
119
+ #define NPY_TLS thread_local
120
+ #elif defined(HAVE__THREAD_LOCAL)
121
+ #define NPY_TLS _Thread_local
122
+ #elif defined(HAVE___THREAD)
123
+ #define NPY_TLS __thread
124
+ #elif defined(HAVE___DECLSPEC_THREAD_)
125
+ #define NPY_TLS __declspec(thread)
126
+ #else
127
+ #define NPY_TLS
128
+ #endif
129
+
130
+ #ifdef WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE
131
+ #define NPY_RETURNS_BORROWED_REF \
132
+ __attribute__((cpychecker_returns_borrowed_ref))
133
+ #else
134
+ #define NPY_RETURNS_BORROWED_REF
135
+ #endif
136
+
137
+ #ifdef WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE
138
+ #define NPY_STEALS_REF_TO_ARG(n) \
139
+ __attribute__((cpychecker_steals_reference_to_arg(n)))
140
+ #else
141
+ #define NPY_STEALS_REF_TO_ARG(n)
142
+ #endif
143
+
144
+ /* 64 bit file position support, also on win-amd64. Issue gh-2256 */
145
+ #if defined(_MSC_VER) && defined(_WIN64) && (_MSC_VER > 1400) || \
146
+ defined(__MINGW32__) || defined(__MINGW64__)
147
+ #include <io.h>
148
+
149
+ #define npy_fseek _fseeki64
150
+ #define npy_ftell _ftelli64
151
+ #define npy_lseek _lseeki64
152
+ #define npy_off_t npy_int64
153
+
154
+ #if NPY_SIZEOF_INT == 8
155
+ #define NPY_OFF_T_PYFMT "i"
156
+ #elif NPY_SIZEOF_LONG == 8
157
+ #define NPY_OFF_T_PYFMT "l"
158
+ #elif NPY_SIZEOF_LONGLONG == 8
159
+ #define NPY_OFF_T_PYFMT "L"
160
+ #else
161
+ #error Unsupported size for type off_t
162
+ #endif
163
+ #else
164
+ #ifdef HAVE_FSEEKO
165
+ #define npy_fseek fseeko
166
+ #else
167
+ #define npy_fseek fseek
168
+ #endif
169
+ #ifdef HAVE_FTELLO
170
+ #define npy_ftell ftello
171
+ #else
172
+ #define npy_ftell ftell
173
+ #endif
174
+ #include <sys/types.h>
175
+ #ifndef _WIN32
176
+ #include <unistd.h>
177
+ #endif
178
+ #define npy_lseek lseek
179
+ #define npy_off_t off_t
180
+
181
+ #if NPY_SIZEOF_OFF_T == NPY_SIZEOF_SHORT
182
+ #define NPY_OFF_T_PYFMT "h"
183
+ #elif NPY_SIZEOF_OFF_T == NPY_SIZEOF_INT
184
+ #define NPY_OFF_T_PYFMT "i"
185
+ #elif NPY_SIZEOF_OFF_T == NPY_SIZEOF_LONG
186
+ #define NPY_OFF_T_PYFMT "l"
187
+ #elif NPY_SIZEOF_OFF_T == NPY_SIZEOF_LONGLONG
188
+ #define NPY_OFF_T_PYFMT "L"
189
+ #else
190
+ #error Unsupported size for type off_t
191
+ #endif
192
+ #endif
193
+
194
+ /* enums for detected endianness */
195
+ enum {
196
+ NPY_CPU_UNKNOWN_ENDIAN,
197
+ NPY_CPU_LITTLE,
198
+ NPY_CPU_BIG
199
+ };
200
+
201
+ /*
202
+ * This is to typedef npy_intp to the appropriate size for Py_ssize_t.
203
+ * (Before NumPy 2.0 we used Py_intptr_t and Py_uintptr_t from `pyport.h`.)
204
+ */
205
+ typedef Py_ssize_t npy_intp;
206
+ typedef size_t npy_uintp;
207
+
208
+ /*
209
+ * Define sizes that were not defined in numpyconfig.h.
210
+ */
211
+ #define NPY_SIZEOF_CHAR 1
212
+ #define NPY_SIZEOF_BYTE 1
213
+ #define NPY_SIZEOF_DATETIME 8
214
+ #define NPY_SIZEOF_TIMEDELTA 8
215
+ #define NPY_SIZEOF_HALF 2
216
+ #define NPY_SIZEOF_CFLOAT NPY_SIZEOF_COMPLEX_FLOAT
217
+ #define NPY_SIZEOF_CDOUBLE NPY_SIZEOF_COMPLEX_DOUBLE
218
+ #define NPY_SIZEOF_CLONGDOUBLE NPY_SIZEOF_COMPLEX_LONGDOUBLE
219
+
220
+ #ifdef constchar
221
+ #undef constchar
222
+ #endif
223
+
224
+ #define NPY_SSIZE_T_PYFMT "n"
225
+ #define constchar char
226
+
227
+ /* NPY_INTP_FMT Note:
228
+ * Unlike the other NPY_*_FMT macros, which are used with PyOS_snprintf,
229
+ * NPY_INTP_FMT is used with PyErr_Format and PyUnicode_FromFormat. Those
230
+ * functions use different formatting codes that are portably specified
231
+ * according to the Python documentation. See issue gh-2388.
232
+ */
233
+ #if NPY_SIZEOF_INTP == NPY_SIZEOF_LONG
234
+ #define NPY_INTP NPY_LONG
235
+ #define NPY_UINTP NPY_ULONG
236
+ #define PyIntpArrType_Type PyLongArrType_Type
237
+ #define PyUIntpArrType_Type PyULongArrType_Type
238
+ #define NPY_MAX_INTP NPY_MAX_LONG
239
+ #define NPY_MIN_INTP NPY_MIN_LONG
240
+ #define NPY_MAX_UINTP NPY_MAX_ULONG
241
+ #define NPY_INTP_FMT "ld"
242
+ #elif NPY_SIZEOF_INTP == NPY_SIZEOF_INT
243
+ #define NPY_INTP NPY_INT
244
+ #define NPY_UINTP NPY_UINT
245
+ #define PyIntpArrType_Type PyIntArrType_Type
246
+ #define PyUIntpArrType_Type PyUIntArrType_Type
247
+ #define NPY_MAX_INTP NPY_MAX_INT
248
+ #define NPY_MIN_INTP NPY_MIN_INT
249
+ #define NPY_MAX_UINTP NPY_MAX_UINT
250
+ #define NPY_INTP_FMT "d"
251
+ #elif defined(PY_LONG_LONG) && (NPY_SIZEOF_INTP == NPY_SIZEOF_LONGLONG)
252
+ #define NPY_INTP NPY_LONGLONG
253
+ #define NPY_UINTP NPY_ULONGLONG
254
+ #define PyIntpArrType_Type PyLongLongArrType_Type
255
+ #define PyUIntpArrType_Type PyULongLongArrType_Type
256
+ #define NPY_MAX_INTP NPY_MAX_LONGLONG
257
+ #define NPY_MIN_INTP NPY_MIN_LONGLONG
258
+ #define NPY_MAX_UINTP NPY_MAX_ULONGLONG
259
+ #define NPY_INTP_FMT "lld"
260
+ #else
261
+ #error "Failed to correctly define NPY_INTP and NPY_UINTP"
262
+ #endif
263
+
264
+
265
+ /*
266
+ * Some platforms don't define bool, long long, or long double.
267
+ * Handle that here.
268
+ */
269
+ #define NPY_BYTE_FMT "hhd"
270
+ #define NPY_UBYTE_FMT "hhu"
271
+ #define NPY_SHORT_FMT "hd"
272
+ #define NPY_USHORT_FMT "hu"
273
+ #define NPY_INT_FMT "d"
274
+ #define NPY_UINT_FMT "u"
275
+ #define NPY_LONG_FMT "ld"
276
+ #define NPY_ULONG_FMT "lu"
277
+ #define NPY_HALF_FMT "g"
278
+ #define NPY_FLOAT_FMT "g"
279
+ #define NPY_DOUBLE_FMT "g"
280
+
281
+
282
+ #ifdef PY_LONG_LONG
283
+ typedef PY_LONG_LONG npy_longlong;
284
+ typedef unsigned PY_LONG_LONG npy_ulonglong;
285
+ # ifdef _MSC_VER
286
+ # define NPY_LONGLONG_FMT "I64d"
287
+ # define NPY_ULONGLONG_FMT "I64u"
288
+ # else
289
+ # define NPY_LONGLONG_FMT "lld"
290
+ # define NPY_ULONGLONG_FMT "llu"
291
+ # endif
292
+ # ifdef _MSC_VER
293
+ # define NPY_LONGLONG_SUFFIX(x) (x##i64)
294
+ # define NPY_ULONGLONG_SUFFIX(x) (x##Ui64)
295
+ # else
296
+ # define NPY_LONGLONG_SUFFIX(x) (x##LL)
297
+ # define NPY_ULONGLONG_SUFFIX(x) (x##ULL)
298
+ # endif
299
+ #else
300
+ typedef long npy_longlong;
301
+ typedef unsigned long npy_ulonglong;
302
+ # define NPY_LONGLONG_SUFFIX(x) (x##L)
303
+ # define NPY_ULONGLONG_SUFFIX(x) (x##UL)
304
+ #endif
305
+
306
+
307
+ typedef unsigned char npy_bool;
308
+ #define NPY_FALSE 0
309
+ #define NPY_TRUE 1
310
+ /*
311
+ * `NPY_SIZEOF_LONGDOUBLE` isn't usually equal to sizeof(long double).
312
+ * In some certain cases, it may forced to be equal to sizeof(double)
313
+ * even against the compiler implementation and the same goes for
314
+ * `complex long double`.
315
+ *
316
+ * Therefore, avoid `long double`, use `npy_longdouble` instead,
317
+ * and when it comes to standard math functions make sure of using
318
+ * the double version when `NPY_SIZEOF_LONGDOUBLE` == `NPY_SIZEOF_DOUBLE`.
319
+ * For example:
320
+ * npy_longdouble *ptr, x;
321
+ * #if NPY_SIZEOF_LONGDOUBLE == NPY_SIZEOF_DOUBLE
322
+ * npy_longdouble r = modf(x, ptr);
323
+ * #else
324
+ * npy_longdouble r = modfl(x, ptr);
325
+ * #endif
326
+ *
327
+ * See https://github.com/numpy/numpy/issues/20348
328
+ */
329
+ #if NPY_SIZEOF_LONGDOUBLE == NPY_SIZEOF_DOUBLE
330
+ #define NPY_LONGDOUBLE_FMT "g"
331
+ #define longdouble_t double
332
+ typedef double npy_longdouble;
333
+ #else
334
+ #define NPY_LONGDOUBLE_FMT "Lg"
335
+ #define longdouble_t long double
336
+ typedef long double npy_longdouble;
337
+ #endif
338
+
339
+ #ifndef Py_USING_UNICODE
340
+ #error Must use Python with unicode enabled.
341
+ #endif
342
+
343
+
344
+ typedef signed char npy_byte;
345
+ typedef unsigned char npy_ubyte;
346
+ typedef unsigned short npy_ushort;
347
+ typedef unsigned int npy_uint;
348
+ typedef unsigned long npy_ulong;
349
+
350
+ /* These are for completeness */
351
+ typedef char npy_char;
352
+ typedef short npy_short;
353
+ typedef int npy_int;
354
+ typedef long npy_long;
355
+ typedef float npy_float;
356
+ typedef double npy_double;
357
+
358
+ typedef Py_hash_t npy_hash_t;
359
+ #define NPY_SIZEOF_HASH_T NPY_SIZEOF_INTP
360
+
361
+ #if defined(__cplusplus)
362
+
363
+ typedef struct
364
+ {
365
+ double _Val[2];
366
+ } npy_cdouble;
367
+
368
+ typedef struct
369
+ {
370
+ float _Val[2];
371
+ } npy_cfloat;
372
+
373
+ typedef struct
374
+ {
375
+ long double _Val[2];
376
+ } npy_clongdouble;
377
+
378
+ #else
379
+
380
+ #include <complex.h>
381
+
382
+
383
+ #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
384
+ typedef _Dcomplex npy_cdouble;
385
+ typedef _Fcomplex npy_cfloat;
386
+ typedef _Lcomplex npy_clongdouble;
387
+ #else /* !defined(_MSC_VER) || defined(__INTEL_COMPILER) */
388
+ typedef double _Complex npy_cdouble;
389
+ typedef float _Complex npy_cfloat;
390
+ typedef longdouble_t _Complex npy_clongdouble;
391
+ #endif
392
+
393
+ #endif
394
+
395
+ /*
396
+ * numarray-style bit-width typedefs
397
+ */
398
+ #define NPY_MAX_INT8 127
399
+ #define NPY_MIN_INT8 -128
400
+ #define NPY_MAX_UINT8 255
401
+ #define NPY_MAX_INT16 32767
402
+ #define NPY_MIN_INT16 -32768
403
+ #define NPY_MAX_UINT16 65535
404
+ #define NPY_MAX_INT32 2147483647
405
+ #define NPY_MIN_INT32 (-NPY_MAX_INT32 - 1)
406
+ #define NPY_MAX_UINT32 4294967295U
407
+ #define NPY_MAX_INT64 NPY_LONGLONG_SUFFIX(9223372036854775807)
408
+ #define NPY_MIN_INT64 (-NPY_MAX_INT64 - NPY_LONGLONG_SUFFIX(1))
409
+ #define NPY_MAX_UINT64 NPY_ULONGLONG_SUFFIX(18446744073709551615)
410
+ #define NPY_MAX_INT128 NPY_LONGLONG_SUFFIX(85070591730234615865843651857942052864)
411
+ #define NPY_MIN_INT128 (-NPY_MAX_INT128 - NPY_LONGLONG_SUFFIX(1))
412
+ #define NPY_MAX_UINT128 NPY_ULONGLONG_SUFFIX(170141183460469231731687303715884105728)
413
+ #define NPY_MAX_INT256 NPY_LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)
414
+ #define NPY_MIN_INT256 (-NPY_MAX_INT256 - NPY_LONGLONG_SUFFIX(1))
415
+ #define NPY_MAX_UINT256 NPY_ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)
416
+ #define NPY_MIN_DATETIME NPY_MIN_INT64
417
+ #define NPY_MAX_DATETIME NPY_MAX_INT64
418
+ #define NPY_MIN_TIMEDELTA NPY_MIN_INT64
419
+ #define NPY_MAX_TIMEDELTA NPY_MAX_INT64
420
+
421
+ /* Need to find the number of bits for each type and
422
+ make definitions accordingly.
423
+
424
+ C states that sizeof(char) == 1 by definition
425
+
426
+ So, just using the sizeof keyword won't help.
427
+
428
+ It also looks like Python itself uses sizeof(char) quite a
429
+ bit, which by definition should be 1 all the time.
430
+
431
+ Idea: Make Use of CHAR_BIT which should tell us how many
432
+ BITS per CHARACTER
433
+ */
434
+
435
+ /* Include platform definitions -- These are in the C89/90 standard */
436
+ #include <limits.h>
437
+ #define NPY_MAX_BYTE SCHAR_MAX
438
+ #define NPY_MIN_BYTE SCHAR_MIN
439
+ #define NPY_MAX_UBYTE UCHAR_MAX
440
+ #define NPY_MAX_SHORT SHRT_MAX
441
+ #define NPY_MIN_SHORT SHRT_MIN
442
+ #define NPY_MAX_USHORT USHRT_MAX
443
+ #define NPY_MAX_INT INT_MAX
444
+ #ifndef INT_MIN
445
+ #define INT_MIN (-INT_MAX - 1)
446
+ #endif
447
+ #define NPY_MIN_INT INT_MIN
448
+ #define NPY_MAX_UINT UINT_MAX
449
+ #define NPY_MAX_LONG LONG_MAX
450
+ #define NPY_MIN_LONG LONG_MIN
451
+ #define NPY_MAX_ULONG ULONG_MAX
452
+
453
+ #define NPY_BITSOF_BOOL (sizeof(npy_bool) * CHAR_BIT)
454
+ #define NPY_BITSOF_CHAR CHAR_BIT
455
+ #define NPY_BITSOF_BYTE (NPY_SIZEOF_BYTE * CHAR_BIT)
456
+ #define NPY_BITSOF_SHORT (NPY_SIZEOF_SHORT * CHAR_BIT)
457
+ #define NPY_BITSOF_INT (NPY_SIZEOF_INT * CHAR_BIT)
458
+ #define NPY_BITSOF_LONG (NPY_SIZEOF_LONG * CHAR_BIT)
459
+ #define NPY_BITSOF_LONGLONG (NPY_SIZEOF_LONGLONG * CHAR_BIT)
460
+ #define NPY_BITSOF_INTP (NPY_SIZEOF_INTP * CHAR_BIT)
461
+ #define NPY_BITSOF_HALF (NPY_SIZEOF_HALF * CHAR_BIT)
462
+ #define NPY_BITSOF_FLOAT (NPY_SIZEOF_FLOAT * CHAR_BIT)
463
+ #define NPY_BITSOF_DOUBLE (NPY_SIZEOF_DOUBLE * CHAR_BIT)
464
+ #define NPY_BITSOF_LONGDOUBLE (NPY_SIZEOF_LONGDOUBLE * CHAR_BIT)
465
+ #define NPY_BITSOF_CFLOAT (NPY_SIZEOF_CFLOAT * CHAR_BIT)
466
+ #define NPY_BITSOF_CDOUBLE (NPY_SIZEOF_CDOUBLE * CHAR_BIT)
467
+ #define NPY_BITSOF_CLONGDOUBLE (NPY_SIZEOF_CLONGDOUBLE * CHAR_BIT)
468
+ #define NPY_BITSOF_DATETIME (NPY_SIZEOF_DATETIME * CHAR_BIT)
469
+ #define NPY_BITSOF_TIMEDELTA (NPY_SIZEOF_TIMEDELTA * CHAR_BIT)
470
+
471
+ #if NPY_BITSOF_LONG == 8
472
+ #define NPY_INT8 NPY_LONG
473
+ #define NPY_UINT8 NPY_ULONG
474
+ typedef long npy_int8;
475
+ typedef unsigned long npy_uint8;
476
+ #define PyInt8ScalarObject PyLongScalarObject
477
+ #define PyInt8ArrType_Type PyLongArrType_Type
478
+ #define PyUInt8ScalarObject PyULongScalarObject
479
+ #define PyUInt8ArrType_Type PyULongArrType_Type
480
+ #define NPY_INT8_FMT NPY_LONG_FMT
481
+ #define NPY_UINT8_FMT NPY_ULONG_FMT
482
+ #elif NPY_BITSOF_LONG == 16
483
+ #define NPY_INT16 NPY_LONG
484
+ #define NPY_UINT16 NPY_ULONG
485
+ typedef long npy_int16;
486
+ typedef unsigned long npy_uint16;
487
+ #define PyInt16ScalarObject PyLongScalarObject
488
+ #define PyInt16ArrType_Type PyLongArrType_Type
489
+ #define PyUInt16ScalarObject PyULongScalarObject
490
+ #define PyUInt16ArrType_Type PyULongArrType_Type
491
+ #define NPY_INT16_FMT NPY_LONG_FMT
492
+ #define NPY_UINT16_FMT NPY_ULONG_FMT
493
+ #elif NPY_BITSOF_LONG == 32
494
+ #define NPY_INT32 NPY_LONG
495
+ #define NPY_UINT32 NPY_ULONG
496
+ typedef long npy_int32;
497
+ typedef unsigned long npy_uint32;
498
+ typedef unsigned long npy_ucs4;
499
+ #define PyInt32ScalarObject PyLongScalarObject
500
+ #define PyInt32ArrType_Type PyLongArrType_Type
501
+ #define PyUInt32ScalarObject PyULongScalarObject
502
+ #define PyUInt32ArrType_Type PyULongArrType_Type
503
+ #define NPY_INT32_FMT NPY_LONG_FMT
504
+ #define NPY_UINT32_FMT NPY_ULONG_FMT
505
+ #elif NPY_BITSOF_LONG == 64
506
+ #define NPY_INT64 NPY_LONG
507
+ #define NPY_UINT64 NPY_ULONG
508
+ typedef long npy_int64;
509
+ typedef unsigned long npy_uint64;
510
+ #define PyInt64ScalarObject PyLongScalarObject
511
+ #define PyInt64ArrType_Type PyLongArrType_Type
512
+ #define PyUInt64ScalarObject PyULongScalarObject
513
+ #define PyUInt64ArrType_Type PyULongArrType_Type
514
+ #define NPY_INT64_FMT NPY_LONG_FMT
515
+ #define NPY_UINT64_FMT NPY_ULONG_FMT
516
+ #define MyPyLong_FromInt64 PyLong_FromLong
517
+ #define MyPyLong_AsInt64 PyLong_AsLong
518
+ #elif NPY_BITSOF_LONG == 128
519
+ #define NPY_INT128 NPY_LONG
520
+ #define NPY_UINT128 NPY_ULONG
521
+ typedef long npy_int128;
522
+ typedef unsigned long npy_uint128;
523
+ #define PyInt128ScalarObject PyLongScalarObject
524
+ #define PyInt128ArrType_Type PyLongArrType_Type
525
+ #define PyUInt128ScalarObject PyULongScalarObject
526
+ #define PyUInt128ArrType_Type PyULongArrType_Type
527
+ #define NPY_INT128_FMT NPY_LONG_FMT
528
+ #define NPY_UINT128_FMT NPY_ULONG_FMT
529
+ #endif
530
+
531
+ #if NPY_BITSOF_LONGLONG == 8
532
+ # ifndef NPY_INT8
533
+ # define NPY_INT8 NPY_LONGLONG
534
+ # define NPY_UINT8 NPY_ULONGLONG
535
+ typedef npy_longlong npy_int8;
536
+ typedef npy_ulonglong npy_uint8;
537
+ # define PyInt8ScalarObject PyLongLongScalarObject
538
+ # define PyInt8ArrType_Type PyLongLongArrType_Type
539
+ # define PyUInt8ScalarObject PyULongLongScalarObject
540
+ # define PyUInt8ArrType_Type PyULongLongArrType_Type
541
+ #define NPY_INT8_FMT NPY_LONGLONG_FMT
542
+ #define NPY_UINT8_FMT NPY_ULONGLONG_FMT
543
+ # endif
544
+ # define NPY_MAX_LONGLONG NPY_MAX_INT8
545
+ # define NPY_MIN_LONGLONG NPY_MIN_INT8
546
+ # define NPY_MAX_ULONGLONG NPY_MAX_UINT8
547
+ #elif NPY_BITSOF_LONGLONG == 16
548
+ # ifndef NPY_INT16
549
+ # define NPY_INT16 NPY_LONGLONG
550
+ # define NPY_UINT16 NPY_ULONGLONG
551
+ typedef npy_longlong npy_int16;
552
+ typedef npy_ulonglong npy_uint16;
553
+ # define PyInt16ScalarObject PyLongLongScalarObject
554
+ # define PyInt16ArrType_Type PyLongLongArrType_Type
555
+ # define PyUInt16ScalarObject PyULongLongScalarObject
556
+ # define PyUInt16ArrType_Type PyULongLongArrType_Type
557
+ #define NPY_INT16_FMT NPY_LONGLONG_FMT
558
+ #define NPY_UINT16_FMT NPY_ULONGLONG_FMT
559
+ # endif
560
+ # define NPY_MAX_LONGLONG NPY_MAX_INT16
561
+ # define NPY_MIN_LONGLONG NPY_MIN_INT16
562
+ # define NPY_MAX_ULONGLONG NPY_MAX_UINT16
563
+ #elif NPY_BITSOF_LONGLONG == 32
564
+ # ifndef NPY_INT32
565
+ # define NPY_INT32 NPY_LONGLONG
566
+ # define NPY_UINT32 NPY_ULONGLONG
567
+ typedef npy_longlong npy_int32;
568
+ typedef npy_ulonglong npy_uint32;
569
+ typedef npy_ulonglong npy_ucs4;
570
+ # define PyInt32ScalarObject PyLongLongScalarObject
571
+ # define PyInt32ArrType_Type PyLongLongArrType_Type
572
+ # define PyUInt32ScalarObject PyULongLongScalarObject
573
+ # define PyUInt32ArrType_Type PyULongLongArrType_Type
574
+ #define NPY_INT32_FMT NPY_LONGLONG_FMT
575
+ #define NPY_UINT32_FMT NPY_ULONGLONG_FMT
576
+ # endif
577
+ # define NPY_MAX_LONGLONG NPY_MAX_INT32
578
+ # define NPY_MIN_LONGLONG NPY_MIN_INT32
579
+ # define NPY_MAX_ULONGLONG NPY_MAX_UINT32
580
+ #elif NPY_BITSOF_LONGLONG == 64
581
+ # ifndef NPY_INT64
582
+ # define NPY_INT64 NPY_LONGLONG
583
+ # define NPY_UINT64 NPY_ULONGLONG
584
+ typedef npy_longlong npy_int64;
585
+ typedef npy_ulonglong npy_uint64;
586
+ # define PyInt64ScalarObject PyLongLongScalarObject
587
+ # define PyInt64ArrType_Type PyLongLongArrType_Type
588
+ # define PyUInt64ScalarObject PyULongLongScalarObject
589
+ # define PyUInt64ArrType_Type PyULongLongArrType_Type
590
+ #define NPY_INT64_FMT NPY_LONGLONG_FMT
591
+ #define NPY_UINT64_FMT NPY_ULONGLONG_FMT
592
+ # define MyPyLong_FromInt64 PyLong_FromLongLong
593
+ # define MyPyLong_AsInt64 PyLong_AsLongLong
594
+ # endif
595
+ # define NPY_MAX_LONGLONG NPY_MAX_INT64
596
+ # define NPY_MIN_LONGLONG NPY_MIN_INT64
597
+ # define NPY_MAX_ULONGLONG NPY_MAX_UINT64
598
+ #elif NPY_BITSOF_LONGLONG == 128
599
+ # ifndef NPY_INT128
600
+ # define NPY_INT128 NPY_LONGLONG
601
+ # define NPY_UINT128 NPY_ULONGLONG
602
+ typedef npy_longlong npy_int128;
603
+ typedef npy_ulonglong npy_uint128;
604
+ # define PyInt128ScalarObject PyLongLongScalarObject
605
+ # define PyInt128ArrType_Type PyLongLongArrType_Type
606
+ # define PyUInt128ScalarObject PyULongLongScalarObject
607
+ # define PyUInt128ArrType_Type PyULongLongArrType_Type
608
+ #define NPY_INT128_FMT NPY_LONGLONG_FMT
609
+ #define NPY_UINT128_FMT NPY_ULONGLONG_FMT
610
+ # endif
611
+ # define NPY_MAX_LONGLONG NPY_MAX_INT128
612
+ # define NPY_MIN_LONGLONG NPY_MIN_INT128
613
+ # define NPY_MAX_ULONGLONG NPY_MAX_UINT128
614
+ #elif NPY_BITSOF_LONGLONG == 256
615
+ # define NPY_INT256 NPY_LONGLONG
616
+ # define NPY_UINT256 NPY_ULONGLONG
617
+ typedef npy_longlong npy_int256;
618
+ typedef npy_ulonglong npy_uint256;
619
+ # define PyInt256ScalarObject PyLongLongScalarObject
620
+ # define PyInt256ArrType_Type PyLongLongArrType_Type
621
+ # define PyUInt256ScalarObject PyULongLongScalarObject
622
+ # define PyUInt256ArrType_Type PyULongLongArrType_Type
623
+ #define NPY_INT256_FMT NPY_LONGLONG_FMT
624
+ #define NPY_UINT256_FMT NPY_ULONGLONG_FMT
625
+ # define NPY_MAX_LONGLONG NPY_MAX_INT256
626
+ # define NPY_MIN_LONGLONG NPY_MIN_INT256
627
+ # define NPY_MAX_ULONGLONG NPY_MAX_UINT256
628
+ #endif
629
+
630
+ #if NPY_BITSOF_INT == 8
631
+ #ifndef NPY_INT8
632
+ #define NPY_INT8 NPY_INT
633
+ #define NPY_UINT8 NPY_UINT
634
+ typedef int npy_int8;
635
+ typedef unsigned int npy_uint8;
636
+ # define PyInt8ScalarObject PyIntScalarObject
637
+ # define PyInt8ArrType_Type PyIntArrType_Type
638
+ # define PyUInt8ScalarObject PyUIntScalarObject
639
+ # define PyUInt8ArrType_Type PyUIntArrType_Type
640
+ #define NPY_INT8_FMT NPY_INT_FMT
641
+ #define NPY_UINT8_FMT NPY_UINT_FMT
642
+ #endif
643
+ #elif NPY_BITSOF_INT == 16
644
+ #ifndef NPY_INT16
645
+ #define NPY_INT16 NPY_INT
646
+ #define NPY_UINT16 NPY_UINT
647
+ typedef int npy_int16;
648
+ typedef unsigned int npy_uint16;
649
+ # define PyInt16ScalarObject PyIntScalarObject
650
+ # define PyInt16ArrType_Type PyIntArrType_Type
651
+ # define PyUInt16ScalarObject PyIntUScalarObject
652
+ # define PyUInt16ArrType_Type PyIntUArrType_Type
653
+ #define NPY_INT16_FMT NPY_INT_FMT
654
+ #define NPY_UINT16_FMT NPY_UINT_FMT
655
+ #endif
656
+ #elif NPY_BITSOF_INT == 32
657
+ #ifndef NPY_INT32
658
+ #define NPY_INT32 NPY_INT
659
+ #define NPY_UINT32 NPY_UINT
660
+ typedef int npy_int32;
661
+ typedef unsigned int npy_uint32;
662
+ typedef unsigned int npy_ucs4;
663
+ # define PyInt32ScalarObject PyIntScalarObject
664
+ # define PyInt32ArrType_Type PyIntArrType_Type
665
+ # define PyUInt32ScalarObject PyUIntScalarObject
666
+ # define PyUInt32ArrType_Type PyUIntArrType_Type
667
+ #define NPY_INT32_FMT NPY_INT_FMT
668
+ #define NPY_UINT32_FMT NPY_UINT_FMT
669
+ #endif
670
+ #elif NPY_BITSOF_INT == 64
671
+ #ifndef NPY_INT64
672
+ #define NPY_INT64 NPY_INT
673
+ #define NPY_UINT64 NPY_UINT
674
+ typedef int npy_int64;
675
+ typedef unsigned int npy_uint64;
676
+ # define PyInt64ScalarObject PyIntScalarObject
677
+ # define PyInt64ArrType_Type PyIntArrType_Type
678
+ # define PyUInt64ScalarObject PyUIntScalarObject
679
+ # define PyUInt64ArrType_Type PyUIntArrType_Type
680
+ #define NPY_INT64_FMT NPY_INT_FMT
681
+ #define NPY_UINT64_FMT NPY_UINT_FMT
682
+ # define MyPyLong_FromInt64 PyLong_FromLong
683
+ # define MyPyLong_AsInt64 PyLong_AsLong
684
+ #endif
685
+ #elif NPY_BITSOF_INT == 128
686
+ #ifndef NPY_INT128
687
+ #define NPY_INT128 NPY_INT
688
+ #define NPY_UINT128 NPY_UINT
689
+ typedef int npy_int128;
690
+ typedef unsigned int npy_uint128;
691
+ # define PyInt128ScalarObject PyIntScalarObject
692
+ # define PyInt128ArrType_Type PyIntArrType_Type
693
+ # define PyUInt128ScalarObject PyUIntScalarObject
694
+ # define PyUInt128ArrType_Type PyUIntArrType_Type
695
+ #define NPY_INT128_FMT NPY_INT_FMT
696
+ #define NPY_UINT128_FMT NPY_UINT_FMT
697
+ #endif
698
+ #endif
699
+
700
+ #if NPY_BITSOF_SHORT == 8
701
+ #ifndef NPY_INT8
702
+ #define NPY_INT8 NPY_SHORT
703
+ #define NPY_UINT8 NPY_USHORT
704
+ typedef short npy_int8;
705
+ typedef unsigned short npy_uint8;
706
+ # define PyInt8ScalarObject PyShortScalarObject
707
+ # define PyInt8ArrType_Type PyShortArrType_Type
708
+ # define PyUInt8ScalarObject PyUShortScalarObject
709
+ # define PyUInt8ArrType_Type PyUShortArrType_Type
710
+ #define NPY_INT8_FMT NPY_SHORT_FMT
711
+ #define NPY_UINT8_FMT NPY_USHORT_FMT
712
+ #endif
713
+ #elif NPY_BITSOF_SHORT == 16
714
+ #ifndef NPY_INT16
715
+ #define NPY_INT16 NPY_SHORT
716
+ #define NPY_UINT16 NPY_USHORT
717
+ typedef short npy_int16;
718
+ typedef unsigned short npy_uint16;
719
+ # define PyInt16ScalarObject PyShortScalarObject
720
+ # define PyInt16ArrType_Type PyShortArrType_Type
721
+ # define PyUInt16ScalarObject PyUShortScalarObject
722
+ # define PyUInt16ArrType_Type PyUShortArrType_Type
723
+ #define NPY_INT16_FMT NPY_SHORT_FMT
724
+ #define NPY_UINT16_FMT NPY_USHORT_FMT
725
+ #endif
726
+ #elif NPY_BITSOF_SHORT == 32
727
+ #ifndef NPY_INT32
728
+ #define NPY_INT32 NPY_SHORT
729
+ #define NPY_UINT32 NPY_USHORT
730
+ typedef short npy_int32;
731
+ typedef unsigned short npy_uint32;
732
+ typedef unsigned short npy_ucs4;
733
+ # define PyInt32ScalarObject PyShortScalarObject
734
+ # define PyInt32ArrType_Type PyShortArrType_Type
735
+ # define PyUInt32ScalarObject PyUShortScalarObject
736
+ # define PyUInt32ArrType_Type PyUShortArrType_Type
737
+ #define NPY_INT32_FMT NPY_SHORT_FMT
738
+ #define NPY_UINT32_FMT NPY_USHORT_FMT
739
+ #endif
740
+ #elif NPY_BITSOF_SHORT == 64
741
+ #ifndef NPY_INT64
742
+ #define NPY_INT64 NPY_SHORT
743
+ #define NPY_UINT64 NPY_USHORT
744
+ typedef short npy_int64;
745
+ typedef unsigned short npy_uint64;
746
+ # define PyInt64ScalarObject PyShortScalarObject
747
+ # define PyInt64ArrType_Type PyShortArrType_Type
748
+ # define PyUInt64ScalarObject PyUShortScalarObject
749
+ # define PyUInt64ArrType_Type PyUShortArrType_Type
750
+ #define NPY_INT64_FMT NPY_SHORT_FMT
751
+ #define NPY_UINT64_FMT NPY_USHORT_FMT
752
+ # define MyPyLong_FromInt64 PyLong_FromLong
753
+ # define MyPyLong_AsInt64 PyLong_AsLong
754
+ #endif
755
+ #elif NPY_BITSOF_SHORT == 128
756
+ #ifndef NPY_INT128
757
+ #define NPY_INT128 NPY_SHORT
758
+ #define NPY_UINT128 NPY_USHORT
759
+ typedef short npy_int128;
760
+ typedef unsigned short npy_uint128;
761
+ # define PyInt128ScalarObject PyShortScalarObject
762
+ # define PyInt128ArrType_Type PyShortArrType_Type
763
+ # define PyUInt128ScalarObject PyUShortScalarObject
764
+ # define PyUInt128ArrType_Type PyUShortArrType_Type
765
+ #define NPY_INT128_FMT NPY_SHORT_FMT
766
+ #define NPY_UINT128_FMT NPY_USHORT_FMT
767
+ #endif
768
+ #endif
769
+
770
+
771
+ #if NPY_BITSOF_CHAR == 8
772
+ #ifndef NPY_INT8
773
+ #define NPY_INT8 NPY_BYTE
774
+ #define NPY_UINT8 NPY_UBYTE
775
+ typedef signed char npy_int8;
776
+ typedef unsigned char npy_uint8;
777
+ # define PyInt8ScalarObject PyByteScalarObject
778
+ # define PyInt8ArrType_Type PyByteArrType_Type
779
+ # define PyUInt8ScalarObject PyUByteScalarObject
780
+ # define PyUInt8ArrType_Type PyUByteArrType_Type
781
+ #define NPY_INT8_FMT NPY_BYTE_FMT
782
+ #define NPY_UINT8_FMT NPY_UBYTE_FMT
783
+ #endif
784
+ #elif NPY_BITSOF_CHAR == 16
785
+ #ifndef NPY_INT16
786
+ #define NPY_INT16 NPY_BYTE
787
+ #define NPY_UINT16 NPY_UBYTE
788
+ typedef signed char npy_int16;
789
+ typedef unsigned char npy_uint16;
790
+ # define PyInt16ScalarObject PyByteScalarObject
791
+ # define PyInt16ArrType_Type PyByteArrType_Type
792
+ # define PyUInt16ScalarObject PyUByteScalarObject
793
+ # define PyUInt16ArrType_Type PyUByteArrType_Type
794
+ #define NPY_INT16_FMT NPY_BYTE_FMT
795
+ #define NPY_UINT16_FMT NPY_UBYTE_FMT
796
+ #endif
797
+ #elif NPY_BITSOF_CHAR == 32
798
+ #ifndef NPY_INT32
799
+ #define NPY_INT32 NPY_BYTE
800
+ #define NPY_UINT32 NPY_UBYTE
801
+ typedef signed char npy_int32;
802
+ typedef unsigned char npy_uint32;
803
+ typedef unsigned char npy_ucs4;
804
+ # define PyInt32ScalarObject PyByteScalarObject
805
+ # define PyInt32ArrType_Type PyByteArrType_Type
806
+ # define PyUInt32ScalarObject PyUByteScalarObject
807
+ # define PyUInt32ArrType_Type PyUByteArrType_Type
808
+ #define NPY_INT32_FMT NPY_BYTE_FMT
809
+ #define NPY_UINT32_FMT NPY_UBYTE_FMT
810
+ #endif
811
+ #elif NPY_BITSOF_CHAR == 64
812
+ #ifndef NPY_INT64
813
+ #define NPY_INT64 NPY_BYTE
814
+ #define NPY_UINT64 NPY_UBYTE
815
+ typedef signed char npy_int64;
816
+ typedef unsigned char npy_uint64;
817
+ # define PyInt64ScalarObject PyByteScalarObject
818
+ # define PyInt64ArrType_Type PyByteArrType_Type
819
+ # define PyUInt64ScalarObject PyUByteScalarObject
820
+ # define PyUInt64ArrType_Type PyUByteArrType_Type
821
+ #define NPY_INT64_FMT NPY_BYTE_FMT
822
+ #define NPY_UINT64_FMT NPY_UBYTE_FMT
823
+ # define MyPyLong_FromInt64 PyLong_FromLong
824
+ # define MyPyLong_AsInt64 PyLong_AsLong
825
+ #endif
826
+ #elif NPY_BITSOF_CHAR == 128
827
+ #ifndef NPY_INT128
828
+ #define NPY_INT128 NPY_BYTE
829
+ #define NPY_UINT128 NPY_UBYTE
830
+ typedef signed char npy_int128;
831
+ typedef unsigned char npy_uint128;
832
+ # define PyInt128ScalarObject PyByteScalarObject
833
+ # define PyInt128ArrType_Type PyByteArrType_Type
834
+ # define PyUInt128ScalarObject PyUByteScalarObject
835
+ # define PyUInt128ArrType_Type PyUByteArrType_Type
836
+ #define NPY_INT128_FMT NPY_BYTE_FMT
837
+ #define NPY_UINT128_FMT NPY_UBYTE_FMT
838
+ #endif
839
+ #endif
840
+
841
+
842
+
843
+ #if NPY_BITSOF_DOUBLE == 32
844
+ #ifndef NPY_FLOAT32
845
+ #define NPY_FLOAT32 NPY_DOUBLE
846
+ #define NPY_COMPLEX64 NPY_CDOUBLE
847
+ typedef double npy_float32;
848
+ typedef npy_cdouble npy_complex64;
849
+ # define PyFloat32ScalarObject PyDoubleScalarObject
850
+ # define PyComplex64ScalarObject PyCDoubleScalarObject
851
+ # define PyFloat32ArrType_Type PyDoubleArrType_Type
852
+ # define PyComplex64ArrType_Type PyCDoubleArrType_Type
853
+ #define NPY_FLOAT32_FMT NPY_DOUBLE_FMT
854
+ #define NPY_COMPLEX64_FMT NPY_CDOUBLE_FMT
855
+ #endif
856
+ #elif NPY_BITSOF_DOUBLE == 64
857
+ #ifndef NPY_FLOAT64
858
+ #define NPY_FLOAT64 NPY_DOUBLE
859
+ #define NPY_COMPLEX128 NPY_CDOUBLE
860
+ typedef double npy_float64;
861
+ typedef npy_cdouble npy_complex128;
862
+ # define PyFloat64ScalarObject PyDoubleScalarObject
863
+ # define PyComplex128ScalarObject PyCDoubleScalarObject
864
+ # define PyFloat64ArrType_Type PyDoubleArrType_Type
865
+ # define PyComplex128ArrType_Type PyCDoubleArrType_Type
866
+ #define NPY_FLOAT64_FMT NPY_DOUBLE_FMT
867
+ #define NPY_COMPLEX128_FMT NPY_CDOUBLE_FMT
868
+ #endif
869
+ #elif NPY_BITSOF_DOUBLE == 80
870
+ #ifndef NPY_FLOAT80
871
+ #define NPY_FLOAT80 NPY_DOUBLE
872
+ #define NPY_COMPLEX160 NPY_CDOUBLE
873
+ typedef double npy_float80;
874
+ typedef npy_cdouble npy_complex160;
875
+ # define PyFloat80ScalarObject PyDoubleScalarObject
876
+ # define PyComplex160ScalarObject PyCDoubleScalarObject
877
+ # define PyFloat80ArrType_Type PyDoubleArrType_Type
878
+ # define PyComplex160ArrType_Type PyCDoubleArrType_Type
879
+ #define NPY_FLOAT80_FMT NPY_DOUBLE_FMT
880
+ #define NPY_COMPLEX160_FMT NPY_CDOUBLE_FMT
881
+ #endif
882
+ #elif NPY_BITSOF_DOUBLE == 96
883
+ #ifndef NPY_FLOAT96
884
+ #define NPY_FLOAT96 NPY_DOUBLE
885
+ #define NPY_COMPLEX192 NPY_CDOUBLE
886
+ typedef double npy_float96;
887
+ typedef npy_cdouble npy_complex192;
888
+ # define PyFloat96ScalarObject PyDoubleScalarObject
889
+ # define PyComplex192ScalarObject PyCDoubleScalarObject
890
+ # define PyFloat96ArrType_Type PyDoubleArrType_Type
891
+ # define PyComplex192ArrType_Type PyCDoubleArrType_Type
892
+ #define NPY_FLOAT96_FMT NPY_DOUBLE_FMT
893
+ #define NPY_COMPLEX192_FMT NPY_CDOUBLE_FMT
894
+ #endif
895
+ #elif NPY_BITSOF_DOUBLE == 128
896
+ #ifndef NPY_FLOAT128
897
+ #define NPY_FLOAT128 NPY_DOUBLE
898
+ #define NPY_COMPLEX256 NPY_CDOUBLE
899
+ typedef double npy_float128;
900
+ typedef npy_cdouble npy_complex256;
901
+ # define PyFloat128ScalarObject PyDoubleScalarObject
902
+ # define PyComplex256ScalarObject PyCDoubleScalarObject
903
+ # define PyFloat128ArrType_Type PyDoubleArrType_Type
904
+ # define PyComplex256ArrType_Type PyCDoubleArrType_Type
905
+ #define NPY_FLOAT128_FMT NPY_DOUBLE_FMT
906
+ #define NPY_COMPLEX256_FMT NPY_CDOUBLE_FMT
907
+ #endif
908
+ #endif
909
+
910
+
911
+
912
+ #if NPY_BITSOF_FLOAT == 32
913
+ #ifndef NPY_FLOAT32
914
+ #define NPY_FLOAT32 NPY_FLOAT
915
+ #define NPY_COMPLEX64 NPY_CFLOAT
916
+ typedef float npy_float32;
917
+ typedef npy_cfloat npy_complex64;
918
+ # define PyFloat32ScalarObject PyFloatScalarObject
919
+ # define PyComplex64ScalarObject PyCFloatScalarObject
920
+ # define PyFloat32ArrType_Type PyFloatArrType_Type
921
+ # define PyComplex64ArrType_Type PyCFloatArrType_Type
922
+ #define NPY_FLOAT32_FMT NPY_FLOAT_FMT
923
+ #define NPY_COMPLEX64_FMT NPY_CFLOAT_FMT
924
+ #endif
925
+ #elif NPY_BITSOF_FLOAT == 64
926
+ #ifndef NPY_FLOAT64
927
+ #define NPY_FLOAT64 NPY_FLOAT
928
+ #define NPY_COMPLEX128 NPY_CFLOAT
929
+ typedef float npy_float64;
930
+ typedef npy_cfloat npy_complex128;
931
+ # define PyFloat64ScalarObject PyFloatScalarObject
932
+ # define PyComplex128ScalarObject PyCFloatScalarObject
933
+ # define PyFloat64ArrType_Type PyFloatArrType_Type
934
+ # define PyComplex128ArrType_Type PyCFloatArrType_Type
935
+ #define NPY_FLOAT64_FMT NPY_FLOAT_FMT
936
+ #define NPY_COMPLEX128_FMT NPY_CFLOAT_FMT
937
+ #endif
938
+ #elif NPY_BITSOF_FLOAT == 80
939
+ #ifndef NPY_FLOAT80
940
+ #define NPY_FLOAT80 NPY_FLOAT
941
+ #define NPY_COMPLEX160 NPY_CFLOAT
942
+ typedef float npy_float80;
943
+ typedef npy_cfloat npy_complex160;
944
+ # define PyFloat80ScalarObject PyFloatScalarObject
945
+ # define PyComplex160ScalarObject PyCFloatScalarObject
946
+ # define PyFloat80ArrType_Type PyFloatArrType_Type
947
+ # define PyComplex160ArrType_Type PyCFloatArrType_Type
948
+ #define NPY_FLOAT80_FMT NPY_FLOAT_FMT
949
+ #define NPY_COMPLEX160_FMT NPY_CFLOAT_FMT
950
+ #endif
951
+ #elif NPY_BITSOF_FLOAT == 96
952
+ #ifndef NPY_FLOAT96
953
+ #define NPY_FLOAT96 NPY_FLOAT
954
+ #define NPY_COMPLEX192 NPY_CFLOAT
955
+ typedef float npy_float96;
956
+ typedef npy_cfloat npy_complex192;
957
+ # define PyFloat96ScalarObject PyFloatScalarObject
958
+ # define PyComplex192ScalarObject PyCFloatScalarObject
959
+ # define PyFloat96ArrType_Type PyFloatArrType_Type
960
+ # define PyComplex192ArrType_Type PyCFloatArrType_Type
961
+ #define NPY_FLOAT96_FMT NPY_FLOAT_FMT
962
+ #define NPY_COMPLEX192_FMT NPY_CFLOAT_FMT
963
+ #endif
964
+ #elif NPY_BITSOF_FLOAT == 128
965
+ #ifndef NPY_FLOAT128
966
+ #define NPY_FLOAT128 NPY_FLOAT
967
+ #define NPY_COMPLEX256 NPY_CFLOAT
968
+ typedef float npy_float128;
969
+ typedef npy_cfloat npy_complex256;
970
+ # define PyFloat128ScalarObject PyFloatScalarObject
971
+ # define PyComplex256ScalarObject PyCFloatScalarObject
972
+ # define PyFloat128ArrType_Type PyFloatArrType_Type
973
+ # define PyComplex256ArrType_Type PyCFloatArrType_Type
974
+ #define NPY_FLOAT128_FMT NPY_FLOAT_FMT
975
+ #define NPY_COMPLEX256_FMT NPY_CFLOAT_FMT
976
+ #endif
977
+ #endif
978
+
979
+ /* half/float16 isn't a floating-point type in C */
980
+ #define NPY_FLOAT16 NPY_HALF
981
+ typedef npy_uint16 npy_half;
982
+ typedef npy_half npy_float16;
983
+
984
+ #if NPY_BITSOF_LONGDOUBLE == 32
985
+ #ifndef NPY_FLOAT32
986
+ #define NPY_FLOAT32 NPY_LONGDOUBLE
987
+ #define NPY_COMPLEX64 NPY_CLONGDOUBLE
988
+ typedef npy_longdouble npy_float32;
989
+ typedef npy_clongdouble npy_complex64;
990
+ # define PyFloat32ScalarObject PyLongDoubleScalarObject
991
+ # define PyComplex64ScalarObject PyCLongDoubleScalarObject
992
+ # define PyFloat32ArrType_Type PyLongDoubleArrType_Type
993
+ # define PyComplex64ArrType_Type PyCLongDoubleArrType_Type
994
+ #define NPY_FLOAT32_FMT NPY_LONGDOUBLE_FMT
995
+ #define NPY_COMPLEX64_FMT NPY_CLONGDOUBLE_FMT
996
+ #endif
997
+ #elif NPY_BITSOF_LONGDOUBLE == 64
998
+ #ifndef NPY_FLOAT64
999
+ #define NPY_FLOAT64 NPY_LONGDOUBLE
1000
+ #define NPY_COMPLEX128 NPY_CLONGDOUBLE
1001
+ typedef npy_longdouble npy_float64;
1002
+ typedef npy_clongdouble npy_complex128;
1003
+ # define PyFloat64ScalarObject PyLongDoubleScalarObject
1004
+ # define PyComplex128ScalarObject PyCLongDoubleScalarObject
1005
+ # define PyFloat64ArrType_Type PyLongDoubleArrType_Type
1006
+ # define PyComplex128ArrType_Type PyCLongDoubleArrType_Type
1007
+ #define NPY_FLOAT64_FMT NPY_LONGDOUBLE_FMT
1008
+ #define NPY_COMPLEX128_FMT NPY_CLONGDOUBLE_FMT
1009
+ #endif
1010
+ #elif NPY_BITSOF_LONGDOUBLE == 80
1011
+ #ifndef NPY_FLOAT80
1012
+ #define NPY_FLOAT80 NPY_LONGDOUBLE
1013
+ #define NPY_COMPLEX160 NPY_CLONGDOUBLE
1014
+ typedef npy_longdouble npy_float80;
1015
+ typedef npy_clongdouble npy_complex160;
1016
+ # define PyFloat80ScalarObject PyLongDoubleScalarObject
1017
+ # define PyComplex160ScalarObject PyCLongDoubleScalarObject
1018
+ # define PyFloat80ArrType_Type PyLongDoubleArrType_Type
1019
+ # define PyComplex160ArrType_Type PyCLongDoubleArrType_Type
1020
+ #define NPY_FLOAT80_FMT NPY_LONGDOUBLE_FMT
1021
+ #define NPY_COMPLEX160_FMT NPY_CLONGDOUBLE_FMT
1022
+ #endif
1023
+ #elif NPY_BITSOF_LONGDOUBLE == 96
1024
+ #ifndef NPY_FLOAT96
1025
+ #define NPY_FLOAT96 NPY_LONGDOUBLE
1026
+ #define NPY_COMPLEX192 NPY_CLONGDOUBLE
1027
+ typedef npy_longdouble npy_float96;
1028
+ typedef npy_clongdouble npy_complex192;
1029
+ # define PyFloat96ScalarObject PyLongDoubleScalarObject
1030
+ # define PyComplex192ScalarObject PyCLongDoubleScalarObject
1031
+ # define PyFloat96ArrType_Type PyLongDoubleArrType_Type
1032
+ # define PyComplex192ArrType_Type PyCLongDoubleArrType_Type
1033
+ #define NPY_FLOAT96_FMT NPY_LONGDOUBLE_FMT
1034
+ #define NPY_COMPLEX192_FMT NPY_CLONGDOUBLE_FMT
1035
+ #endif
1036
+ #elif NPY_BITSOF_LONGDOUBLE == 128
1037
+ #ifndef NPY_FLOAT128
1038
+ #define NPY_FLOAT128 NPY_LONGDOUBLE
1039
+ #define NPY_COMPLEX256 NPY_CLONGDOUBLE
1040
+ typedef npy_longdouble npy_float128;
1041
+ typedef npy_clongdouble npy_complex256;
1042
+ # define PyFloat128ScalarObject PyLongDoubleScalarObject
1043
+ # define PyComplex256ScalarObject PyCLongDoubleScalarObject
1044
+ # define PyFloat128ArrType_Type PyLongDoubleArrType_Type
1045
+ # define PyComplex256ArrType_Type PyCLongDoubleArrType_Type
1046
+ #define NPY_FLOAT128_FMT NPY_LONGDOUBLE_FMT
1047
+ #define NPY_COMPLEX256_FMT NPY_CLONGDOUBLE_FMT
1048
+ #endif
1049
+ #elif NPY_BITSOF_LONGDOUBLE == 256
1050
+ #define NPY_FLOAT256 NPY_LONGDOUBLE
1051
+ #define NPY_COMPLEX512 NPY_CLONGDOUBLE
1052
+ typedef npy_longdouble npy_float256;
1053
+ typedef npy_clongdouble npy_complex512;
1054
+ # define PyFloat256ScalarObject PyLongDoubleScalarObject
1055
+ # define PyComplex512ScalarObject PyCLongDoubleScalarObject
1056
+ # define PyFloat256ArrType_Type PyLongDoubleArrType_Type
1057
+ # define PyComplex512ArrType_Type PyCLongDoubleArrType_Type
1058
+ #define NPY_FLOAT256_FMT NPY_LONGDOUBLE_FMT
1059
+ #define NPY_COMPLEX512_FMT NPY_CLONGDOUBLE_FMT
1060
+ #endif
1061
+
1062
+ /* datetime typedefs */
1063
+ typedef npy_int64 npy_timedelta;
1064
+ typedef npy_int64 npy_datetime;
1065
+ #define NPY_DATETIME_FMT NPY_INT64_FMT
1066
+ #define NPY_TIMEDELTA_FMT NPY_INT64_FMT
1067
+
1068
+ /* End of typedefs for numarray style bit-width names */
1069
+
1070
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_COMMON_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_cpu.h ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * This set (target) cpu specific macros:
3
+ * - Possible values:
4
+ * NPY_CPU_X86
5
+ * NPY_CPU_AMD64
6
+ * NPY_CPU_PPC
7
+ * NPY_CPU_PPC64
8
+ * NPY_CPU_PPC64LE
9
+ * NPY_CPU_SPARC
10
+ * NPY_CPU_S390
11
+ * NPY_CPU_IA64
12
+ * NPY_CPU_HPPA
13
+ * NPY_CPU_ALPHA
14
+ * NPY_CPU_ARMEL
15
+ * NPY_CPU_ARMEB
16
+ * NPY_CPU_SH_LE
17
+ * NPY_CPU_SH_BE
18
+ * NPY_CPU_ARCEL
19
+ * NPY_CPU_ARCEB
20
+ * NPY_CPU_RISCV64
21
+ * NPY_CPU_LOONGARCH
22
+ * NPY_CPU_WASM
23
+ */
24
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_CPU_H_
25
+ #define NUMPY_CORE_INCLUDE_NUMPY_NPY_CPU_H_
26
+
27
+ #include "numpyconfig.h"
28
+
29
+ #if defined( __i386__ ) || defined(i386) || defined(_M_IX86)
30
+ /*
31
+ * __i386__ is defined by gcc and Intel compiler on Linux,
32
+ * _M_IX86 by VS compiler,
33
+ * i386 by Sun compilers on opensolaris at least
34
+ */
35
+ #define NPY_CPU_X86
36
+ #elif defined(__x86_64__) || defined(__amd64__) || defined(__x86_64) || defined(_M_AMD64)
37
+ /*
38
+ * both __x86_64__ and __amd64__ are defined by gcc
39
+ * __x86_64 defined by sun compiler on opensolaris at least
40
+ * _M_AMD64 defined by MS compiler
41
+ */
42
+ #define NPY_CPU_AMD64
43
+ #elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)
44
+ #define NPY_CPU_PPC64LE
45
+ #elif defined(__powerpc64__) && defined(__BIG_ENDIAN__)
46
+ #define NPY_CPU_PPC64
47
+ #elif defined(__ppc__) || defined(__powerpc__) || defined(_ARCH_PPC)
48
+ /*
49
+ * __ppc__ is defined by gcc, I remember having seen __powerpc__ once,
50
+ * but can't find it ATM
51
+ * _ARCH_PPC is used by at least gcc on AIX
52
+ * As __powerpc__ and _ARCH_PPC are also defined by PPC64 check
53
+ * for those specifically first before defaulting to ppc
54
+ */
55
+ #define NPY_CPU_PPC
56
+ #elif defined(__sparc__) || defined(__sparc)
57
+ /* __sparc__ is defined by gcc and Forte (e.g. Sun) compilers */
58
+ #define NPY_CPU_SPARC
59
+ #elif defined(__s390__)
60
+ #define NPY_CPU_S390
61
+ #elif defined(__ia64)
62
+ #define NPY_CPU_IA64
63
+ #elif defined(__hppa)
64
+ #define NPY_CPU_HPPA
65
+ #elif defined(__alpha__)
66
+ #define NPY_CPU_ALPHA
67
+ #elif defined(__arm__) || defined(__aarch64__) || defined(_M_ARM64)
68
+ /* _M_ARM64 is defined in MSVC for ARM64 compilation on Windows */
69
+ #if defined(__ARMEB__) || defined(__AARCH64EB__)
70
+ #if defined(__ARM_32BIT_STATE)
71
+ #define NPY_CPU_ARMEB_AARCH32
72
+ #elif defined(__ARM_64BIT_STATE)
73
+ #define NPY_CPU_ARMEB_AARCH64
74
+ #else
75
+ #define NPY_CPU_ARMEB
76
+ #endif
77
+ #elif defined(__ARMEL__) || defined(__AARCH64EL__) || defined(_M_ARM64)
78
+ #if defined(__ARM_32BIT_STATE)
79
+ #define NPY_CPU_ARMEL_AARCH32
80
+ #elif defined(__ARM_64BIT_STATE) || defined(_M_ARM64) || defined(__AARCH64EL__)
81
+ #define NPY_CPU_ARMEL_AARCH64
82
+ #else
83
+ #define NPY_CPU_ARMEL
84
+ #endif
85
+ #else
86
+ # error Unknown ARM CPU, please report this to numpy maintainers with \
87
+ information about your platform (OS, CPU and compiler)
88
+ #endif
89
+ #elif defined(__sh__) && defined(__LITTLE_ENDIAN__)
90
+ #define NPY_CPU_SH_LE
91
+ #elif defined(__sh__) && defined(__BIG_ENDIAN__)
92
+ #define NPY_CPU_SH_BE
93
+ #elif defined(__MIPSEL__)
94
+ #define NPY_CPU_MIPSEL
95
+ #elif defined(__MIPSEB__)
96
+ #define NPY_CPU_MIPSEB
97
+ #elif defined(__or1k__)
98
+ #define NPY_CPU_OR1K
99
+ #elif defined(__mc68000__)
100
+ #define NPY_CPU_M68K
101
+ #elif defined(__arc__) && defined(__LITTLE_ENDIAN__)
102
+ #define NPY_CPU_ARCEL
103
+ #elif defined(__arc__) && defined(__BIG_ENDIAN__)
104
+ #define NPY_CPU_ARCEB
105
+ #elif defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64
106
+ #define NPY_CPU_RISCV64
107
+ #elif defined(__loongarch__)
108
+ #define NPY_CPU_LOONGARCH
109
+ #elif defined(__EMSCRIPTEN__)
110
+ /* __EMSCRIPTEN__ is defined by emscripten: an LLVM-to-Web compiler */
111
+ #define NPY_CPU_WASM
112
+ #else
113
+ #error Unknown CPU, please report this to numpy maintainers with \
114
+ information about your platform (OS, CPU and compiler)
115
+ #endif
116
+
117
+ /*
118
+ * Except for the following architectures, memory access is limited to the natural
119
+ * alignment of data types otherwise it may lead to bus error or performance regression.
120
+ * For more details about unaligned access, see https://www.kernel.org/doc/Documentation/unaligned-memory-access.txt.
121
+ */
122
+ #if defined(NPY_CPU_X86) || defined(NPY_CPU_AMD64) || defined(__aarch64__) || defined(__powerpc64__)
123
+ #define NPY_ALIGNMENT_REQUIRED 0
124
+ #endif
125
+ #ifndef NPY_ALIGNMENT_REQUIRED
126
+ #define NPY_ALIGNMENT_REQUIRED 1
127
+ #endif
128
+
129
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_CPU_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_endian.h ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_ENDIAN_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_NPY_ENDIAN_H_
3
+
4
+ /*
5
+ * NPY_BYTE_ORDER is set to the same value as BYTE_ORDER set by glibc in
6
+ * endian.h
7
+ */
8
+
9
+ #if defined(NPY_HAVE_ENDIAN_H) || defined(NPY_HAVE_SYS_ENDIAN_H)
10
+ /* Use endian.h if available */
11
+
12
+ #if defined(NPY_HAVE_ENDIAN_H)
13
+ #include <endian.h>
14
+ #elif defined(NPY_HAVE_SYS_ENDIAN_H)
15
+ #include <sys/endian.h>
16
+ #endif
17
+
18
+ #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
19
+ #define NPY_BYTE_ORDER BYTE_ORDER
20
+ #define NPY_LITTLE_ENDIAN LITTLE_ENDIAN
21
+ #define NPY_BIG_ENDIAN BIG_ENDIAN
22
+ #elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN)
23
+ #define NPY_BYTE_ORDER _BYTE_ORDER
24
+ #define NPY_LITTLE_ENDIAN _LITTLE_ENDIAN
25
+ #define NPY_BIG_ENDIAN _BIG_ENDIAN
26
+ #elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN)
27
+ #define NPY_BYTE_ORDER __BYTE_ORDER
28
+ #define NPY_LITTLE_ENDIAN __LITTLE_ENDIAN
29
+ #define NPY_BIG_ENDIAN __BIG_ENDIAN
30
+ #endif
31
+ #endif
32
+
33
+ #ifndef NPY_BYTE_ORDER
34
+ /* Set endianness info using target CPU */
35
+ #include "npy_cpu.h"
36
+
37
+ #define NPY_LITTLE_ENDIAN 1234
38
+ #define NPY_BIG_ENDIAN 4321
39
+
40
+ #if defined(NPY_CPU_X86) \
41
+ || defined(NPY_CPU_AMD64) \
42
+ || defined(NPY_CPU_IA64) \
43
+ || defined(NPY_CPU_ALPHA) \
44
+ || defined(NPY_CPU_ARMEL) \
45
+ || defined(NPY_CPU_ARMEL_AARCH32) \
46
+ || defined(NPY_CPU_ARMEL_AARCH64) \
47
+ || defined(NPY_CPU_SH_LE) \
48
+ || defined(NPY_CPU_MIPSEL) \
49
+ || defined(NPY_CPU_PPC64LE) \
50
+ || defined(NPY_CPU_ARCEL) \
51
+ || defined(NPY_CPU_RISCV64) \
52
+ || defined(NPY_CPU_LOONGARCH) \
53
+ || defined(NPY_CPU_WASM)
54
+ #define NPY_BYTE_ORDER NPY_LITTLE_ENDIAN
55
+
56
+ #elif defined(NPY_CPU_PPC) \
57
+ || defined(NPY_CPU_SPARC) \
58
+ || defined(NPY_CPU_S390) \
59
+ || defined(NPY_CPU_HPPA) \
60
+ || defined(NPY_CPU_PPC64) \
61
+ || defined(NPY_CPU_ARMEB) \
62
+ || defined(NPY_CPU_ARMEB_AARCH32) \
63
+ || defined(NPY_CPU_ARMEB_AARCH64) \
64
+ || defined(NPY_CPU_SH_BE) \
65
+ || defined(NPY_CPU_MIPSEB) \
66
+ || defined(NPY_CPU_OR1K) \
67
+ || defined(NPY_CPU_M68K) \
68
+ || defined(NPY_CPU_ARCEB)
69
+ #define NPY_BYTE_ORDER NPY_BIG_ENDIAN
70
+
71
+ #else
72
+ #error Unknown CPU: can not set endianness
73
+ #endif
74
+
75
+ #endif
76
+
77
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_ENDIAN_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_math.h ADDED
@@ -0,0 +1,602 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_MATH_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_NPY_MATH_H_
3
+
4
+ #include <numpy/npy_common.h>
5
+
6
+ #include <math.h>
7
+
8
+ /* By adding static inline specifiers to npy_math function definitions when
9
+ appropriate, compiler is given the opportunity to optimize */
10
+ #if NPY_INLINE_MATH
11
+ #define NPY_INPLACE static inline
12
+ #else
13
+ #define NPY_INPLACE
14
+ #endif
15
+
16
+
17
+ #ifdef __cplusplus
18
+ extern "C" {
19
+ #endif
20
+
21
+ #define PyArray_MAX(a,b) (((a)>(b))?(a):(b))
22
+ #define PyArray_MIN(a,b) (((a)<(b))?(a):(b))
23
+
24
+ /*
25
+ * NAN and INFINITY like macros (same behavior as glibc for NAN, same as C99
26
+ * for INFINITY)
27
+ *
28
+ * XXX: I should test whether INFINITY and NAN are available on the platform
29
+ */
30
+ static inline float __npy_inff(void)
31
+ {
32
+ const union { npy_uint32 __i; float __f;} __bint = {0x7f800000UL};
33
+ return __bint.__f;
34
+ }
35
+
36
+ static inline float __npy_nanf(void)
37
+ {
38
+ const union { npy_uint32 __i; float __f;} __bint = {0x7fc00000UL};
39
+ return __bint.__f;
40
+ }
41
+
42
+ static inline float __npy_pzerof(void)
43
+ {
44
+ const union { npy_uint32 __i; float __f;} __bint = {0x00000000UL};
45
+ return __bint.__f;
46
+ }
47
+
48
+ static inline float __npy_nzerof(void)
49
+ {
50
+ const union { npy_uint32 __i; float __f;} __bint = {0x80000000UL};
51
+ return __bint.__f;
52
+ }
53
+
54
+ #define NPY_INFINITYF __npy_inff()
55
+ #define NPY_NANF __npy_nanf()
56
+ #define NPY_PZEROF __npy_pzerof()
57
+ #define NPY_NZEROF __npy_nzerof()
58
+
59
+ #define NPY_INFINITY ((npy_double)NPY_INFINITYF)
60
+ #define NPY_NAN ((npy_double)NPY_NANF)
61
+ #define NPY_PZERO ((npy_double)NPY_PZEROF)
62
+ #define NPY_NZERO ((npy_double)NPY_NZEROF)
63
+
64
+ #define NPY_INFINITYL ((npy_longdouble)NPY_INFINITYF)
65
+ #define NPY_NANL ((npy_longdouble)NPY_NANF)
66
+ #define NPY_PZEROL ((npy_longdouble)NPY_PZEROF)
67
+ #define NPY_NZEROL ((npy_longdouble)NPY_NZEROF)
68
+
69
+ /*
70
+ * Useful constants
71
+ */
72
+ #define NPY_E 2.718281828459045235360287471352662498 /* e */
73
+ #define NPY_LOG2E 1.442695040888963407359924681001892137 /* log_2 e */
74
+ #define NPY_LOG10E 0.434294481903251827651128918916605082 /* log_10 e */
75
+ #define NPY_LOGE2 0.693147180559945309417232121458176568 /* log_e 2 */
76
+ #define NPY_LOGE10 2.302585092994045684017991454684364208 /* log_e 10 */
77
+ #define NPY_PI 3.141592653589793238462643383279502884 /* pi */
78
+ #define NPY_PI_2 1.570796326794896619231321691639751442 /* pi/2 */
79
+ #define NPY_PI_4 0.785398163397448309615660845819875721 /* pi/4 */
80
+ #define NPY_1_PI 0.318309886183790671537767526745028724 /* 1/pi */
81
+ #define NPY_2_PI 0.636619772367581343075535053490057448 /* 2/pi */
82
+ #define NPY_EULER 0.577215664901532860606512090082402431 /* Euler constant */
83
+ #define NPY_SQRT2 1.414213562373095048801688724209698079 /* sqrt(2) */
84
+ #define NPY_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */
85
+
86
+ #define NPY_Ef 2.718281828459045235360287471352662498F /* e */
87
+ #define NPY_LOG2Ef 1.442695040888963407359924681001892137F /* log_2 e */
88
+ #define NPY_LOG10Ef 0.434294481903251827651128918916605082F /* log_10 e */
89
+ #define NPY_LOGE2f 0.693147180559945309417232121458176568F /* log_e 2 */
90
+ #define NPY_LOGE10f 2.302585092994045684017991454684364208F /* log_e 10 */
91
+ #define NPY_PIf 3.141592653589793238462643383279502884F /* pi */
92
+ #define NPY_PI_2f 1.570796326794896619231321691639751442F /* pi/2 */
93
+ #define NPY_PI_4f 0.785398163397448309615660845819875721F /* pi/4 */
94
+ #define NPY_1_PIf 0.318309886183790671537767526745028724F /* 1/pi */
95
+ #define NPY_2_PIf 0.636619772367581343075535053490057448F /* 2/pi */
96
+ #define NPY_EULERf 0.577215664901532860606512090082402431F /* Euler constant */
97
+ #define NPY_SQRT2f 1.414213562373095048801688724209698079F /* sqrt(2) */
98
+ #define NPY_SQRT1_2f 0.707106781186547524400844362104849039F /* 1/sqrt(2) */
99
+
100
+ #define NPY_El 2.718281828459045235360287471352662498L /* e */
101
+ #define NPY_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
102
+ #define NPY_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
103
+ #define NPY_LOGE2l 0.693147180559945309417232121458176568L /* log_e 2 */
104
+ #define NPY_LOGE10l 2.302585092994045684017991454684364208L /* log_e 10 */
105
+ #define NPY_PIl 3.141592653589793238462643383279502884L /* pi */
106
+ #define NPY_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
107
+ #define NPY_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
108
+ #define NPY_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
109
+ #define NPY_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
110
+ #define NPY_EULERl 0.577215664901532860606512090082402431L /* Euler constant */
111
+ #define NPY_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
112
+ #define NPY_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
113
+
114
+ /*
115
+ * Integer functions.
116
+ */
117
+ NPY_INPLACE npy_uint npy_gcdu(npy_uint a, npy_uint b);
118
+ NPY_INPLACE npy_uint npy_lcmu(npy_uint a, npy_uint b);
119
+ NPY_INPLACE npy_ulong npy_gcdul(npy_ulong a, npy_ulong b);
120
+ NPY_INPLACE npy_ulong npy_lcmul(npy_ulong a, npy_ulong b);
121
+ NPY_INPLACE npy_ulonglong npy_gcdull(npy_ulonglong a, npy_ulonglong b);
122
+ NPY_INPLACE npy_ulonglong npy_lcmull(npy_ulonglong a, npy_ulonglong b);
123
+
124
+ NPY_INPLACE npy_int npy_gcd(npy_int a, npy_int b);
125
+ NPY_INPLACE npy_int npy_lcm(npy_int a, npy_int b);
126
+ NPY_INPLACE npy_long npy_gcdl(npy_long a, npy_long b);
127
+ NPY_INPLACE npy_long npy_lcml(npy_long a, npy_long b);
128
+ NPY_INPLACE npy_longlong npy_gcdll(npy_longlong a, npy_longlong b);
129
+ NPY_INPLACE npy_longlong npy_lcmll(npy_longlong a, npy_longlong b);
130
+
131
+ NPY_INPLACE npy_ubyte npy_rshiftuhh(npy_ubyte a, npy_ubyte b);
132
+ NPY_INPLACE npy_ubyte npy_lshiftuhh(npy_ubyte a, npy_ubyte b);
133
+ NPY_INPLACE npy_ushort npy_rshiftuh(npy_ushort a, npy_ushort b);
134
+ NPY_INPLACE npy_ushort npy_lshiftuh(npy_ushort a, npy_ushort b);
135
+ NPY_INPLACE npy_uint npy_rshiftu(npy_uint a, npy_uint b);
136
+ NPY_INPLACE npy_uint npy_lshiftu(npy_uint a, npy_uint b);
137
+ NPY_INPLACE npy_ulong npy_rshiftul(npy_ulong a, npy_ulong b);
138
+ NPY_INPLACE npy_ulong npy_lshiftul(npy_ulong a, npy_ulong b);
139
+ NPY_INPLACE npy_ulonglong npy_rshiftull(npy_ulonglong a, npy_ulonglong b);
140
+ NPY_INPLACE npy_ulonglong npy_lshiftull(npy_ulonglong a, npy_ulonglong b);
141
+
142
+ NPY_INPLACE npy_byte npy_rshifthh(npy_byte a, npy_byte b);
143
+ NPY_INPLACE npy_byte npy_lshifthh(npy_byte a, npy_byte b);
144
+ NPY_INPLACE npy_short npy_rshifth(npy_short a, npy_short b);
145
+ NPY_INPLACE npy_short npy_lshifth(npy_short a, npy_short b);
146
+ NPY_INPLACE npy_int npy_rshift(npy_int a, npy_int b);
147
+ NPY_INPLACE npy_int npy_lshift(npy_int a, npy_int b);
148
+ NPY_INPLACE npy_long npy_rshiftl(npy_long a, npy_long b);
149
+ NPY_INPLACE npy_long npy_lshiftl(npy_long a, npy_long b);
150
+ NPY_INPLACE npy_longlong npy_rshiftll(npy_longlong a, npy_longlong b);
151
+ NPY_INPLACE npy_longlong npy_lshiftll(npy_longlong a, npy_longlong b);
152
+
153
+ NPY_INPLACE uint8_t npy_popcountuhh(npy_ubyte a);
154
+ NPY_INPLACE uint8_t npy_popcountuh(npy_ushort a);
155
+ NPY_INPLACE uint8_t npy_popcountu(npy_uint a);
156
+ NPY_INPLACE uint8_t npy_popcountul(npy_ulong a);
157
+ NPY_INPLACE uint8_t npy_popcountull(npy_ulonglong a);
158
+ NPY_INPLACE uint8_t npy_popcounthh(npy_byte a);
159
+ NPY_INPLACE uint8_t npy_popcounth(npy_short a);
160
+ NPY_INPLACE uint8_t npy_popcount(npy_int a);
161
+ NPY_INPLACE uint8_t npy_popcountl(npy_long a);
162
+ NPY_INPLACE uint8_t npy_popcountll(npy_longlong a);
163
+
164
+ /*
165
+ * C99 double math funcs that need fixups or are blocklist-able
166
+ */
167
+ NPY_INPLACE double npy_sin(double x);
168
+ NPY_INPLACE double npy_cos(double x);
169
+ NPY_INPLACE double npy_tan(double x);
170
+ NPY_INPLACE double npy_hypot(double x, double y);
171
+ NPY_INPLACE double npy_log2(double x);
172
+ NPY_INPLACE double npy_atan2(double x, double y);
173
+
174
+ /* Mandatory C99 double math funcs, no blocklisting or fixups */
175
+ /* defined for legacy reasons, should be deprecated at some point */
176
+ #define npy_sinh sinh
177
+ #define npy_cosh cosh
178
+ #define npy_tanh tanh
179
+ #define npy_asin asin
180
+ #define npy_acos acos
181
+ #define npy_atan atan
182
+ #define npy_log log
183
+ #define npy_log10 log10
184
+ #define npy_cbrt cbrt
185
+ #define npy_fabs fabs
186
+ #define npy_ceil ceil
187
+ #define npy_fmod fmod
188
+ #define npy_floor floor
189
+ #define npy_expm1 expm1
190
+ #define npy_log1p log1p
191
+ #define npy_acosh acosh
192
+ #define npy_asinh asinh
193
+ #define npy_atanh atanh
194
+ #define npy_rint rint
195
+ #define npy_trunc trunc
196
+ #define npy_exp2 exp2
197
+ #define npy_frexp frexp
198
+ #define npy_ldexp ldexp
199
+ #define npy_copysign copysign
200
+ #define npy_exp exp
201
+ #define npy_sqrt sqrt
202
+ #define npy_pow pow
203
+ #define npy_modf modf
204
+ #define npy_nextafter nextafter
205
+
206
+ double npy_spacing(double x);
207
+
208
+ /*
209
+ * IEEE 754 fpu handling
210
+ */
211
+
212
+ /* use builtins to avoid function calls in tight loops
213
+ * only available if npy_config.h is available (= numpys own build) */
214
+ #ifdef HAVE___BUILTIN_ISNAN
215
+ #define npy_isnan(x) __builtin_isnan(x)
216
+ #else
217
+ #define npy_isnan(x) isnan(x)
218
+ #endif
219
+
220
+
221
+ /* only available if npy_config.h is available (= numpys own build) */
222
+ #ifdef HAVE___BUILTIN_ISFINITE
223
+ #define npy_isfinite(x) __builtin_isfinite(x)
224
+ #else
225
+ #define npy_isfinite(x) isfinite((x))
226
+ #endif
227
+
228
+ /* only available if npy_config.h is available (= numpys own build) */
229
+ #ifdef HAVE___BUILTIN_ISINF
230
+ #define npy_isinf(x) __builtin_isinf(x)
231
+ #else
232
+ #define npy_isinf(x) isinf((x))
233
+ #endif
234
+
235
+ #define npy_signbit(x) signbit((x))
236
+
237
+ /*
238
+ * float C99 math funcs that need fixups or are blocklist-able
239
+ */
240
+ NPY_INPLACE float npy_sinf(float x);
241
+ NPY_INPLACE float npy_cosf(float x);
242
+ NPY_INPLACE float npy_tanf(float x);
243
+ NPY_INPLACE float npy_expf(float x);
244
+ NPY_INPLACE float npy_sqrtf(float x);
245
+ NPY_INPLACE float npy_hypotf(float x, float y);
246
+ NPY_INPLACE float npy_log2f(float x);
247
+ NPY_INPLACE float npy_atan2f(float x, float y);
248
+ NPY_INPLACE float npy_powf(float x, float y);
249
+ NPY_INPLACE float npy_modff(float x, float* y);
250
+
251
+ /* Mandatory C99 float math funcs, no blocklisting or fixups */
252
+ /* defined for legacy reasons, should be deprecated at some point */
253
+
254
+ #define npy_sinhf sinhf
255
+ #define npy_coshf coshf
256
+ #define npy_tanhf tanhf
257
+ #define npy_asinf asinf
258
+ #define npy_acosf acosf
259
+ #define npy_atanf atanf
260
+ #define npy_logf logf
261
+ #define npy_log10f log10f
262
+ #define npy_cbrtf cbrtf
263
+ #define npy_fabsf fabsf
264
+ #define npy_ceilf ceilf
265
+ #define npy_fmodf fmodf
266
+ #define npy_floorf floorf
267
+ #define npy_expm1f expm1f
268
+ #define npy_log1pf log1pf
269
+ #define npy_asinhf asinhf
270
+ #define npy_acoshf acoshf
271
+ #define npy_atanhf atanhf
272
+ #define npy_rintf rintf
273
+ #define npy_truncf truncf
274
+ #define npy_exp2f exp2f
275
+ #define npy_frexpf frexpf
276
+ #define npy_ldexpf ldexpf
277
+ #define npy_copysignf copysignf
278
+ #define npy_nextafterf nextafterf
279
+
280
+ float npy_spacingf(float x);
281
+
282
+ /*
283
+ * long double C99 double math funcs that need fixups or are blocklist-able
284
+ */
285
+ NPY_INPLACE npy_longdouble npy_sinl(npy_longdouble x);
286
+ NPY_INPLACE npy_longdouble npy_cosl(npy_longdouble x);
287
+ NPY_INPLACE npy_longdouble npy_tanl(npy_longdouble x);
288
+ NPY_INPLACE npy_longdouble npy_expl(npy_longdouble x);
289
+ NPY_INPLACE npy_longdouble npy_sqrtl(npy_longdouble x);
290
+ NPY_INPLACE npy_longdouble npy_hypotl(npy_longdouble x, npy_longdouble y);
291
+ NPY_INPLACE npy_longdouble npy_log2l(npy_longdouble x);
292
+ NPY_INPLACE npy_longdouble npy_atan2l(npy_longdouble x, npy_longdouble y);
293
+ NPY_INPLACE npy_longdouble npy_powl(npy_longdouble x, npy_longdouble y);
294
+ NPY_INPLACE npy_longdouble npy_modfl(npy_longdouble x, npy_longdouble* y);
295
+
296
+ /* Mandatory C99 double math funcs, no blocklisting or fixups */
297
+ /* defined for legacy reasons, should be deprecated at some point */
298
+ #define npy_sinhl sinhl
299
+ #define npy_coshl coshl
300
+ #define npy_tanhl tanhl
301
+ #define npy_fabsl fabsl
302
+ #define npy_floorl floorl
303
+ #define npy_ceill ceill
304
+ #define npy_rintl rintl
305
+ #define npy_truncl truncl
306
+ #define npy_cbrtl cbrtl
307
+ #define npy_log10l log10l
308
+ #define npy_logl logl
309
+ #define npy_expm1l expm1l
310
+ #define npy_asinl asinl
311
+ #define npy_acosl acosl
312
+ #define npy_atanl atanl
313
+ #define npy_asinhl asinhl
314
+ #define npy_acoshl acoshl
315
+ #define npy_atanhl atanhl
316
+ #define npy_log1pl log1pl
317
+ #define npy_exp2l exp2l
318
+ #define npy_fmodl fmodl
319
+ #define npy_frexpl frexpl
320
+ #define npy_ldexpl ldexpl
321
+ #define npy_copysignl copysignl
322
+ #define npy_nextafterl nextafterl
323
+
324
+ npy_longdouble npy_spacingl(npy_longdouble x);
325
+
326
+ /*
327
+ * Non standard functions
328
+ */
329
+ NPY_INPLACE double npy_deg2rad(double x);
330
+ NPY_INPLACE double npy_rad2deg(double x);
331
+ NPY_INPLACE double npy_logaddexp(double x, double y);
332
+ NPY_INPLACE double npy_logaddexp2(double x, double y);
333
+ NPY_INPLACE double npy_divmod(double x, double y, double *modulus);
334
+ NPY_INPLACE double npy_heaviside(double x, double h0);
335
+
336
+ NPY_INPLACE float npy_deg2radf(float x);
337
+ NPY_INPLACE float npy_rad2degf(float x);
338
+ NPY_INPLACE float npy_logaddexpf(float x, float y);
339
+ NPY_INPLACE float npy_logaddexp2f(float x, float y);
340
+ NPY_INPLACE float npy_divmodf(float x, float y, float *modulus);
341
+ NPY_INPLACE float npy_heavisidef(float x, float h0);
342
+
343
+ NPY_INPLACE npy_longdouble npy_deg2radl(npy_longdouble x);
344
+ NPY_INPLACE npy_longdouble npy_rad2degl(npy_longdouble x);
345
+ NPY_INPLACE npy_longdouble npy_logaddexpl(npy_longdouble x, npy_longdouble y);
346
+ NPY_INPLACE npy_longdouble npy_logaddexp2l(npy_longdouble x, npy_longdouble y);
347
+ NPY_INPLACE npy_longdouble npy_divmodl(npy_longdouble x, npy_longdouble y,
348
+ npy_longdouble *modulus);
349
+ NPY_INPLACE npy_longdouble npy_heavisidel(npy_longdouble x, npy_longdouble h0);
350
+
351
+ #define npy_degrees npy_rad2deg
352
+ #define npy_degreesf npy_rad2degf
353
+ #define npy_degreesl npy_rad2degl
354
+
355
+ #define npy_radians npy_deg2rad
356
+ #define npy_radiansf npy_deg2radf
357
+ #define npy_radiansl npy_deg2radl
358
+
359
+ /*
360
+ * Complex declarations
361
+ */
362
+
363
+ static inline double npy_creal(const npy_cdouble z)
364
+ {
365
+ #if defined(__cplusplus)
366
+ return ((double *) &z)[0];
367
+ #else
368
+ return creal(z);
369
+ #endif
370
+ }
371
+
372
+ static inline void npy_csetreal(npy_cdouble *z, const double r)
373
+ {
374
+ ((double *) z)[0] = r;
375
+ }
376
+
377
+ static inline double npy_cimag(const npy_cdouble z)
378
+ {
379
+ #if defined(__cplusplus)
380
+ return ((double *) &z)[1];
381
+ #else
382
+ return cimag(z);
383
+ #endif
384
+ }
385
+
386
+ static inline void npy_csetimag(npy_cdouble *z, const double i)
387
+ {
388
+ ((double *) z)[1] = i;
389
+ }
390
+
391
+ static inline float npy_crealf(const npy_cfloat z)
392
+ {
393
+ #if defined(__cplusplus)
394
+ return ((float *) &z)[0];
395
+ #else
396
+ return crealf(z);
397
+ #endif
398
+ }
399
+
400
+ static inline void npy_csetrealf(npy_cfloat *z, const float r)
401
+ {
402
+ ((float *) z)[0] = r;
403
+ }
404
+
405
+ static inline float npy_cimagf(const npy_cfloat z)
406
+ {
407
+ #if defined(__cplusplus)
408
+ return ((float *) &z)[1];
409
+ #else
410
+ return cimagf(z);
411
+ #endif
412
+ }
413
+
414
+ static inline void npy_csetimagf(npy_cfloat *z, const float i)
415
+ {
416
+ ((float *) z)[1] = i;
417
+ }
418
+
419
+ static inline npy_longdouble npy_creall(const npy_clongdouble z)
420
+ {
421
+ #if defined(__cplusplus)
422
+ return ((longdouble_t *) &z)[0];
423
+ #else
424
+ return creall(z);
425
+ #endif
426
+ }
427
+
428
+ static inline void npy_csetreall(npy_clongdouble *z, const longdouble_t r)
429
+ {
430
+ ((longdouble_t *) z)[0] = r;
431
+ }
432
+
433
+ static inline npy_longdouble npy_cimagl(const npy_clongdouble z)
434
+ {
435
+ #if defined(__cplusplus)
436
+ return ((longdouble_t *) &z)[1];
437
+ #else
438
+ return cimagl(z);
439
+ #endif
440
+ }
441
+
442
+ static inline void npy_csetimagl(npy_clongdouble *z, const longdouble_t i)
443
+ {
444
+ ((longdouble_t *) z)[1] = i;
445
+ }
446
+
447
+ #define NPY_CSETREAL(z, r) npy_csetreal(z, r)
448
+ #define NPY_CSETIMAG(z, i) npy_csetimag(z, i)
449
+ #define NPY_CSETREALF(z, r) npy_csetrealf(z, r)
450
+ #define NPY_CSETIMAGF(z, i) npy_csetimagf(z, i)
451
+ #define NPY_CSETREALL(z, r) npy_csetreall(z, r)
452
+ #define NPY_CSETIMAGL(z, i) npy_csetimagl(z, i)
453
+
454
+ static inline npy_cdouble npy_cpack(double x, double y)
455
+ {
456
+ npy_cdouble z;
457
+ npy_csetreal(&z, x);
458
+ npy_csetimag(&z, y);
459
+ return z;
460
+ }
461
+
462
+ static inline npy_cfloat npy_cpackf(float x, float y)
463
+ {
464
+ npy_cfloat z;
465
+ npy_csetrealf(&z, x);
466
+ npy_csetimagf(&z, y);
467
+ return z;
468
+ }
469
+
470
+ static inline npy_clongdouble npy_cpackl(npy_longdouble x, npy_longdouble y)
471
+ {
472
+ npy_clongdouble z;
473
+ npy_csetreall(&z, x);
474
+ npy_csetimagl(&z, y);
475
+ return z;
476
+ }
477
+
478
+ /*
479
+ * Double precision complex functions
480
+ */
481
+ double npy_cabs(npy_cdouble z);
482
+ double npy_carg(npy_cdouble z);
483
+
484
+ npy_cdouble npy_cexp(npy_cdouble z);
485
+ npy_cdouble npy_clog(npy_cdouble z);
486
+ npy_cdouble npy_cpow(npy_cdouble x, npy_cdouble y);
487
+
488
+ npy_cdouble npy_csqrt(npy_cdouble z);
489
+
490
+ npy_cdouble npy_ccos(npy_cdouble z);
491
+ npy_cdouble npy_csin(npy_cdouble z);
492
+ npy_cdouble npy_ctan(npy_cdouble z);
493
+
494
+ npy_cdouble npy_ccosh(npy_cdouble z);
495
+ npy_cdouble npy_csinh(npy_cdouble z);
496
+ npy_cdouble npy_ctanh(npy_cdouble z);
497
+
498
+ npy_cdouble npy_cacos(npy_cdouble z);
499
+ npy_cdouble npy_casin(npy_cdouble z);
500
+ npy_cdouble npy_catan(npy_cdouble z);
501
+
502
+ npy_cdouble npy_cacosh(npy_cdouble z);
503
+ npy_cdouble npy_casinh(npy_cdouble z);
504
+ npy_cdouble npy_catanh(npy_cdouble z);
505
+
506
+ /*
507
+ * Single precision complex functions
508
+ */
509
+ float npy_cabsf(npy_cfloat z);
510
+ float npy_cargf(npy_cfloat z);
511
+
512
+ npy_cfloat npy_cexpf(npy_cfloat z);
513
+ npy_cfloat npy_clogf(npy_cfloat z);
514
+ npy_cfloat npy_cpowf(npy_cfloat x, npy_cfloat y);
515
+
516
+ npy_cfloat npy_csqrtf(npy_cfloat z);
517
+
518
+ npy_cfloat npy_ccosf(npy_cfloat z);
519
+ npy_cfloat npy_csinf(npy_cfloat z);
520
+ npy_cfloat npy_ctanf(npy_cfloat z);
521
+
522
+ npy_cfloat npy_ccoshf(npy_cfloat z);
523
+ npy_cfloat npy_csinhf(npy_cfloat z);
524
+ npy_cfloat npy_ctanhf(npy_cfloat z);
525
+
526
+ npy_cfloat npy_cacosf(npy_cfloat z);
527
+ npy_cfloat npy_casinf(npy_cfloat z);
528
+ npy_cfloat npy_catanf(npy_cfloat z);
529
+
530
+ npy_cfloat npy_cacoshf(npy_cfloat z);
531
+ npy_cfloat npy_casinhf(npy_cfloat z);
532
+ npy_cfloat npy_catanhf(npy_cfloat z);
533
+
534
+
535
+ /*
536
+ * Extended precision complex functions
537
+ */
538
+ npy_longdouble npy_cabsl(npy_clongdouble z);
539
+ npy_longdouble npy_cargl(npy_clongdouble z);
540
+
541
+ npy_clongdouble npy_cexpl(npy_clongdouble z);
542
+ npy_clongdouble npy_clogl(npy_clongdouble z);
543
+ npy_clongdouble npy_cpowl(npy_clongdouble x, npy_clongdouble y);
544
+
545
+ npy_clongdouble npy_csqrtl(npy_clongdouble z);
546
+
547
+ npy_clongdouble npy_ccosl(npy_clongdouble z);
548
+ npy_clongdouble npy_csinl(npy_clongdouble z);
549
+ npy_clongdouble npy_ctanl(npy_clongdouble z);
550
+
551
+ npy_clongdouble npy_ccoshl(npy_clongdouble z);
552
+ npy_clongdouble npy_csinhl(npy_clongdouble z);
553
+ npy_clongdouble npy_ctanhl(npy_clongdouble z);
554
+
555
+ npy_clongdouble npy_cacosl(npy_clongdouble z);
556
+ npy_clongdouble npy_casinl(npy_clongdouble z);
557
+ npy_clongdouble npy_catanl(npy_clongdouble z);
558
+
559
+ npy_clongdouble npy_cacoshl(npy_clongdouble z);
560
+ npy_clongdouble npy_casinhl(npy_clongdouble z);
561
+ npy_clongdouble npy_catanhl(npy_clongdouble z);
562
+
563
+
564
+ /*
565
+ * Functions that set the floating point error
566
+ * status word.
567
+ */
568
+
569
+ /*
570
+ * platform-dependent code translates floating point
571
+ * status to an integer sum of these values
572
+ */
573
+ #define NPY_FPE_DIVIDEBYZERO 1
574
+ #define NPY_FPE_OVERFLOW 2
575
+ #define NPY_FPE_UNDERFLOW 4
576
+ #define NPY_FPE_INVALID 8
577
+
578
+ int npy_clear_floatstatus_barrier(char*);
579
+ int npy_get_floatstatus_barrier(char*);
580
+ /*
581
+ * use caution with these - clang and gcc8.1 are known to reorder calls
582
+ * to this form of the function which can defeat the check. The _barrier
583
+ * form of the call is preferable, where the argument is
584
+ * (char*)&local_variable
585
+ */
586
+ int npy_clear_floatstatus(void);
587
+ int npy_get_floatstatus(void);
588
+
589
+ void npy_set_floatstatus_divbyzero(void);
590
+ void npy_set_floatstatus_overflow(void);
591
+ void npy_set_floatstatus_underflow(void);
592
+ void npy_set_floatstatus_invalid(void);
593
+
594
+ #ifdef __cplusplus
595
+ }
596
+ #endif
597
+
598
+ #if NPY_INLINE_MATH
599
+ #include "npy_math_internal.h"
600
+ #endif
601
+
602
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_MATH_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_no_deprecated_api.h ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * This include file is provided for inclusion in Cython *.pyd files where
3
+ * one would like to define the NPY_NO_DEPRECATED_API macro. It can be
4
+ * included by
5
+ *
6
+ * cdef extern from "npy_no_deprecated_api.h": pass
7
+ *
8
+ */
9
+ #ifndef NPY_NO_DEPRECATED_API
10
+
11
+ /* put this check here since there may be multiple includes in C extensions. */
12
+ #if defined(NUMPY_CORE_INCLUDE_NUMPY_NDARRAYTYPES_H_) || \
13
+ defined(NUMPY_CORE_INCLUDE_NUMPY_NPY_DEPRECATED_API_H) || \
14
+ defined(NUMPY_CORE_INCLUDE_NUMPY_OLD_DEFINES_H_)
15
+ #error "npy_no_deprecated_api.h" must be first among numpy includes.
16
+ #else
17
+ #define NPY_NO_DEPRECATED_API NPY_API_VERSION
18
+ #endif
19
+
20
+ #endif /* NPY_NO_DEPRECATED_API */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_os.h ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_OS_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_NPY_OS_H_
3
+
4
+ #if defined(linux) || defined(__linux) || defined(__linux__)
5
+ #define NPY_OS_LINUX
6
+ #elif defined(__FreeBSD__) || defined(__NetBSD__) || \
7
+ defined(__OpenBSD__) || defined(__DragonFly__)
8
+ #define NPY_OS_BSD
9
+ #ifdef __FreeBSD__
10
+ #define NPY_OS_FREEBSD
11
+ #elif defined(__NetBSD__)
12
+ #define NPY_OS_NETBSD
13
+ #elif defined(__OpenBSD__)
14
+ #define NPY_OS_OPENBSD
15
+ #elif defined(__DragonFly__)
16
+ #define NPY_OS_DRAGONFLY
17
+ #endif
18
+ #elif defined(sun) || defined(__sun)
19
+ #define NPY_OS_SOLARIS
20
+ #elif defined(__CYGWIN__)
21
+ #define NPY_OS_CYGWIN
22
+ /* We are on Windows.*/
23
+ #elif defined(_WIN32)
24
+ /* We are using MinGW (64-bit or 32-bit)*/
25
+ #if defined(__MINGW32__) || defined(__MINGW64__)
26
+ #define NPY_OS_MINGW
27
+ /* Otherwise, if _WIN64 is defined, we are targeting 64-bit Windows*/
28
+ #elif defined(_WIN64)
29
+ #define NPY_OS_WIN64
30
+ /* Otherwise assume we are targeting 32-bit Windows*/
31
+ #else
32
+ #define NPY_OS_WIN32
33
+ #endif
34
+ #elif defined(__APPLE__)
35
+ #define NPY_OS_DARWIN
36
+ #elif defined(__HAIKU__)
37
+ #define NPY_OS_HAIKU
38
+ #else
39
+ #define NPY_OS_UNKNOWN
40
+ #endif
41
+
42
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_OS_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/numpyconfig.h ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_NUMPYCONFIG_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_NPY_NUMPYCONFIG_H_
3
+
4
+ #include "_numpyconfig.h"
5
+
6
+ /*
7
+ * On Mac OS X, because there is only one configuration stage for all the archs
8
+ * in universal builds, any macro which depends on the arch needs to be
9
+ * hardcoded.
10
+ *
11
+ * Note that distutils/pip will attempt a universal2 build when Python itself
12
+ * is built as universal2, hence this hardcoding is needed even if we do not
13
+ * support universal2 wheels anymore (see gh-22796).
14
+ * This code block can be removed after we have dropped the setup.py based
15
+ * build completely.
16
+ */
17
+ #ifdef __APPLE__
18
+ #undef NPY_SIZEOF_LONG
19
+
20
+ #ifdef __LP64__
21
+ #define NPY_SIZEOF_LONG 8
22
+ #else
23
+ #define NPY_SIZEOF_LONG 4
24
+ #endif
25
+
26
+ #undef NPY_SIZEOF_LONGDOUBLE
27
+ #undef NPY_SIZEOF_COMPLEX_LONGDOUBLE
28
+ #ifdef HAVE_LDOUBLE_IEEE_DOUBLE_LE
29
+ #undef HAVE_LDOUBLE_IEEE_DOUBLE_LE
30
+ #endif
31
+ #ifdef HAVE_LDOUBLE_INTEL_EXTENDED_16_BYTES_LE
32
+ #undef HAVE_LDOUBLE_INTEL_EXTENDED_16_BYTES_LE
33
+ #endif
34
+
35
+ #if defined(__arm64__)
36
+ #define NPY_SIZEOF_LONGDOUBLE 8
37
+ #define NPY_SIZEOF_COMPLEX_LONGDOUBLE 16
38
+ #define HAVE_LDOUBLE_IEEE_DOUBLE_LE 1
39
+ #elif defined(__x86_64)
40
+ #define NPY_SIZEOF_LONGDOUBLE 16
41
+ #define NPY_SIZEOF_COMPLEX_LONGDOUBLE 32
42
+ #define HAVE_LDOUBLE_INTEL_EXTENDED_16_BYTES_LE 1
43
+ #elif defined (__i386)
44
+ #define NPY_SIZEOF_LONGDOUBLE 12
45
+ #define NPY_SIZEOF_COMPLEX_LONGDOUBLE 24
46
+ #elif defined(__ppc__) || defined (__ppc64__)
47
+ #define NPY_SIZEOF_LONGDOUBLE 16
48
+ #define NPY_SIZEOF_COMPLEX_LONGDOUBLE 32
49
+ #else
50
+ #error "unknown architecture"
51
+ #endif
52
+ #endif
53
+
54
+
55
+ /**
56
+ * To help with both NPY_TARGET_VERSION and the NPY_NO_DEPRECATED_API macro,
57
+ * we include API version numbers for specific versions of NumPy.
58
+ * To exclude all API that was deprecated as of 1.7, add the following before
59
+ * #including any NumPy headers:
60
+ * #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
61
+ * The same is true for NPY_TARGET_VERSION, although NumPy will default to
62
+ * a backwards compatible build anyway.
63
+ */
64
+ #define NPY_1_7_API_VERSION 0x00000007
65
+ #define NPY_1_8_API_VERSION 0x00000008
66
+ #define NPY_1_9_API_VERSION 0x00000009
67
+ #define NPY_1_10_API_VERSION 0x0000000a
68
+ #define NPY_1_11_API_VERSION 0x0000000a
69
+ #define NPY_1_12_API_VERSION 0x0000000a
70
+ #define NPY_1_13_API_VERSION 0x0000000b
71
+ #define NPY_1_14_API_VERSION 0x0000000c
72
+ #define NPY_1_15_API_VERSION 0x0000000c
73
+ #define NPY_1_16_API_VERSION 0x0000000d
74
+ #define NPY_1_17_API_VERSION 0x0000000d
75
+ #define NPY_1_18_API_VERSION 0x0000000d
76
+ #define NPY_1_19_API_VERSION 0x0000000d
77
+ #define NPY_1_20_API_VERSION 0x0000000e
78
+ #define NPY_1_21_API_VERSION 0x0000000e
79
+ #define NPY_1_22_API_VERSION 0x0000000f
80
+ #define NPY_1_23_API_VERSION 0x00000010
81
+ #define NPY_1_24_API_VERSION 0x00000010
82
+ #define NPY_1_25_API_VERSION 0x00000011
83
+ #define NPY_2_0_API_VERSION 0x00000012
84
+ #define NPY_2_1_API_VERSION 0x00000013
85
+
86
+
87
+ /*
88
+ * Binary compatibility version number. This number is increased
89
+ * whenever the C-API is changed such that binary compatibility is
90
+ * broken, i.e. whenever a recompile of extension modules is needed.
91
+ */
92
+ #define NPY_VERSION NPY_ABI_VERSION
93
+
94
+ /*
95
+ * Minor API version we are compiling to be compatible with. The version
96
+ * Number is always increased when the API changes via: `NPY_API_VERSION`
97
+ * (and should maybe just track the NumPy version).
98
+ *
99
+ * If we have an internal build, we always target the current version of
100
+ * course.
101
+ *
102
+ * For downstream users, we default to an older version to provide them with
103
+ * maximum compatibility by default. Downstream can choose to extend that
104
+ * default, or narrow it down if they wish to use newer API. If you adjust
105
+ * this, consider the Python version support (example for 1.25.x):
106
+ *
107
+ * NumPy 1.25.x supports Python: 3.9 3.10 3.11 (3.12)
108
+ * NumPy 1.19.x supports Python: 3.6 3.7 3.8 3.9
109
+ * NumPy 1.17.x supports Python: 3.5 3.6 3.7 3.8
110
+ * NumPy 1.15.x supports Python: ... 3.6 3.7
111
+ *
112
+ * Users of the stable ABI may wish to target the last Python that is not
113
+ * end of life. This would be 3.8 at NumPy 1.25 release time.
114
+ * 1.17 as default was the choice of oldest-support-numpy at the time and
115
+ * has in practice no limit (compared to 1.19). Even earlier becomes legacy.
116
+ */
117
+ #if defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD
118
+ /* NumPy internal build, always use current version. */
119
+ #define NPY_FEATURE_VERSION NPY_API_VERSION
120
+ #elif defined(NPY_TARGET_VERSION) && NPY_TARGET_VERSION
121
+ /* user provided a target version, use it */
122
+ #define NPY_FEATURE_VERSION NPY_TARGET_VERSION
123
+ #else
124
+ /* Use the default (increase when dropping Python 3.10 support) */
125
+ #define NPY_FEATURE_VERSION NPY_1_21_API_VERSION
126
+ #endif
127
+
128
+ /* Sanity check the (requested) feature version */
129
+ #if NPY_FEATURE_VERSION > NPY_API_VERSION
130
+ #error "NPY_TARGET_VERSION higher than NumPy headers!"
131
+ #elif NPY_FEATURE_VERSION < NPY_1_15_API_VERSION
132
+ /* No support for irrelevant old targets, no need for error, but warn. */
133
+ #warning "Requested NumPy target lower than supported NumPy 1.15."
134
+ #endif
135
+
136
+ /*
137
+ * We define a human readable translation to the Python version of NumPy
138
+ * for error messages (and also to allow grepping the binaries for conda).
139
+ */
140
+ #if NPY_FEATURE_VERSION == NPY_1_7_API_VERSION
141
+ #define NPY_FEATURE_VERSION_STRING "1.7"
142
+ #elif NPY_FEATURE_VERSION == NPY_1_8_API_VERSION
143
+ #define NPY_FEATURE_VERSION_STRING "1.8"
144
+ #elif NPY_FEATURE_VERSION == NPY_1_9_API_VERSION
145
+ #define NPY_FEATURE_VERSION_STRING "1.9"
146
+ #elif NPY_FEATURE_VERSION == NPY_1_10_API_VERSION /* also 1.11, 1.12 */
147
+ #define NPY_FEATURE_VERSION_STRING "1.10"
148
+ #elif NPY_FEATURE_VERSION == NPY_1_13_API_VERSION
149
+ #define NPY_FEATURE_VERSION_STRING "1.13"
150
+ #elif NPY_FEATURE_VERSION == NPY_1_14_API_VERSION /* also 1.15 */
151
+ #define NPY_FEATURE_VERSION_STRING "1.14"
152
+ #elif NPY_FEATURE_VERSION == NPY_1_16_API_VERSION /* also 1.17, 1.18, 1.19 */
153
+ #define NPY_FEATURE_VERSION_STRING "1.16"
154
+ #elif NPY_FEATURE_VERSION == NPY_1_20_API_VERSION /* also 1.21 */
155
+ #define NPY_FEATURE_VERSION_STRING "1.20"
156
+ #elif NPY_FEATURE_VERSION == NPY_1_22_API_VERSION
157
+ #define NPY_FEATURE_VERSION_STRING "1.22"
158
+ #elif NPY_FEATURE_VERSION == NPY_1_23_API_VERSION /* also 1.24 */
159
+ #define NPY_FEATURE_VERSION_STRING "1.23"
160
+ #elif NPY_FEATURE_VERSION == NPY_1_25_API_VERSION
161
+ #define NPY_FEATURE_VERSION_STRING "1.25"
162
+ #elif NPY_FEATURE_VERSION == NPY_2_0_API_VERSION
163
+ #define NPY_FEATURE_VERSION_STRING "2.0"
164
+ #elif NPY_FEATURE_VERSION == NPY_2_1_API_VERSION
165
+ #define NPY_FEATURE_VERSION_STRING "2.1"
166
+ #else
167
+ #error "Missing version string define for new NumPy version."
168
+ #endif
169
+
170
+
171
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_NUMPYCONFIG_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/random/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ zlib License
2
+ ------------
3
+
4
+ Copyright (C) 2010 - 2019 ridiculous_fish, <libdivide@ridiculousfish.com>
5
+ Copyright (C) 2016 - 2019 Kim Walisch, <kim.walisch@gmail.com>
6
+
7
+ This software is provided 'as-is', without any express or implied
8
+ warranty. In no event will the authors be held liable for any damages
9
+ arising from the use of this software.
10
+
11
+ Permission is granted to anyone to use this software for any purpose,
12
+ including commercial applications, and to alter it and redistribute it
13
+ freely, subject to the following restrictions:
14
+
15
+ 1. The origin of this software must not be misrepresented; you must not
16
+ claim that you wrote the original software. If you use this software
17
+ in a product, an acknowledgment in the product documentation would be
18
+ appreciated but is not required.
19
+ 2. Altered source versions must be plainly marked as such, and must not be
20
+ misrepresented as being the original software.
21
+ 3. This notice may not be removed or altered from any source distribution.
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/random/bitgen.h ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_RANDOM_BITGEN_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_RANDOM_BITGEN_H_
3
+
4
+ #pragma once
5
+ #include <stddef.h>
6
+ #include <stdbool.h>
7
+ #include <stdint.h>
8
+
9
+ /* Must match the declaration in numpy/random/<any>.pxd */
10
+
11
+ typedef struct bitgen {
12
+ void *state;
13
+ uint64_t (*next_uint64)(void *st);
14
+ uint32_t (*next_uint32)(void *st);
15
+ double (*next_double)(void *st);
16
+ uint64_t (*next_raw)(void *st);
17
+ } bitgen_t;
18
+
19
+
20
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_RANDOM_BITGEN_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/random/distributions.h ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_RANDOM_DISTRIBUTIONS_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_RANDOM_DISTRIBUTIONS_H_
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include <Python.h>
9
+ #include "numpy/npy_common.h"
10
+ #include <stddef.h>
11
+ #include <stdbool.h>
12
+ #include <stdint.h>
13
+
14
+ #include "numpy/npy_math.h"
15
+ #include "numpy/random/bitgen.h"
16
+
17
+ /*
18
+ * RAND_INT_TYPE is used to share integer generators with RandomState which
19
+ * used long in place of int64_t. If changing a distribution that uses
20
+ * RAND_INT_TYPE, then the original unmodified copy must be retained for
21
+ * use in RandomState by copying to the legacy distributions source file.
22
+ */
23
+ #ifdef NP_RANDOM_LEGACY
24
+ #define RAND_INT_TYPE long
25
+ #define RAND_INT_MAX LONG_MAX
26
+ #else
27
+ #define RAND_INT_TYPE int64_t
28
+ #define RAND_INT_MAX INT64_MAX
29
+ #endif
30
+
31
+ #ifdef _MSC_VER
32
+ #define DECLDIR __declspec(dllexport)
33
+ #else
34
+ #define DECLDIR extern
35
+ #endif
36
+
37
+ #ifndef MIN
38
+ #define MIN(x, y) (((x) < (y)) ? x : y)
39
+ #define MAX(x, y) (((x) > (y)) ? x : y)
40
+ #endif
41
+
42
+ #ifndef M_PI
43
+ #define M_PI 3.14159265358979323846264338328
44
+ #endif
45
+
46
+ typedef struct s_binomial_t {
47
+ int has_binomial; /* !=0: following parameters initialized for binomial */
48
+ double psave;
49
+ RAND_INT_TYPE nsave;
50
+ double r;
51
+ double q;
52
+ double fm;
53
+ RAND_INT_TYPE m;
54
+ double p1;
55
+ double xm;
56
+ double xl;
57
+ double xr;
58
+ double c;
59
+ double laml;
60
+ double lamr;
61
+ double p2;
62
+ double p3;
63
+ double p4;
64
+ } binomial_t;
65
+
66
+ DECLDIR float random_standard_uniform_f(bitgen_t *bitgen_state);
67
+ DECLDIR double random_standard_uniform(bitgen_t *bitgen_state);
68
+ DECLDIR void random_standard_uniform_fill(bitgen_t *, npy_intp, double *);
69
+ DECLDIR void random_standard_uniform_fill_f(bitgen_t *, npy_intp, float *);
70
+
71
+ DECLDIR int64_t random_positive_int64(bitgen_t *bitgen_state);
72
+ DECLDIR int32_t random_positive_int32(bitgen_t *bitgen_state);
73
+ DECLDIR int64_t random_positive_int(bitgen_t *bitgen_state);
74
+ DECLDIR uint64_t random_uint(bitgen_t *bitgen_state);
75
+
76
+ DECLDIR double random_standard_exponential(bitgen_t *bitgen_state);
77
+ DECLDIR float random_standard_exponential_f(bitgen_t *bitgen_state);
78
+ DECLDIR void random_standard_exponential_fill(bitgen_t *, npy_intp, double *);
79
+ DECLDIR void random_standard_exponential_fill_f(bitgen_t *, npy_intp, float *);
80
+ DECLDIR void random_standard_exponential_inv_fill(bitgen_t *, npy_intp, double *);
81
+ DECLDIR void random_standard_exponential_inv_fill_f(bitgen_t *, npy_intp, float *);
82
+
83
+ DECLDIR double random_standard_normal(bitgen_t *bitgen_state);
84
+ DECLDIR float random_standard_normal_f(bitgen_t *bitgen_state);
85
+ DECLDIR void random_standard_normal_fill(bitgen_t *, npy_intp, double *);
86
+ DECLDIR void random_standard_normal_fill_f(bitgen_t *, npy_intp, float *);
87
+ DECLDIR double random_standard_gamma(bitgen_t *bitgen_state, double shape);
88
+ DECLDIR float random_standard_gamma_f(bitgen_t *bitgen_state, float shape);
89
+
90
+ DECLDIR double random_normal(bitgen_t *bitgen_state, double loc, double scale);
91
+
92
+ DECLDIR double random_gamma(bitgen_t *bitgen_state, double shape, double scale);
93
+ DECLDIR float random_gamma_f(bitgen_t *bitgen_state, float shape, float scale);
94
+
95
+ DECLDIR double random_exponential(bitgen_t *bitgen_state, double scale);
96
+ DECLDIR double random_uniform(bitgen_t *bitgen_state, double lower, double range);
97
+ DECLDIR double random_beta(bitgen_t *bitgen_state, double a, double b);
98
+ DECLDIR double random_chisquare(bitgen_t *bitgen_state, double df);
99
+ DECLDIR double random_f(bitgen_t *bitgen_state, double dfnum, double dfden);
100
+ DECLDIR double random_standard_cauchy(bitgen_t *bitgen_state);
101
+ DECLDIR double random_pareto(bitgen_t *bitgen_state, double a);
102
+ DECLDIR double random_weibull(bitgen_t *bitgen_state, double a);
103
+ DECLDIR double random_power(bitgen_t *bitgen_state, double a);
104
+ DECLDIR double random_laplace(bitgen_t *bitgen_state, double loc, double scale);
105
+ DECLDIR double random_gumbel(bitgen_t *bitgen_state, double loc, double scale);
106
+ DECLDIR double random_logistic(bitgen_t *bitgen_state, double loc, double scale);
107
+ DECLDIR double random_lognormal(bitgen_t *bitgen_state, double mean, double sigma);
108
+ DECLDIR double random_rayleigh(bitgen_t *bitgen_state, double mode);
109
+ DECLDIR double random_standard_t(bitgen_t *bitgen_state, double df);
110
+ DECLDIR double random_noncentral_chisquare(bitgen_t *bitgen_state, double df,
111
+ double nonc);
112
+ DECLDIR double random_noncentral_f(bitgen_t *bitgen_state, double dfnum,
113
+ double dfden, double nonc);
114
+ DECLDIR double random_wald(bitgen_t *bitgen_state, double mean, double scale);
115
+ DECLDIR double random_vonmises(bitgen_t *bitgen_state, double mu, double kappa);
116
+ DECLDIR double random_triangular(bitgen_t *bitgen_state, double left, double mode,
117
+ double right);
118
+
119
+ DECLDIR RAND_INT_TYPE random_poisson(bitgen_t *bitgen_state, double lam);
120
+ DECLDIR RAND_INT_TYPE random_negative_binomial(bitgen_t *bitgen_state, double n,
121
+ double p);
122
+
123
+ DECLDIR int64_t random_binomial(bitgen_t *bitgen_state, double p,
124
+ int64_t n, binomial_t *binomial);
125
+
126
+ DECLDIR int64_t random_logseries(bitgen_t *bitgen_state, double p);
127
+ DECLDIR int64_t random_geometric(bitgen_t *bitgen_state, double p);
128
+ DECLDIR RAND_INT_TYPE random_geometric_search(bitgen_t *bitgen_state, double p);
129
+ DECLDIR RAND_INT_TYPE random_zipf(bitgen_t *bitgen_state, double a);
130
+ DECLDIR int64_t random_hypergeometric(bitgen_t *bitgen_state,
131
+ int64_t good, int64_t bad, int64_t sample);
132
+ DECLDIR uint64_t random_interval(bitgen_t *bitgen_state, uint64_t max);
133
+
134
+ /* Generate random uint64 numbers in closed interval [off, off + rng]. */
135
+ DECLDIR uint64_t random_bounded_uint64(bitgen_t *bitgen_state, uint64_t off,
136
+ uint64_t rng, uint64_t mask,
137
+ bool use_masked);
138
+
139
+ /* Generate random uint32 numbers in closed interval [off, off + rng]. */
140
+ DECLDIR uint32_t random_buffered_bounded_uint32(bitgen_t *bitgen_state,
141
+ uint32_t off, uint32_t rng,
142
+ uint32_t mask, bool use_masked,
143
+ int *bcnt, uint32_t *buf);
144
+ DECLDIR uint16_t random_buffered_bounded_uint16(bitgen_t *bitgen_state,
145
+ uint16_t off, uint16_t rng,
146
+ uint16_t mask, bool use_masked,
147
+ int *bcnt, uint32_t *buf);
148
+ DECLDIR uint8_t random_buffered_bounded_uint8(bitgen_t *bitgen_state, uint8_t off,
149
+ uint8_t rng, uint8_t mask,
150
+ bool use_masked, int *bcnt,
151
+ uint32_t *buf);
152
+ DECLDIR npy_bool random_buffered_bounded_bool(bitgen_t *bitgen_state, npy_bool off,
153
+ npy_bool rng, npy_bool mask,
154
+ bool use_masked, int *bcnt,
155
+ uint32_t *buf);
156
+
157
+ DECLDIR void random_bounded_uint64_fill(bitgen_t *bitgen_state, uint64_t off,
158
+ uint64_t rng, npy_intp cnt,
159
+ bool use_masked, uint64_t *out);
160
+ DECLDIR void random_bounded_uint32_fill(bitgen_t *bitgen_state, uint32_t off,
161
+ uint32_t rng, npy_intp cnt,
162
+ bool use_masked, uint32_t *out);
163
+ DECLDIR void random_bounded_uint16_fill(bitgen_t *bitgen_state, uint16_t off,
164
+ uint16_t rng, npy_intp cnt,
165
+ bool use_masked, uint16_t *out);
166
+ DECLDIR void random_bounded_uint8_fill(bitgen_t *bitgen_state, uint8_t off,
167
+ uint8_t rng, npy_intp cnt,
168
+ bool use_masked, uint8_t *out);
169
+ DECLDIR void random_bounded_bool_fill(bitgen_t *bitgen_state, npy_bool off,
170
+ npy_bool rng, npy_intp cnt,
171
+ bool use_masked, npy_bool *out);
172
+
173
+ DECLDIR void random_multinomial(bitgen_t *bitgen_state, RAND_INT_TYPE n, RAND_INT_TYPE *mnix,
174
+ double *pix, npy_intp d, binomial_t *binomial);
175
+
176
+ /* multivariate hypergeometric, "count" method */
177
+ DECLDIR int random_multivariate_hypergeometric_count(bitgen_t *bitgen_state,
178
+ int64_t total,
179
+ size_t num_colors, int64_t *colors,
180
+ int64_t nsample,
181
+ size_t num_variates, int64_t *variates);
182
+
183
+ /* multivariate hypergeometric, "marginals" method */
184
+ DECLDIR void random_multivariate_hypergeometric_marginals(bitgen_t *bitgen_state,
185
+ int64_t total,
186
+ size_t num_colors, int64_t *colors,
187
+ int64_t nsample,
188
+ size_t num_variates, int64_t *variates);
189
+
190
+ /* Common to legacy-distributions.c and distributions.c but not exported */
191
+
192
+ RAND_INT_TYPE random_binomial_btpe(bitgen_t *bitgen_state,
193
+ RAND_INT_TYPE n,
194
+ double p,
195
+ binomial_t *binomial);
196
+ RAND_INT_TYPE random_binomial_inversion(bitgen_t *bitgen_state,
197
+ RAND_INT_TYPE n,
198
+ double p,
199
+ binomial_t *binomial);
200
+ double random_loggam(double x);
201
+ static inline double next_double(bitgen_t *bitgen_state) {
202
+ return bitgen_state->next_double(bitgen_state->state);
203
+ }
204
+
205
+ #ifdef __cplusplus
206
+ }
207
+ #endif
208
+
209
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_RANDOM_DISTRIBUTIONS_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/random/libdivide.h ADDED
@@ -0,0 +1,2079 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // libdivide.h - Optimized integer division
2
+ // https://libdivide.com
3
+ //
4
+ // Copyright (C) 2010 - 2019 ridiculous_fish, <libdivide@ridiculousfish.com>
5
+ // Copyright (C) 2016 - 2019 Kim Walisch, <kim.walisch@gmail.com>
6
+ //
7
+ // libdivide is dual-licensed under the Boost or zlib licenses.
8
+ // You may use libdivide under the terms of either of these.
9
+ // See LICENSE.txt for more details.
10
+
11
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_LIBDIVIDE_LIBDIVIDE_H_
12
+ #define NUMPY_CORE_INCLUDE_NUMPY_LIBDIVIDE_LIBDIVIDE_H_
13
+
14
+ #define LIBDIVIDE_VERSION "3.0"
15
+ #define LIBDIVIDE_VERSION_MAJOR 3
16
+ #define LIBDIVIDE_VERSION_MINOR 0
17
+
18
+ #include <stdint.h>
19
+
20
+ #if defined(__cplusplus)
21
+ #include <cstdlib>
22
+ #include <cstdio>
23
+ #include <type_traits>
24
+ #else
25
+ #include <stdlib.h>
26
+ #include <stdio.h>
27
+ #endif
28
+
29
+ #if defined(LIBDIVIDE_AVX512)
30
+ #include <immintrin.h>
31
+ #elif defined(LIBDIVIDE_AVX2)
32
+ #include <immintrin.h>
33
+ #elif defined(LIBDIVIDE_SSE2)
34
+ #include <emmintrin.h>
35
+ #endif
36
+
37
+ #if defined(_MSC_VER)
38
+ #include <intrin.h>
39
+ // disable warning C4146: unary minus operator applied
40
+ // to unsigned type, result still unsigned
41
+ #pragma warning(disable: 4146)
42
+ #define LIBDIVIDE_VC
43
+ #endif
44
+
45
+ #if !defined(__has_builtin)
46
+ #define __has_builtin(x) 0
47
+ #endif
48
+
49
+ #if defined(__SIZEOF_INT128__)
50
+ #define HAS_INT128_T
51
+ // clang-cl on Windows does not yet support 128-bit division
52
+ #if !(defined(__clang__) && defined(LIBDIVIDE_VC))
53
+ #define HAS_INT128_DIV
54
+ #endif
55
+ #endif
56
+
57
+ #if defined(__x86_64__) || defined(_M_X64)
58
+ #define LIBDIVIDE_X86_64
59
+ #endif
60
+
61
+ #if defined(__i386__)
62
+ #define LIBDIVIDE_i386
63
+ #endif
64
+
65
+ #if defined(__GNUC__) || defined(__clang__)
66
+ #define LIBDIVIDE_GCC_STYLE_ASM
67
+ #endif
68
+
69
+ #if defined(__cplusplus) || defined(LIBDIVIDE_VC)
70
+ #define LIBDIVIDE_FUNCTION __FUNCTION__
71
+ #else
72
+ #define LIBDIVIDE_FUNCTION __func__
73
+ #endif
74
+
75
+ #define LIBDIVIDE_ERROR(msg) \
76
+ do { \
77
+ fprintf(stderr, "libdivide.h:%d: %s(): Error: %s\n", \
78
+ __LINE__, LIBDIVIDE_FUNCTION, msg); \
79
+ abort(); \
80
+ } while (0)
81
+
82
+ #if defined(LIBDIVIDE_ASSERTIONS_ON)
83
+ #define LIBDIVIDE_ASSERT(x) \
84
+ do { \
85
+ if (!(x)) { \
86
+ fprintf(stderr, "libdivide.h:%d: %s(): Assertion failed: %s\n", \
87
+ __LINE__, LIBDIVIDE_FUNCTION, #x); \
88
+ abort(); \
89
+ } \
90
+ } while (0)
91
+ #else
92
+ #define LIBDIVIDE_ASSERT(x)
93
+ #endif
94
+
95
+ #ifdef __cplusplus
96
+ namespace libdivide {
97
+ #endif
98
+
99
+ // pack divider structs to prevent compilers from padding.
100
+ // This reduces memory usage by up to 43% when using a large
101
+ // array of libdivide dividers and improves performance
102
+ // by up to 10% because of reduced memory bandwidth.
103
+ #pragma pack(push, 1)
104
+
105
+ struct libdivide_u32_t {
106
+ uint32_t magic;
107
+ uint8_t more;
108
+ };
109
+
110
+ struct libdivide_s32_t {
111
+ int32_t magic;
112
+ uint8_t more;
113
+ };
114
+
115
+ struct libdivide_u64_t {
116
+ uint64_t magic;
117
+ uint8_t more;
118
+ };
119
+
120
+ struct libdivide_s64_t {
121
+ int64_t magic;
122
+ uint8_t more;
123
+ };
124
+
125
+ struct libdivide_u32_branchfree_t {
126
+ uint32_t magic;
127
+ uint8_t more;
128
+ };
129
+
130
+ struct libdivide_s32_branchfree_t {
131
+ int32_t magic;
132
+ uint8_t more;
133
+ };
134
+
135
+ struct libdivide_u64_branchfree_t {
136
+ uint64_t magic;
137
+ uint8_t more;
138
+ };
139
+
140
+ struct libdivide_s64_branchfree_t {
141
+ int64_t magic;
142
+ uint8_t more;
143
+ };
144
+
145
+ #pragma pack(pop)
146
+
147
+ // Explanation of the "more" field:
148
+ //
149
+ // * Bits 0-5 is the shift value (for shift path or mult path).
150
+ // * Bit 6 is the add indicator for mult path.
151
+ // * Bit 7 is set if the divisor is negative. We use bit 7 as the negative
152
+ // divisor indicator so that we can efficiently use sign extension to
153
+ // create a bitmask with all bits set to 1 (if the divisor is negative)
154
+ // or 0 (if the divisor is positive).
155
+ //
156
+ // u32: [0-4] shift value
157
+ // [5] ignored
158
+ // [6] add indicator
159
+ // magic number of 0 indicates shift path
160
+ //
161
+ // s32: [0-4] shift value
162
+ // [5] ignored
163
+ // [6] add indicator
164
+ // [7] indicates negative divisor
165
+ // magic number of 0 indicates shift path
166
+ //
167
+ // u64: [0-5] shift value
168
+ // [6] add indicator
169
+ // magic number of 0 indicates shift path
170
+ //
171
+ // s64: [0-5] shift value
172
+ // [6] add indicator
173
+ // [7] indicates negative divisor
174
+ // magic number of 0 indicates shift path
175
+ //
176
+ // In s32 and s64 branchfree modes, the magic number is negated according to
177
+ // whether the divisor is negated. In branchfree strategy, it is not negated.
178
+
179
+ enum {
180
+ LIBDIVIDE_32_SHIFT_MASK = 0x1F,
181
+ LIBDIVIDE_64_SHIFT_MASK = 0x3F,
182
+ LIBDIVIDE_ADD_MARKER = 0x40,
183
+ LIBDIVIDE_NEGATIVE_DIVISOR = 0x80
184
+ };
185
+
186
+ static inline struct libdivide_s32_t libdivide_s32_gen(int32_t d);
187
+ static inline struct libdivide_u32_t libdivide_u32_gen(uint32_t d);
188
+ static inline struct libdivide_s64_t libdivide_s64_gen(int64_t d);
189
+ static inline struct libdivide_u64_t libdivide_u64_gen(uint64_t d);
190
+
191
+ static inline struct libdivide_s32_branchfree_t libdivide_s32_branchfree_gen(int32_t d);
192
+ static inline struct libdivide_u32_branchfree_t libdivide_u32_branchfree_gen(uint32_t d);
193
+ static inline struct libdivide_s64_branchfree_t libdivide_s64_branchfree_gen(int64_t d);
194
+ static inline struct libdivide_u64_branchfree_t libdivide_u64_branchfree_gen(uint64_t d);
195
+
196
+ static inline int32_t libdivide_s32_do(int32_t numer, const struct libdivide_s32_t *denom);
197
+ static inline uint32_t libdivide_u32_do(uint32_t numer, const struct libdivide_u32_t *denom);
198
+ static inline int64_t libdivide_s64_do(int64_t numer, const struct libdivide_s64_t *denom);
199
+ static inline uint64_t libdivide_u64_do(uint64_t numer, const struct libdivide_u64_t *denom);
200
+
201
+ static inline int32_t libdivide_s32_branchfree_do(int32_t numer, const struct libdivide_s32_branchfree_t *denom);
202
+ static inline uint32_t libdivide_u32_branchfree_do(uint32_t numer, const struct libdivide_u32_branchfree_t *denom);
203
+ static inline int64_t libdivide_s64_branchfree_do(int64_t numer, const struct libdivide_s64_branchfree_t *denom);
204
+ static inline uint64_t libdivide_u64_branchfree_do(uint64_t numer, const struct libdivide_u64_branchfree_t *denom);
205
+
206
+ static inline int32_t libdivide_s32_recover(const struct libdivide_s32_t *denom);
207
+ static inline uint32_t libdivide_u32_recover(const struct libdivide_u32_t *denom);
208
+ static inline int64_t libdivide_s64_recover(const struct libdivide_s64_t *denom);
209
+ static inline uint64_t libdivide_u64_recover(const struct libdivide_u64_t *denom);
210
+
211
+ static inline int32_t libdivide_s32_branchfree_recover(const struct libdivide_s32_branchfree_t *denom);
212
+ static inline uint32_t libdivide_u32_branchfree_recover(const struct libdivide_u32_branchfree_t *denom);
213
+ static inline int64_t libdivide_s64_branchfree_recover(const struct libdivide_s64_branchfree_t *denom);
214
+ static inline uint64_t libdivide_u64_branchfree_recover(const struct libdivide_u64_branchfree_t *denom);
215
+
216
+ //////// Internal Utility Functions
217
+
218
+ static inline uint32_t libdivide_mullhi_u32(uint32_t x, uint32_t y) {
219
+ uint64_t xl = x, yl = y;
220
+ uint64_t rl = xl * yl;
221
+ return (uint32_t)(rl >> 32);
222
+ }
223
+
224
+ static inline int32_t libdivide_mullhi_s32(int32_t x, int32_t y) {
225
+ int64_t xl = x, yl = y;
226
+ int64_t rl = xl * yl;
227
+ // needs to be arithmetic shift
228
+ return (int32_t)(rl >> 32);
229
+ }
230
+
231
+ static inline uint64_t libdivide_mullhi_u64(uint64_t x, uint64_t y) {
232
+ #if defined(LIBDIVIDE_VC) && \
233
+ defined(LIBDIVIDE_X86_64)
234
+ return __umulh(x, y);
235
+ #elif defined(HAS_INT128_T)
236
+ __uint128_t xl = x, yl = y;
237
+ __uint128_t rl = xl * yl;
238
+ return (uint64_t)(rl >> 64);
239
+ #else
240
+ // full 128 bits are x0 * y0 + (x0 * y1 << 32) + (x1 * y0 << 32) + (x1 * y1 << 64)
241
+ uint32_t mask = 0xFFFFFFFF;
242
+ uint32_t x0 = (uint32_t)(x & mask);
243
+ uint32_t x1 = (uint32_t)(x >> 32);
244
+ uint32_t y0 = (uint32_t)(y & mask);
245
+ uint32_t y1 = (uint32_t)(y >> 32);
246
+ uint32_t x0y0_hi = libdivide_mullhi_u32(x0, y0);
247
+ uint64_t x0y1 = x0 * (uint64_t)y1;
248
+ uint64_t x1y0 = x1 * (uint64_t)y0;
249
+ uint64_t x1y1 = x1 * (uint64_t)y1;
250
+ uint64_t temp = x1y0 + x0y0_hi;
251
+ uint64_t temp_lo = temp & mask;
252
+ uint64_t temp_hi = temp >> 32;
253
+
254
+ return x1y1 + temp_hi + ((temp_lo + x0y1) >> 32);
255
+ #endif
256
+ }
257
+
258
+ static inline int64_t libdivide_mullhi_s64(int64_t x, int64_t y) {
259
+ #if defined(LIBDIVIDE_VC) && \
260
+ defined(LIBDIVIDE_X86_64)
261
+ return __mulh(x, y);
262
+ #elif defined(HAS_INT128_T)
263
+ __int128_t xl = x, yl = y;
264
+ __int128_t rl = xl * yl;
265
+ return (int64_t)(rl >> 64);
266
+ #else
267
+ // full 128 bits are x0 * y0 + (x0 * y1 << 32) + (x1 * y0 << 32) + (x1 * y1 << 64)
268
+ uint32_t mask = 0xFFFFFFFF;
269
+ uint32_t x0 = (uint32_t)(x & mask);
270
+ uint32_t y0 = (uint32_t)(y & mask);
271
+ int32_t x1 = (int32_t)(x >> 32);
272
+ int32_t y1 = (int32_t)(y >> 32);
273
+ uint32_t x0y0_hi = libdivide_mullhi_u32(x0, y0);
274
+ int64_t t = x1 * (int64_t)y0 + x0y0_hi;
275
+ int64_t w1 = x0 * (int64_t)y1 + (t & mask);
276
+
277
+ return x1 * (int64_t)y1 + (t >> 32) + (w1 >> 32);
278
+ #endif
279
+ }
280
+
281
+ static inline int32_t libdivide_count_leading_zeros32(uint32_t val) {
282
+ #if defined(__GNUC__) || \
283
+ __has_builtin(__builtin_clz)
284
+ // Fast way to count leading zeros
285
+ return __builtin_clz(val);
286
+ #elif defined(LIBDIVIDE_VC)
287
+ unsigned long result;
288
+ if (_BitScanReverse(&result, val)) {
289
+ return 31 - result;
290
+ }
291
+ return 0;
292
+ #else
293
+ if (val == 0)
294
+ return 32;
295
+ int32_t result = 8;
296
+ uint32_t hi = 0xFFU << 24;
297
+ while ((val & hi) == 0) {
298
+ hi >>= 8;
299
+ result += 8;
300
+ }
301
+ while (val & hi) {
302
+ result -= 1;
303
+ hi <<= 1;
304
+ }
305
+ return result;
306
+ #endif
307
+ }
308
+
309
+ static inline int32_t libdivide_count_leading_zeros64(uint64_t val) {
310
+ #if defined(__GNUC__) || \
311
+ __has_builtin(__builtin_clzll)
312
+ // Fast way to count leading zeros
313
+ return __builtin_clzll(val);
314
+ #elif defined(LIBDIVIDE_VC) && defined(_WIN64)
315
+ unsigned long result;
316
+ if (_BitScanReverse64(&result, val)) {
317
+ return 63 - result;
318
+ }
319
+ return 0;
320
+ #else
321
+ uint32_t hi = val >> 32;
322
+ uint32_t lo = val & 0xFFFFFFFF;
323
+ if (hi != 0) return libdivide_count_leading_zeros32(hi);
324
+ return 32 + libdivide_count_leading_zeros32(lo);
325
+ #endif
326
+ }
327
+
328
+ // libdivide_64_div_32_to_32: divides a 64-bit uint {u1, u0} by a 32-bit
329
+ // uint {v}. The result must fit in 32 bits.
330
+ // Returns the quotient directly and the remainder in *r
331
+ static inline uint32_t libdivide_64_div_32_to_32(uint32_t u1, uint32_t u0, uint32_t v, uint32_t *r) {
332
+ #if (defined(LIBDIVIDE_i386) || defined(LIBDIVIDE_X86_64)) && \
333
+ defined(LIBDIVIDE_GCC_STYLE_ASM)
334
+ uint32_t result;
335
+ __asm__("divl %[v]"
336
+ : "=a"(result), "=d"(*r)
337
+ : [v] "r"(v), "a"(u0), "d"(u1)
338
+ );
339
+ return result;
340
+ #else
341
+ uint64_t n = ((uint64_t)u1 << 32) | u0;
342
+ uint32_t result = (uint32_t)(n / v);
343
+ *r = (uint32_t)(n - result * (uint64_t)v);
344
+ return result;
345
+ #endif
346
+ }
347
+
348
+ // libdivide_128_div_64_to_64: divides a 128-bit uint {u1, u0} by a 64-bit
349
+ // uint {v}. The result must fit in 64 bits.
350
+ // Returns the quotient directly and the remainder in *r
351
+ static uint64_t libdivide_128_div_64_to_64(uint64_t u1, uint64_t u0, uint64_t v, uint64_t *r) {
352
+ #if defined(LIBDIVIDE_X86_64) && \
353
+ defined(LIBDIVIDE_GCC_STYLE_ASM)
354
+ uint64_t result;
355
+ __asm__("divq %[v]"
356
+ : "=a"(result), "=d"(*r)
357
+ : [v] "r"(v), "a"(u0), "d"(u1)
358
+ );
359
+ return result;
360
+ #elif defined(HAS_INT128_T) && \
361
+ defined(HAS_INT128_DIV)
362
+ __uint128_t n = ((__uint128_t)u1 << 64) | u0;
363
+ uint64_t result = (uint64_t)(n / v);
364
+ *r = (uint64_t)(n - result * (__uint128_t)v);
365
+ return result;
366
+ #else
367
+ // Code taken from Hacker's Delight:
368
+ // http://www.hackersdelight.org/HDcode/divlu.c.
369
+ // License permits inclusion here per:
370
+ // http://www.hackersdelight.org/permissions.htm
371
+
372
+ const uint64_t b = (1ULL << 32); // Number base (32 bits)
373
+ uint64_t un1, un0; // Norm. dividend LSD's
374
+ uint64_t vn1, vn0; // Norm. divisor digits
375
+ uint64_t q1, q0; // Quotient digits
376
+ uint64_t un64, un21, un10; // Dividend digit pairs
377
+ uint64_t rhat; // A remainder
378
+ int32_t s; // Shift amount for norm
379
+
380
+ // If overflow, set rem. to an impossible value,
381
+ // and return the largest possible quotient
382
+ if (u1 >= v) {
383
+ *r = (uint64_t) -1;
384
+ return (uint64_t) -1;
385
+ }
386
+
387
+ // count leading zeros
388
+ s = libdivide_count_leading_zeros64(v);
389
+ if (s > 0) {
390
+ // Normalize divisor
391
+ v = v << s;
392
+ un64 = (u1 << s) | (u0 >> (64 - s));
393
+ un10 = u0 << s; // Shift dividend left
394
+ } else {
395
+ // Avoid undefined behavior of (u0 >> 64).
396
+ // The behavior is undefined if the right operand is
397
+ // negative, or greater than or equal to the length
398
+ // in bits of the promoted left operand.
399
+ un64 = u1;
400
+ un10 = u0;
401
+ }
402
+
403
+ // Break divisor up into two 32-bit digits
404
+ vn1 = v >> 32;
405
+ vn0 = v & 0xFFFFFFFF;
406
+
407
+ // Break right half of dividend into two digits
408
+ un1 = un10 >> 32;
409
+ un0 = un10 & 0xFFFFFFFF;
410
+
411
+ // Compute the first quotient digit, q1
412
+ q1 = un64 / vn1;
413
+ rhat = un64 - q1 * vn1;
414
+
415
+ while (q1 >= b || q1 * vn0 > b * rhat + un1) {
416
+ q1 = q1 - 1;
417
+ rhat = rhat + vn1;
418
+ if (rhat >= b)
419
+ break;
420
+ }
421
+
422
+ // Multiply and subtract
423
+ un21 = un64 * b + un1 - q1 * v;
424
+
425
+ // Compute the second quotient digit
426
+ q0 = un21 / vn1;
427
+ rhat = un21 - q0 * vn1;
428
+
429
+ while (q0 >= b || q0 * vn0 > b * rhat + un0) {
430
+ q0 = q0 - 1;
431
+ rhat = rhat + vn1;
432
+ if (rhat >= b)
433
+ break;
434
+ }
435
+
436
+ *r = (un21 * b + un0 - q0 * v) >> s;
437
+ return q1 * b + q0;
438
+ #endif
439
+ }
440
+
441
+ // Bitshift a u128 in place, left (signed_shift > 0) or right (signed_shift < 0)
442
+ static inline void libdivide_u128_shift(uint64_t *u1, uint64_t *u0, int32_t signed_shift) {
443
+ if (signed_shift > 0) {
444
+ uint32_t shift = signed_shift;
445
+ *u1 <<= shift;
446
+ *u1 |= *u0 >> (64 - shift);
447
+ *u0 <<= shift;
448
+ }
449
+ else if (signed_shift < 0) {
450
+ uint32_t shift = -signed_shift;
451
+ *u0 >>= shift;
452
+ *u0 |= *u1 << (64 - shift);
453
+ *u1 >>= shift;
454
+ }
455
+ }
456
+
457
+ // Computes a 128 / 128 -> 64 bit division, with a 128 bit remainder.
458
+ static uint64_t libdivide_128_div_128_to_64(uint64_t u_hi, uint64_t u_lo, uint64_t v_hi, uint64_t v_lo, uint64_t *r_hi, uint64_t *r_lo) {
459
+ #if defined(HAS_INT128_T) && \
460
+ defined(HAS_INT128_DIV)
461
+ __uint128_t ufull = u_hi;
462
+ __uint128_t vfull = v_hi;
463
+ ufull = (ufull << 64) | u_lo;
464
+ vfull = (vfull << 64) | v_lo;
465
+ uint64_t res = (uint64_t)(ufull / vfull);
466
+ __uint128_t remainder = ufull - (vfull * res);
467
+ *r_lo = (uint64_t)remainder;
468
+ *r_hi = (uint64_t)(remainder >> 64);
469
+ return res;
470
+ #else
471
+ // Adapted from "Unsigned Doubleword Division" in Hacker's Delight
472
+ // We want to compute u / v
473
+ typedef struct { uint64_t hi; uint64_t lo; } u128_t;
474
+ u128_t u = {u_hi, u_lo};
475
+ u128_t v = {v_hi, v_lo};
476
+
477
+ if (v.hi == 0) {
478
+ // divisor v is a 64 bit value, so we just need one 128/64 division
479
+ // Note that we are simpler than Hacker's Delight here, because we know
480
+ // the quotient fits in 64 bits whereas Hacker's Delight demands a full
481
+ // 128 bit quotient
482
+ *r_hi = 0;
483
+ return libdivide_128_div_64_to_64(u.hi, u.lo, v.lo, r_lo);
484
+ }
485
+ // Here v >= 2**64
486
+ // We know that v.hi != 0, so count leading zeros is OK
487
+ // We have 0 <= n <= 63
488
+ uint32_t n = libdivide_count_leading_zeros64(v.hi);
489
+
490
+ // Normalize the divisor so its MSB is 1
491
+ u128_t v1t = v;
492
+ libdivide_u128_shift(&v1t.hi, &v1t.lo, n);
493
+ uint64_t v1 = v1t.hi; // i.e. v1 = v1t >> 64
494
+
495
+ // To ensure no overflow
496
+ u128_t u1 = u;
497
+ libdivide_u128_shift(&u1.hi, &u1.lo, -1);
498
+
499
+ // Get quotient from divide unsigned insn.
500
+ uint64_t rem_ignored;
501
+ uint64_t q1 = libdivide_128_div_64_to_64(u1.hi, u1.lo, v1, &rem_ignored);
502
+
503
+ // Undo normalization and division of u by 2.
504
+ u128_t q0 = {0, q1};
505
+ libdivide_u128_shift(&q0.hi, &q0.lo, n);
506
+ libdivide_u128_shift(&q0.hi, &q0.lo, -63);
507
+
508
+ // Make q0 correct or too small by 1
509
+ // Equivalent to `if (q0 != 0) q0 = q0 - 1;`
510
+ if (q0.hi != 0 || q0.lo != 0) {
511
+ q0.hi -= (q0.lo == 0); // borrow
512
+ q0.lo -= 1;
513
+ }
514
+
515
+ // Now q0 is correct.
516
+ // Compute q0 * v as q0v
517
+ // = (q0.hi << 64 + q0.lo) * (v.hi << 64 + v.lo)
518
+ // = (q0.hi * v.hi << 128) + (q0.hi * v.lo << 64) +
519
+ // (q0.lo * v.hi << 64) + q0.lo * v.lo)
520
+ // Each term is 128 bit
521
+ // High half of full product (upper 128 bits!) are dropped
522
+ u128_t q0v = {0, 0};
523
+ q0v.hi = q0.hi*v.lo + q0.lo*v.hi + libdivide_mullhi_u64(q0.lo, v.lo);
524
+ q0v.lo = q0.lo*v.lo;
525
+
526
+ // Compute u - q0v as u_q0v
527
+ // This is the remainder
528
+ u128_t u_q0v = u;
529
+ u_q0v.hi -= q0v.hi + (u.lo < q0v.lo); // second term is borrow
530
+ u_q0v.lo -= q0v.lo;
531
+
532
+ // Check if u_q0v >= v
533
+ // This checks if our remainder is larger than the divisor
534
+ if ((u_q0v.hi > v.hi) ||
535
+ (u_q0v.hi == v.hi && u_q0v.lo >= v.lo)) {
536
+ // Increment q0
537
+ q0.lo += 1;
538
+ q0.hi += (q0.lo == 0); // carry
539
+
540
+ // Subtract v from remainder
541
+ u_q0v.hi -= v.hi + (u_q0v.lo < v.lo);
542
+ u_q0v.lo -= v.lo;
543
+ }
544
+
545
+ *r_hi = u_q0v.hi;
546
+ *r_lo = u_q0v.lo;
547
+
548
+ LIBDIVIDE_ASSERT(q0.hi == 0);
549
+ return q0.lo;
550
+ #endif
551
+ }
552
+
553
+ ////////// UINT32
554
+
555
+ static inline struct libdivide_u32_t libdivide_internal_u32_gen(uint32_t d, int branchfree) {
556
+ if (d == 0) {
557
+ LIBDIVIDE_ERROR("divider must be != 0");
558
+ }
559
+
560
+ struct libdivide_u32_t result;
561
+ uint32_t floor_log_2_d = 31 - libdivide_count_leading_zeros32(d);
562
+
563
+ // Power of 2
564
+ if ((d & (d - 1)) == 0) {
565
+ // We need to subtract 1 from the shift value in case of an unsigned
566
+ // branchfree divider because there is a hardcoded right shift by 1
567
+ // in its division algorithm. Because of this we also need to add back
568
+ // 1 in its recovery algorithm.
569
+ result.magic = 0;
570
+ result.more = (uint8_t)(floor_log_2_d - (branchfree != 0));
571
+ } else {
572
+ uint8_t more;
573
+ uint32_t rem, proposed_m;
574
+ proposed_m = libdivide_64_div_32_to_32(1U << floor_log_2_d, 0, d, &rem);
575
+
576
+ LIBDIVIDE_ASSERT(rem > 0 && rem < d);
577
+ const uint32_t e = d - rem;
578
+
579
+ // This power works if e < 2**floor_log_2_d.
580
+ if (!branchfree && (e < (1U << floor_log_2_d))) {
581
+ // This power works
582
+ more = floor_log_2_d;
583
+ } else {
584
+ // We have to use the general 33-bit algorithm. We need to compute
585
+ // (2**power) / d. However, we already have (2**(power-1))/d and
586
+ // its remainder. By doubling both, and then correcting the
587
+ // remainder, we can compute the larger division.
588
+ // don't care about overflow here - in fact, we expect it
589
+ proposed_m += proposed_m;
590
+ const uint32_t twice_rem = rem + rem;
591
+ if (twice_rem >= d || twice_rem < rem) proposed_m += 1;
592
+ more = floor_log_2_d | LIBDIVIDE_ADD_MARKER;
593
+ }
594
+ result.magic = 1 + proposed_m;
595
+ result.more = more;
596
+ // result.more's shift should in general be ceil_log_2_d. But if we
597
+ // used the smaller power, we subtract one from the shift because we're
598
+ // using the smaller power. If we're using the larger power, we
599
+ // subtract one from the shift because it's taken care of by the add
600
+ // indicator. So floor_log_2_d happens to be correct in both cases.
601
+ }
602
+ return result;
603
+ }
604
+
605
+ struct libdivide_u32_t libdivide_u32_gen(uint32_t d) {
606
+ return libdivide_internal_u32_gen(d, 0);
607
+ }
608
+
609
+ struct libdivide_u32_branchfree_t libdivide_u32_branchfree_gen(uint32_t d) {
610
+ if (d == 1) {
611
+ LIBDIVIDE_ERROR("branchfree divider must be != 1");
612
+ }
613
+ struct libdivide_u32_t tmp = libdivide_internal_u32_gen(d, 1);
614
+ struct libdivide_u32_branchfree_t ret = {tmp.magic, (uint8_t)(tmp.more & LIBDIVIDE_32_SHIFT_MASK)};
615
+ return ret;
616
+ }
617
+
618
+ uint32_t libdivide_u32_do(uint32_t numer, const struct libdivide_u32_t *denom) {
619
+ uint8_t more = denom->more;
620
+ if (!denom->magic) {
621
+ return numer >> more;
622
+ }
623
+ else {
624
+ uint32_t q = libdivide_mullhi_u32(denom->magic, numer);
625
+ if (more & LIBDIVIDE_ADD_MARKER) {
626
+ uint32_t t = ((numer - q) >> 1) + q;
627
+ return t >> (more & LIBDIVIDE_32_SHIFT_MASK);
628
+ }
629
+ else {
630
+ // All upper bits are 0,
631
+ // don't need to mask them off.
632
+ return q >> more;
633
+ }
634
+ }
635
+ }
636
+
637
+ uint32_t libdivide_u32_branchfree_do(uint32_t numer, const struct libdivide_u32_branchfree_t *denom) {
638
+ uint32_t q = libdivide_mullhi_u32(denom->magic, numer);
639
+ uint32_t t = ((numer - q) >> 1) + q;
640
+ return t >> denom->more;
641
+ }
642
+
643
+ uint32_t libdivide_u32_recover(const struct libdivide_u32_t *denom) {
644
+ uint8_t more = denom->more;
645
+ uint8_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
646
+
647
+ if (!denom->magic) {
648
+ return 1U << shift;
649
+ } else if (!(more & LIBDIVIDE_ADD_MARKER)) {
650
+ // We compute q = n/d = n*m / 2^(32 + shift)
651
+ // Therefore we have d = 2^(32 + shift) / m
652
+ // We need to ceil it.
653
+ // We know d is not a power of 2, so m is not a power of 2,
654
+ // so we can just add 1 to the floor
655
+ uint32_t hi_dividend = 1U << shift;
656
+ uint32_t rem_ignored;
657
+ return 1 + libdivide_64_div_32_to_32(hi_dividend, 0, denom->magic, &rem_ignored);
658
+ } else {
659
+ // Here we wish to compute d = 2^(32+shift+1)/(m+2^32).
660
+ // Notice (m + 2^32) is a 33 bit number. Use 64 bit division for now
661
+ // Also note that shift may be as high as 31, so shift + 1 will
662
+ // overflow. So we have to compute it as 2^(32+shift)/(m+2^32), and
663
+ // then double the quotient and remainder.
664
+ uint64_t half_n = 1ULL << (32 + shift);
665
+ uint64_t d = (1ULL << 32) | denom->magic;
666
+ // Note that the quotient is guaranteed <= 32 bits, but the remainder
667
+ // may need 33!
668
+ uint32_t half_q = (uint32_t)(half_n / d);
669
+ uint64_t rem = half_n % d;
670
+ // We computed 2^(32+shift)/(m+2^32)
671
+ // Need to double it, and then add 1 to the quotient if doubling th
672
+ // remainder would increase the quotient.
673
+ // Note that rem<<1 cannot overflow, since rem < d and d is 33 bits
674
+ uint32_t full_q = half_q + half_q + ((rem<<1) >= d);
675
+
676
+ // We rounded down in gen (hence +1)
677
+ return full_q + 1;
678
+ }
679
+ }
680
+
681
+ uint32_t libdivide_u32_branchfree_recover(const struct libdivide_u32_branchfree_t *denom) {
682
+ uint8_t more = denom->more;
683
+ uint8_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
684
+
685
+ if (!denom->magic) {
686
+ return 1U << (shift + 1);
687
+ } else {
688
+ // Here we wish to compute d = 2^(32+shift+1)/(m+2^32).
689
+ // Notice (m + 2^32) is a 33 bit number. Use 64 bit division for now
690
+ // Also note that shift may be as high as 31, so shift + 1 will
691
+ // overflow. So we have to compute it as 2^(32+shift)/(m+2^32), and
692
+ // then double the quotient and remainder.
693
+ uint64_t half_n = 1ULL << (32 + shift);
694
+ uint64_t d = (1ULL << 32) | denom->magic;
695
+ // Note that the quotient is guaranteed <= 32 bits, but the remainder
696
+ // may need 33!
697
+ uint32_t half_q = (uint32_t)(half_n / d);
698
+ uint64_t rem = half_n % d;
699
+ // We computed 2^(32+shift)/(m+2^32)
700
+ // Need to double it, and then add 1 to the quotient if doubling th
701
+ // remainder would increase the quotient.
702
+ // Note that rem<<1 cannot overflow, since rem < d and d is 33 bits
703
+ uint32_t full_q = half_q + half_q + ((rem<<1) >= d);
704
+
705
+ // We rounded down in gen (hence +1)
706
+ return full_q + 1;
707
+ }
708
+ }
709
+
710
+ /////////// UINT64
711
+
712
+ static inline struct libdivide_u64_t libdivide_internal_u64_gen(uint64_t d, int branchfree) {
713
+ if (d == 0) {
714
+ LIBDIVIDE_ERROR("divider must be != 0");
715
+ }
716
+
717
+ struct libdivide_u64_t result;
718
+ uint32_t floor_log_2_d = 63 - libdivide_count_leading_zeros64(d);
719
+
720
+ // Power of 2
721
+ if ((d & (d - 1)) == 0) {
722
+ // We need to subtract 1 from the shift value in case of an unsigned
723
+ // branchfree divider because there is a hardcoded right shift by 1
724
+ // in its division algorithm. Because of this we also need to add back
725
+ // 1 in its recovery algorithm.
726
+ result.magic = 0;
727
+ result.more = (uint8_t)(floor_log_2_d - (branchfree != 0));
728
+ } else {
729
+ uint64_t proposed_m, rem;
730
+ uint8_t more;
731
+ // (1 << (64 + floor_log_2_d)) / d
732
+ proposed_m = libdivide_128_div_64_to_64(1ULL << floor_log_2_d, 0, d, &rem);
733
+
734
+ LIBDIVIDE_ASSERT(rem > 0 && rem < d);
735
+ const uint64_t e = d - rem;
736
+
737
+ // This power works if e < 2**floor_log_2_d.
738
+ if (!branchfree && e < (1ULL << floor_log_2_d)) {
739
+ // This power works
740
+ more = floor_log_2_d;
741
+ } else {
742
+ // We have to use the general 65-bit algorithm. We need to compute
743
+ // (2**power) / d. However, we already have (2**(power-1))/d and
744
+ // its remainder. By doubling both, and then correcting the
745
+ // remainder, we can compute the larger division.
746
+ // don't care about overflow here - in fact, we expect it
747
+ proposed_m += proposed_m;
748
+ const uint64_t twice_rem = rem + rem;
749
+ if (twice_rem >= d || twice_rem < rem) proposed_m += 1;
750
+ more = floor_log_2_d | LIBDIVIDE_ADD_MARKER;
751
+ }
752
+ result.magic = 1 + proposed_m;
753
+ result.more = more;
754
+ // result.more's shift should in general be ceil_log_2_d. But if we
755
+ // used the smaller power, we subtract one from the shift because we're
756
+ // using the smaller power. If we're using the larger power, we
757
+ // subtract one from the shift because it's taken care of by the add
758
+ // indicator. So floor_log_2_d happens to be correct in both cases,
759
+ // which is why we do it outside of the if statement.
760
+ }
761
+ return result;
762
+ }
763
+
764
+ struct libdivide_u64_t libdivide_u64_gen(uint64_t d) {
765
+ return libdivide_internal_u64_gen(d, 0);
766
+ }
767
+
768
+ struct libdivide_u64_branchfree_t libdivide_u64_branchfree_gen(uint64_t d) {
769
+ if (d == 1) {
770
+ LIBDIVIDE_ERROR("branchfree divider must be != 1");
771
+ }
772
+ struct libdivide_u64_t tmp = libdivide_internal_u64_gen(d, 1);
773
+ struct libdivide_u64_branchfree_t ret = {tmp.magic, (uint8_t)(tmp.more & LIBDIVIDE_64_SHIFT_MASK)};
774
+ return ret;
775
+ }
776
+
777
+ uint64_t libdivide_u64_do(uint64_t numer, const struct libdivide_u64_t *denom) {
778
+ uint8_t more = denom->more;
779
+ if (!denom->magic) {
780
+ return numer >> more;
781
+ }
782
+ else {
783
+ uint64_t q = libdivide_mullhi_u64(denom->magic, numer);
784
+ if (more & LIBDIVIDE_ADD_MARKER) {
785
+ uint64_t t = ((numer - q) >> 1) + q;
786
+ return t >> (more & LIBDIVIDE_64_SHIFT_MASK);
787
+ }
788
+ else {
789
+ // All upper bits are 0,
790
+ // don't need to mask them off.
791
+ return q >> more;
792
+ }
793
+ }
794
+ }
795
+
796
+ uint64_t libdivide_u64_branchfree_do(uint64_t numer, const struct libdivide_u64_branchfree_t *denom) {
797
+ uint64_t q = libdivide_mullhi_u64(denom->magic, numer);
798
+ uint64_t t = ((numer - q) >> 1) + q;
799
+ return t >> denom->more;
800
+ }
801
+
802
+ uint64_t libdivide_u64_recover(const struct libdivide_u64_t *denom) {
803
+ uint8_t more = denom->more;
804
+ uint8_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
805
+
806
+ if (!denom->magic) {
807
+ return 1ULL << shift;
808
+ } else if (!(more & LIBDIVIDE_ADD_MARKER)) {
809
+ // We compute q = n/d = n*m / 2^(64 + shift)
810
+ // Therefore we have d = 2^(64 + shift) / m
811
+ // We need to ceil it.
812
+ // We know d is not a power of 2, so m is not a power of 2,
813
+ // so we can just add 1 to the floor
814
+ uint64_t hi_dividend = 1ULL << shift;
815
+ uint64_t rem_ignored;
816
+ return 1 + libdivide_128_div_64_to_64(hi_dividend, 0, denom->magic, &rem_ignored);
817
+ } else {
818
+ // Here we wish to compute d = 2^(64+shift+1)/(m+2^64).
819
+ // Notice (m + 2^64) is a 65 bit number. This gets hairy. See
820
+ // libdivide_u32_recover for more on what we do here.
821
+ // TODO: do something better than 128 bit math
822
+
823
+ // Full n is a (potentially) 129 bit value
824
+ // half_n is a 128 bit value
825
+ // Compute the hi half of half_n. Low half is 0.
826
+ uint64_t half_n_hi = 1ULL << shift, half_n_lo = 0;
827
+ // d is a 65 bit value. The high bit is always set to 1.
828
+ const uint64_t d_hi = 1, d_lo = denom->magic;
829
+ // Note that the quotient is guaranteed <= 64 bits,
830
+ // but the remainder may need 65!
831
+ uint64_t r_hi, r_lo;
832
+ uint64_t half_q = libdivide_128_div_128_to_64(half_n_hi, half_n_lo, d_hi, d_lo, &r_hi, &r_lo);
833
+ // We computed 2^(64+shift)/(m+2^64)
834
+ // Double the remainder ('dr') and check if that is larger than d
835
+ // Note that d is a 65 bit value, so r1 is small and so r1 + r1
836
+ // cannot overflow
837
+ uint64_t dr_lo = r_lo + r_lo;
838
+ uint64_t dr_hi = r_hi + r_hi + (dr_lo < r_lo); // last term is carry
839
+ int dr_exceeds_d = (dr_hi > d_hi) || (dr_hi == d_hi && dr_lo >= d_lo);
840
+ uint64_t full_q = half_q + half_q + (dr_exceeds_d ? 1 : 0);
841
+ return full_q + 1;
842
+ }
843
+ }
844
+
845
+ uint64_t libdivide_u64_branchfree_recover(const struct libdivide_u64_branchfree_t *denom) {
846
+ uint8_t more = denom->more;
847
+ uint8_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
848
+
849
+ if (!denom->magic) {
850
+ return 1ULL << (shift + 1);
851
+ } else {
852
+ // Here we wish to compute d = 2^(64+shift+1)/(m+2^64).
853
+ // Notice (m + 2^64) is a 65 bit number. This gets hairy. See
854
+ // libdivide_u32_recover for more on what we do here.
855
+ // TODO: do something better than 128 bit math
856
+
857
+ // Full n is a (potentially) 129 bit value
858
+ // half_n is a 128 bit value
859
+ // Compute the hi half of half_n. Low half is 0.
860
+ uint64_t half_n_hi = 1ULL << shift, half_n_lo = 0;
861
+ // d is a 65 bit value. The high bit is always set to 1.
862
+ const uint64_t d_hi = 1, d_lo = denom->magic;
863
+ // Note that the quotient is guaranteed <= 64 bits,
864
+ // but the remainder may need 65!
865
+ uint64_t r_hi, r_lo;
866
+ uint64_t half_q = libdivide_128_div_128_to_64(half_n_hi, half_n_lo, d_hi, d_lo, &r_hi, &r_lo);
867
+ // We computed 2^(64+shift)/(m+2^64)
868
+ // Double the remainder ('dr') and check if that is larger than d
869
+ // Note that d is a 65 bit value, so r1 is small and so r1 + r1
870
+ // cannot overflow
871
+ uint64_t dr_lo = r_lo + r_lo;
872
+ uint64_t dr_hi = r_hi + r_hi + (dr_lo < r_lo); // last term is carry
873
+ int dr_exceeds_d = (dr_hi > d_hi) || (dr_hi == d_hi && dr_lo >= d_lo);
874
+ uint64_t full_q = half_q + half_q + (dr_exceeds_d ? 1 : 0);
875
+ return full_q + 1;
876
+ }
877
+ }
878
+
879
+ /////////// SINT32
880
+
881
+ static inline struct libdivide_s32_t libdivide_internal_s32_gen(int32_t d, int branchfree) {
882
+ if (d == 0) {
883
+ LIBDIVIDE_ERROR("divider must be != 0");
884
+ }
885
+
886
+ struct libdivide_s32_t result;
887
+
888
+ // If d is a power of 2, or negative a power of 2, we have to use a shift.
889
+ // This is especially important because the magic algorithm fails for -1.
890
+ // To check if d is a power of 2 or its inverse, it suffices to check
891
+ // whether its absolute value has exactly one bit set. This works even for
892
+ // INT_MIN, because abs(INT_MIN) == INT_MIN, and INT_MIN has one bit set
893
+ // and is a power of 2.
894
+ uint32_t ud = (uint32_t)d;
895
+ uint32_t absD = (d < 0) ? -ud : ud;
896
+ uint32_t floor_log_2_d = 31 - libdivide_count_leading_zeros32(absD);
897
+ // check if exactly one bit is set,
898
+ // don't care if absD is 0 since that's divide by zero
899
+ if ((absD & (absD - 1)) == 0) {
900
+ // Branchfree and normal paths are exactly the same
901
+ result.magic = 0;
902
+ result.more = floor_log_2_d | (d < 0 ? LIBDIVIDE_NEGATIVE_DIVISOR : 0);
903
+ } else {
904
+ LIBDIVIDE_ASSERT(floor_log_2_d >= 1);
905
+
906
+ uint8_t more;
907
+ // the dividend here is 2**(floor_log_2_d + 31), so the low 32 bit word
908
+ // is 0 and the high word is floor_log_2_d - 1
909
+ uint32_t rem, proposed_m;
910
+ proposed_m = libdivide_64_div_32_to_32(1U << (floor_log_2_d - 1), 0, absD, &rem);
911
+ const uint32_t e = absD - rem;
912
+
913
+ // We are going to start with a power of floor_log_2_d - 1.
914
+ // This works if works if e < 2**floor_log_2_d.
915
+ if (!branchfree && e < (1U << floor_log_2_d)) {
916
+ // This power works
917
+ more = floor_log_2_d - 1;
918
+ } else {
919
+ // We need to go one higher. This should not make proposed_m
920
+ // overflow, but it will make it negative when interpreted as an
921
+ // int32_t.
922
+ proposed_m += proposed_m;
923
+ const uint32_t twice_rem = rem + rem;
924
+ if (twice_rem >= absD || twice_rem < rem) proposed_m += 1;
925
+ more = floor_log_2_d | LIBDIVIDE_ADD_MARKER;
926
+ }
927
+
928
+ proposed_m += 1;
929
+ int32_t magic = (int32_t)proposed_m;
930
+
931
+ // Mark if we are negative. Note we only negate the magic number in the
932
+ // branchfull case.
933
+ if (d < 0) {
934
+ more |= LIBDIVIDE_NEGATIVE_DIVISOR;
935
+ if (!branchfree) {
936
+ magic = -magic;
937
+ }
938
+ }
939
+
940
+ result.more = more;
941
+ result.magic = magic;
942
+ }
943
+ return result;
944
+ }
945
+
946
+ struct libdivide_s32_t libdivide_s32_gen(int32_t d) {
947
+ return libdivide_internal_s32_gen(d, 0);
948
+ }
949
+
950
+ struct libdivide_s32_branchfree_t libdivide_s32_branchfree_gen(int32_t d) {
951
+ struct libdivide_s32_t tmp = libdivide_internal_s32_gen(d, 1);
952
+ struct libdivide_s32_branchfree_t result = {tmp.magic, tmp.more};
953
+ return result;
954
+ }
955
+
956
+ int32_t libdivide_s32_do(int32_t numer, const struct libdivide_s32_t *denom) {
957
+ uint8_t more = denom->more;
958
+ uint8_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
959
+
960
+ if (!denom->magic) {
961
+ uint32_t sign = (int8_t)more >> 7;
962
+ uint32_t mask = (1U << shift) - 1;
963
+ uint32_t uq = numer + ((numer >> 31) & mask);
964
+ int32_t q = (int32_t)uq;
965
+ q >>= shift;
966
+ q = (q ^ sign) - sign;
967
+ return q;
968
+ } else {
969
+ uint32_t uq = (uint32_t)libdivide_mullhi_s32(denom->magic, numer);
970
+ if (more & LIBDIVIDE_ADD_MARKER) {
971
+ // must be arithmetic shift and then sign extend
972
+ int32_t sign = (int8_t)more >> 7;
973
+ // q += (more < 0 ? -numer : numer)
974
+ // cast required to avoid UB
975
+ uq += ((uint32_t)numer ^ sign) - sign;
976
+ }
977
+ int32_t q = (int32_t)uq;
978
+ q >>= shift;
979
+ q += (q < 0);
980
+ return q;
981
+ }
982
+ }
983
+
984
+ int32_t libdivide_s32_branchfree_do(int32_t numer, const struct libdivide_s32_branchfree_t *denom) {
985
+ uint8_t more = denom->more;
986
+ uint8_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
987
+ // must be arithmetic shift and then sign extend
988
+ int32_t sign = (int8_t)more >> 7;
989
+ int32_t magic = denom->magic;
990
+ int32_t q = libdivide_mullhi_s32(magic, numer);
991
+ q += numer;
992
+
993
+ // If q is non-negative, we have nothing to do
994
+ // If q is negative, we want to add either (2**shift)-1 if d is a power of
995
+ // 2, or (2**shift) if it is not a power of 2
996
+ uint32_t is_power_of_2 = (magic == 0);
997
+ uint32_t q_sign = (uint32_t)(q >> 31);
998
+ q += q_sign & ((1U << shift) - is_power_of_2);
999
+
1000
+ // Now arithmetic right shift
1001
+ q >>= shift;
1002
+ // Negate if needed
1003
+ q = (q ^ sign) - sign;
1004
+
1005
+ return q;
1006
+ }
1007
+
1008
+ int32_t libdivide_s32_recover(const struct libdivide_s32_t *denom) {
1009
+ uint8_t more = denom->more;
1010
+ uint8_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
1011
+ if (!denom->magic) {
1012
+ uint32_t absD = 1U << shift;
1013
+ if (more & LIBDIVIDE_NEGATIVE_DIVISOR) {
1014
+ absD = -absD;
1015
+ }
1016
+ return (int32_t)absD;
1017
+ } else {
1018
+ // Unsigned math is much easier
1019
+ // We negate the magic number only in the branchfull case, and we don't
1020
+ // know which case we're in. However we have enough information to
1021
+ // determine the correct sign of the magic number. The divisor was
1022
+ // negative if LIBDIVIDE_NEGATIVE_DIVISOR is set. If ADD_MARKER is set,
1023
+ // the magic number's sign is opposite that of the divisor.
1024
+ // We want to compute the positive magic number.
1025
+ int negative_divisor = (more & LIBDIVIDE_NEGATIVE_DIVISOR);
1026
+ int magic_was_negated = (more & LIBDIVIDE_ADD_MARKER)
1027
+ ? denom->magic > 0 : denom->magic < 0;
1028
+
1029
+ // Handle the power of 2 case (including branchfree)
1030
+ if (denom->magic == 0) {
1031
+ int32_t result = 1U << shift;
1032
+ return negative_divisor ? -result : result;
1033
+ }
1034
+
1035
+ uint32_t d = (uint32_t)(magic_was_negated ? -denom->magic : denom->magic);
1036
+ uint64_t n = 1ULL << (32 + shift); // this shift cannot exceed 30
1037
+ uint32_t q = (uint32_t)(n / d);
1038
+ int32_t result = (int32_t)q;
1039
+ result += 1;
1040
+ return negative_divisor ? -result : result;
1041
+ }
1042
+ }
1043
+
1044
+ int32_t libdivide_s32_branchfree_recover(const struct libdivide_s32_branchfree_t *denom) {
1045
+ return libdivide_s32_recover((const struct libdivide_s32_t *)denom);
1046
+ }
1047
+
1048
+ ///////////// SINT64
1049
+
1050
+ static inline struct libdivide_s64_t libdivide_internal_s64_gen(int64_t d, int branchfree) {
1051
+ if (d == 0) {
1052
+ LIBDIVIDE_ERROR("divider must be != 0");
1053
+ }
1054
+
1055
+ struct libdivide_s64_t result;
1056
+
1057
+ // If d is a power of 2, or negative a power of 2, we have to use a shift.
1058
+ // This is especially important because the magic algorithm fails for -1.
1059
+ // To check if d is a power of 2 or its inverse, it suffices to check
1060
+ // whether its absolute value has exactly one bit set. This works even for
1061
+ // INT_MIN, because abs(INT_MIN) == INT_MIN, and INT_MIN has one bit set
1062
+ // and is a power of 2.
1063
+ uint64_t ud = (uint64_t)d;
1064
+ uint64_t absD = (d < 0) ? -ud : ud;
1065
+ uint32_t floor_log_2_d = 63 - libdivide_count_leading_zeros64(absD);
1066
+ // check if exactly one bit is set,
1067
+ // don't care if absD is 0 since that's divide by zero
1068
+ if ((absD & (absD - 1)) == 0) {
1069
+ // Branchfree and non-branchfree cases are the same
1070
+ result.magic = 0;
1071
+ result.more = floor_log_2_d | (d < 0 ? LIBDIVIDE_NEGATIVE_DIVISOR : 0);
1072
+ } else {
1073
+ // the dividend here is 2**(floor_log_2_d + 63), so the low 64 bit word
1074
+ // is 0 and the high word is floor_log_2_d - 1
1075
+ uint8_t more;
1076
+ uint64_t rem, proposed_m;
1077
+ proposed_m = libdivide_128_div_64_to_64(1ULL << (floor_log_2_d - 1), 0, absD, &rem);
1078
+ const uint64_t e = absD - rem;
1079
+
1080
+ // We are going to start with a power of floor_log_2_d - 1.
1081
+ // This works if works if e < 2**floor_log_2_d.
1082
+ if (!branchfree && e < (1ULL << floor_log_2_d)) {
1083
+ // This power works
1084
+ more = floor_log_2_d - 1;
1085
+ } else {
1086
+ // We need to go one higher. This should not make proposed_m
1087
+ // overflow, but it will make it negative when interpreted as an
1088
+ // int32_t.
1089
+ proposed_m += proposed_m;
1090
+ const uint64_t twice_rem = rem + rem;
1091
+ if (twice_rem >= absD || twice_rem < rem) proposed_m += 1;
1092
+ // note that we only set the LIBDIVIDE_NEGATIVE_DIVISOR bit if we
1093
+ // also set ADD_MARKER this is an annoying optimization that
1094
+ // enables algorithm #4 to avoid the mask. However we always set it
1095
+ // in the branchfree case
1096
+ more = floor_log_2_d | LIBDIVIDE_ADD_MARKER;
1097
+ }
1098
+ proposed_m += 1;
1099
+ int64_t magic = (int64_t)proposed_m;
1100
+
1101
+ // Mark if we are negative
1102
+ if (d < 0) {
1103
+ more |= LIBDIVIDE_NEGATIVE_DIVISOR;
1104
+ if (!branchfree) {
1105
+ magic = -magic;
1106
+ }
1107
+ }
1108
+
1109
+ result.more = more;
1110
+ result.magic = magic;
1111
+ }
1112
+ return result;
1113
+ }
1114
+
1115
+ struct libdivide_s64_t libdivide_s64_gen(int64_t d) {
1116
+ return libdivide_internal_s64_gen(d, 0);
1117
+ }
1118
+
1119
+ struct libdivide_s64_branchfree_t libdivide_s64_branchfree_gen(int64_t d) {
1120
+ struct libdivide_s64_t tmp = libdivide_internal_s64_gen(d, 1);
1121
+ struct libdivide_s64_branchfree_t ret = {tmp.magic, tmp.more};
1122
+ return ret;
1123
+ }
1124
+
1125
+ int64_t libdivide_s64_do(int64_t numer, const struct libdivide_s64_t *denom) {
1126
+ uint8_t more = denom->more;
1127
+ uint8_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
1128
+
1129
+ if (!denom->magic) { // shift path
1130
+ uint64_t mask = (1ULL << shift) - 1;
1131
+ uint64_t uq = numer + ((numer >> 63) & mask);
1132
+ int64_t q = (int64_t)uq;
1133
+ q >>= shift;
1134
+ // must be arithmetic shift and then sign-extend
1135
+ int64_t sign = (int8_t)more >> 7;
1136
+ q = (q ^ sign) - sign;
1137
+ return q;
1138
+ } else {
1139
+ uint64_t uq = (uint64_t)libdivide_mullhi_s64(denom->magic, numer);
1140
+ if (more & LIBDIVIDE_ADD_MARKER) {
1141
+ // must be arithmetic shift and then sign extend
1142
+ int64_t sign = (int8_t)more >> 7;
1143
+ // q += (more < 0 ? -numer : numer)
1144
+ // cast required to avoid UB
1145
+ uq += ((uint64_t)numer ^ sign) - sign;
1146
+ }
1147
+ int64_t q = (int64_t)uq;
1148
+ q >>= shift;
1149
+ q += (q < 0);
1150
+ return q;
1151
+ }
1152
+ }
1153
+
1154
+ int64_t libdivide_s64_branchfree_do(int64_t numer, const struct libdivide_s64_branchfree_t *denom) {
1155
+ uint8_t more = denom->more;
1156
+ uint8_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
1157
+ // must be arithmetic shift and then sign extend
1158
+ int64_t sign = (int8_t)more >> 7;
1159
+ int64_t magic = denom->magic;
1160
+ int64_t q = libdivide_mullhi_s64(magic, numer);
1161
+ q += numer;
1162
+
1163
+ // If q is non-negative, we have nothing to do.
1164
+ // If q is negative, we want to add either (2**shift)-1 if d is a power of
1165
+ // 2, or (2**shift) if it is not a power of 2.
1166
+ uint64_t is_power_of_2 = (magic == 0);
1167
+ uint64_t q_sign = (uint64_t)(q >> 63);
1168
+ q += q_sign & ((1ULL << shift) - is_power_of_2);
1169
+
1170
+ // Arithmetic right shift
1171
+ q >>= shift;
1172
+ // Negate if needed
1173
+ q = (q ^ sign) - sign;
1174
+
1175
+ return q;
1176
+ }
1177
+
1178
+ int64_t libdivide_s64_recover(const struct libdivide_s64_t *denom) {
1179
+ uint8_t more = denom->more;
1180
+ uint8_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
1181
+ if (denom->magic == 0) { // shift path
1182
+ uint64_t absD = 1ULL << shift;
1183
+ if (more & LIBDIVIDE_NEGATIVE_DIVISOR) {
1184
+ absD = -absD;
1185
+ }
1186
+ return (int64_t)absD;
1187
+ } else {
1188
+ // Unsigned math is much easier
1189
+ int negative_divisor = (more & LIBDIVIDE_NEGATIVE_DIVISOR);
1190
+ int magic_was_negated = (more & LIBDIVIDE_ADD_MARKER)
1191
+ ? denom->magic > 0 : denom->magic < 0;
1192
+
1193
+ uint64_t d = (uint64_t)(magic_was_negated ? -denom->magic : denom->magic);
1194
+ uint64_t n_hi = 1ULL << shift, n_lo = 0;
1195
+ uint64_t rem_ignored;
1196
+ uint64_t q = libdivide_128_div_64_to_64(n_hi, n_lo, d, &rem_ignored);
1197
+ int64_t result = (int64_t)(q + 1);
1198
+ if (negative_divisor) {
1199
+ result = -result;
1200
+ }
1201
+ return result;
1202
+ }
1203
+ }
1204
+
1205
+ int64_t libdivide_s64_branchfree_recover(const struct libdivide_s64_branchfree_t *denom) {
1206
+ return libdivide_s64_recover((const struct libdivide_s64_t *)denom);
1207
+ }
1208
+
1209
+ #if defined(LIBDIVIDE_AVX512)
1210
+
1211
+ static inline __m512i libdivide_u32_do_vector(__m512i numers, const struct libdivide_u32_t *denom);
1212
+ static inline __m512i libdivide_s32_do_vector(__m512i numers, const struct libdivide_s32_t *denom);
1213
+ static inline __m512i libdivide_u64_do_vector(__m512i numers, const struct libdivide_u64_t *denom);
1214
+ static inline __m512i libdivide_s64_do_vector(__m512i numers, const struct libdivide_s64_t *denom);
1215
+
1216
+ static inline __m512i libdivide_u32_branchfree_do_vector(__m512i numers, const struct libdivide_u32_branchfree_t *denom);
1217
+ static inline __m512i libdivide_s32_branchfree_do_vector(__m512i numers, const struct libdivide_s32_branchfree_t *denom);
1218
+ static inline __m512i libdivide_u64_branchfree_do_vector(__m512i numers, const struct libdivide_u64_branchfree_t *denom);
1219
+ static inline __m512i libdivide_s64_branchfree_do_vector(__m512i numers, const struct libdivide_s64_branchfree_t *denom);
1220
+
1221
+ //////// Internal Utility Functions
1222
+
1223
+ static inline __m512i libdivide_s64_signbits(__m512i v) {;
1224
+ return _mm512_srai_epi64(v, 63);
1225
+ }
1226
+
1227
+ static inline __m512i libdivide_s64_shift_right_vector(__m512i v, int amt) {
1228
+ return _mm512_srai_epi64(v, amt);
1229
+ }
1230
+
1231
+ // Here, b is assumed to contain one 32-bit value repeated.
1232
+ static inline __m512i libdivide_mullhi_u32_vector(__m512i a, __m512i b) {
1233
+ __m512i hi_product_0Z2Z = _mm512_srli_epi64(_mm512_mul_epu32(a, b), 32);
1234
+ __m512i a1X3X = _mm512_srli_epi64(a, 32);
1235
+ __m512i mask = _mm512_set_epi32(-1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0);
1236
+ __m512i hi_product_Z1Z3 = _mm512_and_si512(_mm512_mul_epu32(a1X3X, b), mask);
1237
+ return _mm512_or_si512(hi_product_0Z2Z, hi_product_Z1Z3);
1238
+ }
1239
+
1240
+ // b is one 32-bit value repeated.
1241
+ static inline __m512i libdivide_mullhi_s32_vector(__m512i a, __m512i b) {
1242
+ __m512i hi_product_0Z2Z = _mm512_srli_epi64(_mm512_mul_epi32(a, b), 32);
1243
+ __m512i a1X3X = _mm512_srli_epi64(a, 32);
1244
+ __m512i mask = _mm512_set_epi32(-1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0);
1245
+ __m512i hi_product_Z1Z3 = _mm512_and_si512(_mm512_mul_epi32(a1X3X, b), mask);
1246
+ return _mm512_or_si512(hi_product_0Z2Z, hi_product_Z1Z3);
1247
+ }
1248
+
1249
+ // Here, y is assumed to contain one 64-bit value repeated.
1250
+ // https://stackoverflow.com/a/28827013
1251
+ static inline __m512i libdivide_mullhi_u64_vector(__m512i x, __m512i y) {
1252
+ __m512i lomask = _mm512_set1_epi64(0xffffffff);
1253
+ __m512i xh = _mm512_shuffle_epi32(x, (_MM_PERM_ENUM) 0xB1);
1254
+ __m512i yh = _mm512_shuffle_epi32(y, (_MM_PERM_ENUM) 0xB1);
1255
+ __m512i w0 = _mm512_mul_epu32(x, y);
1256
+ __m512i w1 = _mm512_mul_epu32(x, yh);
1257
+ __m512i w2 = _mm512_mul_epu32(xh, y);
1258
+ __m512i w3 = _mm512_mul_epu32(xh, yh);
1259
+ __m512i w0h = _mm512_srli_epi64(w0, 32);
1260
+ __m512i s1 = _mm512_add_epi64(w1, w0h);
1261
+ __m512i s1l = _mm512_and_si512(s1, lomask);
1262
+ __m512i s1h = _mm512_srli_epi64(s1, 32);
1263
+ __m512i s2 = _mm512_add_epi64(w2, s1l);
1264
+ __m512i s2h = _mm512_srli_epi64(s2, 32);
1265
+ __m512i hi = _mm512_add_epi64(w3, s1h);
1266
+ hi = _mm512_add_epi64(hi, s2h);
1267
+
1268
+ return hi;
1269
+ }
1270
+
1271
+ // y is one 64-bit value repeated.
1272
+ static inline __m512i libdivide_mullhi_s64_vector(__m512i x, __m512i y) {
1273
+ __m512i p = libdivide_mullhi_u64_vector(x, y);
1274
+ __m512i t1 = _mm512_and_si512(libdivide_s64_signbits(x), y);
1275
+ __m512i t2 = _mm512_and_si512(libdivide_s64_signbits(y), x);
1276
+ p = _mm512_sub_epi64(p, t1);
1277
+ p = _mm512_sub_epi64(p, t2);
1278
+ return p;
1279
+ }
1280
+
1281
+ ////////// UINT32
1282
+
1283
+ __m512i libdivide_u32_do_vector(__m512i numers, const struct libdivide_u32_t *denom) {
1284
+ uint8_t more = denom->more;
1285
+ if (!denom->magic) {
1286
+ return _mm512_srli_epi32(numers, more);
1287
+ }
1288
+ else {
1289
+ __m512i q = libdivide_mullhi_u32_vector(numers, _mm512_set1_epi32(denom->magic));
1290
+ if (more & LIBDIVIDE_ADD_MARKER) {
1291
+ // uint32_t t = ((numer - q) >> 1) + q;
1292
+ // return t >> denom->shift;
1293
+ uint32_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
1294
+ __m512i t = _mm512_add_epi32(_mm512_srli_epi32(_mm512_sub_epi32(numers, q), 1), q);
1295
+ return _mm512_srli_epi32(t, shift);
1296
+ }
1297
+ else {
1298
+ return _mm512_srli_epi32(q, more);
1299
+ }
1300
+ }
1301
+ }
1302
+
1303
+ __m512i libdivide_u32_branchfree_do_vector(__m512i numers, const struct libdivide_u32_branchfree_t *denom) {
1304
+ __m512i q = libdivide_mullhi_u32_vector(numers, _mm512_set1_epi32(denom->magic));
1305
+ __m512i t = _mm512_add_epi32(_mm512_srli_epi32(_mm512_sub_epi32(numers, q), 1), q);
1306
+ return _mm512_srli_epi32(t, denom->more);
1307
+ }
1308
+
1309
+ ////////// UINT64
1310
+
1311
+ __m512i libdivide_u64_do_vector(__m512i numers, const struct libdivide_u64_t *denom) {
1312
+ uint8_t more = denom->more;
1313
+ if (!denom->magic) {
1314
+ return _mm512_srli_epi64(numers, more);
1315
+ }
1316
+ else {
1317
+ __m512i q = libdivide_mullhi_u64_vector(numers, _mm512_set1_epi64(denom->magic));
1318
+ if (more & LIBDIVIDE_ADD_MARKER) {
1319
+ // uint32_t t = ((numer - q) >> 1) + q;
1320
+ // return t >> denom->shift;
1321
+ uint32_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
1322
+ __m512i t = _mm512_add_epi64(_mm512_srli_epi64(_mm512_sub_epi64(numers, q), 1), q);
1323
+ return _mm512_srli_epi64(t, shift);
1324
+ }
1325
+ else {
1326
+ return _mm512_srli_epi64(q, more);
1327
+ }
1328
+ }
1329
+ }
1330
+
1331
+ __m512i libdivide_u64_branchfree_do_vector(__m512i numers, const struct libdivide_u64_branchfree_t *denom) {
1332
+ __m512i q = libdivide_mullhi_u64_vector(numers, _mm512_set1_epi64(denom->magic));
1333
+ __m512i t = _mm512_add_epi64(_mm512_srli_epi64(_mm512_sub_epi64(numers, q), 1), q);
1334
+ return _mm512_srli_epi64(t, denom->more);
1335
+ }
1336
+
1337
+ ////////// SINT32
1338
+
1339
+ __m512i libdivide_s32_do_vector(__m512i numers, const struct libdivide_s32_t *denom) {
1340
+ uint8_t more = denom->more;
1341
+ if (!denom->magic) {
1342
+ uint32_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
1343
+ uint32_t mask = (1U << shift) - 1;
1344
+ __m512i roundToZeroTweak = _mm512_set1_epi32(mask);
1345
+ // q = numer + ((numer >> 31) & roundToZeroTweak);
1346
+ __m512i q = _mm512_add_epi32(numers, _mm512_and_si512(_mm512_srai_epi32(numers, 31), roundToZeroTweak));
1347
+ q = _mm512_srai_epi32(q, shift);
1348
+ __m512i sign = _mm512_set1_epi32((int8_t)more >> 7);
1349
+ // q = (q ^ sign) - sign;
1350
+ q = _mm512_sub_epi32(_mm512_xor_si512(q, sign), sign);
1351
+ return q;
1352
+ }
1353
+ else {
1354
+ __m512i q = libdivide_mullhi_s32_vector(numers, _mm512_set1_epi32(denom->magic));
1355
+ if (more & LIBDIVIDE_ADD_MARKER) {
1356
+ // must be arithmetic shift
1357
+ __m512i sign = _mm512_set1_epi32((int8_t)more >> 7);
1358
+ // q += ((numer ^ sign) - sign);
1359
+ q = _mm512_add_epi32(q, _mm512_sub_epi32(_mm512_xor_si512(numers, sign), sign));
1360
+ }
1361
+ // q >>= shift
1362
+ q = _mm512_srai_epi32(q, more & LIBDIVIDE_32_SHIFT_MASK);
1363
+ q = _mm512_add_epi32(q, _mm512_srli_epi32(q, 31)); // q += (q < 0)
1364
+ return q;
1365
+ }
1366
+ }
1367
+
1368
+ __m512i libdivide_s32_branchfree_do_vector(__m512i numers, const struct libdivide_s32_branchfree_t *denom) {
1369
+ int32_t magic = denom->magic;
1370
+ uint8_t more = denom->more;
1371
+ uint8_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
1372
+ // must be arithmetic shift
1373
+ __m512i sign = _mm512_set1_epi32((int8_t)more >> 7);
1374
+ __m512i q = libdivide_mullhi_s32_vector(numers, _mm512_set1_epi32(magic));
1375
+ q = _mm512_add_epi32(q, numers); // q += numers
1376
+
1377
+ // If q is non-negative, we have nothing to do
1378
+ // If q is negative, we want to add either (2**shift)-1 if d is
1379
+ // a power of 2, or (2**shift) if it is not a power of 2
1380
+ uint32_t is_power_of_2 = (magic == 0);
1381
+ __m512i q_sign = _mm512_srai_epi32(q, 31); // q_sign = q >> 31
1382
+ __m512i mask = _mm512_set1_epi32((1U << shift) - is_power_of_2);
1383
+ q = _mm512_add_epi32(q, _mm512_and_si512(q_sign, mask)); // q = q + (q_sign & mask)
1384
+ q = _mm512_srai_epi32(q, shift); // q >>= shift
1385
+ q = _mm512_sub_epi32(_mm512_xor_si512(q, sign), sign); // q = (q ^ sign) - sign
1386
+ return q;
1387
+ }
1388
+
1389
+ ////////// SINT64
1390
+
1391
+ __m512i libdivide_s64_do_vector(__m512i numers, const struct libdivide_s64_t *denom) {
1392
+ uint8_t more = denom->more;
1393
+ int64_t magic = denom->magic;
1394
+ if (magic == 0) { // shift path
1395
+ uint32_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
1396
+ uint64_t mask = (1ULL << shift) - 1;
1397
+ __m512i roundToZeroTweak = _mm512_set1_epi64(mask);
1398
+ // q = numer + ((numer >> 63) & roundToZeroTweak);
1399
+ __m512i q = _mm512_add_epi64(numers, _mm512_and_si512(libdivide_s64_signbits(numers), roundToZeroTweak));
1400
+ q = libdivide_s64_shift_right_vector(q, shift);
1401
+ __m512i sign = _mm512_set1_epi32((int8_t)more >> 7);
1402
+ // q = (q ^ sign) - sign;
1403
+ q = _mm512_sub_epi64(_mm512_xor_si512(q, sign), sign);
1404
+ return q;
1405
+ }
1406
+ else {
1407
+ __m512i q = libdivide_mullhi_s64_vector(numers, _mm512_set1_epi64(magic));
1408
+ if (more & LIBDIVIDE_ADD_MARKER) {
1409
+ // must be arithmetic shift
1410
+ __m512i sign = _mm512_set1_epi32((int8_t)more >> 7);
1411
+ // q += ((numer ^ sign) - sign);
1412
+ q = _mm512_add_epi64(q, _mm512_sub_epi64(_mm512_xor_si512(numers, sign), sign));
1413
+ }
1414
+ // q >>= denom->mult_path.shift
1415
+ q = libdivide_s64_shift_right_vector(q, more & LIBDIVIDE_64_SHIFT_MASK);
1416
+ q = _mm512_add_epi64(q, _mm512_srli_epi64(q, 63)); // q += (q < 0)
1417
+ return q;
1418
+ }
1419
+ }
1420
+
1421
+ __m512i libdivide_s64_branchfree_do_vector(__m512i numers, const struct libdivide_s64_branchfree_t *denom) {
1422
+ int64_t magic = denom->magic;
1423
+ uint8_t more = denom->more;
1424
+ uint8_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
1425
+ // must be arithmetic shift
1426
+ __m512i sign = _mm512_set1_epi32((int8_t)more >> 7);
1427
+
1428
+ // libdivide_mullhi_s64(numers, magic);
1429
+ __m512i q = libdivide_mullhi_s64_vector(numers, _mm512_set1_epi64(magic));
1430
+ q = _mm512_add_epi64(q, numers); // q += numers
1431
+
1432
+ // If q is non-negative, we have nothing to do.
1433
+ // If q is negative, we want to add either (2**shift)-1 if d is
1434
+ // a power of 2, or (2**shift) if it is not a power of 2.
1435
+ uint32_t is_power_of_2 = (magic == 0);
1436
+ __m512i q_sign = libdivide_s64_signbits(q); // q_sign = q >> 63
1437
+ __m512i mask = _mm512_set1_epi64((1ULL << shift) - is_power_of_2);
1438
+ q = _mm512_add_epi64(q, _mm512_and_si512(q_sign, mask)); // q = q + (q_sign & mask)
1439
+ q = libdivide_s64_shift_right_vector(q, shift); // q >>= shift
1440
+ q = _mm512_sub_epi64(_mm512_xor_si512(q, sign), sign); // q = (q ^ sign) - sign
1441
+ return q;
1442
+ }
1443
+
1444
+ #elif defined(LIBDIVIDE_AVX2)
1445
+
1446
+ static inline __m256i libdivide_u32_do_vector(__m256i numers, const struct libdivide_u32_t *denom);
1447
+ static inline __m256i libdivide_s32_do_vector(__m256i numers, const struct libdivide_s32_t *denom);
1448
+ static inline __m256i libdivide_u64_do_vector(__m256i numers, const struct libdivide_u64_t *denom);
1449
+ static inline __m256i libdivide_s64_do_vector(__m256i numers, const struct libdivide_s64_t *denom);
1450
+
1451
+ static inline __m256i libdivide_u32_branchfree_do_vector(__m256i numers, const struct libdivide_u32_branchfree_t *denom);
1452
+ static inline __m256i libdivide_s32_branchfree_do_vector(__m256i numers, const struct libdivide_s32_branchfree_t *denom);
1453
+ static inline __m256i libdivide_u64_branchfree_do_vector(__m256i numers, const struct libdivide_u64_branchfree_t *denom);
1454
+ static inline __m256i libdivide_s64_branchfree_do_vector(__m256i numers, const struct libdivide_s64_branchfree_t *denom);
1455
+
1456
+ //////// Internal Utility Functions
1457
+
1458
+ // Implementation of _mm256_srai_epi64(v, 63) (from AVX512).
1459
+ static inline __m256i libdivide_s64_signbits(__m256i v) {
1460
+ __m256i hiBitsDuped = _mm256_shuffle_epi32(v, _MM_SHUFFLE(3, 3, 1, 1));
1461
+ __m256i signBits = _mm256_srai_epi32(hiBitsDuped, 31);
1462
+ return signBits;
1463
+ }
1464
+
1465
+ // Implementation of _mm256_srai_epi64 (from AVX512).
1466
+ static inline __m256i libdivide_s64_shift_right_vector(__m256i v, int amt) {
1467
+ const int b = 64 - amt;
1468
+ __m256i m = _mm256_set1_epi64x(1ULL << (b - 1));
1469
+ __m256i x = _mm256_srli_epi64(v, amt);
1470
+ __m256i result = _mm256_sub_epi64(_mm256_xor_si256(x, m), m);
1471
+ return result;
1472
+ }
1473
+
1474
+ // Here, b is assumed to contain one 32-bit value repeated.
1475
+ static inline __m256i libdivide_mullhi_u32_vector(__m256i a, __m256i b) {
1476
+ __m256i hi_product_0Z2Z = _mm256_srli_epi64(_mm256_mul_epu32(a, b), 32);
1477
+ __m256i a1X3X = _mm256_srli_epi64(a, 32);
1478
+ __m256i mask = _mm256_set_epi32(-1, 0, -1, 0, -1, 0, -1, 0);
1479
+ __m256i hi_product_Z1Z3 = _mm256_and_si256(_mm256_mul_epu32(a1X3X, b), mask);
1480
+ return _mm256_or_si256(hi_product_0Z2Z, hi_product_Z1Z3);
1481
+ }
1482
+
1483
+ // b is one 32-bit value repeated.
1484
+ static inline __m256i libdivide_mullhi_s32_vector(__m256i a, __m256i b) {
1485
+ __m256i hi_product_0Z2Z = _mm256_srli_epi64(_mm256_mul_epi32(a, b), 32);
1486
+ __m256i a1X3X = _mm256_srli_epi64(a, 32);
1487
+ __m256i mask = _mm256_set_epi32(-1, 0, -1, 0, -1, 0, -1, 0);
1488
+ __m256i hi_product_Z1Z3 = _mm256_and_si256(_mm256_mul_epi32(a1X3X, b), mask);
1489
+ return _mm256_or_si256(hi_product_0Z2Z, hi_product_Z1Z3);
1490
+ }
1491
+
1492
+ // Here, y is assumed to contain one 64-bit value repeated.
1493
+ // https://stackoverflow.com/a/28827013
1494
+ static inline __m256i libdivide_mullhi_u64_vector(__m256i x, __m256i y) {
1495
+ __m256i lomask = _mm256_set1_epi64x(0xffffffff);
1496
+ __m256i xh = _mm256_shuffle_epi32(x, 0xB1); // x0l, x0h, x1l, x1h
1497
+ __m256i yh = _mm256_shuffle_epi32(y, 0xB1); // y0l, y0h, y1l, y1h
1498
+ __m256i w0 = _mm256_mul_epu32(x, y); // x0l*y0l, x1l*y1l
1499
+ __m256i w1 = _mm256_mul_epu32(x, yh); // x0l*y0h, x1l*y1h
1500
+ __m256i w2 = _mm256_mul_epu32(xh, y); // x0h*y0l, x1h*y0l
1501
+ __m256i w3 = _mm256_mul_epu32(xh, yh); // x0h*y0h, x1h*y1h
1502
+ __m256i w0h = _mm256_srli_epi64(w0, 32);
1503
+ __m256i s1 = _mm256_add_epi64(w1, w0h);
1504
+ __m256i s1l = _mm256_and_si256(s1, lomask);
1505
+ __m256i s1h = _mm256_srli_epi64(s1, 32);
1506
+ __m256i s2 = _mm256_add_epi64(w2, s1l);
1507
+ __m256i s2h = _mm256_srli_epi64(s2, 32);
1508
+ __m256i hi = _mm256_add_epi64(w3, s1h);
1509
+ hi = _mm256_add_epi64(hi, s2h);
1510
+
1511
+ return hi;
1512
+ }
1513
+
1514
+ // y is one 64-bit value repeated.
1515
+ static inline __m256i libdivide_mullhi_s64_vector(__m256i x, __m256i y) {
1516
+ __m256i p = libdivide_mullhi_u64_vector(x, y);
1517
+ __m256i t1 = _mm256_and_si256(libdivide_s64_signbits(x), y);
1518
+ __m256i t2 = _mm256_and_si256(libdivide_s64_signbits(y), x);
1519
+ p = _mm256_sub_epi64(p, t1);
1520
+ p = _mm256_sub_epi64(p, t2);
1521
+ return p;
1522
+ }
1523
+
1524
+ ////////// UINT32
1525
+
1526
+ __m256i libdivide_u32_do_vector(__m256i numers, const struct libdivide_u32_t *denom) {
1527
+ uint8_t more = denom->more;
1528
+ if (!denom->magic) {
1529
+ return _mm256_srli_epi32(numers, more);
1530
+ }
1531
+ else {
1532
+ __m256i q = libdivide_mullhi_u32_vector(numers, _mm256_set1_epi32(denom->magic));
1533
+ if (more & LIBDIVIDE_ADD_MARKER) {
1534
+ // uint32_t t = ((numer - q) >> 1) + q;
1535
+ // return t >> denom->shift;
1536
+ uint32_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
1537
+ __m256i t = _mm256_add_epi32(_mm256_srli_epi32(_mm256_sub_epi32(numers, q), 1), q);
1538
+ return _mm256_srli_epi32(t, shift);
1539
+ }
1540
+ else {
1541
+ return _mm256_srli_epi32(q, more);
1542
+ }
1543
+ }
1544
+ }
1545
+
1546
+ __m256i libdivide_u32_branchfree_do_vector(__m256i numers, const struct libdivide_u32_branchfree_t *denom) {
1547
+ __m256i q = libdivide_mullhi_u32_vector(numers, _mm256_set1_epi32(denom->magic));
1548
+ __m256i t = _mm256_add_epi32(_mm256_srli_epi32(_mm256_sub_epi32(numers, q), 1), q);
1549
+ return _mm256_srli_epi32(t, denom->more);
1550
+ }
1551
+
1552
+ ////////// UINT64
1553
+
1554
+ __m256i libdivide_u64_do_vector(__m256i numers, const struct libdivide_u64_t *denom) {
1555
+ uint8_t more = denom->more;
1556
+ if (!denom->magic) {
1557
+ return _mm256_srli_epi64(numers, more);
1558
+ }
1559
+ else {
1560
+ __m256i q = libdivide_mullhi_u64_vector(numers, _mm256_set1_epi64x(denom->magic));
1561
+ if (more & LIBDIVIDE_ADD_MARKER) {
1562
+ // uint32_t t = ((numer - q) >> 1) + q;
1563
+ // return t >> denom->shift;
1564
+ uint32_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
1565
+ __m256i t = _mm256_add_epi64(_mm256_srli_epi64(_mm256_sub_epi64(numers, q), 1), q);
1566
+ return _mm256_srli_epi64(t, shift);
1567
+ }
1568
+ else {
1569
+ return _mm256_srli_epi64(q, more);
1570
+ }
1571
+ }
1572
+ }
1573
+
1574
+ __m256i libdivide_u64_branchfree_do_vector(__m256i numers, const struct libdivide_u64_branchfree_t *denom) {
1575
+ __m256i q = libdivide_mullhi_u64_vector(numers, _mm256_set1_epi64x(denom->magic));
1576
+ __m256i t = _mm256_add_epi64(_mm256_srli_epi64(_mm256_sub_epi64(numers, q), 1), q);
1577
+ return _mm256_srli_epi64(t, denom->more);
1578
+ }
1579
+
1580
+ ////////// SINT32
1581
+
1582
+ __m256i libdivide_s32_do_vector(__m256i numers, const struct libdivide_s32_t *denom) {
1583
+ uint8_t more = denom->more;
1584
+ if (!denom->magic) {
1585
+ uint32_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
1586
+ uint32_t mask = (1U << shift) - 1;
1587
+ __m256i roundToZeroTweak = _mm256_set1_epi32(mask);
1588
+ // q = numer + ((numer >> 31) & roundToZeroTweak);
1589
+ __m256i q = _mm256_add_epi32(numers, _mm256_and_si256(_mm256_srai_epi32(numers, 31), roundToZeroTweak));
1590
+ q = _mm256_srai_epi32(q, shift);
1591
+ __m256i sign = _mm256_set1_epi32((int8_t)more >> 7);
1592
+ // q = (q ^ sign) - sign;
1593
+ q = _mm256_sub_epi32(_mm256_xor_si256(q, sign), sign);
1594
+ return q;
1595
+ }
1596
+ else {
1597
+ __m256i q = libdivide_mullhi_s32_vector(numers, _mm256_set1_epi32(denom->magic));
1598
+ if (more & LIBDIVIDE_ADD_MARKER) {
1599
+ // must be arithmetic shift
1600
+ __m256i sign = _mm256_set1_epi32((int8_t)more >> 7);
1601
+ // q += ((numer ^ sign) - sign);
1602
+ q = _mm256_add_epi32(q, _mm256_sub_epi32(_mm256_xor_si256(numers, sign), sign));
1603
+ }
1604
+ // q >>= shift
1605
+ q = _mm256_srai_epi32(q, more & LIBDIVIDE_32_SHIFT_MASK);
1606
+ q = _mm256_add_epi32(q, _mm256_srli_epi32(q, 31)); // q += (q < 0)
1607
+ return q;
1608
+ }
1609
+ }
1610
+
1611
+ __m256i libdivide_s32_branchfree_do_vector(__m256i numers, const struct libdivide_s32_branchfree_t *denom) {
1612
+ int32_t magic = denom->magic;
1613
+ uint8_t more = denom->more;
1614
+ uint8_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
1615
+ // must be arithmetic shift
1616
+ __m256i sign = _mm256_set1_epi32((int8_t)more >> 7);
1617
+ __m256i q = libdivide_mullhi_s32_vector(numers, _mm256_set1_epi32(magic));
1618
+ q = _mm256_add_epi32(q, numers); // q += numers
1619
+
1620
+ // If q is non-negative, we have nothing to do
1621
+ // If q is negative, we want to add either (2**shift)-1 if d is
1622
+ // a power of 2, or (2**shift) if it is not a power of 2
1623
+ uint32_t is_power_of_2 = (magic == 0);
1624
+ __m256i q_sign = _mm256_srai_epi32(q, 31); // q_sign = q >> 31
1625
+ __m256i mask = _mm256_set1_epi32((1U << shift) - is_power_of_2);
1626
+ q = _mm256_add_epi32(q, _mm256_and_si256(q_sign, mask)); // q = q + (q_sign & mask)
1627
+ q = _mm256_srai_epi32(q, shift); // q >>= shift
1628
+ q = _mm256_sub_epi32(_mm256_xor_si256(q, sign), sign); // q = (q ^ sign) - sign
1629
+ return q;
1630
+ }
1631
+
1632
+ ////////// SINT64
1633
+
1634
+ __m256i libdivide_s64_do_vector(__m256i numers, const struct libdivide_s64_t *denom) {
1635
+ uint8_t more = denom->more;
1636
+ int64_t magic = denom->magic;
1637
+ if (magic == 0) { // shift path
1638
+ uint32_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
1639
+ uint64_t mask = (1ULL << shift) - 1;
1640
+ __m256i roundToZeroTweak = _mm256_set1_epi64x(mask);
1641
+ // q = numer + ((numer >> 63) & roundToZeroTweak);
1642
+ __m256i q = _mm256_add_epi64(numers, _mm256_and_si256(libdivide_s64_signbits(numers), roundToZeroTweak));
1643
+ q = libdivide_s64_shift_right_vector(q, shift);
1644
+ __m256i sign = _mm256_set1_epi32((int8_t)more >> 7);
1645
+ // q = (q ^ sign) - sign;
1646
+ q = _mm256_sub_epi64(_mm256_xor_si256(q, sign), sign);
1647
+ return q;
1648
+ }
1649
+ else {
1650
+ __m256i q = libdivide_mullhi_s64_vector(numers, _mm256_set1_epi64x(magic));
1651
+ if (more & LIBDIVIDE_ADD_MARKER) {
1652
+ // must be arithmetic shift
1653
+ __m256i sign = _mm256_set1_epi32((int8_t)more >> 7);
1654
+ // q += ((numer ^ sign) - sign);
1655
+ q = _mm256_add_epi64(q, _mm256_sub_epi64(_mm256_xor_si256(numers, sign), sign));
1656
+ }
1657
+ // q >>= denom->mult_path.shift
1658
+ q = libdivide_s64_shift_right_vector(q, more & LIBDIVIDE_64_SHIFT_MASK);
1659
+ q = _mm256_add_epi64(q, _mm256_srli_epi64(q, 63)); // q += (q < 0)
1660
+ return q;
1661
+ }
1662
+ }
1663
+
1664
+ __m256i libdivide_s64_branchfree_do_vector(__m256i numers, const struct libdivide_s64_branchfree_t *denom) {
1665
+ int64_t magic = denom->magic;
1666
+ uint8_t more = denom->more;
1667
+ uint8_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
1668
+ // must be arithmetic shift
1669
+ __m256i sign = _mm256_set1_epi32((int8_t)more >> 7);
1670
+
1671
+ // libdivide_mullhi_s64(numers, magic);
1672
+ __m256i q = libdivide_mullhi_s64_vector(numers, _mm256_set1_epi64x(magic));
1673
+ q = _mm256_add_epi64(q, numers); // q += numers
1674
+
1675
+ // If q is non-negative, we have nothing to do.
1676
+ // If q is negative, we want to add either (2**shift)-1 if d is
1677
+ // a power of 2, or (2**shift) if it is not a power of 2.
1678
+ uint32_t is_power_of_2 = (magic == 0);
1679
+ __m256i q_sign = libdivide_s64_signbits(q); // q_sign = q >> 63
1680
+ __m256i mask = _mm256_set1_epi64x((1ULL << shift) - is_power_of_2);
1681
+ q = _mm256_add_epi64(q, _mm256_and_si256(q_sign, mask)); // q = q + (q_sign & mask)
1682
+ q = libdivide_s64_shift_right_vector(q, shift); // q >>= shift
1683
+ q = _mm256_sub_epi64(_mm256_xor_si256(q, sign), sign); // q = (q ^ sign) - sign
1684
+ return q;
1685
+ }
1686
+
1687
+ #elif defined(LIBDIVIDE_SSE2)
1688
+
1689
+ static inline __m128i libdivide_u32_do_vector(__m128i numers, const struct libdivide_u32_t *denom);
1690
+ static inline __m128i libdivide_s32_do_vector(__m128i numers, const struct libdivide_s32_t *denom);
1691
+ static inline __m128i libdivide_u64_do_vector(__m128i numers, const struct libdivide_u64_t *denom);
1692
+ static inline __m128i libdivide_s64_do_vector(__m128i numers, const struct libdivide_s64_t *denom);
1693
+
1694
+ static inline __m128i libdivide_u32_branchfree_do_vector(__m128i numers, const struct libdivide_u32_branchfree_t *denom);
1695
+ static inline __m128i libdivide_s32_branchfree_do_vector(__m128i numers, const struct libdivide_s32_branchfree_t *denom);
1696
+ static inline __m128i libdivide_u64_branchfree_do_vector(__m128i numers, const struct libdivide_u64_branchfree_t *denom);
1697
+ static inline __m128i libdivide_s64_branchfree_do_vector(__m128i numers, const struct libdivide_s64_branchfree_t *denom);
1698
+
1699
+ //////// Internal Utility Functions
1700
+
1701
+ // Implementation of _mm_srai_epi64(v, 63) (from AVX512).
1702
+ static inline __m128i libdivide_s64_signbits(__m128i v) {
1703
+ __m128i hiBitsDuped = _mm_shuffle_epi32(v, _MM_SHUFFLE(3, 3, 1, 1));
1704
+ __m128i signBits = _mm_srai_epi32(hiBitsDuped, 31);
1705
+ return signBits;
1706
+ }
1707
+
1708
+ // Implementation of _mm_srai_epi64 (from AVX512).
1709
+ static inline __m128i libdivide_s64_shift_right_vector(__m128i v, int amt) {
1710
+ const int b = 64 - amt;
1711
+ __m128i m = _mm_set1_epi64x(1ULL << (b - 1));
1712
+ __m128i x = _mm_srli_epi64(v, amt);
1713
+ __m128i result = _mm_sub_epi64(_mm_xor_si128(x, m), m);
1714
+ return result;
1715
+ }
1716
+
1717
+ // Here, b is assumed to contain one 32-bit value repeated.
1718
+ static inline __m128i libdivide_mullhi_u32_vector(__m128i a, __m128i b) {
1719
+ __m128i hi_product_0Z2Z = _mm_srli_epi64(_mm_mul_epu32(a, b), 32);
1720
+ __m128i a1X3X = _mm_srli_epi64(a, 32);
1721
+ __m128i mask = _mm_set_epi32(-1, 0, -1, 0);
1722
+ __m128i hi_product_Z1Z3 = _mm_and_si128(_mm_mul_epu32(a1X3X, b), mask);
1723
+ return _mm_or_si128(hi_product_0Z2Z, hi_product_Z1Z3);
1724
+ }
1725
+
1726
+ // SSE2 does not have a signed multiplication instruction, but we can convert
1727
+ // unsigned to signed pretty efficiently. Again, b is just a 32 bit value
1728
+ // repeated four times.
1729
+ static inline __m128i libdivide_mullhi_s32_vector(__m128i a, __m128i b) {
1730
+ __m128i p = libdivide_mullhi_u32_vector(a, b);
1731
+ // t1 = (a >> 31) & y, arithmetic shift
1732
+ __m128i t1 = _mm_and_si128(_mm_srai_epi32(a, 31), b);
1733
+ __m128i t2 = _mm_and_si128(_mm_srai_epi32(b, 31), a);
1734
+ p = _mm_sub_epi32(p, t1);
1735
+ p = _mm_sub_epi32(p, t2);
1736
+ return p;
1737
+ }
1738
+
1739
+ // Here, y is assumed to contain one 64-bit value repeated.
1740
+ // https://stackoverflow.com/a/28827013
1741
+ static inline __m128i libdivide_mullhi_u64_vector(__m128i x, __m128i y) {
1742
+ __m128i lomask = _mm_set1_epi64x(0xffffffff);
1743
+ __m128i xh = _mm_shuffle_epi32(x, 0xB1); // x0l, x0h, x1l, x1h
1744
+ __m128i yh = _mm_shuffle_epi32(y, 0xB1); // y0l, y0h, y1l, y1h
1745
+ __m128i w0 = _mm_mul_epu32(x, y); // x0l*y0l, x1l*y1l
1746
+ __m128i w1 = _mm_mul_epu32(x, yh); // x0l*y0h, x1l*y1h
1747
+ __m128i w2 = _mm_mul_epu32(xh, y); // x0h*y0l, x1h*y0l
1748
+ __m128i w3 = _mm_mul_epu32(xh, yh); // x0h*y0h, x1h*y1h
1749
+ __m128i w0h = _mm_srli_epi64(w0, 32);
1750
+ __m128i s1 = _mm_add_epi64(w1, w0h);
1751
+ __m128i s1l = _mm_and_si128(s1, lomask);
1752
+ __m128i s1h = _mm_srli_epi64(s1, 32);
1753
+ __m128i s2 = _mm_add_epi64(w2, s1l);
1754
+ __m128i s2h = _mm_srli_epi64(s2, 32);
1755
+ __m128i hi = _mm_add_epi64(w3, s1h);
1756
+ hi = _mm_add_epi64(hi, s2h);
1757
+
1758
+ return hi;
1759
+ }
1760
+
1761
+ // y is one 64-bit value repeated.
1762
+ static inline __m128i libdivide_mullhi_s64_vector(__m128i x, __m128i y) {
1763
+ __m128i p = libdivide_mullhi_u64_vector(x, y);
1764
+ __m128i t1 = _mm_and_si128(libdivide_s64_signbits(x), y);
1765
+ __m128i t2 = _mm_and_si128(libdivide_s64_signbits(y), x);
1766
+ p = _mm_sub_epi64(p, t1);
1767
+ p = _mm_sub_epi64(p, t2);
1768
+ return p;
1769
+ }
1770
+
1771
+ ////////// UINT32
1772
+
1773
+ __m128i libdivide_u32_do_vector(__m128i numers, const struct libdivide_u32_t *denom) {
1774
+ uint8_t more = denom->more;
1775
+ if (!denom->magic) {
1776
+ return _mm_srli_epi32(numers, more);
1777
+ }
1778
+ else {
1779
+ __m128i q = libdivide_mullhi_u32_vector(numers, _mm_set1_epi32(denom->magic));
1780
+ if (more & LIBDIVIDE_ADD_MARKER) {
1781
+ // uint32_t t = ((numer - q) >> 1) + q;
1782
+ // return t >> denom->shift;
1783
+ uint32_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
1784
+ __m128i t = _mm_add_epi32(_mm_srli_epi32(_mm_sub_epi32(numers, q), 1), q);
1785
+ return _mm_srli_epi32(t, shift);
1786
+ }
1787
+ else {
1788
+ return _mm_srli_epi32(q, more);
1789
+ }
1790
+ }
1791
+ }
1792
+
1793
+ __m128i libdivide_u32_branchfree_do_vector(__m128i numers, const struct libdivide_u32_branchfree_t *denom) {
1794
+ __m128i q = libdivide_mullhi_u32_vector(numers, _mm_set1_epi32(denom->magic));
1795
+ __m128i t = _mm_add_epi32(_mm_srli_epi32(_mm_sub_epi32(numers, q), 1), q);
1796
+ return _mm_srli_epi32(t, denom->more);
1797
+ }
1798
+
1799
+ ////////// UINT64
1800
+
1801
+ __m128i libdivide_u64_do_vector(__m128i numers, const struct libdivide_u64_t *denom) {
1802
+ uint8_t more = denom->more;
1803
+ if (!denom->magic) {
1804
+ return _mm_srli_epi64(numers, more);
1805
+ }
1806
+ else {
1807
+ __m128i q = libdivide_mullhi_u64_vector(numers, _mm_set1_epi64x(denom->magic));
1808
+ if (more & LIBDIVIDE_ADD_MARKER) {
1809
+ // uint32_t t = ((numer - q) >> 1) + q;
1810
+ // return t >> denom->shift;
1811
+ uint32_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
1812
+ __m128i t = _mm_add_epi64(_mm_srli_epi64(_mm_sub_epi64(numers, q), 1), q);
1813
+ return _mm_srli_epi64(t, shift);
1814
+ }
1815
+ else {
1816
+ return _mm_srli_epi64(q, more);
1817
+ }
1818
+ }
1819
+ }
1820
+
1821
+ __m128i libdivide_u64_branchfree_do_vector(__m128i numers, const struct libdivide_u64_branchfree_t *denom) {
1822
+ __m128i q = libdivide_mullhi_u64_vector(numers, _mm_set1_epi64x(denom->magic));
1823
+ __m128i t = _mm_add_epi64(_mm_srli_epi64(_mm_sub_epi64(numers, q), 1), q);
1824
+ return _mm_srli_epi64(t, denom->more);
1825
+ }
1826
+
1827
+ ////////// SINT32
1828
+
1829
+ __m128i libdivide_s32_do_vector(__m128i numers, const struct libdivide_s32_t *denom) {
1830
+ uint8_t more = denom->more;
1831
+ if (!denom->magic) {
1832
+ uint32_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
1833
+ uint32_t mask = (1U << shift) - 1;
1834
+ __m128i roundToZeroTweak = _mm_set1_epi32(mask);
1835
+ // q = numer + ((numer >> 31) & roundToZeroTweak);
1836
+ __m128i q = _mm_add_epi32(numers, _mm_and_si128(_mm_srai_epi32(numers, 31), roundToZeroTweak));
1837
+ q = _mm_srai_epi32(q, shift);
1838
+ __m128i sign = _mm_set1_epi32((int8_t)more >> 7);
1839
+ // q = (q ^ sign) - sign;
1840
+ q = _mm_sub_epi32(_mm_xor_si128(q, sign), sign);
1841
+ return q;
1842
+ }
1843
+ else {
1844
+ __m128i q = libdivide_mullhi_s32_vector(numers, _mm_set1_epi32(denom->magic));
1845
+ if (more & LIBDIVIDE_ADD_MARKER) {
1846
+ // must be arithmetic shift
1847
+ __m128i sign = _mm_set1_epi32((int8_t)more >> 7);
1848
+ // q += ((numer ^ sign) - sign);
1849
+ q = _mm_add_epi32(q, _mm_sub_epi32(_mm_xor_si128(numers, sign), sign));
1850
+ }
1851
+ // q >>= shift
1852
+ q = _mm_srai_epi32(q, more & LIBDIVIDE_32_SHIFT_MASK);
1853
+ q = _mm_add_epi32(q, _mm_srli_epi32(q, 31)); // q += (q < 0)
1854
+ return q;
1855
+ }
1856
+ }
1857
+
1858
+ __m128i libdivide_s32_branchfree_do_vector(__m128i numers, const struct libdivide_s32_branchfree_t *denom) {
1859
+ int32_t magic = denom->magic;
1860
+ uint8_t more = denom->more;
1861
+ uint8_t shift = more & LIBDIVIDE_32_SHIFT_MASK;
1862
+ // must be arithmetic shift
1863
+ __m128i sign = _mm_set1_epi32((int8_t)more >> 7);
1864
+ __m128i q = libdivide_mullhi_s32_vector(numers, _mm_set1_epi32(magic));
1865
+ q = _mm_add_epi32(q, numers); // q += numers
1866
+
1867
+ // If q is non-negative, we have nothing to do
1868
+ // If q is negative, we want to add either (2**shift)-1 if d is
1869
+ // a power of 2, or (2**shift) if it is not a power of 2
1870
+ uint32_t is_power_of_2 = (magic == 0);
1871
+ __m128i q_sign = _mm_srai_epi32(q, 31); // q_sign = q >> 31
1872
+ __m128i mask = _mm_set1_epi32((1U << shift) - is_power_of_2);
1873
+ q = _mm_add_epi32(q, _mm_and_si128(q_sign, mask)); // q = q + (q_sign & mask)
1874
+ q = _mm_srai_epi32(q, shift); // q >>= shift
1875
+ q = _mm_sub_epi32(_mm_xor_si128(q, sign), sign); // q = (q ^ sign) - sign
1876
+ return q;
1877
+ }
1878
+
1879
+ ////////// SINT64
1880
+
1881
+ __m128i libdivide_s64_do_vector(__m128i numers, const struct libdivide_s64_t *denom) {
1882
+ uint8_t more = denom->more;
1883
+ int64_t magic = denom->magic;
1884
+ if (magic == 0) { // shift path
1885
+ uint32_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
1886
+ uint64_t mask = (1ULL << shift) - 1;
1887
+ __m128i roundToZeroTweak = _mm_set1_epi64x(mask);
1888
+ // q = numer + ((numer >> 63) & roundToZeroTweak);
1889
+ __m128i q = _mm_add_epi64(numers, _mm_and_si128(libdivide_s64_signbits(numers), roundToZeroTweak));
1890
+ q = libdivide_s64_shift_right_vector(q, shift);
1891
+ __m128i sign = _mm_set1_epi32((int8_t)more >> 7);
1892
+ // q = (q ^ sign) - sign;
1893
+ q = _mm_sub_epi64(_mm_xor_si128(q, sign), sign);
1894
+ return q;
1895
+ }
1896
+ else {
1897
+ __m128i q = libdivide_mullhi_s64_vector(numers, _mm_set1_epi64x(magic));
1898
+ if (more & LIBDIVIDE_ADD_MARKER) {
1899
+ // must be arithmetic shift
1900
+ __m128i sign = _mm_set1_epi32((int8_t)more >> 7);
1901
+ // q += ((numer ^ sign) - sign);
1902
+ q = _mm_add_epi64(q, _mm_sub_epi64(_mm_xor_si128(numers, sign), sign));
1903
+ }
1904
+ // q >>= denom->mult_path.shift
1905
+ q = libdivide_s64_shift_right_vector(q, more & LIBDIVIDE_64_SHIFT_MASK);
1906
+ q = _mm_add_epi64(q, _mm_srli_epi64(q, 63)); // q += (q < 0)
1907
+ return q;
1908
+ }
1909
+ }
1910
+
1911
+ __m128i libdivide_s64_branchfree_do_vector(__m128i numers, const struct libdivide_s64_branchfree_t *denom) {
1912
+ int64_t magic = denom->magic;
1913
+ uint8_t more = denom->more;
1914
+ uint8_t shift = more & LIBDIVIDE_64_SHIFT_MASK;
1915
+ // must be arithmetic shift
1916
+ __m128i sign = _mm_set1_epi32((int8_t)more >> 7);
1917
+
1918
+ // libdivide_mullhi_s64(numers, magic);
1919
+ __m128i q = libdivide_mullhi_s64_vector(numers, _mm_set1_epi64x(magic));
1920
+ q = _mm_add_epi64(q, numers); // q += numers
1921
+
1922
+ // If q is non-negative, we have nothing to do.
1923
+ // If q is negative, we want to add either (2**shift)-1 if d is
1924
+ // a power of 2, or (2**shift) if it is not a power of 2.
1925
+ uint32_t is_power_of_2 = (magic == 0);
1926
+ __m128i q_sign = libdivide_s64_signbits(q); // q_sign = q >> 63
1927
+ __m128i mask = _mm_set1_epi64x((1ULL << shift) - is_power_of_2);
1928
+ q = _mm_add_epi64(q, _mm_and_si128(q_sign, mask)); // q = q + (q_sign & mask)
1929
+ q = libdivide_s64_shift_right_vector(q, shift); // q >>= shift
1930
+ q = _mm_sub_epi64(_mm_xor_si128(q, sign), sign); // q = (q ^ sign) - sign
1931
+ return q;
1932
+ }
1933
+
1934
+ #endif
1935
+
1936
+ /////////// C++ stuff
1937
+
1938
+ #ifdef __cplusplus
1939
+
1940
+ // The C++ divider class is templated on both an integer type
1941
+ // (like uint64_t) and an algorithm type.
1942
+ // * BRANCHFULL is the default algorithm type.
1943
+ // * BRANCHFREE is the branchfree algorithm type.
1944
+ enum {
1945
+ BRANCHFULL,
1946
+ BRANCHFREE
1947
+ };
1948
+
1949
+ #if defined(LIBDIVIDE_AVX512)
1950
+ #define LIBDIVIDE_VECTOR_TYPE __m512i
1951
+ #elif defined(LIBDIVIDE_AVX2)
1952
+ #define LIBDIVIDE_VECTOR_TYPE __m256i
1953
+ #elif defined(LIBDIVIDE_SSE2)
1954
+ #define LIBDIVIDE_VECTOR_TYPE __m128i
1955
+ #endif
1956
+
1957
+ #if !defined(LIBDIVIDE_VECTOR_TYPE)
1958
+ #define LIBDIVIDE_DIVIDE_VECTOR(ALGO)
1959
+ #else
1960
+ #define LIBDIVIDE_DIVIDE_VECTOR(ALGO) \
1961
+ LIBDIVIDE_VECTOR_TYPE divide(LIBDIVIDE_VECTOR_TYPE n) const { \
1962
+ return libdivide_##ALGO##_do_vector(n, &denom); \
1963
+ }
1964
+ #endif
1965
+
1966
+ // The DISPATCHER_GEN() macro generates C++ methods (for the given integer
1967
+ // and algorithm types) that redirect to libdivide's C API.
1968
+ #define DISPATCHER_GEN(T, ALGO) \
1969
+ libdivide_##ALGO##_t denom; \
1970
+ dispatcher() { } \
1971
+ dispatcher(T d) \
1972
+ : denom(libdivide_##ALGO##_gen(d)) \
1973
+ { } \
1974
+ T divide(T n) const { \
1975
+ return libdivide_##ALGO##_do(n, &denom); \
1976
+ } \
1977
+ LIBDIVIDE_DIVIDE_VECTOR(ALGO) \
1978
+ T recover() const { \
1979
+ return libdivide_##ALGO##_recover(&denom); \
1980
+ }
1981
+
1982
+ // The dispatcher selects a specific division algorithm for a given
1983
+ // type and ALGO using partial template specialization.
1984
+ template<bool IS_INTEGRAL, bool IS_SIGNED, int SIZEOF, int ALGO> struct dispatcher { };
1985
+
1986
+ template<> struct dispatcher<true, true, sizeof(int32_t), BRANCHFULL> { DISPATCHER_GEN(int32_t, s32) };
1987
+ template<> struct dispatcher<true, true, sizeof(int32_t), BRANCHFREE> { DISPATCHER_GEN(int32_t, s32_branchfree) };
1988
+ template<> struct dispatcher<true, false, sizeof(uint32_t), BRANCHFULL> { DISPATCHER_GEN(uint32_t, u32) };
1989
+ template<> struct dispatcher<true, false, sizeof(uint32_t), BRANCHFREE> { DISPATCHER_GEN(uint32_t, u32_branchfree) };
1990
+ template<> struct dispatcher<true, true, sizeof(int64_t), BRANCHFULL> { DISPATCHER_GEN(int64_t, s64) };
1991
+ template<> struct dispatcher<true, true, sizeof(int64_t), BRANCHFREE> { DISPATCHER_GEN(int64_t, s64_branchfree) };
1992
+ template<> struct dispatcher<true, false, sizeof(uint64_t), BRANCHFULL> { DISPATCHER_GEN(uint64_t, u64) };
1993
+ template<> struct dispatcher<true, false, sizeof(uint64_t), BRANCHFREE> { DISPATCHER_GEN(uint64_t, u64_branchfree) };
1994
+
1995
+ // This is the main divider class for use by the user (C++ API).
1996
+ // The actual division algorithm is selected using the dispatcher struct
1997
+ // based on the integer and algorithm template parameters.
1998
+ template<typename T, int ALGO = BRANCHFULL>
1999
+ class divider {
2000
+ public:
2001
+ // We leave the default constructor empty so that creating
2002
+ // an array of dividers and then initializing them
2003
+ // later doesn't slow us down.
2004
+ divider() { }
2005
+
2006
+ // Constructor that takes the divisor as a parameter
2007
+ divider(T d) : div(d) { }
2008
+
2009
+ // Divides n by the divisor
2010
+ T divide(T n) const {
2011
+ return div.divide(n);
2012
+ }
2013
+
2014
+ // Recovers the divisor, returns the value that was
2015
+ // used to initialize this divider object.
2016
+ T recover() const {
2017
+ return div.recover();
2018
+ }
2019
+
2020
+ bool operator==(const divider<T, ALGO>& other) const {
2021
+ return div.denom.magic == other.denom.magic &&
2022
+ div.denom.more == other.denom.more;
2023
+ }
2024
+
2025
+ bool operator!=(const divider<T, ALGO>& other) const {
2026
+ return !(*this == other);
2027
+ }
2028
+
2029
+ #if defined(LIBDIVIDE_VECTOR_TYPE)
2030
+ // Treats the vector as packed integer values with the same type as
2031
+ // the divider (e.g. s32, u32, s64, u64) and divides each of
2032
+ // them by the divider, returning the packed quotients.
2033
+ LIBDIVIDE_VECTOR_TYPE divide(LIBDIVIDE_VECTOR_TYPE n) const {
2034
+ return div.divide(n);
2035
+ }
2036
+ #endif
2037
+
2038
+ private:
2039
+ // Storage for the actual divisor
2040
+ dispatcher<std::is_integral<T>::value,
2041
+ std::is_signed<T>::value, sizeof(T), ALGO> div;
2042
+ };
2043
+
2044
+ // Overload of operator / for scalar division
2045
+ template<typename T, int ALGO>
2046
+ T operator/(T n, const divider<T, ALGO>& div) {
2047
+ return div.divide(n);
2048
+ }
2049
+
2050
+ // Overload of operator /= for scalar division
2051
+ template<typename T, int ALGO>
2052
+ T& operator/=(T& n, const divider<T, ALGO>& div) {
2053
+ n = div.divide(n);
2054
+ return n;
2055
+ }
2056
+
2057
+ #if defined(LIBDIVIDE_VECTOR_TYPE)
2058
+ // Overload of operator / for vector division
2059
+ template<typename T, int ALGO>
2060
+ LIBDIVIDE_VECTOR_TYPE operator/(LIBDIVIDE_VECTOR_TYPE n, const divider<T, ALGO>& div) {
2061
+ return div.divide(n);
2062
+ }
2063
+ // Overload of operator /= for vector division
2064
+ template<typename T, int ALGO>
2065
+ LIBDIVIDE_VECTOR_TYPE& operator/=(LIBDIVIDE_VECTOR_TYPE& n, const divider<T, ALGO>& div) {
2066
+ n = div.divide(n);
2067
+ return n;
2068
+ }
2069
+ #endif
2070
+
2071
+ // libdivdie::branchfree_divider<T>
2072
+ template <typename T>
2073
+ using branchfree_divider = divider<T, BRANCHFREE>;
2074
+
2075
+ } // namespace libdivide
2076
+
2077
+ #endif // __cplusplus
2078
+
2079
+ #endif // NUMPY_CORE_INCLUDE_NUMPY_LIBDIVIDE_LIBDIVIDE_H_
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/ufuncobject.h ADDED
@@ -0,0 +1,345 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_UFUNCOBJECT_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_UFUNCOBJECT_H_
3
+
4
+ #include <numpy/npy_math.h>
5
+ #include <numpy/npy_common.h>
6
+
7
+ #ifdef __cplusplus
8
+ extern "C" {
9
+ #endif
10
+
11
+ /*
12
+ * The legacy generic inner loop for a standard element-wise or
13
+ * generalized ufunc.
14
+ */
15
+ typedef void (*PyUFuncGenericFunction)
16
+ (char **args,
17
+ npy_intp const *dimensions,
18
+ npy_intp const *strides,
19
+ void *innerloopdata);
20
+
21
+ /*
22
+ * The most generic one-dimensional inner loop for
23
+ * a masked standard element-wise ufunc. "Masked" here means that it skips
24
+ * doing calculations on any items for which the maskptr array has a true
25
+ * value.
26
+ */
27
+ typedef void (PyUFunc_MaskedStridedInnerLoopFunc)(
28
+ char **dataptrs, npy_intp *strides,
29
+ char *maskptr, npy_intp mask_stride,
30
+ npy_intp count,
31
+ NpyAuxData *innerloopdata);
32
+
33
+ /* Forward declaration for the type resolver and loop selector typedefs */
34
+ struct _tagPyUFuncObject;
35
+
36
+ /*
37
+ * Given the operands for calling a ufunc, should determine the
38
+ * calculation input and output data types and return an inner loop function.
39
+ * This function should validate that the casting rule is being followed,
40
+ * and fail if it is not.
41
+ *
42
+ * For backwards compatibility, the regular type resolution function does not
43
+ * support auxiliary data with object semantics. The type resolution call
44
+ * which returns a masked generic function returns a standard NpyAuxData
45
+ * object, for which the NPY_AUXDATA_FREE and NPY_AUXDATA_CLONE macros
46
+ * work.
47
+ *
48
+ * ufunc: The ufunc object.
49
+ * casting: The 'casting' parameter provided to the ufunc.
50
+ * operands: An array of length (ufunc->nin + ufunc->nout),
51
+ * with the output parameters possibly NULL.
52
+ * type_tup: Either NULL, or the type_tup passed to the ufunc.
53
+ * out_dtypes: An array which should be populated with new
54
+ * references to (ufunc->nin + ufunc->nout) new
55
+ * dtypes, one for each input and output. These
56
+ * dtypes should all be in native-endian format.
57
+ *
58
+ * Should return 0 on success, -1 on failure (with exception set),
59
+ * or -2 if Py_NotImplemented should be returned.
60
+ */
61
+ typedef int (PyUFunc_TypeResolutionFunc)(
62
+ struct _tagPyUFuncObject *ufunc,
63
+ NPY_CASTING casting,
64
+ PyArrayObject **operands,
65
+ PyObject *type_tup,
66
+ PyArray_Descr **out_dtypes);
67
+
68
+ /*
69
+ * This is the signature for the functions that may be assigned to the
70
+ * `process_core_dims_func` field of the PyUFuncObject structure.
71
+ * Implementation of this function is optional. This function is only used
72
+ * by generalized ufuncs (i.e. those with the field `core_enabled` set to 1).
73
+ * The function is called by the ufunc during the processing of the arguments
74
+ * of a call of the ufunc. The function can check the core dimensions of the
75
+ * input and output arrays and return -1 with an exception set if any
76
+ * requirements are not satisfied. If the caller of the ufunc didn't provide
77
+ * output arrays, the core dimensions associated with the output arrays (i.e.
78
+ * those that are not also used in input arrays) will have the value -1 in
79
+ * `core_dim_sizes`. This function can replace any output core dimensions
80
+ * that are -1 with a value that is appropriate for the ufunc.
81
+ *
82
+ * Parameter Description
83
+ * --------------- ------------------------------------------------------
84
+ * ufunc The ufunc object
85
+ * core_dim_sizes An array with length `ufunc->core_num_dim_ix`.
86
+ * The core dimensions of the arrays passed to the ufunc
87
+ * will have been set. If the caller of the ufunc didn't
88
+ * provide the output array(s), the output-only core
89
+ * dimensions will have the value -1.
90
+ *
91
+ * The function must not change any element in `core_dim_sizes` that is
92
+ * not -1 on input. Doing so will result in incorrect output from the
93
+ * ufunc, and could result in a crash of the Python interpreter.
94
+ *
95
+ * The function must return 0 on success, -1 on failure (with an exception
96
+ * set).
97
+ */
98
+ typedef int (PyUFunc_ProcessCoreDimsFunc)(
99
+ struct _tagPyUFuncObject *ufunc,
100
+ npy_intp *core_dim_sizes);
101
+
102
+ typedef struct _tagPyUFuncObject {
103
+ PyObject_HEAD
104
+ /*
105
+ * nin: Number of inputs
106
+ * nout: Number of outputs
107
+ * nargs: Always nin + nout (Why is it stored?)
108
+ */
109
+ int nin, nout, nargs;
110
+
111
+ /*
112
+ * Identity for reduction, any of PyUFunc_One, PyUFunc_Zero
113
+ * PyUFunc_MinusOne, PyUFunc_None, PyUFunc_ReorderableNone,
114
+ * PyUFunc_IdentityValue.
115
+ */
116
+ int identity;
117
+
118
+ /* Array of one-dimensional core loops */
119
+ PyUFuncGenericFunction *functions;
120
+ /* Array of funcdata that gets passed into the functions */
121
+ void *const *data;
122
+ /* The number of elements in 'functions' and 'data' */
123
+ int ntypes;
124
+
125
+ /* Used to be unused field 'check_return' */
126
+ int reserved1;
127
+
128
+ /* The name of the ufunc */
129
+ const char *name;
130
+
131
+ /* Array of type numbers, of size ('nargs' * 'ntypes') */
132
+ const char *types;
133
+
134
+ /* Documentation string */
135
+ const char *doc;
136
+
137
+ void *ptr;
138
+ PyObject *obj;
139
+ PyObject *userloops;
140
+
141
+ /* generalized ufunc parameters */
142
+
143
+ /* 0 for scalar ufunc; 1 for generalized ufunc */
144
+ int core_enabled;
145
+ /* number of distinct dimension names in signature */
146
+ int core_num_dim_ix;
147
+
148
+ /*
149
+ * dimension indices of input/output argument k are stored in
150
+ * core_dim_ixs[core_offsets[k]..core_offsets[k]+core_num_dims[k]-1]
151
+ */
152
+
153
+ /* numbers of core dimensions of each argument */
154
+ int *core_num_dims;
155
+ /*
156
+ * dimension indices in a flatted form; indices
157
+ * are in the range of [0,core_num_dim_ix)
158
+ */
159
+ int *core_dim_ixs;
160
+ /*
161
+ * positions of 1st core dimensions of each
162
+ * argument in core_dim_ixs, equivalent to cumsum(core_num_dims)
163
+ */
164
+ int *core_offsets;
165
+ /* signature string for printing purpose */
166
+ char *core_signature;
167
+
168
+ /*
169
+ * A function which resolves the types and fills an array
170
+ * with the dtypes for the inputs and outputs.
171
+ */
172
+ PyUFunc_TypeResolutionFunc *type_resolver;
173
+ /* Was the legacy loop resolver */
174
+ void *reserved2;
175
+ /*
176
+ * This was blocked off to be the "new" inner loop selector in 1.7,
177
+ * but this was never implemented. (This is also why the above
178
+ * selector is called the "legacy" selector.)
179
+ */
180
+ #ifndef Py_LIMITED_API
181
+ vectorcallfunc vectorcall;
182
+ #else
183
+ void *vectorcall;
184
+ #endif
185
+
186
+ /* Was previously the `PyUFunc_MaskedInnerLoopSelectionFunc` */
187
+ void *reserved3;
188
+
189
+ /*
190
+ * List of flags for each operand when ufunc is called by nditer object.
191
+ * These flags will be used in addition to the default flags for each
192
+ * operand set by nditer object.
193
+ */
194
+ npy_uint32 *op_flags;
195
+
196
+ /*
197
+ * List of global flags used when ufunc is called by nditer object.
198
+ * These flags will be used in addition to the default global flags
199
+ * set by nditer object.
200
+ */
201
+ npy_uint32 iter_flags;
202
+
203
+ /* New in NPY_API_VERSION 0x0000000D and above */
204
+ #if NPY_FEATURE_VERSION >= NPY_1_16_API_VERSION
205
+ /*
206
+ * for each core_num_dim_ix distinct dimension names,
207
+ * the possible "frozen" size (-1 if not frozen).
208
+ */
209
+ npy_intp *core_dim_sizes;
210
+
211
+ /*
212
+ * for each distinct core dimension, a set of UFUNC_CORE_DIM* flags
213
+ */
214
+ npy_uint32 *core_dim_flags;
215
+
216
+ /* Identity for reduction, when identity == PyUFunc_IdentityValue */
217
+ PyObject *identity_value;
218
+ #endif /* NPY_FEATURE_VERSION >= NPY_1_16_API_VERSION */
219
+
220
+ /* New in NPY_API_VERSION 0x0000000F and above */
221
+ #if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
222
+ /* New private fields related to dispatching */
223
+ void *_dispatch_cache;
224
+ /* A PyListObject of `(tuple of DTypes, ArrayMethod/Promoter)` */
225
+ PyObject *_loops;
226
+ #endif
227
+ #if NPY_FEATURE_VERSION >= NPY_2_1_API_VERSION
228
+ /*
229
+ * Optional function to process core dimensions of a gufunc.
230
+ */
231
+ PyUFunc_ProcessCoreDimsFunc *process_core_dims_func;
232
+ #endif
233
+ } PyUFuncObject;
234
+
235
+ #include "arrayobject.h"
236
+ /* Generalized ufunc; 0x0001 reserved for possible use as CORE_ENABLED */
237
+ /* the core dimension's size will be determined by the operands. */
238
+ #define UFUNC_CORE_DIM_SIZE_INFERRED 0x0002
239
+ /* the core dimension may be absent */
240
+ #define UFUNC_CORE_DIM_CAN_IGNORE 0x0004
241
+ /* flags inferred during execution */
242
+ #define UFUNC_CORE_DIM_MISSING 0x00040000
243
+
244
+
245
+ #define UFUNC_OBJ_ISOBJECT 1
246
+ #define UFUNC_OBJ_NEEDS_API 2
247
+
248
+
249
+ #if NPY_ALLOW_THREADS
250
+ #define NPY_LOOP_BEGIN_THREADS do {if (!(loop->obj & UFUNC_OBJ_NEEDS_API)) _save = PyEval_SaveThread();} while (0);
251
+ #define NPY_LOOP_END_THREADS do {if (!(loop->obj & UFUNC_OBJ_NEEDS_API)) PyEval_RestoreThread(_save);} while (0);
252
+ #else
253
+ #define NPY_LOOP_BEGIN_THREADS
254
+ #define NPY_LOOP_END_THREADS
255
+ #endif
256
+
257
+ /*
258
+ * UFunc has unit of 0, and the order of operations can be reordered
259
+ * This case allows reduction with multiple axes at once.
260
+ */
261
+ #define PyUFunc_Zero 0
262
+ /*
263
+ * UFunc has unit of 1, and the order of operations can be reordered
264
+ * This case allows reduction with multiple axes at once.
265
+ */
266
+ #define PyUFunc_One 1
267
+ /*
268
+ * UFunc has unit of -1, and the order of operations can be reordered
269
+ * This case allows reduction with multiple axes at once. Intended for
270
+ * bitwise_and reduction.
271
+ */
272
+ #define PyUFunc_MinusOne 2
273
+ /*
274
+ * UFunc has no unit, and the order of operations cannot be reordered.
275
+ * This case does not allow reduction with multiple axes at once.
276
+ */
277
+ #define PyUFunc_None -1
278
+ /*
279
+ * UFunc has no unit, and the order of operations can be reordered
280
+ * This case allows reduction with multiple axes at once.
281
+ */
282
+ #define PyUFunc_ReorderableNone -2
283
+ /*
284
+ * UFunc unit is an identity_value, and the order of operations can be reordered
285
+ * This case allows reduction with multiple axes at once.
286
+ */
287
+ #define PyUFunc_IdentityValue -3
288
+
289
+
290
+ #define UFUNC_REDUCE 0
291
+ #define UFUNC_ACCUMULATE 1
292
+ #define UFUNC_REDUCEAT 2
293
+ #define UFUNC_OUTER 3
294
+
295
+
296
+ typedef struct {
297
+ int nin;
298
+ int nout;
299
+ PyObject *callable;
300
+ } PyUFunc_PyFuncData;
301
+
302
+ /* A linked-list of function information for
303
+ user-defined 1-d loops.
304
+ */
305
+ typedef struct _loop1d_info {
306
+ PyUFuncGenericFunction func;
307
+ void *data;
308
+ int *arg_types;
309
+ struct _loop1d_info *next;
310
+ int nargs;
311
+ PyArray_Descr **arg_dtypes;
312
+ } PyUFunc_Loop1d;
313
+
314
+
315
+ #define UFUNC_PYVALS_NAME "UFUNC_PYVALS"
316
+
317
+ /*
318
+ * THESE MACROS ARE DEPRECATED.
319
+ * Use npy_set_floatstatus_* in the npymath library.
320
+ */
321
+ #define UFUNC_FPE_DIVIDEBYZERO NPY_FPE_DIVIDEBYZERO
322
+ #define UFUNC_FPE_OVERFLOW NPY_FPE_OVERFLOW
323
+ #define UFUNC_FPE_UNDERFLOW NPY_FPE_UNDERFLOW
324
+ #define UFUNC_FPE_INVALID NPY_FPE_INVALID
325
+
326
+ #define generate_divbyzero_error() npy_set_floatstatus_divbyzero()
327
+ #define generate_overflow_error() npy_set_floatstatus_overflow()
328
+
329
+ /* Make sure it gets defined if it isn't already */
330
+ #ifndef UFUNC_NOFPE
331
+ /* Clear the floating point exception default of Borland C++ */
332
+ #if defined(__BORLANDC__)
333
+ #define UFUNC_NOFPE _control87(MCW_EM, MCW_EM);
334
+ #else
335
+ #define UFUNC_NOFPE
336
+ #endif
337
+ #endif
338
+
339
+ #include "__ufunc_api.h"
340
+
341
+ #ifdef __cplusplus
342
+ }
343
+ #endif
344
+
345
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_UFUNCOBJECT_H_ */
parrot/lib/python3.10/site-packages/numpy/_core/include/numpy/utils.h ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_UTILS_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_UTILS_H_
3
+
4
+ #ifndef __COMP_NPY_UNUSED
5
+ #if defined(__GNUC__)
6
+ #define __COMP_NPY_UNUSED __attribute__ ((__unused__))
7
+ #elif defined(__ICC)
8
+ #define __COMP_NPY_UNUSED __attribute__ ((__unused__))
9
+ #elif defined(__clang__)
10
+ #define __COMP_NPY_UNUSED __attribute__ ((unused))
11
+ #else
12
+ #define __COMP_NPY_UNUSED
13
+ #endif
14
+ #endif
15
+
16
+ #if defined(__GNUC__) || defined(__ICC) || defined(__clang__)
17
+ #define NPY_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
18
+ #elif defined(_MSC_VER)
19
+ #define NPY_DECL_ALIGNED(x) __declspec(align(x))
20
+ #else
21
+ #define NPY_DECL_ALIGNED(x)
22
+ #endif
23
+
24
+ /* Use this to tag a variable as not used. It will remove unused variable
25
+ * warning on support platforms (see __COM_NPY_UNUSED) and mangle the variable
26
+ * to avoid accidental use */
27
+ #define NPY_UNUSED(x) __NPY_UNUSED_TAGGED ## x __COMP_NPY_UNUSED
28
+ #define NPY_EXPAND(x) x
29
+
30
+ #define NPY_STRINGIFY(x) #x
31
+ #define NPY_TOSTRING(x) NPY_STRINGIFY(x)
32
+
33
+ #define NPY_CAT__(a, b) a ## b
34
+ #define NPY_CAT_(a, b) NPY_CAT__(a, b)
35
+ #define NPY_CAT(a, b) NPY_CAT_(a, b)
36
+
37
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_UTILS_H_ */
parrot/lib/python3.10/site-packages/numpy/polynomial/__init__.py ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ A sub-package for efficiently dealing with polynomials.
3
+
4
+ Within the documentation for this sub-package, a "finite power series,"
5
+ i.e., a polynomial (also referred to simply as a "series") is represented
6
+ by a 1-D numpy array of the polynomial's coefficients, ordered from lowest
7
+ order term to highest. For example, array([1,2,3]) represents
8
+ ``P_0 + 2*P_1 + 3*P_2``, where P_n is the n-th order basis polynomial
9
+ applicable to the specific module in question, e.g., `polynomial` (which
10
+ "wraps" the "standard" basis) or `chebyshev`. For optimal performance,
11
+ all operations on polynomials, including evaluation at an argument, are
12
+ implemented as operations on the coefficients. Additional (module-specific)
13
+ information can be found in the docstring for the module of interest.
14
+
15
+ This package provides *convenience classes* for each of six different kinds
16
+ of polynomials:
17
+
18
+ ======================== ================
19
+ **Name** **Provides**
20
+ ======================== ================
21
+ `~polynomial.Polynomial` Power series
22
+ `~chebyshev.Chebyshev` Chebyshev series
23
+ `~legendre.Legendre` Legendre series
24
+ `~laguerre.Laguerre` Laguerre series
25
+ `~hermite.Hermite` Hermite series
26
+ `~hermite_e.HermiteE` HermiteE series
27
+ ======================== ================
28
+
29
+ These *convenience classes* provide a consistent interface for creating,
30
+ manipulating, and fitting data with polynomials of different bases.
31
+ The convenience classes are the preferred interface for the `~numpy.polynomial`
32
+ package, and are available from the ``numpy.polynomial`` namespace.
33
+ This eliminates the need to navigate to the corresponding submodules, e.g.
34
+ ``np.polynomial.Polynomial`` or ``np.polynomial.Chebyshev`` instead of
35
+ ``np.polynomial.polynomial.Polynomial`` or
36
+ ``np.polynomial.chebyshev.Chebyshev``, respectively.
37
+ The classes provide a more consistent and concise interface than the
38
+ type-specific functions defined in the submodules for each type of polynomial.
39
+ For example, to fit a Chebyshev polynomial with degree ``1`` to data given
40
+ by arrays ``xdata`` and ``ydata``, the
41
+ `~chebyshev.Chebyshev.fit` class method::
42
+
43
+ >>> from numpy.polynomial import Chebyshev
44
+ >>> xdata = [1, 2, 3, 4]
45
+ >>> ydata = [1, 4, 9, 16]
46
+ >>> c = Chebyshev.fit(xdata, ydata, deg=1)
47
+
48
+ is preferred over the `chebyshev.chebfit` function from the
49
+ ``np.polynomial.chebyshev`` module::
50
+
51
+ >>> from numpy.polynomial.chebyshev import chebfit
52
+ >>> c = chebfit(xdata, ydata, deg=1)
53
+
54
+ See :doc:`routines.polynomials.classes` for more details.
55
+
56
+ Convenience Classes
57
+ ===================
58
+
59
+ The following lists the various constants and methods common to all of
60
+ the classes representing the various kinds of polynomials. In the following,
61
+ the term ``Poly`` represents any one of the convenience classes (e.g.
62
+ `~polynomial.Polynomial`, `~chebyshev.Chebyshev`, `~hermite.Hermite`, etc.)
63
+ while the lowercase ``p`` represents an **instance** of a polynomial class.
64
+
65
+ Constants
66
+ ---------
67
+
68
+ - ``Poly.domain`` -- Default domain
69
+ - ``Poly.window`` -- Default window
70
+ - ``Poly.basis_name`` -- String used to represent the basis
71
+ - ``Poly.maxpower`` -- Maximum value ``n`` such that ``p**n`` is allowed
72
+ - ``Poly.nickname`` -- String used in printing
73
+
74
+ Creation
75
+ --------
76
+
77
+ Methods for creating polynomial instances.
78
+
79
+ - ``Poly.basis(degree)`` -- Basis polynomial of given degree
80
+ - ``Poly.identity()`` -- ``p`` where ``p(x) = x`` for all ``x``
81
+ - ``Poly.fit(x, y, deg)`` -- ``p`` of degree ``deg`` with coefficients
82
+ determined by the least-squares fit to the data ``x``, ``y``
83
+ - ``Poly.fromroots(roots)`` -- ``p`` with specified roots
84
+ - ``p.copy()`` -- Create a copy of ``p``
85
+
86
+ Conversion
87
+ ----------
88
+
89
+ Methods for converting a polynomial instance of one kind to another.
90
+
91
+ - ``p.cast(Poly)`` -- Convert ``p`` to instance of kind ``Poly``
92
+ - ``p.convert(Poly)`` -- Convert ``p`` to instance of kind ``Poly`` or map
93
+ between ``domain`` and ``window``
94
+
95
+ Calculus
96
+ --------
97
+ - ``p.deriv()`` -- Take the derivative of ``p``
98
+ - ``p.integ()`` -- Integrate ``p``
99
+
100
+ Validation
101
+ ----------
102
+ - ``Poly.has_samecoef(p1, p2)`` -- Check if coefficients match
103
+ - ``Poly.has_samedomain(p1, p2)`` -- Check if domains match
104
+ - ``Poly.has_sametype(p1, p2)`` -- Check if types match
105
+ - ``Poly.has_samewindow(p1, p2)`` -- Check if windows match
106
+
107
+ Misc
108
+ ----
109
+ - ``p.linspace()`` -- Return ``x, p(x)`` at equally-spaced points in ``domain``
110
+ - ``p.mapparms()`` -- Return the parameters for the linear mapping between
111
+ ``domain`` and ``window``.
112
+ - ``p.roots()`` -- Return the roots of ``p``.
113
+ - ``p.trim()`` -- Remove trailing coefficients.
114
+ - ``p.cutdeg(degree)`` -- Truncate ``p`` to given degree
115
+ - ``p.truncate(size)`` -- Truncate ``p`` to given size
116
+
117
+ """
118
+ from .polynomial import Polynomial
119
+ from .chebyshev import Chebyshev
120
+ from .legendre import Legendre
121
+ from .hermite import Hermite
122
+ from .hermite_e import HermiteE
123
+ from .laguerre import Laguerre
124
+
125
+ __all__ = [
126
+ "set_default_printstyle",
127
+ "polynomial", "Polynomial",
128
+ "chebyshev", "Chebyshev",
129
+ "legendre", "Legendre",
130
+ "hermite", "Hermite",
131
+ "hermite_e", "HermiteE",
132
+ "laguerre", "Laguerre",
133
+ ]
134
+
135
+
136
+ def set_default_printstyle(style):
137
+ """
138
+ Set the default format for the string representation of polynomials.
139
+
140
+ Values for ``style`` must be valid inputs to ``__format__``, i.e. 'ascii'
141
+ or 'unicode'.
142
+
143
+ Parameters
144
+ ----------
145
+ style : str
146
+ Format string for default printing style. Must be either 'ascii' or
147
+ 'unicode'.
148
+
149
+ Notes
150
+ -----
151
+ The default format depends on the platform: 'unicode' is used on
152
+ Unix-based systems and 'ascii' on Windows. This determination is based on
153
+ default font support for the unicode superscript and subscript ranges.
154
+
155
+ Examples
156
+ --------
157
+ >>> p = np.polynomial.Polynomial([1, 2, 3])
158
+ >>> c = np.polynomial.Chebyshev([1, 2, 3])
159
+ >>> np.polynomial.set_default_printstyle('unicode')
160
+ >>> print(p)
161
+ 1.0 + 2.0·x + 3.0·x²
162
+ >>> print(c)
163
+ 1.0 + 2.0·T₁(x) + 3.0·T₂(x)
164
+ >>> np.polynomial.set_default_printstyle('ascii')
165
+ >>> print(p)
166
+ 1.0 + 2.0 x + 3.0 x**2
167
+ >>> print(c)
168
+ 1.0 + 2.0 T_1(x) + 3.0 T_2(x)
169
+ >>> # Formatting supersedes all class/package-level defaults
170
+ >>> print(f"{p:unicode}")
171
+ 1.0 + 2.0·x + 3.0·x²
172
+ """
173
+ if style not in ('unicode', 'ascii'):
174
+ raise ValueError(
175
+ f"Unsupported format string '{style}'. Valid options are 'ascii' "
176
+ f"and 'unicode'"
177
+ )
178
+ _use_unicode = True
179
+ if style == 'ascii':
180
+ _use_unicode = False
181
+ from ._polybase import ABCPolyBase
182
+ ABCPolyBase._use_unicode = _use_unicode
183
+
184
+
185
+ from numpy._pytesttester import PytestTester
186
+ test = PytestTester(__name__)
187
+ del PytestTester
parrot/lib/python3.10/site-packages/numpy/polynomial/__init__.pyi ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Final, Literal
2
+
3
+ from .polynomial import Polynomial
4
+ from .chebyshev import Chebyshev
5
+ from .legendre import Legendre
6
+ from .hermite import Hermite
7
+ from .hermite_e import HermiteE
8
+ from .laguerre import Laguerre
9
+
10
+ __all__ = [
11
+ "set_default_printstyle",
12
+ "polynomial", "Polynomial",
13
+ "chebyshev", "Chebyshev",
14
+ "legendre", "Legendre",
15
+ "hermite", "Hermite",
16
+ "hermite_e", "HermiteE",
17
+ "laguerre", "Laguerre",
18
+ ]
19
+
20
+ def set_default_printstyle(style: Literal["ascii", "unicode"]) -> None: ...
21
+
22
+ from numpy._pytesttester import PytestTester as _PytestTester
23
+ test: Final[_PytestTester]
parrot/lib/python3.10/site-packages/numpy/polynomial/_polybase.py ADDED
@@ -0,0 +1,1223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Abstract base class for the various polynomial Classes.
3
+
4
+ The ABCPolyBase class provides the methods needed to implement the common API
5
+ for the various polynomial classes. It operates as a mixin, but uses the
6
+ abc module from the stdlib, hence it is only available for Python >= 2.6.
7
+
8
+ """
9
+ import os
10
+ import abc
11
+ import numbers
12
+ from typing import Callable
13
+
14
+ import numpy as np
15
+ from . import polyutils as pu
16
+
17
+ __all__ = ['ABCPolyBase']
18
+
19
+ class ABCPolyBase(abc.ABC):
20
+ """An abstract base class for immutable series classes.
21
+
22
+ ABCPolyBase provides the standard Python numerical methods
23
+ '+', '-', '*', '//', '%', 'divmod', '**', and '()' along with the
24
+ methods listed below.
25
+
26
+ .. versionadded:: 1.9.0
27
+
28
+ Parameters
29
+ ----------
30
+ coef : array_like
31
+ Series coefficients in order of increasing degree, i.e.,
32
+ ``(1, 2, 3)`` gives ``1*P_0(x) + 2*P_1(x) + 3*P_2(x)``, where
33
+ ``P_i`` is the basis polynomials of degree ``i``.
34
+ domain : (2,) array_like, optional
35
+ Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
36
+ to the interval ``[window[0], window[1]]`` by shifting and scaling.
37
+ The default value is the derived class domain.
38
+ window : (2,) array_like, optional
39
+ Window, see domain for its use. The default value is the
40
+ derived class window.
41
+ symbol : str, optional
42
+ Symbol used to represent the independent variable in string
43
+ representations of the polynomial expression, e.g. for printing.
44
+ The symbol must be a valid Python identifier. Default value is 'x'.
45
+
46
+ .. versionadded:: 1.24
47
+
48
+ Attributes
49
+ ----------
50
+ coef : (N,) ndarray
51
+ Series coefficients in order of increasing degree.
52
+ domain : (2,) ndarray
53
+ Domain that is mapped to window.
54
+ window : (2,) ndarray
55
+ Window that domain is mapped to.
56
+ symbol : str
57
+ Symbol representing the independent variable.
58
+
59
+ Class Attributes
60
+ ----------------
61
+ maxpower : int
62
+ Maximum power allowed, i.e., the largest number ``n`` such that
63
+ ``p(x)**n`` is allowed. This is to limit runaway polynomial size.
64
+ domain : (2,) ndarray
65
+ Default domain of the class.
66
+ window : (2,) ndarray
67
+ Default window of the class.
68
+
69
+ """
70
+
71
+ # Not hashable
72
+ __hash__ = None
73
+
74
+ # Opt out of numpy ufuncs and Python ops with ndarray subclasses.
75
+ __array_ufunc__ = None
76
+
77
+ # Limit runaway size. T_n^m has degree n*m
78
+ maxpower = 100
79
+
80
+ # Unicode character mappings for improved __str__
81
+ _superscript_mapping = str.maketrans({
82
+ "0": "⁰",
83
+ "1": "¹",
84
+ "2": "²",
85
+ "3": "³",
86
+ "4": "⁴",
87
+ "5": "⁵",
88
+ "6": "⁶",
89
+ "7": "⁷",
90
+ "8": "⁸",
91
+ "9": "⁹"
92
+ })
93
+ _subscript_mapping = str.maketrans({
94
+ "0": "₀",
95
+ "1": "₁",
96
+ "2": "₂",
97
+ "3": "₃",
98
+ "4": "₄",
99
+ "5": "₅",
100
+ "6": "₆",
101
+ "7": "₇",
102
+ "8": "₈",
103
+ "9": "₉"
104
+ })
105
+ # Some fonts don't support full unicode character ranges necessary for
106
+ # the full set of superscripts and subscripts, including common/default
107
+ # fonts in Windows shells/terminals. Therefore, default to ascii-only
108
+ # printing on windows.
109
+ _use_unicode = not os.name == 'nt'
110
+
111
+ @property
112
+ def symbol(self):
113
+ return self._symbol
114
+
115
+ @property
116
+ @abc.abstractmethod
117
+ def domain(self):
118
+ pass
119
+
120
+ @property
121
+ @abc.abstractmethod
122
+ def window(self):
123
+ pass
124
+
125
+ @property
126
+ @abc.abstractmethod
127
+ def basis_name(self):
128
+ pass
129
+
130
+ @staticmethod
131
+ @abc.abstractmethod
132
+ def _add(c1, c2):
133
+ pass
134
+
135
+ @staticmethod
136
+ @abc.abstractmethod
137
+ def _sub(c1, c2):
138
+ pass
139
+
140
+ @staticmethod
141
+ @abc.abstractmethod
142
+ def _mul(c1, c2):
143
+ pass
144
+
145
+ @staticmethod
146
+ @abc.abstractmethod
147
+ def _div(c1, c2):
148
+ pass
149
+
150
+ @staticmethod
151
+ @abc.abstractmethod
152
+ def _pow(c, pow, maxpower=None):
153
+ pass
154
+
155
+ @staticmethod
156
+ @abc.abstractmethod
157
+ def _val(x, c):
158
+ pass
159
+
160
+ @staticmethod
161
+ @abc.abstractmethod
162
+ def _int(c, m, k, lbnd, scl):
163
+ pass
164
+
165
+ @staticmethod
166
+ @abc.abstractmethod
167
+ def _der(c, m, scl):
168
+ pass
169
+
170
+ @staticmethod
171
+ @abc.abstractmethod
172
+ def _fit(x, y, deg, rcond, full):
173
+ pass
174
+
175
+ @staticmethod
176
+ @abc.abstractmethod
177
+ def _line(off, scl):
178
+ pass
179
+
180
+ @staticmethod
181
+ @abc.abstractmethod
182
+ def _roots(c):
183
+ pass
184
+
185
+ @staticmethod
186
+ @abc.abstractmethod
187
+ def _fromroots(r):
188
+ pass
189
+
190
+ def has_samecoef(self, other):
191
+ """Check if coefficients match.
192
+
193
+ .. versionadded:: 1.6.0
194
+
195
+ Parameters
196
+ ----------
197
+ other : class instance
198
+ The other class must have the ``coef`` attribute.
199
+
200
+ Returns
201
+ -------
202
+ bool : boolean
203
+ True if the coefficients are the same, False otherwise.
204
+
205
+ """
206
+ if len(self.coef) != len(other.coef):
207
+ return False
208
+ elif not np.all(self.coef == other.coef):
209
+ return False
210
+ else:
211
+ return True
212
+
213
+ def has_samedomain(self, other):
214
+ """Check if domains match.
215
+
216
+ .. versionadded:: 1.6.0
217
+
218
+ Parameters
219
+ ----------
220
+ other : class instance
221
+ The other class must have the ``domain`` attribute.
222
+
223
+ Returns
224
+ -------
225
+ bool : boolean
226
+ True if the domains are the same, False otherwise.
227
+
228
+ """
229
+ return np.all(self.domain == other.domain)
230
+
231
+ def has_samewindow(self, other):
232
+ """Check if windows match.
233
+
234
+ .. versionadded:: 1.6.0
235
+
236
+ Parameters
237
+ ----------
238
+ other : class instance
239
+ The other class must have the ``window`` attribute.
240
+
241
+ Returns
242
+ -------
243
+ bool : boolean
244
+ True if the windows are the same, False otherwise.
245
+
246
+ """
247
+ return np.all(self.window == other.window)
248
+
249
+ def has_sametype(self, other):
250
+ """Check if types match.
251
+
252
+ .. versionadded:: 1.7.0
253
+
254
+ Parameters
255
+ ----------
256
+ other : object
257
+ Class instance.
258
+
259
+ Returns
260
+ -------
261
+ bool : boolean
262
+ True if other is same class as self
263
+
264
+ """
265
+ return isinstance(other, self.__class__)
266
+
267
+ def _get_coefficients(self, other):
268
+ """Interpret other as polynomial coefficients.
269
+
270
+ The `other` argument is checked to see if it is of the same
271
+ class as self with identical domain and window. If so,
272
+ return its coefficients, otherwise return `other`.
273
+
274
+ .. versionadded:: 1.9.0
275
+
276
+ Parameters
277
+ ----------
278
+ other : anything
279
+ Object to be checked.
280
+
281
+ Returns
282
+ -------
283
+ coef
284
+ The coefficients of`other` if it is a compatible instance,
285
+ of ABCPolyBase, otherwise `other`.
286
+
287
+ Raises
288
+ ------
289
+ TypeError
290
+ When `other` is an incompatible instance of ABCPolyBase.
291
+
292
+ """
293
+ if isinstance(other, ABCPolyBase):
294
+ if not isinstance(other, self.__class__):
295
+ raise TypeError("Polynomial types differ")
296
+ elif not np.all(self.domain == other.domain):
297
+ raise TypeError("Domains differ")
298
+ elif not np.all(self.window == other.window):
299
+ raise TypeError("Windows differ")
300
+ elif self.symbol != other.symbol:
301
+ raise ValueError("Polynomial symbols differ")
302
+ return other.coef
303
+ return other
304
+
305
+ def __init__(self, coef, domain=None, window=None, symbol='x'):
306
+ [coef] = pu.as_series([coef], trim=False)
307
+ self.coef = coef
308
+
309
+ if domain is not None:
310
+ [domain] = pu.as_series([domain], trim=False)
311
+ if len(domain) != 2:
312
+ raise ValueError("Domain has wrong number of elements.")
313
+ self.domain = domain
314
+
315
+ if window is not None:
316
+ [window] = pu.as_series([window], trim=False)
317
+ if len(window) != 2:
318
+ raise ValueError("Window has wrong number of elements.")
319
+ self.window = window
320
+
321
+ # Validation for symbol
322
+ try:
323
+ if not symbol.isidentifier():
324
+ raise ValueError(
325
+ "Symbol string must be a valid Python identifier"
326
+ )
327
+ # If a user passes in something other than a string, the above
328
+ # results in an AttributeError. Catch this and raise a more
329
+ # informative exception
330
+ except AttributeError:
331
+ raise TypeError("Symbol must be a non-empty string")
332
+
333
+ self._symbol = symbol
334
+
335
+ def __repr__(self):
336
+ coef = repr(self.coef)[6:-1]
337
+ domain = repr(self.domain)[6:-1]
338
+ window = repr(self.window)[6:-1]
339
+ name = self.__class__.__name__
340
+ return (f"{name}({coef}, domain={domain}, window={window}, "
341
+ f"symbol='{self.symbol}')")
342
+
343
+ def __format__(self, fmt_str):
344
+ if fmt_str == '':
345
+ return self.__str__()
346
+ if fmt_str not in ('ascii', 'unicode'):
347
+ raise ValueError(
348
+ f"Unsupported format string '{fmt_str}' passed to "
349
+ f"{self.__class__}.__format__. Valid options are "
350
+ f"'ascii' and 'unicode'"
351
+ )
352
+ if fmt_str == 'ascii':
353
+ return self._generate_string(self._str_term_ascii)
354
+ return self._generate_string(self._str_term_unicode)
355
+
356
+ def __str__(self):
357
+ if self._use_unicode:
358
+ return self._generate_string(self._str_term_unicode)
359
+ return self._generate_string(self._str_term_ascii)
360
+
361
+ def _generate_string(self, term_method):
362
+ """
363
+ Generate the full string representation of the polynomial, using
364
+ ``term_method`` to generate each polynomial term.
365
+ """
366
+ # Get configuration for line breaks
367
+ linewidth = np.get_printoptions().get('linewidth', 75)
368
+ if linewidth < 1:
369
+ linewidth = 1
370
+ out = pu.format_float(self.coef[0])
371
+
372
+ off, scale = self.mapparms()
373
+
374
+ scaled_symbol, needs_parens = self._format_term(pu.format_float,
375
+ off, scale)
376
+ if needs_parens:
377
+ scaled_symbol = '(' + scaled_symbol + ')'
378
+
379
+ for i, coef in enumerate(self.coef[1:]):
380
+ out += " "
381
+ power = str(i + 1)
382
+ # Polynomial coefficient
383
+ # The coefficient array can be an object array with elements that
384
+ # will raise a TypeError with >= 0 (e.g. strings or Python
385
+ # complex). In this case, represent the coefficient as-is.
386
+ try:
387
+ if coef >= 0:
388
+ next_term = "+ " + pu.format_float(coef, parens=True)
389
+ else:
390
+ next_term = "- " + pu.format_float(-coef, parens=True)
391
+ except TypeError:
392
+ next_term = f"+ {coef}"
393
+ # Polynomial term
394
+ next_term += term_method(power, scaled_symbol)
395
+ # Length of the current line with next term added
396
+ line_len = len(out.split('\n')[-1]) + len(next_term)
397
+ # If not the last term in the polynomial, it will be two
398
+ # characters longer due to the +/- with the next term
399
+ if i < len(self.coef[1:]) - 1:
400
+ line_len += 2
401
+ # Handle linebreaking
402
+ if line_len >= linewidth:
403
+ next_term = next_term.replace(" ", "\n", 1)
404
+ out += next_term
405
+ return out
406
+
407
+ @classmethod
408
+ def _str_term_unicode(cls, i, arg_str):
409
+ """
410
+ String representation of single polynomial term using unicode
411
+ characters for superscripts and subscripts.
412
+ """
413
+ if cls.basis_name is None:
414
+ raise NotImplementedError(
415
+ "Subclasses must define either a basis_name, or override "
416
+ "_str_term_unicode(cls, i, arg_str)"
417
+ )
418
+ return (f"·{cls.basis_name}{i.translate(cls._subscript_mapping)}"
419
+ f"({arg_str})")
420
+
421
+ @classmethod
422
+ def _str_term_ascii(cls, i, arg_str):
423
+ """
424
+ String representation of a single polynomial term using ** and _ to
425
+ represent superscripts and subscripts, respectively.
426
+ """
427
+ if cls.basis_name is None:
428
+ raise NotImplementedError(
429
+ "Subclasses must define either a basis_name, or override "
430
+ "_str_term_ascii(cls, i, arg_str)"
431
+ )
432
+ return f" {cls.basis_name}_{i}({arg_str})"
433
+
434
+ @classmethod
435
+ def _repr_latex_term(cls, i, arg_str, needs_parens):
436
+ if cls.basis_name is None:
437
+ raise NotImplementedError(
438
+ "Subclasses must define either a basis name, or override "
439
+ "_repr_latex_term(i, arg_str, needs_parens)")
440
+ # since we always add parens, we don't care if the expression needs them
441
+ return f"{{{cls.basis_name}}}_{{{i}}}({arg_str})"
442
+
443
+ @staticmethod
444
+ def _repr_latex_scalar(x, parens=False):
445
+ # TODO: we're stuck with disabling math formatting until we handle
446
+ # exponents in this function
447
+ return r'\text{{{}}}'.format(pu.format_float(x, parens=parens))
448
+
449
+ def _format_term(self, scalar_format: Callable, off: float, scale: float):
450
+ """ Format a single term in the expansion """
451
+ if off == 0 and scale == 1:
452
+ term = self.symbol
453
+ needs_parens = False
454
+ elif scale == 1:
455
+ term = f"{scalar_format(off)} + {self.symbol}"
456
+ needs_parens = True
457
+ elif off == 0:
458
+ term = f"{scalar_format(scale)}{self.symbol}"
459
+ needs_parens = True
460
+ else:
461
+ term = (
462
+ f"{scalar_format(off)} + "
463
+ f"{scalar_format(scale)}{self.symbol}"
464
+ )
465
+ needs_parens = True
466
+ return term, needs_parens
467
+
468
+ def _repr_latex_(self):
469
+ # get the scaled argument string to the basis functions
470
+ off, scale = self.mapparms()
471
+ term, needs_parens = self._format_term(self._repr_latex_scalar,
472
+ off, scale)
473
+
474
+ mute = r"\color{{LightGray}}{{{}}}".format
475
+
476
+ parts = []
477
+ for i, c in enumerate(self.coef):
478
+ # prevent duplication of + and - signs
479
+ if i == 0:
480
+ coef_str = f"{self._repr_latex_scalar(c)}"
481
+ elif not isinstance(c, numbers.Real):
482
+ coef_str = f" + ({self._repr_latex_scalar(c)})"
483
+ elif c >= 0:
484
+ coef_str = f" + {self._repr_latex_scalar(c, parens=True)}"
485
+ else:
486
+ coef_str = f" - {self._repr_latex_scalar(-c, parens=True)}"
487
+
488
+ # produce the string for the term
489
+ term_str = self._repr_latex_term(i, term, needs_parens)
490
+ if term_str == '1':
491
+ part = coef_str
492
+ else:
493
+ part = rf"{coef_str}\,{term_str}"
494
+
495
+ if c == 0:
496
+ part = mute(part)
497
+
498
+ parts.append(part)
499
+
500
+ if parts:
501
+ body = ''.join(parts)
502
+ else:
503
+ # in case somehow there are no coefficients at all
504
+ body = '0'
505
+
506
+ return rf"${self.symbol} \mapsto {body}$"
507
+
508
+
509
+
510
+ # Pickle and copy
511
+
512
+ def __getstate__(self):
513
+ ret = self.__dict__.copy()
514
+ ret['coef'] = self.coef.copy()
515
+ ret['domain'] = self.domain.copy()
516
+ ret['window'] = self.window.copy()
517
+ ret['symbol'] = self.symbol
518
+ return ret
519
+
520
+ def __setstate__(self, dict):
521
+ self.__dict__ = dict
522
+
523
+ # Call
524
+
525
+ def __call__(self, arg):
526
+ arg = pu.mapdomain(arg, self.domain, self.window)
527
+ return self._val(arg, self.coef)
528
+
529
+ def __iter__(self):
530
+ return iter(self.coef)
531
+
532
+ def __len__(self):
533
+ return len(self.coef)
534
+
535
+ # Numeric properties.
536
+
537
+ def __neg__(self):
538
+ return self.__class__(
539
+ -self.coef, self.domain, self.window, self.symbol
540
+ )
541
+
542
+ def __pos__(self):
543
+ return self
544
+
545
+ def __add__(self, other):
546
+ othercoef = self._get_coefficients(other)
547
+ try:
548
+ coef = self._add(self.coef, othercoef)
549
+ except Exception:
550
+ return NotImplemented
551
+ return self.__class__(coef, self.domain, self.window, self.symbol)
552
+
553
+ def __sub__(self, other):
554
+ othercoef = self._get_coefficients(other)
555
+ try:
556
+ coef = self._sub(self.coef, othercoef)
557
+ except Exception:
558
+ return NotImplemented
559
+ return self.__class__(coef, self.domain, self.window, self.symbol)
560
+
561
+ def __mul__(self, other):
562
+ othercoef = self._get_coefficients(other)
563
+ try:
564
+ coef = self._mul(self.coef, othercoef)
565
+ except Exception:
566
+ return NotImplemented
567
+ return self.__class__(coef, self.domain, self.window, self.symbol)
568
+
569
+ def __truediv__(self, other):
570
+ # there is no true divide if the rhs is not a Number, although it
571
+ # could return the first n elements of an infinite series.
572
+ # It is hard to see where n would come from, though.
573
+ if not isinstance(other, numbers.Number) or isinstance(other, bool):
574
+ raise TypeError(
575
+ f"unsupported types for true division: "
576
+ f"'{type(self)}', '{type(other)}'"
577
+ )
578
+ return self.__floordiv__(other)
579
+
580
+ def __floordiv__(self, other):
581
+ res = self.__divmod__(other)
582
+ if res is NotImplemented:
583
+ return res
584
+ return res[0]
585
+
586
+ def __mod__(self, other):
587
+ res = self.__divmod__(other)
588
+ if res is NotImplemented:
589
+ return res
590
+ return res[1]
591
+
592
+ def __divmod__(self, other):
593
+ othercoef = self._get_coefficients(other)
594
+ try:
595
+ quo, rem = self._div(self.coef, othercoef)
596
+ except ZeroDivisionError:
597
+ raise
598
+ except Exception:
599
+ return NotImplemented
600
+ quo = self.__class__(quo, self.domain, self.window, self.symbol)
601
+ rem = self.__class__(rem, self.domain, self.window, self.symbol)
602
+ return quo, rem
603
+
604
+ def __pow__(self, other):
605
+ coef = self._pow(self.coef, other, maxpower=self.maxpower)
606
+ res = self.__class__(coef, self.domain, self.window, self.symbol)
607
+ return res
608
+
609
+ def __radd__(self, other):
610
+ try:
611
+ coef = self._add(other, self.coef)
612
+ except Exception:
613
+ return NotImplemented
614
+ return self.__class__(coef, self.domain, self.window, self.symbol)
615
+
616
+ def __rsub__(self, other):
617
+ try:
618
+ coef = self._sub(other, self.coef)
619
+ except Exception:
620
+ return NotImplemented
621
+ return self.__class__(coef, self.domain, self.window, self.symbol)
622
+
623
+ def __rmul__(self, other):
624
+ try:
625
+ coef = self._mul(other, self.coef)
626
+ except Exception:
627
+ return NotImplemented
628
+ return self.__class__(coef, self.domain, self.window, self.symbol)
629
+
630
+ def __rdiv__(self, other):
631
+ # set to __floordiv__ /.
632
+ return self.__rfloordiv__(other)
633
+
634
+ def __rtruediv__(self, other):
635
+ # An instance of ABCPolyBase is not considered a
636
+ # Number.
637
+ return NotImplemented
638
+
639
+ def __rfloordiv__(self, other):
640
+ res = self.__rdivmod__(other)
641
+ if res is NotImplemented:
642
+ return res
643
+ return res[0]
644
+
645
+ def __rmod__(self, other):
646
+ res = self.__rdivmod__(other)
647
+ if res is NotImplemented:
648
+ return res
649
+ return res[1]
650
+
651
+ def __rdivmod__(self, other):
652
+ try:
653
+ quo, rem = self._div(other, self.coef)
654
+ except ZeroDivisionError:
655
+ raise
656
+ except Exception:
657
+ return NotImplemented
658
+ quo = self.__class__(quo, self.domain, self.window, self.symbol)
659
+ rem = self.__class__(rem, self.domain, self.window, self.symbol)
660
+ return quo, rem
661
+
662
+ def __eq__(self, other):
663
+ res = (isinstance(other, self.__class__) and
664
+ np.all(self.domain == other.domain) and
665
+ np.all(self.window == other.window) and
666
+ (self.coef.shape == other.coef.shape) and
667
+ np.all(self.coef == other.coef) and
668
+ (self.symbol == other.symbol))
669
+ return res
670
+
671
+ def __ne__(self, other):
672
+ return not self.__eq__(other)
673
+
674
+ #
675
+ # Extra methods.
676
+ #
677
+
678
+ def copy(self):
679
+ """Return a copy.
680
+
681
+ Returns
682
+ -------
683
+ new_series : series
684
+ Copy of self.
685
+
686
+ """
687
+ return self.__class__(self.coef, self.domain, self.window, self.symbol)
688
+
689
+ def degree(self):
690
+ """The degree of the series.
691
+
692
+ .. versionadded:: 1.5.0
693
+
694
+ Returns
695
+ -------
696
+ degree : int
697
+ Degree of the series, one less than the number of coefficients.
698
+
699
+ Examples
700
+ --------
701
+
702
+ Create a polynomial object for ``1 + 7*x + 4*x**2``:
703
+
704
+ >>> poly = np.polynomial.Polynomial([1, 7, 4])
705
+ >>> print(poly)
706
+ 1.0 + 7.0·x + 4.0·x²
707
+ >>> poly.degree()
708
+ 2
709
+
710
+ Note that this method does not check for non-zero coefficients.
711
+ You must trim the polynomial to remove any trailing zeroes:
712
+
713
+ >>> poly = np.polynomial.Polynomial([1, 7, 0])
714
+ >>> print(poly)
715
+ 1.0 + 7.0·x + 0.0·x²
716
+ >>> poly.degree()
717
+ 2
718
+ >>> poly.trim().degree()
719
+ 1
720
+
721
+ """
722
+ return len(self) - 1
723
+
724
+ def cutdeg(self, deg):
725
+ """Truncate series to the given degree.
726
+
727
+ Reduce the degree of the series to `deg` by discarding the
728
+ high order terms. If `deg` is greater than the current degree a
729
+ copy of the current series is returned. This can be useful in least
730
+ squares where the coefficients of the high degree terms may be very
731
+ small.
732
+
733
+ .. versionadded:: 1.5.0
734
+
735
+ Parameters
736
+ ----------
737
+ deg : non-negative int
738
+ The series is reduced to degree `deg` by discarding the high
739
+ order terms. The value of `deg` must be a non-negative integer.
740
+
741
+ Returns
742
+ -------
743
+ new_series : series
744
+ New instance of series with reduced degree.
745
+
746
+ """
747
+ return self.truncate(deg + 1)
748
+
749
+ def trim(self, tol=0):
750
+ """Remove trailing coefficients
751
+
752
+ Remove trailing coefficients until a coefficient is reached whose
753
+ absolute value greater than `tol` or the beginning of the series is
754
+ reached. If all the coefficients would be removed the series is set
755
+ to ``[0]``. A new series instance is returned with the new
756
+ coefficients. The current instance remains unchanged.
757
+
758
+ Parameters
759
+ ----------
760
+ tol : non-negative number.
761
+ All trailing coefficients less than `tol` will be removed.
762
+
763
+ Returns
764
+ -------
765
+ new_series : series
766
+ New instance of series with trimmed coefficients.
767
+
768
+ """
769
+ coef = pu.trimcoef(self.coef, tol)
770
+ return self.__class__(coef, self.domain, self.window, self.symbol)
771
+
772
+ def truncate(self, size):
773
+ """Truncate series to length `size`.
774
+
775
+ Reduce the series to length `size` by discarding the high
776
+ degree terms. The value of `size` must be a positive integer. This
777
+ can be useful in least squares where the coefficients of the
778
+ high degree terms may be very small.
779
+
780
+ Parameters
781
+ ----------
782
+ size : positive int
783
+ The series is reduced to length `size` by discarding the high
784
+ degree terms. The value of `size` must be a positive integer.
785
+
786
+ Returns
787
+ -------
788
+ new_series : series
789
+ New instance of series with truncated coefficients.
790
+
791
+ """
792
+ isize = int(size)
793
+ if isize != size or isize < 1:
794
+ raise ValueError("size must be a positive integer")
795
+ if isize >= len(self.coef):
796
+ coef = self.coef
797
+ else:
798
+ coef = self.coef[:isize]
799
+ return self.__class__(coef, self.domain, self.window, self.symbol)
800
+
801
+ def convert(self, domain=None, kind=None, window=None):
802
+ """Convert series to a different kind and/or domain and/or window.
803
+
804
+ Parameters
805
+ ----------
806
+ domain : array_like, optional
807
+ The domain of the converted series. If the value is None,
808
+ the default domain of `kind` is used.
809
+ kind : class, optional
810
+ The polynomial series type class to which the current instance
811
+ should be converted. If kind is None, then the class of the
812
+ current instance is used.
813
+ window : array_like, optional
814
+ The window of the converted series. If the value is None,
815
+ the default window of `kind` is used.
816
+
817
+ Returns
818
+ -------
819
+ new_series : series
820
+ The returned class can be of different type than the current
821
+ instance and/or have a different domain and/or different
822
+ window.
823
+
824
+ Notes
825
+ -----
826
+ Conversion between domains and class types can result in
827
+ numerically ill defined series.
828
+
829
+ """
830
+ if kind is None:
831
+ kind = self.__class__
832
+ if domain is None:
833
+ domain = kind.domain
834
+ if window is None:
835
+ window = kind.window
836
+ return self(kind.identity(domain, window=window, symbol=self.symbol))
837
+
838
+ def mapparms(self):
839
+ """Return the mapping parameters.
840
+
841
+ The returned values define a linear map ``off + scl*x`` that is
842
+ applied to the input arguments before the series is evaluated. The
843
+ map depends on the ``domain`` and ``window``; if the current
844
+ ``domain`` is equal to the ``window`` the resulting map is the
845
+ identity. If the coefficients of the series instance are to be
846
+ used by themselves outside this class, then the linear function
847
+ must be substituted for the ``x`` in the standard representation of
848
+ the base polynomials.
849
+
850
+ Returns
851
+ -------
852
+ off, scl : float or complex
853
+ The mapping function is defined by ``off + scl*x``.
854
+
855
+ Notes
856
+ -----
857
+ If the current domain is the interval ``[l1, r1]`` and the window
858
+ is ``[l2, r2]``, then the linear mapping function ``L`` is
859
+ defined by the equations::
860
+
861
+ L(l1) = l2
862
+ L(r1) = r2
863
+
864
+ """
865
+ return pu.mapparms(self.domain, self.window)
866
+
867
+ def integ(self, m=1, k=[], lbnd=None):
868
+ """Integrate.
869
+
870
+ Return a series instance that is the definite integral of the
871
+ current series.
872
+
873
+ Parameters
874
+ ----------
875
+ m : non-negative int
876
+ The number of integrations to perform.
877
+ k : array_like
878
+ Integration constants. The first constant is applied to the
879
+ first integration, the second to the second, and so on. The
880
+ list of values must less than or equal to `m` in length and any
881
+ missing values are set to zero.
882
+ lbnd : Scalar
883
+ The lower bound of the definite integral.
884
+
885
+ Returns
886
+ -------
887
+ new_series : series
888
+ A new series representing the integral. The domain is the same
889
+ as the domain of the integrated series.
890
+
891
+ """
892
+ off, scl = self.mapparms()
893
+ if lbnd is None:
894
+ lbnd = 0
895
+ else:
896
+ lbnd = off + scl*lbnd
897
+ coef = self._int(self.coef, m, k, lbnd, 1./scl)
898
+ return self.__class__(coef, self.domain, self.window, self.symbol)
899
+
900
+ def deriv(self, m=1):
901
+ """Differentiate.
902
+
903
+ Return a series instance of that is the derivative of the current
904
+ series.
905
+
906
+ Parameters
907
+ ----------
908
+ m : non-negative int
909
+ Find the derivative of order `m`.
910
+
911
+ Returns
912
+ -------
913
+ new_series : series
914
+ A new series representing the derivative. The domain is the same
915
+ as the domain of the differentiated series.
916
+
917
+ """
918
+ off, scl = self.mapparms()
919
+ coef = self._der(self.coef, m, scl)
920
+ return self.__class__(coef, self.domain, self.window, self.symbol)
921
+
922
+ def roots(self):
923
+ """Return the roots of the series polynomial.
924
+
925
+ Compute the roots for the series. Note that the accuracy of the
926
+ roots decreases the further outside the `domain` they lie.
927
+
928
+ Returns
929
+ -------
930
+ roots : ndarray
931
+ Array containing the roots of the series.
932
+
933
+ """
934
+ roots = self._roots(self.coef)
935
+ return pu.mapdomain(roots, self.window, self.domain)
936
+
937
+ def linspace(self, n=100, domain=None):
938
+ """Return x, y values at equally spaced points in domain.
939
+
940
+ Returns the x, y values at `n` linearly spaced points across the
941
+ domain. Here y is the value of the polynomial at the points x. By
942
+ default the domain is the same as that of the series instance.
943
+ This method is intended mostly as a plotting aid.
944
+
945
+ .. versionadded:: 1.5.0
946
+
947
+ Parameters
948
+ ----------
949
+ n : int, optional
950
+ Number of point pairs to return. The default value is 100.
951
+ domain : {None, array_like}, optional
952
+ If not None, the specified domain is used instead of that of
953
+ the calling instance. It should be of the form ``[beg,end]``.
954
+ The default is None which case the class domain is used.
955
+
956
+ Returns
957
+ -------
958
+ x, y : ndarray
959
+ x is equal to linspace(self.domain[0], self.domain[1], n) and
960
+ y is the series evaluated at element of x.
961
+
962
+ """
963
+ if domain is None:
964
+ domain = self.domain
965
+ x = np.linspace(domain[0], domain[1], n)
966
+ y = self(x)
967
+ return x, y
968
+
969
+ @classmethod
970
+ def fit(cls, x, y, deg, domain=None, rcond=None, full=False, w=None,
971
+ window=None, symbol='x'):
972
+ """Least squares fit to data.
973
+
974
+ Return a series instance that is the least squares fit to the data
975
+ `y` sampled at `x`. The domain of the returned instance can be
976
+ specified and this will often result in a superior fit with less
977
+ chance of ill conditioning.
978
+
979
+ Parameters
980
+ ----------
981
+ x : array_like, shape (M,)
982
+ x-coordinates of the M sample points ``(x[i], y[i])``.
983
+ y : array_like, shape (M,)
984
+ y-coordinates of the M sample points ``(x[i], y[i])``.
985
+ deg : int or 1-D array_like
986
+ Degree(s) of the fitting polynomials. If `deg` is a single integer
987
+ all terms up to and including the `deg`'th term are included in the
988
+ fit. For NumPy versions >= 1.11.0 a list of integers specifying the
989
+ degrees of the terms to include may be used instead.
990
+ domain : {None, [beg, end], []}, optional
991
+ Domain to use for the returned series. If ``None``,
992
+ then a minimal domain that covers the points `x` is chosen. If
993
+ ``[]`` the class domain is used. The default value was the
994
+ class domain in NumPy 1.4 and ``None`` in later versions.
995
+ The ``[]`` option was added in numpy 1.5.0.
996
+ rcond : float, optional
997
+ Relative condition number of the fit. Singular values smaller
998
+ than this relative to the largest singular value will be
999
+ ignored. The default value is ``len(x)*eps``, where eps is the
1000
+ relative precision of the float type, about 2e-16 in most
1001
+ cases.
1002
+ full : bool, optional
1003
+ Switch determining nature of return value. When it is False
1004
+ (the default) just the coefficients are returned, when True
1005
+ diagnostic information from the singular value decomposition is
1006
+ also returned.
1007
+ w : array_like, shape (M,), optional
1008
+ Weights. If not None, the weight ``w[i]`` applies to the unsquared
1009
+ residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1010
+ chosen so that the errors of the products ``w[i]*y[i]`` all have
1011
+ the same variance. When using inverse-variance weighting, use
1012
+ ``w[i] = 1/sigma(y[i])``. The default value is None.
1013
+
1014
+ .. versionadded:: 1.5.0
1015
+ window : {[beg, end]}, optional
1016
+ Window to use for the returned series. The default
1017
+ value is the default class domain
1018
+
1019
+ .. versionadded:: 1.6.0
1020
+ symbol : str, optional
1021
+ Symbol representing the independent variable. Default is 'x'.
1022
+
1023
+ Returns
1024
+ -------
1025
+ new_series : series
1026
+ A series that represents the least squares fit to the data and
1027
+ has the domain and window specified in the call. If the
1028
+ coefficients for the unscaled and unshifted basis polynomials are
1029
+ of interest, do ``new_series.convert().coef``.
1030
+
1031
+ [resid, rank, sv, rcond] : list
1032
+ These values are only returned if ``full == True``
1033
+
1034
+ - resid -- sum of squared residuals of the least squares fit
1035
+ - rank -- the numerical rank of the scaled Vandermonde matrix
1036
+ - sv -- singular values of the scaled Vandermonde matrix
1037
+ - rcond -- value of `rcond`.
1038
+
1039
+ For more details, see `linalg.lstsq`.
1040
+
1041
+ """
1042
+ if domain is None:
1043
+ domain = pu.getdomain(x)
1044
+ if domain[0] == domain[1]:
1045
+ domain[0] -= 1
1046
+ domain[1] += 1
1047
+ elif type(domain) is list and len(domain) == 0:
1048
+ domain = cls.domain
1049
+
1050
+ if window is None:
1051
+ window = cls.window
1052
+
1053
+ xnew = pu.mapdomain(x, domain, window)
1054
+ res = cls._fit(xnew, y, deg, w=w, rcond=rcond, full=full)
1055
+ if full:
1056
+ [coef, status] = res
1057
+ return (
1058
+ cls(coef, domain=domain, window=window, symbol=symbol), status
1059
+ )
1060
+ else:
1061
+ coef = res
1062
+ return cls(coef, domain=domain, window=window, symbol=symbol)
1063
+
1064
+ @classmethod
1065
+ def fromroots(cls, roots, domain=[], window=None, symbol='x'):
1066
+ """Return series instance that has the specified roots.
1067
+
1068
+ Returns a series representing the product
1069
+ ``(x - r[0])*(x - r[1])*...*(x - r[n-1])``, where ``r`` is a
1070
+ list of roots.
1071
+
1072
+ Parameters
1073
+ ----------
1074
+ roots : array_like
1075
+ List of roots.
1076
+ domain : {[], None, array_like}, optional
1077
+ Domain for the resulting series. If None the domain is the
1078
+ interval from the smallest root to the largest. If [] the
1079
+ domain is the class domain. The default is [].
1080
+ window : {None, array_like}, optional
1081
+ Window for the returned series. If None the class window is
1082
+ used. The default is None.
1083
+ symbol : str, optional
1084
+ Symbol representing the independent variable. Default is 'x'.
1085
+
1086
+ Returns
1087
+ -------
1088
+ new_series : series
1089
+ Series with the specified roots.
1090
+
1091
+ """
1092
+ [roots] = pu.as_series([roots], trim=False)
1093
+ if domain is None:
1094
+ domain = pu.getdomain(roots)
1095
+ elif type(domain) is list and len(domain) == 0:
1096
+ domain = cls.domain
1097
+
1098
+ if window is None:
1099
+ window = cls.window
1100
+
1101
+ deg = len(roots)
1102
+ off, scl = pu.mapparms(domain, window)
1103
+ rnew = off + scl*roots
1104
+ coef = cls._fromroots(rnew) / scl**deg
1105
+ return cls(coef, domain=domain, window=window, symbol=symbol)
1106
+
1107
+ @classmethod
1108
+ def identity(cls, domain=None, window=None, symbol='x'):
1109
+ """Identity function.
1110
+
1111
+ If ``p`` is the returned series, then ``p(x) == x`` for all
1112
+ values of x.
1113
+
1114
+ Parameters
1115
+ ----------
1116
+ domain : {None, array_like}, optional
1117
+ If given, the array must be of the form ``[beg, end]``, where
1118
+ ``beg`` and ``end`` are the endpoints of the domain. If None is
1119
+ given then the class domain is used. The default is None.
1120
+ window : {None, array_like}, optional
1121
+ If given, the resulting array must be if the form
1122
+ ``[beg, end]``, where ``beg`` and ``end`` are the endpoints of
1123
+ the window. If None is given then the class window is used. The
1124
+ default is None.
1125
+ symbol : str, optional
1126
+ Symbol representing the independent variable. Default is 'x'.
1127
+
1128
+ Returns
1129
+ -------
1130
+ new_series : series
1131
+ Series of representing the identity.
1132
+
1133
+ """
1134
+ if domain is None:
1135
+ domain = cls.domain
1136
+ if window is None:
1137
+ window = cls.window
1138
+ off, scl = pu.mapparms(window, domain)
1139
+ coef = cls._line(off, scl)
1140
+ return cls(coef, domain, window, symbol)
1141
+
1142
+ @classmethod
1143
+ def basis(cls, deg, domain=None, window=None, symbol='x'):
1144
+ """Series basis polynomial of degree `deg`.
1145
+
1146
+ Returns the series representing the basis polynomial of degree `deg`.
1147
+
1148
+ .. versionadded:: 1.7.0
1149
+
1150
+ Parameters
1151
+ ----------
1152
+ deg : int
1153
+ Degree of the basis polynomial for the series. Must be >= 0.
1154
+ domain : {None, array_like}, optional
1155
+ If given, the array must be of the form ``[beg, end]``, where
1156
+ ``beg`` and ``end`` are the endpoints of the domain. If None is
1157
+ given then the class domain is used. The default is None.
1158
+ window : {None, array_like}, optional
1159
+ If given, the resulting array must be if the form
1160
+ ``[beg, end]``, where ``beg`` and ``end`` are the endpoints of
1161
+ the window. If None is given then the class window is used. The
1162
+ default is None.
1163
+ symbol : str, optional
1164
+ Symbol representing the independent variable. Default is 'x'.
1165
+
1166
+ Returns
1167
+ -------
1168
+ new_series : series
1169
+ A series with the coefficient of the `deg` term set to one and
1170
+ all others zero.
1171
+
1172
+ """
1173
+ if domain is None:
1174
+ domain = cls.domain
1175
+ if window is None:
1176
+ window = cls.window
1177
+ ideg = int(deg)
1178
+
1179
+ if ideg != deg or ideg < 0:
1180
+ raise ValueError("deg must be non-negative integer")
1181
+ return cls([0]*ideg + [1], domain, window, symbol)
1182
+
1183
+ @classmethod
1184
+ def cast(cls, series, domain=None, window=None):
1185
+ """Convert series to series of this class.
1186
+
1187
+ The `series` is expected to be an instance of some polynomial
1188
+ series of one of the types supported by by the numpy.polynomial
1189
+ module, but could be some other class that supports the convert
1190
+ method.
1191
+
1192
+ .. versionadded:: 1.7.0
1193
+
1194
+ Parameters
1195
+ ----------
1196
+ series : series
1197
+ The series instance to be converted.
1198
+ domain : {None, array_like}, optional
1199
+ If given, the array must be of the form ``[beg, end]``, where
1200
+ ``beg`` and ``end`` are the endpoints of the domain. If None is
1201
+ given then the class domain is used. The default is None.
1202
+ window : {None, array_like}, optional
1203
+ If given, the resulting array must be if the form
1204
+ ``[beg, end]``, where ``beg`` and ``end`` are the endpoints of
1205
+ the window. If None is given then the class window is used. The
1206
+ default is None.
1207
+
1208
+ Returns
1209
+ -------
1210
+ new_series : series
1211
+ A series of the same kind as the calling class and equal to
1212
+ `series` when evaluated.
1213
+
1214
+ See Also
1215
+ --------
1216
+ convert : similar instance method
1217
+
1218
+ """
1219
+ if domain is None:
1220
+ domain = cls.domain
1221
+ if window is None:
1222
+ window = cls.window
1223
+ return series.convert(domain, cls, window)
parrot/lib/python3.10/site-packages/numpy/polynomial/_polybase.pyi ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import abc
2
+ import decimal
3
+ import numbers
4
+ import sys
5
+ from collections.abc import Iterator, Mapping, Sequence
6
+ from typing import (
7
+ TYPE_CHECKING,
8
+ Any,
9
+ ClassVar,
10
+ Final,
11
+ Generic,
12
+ Literal,
13
+ SupportsIndex,
14
+ TypeAlias,
15
+ TypeGuard,
16
+ TypeVar,
17
+ overload,
18
+ )
19
+
20
+ import numpy as np
21
+ import numpy.typing as npt
22
+ from numpy._typing import (
23
+ _FloatLike_co,
24
+ _NumberLike_co,
25
+
26
+ _ArrayLikeFloat_co,
27
+ _ArrayLikeComplex_co,
28
+ )
29
+
30
+ from ._polytypes import (
31
+ _AnyInt,
32
+ _CoefLike_co,
33
+
34
+ _Array2,
35
+ _Tuple2,
36
+
37
+ _Series,
38
+ _CoefSeries,
39
+
40
+ _SeriesLikeInt_co,
41
+ _SeriesLikeCoef_co,
42
+
43
+ _ArrayLikeCoefObject_co,
44
+ _ArrayLikeCoef_co,
45
+ )
46
+
47
+ if sys.version_info >= (3, 11):
48
+ from typing import LiteralString
49
+ elif TYPE_CHECKING:
50
+ from typing_extensions import LiteralString
51
+ else:
52
+ LiteralString: TypeAlias = str
53
+
54
+
55
+ __all__: Final[Sequence[str]] = ("ABCPolyBase",)
56
+
57
+
58
+ _NameCo = TypeVar("_NameCo", bound=None | LiteralString, covariant=True)
59
+ _Self = TypeVar("_Self", bound="ABCPolyBase")
60
+ _Other = TypeVar("_Other", bound="ABCPolyBase")
61
+
62
+ _AnyOther: TypeAlias = ABCPolyBase | _CoefLike_co | _SeriesLikeCoef_co
63
+ _Hundred: TypeAlias = Literal[100]
64
+
65
+
66
+ class ABCPolyBase(Generic[_NameCo], metaclass=abc.ABCMeta):
67
+ __hash__: ClassVar[None] # type: ignore[assignment]
68
+ __array_ufunc__: ClassVar[None]
69
+
70
+ maxpower: ClassVar[_Hundred]
71
+ _superscript_mapping: ClassVar[Mapping[int, str]]
72
+ _subscript_mapping: ClassVar[Mapping[int, str]]
73
+ _use_unicode: ClassVar[bool]
74
+
75
+ basis_name: _NameCo
76
+ coef: _CoefSeries
77
+ domain: _Array2[np.inexact[Any] | np.object_]
78
+ window: _Array2[np.inexact[Any] | np.object_]
79
+
80
+ _symbol: LiteralString
81
+ @property
82
+ def symbol(self, /) -> LiteralString: ...
83
+
84
+ def __init__(
85
+ self,
86
+ /,
87
+ coef: _SeriesLikeCoef_co,
88
+ domain: None | _SeriesLikeCoef_co = ...,
89
+ window: None | _SeriesLikeCoef_co = ...,
90
+ symbol: str = ...,
91
+ ) -> None: ...
92
+
93
+ @overload
94
+ def __call__(self, /, arg: _Other) -> _Other: ...
95
+ # TODO: Once `_ShapeType@ndarray` is covariant and bounded (see #26081),
96
+ # additionally include 0-d arrays as input types with scalar return type.
97
+ @overload
98
+ def __call__(
99
+ self,
100
+ /,
101
+ arg: _FloatLike_co | decimal.Decimal | numbers.Real | np.object_,
102
+ ) -> np.float64 | np.complex128: ...
103
+ @overload
104
+ def __call__(
105
+ self,
106
+ /,
107
+ arg: _NumberLike_co | numbers.Complex,
108
+ ) -> np.complex128: ...
109
+ @overload
110
+ def __call__(self, /, arg: _ArrayLikeFloat_co) -> (
111
+ npt.NDArray[np.float64]
112
+ | npt.NDArray[np.complex128]
113
+ | npt.NDArray[np.object_]
114
+ ): ...
115
+ @overload
116
+ def __call__(
117
+ self,
118
+ /,
119
+ arg: _ArrayLikeComplex_co,
120
+ ) -> npt.NDArray[np.complex128] | npt.NDArray[np.object_]: ...
121
+ @overload
122
+ def __call__(
123
+ self,
124
+ /,
125
+ arg: _ArrayLikeCoefObject_co,
126
+ ) -> npt.NDArray[np.object_]: ...
127
+
128
+ def __str__(self, /) -> str: ...
129
+ def __repr__(self, /) -> str: ...
130
+ def __format__(self, fmt_str: str, /) -> str: ...
131
+ def __eq__(self, x: object, /) -> bool: ...
132
+ def __ne__(self, x: object, /) -> bool: ...
133
+ def __neg__(self: _Self, /) -> _Self: ...
134
+ def __pos__(self: _Self, /) -> _Self: ...
135
+ def __add__(self: _Self, x: _AnyOther, /) -> _Self: ...
136
+ def __sub__(self: _Self, x: _AnyOther, /) -> _Self: ...
137
+ def __mul__(self: _Self, x: _AnyOther, /) -> _Self: ...
138
+ def __truediv__(self: _Self, x: _AnyOther, /) -> _Self: ...
139
+ def __floordiv__(self: _Self, x: _AnyOther, /) -> _Self: ...
140
+ def __mod__(self: _Self, x: _AnyOther, /) -> _Self: ...
141
+ def __divmod__(self: _Self, x: _AnyOther, /) -> _Tuple2[_Self]: ...
142
+ def __pow__(self: _Self, x: _AnyOther, /) -> _Self: ...
143
+ def __radd__(self: _Self, x: _AnyOther, /) -> _Self: ...
144
+ def __rsub__(self: _Self, x: _AnyOther, /) -> _Self: ...
145
+ def __rmul__(self: _Self, x: _AnyOther, /) -> _Self: ...
146
+ def __rtruediv__(self: _Self, x: _AnyOther, /) -> _Self: ...
147
+ def __rfloordiv__(self: _Self, x: _AnyOther, /) -> _Self: ...
148
+ def __rmod__(self: _Self, x: _AnyOther, /) -> _Self: ...
149
+ def __rdivmod__(self: _Self, x: _AnyOther, /) -> _Tuple2[_Self]: ...
150
+ def __len__(self, /) -> int: ...
151
+ def __iter__(self, /) -> Iterator[np.inexact[Any] | object]: ...
152
+ def __getstate__(self, /) -> dict[str, Any]: ...
153
+ def __setstate__(self, dict: dict[str, Any], /) -> None: ...
154
+
155
+ def has_samecoef(self, /, other: ABCPolyBase) -> bool: ...
156
+ def has_samedomain(self, /, other: ABCPolyBase) -> bool: ...
157
+ def has_samewindow(self, /, other: ABCPolyBase) -> bool: ...
158
+ @overload
159
+ def has_sametype(self: _Self, /, other: ABCPolyBase) -> TypeGuard[_Self]: ...
160
+ @overload
161
+ def has_sametype(self, /, other: object) -> Literal[False]: ...
162
+
163
+ def copy(self: _Self, /) -> _Self: ...
164
+ def degree(self, /) -> int: ...
165
+ def cutdeg(self: _Self, /) -> _Self: ...
166
+ def trim(self: _Self, /, tol: _FloatLike_co = ...) -> _Self: ...
167
+ def truncate(self: _Self, /, size: _AnyInt) -> _Self: ...
168
+
169
+ @overload
170
+ def convert(
171
+ self,
172
+ domain: None | _SeriesLikeCoef_co,
173
+ kind: type[_Other],
174
+ /,
175
+ window: None | _SeriesLikeCoef_co = ...,
176
+ ) -> _Other: ...
177
+ @overload
178
+ def convert(
179
+ self,
180
+ /,
181
+ domain: None | _SeriesLikeCoef_co = ...,
182
+ *,
183
+ kind: type[_Other],
184
+ window: None | _SeriesLikeCoef_co = ...,
185
+ ) -> _Other: ...
186
+ @overload
187
+ def convert(
188
+ self: _Self,
189
+ /,
190
+ domain: None | _SeriesLikeCoef_co = ...,
191
+ kind: type[_Self] = ...,
192
+ window: None | _SeriesLikeCoef_co = ...,
193
+ ) -> _Self: ...
194
+
195
+ def mapparms(self, /) -> _Tuple2[Any]: ...
196
+
197
+ def integ(
198
+ self: _Self, /,
199
+ m: SupportsIndex = ...,
200
+ k: _CoefLike_co | _SeriesLikeCoef_co = ...,
201
+ lbnd: None | _CoefLike_co = ...,
202
+ ) -> _Self: ...
203
+
204
+ def deriv(self: _Self, /, m: SupportsIndex = ...) -> _Self: ...
205
+
206
+ def roots(self, /) -> _CoefSeries: ...
207
+
208
+ def linspace(
209
+ self, /,
210
+ n: SupportsIndex = ...,
211
+ domain: None | _SeriesLikeCoef_co = ...,
212
+ ) -> _Tuple2[_Series[np.float64 | np.complex128]]: ...
213
+
214
+ @overload
215
+ @classmethod
216
+ def fit(
217
+ cls: type[_Self], /,
218
+ x: _SeriesLikeCoef_co,
219
+ y: _SeriesLikeCoef_co,
220
+ deg: int | _SeriesLikeInt_co,
221
+ domain: None | _SeriesLikeCoef_co = ...,
222
+ rcond: _FloatLike_co = ...,
223
+ full: Literal[False] = ...,
224
+ w: None | _SeriesLikeCoef_co = ...,
225
+ window: None | _SeriesLikeCoef_co = ...,
226
+ symbol: str = ...,
227
+ ) -> _Self: ...
228
+ @overload
229
+ @classmethod
230
+ def fit(
231
+ cls: type[_Self], /,
232
+ x: _SeriesLikeCoef_co,
233
+ y: _SeriesLikeCoef_co,
234
+ deg: int | _SeriesLikeInt_co,
235
+ domain: None | _SeriesLikeCoef_co = ...,
236
+ rcond: _FloatLike_co = ...,
237
+ *,
238
+ full: Literal[True],
239
+ w: None | _SeriesLikeCoef_co = ...,
240
+ window: None | _SeriesLikeCoef_co = ...,
241
+ symbol: str = ...,
242
+ ) -> tuple[_Self, Sequence[np.inexact[Any] | np.int32]]: ...
243
+ @overload
244
+ @classmethod
245
+ def fit(
246
+ cls: type[_Self],
247
+ x: _SeriesLikeCoef_co,
248
+ y: _SeriesLikeCoef_co,
249
+ deg: int | _SeriesLikeInt_co,
250
+ domain: None | _SeriesLikeCoef_co,
251
+ rcond: _FloatLike_co,
252
+ full: Literal[True], /,
253
+ w: None | _SeriesLikeCoef_co = ...,
254
+ window: None | _SeriesLikeCoef_co = ...,
255
+ symbol: str = ...,
256
+ ) -> tuple[_Self, Sequence[np.inexact[Any] | np.int32]]: ...
257
+
258
+ @classmethod
259
+ def fromroots(
260
+ cls: type[_Self], /,
261
+ roots: _ArrayLikeCoef_co,
262
+ domain: None | _SeriesLikeCoef_co = ...,
263
+ window: None | _SeriesLikeCoef_co = ...,
264
+ symbol: str = ...,
265
+ ) -> _Self: ...
266
+
267
+ @classmethod
268
+ def identity(
269
+ cls: type[_Self], /,
270
+ domain: None | _SeriesLikeCoef_co = ...,
271
+ window: None | _SeriesLikeCoef_co = ...,
272
+ symbol: str = ...,
273
+ ) -> _Self: ...
274
+
275
+ @classmethod
276
+ def basis(
277
+ cls: type[_Self], /,
278
+ deg: _AnyInt,
279
+ domain: None | _SeriesLikeCoef_co = ...,
280
+ window: None | _SeriesLikeCoef_co = ...,
281
+ symbol: str = ...,
282
+ ) -> _Self: ...
283
+
284
+ @classmethod
285
+ def cast(
286
+ cls: type[_Self], /,
287
+ series: ABCPolyBase,
288
+ domain: None | _SeriesLikeCoef_co = ...,
289
+ window: None | _SeriesLikeCoef_co = ...,
290
+ ) -> _Self: ...
291
+
292
+ @classmethod
293
+ def _str_term_unicode(cls, i: str, arg_str: str) -> str: ...
294
+ @staticmethod
295
+ def _str_term_ascii(i: str, arg_str: str) -> str: ...
296
+ @staticmethod
297
+ def _repr_latex_term(i: str, arg_str: str, needs_parens: bool) -> str: ...
parrot/lib/python3.10/site-packages/numpy/polynomial/_polytypes.pyi ADDED
@@ -0,0 +1,912 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ from collections.abc import Callable, Sequence
3
+ from typing import (
4
+ TYPE_CHECKING,
5
+ Any,
6
+ Literal,
7
+ NoReturn,
8
+ Protocol,
9
+ SupportsIndex,
10
+ SupportsInt,
11
+ TypeAlias,
12
+ TypeVar,
13
+ final,
14
+ overload,
15
+ )
16
+
17
+ import numpy as np
18
+ import numpy.typing as npt
19
+ from numpy._typing import (
20
+ # array-likes
21
+ _ArrayLikeFloat_co,
22
+ _ArrayLikeComplex_co,
23
+ _ArrayLikeNumber_co,
24
+ _ArrayLikeObject_co,
25
+ _NestedSequence,
26
+
27
+ # scalar-likes
28
+ _IntLike_co,
29
+ _FloatLike_co,
30
+ _ComplexLike_co,
31
+ _NumberLike_co,
32
+ )
33
+
34
+ if sys.version_info >= (3, 11):
35
+ from typing import LiteralString
36
+ elif TYPE_CHECKING:
37
+ from typing_extensions import LiteralString
38
+ else:
39
+ LiteralString: TypeAlias = str
40
+
41
+ _T = TypeVar("_T")
42
+ _T_contra = TypeVar("_T_contra", contravariant=True)
43
+
44
+ _Tuple2: TypeAlias = tuple[_T, _T]
45
+
46
+ _V = TypeVar("_V")
47
+ _V_co = TypeVar("_V_co", covariant=True)
48
+ _Self = TypeVar("_Self", bound=object)
49
+
50
+ _SCT = TypeVar("_SCT", bound=np.number[Any] | np.bool | np.object_)
51
+ _SCT_co = TypeVar(
52
+ "_SCT_co",
53
+ bound=np.number[Any] | np.bool | np.object_,
54
+ covariant=True,
55
+ )
56
+
57
+ @final
58
+ class _SupportsArray(Protocol[_SCT_co]):
59
+ def __array__(self ,) -> npt.NDArray[_SCT_co]: ...
60
+
61
+ @final
62
+ class _SupportsCoefOps(Protocol[_T_contra]):
63
+ # compatible with e.g. `int`, `float`, `complex`, `Decimal`, `Fraction`,
64
+ # and `ABCPolyBase`
65
+ def __eq__(self, x: object, /) -> bool: ...
66
+ def __ne__(self, x: object, /) -> bool: ...
67
+
68
+ def __neg__(self: _Self, /) -> _Self: ...
69
+ def __pos__(self: _Self, /) -> _Self: ...
70
+
71
+ def __add__(self: _Self, x: _T_contra, /) -> _Self: ...
72
+ def __sub__(self: _Self, x: _T_contra, /) -> _Self: ...
73
+ def __mul__(self: _Self, x: _T_contra, /) -> _Self: ...
74
+ def __truediv__(self: _Self, x: _T_contra, /) -> _Self | float: ...
75
+ def __pow__(self: _Self, x: _T_contra, /) -> _Self | float: ...
76
+
77
+ def __radd__(self: _Self, x: _T_contra, /) -> _Self: ...
78
+ def __rsub__(self: _Self, x: _T_contra, /) -> _Self: ...
79
+ def __rmul__(self: _Self, x: _T_contra, /) -> _Self: ...
80
+ def __rtruediv__(self: _Self, x: _T_contra, /) -> _Self | float: ...
81
+
82
+ _Series: TypeAlias = np.ndarray[tuple[int], np.dtype[_SCT]]
83
+
84
+ _FloatSeries: TypeAlias = _Series[np.floating[Any]]
85
+ _ComplexSeries: TypeAlias = _Series[np.complexfloating[Any, Any]]
86
+ _NumberSeries: TypeAlias = _Series[np.number[Any]]
87
+ _ObjectSeries: TypeAlias = _Series[np.object_]
88
+ _CoefSeries: TypeAlias = _Series[np.inexact[Any] | np.object_]
89
+
90
+ _FloatArray: TypeAlias = npt.NDArray[np.floating[Any]]
91
+ _ComplexArray: TypeAlias = npt.NDArray[np.complexfloating[Any, Any]]
92
+ _ObjectArray: TypeAlias = npt.NDArray[np.object_]
93
+ _CoefArray: TypeAlias = npt.NDArray[np.inexact[Any] | np.object_]
94
+
95
+ _Array1: TypeAlias = np.ndarray[tuple[Literal[1]], np.dtype[_SCT]]
96
+ _Array2: TypeAlias = np.ndarray[tuple[Literal[2]], np.dtype[_SCT]]
97
+
98
+ _AnyInt: TypeAlias = SupportsInt | SupportsIndex
99
+
100
+ _CoefObjectLike_co: TypeAlias = np.object_ | _SupportsCoefOps
101
+ _CoefLike_co: TypeAlias = _NumberLike_co | _CoefObjectLike_co
102
+
103
+ # The term "series" is used here to refer to 1-d arrays of numeric scalars.
104
+ _SeriesLikeBool_co: TypeAlias = (
105
+ _SupportsArray[np.bool]
106
+ | Sequence[bool | np.bool]
107
+ )
108
+ _SeriesLikeInt_co: TypeAlias = (
109
+ _SupportsArray[np.integer[Any] | np.bool]
110
+ | Sequence[_IntLike_co]
111
+ )
112
+ _SeriesLikeFloat_co: TypeAlias = (
113
+ _SupportsArray[np.floating[Any] | np.integer[Any] | np.bool]
114
+ | Sequence[_FloatLike_co]
115
+ )
116
+ _SeriesLikeComplex_co: TypeAlias = (
117
+ _SupportsArray[np.integer[Any] | np.inexact[Any] | np.bool]
118
+ | Sequence[_ComplexLike_co]
119
+ )
120
+ _SeriesLikeObject_co: TypeAlias = (
121
+ _SupportsArray[np.object_]
122
+ | Sequence[_CoefObjectLike_co]
123
+ )
124
+ _SeriesLikeCoef_co: TypeAlias = (
125
+ # npt.NDArray[np.number[Any] | np.bool | np.object_]
126
+ _SupportsArray[np.number[Any] | np.bool | np.object_]
127
+ | Sequence[_CoefLike_co]
128
+ )
129
+
130
+ _ArrayLikeCoefObject_co: TypeAlias = (
131
+ _CoefObjectLike_co
132
+ | _SeriesLikeObject_co
133
+ | _NestedSequence[_SeriesLikeObject_co]
134
+ )
135
+ _ArrayLikeCoef_co: TypeAlias = (
136
+ npt.NDArray[np.number[Any] | np.bool | np.object_]
137
+ | _ArrayLikeNumber_co
138
+ | _ArrayLikeCoefObject_co
139
+ )
140
+
141
+ _Name_co = TypeVar("_Name_co", bound=LiteralString, covariant=True)
142
+
143
+ class _Named(Protocol[_Name_co]):
144
+ @property
145
+ def __name__(self, /) -> _Name_co: ...
146
+
147
+ _Line: TypeAlias = np.ndarray[tuple[Literal[1, 2]], np.dtype[_SCT]]
148
+
149
+ @final
150
+ class _FuncLine(_Named[_Name_co], Protocol[_Name_co]):
151
+ @overload
152
+ def __call__(self, /, off: _SCT, scl: _SCT) -> _Line[_SCT]: ...
153
+ @overload
154
+ def __call__(self, /, off: int, scl: int) -> _Line[np.int_] : ...
155
+ @overload
156
+ def __call__(self, /, off: float, scl: float) -> _Line[np.float64]: ...
157
+ @overload
158
+ def __call__(
159
+ self,
160
+ /,
161
+ off: complex,
162
+ scl: complex,
163
+ ) -> _Line[np.complex128]: ...
164
+ @overload
165
+ def __call__(
166
+ self,
167
+ /,
168
+ off: _SupportsCoefOps,
169
+ scl: _SupportsCoefOps,
170
+ ) -> _Line[np.object_]: ...
171
+
172
+ @final
173
+ class _FuncFromRoots(_Named[_Name_co], Protocol[_Name_co]):
174
+ @overload
175
+ def __call__(self, /, roots: _SeriesLikeFloat_co) -> _FloatSeries: ...
176
+ @overload
177
+ def __call__(self, /, roots: _SeriesLikeComplex_co) -> _ComplexSeries: ...
178
+ @overload
179
+ def __call__(self, /, roots: _SeriesLikeCoef_co) -> _ObjectSeries: ...
180
+
181
+ @final
182
+ class _FuncBinOp(_Named[_Name_co], Protocol[_Name_co]):
183
+ @overload
184
+ def __call__(
185
+ self,
186
+ /,
187
+ c1: _SeriesLikeBool_co,
188
+ c2: _SeriesLikeBool_co,
189
+ ) -> NoReturn: ...
190
+ @overload
191
+ def __call__(
192
+ self,
193
+ /,
194
+ c1: _SeriesLikeFloat_co,
195
+ c2: _SeriesLikeFloat_co,
196
+ ) -> _FloatSeries: ...
197
+ @overload
198
+ def __call__(
199
+ self,
200
+ /,
201
+ c1: _SeriesLikeComplex_co,
202
+ c2: _SeriesLikeComplex_co,
203
+ ) -> _ComplexSeries: ...
204
+ @overload
205
+ def __call__(
206
+ self,
207
+ /,
208
+ c1: _SeriesLikeCoef_co,
209
+ c2: _SeriesLikeCoef_co,
210
+ ) -> _ObjectSeries: ...
211
+
212
+ @final
213
+ class _FuncUnOp(_Named[_Name_co], Protocol[_Name_co]):
214
+ @overload
215
+ def __call__(self, /, c: _SeriesLikeFloat_co) -> _FloatSeries: ...
216
+ @overload
217
+ def __call__(self, /, c: _SeriesLikeComplex_co) -> _ComplexSeries: ...
218
+ @overload
219
+ def __call__(self, /, c: _SeriesLikeCoef_co) -> _ObjectSeries: ...
220
+
221
+ @final
222
+ class _FuncPoly2Ortho(_Named[_Name_co], Protocol[_Name_co]):
223
+ @overload
224
+ def __call__(self, /, pol: _SeriesLikeFloat_co) -> _FloatSeries: ...
225
+ @overload
226
+ def __call__(self, /, pol: _SeriesLikeComplex_co) -> _ComplexSeries: ...
227
+ @overload
228
+ def __call__(self, /, pol: _SeriesLikeCoef_co) -> _ObjectSeries: ...
229
+
230
+ @final
231
+ class _FuncPow(_Named[_Name_co], Protocol[_Name_co]):
232
+ @overload
233
+ def __call__(
234
+ self,
235
+ /,
236
+ c: _SeriesLikeFloat_co,
237
+ pow: _IntLike_co,
238
+ maxpower: None | _IntLike_co = ...,
239
+ ) -> _FloatSeries: ...
240
+ @overload
241
+ def __call__(
242
+ self,
243
+ /,
244
+ c: _SeriesLikeComplex_co,
245
+ pow: _IntLike_co,
246
+ maxpower: None | _IntLike_co = ...,
247
+ ) -> _ComplexSeries: ...
248
+ @overload
249
+ def __call__(
250
+ self,
251
+ /,
252
+ c: _SeriesLikeCoef_co,
253
+ pow: _IntLike_co,
254
+ maxpower: None | _IntLike_co = ...,
255
+ ) -> _ObjectSeries: ...
256
+
257
+ @final
258
+ class _FuncDer(_Named[_Name_co], Protocol[_Name_co]):
259
+ @overload
260
+ def __call__(
261
+ self,
262
+ /,
263
+ c: _ArrayLikeFloat_co,
264
+ m: SupportsIndex = ...,
265
+ scl: _FloatLike_co = ...,
266
+ axis: SupportsIndex = ...,
267
+ ) -> _FloatArray: ...
268
+ @overload
269
+ def __call__(
270
+ self,
271
+ /,
272
+ c: _ArrayLikeComplex_co,
273
+ m: SupportsIndex = ...,
274
+ scl: _ComplexLike_co = ...,
275
+ axis: SupportsIndex = ...,
276
+ ) -> _ComplexArray: ...
277
+ @overload
278
+ def __call__(
279
+ self,
280
+ /,
281
+ c: _ArrayLikeCoef_co,
282
+ m: SupportsIndex = ...,
283
+ scl: _CoefLike_co = ...,
284
+ axis: SupportsIndex = ...,
285
+ ) -> _ObjectArray: ...
286
+
287
+ @final
288
+ class _FuncInteg(_Named[_Name_co], Protocol[_Name_co]):
289
+ @overload
290
+ def __call__(
291
+ self,
292
+ /,
293
+ c: _ArrayLikeFloat_co,
294
+ m: SupportsIndex = ...,
295
+ k: _FloatLike_co | _SeriesLikeFloat_co = ...,
296
+ lbnd: _FloatLike_co = ...,
297
+ scl: _FloatLike_co = ...,
298
+ axis: SupportsIndex = ...,
299
+ ) -> _FloatArray: ...
300
+ @overload
301
+ def __call__(
302
+ self,
303
+ /,
304
+ c: _ArrayLikeComplex_co,
305
+ m: SupportsIndex = ...,
306
+ k: _ComplexLike_co | _SeriesLikeComplex_co = ...,
307
+ lbnd: _ComplexLike_co = ...,
308
+ scl: _ComplexLike_co = ...,
309
+ axis: SupportsIndex = ...,
310
+ ) -> _ComplexArray: ...
311
+ @overload
312
+ def __call__(
313
+ self,
314
+ /,
315
+ c: _ArrayLikeCoef_co,
316
+ m: SupportsIndex = ...,
317
+ k: _SeriesLikeCoef_co | _SeriesLikeCoef_co = ...,
318
+ lbnd: _CoefLike_co = ...,
319
+ scl: _CoefLike_co = ...,
320
+ axis: SupportsIndex = ...,
321
+ ) -> _ObjectArray: ...
322
+
323
+ @final
324
+ class _FuncValFromRoots(_Named[_Name_co], Protocol[_Name_co]):
325
+ @overload
326
+ def __call__(
327
+ self,
328
+ /,
329
+ x: _FloatLike_co,
330
+ r: _FloatLike_co,
331
+ tensor: bool = ...,
332
+ ) -> np.floating[Any]: ...
333
+ @overload
334
+ def __call__(
335
+ self,
336
+ /,
337
+ x: _NumberLike_co,
338
+ r: _NumberLike_co,
339
+ tensor: bool = ...,
340
+ ) -> np.complexfloating[Any, Any]: ...
341
+ @overload
342
+ def __call__(
343
+ self,
344
+ /,
345
+ x: _FloatLike_co | _ArrayLikeFloat_co,
346
+ r: _ArrayLikeFloat_co,
347
+ tensor: bool = ...,
348
+ ) -> _FloatArray: ...
349
+ @overload
350
+ def __call__(
351
+ self,
352
+ /,
353
+ x: _NumberLike_co | _ArrayLikeComplex_co,
354
+ r: _ArrayLikeComplex_co,
355
+ tensor: bool = ...,
356
+ ) -> _ComplexArray: ...
357
+ @overload
358
+ def __call__(
359
+ self,
360
+ /,
361
+ x: _CoefLike_co | _ArrayLikeCoef_co,
362
+ r: _ArrayLikeCoef_co,
363
+ tensor: bool = ...,
364
+ ) -> _ObjectArray: ...
365
+ @overload
366
+ def __call__(
367
+ self,
368
+ /,
369
+ x: _CoefLike_co,
370
+ r: _CoefLike_co,
371
+ tensor: bool = ...,
372
+ ) -> _SupportsCoefOps: ...
373
+
374
+ @final
375
+ class _FuncVal(_Named[_Name_co], Protocol[_Name_co]):
376
+ @overload
377
+ def __call__(
378
+ self,
379
+ /,
380
+ x: _FloatLike_co,
381
+ c: _SeriesLikeFloat_co,
382
+ tensor: bool = ...,
383
+ ) -> np.floating[Any]: ...
384
+ @overload
385
+ def __call__(
386
+ self,
387
+ /,
388
+ x: _NumberLike_co,
389
+ c: _SeriesLikeComplex_co,
390
+ tensor: bool = ...,
391
+ ) -> np.complexfloating[Any, Any]: ...
392
+ @overload
393
+ def __call__(
394
+ self,
395
+ /,
396
+ x: _ArrayLikeFloat_co,
397
+ c: _ArrayLikeFloat_co,
398
+ tensor: bool = ...,
399
+ ) -> _FloatArray: ...
400
+ @overload
401
+ def __call__(
402
+ self,
403
+ /,
404
+ x: _ArrayLikeComplex_co,
405
+ c: _ArrayLikeComplex_co,
406
+ tensor: bool = ...,
407
+ ) -> _ComplexArray: ...
408
+ @overload
409
+ def __call__(
410
+ self,
411
+ /,
412
+ x: _ArrayLikeCoef_co,
413
+ c: _ArrayLikeCoef_co,
414
+ tensor: bool = ...,
415
+ ) -> _ObjectArray: ...
416
+ @overload
417
+ def __call__(
418
+ self,
419
+ /,
420
+ x: _CoefLike_co,
421
+ c: _SeriesLikeObject_co,
422
+ tensor: bool = ...,
423
+ ) -> _SupportsCoefOps: ...
424
+
425
+ @final
426
+ class _FuncVal2D(_Named[_Name_co], Protocol[_Name_co]):
427
+ @overload
428
+ def __call__(
429
+ self,
430
+ /,
431
+ x: _FloatLike_co,
432
+ y: _FloatLike_co,
433
+ c: _SeriesLikeFloat_co,
434
+ ) -> np.floating[Any]: ...
435
+ @overload
436
+ def __call__(
437
+ self,
438
+ /,
439
+ x: _NumberLike_co,
440
+ y: _NumberLike_co,
441
+ c: _SeriesLikeComplex_co,
442
+ ) -> np.complexfloating[Any, Any]: ...
443
+ @overload
444
+ def __call__(
445
+ self,
446
+ /,
447
+ x: _ArrayLikeFloat_co,
448
+ y: _ArrayLikeFloat_co,
449
+ c: _ArrayLikeFloat_co,
450
+ ) -> _FloatArray: ...
451
+ @overload
452
+ def __call__(
453
+ self,
454
+ /,
455
+ x: _ArrayLikeComplex_co,
456
+ y: _ArrayLikeComplex_co,
457
+ c: _ArrayLikeComplex_co,
458
+ ) -> _ComplexArray: ...
459
+ @overload
460
+ def __call__(
461
+ self,
462
+ /,
463
+ x: _ArrayLikeCoef_co,
464
+ y: _ArrayLikeCoef_co,
465
+ c: _ArrayLikeCoef_co,
466
+ ) -> _ObjectArray: ...
467
+ @overload
468
+ def __call__(
469
+ self,
470
+ /,
471
+ x: _CoefLike_co,
472
+ y: _CoefLike_co,
473
+ c: _SeriesLikeCoef_co,
474
+ ) -> _SupportsCoefOps: ...
475
+
476
+ @final
477
+ class _FuncVal3D(_Named[_Name_co], Protocol[_Name_co]):
478
+ @overload
479
+ def __call__(
480
+ self,
481
+ /,
482
+ x: _FloatLike_co,
483
+ y: _FloatLike_co,
484
+ z: _FloatLike_co,
485
+ c: _SeriesLikeFloat_co
486
+ ) -> np.floating[Any]: ...
487
+ @overload
488
+ def __call__(
489
+ self,
490
+ /,
491
+ x: _NumberLike_co,
492
+ y: _NumberLike_co,
493
+ z: _NumberLike_co,
494
+ c: _SeriesLikeComplex_co,
495
+ ) -> np.complexfloating[Any, Any]: ...
496
+ @overload
497
+ def __call__(
498
+ self,
499
+ /,
500
+ x: _ArrayLikeFloat_co,
501
+ y: _ArrayLikeFloat_co,
502
+ z: _ArrayLikeFloat_co,
503
+ c: _ArrayLikeFloat_co,
504
+ ) -> _FloatArray: ...
505
+ @overload
506
+ def __call__(
507
+ self,
508
+ /,
509
+ x: _ArrayLikeComplex_co,
510
+ y: _ArrayLikeComplex_co,
511
+ z: _ArrayLikeComplex_co,
512
+ c: _ArrayLikeComplex_co,
513
+ ) -> _ComplexArray: ...
514
+ @overload
515
+ def __call__(
516
+ self,
517
+ /,
518
+ x: _ArrayLikeCoef_co,
519
+ y: _ArrayLikeCoef_co,
520
+ z: _ArrayLikeCoef_co,
521
+ c: _ArrayLikeCoef_co,
522
+ ) -> _ObjectArray: ...
523
+ @overload
524
+ def __call__(
525
+ self,
526
+ /,
527
+ x: _CoefLike_co,
528
+ y: _CoefLike_co,
529
+ z: _CoefLike_co,
530
+ c: _SeriesLikeCoef_co,
531
+ ) -> _SupportsCoefOps: ...
532
+
533
+ _AnyValF: TypeAlias = Callable[
534
+ [npt.ArrayLike, npt.ArrayLike, bool],
535
+ _CoefArray,
536
+ ]
537
+
538
+ @final
539
+ class _FuncValND(_Named[_Name_co], Protocol[_Name_co]):
540
+ @overload
541
+ def __call__(
542
+ self,
543
+ val_f: _AnyValF,
544
+ c: _SeriesLikeFloat_co,
545
+ /,
546
+ *args: _FloatLike_co,
547
+ ) -> np.floating[Any]: ...
548
+ @overload
549
+ def __call__(
550
+ self,
551
+ val_f: _AnyValF,
552
+ c: _SeriesLikeComplex_co,
553
+ /,
554
+ *args: _NumberLike_co,
555
+ ) -> np.complexfloating[Any, Any]: ...
556
+ @overload
557
+ def __call__(
558
+ self,
559
+ val_f: _AnyValF,
560
+ c: _ArrayLikeFloat_co,
561
+ /,
562
+ *args: _ArrayLikeFloat_co,
563
+ ) -> _FloatArray: ...
564
+ @overload
565
+ def __call__(
566
+ self,
567
+ val_f: _AnyValF,
568
+ c: _ArrayLikeComplex_co,
569
+ /,
570
+ *args: _ArrayLikeComplex_co,
571
+ ) -> _ComplexArray: ...
572
+ @overload
573
+ def __call__(
574
+ self,
575
+ val_f: _AnyValF,
576
+ c: _ArrayLikeCoef_co,
577
+ /,
578
+ *args: _ArrayLikeCoef_co,
579
+ ) -> _ObjectArray: ...
580
+ @overload
581
+ def __call__(
582
+ self,
583
+ val_f: _AnyValF,
584
+ c: _SeriesLikeObject_co,
585
+ /,
586
+ *args: _CoefObjectLike_co,
587
+ ) -> _SupportsCoefOps: ...
588
+
589
+ @final
590
+ class _FuncVander(_Named[_Name_co], Protocol[_Name_co]):
591
+ @overload
592
+ def __call__(
593
+ self,
594
+ /,
595
+ x: _ArrayLikeFloat_co,
596
+ deg: SupportsIndex,
597
+ ) -> _FloatArray: ...
598
+ @overload
599
+ def __call__(
600
+ self,
601
+ /,
602
+ x: _ArrayLikeComplex_co,
603
+ deg: SupportsIndex,
604
+ ) -> _ComplexArray: ...
605
+ @overload
606
+ def __call__(
607
+ self,
608
+ /,
609
+ x: _ArrayLikeCoef_co,
610
+ deg: SupportsIndex,
611
+ ) -> _ObjectArray: ...
612
+ @overload
613
+ def __call__(
614
+ self,
615
+ /,
616
+ x: npt.ArrayLike,
617
+ deg: SupportsIndex,
618
+ ) -> _CoefArray: ...
619
+
620
+ _AnyDegrees: TypeAlias = Sequence[SupportsIndex]
621
+
622
+ @final
623
+ class _FuncVander2D(_Named[_Name_co], Protocol[_Name_co]):
624
+ @overload
625
+ def __call__(
626
+ self,
627
+ /,
628
+ x: _ArrayLikeFloat_co,
629
+ y: _ArrayLikeFloat_co,
630
+ deg: _AnyDegrees,
631
+ ) -> _FloatArray: ...
632
+ @overload
633
+ def __call__(
634
+ self,
635
+ /,
636
+ x: _ArrayLikeComplex_co,
637
+ y: _ArrayLikeComplex_co,
638
+ deg: _AnyDegrees,
639
+ ) -> _ComplexArray: ...
640
+ @overload
641
+ def __call__(
642
+ self,
643
+ /,
644
+ x: _ArrayLikeCoef_co,
645
+ y: _ArrayLikeCoef_co,
646
+ deg: _AnyDegrees,
647
+ ) -> _ObjectArray: ...
648
+ @overload
649
+ def __call__(
650
+ self,
651
+ /,
652
+ x: npt.ArrayLike,
653
+ y: npt.ArrayLike,
654
+ deg: _AnyDegrees,
655
+ ) -> _CoefArray: ...
656
+
657
+ @final
658
+ class _FuncVander3D(_Named[_Name_co], Protocol[_Name_co]):
659
+ @overload
660
+ def __call__(
661
+ self,
662
+ /,
663
+ x: _ArrayLikeFloat_co,
664
+ y: _ArrayLikeFloat_co,
665
+ z: _ArrayLikeFloat_co,
666
+ deg: _AnyDegrees,
667
+ ) -> _FloatArray: ...
668
+ @overload
669
+ def __call__(
670
+ self,
671
+ /,
672
+ x: _ArrayLikeComplex_co,
673
+ y: _ArrayLikeComplex_co,
674
+ z: _ArrayLikeComplex_co,
675
+ deg: _AnyDegrees,
676
+ ) -> _ComplexArray: ...
677
+ @overload
678
+ def __call__(
679
+ self,
680
+ /,
681
+ x: _ArrayLikeCoef_co,
682
+ y: _ArrayLikeCoef_co,
683
+ z: _ArrayLikeCoef_co,
684
+ deg: _AnyDegrees,
685
+ ) -> _ObjectArray: ...
686
+ @overload
687
+ def __call__(
688
+ self,
689
+ /,
690
+ x: npt.ArrayLike,
691
+ y: npt.ArrayLike,
692
+ z: npt.ArrayLike,
693
+ deg: _AnyDegrees,
694
+ ) -> _CoefArray: ...
695
+
696
+ # keep in sync with the broadest overload of `._FuncVander`
697
+ _AnyFuncVander: TypeAlias = Callable[
698
+ [npt.ArrayLike, SupportsIndex],
699
+ _CoefArray,
700
+ ]
701
+
702
+ @final
703
+ class _FuncVanderND(_Named[_Name_co], Protocol[_Name_co]):
704
+ @overload
705
+ def __call__(
706
+ self,
707
+ /,
708
+ vander_fs: Sequence[_AnyFuncVander],
709
+ points: Sequence[_ArrayLikeFloat_co],
710
+ degrees: Sequence[SupportsIndex],
711
+ ) -> _FloatArray: ...
712
+ @overload
713
+ def __call__(
714
+ self,
715
+ /,
716
+ vander_fs: Sequence[_AnyFuncVander],
717
+ points: Sequence[_ArrayLikeComplex_co],
718
+ degrees: Sequence[SupportsIndex],
719
+ ) -> _ComplexArray: ...
720
+ @overload
721
+ def __call__(
722
+ self,
723
+ /,
724
+ vander_fs: Sequence[_AnyFuncVander],
725
+ points: Sequence[
726
+ _ArrayLikeObject_co | _ArrayLikeComplex_co,
727
+ ],
728
+ degrees: Sequence[SupportsIndex],
729
+ ) -> _ObjectArray: ...
730
+ @overload
731
+ def __call__(
732
+ self,
733
+ /,
734
+ vander_fs: Sequence[_AnyFuncVander],
735
+ points: Sequence[npt.ArrayLike],
736
+ degrees: Sequence[SupportsIndex],
737
+ ) -> _CoefArray: ...
738
+
739
+ _FullFitResult: TypeAlias = Sequence[np.inexact[Any] | np.int32]
740
+
741
+ @final
742
+ class _FuncFit(_Named[_Name_co], Protocol[_Name_co]):
743
+ @overload
744
+ def __call__(
745
+ self,
746
+ /,
747
+ x: _SeriesLikeFloat_co,
748
+ y: _ArrayLikeFloat_co,
749
+ deg: int | _SeriesLikeInt_co,
750
+ rcond: None | float = ...,
751
+ full: Literal[False] = ...,
752
+ w: None | _SeriesLikeFloat_co = ...,
753
+ ) -> _FloatArray: ...
754
+ @overload
755
+ def __call__(
756
+ self,
757
+ x: _SeriesLikeFloat_co,
758
+ y: _ArrayLikeFloat_co,
759
+ deg: int | _SeriesLikeInt_co,
760
+ rcond: None | float,
761
+ full: Literal[True],
762
+ /,
763
+ w: None | _SeriesLikeFloat_co = ...,
764
+ ) -> tuple[_FloatArray, _FullFitResult]: ...
765
+ @overload
766
+ def __call__(
767
+ self,
768
+ /,
769
+ x: _SeriesLikeFloat_co,
770
+ y: _ArrayLikeFloat_co,
771
+ deg: int | _SeriesLikeInt_co,
772
+ rcond: None | float = ...,
773
+ *,
774
+ full: Literal[True],
775
+ w: None | _SeriesLikeFloat_co = ...,
776
+ ) -> tuple[_FloatArray, _FullFitResult]: ...
777
+
778
+ @overload
779
+ def __call__(
780
+ self,
781
+ /,
782
+ x: _SeriesLikeComplex_co,
783
+ y: _ArrayLikeComplex_co,
784
+ deg: int | _SeriesLikeInt_co,
785
+ rcond: None | float = ...,
786
+ full: Literal[False] = ...,
787
+ w: None | _SeriesLikeFloat_co = ...,
788
+ ) -> _ComplexArray: ...
789
+ @overload
790
+ def __call__(
791
+ self,
792
+ x: _SeriesLikeComplex_co,
793
+ y: _ArrayLikeComplex_co,
794
+ deg: int | _SeriesLikeInt_co,
795
+ rcond: None | float,
796
+ full: Literal[True],
797
+ /,
798
+ w: None | _SeriesLikeFloat_co = ...,
799
+ ) -> tuple[_ComplexArray, _FullFitResult]: ...
800
+ @overload
801
+ def __call__(
802
+ self,
803
+ /,
804
+ x: _SeriesLikeComplex_co,
805
+ y: _ArrayLikeComplex_co,
806
+ deg: int | _SeriesLikeInt_co,
807
+ rcond: None | float = ...,
808
+ *,
809
+ full: Literal[True],
810
+ w: None | _SeriesLikeFloat_co = ...,
811
+ ) -> tuple[_ComplexArray, _FullFitResult]: ...
812
+
813
+ @overload
814
+ def __call__(
815
+ self,
816
+ /,
817
+ x: _SeriesLikeComplex_co,
818
+ y: _ArrayLikeCoef_co,
819
+ deg: int | _SeriesLikeInt_co,
820
+ rcond: None | float = ...,
821
+ full: Literal[False] = ...,
822
+ w: None | _SeriesLikeFloat_co = ...,
823
+ ) -> _ObjectArray: ...
824
+ @overload
825
+ def __call__(
826
+ self,
827
+ x: _SeriesLikeComplex_co,
828
+ y: _ArrayLikeCoef_co,
829
+ deg: int | _SeriesLikeInt_co,
830
+ rcond: None | float,
831
+ full: Literal[True],
832
+ /,
833
+ w: None | _SeriesLikeFloat_co = ...,
834
+ ) -> tuple[_ObjectArray, _FullFitResult]: ...
835
+ @overload
836
+ def __call__(
837
+ self,
838
+ /,
839
+ x: _SeriesLikeComplex_co,
840
+ y: _ArrayLikeCoef_co,
841
+ deg: int | _SeriesLikeInt_co,
842
+ rcond: None | float = ...,
843
+ *,
844
+ full: Literal[True],
845
+ w: None | _SeriesLikeFloat_co = ...,
846
+ ) -> tuple[_ObjectArray, _FullFitResult]: ...
847
+
848
+ @final
849
+ class _FuncRoots(_Named[_Name_co], Protocol[_Name_co]):
850
+ @overload
851
+ def __call__(
852
+ self,
853
+ /,
854
+ c: _SeriesLikeFloat_co,
855
+ ) -> _Series[np.float64]: ...
856
+ @overload
857
+ def __call__(
858
+ self,
859
+ /,
860
+ c: _SeriesLikeComplex_co,
861
+ ) -> _Series[np.complex128]: ...
862
+ @overload
863
+ def __call__(self, /, c: _SeriesLikeCoef_co) -> _ObjectSeries: ...
864
+
865
+
866
+ _Companion: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_SCT]]
867
+
868
+ @final
869
+ class _FuncCompanion(_Named[_Name_co], Protocol[_Name_co]):
870
+ @overload
871
+ def __call__(
872
+ self,
873
+ /,
874
+ c: _SeriesLikeFloat_co,
875
+ ) -> _Companion[np.float64]: ...
876
+ @overload
877
+ def __call__(
878
+ self,
879
+ /,
880
+ c: _SeriesLikeComplex_co,
881
+ ) -> _Companion[np.complex128]: ...
882
+ @overload
883
+ def __call__(self, /, c: _SeriesLikeCoef_co) -> _Companion[np.object_]: ...
884
+
885
+ @final
886
+ class _FuncGauss(_Named[_Name_co], Protocol[_Name_co]):
887
+ def __call__(
888
+ self,
889
+ /,
890
+ deg: SupportsIndex,
891
+ ) -> _Tuple2[_Series[np.float64]]: ...
892
+
893
+ @final
894
+ class _FuncWeight(_Named[_Name_co], Protocol[_Name_co]):
895
+ @overload
896
+ def __call__(
897
+ self,
898
+ /,
899
+ c: _ArrayLikeFloat_co,
900
+ ) -> npt.NDArray[np.float64]: ...
901
+ @overload
902
+ def __call__(
903
+ self,
904
+ /,
905
+ c: _ArrayLikeComplex_co,
906
+ ) -> npt.NDArray[np.complex128]: ...
907
+ @overload
908
+ def __call__(self, /, c: _ArrayLikeCoef_co) -> _ObjectArray: ...
909
+
910
+ @final
911
+ class _FuncPts(_Named[_Name_co], Protocol[_Name_co]):
912
+ def __call__(self, /, npts: _AnyInt) -> _Series[np.float64]: ...
parrot/lib/python3.10/site-packages/numpy/polynomial/chebyshev.py ADDED
@@ -0,0 +1,2086 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ====================================================
3
+ Chebyshev Series (:mod:`numpy.polynomial.chebyshev`)
4
+ ====================================================
5
+
6
+ This module provides a number of objects (mostly functions) useful for
7
+ dealing with Chebyshev series, including a `Chebyshev` class that
8
+ encapsulates the usual arithmetic operations. (General information
9
+ on how this module represents and works with such polynomials is in the
10
+ docstring for its "parent" sub-package, `numpy.polynomial`).
11
+
12
+ Classes
13
+ -------
14
+
15
+ .. autosummary::
16
+ :toctree: generated/
17
+
18
+ Chebyshev
19
+
20
+
21
+ Constants
22
+ ---------
23
+
24
+ .. autosummary::
25
+ :toctree: generated/
26
+
27
+ chebdomain
28
+ chebzero
29
+ chebone
30
+ chebx
31
+
32
+ Arithmetic
33
+ ----------
34
+
35
+ .. autosummary::
36
+ :toctree: generated/
37
+
38
+ chebadd
39
+ chebsub
40
+ chebmulx
41
+ chebmul
42
+ chebdiv
43
+ chebpow
44
+ chebval
45
+ chebval2d
46
+ chebval3d
47
+ chebgrid2d
48
+ chebgrid3d
49
+
50
+ Calculus
51
+ --------
52
+
53
+ .. autosummary::
54
+ :toctree: generated/
55
+
56
+ chebder
57
+ chebint
58
+
59
+ Misc Functions
60
+ --------------
61
+
62
+ .. autosummary::
63
+ :toctree: generated/
64
+
65
+ chebfromroots
66
+ chebroots
67
+ chebvander
68
+ chebvander2d
69
+ chebvander3d
70
+ chebgauss
71
+ chebweight
72
+ chebcompanion
73
+ chebfit
74
+ chebpts1
75
+ chebpts2
76
+ chebtrim
77
+ chebline
78
+ cheb2poly
79
+ poly2cheb
80
+ chebinterpolate
81
+
82
+ See also
83
+ --------
84
+ `numpy.polynomial`
85
+
86
+ Notes
87
+ -----
88
+ The implementations of multiplication, division, integration, and
89
+ differentiation use the algebraic identities [1]_:
90
+
91
+ .. math::
92
+ T_n(x) = \\frac{z^n + z^{-n}}{2} \\\\
93
+ z\\frac{dx}{dz} = \\frac{z - z^{-1}}{2}.
94
+
95
+ where
96
+
97
+ .. math:: x = \\frac{z + z^{-1}}{2}.
98
+
99
+ These identities allow a Chebyshev series to be expressed as a finite,
100
+ symmetric Laurent series. In this module, this sort of Laurent series
101
+ is referred to as a "z-series."
102
+
103
+ References
104
+ ----------
105
+ .. [1] A. T. Benjamin, et al., "Combinatorial Trigonometry with Chebyshev
106
+ Polynomials," *Journal of Statistical Planning and Inference 14*, 2008
107
+ (https://web.archive.org/web/20080221202153/https://www.math.hmc.edu/~benjamin/papers/CombTrig.pdf, pg. 4)
108
+
109
+ """
110
+ import numpy as np
111
+ import numpy.linalg as la
112
+ from numpy.lib.array_utils import normalize_axis_index
113
+
114
+ from . import polyutils as pu
115
+ from ._polybase import ABCPolyBase
116
+
117
+ __all__ = [
118
+ 'chebzero', 'chebone', 'chebx', 'chebdomain', 'chebline', 'chebadd',
119
+ 'chebsub', 'chebmulx', 'chebmul', 'chebdiv', 'chebpow', 'chebval',
120
+ 'chebder', 'chebint', 'cheb2poly', 'poly2cheb', 'chebfromroots',
121
+ 'chebvander', 'chebfit', 'chebtrim', 'chebroots', 'chebpts1',
122
+ 'chebpts2', 'Chebyshev', 'chebval2d', 'chebval3d', 'chebgrid2d',
123
+ 'chebgrid3d', 'chebvander2d', 'chebvander3d', 'chebcompanion',
124
+ 'chebgauss', 'chebweight', 'chebinterpolate']
125
+
126
+ chebtrim = pu.trimcoef
127
+
128
+ #
129
+ # A collection of functions for manipulating z-series. These are private
130
+ # functions and do minimal error checking.
131
+ #
132
+
133
+ def _cseries_to_zseries(c):
134
+ """Convert Chebyshev series to z-series.
135
+
136
+ Convert a Chebyshev series to the equivalent z-series. The result is
137
+ never an empty array. The dtype of the return is the same as that of
138
+ the input. No checks are run on the arguments as this routine is for
139
+ internal use.
140
+
141
+ Parameters
142
+ ----------
143
+ c : 1-D ndarray
144
+ Chebyshev coefficients, ordered from low to high
145
+
146
+ Returns
147
+ -------
148
+ zs : 1-D ndarray
149
+ Odd length symmetric z-series, ordered from low to high.
150
+
151
+ """
152
+ n = c.size
153
+ zs = np.zeros(2*n-1, dtype=c.dtype)
154
+ zs[n-1:] = c/2
155
+ return zs + zs[::-1]
156
+
157
+
158
+ def _zseries_to_cseries(zs):
159
+ """Convert z-series to a Chebyshev series.
160
+
161
+ Convert a z series to the equivalent Chebyshev series. The result is
162
+ never an empty array. The dtype of the return is the same as that of
163
+ the input. No checks are run on the arguments as this routine is for
164
+ internal use.
165
+
166
+ Parameters
167
+ ----------
168
+ zs : 1-D ndarray
169
+ Odd length symmetric z-series, ordered from low to high.
170
+
171
+ Returns
172
+ -------
173
+ c : 1-D ndarray
174
+ Chebyshev coefficients, ordered from low to high.
175
+
176
+ """
177
+ n = (zs.size + 1)//2
178
+ c = zs[n-1:].copy()
179
+ c[1:n] *= 2
180
+ return c
181
+
182
+
183
+ def _zseries_mul(z1, z2):
184
+ """Multiply two z-series.
185
+
186
+ Multiply two z-series to produce a z-series.
187
+
188
+ Parameters
189
+ ----------
190
+ z1, z2 : 1-D ndarray
191
+ The arrays must be 1-D but this is not checked.
192
+
193
+ Returns
194
+ -------
195
+ product : 1-D ndarray
196
+ The product z-series.
197
+
198
+ Notes
199
+ -----
200
+ This is simply convolution. If symmetric/anti-symmetric z-series are
201
+ denoted by S/A then the following rules apply:
202
+
203
+ S*S, A*A -> S
204
+ S*A, A*S -> A
205
+
206
+ """
207
+ return np.convolve(z1, z2)
208
+
209
+
210
+ def _zseries_div(z1, z2):
211
+ """Divide the first z-series by the second.
212
+
213
+ Divide `z1` by `z2` and return the quotient and remainder as z-series.
214
+ Warning: this implementation only applies when both z1 and z2 have the
215
+ same symmetry, which is sufficient for present purposes.
216
+
217
+ Parameters
218
+ ----------
219
+ z1, z2 : 1-D ndarray
220
+ The arrays must be 1-D and have the same symmetry, but this is not
221
+ checked.
222
+
223
+ Returns
224
+ -------
225
+
226
+ (quotient, remainder) : 1-D ndarrays
227
+ Quotient and remainder as z-series.
228
+
229
+ Notes
230
+ -----
231
+ This is not the same as polynomial division on account of the desired form
232
+ of the remainder. If symmetric/anti-symmetric z-series are denoted by S/A
233
+ then the following rules apply:
234
+
235
+ S/S -> S,S
236
+ A/A -> S,A
237
+
238
+ The restriction to types of the same symmetry could be fixed but seems like
239
+ unneeded generality. There is no natural form for the remainder in the case
240
+ where there is no symmetry.
241
+
242
+ """
243
+ z1 = z1.copy()
244
+ z2 = z2.copy()
245
+ lc1 = len(z1)
246
+ lc2 = len(z2)
247
+ if lc2 == 1:
248
+ z1 /= z2
249
+ return z1, z1[:1]*0
250
+ elif lc1 < lc2:
251
+ return z1[:1]*0, z1
252
+ else:
253
+ dlen = lc1 - lc2
254
+ scl = z2[0]
255
+ z2 /= scl
256
+ quo = np.empty(dlen + 1, dtype=z1.dtype)
257
+ i = 0
258
+ j = dlen
259
+ while i < j:
260
+ r = z1[i]
261
+ quo[i] = z1[i]
262
+ quo[dlen - i] = r
263
+ tmp = r*z2
264
+ z1[i:i+lc2] -= tmp
265
+ z1[j:j+lc2] -= tmp
266
+ i += 1
267
+ j -= 1
268
+ r = z1[i]
269
+ quo[i] = r
270
+ tmp = r*z2
271
+ z1[i:i+lc2] -= tmp
272
+ quo /= scl
273
+ rem = z1[i+1:i-1+lc2].copy()
274
+ return quo, rem
275
+
276
+
277
+ def _zseries_der(zs):
278
+ """Differentiate a z-series.
279
+
280
+ The derivative is with respect to x, not z. This is achieved using the
281
+ chain rule and the value of dx/dz given in the module notes.
282
+
283
+ Parameters
284
+ ----------
285
+ zs : z-series
286
+ The z-series to differentiate.
287
+
288
+ Returns
289
+ -------
290
+ derivative : z-series
291
+ The derivative
292
+
293
+ Notes
294
+ -----
295
+ The zseries for x (ns) has been multiplied by two in order to avoid
296
+ using floats that are incompatible with Decimal and likely other
297
+ specialized scalar types. This scaling has been compensated by
298
+ multiplying the value of zs by two also so that the two cancels in the
299
+ division.
300
+
301
+ """
302
+ n = len(zs)//2
303
+ ns = np.array([-1, 0, 1], dtype=zs.dtype)
304
+ zs *= np.arange(-n, n+1)*2
305
+ d, r = _zseries_div(zs, ns)
306
+ return d
307
+
308
+
309
+ def _zseries_int(zs):
310
+ """Integrate a z-series.
311
+
312
+ The integral is with respect to x, not z. This is achieved by a change
313
+ of variable using dx/dz given in the module notes.
314
+
315
+ Parameters
316
+ ----------
317
+ zs : z-series
318
+ The z-series to integrate
319
+
320
+ Returns
321
+ -------
322
+ integral : z-series
323
+ The indefinite integral
324
+
325
+ Notes
326
+ -----
327
+ The zseries for x (ns) has been multiplied by two in order to avoid
328
+ using floats that are incompatible with Decimal and likely other
329
+ specialized scalar types. This scaling has been compensated by
330
+ dividing the resulting zs by two.
331
+
332
+ """
333
+ n = 1 + len(zs)//2
334
+ ns = np.array([-1, 0, 1], dtype=zs.dtype)
335
+ zs = _zseries_mul(zs, ns)
336
+ div = np.arange(-n, n+1)*2
337
+ zs[:n] /= div[:n]
338
+ zs[n+1:] /= div[n+1:]
339
+ zs[n] = 0
340
+ return zs
341
+
342
+ #
343
+ # Chebyshev series functions
344
+ #
345
+
346
+
347
+ def poly2cheb(pol):
348
+ """
349
+ Convert a polynomial to a Chebyshev series.
350
+
351
+ Convert an array representing the coefficients of a polynomial (relative
352
+ to the "standard" basis) ordered from lowest degree to highest, to an
353
+ array of the coefficients of the equivalent Chebyshev series, ordered
354
+ from lowest to highest degree.
355
+
356
+ Parameters
357
+ ----------
358
+ pol : array_like
359
+ 1-D array containing the polynomial coefficients
360
+
361
+ Returns
362
+ -------
363
+ c : ndarray
364
+ 1-D array containing the coefficients of the equivalent Chebyshev
365
+ series.
366
+
367
+ See Also
368
+ --------
369
+ cheb2poly
370
+
371
+ Notes
372
+ -----
373
+ The easy way to do conversions between polynomial basis sets
374
+ is to use the convert method of a class instance.
375
+
376
+ Examples
377
+ --------
378
+ >>> from numpy import polynomial as P
379
+ >>> p = P.Polynomial(range(4))
380
+ >>> p
381
+ Polynomial([0., 1., 2., 3.], domain=[-1., 1.], window=[-1., 1.], symbol='x')
382
+ >>> c = p.convert(kind=P.Chebyshev)
383
+ >>> c
384
+ Chebyshev([1. , 3.25, 1. , 0.75], domain=[-1., 1.], window=[-1., ...
385
+ >>> P.chebyshev.poly2cheb(range(4))
386
+ array([1. , 3.25, 1. , 0.75])
387
+
388
+ """
389
+ [pol] = pu.as_series([pol])
390
+ deg = len(pol) - 1
391
+ res = 0
392
+ for i in range(deg, -1, -1):
393
+ res = chebadd(chebmulx(res), pol[i])
394
+ return res
395
+
396
+
397
+ def cheb2poly(c):
398
+ """
399
+ Convert a Chebyshev series to a polynomial.
400
+
401
+ Convert an array representing the coefficients of a Chebyshev series,
402
+ ordered from lowest degree to highest, to an array of the coefficients
403
+ of the equivalent polynomial (relative to the "standard" basis) ordered
404
+ from lowest to highest degree.
405
+
406
+ Parameters
407
+ ----------
408
+ c : array_like
409
+ 1-D array containing the Chebyshev series coefficients, ordered
410
+ from lowest order term to highest.
411
+
412
+ Returns
413
+ -------
414
+ pol : ndarray
415
+ 1-D array containing the coefficients of the equivalent polynomial
416
+ (relative to the "standard" basis) ordered from lowest order term
417
+ to highest.
418
+
419
+ See Also
420
+ --------
421
+ poly2cheb
422
+
423
+ Notes
424
+ -----
425
+ The easy way to do conversions between polynomial basis sets
426
+ is to use the convert method of a class instance.
427
+
428
+ Examples
429
+ --------
430
+ >>> from numpy import polynomial as P
431
+ >>> c = P.Chebyshev(range(4))
432
+ >>> c
433
+ Chebyshev([0., 1., 2., 3.], domain=[-1., 1.], window=[-1., 1.], symbol='x')
434
+ >>> p = c.convert(kind=P.Polynomial)
435
+ >>> p
436
+ Polynomial([-2., -8., 4., 12.], domain=[-1., 1.], window=[-1., 1.], ...
437
+ >>> P.chebyshev.cheb2poly(range(4))
438
+ array([-2., -8., 4., 12.])
439
+
440
+ """
441
+ from .polynomial import polyadd, polysub, polymulx
442
+
443
+ [c] = pu.as_series([c])
444
+ n = len(c)
445
+ if n < 3:
446
+ return c
447
+ else:
448
+ c0 = c[-2]
449
+ c1 = c[-1]
450
+ # i is the current degree of c1
451
+ for i in range(n - 1, 1, -1):
452
+ tmp = c0
453
+ c0 = polysub(c[i - 2], c1)
454
+ c1 = polyadd(tmp, polymulx(c1)*2)
455
+ return polyadd(c0, polymulx(c1))
456
+
457
+
458
+ #
459
+ # These are constant arrays are of integer type so as to be compatible
460
+ # with the widest range of other types, such as Decimal.
461
+ #
462
+
463
+ # Chebyshev default domain.
464
+ chebdomain = np.array([-1., 1.])
465
+
466
+ # Chebyshev coefficients representing zero.
467
+ chebzero = np.array([0])
468
+
469
+ # Chebyshev coefficients representing one.
470
+ chebone = np.array([1])
471
+
472
+ # Chebyshev coefficients representing the identity x.
473
+ chebx = np.array([0, 1])
474
+
475
+
476
+ def chebline(off, scl):
477
+ """
478
+ Chebyshev series whose graph is a straight line.
479
+
480
+ Parameters
481
+ ----------
482
+ off, scl : scalars
483
+ The specified line is given by ``off + scl*x``.
484
+
485
+ Returns
486
+ -------
487
+ y : ndarray
488
+ This module's representation of the Chebyshev series for
489
+ ``off + scl*x``.
490
+
491
+ See Also
492
+ --------
493
+ numpy.polynomial.polynomial.polyline
494
+ numpy.polynomial.legendre.legline
495
+ numpy.polynomial.laguerre.lagline
496
+ numpy.polynomial.hermite.hermline
497
+ numpy.polynomial.hermite_e.hermeline
498
+
499
+ Examples
500
+ --------
501
+ >>> import numpy.polynomial.chebyshev as C
502
+ >>> C.chebline(3,2)
503
+ array([3, 2])
504
+ >>> C.chebval(-3, C.chebline(3,2)) # should be -3
505
+ -3.0
506
+
507
+ """
508
+ if scl != 0:
509
+ return np.array([off, scl])
510
+ else:
511
+ return np.array([off])
512
+
513
+
514
+ def chebfromroots(roots):
515
+ """
516
+ Generate a Chebyshev series with given roots.
517
+
518
+ The function returns the coefficients of the polynomial
519
+
520
+ .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
521
+
522
+ in Chebyshev form, where the :math:`r_n` are the roots specified in
523
+ `roots`. If a zero has multiplicity n, then it must appear in `roots`
524
+ n times. For instance, if 2 is a root of multiplicity three and 3 is a
525
+ root of multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3].
526
+ The roots can appear in any order.
527
+
528
+ If the returned coefficients are `c`, then
529
+
530
+ .. math:: p(x) = c_0 + c_1 * T_1(x) + ... + c_n * T_n(x)
531
+
532
+ The coefficient of the last term is not generally 1 for monic
533
+ polynomials in Chebyshev form.
534
+
535
+ Parameters
536
+ ----------
537
+ roots : array_like
538
+ Sequence containing the roots.
539
+
540
+ Returns
541
+ -------
542
+ out : ndarray
543
+ 1-D array of coefficients. If all roots are real then `out` is a
544
+ real array, if some of the roots are complex, then `out` is complex
545
+ even if all the coefficients in the result are real (see Examples
546
+ below).
547
+
548
+ See Also
549
+ --------
550
+ numpy.polynomial.polynomial.polyfromroots
551
+ numpy.polynomial.legendre.legfromroots
552
+ numpy.polynomial.laguerre.lagfromroots
553
+ numpy.polynomial.hermite.hermfromroots
554
+ numpy.polynomial.hermite_e.hermefromroots
555
+
556
+ Examples
557
+ --------
558
+ >>> import numpy.polynomial.chebyshev as C
559
+ >>> C.chebfromroots((-1,0,1)) # x^3 - x relative to the standard basis
560
+ array([ 0. , -0.25, 0. , 0.25])
561
+ >>> j = complex(0,1)
562
+ >>> C.chebfromroots((-j,j)) # x^2 + 1 relative to the standard basis
563
+ array([1.5+0.j, 0. +0.j, 0.5+0.j])
564
+
565
+ """
566
+ return pu._fromroots(chebline, chebmul, roots)
567
+
568
+
569
+ def chebadd(c1, c2):
570
+ """
571
+ Add one Chebyshev series to another.
572
+
573
+ Returns the sum of two Chebyshev series `c1` + `c2`. The arguments
574
+ are sequences of coefficients ordered from lowest order term to
575
+ highest, i.e., [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
576
+
577
+ Parameters
578
+ ----------
579
+ c1, c2 : array_like
580
+ 1-D arrays of Chebyshev series coefficients ordered from low to
581
+ high.
582
+
583
+ Returns
584
+ -------
585
+ out : ndarray
586
+ Array representing the Chebyshev series of their sum.
587
+
588
+ See Also
589
+ --------
590
+ chebsub, chebmulx, chebmul, chebdiv, chebpow
591
+
592
+ Notes
593
+ -----
594
+ Unlike multiplication, division, etc., the sum of two Chebyshev series
595
+ is a Chebyshev series (without having to "reproject" the result onto
596
+ the basis set) so addition, just like that of "standard" polynomials,
597
+ is simply "component-wise."
598
+
599
+ Examples
600
+ --------
601
+ >>> from numpy.polynomial import chebyshev as C
602
+ >>> c1 = (1,2,3)
603
+ >>> c2 = (3,2,1)
604
+ >>> C.chebadd(c1,c2)
605
+ array([4., 4., 4.])
606
+
607
+ """
608
+ return pu._add(c1, c2)
609
+
610
+
611
+ def chebsub(c1, c2):
612
+ """
613
+ Subtract one Chebyshev series from another.
614
+
615
+ Returns the difference of two Chebyshev series `c1` - `c2`. The
616
+ sequences of coefficients are from lowest order term to highest, i.e.,
617
+ [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
618
+
619
+ Parameters
620
+ ----------
621
+ c1, c2 : array_like
622
+ 1-D arrays of Chebyshev series coefficients ordered from low to
623
+ high.
624
+
625
+ Returns
626
+ -------
627
+ out : ndarray
628
+ Of Chebyshev series coefficients representing their difference.
629
+
630
+ See Also
631
+ --------
632
+ chebadd, chebmulx, chebmul, chebdiv, chebpow
633
+
634
+ Notes
635
+ -----
636
+ Unlike multiplication, division, etc., the difference of two Chebyshev
637
+ series is a Chebyshev series (without having to "reproject" the result
638
+ onto the basis set) so subtraction, just like that of "standard"
639
+ polynomials, is simply "component-wise."
640
+
641
+ Examples
642
+ --------
643
+ >>> from numpy.polynomial import chebyshev as C
644
+ >>> c1 = (1,2,3)
645
+ >>> c2 = (3,2,1)
646
+ >>> C.chebsub(c1,c2)
647
+ array([-2., 0., 2.])
648
+ >>> C.chebsub(c2,c1) # -C.chebsub(c1,c2)
649
+ array([ 2., 0., -2.])
650
+
651
+ """
652
+ return pu._sub(c1, c2)
653
+
654
+
655
+ def chebmulx(c):
656
+ """Multiply a Chebyshev series by x.
657
+
658
+ Multiply the polynomial `c` by x, where x is the independent
659
+ variable.
660
+
661
+
662
+ Parameters
663
+ ----------
664
+ c : array_like
665
+ 1-D array of Chebyshev series coefficients ordered from low to
666
+ high.
667
+
668
+ Returns
669
+ -------
670
+ out : ndarray
671
+ Array representing the result of the multiplication.
672
+
673
+ See Also
674
+ --------
675
+ chebadd, chebsub, chebmul, chebdiv, chebpow
676
+
677
+ Notes
678
+ -----
679
+
680
+ .. versionadded:: 1.5.0
681
+
682
+ Examples
683
+ --------
684
+ >>> from numpy.polynomial import chebyshev as C
685
+ >>> C.chebmulx([1,2,3])
686
+ array([1. , 2.5, 1. , 1.5])
687
+
688
+ """
689
+ # c is a trimmed copy
690
+ [c] = pu.as_series([c])
691
+ # The zero series needs special treatment
692
+ if len(c) == 1 and c[0] == 0:
693
+ return c
694
+
695
+ prd = np.empty(len(c) + 1, dtype=c.dtype)
696
+ prd[0] = c[0]*0
697
+ prd[1] = c[0]
698
+ if len(c) > 1:
699
+ tmp = c[1:]/2
700
+ prd[2:] = tmp
701
+ prd[0:-2] += tmp
702
+ return prd
703
+
704
+
705
+ def chebmul(c1, c2):
706
+ """
707
+ Multiply one Chebyshev series by another.
708
+
709
+ Returns the product of two Chebyshev series `c1` * `c2`. The arguments
710
+ are sequences of coefficients, from lowest order "term" to highest,
711
+ e.g., [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
712
+
713
+ Parameters
714
+ ----------
715
+ c1, c2 : array_like
716
+ 1-D arrays of Chebyshev series coefficients ordered from low to
717
+ high.
718
+
719
+ Returns
720
+ -------
721
+ out : ndarray
722
+ Of Chebyshev series coefficients representing their product.
723
+
724
+ See Also
725
+ --------
726
+ chebadd, chebsub, chebmulx, chebdiv, chebpow
727
+
728
+ Notes
729
+ -----
730
+ In general, the (polynomial) product of two C-series results in terms
731
+ that are not in the Chebyshev polynomial basis set. Thus, to express
732
+ the product as a C-series, it is typically necessary to "reproject"
733
+ the product onto said basis set, which typically produces
734
+ "unintuitive live" (but correct) results; see Examples section below.
735
+
736
+ Examples
737
+ --------
738
+ >>> from numpy.polynomial import chebyshev as C
739
+ >>> c1 = (1,2,3)
740
+ >>> c2 = (3,2,1)
741
+ >>> C.chebmul(c1,c2) # multiplication requires "reprojection"
742
+ array([ 6.5, 12. , 12. , 4. , 1.5])
743
+
744
+ """
745
+ # c1, c2 are trimmed copies
746
+ [c1, c2] = pu.as_series([c1, c2])
747
+ z1 = _cseries_to_zseries(c1)
748
+ z2 = _cseries_to_zseries(c2)
749
+ prd = _zseries_mul(z1, z2)
750
+ ret = _zseries_to_cseries(prd)
751
+ return pu.trimseq(ret)
752
+
753
+
754
+ def chebdiv(c1, c2):
755
+ """
756
+ Divide one Chebyshev series by another.
757
+
758
+ Returns the quotient-with-remainder of two Chebyshev series
759
+ `c1` / `c2`. The arguments are sequences of coefficients from lowest
760
+ order "term" to highest, e.g., [1,2,3] represents the series
761
+ ``T_0 + 2*T_1 + 3*T_2``.
762
+
763
+ Parameters
764
+ ----------
765
+ c1, c2 : array_like
766
+ 1-D arrays of Chebyshev series coefficients ordered from low to
767
+ high.
768
+
769
+ Returns
770
+ -------
771
+ [quo, rem] : ndarrays
772
+ Of Chebyshev series coefficients representing the quotient and
773
+ remainder.
774
+
775
+ See Also
776
+ --------
777
+ chebadd, chebsub, chebmulx, chebmul, chebpow
778
+
779
+ Notes
780
+ -----
781
+ In general, the (polynomial) division of one C-series by another
782
+ results in quotient and remainder terms that are not in the Chebyshev
783
+ polynomial basis set. Thus, to express these results as C-series, it
784
+ is typically necessary to "reproject" the results onto said basis
785
+ set, which typically produces "unintuitive" (but correct) results;
786
+ see Examples section below.
787
+
788
+ Examples
789
+ --------
790
+ >>> from numpy.polynomial import chebyshev as C
791
+ >>> c1 = (1,2,3)
792
+ >>> c2 = (3,2,1)
793
+ >>> C.chebdiv(c1,c2) # quotient "intuitive," remainder not
794
+ (array([3.]), array([-8., -4.]))
795
+ >>> c2 = (0,1,2,3)
796
+ >>> C.chebdiv(c2,c1) # neither "intuitive"
797
+ (array([0., 2.]), array([-2., -4.]))
798
+
799
+ """
800
+ # c1, c2 are trimmed copies
801
+ [c1, c2] = pu.as_series([c1, c2])
802
+ if c2[-1] == 0:
803
+ raise ZeroDivisionError()
804
+
805
+ # note: this is more efficient than `pu._div(chebmul, c1, c2)`
806
+ lc1 = len(c1)
807
+ lc2 = len(c2)
808
+ if lc1 < lc2:
809
+ return c1[:1]*0, c1
810
+ elif lc2 == 1:
811
+ return c1/c2[-1], c1[:1]*0
812
+ else:
813
+ z1 = _cseries_to_zseries(c1)
814
+ z2 = _cseries_to_zseries(c2)
815
+ quo, rem = _zseries_div(z1, z2)
816
+ quo = pu.trimseq(_zseries_to_cseries(quo))
817
+ rem = pu.trimseq(_zseries_to_cseries(rem))
818
+ return quo, rem
819
+
820
+
821
+ def chebpow(c, pow, maxpower=16):
822
+ """Raise a Chebyshev series to a power.
823
+
824
+ Returns the Chebyshev series `c` raised to the power `pow`. The
825
+ argument `c` is a sequence of coefficients ordered from low to high.
826
+ i.e., [1,2,3] is the series ``T_0 + 2*T_1 + 3*T_2.``
827
+
828
+ Parameters
829
+ ----------
830
+ c : array_like
831
+ 1-D array of Chebyshev series coefficients ordered from low to
832
+ high.
833
+ pow : integer
834
+ Power to which the series will be raised
835
+ maxpower : integer, optional
836
+ Maximum power allowed. This is mainly to limit growth of the series
837
+ to unmanageable size. Default is 16
838
+
839
+ Returns
840
+ -------
841
+ coef : ndarray
842
+ Chebyshev series of power.
843
+
844
+ See Also
845
+ --------
846
+ chebadd, chebsub, chebmulx, chebmul, chebdiv
847
+
848
+ Examples
849
+ --------
850
+ >>> from numpy.polynomial import chebyshev as C
851
+ >>> C.chebpow([1, 2, 3, 4], 2)
852
+ array([15.5, 22. , 16. , ..., 12.5, 12. , 8. ])
853
+
854
+ """
855
+ # note: this is more efficient than `pu._pow(chebmul, c1, c2)`, as it
856
+ # avoids converting between z and c series repeatedly
857
+
858
+ # c is a trimmed copy
859
+ [c] = pu.as_series([c])
860
+ power = int(pow)
861
+ if power != pow or power < 0:
862
+ raise ValueError("Power must be a non-negative integer.")
863
+ elif maxpower is not None and power > maxpower:
864
+ raise ValueError("Power is too large")
865
+ elif power == 0:
866
+ return np.array([1], dtype=c.dtype)
867
+ elif power == 1:
868
+ return c
869
+ else:
870
+ # This can be made more efficient by using powers of two
871
+ # in the usual way.
872
+ zs = _cseries_to_zseries(c)
873
+ prd = zs
874
+ for i in range(2, power + 1):
875
+ prd = np.convolve(prd, zs)
876
+ return _zseries_to_cseries(prd)
877
+
878
+
879
+ def chebder(c, m=1, scl=1, axis=0):
880
+ """
881
+ Differentiate a Chebyshev series.
882
+
883
+ Returns the Chebyshev series coefficients `c` differentiated `m` times
884
+ along `axis`. At each iteration the result is multiplied by `scl` (the
885
+ scaling factor is for use in a linear change of variable). The argument
886
+ `c` is an array of coefficients from low to high degree along each
887
+ axis, e.g., [1,2,3] represents the series ``1*T_0 + 2*T_1 + 3*T_2``
888
+ while [[1,2],[1,2]] represents ``1*T_0(x)*T_0(y) + 1*T_1(x)*T_0(y) +
889
+ 2*T_0(x)*T_1(y) + 2*T_1(x)*T_1(y)`` if axis=0 is ``x`` and axis=1 is
890
+ ``y``.
891
+
892
+ Parameters
893
+ ----------
894
+ c : array_like
895
+ Array of Chebyshev series coefficients. If c is multidimensional
896
+ the different axis correspond to different variables with the
897
+ degree in each axis given by the corresponding index.
898
+ m : int, optional
899
+ Number of derivatives taken, must be non-negative. (Default: 1)
900
+ scl : scalar, optional
901
+ Each differentiation is multiplied by `scl`. The end result is
902
+ multiplication by ``scl**m``. This is for use in a linear change of
903
+ variable. (Default: 1)
904
+ axis : int, optional
905
+ Axis over which the derivative is taken. (Default: 0).
906
+
907
+ .. versionadded:: 1.7.0
908
+
909
+ Returns
910
+ -------
911
+ der : ndarray
912
+ Chebyshev series of the derivative.
913
+
914
+ See Also
915
+ --------
916
+ chebint
917
+
918
+ Notes
919
+ -----
920
+ In general, the result of differentiating a C-series needs to be
921
+ "reprojected" onto the C-series basis set. Thus, typically, the
922
+ result of this function is "unintuitive," albeit correct; see Examples
923
+ section below.
924
+
925
+ Examples
926
+ --------
927
+ >>> from numpy.polynomial import chebyshev as C
928
+ >>> c = (1,2,3,4)
929
+ >>> C.chebder(c)
930
+ array([14., 12., 24.])
931
+ >>> C.chebder(c,3)
932
+ array([96.])
933
+ >>> C.chebder(c,scl=-1)
934
+ array([-14., -12., -24.])
935
+ >>> C.chebder(c,2,-1)
936
+ array([12., 96.])
937
+
938
+ """
939
+ c = np.array(c, ndmin=1, copy=True)
940
+ if c.dtype.char in '?bBhHiIlLqQpP':
941
+ c = c.astype(np.double)
942
+ cnt = pu._as_int(m, "the order of derivation")
943
+ iaxis = pu._as_int(axis, "the axis")
944
+ if cnt < 0:
945
+ raise ValueError("The order of derivation must be non-negative")
946
+ iaxis = normalize_axis_index(iaxis, c.ndim)
947
+
948
+ if cnt == 0:
949
+ return c
950
+
951
+ c = np.moveaxis(c, iaxis, 0)
952
+ n = len(c)
953
+ if cnt >= n:
954
+ c = c[:1]*0
955
+ else:
956
+ for i in range(cnt):
957
+ n = n - 1
958
+ c *= scl
959
+ der = np.empty((n,) + c.shape[1:], dtype=c.dtype)
960
+ for j in range(n, 2, -1):
961
+ der[j - 1] = (2*j)*c[j]
962
+ c[j - 2] += (j*c[j])/(j - 2)
963
+ if n > 1:
964
+ der[1] = 4*c[2]
965
+ der[0] = c[1]
966
+ c = der
967
+ c = np.moveaxis(c, 0, iaxis)
968
+ return c
969
+
970
+
971
+ def chebint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
972
+ """
973
+ Integrate a Chebyshev series.
974
+
975
+ Returns the Chebyshev series coefficients `c` integrated `m` times from
976
+ `lbnd` along `axis`. At each iteration the resulting series is
977
+ **multiplied** by `scl` and an integration constant, `k`, is added.
978
+ The scaling factor is for use in a linear change of variable. ("Buyer
979
+ beware": note that, depending on what one is doing, one may want `scl`
980
+ to be the reciprocal of what one might expect; for more information,
981
+ see the Notes section below.) The argument `c` is an array of
982
+ coefficients from low to high degree along each axis, e.g., [1,2,3]
983
+ represents the series ``T_0 + 2*T_1 + 3*T_2`` while [[1,2],[1,2]]
984
+ represents ``1*T_0(x)*T_0(y) + 1*T_1(x)*T_0(y) + 2*T_0(x)*T_1(y) +
985
+ 2*T_1(x)*T_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``.
986
+
987
+ Parameters
988
+ ----------
989
+ c : array_like
990
+ Array of Chebyshev series coefficients. If c is multidimensional
991
+ the different axis correspond to different variables with the
992
+ degree in each axis given by the corresponding index.
993
+ m : int, optional
994
+ Order of integration, must be positive. (Default: 1)
995
+ k : {[], list, scalar}, optional
996
+ Integration constant(s). The value of the first integral at zero
997
+ is the first value in the list, the value of the second integral
998
+ at zero is the second value, etc. If ``k == []`` (the default),
999
+ all constants are set to zero. If ``m == 1``, a single scalar can
1000
+ be given instead of a list.
1001
+ lbnd : scalar, optional
1002
+ The lower bound of the integral. (Default: 0)
1003
+ scl : scalar, optional
1004
+ Following each integration the result is *multiplied* by `scl`
1005
+ before the integration constant is added. (Default: 1)
1006
+ axis : int, optional
1007
+ Axis over which the integral is taken. (Default: 0).
1008
+
1009
+ .. versionadded:: 1.7.0
1010
+
1011
+ Returns
1012
+ -------
1013
+ S : ndarray
1014
+ C-series coefficients of the integral.
1015
+
1016
+ Raises
1017
+ ------
1018
+ ValueError
1019
+ If ``m < 1``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or
1020
+ ``np.ndim(scl) != 0``.
1021
+
1022
+ See Also
1023
+ --------
1024
+ chebder
1025
+
1026
+ Notes
1027
+ -----
1028
+ Note that the result of each integration is *multiplied* by `scl`.
1029
+ Why is this important to note? Say one is making a linear change of
1030
+ variable :math:`u = ax + b` in an integral relative to `x`. Then
1031
+ :math:`dx = du/a`, so one will need to set `scl` equal to
1032
+ :math:`1/a`- perhaps not what one would have first thought.
1033
+
1034
+ Also note that, in general, the result of integrating a C-series needs
1035
+ to be "reprojected" onto the C-series basis set. Thus, typically,
1036
+ the result of this function is "unintuitive," albeit correct; see
1037
+ Examples section below.
1038
+
1039
+ Examples
1040
+ --------
1041
+ >>> from numpy.polynomial import chebyshev as C
1042
+ >>> c = (1,2,3)
1043
+ >>> C.chebint(c)
1044
+ array([ 0.5, -0.5, 0.5, 0.5])
1045
+ >>> C.chebint(c,3)
1046
+ array([ 0.03125 , -0.1875 , 0.04166667, -0.05208333, 0.01041667, # may vary
1047
+ 0.00625 ])
1048
+ >>> C.chebint(c, k=3)
1049
+ array([ 3.5, -0.5, 0.5, 0.5])
1050
+ >>> C.chebint(c,lbnd=-2)
1051
+ array([ 8.5, -0.5, 0.5, 0.5])
1052
+ >>> C.chebint(c,scl=-2)
1053
+ array([-1., 1., -1., -1.])
1054
+
1055
+ """
1056
+ c = np.array(c, ndmin=1, copy=True)
1057
+ if c.dtype.char in '?bBhHiIlLqQpP':
1058
+ c = c.astype(np.double)
1059
+ if not np.iterable(k):
1060
+ k = [k]
1061
+ cnt = pu._as_int(m, "the order of integration")
1062
+ iaxis = pu._as_int(axis, "the axis")
1063
+ if cnt < 0:
1064
+ raise ValueError("The order of integration must be non-negative")
1065
+ if len(k) > cnt:
1066
+ raise ValueError("Too many integration constants")
1067
+ if np.ndim(lbnd) != 0:
1068
+ raise ValueError("lbnd must be a scalar.")
1069
+ if np.ndim(scl) != 0:
1070
+ raise ValueError("scl must be a scalar.")
1071
+ iaxis = normalize_axis_index(iaxis, c.ndim)
1072
+
1073
+ if cnt == 0:
1074
+ return c
1075
+
1076
+ c = np.moveaxis(c, iaxis, 0)
1077
+ k = list(k) + [0]*(cnt - len(k))
1078
+ for i in range(cnt):
1079
+ n = len(c)
1080
+ c *= scl
1081
+ if n == 1 and np.all(c[0] == 0):
1082
+ c[0] += k[i]
1083
+ else:
1084
+ tmp = np.empty((n + 1,) + c.shape[1:], dtype=c.dtype)
1085
+ tmp[0] = c[0]*0
1086
+ tmp[1] = c[0]
1087
+ if n > 1:
1088
+ tmp[2] = c[1]/4
1089
+ for j in range(2, n):
1090
+ tmp[j + 1] = c[j]/(2*(j + 1))
1091
+ tmp[j - 1] -= c[j]/(2*(j - 1))
1092
+ tmp[0] += k[i] - chebval(lbnd, tmp)
1093
+ c = tmp
1094
+ c = np.moveaxis(c, 0, iaxis)
1095
+ return c
1096
+
1097
+
1098
+ def chebval(x, c, tensor=True):
1099
+ """
1100
+ Evaluate a Chebyshev series at points x.
1101
+
1102
+ If `c` is of length `n + 1`, this function returns the value:
1103
+
1104
+ .. math:: p(x) = c_0 * T_0(x) + c_1 * T_1(x) + ... + c_n * T_n(x)
1105
+
1106
+ The parameter `x` is converted to an array only if it is a tuple or a
1107
+ list, otherwise it is treated as a scalar. In either case, either `x`
1108
+ or its elements must support multiplication and addition both with
1109
+ themselves and with the elements of `c`.
1110
+
1111
+ If `c` is a 1-D array, then ``p(x)`` will have the same shape as `x`. If
1112
+ `c` is multidimensional, then the shape of the result depends on the
1113
+ value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
1114
+ x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
1115
+ scalars have shape (,).
1116
+
1117
+ Trailing zeros in the coefficients will be used in the evaluation, so
1118
+ they should be avoided if efficiency is a concern.
1119
+
1120
+ Parameters
1121
+ ----------
1122
+ x : array_like, compatible object
1123
+ If `x` is a list or tuple, it is converted to an ndarray, otherwise
1124
+ it is left unchanged and treated as a scalar. In either case, `x`
1125
+ or its elements must support addition and multiplication with
1126
+ themselves and with the elements of `c`.
1127
+ c : array_like
1128
+ Array of coefficients ordered so that the coefficients for terms of
1129
+ degree n are contained in c[n]. If `c` is multidimensional the
1130
+ remaining indices enumerate multiple polynomials. In the two
1131
+ dimensional case the coefficients may be thought of as stored in
1132
+ the columns of `c`.
1133
+ tensor : boolean, optional
1134
+ If True, the shape of the coefficient array is extended with ones
1135
+ on the right, one for each dimension of `x`. Scalars have dimension 0
1136
+ for this action. The result is that every column of coefficients in
1137
+ `c` is evaluated for every element of `x`. If False, `x` is broadcast
1138
+ over the columns of `c` for the evaluation. This keyword is useful
1139
+ when `c` is multidimensional. The default value is True.
1140
+
1141
+ .. versionadded:: 1.7.0
1142
+
1143
+ Returns
1144
+ -------
1145
+ values : ndarray, algebra_like
1146
+ The shape of the return value is described above.
1147
+
1148
+ See Also
1149
+ --------
1150
+ chebval2d, chebgrid2d, chebval3d, chebgrid3d
1151
+
1152
+ Notes
1153
+ -----
1154
+ The evaluation uses Clenshaw recursion, aka synthetic division.
1155
+
1156
+ """
1157
+ c = np.array(c, ndmin=1, copy=True)
1158
+ if c.dtype.char in '?bBhHiIlLqQpP':
1159
+ c = c.astype(np.double)
1160
+ if isinstance(x, (tuple, list)):
1161
+ x = np.asarray(x)
1162
+ if isinstance(x, np.ndarray) and tensor:
1163
+ c = c.reshape(c.shape + (1,)*x.ndim)
1164
+
1165
+ if len(c) == 1:
1166
+ c0 = c[0]
1167
+ c1 = 0
1168
+ elif len(c) == 2:
1169
+ c0 = c[0]
1170
+ c1 = c[1]
1171
+ else:
1172
+ x2 = 2*x
1173
+ c0 = c[-2]
1174
+ c1 = c[-1]
1175
+ for i in range(3, len(c) + 1):
1176
+ tmp = c0
1177
+ c0 = c[-i] - c1
1178
+ c1 = tmp + c1*x2
1179
+ return c0 + c1*x
1180
+
1181
+
1182
+ def chebval2d(x, y, c):
1183
+ """
1184
+ Evaluate a 2-D Chebyshev series at points (x, y).
1185
+
1186
+ This function returns the values:
1187
+
1188
+ .. math:: p(x,y) = \\sum_{i,j} c_{i,j} * T_i(x) * T_j(y)
1189
+
1190
+ The parameters `x` and `y` are converted to arrays only if they are
1191
+ tuples or a lists, otherwise they are treated as a scalars and they
1192
+ must have the same shape after conversion. In either case, either `x`
1193
+ and `y` or their elements must support multiplication and addition both
1194
+ with themselves and with the elements of `c`.
1195
+
1196
+ If `c` is a 1-D array a one is implicitly appended to its shape to make
1197
+ it 2-D. The shape of the result will be c.shape[2:] + x.shape.
1198
+
1199
+ Parameters
1200
+ ----------
1201
+ x, y : array_like, compatible objects
1202
+ The two dimensional series is evaluated at the points ``(x, y)``,
1203
+ where `x` and `y` must have the same shape. If `x` or `y` is a list
1204
+ or tuple, it is first converted to an ndarray, otherwise it is left
1205
+ unchanged and if it isn't an ndarray it is treated as a scalar.
1206
+ c : array_like
1207
+ Array of coefficients ordered so that the coefficient of the term
1208
+ of multi-degree i,j is contained in ``c[i,j]``. If `c` has
1209
+ dimension greater than 2 the remaining indices enumerate multiple
1210
+ sets of coefficients.
1211
+
1212
+ Returns
1213
+ -------
1214
+ values : ndarray, compatible object
1215
+ The values of the two dimensional Chebyshev series at points formed
1216
+ from pairs of corresponding values from `x` and `y`.
1217
+
1218
+ See Also
1219
+ --------
1220
+ chebval, chebgrid2d, chebval3d, chebgrid3d
1221
+
1222
+ Notes
1223
+ -----
1224
+
1225
+ .. versionadded:: 1.7.0
1226
+
1227
+ """
1228
+ return pu._valnd(chebval, c, x, y)
1229
+
1230
+
1231
+ def chebgrid2d(x, y, c):
1232
+ """
1233
+ Evaluate a 2-D Chebyshev series on the Cartesian product of x and y.
1234
+
1235
+ This function returns the values:
1236
+
1237
+ .. math:: p(a,b) = \\sum_{i,j} c_{i,j} * T_i(a) * T_j(b),
1238
+
1239
+ where the points `(a, b)` consist of all pairs formed by taking
1240
+ `a` from `x` and `b` from `y`. The resulting points form a grid with
1241
+ `x` in the first dimension and `y` in the second.
1242
+
1243
+ The parameters `x` and `y` are converted to arrays only if they are
1244
+ tuples or a lists, otherwise they are treated as a scalars. In either
1245
+ case, either `x` and `y` or their elements must support multiplication
1246
+ and addition both with themselves and with the elements of `c`.
1247
+
1248
+ If `c` has fewer than two dimensions, ones are implicitly appended to
1249
+ its shape to make it 2-D. The shape of the result will be c.shape[2:] +
1250
+ x.shape + y.shape.
1251
+
1252
+ Parameters
1253
+ ----------
1254
+ x, y : array_like, compatible objects
1255
+ The two dimensional series is evaluated at the points in the
1256
+ Cartesian product of `x` and `y`. If `x` or `y` is a list or
1257
+ tuple, it is first converted to an ndarray, otherwise it is left
1258
+ unchanged and, if it isn't an ndarray, it is treated as a scalar.
1259
+ c : array_like
1260
+ Array of coefficients ordered so that the coefficient of the term of
1261
+ multi-degree i,j is contained in ``c[i,j]``. If `c` has dimension
1262
+ greater than two the remaining indices enumerate multiple sets of
1263
+ coefficients.
1264
+
1265
+ Returns
1266
+ -------
1267
+ values : ndarray, compatible object
1268
+ The values of the two dimensional Chebyshev series at points in the
1269
+ Cartesian product of `x` and `y`.
1270
+
1271
+ See Also
1272
+ --------
1273
+ chebval, chebval2d, chebval3d, chebgrid3d
1274
+
1275
+ Notes
1276
+ -----
1277
+
1278
+ .. versionadded:: 1.7.0
1279
+
1280
+ """
1281
+ return pu._gridnd(chebval, c, x, y)
1282
+
1283
+
1284
+ def chebval3d(x, y, z, c):
1285
+ """
1286
+ Evaluate a 3-D Chebyshev series at points (x, y, z).
1287
+
1288
+ This function returns the values:
1289
+
1290
+ .. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * T_i(x) * T_j(y) * T_k(z)
1291
+
1292
+ The parameters `x`, `y`, and `z` are converted to arrays only if
1293
+ they are tuples or a lists, otherwise they are treated as a scalars and
1294
+ they must have the same shape after conversion. In either case, either
1295
+ `x`, `y`, and `z` or their elements must support multiplication and
1296
+ addition both with themselves and with the elements of `c`.
1297
+
1298
+ If `c` has fewer than 3 dimensions, ones are implicitly appended to its
1299
+ shape to make it 3-D. The shape of the result will be c.shape[3:] +
1300
+ x.shape.
1301
+
1302
+ Parameters
1303
+ ----------
1304
+ x, y, z : array_like, compatible object
1305
+ The three dimensional series is evaluated at the points
1306
+ ``(x, y, z)``, where `x`, `y`, and `z` must have the same shape. If
1307
+ any of `x`, `y`, or `z` is a list or tuple, it is first converted
1308
+ to an ndarray, otherwise it is left unchanged and if it isn't an
1309
+ ndarray it is treated as a scalar.
1310
+ c : array_like
1311
+ Array of coefficients ordered so that the coefficient of the term of
1312
+ multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
1313
+ greater than 3 the remaining indices enumerate multiple sets of
1314
+ coefficients.
1315
+
1316
+ Returns
1317
+ -------
1318
+ values : ndarray, compatible object
1319
+ The values of the multidimensional polynomial on points formed with
1320
+ triples of corresponding values from `x`, `y`, and `z`.
1321
+
1322
+ See Also
1323
+ --------
1324
+ chebval, chebval2d, chebgrid2d, chebgrid3d
1325
+
1326
+ Notes
1327
+ -----
1328
+
1329
+ .. versionadded:: 1.7.0
1330
+
1331
+ """
1332
+ return pu._valnd(chebval, c, x, y, z)
1333
+
1334
+
1335
+ def chebgrid3d(x, y, z, c):
1336
+ """
1337
+ Evaluate a 3-D Chebyshev series on the Cartesian product of x, y, and z.
1338
+
1339
+ This function returns the values:
1340
+
1341
+ .. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * T_i(a) * T_j(b) * T_k(c)
1342
+
1343
+ where the points ``(a, b, c)`` consist of all triples formed by taking
1344
+ `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
1345
+ a grid with `x` in the first dimension, `y` in the second, and `z` in
1346
+ the third.
1347
+
1348
+ The parameters `x`, `y`, and `z` are converted to arrays only if they
1349
+ are tuples or a lists, otherwise they are treated as a scalars. In
1350
+ either case, either `x`, `y`, and `z` or their elements must support
1351
+ multiplication and addition both with themselves and with the elements
1352
+ of `c`.
1353
+
1354
+ If `c` has fewer than three dimensions, ones are implicitly appended to
1355
+ its shape to make it 3-D. The shape of the result will be c.shape[3:] +
1356
+ x.shape + y.shape + z.shape.
1357
+
1358
+ Parameters
1359
+ ----------
1360
+ x, y, z : array_like, compatible objects
1361
+ The three dimensional series is evaluated at the points in the
1362
+ Cartesian product of `x`, `y`, and `z`. If `x`, `y`, or `z` is a
1363
+ list or tuple, it is first converted to an ndarray, otherwise it is
1364
+ left unchanged and, if it isn't an ndarray, it is treated as a
1365
+ scalar.
1366
+ c : array_like
1367
+ Array of coefficients ordered so that the coefficients for terms of
1368
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
1369
+ greater than two the remaining indices enumerate multiple sets of
1370
+ coefficients.
1371
+
1372
+ Returns
1373
+ -------
1374
+ values : ndarray, compatible object
1375
+ The values of the two dimensional polynomial at points in the Cartesian
1376
+ product of `x` and `y`.
1377
+
1378
+ See Also
1379
+ --------
1380
+ chebval, chebval2d, chebgrid2d, chebval3d
1381
+
1382
+ Notes
1383
+ -----
1384
+
1385
+ .. versionadded:: 1.7.0
1386
+
1387
+ """
1388
+ return pu._gridnd(chebval, c, x, y, z)
1389
+
1390
+
1391
+ def chebvander(x, deg):
1392
+ """Pseudo-Vandermonde matrix of given degree.
1393
+
1394
+ Returns the pseudo-Vandermonde matrix of degree `deg` and sample points
1395
+ `x`. The pseudo-Vandermonde matrix is defined by
1396
+
1397
+ .. math:: V[..., i] = T_i(x),
1398
+
1399
+ where ``0 <= i <= deg``. The leading indices of `V` index the elements of
1400
+ `x` and the last index is the degree of the Chebyshev polynomial.
1401
+
1402
+ If `c` is a 1-D array of coefficients of length ``n + 1`` and `V` is the
1403
+ matrix ``V = chebvander(x, n)``, then ``np.dot(V, c)`` and
1404
+ ``chebval(x, c)`` are the same up to roundoff. This equivalence is
1405
+ useful both for least squares fitting and for the evaluation of a large
1406
+ number of Chebyshev series of the same degree and sample points.
1407
+
1408
+ Parameters
1409
+ ----------
1410
+ x : array_like
1411
+ Array of points. The dtype is converted to float64 or complex128
1412
+ depending on whether any of the elements are complex. If `x` is
1413
+ scalar it is converted to a 1-D array.
1414
+ deg : int
1415
+ Degree of the resulting matrix.
1416
+
1417
+ Returns
1418
+ -------
1419
+ vander : ndarray
1420
+ The pseudo Vandermonde matrix. The shape of the returned matrix is
1421
+ ``x.shape + (deg + 1,)``, where The last index is the degree of the
1422
+ corresponding Chebyshev polynomial. The dtype will be the same as
1423
+ the converted `x`.
1424
+
1425
+ """
1426
+ ideg = pu._as_int(deg, "deg")
1427
+ if ideg < 0:
1428
+ raise ValueError("deg must be non-negative")
1429
+
1430
+ x = np.array(x, copy=None, ndmin=1) + 0.0
1431
+ dims = (ideg + 1,) + x.shape
1432
+ dtyp = x.dtype
1433
+ v = np.empty(dims, dtype=dtyp)
1434
+ # Use forward recursion to generate the entries.
1435
+ v[0] = x*0 + 1
1436
+ if ideg > 0:
1437
+ x2 = 2*x
1438
+ v[1] = x
1439
+ for i in range(2, ideg + 1):
1440
+ v[i] = v[i-1]*x2 - v[i-2]
1441
+ return np.moveaxis(v, 0, -1)
1442
+
1443
+
1444
+ def chebvander2d(x, y, deg):
1445
+ """Pseudo-Vandermonde matrix of given degrees.
1446
+
1447
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1448
+ points ``(x, y)``. The pseudo-Vandermonde matrix is defined by
1449
+
1450
+ .. math:: V[..., (deg[1] + 1)*i + j] = T_i(x) * T_j(y),
1451
+
1452
+ where ``0 <= i <= deg[0]`` and ``0 <= j <= deg[1]``. The leading indices of
1453
+ `V` index the points ``(x, y)`` and the last index encodes the degrees of
1454
+ the Chebyshev polynomials.
1455
+
1456
+ If ``V = chebvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`
1457
+ correspond to the elements of a 2-D coefficient array `c` of shape
1458
+ (xdeg + 1, ydeg + 1) in the order
1459
+
1460
+ .. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ...
1461
+
1462
+ and ``np.dot(V, c.flat)`` and ``chebval2d(x, y, c)`` will be the same
1463
+ up to roundoff. This equivalence is useful both for least squares
1464
+ fitting and for the evaluation of a large number of 2-D Chebyshev
1465
+ series of the same degrees and sample points.
1466
+
1467
+ Parameters
1468
+ ----------
1469
+ x, y : array_like
1470
+ Arrays of point coordinates, all of the same shape. The dtypes
1471
+ will be converted to either float64 or complex128 depending on
1472
+ whether any of the elements are complex. Scalars are converted to
1473
+ 1-D arrays.
1474
+ deg : list of ints
1475
+ List of maximum degrees of the form [x_deg, y_deg].
1476
+
1477
+ Returns
1478
+ -------
1479
+ vander2d : ndarray
1480
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1481
+ :math:`order = (deg[0]+1)*(deg[1]+1)`. The dtype will be the same
1482
+ as the converted `x` and `y`.
1483
+
1484
+ See Also
1485
+ --------
1486
+ chebvander, chebvander3d, chebval2d, chebval3d
1487
+
1488
+ Notes
1489
+ -----
1490
+
1491
+ .. versionadded:: 1.7.0
1492
+
1493
+ """
1494
+ return pu._vander_nd_flat((chebvander, chebvander), (x, y), deg)
1495
+
1496
+
1497
+ def chebvander3d(x, y, z, deg):
1498
+ """Pseudo-Vandermonde matrix of given degrees.
1499
+
1500
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1501
+ points ``(x, y, z)``. If `l`, `m`, `n` are the given degrees in `x`, `y`, `z`,
1502
+ then The pseudo-Vandermonde matrix is defined by
1503
+
1504
+ .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = T_i(x)*T_j(y)*T_k(z),
1505
+
1506
+ where ``0 <= i <= l``, ``0 <= j <= m``, and ``0 <= j <= n``. The leading
1507
+ indices of `V` index the points ``(x, y, z)`` and the last index encodes
1508
+ the degrees of the Chebyshev polynomials.
1509
+
1510
+ If ``V = chebvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
1511
+ of `V` correspond to the elements of a 3-D coefficient array `c` of
1512
+ shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order
1513
+
1514
+ .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...
1515
+
1516
+ and ``np.dot(V, c.flat)`` and ``chebval3d(x, y, z, c)`` will be the
1517
+ same up to roundoff. This equivalence is useful both for least squares
1518
+ fitting and for the evaluation of a large number of 3-D Chebyshev
1519
+ series of the same degrees and sample points.
1520
+
1521
+ Parameters
1522
+ ----------
1523
+ x, y, z : array_like
1524
+ Arrays of point coordinates, all of the same shape. The dtypes will
1525
+ be converted to either float64 or complex128 depending on whether
1526
+ any of the elements are complex. Scalars are converted to 1-D
1527
+ arrays.
1528
+ deg : list of ints
1529
+ List of maximum degrees of the form [x_deg, y_deg, z_deg].
1530
+
1531
+ Returns
1532
+ -------
1533
+ vander3d : ndarray
1534
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1535
+ :math:`order = (deg[0]+1)*(deg[1]+1)*(deg[2]+1)`. The dtype will
1536
+ be the same as the converted `x`, `y`, and `z`.
1537
+
1538
+ See Also
1539
+ --------
1540
+ chebvander, chebvander3d, chebval2d, chebval3d
1541
+
1542
+ Notes
1543
+ -----
1544
+
1545
+ .. versionadded:: 1.7.0
1546
+
1547
+ """
1548
+ return pu._vander_nd_flat((chebvander, chebvander, chebvander), (x, y, z), deg)
1549
+
1550
+
1551
+ def chebfit(x, y, deg, rcond=None, full=False, w=None):
1552
+ """
1553
+ Least squares fit of Chebyshev series to data.
1554
+
1555
+ Return the coefficients of a Chebyshev series of degree `deg` that is the
1556
+ least squares fit to the data values `y` given at points `x`. If `y` is
1557
+ 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
1558
+ fits are done, one for each column of `y`, and the resulting
1559
+ coefficients are stored in the corresponding columns of a 2-D return.
1560
+ The fitted polynomial(s) are in the form
1561
+
1562
+ .. math:: p(x) = c_0 + c_1 * T_1(x) + ... + c_n * T_n(x),
1563
+
1564
+ where `n` is `deg`.
1565
+
1566
+ Parameters
1567
+ ----------
1568
+ x : array_like, shape (M,)
1569
+ x-coordinates of the M sample points ``(x[i], y[i])``.
1570
+ y : array_like, shape (M,) or (M, K)
1571
+ y-coordinates of the sample points. Several data sets of sample
1572
+ points sharing the same x-coordinates can be fitted at once by
1573
+ passing in a 2D-array that contains one dataset per column.
1574
+ deg : int or 1-D array_like
1575
+ Degree(s) of the fitting polynomials. If `deg` is a single integer,
1576
+ all terms up to and including the `deg`'th term are included in the
1577
+ fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1578
+ degrees of the terms to include may be used instead.
1579
+ rcond : float, optional
1580
+ Relative condition number of the fit. Singular values smaller than
1581
+ this relative to the largest singular value will be ignored. The
1582
+ default value is ``len(x)*eps``, where eps is the relative precision of
1583
+ the float type, about 2e-16 in most cases.
1584
+ full : bool, optional
1585
+ Switch determining nature of return value. When it is False (the
1586
+ default) just the coefficients are returned, when True diagnostic
1587
+ information from the singular value decomposition is also returned.
1588
+ w : array_like, shape (`M`,), optional
1589
+ Weights. If not None, the weight ``w[i]`` applies to the unsquared
1590
+ residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1591
+ chosen so that the errors of the products ``w[i]*y[i]`` all have the
1592
+ same variance. When using inverse-variance weighting, use
1593
+ ``w[i] = 1/sigma(y[i])``. The default value is None.
1594
+
1595
+ .. versionadded:: 1.5.0
1596
+
1597
+ Returns
1598
+ -------
1599
+ coef : ndarray, shape (M,) or (M, K)
1600
+ Chebyshev coefficients ordered from low to high. If `y` was 2-D,
1601
+ the coefficients for the data in column k of `y` are in column
1602
+ `k`.
1603
+
1604
+ [residuals, rank, singular_values, rcond] : list
1605
+ These values are only returned if ``full == True``
1606
+
1607
+ - residuals -- sum of squared residuals of the least squares fit
1608
+ - rank -- the numerical rank of the scaled Vandermonde matrix
1609
+ - singular_values -- singular values of the scaled Vandermonde matrix
1610
+ - rcond -- value of `rcond`.
1611
+
1612
+ For more details, see `numpy.linalg.lstsq`.
1613
+
1614
+ Warns
1615
+ -----
1616
+ RankWarning
1617
+ The rank of the coefficient matrix in the least-squares fit is
1618
+ deficient. The warning is only raised if ``full == False``. The
1619
+ warnings can be turned off by
1620
+
1621
+ >>> import warnings
1622
+ >>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
1623
+
1624
+ See Also
1625
+ --------
1626
+ numpy.polynomial.polynomial.polyfit
1627
+ numpy.polynomial.legendre.legfit
1628
+ numpy.polynomial.laguerre.lagfit
1629
+ numpy.polynomial.hermite.hermfit
1630
+ numpy.polynomial.hermite_e.hermefit
1631
+ chebval : Evaluates a Chebyshev series.
1632
+ chebvander : Vandermonde matrix of Chebyshev series.
1633
+ chebweight : Chebyshev weight function.
1634
+ numpy.linalg.lstsq : Computes a least-squares fit from the matrix.
1635
+ scipy.interpolate.UnivariateSpline : Computes spline fits.
1636
+
1637
+ Notes
1638
+ -----
1639
+ The solution is the coefficients of the Chebyshev series `p` that
1640
+ minimizes the sum of the weighted squared errors
1641
+
1642
+ .. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,
1643
+
1644
+ where :math:`w_j` are the weights. This problem is solved by setting up
1645
+ as the (typically) overdetermined matrix equation
1646
+
1647
+ .. math:: V(x) * c = w * y,
1648
+
1649
+ where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the
1650
+ coefficients to be solved for, `w` are the weights, and `y` are the
1651
+ observed values. This equation is then solved using the singular value
1652
+ decomposition of `V`.
1653
+
1654
+ If some of the singular values of `V` are so small that they are
1655
+ neglected, then a `~exceptions.RankWarning` will be issued. This means that
1656
+ the coefficient values may be poorly determined. Using a lower order fit
1657
+ will usually get rid of the warning. The `rcond` parameter can also be
1658
+ set to a value smaller than its default, but the resulting fit may be
1659
+ spurious and have large contributions from roundoff error.
1660
+
1661
+ Fits using Chebyshev series are usually better conditioned than fits
1662
+ using power series, but much can depend on the distribution of the
1663
+ sample points and the smoothness of the data. If the quality of the fit
1664
+ is inadequate splines may be a good alternative.
1665
+
1666
+ References
1667
+ ----------
1668
+ .. [1] Wikipedia, "Curve fitting",
1669
+ https://en.wikipedia.org/wiki/Curve_fitting
1670
+
1671
+ Examples
1672
+ --------
1673
+
1674
+ """
1675
+ return pu._fit(chebvander, x, y, deg, rcond, full, w)
1676
+
1677
+
1678
+ def chebcompanion(c):
1679
+ """Return the scaled companion matrix of c.
1680
+
1681
+ The basis polynomials are scaled so that the companion matrix is
1682
+ symmetric when `c` is a Chebyshev basis polynomial. This provides
1683
+ better eigenvalue estimates than the unscaled case and for basis
1684
+ polynomials the eigenvalues are guaranteed to be real if
1685
+ `numpy.linalg.eigvalsh` is used to obtain them.
1686
+
1687
+ Parameters
1688
+ ----------
1689
+ c : array_like
1690
+ 1-D array of Chebyshev series coefficients ordered from low to high
1691
+ degree.
1692
+
1693
+ Returns
1694
+ -------
1695
+ mat : ndarray
1696
+ Scaled companion matrix of dimensions (deg, deg).
1697
+
1698
+ Notes
1699
+ -----
1700
+
1701
+ .. versionadded:: 1.7.0
1702
+
1703
+ """
1704
+ # c is a trimmed copy
1705
+ [c] = pu.as_series([c])
1706
+ if len(c) < 2:
1707
+ raise ValueError('Series must have maximum degree of at least 1.')
1708
+ if len(c) == 2:
1709
+ return np.array([[-c[0]/c[1]]])
1710
+
1711
+ n = len(c) - 1
1712
+ mat = np.zeros((n, n), dtype=c.dtype)
1713
+ scl = np.array([1.] + [np.sqrt(.5)]*(n-1))
1714
+ top = mat.reshape(-1)[1::n+1]
1715
+ bot = mat.reshape(-1)[n::n+1]
1716
+ top[0] = np.sqrt(.5)
1717
+ top[1:] = 1/2
1718
+ bot[...] = top
1719
+ mat[:, -1] -= (c[:-1]/c[-1])*(scl/scl[-1])*.5
1720
+ return mat
1721
+
1722
+
1723
+ def chebroots(c):
1724
+ """
1725
+ Compute the roots of a Chebyshev series.
1726
+
1727
+ Return the roots (a.k.a. "zeros") of the polynomial
1728
+
1729
+ .. math:: p(x) = \\sum_i c[i] * T_i(x).
1730
+
1731
+ Parameters
1732
+ ----------
1733
+ c : 1-D array_like
1734
+ 1-D array of coefficients.
1735
+
1736
+ Returns
1737
+ -------
1738
+ out : ndarray
1739
+ Array of the roots of the series. If all the roots are real,
1740
+ then `out` is also real, otherwise it is complex.
1741
+
1742
+ See Also
1743
+ --------
1744
+ numpy.polynomial.polynomial.polyroots
1745
+ numpy.polynomial.legendre.legroots
1746
+ numpy.polynomial.laguerre.lagroots
1747
+ numpy.polynomial.hermite.hermroots
1748
+ numpy.polynomial.hermite_e.hermeroots
1749
+
1750
+ Notes
1751
+ -----
1752
+ The root estimates are obtained as the eigenvalues of the companion
1753
+ matrix, Roots far from the origin of the complex plane may have large
1754
+ errors due to the numerical instability of the series for such
1755
+ values. Roots with multiplicity greater than 1 will also show larger
1756
+ errors as the value of the series near such points is relatively
1757
+ insensitive to errors in the roots. Isolated roots near the origin can
1758
+ be improved by a few iterations of Newton's method.
1759
+
1760
+ The Chebyshev series basis polynomials aren't powers of `x` so the
1761
+ results of this function may seem unintuitive.
1762
+
1763
+ Examples
1764
+ --------
1765
+ >>> import numpy.polynomial.chebyshev as cheb
1766
+ >>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
1767
+ array([ -5.00000000e-01, 2.60860684e-17, 1.00000000e+00]) # may vary
1768
+
1769
+ """
1770
+ # c is a trimmed copy
1771
+ [c] = pu.as_series([c])
1772
+ if len(c) < 2:
1773
+ return np.array([], dtype=c.dtype)
1774
+ if len(c) == 2:
1775
+ return np.array([-c[0]/c[1]])
1776
+
1777
+ # rotated companion matrix reduces error
1778
+ m = chebcompanion(c)[::-1,::-1]
1779
+ r = la.eigvals(m)
1780
+ r.sort()
1781
+ return r
1782
+
1783
+
1784
+ def chebinterpolate(func, deg, args=()):
1785
+ """Interpolate a function at the Chebyshev points of the first kind.
1786
+
1787
+ Returns the Chebyshev series that interpolates `func` at the Chebyshev
1788
+ points of the first kind in the interval [-1, 1]. The interpolating
1789
+ series tends to a minmax approximation to `func` with increasing `deg`
1790
+ if the function is continuous in the interval.
1791
+
1792
+ .. versionadded:: 1.14.0
1793
+
1794
+ Parameters
1795
+ ----------
1796
+ func : function
1797
+ The function to be approximated. It must be a function of a single
1798
+ variable of the form ``f(x, a, b, c...)``, where ``a, b, c...`` are
1799
+ extra arguments passed in the `args` parameter.
1800
+ deg : int
1801
+ Degree of the interpolating polynomial
1802
+ args : tuple, optional
1803
+ Extra arguments to be used in the function call. Default is no extra
1804
+ arguments.
1805
+
1806
+ Returns
1807
+ -------
1808
+ coef : ndarray, shape (deg + 1,)
1809
+ Chebyshev coefficients of the interpolating series ordered from low to
1810
+ high.
1811
+
1812
+ Examples
1813
+ --------
1814
+ >>> import numpy.polynomial.chebyshev as C
1815
+ >>> C.chebinterpolate(lambda x: np.tanh(x) + 0.5, 8)
1816
+ array([ 5.00000000e-01, 8.11675684e-01, -9.86864911e-17,
1817
+ -5.42457905e-02, -2.71387850e-16, 4.51658839e-03,
1818
+ 2.46716228e-17, -3.79694221e-04, -3.26899002e-16])
1819
+
1820
+ Notes
1821
+ -----
1822
+
1823
+ The Chebyshev polynomials used in the interpolation are orthogonal when
1824
+ sampled at the Chebyshev points of the first kind. If it is desired to
1825
+ constrain some of the coefficients they can simply be set to the desired
1826
+ value after the interpolation, no new interpolation or fit is needed. This
1827
+ is especially useful if it is known apriori that some of coefficients are
1828
+ zero. For instance, if the function is even then the coefficients of the
1829
+ terms of odd degree in the result can be set to zero.
1830
+
1831
+ """
1832
+ deg = np.asarray(deg)
1833
+
1834
+ # check arguments.
1835
+ if deg.ndim > 0 or deg.dtype.kind not in 'iu' or deg.size == 0:
1836
+ raise TypeError("deg must be an int")
1837
+ if deg < 0:
1838
+ raise ValueError("expected deg >= 0")
1839
+
1840
+ order = deg + 1
1841
+ xcheb = chebpts1(order)
1842
+ yfunc = func(xcheb, *args)
1843
+ m = chebvander(xcheb, deg)
1844
+ c = np.dot(m.T, yfunc)
1845
+ c[0] /= order
1846
+ c[1:] /= 0.5*order
1847
+
1848
+ return c
1849
+
1850
+
1851
+ def chebgauss(deg):
1852
+ """
1853
+ Gauss-Chebyshev quadrature.
1854
+
1855
+ Computes the sample points and weights for Gauss-Chebyshev quadrature.
1856
+ These sample points and weights will correctly integrate polynomials of
1857
+ degree :math:`2*deg - 1` or less over the interval :math:`[-1, 1]` with
1858
+ the weight function :math:`f(x) = 1/\\sqrt{1 - x^2}`.
1859
+
1860
+ Parameters
1861
+ ----------
1862
+ deg : int
1863
+ Number of sample points and weights. It must be >= 1.
1864
+
1865
+ Returns
1866
+ -------
1867
+ x : ndarray
1868
+ 1-D ndarray containing the sample points.
1869
+ y : ndarray
1870
+ 1-D ndarray containing the weights.
1871
+
1872
+ Notes
1873
+ -----
1874
+
1875
+ .. versionadded:: 1.7.0
1876
+
1877
+ The results have only been tested up to degree 100, higher degrees may
1878
+ be problematic. For Gauss-Chebyshev there are closed form solutions for
1879
+ the sample points and weights. If n = `deg`, then
1880
+
1881
+ .. math:: x_i = \\cos(\\pi (2 i - 1) / (2 n))
1882
+
1883
+ .. math:: w_i = \\pi / n
1884
+
1885
+ """
1886
+ ideg = pu._as_int(deg, "deg")
1887
+ if ideg <= 0:
1888
+ raise ValueError("deg must be a positive integer")
1889
+
1890
+ x = np.cos(np.pi * np.arange(1, 2*ideg, 2) / (2.0*ideg))
1891
+ w = np.ones(ideg)*(np.pi/ideg)
1892
+
1893
+ return x, w
1894
+
1895
+
1896
+ def chebweight(x):
1897
+ """
1898
+ The weight function of the Chebyshev polynomials.
1899
+
1900
+ The weight function is :math:`1/\\sqrt{1 - x^2}` and the interval of
1901
+ integration is :math:`[-1, 1]`. The Chebyshev polynomials are
1902
+ orthogonal, but not normalized, with respect to this weight function.
1903
+
1904
+ Parameters
1905
+ ----------
1906
+ x : array_like
1907
+ Values at which the weight function will be computed.
1908
+
1909
+ Returns
1910
+ -------
1911
+ w : ndarray
1912
+ The weight function at `x`.
1913
+
1914
+ Notes
1915
+ -----
1916
+
1917
+ .. versionadded:: 1.7.0
1918
+
1919
+ """
1920
+ w = 1./(np.sqrt(1. + x) * np.sqrt(1. - x))
1921
+ return w
1922
+
1923
+
1924
+ def chebpts1(npts):
1925
+ """
1926
+ Chebyshev points of the first kind.
1927
+
1928
+ The Chebyshev points of the first kind are the points ``cos(x)``,
1929
+ where ``x = [pi*(k + .5)/npts for k in range(npts)]``.
1930
+
1931
+ Parameters
1932
+ ----------
1933
+ npts : int
1934
+ Number of sample points desired.
1935
+
1936
+ Returns
1937
+ -------
1938
+ pts : ndarray
1939
+ The Chebyshev points of the first kind.
1940
+
1941
+ See Also
1942
+ --------
1943
+ chebpts2
1944
+
1945
+ Notes
1946
+ -----
1947
+
1948
+ .. versionadded:: 1.5.0
1949
+
1950
+ """
1951
+ _npts = int(npts)
1952
+ if _npts != npts:
1953
+ raise ValueError("npts must be integer")
1954
+ if _npts < 1:
1955
+ raise ValueError("npts must be >= 1")
1956
+
1957
+ x = 0.5 * np.pi / _npts * np.arange(-_npts+1, _npts+1, 2)
1958
+ return np.sin(x)
1959
+
1960
+
1961
+ def chebpts2(npts):
1962
+ """
1963
+ Chebyshev points of the second kind.
1964
+
1965
+ The Chebyshev points of the second kind are the points ``cos(x)``,
1966
+ where ``x = [pi*k/(npts - 1) for k in range(npts)]`` sorted in ascending
1967
+ order.
1968
+
1969
+ Parameters
1970
+ ----------
1971
+ npts : int
1972
+ Number of sample points desired.
1973
+
1974
+ Returns
1975
+ -------
1976
+ pts : ndarray
1977
+ The Chebyshev points of the second kind.
1978
+
1979
+ Notes
1980
+ -----
1981
+
1982
+ .. versionadded:: 1.5.0
1983
+
1984
+ """
1985
+ _npts = int(npts)
1986
+ if _npts != npts:
1987
+ raise ValueError("npts must be integer")
1988
+ if _npts < 2:
1989
+ raise ValueError("npts must be >= 2")
1990
+
1991
+ x = np.linspace(-np.pi, 0, _npts)
1992
+ return np.cos(x)
1993
+
1994
+
1995
+ #
1996
+ # Chebyshev series class
1997
+ #
1998
+
1999
+ class Chebyshev(ABCPolyBase):
2000
+ """A Chebyshev series class.
2001
+
2002
+ The Chebyshev class provides the standard Python numerical methods
2003
+ '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the
2004
+ attributes and methods listed below.
2005
+
2006
+ Parameters
2007
+ ----------
2008
+ coef : array_like
2009
+ Chebyshev coefficients in order of increasing degree, i.e.,
2010
+ ``(1, 2, 3)`` gives ``1*T_0(x) + 2*T_1(x) + 3*T_2(x)``.
2011
+ domain : (2,) array_like, optional
2012
+ Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
2013
+ to the interval ``[window[0], window[1]]`` by shifting and scaling.
2014
+ The default value is [-1., 1.].
2015
+ window : (2,) array_like, optional
2016
+ Window, see `domain` for its use. The default value is [-1., 1.].
2017
+
2018
+ .. versionadded:: 1.6.0
2019
+ symbol : str, optional
2020
+ Symbol used to represent the independent variable in string
2021
+ representations of the polynomial expression, e.g. for printing.
2022
+ The symbol must be a valid Python identifier. Default value is 'x'.
2023
+
2024
+ .. versionadded:: 1.24
2025
+
2026
+ """
2027
+ # Virtual Functions
2028
+ _add = staticmethod(chebadd)
2029
+ _sub = staticmethod(chebsub)
2030
+ _mul = staticmethod(chebmul)
2031
+ _div = staticmethod(chebdiv)
2032
+ _pow = staticmethod(chebpow)
2033
+ _val = staticmethod(chebval)
2034
+ _int = staticmethod(chebint)
2035
+ _der = staticmethod(chebder)
2036
+ _fit = staticmethod(chebfit)
2037
+ _line = staticmethod(chebline)
2038
+ _roots = staticmethod(chebroots)
2039
+ _fromroots = staticmethod(chebfromroots)
2040
+
2041
+ @classmethod
2042
+ def interpolate(cls, func, deg, domain=None, args=()):
2043
+ """Interpolate a function at the Chebyshev points of the first kind.
2044
+
2045
+ Returns the series that interpolates `func` at the Chebyshev points of
2046
+ the first kind scaled and shifted to the `domain`. The resulting series
2047
+ tends to a minmax approximation of `func` when the function is
2048
+ continuous in the domain.
2049
+
2050
+ .. versionadded:: 1.14.0
2051
+
2052
+ Parameters
2053
+ ----------
2054
+ func : function
2055
+ The function to be interpolated. It must be a function of a single
2056
+ variable of the form ``f(x, a, b, c...)``, where ``a, b, c...`` are
2057
+ extra arguments passed in the `args` parameter.
2058
+ deg : int
2059
+ Degree of the interpolating polynomial.
2060
+ domain : {None, [beg, end]}, optional
2061
+ Domain over which `func` is interpolated. The default is None, in
2062
+ which case the domain is [-1, 1].
2063
+ args : tuple, optional
2064
+ Extra arguments to be used in the function call. Default is no
2065
+ extra arguments.
2066
+
2067
+ Returns
2068
+ -------
2069
+ polynomial : Chebyshev instance
2070
+ Interpolating Chebyshev instance.
2071
+
2072
+ Notes
2073
+ -----
2074
+ See `numpy.polynomial.chebinterpolate` for more details.
2075
+
2076
+ """
2077
+ if domain is None:
2078
+ domain = cls.domain
2079
+ xfunc = lambda x: func(pu.mapdomain(x, cls.window, domain), *args)
2080
+ coef = chebinterpolate(xfunc, deg)
2081
+ return cls(coef, domain=domain)
2082
+
2083
+ # Virtual properties
2084
+ domain = np.array(chebdomain)
2085
+ window = np.array(chebdomain)
2086
+ basis_name = 'T'
parrot/lib/python3.10/site-packages/numpy/polynomial/chebyshev.pyi ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections.abc import Callable, Iterable
2
+ from typing import (
3
+ Any,
4
+ Concatenate,
5
+ Final,
6
+ Literal as L,
7
+ TypeVar,
8
+ overload,
9
+ )
10
+
11
+ import numpy as np
12
+ import numpy.typing as npt
13
+ from numpy._typing import _IntLike_co
14
+
15
+ from ._polybase import ABCPolyBase
16
+ from ._polytypes import (
17
+ _SeriesLikeCoef_co,
18
+ _Array1,
19
+ _Series,
20
+ _Array2,
21
+ _CoefSeries,
22
+ _FuncBinOp,
23
+ _FuncCompanion,
24
+ _FuncDer,
25
+ _FuncFit,
26
+ _FuncFromRoots,
27
+ _FuncGauss,
28
+ _FuncInteg,
29
+ _FuncLine,
30
+ _FuncPoly2Ortho,
31
+ _FuncPow,
32
+ _FuncPts,
33
+ _FuncRoots,
34
+ _FuncUnOp,
35
+ _FuncVal,
36
+ _FuncVal2D,
37
+ _FuncVal3D,
38
+ _FuncValFromRoots,
39
+ _FuncVander,
40
+ _FuncVander2D,
41
+ _FuncVander3D,
42
+ _FuncWeight,
43
+ )
44
+ from .polyutils import trimcoef as chebtrim
45
+
46
+ __all__ = [
47
+ "chebzero",
48
+ "chebone",
49
+ "chebx",
50
+ "chebdomain",
51
+ "chebline",
52
+ "chebadd",
53
+ "chebsub",
54
+ "chebmulx",
55
+ "chebmul",
56
+ "chebdiv",
57
+ "chebpow",
58
+ "chebval",
59
+ "chebder",
60
+ "chebint",
61
+ "cheb2poly",
62
+ "poly2cheb",
63
+ "chebfromroots",
64
+ "chebvander",
65
+ "chebfit",
66
+ "chebtrim",
67
+ "chebroots",
68
+ "chebpts1",
69
+ "chebpts2",
70
+ "Chebyshev",
71
+ "chebval2d",
72
+ "chebval3d",
73
+ "chebgrid2d",
74
+ "chebgrid3d",
75
+ "chebvander2d",
76
+ "chebvander3d",
77
+ "chebcompanion",
78
+ "chebgauss",
79
+ "chebweight",
80
+ "chebinterpolate",
81
+ ]
82
+
83
+ _SCT = TypeVar("_SCT", bound=np.number[Any] | np.object_)
84
+ def _cseries_to_zseries(c: npt.NDArray[_SCT]) -> _Series[_SCT]: ...
85
+ def _zseries_to_cseries(zs: npt.NDArray[_SCT]) -> _Series[_SCT]: ...
86
+ def _zseries_mul(
87
+ z1: npt.NDArray[_SCT],
88
+ z2: npt.NDArray[_SCT],
89
+ ) -> _Series[_SCT]: ...
90
+ def _zseries_div(
91
+ z1: npt.NDArray[_SCT],
92
+ z2: npt.NDArray[_SCT],
93
+ ) -> _Series[_SCT]: ...
94
+ def _zseries_der(zs: npt.NDArray[_SCT]) -> _Series[_SCT]: ...
95
+ def _zseries_int(zs: npt.NDArray[_SCT]) -> _Series[_SCT]: ...
96
+
97
+ poly2cheb: _FuncPoly2Ortho[L["poly2cheb"]]
98
+ cheb2poly: _FuncUnOp[L["cheb2poly"]]
99
+
100
+ chebdomain: Final[_Array2[np.float64]]
101
+ chebzero: Final[_Array1[np.int_]]
102
+ chebone: Final[_Array1[np.int_]]
103
+ chebx: Final[_Array2[np.int_]]
104
+
105
+ chebline: _FuncLine[L["chebline"]]
106
+ chebfromroots: _FuncFromRoots[L["chebfromroots"]]
107
+ chebadd: _FuncBinOp[L["chebadd"]]
108
+ chebsub: _FuncBinOp[L["chebsub"]]
109
+ chebmulx: _FuncUnOp[L["chebmulx"]]
110
+ chebmul: _FuncBinOp[L["chebmul"]]
111
+ chebdiv: _FuncBinOp[L["chebdiv"]]
112
+ chebpow: _FuncPow[L["chebpow"]]
113
+ chebder: _FuncDer[L["chebder"]]
114
+ chebint: _FuncInteg[L["chebint"]]
115
+ chebval: _FuncVal[L["chebval"]]
116
+ chebval2d: _FuncVal2D[L["chebval2d"]]
117
+ chebval3d: _FuncVal3D[L["chebval3d"]]
118
+ chebvalfromroots: _FuncValFromRoots[L["chebvalfromroots"]]
119
+ chebgrid2d: _FuncVal2D[L["chebgrid2d"]]
120
+ chebgrid3d: _FuncVal3D[L["chebgrid3d"]]
121
+ chebvander: _FuncVander[L["chebvander"]]
122
+ chebvander2d: _FuncVander2D[L["chebvander2d"]]
123
+ chebvander3d: _FuncVander3D[L["chebvander3d"]]
124
+ chebfit: _FuncFit[L["chebfit"]]
125
+ chebcompanion: _FuncCompanion[L["chebcompanion"]]
126
+ chebroots: _FuncRoots[L["chebroots"]]
127
+ chebgauss: _FuncGauss[L["chebgauss"]]
128
+ chebweight: _FuncWeight[L["chebweight"]]
129
+ chebpts1: _FuncPts[L["chebpts1"]]
130
+ chebpts2: _FuncPts[L["chebpts2"]]
131
+
132
+ # keep in sync with `Chebyshev.interpolate`
133
+ _RT = TypeVar("_RT", bound=np.number[Any] | np.bool | np.object_)
134
+ @overload
135
+ def chebinterpolate(
136
+ func: np.ufunc,
137
+ deg: _IntLike_co,
138
+ args: tuple[()] = ...,
139
+ ) -> npt.NDArray[np.float64 | np.complex128 | np.object_]: ...
140
+ @overload
141
+ def chebinterpolate(
142
+ func: Callable[[npt.NDArray[np.float64]], _RT],
143
+ deg: _IntLike_co,
144
+ args: tuple[()] = ...,
145
+ ) -> npt.NDArray[_RT]: ...
146
+ @overload
147
+ def chebinterpolate(
148
+ func: Callable[Concatenate[npt.NDArray[np.float64], ...], _RT],
149
+ deg: _IntLike_co,
150
+ args: Iterable[Any],
151
+ ) -> npt.NDArray[_RT]: ...
152
+
153
+ _Self = TypeVar("_Self", bound=object)
154
+
155
+ class Chebyshev(ABCPolyBase[L["T"]]):
156
+ @overload
157
+ @classmethod
158
+ def interpolate(
159
+ cls: type[_Self],
160
+ /,
161
+ func: Callable[[npt.NDArray[np.float64]], _CoefSeries],
162
+ deg: _IntLike_co,
163
+ domain: None | _SeriesLikeCoef_co = ...,
164
+ args: tuple[()] = ...,
165
+ ) -> _Self: ...
166
+ @overload
167
+ @classmethod
168
+ def interpolate(
169
+ cls: type[_Self],
170
+ /,
171
+ func: Callable[
172
+ Concatenate[npt.NDArray[np.float64], ...],
173
+ _CoefSeries,
174
+ ],
175
+ deg: _IntLike_co,
176
+ domain: None | _SeriesLikeCoef_co = ...,
177
+ *,
178
+ args: Iterable[Any],
179
+ ) -> _Self: ...
180
+ @overload
181
+ @classmethod
182
+ def interpolate(
183
+ cls: type[_Self],
184
+ func: Callable[
185
+ Concatenate[npt.NDArray[np.float64], ...],
186
+ _CoefSeries,
187
+ ],
188
+ deg: _IntLike_co,
189
+ domain: None | _SeriesLikeCoef_co,
190
+ args: Iterable[Any],
191
+ /,
192
+ ) -> _Self: ...
parrot/lib/python3.10/site-packages/numpy/polynomial/hermite.py ADDED
@@ -0,0 +1,1793 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==============================================================
3
+ Hermite Series, "Physicists" (:mod:`numpy.polynomial.hermite`)
4
+ ==============================================================
5
+
6
+ This module provides a number of objects (mostly functions) useful for
7
+ dealing with Hermite series, including a `Hermite` class that
8
+ encapsulates the usual arithmetic operations. (General information
9
+ on how this module represents and works with such polynomials is in the
10
+ docstring for its "parent" sub-package, `numpy.polynomial`).
11
+
12
+ Classes
13
+ -------
14
+ .. autosummary::
15
+ :toctree: generated/
16
+
17
+ Hermite
18
+
19
+ Constants
20
+ ---------
21
+ .. autosummary::
22
+ :toctree: generated/
23
+
24
+ hermdomain
25
+ hermzero
26
+ hermone
27
+ hermx
28
+
29
+ Arithmetic
30
+ ----------
31
+ .. autosummary::
32
+ :toctree: generated/
33
+
34
+ hermadd
35
+ hermsub
36
+ hermmulx
37
+ hermmul
38
+ hermdiv
39
+ hermpow
40
+ hermval
41
+ hermval2d
42
+ hermval3d
43
+ hermgrid2d
44
+ hermgrid3d
45
+
46
+ Calculus
47
+ --------
48
+ .. autosummary::
49
+ :toctree: generated/
50
+
51
+ hermder
52
+ hermint
53
+
54
+ Misc Functions
55
+ --------------
56
+ .. autosummary::
57
+ :toctree: generated/
58
+
59
+ hermfromroots
60
+ hermroots
61
+ hermvander
62
+ hermvander2d
63
+ hermvander3d
64
+ hermgauss
65
+ hermweight
66
+ hermcompanion
67
+ hermfit
68
+ hermtrim
69
+ hermline
70
+ herm2poly
71
+ poly2herm
72
+
73
+ See also
74
+ --------
75
+ `numpy.polynomial`
76
+
77
+ """
78
+ import numpy as np
79
+ import numpy.linalg as la
80
+ from numpy.lib.array_utils import normalize_axis_index
81
+
82
+ from . import polyutils as pu
83
+ from ._polybase import ABCPolyBase
84
+
85
+ __all__ = [
86
+ 'hermzero', 'hermone', 'hermx', 'hermdomain', 'hermline', 'hermadd',
87
+ 'hermsub', 'hermmulx', 'hermmul', 'hermdiv', 'hermpow', 'hermval',
88
+ 'hermder', 'hermint', 'herm2poly', 'poly2herm', 'hermfromroots',
89
+ 'hermvander', 'hermfit', 'hermtrim', 'hermroots', 'Hermite',
90
+ 'hermval2d', 'hermval3d', 'hermgrid2d', 'hermgrid3d', 'hermvander2d',
91
+ 'hermvander3d', 'hermcompanion', 'hermgauss', 'hermweight']
92
+
93
+ hermtrim = pu.trimcoef
94
+
95
+
96
+ def poly2herm(pol):
97
+ """
98
+ poly2herm(pol)
99
+
100
+ Convert a polynomial to a Hermite series.
101
+
102
+ Convert an array representing the coefficients of a polynomial (relative
103
+ to the "standard" basis) ordered from lowest degree to highest, to an
104
+ array of the coefficients of the equivalent Hermite series, ordered
105
+ from lowest to highest degree.
106
+
107
+ Parameters
108
+ ----------
109
+ pol : array_like
110
+ 1-D array containing the polynomial coefficients
111
+
112
+ Returns
113
+ -------
114
+ c : ndarray
115
+ 1-D array containing the coefficients of the equivalent Hermite
116
+ series.
117
+
118
+ See Also
119
+ --------
120
+ herm2poly
121
+
122
+ Notes
123
+ -----
124
+ The easy way to do conversions between polynomial basis sets
125
+ is to use the convert method of a class instance.
126
+
127
+ Examples
128
+ --------
129
+ >>> from numpy.polynomial.hermite import poly2herm
130
+ >>> poly2herm(np.arange(4))
131
+ array([1. , 2.75 , 0.5 , 0.375])
132
+
133
+ """
134
+ [pol] = pu.as_series([pol])
135
+ deg = len(pol) - 1
136
+ res = 0
137
+ for i in range(deg, -1, -1):
138
+ res = hermadd(hermmulx(res), pol[i])
139
+ return res
140
+
141
+
142
+ def herm2poly(c):
143
+ """
144
+ Convert a Hermite series to a polynomial.
145
+
146
+ Convert an array representing the coefficients of a Hermite series,
147
+ ordered from lowest degree to highest, to an array of the coefficients
148
+ of the equivalent polynomial (relative to the "standard" basis) ordered
149
+ from lowest to highest degree.
150
+
151
+ Parameters
152
+ ----------
153
+ c : array_like
154
+ 1-D array containing the Hermite series coefficients, ordered
155
+ from lowest order term to highest.
156
+
157
+ Returns
158
+ -------
159
+ pol : ndarray
160
+ 1-D array containing the coefficients of the equivalent polynomial
161
+ (relative to the "standard" basis) ordered from lowest order term
162
+ to highest.
163
+
164
+ See Also
165
+ --------
166
+ poly2herm
167
+
168
+ Notes
169
+ -----
170
+ The easy way to do conversions between polynomial basis sets
171
+ is to use the convert method of a class instance.
172
+
173
+ Examples
174
+ --------
175
+ >>> from numpy.polynomial.hermite import herm2poly
176
+ >>> herm2poly([ 1. , 2.75 , 0.5 , 0.375])
177
+ array([0., 1., 2., 3.])
178
+
179
+ """
180
+ from .polynomial import polyadd, polysub, polymulx
181
+
182
+ [c] = pu.as_series([c])
183
+ n = len(c)
184
+ if n == 1:
185
+ return c
186
+ if n == 2:
187
+ c[1] *= 2
188
+ return c
189
+ else:
190
+ c0 = c[-2]
191
+ c1 = c[-1]
192
+ # i is the current degree of c1
193
+ for i in range(n - 1, 1, -1):
194
+ tmp = c0
195
+ c0 = polysub(c[i - 2], c1*(2*(i - 1)))
196
+ c1 = polyadd(tmp, polymulx(c1)*2)
197
+ return polyadd(c0, polymulx(c1)*2)
198
+
199
+
200
+ #
201
+ # These are constant arrays are of integer type so as to be compatible
202
+ # with the widest range of other types, such as Decimal.
203
+ #
204
+
205
+ # Hermite
206
+ hermdomain = np.array([-1., 1.])
207
+
208
+ # Hermite coefficients representing zero.
209
+ hermzero = np.array([0])
210
+
211
+ # Hermite coefficients representing one.
212
+ hermone = np.array([1])
213
+
214
+ # Hermite coefficients representing the identity x.
215
+ hermx = np.array([0, 1/2])
216
+
217
+
218
+ def hermline(off, scl):
219
+ """
220
+ Hermite series whose graph is a straight line.
221
+
222
+
223
+
224
+ Parameters
225
+ ----------
226
+ off, scl : scalars
227
+ The specified line is given by ``off + scl*x``.
228
+
229
+ Returns
230
+ -------
231
+ y : ndarray
232
+ This module's representation of the Hermite series for
233
+ ``off + scl*x``.
234
+
235
+ See Also
236
+ --------
237
+ numpy.polynomial.polynomial.polyline
238
+ numpy.polynomial.chebyshev.chebline
239
+ numpy.polynomial.legendre.legline
240
+ numpy.polynomial.laguerre.lagline
241
+ numpy.polynomial.hermite_e.hermeline
242
+
243
+ Examples
244
+ --------
245
+ >>> from numpy.polynomial.hermite import hermline, hermval
246
+ >>> hermval(0,hermline(3, 2))
247
+ 3.0
248
+ >>> hermval(1,hermline(3, 2))
249
+ 5.0
250
+
251
+ """
252
+ if scl != 0:
253
+ return np.array([off, scl/2])
254
+ else:
255
+ return np.array([off])
256
+
257
+
258
+ def hermfromroots(roots):
259
+ """
260
+ Generate a Hermite series with given roots.
261
+
262
+ The function returns the coefficients of the polynomial
263
+
264
+ .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
265
+
266
+ in Hermite form, where the :math:`r_n` are the roots specified in `roots`.
267
+ If a zero has multiplicity n, then it must appear in `roots` n times.
268
+ For instance, if 2 is a root of multiplicity three and 3 is a root of
269
+ multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3]. The
270
+ roots can appear in any order.
271
+
272
+ If the returned coefficients are `c`, then
273
+
274
+ .. math:: p(x) = c_0 + c_1 * H_1(x) + ... + c_n * H_n(x)
275
+
276
+ The coefficient of the last term is not generally 1 for monic
277
+ polynomials in Hermite form.
278
+
279
+ Parameters
280
+ ----------
281
+ roots : array_like
282
+ Sequence containing the roots.
283
+
284
+ Returns
285
+ -------
286
+ out : ndarray
287
+ 1-D array of coefficients. If all roots are real then `out` is a
288
+ real array, if some of the roots are complex, then `out` is complex
289
+ even if all the coefficients in the result are real (see Examples
290
+ below).
291
+
292
+ See Also
293
+ --------
294
+ numpy.polynomial.polynomial.polyfromroots
295
+ numpy.polynomial.legendre.legfromroots
296
+ numpy.polynomial.laguerre.lagfromroots
297
+ numpy.polynomial.chebyshev.chebfromroots
298
+ numpy.polynomial.hermite_e.hermefromroots
299
+
300
+ Examples
301
+ --------
302
+ >>> from numpy.polynomial.hermite import hermfromroots, hermval
303
+ >>> coef = hermfromroots((-1, 0, 1))
304
+ >>> hermval((-1, 0, 1), coef)
305
+ array([0., 0., 0.])
306
+ >>> coef = hermfromroots((-1j, 1j))
307
+ >>> hermval((-1j, 1j), coef)
308
+ array([0.+0.j, 0.+0.j])
309
+
310
+ """
311
+ return pu._fromroots(hermline, hermmul, roots)
312
+
313
+
314
+ def hermadd(c1, c2):
315
+ """
316
+ Add one Hermite series to another.
317
+
318
+ Returns the sum of two Hermite series `c1` + `c2`. The arguments
319
+ are sequences of coefficients ordered from lowest order term to
320
+ highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
321
+
322
+ Parameters
323
+ ----------
324
+ c1, c2 : array_like
325
+ 1-D arrays of Hermite series coefficients ordered from low to
326
+ high.
327
+
328
+ Returns
329
+ -------
330
+ out : ndarray
331
+ Array representing the Hermite series of their sum.
332
+
333
+ See Also
334
+ --------
335
+ hermsub, hermmulx, hermmul, hermdiv, hermpow
336
+
337
+ Notes
338
+ -----
339
+ Unlike multiplication, division, etc., the sum of two Hermite series
340
+ is a Hermite series (without having to "reproject" the result onto
341
+ the basis set) so addition, just like that of "standard" polynomials,
342
+ is simply "component-wise."
343
+
344
+ Examples
345
+ --------
346
+ >>> from numpy.polynomial.hermite import hermadd
347
+ >>> hermadd([1, 2, 3], [1, 2, 3, 4])
348
+ array([2., 4., 6., 4.])
349
+
350
+ """
351
+ return pu._add(c1, c2)
352
+
353
+
354
+ def hermsub(c1, c2):
355
+ """
356
+ Subtract one Hermite series from another.
357
+
358
+ Returns the difference of two Hermite series `c1` - `c2`. The
359
+ sequences of coefficients are from lowest order term to highest, i.e.,
360
+ [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
361
+
362
+ Parameters
363
+ ----------
364
+ c1, c2 : array_like
365
+ 1-D arrays of Hermite series coefficients ordered from low to
366
+ high.
367
+
368
+ Returns
369
+ -------
370
+ out : ndarray
371
+ Of Hermite series coefficients representing their difference.
372
+
373
+ See Also
374
+ --------
375
+ hermadd, hermmulx, hermmul, hermdiv, hermpow
376
+
377
+ Notes
378
+ -----
379
+ Unlike multiplication, division, etc., the difference of two Hermite
380
+ series is a Hermite series (without having to "reproject" the result
381
+ onto the basis set) so subtraction, just like that of "standard"
382
+ polynomials, is simply "component-wise."
383
+
384
+ Examples
385
+ --------
386
+ >>> from numpy.polynomial.hermite import hermsub
387
+ >>> hermsub([1, 2, 3, 4], [1, 2, 3])
388
+ array([0., 0., 0., 4.])
389
+
390
+ """
391
+ return pu._sub(c1, c2)
392
+
393
+
394
+ def hermmulx(c):
395
+ """Multiply a Hermite series by x.
396
+
397
+ Multiply the Hermite series `c` by x, where x is the independent
398
+ variable.
399
+
400
+
401
+ Parameters
402
+ ----------
403
+ c : array_like
404
+ 1-D array of Hermite series coefficients ordered from low to
405
+ high.
406
+
407
+ Returns
408
+ -------
409
+ out : ndarray
410
+ Array representing the result of the multiplication.
411
+
412
+ See Also
413
+ --------
414
+ hermadd, hermsub, hermmul, hermdiv, hermpow
415
+
416
+ Notes
417
+ -----
418
+ The multiplication uses the recursion relationship for Hermite
419
+ polynomials in the form
420
+
421
+ .. math::
422
+
423
+ xP_i(x) = (P_{i + 1}(x)/2 + i*P_{i - 1}(x))
424
+
425
+ Examples
426
+ --------
427
+ >>> from numpy.polynomial.hermite import hermmulx
428
+ >>> hermmulx([1, 2, 3])
429
+ array([2. , 6.5, 1. , 1.5])
430
+
431
+ """
432
+ # c is a trimmed copy
433
+ [c] = pu.as_series([c])
434
+ # The zero series needs special treatment
435
+ if len(c) == 1 and c[0] == 0:
436
+ return c
437
+
438
+ prd = np.empty(len(c) + 1, dtype=c.dtype)
439
+ prd[0] = c[0]*0
440
+ prd[1] = c[0]/2
441
+ for i in range(1, len(c)):
442
+ prd[i + 1] = c[i]/2
443
+ prd[i - 1] += c[i]*i
444
+ return prd
445
+
446
+
447
+ def hermmul(c1, c2):
448
+ """
449
+ Multiply one Hermite series by another.
450
+
451
+ Returns the product of two Hermite series `c1` * `c2`. The arguments
452
+ are sequences of coefficients, from lowest order "term" to highest,
453
+ e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
454
+
455
+ Parameters
456
+ ----------
457
+ c1, c2 : array_like
458
+ 1-D arrays of Hermite series coefficients ordered from low to
459
+ high.
460
+
461
+ Returns
462
+ -------
463
+ out : ndarray
464
+ Of Hermite series coefficients representing their product.
465
+
466
+ See Also
467
+ --------
468
+ hermadd, hermsub, hermmulx, hermdiv, hermpow
469
+
470
+ Notes
471
+ -----
472
+ In general, the (polynomial) product of two C-series results in terms
473
+ that are not in the Hermite polynomial basis set. Thus, to express
474
+ the product as a Hermite series, it is necessary to "reproject" the
475
+ product onto said basis set, which may produce "unintuitive" (but
476
+ correct) results; see Examples section below.
477
+
478
+ Examples
479
+ --------
480
+ >>> from numpy.polynomial.hermite import hermmul
481
+ >>> hermmul([1, 2, 3], [0, 1, 2])
482
+ array([52., 29., 52., 7., 6.])
483
+
484
+ """
485
+ # s1, s2 are trimmed copies
486
+ [c1, c2] = pu.as_series([c1, c2])
487
+
488
+ if len(c1) > len(c2):
489
+ c = c2
490
+ xs = c1
491
+ else:
492
+ c = c1
493
+ xs = c2
494
+
495
+ if len(c) == 1:
496
+ c0 = c[0]*xs
497
+ c1 = 0
498
+ elif len(c) == 2:
499
+ c0 = c[0]*xs
500
+ c1 = c[1]*xs
501
+ else:
502
+ nd = len(c)
503
+ c0 = c[-2]*xs
504
+ c1 = c[-1]*xs
505
+ for i in range(3, len(c) + 1):
506
+ tmp = c0
507
+ nd = nd - 1
508
+ c0 = hermsub(c[-i]*xs, c1*(2*(nd - 1)))
509
+ c1 = hermadd(tmp, hermmulx(c1)*2)
510
+ return hermadd(c0, hermmulx(c1)*2)
511
+
512
+
513
+ def hermdiv(c1, c2):
514
+ """
515
+ Divide one Hermite series by another.
516
+
517
+ Returns the quotient-with-remainder of two Hermite series
518
+ `c1` / `c2`. The arguments are sequences of coefficients from lowest
519
+ order "term" to highest, e.g., [1,2,3] represents the series
520
+ ``P_0 + 2*P_1 + 3*P_2``.
521
+
522
+ Parameters
523
+ ----------
524
+ c1, c2 : array_like
525
+ 1-D arrays of Hermite series coefficients ordered from low to
526
+ high.
527
+
528
+ Returns
529
+ -------
530
+ [quo, rem] : ndarrays
531
+ Of Hermite series coefficients representing the quotient and
532
+ remainder.
533
+
534
+ See Also
535
+ --------
536
+ hermadd, hermsub, hermmulx, hermmul, hermpow
537
+
538
+ Notes
539
+ -----
540
+ In general, the (polynomial) division of one Hermite series by another
541
+ results in quotient and remainder terms that are not in the Hermite
542
+ polynomial basis set. Thus, to express these results as a Hermite
543
+ series, it is necessary to "reproject" the results onto the Hermite
544
+ basis set, which may produce "unintuitive" (but correct) results; see
545
+ Examples section below.
546
+
547
+ Examples
548
+ --------
549
+ >>> from numpy.polynomial.hermite import hermdiv
550
+ >>> hermdiv([ 52., 29., 52., 7., 6.], [0, 1, 2])
551
+ (array([1., 2., 3.]), array([0.]))
552
+ >>> hermdiv([ 54., 31., 52., 7., 6.], [0, 1, 2])
553
+ (array([1., 2., 3.]), array([2., 2.]))
554
+ >>> hermdiv([ 53., 30., 52., 7., 6.], [0, 1, 2])
555
+ (array([1., 2., 3.]), array([1., 1.]))
556
+
557
+ """
558
+ return pu._div(hermmul, c1, c2)
559
+
560
+
561
+ def hermpow(c, pow, maxpower=16):
562
+ """Raise a Hermite series to a power.
563
+
564
+ Returns the Hermite series `c` raised to the power `pow`. The
565
+ argument `c` is a sequence of coefficients ordered from low to high.
566
+ i.e., [1,2,3] is the series ``P_0 + 2*P_1 + 3*P_2.``
567
+
568
+ Parameters
569
+ ----------
570
+ c : array_like
571
+ 1-D array of Hermite series coefficients ordered from low to
572
+ high.
573
+ pow : integer
574
+ Power to which the series will be raised
575
+ maxpower : integer, optional
576
+ Maximum power allowed. This is mainly to limit growth of the series
577
+ to unmanageable size. Default is 16
578
+
579
+ Returns
580
+ -------
581
+ coef : ndarray
582
+ Hermite series of power.
583
+
584
+ See Also
585
+ --------
586
+ hermadd, hermsub, hermmulx, hermmul, hermdiv
587
+
588
+ Examples
589
+ --------
590
+ >>> from numpy.polynomial.hermite import hermpow
591
+ >>> hermpow([1, 2, 3], 2)
592
+ array([81., 52., 82., 12., 9.])
593
+
594
+ """
595
+ return pu._pow(hermmul, c, pow, maxpower)
596
+
597
+
598
+ def hermder(c, m=1, scl=1, axis=0):
599
+ """
600
+ Differentiate a Hermite series.
601
+
602
+ Returns the Hermite series coefficients `c` differentiated `m` times
603
+ along `axis`. At each iteration the result is multiplied by `scl` (the
604
+ scaling factor is for use in a linear change of variable). The argument
605
+ `c` is an array of coefficients from low to high degree along each
606
+ axis, e.g., [1,2,3] represents the series ``1*H_0 + 2*H_1 + 3*H_2``
607
+ while [[1,2],[1,2]] represents ``1*H_0(x)*H_0(y) + 1*H_1(x)*H_0(y) +
608
+ 2*H_0(x)*H_1(y) + 2*H_1(x)*H_1(y)`` if axis=0 is ``x`` and axis=1 is
609
+ ``y``.
610
+
611
+ Parameters
612
+ ----------
613
+ c : array_like
614
+ Array of Hermite series coefficients. If `c` is multidimensional the
615
+ different axis correspond to different variables with the degree in
616
+ each axis given by the corresponding index.
617
+ m : int, optional
618
+ Number of derivatives taken, must be non-negative. (Default: 1)
619
+ scl : scalar, optional
620
+ Each differentiation is multiplied by `scl`. The end result is
621
+ multiplication by ``scl**m``. This is for use in a linear change of
622
+ variable. (Default: 1)
623
+ axis : int, optional
624
+ Axis over which the derivative is taken. (Default: 0).
625
+
626
+ .. versionadded:: 1.7.0
627
+
628
+ Returns
629
+ -------
630
+ der : ndarray
631
+ Hermite series of the derivative.
632
+
633
+ See Also
634
+ --------
635
+ hermint
636
+
637
+ Notes
638
+ -----
639
+ In general, the result of differentiating a Hermite series does not
640
+ resemble the same operation on a power series. Thus the result of this
641
+ function may be "unintuitive," albeit correct; see Examples section
642
+ below.
643
+
644
+ Examples
645
+ --------
646
+ >>> from numpy.polynomial.hermite import hermder
647
+ >>> hermder([ 1. , 0.5, 0.5, 0.5])
648
+ array([1., 2., 3.])
649
+ >>> hermder([-0.5, 1./2., 1./8., 1./12., 1./16.], m=2)
650
+ array([1., 2., 3.])
651
+
652
+ """
653
+ c = np.array(c, ndmin=1, copy=True)
654
+ if c.dtype.char in '?bBhHiIlLqQpP':
655
+ c = c.astype(np.double)
656
+ cnt = pu._as_int(m, "the order of derivation")
657
+ iaxis = pu._as_int(axis, "the axis")
658
+ if cnt < 0:
659
+ raise ValueError("The order of derivation must be non-negative")
660
+ iaxis = normalize_axis_index(iaxis, c.ndim)
661
+
662
+ if cnt == 0:
663
+ return c
664
+
665
+ c = np.moveaxis(c, iaxis, 0)
666
+ n = len(c)
667
+ if cnt >= n:
668
+ c = c[:1]*0
669
+ else:
670
+ for i in range(cnt):
671
+ n = n - 1
672
+ c *= scl
673
+ der = np.empty((n,) + c.shape[1:], dtype=c.dtype)
674
+ for j in range(n, 0, -1):
675
+ der[j - 1] = (2*j)*c[j]
676
+ c = der
677
+ c = np.moveaxis(c, 0, iaxis)
678
+ return c
679
+
680
+
681
+ def hermint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
682
+ """
683
+ Integrate a Hermite series.
684
+
685
+ Returns the Hermite series coefficients `c` integrated `m` times from
686
+ `lbnd` along `axis`. At each iteration the resulting series is
687
+ **multiplied** by `scl` and an integration constant, `k`, is added.
688
+ The scaling factor is for use in a linear change of variable. ("Buyer
689
+ beware": note that, depending on what one is doing, one may want `scl`
690
+ to be the reciprocal of what one might expect; for more information,
691
+ see the Notes section below.) The argument `c` is an array of
692
+ coefficients from low to high degree along each axis, e.g., [1,2,3]
693
+ represents the series ``H_0 + 2*H_1 + 3*H_2`` while [[1,2],[1,2]]
694
+ represents ``1*H_0(x)*H_0(y) + 1*H_1(x)*H_0(y) + 2*H_0(x)*H_1(y) +
695
+ 2*H_1(x)*H_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``.
696
+
697
+ Parameters
698
+ ----------
699
+ c : array_like
700
+ Array of Hermite series coefficients. If c is multidimensional the
701
+ different axis correspond to different variables with the degree in
702
+ each axis given by the corresponding index.
703
+ m : int, optional
704
+ Order of integration, must be positive. (Default: 1)
705
+ k : {[], list, scalar}, optional
706
+ Integration constant(s). The value of the first integral at
707
+ ``lbnd`` is the first value in the list, the value of the second
708
+ integral at ``lbnd`` is the second value, etc. If ``k == []`` (the
709
+ default), all constants are set to zero. If ``m == 1``, a single
710
+ scalar can be given instead of a list.
711
+ lbnd : scalar, optional
712
+ The lower bound of the integral. (Default: 0)
713
+ scl : scalar, optional
714
+ Following each integration the result is *multiplied* by `scl`
715
+ before the integration constant is added. (Default: 1)
716
+ axis : int, optional
717
+ Axis over which the integral is taken. (Default: 0).
718
+
719
+ .. versionadded:: 1.7.0
720
+
721
+ Returns
722
+ -------
723
+ S : ndarray
724
+ Hermite series coefficients of the integral.
725
+
726
+ Raises
727
+ ------
728
+ ValueError
729
+ If ``m < 0``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or
730
+ ``np.ndim(scl) != 0``.
731
+
732
+ See Also
733
+ --------
734
+ hermder
735
+
736
+ Notes
737
+ -----
738
+ Note that the result of each integration is *multiplied* by `scl`.
739
+ Why is this important to note? Say one is making a linear change of
740
+ variable :math:`u = ax + b` in an integral relative to `x`. Then
741
+ :math:`dx = du/a`, so one will need to set `scl` equal to
742
+ :math:`1/a` - perhaps not what one would have first thought.
743
+
744
+ Also note that, in general, the result of integrating a C-series needs
745
+ to be "reprojected" onto the C-series basis set. Thus, typically,
746
+ the result of this function is "unintuitive," albeit correct; see
747
+ Examples section below.
748
+
749
+ Examples
750
+ --------
751
+ >>> from numpy.polynomial.hermite import hermint
752
+ >>> hermint([1,2,3]) # integrate once, value 0 at 0.
753
+ array([1. , 0.5, 0.5, 0.5])
754
+ >>> hermint([1,2,3], m=2) # integrate twice, value & deriv 0 at 0
755
+ array([-0.5 , 0.5 , 0.125 , 0.08333333, 0.0625 ]) # may vary
756
+ >>> hermint([1,2,3], k=1) # integrate once, value 1 at 0.
757
+ array([2. , 0.5, 0.5, 0.5])
758
+ >>> hermint([1,2,3], lbnd=-1) # integrate once, value 0 at -1
759
+ array([-2. , 0.5, 0.5, 0.5])
760
+ >>> hermint([1,2,3], m=2, k=[1,2], lbnd=-1)
761
+ array([ 1.66666667, -0.5 , 0.125 , 0.08333333, 0.0625 ]) # may vary
762
+
763
+ """
764
+ c = np.array(c, ndmin=1, copy=True)
765
+ if c.dtype.char in '?bBhHiIlLqQpP':
766
+ c = c.astype(np.double)
767
+ if not np.iterable(k):
768
+ k = [k]
769
+ cnt = pu._as_int(m, "the order of integration")
770
+ iaxis = pu._as_int(axis, "the axis")
771
+ if cnt < 0:
772
+ raise ValueError("The order of integration must be non-negative")
773
+ if len(k) > cnt:
774
+ raise ValueError("Too many integration constants")
775
+ if np.ndim(lbnd) != 0:
776
+ raise ValueError("lbnd must be a scalar.")
777
+ if np.ndim(scl) != 0:
778
+ raise ValueError("scl must be a scalar.")
779
+ iaxis = normalize_axis_index(iaxis, c.ndim)
780
+
781
+ if cnt == 0:
782
+ return c
783
+
784
+ c = np.moveaxis(c, iaxis, 0)
785
+ k = list(k) + [0]*(cnt - len(k))
786
+ for i in range(cnt):
787
+ n = len(c)
788
+ c *= scl
789
+ if n == 1 and np.all(c[0] == 0):
790
+ c[0] += k[i]
791
+ else:
792
+ tmp = np.empty((n + 1,) + c.shape[1:], dtype=c.dtype)
793
+ tmp[0] = c[0]*0
794
+ tmp[1] = c[0]/2
795
+ for j in range(1, n):
796
+ tmp[j + 1] = c[j]/(2*(j + 1))
797
+ tmp[0] += k[i] - hermval(lbnd, tmp)
798
+ c = tmp
799
+ c = np.moveaxis(c, 0, iaxis)
800
+ return c
801
+
802
+
803
+ def hermval(x, c, tensor=True):
804
+ """
805
+ Evaluate an Hermite series at points x.
806
+
807
+ If `c` is of length ``n + 1``, this function returns the value:
808
+
809
+ .. math:: p(x) = c_0 * H_0(x) + c_1 * H_1(x) + ... + c_n * H_n(x)
810
+
811
+ The parameter `x` is converted to an array only if it is a tuple or a
812
+ list, otherwise it is treated as a scalar. In either case, either `x`
813
+ or its elements must support multiplication and addition both with
814
+ themselves and with the elements of `c`.
815
+
816
+ If `c` is a 1-D array, then ``p(x)`` will have the same shape as `x`. If
817
+ `c` is multidimensional, then the shape of the result depends on the
818
+ value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
819
+ x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
820
+ scalars have shape (,).
821
+
822
+ Trailing zeros in the coefficients will be used in the evaluation, so
823
+ they should be avoided if efficiency is a concern.
824
+
825
+ Parameters
826
+ ----------
827
+ x : array_like, compatible object
828
+ If `x` is a list or tuple, it is converted to an ndarray, otherwise
829
+ it is left unchanged and treated as a scalar. In either case, `x`
830
+ or its elements must support addition and multiplication with
831
+ themselves and with the elements of `c`.
832
+ c : array_like
833
+ Array of coefficients ordered so that the coefficients for terms of
834
+ degree n are contained in c[n]. If `c` is multidimensional the
835
+ remaining indices enumerate multiple polynomials. In the two
836
+ dimensional case the coefficients may be thought of as stored in
837
+ the columns of `c`.
838
+ tensor : boolean, optional
839
+ If True, the shape of the coefficient array is extended with ones
840
+ on the right, one for each dimension of `x`. Scalars have dimension 0
841
+ for this action. The result is that every column of coefficients in
842
+ `c` is evaluated for every element of `x`. If False, `x` is broadcast
843
+ over the columns of `c` for the evaluation. This keyword is useful
844
+ when `c` is multidimensional. The default value is True.
845
+
846
+ .. versionadded:: 1.7.0
847
+
848
+ Returns
849
+ -------
850
+ values : ndarray, algebra_like
851
+ The shape of the return value is described above.
852
+
853
+ See Also
854
+ --------
855
+ hermval2d, hermgrid2d, hermval3d, hermgrid3d
856
+
857
+ Notes
858
+ -----
859
+ The evaluation uses Clenshaw recursion, aka synthetic division.
860
+
861
+ Examples
862
+ --------
863
+ >>> from numpy.polynomial.hermite import hermval
864
+ >>> coef = [1,2,3]
865
+ >>> hermval(1, coef)
866
+ 11.0
867
+ >>> hermval([[1,2],[3,4]], coef)
868
+ array([[ 11., 51.],
869
+ [115., 203.]])
870
+
871
+ """
872
+ c = np.array(c, ndmin=1, copy=None)
873
+ if c.dtype.char in '?bBhHiIlLqQpP':
874
+ c = c.astype(np.double)
875
+ if isinstance(x, (tuple, list)):
876
+ x = np.asarray(x)
877
+ if isinstance(x, np.ndarray) and tensor:
878
+ c = c.reshape(c.shape + (1,)*x.ndim)
879
+
880
+ x2 = x*2
881
+ if len(c) == 1:
882
+ c0 = c[0]
883
+ c1 = 0
884
+ elif len(c) == 2:
885
+ c0 = c[0]
886
+ c1 = c[1]
887
+ else:
888
+ nd = len(c)
889
+ c0 = c[-2]
890
+ c1 = c[-1]
891
+ for i in range(3, len(c) + 1):
892
+ tmp = c0
893
+ nd = nd - 1
894
+ c0 = c[-i] - c1*(2*(nd - 1))
895
+ c1 = tmp + c1*x2
896
+ return c0 + c1*x2
897
+
898
+
899
+ def hermval2d(x, y, c):
900
+ """
901
+ Evaluate a 2-D Hermite series at points (x, y).
902
+
903
+ This function returns the values:
904
+
905
+ .. math:: p(x,y) = \\sum_{i,j} c_{i,j} * H_i(x) * H_j(y)
906
+
907
+ The parameters `x` and `y` are converted to arrays only if they are
908
+ tuples or a lists, otherwise they are treated as a scalars and they
909
+ must have the same shape after conversion. In either case, either `x`
910
+ and `y` or their elements must support multiplication and addition both
911
+ with themselves and with the elements of `c`.
912
+
913
+ If `c` is a 1-D array a one is implicitly appended to its shape to make
914
+ it 2-D. The shape of the result will be c.shape[2:] + x.shape.
915
+
916
+ Parameters
917
+ ----------
918
+ x, y : array_like, compatible objects
919
+ The two dimensional series is evaluated at the points ``(x, y)``,
920
+ where `x` and `y` must have the same shape. If `x` or `y` is a list
921
+ or tuple, it is first converted to an ndarray, otherwise it is left
922
+ unchanged and if it isn't an ndarray it is treated as a scalar.
923
+ c : array_like
924
+ Array of coefficients ordered so that the coefficient of the term
925
+ of multi-degree i,j is contained in ``c[i,j]``. If `c` has
926
+ dimension greater than two the remaining indices enumerate multiple
927
+ sets of coefficients.
928
+
929
+ Returns
930
+ -------
931
+ values : ndarray, compatible object
932
+ The values of the two dimensional polynomial at points formed with
933
+ pairs of corresponding values from `x` and `y`.
934
+
935
+ See Also
936
+ --------
937
+ hermval, hermgrid2d, hermval3d, hermgrid3d
938
+
939
+ Notes
940
+ -----
941
+
942
+ .. versionadded:: 1.7.0
943
+
944
+ Examples
945
+ --------
946
+ >>> from numpy.polynomial.hermite import hermval2d
947
+ >>> x = [1, 2]
948
+ >>> y = [4, 5]
949
+ >>> c = [[1, 2, 3], [4, 5, 6]]
950
+ >>> hermval2d(x, y, c)
951
+ array([1035., 2883.])
952
+
953
+ """
954
+ return pu._valnd(hermval, c, x, y)
955
+
956
+
957
+ def hermgrid2d(x, y, c):
958
+ """
959
+ Evaluate a 2-D Hermite series on the Cartesian product of x and y.
960
+
961
+ This function returns the values:
962
+
963
+ .. math:: p(a,b) = \\sum_{i,j} c_{i,j} * H_i(a) * H_j(b)
964
+
965
+ where the points ``(a, b)`` consist of all pairs formed by taking
966
+ `a` from `x` and `b` from `y`. The resulting points form a grid with
967
+ `x` in the first dimension and `y` in the second.
968
+
969
+ The parameters `x` and `y` are converted to arrays only if they are
970
+ tuples or a lists, otherwise they are treated as a scalars. In either
971
+ case, either `x` and `y` or their elements must support multiplication
972
+ and addition both with themselves and with the elements of `c`.
973
+
974
+ If `c` has fewer than two dimensions, ones are implicitly appended to
975
+ its shape to make it 2-D. The shape of the result will be c.shape[2:] +
976
+ x.shape.
977
+
978
+ Parameters
979
+ ----------
980
+ x, y : array_like, compatible objects
981
+ The two dimensional series is evaluated at the points in the
982
+ Cartesian product of `x` and `y`. If `x` or `y` is a list or
983
+ tuple, it is first converted to an ndarray, otherwise it is left
984
+ unchanged and, if it isn't an ndarray, it is treated as a scalar.
985
+ c : array_like
986
+ Array of coefficients ordered so that the coefficients for terms of
987
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
988
+ greater than two the remaining indices enumerate multiple sets of
989
+ coefficients.
990
+
991
+ Returns
992
+ -------
993
+ values : ndarray, compatible object
994
+ The values of the two dimensional polynomial at points in the Cartesian
995
+ product of `x` and `y`.
996
+
997
+ See Also
998
+ --------
999
+ hermval, hermval2d, hermval3d, hermgrid3d
1000
+
1001
+ Notes
1002
+ -----
1003
+
1004
+ .. versionadded:: 1.7.0
1005
+
1006
+ Examples
1007
+ --------
1008
+ >>> from numpy.polynomial.hermite import hermgrid2d
1009
+ >>> x = [1, 2, 3]
1010
+ >>> y = [4, 5]
1011
+ >>> c = [[1, 2, 3], [4, 5, 6]]
1012
+ >>> hermgrid2d(x, y, c)
1013
+ array([[1035., 1599.],
1014
+ [1867., 2883.],
1015
+ [2699., 4167.]])
1016
+
1017
+ """
1018
+ return pu._gridnd(hermval, c, x, y)
1019
+
1020
+
1021
+ def hermval3d(x, y, z, c):
1022
+ """
1023
+ Evaluate a 3-D Hermite series at points (x, y, z).
1024
+
1025
+ This function returns the values:
1026
+
1027
+ .. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * H_i(x) * H_j(y) * H_k(z)
1028
+
1029
+ The parameters `x`, `y`, and `z` are converted to arrays only if
1030
+ they are tuples or a lists, otherwise they are treated as a scalars and
1031
+ they must have the same shape after conversion. In either case, either
1032
+ `x`, `y`, and `z` or their elements must support multiplication and
1033
+ addition both with themselves and with the elements of `c`.
1034
+
1035
+ If `c` has fewer than 3 dimensions, ones are implicitly appended to its
1036
+ shape to make it 3-D. The shape of the result will be c.shape[3:] +
1037
+ x.shape.
1038
+
1039
+ Parameters
1040
+ ----------
1041
+ x, y, z : array_like, compatible object
1042
+ The three dimensional series is evaluated at the points
1043
+ ``(x, y, z)``, where `x`, `y`, and `z` must have the same shape. If
1044
+ any of `x`, `y`, or `z` is a list or tuple, it is first converted
1045
+ to an ndarray, otherwise it is left unchanged and if it isn't an
1046
+ ndarray it is treated as a scalar.
1047
+ c : array_like
1048
+ Array of coefficients ordered so that the coefficient of the term of
1049
+ multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
1050
+ greater than 3 the remaining indices enumerate multiple sets of
1051
+ coefficients.
1052
+
1053
+ Returns
1054
+ -------
1055
+ values : ndarray, compatible object
1056
+ The values of the multidimensional polynomial on points formed with
1057
+ triples of corresponding values from `x`, `y`, and `z`.
1058
+
1059
+ See Also
1060
+ --------
1061
+ hermval, hermval2d, hermgrid2d, hermgrid3d
1062
+
1063
+ Notes
1064
+ -----
1065
+
1066
+ .. versionadded:: 1.7.0
1067
+
1068
+ Examples
1069
+ --------
1070
+ >>> from numpy.polynomial.hermite import hermval3d
1071
+ >>> x = [1, 2]
1072
+ >>> y = [4, 5]
1073
+ >>> z = [6, 7]
1074
+ >>> c = [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]
1075
+ >>> hermval3d(x, y, z, c)
1076
+ array([ 40077., 120131.])
1077
+
1078
+ """
1079
+ return pu._valnd(hermval, c, x, y, z)
1080
+
1081
+
1082
+ def hermgrid3d(x, y, z, c):
1083
+ """
1084
+ Evaluate a 3-D Hermite series on the Cartesian product of x, y, and z.
1085
+
1086
+ This function returns the values:
1087
+
1088
+ .. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * H_i(a) * H_j(b) * H_k(c)
1089
+
1090
+ where the points ``(a, b, c)`` consist of all triples formed by taking
1091
+ `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
1092
+ a grid with `x` in the first dimension, `y` in the second, and `z` in
1093
+ the third.
1094
+
1095
+ The parameters `x`, `y`, and `z` are converted to arrays only if they
1096
+ are tuples or a lists, otherwise they are treated as a scalars. In
1097
+ either case, either `x`, `y`, and `z` or their elements must support
1098
+ multiplication and addition both with themselves and with the elements
1099
+ of `c`.
1100
+
1101
+ If `c` has fewer than three dimensions, ones are implicitly appended to
1102
+ its shape to make it 3-D. The shape of the result will be c.shape[3:] +
1103
+ x.shape + y.shape + z.shape.
1104
+
1105
+ Parameters
1106
+ ----------
1107
+ x, y, z : array_like, compatible objects
1108
+ The three dimensional series is evaluated at the points in the
1109
+ Cartesian product of `x`, `y`, and `z`. If `x`, `y`, or `z` is a
1110
+ list or tuple, it is first converted to an ndarray, otherwise it is
1111
+ left unchanged and, if it isn't an ndarray, it is treated as a
1112
+ scalar.
1113
+ c : array_like
1114
+ Array of coefficients ordered so that the coefficients for terms of
1115
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
1116
+ greater than two the remaining indices enumerate multiple sets of
1117
+ coefficients.
1118
+
1119
+ Returns
1120
+ -------
1121
+ values : ndarray, compatible object
1122
+ The values of the two dimensional polynomial at points in the Cartesian
1123
+ product of `x` and `y`.
1124
+
1125
+ See Also
1126
+ --------
1127
+ hermval, hermval2d, hermgrid2d, hermval3d
1128
+
1129
+ Notes
1130
+ -----
1131
+
1132
+ .. versionadded:: 1.7.0
1133
+
1134
+ Examples
1135
+ --------
1136
+ >>> from numpy.polynomial.hermite import hermgrid3d
1137
+ >>> x = [1, 2]
1138
+ >>> y = [4, 5]
1139
+ >>> z = [6, 7]
1140
+ >>> c = [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]
1141
+ >>> hermgrid3d(x, y, z, c)
1142
+ array([[[ 40077., 54117.],
1143
+ [ 49293., 66561.]],
1144
+ [[ 72375., 97719.],
1145
+ [ 88975., 120131.]]])
1146
+
1147
+ """
1148
+ return pu._gridnd(hermval, c, x, y, z)
1149
+
1150
+
1151
+ def hermvander(x, deg):
1152
+ """Pseudo-Vandermonde matrix of given degree.
1153
+
1154
+ Returns the pseudo-Vandermonde matrix of degree `deg` and sample points
1155
+ `x`. The pseudo-Vandermonde matrix is defined by
1156
+
1157
+ .. math:: V[..., i] = H_i(x),
1158
+
1159
+ where ``0 <= i <= deg``. The leading indices of `V` index the elements of
1160
+ `x` and the last index is the degree of the Hermite polynomial.
1161
+
1162
+ If `c` is a 1-D array of coefficients of length ``n + 1`` and `V` is the
1163
+ array ``V = hermvander(x, n)``, then ``np.dot(V, c)`` and
1164
+ ``hermval(x, c)`` are the same up to roundoff. This equivalence is
1165
+ useful both for least squares fitting and for the evaluation of a large
1166
+ number of Hermite series of the same degree and sample points.
1167
+
1168
+ Parameters
1169
+ ----------
1170
+ x : array_like
1171
+ Array of points. The dtype is converted to float64 or complex128
1172
+ depending on whether any of the elements are complex. If `x` is
1173
+ scalar it is converted to a 1-D array.
1174
+ deg : int
1175
+ Degree of the resulting matrix.
1176
+
1177
+ Returns
1178
+ -------
1179
+ vander : ndarray
1180
+ The pseudo-Vandermonde matrix. The shape of the returned matrix is
1181
+ ``x.shape + (deg + 1,)``, where The last index is the degree of the
1182
+ corresponding Hermite polynomial. The dtype will be the same as
1183
+ the converted `x`.
1184
+
1185
+ Examples
1186
+ --------
1187
+ >>> import numpy as np
1188
+ >>> from numpy.polynomial.hermite import hermvander
1189
+ >>> x = np.array([-1, 0, 1])
1190
+ >>> hermvander(x, 3)
1191
+ array([[ 1., -2., 2., 4.],
1192
+ [ 1., 0., -2., -0.],
1193
+ [ 1., 2., 2., -4.]])
1194
+
1195
+ """
1196
+ ideg = pu._as_int(deg, "deg")
1197
+ if ideg < 0:
1198
+ raise ValueError("deg must be non-negative")
1199
+
1200
+ x = np.array(x, copy=None, ndmin=1) + 0.0
1201
+ dims = (ideg + 1,) + x.shape
1202
+ dtyp = x.dtype
1203
+ v = np.empty(dims, dtype=dtyp)
1204
+ v[0] = x*0 + 1
1205
+ if ideg > 0:
1206
+ x2 = x*2
1207
+ v[1] = x2
1208
+ for i in range(2, ideg + 1):
1209
+ v[i] = (v[i-1]*x2 - v[i-2]*(2*(i - 1)))
1210
+ return np.moveaxis(v, 0, -1)
1211
+
1212
+
1213
+ def hermvander2d(x, y, deg):
1214
+ """Pseudo-Vandermonde matrix of given degrees.
1215
+
1216
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1217
+ points ``(x, y)``. The pseudo-Vandermonde matrix is defined by
1218
+
1219
+ .. math:: V[..., (deg[1] + 1)*i + j] = H_i(x) * H_j(y),
1220
+
1221
+ where ``0 <= i <= deg[0]`` and ``0 <= j <= deg[1]``. The leading indices of
1222
+ `V` index the points ``(x, y)`` and the last index encodes the degrees of
1223
+ the Hermite polynomials.
1224
+
1225
+ If ``V = hermvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`
1226
+ correspond to the elements of a 2-D coefficient array `c` of shape
1227
+ (xdeg + 1, ydeg + 1) in the order
1228
+
1229
+ .. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ...
1230
+
1231
+ and ``np.dot(V, c.flat)`` and ``hermval2d(x, y, c)`` will be the same
1232
+ up to roundoff. This equivalence is useful both for least squares
1233
+ fitting and for the evaluation of a large number of 2-D Hermite
1234
+ series of the same degrees and sample points.
1235
+
1236
+ Parameters
1237
+ ----------
1238
+ x, y : array_like
1239
+ Arrays of point coordinates, all of the same shape. The dtypes
1240
+ will be converted to either float64 or complex128 depending on
1241
+ whether any of the elements are complex. Scalars are converted to 1-D
1242
+ arrays.
1243
+ deg : list of ints
1244
+ List of maximum degrees of the form [x_deg, y_deg].
1245
+
1246
+ Returns
1247
+ -------
1248
+ vander2d : ndarray
1249
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1250
+ :math:`order = (deg[0]+1)*(deg[1]+1)`. The dtype will be the same
1251
+ as the converted `x` and `y`.
1252
+
1253
+ See Also
1254
+ --------
1255
+ hermvander, hermvander3d, hermval2d, hermval3d
1256
+
1257
+ Notes
1258
+ -----
1259
+
1260
+ .. versionadded:: 1.7.0
1261
+
1262
+ Examples
1263
+ --------
1264
+ >>> import numpy as np
1265
+ >>> from numpy.polynomial.hermite import hermvander2d
1266
+ >>> x = np.array([-1, 0, 1])
1267
+ >>> y = np.array([-1, 0, 1])
1268
+ >>> hermvander2d(x, y, [2, 2])
1269
+ array([[ 1., -2., 2., -2., 4., -4., 2., -4., 4.],
1270
+ [ 1., 0., -2., 0., 0., -0., -2., -0., 4.],
1271
+ [ 1., 2., 2., 2., 4., 4., 2., 4., 4.]])
1272
+
1273
+ """
1274
+ return pu._vander_nd_flat((hermvander, hermvander), (x, y), deg)
1275
+
1276
+
1277
+ def hermvander3d(x, y, z, deg):
1278
+ """Pseudo-Vandermonde matrix of given degrees.
1279
+
1280
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1281
+ points ``(x, y, z)``. If `l`, `m`, `n` are the given degrees in `x`, `y`, `z`,
1282
+ then The pseudo-Vandermonde matrix is defined by
1283
+
1284
+ .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = H_i(x)*H_j(y)*H_k(z),
1285
+
1286
+ where ``0 <= i <= l``, ``0 <= j <= m``, and ``0 <= j <= n``. The leading
1287
+ indices of `V` index the points ``(x, y, z)`` and the last index encodes
1288
+ the degrees of the Hermite polynomials.
1289
+
1290
+ If ``V = hermvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
1291
+ of `V` correspond to the elements of a 3-D coefficient array `c` of
1292
+ shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order
1293
+
1294
+ .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...
1295
+
1296
+ and ``np.dot(V, c.flat)`` and ``hermval3d(x, y, z, c)`` will be the
1297
+ same up to roundoff. This equivalence is useful both for least squares
1298
+ fitting and for the evaluation of a large number of 3-D Hermite
1299
+ series of the same degrees and sample points.
1300
+
1301
+ Parameters
1302
+ ----------
1303
+ x, y, z : array_like
1304
+ Arrays of point coordinates, all of the same shape. The dtypes will
1305
+ be converted to either float64 or complex128 depending on whether
1306
+ any of the elements are complex. Scalars are converted to 1-D
1307
+ arrays.
1308
+ deg : list of ints
1309
+ List of maximum degrees of the form [x_deg, y_deg, z_deg].
1310
+
1311
+ Returns
1312
+ -------
1313
+ vander3d : ndarray
1314
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1315
+ :math:`order = (deg[0]+1)*(deg[1]+1)*(deg[2]+1)`. The dtype will
1316
+ be the same as the converted `x`, `y`, and `z`.
1317
+
1318
+ See Also
1319
+ --------
1320
+ hermvander, hermvander3d, hermval2d, hermval3d
1321
+
1322
+ Notes
1323
+ -----
1324
+
1325
+ .. versionadded:: 1.7.0
1326
+
1327
+ Examples
1328
+ --------
1329
+ >>> from numpy.polynomial.hermite import hermvander3d
1330
+ >>> x = np.array([-1, 0, 1])
1331
+ >>> y = np.array([-1, 0, 1])
1332
+ >>> z = np.array([-1, 0, 1])
1333
+ >>> hermvander3d(x, y, z, [0, 1, 2])
1334
+ array([[ 1., -2., 2., -2., 4., -4.],
1335
+ [ 1., 0., -2., 0., 0., -0.],
1336
+ [ 1., 2., 2., 2., 4., 4.]])
1337
+
1338
+ """
1339
+ return pu._vander_nd_flat((hermvander, hermvander, hermvander), (x, y, z), deg)
1340
+
1341
+
1342
+ def hermfit(x, y, deg, rcond=None, full=False, w=None):
1343
+ """
1344
+ Least squares fit of Hermite series to data.
1345
+
1346
+ Return the coefficients of a Hermite series of degree `deg` that is the
1347
+ least squares fit to the data values `y` given at points `x`. If `y` is
1348
+ 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
1349
+ fits are done, one for each column of `y`, and the resulting
1350
+ coefficients are stored in the corresponding columns of a 2-D return.
1351
+ The fitted polynomial(s) are in the form
1352
+
1353
+ .. math:: p(x) = c_0 + c_1 * H_1(x) + ... + c_n * H_n(x),
1354
+
1355
+ where `n` is `deg`.
1356
+
1357
+ Parameters
1358
+ ----------
1359
+ x : array_like, shape (M,)
1360
+ x-coordinates of the M sample points ``(x[i], y[i])``.
1361
+ y : array_like, shape (M,) or (M, K)
1362
+ y-coordinates of the sample points. Several data sets of sample
1363
+ points sharing the same x-coordinates can be fitted at once by
1364
+ passing in a 2D-array that contains one dataset per column.
1365
+ deg : int or 1-D array_like
1366
+ Degree(s) of the fitting polynomials. If `deg` is a single integer
1367
+ all terms up to and including the `deg`'th term are included in the
1368
+ fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1369
+ degrees of the terms to include may be used instead.
1370
+ rcond : float, optional
1371
+ Relative condition number of the fit. Singular values smaller than
1372
+ this relative to the largest singular value will be ignored. The
1373
+ default value is len(x)*eps, where eps is the relative precision of
1374
+ the float type, about 2e-16 in most cases.
1375
+ full : bool, optional
1376
+ Switch determining nature of return value. When it is False (the
1377
+ default) just the coefficients are returned, when True diagnostic
1378
+ information from the singular value decomposition is also returned.
1379
+ w : array_like, shape (`M`,), optional
1380
+ Weights. If not None, the weight ``w[i]`` applies to the unsquared
1381
+ residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1382
+ chosen so that the errors of the products ``w[i]*y[i]`` all have the
1383
+ same variance. When using inverse-variance weighting, use
1384
+ ``w[i] = 1/sigma(y[i])``. The default value is None.
1385
+
1386
+ Returns
1387
+ -------
1388
+ coef : ndarray, shape (M,) or (M, K)
1389
+ Hermite coefficients ordered from low to high. If `y` was 2-D,
1390
+ the coefficients for the data in column k of `y` are in column
1391
+ `k`.
1392
+
1393
+ [residuals, rank, singular_values, rcond] : list
1394
+ These values are only returned if ``full == True``
1395
+
1396
+ - residuals -- sum of squared residuals of the least squares fit
1397
+ - rank -- the numerical rank of the scaled Vandermonde matrix
1398
+ - singular_values -- singular values of the scaled Vandermonde matrix
1399
+ - rcond -- value of `rcond`.
1400
+
1401
+ For more details, see `numpy.linalg.lstsq`.
1402
+
1403
+ Warns
1404
+ -----
1405
+ RankWarning
1406
+ The rank of the coefficient matrix in the least-squares fit is
1407
+ deficient. The warning is only raised if ``full == False``. The
1408
+ warnings can be turned off by
1409
+
1410
+ >>> import warnings
1411
+ >>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
1412
+
1413
+ See Also
1414
+ --------
1415
+ numpy.polynomial.chebyshev.chebfit
1416
+ numpy.polynomial.legendre.legfit
1417
+ numpy.polynomial.laguerre.lagfit
1418
+ numpy.polynomial.polynomial.polyfit
1419
+ numpy.polynomial.hermite_e.hermefit
1420
+ hermval : Evaluates a Hermite series.
1421
+ hermvander : Vandermonde matrix of Hermite series.
1422
+ hermweight : Hermite weight function
1423
+ numpy.linalg.lstsq : Computes a least-squares fit from the matrix.
1424
+ scipy.interpolate.UnivariateSpline : Computes spline fits.
1425
+
1426
+ Notes
1427
+ -----
1428
+ The solution is the coefficients of the Hermite series `p` that
1429
+ minimizes the sum of the weighted squared errors
1430
+
1431
+ .. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,
1432
+
1433
+ where the :math:`w_j` are the weights. This problem is solved by
1434
+ setting up the (typically) overdetermined matrix equation
1435
+
1436
+ .. math:: V(x) * c = w * y,
1437
+
1438
+ where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the
1439
+ coefficients to be solved for, `w` are the weights, `y` are the
1440
+ observed values. This equation is then solved using the singular value
1441
+ decomposition of `V`.
1442
+
1443
+ If some of the singular values of `V` are so small that they are
1444
+ neglected, then a `~exceptions.RankWarning` will be issued. This means that
1445
+ the coefficient values may be poorly determined. Using a lower order fit
1446
+ will usually get rid of the warning. The `rcond` parameter can also be
1447
+ set to a value smaller than its default, but the resulting fit may be
1448
+ spurious and have large contributions from roundoff error.
1449
+
1450
+ Fits using Hermite series are probably most useful when the data can be
1451
+ approximated by ``sqrt(w(x)) * p(x)``, where ``w(x)`` is the Hermite
1452
+ weight. In that case the weight ``sqrt(w(x[i]))`` should be used
1453
+ together with data values ``y[i]/sqrt(w(x[i]))``. The weight function is
1454
+ available as `hermweight`.
1455
+
1456
+ References
1457
+ ----------
1458
+ .. [1] Wikipedia, "Curve fitting",
1459
+ https://en.wikipedia.org/wiki/Curve_fitting
1460
+
1461
+ Examples
1462
+ --------
1463
+ >>> import numpy as np
1464
+ >>> from numpy.polynomial.hermite import hermfit, hermval
1465
+ >>> x = np.linspace(-10, 10)
1466
+ >>> rng = np.random.default_rng()
1467
+ >>> err = rng.normal(scale=1./10, size=len(x))
1468
+ >>> y = hermval(x, [1, 2, 3]) + err
1469
+ >>> hermfit(x, y, 2)
1470
+ array([1.02294967, 2.00016403, 2.99994614]) # may vary
1471
+
1472
+ """
1473
+ return pu._fit(hermvander, x, y, deg, rcond, full, w)
1474
+
1475
+
1476
+ def hermcompanion(c):
1477
+ """Return the scaled companion matrix of c.
1478
+
1479
+ The basis polynomials are scaled so that the companion matrix is
1480
+ symmetric when `c` is an Hermite basis polynomial. This provides
1481
+ better eigenvalue estimates than the unscaled case and for basis
1482
+ polynomials the eigenvalues are guaranteed to be real if
1483
+ `numpy.linalg.eigvalsh` is used to obtain them.
1484
+
1485
+ Parameters
1486
+ ----------
1487
+ c : array_like
1488
+ 1-D array of Hermite series coefficients ordered from low to high
1489
+ degree.
1490
+
1491
+ Returns
1492
+ -------
1493
+ mat : ndarray
1494
+ Scaled companion matrix of dimensions (deg, deg).
1495
+
1496
+ Notes
1497
+ -----
1498
+
1499
+ .. versionadded:: 1.7.0
1500
+
1501
+ Examples
1502
+ --------
1503
+ >>> from numpy.polynomial.hermite import hermcompanion
1504
+ >>> hermcompanion([1, 0, 1])
1505
+ array([[0. , 0.35355339],
1506
+ [0.70710678, 0. ]])
1507
+
1508
+ """
1509
+ # c is a trimmed copy
1510
+ [c] = pu.as_series([c])
1511
+ if len(c) < 2:
1512
+ raise ValueError('Series must have maximum degree of at least 1.')
1513
+ if len(c) == 2:
1514
+ return np.array([[-.5*c[0]/c[1]]])
1515
+
1516
+ n = len(c) - 1
1517
+ mat = np.zeros((n, n), dtype=c.dtype)
1518
+ scl = np.hstack((1., 1./np.sqrt(2.*np.arange(n - 1, 0, -1))))
1519
+ scl = np.multiply.accumulate(scl)[::-1]
1520
+ top = mat.reshape(-1)[1::n+1]
1521
+ bot = mat.reshape(-1)[n::n+1]
1522
+ top[...] = np.sqrt(.5*np.arange(1, n))
1523
+ bot[...] = top
1524
+ mat[:, -1] -= scl*c[:-1]/(2.0*c[-1])
1525
+ return mat
1526
+
1527
+
1528
+ def hermroots(c):
1529
+ """
1530
+ Compute the roots of a Hermite series.
1531
+
1532
+ Return the roots (a.k.a. "zeros") of the polynomial
1533
+
1534
+ .. math:: p(x) = \\sum_i c[i] * H_i(x).
1535
+
1536
+ Parameters
1537
+ ----------
1538
+ c : 1-D array_like
1539
+ 1-D array of coefficients.
1540
+
1541
+ Returns
1542
+ -------
1543
+ out : ndarray
1544
+ Array of the roots of the series. If all the roots are real,
1545
+ then `out` is also real, otherwise it is complex.
1546
+
1547
+ See Also
1548
+ --------
1549
+ numpy.polynomial.polynomial.polyroots
1550
+ numpy.polynomial.legendre.legroots
1551
+ numpy.polynomial.laguerre.lagroots
1552
+ numpy.polynomial.chebyshev.chebroots
1553
+ numpy.polynomial.hermite_e.hermeroots
1554
+
1555
+ Notes
1556
+ -----
1557
+ The root estimates are obtained as the eigenvalues of the companion
1558
+ matrix, Roots far from the origin of the complex plane may have large
1559
+ errors due to the numerical instability of the series for such
1560
+ values. Roots with multiplicity greater than 1 will also show larger
1561
+ errors as the value of the series near such points is relatively
1562
+ insensitive to errors in the roots. Isolated roots near the origin can
1563
+ be improved by a few iterations of Newton's method.
1564
+
1565
+ The Hermite series basis polynomials aren't powers of `x` so the
1566
+ results of this function may seem unintuitive.
1567
+
1568
+ Examples
1569
+ --------
1570
+ >>> from numpy.polynomial.hermite import hermroots, hermfromroots
1571
+ >>> coef = hermfromroots([-1, 0, 1])
1572
+ >>> coef
1573
+ array([0. , 0.25 , 0. , 0.125])
1574
+ >>> hermroots(coef)
1575
+ array([-1.00000000e+00, -1.38777878e-17, 1.00000000e+00])
1576
+
1577
+ """
1578
+ # c is a trimmed copy
1579
+ [c] = pu.as_series([c])
1580
+ if len(c) <= 1:
1581
+ return np.array([], dtype=c.dtype)
1582
+ if len(c) == 2:
1583
+ return np.array([-.5*c[0]/c[1]])
1584
+
1585
+ # rotated companion matrix reduces error
1586
+ m = hermcompanion(c)[::-1,::-1]
1587
+ r = la.eigvals(m)
1588
+ r.sort()
1589
+ return r
1590
+
1591
+
1592
+ def _normed_hermite_n(x, n):
1593
+ """
1594
+ Evaluate a normalized Hermite polynomial.
1595
+
1596
+ Compute the value of the normalized Hermite polynomial of degree ``n``
1597
+ at the points ``x``.
1598
+
1599
+
1600
+ Parameters
1601
+ ----------
1602
+ x : ndarray of double.
1603
+ Points at which to evaluate the function
1604
+ n : int
1605
+ Degree of the normalized Hermite function to be evaluated.
1606
+
1607
+ Returns
1608
+ -------
1609
+ values : ndarray
1610
+ The shape of the return value is described above.
1611
+
1612
+ Notes
1613
+ -----
1614
+ .. versionadded:: 1.10.0
1615
+
1616
+ This function is needed for finding the Gauss points and integration
1617
+ weights for high degrees. The values of the standard Hermite functions
1618
+ overflow when n >= 207.
1619
+
1620
+ """
1621
+ if n == 0:
1622
+ return np.full(x.shape, 1/np.sqrt(np.sqrt(np.pi)))
1623
+
1624
+ c0 = 0.
1625
+ c1 = 1./np.sqrt(np.sqrt(np.pi))
1626
+ nd = float(n)
1627
+ for i in range(n - 1):
1628
+ tmp = c0
1629
+ c0 = -c1*np.sqrt((nd - 1.)/nd)
1630
+ c1 = tmp + c1*x*np.sqrt(2./nd)
1631
+ nd = nd - 1.0
1632
+ return c0 + c1*x*np.sqrt(2)
1633
+
1634
+
1635
+ def hermgauss(deg):
1636
+ """
1637
+ Gauss-Hermite quadrature.
1638
+
1639
+ Computes the sample points and weights for Gauss-Hermite quadrature.
1640
+ These sample points and weights will correctly integrate polynomials of
1641
+ degree :math:`2*deg - 1` or less over the interval :math:`[-\\inf, \\inf]`
1642
+ with the weight function :math:`f(x) = \\exp(-x^2)`.
1643
+
1644
+ Parameters
1645
+ ----------
1646
+ deg : int
1647
+ Number of sample points and weights. It must be >= 1.
1648
+
1649
+ Returns
1650
+ -------
1651
+ x : ndarray
1652
+ 1-D ndarray containing the sample points.
1653
+ y : ndarray
1654
+ 1-D ndarray containing the weights.
1655
+
1656
+ Notes
1657
+ -----
1658
+
1659
+ .. versionadded:: 1.7.0
1660
+
1661
+ The results have only been tested up to degree 100, higher degrees may
1662
+ be problematic. The weights are determined by using the fact that
1663
+
1664
+ .. math:: w_k = c / (H'_n(x_k) * H_{n-1}(x_k))
1665
+
1666
+ where :math:`c` is a constant independent of :math:`k` and :math:`x_k`
1667
+ is the k'th root of :math:`H_n`, and then scaling the results to get
1668
+ the right value when integrating 1.
1669
+
1670
+ Examples
1671
+ --------
1672
+ >>> from numpy.polynomial.hermite import hermgauss
1673
+ >>> hermgauss(2)
1674
+ (array([-0.70710678, 0.70710678]), array([0.88622693, 0.88622693]))
1675
+
1676
+ """
1677
+ ideg = pu._as_int(deg, "deg")
1678
+ if ideg <= 0:
1679
+ raise ValueError("deg must be a positive integer")
1680
+
1681
+ # first approximation of roots. We use the fact that the companion
1682
+ # matrix is symmetric in this case in order to obtain better zeros.
1683
+ c = np.array([0]*deg + [1], dtype=np.float64)
1684
+ m = hermcompanion(c)
1685
+ x = la.eigvalsh(m)
1686
+
1687
+ # improve roots by one application of Newton
1688
+ dy = _normed_hermite_n(x, ideg)
1689
+ df = _normed_hermite_n(x, ideg - 1) * np.sqrt(2*ideg)
1690
+ x -= dy/df
1691
+
1692
+ # compute the weights. We scale the factor to avoid possible numerical
1693
+ # overflow.
1694
+ fm = _normed_hermite_n(x, ideg - 1)
1695
+ fm /= np.abs(fm).max()
1696
+ w = 1/(fm * fm)
1697
+
1698
+ # for Hermite we can also symmetrize
1699
+ w = (w + w[::-1])/2
1700
+ x = (x - x[::-1])/2
1701
+
1702
+ # scale w to get the right value
1703
+ w *= np.sqrt(np.pi) / w.sum()
1704
+
1705
+ return x, w
1706
+
1707
+
1708
+ def hermweight(x):
1709
+ """
1710
+ Weight function of the Hermite polynomials.
1711
+
1712
+ The weight function is :math:`\\exp(-x^2)` and the interval of
1713
+ integration is :math:`[-\\inf, \\inf]`. the Hermite polynomials are
1714
+ orthogonal, but not normalized, with respect to this weight function.
1715
+
1716
+ Parameters
1717
+ ----------
1718
+ x : array_like
1719
+ Values at which the weight function will be computed.
1720
+
1721
+ Returns
1722
+ -------
1723
+ w : ndarray
1724
+ The weight function at `x`.
1725
+
1726
+ Notes
1727
+ -----
1728
+
1729
+ .. versionadded:: 1.7.0
1730
+
1731
+ Examples
1732
+ --------
1733
+ >>> import numpy as np
1734
+ >>> from numpy.polynomial.hermite import hermweight
1735
+ >>> x = np.arange(-2, 2)
1736
+ >>> hermweight(x)
1737
+ array([0.01831564, 0.36787944, 1. , 0.36787944])
1738
+
1739
+ """
1740
+ w = np.exp(-x**2)
1741
+ return w
1742
+
1743
+
1744
+ #
1745
+ # Hermite series class
1746
+ #
1747
+
1748
+ class Hermite(ABCPolyBase):
1749
+ """An Hermite series class.
1750
+
1751
+ The Hermite class provides the standard Python numerical methods
1752
+ '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the
1753
+ attributes and methods listed below.
1754
+
1755
+ Parameters
1756
+ ----------
1757
+ coef : array_like
1758
+ Hermite coefficients in order of increasing degree, i.e,
1759
+ ``(1, 2, 3)`` gives ``1*H_0(x) + 2*H_1(x) + 3*H_2(x)``.
1760
+ domain : (2,) array_like, optional
1761
+ Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
1762
+ to the interval ``[window[0], window[1]]`` by shifting and scaling.
1763
+ The default value is [-1., 1.].
1764
+ window : (2,) array_like, optional
1765
+ Window, see `domain` for its use. The default value is [-1., 1.].
1766
+
1767
+ .. versionadded:: 1.6.0
1768
+ symbol : str, optional
1769
+ Symbol used to represent the independent variable in string
1770
+ representations of the polynomial expression, e.g. for printing.
1771
+ The symbol must be a valid Python identifier. Default value is 'x'.
1772
+
1773
+ .. versionadded:: 1.24
1774
+
1775
+ """
1776
+ # Virtual Functions
1777
+ _add = staticmethod(hermadd)
1778
+ _sub = staticmethod(hermsub)
1779
+ _mul = staticmethod(hermmul)
1780
+ _div = staticmethod(hermdiv)
1781
+ _pow = staticmethod(hermpow)
1782
+ _val = staticmethod(hermval)
1783
+ _int = staticmethod(hermint)
1784
+ _der = staticmethod(hermder)
1785
+ _fit = staticmethod(hermfit)
1786
+ _line = staticmethod(hermline)
1787
+ _roots = staticmethod(hermroots)
1788
+ _fromroots = staticmethod(hermfromroots)
1789
+
1790
+ # Virtual properties
1791
+ domain = np.array(hermdomain)
1792
+ window = np.array(hermdomain)
1793
+ basis_name = 'H'