From bug-octave-request at che dot utexas dot edu Sat Oct 9 21:54:11 1993 Subject: assignment bug with empty matrices From: Karl Holmstrom To: bug-octave at che dot utexas dot edu Date: Sat, 09 Oct 1993 17:34:59 +0200 BUG DESCRIPTION: octave version 0.76 on HP-UX 8.07: The following assignments fail when A is not previously defined: A(1:2,:) = [1 2 3;4 5 6] A(:,1:3) = [1 2 3;4 5 6] Both operations are allowed in Matlab. SAMPLE SESSION: kyyppi <17:27> <~>: octave Octave, version 0.76. Copyright (C) 1992, 1993, John W. Eaton. This is free software with ABSOLUTELY NO WARRANTY. For details, type `warranty'. octave:1> A(1:2,:) = [1 2 3;4 5 6] error: A(range,:) = X: the number of rows in X must match the number of elements in range, and the number of columns in X must match the number of columns in A error: evaluating assignment expression near line 1, column 10 octave:2> exit kyyppi <17:27> <~>: POSSIBLE FIX: (two modifications in tc-assign.cc) ------ start of diff ------ *** tc-assign.cc.orig Sat Oct 9 17:12:24 1993 --- tc-assign.cc Sat Oct 9 17:12:42 1993 *************** *** 934,941 **** case magic_colon: { int nc = columns (); ! if (! indexed_assign_conforms (ri.nelem (), nc, rhs_nr, rhs_nc)) { error ("A(range,:) = X: the number of rows in X must match\ the number of elements in range, and the number of columns in X must\ match the number of columns in A"); --- 934,955 ---- case magic_colon: { int nc = columns (); ! if (nc == 0 && rows () == 0) { + if (rhs.is_complex_type ()) + { + complex_matrix = new ComplexMatrix (); + type_tag = complex_matrix_constant; + } + else + { + matrix = new Matrix (); + type_tag = matrix_constant; + } + nc = rhs_nc; + } + else if (! indexed_assign_conforms (ri.nelem (), nc, rhs_nr, rhs_nc)) + { error ("A(range,:) = X: the number of rows in X must match\ the number of elements in range, and the number of columns in X must\ match the number of columns in A"); *************** *** 1023,1029 **** { Range rj = tmp_j.range_value (); int nr = rows (); ! if (! indexed_assign_conforms (nr, rj.nelem (), rhs_nr, rhs_nc)) { error ("A(:,range) = X: the number of rows in X must match\ the number of rows in A, and the number of columns in X must match\ --- 1037,1057 ---- { Range rj = tmp_j.range_value (); int nr = rows (); ! if (columns() == 0 && nr == 0) ! { ! if (rhs.is_complex_type ()) ! { ! complex_matrix = new ComplexMatrix (); ! type_tag = complex_matrix_constant; ! } ! else ! { ! matrix = new Matrix (); ! type_tag = matrix_constant; ! } ! nr = rhs_nr; ! } ! else if (! indexed_assign_conforms (nr, rj.nelem (), rhs_nr, rhs_nc)) { error ("A(:,range) = X: the number of rows in X must match\ the number of rows in A, and the number of columns in X must match\ ------ end of diff ------ kalle