passagemath-objects 10.6.44__cp314-cp314t-macosx_13_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. passagemath_objects/.dylibs/libgmp.10.dylib +0 -0
  2. passagemath_objects/__init__.py +3 -0
  3. passagemath_objects-10.6.44.dist-info/METADATA +115 -0
  4. passagemath_objects-10.6.44.dist-info/RECORD +280 -0
  5. passagemath_objects-10.6.44.dist-info/WHEEL +6 -0
  6. passagemath_objects-10.6.44.dist-info/top_level.txt +3 -0
  7. sage/all__sagemath_objects.py +37 -0
  8. sage/arith/all__sagemath_objects.py +5 -0
  9. sage/arith/long.pxd +411 -0
  10. sage/arith/numerical_approx.cpython-314t-darwin.so +0 -0
  11. sage/arith/numerical_approx.pxd +35 -0
  12. sage/arith/numerical_approx.pyx +75 -0
  13. sage/arith/power.cpython-314t-darwin.so +0 -0
  14. sage/arith/power.pxd +31 -0
  15. sage/arith/power.pyx +127 -0
  16. sage/categories/action.cpython-314t-darwin.so +0 -0
  17. sage/categories/action.pxd +29 -0
  18. sage/categories/action.pyx +641 -0
  19. sage/categories/algebra_functor.py +745 -0
  20. sage/categories/all__sagemath_objects.py +33 -0
  21. sage/categories/basic.py +62 -0
  22. sage/categories/cartesian_product.py +295 -0
  23. sage/categories/category.py +3401 -0
  24. sage/categories/category_cy_helper.cpython-314t-darwin.so +0 -0
  25. sage/categories/category_cy_helper.pxd +8 -0
  26. sage/categories/category_cy_helper.pyx +322 -0
  27. sage/categories/category_singleton.cpython-314t-darwin.so +0 -0
  28. sage/categories/category_singleton.pxd +3 -0
  29. sage/categories/category_singleton.pyx +342 -0
  30. sage/categories/category_types.py +637 -0
  31. sage/categories/category_with_axiom.py +2876 -0
  32. sage/categories/covariant_functorial_construction.py +703 -0
  33. sage/categories/facade_sets.py +228 -0
  34. sage/categories/functor.cpython-314t-darwin.so +0 -0
  35. sage/categories/functor.pxd +7 -0
  36. sage/categories/functor.pyx +691 -0
  37. sage/categories/homset.py +1338 -0
  38. sage/categories/homsets.py +364 -0
  39. sage/categories/isomorphic_objects.py +73 -0
  40. sage/categories/map.cpython-314t-darwin.so +0 -0
  41. sage/categories/map.pxd +34 -0
  42. sage/categories/map.pyx +2106 -0
  43. sage/categories/morphism.cpython-314t-darwin.so +0 -0
  44. sage/categories/morphism.pxd +14 -0
  45. sage/categories/morphism.pyx +895 -0
  46. sage/categories/objects.py +167 -0
  47. sage/categories/primer.py +1696 -0
  48. sage/categories/pushout.py +4834 -0
  49. sage/categories/quotients.py +64 -0
  50. sage/categories/realizations.py +200 -0
  51. sage/categories/sets_cat.py +3290 -0
  52. sage/categories/sets_with_partial_maps.py +52 -0
  53. sage/categories/subobjects.py +64 -0
  54. sage/categories/subquotients.py +21 -0
  55. sage/categories/with_realizations.py +311 -0
  56. sage/cpython/__init__.py +19 -0
  57. sage/cpython/_py2_random.py +619 -0
  58. sage/cpython/all.py +3 -0
  59. sage/cpython/atexit.cpython-314t-darwin.so +0 -0
  60. sage/cpython/atexit.pyx +269 -0
  61. sage/cpython/builtin_types.cpython-314t-darwin.so +0 -0
  62. sage/cpython/builtin_types.pyx +7 -0
  63. sage/cpython/cython_metaclass.cpython-314t-darwin.so +0 -0
  64. sage/cpython/cython_metaclass.h +117 -0
  65. sage/cpython/cython_metaclass.pxd +3 -0
  66. sage/cpython/cython_metaclass.pyx +130 -0
  67. sage/cpython/debug.cpython-314t-darwin.so +0 -0
  68. sage/cpython/debug.pyx +302 -0
  69. sage/cpython/dict_del_by_value.cpython-314t-darwin.so +0 -0
  70. sage/cpython/dict_del_by_value.pxd +9 -0
  71. sage/cpython/dict_del_by_value.pyx +191 -0
  72. sage/cpython/dict_internal.h +245 -0
  73. sage/cpython/getattr.cpython-314t-darwin.so +0 -0
  74. sage/cpython/getattr.pxd +9 -0
  75. sage/cpython/getattr.pyx +439 -0
  76. sage/cpython/pycore_long.h +97 -0
  77. sage/cpython/pycore_long.pxd +10 -0
  78. sage/cpython/python_debug.h +44 -0
  79. sage/cpython/python_debug.pxd +47 -0
  80. sage/cpython/pyx_visit.h +13 -0
  81. sage/cpython/string.cpython-314t-darwin.so +0 -0
  82. sage/cpython/string.pxd +76 -0
  83. sage/cpython/string.pyx +34 -0
  84. sage/cpython/string_impl.h +60 -0
  85. sage/cpython/type.cpython-314t-darwin.so +0 -0
  86. sage/cpython/type.pxd +2 -0
  87. sage/cpython/type.pyx +40 -0
  88. sage/cpython/wrapperdescr.pxd +67 -0
  89. sage/ext/all__sagemath_objects.py +3 -0
  90. sage/ext/ccobject.h +64 -0
  91. sage/ext/cplusplus.pxd +17 -0
  92. sage/ext/mod_int.h +30 -0
  93. sage/ext/mod_int.pxd +24 -0
  94. sage/ext/stdsage.pxd +39 -0
  95. sage/groups/all__sagemath_objects.py +1 -0
  96. sage/groups/group.cpython-314t-darwin.so +0 -0
  97. sage/groups/group.pxd +14 -0
  98. sage/groups/group.pyx +322 -0
  99. sage/groups/old.cpython-314t-darwin.so +0 -0
  100. sage/groups/old.pxd +14 -0
  101. sage/groups/old.pyx +219 -0
  102. sage/libs/all__sagemath_objects.py +3 -0
  103. sage/libs/gmp/__init__.py +1 -0
  104. sage/libs/gmp/all.pxd +6 -0
  105. sage/libs/gmp/binop.pxd +23 -0
  106. sage/libs/gmp/misc.pxd +8 -0
  107. sage/libs/gmp/mpf.pxd +88 -0
  108. sage/libs/gmp/mpn.pxd +57 -0
  109. sage/libs/gmp/mpq.pxd +57 -0
  110. sage/libs/gmp/mpz.pxd +202 -0
  111. sage/libs/gmp/pylong.cpython-314t-darwin.so +0 -0
  112. sage/libs/gmp/pylong.pxd +12 -0
  113. sage/libs/gmp/pylong.pyx +150 -0
  114. sage/libs/gmp/random.pxd +25 -0
  115. sage/libs/gmp/randomize.pxd +59 -0
  116. sage/libs/gmp/types.pxd +53 -0
  117. sage/libs/gmpxx.pxd +19 -0
  118. sage/misc/abstract_method.py +276 -0
  119. sage/misc/all__sagemath_objects.py +43 -0
  120. sage/misc/bindable_class.py +253 -0
  121. sage/misc/c3_controlled.cpython-314t-darwin.so +0 -0
  122. sage/misc/c3_controlled.pxd +2 -0
  123. sage/misc/c3_controlled.pyx +1402 -0
  124. sage/misc/cachefunc.cpython-314t-darwin.so +0 -0
  125. sage/misc/cachefunc.pxd +43 -0
  126. sage/misc/cachefunc.pyx +3781 -0
  127. sage/misc/call.py +188 -0
  128. sage/misc/classcall_metaclass.cpython-314t-darwin.so +0 -0
  129. sage/misc/classcall_metaclass.pxd +14 -0
  130. sage/misc/classcall_metaclass.pyx +599 -0
  131. sage/misc/constant_function.cpython-314t-darwin.so +0 -0
  132. sage/misc/constant_function.pyx +130 -0
  133. sage/misc/decorators.py +747 -0
  134. sage/misc/fast_methods.cpython-314t-darwin.so +0 -0
  135. sage/misc/fast_methods.pxd +20 -0
  136. sage/misc/fast_methods.pyx +351 -0
  137. sage/misc/flatten.py +90 -0
  138. sage/misc/fpickle.cpython-314t-darwin.so +0 -0
  139. sage/misc/fpickle.pyx +177 -0
  140. sage/misc/function_mangling.cpython-314t-darwin.so +0 -0
  141. sage/misc/function_mangling.pxd +11 -0
  142. sage/misc/function_mangling.pyx +308 -0
  143. sage/misc/inherit_comparison.cpython-314t-darwin.so +0 -0
  144. sage/misc/inherit_comparison.pxd +5 -0
  145. sage/misc/inherit_comparison.pyx +105 -0
  146. sage/misc/instancedoc.cpython-314t-darwin.so +0 -0
  147. sage/misc/instancedoc.pyx +331 -0
  148. sage/misc/lazy_attribute.cpython-314t-darwin.so +0 -0
  149. sage/misc/lazy_attribute.pyx +607 -0
  150. sage/misc/lazy_format.py +135 -0
  151. sage/misc/lazy_import.cpython-314t-darwin.so +0 -0
  152. sage/misc/lazy_import.pyx +1299 -0
  153. sage/misc/lazy_import_cache.py +36 -0
  154. sage/misc/lazy_list.cpython-314t-darwin.so +0 -0
  155. sage/misc/lazy_list.pxd +19 -0
  156. sage/misc/lazy_list.pyx +1187 -0
  157. sage/misc/lazy_string.cpython-314t-darwin.so +0 -0
  158. sage/misc/lazy_string.pxd +7 -0
  159. sage/misc/lazy_string.pyx +546 -0
  160. sage/misc/misc.py +1066 -0
  161. sage/misc/misc_c.cpython-314t-darwin.so +0 -0
  162. sage/misc/misc_c.pxd +3 -0
  163. sage/misc/misc_c.pyx +766 -0
  164. sage/misc/namespace_package.py +37 -0
  165. sage/misc/nested_class.cpython-314t-darwin.so +0 -0
  166. sage/misc/nested_class.pxd +3 -0
  167. sage/misc/nested_class.pyx +394 -0
  168. sage/misc/persist.cpython-314t-darwin.so +0 -0
  169. sage/misc/persist.pyx +1251 -0
  170. sage/misc/prandom.py +418 -0
  171. sage/misc/randstate.cpython-314t-darwin.so +0 -0
  172. sage/misc/randstate.pxd +30 -0
  173. sage/misc/randstate.pyx +1059 -0
  174. sage/misc/repr.py +203 -0
  175. sage/misc/reset.cpython-314t-darwin.so +0 -0
  176. sage/misc/reset.pyx +196 -0
  177. sage/misc/sage_ostools.cpython-314t-darwin.so +0 -0
  178. sage/misc/sage_ostools.pyx +323 -0
  179. sage/misc/sage_timeit.py +275 -0
  180. sage/misc/sage_timeit_class.cpython-314t-darwin.so +0 -0
  181. sage/misc/sage_timeit_class.pyx +120 -0
  182. sage/misc/sage_unittest.py +637 -0
  183. sage/misc/sageinspect.py +2768 -0
  184. sage/misc/session.cpython-314t-darwin.so +0 -0
  185. sage/misc/session.pyx +392 -0
  186. sage/misc/superseded.py +557 -0
  187. sage/misc/test_nested_class.py +228 -0
  188. sage/misc/timing.py +264 -0
  189. sage/misc/unknown.py +222 -0
  190. sage/misc/verbose.py +253 -0
  191. sage/misc/weak_dict.cpython-314t-darwin.so +0 -0
  192. sage/misc/weak_dict.pxd +15 -0
  193. sage/misc/weak_dict.pyx +1231 -0
  194. sage/modules/all__sagemath_objects.py +1 -0
  195. sage/modules/module.cpython-314t-darwin.so +0 -0
  196. sage/modules/module.pxd +5 -0
  197. sage/modules/module.pyx +329 -0
  198. sage/rings/all__sagemath_objects.py +3 -0
  199. sage/rings/integer_fake.h +22 -0
  200. sage/rings/integer_fake.pxd +55 -0
  201. sage/sets/all__sagemath_objects.py +3 -0
  202. sage/sets/pythonclass.cpython-314t-darwin.so +0 -0
  203. sage/sets/pythonclass.pxd +9 -0
  204. sage/sets/pythonclass.pyx +247 -0
  205. sage/structure/__init__.py +4 -0
  206. sage/structure/all.py +30 -0
  207. sage/structure/category_object.cpython-314t-darwin.so +0 -0
  208. sage/structure/category_object.pxd +28 -0
  209. sage/structure/category_object.pyx +1087 -0
  210. sage/structure/coerce.cpython-314t-darwin.so +0 -0
  211. sage/structure/coerce.pxd +44 -0
  212. sage/structure/coerce.pyx +2107 -0
  213. sage/structure/coerce_actions.cpython-314t-darwin.so +0 -0
  214. sage/structure/coerce_actions.pxd +27 -0
  215. sage/structure/coerce_actions.pyx +988 -0
  216. sage/structure/coerce_dict.cpython-314t-darwin.so +0 -0
  217. sage/structure/coerce_dict.pxd +51 -0
  218. sage/structure/coerce_dict.pyx +1557 -0
  219. sage/structure/coerce_exceptions.py +23 -0
  220. sage/structure/coerce_maps.cpython-314t-darwin.so +0 -0
  221. sage/structure/coerce_maps.pxd +28 -0
  222. sage/structure/coerce_maps.pyx +718 -0
  223. sage/structure/debug_options.cpython-314t-darwin.so +0 -0
  224. sage/structure/debug_options.pxd +6 -0
  225. sage/structure/debug_options.pyx +54 -0
  226. sage/structure/dynamic_class.py +541 -0
  227. sage/structure/element.cpython-314t-darwin.so +0 -0
  228. sage/structure/element.pxd +272 -0
  229. sage/structure/element.pyx +4772 -0
  230. sage/structure/element_wrapper.cpython-314t-darwin.so +0 -0
  231. sage/structure/element_wrapper.pxd +12 -0
  232. sage/structure/element_wrapper.pyx +582 -0
  233. sage/structure/factorization.py +1422 -0
  234. sage/structure/factorization_integer.py +105 -0
  235. sage/structure/factory.cpython-314t-darwin.so +0 -0
  236. sage/structure/factory.pyx +786 -0
  237. sage/structure/formal_sum.py +489 -0
  238. sage/structure/gens_py.py +73 -0
  239. sage/structure/global_options.py +1743 -0
  240. sage/structure/indexed_generators.py +863 -0
  241. sage/structure/list_clone.cpython-314t-darwin.so +0 -0
  242. sage/structure/list_clone.pxd +65 -0
  243. sage/structure/list_clone.pyx +1867 -0
  244. sage/structure/list_clone_demo.cpython-314t-darwin.so +0 -0
  245. sage/structure/list_clone_demo.pyx +248 -0
  246. sage/structure/list_clone_timings.py +179 -0
  247. sage/structure/list_clone_timings_cy.cpython-314t-darwin.so +0 -0
  248. sage/structure/list_clone_timings_cy.pyx +86 -0
  249. sage/structure/mutability.cpython-314t-darwin.so +0 -0
  250. sage/structure/mutability.pxd +21 -0
  251. sage/structure/mutability.pyx +348 -0
  252. sage/structure/nonexact.py +69 -0
  253. sage/structure/parent.cpython-314t-darwin.so +0 -0
  254. sage/structure/parent.pxd +112 -0
  255. sage/structure/parent.pyx +3093 -0
  256. sage/structure/parent_base.cpython-314t-darwin.so +0 -0
  257. sage/structure/parent_base.pxd +13 -0
  258. sage/structure/parent_base.pyx +44 -0
  259. sage/structure/parent_gens.cpython-314t-darwin.so +0 -0
  260. sage/structure/parent_gens.pxd +22 -0
  261. sage/structure/parent_gens.pyx +377 -0
  262. sage/structure/parent_old.cpython-314t-darwin.so +0 -0
  263. sage/structure/parent_old.pxd +25 -0
  264. sage/structure/parent_old.pyx +294 -0
  265. sage/structure/proof/__init__.py +1 -0
  266. sage/structure/proof/all.py +243 -0
  267. sage/structure/proof/proof.py +300 -0
  268. sage/structure/richcmp.cpython-314t-darwin.so +0 -0
  269. sage/structure/richcmp.pxd +213 -0
  270. sage/structure/richcmp.pyx +495 -0
  271. sage/structure/sage_object.cpython-314t-darwin.so +0 -0
  272. sage/structure/sage_object.pxd +3 -0
  273. sage/structure/sage_object.pyx +988 -0
  274. sage/structure/sage_object_test.py +19 -0
  275. sage/structure/sequence.py +937 -0
  276. sage/structure/set_factories.py +1178 -0
  277. sage/structure/set_factories_example.py +527 -0
  278. sage/structure/support_view.py +179 -0
  279. sage/structure/test_factory.py +56 -0
  280. sage/structure/unique_representation.py +1359 -0
