Ticket #3704: trac-3704-diagonal_matrix-2.patch

File trac-3704-diagonal_matrix-2.patch, 1.3 KB (added by jason, 13 years ago)
  • sage/matrix/constructor.py

    # HG changeset patch
    # User Jason Grout <jason-sage@creativetrax.com>
    # Date 1218844983 18000
    # Node ID 8f16ef06b1a85823913a55d29f2c0662976069b0
    # Parent  ae243fa83947454694c539f374acabbe5ab5a2b1
    [mq]: trac-3704-diagonal_matrix-2.patch
    
    diff -r ae243fa83947 -r 8f16ef06b1a8 sage/matrix/constructor.py
    a b  
    696696        [0 0 3]
    697697        sage: a.parent()
    698698        Full MatrixSpace of 3 by 3 dense matrices over Rational Field
     699        sage: a = diagonal_matrix(v, sparse=True); a
     700        [1 0 0]
     701        [0 2 0]
     702        [0 0 3]
     703        sage: a.parent()
     704        Full MatrixSpace of 3 by 3 sparse matrices over Rational Field
    699705    """
    700706
    701707    args = list(args)
     
    708714    # Because we specify the diagonal entries as a dictionary,
    709715    # matrix() wants to default to sparse.  We want dense as a default,
    710716    # though, so we have to specifically test for the sparse keyword.
    711     sparse = kwds.pop('sparse',False)
    712     kwds['sparse'] = sparse
     717    kwds.setdefault('sparse', False)
    713718   
    714719    # If the first item in args is a list or tuple, use that as the diagonal
    715720    # Otherwise, assume that the entire list is the diagonal.