Mercurial > hg > octave-nkf
comparison liboctave/Sparse.cc @ 12184:d8de1a28274c
sparse matrix indexed assignment bug
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 27 Jan 2011 16:46:50 -0500 |
parents | 4ced6b90fffb |
children | 211f8c905a4f |
comparison
equal
deleted
inserted
replaced
12183:b4d26c65e7e6 | 12184:d8de1a28274c |
---|---|
1856 octave_idx_type nz = nnz (); | 1856 octave_idx_type nz = nnz (); |
1857 | 1857 |
1858 octave_idx_type n = rhs.rows (); | 1858 octave_idx_type n = rhs.rows (); |
1859 octave_idx_type m = rhs.columns (); | 1859 octave_idx_type m = rhs.columns (); |
1860 | 1860 |
1861 if (idx_i.length (nr) == n && idx_j.length (nc) == m) | 1861 // FIXME -- this should probably be written more like the |
1862 { | 1862 // Array<T>::assign function... |
1863 if (n == 0 || m == 0) | 1863 |
1864 return; | 1864 bool orig_zero_by_zero = (nr == 0 && nc == 0); |
1865 | 1865 |
1866 octave_idx_type nrx = idx_i.extent (nr), ncx = idx_j.extent (nc); | 1866 if (orig_zero_by_zero || (idx_i.length (nr) == n && idx_j.length (nc) == m)) |
1867 { | |
1868 octave_idx_type nrx; | |
1869 octave_idx_type ncx; | |
1870 | |
1871 if (orig_zero_by_zero) | |
1872 { | |
1873 if (idx_i.is_colon ()) | |
1874 { | |
1875 nrx = n; | |
1876 | |
1877 if (idx_j.is_colon ()) | |
1878 ncx = n; | |
1879 else | |
1880 ncx = idx_j.extent (nc); | |
1881 } | |
1882 else if (idx_j.is_colon ()) | |
1883 { | |
1884 nrx = idx_i.extent (nr); | |
1885 ncx = m; | |
1886 } | |
1887 } | |
1888 else | |
1889 { | |
1890 nrx = idx_i.extent (nr); | |
1891 ncx = idx_j.extent (nc); | |
1892 } | |
1893 | |
1867 // Try to resize first if necessary. | 1894 // Try to resize first if necessary. |
1868 if (nrx != nr || ncx != nc) | 1895 if (nrx != nr || ncx != nc) |
1869 { | 1896 { |
1870 resize (nrx, ncx); | 1897 resize (nrx, ncx); |
1871 nr = rows (); | 1898 nr = rows (); |
1872 nc = cols (); | 1899 nc = cols (); |
1873 // nz is preserved. | 1900 // nz is preserved. |
1874 } | 1901 } |
1902 | |
1903 if (n == 0 || m == 0) | |
1904 return; | |
1875 | 1905 |
1876 if (idx_i.is_colon ()) | 1906 if (idx_i.is_colon ()) |
1877 { | 1907 { |
1878 octave_idx_type lb, ub; | 1908 octave_idx_type lb, ub; |
1879 // Great, we're just manipulating columns. This is going to be quite | 1909 // Great, we're just manipulating columns. This is going to be quite |
2597 ## size = [2 0] | 2627 ## size = [2 0] |
2598 %!test test_sparse_slice([2 0], 21, []); | 2628 %!test test_sparse_slice([2 0], 21, []); |
2599 %!test test_sparse_slice([2 0], 21, 1); | 2629 %!test test_sparse_slice([2 0], 21, 1); |
2600 %!test test_sparse_slice([2 0], 21, 2); | 2630 %!test test_sparse_slice([2 0], 21, 2); |
2601 %!test test_sparse_slice([2 0], 21, [2,2]); | 2631 %!test test_sparse_slice([2 0], 21, [2,2]); |
2602 %!assert(set_slice(sparse(ones([2 0])), 21, 3), sparse(2,0)); # sparse different from full | 2632 %!assert(set_slice(sparse(ones([2 0])), 21, 3), sparse(3,0)); |
2603 %!assert(set_slice(sparse(ones([2 0])), 21, 4), sparse(2,0)); # sparse different from full | 2633 %!assert(set_slice(sparse(ones([2 0])), 21, 4), sparse(4,0)); |
2604 %!test test_sparse_slice([2 0], 22, []); | 2634 %!test test_sparse_slice([2 0], 22, []); |
2605 %!test test_sparse_slice([2 0], 22, 1); | 2635 %!test test_sparse_slice([2 0], 22, 1); |
2606 %!test test_sparse_slice([2 0], 22, 2); | 2636 %!test test_sparse_slice([2 0], 22, 2); |
2607 %!test test_sparse_slice([2 0], 22, [2,2]); | 2637 %!test test_sparse_slice([2 0], 22, [2,2]); |
2608 %!assert(set_slice(sparse(ones([2 0])), 22, 3), sparse([0 0 2;0 0 2])); # sparse different from full | 2638 %!assert(set_slice(sparse(ones([2 0])), 22, 3), sparse([0 0 2;0 0 2])); # sparse different from full |
2617 %!assert(set_slice(sparse(ones([0 2])), 21, 4), sparse([0 0;0 0;0 0;2 2])); # sparse different from full | 2647 %!assert(set_slice(sparse(ones([0 2])), 21, 4), sparse([0 0;0 0;0 0;2 2])); # sparse different from full |
2618 %!test test_sparse_slice([0 2], 22, []); | 2648 %!test test_sparse_slice([0 2], 22, []); |
2619 %!test test_sparse_slice([0 2], 22, 1); | 2649 %!test test_sparse_slice([0 2], 22, 1); |
2620 %!test test_sparse_slice([0 2], 22, 2); | 2650 %!test test_sparse_slice([0 2], 22, 2); |
2621 %!test test_sparse_slice([0 2], 22, [2,2]); | 2651 %!test test_sparse_slice([0 2], 22, [2,2]); |
2622 %!assert(set_slice(sparse(ones([0 2])), 22, 3), sparse(0,2)); # sparse different from full | 2652 %!assert(set_slice(sparse(ones([0 2])), 22, 3), sparse(0,3)); |
2623 %!assert(set_slice(sparse(ones([0 2])), 22, 4), sparse(0,2)); # sparse different from full | 2653 %!assert(set_slice(sparse(ones([0 2])), 22, 4), sparse(0,4)); |
2624 | 2654 |
2625 ## size = [2 1] | 2655 ## size = [2 1] |
2626 %!test test_sparse_slice([2 1], 21, []); | 2656 %!test test_sparse_slice([2 1], 21, []); |
2627 %!test test_sparse_slice([2 1], 21, 1); | 2657 %!test test_sparse_slice([2 1], 21, 1); |
2628 %!test test_sparse_slice([2 1], 21, 2); | 2658 %!test test_sparse_slice([2 1], 21, 2); |