Ticket #14049: trac_14049-matrixslice-zero.patch

File trac_14049-matrixslice-zero.patch, 1.3 KB (added by jason, 8 years ago)
  • sage/matrix/matrix0.pyx

    # HG changeset patch
    # User Jason Grout <jason.grout@drake.edu>
    # Date 1359769333 21600
    # Node ID 4ddc77b024683949e3d3c89f41c1f9f987cd02a6
    # Parent  07ffd1e361c57a8f3c7e263e862bbf2d179f885b
    Matrix slicing did not handle empty matrices well
    
    Before this patch, an empty slice would return a zero-row and zero-column matrix,
    even if the matrix had only zero rows or only zero columns.
    
    Reported at http://ask.sagemath.org/question/2207/empty-matrix
    
    diff --git a/sage/matrix/matrix0.pyx b/sage/matrix/matrix0.pyx
    a b  
    829829            sage: A[1:3].is_immutable()
    830830            True
    831831
     832        Slices that result in zero rows or zero columns are supported too::
     833
     834            sage: m = identity_matrix(QQ, 4)[4:,:]
     835            sage: m.nrows(), m.ncols()
     836            (0, 4)
     837            sage: m * vector(QQ, 4)
     838            ()
     839
    832840        TESTS:
    833841
    834842        If we're given lists as arguments, we should throw an
     
    969977                col_list = [col]
    970978
    971979            if len(row_list) == 0 or len(col_list) == 0:
    972                 return self.new_matrix(nrows=0,ncols=0)
     980                return self.new_matrix(nrows=len(row_list), ncols=len(col_list))
    973981
    974982            return self.matrix_from_rows_and_columns(row_list,col_list)
    975983