Mercurial > hg > octave-nkf
changeset 7646:ad16ea379d2f
additional fixes for Array::assignN
author | David Bateman <dbateman@free.fr> |
---|---|
date | Wed, 26 Mar 2008 15:38:25 -0400 |
parents | 734854f21c94 |
children | 7b382848a18f |
files | liboctave/Array.cc liboctave/ChangeLog test/ChangeLog test/test_index-wfi-f.m |
diffstat | 4 files changed, 148 insertions(+), 110 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -3365,18 +3365,22 @@ { int ncolon = 0; int fcolon = 0; - int lcolon = 0; + octave_idx_type new_dims_numel = 1; + int new_dims_vec = 0; for (int i = 0; i < n_idx; i++) if (idx(i).is_colon ()) { ncolon ++; if (ncolon == 1) fcolon = i; - lcolon = i; - new_dims (i) = 1; } else - new_dims (i) = idx(i).capacity (); + { + octave_idx_type cap = idx(i).capacity (); + new_dims_numel *= cap; + if (cap != 1) + new_dims_vec ++; + } if (ncolon == n_idx) { @@ -3387,9 +3391,7 @@ } else { - octave_idx_type new_dims_numel = new_dims.numel (); octave_idx_type rhs_dims_numel = rhs_dims.numel (); - bool is_vec = is_vector (new_dims); for (int i = 0; i < n_idx; i++) new_dims(i) = idx(i).orig_empty () ? 0 : idx(i).max () + 1; @@ -3397,13 +3399,17 @@ if (new_dims_numel != rhs_dims_numel && ncolon > 0 && new_dims_numel == 1) { - if (ncolon == 2 && rhs_dims_len == 2 && - rhs_dims(0) == 1) - new_dims (lcolon) = rhs_dims_numel; + if (ncolon == rhs_dims_len) + { + int k = 0; + for (int i = 0; i < n_idx; i++) + if (idx(i).is_colon ()) + new_dims (i) = rhs_dims (k++); + } else new_dims (fcolon) = rhs_dims_numel; } - else if (new_dims_numel != rhs_dims_numel || !is_vec) + else if (new_dims_numel != rhs_dims_numel || new_dims_vec > 1) { (*current_liboctave_error_handler) ("A(IDX-LIST) = RHS: mismatched index and RHS dimension");
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2008-03-26 David Bateman <dbateman@feee.fr> + + * Array.cc (assignN): Additional fix for vector assignments. + 2008-03-25 David Bateman <dbateman@feee.fr> * Array.cc (assignN): refactor calculation of new dimensions when
--- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +2008-03-26 David Bateman <dbateman@free.fr> + + * test_index-wfi-f.m: Split large block of tests. New tests. + 2008-03-26 John W. Eaton <jwe@octave.org> * fntests.m (report_files_with_no_tests): New function.
--- a/test/test_index-wfi-f.m +++ b/test/test_index-wfi-f.m @@ -380,106 +380,130 @@ %! assert(a(2),3); %! warning (wfi.state, "Octave:fortran-indexing"); -%% test/octave.test/index-wfi-f/misc.m -%!test -%! wfi = warning ("query", "Octave:fortran-indexing"); -%! warning ("off", "Octave:fortran-indexing"); +%% Additional tests +%!shared a, b %! a = [1,2;3,4]; %! b = a; %! b(:,:,2) = [5,6;7,8]; -%! a1 = [1; 3; 2; 4]; -%! a2 = [1, 3]; -%! a3 = [1, 2; 3, 4]; -%! a4 = [1; 3]; -%! a5 = 1; -%! a6 = [1; 3]; -%! a7 = [1, 2; 3, 4]; -%! a8(:,:,1) = [1, 2; 3, 4]; -%! a8(:,:,2) = [1, 2; 3, 4]; -%! a9(:,:,1,1) = [1, 2; 3, 4]; -%! a9(:,:,1,2) = [1, 2; 3, 4]; -%! a10(:,:,1,1) = [1, 2; 3, 4]; -%! a10(:,:,2,1) = [1, 2; 3, 4]; -%! a10(:,:,1,2) = [1, 2; 3, 4]; -%! a10(:,:,2,2) = [1, 2; 3, 4]; -%! a11 = zeros (1, 0); -%! a12 = zeros (1, 0, 2); -%! a13 = zeros (1, 1, 0); -%! clear a14; a14(1:10,1) = 1:10; -%! clear a15; a15(1,:) = a2; -%! clear a16; a16(1,:) = a4; -%! clear a17; a17(:,1) = a4; -%! clear a18; a18(1,:,:) = a; -%! a19 = reshape (a, [1,2,2]); -%! clear a20; a20(1,1:4,2) = reshape (1:4, [1,1,4]); -%! clear a21; a21(:,:,2) = 1:4; -%! clear a22; a22(:,:,:) = 1:4; -%! clear a23; a23(1,:,:) = 1:4; -%! clear a24; a24(:,1,:) = 1:4; -%! clear a25; a25(:,:,1) = 1:4; -%! clear a26; a26(:,:,1) = [1:4]'; -%! clear a27; a27(:,:,1) = reshape(1:4,[1,1,4]); -%! clear a28; a28(1,:,:) = 1:4; -%! clear a29; a29(1,:,:) = [1:4]'; -%! clear a30; a30(1,:,:) = reshape (1:4,[1,1,4]); -%! b1 = [1; 3; 2; 4; 5; 7; 6; 8]; -%! b2 = [1, 2, 5, 6; 3, 4, 7, 8]; -%! b3 = [1; 3]; -%! b4(:,:,1) = [1, 2; 3, 4]; -%! b4(:,:,2) = [5, 6; 7, 8]; -%! b5 = [1; 3]; -%! b6(:,:,1,1) = [1; 3]; -%! b6(:,:,1,2) = [1; 3]; -%! b7 = 5; -%! b8 = [5, 6]; -%! b9 = [1, 2, 5, 6]; -%! b10 = zeros (1, 0, 2); -%! b11 = zeros (1, 0); -%! b12 = [5; 7]; -%! b13 = zeros (0, 1); -%! -%! assert(a(:),a1); -%! assert(a(1:2), a2); -%! assert(a(:,:), a3); -%! assert(a(:,1), a4); -%! assert(a(1,1), a5); -%! assert(a(1:2,1), a6); -%! assert(a(:,:,1), a7); -%! assert(a(:,:,[1,1]), a8); -%! assert(a(:,:,1,[1,1]), a9); -%! assert(a(:,:,[1,1],[1,1]), a10); -%! assert(a(1,[]), a11); -%! assert(a(1,[],[1,1]), a12); -%! assert(a(1,1,[]), a13); -%! assert(a14, (1:10)'); -%! assert(b(:), b1); -%! assert(b(:,:), b2); -%! assert(b(:,1), b3); -%! assert(b(:,:,:), b4); -%! assert(b(:,1,1), b5); -%! assert(b(:,1,1,[1,1]), b6); -%! assert(b(1,3), b7); -%! assert(b(1,[3,4]), b8); -%! assert(b(1,1:4), b9); -%! assert(b(1,[],:), b10); -%! assert(b(1,[]), b11); -%! assert(b(:,3), b12); -%! assert(b([1,2],3), b12); -%! assert(b(true(2,1),3), b12); -%! assert(b(false(2,1),3), b13) -%! assert(b([],3), b13) -%! assert(a15, a2); -%! assert(a16, a2); -%! assert(a17, a4); -%! assert(a18, a19); -%! assert(a20, a21); -%! assert(a22, [1:4]); -%! assert(a23, reshape (1:4, [1,1,4])); -%! assert(a24, reshape (1:4, [1,1,4])); -%! assert(a25, [1,2,3,4]); -%! assert(a26, [1;2;3;4]); -%! assert(a27, [1;2;3;4]); -%! assert(a28, reshape (1:4, [1,1,4])); -%! assert(a29, [1,2,3,4]); -%! assert(a30, [1,2,3,4]); -%! warning (wfi.state, "Octave:fortran-indexing"); + +%!assert (a(:), [1;3;2;4]); +%!assert (a(1:2), [1,3]); +%!assert (a(:,:), [1,2;3,4]); +%!assert (a(:,1), [1;3]); +%!assert (a(1,1), 1); +%!assert (a(1:2,1), [1;3]); +%!assert (a(:,:,1), [1,2;3,4]); + +%!test +%! c(:,:,1) = [1,2;3,4]; +%! c(:,:,2) = [1,2;3,4]; +%! assert (a(:,:,[1,1]),c) + +%!test +%! c(:,:,1,1) = [1,2;3,4]; +%! c(:,:,1,2) = [1,2;3,4]; +%! assert (a(:,:,1,[1,1]),c) + +%!test +%! c(:,:,1,1) = [1,2;3,4]; +%! c(:,:,2,1) = [1,2;3,4]; +%! c(:,:,1,2) = [1,2;3,4]; +%! c(:,:,2,2) = [1,2;3,4]; +%! assert (a(:,:,[1,1],[1,1]),c) + +%!assert (a(1,[]), zeros(1,0)); +%!assert (a(1,[],[1,1]), zeros(1,0,2)); +%!assert (a(1,1,[]), zeros(1,1,0)); + +%!test +%! c (1:10,1) = 1:10; +%! assert (c, [1:10]'); + +%!assert (b(:), [1; 3; 2; 4; 5; 7; 6; 8]); +%!assert (b(:,:), [1, 2, 5, 6; 3, 4, 7, 8]); +%!assert (b(:,1), [1;3]); +%!assert (b(:,:,:), reshape ([1,3,2,4,5,7,6,8],[2,2,2])); +%!assert (b(:,1,1), [1;3]); +%!assert (b(:,1,1,[1,1]),reshape([1,3,1,3],[2,1,1,2])); +%!assert (b(1,3), 5); +%!assert (b(1,[3,4]), [5,6]); +%!assert (b(1,1:4), [1,2,5,6]); +%!assert (b(1,[],:), zeros (1,0,2)); +%!assert (b(1,[]), zeros(1,0)); +%!assert (b(:,3), [5;7]) +%!assert (b([1,2],3), [5;7]) +%!assert (b(true(2,1),3), [5;7]) +%!assert (b(false(2,1),3), zeros(0,1)) +%!assert (b([],3), zeros(0,1)); + +%!shared x +%! # Dummy shared block to clear any previous definitions +%! x = 1; + +%!test +%! a(1,:) = [1,3]; +%! assert (a, [1,3]); + +%!test +%! a(1,:) = [1;3]; +%! assert (a, [1,3]); + +%!test +%! a(:,1) = [1;3]; +%! assert (a, [1;3]); + +%!test +%! a = [1,2;3,4]; +%! b (1,:,:) = a; +%! assert (b, reshape (a, [1,2,2])); + +%!test +%! a(1,1:4,2) = reshape (1:4, [1,1,4]); +%! b(:,:,2) = 1:4; +%! assert (a, b); + +%!test +%! a(:,:,:) = 1:4; +%! assert (a, [1:4]); + +%!test +%! a(:,:,1) = 1:4;; +%! assert (a, [1:4]); + +%!test +%! a(:,:,1) = [1:4]'; +%! assert (a, [1:4]'); + +%!test +%! a(:,:,1) = reshape(1:4,[1,1,4]); +%! assert (a, [1:4]'); + +%!test +%! a(:,1,:) = 1:4; +%! assert (a, reshape (1:4,[1,1,4])); + +%!test +%! a(:,1,:) = [1:4]'; +%! assert (a, [1:4]'); + +%!test +%! a(:,1,:) = reshape(1:4,[1,1,4]);; +%! assert (a, [1:4]'); + +%!test +%! a(1,:,:) = 1:4; +%! assert (a, reshape (1:4,[1,1,4])); + +%!test +%! a(1,:,:) = [1:4]'; +%! assert (a, [1:4]); + +%!test +%! a(1,:,:) = reshape(1:4,[1,1,4]); +%! assert (a, [1:4]); + +%!test +%! a(1,:,:,:) = reshape(1:4,[1,1,4]); +%! assert (a, reshape (1:4,[1,1,1,4])); + +%!error (a(1:2,1:2) = 1:4)