Ticket #11721: trac_11721-matrix-arguments.patch

File trac_11721-matrix-arguments.patch, 5.1 KB (added by rbeezer, 10 years ago)
  • sage/matrix/constructor.py

    # HG changeset patch
    # User Rob Beezer <beezer@ups.edu>
    # Date 1314119608 25200
    # Node ID 40d277b3d6c2f4f69cf6b787903a47c1379663f8
    # Parent  2a2abbcad325ccca9399981ceddf5897eb467e64
    11721: arguments to matrix rows(), columns(), jordan_block()
    
    diff --git a/sage/matrix/constructor.py b/sage/matrix/constructor.py
    a b  
    26542654
    26552655def jordan_block(eigenvalue, size, sparse=False):
    26562656    r"""
    2657     Form the Jordan block with the specified size associated with the
    2658     eigenvalue.
     2657    Returns the Jordan block for the given eigenvalue with given size.
    26592658   
    26602659    INPUT:
    26612660   
    2662    
    2663     -  ``eigenvalue`` - eigenvalue for the diagonal entries
    2664        of the block
    2665    
    2666     -  ``size`` - size of the Jordan block
    2667    
    2668     -  ``sparse`` - (default False) if True, return a
    2669        sparse matrix
     2661    -  ``eigenvalue`` - eigenvalue for the diagonal entries of the block
     2662    -  ``size`` - size of the square matrix
     2663    -  ``sparse`` - (default: False) - if True, return a sparse matrix
    26702664   
    26712665   
    26722666    EXAMPLE::
     
    26752669        [5 1 0]
    26762670        [0 5 1]
    26772671        [0 0 5]
     2672       
     2673    TESTS::
     2674   
     2675        sage: jordan_block(6.2, 'junk')
     2676        Traceback (most recent call last):
     2677        ...
     2678        TypeError: size of Jordan block needs to be an integer, not junk
     2679        sage: jordan_block(6.2, -1)
     2680        Traceback (most recent call last):
     2681        ...
     2682        ValueError: size of Jordan block must be non-negative, not -1
    26782683    """
     2684    try:
     2685        size = ZZ(size)
     2686    except TypeError:
     2687        msg = "size of Jordan block needs to be an integer, not {0}"
     2688        raise TypeError(msg.format(size))
     2689    if size < 0:
     2690        msg = "size of Jordan block must be non-negative, not {0}"
     2691        raise ValueError(msg.format(size))
    26792692    block = diagonal_matrix([eigenvalue]*size, sparse=sparse)
    26802693    for i in xrange(size-1):
    26812694        block[i,i+1]=1
  • sage/matrix/matrix1.pyx

    diff --git a/sage/matrix/matrix1.pyx b/sage/matrix/matrix1.pyx
    a b  
    559559    #############################################################################################
    560560
    561561    def columns(self, copy=True):
    562         """
     562        r"""
    563563        Return a list of the columns of self.
    564564
    565565        INPUT:
    566566
    567567        - ``copy`` - (default: True) if True, return a copy of the list
    568            of columns which is safe to change.
     568          of columns which is safe to change.
    569569
    570         If self is sparse, returns columns as sparse vectors, and if self
    571         is dense returns them as dense vectors.
     570        If ``self`` is a sparse matrix, columns are returned as sparse vectors,
     571        otherwise returned vectors are dense.
    572572
    573573        EXAMPLES::
    574574
     
    583583            sage: m = matrix(RR, 3, 3, {(1,2): pi, (2, 2): -1, (0,1): sqrt(2)})
    584584            sage: parent(m.columns()[0])
    585585            Sparse vector space of dimension 3 over Real Field with 53 bits of precision
     586
     587        Sparse matrices produce sparse columns.  ::
     588       
     589            sage: A = matrix(QQ, 2, range(4), sparse=True)
     590            sage: v = A.columns()[0]
     591            sage: v.is_sparse()
     592            True
     593
     594        TESTS::
     595       
     596            sage: A = matrix(QQ, 4, range(16))
     597            sage: A.columns('junk')
     598            Traceback (most recent call last):
     599            ...
     600            ValueError: 'copy' must be True or False, not junk
    586601        """
     602        if not copy in [True, False]:
     603            msg = "'copy' must be True or False, not {0}"
     604            raise ValueError(msg.format(copy))
    587605        x = self.fetch('columns')
    588606        if not x is None:
    589607            if copy: return list(x)
     
    597615        return columns
    598616
    599617    def rows(self, copy=True):
    600         """
     618        r"""
    601619        Return a list of the rows of self.
    602620
    603621        INPUT:
     
    605623        - ``copy`` - (default: True) if True, return a copy of the list
    606624          of rows which is safe to change.
    607625
    608         If self is sparse, returns rows as sparse vectors, and if self is
    609         dense returns them as dense vectors.
     626        If ``self`` is a sparse matrix, rows are returned as sparse vectors,
     627        otherwise returned vectors are dense.
    610628
    611629        EXAMPLES::
    612630
     
    621639            sage: m = matrix(RR, 3, 3, {(1,2): pi, (2, 2): -1, (0,1): sqrt(2)})
    622640            sage: parent(m.rows()[0])
    623641            Sparse vector space of dimension 3 over Real Field with 53 bits of precision
     642
     643        Sparse matrices produce sparse rows.  ::
     644       
     645            sage: A = matrix(QQ, 2, range(4), sparse=True)
     646            sage: v = A.rows()[0]
     647            sage: v.is_sparse()
     648            True
     649
     650        TESTS::
     651       
     652            sage: A = matrix(QQ, 4, range(16))
     653            sage: A.rows('junk')
     654            Traceback (most recent call last):
     655            ...
     656            ValueError: 'copy' must be True or False, not junk
    624657        """
     658        if not copy in [True, False]:
     659            msg = "'copy' must be True or False, not {0}"
     660            raise ValueError(msg.format(copy))
    625661        x = self.fetch('rows')
    626662        if not x is None:
    627663            if copy: return list(x)