# HG changeset patch # User jwe # Date 1069650166 0 # Node ID 14ab7b05a572a4f5fff3c1a77dc0fc3b5b018684 # Parent 361fe3e50f7af92287e9942c287dc55601d0027c [project @ 2003-11-24 05:02:46 by jwe] diff -r 361fe3e50f7a -r 14ab7b05a572 liboctave/Array.cc --- a/liboctave/Array.cc Mon Nov 24 03:12:17 2003 +0000 +++ b/liboctave/Array.cc Mon Nov 24 05:02:46 2003 +0000 @@ -1792,14 +1792,7 @@ int orig_len = number_of_elements (dims ()); - Array idx_orig_dimsXXX = ra_idx.orig_dimensions (); - - dim_vector idx_orig_dims; - - idx_orig_dims.resize (idx_orig_dimsXXX.length ()); - - for (int i = 0; i < idx_orig_dimsXXX.length (); i++) - idx_orig_dims(i) = idx_orig_dimsXXX(i); + dim_vector idx_orig_dims = ra_idx.orig_dimensions (); if (ra_idx.is_colon ()) { diff -r 361fe3e50f7a -r 14ab7b05a572 liboctave/ChangeLog --- a/liboctave/ChangeLog Mon Nov 24 03:12:17 2003 +0000 +++ b/liboctave/ChangeLog Mon Nov 24 05:02:46 2003 +0000 @@ -1,5 +1,16 @@ 2003-11-23 John W. Eaton + * idx-vector.h (idx_vector::orig_empty): Check orig_dims for + zeros, not orig_rows or orig_columns. + (idx_vector::idx_vector_rep::orig_rows): Define using orig_dims. + (idx_vector::idx_vector_rep::orig_columns): Likewise. + + * idx-vector.cc (idx_vector::idx_vector_rep::orig_nr, + (idx_vector::idx_vector_rep::orig_nc): Delete. + + * idx-vector.cc (idx_vector::idx_vector_rep): + Use initialization lists for constructors. + * Array.cc (Array::indexN): Correctly handle single colon index. Omit special case for ra_idx.capacity () == 1. Always allow single index for matrix args with optional warning. diff -r 361fe3e50f7a -r 14ab7b05a572 liboctave/idx-vector.cc --- a/liboctave/idx-vector.cc Mon Nov 24 03:12:17 2003 +0000 +++ b/liboctave/idx-vector.cc Mon Nov 24 05:02:46 2003 +0000 @@ -44,31 +44,18 @@ #define IDX_VEC_REP idx_vector::idx_vector_rep IDX_VEC_REP::idx_vector_rep (const IDX_VEC_REP& a) + : data (0), len (a.len), num_zeros (a.num_zeros), num_ones (a.num_ones), + 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), one_zero (a.one_zero), initialized (a.initialized), + frozen (a.frozen), colon_equiv_checked (a.colon_equiv_checked), + colon_equiv (a.colon_equiv), orig_dims (a.orig_dims) { - data = 0; - initialized = a.initialized; - frozen = a.frozen; - colon_equiv_checked = a.colon_equiv_checked; - colon_equiv = a.colon_equiv; - - colon = a.colon; - - orig_nr = a.orig_nr; - orig_nc = a.orig_nc; - - len = a.len; if (len > 0) { data = new int [len]; for (int i = 0; i < len; i++) data[i] = a.data[i]; - - num_zeros = a.num_zeros; - num_ones = a.num_ones; - one_zero = a.one_zero; - - max_val = a.max_val; - min_val = a.min_val; } } @@ -106,26 +93,13 @@ } IDX_VEC_REP::idx_vector_rep (const ColumnVector& v) + : data (0), len (v.length ()), num_zeros (0), num_ones (0), max_val (0), + min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), + colon (0), one_zero (0), initialized (0), frozen (0), + colon_equiv_checked (0), colon_equiv (0), orig_dims (len, 1) { - data = 0; - initialized = 0; - frozen = 0; - colon_equiv_checked = 0; - colon_equiv = 0; - colon = 0; - one_zero = 0; - - len = v.length (); - - orig_nr = len; - orig_nc = 1; - if (len == 0) { - num_zeros = 0; - num_ones = 0; - max_val = 0; - min_val = 0; initialized = 1; return; } @@ -148,26 +122,14 @@ } IDX_VEC_REP::idx_vector_rep (const NDArray& nda) + : data (0), len (nda.length ()), num_zeros (0), num_ones (0), + max_val (0), min_val (0), count (1), frozen_at_z_len (0), + frozen_len (0), colon (0), one_zero (0), initialized (0), + frozen (0), colon_equiv_checked (0), colon_equiv (0), + orig_dims (nda.dims ()) { - data = 0; - initialized = 0; - frozen = 0; - colon_equiv_checked = 0; - colon_equiv = 0; - colon = 0; - one_zero = 0; - - orig_nr = nda.rows (); - orig_nc = nda.cols (); - - len = nda.length (); - if (len == 0) { - num_zeros = 0; - num_ones = 0; - max_val = 0; - min_val = 0; initialized = 1; return; } @@ -191,20 +153,12 @@ } IDX_VEC_REP::idx_vector_rep (const Range& r) + : data (0), len (r.nelem ()), num_zeros (0), num_ones (0), + max_val (0), min_val (0), count (1), frozen_at_z_len (0), + frozen_len (0), colon (0), one_zero (0), initialized (0), + frozen (0), colon_equiv_checked (0), colon_equiv (0), + orig_dims (1, len) { - data = 0; - initialized = 0; - frozen = 0; - colon_equiv_checked = 0; - colon_equiv = 0; - colon = 0; - one_zero = 0; - - len = r.nelem (); - - orig_nr = 1; - orig_nc = len; - if (len < 0) { (*current_liboctave_error_handler) ("invalid range used as index"); @@ -212,10 +166,6 @@ } else if (len == 0) { - num_zeros = 0; - num_ones = 0; - max_val = 0; - min_val = 0; initialized = 1; return; } @@ -239,20 +189,12 @@ } IDX_VEC_REP::idx_vector_rep (double d) + : data (0), len (1), num_zeros (0), num_ones (0), + max_val (0), min_val (0), count (1), frozen_at_z_len (0), + frozen_len (0), colon (0), one_zero (0), initialized (0), + frozen (0), colon_equiv_checked (0), colon_equiv (0), + orig_dims (1, 1) { - data = 0; - initialized = 0; - frozen = 0; - colon_equiv_checked = 0; - colon_equiv = 0; - colon = 0; - one_zero = 0; - - len = 1; - - orig_nr = 1; - orig_nc = 1; - if (idx_is_inf_or_nan (d)) return; else @@ -266,20 +208,12 @@ } IDX_VEC_REP::idx_vector_rep (int i) + : data (0), len (1), num_zeros (0), num_ones (0), + max_val (0), min_val (0), count (1), frozen_at_z_len (0), + frozen_len (0), colon (0), one_zero (0), initialized (0), + frozen (0), colon_equiv_checked (0), colon_equiv (0), + orig_dims (1, 1) { - data = 0; - initialized = 0; - frozen = 0; - colon_equiv_checked = 0; - colon_equiv = 0; - colon = 0; - one_zero = 0; - - len = 1; - - orig_nr = 1; - orig_nc = 1; - data = new int [len]; data[0] = tree_to_mat_idx (i); @@ -288,38 +222,24 @@ } IDX_VEC_REP::idx_vector_rep (char c) + : data (0), len (0), num_zeros (0), num_ones (0), + max_val (0), min_val (0), count (1), frozen_at_z_len (0), + frozen_len (0), colon (1), one_zero (0), initialized (0), + frozen (0), colon_equiv_checked (0), colon_equiv (0), + orig_dims (0, 0) { assert (c == ':'); - colon = 1; - len = 0; - num_zeros = 0; - num_ones = 0; - one_zero = 0; - initialized = 0; - frozen = 0; - colon_equiv_checked = 0; - colon_equiv = 0; - data = 0; - init_state (); } IDX_VEC_REP::idx_vector_rep (bool b) + : data (0), len (1), num_zeros (0), num_ones (0), + max_val (0), min_val (0), count (1), frozen_at_z_len (0), + frozen_len (0), colon (0), one_zero (1), initialized (0), + frozen (0), colon_equiv_checked (0), colon_equiv (0), + orig_dims (1, 1) { - data = 0; - initialized = 0; - frozen = 0; - colon_equiv_checked = 0; - colon_equiv = 0; - colon = 0; - one_zero = 1; - - len = 1; - - orig_nr = 1; - orig_nc = 1; - data = new int [len]; data[0] = tree_to_mat_idx (b); @@ -328,27 +248,14 @@ } IDX_VEC_REP::idx_vector_rep (const boolNDArray& bnda) + : data (0), len (bnda.length ()), num_zeros (0), num_ones (0), + max_val (0), min_val (0), count (1), frozen_at_z_len (0), + frozen_len (0), colon (0), one_zero (1), initialized (0), + frozen (0), colon_equiv_checked (0), colon_equiv (0), + orig_dims (bnda.dims ()) { - data = 0; - initialized = 0; - frozen = 0; - colon_equiv_checked = 0; - colon_equiv = 0; - colon = 0; - one_zero = 1; - - orig_nr = bnda.rows (); - orig_nc = bnda.cols (); - - len = bnda.length (); - if (len == 0) { - num_zeros = 0; - num_ones = 0; - one_zero = 0; - max_val = 0; - min_val = 0; initialized = 1; return; } @@ -369,16 +276,6 @@ { if (this != &a) { - initialized = a.initialized; - frozen = a.frozen; - colon_equiv_checked = a.colon_equiv_checked; - colon_equiv = a.colon_equiv; - - colon = a.colon; - - orig_nr = a.orig_nr; - orig_nc = a.orig_nc; - delete [] data; len = a.len; data = new int [len]; @@ -387,11 +284,19 @@ num_zeros = a.num_zeros; num_ones = a.num_ones; - one_zero = a.one_zero; - 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; + one_zero = a.one_zero; + initialized = a.initialized; + frozen = a.frozen; + colon_equiv_checked = a.colon_equiv_checked; + colon_equiv = a.colon_equiv; + orig_dims = a.orig_dims; } + return *this; } diff -r 361fe3e50f7a -r 14ab7b05a572 liboctave/idx-vector.h --- a/liboctave/idx-vector.h Mon Nov 24 03:12:17 2003 +0000 +++ b/liboctave/idx-vector.h Mon Nov 24 05:02:46 2003 +0000 @@ -29,7 +29,7 @@ #include -#include "Array.h" +#include "dim-vector.h" class ColumnVector; class boolNDArray; @@ -47,20 +47,10 @@ public: idx_vector_rep (void) - { - colon = 0; - len = 0; - num_zeros = 0; - num_ones = 0; - one_zero = 0; - orig_nr = 0; - orig_nc = 0; - initialized = 0; - frozen = 0; - colon_equiv_checked = 0; - colon_equiv = 0; - data = 0; - } + : data (0), len (0), num_zeros (0), num_ones (0), max_val (0), + min_val (0), count (1), frozen_at_z_len (0), frozen_len (0), + colon (0), one_zero (0), initialized (0), frozen (0), + colon_equiv_checked (0), colon_equiv (0), orig_dims () { } idx_vector_rep (const ColumnVector& v); @@ -106,10 +96,10 @@ void sort (bool uniq); - int orig_rows (void) const { return orig_nr; } - int orig_columns (void) const { return orig_nc; } + int orig_rows (void) const { return orig_dims(0); } + int orig_columns (void) const { return orig_dims(1); } - Array orig_dimensions (void) const { return orig_dims; } + dim_vector orig_dimensions (void) const { return orig_dims; } // other stuff @@ -128,18 +118,10 @@ int max_val; int min_val; - // XXX FIXME XXX -- with the introduction of orig_dims, these two - // variables are not neccessary. orig_dims(0) and orig_dims(1) - // should replace them in the code. - - int orig_nr; - int orig_nc; - - Array orig_dims; - int count; int frozen_at_z_len; int frozen_len; + unsigned int colon : 1; unsigned int one_zero : 1; unsigned int initialized : 1; @@ -147,6 +129,8 @@ unsigned int colon_equiv_checked : 1; unsigned int colon_equiv : 1; + dim_vector orig_dims; + void init_state (void); void maybe_convert_one_zero_to_idx (int z_len); @@ -258,18 +242,15 @@ int orig_rows (void) const { return rep->orig_rows (); } int orig_columns (void) const { return rep->orig_columns (); } - Array orig_dimensions (void) const { return rep->orig_dimensions (); } + dim_vector orig_dimensions (void) const { return rep->orig_dimensions (); } int orig_empty (void) const - { - return (! is_colon () - && (orig_rows () == 0 || orig_columns () == 0)); - } + { return (! is_colon () && orig_dimensions().any_zero ()); } -// Unsafe. Avoid at all cost. + // Unsafe. Avoid at all cost. void shorten (int n) { rep->shorten (n); } -// i/o + // i/o int freeze (int z_len, const char *tag, bool resize_ok = false, bool warn_resize = false)