Mercurial > hg > octave-lojdl
changeset 4504:f6a61399bc5c
[project @ 2003-09-09 17:48:00 by jwe]
author | jwe |
---|---|
date | Tue, 09 Sep 2003 17:49:13 +0000 |
parents | 55db663c15ce |
children | e944fbe3fff2 |
files | doc/interpreter/var.txi liboctave/ArrayN-idx.h liboctave/ArrayN-inline.h liboctave/ArrayN.cc liboctave/ArrayN.h liboctave/ChangeLog liboctave/idx-vector.h test/octave.test/string/dec2bin-3.m test/octave.test/string/dec2bin-4.m test/octave.test/string/dec2hex-3.m test/octave.test/string/dec2hex-4.m test/octave.test/string/string.exp |
diffstat | 12 files changed, 151 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/interpreter/var.txi +++ b/doc/interpreter/var.txi @@ -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,
--- a/liboctave/ArrayN-idx.h +++ b/liboctave/ArrayN-idx.h @@ -286,6 +286,46 @@ } static inline bool +vector_equivalent (const Array<int>& 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<int> a, const Array<int> 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<idx_vector>& ra_idx) { bool retval = true; @@ -426,7 +466,7 @@ Array<int> 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; }
--- a/liboctave/ArrayN-inline.h +++ b/liboctave/ArrayN-inline.h @@ -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;
--- a/liboctave/ArrayN.cc +++ b/liboctave/ArrayN.cc @@ -310,6 +310,34 @@ } template <class T> +void +ArrayN<T>::maybe_delete_dims (void) +{ + int ndims = dimensions.length (); + Array<int> 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<int> (i + 1, dimensions(i)); + } + } + else + { + new_dims(i) = dimensions(i); + } + } + + if (ndims != new_dims.length ()) + dimensions = new_dims; +} + +template <class T> std::ostream& operator << (std::ostream& os, const ArrayN<T>& a) {
--- a/liboctave/ArrayN.h +++ b/liboctave/ArrayN.h @@ -36,6 +36,7 @@ #include <cstdlib> #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<T> (m) + { + set_max_indices (2); + + Array<int> dim (2); + + dim(0) = m.dim1 (); + dim(1) = m.dim2 (); + + dimensions = dim; + } + ~ArrayN (void) { } ArrayN<T>& operator = (const ArrayN<T>& a) @@ -185,7 +202,8 @@ ArrayN<T> index (Array<idx_vector>& ra_idx, int resize_ok = 0, const T& rfv = resize_fill_value (T ())) const; - + + void maybe_delete_dims (void); #endif };
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,20 @@ +2003-09-09 Petter Risholm <risholm@stud.ntnu.no> + + * 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<T>::maybe_delete_dims): New function. + * ArrayN.h: Provide decl. + + * ArrayN.h (ArrayN<T>::ArrayN<T> (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 <jwe@bevo.che.wisc.edu> * lo-specfun.cc (xlgamma): Require nonnegative argument.
--- a/liboctave/idx-vector.h +++ b/liboctave/idx-vector.h @@ -29,6 +29,8 @@ #include <iostream> +#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<int> 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<int> 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<int> orig_dimensions (void) const { return rep->orig_dimensions (); } + int orig_empty (void) const { return (! is_colon ()
--- a/test/octave.test/string/dec2bin-3.m +++ b/test/octave.test/string/dec2bin-3.m @@ -1,1 +1,2 @@ -dec2bin (1, 2) +strcmp (dec2bin (14, 6), "001110") +
new file mode 100644 --- /dev/null +++ b/test/octave.test/string/dec2bin-4.m @@ -0,0 +1,1 @@ +dec2bin (1, 2, 3)
--- a/test/octave.test/string/dec2hex-3.m +++ b/test/octave.test/string/dec2hex-3.m @@ -1,1 +1,1 @@ -dec2hex (1, 2) +strcmp (tolower (dec2hex (2748, 5)), "00abc")
new file mode 100644 --- /dev/null +++ b/test/octave.test/string/dec2hex-4.m @@ -0,0 +1,1 @@ +dec2hex (1, 2, 3)
--- a/test/octave.test/string/string.exp +++ b/test/octave.test/string/string.exp @@ -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"