# HG changeset patch # User jwe # Date 1065746995 0 # Node ID 01ee68d180694245a3df0c7babe810a1cbff99f6 # Parent b570d7825fb946d7413727370157c3a7ecb0d135 [project @ 2003-10-10 00:49:54 by jwe] diff -r b570d7825fb9 -r 01ee68d18069 ChangeLog --- a/ChangeLog Tue Oct 07 14:57:39 2003 +0000 +++ b/ChangeLog Fri Oct 10 00:49:55 2003 +0000 @@ -1,3 +1,7 @@ +2003-10-07 John W. Eaton + + * configure.in (AC_PREREQ): Require 2.57. + 2003-09-19 John W. Eaton * configure.in (AH_BOTTOM): Don't define HEAVYWEIGHT_INDEXING here. diff -r b570d7825fb9 -r 01ee68d18069 liboctave/Array.cc --- a/liboctave/Array.cc Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/Array.cc Fri Oct 10 00:49:55 2003 +0000 @@ -52,6 +52,43 @@ delete [] idx; } +template +Array +Array::squeeze (void) const +{ + Array retval = *this; + + bool dims_changed = false; + + dim_vector new_dimensions = dimensions; + + int k = 0; + + for (int i = 0; i < ndims (); i++) + { + if (dimensions(i) == 1) + dims_changed = true; + else + new_dimensions(k++) = dimensions(i); + } + + if (dims_changed) + { + if (k == 0) + new_dimensions = dim_vector (1); + else + new_dimensions.resize (k); + + Array retval = *this; + + retval.make_unique (); + + retval.dimensions = new_dimensions; + } + + return retval; +} + // A guess (should be quite conservative). #define MALLOC_OVERHEAD 1024 @@ -85,13 +122,10 @@ int nt = nr + nc; double dt = dr * dc; - if (dt <= 0.5) + if (dt < 0.5) { nt--; dt *= 2; - - if (dt <= 0.5) - nt--; } return (nt < nl || (nt == nl && dt < dl)) ? r * c : max_items; @@ -128,13 +162,16 @@ int nt = nr + nc + np; double dt = dr * dc * dp; - if (dt <= 0.5) + if (dt < 0.5) { nt--; dt *= 2; - if (dt <= 0.5) - nt--; + if (dt < 0.5) + { + nt--; + dt *= 2; + } } return (nt < nl || (nt == nl && dt < dl)) ? r * c * p : max_items; @@ -178,15 +215,12 @@ nt += nra_idx; dt *= dra_idx; - } - - if (dt <= 0.5) - { - nt--; - dt *= 2; - - if (dt <= 0.5) - nt--; + + if (dt < 0.5) + { + nt--; + dt *= 2; + } } if (nt < nl || (nt == nl && dt < dl)) diff -r b570d7825fb9 -r 01ee68d18069 liboctave/Array.h --- a/liboctave/Array.h Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/Array.h Fri Oct 10 00:49:55 2003 +0000 @@ -246,6 +246,8 @@ dim_vector dims (void) const { return dimensions; } + Array squeeze (void) const; + static int get_size (int r, int c); static int get_size (int r, int c, int p); static int get_size (const dim_vector& dims); diff -r b570d7825fb9 -r 01ee68d18069 liboctave/ArrayN.h --- a/liboctave/ArrayN.h Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/ArrayN.h Fri Oct 10 00:49:55 2003 +0000 @@ -71,6 +71,8 @@ ArrayN (const ArrayN& a) : Array (a, a.dims ()) { } + ArrayN (const Array& a) : Array (a) { } + ArrayN (const Array& a, const dim_vector& dims) : Array (a, dims) { } ~ArrayN (void) { } @@ -89,6 +91,8 @@ void resize (const dim_vector& dims, const T& val) { Array::resize (dims, val); } + ArrayN squeeze (void) const { return Array::squeeze (); } + ArrayN& insert (const ArrayN& a, const dim_vector& dims) { Array::insert (a, dims); diff -r b570d7825fb9 -r 01ee68d18069 liboctave/CNDArray.cc --- a/liboctave/CNDArray.cc Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/CNDArray.cc Fri Oct 10 00:49:55 2003 +0000 @@ -33,6 +33,8 @@ #include "mx-base.h" #include "lo-ieee.h" +#include "ArrayN-inline.h" + // XXX FIXME XXX -- this is not quite the right thing. boolMatrix @@ -96,6 +98,14 @@ return retval; } +void +ComplexNDArray::increment_index (Array& ra_idx, + const dim_vector& dimensions, + int start_dimension) +{ + ::increment_index (ra_idx, dimensions, start_dimension); +} + /* ;;; Local Variables: *** ;;; mode: C++ *** diff -r b570d7825fb9 -r 01ee68d18069 liboctave/CNDArray.h --- a/liboctave/CNDArray.h Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/CNDArray.h Fri Oct 10 00:49:55 2003 +0000 @@ -69,6 +69,12 @@ ComplexMatrix matrix_value (void) const; + ComplexNDArray squeeze (void) const { return ArrayN::squeeze (); } + + static void increment_index (Array& ra_idx, + const dim_vector& dimensions, + int start_dimension = 0); + // i/o // friend std::ostream& operator << (std::ostream& os, const NDArray& a); diff -r b570d7825fb9 -r 01ee68d18069 liboctave/ChangeLog --- a/liboctave/ChangeLog Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/ChangeLog Fri Oct 10 00:49:55 2003 +0000 @@ -1,3 +1,22 @@ +2003-10-09 John W. Eaton + + * CNDArray.cc (ComplexNDArray::increment_index): New function. + * dNDArray.cc (NDArray::increment_index): Likewise. + * boolNDArray.cc (boolNDArray::increment_index): Likewise. + * chNDArray.cc (charNDArray::increment_index): Likewise. + + * dim-vector.h (rows, cols): Delete unused data members. + + * Array.cc (Array::get_size): Fix thinko. + +2003-10-08 John W. Eaton + + * Array.cc (Array::squeeze): New function. + * CNDArray.h (ComplexNDArray::squeeze): Likewise. + * dNDArray.h (NDArray::squeeze): Likewise. + * boolNDArray.h (boolNDArray::squeeze): Likewise. + * chNDArray.h (charNDArray::squeeze): Likewise. + 2003-10-06 Petter Risholm * Array.cc (ArrayN::indexN): New definition. diff -r b570d7825fb9 -r 01ee68d18069 liboctave/boolNDArray.cc --- a/liboctave/boolNDArray.cc Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/boolNDArray.cc Fri Oct 10 00:49:55 2003 +0000 @@ -33,6 +33,8 @@ #include "mx-base.h" #include "lo-ieee.h" +#include "ArrayN-inline.h" + // XXX FIXME XXX -- this is not quite the right thing. boolMatrix @@ -96,6 +98,14 @@ return retval; } +void +boolNDArray::increment_index (Array& ra_idx, + const dim_vector& dimensions, + int start_dimension) +{ + ::increment_index (ra_idx, dimensions, start_dimension); +} + /* ;;; Local Variables: *** ;;; mode: C++ *** diff -r b570d7825fb9 -r 01ee68d18069 liboctave/boolNDArray.h --- a/liboctave/boolNDArray.h Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/boolNDArray.h Fri Oct 10 00:49:55 2003 +0000 @@ -69,6 +69,12 @@ boolMatrix matrix_value (void) const; + boolNDArray squeeze (void) const { return ArrayN::squeeze (); } + + static void increment_index (Array& ra_idx, + const dim_vector& dimensions, + int start_dimension = 0); + // i/o // friend std::ostream& operator << (std::ostream& os, const NDArray& a); diff -r b570d7825fb9 -r 01ee68d18069 liboctave/chNDArray.cc --- a/liboctave/chNDArray.cc Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/chNDArray.cc Fri Oct 10 00:49:55 2003 +0000 @@ -33,6 +33,8 @@ #include "mx-base.h" #include "lo-ieee.h" +#include "ArrayN-inline.h" + // XXX FIXME XXX -- this is not quite the right thing. boolMatrix @@ -96,6 +98,14 @@ return retval; } +void +charNDArray::increment_index (Array& ra_idx, + const dim_vector& dimensions, + int start_dimension) +{ + ::increment_index (ra_idx, dimensions, start_dimension); +} + /* ;;; Local Variables: *** ;;; mode: C++ *** diff -r b570d7825fb9 -r 01ee68d18069 liboctave/chNDArray.h --- a/liboctave/chNDArray.h Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/chNDArray.h Fri Oct 10 00:49:55 2003 +0000 @@ -74,6 +74,12 @@ charMatrix matrix_value (void) const; + charNDArray squeeze (void) const { return ArrayN::squeeze (); } + + static void increment_index (Array& ra_idx, + const dim_vector& dimensions, + int start_dimension = 0); + // i/o // friend std::ostream& operator << (std::ostream& os, const charNDArray& a); diff -r b570d7825fb9 -r 01ee68d18069 liboctave/dNDArray.cc --- a/liboctave/dNDArray.cc Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/dNDArray.cc Fri Oct 10 00:49:55 2003 +0000 @@ -34,6 +34,8 @@ #include "lo-error.h" #include "lo-ieee.h" +#include "ArrayN-inline.h" + // XXX FIXME XXX -- this is not quite the right thing. boolMatrix @@ -70,6 +72,40 @@ return retval; } +Matrix +NDArray::matrix_value (void) const +{ + Matrix retval; + + int nd = ndims (); + + switch (nd) + { + case 1: + retval = Matrix (Array2 (*this, dimensions(0), 1)); + break; + + case 2: + retval = Matrix (Array2 (*this, dimensions(0), dimensions(1))); + break; + + default: + (*current_liboctave_error_handler) + ("invalid converstion of NDArray to Matrix"); + break; + } + + return retval; +} + +void +NDArray::increment_index (Array& ra_idx, + const dim_vector& dimensions, + int start_dimension) +{ + ::increment_index (ra_idx, dimensions, start_dimension); +} + bool NDArray::any_element_is_negative (bool neg_zero) const { @@ -120,32 +156,6 @@ return true; } -Matrix -NDArray::matrix_value (void) const -{ - Matrix retval; - - int nd = ndims (); - - switch (nd) - { - case 1: - retval = Matrix (Array2 (*this, dimensions(0), 1)); - break; - - case 2: - retval = Matrix (Array2 (*this, dimensions(0), dimensions(1))); - break; - - default: - (*current_liboctave_error_handler) - ("invalid converstion of NDArray to Matrix"); - break; - } - - return retval; -} - /* ;;; Local Variables: *** ;;; mode: C++ *** diff -r b570d7825fb9 -r 01ee68d18069 liboctave/dNDArray.h --- a/liboctave/dNDArray.h Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/dNDArray.h Fri Oct 10 00:49:55 2003 +0000 @@ -68,6 +68,12 @@ Matrix matrix_value (void) const; + NDArray squeeze (void) const { return ArrayN::squeeze (); } + + static void increment_index (Array& ra_idx, + const dim_vector& dimensions, + int start_dimension = 0); + // i/o // friend std::ostream& operator << (std::ostream& os, const NDArray& a); diff -r b570d7825fb9 -r 01ee68d18069 liboctave/dim-vector.h --- a/liboctave/dim-vector.h Tue Oct 07 14:57:39 2003 +0000 +++ b/liboctave/dim-vector.h Fri Oct 10 00:49:55 2003 +0000 @@ -118,8 +118,6 @@ private: - int rows; - int cols; int ndims; int *dims; }; diff -r b570d7825fb9 -r 01ee68d18069 src/ChangeLog --- a/src/ChangeLog Tue Oct 07 14:57:39 2003 +0000 +++ b/src/ChangeLog Fri Oct 10 00:49:55 2003 +0000 @@ -1,3 +1,19 @@ +2003-10-09 John W. Eaton + + * pr-output.cc (PRINT_ND_ARRAY): New macro. + (octave_print_internal): Use it. + +2003-10-08 John W. Eaton + + * ov.cc (octave_value::octave_value (const ArrayN&, + bool)): New constructor. + * ov.h: Provide decl. + + * ov.h (octave_value::squeeze): New virtual function. + * ov-base.cc (squeeze): Provide default implementation. + * ov-base-mat.h (octave_base_matrix::squeeze): New function. + * data.cc (Fsqueeze): New function. + 2003-10-03 John W. Eaton * load-save.cc (make_valid_identifier): Return new string. diff -r b570d7825fb9 -r 01ee68d18069 src/OPERATORS/op-m-m.cc --- a/src/OPERATORS/op-m-m.cc Tue Oct 07 14:57:39 2003 +0000 +++ b/src/OPERATORS/op-m-m.cc Fri Oct 10 00:49:55 2003 +0000 @@ -88,6 +88,20 @@ DEFBINOP_FN (el_and, matrix, matrix, mx_el_and) DEFBINOP_FN (el_or, matrix, matrix, mx_el_or) +#if 0 +static octave_value +oct_assignop_assign (octave_value& a1, + const octave_value_list& idx, + const octave_value& a2) +{ + CAST_BINOP_ARGS (octave_matrix&, const octave_matrix&); + + v1.assign (idx, v2.double_nd_array_value ()); + + return octave_value (); +} +#endif + DEFASSIGNOP_FN (assign, matrix, matrix, assign) void diff -r b570d7825fb9 -r 01ee68d18069 src/data.cc --- a/src/data.cc Tue Oct 07 14:57:39 2003 +0000 +++ b/src/data.cc Fri Oct 10 00:49:55 2003 +0000 @@ -1184,6 +1184,22 @@ return retval; } +DEFUN (squeeze, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} squeeze (@var{x})\n\ +Remove singleton dimensions from @var{x} and return the result.\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 1) + return args(0).squeeze (); + else + print_usage ("squeeze"); + + return retval; +} + void symbols_of_data (void) { diff -r b570d7825fb9 -r 01ee68d18069 src/ov-base-mat.h --- a/src/ov-base-mat.h Tue Oct 07 14:57:39 2003 +0000 +++ b/src/ov-base-mat.h Fri Oct 10 00:49:55 2003 +0000 @@ -66,6 +66,8 @@ octave_value *clone (void) const { return new octave_base_matrix (*this); } octave_value *empty_clone (void) const { return new octave_base_matrix (); } + octave_value squeeze (void) const { return matrix.squeeze (); } + octave_value subsref (const std::string& type, const std::list& idx); diff -r b570d7825fb9 -r 01ee68d18069 src/ov-base.cc --- a/src/ov-base.cc Tue Oct 07 14:57:39 2003 +0000 +++ b/src/ov-base.cc Fri Oct 10 00:49:55 2003 +0000 @@ -56,6 +56,14 @@ DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_base_value, ""); octave_value +octave_base_value::squeeze (void) const +{ + std::string nm = type_name (); + error ("squeeze: invalid operation for %s type", nm.c_str ()); + return octave_value (); +} + +octave_value octave_base_value::subsref (const std::string&, const std::list&) { diff -r b570d7825fb9 -r 01ee68d18069 src/ov-base.h --- a/src/ov-base.h Tue Oct 07 14:57:39 2003 +0000 +++ b/src/ov-base.h Fri Oct 10 00:49:55 2003 +0000 @@ -68,6 +68,8 @@ type_conv_fcn numeric_conversion_function (void) const { return static_cast (0); } + octave_value squeeze (void) const; + octave_value *try_narrowing_conversion (void) { return static_cast (0); } diff -r b570d7825fb9 -r 01ee68d18069 src/ov.cc --- a/src/ov.cc Tue Oct 07 14:57:39 2003 +0000 +++ b/src/ov.cc Fri Oct 10 00:49:55 2003 +0000 @@ -410,6 +410,19 @@ rep->count = 1; } +octave_value::octave_value (const ArrayN& a, bool is_cs_list) + : rep (0) +{ + Cell c (a); + + if (is_cs_list) + rep = new octave_cs_list (c); + else + rep = new octave_cell (c); + + rep->count = 1; +} + octave_value::octave_value (const Matrix& m) : rep (new octave_matrix (m)) { diff -r b570d7825fb9 -r 01ee68d18069 src/ov.h --- a/src/ov.h Tue Oct 07 14:57:39 2003 +0000 +++ b/src/ov.h Fri Oct 10 00:49:55 2003 +0000 @@ -182,7 +182,8 @@ octave_value (octave_time t); octave_value (double d); - octave_value (const Cell& m, bool is_cs_list = false); + octave_value (const ArrayN& a, bool is_cs_list = false); + octave_value (const Cell& c, bool is_cs_list = false); octave_value (const Matrix& m); octave_value (const NDArray& nda); octave_value (const DiagMatrix& d); @@ -269,6 +270,9 @@ void maybe_mutate (void); + virtual octave_value squeeze (void) const + { return rep->squeeze (); } + virtual octave_value *try_narrowing_conversion (void) { return rep->try_narrowing_conversion (); } diff -r b570d7825fb9 -r 01ee68d18069 src/pr-output.cc --- a/src/pr-output.cc Tue Oct 07 14:57:39 2003 +0000 +++ b/src/pr-output.cc Fri Oct 10 00:49:55 2003 +0000 @@ -1485,6 +1485,69 @@ } } +#define PRINT_ND_ARRAY(os, nda, NDA_T, ELT_T, MAT_T) \ + do \ + { \ + int ndims = nda.ndims (); \ + \ + dim_vector dims = nda.dims (); \ + \ + Array ra_idx (ndims, 0); \ + \ + int m = 1; \ + \ + for (int i = 2; i < ndims; i++) \ + m *= dims(i); \ + \ + int nr = dims(0); \ + int nc = dims(1); \ + \ + for (int i = 0; i < m; i++) \ + { \ + std::string nm = "ans"; \ + \ + if (m > 1) \ + { \ + nm += "(:,:,"; \ + \ + OSSTREAM buf; \ + \ + for (int k = 2; k < ndims; k++) \ + { \ + buf << ra_idx(k) + 1; \ + \ + if (k < ndims - 1) \ + buf << ","; \ + else \ + buf << ")"; \ + } \ + \ + buf << OSSTREAM_ENDS; \ + \ + nm += OSSTREAM_STR (buf); \ + \ + OSSTREAM_FREEZE (buf); \ + } \ + \ + Array idx (ndims); \ + \ + idx(0) = idx_vector (':'); \ + idx(1) = idx_vector (':'); \ + \ + for (int k = 2; k < ndims; k++) \ + idx(k) = idx_vector (ra_idx(k) + 1); \ + \ + octave_value page \ + = MAT_T (Array2 (nda.index (idx), nr, nc)); \ + \ + page.print_with_name (os, nm); \ + \ + if (i < m) \ + NDA_T::increment_index (ra_idx, dims, 2); \ + } \ + } \ + while (0) + void octave_print_internal (std::ostream& os, const NDArray& nda, bool pr_as_read_syntax, int extra_indent) @@ -1498,7 +1561,7 @@ break; default: - os << nda; + PRINT_ND_ARRAY (os, nda, NDArray, double, Matrix); break; } } @@ -1691,7 +1754,7 @@ break; default: - os << nda; + PRINT_ND_ARRAY (os, nda, ComplexNDArray, Complex, ComplexMatrix); break; } } @@ -1826,7 +1889,7 @@ break; default: - os << nda; + PRINT_ND_ARRAY (os, nda, boolNDArray, bool, boolMatrix); break; } } @@ -1892,7 +1955,7 @@ break; default: - os << nda; + PRINT_ND_ARRAY (os, nda, charNDArray, char, charMatrix); break; } }