BryanW commited on
Commit
6c54293
·
verified ·
1 Parent(s): ce2a3d7

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. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/aiohappyeyeballs/__pycache__/_staggered.cpython-312.pyc +0 -0
  2. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/filelock-3.17.0.dist-info/licenses/LICENSE +24 -0
  3. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_add_newdocs_scalars.py +372 -0
  4. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_asarray.pyi +42 -0
  5. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_exceptions.py +172 -0
  6. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_internal.pyi +30 -0
  7. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_type_aliases.pyi +13 -0
  8. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_ufunc_config.py +466 -0
  9. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/arrayprint.py +1725 -0
  10. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/einsumfunc.py +1443 -0
  11. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/memmap.py +338 -0
  12. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/records.py +1099 -0
  13. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/records.pyi +234 -0
  14. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/shape_base.pyi +123 -0
  15. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/sacrebleu-2.6.0.dist-info/licenses/LICENSE.txt +201 -0
  16. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/tabulate/__pycache__/__init__.cpython-312.pyc +0 -0
  17. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/tabulate/__pycache__/version.cpython-312.pyc +0 -0
  18. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/__init__.cpython-312.pyc +0 -0
  19. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/_device_limits.cpython-312.pyc +0 -0
  20. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/_memory_viz.cpython-312.pyc +0 -0
  21. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/_pin_memory_utils.cpython-312.pyc +0 -0
  22. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/_utils.cpython-312.pyc +0 -0
  23. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/gds.cpython-312.pyc +0 -0
  24. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/graphs.cpython-312.pyc +0 -0
  25. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/green_contexts.cpython-312.pyc +0 -0
  26. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/memory.cpython-312.pyc +0 -0
  27. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/nvtx.cpython-312.pyc +0 -0
  28. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/profiler.cpython-312.pyc +0 -0
  29. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_adaptive_avg_pool3d_cpu_dispatch.h +29 -0
  30. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_assert_async_cpu_dispatch.h +29 -0
  31. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_autocast_to_full_precision_ops.h +34 -0
  32. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_efficient_attention_backward_cuda_dispatch.h +29 -0
  33. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_embedding_bag_native.h +28 -0
  34. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_fake_quantize_learnable_per_channel_affine_backward_cpu_dispatch.h +28 -0
  35. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_fft_r2c.h +45 -0
  36. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_foreach_sub_cuda_dispatch.h +33 -0
  37. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_fused_sdp_choice.h +36 -0
  38. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_has_same_storage_numel.h +36 -0
  39. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_masked_softmax_native.h +28 -0
  40. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_mkldnn_transpose_native.h +28 -0
  41. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_nested_tensor_size_ops.h +45 -0
  42. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_pdist_backward_native.h +27 -0
  43. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_triton_multi_head_attention_cuda_dispatch.h +28 -0
  44. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_validate_sparse_bsr_tensor_args.h +36 -0
  45. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/abs_native.h +36 -0
  46. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/asinh_cpu_dispatch.h +31 -0
  47. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/batch_norm_backward_elemt.h +45 -0
  48. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/batch_norm_backward_native.h +28 -0
  49. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/cdist.h +36 -0
  50. Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/conj_physical_cpu_dispatch.h +29 -0
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/aiohappyeyeballs/__pycache__/_staggered.cpython-312.pyc ADDED
Binary file (8.04 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/filelock-3.17.0.dist-info/licenses/LICENSE ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org>
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_add_newdocs_scalars.py ADDED
@@ -0,0 +1,372 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ This file is separate from ``_add_newdocs.py`` so that it can be mocked out by
3
+ our sphinx ``conf.py`` during doc builds, where we want to avoid showing
4
+ platform-dependent information.
5
+ """
6
+ import sys
7
+ import os
8
+ from numpy.core import dtype
9
+ from numpy.core import numerictypes as _numerictypes
10
+ from numpy.core.function_base import add_newdoc
11
+
12
+ ##############################################################################
13
+ #
14
+ # Documentation for concrete scalar classes
15
+ #
16
+ ##############################################################################
17
+
18
+ def numeric_type_aliases(aliases):
19
+ def type_aliases_gen():
20
+ for alias, doc in aliases:
21
+ try:
22
+ alias_type = getattr(_numerictypes, alias)
23
+ except AttributeError:
24
+ # The set of aliases that actually exist varies between platforms
25
+ pass
26
+ else:
27
+ yield (alias_type, alias, doc)
28
+ return list(type_aliases_gen())
29
+
30
+
31
+ possible_aliases = numeric_type_aliases([
32
+ ('int8', '8-bit signed integer (``-128`` to ``127``)'),
33
+ ('int16', '16-bit signed integer (``-32_768`` to ``32_767``)'),
34
+ ('int32', '32-bit signed integer (``-2_147_483_648`` to ``2_147_483_647``)'),
35
+ ('int64', '64-bit signed integer (``-9_223_372_036_854_775_808`` to ``9_223_372_036_854_775_807``)'),
36
+ ('intp', 'Signed integer large enough to fit pointer, compatible with C ``intptr_t``'),
37
+ ('uint8', '8-bit unsigned integer (``0`` to ``255``)'),
38
+ ('uint16', '16-bit unsigned integer (``0`` to ``65_535``)'),
39
+ ('uint32', '32-bit unsigned integer (``0`` to ``4_294_967_295``)'),
40
+ ('uint64', '64-bit unsigned integer (``0`` to ``18_446_744_073_709_551_615``)'),
41
+ ('uintp', 'Unsigned integer large enough to fit pointer, compatible with C ``uintptr_t``'),
42
+ ('float16', '16-bit-precision floating-point number type: sign bit, 5 bits exponent, 10 bits mantissa'),
43
+ ('float32', '32-bit-precision floating-point number type: sign bit, 8 bits exponent, 23 bits mantissa'),
44
+ ('float64', '64-bit precision floating-point number type: sign bit, 11 bits exponent, 52 bits mantissa'),
45
+ ('float96', '96-bit extended-precision floating-point number type'),
46
+ ('float128', '128-bit extended-precision floating-point number type'),
47
+ ('complex64', 'Complex number type composed of 2 32-bit-precision floating-point numbers'),
48
+ ('complex128', 'Complex number type composed of 2 64-bit-precision floating-point numbers'),
49
+ ('complex192', 'Complex number type composed of 2 96-bit extended-precision floating-point numbers'),
50
+ ('complex256', 'Complex number type composed of 2 128-bit extended-precision floating-point numbers'),
51
+ ])
52
+
53
+
54
+ def _get_platform_and_machine():
55
+ try:
56
+ system, _, _, _, machine = os.uname()
57
+ except AttributeError:
58
+ system = sys.platform
59
+ if system == 'win32':
60
+ machine = os.environ.get('PROCESSOR_ARCHITEW6432', '') \
61
+ or os.environ.get('PROCESSOR_ARCHITECTURE', '')
62
+ else:
63
+ machine = 'unknown'
64
+ return system, machine
65
+
66
+
67
+ _system, _machine = _get_platform_and_machine()
68
+ _doc_alias_string = f":Alias on this platform ({_system} {_machine}):"
69
+
70
+
71
+ def add_newdoc_for_scalar_type(obj, fixed_aliases, doc):
72
+ # note: `:field: value` is rST syntax which renders as field lists.
73
+ o = getattr(_numerictypes, obj)
74
+
75
+ character_code = dtype(o).char
76
+ canonical_name_doc = "" if obj == o.__name__ else \
77
+ f":Canonical name: `numpy.{obj}`\n "
78
+ if fixed_aliases:
79
+ alias_doc = ''.join(f":Alias: `numpy.{alias}`\n "
80
+ for alias in fixed_aliases)
81
+ else:
82
+ alias_doc = ''
83
+ alias_doc += ''.join(f"{_doc_alias_string} `numpy.{alias}`: {doc}.\n "
84
+ for (alias_type, alias, doc) in possible_aliases if alias_type is o)
85
+
86
+ docstring = f"""
87
+ {doc.strip()}
88
+
89
+ :Character code: ``'{character_code}'``
90
+ {canonical_name_doc}{alias_doc}
91
+ """
92
+
93
+ add_newdoc('numpy.core.numerictypes', obj, docstring)
94
+
95
+
96
+ add_newdoc_for_scalar_type('bool_', [],
97
+ """
98
+ Boolean type (True or False), stored as a byte.
99
+
100
+ .. warning::
101
+
102
+ The :class:`bool_` type is not a subclass of the :class:`int_` type
103
+ (the :class:`bool_` is not even a number type). This is different
104
+ than Python's default implementation of :class:`bool` as a
105
+ sub-class of :class:`int`.
106
+ """)
107
+
108
+ add_newdoc_for_scalar_type('byte', [],
109
+ """
110
+ Signed integer type, compatible with C ``char``.
111
+ """)
112
+
113
+ add_newdoc_for_scalar_type('short', [],
114
+ """
115
+ Signed integer type, compatible with C ``short``.
116
+ """)
117
+
118
+ add_newdoc_for_scalar_type('intc', [],
119
+ """
120
+ Signed integer type, compatible with C ``int``.
121
+ """)
122
+
123
+ add_newdoc_for_scalar_type('int_', [],
124
+ """
125
+ Signed integer type, compatible with Python `int` and C ``long``.
126
+ """)
127
+
128
+ add_newdoc_for_scalar_type('longlong', [],
129
+ """
130
+ Signed integer type, compatible with C ``long long``.
131
+ """)
132
+
133
+ add_newdoc_for_scalar_type('ubyte', [],
134
+ """
135
+ Unsigned integer type, compatible with C ``unsigned char``.
136
+ """)
137
+
138
+ add_newdoc_for_scalar_type('ushort', [],
139
+ """
140
+ Unsigned integer type, compatible with C ``unsigned short``.
141
+ """)
142
+
143
+ add_newdoc_for_scalar_type('uintc', [],
144
+ """
145
+ Unsigned integer type, compatible with C ``unsigned int``.
146
+ """)
147
+
148
+ add_newdoc_for_scalar_type('uint', [],
149
+ """
150
+ Unsigned integer type, compatible with C ``unsigned long``.
151
+ """)
152
+
153
+ add_newdoc_for_scalar_type('ulonglong', [],
154
+ """
155
+ Signed integer type, compatible with C ``unsigned long long``.
156
+ """)
157
+
158
+ add_newdoc_for_scalar_type('half', [],
159
+ """
160
+ Half-precision floating-point number type.
161
+ """)
162
+
163
+ add_newdoc_for_scalar_type('single', [],
164
+ """
165
+ Single-precision floating-point number type, compatible with C ``float``.
166
+ """)
167
+
168
+ add_newdoc_for_scalar_type('double', ['float_'],
169
+ """
170
+ Double-precision floating-point number type, compatible with Python `float`
171
+ and C ``double``.
172
+ """)
173
+
174
+ add_newdoc_for_scalar_type('longdouble', ['longfloat'],
175
+ """
176
+ Extended-precision floating-point number type, compatible with C
177
+ ``long double`` but not necessarily with IEEE 754 quadruple-precision.
178
+ """)
179
+
180
+ add_newdoc_for_scalar_type('csingle', ['singlecomplex'],
181
+ """
182
+ Complex number type composed of two single-precision floating-point
183
+ numbers.
184
+ """)
185
+
186
+ add_newdoc_for_scalar_type('cdouble', ['cfloat', 'complex_'],
187
+ """
188
+ Complex number type composed of two double-precision floating-point
189
+ numbers, compatible with Python `complex`.
190
+ """)
191
+
192
+ add_newdoc_for_scalar_type('clongdouble', ['clongfloat', 'longcomplex'],
193
+ """
194
+ Complex number type composed of two extended-precision floating-point
195
+ numbers.
196
+ """)
197
+
198
+ add_newdoc_for_scalar_type('object_', [],
199
+ """
200
+ Any Python object.
201
+ """)
202
+
203
+ add_newdoc_for_scalar_type('str_', ['unicode_'],
204
+ r"""
205
+ A unicode string.
206
+
207
+ This type strips trailing null codepoints.
208
+
209
+ >>> s = np.str_("abc\x00")
210
+ >>> s
211
+ 'abc'
212
+
213
+ Unlike the builtin `str`, this supports the :ref:`python:bufferobjects`, exposing its
214
+ contents as UCS4:
215
+
216
+ >>> m = memoryview(np.str_("abc"))
217
+ >>> m.format
218
+ '3w'
219
+ >>> m.tobytes()
220
+ b'a\x00\x00\x00b\x00\x00\x00c\x00\x00\x00'
221
+ """)
222
+
223
+ add_newdoc_for_scalar_type('bytes_', ['string_'],
224
+ r"""
225
+ A byte string.
226
+
227
+ When used in arrays, this type strips trailing null bytes.
228
+ """)
229
+
230
+ add_newdoc_for_scalar_type('void', [],
231
+ r"""
232
+ np.void(length_or_data, /, dtype=None)
233
+
234
+ Create a new structured or unstructured void scalar.
235
+
236
+ Parameters
237
+ ----------
238
+ length_or_data : int, array-like, bytes-like, object
239
+ One of multiple meanings (see notes). The length or
240
+ bytes data of an unstructured void. Or alternatively,
241
+ the data to be stored in the new scalar when `dtype`
242
+ is provided.
243
+ This can be an array-like, in which case an array may
244
+ be returned.
245
+ dtype : dtype, optional
246
+ If provided the dtype of the new scalar. This dtype must
247
+ be "void" dtype (i.e. a structured or unstructured void,
248
+ see also :ref:`defining-structured-types`).
249
+
250
+ ..versionadded:: 1.24
251
+
252
+ Notes
253
+ -----
254
+ For historical reasons and because void scalars can represent both
255
+ arbitrary byte data and structured dtypes, the void constructor
256
+ has three calling conventions:
257
+
258
+ 1. ``np.void(5)`` creates a ``dtype="V5"`` scalar filled with five
259
+ ``\0`` bytes. The 5 can be a Python or NumPy integer.
260
+ 2. ``np.void(b"bytes-like")`` creates a void scalar from the byte string.
261
+ The dtype itemsize will match the byte string length, here ``"V10"``.
262
+ 3. When a ``dtype=`` is passed the call is roughly the same as an
263
+ array creation. However, a void scalar rather than array is returned.
264
+
265
+ Please see the examples which show all three different conventions.
266
+
267
+ Examples
268
+ --------
269
+ >>> np.void(5)
270
+ void(b'\x00\x00\x00\x00\x00')
271
+ >>> np.void(b'abcd')
272
+ void(b'\x61\x62\x63\x64')
273
+ >>> np.void((5, 3.2, "eggs"), dtype="i,d,S5")
274
+ (5, 3.2, b'eggs') # looks like a tuple, but is `np.void`
275
+ >>> np.void(3, dtype=[('x', np.int8), ('y', np.int8)])
276
+ (3, 3) # looks like a tuple, but is `np.void`
277
+
278
+ """)
279
+
280
+ add_newdoc_for_scalar_type('datetime64', [],
281
+ """
282
+ If created from a 64-bit integer, it represents an offset from
283
+ ``1970-01-01T00:00:00``.
284
+ If created from string, the string can be in ISO 8601 date
285
+ or datetime format.
286
+
287
+ >>> np.datetime64(10, 'Y')
288
+ numpy.datetime64('1980')
289
+ >>> np.datetime64('1980', 'Y')
290
+ numpy.datetime64('1980')
291
+ >>> np.datetime64(10, 'D')
292
+ numpy.datetime64('1970-01-11')
293
+
294
+ See :ref:`arrays.datetime` for more information.
295
+ """)
296
+
297
+ add_newdoc_for_scalar_type('timedelta64', [],
298
+ """
299
+ A timedelta stored as a 64-bit integer.
300
+
301
+ See :ref:`arrays.datetime` for more information.
302
+ """)
303
+
304
+ add_newdoc('numpy.core.numerictypes', "integer", ('is_integer',
305
+ """
306
+ integer.is_integer() -> bool
307
+
308
+ Return ``True`` if the number is finite with integral value.
309
+
310
+ .. versionadded:: 1.22
311
+
312
+ Examples
313
+ --------
314
+ >>> np.int64(-2).is_integer()
315
+ True
316
+ >>> np.uint32(5).is_integer()
317
+ True
318
+ """))
319
+
320
+ # TODO: work out how to put this on the base class, np.floating
321
+ for float_name in ('half', 'single', 'double', 'longdouble'):
322
+ add_newdoc('numpy.core.numerictypes', float_name, ('as_integer_ratio',
323
+ """
324
+ {ftype}.as_integer_ratio() -> (int, int)
325
+
326
+ Return a pair of integers, whose ratio is exactly equal to the original
327
+ floating point number, and with a positive denominator.
328
+ Raise `OverflowError` on infinities and a `ValueError` on NaNs.
329
+
330
+ >>> np.{ftype}(10.0).as_integer_ratio()
331
+ (10, 1)
332
+ >>> np.{ftype}(0.0).as_integer_ratio()
333
+ (0, 1)
334
+ >>> np.{ftype}(-.25).as_integer_ratio()
335
+ (-1, 4)
336
+ """.format(ftype=float_name)))
337
+
338
+ add_newdoc('numpy.core.numerictypes', float_name, ('is_integer',
339
+ f"""
340
+ {float_name}.is_integer() -> bool
341
+
342
+ Return ``True`` if the floating point number is finite with integral
343
+ value, and ``False`` otherwise.
344
+
345
+ .. versionadded:: 1.22
346
+
347
+ Examples
348
+ --------
349
+ >>> np.{float_name}(-2.0).is_integer()
350
+ True
351
+ >>> np.{float_name}(3.2).is_integer()
352
+ False
353
+ """))
354
+
355
+ for int_name in ('int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32',
356
+ 'int64', 'uint64', 'int64', 'uint64', 'int64', 'uint64'):
357
+ # Add negative examples for signed cases by checking typecode
358
+ add_newdoc('numpy.core.numerictypes', int_name, ('bit_count',
359
+ f"""
360
+ {int_name}.bit_count() -> int
361
+
362
+ Computes the number of 1-bits in the absolute value of the input.
363
+ Analogous to the builtin `int.bit_count` or ``popcount`` in C++.
364
+
365
+ Examples
366
+ --------
367
+ >>> np.{int_name}(127).bit_count()
368
+ 7""" +
369
+ (f"""
370
+ >>> np.{int_name}(-127).bit_count()
371
+ 7
372
+ """ if dtype(int_name).char.islower() else "")))
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_asarray.pyi ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections.abc import Iterable
2
+ from typing import Any, TypeVar, Union, overload, Literal
3
+
4
+ from numpy import ndarray
5
+ from numpy._typing import DTypeLike, _SupportsArrayFunc
6
+
7
+ _ArrayType = TypeVar("_ArrayType", bound=ndarray[Any, Any])
8
+
9
+ _Requirements = Literal[
10
+ "C", "C_CONTIGUOUS", "CONTIGUOUS",
11
+ "F", "F_CONTIGUOUS", "FORTRAN",
12
+ "A", "ALIGNED",
13
+ "W", "WRITEABLE",
14
+ "O", "OWNDATA"
15
+ ]
16
+ _E = Literal["E", "ENSUREARRAY"]
17
+ _RequirementsWithE = Union[_Requirements, _E]
18
+
19
+ @overload
20
+ def require(
21
+ a: _ArrayType,
22
+ dtype: None = ...,
23
+ requirements: None | _Requirements | Iterable[_Requirements] = ...,
24
+ *,
25
+ like: _SupportsArrayFunc = ...
26
+ ) -> _ArrayType: ...
27
+ @overload
28
+ def require(
29
+ a: object,
30
+ dtype: DTypeLike = ...,
31
+ requirements: _E | Iterable[_RequirementsWithE] = ...,
32
+ *,
33
+ like: _SupportsArrayFunc = ...
34
+ ) -> ndarray[Any, Any]: ...
35
+ @overload
36
+ def require(
37
+ a: object,
38
+ dtype: DTypeLike = ...,
39
+ requirements: None | _Requirements | Iterable[_Requirements] = ...,
40
+ *,
41
+ like: _SupportsArrayFunc = ...
42
+ ) -> ndarray[Any, Any]: ...
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_exceptions.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Various richly-typed exceptions, that also help us deal with string formatting
3
+ in python where it's easier.
4
+
5
+ By putting the formatting in `__str__`, we also avoid paying the cost for
6
+ users who silence the exceptions.
7
+ """
8
+ from .._utils import set_module
9
+
10
+ def _unpack_tuple(tup):
11
+ if len(tup) == 1:
12
+ return tup[0]
13
+ else:
14
+ return tup
15
+
16
+
17
+ def _display_as_base(cls):
18
+ """
19
+ A decorator that makes an exception class look like its base.
20
+
21
+ We use this to hide subclasses that are implementation details - the user
22
+ should catch the base type, which is what the traceback will show them.
23
+
24
+ Classes decorated with this decorator are subject to removal without a
25
+ deprecation warning.
26
+ """
27
+ assert issubclass(cls, Exception)
28
+ cls.__name__ = cls.__base__.__name__
29
+ return cls
30
+
31
+
32
+ class UFuncTypeError(TypeError):
33
+ """ Base class for all ufunc exceptions """
34
+ def __init__(self, ufunc):
35
+ self.ufunc = ufunc
36
+
37
+
38
+ @_display_as_base
39
+ class _UFuncNoLoopError(UFuncTypeError):
40
+ """ Thrown when a ufunc loop cannot be found """
41
+ def __init__(self, ufunc, dtypes):
42
+ super().__init__(ufunc)
43
+ self.dtypes = tuple(dtypes)
44
+
45
+ def __str__(self):
46
+ return (
47
+ "ufunc {!r} did not contain a loop with signature matching types "
48
+ "{!r} -> {!r}"
49
+ ).format(
50
+ self.ufunc.__name__,
51
+ _unpack_tuple(self.dtypes[:self.ufunc.nin]),
52
+ _unpack_tuple(self.dtypes[self.ufunc.nin:])
53
+ )
54
+
55
+
56
+ @_display_as_base
57
+ class _UFuncBinaryResolutionError(_UFuncNoLoopError):
58
+ """ Thrown when a binary resolution fails """
59
+ def __init__(self, ufunc, dtypes):
60
+ super().__init__(ufunc, dtypes)
61
+ assert len(self.dtypes) == 2
62
+
63
+ def __str__(self):
64
+ return (
65
+ "ufunc {!r} cannot use operands with types {!r} and {!r}"
66
+ ).format(
67
+ self.ufunc.__name__, *self.dtypes
68
+ )
69
+
70
+
71
+ @_display_as_base
72
+ class _UFuncCastingError(UFuncTypeError):
73
+ def __init__(self, ufunc, casting, from_, to):
74
+ super().__init__(ufunc)
75
+ self.casting = casting
76
+ self.from_ = from_
77
+ self.to = to
78
+
79
+
80
+ @_display_as_base
81
+ class _UFuncInputCastingError(_UFuncCastingError):
82
+ """ Thrown when a ufunc input cannot be casted """
83
+ def __init__(self, ufunc, casting, from_, to, i):
84
+ super().__init__(ufunc, casting, from_, to)
85
+ self.in_i = i
86
+
87
+ def __str__(self):
88
+ # only show the number if more than one input exists
89
+ i_str = "{} ".format(self.in_i) if self.ufunc.nin != 1 else ""
90
+ return (
91
+ "Cannot cast ufunc {!r} input {}from {!r} to {!r} with casting "
92
+ "rule {!r}"
93
+ ).format(
94
+ self.ufunc.__name__, i_str, self.from_, self.to, self.casting
95
+ )
96
+
97
+
98
+ @_display_as_base
99
+ class _UFuncOutputCastingError(_UFuncCastingError):
100
+ """ Thrown when a ufunc output cannot be casted """
101
+ def __init__(self, ufunc, casting, from_, to, i):
102
+ super().__init__(ufunc, casting, from_, to)
103
+ self.out_i = i
104
+
105
+ def __str__(self):
106
+ # only show the number if more than one output exists
107
+ i_str = "{} ".format(self.out_i) if self.ufunc.nout != 1 else ""
108
+ return (
109
+ "Cannot cast ufunc {!r} output {}from {!r} to {!r} with casting "
110
+ "rule {!r}"
111
+ ).format(
112
+ self.ufunc.__name__, i_str, self.from_, self.to, self.casting
113
+ )
114
+
115
+
116
+ @_display_as_base
117
+ class _ArrayMemoryError(MemoryError):
118
+ """ Thrown when an array cannot be allocated"""
119
+ def __init__(self, shape, dtype):
120
+ self.shape = shape
121
+ self.dtype = dtype
122
+
123
+ @property
124
+ def _total_size(self):
125
+ num_bytes = self.dtype.itemsize
126
+ for dim in self.shape:
127
+ num_bytes *= dim
128
+ return num_bytes
129
+
130
+ @staticmethod
131
+ def _size_to_string(num_bytes):
132
+ """ Convert a number of bytes into a binary size string """
133
+
134
+ # https://en.wikipedia.org/wiki/Binary_prefix
135
+ LOG2_STEP = 10
136
+ STEP = 1024
137
+ units = ['bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB']
138
+
139
+ unit_i = max(num_bytes.bit_length() - 1, 1) // LOG2_STEP
140
+ unit_val = 1 << (unit_i * LOG2_STEP)
141
+ n_units = num_bytes / unit_val
142
+ del unit_val
143
+
144
+ # ensure we pick a unit that is correct after rounding
145
+ if round(n_units) == STEP:
146
+ unit_i += 1
147
+ n_units /= STEP
148
+
149
+ # deal with sizes so large that we don't have units for them
150
+ if unit_i >= len(units):
151
+ new_unit_i = len(units) - 1
152
+ n_units *= 1 << ((unit_i - new_unit_i) * LOG2_STEP)
153
+ unit_i = new_unit_i
154
+
155
+ unit_name = units[unit_i]
156
+ # format with a sensible number of digits
157
+ if unit_i == 0:
158
+ # no decimal point on bytes
159
+ return '{:.0f} {}'.format(n_units, unit_name)
160
+ elif round(n_units) < 1000:
161
+ # 3 significant figures, if none are dropped to the left of the .
162
+ return '{:#.3g} {}'.format(n_units, unit_name)
163
+ else:
164
+ # just give all the digits otherwise
165
+ return '{:#.0f} {}'.format(n_units, unit_name)
166
+
167
+ def __str__(self):
168
+ size_str = self._size_to_string(self._total_size)
169
+ return (
170
+ "Unable to allocate {} for an array with shape {} and data type {}"
171
+ .format(size_str, self.shape, self.dtype)
172
+ )
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_internal.pyi ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, TypeVar, overload, Generic
2
+ import ctypes as ct
3
+
4
+ from numpy import ndarray
5
+ from numpy.ctypeslib import c_intp
6
+
7
+ _CastT = TypeVar("_CastT", bound=ct._CanCastTo) # Copied from `ctypes.cast`
8
+ _CT = TypeVar("_CT", bound=ct._CData)
9
+ _PT = TypeVar("_PT", bound=None | int)
10
+
11
+ # TODO: Let the likes of `shape_as` and `strides_as` return `None`
12
+ # for 0D arrays once we've got shape-support
13
+
14
+ class _ctypes(Generic[_PT]):
15
+ @overload
16
+ def __new__(cls, array: ndarray[Any, Any], ptr: None = ...) -> _ctypes[None]: ...
17
+ @overload
18
+ def __new__(cls, array: ndarray[Any, Any], ptr: _PT) -> _ctypes[_PT]: ...
19
+ @property
20
+ def data(self) -> _PT: ...
21
+ @property
22
+ def shape(self) -> ct.Array[c_intp]: ...
23
+ @property
24
+ def strides(self) -> ct.Array[c_intp]: ...
25
+ @property
26
+ def _as_parameter_(self) -> ct.c_void_p: ...
27
+
28
+ def data_as(self, obj: type[_CastT]) -> _CastT: ...
29
+ def shape_as(self, obj: type[_CT]) -> ct.Array[_CT]: ...
30
+ def strides_as(self, obj: type[_CT]) -> ct.Array[_CT]: ...
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_type_aliases.pyi ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, TypedDict
2
+
3
+ from numpy import generic, signedinteger, unsignedinteger, floating, complexfloating
4
+
5
+ class _SCTypes(TypedDict):
6
+ int: list[type[signedinteger[Any]]]
7
+ uint: list[type[unsignedinteger[Any]]]
8
+ float: list[type[floating[Any]]]
9
+ complex: list[type[complexfloating[Any, Any]]]
10
+ others: list[type]
11
+
12
+ sctypeDict: dict[int | str, type[generic]]
13
+ sctypes: _SCTypes
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_ufunc_config.py ADDED
@@ -0,0 +1,466 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Functions for changing global ufunc configuration
3
+
4
+ This provides helpers which wrap `umath.geterrobj` and `umath.seterrobj`
5
+ """
6
+ import collections.abc
7
+ import contextlib
8
+ import contextvars
9
+
10
+ from .._utils import set_module
11
+ from .umath import (
12
+ UFUNC_BUFSIZE_DEFAULT,
13
+ ERR_IGNORE, ERR_WARN, ERR_RAISE, ERR_CALL, ERR_PRINT, ERR_LOG, ERR_DEFAULT,
14
+ SHIFT_DIVIDEBYZERO, SHIFT_OVERFLOW, SHIFT_UNDERFLOW, SHIFT_INVALID,
15
+ )
16
+ from . import umath
17
+
18
+ __all__ = [
19
+ "seterr", "geterr", "setbufsize", "getbufsize", "seterrcall", "geterrcall",
20
+ "errstate", '_no_nep50_warning'
21
+ ]
22
+
23
+ _errdict = {"ignore": ERR_IGNORE,
24
+ "warn": ERR_WARN,
25
+ "raise": ERR_RAISE,
26
+ "call": ERR_CALL,
27
+ "print": ERR_PRINT,
28
+ "log": ERR_LOG}
29
+
30
+ _errdict_rev = {value: key for key, value in _errdict.items()}
31
+
32
+
33
+ @set_module('numpy')
34
+ def seterr(all=None, divide=None, over=None, under=None, invalid=None):
35
+ """
36
+ Set how floating-point errors are handled.
37
+
38
+ Note that operations on integer scalar types (such as `int16`) are
39
+ handled like floating point, and are affected by these settings.
40
+
41
+ Parameters
42
+ ----------
43
+ all : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
44
+ Set treatment for all types of floating-point errors at once:
45
+
46
+ - ignore: Take no action when the exception occurs.
47
+ - warn: Print a `RuntimeWarning` (via the Python `warnings` module).
48
+ - raise: Raise a `FloatingPointError`.
49
+ - call: Call a function specified using the `seterrcall` function.
50
+ - print: Print a warning directly to ``stdout``.
51
+ - log: Record error in a Log object specified by `seterrcall`.
52
+
53
+ The default is not to change the current behavior.
54
+ divide : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
55
+ Treatment for division by zero.
56
+ over : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
57
+ Treatment for floating-point overflow.
58
+ under : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
59
+ Treatment for floating-point underflow.
60
+ invalid : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
61
+ Treatment for invalid floating-point operation.
62
+
63
+ Returns
64
+ -------
65
+ old_settings : dict
66
+ Dictionary containing the old settings.
67
+
68
+ See also
69
+ --------
70
+ seterrcall : Set a callback function for the 'call' mode.
71
+ geterr, geterrcall, errstate
72
+
73
+ Notes
74
+ -----
75
+ The floating-point exceptions are defined in the IEEE 754 standard [1]_:
76
+
77
+ - Division by zero: infinite result obtained from finite numbers.
78
+ - Overflow: result too large to be expressed.
79
+ - Underflow: result so close to zero that some precision
80
+ was lost.
81
+ - Invalid operation: result is not an expressible number, typically
82
+ indicates that a NaN was produced.
83
+
84
+ .. [1] https://en.wikipedia.org/wiki/IEEE_754
85
+
86
+ Examples
87
+ --------
88
+ >>> old_settings = np.seterr(all='ignore') #seterr to known value
89
+ >>> np.seterr(over='raise')
90
+ {'divide': 'ignore', 'over': 'ignore', 'under': 'ignore', 'invalid': 'ignore'}
91
+ >>> np.seterr(**old_settings) # reset to default
92
+ {'divide': 'ignore', 'over': 'raise', 'under': 'ignore', 'invalid': 'ignore'}
93
+
94
+ >>> np.int16(32000) * np.int16(3)
95
+ 30464
96
+ >>> old_settings = np.seterr(all='warn', over='raise')
97
+ >>> np.int16(32000) * np.int16(3)
98
+ Traceback (most recent call last):
99
+ File "<stdin>", line 1, in <module>
100
+ FloatingPointError: overflow encountered in scalar multiply
101
+
102
+ >>> old_settings = np.seterr(all='print')
103
+ >>> np.geterr()
104
+ {'divide': 'print', 'over': 'print', 'under': 'print', 'invalid': 'print'}
105
+ >>> np.int16(32000) * np.int16(3)
106
+ 30464
107
+
108
+ """
109
+
110
+ pyvals = umath.geterrobj()
111
+ old = geterr()
112
+
113
+ if divide is None:
114
+ divide = all or old['divide']
115
+ if over is None:
116
+ over = all or old['over']
117
+ if under is None:
118
+ under = all or old['under']
119
+ if invalid is None:
120
+ invalid = all or old['invalid']
121
+
122
+ maskvalue = ((_errdict[divide] << SHIFT_DIVIDEBYZERO) +
123
+ (_errdict[over] << SHIFT_OVERFLOW) +
124
+ (_errdict[under] << SHIFT_UNDERFLOW) +
125
+ (_errdict[invalid] << SHIFT_INVALID))
126
+
127
+ pyvals[1] = maskvalue
128
+ umath.seterrobj(pyvals)
129
+ return old
130
+
131
+
132
+ @set_module('numpy')
133
+ def geterr():
134
+ """
135
+ Get the current way of handling floating-point errors.
136
+
137
+ Returns
138
+ -------
139
+ res : dict
140
+ A dictionary with keys "divide", "over", "under", and "invalid",
141
+ whose values are from the strings "ignore", "print", "log", "warn",
142
+ "raise", and "call". The keys represent possible floating-point
143
+ exceptions, and the values define how these exceptions are handled.
144
+
145
+ See Also
146
+ --------
147
+ geterrcall, seterr, seterrcall
148
+
149
+ Notes
150
+ -----
151
+ For complete documentation of the types of floating-point exceptions and
152
+ treatment options, see `seterr`.
153
+
154
+ Examples
155
+ --------
156
+ >>> np.geterr()
157
+ {'divide': 'warn', 'over': 'warn', 'under': 'ignore', 'invalid': 'warn'}
158
+ >>> np.arange(3.) / np.arange(3.)
159
+ array([nan, 1., 1.])
160
+
161
+ >>> oldsettings = np.seterr(all='warn', over='raise')
162
+ >>> np.geterr()
163
+ {'divide': 'warn', 'over': 'raise', 'under': 'warn', 'invalid': 'warn'}
164
+ >>> np.arange(3.) / np.arange(3.)
165
+ array([nan, 1., 1.])
166
+
167
+ """
168
+ maskvalue = umath.geterrobj()[1]
169
+ mask = 7
170
+ res = {}
171
+ val = (maskvalue >> SHIFT_DIVIDEBYZERO) & mask
172
+ res['divide'] = _errdict_rev[val]
173
+ val = (maskvalue >> SHIFT_OVERFLOW) & mask
174
+ res['over'] = _errdict_rev[val]
175
+ val = (maskvalue >> SHIFT_UNDERFLOW) & mask
176
+ res['under'] = _errdict_rev[val]
177
+ val = (maskvalue >> SHIFT_INVALID) & mask
178
+ res['invalid'] = _errdict_rev[val]
179
+ return res
180
+
181
+
182
+ @set_module('numpy')
183
+ def setbufsize(size):
184
+ """
185
+ Set the size of the buffer used in ufuncs.
186
+
187
+ Parameters
188
+ ----------
189
+ size : int
190
+ Size of buffer.
191
+
192
+ """
193
+ if size > 10e6:
194
+ raise ValueError("Buffer size, %s, is too big." % size)
195
+ if size < 5:
196
+ raise ValueError("Buffer size, %s, is too small." % size)
197
+ if size % 16 != 0:
198
+ raise ValueError("Buffer size, %s, is not a multiple of 16." % size)
199
+
200
+ pyvals = umath.geterrobj()
201
+ old = getbufsize()
202
+ pyvals[0] = size
203
+ umath.seterrobj(pyvals)
204
+ return old
205
+
206
+
207
+ @set_module('numpy')
208
+ def getbufsize():
209
+ """
210
+ Return the size of the buffer used in ufuncs.
211
+
212
+ Returns
213
+ -------
214
+ getbufsize : int
215
+ Size of ufunc buffer in bytes.
216
+
217
+ """
218
+ return umath.geterrobj()[0]
219
+
220
+
221
+ @set_module('numpy')
222
+ def seterrcall(func):
223
+ """
224
+ Set the floating-point error callback function or log object.
225
+
226
+ There are two ways to capture floating-point error messages. The first
227
+ is to set the error-handler to 'call', using `seterr`. Then, set
228
+ the function to call using this function.
229
+
230
+ The second is to set the error-handler to 'log', using `seterr`.
231
+ Floating-point errors then trigger a call to the 'write' method of
232
+ the provided object.
233
+
234
+ Parameters
235
+ ----------
236
+ func : callable f(err, flag) or object with write method
237
+ Function to call upon floating-point errors ('call'-mode) or
238
+ object whose 'write' method is used to log such message ('log'-mode).
239
+
240
+ The call function takes two arguments. The first is a string describing
241
+ the type of error (such as "divide by zero", "overflow", "underflow",
242
+ or "invalid value"), and the second is the status flag. The flag is a
243
+ byte, whose four least-significant bits indicate the type of error, one
244
+ of "divide", "over", "under", "invalid"::
245
+
246
+ [0 0 0 0 divide over under invalid]
247
+
248
+ In other words, ``flags = divide + 2*over + 4*under + 8*invalid``.
249
+
250
+ If an object is provided, its write method should take one argument,
251
+ a string.
252
+
253
+ Returns
254
+ -------
255
+ h : callable, log instance or None
256
+ The old error handler.
257
+
258
+ See Also
259
+ --------
260
+ seterr, geterr, geterrcall
261
+
262
+ Examples
263
+ --------
264
+ Callback upon error:
265
+
266
+ >>> def err_handler(type, flag):
267
+ ... print("Floating point error (%s), with flag %s" % (type, flag))
268
+ ...
269
+
270
+ >>> saved_handler = np.seterrcall(err_handler)
271
+ >>> save_err = np.seterr(all='call')
272
+
273
+ >>> np.array([1, 2, 3]) / 0.0
274
+ Floating point error (divide by zero), with flag 1
275
+ array([inf, inf, inf])
276
+
277
+ >>> np.seterrcall(saved_handler)
278
+ <function err_handler at 0x...>
279
+ >>> np.seterr(**save_err)
280
+ {'divide': 'call', 'over': 'call', 'under': 'call', 'invalid': 'call'}
281
+
282
+ Log error message:
283
+
284
+ >>> class Log:
285
+ ... def write(self, msg):
286
+ ... print("LOG: %s" % msg)
287
+ ...
288
+
289
+ >>> log = Log()
290
+ >>> saved_handler = np.seterrcall(log)
291
+ >>> save_err = np.seterr(all='log')
292
+
293
+ >>> np.array([1, 2, 3]) / 0.0
294
+ LOG: Warning: divide by zero encountered in divide
295
+ array([inf, inf, inf])
296
+
297
+ >>> np.seterrcall(saved_handler)
298
+ <numpy.core.numeric.Log object at 0x...>
299
+ >>> np.seterr(**save_err)
300
+ {'divide': 'log', 'over': 'log', 'under': 'log', 'invalid': 'log'}
301
+
302
+ """
303
+ if func is not None and not isinstance(func, collections.abc.Callable):
304
+ if (not hasattr(func, 'write') or
305
+ not isinstance(func.write, collections.abc.Callable)):
306
+ raise ValueError("Only callable can be used as callback")
307
+ pyvals = umath.geterrobj()
308
+ old = geterrcall()
309
+ pyvals[2] = func
310
+ umath.seterrobj(pyvals)
311
+ return old
312
+
313
+
314
+ @set_module('numpy')
315
+ def geterrcall():
316
+ """
317
+ Return the current callback function used on floating-point errors.
318
+
319
+ When the error handling for a floating-point error (one of "divide",
320
+ "over", "under", or "invalid") is set to 'call' or 'log', the function
321
+ that is called or the log instance that is written to is returned by
322
+ `geterrcall`. This function or log instance has been set with
323
+ `seterrcall`.
324
+
325
+ Returns
326
+ -------
327
+ errobj : callable, log instance or None
328
+ The current error handler. If no handler was set through `seterrcall`,
329
+ ``None`` is returned.
330
+
331
+ See Also
332
+ --------
333
+ seterrcall, seterr, geterr
334
+
335
+ Notes
336
+ -----
337
+ For complete documentation of the types of floating-point exceptions and
338
+ treatment options, see `seterr`.
339
+
340
+ Examples
341
+ --------
342
+ >>> np.geterrcall() # we did not yet set a handler, returns None
343
+
344
+ >>> oldsettings = np.seterr(all='call')
345
+ >>> def err_handler(type, flag):
346
+ ... print("Floating point error (%s), with flag %s" % (type, flag))
347
+ >>> oldhandler = np.seterrcall(err_handler)
348
+ >>> np.array([1, 2, 3]) / 0.0
349
+ Floating point error (divide by zero), with flag 1
350
+ array([inf, inf, inf])
351
+
352
+ >>> cur_handler = np.geterrcall()
353
+ >>> cur_handler is err_handler
354
+ True
355
+
356
+ """
357
+ return umath.geterrobj()[2]
358
+
359
+
360
+ class _unspecified:
361
+ pass
362
+
363
+
364
+ _Unspecified = _unspecified()
365
+
366
+
367
+ @set_module('numpy')
368
+ class errstate(contextlib.ContextDecorator):
369
+ """
370
+ errstate(**kwargs)
371
+
372
+ Context manager for floating-point error handling.
373
+
374
+ Using an instance of `errstate` as a context manager allows statements in
375
+ that context to execute with a known error handling behavior. Upon entering
376
+ the context the error handling is set with `seterr` and `seterrcall`, and
377
+ upon exiting it is reset to what it was before.
378
+
379
+ .. versionchanged:: 1.17.0
380
+ `errstate` is also usable as a function decorator, saving
381
+ a level of indentation if an entire function is wrapped.
382
+ See :py:class:`contextlib.ContextDecorator` for more information.
383
+
384
+ Parameters
385
+ ----------
386
+ kwargs : {divide, over, under, invalid}
387
+ Keyword arguments. The valid keywords are the possible floating-point
388
+ exceptions. Each keyword should have a string value that defines the
389
+ treatment for the particular error. Possible values are
390
+ {'ignore', 'warn', 'raise', 'call', 'print', 'log'}.
391
+
392
+ See Also
393
+ --------
394
+ seterr, geterr, seterrcall, geterrcall
395
+
396
+ Notes
397
+ -----
398
+ For complete documentation of the types of floating-point exceptions and
399
+ treatment options, see `seterr`.
400
+
401
+ Examples
402
+ --------
403
+ >>> olderr = np.seterr(all='ignore') # Set error handling to known state.
404
+
405
+ >>> np.arange(3) / 0.
406
+ array([nan, inf, inf])
407
+ >>> with np.errstate(divide='warn'):
408
+ ... np.arange(3) / 0.
409
+ array([nan, inf, inf])
410
+
411
+ >>> np.sqrt(-1)
412
+ nan
413
+ >>> with np.errstate(invalid='raise'):
414
+ ... np.sqrt(-1)
415
+ Traceback (most recent call last):
416
+ File "<stdin>", line 2, in <module>
417
+ FloatingPointError: invalid value encountered in sqrt
418
+
419
+ Outside the context the error handling behavior has not changed:
420
+
421
+ >>> np.geterr()
422
+ {'divide': 'ignore', 'over': 'ignore', 'under': 'ignore', 'invalid': 'ignore'}
423
+
424
+ """
425
+
426
+ def __init__(self, *, call=_Unspecified, **kwargs):
427
+ self.call = call
428
+ self.kwargs = kwargs
429
+
430
+ def __enter__(self):
431
+ self.oldstate = seterr(**self.kwargs)
432
+ if self.call is not _Unspecified:
433
+ self.oldcall = seterrcall(self.call)
434
+
435
+ def __exit__(self, *exc_info):
436
+ seterr(**self.oldstate)
437
+ if self.call is not _Unspecified:
438
+ seterrcall(self.oldcall)
439
+
440
+
441
+ def _setdef():
442
+ defval = [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT, None]
443
+ umath.seterrobj(defval)
444
+
445
+
446
+ # set the default values
447
+ _setdef()
448
+
449
+
450
+ NO_NEP50_WARNING = contextvars.ContextVar("_no_nep50_warning", default=False)
451
+
452
+ @set_module('numpy')
453
+ @contextlib.contextmanager
454
+ def _no_nep50_warning():
455
+ """
456
+ Context manager to disable NEP 50 warnings. This context manager is
457
+ only relevant if the NEP 50 warnings are enabled globally (which is not
458
+ thread/context safe).
459
+
460
+ This warning context manager itself is fully safe, however.
461
+ """
462
+ token = NO_NEP50_WARNING.set(True)
463
+ try:
464
+ yield
465
+ finally:
466
+ NO_NEP50_WARNING.reset(token)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/arrayprint.py ADDED
@@ -0,0 +1,1725 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Array printing function
2
+
3
+ $Id: arrayprint.py,v 1.9 2005/09/13 13:58:44 teoliphant Exp $
4
+
5
+ """
6
+ __all__ = ["array2string", "array_str", "array_repr", "set_string_function",
7
+ "set_printoptions", "get_printoptions", "printoptions",
8
+ "format_float_positional", "format_float_scientific"]
9
+ __docformat__ = 'restructuredtext'
10
+
11
+ #
12
+ # Written by Konrad Hinsen <hinsenk@ere.umontreal.ca>
13
+ # last revision: 1996-3-13
14
+ # modified by Jim Hugunin 1997-3-3 for repr's and str's (and other details)
15
+ # and by Perry Greenfield 2000-4-1 for numarray
16
+ # and by Travis Oliphant 2005-8-22 for numpy
17
+
18
+
19
+ # Note: Both scalartypes.c.src and arrayprint.py implement strs for numpy
20
+ # scalars but for different purposes. scalartypes.c.src has str/reprs for when
21
+ # the scalar is printed on its own, while arrayprint.py has strs for when
22
+ # scalars are printed inside an ndarray. Only the latter strs are currently
23
+ # user-customizable.
24
+
25
+ import functools
26
+ import numbers
27
+ import sys
28
+ try:
29
+ from _thread import get_ident
30
+ except ImportError:
31
+ from _dummy_thread import get_ident
32
+
33
+ import numpy as np
34
+ from . import numerictypes as _nt
35
+ from .umath import absolute, isinf, isfinite, isnat
36
+ from . import multiarray
37
+ from .multiarray import (array, dragon4_positional, dragon4_scientific,
38
+ datetime_as_string, datetime_data, ndarray,
39
+ set_legacy_print_mode)
40
+ from .fromnumeric import any
41
+ from .numeric import concatenate, asarray, errstate
42
+ from .numerictypes import (longlong, intc, int_, float_, complex_, bool_,
43
+ flexible)
44
+ from .overrides import array_function_dispatch, set_module
45
+ import operator
46
+ import warnings
47
+ import contextlib
48
+
49
+ _format_options = {
50
+ 'edgeitems': 3, # repr N leading and trailing items of each dimension
51
+ 'threshold': 1000, # total items > triggers array summarization
52
+ 'floatmode': 'maxprec',
53
+ 'precision': 8, # precision of floating point representations
54
+ 'suppress': False, # suppress printing small floating values in exp format
55
+ 'linewidth': 75,
56
+ 'nanstr': 'nan',
57
+ 'infstr': 'inf',
58
+ 'sign': '-',
59
+ 'formatter': None,
60
+ # Internally stored as an int to simplify comparisons; converted from/to
61
+ # str/False on the way in/out.
62
+ 'legacy': sys.maxsize}
63
+
64
+ def _make_options_dict(precision=None, threshold=None, edgeitems=None,
65
+ linewidth=None, suppress=None, nanstr=None, infstr=None,
66
+ sign=None, formatter=None, floatmode=None, legacy=None):
67
+ """
68
+ Make a dictionary out of the non-None arguments, plus conversion of
69
+ *legacy* and sanity checks.
70
+ """
71
+
72
+ options = {k: v for k, v in locals().items() if v is not None}
73
+
74
+ if suppress is not None:
75
+ options['suppress'] = bool(suppress)
76
+
77
+ modes = ['fixed', 'unique', 'maxprec', 'maxprec_equal']
78
+ if floatmode not in modes + [None]:
79
+ raise ValueError("floatmode option must be one of " +
80
+ ", ".join('"{}"'.format(m) for m in modes))
81
+
82
+ if sign not in [None, '-', '+', ' ']:
83
+ raise ValueError("sign option must be one of ' ', '+', or '-'")
84
+
85
+ if legacy == False:
86
+ options['legacy'] = sys.maxsize
87
+ elif legacy == '1.13':
88
+ options['legacy'] = 113
89
+ elif legacy == '1.21':
90
+ options['legacy'] = 121
91
+ elif legacy is None:
92
+ pass # OK, do nothing.
93
+ else:
94
+ warnings.warn(
95
+ "legacy printing option can currently only be '1.13', '1.21', or "
96
+ "`False`", stacklevel=3)
97
+
98
+ if threshold is not None:
99
+ # forbid the bad threshold arg suggested by stack overflow, gh-12351
100
+ if not isinstance(threshold, numbers.Number):
101
+ raise TypeError("threshold must be numeric")
102
+ if np.isnan(threshold):
103
+ raise ValueError("threshold must be non-NAN, try "
104
+ "sys.maxsize for untruncated representation")
105
+
106
+ if precision is not None:
107
+ # forbid the bad precision arg as suggested by issue #18254
108
+ try:
109
+ options['precision'] = operator.index(precision)
110
+ except TypeError as e:
111
+ raise TypeError('precision must be an integer') from e
112
+
113
+ return options
114
+
115
+
116
+ @set_module('numpy')
117
+ def set_printoptions(precision=None, threshold=None, edgeitems=None,
118
+ linewidth=None, suppress=None, nanstr=None, infstr=None,
119
+ formatter=None, sign=None, floatmode=None, *, legacy=None):
120
+ """
121
+ Set printing options.
122
+
123
+ These options determine the way floating point numbers, arrays and
124
+ other NumPy objects are displayed.
125
+
126
+ Parameters
127
+ ----------
128
+ precision : int or None, optional
129
+ Number of digits of precision for floating point output (default 8).
130
+ May be None if `floatmode` is not `fixed`, to print as many digits as
131
+ necessary to uniquely specify the value.
132
+ threshold : int, optional
133
+ Total number of array elements which trigger summarization
134
+ rather than full repr (default 1000).
135
+ To always use the full repr without summarization, pass `sys.maxsize`.
136
+ edgeitems : int, optional
137
+ Number of array items in summary at beginning and end of
138
+ each dimension (default 3).
139
+ linewidth : int, optional
140
+ The number of characters per line for the purpose of inserting
141
+ line breaks (default 75).
142
+ suppress : bool, optional
143
+ If True, always print floating point numbers using fixed point
144
+ notation, in which case numbers equal to zero in the current precision
145
+ will print as zero. If False, then scientific notation is used when
146
+ absolute value of the smallest number is < 1e-4 or the ratio of the
147
+ maximum absolute value to the minimum is > 1e3. The default is False.
148
+ nanstr : str, optional
149
+ String representation of floating point not-a-number (default nan).
150
+ infstr : str, optional
151
+ String representation of floating point infinity (default inf).
152
+ sign : string, either '-', '+', or ' ', optional
153
+ Controls printing of the sign of floating-point types. If '+', always
154
+ print the sign of positive values. If ' ', always prints a space
155
+ (whitespace character) in the sign position of positive values. If
156
+ '-', omit the sign character of positive values. (default '-')
157
+ formatter : dict of callables, optional
158
+ If not None, the keys should indicate the type(s) that the respective
159
+ formatting function applies to. Callables should return a string.
160
+ Types that are not specified (by their corresponding keys) are handled
161
+ by the default formatters. Individual types for which a formatter
162
+ can be set are:
163
+
164
+ - 'bool'
165
+ - 'int'
166
+ - 'timedelta' : a `numpy.timedelta64`
167
+ - 'datetime' : a `numpy.datetime64`
168
+ - 'float'
169
+ - 'longfloat' : 128-bit floats
170
+ - 'complexfloat'
171
+ - 'longcomplexfloat' : composed of two 128-bit floats
172
+ - 'numpystr' : types `numpy.bytes_` and `numpy.str_`
173
+ - 'object' : `np.object_` arrays
174
+
175
+ Other keys that can be used to set a group of types at once are:
176
+
177
+ - 'all' : sets all types
178
+ - 'int_kind' : sets 'int'
179
+ - 'float_kind' : sets 'float' and 'longfloat'
180
+ - 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat'
181
+ - 'str_kind' : sets 'numpystr'
182
+ floatmode : str, optional
183
+ Controls the interpretation of the `precision` option for
184
+ floating-point types. Can take the following values
185
+ (default maxprec_equal):
186
+
187
+ * 'fixed': Always print exactly `precision` fractional digits,
188
+ even if this would print more or fewer digits than
189
+ necessary to specify the value uniquely.
190
+ * 'unique': Print the minimum number of fractional digits necessary
191
+ to represent each value uniquely. Different elements may
192
+ have a different number of digits. The value of the
193
+ `precision` option is ignored.
194
+ * 'maxprec': Print at most `precision` fractional digits, but if
195
+ an element can be uniquely represented with fewer digits
196
+ only print it with that many.
197
+ * 'maxprec_equal': Print at most `precision` fractional digits,
198
+ but if every element in the array can be uniquely
199
+ represented with an equal number of fewer digits, use that
200
+ many digits for all elements.
201
+ legacy : string or `False`, optional
202
+ If set to the string `'1.13'` enables 1.13 legacy printing mode. This
203
+ approximates numpy 1.13 print output by including a space in the sign
204
+ position of floats and different behavior for 0d arrays. This also
205
+ enables 1.21 legacy printing mode (described below).
206
+
207
+ If set to the string `'1.21'` enables 1.21 legacy printing mode. This
208
+ approximates numpy 1.21 print output of complex structured dtypes
209
+ by not inserting spaces after commas that separate fields and after
210
+ colons.
211
+
212
+ If set to `False`, disables legacy mode.
213
+
214
+ Unrecognized strings will be ignored with a warning for forward
215
+ compatibility.
216
+
217
+ .. versionadded:: 1.14.0
218
+ .. versionchanged:: 1.22.0
219
+
220
+ See Also
221
+ --------
222
+ get_printoptions, printoptions, set_string_function, array2string
223
+
224
+ Notes
225
+ -----
226
+ `formatter` is always reset with a call to `set_printoptions`.
227
+
228
+ Use `printoptions` as a context manager to set the values temporarily.
229
+
230
+ Examples
231
+ --------
232
+ Floating point precision can be set:
233
+
234
+ >>> np.set_printoptions(precision=4)
235
+ >>> np.array([1.123456789])
236
+ [1.1235]
237
+
238
+ Long arrays can be summarised:
239
+
240
+ >>> np.set_printoptions(threshold=5)
241
+ >>> np.arange(10)
242
+ array([0, 1, 2, ..., 7, 8, 9])
243
+
244
+ Small results can be suppressed:
245
+
246
+ >>> eps = np.finfo(float).eps
247
+ >>> x = np.arange(4.)
248
+ >>> x**2 - (x + eps)**2
249
+ array([-4.9304e-32, -4.4409e-16, 0.0000e+00, 0.0000e+00])
250
+ >>> np.set_printoptions(suppress=True)
251
+ >>> x**2 - (x + eps)**2
252
+ array([-0., -0., 0., 0.])
253
+
254
+ A custom formatter can be used to display array elements as desired:
255
+
256
+ >>> np.set_printoptions(formatter={'all':lambda x: 'int: '+str(-x)})
257
+ >>> x = np.arange(3)
258
+ >>> x
259
+ array([int: 0, int: -1, int: -2])
260
+ >>> np.set_printoptions() # formatter gets reset
261
+ >>> x
262
+ array([0, 1, 2])
263
+
264
+ To put back the default options, you can use:
265
+
266
+ >>> np.set_printoptions(edgeitems=3, infstr='inf',
267
+ ... linewidth=75, nanstr='nan', precision=8,
268
+ ... suppress=False, threshold=1000, formatter=None)
269
+
270
+ Also to temporarily override options, use `printoptions` as a context manager:
271
+
272
+ >>> with np.printoptions(precision=2, suppress=True, threshold=5):
273
+ ... np.linspace(0, 10, 10)
274
+ array([ 0. , 1.11, 2.22, ..., 7.78, 8.89, 10. ])
275
+
276
+ """
277
+ opt = _make_options_dict(precision, threshold, edgeitems, linewidth,
278
+ suppress, nanstr, infstr, sign, formatter,
279
+ floatmode, legacy)
280
+ # formatter is always reset
281
+ opt['formatter'] = formatter
282
+ _format_options.update(opt)
283
+
284
+ # set the C variable for legacy mode
285
+ if _format_options['legacy'] == 113:
286
+ set_legacy_print_mode(113)
287
+ # reset the sign option in legacy mode to avoid confusion
288
+ _format_options['sign'] = '-'
289
+ elif _format_options['legacy'] == 121:
290
+ set_legacy_print_mode(121)
291
+ elif _format_options['legacy'] == sys.maxsize:
292
+ set_legacy_print_mode(0)
293
+
294
+
295
+ @set_module('numpy')
296
+ def get_printoptions():
297
+ """
298
+ Return the current print options.
299
+
300
+ Returns
301
+ -------
302
+ print_opts : dict
303
+ Dictionary of current print options with keys
304
+
305
+ - precision : int
306
+ - threshold : int
307
+ - edgeitems : int
308
+ - linewidth : int
309
+ - suppress : bool
310
+ - nanstr : str
311
+ - infstr : str
312
+ - formatter : dict of callables
313
+ - sign : str
314
+
315
+ For a full description of these options, see `set_printoptions`.
316
+
317
+ See Also
318
+ --------
319
+ set_printoptions, printoptions, set_string_function
320
+
321
+ """
322
+ opts = _format_options.copy()
323
+ opts['legacy'] = {
324
+ 113: '1.13', 121: '1.21', sys.maxsize: False,
325
+ }[opts['legacy']]
326
+ return opts
327
+
328
+
329
+ def _get_legacy_print_mode():
330
+ """Return the legacy print mode as an int."""
331
+ return _format_options['legacy']
332
+
333
+
334
+ @set_module('numpy')
335
+ @contextlib.contextmanager
336
+ def printoptions(*args, **kwargs):
337
+ """Context manager for setting print options.
338
+
339
+ Set print options for the scope of the `with` block, and restore the old
340
+ options at the end. See `set_printoptions` for the full description of
341
+ available options.
342
+
343
+ Examples
344
+ --------
345
+
346
+ >>> from numpy.testing import assert_equal
347
+ >>> with np.printoptions(precision=2):
348
+ ... np.array([2.0]) / 3
349
+ array([0.67])
350
+
351
+ The `as`-clause of the `with`-statement gives the current print options:
352
+
353
+ >>> with np.printoptions(precision=2) as opts:
354
+ ... assert_equal(opts, np.get_printoptions())
355
+
356
+ See Also
357
+ --------
358
+ set_printoptions, get_printoptions
359
+
360
+ """
361
+ opts = np.get_printoptions()
362
+ try:
363
+ np.set_printoptions(*args, **kwargs)
364
+ yield np.get_printoptions()
365
+ finally:
366
+ np.set_printoptions(**opts)
367
+
368
+
369
+ def _leading_trailing(a, edgeitems, index=()):
370
+ """
371
+ Keep only the N-D corners (leading and trailing edges) of an array.
372
+
373
+ Should be passed a base-class ndarray, since it makes no guarantees about
374
+ preserving subclasses.
375
+ """
376
+ axis = len(index)
377
+ if axis == a.ndim:
378
+ return a[index]
379
+
380
+ if a.shape[axis] > 2*edgeitems:
381
+ return concatenate((
382
+ _leading_trailing(a, edgeitems, index + np.index_exp[ :edgeitems]),
383
+ _leading_trailing(a, edgeitems, index + np.index_exp[-edgeitems:])
384
+ ), axis=axis)
385
+ else:
386
+ return _leading_trailing(a, edgeitems, index + np.index_exp[:])
387
+
388
+
389
+ def _object_format(o):
390
+ """ Object arrays containing lists should be printed unambiguously """
391
+ if type(o) is list:
392
+ fmt = 'list({!r})'
393
+ else:
394
+ fmt = '{!r}'
395
+ return fmt.format(o)
396
+
397
+ def repr_format(x):
398
+ return repr(x)
399
+
400
+ def str_format(x):
401
+ return str(x)
402
+
403
+ def _get_formatdict(data, *, precision, floatmode, suppress, sign, legacy,
404
+ formatter, **kwargs):
405
+ # note: extra arguments in kwargs are ignored
406
+
407
+ # wrapped in lambdas to avoid taking a code path with the wrong type of data
408
+ formatdict = {
409
+ 'bool': lambda: BoolFormat(data),
410
+ 'int': lambda: IntegerFormat(data),
411
+ 'float': lambda: FloatingFormat(
412
+ data, precision, floatmode, suppress, sign, legacy=legacy),
413
+ 'longfloat': lambda: FloatingFormat(
414
+ data, precision, floatmode, suppress, sign, legacy=legacy),
415
+ 'complexfloat': lambda: ComplexFloatingFormat(
416
+ data, precision, floatmode, suppress, sign, legacy=legacy),
417
+ 'longcomplexfloat': lambda: ComplexFloatingFormat(
418
+ data, precision, floatmode, suppress, sign, legacy=legacy),
419
+ 'datetime': lambda: DatetimeFormat(data, legacy=legacy),
420
+ 'timedelta': lambda: TimedeltaFormat(data),
421
+ 'object': lambda: _object_format,
422
+ 'void': lambda: str_format,
423
+ 'numpystr': lambda: repr_format}
424
+
425
+ # we need to wrap values in `formatter` in a lambda, so that the interface
426
+ # is the same as the above values.
427
+ def indirect(x):
428
+ return lambda: x
429
+
430
+ if formatter is not None:
431
+ fkeys = [k for k in formatter.keys() if formatter[k] is not None]
432
+ if 'all' in fkeys:
433
+ for key in formatdict.keys():
434
+ formatdict[key] = indirect(formatter['all'])
435
+ if 'int_kind' in fkeys:
436
+ for key in ['int']:
437
+ formatdict[key] = indirect(formatter['int_kind'])
438
+ if 'float_kind' in fkeys:
439
+ for key in ['float', 'longfloat']:
440
+ formatdict[key] = indirect(formatter['float_kind'])
441
+ if 'complex_kind' in fkeys:
442
+ for key in ['complexfloat', 'longcomplexfloat']:
443
+ formatdict[key] = indirect(formatter['complex_kind'])
444
+ if 'str_kind' in fkeys:
445
+ formatdict['numpystr'] = indirect(formatter['str_kind'])
446
+ for key in formatdict.keys():
447
+ if key in fkeys:
448
+ formatdict[key] = indirect(formatter[key])
449
+
450
+ return formatdict
451
+
452
+ def _get_format_function(data, **options):
453
+ """
454
+ find the right formatting function for the dtype_
455
+ """
456
+ dtype_ = data.dtype
457
+ dtypeobj = dtype_.type
458
+ formatdict = _get_formatdict(data, **options)
459
+ if dtypeobj is None:
460
+ return formatdict["numpystr"]()
461
+ elif issubclass(dtypeobj, _nt.bool_):
462
+ return formatdict['bool']()
463
+ elif issubclass(dtypeobj, _nt.integer):
464
+ if issubclass(dtypeobj, _nt.timedelta64):
465
+ return formatdict['timedelta']()
466
+ else:
467
+ return formatdict['int']()
468
+ elif issubclass(dtypeobj, _nt.floating):
469
+ if issubclass(dtypeobj, _nt.longfloat):
470
+ return formatdict['longfloat']()
471
+ else:
472
+ return formatdict['float']()
473
+ elif issubclass(dtypeobj, _nt.complexfloating):
474
+ if issubclass(dtypeobj, _nt.clongfloat):
475
+ return formatdict['longcomplexfloat']()
476
+ else:
477
+ return formatdict['complexfloat']()
478
+ elif issubclass(dtypeobj, (_nt.str_, _nt.bytes_)):
479
+ return formatdict['numpystr']()
480
+ elif issubclass(dtypeobj, _nt.datetime64):
481
+ return formatdict['datetime']()
482
+ elif issubclass(dtypeobj, _nt.object_):
483
+ return formatdict['object']()
484
+ elif issubclass(dtypeobj, _nt.void):
485
+ if dtype_.names is not None:
486
+ return StructuredVoidFormat.from_data(data, **options)
487
+ else:
488
+ return formatdict['void']()
489
+ else:
490
+ return formatdict['numpystr']()
491
+
492
+
493
+ def _recursive_guard(fillvalue='...'):
494
+ """
495
+ Like the python 3.2 reprlib.recursive_repr, but forwards *args and **kwargs
496
+
497
+ Decorates a function such that if it calls itself with the same first
498
+ argument, it returns `fillvalue` instead of recursing.
499
+
500
+ Largely copied from reprlib.recursive_repr
501
+ """
502
+
503
+ def decorating_function(f):
504
+ repr_running = set()
505
+
506
+ @functools.wraps(f)
507
+ def wrapper(self, *args, **kwargs):
508
+ key = id(self), get_ident()
509
+ if key in repr_running:
510
+ return fillvalue
511
+ repr_running.add(key)
512
+ try:
513
+ return f(self, *args, **kwargs)
514
+ finally:
515
+ repr_running.discard(key)
516
+
517
+ return wrapper
518
+
519
+ return decorating_function
520
+
521
+
522
+ # gracefully handle recursive calls, when object arrays contain themselves
523
+ @_recursive_guard()
524
+ def _array2string(a, options, separator=' ', prefix=""):
525
+ # The formatter __init__s in _get_format_function cannot deal with
526
+ # subclasses yet, and we also need to avoid recursion issues in
527
+ # _formatArray with subclasses which return 0d arrays in place of scalars
528
+ data = asarray(a)
529
+ if a.shape == ():
530
+ a = data
531
+
532
+ if a.size > options['threshold']:
533
+ summary_insert = "..."
534
+ data = _leading_trailing(data, options['edgeitems'])
535
+ else:
536
+ summary_insert = ""
537
+
538
+ # find the right formatting function for the array
539
+ format_function = _get_format_function(data, **options)
540
+
541
+ # skip over "["
542
+ next_line_prefix = " "
543
+ # skip over array(
544
+ next_line_prefix += " "*len(prefix)
545
+
546
+ lst = _formatArray(a, format_function, options['linewidth'],
547
+ next_line_prefix, separator, options['edgeitems'],
548
+ summary_insert, options['legacy'])
549
+ return lst
550
+
551
+
552
+ def _array2string_dispatcher(
553
+ a, max_line_width=None, precision=None,
554
+ suppress_small=None, separator=None, prefix=None,
555
+ style=None, formatter=None, threshold=None,
556
+ edgeitems=None, sign=None, floatmode=None, suffix=None,
557
+ *, legacy=None):
558
+ return (a,)
559
+
560
+
561
+ @array_function_dispatch(_array2string_dispatcher, module='numpy')
562
+ def array2string(a, max_line_width=None, precision=None,
563
+ suppress_small=None, separator=' ', prefix="",
564
+ style=np._NoValue, formatter=None, threshold=None,
565
+ edgeitems=None, sign=None, floatmode=None, suffix="",
566
+ *, legacy=None):
567
+ """
568
+ Return a string representation of an array.
569
+
570
+ Parameters
571
+ ----------
572
+ a : ndarray
573
+ Input array.
574
+ max_line_width : int, optional
575
+ Inserts newlines if text is longer than `max_line_width`.
576
+ Defaults to ``numpy.get_printoptions()['linewidth']``.
577
+ precision : int or None, optional
578
+ Floating point precision.
579
+ Defaults to ``numpy.get_printoptions()['precision']``.
580
+ suppress_small : bool, optional
581
+ Represent numbers "very close" to zero as zero; default is False.
582
+ Very close is defined by precision: if the precision is 8, e.g.,
583
+ numbers smaller (in absolute value) than 5e-9 are represented as
584
+ zero.
585
+ Defaults to ``numpy.get_printoptions()['suppress']``.
586
+ separator : str, optional
587
+ Inserted between elements.
588
+ prefix : str, optional
589
+ suffix : str, optional
590
+ The length of the prefix and suffix strings are used to respectively
591
+ align and wrap the output. An array is typically printed as::
592
+
593
+ prefix + array2string(a) + suffix
594
+
595
+ The output is left-padded by the length of the prefix string, and
596
+ wrapping is forced at the column ``max_line_width - len(suffix)``.
597
+ It should be noted that the content of prefix and suffix strings are
598
+ not included in the output.
599
+ style : _NoValue, optional
600
+ Has no effect, do not use.
601
+
602
+ .. deprecated:: 1.14.0
603
+ formatter : dict of callables, optional
604
+ If not None, the keys should indicate the type(s) that the respective
605
+ formatting function applies to. Callables should return a string.
606
+ Types that are not specified (by their corresponding keys) are handled
607
+ by the default formatters. Individual types for which a formatter
608
+ can be set are:
609
+
610
+ - 'bool'
611
+ - 'int'
612
+ - 'timedelta' : a `numpy.timedelta64`
613
+ - 'datetime' : a `numpy.datetime64`
614
+ - 'float'
615
+ - 'longfloat' : 128-bit floats
616
+ - 'complexfloat'
617
+ - 'longcomplexfloat' : composed of two 128-bit floats
618
+ - 'void' : type `numpy.void`
619
+ - 'numpystr' : types `numpy.bytes_` and `numpy.str_`
620
+
621
+ Other keys that can be used to set a group of types at once are:
622
+
623
+ - 'all' : sets all types
624
+ - 'int_kind' : sets 'int'
625
+ - 'float_kind' : sets 'float' and 'longfloat'
626
+ - 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat'
627
+ - 'str_kind' : sets 'numpystr'
628
+ threshold : int, optional
629
+ Total number of array elements which trigger summarization
630
+ rather than full repr.
631
+ Defaults to ``numpy.get_printoptions()['threshold']``.
632
+ edgeitems : int, optional
633
+ Number of array items in summary at beginning and end of
634
+ each dimension.
635
+ Defaults to ``numpy.get_printoptions()['edgeitems']``.
636
+ sign : string, either '-', '+', or ' ', optional
637
+ Controls printing of the sign of floating-point types. If '+', always
638
+ print the sign of positive values. If ' ', always prints a space
639
+ (whitespace character) in the sign position of positive values. If
640
+ '-', omit the sign character of positive values.
641
+ Defaults to ``numpy.get_printoptions()['sign']``.
642
+ floatmode : str, optional
643
+ Controls the interpretation of the `precision` option for
644
+ floating-point types.
645
+ Defaults to ``numpy.get_printoptions()['floatmode']``.
646
+ Can take the following values:
647
+
648
+ - 'fixed': Always print exactly `precision` fractional digits,
649
+ even if this would print more or fewer digits than
650
+ necessary to specify the value uniquely.
651
+ - 'unique': Print the minimum number of fractional digits necessary
652
+ to represent each value uniquely. Different elements may
653
+ have a different number of digits. The value of the
654
+ `precision` option is ignored.
655
+ - 'maxprec': Print at most `precision` fractional digits, but if
656
+ an element can be uniquely represented with fewer digits
657
+ only print it with that many.
658
+ - 'maxprec_equal': Print at most `precision` fractional digits,
659
+ but if every element in the array can be uniquely
660
+ represented with an equal number of fewer digits, use that
661
+ many digits for all elements.
662
+ legacy : string or `False`, optional
663
+ If set to the string `'1.13'` enables 1.13 legacy printing mode. This
664
+ approximates numpy 1.13 print output by including a space in the sign
665
+ position of floats and different behavior for 0d arrays. If set to
666
+ `False`, disables legacy mode. Unrecognized strings will be ignored
667
+ with a warning for forward compatibility.
668
+
669
+ .. versionadded:: 1.14.0
670
+
671
+ Returns
672
+ -------
673
+ array_str : str
674
+ String representation of the array.
675
+
676
+ Raises
677
+ ------
678
+ TypeError
679
+ if a callable in `formatter` does not return a string.
680
+
681
+ See Also
682
+ --------
683
+ array_str, array_repr, set_printoptions, get_printoptions
684
+
685
+ Notes
686
+ -----
687
+ If a formatter is specified for a certain type, the `precision` keyword is
688
+ ignored for that type.
689
+
690
+ This is a very flexible function; `array_repr` and `array_str` are using
691
+ `array2string` internally so keywords with the same name should work
692
+ identically in all three functions.
693
+
694
+ Examples
695
+ --------
696
+ >>> x = np.array([1e-16,1,2,3])
697
+ >>> np.array2string(x, precision=2, separator=',',
698
+ ... suppress_small=True)
699
+ '[0.,1.,2.,3.]'
700
+
701
+ >>> x = np.arange(3.)
702
+ >>> np.array2string(x, formatter={'float_kind':lambda x: "%.2f" % x})
703
+ '[0.00 1.00 2.00]'
704
+
705
+ >>> x = np.arange(3)
706
+ >>> np.array2string(x, formatter={'int':lambda x: hex(x)})
707
+ '[0x0 0x1 0x2]'
708
+
709
+ """
710
+
711
+ overrides = _make_options_dict(precision, threshold, edgeitems,
712
+ max_line_width, suppress_small, None, None,
713
+ sign, formatter, floatmode, legacy)
714
+ options = _format_options.copy()
715
+ options.update(overrides)
716
+
717
+ if options['legacy'] <= 113:
718
+ if style is np._NoValue:
719
+ style = repr
720
+
721
+ if a.shape == () and a.dtype.names is None:
722
+ return style(a.item())
723
+ elif style is not np._NoValue:
724
+ # Deprecation 11-9-2017 v1.14
725
+ warnings.warn("'style' argument is deprecated and no longer functional"
726
+ " except in 1.13 'legacy' mode",
727
+ DeprecationWarning, stacklevel=2)
728
+
729
+ if options['legacy'] > 113:
730
+ options['linewidth'] -= len(suffix)
731
+
732
+ # treat as a null array if any of shape elements == 0
733
+ if a.size == 0:
734
+ return "[]"
735
+
736
+ return _array2string(a, options, separator, prefix)
737
+
738
+
739
+ def _extendLine(s, line, word, line_width, next_line_prefix, legacy):
740
+ needs_wrap = len(line) + len(word) > line_width
741
+ if legacy > 113:
742
+ # don't wrap lines if it won't help
743
+ if len(line) <= len(next_line_prefix):
744
+ needs_wrap = False
745
+
746
+ if needs_wrap:
747
+ s += line.rstrip() + "\n"
748
+ line = next_line_prefix
749
+ line += word
750
+ return s, line
751
+
752
+
753
+ def _extendLine_pretty(s, line, word, line_width, next_line_prefix, legacy):
754
+ """
755
+ Extends line with nicely formatted (possibly multi-line) string ``word``.
756
+ """
757
+ words = word.splitlines()
758
+ if len(words) == 1 or legacy <= 113:
759
+ return _extendLine(s, line, word, line_width, next_line_prefix, legacy)
760
+
761
+ max_word_length = max(len(word) for word in words)
762
+ if (len(line) + max_word_length > line_width and
763
+ len(line) > len(next_line_prefix)):
764
+ s += line.rstrip() + '\n'
765
+ line = next_line_prefix + words[0]
766
+ indent = next_line_prefix
767
+ else:
768
+ indent = len(line)*' '
769
+ line += words[0]
770
+
771
+ for word in words[1::]:
772
+ s += line.rstrip() + '\n'
773
+ line = indent + word
774
+
775
+ suffix_length = max_word_length - len(words[-1])
776
+ line += suffix_length*' '
777
+
778
+ return s, line
779
+
780
+ def _formatArray(a, format_function, line_width, next_line_prefix,
781
+ separator, edge_items, summary_insert, legacy):
782
+ """formatArray is designed for two modes of operation:
783
+
784
+ 1. Full output
785
+
786
+ 2. Summarized output
787
+
788
+ """
789
+ def recurser(index, hanging_indent, curr_width):
790
+ """
791
+ By using this local function, we don't need to recurse with all the
792
+ arguments. Since this function is not created recursively, the cost is
793
+ not significant
794
+ """
795
+ axis = len(index)
796
+ axes_left = a.ndim - axis
797
+
798
+ if axes_left == 0:
799
+ return format_function(a[index])
800
+
801
+ # when recursing, add a space to align with the [ added, and reduce the
802
+ # length of the line by 1
803
+ next_hanging_indent = hanging_indent + ' '
804
+ if legacy <= 113:
805
+ next_width = curr_width
806
+ else:
807
+ next_width = curr_width - len(']')
808
+
809
+ a_len = a.shape[axis]
810
+ show_summary = summary_insert and 2*edge_items < a_len
811
+ if show_summary:
812
+ leading_items = edge_items
813
+ trailing_items = edge_items
814
+ else:
815
+ leading_items = 0
816
+ trailing_items = a_len
817
+
818
+ # stringify the array with the hanging indent on the first line too
819
+ s = ''
820
+
821
+ # last axis (rows) - wrap elements if they would not fit on one line
822
+ if axes_left == 1:
823
+ # the length up until the beginning of the separator / bracket
824
+ if legacy <= 113:
825
+ elem_width = curr_width - len(separator.rstrip())
826
+ else:
827
+ elem_width = curr_width - max(len(separator.rstrip()), len(']'))
828
+
829
+ line = hanging_indent
830
+ for i in range(leading_items):
831
+ word = recurser(index + (i,), next_hanging_indent, next_width)
832
+ s, line = _extendLine_pretty(
833
+ s, line, word, elem_width, hanging_indent, legacy)
834
+ line += separator
835
+
836
+ if show_summary:
837
+ s, line = _extendLine(
838
+ s, line, summary_insert, elem_width, hanging_indent, legacy)
839
+ if legacy <= 113:
840
+ line += ", "
841
+ else:
842
+ line += separator
843
+
844
+ for i in range(trailing_items, 1, -1):
845
+ word = recurser(index + (-i,), next_hanging_indent, next_width)
846
+ s, line = _extendLine_pretty(
847
+ s, line, word, elem_width, hanging_indent, legacy)
848
+ line += separator
849
+
850
+ if legacy <= 113:
851
+ # width of the separator is not considered on 1.13
852
+ elem_width = curr_width
853
+ word = recurser(index + (-1,), next_hanging_indent, next_width)
854
+ s, line = _extendLine_pretty(
855
+ s, line, word, elem_width, hanging_indent, legacy)
856
+
857
+ s += line
858
+
859
+ # other axes - insert newlines between rows
860
+ else:
861
+ s = ''
862
+ line_sep = separator.rstrip() + '\n'*(axes_left - 1)
863
+
864
+ for i in range(leading_items):
865
+ nested = recurser(index + (i,), next_hanging_indent, next_width)
866
+ s += hanging_indent + nested + line_sep
867
+
868
+ if show_summary:
869
+ if legacy <= 113:
870
+ # trailing space, fixed nbr of newlines, and fixed separator
871
+ s += hanging_indent + summary_insert + ", \n"
872
+ else:
873
+ s += hanging_indent + summary_insert + line_sep
874
+
875
+ for i in range(trailing_items, 1, -1):
876
+ nested = recurser(index + (-i,), next_hanging_indent,
877
+ next_width)
878
+ s += hanging_indent + nested + line_sep
879
+
880
+ nested = recurser(index + (-1,), next_hanging_indent, next_width)
881
+ s += hanging_indent + nested
882
+
883
+ # remove the hanging indent, and wrap in []
884
+ s = '[' + s[len(hanging_indent):] + ']'
885
+ return s
886
+
887
+ try:
888
+ # invoke the recursive part with an initial index and prefix
889
+ return recurser(index=(),
890
+ hanging_indent=next_line_prefix,
891
+ curr_width=line_width)
892
+ finally:
893
+ # recursive closures have a cyclic reference to themselves, which
894
+ # requires gc to collect (gh-10620). To avoid this problem, for
895
+ # performance and PyPy friendliness, we break the cycle:
896
+ recurser = None
897
+
898
+ def _none_or_positive_arg(x, name):
899
+ if x is None:
900
+ return -1
901
+ if x < 0:
902
+ raise ValueError("{} must be >= 0".format(name))
903
+ return x
904
+
905
+ class FloatingFormat:
906
+ """ Formatter for subtypes of np.floating """
907
+ def __init__(self, data, precision, floatmode, suppress_small, sign=False,
908
+ *, legacy=None):
909
+ # for backcompatibility, accept bools
910
+ if isinstance(sign, bool):
911
+ sign = '+' if sign else '-'
912
+
913
+ self._legacy = legacy
914
+ if self._legacy <= 113:
915
+ # when not 0d, legacy does not support '-'
916
+ if data.shape != () and sign == '-':
917
+ sign = ' '
918
+
919
+ self.floatmode = floatmode
920
+ if floatmode == 'unique':
921
+ self.precision = None
922
+ else:
923
+ self.precision = precision
924
+
925
+ self.precision = _none_or_positive_arg(self.precision, 'precision')
926
+
927
+ self.suppress_small = suppress_small
928
+ self.sign = sign
929
+ self.exp_format = False
930
+ self.large_exponent = False
931
+
932
+ self.fillFormat(data)
933
+
934
+ def fillFormat(self, data):
935
+ # only the finite values are used to compute the number of digits
936
+ finite_vals = data[isfinite(data)]
937
+
938
+ # choose exponential mode based on the non-zero finite values:
939
+ abs_non_zero = absolute(finite_vals[finite_vals != 0])
940
+ if len(abs_non_zero) != 0:
941
+ max_val = np.max(abs_non_zero)
942
+ min_val = np.min(abs_non_zero)
943
+ with errstate(over='ignore'): # division can overflow
944
+ if max_val >= 1.e8 or (not self.suppress_small and
945
+ (min_val < 0.0001 or max_val/min_val > 1000.)):
946
+ self.exp_format = True
947
+
948
+ # do a first pass of printing all the numbers, to determine sizes
949
+ if len(finite_vals) == 0:
950
+ self.pad_left = 0
951
+ self.pad_right = 0
952
+ self.trim = '.'
953
+ self.exp_size = -1
954
+ self.unique = True
955
+ self.min_digits = None
956
+ elif self.exp_format:
957
+ trim, unique = '.', True
958
+ if self.floatmode == 'fixed' or self._legacy <= 113:
959
+ trim, unique = 'k', False
960
+ strs = (dragon4_scientific(x, precision=self.precision,
961
+ unique=unique, trim=trim, sign=self.sign == '+')
962
+ for x in finite_vals)
963
+ frac_strs, _, exp_strs = zip(*(s.partition('e') for s in strs))
964
+ int_part, frac_part = zip(*(s.split('.') for s in frac_strs))
965
+ self.exp_size = max(len(s) for s in exp_strs) - 1
966
+
967
+ self.trim = 'k'
968
+ self.precision = max(len(s) for s in frac_part)
969
+ self.min_digits = self.precision
970
+ self.unique = unique
971
+
972
+ # for back-compat with np 1.13, use 2 spaces & sign and full prec
973
+ if self._legacy <= 113:
974
+ self.pad_left = 3
975
+ else:
976
+ # this should be only 1 or 2. Can be calculated from sign.
977
+ self.pad_left = max(len(s) for s in int_part)
978
+ # pad_right is only needed for nan length calculation
979
+ self.pad_right = self.exp_size + 2 + self.precision
980
+ else:
981
+ trim, unique = '.', True
982
+ if self.floatmode == 'fixed':
983
+ trim, unique = 'k', False
984
+ strs = (dragon4_positional(x, precision=self.precision,
985
+ fractional=True,
986
+ unique=unique, trim=trim,
987
+ sign=self.sign == '+')
988
+ for x in finite_vals)
989
+ int_part, frac_part = zip(*(s.split('.') for s in strs))
990
+ if self._legacy <= 113:
991
+ self.pad_left = 1 + max(len(s.lstrip('-+')) for s in int_part)
992
+ else:
993
+ self.pad_left = max(len(s) for s in int_part)
994
+ self.pad_right = max(len(s) for s in frac_part)
995
+ self.exp_size = -1
996
+ self.unique = unique
997
+
998
+ if self.floatmode in ['fixed', 'maxprec_equal']:
999
+ self.precision = self.min_digits = self.pad_right
1000
+ self.trim = 'k'
1001
+ else:
1002
+ self.trim = '.'
1003
+ self.min_digits = 0
1004
+
1005
+ if self._legacy > 113:
1006
+ # account for sign = ' ' by adding one to pad_left
1007
+ if self.sign == ' ' and not any(np.signbit(finite_vals)):
1008
+ self.pad_left += 1
1009
+
1010
+ # if there are non-finite values, may need to increase pad_left
1011
+ if data.size != finite_vals.size:
1012
+ neginf = self.sign != '-' or any(data[isinf(data)] < 0)
1013
+ nanlen = len(_format_options['nanstr'])
1014
+ inflen = len(_format_options['infstr']) + neginf
1015
+ offset = self.pad_right + 1 # +1 for decimal pt
1016
+ self.pad_left = max(self.pad_left, nanlen - offset, inflen - offset)
1017
+
1018
+ def __call__(self, x):
1019
+ if not np.isfinite(x):
1020
+ with errstate(invalid='ignore'):
1021
+ if np.isnan(x):
1022
+ sign = '+' if self.sign == '+' else ''
1023
+ ret = sign + _format_options['nanstr']
1024
+ else: # isinf
1025
+ sign = '-' if x < 0 else '+' if self.sign == '+' else ''
1026
+ ret = sign + _format_options['infstr']
1027
+ return ' '*(self.pad_left + self.pad_right + 1 - len(ret)) + ret
1028
+
1029
+ if self.exp_format:
1030
+ return dragon4_scientific(x,
1031
+ precision=self.precision,
1032
+ min_digits=self.min_digits,
1033
+ unique=self.unique,
1034
+ trim=self.trim,
1035
+ sign=self.sign == '+',
1036
+ pad_left=self.pad_left,
1037
+ exp_digits=self.exp_size)
1038
+ else:
1039
+ return dragon4_positional(x,
1040
+ precision=self.precision,
1041
+ min_digits=self.min_digits,
1042
+ unique=self.unique,
1043
+ fractional=True,
1044
+ trim=self.trim,
1045
+ sign=self.sign == '+',
1046
+ pad_left=self.pad_left,
1047
+ pad_right=self.pad_right)
1048
+
1049
+
1050
+ @set_module('numpy')
1051
+ def format_float_scientific(x, precision=None, unique=True, trim='k',
1052
+ sign=False, pad_left=None, exp_digits=None,
1053
+ min_digits=None):
1054
+ """
1055
+ Format a floating-point scalar as a decimal string in scientific notation.
1056
+
1057
+ Provides control over rounding, trimming and padding. Uses and assumes
1058
+ IEEE unbiased rounding. Uses the "Dragon4" algorithm.
1059
+
1060
+ Parameters
1061
+ ----------
1062
+ x : python float or numpy floating scalar
1063
+ Value to format.
1064
+ precision : non-negative integer or None, optional
1065
+ Maximum number of digits to print. May be None if `unique` is
1066
+ `True`, but must be an integer if unique is `False`.
1067
+ unique : boolean, optional
1068
+ If `True`, use a digit-generation strategy which gives the shortest
1069
+ representation which uniquely identifies the floating-point number from
1070
+ other values of the same type, by judicious rounding. If `precision`
1071
+ is given fewer digits than necessary can be printed. If `min_digits`
1072
+ is given more can be printed, in which cases the last digit is rounded
1073
+ with unbiased rounding.
1074
+ If `False`, digits are generated as if printing an infinite-precision
1075
+ value and stopping after `precision` digits, rounding the remaining
1076
+ value with unbiased rounding
1077
+ trim : one of 'k', '.', '0', '-', optional
1078
+ Controls post-processing trimming of trailing digits, as follows:
1079
+
1080
+ * 'k' : keep trailing zeros, keep decimal point (no trimming)
1081
+ * '.' : trim all trailing zeros, leave decimal point
1082
+ * '0' : trim all but the zero before the decimal point. Insert the
1083
+ zero if it is missing.
1084
+ * '-' : trim trailing zeros and any trailing decimal point
1085
+ sign : boolean, optional
1086
+ Whether to show the sign for positive values.
1087
+ pad_left : non-negative integer, optional
1088
+ Pad the left side of the string with whitespace until at least that
1089
+ many characters are to the left of the decimal point.
1090
+ exp_digits : non-negative integer, optional
1091
+ Pad the exponent with zeros until it contains at least this many digits.
1092
+ If omitted, the exponent will be at least 2 digits.
1093
+ min_digits : non-negative integer or None, optional
1094
+ Minimum number of digits to print. This only has an effect for
1095
+ `unique=True`. In that case more digits than necessary to uniquely
1096
+ identify the value may be printed and rounded unbiased.
1097
+
1098
+ -- versionadded:: 1.21.0
1099
+
1100
+ Returns
1101
+ -------
1102
+ rep : string
1103
+ The string representation of the floating point value
1104
+
1105
+ See Also
1106
+ --------
1107
+ format_float_positional
1108
+
1109
+ Examples
1110
+ --------
1111
+ >>> np.format_float_scientific(np.float32(np.pi))
1112
+ '3.1415927e+00'
1113
+ >>> s = np.float32(1.23e24)
1114
+ >>> np.format_float_scientific(s, unique=False, precision=15)
1115
+ '1.230000071797338e+24'
1116
+ >>> np.format_float_scientific(s, exp_digits=4)
1117
+ '1.23e+0024'
1118
+ """
1119
+ precision = _none_or_positive_arg(precision, 'precision')
1120
+ pad_left = _none_or_positive_arg(pad_left, 'pad_left')
1121
+ exp_digits = _none_or_positive_arg(exp_digits, 'exp_digits')
1122
+ min_digits = _none_or_positive_arg(min_digits, 'min_digits')
1123
+ if min_digits > 0 and precision > 0 and min_digits > precision:
1124
+ raise ValueError("min_digits must be less than or equal to precision")
1125
+ return dragon4_scientific(x, precision=precision, unique=unique,
1126
+ trim=trim, sign=sign, pad_left=pad_left,
1127
+ exp_digits=exp_digits, min_digits=min_digits)
1128
+
1129
+
1130
+ @set_module('numpy')
1131
+ def format_float_positional(x, precision=None, unique=True,
1132
+ fractional=True, trim='k', sign=False,
1133
+ pad_left=None, pad_right=None, min_digits=None):
1134
+ """
1135
+ Format a floating-point scalar as a decimal string in positional notation.
1136
+
1137
+ Provides control over rounding, trimming and padding. Uses and assumes
1138
+ IEEE unbiased rounding. Uses the "Dragon4" algorithm.
1139
+
1140
+ Parameters
1141
+ ----------
1142
+ x : python float or numpy floating scalar
1143
+ Value to format.
1144
+ precision : non-negative integer or None, optional
1145
+ Maximum number of digits to print. May be None if `unique` is
1146
+ `True`, but must be an integer if unique is `False`.
1147
+ unique : boolean, optional
1148
+ If `True`, use a digit-generation strategy which gives the shortest
1149
+ representation which uniquely identifies the floating-point number from
1150
+ other values of the same type, by judicious rounding. If `precision`
1151
+ is given fewer digits than necessary can be printed, or if `min_digits`
1152
+ is given more can be printed, in which cases the last digit is rounded
1153
+ with unbiased rounding.
1154
+ If `False`, digits are generated as if printing an infinite-precision
1155
+ value and stopping after `precision` digits, rounding the remaining
1156
+ value with unbiased rounding
1157
+ fractional : boolean, optional
1158
+ If `True`, the cutoffs of `precision` and `min_digits` refer to the
1159
+ total number of digits after the decimal point, including leading
1160
+ zeros.
1161
+ If `False`, `precision` and `min_digits` refer to the total number of
1162
+ significant digits, before or after the decimal point, ignoring leading
1163
+ zeros.
1164
+ trim : one of 'k', '.', '0', '-', optional
1165
+ Controls post-processing trimming of trailing digits, as follows:
1166
+
1167
+ * 'k' : keep trailing zeros, keep decimal point (no trimming)
1168
+ * '.' : trim all trailing zeros, leave decimal point
1169
+ * '0' : trim all but the zero before the decimal point. Insert the
1170
+ zero if it is missing.
1171
+ * '-' : trim trailing zeros and any trailing decimal point
1172
+ sign : boolean, optional
1173
+ Whether to show the sign for positive values.
1174
+ pad_left : non-negative integer, optional
1175
+ Pad the left side of the string with whitespace until at least that
1176
+ many characters are to the left of the decimal point.
1177
+ pad_right : non-negative integer, optional
1178
+ Pad the right side of the string with whitespace until at least that
1179
+ many characters are to the right of the decimal point.
1180
+ min_digits : non-negative integer or None, optional
1181
+ Minimum number of digits to print. Only has an effect if `unique=True`
1182
+ in which case additional digits past those necessary to uniquely
1183
+ identify the value may be printed, rounding the last additional digit.
1184
+
1185
+ -- versionadded:: 1.21.0
1186
+
1187
+ Returns
1188
+ -------
1189
+ rep : string
1190
+ The string representation of the floating point value
1191
+
1192
+ See Also
1193
+ --------
1194
+ format_float_scientific
1195
+
1196
+ Examples
1197
+ --------
1198
+ >>> np.format_float_positional(np.float32(np.pi))
1199
+ '3.1415927'
1200
+ >>> np.format_float_positional(np.float16(np.pi))
1201
+ '3.14'
1202
+ >>> np.format_float_positional(np.float16(0.3))
1203
+ '0.3'
1204
+ >>> np.format_float_positional(np.float16(0.3), unique=False, precision=10)
1205
+ '0.3000488281'
1206
+ """
1207
+ precision = _none_or_positive_arg(precision, 'precision')
1208
+ pad_left = _none_or_positive_arg(pad_left, 'pad_left')
1209
+ pad_right = _none_or_positive_arg(pad_right, 'pad_right')
1210
+ min_digits = _none_or_positive_arg(min_digits, 'min_digits')
1211
+ if not fractional and precision == 0:
1212
+ raise ValueError("precision must be greater than 0 if "
1213
+ "fractional=False")
1214
+ if min_digits > 0 and precision > 0 and min_digits > precision:
1215
+ raise ValueError("min_digits must be less than or equal to precision")
1216
+ return dragon4_positional(x, precision=precision, unique=unique,
1217
+ fractional=fractional, trim=trim,
1218
+ sign=sign, pad_left=pad_left,
1219
+ pad_right=pad_right, min_digits=min_digits)
1220
+
1221
+
1222
+ class IntegerFormat:
1223
+ def __init__(self, data):
1224
+ if data.size > 0:
1225
+ max_str_len = max(len(str(np.max(data))),
1226
+ len(str(np.min(data))))
1227
+ else:
1228
+ max_str_len = 0
1229
+ self.format = '%{}d'.format(max_str_len)
1230
+
1231
+ def __call__(self, x):
1232
+ return self.format % x
1233
+
1234
+
1235
+ class BoolFormat:
1236
+ def __init__(self, data, **kwargs):
1237
+ # add an extra space so " True" and "False" have the same length and
1238
+ # array elements align nicely when printed, except in 0d arrays
1239
+ self.truestr = ' True' if data.shape != () else 'True'
1240
+
1241
+ def __call__(self, x):
1242
+ return self.truestr if x else "False"
1243
+
1244
+
1245
+ class ComplexFloatingFormat:
1246
+ """ Formatter for subtypes of np.complexfloating """
1247
+ def __init__(self, x, precision, floatmode, suppress_small,
1248
+ sign=False, *, legacy=None):
1249
+ # for backcompatibility, accept bools
1250
+ if isinstance(sign, bool):
1251
+ sign = '+' if sign else '-'
1252
+
1253
+ floatmode_real = floatmode_imag = floatmode
1254
+ if legacy <= 113:
1255
+ floatmode_real = 'maxprec_equal'
1256
+ floatmode_imag = 'maxprec'
1257
+
1258
+ self.real_format = FloatingFormat(
1259
+ x.real, precision, floatmode_real, suppress_small,
1260
+ sign=sign, legacy=legacy
1261
+ )
1262
+ self.imag_format = FloatingFormat(
1263
+ x.imag, precision, floatmode_imag, suppress_small,
1264
+ sign='+', legacy=legacy
1265
+ )
1266
+
1267
+ def __call__(self, x):
1268
+ r = self.real_format(x.real)
1269
+ i = self.imag_format(x.imag)
1270
+
1271
+ # add the 'j' before the terminal whitespace in i
1272
+ sp = len(i.rstrip())
1273
+ i = i[:sp] + 'j' + i[sp:]
1274
+
1275
+ return r + i
1276
+
1277
+
1278
+ class _TimelikeFormat:
1279
+ def __init__(self, data):
1280
+ non_nat = data[~isnat(data)]
1281
+ if len(non_nat) > 0:
1282
+ # Max str length of non-NaT elements
1283
+ max_str_len = max(len(self._format_non_nat(np.max(non_nat))),
1284
+ len(self._format_non_nat(np.min(non_nat))))
1285
+ else:
1286
+ max_str_len = 0
1287
+ if len(non_nat) < data.size:
1288
+ # data contains a NaT
1289
+ max_str_len = max(max_str_len, 5)
1290
+ self._format = '%{}s'.format(max_str_len)
1291
+ self._nat = "'NaT'".rjust(max_str_len)
1292
+
1293
+ def _format_non_nat(self, x):
1294
+ # override in subclass
1295
+ raise NotImplementedError
1296
+
1297
+ def __call__(self, x):
1298
+ if isnat(x):
1299
+ return self._nat
1300
+ else:
1301
+ return self._format % self._format_non_nat(x)
1302
+
1303
+
1304
+ class DatetimeFormat(_TimelikeFormat):
1305
+ def __init__(self, x, unit=None, timezone=None, casting='same_kind',
1306
+ legacy=False):
1307
+ # Get the unit from the dtype
1308
+ if unit is None:
1309
+ if x.dtype.kind == 'M':
1310
+ unit = datetime_data(x.dtype)[0]
1311
+ else:
1312
+ unit = 's'
1313
+
1314
+ if timezone is None:
1315
+ timezone = 'naive'
1316
+ self.timezone = timezone
1317
+ self.unit = unit
1318
+ self.casting = casting
1319
+ self.legacy = legacy
1320
+
1321
+ # must be called after the above are configured
1322
+ super().__init__(x)
1323
+
1324
+ def __call__(self, x):
1325
+ if self.legacy <= 113:
1326
+ return self._format_non_nat(x)
1327
+ return super().__call__(x)
1328
+
1329
+ def _format_non_nat(self, x):
1330
+ return "'%s'" % datetime_as_string(x,
1331
+ unit=self.unit,
1332
+ timezone=self.timezone,
1333
+ casting=self.casting)
1334
+
1335
+
1336
+ class TimedeltaFormat(_TimelikeFormat):
1337
+ def _format_non_nat(self, x):
1338
+ return str(x.astype('i8'))
1339
+
1340
+
1341
+ class SubArrayFormat:
1342
+ def __init__(self, format_function, **options):
1343
+ self.format_function = format_function
1344
+ self.threshold = options['threshold']
1345
+ self.edge_items = options['edgeitems']
1346
+
1347
+ def __call__(self, a):
1348
+ self.summary_insert = "..." if a.size > self.threshold else ""
1349
+ return self.format_array(a)
1350
+
1351
+ def format_array(self, a):
1352
+ if np.ndim(a) == 0:
1353
+ return self.format_function(a)
1354
+
1355
+ if self.summary_insert and a.shape[0] > 2*self.edge_items:
1356
+ formatted = (
1357
+ [self.format_array(a_) for a_ in a[:self.edge_items]]
1358
+ + [self.summary_insert]
1359
+ + [self.format_array(a_) for a_ in a[-self.edge_items:]]
1360
+ )
1361
+ else:
1362
+ formatted = [self.format_array(a_) for a_ in a]
1363
+
1364
+ return "[" + ", ".join(formatted) + "]"
1365
+
1366
+
1367
+ class StructuredVoidFormat:
1368
+ """
1369
+ Formatter for structured np.void objects.
1370
+
1371
+ This does not work on structured alias types like np.dtype(('i4', 'i2,i2')),
1372
+ as alias scalars lose their field information, and the implementation
1373
+ relies upon np.void.__getitem__.
1374
+ """
1375
+ def __init__(self, format_functions):
1376
+ self.format_functions = format_functions
1377
+
1378
+ @classmethod
1379
+ def from_data(cls, data, **options):
1380
+ """
1381
+ This is a second way to initialize StructuredVoidFormat, using the raw data
1382
+ as input. Added to avoid changing the signature of __init__.
1383
+ """
1384
+ format_functions = []
1385
+ for field_name in data.dtype.names:
1386
+ format_function = _get_format_function(data[field_name], **options)
1387
+ if data.dtype[field_name].shape != ():
1388
+ format_function = SubArrayFormat(format_function, **options)
1389
+ format_functions.append(format_function)
1390
+ return cls(format_functions)
1391
+
1392
+ def __call__(self, x):
1393
+ str_fields = [
1394
+ format_function(field)
1395
+ for field, format_function in zip(x, self.format_functions)
1396
+ ]
1397
+ if len(str_fields) == 1:
1398
+ return "({},)".format(str_fields[0])
1399
+ else:
1400
+ return "({})".format(", ".join(str_fields))
1401
+
1402
+
1403
+ def _void_scalar_repr(x):
1404
+ """
1405
+ Implements the repr for structured-void scalars. It is called from the
1406
+ scalartypes.c.src code, and is placed here because it uses the elementwise
1407
+ formatters defined above.
1408
+ """
1409
+ return StructuredVoidFormat.from_data(array(x), **_format_options)(x)
1410
+
1411
+
1412
+ _typelessdata = [int_, float_, complex_, bool_]
1413
+
1414
+
1415
+ def dtype_is_implied(dtype):
1416
+ """
1417
+ Determine if the given dtype is implied by the representation of its values.
1418
+
1419
+ Parameters
1420
+ ----------
1421
+ dtype : dtype
1422
+ Data type
1423
+
1424
+ Returns
1425
+ -------
1426
+ implied : bool
1427
+ True if the dtype is implied by the representation of its values.
1428
+
1429
+ Examples
1430
+ --------
1431
+ >>> np.core.arrayprint.dtype_is_implied(int)
1432
+ True
1433
+ >>> np.array([1, 2, 3], int)
1434
+ array([1, 2, 3])
1435
+ >>> np.core.arrayprint.dtype_is_implied(np.int8)
1436
+ False
1437
+ >>> np.array([1, 2, 3], np.int8)
1438
+ array([1, 2, 3], dtype=int8)
1439
+ """
1440
+ dtype = np.dtype(dtype)
1441
+ if _format_options['legacy'] <= 113 and dtype.type == bool_:
1442
+ return False
1443
+
1444
+ # not just void types can be structured, and names are not part of the repr
1445
+ if dtype.names is not None:
1446
+ return False
1447
+
1448
+ # should care about endianness *unless size is 1* (e.g., int8, bool)
1449
+ if not dtype.isnative:
1450
+ return False
1451
+
1452
+ return dtype.type in _typelessdata
1453
+
1454
+
1455
+ def dtype_short_repr(dtype):
1456
+ """
1457
+ Convert a dtype to a short form which evaluates to the same dtype.
1458
+
1459
+ The intent is roughly that the following holds
1460
+
1461
+ >>> from numpy import *
1462
+ >>> dt = np.int64([1, 2]).dtype
1463
+ >>> assert eval(dtype_short_repr(dt)) == dt
1464
+ """
1465
+ if type(dtype).__repr__ != np.dtype.__repr__:
1466
+ # TODO: Custom repr for user DTypes, logic should likely move.
1467
+ return repr(dtype)
1468
+ if dtype.names is not None:
1469
+ # structured dtypes give a list or tuple repr
1470
+ return str(dtype)
1471
+ elif issubclass(dtype.type, flexible):
1472
+ # handle these separately so they don't give garbage like str256
1473
+ return "'%s'" % str(dtype)
1474
+
1475
+ typename = dtype.name
1476
+ if not dtype.isnative:
1477
+ # deal with cases like dtype('<u2') that are identical to an
1478
+ # established dtype (in this case uint16)
1479
+ # except that they have a different endianness.
1480
+ return "'%s'" % str(dtype)
1481
+ # quote typenames which can't be represented as python variable names
1482
+ if typename and not (typename[0].isalpha() and typename.isalnum()):
1483
+ typename = repr(typename)
1484
+ return typename
1485
+
1486
+
1487
+ def _array_repr_implementation(
1488
+ arr, max_line_width=None, precision=None, suppress_small=None,
1489
+ array2string=array2string):
1490
+ """Internal version of array_repr() that allows overriding array2string."""
1491
+ if max_line_width is None:
1492
+ max_line_width = _format_options['linewidth']
1493
+
1494
+ if type(arr) is not ndarray:
1495
+ class_name = type(arr).__name__
1496
+ else:
1497
+ class_name = "array"
1498
+
1499
+ skipdtype = dtype_is_implied(arr.dtype) and arr.size > 0
1500
+
1501
+ prefix = class_name + "("
1502
+ suffix = ")" if skipdtype else ","
1503
+
1504
+ if (_format_options['legacy'] <= 113 and
1505
+ arr.shape == () and not arr.dtype.names):
1506
+ lst = repr(arr.item())
1507
+ elif arr.size > 0 or arr.shape == (0,):
1508
+ lst = array2string(arr, max_line_width, precision, suppress_small,
1509
+ ', ', prefix, suffix=suffix)
1510
+ else: # show zero-length shape unless it is (0,)
1511
+ lst = "[], shape=%s" % (repr(arr.shape),)
1512
+
1513
+ arr_str = prefix + lst + suffix
1514
+
1515
+ if skipdtype:
1516
+ return arr_str
1517
+
1518
+ dtype_str = "dtype={})".format(dtype_short_repr(arr.dtype))
1519
+
1520
+ # compute whether we should put dtype on a new line: Do so if adding the
1521
+ # dtype would extend the last line past max_line_width.
1522
+ # Note: This line gives the correct result even when rfind returns -1.
1523
+ last_line_len = len(arr_str) - (arr_str.rfind('\n') + 1)
1524
+ spacer = " "
1525
+ if _format_options['legacy'] <= 113:
1526
+ if issubclass(arr.dtype.type, flexible):
1527
+ spacer = '\n' + ' '*len(class_name + "(")
1528
+ elif last_line_len + len(dtype_str) + 1 > max_line_width:
1529
+ spacer = '\n' + ' '*len(class_name + "(")
1530
+
1531
+ return arr_str + spacer + dtype_str
1532
+
1533
+
1534
+ def _array_repr_dispatcher(
1535
+ arr, max_line_width=None, precision=None, suppress_small=None):
1536
+ return (arr,)
1537
+
1538
+
1539
+ @array_function_dispatch(_array_repr_dispatcher, module='numpy')
1540
+ def array_repr(arr, max_line_width=None, precision=None, suppress_small=None):
1541
+ """
1542
+ Return the string representation of an array.
1543
+
1544
+ Parameters
1545
+ ----------
1546
+ arr : ndarray
1547
+ Input array.
1548
+ max_line_width : int, optional
1549
+ Inserts newlines if text is longer than `max_line_width`.
1550
+ Defaults to ``numpy.get_printoptions()['linewidth']``.
1551
+ precision : int, optional
1552
+ Floating point precision.
1553
+ Defaults to ``numpy.get_printoptions()['precision']``.
1554
+ suppress_small : bool, optional
1555
+ Represent numbers "very close" to zero as zero; default is False.
1556
+ Very close is defined by precision: if the precision is 8, e.g.,
1557
+ numbers smaller (in absolute value) than 5e-9 are represented as
1558
+ zero.
1559
+ Defaults to ``numpy.get_printoptions()['suppress']``.
1560
+
1561
+ Returns
1562
+ -------
1563
+ string : str
1564
+ The string representation of an array.
1565
+
1566
+ See Also
1567
+ --------
1568
+ array_str, array2string, set_printoptions
1569
+
1570
+ Examples
1571
+ --------
1572
+ >>> np.array_repr(np.array([1,2]))
1573
+ 'array([1, 2])'
1574
+ >>> np.array_repr(np.ma.array([0.]))
1575
+ 'MaskedArray([0.])'
1576
+ >>> np.array_repr(np.array([], np.int32))
1577
+ 'array([], dtype=int32)'
1578
+
1579
+ >>> x = np.array([1e-6, 4e-7, 2, 3])
1580
+ >>> np.array_repr(x, precision=6, suppress_small=True)
1581
+ 'array([0.000001, 0. , 2. , 3. ])'
1582
+
1583
+ """
1584
+ return _array_repr_implementation(
1585
+ arr, max_line_width, precision, suppress_small)
1586
+
1587
+
1588
+ @_recursive_guard()
1589
+ def _guarded_repr_or_str(v):
1590
+ if isinstance(v, bytes):
1591
+ return repr(v)
1592
+ return str(v)
1593
+
1594
+
1595
+ def _array_str_implementation(
1596
+ a, max_line_width=None, precision=None, suppress_small=None,
1597
+ array2string=array2string):
1598
+ """Internal version of array_str() that allows overriding array2string."""
1599
+ if (_format_options['legacy'] <= 113 and
1600
+ a.shape == () and not a.dtype.names):
1601
+ return str(a.item())
1602
+
1603
+ # the str of 0d arrays is a special case: It should appear like a scalar,
1604
+ # so floats are not truncated by `precision`, and strings are not wrapped
1605
+ # in quotes. So we return the str of the scalar value.
1606
+ if a.shape == ():
1607
+ # obtain a scalar and call str on it, avoiding problems for subclasses
1608
+ # for which indexing with () returns a 0d instead of a scalar by using
1609
+ # ndarray's getindex. Also guard against recursive 0d object arrays.
1610
+ return _guarded_repr_or_str(np.ndarray.__getitem__(a, ()))
1611
+
1612
+ return array2string(a, max_line_width, precision, suppress_small, ' ', "")
1613
+
1614
+
1615
+ def _array_str_dispatcher(
1616
+ a, max_line_width=None, precision=None, suppress_small=None):
1617
+ return (a,)
1618
+
1619
+
1620
+ @array_function_dispatch(_array_str_dispatcher, module='numpy')
1621
+ def array_str(a, max_line_width=None, precision=None, suppress_small=None):
1622
+ """
1623
+ Return a string representation of the data in an array.
1624
+
1625
+ The data in the array is returned as a single string. This function is
1626
+ similar to `array_repr`, the difference being that `array_repr` also
1627
+ returns information on the kind of array and its data type.
1628
+
1629
+ Parameters
1630
+ ----------
1631
+ a : ndarray
1632
+ Input array.
1633
+ max_line_width : int, optional
1634
+ Inserts newlines if text is longer than `max_line_width`.
1635
+ Defaults to ``numpy.get_printoptions()['linewidth']``.
1636
+ precision : int, optional
1637
+ Floating point precision.
1638
+ Defaults to ``numpy.get_printoptions()['precision']``.
1639
+ suppress_small : bool, optional
1640
+ Represent numbers "very close" to zero as zero; default is False.
1641
+ Very close is defined by precision: if the precision is 8, e.g.,
1642
+ numbers smaller (in absolute value) than 5e-9 are represented as
1643
+ zero.
1644
+ Defaults to ``numpy.get_printoptions()['suppress']``.
1645
+
1646
+ See Also
1647
+ --------
1648
+ array2string, array_repr, set_printoptions
1649
+
1650
+ Examples
1651
+ --------
1652
+ >>> np.array_str(np.arange(3))
1653
+ '[0 1 2]'
1654
+
1655
+ """
1656
+ return _array_str_implementation(
1657
+ a, max_line_width, precision, suppress_small)
1658
+
1659
+
1660
+ # needed if __array_function__ is disabled
1661
+ _array2string_impl = getattr(array2string, '__wrapped__', array2string)
1662
+ _default_array_str = functools.partial(_array_str_implementation,
1663
+ array2string=_array2string_impl)
1664
+ _default_array_repr = functools.partial(_array_repr_implementation,
1665
+ array2string=_array2string_impl)
1666
+
1667
+
1668
+ def set_string_function(f, repr=True):
1669
+ """
1670
+ Set a Python function to be used when pretty printing arrays.
1671
+
1672
+ Parameters
1673
+ ----------
1674
+ f : function or None
1675
+ Function to be used to pretty print arrays. The function should expect
1676
+ a single array argument and return a string of the representation of
1677
+ the array. If None, the function is reset to the default NumPy function
1678
+ to print arrays.
1679
+ repr : bool, optional
1680
+ If True (default), the function for pretty printing (``__repr__``)
1681
+ is set, if False the function that returns the default string
1682
+ representation (``__str__``) is set.
1683
+
1684
+ See Also
1685
+ --------
1686
+ set_printoptions, get_printoptions
1687
+
1688
+ Examples
1689
+ --------
1690
+ >>> def pprint(arr):
1691
+ ... return 'HA! - What are you going to do now?'
1692
+ ...
1693
+ >>> np.set_string_function(pprint)
1694
+ >>> a = np.arange(10)
1695
+ >>> a
1696
+ HA! - What are you going to do now?
1697
+ >>> _ = a
1698
+ >>> # [0 1 2 3 4 5 6 7 8 9]
1699
+
1700
+ We can reset the function to the default:
1701
+
1702
+ >>> np.set_string_function(None)
1703
+ >>> a
1704
+ array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
1705
+
1706
+ `repr` affects either pretty printing or normal string representation.
1707
+ Note that ``__repr__`` is still affected by setting ``__str__``
1708
+ because the width of each array element in the returned string becomes
1709
+ equal to the length of the result of ``__str__()``.
1710
+
1711
+ >>> x = np.arange(4)
1712
+ >>> np.set_string_function(lambda x:'random', repr=False)
1713
+ >>> x.__str__()
1714
+ 'random'
1715
+ >>> x.__repr__()
1716
+ 'array([0, 1, 2, 3])'
1717
+
1718
+ """
1719
+ if f is None:
1720
+ if repr:
1721
+ return multiarray.set_string_function(_default_array_repr, 1)
1722
+ else:
1723
+ return multiarray.set_string_function(_default_array_str, 0)
1724
+ else:
1725
+ return multiarray.set_string_function(f, repr)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/einsumfunc.py ADDED
@@ -0,0 +1,1443 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Implementation of optimized einsum.
3
+
4
+ """
5
+ import itertools
6
+ import operator
7
+
8
+ from numpy.core.multiarray import c_einsum
9
+ from numpy.core.numeric import asanyarray, tensordot
10
+ from numpy.core.overrides import array_function_dispatch
11
+
12
+ __all__ = ['einsum', 'einsum_path']
13
+
14
+ einsum_symbols = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
15
+ einsum_symbols_set = set(einsum_symbols)
16
+
17
+
18
+ def _flop_count(idx_contraction, inner, num_terms, size_dictionary):
19
+ """
20
+ Computes the number of FLOPS in the contraction.
21
+
22
+ Parameters
23
+ ----------
24
+ idx_contraction : iterable
25
+ The indices involved in the contraction
26
+ inner : bool
27
+ Does this contraction require an inner product?
28
+ num_terms : int
29
+ The number of terms in a contraction
30
+ size_dictionary : dict
31
+ The size of each of the indices in idx_contraction
32
+
33
+ Returns
34
+ -------
35
+ flop_count : int
36
+ The total number of FLOPS required for the contraction.
37
+
38
+ Examples
39
+ --------
40
+
41
+ >>> _flop_count('abc', False, 1, {'a': 2, 'b':3, 'c':5})
42
+ 30
43
+
44
+ >>> _flop_count('abc', True, 2, {'a': 2, 'b':3, 'c':5})
45
+ 60
46
+
47
+ """
48
+
49
+ overall_size = _compute_size_by_dict(idx_contraction, size_dictionary)
50
+ op_factor = max(1, num_terms - 1)
51
+ if inner:
52
+ op_factor += 1
53
+
54
+ return overall_size * op_factor
55
+
56
+ def _compute_size_by_dict(indices, idx_dict):
57
+ """
58
+ Computes the product of the elements in indices based on the dictionary
59
+ idx_dict.
60
+
61
+ Parameters
62
+ ----------
63
+ indices : iterable
64
+ Indices to base the product on.
65
+ idx_dict : dictionary
66
+ Dictionary of index sizes
67
+
68
+ Returns
69
+ -------
70
+ ret : int
71
+ The resulting product.
72
+
73
+ Examples
74
+ --------
75
+ >>> _compute_size_by_dict('abbc', {'a': 2, 'b':3, 'c':5})
76
+ 90
77
+
78
+ """
79
+ ret = 1
80
+ for i in indices:
81
+ ret *= idx_dict[i]
82
+ return ret
83
+
84
+
85
+ def _find_contraction(positions, input_sets, output_set):
86
+ """
87
+ Finds the contraction for a given set of input and output sets.
88
+
89
+ Parameters
90
+ ----------
91
+ positions : iterable
92
+ Integer positions of terms used in the contraction.
93
+ input_sets : list
94
+ List of sets that represent the lhs side of the einsum subscript
95
+ output_set : set
96
+ Set that represents the rhs side of the overall einsum subscript
97
+
98
+ Returns
99
+ -------
100
+ new_result : set
101
+ The indices of the resulting contraction
102
+ remaining : list
103
+ List of sets that have not been contracted, the new set is appended to
104
+ the end of this list
105
+ idx_removed : set
106
+ Indices removed from the entire contraction
107
+ idx_contraction : set
108
+ The indices used in the current contraction
109
+
110
+ Examples
111
+ --------
112
+
113
+ # A simple dot product test case
114
+ >>> pos = (0, 1)
115
+ >>> isets = [set('ab'), set('bc')]
116
+ >>> oset = set('ac')
117
+ >>> _find_contraction(pos, isets, oset)
118
+ ({'a', 'c'}, [{'a', 'c'}], {'b'}, {'a', 'b', 'c'})
119
+
120
+ # A more complex case with additional terms in the contraction
121
+ >>> pos = (0, 2)
122
+ >>> isets = [set('abd'), set('ac'), set('bdc')]
123
+ >>> oset = set('ac')
124
+ >>> _find_contraction(pos, isets, oset)
125
+ ({'a', 'c'}, [{'a', 'c'}, {'a', 'c'}], {'b', 'd'}, {'a', 'b', 'c', 'd'})
126
+ """
127
+
128
+ idx_contract = set()
129
+ idx_remain = output_set.copy()
130
+ remaining = []
131
+ for ind, value in enumerate(input_sets):
132
+ if ind in positions:
133
+ idx_contract |= value
134
+ else:
135
+ remaining.append(value)
136
+ idx_remain |= value
137
+
138
+ new_result = idx_remain & idx_contract
139
+ idx_removed = (idx_contract - new_result)
140
+ remaining.append(new_result)
141
+
142
+ return (new_result, remaining, idx_removed, idx_contract)
143
+
144
+
145
+ def _optimal_path(input_sets, output_set, idx_dict, memory_limit):
146
+ """
147
+ Computes all possible pair contractions, sieves the results based
148
+ on ``memory_limit`` and returns the lowest cost path. This algorithm
149
+ scales factorial with respect to the elements in the list ``input_sets``.
150
+
151
+ Parameters
152
+ ----------
153
+ input_sets : list
154
+ List of sets that represent the lhs side of the einsum subscript
155
+ output_set : set
156
+ Set that represents the rhs side of the overall einsum subscript
157
+ idx_dict : dictionary
158
+ Dictionary of index sizes
159
+ memory_limit : int
160
+ The maximum number of elements in a temporary array
161
+
162
+ Returns
163
+ -------
164
+ path : list
165
+ The optimal contraction order within the memory limit constraint.
166
+
167
+ Examples
168
+ --------
169
+ >>> isets = [set('abd'), set('ac'), set('bdc')]
170
+ >>> oset = set()
171
+ >>> idx_sizes = {'a': 1, 'b':2, 'c':3, 'd':4}
172
+ >>> _optimal_path(isets, oset, idx_sizes, 5000)
173
+ [(0, 2), (0, 1)]
174
+ """
175
+
176
+ full_results = [(0, [], input_sets)]
177
+ for iteration in range(len(input_sets) - 1):
178
+ iter_results = []
179
+
180
+ # Compute all unique pairs
181
+ for curr in full_results:
182
+ cost, positions, remaining = curr
183
+ for con in itertools.combinations(range(len(input_sets) - iteration), 2):
184
+
185
+ # Find the contraction
186
+ cont = _find_contraction(con, remaining, output_set)
187
+ new_result, new_input_sets, idx_removed, idx_contract = cont
188
+
189
+ # Sieve the results based on memory_limit
190
+ new_size = _compute_size_by_dict(new_result, idx_dict)
191
+ if new_size > memory_limit:
192
+ continue
193
+
194
+ # Build (total_cost, positions, indices_remaining)
195
+ total_cost = cost + _flop_count(idx_contract, idx_removed, len(con), idx_dict)
196
+ new_pos = positions + [con]
197
+ iter_results.append((total_cost, new_pos, new_input_sets))
198
+
199
+ # Update combinatorial list, if we did not find anything return best
200
+ # path + remaining contractions
201
+ if iter_results:
202
+ full_results = iter_results
203
+ else:
204
+ path = min(full_results, key=lambda x: x[0])[1]
205
+ path += [tuple(range(len(input_sets) - iteration))]
206
+ return path
207
+
208
+ # If we have not found anything return single einsum contraction
209
+ if len(full_results) == 0:
210
+ return [tuple(range(len(input_sets)))]
211
+
212
+ path = min(full_results, key=lambda x: x[0])[1]
213
+ return path
214
+
215
+ def _parse_possible_contraction(positions, input_sets, output_set, idx_dict, memory_limit, path_cost, naive_cost):
216
+ """Compute the cost (removed size + flops) and resultant indices for
217
+ performing the contraction specified by ``positions``.
218
+
219
+ Parameters
220
+ ----------
221
+ positions : tuple of int
222
+ The locations of the proposed tensors to contract.
223
+ input_sets : list of sets
224
+ The indices found on each tensors.
225
+ output_set : set
226
+ The output indices of the expression.
227
+ idx_dict : dict
228
+ Mapping of each index to its size.
229
+ memory_limit : int
230
+ The total allowed size for an intermediary tensor.
231
+ path_cost : int
232
+ The contraction cost so far.
233
+ naive_cost : int
234
+ The cost of the unoptimized expression.
235
+
236
+ Returns
237
+ -------
238
+ cost : (int, int)
239
+ A tuple containing the size of any indices removed, and the flop cost.
240
+ positions : tuple of int
241
+ The locations of the proposed tensors to contract.
242
+ new_input_sets : list of sets
243
+ The resulting new list of indices if this proposed contraction is performed.
244
+
245
+ """
246
+
247
+ # Find the contraction
248
+ contract = _find_contraction(positions, input_sets, output_set)
249
+ idx_result, new_input_sets, idx_removed, idx_contract = contract
250
+
251
+ # Sieve the results based on memory_limit
252
+ new_size = _compute_size_by_dict(idx_result, idx_dict)
253
+ if new_size > memory_limit:
254
+ return None
255
+
256
+ # Build sort tuple
257
+ old_sizes = (_compute_size_by_dict(input_sets[p], idx_dict) for p in positions)
258
+ removed_size = sum(old_sizes) - new_size
259
+
260
+ # NB: removed_size used to be just the size of any removed indices i.e.:
261
+ # helpers.compute_size_by_dict(idx_removed, idx_dict)
262
+ cost = _flop_count(idx_contract, idx_removed, len(positions), idx_dict)
263
+ sort = (-removed_size, cost)
264
+
265
+ # Sieve based on total cost as well
266
+ if (path_cost + cost) > naive_cost:
267
+ return None
268
+
269
+ # Add contraction to possible choices
270
+ return [sort, positions, new_input_sets]
271
+
272
+
273
+ def _update_other_results(results, best):
274
+ """Update the positions and provisional input_sets of ``results`` based on
275
+ performing the contraction result ``best``. Remove any involving the tensors
276
+ contracted.
277
+
278
+ Parameters
279
+ ----------
280
+ results : list
281
+ List of contraction results produced by ``_parse_possible_contraction``.
282
+ best : list
283
+ The best contraction of ``results`` i.e. the one that will be performed.
284
+
285
+ Returns
286
+ -------
287
+ mod_results : list
288
+ The list of modified results, updated with outcome of ``best`` contraction.
289
+ """
290
+
291
+ best_con = best[1]
292
+ bx, by = best_con
293
+ mod_results = []
294
+
295
+ for cost, (x, y), con_sets in results:
296
+
297
+ # Ignore results involving tensors just contracted
298
+ if x in best_con or y in best_con:
299
+ continue
300
+
301
+ # Update the input_sets
302
+ del con_sets[by - int(by > x) - int(by > y)]
303
+ del con_sets[bx - int(bx > x) - int(bx > y)]
304
+ con_sets.insert(-1, best[2][-1])
305
+
306
+ # Update the position indices
307
+ mod_con = x - int(x > bx) - int(x > by), y - int(y > bx) - int(y > by)
308
+ mod_results.append((cost, mod_con, con_sets))
309
+
310
+ return mod_results
311
+
312
+ def _greedy_path(input_sets, output_set, idx_dict, memory_limit):
313
+ """
314
+ Finds the path by contracting the best pair until the input list is
315
+ exhausted. The best pair is found by minimizing the tuple
316
+ ``(-prod(indices_removed), cost)``. What this amounts to is prioritizing
317
+ matrix multiplication or inner product operations, then Hadamard like
318
+ operations, and finally outer operations. Outer products are limited by
319
+ ``memory_limit``. This algorithm scales cubically with respect to the
320
+ number of elements in the list ``input_sets``.
321
+
322
+ Parameters
323
+ ----------
324
+ input_sets : list
325
+ List of sets that represent the lhs side of the einsum subscript
326
+ output_set : set
327
+ Set that represents the rhs side of the overall einsum subscript
328
+ idx_dict : dictionary
329
+ Dictionary of index sizes
330
+ memory_limit : int
331
+ The maximum number of elements in a temporary array
332
+
333
+ Returns
334
+ -------
335
+ path : list
336
+ The greedy contraction order within the memory limit constraint.
337
+
338
+ Examples
339
+ --------
340
+ >>> isets = [set('abd'), set('ac'), set('bdc')]
341
+ >>> oset = set()
342
+ >>> idx_sizes = {'a': 1, 'b':2, 'c':3, 'd':4}
343
+ >>> _greedy_path(isets, oset, idx_sizes, 5000)
344
+ [(0, 2), (0, 1)]
345
+ """
346
+
347
+ # Handle trivial cases that leaked through
348
+ if len(input_sets) == 1:
349
+ return [(0,)]
350
+ elif len(input_sets) == 2:
351
+ return [(0, 1)]
352
+
353
+ # Build up a naive cost
354
+ contract = _find_contraction(range(len(input_sets)), input_sets, output_set)
355
+ idx_result, new_input_sets, idx_removed, idx_contract = contract
356
+ naive_cost = _flop_count(idx_contract, idx_removed, len(input_sets), idx_dict)
357
+
358
+ # Initially iterate over all pairs
359
+ comb_iter = itertools.combinations(range(len(input_sets)), 2)
360
+ known_contractions = []
361
+
362
+ path_cost = 0
363
+ path = []
364
+
365
+ for iteration in range(len(input_sets) - 1):
366
+
367
+ # Iterate over all pairs on first step, only previously found pairs on subsequent steps
368
+ for positions in comb_iter:
369
+
370
+ # Always initially ignore outer products
371
+ if input_sets[positions[0]].isdisjoint(input_sets[positions[1]]):
372
+ continue
373
+
374
+ result = _parse_possible_contraction(positions, input_sets, output_set, idx_dict, memory_limit, path_cost,
375
+ naive_cost)
376
+ if result is not None:
377
+ known_contractions.append(result)
378
+
379
+ # If we do not have a inner contraction, rescan pairs including outer products
380
+ if len(known_contractions) == 0:
381
+
382
+ # Then check the outer products
383
+ for positions in itertools.combinations(range(len(input_sets)), 2):
384
+ result = _parse_possible_contraction(positions, input_sets, output_set, idx_dict, memory_limit,
385
+ path_cost, naive_cost)
386
+ if result is not None:
387
+ known_contractions.append(result)
388
+
389
+ # If we still did not find any remaining contractions, default back to einsum like behavior
390
+ if len(known_contractions) == 0:
391
+ path.append(tuple(range(len(input_sets))))
392
+ break
393
+
394
+ # Sort based on first index
395
+ best = min(known_contractions, key=lambda x: x[0])
396
+
397
+ # Now propagate as many unused contractions as possible to next iteration
398
+ known_contractions = _update_other_results(known_contractions, best)
399
+
400
+ # Next iteration only compute contractions with the new tensor
401
+ # All other contractions have been accounted for
402
+ input_sets = best[2]
403
+ new_tensor_pos = len(input_sets) - 1
404
+ comb_iter = ((i, new_tensor_pos) for i in range(new_tensor_pos))
405
+
406
+ # Update path and total cost
407
+ path.append(best[1])
408
+ path_cost += best[0][1]
409
+
410
+ return path
411
+
412
+
413
+ def _can_dot(inputs, result, idx_removed):
414
+ """
415
+ Checks if we can use BLAS (np.tensordot) call and its beneficial to do so.
416
+
417
+ Parameters
418
+ ----------
419
+ inputs : list of str
420
+ Specifies the subscripts for summation.
421
+ result : str
422
+ Resulting summation.
423
+ idx_removed : set
424
+ Indices that are removed in the summation
425
+
426
+
427
+ Returns
428
+ -------
429
+ type : bool
430
+ Returns true if BLAS should and can be used, else False
431
+
432
+ Notes
433
+ -----
434
+ If the operations is BLAS level 1 or 2 and is not already aligned
435
+ we default back to einsum as the memory movement to copy is more
436
+ costly than the operation itself.
437
+
438
+
439
+ Examples
440
+ --------
441
+
442
+ # Standard GEMM operation
443
+ >>> _can_dot(['ij', 'jk'], 'ik', set('j'))
444
+ True
445
+
446
+ # Can use the standard BLAS, but requires odd data movement
447
+ >>> _can_dot(['ijj', 'jk'], 'ik', set('j'))
448
+ False
449
+
450
+ # DDOT where the memory is not aligned
451
+ >>> _can_dot(['ijk', 'ikj'], '', set('ijk'))
452
+ False
453
+
454
+ """
455
+
456
+ # All `dot` calls remove indices
457
+ if len(idx_removed) == 0:
458
+ return False
459
+
460
+ # BLAS can only handle two operands
461
+ if len(inputs) != 2:
462
+ return False
463
+
464
+ input_left, input_right = inputs
465
+
466
+ for c in set(input_left + input_right):
467
+ # can't deal with repeated indices on same input or more than 2 total
468
+ nl, nr = input_left.count(c), input_right.count(c)
469
+ if (nl > 1) or (nr > 1) or (nl + nr > 2):
470
+ return False
471
+
472
+ # can't do implicit summation or dimension collapse e.g.
473
+ # "ab,bc->c" (implicitly sum over 'a')
474
+ # "ab,ca->ca" (take diagonal of 'a')
475
+ if nl + nr - 1 == int(c in result):
476
+ return False
477
+
478
+ # Build a few temporaries
479
+ set_left = set(input_left)
480
+ set_right = set(input_right)
481
+ keep_left = set_left - idx_removed
482
+ keep_right = set_right - idx_removed
483
+ rs = len(idx_removed)
484
+
485
+ # At this point we are a DOT, GEMV, or GEMM operation
486
+
487
+ # Handle inner products
488
+
489
+ # DDOT with aligned data
490
+ if input_left == input_right:
491
+ return True
492
+
493
+ # DDOT without aligned data (better to use einsum)
494
+ if set_left == set_right:
495
+ return False
496
+
497
+ # Handle the 4 possible (aligned) GEMV or GEMM cases
498
+
499
+ # GEMM or GEMV no transpose
500
+ if input_left[-rs:] == input_right[:rs]:
501
+ return True
502
+
503
+ # GEMM or GEMV transpose both
504
+ if input_left[:rs] == input_right[-rs:]:
505
+ return True
506
+
507
+ # GEMM or GEMV transpose right
508
+ if input_left[-rs:] == input_right[-rs:]:
509
+ return True
510
+
511
+ # GEMM or GEMV transpose left
512
+ if input_left[:rs] == input_right[:rs]:
513
+ return True
514
+
515
+ # Einsum is faster than GEMV if we have to copy data
516
+ if not keep_left or not keep_right:
517
+ return False
518
+
519
+ # We are a matrix-matrix product, but we need to copy data
520
+ return True
521
+
522
+
523
+ def _parse_einsum_input(operands):
524
+ """
525
+ A reproduction of einsum c side einsum parsing in python.
526
+
527
+ Returns
528
+ -------
529
+ input_strings : str
530
+ Parsed input strings
531
+ output_string : str
532
+ Parsed output string
533
+ operands : list of array_like
534
+ The operands to use in the numpy contraction
535
+
536
+ Examples
537
+ --------
538
+ The operand list is simplified to reduce printing:
539
+
540
+ >>> np.random.seed(123)
541
+ >>> a = np.random.rand(4, 4)
542
+ >>> b = np.random.rand(4, 4, 4)
543
+ >>> _parse_einsum_input(('...a,...a->...', a, b))
544
+ ('za,xza', 'xz', [a, b]) # may vary
545
+
546
+ >>> _parse_einsum_input((a, [Ellipsis, 0], b, [Ellipsis, 0]))
547
+ ('za,xza', 'xz', [a, b]) # may vary
548
+ """
549
+
550
+ if len(operands) == 0:
551
+ raise ValueError("No input operands")
552
+
553
+ if isinstance(operands[0], str):
554
+ subscripts = operands[0].replace(" ", "")
555
+ operands = [asanyarray(v) for v in operands[1:]]
556
+
557
+ # Ensure all characters are valid
558
+ for s in subscripts:
559
+ if s in '.,->':
560
+ continue
561
+ if s not in einsum_symbols:
562
+ raise ValueError("Character %s is not a valid symbol." % s)
563
+
564
+ else:
565
+ tmp_operands = list(operands)
566
+ operand_list = []
567
+ subscript_list = []
568
+ for p in range(len(operands) // 2):
569
+ operand_list.append(tmp_operands.pop(0))
570
+ subscript_list.append(tmp_operands.pop(0))
571
+
572
+ output_list = tmp_operands[-1] if len(tmp_operands) else None
573
+ operands = [asanyarray(v) for v in operand_list]
574
+ subscripts = ""
575
+ last = len(subscript_list) - 1
576
+ for num, sub in enumerate(subscript_list):
577
+ for s in sub:
578
+ if s is Ellipsis:
579
+ subscripts += "..."
580
+ else:
581
+ try:
582
+ s = operator.index(s)
583
+ except TypeError as e:
584
+ raise TypeError("For this input type lists must contain "
585
+ "either int or Ellipsis") from e
586
+ subscripts += einsum_symbols[s]
587
+ if num != last:
588
+ subscripts += ","
589
+
590
+ if output_list is not None:
591
+ subscripts += "->"
592
+ for s in output_list:
593
+ if s is Ellipsis:
594
+ subscripts += "..."
595
+ else:
596
+ try:
597
+ s = operator.index(s)
598
+ except TypeError as e:
599
+ raise TypeError("For this input type lists must contain "
600
+ "either int or Ellipsis") from e
601
+ subscripts += einsum_symbols[s]
602
+ # Check for proper "->"
603
+ if ("-" in subscripts) or (">" in subscripts):
604
+ invalid = (subscripts.count("-") > 1) or (subscripts.count(">") > 1)
605
+ if invalid or (subscripts.count("->") != 1):
606
+ raise ValueError("Subscripts can only contain one '->'.")
607
+
608
+ # Parse ellipses
609
+ if "." in subscripts:
610
+ used = subscripts.replace(".", "").replace(",", "").replace("->", "")
611
+ unused = list(einsum_symbols_set - set(used))
612
+ ellipse_inds = "".join(unused)
613
+ longest = 0
614
+
615
+ if "->" in subscripts:
616
+ input_tmp, output_sub = subscripts.split("->")
617
+ split_subscripts = input_tmp.split(",")
618
+ out_sub = True
619
+ else:
620
+ split_subscripts = subscripts.split(',')
621
+ out_sub = False
622
+
623
+ for num, sub in enumerate(split_subscripts):
624
+ if "." in sub:
625
+ if (sub.count(".") != 3) or (sub.count("...") != 1):
626
+ raise ValueError("Invalid Ellipses.")
627
+
628
+ # Take into account numerical values
629
+ if operands[num].shape == ():
630
+ ellipse_count = 0
631
+ else:
632
+ ellipse_count = max(operands[num].ndim, 1)
633
+ ellipse_count -= (len(sub) - 3)
634
+
635
+ if ellipse_count > longest:
636
+ longest = ellipse_count
637
+
638
+ if ellipse_count < 0:
639
+ raise ValueError("Ellipses lengths do not match.")
640
+ elif ellipse_count == 0:
641
+ split_subscripts[num] = sub.replace('...', '')
642
+ else:
643
+ rep_inds = ellipse_inds[-ellipse_count:]
644
+ split_subscripts[num] = sub.replace('...', rep_inds)
645
+
646
+ subscripts = ",".join(split_subscripts)
647
+ if longest == 0:
648
+ out_ellipse = ""
649
+ else:
650
+ out_ellipse = ellipse_inds[-longest:]
651
+
652
+ if out_sub:
653
+ subscripts += "->" + output_sub.replace("...", out_ellipse)
654
+ else:
655
+ # Special care for outputless ellipses
656
+ output_subscript = ""
657
+ tmp_subscripts = subscripts.replace(",", "")
658
+ for s in sorted(set(tmp_subscripts)):
659
+ if s not in (einsum_symbols):
660
+ raise ValueError("Character %s is not a valid symbol." % s)
661
+ if tmp_subscripts.count(s) == 1:
662
+ output_subscript += s
663
+ normal_inds = ''.join(sorted(set(output_subscript) -
664
+ set(out_ellipse)))
665
+
666
+ subscripts += "->" + out_ellipse + normal_inds
667
+
668
+ # Build output string if does not exist
669
+ if "->" in subscripts:
670
+ input_subscripts, output_subscript = subscripts.split("->")
671
+ else:
672
+ input_subscripts = subscripts
673
+ # Build output subscripts
674
+ tmp_subscripts = subscripts.replace(",", "")
675
+ output_subscript = ""
676
+ for s in sorted(set(tmp_subscripts)):
677
+ if s not in einsum_symbols:
678
+ raise ValueError("Character %s is not a valid symbol." % s)
679
+ if tmp_subscripts.count(s) == 1:
680
+ output_subscript += s
681
+
682
+ # Make sure output subscripts are in the input
683
+ for char in output_subscript:
684
+ if char not in input_subscripts:
685
+ raise ValueError("Output character %s did not appear in the input"
686
+ % char)
687
+
688
+ # Make sure number operands is equivalent to the number of terms
689
+ if len(input_subscripts.split(',')) != len(operands):
690
+ raise ValueError("Number of einsum subscripts must be equal to the "
691
+ "number of operands.")
692
+
693
+ return (input_subscripts, output_subscript, operands)
694
+
695
+
696
+ def _einsum_path_dispatcher(*operands, optimize=None, einsum_call=None):
697
+ # NOTE: technically, we should only dispatch on array-like arguments, not
698
+ # subscripts (given as strings). But separating operands into
699
+ # arrays/subscripts is a little tricky/slow (given einsum's two supported
700
+ # signatures), so as a practical shortcut we dispatch on everything.
701
+ # Strings will be ignored for dispatching since they don't define
702
+ # __array_function__.
703
+ return operands
704
+
705
+
706
+ @array_function_dispatch(_einsum_path_dispatcher, module='numpy')
707
+ def einsum_path(*operands, optimize='greedy', einsum_call=False):
708
+ """
709
+ einsum_path(subscripts, *operands, optimize='greedy')
710
+
711
+ Evaluates the lowest cost contraction order for an einsum expression by
712
+ considering the creation of intermediate arrays.
713
+
714
+ Parameters
715
+ ----------
716
+ subscripts : str
717
+ Specifies the subscripts for summation.
718
+ *operands : list of array_like
719
+ These are the arrays for the operation.
720
+ optimize : {bool, list, tuple, 'greedy', 'optimal'}
721
+ Choose the type of path. If a tuple is provided, the second argument is
722
+ assumed to be the maximum intermediate size created. If only a single
723
+ argument is provided the largest input or output array size is used
724
+ as a maximum intermediate size.
725
+
726
+ * if a list is given that starts with ``einsum_path``, uses this as the
727
+ contraction path
728
+ * if False no optimization is taken
729
+ * if True defaults to the 'greedy' algorithm
730
+ * 'optimal' An algorithm that combinatorially explores all possible
731
+ ways of contracting the listed tensors and chooses the least costly
732
+ path. Scales exponentially with the number of terms in the
733
+ contraction.
734
+ * 'greedy' An algorithm that chooses the best pair contraction
735
+ at each step. Effectively, this algorithm searches the largest inner,
736
+ Hadamard, and then outer products at each step. Scales cubically with
737
+ the number of terms in the contraction. Equivalent to the 'optimal'
738
+ path for most contractions.
739
+
740
+ Default is 'greedy'.
741
+
742
+ Returns
743
+ -------
744
+ path : list of tuples
745
+ A list representation of the einsum path.
746
+ string_repr : str
747
+ A printable representation of the einsum path.
748
+
749
+ Notes
750
+ -----
751
+ The resulting path indicates which terms of the input contraction should be
752
+ contracted first, the result of this contraction is then appended to the
753
+ end of the contraction list. This list can then be iterated over until all
754
+ intermediate contractions are complete.
755
+
756
+ See Also
757
+ --------
758
+ einsum, linalg.multi_dot
759
+
760
+ Examples
761
+ --------
762
+
763
+ We can begin with a chain dot example. In this case, it is optimal to
764
+ contract the ``b`` and ``c`` tensors first as represented by the first
765
+ element of the path ``(1, 2)``. The resulting tensor is added to the end
766
+ of the contraction and the remaining contraction ``(0, 1)`` is then
767
+ completed.
768
+
769
+ >>> np.random.seed(123)
770
+ >>> a = np.random.rand(2, 2)
771
+ >>> b = np.random.rand(2, 5)
772
+ >>> c = np.random.rand(5, 2)
773
+ >>> path_info = np.einsum_path('ij,jk,kl->il', a, b, c, optimize='greedy')
774
+ >>> print(path_info[0])
775
+ ['einsum_path', (1, 2), (0, 1)]
776
+ >>> print(path_info[1])
777
+ Complete contraction: ij,jk,kl->il # may vary
778
+ Naive scaling: 4
779
+ Optimized scaling: 3
780
+ Naive FLOP count: 1.600e+02
781
+ Optimized FLOP count: 5.600e+01
782
+ Theoretical speedup: 2.857
783
+ Largest intermediate: 4.000e+00 elements
784
+ -------------------------------------------------------------------------
785
+ scaling current remaining
786
+ -------------------------------------------------------------------------
787
+ 3 kl,jk->jl ij,jl->il
788
+ 3 jl,ij->il il->il
789
+
790
+
791
+ A more complex index transformation example.
792
+
793
+ >>> I = np.random.rand(10, 10, 10, 10)
794
+ >>> C = np.random.rand(10, 10)
795
+ >>> path_info = np.einsum_path('ea,fb,abcd,gc,hd->efgh', C, C, I, C, C,
796
+ ... optimize='greedy')
797
+
798
+ >>> print(path_info[0])
799
+ ['einsum_path', (0, 2), (0, 3), (0, 2), (0, 1)]
800
+ >>> print(path_info[1])
801
+ Complete contraction: ea,fb,abcd,gc,hd->efgh # may vary
802
+ Naive scaling: 8
803
+ Optimized scaling: 5
804
+ Naive FLOP count: 8.000e+08
805
+ Optimized FLOP count: 8.000e+05
806
+ Theoretical speedup: 1000.000
807
+ Largest intermediate: 1.000e+04 elements
808
+ --------------------------------------------------------------------------
809
+ scaling current remaining
810
+ --------------------------------------------------------------------------
811
+ 5 abcd,ea->bcde fb,gc,hd,bcde->efgh
812
+ 5 bcde,fb->cdef gc,hd,cdef->efgh
813
+ 5 cdef,gc->defg hd,defg->efgh
814
+ 5 defg,hd->efgh efgh->efgh
815
+ """
816
+
817
+ # Figure out what the path really is
818
+ path_type = optimize
819
+ if path_type is True:
820
+ path_type = 'greedy'
821
+ if path_type is None:
822
+ path_type = False
823
+
824
+ explicit_einsum_path = False
825
+ memory_limit = None
826
+
827
+ # No optimization or a named path algorithm
828
+ if (path_type is False) or isinstance(path_type, str):
829
+ pass
830
+
831
+ # Given an explicit path
832
+ elif len(path_type) and (path_type[0] == 'einsum_path'):
833
+ explicit_einsum_path = True
834
+
835
+ # Path tuple with memory limit
836
+ elif ((len(path_type) == 2) and isinstance(path_type[0], str) and
837
+ isinstance(path_type[1], (int, float))):
838
+ memory_limit = int(path_type[1])
839
+ path_type = path_type[0]
840
+
841
+ else:
842
+ raise TypeError("Did not understand the path: %s" % str(path_type))
843
+
844
+ # Hidden option, only einsum should call this
845
+ einsum_call_arg = einsum_call
846
+
847
+ # Python side parsing
848
+ input_subscripts, output_subscript, operands = _parse_einsum_input(operands)
849
+
850
+ # Build a few useful list and sets
851
+ input_list = input_subscripts.split(',')
852
+ input_sets = [set(x) for x in input_list]
853
+ output_set = set(output_subscript)
854
+ indices = set(input_subscripts.replace(',', ''))
855
+
856
+ # Get length of each unique dimension and ensure all dimensions are correct
857
+ dimension_dict = {}
858
+ broadcast_indices = [[] for x in range(len(input_list))]
859
+ for tnum, term in enumerate(input_list):
860
+ sh = operands[tnum].shape
861
+ if len(sh) != len(term):
862
+ raise ValueError("Einstein sum subscript %s does not contain the "
863
+ "correct number of indices for operand %d."
864
+ % (input_subscripts[tnum], tnum))
865
+ for cnum, char in enumerate(term):
866
+ dim = sh[cnum]
867
+
868
+ # Build out broadcast indices
869
+ if dim == 1:
870
+ broadcast_indices[tnum].append(char)
871
+
872
+ if char in dimension_dict.keys():
873
+ # For broadcasting cases we always want the largest dim size
874
+ if dimension_dict[char] == 1:
875
+ dimension_dict[char] = dim
876
+ elif dim not in (1, dimension_dict[char]):
877
+ raise ValueError("Size of label '%s' for operand %d (%d) "
878
+ "does not match previous terms (%d)."
879
+ % (char, tnum, dimension_dict[char], dim))
880
+ else:
881
+ dimension_dict[char] = dim
882
+
883
+ # Convert broadcast inds to sets
884
+ broadcast_indices = [set(x) for x in broadcast_indices]
885
+
886
+ # Compute size of each input array plus the output array
887
+ size_list = [_compute_size_by_dict(term, dimension_dict)
888
+ for term in input_list + [output_subscript]]
889
+ max_size = max(size_list)
890
+
891
+ if memory_limit is None:
892
+ memory_arg = max_size
893
+ else:
894
+ memory_arg = memory_limit
895
+
896
+ # Compute naive cost
897
+ # This isn't quite right, need to look into exactly how einsum does this
898
+ inner_product = (sum(len(x) for x in input_sets) - len(indices)) > 0
899
+ naive_cost = _flop_count(indices, inner_product, len(input_list), dimension_dict)
900
+
901
+ # Compute the path
902
+ if explicit_einsum_path:
903
+ path = path_type[1:]
904
+ elif (
905
+ (path_type is False)
906
+ or (len(input_list) in [1, 2])
907
+ or (indices == output_set)
908
+ ):
909
+ # Nothing to be optimized, leave it to einsum
910
+ path = [tuple(range(len(input_list)))]
911
+ elif path_type == "greedy":
912
+ path = _greedy_path(input_sets, output_set, dimension_dict, memory_arg)
913
+ elif path_type == "optimal":
914
+ path = _optimal_path(input_sets, output_set, dimension_dict, memory_arg)
915
+ else:
916
+ raise KeyError("Path name %s not found", path_type)
917
+
918
+ cost_list, scale_list, size_list, contraction_list = [], [], [], []
919
+
920
+ # Build contraction tuple (positions, gemm, einsum_str, remaining)
921
+ for cnum, contract_inds in enumerate(path):
922
+ # Make sure we remove inds from right to left
923
+ contract_inds = tuple(sorted(list(contract_inds), reverse=True))
924
+
925
+ contract = _find_contraction(contract_inds, input_sets, output_set)
926
+ out_inds, input_sets, idx_removed, idx_contract = contract
927
+
928
+ cost = _flop_count(idx_contract, idx_removed, len(contract_inds), dimension_dict)
929
+ cost_list.append(cost)
930
+ scale_list.append(len(idx_contract))
931
+ size_list.append(_compute_size_by_dict(out_inds, dimension_dict))
932
+
933
+ bcast = set()
934
+ tmp_inputs = []
935
+ for x in contract_inds:
936
+ tmp_inputs.append(input_list.pop(x))
937
+ bcast |= broadcast_indices.pop(x)
938
+
939
+ new_bcast_inds = bcast - idx_removed
940
+
941
+ # If we're broadcasting, nix blas
942
+ if not len(idx_removed & bcast):
943
+ do_blas = _can_dot(tmp_inputs, out_inds, idx_removed)
944
+ else:
945
+ do_blas = False
946
+
947
+ # Last contraction
948
+ if (cnum - len(path)) == -1:
949
+ idx_result = output_subscript
950
+ else:
951
+ sort_result = [(dimension_dict[ind], ind) for ind in out_inds]
952
+ idx_result = "".join([x[1] for x in sorted(sort_result)])
953
+
954
+ input_list.append(idx_result)
955
+ broadcast_indices.append(new_bcast_inds)
956
+ einsum_str = ",".join(tmp_inputs) + "->" + idx_result
957
+
958
+ contraction = (contract_inds, idx_removed, einsum_str, input_list[:], do_blas)
959
+ contraction_list.append(contraction)
960
+
961
+ opt_cost = sum(cost_list) + 1
962
+
963
+ if len(input_list) != 1:
964
+ # Explicit "einsum_path" is usually trusted, but we detect this kind of
965
+ # mistake in order to prevent from returning an intermediate value.
966
+ raise RuntimeError(
967
+ "Invalid einsum_path is specified: {} more operands has to be "
968
+ "contracted.".format(len(input_list) - 1))
969
+
970
+ if einsum_call_arg:
971
+ return (operands, contraction_list)
972
+
973
+ # Return the path along with a nice string representation
974
+ overall_contraction = input_subscripts + "->" + output_subscript
975
+ header = ("scaling", "current", "remaining")
976
+
977
+ speedup = naive_cost / opt_cost
978
+ max_i = max(size_list)
979
+
980
+ path_print = " Complete contraction: %s\n" % overall_contraction
981
+ path_print += " Naive scaling: %d\n" % len(indices)
982
+ path_print += " Optimized scaling: %d\n" % max(scale_list)
983
+ path_print += " Naive FLOP count: %.3e\n" % naive_cost
984
+ path_print += " Optimized FLOP count: %.3e\n" % opt_cost
985
+ path_print += " Theoretical speedup: %3.3f\n" % speedup
986
+ path_print += " Largest intermediate: %.3e elements\n" % max_i
987
+ path_print += "-" * 74 + "\n"
988
+ path_print += "%6s %24s %40s\n" % header
989
+ path_print += "-" * 74
990
+
991
+ for n, contraction in enumerate(contraction_list):
992
+ inds, idx_rm, einsum_str, remaining, blas = contraction
993
+ remaining_str = ",".join(remaining) + "->" + output_subscript
994
+ path_run = (scale_list[n], einsum_str, remaining_str)
995
+ path_print += "\n%4d %24s %40s" % path_run
996
+
997
+ path = ['einsum_path'] + path
998
+ return (path, path_print)
999
+
1000
+
1001
+ def _einsum_dispatcher(*operands, out=None, optimize=None, **kwargs):
1002
+ # Arguably we dispatch on more arguments than we really should; see note in
1003
+ # _einsum_path_dispatcher for why.
1004
+ yield from operands
1005
+ yield out
1006
+
1007
+
1008
+ # Rewrite einsum to handle different cases
1009
+ @array_function_dispatch(_einsum_dispatcher, module='numpy')
1010
+ def einsum(*operands, out=None, optimize=False, **kwargs):
1011
+ """
1012
+ einsum(subscripts, *operands, out=None, dtype=None, order='K',
1013
+ casting='safe', optimize=False)
1014
+
1015
+ Evaluates the Einstein summation convention on the operands.
1016
+
1017
+ Using the Einstein summation convention, many common multi-dimensional,
1018
+ linear algebraic array operations can be represented in a simple fashion.
1019
+ In *implicit* mode `einsum` computes these values.
1020
+
1021
+ In *explicit* mode, `einsum` provides further flexibility to compute
1022
+ other array operations that might not be considered classical Einstein
1023
+ summation operations, by disabling, or forcing summation over specified
1024
+ subscript labels.
1025
+
1026
+ See the notes and examples for clarification.
1027
+
1028
+ Parameters
1029
+ ----------
1030
+ subscripts : str
1031
+ Specifies the subscripts for summation as comma separated list of
1032
+ subscript labels. An implicit (classical Einstein summation)
1033
+ calculation is performed unless the explicit indicator '->' is
1034
+ included as well as subscript labels of the precise output form.
1035
+ operands : list of array_like
1036
+ These are the arrays for the operation.
1037
+ out : ndarray, optional
1038
+ If provided, the calculation is done into this array.
1039
+ dtype : {data-type, None}, optional
1040
+ If provided, forces the calculation to use the data type specified.
1041
+ Note that you may have to also give a more liberal `casting`
1042
+ parameter to allow the conversions. Default is None.
1043
+ order : {'C', 'F', 'A', 'K'}, optional
1044
+ Controls the memory layout of the output. 'C' means it should
1045
+ be C contiguous. 'F' means it should be Fortran contiguous,
1046
+ 'A' means it should be 'F' if the inputs are all 'F', 'C' otherwise.
1047
+ 'K' means it should be as close to the layout as the inputs as
1048
+ is possible, including arbitrarily permuted axes.
1049
+ Default is 'K'.
1050
+ casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
1051
+ Controls what kind of data casting may occur. Setting this to
1052
+ 'unsafe' is not recommended, as it can adversely affect accumulations.
1053
+
1054
+ * 'no' means the data types should not be cast at all.
1055
+ * 'equiv' means only byte-order changes are allowed.
1056
+ * 'safe' means only casts which can preserve values are allowed.
1057
+ * 'same_kind' means only safe casts or casts within a kind,
1058
+ like float64 to float32, are allowed.
1059
+ * 'unsafe' means any data conversions may be done.
1060
+
1061
+ Default is 'safe'.
1062
+ optimize : {False, True, 'greedy', 'optimal'}, optional
1063
+ Controls if intermediate optimization should occur. No optimization
1064
+ will occur if False and True will default to the 'greedy' algorithm.
1065
+ Also accepts an explicit contraction list from the ``np.einsum_path``
1066
+ function. See ``np.einsum_path`` for more details. Defaults to False.
1067
+
1068
+ Returns
1069
+ -------
1070
+ output : ndarray
1071
+ The calculation based on the Einstein summation convention.
1072
+
1073
+ See Also
1074
+ --------
1075
+ einsum_path, dot, inner, outer, tensordot, linalg.multi_dot
1076
+ einops :
1077
+ similar verbose interface is provided by
1078
+ `einops <https://github.com/arogozhnikov/einops>`_ package to cover
1079
+ additional operations: transpose, reshape/flatten, repeat/tile,
1080
+ squeeze/unsqueeze and reductions.
1081
+ opt_einsum :
1082
+ `opt_einsum <https://optimized-einsum.readthedocs.io/en/stable/>`_
1083
+ optimizes contraction order for einsum-like expressions
1084
+ in backend-agnostic manner.
1085
+
1086
+ Notes
1087
+ -----
1088
+ .. versionadded:: 1.6.0
1089
+
1090
+ The Einstein summation convention can be used to compute
1091
+ many multi-dimensional, linear algebraic array operations. `einsum`
1092
+ provides a succinct way of representing these.
1093
+
1094
+ A non-exhaustive list of these operations,
1095
+ which can be computed by `einsum`, is shown below along with examples:
1096
+
1097
+ * Trace of an array, :py:func:`numpy.trace`.
1098
+ * Return a diagonal, :py:func:`numpy.diag`.
1099
+ * Array axis summations, :py:func:`numpy.sum`.
1100
+ * Transpositions and permutations, :py:func:`numpy.transpose`.
1101
+ * Matrix multiplication and dot product, :py:func:`numpy.matmul` :py:func:`numpy.dot`.
1102
+ * Vector inner and outer products, :py:func:`numpy.inner` :py:func:`numpy.outer`.
1103
+ * Broadcasting, element-wise and scalar multiplication, :py:func:`numpy.multiply`.
1104
+ * Tensor contractions, :py:func:`numpy.tensordot`.
1105
+ * Chained array operations, in efficient calculation order, :py:func:`numpy.einsum_path`.
1106
+
1107
+ The subscripts string is a comma-separated list of subscript labels,
1108
+ where each label refers to a dimension of the corresponding operand.
1109
+ Whenever a label is repeated it is summed, so ``np.einsum('i,i', a, b)``
1110
+ is equivalent to :py:func:`np.inner(a,b) <numpy.inner>`. If a label
1111
+ appears only once, it is not summed, so ``np.einsum('i', a)`` produces a
1112
+ view of ``a`` with no changes. A further example ``np.einsum('ij,jk', a, b)``
1113
+ describes traditional matrix multiplication and is equivalent to
1114
+ :py:func:`np.matmul(a,b) <numpy.matmul>`. Repeated subscript labels in one
1115
+ operand take the diagonal. For example, ``np.einsum('ii', a)`` is equivalent
1116
+ to :py:func:`np.trace(a) <numpy.trace>`.
1117
+
1118
+ In *implicit mode*, the chosen subscripts are important
1119
+ since the axes of the output are reordered alphabetically. This
1120
+ means that ``np.einsum('ij', a)`` doesn't affect a 2D array, while
1121
+ ``np.einsum('ji', a)`` takes its transpose. Additionally,
1122
+ ``np.einsum('ij,jk', a, b)`` returns a matrix multiplication, while,
1123
+ ``np.einsum('ij,jh', a, b)`` returns the transpose of the
1124
+ multiplication since subscript 'h' precedes subscript 'i'.
1125
+
1126
+ In *explicit mode* the output can be directly controlled by
1127
+ specifying output subscript labels. This requires the
1128
+ identifier '->' as well as the list of output subscript labels.
1129
+ This feature increases the flexibility of the function since
1130
+ summing can be disabled or forced when required. The call
1131
+ ``np.einsum('i->', a)`` is like :py:func:`np.sum(a, axis=-1) <numpy.sum>`,
1132
+ and ``np.einsum('ii->i', a)`` is like :py:func:`np.diag(a) <numpy.diag>`.
1133
+ The difference is that `einsum` does not allow broadcasting by default.
1134
+ Additionally ``np.einsum('ij,jh->ih', a, b)`` directly specifies the
1135
+ order of the output subscript labels and therefore returns matrix
1136
+ multiplication, unlike the example above in implicit mode.
1137
+
1138
+ To enable and control broadcasting, use an ellipsis. Default
1139
+ NumPy-style broadcasting is done by adding an ellipsis
1140
+ to the left of each term, like ``np.einsum('...ii->...i', a)``.
1141
+ To take the trace along the first and last axes,
1142
+ you can do ``np.einsum('i...i', a)``, or to do a matrix-matrix
1143
+ product with the left-most indices instead of rightmost, one can do
1144
+ ``np.einsum('ij...,jk...->ik...', a, b)``.
1145
+
1146
+ When there is only one operand, no axes are summed, and no output
1147
+ parameter is provided, a view into the operand is returned instead
1148
+ of a new array. Thus, taking the diagonal as ``np.einsum('ii->i', a)``
1149
+ produces a view (changed in version 1.10.0).
1150
+
1151
+ `einsum` also provides an alternative way to provide the subscripts
1152
+ and operands as ``einsum(op0, sublist0, op1, sublist1, ..., [sublistout])``.
1153
+ If the output shape is not provided in this format `einsum` will be
1154
+ calculated in implicit mode, otherwise it will be performed explicitly.
1155
+ The examples below have corresponding `einsum` calls with the two
1156
+ parameter methods.
1157
+
1158
+ .. versionadded:: 1.10.0
1159
+
1160
+ Views returned from einsum are now writeable whenever the input array
1161
+ is writeable. For example, ``np.einsum('ijk...->kji...', a)`` will now
1162
+ have the same effect as :py:func:`np.swapaxes(a, 0, 2) <numpy.swapaxes>`
1163
+ and ``np.einsum('ii->i', a)`` will return a writeable view of the diagonal
1164
+ of a 2D array.
1165
+
1166
+ .. versionadded:: 1.12.0
1167
+
1168
+ Added the ``optimize`` argument which will optimize the contraction order
1169
+ of an einsum expression. For a contraction with three or more operands this
1170
+ can greatly increase the computational efficiency at the cost of a larger
1171
+ memory footprint during computation.
1172
+
1173
+ Typically a 'greedy' algorithm is applied which empirical tests have shown
1174
+ returns the optimal path in the majority of cases. In some cases 'optimal'
1175
+ will return the superlative path through a more expensive, exhaustive search.
1176
+ For iterative calculations it may be advisable to calculate the optimal path
1177
+ once and reuse that path by supplying it as an argument. An example is given
1178
+ below.
1179
+
1180
+ See :py:func:`numpy.einsum_path` for more details.
1181
+
1182
+ Examples
1183
+ --------
1184
+ >>> a = np.arange(25).reshape(5,5)
1185
+ >>> b = np.arange(5)
1186
+ >>> c = np.arange(6).reshape(2,3)
1187
+
1188
+ Trace of a matrix:
1189
+
1190
+ >>> np.einsum('ii', a)
1191
+ 60
1192
+ >>> np.einsum(a, [0,0])
1193
+ 60
1194
+ >>> np.trace(a)
1195
+ 60
1196
+
1197
+ Extract the diagonal (requires explicit form):
1198
+
1199
+ >>> np.einsum('ii->i', a)
1200
+ array([ 0, 6, 12, 18, 24])
1201
+ >>> np.einsum(a, [0,0], [0])
1202
+ array([ 0, 6, 12, 18, 24])
1203
+ >>> np.diag(a)
1204
+ array([ 0, 6, 12, 18, 24])
1205
+
1206
+ Sum over an axis (requires explicit form):
1207
+
1208
+ >>> np.einsum('ij->i', a)
1209
+ array([ 10, 35, 60, 85, 110])
1210
+ >>> np.einsum(a, [0,1], [0])
1211
+ array([ 10, 35, 60, 85, 110])
1212
+ >>> np.sum(a, axis=1)
1213
+ array([ 10, 35, 60, 85, 110])
1214
+
1215
+ For higher dimensional arrays summing a single axis can be done with ellipsis:
1216
+
1217
+ >>> np.einsum('...j->...', a)
1218
+ array([ 10, 35, 60, 85, 110])
1219
+ >>> np.einsum(a, [Ellipsis,1], [Ellipsis])
1220
+ array([ 10, 35, 60, 85, 110])
1221
+
1222
+ Compute a matrix transpose, or reorder any number of axes:
1223
+
1224
+ >>> np.einsum('ji', c)
1225
+ array([[0, 3],
1226
+ [1, 4],
1227
+ [2, 5]])
1228
+ >>> np.einsum('ij->ji', c)
1229
+ array([[0, 3],
1230
+ [1, 4],
1231
+ [2, 5]])
1232
+ >>> np.einsum(c, [1,0])
1233
+ array([[0, 3],
1234
+ [1, 4],
1235
+ [2, 5]])
1236
+ >>> np.transpose(c)
1237
+ array([[0, 3],
1238
+ [1, 4],
1239
+ [2, 5]])
1240
+
1241
+ Vector inner products:
1242
+
1243
+ >>> np.einsum('i,i', b, b)
1244
+ 30
1245
+ >>> np.einsum(b, [0], b, [0])
1246
+ 30
1247
+ >>> np.inner(b,b)
1248
+ 30
1249
+
1250
+ Matrix vector multiplication:
1251
+
1252
+ >>> np.einsum('ij,j', a, b)
1253
+ array([ 30, 80, 130, 180, 230])
1254
+ >>> np.einsum(a, [0,1], b, [1])
1255
+ array([ 30, 80, 130, 180, 230])
1256
+ >>> np.dot(a, b)
1257
+ array([ 30, 80, 130, 180, 230])
1258
+ >>> np.einsum('...j,j', a, b)
1259
+ array([ 30, 80, 130, 180, 230])
1260
+
1261
+ Broadcasting and scalar multiplication:
1262
+
1263
+ >>> np.einsum('..., ...', 3, c)
1264
+ array([[ 0, 3, 6],
1265
+ [ 9, 12, 15]])
1266
+ >>> np.einsum(',ij', 3, c)
1267
+ array([[ 0, 3, 6],
1268
+ [ 9, 12, 15]])
1269
+ >>> np.einsum(3, [Ellipsis], c, [Ellipsis])
1270
+ array([[ 0, 3, 6],
1271
+ [ 9, 12, 15]])
1272
+ >>> np.multiply(3, c)
1273
+ array([[ 0, 3, 6],
1274
+ [ 9, 12, 15]])
1275
+
1276
+ Vector outer product:
1277
+
1278
+ >>> np.einsum('i,j', np.arange(2)+1, b)
1279
+ array([[0, 1, 2, 3, 4],
1280
+ [0, 2, 4, 6, 8]])
1281
+ >>> np.einsum(np.arange(2)+1, [0], b, [1])
1282
+ array([[0, 1, 2, 3, 4],
1283
+ [0, 2, 4, 6, 8]])
1284
+ >>> np.outer(np.arange(2)+1, b)
1285
+ array([[0, 1, 2, 3, 4],
1286
+ [0, 2, 4, 6, 8]])
1287
+
1288
+ Tensor contraction:
1289
+
1290
+ >>> a = np.arange(60.).reshape(3,4,5)
1291
+ >>> b = np.arange(24.).reshape(4,3,2)
1292
+ >>> np.einsum('ijk,jil->kl', a, b)
1293
+ array([[4400., 4730.],
1294
+ [4532., 4874.],
1295
+ [4664., 5018.],
1296
+ [4796., 5162.],
1297
+ [4928., 5306.]])
1298
+ >>> np.einsum(a, [0,1,2], b, [1,0,3], [2,3])
1299
+ array([[4400., 4730.],
1300
+ [4532., 4874.],
1301
+ [4664., 5018.],
1302
+ [4796., 5162.],
1303
+ [4928., 5306.]])
1304
+ >>> np.tensordot(a,b, axes=([1,0],[0,1]))
1305
+ array([[4400., 4730.],
1306
+ [4532., 4874.],
1307
+ [4664., 5018.],
1308
+ [4796., 5162.],
1309
+ [4928., 5306.]])
1310
+
1311
+ Writeable returned arrays (since version 1.10.0):
1312
+
1313
+ >>> a = np.zeros((3, 3))
1314
+ >>> np.einsum('ii->i', a)[:] = 1
1315
+ >>> a
1316
+ array([[1., 0., 0.],
1317
+ [0., 1., 0.],
1318
+ [0., 0., 1.]])
1319
+
1320
+ Example of ellipsis use:
1321
+
1322
+ >>> a = np.arange(6).reshape((3,2))
1323
+ >>> b = np.arange(12).reshape((4,3))
1324
+ >>> np.einsum('ki,jk->ij', a, b)
1325
+ array([[10, 28, 46, 64],
1326
+ [13, 40, 67, 94]])
1327
+ >>> np.einsum('ki,...k->i...', a, b)
1328
+ array([[10, 28, 46, 64],
1329
+ [13, 40, 67, 94]])
1330
+ >>> np.einsum('k...,jk', a, b)
1331
+ array([[10, 28, 46, 64],
1332
+ [13, 40, 67, 94]])
1333
+
1334
+ Chained array operations. For more complicated contractions, speed ups
1335
+ might be achieved by repeatedly computing a 'greedy' path or pre-computing the
1336
+ 'optimal' path and repeatedly applying it, using an
1337
+ `einsum_path` insertion (since version 1.12.0). Performance improvements can be
1338
+ particularly significant with larger arrays:
1339
+
1340
+ >>> a = np.ones(64).reshape(2,4,8)
1341
+
1342
+ Basic `einsum`: ~1520ms (benchmarked on 3.1GHz Intel i5.)
1343
+
1344
+ >>> for iteration in range(500):
1345
+ ... _ = np.einsum('ijk,ilm,njm,nlk,abc->',a,a,a,a,a)
1346
+
1347
+ Sub-optimal `einsum` (due to repeated path calculation time): ~330ms
1348
+
1349
+ >>> for iteration in range(500):
1350
+ ... _ = np.einsum('ijk,ilm,njm,nlk,abc->',a,a,a,a,a, optimize='optimal')
1351
+
1352
+ Greedy `einsum` (faster optimal path approximation): ~160ms
1353
+
1354
+ >>> for iteration in range(500):
1355
+ ... _ = np.einsum('ijk,ilm,njm,nlk,abc->',a,a,a,a,a, optimize='greedy')
1356
+
1357
+ Optimal `einsum` (best usage pattern in some use cases): ~110ms
1358
+
1359
+ >>> path = np.einsum_path('ijk,ilm,njm,nlk,abc->',a,a,a,a,a, optimize='optimal')[0]
1360
+ >>> for iteration in range(500):
1361
+ ... _ = np.einsum('ijk,ilm,njm,nlk,abc->',a,a,a,a,a, optimize=path)
1362
+
1363
+ """
1364
+ # Special handling if out is specified
1365
+ specified_out = out is not None
1366
+
1367
+ # If no optimization, run pure einsum
1368
+ if optimize is False:
1369
+ if specified_out:
1370
+ kwargs['out'] = out
1371
+ return c_einsum(*operands, **kwargs)
1372
+
1373
+ # Check the kwargs to avoid a more cryptic error later, without having to
1374
+ # repeat default values here
1375
+ valid_einsum_kwargs = ['dtype', 'order', 'casting']
1376
+ unknown_kwargs = [k for (k, v) in kwargs.items() if
1377
+ k not in valid_einsum_kwargs]
1378
+ if len(unknown_kwargs):
1379
+ raise TypeError("Did not understand the following kwargs: %s"
1380
+ % unknown_kwargs)
1381
+
1382
+ # Build the contraction list and operand
1383
+ operands, contraction_list = einsum_path(*operands, optimize=optimize,
1384
+ einsum_call=True)
1385
+
1386
+ # Handle order kwarg for output array, c_einsum allows mixed case
1387
+ output_order = kwargs.pop('order', 'K')
1388
+ if output_order.upper() == 'A':
1389
+ if all(arr.flags.f_contiguous for arr in operands):
1390
+ output_order = 'F'
1391
+ else:
1392
+ output_order = 'C'
1393
+
1394
+ # Start contraction loop
1395
+ for num, contraction in enumerate(contraction_list):
1396
+ inds, idx_rm, einsum_str, remaining, blas = contraction
1397
+ tmp_operands = [operands.pop(x) for x in inds]
1398
+
1399
+ # Do we need to deal with the output?
1400
+ handle_out = specified_out and ((num + 1) == len(contraction_list))
1401
+
1402
+ # Call tensordot if still possible
1403
+ if blas:
1404
+ # Checks have already been handled
1405
+ input_str, results_index = einsum_str.split('->')
1406
+ input_left, input_right = input_str.split(',')
1407
+
1408
+ tensor_result = input_left + input_right
1409
+ for s in idx_rm:
1410
+ tensor_result = tensor_result.replace(s, "")
1411
+
1412
+ # Find indices to contract over
1413
+ left_pos, right_pos = [], []
1414
+ for s in sorted(idx_rm):
1415
+ left_pos.append(input_left.find(s))
1416
+ right_pos.append(input_right.find(s))
1417
+
1418
+ # Contract!
1419
+ new_view = tensordot(*tmp_operands, axes=(tuple(left_pos), tuple(right_pos)))
1420
+
1421
+ # Build a new view if needed
1422
+ if (tensor_result != results_index) or handle_out:
1423
+ if handle_out:
1424
+ kwargs["out"] = out
1425
+ new_view = c_einsum(tensor_result + '->' + results_index, new_view, **kwargs)
1426
+
1427
+ # Call einsum
1428
+ else:
1429
+ # If out was specified
1430
+ if handle_out:
1431
+ kwargs["out"] = out
1432
+
1433
+ # Do the contraction
1434
+ new_view = c_einsum(einsum_str, *tmp_operands, **kwargs)
1435
+
1436
+ # Append new items and dereference what we can
1437
+ operands.append(new_view)
1438
+ del tmp_operands, new_view
1439
+
1440
+ if specified_out:
1441
+ return out
1442
+ else:
1443
+ return asanyarray(operands[0], order=output_order)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/memmap.py ADDED
@@ -0,0 +1,338 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from contextlib import nullcontext
2
+
3
+ import numpy as np
4
+ from .._utils import set_module
5
+ from .numeric import uint8, ndarray, dtype
6
+ from numpy.compat import os_fspath, is_pathlib_path
7
+
8
+ __all__ = ['memmap']
9
+
10
+ dtypedescr = dtype
11
+ valid_filemodes = ["r", "c", "r+", "w+"]
12
+ writeable_filemodes = ["r+", "w+"]
13
+
14
+ mode_equivalents = {
15
+ "readonly":"r",
16
+ "copyonwrite":"c",
17
+ "readwrite":"r+",
18
+ "write":"w+"
19
+ }
20
+
21
+
22
+ @set_module('numpy')
23
+ class memmap(ndarray):
24
+ """Create a memory-map to an array stored in a *binary* file on disk.
25
+
26
+ Memory-mapped files are used for accessing small segments of large files
27
+ on disk, without reading the entire file into memory. NumPy's
28
+ memmap's are array-like objects. This differs from Python's ``mmap``
29
+ module, which uses file-like objects.
30
+
31
+ This subclass of ndarray has some unpleasant interactions with
32
+ some operations, because it doesn't quite fit properly as a subclass.
33
+ An alternative to using this subclass is to create the ``mmap``
34
+ object yourself, then create an ndarray with ndarray.__new__ directly,
35
+ passing the object created in its 'buffer=' parameter.
36
+
37
+ This class may at some point be turned into a factory function
38
+ which returns a view into an mmap buffer.
39
+
40
+ Flush the memmap instance to write the changes to the file. Currently there
41
+ is no API to close the underlying ``mmap``. It is tricky to ensure the
42
+ resource is actually closed, since it may be shared between different
43
+ memmap instances.
44
+
45
+
46
+ Parameters
47
+ ----------
48
+ filename : str, file-like object, or pathlib.Path instance
49
+ The file name or file object to be used as the array data buffer.
50
+ dtype : data-type, optional
51
+ The data-type used to interpret the file contents.
52
+ Default is `uint8`.
53
+ mode : {'r+', 'r', 'w+', 'c'}, optional
54
+ The file is opened in this mode:
55
+
56
+ +------+-------------------------------------------------------------+
57
+ | 'r' | Open existing file for reading only. |
58
+ +------+-------------------------------------------------------------+
59
+ | 'r+' | Open existing file for reading and writing. |
60
+ +------+-------------------------------------------------------------+
61
+ | 'w+' | Create or overwrite existing file for reading and writing. |
62
+ | | If ``mode == 'w+'`` then `shape` must also be specified. |
63
+ +------+-------------------------------------------------------------+
64
+ | 'c' | Copy-on-write: assignments affect data in memory, but |
65
+ | | changes are not saved to disk. The file on disk is |
66
+ | | read-only. |
67
+ +------+-------------------------------------------------------------+
68
+
69
+ Default is 'r+'.
70
+ offset : int, optional
71
+ In the file, array data starts at this offset. Since `offset` is
72
+ measured in bytes, it should normally be a multiple of the byte-size
73
+ of `dtype`. When ``mode != 'r'``, even positive offsets beyond end of
74
+ file are valid; The file will be extended to accommodate the
75
+ additional data. By default, ``memmap`` will start at the beginning of
76
+ the file, even if ``filename`` is a file pointer ``fp`` and
77
+ ``fp.tell() != 0``.
78
+ shape : tuple, optional
79
+ The desired shape of the array. If ``mode == 'r'`` and the number
80
+ of remaining bytes after `offset` is not a multiple of the byte-size
81
+ of `dtype`, you must specify `shape`. By default, the returned array
82
+ will be 1-D with the number of elements determined by file size
83
+ and data-type.
84
+ order : {'C', 'F'}, optional
85
+ Specify the order of the ndarray memory layout:
86
+ :term:`row-major`, C-style or :term:`column-major`,
87
+ Fortran-style. This only has an effect if the shape is
88
+ greater than 1-D. The default order is 'C'.
89
+
90
+ Attributes
91
+ ----------
92
+ filename : str or pathlib.Path instance
93
+ Path to the mapped file.
94
+ offset : int
95
+ Offset position in the file.
96
+ mode : str
97
+ File mode.
98
+
99
+ Methods
100
+ -------
101
+ flush
102
+ Flush any changes in memory to file on disk.
103
+ When you delete a memmap object, flush is called first to write
104
+ changes to disk.
105
+
106
+
107
+ See also
108
+ --------
109
+ lib.format.open_memmap : Create or load a memory-mapped ``.npy`` file.
110
+
111
+ Notes
112
+ -----
113
+ The memmap object can be used anywhere an ndarray is accepted.
114
+ Given a memmap ``fp``, ``isinstance(fp, numpy.ndarray)`` returns
115
+ ``True``.
116
+
117
+ Memory-mapped files cannot be larger than 2GB on 32-bit systems.
118
+
119
+ When a memmap causes a file to be created or extended beyond its
120
+ current size in the filesystem, the contents of the new part are
121
+ unspecified. On systems with POSIX filesystem semantics, the extended
122
+ part will be filled with zero bytes.
123
+
124
+ Examples
125
+ --------
126
+ >>> data = np.arange(12, dtype='float32')
127
+ >>> data.resize((3,4))
128
+
129
+ This example uses a temporary file so that doctest doesn't write
130
+ files to your directory. You would use a 'normal' filename.
131
+
132
+ >>> from tempfile import mkdtemp
133
+ >>> import os.path as path
134
+ >>> filename = path.join(mkdtemp(), 'newfile.dat')
135
+
136
+ Create a memmap with dtype and shape that matches our data:
137
+
138
+ >>> fp = np.memmap(filename, dtype='float32', mode='w+', shape=(3,4))
139
+ >>> fp
140
+ memmap([[0., 0., 0., 0.],
141
+ [0., 0., 0., 0.],
142
+ [0., 0., 0., 0.]], dtype=float32)
143
+
144
+ Write data to memmap array:
145
+
146
+ >>> fp[:] = data[:]
147
+ >>> fp
148
+ memmap([[ 0., 1., 2., 3.],
149
+ [ 4., 5., 6., 7.],
150
+ [ 8., 9., 10., 11.]], dtype=float32)
151
+
152
+ >>> fp.filename == path.abspath(filename)
153
+ True
154
+
155
+ Flushes memory changes to disk in order to read them back
156
+
157
+ >>> fp.flush()
158
+
159
+ Load the memmap and verify data was stored:
160
+
161
+ >>> newfp = np.memmap(filename, dtype='float32', mode='r', shape=(3,4))
162
+ >>> newfp
163
+ memmap([[ 0., 1., 2., 3.],
164
+ [ 4., 5., 6., 7.],
165
+ [ 8., 9., 10., 11.]], dtype=float32)
166
+
167
+ Read-only memmap:
168
+
169
+ >>> fpr = np.memmap(filename, dtype='float32', mode='r', shape=(3,4))
170
+ >>> fpr.flags.writeable
171
+ False
172
+
173
+ Copy-on-write memmap:
174
+
175
+ >>> fpc = np.memmap(filename, dtype='float32', mode='c', shape=(3,4))
176
+ >>> fpc.flags.writeable
177
+ True
178
+
179
+ It's possible to assign to copy-on-write array, but values are only
180
+ written into the memory copy of the array, and not written to disk:
181
+
182
+ >>> fpc
183
+ memmap([[ 0., 1., 2., 3.],
184
+ [ 4., 5., 6., 7.],
185
+ [ 8., 9., 10., 11.]], dtype=float32)
186
+ >>> fpc[0,:] = 0
187
+ >>> fpc
188
+ memmap([[ 0., 0., 0., 0.],
189
+ [ 4., 5., 6., 7.],
190
+ [ 8., 9., 10., 11.]], dtype=float32)
191
+
192
+ File on disk is unchanged:
193
+
194
+ >>> fpr
195
+ memmap([[ 0., 1., 2., 3.],
196
+ [ 4., 5., 6., 7.],
197
+ [ 8., 9., 10., 11.]], dtype=float32)
198
+
199
+ Offset into a memmap:
200
+
201
+ >>> fpo = np.memmap(filename, dtype='float32', mode='r', offset=16)
202
+ >>> fpo
203
+ memmap([ 4., 5., 6., 7., 8., 9., 10., 11.], dtype=float32)
204
+
205
+ """
206
+
207
+ __array_priority__ = -100.0
208
+
209
+ def __new__(subtype, filename, dtype=uint8, mode='r+', offset=0,
210
+ shape=None, order='C'):
211
+ # Import here to minimize 'import numpy' overhead
212
+ import mmap
213
+ import os.path
214
+ try:
215
+ mode = mode_equivalents[mode]
216
+ except KeyError as e:
217
+ if mode not in valid_filemodes:
218
+ raise ValueError(
219
+ "mode must be one of {!r} (got {!r})"
220
+ .format(valid_filemodes + list(mode_equivalents.keys()), mode)
221
+ ) from None
222
+
223
+ if mode == 'w+' and shape is None:
224
+ raise ValueError("shape must be given if mode == 'w+'")
225
+
226
+ if hasattr(filename, 'read'):
227
+ f_ctx = nullcontext(filename)
228
+ else:
229
+ f_ctx = open(os_fspath(filename), ('r' if mode == 'c' else mode)+'b')
230
+
231
+ with f_ctx as fid:
232
+ fid.seek(0, 2)
233
+ flen = fid.tell()
234
+ descr = dtypedescr(dtype)
235
+ _dbytes = descr.itemsize
236
+
237
+ if shape is None:
238
+ bytes = flen - offset
239
+ if bytes % _dbytes:
240
+ raise ValueError("Size of available data is not a "
241
+ "multiple of the data-type size.")
242
+ size = bytes // _dbytes
243
+ shape = (size,)
244
+ else:
245
+ if not isinstance(shape, tuple):
246
+ shape = (shape,)
247
+ size = np.intp(1) # avoid default choice of np.int_, which might overflow
248
+ for k in shape:
249
+ size *= k
250
+
251
+ bytes = int(offset + size*_dbytes)
252
+
253
+ if mode in ('w+', 'r+') and flen < bytes:
254
+ fid.seek(bytes - 1, 0)
255
+ fid.write(b'\0')
256
+ fid.flush()
257
+
258
+ if mode == 'c':
259
+ acc = mmap.ACCESS_COPY
260
+ elif mode == 'r':
261
+ acc = mmap.ACCESS_READ
262
+ else:
263
+ acc = mmap.ACCESS_WRITE
264
+
265
+ start = offset - offset % mmap.ALLOCATIONGRANULARITY
266
+ bytes -= start
267
+ array_offset = offset - start
268
+ mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start)
269
+
270
+ self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
271
+ offset=array_offset, order=order)
272
+ self._mmap = mm
273
+ self.offset = offset
274
+ self.mode = mode
275
+
276
+ if is_pathlib_path(filename):
277
+ # special case - if we were constructed with a pathlib.path,
278
+ # then filename is a path object, not a string
279
+ self.filename = filename.resolve()
280
+ elif hasattr(fid, "name") and isinstance(fid.name, str):
281
+ # py3 returns int for TemporaryFile().name
282
+ self.filename = os.path.abspath(fid.name)
283
+ # same as memmap copies (e.g. memmap + 1)
284
+ else:
285
+ self.filename = None
286
+
287
+ return self
288
+
289
+ def __array_finalize__(self, obj):
290
+ if hasattr(obj, '_mmap') and np.may_share_memory(self, obj):
291
+ self._mmap = obj._mmap
292
+ self.filename = obj.filename
293
+ self.offset = obj.offset
294
+ self.mode = obj.mode
295
+ else:
296
+ self._mmap = None
297
+ self.filename = None
298
+ self.offset = None
299
+ self.mode = None
300
+
301
+ def flush(self):
302
+ """
303
+ Write any changes in the array to the file on disk.
304
+
305
+ For further information, see `memmap`.
306
+
307
+ Parameters
308
+ ----------
309
+ None
310
+
311
+ See Also
312
+ --------
313
+ memmap
314
+
315
+ """
316
+ if self.base is not None and hasattr(self.base, 'flush'):
317
+ self.base.flush()
318
+
319
+ def __array_wrap__(self, arr, context=None):
320
+ arr = super().__array_wrap__(arr, context)
321
+
322
+ # Return a memmap if a memmap was given as the output of the
323
+ # ufunc. Leave the arr class unchanged if self is not a memmap
324
+ # to keep original memmap subclasses behavior
325
+ if self is arr or type(self) is not memmap:
326
+ return arr
327
+ # Return scalar instead of 0d memmap, e.g. for np.sum with
328
+ # axis=None
329
+ if arr.shape == ():
330
+ return arr[()]
331
+ # Return ndarray otherwise
332
+ return arr.view(np.ndarray)
333
+
334
+ def __getitem__(self, index):
335
+ res = super().__getitem__(index)
336
+ if type(res) is memmap and res._mmap is None:
337
+ return res.view(type=ndarray)
338
+ return res
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/records.py ADDED
@@ -0,0 +1,1099 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Record Arrays
3
+ =============
4
+ Record arrays expose the fields of structured arrays as properties.
5
+
6
+ Most commonly, ndarrays contain elements of a single type, e.g. floats,
7
+ integers, bools etc. However, it is possible for elements to be combinations
8
+ of these using structured types, such as::
9
+
10
+ >>> a = np.array([(1, 2.0), (1, 2.0)], dtype=[('x', np.int64), ('y', np.float64)])
11
+ >>> a
12
+ array([(1, 2.), (1, 2.)], dtype=[('x', '<i8'), ('y', '<f8')])
13
+
14
+ Here, each element consists of two fields: x (and int), and y (a float).
15
+ This is known as a structured array. The different fields are analogous
16
+ to columns in a spread-sheet. The different fields can be accessed as
17
+ one would a dictionary::
18
+
19
+ >>> a['x']
20
+ array([1, 1])
21
+
22
+ >>> a['y']
23
+ array([2., 2.])
24
+
25
+ Record arrays allow us to access fields as properties::
26
+
27
+ >>> ar = np.rec.array(a)
28
+
29
+ >>> ar.x
30
+ array([1, 1])
31
+
32
+ >>> ar.y
33
+ array([2., 2.])
34
+
35
+ """
36
+ import warnings
37
+ from collections import Counter
38
+ from contextlib import nullcontext
39
+
40
+ from .._utils import set_module
41
+ from . import numeric as sb
42
+ from . import numerictypes as nt
43
+ from numpy.compat import os_fspath
44
+ from .arrayprint import _get_legacy_print_mode
45
+
46
+ # All of the functions allow formats to be a dtype
47
+ __all__ = [
48
+ 'record', 'recarray', 'format_parser',
49
+ 'fromarrays', 'fromrecords', 'fromstring', 'fromfile', 'array',
50
+ ]
51
+
52
+
53
+ ndarray = sb.ndarray
54
+
55
+ _byteorderconv = {'b':'>',
56
+ 'l':'<',
57
+ 'n':'=',
58
+ 'B':'>',
59
+ 'L':'<',
60
+ 'N':'=',
61
+ 'S':'s',
62
+ 's':'s',
63
+ '>':'>',
64
+ '<':'<',
65
+ '=':'=',
66
+ '|':'|',
67
+ 'I':'|',
68
+ 'i':'|'}
69
+
70
+ # formats regular expression
71
+ # allows multidimensional spec with a tuple syntax in front
72
+ # of the letter code '(2,3)f4' and ' ( 2 , 3 ) f4 '
73
+ # are equally allowed
74
+
75
+ numfmt = nt.sctypeDict
76
+
77
+
78
+ def find_duplicate(list):
79
+ """Find duplication in a list, return a list of duplicated elements"""
80
+ return [
81
+ item
82
+ for item, counts in Counter(list).items()
83
+ if counts > 1
84
+ ]
85
+
86
+
87
+ @set_module('numpy')
88
+ class format_parser:
89
+ """
90
+ Class to convert formats, names, titles description to a dtype.
91
+
92
+ After constructing the format_parser object, the dtype attribute is
93
+ the converted data-type:
94
+ ``dtype = format_parser(formats, names, titles).dtype``
95
+
96
+ Attributes
97
+ ----------
98
+ dtype : dtype
99
+ The converted data-type.
100
+
101
+ Parameters
102
+ ----------
103
+ formats : str or list of str
104
+ The format description, either specified as a string with
105
+ comma-separated format descriptions in the form ``'f8, i4, a5'``, or
106
+ a list of format description strings in the form
107
+ ``['f8', 'i4', 'a5']``.
108
+ names : str or list/tuple of str
109
+ The field names, either specified as a comma-separated string in the
110
+ form ``'col1, col2, col3'``, or as a list or tuple of strings in the
111
+ form ``['col1', 'col2', 'col3']``.
112
+ An empty list can be used, in that case default field names
113
+ ('f0', 'f1', ...) are used.
114
+ titles : sequence
115
+ Sequence of title strings. An empty list can be used to leave titles
116
+ out.
117
+ aligned : bool, optional
118
+ If True, align the fields by padding as the C-compiler would.
119
+ Default is False.
120
+ byteorder : str, optional
121
+ If specified, all the fields will be changed to the
122
+ provided byte-order. Otherwise, the default byte-order is
123
+ used. For all available string specifiers, see `dtype.newbyteorder`.
124
+
125
+ See Also
126
+ --------
127
+ dtype, typename, sctype2char
128
+
129
+ Examples
130
+ --------
131
+ >>> np.format_parser(['<f8', '<i4', '<a5'], ['col1', 'col2', 'col3'],
132
+ ... ['T1', 'T2', 'T3']).dtype
133
+ dtype([(('T1', 'col1'), '<f8'), (('T2', 'col2'), '<i4'), (('T3', 'col3'), 'S5')])
134
+
135
+ `names` and/or `titles` can be empty lists. If `titles` is an empty list,
136
+ titles will simply not appear. If `names` is empty, default field names
137
+ will be used.
138
+
139
+ >>> np.format_parser(['f8', 'i4', 'a5'], ['col1', 'col2', 'col3'],
140
+ ... []).dtype
141
+ dtype([('col1', '<f8'), ('col2', '<i4'), ('col3', '<S5')])
142
+ >>> np.format_parser(['<f8', '<i4', '<a5'], [], []).dtype
143
+ dtype([('f0', '<f8'), ('f1', '<i4'), ('f2', 'S5')])
144
+
145
+ """
146
+
147
+ def __init__(self, formats, names, titles, aligned=False, byteorder=None):
148
+ self._parseFormats(formats, aligned)
149
+ self._setfieldnames(names, titles)
150
+ self._createdtype(byteorder)
151
+
152
+ def _parseFormats(self, formats, aligned=False):
153
+ """ Parse the field formats """
154
+
155
+ if formats is None:
156
+ raise ValueError("Need formats argument")
157
+ if isinstance(formats, list):
158
+ dtype = sb.dtype(
159
+ [('f{}'.format(i), format_) for i, format_ in enumerate(formats)],
160
+ aligned,
161
+ )
162
+ else:
163
+ dtype = sb.dtype(formats, aligned)
164
+ fields = dtype.fields
165
+ if fields is None:
166
+ dtype = sb.dtype([('f1', dtype)], aligned)
167
+ fields = dtype.fields
168
+ keys = dtype.names
169
+ self._f_formats = [fields[key][0] for key in keys]
170
+ self._offsets = [fields[key][1] for key in keys]
171
+ self._nfields = len(keys)
172
+
173
+ def _setfieldnames(self, names, titles):
174
+ """convert input field names into a list and assign to the _names
175
+ attribute """
176
+
177
+ if names:
178
+ if type(names) in [list, tuple]:
179
+ pass
180
+ elif isinstance(names, str):
181
+ names = names.split(',')
182
+ else:
183
+ raise NameError("illegal input names %s" % repr(names))
184
+
185
+ self._names = [n.strip() for n in names[:self._nfields]]
186
+ else:
187
+ self._names = []
188
+
189
+ # if the names are not specified, they will be assigned as
190
+ # "f0, f1, f2,..."
191
+ # if not enough names are specified, they will be assigned as "f[n],
192
+ # f[n+1],..." etc. where n is the number of specified names..."
193
+ self._names += ['f%d' % i for i in range(len(self._names),
194
+ self._nfields)]
195
+ # check for redundant names
196
+ _dup = find_duplicate(self._names)
197
+ if _dup:
198
+ raise ValueError("Duplicate field names: %s" % _dup)
199
+
200
+ if titles:
201
+ self._titles = [n.strip() for n in titles[:self._nfields]]
202
+ else:
203
+ self._titles = []
204
+ titles = []
205
+
206
+ if self._nfields > len(titles):
207
+ self._titles += [None] * (self._nfields - len(titles))
208
+
209
+ def _createdtype(self, byteorder):
210
+ dtype = sb.dtype({
211
+ 'names': self._names,
212
+ 'formats': self._f_formats,
213
+ 'offsets': self._offsets,
214
+ 'titles': self._titles,
215
+ })
216
+ if byteorder is not None:
217
+ byteorder = _byteorderconv[byteorder[0]]
218
+ dtype = dtype.newbyteorder(byteorder)
219
+
220
+ self.dtype = dtype
221
+
222
+
223
+ class record(nt.void):
224
+ """A data-type scalar that allows field access as attribute lookup.
225
+ """
226
+
227
+ # manually set name and module so that this class's type shows up
228
+ # as numpy.record when printed
229
+ __name__ = 'record'
230
+ __module__ = 'numpy'
231
+
232
+ def __repr__(self):
233
+ if _get_legacy_print_mode() <= 113:
234
+ return self.__str__()
235
+ return super().__repr__()
236
+
237
+ def __str__(self):
238
+ if _get_legacy_print_mode() <= 113:
239
+ return str(self.item())
240
+ return super().__str__()
241
+
242
+ def __getattribute__(self, attr):
243
+ if attr in ('setfield', 'getfield', 'dtype'):
244
+ return nt.void.__getattribute__(self, attr)
245
+ try:
246
+ return nt.void.__getattribute__(self, attr)
247
+ except AttributeError:
248
+ pass
249
+ fielddict = nt.void.__getattribute__(self, 'dtype').fields
250
+ res = fielddict.get(attr, None)
251
+ if res:
252
+ obj = self.getfield(*res[:2])
253
+ # if it has fields return a record,
254
+ # otherwise return the object
255
+ try:
256
+ dt = obj.dtype
257
+ except AttributeError:
258
+ #happens if field is Object type
259
+ return obj
260
+ if dt.names is not None:
261
+ return obj.view((self.__class__, obj.dtype))
262
+ return obj
263
+ else:
264
+ raise AttributeError("'record' object has no "
265
+ "attribute '%s'" % attr)
266
+
267
+ def __setattr__(self, attr, val):
268
+ if attr in ('setfield', 'getfield', 'dtype'):
269
+ raise AttributeError("Cannot set '%s' attribute" % attr)
270
+ fielddict = nt.void.__getattribute__(self, 'dtype').fields
271
+ res = fielddict.get(attr, None)
272
+ if res:
273
+ return self.setfield(val, *res[:2])
274
+ else:
275
+ if getattr(self, attr, None):
276
+ return nt.void.__setattr__(self, attr, val)
277
+ else:
278
+ raise AttributeError("'record' object has no "
279
+ "attribute '%s'" % attr)
280
+
281
+ def __getitem__(self, indx):
282
+ obj = nt.void.__getitem__(self, indx)
283
+
284
+ # copy behavior of record.__getattribute__,
285
+ if isinstance(obj, nt.void) and obj.dtype.names is not None:
286
+ return obj.view((self.__class__, obj.dtype))
287
+ else:
288
+ # return a single element
289
+ return obj
290
+
291
+ def pprint(self):
292
+ """Pretty-print all fields."""
293
+ # pretty-print all fields
294
+ names = self.dtype.names
295
+ maxlen = max(len(name) for name in names)
296
+ fmt = '%% %ds: %%s' % maxlen
297
+ rows = [fmt % (name, getattr(self, name)) for name in names]
298
+ return "\n".join(rows)
299
+
300
+ # The recarray is almost identical to a standard array (which supports
301
+ # named fields already) The biggest difference is that it can use
302
+ # attribute-lookup to find the fields and it is constructed using
303
+ # a record.
304
+
305
+ # If byteorder is given it forces a particular byteorder on all
306
+ # the fields (and any subfields)
307
+
308
+ class recarray(ndarray):
309
+ """Construct an ndarray that allows field access using attributes.
310
+
311
+ Arrays may have a data-types containing fields, analogous
312
+ to columns in a spread sheet. An example is ``[(x, int), (y, float)]``,
313
+ where each entry in the array is a pair of ``(int, float)``. Normally,
314
+ these attributes are accessed using dictionary lookups such as ``arr['x']``
315
+ and ``arr['y']``. Record arrays allow the fields to be accessed as members
316
+ of the array, using ``arr.x`` and ``arr.y``.
317
+
318
+ Parameters
319
+ ----------
320
+ shape : tuple
321
+ Shape of output array.
322
+ dtype : data-type, optional
323
+ The desired data-type. By default, the data-type is determined
324
+ from `formats`, `names`, `titles`, `aligned` and `byteorder`.
325
+ formats : list of data-types, optional
326
+ A list containing the data-types for the different columns, e.g.
327
+ ``['i4', 'f8', 'i4']``. `formats` does *not* support the new
328
+ convention of using types directly, i.e. ``(int, float, int)``.
329
+ Note that `formats` must be a list, not a tuple.
330
+ Given that `formats` is somewhat limited, we recommend specifying
331
+ `dtype` instead.
332
+ names : tuple of str, optional
333
+ The name of each column, e.g. ``('x', 'y', 'z')``.
334
+ buf : buffer, optional
335
+ By default, a new array is created of the given shape and data-type.
336
+ If `buf` is specified and is an object exposing the buffer interface,
337
+ the array will use the memory from the existing buffer. In this case,
338
+ the `offset` and `strides` keywords are available.
339
+
340
+ Other Parameters
341
+ ----------------
342
+ titles : tuple of str, optional
343
+ Aliases for column names. For example, if `names` were
344
+ ``('x', 'y', 'z')`` and `titles` is
345
+ ``('x_coordinate', 'y_coordinate', 'z_coordinate')``, then
346
+ ``arr['x']`` is equivalent to both ``arr.x`` and ``arr.x_coordinate``.
347
+ byteorder : {'<', '>', '='}, optional
348
+ Byte-order for all fields.
349
+ aligned : bool, optional
350
+ Align the fields in memory as the C-compiler would.
351
+ strides : tuple of ints, optional
352
+ Buffer (`buf`) is interpreted according to these strides (strides
353
+ define how many bytes each array element, row, column, etc.
354
+ occupy in memory).
355
+ offset : int, optional
356
+ Start reading buffer (`buf`) from this offset onwards.
357
+ order : {'C', 'F'}, optional
358
+ Row-major (C-style) or column-major (Fortran-style) order.
359
+
360
+ Returns
361
+ -------
362
+ rec : recarray
363
+ Empty array of the given shape and type.
364
+
365
+ See Also
366
+ --------
367
+ core.records.fromrecords : Construct a record array from data.
368
+ record : fundamental data-type for `recarray`.
369
+ format_parser : determine a data-type from formats, names, titles.
370
+
371
+ Notes
372
+ -----
373
+ This constructor can be compared to ``empty``: it creates a new record
374
+ array but does not fill it with data. To create a record array from data,
375
+ use one of the following methods:
376
+
377
+ 1. Create a standard ndarray and convert it to a record array,
378
+ using ``arr.view(np.recarray)``
379
+ 2. Use the `buf` keyword.
380
+ 3. Use `np.rec.fromrecords`.
381
+
382
+ Examples
383
+ --------
384
+ Create an array with two fields, ``x`` and ``y``:
385
+
386
+ >>> x = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', '<f8'), ('y', '<i8')])
387
+ >>> x
388
+ array([(1., 2), (3., 4)], dtype=[('x', '<f8'), ('y', '<i8')])
389
+
390
+ >>> x['x']
391
+ array([1., 3.])
392
+
393
+ View the array as a record array:
394
+
395
+ >>> x = x.view(np.recarray)
396
+
397
+ >>> x.x
398
+ array([1., 3.])
399
+
400
+ >>> x.y
401
+ array([2, 4])
402
+
403
+ Create a new, empty record array:
404
+
405
+ >>> np.recarray((2,),
406
+ ... dtype=[('x', int), ('y', float), ('z', int)]) #doctest: +SKIP
407
+ rec.array([(-1073741821, 1.2249118382103472e-301, 24547520),
408
+ (3471280, 1.2134086255804012e-316, 0)],
409
+ dtype=[('x', '<i4'), ('y', '<f8'), ('z', '<i4')])
410
+
411
+ """
412
+
413
+ # manually set name and module so that this class's type shows
414
+ # up as "numpy.recarray" when printed
415
+ __name__ = 'recarray'
416
+ __module__ = 'numpy'
417
+
418
+ def __new__(subtype, shape, dtype=None, buf=None, offset=0, strides=None,
419
+ formats=None, names=None, titles=None,
420
+ byteorder=None, aligned=False, order='C'):
421
+
422
+ if dtype is not None:
423
+ descr = sb.dtype(dtype)
424
+ else:
425
+ descr = format_parser(formats, names, titles, aligned, byteorder).dtype
426
+
427
+ if buf is None:
428
+ self = ndarray.__new__(subtype, shape, (record, descr), order=order)
429
+ else:
430
+ self = ndarray.__new__(subtype, shape, (record, descr),
431
+ buffer=buf, offset=offset,
432
+ strides=strides, order=order)
433
+ return self
434
+
435
+ def __array_finalize__(self, obj):
436
+ if self.dtype.type is not record and self.dtype.names is not None:
437
+ # if self.dtype is not np.record, invoke __setattr__ which will
438
+ # convert it to a record if it is a void dtype.
439
+ self.dtype = self.dtype
440
+
441
+ def __getattribute__(self, attr):
442
+ # See if ndarray has this attr, and return it if so. (note that this
443
+ # means a field with the same name as an ndarray attr cannot be
444
+ # accessed by attribute).
445
+ try:
446
+ return object.__getattribute__(self, attr)
447
+ except AttributeError: # attr must be a fieldname
448
+ pass
449
+
450
+ # look for a field with this name
451
+ fielddict = ndarray.__getattribute__(self, 'dtype').fields
452
+ try:
453
+ res = fielddict[attr][:2]
454
+ except (TypeError, KeyError) as e:
455
+ raise AttributeError("recarray has no attribute %s" % attr) from e
456
+ obj = self.getfield(*res)
457
+
458
+ # At this point obj will always be a recarray, since (see
459
+ # PyArray_GetField) the type of obj is inherited. Next, if obj.dtype is
460
+ # non-structured, convert it to an ndarray. Then if obj is structured
461
+ # with void type convert it to the same dtype.type (eg to preserve
462
+ # numpy.record type if present), since nested structured fields do not
463
+ # inherit type. Don't do this for non-void structures though.
464
+ if obj.dtype.names is not None:
465
+ if issubclass(obj.dtype.type, nt.void):
466
+ return obj.view(dtype=(self.dtype.type, obj.dtype))
467
+ return obj
468
+ else:
469
+ return obj.view(ndarray)
470
+
471
+ # Save the dictionary.
472
+ # If the attr is a field name and not in the saved dictionary
473
+ # Undo any "setting" of the attribute and do a setfield
474
+ # Thus, you can't create attributes on-the-fly that are field names.
475
+ def __setattr__(self, attr, val):
476
+
477
+ # Automatically convert (void) structured types to records
478
+ # (but not non-void structures, subarrays, or non-structured voids)
479
+ if attr == 'dtype' and issubclass(val.type, nt.void) and val.names is not None:
480
+ val = sb.dtype((record, val))
481
+
482
+ newattr = attr not in self.__dict__
483
+ try:
484
+ ret = object.__setattr__(self, attr, val)
485
+ except Exception:
486
+ fielddict = ndarray.__getattribute__(self, 'dtype').fields or {}
487
+ if attr not in fielddict:
488
+ raise
489
+ else:
490
+ fielddict = ndarray.__getattribute__(self, 'dtype').fields or {}
491
+ if attr not in fielddict:
492
+ return ret
493
+ if newattr:
494
+ # We just added this one or this setattr worked on an
495
+ # internal attribute.
496
+ try:
497
+ object.__delattr__(self, attr)
498
+ except Exception:
499
+ return ret
500
+ try:
501
+ res = fielddict[attr][:2]
502
+ except (TypeError, KeyError) as e:
503
+ raise AttributeError(
504
+ "record array has no attribute %s" % attr
505
+ ) from e
506
+ return self.setfield(val, *res)
507
+
508
+ def __getitem__(self, indx):
509
+ obj = super().__getitem__(indx)
510
+
511
+ # copy behavior of getattr, except that here
512
+ # we might also be returning a single element
513
+ if isinstance(obj, ndarray):
514
+ if obj.dtype.names is not None:
515
+ obj = obj.view(type(self))
516
+ if issubclass(obj.dtype.type, nt.void):
517
+ return obj.view(dtype=(self.dtype.type, obj.dtype))
518
+ return obj
519
+ else:
520
+ return obj.view(type=ndarray)
521
+ else:
522
+ # return a single element
523
+ return obj
524
+
525
+ def __repr__(self):
526
+
527
+ repr_dtype = self.dtype
528
+ if self.dtype.type is record or not issubclass(self.dtype.type, nt.void):
529
+ # If this is a full record array (has numpy.record dtype),
530
+ # or if it has a scalar (non-void) dtype with no records,
531
+ # represent it using the rec.array function. Since rec.array
532
+ # converts dtype to a numpy.record for us, convert back
533
+ # to non-record before printing
534
+ if repr_dtype.type is record:
535
+ repr_dtype = sb.dtype((nt.void, repr_dtype))
536
+ prefix = "rec.array("
537
+ fmt = 'rec.array(%s,%sdtype=%s)'
538
+ else:
539
+ # otherwise represent it using np.array plus a view
540
+ # This should only happen if the user is playing
541
+ # strange games with dtypes.
542
+ prefix = "array("
543
+ fmt = 'array(%s,%sdtype=%s).view(numpy.recarray)'
544
+
545
+ # get data/shape string. logic taken from numeric.array_repr
546
+ if self.size > 0 or self.shape == (0,):
547
+ lst = sb.array2string(
548
+ self, separator=', ', prefix=prefix, suffix=',')
549
+ else:
550
+ # show zero-length shape unless it is (0,)
551
+ lst = "[], shape=%s" % (repr(self.shape),)
552
+
553
+ lf = '\n'+' '*len(prefix)
554
+ if _get_legacy_print_mode() <= 113:
555
+ lf = ' ' + lf # trailing space
556
+ return fmt % (lst, lf, repr_dtype)
557
+
558
+ def field(self, attr, val=None):
559
+ if isinstance(attr, int):
560
+ names = ndarray.__getattribute__(self, 'dtype').names
561
+ attr = names[attr]
562
+
563
+ fielddict = ndarray.__getattribute__(self, 'dtype').fields
564
+
565
+ res = fielddict[attr][:2]
566
+
567
+ if val is None:
568
+ obj = self.getfield(*res)
569
+ if obj.dtype.names is not None:
570
+ return obj
571
+ return obj.view(ndarray)
572
+ else:
573
+ return self.setfield(val, *res)
574
+
575
+
576
+ def _deprecate_shape_0_as_None(shape):
577
+ if shape == 0:
578
+ warnings.warn(
579
+ "Passing `shape=0` to have the shape be inferred is deprecated, "
580
+ "and in future will be equivalent to `shape=(0,)`. To infer "
581
+ "the shape and suppress this warning, pass `shape=None` instead.",
582
+ FutureWarning, stacklevel=3)
583
+ return None
584
+ else:
585
+ return shape
586
+
587
+
588
+ @set_module("numpy.rec")
589
+ def fromarrays(arrayList, dtype=None, shape=None, formats=None,
590
+ names=None, titles=None, aligned=False, byteorder=None):
591
+ """Create a record array from a (flat) list of arrays
592
+
593
+ Parameters
594
+ ----------
595
+ arrayList : list or tuple
596
+ List of array-like objects (such as lists, tuples,
597
+ and ndarrays).
598
+ dtype : data-type, optional
599
+ valid dtype for all arrays
600
+ shape : int or tuple of ints, optional
601
+ Shape of the resulting array. If not provided, inferred from
602
+ ``arrayList[0]``.
603
+ formats, names, titles, aligned, byteorder :
604
+ If `dtype` is ``None``, these arguments are passed to
605
+ `numpy.format_parser` to construct a dtype. See that function for
606
+ detailed documentation.
607
+
608
+ Returns
609
+ -------
610
+ np.recarray
611
+ Record array consisting of given arrayList columns.
612
+
613
+ Examples
614
+ --------
615
+ >>> x1=np.array([1,2,3,4])
616
+ >>> x2=np.array(['a','dd','xyz','12'])
617
+ >>> x3=np.array([1.1,2,3,4])
618
+ >>> r = np.core.records.fromarrays([x1,x2,x3],names='a,b,c')
619
+ >>> print(r[1])
620
+ (2, 'dd', 2.0) # may vary
621
+ >>> x1[1]=34
622
+ >>> r.a
623
+ array([1, 2, 3, 4])
624
+
625
+ >>> x1 = np.array([1, 2, 3, 4])
626
+ >>> x2 = np.array(['a', 'dd', 'xyz', '12'])
627
+ >>> x3 = np.array([1.1, 2, 3,4])
628
+ >>> r = np.core.records.fromarrays(
629
+ ... [x1, x2, x3],
630
+ ... dtype=np.dtype([('a', np.int32), ('b', 'S3'), ('c', np.float32)]))
631
+ >>> r
632
+ rec.array([(1, b'a', 1.1), (2, b'dd', 2. ), (3, b'xyz', 3. ),
633
+ (4, b'12', 4. )],
634
+ dtype=[('a', '<i4'), ('b', 'S3'), ('c', '<f4')])
635
+ """
636
+
637
+ arrayList = [sb.asarray(x) for x in arrayList]
638
+
639
+ # NumPy 1.19.0, 2020-01-01
640
+ shape = _deprecate_shape_0_as_None(shape)
641
+
642
+ if shape is None:
643
+ shape = arrayList[0].shape
644
+ elif isinstance(shape, int):
645
+ shape = (shape,)
646
+
647
+ if formats is None and dtype is None:
648
+ # go through each object in the list to see if it is an ndarray
649
+ # and determine the formats.
650
+ formats = [obj.dtype for obj in arrayList]
651
+
652
+ if dtype is not None:
653
+ descr = sb.dtype(dtype)
654
+ else:
655
+ descr = format_parser(formats, names, titles, aligned, byteorder).dtype
656
+ _names = descr.names
657
+
658
+ # Determine shape from data-type.
659
+ if len(descr) != len(arrayList):
660
+ raise ValueError("mismatch between the number of fields "
661
+ "and the number of arrays")
662
+
663
+ d0 = descr[0].shape
664
+ nn = len(d0)
665
+ if nn > 0:
666
+ shape = shape[:-nn]
667
+
668
+ _array = recarray(shape, descr)
669
+
670
+ # populate the record array (makes a copy)
671
+ for k, obj in enumerate(arrayList):
672
+ nn = descr[k].ndim
673
+ testshape = obj.shape[:obj.ndim - nn]
674
+ name = _names[k]
675
+ if testshape != shape:
676
+ raise ValueError(f'array-shape mismatch in array {k} ("{name}")')
677
+
678
+ _array[name] = obj
679
+
680
+ return _array
681
+
682
+
683
+ @set_module("numpy.rec")
684
+ def fromrecords(recList, dtype=None, shape=None, formats=None, names=None,
685
+ titles=None, aligned=False, byteorder=None):
686
+ """Create a recarray from a list of records in text form.
687
+
688
+ Parameters
689
+ ----------
690
+ recList : sequence
691
+ data in the same field may be heterogeneous - they will be promoted
692
+ to the highest data type.
693
+ dtype : data-type, optional
694
+ valid dtype for all arrays
695
+ shape : int or tuple of ints, optional
696
+ shape of each array.
697
+ formats, names, titles, aligned, byteorder :
698
+ If `dtype` is ``None``, these arguments are passed to
699
+ `numpy.format_parser` to construct a dtype. See that function for
700
+ detailed documentation.
701
+
702
+ If both `formats` and `dtype` are None, then this will auto-detect
703
+ formats. Use list of tuples rather than list of lists for faster
704
+ processing.
705
+
706
+ Returns
707
+ -------
708
+ np.recarray
709
+ record array consisting of given recList rows.
710
+
711
+ Examples
712
+ --------
713
+ >>> r=np.core.records.fromrecords([(456,'dbe',1.2),(2,'de',1.3)],
714
+ ... names='col1,col2,col3')
715
+ >>> print(r[0])
716
+ (456, 'dbe', 1.2)
717
+ >>> r.col1
718
+ array([456, 2])
719
+ >>> r.col2
720
+ array(['dbe', 'de'], dtype='<U3')
721
+ >>> import pickle
722
+ >>> pickle.loads(pickle.dumps(r))
723
+ rec.array([(456, 'dbe', 1.2), ( 2, 'de', 1.3)],
724
+ dtype=[('col1', '<i8'), ('col2', '<U3'), ('col3', '<f8')])
725
+ """
726
+
727
+ if formats is None and dtype is None: # slower
728
+ obj = sb.array(recList, dtype=object)
729
+ arrlist = [sb.array(obj[..., i].tolist()) for i in range(obj.shape[-1])]
730
+ return fromarrays(arrlist, formats=formats, shape=shape, names=names,
731
+ titles=titles, aligned=aligned, byteorder=byteorder)
732
+
733
+ if dtype is not None:
734
+ descr = sb.dtype((record, dtype))
735
+ else:
736
+ descr = format_parser(formats, names, titles, aligned, byteorder).dtype
737
+
738
+ try:
739
+ retval = sb.array(recList, dtype=descr)
740
+ except (TypeError, ValueError):
741
+ # NumPy 1.19.0, 2020-01-01
742
+ shape = _deprecate_shape_0_as_None(shape)
743
+ if shape is None:
744
+ shape = len(recList)
745
+ if isinstance(shape, int):
746
+ shape = (shape,)
747
+ if len(shape) > 1:
748
+ raise ValueError("Can only deal with 1-d array.")
749
+ _array = recarray(shape, descr)
750
+ for k in range(_array.size):
751
+ _array[k] = tuple(recList[k])
752
+ # list of lists instead of list of tuples ?
753
+ # 2018-02-07, 1.14.1
754
+ warnings.warn(
755
+ "fromrecords expected a list of tuples, may have received a list "
756
+ "of lists instead. In the future that will raise an error",
757
+ FutureWarning, stacklevel=2)
758
+ return _array
759
+ else:
760
+ if shape is not None and retval.shape != shape:
761
+ retval.shape = shape
762
+
763
+ res = retval.view(recarray)
764
+
765
+ return res
766
+
767
+
768
+ @set_module("numpy.rec")
769
+ def fromstring(datastring, dtype=None, shape=None, offset=0, formats=None,
770
+ names=None, titles=None, aligned=False, byteorder=None):
771
+ r"""Create a record array from binary data
772
+
773
+ Note that despite the name of this function it does not accept `str`
774
+ instances.
775
+
776
+ Parameters
777
+ ----------
778
+ datastring : bytes-like
779
+ Buffer of binary data
780
+ dtype : data-type, optional
781
+ Valid dtype for all arrays
782
+ shape : int or tuple of ints, optional
783
+ Shape of each array.
784
+ offset : int, optional
785
+ Position in the buffer to start reading from.
786
+ formats, names, titles, aligned, byteorder :
787
+ If `dtype` is ``None``, these arguments are passed to
788
+ `numpy.format_parser` to construct a dtype. See that function for
789
+ detailed documentation.
790
+
791
+
792
+ Returns
793
+ -------
794
+ np.recarray
795
+ Record array view into the data in datastring. This will be readonly
796
+ if `datastring` is readonly.
797
+
798
+ See Also
799
+ --------
800
+ numpy.frombuffer
801
+
802
+ Examples
803
+ --------
804
+ >>> a = b'\x01\x02\x03abc'
805
+ >>> np.core.records.fromstring(a, dtype='u1,u1,u1,S3')
806
+ rec.array([(1, 2, 3, b'abc')],
807
+ dtype=[('f0', 'u1'), ('f1', 'u1'), ('f2', 'u1'), ('f3', 'S3')])
808
+
809
+ >>> grades_dtype = [('Name', (np.str_, 10)), ('Marks', np.float64),
810
+ ... ('GradeLevel', np.int32)]
811
+ >>> grades_array = np.array([('Sam', 33.3, 3), ('Mike', 44.4, 5),
812
+ ... ('Aadi', 66.6, 6)], dtype=grades_dtype)
813
+ >>> np.core.records.fromstring(grades_array.tobytes(), dtype=grades_dtype)
814
+ rec.array([('Sam', 33.3, 3), ('Mike', 44.4, 5), ('Aadi', 66.6, 6)],
815
+ dtype=[('Name', '<U10'), ('Marks', '<f8'), ('GradeLevel', '<i4')])
816
+
817
+ >>> s = '\x01\x02\x03abc'
818
+ >>> np.core.records.fromstring(s, dtype='u1,u1,u1,S3')
819
+ Traceback (most recent call last)
820
+ ...
821
+ TypeError: a bytes-like object is required, not 'str'
822
+ """
823
+
824
+ if dtype is None and formats is None:
825
+ raise TypeError("fromstring() needs a 'dtype' or 'formats' argument")
826
+
827
+ if dtype is not None:
828
+ descr = sb.dtype(dtype)
829
+ else:
830
+ descr = format_parser(formats, names, titles, aligned, byteorder).dtype
831
+
832
+ itemsize = descr.itemsize
833
+
834
+ # NumPy 1.19.0, 2020-01-01
835
+ shape = _deprecate_shape_0_as_None(shape)
836
+
837
+ if shape in (None, -1):
838
+ shape = (len(datastring) - offset) // itemsize
839
+
840
+ _array = recarray(shape, descr, buf=datastring, offset=offset)
841
+ return _array
842
+
843
+ def get_remaining_size(fd):
844
+ pos = fd.tell()
845
+ try:
846
+ fd.seek(0, 2)
847
+ return fd.tell() - pos
848
+ finally:
849
+ fd.seek(pos, 0)
850
+
851
+
852
+ @set_module("numpy.rec")
853
+ def fromfile(fd, dtype=None, shape=None, offset=0, formats=None,
854
+ names=None, titles=None, aligned=False, byteorder=None):
855
+ """Create an array from binary file data
856
+
857
+ Parameters
858
+ ----------
859
+ fd : str or file type
860
+ If file is a string or a path-like object then that file is opened,
861
+ else it is assumed to be a file object. The file object must
862
+ support random access (i.e. it must have tell and seek methods).
863
+ dtype : data-type, optional
864
+ valid dtype for all arrays
865
+ shape : int or tuple of ints, optional
866
+ shape of each array.
867
+ offset : int, optional
868
+ Position in the file to start reading from.
869
+ formats, names, titles, aligned, byteorder :
870
+ If `dtype` is ``None``, these arguments are passed to
871
+ `numpy.format_parser` to construct a dtype. See that function for
872
+ detailed documentation
873
+
874
+ Returns
875
+ -------
876
+ np.recarray
877
+ record array consisting of data enclosed in file.
878
+
879
+ Examples
880
+ --------
881
+ >>> from tempfile import TemporaryFile
882
+ >>> a = np.empty(10,dtype='f8,i4,a5')
883
+ >>> a[5] = (0.5,10,'abcde')
884
+ >>>
885
+ >>> fd=TemporaryFile()
886
+ >>> a = a.newbyteorder('<')
887
+ >>> a.tofile(fd)
888
+ >>>
889
+ >>> _ = fd.seek(0)
890
+ >>> r=np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10,
891
+ ... byteorder='<')
892
+ >>> print(r[5])
893
+ (0.5, 10, 'abcde')
894
+ >>> r.shape
895
+ (10,)
896
+ """
897
+
898
+ if dtype is None and formats is None:
899
+ raise TypeError("fromfile() needs a 'dtype' or 'formats' argument")
900
+
901
+ # NumPy 1.19.0, 2020-01-01
902
+ shape = _deprecate_shape_0_as_None(shape)
903
+
904
+ if shape is None:
905
+ shape = (-1,)
906
+ elif isinstance(shape, int):
907
+ shape = (shape,)
908
+
909
+ if hasattr(fd, 'readinto'):
910
+ # GH issue 2504. fd supports io.RawIOBase or io.BufferedIOBase interface.
911
+ # Example of fd: gzip, BytesIO, BufferedReader
912
+ # file already opened
913
+ ctx = nullcontext(fd)
914
+ else:
915
+ # open file
916
+ ctx = open(os_fspath(fd), 'rb')
917
+
918
+ with ctx as fd:
919
+ if offset > 0:
920
+ fd.seek(offset, 1)
921
+ size = get_remaining_size(fd)
922
+
923
+ if dtype is not None:
924
+ descr = sb.dtype(dtype)
925
+ else:
926
+ descr = format_parser(formats, names, titles, aligned, byteorder).dtype
927
+
928
+ itemsize = descr.itemsize
929
+
930
+ shapeprod = sb.array(shape).prod(dtype=nt.intp)
931
+ shapesize = shapeprod * itemsize
932
+ if shapesize < 0:
933
+ shape = list(shape)
934
+ shape[shape.index(-1)] = size // -shapesize
935
+ shape = tuple(shape)
936
+ shapeprod = sb.array(shape).prod(dtype=nt.intp)
937
+
938
+ nbytes = shapeprod * itemsize
939
+
940
+ if nbytes > size:
941
+ raise ValueError(
942
+ "Not enough bytes left in file for specified shape and type")
943
+
944
+ # create the array
945
+ _array = recarray(shape, descr)
946
+ nbytesread = fd.readinto(_array.data)
947
+ if nbytesread != nbytes:
948
+ raise OSError("Didn't read as many bytes as expected")
949
+
950
+ return _array
951
+
952
+
953
+ @set_module("numpy.rec")
954
+ def array(obj, dtype=None, shape=None, offset=0, strides=None, formats=None,
955
+ names=None, titles=None, aligned=False, byteorder=None, copy=True):
956
+ """
957
+ Construct a record array from a wide-variety of objects.
958
+
959
+ A general-purpose record array constructor that dispatches to the
960
+ appropriate `recarray` creation function based on the inputs (see Notes).
961
+
962
+ Parameters
963
+ ----------
964
+ obj : any
965
+ Input object. See Notes for details on how various input types are
966
+ treated.
967
+ dtype : data-type, optional
968
+ Valid dtype for array.
969
+ shape : int or tuple of ints, optional
970
+ Shape of each array.
971
+ offset : int, optional
972
+ Position in the file or buffer to start reading from.
973
+ strides : tuple of ints, optional
974
+ Buffer (`buf`) is interpreted according to these strides (strides
975
+ define how many bytes each array element, row, column, etc.
976
+ occupy in memory).
977
+ formats, names, titles, aligned, byteorder :
978
+ If `dtype` is ``None``, these arguments are passed to
979
+ `numpy.format_parser` to construct a dtype. See that function for
980
+ detailed documentation.
981
+ copy : bool, optional
982
+ Whether to copy the input object (True), or to use a reference instead.
983
+ This option only applies when the input is an ndarray or recarray.
984
+ Defaults to True.
985
+
986
+ Returns
987
+ -------
988
+ np.recarray
989
+ Record array created from the specified object.
990
+
991
+ Notes
992
+ -----
993
+ If `obj` is ``None``, then call the `~numpy.recarray` constructor. If
994
+ `obj` is a string, then call the `fromstring` constructor. If `obj` is a
995
+ list or a tuple, then if the first object is an `~numpy.ndarray`, call
996
+ `fromarrays`, otherwise call `fromrecords`. If `obj` is a
997
+ `~numpy.recarray`, then make a copy of the data in the recarray
998
+ (if ``copy=True``) and use the new formats, names, and titles. If `obj`
999
+ is a file, then call `fromfile`. Finally, if obj is an `ndarray`, then
1000
+ return ``obj.view(recarray)``, making a copy of the data if ``copy=True``.
1001
+
1002
+ Examples
1003
+ --------
1004
+ >>> a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
1005
+ array([[1, 2, 3],
1006
+ [4, 5, 6],
1007
+ [7, 8, 9]])
1008
+
1009
+ >>> np.core.records.array(a)
1010
+ rec.array([[1, 2, 3],
1011
+ [4, 5, 6],
1012
+ [7, 8, 9]],
1013
+ dtype=int32)
1014
+
1015
+ >>> b = [(1, 1), (2, 4), (3, 9)]
1016
+ >>> c = np.core.records.array(b, formats = ['i2', 'f2'], names = ('x', 'y'))
1017
+ >>> c
1018
+ rec.array([(1, 1.0), (2, 4.0), (3, 9.0)],
1019
+ dtype=[('x', '<i2'), ('y', '<f2')])
1020
+
1021
+ >>> c.x
1022
+ rec.array([1, 2, 3], dtype=int16)
1023
+
1024
+ >>> c.y
1025
+ rec.array([ 1.0, 4.0, 9.0], dtype=float16)
1026
+
1027
+ >>> r = np.rec.array(['abc','def'], names=['col1','col2'])
1028
+ >>> print(r.col1)
1029
+ abc
1030
+
1031
+ >>> r.col1
1032
+ array('abc', dtype='<U3')
1033
+
1034
+ >>> r.col2
1035
+ array('def', dtype='<U3')
1036
+ """
1037
+
1038
+ if ((isinstance(obj, (type(None), str)) or hasattr(obj, 'readinto')) and
1039
+ formats is None and dtype is None):
1040
+ raise ValueError("Must define formats (or dtype) if object is "
1041
+ "None, string, or an open file")
1042
+
1043
+ kwds = {}
1044
+ if dtype is not None:
1045
+ dtype = sb.dtype(dtype)
1046
+ elif formats is not None:
1047
+ dtype = format_parser(formats, names, titles,
1048
+ aligned, byteorder).dtype
1049
+ else:
1050
+ kwds = {'formats': formats,
1051
+ 'names': names,
1052
+ 'titles': titles,
1053
+ 'aligned': aligned,
1054
+ 'byteorder': byteorder
1055
+ }
1056
+
1057
+ if obj is None:
1058
+ if shape is None:
1059
+ raise ValueError("Must define a shape if obj is None")
1060
+ return recarray(shape, dtype, buf=obj, offset=offset, strides=strides)
1061
+
1062
+ elif isinstance(obj, bytes):
1063
+ return fromstring(obj, dtype, shape=shape, offset=offset, **kwds)
1064
+
1065
+ elif isinstance(obj, (list, tuple)):
1066
+ if isinstance(obj[0], (tuple, list)):
1067
+ return fromrecords(obj, dtype=dtype, shape=shape, **kwds)
1068
+ else:
1069
+ return fromarrays(obj, dtype=dtype, shape=shape, **kwds)
1070
+
1071
+ elif isinstance(obj, recarray):
1072
+ if dtype is not None and (obj.dtype != dtype):
1073
+ new = obj.view(dtype)
1074
+ else:
1075
+ new = obj
1076
+ if copy:
1077
+ new = new.copy()
1078
+ return new
1079
+
1080
+ elif hasattr(obj, 'readinto'):
1081
+ return fromfile(obj, dtype=dtype, shape=shape, offset=offset)
1082
+
1083
+ elif isinstance(obj, ndarray):
1084
+ if dtype is not None and (obj.dtype != dtype):
1085
+ new = obj.view(dtype)
1086
+ else:
1087
+ new = obj
1088
+ if copy:
1089
+ new = new.copy()
1090
+ return new.view(recarray)
1091
+
1092
+ else:
1093
+ interface = getattr(obj, "__array_interface__", None)
1094
+ if interface is None or not isinstance(interface, dict):
1095
+ raise ValueError("Unknown input type")
1096
+ obj = sb.array(obj)
1097
+ if dtype is not None and (obj.dtype != dtype):
1098
+ obj = obj.view(dtype)
1099
+ return obj.view(recarray)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/records.pyi ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from collections.abc import Sequence, Iterable
3
+ from typing import (
4
+ Any,
5
+ TypeVar,
6
+ overload,
7
+ Protocol,
8
+ )
9
+
10
+ from numpy import (
11
+ format_parser as format_parser,
12
+ record as record,
13
+ recarray as recarray,
14
+ dtype,
15
+ generic,
16
+ void,
17
+ _ByteOrder,
18
+ _SupportsBuffer,
19
+ )
20
+
21
+ from numpy._typing import (
22
+ ArrayLike,
23
+ DTypeLike,
24
+ NDArray,
25
+ _ShapeLike,
26
+ _ArrayLikeVoid_co,
27
+ _NestedSequence,
28
+ )
29
+
30
+ _SCT = TypeVar("_SCT", bound=generic)
31
+
32
+ _RecArray = recarray[Any, dtype[_SCT]]
33
+
34
+ class _SupportsReadInto(Protocol):
35
+ def seek(self, offset: int, whence: int, /) -> object: ...
36
+ def tell(self, /) -> int: ...
37
+ def readinto(self, buffer: memoryview, /) -> int: ...
38
+
39
+ __all__: list[str]
40
+
41
+ @overload
42
+ def fromarrays(
43
+ arrayList: Iterable[ArrayLike],
44
+ dtype: DTypeLike = ...,
45
+ shape: None | _ShapeLike = ...,
46
+ formats: None = ...,
47
+ names: None = ...,
48
+ titles: None = ...,
49
+ aligned: bool = ...,
50
+ byteorder: None = ...,
51
+ ) -> _RecArray[Any]: ...
52
+ @overload
53
+ def fromarrays(
54
+ arrayList: Iterable[ArrayLike],
55
+ dtype: None = ...,
56
+ shape: None | _ShapeLike = ...,
57
+ *,
58
+ formats: DTypeLike,
59
+ names: None | str | Sequence[str] = ...,
60
+ titles: None | str | Sequence[str] = ...,
61
+ aligned: bool = ...,
62
+ byteorder: None | _ByteOrder = ...,
63
+ ) -> _RecArray[record]: ...
64
+
65
+ @overload
66
+ def fromrecords(
67
+ recList: _ArrayLikeVoid_co | tuple[Any, ...] | _NestedSequence[tuple[Any, ...]],
68
+ dtype: DTypeLike = ...,
69
+ shape: None | _ShapeLike = ...,
70
+ formats: None = ...,
71
+ names: None = ...,
72
+ titles: None = ...,
73
+ aligned: bool = ...,
74
+ byteorder: None = ...,
75
+ ) -> _RecArray[record]: ...
76
+ @overload
77
+ def fromrecords(
78
+ recList: _ArrayLikeVoid_co | tuple[Any, ...] | _NestedSequence[tuple[Any, ...]],
79
+ dtype: None = ...,
80
+ shape: None | _ShapeLike = ...,
81
+ *,
82
+ formats: DTypeLike,
83
+ names: None | str | Sequence[str] = ...,
84
+ titles: None | str | Sequence[str] = ...,
85
+ aligned: bool = ...,
86
+ byteorder: None | _ByteOrder = ...,
87
+ ) -> _RecArray[record]: ...
88
+
89
+ @overload
90
+ def fromstring(
91
+ datastring: _SupportsBuffer,
92
+ dtype: DTypeLike,
93
+ shape: None | _ShapeLike = ...,
94
+ offset: int = ...,
95
+ formats: None = ...,
96
+ names: None = ...,
97
+ titles: None = ...,
98
+ aligned: bool = ...,
99
+ byteorder: None = ...,
100
+ ) -> _RecArray[record]: ...
101
+ @overload
102
+ def fromstring(
103
+ datastring: _SupportsBuffer,
104
+ dtype: None = ...,
105
+ shape: None | _ShapeLike = ...,
106
+ offset: int = ...,
107
+ *,
108
+ formats: DTypeLike,
109
+ names: None | str | Sequence[str] = ...,
110
+ titles: None | str | Sequence[str] = ...,
111
+ aligned: bool = ...,
112
+ byteorder: None | _ByteOrder = ...,
113
+ ) -> _RecArray[record]: ...
114
+
115
+ @overload
116
+ def fromfile(
117
+ fd: str | bytes | os.PathLike[str] | os.PathLike[bytes] | _SupportsReadInto,
118
+ dtype: DTypeLike,
119
+ shape: None | _ShapeLike = ...,
120
+ offset: int = ...,
121
+ formats: None = ...,
122
+ names: None = ...,
123
+ titles: None = ...,
124
+ aligned: bool = ...,
125
+ byteorder: None = ...,
126
+ ) -> _RecArray[Any]: ...
127
+ @overload
128
+ def fromfile(
129
+ fd: str | bytes | os.PathLike[str] | os.PathLike[bytes] | _SupportsReadInto,
130
+ dtype: None = ...,
131
+ shape: None | _ShapeLike = ...,
132
+ offset: int = ...,
133
+ *,
134
+ formats: DTypeLike,
135
+ names: None | str | Sequence[str] = ...,
136
+ titles: None | str | Sequence[str] = ...,
137
+ aligned: bool = ...,
138
+ byteorder: None | _ByteOrder = ...,
139
+ ) -> _RecArray[record]: ...
140
+
141
+ @overload
142
+ def array(
143
+ obj: _SCT | NDArray[_SCT],
144
+ dtype: None = ...,
145
+ shape: None | _ShapeLike = ...,
146
+ offset: int = ...,
147
+ formats: None = ...,
148
+ names: None = ...,
149
+ titles: None = ...,
150
+ aligned: bool = ...,
151
+ byteorder: None = ...,
152
+ copy: bool = ...,
153
+ ) -> _RecArray[_SCT]: ...
154
+ @overload
155
+ def array(
156
+ obj: ArrayLike,
157
+ dtype: DTypeLike,
158
+ shape: None | _ShapeLike = ...,
159
+ offset: int = ...,
160
+ formats: None = ...,
161
+ names: None = ...,
162
+ titles: None = ...,
163
+ aligned: bool = ...,
164
+ byteorder: None = ...,
165
+ copy: bool = ...,
166
+ ) -> _RecArray[Any]: ...
167
+ @overload
168
+ def array(
169
+ obj: ArrayLike,
170
+ dtype: None = ...,
171
+ shape: None | _ShapeLike = ...,
172
+ offset: int = ...,
173
+ *,
174
+ formats: DTypeLike,
175
+ names: None | str | Sequence[str] = ...,
176
+ titles: None | str | Sequence[str] = ...,
177
+ aligned: bool = ...,
178
+ byteorder: None | _ByteOrder = ...,
179
+ copy: bool = ...,
180
+ ) -> _RecArray[record]: ...
181
+ @overload
182
+ def array(
183
+ obj: None,
184
+ dtype: DTypeLike,
185
+ shape: _ShapeLike,
186
+ offset: int = ...,
187
+ formats: None = ...,
188
+ names: None = ...,
189
+ titles: None = ...,
190
+ aligned: bool = ...,
191
+ byteorder: None = ...,
192
+ copy: bool = ...,
193
+ ) -> _RecArray[Any]: ...
194
+ @overload
195
+ def array(
196
+ obj: None,
197
+ dtype: None = ...,
198
+ *,
199
+ shape: _ShapeLike,
200
+ offset: int = ...,
201
+ formats: DTypeLike,
202
+ names: None | str | Sequence[str] = ...,
203
+ titles: None | str | Sequence[str] = ...,
204
+ aligned: bool = ...,
205
+ byteorder: None | _ByteOrder = ...,
206
+ copy: bool = ...,
207
+ ) -> _RecArray[record]: ...
208
+ @overload
209
+ def array(
210
+ obj: _SupportsReadInto,
211
+ dtype: DTypeLike,
212
+ shape: None | _ShapeLike = ...,
213
+ offset: int = ...,
214
+ formats: None = ...,
215
+ names: None = ...,
216
+ titles: None = ...,
217
+ aligned: bool = ...,
218
+ byteorder: None = ...,
219
+ copy: bool = ...,
220
+ ) -> _RecArray[Any]: ...
221
+ @overload
222
+ def array(
223
+ obj: _SupportsReadInto,
224
+ dtype: None = ...,
225
+ shape: None | _ShapeLike = ...,
226
+ offset: int = ...,
227
+ *,
228
+ formats: DTypeLike,
229
+ names: None | str | Sequence[str] = ...,
230
+ titles: None | str | Sequence[str] = ...,
231
+ aligned: bool = ...,
232
+ byteorder: None | _ByteOrder = ...,
233
+ copy: bool = ...,
234
+ ) -> _RecArray[record]: ...
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/shape_base.pyi ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections.abc import Sequence
2
+ from typing import TypeVar, overload, Any, SupportsIndex
3
+
4
+ from numpy import generic, _CastingKind
5
+ from numpy._typing import (
6
+ NDArray,
7
+ ArrayLike,
8
+ DTypeLike,
9
+ _ArrayLike,
10
+ _DTypeLike,
11
+ )
12
+
13
+ _SCT = TypeVar("_SCT", bound=generic)
14
+ _ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
15
+
16
+ __all__: list[str]
17
+
18
+ @overload
19
+ def atleast_1d(arys: _ArrayLike[_SCT], /) -> NDArray[_SCT]: ...
20
+ @overload
21
+ def atleast_1d(arys: ArrayLike, /) -> NDArray[Any]: ...
22
+ @overload
23
+ def atleast_1d(*arys: ArrayLike) -> list[NDArray[Any]]: ...
24
+
25
+ @overload
26
+ def atleast_2d(arys: _ArrayLike[_SCT], /) -> NDArray[_SCT]: ...
27
+ @overload
28
+ def atleast_2d(arys: ArrayLike, /) -> NDArray[Any]: ...
29
+ @overload
30
+ def atleast_2d(*arys: ArrayLike) -> list[NDArray[Any]]: ...
31
+
32
+ @overload
33
+ def atleast_3d(arys: _ArrayLike[_SCT], /) -> NDArray[_SCT]: ...
34
+ @overload
35
+ def atleast_3d(arys: ArrayLike, /) -> NDArray[Any]: ...
36
+ @overload
37
+ def atleast_3d(*arys: ArrayLike) -> list[NDArray[Any]]: ...
38
+
39
+ @overload
40
+ def vstack(
41
+ tup: Sequence[_ArrayLike[_SCT]],
42
+ *,
43
+ dtype: None = ...,
44
+ casting: _CastingKind = ...
45
+ ) -> NDArray[_SCT]: ...
46
+ @overload
47
+ def vstack(
48
+ tup: Sequence[ArrayLike],
49
+ *,
50
+ dtype: _DTypeLike[_SCT],
51
+ casting: _CastingKind = ...
52
+ ) -> NDArray[_SCT]: ...
53
+ @overload
54
+ def vstack(
55
+ tup: Sequence[ArrayLike],
56
+ *,
57
+ dtype: DTypeLike = ...,
58
+ casting: _CastingKind = ...
59
+ ) -> NDArray[Any]: ...
60
+
61
+ @overload
62
+ def hstack(
63
+ tup: Sequence[_ArrayLike[_SCT]],
64
+ *,
65
+ dtype: None = ...,
66
+ casting: _CastingKind = ...
67
+ ) -> NDArray[_SCT]: ...
68
+ @overload
69
+ def hstack(
70
+ tup: Sequence[ArrayLike],
71
+ *,
72
+ dtype: _DTypeLike[_SCT],
73
+ casting: _CastingKind = ...
74
+ ) -> NDArray[_SCT]: ...
75
+ @overload
76
+ def hstack(
77
+ tup: Sequence[ArrayLike],
78
+ *,
79
+ dtype: DTypeLike = ...,
80
+ casting: _CastingKind = ...
81
+ ) -> NDArray[Any]: ...
82
+
83
+ @overload
84
+ def stack(
85
+ arrays: Sequence[_ArrayLike[_SCT]],
86
+ axis: SupportsIndex = ...,
87
+ out: None = ...,
88
+ *,
89
+ dtype: None = ...,
90
+ casting: _CastingKind = ...
91
+ ) -> NDArray[_SCT]: ...
92
+ @overload
93
+ def stack(
94
+ arrays: Sequence[ArrayLike],
95
+ axis: SupportsIndex = ...,
96
+ out: None = ...,
97
+ *,
98
+ dtype: _DTypeLike[_SCT],
99
+ casting: _CastingKind = ...
100
+ ) -> NDArray[_SCT]: ...
101
+ @overload
102
+ def stack(
103
+ arrays: Sequence[ArrayLike],
104
+ axis: SupportsIndex = ...,
105
+ out: None = ...,
106
+ *,
107
+ dtype: DTypeLike = ...,
108
+ casting: _CastingKind = ...
109
+ ) -> NDArray[Any]: ...
110
+ @overload
111
+ def stack(
112
+ arrays: Sequence[ArrayLike],
113
+ axis: SupportsIndex = ...,
114
+ out: _ArrayType = ...,
115
+ *,
116
+ dtype: DTypeLike = ...,
117
+ casting: _CastingKind = ...
118
+ ) -> _ArrayType: ...
119
+
120
+ @overload
121
+ def block(arrays: _ArrayLike[_SCT]) -> NDArray[_SCT]: ...
122
+ @overload
123
+ def block(arrays: ArrayLike) -> NDArray[Any]: ...
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/sacrebleu-2.6.0.dist-info/licenses/LICENSE.txt ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/tabulate/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (91.8 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/tabulate/__pycache__/version.cpython-312.pyc ADDED
Binary file (329 Bytes). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (78.7 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/_device_limits.cpython-312.pyc ADDED
Binary file (5.08 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/_memory_viz.cpython-312.pyc ADDED
Binary file (34.6 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/_pin_memory_utils.cpython-312.pyc ADDED
Binary file (1.37 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/_utils.cpython-312.pyc ADDED
Binary file (22 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/gds.cpython-312.pyc ADDED
Binary file (8.01 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/graphs.cpython-312.pyc ADDED
Binary file (32.4 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/green_contexts.cpython-312.pyc ADDED
Binary file (2.01 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/memory.cpython-312.pyc ADDED
Binary file (62.2 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/nvtx.cpython-312.pyc ADDED
Binary file (4.98 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/__pycache__/profiler.cpython-312.pyc ADDED
Binary file (3.76 kB). View file
 
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_adaptive_avg_pool3d_cpu_dispatch.h ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
4
+
5
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
6
+
7
+ // The only #includes we need are for custom classes that have defaults in the C++ API
8
+ #include <c10/core/MemoryFormat.h>
9
+ #include <c10/core/Scalar.h>
10
+ #include <ATen/core/Reduction.h>
11
+
12
+ // Forward declarations of any types needed in the operator signatures.
13
+ // We can't directly include these classes because it will cause circular include dependencies.
14
+ // This file is included by TensorBody.h, which defines the Tensor class.
15
+ #include <ATen/core/ATen_fwd.h>
16
+
17
+ namespace at {
18
+
19
+ namespace cpu {
20
+
21
+ TORCH_API at::Tensor _adaptive_avg_pool3d(const at::Tensor & self, at::IntArrayRef output_size);
22
+ TORCH_API at::Tensor _adaptive_avg_pool3d_symint(const at::Tensor & self, c10::SymIntArrayRef output_size);
23
+
24
+ } // namespace cpu
25
+ } // namespace at
26
+
27
+ #else
28
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
29
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_assert_async_cpu_dispatch.h ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
4
+
5
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
6
+
7
+ // The only #includes we need are for custom classes that have defaults in the C++ API
8
+ #include <c10/core/MemoryFormat.h>
9
+ #include <c10/core/Scalar.h>
10
+ #include <ATen/core/Reduction.h>
11
+
12
+ // Forward declarations of any types needed in the operator signatures.
13
+ // We can't directly include these classes because it will cause circular include dependencies.
14
+ // This file is included by TensorBody.h, which defines the Tensor class.
15
+ #include <ATen/core/ATen_fwd.h>
16
+
17
+ namespace at {
18
+
19
+ namespace cpu {
20
+
21
+ TORCH_API void _assert_async(const at::Tensor & self);
22
+ TORCH_API void _assert_async(const at::Tensor & self, c10::string_view assert_msg);
23
+
24
+ } // namespace cpu
25
+ } // namespace at
26
+
27
+ #else
28
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
29
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_autocast_to_full_precision_ops.h ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from Operator.h
5
+
6
+ #include <string_view>
7
+ #include <tuple>
8
+ #include <vector>
9
+
10
+ // Forward declarations of any types needed in the operator signatures.
11
+ // We can't directly include these classes because it will cause circular include dependencies.
12
+ // This file is included by TensorBody.h, which defines the Tensor class.
13
+ #include <ATen/core/ATen_fwd.h>
14
+
15
+ namespace at {
16
+ namespace _ops {
17
+
18
+
19
+ struct TORCH_API _autocast_to_full_precision {
20
+ using schema = at::Tensor (const at::Tensor &, bool, bool);
21
+ using ptr_schema = schema*;
22
+ // See Note [static constexpr char* members for windows NVCC]
23
+ static constexpr const char* name = "aten::_autocast_to_full_precision";
24
+ static constexpr const char* overload_name = "";
25
+ static constexpr const char* schema_str = "_autocast_to_full_precision(Tensor(a) self, bool cuda_enabled, bool cpu_enabled) -> Tensor(a)";
26
+ static at::Tensor call(const at::Tensor & self, bool cuda_enabled, bool cpu_enabled);
27
+ static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, bool cuda_enabled, bool cpu_enabled);
28
+ };
29
+
30
+ }} // namespace at::_ops
31
+
32
+ #else
33
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
34
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_efficient_attention_backward_cuda_dispatch.h ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
4
+
5
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
6
+
7
+ // The only #includes we need are for custom classes that have defaults in the C++ API
8
+ #include <c10/core/MemoryFormat.h>
9
+ #include <c10/core/Scalar.h>
10
+ #include <ATen/core/Reduction.h>
11
+
12
+ // Forward declarations of any types needed in the operator signatures.
13
+ // We can't directly include these classes because it will cause circular include dependencies.
14
+ // This file is included by TensorBody.h, which defines the Tensor class.
15
+ #include <ATen/core/ATen_fwd.h>
16
+
17
+ namespace at {
18
+
19
+ namespace cuda {
20
+
21
+ TORCH_API ::std::tuple<at::Tensor,at::Tensor,at::Tensor,at::Tensor> _efficient_attention_backward(const at::Tensor & grad_out_, const at::Tensor & query, const at::Tensor & key, const at::Tensor & value, const ::std::optional<at::Tensor> & bias, const at::Tensor & out, const ::std::optional<at::Tensor> & cu_seqlens_q, const ::std::optional<at::Tensor> & cu_seqlens_k, int64_t max_seqlen_q, int64_t max_seqlen_k, const at::Tensor & logsumexp, double dropout_p, const at::Tensor & philox_seed, const at::Tensor & philox_offset, int64_t custom_mask_type, bool bias_requires_grad, ::std::optional<double> scale=::std::nullopt, ::std::optional<int64_t> num_splits_key=::std::nullopt, ::std::optional<int64_t> window_size=::std::nullopt, bool shared_storage_dqdkdv=false);
22
+ TORCH_API ::std::tuple<at::Tensor,at::Tensor,at::Tensor,at::Tensor> _efficient_attention_backward_symint(const at::Tensor & grad_out_, const at::Tensor & query, const at::Tensor & key, const at::Tensor & value, const ::std::optional<at::Tensor> & bias, const at::Tensor & out, const ::std::optional<at::Tensor> & cu_seqlens_q, const ::std::optional<at::Tensor> & cu_seqlens_k, c10::SymInt max_seqlen_q, c10::SymInt max_seqlen_k, const at::Tensor & logsumexp, double dropout_p, const at::Tensor & philox_seed, const at::Tensor & philox_offset, int64_t custom_mask_type, bool bias_requires_grad, ::std::optional<double> scale=::std::nullopt, ::std::optional<int64_t> num_splits_key=::std::nullopt, ::std::optional<int64_t> window_size=::std::nullopt, bool shared_storage_dqdkdv=false);
23
+
24
+ } // namespace cuda
25
+ } // namespace at
26
+
27
+ #else
28
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
29
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_embedding_bag_native.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from NativeFunction.h
5
+
6
+ #include <c10/core/Scalar.h>
7
+ #include <c10/core/Storage.h>
8
+ #include <c10/core/TensorOptions.h>
9
+ #include <c10/util/Deprecated.h>
10
+ #include <optional>
11
+ #include <c10/core/QScheme.h>
12
+ #include <ATen/core/Reduction.h>
13
+ #include <ATen/core/Tensor.h>
14
+ #include <tuple>
15
+ #include <vector>
16
+
17
+
18
+ namespace at {
19
+ namespace native {
20
+ TORCH_API ::std::tuple<at::Tensor &,at::Tensor &,at::Tensor &,at::Tensor &> _embedding_bag_out(const at::Tensor & weight, const at::Tensor & indices, const at::Tensor & offsets, bool scale_grad_by_freq, int64_t mode, bool sparse, const ::std::optional<at::Tensor> & per_sample_weights, bool include_last_offset, int64_t padding_idx, at::Tensor & out0, at::Tensor & out1, at::Tensor & out2, at::Tensor & out3);
21
+ TORCH_API ::std::tuple<at::Tensor,at::Tensor,at::Tensor,at::Tensor> _embedding_bag_cpu(const at::Tensor & weight, const at::Tensor & indices, const at::Tensor & offsets, bool scale_grad_by_freq=false, int64_t mode=0, bool sparse=false, const ::std::optional<at::Tensor> & per_sample_weights={}, bool include_last_offset=false, int64_t padding_idx=-1);
22
+ TORCH_API ::std::tuple<at::Tensor,at::Tensor,at::Tensor,at::Tensor> _embedding_bag_cuda(const at::Tensor & weight, const at::Tensor & indices, const at::Tensor & offsets, bool scale_grad_by_freq=false, int64_t mode=0, bool sparse=false, const ::std::optional<at::Tensor> & per_sample_weights={}, bool include_last_offset=false, int64_t padding_idx=-1);
23
+ } // namespace native
24
+ } // namespace at
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_fake_quantize_learnable_per_channel_affine_backward_cpu_dispatch.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
4
+
5
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
6
+
7
+ // The only #includes we need are for custom classes that have defaults in the C++ API
8
+ #include <c10/core/MemoryFormat.h>
9
+ #include <c10/core/Scalar.h>
10
+ #include <ATen/core/Reduction.h>
11
+
12
+ // Forward declarations of any types needed in the operator signatures.
13
+ // We can't directly include these classes because it will cause circular include dependencies.
14
+ // This file is included by TensorBody.h, which defines the Tensor class.
15
+ #include <ATen/core/ATen_fwd.h>
16
+
17
+ namespace at {
18
+
19
+ namespace cpu {
20
+
21
+ TORCH_API ::std::tuple<at::Tensor,at::Tensor,at::Tensor> _fake_quantize_learnable_per_channel_affine_backward(const at::Tensor & grad, const at::Tensor & self, const at::Tensor & scale, const at::Tensor & zero_point, int64_t axis, int64_t quant_min, int64_t quant_max, double grad_factor=1.0);
22
+
23
+ } // namespace cpu
24
+ } // namespace at
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_fft_r2c.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from Function.h
5
+
6
+ #include <ATen/Context.h>
7
+ #include <ATen/DeviceGuard.h>
8
+ #include <ATen/TensorUtils.h>
9
+ #include <ATen/TracerMode.h>
10
+ #include <ATen/core/Generator.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <c10/core/Scalar.h>
14
+ #include <c10/core/Storage.h>
15
+ #include <c10/core/TensorOptions.h>
16
+ #include <c10/util/Deprecated.h>
17
+ #include <optional>
18
+ #include <string_view>
19
+
20
+
21
+
22
+ #include <ATen/ops/_fft_r2c_ops.h>
23
+
24
+ namespace at {
25
+
26
+
27
+ // aten::_fft_r2c(Tensor self, int[] dim, int normalization, bool onesided) -> Tensor
28
+ inline at::Tensor _fft_r2c(const at::Tensor & self, at::IntArrayRef dim, int64_t normalization, bool onesided) {
29
+ return at::_ops::_fft_r2c::call(self, dim, normalization, onesided);
30
+ }
31
+
32
+ // aten::_fft_r2c.out(Tensor self, int[] dim, int normalization, bool onesided, *, Tensor(a!) out) -> Tensor(a!)
33
+ inline at::Tensor & _fft_r2c_out(at::Tensor & out, const at::Tensor & self, at::IntArrayRef dim, int64_t normalization, bool onesided) {
34
+ return at::_ops::_fft_r2c_out::call(self, dim, normalization, onesided, out);
35
+ }
36
+ // aten::_fft_r2c.out(Tensor self, int[] dim, int normalization, bool onesided, *, Tensor(a!) out) -> Tensor(a!)
37
+ inline at::Tensor & _fft_r2c_outf(const at::Tensor & self, at::IntArrayRef dim, int64_t normalization, bool onesided, at::Tensor & out) {
38
+ return at::_ops::_fft_r2c_out::call(self, dim, normalization, onesided, out);
39
+ }
40
+
41
+ }
42
+
43
+ #else
44
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
45
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_foreach_sub_cuda_dispatch.h ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
4
+
5
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
6
+
7
+ // The only #includes we need are for custom classes that have defaults in the C++ API
8
+ #include <c10/core/MemoryFormat.h>
9
+ #include <c10/core/Scalar.h>
10
+ #include <ATen/core/Reduction.h>
11
+
12
+ // Forward declarations of any types needed in the operator signatures.
13
+ // We can't directly include these classes because it will cause circular include dependencies.
14
+ // This file is included by TensorBody.h, which defines the Tensor class.
15
+ #include <ATen/core/ATen_fwd.h>
16
+
17
+ namespace at {
18
+
19
+ namespace cuda {
20
+
21
+ TORCH_API ::std::vector<at::Tensor> _foreach_sub(at::TensorList self, const at::Scalar & scalar);
22
+ TORCH_API void _foreach_sub_(at::TensorList self, const at::Scalar & scalar);
23
+ TORCH_API ::std::vector<at::Tensor> _foreach_sub(at::TensorList self, at::TensorList other, const at::Scalar & alpha=1);
24
+ TORCH_API void _foreach_sub_(at::TensorList self, at::TensorList other, const at::Scalar & alpha=1);
25
+ TORCH_API ::std::vector<at::Tensor> _foreach_sub(at::TensorList self, at::ArrayRef<at::Scalar> scalars);
26
+ TORCH_API void _foreach_sub_(at::TensorList self, at::ArrayRef<at::Scalar> scalars);
27
+
28
+ } // namespace cuda
29
+ } // namespace at
30
+
31
+ #else
32
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
33
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_fused_sdp_choice.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from Function.h
5
+
6
+ #include <ATen/Context.h>
7
+ #include <ATen/DeviceGuard.h>
8
+ #include <ATen/TensorUtils.h>
9
+ #include <ATen/TracerMode.h>
10
+ #include <ATen/core/Generator.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <c10/core/Scalar.h>
14
+ #include <c10/core/Storage.h>
15
+ #include <c10/core/TensorOptions.h>
16
+ #include <c10/util/Deprecated.h>
17
+ #include <optional>
18
+ #include <string_view>
19
+
20
+
21
+
22
+ #include <ATen/ops/_fused_sdp_choice_ops.h>
23
+
24
+ namespace at {
25
+
26
+
27
+ // aten::_fused_sdp_choice(Tensor query, Tensor key, Tensor value, Tensor? attn_mask=None, float dropout_p=0.0, bool is_causal=False, *, float? scale=None, bool enable_gqa=False) -> int
28
+ inline int64_t _fused_sdp_choice(const at::Tensor & query, const at::Tensor & key, const at::Tensor & value, const ::std::optional<at::Tensor> & attn_mask={}, double dropout_p=0.0, bool is_causal=false, ::std::optional<double> scale=::std::nullopt, bool enable_gqa=false) {
29
+ return at::_ops::_fused_sdp_choice::call(query, key, value, attn_mask, dropout_p, is_causal, scale, enable_gqa);
30
+ }
31
+
32
+ }
33
+
34
+ #else
35
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
36
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_has_same_storage_numel.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from Function.h
5
+
6
+ #include <ATen/Context.h>
7
+ #include <ATen/DeviceGuard.h>
8
+ #include <ATen/TensorUtils.h>
9
+ #include <ATen/TracerMode.h>
10
+ #include <ATen/core/Generator.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <c10/core/Scalar.h>
14
+ #include <c10/core/Storage.h>
15
+ #include <c10/core/TensorOptions.h>
16
+ #include <c10/util/Deprecated.h>
17
+ #include <optional>
18
+ #include <string_view>
19
+
20
+
21
+
22
+ #include <ATen/ops/_has_same_storage_numel_ops.h>
23
+
24
+ namespace at {
25
+
26
+
27
+ // aten::_has_same_storage_numel(Tensor self, Tensor other) -> bool
28
+ inline bool _has_same_storage_numel(const at::Tensor & self, const at::Tensor & other) {
29
+ return at::_ops::_has_same_storage_numel::call(self, other);
30
+ }
31
+
32
+ }
33
+
34
+ #else
35
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
36
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_masked_softmax_native.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from NativeFunction.h
5
+
6
+ #include <c10/core/Scalar.h>
7
+ #include <c10/core/Storage.h>
8
+ #include <c10/core/TensorOptions.h>
9
+ #include <c10/util/Deprecated.h>
10
+ #include <optional>
11
+ #include <c10/core/QScheme.h>
12
+ #include <ATen/core/Reduction.h>
13
+ #include <ATen/core/Tensor.h>
14
+ #include <tuple>
15
+ #include <vector>
16
+
17
+
18
+ namespace at {
19
+ namespace native {
20
+ TORCH_API at::Tensor & _masked_softmax_out(const at::Tensor & self, const at::Tensor & mask, ::std::optional<int64_t> dim, ::std::optional<int64_t> mask_type, at::Tensor & out);
21
+ TORCH_API at::Tensor masked_softmax_cpu(const at::Tensor & self, const at::Tensor & mask, ::std::optional<int64_t> dim=::std::nullopt, ::std::optional<int64_t> mask_type=::std::nullopt);
22
+ TORCH_API at::Tensor masked_softmax_cuda(const at::Tensor & self, const at::Tensor & mask, ::std::optional<int64_t> dim=::std::nullopt, ::std::optional<int64_t> mask_type=::std::nullopt);
23
+ } // namespace native
24
+ } // namespace at
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_mkldnn_transpose_native.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from NativeFunction.h
5
+
6
+ #include <c10/core/Scalar.h>
7
+ #include <c10/core/Storage.h>
8
+ #include <c10/core/TensorOptions.h>
9
+ #include <c10/util/Deprecated.h>
10
+ #include <optional>
11
+ #include <c10/core/QScheme.h>
12
+ #include <ATen/core/Reduction.h>
13
+ #include <ATen/core/Tensor.h>
14
+ #include <tuple>
15
+ #include <vector>
16
+
17
+
18
+ namespace at {
19
+ namespace native {
20
+ TORCH_API at::Tensor & _mkldnn_transpose_out(const at::Tensor & self, int64_t dim0, int64_t dim1, at::Tensor & out);
21
+ TORCH_API at::Tensor mkldnn_transpose(const at::Tensor & self, int64_t dim0, int64_t dim1);
22
+ TORCH_API at::Tensor & mkldnn_transpose_(at::Tensor & self, int64_t dim0, int64_t dim1);
23
+ } // namespace native
24
+ } // namespace at
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_nested_tensor_size_ops.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from Operator.h
5
+
6
+ #include <string_view>
7
+ #include <tuple>
8
+ #include <vector>
9
+
10
+ // Forward declarations of any types needed in the operator signatures.
11
+ // We can't directly include these classes because it will cause circular include dependencies.
12
+ // This file is included by TensorBody.h, which defines the Tensor class.
13
+ #include <ATen/core/ATen_fwd.h>
14
+
15
+ namespace at {
16
+ namespace _ops {
17
+
18
+
19
+ struct TORCH_API _nested_tensor_size {
20
+ using schema = at::Tensor (const at::Tensor &);
21
+ using ptr_schema = schema*;
22
+ // See Note [static constexpr char* members for windows NVCC]
23
+ static constexpr const char* name = "aten::_nested_tensor_size";
24
+ static constexpr const char* overload_name = "";
25
+ static constexpr const char* schema_str = "_nested_tensor_size(Tensor self) -> Tensor";
26
+ static at::Tensor call(const at::Tensor & self);
27
+ static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self);
28
+ };
29
+
30
+ struct TORCH_API _nested_tensor_size_out {
31
+ using schema = at::Tensor & (const at::Tensor &, at::Tensor &);
32
+ using ptr_schema = schema*;
33
+ // See Note [static constexpr char* members for windows NVCC]
34
+ static constexpr const char* name = "aten::_nested_tensor_size";
35
+ static constexpr const char* overload_name = "out";
36
+ static constexpr const char* schema_str = "_nested_tensor_size.out(Tensor self, *, Tensor(a!) out) -> Tensor(a!)";
37
+ static at::Tensor & call(const at::Tensor & self, at::Tensor & out);
38
+ static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, at::Tensor & out);
39
+ };
40
+
41
+ }} // namespace at::_ops
42
+
43
+ #else
44
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
45
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_pdist_backward_native.h ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from NativeFunction.h
5
+
6
+ #include <c10/core/Scalar.h>
7
+ #include <c10/core/Storage.h>
8
+ #include <c10/core/TensorOptions.h>
9
+ #include <c10/util/Deprecated.h>
10
+ #include <optional>
11
+ #include <c10/core/QScheme.h>
12
+ #include <ATen/core/Reduction.h>
13
+ #include <ATen/core/Tensor.h>
14
+ #include <tuple>
15
+ #include <vector>
16
+
17
+
18
+ namespace at {
19
+ namespace native {
20
+ TORCH_API at::Tensor & _pdist_backward_out(const at::Tensor & grad, const at::Tensor & self, double p, const at::Tensor & pdist, at::Tensor & out);
21
+ TORCH_API at::Tensor _pdist_backward(const at::Tensor & grad, const at::Tensor & self, double p, const at::Tensor & pdist);
22
+ } // namespace native
23
+ } // namespace at
24
+
25
+ #else
26
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
27
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_triton_multi_head_attention_cuda_dispatch.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
4
+
5
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
6
+
7
+ // The only #includes we need are for custom classes that have defaults in the C++ API
8
+ #include <c10/core/MemoryFormat.h>
9
+ #include <c10/core/Scalar.h>
10
+ #include <ATen/core/Reduction.h>
11
+
12
+ // Forward declarations of any types needed in the operator signatures.
13
+ // We can't directly include these classes because it will cause circular include dependencies.
14
+ // This file is included by TensorBody.h, which defines the Tensor class.
15
+ #include <ATen/core/ATen_fwd.h>
16
+
17
+ namespace at {
18
+
19
+ namespace cuda {
20
+
21
+ TORCH_API at::Tensor _triton_multi_head_attention(const at::Tensor & query, const at::Tensor & key, const at::Tensor & value, int64_t embed_dim, int64_t num_head, const at::Tensor & qkv_weight, const at::Tensor & qkv_bias, const at::Tensor & proj_weight, const at::Tensor & proj_bias, const ::std::optional<at::Tensor> & mask={});
22
+
23
+ } // namespace cuda
24
+ } // namespace at
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/_validate_sparse_bsr_tensor_args.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from Function.h
5
+
6
+ #include <ATen/Context.h>
7
+ #include <ATen/DeviceGuard.h>
8
+ #include <ATen/TensorUtils.h>
9
+ #include <ATen/TracerMode.h>
10
+ #include <ATen/core/Generator.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <c10/core/Scalar.h>
14
+ #include <c10/core/Storage.h>
15
+ #include <c10/core/TensorOptions.h>
16
+ #include <c10/util/Deprecated.h>
17
+ #include <optional>
18
+ #include <string_view>
19
+
20
+
21
+
22
+ #include <ATen/ops/_validate_sparse_bsr_tensor_args_ops.h>
23
+
24
+ namespace at {
25
+
26
+
27
+ // aten::_validate_sparse_bsr_tensor_args(Tensor crow_indices, Tensor col_indices, Tensor values, int[] size, bool? check_pinning=None) -> ()
28
+ inline void _validate_sparse_bsr_tensor_args(const at::Tensor & crow_indices, const at::Tensor & col_indices, const at::Tensor & values, at::IntArrayRef size, ::std::optional<bool> check_pinning=::std::nullopt) {
29
+ return at::_ops::_validate_sparse_bsr_tensor_args::call(crow_indices, col_indices, values, size, check_pinning);
30
+ }
31
+
32
+ }
33
+
34
+ #else
35
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
36
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/abs_native.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from NativeFunction.h
5
+
6
+ #include <c10/core/Scalar.h>
7
+ #include <c10/core/Storage.h>
8
+ #include <c10/core/TensorOptions.h>
9
+ #include <c10/util/Deprecated.h>
10
+ #include <optional>
11
+ #include <c10/core/QScheme.h>
12
+ #include <ATen/core/Reduction.h>
13
+ #include <ATen/core/Tensor.h>
14
+ #include <tuple>
15
+ #include <vector>
16
+
17
+
18
+ namespace at {
19
+ namespace native {
20
+ TORCH_API at::Tensor abs(const at::Tensor & self);
21
+ TORCH_API at::Tensor & abs_(at::Tensor & self);
22
+ TORCH_API at::Tensor & abs_out(const at::Tensor & self, at::Tensor & out);
23
+ TORCH_API at::Tensor NestedTensor_abs(const at::Tensor & self);
24
+ TORCH_API at::Tensor & NestedTensor_abs_(at::Tensor & self);
25
+ TORCH_API at::Tensor abs_sparse(const at::Tensor & self);
26
+ TORCH_API at::Tensor & abs_sparse_out(const at::Tensor & self, at::Tensor & out);
27
+ TORCH_API at::Tensor & abs_sparse_(at::Tensor & self);
28
+ TORCH_API at::Tensor abs_sparse_csr(const at::Tensor & self);
29
+ TORCH_API at::Tensor & abs_sparse_csr_out(const at::Tensor & self, at::Tensor & out);
30
+ TORCH_API at::Tensor & abs_sparse_csr_(at::Tensor & self);
31
+ } // namespace native
32
+ } // namespace at
33
+
34
+ #else
35
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
36
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/asinh_cpu_dispatch.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
4
+
5
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
6
+
7
+ // The only #includes we need are for custom classes that have defaults in the C++ API
8
+ #include <c10/core/MemoryFormat.h>
9
+ #include <c10/core/Scalar.h>
10
+ #include <ATen/core/Reduction.h>
11
+
12
+ // Forward declarations of any types needed in the operator signatures.
13
+ // We can't directly include these classes because it will cause circular include dependencies.
14
+ // This file is included by TensorBody.h, which defines the Tensor class.
15
+ #include <ATen/core/ATen_fwd.h>
16
+
17
+ namespace at {
18
+
19
+ namespace cpu {
20
+
21
+ TORCH_API at::Tensor asinh(const at::Tensor & self);
22
+ TORCH_API at::Tensor & asinh_out(at::Tensor & out, const at::Tensor & self);
23
+ TORCH_API at::Tensor & asinh_outf(const at::Tensor & self, at::Tensor & out);
24
+ TORCH_API at::Tensor & asinh_(at::Tensor & self);
25
+
26
+ } // namespace cpu
27
+ } // namespace at
28
+
29
+ #else
30
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
31
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/batch_norm_backward_elemt.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from Function.h
5
+
6
+ #include <ATen/Context.h>
7
+ #include <ATen/DeviceGuard.h>
8
+ #include <ATen/TensorUtils.h>
9
+ #include <ATen/TracerMode.h>
10
+ #include <ATen/core/Generator.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <c10/core/Scalar.h>
14
+ #include <c10/core/Storage.h>
15
+ #include <c10/core/TensorOptions.h>
16
+ #include <c10/util/Deprecated.h>
17
+ #include <optional>
18
+ #include <string_view>
19
+
20
+
21
+
22
+ #include <ATen/ops/batch_norm_backward_elemt_ops.h>
23
+
24
+ namespace at {
25
+
26
+
27
+ // aten::batch_norm_backward_elemt(Tensor grad_out, Tensor input, Tensor mean, Tensor invstd, Tensor? weight, Tensor sum_dy, Tensor sum_dy_xmu, Tensor count) -> Tensor
28
+ inline at::Tensor batch_norm_backward_elemt(const at::Tensor & grad_out, const at::Tensor & input, const at::Tensor & mean, const at::Tensor & invstd, const ::std::optional<at::Tensor> & weight, const at::Tensor & sum_dy, const at::Tensor & sum_dy_xmu, const at::Tensor & count) {
29
+ return at::_ops::batch_norm_backward_elemt::call(grad_out, input, mean, invstd, weight, sum_dy, sum_dy_xmu, count);
30
+ }
31
+
32
+ // aten::batch_norm_backward_elemt.out(Tensor grad_out, Tensor input, Tensor mean, Tensor invstd, Tensor? weight, Tensor sum_dy, Tensor sum_dy_xmu, Tensor count, *, Tensor(a!) out) -> Tensor(a!)
33
+ inline at::Tensor & batch_norm_backward_elemt_out(at::Tensor & out, const at::Tensor & grad_out, const at::Tensor & input, const at::Tensor & mean, const at::Tensor & invstd, const ::std::optional<at::Tensor> & weight, const at::Tensor & sum_dy, const at::Tensor & sum_dy_xmu, const at::Tensor & count) {
34
+ return at::_ops::batch_norm_backward_elemt_out::call(grad_out, input, mean, invstd, weight, sum_dy, sum_dy_xmu, count, out);
35
+ }
36
+ // aten::batch_norm_backward_elemt.out(Tensor grad_out, Tensor input, Tensor mean, Tensor invstd, Tensor? weight, Tensor sum_dy, Tensor sum_dy_xmu, Tensor count, *, Tensor(a!) out) -> Tensor(a!)
37
+ inline at::Tensor & batch_norm_backward_elemt_outf(const at::Tensor & grad_out, const at::Tensor & input, const at::Tensor & mean, const at::Tensor & invstd, const ::std::optional<at::Tensor> & weight, const at::Tensor & sum_dy, const at::Tensor & sum_dy_xmu, const at::Tensor & count, at::Tensor & out) {
38
+ return at::_ops::batch_norm_backward_elemt_out::call(grad_out, input, mean, invstd, weight, sum_dy, sum_dy_xmu, count, out);
39
+ }
40
+
41
+ }
42
+
43
+ #else
44
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
45
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/batch_norm_backward_native.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from NativeFunction.h
5
+
6
+ #include <c10/core/Scalar.h>
7
+ #include <c10/core/Storage.h>
8
+ #include <c10/core/TensorOptions.h>
9
+ #include <c10/util/Deprecated.h>
10
+ #include <optional>
11
+ #include <c10/core/QScheme.h>
12
+ #include <ATen/core/Reduction.h>
13
+ #include <ATen/core/Tensor.h>
14
+ #include <tuple>
15
+ #include <vector>
16
+
17
+
18
+ namespace at {
19
+ namespace native {
20
+ TORCH_API ::std::tuple<at::Tensor,at::Tensor,at::Tensor> _new_batch_norm_backward_cpu(const at::Tensor & grad_out, const at::Tensor & input, const at::Tensor & weight, const ::std::optional<at::Tensor> & running_mean, const ::std::optional<at::Tensor> & running_var, const ::std::optional<at::Tensor> & save_mean, const ::std::optional<at::Tensor> & save_var, bool update, double eps, ::std::array<bool,3> output_mask, const at::Tensor & reserve);
21
+ TORCH_API ::std::tuple<at::Tensor,at::Tensor,at::Tensor> _new_batch_norm_backward_cuda(const at::Tensor & grad_out, const at::Tensor & input, const at::Tensor & weight, const ::std::optional<at::Tensor> & running_mean, const ::std::optional<at::Tensor> & running_var, const ::std::optional<at::Tensor> & save_mean, const ::std::optional<at::Tensor> & save_var, bool update, double eps, ::std::array<bool,3> output_mask, const at::Tensor & reserve);
22
+ TORCH_API ::std::tuple<at::Tensor,at::Tensor,at::Tensor> _new_batch_norm_backward_mkldnn(const at::Tensor & grad_out, const at::Tensor & input, const at::Tensor & weight, const ::std::optional<at::Tensor> & running_mean, const ::std::optional<at::Tensor> & running_var, const ::std::optional<at::Tensor> & save_mean, const ::std::optional<at::Tensor> & save_var, bool update, double eps, ::std::array<bool,3> output_mask, const at::Tensor & reserve);
23
+ } // namespace native
24
+ } // namespace at
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/cdist.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated by torchgen/gen.py from Function.h
5
+
6
+ #include <ATen/Context.h>
7
+ #include <ATen/DeviceGuard.h>
8
+ #include <ATen/TensorUtils.h>
9
+ #include <ATen/TracerMode.h>
10
+ #include <ATen/core/Generator.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <c10/core/Scalar.h>
14
+ #include <c10/core/Storage.h>
15
+ #include <c10/core/TensorOptions.h>
16
+ #include <c10/util/Deprecated.h>
17
+ #include <optional>
18
+ #include <string_view>
19
+
20
+
21
+
22
+ #include <ATen/ops/cdist_ops.h>
23
+
24
+ namespace at {
25
+
26
+
27
+ // aten::cdist(Tensor x1, Tensor x2, float p=2, int? compute_mode=None) -> Tensor
28
+ inline at::Tensor cdist(const at::Tensor & x1, const at::Tensor & x2, double p=2, ::std::optional<int64_t> compute_mode=::std::nullopt) {
29
+ return at::_ops::cdist::call(x1, x2, p, compute_mode);
30
+ }
31
+
32
+ }
33
+
34
+ #else
35
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
36
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/include/ATen/ops/conj_physical_cpu_dispatch.h ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
4
+
5
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
6
+
7
+ // The only #includes we need are for custom classes that have defaults in the C++ API
8
+ #include <c10/core/MemoryFormat.h>
9
+ #include <c10/core/Scalar.h>
10
+ #include <ATen/core/Reduction.h>
11
+
12
+ // Forward declarations of any types needed in the operator signatures.
13
+ // We can't directly include these classes because it will cause circular include dependencies.
14
+ // This file is included by TensorBody.h, which defines the Tensor class.
15
+ #include <ATen/core/ATen_fwd.h>
16
+
17
+ namespace at {
18
+
19
+ namespace cpu {
20
+
21
+ TORCH_API at::Tensor & conj_physical_out(at::Tensor & out, const at::Tensor & self);
22
+ TORCH_API at::Tensor & conj_physical_outf(const at::Tensor & self, at::Tensor & out);
23
+
24
+ } // namespace cpu
25
+ } // namespace at
26
+
27
+ #else
28
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
29
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)