From bug-octave-request at bevo dot che dot wisc dot edu Thu Oct 12 11:13:21 2000 Subject: magic colon speedup From: "John W. Eaton" To: Paul Kienzle Cc: bug-octave at bevo dot che dot wisc dot edu Date: Thu, 12 Oct 2000 11:13:12 -0500 On 5-Oct-2000, Paul Kienzle wrote: | To: bug-octave at bevo dot che dot wisc dot edu | Cc: pkienzle | Subject: magic colon speedup | | Bug report for Octave 2.1.31 configured for %OCTAVE_CANONICAL_HOST_TYPE% | | Description: | ----------- | | x(:) makes an unnecessary copy of the matrix for size mxn, with m,n != 1 I made the changes below. I did not apply your patch directly, since it seems to undo some recent changes to the CVS sources. jwe Index: Array2-idx.h =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/Array2-idx.h,v retrieving revision 1.30 diff -c -r1.30 Array2-idx.h *** Array2-idx.h 2000/10/10 23:41:20 1.30 --- Array2-idx.h 2000/10/12 16:12:09 *************** *** 66,73 **** int idx_orig_rows = idx_arg.orig_rows (); int idx_orig_columns = idx_arg.orig_columns (); ! if (nr == 1 && nc == 1) { Array tmp = Array::index (idx_arg); if (tmp.length () != 0) --- 66,82 ---- int idx_orig_rows = idx_arg.orig_rows (); int idx_orig_columns = idx_arg.orig_columns (); ! if (idx_arg.is_colon ()) { + // Fast magic colon processing. + + int result_nr = nr * nc; + int result_nc = result_nr ? 1 : 0; + + retval = Array2 (*this, result_nr, result_nc); + } + else if (nr == 1 && nc == 1) + { Array tmp = Array::index (idx_arg); if (tmp.length () != 0) *************** *** 77,83 **** } else if (nr == 1 || nc == 1) { ! int result_is_column_vector = (nc == 1 || idx_arg.is_colon ()); Array tmp = Array::index (idx_arg); --- 86,92 ---- } else if (nr == 1 || nc == 1) { ! int result_is_column_vector = (nc == 1); Array tmp = Array::index (idx_arg); *************** *** 94,100 **** } } else if (liboctave_dfi_flag - || idx_arg.is_colon () || (idx_arg.one_zero_only () && idx_orig_rows == nr && idx_orig_columns == nc)) --- 103,108 ---- *************** *** 109,120 **** int result_nr = idx_orig_rows; int result_nc = idx_orig_columns; ! if (idx_arg.is_colon ()) ! { ! result_nr = nr * nc; ! result_nc = result_nr ? 1 : 0; ! } ! else if (idx_arg.one_zero_only ()) { result_nr = idx_arg.ones_count (); result_nc = (result_nr > 0 ? 1 : 0); --- 117,123 ---- int result_nr = idx_orig_rows; int result_nc = idx_orig_columns; ! if (idx_arg.one_zero_only ()) { result_nr = idx_arg.ones_count (); result_nc = (result_nr > 0 ? 1 : 0); ----------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.che.wisc.edu/octave/octave.html How to fund new projects: http://www.che.wisc.edu/octave/funding.html Subscription information: http://www.che.wisc.edu/octave/archive.html -----------------------------------------------------------------------