Ticket #12480: 12480_review.patch

File 12480_review.patch, 14.9 KB (added by jdemeyer, 9 years ago)

Reviewer patch, apply on top of previous

  • sage/rings/padics/padic_ZZ_pX_CR_element.pyx

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1330936876 -3600
    # Node ID 3dbf6aa6b0e0e9c7f5211eef7473593086e09f0a
    # Parent  ba343d5c47e84c15f5ca979b5b4b03bd2ce5c638
    Reviewer patch: clean up documentation strings and exceptions
    
    diff --git a/sage/rings/padics/padic_ZZ_pX_CR_element.pyx b/sage/rings/padics/padic_ZZ_pX_CR_element.pyx
    a b  
    13051305            w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25)       
    13061306        """
    13071307        if self.relprec == 0:
    1308             raise RuntimeError("p-adic Internal l-shift called with relative precision 0")
     1308            raise ValueError("p-adic Internal l-shift called with relative precision 0")
    13091309        cdef ZZ_pX_c tmpP
    13101310        cdef ZZ_pX_Modulus_c* mod
    13111311        if self.prime_pow.e == 1:
     
    13641364                elif PY_TYPE_CHECK(self.prime_pow, PowComputer_ZZ_pX_small_Eis):
    13651365                    high_array = (<PowComputer_ZZ_pX_small_Eis>self.prime_pow).high_shifter
    13661366                else:
    1367                     raise RuntimeError, "unrecognized PowComputer type"                   
     1367                    raise TypeError("unrecognized PowComputer type")
    13681368                ZZ_pX_conv_modulus(high_shifter, high_array[0], c.x)
    13691369                ZZ_pX_InvMod_newton_ram(high_shifter, high_shifter, modulus[0], c.x)
    13701370                ZZ_pX_PowerMod_long_pre(high_shifter, high_shifter, shift, modulus[0])
     
    14021402                    high_array = (<PowComputer_ZZ_pX_small_Eis>self.prime_pow).high_shifter
    14031403                    high_length = (<PowComputer_ZZ_pX_small_Eis>self.prime_pow).high_length
    14041404                else:
    1405                     raise RuntimeError, "unrecognized PowComputer type"
     1405                    raise TypeError("unrecognized PowComputer type")
    14061406                if shift >= self.prime_pow.prec_cap:
    14071407                    # high_shifter = p^(2^(high_length - 1))/x^(e*2^(high_length - 1))
    14081408                    ZZ_pX_conv_modulus(high_shifter, high_array[high_length-1], c.x)
     
    31393139                elif PY_TYPE_CHECK(self.prime_pow, PowComputer_ZZ_pX_big_Eis):
    31403140                    ZZ_pX_conv_modulus(to_mul, (<PowComputer_ZZ_pX_big_Eis>self.prime_pow).high_shifter[0], self.prime_pow.get_context_capdiv(ans_rprec).x)
    31413141                else:
    3142                     raise RuntimeError, "unrecognized PowComputer type"
     3142                    raise TypeError("unrecognized PowComputer type")
    31433143                sig_on()
    31443144                ZZ_pX_InvMod_newton_ram(to_mul, to_mul, self.prime_pow.get_modulus_capdiv(ans_rprec)[0], self.prime_pow.get_context_capdiv(ans_rprec).x)
    31453145                sig_off()
     
    31843184                elif PY_TYPE_CHECK(self.prime_pow, PowComputer_ZZ_pX_big_Eis):
    31853185                    ZZ_pX_conv_modulus(to_mul, (<PowComputer_ZZ_pX_big_Eis>self.prime_pow).high_shifter[0], self.prime_pow.get_context_capdiv(ans_rprec).x)
    31863186                else:
    3187                     raise RuntimeError, "unrecognized PowComputer type"
     3187                    raise TypeError("unrecognized PowComputer type")
    31883188                sig_on()
    31893189                ZZ_pX_InvMod_newton_ram(to_mul, to_mul, self.prime_pow.get_modulus_capdiv(ans_rprec)[0], self.prime_pow.get_context_capdiv(ans_rprec).x)
    31903190                sig_off()
  • sage/rings/padics/pow_computer_ext.pyx

    diff --git a/sage/rings/padics/pow_computer_ext.pyx b/sage/rings/padics/pow_computer_ext.pyx
    a b  
    6565    """
    6666    Precomputes quantities for shifting right in Eisenstein extensions.
    6767
    68     INPUT::
     68    INPUT:
    6969   
    70         - prime_pow -- the PowComputer to be initialized
    71         - shift_seed -- x^e/p as a polynomial of degree at most e-1 in x.
     70    - ``prime_pow`` -- the PowComputer to be initialized
     71    - ``shift_seed`` -- x^e/p as a polynomial of degree at most e-1 in x.
    7272
    7373    EXAMPLES::
    7474
     
    171171        low_shifter_p = (<PowComputer_ZZ_pX_big_Eis>prime_pow).low_shifter
    172172        high_shifter_p = (<PowComputer_ZZ_pX_big_Eis>prime_pow).high_shifter
    173173    else:
    174         raise RuntimeError, "unrecognized Eisenstein type"
     174        raise TypeError("unrecognized Eisenstein type")
    175175       
    176176    cdef long i
    177177    cdef ZZ_pX_c tmp, modup, into_multiplier, shift_seed_inv
     
    352352        high_length = (<PowComputer_ZZ_pX_FM_Eis>self).high_length
    353353        fm = True
    354354    else:
    355         raise RuntimeError, "inconsistent type"
     355        raise TypeError("inconsistent type")
    356356   
    357357    cdef ntl_ZZ_pX printer
    358358    if n < 0:
     
    608608        """
    609609        # READ THE DOCSTRING
    610610        if n < 0:
    611             raise ValueError, "n must be positive"
     611            # Exception will be ignored by Cython
     612            raise ValueError("n must be positive")
    612613        if n <= self.cache_limit:
    613614            ZZ_to_mpz(&self.temp_m, &(self.small_powers[n]))
    614615        elif n == self.prec_cap:
     
    653654            625
    654655        """
    655656        if n < 0:
    656             raise ValueError, "n must be positive"
     657            # Exception will be ignored by Cython
     658            raise ValueError("n must be positive")
    657659        if n <= self.cache_limit:
    658660            return &(self.small_powers[n])
    659661        if n == self.prec_cap:
     
    820822        if n < 0:
    821823            n = -n
    822824        elif n == 0:
    823             raise ValueError, "n must be nonzero"
     825            # Exception will be ignored by Cython
     826            raise ValueError("n must be nonzero")
    824827        pn.x = self.pow_ZZ_tmp(n)[0]
    825828        cdef ntl_ZZ_pContext_class context = (<ntl_ZZ_pContext_factory>ZZ_pContext_factory).make_c(pn)
    826829        return context
     
    873876        """
    874877        Runs a speed test.
    875878
    876         INPUT::
     879        INPUT:
    877880       
    878             n -- input to a function to be tested (the function needs to be set in the source code).
    879             runs -- The number of runs of that function
     881        - ``n`` -- input to a function to be tested (the function needs to be set in the source code).
     882        - ``runs`` -- The number of runs of that function
    880883       
    881         OUTPUT::
     884        OUTPUT:
    882885       
    883             The time in seconds that it takes to call the function on n, runs times.
     886        - The time in seconds that it takes to call the function on ``n``,
     887          ``runs`` times.
     888
     889        EXAMPLES::
    884890
    885891            sage: PC = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5, 0, 1], 5^10), 'small', 'e',ntl.ZZ_pX([1],5^10))
    886892            sage: PC.speed_test(10, 10^6) # random
     
    9991005            sage: A._get_modulus_test(a, b, 2) # indirect doctest
    10001006            [4 24]
    10011007        """
     1008        # Exception will be ignored by Cython
    10021009        raise NotImplementedError
    10031010
    10041011    def _get_modulus_test(self, ntl_ZZ_pX a, ntl_ZZ_pX b, Integer n):
     
    10531060            sage: A._get_top_modulus_test(a, b) #indirect doctest
    10541061            [1783058 7785200]         
    10551062        """
     1063        # Exception will be ignored by Cython
    10561064        raise NotImplementedError
    10571065
    10581066    def _get_top_modulus_test(self, ntl_ZZ_pX a, ntl_ZZ_pX b):
     
    11371145
    11381146        Does not affect self.
    11391147       
    1140         INPUT::
     1148        INPUT:
    11411149
    1142             - x -- The ZZ_pX_c to be set
     1150        - ``x`` -- The ``ZZ_pX_c`` to be set
    11431151           
    1144             - a -- A ZZ_pX_c currently holding an approximation to the
    1145              Teichmuller representative (this approximation can be any
    1146              integer).  It will be set to the actual Teichmuller lift
     1152        - ``a`` -- A ``ZZ_pX_c`` ``currently holding an approximation to the
     1153          Teichmuller representative (this approximation can be any
     1154          integer).  It will be set to the actual Teichmuller lift
    11471155
    1148             - absprec -- the desired precision of the Teichmuller lift
     1156        - ``absprec`` -- the desired precision of the Teichmuller lift
    11491157
    1150         OUTPUT::
     1158        OUTPUT:
    11511159       
    1152             - 1 -- x should be set to zero (or usually, ZZ_pX_destruct'd)
    1153             - 0 -- normal
     1160        - 1 -- x should be set to zero (or usually, ZZ_pX_destruct'd)
     1161        - 0 -- normal
    11541162
    11551163        EXAMPLES::
    11561164       
     
    13581366        """
    13591367        Duplicates functionality of get_top_modulus if n == self.prec_cap.
    13601368
    1361         If not, raises an error.
     1369        If not, raise an exception (which will be ignored by Cython).
    13621370
    13631371        EXAMPLES::
    13641372       
     
    13711379        if n == self.prec_cap:
    13721380            return &self.mod
    13731381        else:
    1374             raise ValueError, "fixed modulus PowComputers only store top modulus"
     1382            # Exception will be ignored by Cython
     1383            raise ValueError("fixed modulus PowComputers only store top modulus")
    13751384
    13761385cdef class PowComputer_ZZ_pX_FM_Eis(PowComputer_ZZ_pX_FM):
    13771386    """
     
    17181727
    17191728    cdef ntl_ZZ_pContext_class get_context(self, long n):
    17201729        """
    1721         Returns the context for p^n.
     1730        Return the context for p^n.  This will use the cache if
     1731        ``abs(n) <= self.cache_limit``.
    17221732
    1723         Note that this function will raise an Index error if n > self.cache_limit.
    1724         Also, it will return None on input 0
    1725 
    1726         INPUT::
     1733        INPUT:
    17271734       
    1728             - n -- A long between 1 and self.cache_limit, inclusive
     1735        - ``n`` -- A nonzero long
    17291736           
    1730         OUTPUT::
     1737        OUTPUT:
    17311738       
    1732             A context for p^n
     1739        - A context for p^n
    17331740
    17341741        EXAMPLES::
    17351742       
     
    17461753
    17471754    cdef restore_context(self, long n):
    17481755        """
    1749         Restores the context for p^n.
     1756        Restore the context for p^n.  This will use the cache if
     1757        ``abs(n) <= self.cache_limit``.
    17501758
    1751         INPUT::
     1759        INPUT:
    17521760       
    1753             - n -- A long between 1 and self.cache_limit, inclusive
     1761        - ``n`` -- A nonzero long
    17541762
    17551763        EXAMPLES::
    17561764       
     
    17911799        """
    17921800        Returns the modulus corresponding to self.polynomial() (mod self.prime^n).
    17931801
    1794         INPUT::
     1802        INPUT:
    17951803       
    1796             - n -- A long between 1 and self.cache_limit, inclusive if
    1797                    n is larger, this function will return
    1798                    self.mod[prec_cap] lifted to that precision.
     1804        - ``n`` -- A long between 1 and ``self.cache_limit``, inclusive.
     1805          If `n` is larger, this function will return ``self.mod[prec_cap]``
     1806          lifted to that precision.
    17991807
    18001808        EXAMPLES::
    18011809       
     
    21422150        """
    21432151        Returns the context for p^n.
    21442152
    2145         Note that this function will raise an Index error if n > self.cache_limit.
    2146         Also, it will return None on input 0
     2153        INPUT:
     2154       
     2155        - ``n`` -- A nonzero long
    21472156
    2148         INPUT::
     2157        OUTPUT:
    21492158       
    2150             n -- A nonzero long
    2151 
    2152         OUTPUT::
    2153        
    2154             A context for p^n
     2159        - A context for p^n
    21552160
    21562161        EXAMPLES::
    21572162       
     
    21622167            NTL modulus 390625
    21632168        """
    21642169        if n == 0:
    2165             raise ValueError, "n must be nonzero"
     2170            # Exception will be ignored by Cython
     2171            raise ValueError("n must be nonzero")
    21662172        if n < 0:
    21672173            n = -n
    21682174        if n <= self.cache_limit:
     
    22032209        """
    22042210        Returns the modulus corresponding to self.polynomial() (mod self.prime^n).
    22052211
    2206         INPUT::
     2212        INPUT:
    22072213       
    2208             n -- A nonzero long
     2214        - ``n`` -- A nonzero long
    22092215
    22102216        EXAMPLES::
    22112217       
     
    22252231        cdef ntl_ZZ_pX_Modulus holder
    22262232        cdef ntl_ZZ_pContext_class c
    22272233        if n == 0:
    2228             raise ValueError, "n must be nonzero"
     2234            # Exception will be ignored by Cython
     2235            raise ValueError("n must be nonzero")
    22292236        if n < 0:
    22302237            n = -n
    22312238        elif n <= self.cache_limit:
     
    24182425    Once you create a PowComputer, merely call it to get values out.
    24192426    You can input any integer, even if it's outside of the precomputed range.
    24202427
    2421     INPUT::
     2428    INPUT:
    24222429   
    2423         - prime -- An integer, the base that you want to exponentiate.
     2430    - ``prime`` -- An integer, the base that you want to exponentiate.
    24242431
    2425         - cache_limit -- A positive integer that you want to cache
    2426           powers up to.
     2432    - ``cache_limit`` -- A positive integer that you want to cache
     2433      powers up to.
    24272434
    2428         - prec_cap -- The cap on precisions of elements.  For ramified
    2429           extensions, p^((prec_cap - 1) // e) will be the largest
    2430           power of p distinguishable from zero
     2435    - ``prec_cap`` -- The cap on precisions of elements.  For ramified
     2436      extensions, p^((prec_cap - 1) // e) will be the largest
     2437      power of p distinguishable from zero
    24312438
    2432         - in_field -- Boolean indicating whether this PowComputer is
    2433           attached to a field or not.
     2439    - ``in_field`` -- Boolean indicating whether this PowComputer is
     2440      attached to a field or not.
    24342441
    2435         - poly -- An ntl_ZZ_pX or ntl_ZZ_pEX defining the extension.
    2436           It should be defined modulo p^((prec_cap - 1) // e + 1)
     2442    - ``poly`` -- An ``ntl_ZZ_pX`` or ``ntl_ZZ_pEX`` defining the extension.
     2443      It should be defined modulo p^((prec_cap - 1) // e + 1)
    24372444
    2438         - prec_type -- 'FM', 'small', or 'big', defining how caching
    2439           is done.
     2445    - ``prec_type`` -- 'FM', 'small', or 'big', defining how caching
     2446      is done.
    24402447
    2441         - ext_type -- 'u' = unramified, 'e' = Eisenstein, 't' =
    2442           two-step
     2448    - ``ext_type`` -- 'u' = unramified, 'e' = Eisenstein, 't' =
     2449      two-step
    24432450
    2444         - shift_seed -- (required only for Eisenstein and two-step)
    2445           For Eisenstein and two-step extensions, if f = a_n x^n - p
    2446           a_{n-1} x^{n-1} - ... - p a_0 with a_n a unit, then
    2447           shift_seed should be 1/a_n (a_{n-1} x^{n-1} + ... + a_0)
     2451    - ``shift_seed`` -- (required only for Eisenstein and two-step)
     2452      For Eisenstein and two-step extensions, if f = a_n x^n - p
     2453      a_{n-1} x^{n-1} - ... - p a_0 with a_n a unit, then
     2454      shift_seed should be 1/a_n (a_{n-1} x^{n-1} + ... + a_0)
    24482455               
    24492456    EXAMPLES::
    24502457   
     
    24582465    cdef long _ram_prec_cap = mpz_get_si((<Integer>Integer(ram_prec_cap)).value)
    24592466    cdef bint inf = in_field
    24602467    if ext_type != "u" and shift_seed is None:
    2461         raise ValueError, "must provide shift seed"
     2468        raise ValueError("must provide shift seed")
    24622469    if prec_type == "small" and ext_type == "u":
    24632470        return PowComputer_ZZ_pX_small(_prime, _cache_limit, _prec_cap, _ram_prec_cap, inf, poly, None)
    24642471    elif prec_type == "small" and ext_type == "e":
     
    24722479    elif prec_type == "FM" and ext_type == "e":
    24732480        return PowComputer_ZZ_pX_FM_Eis(_prime, _cache_limit, _prec_cap, _ram_prec_cap, inf, poly, shift_seed)
    24742481    else:
    2475         raise ValueError, "prec_type must be one of 'small', 'big' or 'FM' and ext_type must be one of 'u' or 'e' or 't'"
     2482        raise ValueError("prec_type must be one of 'small', 'big' or 'FM' and ext_type must be one of 'u' or 'e' or 't'")
    24762483