@@ -0,0 +1,228 @@
1
+ # sage_setup: distribution = sagemath-objects
2
+ """
3
+ Test for nested class Parent
4
+
5
+ This file contains a discussion, examples, and tests about nested
6
+ classes and parents. It is kept in a separate file to avoid import
7
+ loops.
8
+
9
+ EXAMPLES:
10
+
11
+ Currently pickling fails for parents using nested classes (typically
12
+ for categories), but deriving only from Parent::
13
+
14
+ sage: from sage.misc.test_nested_class import TestParent1, TestParent2, TestParent3, TestParent4
15
+ sage: P = TestParent1()
16
+ sage: TestSuite(P).run()
17
+ Failure ...
18
+ The following tests failed: _test_elements, _test_pickling
19
+
20
+ They actually need to be in the NestedClassMetaclass. However, due to
21
+ a technical detail, this is currently not directly supported::
22
+
23
+ sage: P = TestParent2()
24
+ Traceback (most recent call last):
25
+ ...
26
+ TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
27
+ sage: TestSuite(P).run() # not tested
28
+
29
+ Instead, the easiest is to inherit from UniqueRepresentation, which is
30
+ what you want to do anyway most of the time::
31
+
32
+ sage: P = TestParent3()
33
+ sage: TestSuite(P).run()
34
+
35
+ This is what all Sage's parents using categories currently do. An
36
+ alternative is to use ClasscallMetaclass as metaclass::
37
+
38
+ sage: P = TestParent4()
39
+ sage: TestSuite(P).run()
40
+ """
41
+ # *****************************************************************************
42
+ # Copyright (C) 2009 Nicolas M. Thiery <nthiery at users.sf.net>
43
+ #
44
+ # Distributed under the terms of the GNU General Public License (GPL)
45
+ # http://www.gnu.org/licenses/
46
+ # ******************************************************************************
47
+
48
+ __all__ = [] # Don't document any parents
49
+
50
+ from sage.structure.parent import Parent
51
+ from sage.structure.element_wrapper import ElementWrapper
52
+ from sage.structure.unique_representation import UniqueRepresentation
53
+ from sage.misc.classcall_metaclass import ClasscallMetaclass
54
+ from sage.misc.nested_class import NestedClassMetaclass
55
+
56
+
57
+ class TestParent1(Parent):
58
+ def __init__(self):
59
+ """
60
+ EXAMPLES::
61
+
62
+ sage: sage.misc.test_nested_class.TestParent1()
63
+ <sage.misc.test_nested_class.TestParent1_with_category object at ...>
64
+ """
65
+ from sage.categories.sets_cat import Sets
66
+ Parent.__init__(self, category=Sets())
67
+
68
+ class Element(ElementWrapper):
69
+ pass
70
+
71
+
72
+ class TestParent2(Parent, metaclass=NestedClassMetaclass):
73
+ def __init__(self):
74
+ """
75
+ EXAMPLES::
76
+
77
+ sage: sage.misc.test_nested_class.TestParent2()
78
+ Traceback (most recent call last):
79
+ ...
80
+ TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
81
+ """
82
+ from sage.categories.sets_cat import Sets
83
+ Parent.__init__(self, category=Sets())
84
+
85
+ class Element(ElementWrapper):
86
+ pass
87
+
88
+
89
+ class TestParent3(UniqueRepresentation, Parent):
90
+
91
+ def __init__(self):
92
+ """
93
+ EXAMPLES::
94
+
95
+ sage: sage.misc.test_nested_class.TestParent3()
96
+ <sage.misc.test_nested_class.TestParent3_with_category object at ...>
97
+ """
98
+ from sage.categories.sets_cat import Sets
99
+ Parent.__init__(self, category=Sets())
100
+
101
+ class Element(ElementWrapper):
102
+ pass
103
+
104
+
105
+ class TestParent4(Parent, metaclass=ClasscallMetaclass):
106
+ def __init__(self):
107
+ """
108
+ EXAMPLES::
109
+
110
+ sage: sage.misc.test_nested_class.TestParent4()
111
+ <sage.misc.test_nested_class.TestParent4_with_category object at ...>
112
+ """
113
+ from sage.categories.sets_cat import Sets
114
+ Parent.__init__(self, category=Sets())
115
+
116
+ def __eq__(self, other):
117
+ """
118
+ EXAMPLES::
119
+
120
+ sage: from sage.misc.test_nested_class import TestParent4
121
+ sage: TestParent4() == TestParent4()
122
+ True
123
+ """
124
+ return self.__class__ == other.__class__
125
+
126
+ def __ne__(self, other):
127
+ """
128
+ EXAMPLES::
129
+
130
+ sage: from sage.misc.test_nested_class import TestParent4
131
+ sage: TestParent4() != TestParent4()
132
+ False
133
+ """
134
+ return self.__class__ != other.__class__
135
+
136
+ def __hash__(self):
137
+ """
138
+ Return the hash of ``self``.
139
+
140
+ EXAMPLES::
141
+
142
+ sage: from sage.misc.test_nested_class import TestParent4
143
+ sage: hash(TestParent4()) == hash(TestParent4())
144
+ True
145
+ """
146
+ return hash(8960522744683456048)
147
+
148
+ class Element(ElementWrapper):
149
+ pass
150
+
151
+
152
+ # Class for tests:
153
+ class B:
154
+ """
155
+ A normal external class.
156
+ """
157
+ pass
158
+
159
+
160
+ class ABB:
161
+ class B:
162
+ """
163
+ This class is broken and cannot be pickled.
164
+ A warning is emitted during compilation.
165
+ """
166
+ pass
167
+
168
+
169
+ class ABL:
170
+ """
171
+ There is no problem here.
172
+ """
173
+ B = B
174
+
175
+
176
+ class ALB:
177
+ """
178
+ There is a nested class just below. Which can't be properly sphinxed.
179
+ """
180
+ class C:
181
+ """
182
+ Internal C class.
183
+
184
+ Thanks to the links below this class is pickled ok.
185
+ But it is sphinxed wrong: It is typeset as a link to an outer class.
186
+ """
187
+ pass
188
+
189
+
190
+ C = ALB.C
191
+
192
+
193
+ class ABBMeta(metaclass=NestedClassMetaclass):
194
+ class B:
195
+ """
196
+ B interne
197
+ """
198
+ pass
199
+
200
+
201
+ class ABLMeta(metaclass=NestedClassMetaclass):
202
+ B = B
203
+
204
+
205
+ class ALBMeta(metaclass=NestedClassMetaclass):
206
+ """
207
+ There is a nested class just below which is properly sphinxed.
208
+ """
209
+ class CMeta:
210
+ """
211
+ B interne
212
+ """
213
+ pass
214
+
215
+
216
+ CMeta = ALBMeta.CMeta
217
+
218
+
219
+ class TestNestedParent(UniqueRepresentation, Parent):
220
+ """
221
+ This is a dummy for testing source inspection of nested classes.
222
+
223
+ See the test in ``sage.misc.sageinspect.sage_getsourcelines``.
224
+ """
225
+
226
+ class Element:
227
+ "This is a dummy element class"
228
+ pass
sage/misc/timing.py ADDED
@@ -0,0 +1,264 @@
1
+ # pyright: strict
2
+ # sage_setup: distribution = sagemath-objects
3
+ r"""
4
+ Timing functions
5
+ """
6
+
7
+ # ****************************************************************************
8
+ # Copyright (C) 2006 William Stein <wstein@gmail.com>
9
+ # 2006 Gonzalo Tornaria
10
+ # 2008 Martin Albrecht
11
+ # 2009 Mike Hansen
12
+ # 2018 Frédéric Chapoton
13
+ #
14
+ # This program is free software: you can redistribute it and/or modify
15
+ # it under the terms of the GNU General Public License as published by
16
+ # the Free Software Foundation, either version 2 of the License, or
17
+ # (at your option) any later version.
18
+ # https://www.gnu.org/licenses/
19
+ # ****************************************************************************
20
+
21
+ from __future__ import annotations
22
+
23
+ import time
24
+ from typing import TYPE_CHECKING, overload
25
+
26
+ if TYPE_CHECKING:
27
+ from weakref import ReferenceType
28
+
29
+ from sage.interfaces.expect import Expect
30
+
31
+
32
+ @overload
33
+ def cputime(t: float = 0, subprocesses: bool = False) -> float: ...
34
+ @overload
35
+ def cputime(t: GlobalCputime, subprocesses: bool) -> GlobalCputime: ...
36
+
37
+
38
+ def cputime(
39
+ t: float | GlobalCputime = 0, subprocesses: bool = False
40
+ ) -> float | GlobalCputime:
41
+ """
42
+ Return the time in CPU seconds since Sage started, or with
43
+ optional argument ``t``, return the time since ``t``. This is how
44
+ much time Sage has spent using the CPU (to be precise, the sum of the system
45
+ and user CPU times of the process). If ``subprocesses=False``
46
+ this does not count time spent in subprocesses spawned by Sage
47
+ (e.g., Gap, Singular, etc.). If ``subprocesses=True`` this
48
+ function tries to take all subprocesses with a working
49
+ ``cputime()`` implementation into account.
50
+
51
+ INPUT:
52
+
53
+ - ``t`` -- (optional) time in CPU seconds, if ``t`` is a result
54
+ from an earlier call with ``subprocesses=True``, then
55
+ ``subprocesses=True`` is assumed.
56
+
57
+ - ``subprocesses`` -- boolean (default: ``False``); include subprocesses
58
+
59
+ OUTPUT:
60
+
61
+ - ``float`` -- time in CPU seconds if ``subprocesses=False``
62
+
63
+ - :class:`GlobalCputime` -- object which holds CPU times of
64
+ subprocesses otherwise
65
+
66
+ EXAMPLES::
67
+
68
+ sage: t = cputime()
69
+ sage: F = gp.factor(2^199-1) # needs sage.libs.pari
70
+ sage: cputime(t) # somewhat random
71
+ 0.010999000000000092
72
+
73
+ sage: t = cputime(subprocesses=True)
74
+ sage: F = gp.factor(2^199-1) # needs sage.libs.pari
75
+ sage: cputime(t) # somewhat random
76
+ 0.091999
77
+
78
+ sage: w = walltime()
79
+ sage: F = gp.factor(2^199-1) # needs sage.libs.pari
80
+ sage: walltime(w) # somewhat random
81
+ 0.58425593376159668
82
+
83
+ .. NOTE::
84
+
85
+ Even with ``subprocesses=True`` there is no guarantee that the
86
+ CPU time is reported correctly because subprocesses can be
87
+ started and terminated at any given time.
88
+ """
89
+ try:
90
+ import resource # type: ignore
91
+ except ImportError:
92
+ # The module 'resource' is removed in Pyodide to browser limitations.
93
+ if isinstance(t, GlobalCputime):
94
+ t = float(t)
95
+ return walltime(t)
96
+
97
+ if isinstance(t, GlobalCputime):
98
+ subprocesses = True
99
+
100
+ if not subprocesses:
101
+ try:
102
+ t = float(t)
103
+ except TypeError:
104
+ t = 0.0
105
+ return time.process_time() - t
106
+
107
+ try:
108
+ from sage.interfaces.quit import expect_objects
109
+ except ImportError:
110
+ expect_objects = ()
111
+
112
+ if t == 0:
113
+ ret = GlobalCputime(cputime())
114
+ for reference in expect_objects:
115
+ process = reference()
116
+ if process and process.is_running():
117
+ try:
118
+ ct = process.cputime()
119
+ ret.total += ct
120
+ ret.interfaces[reference] = ct
121
+ except NotImplementedError:
122
+ pass
123
+ return ret
124
+
125
+ if not isinstance(t, GlobalCputime):
126
+ t = GlobalCputime(t)
127
+ ret = GlobalCputime(cputime() - t.local)
128
+ for reference in expect_objects:
129
+ process = reference()
130
+ if process and process.is_running():
131
+ try:
132
+ ct = process.cputime() - t.interfaces.get(reference, 0.0)
133
+ ret.total += ct
134
+ ret.interfaces[reference] = ct
135
+ except NotImplementedError:
136
+ pass
137
+ return ret
138
+
139
+
140
+ class GlobalCputime:
141
+ """
142
+ Container for CPU times of subprocesses.
143
+
144
+ AUTHOR:
145
+
146
+ - Martin Albrecht - (2008-12): initial version
147
+
148
+ EXAMPLES:
149
+
150
+ Objects of this type are returned if ``subprocesses=True`` is
151
+ passed to :func:`cputime`::
152
+
153
+ sage: cputime(subprocesses=True) # indirect doctest, output random
154
+ 0.2347431
155
+
156
+ We can use it to keep track of the CPU time spent in Singular for
157
+ example::
158
+
159
+ sage: t = cputime(subprocesses=True)
160
+ sage: P = PolynomialRing(QQ,7,'x')
161
+ sage: I = sage.rings.ideal.Katsura(P) # needs sage.libs.singular
162
+ sage: gb = I.groebner_basis() # calls Singular # needs sage.libs.singular
163
+ sage: cputime(subprocesses=True) - t # output random
164
+ 0.462987
165
+
166
+ For further processing we can then convert this container to a
167
+ float::
168
+
169
+ sage: t = cputime(subprocesses=True)
170
+ sage: float(t) # output somewhat random
171
+ 2.1088339999999999
172
+
173
+ .. SEEALSO::
174
+
175
+ :func:`cputime`
176
+ """
177
+
178
+ def __init__(self, t: float) -> None:
179
+ """
180
+ Create a new CPU time object which also keeps track of
181
+ subprocesses.
182
+
183
+ EXAMPLES::
184
+
185
+ sage: from sage.misc.timing import GlobalCputime
186
+ sage: ct = GlobalCputime(0.0); ct
187
+ 0.0...
188
+ """
189
+ self.total: float = t
190
+ self.local: float = t
191
+ self.interfaces: dict[ReferenceType[Expect], float] = {}
192
+
193
+ def __repr__(self) -> str:
194
+ """
195
+ EXAMPLES::
196
+
197
+ sage: cputime(subprocesses=True) # indirect doctest, output random
198
+ 0.2347431
199
+ """
200
+ return str(self.total)
201
+
202
+ def __add__(self, other: GlobalCputime | float) -> GlobalCputime:
203
+ """
204
+ EXAMPLES::
205
+
206
+ sage: t = cputime(subprocesses=True)
207
+ sage: P = PolynomialRing(QQ,7,'x')
208
+ sage: I = sage.rings.ideal.Katsura(P) # needs sage.libs.singular
209
+ sage: gb = I.groebner_basis() # calls Singular # needs sage.libs.singular
210
+ sage: cputime(subprocesses=True) + t # output random
211
+ 2.798708
212
+ """
213
+ if not isinstance(other, GlobalCputime):
214
+ other = GlobalCputime(other)
215
+ ret = GlobalCputime(self.total + other.total)
216
+ return ret
217
+
218
+ def __sub__(self, other: GlobalCputime | float) -> GlobalCputime:
219
+ """
220
+ EXAMPLES::
221
+
222
+ sage: t = cputime(subprocesses=True)
223
+ sage: P = PolynomialRing(QQ,7,'x')
224
+ sage: I = sage.rings.ideal.Katsura(P) # needs sage.libs.singular
225
+ sage: gb = I.groebner_basis() # calls Singular # needs sage.libs.singular
226
+ sage: cputime(subprocesses=True) - t # output random
227
+ 0.462987
228
+ """
229
+ if not isinstance(other, GlobalCputime):
230
+ other = GlobalCputime(other)
231
+ ret = GlobalCputime(self.total - other.total)
232
+ return ret
233
+
234
+ def __float__(self) -> float:
235
+ """
236
+ EXAMPLES::
237
+
238
+ sage: t = cputime(subprocesses=True)
239
+ sage: float(t) # output somewhat random
240
+ 2.1088339999999999
241
+ """
242
+ return float(self.total)
243
+
244
+
245
+ def walltime(t: float = 0) -> float:
246
+ """
247
+ Return the wall time in second, or with optional argument ``t``, return
248
+ the wall time since time ``t``. "Wall time" means the time on a wall
249
+ clock, i.e., the actual time.
250
+
251
+ INPUT:
252
+
253
+ - ``t`` -- (optional) float, time in CPU seconds
254
+
255
+ OUTPUT: ``float`` -- time in seconds
256
+
257
+ EXAMPLES::
258
+
259
+ sage: w = walltime()
260
+ sage: F = factor(2^199-1) # needs sage.libs.pari
261
+ sage: walltime(w) # somewhat random
262
+ 0.8823847770690918
263
+ """
264
+ return time.time() - t
sage/misc/unknown.py ADDED
@@ -0,0 +1,222 @@
1
+ # sage_setup: distribution = sagemath-objects
2
+ """
3
+ The Unknown truth value
4
+
5
+ The ``Unknown`` object is used in Sage in several places as return value
6
+ in addition to ``True`` and ``False``, in order to signal uncertainty
7
+ about or inability to compute the result. ``Unknown`` can be identified
8
+ using ``is``, or by catching :exc:`UnknownError` from a boolean operation.
9
+
10
+ .. WARNING::
11
+
12
+ Calling ``bool()`` with ``Unknown`` as argument will throw an
13
+ :exc:`UnknownError`. This also means that in the following cases,
14
+ ``and``, ``not``, and ``or`` fail or return a somewhat wrong value::
15
+
16
+ sage: not Unknown # should return Unknown
17
+ Traceback (most recent call last):
18
+ ...
19
+ UnknownError: Unknown does not evaluate in boolean context
20
+ sage: Unknown and False # should return False
21
+ Traceback (most recent call last):
22
+ ...
23
+ UnknownError: Unknown does not evaluate in boolean context
24
+ sage: Unknown or False # should return Unknown
25
+ Traceback (most recent call last):
26
+ ...
27
+ UnknownError: Unknown does not evaluate in boolean context
28
+
29
+ EXAMPLES::
30
+
31
+ sage: def func(n):
32
+ ....: if n > 0:
33
+ ....: return True
34
+ ....: elif n < 0:
35
+ ....: return False
36
+ ....: else:
37
+ ....: return Unknown
38
+
39
+ Using direct identification::
40
+
41
+ sage: for n in [-3, 0, 12]:
42
+ ....: res = func(n)
43
+ ....: if res is True:
44
+ ....: print("n={} is positive".format(n))
45
+ ....: elif res is False:
46
+ ....: print("n={} is negative".format(n))
47
+ ....: else:
48
+ ....: print("n={} is neither positive nor negative".format(n))
49
+ n=-3 is negative
50
+ n=0 is neither positive nor negative
51
+ n=12 is positive
52
+
53
+ Using :exc:`UnknownError`::
54
+
55
+ sage: for n in [-3, 0, 12]:
56
+ ....: try:
57
+ ....: if func(n):
58
+ ....: print("n={} is positive".format(n))
59
+ ....: else:
60
+ ....: print("n={} is negative".format(n))
61
+ ....: except UnknownError:
62
+ ....: print("n={} is neither positive nor negative".format(n))
63
+ n=-3 is negative
64
+ n=0 is neither positive nor negative
65
+ n=12 is positive
66
+
67
+ AUTHORS:
68
+
69
+ - Florent Hivert (2010): initial version.
70
+ - Ralf Stephan, Vincent Delecroix (2018-2020): redesign
71
+ """
72
+ # ****************************************************************************
73
+ # Copyright (C) 2010 Florent Hivert <florent.hivert at lri.fr>
74
+ # 2018-2020 Ralf Stefan
75
+ # 2018-2020 Vincent Delecroix <20100.delecroix@gmail.com>
76
+ #
77
+ # Distributed under the terms of the GNU General Public License (GPL)
78
+ # as published by the Free Software Foundation; either version 2 of
79
+ # the License, or (at your option) any later version.
80
+ # https://www.gnu.org/licenses/
81
+ # ****************************************************************************
82
+
83
+
84
+ from sage.structure.unique_representation import UniqueRepresentation
85
+ from sage.structure.richcmp import richcmp_method, rich_to_bool
86
+
87
+
88
+ class UnknownError(TypeError):
89
+ """
90
+ Raised whenever :class:`Unknown` is used in a boolean operation.
91
+
92
+ EXAMPLES::
93
+
94
+ sage: not Unknown
95
+ Traceback (most recent call last):
96
+ ...
97
+ UnknownError: Unknown does not evaluate in boolean context
98
+ """
99
+ pass
100
+
101
+
102
+ @richcmp_method
103
+ class UnknownClass(UniqueRepresentation):
104
+ """
105
+ The Unknown truth value.
106
+
107
+ The ``Unknown`` object is used in Sage in several places as return value
108
+ in addition to ``True`` and ``False``, in order to signal uncertainty
109
+ about or inability to compute the result. ``Unknown`` can be identified
110
+ using ``is``, or by catching :exc:`UnknownError` from a boolean
111
+ operation.
112
+
113
+ .. WARNING::
114
+
115
+ Calling ``bool()`` with ``Unknown`` as argument will throw an
116
+ :exc:`UnknownError`. This also means that applying ``and``, ``not``,
117
+ and ``or`` to ``Unknown`` might fail.
118
+
119
+ TESTS::
120
+
121
+ sage: TestSuite(Unknown).run()
122
+ """
123
+ def __repr__(self):
124
+ """
125
+ TESTS::
126
+
127
+ sage: Unknown
128
+ Unknown
129
+ """
130
+ return "Unknown"
131
+
132
+ def __bool__(self):
133
+ """
134
+ When evaluated in a boolean context ``Unknown`` raises a :exc:`UnknownError`.
135
+
136
+ EXAMPLES::
137
+
138
+ sage: bool(Unknown)
139
+ Traceback (most recent call last):
140
+ ...
141
+ UnknownError: Unknown does not evaluate in boolean context
142
+ sage: not Unknown
143
+ Traceback (most recent call last):
144
+ ...
145
+ UnknownError: Unknown does not evaluate in boolean context
146
+ """
147
+ raise UnknownError('Unknown does not evaluate in boolean context')
148
+
149
+ def __and__(self, other):
150
+ """
151
+ The ``&`` logical operation.
152
+
153
+ EXAMPLES::
154
+
155
+ sage: Unknown & False
156
+ False
157
+ sage: Unknown & Unknown
158
+ Unknown
159
+ sage: Unknown & True
160
+ Unknown
161
+
162
+ sage: Unknown.__or__(3)
163
+ NotImplemented
164
+ """
165
+ if other is False:
166
+ return False
167
+ elif other is True or other is Unknown:
168
+ return self
169
+ else:
170
+ return NotImplemented
171
+
172
+ def __or__(self, other):
173
+ """
174
+ The ``|`` logical connector.
175
+
176
+ EXAMPLES::
177
+
178
+ sage: Unknown | False
179
+ Unknown
180
+ sage: Unknown | Unknown
181
+ Unknown
182
+ sage: Unknown | True
183
+ True
184
+
185
+ sage: Unknown.__or__(3)
186
+ NotImplemented
187
+ """
188
+ if other is True:
189
+ return True
190
+ elif other is False or other is Unknown:
191
+ return self
192
+ else:
193
+ return NotImplemented
194
+
195
+ def __richcmp__(self, other, op):
196
+ """
197
+ Comparison of truth value.
198
+
199
+ EXAMPLES::
200
+
201
+ sage: l = [False, Unknown, True]
202
+ sage: for a in l: print([a < b for b in l])
203
+ [False, True, True]
204
+ [False, False, True]
205
+ [False, False, False]
206
+
207
+ sage: for a in l: print([a <= b for b in l])
208
+ [True, True, True]
209
+ [False, True, True]
210
+ [False, False, True]
211
+ """
212
+ if other is self:
213
+ return rich_to_bool(op, 0)
214
+ if not isinstance(other, bool):
215
+ return NotImplemented
216
+ if other:
217
+ return rich_to_bool(op, -1)
218
+ else:
219
+ return rich_to_bool(op, +1)
220
+
221
+
222
+ Unknown = UnknownClass()