Mercurial > hg > octave-lyh
changeset 4673:6639c2574023
[project @ 2003-12-10 16:11:54 by jwe]
author | jwe |
---|---|
date | Wed, 10 Dec 2003 16:11:54 +0000 |
parents | 2c5adf308c84 |
children | 7736835a5c8e |
files | liboctave/Array-util.cc liboctave/Array.cc liboctave/ChangeLog liboctave/dim-vector.h scripts/ChangeLog scripts/statistics/base/mean.m src/ChangeLog src/OPERATORS/op-bm-bm.cc src/OPERATORS/op-cell.cc src/OPERATORS/op-cm-cm.cc src/OPERATORS/op-m-m.cc src/OPERATORS/op-str-str.cc src/OPERATORS/op-streamoff.cc |
diffstat | 13 files changed, 122 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array-util.cc +++ b/liboctave/Array-util.cc @@ -311,15 +311,6 @@ return retval; } -dim_vector -get_zero_len_size (const dim_vector& /* frozen_lengths */, - const dim_vector& /* dimensions */) -{ - dim_vector retval; - assert (0); - return retval; -} - bool all_colon_equiv (const Array<idx_vector>& ra_idx, const dim_vector& frozen_lengths)
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -1859,6 +1859,7 @@ else { dim_vector new_dims; + new_dims.resize (n_dims); for (int i = 0; i < n_dims; i++) @@ -1867,6 +1868,8 @@ new_dims(i) = 1; } + new_dims.chop_trailing_singletons (); + retval = Array<T> (new_dims); } } @@ -1885,6 +1888,8 @@ new_dims(i) = 1; } + new_dims.chop_trailing_singletons (); + retval = Array<T> (tmp, new_dims); } else @@ -1917,6 +1922,8 @@ result_dims(1) = (ntot > 0 ? 1 : 0); } + result_dims.chop_trailing_singletons (); + retval.resize (result_dims); int n = number_of_elements (result_dims); @@ -2022,14 +2029,12 @@ { if (all_ok (ra_idx)) { - if (any_orig_empty (ra_idx)) + if (any_orig_empty (ra_idx) || any_zero_len (frozen_lengths)) { + frozen_lengths.chop_trailing_singletons (); + retval.resize (frozen_lengths); } - else if (any_zero_len (frozen_lengths)) - { - retval.resize (get_zero_len_size (frozen_lengths, dimensions)); - } else if (all_colon_equiv (ra_idx, dimensions) && frozen_lengths.length () == n_dims) { @@ -2037,9 +2042,13 @@ } else { - retval.resize (frozen_lengths); - - int n = number_of_elements (frozen_lengths); + dim_vector frozen_lengths_for_resize = frozen_lengths; + + frozen_lengths_for_resize.chop_trailing_singletons (); + + retval.resize (frozen_lengths_for_resize); + + int n = retval.length (); Array<int> result_idx (ra_idx.length (), 0); @@ -2051,17 +2060,13 @@ { elt_idx = get_elt_idx (ra_idx, result_idx); - int numelem_result = - get_scalar_idx (result_idx, frozen_lengths); - int numelem_elt = get_scalar_idx (elt_idx, this_dims); - if (numelem_result > length () || numelem_result < 0 - || numelem_elt > length () || numelem_elt < 0) + if (numelem_elt > length () || numelem_elt < 0) (*current_liboctave_error_handler) - ("attempt to grow array along ambiguous dimension"); + ("invalid N-d array index"); else - retval.checkelem (numelem_result) = checkelem (numelem_elt); + retval.elem (i) = elem (numelem_elt); increment_index (result_idx, frozen_lengths);
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,18 @@ +2003-12-10 John W. Eaton <jwe@bevo.che.wisc.edu> + + * Array-util.cc (get_zero_len_size): Delete. + * Array.cc (Array<T>::index (Array<idx_vector>&, int, const T&)): + Handle zero-length result dimensions the same as empty original + indices. + +2003-12-09 John W. Eaton <jwe@bevo.che.wisc.edu> + + * dim-vector.h (dim_vector::chop_trailing_singleton_dims, + dim_vector::dim_vector_rep::chop_trailing_singleton_dims): + New functions. + * Array.cc (ArrayN<T>::indexN): Use it. + (ArrayN<T>::index (Array<idx_vector>&, int, const T&)): Likewise. + 2003-11-26 John W. Eaton <jwe@bevo.che.wisc.edu> * boolNDArray.cc: Define BOOL ops. Define mixed CMP ops.
--- a/liboctave/dim-vector.h +++ b/liboctave/dim-vector.h @@ -111,6 +111,17 @@ return dims[i]; } + void chop_trailing_singletons (void) + { + for (int i = ndims - 1; i > 1; i--) + { + if (dims[i] == 1) + ndims--; + else + break; + } + } + private: // No assignment! @@ -200,7 +211,6 @@ } } - std::string str (char sep = 'x') const { OSSTREAM buf; @@ -287,6 +297,12 @@ return retval; } + + void chop_trailing_singletons (void) + { + make_unique (); + rep->chop_trailing_singletons (); + } }; static inline bool
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2003-12-10 Quentin Spencer <qspencer@ieee.org> + + * statistics/base/mean.m: Remove special case for row vectors. + 2003-11-19 Quentin Spencer <qspencer@ieee.org> * signal/freqz_plot.m: Save and restore automatic_replot too.
--- a/scripts/statistics/base/mean.m +++ b/scripts/statistics/base/mean.m @@ -87,10 +87,6 @@ usage ("mean (x, dim, opt) or mean (x, dim, opt)"); endif - if (rows (x) == 1) - x = x.'; - endif - if (need_dim) t = find (size (x) != 1); if (isempty (t))
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-12-09 John W. Eaton <jwe@bevo.che.wisc.edu> + + * OPERATORS/op-cell.cc: Allow transpose for cell arrays. + * OPERATORS/op-m-m.cc, OPERATORS/op-cm-cm.cc, + OPERATORS/op-bm-bm.cc, OPERATORS/op-streamoff.cc, + OPERATORS/op-str-str.cc: Improve error message for attempt to + transpose N-d object. + 2003-11-27 John W. Eaton <jwe@bevo.che.wisc.edu> * pt-arg-list.cc (F__end__): Handle N-d objects.
--- a/src/OPERATORS/op-bm-bm.cc +++ b/src/OPERATORS/op-bm-bm.cc @@ -45,7 +45,13 @@ { CAST_UNOP_ARG (const octave_bool_matrix&); - return octave_value (v.bool_matrix_value().transpose ()); + if (v.ndims () > 2) + { + error ("transpose not defined for N-d objects"); + return octave_value (); + } + else + return octave_value (v.bool_matrix_value().transpose ()); } // bool matrix by bool matrix ops.
--- a/src/OPERATORS/op-cell.cc +++ b/src/OPERATORS/op-cell.cc @@ -39,11 +39,27 @@ // cell ops. +DEFUNOP (transpose, cell) +{ + CAST_UNOP_ARG (const octave_cell&); + + if (v.ndims () > 2) + { + error ("transpose not defined for N-d objects"); + return octave_value (); + } + else + return octave_value (Cell (v.cell_value().transpose ())); +} + DEFASSIGNANYOP_FN (assign, cell, assign); void install_cell_ops (void) { + INSTALL_UNOP (op_transpose, octave_cell, transpose); + INSTALL_UNOP (op_hermitian, octave_cell, transpose); + INSTALL_ASSIGNANYOP (op_asn_eq, octave_cell, assign); }
--- a/src/OPERATORS/op-cm-cm.cc +++ b/src/OPERATORS/op-cm-cm.cc @@ -46,14 +46,26 @@ { CAST_UNOP_ARG (const octave_complex_matrix&); - return octave_value (v.complex_matrix_value().transpose ()); + if (v.ndims () > 2) + { + error ("transpose not defined for N-d objects"); + return octave_value (); + } + else + return octave_value (v.complex_matrix_value().transpose ()); } DEFUNOP (hermitian, complex_matrix) { CAST_UNOP_ARG (const octave_complex_matrix&); - return octave_value (v.complex_matrix_value().hermitian ()); + if (v.ndims () > 2) + { + error ("complex-conjugate transpose not defined for N-d objects"); + return octave_value (); + } + else + return octave_value (v.complex_matrix_value().hermitian ()); } DEFNCUNOP_METHOD (incr, complex_matrix, increment)
--- a/src/OPERATORS/op-m-m.cc +++ b/src/OPERATORS/op-m-m.cc @@ -46,7 +46,13 @@ { CAST_UNOP_ARG (const octave_matrix&); - return octave_value (v.matrix_value().transpose ()); + if (v.ndims () > 2) + { + error ("transpose not defined for N-d objects"); + return octave_value (); + } + else + return octave_value (v.matrix_value().transpose ()); } DEFNCUNOP_METHOD (incr, matrix, increment)
--- a/src/OPERATORS/op-str-str.cc +++ b/src/OPERATORS/op-str-str.cc @@ -41,7 +41,13 @@ { CAST_UNOP_ARG (const octave_char_matrix_str&); - return octave_value (v.char_matrix_value().transpose (), true); + if (v.ndims () > 2) + { + error ("transpose not defined for N-d objects"); + return octave_value (); + } + else + return octave_value (v.char_matrix_value().transpose (), true); } // string by string ops.
--- a/src/OPERATORS/op-streamoff.cc +++ b/src/OPERATORS/op-streamoff.cc @@ -38,7 +38,13 @@ { CAST_UNOP_ARG (const octave_streamoff&); - return octave_value (streamoff_array (v.streamoff_array_value().transpose ())); + if (v.ndims () > 2) + { + error ("transpose not defined for N-d objects"); + return octave_value (); + } + else + return octave_value (streamoff_array (v.streamoff_array_value().transpose ())); } DEFNCUNOP_METHOD (incr, streamoff, increment)