Mercurial > hg > octave-shane
changeset 11679:f95adf778670 release-3-0-x
logical indexing compatibility fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 07 Mar 2008 20:21:48 -0500 |
parents | c8b80a1af968 |
children | 83f68ef05c8e |
files | liboctave/ChangeLog liboctave/idx-vector.cc test/ChangeLog test/test_logical-wfi-f.m test/test_logical-wfi-t.m |
diffstat | 5 files changed, 51 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2008-03-07 John W. Eaton <jwe@octave.org> + + * idx-vector.cc (IDX_VEC_REP::idx_vector_rep (bool), + IDX_VEC_REP::idx_vector_rep (const boolNDArray&)): + Simply perform the equivalent of "find" on the bool argument here, + set one_zero to 0 and orig_dims to size of resulting index vector. + (IDX_VEC_REP::freeze): Don't call maybe_convert_one_zero_to_idx here. + 2008-03-03 David Bateman <dbateman@free.fr> * Sparse.cc (assign1, assign1): Take care of repeated index
--- a/liboctave/idx-vector.cc +++ b/liboctave/idx-vector.cc @@ -273,41 +273,51 @@ } IDX_VEC_REP::idx_vector_rep (bool b) - : data (0), len (1), num_zeros (0), num_ones (0), + : data (0), len (b ? 1 : 0), num_zeros (0), num_ones (0), max_val (0), min_val (0), count (1), frozen_at_z_len (0), - frozen_len (0), colon (0), one_zero (1), initialized (0), + frozen_len (0), colon (0), one_zero (0), initialized (0), frozen (0), colon_equiv_checked (0), colon_equiv (0), - orig_dims (1, 1) + orig_dims (len, len) { - data = new octave_idx_type [len]; - - data[0] = tree_to_mat_idx (b); - - init_state (); + if (len == 0) + initialized = 1; + else + { + data = new octave_idx_type [len]; + data[0] = 0; + init_state (); + } } IDX_VEC_REP::idx_vector_rep (const boolNDArray& bnda) - : data (0), len (bnda.length ()), num_zeros (0), num_ones (0), + : data (0), len (bnda.nnz ()), num_zeros (0), num_ones (0), max_val (0), min_val (0), count (1), frozen_at_z_len (0), - frozen_len (0), colon (0), one_zero (1), initialized (0), + frozen_len (0), colon (0), one_zero (0), initialized (0), frozen (0), colon_equiv_checked (0), colon_equiv (0), - orig_dims (bnda.dims ()) + orig_dims () { if (len == 0) { + orig_dims = dim_vector (0, 0); initialized = 1; - return; } else { - octave_idx_type k = 0; data = new octave_idx_type [len]; - for (octave_idx_type i = 0; i < len; i++) - data[k++] = tree_to_mat_idx (bnda.elem (i)); + octave_idx_type ntot = bnda.length (); + + for (octave_idx_type i = 0, k = 0; i < ntot; i++, k < len) + if (bnda.elem (i)) + data[k++] = i; + + dim_vector dv = bnda.dims (); + + orig_dims = ((dv.length () == 2 && dv(0) == 1) + ? dim_vector (1, len) : orig_dims = dim_vector (len, 1)); + + init_state (); } - - init_state (); } IDX_VEC_REP& @@ -569,8 +579,6 @@ frozen_len = 0; else { - maybe_convert_one_zero_to_idx (z_len); - max_val = max (); min_val = min ();
--- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2008-03-07 John W. Eaton <jwe@octave.org> + + * test_logical-wfi-t.m, test_logical-wfi-f.m: Update tests for + logical indexing bug fix. + 2008-03-06 John W. Eaton <jwe@octave.org> * test_string.m: Delete obsolete test for deblank.
--- a/test/test_logical-wfi-f.m +++ b/test/test_logical-wfi-f.m @@ -46,8 +46,9 @@ %!test %! wfi = warning ("query", "Octave:fortran-indexing"); %! warning ("off", "Octave:fortran-indexing"); -%! a = 2; -%! assert(all (a(logical ([1,1])) == [2,2])); +%!shared a +%! a = 2; +%!error <invalid vector index> a(logical ([1,1])); %! warning ("wfi.state", "Octave:fortran-indexing"); %% test/octave.test/logical-wfi-f/v-1.m @@ -79,7 +80,7 @@ %! wfi = warning ("query", "Octave:fortran-indexing"); %! warning ("off", "Octave:fortran-indexing"); %! a = [9,8,7,6]; -%! assert(all (a(logical ([1,1])) == [9,9])); +%! assert(all (a(logical ([1,1])) == [9,8])); %! warning ("wfi.state", "Octave:fortran-indexing"); %% test/octave.test/logical-wfi-f/m-1.m @@ -95,7 +96,7 @@ %! wfi = warning ("query", "Octave:fortran-indexing"); %! warning ("off", "Octave:fortran-indexing"); %! a = [9,8;7,6]; -%! assert(all (a(logical ([1,1,1,1])) == [9;7;8;6])); +%! assert(all (a(logical ([1,1,1,1])) == [9,7,8,6])); %! warning ("wfi.state", "Octave:fortran-indexing"); %% test/octave.test/logical-wfi-f/m-3.m @@ -103,7 +104,7 @@ %! wfi = warning ("query", "Octave:fortran-indexing"); %! warning ("off", "Octave:fortran-indexing"); %! a = [9,8;7,6]; -%! assert(all (a(logical ([0,1,1,0])) == [7;8])); +%! assert(all (a(logical ([0,1,1,0])) == [7,8])); %! warning ("wfi.state", "Octave:fortran-indexing"); %% test/octave.test/logical-wfi-f/m-4.m
--- a/test/test_logical-wfi-t.m +++ b/test/test_logical-wfi-t.m @@ -46,8 +46,9 @@ %!test %! wfi = warning ("query", "Octave:fortran-indexing"); %! warning ("on", "Octave:fortran-indexing"); +%!shared a %! a = 2; -%! assert(all (a(logical ([1,1])) == [2,2])); +%!error <invalid vector index.*> a(logical ([1,1])); %! warning ("wfi.state", "Octave:fortran-indexing"); %% test/octave.test/logical-wfi-t/v-1.m @@ -79,7 +80,7 @@ %! wfi = warning ("query", "Octave:fortran-indexing"); %! warning ("on", "Octave:fortran-indexing"); %! a = [9,8,7,6]; -%! assert(all (a(logical ([1,1])) == [9,9])); +%! assert(all (a(logical ([1,1])) == [9,8])); %! warning ("wfi.state", "Octave:fortran-indexing"); %% test/octave.test/logical-wfi-t/m-1.m @@ -95,7 +96,7 @@ %! wfi = warning ("query", "Octave:fortran-indexing"); %! warning ("on", "Octave:fortran-indexing"); %! a = [9,8;7,6]; -%! all (a(logical ([1,1,1,1])) == [9;7;8;6]); +%! all (a(logical ([1,1,1,1])) == [9,7,8,6]); %! warning ("wfi.state", "Octave:fortran-indexing"); %% test/octave.test/logical-wfi-t/m-3.m @@ -103,7 +104,7 @@ %! wfi = warning ("query", "Octave:fortran-indexing"); %! warning ("on", "Octave:fortran-indexing"); %! a = [9,8;7,6]; -%! all (a(logical ([0,1,1,0])) == [7;8]); +%! all (a(logical ([0,1,1,0])) == [7,8]); %! warning ("wfi.state", "Octave:fortran-indexing"); %% test/octave.test/logical-wfi-t/m-4.m