diff liboctave/DiagArray2.h @ 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 63ae976ac2e7
children
line wrap: on
line diff
--- a/liboctave/DiagArray2.h	Thu Sep 13 15:14:47 2012 -0400
+++ b/liboctave/DiagArray2.h	Fri Sep 21 16:42:33 2012 -0400
@@ -64,7 +64,7 @@
 
   template <class U>
   DiagArray2 (const DiagArray2<U>& a)
-    : Array<T> (a.diag ()), d1 (a.dim1 ()), d2 (a.dim2 ()) { }
+    : Array<T> (a.extract_diag ()), d1 (a.dim1 ()), d2 (a.dim2 ()) { }
 
   ~DiagArray2 (void) { }
 
@@ -98,6 +98,11 @@
   dim_vector dims (void) const { return dim_vector (d1, d2); }
 
   Array<T> diag (octave_idx_type k = 0) const;
+  Array<T> extract_diag (octave_idx_type k = 0) const;
+  DiagArray2<T> build_diag_matrix () const
+  {
+    return DiagArray2<T> (array_value ());
+  }
 
   // Warning: the non-const two-index versions will silently ignore assignments
   // to off-diagonal elements.