From bug-octave-request at bevo dot che dot wisc dot edu Wed Oct 20 22:06:54 1999 Subject: Parsing bug in diag (2.0.14) From: "John W. Eaton" To: A+A Adler cc: bug-octave at bevo dot che dot wisc dot edu Date: Wed, 20 Oct 1999 22:05:40 -0500 (CDT) On 20-Oct-1999, A+A Adler wrote: | I just noticed a bizzare effect using diag. | If you use it in the mode diag(vector,x), the | vector needs either [] brackets around it, or | it needs a more complicated expression (1:2)+1 | | Transcript follows | | octave:1> diag(1:2) | ans = 1 0 | 0 2 | octave:2> diag(1:2,1) | error: diag: wrong type argument `range' | error: evaluating index expression near line 2, column 1 | octave:2> diag([1:2],1) | ans = 0 1 0 | 0 0 2 | 0 0 0 | octave:3> diag((1:2),1) | error: diag: wrong type argument `range' | error: evaluating index expression near line 4, column 1 | octave:3> diag((1:2)+1,1) | ans = 0 2 0 | 0 0 3 | 0 0 0 | octave:4> version | ans = 2.0.14 Please try the following patch. Thanks, jwe 1999-10-20 John W. Eaton * data.cc (make_diag (const octave_value&, const octave_value&)): Delete special cases for scalars and simply attempt conversion of first arg to a matrix value. If that fails, we will still see an error message. *** src/data.cc~ Thu Mar 18 12:08:53 1999 --- src/data.cc Wed Oct 20 22:02:46 1999 *************** *** 463,495 **** } int k = NINT (tmp); - int n = ABS (k) + 1; if (a.is_real_type ()) { ! if (a.is_scalar_type ()) ! { ! double d = a.double_value (); ! if (k == 0) ! retval = d; ! else if (k > 0) ! { ! Matrix m (n, n, 0.0); ! m (0, k) = d; ! retval = m; ! } ! else if (k < 0) ! { ! Matrix m (n, n, 0.0); ! m (-k, 0) = d; ! retval = m; ! } ! } ! else if (a.is_matrix_type ()) { - Matrix m = a.matrix_value (); - int nr = m.rows (); int nc = m.columns (); --- 463,475 ---- } int k = NINT (tmp); if (a.is_real_type ()) { ! Matrix m = a.matrix_value (); ! if (! error_state) { int nr = m.rows (); int nc = m.columns (); *************** *** 503,536 **** retval = d; } } - else - gripe_wrong_type_arg ("diag", a); } else if (a.is_complex_type ()) { ! if (a.is_scalar_type ()) ! { ! Complex c = a.complex_value (); ! if (k == 0) ! retval = c; ! else if (k > 0) ! { ! ComplexMatrix m (n, n, 0.0); ! m (0, k) = c; ! retval = m; ! } ! else if (k < 0) ! { ! ComplexMatrix m (n, n, 0.0); ! m (-k, 0) = c; ! retval = m; ! } ! } ! else if (a.is_matrix_type ()) { - ComplexMatrix cm = a.complex_matrix_value (); - int nr = cm.rows (); int nc = cm.columns (); --- 483,495 ---- retval = d; } } } else if (a.is_complex_type ()) { ! ComplexMatrix cm = a.complex_matrix_value (); ! if (! error_state) { int nr = cm.rows (); int nc = cm.columns (); *************** *** 544,551 **** retval = d; } } - else - gripe_wrong_type_arg ("diag", a); } else gripe_wrong_type_arg ("diag", a); --- 503,508 ---- --------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. To ensure that development continues, see www.che.wisc.edu/octave/giftform.html Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html ---------------------------------------------------------------------