# 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


124  124  from sage.rings.integer cimport Integer 
125  125  
126  126  # 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, 
128  128  # and creating a category. We should rarely hit the second case 
129  129  # (is_Ring_slow below). Note that this function will slightly slow 
130  130  # down in the very rare case when R is not of type Ring, but it is in 
… 
… 

444  444  if not is_Ring(arg0): 
445  445  msg = "first argument must be base ring of zero vector, not {0}" 
446  446  raise TypeError(msg.format(arg0)) 
447   return (arg0**degree).zero_vector() 
448  447  else: 
449  448  if not isinstance(arg2, dict) and len(arg2) != degree: 
450  449  raise ValueError, "incompatible degrees in vector constructor" 
… 
… 

656  655  sage: zero_vector(x^2, 5) 
657  656  Traceback (most recent call last): 
658  657  ... 
659   TypeError: arg0 must be a ring 
 658  TypeError: first argument must be a ring 
660  659  """ 
661  660  if arg1 is None: 
662  661  # default to a zero vector over the integers (ZZ) if no ring given 
663  662  return (ZZ**arg0).zero_vector() 
664  663  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 categorytheoretic check anyways. We want to avoid 
668   # calling is_Ring. 
669  664  return (arg0**arg1).zero_vector() 
670   raise TypeError, "arg0 must be a ring" 
 665  raise TypeError, "first argument must be a ring" 
671  666  
672  667  def random_vector(ring, degree=None, *args, **kwds): 
673  668  r""" 