changeset 20673:3d8aee0b7415

Allow assigning row vector to column of Sparse array (bug #45589). * Sparse.cc (assign): Check for case where a row vector or column vector is assigned to a column or row index respectively. Transpose the right-hand side argument before assignment. Add BIST test for bug #45589.
author Lachlan Andrew <lachlanbis@gmail.com>
date Sun, 01 Nov 2015 19:59:12 -0800
parents 7ae6bbf0a567
children ae83fda9929f
files liboctave/array/Sparse.cc
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/array/Sparse.cc	Fri Oct 30 12:53:08 2015 +0000
+++ b/liboctave/array/Sparse.cc	Sun Nov 01 19:59:12 2015 -0800
@@ -2213,6 +2213,10 @@
       else
         assign (idx_i, idx_j, Sparse<T> (n, m));
     }
+  else if (idx_i.length (nr) == m && idx_j.length (nc) == n && (n==1 || m==1))
+    {
+      assign (idx_i, idx_j, rhs.transpose ());
+    }
   else
     gripe_nonconformant  ("=", idx_i.length (nr), idx_j.length (nc), n, m);
 }
@@ -2896,6 +2900,14 @@
 %! assert (size (all (a)), [1 1]);
 %!test a=sparse (2,2); assert (isequal (all (a), sparse ([0 0])));
 
+## Test assigning row to a column slice (bug #45589)
+%!test
+%! a = sparse (magic (3));
+%! b = a;
+%! a(1,:) = 1:3;
+%! b(1,:) = (1:3)';
+%! assert (a, b);
+
 */
 
 template <class T>