Ticket #10595: trac_10595-vector-constructor-empty-list.patch

File trac_10595-vector-constructor-empty-list.patch, 2.0 KB (added by Rob Beezer, 12 years ago)
  • sage/modules/free_module_element.pyx

    # HG changeset patch
    # User Rob Beezer <beezer@ups.edu>
    # Date 1294788504 28800
    # Node ID 9f650a053251fc954d2e6e26843c8e9a0795ead5
    # Parent  3b5f79f2d47e5ec182180673a97a3e7bd4fdefb1
    10595: vector constructor defaults to ZZ with empty list
    
    diff -r 3b5f79f2d47e -r 9f650a053251 sage/modules/free_module_element.pyx
    a b  
    346346        (1, 2, 3)
    347347        sage: parent(v)
    348348        Ambient free module of rank 3 over the principal ideal domain Integer Ring
     349       
     350    Am empty list, without a ring given, will default to the integers. ::
     351   
     352        sage: x = vector([]); x
     353        ()
     354        sage: x.parent()
     355        Ambient free module of rank 0 over the principal ideal domain Integer Ring
    349356    """
    350357    if hasattr(arg0, '_vector_'):
    351358        return arg0._vector_(arg1)
     
    448455    the entries in the list. If ``R`` is given, the entries
    449456    are coerced in.  Otherwise a common ring is found. For
    450457    more details, see the
    451     :class:`~sage.structure.sequence.Sequence` object.
     458    :class:`~sage.structure.sequence.Sequence` object.  When ``v``
     459    has no elements and ``R`` is ``None``, the ring returned is
     460    the integers.
    452461
    453462
    454463    EXAMPLES::
     
    477486        ...
    478487        TypeError: unable to find a common ring for all elements
    479488
     489    This checks a bug listed at Trac #10595.  Without good evidence for a ring, the default
     490    is the integers.
     491       
     492        sage: prepare([], None)
     493        ([], Integer Ring)
    480494    """
    481495    if isinstance(v, dict):
    482496        # convert to a list
     
    485499            X[key] = value
    486500        v = X
    487501    # convert to a Sequence over common ring
     502    # default to ZZ on an empty list
     503    if len(v) == 0 and R == None:
     504      R = sage.rings.integer_ring.IntegerRing()
    488505    v = Sequence(v, universe=R, use_sage_types=True)
    489506    ring = v.universe()
    490507    if not is_Ring(ring):