Mercurial > hg > octave-lojdl
changeset 7573:755bf7ecc29b
eliminate one_zero stuff from idx_vector
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 08 Mar 2008 10:14:37 -0500 |
parents | 85da2ab0c6fd |
children | 9669b69e34ef |
files | liboctave/Array.cc liboctave/ChangeLog liboctave/Sparse.cc liboctave/idx-vector.cc liboctave/idx-vector.h |
diffstat | 5 files changed, 43 insertions(+), 137 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -2074,12 +2074,6 @@ { retval.resize_no_fill (0); } - else if (len == 1 && n > 1 - && idx_arg.one_zero_only () - && idx_arg.ones_count () == n) - { - retval.resize_and_fill (n, elem (0)); - } else { retval.resize_no_fill (n); @@ -2133,9 +2127,7 @@ octave_idx_type len = tmp.length (); - if (len == 0 && idx_arg.one_zero_only ()) - retval = Array<T> (tmp, dim_vector (0, 0)); - else if (len >= idx_orig_dims.numel ()) + if (len >= idx_orig_dims.numel ()) retval = Array<T> (tmp, idx_orig_dims); } else if (nr == 1 || nc == 1) @@ -2148,8 +2140,7 @@ octave_idx_type len = tmp.length (); - if ((len != 0 && idx_arg.one_zero_only ()) - || idx_orig_rows == 1 || idx_orig_columns == 1) + if (idx_orig_rows == 1 || idx_orig_columns == 1) { if (nr == 1) retval = Array<T> (tmp, dim_vector (1, len)); @@ -2161,11 +2152,8 @@ } else { - if (! (idx_arg.one_zero_only () - && idx_orig_rows == nr - && idx_orig_columns == nc)) - (*current_liboctave_warning_with_id_handler) - ("Octave:fortran-indexing", "single index used for matrix"); + (*current_liboctave_warning_with_id_handler) + ("Octave:fortran-indexing", "single index used for matrix"); // This code is only for indexing matrices. The vector // cases are handled above. @@ -2177,12 +2165,6 @@ octave_idx_type result_nr = idx_orig_rows; octave_idx_type result_nc = idx_orig_columns; - if (idx_arg.one_zero_only ()) - { - result_nr = idx_arg.ones_count (); - result_nc = (result_nr > 0 ? 1 : 0); - } - retval.resize_no_fill (result_nr, result_nc); octave_idx_type k = 0; @@ -2232,9 +2214,7 @@ { bool vec_equiv = vector_equivalent (dv); - if (! vec_equiv - && ! (ra_idx.is_colon () - || (ra_idx.one_zero_only () && idx_orig_dims == dv))) + if (! (vec_equiv || ra_idx.is_colon ())) (*current_liboctave_warning_with_id_handler) ("Octave:fortran-indexing", "single index used for N-d array"); @@ -2262,14 +2242,6 @@ else result_dims = idx_orig_dims; - if (ra_idx.one_zero_only ()) - { - result_dims.resize (2); - octave_idx_type ntot = ra_idx.ones_count (); - result_dims(0) = ntot; - result_dims(1) = (ntot > 0 ? 1 : 0); - } - result_dims.chop_trailing_singletons (); retval.resize (result_dims); @@ -3067,10 +3039,7 @@ } else { - if (! (idx_i.is_colon () - || (idx_i.one_zero_only () - && idx_i.orig_rows () == lhs_nr - && idx_i.orig_columns () == lhs_nc))) + if (! idx_i.is_colon ()) (*current_liboctave_warning_with_id_handler) ("Octave:fortran-indexing", "single index used for matrix"); @@ -3182,9 +3151,7 @@ idx_vector iidx = idx(0); int iidx_is_colon = iidx.is_colon (); - if (! (iidx_is_colon - || (iidx.one_zero_only () - && iidx.orig_dimensions () == lhs.dims ()))) + if (! iidx_is_colon) (*current_liboctave_warning_with_id_handler) ("Octave:fortran-indexing", "single index used for N-d array");
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,15 @@ +2008-03-08 John W. Eaton <jwe@octave.org> + + * Sparse.cc (Sparse<T>::index, assign): Likewise. + * Array.cc (Array<T>::index1, Array<T>::index2, Array<T>::indexN, + assign2): Eliminate use of idx_vector::is_one_zero method. + * idx-vector.cc, idx-vector.h + (idx_vector::maybe_convert_one_zero_to_idx, + IDX_VEC_REP::maybe_convert_one_zero_to_idx): Delete unused function. + (IDX_VEC_REP::one_zero): Delete data member. + (IDX_VEC_REP::is_colon_equiv): Delete one_zero check. + (idx_vector::is_one_zero, IDX_VEC_REP::is_one_zero): Delete function. + 2008-03-07 John W. Eaton <jwe@octave.org> * idx-vector.cc (IDX_VEC_REP::idx_vector_rep (bool),
--- a/liboctave/Sparse.cc +++ b/liboctave/Sparse.cc @@ -1514,9 +1514,7 @@ // you get!! octave_idx_type n = idx_arg.freeze (length (), "sparse vector", resize_ok); if (n == 0) - if (idx_arg.one_zero_only ()) - retval = Sparse<T> (dim_vector (0, 0)); - else + retval = Sparse<T> (idx_orig_dims); else if (nz < 1) if (n >= idx_orig_dims.numel ()) @@ -1578,8 +1576,7 @@ else retval = Sparse<T> (dim_vector (0, 1)); else if (nz < 1) - if ((n != 0 && idx_arg.one_zero_only ()) - || idx_orig_rows == 1 || idx_orig_columns == 1) + if (idx_orig_rows == 1 || idx_orig_columns == 1) retval = Sparse<T> ((nr == 1 ? 1 : n), (nr == 1 ? n : 1)); else retval = Sparse<T> (idx_orig_dims); @@ -1613,8 +1610,7 @@ } } - if (idx_arg.one_zero_only () || idx_orig_rows == 1 || - idx_orig_columns == 1) + if (idx_orig_rows == 1 || idx_orig_columns == 1) { if (nr == 1) { @@ -1723,11 +1719,8 @@ } else { - if (! (idx_arg.one_zero_only () - && idx_orig_rows == nr - && idx_orig_columns == nc)) - (*current_liboctave_warning_with_id_handler) - ("Octave:fortran-indexing", "single index used for sparse matrix"); + (*current_liboctave_warning_with_id_handler) + ("Octave:fortran-indexing", "single index used for sparse matrix"); // This code is only for indexing matrices. The vector // cases are handled above. @@ -1739,14 +1732,8 @@ octave_idx_type result_nr = idx_orig_rows; octave_idx_type result_nc = idx_orig_columns; - if (idx_arg.one_zero_only ()) - { - result_nr = idx_arg.ones_count (); - result_nc = (result_nr > 0 ? 1 : 0); - } - if (nz < 1) - retval = Sparse<T> (result_nr, result_nc); + retval = Sparse<T> (result_nr, result_nc); else { // Count number of non-zero elements @@ -3128,10 +3115,7 @@ } else { - if (! (idx_i.is_colon () - || (idx_i.one_zero_only () - && idx_i.orig_rows () == lhs_nr - && idx_i.orig_columns () == lhs_nc))) + if (! idx_i.is_colon ()) (*current_liboctave_warning_with_id_handler) ("Octave:fortran-indexing", "single index used for matrix");
--- a/liboctave/idx-vector.cc +++ b/liboctave/idx-vector.cc @@ -45,9 +45,8 @@ range_base (a.range_base), range_step (a.range_step), max_val (a.max_val), min_val (a.min_val), frozen_at_z_len (a.frozen_at_z_len), frozen_len (a.frozen_len), - colon (a.colon), range(a.range), one_zero (a.one_zero), - initialized (a.initialized), frozen (a.frozen), - colon_equiv_checked (a.colon_equiv_checked), + colon (a.colon), range(a.range), initialized (a.initialized), + frozen (a.frozen), colon_equiv_checked (a.colon_equiv_checked), colon_equiv (a.colon_equiv), orig_dims (a.orig_dims) { if (len > 0) @@ -105,7 +104,7 @@ : data (0), len (v.length ()), num_zeros (0), num_ones (0), range_base (0), range_step (0), max_val (0), min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), colon (0), range(0), - one_zero (0), initialized (0), frozen (0), colon_equiv_checked (0), + initialized (0), frozen (0), colon_equiv_checked (0), colon_equiv (0), orig_dims (len, 1) { if (len == 0) @@ -140,7 +139,7 @@ : data (0), len (nda.length ()), num_zeros (0), num_ones (0), range_base (0), range_step (0), max_val (0), min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), colon (0), range(0), - one_zero (0), initialized (0), frozen (0), colon_equiv_checked (0), + initialized (0), frozen (0), colon_equiv_checked (0), colon_equiv (0), orig_dims (nda.dims ()) { if (len == 0) @@ -176,7 +175,7 @@ : data (0), len (r.nelem ()), num_zeros (0), num_ones (0), range_base (0), range_step (0), max_val (0), min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), colon (0), - range(1), one_zero (0), initialized (0), frozen (0), + range(1), initialized (0), frozen (0), colon_equiv_checked (0), colon_equiv (0), orig_dims (1, len) { if (len < 0) @@ -206,8 +205,8 @@ : data (0), len (1), num_zeros (0), num_ones (0), range_base (0), range_step (0), max_val (0), min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), colon (0), - range(1), one_zero (0), initialized (0), frozen (0), - colon_equiv_checked (0), colon_equiv (0), orig_dims (1, 1) + range(1), initialized (0), frozen (0), colon_equiv_checked (0), + colon_equiv (0), orig_dims (1, 1) { if (idx_is_inf_or_nan (d)) return; @@ -229,9 +228,8 @@ : data (0), len (1), num_zeros (0), num_ones (0), range_base (tree_to_mat_idx (i)), range_step (1), max_val (0), min_val (0), count (1), frozen_at_z_len (0), - frozen_len (0), colon (0), range(1), one_zero (0), - initialized (0), frozen (0), colon_equiv_checked (0), - colon_equiv (0), orig_dims (1, 1) + frozen_len (0), colon (0), range(1), initialized (0), + frozen (0), colon_equiv_checked (0), colon_equiv (0), orig_dims (1, 1) { init_state (); } @@ -240,7 +238,7 @@ : data (0), len (0), num_zeros (0), num_ones (0), range_base (0), range_step (0), max_val (0), min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), colon (1), range(0), - one_zero (0), initialized (0), frozen (0), colon_equiv_checked (0), + initialized (0), frozen (0), colon_equiv_checked (0), colon_equiv (0), orig_dims (0, 0) { assert (c == ':'); @@ -252,7 +250,7 @@ : data (0), len (b ? 1 : 0), num_zeros (0), num_ones (0), range_base (0), range_step (0), max_val (0), min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), colon (0), range(0), - one_zero (0), initialized (0), frozen (0), colon_equiv_checked (0), + initialized (0), frozen (0), colon_equiv_checked (0), colon_equiv (0), orig_dims (len, len) { if (len == 0) @@ -269,7 +267,7 @@ : data (0), len (bnda.nnz ()), num_zeros (0), num_ones (0), range_base (0), range_step (0), max_val (0), min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), colon (0), - range(0), one_zero (0), initialized (0), frozen (0), + range(0), initialized (0), frozen (0), colon_equiv_checked (0), colon_equiv (0), orig_dims () { if (len == 0) @@ -324,7 +322,6 @@ frozen_len = a.frozen_len; colon = a.colon; range = a.range; - one_zero = a.one_zero; initialized = a.initialized; frozen = a.frozen; colon_equiv_checked = a.colon_equiv_checked; @@ -391,49 +388,6 @@ initialized = 1; } -void -IDX_VEC_REP::maybe_convert_one_zero_to_idx (octave_idx_type z_len) -{ - if (one_zero && (z_len == len || z_len == 0)) - { - if (num_ones == 0) - { - len = 0; - max_val = 0; - min_val = 0; - delete [] data; - data = 0; - } - else - { - assert (num_ones + num_zeros == len); - - octave_idx_type *new_data = new octave_idx_type [num_ones]; - octave_idx_type k = 0; - for (octave_idx_type i = 0; i < len; i++) - if (data[i] == 0) - new_data[k++] = i; - - delete [] data; - len = num_ones; - data = new_data; - - min_val = max_val = data[0]; - - octave_idx_type i = 0; - do - { - if (data[i] > max_val) - max_val = data[i]; - - if (data[i] < min_val) - min_val = data[i]; - } - while (++i < len); - } - } -} - octave_idx_type IDX_VEC_REP::checkelem (octave_idx_type n) const { @@ -505,11 +459,7 @@ } else if (static_cast<octave_idx_type> (len) > 1) { - if (one_zero) - { - colon_equiv = (len == n && ones_count () == n); - } - else if (sort_uniq) + if (sort_uniq) { octave_idx_type *tmp_data = copy_data (data, len);
--- a/liboctave/idx-vector.h +++ b/liboctave/idx-vector.h @@ -51,7 +51,7 @@ : data (0), len (0), num_zeros (0), num_ones (0), range_base (0), range_step (0), max_val (0), min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), - colon (0), range(0), one_zero (0), initialized (0), frozen (0), + colon (0), range(0), initialized (0), frozen (0), colon_equiv_checked (0), colon_equiv (0), orig_dims () { } idx_vector_rep (const ColumnVector& v); @@ -63,7 +63,7 @@ : data (0), len (inda.length ()), num_zeros (0), num_ones (0), range_base (0), range_step (0), max_val (0), min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), colon (0), - range(0), one_zero (0), initialized (0), frozen (0), + range(0), initialized (0), frozen (0), colon_equiv_checked (0), colon_equiv (0), orig_dims (inda.dims ()) { if (len == 0) @@ -97,7 +97,7 @@ : data (0), len (1), num_zeros (0), num_ones (0), range_base (0), range_step (0), max_val (0), min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), colon (0), - range(0), one_zero (0), initialized (0), frozen (0), + range(0), initialized (0), frozen (0), colon_equiv_checked (0), colon_equiv (0), orig_dims (1, 1) { data = new octave_idx_type [len]; @@ -131,7 +131,6 @@ octave_idx_type max (void) const { return max_val; } octave_idx_type min (void) const { return min_val; } - int one_zero_only (void) const { return one_zero; } octave_idx_type zeros_count (void) const { return num_zeros; } octave_idx_type ones_count (void) const { return num_ones; } @@ -171,7 +170,6 @@ unsigned int colon : 1; unsigned int range : 1; - unsigned int one_zero : 1; unsigned int initialized : 1; unsigned int frozen : 1; unsigned int colon_equiv_checked : 1; @@ -181,8 +179,6 @@ void init_state (void); - void maybe_convert_one_zero_to_idx (octave_idx_type z_len); - octave_idx_type tree_to_mat_idx (double x, bool& conversion_error); octave_idx_type tree_to_mat_idx (octave_idx_type i) { return i - 1; } @@ -250,7 +246,7 @@ octave_idx_type max (void) const { return rep->max (); } octave_idx_type min (void) const { return rep->min (); } - int one_zero_only (void) const { return rep->one_zero_only (); } + int one_zero_only (void) const { return 0; } octave_idx_type zeros_count (void) const { return rep->zeros_count (); } octave_idx_type ones_count (void) const { return rep->ones_count (); } @@ -281,9 +277,6 @@ friend std::ostream& operator << (std::ostream& os, const idx_vector& a) { return a.print (os); } - void maybe_convert_one_zero_to_idx (octave_idx_type z_len) - { rep->maybe_convert_one_zero_to_idx (z_len); } - private: idx_vector_rep *rep;