Ticket #4492: trac_4492.patch

File trac_4492.patch, 1.9 KB (added by was, 12 years ago)

apply *only* this patch (don't apply wjp's)

  • sage/matrix/constructor.py

    # HG changeset patch
    # User sdietzel@cs.washington.edu
    # Date 1264532149 28800
    # Node ID a4965379b84fa1ba9539f018c3da09cd29f15619
    # Parent  6c6a92e8529335ffd28f3b40f1f691055f5e3c08
    trac 4492 -- block_matrix reacts inconsistently with 0.
    
    diff -r 6c6a92e85293 -r a4965379b84f sage/matrix/constructor.py
    a b  
    990990   
    991991    One can use constant entries::
    992992   
    993         sage: block_matrix([1, A, 0, 1])
    994         [ 1  0| 3  9]
    995         [ 0  1| 6 10]
    996         [-----+-----]
    997         [ 0  0| 1  0]
    998         [ 0  0| 0  1]
     993        sage: block_matrix([1, A, 0, -2/3])
     994        [   1    0|   3    9]
     995        [   0    1|   6   10]
     996        [---------+---------]
     997        [   0    0|-2/3    0]
     998        [   0    0|   0 -2/3]
     999
     1000    A zero entry may represent a square or non-square zero matrix.
     1001    Note that in the first ambiguous example below this function turns
     1002    0 into a square matrix.  However, in the second example, the
     1003    dimensions of the 0 matrices are not ambiguous::
     1004
     1005        sage: A = matrix(QQ, 2, 2, [3,9,6,10])
     1006        sage: block_matrix([0, A, 0, A])
     1007        [ 0  0| 3  9]
     1008        [ 0  0| 6 10]
     1009        [-----+-----]
     1010        [ 0  0| 3  9]
     1011        [ 0  0| 6 10]
     1012        sage: B = matrix(QQ, 1, 1, [ 1 ] )
     1013        sage: block_matrix([B, 0, 0, A])
     1014        [ 1| 0  0]
     1015        [--+-----]
     1016        [ 0| 3  9]
     1017        [ 0| 6 10]
    9991018   
    10001019    One can specify the number of rows or columns (optional for square
    10011020    number of matrices)::
     
    10691088        for i in range(nrows):
    10701089            for j in range(0, ncols):
    10711090                x = sub_matrices[i*ncols+j]
    1072                 if not is_Matrix(x) and x: # must be square matrix
     1091                if not is_Matrix(x): # we make a square matrix in ambiguous cases, as documented above
    10731092                    if row_heights[i] is None:
    10741093                        row_heights[i] = col_widths[j]
    10751094                    if col_widths[j] is None: