From bug-octave-request at che dot utexas dot edu Tue May 24 20:01:26 1994 Subject: Re: a(:,[]) = [] From: John Eaton To: Ken Neighbors cc: bug-octave at che dot utexas dot edu (Octave Bug) Date: Tue, 24 May 94 20:01:17 EDT Ken Neighbors wrote: : Using an empty matrix as an index apparently isn't allowed in octave, : but perhaps it should be (especially for compatability with MATLAB). : octave:1> a = [1 2; 3 4]; : octave:2> a(:,[]) = [] : error: second matrix index is an empty matrix : error: evaluating assignment expression near line 2, column 9 Please try the following patch. It will actually make Octave accept a few more things than Matlab does. For example, Matlab doesn't seem to mind that your example above doesn't really conform (the : stands for two elements in this case, so the index is 2x0 while the RHS is 0x0) but it does complain if you try a([],[]) = [], which seems really bizarre to me... At some point I may actually fix Octave to ensure that assignments with empty indices and empty right-hand sides actually do conform, but if I do, I'll allow you to select how strict you want the check to be. Thanks, jwe *** src/tc-assign.cc~ 1.13 1994/05/17 20:14:06 --- src/tc-assign.cc 1994/05/25 00:31:35 *************** *** 182,187 **** --- 202,209 ---- } } + // The do_matrix_assignment functions can't handle empty matrices, so + // don't let any pass through here. switch (nargs) { case 2: *************** *** 189,196 **** ::error ("matrix index is null"); else if (args[1].is_undefined ()) ::error ("matrix index is undefined"); - else if (args[1].is_empty ()) - ::error ("matrix index is an empty matrix"); else do_matrix_assignment (rhs, args[1]); break; --- 211,216 ---- *************** *** 201,210 **** ::error ("first matrix index is undefined"); else if (args[2].is_undefined ()) ::error ("second matrix index is undefined"); ! else if (args[1].is_empty ()) ! ::error ("first matrix index is an empty matrix"); ! else if (args[2].is_empty ()) ! ::error ("second matrix index is an empty matrix"); else do_matrix_assignment (rhs, args[1], args[2]); break; --- 221,237 ---- ::error ("first matrix index is undefined"); else if (args[2].is_undefined ()) ::error ("second matrix index is undefined"); ! else if (args[1].is_empty () || args[2].is_empty ()) ! { ! if (! rhs.is_empty ()) ! { ! ::error ("in assignment expression, a matrix index is empty"); ! ::error ("but hte right hand side is not an empty matrix"); ! } ! // XXX FIXME XXX -- to really be correct here, we should probably ! // check to see if the assignment conforms, but that seems like more ! // work than it's worth right now... ! } else do_matrix_assignment (rhs, args[1], args[2]); break; *************** *** 221,230 **** int nr = rows (); int nc = columns (); ! if (user_pref.do_fortran_indexing) ! fortran_style_matrix_assignment (rhs, i_arg); ! else if (nr <= 1 || nc <= 1) ! vector_assignment (rhs, i_arg); else ::error ("single index only valid for row or column vector"); } --- 251,281 ---- int nr = rows (); int nc = columns (); ! if (user_pref.do_fortran_indexing || nr <= 1 || nc <= 1) ! { ! if (i_arg.is_empty ()) ! { ! if (! rhs.is_empty ()) ! { ! ::error ("in assignment expression, matrix index is empty but"); ! ::error ("right hand side is not an empty matrix"); ! } ! // XXX FIXME XXX -- to really be correct here, we should probably ! // check to see if the assignment conforms, but that seems like more ! // work than it's worth right now... ! ! // The assignment functions can't handle empty matrices, so don't let ! // any pass through here. ! return; ! } ! ! if (user_pref.do_fortran_indexing) ! fortran_style_matrix_assignment (rhs, i_arg); ! else if (nr <= 1 || nc <= 1) ! vector_assignment (rhs, i_arg); ! else ! panic_impossible (); ! } else ::error ("single index only valid for row or column vector"); }