Mercurial > hg > octave-nkf
changeset 4946:48a39e2b2ab7
[project @ 2004-08-31 17:27:04 by jwe]
author | jwe |
---|---|
date | Tue, 31 Aug 2004 17:27:05 +0000 |
parents | 4bd917f8a4a7 |
children | b2bf2a130eba |
files | doc/interpreter/strings.txi liboctave/ChangeLog liboctave/Makefile.in scripts/control/base/bode.m scripts/control/base/ctrb.m scripts/control/hinf/is_dgkf.m scripts/control/obsolete/qzval.m scripts/control/system/c2d.m scripts/control/system/ss.m scripts/control/system/ss2sys.m scripts/control/system/sysgettype.m scripts/strings/index.m scripts/strings/rindex.m scripts/strings/str2mat.m scripts/strings/strcmp.m scripts/strings/substr.m src/ChangeLog src/data.cc src/oct-stream.cc src/ov.h |
diffstat | 20 files changed, 214 insertions(+), 199 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/interpreter/strings.txi +++ b/doc/interpreter/strings.txi @@ -64,7 +64,7 @@ Represents a literal single-quote character, @samp{'}. @item \0 -Represents the ``nul'' character, control-@, ASCII code 0. +Represents the ``nul'' character, control-@@, ASCII code 0. @item \a Represents the ``alert'' character, control-g, ASCII code 7.
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,5 +1,7 @@ 2004-08-31 John W. Eaton <jwe@octave.org> + * Makefile.in (EXTRAS): Add intNDArray.cc to the list. + * data-conv.h (oct_data_conv::data_type): Include sized types. Explicitly number enum elements.
--- a/liboctave/Makefile.in +++ b/liboctave/Makefile.in @@ -129,7 +129,7 @@ $(LIBOCT_READLINE_SOURCES) \ $(LIBOCT_PATHSEARCH_SOURCES) -EXTRAS := mx-inlines.cc kpse.cc +EXTRAS := mx-inlines.cc kpse.cc intNDArray.cc INCLUDES_FOR_INSTALL := $(INCLUDES) $(TEMPLATE_SRC) $(EXTRAS)
--- a/scripts/control/base/bode.m +++ b/scripts/control/base/bode.m @@ -80,7 +80,6 @@ ## the vector of frequency values used ## @end table ## -## @strong{Notes} ## @enumerate ## @item If no output arguments are given, e.g., ## @example
--- a/scripts/control/base/ctrb.m +++ b/scripts/control/base/ctrb.m @@ -27,7 +27,7 @@ ## ## of a system data structure or the pair (@var{a}, @var{b}). ## -## @strong{Note} @code{ctrb} forms the controllability matrix. +## @code{ctrb} forms the controllability matrix. ## The numerical properties of @code{is_controllable} ## are much better for controllability tests. ## @end deftypefn
--- a/scripts/control/hinf/is_dgkf.m +++ b/scripts/control/hinf/is_dgkf.m @@ -60,13 +60,13 @@ ## @item bu ## (@var{n} x @var{nu}) @var{ru}-transformed controlled input matrix; ## -## @strong{Note} @math{B = [Bw Bu]} +## @math{B = [Bw Bu]} ## @item cz ## (@var{nz} x @var{n}) Qz-transformed error output matrix ## @item cy ## (@var{ny} x @var{n}) @var{ry}-transformed measured output matrix ## -## @strong{Note} @math{C = [Cz; Cy]} +## @math{C = [Cz; Cy]} ## @item dzu ## @item dyw ## off-diagonal blocks of transformed system @math{D} matrix that enter
--- a/scripts/control/obsolete/qzval.m +++ b/scripts/control/obsolete/qzval.m @@ -32,7 +32,7 @@ ## ## @var{a} and @var{b} must be real matrices. ## -## @strong{Note} @code{qzval} is obsolete; use @code{qz} instead. +## @code{qzval} is obsolete; use @code{qz} instead. ## @end deftypefn ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu>
--- a/scripts/control/system/c2d.m +++ b/scripts/control/system/c2d.m @@ -44,7 +44,7 @@ ## @item t ## sampling time; required if sys is purely continuous. ## -## @strong{Note} If the 2nd argument is not a string, @code{c2d} assumes that +## If the 2nd argument is not a string, @code{c2d} assumes that ## the 2nd argument is @var{t} and performs appropriate argument checks. ## @item "matched" ## Use the matched pole/zero equivalent transformation (currently only @@ -66,7 +66,7 @@ ## @end example ## via the matrix exponential or bilinear transform ## -## @strong{Note} This function adds the suffix @code{_d} +## This function adds the suffix @code{_d} ## to the names of the new discrete states. ## @end deftypefn
--- a/scripts/control/system/ss.m +++ b/scripts/control/system/ss.m @@ -72,7 +72,7 @@ ## ## Unlike states, discrete/continous outputs may appear in any order. ## -## @strong{Note} @code{sys2ss} returns a vector @var{yd} where +## @code{sys2ss} returns a vector @var{yd} where ## @var{yd}(@var{outlist}) = 1; all other entries of @var{yd} are 0. ## ## @strong{Outputs}
--- a/scripts/control/system/ss2sys.m +++ b/scripts/control/system/ss2sys.m @@ -72,7 +72,7 @@ ## ## Unlike states, discrete/continous outputs may appear in any order. ## -## @strong{Note} @code{sys2ss} returns a vector @var{yd} where +## @code{sys2ss} returns a vector @var{yd} where ## @var{yd}(@var{outlist}) = 1; all other entries of @var{yd} are 0. ## ## @strong{Outputs}
--- a/scripts/control/system/sysgettype.m +++ b/scripts/control/system/sysgettype.m @@ -28,7 +28,7 @@ ## constructed: ## values: @code{"ss"}, @code{"zp"}, or @code{"tf"} ## -## @strong{Note} FIR initialized systems return @code{systype="tf"}. +## FIR initialized systems return @code{systype="tf"}. ## @end deftypefn function systype = sysgettype (sys)
--- a/scripts/strings/index.m +++ b/scripts/strings/index.m @@ -27,7 +27,7 @@ ## @result{} 4 ## @end example ## -## @strong{Note:} This function does not work for arrays of strings. +## @strong{Caution:} This function does not work for arrays of strings. ## @end deftypefn ## Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
--- a/scripts/strings/rindex.m +++ b/scripts/strings/rindex.m @@ -27,7 +27,7 @@ ## @result{} 6 ## @end example ## -## @strong{Note:} This function does not work for arrays of strings. +## @strong{Caution:} This function does not work for arrays of strings. ## @end deftypefn ## Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
--- a/scripts/strings/str2mat.m +++ b/scripts/strings/str2mat.m @@ -23,7 +23,6 @@ ## its rows. Each string is padded with blanks in order to form a valid ## matrix. ## -## @strong{Note:} ## This function is modelled after @sc{Matlab}. In Octave, you can create ## a matrix of strings by @code{[@var{s_1}; @dots{}; @var{s_n}]} even if ## the strings are not all the same length.
--- a/scripts/strings/strcmp.m +++ b/scripts/strings/strcmp.m @@ -21,7 +21,7 @@ ## @deftypefn {Function File} {} strcmp (@var{s1}, @var{s2}) ## Compares two strings, returning 1 if they are the same, and 0 otherwise. ## -## @strong{Note:} For compatibility with @sc{Matlab}, Octave's strcmp +## @strong{Caution:} For compatibility with @sc{Matlab}, Octave's strcmp ## function returns 1 if the strings are equal, and 0 otherwise. This is ## just the opposite of the corresponding C library function. ## @end deftypefn
--- a/scripts/strings/substr.m +++ b/scripts/strings/substr.m @@ -34,7 +34,6 @@ ## @end example ## ## @quotation -## @strong{Note:} ## This function is patterned after AWK. You can get the same result by ## @code{@var{s} (@var{beg} : (@var{beg} + @var{len} - 1))}. ## @end quotation
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2004-08-31 John W. Eaton <jwe@octave.org> + + * data.cc (fill_matrix, identity_matrix): Convert class name to + oct_data_conv::data_type and switch on that. + (identity_matrix (int, int)): New template. + (identity_matrix (int, int, const std::string&)): Use it. + + * ov.h (octave_type_traits, octave_array_type_traits): Move here. + * oct-stream.cc: From here. + 2004-08-31 David Bateman <dbateman@free.fr> * data.cc (Fzeros, Fones, Feye): Update help text for optional
--- a/src/data.cc +++ b/src/data.cc @@ -1208,31 +1208,24 @@ int nargin = args.length (); - std::string nm = "double"; - - int ndim = 0; + oct_data_conv::data_type dt = oct_data_conv::dt_double; - dim_vector dims; + dim_vector dims (1, 1); - // Check for type information. - if (nargin > 0 && args(nargin-1).is_string ()) { - nm = args(nargin-1).string_value(); + std::string nm = args(nargin-1).string_value (); nargin--; - if (nm != "int8" && nm != "int16" && nm != "int32" && nm != "int64" && - nm != "uint8" && nm != "uint16" && nm != "uint32" && nm != "uint64" - && nm != "double") - error ("%s: Unrecognized or illegal classname", fcn); + dt = oct_data_conv::string_to_data_type (nm); + + if (error_state) + return retval; } - // determine matrix dimension - switch (nargin) { case 0: - ndim = 0; break; case 1: @@ -1259,78 +1252,62 @@ if (! error_state) { - ndim = dims.length (); - - for (int i = ndim-1; i > 1; i--) - { - if (dims(i) == 1) - ndim--; - else - break; - } - - dims.resize (ndim); + dims.chop_trailing_singletons (); check_dimensions (dims, fcn); + // XXX FIXME XXX -- perhaps this should be made extensible by + // using the class name to lookup a function to call to create + // the new value. + + // Note that automatic narrowing will handle conversion from + // NDArray to scalar. + if (! error_state) { + switch (dt) + { + case oct_data_conv::dt_int8: + retval = int8NDArray (dims, val); + break; -#define INT_FILL_MATRIX(TYPE) \ - { \ - switch (ndim) \ - { \ - case 0: \ - retval = octave_ ## TYPE (val); \ - break; \ - \ - default: \ - retval = TYPE ## NDArray (dims, val); \ - break; \ - } \ - } + case oct_data_conv::dt_uint8: + retval = uint8NDArray (dims, val); + break; + + case oct_data_conv::dt_int16: + retval = int16NDArray (dims, val); + break; + + case oct_data_conv::dt_uint16: + retval = uint16NDArray (dims, val); + break; + + case oct_data_conv::dt_int32: + retval = int32NDArray (dims, val); + break; - if (nm == "int8") - INT_FILL_MATRIX (int8) - else if (nm == "int16") - INT_FILL_MATRIX (int16) - else if (nm == "int32") - INT_FILL_MATRIX (int32) - else if (nm == "int64") - INT_FILL_MATRIX (int64) - else if (nm == "uint8") - INT_FILL_MATRIX (uint8) - else if (nm == "uint16") - INT_FILL_MATRIX (uint16) - else if (nm == "uint32") - INT_FILL_MATRIX (uint32) - else if (nm == "uint64") - INT_FILL_MATRIX (uint64) - else - { - // Construct either scalar, matrix or N-d array. - switch (ndim) - { - case 0: - retval = val; - break; + case oct_data_conv::dt_uint32: + retval = uint32NDArray (dims, val); + break; + + case oct_data_conv::dt_int64: + retval = int64NDArray (dims, val); + break; - case 1: - retval = Matrix (dims(0), dims(0), val); - break; - - case 2: - retval = Matrix (dims(0), dims(1), val); - break; + case oct_data_conv::dt_uint64: + retval = uint64NDArray (dims, val); + break; - default: - retval = NDArray (dims, val); - break; - } + case oct_data_conv::dt_single: // XXX FIXME XXX + case oct_data_conv::dt_double: + retval = NDArray (dims, val); + break; + + default: + error ("%s: invalid class name", fcn); + break; } - -#undef INT_FILL_MATRIX - } } @@ -1384,72 +1361,101 @@ return fill_matrix (args, 0.0, "zeros"); } +template <class MT> +octave_value +identity_matrix (int nr, int nc) +{ + octave_value retval; + + typename octave_array_type_traits<MT>::element_type one (1); + + if (nr == 1 && nc == 1) + retval = one; + else + { + dim_vector dims (nr, nc); + + typename octave_array_type_traits<MT>::element_type zero (0); + + MT m (dims, zero); + + if (nr > 0 && nc > 0) + { + int n = std::min (nr, nc); + + for (int i = 0; i < n; i++) + m(i,i) = one; + } + + retval = m; + } + + return retval; +} + static octave_value identity_matrix (int nr, int nc, const std::string& nm) { octave_value retval; -#define INT_EYE_MATRIX(TYPE) \ - { \ - if (nr == 1 && nc == 1) \ - retval = octave_ ## TYPE (1); \ - else \ - { \ - dim_vector dims (nr, nc); \ - TYPE ## NDArray m (dims, octave_ ## TYPE (0));\ - if (nr > 0 && nc > 0) \ - { \ - int n = std::min (nr, nc); \ - \ - for (int i = 0; i < n; i++) \ - m (i, i) = octave_ ## TYPE (1); \ - } \ - retval = m; \ - } \ - } + oct_data_conv::data_type dt = oct_data_conv::string_to_data_type (nm); + + // XXX FIXME XXX -- perhaps this should be made extensible by using + // the class name to lookup a function to call to create the new + // value. + + if (! error_state) + { + switch (dt) + { + case oct_data_conv::dt_int8: + retval = identity_matrix<int8NDArray> (nr, nc); + break; + + case oct_data_conv::dt_uint8: + retval = identity_matrix<uint8NDArray> (nr, nc); + break; + + case oct_data_conv::dt_int16: + retval = identity_matrix<int16NDArray> (nr, nc); + break; - if (nm == "int8") - INT_EYE_MATRIX (int8) - else if (nm == "int16") - INT_EYE_MATRIX (int16) - else if (nm == "int32") - INT_EYE_MATRIX (int32) - else if (nm == "int64") - INT_EYE_MATRIX (int64) - else if (nm == "uint8") - INT_EYE_MATRIX (uint8) - else if (nm == "uint16") - INT_EYE_MATRIX (uint16) - else if (nm == "uint32") - INT_EYE_MATRIX (uint32) - else if (nm == "uint64") - INT_EYE_MATRIX (uint64) - else - { - if (nr == 1 && nc == 1) - retval = 1.0; - else - { + case oct_data_conv::dt_uint16: + retval = identity_matrix<uint16NDArray> (nr, nc); + break; + + case oct_data_conv::dt_int32: + retval = identity_matrix<int32NDArray> (nr, nc); + break; + + case oct_data_conv::dt_uint32: + retval = identity_matrix<uint32NDArray> (nr, nc); + break; - Matrix m (nr, nc, 0.0); - - if (nr > 0 && nc > 0) - { - int n = std::min (nr, nc); + case oct_data_conv::dt_int64: + retval = identity_matrix<int64NDArray> (nr, nc); + break; + + case oct_data_conv::dt_uint64: + retval = identity_matrix<uint64NDArray> (nr, nc); + break; - for (int i = 0; i < n; i++) - m (i, i) = 1.0; - } + case oct_data_conv::dt_single: // XXX FIXME XXX + case oct_data_conv::dt_double: + retval = identity_matrix<NDArray> (nr, nc); + break; - retval = m; + default: + error ("eye: invalid class name"); + break; } } -#undef INT_EYE_MATRIX - return retval; } +#undef INT_EYE_MATRIX + DEFUN (eye, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} eye (@var{x})\n\
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -2770,61 +2770,6 @@ rep->close (); } -// XXX FIXME XXX -- these trait classes probably belong somehwere else... - -template <typename T> -class -octave_type_traits -{ -public: - typedef T val_type; -}; - -#define OCTAVE_TYPE_TRAIT(T, VAL_T) \ - template <> \ - class \ - octave_type_traits<T> \ - { \ - public: \ - typedef VAL_T val_type; \ - } - -OCTAVE_TYPE_TRAIT (octave_int8, octave_int8::val_type); -OCTAVE_TYPE_TRAIT (octave_uint8, octave_uint8::val_type); -OCTAVE_TYPE_TRAIT (octave_int16, octave_int16::val_type); -OCTAVE_TYPE_TRAIT (octave_uint16, octave_uint16::val_type); -OCTAVE_TYPE_TRAIT (octave_int32, octave_int32::val_type); -OCTAVE_TYPE_TRAIT (octave_uint32, octave_uint32::val_type); -OCTAVE_TYPE_TRAIT (octave_int64, octave_int64::val_type); -OCTAVE_TYPE_TRAIT (octave_uint64, octave_uint64::val_type); - -template <typename T> -class octave_array_type_traits -{ -public: - typedef T element_type; -}; - -#define OCTAVE_ARRAY_TYPE_TRAIT(T, ELT_T) \ - template <> \ - class \ - octave_array_type_traits<T> \ - { \ - public: \ - typedef ELT_T element_type; \ - } - -OCTAVE_ARRAY_TYPE_TRAIT (charNDArray, char); -OCTAVE_ARRAY_TYPE_TRAIT (int8NDArray, octave_int8); -OCTAVE_ARRAY_TYPE_TRAIT (uint8NDArray, octave_uint8); -OCTAVE_ARRAY_TYPE_TRAIT (int16NDArray, octave_int16); -OCTAVE_ARRAY_TYPE_TRAIT (uint16NDArray, octave_uint16); -OCTAVE_ARRAY_TYPE_TRAIT (int32NDArray, octave_int32); -OCTAVE_ARRAY_TYPE_TRAIT (uint32NDArray, octave_uint32); -OCTAVE_ARRAY_TYPE_TRAIT (int64NDArray, octave_int64); -OCTAVE_ARRAY_TYPE_TRAIT (uint64NDArray, octave_uint64); -OCTAVE_ARRAY_TYPE_TRAIT (NDArray, double); - template <class RET_T, class READ_T> octave_value do_read (octave_stream& strm, int nr, int nc, int block_size,
--- a/src/ov.h +++ b/src/ov.h @@ -951,6 +951,61 @@ extern void install_types (void); +// XXX FIXME XXX -- these trait classes probably belong somehwere else... + +template <typename T> +class +octave_type_traits +{ +public: + typedef T val_type; +}; + +#define OCTAVE_TYPE_TRAIT(T, VAL_T) \ + template <> \ + class \ + octave_type_traits<T> \ + { \ + public: \ + typedef VAL_T val_type; \ + } + +OCTAVE_TYPE_TRAIT (octave_int8, octave_int8::val_type); +OCTAVE_TYPE_TRAIT (octave_uint8, octave_uint8::val_type); +OCTAVE_TYPE_TRAIT (octave_int16, octave_int16::val_type); +OCTAVE_TYPE_TRAIT (octave_uint16, octave_uint16::val_type); +OCTAVE_TYPE_TRAIT (octave_int32, octave_int32::val_type); +OCTAVE_TYPE_TRAIT (octave_uint32, octave_uint32::val_type); +OCTAVE_TYPE_TRAIT (octave_int64, octave_int64::val_type); +OCTAVE_TYPE_TRAIT (octave_uint64, octave_uint64::val_type); + +template <typename T> +class octave_array_type_traits +{ +public: + typedef T element_type; +}; + +#define OCTAVE_ARRAY_TYPE_TRAIT(T, ELT_T) \ + template <> \ + class \ + octave_array_type_traits<T> \ + { \ + public: \ + typedef ELT_T element_type; \ + } + +OCTAVE_ARRAY_TYPE_TRAIT (charNDArray, char); +OCTAVE_ARRAY_TYPE_TRAIT (int8NDArray, octave_int8); +OCTAVE_ARRAY_TYPE_TRAIT (uint8NDArray, octave_uint8); +OCTAVE_ARRAY_TYPE_TRAIT (int16NDArray, octave_int16); +OCTAVE_ARRAY_TYPE_TRAIT (uint16NDArray, octave_uint16); +OCTAVE_ARRAY_TYPE_TRAIT (int32NDArray, octave_int32); +OCTAVE_ARRAY_TYPE_TRAIT (uint32NDArray, octave_uint32); +OCTAVE_ARRAY_TYPE_TRAIT (int64NDArray, octave_int64); +OCTAVE_ARRAY_TYPE_TRAIT (uint64NDArray, octave_uint64); +OCTAVE_ARRAY_TYPE_TRAIT (NDArray, double); + #endif /*