# HG changeset patch # User jwe # Date 1063129753 0 # Node ID f6a61399bc5c31c093b3fb208c843f5c667a389c # Parent 55db663c15ced9f451f98176d4a8f66f71e21996 [project @ 2003-09-09 17:48:00 by jwe] diff -r 55db663c15ce -r f6a61399bc5c doc/interpreter/var.txi --- a/doc/interpreter/var.txi Tue Sep 09 01:54:26 2003 +0000 +++ b/doc/interpreter/var.txi Tue Sep 09 17:49:13 2003 +0000 @@ -75,11 +75,25 @@ @example @group global a -global b = 2 -global c = 3, d, e = 5 +global a b +global c = 2 +global d = 3 e f = 5 @end group @end example +A global variable may only be initialized once in a @code{global} +statement. For example, after executing the following code + +@example +@group +global gvar = 1 +global gvar = 2 +@end group +@end example + +@noindent +the value of the global variable @code{gvar} is 1, not 2. + It is necessary declare a variable as global within a function body in order to access it. For example, diff -r 55db663c15ce -r f6a61399bc5c liboctave/ArrayN-idx.h --- a/liboctave/ArrayN-idx.h Tue Sep 09 01:54:26 2003 +0000 +++ b/liboctave/ArrayN-idx.h Tue Sep 09 17:49:13 2003 +0000 @@ -286,6 +286,46 @@ } static inline bool +vector_equivalent (const Array& ra_idx) +{ + int n = ra_idx.length (); + + bool found_first = false; + + for (int i = 0; i < n; i++) + { + if (ra_idx(i) != 1) + { + if (! found_first) + found_first = true; + else + return false; + } + } + + return true; +} + +static inline bool +equal_arrays (const Array a, const Array b) +{ + bool retval = true; + + if (a.length () != b.length ()) + retval = false; + else + { + for (int i = 0; i < a.length (); i++) + { + if (a(i) != b(i)) + retval = false; + } + } + + return retval; +} + +static inline bool all_ok (const Array& ra_idx) { bool retval = true; @@ -426,7 +466,7 @@ Array retval (n); for (int i = 0; i < n; i++) - retval(i) = ra_idx(result_idx(i)); + retval(i) = ra_idx(i).elem (result_idx(i)); return retval; } diff -r 55db663c15ce -r f6a61399bc5c liboctave/ArrayN-inline.h --- a/liboctave/ArrayN-inline.h Tue Sep 09 01:54:26 2003 +0000 +++ b/liboctave/ArrayN-inline.h Tue Sep 09 17:49:13 2003 +0000 @@ -32,7 +32,7 @@ { for (int i = 0; i < n; i++) { - if (ra_idx(i) < 0 || ra_idx(i) >= dimensions (i)) + if (ra_idx(i) < 0 || ra_idx(i) > dimensions (i)) { retval = false; break; diff -r 55db663c15ce -r f6a61399bc5c liboctave/ArrayN.cc --- a/liboctave/ArrayN.cc Tue Sep 09 01:54:26 2003 +0000 +++ b/liboctave/ArrayN.cc Tue Sep 09 17:49:13 2003 +0000 @@ -310,6 +310,34 @@ } template +void +ArrayN::maybe_delete_dims (void) +{ + int ndims = dimensions.length (); + Array new_dims (1,1); + bool delete_dims = true; + + for (int i = ndims - 1; i >= 0; i--) + { + if (delete_dims) + { + if (dimensions(i) != 1) + { + delete_dims = false; + new_dims = Array (i + 1, dimensions(i)); + } + } + else + { + new_dims(i) = dimensions(i); + } + } + + if (ndims != new_dims.length ()) + dimensions = new_dims; +} + +template std::ostream& operator << (std::ostream& os, const ArrayN& a) { diff -r 55db663c15ce -r f6a61399bc5c liboctave/ArrayN.h --- a/liboctave/ArrayN.h Tue Sep 09 01:54:26 2003 +0000 +++ b/liboctave/ArrayN.h Tue Sep 09 17:49:13 2003 +0000 @@ -36,6 +36,7 @@ #include #include "Array.h" +#include "dMatrix.h" #include "lo-error.h" class idx_vector; @@ -92,6 +93,22 @@ set_max_indices (dimensions.length ()); } + // New constructor which takes a Matrix as an argument. This should + // be moved to a subclass of ArrayN (NDArray) once we add a double + // instantiation of ArrayN. + + ArrayN (const Matrix& m) : Array (m) + { + set_max_indices (2); + + Array dim (2); + + dim(0) = m.dim1 (); + dim(1) = m.dim2 (); + + dimensions = dim; + } + ~ArrayN (void) { } ArrayN& operator = (const ArrayN& a) @@ -185,7 +202,8 @@ ArrayN index (Array& ra_idx, int resize_ok = 0, const T& rfv = resize_fill_value (T ())) const; - + + void maybe_delete_dims (void); #endif }; diff -r 55db663c15ce -r f6a61399bc5c liboctave/ChangeLog --- a/liboctave/ChangeLog Tue Sep 09 01:54:26 2003 +0000 +++ b/liboctave/ChangeLog Tue Sep 09 17:49:13 2003 +0000 @@ -1,3 +1,20 @@ +2003-09-09 Petter Risholm + + * ArrayN-idx.h (vector_equivalent, equal_arrays): New functions. + (get_elt_idx): Index ra_idx correctly. + + * ArrayN-inline.h (index_in_bounds): Index is also condidered in + bounds if it is exactly on the bound. + + * ArrayN.cc (ArrayN::maybe_delete_dims): New function. + * ArrayN.h: Provide decl. + + * ArrayN.h (ArrayN::ArrayN (const Matrix&)): New constructor. + + * idx-vector.h (idx_vector::orig_dims): New member variable. + (idx_vector::idx_vector_rep::orig_dimensions): New function. + (idx_vector::orig_dimensions): New function. + 2003-09-04 John W. Eaton * lo-specfun.cc (xlgamma): Require nonnegative argument. diff -r 55db663c15ce -r f6a61399bc5c liboctave/idx-vector.h --- a/liboctave/idx-vector.h Tue Sep 09 01:54:26 2003 +0000 +++ b/liboctave/idx-vector.h Tue Sep 09 17:49:13 2003 +0000 @@ -29,6 +29,8 @@ #include +#include "Array.h" + class ColumnVector; class boolMatrix; class Matrix; @@ -107,6 +109,8 @@ int orig_rows (void) const { return orig_nr; } int orig_columns (void) const { return orig_nc; } + Array orig_dimensions (void) const { return orig_dims; } + // other stuff void shorten (int n); // Unsafe. Avoid at all cost. @@ -123,8 +127,16 @@ int num_ones; 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; @@ -246,6 +258,8 @@ 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 (); } + int orig_empty (void) const { return (! is_colon () diff -r 55db663c15ce -r f6a61399bc5c test/octave.test/string/dec2bin-3.m --- a/test/octave.test/string/dec2bin-3.m Tue Sep 09 01:54:26 2003 +0000 +++ b/test/octave.test/string/dec2bin-3.m Tue Sep 09 17:49:13 2003 +0000 @@ -1,1 +1,2 @@ -dec2bin (1, 2) +strcmp (dec2bin (14, 6), "001110") + diff -r 55db663c15ce -r f6a61399bc5c test/octave.test/string/dec2bin-4.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/octave.test/string/dec2bin-4.m Tue Sep 09 17:49:13 2003 +0000 @@ -0,0 +1,1 @@ +dec2bin (1, 2, 3) diff -r 55db663c15ce -r f6a61399bc5c test/octave.test/string/dec2hex-3.m --- a/test/octave.test/string/dec2hex-3.m Tue Sep 09 01:54:26 2003 +0000 +++ b/test/octave.test/string/dec2hex-3.m Tue Sep 09 17:49:13 2003 +0000 @@ -1,1 +1,1 @@ -dec2hex (1, 2) +strcmp (tolower (dec2hex (2748, 5)), "00abc") diff -r 55db663c15ce -r f6a61399bc5c test/octave.test/string/dec2hex-4.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/octave.test/string/dec2hex-4.m Tue Sep 09 17:49:13 2003 +0000 @@ -0,0 +1,1 @@ +dec2hex (1, 2, 3) diff -r 55db663c15ce -r f6a61399bc5c test/octave.test/string/string.exp --- a/test/octave.test/string/string.exp Tue Sep 09 01:54:26 2003 +0000 +++ b/test/octave.test/string/string.exp Tue Sep 09 17:49:13 2003 +0000 @@ -295,8 +295,12 @@ do_test dec2bin-2.m set test dec2bin-3 +set prog_output "^ans = 1" +do_test dec2bin-3.m + +set test dec2bin-4 set prog_output "^usage:.*" -do_test dec2bin-3.m +do_test dec2bin-4.m set test dec2hex-1 set prog_output "^ans = 1" @@ -307,8 +311,12 @@ do_test dec2hex-2.m set test dec2hex-3 +set prog_output "^ans = 1" +do_test dec2hex-3.m + +set test dec2hex-4 set prog_output "^usage:.*" -do_test dec2hex-3.m +do_test dec2hex-4.m set test hex2dec-1 set prog_output "^ans = 1"