# 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 One can use constant entries:: sage: block_matrix([1, A, 0, 1]) [ 1  0| 3  9] [ 0  1| 6 10] [-----+-----] [ 0  0| 1  0] [ 0  0| 0  1] sage: block_matrix([1, A, 0, -2/3]) [   1    0|   3    9] [   0    1|   6   10] [---------+---------] [   0    0|-2/3    0] [   0    0|   0 -2/3] A zero entry may represent a square or non-square zero matrix. Note that in the first ambiguous example below this function turns 0 into a square matrix.  However, in the second example, the dimensions of the 0 matrices are not ambiguous:: sage: A = matrix(QQ, 2, 2, [3,9,6,10]) sage: block_matrix([0, A, 0, A]) [ 0  0| 3  9] [ 0  0| 6 10] [-----+-----] [ 0  0| 3  9] [ 0  0| 6 10] sage: B = matrix(QQ, 1, 1, [ 1 ] ) sage: block_matrix([B, 0, 0, A]) [ 1| 0  0] [--+-----] [ 0| 3  9] [ 0| 6 10] One can specify the number of rows or columns (optional for square number of matrices):: for i in range(nrows): for j in range(0, ncols): x = sub_matrices[i*ncols+j] if not is_Matrix(x) and x: # must be square matrix if not is_Matrix(x): # we make a square matrix in ambiguous cases, as documented above if row_heights[i] is None: row_heights[i] = col_widths[j] if col_widths[j] is None: