# HG changeset patch # User jwe # Date 1074715825 0 # Node ID 4d2e1623c9a9c0b013f4f8d21404b9b61c508142 # Parent 34a740dc31a6f8c52b5f0fb80d83b6b62658a776 [project @ 2004-01-21 20:10:25 by jwe] diff -r 34a740dc31a6 -r 4d2e1623c9a9 liboctave/Array.cc --- a/liboctave/Array.cc Wed Jan 21 19:55:37 2004 +0000 +++ b/liboctave/Array.cc Wed Jan 21 20:10:25 2004 +0000 @@ -2059,7 +2059,7 @@ for (int i = 0; i < n; i++) { elt_idx = get_elt_idx (ra_idx, result_idx); - + int numelem_elt = get_scalar_idx (elt_idx, this_dims); if (numelem_elt > length () || numelem_elt < 0) @@ -2067,9 +2067,9 @@ ("invalid N-d array index"); else retval.elem (i) = elem (numelem_elt); - + increment_index (result_idx, frozen_lengths); - + } } } @@ -2623,104 +2623,103 @@ else { (*current_liboctave_error_handler) - ("A(I) = X: X must be a scalar or a matrix with the same size as I"); - + ("A(I) = X: X must be a scalar or a matrix with the same size as I"); + retval = 0; } // idx_vector::freeze() printed an error message for us. } - else if (n_idx < lhs_dims.length ()) + } + + else if (n_idx < lhs_dims.length ()) + { + // Number of indices is less than dimensions. + + if (any_ones (idx_is_colon)|| any_ones (idx_is_colon_equiv)) { - // Number of indices is less than dimensions. - - if (any_ones (idx_is_colon)|| any_ones (idx_is_colon_equiv)) - { - (*current_liboctave_error_handler) - ("number of indices is less than number of dimensions, one or more indices are colons"); - } - else - { - // Fewer indices than dimensions, no colons. - - bool resize = false; - - // Subtract one since the last idx do not tell us - // anything about dimensionality. - - for (int i = 0; i < idx.length () - 1; i++) - { - // Subtract one since idx counts from 0 while dims - // count from 1. - - if (idx(i).elem (0) + 1 > lhs_dims(i)) - resize = true; - } - - if (resize) - { - dim_vector new_dims; - new_dims.resize (lhs_dims.length ()); - - for (int i = 0; i < lhs_dims.length (); i++) - { - if (i < idx.length () - 1 - && idx(i).elem (0) + 1 > lhs_dims(i)) - new_dims(i) = idx(i).elem (0)+1; - else - new_dims(i) = lhs_dims(i); - } - - lhs.resize (new_dims, rfv); - - lhs_dims = lhs.dims (); - } - - Array one_arg_temp (1, 0); - - RT scalar = rhs.elem (one_arg_temp); - - Array int_arr = conv_to_int_array (idx); - - int numelem = get_scalar_idx (int_arr, lhs_dims); - - if (numelem > lhs.length () || numelem < 0) - (*current_liboctave_error_handler) - ("attempt to grow array along ambiguous dimension"); - else - lhs.checkelem (numelem) = scalar; - } + (*current_liboctave_error_handler) + ("number of indices is less than number of dimensions, one or more indices are colons"); } else { - // Scalar to matrix assignment with as many indices as lhs - // dimensions. - - int n = Array::get_size (frozen_len); - - Array result_idx (lhs_dims.length (), 0); - - Array elt_idx; + // Fewer indices than dimensions, no colons. + + bool resize = false; + + // Subtract one since the last idx do not tell us + // anything about dimensionality. + + for (int i = 0; i < idx.length () - 1; i++) + { + // Subtract one since idx counts from 0 while dims + // count from 1. + + if (idx(i).elem (0) + 1 > lhs_dims(i)) + resize = true; + } + + if (resize) + { + dim_vector new_dims; + new_dims.resize (lhs_dims.length ()); + + for (int i = 0; i < lhs_dims.length (); i++) + { + if (i < idx.length () - 1 + && idx(i).elem (0) + 1 > lhs_dims(i)) + new_dims(i) = idx(i).elem (0)+1; + else + new_dims(i) = lhs_dims(i); + } + + lhs.resize (new_dims, rfv); + + lhs_dims = lhs.dims (); + } RT scalar = rhs.elem (0); - for (int i = 0; i < n; i++) - { - elt_idx = get_elt_idx (idx, result_idx); - - dim_vector lhs_inc; - lhs_inc.resize (lhs_dims.length ()); - - for (int j = 0; j < lhs_dims.length (); j++) - lhs_inc(j) = lhs_dims(j) + 1; - - if (index_in_bounds(elt_idx, lhs_inc)) - lhs.checkelem (elt_idx) = scalar; - else - lhs.checkelem (elt_idx) = rfv; - - increment_index (result_idx, frozen_len); - } + Array int_arr = conv_to_int_array (idx); + + int numelem = get_scalar_idx (int_arr, lhs_dims); + + if (numelem > lhs.length () || numelem < 0) + (*current_liboctave_error_handler) + ("attempt to grow array along ambiguous dimension"); + else + lhs.checkelem (numelem) = scalar; + } + } + else if (n_idx == lhs_dims.length () && rhs_is_scalar) + { + // Scalar to matrix assignment with as many indices as lhs + // dimensions. + + int n = Array::get_size (frozen_len); + + Array result_idx (lhs_dims.length (), 0); + + Array elt_idx; + + RT scalar = rhs.elem (0); + + for (int i = 0; i < n; i++) + { + elt_idx = get_elt_idx (idx, result_idx); + + dim_vector lhs_inc; + lhs_inc.resize (lhs_dims.length ()); + + for (int j = 0; j < lhs_dims.length (); j++) + lhs_inc(j) = lhs_dims(j) + 1; + + if (index_in_bounds(elt_idx, lhs_inc)) + lhs.checkelem (elt_idx) = scalar; + else + lhs.checkelem (elt_idx) = rfv; + + increment_index (result_idx, frozen_len); } } else if (rhs_dims.length () > 1) @@ -2738,7 +2737,9 @@ for (int j = 0; j < idx_is_colon.length (); j++) { - if (idx_is_colon(j)) + if (rhs_dims(jj) == 1) + jj++; + else if (idx_is_colon(j)) { if (jj > rhs_dims_len || rhs_dims(jj) < lhs_dims(j)) { @@ -2751,6 +2752,9 @@ } } + if (jj != rhs_dims_len) + dim_ok = false; + if (! dim_ok) (*current_liboctave_error_handler) ("subscripted assignment dimension mismatch"); @@ -2790,7 +2794,7 @@ { new_dims(i) = lhs_dims(i) > idx(i).max () + 1 ? lhs_dims(i) : idx(i).max () + 1; - if (frozen_len(i) > 1) + if ((ii < rhs_dims.length () && rhs_dims (ii) == 1) || frozen_len(i) > 1) //Changed this from 1 to 0 ii++; } if (new_dims(i) != lhs_dims(i)) diff -r 34a740dc31a6 -r 4d2e1623c9a9 liboctave/ChangeLog --- a/liboctave/ChangeLog Wed Jan 21 19:55:37 2004 +0000 +++ b/liboctave/ChangeLog Wed Jan 21 20:10:25 2004 +0000 @@ -1,3 +1,11 @@ +2004-01-21 Petter Risholm + + * Array.cc (Array::assignN(Array&, const Array&, + const LT&)): Fix incorrectly nested if statement. + Retrieve scalar element by passin 0 instead of an index array. + Check for singleton dimensions where RHS is matrix or higher + dimension. + 2004-01-19 John W. Eaton * lo-ieee.cc (octave_ieee_init): Ensure that octave_Inf,