From f36275a78691ff374b8aab5d972cd72db6ce5268 Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Mon, 22 Jul 2019 17:19:11 +0900 Subject: [PATCH 1/7] Turn on cython directive binding --- src/sage_setup/cython_options.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sage_setup/cython_options.py b/src/sage_setup/cython_options.py index a02401c4d23..a6c40daf137 100644 --- a/src/sage_setup/cython_options.py +++ b/src/sage_setup/cython_options.py @@ -9,6 +9,8 @@ def compiler_directives(profile: bool): auto_pickle=False, # Do not create __test__ dictionary automatically from docstrings autotestdict=False, + # When enabled, functions will bind to an instance when looked up as a class attribute (hence the name) and will emulate the attributes of Python functions, including introspections like argument names and annotations. + binding=True, # Do not check for division by 0 (this is about 35% quicker than with check) cdivision=True, # Embed a textual copy of the call signature in the docstring (to support tools like IPython) From 36ec4930832d840a73f1bcefe1d22bb27c566e49 Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Wed, 8 Sep 2021 10:06:05 +0900 Subject: [PATCH 2/7] Reformat the comment --- src/sage_setup/cython_options.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sage_setup/cython_options.py b/src/sage_setup/cython_options.py index a6c40daf137..9bf91c992c8 100644 --- a/src/sage_setup/cython_options.py +++ b/src/sage_setup/cython_options.py @@ -9,7 +9,10 @@ def compiler_directives(profile: bool): auto_pickle=False, # Do not create __test__ dictionary automatically from docstrings autotestdict=False, - # When enabled, functions will bind to an instance when looked up as a class attribute (hence the name) and will emulate the attributes of Python functions, including introspections like argument names and annotations. + # When enabled, functions will bind to an instance when looked up as a + # class attribute (hence the name) and will emulate the attributes of + # Python functions, including introspections like argument names and + # annotations binding=True, # Do not check for division by 0 (this is about 35% quicker than with check) cdivision=True, From bea228b1437527a91478e539b1db9ab57e5b45fc Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sun, 1 May 2022 11:43:02 +0000 Subject: [PATCH 3/7] Try with localized import --- src/sage/symbolic/function.pyx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sage/symbolic/function.pyx b/src/sage/symbolic/function.pyx index 480a6019e7c..72c9941c9a7 100644 --- a/src/sage/symbolic/function.pyx +++ b/src/sage/symbolic/function.pyx @@ -142,7 +142,7 @@ from sage.structure.sage_object cimport SageObject from sage.structure.element cimport Element, parent, Expression from sage.misc.lazy_attribute import lazy_attribute from .expression import ( - call_registered_function, find_registered_function, register_or_update_function, + find_registered_function, register_or_update_function, get_sfunction_from_hash ) from .expression import get_sfunction_from_serial as get_sfunction_from_serial @@ -544,6 +544,8 @@ cdef class Function(SageObject): if not isinstance(a, Expression): raise TypeError("arguments must be symbolic expressions") + from .expression import call_registered_function + return call_registered_function(self._serial, self._nargs, args, hold, not symbolic_input, SR) From 89b80815a3a207f798af01b517c623db40ab180e Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 7 May 2022 13:59:56 +0000 Subject: [PATCH 4/7] Inline all other imports from expression --- src/sage/symbolic/function.pyx | 16 +++++++++++----- src/sage/symbolic/ring.pyx | 7 +++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/sage/symbolic/function.pyx b/src/sage/symbolic/function.pyx index 72c9941c9a7..1a01f45e82f 100644 --- a/src/sage/symbolic/function.pyx +++ b/src/sage/symbolic/function.pyx @@ -141,11 +141,6 @@ is attempted, and after that ``sin()`` which succeeds:: from sage.structure.sage_object cimport SageObject from sage.structure.element cimport Element, parent, Expression from sage.misc.lazy_attribute import lazy_attribute -from .expression import ( - find_registered_function, register_or_update_function, - get_sfunction_from_hash -) -from .expression import get_sfunction_from_serial as get_sfunction_from_serial from sage.structure.coerce cimport (coercion_model, py_scalar_to_element, is_numpy_type, is_mpmath_type) @@ -263,6 +258,8 @@ cdef class Function(SageObject): f(x) """ + from .expression import register_or_update_function + self._serial = register_or_update_function(self, self._name, self._latex_name, self._nargs, self._evalf_params_first, False) @@ -840,6 +837,9 @@ cdef class GinacFunction(BuiltinFunction): preserved_arg=preserved_arg, alt_name=alt_name) cdef _is_registered(self): + from .expression import find_registered_function, get_sfunction_from_serial + + # Since this is function is defined in C++, it is already in # ginac's function registry fname = self._ginac_name if self._ginac_name is not None else self._name @@ -847,6 +847,8 @@ cdef class GinacFunction(BuiltinFunction): return bool(get_sfunction_from_serial(self._serial)) cdef _register_function(self): + from .expression import register_or_update_function + # We don't need to add anything to GiNaC's function registry # However, if any custom methods were provided in the python class, # we should set the properties of the function_options object @@ -1094,6 +1096,8 @@ cdef class BuiltinFunction(Function): sage: loads(dumps(cot)) == cot # trac #15138 True """ + from .expression import find_registered_function, get_sfunction_from_serial + # check if already defined cdef unsigned int serial @@ -1192,6 +1196,8 @@ cdef class SymbolicFunction(Function): cdef _is_registered(SymbolicFunction self): + from .expression import get_sfunction_from_hash + # see if there is already a SymbolicFunction with the same state cdef long myhash = self._hash_() cdef SymbolicFunction sfunc = get_sfunction_from_hash(myhash) diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index 05694e3b085..a7332b86386 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -52,8 +52,11 @@ from sage.structure.coerce cimport is_numpy_type import sage.rings.abc from sage.rings.integer_ring import ZZ -# is_SymbolicVariable used to be defined here; re-export it -from sage.symbolic.expression import _is_SymbolicVariable as is_SymbolicVariable +# is_SymbolicVariable used to be defined here; re-export it here lazily +cpdef bint is_SymbolicVariable(x): + from sage.symbolic.expression import _is_SymbolicVariable + + return _is_SymbolicVariable(x) import keyword import operator From 9bbf574712ba9cb674a52a850fc6d10abfecac5b Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 7 May 2022 14:39:47 +0000 Subject: [PATCH 5/7] Fix a few tests --- src/sage/arith/misc.py | 8 ++++---- src/sage/graphs/strongly_regular_db.pyx | 2 +- src/sage/interfaces/sage0.py | 2 +- src/sage/libs/singular/ring.pyx | 2 +- src/sage/misc/c3_controlled.pyx | 2 +- src/sage/rings/finite_rings/hom_finite_field.pyx | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/sage/arith/misc.py b/src/sage/arith/misc.py index 9966d0b8571..568f800786e 100644 --- a/src/sage/arith/misc.py +++ b/src/sage/arith/misc.py @@ -2115,9 +2115,9 @@ def get_gcd(order): EXAMPLES:: sage: sage.arith.misc.get_gcd(4000) - + sage: sage.arith.misc.get_gcd(400000) - + sage: sage.arith.misc.get_gcd(4000000000) """ @@ -2137,9 +2137,9 @@ def get_inverse_mod(order): EXAMPLES:: sage: sage.arith.misc.get_inverse_mod(6000) - + sage: sage.arith.misc.get_inverse_mod(600000) - + sage: sage.arith.misc.get_inverse_mod(6000000000) """ diff --git a/src/sage/graphs/strongly_regular_db.pyx b/src/sage/graphs/strongly_regular_db.pyx index d98a5f553c4..d99a1686bb1 100644 --- a/src/sage/graphs/strongly_regular_db.pyx +++ b/src/sage/graphs/strongly_regular_db.pyx @@ -1136,7 +1136,7 @@ def is_RSHCD(int v,int k,int l,int mu): sage: from sage.graphs.strongly_regular_db import is_RSHCD sage: t = is_RSHCD(64,27,10,12); t - [, 64, 27, 10, 12] + [, 64, 27, 10, 12] sage: g = t[0](*t[1:]); g Graph on 64 vertices sage: g.is_strongly_regular(parameters=True) diff --git a/src/sage/interfaces/sage0.py b/src/sage/interfaces/sage0.py index 5a303d57745..91e1f028c6c 100644 --- a/src/sage/interfaces/sage0.py +++ b/src/sage/interfaces/sage0.py @@ -554,7 +554,7 @@ def _repr_(self): EXAMPLES:: sage: sage0(4).gcd - + """ return str(self._obj.parent().eval('%s.%s' % (self._obj._name, self._name))) diff --git a/src/sage/libs/singular/ring.pyx b/src/sage/libs/singular/ring.pyx index d49cf529073..c1214f11afa 100644 --- a/src/sage/libs/singular/ring.pyx +++ b/src/sage/libs/singular/ring.pyx @@ -772,7 +772,7 @@ cpdef poison_currRing(frame, event, arg): sage: from sage.libs.singular.ring import poison_currRing sage: sys.settrace(poison_currRing) sage: sys.gettrace() - + sage: sys.settrace(previous_trace_func) # switch it off again """ global currRing diff --git a/src/sage/misc/c3_controlled.pyx b/src/sage/misc/c3_controlled.pyx index 3e70e529ad2..d43625bc673 100644 --- a/src/sage/misc/c3_controlled.pyx +++ b/src/sage/misc/c3_controlled.pyx @@ -1088,7 +1088,7 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): sage: x._bases [5, 2] sage: x._key - + sage: x._key(10) 10 diff --git a/src/sage/rings/finite_rings/hom_finite_field.pyx b/src/sage/rings/finite_rings/hom_finite_field.pyx index 62f42e6a451..18346390f30 100644 --- a/src/sage/rings/finite_rings/hom_finite_field.pyx +++ b/src/sage/rings/finite_rings/hom_finite_field.pyx @@ -435,7 +435,7 @@ cdef class FiniteFieldHomomorphism_generic(RingHomomorphism_im_gens): sage: Frob = k.frobenius_endomorphism() sage: embed = Frob.fixed_field()[1] sage: embed.__reduce__() # indirect doctest - (, + (, (, Set of field embeddings from Finite Field of size 5 to Finite Field in t of size 5^3, {}, @@ -835,7 +835,7 @@ cdef class FrobeniusEndomorphism_finite_field(FrobeniusEndomorphism_generic): sage: k. = GF(5^3) sage: Frob = k.frobenius_endomorphism(2) sage: Frob.__reduce__() # indirect doctest - (, + (, (, Automorphism group of Finite Field in t of size 5^3, {}, From 803804f82c0356ecf77094c636ce77a12c4b4589 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 7 May 2022 14:40:16 +0000 Subject: [PATCH 6/7] and one more test --- src/sage/structure/list_clone.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/structure/list_clone.pyx b/src/sage/structure/list_clone.pyx index 125f32762ef..35bc3e3eea5 100644 --- a/src/sage/structure/list_clone.pyx +++ b/src/sage/structure/list_clone.pyx @@ -934,7 +934,7 @@ cdef class ClonableArray(ClonableElement): sage: loads(dumps(el)) [1, 2, 4] sage: t = el.__reduce__(); t - (, + (, (, , [1, 2, 4], From a23ffe9b9fd43e43ecacd73eaf6e21577b114a60 Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Tue, 10 May 2022 13:36:08 +0900 Subject: [PATCH 7/7] Tiny edits --- src/sage/symbolic/expression.pyx | 3 +-- src/sage/symbolic/function.pyx | 3 +-- src/sage/symbolic/ring.pyx | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index 0fd0eeea6bd..2742649c8d8 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -6100,7 +6100,7 @@ cdef class Expression(Expression_abc): sage: x = SR.var("x") sage: f = function("f") - sage: bool(f(exp(I*x)).diff(x).demoivre() == + sage: bool(f(exp(I*x)).diff(x).demoivre() == ....: f(exp(I*x)).demoivre().diff(x)) True """ @@ -6351,7 +6351,6 @@ cdef class Expression(Expression_abc): sage: type(u._unpack_operands()[0]) <... 'tuple'> """ - from sage.symbolic.expression import unpack_operands return unpack_operands(self) def operands(self): diff --git a/src/sage/symbolic/function.pyx b/src/sage/symbolic/function.pyx index 1a01f45e82f..a99735fa988 100644 --- a/src/sage/symbolic/function.pyx +++ b/src/sage/symbolic/function.pyx @@ -542,7 +542,7 @@ cdef class Function(SageObject): raise TypeError("arguments must be symbolic expressions") from .expression import call_registered_function - + return call_registered_function(self._serial, self._nargs, args, hold, not symbolic_input, SR) @@ -839,7 +839,6 @@ cdef class GinacFunction(BuiltinFunction): cdef _is_registered(self): from .expression import find_registered_function, get_sfunction_from_serial - # Since this is function is defined in C++, it is already in # ginac's function registry fname = self._ginac_name if self._ginac_name is not None else self._name diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index a7332b86386..5faad7ffa00 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -55,7 +55,7 @@ from sage.rings.integer_ring import ZZ # is_SymbolicVariable used to be defined here; re-export it here lazily cpdef bint is_SymbolicVariable(x): from sage.symbolic.expression import _is_SymbolicVariable - + return _is_SymbolicVariable(x) import keyword