ZTWHHH commited on
Commit
633cc65
·
verified ·
1 Parent(s): 3b312ef

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. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/__init__.cpython-310.pyc +0 -0
  3. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_basic.cpython-310.pyc +0 -0
  4. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_blas.cpython-310.pyc +0 -0
  5. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_cython_blas.cpython-310.pyc +0 -0
  6. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_cythonized_array_utils.cpython-310.pyc +0 -0
  7. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_decomp.cpython-310.pyc +0 -0
  8. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_decomp_ldl.cpython-310.pyc +0 -0
  9. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_decomp_lu.cpython-310.pyc +0 -0
  10. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_decomp_polar.cpython-310.pyc +0 -0
  11. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_lapack.cpython-310.pyc +0 -0
  12. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_matfuncs.cpython-310.pyc +0 -0
  13. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_solve_toeplitz.cpython-310.pyc +0 -0
  14. mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_solvers.cpython-310.pyc +0 -0
  15. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/__multiarray_api.c +314 -0
  16. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/__multiarray_api.h +1566 -0
  17. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/__ufunc_api.h +314 -0
  18. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/_dtype_api.h +408 -0
  19. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/_neighborhood_iterator_imp.h +90 -0
  20. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/_numpyconfig.h +32 -0
  21. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/arrayscalars.h +186 -0
  22. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/experimental_dtype_api.h +365 -0
  23. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/halffloat.h +70 -0
  24. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/ndarrayobject.h +251 -0
  25. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/ndarraytypes.h +1945 -0
  26. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/noprefix.h +211 -0
  27. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/npy_3kcompat.h +595 -0
  28. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/npy_cpu.h +129 -0
  29. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/npy_endian.h +77 -0
  30. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/npy_interrupt.h +56 -0
  31. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/npy_math.h +563 -0
  32. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/npy_no_deprecated_api.h +20 -0
  33. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/npy_os.h +42 -0
  34. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/numpyconfig.h +138 -0
  35. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/random/LICENSE.txt +21 -0
  36. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/random/bitgen.h +20 -0
  37. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/random/distributions.h +209 -0
  38. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/random/libdivide.h +2079 -0
  39. moondream/lib/python3.10/site-packages/numpy/core/include/numpy/ufuncobject.h +359 -0
  40. moondream/lib/python3.10/site-packages/numpy/fft/__init__.py +212 -0
  41. moondream/lib/python3.10/site-packages/numpy/fft/__init__.pyi +29 -0
  42. moondream/lib/python3.10/site-packages/numpy/fft/__pycache__/_pocketfft.cpython-310.pyc +0 -0
  43. moondream/lib/python3.10/site-packages/numpy/fft/__pycache__/helper.cpython-310.pyc +0 -0
  44. moondream/lib/python3.10/site-packages/numpy/fft/_pocketfft.py +1424 -0
  45. moondream/lib/python3.10/site-packages/numpy/fft/_pocketfft.pyi +108 -0
  46. moondream/lib/python3.10/site-packages/numpy/fft/_pocketfft_internal.cpython-310-x86_64-linux-gnu.so +0 -0
  47. moondream/lib/python3.10/site-packages/numpy/fft/helper.py +221 -0
  48. moondream/lib/python3.10/site-packages/numpy/fft/helper.pyi +47 -0
  49. moondream/lib/python3.10/site-packages/numpy/fft/tests/__init__.py +0 -0
  50. moondream/lib/python3.10/site-packages/numpy/fft/tests/__pycache__/__init__.cpython-310.pyc +0 -0
.gitattributes CHANGED
@@ -563,3 +563,4 @@ mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_ansari_swilk_statistics
563
  mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_qmc_cy.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
564
  mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_stats.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
565
  mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_mstats_basic.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
 
 
563
  mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_qmc_cy.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
564
  mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_stats.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
565
  mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_mstats_basic.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
566
+ moondream/lib/python3.10/site-packages/numpy/ma/__pycache__/core.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (178 Bytes). View file
 
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_basic.cpython-310.pyc ADDED
Binary file (64.1 kB). View file
 
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_blas.cpython-310.pyc ADDED
Binary file (31.3 kB). View file
 
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_cython_blas.cpython-310.pyc ADDED
Binary file (4.23 kB). View file
 
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_cythonized_array_utils.cpython-310.pyc ADDED
Binary file (5.17 kB). View file
 
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_decomp.cpython-310.pyc ADDED
Binary file (96.1 kB). View file
 
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_decomp_ldl.cpython-310.pyc ADDED
Binary file (4.99 kB). View file
 
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_decomp_lu.cpython-310.pyc ADDED
Binary file (11.2 kB). View file
 
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_decomp_polar.cpython-310.pyc ADDED
Binary file (3.2 kB). View file
 
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_lapack.cpython-310.pyc ADDED
Binary file (87.7 kB). View file
 
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_matfuncs.cpython-310.pyc ADDED
Binary file (36 kB). View file
 
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_solve_toeplitz.cpython-310.pyc ADDED
Binary file (4.43 kB). View file
 
mantis_evalkit/lib/python3.10/site-packages/scipy/linalg/tests/__pycache__/test_solvers.cpython-310.pyc ADDED
Binary file (23.8 kB). View file
 
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/__multiarray_api.c ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ (void *) &PyBigArray_Type,
9
+ (void *) &PyArray_Type,
10
+ (void *) &PyArrayDescr_Type,
11
+ (void *) &PyArrayFlags_Type,
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
+ (void *) PyArray_SetNumericOps,
48
+ (void *) PyArray_GetNumericOps,
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_CastTo,
58
+ (void *) PyArray_CastAnyTo,
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_ScalarFromObject,
73
+ (void *) PyArray_GetCastFunc,
74
+ (void *) PyArray_FromDims,
75
+ (void *) PyArray_FromDimsAndDataAndDescr,
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
+ (void *) PyArray_MoveInto,
89
+ (void *) PyArray_CopyInto,
90
+ (void *) PyArray_CopyAnyInto,
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
+ (void *) PyArray_FillObjectArray,
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
+ (void *) PyArray_NewFlagsObject,
123
+ (void *) PyArray_CanCastScalar,
124
+ (void *) PyArray_CompareUCS4,
125
+ (void *) PyArray_RemoveSmallest,
126
+ (void *) PyArray_ElementStrides,
127
+ (void *) PyArray_Item_INCREF,
128
+ (void *) PyArray_Item_XDECREF,
129
+ (void *) PyArray_FieldNames,
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
+ (void *) PyArray_As1D,
171
+ (void *) PyArray_As2D,
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
+ (void *) PyArray_CopyAndTranspose,
179
+ (void *) PyArray_Correlate,
180
+ (void *) PyArray_TypestrConvert,
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
+ (void *) PyArray_TypeNumFromName,
205
+ (void *) PyArray_ClipmodeConverter,
206
+ (void *) PyArray_OutputConverter,
207
+ (void *) PyArray_BroadcastToShape,
208
+ (void *) _PyArray_SigintHandler,
209
+ (void *) _PyArray_GetSigintBuf,
210
+ (void *) PyArray_DescrAlignConverter,
211
+ (void *) PyArray_DescrAlignConverter2,
212
+ (void *) PyArray_SearchsideConverter,
213
+ (void *) PyArray_CheckAxis,
214
+ (void *) PyArray_OverflowMultiplyList,
215
+ (void *) PyArray_CompareString,
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
+ (void *) PyArray_SetDatetimeParseFunction,
227
+ (void *) PyArray_DatetimeToDatetimeStruct,
228
+ (void *) PyArray_TimedeltaToTimedeltaStruct,
229
+ (void *) PyArray_DatetimeStructToDatetime,
230
+ (void *) PyArray_TimedeltaStructToTimedelta,
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
+ (void *) PyArray_GetArrayParamsFromObject,
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
+ (void *) PyDataMem_SetEventHook,
299
+ (NPY_CASTING *) &NPY_DEFAULT_ASSIGN_CASTING,
300
+ (void *) PyArray_MapIterSwapAxes,
301
+ (void *) PyArray_MapIterArray,
302
+ (void *) PyArray_MapIterNext,
303
+ (void *) PyArray_Partition,
304
+ (void *) PyArray_ArgPartition,
305
+ (void *) PyArray_SelectkindConverter,
306
+ (void *) PyDataMem_NEW_ZEROED,
307
+ (void *) PyArray_CheckAnyScalarExact,
308
+ (void *) PyArray_MapIterArrayCopyIfOverlap,
309
+ (void *) PyArray_ResolveWritebackIfCopy,
310
+ (void *) PyArray_SetWritebackIfCopyBase,
311
+ (void *) PyDataMem_SetHandler,
312
+ (void *) PyDataMem_GetHandler,
313
+ (PyObject* *) &PyDataMem_DefaultHandler
314
+ };
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/__multiarray_api.h ADDED
@@ -0,0 +1,1566 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 PyArrayMapIter_Type;
10
+ extern NPY_NO_EXPORT PyTypeObject PyArrayNeighborhoodIter_Type;
11
+ extern NPY_NO_EXPORT PyBoolScalarObject _PyArrayScalar_BoolValues[2];
12
+
13
+ NPY_NO_EXPORT unsigned int PyArray_GetNDArrayCVersion \
14
+ (void);
15
+ extern NPY_NO_EXPORT PyTypeObject PyBigArray_Type;
16
+
17
+ extern NPY_NO_EXPORT PyTypeObject PyArray_Type;
18
+
19
+ extern NPY_NO_EXPORT PyArray_DTypeMeta PyArrayDescr_TypeFull;
20
+ #define PyArrayDescr_Type (*(PyTypeObject *)(&PyArrayDescr_TypeFull))
21
+
22
+ extern NPY_NO_EXPORT PyTypeObject PyArrayFlags_Type;
23
+
24
+ extern NPY_NO_EXPORT PyTypeObject PyArrayIter_Type;
25
+
26
+ extern NPY_NO_EXPORT PyTypeObject PyArrayMultiIter_Type;
27
+
28
+ extern NPY_NO_EXPORT int NPY_NUMUSERTYPES;
29
+
30
+ extern NPY_NO_EXPORT PyTypeObject PyBoolArrType_Type;
31
+
32
+ extern NPY_NO_EXPORT PyBoolScalarObject _PyArrayScalar_BoolValues[2];
33
+
34
+ extern NPY_NO_EXPORT PyTypeObject PyGenericArrType_Type;
35
+
36
+ extern NPY_NO_EXPORT PyTypeObject PyNumberArrType_Type;
37
+
38
+ extern NPY_NO_EXPORT PyTypeObject PyIntegerArrType_Type;
39
+
40
+ extern NPY_NO_EXPORT PyTypeObject PySignedIntegerArrType_Type;
41
+
42
+ extern NPY_NO_EXPORT PyTypeObject PyUnsignedIntegerArrType_Type;
43
+
44
+ extern NPY_NO_EXPORT PyTypeObject PyInexactArrType_Type;
45
+
46
+ extern NPY_NO_EXPORT PyTypeObject PyFloatingArrType_Type;
47
+
48
+ extern NPY_NO_EXPORT PyTypeObject PyComplexFloatingArrType_Type;
49
+
50
+ extern NPY_NO_EXPORT PyTypeObject PyFlexibleArrType_Type;
51
+
52
+ extern NPY_NO_EXPORT PyTypeObject PyCharacterArrType_Type;
53
+
54
+ extern NPY_NO_EXPORT PyTypeObject PyByteArrType_Type;
55
+
56
+ extern NPY_NO_EXPORT PyTypeObject PyShortArrType_Type;
57
+
58
+ extern NPY_NO_EXPORT PyTypeObject PyIntArrType_Type;
59
+
60
+ extern NPY_NO_EXPORT PyTypeObject PyLongArrType_Type;
61
+
62
+ extern NPY_NO_EXPORT PyTypeObject PyLongLongArrType_Type;
63
+
64
+ extern NPY_NO_EXPORT PyTypeObject PyUByteArrType_Type;
65
+
66
+ extern NPY_NO_EXPORT PyTypeObject PyUShortArrType_Type;
67
+
68
+ extern NPY_NO_EXPORT PyTypeObject PyUIntArrType_Type;
69
+
70
+ extern NPY_NO_EXPORT PyTypeObject PyULongArrType_Type;
71
+
72
+ extern NPY_NO_EXPORT PyTypeObject PyULongLongArrType_Type;
73
+
74
+ extern NPY_NO_EXPORT PyTypeObject PyFloatArrType_Type;
75
+
76
+ extern NPY_NO_EXPORT PyTypeObject PyDoubleArrType_Type;
77
+
78
+ extern NPY_NO_EXPORT PyTypeObject PyLongDoubleArrType_Type;
79
+
80
+ extern NPY_NO_EXPORT PyTypeObject PyCFloatArrType_Type;
81
+
82
+ extern NPY_NO_EXPORT PyTypeObject PyCDoubleArrType_Type;
83
+
84
+ extern NPY_NO_EXPORT PyTypeObject PyCLongDoubleArrType_Type;
85
+
86
+ extern NPY_NO_EXPORT PyTypeObject PyObjectArrType_Type;
87
+
88
+ extern NPY_NO_EXPORT PyTypeObject PyStringArrType_Type;
89
+
90
+ extern NPY_NO_EXPORT PyTypeObject PyUnicodeArrType_Type;
91
+
92
+ extern NPY_NO_EXPORT PyTypeObject PyVoidArrType_Type;
93
+
94
+ NPY_NO_EXPORT int PyArray_SetNumericOps \
95
+ (PyObject *);
96
+ NPY_NO_EXPORT PyObject * PyArray_GetNumericOps \
97
+ (void);
98
+ NPY_NO_EXPORT int PyArray_INCREF \
99
+ (PyArrayObject *);
100
+ NPY_NO_EXPORT int PyArray_XDECREF \
101
+ (PyArrayObject *);
102
+ NPY_NO_EXPORT void PyArray_SetStringFunction \
103
+ (PyObject *, int);
104
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrFromType \
105
+ (int);
106
+ NPY_NO_EXPORT PyObject * PyArray_TypeObjectFromType \
107
+ (int);
108
+ NPY_NO_EXPORT char * PyArray_Zero \
109
+ (PyArrayObject *);
110
+ NPY_NO_EXPORT char * PyArray_One \
111
+ (PyArrayObject *);
112
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_CastToType \
113
+ (PyArrayObject *, PyArray_Descr *, int);
114
+ NPY_NO_EXPORT int PyArray_CastTo \
115
+ (PyArrayObject *, PyArrayObject *);
116
+ NPY_NO_EXPORT int PyArray_CastAnyTo \
117
+ (PyArrayObject *, PyArrayObject *);
118
+ NPY_NO_EXPORT int PyArray_CanCastSafely \
119
+ (int, int);
120
+ NPY_NO_EXPORT npy_bool PyArray_CanCastTo \
121
+ (PyArray_Descr *, PyArray_Descr *);
122
+ NPY_NO_EXPORT int PyArray_ObjectType \
123
+ (PyObject *, int);
124
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrFromObject \
125
+ (PyObject *, PyArray_Descr *);
126
+ NPY_NO_EXPORT PyArrayObject ** PyArray_ConvertToCommonType \
127
+ (PyObject *, int *);
128
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrFromScalar \
129
+ (PyObject *);
130
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrFromTypeObject \
131
+ (PyObject *);
132
+ NPY_NO_EXPORT npy_intp PyArray_Size \
133
+ (PyObject *);
134
+ NPY_NO_EXPORT PyObject * PyArray_Scalar \
135
+ (void *, PyArray_Descr *, PyObject *);
136
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromScalar \
137
+ (PyObject *, PyArray_Descr *);
138
+ NPY_NO_EXPORT void PyArray_ScalarAsCtype \
139
+ (PyObject *, void *);
140
+ NPY_NO_EXPORT int PyArray_CastScalarToCtype \
141
+ (PyObject *, void *, PyArray_Descr *);
142
+ NPY_NO_EXPORT int PyArray_CastScalarDirect \
143
+ (PyObject *, PyArray_Descr *, void *, int);
144
+ NPY_NO_EXPORT PyObject * PyArray_ScalarFromObject \
145
+ (PyObject *);
146
+ NPY_NO_EXPORT PyArray_VectorUnaryFunc * PyArray_GetCastFunc \
147
+ (PyArray_Descr *, int);
148
+ NPY_NO_EXPORT PyObject * PyArray_FromDims \
149
+ (int NPY_UNUSED(nd), int *NPY_UNUSED(d), int NPY_UNUSED(type));
150
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_FromDimsAndDataAndDescr \
151
+ (int NPY_UNUSED(nd), int *NPY_UNUSED(d), PyArray_Descr *, char *NPY_UNUSED(data));
152
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromAny \
153
+ (PyObject *, PyArray_Descr *, int, int, int, PyObject *);
154
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(1) PyObject * PyArray_EnsureArray \
155
+ (PyObject *);
156
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(1) PyObject * PyArray_EnsureAnyArray \
157
+ (PyObject *);
158
+ NPY_NO_EXPORT PyObject * PyArray_FromFile \
159
+ (FILE *, PyArray_Descr *, npy_intp, char *);
160
+ NPY_NO_EXPORT PyObject * PyArray_FromString \
161
+ (char *, npy_intp, PyArray_Descr *, npy_intp, char *);
162
+ NPY_NO_EXPORT PyObject * PyArray_FromBuffer \
163
+ (PyObject *, PyArray_Descr *, npy_intp, npy_intp);
164
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromIter \
165
+ (PyObject *, PyArray_Descr *, npy_intp);
166
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(1) PyObject * PyArray_Return \
167
+ (PyArrayObject *);
168
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_GetField \
169
+ (PyArrayObject *, PyArray_Descr *, int);
170
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) int PyArray_SetField \
171
+ (PyArrayObject *, PyArray_Descr *, int, PyObject *);
172
+ NPY_NO_EXPORT PyObject * PyArray_Byteswap \
173
+ (PyArrayObject *, npy_bool);
174
+ NPY_NO_EXPORT PyObject * PyArray_Resize \
175
+ (PyArrayObject *, PyArray_Dims *, int, NPY_ORDER NPY_UNUSED(order));
176
+ NPY_NO_EXPORT int PyArray_MoveInto \
177
+ (PyArrayObject *, PyArrayObject *);
178
+ NPY_NO_EXPORT int PyArray_CopyInto \
179
+ (PyArrayObject *, PyArrayObject *);
180
+ NPY_NO_EXPORT int PyArray_CopyAnyInto \
181
+ (PyArrayObject *, PyArrayObject *);
182
+ NPY_NO_EXPORT int PyArray_CopyObject \
183
+ (PyArrayObject *, PyObject *);
184
+ NPY_NO_EXPORT PyObject * PyArray_NewCopy \
185
+ (PyArrayObject *, NPY_ORDER);
186
+ NPY_NO_EXPORT PyObject * PyArray_ToList \
187
+ (PyArrayObject *);
188
+ NPY_NO_EXPORT PyObject * PyArray_ToString \
189
+ (PyArrayObject *, NPY_ORDER);
190
+ NPY_NO_EXPORT int PyArray_ToFile \
191
+ (PyArrayObject *, FILE *, char *, char *);
192
+ NPY_NO_EXPORT int PyArray_Dump \
193
+ (PyObject *, PyObject *, int);
194
+ NPY_NO_EXPORT PyObject * PyArray_Dumps \
195
+ (PyObject *, int);
196
+ NPY_NO_EXPORT int PyArray_ValidType \
197
+ (int);
198
+ NPY_NO_EXPORT void PyArray_UpdateFlags \
199
+ (PyArrayObject *, int);
200
+ NPY_NO_EXPORT PyObject * PyArray_New \
201
+ (PyTypeObject *, int, npy_intp const *, int, npy_intp const *, void *, int, int, PyObject *);
202
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_NewFromDescr \
203
+ (PyTypeObject *, PyArray_Descr *, int, npy_intp const *, npy_intp const *, void *, int, PyObject *);
204
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrNew \
205
+ (PyArray_Descr *);
206
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrNewFromType \
207
+ (int);
208
+ NPY_NO_EXPORT double PyArray_GetPriority \
209
+ (PyObject *, double);
210
+ NPY_NO_EXPORT PyObject * PyArray_IterNew \
211
+ (PyObject *);
212
+ NPY_NO_EXPORT PyObject* PyArray_MultiIterNew \
213
+ (int, ...);
214
+ NPY_NO_EXPORT int PyArray_PyIntAsInt \
215
+ (PyObject *);
216
+ NPY_NO_EXPORT npy_intp PyArray_PyIntAsIntp \
217
+ (PyObject *);
218
+ NPY_NO_EXPORT int PyArray_Broadcast \
219
+ (PyArrayMultiIterObject *);
220
+ NPY_NO_EXPORT void PyArray_FillObjectArray \
221
+ (PyArrayObject *, PyObject *);
222
+ NPY_NO_EXPORT int PyArray_FillWithScalar \
223
+ (PyArrayObject *, PyObject *);
224
+ NPY_NO_EXPORT npy_bool PyArray_CheckStrides \
225
+ (int, int, npy_intp, npy_intp, npy_intp const *, npy_intp const *);
226
+ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrNewByteorder \
227
+ (PyArray_Descr *, char);
228
+ NPY_NO_EXPORT PyObject * PyArray_IterAllButAxis \
229
+ (PyObject *, int *);
230
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_CheckFromAny \
231
+ (PyObject *, PyArray_Descr *, int, int, int, PyObject *);
232
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromArray \
233
+ (PyArrayObject *, PyArray_Descr *, int);
234
+ NPY_NO_EXPORT PyObject * PyArray_FromInterface \
235
+ (PyObject *);
236
+ NPY_NO_EXPORT PyObject * PyArray_FromStructInterface \
237
+ (PyObject *);
238
+ NPY_NO_EXPORT PyObject * PyArray_FromArrayAttr \
239
+ (PyObject *, PyArray_Descr *, PyObject *);
240
+ NPY_NO_EXPORT NPY_SCALARKIND PyArray_ScalarKind \
241
+ (int, PyArrayObject **);
242
+ NPY_NO_EXPORT int PyArray_CanCoerceScalar \
243
+ (int, int, NPY_SCALARKIND);
244
+ NPY_NO_EXPORT PyObject * PyArray_NewFlagsObject \
245
+ (PyObject *);
246
+ NPY_NO_EXPORT npy_bool PyArray_CanCastScalar \
247
+ (PyTypeObject *, PyTypeObject *);
248
+ NPY_NO_EXPORT int PyArray_CompareUCS4 \
249
+ (npy_ucs4 const *, npy_ucs4 const *, size_t);
250
+ NPY_NO_EXPORT int PyArray_RemoveSmallest \
251
+ (PyArrayMultiIterObject *);
252
+ NPY_NO_EXPORT int PyArray_ElementStrides \
253
+ (PyObject *);
254
+ NPY_NO_EXPORT void PyArray_Item_INCREF \
255
+ (char *, PyArray_Descr *);
256
+ NPY_NO_EXPORT void PyArray_Item_XDECREF \
257
+ (char *, PyArray_Descr *);
258
+ NPY_NO_EXPORT PyObject * PyArray_FieldNames \
259
+ (PyObject *);
260
+ NPY_NO_EXPORT PyObject * PyArray_Transpose \
261
+ (PyArrayObject *, PyArray_Dims *);
262
+ NPY_NO_EXPORT PyObject * PyArray_TakeFrom \
263
+ (PyArrayObject *, PyObject *, int, PyArrayObject *, NPY_CLIPMODE);
264
+ NPY_NO_EXPORT PyObject * PyArray_PutTo \
265
+ (PyArrayObject *, PyObject*, PyObject *, NPY_CLIPMODE);
266
+ NPY_NO_EXPORT PyObject * PyArray_PutMask \
267
+ (PyArrayObject *, PyObject*, PyObject*);
268
+ NPY_NO_EXPORT PyObject * PyArray_Repeat \
269
+ (PyArrayObject *, PyObject *, int);
270
+ NPY_NO_EXPORT PyObject * PyArray_Choose \
271
+ (PyArrayObject *, PyObject *, PyArrayObject *, NPY_CLIPMODE);
272
+ NPY_NO_EXPORT int PyArray_Sort \
273
+ (PyArrayObject *, int, NPY_SORTKIND);
274
+ NPY_NO_EXPORT PyObject * PyArray_ArgSort \
275
+ (PyArrayObject *, int, NPY_SORTKIND);
276
+ NPY_NO_EXPORT PyObject * PyArray_SearchSorted \
277
+ (PyArrayObject *, PyObject *, NPY_SEARCHSIDE, PyObject *);
278
+ NPY_NO_EXPORT PyObject * PyArray_ArgMax \
279
+ (PyArrayObject *, int, PyArrayObject *);
280
+ NPY_NO_EXPORT PyObject * PyArray_ArgMin \
281
+ (PyArrayObject *, int, PyArrayObject *);
282
+ NPY_NO_EXPORT PyObject * PyArray_Reshape \
283
+ (PyArrayObject *, PyObject *);
284
+ NPY_NO_EXPORT PyObject * PyArray_Newshape \
285
+ (PyArrayObject *, PyArray_Dims *, NPY_ORDER);
286
+ NPY_NO_EXPORT PyObject * PyArray_Squeeze \
287
+ (PyArrayObject *);
288
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_View \
289
+ (PyArrayObject *, PyArray_Descr *, PyTypeObject *);
290
+ NPY_NO_EXPORT PyObject * PyArray_SwapAxes \
291
+ (PyArrayObject *, int, int);
292
+ NPY_NO_EXPORT PyObject * PyArray_Max \
293
+ (PyArrayObject *, int, PyArrayObject *);
294
+ NPY_NO_EXPORT PyObject * PyArray_Min \
295
+ (PyArrayObject *, int, PyArrayObject *);
296
+ NPY_NO_EXPORT PyObject * PyArray_Ptp \
297
+ (PyArrayObject *, int, PyArrayObject *);
298
+ NPY_NO_EXPORT PyObject * PyArray_Mean \
299
+ (PyArrayObject *, int, int, PyArrayObject *);
300
+ NPY_NO_EXPORT PyObject * PyArray_Trace \
301
+ (PyArrayObject *, int, int, int, int, PyArrayObject *);
302
+ NPY_NO_EXPORT PyObject * PyArray_Diagonal \
303
+ (PyArrayObject *, int, int, int);
304
+ NPY_NO_EXPORT PyObject * PyArray_Clip \
305
+ (PyArrayObject *, PyObject *, PyObject *, PyArrayObject *);
306
+ NPY_NO_EXPORT PyObject * PyArray_Conjugate \
307
+ (PyArrayObject *, PyArrayObject *);
308
+ NPY_NO_EXPORT PyObject * PyArray_Nonzero \
309
+ (PyArrayObject *);
310
+ NPY_NO_EXPORT PyObject * PyArray_Std \
311
+ (PyArrayObject *, int, int, PyArrayObject *, int);
312
+ NPY_NO_EXPORT PyObject * PyArray_Sum \
313
+ (PyArrayObject *, int, int, PyArrayObject *);
314
+ NPY_NO_EXPORT PyObject * PyArray_CumSum \
315
+ (PyArrayObject *, int, int, PyArrayObject *);
316
+ NPY_NO_EXPORT PyObject * PyArray_Prod \
317
+ (PyArrayObject *, int, int, PyArrayObject *);
318
+ NPY_NO_EXPORT PyObject * PyArray_CumProd \
319
+ (PyArrayObject *, int, int, PyArrayObject *);
320
+ NPY_NO_EXPORT PyObject * PyArray_All \
321
+ (PyArrayObject *, int, PyArrayObject *);
322
+ NPY_NO_EXPORT PyObject * PyArray_Any \
323
+ (PyArrayObject *, int, PyArrayObject *);
324
+ NPY_NO_EXPORT PyObject * PyArray_Compress \
325
+ (PyArrayObject *, PyObject *, int, PyArrayObject *);
326
+ NPY_NO_EXPORT PyObject * PyArray_Flatten \
327
+ (PyArrayObject *, NPY_ORDER);
328
+ NPY_NO_EXPORT PyObject * PyArray_Ravel \
329
+ (PyArrayObject *, NPY_ORDER);
330
+ NPY_NO_EXPORT npy_intp PyArray_MultiplyList \
331
+ (npy_intp const *, int);
332
+ NPY_NO_EXPORT int PyArray_MultiplyIntList \
333
+ (int const *, int);
334
+ NPY_NO_EXPORT void * PyArray_GetPtr \
335
+ (PyArrayObject *, npy_intp const*);
336
+ NPY_NO_EXPORT int PyArray_CompareLists \
337
+ (npy_intp const *, npy_intp const *, int);
338
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(5) int PyArray_AsCArray \
339
+ (PyObject **, void *, npy_intp *, int, PyArray_Descr*);
340
+ NPY_NO_EXPORT int PyArray_As1D \
341
+ (PyObject **NPY_UNUSED(op), char **NPY_UNUSED(ptr), int *NPY_UNUSED(d1), int NPY_UNUSED(typecode));
342
+ NPY_NO_EXPORT int PyArray_As2D \
343
+ (PyObject **NPY_UNUSED(op), char ***NPY_UNUSED(ptr), int *NPY_UNUSED(d1), int *NPY_UNUSED(d2), int NPY_UNUSED(typecode));
344
+ NPY_NO_EXPORT int PyArray_Free \
345
+ (PyObject *, void *);
346
+ NPY_NO_EXPORT int PyArray_Converter \
347
+ (PyObject *, PyObject **);
348
+ NPY_NO_EXPORT int PyArray_IntpFromSequence \
349
+ (PyObject *, npy_intp *, int);
350
+ NPY_NO_EXPORT PyObject * PyArray_Concatenate \
351
+ (PyObject *, int);
352
+ NPY_NO_EXPORT PyObject * PyArray_InnerProduct \
353
+ (PyObject *, PyObject *);
354
+ NPY_NO_EXPORT PyObject * PyArray_MatrixProduct \
355
+ (PyObject *, PyObject *);
356
+ NPY_NO_EXPORT PyObject * PyArray_CopyAndTranspose \
357
+ (PyObject *);
358
+ NPY_NO_EXPORT PyObject * PyArray_Correlate \
359
+ (PyObject *, PyObject *, int);
360
+ NPY_NO_EXPORT int PyArray_TypestrConvert \
361
+ (int, int);
362
+ NPY_NO_EXPORT int PyArray_DescrConverter \
363
+ (PyObject *, PyArray_Descr **);
364
+ NPY_NO_EXPORT int PyArray_DescrConverter2 \
365
+ (PyObject *, PyArray_Descr **);
366
+ NPY_NO_EXPORT int PyArray_IntpConverter \
367
+ (PyObject *, PyArray_Dims *);
368
+ NPY_NO_EXPORT int PyArray_BufferConverter \
369
+ (PyObject *, PyArray_Chunk *);
370
+ NPY_NO_EXPORT int PyArray_AxisConverter \
371
+ (PyObject *, int *);
372
+ NPY_NO_EXPORT int PyArray_BoolConverter \
373
+ (PyObject *, npy_bool *);
374
+ NPY_NO_EXPORT int PyArray_ByteorderConverter \
375
+ (PyObject *, char *);
376
+ NPY_NO_EXPORT int PyArray_OrderConverter \
377
+ (PyObject *, NPY_ORDER *);
378
+ NPY_NO_EXPORT unsigned char PyArray_EquivTypes \
379
+ (PyArray_Descr *, PyArray_Descr *);
380
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_Zeros \
381
+ (int, npy_intp const *, PyArray_Descr *, int);
382
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_Empty \
383
+ (int, npy_intp const *, PyArray_Descr *, int);
384
+ NPY_NO_EXPORT PyObject * PyArray_Where \
385
+ (PyObject *, PyObject *, PyObject *);
386
+ NPY_NO_EXPORT PyObject * PyArray_Arange \
387
+ (double, double, double, int);
388
+ NPY_NO_EXPORT PyObject * PyArray_ArangeObj \
389
+ (PyObject *, PyObject *, PyObject *, PyArray_Descr *);
390
+ NPY_NO_EXPORT int PyArray_SortkindConverter \
391
+ (PyObject *, NPY_SORTKIND *);
392
+ NPY_NO_EXPORT PyObject * PyArray_LexSort \
393
+ (PyObject *, int);
394
+ NPY_NO_EXPORT PyObject * PyArray_Round \
395
+ (PyArrayObject *, int, PyArrayObject *);
396
+ NPY_NO_EXPORT unsigned char PyArray_EquivTypenums \
397
+ (int, int);
398
+ NPY_NO_EXPORT int PyArray_RegisterDataType \
399
+ (PyArray_Descr *);
400
+ NPY_NO_EXPORT int PyArray_RegisterCastFunc \
401
+ (PyArray_Descr *, int, PyArray_VectorUnaryFunc *);
402
+ NPY_NO_EXPORT int PyArray_RegisterCanCast \
403
+ (PyArray_Descr *, int, NPY_SCALARKIND);
404
+ NPY_NO_EXPORT void PyArray_InitArrFuncs \
405
+ (PyArray_ArrFuncs *);
406
+ NPY_NO_EXPORT PyObject * PyArray_IntTupleFromIntp \
407
+ (int, npy_intp const *);
408
+ NPY_NO_EXPORT int PyArray_TypeNumFromName \
409
+ (char const *);
410
+ NPY_NO_EXPORT int PyArray_ClipmodeConverter \
411
+ (PyObject *, NPY_CLIPMODE *);
412
+ NPY_NO_EXPORT int PyArray_OutputConverter \
413
+ (PyObject *, PyArrayObject **);
414
+ NPY_NO_EXPORT PyObject * PyArray_BroadcastToShape \
415
+ (PyObject *, npy_intp *, int);
416
+ NPY_NO_EXPORT void _PyArray_SigintHandler \
417
+ (int);
418
+ NPY_NO_EXPORT void* _PyArray_GetSigintBuf \
419
+ (void);
420
+ NPY_NO_EXPORT int PyArray_DescrAlignConverter \
421
+ (PyObject *, PyArray_Descr **);
422
+ NPY_NO_EXPORT int PyArray_DescrAlignConverter2 \
423
+ (PyObject *, PyArray_Descr **);
424
+ NPY_NO_EXPORT int PyArray_SearchsideConverter \
425
+ (PyObject *, void *);
426
+ NPY_NO_EXPORT PyObject * PyArray_CheckAxis \
427
+ (PyArrayObject *, int *, int);
428
+ NPY_NO_EXPORT npy_intp PyArray_OverflowMultiplyList \
429
+ (npy_intp const *, int);
430
+ NPY_NO_EXPORT int PyArray_CompareString \
431
+ (const char *, const char *, size_t);
432
+ NPY_NO_EXPORT PyObject* PyArray_MultiIterFromObjects \
433
+ (PyObject **, int, int, ...);
434
+ NPY_NO_EXPORT int PyArray_GetEndianness \
435
+ (void);
436
+ NPY_NO_EXPORT unsigned int PyArray_GetNDArrayCFeatureVersion \
437
+ (void);
438
+ NPY_NO_EXPORT PyObject * PyArray_Correlate2 \
439
+ (PyObject *, PyObject *, int);
440
+ NPY_NO_EXPORT PyObject* PyArray_NeighborhoodIterNew \
441
+ (PyArrayIterObject *, const npy_intp *, int, PyArrayObject*);
442
+ extern NPY_NO_EXPORT PyTypeObject PyTimeIntegerArrType_Type;
443
+
444
+ extern NPY_NO_EXPORT PyTypeObject PyDatetimeArrType_Type;
445
+
446
+ extern NPY_NO_EXPORT PyTypeObject PyTimedeltaArrType_Type;
447
+
448
+ extern NPY_NO_EXPORT PyTypeObject PyHalfArrType_Type;
449
+
450
+ extern NPY_NO_EXPORT PyTypeObject NpyIter_Type;
451
+
452
+ NPY_NO_EXPORT void PyArray_SetDatetimeParseFunction \
453
+ (PyObject *NPY_UNUSED(op));
454
+ NPY_NO_EXPORT void PyArray_DatetimeToDatetimeStruct \
455
+ (npy_datetime NPY_UNUSED(val), NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_datetimestruct *);
456
+ NPY_NO_EXPORT void PyArray_TimedeltaToTimedeltaStruct \
457
+ (npy_timedelta NPY_UNUSED(val), NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_timedeltastruct *);
458
+ NPY_NO_EXPORT npy_datetime PyArray_DatetimeStructToDatetime \
459
+ (NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_datetimestruct *NPY_UNUSED(d));
460
+ NPY_NO_EXPORT npy_datetime PyArray_TimedeltaStructToTimedelta \
461
+ (NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_timedeltastruct *NPY_UNUSED(d));
462
+ NPY_NO_EXPORT NpyIter * NpyIter_New \
463
+ (PyArrayObject *, npy_uint32, NPY_ORDER, NPY_CASTING, PyArray_Descr*);
464
+ NPY_NO_EXPORT NpyIter * NpyIter_MultiNew \
465
+ (int, PyArrayObject **, npy_uint32, NPY_ORDER, NPY_CASTING, npy_uint32 *, PyArray_Descr **);
466
+ NPY_NO_EXPORT NpyIter * NpyIter_AdvancedNew \
467
+ (int, PyArrayObject **, npy_uint32, NPY_ORDER, NPY_CASTING, npy_uint32 *, PyArray_Descr **, int, int **, npy_intp *, npy_intp);
468
+ NPY_NO_EXPORT NpyIter * NpyIter_Copy \
469
+ (NpyIter *);
470
+ NPY_NO_EXPORT int NpyIter_Deallocate \
471
+ (NpyIter *);
472
+ NPY_NO_EXPORT npy_bool NpyIter_HasDelayedBufAlloc \
473
+ (NpyIter *);
474
+ NPY_NO_EXPORT npy_bool NpyIter_HasExternalLoop \
475
+ (NpyIter *);
476
+ NPY_NO_EXPORT int NpyIter_EnableExternalLoop \
477
+ (NpyIter *);
478
+ NPY_NO_EXPORT npy_intp * NpyIter_GetInnerStrideArray \
479
+ (NpyIter *);
480
+ NPY_NO_EXPORT npy_intp * NpyIter_GetInnerLoopSizePtr \
481
+ (NpyIter *);
482
+ NPY_NO_EXPORT int NpyIter_Reset \
483
+ (NpyIter *, char **);
484
+ NPY_NO_EXPORT int NpyIter_ResetBasePointers \
485
+ (NpyIter *, char **, char **);
486
+ NPY_NO_EXPORT int NpyIter_ResetToIterIndexRange \
487
+ (NpyIter *, npy_intp, npy_intp, char **);
488
+ NPY_NO_EXPORT int NpyIter_GetNDim \
489
+ (NpyIter *);
490
+ NPY_NO_EXPORT int NpyIter_GetNOp \
491
+ (NpyIter *);
492
+ NPY_NO_EXPORT NpyIter_IterNextFunc * NpyIter_GetIterNext \
493
+ (NpyIter *, char **);
494
+ NPY_NO_EXPORT npy_intp NpyIter_GetIterSize \
495
+ (NpyIter *);
496
+ NPY_NO_EXPORT void NpyIter_GetIterIndexRange \
497
+ (NpyIter *, npy_intp *, npy_intp *);
498
+ NPY_NO_EXPORT npy_intp NpyIter_GetIterIndex \
499
+ (NpyIter *);
500
+ NPY_NO_EXPORT int NpyIter_GotoIterIndex \
501
+ (NpyIter *, npy_intp);
502
+ NPY_NO_EXPORT npy_bool NpyIter_HasMultiIndex \
503
+ (NpyIter *);
504
+ NPY_NO_EXPORT int NpyIter_GetShape \
505
+ (NpyIter *, npy_intp *);
506
+ NPY_NO_EXPORT NpyIter_GetMultiIndexFunc * NpyIter_GetGetMultiIndex \
507
+ (NpyIter *, char **);
508
+ NPY_NO_EXPORT int NpyIter_GotoMultiIndex \
509
+ (NpyIter *, npy_intp const *);
510
+ NPY_NO_EXPORT int NpyIter_RemoveMultiIndex \
511
+ (NpyIter *);
512
+ NPY_NO_EXPORT npy_bool NpyIter_HasIndex \
513
+ (NpyIter *);
514
+ NPY_NO_EXPORT npy_bool NpyIter_IsBuffered \
515
+ (NpyIter *);
516
+ NPY_NO_EXPORT npy_bool NpyIter_IsGrowInner \
517
+ (NpyIter *);
518
+ NPY_NO_EXPORT npy_intp NpyIter_GetBufferSize \
519
+ (NpyIter *);
520
+ NPY_NO_EXPORT npy_intp * NpyIter_GetIndexPtr \
521
+ (NpyIter *);
522
+ NPY_NO_EXPORT int NpyIter_GotoIndex \
523
+ (NpyIter *, npy_intp);
524
+ NPY_NO_EXPORT char ** NpyIter_GetDataPtrArray \
525
+ (NpyIter *);
526
+ NPY_NO_EXPORT PyArray_Descr ** NpyIter_GetDescrArray \
527
+ (NpyIter *);
528
+ NPY_NO_EXPORT PyArrayObject ** NpyIter_GetOperandArray \
529
+ (NpyIter *);
530
+ NPY_NO_EXPORT PyArrayObject * NpyIter_GetIterView \
531
+ (NpyIter *, npy_intp);
532
+ NPY_NO_EXPORT void NpyIter_GetReadFlags \
533
+ (NpyIter *, char *);
534
+ NPY_NO_EXPORT void NpyIter_GetWriteFlags \
535
+ (NpyIter *, char *);
536
+ NPY_NO_EXPORT void NpyIter_DebugPrint \
537
+ (NpyIter *);
538
+ NPY_NO_EXPORT npy_bool NpyIter_IterationNeedsAPI \
539
+ (NpyIter *);
540
+ NPY_NO_EXPORT void NpyIter_GetInnerFixedStrideArray \
541
+ (NpyIter *, npy_intp *);
542
+ NPY_NO_EXPORT int NpyIter_RemoveAxis \
543
+ (NpyIter *, int);
544
+ NPY_NO_EXPORT npy_intp * NpyIter_GetAxisStrideArray \
545
+ (NpyIter *, int);
546
+ NPY_NO_EXPORT npy_bool NpyIter_RequiresBuffering \
547
+ (NpyIter *);
548
+ NPY_NO_EXPORT char ** NpyIter_GetInitialDataPtrArray \
549
+ (NpyIter *);
550
+ NPY_NO_EXPORT int NpyIter_CreateCompatibleStrides \
551
+ (NpyIter *, npy_intp, npy_intp *);
552
+ NPY_NO_EXPORT int PyArray_CastingConverter \
553
+ (PyObject *, NPY_CASTING *);
554
+ NPY_NO_EXPORT npy_intp PyArray_CountNonzero \
555
+ (PyArrayObject *);
556
+ NPY_NO_EXPORT PyArray_Descr * PyArray_PromoteTypes \
557
+ (PyArray_Descr *, PyArray_Descr *);
558
+ NPY_NO_EXPORT PyArray_Descr * PyArray_MinScalarType \
559
+ (PyArrayObject *);
560
+ NPY_NO_EXPORT PyArray_Descr * PyArray_ResultType \
561
+ (npy_intp, PyArrayObject *arrs[], npy_intp, PyArray_Descr *descrs[]);
562
+ NPY_NO_EXPORT npy_bool PyArray_CanCastArrayTo \
563
+ (PyArrayObject *, PyArray_Descr *, NPY_CASTING);
564
+ NPY_NO_EXPORT npy_bool PyArray_CanCastTypeTo \
565
+ (PyArray_Descr *, PyArray_Descr *, NPY_CASTING);
566
+ NPY_NO_EXPORT PyArrayObject * PyArray_EinsteinSum \
567
+ (char *, npy_intp, PyArrayObject **, PyArray_Descr *, NPY_ORDER, NPY_CASTING, PyArrayObject *);
568
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_NewLikeArray \
569
+ (PyArrayObject *, NPY_ORDER, PyArray_Descr *, int);
570
+ NPY_NO_EXPORT int PyArray_GetArrayParamsFromObject \
571
+ (PyObject *NPY_UNUSED(op), PyArray_Descr *NPY_UNUSED(requested_dtype), npy_bool NPY_UNUSED(writeable), PyArray_Descr **NPY_UNUSED(out_dtype), int *NPY_UNUSED(out_ndim), npy_intp *NPY_UNUSED(out_dims), PyArrayObject **NPY_UNUSED(out_arr), PyObject *NPY_UNUSED(context));
572
+ NPY_NO_EXPORT int PyArray_ConvertClipmodeSequence \
573
+ (PyObject *, NPY_CLIPMODE *, int);
574
+ NPY_NO_EXPORT PyObject * PyArray_MatrixProduct2 \
575
+ (PyObject *, PyObject *, PyArrayObject*);
576
+ NPY_NO_EXPORT npy_bool NpyIter_IsFirstVisit \
577
+ (NpyIter *, int);
578
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) int PyArray_SetBaseObject \
579
+ (PyArrayObject *, PyObject *);
580
+ NPY_NO_EXPORT void PyArray_CreateSortedStridePerm \
581
+ (int, npy_intp const *, npy_stride_sort_item *);
582
+ NPY_NO_EXPORT void PyArray_RemoveAxesInPlace \
583
+ (PyArrayObject *, const npy_bool *);
584
+ NPY_NO_EXPORT void PyArray_DebugPrint \
585
+ (PyArrayObject *);
586
+ NPY_NO_EXPORT int PyArray_FailUnlessWriteable \
587
+ (PyArrayObject *, const char *);
588
+ NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) int PyArray_SetUpdateIfCopyBase \
589
+ (PyArrayObject *, PyArrayObject *);
590
+ NPY_NO_EXPORT void * PyDataMem_NEW \
591
+ (size_t);
592
+ NPY_NO_EXPORT void PyDataMem_FREE \
593
+ (void *);
594
+ NPY_NO_EXPORT void * PyDataMem_RENEW \
595
+ (void *, size_t);
596
+ NPY_NO_EXPORT PyDataMem_EventHookFunc * PyDataMem_SetEventHook \
597
+ (PyDataMem_EventHookFunc *, void *, void **);
598
+ extern NPY_NO_EXPORT NPY_CASTING NPY_DEFAULT_ASSIGN_CASTING;
599
+
600
+ NPY_NO_EXPORT void PyArray_MapIterSwapAxes \
601
+ (PyArrayMapIterObject *, PyArrayObject **, int);
602
+ NPY_NO_EXPORT PyObject * PyArray_MapIterArray \
603
+ (PyArrayObject *, PyObject *);
604
+ NPY_NO_EXPORT void PyArray_MapIterNext \
605
+ (PyArrayMapIterObject *);
606
+ NPY_NO_EXPORT int PyArray_Partition \
607
+ (PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND);
608
+ NPY_NO_EXPORT PyObject * PyArray_ArgPartition \
609
+ (PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND);
610
+ NPY_NO_EXPORT int PyArray_SelectkindConverter \
611
+ (PyObject *, NPY_SELECTKIND *);
612
+ NPY_NO_EXPORT void * PyDataMem_NEW_ZEROED \
613
+ (size_t, size_t);
614
+ NPY_NO_EXPORT int PyArray_CheckAnyScalarExact \
615
+ (PyObject *);
616
+ NPY_NO_EXPORT PyObject * PyArray_MapIterArrayCopyIfOverlap \
617
+ (PyArrayObject *, PyObject *, int, PyArrayObject *);
618
+ NPY_NO_EXPORT int PyArray_ResolveWritebackIfCopy \
619
+ (PyArrayObject *);
620
+ NPY_NO_EXPORT int PyArray_SetWritebackIfCopyBase \
621
+ (PyArrayObject *, PyArrayObject *);
622
+ NPY_NO_EXPORT PyObject * PyDataMem_SetHandler \
623
+ (PyObject *);
624
+ NPY_NO_EXPORT PyObject * PyDataMem_GetHandler \
625
+ (void);
626
+ extern NPY_NO_EXPORT PyObject* PyDataMem_DefaultHandler;
627
+
628
+
629
+ #else
630
+
631
+ #if defined(PY_ARRAY_UNIQUE_SYMBOL)
632
+ #define PyArray_API PY_ARRAY_UNIQUE_SYMBOL
633
+ #endif
634
+
635
+ #if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
636
+ extern void **PyArray_API;
637
+ #else
638
+ #if defined(PY_ARRAY_UNIQUE_SYMBOL)
639
+ void **PyArray_API;
640
+ #else
641
+ static void **PyArray_API=NULL;
642
+ #endif
643
+ #endif
644
+
645
+ #define PyArray_GetNDArrayCVersion \
646
+ (*(unsigned int (*)(void)) \
647
+ PyArray_API[0])
648
+ #define PyBigArray_Type (*(PyTypeObject *)PyArray_API[1])
649
+ #define PyArray_Type (*(PyTypeObject *)PyArray_API[2])
650
+ #define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[3])
651
+ #define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[4])
652
+ #define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[5])
653
+ #define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[6])
654
+ #define NPY_NUMUSERTYPES (*(int *)PyArray_API[7])
655
+ #define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[8])
656
+ #define _PyArrayScalar_BoolValues ((PyBoolScalarObject *)PyArray_API[9])
657
+ #define PyGenericArrType_Type (*(PyTypeObject *)PyArray_API[10])
658
+ #define PyNumberArrType_Type (*(PyTypeObject *)PyArray_API[11])
659
+ #define PyIntegerArrType_Type (*(PyTypeObject *)PyArray_API[12])
660
+ #define PySignedIntegerArrType_Type (*(PyTypeObject *)PyArray_API[13])
661
+ #define PyUnsignedIntegerArrType_Type (*(PyTypeObject *)PyArray_API[14])
662
+ #define PyInexactArrType_Type (*(PyTypeObject *)PyArray_API[15])
663
+ #define PyFloatingArrType_Type (*(PyTypeObject *)PyArray_API[16])
664
+ #define PyComplexFloatingArrType_Type (*(PyTypeObject *)PyArray_API[17])
665
+ #define PyFlexibleArrType_Type (*(PyTypeObject *)PyArray_API[18])
666
+ #define PyCharacterArrType_Type (*(PyTypeObject *)PyArray_API[19])
667
+ #define PyByteArrType_Type (*(PyTypeObject *)PyArray_API[20])
668
+ #define PyShortArrType_Type (*(PyTypeObject *)PyArray_API[21])
669
+ #define PyIntArrType_Type (*(PyTypeObject *)PyArray_API[22])
670
+ #define PyLongArrType_Type (*(PyTypeObject *)PyArray_API[23])
671
+ #define PyLongLongArrType_Type (*(PyTypeObject *)PyArray_API[24])
672
+ #define PyUByteArrType_Type (*(PyTypeObject *)PyArray_API[25])
673
+ #define PyUShortArrType_Type (*(PyTypeObject *)PyArray_API[26])
674
+ #define PyUIntArrType_Type (*(PyTypeObject *)PyArray_API[27])
675
+ #define PyULongArrType_Type (*(PyTypeObject *)PyArray_API[28])
676
+ #define PyULongLongArrType_Type (*(PyTypeObject *)PyArray_API[29])
677
+ #define PyFloatArrType_Type (*(PyTypeObject *)PyArray_API[30])
678
+ #define PyDoubleArrType_Type (*(PyTypeObject *)PyArray_API[31])
679
+ #define PyLongDoubleArrType_Type (*(PyTypeObject *)PyArray_API[32])
680
+ #define PyCFloatArrType_Type (*(PyTypeObject *)PyArray_API[33])
681
+ #define PyCDoubleArrType_Type (*(PyTypeObject *)PyArray_API[34])
682
+ #define PyCLongDoubleArrType_Type (*(PyTypeObject *)PyArray_API[35])
683
+ #define PyObjectArrType_Type (*(PyTypeObject *)PyArray_API[36])
684
+ #define PyStringArrType_Type (*(PyTypeObject *)PyArray_API[37])
685
+ #define PyUnicodeArrType_Type (*(PyTypeObject *)PyArray_API[38])
686
+ #define PyVoidArrType_Type (*(PyTypeObject *)PyArray_API[39])
687
+ #define PyArray_SetNumericOps \
688
+ (*(int (*)(PyObject *)) \
689
+ PyArray_API[40])
690
+ #define PyArray_GetNumericOps \
691
+ (*(PyObject * (*)(void)) \
692
+ PyArray_API[41])
693
+ #define PyArray_INCREF \
694
+ (*(int (*)(PyArrayObject *)) \
695
+ PyArray_API[42])
696
+ #define PyArray_XDECREF \
697
+ (*(int (*)(PyArrayObject *)) \
698
+ PyArray_API[43])
699
+ #define PyArray_SetStringFunction \
700
+ (*(void (*)(PyObject *, int)) \
701
+ PyArray_API[44])
702
+ #define PyArray_DescrFromType \
703
+ (*(PyArray_Descr * (*)(int)) \
704
+ PyArray_API[45])
705
+ #define PyArray_TypeObjectFromType \
706
+ (*(PyObject * (*)(int)) \
707
+ PyArray_API[46])
708
+ #define PyArray_Zero \
709
+ (*(char * (*)(PyArrayObject *)) \
710
+ PyArray_API[47])
711
+ #define PyArray_One \
712
+ (*(char * (*)(PyArrayObject *)) \
713
+ PyArray_API[48])
714
+ #define PyArray_CastToType \
715
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Descr *, int)) \
716
+ PyArray_API[49])
717
+ #define PyArray_CastTo \
718
+ (*(int (*)(PyArrayObject *, PyArrayObject *)) \
719
+ PyArray_API[50])
720
+ #define PyArray_CastAnyTo \
721
+ (*(int (*)(PyArrayObject *, PyArrayObject *)) \
722
+ PyArray_API[51])
723
+ #define PyArray_CanCastSafely \
724
+ (*(int (*)(int, int)) \
725
+ PyArray_API[52])
726
+ #define PyArray_CanCastTo \
727
+ (*(npy_bool (*)(PyArray_Descr *, PyArray_Descr *)) \
728
+ PyArray_API[53])
729
+ #define PyArray_ObjectType \
730
+ (*(int (*)(PyObject *, int)) \
731
+ PyArray_API[54])
732
+ #define PyArray_DescrFromObject \
733
+ (*(PyArray_Descr * (*)(PyObject *, PyArray_Descr *)) \
734
+ PyArray_API[55])
735
+ #define PyArray_ConvertToCommonType \
736
+ (*(PyArrayObject ** (*)(PyObject *, int *)) \
737
+ PyArray_API[56])
738
+ #define PyArray_DescrFromScalar \
739
+ (*(PyArray_Descr * (*)(PyObject *)) \
740
+ PyArray_API[57])
741
+ #define PyArray_DescrFromTypeObject \
742
+ (*(PyArray_Descr * (*)(PyObject *)) \
743
+ PyArray_API[58])
744
+ #define PyArray_Size \
745
+ (*(npy_intp (*)(PyObject *)) \
746
+ PyArray_API[59])
747
+ #define PyArray_Scalar \
748
+ (*(PyObject * (*)(void *, PyArray_Descr *, PyObject *)) \
749
+ PyArray_API[60])
750
+ #define PyArray_FromScalar \
751
+ (*(PyObject * (*)(PyObject *, PyArray_Descr *)) \
752
+ PyArray_API[61])
753
+ #define PyArray_ScalarAsCtype \
754
+ (*(void (*)(PyObject *, void *)) \
755
+ PyArray_API[62])
756
+ #define PyArray_CastScalarToCtype \
757
+ (*(int (*)(PyObject *, void *, PyArray_Descr *)) \
758
+ PyArray_API[63])
759
+ #define PyArray_CastScalarDirect \
760
+ (*(int (*)(PyObject *, PyArray_Descr *, void *, int)) \
761
+ PyArray_API[64])
762
+ #define PyArray_ScalarFromObject \
763
+ (*(PyObject * (*)(PyObject *)) \
764
+ PyArray_API[65])
765
+ #define PyArray_GetCastFunc \
766
+ (*(PyArray_VectorUnaryFunc * (*)(PyArray_Descr *, int)) \
767
+ PyArray_API[66])
768
+ #define PyArray_FromDims \
769
+ (*(PyObject * (*)(int NPY_UNUSED(nd), int *NPY_UNUSED(d), int NPY_UNUSED(type))) \
770
+ PyArray_API[67])
771
+ #define PyArray_FromDimsAndDataAndDescr \
772
+ (*(PyObject * (*)(int NPY_UNUSED(nd), int *NPY_UNUSED(d), PyArray_Descr *, char *NPY_UNUSED(data))) \
773
+ PyArray_API[68])
774
+ #define PyArray_FromAny \
775
+ (*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) \
776
+ PyArray_API[69])
777
+ #define PyArray_EnsureArray \
778
+ (*(PyObject * (*)(PyObject *)) \
779
+ PyArray_API[70])
780
+ #define PyArray_EnsureAnyArray \
781
+ (*(PyObject * (*)(PyObject *)) \
782
+ PyArray_API[71])
783
+ #define PyArray_FromFile \
784
+ (*(PyObject * (*)(FILE *, PyArray_Descr *, npy_intp, char *)) \
785
+ PyArray_API[72])
786
+ #define PyArray_FromString \
787
+ (*(PyObject * (*)(char *, npy_intp, PyArray_Descr *, npy_intp, char *)) \
788
+ PyArray_API[73])
789
+ #define PyArray_FromBuffer \
790
+ (*(PyObject * (*)(PyObject *, PyArray_Descr *, npy_intp, npy_intp)) \
791
+ PyArray_API[74])
792
+ #define PyArray_FromIter \
793
+ (*(PyObject * (*)(PyObject *, PyArray_Descr *, npy_intp)) \
794
+ PyArray_API[75])
795
+ #define PyArray_Return \
796
+ (*(PyObject * (*)(PyArrayObject *)) \
797
+ PyArray_API[76])
798
+ #define PyArray_GetField \
799
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Descr *, int)) \
800
+ PyArray_API[77])
801
+ #define PyArray_SetField \
802
+ (*(int (*)(PyArrayObject *, PyArray_Descr *, int, PyObject *)) \
803
+ PyArray_API[78])
804
+ #define PyArray_Byteswap \
805
+ (*(PyObject * (*)(PyArrayObject *, npy_bool)) \
806
+ PyArray_API[79])
807
+ #define PyArray_Resize \
808
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Dims *, int, NPY_ORDER NPY_UNUSED(order))) \
809
+ PyArray_API[80])
810
+ #define PyArray_MoveInto \
811
+ (*(int (*)(PyArrayObject *, PyArrayObject *)) \
812
+ PyArray_API[81])
813
+ #define PyArray_CopyInto \
814
+ (*(int (*)(PyArrayObject *, PyArrayObject *)) \
815
+ PyArray_API[82])
816
+ #define PyArray_CopyAnyInto \
817
+ (*(int (*)(PyArrayObject *, PyArrayObject *)) \
818
+ PyArray_API[83])
819
+ #define PyArray_CopyObject \
820
+ (*(int (*)(PyArrayObject *, PyObject *)) \
821
+ PyArray_API[84])
822
+ #define PyArray_NewCopy \
823
+ (*(PyObject * (*)(PyArrayObject *, NPY_ORDER)) \
824
+ PyArray_API[85])
825
+ #define PyArray_ToList \
826
+ (*(PyObject * (*)(PyArrayObject *)) \
827
+ PyArray_API[86])
828
+ #define PyArray_ToString \
829
+ (*(PyObject * (*)(PyArrayObject *, NPY_ORDER)) \
830
+ PyArray_API[87])
831
+ #define PyArray_ToFile \
832
+ (*(int (*)(PyArrayObject *, FILE *, char *, char *)) \
833
+ PyArray_API[88])
834
+ #define PyArray_Dump \
835
+ (*(int (*)(PyObject *, PyObject *, int)) \
836
+ PyArray_API[89])
837
+ #define PyArray_Dumps \
838
+ (*(PyObject * (*)(PyObject *, int)) \
839
+ PyArray_API[90])
840
+ #define PyArray_ValidType \
841
+ (*(int (*)(int)) \
842
+ PyArray_API[91])
843
+ #define PyArray_UpdateFlags \
844
+ (*(void (*)(PyArrayObject *, int)) \
845
+ PyArray_API[92])
846
+ #define PyArray_New \
847
+ (*(PyObject * (*)(PyTypeObject *, int, npy_intp const *, int, npy_intp const *, void *, int, int, PyObject *)) \
848
+ PyArray_API[93])
849
+ #define PyArray_NewFromDescr \
850
+ (*(PyObject * (*)(PyTypeObject *, PyArray_Descr *, int, npy_intp const *, npy_intp const *, void *, int, PyObject *)) \
851
+ PyArray_API[94])
852
+ #define PyArray_DescrNew \
853
+ (*(PyArray_Descr * (*)(PyArray_Descr *)) \
854
+ PyArray_API[95])
855
+ #define PyArray_DescrNewFromType \
856
+ (*(PyArray_Descr * (*)(int)) \
857
+ PyArray_API[96])
858
+ #define PyArray_GetPriority \
859
+ (*(double (*)(PyObject *, double)) \
860
+ PyArray_API[97])
861
+ #define PyArray_IterNew \
862
+ (*(PyObject * (*)(PyObject *)) \
863
+ PyArray_API[98])
864
+ #define PyArray_MultiIterNew \
865
+ (*(PyObject* (*)(int, ...)) \
866
+ PyArray_API[99])
867
+ #define PyArray_PyIntAsInt \
868
+ (*(int (*)(PyObject *)) \
869
+ PyArray_API[100])
870
+ #define PyArray_PyIntAsIntp \
871
+ (*(npy_intp (*)(PyObject *)) \
872
+ PyArray_API[101])
873
+ #define PyArray_Broadcast \
874
+ (*(int (*)(PyArrayMultiIterObject *)) \
875
+ PyArray_API[102])
876
+ #define PyArray_FillObjectArray \
877
+ (*(void (*)(PyArrayObject *, PyObject *)) \
878
+ PyArray_API[103])
879
+ #define PyArray_FillWithScalar \
880
+ (*(int (*)(PyArrayObject *, PyObject *)) \
881
+ PyArray_API[104])
882
+ #define PyArray_CheckStrides \
883
+ (*(npy_bool (*)(int, int, npy_intp, npy_intp, npy_intp const *, npy_intp const *)) \
884
+ PyArray_API[105])
885
+ #define PyArray_DescrNewByteorder \
886
+ (*(PyArray_Descr * (*)(PyArray_Descr *, char)) \
887
+ PyArray_API[106])
888
+ #define PyArray_IterAllButAxis \
889
+ (*(PyObject * (*)(PyObject *, int *)) \
890
+ PyArray_API[107])
891
+ #define PyArray_CheckFromAny \
892
+ (*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) \
893
+ PyArray_API[108])
894
+ #define PyArray_FromArray \
895
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Descr *, int)) \
896
+ PyArray_API[109])
897
+ #define PyArray_FromInterface \
898
+ (*(PyObject * (*)(PyObject *)) \
899
+ PyArray_API[110])
900
+ #define PyArray_FromStructInterface \
901
+ (*(PyObject * (*)(PyObject *)) \
902
+ PyArray_API[111])
903
+ #define PyArray_FromArrayAttr \
904
+ (*(PyObject * (*)(PyObject *, PyArray_Descr *, PyObject *)) \
905
+ PyArray_API[112])
906
+ #define PyArray_ScalarKind \
907
+ (*(NPY_SCALARKIND (*)(int, PyArrayObject **)) \
908
+ PyArray_API[113])
909
+ #define PyArray_CanCoerceScalar \
910
+ (*(int (*)(int, int, NPY_SCALARKIND)) \
911
+ PyArray_API[114])
912
+ #define PyArray_NewFlagsObject \
913
+ (*(PyObject * (*)(PyObject *)) \
914
+ PyArray_API[115])
915
+ #define PyArray_CanCastScalar \
916
+ (*(npy_bool (*)(PyTypeObject *, PyTypeObject *)) \
917
+ PyArray_API[116])
918
+ #define PyArray_CompareUCS4 \
919
+ (*(int (*)(npy_ucs4 const *, npy_ucs4 const *, size_t)) \
920
+ PyArray_API[117])
921
+ #define PyArray_RemoveSmallest \
922
+ (*(int (*)(PyArrayMultiIterObject *)) \
923
+ PyArray_API[118])
924
+ #define PyArray_ElementStrides \
925
+ (*(int (*)(PyObject *)) \
926
+ PyArray_API[119])
927
+ #define PyArray_Item_INCREF \
928
+ (*(void (*)(char *, PyArray_Descr *)) \
929
+ PyArray_API[120])
930
+ #define PyArray_Item_XDECREF \
931
+ (*(void (*)(char *, PyArray_Descr *)) \
932
+ PyArray_API[121])
933
+ #define PyArray_FieldNames \
934
+ (*(PyObject * (*)(PyObject *)) \
935
+ PyArray_API[122])
936
+ #define PyArray_Transpose \
937
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Dims *)) \
938
+ PyArray_API[123])
939
+ #define PyArray_TakeFrom \
940
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, int, PyArrayObject *, NPY_CLIPMODE)) \
941
+ PyArray_API[124])
942
+ #define PyArray_PutTo \
943
+ (*(PyObject * (*)(PyArrayObject *, PyObject*, PyObject *, NPY_CLIPMODE)) \
944
+ PyArray_API[125])
945
+ #define PyArray_PutMask \
946
+ (*(PyObject * (*)(PyArrayObject *, PyObject*, PyObject*)) \
947
+ PyArray_API[126])
948
+ #define PyArray_Repeat \
949
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, int)) \
950
+ PyArray_API[127])
951
+ #define PyArray_Choose \
952
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, PyArrayObject *, NPY_CLIPMODE)) \
953
+ PyArray_API[128])
954
+ #define PyArray_Sort \
955
+ (*(int (*)(PyArrayObject *, int, NPY_SORTKIND)) \
956
+ PyArray_API[129])
957
+ #define PyArray_ArgSort \
958
+ (*(PyObject * (*)(PyArrayObject *, int, NPY_SORTKIND)) \
959
+ PyArray_API[130])
960
+ #define PyArray_SearchSorted \
961
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, NPY_SEARCHSIDE, PyObject *)) \
962
+ PyArray_API[131])
963
+ #define PyArray_ArgMax \
964
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
965
+ PyArray_API[132])
966
+ #define PyArray_ArgMin \
967
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
968
+ PyArray_API[133])
969
+ #define PyArray_Reshape \
970
+ (*(PyObject * (*)(PyArrayObject *, PyObject *)) \
971
+ PyArray_API[134])
972
+ #define PyArray_Newshape \
973
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Dims *, NPY_ORDER)) \
974
+ PyArray_API[135])
975
+ #define PyArray_Squeeze \
976
+ (*(PyObject * (*)(PyArrayObject *)) \
977
+ PyArray_API[136])
978
+ #define PyArray_View \
979
+ (*(PyObject * (*)(PyArrayObject *, PyArray_Descr *, PyTypeObject *)) \
980
+ PyArray_API[137])
981
+ #define PyArray_SwapAxes \
982
+ (*(PyObject * (*)(PyArrayObject *, int, int)) \
983
+ PyArray_API[138])
984
+ #define PyArray_Max \
985
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
986
+ PyArray_API[139])
987
+ #define PyArray_Min \
988
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
989
+ PyArray_API[140])
990
+ #define PyArray_Ptp \
991
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
992
+ PyArray_API[141])
993
+ #define PyArray_Mean \
994
+ (*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
995
+ PyArray_API[142])
996
+ #define PyArray_Trace \
997
+ (*(PyObject * (*)(PyArrayObject *, int, int, int, int, PyArrayObject *)) \
998
+ PyArray_API[143])
999
+ #define PyArray_Diagonal \
1000
+ (*(PyObject * (*)(PyArrayObject *, int, int, int)) \
1001
+ PyArray_API[144])
1002
+ #define PyArray_Clip \
1003
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, PyObject *, PyArrayObject *)) \
1004
+ PyArray_API[145])
1005
+ #define PyArray_Conjugate \
1006
+ (*(PyObject * (*)(PyArrayObject *, PyArrayObject *)) \
1007
+ PyArray_API[146])
1008
+ #define PyArray_Nonzero \
1009
+ (*(PyObject * (*)(PyArrayObject *)) \
1010
+ PyArray_API[147])
1011
+ #define PyArray_Std \
1012
+ (*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *, int)) \
1013
+ PyArray_API[148])
1014
+ #define PyArray_Sum \
1015
+ (*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
1016
+ PyArray_API[149])
1017
+ #define PyArray_CumSum \
1018
+ (*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
1019
+ PyArray_API[150])
1020
+ #define PyArray_Prod \
1021
+ (*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
1022
+ PyArray_API[151])
1023
+ #define PyArray_CumProd \
1024
+ (*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
1025
+ PyArray_API[152])
1026
+ #define PyArray_All \
1027
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
1028
+ PyArray_API[153])
1029
+ #define PyArray_Any \
1030
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
1031
+ PyArray_API[154])
1032
+ #define PyArray_Compress \
1033
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, int, PyArrayObject *)) \
1034
+ PyArray_API[155])
1035
+ #define PyArray_Flatten \
1036
+ (*(PyObject * (*)(PyArrayObject *, NPY_ORDER)) \
1037
+ PyArray_API[156])
1038
+ #define PyArray_Ravel \
1039
+ (*(PyObject * (*)(PyArrayObject *, NPY_ORDER)) \
1040
+ PyArray_API[157])
1041
+ #define PyArray_MultiplyList \
1042
+ (*(npy_intp (*)(npy_intp const *, int)) \
1043
+ PyArray_API[158])
1044
+ #define PyArray_MultiplyIntList \
1045
+ (*(int (*)(int const *, int)) \
1046
+ PyArray_API[159])
1047
+ #define PyArray_GetPtr \
1048
+ (*(void * (*)(PyArrayObject *, npy_intp const*)) \
1049
+ PyArray_API[160])
1050
+ #define PyArray_CompareLists \
1051
+ (*(int (*)(npy_intp const *, npy_intp const *, int)) \
1052
+ PyArray_API[161])
1053
+ #define PyArray_AsCArray \
1054
+ (*(int (*)(PyObject **, void *, npy_intp *, int, PyArray_Descr*)) \
1055
+ PyArray_API[162])
1056
+ #define PyArray_As1D \
1057
+ (*(int (*)(PyObject **NPY_UNUSED(op), char **NPY_UNUSED(ptr), int *NPY_UNUSED(d1), int NPY_UNUSED(typecode))) \
1058
+ PyArray_API[163])
1059
+ #define PyArray_As2D \
1060
+ (*(int (*)(PyObject **NPY_UNUSED(op), char ***NPY_UNUSED(ptr), int *NPY_UNUSED(d1), int *NPY_UNUSED(d2), int NPY_UNUSED(typecode))) \
1061
+ PyArray_API[164])
1062
+ #define PyArray_Free \
1063
+ (*(int (*)(PyObject *, void *)) \
1064
+ PyArray_API[165])
1065
+ #define PyArray_Converter \
1066
+ (*(int (*)(PyObject *, PyObject **)) \
1067
+ PyArray_API[166])
1068
+ #define PyArray_IntpFromSequence \
1069
+ (*(int (*)(PyObject *, npy_intp *, int)) \
1070
+ PyArray_API[167])
1071
+ #define PyArray_Concatenate \
1072
+ (*(PyObject * (*)(PyObject *, int)) \
1073
+ PyArray_API[168])
1074
+ #define PyArray_InnerProduct \
1075
+ (*(PyObject * (*)(PyObject *, PyObject *)) \
1076
+ PyArray_API[169])
1077
+ #define PyArray_MatrixProduct \
1078
+ (*(PyObject * (*)(PyObject *, PyObject *)) \
1079
+ PyArray_API[170])
1080
+ #define PyArray_CopyAndTranspose \
1081
+ (*(PyObject * (*)(PyObject *)) \
1082
+ PyArray_API[171])
1083
+ #define PyArray_Correlate \
1084
+ (*(PyObject * (*)(PyObject *, PyObject *, int)) \
1085
+ PyArray_API[172])
1086
+ #define PyArray_TypestrConvert \
1087
+ (*(int (*)(int, int)) \
1088
+ PyArray_API[173])
1089
+ #define PyArray_DescrConverter \
1090
+ (*(int (*)(PyObject *, PyArray_Descr **)) \
1091
+ PyArray_API[174])
1092
+ #define PyArray_DescrConverter2 \
1093
+ (*(int (*)(PyObject *, PyArray_Descr **)) \
1094
+ PyArray_API[175])
1095
+ #define PyArray_IntpConverter \
1096
+ (*(int (*)(PyObject *, PyArray_Dims *)) \
1097
+ PyArray_API[176])
1098
+ #define PyArray_BufferConverter \
1099
+ (*(int (*)(PyObject *, PyArray_Chunk *)) \
1100
+ PyArray_API[177])
1101
+ #define PyArray_AxisConverter \
1102
+ (*(int (*)(PyObject *, int *)) \
1103
+ PyArray_API[178])
1104
+ #define PyArray_BoolConverter \
1105
+ (*(int (*)(PyObject *, npy_bool *)) \
1106
+ PyArray_API[179])
1107
+ #define PyArray_ByteorderConverter \
1108
+ (*(int (*)(PyObject *, char *)) \
1109
+ PyArray_API[180])
1110
+ #define PyArray_OrderConverter \
1111
+ (*(int (*)(PyObject *, NPY_ORDER *)) \
1112
+ PyArray_API[181])
1113
+ #define PyArray_EquivTypes \
1114
+ (*(unsigned char (*)(PyArray_Descr *, PyArray_Descr *)) \
1115
+ PyArray_API[182])
1116
+ #define PyArray_Zeros \
1117
+ (*(PyObject * (*)(int, npy_intp const *, PyArray_Descr *, int)) \
1118
+ PyArray_API[183])
1119
+ #define PyArray_Empty \
1120
+ (*(PyObject * (*)(int, npy_intp const *, PyArray_Descr *, int)) \
1121
+ PyArray_API[184])
1122
+ #define PyArray_Where \
1123
+ (*(PyObject * (*)(PyObject *, PyObject *, PyObject *)) \
1124
+ PyArray_API[185])
1125
+ #define PyArray_Arange \
1126
+ (*(PyObject * (*)(double, double, double, int)) \
1127
+ PyArray_API[186])
1128
+ #define PyArray_ArangeObj \
1129
+ (*(PyObject * (*)(PyObject *, PyObject *, PyObject *, PyArray_Descr *)) \
1130
+ PyArray_API[187])
1131
+ #define PyArray_SortkindConverter \
1132
+ (*(int (*)(PyObject *, NPY_SORTKIND *)) \
1133
+ PyArray_API[188])
1134
+ #define PyArray_LexSort \
1135
+ (*(PyObject * (*)(PyObject *, int)) \
1136
+ PyArray_API[189])
1137
+ #define PyArray_Round \
1138
+ (*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
1139
+ PyArray_API[190])
1140
+ #define PyArray_EquivTypenums \
1141
+ (*(unsigned char (*)(int, int)) \
1142
+ PyArray_API[191])
1143
+ #define PyArray_RegisterDataType \
1144
+ (*(int (*)(PyArray_Descr *)) \
1145
+ PyArray_API[192])
1146
+ #define PyArray_RegisterCastFunc \
1147
+ (*(int (*)(PyArray_Descr *, int, PyArray_VectorUnaryFunc *)) \
1148
+ PyArray_API[193])
1149
+ #define PyArray_RegisterCanCast \
1150
+ (*(int (*)(PyArray_Descr *, int, NPY_SCALARKIND)) \
1151
+ PyArray_API[194])
1152
+ #define PyArray_InitArrFuncs \
1153
+ (*(void (*)(PyArray_ArrFuncs *)) \
1154
+ PyArray_API[195])
1155
+ #define PyArray_IntTupleFromIntp \
1156
+ (*(PyObject * (*)(int, npy_intp const *)) \
1157
+ PyArray_API[196])
1158
+ #define PyArray_TypeNumFromName \
1159
+ (*(int (*)(char const *)) \
1160
+ PyArray_API[197])
1161
+ #define PyArray_ClipmodeConverter \
1162
+ (*(int (*)(PyObject *, NPY_CLIPMODE *)) \
1163
+ PyArray_API[198])
1164
+ #define PyArray_OutputConverter \
1165
+ (*(int (*)(PyObject *, PyArrayObject **)) \
1166
+ PyArray_API[199])
1167
+ #define PyArray_BroadcastToShape \
1168
+ (*(PyObject * (*)(PyObject *, npy_intp *, int)) \
1169
+ PyArray_API[200])
1170
+ #define _PyArray_SigintHandler \
1171
+ (*(void (*)(int)) \
1172
+ PyArray_API[201])
1173
+ #define _PyArray_GetSigintBuf \
1174
+ (*(void* (*)(void)) \
1175
+ PyArray_API[202])
1176
+ #define PyArray_DescrAlignConverter \
1177
+ (*(int (*)(PyObject *, PyArray_Descr **)) \
1178
+ PyArray_API[203])
1179
+ #define PyArray_DescrAlignConverter2 \
1180
+ (*(int (*)(PyObject *, PyArray_Descr **)) \
1181
+ PyArray_API[204])
1182
+ #define PyArray_SearchsideConverter \
1183
+ (*(int (*)(PyObject *, void *)) \
1184
+ PyArray_API[205])
1185
+ #define PyArray_CheckAxis \
1186
+ (*(PyObject * (*)(PyArrayObject *, int *, int)) \
1187
+ PyArray_API[206])
1188
+ #define PyArray_OverflowMultiplyList \
1189
+ (*(npy_intp (*)(npy_intp const *, int)) \
1190
+ PyArray_API[207])
1191
+ #define PyArray_CompareString \
1192
+ (*(int (*)(const char *, const char *, size_t)) \
1193
+ PyArray_API[208])
1194
+ #define PyArray_MultiIterFromObjects \
1195
+ (*(PyObject* (*)(PyObject **, int, int, ...)) \
1196
+ PyArray_API[209])
1197
+ #define PyArray_GetEndianness \
1198
+ (*(int (*)(void)) \
1199
+ PyArray_API[210])
1200
+ #define PyArray_GetNDArrayCFeatureVersion \
1201
+ (*(unsigned int (*)(void)) \
1202
+ PyArray_API[211])
1203
+ #define PyArray_Correlate2 \
1204
+ (*(PyObject * (*)(PyObject *, PyObject *, int)) \
1205
+ PyArray_API[212])
1206
+ #define PyArray_NeighborhoodIterNew \
1207
+ (*(PyObject* (*)(PyArrayIterObject *, const npy_intp *, int, PyArrayObject*)) \
1208
+ PyArray_API[213])
1209
+ #define PyTimeIntegerArrType_Type (*(PyTypeObject *)PyArray_API[214])
1210
+ #define PyDatetimeArrType_Type (*(PyTypeObject *)PyArray_API[215])
1211
+ #define PyTimedeltaArrType_Type (*(PyTypeObject *)PyArray_API[216])
1212
+ #define PyHalfArrType_Type (*(PyTypeObject *)PyArray_API[217])
1213
+ #define NpyIter_Type (*(PyTypeObject *)PyArray_API[218])
1214
+ #define PyArray_SetDatetimeParseFunction \
1215
+ (*(void (*)(PyObject *NPY_UNUSED(op))) \
1216
+ PyArray_API[219])
1217
+ #define PyArray_DatetimeToDatetimeStruct \
1218
+ (*(void (*)(npy_datetime NPY_UNUSED(val), NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_datetimestruct *)) \
1219
+ PyArray_API[220])
1220
+ #define PyArray_TimedeltaToTimedeltaStruct \
1221
+ (*(void (*)(npy_timedelta NPY_UNUSED(val), NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_timedeltastruct *)) \
1222
+ PyArray_API[221])
1223
+ #define PyArray_DatetimeStructToDatetime \
1224
+ (*(npy_datetime (*)(NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_datetimestruct *NPY_UNUSED(d))) \
1225
+ PyArray_API[222])
1226
+ #define PyArray_TimedeltaStructToTimedelta \
1227
+ (*(npy_datetime (*)(NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_timedeltastruct *NPY_UNUSED(d))) \
1228
+ PyArray_API[223])
1229
+ #define NpyIter_New \
1230
+ (*(NpyIter * (*)(PyArrayObject *, npy_uint32, NPY_ORDER, NPY_CASTING, PyArray_Descr*)) \
1231
+ PyArray_API[224])
1232
+ #define NpyIter_MultiNew \
1233
+ (*(NpyIter * (*)(int, PyArrayObject **, npy_uint32, NPY_ORDER, NPY_CASTING, npy_uint32 *, PyArray_Descr **)) \
1234
+ PyArray_API[225])
1235
+ #define NpyIter_AdvancedNew \
1236
+ (*(NpyIter * (*)(int, PyArrayObject **, npy_uint32, NPY_ORDER, NPY_CASTING, npy_uint32 *, PyArray_Descr **, int, int **, npy_intp *, npy_intp)) \
1237
+ PyArray_API[226])
1238
+ #define NpyIter_Copy \
1239
+ (*(NpyIter * (*)(NpyIter *)) \
1240
+ PyArray_API[227])
1241
+ #define NpyIter_Deallocate \
1242
+ (*(int (*)(NpyIter *)) \
1243
+ PyArray_API[228])
1244
+ #define NpyIter_HasDelayedBufAlloc \
1245
+ (*(npy_bool (*)(NpyIter *)) \
1246
+ PyArray_API[229])
1247
+ #define NpyIter_HasExternalLoop \
1248
+ (*(npy_bool (*)(NpyIter *)) \
1249
+ PyArray_API[230])
1250
+ #define NpyIter_EnableExternalLoop \
1251
+ (*(int (*)(NpyIter *)) \
1252
+ PyArray_API[231])
1253
+ #define NpyIter_GetInnerStrideArray \
1254
+ (*(npy_intp * (*)(NpyIter *)) \
1255
+ PyArray_API[232])
1256
+ #define NpyIter_GetInnerLoopSizePtr \
1257
+ (*(npy_intp * (*)(NpyIter *)) \
1258
+ PyArray_API[233])
1259
+ #define NpyIter_Reset \
1260
+ (*(int (*)(NpyIter *, char **)) \
1261
+ PyArray_API[234])
1262
+ #define NpyIter_ResetBasePointers \
1263
+ (*(int (*)(NpyIter *, char **, char **)) \
1264
+ PyArray_API[235])
1265
+ #define NpyIter_ResetToIterIndexRange \
1266
+ (*(int (*)(NpyIter *, npy_intp, npy_intp, char **)) \
1267
+ PyArray_API[236])
1268
+ #define NpyIter_GetNDim \
1269
+ (*(int (*)(NpyIter *)) \
1270
+ PyArray_API[237])
1271
+ #define NpyIter_GetNOp \
1272
+ (*(int (*)(NpyIter *)) \
1273
+ PyArray_API[238])
1274
+ #define NpyIter_GetIterNext \
1275
+ (*(NpyIter_IterNextFunc * (*)(NpyIter *, char **)) \
1276
+ PyArray_API[239])
1277
+ #define NpyIter_GetIterSize \
1278
+ (*(npy_intp (*)(NpyIter *)) \
1279
+ PyArray_API[240])
1280
+ #define NpyIter_GetIterIndexRange \
1281
+ (*(void (*)(NpyIter *, npy_intp *, npy_intp *)) \
1282
+ PyArray_API[241])
1283
+ #define NpyIter_GetIterIndex \
1284
+ (*(npy_intp (*)(NpyIter *)) \
1285
+ PyArray_API[242])
1286
+ #define NpyIter_GotoIterIndex \
1287
+ (*(int (*)(NpyIter *, npy_intp)) \
1288
+ PyArray_API[243])
1289
+ #define NpyIter_HasMultiIndex \
1290
+ (*(npy_bool (*)(NpyIter *)) \
1291
+ PyArray_API[244])
1292
+ #define NpyIter_GetShape \
1293
+ (*(int (*)(NpyIter *, npy_intp *)) \
1294
+ PyArray_API[245])
1295
+ #define NpyIter_GetGetMultiIndex \
1296
+ (*(NpyIter_GetMultiIndexFunc * (*)(NpyIter *, char **)) \
1297
+ PyArray_API[246])
1298
+ #define NpyIter_GotoMultiIndex \
1299
+ (*(int (*)(NpyIter *, npy_intp const *)) \
1300
+ PyArray_API[247])
1301
+ #define NpyIter_RemoveMultiIndex \
1302
+ (*(int (*)(NpyIter *)) \
1303
+ PyArray_API[248])
1304
+ #define NpyIter_HasIndex \
1305
+ (*(npy_bool (*)(NpyIter *)) \
1306
+ PyArray_API[249])
1307
+ #define NpyIter_IsBuffered \
1308
+ (*(npy_bool (*)(NpyIter *)) \
1309
+ PyArray_API[250])
1310
+ #define NpyIter_IsGrowInner \
1311
+ (*(npy_bool (*)(NpyIter *)) \
1312
+ PyArray_API[251])
1313
+ #define NpyIter_GetBufferSize \
1314
+ (*(npy_intp (*)(NpyIter *)) \
1315
+ PyArray_API[252])
1316
+ #define NpyIter_GetIndexPtr \
1317
+ (*(npy_intp * (*)(NpyIter *)) \
1318
+ PyArray_API[253])
1319
+ #define NpyIter_GotoIndex \
1320
+ (*(int (*)(NpyIter *, npy_intp)) \
1321
+ PyArray_API[254])
1322
+ #define NpyIter_GetDataPtrArray \
1323
+ (*(char ** (*)(NpyIter *)) \
1324
+ PyArray_API[255])
1325
+ #define NpyIter_GetDescrArray \
1326
+ (*(PyArray_Descr ** (*)(NpyIter *)) \
1327
+ PyArray_API[256])
1328
+ #define NpyIter_GetOperandArray \
1329
+ (*(PyArrayObject ** (*)(NpyIter *)) \
1330
+ PyArray_API[257])
1331
+ #define NpyIter_GetIterView \
1332
+ (*(PyArrayObject * (*)(NpyIter *, npy_intp)) \
1333
+ PyArray_API[258])
1334
+ #define NpyIter_GetReadFlags \
1335
+ (*(void (*)(NpyIter *, char *)) \
1336
+ PyArray_API[259])
1337
+ #define NpyIter_GetWriteFlags \
1338
+ (*(void (*)(NpyIter *, char *)) \
1339
+ PyArray_API[260])
1340
+ #define NpyIter_DebugPrint \
1341
+ (*(void (*)(NpyIter *)) \
1342
+ PyArray_API[261])
1343
+ #define NpyIter_IterationNeedsAPI \
1344
+ (*(npy_bool (*)(NpyIter *)) \
1345
+ PyArray_API[262])
1346
+ #define NpyIter_GetInnerFixedStrideArray \
1347
+ (*(void (*)(NpyIter *, npy_intp *)) \
1348
+ PyArray_API[263])
1349
+ #define NpyIter_RemoveAxis \
1350
+ (*(int (*)(NpyIter *, int)) \
1351
+ PyArray_API[264])
1352
+ #define NpyIter_GetAxisStrideArray \
1353
+ (*(npy_intp * (*)(NpyIter *, int)) \
1354
+ PyArray_API[265])
1355
+ #define NpyIter_RequiresBuffering \
1356
+ (*(npy_bool (*)(NpyIter *)) \
1357
+ PyArray_API[266])
1358
+ #define NpyIter_GetInitialDataPtrArray \
1359
+ (*(char ** (*)(NpyIter *)) \
1360
+ PyArray_API[267])
1361
+ #define NpyIter_CreateCompatibleStrides \
1362
+ (*(int (*)(NpyIter *, npy_intp, npy_intp *)) \
1363
+ PyArray_API[268])
1364
+ #define PyArray_CastingConverter \
1365
+ (*(int (*)(PyObject *, NPY_CASTING *)) \
1366
+ PyArray_API[269])
1367
+ #define PyArray_CountNonzero \
1368
+ (*(npy_intp (*)(PyArrayObject *)) \
1369
+ PyArray_API[270])
1370
+ #define PyArray_PromoteTypes \
1371
+ (*(PyArray_Descr * (*)(PyArray_Descr *, PyArray_Descr *)) \
1372
+ PyArray_API[271])
1373
+ #define PyArray_MinScalarType \
1374
+ (*(PyArray_Descr * (*)(PyArrayObject *)) \
1375
+ PyArray_API[272])
1376
+ #define PyArray_ResultType \
1377
+ (*(PyArray_Descr * (*)(npy_intp, PyArrayObject *arrs[], npy_intp, PyArray_Descr *descrs[])) \
1378
+ PyArray_API[273])
1379
+ #define PyArray_CanCastArrayTo \
1380
+ (*(npy_bool (*)(PyArrayObject *, PyArray_Descr *, NPY_CASTING)) \
1381
+ PyArray_API[274])
1382
+ #define PyArray_CanCastTypeTo \
1383
+ (*(npy_bool (*)(PyArray_Descr *, PyArray_Descr *, NPY_CASTING)) \
1384
+ PyArray_API[275])
1385
+ #define PyArray_EinsteinSum \
1386
+ (*(PyArrayObject * (*)(char *, npy_intp, PyArrayObject **, PyArray_Descr *, NPY_ORDER, NPY_CASTING, PyArrayObject *)) \
1387
+ PyArray_API[276])
1388
+ #define PyArray_NewLikeArray \
1389
+ (*(PyObject * (*)(PyArrayObject *, NPY_ORDER, PyArray_Descr *, int)) \
1390
+ PyArray_API[277])
1391
+ #define PyArray_GetArrayParamsFromObject \
1392
+ (*(int (*)(PyObject *NPY_UNUSED(op), PyArray_Descr *NPY_UNUSED(requested_dtype), npy_bool NPY_UNUSED(writeable), PyArray_Descr **NPY_UNUSED(out_dtype), int *NPY_UNUSED(out_ndim), npy_intp *NPY_UNUSED(out_dims), PyArrayObject **NPY_UNUSED(out_arr), PyObject *NPY_UNUSED(context))) \
1393
+ PyArray_API[278])
1394
+ #define PyArray_ConvertClipmodeSequence \
1395
+ (*(int (*)(PyObject *, NPY_CLIPMODE *, int)) \
1396
+ PyArray_API[279])
1397
+ #define PyArray_MatrixProduct2 \
1398
+ (*(PyObject * (*)(PyObject *, PyObject *, PyArrayObject*)) \
1399
+ PyArray_API[280])
1400
+ #define NpyIter_IsFirstVisit \
1401
+ (*(npy_bool (*)(NpyIter *, int)) \
1402
+ PyArray_API[281])
1403
+ #define PyArray_SetBaseObject \
1404
+ (*(int (*)(PyArrayObject *, PyObject *)) \
1405
+ PyArray_API[282])
1406
+ #define PyArray_CreateSortedStridePerm \
1407
+ (*(void (*)(int, npy_intp const *, npy_stride_sort_item *)) \
1408
+ PyArray_API[283])
1409
+ #define PyArray_RemoveAxesInPlace \
1410
+ (*(void (*)(PyArrayObject *, const npy_bool *)) \
1411
+ PyArray_API[284])
1412
+ #define PyArray_DebugPrint \
1413
+ (*(void (*)(PyArrayObject *)) \
1414
+ PyArray_API[285])
1415
+ #define PyArray_FailUnlessWriteable \
1416
+ (*(int (*)(PyArrayObject *, const char *)) \
1417
+ PyArray_API[286])
1418
+ #define PyArray_SetUpdateIfCopyBase \
1419
+ (*(int (*)(PyArrayObject *, PyArrayObject *)) \
1420
+ PyArray_API[287])
1421
+ #define PyDataMem_NEW \
1422
+ (*(void * (*)(size_t)) \
1423
+ PyArray_API[288])
1424
+ #define PyDataMem_FREE \
1425
+ (*(void (*)(void *)) \
1426
+ PyArray_API[289])
1427
+ #define PyDataMem_RENEW \
1428
+ (*(void * (*)(void *, size_t)) \
1429
+ PyArray_API[290])
1430
+ #define PyDataMem_SetEventHook \
1431
+ (*(PyDataMem_EventHookFunc * (*)(PyDataMem_EventHookFunc *, void *, void **)) \
1432
+ PyArray_API[291])
1433
+ #define NPY_DEFAULT_ASSIGN_CASTING (*(NPY_CASTING *)PyArray_API[292])
1434
+ #define PyArray_MapIterSwapAxes \
1435
+ (*(void (*)(PyArrayMapIterObject *, PyArrayObject **, int)) \
1436
+ PyArray_API[293])
1437
+ #define PyArray_MapIterArray \
1438
+ (*(PyObject * (*)(PyArrayObject *, PyObject *)) \
1439
+ PyArray_API[294])
1440
+ #define PyArray_MapIterNext \
1441
+ (*(void (*)(PyArrayMapIterObject *)) \
1442
+ PyArray_API[295])
1443
+ #define PyArray_Partition \
1444
+ (*(int (*)(PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND)) \
1445
+ PyArray_API[296])
1446
+ #define PyArray_ArgPartition \
1447
+ (*(PyObject * (*)(PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND)) \
1448
+ PyArray_API[297])
1449
+ #define PyArray_SelectkindConverter \
1450
+ (*(int (*)(PyObject *, NPY_SELECTKIND *)) \
1451
+ PyArray_API[298])
1452
+ #define PyDataMem_NEW_ZEROED \
1453
+ (*(void * (*)(size_t, size_t)) \
1454
+ PyArray_API[299])
1455
+ #define PyArray_CheckAnyScalarExact \
1456
+ (*(int (*)(PyObject *)) \
1457
+ PyArray_API[300])
1458
+ #define PyArray_MapIterArrayCopyIfOverlap \
1459
+ (*(PyObject * (*)(PyArrayObject *, PyObject *, int, PyArrayObject *)) \
1460
+ PyArray_API[301])
1461
+ #define PyArray_ResolveWritebackIfCopy \
1462
+ (*(int (*)(PyArrayObject *)) \
1463
+ PyArray_API[302])
1464
+ #define PyArray_SetWritebackIfCopyBase \
1465
+ (*(int (*)(PyArrayObject *, PyArrayObject *)) \
1466
+ PyArray_API[303])
1467
+
1468
+ #if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
1469
+ #define PyDataMem_SetHandler \
1470
+ (*(PyObject * (*)(PyObject *)) \
1471
+ PyArray_API[304])
1472
+ #endif
1473
+
1474
+ #if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
1475
+ #define PyDataMem_GetHandler \
1476
+ (*(PyObject * (*)(void)) \
1477
+ PyArray_API[305])
1478
+ #endif
1479
+ #define PyDataMem_DefaultHandler (*(PyObject* *)PyArray_API[306])
1480
+
1481
+ #if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)
1482
+ static int
1483
+ _import_array(void)
1484
+ {
1485
+ int st;
1486
+ PyObject *numpy = PyImport_ImportModule("numpy.core._multiarray_umath");
1487
+ PyObject *c_api = NULL;
1488
+
1489
+ if (numpy == NULL) {
1490
+ return -1;
1491
+ }
1492
+ c_api = PyObject_GetAttrString(numpy, "_ARRAY_API");
1493
+ Py_DECREF(numpy);
1494
+ if (c_api == NULL) {
1495
+ return -1;
1496
+ }
1497
+
1498
+ if (!PyCapsule_CheckExact(c_api)) {
1499
+ PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is not PyCapsule object");
1500
+ Py_DECREF(c_api);
1501
+ return -1;
1502
+ }
1503
+ PyArray_API = (void **)PyCapsule_GetPointer(c_api, NULL);
1504
+ Py_DECREF(c_api);
1505
+ if (PyArray_API == NULL) {
1506
+ PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is NULL pointer");
1507
+ return -1;
1508
+ }
1509
+
1510
+ /* Perform runtime check of C API version */
1511
+ if (NPY_VERSION != PyArray_GetNDArrayCVersion()) {
1512
+ PyErr_Format(PyExc_RuntimeError, "module compiled against "\
1513
+ "ABI version 0x%x but this version of numpy is 0x%x", \
1514
+ (int) NPY_VERSION, (int) PyArray_GetNDArrayCVersion());
1515
+ return -1;
1516
+ }
1517
+ if (NPY_FEATURE_VERSION > PyArray_GetNDArrayCFeatureVersion()) {
1518
+ PyErr_Format(PyExc_RuntimeError, "module compiled against "\
1519
+ "API version 0x%x but this version of numpy is 0x%x . "\
1520
+ "Check the section C-API incompatibility at the "\
1521
+ "Troubleshooting ImportError section at "\
1522
+ "https://numpy.org/devdocs/user/troubleshooting-importerror.html"\
1523
+ "#c-api-incompatibility "\
1524
+ "for indications on how to solve this problem .", \
1525
+ (int) NPY_FEATURE_VERSION, (int) PyArray_GetNDArrayCFeatureVersion());
1526
+ return -1;
1527
+ }
1528
+
1529
+ /*
1530
+ * Perform runtime check of endianness and check it matches the one set by
1531
+ * the headers (npy_endian.h) as a safeguard
1532
+ */
1533
+ st = PyArray_GetEndianness();
1534
+ if (st == NPY_CPU_UNKNOWN_ENDIAN) {
1535
+ PyErr_SetString(PyExc_RuntimeError,
1536
+ "FATAL: module compiled as unknown endian");
1537
+ return -1;
1538
+ }
1539
+ #if NPY_BYTE_ORDER == NPY_BIG_ENDIAN
1540
+ if (st != NPY_CPU_BIG) {
1541
+ PyErr_SetString(PyExc_RuntimeError,
1542
+ "FATAL: module compiled as big endian, but "
1543
+ "detected different endianness at runtime");
1544
+ return -1;
1545
+ }
1546
+ #elif NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN
1547
+ if (st != NPY_CPU_LITTLE) {
1548
+ PyErr_SetString(PyExc_RuntimeError,
1549
+ "FATAL: module compiled as little endian, but "
1550
+ "detected different endianness at runtime");
1551
+ return -1;
1552
+ }
1553
+ #endif
1554
+
1555
+ return 0;
1556
+ }
1557
+
1558
+ #define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NULL; } }
1559
+
1560
+ #define import_array1(ret) {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return ret; } }
1561
+
1562
+ #define import_array2(msg, ret) {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, msg); return ret; } }
1563
+
1564
+ #endif
1565
+
1566
+ #endif
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/__ufunc_api.h ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 **, 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 int PyUFunc_GenericFunction \
13
+ (PyUFuncObject *NPY_UNUSED(ufunc), PyObject *NPY_UNUSED(args), PyObject *NPY_UNUSED(kwds), PyArrayObject **NPY_UNUSED(op));
14
+ NPY_NO_EXPORT void PyUFunc_f_f_As_d_d \
15
+ (char **, npy_intp const *, npy_intp const *, void *);
16
+ NPY_NO_EXPORT void PyUFunc_d_d \
17
+ (char **, npy_intp const *, npy_intp const *, void *);
18
+ NPY_NO_EXPORT void PyUFunc_f_f \
19
+ (char **, npy_intp const *, npy_intp const *, void *);
20
+ NPY_NO_EXPORT void PyUFunc_g_g \
21
+ (char **, npy_intp const *, npy_intp const *, void *);
22
+ NPY_NO_EXPORT void PyUFunc_F_F_As_D_D \
23
+ (char **, npy_intp const *, npy_intp const *, void *);
24
+ NPY_NO_EXPORT void PyUFunc_F_F \
25
+ (char **, npy_intp const *, npy_intp const *, void *);
26
+ NPY_NO_EXPORT void PyUFunc_D_D \
27
+ (char **, npy_intp const *, npy_intp const *, void *);
28
+ NPY_NO_EXPORT void PyUFunc_G_G \
29
+ (char **, npy_intp const *, npy_intp const *, void *);
30
+ NPY_NO_EXPORT void PyUFunc_O_O \
31
+ (char **, npy_intp const *, npy_intp const *, void *);
32
+ NPY_NO_EXPORT void PyUFunc_ff_f_As_dd_d \
33
+ (char **, npy_intp const *, npy_intp const *, void *);
34
+ NPY_NO_EXPORT void PyUFunc_ff_f \
35
+ (char **, npy_intp const *, npy_intp const *, void *);
36
+ NPY_NO_EXPORT void PyUFunc_dd_d \
37
+ (char **, npy_intp const *, npy_intp const *, void *);
38
+ NPY_NO_EXPORT void PyUFunc_gg_g \
39
+ (char **, npy_intp const *, npy_intp const *, void *);
40
+ NPY_NO_EXPORT void PyUFunc_FF_F_As_DD_D \
41
+ (char **, npy_intp const *, npy_intp const *, void *);
42
+ NPY_NO_EXPORT void PyUFunc_DD_D \
43
+ (char **, npy_intp const *, npy_intp const *, void *);
44
+ NPY_NO_EXPORT void PyUFunc_FF_F \
45
+ (char **, npy_intp const *, npy_intp const *, void *);
46
+ NPY_NO_EXPORT void PyUFunc_GG_G \
47
+ (char **, npy_intp const *, npy_intp const *, void *);
48
+ NPY_NO_EXPORT void PyUFunc_OO_O \
49
+ (char **, npy_intp const *, npy_intp const *, void *);
50
+ NPY_NO_EXPORT void PyUFunc_O_O_method \
51
+ (char **, npy_intp const *, npy_intp const *, void *);
52
+ NPY_NO_EXPORT void PyUFunc_OO_O_method \
53
+ (char **, npy_intp const *, npy_intp const *, void *);
54
+ NPY_NO_EXPORT void PyUFunc_On_Om \
55
+ (char **, npy_intp const *, npy_intp const *, void *);
56
+ NPY_NO_EXPORT int PyUFunc_GetPyValues \
57
+ (char *, int *, int *, PyObject **);
58
+ NPY_NO_EXPORT int PyUFunc_checkfperr \
59
+ (int, PyObject *, int *);
60
+ NPY_NO_EXPORT void PyUFunc_clearfperr \
61
+ (void);
62
+ NPY_NO_EXPORT int PyUFunc_getfperr \
63
+ (void);
64
+ NPY_NO_EXPORT int PyUFunc_handlefperr \
65
+ (int, PyObject *, int, int *);
66
+ NPY_NO_EXPORT int PyUFunc_ReplaceLoopBySignature \
67
+ (PyUFuncObject *, PyUFuncGenericFunction, const int *, PyUFuncGenericFunction *);
68
+ NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndDataAndSignature \
69
+ (PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int, const char *);
70
+ NPY_NO_EXPORT int PyUFunc_SetUsesArraysAsData \
71
+ (void **NPY_UNUSED(data), size_t NPY_UNUSED(i));
72
+ NPY_NO_EXPORT void PyUFunc_e_e \
73
+ (char **, npy_intp const *, npy_intp const *, void *);
74
+ NPY_NO_EXPORT void PyUFunc_e_e_As_f_f \
75
+ (char **, npy_intp const *, npy_intp const *, void *);
76
+ NPY_NO_EXPORT void PyUFunc_e_e_As_d_d \
77
+ (char **, npy_intp const *, npy_intp const *, void *);
78
+ NPY_NO_EXPORT void PyUFunc_ee_e \
79
+ (char **, npy_intp const *, npy_intp const *, void *);
80
+ NPY_NO_EXPORT void PyUFunc_ee_e_As_ff_f \
81
+ (char **, npy_intp const *, npy_intp const *, void *);
82
+ NPY_NO_EXPORT void PyUFunc_ee_e_As_dd_d \
83
+ (char **, npy_intp const *, npy_intp const *, void *);
84
+ NPY_NO_EXPORT int PyUFunc_DefaultTypeResolver \
85
+ (PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyObject *, PyArray_Descr **);
86
+ NPY_NO_EXPORT int PyUFunc_ValidateCasting \
87
+ (PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyArray_Descr **);
88
+ NPY_NO_EXPORT int PyUFunc_RegisterLoopForDescr \
89
+ (PyUFuncObject *, PyArray_Descr *, PyUFuncGenericFunction, PyArray_Descr **, void *);
90
+ NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndDataAndSignatureAndIdentity \
91
+ (PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, const int, const char *, PyObject *);
92
+
93
+ #else
94
+
95
+ #if defined(PY_UFUNC_UNIQUE_SYMBOL)
96
+ #define PyUFunc_API PY_UFUNC_UNIQUE_SYMBOL
97
+ #endif
98
+
99
+ #if defined(NO_IMPORT) || defined(NO_IMPORT_UFUNC)
100
+ extern void **PyUFunc_API;
101
+ #else
102
+ #if defined(PY_UFUNC_UNIQUE_SYMBOL)
103
+ void **PyUFunc_API;
104
+ #else
105
+ static void **PyUFunc_API=NULL;
106
+ #endif
107
+ #endif
108
+
109
+ #define PyUFunc_Type (*(PyTypeObject *)PyUFunc_API[0])
110
+ #define PyUFunc_FromFuncAndData \
111
+ (*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int)) \
112
+ PyUFunc_API[1])
113
+ #define PyUFunc_RegisterLoopForType \
114
+ (*(int (*)(PyUFuncObject *, int, PyUFuncGenericFunction, const int *, void *)) \
115
+ PyUFunc_API[2])
116
+ #define PyUFunc_GenericFunction \
117
+ (*(int (*)(PyUFuncObject *NPY_UNUSED(ufunc), PyObject *NPY_UNUSED(args), PyObject *NPY_UNUSED(kwds), PyArrayObject **NPY_UNUSED(op))) \
118
+ PyUFunc_API[3])
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_GetPyValues \
183
+ (*(int (*)(char *, int *, int *, PyObject **)) \
184
+ PyUFunc_API[25])
185
+ #define PyUFunc_checkfperr \
186
+ (*(int (*)(int, PyObject *, int *)) \
187
+ PyUFunc_API[26])
188
+ #define PyUFunc_clearfperr \
189
+ (*(void (*)(void)) \
190
+ PyUFunc_API[27])
191
+ #define PyUFunc_getfperr \
192
+ (*(int (*)(void)) \
193
+ PyUFunc_API[28])
194
+ #define PyUFunc_handlefperr \
195
+ (*(int (*)(int, PyObject *, int, int *)) \
196
+ PyUFunc_API[29])
197
+ #define PyUFunc_ReplaceLoopBySignature \
198
+ (*(int (*)(PyUFuncObject *, PyUFuncGenericFunction, const int *, PyUFuncGenericFunction *)) \
199
+ PyUFunc_API[30])
200
+ #define PyUFunc_FromFuncAndDataAndSignature \
201
+ (*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int, const char *)) \
202
+ PyUFunc_API[31])
203
+ #define PyUFunc_SetUsesArraysAsData \
204
+ (*(int (*)(void **NPY_UNUSED(data), size_t NPY_UNUSED(i))) \
205
+ PyUFunc_API[32])
206
+ #define PyUFunc_e_e \
207
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
208
+ PyUFunc_API[33])
209
+ #define PyUFunc_e_e_As_f_f \
210
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
211
+ PyUFunc_API[34])
212
+ #define PyUFunc_e_e_As_d_d \
213
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
214
+ PyUFunc_API[35])
215
+ #define PyUFunc_ee_e \
216
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
217
+ PyUFunc_API[36])
218
+ #define PyUFunc_ee_e_As_ff_f \
219
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
220
+ PyUFunc_API[37])
221
+ #define PyUFunc_ee_e_As_dd_d \
222
+ (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
223
+ PyUFunc_API[38])
224
+ #define PyUFunc_DefaultTypeResolver \
225
+ (*(int (*)(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyObject *, PyArray_Descr **)) \
226
+ PyUFunc_API[39])
227
+ #define PyUFunc_ValidateCasting \
228
+ (*(int (*)(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyArray_Descr **)) \
229
+ PyUFunc_API[40])
230
+ #define PyUFunc_RegisterLoopForDescr \
231
+ (*(int (*)(PyUFuncObject *, PyArray_Descr *, PyUFuncGenericFunction, PyArray_Descr **, void *)) \
232
+ PyUFunc_API[41])
233
+
234
+ #if NPY_FEATURE_VERSION >= NPY_1_16_API_VERSION
235
+ #define PyUFunc_FromFuncAndDataAndSignatureAndIdentity \
236
+ (*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, const int, const char *, PyObject *)) \
237
+ PyUFunc_API[42])
238
+ #endif
239
+
240
+ static inline int
241
+ _import_umath(void)
242
+ {
243
+ PyObject *numpy = PyImport_ImportModule("numpy.core._multiarray_umath");
244
+ PyObject *c_api = NULL;
245
+
246
+ if (numpy == NULL) {
247
+ PyErr_SetString(PyExc_ImportError,
248
+ "numpy.core._multiarray_umath failed to import");
249
+ return -1;
250
+ }
251
+ c_api = PyObject_GetAttrString(numpy, "_UFUNC_API");
252
+ Py_DECREF(numpy);
253
+ if (c_api == NULL) {
254
+ PyErr_SetString(PyExc_AttributeError, "_UFUNC_API not found");
255
+ return -1;
256
+ }
257
+
258
+ if (!PyCapsule_CheckExact(c_api)) {
259
+ PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is not PyCapsule object");
260
+ Py_DECREF(c_api);
261
+ return -1;
262
+ }
263
+ PyUFunc_API = (void **)PyCapsule_GetPointer(c_api, NULL);
264
+ Py_DECREF(c_api);
265
+ if (PyUFunc_API == NULL) {
266
+ PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is NULL pointer");
267
+ return -1;
268
+ }
269
+ return 0;
270
+ }
271
+
272
+ #define import_umath() \
273
+ do {\
274
+ UFUNC_NOFPE\
275
+ if (_import_umath() < 0) {\
276
+ PyErr_Print();\
277
+ PyErr_SetString(PyExc_ImportError,\
278
+ "numpy.core.umath failed to import");\
279
+ return NULL;\
280
+ }\
281
+ } while(0)
282
+
283
+ #define import_umath1(ret) \
284
+ do {\
285
+ UFUNC_NOFPE\
286
+ if (_import_umath() < 0) {\
287
+ PyErr_Print();\
288
+ PyErr_SetString(PyExc_ImportError,\
289
+ "numpy.core.umath failed to import");\
290
+ return ret;\
291
+ }\
292
+ } while(0)
293
+
294
+ #define import_umath2(ret, msg) \
295
+ do {\
296
+ UFUNC_NOFPE\
297
+ if (_import_umath() < 0) {\
298
+ PyErr_Print();\
299
+ PyErr_SetString(PyExc_ImportError, msg);\
300
+ return ret;\
301
+ }\
302
+ } while(0)
303
+
304
+ #define import_ufunc() \
305
+ do {\
306
+ UFUNC_NOFPE\
307
+ if (_import_umath() < 0) {\
308
+ PyErr_Print();\
309
+ PyErr_SetString(PyExc_ImportError,\
310
+ "numpy.core.umath failed to import");\
311
+ }\
312
+ } while(0)
313
+
314
+ #endif
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/_dtype_api.h ADDED
@@ -0,0 +1,408 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * DType related API shared by the (experimental) public API And internal API.
3
+ */
4
+
5
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY___DTYPE_API_H_
6
+ #define NUMPY_CORE_INCLUDE_NUMPY___DTYPE_API_H_
7
+
8
+ #define __EXPERIMENTAL_DTYPE_API_VERSION 11
9
+
10
+ struct PyArrayMethodObject_tag;
11
+
12
+ /*
13
+ * Largely opaque struct for DType classes (i.e. metaclass instances).
14
+ * The internal definition is currently in `ndarraytypes.h` (export is a bit
15
+ * more complex because `PyArray_Descr` is a DTypeMeta internally but not
16
+ * externally).
17
+ */
18
+ #if !(defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD)
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
+ #endif /* not internal build */
52
+
53
+ /*
54
+ * ******************************************************
55
+ * ArrayMethod API (Casting and UFuncs)
56
+ * ******************************************************
57
+ */
58
+ /*
59
+ * NOTE: Expected changes:
60
+ * * probably split runtime and general flags into two
61
+ * * should possibly not use an enum for typedef for more stable ABI?
62
+ */
63
+ typedef enum {
64
+ /* Flag for whether the GIL is required */
65
+ NPY_METH_REQUIRES_PYAPI = 1 << 0,
66
+ /*
67
+ * Some functions cannot set floating point error flags, this flag
68
+ * gives us the option (not requirement) to skip floating point error
69
+ * setup/check. No function should set error flags and ignore them
70
+ * since it would interfere with chaining operations (e.g. casting).
71
+ */
72
+ NPY_METH_NO_FLOATINGPOINT_ERRORS = 1 << 1,
73
+ /* Whether the method supports unaligned access (not runtime) */
74
+ NPY_METH_SUPPORTS_UNALIGNED = 1 << 2,
75
+ /*
76
+ * Used for reductions to allow reordering the operation. At this point
77
+ * assume that if set, it also applies to normal operations though!
78
+ */
79
+ NPY_METH_IS_REORDERABLE = 1 << 3,
80
+ /*
81
+ * Private flag for now for *logic* functions. The logical functions
82
+ * `logical_or` and `logical_and` can always cast the inputs to booleans
83
+ * "safely" (because that is how the cast to bool is defined).
84
+ * @seberg: I am not sure this is the best way to handle this, so its
85
+ * private for now (also it is very limited anyway).
86
+ * There is one "exception". NA aware dtypes cannot cast to bool
87
+ * (hopefully), so the `??->?` loop should error even with this flag.
88
+ * But a second NA fallback loop will be necessary.
89
+ */
90
+ _NPY_METH_FORCE_CAST_INPUTS = 1 << 17,
91
+
92
+ /* All flags which can change at runtime */
93
+ NPY_METH_RUNTIME_FLAGS = (
94
+ NPY_METH_REQUIRES_PYAPI |
95
+ NPY_METH_NO_FLOATINGPOINT_ERRORS),
96
+ } NPY_ARRAYMETHOD_FLAGS;
97
+
98
+
99
+ typedef struct PyArrayMethod_Context_tag {
100
+ /* The caller, which is typically the original ufunc. May be NULL */
101
+ PyObject *caller;
102
+ /* The method "self". Publically currentl an opaque object. */
103
+ struct PyArrayMethodObject_tag *method;
104
+
105
+ /* Operand descriptors, filled in by resolve_descriptors */
106
+ PyArray_Descr **descriptors;
107
+ /* Structure may grow (this is harmless for DType authors) */
108
+ } PyArrayMethod_Context;
109
+
110
+
111
+ /*
112
+ * The main object for creating a new ArrayMethod. We use the typical `slots`
113
+ * mechanism used by the Python limited API (see below for the slot defs).
114
+ */
115
+ typedef struct {
116
+ const char *name;
117
+ int nin, nout;
118
+ NPY_CASTING casting;
119
+ NPY_ARRAYMETHOD_FLAGS flags;
120
+ PyArray_DTypeMeta **dtypes;
121
+ PyType_Slot *slots;
122
+ } PyArrayMethod_Spec;
123
+
124
+
125
+ /*
126
+ * ArrayMethod slots
127
+ * -----------------
128
+ *
129
+ * SLOTS IDs For the ArrayMethod creation, once fully public, IDs are fixed
130
+ * but can be deprecated and arbitrarily extended.
131
+ */
132
+ #define NPY_METH_resolve_descriptors 1
133
+ /* We may want to adapt the `get_loop` signature a bit: */
134
+ #define _NPY_METH_get_loop 2
135
+ #define NPY_METH_get_reduction_initial 3
136
+ /* specific loops for constructions/default get_loop: */
137
+ #define NPY_METH_strided_loop 4
138
+ #define NPY_METH_contiguous_loop 5
139
+ #define NPY_METH_unaligned_strided_loop 6
140
+ #define NPY_METH_unaligned_contiguous_loop 7
141
+ #define NPY_METH_contiguous_indexed_loop 8
142
+
143
+ /*
144
+ * The resolve descriptors function, must be able to handle NULL values for
145
+ * all output (but not input) `given_descrs` and fill `loop_descrs`.
146
+ * Return -1 on error or 0 if the operation is not possible without an error
147
+ * set. (This may still be in flux.)
148
+ * Otherwise must return the "casting safety", for normal functions, this is
149
+ * almost always "safe" (or even "equivalent"?).
150
+ *
151
+ * `resolve_descriptors` is optional if all output DTypes are non-parametric.
152
+ */
153
+ typedef NPY_CASTING (resolve_descriptors_function)(
154
+ /* "method" is currently opaque (necessary e.g. to wrap Python) */
155
+ struct PyArrayMethodObject_tag *method,
156
+ /* DTypes the method was created for */
157
+ PyArray_DTypeMeta **dtypes,
158
+ /* Input descriptors (instances). Outputs may be NULL. */
159
+ PyArray_Descr **given_descrs,
160
+ /* Exact loop descriptors to use, must not hold references on error */
161
+ PyArray_Descr **loop_descrs,
162
+ npy_intp *view_offset);
163
+
164
+
165
+ typedef int (PyArrayMethod_StridedLoop)(PyArrayMethod_Context *context,
166
+ char *const *data, const npy_intp *dimensions, const npy_intp *strides,
167
+ NpyAuxData *transferdata);
168
+
169
+
170
+ typedef int (get_loop_function)(
171
+ PyArrayMethod_Context *context,
172
+ int aligned, int move_references,
173
+ const npy_intp *strides,
174
+ PyArrayMethod_StridedLoop **out_loop,
175
+ NpyAuxData **out_transferdata,
176
+ NPY_ARRAYMETHOD_FLAGS *flags);
177
+
178
+ /**
179
+ * Query an ArrayMethod for the initial value for use in reduction.
180
+ *
181
+ * @param context The arraymethod context, mainly to access the descriptors.
182
+ * @param reduction_is_empty Whether the reduction is empty. When it is, the
183
+ * value returned may differ. In this case it is a "default" value that
184
+ * may differ from the "identity" value normally used. For example:
185
+ * - `0.0` is the default for `sum([])`. But `-0.0` is the correct
186
+ * identity otherwise as it preserves the sign for `sum([-0.0])`.
187
+ * - We use no identity for object, but return the default of `0` and `1`
188
+ * for the empty `sum([], dtype=object)` and `prod([], dtype=object)`.
189
+ * This allows `np.sum(np.array(["a", "b"], dtype=object))` to work.
190
+ * - `-inf` or `INT_MIN` for `max` is an identity, but at least `INT_MIN`
191
+ * not a good *default* when there are no items.
192
+ * @param initial Pointer to initial data to be filled (if possible)
193
+ *
194
+ * @returns -1, 0, or 1 indicating error, no initial value, and initial being
195
+ * successfully filled. Errors must not be given where 0 is correct, NumPy
196
+ * may call this even when not strictly necessary.
197
+ */
198
+ typedef int (get_reduction_initial_function)(
199
+ PyArrayMethod_Context *context, npy_bool reduction_is_empty,
200
+ char *initial);
201
+
202
+ /*
203
+ * The following functions are only used by the wrapping array method defined
204
+ * in umath/wrapping_array_method.c
205
+ */
206
+
207
+ /*
208
+ * The function to convert the given descriptors (passed in to
209
+ * `resolve_descriptors`) and translates them for the wrapped loop.
210
+ * The new descriptors MUST be viewable with the old ones, `NULL` must be
211
+ * supported (for outputs) and should normally be forwarded.
212
+ *
213
+ * The function must clean up on error.
214
+ *
215
+ * NOTE: We currently assume that this translation gives "viewable" results.
216
+ * I.e. there is no additional casting related to the wrapping process.
217
+ * In principle that could be supported, but not sure it is useful.
218
+ * This currently also means that e.g. alignment must apply identically
219
+ * to the new dtypes.
220
+ *
221
+ * TODO: Due to the fact that `resolve_descriptors` is also used for `can_cast`
222
+ * there is no way to "pass out" the result of this function. This means
223
+ * it will be called twice for every ufunc call.
224
+ * (I am considering including `auxdata` as an "optional" parameter to
225
+ * `resolve_descriptors`, so that it can be filled there if not NULL.)
226
+ */
227
+ typedef int translate_given_descrs_func(int nin, int nout,
228
+ PyArray_DTypeMeta *wrapped_dtypes[],
229
+ PyArray_Descr *given_descrs[], PyArray_Descr *new_descrs[]);
230
+
231
+ /**
232
+ * The function to convert the actual loop descriptors (as returned by the
233
+ * original `resolve_descriptors` function) to the ones the output array
234
+ * should use.
235
+ * This function must return "viewable" types, it must not mutate them in any
236
+ * form that would break the inner-loop logic. Does not need to support NULL.
237
+ *
238
+ * The function must clean up on error.
239
+ *
240
+ * @param nargs Number of arguments
241
+ * @param new_dtypes The DTypes of the output (usually probably not needed)
242
+ * @param given_descrs Original given_descrs to the resolver, necessary to
243
+ * fetch any information related to the new dtypes from the original.
244
+ * @param original_descrs The `loop_descrs` returned by the wrapped loop.
245
+ * @param loop_descrs The output descriptors, compatible to `original_descrs`.
246
+ *
247
+ * @returns 0 on success, -1 on failure.
248
+ */
249
+ typedef int translate_loop_descrs_func(int nin, int nout,
250
+ PyArray_DTypeMeta *new_dtypes[], PyArray_Descr *given_descrs[],
251
+ PyArray_Descr *original_descrs[], PyArray_Descr *loop_descrs[]);
252
+
253
+
254
+ /*
255
+ * A traverse loop working on a single array. This is similar to the general
256
+ * strided-loop function. This is designed for loops that need to visit every
257
+ * element of a single array.
258
+ *
259
+ * Currently this is used for array clearing, via the NPY_DT_get_clear_loop
260
+ * API hook, and zero-filling, via the NPY_DT_get_fill_zero_loop API hook.
261
+ * These are most useful for handling arrays storing embedded references to
262
+ * python objects or heap-allocated data.
263
+ *
264
+ * The `void *traverse_context` is passed in because we may need to pass in
265
+ * Intepreter state or similar in the future, but we don't want to pass in
266
+ * a full context (with pointers to dtypes, method, caller which all make
267
+ * no sense for a traverse function).
268
+ *
269
+ * We assume for now that this context can be just passed through in the
270
+ * the future (for structured dtypes).
271
+ *
272
+ */
273
+ typedef int (traverse_loop_function)(
274
+ void *traverse_context, PyArray_Descr *descr, char *data,
275
+ npy_intp size, npy_intp stride, NpyAuxData *auxdata);
276
+
277
+
278
+ /*
279
+ * Simplified get_loop function specific to dtype traversal
280
+ *
281
+ * It should set the flags needed for the traversal loop and set out_loop to the
282
+ * loop function, which must be a valid traverse_loop_function
283
+ * pointer. Currently this is used for zero-filling and clearing arrays storing
284
+ * embedded references.
285
+ *
286
+ */
287
+ typedef int (get_traverse_loop_function)(
288
+ void *traverse_context, PyArray_Descr *descr,
289
+ int aligned, npy_intp fixed_stride,
290
+ traverse_loop_function **out_loop, NpyAuxData **out_auxdata,
291
+ NPY_ARRAYMETHOD_FLAGS *flags);
292
+
293
+
294
+ /*
295
+ * ****************************
296
+ * DTYPE API
297
+ * ****************************
298
+ */
299
+
300
+ #define NPY_DT_ABSTRACT 1 << 1
301
+ #define NPY_DT_PARAMETRIC 1 << 2
302
+ #define NPY_DT_NUMERIC 1 << 3
303
+
304
+ /*
305
+ * These correspond to slots in the NPY_DType_Slots struct and must
306
+ * be in the same order as the members of that struct. If new slots
307
+ * get added or old slots get removed NPY_NUM_DTYPE_SLOTS must also
308
+ * be updated
309
+ */
310
+
311
+ #define NPY_DT_discover_descr_from_pyobject 1
312
+ // this slot is considered private because its API hasn't beed decided
313
+ #define _NPY_DT_is_known_scalar_type 2
314
+ #define NPY_DT_default_descr 3
315
+ #define NPY_DT_common_dtype 4
316
+ #define NPY_DT_common_instance 5
317
+ #define NPY_DT_ensure_canonical 6
318
+ #define NPY_DT_setitem 7
319
+ #define NPY_DT_getitem 8
320
+ #define NPY_DT_get_clear_loop 9
321
+ #define NPY_DT_get_fill_zero_loop 10
322
+
323
+ // These PyArray_ArrFunc slots will be deprecated and replaced eventually
324
+ // getitem and setitem can be defined as a performance optimization;
325
+ // by default the user dtypes call `legacy_getitem_using_DType` and
326
+ // `legacy_setitem_using_DType`, respectively. This functionality is
327
+ // only supported for basic NumPy DTypes.
328
+
329
+
330
+ // used to separate dtype slots from arrfuncs slots
331
+ // intended only for internal use but defined here for clarity
332
+ #define _NPY_DT_ARRFUNCS_OFFSET (1 << 10)
333
+
334
+ // Cast is disabled
335
+ // #define NPY_DT_PyArray_ArrFuncs_cast 0 + _NPY_DT_ARRFUNCS_OFFSET
336
+
337
+ #define NPY_DT_PyArray_ArrFuncs_getitem 1 + _NPY_DT_ARRFUNCS_OFFSET
338
+ #define NPY_DT_PyArray_ArrFuncs_setitem 2 + _NPY_DT_ARRFUNCS_OFFSET
339
+
340
+ #define NPY_DT_PyArray_ArrFuncs_copyswapn 3 + _NPY_DT_ARRFUNCS_OFFSET
341
+ #define NPY_DT_PyArray_ArrFuncs_copyswap 4 + _NPY_DT_ARRFUNCS_OFFSET
342
+ #define NPY_DT_PyArray_ArrFuncs_compare 5 + _NPY_DT_ARRFUNCS_OFFSET
343
+ #define NPY_DT_PyArray_ArrFuncs_argmax 6 + _NPY_DT_ARRFUNCS_OFFSET
344
+ #define NPY_DT_PyArray_ArrFuncs_dotfunc 7 + _NPY_DT_ARRFUNCS_OFFSET
345
+ #define NPY_DT_PyArray_ArrFuncs_scanfunc 8 + _NPY_DT_ARRFUNCS_OFFSET
346
+ #define NPY_DT_PyArray_ArrFuncs_fromstr 9 + _NPY_DT_ARRFUNCS_OFFSET
347
+ #define NPY_DT_PyArray_ArrFuncs_nonzero 10 + _NPY_DT_ARRFUNCS_OFFSET
348
+ #define NPY_DT_PyArray_ArrFuncs_fill 11 + _NPY_DT_ARRFUNCS_OFFSET
349
+ #define NPY_DT_PyArray_ArrFuncs_fillwithscalar 12 + _NPY_DT_ARRFUNCS_OFFSET
350
+ #define NPY_DT_PyArray_ArrFuncs_sort 13 + _NPY_DT_ARRFUNCS_OFFSET
351
+ #define NPY_DT_PyArray_ArrFuncs_argsort 14 + _NPY_DT_ARRFUNCS_OFFSET
352
+
353
+ // Casting related slots are disabled. See
354
+ // https://github.com/numpy/numpy/pull/23173#discussion_r1101098163
355
+ // #define NPY_DT_PyArray_ArrFuncs_castdict 15 + _NPY_DT_ARRFUNCS_OFFSET
356
+ // #define NPY_DT_PyArray_ArrFuncs_scalarkind 16 + _NPY_DT_ARRFUNCS_OFFSET
357
+ // #define NPY_DT_PyArray_ArrFuncs_cancastscalarkindto 17 + _NPY_DT_ARRFUNCS_OFFSET
358
+ // #define NPY_DT_PyArray_ArrFuncs_cancastto 18 + _NPY_DT_ARRFUNCS_OFFSET
359
+
360
+ // These are deprecated in NumPy 1.19, so are disabled here.
361
+ // #define NPY_DT_PyArray_ArrFuncs_fastclip 19 + _NPY_DT_ARRFUNCS_OFFSET
362
+ // #define NPY_DT_PyArray_ArrFuncs_fastputmask 20 + _NPY_DT_ARRFUNCS_OFFSET
363
+ // #define NPY_DT_PyArray_ArrFuncs_fasttake 21 + _NPY_DT_ARRFUNCS_OFFSET
364
+ #define NPY_DT_PyArray_ArrFuncs_argmin 22 + _NPY_DT_ARRFUNCS_OFFSET
365
+
366
+ // TODO: These slots probably still need some thought, and/or a way to "grow"?
367
+ typedef struct {
368
+ PyTypeObject *typeobj; /* type of python scalar or NULL */
369
+ int flags; /* flags, including parametric and abstract */
370
+ /* NULL terminated cast definitions. Use NULL for the newly created DType */
371
+ PyArrayMethod_Spec **casts;
372
+ PyType_Slot *slots;
373
+ /* Baseclass or NULL (will always subclass `np.dtype`) */
374
+ PyTypeObject *baseclass;
375
+ } PyArrayDTypeMeta_Spec;
376
+
377
+
378
+ typedef PyArray_Descr *(discover_descr_from_pyobject_function)(
379
+ PyArray_DTypeMeta *cls, PyObject *obj);
380
+
381
+ /*
382
+ * Before making this public, we should decide whether it should pass
383
+ * the type, or allow looking at the object. A possible use-case:
384
+ * `np.array(np.array([0]), dtype=np.ndarray)`
385
+ * Could consider arrays that are not `dtype=ndarray` "scalars".
386
+ */
387
+ typedef int (is_known_scalar_type_function)(
388
+ PyArray_DTypeMeta *cls, PyTypeObject *obj);
389
+
390
+ typedef PyArray_Descr *(default_descr_function)(PyArray_DTypeMeta *cls);
391
+ typedef PyArray_DTypeMeta *(common_dtype_function)(
392
+ PyArray_DTypeMeta *dtype1, PyArray_DTypeMeta *dtype2);
393
+ typedef PyArray_Descr *(common_instance_function)(
394
+ PyArray_Descr *dtype1, PyArray_Descr *dtype2);
395
+ typedef PyArray_Descr *(ensure_canonical_function)(PyArray_Descr *dtype);
396
+
397
+ /*
398
+ * TODO: These two functions are currently only used for experimental DType
399
+ * API support. Their relation should be "reversed": NumPy should
400
+ * always use them internally.
401
+ * There are open points about "casting safety" though, e.g. setting
402
+ * elements is currently always unsafe.
403
+ */
404
+ typedef int(setitemfunction)(PyArray_Descr *, PyObject *, char *);
405
+ typedef PyObject *(getitemfunction)(PyArray_Descr *, char *);
406
+
407
+
408
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY___DTYPE_API_H_ */
moondream/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
+ }
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/_numpyconfig.h ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_OFF_T 8
14
+ #define NPY_SIZEOF_PY_LONG_LONG 8
15
+ #define NPY_SIZEOF_LONGLONG 8
16
+
17
+ #define NPY_USE_C99_COMPLEX 1
18
+ #define NPY_HAVE_COMPLEX_DOUBLE 1
19
+ #define NPY_HAVE_COMPLEX_FLOAT 1
20
+ #define NPY_HAVE_COMPLEX_LONG_DOUBLE 1
21
+ #define NPY_USE_C99_FORMATS 1
22
+
23
+ /* #undef NPY_NO_SIGNAL */
24
+ #define NPY_NO_SMP 0
25
+
26
+ #define NPY_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
27
+ #define NPY_ABI_VERSION 0x01000009
28
+ #define NPY_API_VERSION 0x00000011
29
+
30
+ #ifndef __STDC_FORMAT_MACROS
31
+ #define __STDC_FORMAT_MACROS 1
32
+ #endif
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/arrayscalars.h ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ typedef struct {
139
+ /* note that the PyObject_HEAD macro lives right here */
140
+ PyUnicodeObject base;
141
+ Py_UCS4 *obval;
142
+ #if NPY_FEATURE_VERSION >= NPY_1_20_API_VERSION
143
+ char *buffer_fmt;
144
+ #endif
145
+ } PyUnicodeScalarObject;
146
+
147
+
148
+ typedef struct {
149
+ PyObject_VAR_HEAD
150
+ char *obval;
151
+ PyArray_Descr *descr;
152
+ int flags;
153
+ PyObject *base;
154
+ #if NPY_FEATURE_VERSION >= NPY_1_20_API_VERSION
155
+ void *_buffer_info; /* private buffer info, tagged to allow warning */
156
+ #endif
157
+ } PyVoidScalarObject;
158
+
159
+ /* Macros
160
+ Py<Cls><bitsize>ScalarObject
161
+ Py<Cls><bitsize>ArrType_Type
162
+ are defined in ndarrayobject.h
163
+ */
164
+
165
+ #define PyArrayScalar_False ((PyObject *)(&(_PyArrayScalar_BoolValues[0])))
166
+ #define PyArrayScalar_True ((PyObject *)(&(_PyArrayScalar_BoolValues[1])))
167
+ #define PyArrayScalar_FromLong(i) \
168
+ ((PyObject *)(&(_PyArrayScalar_BoolValues[((i)!=0)])))
169
+ #define PyArrayScalar_RETURN_BOOL_FROM_LONG(i) \
170
+ return Py_INCREF(PyArrayScalar_FromLong(i)), \
171
+ PyArrayScalar_FromLong(i)
172
+ #define PyArrayScalar_RETURN_FALSE \
173
+ return Py_INCREF(PyArrayScalar_False), \
174
+ PyArrayScalar_False
175
+ #define PyArrayScalar_RETURN_TRUE \
176
+ return Py_INCREF(PyArrayScalar_True), \
177
+ PyArrayScalar_True
178
+
179
+ #define PyArrayScalar_New(cls) \
180
+ Py##cls##ArrType_Type.tp_alloc(&Py##cls##ArrType_Type, 0)
181
+ #define PyArrayScalar_VAL(obj, cls) \
182
+ ((Py##cls##ScalarObject *)obj)->obval
183
+ #define PyArrayScalar_ASSIGN(obj, cls, val) \
184
+ PyArrayScalar_VAL(obj, cls) = val
185
+
186
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_ARRAYSCALARS_H_ */
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/experimental_dtype_api.h ADDED
@@ -0,0 +1,365 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * This header exports the new experimental DType API as proposed in
3
+ * NEPs 41 to 43. For background, please check these NEPs. Otherwise,
4
+ * this header also serves as documentation for the time being.
5
+ *
6
+ * The header includes `_dtype_api.h` which holds most definition while this
7
+ * header mainly wraps functions for public consumption.
8
+ *
9
+ * Please do not hesitate to contact @seberg with questions. This is
10
+ * developed together with https://github.com/seberg/experimental_user_dtypes
11
+ * and those interested in experimenting are encouraged to contribute there.
12
+ *
13
+ * To use the functions defined in the header, call::
14
+ *
15
+ * if (import_experimental_dtype_api(version) < 0) {
16
+ * return NULL;
17
+ * }
18
+ *
19
+ * in your module init. (A version mismatch will be reported, just update
20
+ * to the correct one, this will alert you of possible changes.)
21
+ *
22
+ * The following lists the main symbols currently exported. Please do not
23
+ * hesitate to ask for help or clarification:
24
+ *
25
+ * - PyUFunc_AddLoopFromSpec:
26
+ *
27
+ * Register a new loop for a ufunc. This uses the `PyArrayMethod_Spec`
28
+ * which must be filled in (see in-line comments).
29
+ *
30
+ * - PyUFunc_AddWrappingLoop:
31
+ *
32
+ * Register a new loop which reuses an existing one, but modifies the
33
+ * result dtypes. Please search the internal NumPy docs for more info
34
+ * at this point. (Used for physical units dtype.)
35
+ *
36
+ * - PyUFunc_AddPromoter:
37
+ *
38
+ * Register a new promoter for a ufunc. A promoter is a function stored
39
+ * in a PyCapsule (see in-line comments). It is passed the operation and
40
+ * requested DType signatures and can mutate it to attempt a new search
41
+ * for a matching loop/promoter.
42
+ * I.e. for Numba a promoter could even add the desired loop.
43
+ *
44
+ * - PyArrayInitDTypeMeta_FromSpec:
45
+ *
46
+ * Initialize a new DType. It must currently be a static Python C type
47
+ * that is declared as `PyArray_DTypeMeta` and not `PyTypeObject`.
48
+ * Further, it must subclass `np.dtype` and set its type to
49
+ * `PyArrayDTypeMeta_Type` (before calling `PyType_Read()`).
50
+ *
51
+ * - PyArray_CommonDType:
52
+ *
53
+ * Find the common-dtype ("promotion") for two DType classes. Similar
54
+ * to `np.result_type`, but works on the classes and not instances.
55
+ *
56
+ * - PyArray_PromoteDTypeSequence:
57
+ *
58
+ * Same as CommonDType, but works with an arbitrary number of DTypes.
59
+ * This function is smarter and can often return successful and unambiguous
60
+ * results when `common_dtype(common_dtype(dt1, dt2), dt3)` would
61
+ * depend on the operation order or fail. Nevertheless, DTypes should
62
+ * aim to ensure that their common-dtype implementation is associative
63
+ * and commutative! (Mainly, unsigned and signed integers are not.)
64
+ *
65
+ * For guaranteed consistent results DTypes must implement common-Dtype
66
+ * "transitively". If A promotes B and B promotes C, than A must generally
67
+ * also promote C; where "promotes" means implements the promotion.
68
+ * (There are some exceptions for abstract DTypes)
69
+ *
70
+ * - PyArray_GetDefaultDescr:
71
+ *
72
+ * Given a DType class, returns the default instance (descriptor).
73
+ * This is an inline function checking for `singleton` first and only
74
+ * calls the `default_descr` function if necessary.
75
+ *
76
+ * - PyArray_DoubleDType, etc.:
77
+ *
78
+ * Aliases to the DType classes for the builtin NumPy DTypes.
79
+ *
80
+ * WARNING
81
+ * =======
82
+ *
83
+ * By using this header, you understand that this is a fully experimental
84
+ * exposure. Details are expected to change, and some options may have no
85
+ * effect. (Please contact @seberg if you have questions!)
86
+ * If the exposure stops working, please file a bug report with NumPy.
87
+ * Further, a DType created using this API/header should still be expected
88
+ * to be incompatible with some functionality inside and outside of NumPy.
89
+ * In this case crashes must be expected. Please report any such problems
90
+ * so that they can be fixed before final exposure.
91
+ * Furthermore, expect missing checks for programming errors which the final
92
+ * API is expected to have.
93
+ *
94
+ * Symbols with a leading underscore are likely to not be included in the
95
+ * first public version, if these are central to your use-case, please let
96
+ * us know, so that we can reconsider.
97
+ *
98
+ * "Array-like" consumer API not yet under considerations
99
+ * ======================================================
100
+ *
101
+ * The new DType API is designed in a way to make it potentially useful for
102
+ * alternative "array-like" implementations. This will require careful
103
+ * exposure of details and functions and is not part of this experimental API.
104
+ *
105
+ * Brief (incompatibility) changelog
106
+ * =================================
107
+ *
108
+ * 2. None (only additions).
109
+ * 3. New `npy_intp *view_offset` argument for `resolve_descriptors`.
110
+ * This replaces the `NPY_CAST_IS_VIEW` flag. It can be set to 0 if the
111
+ * operation is a view, and is pre-initialized to `NPY_MIN_INTP` indicating
112
+ * that the operation is not a view.
113
+ */
114
+
115
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_EXPERIMENTAL_DTYPE_API_H_
116
+ #define NUMPY_CORE_INCLUDE_NUMPY_EXPERIMENTAL_DTYPE_API_H_
117
+
118
+ #include <Python.h>
119
+ #include "ndarraytypes.h"
120
+ #include "_dtype_api.h"
121
+
122
+ /*
123
+ * The contents of PyArrayMethodObject are currently opaque (is there a way
124
+ * good way to make them be `PyObject *`?)
125
+ */
126
+ typedef struct PyArrayMethodObject_tag PyArrayMethodObject;
127
+
128
+ /*
129
+ * There must be a better way?! -- Oh well, this is experimental
130
+ * (my issue with it, is that I cannot undef those helpers).
131
+ */
132
+ #if defined(PY_ARRAY_UNIQUE_SYMBOL)
133
+ #define NPY_EXP_DTYPE_API_CONCAT_HELPER2(x, y) x ## y
134
+ #define NPY_EXP_DTYPE_API_CONCAT_HELPER(arg) NPY_EXP_DTYPE_API_CONCAT_HELPER2(arg, __experimental_dtype_api_table)
135
+ #define __experimental_dtype_api_table NPY_EXP_DTYPE_API_CONCAT_HELPER(PY_ARRAY_UNIQUE_SYMBOL)
136
+ #else
137
+ #define __experimental_dtype_api_table __experimental_dtype_api_table
138
+ #endif
139
+
140
+ /* Support for correct multi-file projects: */
141
+ #if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
142
+ extern void **__experimental_dtype_api_table;
143
+ #else
144
+ /*
145
+ * Just a hack so I don't forget importing as much myself, I spend way too
146
+ * much time noticing it the first time around :).
147
+ */
148
+ static void
149
+ __not_imported(void)
150
+ {
151
+ printf("*****\nCritical error, dtype API not imported\n*****\n");
152
+ }
153
+
154
+ static void *__uninitialized_table[] = {
155
+ &__not_imported, &__not_imported, &__not_imported, &__not_imported,
156
+ &__not_imported, &__not_imported, &__not_imported, &__not_imported};
157
+
158
+ #if defined(PY_ARRAY_UNIQUE_SYMBOL)
159
+ void **__experimental_dtype_api_table = __uninitialized_table;
160
+ #else
161
+ static void **__experimental_dtype_api_table = __uninitialized_table;
162
+ #endif
163
+ #endif
164
+
165
+
166
+ typedef int _ufunc_addloop_fromspec_func(
167
+ PyObject *ufunc, PyArrayMethod_Spec *spec);
168
+ /*
169
+ * The main ufunc registration function. This adds a new implementation/loop
170
+ * to a ufunc. It replaces `PyUFunc_RegisterLoopForType`.
171
+ */
172
+ #define PyUFunc_AddLoopFromSpec \
173
+ (*(_ufunc_addloop_fromspec_func *)(__experimental_dtype_api_table[0]))
174
+
175
+
176
+ /* Please see the NumPy definitions in `array_method.h` for details on these */
177
+ typedef int translate_given_descrs_func(int nin, int nout,
178
+ PyArray_DTypeMeta *wrapped_dtypes[],
179
+ PyArray_Descr *given_descrs[], PyArray_Descr *new_descrs[]);
180
+ typedef int translate_loop_descrs_func(int nin, int nout,
181
+ PyArray_DTypeMeta *new_dtypes[], PyArray_Descr *given_descrs[],
182
+ PyArray_Descr *original_descrs[], PyArray_Descr *loop_descrs[]);
183
+
184
+ typedef int _ufunc_wrapping_loop_func(PyObject *ufunc_obj,
185
+ PyArray_DTypeMeta *new_dtypes[], PyArray_DTypeMeta *wrapped_dtypes[],
186
+ translate_given_descrs_func *translate_given_descrs,
187
+ translate_loop_descrs_func *translate_loop_descrs);
188
+ #define PyUFunc_AddWrappingLoop \
189
+ (*(_ufunc_wrapping_loop_func *)(__experimental_dtype_api_table[7]))
190
+
191
+ /*
192
+ * Type of the C promoter function, which must be wrapped into a
193
+ * PyCapsule with name "numpy._ufunc_promoter".
194
+ *
195
+ * Note that currently the output dtypes are always NULL unless they are
196
+ * also part of the signature. This is an implementation detail and could
197
+ * change in the future. However, in general promoters should not have a
198
+ * need for output dtypes.
199
+ * (There are potential use-cases, these are currently unsupported.)
200
+ */
201
+ typedef int promoter_function(PyObject *ufunc,
202
+ PyArray_DTypeMeta *op_dtypes[], PyArray_DTypeMeta *signature[],
203
+ PyArray_DTypeMeta *new_op_dtypes[]);
204
+
205
+ /*
206
+ * Function to register a promoter.
207
+ *
208
+ * @param ufunc The ufunc object to register the promoter with.
209
+ * @param DType_tuple A Python tuple containing DTypes or None matching the
210
+ * number of inputs and outputs of the ufunc.
211
+ * @param promoter A PyCapsule with name "numpy._ufunc_promoter" containing
212
+ * a pointer to a `promoter_function`.
213
+ */
214
+ typedef int _ufunc_addpromoter_func(
215
+ PyObject *ufunc, PyObject *DType_tuple, PyObject *promoter);
216
+ #define PyUFunc_AddPromoter \
217
+ (*(_ufunc_addpromoter_func *)(__experimental_dtype_api_table[1]))
218
+
219
+ #define PyArrayDTypeMeta_Type \
220
+ (*(PyTypeObject *)__experimental_dtype_api_table[2])
221
+ typedef int __dtypemeta_fromspec(
222
+ PyArray_DTypeMeta *DType, PyArrayDTypeMeta_Spec *dtype_spec);
223
+ /*
224
+ * Finalize creation of a DTypeMeta. You must ensure that the DTypeMeta is
225
+ * a proper subclass. The DTypeMeta object has additional fields compared to
226
+ * a normal PyTypeObject!
227
+ * The only (easy) creation of a new DType is to create a static Type which
228
+ * inherits `PyArray_DescrType`, sets its type to `PyArrayDTypeMeta_Type` and
229
+ * uses `PyArray_DTypeMeta` defined above as the C-structure.
230
+ */
231
+ #define PyArrayInitDTypeMeta_FromSpec \
232
+ ((__dtypemeta_fromspec *)(__experimental_dtype_api_table[3]))
233
+
234
+
235
+ /*
236
+ * *************************************
237
+ * WORKING WITH DTYPES
238
+ * *************************************
239
+ */
240
+
241
+ typedef PyArray_DTypeMeta *__common_dtype(
242
+ PyArray_DTypeMeta *DType1, PyArray_DTypeMeta *DType2);
243
+ #define PyArray_CommonDType \
244
+ ((__common_dtype *)(__experimental_dtype_api_table[4]))
245
+
246
+
247
+ typedef PyArray_DTypeMeta *__promote_dtype_sequence(
248
+ npy_intp num, PyArray_DTypeMeta *DTypes[]);
249
+ #define PyArray_PromoteDTypeSequence \
250
+ ((__promote_dtype_sequence *)(__experimental_dtype_api_table[5]))
251
+
252
+
253
+ typedef PyArray_Descr *__get_default_descr(
254
+ PyArray_DTypeMeta *DType);
255
+ #define _PyArray_GetDefaultDescr \
256
+ ((__get_default_descr *)(__experimental_dtype_api_table[6]))
257
+
258
+ static inline PyArray_Descr *
259
+ PyArray_GetDefaultDescr(PyArray_DTypeMeta *DType)
260
+ {
261
+ if (DType->singleton != NULL) {
262
+ Py_INCREF(DType->singleton);
263
+ return DType->singleton;
264
+ }
265
+ return _PyArray_GetDefaultDescr(DType);
266
+ }
267
+
268
+
269
+ /*
270
+ * NumPy's builtin DTypes:
271
+ */
272
+ #define PyArray_BoolDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[10])
273
+ /* Integers */
274
+ #define PyArray_ByteDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[11])
275
+ #define PyArray_UByteDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[12])
276
+ #define PyArray_ShortDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[13])
277
+ #define PyArray_UShortDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[14])
278
+ #define PyArray_IntDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[15])
279
+ #define PyArray_UIntDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[16])
280
+ #define PyArray_LongDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[17])
281
+ #define PyArray_ULongDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[18])
282
+ #define PyArray_LongLongDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[19])
283
+ #define PyArray_ULongLongDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[20])
284
+ /* Integer aliases */
285
+ #define PyArray_Int8Type (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[21])
286
+ #define PyArray_UInt8DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[22])
287
+ #define PyArray_Int16DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[23])
288
+ #define PyArray_UInt16DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[24])
289
+ #define PyArray_Int32DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[25])
290
+ #define PyArray_UInt32DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[26])
291
+ #define PyArray_Int64DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[27])
292
+ #define PyArray_UInt64DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[28])
293
+ #define PyArray_IntpDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[29])
294
+ #define PyArray_UIntpDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[30])
295
+ /* Floats */
296
+ #define PyArray_HalfType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[31])
297
+ #define PyArray_FloatDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[32])
298
+ #define PyArray_DoubleDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[33])
299
+ #define PyArray_LongDoubleDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[34])
300
+ /* Complex */
301
+ #define PyArray_CFloatDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[35])
302
+ #define PyArray_CDoubleDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[36])
303
+ #define PyArray_CLongDoubleDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[37])
304
+ /* String/Bytes */
305
+ #define PyArray_StringDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[38])
306
+ #define PyArray_UnicodeDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[39])
307
+ /* Datetime/Timedelta */
308
+ #define PyArray_DatetimeDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[40])
309
+ #define PyArray_TimedeltaDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[41])
310
+ /* Object/Void */
311
+ #define PyArray_ObjectDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[42])
312
+ #define PyArray_VoidDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[43])
313
+
314
+ /*
315
+ * ********************************
316
+ * Initialization
317
+ * ********************************
318
+ *
319
+ * Import the experimental API, the version must match the one defined in
320
+ * the header to ensure changes are taken into account. NumPy will further
321
+ * runtime-check this.
322
+ * You must call this function to use the symbols defined in this file.
323
+ */
324
+ #if !defined(NO_IMPORT) && !defined(NO_IMPORT_ARRAY)
325
+
326
+ static int
327
+ import_experimental_dtype_api(int version)
328
+ {
329
+ if (version != __EXPERIMENTAL_DTYPE_API_VERSION) {
330
+ PyErr_Format(PyExc_RuntimeError,
331
+ "DType API version %d did not match header version %d. Please "
332
+ "update the import statement and check for API changes.",
333
+ version, __EXPERIMENTAL_DTYPE_API_VERSION);
334
+ return -1;
335
+ }
336
+ if (__experimental_dtype_api_table != __uninitialized_table) {
337
+ /* already imported. */
338
+ return 0;
339
+ }
340
+
341
+ PyObject *multiarray = PyImport_ImportModule("numpy.core._multiarray_umath");
342
+ if (multiarray == NULL) {
343
+ return -1;
344
+ }
345
+
346
+ PyObject *api = PyObject_CallMethod(multiarray,
347
+ "_get_experimental_dtype_api", "i", version);
348
+ Py_DECREF(multiarray);
349
+ if (api == NULL) {
350
+ return -1;
351
+ }
352
+ __experimental_dtype_api_table = (void **)PyCapsule_GetPointer(api,
353
+ "experimental_dtype_api_table");
354
+ Py_DECREF(api);
355
+
356
+ if (__experimental_dtype_api_table == NULL) {
357
+ __experimental_dtype_api_table = __uninitialized_table;
358
+ return -1;
359
+ }
360
+ return 0;
361
+ }
362
+
363
+ #endif /* !defined(NO_IMPORT) && !defined(NO_IMPORT_ARRAY) */
364
+
365
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_EXPERIMENTAL_DTYPE_API_H_ */
moondream/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_ */
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/ndarrayobject.h ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
14
+ /* Includes the "function" C-API -- these are all stored in a
15
+ list of pointers --- one for each file
16
+ The two lists are concatenated into one in multiarray.
17
+
18
+ They are available as import_array()
19
+ */
20
+
21
+ #include "__multiarray_api.h"
22
+
23
+
24
+ /* C-API that requires previous API to be defined */
25
+
26
+ #define PyArray_DescrCheck(op) PyObject_TypeCheck(op, &PyArrayDescr_Type)
27
+
28
+ #define PyArray_Check(op) PyObject_TypeCheck(op, &PyArray_Type)
29
+ #define PyArray_CheckExact(op) (((PyObject*)(op))->ob_type == &PyArray_Type)
30
+
31
+ #define PyArray_HasArrayInterfaceType(op, type, context, out) \
32
+ ((((out)=PyArray_FromStructInterface(op)) != Py_NotImplemented) || \
33
+ (((out)=PyArray_FromInterface(op)) != Py_NotImplemented) || \
34
+ (((out)=PyArray_FromArrayAttr(op, type, context)) != \
35
+ Py_NotImplemented))
36
+
37
+ #define PyArray_HasArrayInterface(op, out) \
38
+ PyArray_HasArrayInterfaceType(op, NULL, NULL, out)
39
+
40
+ #define PyArray_IsZeroDim(op) (PyArray_Check(op) && \
41
+ (PyArray_NDIM((PyArrayObject *)op) == 0))
42
+
43
+ #define PyArray_IsScalar(obj, cls) \
44
+ (PyObject_TypeCheck(obj, &Py##cls##ArrType_Type))
45
+
46
+ #define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \
47
+ PyArray_IsZeroDim(m))
48
+ #define PyArray_IsPythonNumber(obj) \
49
+ (PyFloat_Check(obj) || PyComplex_Check(obj) || \
50
+ PyLong_Check(obj) || PyBool_Check(obj))
51
+ #define PyArray_IsIntegerScalar(obj) (PyLong_Check(obj) \
52
+ || PyArray_IsScalar((obj), Integer))
53
+ #define PyArray_IsPythonScalar(obj) \
54
+ (PyArray_IsPythonNumber(obj) || PyBytes_Check(obj) || \
55
+ PyUnicode_Check(obj))
56
+
57
+ #define PyArray_IsAnyScalar(obj) \
58
+ (PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))
59
+
60
+ #define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \
61
+ PyArray_CheckScalar(obj))
62
+
63
+
64
+ #define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? \
65
+ Py_INCREF(m), (m) : \
66
+ (PyArrayObject *)(PyArray_Copy(m)))
67
+
68
+ #define PyArray_SAMESHAPE(a1,a2) ((PyArray_NDIM(a1) == PyArray_NDIM(a2)) && \
69
+ PyArray_CompareLists(PyArray_DIMS(a1), \
70
+ PyArray_DIMS(a2), \
71
+ PyArray_NDIM(a1)))
72
+
73
+ #define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))
74
+ #define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))
75
+ #define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)
76
+
77
+ #define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, \
78
+ NULL)
79
+
80
+ #define PyArray_FROM_OT(m,type) PyArray_FromAny(m, \
81
+ PyArray_DescrFromType(type), 0, 0, 0, NULL)
82
+
83
+ #define PyArray_FROM_OTF(m, type, flags) \
84
+ PyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \
85
+ (((flags) & NPY_ARRAY_ENSURECOPY) ? \
86
+ ((flags) | NPY_ARRAY_DEFAULT) : (flags)), NULL)
87
+
88
+ #define PyArray_FROMANY(m, type, min, max, flags) \
89
+ PyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \
90
+ (((flags) & NPY_ARRAY_ENSURECOPY) ? \
91
+ (flags) | NPY_ARRAY_DEFAULT : (flags)), NULL)
92
+
93
+ #define PyArray_ZEROS(m, dims, type, is_f_order) \
94
+ PyArray_Zeros(m, dims, PyArray_DescrFromType(type), is_f_order)
95
+
96
+ #define PyArray_EMPTY(m, dims, type, is_f_order) \
97
+ PyArray_Empty(m, dims, PyArray_DescrFromType(type), is_f_order)
98
+
99
+ #define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), val, \
100
+ PyArray_NBYTES(obj))
101
+ #ifndef PYPY_VERSION
102
+ #define PyArray_REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)
103
+ #define NPY_REFCOUNT PyArray_REFCOUNT
104
+ #endif
105
+ #define NPY_MAX_ELSIZE (2 * NPY_SIZEOF_LONGDOUBLE)
106
+
107
+ #define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \
108
+ PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
109
+ max_depth, NPY_ARRAY_DEFAULT, NULL)
110
+
111
+ #define PyArray_EquivArrTypes(a1, a2) \
112
+ PyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))
113
+
114
+ #define PyArray_EquivByteorders(b1, b2) \
115
+ (((b1) == (b2)) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))
116
+
117
+ #define PyArray_SimpleNew(nd, dims, typenum) \
118
+ PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)
119
+
120
+ #define PyArray_SimpleNewFromData(nd, dims, typenum, data) \
121
+ PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, \
122
+ data, 0, NPY_ARRAY_CARRAY, NULL)
123
+
124
+ #define PyArray_SimpleNewFromDescr(nd, dims, descr) \
125
+ PyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, \
126
+ NULL, NULL, 0, NULL)
127
+
128
+ #define PyArray_ToScalar(data, arr) \
129
+ PyArray_Scalar(data, PyArray_DESCR(arr), (PyObject *)arr)
130
+
131
+
132
+ /* These might be faster without the dereferencing of obj
133
+ going on inside -- of course an optimizing compiler should
134
+ inline the constants inside a for loop making it a moot point
135
+ */
136
+
137
+ #define PyArray_GETPTR1(obj, i) ((void *)(PyArray_BYTES(obj) + \
138
+ (i)*PyArray_STRIDES(obj)[0]))
139
+
140
+ #define PyArray_GETPTR2(obj, i, j) ((void *)(PyArray_BYTES(obj) + \
141
+ (i)*PyArray_STRIDES(obj)[0] + \
142
+ (j)*PyArray_STRIDES(obj)[1]))
143
+
144
+ #define PyArray_GETPTR3(obj, i, j, k) ((void *)(PyArray_BYTES(obj) + \
145
+ (i)*PyArray_STRIDES(obj)[0] + \
146
+ (j)*PyArray_STRIDES(obj)[1] + \
147
+ (k)*PyArray_STRIDES(obj)[2]))
148
+
149
+ #define PyArray_GETPTR4(obj, i, j, k, l) ((void *)(PyArray_BYTES(obj) + \
150
+ (i)*PyArray_STRIDES(obj)[0] + \
151
+ (j)*PyArray_STRIDES(obj)[1] + \
152
+ (k)*PyArray_STRIDES(obj)[2] + \
153
+ (l)*PyArray_STRIDES(obj)[3]))
154
+
155
+ static inline void
156
+ PyArray_DiscardWritebackIfCopy(PyArrayObject *arr)
157
+ {
158
+ PyArrayObject_fields *fa = (PyArrayObject_fields *)arr;
159
+ if (fa && fa->base) {
160
+ if (fa->flags & NPY_ARRAY_WRITEBACKIFCOPY) {
161
+ PyArray_ENABLEFLAGS((PyArrayObject*)fa->base, NPY_ARRAY_WRITEABLE);
162
+ Py_DECREF(fa->base);
163
+ fa->base = NULL;
164
+ PyArray_CLEARFLAGS(arr, NPY_ARRAY_WRITEBACKIFCOPY);
165
+ }
166
+ }
167
+ }
168
+
169
+ #define PyArray_DESCR_REPLACE(descr) do { \
170
+ PyArray_Descr *_new_; \
171
+ _new_ = PyArray_DescrNew(descr); \
172
+ Py_XDECREF(descr); \
173
+ descr = _new_; \
174
+ } while(0)
175
+
176
+ /* Copy should always return contiguous array */
177
+ #define PyArray_Copy(obj) PyArray_NewCopy(obj, NPY_CORDER)
178
+
179
+ #define PyArray_FromObject(op, type, min_depth, max_depth) \
180
+ PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
181
+ max_depth, NPY_ARRAY_BEHAVED | \
182
+ NPY_ARRAY_ENSUREARRAY, NULL)
183
+
184
+ #define PyArray_ContiguousFromObject(op, type, min_depth, max_depth) \
185
+ PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
186
+ max_depth, NPY_ARRAY_DEFAULT | \
187
+ NPY_ARRAY_ENSUREARRAY, NULL)
188
+
189
+ #define PyArray_CopyFromObject(op, type, min_depth, max_depth) \
190
+ PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
191
+ max_depth, NPY_ARRAY_ENSURECOPY | \
192
+ NPY_ARRAY_DEFAULT | \
193
+ NPY_ARRAY_ENSUREARRAY, NULL)
194
+
195
+ #define PyArray_Cast(mp, type_num) \
196
+ PyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)
197
+
198
+ #define PyArray_Take(ap, items, axis) \
199
+ PyArray_TakeFrom(ap, items, axis, NULL, NPY_RAISE)
200
+
201
+ #define PyArray_Put(ap, items, values) \
202
+ PyArray_PutTo(ap, items, values, NPY_RAISE)
203
+
204
+ /* Compatibility with old Numeric stuff -- don't use in new code */
205
+
206
+ #define PyArray_FromDimsAndData(nd, d, type, data) \
207
+ PyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \
208
+ data)
209
+
210
+
211
+ /*
212
+ Check to see if this key in the dictionary is the "title"
213
+ entry of the tuple (i.e. a duplicate dictionary entry in the fields
214
+ dict).
215
+ */
216
+
217
+ static inline int
218
+ NPY_TITLE_KEY_check(PyObject *key, PyObject *value)
219
+ {
220
+ PyObject *title;
221
+ if (PyTuple_Size(value) != 3) {
222
+ return 0;
223
+ }
224
+ title = PyTuple_GetItem(value, 2);
225
+ if (key == title) {
226
+ return 1;
227
+ }
228
+ #ifdef PYPY_VERSION
229
+ /*
230
+ * On PyPy, dictionary keys do not always preserve object identity.
231
+ * Fall back to comparison by value.
232
+ */
233
+ if (PyUnicode_Check(title) && PyUnicode_Check(key)) {
234
+ return PyUnicode_Compare(title, key) == 0 ? 1 : 0;
235
+ }
236
+ #endif
237
+ return 0;
238
+ }
239
+
240
+ /* Macro, for backward compat with "if NPY_TITLE_KEY(key, value) { ..." */
241
+ #define NPY_TITLE_KEY(key, value) (NPY_TITLE_KEY_check((key), (value)))
242
+
243
+ #define DEPRECATE(msg) PyErr_WarnEx(PyExc_DeprecationWarning,msg,1)
244
+ #define DEPRECATE_FUTUREWARNING(msg) PyErr_WarnEx(PyExc_FutureWarning,msg,1)
245
+
246
+ #ifdef __cplusplus
247
+ }
248
+ #endif
249
+
250
+
251
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NDARRAYOBJECT_H_ */
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/ndarraytypes.h ADDED
@@ -0,0 +1,1945 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /* Only use thread if configured in config and python supports it */
12
+ #if defined WITH_THREAD && !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
+ #if !defined(_NPY_NO_DEPRECATIONS) && \
23
+ ((defined(__GNUC__)&& __GNUC__ >= 6) || \
24
+ __has_extension(attribute_deprecated_with_message))
25
+ #define NPY_ATTR_DEPRECATE(text) __attribute__ ((deprecated (text)))
26
+ #else
27
+ #define NPY_ATTR_DEPRECATE(text)
28
+ #endif
29
+
30
+ /*
31
+ * There are several places in the code where an array of dimensions
32
+ * is allocated statically. This is the size of that static
33
+ * allocation.
34
+ *
35
+ * The array creation itself could have arbitrary dimensions but all
36
+ * the places where static allocation is used would need to be changed
37
+ * to dynamic (including inside of several structures)
38
+ */
39
+
40
+ #define NPY_MAXDIMS 32
41
+ #define NPY_MAXARGS 32
42
+
43
+ /* Used for Converter Functions "O&" code in ParseTuple */
44
+ #define NPY_FAIL 0
45
+ #define NPY_SUCCEED 1
46
+
47
+
48
+ enum NPY_TYPES { NPY_BOOL=0,
49
+ NPY_BYTE, NPY_UBYTE,
50
+ NPY_SHORT, NPY_USHORT,
51
+ NPY_INT, NPY_UINT,
52
+ NPY_LONG, NPY_ULONG,
53
+ NPY_LONGLONG, NPY_ULONGLONG,
54
+ NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE,
55
+ NPY_CFLOAT, NPY_CDOUBLE, NPY_CLONGDOUBLE,
56
+ NPY_OBJECT=17,
57
+ NPY_STRING, NPY_UNICODE,
58
+ NPY_VOID,
59
+ /*
60
+ * New 1.6 types appended, may be integrated
61
+ * into the above in 2.0.
62
+ */
63
+ NPY_DATETIME, NPY_TIMEDELTA, NPY_HALF,
64
+
65
+ NPY_NTYPES,
66
+ NPY_NOTYPE,
67
+ NPY_CHAR NPY_ATTR_DEPRECATE("Use NPY_STRING"),
68
+ NPY_USERDEF=256, /* leave room for characters */
69
+
70
+ /* The number of types not including the new 1.6 types */
71
+ NPY_NTYPES_ABI_COMPATIBLE=21
72
+ };
73
+ #if defined(_MSC_VER) && !defined(__clang__)
74
+ #pragma deprecated(NPY_CHAR)
75
+ #endif
76
+
77
+ /* basetype array priority */
78
+ #define NPY_PRIORITY 0.0
79
+
80
+ /* default subtype priority */
81
+ #define NPY_SUBTYPE_PRIORITY 1.0
82
+
83
+ /* default scalar priority */
84
+ #define NPY_SCALAR_PRIORITY -1000000.0
85
+
86
+ /* How many floating point types are there (excluding half) */
87
+ #define NPY_NUM_FLOATTYPE 3
88
+
89
+ /*
90
+ * These characters correspond to the array type and the struct
91
+ * module
92
+ */
93
+
94
+ enum NPY_TYPECHAR {
95
+ NPY_BOOLLTR = '?',
96
+ NPY_BYTELTR = 'b',
97
+ NPY_UBYTELTR = 'B',
98
+ NPY_SHORTLTR = 'h',
99
+ NPY_USHORTLTR = 'H',
100
+ NPY_INTLTR = 'i',
101
+ NPY_UINTLTR = 'I',
102
+ NPY_LONGLTR = 'l',
103
+ NPY_ULONGLTR = 'L',
104
+ NPY_LONGLONGLTR = 'q',
105
+ NPY_ULONGLONGLTR = 'Q',
106
+ NPY_HALFLTR = 'e',
107
+ NPY_FLOATLTR = 'f',
108
+ NPY_DOUBLELTR = 'd',
109
+ NPY_LONGDOUBLELTR = 'g',
110
+ NPY_CFLOATLTR = 'F',
111
+ NPY_CDOUBLELTR = 'D',
112
+ NPY_CLONGDOUBLELTR = 'G',
113
+ NPY_OBJECTLTR = 'O',
114
+ NPY_STRINGLTR = 'S',
115
+ NPY_STRINGLTR2 = 'a',
116
+ NPY_UNICODELTR = 'U',
117
+ NPY_VOIDLTR = 'V',
118
+ NPY_DATETIMELTR = 'M',
119
+ NPY_TIMEDELTALTR = 'm',
120
+ NPY_CHARLTR = 'c',
121
+
122
+ /*
123
+ * No Descriptor, just a define -- this let's
124
+ * Python users specify an array of integers
125
+ * large enough to hold a pointer on the
126
+ * platform
127
+ */
128
+ NPY_INTPLTR = 'p',
129
+ NPY_UINTPLTR = 'P',
130
+
131
+ /*
132
+ * These are for dtype 'kinds', not dtype 'typecodes'
133
+ * as the above are for.
134
+ */
135
+ NPY_GENBOOLLTR ='b',
136
+ NPY_SIGNEDLTR = 'i',
137
+ NPY_UNSIGNEDLTR = 'u',
138
+ NPY_FLOATINGLTR = 'f',
139
+ NPY_COMPLEXLTR = 'c'
140
+ };
141
+
142
+ /*
143
+ * Changing this may break Numpy API compatibility
144
+ * due to changing offsets in PyArray_ArrFuncs, so be
145
+ * careful. Here we have reused the mergesort slot for
146
+ * any kind of stable sort, the actual implementation will
147
+ * depend on the data type.
148
+ */
149
+ typedef enum {
150
+ NPY_QUICKSORT=0,
151
+ NPY_HEAPSORT=1,
152
+ NPY_MERGESORT=2,
153
+ NPY_STABLESORT=2,
154
+ } NPY_SORTKIND;
155
+ #define NPY_NSORTS (NPY_STABLESORT + 1)
156
+
157
+
158
+ typedef enum {
159
+ NPY_INTROSELECT=0
160
+ } NPY_SELECTKIND;
161
+ #define NPY_NSELECTS (NPY_INTROSELECT + 1)
162
+
163
+
164
+ typedef enum {
165
+ NPY_SEARCHLEFT=0,
166
+ NPY_SEARCHRIGHT=1
167
+ } NPY_SEARCHSIDE;
168
+ #define NPY_NSEARCHSIDES (NPY_SEARCHRIGHT + 1)
169
+
170
+
171
+ typedef enum {
172
+ NPY_NOSCALAR=-1,
173
+ NPY_BOOL_SCALAR,
174
+ NPY_INTPOS_SCALAR,
175
+ NPY_INTNEG_SCALAR,
176
+ NPY_FLOAT_SCALAR,
177
+ NPY_COMPLEX_SCALAR,
178
+ NPY_OBJECT_SCALAR
179
+ } NPY_SCALARKIND;
180
+ #define NPY_NSCALARKINDS (NPY_OBJECT_SCALAR + 1)
181
+
182
+ /* For specifying array memory layout or iteration order */
183
+ typedef enum {
184
+ /* Fortran order if inputs are all Fortran, C otherwise */
185
+ NPY_ANYORDER=-1,
186
+ /* C order */
187
+ NPY_CORDER=0,
188
+ /* Fortran order */
189
+ NPY_FORTRANORDER=1,
190
+ /* An order as close to the inputs as possible */
191
+ NPY_KEEPORDER=2
192
+ } NPY_ORDER;
193
+
194
+ /* For specifying allowed casting in operations which support it */
195
+ typedef enum {
196
+ _NPY_ERROR_OCCURRED_IN_CAST = -1,
197
+ /* Only allow identical types */
198
+ NPY_NO_CASTING=0,
199
+ /* Allow identical and byte swapped types */
200
+ NPY_EQUIV_CASTING=1,
201
+ /* Only allow safe casts */
202
+ NPY_SAFE_CASTING=2,
203
+ /* Allow safe casts or casts within the same kind */
204
+ NPY_SAME_KIND_CASTING=3,
205
+ /* Allow any casts */
206
+ NPY_UNSAFE_CASTING=4,
207
+ } NPY_CASTING;
208
+
209
+ typedef enum {
210
+ NPY_CLIP=0,
211
+ NPY_WRAP=1,
212
+ NPY_RAISE=2
213
+ } NPY_CLIPMODE;
214
+
215
+ typedef enum {
216
+ NPY_VALID=0,
217
+ NPY_SAME=1,
218
+ NPY_FULL=2
219
+ } NPY_CORRELATEMODE;
220
+
221
+ /* The special not-a-time (NaT) value */
222
+ #define NPY_DATETIME_NAT NPY_MIN_INT64
223
+
224
+ /*
225
+ * Upper bound on the length of a DATETIME ISO 8601 string
226
+ * YEAR: 21 (64-bit year)
227
+ * MONTH: 3
228
+ * DAY: 3
229
+ * HOURS: 3
230
+ * MINUTES: 3
231
+ * SECONDS: 3
232
+ * ATTOSECONDS: 1 + 3*6
233
+ * TIMEZONE: 5
234
+ * NULL TERMINATOR: 1
235
+ */
236
+ #define NPY_DATETIME_MAX_ISO8601_STRLEN (21 + 3*5 + 1 + 3*6 + 6 + 1)
237
+
238
+ /* The FR in the unit names stands for frequency */
239
+ typedef enum {
240
+ /* Force signed enum type, must be -1 for code compatibility */
241
+ NPY_FR_ERROR = -1, /* error or undetermined */
242
+
243
+ /* Start of valid units */
244
+ NPY_FR_Y = 0, /* Years */
245
+ NPY_FR_M = 1, /* Months */
246
+ NPY_FR_W = 2, /* Weeks */
247
+ /* Gap where 1.6 NPY_FR_B (value 3) was */
248
+ NPY_FR_D = 4, /* Days */
249
+ NPY_FR_h = 5, /* hours */
250
+ NPY_FR_m = 6, /* minutes */
251
+ NPY_FR_s = 7, /* seconds */
252
+ NPY_FR_ms = 8, /* milliseconds */
253
+ NPY_FR_us = 9, /* microseconds */
254
+ NPY_FR_ns = 10, /* nanoseconds */
255
+ NPY_FR_ps = 11, /* picoseconds */
256
+ NPY_FR_fs = 12, /* femtoseconds */
257
+ NPY_FR_as = 13, /* attoseconds */
258
+ NPY_FR_GENERIC = 14 /* unbound units, can convert to anything */
259
+ } NPY_DATETIMEUNIT;
260
+
261
+ /*
262
+ * NOTE: With the NPY_FR_B gap for 1.6 ABI compatibility, NPY_DATETIME_NUMUNITS
263
+ * is technically one more than the actual number of units.
264
+ */
265
+ #define NPY_DATETIME_NUMUNITS (NPY_FR_GENERIC + 1)
266
+ #define NPY_DATETIME_DEFAULTUNIT NPY_FR_GENERIC
267
+
268
+ /*
269
+ * Business day conventions for mapping invalid business
270
+ * days to valid business days.
271
+ */
272
+ typedef enum {
273
+ /* Go forward in time to the following business day. */
274
+ NPY_BUSDAY_FORWARD,
275
+ NPY_BUSDAY_FOLLOWING = NPY_BUSDAY_FORWARD,
276
+ /* Go backward in time to the preceding business day. */
277
+ NPY_BUSDAY_BACKWARD,
278
+ NPY_BUSDAY_PRECEDING = NPY_BUSDAY_BACKWARD,
279
+ /*
280
+ * Go forward in time to the following business day, unless it
281
+ * crosses a month boundary, in which case go backward
282
+ */
283
+ NPY_BUSDAY_MODIFIEDFOLLOWING,
284
+ /*
285
+ * Go backward in time to the preceding business day, unless it
286
+ * crosses a month boundary, in which case go forward.
287
+ */
288
+ NPY_BUSDAY_MODIFIEDPRECEDING,
289
+ /* Produce a NaT for non-business days. */
290
+ NPY_BUSDAY_NAT,
291
+ /* Raise an exception for non-business days. */
292
+ NPY_BUSDAY_RAISE
293
+ } NPY_BUSDAY_ROLL;
294
+
295
+ /************************************************************
296
+ * NumPy Auxiliary Data for inner loops, sort functions, etc.
297
+ ************************************************************/
298
+
299
+ /*
300
+ * When creating an auxiliary data struct, this should always appear
301
+ * as the first member, like this:
302
+ *
303
+ * typedef struct {
304
+ * NpyAuxData base;
305
+ * double constant;
306
+ * } constant_multiplier_aux_data;
307
+ */
308
+ typedef struct NpyAuxData_tag NpyAuxData;
309
+
310
+ /* Function pointers for freeing or cloning auxiliary data */
311
+ typedef void (NpyAuxData_FreeFunc) (NpyAuxData *);
312
+ typedef NpyAuxData *(NpyAuxData_CloneFunc) (NpyAuxData *);
313
+
314
+ struct NpyAuxData_tag {
315
+ NpyAuxData_FreeFunc *free;
316
+ NpyAuxData_CloneFunc *clone;
317
+ /* To allow for a bit of expansion without breaking the ABI */
318
+ void *reserved[2];
319
+ };
320
+
321
+ /* Macros to use for freeing and cloning auxiliary data */
322
+ #define NPY_AUXDATA_FREE(auxdata) \
323
+ do { \
324
+ if ((auxdata) != NULL) { \
325
+ (auxdata)->free(auxdata); \
326
+ } \
327
+ } while(0)
328
+ #define NPY_AUXDATA_CLONE(auxdata) \
329
+ ((auxdata)->clone(auxdata))
330
+
331
+ #define NPY_ERR(str) fprintf(stderr, #str); fflush(stderr);
332
+ #define NPY_ERR2(str) fprintf(stderr, str); fflush(stderr);
333
+
334
+ /*
335
+ * Macros to define how array, and dimension/strides data is
336
+ * allocated. These should be made private
337
+ */
338
+
339
+ #define NPY_USE_PYMEM 1
340
+
341
+
342
+ #if NPY_USE_PYMEM == 1
343
+ /* use the Raw versions which are safe to call with the GIL released */
344
+ #define PyArray_malloc PyMem_RawMalloc
345
+ #define PyArray_free PyMem_RawFree
346
+ #define PyArray_realloc PyMem_RawRealloc
347
+ #else
348
+ #define PyArray_malloc malloc
349
+ #define PyArray_free free
350
+ #define PyArray_realloc realloc
351
+ #endif
352
+
353
+ /* Dimensions and strides */
354
+ #define PyDimMem_NEW(size) \
355
+ ((npy_intp *)PyArray_malloc(size*sizeof(npy_intp)))
356
+
357
+ #define PyDimMem_FREE(ptr) PyArray_free(ptr)
358
+
359
+ #define PyDimMem_RENEW(ptr,size) \
360
+ ((npy_intp *)PyArray_realloc(ptr,size*sizeof(npy_intp)))
361
+
362
+ /* forward declaration */
363
+ struct _PyArray_Descr;
364
+
365
+ /* These must deal with unaligned and swapped data if necessary */
366
+ typedef PyObject * (PyArray_GetItemFunc) (void *, void *);
367
+ typedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);
368
+
369
+ typedef void (PyArray_CopySwapNFunc)(void *, npy_intp, void *, npy_intp,
370
+ npy_intp, int, void *);
371
+
372
+ typedef void (PyArray_CopySwapFunc)(void *, void *, int, void *);
373
+ typedef npy_bool (PyArray_NonzeroFunc)(void *, void *);
374
+
375
+
376
+ /*
377
+ * These assume aligned and notswapped data -- a buffer will be used
378
+ * before or contiguous data will be obtained
379
+ */
380
+
381
+ typedef int (PyArray_CompareFunc)(const void *, const void *, void *);
382
+ typedef int (PyArray_ArgFunc)(void*, npy_intp, npy_intp*, void *);
383
+
384
+ typedef void (PyArray_DotFunc)(void *, npy_intp, void *, npy_intp, void *,
385
+ npy_intp, void *);
386
+
387
+ typedef void (PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *,
388
+ void *);
389
+
390
+ /*
391
+ * XXX the ignore argument should be removed next time the API version
392
+ * is bumped. It used to be the separator.
393
+ */
394
+ typedef int (PyArray_ScanFunc)(FILE *fp, void *dptr,
395
+ char *ignore, struct _PyArray_Descr *);
396
+ typedef int (PyArray_FromStrFunc)(char *s, void *dptr, char **endptr,
397
+ struct _PyArray_Descr *);
398
+
399
+ typedef int (PyArray_FillFunc)(void *, npy_intp, void *);
400
+
401
+ typedef int (PyArray_SortFunc)(void *, npy_intp, void *);
402
+ typedef int (PyArray_ArgSortFunc)(void *, npy_intp *, npy_intp, void *);
403
+ typedef int (PyArray_PartitionFunc)(void *, npy_intp, npy_intp,
404
+ npy_intp *, npy_intp *,
405
+ void *);
406
+ typedef int (PyArray_ArgPartitionFunc)(void *, npy_intp *, npy_intp, npy_intp,
407
+ npy_intp *, npy_intp *,
408
+ void *);
409
+
410
+ typedef int (PyArray_FillWithScalarFunc)(void *, npy_intp, void *, void *);
411
+
412
+ typedef int (PyArray_ScalarKindFunc)(void *);
413
+
414
+ typedef void (PyArray_FastClipFunc)(void *in, npy_intp n_in, void *min,
415
+ void *max, void *out);
416
+ typedef void (PyArray_FastPutmaskFunc)(void *in, void *mask, npy_intp n_in,
417
+ void *values, npy_intp nv);
418
+ typedef int (PyArray_FastTakeFunc)(void *dest, void *src, npy_intp *indarray,
419
+ npy_intp nindarray, npy_intp n_outer,
420
+ npy_intp m_middle, npy_intp nelem,
421
+ NPY_CLIPMODE clipmode);
422
+
423
+ typedef struct {
424
+ npy_intp *ptr;
425
+ int len;
426
+ } PyArray_Dims;
427
+
428
+ typedef struct {
429
+ /*
430
+ * Functions to cast to most other standard types
431
+ * Can have some NULL entries. The types
432
+ * DATETIME, TIMEDELTA, and HALF go into the castdict
433
+ * even though they are built-in.
434
+ */
435
+ PyArray_VectorUnaryFunc *cast[NPY_NTYPES_ABI_COMPATIBLE];
436
+
437
+ /* The next four functions *cannot* be NULL */
438
+
439
+ /*
440
+ * Functions to get and set items with standard Python types
441
+ * -- not array scalars
442
+ */
443
+ PyArray_GetItemFunc *getitem;
444
+ PyArray_SetItemFunc *setitem;
445
+
446
+ /*
447
+ * Copy and/or swap data. Memory areas may not overlap
448
+ * Use memmove first if they might
449
+ */
450
+ PyArray_CopySwapNFunc *copyswapn;
451
+ PyArray_CopySwapFunc *copyswap;
452
+
453
+ /*
454
+ * Function to compare items
455
+ * Can be NULL
456
+ */
457
+ PyArray_CompareFunc *compare;
458
+
459
+ /*
460
+ * Function to select largest
461
+ * Can be NULL
462
+ */
463
+ PyArray_ArgFunc *argmax;
464
+
465
+ /*
466
+ * Function to compute dot product
467
+ * Can be NULL
468
+ */
469
+ PyArray_DotFunc *dotfunc;
470
+
471
+ /*
472
+ * Function to scan an ASCII file and
473
+ * place a single value plus possible separator
474
+ * Can be NULL
475
+ */
476
+ PyArray_ScanFunc *scanfunc;
477
+
478
+ /*
479
+ * Function to read a single value from a string
480
+ * and adjust the pointer; Can be NULL
481
+ */
482
+ PyArray_FromStrFunc *fromstr;
483
+
484
+ /*
485
+ * Function to determine if data is zero or not
486
+ * If NULL a default version is
487
+ * used at Registration time.
488
+ */
489
+ PyArray_NonzeroFunc *nonzero;
490
+
491
+ /*
492
+ * Used for arange. Should return 0 on success
493
+ * and -1 on failure.
494
+ * Can be NULL.
495
+ */
496
+ PyArray_FillFunc *fill;
497
+
498
+ /*
499
+ * Function to fill arrays with scalar values
500
+ * Can be NULL
501
+ */
502
+ PyArray_FillWithScalarFunc *fillwithscalar;
503
+
504
+ /*
505
+ * Sorting functions
506
+ * Can be NULL
507
+ */
508
+ PyArray_SortFunc *sort[NPY_NSORTS];
509
+ PyArray_ArgSortFunc *argsort[NPY_NSORTS];
510
+
511
+ /*
512
+ * Dictionary of additional casting functions
513
+ * PyArray_VectorUnaryFuncs
514
+ * which can be populated to support casting
515
+ * to other registered types. Can be NULL
516
+ */
517
+ PyObject *castdict;
518
+
519
+ /*
520
+ * Functions useful for generalizing
521
+ * the casting rules.
522
+ * Can be NULL;
523
+ */
524
+ PyArray_ScalarKindFunc *scalarkind;
525
+ int **cancastscalarkindto;
526
+ int *cancastto;
527
+
528
+ PyArray_FastClipFunc *fastclip;
529
+ PyArray_FastPutmaskFunc *fastputmask;
530
+ PyArray_FastTakeFunc *fasttake;
531
+
532
+ /*
533
+ * Function to select smallest
534
+ * Can be NULL
535
+ */
536
+ PyArray_ArgFunc *argmin;
537
+
538
+ } PyArray_ArrFuncs;
539
+
540
+ /* The item must be reference counted when it is inserted or extracted. */
541
+ #define NPY_ITEM_REFCOUNT 0x01
542
+ /* Same as needing REFCOUNT */
543
+ #define NPY_ITEM_HASOBJECT 0x01
544
+ /* Convert to list for pickling */
545
+ #define NPY_LIST_PICKLE 0x02
546
+ /* The item is a POINTER */
547
+ #define NPY_ITEM_IS_POINTER 0x04
548
+ /* memory needs to be initialized for this data-type */
549
+ #define NPY_NEEDS_INIT 0x08
550
+ /* operations need Python C-API so don't give-up thread. */
551
+ #define NPY_NEEDS_PYAPI 0x10
552
+ /* Use f.getitem when extracting elements of this data-type */
553
+ #define NPY_USE_GETITEM 0x20
554
+ /* Use f.setitem when setting creating 0-d array from this data-type.*/
555
+ #define NPY_USE_SETITEM 0x40
556
+ /* A sticky flag specifically for structured arrays */
557
+ #define NPY_ALIGNED_STRUCT 0x80
558
+
559
+ /*
560
+ *These are inherited for global data-type if any data-types in the
561
+ * field have them
562
+ */
563
+ #define NPY_FROM_FIELDS (NPY_NEEDS_INIT | NPY_LIST_PICKLE | \
564
+ NPY_ITEM_REFCOUNT | NPY_NEEDS_PYAPI)
565
+
566
+ #define NPY_OBJECT_DTYPE_FLAGS (NPY_LIST_PICKLE | NPY_USE_GETITEM | \
567
+ NPY_ITEM_IS_POINTER | NPY_ITEM_REFCOUNT | \
568
+ NPY_NEEDS_INIT | NPY_NEEDS_PYAPI)
569
+
570
+ #define PyDataType_FLAGCHK(dtype, flag) \
571
+ (((dtype)->flags & (flag)) == (flag))
572
+
573
+ #define PyDataType_REFCHK(dtype) \
574
+ PyDataType_FLAGCHK(dtype, NPY_ITEM_REFCOUNT)
575
+
576
+ typedef struct _PyArray_Descr {
577
+ PyObject_HEAD
578
+ /*
579
+ * the type object representing an
580
+ * instance of this type -- should not
581
+ * be two type_numbers with the same type
582
+ * object.
583
+ */
584
+ PyTypeObject *typeobj;
585
+ /* kind for this type */
586
+ char kind;
587
+ /* unique-character representing this type */
588
+ char type;
589
+ /*
590
+ * '>' (big), '<' (little), '|'
591
+ * (not-applicable), or '=' (native).
592
+ */
593
+ char byteorder;
594
+ /* flags describing data type */
595
+ char flags;
596
+ /* number representing this type */
597
+ int type_num;
598
+ /* element size (itemsize) for this type */
599
+ int elsize;
600
+ /* alignment needed for this type */
601
+ int alignment;
602
+ /*
603
+ * Non-NULL if this type is
604
+ * is an array (C-contiguous)
605
+ * of some other type
606
+ */
607
+ struct _arr_descr *subarray;
608
+ /*
609
+ * The fields dictionary for this type
610
+ * For statically defined descr this
611
+ * is always Py_None
612
+ */
613
+ PyObject *fields;
614
+ /*
615
+ * An ordered tuple of field names or NULL
616
+ * if no fields are defined
617
+ */
618
+ PyObject *names;
619
+ /*
620
+ * a table of functions specific for each
621
+ * basic data descriptor
622
+ */
623
+ PyArray_ArrFuncs *f;
624
+ /* Metadata about this dtype */
625
+ PyObject *metadata;
626
+ /*
627
+ * Metadata specific to the C implementation
628
+ * of the particular dtype. This was added
629
+ * for NumPy 1.7.0.
630
+ */
631
+ NpyAuxData *c_metadata;
632
+ /* Cached hash value (-1 if not yet computed).
633
+ * This was added for NumPy 2.0.0.
634
+ */
635
+ npy_hash_t hash;
636
+ } PyArray_Descr;
637
+
638
+ typedef struct _arr_descr {
639
+ PyArray_Descr *base;
640
+ PyObject *shape; /* a tuple */
641
+ } PyArray_ArrayDescr;
642
+
643
+ /*
644
+ * Memory handler structure for array data.
645
+ */
646
+ /* The declaration of free differs from PyMemAllocatorEx */
647
+ typedef struct {
648
+ void *ctx;
649
+ void* (*malloc) (void *ctx, size_t size);
650
+ void* (*calloc) (void *ctx, size_t nelem, size_t elsize);
651
+ void* (*realloc) (void *ctx, void *ptr, size_t new_size);
652
+ void (*free) (void *ctx, void *ptr, size_t size);
653
+ /*
654
+ * This is the end of the version=1 struct. Only add new fields after
655
+ * this line
656
+ */
657
+ } PyDataMemAllocator;
658
+
659
+ typedef struct {
660
+ char name[127]; /* multiple of 64 to keep the struct aligned */
661
+ uint8_t version; /* currently 1 */
662
+ PyDataMemAllocator allocator;
663
+ } PyDataMem_Handler;
664
+
665
+
666
+ /*
667
+ * The main array object structure.
668
+ *
669
+ * It has been recommended to use the inline functions defined below
670
+ * (PyArray_DATA and friends) to access fields here for a number of
671
+ * releases. Direct access to the members themselves is deprecated.
672
+ * To ensure that your code does not use deprecated access,
673
+ * #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
674
+ * (or NPY_1_8_API_VERSION or higher as required).
675
+ */
676
+ /* This struct will be moved to a private header in a future release */
677
+ typedef struct tagPyArrayObject_fields {
678
+ PyObject_HEAD
679
+ /* Pointer to the raw data buffer */
680
+ char *data;
681
+ /* The number of dimensions, also called 'ndim' */
682
+ int nd;
683
+ /* The size in each dimension, also called 'shape' */
684
+ npy_intp *dimensions;
685
+ /*
686
+ * Number of bytes to jump to get to the
687
+ * next element in each dimension
688
+ */
689
+ npy_intp *strides;
690
+ /*
691
+ * This object is decref'd upon
692
+ * deletion of array. Except in the
693
+ * case of WRITEBACKIFCOPY which has
694
+ * special handling.
695
+ *
696
+ * For views it points to the original
697
+ * array, collapsed so no chains of
698
+ * views occur.
699
+ *
700
+ * For creation from buffer object it
701
+ * points to an object that should be
702
+ * decref'd on deletion
703
+ *
704
+ * For WRITEBACKIFCOPY flag this is an
705
+ * array to-be-updated upon calling
706
+ * PyArray_ResolveWritebackIfCopy
707
+ */
708
+ PyObject *base;
709
+ /* Pointer to type structure */
710
+ PyArray_Descr *descr;
711
+ /* Flags describing array -- see below */
712
+ int flags;
713
+ /* For weak references */
714
+ PyObject *weakreflist;
715
+ #if NPY_FEATURE_VERSION >= NPY_1_20_API_VERSION
716
+ void *_buffer_info; /* private buffer info, tagged to allow warning */
717
+ #endif
718
+ /*
719
+ * For malloc/calloc/realloc/free per object
720
+ */
721
+ #if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
722
+ PyObject *mem_handler;
723
+ #endif
724
+ } PyArrayObject_fields;
725
+
726
+ /*
727
+ * To hide the implementation details, we only expose
728
+ * the Python struct HEAD.
729
+ */
730
+ #if !defined(NPY_NO_DEPRECATED_API) || \
731
+ (NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION)
732
+ /*
733
+ * Can't put this in npy_deprecated_api.h like the others.
734
+ * PyArrayObject field access is deprecated as of NumPy 1.7.
735
+ */
736
+ typedef PyArrayObject_fields PyArrayObject;
737
+ #else
738
+ typedef struct tagPyArrayObject {
739
+ PyObject_HEAD
740
+ } PyArrayObject;
741
+ #endif
742
+
743
+ /*
744
+ * Removed 2020-Nov-25, NumPy 1.20
745
+ * #define NPY_SIZEOF_PYARRAYOBJECT (sizeof(PyArrayObject_fields))
746
+ *
747
+ * The above macro was removed as it gave a false sense of a stable ABI
748
+ * with respect to the structures size. If you require a runtime constant,
749
+ * you can use `PyArray_Type.tp_basicsize` instead. Otherwise, please
750
+ * see the PyArrayObject documentation or ask the NumPy developers for
751
+ * information on how to correctly replace the macro in a way that is
752
+ * compatible with multiple NumPy versions.
753
+ */
754
+
755
+
756
+ /* Array Flags Object */
757
+ typedef struct PyArrayFlagsObject {
758
+ PyObject_HEAD
759
+ PyObject *arr;
760
+ int flags;
761
+ } PyArrayFlagsObject;
762
+
763
+ /* Mirrors buffer object to ptr */
764
+
765
+ typedef struct {
766
+ PyObject_HEAD
767
+ PyObject *base;
768
+ void *ptr;
769
+ npy_intp len;
770
+ int flags;
771
+ } PyArray_Chunk;
772
+
773
+ typedef struct {
774
+ NPY_DATETIMEUNIT base;
775
+ int num;
776
+ } PyArray_DatetimeMetaData;
777
+
778
+ typedef struct {
779
+ NpyAuxData base;
780
+ PyArray_DatetimeMetaData meta;
781
+ } PyArray_DatetimeDTypeMetaData;
782
+
783
+ /*
784
+ * This structure contains an exploded view of a date-time value.
785
+ * NaT is represented by year == NPY_DATETIME_NAT.
786
+ */
787
+ typedef struct {
788
+ npy_int64 year;
789
+ npy_int32 month, day, hour, min, sec, us, ps, as;
790
+ } npy_datetimestruct;
791
+
792
+ /* This is not used internally. */
793
+ typedef struct {
794
+ npy_int64 day;
795
+ npy_int32 sec, us, ps, as;
796
+ } npy_timedeltastruct;
797
+
798
+ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
799
+
800
+ /*
801
+ * Means c-style contiguous (last index varies the fastest). The data
802
+ * elements right after each other.
803
+ *
804
+ * This flag may be requested in constructor functions.
805
+ * This flag may be tested for in PyArray_FLAGS(arr).
806
+ */
807
+ #define NPY_ARRAY_C_CONTIGUOUS 0x0001
808
+
809
+ /*
810
+ * Set if array is a contiguous Fortran array: the first index varies
811
+ * the fastest in memory (strides array is reverse of C-contiguous
812
+ * array)
813
+ *
814
+ * This flag may be requested in constructor functions.
815
+ * This flag may be tested for in PyArray_FLAGS(arr).
816
+ */
817
+ #define NPY_ARRAY_F_CONTIGUOUS 0x0002
818
+
819
+ /*
820
+ * Note: all 0-d arrays are C_CONTIGUOUS and F_CONTIGUOUS. If a
821
+ * 1-d array is C_CONTIGUOUS it is also F_CONTIGUOUS. Arrays with
822
+ * more then one dimension can be C_CONTIGUOUS and F_CONTIGUOUS
823
+ * at the same time if they have either zero or one element.
824
+ * A higher dimensional array always has the same contiguity flags as
825
+ * `array.squeeze()`; dimensions with `array.shape[dimension] == 1` are
826
+ * effectively ignored when checking for contiguity.
827
+ */
828
+
829
+ /*
830
+ * If set, the array owns the data: it will be free'd when the array
831
+ * is deleted.
832
+ *
833
+ * This flag may be tested for in PyArray_FLAGS(arr).
834
+ */
835
+ #define NPY_ARRAY_OWNDATA 0x0004
836
+
837
+ /*
838
+ * An array never has the next four set; they're only used as parameter
839
+ * flags to the various FromAny functions
840
+ *
841
+ * This flag may be requested in constructor functions.
842
+ */
843
+
844
+ /* Cause a cast to occur regardless of whether or not it is safe. */
845
+ #define NPY_ARRAY_FORCECAST 0x0010
846
+
847
+ /*
848
+ * Always copy the array. Returned arrays are always CONTIGUOUS,
849
+ * ALIGNED, and WRITEABLE. See also: NPY_ARRAY_ENSURENOCOPY = 0x4000.
850
+ *
851
+ * This flag may be requested in constructor functions.
852
+ */
853
+ #define NPY_ARRAY_ENSURECOPY 0x0020
854
+
855
+ /*
856
+ * Make sure the returned array is a base-class ndarray
857
+ *
858
+ * This flag may be requested in constructor functions.
859
+ */
860
+ #define NPY_ARRAY_ENSUREARRAY 0x0040
861
+
862
+ /*
863
+ * Make sure that the strides are in units of the element size Needed
864
+ * for some operations with record-arrays.
865
+ *
866
+ * This flag may be requested in constructor functions.
867
+ */
868
+ #define NPY_ARRAY_ELEMENTSTRIDES 0x0080
869
+
870
+ /*
871
+ * Array data is aligned on the appropriate memory address for the type
872
+ * stored according to how the compiler would align things (e.g., an
873
+ * array of integers (4 bytes each) starts on a memory address that's
874
+ * a multiple of 4)
875
+ *
876
+ * This flag may be requested in constructor functions.
877
+ * This flag may be tested for in PyArray_FLAGS(arr).
878
+ */
879
+ #define NPY_ARRAY_ALIGNED 0x0100
880
+
881
+ /*
882
+ * Array data has the native endianness
883
+ *
884
+ * This flag may be requested in constructor functions.
885
+ */
886
+ #define NPY_ARRAY_NOTSWAPPED 0x0200
887
+
888
+ /*
889
+ * Array data is writeable
890
+ *
891
+ * This flag may be requested in constructor functions.
892
+ * This flag may be tested for in PyArray_FLAGS(arr).
893
+ */
894
+ #define NPY_ARRAY_WRITEABLE 0x0400
895
+
896
+ /*
897
+ * If this flag is set, then base contains a pointer to an array of
898
+ * the same size that should be updated with the current contents of
899
+ * this array when PyArray_ResolveWritebackIfCopy is called.
900
+ *
901
+ * This flag may be requested in constructor functions.
902
+ * This flag may be tested for in PyArray_FLAGS(arr).
903
+ */
904
+ #define NPY_ARRAY_WRITEBACKIFCOPY 0x2000
905
+
906
+ /*
907
+ * No copy may be made while converting from an object/array (result is a view)
908
+ *
909
+ * This flag may be requested in constructor functions.
910
+ */
911
+ #define NPY_ARRAY_ENSURENOCOPY 0x4000
912
+
913
+ /*
914
+ * NOTE: there are also internal flags defined in multiarray/arrayobject.h,
915
+ * which start at bit 31 and work down.
916
+ */
917
+
918
+ #define NPY_ARRAY_BEHAVED (NPY_ARRAY_ALIGNED | \
919
+ NPY_ARRAY_WRITEABLE)
920
+ #define NPY_ARRAY_BEHAVED_NS (NPY_ARRAY_ALIGNED | \
921
+ NPY_ARRAY_WRITEABLE | \
922
+ NPY_ARRAY_NOTSWAPPED)
923
+ #define NPY_ARRAY_CARRAY (NPY_ARRAY_C_CONTIGUOUS | \
924
+ NPY_ARRAY_BEHAVED)
925
+ #define NPY_ARRAY_CARRAY_RO (NPY_ARRAY_C_CONTIGUOUS | \
926
+ NPY_ARRAY_ALIGNED)
927
+ #define NPY_ARRAY_FARRAY (NPY_ARRAY_F_CONTIGUOUS | \
928
+ NPY_ARRAY_BEHAVED)
929
+ #define NPY_ARRAY_FARRAY_RO (NPY_ARRAY_F_CONTIGUOUS | \
930
+ NPY_ARRAY_ALIGNED)
931
+ #define NPY_ARRAY_DEFAULT (NPY_ARRAY_CARRAY)
932
+ #define NPY_ARRAY_IN_ARRAY (NPY_ARRAY_CARRAY_RO)
933
+ #define NPY_ARRAY_OUT_ARRAY (NPY_ARRAY_CARRAY)
934
+ #define NPY_ARRAY_INOUT_ARRAY (NPY_ARRAY_CARRAY)
935
+ #define NPY_ARRAY_INOUT_ARRAY2 (NPY_ARRAY_CARRAY | \
936
+ NPY_ARRAY_WRITEBACKIFCOPY)
937
+ #define NPY_ARRAY_IN_FARRAY (NPY_ARRAY_FARRAY_RO)
938
+ #define NPY_ARRAY_OUT_FARRAY (NPY_ARRAY_FARRAY)
939
+ #define NPY_ARRAY_INOUT_FARRAY (NPY_ARRAY_FARRAY)
940
+ #define NPY_ARRAY_INOUT_FARRAY2 (NPY_ARRAY_FARRAY | \
941
+ NPY_ARRAY_WRITEBACKIFCOPY)
942
+
943
+ #define NPY_ARRAY_UPDATE_ALL (NPY_ARRAY_C_CONTIGUOUS | \
944
+ NPY_ARRAY_F_CONTIGUOUS | \
945
+ NPY_ARRAY_ALIGNED)
946
+
947
+ /* This flag is for the array interface, not PyArrayObject */
948
+ #define NPY_ARR_HAS_DESCR 0x0800
949
+
950
+
951
+
952
+
953
+ /*
954
+ * Size of internal buffers used for alignment Make BUFSIZE a multiple
955
+ * of sizeof(npy_cdouble) -- usually 16 so that ufunc buffers are aligned
956
+ */
957
+ #define NPY_MIN_BUFSIZE ((int)sizeof(npy_cdouble))
958
+ #define NPY_MAX_BUFSIZE (((int)sizeof(npy_cdouble))*1000000)
959
+ #define NPY_BUFSIZE 8192
960
+ /* buffer stress test size: */
961
+ /*#define NPY_BUFSIZE 17*/
962
+
963
+ #define PyArray_MAX(a,b) (((a)>(b))?(a):(b))
964
+ #define PyArray_MIN(a,b) (((a)<(b))?(a):(b))
965
+ #define PyArray_CLT(p,q) ((((p).real==(q).real) ? ((p).imag < (q).imag) : \
966
+ ((p).real < (q).real)))
967
+ #define PyArray_CGT(p,q) ((((p).real==(q).real) ? ((p).imag > (q).imag) : \
968
+ ((p).real > (q).real)))
969
+ #define PyArray_CLE(p,q) ((((p).real==(q).real) ? ((p).imag <= (q).imag) : \
970
+ ((p).real <= (q).real)))
971
+ #define PyArray_CGE(p,q) ((((p).real==(q).real) ? ((p).imag >= (q).imag) : \
972
+ ((p).real >= (q).real)))
973
+ #define PyArray_CEQ(p,q) (((p).real==(q).real) && ((p).imag == (q).imag))
974
+ #define PyArray_CNE(p,q) (((p).real!=(q).real) || ((p).imag != (q).imag))
975
+
976
+ /*
977
+ * C API: consists of Macros and functions. The MACROS are defined
978
+ * here.
979
+ */
980
+
981
+
982
+ #define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS((m), NPY_ARRAY_C_CONTIGUOUS)
983
+ #define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS((m), NPY_ARRAY_WRITEABLE)
984
+ #define PyArray_ISALIGNED(m) PyArray_CHKFLAGS((m), NPY_ARRAY_ALIGNED)
985
+
986
+ #define PyArray_IS_C_CONTIGUOUS(m) PyArray_CHKFLAGS((m), NPY_ARRAY_C_CONTIGUOUS)
987
+ #define PyArray_IS_F_CONTIGUOUS(m) PyArray_CHKFLAGS((m), NPY_ARRAY_F_CONTIGUOUS)
988
+
989
+ /* the variable is used in some places, so always define it */
990
+ #define NPY_BEGIN_THREADS_DEF PyThreadState *_save=NULL;
991
+ #if NPY_ALLOW_THREADS
992
+ #define NPY_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
993
+ #define NPY_END_ALLOW_THREADS Py_END_ALLOW_THREADS
994
+ #define NPY_BEGIN_THREADS do {_save = PyEval_SaveThread();} while (0);
995
+ #define NPY_END_THREADS do { if (_save) \
996
+ { PyEval_RestoreThread(_save); _save = NULL;} } while (0);
997
+ #define NPY_BEGIN_THREADS_THRESHOLDED(loop_size) do { if ((loop_size) > 500) \
998
+ { _save = PyEval_SaveThread();} } while (0);
999
+
1000
+ #define NPY_BEGIN_THREADS_DESCR(dtype) \
1001
+ do {if (!(PyDataType_FLAGCHK((dtype), NPY_NEEDS_PYAPI))) \
1002
+ NPY_BEGIN_THREADS;} while (0);
1003
+
1004
+ #define NPY_END_THREADS_DESCR(dtype) \
1005
+ do {if (!(PyDataType_FLAGCHK((dtype), NPY_NEEDS_PYAPI))) \
1006
+ NPY_END_THREADS; } while (0);
1007
+
1008
+ #define NPY_ALLOW_C_API_DEF PyGILState_STATE __save__;
1009
+ #define NPY_ALLOW_C_API do {__save__ = PyGILState_Ensure();} while (0);
1010
+ #define NPY_DISABLE_C_API do {PyGILState_Release(__save__);} while (0);
1011
+ #else
1012
+ #define NPY_BEGIN_ALLOW_THREADS
1013
+ #define NPY_END_ALLOW_THREADS
1014
+ #define NPY_BEGIN_THREADS
1015
+ #define NPY_END_THREADS
1016
+ #define NPY_BEGIN_THREADS_THRESHOLDED(loop_size)
1017
+ #define NPY_BEGIN_THREADS_DESCR(dtype)
1018
+ #define NPY_END_THREADS_DESCR(dtype)
1019
+ #define NPY_ALLOW_C_API_DEF
1020
+ #define NPY_ALLOW_C_API
1021
+ #define NPY_DISABLE_C_API
1022
+ #endif
1023
+
1024
+ /**********************************
1025
+ * The nditer object, added in 1.6
1026
+ **********************************/
1027
+
1028
+ /* The actual structure of the iterator is an internal detail */
1029
+ typedef struct NpyIter_InternalOnly NpyIter;
1030
+
1031
+ /* Iterator function pointers that may be specialized */
1032
+ typedef int (NpyIter_IterNextFunc)(NpyIter *iter);
1033
+ typedef void (NpyIter_GetMultiIndexFunc)(NpyIter *iter,
1034
+ npy_intp *outcoords);
1035
+
1036
+ /*** Global flags that may be passed to the iterator constructors ***/
1037
+
1038
+ /* Track an index representing C order */
1039
+ #define NPY_ITER_C_INDEX 0x00000001
1040
+ /* Track an index representing Fortran order */
1041
+ #define NPY_ITER_F_INDEX 0x00000002
1042
+ /* Track a multi-index */
1043
+ #define NPY_ITER_MULTI_INDEX 0x00000004
1044
+ /* User code external to the iterator does the 1-dimensional innermost loop */
1045
+ #define NPY_ITER_EXTERNAL_LOOP 0x00000008
1046
+ /* Convert all the operands to a common data type */
1047
+ #define NPY_ITER_COMMON_DTYPE 0x00000010
1048
+ /* Operands may hold references, requiring API access during iteration */
1049
+ #define NPY_ITER_REFS_OK 0x00000020
1050
+ /* Zero-sized operands should be permitted, iteration checks IterSize for 0 */
1051
+ #define NPY_ITER_ZEROSIZE_OK 0x00000040
1052
+ /* Permits reductions (size-0 stride with dimension size > 1) */
1053
+ #define NPY_ITER_REDUCE_OK 0x00000080
1054
+ /* Enables sub-range iteration */
1055
+ #define NPY_ITER_RANGED 0x00000100
1056
+ /* Enables buffering */
1057
+ #define NPY_ITER_BUFFERED 0x00000200
1058
+ /* When buffering is enabled, grows the inner loop if possible */
1059
+ #define NPY_ITER_GROWINNER 0x00000400
1060
+ /* Delay allocation of buffers until first Reset* call */
1061
+ #define NPY_ITER_DELAY_BUFALLOC 0x00000800
1062
+ /* When NPY_KEEPORDER is specified, disable reversing negative-stride axes */
1063
+ #define NPY_ITER_DONT_NEGATE_STRIDES 0x00001000
1064
+ /*
1065
+ * If output operands overlap with other operands (based on heuristics that
1066
+ * has false positives but no false negatives), make temporary copies to
1067
+ * eliminate overlap.
1068
+ */
1069
+ #define NPY_ITER_COPY_IF_OVERLAP 0x00002000
1070
+
1071
+ /*** Per-operand flags that may be passed to the iterator constructors ***/
1072
+
1073
+ /* The operand will be read from and written to */
1074
+ #define NPY_ITER_READWRITE 0x00010000
1075
+ /* The operand will only be read from */
1076
+ #define NPY_ITER_READONLY 0x00020000
1077
+ /* The operand will only be written to */
1078
+ #define NPY_ITER_WRITEONLY 0x00040000
1079
+ /* The operand's data must be in native byte order */
1080
+ #define NPY_ITER_NBO 0x00080000
1081
+ /* The operand's data must be aligned */
1082
+ #define NPY_ITER_ALIGNED 0x00100000
1083
+ /* The operand's data must be contiguous (within the inner loop) */
1084
+ #define NPY_ITER_CONTIG 0x00200000
1085
+ /* The operand may be copied to satisfy requirements */
1086
+ #define NPY_ITER_COPY 0x00400000
1087
+ /* The operand may be copied with WRITEBACKIFCOPY to satisfy requirements */
1088
+ #define NPY_ITER_UPDATEIFCOPY 0x00800000
1089
+ /* Allocate the operand if it is NULL */
1090
+ #define NPY_ITER_ALLOCATE 0x01000000
1091
+ /* If an operand is allocated, don't use any subtype */
1092
+ #define NPY_ITER_NO_SUBTYPE 0x02000000
1093
+ /* This is a virtual array slot, operand is NULL but temporary data is there */
1094
+ #define NPY_ITER_VIRTUAL 0x04000000
1095
+ /* Require that the dimension match the iterator dimensions exactly */
1096
+ #define NPY_ITER_NO_BROADCAST 0x08000000
1097
+ /* A mask is being used on this array, affects buffer -> array copy */
1098
+ #define NPY_ITER_WRITEMASKED 0x10000000
1099
+ /* This array is the mask for all WRITEMASKED operands */
1100
+ #define NPY_ITER_ARRAYMASK 0x20000000
1101
+ /* Assume iterator order data access for COPY_IF_OVERLAP */
1102
+ #define NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE 0x40000000
1103
+
1104
+ #define NPY_ITER_GLOBAL_FLAGS 0x0000ffff
1105
+ #define NPY_ITER_PER_OP_FLAGS 0xffff0000
1106
+
1107
+
1108
+ /*****************************
1109
+ * Basic iterator object
1110
+ *****************************/
1111
+
1112
+ /* FWD declaration */
1113
+ typedef struct PyArrayIterObject_tag PyArrayIterObject;
1114
+
1115
+ /*
1116
+ * type of the function which translates a set of coordinates to a
1117
+ * pointer to the data
1118
+ */
1119
+ typedef char* (*npy_iter_get_dataptr_t)(
1120
+ PyArrayIterObject* iter, const npy_intp*);
1121
+
1122
+ struct PyArrayIterObject_tag {
1123
+ PyObject_HEAD
1124
+ int nd_m1; /* number of dimensions - 1 */
1125
+ npy_intp index, size;
1126
+ npy_intp coordinates[NPY_MAXDIMS];/* N-dimensional loop */
1127
+ npy_intp dims_m1[NPY_MAXDIMS]; /* ao->dimensions - 1 */
1128
+ npy_intp strides[NPY_MAXDIMS]; /* ao->strides or fake */
1129
+ npy_intp backstrides[NPY_MAXDIMS];/* how far to jump back */
1130
+ npy_intp factors[NPY_MAXDIMS]; /* shape factors */
1131
+ PyArrayObject *ao;
1132
+ char *dataptr; /* pointer to current item*/
1133
+ npy_bool contiguous;
1134
+
1135
+ npy_intp bounds[NPY_MAXDIMS][2];
1136
+ npy_intp limits[NPY_MAXDIMS][2];
1137
+ npy_intp limits_sizes[NPY_MAXDIMS];
1138
+ npy_iter_get_dataptr_t translate;
1139
+ } ;
1140
+
1141
+
1142
+ /* Iterator API */
1143
+ #define PyArrayIter_Check(op) PyObject_TypeCheck((op), &PyArrayIter_Type)
1144
+
1145
+ #define _PyAIT(it) ((PyArrayIterObject *)(it))
1146
+ #define PyArray_ITER_RESET(it) do { \
1147
+ _PyAIT(it)->index = 0; \
1148
+ _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
1149
+ memset(_PyAIT(it)->coordinates, 0, \
1150
+ (_PyAIT(it)->nd_m1+1)*sizeof(npy_intp)); \
1151
+ } while (0)
1152
+
1153
+ #define _PyArray_ITER_NEXT1(it) do { \
1154
+ (it)->dataptr += _PyAIT(it)->strides[0]; \
1155
+ (it)->coordinates[0]++; \
1156
+ } while (0)
1157
+
1158
+ #define _PyArray_ITER_NEXT2(it) do { \
1159
+ if ((it)->coordinates[1] < (it)->dims_m1[1]) { \
1160
+ (it)->coordinates[1]++; \
1161
+ (it)->dataptr += (it)->strides[1]; \
1162
+ } \
1163
+ else { \
1164
+ (it)->coordinates[1] = 0; \
1165
+ (it)->coordinates[0]++; \
1166
+ (it)->dataptr += (it)->strides[0] - \
1167
+ (it)->backstrides[1]; \
1168
+ } \
1169
+ } while (0)
1170
+
1171
+ #define PyArray_ITER_NEXT(it) do { \
1172
+ _PyAIT(it)->index++; \
1173
+ if (_PyAIT(it)->nd_m1 == 0) { \
1174
+ _PyArray_ITER_NEXT1(_PyAIT(it)); \
1175
+ } \
1176
+ else if (_PyAIT(it)->contiguous) \
1177
+ _PyAIT(it)->dataptr += PyArray_DESCR(_PyAIT(it)->ao)->elsize; \
1178
+ else if (_PyAIT(it)->nd_m1 == 1) { \
1179
+ _PyArray_ITER_NEXT2(_PyAIT(it)); \
1180
+ } \
1181
+ else { \
1182
+ int __npy_i; \
1183
+ for (__npy_i=_PyAIT(it)->nd_m1; __npy_i >= 0; __npy_i--) { \
1184
+ if (_PyAIT(it)->coordinates[__npy_i] < \
1185
+ _PyAIT(it)->dims_m1[__npy_i]) { \
1186
+ _PyAIT(it)->coordinates[__npy_i]++; \
1187
+ _PyAIT(it)->dataptr += \
1188
+ _PyAIT(it)->strides[__npy_i]; \
1189
+ break; \
1190
+ } \
1191
+ else { \
1192
+ _PyAIT(it)->coordinates[__npy_i] = 0; \
1193
+ _PyAIT(it)->dataptr -= \
1194
+ _PyAIT(it)->backstrides[__npy_i]; \
1195
+ } \
1196
+ } \
1197
+ } \
1198
+ } while (0)
1199
+
1200
+ #define PyArray_ITER_GOTO(it, destination) do { \
1201
+ int __npy_i; \
1202
+ _PyAIT(it)->index = 0; \
1203
+ _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
1204
+ for (__npy_i = _PyAIT(it)->nd_m1; __npy_i>=0; __npy_i--) { \
1205
+ if (destination[__npy_i] < 0) { \
1206
+ destination[__npy_i] += \
1207
+ _PyAIT(it)->dims_m1[__npy_i]+1; \
1208
+ } \
1209
+ _PyAIT(it)->dataptr += destination[__npy_i] * \
1210
+ _PyAIT(it)->strides[__npy_i]; \
1211
+ _PyAIT(it)->coordinates[__npy_i] = \
1212
+ destination[__npy_i]; \
1213
+ _PyAIT(it)->index += destination[__npy_i] * \
1214
+ ( __npy_i==_PyAIT(it)->nd_m1 ? 1 : \
1215
+ _PyAIT(it)->dims_m1[__npy_i+1]+1) ; \
1216
+ } \
1217
+ } while (0)
1218
+
1219
+ #define PyArray_ITER_GOTO1D(it, ind) do { \
1220
+ int __npy_i; \
1221
+ npy_intp __npy_ind = (npy_intp)(ind); \
1222
+ if (__npy_ind < 0) __npy_ind += _PyAIT(it)->size; \
1223
+ _PyAIT(it)->index = __npy_ind; \
1224
+ if (_PyAIT(it)->nd_m1 == 0) { \
1225
+ _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao) + \
1226
+ __npy_ind * _PyAIT(it)->strides[0]; \
1227
+ } \
1228
+ else if (_PyAIT(it)->contiguous) \
1229
+ _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao) + \
1230
+ __npy_ind * PyArray_DESCR(_PyAIT(it)->ao)->elsize; \
1231
+ else { \
1232
+ _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
1233
+ for (__npy_i = 0; __npy_i<=_PyAIT(it)->nd_m1; \
1234
+ __npy_i++) { \
1235
+ _PyAIT(it)->coordinates[__npy_i] = \
1236
+ (__npy_ind / _PyAIT(it)->factors[__npy_i]); \
1237
+ _PyAIT(it)->dataptr += \
1238
+ (__npy_ind / _PyAIT(it)->factors[__npy_i]) \
1239
+ * _PyAIT(it)->strides[__npy_i]; \
1240
+ __npy_ind %= _PyAIT(it)->factors[__npy_i]; \
1241
+ } \
1242
+ } \
1243
+ } while (0)
1244
+
1245
+ #define PyArray_ITER_DATA(it) ((void *)(_PyAIT(it)->dataptr))
1246
+
1247
+ #define PyArray_ITER_NOTDONE(it) (_PyAIT(it)->index < _PyAIT(it)->size)
1248
+
1249
+
1250
+ /*
1251
+ * Any object passed to PyArray_Broadcast must be binary compatible
1252
+ * with this structure.
1253
+ */
1254
+
1255
+ typedef struct {
1256
+ PyObject_HEAD
1257
+ int numiter; /* number of iters */
1258
+ npy_intp size; /* broadcasted size */
1259
+ npy_intp index; /* current index */
1260
+ int nd; /* number of dims */
1261
+ npy_intp dimensions[NPY_MAXDIMS]; /* dimensions */
1262
+ PyArrayIterObject *iters[NPY_MAXARGS]; /* iterators */
1263
+ } PyArrayMultiIterObject;
1264
+
1265
+ #define _PyMIT(m) ((PyArrayMultiIterObject *)(m))
1266
+ #define PyArray_MultiIter_RESET(multi) do { \
1267
+ int __npy_mi; \
1268
+ _PyMIT(multi)->index = 0; \
1269
+ for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \
1270
+ PyArray_ITER_RESET(_PyMIT(multi)->iters[__npy_mi]); \
1271
+ } \
1272
+ } while (0)
1273
+
1274
+ #define PyArray_MultiIter_NEXT(multi) do { \
1275
+ int __npy_mi; \
1276
+ _PyMIT(multi)->index++; \
1277
+ for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \
1278
+ PyArray_ITER_NEXT(_PyMIT(multi)->iters[__npy_mi]); \
1279
+ } \
1280
+ } while (0)
1281
+
1282
+ #define PyArray_MultiIter_GOTO(multi, dest) do { \
1283
+ int __npy_mi; \
1284
+ for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \
1285
+ PyArray_ITER_GOTO(_PyMIT(multi)->iters[__npy_mi], dest); \
1286
+ } \
1287
+ _PyMIT(multi)->index = _PyMIT(multi)->iters[0]->index; \
1288
+ } while (0)
1289
+
1290
+ #define PyArray_MultiIter_GOTO1D(multi, ind) do { \
1291
+ int __npy_mi; \
1292
+ for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \
1293
+ PyArray_ITER_GOTO1D(_PyMIT(multi)->iters[__npy_mi], ind); \
1294
+ } \
1295
+ _PyMIT(multi)->index = _PyMIT(multi)->iters[0]->index; \
1296
+ } while (0)
1297
+
1298
+ #define PyArray_MultiIter_DATA(multi, i) \
1299
+ ((void *)(_PyMIT(multi)->iters[i]->dataptr))
1300
+
1301
+ #define PyArray_MultiIter_NEXTi(multi, i) \
1302
+ PyArray_ITER_NEXT(_PyMIT(multi)->iters[i])
1303
+
1304
+ #define PyArray_MultiIter_NOTDONE(multi) \
1305
+ (_PyMIT(multi)->index < _PyMIT(multi)->size)
1306
+
1307
+ /*
1308
+ * Store the information needed for fancy-indexing over an array. The
1309
+ * fields are slightly unordered to keep consec, dataptr and subspace
1310
+ * where they were originally.
1311
+ */
1312
+ typedef struct {
1313
+ PyObject_HEAD
1314
+ /*
1315
+ * Multi-iterator portion --- needs to be present in this
1316
+ * order to work with PyArray_Broadcast
1317
+ */
1318
+
1319
+ int numiter; /* number of index-array
1320
+ iterators */
1321
+ npy_intp size; /* size of broadcasted
1322
+ result */
1323
+ npy_intp index; /* current index */
1324
+ int nd; /* number of dims */
1325
+ npy_intp dimensions[NPY_MAXDIMS]; /* dimensions */
1326
+ NpyIter *outer; /* index objects
1327
+ iterator */
1328
+ void *unused[NPY_MAXDIMS - 2];
1329
+ PyArrayObject *array;
1330
+ /* Flat iterator for the indexed array. For compatibility solely. */
1331
+ PyArrayIterObject *ait;
1332
+
1333
+ /*
1334
+ * Subspace array. For binary compatibility (was an iterator,
1335
+ * but only the check for NULL should be used).
1336
+ */
1337
+ PyArrayObject *subspace;
1338
+
1339
+ /*
1340
+ * if subspace iteration, then this is the array of axes in
1341
+ * the underlying array represented by the index objects
1342
+ */
1343
+ int iteraxes[NPY_MAXDIMS];
1344
+ npy_intp fancy_strides[NPY_MAXDIMS];
1345
+
1346
+ /* pointer when all fancy indices are 0 */
1347
+ char *baseoffset;
1348
+
1349
+ /*
1350
+ * after binding consec denotes at which axis the fancy axes
1351
+ * are inserted.
1352
+ */
1353
+ int consec;
1354
+ char *dataptr;
1355
+
1356
+ int nd_fancy;
1357
+ npy_intp fancy_dims[NPY_MAXDIMS];
1358
+
1359
+ /*
1360
+ * Whether the iterator (any of the iterators) requires API. This is
1361
+ * unused by NumPy itself; ArrayMethod flags are more precise.
1362
+ */
1363
+ int needs_api;
1364
+
1365
+ /*
1366
+ * Extra op information.
1367
+ */
1368
+ PyArrayObject *extra_op;
1369
+ PyArray_Descr *extra_op_dtype; /* desired dtype */
1370
+ npy_uint32 *extra_op_flags; /* Iterator flags */
1371
+
1372
+ NpyIter *extra_op_iter;
1373
+ NpyIter_IterNextFunc *extra_op_next;
1374
+ char **extra_op_ptrs;
1375
+
1376
+ /*
1377
+ * Information about the iteration state.
1378
+ */
1379
+ NpyIter_IterNextFunc *outer_next;
1380
+ char **outer_ptrs;
1381
+ npy_intp *outer_strides;
1382
+
1383
+ /*
1384
+ * Information about the subspace iterator.
1385
+ */
1386
+ NpyIter *subspace_iter;
1387
+ NpyIter_IterNextFunc *subspace_next;
1388
+ char **subspace_ptrs;
1389
+ npy_intp *subspace_strides;
1390
+
1391
+ /* Count for the external loop (which ever it is) for API iteration */
1392
+ npy_intp iter_count;
1393
+
1394
+ } PyArrayMapIterObject;
1395
+
1396
+ enum {
1397
+ NPY_NEIGHBORHOOD_ITER_ZERO_PADDING,
1398
+ NPY_NEIGHBORHOOD_ITER_ONE_PADDING,
1399
+ NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING,
1400
+ NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING,
1401
+ NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING
1402
+ };
1403
+
1404
+ typedef struct {
1405
+ PyObject_HEAD
1406
+
1407
+ /*
1408
+ * PyArrayIterObject part: keep this in this exact order
1409
+ */
1410
+ int nd_m1; /* number of dimensions - 1 */
1411
+ npy_intp index, size;
1412
+ npy_intp coordinates[NPY_MAXDIMS];/* N-dimensional loop */
1413
+ npy_intp dims_m1[NPY_MAXDIMS]; /* ao->dimensions - 1 */
1414
+ npy_intp strides[NPY_MAXDIMS]; /* ao->strides or fake */
1415
+ npy_intp backstrides[NPY_MAXDIMS];/* how far to jump back */
1416
+ npy_intp factors[NPY_MAXDIMS]; /* shape factors */
1417
+ PyArrayObject *ao;
1418
+ char *dataptr; /* pointer to current item*/
1419
+ npy_bool contiguous;
1420
+
1421
+ npy_intp bounds[NPY_MAXDIMS][2];
1422
+ npy_intp limits[NPY_MAXDIMS][2];
1423
+ npy_intp limits_sizes[NPY_MAXDIMS];
1424
+ npy_iter_get_dataptr_t translate;
1425
+
1426
+ /*
1427
+ * New members
1428
+ */
1429
+ npy_intp nd;
1430
+
1431
+ /* Dimensions is the dimension of the array */
1432
+ npy_intp dimensions[NPY_MAXDIMS];
1433
+
1434
+ /*
1435
+ * Neighborhood points coordinates are computed relatively to the
1436
+ * point pointed by _internal_iter
1437
+ */
1438
+ PyArrayIterObject* _internal_iter;
1439
+ /*
1440
+ * To keep a reference to the representation of the constant value
1441
+ * for constant padding
1442
+ */
1443
+ char* constant;
1444
+
1445
+ int mode;
1446
+ } PyArrayNeighborhoodIterObject;
1447
+
1448
+ /*
1449
+ * Neighborhood iterator API
1450
+ */
1451
+
1452
+ /* General: those work for any mode */
1453
+ static inline int
1454
+ PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter);
1455
+ static inline int
1456
+ PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter);
1457
+ #if 0
1458
+ static inline int
1459
+ PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter);
1460
+ #endif
1461
+
1462
+ /*
1463
+ * Include inline implementations - functions defined there are not
1464
+ * considered public API
1465
+ */
1466
+ #define NUMPY_CORE_INCLUDE_NUMPY__NEIGHBORHOOD_IMP_H_
1467
+ #include "_neighborhood_iterator_imp.h"
1468
+ #undef NUMPY_CORE_INCLUDE_NUMPY__NEIGHBORHOOD_IMP_H_
1469
+
1470
+
1471
+
1472
+ /* The default array type */
1473
+ #define NPY_DEFAULT_TYPE NPY_DOUBLE
1474
+
1475
+ /*
1476
+ * All sorts of useful ways to look into a PyArrayObject. It is recommended
1477
+ * to use PyArrayObject * objects instead of always casting from PyObject *,
1478
+ * for improved type checking.
1479
+ *
1480
+ * In many cases here the macro versions of the accessors are deprecated,
1481
+ * but can't be immediately changed to inline functions because the
1482
+ * preexisting macros accept PyObject * and do automatic casts. Inline
1483
+ * functions accepting PyArrayObject * provides for some compile-time
1484
+ * checking of correctness when working with these objects in C.
1485
+ */
1486
+
1487
+ #define PyArray_ISONESEGMENT(m) (PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS) || \
1488
+ PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS))
1489
+
1490
+ #define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) && \
1491
+ (!PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS)))
1492
+
1493
+ #define PyArray_FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) ? \
1494
+ NPY_ARRAY_F_CONTIGUOUS : 0))
1495
+
1496
+ #if (defined(NPY_NO_DEPRECATED_API) && (NPY_1_7_API_VERSION <= NPY_NO_DEPRECATED_API))
1497
+ /*
1498
+ * Changing access macros into functions, to allow for future hiding
1499
+ * of the internal memory layout. This later hiding will allow the 2.x series
1500
+ * to change the internal representation of arrays without affecting
1501
+ * ABI compatibility.
1502
+ */
1503
+
1504
+ static inline int
1505
+ PyArray_NDIM(const PyArrayObject *arr)
1506
+ {
1507
+ return ((PyArrayObject_fields *)arr)->nd;
1508
+ }
1509
+
1510
+ static inline void *
1511
+ PyArray_DATA(PyArrayObject *arr)
1512
+ {
1513
+ return ((PyArrayObject_fields *)arr)->data;
1514
+ }
1515
+
1516
+ static inline char *
1517
+ PyArray_BYTES(PyArrayObject *arr)
1518
+ {
1519
+ return ((PyArrayObject_fields *)arr)->data;
1520
+ }
1521
+
1522
+ static inline npy_intp *
1523
+ PyArray_DIMS(PyArrayObject *arr)
1524
+ {
1525
+ return ((PyArrayObject_fields *)arr)->dimensions;
1526
+ }
1527
+
1528
+ static inline npy_intp *
1529
+ PyArray_STRIDES(PyArrayObject *arr)
1530
+ {
1531
+ return ((PyArrayObject_fields *)arr)->strides;
1532
+ }
1533
+
1534
+ static inline npy_intp
1535
+ PyArray_DIM(const PyArrayObject *arr, int idim)
1536
+ {
1537
+ return ((PyArrayObject_fields *)arr)->dimensions[idim];
1538
+ }
1539
+
1540
+ static inline npy_intp
1541
+ PyArray_STRIDE(const PyArrayObject *arr, int istride)
1542
+ {
1543
+ return ((PyArrayObject_fields *)arr)->strides[istride];
1544
+ }
1545
+
1546
+ static inline NPY_RETURNS_BORROWED_REF PyObject *
1547
+ PyArray_BASE(PyArrayObject *arr)
1548
+ {
1549
+ return ((PyArrayObject_fields *)arr)->base;
1550
+ }
1551
+
1552
+ static inline NPY_RETURNS_BORROWED_REF PyArray_Descr *
1553
+ PyArray_DESCR(PyArrayObject *arr)
1554
+ {
1555
+ return ((PyArrayObject_fields *)arr)->descr;
1556
+ }
1557
+
1558
+ static inline int
1559
+ PyArray_FLAGS(const PyArrayObject *arr)
1560
+ {
1561
+ return ((PyArrayObject_fields *)arr)->flags;
1562
+ }
1563
+
1564
+ static inline npy_intp
1565
+ PyArray_ITEMSIZE(const PyArrayObject *arr)
1566
+ {
1567
+ return ((PyArrayObject_fields *)arr)->descr->elsize;
1568
+ }
1569
+
1570
+ static inline int
1571
+ PyArray_TYPE(const PyArrayObject *arr)
1572
+ {
1573
+ return ((PyArrayObject_fields *)arr)->descr->type_num;
1574
+ }
1575
+
1576
+ static inline int
1577
+ PyArray_CHKFLAGS(const PyArrayObject *arr, int flags)
1578
+ {
1579
+ return (PyArray_FLAGS(arr) & flags) == flags;
1580
+ }
1581
+
1582
+ static inline PyObject *
1583
+ PyArray_GETITEM(const PyArrayObject *arr, const char *itemptr)
1584
+ {
1585
+ return ((PyArrayObject_fields *)arr)->descr->f->getitem(
1586
+ (void *)itemptr, (PyArrayObject *)arr);
1587
+ }
1588
+
1589
+ /*
1590
+ * SETITEM should only be used if it is known that the value is a scalar
1591
+ * and of a type understood by the arrays dtype.
1592
+ * Use `PyArray_Pack` if the value may be of a different dtype.
1593
+ */
1594
+ static inline int
1595
+ PyArray_SETITEM(PyArrayObject *arr, char *itemptr, PyObject *v)
1596
+ {
1597
+ return ((PyArrayObject_fields *)arr)->descr->f->setitem(v, itemptr, arr);
1598
+ }
1599
+
1600
+ #else
1601
+
1602
+ /* These macros are deprecated as of NumPy 1.7. */
1603
+ #define PyArray_NDIM(obj) (((PyArrayObject_fields *)(obj))->nd)
1604
+ #define PyArray_BYTES(obj) (((PyArrayObject_fields *)(obj))->data)
1605
+ #define PyArray_DATA(obj) ((void *)((PyArrayObject_fields *)(obj))->data)
1606
+ #define PyArray_DIMS(obj) (((PyArrayObject_fields *)(obj))->dimensions)
1607
+ #define PyArray_STRIDES(obj) (((PyArrayObject_fields *)(obj))->strides)
1608
+ #define PyArray_DIM(obj,n) (PyArray_DIMS(obj)[n])
1609
+ #define PyArray_STRIDE(obj,n) (PyArray_STRIDES(obj)[n])
1610
+ #define PyArray_BASE(obj) (((PyArrayObject_fields *)(obj))->base)
1611
+ #define PyArray_DESCR(obj) (((PyArrayObject_fields *)(obj))->descr)
1612
+ #define PyArray_FLAGS(obj) (((PyArrayObject_fields *)(obj))->flags)
1613
+ #define PyArray_CHKFLAGS(m, FLAGS) \
1614
+ ((((PyArrayObject_fields *)(m))->flags & (FLAGS)) == (FLAGS))
1615
+ #define PyArray_ITEMSIZE(obj) \
1616
+ (((PyArrayObject_fields *)(obj))->descr->elsize)
1617
+ #define PyArray_TYPE(obj) \
1618
+ (((PyArrayObject_fields *)(obj))->descr->type_num)
1619
+ #define PyArray_GETITEM(obj,itemptr) \
1620
+ PyArray_DESCR(obj)->f->getitem((char *)(itemptr), \
1621
+ (PyArrayObject *)(obj))
1622
+
1623
+ #define PyArray_SETITEM(obj,itemptr,v) \
1624
+ PyArray_DESCR(obj)->f->setitem((PyObject *)(v), \
1625
+ (char *)(itemptr), \
1626
+ (PyArrayObject *)(obj))
1627
+ #endif
1628
+
1629
+ static inline PyArray_Descr *
1630
+ PyArray_DTYPE(PyArrayObject *arr)
1631
+ {
1632
+ return ((PyArrayObject_fields *)arr)->descr;
1633
+ }
1634
+
1635
+ static inline npy_intp *
1636
+ PyArray_SHAPE(PyArrayObject *arr)
1637
+ {
1638
+ return ((PyArrayObject_fields *)arr)->dimensions;
1639
+ }
1640
+
1641
+ /*
1642
+ * Enables the specified array flags. Does no checking,
1643
+ * assumes you know what you're doing.
1644
+ */
1645
+ static inline void
1646
+ PyArray_ENABLEFLAGS(PyArrayObject *arr, int flags)
1647
+ {
1648
+ ((PyArrayObject_fields *)arr)->flags |= flags;
1649
+ }
1650
+
1651
+ /*
1652
+ * Clears the specified array flags. Does no checking,
1653
+ * assumes you know what you're doing.
1654
+ */
1655
+ static inline void
1656
+ PyArray_CLEARFLAGS(PyArrayObject *arr, int flags)
1657
+ {
1658
+ ((PyArrayObject_fields *)arr)->flags &= ~flags;
1659
+ }
1660
+
1661
+ #if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
1662
+ static inline NPY_RETURNS_BORROWED_REF PyObject *
1663
+ PyArray_HANDLER(PyArrayObject *arr)
1664
+ {
1665
+ return ((PyArrayObject_fields *)arr)->mem_handler;
1666
+ }
1667
+ #endif
1668
+
1669
+ #define PyTypeNum_ISBOOL(type) ((type) == NPY_BOOL)
1670
+
1671
+ #define PyTypeNum_ISUNSIGNED(type) (((type) == NPY_UBYTE) || \
1672
+ ((type) == NPY_USHORT) || \
1673
+ ((type) == NPY_UINT) || \
1674
+ ((type) == NPY_ULONG) || \
1675
+ ((type) == NPY_ULONGLONG))
1676
+
1677
+ #define PyTypeNum_ISSIGNED(type) (((type) == NPY_BYTE) || \
1678
+ ((type) == NPY_SHORT) || \
1679
+ ((type) == NPY_INT) || \
1680
+ ((type) == NPY_LONG) || \
1681
+ ((type) == NPY_LONGLONG))
1682
+
1683
+ #define PyTypeNum_ISINTEGER(type) (((type) >= NPY_BYTE) && \
1684
+ ((type) <= NPY_ULONGLONG))
1685
+
1686
+ #define PyTypeNum_ISFLOAT(type) ((((type) >= NPY_FLOAT) && \
1687
+ ((type) <= NPY_LONGDOUBLE)) || \
1688
+ ((type) == NPY_HALF))
1689
+
1690
+ #define PyTypeNum_ISNUMBER(type) (((type) <= NPY_CLONGDOUBLE) || \
1691
+ ((type) == NPY_HALF))
1692
+
1693
+ #define PyTypeNum_ISSTRING(type) (((type) == NPY_STRING) || \
1694
+ ((type) == NPY_UNICODE))
1695
+
1696
+ #define PyTypeNum_ISCOMPLEX(type) (((type) >= NPY_CFLOAT) && \
1697
+ ((type) <= NPY_CLONGDOUBLE))
1698
+
1699
+ #define PyTypeNum_ISPYTHON(type) (((type) == NPY_LONG) || \
1700
+ ((type) == NPY_DOUBLE) || \
1701
+ ((type) == NPY_CDOUBLE) || \
1702
+ ((type) == NPY_BOOL) || \
1703
+ ((type) == NPY_OBJECT ))
1704
+
1705
+ #define PyTypeNum_ISFLEXIBLE(type) (((type) >=NPY_STRING) && \
1706
+ ((type) <=NPY_VOID))
1707
+
1708
+ #define PyTypeNum_ISDATETIME(type) (((type) >=NPY_DATETIME) && \
1709
+ ((type) <=NPY_TIMEDELTA))
1710
+
1711
+ #define PyTypeNum_ISUSERDEF(type) (((type) >= NPY_USERDEF) && \
1712
+ ((type) < NPY_USERDEF+ \
1713
+ NPY_NUMUSERTYPES))
1714
+
1715
+ #define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \
1716
+ PyTypeNum_ISUSERDEF(type))
1717
+
1718
+ #define PyTypeNum_ISOBJECT(type) ((type) == NPY_OBJECT)
1719
+
1720
+
1721
+ #define PyDataType_ISBOOL(obj) PyTypeNum_ISBOOL(((PyArray_Descr*)(obj))->type_num)
1722
+ #define PyDataType_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(((PyArray_Descr*)(obj))->type_num)
1723
+ #define PyDataType_ISSIGNED(obj) PyTypeNum_ISSIGNED(((PyArray_Descr*)(obj))->type_num)
1724
+ #define PyDataType_ISINTEGER(obj) PyTypeNum_ISINTEGER(((PyArray_Descr*)(obj))->type_num )
1725
+ #define PyDataType_ISFLOAT(obj) PyTypeNum_ISFLOAT(((PyArray_Descr*)(obj))->type_num)
1726
+ #define PyDataType_ISNUMBER(obj) PyTypeNum_ISNUMBER(((PyArray_Descr*)(obj))->type_num)
1727
+ #define PyDataType_ISSTRING(obj) PyTypeNum_ISSTRING(((PyArray_Descr*)(obj))->type_num)
1728
+ #define PyDataType_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(((PyArray_Descr*)(obj))->type_num)
1729
+ #define PyDataType_ISPYTHON(obj) PyTypeNum_ISPYTHON(((PyArray_Descr*)(obj))->type_num)
1730
+ #define PyDataType_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(((PyArray_Descr*)(obj))->type_num)
1731
+ #define PyDataType_ISDATETIME(obj) PyTypeNum_ISDATETIME(((PyArray_Descr*)(obj))->type_num)
1732
+ #define PyDataType_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(((PyArray_Descr*)(obj))->type_num)
1733
+ #define PyDataType_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(((PyArray_Descr*)(obj))->type_num)
1734
+ #define PyDataType_ISOBJECT(obj) PyTypeNum_ISOBJECT(((PyArray_Descr*)(obj))->type_num)
1735
+ #define PyDataType_HASFIELDS(obj) (((PyArray_Descr *)(obj))->names != NULL)
1736
+ #define PyDataType_HASSUBARRAY(dtype) ((dtype)->subarray != NULL)
1737
+ #define PyDataType_ISUNSIZED(dtype) ((dtype)->elsize == 0 && \
1738
+ !PyDataType_HASFIELDS(dtype))
1739
+ #define PyDataType_MAKEUNSIZED(dtype) ((dtype)->elsize = 0)
1740
+
1741
+ #define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))
1742
+ #define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))
1743
+ #define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))
1744
+ #define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))
1745
+ #define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))
1746
+ #define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))
1747
+ #define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))
1748
+ #define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))
1749
+ #define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))
1750
+ #define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))
1751
+ #define PyArray_ISDATETIME(obj) PyTypeNum_ISDATETIME(PyArray_TYPE(obj))
1752
+ #define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))
1753
+ #define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))
1754
+ #define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))
1755
+ #define PyArray_HASFIELDS(obj) PyDataType_HASFIELDS(PyArray_DESCR(obj))
1756
+
1757
+ /*
1758
+ * FIXME: This should check for a flag on the data-type that
1759
+ * states whether or not it is variable length. Because the
1760
+ * ISFLEXIBLE check is hard-coded to the built-in data-types.
1761
+ */
1762
+ #define PyArray_ISVARIABLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))
1763
+
1764
+ #define PyArray_SAFEALIGNEDCOPY(obj) (PyArray_ISALIGNED(obj) && !PyArray_ISVARIABLE(obj))
1765
+
1766
+
1767
+ #define NPY_LITTLE '<'
1768
+ #define NPY_BIG '>'
1769
+ #define NPY_NATIVE '='
1770
+ #define NPY_SWAP 's'
1771
+ #define NPY_IGNORE '|'
1772
+
1773
+ #if NPY_BYTE_ORDER == NPY_BIG_ENDIAN
1774
+ #define NPY_NATBYTE NPY_BIG
1775
+ #define NPY_OPPBYTE NPY_LITTLE
1776
+ #else
1777
+ #define NPY_NATBYTE NPY_LITTLE
1778
+ #define NPY_OPPBYTE NPY_BIG
1779
+ #endif
1780
+
1781
+ #define PyArray_ISNBO(arg) ((arg) != NPY_OPPBYTE)
1782
+ #define PyArray_IsNativeByteOrder PyArray_ISNBO
1783
+ #define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)
1784
+ #define PyArray_ISBYTESWAPPED(m) (!PyArray_ISNOTSWAPPED(m))
1785
+
1786
+ #define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) && \
1787
+ PyArray_ISNOTSWAPPED(m))
1788
+
1789
+ #define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, NPY_ARRAY_CARRAY)
1790
+ #define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_CARRAY_RO)
1791
+ #define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, NPY_ARRAY_FARRAY)
1792
+ #define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_FARRAY_RO)
1793
+ #define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, NPY_ARRAY_BEHAVED)
1794
+ #define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_ALIGNED)
1795
+
1796
+
1797
+ #define PyDataType_ISNOTSWAPPED(d) PyArray_ISNBO(((PyArray_Descr *)(d))->byteorder)
1798
+ #define PyDataType_ISBYTESWAPPED(d) (!PyDataType_ISNOTSWAPPED(d))
1799
+
1800
+ /************************************************************
1801
+ * A struct used by PyArray_CreateSortedStridePerm, new in 1.7.
1802
+ ************************************************************/
1803
+
1804
+ typedef struct {
1805
+ npy_intp perm, stride;
1806
+ } npy_stride_sort_item;
1807
+
1808
+ /************************************************************
1809
+ * This is the form of the struct that's stored in the
1810
+ * PyCapsule returned by an array's __array_struct__ attribute. See
1811
+ * https://docs.scipy.org/doc/numpy/reference/arrays.interface.html for the full
1812
+ * documentation.
1813
+ ************************************************************/
1814
+ typedef struct {
1815
+ int two; /*
1816
+ * contains the integer 2 as a sanity
1817
+ * check
1818
+ */
1819
+
1820
+ int nd; /* number of dimensions */
1821
+
1822
+ char typekind; /*
1823
+ * kind in array --- character code of
1824
+ * typestr
1825
+ */
1826
+
1827
+ int itemsize; /* size of each element */
1828
+
1829
+ int flags; /*
1830
+ * how should be data interpreted. Valid
1831
+ * flags are CONTIGUOUS (1), F_CONTIGUOUS (2),
1832
+ * ALIGNED (0x100), NOTSWAPPED (0x200), and
1833
+ * WRITEABLE (0x400). ARR_HAS_DESCR (0x800)
1834
+ * states that arrdescr field is present in
1835
+ * structure
1836
+ */
1837
+
1838
+ npy_intp *shape; /*
1839
+ * A length-nd array of shape
1840
+ * information
1841
+ */
1842
+
1843
+ npy_intp *strides; /* A length-nd array of stride information */
1844
+
1845
+ void *data; /* A pointer to the first element of the array */
1846
+
1847
+ PyObject *descr; /*
1848
+ * A list of fields or NULL (ignored if flags
1849
+ * does not have ARR_HAS_DESCR flag set)
1850
+ */
1851
+ } PyArrayInterface;
1852
+
1853
+ /*
1854
+ * This is a function for hooking into the PyDataMem_NEW/FREE/RENEW functions.
1855
+ * See the documentation for PyDataMem_SetEventHook.
1856
+ */
1857
+ typedef void (PyDataMem_EventHookFunc)(void *inp, void *outp, size_t size,
1858
+ void *user_data);
1859
+
1860
+
1861
+ /*
1862
+ * PyArray_DTypeMeta related definitions.
1863
+ *
1864
+ * As of now, this API is preliminary and will be extended as necessary.
1865
+ */
1866
+ #if defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD
1867
+ /*
1868
+ * The Structures defined in this block are currently considered
1869
+ * private API and may change without warning!
1870
+ * Part of this (at least the size) is expected to be public API without
1871
+ * further modifications.
1872
+ */
1873
+ /* TODO: Make this definition public in the API, as soon as its settled */
1874
+ NPY_NO_EXPORT extern PyTypeObject PyArrayDTypeMeta_Type;
1875
+
1876
+ /*
1877
+ * While NumPy DTypes would not need to be heap types the plan is to
1878
+ * make DTypes available in Python at which point they will be heap types.
1879
+ * Since we also wish to add fields to the DType class, this looks like
1880
+ * a typical instance definition, but with PyHeapTypeObject instead of
1881
+ * only the PyObject_HEAD.
1882
+ * This must only be exposed very extremely careful consideration, since
1883
+ * it is a fairly complex construct which may be better to allow
1884
+ * refactoring of.
1885
+ */
1886
+ typedef struct {
1887
+ PyHeapTypeObject super;
1888
+
1889
+ /*
1890
+ * Most DTypes will have a singleton default instance, for the
1891
+ * parametric legacy DTypes (bytes, string, void, datetime) this
1892
+ * may be a pointer to the *prototype* instance?
1893
+ */
1894
+ PyArray_Descr *singleton;
1895
+ /* Copy of the legacy DTypes type number, usually invalid. */
1896
+ int type_num;
1897
+
1898
+ /* The type object of the scalar instances (may be NULL?) */
1899
+ PyTypeObject *scalar_type;
1900
+ /*
1901
+ * DType flags to signal legacy, parametric, or
1902
+ * abstract. But plenty of space for additional information/flags.
1903
+ */
1904
+ npy_uint64 flags;
1905
+
1906
+ /*
1907
+ * Use indirection in order to allow a fixed size for this struct.
1908
+ * A stable ABI size makes creating a static DType less painful
1909
+ * while also ensuring flexibility for all opaque API (with one
1910
+ * indirection due the pointer lookup).
1911
+ */
1912
+ void *dt_slots;
1913
+ void *reserved[3];
1914
+ } PyArray_DTypeMeta;
1915
+
1916
+ #endif /* NPY_INTERNAL_BUILD */
1917
+
1918
+
1919
+ /*
1920
+ * Use the keyword NPY_DEPRECATED_INCLUDES to ensure that the header files
1921
+ * npy_*_*_deprecated_api.h are only included from here and nowhere else.
1922
+ */
1923
+ #ifdef NPY_DEPRECATED_INCLUDES
1924
+ #error "Do not use the reserved keyword NPY_DEPRECATED_INCLUDES."
1925
+ #endif
1926
+ #define NPY_DEPRECATED_INCLUDES
1927
+ #if !defined(NPY_NO_DEPRECATED_API) || \
1928
+ (NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION)
1929
+ #include "npy_1_7_deprecated_api.h"
1930
+ #endif
1931
+ /*
1932
+ * There is no file npy_1_8_deprecated_api.h since there are no additional
1933
+ * deprecated API features in NumPy 1.8.
1934
+ *
1935
+ * Note to maintainers: insert code like the following in future NumPy
1936
+ * versions.
1937
+ *
1938
+ * #if !defined(NPY_NO_DEPRECATED_API) || \
1939
+ * (NPY_NO_DEPRECATED_API < NPY_1_9_API_VERSION)
1940
+ * #include "npy_1_9_deprecated_api.h"
1941
+ * #endif
1942
+ */
1943
+ #undef NPY_DEPRECATED_INCLUDES
1944
+
1945
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NDARRAYTYPES_H_ */
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/noprefix.h ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NOPREFIX_H_
2
+ #define NUMPY_CORE_INCLUDE_NUMPY_NOPREFIX_H_
3
+
4
+ /*
5
+ * You can directly include noprefix.h as a backward
6
+ * compatibility measure
7
+ */
8
+ #ifndef NPY_NO_PREFIX
9
+ #include "ndarrayobject.h"
10
+ #include "npy_interrupt.h"
11
+ #endif
12
+
13
+ #define SIGSETJMP NPY_SIGSETJMP
14
+ #define SIGLONGJMP NPY_SIGLONGJMP
15
+ #define SIGJMP_BUF NPY_SIGJMP_BUF
16
+
17
+ #define MAX_DIMS NPY_MAXDIMS
18
+
19
+ #define longlong npy_longlong
20
+ #define ulonglong npy_ulonglong
21
+ #define Bool npy_bool
22
+ #define longdouble npy_longdouble
23
+ #define byte npy_byte
24
+
25
+ #ifndef _BSD_SOURCE
26
+ #define ushort npy_ushort
27
+ #define uint npy_uint
28
+ #define ulong npy_ulong
29
+ #endif
30
+
31
+ #define ubyte npy_ubyte
32
+ #define ushort npy_ushort
33
+ #define uint npy_uint
34
+ #define ulong npy_ulong
35
+ #define cfloat npy_cfloat
36
+ #define cdouble npy_cdouble
37
+ #define clongdouble npy_clongdouble
38
+ #define Int8 npy_int8
39
+ #define UInt8 npy_uint8
40
+ #define Int16 npy_int16
41
+ #define UInt16 npy_uint16
42
+ #define Int32 npy_int32
43
+ #define UInt32 npy_uint32
44
+ #define Int64 npy_int64
45
+ #define UInt64 npy_uint64
46
+ #define Int128 npy_int128
47
+ #define UInt128 npy_uint128
48
+ #define Int256 npy_int256
49
+ #define UInt256 npy_uint256
50
+ #define Float16 npy_float16
51
+ #define Complex32 npy_complex32
52
+ #define Float32 npy_float32
53
+ #define Complex64 npy_complex64
54
+ #define Float64 npy_float64
55
+ #define Complex128 npy_complex128
56
+ #define Float80 npy_float80
57
+ #define Complex160 npy_complex160
58
+ #define Float96 npy_float96
59
+ #define Complex192 npy_complex192
60
+ #define Float128 npy_float128
61
+ #define Complex256 npy_complex256
62
+ #define intp npy_intp
63
+ #define uintp npy_uintp
64
+ #define datetime npy_datetime
65
+ #define timedelta npy_timedelta
66
+
67
+ #define SIZEOF_LONGLONG NPY_SIZEOF_LONGLONG
68
+ #define SIZEOF_INTP NPY_SIZEOF_INTP
69
+ #define SIZEOF_UINTP NPY_SIZEOF_UINTP
70
+ #define SIZEOF_HALF NPY_SIZEOF_HALF
71
+ #define SIZEOF_LONGDOUBLE NPY_SIZEOF_LONGDOUBLE
72
+ #define SIZEOF_DATETIME NPY_SIZEOF_DATETIME
73
+ #define SIZEOF_TIMEDELTA NPY_SIZEOF_TIMEDELTA
74
+
75
+ #define LONGLONG_FMT NPY_LONGLONG_FMT
76
+ #define ULONGLONG_FMT NPY_ULONGLONG_FMT
77
+ #define LONGLONG_SUFFIX NPY_LONGLONG_SUFFIX
78
+ #define ULONGLONG_SUFFIX NPY_ULONGLONG_SUFFIX
79
+
80
+ #define MAX_INT8 127
81
+ #define MIN_INT8 -128
82
+ #define MAX_UINT8 255
83
+ #define MAX_INT16 32767
84
+ #define MIN_INT16 -32768
85
+ #define MAX_UINT16 65535
86
+ #define MAX_INT32 2147483647
87
+ #define MIN_INT32 (-MAX_INT32 - 1)
88
+ #define MAX_UINT32 4294967295U
89
+ #define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)
90
+ #define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))
91
+ #define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)
92
+ #define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)
93
+ #define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))
94
+ #define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)
95
+ #define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)
96
+ #define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))
97
+ #define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)
98
+
99
+ #define MAX_BYTE NPY_MAX_BYTE
100
+ #define MIN_BYTE NPY_MIN_BYTE
101
+ #define MAX_UBYTE NPY_MAX_UBYTE
102
+ #define MAX_SHORT NPY_MAX_SHORT
103
+ #define MIN_SHORT NPY_MIN_SHORT
104
+ #define MAX_USHORT NPY_MAX_USHORT
105
+ #define MAX_INT NPY_MAX_INT
106
+ #define MIN_INT NPY_MIN_INT
107
+ #define MAX_UINT NPY_MAX_UINT
108
+ #define MAX_LONG NPY_MAX_LONG
109
+ #define MIN_LONG NPY_MIN_LONG
110
+ #define MAX_ULONG NPY_MAX_ULONG
111
+ #define MAX_LONGLONG NPY_MAX_LONGLONG
112
+ #define MIN_LONGLONG NPY_MIN_LONGLONG
113
+ #define MAX_ULONGLONG NPY_MAX_ULONGLONG
114
+ #define MIN_DATETIME NPY_MIN_DATETIME
115
+ #define MAX_DATETIME NPY_MAX_DATETIME
116
+ #define MIN_TIMEDELTA NPY_MIN_TIMEDELTA
117
+ #define MAX_TIMEDELTA NPY_MAX_TIMEDELTA
118
+
119
+ #define BITSOF_BOOL NPY_BITSOF_BOOL
120
+ #define BITSOF_CHAR NPY_BITSOF_CHAR
121
+ #define BITSOF_SHORT NPY_BITSOF_SHORT
122
+ #define BITSOF_INT NPY_BITSOF_INT
123
+ #define BITSOF_LONG NPY_BITSOF_LONG
124
+ #define BITSOF_LONGLONG NPY_BITSOF_LONGLONG
125
+ #define BITSOF_HALF NPY_BITSOF_HALF
126
+ #define BITSOF_FLOAT NPY_BITSOF_FLOAT
127
+ #define BITSOF_DOUBLE NPY_BITSOF_DOUBLE
128
+ #define BITSOF_LONGDOUBLE NPY_BITSOF_LONGDOUBLE
129
+ #define BITSOF_DATETIME NPY_BITSOF_DATETIME
130
+ #define BITSOF_TIMEDELTA NPY_BITSOF_TIMEDELTA
131
+
132
+ #define _pya_malloc PyArray_malloc
133
+ #define _pya_free PyArray_free
134
+ #define _pya_realloc PyArray_realloc
135
+
136
+ #define BEGIN_THREADS_DEF NPY_BEGIN_THREADS_DEF
137
+ #define BEGIN_THREADS NPY_BEGIN_THREADS
138
+ #define END_THREADS NPY_END_THREADS
139
+ #define ALLOW_C_API_DEF NPY_ALLOW_C_API_DEF
140
+ #define ALLOW_C_API NPY_ALLOW_C_API
141
+ #define DISABLE_C_API NPY_DISABLE_C_API
142
+
143
+ #define PY_FAIL NPY_FAIL
144
+ #define PY_SUCCEED NPY_SUCCEED
145
+
146
+ #ifndef TRUE
147
+ #define TRUE NPY_TRUE
148
+ #endif
149
+
150
+ #ifndef FALSE
151
+ #define FALSE NPY_FALSE
152
+ #endif
153
+
154
+ #define LONGDOUBLE_FMT NPY_LONGDOUBLE_FMT
155
+
156
+ #define CONTIGUOUS NPY_CONTIGUOUS
157
+ #define C_CONTIGUOUS NPY_C_CONTIGUOUS
158
+ #define FORTRAN NPY_FORTRAN
159
+ #define F_CONTIGUOUS NPY_F_CONTIGUOUS
160
+ #define OWNDATA NPY_OWNDATA
161
+ #define FORCECAST NPY_FORCECAST
162
+ #define ENSURECOPY NPY_ENSURECOPY
163
+ #define ENSUREARRAY NPY_ENSUREARRAY
164
+ #define ELEMENTSTRIDES NPY_ELEMENTSTRIDES
165
+ #define ALIGNED NPY_ALIGNED
166
+ #define NOTSWAPPED NPY_NOTSWAPPED
167
+ #define WRITEABLE NPY_WRITEABLE
168
+ #define WRITEBACKIFCOPY NPY_ARRAY_WRITEBACKIFCOPY
169
+ #define ARR_HAS_DESCR NPY_ARR_HAS_DESCR
170
+ #define BEHAVED NPY_BEHAVED
171
+ #define BEHAVED_NS NPY_BEHAVED_NS
172
+ #define CARRAY NPY_CARRAY
173
+ #define CARRAY_RO NPY_CARRAY_RO
174
+ #define FARRAY NPY_FARRAY
175
+ #define FARRAY_RO NPY_FARRAY_RO
176
+ #define DEFAULT NPY_DEFAULT
177
+ #define IN_ARRAY NPY_IN_ARRAY
178
+ #define OUT_ARRAY NPY_OUT_ARRAY
179
+ #define INOUT_ARRAY NPY_INOUT_ARRAY
180
+ #define IN_FARRAY NPY_IN_FARRAY
181
+ #define OUT_FARRAY NPY_OUT_FARRAY
182
+ #define INOUT_FARRAY NPY_INOUT_FARRAY
183
+ #define UPDATE_ALL NPY_UPDATE_ALL
184
+
185
+ #define OWN_DATA NPY_OWNDATA
186
+ #define BEHAVED_FLAGS NPY_BEHAVED
187
+ #define BEHAVED_FLAGS_NS NPY_BEHAVED_NS
188
+ #define CARRAY_FLAGS_RO NPY_CARRAY_RO
189
+ #define CARRAY_FLAGS NPY_CARRAY
190
+ #define FARRAY_FLAGS NPY_FARRAY
191
+ #define FARRAY_FLAGS_RO NPY_FARRAY_RO
192
+ #define DEFAULT_FLAGS NPY_DEFAULT
193
+ #define UPDATE_ALL_FLAGS NPY_UPDATE_ALL_FLAGS
194
+
195
+ #ifndef MIN
196
+ #define MIN PyArray_MIN
197
+ #endif
198
+ #ifndef MAX
199
+ #define MAX PyArray_MAX
200
+ #endif
201
+ #define MAX_INTP NPY_MAX_INTP
202
+ #define MIN_INTP NPY_MIN_INTP
203
+ #define MAX_UINTP NPY_MAX_UINTP
204
+ #define INTP_FMT NPY_INTP_FMT
205
+
206
+ #ifndef PYPY_VERSION
207
+ #define REFCOUNT PyArray_REFCOUNT
208
+ #define MAX_ELSIZE NPY_MAX_ELSIZE
209
+ #endif
210
+
211
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NOPREFIX_H_ */
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/npy_3kcompat.h ADDED
@@ -0,0 +1,595 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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. Although the stuff below is unlikely to change, we don't provide
9
+ * strong backwards compatibility guarantees at the moment.
10
+ */
11
+
12
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_3KCOMPAT_H_
13
+ #define NUMPY_CORE_INCLUDE_NUMPY_NPY_3KCOMPAT_H_
14
+
15
+ #include <Python.h>
16
+ #include <stdio.h>
17
+
18
+ #ifndef NPY_PY3K
19
+ #define NPY_PY3K 1
20
+ #endif
21
+
22
+ #include "numpy/npy_common.h"
23
+ #include "numpy/ndarrayobject.h"
24
+
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ /*
30
+ * PyInt -> PyLong
31
+ */
32
+
33
+
34
+ /*
35
+ * This is a renamed copy of the Python non-limited API function _PyLong_AsInt. It is
36
+ * included here because it is missing from the PyPy API. It completes the PyLong_As*
37
+ * group of functions and can be useful in replacing PyInt_Check.
38
+ */
39
+ static inline int
40
+ Npy__PyLong_AsInt(PyObject *obj)
41
+ {
42
+ int overflow;
43
+ long result = PyLong_AsLongAndOverflow(obj, &overflow);
44
+
45
+ /* INT_MAX and INT_MIN are defined in Python.h */
46
+ if (overflow || result > INT_MAX || result < INT_MIN) {
47
+ /* XXX: could be cute and give a different
48
+ message for overflow == -1 */
49
+ PyErr_SetString(PyExc_OverflowError,
50
+ "Python int too large to convert to C int");
51
+ return -1;
52
+ }
53
+ return (int)result;
54
+ }
55
+
56
+
57
+ #if defined(NPY_PY3K)
58
+ /* Return True only if the long fits in a C long */
59
+ static inline int PyInt_Check(PyObject *op) {
60
+ int overflow = 0;
61
+ if (!PyLong_Check(op)) {
62
+ return 0;
63
+ }
64
+ PyLong_AsLongAndOverflow(op, &overflow);
65
+ return (overflow == 0);
66
+ }
67
+
68
+
69
+ #define PyInt_FromLong PyLong_FromLong
70
+ #define PyInt_AsLong PyLong_AsLong
71
+ #define PyInt_AS_LONG PyLong_AsLong
72
+ #define PyInt_AsSsize_t PyLong_AsSsize_t
73
+ #define PyNumber_Int PyNumber_Long
74
+
75
+ /* NOTE:
76
+ *
77
+ * Since the PyLong type is very different from the fixed-range PyInt,
78
+ * we don't define PyInt_Type -> PyLong_Type.
79
+ */
80
+ #endif /* NPY_PY3K */
81
+
82
+ /* Py3 changes PySlice_GetIndicesEx' first argument's type to PyObject* */
83
+ #ifdef NPY_PY3K
84
+ # define NpySlice_GetIndicesEx PySlice_GetIndicesEx
85
+ #else
86
+ # define NpySlice_GetIndicesEx(op, nop, start, end, step, slicelength) \
87
+ PySlice_GetIndicesEx((PySliceObject *)op, nop, start, end, step, slicelength)
88
+ #endif
89
+
90
+ #if PY_VERSION_HEX < 0x030900a4
91
+ /* Introduced in https://github.com/python/cpython/commit/d2ec81a8c99796b51fb8c49b77a7fe369863226f */
92
+ #define Py_SET_TYPE(obj, type) ((Py_TYPE(obj) = (type)), (void)0)
93
+ /* Introduced in https://github.com/python/cpython/commit/b10dc3e7a11fcdb97e285882eba6da92594f90f9 */
94
+ #define Py_SET_SIZE(obj, size) ((Py_SIZE(obj) = (size)), (void)0)
95
+ /* Introduced in https://github.com/python/cpython/commit/c86a11221df7e37da389f9c6ce6e47ea22dc44ff */
96
+ #define Py_SET_REFCNT(obj, refcnt) ((Py_REFCNT(obj) = (refcnt)), (void)0)
97
+ #endif
98
+
99
+
100
+ #define Npy_EnterRecursiveCall(x) Py_EnterRecursiveCall(x)
101
+
102
+ /*
103
+ * PyString -> PyBytes
104
+ */
105
+
106
+ #if defined(NPY_PY3K)
107
+
108
+ #define PyString_Type PyBytes_Type
109
+ #define PyString_Check PyBytes_Check
110
+ #define PyStringObject PyBytesObject
111
+ #define PyString_FromString PyBytes_FromString
112
+ #define PyString_FromStringAndSize PyBytes_FromStringAndSize
113
+ #define PyString_AS_STRING PyBytes_AS_STRING
114
+ #define PyString_AsStringAndSize PyBytes_AsStringAndSize
115
+ #define PyString_FromFormat PyBytes_FromFormat
116
+ #define PyString_Concat PyBytes_Concat
117
+ #define PyString_ConcatAndDel PyBytes_ConcatAndDel
118
+ #define PyString_AsString PyBytes_AsString
119
+ #define PyString_GET_SIZE PyBytes_GET_SIZE
120
+ #define PyString_Size PyBytes_Size
121
+
122
+ #define PyUString_Type PyUnicode_Type
123
+ #define PyUString_Check PyUnicode_Check
124
+ #define PyUStringObject PyUnicodeObject
125
+ #define PyUString_FromString PyUnicode_FromString
126
+ #define PyUString_FromStringAndSize PyUnicode_FromStringAndSize
127
+ #define PyUString_FromFormat PyUnicode_FromFormat
128
+ #define PyUString_Concat PyUnicode_Concat2
129
+ #define PyUString_ConcatAndDel PyUnicode_ConcatAndDel
130
+ #define PyUString_GET_SIZE PyUnicode_GET_SIZE
131
+ #define PyUString_Size PyUnicode_Size
132
+ #define PyUString_InternFromString PyUnicode_InternFromString
133
+ #define PyUString_Format PyUnicode_Format
134
+
135
+ #define PyBaseString_Check(obj) (PyUnicode_Check(obj))
136
+
137
+ #else
138
+
139
+ #define PyBytes_Type PyString_Type
140
+ #define PyBytes_Check PyString_Check
141
+ #define PyBytesObject PyStringObject
142
+ #define PyBytes_FromString PyString_FromString
143
+ #define PyBytes_FromStringAndSize PyString_FromStringAndSize
144
+ #define PyBytes_AS_STRING PyString_AS_STRING
145
+ #define PyBytes_AsStringAndSize PyString_AsStringAndSize
146
+ #define PyBytes_FromFormat PyString_FromFormat
147
+ #define PyBytes_Concat PyString_Concat
148
+ #define PyBytes_ConcatAndDel PyString_ConcatAndDel
149
+ #define PyBytes_AsString PyString_AsString
150
+ #define PyBytes_GET_SIZE PyString_GET_SIZE
151
+ #define PyBytes_Size PyString_Size
152
+
153
+ #define PyUString_Type PyString_Type
154
+ #define PyUString_Check PyString_Check
155
+ #define PyUStringObject PyStringObject
156
+ #define PyUString_FromString PyString_FromString
157
+ #define PyUString_FromStringAndSize PyString_FromStringAndSize
158
+ #define PyUString_FromFormat PyString_FromFormat
159
+ #define PyUString_Concat PyString_Concat
160
+ #define PyUString_ConcatAndDel PyString_ConcatAndDel
161
+ #define PyUString_GET_SIZE PyString_GET_SIZE
162
+ #define PyUString_Size PyString_Size
163
+ #define PyUString_InternFromString PyString_InternFromString
164
+ #define PyUString_Format PyString_Format
165
+
166
+ #define PyBaseString_Check(obj) (PyBytes_Check(obj) || PyUnicode_Check(obj))
167
+
168
+ #endif /* NPY_PY3K */
169
+
170
+ /*
171
+ * Macros to protect CRT calls against instant termination when passed an
172
+ * invalid parameter (https://bugs.python.org/issue23524).
173
+ */
174
+ #if defined _MSC_VER && _MSC_VER >= 1900
175
+
176
+ #include <stdlib.h>
177
+
178
+ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
179
+ #define NPY_BEGIN_SUPPRESS_IPH { _invalid_parameter_handler _Py_old_handler = \
180
+ _set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
181
+ #define NPY_END_SUPPRESS_IPH _set_thread_local_invalid_parameter_handler(_Py_old_handler); }
182
+
183
+ #else
184
+
185
+ #define NPY_BEGIN_SUPPRESS_IPH
186
+ #define NPY_END_SUPPRESS_IPH
187
+
188
+ #endif /* _MSC_VER >= 1900 */
189
+
190
+
191
+ static inline void
192
+ PyUnicode_ConcatAndDel(PyObject **left, PyObject *right)
193
+ {
194
+ Py_SETREF(*left, PyUnicode_Concat(*left, right));
195
+ Py_DECREF(right);
196
+ }
197
+
198
+ static inline void
199
+ PyUnicode_Concat2(PyObject **left, PyObject *right)
200
+ {
201
+ Py_SETREF(*left, PyUnicode_Concat(*left, right));
202
+ }
203
+
204
+ /*
205
+ * PyFile_* compatibility
206
+ */
207
+
208
+ /*
209
+ * Get a FILE* handle to the file represented by the Python object
210
+ */
211
+ static inline FILE*
212
+ npy_PyFile_Dup2(PyObject *file, char *mode, npy_off_t *orig_pos)
213
+ {
214
+ int fd, fd2, unbuf;
215
+ Py_ssize_t fd2_tmp;
216
+ PyObject *ret, *os, *io, *io_raw;
217
+ npy_off_t pos;
218
+ FILE *handle;
219
+
220
+ /* For Python 2 PyFileObject, use PyFile_AsFile */
221
+ #if !defined(NPY_PY3K)
222
+ if (PyFile_Check(file)) {
223
+ return PyFile_AsFile(file);
224
+ }
225
+ #endif
226
+
227
+ /* Flush first to ensure things end up in the file in the correct order */
228
+ ret = PyObject_CallMethod(file, "flush", "");
229
+ if (ret == NULL) {
230
+ return NULL;
231
+ }
232
+ Py_DECREF(ret);
233
+ fd = PyObject_AsFileDescriptor(file);
234
+ if (fd == -1) {
235
+ return NULL;
236
+ }
237
+
238
+ /*
239
+ * The handle needs to be dup'd because we have to call fclose
240
+ * at the end
241
+ */
242
+ os = PyImport_ImportModule("os");
243
+ if (os == NULL) {
244
+ return NULL;
245
+ }
246
+ ret = PyObject_CallMethod(os, "dup", "i", fd);
247
+ Py_DECREF(os);
248
+ if (ret == NULL) {
249
+ return NULL;
250
+ }
251
+ fd2_tmp = PyNumber_AsSsize_t(ret, PyExc_IOError);
252
+ Py_DECREF(ret);
253
+ if (fd2_tmp == -1 && PyErr_Occurred()) {
254
+ return NULL;
255
+ }
256
+ if (fd2_tmp < INT_MIN || fd2_tmp > INT_MAX) {
257
+ PyErr_SetString(PyExc_IOError,
258
+ "Getting an 'int' from os.dup() failed");
259
+ return NULL;
260
+ }
261
+ fd2 = (int)fd2_tmp;
262
+
263
+ /* Convert to FILE* handle */
264
+ #ifdef _WIN32
265
+ NPY_BEGIN_SUPPRESS_IPH
266
+ handle = _fdopen(fd2, mode);
267
+ NPY_END_SUPPRESS_IPH
268
+ #else
269
+ handle = fdopen(fd2, mode);
270
+ #endif
271
+ if (handle == NULL) {
272
+ PyErr_SetString(PyExc_IOError,
273
+ "Getting a FILE* from a Python file object via "
274
+ "_fdopen failed. If you built NumPy, you probably "
275
+ "linked with the wrong debug/release runtime");
276
+ return NULL;
277
+ }
278
+
279
+ /* Record the original raw file handle position */
280
+ *orig_pos = npy_ftell(handle);
281
+ if (*orig_pos == -1) {
282
+ /* The io module is needed to determine if buffering is used */
283
+ io = PyImport_ImportModule("io");
284
+ if (io == NULL) {
285
+ fclose(handle);
286
+ return NULL;
287
+ }
288
+ /* File object instances of RawIOBase are unbuffered */
289
+ io_raw = PyObject_GetAttrString(io, "RawIOBase");
290
+ Py_DECREF(io);
291
+ if (io_raw == NULL) {
292
+ fclose(handle);
293
+ return NULL;
294
+ }
295
+ unbuf = PyObject_IsInstance(file, io_raw);
296
+ Py_DECREF(io_raw);
297
+ if (unbuf == 1) {
298
+ /* Succeed if the IO is unbuffered */
299
+ return handle;
300
+ }
301
+ else {
302
+ PyErr_SetString(PyExc_IOError, "obtaining file position failed");
303
+ fclose(handle);
304
+ return NULL;
305
+ }
306
+ }
307
+
308
+ /* Seek raw handle to the Python-side position */
309
+ ret = PyObject_CallMethod(file, "tell", "");
310
+ if (ret == NULL) {
311
+ fclose(handle);
312
+ return NULL;
313
+ }
314
+ pos = PyLong_AsLongLong(ret);
315
+ Py_DECREF(ret);
316
+ if (PyErr_Occurred()) {
317
+ fclose(handle);
318
+ return NULL;
319
+ }
320
+ if (npy_fseek(handle, pos, SEEK_SET) == -1) {
321
+ PyErr_SetString(PyExc_IOError, "seeking file failed");
322
+ fclose(handle);
323
+ return NULL;
324
+ }
325
+ return handle;
326
+ }
327
+
328
+ /*
329
+ * Close the dup-ed file handle, and seek the Python one to the current position
330
+ */
331
+ static inline int
332
+ npy_PyFile_DupClose2(PyObject *file, FILE* handle, npy_off_t orig_pos)
333
+ {
334
+ int fd, unbuf;
335
+ PyObject *ret, *io, *io_raw;
336
+ npy_off_t position;
337
+
338
+ /* For Python 2 PyFileObject, do nothing */
339
+ #if !defined(NPY_PY3K)
340
+ if (PyFile_Check(file)) {
341
+ return 0;
342
+ }
343
+ #endif
344
+
345
+ position = npy_ftell(handle);
346
+
347
+ /* Close the FILE* handle */
348
+ fclose(handle);
349
+
350
+ /*
351
+ * Restore original file handle position, in order to not confuse
352
+ * Python-side data structures
353
+ */
354
+ fd = PyObject_AsFileDescriptor(file);
355
+ if (fd == -1) {
356
+ return -1;
357
+ }
358
+
359
+ if (npy_lseek(fd, orig_pos, SEEK_SET) == -1) {
360
+
361
+ /* The io module is needed to determine if buffering is used */
362
+ io = PyImport_ImportModule("io");
363
+ if (io == NULL) {
364
+ return -1;
365
+ }
366
+ /* File object instances of RawIOBase are unbuffered */
367
+ io_raw = PyObject_GetAttrString(io, "RawIOBase");
368
+ Py_DECREF(io);
369
+ if (io_raw == NULL) {
370
+ return -1;
371
+ }
372
+ unbuf = PyObject_IsInstance(file, io_raw);
373
+ Py_DECREF(io_raw);
374
+ if (unbuf == 1) {
375
+ /* Succeed if the IO is unbuffered */
376
+ return 0;
377
+ }
378
+ else {
379
+ PyErr_SetString(PyExc_IOError, "seeking file failed");
380
+ return -1;
381
+ }
382
+ }
383
+
384
+ if (position == -1) {
385
+ PyErr_SetString(PyExc_IOError, "obtaining file position failed");
386
+ return -1;
387
+ }
388
+
389
+ /* Seek Python-side handle to the FILE* handle position */
390
+ ret = PyObject_CallMethod(file, "seek", NPY_OFF_T_PYFMT "i", position, 0);
391
+ if (ret == NULL) {
392
+ return -1;
393
+ }
394
+ Py_DECREF(ret);
395
+ return 0;
396
+ }
397
+
398
+ static inline int
399
+ npy_PyFile_Check(PyObject *file)
400
+ {
401
+ int fd;
402
+ /* For Python 2, check if it is a PyFileObject */
403
+ #if !defined(NPY_PY3K)
404
+ if (PyFile_Check(file)) {
405
+ return 1;
406
+ }
407
+ #endif
408
+ fd = PyObject_AsFileDescriptor(file);
409
+ if (fd == -1) {
410
+ PyErr_Clear();
411
+ return 0;
412
+ }
413
+ return 1;
414
+ }
415
+
416
+ static inline PyObject*
417
+ npy_PyFile_OpenFile(PyObject *filename, const char *mode)
418
+ {
419
+ PyObject *open;
420
+ open = PyDict_GetItemString(PyEval_GetBuiltins(), "open");
421
+ if (open == NULL) {
422
+ return NULL;
423
+ }
424
+ return PyObject_CallFunction(open, "Os", filename, mode);
425
+ }
426
+
427
+ static inline int
428
+ npy_PyFile_CloseFile(PyObject *file)
429
+ {
430
+ PyObject *ret;
431
+
432
+ ret = PyObject_CallMethod(file, "close", NULL);
433
+ if (ret == NULL) {
434
+ return -1;
435
+ }
436
+ Py_DECREF(ret);
437
+ return 0;
438
+ }
439
+
440
+
441
+ /* This is a copy of _PyErr_ChainExceptions
442
+ */
443
+ static inline void
444
+ npy_PyErr_ChainExceptions(PyObject *exc, PyObject *val, PyObject *tb)
445
+ {
446
+ if (exc == NULL)
447
+ return;
448
+
449
+ if (PyErr_Occurred()) {
450
+ /* only py3 supports this anyway */
451
+ #ifdef NPY_PY3K
452
+ PyObject *exc2, *val2, *tb2;
453
+ PyErr_Fetch(&exc2, &val2, &tb2);
454
+ PyErr_NormalizeException(&exc, &val, &tb);
455
+ if (tb != NULL) {
456
+ PyException_SetTraceback(val, tb);
457
+ Py_DECREF(tb);
458
+ }
459
+ Py_DECREF(exc);
460
+ PyErr_NormalizeException(&exc2, &val2, &tb2);
461
+ PyException_SetContext(val2, val);
462
+ PyErr_Restore(exc2, val2, tb2);
463
+ #endif
464
+ }
465
+ else {
466
+ PyErr_Restore(exc, val, tb);
467
+ }
468
+ }
469
+
470
+
471
+ /* This is a copy of _PyErr_ChainExceptions, with:
472
+ * - a minimal implementation for python 2
473
+ * - __cause__ used instead of __context__
474
+ */
475
+ static inline void
476
+ npy_PyErr_ChainExceptionsCause(PyObject *exc, PyObject *val, PyObject *tb)
477
+ {
478
+ if (exc == NULL)
479
+ return;
480
+
481
+ if (PyErr_Occurred()) {
482
+ /* only py3 supports this anyway */
483
+ #ifdef NPY_PY3K
484
+ PyObject *exc2, *val2, *tb2;
485
+ PyErr_Fetch(&exc2, &val2, &tb2);
486
+ PyErr_NormalizeException(&exc, &val, &tb);
487
+ if (tb != NULL) {
488
+ PyException_SetTraceback(val, tb);
489
+ Py_DECREF(tb);
490
+ }
491
+ Py_DECREF(exc);
492
+ PyErr_NormalizeException(&exc2, &val2, &tb2);
493
+ PyException_SetCause(val2, val);
494
+ PyErr_Restore(exc2, val2, tb2);
495
+ #endif
496
+ }
497
+ else {
498
+ PyErr_Restore(exc, val, tb);
499
+ }
500
+ }
501
+
502
+ /*
503
+ * PyObject_Cmp
504
+ */
505
+ #if defined(NPY_PY3K)
506
+ static inline int
507
+ PyObject_Cmp(PyObject *i1, PyObject *i2, int *cmp)
508
+ {
509
+ int v;
510
+ v = PyObject_RichCompareBool(i1, i2, Py_LT);
511
+ if (v == 1) {
512
+ *cmp = -1;
513
+ return 1;
514
+ }
515
+ else if (v == -1) {
516
+ return -1;
517
+ }
518
+
519
+ v = PyObject_RichCompareBool(i1, i2, Py_GT);
520
+ if (v == 1) {
521
+ *cmp = 1;
522
+ return 1;
523
+ }
524
+ else if (v == -1) {
525
+ return -1;
526
+ }
527
+
528
+ v = PyObject_RichCompareBool(i1, i2, Py_EQ);
529
+ if (v == 1) {
530
+ *cmp = 0;
531
+ return 1;
532
+ }
533
+ else {
534
+ *cmp = 0;
535
+ return -1;
536
+ }
537
+ }
538
+ #endif
539
+
540
+ /*
541
+ * PyCObject functions adapted to PyCapsules.
542
+ *
543
+ * The main job here is to get rid of the improved error handling
544
+ * of PyCapsules. It's a shame...
545
+ */
546
+ static inline PyObject *
547
+ NpyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *))
548
+ {
549
+ PyObject *ret = PyCapsule_New(ptr, NULL, dtor);
550
+ if (ret == NULL) {
551
+ PyErr_Clear();
552
+ }
553
+ return ret;
554
+ }
555
+
556
+ static inline PyObject *
557
+ NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, void (*dtor)(PyObject *))
558
+ {
559
+ PyObject *ret = NpyCapsule_FromVoidPtr(ptr, dtor);
560
+ if (ret != NULL && PyCapsule_SetContext(ret, context) != 0) {
561
+ PyErr_Clear();
562
+ Py_DECREF(ret);
563
+ ret = NULL;
564
+ }
565
+ return ret;
566
+ }
567
+
568
+ static inline void *
569
+ NpyCapsule_AsVoidPtr(PyObject *obj)
570
+ {
571
+ void *ret = PyCapsule_GetPointer(obj, NULL);
572
+ if (ret == NULL) {
573
+ PyErr_Clear();
574
+ }
575
+ return ret;
576
+ }
577
+
578
+ static inline void *
579
+ NpyCapsule_GetDesc(PyObject *obj)
580
+ {
581
+ return PyCapsule_GetContext(obj);
582
+ }
583
+
584
+ static inline int
585
+ NpyCapsule_Check(PyObject *ptr)
586
+ {
587
+ return PyCapsule_CheckExact(ptr);
588
+ }
589
+
590
+ #ifdef __cplusplus
591
+ }
592
+ #endif
593
+
594
+
595
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_3KCOMPAT_H_ */
moondream/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_ */
moondream/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_ */
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/npy_interrupt.h ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * This API is only provided because it is part of publicly exported
3
+ * headers. Its use is considered DEPRECATED, and it will be removed
4
+ * eventually.
5
+ * (This includes the _PyArray_SigintHandler and _PyArray_GetSigintBuf
6
+ * functions which are however, public API, and not headers.)
7
+ *
8
+ * Instead of using these non-threadsafe macros consider periodically
9
+ * querying `PyErr_CheckSignals()` or `PyOS_InterruptOccurred()` will work.
10
+ * Both of these require holding the GIL, although cpython could add a
11
+ * version of `PyOS_InterruptOccurred()` which does not. Such a version
12
+ * actually exists as private API in Python 3.10, and backported to 3.9 and 3.8,
13
+ * see also https://bugs.python.org/issue41037 and
14
+ * https://github.com/python/cpython/pull/20599).
15
+ */
16
+
17
+ #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_INTERRUPT_H_
18
+ #define NUMPY_CORE_INCLUDE_NUMPY_NPY_INTERRUPT_H_
19
+
20
+ #ifndef NPY_NO_SIGNAL
21
+
22
+ #include <setjmp.h>
23
+ #include <signal.h>
24
+
25
+ #ifndef sigsetjmp
26
+
27
+ #define NPY_SIGSETJMP(arg1, arg2) setjmp(arg1)
28
+ #define NPY_SIGLONGJMP(arg1, arg2) longjmp(arg1, arg2)
29
+ #define NPY_SIGJMP_BUF jmp_buf
30
+
31
+ #else
32
+
33
+ #define NPY_SIGSETJMP(arg1, arg2) sigsetjmp(arg1, arg2)
34
+ #define NPY_SIGLONGJMP(arg1, arg2) siglongjmp(arg1, arg2)
35
+ #define NPY_SIGJMP_BUF sigjmp_buf
36
+
37
+ #endif
38
+
39
+ # define NPY_SIGINT_ON { \
40
+ PyOS_sighandler_t _npy_sig_save; \
41
+ _npy_sig_save = PyOS_setsig(SIGINT, _PyArray_SigintHandler); \
42
+ if (NPY_SIGSETJMP(*((NPY_SIGJMP_BUF *)_PyArray_GetSigintBuf()), \
43
+ 1) == 0) { \
44
+
45
+ # define NPY_SIGINT_OFF } \
46
+ PyOS_setsig(SIGINT, _npy_sig_save); \
47
+ }
48
+
49
+ #else /* NPY_NO_SIGNAL */
50
+
51
+ #define NPY_SIGINT_ON
52
+ #define NPY_SIGINT_OFF
53
+
54
+ #endif /* HAVE_SIGSETJMP */
55
+
56
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_INTERRUPT_H_ */
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/npy_math.h ADDED
@@ -0,0 +1,563 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /*
22
+ * NAN and INFINITY like macros (same behavior as glibc for NAN, same as C99
23
+ * for INFINITY)
24
+ *
25
+ * XXX: I should test whether INFINITY and NAN are available on the platform
26
+ */
27
+ static inline float __npy_inff(void)
28
+ {
29
+ const union { npy_uint32 __i; float __f;} __bint = {0x7f800000UL};
30
+ return __bint.__f;
31
+ }
32
+
33
+ static inline float __npy_nanf(void)
34
+ {
35
+ const union { npy_uint32 __i; float __f;} __bint = {0x7fc00000UL};
36
+ return __bint.__f;
37
+ }
38
+
39
+ static inline float __npy_pzerof(void)
40
+ {
41
+ const union { npy_uint32 __i; float __f;} __bint = {0x00000000UL};
42
+ return __bint.__f;
43
+ }
44
+
45
+ static inline float __npy_nzerof(void)
46
+ {
47
+ const union { npy_uint32 __i; float __f;} __bint = {0x80000000UL};
48
+ return __bint.__f;
49
+ }
50
+
51
+ #define NPY_INFINITYF __npy_inff()
52
+ #define NPY_NANF __npy_nanf()
53
+ #define NPY_PZEROF __npy_pzerof()
54
+ #define NPY_NZEROF __npy_nzerof()
55
+
56
+ #define NPY_INFINITY ((npy_double)NPY_INFINITYF)
57
+ #define NPY_NAN ((npy_double)NPY_NANF)
58
+ #define NPY_PZERO ((npy_double)NPY_PZEROF)
59
+ #define NPY_NZERO ((npy_double)NPY_NZEROF)
60
+
61
+ #define NPY_INFINITYL ((npy_longdouble)NPY_INFINITYF)
62
+ #define NPY_NANL ((npy_longdouble)NPY_NANF)
63
+ #define NPY_PZEROL ((npy_longdouble)NPY_PZEROF)
64
+ #define NPY_NZEROL ((npy_longdouble)NPY_NZEROF)
65
+
66
+ /*
67
+ * Useful constants
68
+ */
69
+ #define NPY_E 2.718281828459045235360287471352662498 /* e */
70
+ #define NPY_LOG2E 1.442695040888963407359924681001892137 /* log_2 e */
71
+ #define NPY_LOG10E 0.434294481903251827651128918916605082 /* log_10 e */
72
+ #define NPY_LOGE2 0.693147180559945309417232121458176568 /* log_e 2 */
73
+ #define NPY_LOGE10 2.302585092994045684017991454684364208 /* log_e 10 */
74
+ #define NPY_PI 3.141592653589793238462643383279502884 /* pi */
75
+ #define NPY_PI_2 1.570796326794896619231321691639751442 /* pi/2 */
76
+ #define NPY_PI_4 0.785398163397448309615660845819875721 /* pi/4 */
77
+ #define NPY_1_PI 0.318309886183790671537767526745028724 /* 1/pi */
78
+ #define NPY_2_PI 0.636619772367581343075535053490057448 /* 2/pi */
79
+ #define NPY_EULER 0.577215664901532860606512090082402431 /* Euler constant */
80
+ #define NPY_SQRT2 1.414213562373095048801688724209698079 /* sqrt(2) */
81
+ #define NPY_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */
82
+
83
+ #define NPY_Ef 2.718281828459045235360287471352662498F /* e */
84
+ #define NPY_LOG2Ef 1.442695040888963407359924681001892137F /* log_2 e */
85
+ #define NPY_LOG10Ef 0.434294481903251827651128918916605082F /* log_10 e */
86
+ #define NPY_LOGE2f 0.693147180559945309417232121458176568F /* log_e 2 */
87
+ #define NPY_LOGE10f 2.302585092994045684017991454684364208F /* log_e 10 */
88
+ #define NPY_PIf 3.141592653589793238462643383279502884F /* pi */
89
+ #define NPY_PI_2f 1.570796326794896619231321691639751442F /* pi/2 */
90
+ #define NPY_PI_4f 0.785398163397448309615660845819875721F /* pi/4 */
91
+ #define NPY_1_PIf 0.318309886183790671537767526745028724F /* 1/pi */
92
+ #define NPY_2_PIf 0.636619772367581343075535053490057448F /* 2/pi */
93
+ #define NPY_EULERf 0.577215664901532860606512090082402431F /* Euler constant */
94
+ #define NPY_SQRT2f 1.414213562373095048801688724209698079F /* sqrt(2) */
95
+ #define NPY_SQRT1_2f 0.707106781186547524400844362104849039F /* 1/sqrt(2) */
96
+
97
+ #define NPY_El 2.718281828459045235360287471352662498L /* e */
98
+ #define NPY_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
99
+ #define NPY_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
100
+ #define NPY_LOGE2l 0.693147180559945309417232121458176568L /* log_e 2 */
101
+ #define NPY_LOGE10l 2.302585092994045684017991454684364208L /* log_e 10 */
102
+ #define NPY_PIl 3.141592653589793238462643383279502884L /* pi */
103
+ #define NPY_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
104
+ #define NPY_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
105
+ #define NPY_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
106
+ #define NPY_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
107
+ #define NPY_EULERl 0.577215664901532860606512090082402431L /* Euler constant */
108
+ #define NPY_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
109
+ #define NPY_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
110
+
111
+ /*
112
+ * Integer functions.
113
+ */
114
+ NPY_INPLACE npy_uint npy_gcdu(npy_uint a, npy_uint b);
115
+ NPY_INPLACE npy_uint npy_lcmu(npy_uint a, npy_uint b);
116
+ NPY_INPLACE npy_ulong npy_gcdul(npy_ulong a, npy_ulong b);
117
+ NPY_INPLACE npy_ulong npy_lcmul(npy_ulong a, npy_ulong b);
118
+ NPY_INPLACE npy_ulonglong npy_gcdull(npy_ulonglong a, npy_ulonglong b);
119
+ NPY_INPLACE npy_ulonglong npy_lcmull(npy_ulonglong a, npy_ulonglong b);
120
+
121
+ NPY_INPLACE npy_int npy_gcd(npy_int a, npy_int b);
122
+ NPY_INPLACE npy_int npy_lcm(npy_int a, npy_int b);
123
+ NPY_INPLACE npy_long npy_gcdl(npy_long a, npy_long b);
124
+ NPY_INPLACE npy_long npy_lcml(npy_long a, npy_long b);
125
+ NPY_INPLACE npy_longlong npy_gcdll(npy_longlong a, npy_longlong b);
126
+ NPY_INPLACE npy_longlong npy_lcmll(npy_longlong a, npy_longlong b);
127
+
128
+ NPY_INPLACE npy_ubyte npy_rshiftuhh(npy_ubyte a, npy_ubyte b);
129
+ NPY_INPLACE npy_ubyte npy_lshiftuhh(npy_ubyte a, npy_ubyte b);
130
+ NPY_INPLACE npy_ushort npy_rshiftuh(npy_ushort a, npy_ushort b);
131
+ NPY_INPLACE npy_ushort npy_lshiftuh(npy_ushort a, npy_ushort b);
132
+ NPY_INPLACE npy_uint npy_rshiftu(npy_uint a, npy_uint b);
133
+ NPY_INPLACE npy_uint npy_lshiftu(npy_uint a, npy_uint b);
134
+ NPY_INPLACE npy_ulong npy_rshiftul(npy_ulong a, npy_ulong b);
135
+ NPY_INPLACE npy_ulong npy_lshiftul(npy_ulong a, npy_ulong b);
136
+ NPY_INPLACE npy_ulonglong npy_rshiftull(npy_ulonglong a, npy_ulonglong b);
137
+ NPY_INPLACE npy_ulonglong npy_lshiftull(npy_ulonglong a, npy_ulonglong b);
138
+
139
+ NPY_INPLACE npy_byte npy_rshifthh(npy_byte a, npy_byte b);
140
+ NPY_INPLACE npy_byte npy_lshifthh(npy_byte a, npy_byte b);
141
+ NPY_INPLACE npy_short npy_rshifth(npy_short a, npy_short b);
142
+ NPY_INPLACE npy_short npy_lshifth(npy_short a, npy_short b);
143
+ NPY_INPLACE npy_int npy_rshift(npy_int a, npy_int b);
144
+ NPY_INPLACE npy_int npy_lshift(npy_int a, npy_int b);
145
+ NPY_INPLACE npy_long npy_rshiftl(npy_long a, npy_long b);
146
+ NPY_INPLACE npy_long npy_lshiftl(npy_long a, npy_long b);
147
+ NPY_INPLACE npy_longlong npy_rshiftll(npy_longlong a, npy_longlong b);
148
+ NPY_INPLACE npy_longlong npy_lshiftll(npy_longlong a, npy_longlong b);
149
+
150
+ NPY_INPLACE uint8_t npy_popcountuhh(npy_ubyte a);
151
+ NPY_INPLACE uint8_t npy_popcountuh(npy_ushort a);
152
+ NPY_INPLACE uint8_t npy_popcountu(npy_uint a);
153
+ NPY_INPLACE uint8_t npy_popcountul(npy_ulong a);
154
+ NPY_INPLACE uint8_t npy_popcountull(npy_ulonglong a);
155
+ NPY_INPLACE uint8_t npy_popcounthh(npy_byte a);
156
+ NPY_INPLACE uint8_t npy_popcounth(npy_short a);
157
+ NPY_INPLACE uint8_t npy_popcount(npy_int a);
158
+ NPY_INPLACE uint8_t npy_popcountl(npy_long a);
159
+ NPY_INPLACE uint8_t npy_popcountll(npy_longlong a);
160
+
161
+ /*
162
+ * C99 double math funcs that need fixups or are blocklist-able
163
+ */
164
+ NPY_INPLACE double npy_sin(double x);
165
+ NPY_INPLACE double npy_cos(double x);
166
+ NPY_INPLACE double npy_tan(double x);
167
+ NPY_INPLACE double npy_hypot(double x, double y);
168
+ NPY_INPLACE double npy_log2(double x);
169
+ NPY_INPLACE double npy_atan2(double x, double y);
170
+
171
+ /* Mandatory C99 double math funcs, no blocklisting or fixups */
172
+ /* defined for legacy reasons, should be deprecated at some point */
173
+ #define npy_sinh sinh
174
+ #define npy_cosh cosh
175
+ #define npy_tanh tanh
176
+ #define npy_asin asin
177
+ #define npy_acos acos
178
+ #define npy_atan atan
179
+ #define npy_log log
180
+ #define npy_log10 log10
181
+ #define npy_cbrt cbrt
182
+ #define npy_fabs fabs
183
+ #define npy_ceil ceil
184
+ #define npy_fmod fmod
185
+ #define npy_floor floor
186
+ #define npy_expm1 expm1
187
+ #define npy_log1p log1p
188
+ #define npy_acosh acosh
189
+ #define npy_asinh asinh
190
+ #define npy_atanh atanh
191
+ #define npy_rint rint
192
+ #define npy_trunc trunc
193
+ #define npy_exp2 exp2
194
+ #define npy_frexp frexp
195
+ #define npy_ldexp ldexp
196
+ #define npy_copysign copysign
197
+ #define npy_exp exp
198
+ #define npy_sqrt sqrt
199
+ #define npy_pow pow
200
+ #define npy_modf modf
201
+ #define npy_nextafter nextafter
202
+
203
+ double npy_spacing(double x);
204
+
205
+ /*
206
+ * IEEE 754 fpu handling
207
+ */
208
+
209
+ /* use builtins to avoid function calls in tight loops
210
+ * only available if npy_config.h is available (= numpys own build) */
211
+ #ifdef HAVE___BUILTIN_ISNAN
212
+ #define npy_isnan(x) __builtin_isnan(x)
213
+ #else
214
+ #define npy_isnan(x) isnan(x)
215
+ #endif
216
+
217
+
218
+ /* only available if npy_config.h is available (= numpys own build) */
219
+ #ifdef HAVE___BUILTIN_ISFINITE
220
+ #define npy_isfinite(x) __builtin_isfinite(x)
221
+ #else
222
+ #define npy_isfinite(x) isfinite((x))
223
+ #endif
224
+
225
+ /* only available if npy_config.h is available (= numpys own build) */
226
+ #ifdef HAVE___BUILTIN_ISINF
227
+ #define npy_isinf(x) __builtin_isinf(x)
228
+ #else
229
+ #define npy_isinf(x) isinf((x))
230
+ #endif
231
+
232
+ #define npy_signbit(x) signbit((x))
233
+
234
+ /*
235
+ * float C99 math funcs that need fixups or are blocklist-able
236
+ */
237
+ NPY_INPLACE float npy_sinf(float x);
238
+ NPY_INPLACE float npy_cosf(float x);
239
+ NPY_INPLACE float npy_tanf(float x);
240
+ NPY_INPLACE float npy_expf(float x);
241
+ NPY_INPLACE float npy_sqrtf(float x);
242
+ NPY_INPLACE float npy_hypotf(float x, float y);
243
+ NPY_INPLACE float npy_log2f(float x);
244
+ NPY_INPLACE float npy_atan2f(float x, float y);
245
+ NPY_INPLACE float npy_powf(float x, float y);
246
+ NPY_INPLACE float npy_modff(float x, float* y);
247
+
248
+ /* Mandatory C99 float math funcs, no blocklisting or fixups */
249
+ /* defined for legacy reasons, should be deprecated at some point */
250
+
251
+ #define npy_sinhf sinhf
252
+ #define npy_coshf coshf
253
+ #define npy_tanhf tanhf
254
+ #define npy_asinf asinf
255
+ #define npy_acosf acosf
256
+ #define npy_atanf atanf
257
+ #define npy_logf logf
258
+ #define npy_log10f log10f
259
+ #define npy_cbrtf cbrtf
260
+ #define npy_fabsf fabsf
261
+ #define npy_ceilf ceilf
262
+ #define npy_fmodf fmodf
263
+ #define npy_floorf floorf
264
+ #define npy_expm1f expm1f
265
+ #define npy_log1pf log1pf
266
+ #define npy_asinhf asinhf
267
+ #define npy_acoshf acoshf
268
+ #define npy_atanhf atanhf
269
+ #define npy_rintf rintf
270
+ #define npy_truncf truncf
271
+ #define npy_exp2f exp2f
272
+ #define npy_frexpf frexpf
273
+ #define npy_ldexpf ldexpf
274
+ #define npy_copysignf copysignf
275
+ #define npy_nextafterf nextafterf
276
+
277
+ float npy_spacingf(float x);
278
+
279
+ /*
280
+ * long double C99 double math funcs that need fixups or are blocklist-able
281
+ */
282
+ NPY_INPLACE npy_longdouble npy_sinl(npy_longdouble x);
283
+ NPY_INPLACE npy_longdouble npy_cosl(npy_longdouble x);
284
+ NPY_INPLACE npy_longdouble npy_tanl(npy_longdouble x);
285
+ NPY_INPLACE npy_longdouble npy_expl(npy_longdouble x);
286
+ NPY_INPLACE npy_longdouble npy_sqrtl(npy_longdouble x);
287
+ NPY_INPLACE npy_longdouble npy_hypotl(npy_longdouble x, npy_longdouble y);
288
+ NPY_INPLACE npy_longdouble npy_log2l(npy_longdouble x);
289
+ NPY_INPLACE npy_longdouble npy_atan2l(npy_longdouble x, npy_longdouble y);
290
+ NPY_INPLACE npy_longdouble npy_powl(npy_longdouble x, npy_longdouble y);
291
+ NPY_INPLACE npy_longdouble npy_modfl(npy_longdouble x, npy_longdouble* y);
292
+
293
+ /* Mandatory C99 double math funcs, no blocklisting or fixups */
294
+ /* defined for legacy reasons, should be deprecated at some point */
295
+ #define npy_sinhl sinhl
296
+ #define npy_coshl coshl
297
+ #define npy_tanhl tanhl
298
+ #define npy_fabsl fabsl
299
+ #define npy_floorl floorl
300
+ #define npy_ceill ceill
301
+ #define npy_rintl rintl
302
+ #define npy_truncl truncl
303
+ #define npy_cbrtl cbrtl
304
+ #define npy_log10l log10l
305
+ #define npy_logl logl
306
+ #define npy_expm1l expm1l
307
+ #define npy_asinl asinl
308
+ #define npy_acosl acosl
309
+ #define npy_atanl atanl
310
+ #define npy_asinhl asinhl
311
+ #define npy_acoshl acoshl
312
+ #define npy_atanhl atanhl
313
+ #define npy_log1pl log1pl
314
+ #define npy_exp2l exp2l
315
+ #define npy_fmodl fmodl
316
+ #define npy_frexpl frexpl
317
+ #define npy_ldexpl ldexpl
318
+ #define npy_copysignl copysignl
319
+ #define npy_nextafterl nextafterl
320
+
321
+ npy_longdouble npy_spacingl(npy_longdouble x);
322
+
323
+ /*
324
+ * Non standard functions
325
+ */
326
+ NPY_INPLACE double npy_deg2rad(double x);
327
+ NPY_INPLACE double npy_rad2deg(double x);
328
+ NPY_INPLACE double npy_logaddexp(double x, double y);
329
+ NPY_INPLACE double npy_logaddexp2(double x, double y);
330
+ NPY_INPLACE double npy_divmod(double x, double y, double *modulus);
331
+ NPY_INPLACE double npy_heaviside(double x, double h0);
332
+
333
+ NPY_INPLACE float npy_deg2radf(float x);
334
+ NPY_INPLACE float npy_rad2degf(float x);
335
+ NPY_INPLACE float npy_logaddexpf(float x, float y);
336
+ NPY_INPLACE float npy_logaddexp2f(float x, float y);
337
+ NPY_INPLACE float npy_divmodf(float x, float y, float *modulus);
338
+ NPY_INPLACE float npy_heavisidef(float x, float h0);
339
+
340
+ NPY_INPLACE npy_longdouble npy_deg2radl(npy_longdouble x);
341
+ NPY_INPLACE npy_longdouble npy_rad2degl(npy_longdouble x);
342
+ NPY_INPLACE npy_longdouble npy_logaddexpl(npy_longdouble x, npy_longdouble y);
343
+ NPY_INPLACE npy_longdouble npy_logaddexp2l(npy_longdouble x, npy_longdouble y);
344
+ NPY_INPLACE npy_longdouble npy_divmodl(npy_longdouble x, npy_longdouble y,
345
+ npy_longdouble *modulus);
346
+ NPY_INPLACE npy_longdouble npy_heavisidel(npy_longdouble x, npy_longdouble h0);
347
+
348
+ #define npy_degrees npy_rad2deg
349
+ #define npy_degreesf npy_rad2degf
350
+ #define npy_degreesl npy_rad2degl
351
+
352
+ #define npy_radians npy_deg2rad
353
+ #define npy_radiansf npy_deg2radf
354
+ #define npy_radiansl npy_deg2radl
355
+
356
+ /*
357
+ * Complex declarations
358
+ */
359
+
360
+ /*
361
+ * C99 specifies that complex numbers have the same representation as
362
+ * an array of two elements, where the first element is the real part
363
+ * and the second element is the imaginary part.
364
+ */
365
+ #define __NPY_CPACK_IMP(x, y, type, ctype) \
366
+ union { \
367
+ ctype z; \
368
+ type a[2]; \
369
+ } z1; \
370
+ \
371
+ z1.a[0] = (x); \
372
+ z1.a[1] = (y); \
373
+ \
374
+ return z1.z;
375
+
376
+ static inline npy_cdouble npy_cpack(double x, double y)
377
+ {
378
+ __NPY_CPACK_IMP(x, y, double, npy_cdouble);
379
+ }
380
+
381
+ static inline npy_cfloat npy_cpackf(float x, float y)
382
+ {
383
+ __NPY_CPACK_IMP(x, y, float, npy_cfloat);
384
+ }
385
+
386
+ static inline npy_clongdouble npy_cpackl(npy_longdouble x, npy_longdouble y)
387
+ {
388
+ __NPY_CPACK_IMP(x, y, npy_longdouble, npy_clongdouble);
389
+ }
390
+ #undef __NPY_CPACK_IMP
391
+
392
+ /*
393
+ * Same remark as above, but in the other direction: extract first/second
394
+ * member of complex number, assuming a C99-compatible representation
395
+ *
396
+ * Those are defineds as static inline, and such as a reasonable compiler would
397
+ * most likely compile this to one or two instructions (on CISC at least)
398
+ */
399
+ #define __NPY_CEXTRACT_IMP(z, index, type, ctype) \
400
+ union { \
401
+ ctype z; \
402
+ type a[2]; \
403
+ } __z_repr; \
404
+ __z_repr.z = z; \
405
+ \
406
+ return __z_repr.a[index];
407
+
408
+ static inline double npy_creal(npy_cdouble z)
409
+ {
410
+ __NPY_CEXTRACT_IMP(z, 0, double, npy_cdouble);
411
+ }
412
+
413
+ static inline double npy_cimag(npy_cdouble z)
414
+ {
415
+ __NPY_CEXTRACT_IMP(z, 1, double, npy_cdouble);
416
+ }
417
+
418
+ static inline float npy_crealf(npy_cfloat z)
419
+ {
420
+ __NPY_CEXTRACT_IMP(z, 0, float, npy_cfloat);
421
+ }
422
+
423
+ static inline float npy_cimagf(npy_cfloat z)
424
+ {
425
+ __NPY_CEXTRACT_IMP(z, 1, float, npy_cfloat);
426
+ }
427
+
428
+ static inline npy_longdouble npy_creall(npy_clongdouble z)
429
+ {
430
+ __NPY_CEXTRACT_IMP(z, 0, npy_longdouble, npy_clongdouble);
431
+ }
432
+
433
+ static inline npy_longdouble npy_cimagl(npy_clongdouble z)
434
+ {
435
+ __NPY_CEXTRACT_IMP(z, 1, npy_longdouble, npy_clongdouble);
436
+ }
437
+ #undef __NPY_CEXTRACT_IMP
438
+
439
+ /*
440
+ * Double precision complex functions
441
+ */
442
+ double npy_cabs(npy_cdouble z);
443
+ double npy_carg(npy_cdouble z);
444
+
445
+ npy_cdouble npy_cexp(npy_cdouble z);
446
+ npy_cdouble npy_clog(npy_cdouble z);
447
+ npy_cdouble npy_cpow(npy_cdouble x, npy_cdouble y);
448
+
449
+ npy_cdouble npy_csqrt(npy_cdouble z);
450
+
451
+ npy_cdouble npy_ccos(npy_cdouble z);
452
+ npy_cdouble npy_csin(npy_cdouble z);
453
+ npy_cdouble npy_ctan(npy_cdouble z);
454
+
455
+ npy_cdouble npy_ccosh(npy_cdouble z);
456
+ npy_cdouble npy_csinh(npy_cdouble z);
457
+ npy_cdouble npy_ctanh(npy_cdouble z);
458
+
459
+ npy_cdouble npy_cacos(npy_cdouble z);
460
+ npy_cdouble npy_casin(npy_cdouble z);
461
+ npy_cdouble npy_catan(npy_cdouble z);
462
+
463
+ npy_cdouble npy_cacosh(npy_cdouble z);
464
+ npy_cdouble npy_casinh(npy_cdouble z);
465
+ npy_cdouble npy_catanh(npy_cdouble z);
466
+
467
+ /*
468
+ * Single precision complex functions
469
+ */
470
+ float npy_cabsf(npy_cfloat z);
471
+ float npy_cargf(npy_cfloat z);
472
+
473
+ npy_cfloat npy_cexpf(npy_cfloat z);
474
+ npy_cfloat npy_clogf(npy_cfloat z);
475
+ npy_cfloat npy_cpowf(npy_cfloat x, npy_cfloat y);
476
+
477
+ npy_cfloat npy_csqrtf(npy_cfloat z);
478
+
479
+ npy_cfloat npy_ccosf(npy_cfloat z);
480
+ npy_cfloat npy_csinf(npy_cfloat z);
481
+ npy_cfloat npy_ctanf(npy_cfloat z);
482
+
483
+ npy_cfloat npy_ccoshf(npy_cfloat z);
484
+ npy_cfloat npy_csinhf(npy_cfloat z);
485
+ npy_cfloat npy_ctanhf(npy_cfloat z);
486
+
487
+ npy_cfloat npy_cacosf(npy_cfloat z);
488
+ npy_cfloat npy_casinf(npy_cfloat z);
489
+ npy_cfloat npy_catanf(npy_cfloat z);
490
+
491
+ npy_cfloat npy_cacoshf(npy_cfloat z);
492
+ npy_cfloat npy_casinhf(npy_cfloat z);
493
+ npy_cfloat npy_catanhf(npy_cfloat z);
494
+
495
+
496
+ /*
497
+ * Extended precision complex functions
498
+ */
499
+ npy_longdouble npy_cabsl(npy_clongdouble z);
500
+ npy_longdouble npy_cargl(npy_clongdouble z);
501
+
502
+ npy_clongdouble npy_cexpl(npy_clongdouble z);
503
+ npy_clongdouble npy_clogl(npy_clongdouble z);
504
+ npy_clongdouble npy_cpowl(npy_clongdouble x, npy_clongdouble y);
505
+
506
+ npy_clongdouble npy_csqrtl(npy_clongdouble z);
507
+
508
+ npy_clongdouble npy_ccosl(npy_clongdouble z);
509
+ npy_clongdouble npy_csinl(npy_clongdouble z);
510
+ npy_clongdouble npy_ctanl(npy_clongdouble z);
511
+
512
+ npy_clongdouble npy_ccoshl(npy_clongdouble z);
513
+ npy_clongdouble npy_csinhl(npy_clongdouble z);
514
+ npy_clongdouble npy_ctanhl(npy_clongdouble z);
515
+
516
+ npy_clongdouble npy_cacosl(npy_clongdouble z);
517
+ npy_clongdouble npy_casinl(npy_clongdouble z);
518
+ npy_clongdouble npy_catanl(npy_clongdouble z);
519
+
520
+ npy_clongdouble npy_cacoshl(npy_clongdouble z);
521
+ npy_clongdouble npy_casinhl(npy_clongdouble z);
522
+ npy_clongdouble npy_catanhl(npy_clongdouble z);
523
+
524
+
525
+ /*
526
+ * Functions that set the floating point error
527
+ * status word.
528
+ */
529
+
530
+ /*
531
+ * platform-dependent code translates floating point
532
+ * status to an integer sum of these values
533
+ */
534
+ #define NPY_FPE_DIVIDEBYZERO 1
535
+ #define NPY_FPE_OVERFLOW 2
536
+ #define NPY_FPE_UNDERFLOW 4
537
+ #define NPY_FPE_INVALID 8
538
+
539
+ int npy_clear_floatstatus_barrier(char*);
540
+ int npy_get_floatstatus_barrier(char*);
541
+ /*
542
+ * use caution with these - clang and gcc8.1 are known to reorder calls
543
+ * to this form of the function which can defeat the check. The _barrier
544
+ * form of the call is preferable, where the argument is
545
+ * (char*)&local_variable
546
+ */
547
+ int npy_clear_floatstatus(void);
548
+ int npy_get_floatstatus(void);
549
+
550
+ void npy_set_floatstatus_divbyzero(void);
551
+ void npy_set_floatstatus_overflow(void);
552
+ void npy_set_floatstatus_underflow(void);
553
+ void npy_set_floatstatus_invalid(void);
554
+
555
+ #ifdef __cplusplus
556
+ }
557
+ #endif
558
+
559
+ #if NPY_INLINE_MATH
560
+ #include "npy_math_internal.h"
561
+ #endif
562
+
563
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_MATH_H_ */
moondream/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 */
moondream/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_ */
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/numpyconfig.h ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #undef NPY_SIZEOF_PY_INTPTR_T
20
+
21
+ #ifdef __LP64__
22
+ #define NPY_SIZEOF_LONG 8
23
+ #define NPY_SIZEOF_PY_INTPTR_T 8
24
+ #else
25
+ #define NPY_SIZEOF_LONG 4
26
+ #define NPY_SIZEOF_PY_INTPTR_T 4
27
+ #endif
28
+
29
+ #undef NPY_SIZEOF_LONGDOUBLE
30
+ #undef NPY_SIZEOF_COMPLEX_LONGDOUBLE
31
+ #ifdef HAVE_LDOUBLE_IEEE_DOUBLE_LE
32
+ #undef HAVE_LDOUBLE_IEEE_DOUBLE_LE
33
+ #endif
34
+ #ifdef HAVE_LDOUBLE_INTEL_EXTENDED_16_BYTES_LE
35
+ #undef HAVE_LDOUBLE_INTEL_EXTENDED_16_BYTES_LE
36
+ #endif
37
+
38
+ #if defined(__arm64__)
39
+ #define NPY_SIZEOF_LONGDOUBLE 8
40
+ #define NPY_SIZEOF_COMPLEX_LONGDOUBLE 16
41
+ #define HAVE_LDOUBLE_IEEE_DOUBLE_LE 1
42
+ #elif defined(__x86_64)
43
+ #define NPY_SIZEOF_LONGDOUBLE 16
44
+ #define NPY_SIZEOF_COMPLEX_LONGDOUBLE 32
45
+ #define HAVE_LDOUBLE_INTEL_EXTENDED_16_BYTES_LE 1
46
+ #elif defined (__i386)
47
+ #define NPY_SIZEOF_LONGDOUBLE 12
48
+ #define NPY_SIZEOF_COMPLEX_LONGDOUBLE 24
49
+ #elif defined(__ppc__) || defined (__ppc64__)
50
+ #define NPY_SIZEOF_LONGDOUBLE 16
51
+ #define NPY_SIZEOF_COMPLEX_LONGDOUBLE 32
52
+ #else
53
+ #error "unknown architecture"
54
+ #endif
55
+ #endif
56
+
57
+
58
+ /**
59
+ * To help with both NPY_TARGET_VERSION and the NPY_NO_DEPRECATED_API macro,
60
+ * we include API version numbers for specific versions of NumPy.
61
+ * To exclude all API that was deprecated as of 1.7, add the following before
62
+ * #including any NumPy headers:
63
+ * #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
64
+ * The same is true for NPY_TARGET_VERSION, although NumPy will default to
65
+ * a backwards compatible build anyway.
66
+ */
67
+ #define NPY_1_7_API_VERSION 0x00000007
68
+ #define NPY_1_8_API_VERSION 0x00000008
69
+ #define NPY_1_9_API_VERSION 0x00000009
70
+ #define NPY_1_10_API_VERSION 0x0000000a
71
+ #define NPY_1_11_API_VERSION 0x0000000a
72
+ #define NPY_1_12_API_VERSION 0x0000000a
73
+ #define NPY_1_13_API_VERSION 0x0000000b
74
+ #define NPY_1_14_API_VERSION 0x0000000c
75
+ #define NPY_1_15_API_VERSION 0x0000000c
76
+ #define NPY_1_16_API_VERSION 0x0000000d
77
+ #define NPY_1_17_API_VERSION 0x0000000d
78
+ #define NPY_1_18_API_VERSION 0x0000000d
79
+ #define NPY_1_19_API_VERSION 0x0000000d
80
+ #define NPY_1_20_API_VERSION 0x0000000e
81
+ #define NPY_1_21_API_VERSION 0x0000000e
82
+ #define NPY_1_22_API_VERSION 0x0000000f
83
+ #define NPY_1_23_API_VERSION 0x00000010
84
+ #define NPY_1_24_API_VERSION 0x00000010
85
+ #define NPY_1_25_API_VERSION 0x00000011
86
+
87
+
88
+ /*
89
+ * Binary compatibility version number. This number is increased
90
+ * whenever the C-API is changed such that binary compatibility is
91
+ * broken, i.e. whenever a recompile of extension modules is needed.
92
+ */
93
+ #define NPY_VERSION NPY_ABI_VERSION
94
+
95
+ /*
96
+ * Minor API version we are compiling to be compatible with. The version
97
+ * Number is always increased when the API changes via: `NPY_API_VERSION`
98
+ * (and should maybe just track the NumPy version).
99
+ *
100
+ * If we have an internal build, we always target the current version of
101
+ * course.
102
+ *
103
+ * For downstream users, we default to an older version to provide them with
104
+ * maximum compatibility by default. Downstream can choose to extend that
105
+ * default, or narrow it down if they wish to use newer API. If you adjust
106
+ * this, consider the Python version support (example for 1.25.x):
107
+ *
108
+ * NumPy 1.25.x supports Python: 3.9 3.10 3.11 (3.12)
109
+ * NumPy 1.19.x supports Python: 3.6 3.7 3.8 3.9
110
+ * NumPy 1.17.x supports Python: 3.5 3.6 3.7 3.8
111
+ * NumPy 1.15.x supports Python: ... 3.6 3.7
112
+ *
113
+ * Users of the stable ABI may wish to target the last Python that is not
114
+ * end of life. This would be 3.8 at NumPy 1.25 release time.
115
+ * 1.17 as default was the choice of oldest-support-numpy at the time and
116
+ * has in practice no limit (comapared to 1.19). Even earlier becomes legacy.
117
+ */
118
+ #if defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD
119
+ /* NumPy internal build, always use current version. */
120
+ #define NPY_FEATURE_VERSION NPY_API_VERSION
121
+ #elif defined(NPY_TARGET_VERSION) && NPY_TARGET_VERSION
122
+ /* user provided a target version, use it */
123
+ #define NPY_FEATURE_VERSION NPY_TARGET_VERSION
124
+ #else
125
+ /* Use the default (increase when dropping Python 3.9 support) */
126
+ #define NPY_FEATURE_VERSION NPY_1_19_API_VERSION
127
+ #endif
128
+
129
+ /* Sanity check the (requested) feature version */
130
+ #if NPY_FEATURE_VERSION > NPY_API_VERSION
131
+ #error "NPY_TARGET_VERSION higher than NumPy headers!"
132
+ #elif NPY_FEATURE_VERSION < NPY_1_15_API_VERSION
133
+ /* No support for irrelevant old targets, no need for error, but warn. */
134
+ #warning "Requested NumPy target lower than supported NumPy 1.15."
135
+ #endif
136
+
137
+
138
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_NUMPYCONFIG_H_ */
moondream/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.
moondream/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_ */
moondream/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_ */
moondream/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_
moondream/lib/python3.10/site-packages/numpy/core/include/numpy/ufuncobject.h ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Legacy loop selector. (This should NOT normally be used and we can expect
70
+ * that only the `PyUFunc_DefaultLegacyInnerLoopSelector` is ever set).
71
+ * However, unlike the masked version, it probably still works.
72
+ *
73
+ * ufunc: The ufunc object.
74
+ * dtypes: An array which has been populated with dtypes,
75
+ * in most cases by the type resolution function
76
+ * for the same ufunc.
77
+ * out_innerloop: Should be populated with the correct ufunc inner
78
+ * loop for the given type.
79
+ * out_innerloopdata: Should be populated with the void* data to
80
+ * be passed into the out_innerloop function.
81
+ * out_needs_api: If the inner loop needs to use the Python API,
82
+ * should set the to 1, otherwise should leave
83
+ * this untouched.
84
+ */
85
+ typedef int (PyUFunc_LegacyInnerLoopSelectionFunc)(
86
+ struct _tagPyUFuncObject *ufunc,
87
+ PyArray_Descr **dtypes,
88
+ PyUFuncGenericFunction *out_innerloop,
89
+ void **out_innerloopdata,
90
+ int *out_needs_api);
91
+
92
+
93
+ typedef struct _tagPyUFuncObject {
94
+ PyObject_HEAD
95
+ /*
96
+ * nin: Number of inputs
97
+ * nout: Number of outputs
98
+ * nargs: Always nin + nout (Why is it stored?)
99
+ */
100
+ int nin, nout, nargs;
101
+
102
+ /*
103
+ * Identity for reduction, any of PyUFunc_One, PyUFunc_Zero
104
+ * PyUFunc_MinusOne, PyUFunc_None, PyUFunc_ReorderableNone,
105
+ * PyUFunc_IdentityValue.
106
+ */
107
+ int identity;
108
+
109
+ /* Array of one-dimensional core loops */
110
+ PyUFuncGenericFunction *functions;
111
+ /* Array of funcdata that gets passed into the functions */
112
+ void **data;
113
+ /* The number of elements in 'functions' and 'data' */
114
+ int ntypes;
115
+
116
+ /* Used to be unused field 'check_return' */
117
+ int reserved1;
118
+
119
+ /* The name of the ufunc */
120
+ const char *name;
121
+
122
+ /* Array of type numbers, of size ('nargs' * 'ntypes') */
123
+ char *types;
124
+
125
+ /* Documentation string */
126
+ const char *doc;
127
+
128
+ void *ptr;
129
+ PyObject *obj;
130
+ PyObject *userloops;
131
+
132
+ /* generalized ufunc parameters */
133
+
134
+ /* 0 for scalar ufunc; 1 for generalized ufunc */
135
+ int core_enabled;
136
+ /* number of distinct dimension names in signature */
137
+ int core_num_dim_ix;
138
+
139
+ /*
140
+ * dimension indices of input/output argument k are stored in
141
+ * core_dim_ixs[core_offsets[k]..core_offsets[k]+core_num_dims[k]-1]
142
+ */
143
+
144
+ /* numbers of core dimensions of each argument */
145
+ int *core_num_dims;
146
+ /*
147
+ * dimension indices in a flatted form; indices
148
+ * are in the range of [0,core_num_dim_ix)
149
+ */
150
+ int *core_dim_ixs;
151
+ /*
152
+ * positions of 1st core dimensions of each
153
+ * argument in core_dim_ixs, equivalent to cumsum(core_num_dims)
154
+ */
155
+ int *core_offsets;
156
+ /* signature string for printing purpose */
157
+ char *core_signature;
158
+
159
+ /*
160
+ * A function which resolves the types and fills an array
161
+ * with the dtypes for the inputs and outputs.
162
+ */
163
+ PyUFunc_TypeResolutionFunc *type_resolver;
164
+ /*
165
+ * A function which returns an inner loop written for
166
+ * NumPy 1.6 and earlier ufuncs. This is for backwards
167
+ * compatibility, and may be NULL if inner_loop_selector
168
+ * is specified.
169
+ */
170
+ PyUFunc_LegacyInnerLoopSelectionFunc *legacy_inner_loop_selector;
171
+ /*
172
+ * This was blocked off to be the "new" inner loop selector in 1.7,
173
+ * but this was never implemented. (This is also why the above
174
+ * selector is called the "legacy" selector.)
175
+ */
176
+ #ifndef Py_LIMITED_API
177
+ vectorcallfunc vectorcall;
178
+ #else
179
+ void *vectorcall;
180
+ #endif
181
+
182
+ /* Was previously the `PyUFunc_MaskedInnerLoopSelectionFunc` */
183
+ void *_always_null_previously_masked_innerloop_selector;
184
+
185
+ /*
186
+ * List of flags for each operand when ufunc is called by nditer object.
187
+ * These flags will be used in addition to the default flags for each
188
+ * operand set by nditer object.
189
+ */
190
+ npy_uint32 *op_flags;
191
+
192
+ /*
193
+ * List of global flags used when ufunc is called by nditer object.
194
+ * These flags will be used in addition to the default global flags
195
+ * set by nditer object.
196
+ */
197
+ npy_uint32 iter_flags;
198
+
199
+ /* New in NPY_API_VERSION 0x0000000D and above */
200
+ #if NPY_FEATURE_VERSION >= NPY_1_16_API_VERSION
201
+ /*
202
+ * for each core_num_dim_ix distinct dimension names,
203
+ * the possible "frozen" size (-1 if not frozen).
204
+ */
205
+ npy_intp *core_dim_sizes;
206
+
207
+ /*
208
+ * for each distinct core dimension, a set of UFUNC_CORE_DIM* flags
209
+ */
210
+ npy_uint32 *core_dim_flags;
211
+
212
+ /* Identity for reduction, when identity == PyUFunc_IdentityValue */
213
+ PyObject *identity_value;
214
+ #endif /* NPY_FEATURE_VERSION >= NPY_1_16_API_VERSION */
215
+
216
+ /* New in NPY_API_VERSION 0x0000000F and above */
217
+ #if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
218
+ /* New private fields related to dispatching */
219
+ void *_dispatch_cache;
220
+ /* A PyListObject of `(tuple of DTypes, ArrayMethod/Promoter)` */
221
+ PyObject *_loops;
222
+ #endif
223
+ } PyUFuncObject;
224
+
225
+ #include "arrayobject.h"
226
+ /* Generalized ufunc; 0x0001 reserved for possible use as CORE_ENABLED */
227
+ /* the core dimension's size will be determined by the operands. */
228
+ #define UFUNC_CORE_DIM_SIZE_INFERRED 0x0002
229
+ /* the core dimension may be absent */
230
+ #define UFUNC_CORE_DIM_CAN_IGNORE 0x0004
231
+ /* flags inferred during execution */
232
+ #define UFUNC_CORE_DIM_MISSING 0x00040000
233
+
234
+ #define UFUNC_ERR_IGNORE 0
235
+ #define UFUNC_ERR_WARN 1
236
+ #define UFUNC_ERR_RAISE 2
237
+ #define UFUNC_ERR_CALL 3
238
+ #define UFUNC_ERR_PRINT 4
239
+ #define UFUNC_ERR_LOG 5
240
+
241
+ /* Python side integer mask */
242
+
243
+ #define UFUNC_MASK_DIVIDEBYZERO 0x07
244
+ #define UFUNC_MASK_OVERFLOW 0x3f
245
+ #define UFUNC_MASK_UNDERFLOW 0x1ff
246
+ #define UFUNC_MASK_INVALID 0xfff
247
+
248
+ #define UFUNC_SHIFT_DIVIDEBYZERO 0
249
+ #define UFUNC_SHIFT_OVERFLOW 3
250
+ #define UFUNC_SHIFT_UNDERFLOW 6
251
+ #define UFUNC_SHIFT_INVALID 9
252
+
253
+
254
+ #define UFUNC_OBJ_ISOBJECT 1
255
+ #define UFUNC_OBJ_NEEDS_API 2
256
+
257
+ /* Default user error mode */
258
+ #define UFUNC_ERR_DEFAULT \
259
+ (UFUNC_ERR_WARN << UFUNC_SHIFT_DIVIDEBYZERO) + \
260
+ (UFUNC_ERR_WARN << UFUNC_SHIFT_OVERFLOW) + \
261
+ (UFUNC_ERR_WARN << UFUNC_SHIFT_INVALID)
262
+
263
+ #if NPY_ALLOW_THREADS
264
+ #define NPY_LOOP_BEGIN_THREADS do {if (!(loop->obj & UFUNC_OBJ_NEEDS_API)) _save = PyEval_SaveThread();} while (0);
265
+ #define NPY_LOOP_END_THREADS do {if (!(loop->obj & UFUNC_OBJ_NEEDS_API)) PyEval_RestoreThread(_save);} while (0);
266
+ #else
267
+ #define NPY_LOOP_BEGIN_THREADS
268
+ #define NPY_LOOP_END_THREADS
269
+ #endif
270
+
271
+ /*
272
+ * UFunc has unit of 0, and the order of operations can be reordered
273
+ * This case allows reduction with multiple axes at once.
274
+ */
275
+ #define PyUFunc_Zero 0
276
+ /*
277
+ * UFunc has unit of 1, and the order of operations can be reordered
278
+ * This case allows reduction with multiple axes at once.
279
+ */
280
+ #define PyUFunc_One 1
281
+ /*
282
+ * UFunc has unit of -1, and the order of operations can be reordered
283
+ * This case allows reduction with multiple axes at once. Intended for
284
+ * bitwise_and reduction.
285
+ */
286
+ #define PyUFunc_MinusOne 2
287
+ /*
288
+ * UFunc has no unit, and the order of operations cannot be reordered.
289
+ * This case does not allow reduction with multiple axes at once.
290
+ */
291
+ #define PyUFunc_None -1
292
+ /*
293
+ * UFunc has no unit, and the order of operations can be reordered
294
+ * This case allows reduction with multiple axes at once.
295
+ */
296
+ #define PyUFunc_ReorderableNone -2
297
+ /*
298
+ * UFunc unit is an identity_value, and the order of operations can be reordered
299
+ * This case allows reduction with multiple axes at once.
300
+ */
301
+ #define PyUFunc_IdentityValue -3
302
+
303
+
304
+ #define UFUNC_REDUCE 0
305
+ #define UFUNC_ACCUMULATE 1
306
+ #define UFUNC_REDUCEAT 2
307
+ #define UFUNC_OUTER 3
308
+
309
+
310
+ typedef struct {
311
+ int nin;
312
+ int nout;
313
+ PyObject *callable;
314
+ } PyUFunc_PyFuncData;
315
+
316
+ /* A linked-list of function information for
317
+ user-defined 1-d loops.
318
+ */
319
+ typedef struct _loop1d_info {
320
+ PyUFuncGenericFunction func;
321
+ void *data;
322
+ int *arg_types;
323
+ struct _loop1d_info *next;
324
+ int nargs;
325
+ PyArray_Descr **arg_dtypes;
326
+ } PyUFunc_Loop1d;
327
+
328
+
329
+ #include "__ufunc_api.h"
330
+
331
+ #define UFUNC_PYVALS_NAME "UFUNC_PYVALS"
332
+
333
+ /*
334
+ * THESE MACROS ARE DEPRECATED.
335
+ * Use npy_set_floatstatus_* in the npymath library.
336
+ */
337
+ #define UFUNC_FPE_DIVIDEBYZERO NPY_FPE_DIVIDEBYZERO
338
+ #define UFUNC_FPE_OVERFLOW NPY_FPE_OVERFLOW
339
+ #define UFUNC_FPE_UNDERFLOW NPY_FPE_UNDERFLOW
340
+ #define UFUNC_FPE_INVALID NPY_FPE_INVALID
341
+
342
+ #define generate_divbyzero_error() npy_set_floatstatus_divbyzero()
343
+ #define generate_overflow_error() npy_set_floatstatus_overflow()
344
+
345
+ /* Make sure it gets defined if it isn't already */
346
+ #ifndef UFUNC_NOFPE
347
+ /* Clear the floating point exception default of Borland C++ */
348
+ #if defined(__BORLANDC__)
349
+ #define UFUNC_NOFPE _control87(MCW_EM, MCW_EM);
350
+ #else
351
+ #define UFUNC_NOFPE
352
+ #endif
353
+ #endif
354
+
355
+ #ifdef __cplusplus
356
+ }
357
+ #endif
358
+
359
+ #endif /* NUMPY_CORE_INCLUDE_NUMPY_UFUNCOBJECT_H_ */
moondream/lib/python3.10/site-packages/numpy/fft/__init__.py ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Discrete Fourier Transform (:mod:`numpy.fft`)
3
+ =============================================
4
+
5
+ .. currentmodule:: numpy.fft
6
+
7
+ The SciPy module `scipy.fft` is a more comprehensive superset
8
+ of ``numpy.fft``, which includes only a basic set of routines.
9
+
10
+ Standard FFTs
11
+ -------------
12
+
13
+ .. autosummary::
14
+ :toctree: generated/
15
+
16
+ fft Discrete Fourier transform.
17
+ ifft Inverse discrete Fourier transform.
18
+ fft2 Discrete Fourier transform in two dimensions.
19
+ ifft2 Inverse discrete Fourier transform in two dimensions.
20
+ fftn Discrete Fourier transform in N-dimensions.
21
+ ifftn Inverse discrete Fourier transform in N dimensions.
22
+
23
+ Real FFTs
24
+ ---------
25
+
26
+ .. autosummary::
27
+ :toctree: generated/
28
+
29
+ rfft Real discrete Fourier transform.
30
+ irfft Inverse real discrete Fourier transform.
31
+ rfft2 Real discrete Fourier transform in two dimensions.
32
+ irfft2 Inverse real discrete Fourier transform in two dimensions.
33
+ rfftn Real discrete Fourier transform in N dimensions.
34
+ irfftn Inverse real discrete Fourier transform in N dimensions.
35
+
36
+ Hermitian FFTs
37
+ --------------
38
+
39
+ .. autosummary::
40
+ :toctree: generated/
41
+
42
+ hfft Hermitian discrete Fourier transform.
43
+ ihfft Inverse Hermitian discrete Fourier transform.
44
+
45
+ Helper routines
46
+ ---------------
47
+
48
+ .. autosummary::
49
+ :toctree: generated/
50
+
51
+ fftfreq Discrete Fourier Transform sample frequencies.
52
+ rfftfreq DFT sample frequencies (for usage with rfft, irfft).
53
+ fftshift Shift zero-frequency component to center of spectrum.
54
+ ifftshift Inverse of fftshift.
55
+
56
+
57
+ Background information
58
+ ----------------------
59
+
60
+ Fourier analysis is fundamentally a method for expressing a function as a
61
+ sum of periodic components, and for recovering the function from those
62
+ components. When both the function and its Fourier transform are
63
+ replaced with discretized counterparts, it is called the discrete Fourier
64
+ transform (DFT). The DFT has become a mainstay of numerical computing in
65
+ part because of a very fast algorithm for computing it, called the Fast
66
+ Fourier Transform (FFT), which was known to Gauss (1805) and was brought
67
+ to light in its current form by Cooley and Tukey [CT]_. Press et al. [NR]_
68
+ provide an accessible introduction to Fourier analysis and its
69
+ applications.
70
+
71
+ Because the discrete Fourier transform separates its input into
72
+ components that contribute at discrete frequencies, it has a great number
73
+ of applications in digital signal processing, e.g., for filtering, and in
74
+ this context the discretized input to the transform is customarily
75
+ referred to as a *signal*, which exists in the *time domain*. The output
76
+ is called a *spectrum* or *transform* and exists in the *frequency
77
+ domain*.
78
+
79
+ Implementation details
80
+ ----------------------
81
+
82
+ There are many ways to define the DFT, varying in the sign of the
83
+ exponent, normalization, etc. In this implementation, the DFT is defined
84
+ as
85
+
86
+ .. math::
87
+ A_k = \\sum_{m=0}^{n-1} a_m \\exp\\left\\{-2\\pi i{mk \\over n}\\right\\}
88
+ \\qquad k = 0,\\ldots,n-1.
89
+
90
+ The DFT is in general defined for complex inputs and outputs, and a
91
+ single-frequency component at linear frequency :math:`f` is
92
+ represented by a complex exponential
93
+ :math:`a_m = \\exp\\{2\\pi i\\,f m\\Delta t\\}`, where :math:`\\Delta t`
94
+ is the sampling interval.
95
+
96
+ The values in the result follow so-called "standard" order: If ``A =
97
+ fft(a, n)``, then ``A[0]`` contains the zero-frequency term (the sum of
98
+ the signal), which is always purely real for real inputs. Then ``A[1:n/2]``
99
+ contains the positive-frequency terms, and ``A[n/2+1:]`` contains the
100
+ negative-frequency terms, in order of decreasingly negative frequency.
101
+ For an even number of input points, ``A[n/2]`` represents both positive and
102
+ negative Nyquist frequency, and is also purely real for real input. For
103
+ an odd number of input points, ``A[(n-1)/2]`` contains the largest positive
104
+ frequency, while ``A[(n+1)/2]`` contains the largest negative frequency.
105
+ The routine ``np.fft.fftfreq(n)`` returns an array giving the frequencies
106
+ of corresponding elements in the output. The routine
107
+ ``np.fft.fftshift(A)`` shifts transforms and their frequencies to put the
108
+ zero-frequency components in the middle, and ``np.fft.ifftshift(A)`` undoes
109
+ that shift.
110
+
111
+ When the input `a` is a time-domain signal and ``A = fft(a)``, ``np.abs(A)``
112
+ is its amplitude spectrum and ``np.abs(A)**2`` is its power spectrum.
113
+ The phase spectrum is obtained by ``np.angle(A)``.
114
+
115
+ The inverse DFT is defined as
116
+
117
+ .. math::
118
+ a_m = \\frac{1}{n}\\sum_{k=0}^{n-1}A_k\\exp\\left\\{2\\pi i{mk\\over n}\\right\\}
119
+ \\qquad m = 0,\\ldots,n-1.
120
+
121
+ It differs from the forward transform by the sign of the exponential
122
+ argument and the default normalization by :math:`1/n`.
123
+
124
+ Type Promotion
125
+ --------------
126
+
127
+ `numpy.fft` promotes ``float32`` and ``complex64`` arrays to ``float64`` and
128
+ ``complex128`` arrays respectively. For an FFT implementation that does not
129
+ promote input arrays, see `scipy.fftpack`.
130
+
131
+ Normalization
132
+ -------------
133
+
134
+ The argument ``norm`` indicates which direction of the pair of direct/inverse
135
+ transforms is scaled and with what normalization factor.
136
+ The default normalization (``"backward"``) has the direct (forward) transforms
137
+ unscaled and the inverse (backward) transforms scaled by :math:`1/n`. It is
138
+ possible to obtain unitary transforms by setting the keyword argument ``norm``
139
+ to ``"ortho"`` so that both direct and inverse transforms are scaled by
140
+ :math:`1/\\sqrt{n}`. Finally, setting the keyword argument ``norm`` to
141
+ ``"forward"`` has the direct transforms scaled by :math:`1/n` and the inverse
142
+ transforms unscaled (i.e. exactly opposite to the default ``"backward"``).
143
+ `None` is an alias of the default option ``"backward"`` for backward
144
+ compatibility.
145
+
146
+ Real and Hermitian transforms
147
+ -----------------------------
148
+
149
+ When the input is purely real, its transform is Hermitian, i.e., the
150
+ component at frequency :math:`f_k` is the complex conjugate of the
151
+ component at frequency :math:`-f_k`, which means that for real
152
+ inputs there is no information in the negative frequency components that
153
+ is not already available from the positive frequency components.
154
+ The family of `rfft` functions is
155
+ designed to operate on real inputs, and exploits this symmetry by
156
+ computing only the positive frequency components, up to and including the
157
+ Nyquist frequency. Thus, ``n`` input points produce ``n/2+1`` complex
158
+ output points. The inverses of this family assumes the same symmetry of
159
+ its input, and for an output of ``n`` points uses ``n/2+1`` input points.
160
+
161
+ Correspondingly, when the spectrum is purely real, the signal is
162
+ Hermitian. The `hfft` family of functions exploits this symmetry by
163
+ using ``n/2+1`` complex points in the input (time) domain for ``n`` real
164
+ points in the frequency domain.
165
+
166
+ In higher dimensions, FFTs are used, e.g., for image analysis and
167
+ filtering. The computational efficiency of the FFT means that it can
168
+ also be a faster way to compute large convolutions, using the property
169
+ that a convolution in the time domain is equivalent to a point-by-point
170
+ multiplication in the frequency domain.
171
+
172
+ Higher dimensions
173
+ -----------------
174
+
175
+ In two dimensions, the DFT is defined as
176
+
177
+ .. math::
178
+ A_{kl} = \\sum_{m=0}^{M-1} \\sum_{n=0}^{N-1}
179
+ a_{mn}\\exp\\left\\{-2\\pi i \\left({mk\\over M}+{nl\\over N}\\right)\\right\\}
180
+ \\qquad k = 0, \\ldots, M-1;\\quad l = 0, \\ldots, N-1,
181
+
182
+ which extends in the obvious way to higher dimensions, and the inverses
183
+ in higher dimensions also extend in the same way.
184
+
185
+ References
186
+ ----------
187
+
188
+ .. [CT] Cooley, James W., and John W. Tukey, 1965, "An algorithm for the
189
+ machine calculation of complex Fourier series," *Math. Comput.*
190
+ 19: 297-301.
191
+
192
+ .. [NR] Press, W., Teukolsky, S., Vetterline, W.T., and Flannery, B.P.,
193
+ 2007, *Numerical Recipes: The Art of Scientific Computing*, ch.
194
+ 12-13. Cambridge Univ. Press, Cambridge, UK.
195
+
196
+ Examples
197
+ --------
198
+
199
+ For examples, see the various functions.
200
+
201
+ """
202
+
203
+ from . import _pocketfft, helper
204
+ from ._pocketfft import *
205
+ from .helper import *
206
+
207
+ __all__ = _pocketfft.__all__.copy()
208
+ __all__ += helper.__all__
209
+
210
+ from numpy._pytesttester import PytestTester
211
+ test = PytestTester(__name__)
212
+ del PytestTester
moondream/lib/python3.10/site-packages/numpy/fft/__init__.pyi ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from numpy._pytesttester import PytestTester
2
+
3
+ from numpy.fft._pocketfft import (
4
+ fft as fft,
5
+ ifft as ifft,
6
+ rfft as rfft,
7
+ irfft as irfft,
8
+ hfft as hfft,
9
+ ihfft as ihfft,
10
+ rfftn as rfftn,
11
+ irfftn as irfftn,
12
+ rfft2 as rfft2,
13
+ irfft2 as irfft2,
14
+ fft2 as fft2,
15
+ ifft2 as ifft2,
16
+ fftn as fftn,
17
+ ifftn as ifftn,
18
+ )
19
+
20
+ from numpy.fft.helper import (
21
+ fftshift as fftshift,
22
+ ifftshift as ifftshift,
23
+ fftfreq as fftfreq,
24
+ rfftfreq as rfftfreq,
25
+ )
26
+
27
+ __all__: list[str]
28
+ __path__: list[str]
29
+ test: PytestTester
moondream/lib/python3.10/site-packages/numpy/fft/__pycache__/_pocketfft.cpython-310.pyc ADDED
Binary file (51.8 kB). View file
 
moondream/lib/python3.10/site-packages/numpy/fft/__pycache__/helper.cpython-310.pyc ADDED
Binary file (6.68 kB). View file
 
moondream/lib/python3.10/site-packages/numpy/fft/_pocketfft.py ADDED
@@ -0,0 +1,1424 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Discrete Fourier Transforms
3
+
4
+ Routines in this module:
5
+
6
+ fft(a, n=None, axis=-1, norm="backward")
7
+ ifft(a, n=None, axis=-1, norm="backward")
8
+ rfft(a, n=None, axis=-1, norm="backward")
9
+ irfft(a, n=None, axis=-1, norm="backward")
10
+ hfft(a, n=None, axis=-1, norm="backward")
11
+ ihfft(a, n=None, axis=-1, norm="backward")
12
+ fftn(a, s=None, axes=None, norm="backward")
13
+ ifftn(a, s=None, axes=None, norm="backward")
14
+ rfftn(a, s=None, axes=None, norm="backward")
15
+ irfftn(a, s=None, axes=None, norm="backward")
16
+ fft2(a, s=None, axes=(-2,-1), norm="backward")
17
+ ifft2(a, s=None, axes=(-2, -1), norm="backward")
18
+ rfft2(a, s=None, axes=(-2,-1), norm="backward")
19
+ irfft2(a, s=None, axes=(-2, -1), norm="backward")
20
+
21
+ i = inverse transform
22
+ r = transform of purely real data
23
+ h = Hermite transform
24
+ n = n-dimensional transform
25
+ 2 = 2-dimensional transform
26
+ (Note: 2D routines are just nD routines with different default
27
+ behavior.)
28
+
29
+ """
30
+ __all__ = ['fft', 'ifft', 'rfft', 'irfft', 'hfft', 'ihfft', 'rfftn',
31
+ 'irfftn', 'rfft2', 'irfft2', 'fft2', 'ifft2', 'fftn', 'ifftn']
32
+
33
+ import functools
34
+
35
+ from numpy.core import asarray, zeros, swapaxes, conjugate, take, sqrt
36
+ from . import _pocketfft_internal as pfi
37
+ from numpy.core.multiarray import normalize_axis_index
38
+ from numpy.core import overrides
39
+
40
+
41
+ array_function_dispatch = functools.partial(
42
+ overrides.array_function_dispatch, module='numpy.fft')
43
+
44
+
45
+ # `inv_norm` is a float by which the result of the transform needs to be
46
+ # divided. This replaces the original, more intuitive 'fct` parameter to avoid
47
+ # divisions by zero (or alternatively additional checks) in the case of
48
+ # zero-length axes during its computation.
49
+ def _raw_fft(a, n, axis, is_real, is_forward, inv_norm):
50
+ axis = normalize_axis_index(axis, a.ndim)
51
+ if n is None:
52
+ n = a.shape[axis]
53
+
54
+ fct = 1/inv_norm
55
+
56
+ if a.shape[axis] != n:
57
+ s = list(a.shape)
58
+ index = [slice(None)]*len(s)
59
+ if s[axis] > n:
60
+ index[axis] = slice(0, n)
61
+ a = a[tuple(index)]
62
+ else:
63
+ index[axis] = slice(0, s[axis])
64
+ s[axis] = n
65
+ z = zeros(s, a.dtype.char)
66
+ z[tuple(index)] = a
67
+ a = z
68
+
69
+ if axis == a.ndim-1:
70
+ r = pfi.execute(a, is_real, is_forward, fct)
71
+ else:
72
+ a = swapaxes(a, axis, -1)
73
+ r = pfi.execute(a, is_real, is_forward, fct)
74
+ r = swapaxes(r, axis, -1)
75
+ return r
76
+
77
+
78
+ def _get_forward_norm(n, norm):
79
+ if n < 1:
80
+ raise ValueError(f"Invalid number of FFT data points ({n}) specified.")
81
+
82
+ if norm is None or norm == "backward":
83
+ return 1
84
+ elif norm == "ortho":
85
+ return sqrt(n)
86
+ elif norm == "forward":
87
+ return n
88
+ raise ValueError(f'Invalid norm value {norm}; should be "backward",'
89
+ '"ortho" or "forward".')
90
+
91
+
92
+ def _get_backward_norm(n, norm):
93
+ if n < 1:
94
+ raise ValueError(f"Invalid number of FFT data points ({n}) specified.")
95
+
96
+ if norm is None or norm == "backward":
97
+ return n
98
+ elif norm == "ortho":
99
+ return sqrt(n)
100
+ elif norm == "forward":
101
+ return 1
102
+ raise ValueError(f'Invalid norm value {norm}; should be "backward", '
103
+ '"ortho" or "forward".')
104
+
105
+
106
+ _SWAP_DIRECTION_MAP = {"backward": "forward", None: "forward",
107
+ "ortho": "ortho", "forward": "backward"}
108
+
109
+
110
+ def _swap_direction(norm):
111
+ try:
112
+ return _SWAP_DIRECTION_MAP[norm]
113
+ except KeyError:
114
+ raise ValueError(f'Invalid norm value {norm}; should be "backward", '
115
+ '"ortho" or "forward".') from None
116
+
117
+
118
+ def _fft_dispatcher(a, n=None, axis=None, norm=None):
119
+ return (a,)
120
+
121
+
122
+ @array_function_dispatch(_fft_dispatcher)
123
+ def fft(a, n=None, axis=-1, norm=None):
124
+ """
125
+ Compute the one-dimensional discrete Fourier Transform.
126
+
127
+ This function computes the one-dimensional *n*-point discrete Fourier
128
+ Transform (DFT) with the efficient Fast Fourier Transform (FFT)
129
+ algorithm [CT].
130
+
131
+ Parameters
132
+ ----------
133
+ a : array_like
134
+ Input array, can be complex.
135
+ n : int, optional
136
+ Length of the transformed axis of the output.
137
+ If `n` is smaller than the length of the input, the input is cropped.
138
+ If it is larger, the input is padded with zeros. If `n` is not given,
139
+ the length of the input along the axis specified by `axis` is used.
140
+ axis : int, optional
141
+ Axis over which to compute the FFT. If not given, the last axis is
142
+ used.
143
+ norm : {"backward", "ortho", "forward"}, optional
144
+ .. versionadded:: 1.10.0
145
+
146
+ Normalization mode (see `numpy.fft`). Default is "backward".
147
+ Indicates which direction of the forward/backward pair of transforms
148
+ is scaled and with what normalization factor.
149
+
150
+ .. versionadded:: 1.20.0
151
+
152
+ The "backward", "forward" values were added.
153
+
154
+ Returns
155
+ -------
156
+ out : complex ndarray
157
+ The truncated or zero-padded input, transformed along the axis
158
+ indicated by `axis`, or the last one if `axis` is not specified.
159
+
160
+ Raises
161
+ ------
162
+ IndexError
163
+ If `axis` is not a valid axis of `a`.
164
+
165
+ See Also
166
+ --------
167
+ numpy.fft : for definition of the DFT and conventions used.
168
+ ifft : The inverse of `fft`.
169
+ fft2 : The two-dimensional FFT.
170
+ fftn : The *n*-dimensional FFT.
171
+ rfftn : The *n*-dimensional FFT of real input.
172
+ fftfreq : Frequency bins for given FFT parameters.
173
+
174
+ Notes
175
+ -----
176
+ FFT (Fast Fourier Transform) refers to a way the discrete Fourier
177
+ Transform (DFT) can be calculated efficiently, by using symmetries in the
178
+ calculated terms. The symmetry is highest when `n` is a power of 2, and
179
+ the transform is therefore most efficient for these sizes.
180
+
181
+ The DFT is defined, with the conventions used in this implementation, in
182
+ the documentation for the `numpy.fft` module.
183
+
184
+ References
185
+ ----------
186
+ .. [CT] Cooley, James W., and John W. Tukey, 1965, "An algorithm for the
187
+ machine calculation of complex Fourier series," *Math. Comput.*
188
+ 19: 297-301.
189
+
190
+ Examples
191
+ --------
192
+ >>> np.fft.fft(np.exp(2j * np.pi * np.arange(8) / 8))
193
+ array([-2.33486982e-16+1.14423775e-17j, 8.00000000e+00-1.25557246e-15j,
194
+ 2.33486982e-16+2.33486982e-16j, 0.00000000e+00+1.22464680e-16j,
195
+ -1.14423775e-17+2.33486982e-16j, 0.00000000e+00+5.20784380e-16j,
196
+ 1.14423775e-17+1.14423775e-17j, 0.00000000e+00+1.22464680e-16j])
197
+
198
+ In this example, real input has an FFT which is Hermitian, i.e., symmetric
199
+ in the real part and anti-symmetric in the imaginary part, as described in
200
+ the `numpy.fft` documentation:
201
+
202
+ >>> import matplotlib.pyplot as plt
203
+ >>> t = np.arange(256)
204
+ >>> sp = np.fft.fft(np.sin(t))
205
+ >>> freq = np.fft.fftfreq(t.shape[-1])
206
+ >>> plt.plot(freq, sp.real, freq, sp.imag)
207
+ [<matplotlib.lines.Line2D object at 0x...>, <matplotlib.lines.Line2D object at 0x...>]
208
+ >>> plt.show()
209
+
210
+ """
211
+ a = asarray(a)
212
+ if n is None:
213
+ n = a.shape[axis]
214
+ inv_norm = _get_forward_norm(n, norm)
215
+ output = _raw_fft(a, n, axis, False, True, inv_norm)
216
+ return output
217
+
218
+
219
+ @array_function_dispatch(_fft_dispatcher)
220
+ def ifft(a, n=None, axis=-1, norm=None):
221
+ """
222
+ Compute the one-dimensional inverse discrete Fourier Transform.
223
+
224
+ This function computes the inverse of the one-dimensional *n*-point
225
+ discrete Fourier transform computed by `fft`. In other words,
226
+ ``ifft(fft(a)) == a`` to within numerical accuracy.
227
+ For a general description of the algorithm and definitions,
228
+ see `numpy.fft`.
229
+
230
+ The input should be ordered in the same way as is returned by `fft`,
231
+ i.e.,
232
+
233
+ * ``a[0]`` should contain the zero frequency term,
234
+ * ``a[1:n//2]`` should contain the positive-frequency terms,
235
+ * ``a[n//2 + 1:]`` should contain the negative-frequency terms, in
236
+ increasing order starting from the most negative frequency.
237
+
238
+ For an even number of input points, ``A[n//2]`` represents the sum of
239
+ the values at the positive and negative Nyquist frequencies, as the two
240
+ are aliased together. See `numpy.fft` for details.
241
+
242
+ Parameters
243
+ ----------
244
+ a : array_like
245
+ Input array, can be complex.
246
+ n : int, optional
247
+ Length of the transformed axis of the output.
248
+ If `n` is smaller than the length of the input, the input is cropped.
249
+ If it is larger, the input is padded with zeros. If `n` is not given,
250
+ the length of the input along the axis specified by `axis` is used.
251
+ See notes about padding issues.
252
+ axis : int, optional
253
+ Axis over which to compute the inverse DFT. If not given, the last
254
+ axis is used.
255
+ norm : {"backward", "ortho", "forward"}, optional
256
+ .. versionadded:: 1.10.0
257
+
258
+ Normalization mode (see `numpy.fft`). Default is "backward".
259
+ Indicates which direction of the forward/backward pair of transforms
260
+ is scaled and with what normalization factor.
261
+
262
+ .. versionadded:: 1.20.0
263
+
264
+ The "backward", "forward" values were added.
265
+
266
+ Returns
267
+ -------
268
+ out : complex ndarray
269
+ The truncated or zero-padded input, transformed along the axis
270
+ indicated by `axis`, or the last one if `axis` is not specified.
271
+
272
+ Raises
273
+ ------
274
+ IndexError
275
+ If `axis` is not a valid axis of `a`.
276
+
277
+ See Also
278
+ --------
279
+ numpy.fft : An introduction, with definitions and general explanations.
280
+ fft : The one-dimensional (forward) FFT, of which `ifft` is the inverse
281
+ ifft2 : The two-dimensional inverse FFT.
282
+ ifftn : The n-dimensional inverse FFT.
283
+
284
+ Notes
285
+ -----
286
+ If the input parameter `n` is larger than the size of the input, the input
287
+ is padded by appending zeros at the end. Even though this is the common
288
+ approach, it might lead to surprising results. If a different padding is
289
+ desired, it must be performed before calling `ifft`.
290
+
291
+ Examples
292
+ --------
293
+ >>> np.fft.ifft([0, 4, 0, 0])
294
+ array([ 1.+0.j, 0.+1.j, -1.+0.j, 0.-1.j]) # may vary
295
+
296
+ Create and plot a band-limited signal with random phases:
297
+
298
+ >>> import matplotlib.pyplot as plt
299
+ >>> t = np.arange(400)
300
+ >>> n = np.zeros((400,), dtype=complex)
301
+ >>> n[40:60] = np.exp(1j*np.random.uniform(0, 2*np.pi, (20,)))
302
+ >>> s = np.fft.ifft(n)
303
+ >>> plt.plot(t, s.real, label='real')
304
+ [<matplotlib.lines.Line2D object at ...>]
305
+ >>> plt.plot(t, s.imag, '--', label='imaginary')
306
+ [<matplotlib.lines.Line2D object at ...>]
307
+ >>> plt.legend()
308
+ <matplotlib.legend.Legend object at ...>
309
+ >>> plt.show()
310
+
311
+ """
312
+ a = asarray(a)
313
+ if n is None:
314
+ n = a.shape[axis]
315
+ inv_norm = _get_backward_norm(n, norm)
316
+ output = _raw_fft(a, n, axis, False, False, inv_norm)
317
+ return output
318
+
319
+
320
+ @array_function_dispatch(_fft_dispatcher)
321
+ def rfft(a, n=None, axis=-1, norm=None):
322
+ """
323
+ Compute the one-dimensional discrete Fourier Transform for real input.
324
+
325
+ This function computes the one-dimensional *n*-point discrete Fourier
326
+ Transform (DFT) of a real-valued array by means of an efficient algorithm
327
+ called the Fast Fourier Transform (FFT).
328
+
329
+ Parameters
330
+ ----------
331
+ a : array_like
332
+ Input array
333
+ n : int, optional
334
+ Number of points along transformation axis in the input to use.
335
+ If `n` is smaller than the length of the input, the input is cropped.
336
+ If it is larger, the input is padded with zeros. If `n` is not given,
337
+ the length of the input along the axis specified by `axis` is used.
338
+ axis : int, optional
339
+ Axis over which to compute the FFT. If not given, the last axis is
340
+ used.
341
+ norm : {"backward", "ortho", "forward"}, optional
342
+ .. versionadded:: 1.10.0
343
+
344
+ Normalization mode (see `numpy.fft`). Default is "backward".
345
+ Indicates which direction of the forward/backward pair of transforms
346
+ is scaled and with what normalization factor.
347
+
348
+ .. versionadded:: 1.20.0
349
+
350
+ The "backward", "forward" values were added.
351
+
352
+ Returns
353
+ -------
354
+ out : complex ndarray
355
+ The truncated or zero-padded input, transformed along the axis
356
+ indicated by `axis`, or the last one if `axis` is not specified.
357
+ If `n` is even, the length of the transformed axis is ``(n/2)+1``.
358
+ If `n` is odd, the length is ``(n+1)/2``.
359
+
360
+ Raises
361
+ ------
362
+ IndexError
363
+ If `axis` is not a valid axis of `a`.
364
+
365
+ See Also
366
+ --------
367
+ numpy.fft : For definition of the DFT and conventions used.
368
+ irfft : The inverse of `rfft`.
369
+ fft : The one-dimensional FFT of general (complex) input.
370
+ fftn : The *n*-dimensional FFT.
371
+ rfftn : The *n*-dimensional FFT of real input.
372
+
373
+ Notes
374
+ -----
375
+ When the DFT is computed for purely real input, the output is
376
+ Hermitian-symmetric, i.e. the negative frequency terms are just the complex
377
+ conjugates of the corresponding positive-frequency terms, and the
378
+ negative-frequency terms are therefore redundant. This function does not
379
+ compute the negative frequency terms, and the length of the transformed
380
+ axis of the output is therefore ``n//2 + 1``.
381
+
382
+ When ``A = rfft(a)`` and fs is the sampling frequency, ``A[0]`` contains
383
+ the zero-frequency term 0*fs, which is real due to Hermitian symmetry.
384
+
385
+ If `n` is even, ``A[-1]`` contains the term representing both positive
386
+ and negative Nyquist frequency (+fs/2 and -fs/2), and must also be purely
387
+ real. If `n` is odd, there is no term at fs/2; ``A[-1]`` contains
388
+ the largest positive frequency (fs/2*(n-1)/n), and is complex in the
389
+ general case.
390
+
391
+ If the input `a` contains an imaginary part, it is silently discarded.
392
+
393
+ Examples
394
+ --------
395
+ >>> np.fft.fft([0, 1, 0, 0])
396
+ array([ 1.+0.j, 0.-1.j, -1.+0.j, 0.+1.j]) # may vary
397
+ >>> np.fft.rfft([0, 1, 0, 0])
398
+ array([ 1.+0.j, 0.-1.j, -1.+0.j]) # may vary
399
+
400
+ Notice how the final element of the `fft` output is the complex conjugate
401
+ of the second element, for real input. For `rfft`, this symmetry is
402
+ exploited to compute only the non-negative frequency terms.
403
+
404
+ """
405
+ a = asarray(a)
406
+ if n is None:
407
+ n = a.shape[axis]
408
+ inv_norm = _get_forward_norm(n, norm)
409
+ output = _raw_fft(a, n, axis, True, True, inv_norm)
410
+ return output
411
+
412
+
413
+ @array_function_dispatch(_fft_dispatcher)
414
+ def irfft(a, n=None, axis=-1, norm=None):
415
+ """
416
+ Computes the inverse of `rfft`.
417
+
418
+ This function computes the inverse of the one-dimensional *n*-point
419
+ discrete Fourier Transform of real input computed by `rfft`.
420
+ In other words, ``irfft(rfft(a), len(a)) == a`` to within numerical
421
+ accuracy. (See Notes below for why ``len(a)`` is necessary here.)
422
+
423
+ The input is expected to be in the form returned by `rfft`, i.e. the
424
+ real zero-frequency term followed by the complex positive frequency terms
425
+ in order of increasing frequency. Since the discrete Fourier Transform of
426
+ real input is Hermitian-symmetric, the negative frequency terms are taken
427
+ to be the complex conjugates of the corresponding positive frequency terms.
428
+
429
+ Parameters
430
+ ----------
431
+ a : array_like
432
+ The input array.
433
+ n : int, optional
434
+ Length of the transformed axis of the output.
435
+ For `n` output points, ``n//2+1`` input points are necessary. If the
436
+ input is longer than this, it is cropped. If it is shorter than this,
437
+ it is padded with zeros. If `n` is not given, it is taken to be
438
+ ``2*(m-1)`` where ``m`` is the length of the input along the axis
439
+ specified by `axis`.
440
+ axis : int, optional
441
+ Axis over which to compute the inverse FFT. If not given, the last
442
+ axis is used.
443
+ norm : {"backward", "ortho", "forward"}, optional
444
+ .. versionadded:: 1.10.0
445
+
446
+ Normalization mode (see `numpy.fft`). Default is "backward".
447
+ Indicates which direction of the forward/backward pair of transforms
448
+ is scaled and with what normalization factor.
449
+
450
+ .. versionadded:: 1.20.0
451
+
452
+ The "backward", "forward" values were added.
453
+
454
+ Returns
455
+ -------
456
+ out : ndarray
457
+ The truncated or zero-padded input, transformed along the axis
458
+ indicated by `axis`, or the last one if `axis` is not specified.
459
+ The length of the transformed axis is `n`, or, if `n` is not given,
460
+ ``2*(m-1)`` where ``m`` is the length of the transformed axis of the
461
+ input. To get an odd number of output points, `n` must be specified.
462
+
463
+ Raises
464
+ ------
465
+ IndexError
466
+ If `axis` is not a valid axis of `a`.
467
+
468
+ See Also
469
+ --------
470
+ numpy.fft : For definition of the DFT and conventions used.
471
+ rfft : The one-dimensional FFT of real input, of which `irfft` is inverse.
472
+ fft : The one-dimensional FFT.
473
+ irfft2 : The inverse of the two-dimensional FFT of real input.
474
+ irfftn : The inverse of the *n*-dimensional FFT of real input.
475
+
476
+ Notes
477
+ -----
478
+ Returns the real valued `n`-point inverse discrete Fourier transform
479
+ of `a`, where `a` contains the non-negative frequency terms of a
480
+ Hermitian-symmetric sequence. `n` is the length of the result, not the
481
+ input.
482
+
483
+ If you specify an `n` such that `a` must be zero-padded or truncated, the
484
+ extra/removed values will be added/removed at high frequencies. One can
485
+ thus resample a series to `m` points via Fourier interpolation by:
486
+ ``a_resamp = irfft(rfft(a), m)``.
487
+
488
+ The correct interpretation of the hermitian input depends on the length of
489
+ the original data, as given by `n`. This is because each input shape could
490
+ correspond to either an odd or even length signal. By default, `irfft`
491
+ assumes an even output length which puts the last entry at the Nyquist
492
+ frequency; aliasing with its symmetric counterpart. By Hermitian symmetry,
493
+ the value is thus treated as purely real. To avoid losing information, the
494
+ correct length of the real input **must** be given.
495
+
496
+ Examples
497
+ --------
498
+ >>> np.fft.ifft([1, -1j, -1, 1j])
499
+ array([0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]) # may vary
500
+ >>> np.fft.irfft([1, -1j, -1])
501
+ array([0., 1., 0., 0.])
502
+
503
+ Notice how the last term in the input to the ordinary `ifft` is the
504
+ complex conjugate of the second term, and the output has zero imaginary
505
+ part everywhere. When calling `irfft`, the negative frequencies are not
506
+ specified, and the output array is purely real.
507
+
508
+ """
509
+ a = asarray(a)
510
+ if n is None:
511
+ n = (a.shape[axis] - 1) * 2
512
+ inv_norm = _get_backward_norm(n, norm)
513
+ output = _raw_fft(a, n, axis, True, False, inv_norm)
514
+ return output
515
+
516
+
517
+ @array_function_dispatch(_fft_dispatcher)
518
+ def hfft(a, n=None, axis=-1, norm=None):
519
+ """
520
+ Compute the FFT of a signal that has Hermitian symmetry, i.e., a real
521
+ spectrum.
522
+
523
+ Parameters
524
+ ----------
525
+ a : array_like
526
+ The input array.
527
+ n : int, optional
528
+ Length of the transformed axis of the output. For `n` output
529
+ points, ``n//2 + 1`` input points are necessary. If the input is
530
+ longer than this, it is cropped. If it is shorter than this, it is
531
+ padded with zeros. If `n` is not given, it is taken to be ``2*(m-1)``
532
+ where ``m`` is the length of the input along the axis specified by
533
+ `axis`.
534
+ axis : int, optional
535
+ Axis over which to compute the FFT. If not given, the last
536
+ axis is used.
537
+ norm : {"backward", "ortho", "forward"}, optional
538
+ .. versionadded:: 1.10.0
539
+
540
+ Normalization mode (see `numpy.fft`). Default is "backward".
541
+ Indicates which direction of the forward/backward pair of transforms
542
+ is scaled and with what normalization factor.
543
+
544
+ .. versionadded:: 1.20.0
545
+
546
+ The "backward", "forward" values were added.
547
+
548
+ Returns
549
+ -------
550
+ out : ndarray
551
+ The truncated or zero-padded input, transformed along the axis
552
+ indicated by `axis`, or the last one if `axis` is not specified.
553
+ The length of the transformed axis is `n`, or, if `n` is not given,
554
+ ``2*m - 2`` where ``m`` is the length of the transformed axis of
555
+ the input. To get an odd number of output points, `n` must be
556
+ specified, for instance as ``2*m - 1`` in the typical case,
557
+
558
+ Raises
559
+ ------
560
+ IndexError
561
+ If `axis` is not a valid axis of `a`.
562
+
563
+ See also
564
+ --------
565
+ rfft : Compute the one-dimensional FFT for real input.
566
+ ihfft : The inverse of `hfft`.
567
+
568
+ Notes
569
+ -----
570
+ `hfft`/`ihfft` are a pair analogous to `rfft`/`irfft`, but for the
571
+ opposite case: here the signal has Hermitian symmetry in the time
572
+ domain and is real in the frequency domain. So here it's `hfft` for
573
+ which you must supply the length of the result if it is to be odd.
574
+
575
+ * even: ``ihfft(hfft(a, 2*len(a) - 2)) == a``, within roundoff error,
576
+ * odd: ``ihfft(hfft(a, 2*len(a) - 1)) == a``, within roundoff error.
577
+
578
+ The correct interpretation of the hermitian input depends on the length of
579
+ the original data, as given by `n`. This is because each input shape could
580
+ correspond to either an odd or even length signal. By default, `hfft`
581
+ assumes an even output length which puts the last entry at the Nyquist
582
+ frequency; aliasing with its symmetric counterpart. By Hermitian symmetry,
583
+ the value is thus treated as purely real. To avoid losing information, the
584
+ shape of the full signal **must** be given.
585
+
586
+ Examples
587
+ --------
588
+ >>> signal = np.array([1, 2, 3, 4, 3, 2])
589
+ >>> np.fft.fft(signal)
590
+ array([15.+0.j, -4.+0.j, 0.+0.j, -1.-0.j, 0.+0.j, -4.+0.j]) # may vary
591
+ >>> np.fft.hfft(signal[:4]) # Input first half of signal
592
+ array([15., -4., 0., -1., 0., -4.])
593
+ >>> np.fft.hfft(signal, 6) # Input entire signal and truncate
594
+ array([15., -4., 0., -1., 0., -4.])
595
+
596
+
597
+ >>> signal = np.array([[1, 1.j], [-1.j, 2]])
598
+ >>> np.conj(signal.T) - signal # check Hermitian symmetry
599
+ array([[ 0.-0.j, -0.+0.j], # may vary
600
+ [ 0.+0.j, 0.-0.j]])
601
+ >>> freq_spectrum = np.fft.hfft(signal)
602
+ >>> freq_spectrum
603
+ array([[ 1., 1.],
604
+ [ 2., -2.]])
605
+
606
+ """
607
+ a = asarray(a)
608
+ if n is None:
609
+ n = (a.shape[axis] - 1) * 2
610
+ new_norm = _swap_direction(norm)
611
+ output = irfft(conjugate(a), n, axis, norm=new_norm)
612
+ return output
613
+
614
+
615
+ @array_function_dispatch(_fft_dispatcher)
616
+ def ihfft(a, n=None, axis=-1, norm=None):
617
+ """
618
+ Compute the inverse FFT of a signal that has Hermitian symmetry.
619
+
620
+ Parameters
621
+ ----------
622
+ a : array_like
623
+ Input array.
624
+ n : int, optional
625
+ Length of the inverse FFT, the number of points along
626
+ transformation axis in the input to use. If `n` is smaller than
627
+ the length of the input, the input is cropped. If it is larger,
628
+ the input is padded with zeros. If `n` is not given, the length of
629
+ the input along the axis specified by `axis` is used.
630
+ axis : int, optional
631
+ Axis over which to compute the inverse FFT. If not given, the last
632
+ axis is used.
633
+ norm : {"backward", "ortho", "forward"}, optional
634
+ .. versionadded:: 1.10.0
635
+
636
+ Normalization mode (see `numpy.fft`). Default is "backward".
637
+ Indicates which direction of the forward/backward pair of transforms
638
+ is scaled and with what normalization factor.
639
+
640
+ .. versionadded:: 1.20.0
641
+
642
+ The "backward", "forward" values were added.
643
+
644
+ Returns
645
+ -------
646
+ out : complex ndarray
647
+ The truncated or zero-padded input, transformed along the axis
648
+ indicated by `axis`, or the last one if `axis` is not specified.
649
+ The length of the transformed axis is ``n//2 + 1``.
650
+
651
+ See also
652
+ --------
653
+ hfft, irfft
654
+
655
+ Notes
656
+ -----
657
+ `hfft`/`ihfft` are a pair analogous to `rfft`/`irfft`, but for the
658
+ opposite case: here the signal has Hermitian symmetry in the time
659
+ domain and is real in the frequency domain. So here it's `hfft` for
660
+ which you must supply the length of the result if it is to be odd:
661
+
662
+ * even: ``ihfft(hfft(a, 2*len(a) - 2)) == a``, within roundoff error,
663
+ * odd: ``ihfft(hfft(a, 2*len(a) - 1)) == a``, within roundoff error.
664
+
665
+ Examples
666
+ --------
667
+ >>> spectrum = np.array([ 15, -4, 0, -1, 0, -4])
668
+ >>> np.fft.ifft(spectrum)
669
+ array([1.+0.j, 2.+0.j, 3.+0.j, 4.+0.j, 3.+0.j, 2.+0.j]) # may vary
670
+ >>> np.fft.ihfft(spectrum)
671
+ array([ 1.-0.j, 2.-0.j, 3.-0.j, 4.-0.j]) # may vary
672
+
673
+ """
674
+ a = asarray(a)
675
+ if n is None:
676
+ n = a.shape[axis]
677
+ new_norm = _swap_direction(norm)
678
+ output = conjugate(rfft(a, n, axis, norm=new_norm))
679
+ return output
680
+
681
+
682
+ def _cook_nd_args(a, s=None, axes=None, invreal=0):
683
+ if s is None:
684
+ shapeless = 1
685
+ if axes is None:
686
+ s = list(a.shape)
687
+ else:
688
+ s = take(a.shape, axes)
689
+ else:
690
+ shapeless = 0
691
+ s = list(s)
692
+ if axes is None:
693
+ axes = list(range(-len(s), 0))
694
+ if len(s) != len(axes):
695
+ raise ValueError("Shape and axes have different lengths.")
696
+ if invreal and shapeless:
697
+ s[-1] = (a.shape[axes[-1]] - 1) * 2
698
+ return s, axes
699
+
700
+
701
+ def _raw_fftnd(a, s=None, axes=None, function=fft, norm=None):
702
+ a = asarray(a)
703
+ s, axes = _cook_nd_args(a, s, axes)
704
+ itl = list(range(len(axes)))
705
+ itl.reverse()
706
+ for ii in itl:
707
+ a = function(a, n=s[ii], axis=axes[ii], norm=norm)
708
+ return a
709
+
710
+
711
+ def _fftn_dispatcher(a, s=None, axes=None, norm=None):
712
+ return (a,)
713
+
714
+
715
+ @array_function_dispatch(_fftn_dispatcher)
716
+ def fftn(a, s=None, axes=None, norm=None):
717
+ """
718
+ Compute the N-dimensional discrete Fourier Transform.
719
+
720
+ This function computes the *N*-dimensional discrete Fourier Transform over
721
+ any number of axes in an *M*-dimensional array by means of the Fast Fourier
722
+ Transform (FFT).
723
+
724
+ Parameters
725
+ ----------
726
+ a : array_like
727
+ Input array, can be complex.
728
+ s : sequence of ints, optional
729
+ Shape (length of each transformed axis) of the output
730
+ (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
731
+ This corresponds to ``n`` for ``fft(x, n)``.
732
+ Along any axis, if the given shape is smaller than that of the input,
733
+ the input is cropped. If it is larger, the input is padded with zeros.
734
+ if `s` is not given, the shape of the input along the axes specified
735
+ by `axes` is used.
736
+ axes : sequence of ints, optional
737
+ Axes over which to compute the FFT. If not given, the last ``len(s)``
738
+ axes are used, or all axes if `s` is also not specified.
739
+ Repeated indices in `axes` means that the transform over that axis is
740
+ performed multiple times.
741
+ norm : {"backward", "ortho", "forward"}, optional
742
+ .. versionadded:: 1.10.0
743
+
744
+ Normalization mode (see `numpy.fft`). Default is "backward".
745
+ Indicates which direction of the forward/backward pair of transforms
746
+ is scaled and with what normalization factor.
747
+
748
+ .. versionadded:: 1.20.0
749
+
750
+ The "backward", "forward" values were added.
751
+
752
+ Returns
753
+ -------
754
+ out : complex ndarray
755
+ The truncated or zero-padded input, transformed along the axes
756
+ indicated by `axes`, or by a combination of `s` and `a`,
757
+ as explained in the parameters section above.
758
+
759
+ Raises
760
+ ------
761
+ ValueError
762
+ If `s` and `axes` have different length.
763
+ IndexError
764
+ If an element of `axes` is larger than than the number of axes of `a`.
765
+
766
+ See Also
767
+ --------
768
+ numpy.fft : Overall view of discrete Fourier transforms, with definitions
769
+ and conventions used.
770
+ ifftn : The inverse of `fftn`, the inverse *n*-dimensional FFT.
771
+ fft : The one-dimensional FFT, with definitions and conventions used.
772
+ rfftn : The *n*-dimensional FFT of real input.
773
+ fft2 : The two-dimensional FFT.
774
+ fftshift : Shifts zero-frequency terms to centre of array
775
+
776
+ Notes
777
+ -----
778
+ The output, analogously to `fft`, contains the term for zero frequency in
779
+ the low-order corner of all axes, the positive frequency terms in the
780
+ first half of all axes, the term for the Nyquist frequency in the middle
781
+ of all axes and the negative frequency terms in the second half of all
782
+ axes, in order of decreasingly negative frequency.
783
+
784
+ See `numpy.fft` for details, definitions and conventions used.
785
+
786
+ Examples
787
+ --------
788
+ >>> a = np.mgrid[:3, :3, :3][0]
789
+ >>> np.fft.fftn(a, axes=(1, 2))
790
+ array([[[ 0.+0.j, 0.+0.j, 0.+0.j], # may vary
791
+ [ 0.+0.j, 0.+0.j, 0.+0.j],
792
+ [ 0.+0.j, 0.+0.j, 0.+0.j]],
793
+ [[ 9.+0.j, 0.+0.j, 0.+0.j],
794
+ [ 0.+0.j, 0.+0.j, 0.+0.j],
795
+ [ 0.+0.j, 0.+0.j, 0.+0.j]],
796
+ [[18.+0.j, 0.+0.j, 0.+0.j],
797
+ [ 0.+0.j, 0.+0.j, 0.+0.j],
798
+ [ 0.+0.j, 0.+0.j, 0.+0.j]]])
799
+ >>> np.fft.fftn(a, (2, 2), axes=(0, 1))
800
+ array([[[ 2.+0.j, 2.+0.j, 2.+0.j], # may vary
801
+ [ 0.+0.j, 0.+0.j, 0.+0.j]],
802
+ [[-2.+0.j, -2.+0.j, -2.+0.j],
803
+ [ 0.+0.j, 0.+0.j, 0.+0.j]]])
804
+
805
+ >>> import matplotlib.pyplot as plt
806
+ >>> [X, Y] = np.meshgrid(2 * np.pi * np.arange(200) / 12,
807
+ ... 2 * np.pi * np.arange(200) / 34)
808
+ >>> S = np.sin(X) + np.cos(Y) + np.random.uniform(0, 1, X.shape)
809
+ >>> FS = np.fft.fftn(S)
810
+ >>> plt.imshow(np.log(np.abs(np.fft.fftshift(FS))**2))
811
+ <matplotlib.image.AxesImage object at 0x...>
812
+ >>> plt.show()
813
+
814
+ """
815
+ return _raw_fftnd(a, s, axes, fft, norm)
816
+
817
+
818
+ @array_function_dispatch(_fftn_dispatcher)
819
+ def ifftn(a, s=None, axes=None, norm=None):
820
+ """
821
+ Compute the N-dimensional inverse discrete Fourier Transform.
822
+
823
+ This function computes the inverse of the N-dimensional discrete
824
+ Fourier Transform over any number of axes in an M-dimensional array by
825
+ means of the Fast Fourier Transform (FFT). In other words,
826
+ ``ifftn(fftn(a)) == a`` to within numerical accuracy.
827
+ For a description of the definitions and conventions used, see `numpy.fft`.
828
+
829
+ The input, analogously to `ifft`, should be ordered in the same way as is
830
+ returned by `fftn`, i.e. it should have the term for zero frequency
831
+ in all axes in the low-order corner, the positive frequency terms in the
832
+ first half of all axes, the term for the Nyquist frequency in the middle
833
+ of all axes and the negative frequency terms in the second half of all
834
+ axes, in order of decreasingly negative frequency.
835
+
836
+ Parameters
837
+ ----------
838
+ a : array_like
839
+ Input array, can be complex.
840
+ s : sequence of ints, optional
841
+ Shape (length of each transformed axis) of the output
842
+ (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
843
+ This corresponds to ``n`` for ``ifft(x, n)``.
844
+ Along any axis, if the given shape is smaller than that of the input,
845
+ the input is cropped. If it is larger, the input is padded with zeros.
846
+ if `s` is not given, the shape of the input along the axes specified
847
+ by `axes` is used. See notes for issue on `ifft` zero padding.
848
+ axes : sequence of ints, optional
849
+ Axes over which to compute the IFFT. If not given, the last ``len(s)``
850
+ axes are used, or all axes if `s` is also not specified.
851
+ Repeated indices in `axes` means that the inverse transform over that
852
+ axis is performed multiple times.
853
+ norm : {"backward", "ortho", "forward"}, optional
854
+ .. versionadded:: 1.10.0
855
+
856
+ Normalization mode (see `numpy.fft`). Default is "backward".
857
+ Indicates which direction of the forward/backward pair of transforms
858
+ is scaled and with what normalization factor.
859
+
860
+ .. versionadded:: 1.20.0
861
+
862
+ The "backward", "forward" values were added.
863
+
864
+ Returns
865
+ -------
866
+ out : complex ndarray
867
+ The truncated or zero-padded input, transformed along the axes
868
+ indicated by `axes`, or by a combination of `s` or `a`,
869
+ as explained in the parameters section above.
870
+
871
+ Raises
872
+ ------
873
+ ValueError
874
+ If `s` and `axes` have different length.
875
+ IndexError
876
+ If an element of `axes` is larger than than the number of axes of `a`.
877
+
878
+ See Also
879
+ --------
880
+ numpy.fft : Overall view of discrete Fourier transforms, with definitions
881
+ and conventions used.
882
+ fftn : The forward *n*-dimensional FFT, of which `ifftn` is the inverse.
883
+ ifft : The one-dimensional inverse FFT.
884
+ ifft2 : The two-dimensional inverse FFT.
885
+ ifftshift : Undoes `fftshift`, shifts zero-frequency terms to beginning
886
+ of array.
887
+
888
+ Notes
889
+ -----
890
+ See `numpy.fft` for definitions and conventions used.
891
+
892
+ Zero-padding, analogously with `ifft`, is performed by appending zeros to
893
+ the input along the specified dimension. Although this is the common
894
+ approach, it might lead to surprising results. If another form of zero
895
+ padding is desired, it must be performed before `ifftn` is called.
896
+
897
+ Examples
898
+ --------
899
+ >>> a = np.eye(4)
900
+ >>> np.fft.ifftn(np.fft.fftn(a, axes=(0,)), axes=(1,))
901
+ array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], # may vary
902
+ [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
903
+ [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
904
+ [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])
905
+
906
+
907
+ Create and plot an image with band-limited frequency content:
908
+
909
+ >>> import matplotlib.pyplot as plt
910
+ >>> n = np.zeros((200,200), dtype=complex)
911
+ >>> n[60:80, 20:40] = np.exp(1j*np.random.uniform(0, 2*np.pi, (20, 20)))
912
+ >>> im = np.fft.ifftn(n).real
913
+ >>> plt.imshow(im)
914
+ <matplotlib.image.AxesImage object at 0x...>
915
+ >>> plt.show()
916
+
917
+ """
918
+ return _raw_fftnd(a, s, axes, ifft, norm)
919
+
920
+
921
+ @array_function_dispatch(_fftn_dispatcher)
922
+ def fft2(a, s=None, axes=(-2, -1), norm=None):
923
+ """
924
+ Compute the 2-dimensional discrete Fourier Transform.
925
+
926
+ This function computes the *n*-dimensional discrete Fourier Transform
927
+ over any axes in an *M*-dimensional array by means of the
928
+ Fast Fourier Transform (FFT). By default, the transform is computed over
929
+ the last two axes of the input array, i.e., a 2-dimensional FFT.
930
+
931
+ Parameters
932
+ ----------
933
+ a : array_like
934
+ Input array, can be complex
935
+ s : sequence of ints, optional
936
+ Shape (length of each transformed axis) of the output
937
+ (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
938
+ This corresponds to ``n`` for ``fft(x, n)``.
939
+ Along each axis, if the given shape is smaller than that of the input,
940
+ the input is cropped. If it is larger, the input is padded with zeros.
941
+ if `s` is not given, the shape of the input along the axes specified
942
+ by `axes` is used.
943
+ axes : sequence of ints, optional
944
+ Axes over which to compute the FFT. If not given, the last two
945
+ axes are used. A repeated index in `axes` means the transform over
946
+ that axis is performed multiple times. A one-element sequence means
947
+ that a one-dimensional FFT is performed.
948
+ norm : {"backward", "ortho", "forward"}, optional
949
+ .. versionadded:: 1.10.0
950
+
951
+ Normalization mode (see `numpy.fft`). Default is "backward".
952
+ Indicates which direction of the forward/backward pair of transforms
953
+ is scaled and with what normalization factor.
954
+
955
+ .. versionadded:: 1.20.0
956
+
957
+ The "backward", "forward" values were added.
958
+
959
+ Returns
960
+ -------
961
+ out : complex ndarray
962
+ The truncated or zero-padded input, transformed along the axes
963
+ indicated by `axes`, or the last two axes if `axes` is not given.
964
+
965
+ Raises
966
+ ------
967
+ ValueError
968
+ If `s` and `axes` have different length, or `axes` not given and
969
+ ``len(s) != 2``.
970
+ IndexError
971
+ If an element of `axes` is larger than than the number of axes of `a`.
972
+
973
+ See Also
974
+ --------
975
+ numpy.fft : Overall view of discrete Fourier transforms, with definitions
976
+ and conventions used.
977
+ ifft2 : The inverse two-dimensional FFT.
978
+ fft : The one-dimensional FFT.
979
+ fftn : The *n*-dimensional FFT.
980
+ fftshift : Shifts zero-frequency terms to the center of the array.
981
+ For two-dimensional input, swaps first and third quadrants, and second
982
+ and fourth quadrants.
983
+
984
+ Notes
985
+ -----
986
+ `fft2` is just `fftn` with a different default for `axes`.
987
+
988
+ The output, analogously to `fft`, contains the term for zero frequency in
989
+ the low-order corner of the transformed axes, the positive frequency terms
990
+ in the first half of these axes, the term for the Nyquist frequency in the
991
+ middle of the axes and the negative frequency terms in the second half of
992
+ the axes, in order of decreasingly negative frequency.
993
+
994
+ See `fftn` for details and a plotting example, and `numpy.fft` for
995
+ definitions and conventions used.
996
+
997
+
998
+ Examples
999
+ --------
1000
+ >>> a = np.mgrid[:5, :5][0]
1001
+ >>> np.fft.fft2(a)
1002
+ array([[ 50. +0.j , 0. +0.j , 0. +0.j , # may vary
1003
+ 0. +0.j , 0. +0.j ],
1004
+ [-12.5+17.20477401j, 0. +0.j , 0. +0.j ,
1005
+ 0. +0.j , 0. +0.j ],
1006
+ [-12.5 +4.0614962j , 0. +0.j , 0. +0.j ,
1007
+ 0. +0.j , 0. +0.j ],
1008
+ [-12.5 -4.0614962j , 0. +0.j , 0. +0.j ,
1009
+ 0. +0.j , 0. +0.j ],
1010
+ [-12.5-17.20477401j, 0. +0.j , 0. +0.j ,
1011
+ 0. +0.j , 0. +0.j ]])
1012
+
1013
+ """
1014
+ return _raw_fftnd(a, s, axes, fft, norm)
1015
+
1016
+
1017
+ @array_function_dispatch(_fftn_dispatcher)
1018
+ def ifft2(a, s=None, axes=(-2, -1), norm=None):
1019
+ """
1020
+ Compute the 2-dimensional inverse discrete Fourier Transform.
1021
+
1022
+ This function computes the inverse of the 2-dimensional discrete Fourier
1023
+ Transform over any number of axes in an M-dimensional array by means of
1024
+ the Fast Fourier Transform (FFT). In other words, ``ifft2(fft2(a)) == a``
1025
+ to within numerical accuracy. By default, the inverse transform is
1026
+ computed over the last two axes of the input array.
1027
+
1028
+ The input, analogously to `ifft`, should be ordered in the same way as is
1029
+ returned by `fft2`, i.e. it should have the term for zero frequency
1030
+ in the low-order corner of the two axes, the positive frequency terms in
1031
+ the first half of these axes, the term for the Nyquist frequency in the
1032
+ middle of the axes and the negative frequency terms in the second half of
1033
+ both axes, in order of decreasingly negative frequency.
1034
+
1035
+ Parameters
1036
+ ----------
1037
+ a : array_like
1038
+ Input array, can be complex.
1039
+ s : sequence of ints, optional
1040
+ Shape (length of each axis) of the output (``s[0]`` refers to axis 0,
1041
+ ``s[1]`` to axis 1, etc.). This corresponds to `n` for ``ifft(x, n)``.
1042
+ Along each axis, if the given shape is smaller than that of the input,
1043
+ the input is cropped. If it is larger, the input is padded with zeros.
1044
+ if `s` is not given, the shape of the input along the axes specified
1045
+ by `axes` is used. See notes for issue on `ifft` zero padding.
1046
+ axes : sequence of ints, optional
1047
+ Axes over which to compute the FFT. If not given, the last two
1048
+ axes are used. A repeated index in `axes` means the transform over
1049
+ that axis is performed multiple times. A one-element sequence means
1050
+ that a one-dimensional FFT is performed.
1051
+ norm : {"backward", "ortho", "forward"}, optional
1052
+ .. versionadded:: 1.10.0
1053
+
1054
+ Normalization mode (see `numpy.fft`). Default is "backward".
1055
+ Indicates which direction of the forward/backward pair of transforms
1056
+ is scaled and with what normalization factor.
1057
+
1058
+ .. versionadded:: 1.20.0
1059
+
1060
+ The "backward", "forward" values were added.
1061
+
1062
+ Returns
1063
+ -------
1064
+ out : complex ndarray
1065
+ The truncated or zero-padded input, transformed along the axes
1066
+ indicated by `axes`, or the last two axes if `axes` is not given.
1067
+
1068
+ Raises
1069
+ ------
1070
+ ValueError
1071
+ If `s` and `axes` have different length, or `axes` not given and
1072
+ ``len(s) != 2``.
1073
+ IndexError
1074
+ If an element of `axes` is larger than than the number of axes of `a`.
1075
+
1076
+ See Also
1077
+ --------
1078
+ numpy.fft : Overall view of discrete Fourier transforms, with definitions
1079
+ and conventions used.
1080
+ fft2 : The forward 2-dimensional FFT, of which `ifft2` is the inverse.
1081
+ ifftn : The inverse of the *n*-dimensional FFT.
1082
+ fft : The one-dimensional FFT.
1083
+ ifft : The one-dimensional inverse FFT.
1084
+
1085
+ Notes
1086
+ -----
1087
+ `ifft2` is just `ifftn` with a different default for `axes`.
1088
+
1089
+ See `ifftn` for details and a plotting example, and `numpy.fft` for
1090
+ definition and conventions used.
1091
+
1092
+ Zero-padding, analogously with `ifft`, is performed by appending zeros to
1093
+ the input along the specified dimension. Although this is the common
1094
+ approach, it might lead to surprising results. If another form of zero
1095
+ padding is desired, it must be performed before `ifft2` is called.
1096
+
1097
+ Examples
1098
+ --------
1099
+ >>> a = 4 * np.eye(4)
1100
+ >>> np.fft.ifft2(a)
1101
+ array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], # may vary
1102
+ [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],
1103
+ [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
1104
+ [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]])
1105
+
1106
+ """
1107
+ return _raw_fftnd(a, s, axes, ifft, norm)
1108
+
1109
+
1110
+ @array_function_dispatch(_fftn_dispatcher)
1111
+ def rfftn(a, s=None, axes=None, norm=None):
1112
+ """
1113
+ Compute the N-dimensional discrete Fourier Transform for real input.
1114
+
1115
+ This function computes the N-dimensional discrete Fourier Transform over
1116
+ any number of axes in an M-dimensional real array by means of the Fast
1117
+ Fourier Transform (FFT). By default, all axes are transformed, with the
1118
+ real transform performed over the last axis, while the remaining
1119
+ transforms are complex.
1120
+
1121
+ Parameters
1122
+ ----------
1123
+ a : array_like
1124
+ Input array, taken to be real.
1125
+ s : sequence of ints, optional
1126
+ Shape (length along each transformed axis) to use from the input.
1127
+ (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
1128
+ The final element of `s` corresponds to `n` for ``rfft(x, n)``, while
1129
+ for the remaining axes, it corresponds to `n` for ``fft(x, n)``.
1130
+ Along any axis, if the given shape is smaller than that of the input,
1131
+ the input is cropped. If it is larger, the input is padded with zeros.
1132
+ if `s` is not given, the shape of the input along the axes specified
1133
+ by `axes` is used.
1134
+ axes : sequence of ints, optional
1135
+ Axes over which to compute the FFT. If not given, the last ``len(s)``
1136
+ axes are used, or all axes if `s` is also not specified.
1137
+ norm : {"backward", "ortho", "forward"}, optional
1138
+ .. versionadded:: 1.10.0
1139
+
1140
+ Normalization mode (see `numpy.fft`). Default is "backward".
1141
+ Indicates which direction of the forward/backward pair of transforms
1142
+ is scaled and with what normalization factor.
1143
+
1144
+ .. versionadded:: 1.20.0
1145
+
1146
+ The "backward", "forward" values were added.
1147
+
1148
+ Returns
1149
+ -------
1150
+ out : complex ndarray
1151
+ The truncated or zero-padded input, transformed along the axes
1152
+ indicated by `axes`, or by a combination of `s` and `a`,
1153
+ as explained in the parameters section above.
1154
+ The length of the last axis transformed will be ``s[-1]//2+1``,
1155
+ while the remaining transformed axes will have lengths according to
1156
+ `s`, or unchanged from the input.
1157
+
1158
+ Raises
1159
+ ------
1160
+ ValueError
1161
+ If `s` and `axes` have different length.
1162
+ IndexError
1163
+ If an element of `axes` is larger than than the number of axes of `a`.
1164
+
1165
+ See Also
1166
+ --------
1167
+ irfftn : The inverse of `rfftn`, i.e. the inverse of the n-dimensional FFT
1168
+ of real input.
1169
+ fft : The one-dimensional FFT, with definitions and conventions used.
1170
+ rfft : The one-dimensional FFT of real input.
1171
+ fftn : The n-dimensional FFT.
1172
+ rfft2 : The two-dimensional FFT of real input.
1173
+
1174
+ Notes
1175
+ -----
1176
+ The transform for real input is performed over the last transformation
1177
+ axis, as by `rfft`, then the transform over the remaining axes is
1178
+ performed as by `fftn`. The order of the output is as for `rfft` for the
1179
+ final transformation axis, and as for `fftn` for the remaining
1180
+ transformation axes.
1181
+
1182
+ See `fft` for details, definitions and conventions used.
1183
+
1184
+ Examples
1185
+ --------
1186
+ >>> a = np.ones((2, 2, 2))
1187
+ >>> np.fft.rfftn(a)
1188
+ array([[[8.+0.j, 0.+0.j], # may vary
1189
+ [0.+0.j, 0.+0.j]],
1190
+ [[0.+0.j, 0.+0.j],
1191
+ [0.+0.j, 0.+0.j]]])
1192
+
1193
+ >>> np.fft.rfftn(a, axes=(2, 0))
1194
+ array([[[4.+0.j, 0.+0.j], # may vary
1195
+ [4.+0.j, 0.+0.j]],
1196
+ [[0.+0.j, 0.+0.j],
1197
+ [0.+0.j, 0.+0.j]]])
1198
+
1199
+ """
1200
+ a = asarray(a)
1201
+ s, axes = _cook_nd_args(a, s, axes)
1202
+ a = rfft(a, s[-1], axes[-1], norm)
1203
+ for ii in range(len(axes)-1):
1204
+ a = fft(a, s[ii], axes[ii], norm)
1205
+ return a
1206
+
1207
+
1208
+ @array_function_dispatch(_fftn_dispatcher)
1209
+ def rfft2(a, s=None, axes=(-2, -1), norm=None):
1210
+ """
1211
+ Compute the 2-dimensional FFT of a real array.
1212
+
1213
+ Parameters
1214
+ ----------
1215
+ a : array
1216
+ Input array, taken to be real.
1217
+ s : sequence of ints, optional
1218
+ Shape of the FFT.
1219
+ axes : sequence of ints, optional
1220
+ Axes over which to compute the FFT.
1221
+ norm : {"backward", "ortho", "forward"}, optional
1222
+ .. versionadded:: 1.10.0
1223
+
1224
+ Normalization mode (see `numpy.fft`). Default is "backward".
1225
+ Indicates which direction of the forward/backward pair of transforms
1226
+ is scaled and with what normalization factor.
1227
+
1228
+ .. versionadded:: 1.20.0
1229
+
1230
+ The "backward", "forward" values were added.
1231
+
1232
+ Returns
1233
+ -------
1234
+ out : ndarray
1235
+ The result of the real 2-D FFT.
1236
+
1237
+ See Also
1238
+ --------
1239
+ rfftn : Compute the N-dimensional discrete Fourier Transform for real
1240
+ input.
1241
+
1242
+ Notes
1243
+ -----
1244
+ This is really just `rfftn` with different default behavior.
1245
+ For more details see `rfftn`.
1246
+
1247
+ Examples
1248
+ --------
1249
+ >>> a = np.mgrid[:5, :5][0]
1250
+ >>> np.fft.rfft2(a)
1251
+ array([[ 50. +0.j , 0. +0.j , 0. +0.j ],
1252
+ [-12.5+17.20477401j, 0. +0.j , 0. +0.j ],
1253
+ [-12.5 +4.0614962j , 0. +0.j , 0. +0.j ],
1254
+ [-12.5 -4.0614962j , 0. +0.j , 0. +0.j ],
1255
+ [-12.5-17.20477401j, 0. +0.j , 0. +0.j ]])
1256
+ """
1257
+ return rfftn(a, s, axes, norm)
1258
+
1259
+
1260
+ @array_function_dispatch(_fftn_dispatcher)
1261
+ def irfftn(a, s=None, axes=None, norm=None):
1262
+ """
1263
+ Computes the inverse of `rfftn`.
1264
+
1265
+ This function computes the inverse of the N-dimensional discrete
1266
+ Fourier Transform for real input over any number of axes in an
1267
+ M-dimensional array by means of the Fast Fourier Transform (FFT). In
1268
+ other words, ``irfftn(rfftn(a), a.shape) == a`` to within numerical
1269
+ accuracy. (The ``a.shape`` is necessary like ``len(a)`` is for `irfft`,
1270
+ and for the same reason.)
1271
+
1272
+ The input should be ordered in the same way as is returned by `rfftn`,
1273
+ i.e. as for `irfft` for the final transformation axis, and as for `ifftn`
1274
+ along all the other axes.
1275
+
1276
+ Parameters
1277
+ ----------
1278
+ a : array_like
1279
+ Input array.
1280
+ s : sequence of ints, optional
1281
+ Shape (length of each transformed axis) of the output
1282
+ (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.). `s` is also the
1283
+ number of input points used along this axis, except for the last axis,
1284
+ where ``s[-1]//2+1`` points of the input are used.
1285
+ Along any axis, if the shape indicated by `s` is smaller than that of
1286
+ the input, the input is cropped. If it is larger, the input is padded
1287
+ with zeros. If `s` is not given, the shape of the input along the axes
1288
+ specified by axes is used. Except for the last axis which is taken to
1289
+ be ``2*(m-1)`` where ``m`` is the length of the input along that axis.
1290
+ axes : sequence of ints, optional
1291
+ Axes over which to compute the inverse FFT. If not given, the last
1292
+ `len(s)` axes are used, or all axes if `s` is also not specified.
1293
+ Repeated indices in `axes` means that the inverse transform over that
1294
+ axis is performed multiple times.
1295
+ norm : {"backward", "ortho", "forward"}, optional
1296
+ .. versionadded:: 1.10.0
1297
+
1298
+ Normalization mode (see `numpy.fft`). Default is "backward".
1299
+ Indicates which direction of the forward/backward pair of transforms
1300
+ is scaled and with what normalization factor.
1301
+
1302
+ .. versionadded:: 1.20.0
1303
+
1304
+ The "backward", "forward" values were added.
1305
+
1306
+ Returns
1307
+ -------
1308
+ out : ndarray
1309
+ The truncated or zero-padded input, transformed along the axes
1310
+ indicated by `axes`, or by a combination of `s` or `a`,
1311
+ as explained in the parameters section above.
1312
+ The length of each transformed axis is as given by the corresponding
1313
+ element of `s`, or the length of the input in every axis except for the
1314
+ last one if `s` is not given. In the final transformed axis the length
1315
+ of the output when `s` is not given is ``2*(m-1)`` where ``m`` is the
1316
+ length of the final transformed axis of the input. To get an odd
1317
+ number of output points in the final axis, `s` must be specified.
1318
+
1319
+ Raises
1320
+ ------
1321
+ ValueError
1322
+ If `s` and `axes` have different length.
1323
+ IndexError
1324
+ If an element of `axes` is larger than than the number of axes of `a`.
1325
+
1326
+ See Also
1327
+ --------
1328
+ rfftn : The forward n-dimensional FFT of real input,
1329
+ of which `ifftn` is the inverse.
1330
+ fft : The one-dimensional FFT, with definitions and conventions used.
1331
+ irfft : The inverse of the one-dimensional FFT of real input.
1332
+ irfft2 : The inverse of the two-dimensional FFT of real input.
1333
+
1334
+ Notes
1335
+ -----
1336
+ See `fft` for definitions and conventions used.
1337
+
1338
+ See `rfft` for definitions and conventions used for real input.
1339
+
1340
+ The correct interpretation of the hermitian input depends on the shape of
1341
+ the original data, as given by `s`. This is because each input shape could
1342
+ correspond to either an odd or even length signal. By default, `irfftn`
1343
+ assumes an even output length which puts the last entry at the Nyquist
1344
+ frequency; aliasing with its symmetric counterpart. When performing the
1345
+ final complex to real transform, the last value is thus treated as purely
1346
+ real. To avoid losing information, the correct shape of the real input
1347
+ **must** be given.
1348
+
1349
+ Examples
1350
+ --------
1351
+ >>> a = np.zeros((3, 2, 2))
1352
+ >>> a[0, 0, 0] = 3 * 2 * 2
1353
+ >>> np.fft.irfftn(a)
1354
+ array([[[1., 1.],
1355
+ [1., 1.]],
1356
+ [[1., 1.],
1357
+ [1., 1.]],
1358
+ [[1., 1.],
1359
+ [1., 1.]]])
1360
+
1361
+ """
1362
+ a = asarray(a)
1363
+ s, axes = _cook_nd_args(a, s, axes, invreal=1)
1364
+ for ii in range(len(axes)-1):
1365
+ a = ifft(a, s[ii], axes[ii], norm)
1366
+ a = irfft(a, s[-1], axes[-1], norm)
1367
+ return a
1368
+
1369
+
1370
+ @array_function_dispatch(_fftn_dispatcher)
1371
+ def irfft2(a, s=None, axes=(-2, -1), norm=None):
1372
+ """
1373
+ Computes the inverse of `rfft2`.
1374
+
1375
+ Parameters
1376
+ ----------
1377
+ a : array_like
1378
+ The input array
1379
+ s : sequence of ints, optional
1380
+ Shape of the real output to the inverse FFT.
1381
+ axes : sequence of ints, optional
1382
+ The axes over which to compute the inverse fft.
1383
+ Default is the last two axes.
1384
+ norm : {"backward", "ortho", "forward"}, optional
1385
+ .. versionadded:: 1.10.0
1386
+
1387
+ Normalization mode (see `numpy.fft`). Default is "backward".
1388
+ Indicates which direction of the forward/backward pair of transforms
1389
+ is scaled and with what normalization factor.
1390
+
1391
+ .. versionadded:: 1.20.0
1392
+
1393
+ The "backward", "forward" values were added.
1394
+
1395
+ Returns
1396
+ -------
1397
+ out : ndarray
1398
+ The result of the inverse real 2-D FFT.
1399
+
1400
+ See Also
1401
+ --------
1402
+ rfft2 : The forward two-dimensional FFT of real input,
1403
+ of which `irfft2` is the inverse.
1404
+ rfft : The one-dimensional FFT for real input.
1405
+ irfft : The inverse of the one-dimensional FFT of real input.
1406
+ irfftn : Compute the inverse of the N-dimensional FFT of real input.
1407
+
1408
+ Notes
1409
+ -----
1410
+ This is really `irfftn` with different defaults.
1411
+ For more details see `irfftn`.
1412
+
1413
+ Examples
1414
+ --------
1415
+ >>> a = np.mgrid[:5, :5][0]
1416
+ >>> A = np.fft.rfft2(a)
1417
+ >>> np.fft.irfft2(A, s=a.shape)
1418
+ array([[0., 0., 0., 0., 0.],
1419
+ [1., 1., 1., 1., 1.],
1420
+ [2., 2., 2., 2., 2.],
1421
+ [3., 3., 3., 3., 3.],
1422
+ [4., 4., 4., 4., 4.]])
1423
+ """
1424
+ return irfftn(a, s, axes, norm)
moondream/lib/python3.10/site-packages/numpy/fft/_pocketfft.pyi ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections.abc import Sequence
2
+ from typing import Literal as L
3
+
4
+ from numpy import complex128, float64
5
+ from numpy._typing import ArrayLike, NDArray, _ArrayLikeNumber_co
6
+
7
+ _NormKind = L[None, "backward", "ortho", "forward"]
8
+
9
+ __all__: list[str]
10
+
11
+ def fft(
12
+ a: ArrayLike,
13
+ n: None | int = ...,
14
+ axis: int = ...,
15
+ norm: _NormKind = ...,
16
+ ) -> NDArray[complex128]: ...
17
+
18
+ def ifft(
19
+ a: ArrayLike,
20
+ n: None | int = ...,
21
+ axis: int = ...,
22
+ norm: _NormKind = ...,
23
+ ) -> NDArray[complex128]: ...
24
+
25
+ def rfft(
26
+ a: ArrayLike,
27
+ n: None | int = ...,
28
+ axis: int = ...,
29
+ norm: _NormKind = ...,
30
+ ) -> NDArray[complex128]: ...
31
+
32
+ def irfft(
33
+ a: ArrayLike,
34
+ n: None | int = ...,
35
+ axis: int = ...,
36
+ norm: _NormKind = ...,
37
+ ) -> NDArray[float64]: ...
38
+
39
+ # Input array must be compatible with `np.conjugate`
40
+ def hfft(
41
+ a: _ArrayLikeNumber_co,
42
+ n: None | int = ...,
43
+ axis: int = ...,
44
+ norm: _NormKind = ...,
45
+ ) -> NDArray[float64]: ...
46
+
47
+ def ihfft(
48
+ a: ArrayLike,
49
+ n: None | int = ...,
50
+ axis: int = ...,
51
+ norm: _NormKind = ...,
52
+ ) -> NDArray[complex128]: ...
53
+
54
+ def fftn(
55
+ a: ArrayLike,
56
+ s: None | Sequence[int] = ...,
57
+ axes: None | Sequence[int] = ...,
58
+ norm: _NormKind = ...,
59
+ ) -> NDArray[complex128]: ...
60
+
61
+ def ifftn(
62
+ a: ArrayLike,
63
+ s: None | Sequence[int] = ...,
64
+ axes: None | Sequence[int] = ...,
65
+ norm: _NormKind = ...,
66
+ ) -> NDArray[complex128]: ...
67
+
68
+ def rfftn(
69
+ a: ArrayLike,
70
+ s: None | Sequence[int] = ...,
71
+ axes: None | Sequence[int] = ...,
72
+ norm: _NormKind = ...,
73
+ ) -> NDArray[complex128]: ...
74
+
75
+ def irfftn(
76
+ a: ArrayLike,
77
+ s: None | Sequence[int] = ...,
78
+ axes: None | Sequence[int] = ...,
79
+ norm: _NormKind = ...,
80
+ ) -> NDArray[float64]: ...
81
+
82
+ def fft2(
83
+ a: ArrayLike,
84
+ s: None | Sequence[int] = ...,
85
+ axes: None | Sequence[int] = ...,
86
+ norm: _NormKind = ...,
87
+ ) -> NDArray[complex128]: ...
88
+
89
+ def ifft2(
90
+ a: ArrayLike,
91
+ s: None | Sequence[int] = ...,
92
+ axes: None | Sequence[int] = ...,
93
+ norm: _NormKind = ...,
94
+ ) -> NDArray[complex128]: ...
95
+
96
+ def rfft2(
97
+ a: ArrayLike,
98
+ s: None | Sequence[int] = ...,
99
+ axes: None | Sequence[int] = ...,
100
+ norm: _NormKind = ...,
101
+ ) -> NDArray[complex128]: ...
102
+
103
+ def irfft2(
104
+ a: ArrayLike,
105
+ s: None | Sequence[int] = ...,
106
+ axes: None | Sequence[int] = ...,
107
+ norm: _NormKind = ...,
108
+ ) -> NDArray[float64]: ...
moondream/lib/python3.10/site-packages/numpy/fft/_pocketfft_internal.cpython-310-x86_64-linux-gnu.so ADDED
Binary file (97 kB). View file
 
moondream/lib/python3.10/site-packages/numpy/fft/helper.py ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Discrete Fourier Transforms - helper.py
3
+
4
+ """
5
+ from numpy.core import integer, empty, arange, asarray, roll
6
+ from numpy.core.overrides import array_function_dispatch, set_module
7
+
8
+ # Created by Pearu Peterson, September 2002
9
+
10
+ __all__ = ['fftshift', 'ifftshift', 'fftfreq', 'rfftfreq']
11
+
12
+ integer_types = (int, integer)
13
+
14
+
15
+ def _fftshift_dispatcher(x, axes=None):
16
+ return (x,)
17
+
18
+
19
+ @array_function_dispatch(_fftshift_dispatcher, module='numpy.fft')
20
+ def fftshift(x, axes=None):
21
+ """
22
+ Shift the zero-frequency component to the center of the spectrum.
23
+
24
+ This function swaps half-spaces for all axes listed (defaults to all).
25
+ Note that ``y[0]`` is the Nyquist component only if ``len(x)`` is even.
26
+
27
+ Parameters
28
+ ----------
29
+ x : array_like
30
+ Input array.
31
+ axes : int or shape tuple, optional
32
+ Axes over which to shift. Default is None, which shifts all axes.
33
+
34
+ Returns
35
+ -------
36
+ y : ndarray
37
+ The shifted array.
38
+
39
+ See Also
40
+ --------
41
+ ifftshift : The inverse of `fftshift`.
42
+
43
+ Examples
44
+ --------
45
+ >>> freqs = np.fft.fftfreq(10, 0.1)
46
+ >>> freqs
47
+ array([ 0., 1., 2., ..., -3., -2., -1.])
48
+ >>> np.fft.fftshift(freqs)
49
+ array([-5., -4., -3., -2., -1., 0., 1., 2., 3., 4.])
50
+
51
+ Shift the zero-frequency component only along the second axis:
52
+
53
+ >>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
54
+ >>> freqs
55
+ array([[ 0., 1., 2.],
56
+ [ 3., 4., -4.],
57
+ [-3., -2., -1.]])
58
+ >>> np.fft.fftshift(freqs, axes=(1,))
59
+ array([[ 2., 0., 1.],
60
+ [-4., 3., 4.],
61
+ [-1., -3., -2.]])
62
+
63
+ """
64
+ x = asarray(x)
65
+ if axes is None:
66
+ axes = tuple(range(x.ndim))
67
+ shift = [dim // 2 for dim in x.shape]
68
+ elif isinstance(axes, integer_types):
69
+ shift = x.shape[axes] // 2
70
+ else:
71
+ shift = [x.shape[ax] // 2 for ax in axes]
72
+
73
+ return roll(x, shift, axes)
74
+
75
+
76
+ @array_function_dispatch(_fftshift_dispatcher, module='numpy.fft')
77
+ def ifftshift(x, axes=None):
78
+ """
79
+ The inverse of `fftshift`. Although identical for even-length `x`, the
80
+ functions differ by one sample for odd-length `x`.
81
+
82
+ Parameters
83
+ ----------
84
+ x : array_like
85
+ Input array.
86
+ axes : int or shape tuple, optional
87
+ Axes over which to calculate. Defaults to None, which shifts all axes.
88
+
89
+ Returns
90
+ -------
91
+ y : ndarray
92
+ The shifted array.
93
+
94
+ See Also
95
+ --------
96
+ fftshift : Shift zero-frequency component to the center of the spectrum.
97
+
98
+ Examples
99
+ --------
100
+ >>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
101
+ >>> freqs
102
+ array([[ 0., 1., 2.],
103
+ [ 3., 4., -4.],
104
+ [-3., -2., -1.]])
105
+ >>> np.fft.ifftshift(np.fft.fftshift(freqs))
106
+ array([[ 0., 1., 2.],
107
+ [ 3., 4., -4.],
108
+ [-3., -2., -1.]])
109
+
110
+ """
111
+ x = asarray(x)
112
+ if axes is None:
113
+ axes = tuple(range(x.ndim))
114
+ shift = [-(dim // 2) for dim in x.shape]
115
+ elif isinstance(axes, integer_types):
116
+ shift = -(x.shape[axes] // 2)
117
+ else:
118
+ shift = [-(x.shape[ax] // 2) for ax in axes]
119
+
120
+ return roll(x, shift, axes)
121
+
122
+
123
+ @set_module('numpy.fft')
124
+ def fftfreq(n, d=1.0):
125
+ """
126
+ Return the Discrete Fourier Transform sample frequencies.
127
+
128
+ The returned float array `f` contains the frequency bin centers in cycles
129
+ per unit of the sample spacing (with zero at the start). For instance, if
130
+ the sample spacing is in seconds, then the frequency unit is cycles/second.
131
+
132
+ Given a window length `n` and a sample spacing `d`::
133
+
134
+ f = [0, 1, ..., n/2-1, -n/2, ..., -1] / (d*n) if n is even
135
+ f = [0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (d*n) if n is odd
136
+
137
+ Parameters
138
+ ----------
139
+ n : int
140
+ Window length.
141
+ d : scalar, optional
142
+ Sample spacing (inverse of the sampling rate). Defaults to 1.
143
+
144
+ Returns
145
+ -------
146
+ f : ndarray
147
+ Array of length `n` containing the sample frequencies.
148
+
149
+ Examples
150
+ --------
151
+ >>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float)
152
+ >>> fourier = np.fft.fft(signal)
153
+ >>> n = signal.size
154
+ >>> timestep = 0.1
155
+ >>> freq = np.fft.fftfreq(n, d=timestep)
156
+ >>> freq
157
+ array([ 0. , 1.25, 2.5 , ..., -3.75, -2.5 , -1.25])
158
+
159
+ """
160
+ if not isinstance(n, integer_types):
161
+ raise ValueError("n should be an integer")
162
+ val = 1.0 / (n * d)
163
+ results = empty(n, int)
164
+ N = (n-1)//2 + 1
165
+ p1 = arange(0, N, dtype=int)
166
+ results[:N] = p1
167
+ p2 = arange(-(n//2), 0, dtype=int)
168
+ results[N:] = p2
169
+ return results * val
170
+
171
+
172
+ @set_module('numpy.fft')
173
+ def rfftfreq(n, d=1.0):
174
+ """
175
+ Return the Discrete Fourier Transform sample frequencies
176
+ (for usage with rfft, irfft).
177
+
178
+ The returned float array `f` contains the frequency bin centers in cycles
179
+ per unit of the sample spacing (with zero at the start). For instance, if
180
+ the sample spacing is in seconds, then the frequency unit is cycles/second.
181
+
182
+ Given a window length `n` and a sample spacing `d`::
183
+
184
+ f = [0, 1, ..., n/2-1, n/2] / (d*n) if n is even
185
+ f = [0, 1, ..., (n-1)/2-1, (n-1)/2] / (d*n) if n is odd
186
+
187
+ Unlike `fftfreq` (but like `scipy.fftpack.rfftfreq`)
188
+ the Nyquist frequency component is considered to be positive.
189
+
190
+ Parameters
191
+ ----------
192
+ n : int
193
+ Window length.
194
+ d : scalar, optional
195
+ Sample spacing (inverse of the sampling rate). Defaults to 1.
196
+
197
+ Returns
198
+ -------
199
+ f : ndarray
200
+ Array of length ``n//2 + 1`` containing the sample frequencies.
201
+
202
+ Examples
203
+ --------
204
+ >>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5, -3, 4], dtype=float)
205
+ >>> fourier = np.fft.rfft(signal)
206
+ >>> n = signal.size
207
+ >>> sample_rate = 100
208
+ >>> freq = np.fft.fftfreq(n, d=1./sample_rate)
209
+ >>> freq
210
+ array([ 0., 10., 20., ..., -30., -20., -10.])
211
+ >>> freq = np.fft.rfftfreq(n, d=1./sample_rate)
212
+ >>> freq
213
+ array([ 0., 10., 20., 30., 40., 50.])
214
+
215
+ """
216
+ if not isinstance(n, integer_types):
217
+ raise ValueError("n should be an integer")
218
+ val = 1.0/(n*d)
219
+ N = n//2 + 1
220
+ results = arange(0, N, dtype=int)
221
+ return results * val
moondream/lib/python3.10/site-packages/numpy/fft/helper.pyi ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, TypeVar, overload
2
+
3
+ from numpy import generic, integer, floating, complexfloating
4
+ from numpy._typing import (
5
+ NDArray,
6
+ ArrayLike,
7
+ _ShapeLike,
8
+ _ArrayLike,
9
+ _ArrayLikeFloat_co,
10
+ _ArrayLikeComplex_co,
11
+ )
12
+
13
+ _SCT = TypeVar("_SCT", bound=generic)
14
+
15
+ __all__: list[str]
16
+
17
+ @overload
18
+ def fftshift(x: _ArrayLike[_SCT], axes: None | _ShapeLike = ...) -> NDArray[_SCT]: ...
19
+ @overload
20
+ def fftshift(x: ArrayLike, axes: None | _ShapeLike = ...) -> NDArray[Any]: ...
21
+
22
+ @overload
23
+ def ifftshift(x: _ArrayLike[_SCT], axes: None | _ShapeLike = ...) -> NDArray[_SCT]: ...
24
+ @overload
25
+ def ifftshift(x: ArrayLike, axes: None | _ShapeLike = ...) -> NDArray[Any]: ...
26
+
27
+ @overload
28
+ def fftfreq(
29
+ n: int | integer[Any],
30
+ d: _ArrayLikeFloat_co = ...,
31
+ ) -> NDArray[floating[Any]]: ...
32
+ @overload
33
+ def fftfreq(
34
+ n: int | integer[Any],
35
+ d: _ArrayLikeComplex_co = ...,
36
+ ) -> NDArray[complexfloating[Any, Any]]: ...
37
+
38
+ @overload
39
+ def rfftfreq(
40
+ n: int | integer[Any],
41
+ d: _ArrayLikeFloat_co = ...,
42
+ ) -> NDArray[floating[Any]]: ...
43
+ @overload
44
+ def rfftfreq(
45
+ n: int | integer[Any],
46
+ d: _ArrayLikeComplex_co = ...,
47
+ ) -> NDArray[complexfloating[Any, Any]]: ...
moondream/lib/python3.10/site-packages/numpy/fft/tests/__init__.py ADDED
File without changes
moondream/lib/python3.10/site-packages/numpy/fft/tests/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (170 Bytes). View file