changeset 11717:e5510f2d482a release-3-0-x

refactor Array::assignN dimensioning code for empty initial matrices
author David Bateman <dbateman@free.fr>
date Wed, 26 Mar 2008 15:41:59 -0400
parents 017e13f0d056
children 6e7e29c2155b
files liboctave/Array-util.cc liboctave/Array-util.h liboctave/Array.cc liboctave/ChangeLog test/ChangeLog test/test_index-wfi-f.m test/test_index-wfi-t.m
diffstat 7 files changed, 324 insertions(+), 167 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/Array-util.cc
+++ b/liboctave/Array-util.cc
@@ -135,6 +135,26 @@
 }
 
 bool
+is_vector (const dim_vector& dim)
+{
+  int m = 0;
+  int n = dim.length ();
+  bool retval = true;
+
+  if (n == 0)
+    m = 2;
+  else
+    {
+      for (int i = 0; i < n; i ++)
+	if (dim (i) > 1)
+	  m++;
+	else if (dim(i) < 1)
+	  m += 2;
+    }
+  return (m < 2);
+}
+
+bool
 any_ones (const Array<octave_idx_type>& arr)
 {
   bool retval = false;
--- a/liboctave/Array-util.h
+++ b/liboctave/Array-util.h
@@ -43,6 +43,8 @@
 
 extern OCTAVE_API bool is_scalar (const dim_vector& dim);
 
+extern OCTAVE_API bool is_vector (const dim_vector& dim);
+
 extern OCTAVE_API bool any_ones (const Array<octave_idx_type>& arr);
 
 extern OCTAVE_API octave_idx_type compute_index (const Array<octave_idx_type>& ra_idx, const dim_vector& dims);
--- a/liboctave/Array.cc
+++ b/liboctave/Array.cc
@@ -3092,35 +3092,100 @@
 
       if (orig_empty)
 	{
-	  int k = 0;
-	  for (int i = 0; i < n_idx; i++)
+	  if (rhs_is_scalar)
+	    {
+	      for (int i = 0; i < n_idx; i++)
+		{
+		  if (idx(i).is_colon ())
+		    new_dims(i) = 1;
+		  else
+		    new_dims(i) = idx(i).orig_empty () ? 0 : idx(i).max () + 1;
+		}
+	    }
+	  else if (is_vector (rhs_dims))
 	    {
-	      // If index is a colon, resizing to RHS dimensions is
-	      // allowed because we started out empty.
-
-	      if (idx(i).is_colon ())
+	      int ncolon = 0;
+	      int fcolon = 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;
+		  } 
+		else
+		  {
+		    octave_idx_type cap = idx(i).capacity ();
+		    new_dims_numel *= cap;
+		    if (cap != 1)
+		      new_dims_vec ++;
+		  }
+
+	      if (ncolon == n_idx)
 		{
-		  if (k < rhs_dims.length ())
-		    new_dims(i) = rhs_dims(k++);
-		  else
-		    new_dims(i) = 1;
+		  new_dims = rhs_dims;
+		  new_dims.resize (n_idx);
+		  for (int i = rhs_dims_len; i < n_idx; i++)
+		    new_dims (i) = 1;
 		}
 	      else
 		{
-		  octave_idx_type nelem = idx(i).capacity ();
-
-		  if (nelem >= 1
-		      && ((k < rhs_dims.length () && nelem == rhs_dims(k))
-			  || rhs_is_scalar) || ! idx(i).is_colon())
-		    k++;
-		  else if (! (nelem == 1 || rhs_is_scalar))
+		  octave_idx_type rhs_dims_numel = rhs_dims.numel ();
+	      	      
+		  for (int i = 0; i < n_idx; i++)
+		    new_dims(i) = idx(i).orig_empty () ? 0 : idx(i).max () + 1;
+
+		  if (new_dims_numel != rhs_dims_numel && 
+		      ncolon > 0 && new_dims_numel == 1)
+		    {
+		      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 || new_dims_vec > 1)
 		    {
 		      (*current_liboctave_error_handler)
 			("A(IDX-LIST) = RHS: mismatched index and RHS dimension");
 		      return retval;
 		    }
-
-		  new_dims(i) = idx(i).orig_empty () ? 0 : idx(i).max () + 1;
+		}
+	    }
+	  else
+	    {
+	      int k = 0;
+	      for (int i = 0; i < n_idx; i++)
+		{
+		  if (idx(i).is_colon ())
+		    {
+		      if (k < rhs_dims_len)
+			new_dims(i) = rhs_dims(k++);
+		      else
+			new_dims(i) = 1;
+		    }
+		  else
+		    {
+		      octave_idx_type nelem = idx(i).capacity ();
+
+		      if (nelem >= 1 
+			  && (k < rhs_dims_len && nelem == rhs_dims(k)))
+			k++;
+		      else if (nelem != 1)
+			{
+			  (*current_liboctave_error_handler)
+			    ("A(IDX-LIST) = RHS: mismatched index and RHS dimension");
+			  return retval;
+			}
+		      new_dims(i) = idx(i).orig_empty () ? 0 : 
+			idx(i).max () + 1;
+		    }
 		}
 	    }
 	}
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,3 +1,11 @@
+2008-03-26  David Bateman  <dbateman@feee.fr>
+
+	* Array.cc (assignN): refactor calculation of new dimensions when
+	original matrix is empty.
+	* Array-util.cc (bool is_vector (const dim_vector&)): New
+	function.
+	* Array-util.h (bool is_vector (const dim_vector&)): declare it.
+
 2008-03-25  David Bateman  <dbateman@free.fr>
 
 	* sparse-base-chol.h (sparse_base_chol_rep::~sparse_base_chol_rep
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,11 @@
+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>
+
+	* test_index-wfi-f.m: New tests.
+
 2008-03-07  John W. Eaton  <jwe@octave.org>
 
 	* test_logical-wfi-t.m, test_logical-wfi-f.m: Update tests for
--- a/test/test_index-wfi-f.m
+++ b/test/test_index-wfi-f.m
@@ -24,7 +24,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = [];
 %! assert(isempty (a));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-2.m
 %!test
@@ -32,7 +32,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! assert(a(1),1);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-3.m
 %!test
@@ -40,7 +40,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! assert(a(:),1);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-4.m
 %!test
@@ -48,7 +48,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! assert(a(:,:),1);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-5.m
 %!test
@@ -56,7 +56,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! assert(a(1,:),1);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-6.m
 %!test
@@ -64,7 +64,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! assert(a(:,1),1);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-7.m
 %!test
@@ -72,7 +72,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! assert(isempty (a(logical (0))));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-8.m
 %!test
@@ -80,7 +80,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a(-1)");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-9.m
 %!test
@@ -88,7 +88,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a(2);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-10.m
 %!test
@@ -96,7 +96,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a(2,:);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-11.m
 %!test
@@ -104,7 +104,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a(:,2);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-12.m
 %!test
@@ -112,7 +112,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a(-1,:);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-13.m
 %!test
@@ -120,7 +120,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a(:,-1);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-14.m
 %!test
@@ -128,7 +128,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([1,2,3]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-15.m
 %!test
@@ -136,7 +136,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([1;2;3]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-16.m
 %!test
@@ -144,7 +144,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([1,2;3,4]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-17.m
 %!test
@@ -152,7 +152,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([0,1]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-18.m
 %!test
@@ -160,7 +160,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([0;1]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-19.m
 %!test
@@ -168,7 +168,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([-1,0]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/s-20.m
 %!test
@@ -176,7 +176,7 @@
 %! warning ("off", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([-1;0]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-1.m
 %!test
@@ -186,7 +186,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(a(1),4);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-2.m
 %!test
@@ -196,7 +196,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(a(2),3);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-3.m
 %!test
@@ -206,7 +206,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(all (a(:) == a_prime));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-4.m
 %!test
@@ -216,7 +216,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(all (a(1,:) == a));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-5.m
 %!test
@@ -226,7 +226,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(a(:,3),2);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-6.m
 %!test
@@ -236,7 +236,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(all (a(:,:) == a));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-7.m
 %!test
@@ -246,7 +246,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(all (a(logical ([0,1,1,0])) == mid_a));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-8.m
 %!test
@@ -256,7 +256,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! fail("a(0);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-9.m
 %!test
@@ -266,7 +266,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! fail("a(5);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-10.m
 %!test
@@ -276,7 +276,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! fail("a(0,1);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-11.m
 %!test
@@ -286,7 +286,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(isempty (a(logical (0),:)));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-12.m
 %!test
@@ -296,7 +296,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! fail("a(:,0);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-13.m
 %!test
@@ -306,7 +306,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(isempty (a([])));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-14.m
 %!test
@@ -316,7 +316,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(isempty (a([],:)));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/v-15.m
 %!test
@@ -326,7 +326,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(isempty (a(:,[])));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/m-1.m
 %!test
@@ -339,7 +339,7 @@
 %! a_row_1 = [1,2];
 %! a_row_2 = [3,4];
 %! assert(all (all (a(:,:) == a)));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/m-2.m
 %!test
@@ -352,7 +352,7 @@
 %! a_row_1 = [1,2];
 %! a_row_2 = [3,4];
 %! assert(all (a(:) == a_fvec));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/m-3.m
 %!test
@@ -365,7 +365,7 @@
 %! a_row_1 = [1,2];
 %! a_row_2 = [3,4];
 %! fail("a(0);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-f/m-4.m
 %!test
@@ -378,78 +378,132 @@
 %! a_row_1 = [1,2];
 %! a_row_2 = [3,4];
 %! assert(a(2),3);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! 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;
-%! 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)
-%! 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)
--- a/test/test_index-wfi-t.m
+++ b/test/test_index-wfi-t.m
@@ -24,7 +24,7 @@
 %! warn_fortran_indexing = 1;
 %! a = [];
 %! assert(isempty (a));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-2.m
 %!test
@@ -32,7 +32,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! assert(a(1),1);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-3.m
 %!test
@@ -40,7 +40,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! assert(a(:),1);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-4.m
 %!test
@@ -48,7 +48,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! assert(a(:,:),1);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-5.m
 %!test
@@ -56,7 +56,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! assert(a(1,:),1);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-6.m
 %!test
@@ -64,7 +64,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! assert(a(:,1),1);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-7.m
 %!test
@@ -72,7 +72,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! assert(isempty (a(logical (0))));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-8.m
 %!test
@@ -80,7 +80,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a(-1);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-9.m
 %!test
@@ -88,7 +88,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a(2);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-10.m
 %!test
@@ -96,7 +96,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a(2,:);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-11.m
 %!test
@@ -104,7 +104,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a(:,2);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-12.m
 %!test
@@ -112,7 +112,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a(-1,:);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-13.m
 %!test
@@ -120,7 +120,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a(:,-1);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-14.m
 %!test
@@ -128,7 +128,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([1,2,3]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-15.m
 %!test
@@ -136,7 +136,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([1;2;3]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-16.m
 %!test
@@ -144,7 +144,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([1,2;3,4]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-17.m
 %!test
@@ -152,7 +152,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([0,1]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-18.m
 %!test
@@ -160,7 +160,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([0;1]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-19.m
 %!test
@@ -168,7 +168,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([-1,0]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/s-20.m
 %!test
@@ -176,7 +176,7 @@
 %! warning ("on", "Octave:fortran-indexing");
 %! a = 1;
 %! fail("a([-1;0]);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-1.m
 %!test
@@ -186,7 +186,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(a(1),4);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-2.m
 %!test
@@ -196,7 +196,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(a(2),3);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-3.m
 %!test
@@ -206,7 +206,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(all (a(:) == a_prime));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-4.m
 %!test
@@ -216,7 +216,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(all (a(1,:) == a));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-5.m
 %!test
@@ -226,7 +226,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(a(:,3),2);
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-6.m
 %!test
@@ -236,7 +236,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(all (a(:,:) == a));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-7.m
 %!test
@@ -246,7 +246,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(all (a(logical ([0,1,1,0])) == mid_a));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-8.m
 %!test
@@ -256,7 +256,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! fail("a(0);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-9.m
 %!test
@@ -266,7 +266,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! fail("a(5);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-10.m
 %!test
@@ -276,7 +276,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! fail("a(0,1);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-11.m
 %!test
@@ -286,7 +286,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(isempty (a(logical (0),:)));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-12.m
 %!test
@@ -296,7 +296,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! fail("a(:,0);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-13.m
 %!test
@@ -306,7 +306,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(isempty (a([])));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-14.m
 %!test
@@ -316,7 +316,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(isempty (a([],:)));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/v-15.m
 %!test
@@ -326,7 +326,7 @@
 %! a_prime = [4;3;2;1];
 %! mid_a = [3,2];
 %! assert(isempty (a(:,[])));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/m-1.m
 %!test
@@ -339,7 +339,7 @@
 %! a_row_1 = [1,2];
 %! a_row_2 = [3,4];
 %! assert(all (all (a(:,:) == a)));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/m-2.m
 %!test
@@ -352,7 +352,7 @@
 %! a_row_1 = [1,2];
 %! a_row_2 = [3,4];
 %! assert(all (a(:) == a_fvec));
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/m-3.m
 %!test
@@ -365,7 +365,7 @@
 %! a_row_1 = [1,2];
 %! a_row_2 = [3,4];
 %! fail("a(0);");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");
 
 %% test/octave.test/index-wfi-t/m-4.m
 %!test
@@ -378,4 +378,4 @@
 %! a_row_1 = [1,2];
 %! a_row_2 = [3,4];
 %! fail("a(2);","warning");
-%! warning ("wfi.state", "Octave:fortran-indexing");
+%! warning (wfi.state, "Octave:fortran-indexing");