Ticket #11298: trac11298_singular_standard_options.rebase4.7.1.a1.patch

File trac11298_singular_standard_options.rebase4.7.1.a1.patch, 17.3 KB (added by burcin, 11 years ago)

rebased Simon's patch to 4.7.1.alpha1

  • doc/en/reference/misc.rst

    # HG changeset patch
    # User Simon King <simon.king@uni-jena.de>
    # Date 1306393520 -7200
    # Node ID ef174c01a0ecc333c1143cb62118c096e62f0c62
    # Parent  927091ce19fcc1ce512321787a7ee6f8a0f55dcb
    #11298: Improve introspection for sage.misc.decorators.sage_wraps, and use it for (lib)singular_standard_options.
    Put sage.misc.decorators into the reference manual.
    
    diff --git a/doc/en/reference/misc.rst b/doc/en/reference/misc.rst
    a b  
    88
    99   sage/misc/abstract_method
    1010   sage/misc/cachefunc
     11   sage/misc/decorators
    1112   sage/misc/classgraph
    1213   sage/misc/function_mangling
    1314   sage/misc/exceptions
  • sage/misc/decorators.py

    diff --git a/sage/misc/decorators.py b/sage/misc/decorators.py
    a b  
    66AUTHORS:
    77
    88- Tim Dumol (5 Dec 2009) -- initial version.
    9 - Johan S. R. Nielsen (2010) -- collect decorators from various modules
    10 - Johan S. R. Nielsen (8 apr 2011) -- improve introspection on decorators
     9- Johan S. R. Nielsen (2010) -- collect decorators from various modules.
     10- Johan S. R. Nielsen (8 apr 2011) -- improve introspection on decorators.
     11- Simon King (2011-05-26) -- improve introspection of sage_wraps. Put this
     12  file into the reference manual.
     13
    1114"""
    1215from functools import partial, update_wrapper, WRAPPER_ASSIGNMENTS, WRAPPER_UPDATES
    1316from copy import copy
    14 from sage.misc.sageinspect import sage_getsource
     17from sage.misc.sageinspect import sage_getsource, sage_getsourcelines
    1518from sage.misc.misc import verbose, deprecation
    1619from inspect import ArgSpec
    1720
    1821def sage_wraps(wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES):
    19     """
     22    r"""
    2023    Decorator factory which should be used in decorators for making sure that
    2124    meta-information on the decorated callables are retained through the
    2225    decorator, such that the introspection functions of
     
    3033    the special attribute ``_sage_argspec_`` of the wrapping function (for an
    3134    example, see e.g. ``@options`` decorator in this module).
    3235
    33     EXAMPLES::
     36    EXAMPLES:
    3437
    3538    Demonstrate that documentation string and source are retained from the
    36     decorated function
     39    decorated function::
    3740
    3841        sage: def square(f):
    3942        ...     @sage_wraps(f)
     
    5053        x^2
    5154        sage: g.__doc__
    5255        'My little function'
    53         sage: from sage.misc.sageinspect import sage_getsource
     56        sage: from sage.misc.sageinspect import sage_getsource, sage_getsourcelines, sage_getfile
    5457        sage: sage_getsource(g)
    5558        '@square...def g(x)...'
    5659
    5760    Demonstrate that the argument description are retained from the decorated
    58     function through the special method (when left unchanged) (see trac #9976).
     61    function through the special method (when left unchanged) (see trac #9976)::
    5962
    6063        sage: def diff_arg_dec(f):
    6164        ...     @sage_wraps(f)
     
    7376        sage: sage_getargspec(g)
    7477        ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None)
    7578
     79    Demonstrate that it correctly gets the source lines and the source
     80    file, which is essential for interactive code edition; note that we
     81    do not test the line numbers, as they may easily change::
     82
     83        sage: P.<x,y> = QQ[]
     84        sage: I = P*[x,y]
     85        sage: sage_getfile(I.interreduced_basis)
     86        '...sage/rings/polynomial/multi_polynomial_ideal.py'
     87        sage: sage_getsourcelines(I.interreduced_basis)
     88        (['    @singular_standard_options\n',
     89          '    @libsingular_standard_options\n',
     90          '    def interreduced_basis(self):\n',
     91          ...
     92          '        return ret\n'], ...)
     93
    7694    Demonstrate that sage_wraps works for non-function callables
    77     (Trac 9919)
     95    (Trac 9919)::
    7896
    7997        sage: def square_for_met(f):
    8098        ...     @sage_wraps(f)
     
    99117    def f(wrapper):
    100118        update_wrapper(wrapper, wrapped, assigned=assigned, updated=updated)
    101119        wrapper._sage_src_=lambda: sage_getsource(wrapped)
     120        wrapper._sage_src_lines_=lambda: sage_getsourcelines(wrapped)
    102121        #Getting the signature right in documentation by Sphinx (Trac 9976)
    103122        #The attribute _sage_argspec_() is read by Sphinx if present and used
    104123        #as the argspec of the function instead of using reflection.
    105         from sageinspect import sage_getargspec
     124        from sageinspect import sage_getargspec, sage_getsource
    106125        argspec = sage_getargspec(wrapped)
    107126        wrapper._sage_argspec_ = lambda: argspec
    108127        return wrapper
     
    365384    def __init__(self, name, **options):
    366385        """
    367386        A decorator for functions which collects all keywords
    368         starting with name_ and collects them into a dictionary
     387        starting with ``name+'_'`` and collects them into a dictionary
    369388        which will be passed on to the wrapped function as a
    370         dictionary called name_options.
     389        dictionary called ``name_options``.
    371390
    372391        The keyword arguments passed into the constructor are taken
    373         to be default for the name_options dictionary.
     392        to be default for the ``name_options`` dictionary.
    374393
    375394        EXAMPLES::
    376395
     
    464483            {'rgbcolor': (0, 0, 1)}
    465484
    466485        Demonstrate that the introspected argument specification of the wrapped
    467         function is updated (see trac #9976).
     486        function is updated (see trac #9976)::
    468487
    469488            sage: from sage.misc.decorators import options
    470489            sage: o = options(rgbcolor=(0,0,1))
  • sage/misc/sageinspect.py

    diff --git a/sage/misc/sageinspect.py b/sage/misc/sageinspect.py
    a b  
    13501350        ...
    13511351        '    raise ValueError, "k must be an integer or an integer + 1/2"\n'], 31)
    13521352
    1353     Here are some cases that where covered in trac ticket #11298::
     1353    Here are some cases that where covered in trac ticket #11298;
     1354    note that line numbers may easily change, and therefore we do
     1355    not test them::
    13541356
    13551357        sage: P.<x,y> = QQ[]
    13561358        sage: I = P*[x,y]
     
    13591361          "    def __init__(self, base_ring, n, names, order='degrevlex'):\n",
    13601362        ...
    13611363          '          M.append(new_MP(self, p_Copy(tempvector,_ring)))\n',
    1362           '          return M\n'], 225)
     1364          '          return M\n'], ...)
    13631365        sage: sage_getsourcelines(I)
    13641366        (['class MPolynomialIdeal( MPolynomialIdeal_singular_repr, \\\n',
    13651367        ...
    1366         '        return result_ring.ideal(result)\n'], 2612)
     1368        '        return result_ring.ideal(result)\n'], ...)
    13671369        sage: x = var('x')
    13681370        sage: sage_getsourcelines(x)
    13691371        (['cdef class Expression(CommutativeRingElement):\n',
    13701372          '    cpdef object pyobject(self):\n',
    13711373        ...
    1372           '        return self / x\n'], 191)
     1374          '        return self / x\n'], ...)
    13731375       
    13741376
    13751377    AUTHORS:
  • sage/rings/polynomial/multi_polynomial_ideal.py

    diff --git a/sage/rings/polynomial/multi_polynomial_ideal.py b/sage/rings/polynomial/multi_polynomial_ideal.py
    a b  
    424424            pass
    425425
    426426def singular_standard_options(func):
    427     """
     427    r"""
    428428    Decorator to force a reduced Singular groebner basis.
    429429   
    430430    TESTS::
     
    435435        sage: "buchberger" in sage_getsource(J.interreduced_basis)
    436436        True
    437437
     438    The following tests against a bug that was fixed in trac ticket #11298::
     439
     440        sage: from sage.misc.sageinspect import sage_getsourcelines, sage_getargspec
     441        sage: P.<x,y> = QQ[]
     442        sage: I = P*[x,y]
     443        sage: sage_getargspec(I.interreduced_basis)
     444        ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None)
     445        sage: sage_getsourcelines(I.interreduced_basis)
     446        (['    @singular_standard_options\n',
     447          '    @libsingular_standard_options\n',
     448          '    def interreduced_basis(self):\n',
     449          ...
     450          '        return ret\n'], ...)
     451
    438452    .. note::
    439453
    440454       This decorator is used automatically internally so the user
    441455       does not need to use it manually.
    442456    """
     457    from sage.misc.decorators import sage_wraps
     458    @sage_wraps(func)
    443459    def wrapper(*args, **kwds):
    444         """
    445         Execute function in ``SingularDefaultContext``.
    446         """
     460#        """
     461#        Execute function in ``SingularDefaultContext``.
     462#        """
    447463        with SingularDefaultContext():
    448464            return func(*args, **kwds)
    449 
    450     from sage.misc.sageinspect import sage_getsource
    451     wrapper._sage_src_ = lambda: sage_getsource(func)
    452     wrapper.__name__ = func.__name__
    453     wrapper.__doc__ = func.__doc__
    454465    return wrapper
    455466
    456467def libsingular_standard_options(func):
    457     """
     468    r"""
    458469    Decorator to force a reduced Singular groebner basis.
    459470
    460471    TESTS::
     
    465476        sage: "buchberger" in sage_getsource(J.interreduced_basis)
    466477        True
    467478
     479    The following tests against a bug that was fixed in trac ticket #11298::
     480
     481        sage: from sage.misc.sageinspect import sage_getsourcelines, sage_getargspec
     482        sage: P.<x,y> = QQ[]
     483        sage: I = P*[x,y]
     484        sage: sage_getargspec(I.interreduced_basis)
     485        ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None)
     486        sage: sage_getsourcelines(I.interreduced_basis)
     487        (['    @singular_standard_options\n',
     488          '    @libsingular_standard_options\n',
     489          '    def interreduced_basis(self):\n',
     490          ...
     491          '        return ret\n'], ...)
     492
    468493    .. note::
    469494
    470495       This decorator is used automatically internally so the user
    471496       does not need to use it manually.
    472497    """
     498    from sage.misc.decorators import sage_wraps
     499    @sage_wraps(func)
    473500    def wrapper(*args, **kwds):
    474501        """
    475502        Execute function in ``LibSingularDefaultContext``.
    476503        """
    477504        with LibSingularDefaultContext():
    478505            return func(*args, **kwds)
    479 
    480     from sage.misc.sageinspect import sage_getsource
    481     wrapper._sage_src_ = lambda: sage_getsource(func)
    482     wrapper.__name__ = func.__name__
    483     wrapper.__doc__ = func.__doc__
    484506    return wrapper
    485507
    486508class MagmaDefaultContext:
     
    531553    Decorator to force default options for Magma.
    532554
    533555    EXAMPLE::
     556
    534557        sage: P.<a,b,c,d,e> = PolynomialRing(GF(127))
    535558        sage: J = sage.rings.ideal.Cyclic(P).homogenize()
    536559        sage: from sage.misc.sageinspect import sage_getsource
     
    538561        True
    539562
    540563    """
     564    from sage.misc.decorators import sage_wraps
     565    @sage_wraps(func)
    541566    def wrapper(*args, **kwds):
    542567        """
    543568        Execute function in ``MagmaDefaultContext``.
    544569        """
    545570        with MagmaDefaultContext():
    546571            return func(*args, **kwds)
    547 
    548     from sage.misc.sageinspect import sage_getsource
    549     wrapper._sage_src_ = lambda: sage_getsource(func)
    550     wrapper.__name__ = func.__name__
    551     wrapper.__doc__ = func.__doc__
    552572    return wrapper
    553573
    554574class RequireField(MethodDecorator):
     
    901921            ...
    902922            ValueError: Coefficient ring must be a field for function 'complete_primary_decomposition'.
    903923       
    904         ALGORITHM: Uses Singular.
     924        ALGORITHM:
     925
     926        Uses Singular.
    905927
    906928        .. note::
    907929       
     
    977999            sage: reduce(lambda Qi,Qj: Qi.intersection(Qj), pd) == I
    9781000            True
    9791001       
    980         ALGORITHM: Uses Singular.
     1002        ALGORITHM:
     1003
     1004        Uses Singular.
    9811005       
    9821006        REFERENCES:
    9831007
     
    10411065            [Ideal (z^3 + 2, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field,
    10421066             Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field]
    10431067       
    1044         ALGORITHM: Uses Singular.
     1068        ALGORITHM:
     1069
     1070        Uses Singular.
    10451071       
    10461072        REFERENCES:
    10471073
     
    12521278            verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation.
    12531279            2
    12541280
    1255         ALGORITHM: Uses Singular, unless the characteristic is too large.
     1281        ALGORITHM:
     1282
     1283        Uses Singular, unless the characteristic is too large.
    12561284
    12571285        .. note::
    12581286
     
    13211349        Return the vector space dimension of the ring modulo this ideal. If
    13221350        the ideal is not zero-dimensional, a TypeError is raised.
    13231351       
    1324         ALGORITHM: Uses Singular.
     1352        ALGORITHM:
     1353
     1354        Uses Singular.
    13251355       
    13261356        EXAMPLE::
    13271357       
     
    13951425             b*d^4 - b + d^5 - d, b*c - b*d + c^2*d^4 + c*d - 2*d^2,
    13961426             b^2 + 2*b*d + d^2, a + b + c + d]
    13971427       
    1398         ALGORITHM: Uses Singular.
     1428        ALGORITHM:
     1429
     1430        Uses Singular.
    13991431       
    14001432        .. note::
    14011433
     
    15411573            b*d^4 - b + d^5 - d, b*c - b*d + c^2*d^4 + c*d - 2*d^2,
    15421574            b^2 + 2*b*d + d^2, a + b + c + d]
    15431575       
    1544         ALGORITHM: Uses libSINGULAR.
     1576        ALGORITHM:
     1577
     1578        Uses libSINGULAR.
    15451579        """
    15461580        from sage.rings.polynomial.multi_polynomial_ideal_libsingular import std_libsingular, slimgb_libsingular
    15471581        from sage.libs.singular import singular_function
     
    16601694            of Multivariate Polynomial Ring in x, y, z over Rational
    16611695            Field]
    16621696       
    1663         ALGORITHM: Uses Singular.
     1697        ALGORITHM:
     1698
     1699        Uses Singular.
    16641700        """
    16651701        import sage.libs.singular
    16661702        minAssGTZ = sage.libs.singular.ff.primdec__lib.minAssGTZ
     
    17501786            sage: I.integral_closure()
    17511787            [x^2, y^5, -x*y^3]
    17521788       
    1753         ALGORITHM: Use libSingular
     1789        ALGORITHM:
     1790
     1791        Uses libSINGULAR.
    17541792        """
    17551793        from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
    17561794
     
    17801818            sage: M*G
    17811819            (0, 0)
    17821820       
    1783         ALGORITHM: Uses Singular's syz command
     1821        ALGORITHM:
     1822
     1823        Uses Singular's syz command.
    17841824        """
    17851825        import sage.libs.singular
    17861826        syz = sage.libs.singular.ff.syz
     
    18721912            sage: I.interreduced_basis()
    18731913            [x]
    18741914       
    1875         ALGORITHM: Uses Singular's interred command or
     1915        ALGORITHM:
     1916
     1917        Uses Singular's interred command or
    18761918        :func:`sage.rings.polynomial.toy_buchberger.inter_reduction``
    18771919        if conversion to Singular fails.
    18781920        """
     
    19171959       
    19181960            S * G = \sum_{i=0}^{m} h_ig_i ---->_G 0.
    19191961       
    1920         ALGORITHM: Uses Singular
     1962        ALGORITHM:
     1963
     1964        Uses Singular.
    19211965       
    19221966        EXAMPLE::
    19231967       
     
    20702114             y^9 - y^7*x^2 - y^7*x - y^6*x^3 - y^6*x^2 - 3*y^6 - 3*y^5*x - y^3*x^7 - 3*y^3*x^6
    20712115             - 3*y^3*x^5 - y^3*x^4 - 9*y^2*x^5 - 18*y^2*x^4 - 9*y^2*x^3 - 27*y*x^3 - 27*y*x^2 - 27*x]
    20722116
    2073         ALGORITHM: Uses Singular
     2117        ALGORITHM:
     2118
     2119        Uses Singular.
    20742120        """
    20752121        from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
    20762122        R = self.ring()
     
    21212167            Ideal (y^2 - x*z, x*y - z, x^2 - y) of Multivariate
    21222168            Polynomial Ring in x, y, t, s, z over Rational Field
    21232169       
    2124         ALGORITHM: Uses SINGULAR
     2170        ALGORITHM:
     2171
     2172        Uses Singular.
    21252173       
    21262174        .. note::
    21272175
     
    23842432            sage: I.variety()
    23852433            [...{y: -q^3, x: 0}...]
    23862434       
    2387         ALGORITHM: Uses triangular decomposition.
     2435        ALGORITHM:
     2436
     2437        Uses triangular decomposition.
    23882438        """
    23892439        def _variety(T, V, v=None):
    23902440            """
     
    25372587        in case it is finite dimensional and if the input is a standard
    25382588        basis with respect to the ring ordering.
    25392589       
    2540         INPUT: algorithm - defaults to use libsingular, if it is anything
    2541         else we will use the kbase() command
     2590        INPUT:
     2591
     2592        ``algorithm`` - defaults to use libsingular, if it is anything
     2593        else we will use the ``kbase()`` command
    25422594       
    25432595        EXAMPLES::
    25442596       
     
    26022654        Return the Groebner basis for this ideal, computed using
    26032655        Macaulay2.
    26042656       
    2605         ALGORITHM: Computed using Macaulay2. A big advantage of Macaulay2
    2606         is that it can compute the Groebner basis of ideals in polynomial rings
    2607         over the integers.
     2657        ALGORITHM:
     2658
     2659        Computed using Macaulay2. A big advantage of Macaulay2 is that
     2660        it can compute the Groebner basis of ideals in polynomial
     2661        rings over the integers.
    26082662       
    26092663        EXAMPLE::
    26102664       
     
    26872741        Return a set of generators / a basis of self. This is usually the
    26882742        set of generators provided during object creation.
    26892743     
    2690         EXAMPLE:
     2744        EXAMPLE::
    26912745     
    26922746           sage: P.<x,y> = PolynomialRing(QQ,2)
    26932747           sage: I = Ideal([x,y+1]); I
     
    30813135            Y^2 + (-3/5)*Z^2 + (2/5*t^2 - 2/5*t + 1/15)*Y + (-2/5*t^2 + 2/5*t - 1/15)*Z - 1/10*t^4 + 1/5*t^3 - 7/30*t^2 + 2/5*t + 11/90,
    30823136            Y*Z + 6/5*Z^2 + (1/5*t^2 - 1/5*t + 1/30)*Y + (4/5*t^2 - 4/5*t + 2/15)*Z + 1/5*t^4 - 2/5*t^3 + 7/15*t^2 - 3/10*t - 11/45, X + 2*Y + 2*Z + t^2 - t - 1/3]
    30833137
    3084         ALGORITHM: Uses Singular, Magma (if available), Macaulay2 (if
    3085         available), or a toy implementation.
     3138        ALGORITHM:
     3139
     3140        Uses Singular, Magma (if available), Macaulay2 (if available),
     3141        or a toy implementation.
    30863142        """
    30873143        from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
    30883144        from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence