passagemath-objects 10.8.1a3__cp314-cp314-win_amd64.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.
- passagemath_objects/__init__.py +3 -0
- passagemath_objects-10.8.1a3.dist-info/DELVEWHEEL +2 -0
- passagemath_objects-10.8.1a3.dist-info/METADATA +114 -0
- passagemath_objects-10.8.1a3.dist-info/RECORD +283 -0
- passagemath_objects-10.8.1a3.dist-info/WHEEL +5 -0
- passagemath_objects-10.8.1a3.dist-info/top_level.txt +3 -0
- passagemath_objects.libs/libgmp-10-60021eeab4282b29024e43b2b1412b53.dll +0 -0
- sage/all__sagemath_objects.py +46 -0
- sage/arith/all__sagemath_objects.py +5 -0
- sage/arith/long.pxd +411 -0
- sage/arith/numerical_approx.cp314-win_amd64.pyd +0 -0
- sage/arith/numerical_approx.pxd +35 -0
- sage/arith/numerical_approx.pyx +75 -0
- sage/arith/power.cp314-win_amd64.pyd +0 -0
- sage/arith/power.pxd +31 -0
- sage/arith/power.pyx +127 -0
- sage/categories/action.cp314-win_amd64.pyd +0 -0
- sage/categories/action.pxd +29 -0
- sage/categories/action.pyx +641 -0
- sage/categories/algebra_functor.py +745 -0
- sage/categories/all__sagemath_objects.py +33 -0
- sage/categories/basic.py +71 -0
- sage/categories/cartesian_product.py +292 -0
- sage/categories/category.py +3379 -0
- sage/categories/category_cy_helper.cp314-win_amd64.pyd +0 -0
- sage/categories/category_cy_helper.pxd +8 -0
- sage/categories/category_cy_helper.pyx +322 -0
- sage/categories/category_singleton.cp314-win_amd64.pyd +0 -0
- sage/categories/category_singleton.pxd +3 -0
- sage/categories/category_singleton.pyx +343 -0
- sage/categories/category_types.py +637 -0
- sage/categories/category_with_axiom.py +2889 -0
- sage/categories/covariant_functorial_construction.py +700 -0
- sage/categories/facade_sets.py +228 -0
- sage/categories/functor.cp314-win_amd64.pyd +0 -0
- sage/categories/functor.pxd +7 -0
- sage/categories/functor.pyx +659 -0
- sage/categories/homset.py +1289 -0
- sage/categories/homsets.py +364 -0
- sage/categories/isomorphic_objects.py +73 -0
- sage/categories/map.cp314-win_amd64.pyd +0 -0
- sage/categories/map.pxd +34 -0
- sage/categories/map.pyx +2106 -0
- sage/categories/morphism.cp314-win_amd64.pyd +0 -0
- sage/categories/morphism.pxd +14 -0
- sage/categories/morphism.pyx +895 -0
- sage/categories/objects.py +167 -0
- sage/categories/primer.py +1695 -0
- sage/categories/pushout.py +4847 -0
- sage/categories/quotients.py +64 -0
- sage/categories/realizations.py +200 -0
- sage/categories/sets_cat.py +3305 -0
- sage/categories/sets_with_partial_maps.py +52 -0
- sage/categories/subobjects.py +64 -0
- sage/categories/subquotients.py +21 -0
- sage/categories/with_realizations.py +311 -0
- sage/cpython/__init__.py +22 -0
- sage/cpython/_py2_random.py +619 -0
- sage/cpython/all.py +3 -0
- sage/cpython/atexit.cp314-win_amd64.pyd +0 -0
- sage/cpython/atexit.pyx +269 -0
- sage/cpython/builtin_types.cp314-win_amd64.pyd +0 -0
- sage/cpython/builtin_types.pyx +7 -0
- sage/cpython/cython_metaclass.cp314-win_amd64.pyd +0 -0
- sage/cpython/cython_metaclass.h +117 -0
- sage/cpython/cython_metaclass.pxd +3 -0
- sage/cpython/cython_metaclass.pyx +130 -0
- sage/cpython/debug.cp314-win_amd64.pyd +0 -0
- sage/cpython/debug.pyx +302 -0
- sage/cpython/dict_del_by_value.cp314-win_amd64.pyd +0 -0
- sage/cpython/dict_del_by_value.pxd +9 -0
- sage/cpython/dict_del_by_value.pyx +191 -0
- sage/cpython/dict_internal.h +80 -0
- sage/cpython/getattr.cp314-win_amd64.pyd +0 -0
- sage/cpython/getattr.pxd +9 -0
- sage/cpython/getattr.pyx +439 -0
- sage/cpython/pycore_long.h +97 -0
- sage/cpython/pycore_long.pxd +10 -0
- sage/cpython/python_debug.h +44 -0
- sage/cpython/python_debug.pxd +47 -0
- sage/cpython/pyx_visit.h +13 -0
- sage/cpython/string.cp314-win_amd64.pyd +0 -0
- sage/cpython/string.pxd +76 -0
- sage/cpython/string.pyx +34 -0
- sage/cpython/string_impl.h +60 -0
- sage/cpython/type.cp314-win_amd64.pyd +0 -0
- sage/cpython/type.pxd +2 -0
- sage/cpython/type.pyx +40 -0
- sage/cpython/wrapperdescr.pxd +67 -0
- sage/ext/all__sagemath_objects.py +3 -0
- sage/ext/ccobject.h +64 -0
- sage/ext/cplusplus.pxd +17 -0
- sage/ext/mod_int.h +30 -0
- sage/ext/mod_int.pxd +24 -0
- sage/ext/stdsage.pxd +39 -0
- sage/groups/all__sagemath_objects.py +1 -0
- sage/groups/group.cp314-win_amd64.pyd +0 -0
- sage/groups/group.pxd +14 -0
- sage/groups/group.pyx +296 -0
- sage/groups/old.cp314-win_amd64.pyd +0 -0
- sage/groups/old.pxd +14 -0
- sage/groups/old.pyx +219 -0
- sage/libs/all__sagemath_objects.py +3 -0
- sage/libs/gmp/__init__.py +1 -0
- sage/libs/gmp/all.pxd +6 -0
- sage/libs/gmp/binop.pxd +23 -0
- sage/libs/gmp/misc.pxd +8 -0
- sage/libs/gmp/mpf.pxd +88 -0
- sage/libs/gmp/mpn.pxd +57 -0
- sage/libs/gmp/mpq.pxd +57 -0
- sage/libs/gmp/mpz.pxd +202 -0
- sage/libs/gmp/pylong.cp314-win_amd64.pyd +0 -0
- sage/libs/gmp/pylong.pxd +12 -0
- sage/libs/gmp/pylong.pyx +150 -0
- sage/libs/gmp/random.pxd +25 -0
- sage/libs/gmp/randomize.pxd +59 -0
- sage/libs/gmp/types.pxd +53 -0
- sage/libs/gmpxx.pxd +19 -0
- sage/misc/abstract_method.py +276 -0
- sage/misc/all__sagemath_objects.py +43 -0
- sage/misc/bindable_class.py +253 -0
- sage/misc/c3_controlled.cp314-win_amd64.pyd +0 -0
- sage/misc/c3_controlled.pxd +2 -0
- sage/misc/c3_controlled.pyx +1402 -0
- sage/misc/cachefunc.cp314-win_amd64.pyd +0 -0
- sage/misc/cachefunc.pxd +43 -0
- sage/misc/cachefunc.pyx +3801 -0
- sage/misc/call.py +188 -0
- sage/misc/classcall_metaclass.cp314-win_amd64.pyd +0 -0
- sage/misc/classcall_metaclass.pxd +14 -0
- sage/misc/classcall_metaclass.pyx +599 -0
- sage/misc/constant_function.cp314-win_amd64.pyd +0 -0
- sage/misc/constant_function.pyx +130 -0
- sage/misc/decorators.py +739 -0
- sage/misc/fast_methods.cp314-win_amd64.pyd +0 -0
- sage/misc/fast_methods.pxd +20 -0
- sage/misc/fast_methods.pyx +351 -0
- sage/misc/flatten.py +90 -0
- sage/misc/fpickle.cp314-win_amd64.pyd +0 -0
- sage/misc/fpickle.pyx +176 -0
- sage/misc/function_mangling.cp314-win_amd64.pyd +0 -0
- sage/misc/function_mangling.pxd +11 -0
- sage/misc/function_mangling.pyx +308 -0
- sage/misc/inherit_comparison.cp314-win_amd64.pyd +0 -0
- sage/misc/inherit_comparison.pxd +5 -0
- sage/misc/inherit_comparison.pyx +105 -0
- sage/misc/instancedoc.cp314-win_amd64.pyd +0 -0
- sage/misc/instancedoc.pyx +331 -0
- sage/misc/lazy_attribute.cp314-win_amd64.pyd +0 -0
- sage/misc/lazy_attribute.pyx +607 -0
- sage/misc/lazy_format.py +132 -0
- sage/misc/lazy_import.cp314-win_amd64.pyd +0 -0
- sage/misc/lazy_import.pxd +13 -0
- sage/misc/lazy_import.pyx +1307 -0
- sage/misc/lazy_import_cache.py +36 -0
- sage/misc/lazy_list.cp314-win_amd64.pyd +0 -0
- sage/misc/lazy_list.pxd +19 -0
- sage/misc/lazy_list.pyx +1187 -0
- sage/misc/lazy_string.cp314-win_amd64.pyd +0 -0
- sage/misc/lazy_string.pxd +7 -0
- sage/misc/lazy_string.pyx +546 -0
- sage/misc/misc.py +980 -0
- sage/misc/misc_c.cp314-win_amd64.pyd +0 -0
- sage/misc/misc_c.pxd +3 -0
- sage/misc/misc_c.pyx +765 -0
- sage/misc/namespace_package.py +37 -0
- sage/misc/nested_class.cp314-win_amd64.pyd +0 -0
- sage/misc/nested_class.pxd +3 -0
- sage/misc/nested_class.pyx +394 -0
- sage/misc/persist.cp314-win_amd64.pyd +0 -0
- sage/misc/persist.pyx +1279 -0
- sage/misc/prandom.py +418 -0
- sage/misc/randstate.cp314-win_amd64.pyd +0 -0
- sage/misc/randstate.pxd +31 -0
- sage/misc/randstate.pyx +1096 -0
- sage/misc/repr.py +203 -0
- sage/misc/reset.cp314-win_amd64.pyd +0 -0
- sage/misc/reset.pyx +196 -0
- sage/misc/sage_ostools.cp314-win_amd64.pyd +0 -0
- sage/misc/sage_ostools.pyx +323 -0
- sage/misc/sage_timeit.py +275 -0
- sage/misc/sage_timeit_class.cp314-win_amd64.pyd +0 -0
- sage/misc/sage_timeit_class.pyx +120 -0
- sage/misc/sage_unittest.py +639 -0
- sage/misc/sageinspect.py +2792 -0
- sage/misc/session.cp314-win_amd64.pyd +0 -0
- sage/misc/session.pyx +392 -0
- sage/misc/superseded.py +576 -0
- sage/misc/test_nested_class.py +228 -0
- sage/misc/timing.py +264 -0
- sage/misc/unknown.py +222 -0
- sage/misc/verbose.py +253 -0
- sage/misc/weak_dict.cp314-win_amd64.pyd +0 -0
- sage/misc/weak_dict.pxd +15 -0
- sage/misc/weak_dict.pyx +1197 -0
- sage/modules/all__sagemath_objects.py +1 -0
- sage/modules/module.cp314-win_amd64.pyd +0 -0
- sage/modules/module.pxd +5 -0
- sage/modules/module.pyx +329 -0
- sage/rings/all__sagemath_objects.py +3 -0
- sage/rings/integer_fake.h +22 -0
- sage/rings/integer_fake.pxd +55 -0
- sage/rings/integer_fake.pyi +8 -0
- sage/sets/all__sagemath_objects.py +3 -0
- sage/sets/pythonclass.cp314-win_amd64.pyd +0 -0
- sage/sets/pythonclass.pxd +9 -0
- sage/sets/pythonclass.pyx +247 -0
- sage/structure/__init__.py +13 -0
- sage/structure/all.py +30 -0
- sage/structure/category_object.cp314-win_amd64.pyd +0 -0
- sage/structure/category_object.pxd +28 -0
- sage/structure/category_object.pyx +1090 -0
- sage/structure/coerce.cp314-win_amd64.pyd +0 -0
- sage/structure/coerce.pxd +44 -0
- sage/structure/coerce.pyx +2113 -0
- sage/structure/coerce_actions.cp314-win_amd64.pyd +0 -0
- sage/structure/coerce_actions.pxd +27 -0
- sage/structure/coerce_actions.pyx +988 -0
- sage/structure/coerce_dict.cp314-win_amd64.pyd +0 -0
- sage/structure/coerce_dict.pxd +51 -0
- sage/structure/coerce_dict.pyx +1557 -0
- sage/structure/coerce_exceptions.py +23 -0
- sage/structure/coerce_maps.cp314-win_amd64.pyd +0 -0
- sage/structure/coerce_maps.pxd +24 -0
- sage/structure/coerce_maps.pyx +656 -0
- sage/structure/debug_options.cp314-win_amd64.pyd +0 -0
- sage/structure/debug_options.pxd +6 -0
- sage/structure/debug_options.pyx +54 -0
- sage/structure/dynamic_class.py +541 -0
- sage/structure/element.cp314-win_amd64.pyd +0 -0
- sage/structure/element.pxd +271 -0
- sage/structure/element.pyx +4584 -0
- sage/structure/element_wrapper.cp314-win_amd64.pyd +0 -0
- sage/structure/element_wrapper.pxd +12 -0
- sage/structure/element_wrapper.pyx +582 -0
- sage/structure/factorization.py +1457 -0
- sage/structure/factorization_integer.py +154 -0
- sage/structure/factory.cp314-win_amd64.pyd +0 -0
- sage/structure/factory.pyx +863 -0
- sage/structure/formal_sum.py +489 -0
- sage/structure/gens_py.py +73 -0
- sage/structure/global_options.py +1725 -0
- sage/structure/indexed_generators.py +863 -0
- sage/structure/list_clone.cp314-win_amd64.pyd +0 -0
- sage/structure/list_clone.pxd +65 -0
- sage/structure/list_clone.pyx +1867 -0
- sage/structure/list_clone_demo.cp314-win_amd64.pyd +0 -0
- sage/structure/list_clone_demo.pyx +248 -0
- sage/structure/list_clone_timings.py +179 -0
- sage/structure/list_clone_timings_cy.cp314-win_amd64.pyd +0 -0
- sage/structure/list_clone_timings_cy.pyx +86 -0
- sage/structure/mutability.cp314-win_amd64.pyd +0 -0
- sage/structure/mutability.pxd +21 -0
- sage/structure/mutability.pyx +346 -0
- sage/structure/nonexact.py +69 -0
- sage/structure/parent.cp314-win_amd64.pyd +0 -0
- sage/structure/parent.pxd +112 -0
- sage/structure/parent.pyx +3087 -0
- sage/structure/parent_base.cp314-win_amd64.pyd +0 -0
- sage/structure/parent_base.pxd +13 -0
- sage/structure/parent_base.pyx +35 -0
- sage/structure/parent_gens.cp314-win_amd64.pyd +0 -0
- sage/structure/parent_gens.pxd +22 -0
- sage/structure/parent_gens.pyx +374 -0
- sage/structure/parent_old.cp314-win_amd64.pyd +0 -0
- sage/structure/parent_old.pxd +24 -0
- sage/structure/parent_old.pyx +278 -0
- sage/structure/proof/__init__.py +1 -0
- sage/structure/proof/all.py +243 -0
- sage/structure/proof/proof.py +300 -0
- sage/structure/richcmp.cp314-win_amd64.pyd +0 -0
- sage/structure/richcmp.pxd +212 -0
- sage/structure/richcmp.pyx +494 -0
- sage/structure/sage_object.cp314-win_amd64.pyd +0 -0
- sage/structure/sage_object.pxd +3 -0
- sage/structure/sage_object.pyx +1088 -0
- sage/structure/sage_object_test.py +19 -0
- sage/structure/sequence.py +937 -0
- sage/structure/set_factories.py +1178 -0
- sage/structure/set_factories_example.py +527 -0
- sage/structure/support_view.py +164 -0
- sage/structure/test_factory.py +56 -0
- sage/structure/unique_representation.py +1443 -0
sage/cpython/string.pxd
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
# ****************************************************************************
|
|
3
|
+
# Copyright (C) 2017 Erik M. Bray <erik.bray@lri.fr>
|
|
4
|
+
#
|
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
# https://www.gnu.org/licenses/
|
|
10
|
+
# ****************************************************************************
|
|
11
|
+
|
|
12
|
+
cdef extern from "string_impl.h":
|
|
13
|
+
str _cstr_to_str(const char* c, encoding, errors)
|
|
14
|
+
bytes _str_to_bytes(s, encoding, errors)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
cdef inline str char_to_str(const char* c, encoding=None, errors=None):
|
|
18
|
+
r"""
|
|
19
|
+
Convert a C string to a Python ``str``.
|
|
20
|
+
"""
|
|
21
|
+
# Implemented in C to avoid relying on PY_MAJOR_VERSION
|
|
22
|
+
# compile-time variable. We keep the Cython wrapper to deal with
|
|
23
|
+
# the default arguments.
|
|
24
|
+
return _cstr_to_str(c, encoding, errors)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
cpdef inline str bytes_to_str(b, encoding=None, errors=None):
|
|
28
|
+
r"""
|
|
29
|
+
Convert ``bytes`` to ``str``.
|
|
30
|
+
|
|
31
|
+
This decodes the given ``bytes`` to a Python 3 unicode ``str`` using
|
|
32
|
+
the specified encoding. It is a no-op on ``str`` input.
|
|
33
|
+
|
|
34
|
+
EXAMPLES::
|
|
35
|
+
|
|
36
|
+
sage: from sage.cpython.string import bytes_to_str
|
|
37
|
+
sage: s = bytes_to_str(b'\xcf\x80')
|
|
38
|
+
sage: s == u'π'
|
|
39
|
+
True
|
|
40
|
+
sage: bytes_to_str([])
|
|
41
|
+
Traceback (most recent call last):
|
|
42
|
+
...
|
|
43
|
+
TypeError: expected bytes, list found
|
|
44
|
+
"""
|
|
45
|
+
if isinstance(b, str):
|
|
46
|
+
return b
|
|
47
|
+
if type(b) is not bytes:
|
|
48
|
+
raise TypeError(f"expected bytes, {type(b).__name__} found")
|
|
49
|
+
|
|
50
|
+
return _cstr_to_str(<bytes>b, encoding, errors)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
cpdef inline bytes str_to_bytes(s, encoding=None, errors=None):
|
|
54
|
+
r"""
|
|
55
|
+
Convert ``str`` or ``unicode`` to ``bytes``.
|
|
56
|
+
|
|
57
|
+
It encodes the given ``str`` to a Python 3 ``bytes``
|
|
58
|
+
using the specified encoding. It is a no-op on ``bytes`` input.
|
|
59
|
+
|
|
60
|
+
EXAMPLES::
|
|
61
|
+
|
|
62
|
+
sage: from sage.cpython.string import str_to_bytes
|
|
63
|
+
sage: bs = [str_to_bytes(u'π')]
|
|
64
|
+
sage: all(b == b'\xcf\x80' for b in bs)
|
|
65
|
+
True
|
|
66
|
+
sage: str_to_bytes([])
|
|
67
|
+
Traceback (most recent call last):
|
|
68
|
+
...
|
|
69
|
+
TypeError: expected str... list found
|
|
70
|
+
"""
|
|
71
|
+
# Implemented in C to avoid relying on PY_MAJOR_VERSION
|
|
72
|
+
# compile-time variable. We keep the Cython wrapper to deal with
|
|
73
|
+
# the default arguments.
|
|
74
|
+
if isinstance(s, bytes):
|
|
75
|
+
return s
|
|
76
|
+
return _str_to_bytes(s, encoding, errors)
|
sage/cpython/string.pyx
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
"""
|
|
3
|
+
String <-> bytes encoding/decoding
|
|
4
|
+
|
|
5
|
+
TESTS:
|
|
6
|
+
|
|
7
|
+
Check that this can be used outside of Sage (see :issue:`25549`)::
|
|
8
|
+
|
|
9
|
+
sage: cython( # needs sage.misc.cython
|
|
10
|
+
....: '''
|
|
11
|
+
....: from sage.cpython.string cimport char_to_str
|
|
12
|
+
....: print(char_to_str("hello world!"))
|
|
13
|
+
....: ''')
|
|
14
|
+
hello world!
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
# ****************************************************************************
|
|
18
|
+
# Copyright (C) 2017 Erik M. Bray <erik.bray@lri.fr>
|
|
19
|
+
#
|
|
20
|
+
# This program is free software: you can redistribute it and/or modify
|
|
21
|
+
# it under the terms of the GNU General Public License as published by
|
|
22
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
23
|
+
# (at your option) any later version.
|
|
24
|
+
# https://www.gnu.org/licenses/
|
|
25
|
+
# ****************************************************************************
|
|
26
|
+
|
|
27
|
+
import sys
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# Provide this as a shortcut to calling sys.getfilesystemencoding(), which
|
|
31
|
+
# after interpreter initialization is constant.
|
|
32
|
+
FS_ENCODING = sys.getfilesystemencoding()
|
|
33
|
+
|
|
34
|
+
# Functions in this module are implemented in the .pxd file for inlining.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* sage_setup: distribution = sagemath-objects
|
|
2
|
+
*/
|
|
3
|
+
/*****************************************************************************
|
|
4
|
+
# Copyright (C) 2017 Erik M. Bray <erik.bray@lri.fr>
|
|
5
|
+
# Copyright (C) 2018 Jeroen Demeyer <J.Demeyer@UGent.be>
|
|
6
|
+
#
|
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
|
9
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
10
|
+
# (at your option) any later version.
|
|
11
|
+
# https://www.gnu.org/licenses/
|
|
12
|
+
*****************************************************************************/
|
|
13
|
+
|
|
14
|
+
#include <Python.h>
|
|
15
|
+
#include <string.h>
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
static inline PyObject* _cstr_to_str(const char* c, PyObject* encoding, PyObject* errors)
|
|
19
|
+
{
|
|
20
|
+
const char* err = NULL; // Default: strict
|
|
21
|
+
const char* enc = NULL; // Default: utf-8
|
|
22
|
+
|
|
23
|
+
if (errors != Py_None) {
|
|
24
|
+
err = PyUnicode_AsUTF8(errors);
|
|
25
|
+
if (!err) return NULL;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (encoding != Py_None) {
|
|
29
|
+
enc = PyUnicode_AsUTF8(encoding);
|
|
30
|
+
if (!enc) return NULL;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return PyUnicode_Decode(c, strlen(c), enc, err);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
static inline PyObject* _str_to_bytes(PyObject* s, PyObject* encoding, PyObject* errors)
|
|
38
|
+
{
|
|
39
|
+
if (!PyUnicode_Check(s)) {
|
|
40
|
+
PyErr_Format(PyExc_TypeError,
|
|
41
|
+
"expected str, %s found",
|
|
42
|
+
Py_TYPE(s)->tp_name);
|
|
43
|
+
return NULL;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const char* err = NULL; // Default: strict
|
|
47
|
+
const char* enc = NULL; // Default: utf-8
|
|
48
|
+
|
|
49
|
+
if (errors != Py_None) {
|
|
50
|
+
err = PyUnicode_AsUTF8(errors);
|
|
51
|
+
if (!err) return NULL;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (encoding != Py_None) {
|
|
55
|
+
enc = PyUnicode_AsUTF8(encoding);
|
|
56
|
+
if (!enc) return NULL;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return PyUnicode_AsEncodedString(s, enc, err);
|
|
60
|
+
}
|
|
Binary file
|
sage/cpython/type.pxd
ADDED
sage/cpython/type.pyx
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
"""
|
|
3
|
+
Type internals
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from cpython.object cimport Py_TYPE, PyTypeObject, Py_TPFLAGS_HEAPTYPE
|
|
7
|
+
|
|
8
|
+
cdef PyTypeObject* PyInstance_Type = NULL
|
|
9
|
+
try:
|
|
10
|
+
from types import InstanceType
|
|
11
|
+
PyInstance_Type = <PyTypeObject*>InstanceType
|
|
12
|
+
except ImportError:
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
cpdef bint can_assign_class(obj) noexcept:
|
|
17
|
+
"""
|
|
18
|
+
Can we assign ``obj.__class__``?
|
|
19
|
+
|
|
20
|
+
Note that Python 3.5 has experimented with allowing assigning
|
|
21
|
+
``__class__`` in more cases but this was mostly reverted. In this
|
|
22
|
+
function, we apply the Python 2.7 semantics.
|
|
23
|
+
|
|
24
|
+
EXAMPLES::
|
|
25
|
+
|
|
26
|
+
sage: class X: pass
|
|
27
|
+
sage: from sage.cpython.type import can_assign_class
|
|
28
|
+
sage: can_assign_class(X())
|
|
29
|
+
True
|
|
30
|
+
sage: class Y(int): pass
|
|
31
|
+
sage: from sage.cpython.type import can_assign_class
|
|
32
|
+
sage: can_assign_class(Y())
|
|
33
|
+
True
|
|
34
|
+
sage: can_assign_class(1)
|
|
35
|
+
False
|
|
36
|
+
"""
|
|
37
|
+
cdef PyTypeObject* tp = Py_TYPE(obj)
|
|
38
|
+
if tp is PyInstance_Type:
|
|
39
|
+
return True
|
|
40
|
+
return (tp.tp_flags & Py_TPFLAGS_HEAPTYPE) != 0
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
from cpython.object cimport PyObject, PyTypeObject
|
|
3
|
+
|
|
4
|
+
cdef extern from *:
|
|
5
|
+
ctypedef object (*wrapperfunc)(self, args, void* wrapped)
|
|
6
|
+
ctypedef object (*wrapperfunc_kwds)(self, args, void* wrapped, kwds)
|
|
7
|
+
|
|
8
|
+
struct wrapperbase:
|
|
9
|
+
char* name
|
|
10
|
+
int offset
|
|
11
|
+
void* function
|
|
12
|
+
wrapperfunc wrapper
|
|
13
|
+
char* doc
|
|
14
|
+
int flags
|
|
15
|
+
PyObject* name_strobj
|
|
16
|
+
|
|
17
|
+
int PyWrapperFlag_KEYWORDS
|
|
18
|
+
|
|
19
|
+
ctypedef class sage.cpython.builtin_types.wrapper_descriptor [object PyWrapperDescrObject]:
|
|
20
|
+
cdef type d_type
|
|
21
|
+
cdef d_name
|
|
22
|
+
cdef wrapperbase* d_base
|
|
23
|
+
cdef void* d_wrapped
|
|
24
|
+
|
|
25
|
+
PyDescr_NewWrapper(PyTypeObject* cls, wrapperbase* wrapper, void* wrapped)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
cdef wrapperdescr_fastcall(wrapper_descriptor slotwrapper, self, args, kwds)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
cdef inline wrapperbase* get_slotdef(wrapper_descriptor slotwrapper) except NULL:
|
|
32
|
+
"""
|
|
33
|
+
Given a slot wrapper, return the corresponding ``slotdef``.
|
|
34
|
+
|
|
35
|
+
A ``slotdef`` is associated to a specific slot like ``__eq__``
|
|
36
|
+
and does not depend at all on the type. In other words, calling
|
|
37
|
+
``get_slotdef(t.__eq__)`` will return the same ``slotdef``
|
|
38
|
+
independent of the type ``t`` (provided that the type implements
|
|
39
|
+
rich comparison in C).
|
|
40
|
+
|
|
41
|
+
TESTS::
|
|
42
|
+
|
|
43
|
+
sage: # needs sage.misc.cython
|
|
44
|
+
sage: cython(
|
|
45
|
+
....: '''
|
|
46
|
+
....: from sage.cpython.wrapperdescr cimport get_slotdef
|
|
47
|
+
....: from cpython.long cimport PyLong_FromVoidPtr
|
|
48
|
+
....: def py_get_slotdef(slotwrapper):
|
|
49
|
+
....: return PyLong_FromVoidPtr(get_slotdef(slotwrapper))
|
|
50
|
+
....: ''')
|
|
51
|
+
sage: py_get_slotdef(object.__init__) # random
|
|
52
|
+
140016903442416
|
|
53
|
+
sage: py_get_slotdef(bytes.__lt__) # random
|
|
54
|
+
140016903441800
|
|
55
|
+
sage: py_get_slotdef(bytes.__lt__) == py_get_slotdef(Integer.__lt__)
|
|
56
|
+
True
|
|
57
|
+
sage: py_get_slotdef(bytes.__lt__) == py_get_slotdef(bytes.__gt__)
|
|
58
|
+
False
|
|
59
|
+
sage: class X():
|
|
60
|
+
....: def __eq__(self, other):
|
|
61
|
+
....: return False
|
|
62
|
+
sage: py_get_slotdef(X.__eq__)
|
|
63
|
+
Traceback (most recent call last):
|
|
64
|
+
...
|
|
65
|
+
TypeError: Cannot convert ... to wrapper_descriptor
|
|
66
|
+
"""
|
|
67
|
+
return slotwrapper.d_base
|
sage/ext/ccobject.h
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* sage_setup: distribution = sagemath-objects
|
|
2
|
+
*/
|
|
3
|
+
#ifndef __SAGE_CCOBJECT_H__
|
|
4
|
+
#define __SAGE_CCOBJECT_H__
|
|
5
|
+
|
|
6
|
+
#ifdef __cplusplus
|
|
7
|
+
|
|
8
|
+
#include <iostream>
|
|
9
|
+
#include <sstream>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
template <class T>
|
|
13
|
+
static CYTHON_INLINE int ccreadstr(T& x, PyObject* b)
|
|
14
|
+
{
|
|
15
|
+
PyObject* converted = NULL;
|
|
16
|
+
|
|
17
|
+
// Accept "str" input
|
|
18
|
+
if (PyUnicode_Check(b))
|
|
19
|
+
{
|
|
20
|
+
converted = PyUnicode_EncodeFSDefault(b);
|
|
21
|
+
if (!converted) {return -1;}
|
|
22
|
+
b = converted;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
char* buffer;
|
|
26
|
+
Py_ssize_t length;
|
|
27
|
+
|
|
28
|
+
if (PyBytes_AsStringAndSize(b, &buffer, &length) == -1)
|
|
29
|
+
{Py_XDECREF(converted); return -1;}
|
|
30
|
+
std::istringstream input(std::string(buffer, length));
|
|
31
|
+
Py_XDECREF(converted);
|
|
32
|
+
|
|
33
|
+
input >> x;
|
|
34
|
+
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
template <class T>
|
|
40
|
+
static CYTHON_INLINE PyObject* ccrepr(const T& x)
|
|
41
|
+
{
|
|
42
|
+
std::ostringstream instore;
|
|
43
|
+
instore << x;
|
|
44
|
+
std::string instr = instore.str();
|
|
45
|
+
return PyUnicode_DecodeFSDefaultAndSize(instr.c_str(), instr.size());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/* Arrays */
|
|
50
|
+
template <class T>
|
|
51
|
+
static inline T* Allocate_array(size_t n)
|
|
52
|
+
{
|
|
53
|
+
return new T[n];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
template <class T>
|
|
57
|
+
static inline void Delete_array(T* v)
|
|
58
|
+
{
|
|
59
|
+
delete[] v;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#endif
|
|
63
|
+
|
|
64
|
+
#endif /* ifndef __SAGE_CCOBJECT_H__ */
|
sage/ext/cplusplus.pxd
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
# ***************************************************************************
|
|
3
|
+
# Copyright (C) 2017 Jeroen Demeyer <J.Demeyer@UGent.be>
|
|
4
|
+
#
|
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
# https://www.gnu.org/licenses/
|
|
10
|
+
# ***************************************************************************
|
|
11
|
+
|
|
12
|
+
cdef extern from "ccobject.h":
|
|
13
|
+
# Print representation of any C++ object
|
|
14
|
+
str ccrepr[T](const T& x)
|
|
15
|
+
|
|
16
|
+
# Read a Python bytes/str into a C++ object
|
|
17
|
+
int ccreadstr[T](T x, object b) except -1
|
sage/ext/mod_int.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* sage_setup: distribution = sagemath-objects
|
|
2
|
+
*/
|
|
3
|
+
/* See mod_int.pxd if you want to use these declarations in Cython */
|
|
4
|
+
|
|
5
|
+
/* CPython using signed long as the data type for plain integers, which is
|
|
6
|
+
* - 8 bytes on 64-bit Linux and OSX
|
|
7
|
+
* - 4 bytes on 64-bit Windows and all 32-bit supported platforms.
|
|
8
|
+
* If you want to convert mod_int quickly to Python, then it must fit
|
|
9
|
+
* into such an integer. Otherwise you'll end up with Python's
|
|
10
|
+
* arbitrary-size integers instead of machine ints.
|
|
11
|
+
*
|
|
12
|
+
* However, 4 bytes is rather small and one can quickly run out of
|
|
13
|
+
* primes, especially if the problem has many bad primes. See Trac
|
|
14
|
+
* #10281 for details.
|
|
15
|
+
*
|
|
16
|
+
* Hence, we use signed 64-bit ints. This gives us fast conversion
|
|
17
|
+
* to/from Python on 64-bit Linux and OSX, and a large number of
|
|
18
|
+
* available (but not quite as fast) primes on 64-bit Windows and all
|
|
19
|
+
* 32-bit platforms (see Issue #10281)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
typedef int64_t mod_int;
|
|
23
|
+
|
|
24
|
+
/* The largest value we can do arithmetic on without risking overflowing.
|
|
25
|
+
* That is, you can multiply two MOD_INT_MAX in a mod_int.
|
|
26
|
+
*/
|
|
27
|
+
#define MOD_INT_OVERFLOW_UNSIGNED ((((uint64_t)1) << (sizeof(mod_int)*8 - 1)) - 1)
|
|
28
|
+
#define MOD_INT_OVERFLOW ((mod_int)MOD_INT_OVERFLOW_UNSIGNED)
|
|
29
|
+
#define MOD_INT_MAX ((mod_int)sqrt(MOD_INT_OVERFLOW_UNSIGNED) - 1)
|
|
30
|
+
|
sage/ext/mod_int.pxd
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
"""
|
|
3
|
+
The `mod_int` Data Type
|
|
4
|
+
|
|
5
|
+
* In C/C++ headers, you can `#include "mod_int.h"`
|
|
6
|
+
* In Cython files, use `from sage.ext.mod_int cimport *`
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# ***************************************************************************
|
|
10
|
+
# Copyright (C) 2013 Volker Braun <vbraun.name@gmail.com>
|
|
11
|
+
# Copyright (C) 2013 William Stein <wstein@gmail.com>
|
|
12
|
+
#
|
|
13
|
+
# This program is free software: you can redistribute it and/or modify
|
|
14
|
+
# it under the terms of the GNU General Public License as published by
|
|
15
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
16
|
+
# (at your option) any later version.
|
|
17
|
+
# https://www.gnu.org/licenses/
|
|
18
|
+
# ***************************************************************************
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
cdef extern from "mod_int.h":
|
|
22
|
+
ctypedef long mod_int
|
|
23
|
+
mod_int MOD_INT_MAX
|
|
24
|
+
mod_int MOD_INT_OVERFLOW
|
sage/ext/stdsage.pxd
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
"""
|
|
3
|
+
Standard C helper code for Cython modules
|
|
4
|
+
"""
|
|
5
|
+
# ***************************************************************************
|
|
6
|
+
# Copyright (C) 2015 Jeroen Demeyer <jdemeyer@cage.ugent.be>
|
|
7
|
+
#
|
|
8
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
9
|
+
# as published by the Free Software Foundation; either version 2 of
|
|
10
|
+
# the License, or (at your option) any later version.
|
|
11
|
+
# https://www.gnu.org/licenses/
|
|
12
|
+
# ***************************************************************************
|
|
13
|
+
|
|
14
|
+
from cpython.object cimport Py_TYPE, PyTypeObject, PyObject
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
cdef inline PY_NEW(type t):
|
|
18
|
+
"""
|
|
19
|
+
Return ``t.__new__(t)``. This works even for types like
|
|
20
|
+
:class:`Integer` where we change ``tp_new`` at runtime (Cython
|
|
21
|
+
optimizations assume that ``tp_new`` doesn't change).
|
|
22
|
+
"""
|
|
23
|
+
return (<PyTypeObject*>t).tp_new(t, <PyObject*>NULL, <PyObject*>NULL)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
cdef inline void PY_SET_TP_NEW(type dst, type src) noexcept:
|
|
27
|
+
"""
|
|
28
|
+
Manually set ``dst.__new__`` to ``src.__new__``. This is used to
|
|
29
|
+
speed up Cython's boilerplate object construction code by skipping
|
|
30
|
+
irrelevant base class ``tp_new`` methods.
|
|
31
|
+
"""
|
|
32
|
+
(<PyTypeObject*>dst).tp_new = (<PyTypeObject*>src).tp_new
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
cdef inline bint HAS_DICTIONARY(obj) noexcept:
|
|
36
|
+
"""
|
|
37
|
+
Test whether the given object has a Python dictionary.
|
|
38
|
+
"""
|
|
39
|
+
return Py_TYPE(obj).tp_dictoffset != 0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
Binary file
|
sage/groups/group.pxd
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
from sage.structure.parent cimport Parent
|
|
3
|
+
|
|
4
|
+
cdef class Group(Parent):
|
|
5
|
+
pass
|
|
6
|
+
|
|
7
|
+
cdef class AbelianGroup(Group):
|
|
8
|
+
pass
|
|
9
|
+
|
|
10
|
+
cdef class FiniteGroup(Group):
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
cdef class AlgebraicGroup(Group):
|
|
14
|
+
pass
|