Ticket #11657: trac_11657-zero-vector-edits.patch

File trac_11657-zero-vector-edits.patch, 2.0 KB (added by rbeezer, 11 years ago)
  • sage/modules/free_module_element.pyx

    # HG changeset patch
    # User Rob Beezer <beezer@ups.edu>
    # Date 1314228524 25200
    # Node ID 1291d8f0943945d62d33a6eb472dae07d9797a67
    # Parent  dcd8f9489abe84cf4796325776f324fcdd311f2b
    11657: zero vector creation edits
    
    diff --git a/sage/modules/free_module_element.pyx b/sage/modules/free_module_element.pyx
    a b  
    124124from sage.rings.integer cimport Integer
    125125
    126126# We define our own faster is_Ring since is_Ring in the
    127 # sage.rings.ring module is slowedue to it doing an import every time,
     127# sage.rings.ring module is slow due to it doing an import every time,
    128128# and creating a category.  We should rarely hit the second case
    129129# (is_Ring_slow below).  Note that this function will slightly slow
    130130# down in the very rare case when R is not of type Ring, but it is in
     
    444444            if not is_Ring(arg0):
    445445                msg = "first argument must be base ring of zero vector, not {0}"
    446446                raise TypeError(msg.format(arg0))
    447             return (arg0**degree).zero_vector()
    448447        else:
    449448            if not isinstance(arg2, dict) and len(arg2) != degree:
    450449                raise ValueError, "incompatible degrees in vector constructor"
     
    656655        sage: zero_vector(x^2, 5)
    657656        Traceback (most recent call last):
    658657        ...
    659         TypeError: arg0 must be a ring
     658        TypeError: first argument must be a ring
    660659    """
    661660    if arg1 is None:
    662661        # default to a zero vector over the integers (ZZ) if no ring given
    663662        return (ZZ**arg0).zero_vector()
    664663    if is_Ring(arg0):
    665         # NOTE: The "or" above is for speed reasons: is_Ring only called in
    666         # when not a ring (slow path, get error), or when is_Ring would do
    667         # some slow category-theoretic check anyways.  We want to avoid
    668         # calling is_Ring.
    669664        return (arg0**arg1).zero_vector()
    670     raise TypeError, "arg0 must be a ring"
     665    raise TypeError, "first argument must be a ring"
    671666
    672667def random_vector(ring, degree=None, *args, **kwds):
    673668    r"""