Ticket #10604: trac_10604_fix_matrix_stack

File trac_10604_fix_matrix_stack, 1.6 KB (added by ddrake, 11 years ago)

fix failing doctest in number_field_ideal.py

Line 
1# HG changeset patch
2# User Dan Drake <drake@kaist.edu>
3# Date 1296137579 -32400
4# Node ID f403b9fc3be65eeb0bcd83be96f46adb0e5be4fd
5# Parent  668eeedbbc48de8373748844a1f8013a084ecf47
6trac 10604: fix .stack() for dense matrices; diagonal_matrix now returns
7sparse matrices, which causes a doctest to fail in
8rings/number_field/number_field_ideal.py because .stack() doesn't accept
9a sparse matrix.
10
11diff --git a/sage/matrix/matrix_integer_dense.pyx b/sage/matrix/matrix_integer_dense.pyx
12--- a/sage/matrix/matrix_integer_dense.pyx
13+++ b/sage/matrix/matrix_integer_dense.pyx
14@@ -4418,12 +4418,31 @@
15             [ 0  1  2]
16             [ 3  4  5]
17             [10 11 12]
18+
19+        TESTS:
20+
21+        Stacking a dense matrix atop a sparse one should work::
22+
23+            sage: M = Matrix(ZZ, 2, 3, range(6))
24+            sage: M.is_sparse()
25+            False
26+            sage: N = diagonal_matrix([10,11,12], sparse=True)
27+            sage: N.is_sparse()
28+            True
29+            sage: P = M.stack(N); P
30+            [ 0  1  2]
31+            [ 3  4  5]
32+            [10  0  0]
33+            [ 0 11  0]
34+            [ 0  0 12]
35+            sage: P.is_sparse()
36+            False
37         """
38         if self._ncols != other.ncols():
39             raise TypeError, "number of columns must be the same"
40         if not (self._base_ring is other.base_ring()):
41             other = other.change_ring(self._base_ring)
42-        cdef Matrix_integer_dense A = other
43+        cdef Matrix_integer_dense A = other.dense_matrix()
44         cdef Matrix_integer_dense M
45         M = self.new_matrix(nrows = self._nrows + A._nrows, ncols = self.ncols())
46         cdef Py_ssize_t i, k