diff src/data.cc @ 15428:fd5c0159b588 stable

Fix diag handling of diagvectors (bug #37411) * DiagArray2.h (extract_diag): New function * DiagArray2.cc (extract_diag): Ditto * ov.h (octave_value): New constructors for DiagArray2<T> types. * ov.cc (octave_value): Ditto * ov-base-diag.h (octave_base_diag<DMT,MT>::diag): Remove definition. * ov-base-diag.cc (octave_base_diag<DMT,MT>::diag) Rewrite to check for special diagvector case. * data.cc: Add test for this bug
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Fri, 21 Sep 2012 16:42:33 -0400
parents 5bb5fcffa29d
children d174210ce1ec
line wrap: on
line diff
--- a/src/data.cc	Thu Sep 13 15:14:47 2012 -0400
+++ b/src/data.cc	Fri Sep 21 16:42:33 2012 -0400
@@ -1354,6 +1354,11 @@
 %!assert(diag (int8([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8([1; 2; 3]));
 %!assert(diag (int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8([1; 2; 3]));
 
+## bug #37411
+%!assert (diag (diag ([5, 2, 3])(:,1)), diag([5 0 0 ]))
+%!assert (diag (diag ([5, 2, 3])(:,1), 2),  [0 0 5 0 0; zeros(4, 5)])
+%!assert (diag (diag ([5, 2, 3])(:,1), -2), [[0 0 5 0 0]', zeros(5, 4)])
+
 ## Test non-square size
 %!assert(diag ([1,2,3], 6, 3), [1 0 0; 0 2 0; 0 0 3; 0 0 0; 0 0 0; 0 0 0])
 %!assert (diag (1, 2, 3), [1,0,0; 0,0,0]);