Ticket #9054: trac_9054_cached_method.patch

File trac_9054_cached_method.patch, 3.8 KB (added by saraedum, 6 years ago)

replace manual caching with cached_method

  • sage/rings/function_field/function_field.py

    exporting patch:
    # HG changeset patch
    # User Julian Rueth <julian.rueth@gmail.com>
    Trac 9054: use cached_method decorator
    
    diff --git a/sage/rings/function_field/function_field.py b/sage/rings/function_field/function_field.py
    index 78d0807..f894165 100644
    a b from sage.structure.parent_gens import ParentWithGens 
    5959from sage.structure.parent import Parent
    6060import function_field_element
    6161import constructor
     62
     63from sage.misc.cachefunc import cached_method
     64
    6265from sage.categories.function_fields import FunctionFields
    6366CAT = FunctionFields()
    6467
    class FunctionField_polymod(FunctionField): 
    718721        """
    719722        return self._ring
    720723
     724    @cached_method
    721725    def vector_space(self):
    722726        """
    723727        Return a vector space V and isomorphisms self --> V and V --> self.
    class FunctionField_polymod(FunctionField): 
    793797              To:   Vector space of dimension 2 over Function field in w defined by y^5 - 2*x*y + (-x^4 - 1)/x)
    794798                   
    795799        """
    796         try: return self._vector_space
    797         except AttributeError:
    798             V = self.base_field()**self.degree()
    799             from_V = maps.MapVectorSpaceToFunctionField(V, self)
    800             to_V   = maps.MapFunctionFieldToVectorSpace(self, V)
    801             self._vector_space = (V, from_V, to_V)
    802             return self._vector_space
     800        V = self.base_field()**self.degree()
     801        from maps import MapVectorSpaceToFunctionField, MapFunctionFieldToVectorSpace
     802        from_V = MapVectorSpaceToFunctionField(V, self)
     803        to_V   = MapFunctionFieldToVectorSpace(self, V)
     804        self._vector_space = (V, from_V, to_V)
     805        return self._vector_space
    803806       
    804807
    805808    def maximal_order(self):
    class RationalFunctionField(FunctionField): 
    11491152        from sage.structure.factorization import Factorization
    11501153        return Factorization(w, unit=unit)
    11511154
     1155    @cached_method
    11521156    def polynomial_ring(self, var='x'):
    11531157        """
    11541158        Return polynomial ring K[var] that could be used to represent
    class RationalFunctionField(FunctionField): 
    11901194              To:   Vector space of dimension 1 over Rational function field in x over Rational Field)
    11911195       
    11921196        """
    1193         try: return self._vector_space
    1194         except AttributeError:
    1195             V = self.base_field()**1
    1196             from_V = maps.MapVectorSpaceToFunctionField(V, self)
    1197             to_V   = maps.MapFunctionFieldToVectorSpace(self, V)
    1198             self._vector_space = (V, from_V, to_V)
    1199             return self._vector_space
     1197        V = self.base_field()**1
     1198        from maps import MapVectorSpaceToFunctionField, MapFunctionFieldToVectorSpace
     1199        from_V = MapVectorSpaceToFunctionField(V, self)
     1200        to_V   = MapFunctionFieldToVectorSpace(self, V)
     1201        self._vector_space = (V, from_V, to_V)
     1202        return self._vector_space
    12001203
    12011204    def random_element(self, *args, **kwds):
    12021205        """
    class RationalFunctionField(FunctionField): 
    13301333        """
    13311334        return self._field
    13321335
     1336    @cached_method
    13331337    def maximal_order(self):
    13341338        """
    13351339        Return the maximal order of this function field.  Since this
    class RationalFunctionField(FunctionField): 
    13451349            Maximal order in Rational function field in t over Rational Field
    13461350       
    13471351        """
    1348         try: return self._maximal_order
    1349         except AttributeError:
    1350             from function_field_order import FunctionFieldOrder_rational
    1351             self._maximal_order = FunctionFieldOrder_rational(self)
    1352             return self._maximal_order
     1352        from function_field_order import FunctionFieldOrder_rational
     1353        return FunctionFieldOrder_rational(self)
    13531354
    13541355    equation_order = maximal_order
    13551356