Mercurial > hg > octave-terminal
changeset 15527:73d23a6e7bf3
Merge in Richard's changes
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Mon, 15 Oct 2012 13:16:58 -0400 |
parents | ae43fc2ddcac (diff) 1353ca03266f (current diff) |
children | 8d2b3db8b5b0 |
files | |
diffstat | 26 files changed, 236 insertions(+), 99 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS +++ b/NEWS @@ -93,10 +93,11 @@ ** Other new functions added in 3.8.0: - betaincinv erfcinv polyeig shrinkfaces - cmpermute findfigs splinefit - cmunique fminsearch tetramesh - colorcube lines rgbplot + betaincinv erfcinv lines rgbplot + cmpermute findfigs polyeig shrinkfaces + cmunique fminsearch splinefit + colorcube iscolormap tetramesh + ** Deprecated functions. The following functions were deprecated in Octave 3.4 and have been
--- a/configure.ac +++ b/configure.ac @@ -622,7 +622,7 @@ #if defined (HAVE_PCRE_H) # include <pcre.h> #elif defined (HAVE_PCRE_PCRE_H) - # include <pcre.h> + # include <pcre/pcre.h> #error "NO PCRE HEADER" #endif #if defined (PCRE_INFO_NAMECOUNT) \
--- a/doc/interpreter/Makefile.am +++ b/doc/interpreter/Makefile.am @@ -249,6 +249,7 @@ EXTRA_DIST = \ config-images.sh \ contributors.in \ + doc-cache \ find-docstring-files.sh \ images \ images.awk \
--- a/doc/interpreter/errors.txi +++ b/doc/interpreter/errors.txi @@ -296,7 +296,10 @@ If a warning has such an ID the user can enable and disable this warning as will be described in the next section. To assign an ID to a warning, simply call @code{warning} with two string arguments, where the first -is the identification string, and the second is the actual warning. +is the identification string, and the second is the actual warning. Note +that warning IDs are in the format "NAMESPACE:WARNING-NAME". The namespace +"Octave" is used for Octave's own warnings. Any other string is available +as a namespace for user's own warnings. @DOCSTRING(warning) @@ -315,7 +318,7 @@ @example @group -warning ("non-negative-variable", +warning ("example:non-negative-variable", "'a' must be non-negative. Setting 'a' to zero."); @end group @end example @@ -325,8 +328,8 @@ @example @group -warning ("off", "non-negative-variable"); -warning ("non-negative-variable", +warning ("off", "example:non-negative-variable"); +warning ("example:non-negative-variable", "'a' must be non-negative. Setting 'a' to zero."); @end group @end example
--- a/doc/interpreter/image.txi +++ b/doc/interpreter/image.txi @@ -117,6 +117,8 @@ an RGB color. The color map must be of class @code{double} with values between 0 and 1. +@DOCSTRING(iscolormap) + @DOCSTRING(gray2ind) @DOCSTRING(ind2gray)
--- a/doc/interpreter/mk_doc_cache.m +++ b/doc/interpreter/mk_doc_cache.m @@ -121,4 +121,5 @@ cache(:,k:end) = []; # delete unused pre-allocated entries +save_header_format_string (["# doc-cache created by Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z"]); save ("-text", output_file, "cache");
--- a/libinterp/dldfcn/__fltk_uigetfile__.cc +++ b/libinterp/dldfcn/__fltk_uigetfile__.cc @@ -24,7 +24,7 @@ #include <config.h> #endif -#if defined (HAVE_FLTK) +#ifdef HAVE_FLTK #ifdef WIN32 #define WIN32_LEAN_AND_MEAN @@ -39,6 +39,8 @@ // headers which may require Octave's Complex typedef. #undef Complex +#endif + #include "defun-dld.h" #include "file-ops.h" @@ -48,6 +50,7 @@ Undocumented internal function.\n\ @end deftypefn") { +#ifdef HAVE_FLTK // Expected argument list: // // args(0) ... FileFilter in fltk format @@ -132,6 +135,10 @@ Fl::flush (); return retval; +#else + error ("__fltk_uigetfile__: not available without OpenGL and FLTK libraries"); + return octave_value (); +#endif } /* @@ -139,4 +146,3 @@ %!assert (1) */ -#endif
--- a/libinterp/dldfcn/__init_fltk__.cc +++ b/libinterp/dldfcn/__init_fltk__.cc @@ -29,7 +29,7 @@ */ -// PKG_ADD: register_graphics_toolkit ("fltk"); +// PKG_ADD: if (__have_fltk__ ()) register_graphics_toolkit ("fltk"); endif #ifdef HAVE_CONFIG_H #include <config.h> @@ -38,7 +38,7 @@ #include "defun-dld.h" #include "error.h" -#if defined (HAVE_FLTK) +#ifdef HAVE_FLTK #include <map> #include <set> @@ -1984,10 +1984,17 @@ } }; +#endif + // Initialize the fltk graphics toolkit. -DEFUN_DLD (__init_fltk__, , , "") +DEFUN_DLD (__init_fltk__, , , + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} __init_fltk__ ()\n\ +Undocumented internal function.\n\ +@end deftypefn") { +#ifdef HAVE_FLTK if (! toolkit_loaded) { mlock (); @@ -2000,20 +2007,36 @@ args(0) = "__fltk_redraw__"; feval ("add_input_event_hook", args, 0); } - - octave_value retval; - return retval; -} - -DEFUN_DLD (__fltk_redraw__, , , "") -{ - __fltk_redraw__ (); +#else + error ("__init_fltk__: not available without OpenGL and FLTK libraries"); +#endif return octave_value (); } -DEFUN_DLD (__fltk_maxtime__, args, ,"") +DEFUN_DLD (__fltk_redraw__, , , + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} __fltk_redraw__ ()\n\ +Undocumented internal function.\n\ +@end deftypefn") { +#ifdef HAVE_FLTK + __fltk_redraw__ (); +#else + error ("__fltk_redraw__: not available without OpenGL and FLTK libraries"); +#endif + + return octave_value (); +} + +DEFUN_DLD (__fltk_maxtime__, args, , + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {@var{maxtime} =} __fltk_maxtime__ ()\n\ +@deftypefnx {Loadable Function} {} __fltk_maxtime__ (@var{maxtime})\n\ +Undocumented internal function.\n\ +@end deftypefn") +{ +#ifdef HAVE_FLTK octave_value retval = fltk_maxtime; if (args.length () == 1) @@ -2025,10 +2048,29 @@ } return retval; +#else + error ("__fltk_maxtime__: not available without OpenGL and FLTK libraries"); + return octave_value (); +#endif } +DEFUN_DLD (__have_fltk__, , , + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {@var{FLTK_available} =} __have_fltk__ ()\n\ +Undocumented internal function.\n\ +@end deftypefn") +{ + octave_value retval; + +#ifdef HAVE_FLTK + retval = true; +#else + retval = false; #endif + return retval; +} + // FIXME -- This function should be abstracted and made potentially // available to all graphics toolkits. This suggests putting it in // graphics.cc as is done for drawnow() and having the master @@ -2046,7 +2088,7 @@ @seealso{gui_mode}\n\ @end deftypefn") { -#if defined (HAVE_FLTK) +#ifdef HAVE_FLTK octave_value retval = wheel_zoom_speed; if (args.length () == 1) @@ -2086,7 +2128,7 @@ @seealso{mouse_wheel_zoom}\n\ @end deftypefn") { -#if defined (HAVE_FLTK) +#ifdef HAVE_FLTK caseless_str mode_str; if (gui_mode == pan_zoom) @@ -2122,8 +2164,7 @@ return octave_value (mode_str); #else - error ("mouse_wheel_zoom: not available without OpenGL and FLTK libraries"); + error ("gui_mode: not available without OpenGL and FLTK libraries"); return octave_value (); #endif } -
--- a/libinterp/interp-core/zfstream.cc +++ b/libinterp/interp-core/zfstream.cc @@ -473,6 +473,11 @@ if ((io_mode & std::ios_base::in) && way == std::ios_base::cur) computed_off += this->gptr () - this->egptr (); + // Handle tellg/tellp as a special case up front, no need to seek + // or invalidate get/put buffers + if (off == 0 && way == std::ios_base::cur) + return pos_type (gztell (file) + computed_off); + if (way == std::ios_base::beg) ret = pos_type (gzseek (file, computed_off, SEEK_SET)); else if (way == std::ios_base::cur)
--- a/libinterp/interpfcn/data.cc +++ b/libinterp/interpfcn/data.cc @@ -4116,53 +4116,53 @@ { if (args(0).is_single_type ()) { - float val = args(0).float_value (); + Array<float> x = args(0).float_array_value (); if (! error_state) - { - val = ::fabsf (val); - if (xisnan (val) || xisinf (val)) - retval = fill_matrix (octave_value ("single"), - lo_ieee_nan_value (), - lo_ieee_float_nan_value (), "eps"); - else if (val < std::numeric_limits<float>::min ()) - retval = fill_matrix (octave_value ("single"), 0e0, - powf (2.0, -149e0), "eps"); - else + { + Array<float> epsval (x.dims ()); + + for (octave_idx_type i = 0; i < x.numel (); i++) { - int expon; - frexpf (val, &expon); - val = std::pow (static_cast <float> (2.0), - static_cast <float> (expon - 24)); - retval = fill_matrix (octave_value ("single"), - std::numeric_limits<double>::epsilon (), - val, "eps"); + float val = ::fabsf (x(i)); + if (xisnan (val) || xisinf (val)) + epsval(i) = lo_ieee_nan_value (); + else if (val < std::numeric_limits<float>::min ()) + epsval(i) = powf (2.0, -149e0); + else + { + int expon; + frexpf (val, &expon); + epsval(i) = std::pow (static_cast <float> (2.0), + static_cast <float> (expon - 24)); + } } + retval = epsval; } } else { - double val = args(0).double_value (); + Array<double> x = args(0).array_value (); if (! error_state) { - val = ::fabs (val); - if (xisnan (val) || xisinf (val)) - retval = fill_matrix (octave_value_list (), - lo_ieee_nan_value (), - lo_ieee_float_nan_value (), "eps"); - else if (val < std::numeric_limits<double>::min ()) - retval = fill_matrix (octave_value_list (), - pow (2.0, -1074e0), 0e0, "eps"); - else + Array<double> epsval (x.dims ()); + + for (octave_idx_type i = 0; i < x.numel (); i++) { - int expon; - frexp (val, &expon); - val = std::pow (static_cast <double> (2.0), - static_cast <double> (expon - 53)); - retval = fill_matrix (octave_value_list (), val, - std::numeric_limits<float>::epsilon (), - "eps"); + double val = ::fabs (x(i)); + if (xisnan (val) || xisinf (val)) + epsval(i) = lo_ieee_nan_value (); + else if (val < std::numeric_limits<double>::min ()) + epsval(i) = pow (2.0, -1074e0); + else + { + int expon; + frexp (val, &expon); + epsval(i) = std::pow (static_cast <double> (2.0), + static_cast <double> (expon - 53)); + } + retval = epsval; } } } @@ -4184,6 +4184,8 @@ %!assert (eps (realmin/16), 2^(-1074)) %!assert (eps (Inf), NaN) %!assert (eps (NaN), NaN) +%!assert (eps ([1/2 1 2 realmax 0 realmin/2 realmin/16 Inf NaN]), +%! [2^(-53) 2^(-52) 2^(-51) 2^971 2^(-1074) 2^(-1074) 2^(-1074) NaN NaN]) %!assert (eps (single (1/2)), single (2^(-24))) %!assert (eps (single (1)), single (2^(-23))) %!assert (eps (single (2)), single (2^(-22))) @@ -4193,6 +4195,9 @@ %!assert (eps (realmin ("single")/16), single (2^(-149))) %!assert (eps (single (Inf)), single (NaN)) %!assert (eps (single (NaN)), single (NaN)) +%!assert (eps (single ([1/2 1 2 realmax("single") 0 realmin("single")/2 realmin("single")/16 Inf NaN])), +%! single ([2^(-24) 2^(-23) 2^(-22) 2^104 2^(-149) 2^(-149) 2^(-149) NaN NaN])) + */ DEFUN (pi, args, ,
--- a/libinterp/interpfcn/error.cc +++ b/libinterp/interpfcn/error.cc @@ -1213,8 +1213,10 @@ to go on.\n\ \n\ The optional message identifier allows users to enable or disable\n\ -warnings tagged by @var{id}. The special identifier @samp{\"all\"} may\n\ -be used to set the state of all warnings.\n\ +warnings tagged by @var{id}. A message identifier is of the form\n\ +\"NAMESPACE:WARNING-NAME\". Octave's own warnings use the \"Octave\"\n\ +namespace (@pxref{doc-warning_ids}). The special identifier @samp{\"all\"}\n\ +may be used to set the state of all warnings.\n\ \n\ If the first argument is @samp{\"on\"} or @samp{\"off\"}, set the state\n\ of a particular warning using the identifier @var{id}. If the first\n\
--- a/libinterp/interpfcn/graphics.in.h +++ b/libinterp/interpfcn/graphics.in.h @@ -4810,6 +4810,8 @@ // properties declarations. BEGIN_PROPERTIES (hggroup) + string_property displayname , "" + radio_property erasemode , "{normal}|none|xor|background" // hidden properties for limit computation row_vector_property xlim hr , Matrix () row_vector_property ylim hr , Matrix ()
--- a/libinterp/interpfcn/variables.cc +++ b/libinterp/interpfcn/variables.cc @@ -543,13 +543,13 @@ Check only for built-in functions.\n\ \n\ @item \"file\"\n\ -Check only for files.\n\ +Check only for files and directories.\n\ \n\ @item \"dir\"\n\ Check only for directories.\n\ @end table\n\ \n\ -@seealso{file_in_loadpath}\n\ +@seealso{file_in_loadpath, file_in_path, stat}\n\ @end deftypefn") { octave_value retval = false;
--- a/libinterp/octave-value/ov-base.cc +++ b/libinterp/octave-value/ov-base.cc @@ -1193,6 +1193,7 @@ "erfinv", "erfcinv", "erfc", + "erfcx", "exp", "expm1", "finite",
--- a/libinterp/octave-value/ov-base.h +++ b/libinterp/octave-value/ov-base.h @@ -802,9 +802,9 @@ // (think of an empty cell array with >2G elements). octave_refcount<octave_idx_type> count; -private: + static const char *get_umap_name (unary_mapper_t); - static const char *get_umap_name (unary_mapper_t); +private: static int curr_print_indent_level; static bool beginning_of_line;
--- a/libinterp/octave-value/ov-ch-mat.cc +++ b/libinterp/octave-value/ov-ch-mat.cc @@ -172,6 +172,8 @@ octave_value octave_char_matrix::map (unary_mapper_t umap) const { + octave_value retval; + switch (umap) { #define STRING_MAPPER(UMAP,FCN,TYPE) \ @@ -194,10 +196,26 @@ STRING_MAPPER (xtolower, std::tolower, char); STRING_MAPPER (xtoupper, std::toupper, char); - default: + // For Matlab compatibility, these should work on ASCII values + // without error or warning. + case umap_abs: + case umap_ceil: + case umap_fix: + case umap_floor: + case umap_imag: + case umap_isinf: + case umap_isnan: + case umap_real: + case umap_round: { octave_matrix m (array_value (true)); return m.map (umap); } + + default: + error ("%s: expecting numeric argument", get_umap_name (umap)); + break; } + + return retval; }
--- a/scripts/image/cmpermute.m +++ b/scripts/image/cmpermute.m @@ -54,9 +54,7 @@ error ("cmpermute: X must be an indexed image"); endif - if (! isnumeric (map) || iscomplex (map) - || ndims (map) != 2 || columns (map) != 3 - || any (map(:) < 0) || any (map(:) > 1)) + if (! iscolormap (map)) error ("cmpermute: MAP must be a valid colormap"); endif
--- a/scripts/image/cmunique.m +++ b/scripts/image/cmunique.m @@ -68,9 +68,7 @@ if (nargin == 2) ## (X, map) case - if (! isnumeric (map) || iscomplex (map) - || ndims (map) != 2 || columns (map) != 3 - || any (map(:) < 0) || any (map(:) > 1)) + if (! iscolormap (map)) error ("cmunique: MAP must be a valid colormap"); endif [newmap,i,j] = unique (map, "rows"); # calculate unique colormap
--- a/scripts/image/imwrite.m +++ b/scripts/image/imwrite.m @@ -161,13 +161,8 @@ else error ("imwrite: %s: invalid class for indexed image data", img_class); endif - if (isa (map, "double")) - if (ndims (map) != 2 || columns (map) != 3) - error ("imwrite: invalid size for colormap"); - endif - else - error ("imwrite: %s invalid class for indexed image colormap", - class (map)); + if (! iscolormap (map)) + error ("imwrite: invalid indexed image colormap"); endif ## FIXME -- we should really be writing indexed images here but
--- a/scripts/image/ind2rgb.m +++ b/scripts/image/ind2rgb.m @@ -46,7 +46,7 @@ endif ## Check the color map. - if (ndims (map) != 2 || columns (map) != 3) + if (! iscolormap (map)) error ("ind2rgb: MAP must be a valid colormap"); endif
new file mode 100644 --- /dev/null +++ b/scripts/image/iscolormap.m @@ -0,0 +1,52 @@ +## Copyright (C) 2012 Carnë Draug +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} iscolormap (@var{cmap}) +## Return true if @var{cmap} is a colormap. +## +## A colormap is an @var{n} row by 3 column matrix. The columns contain red, +## green, and blue intensities respectively. All entries must be between 0 +## and 1 inclusive. +## +## @seealso{colormap, rgbplot} +## @end deftypefn + +## Author: Carnë Draug <carandraug+dev@gmail.com> + +function retval = iscolormap (cmap) + + if (nargin != 1) + print_usage; + endif + + retval = (isnumeric (cmap) && isreal (cmap) && + columns (cmap) == 3 && ndims (cmap) == 2 && isa (cmap, "double") && + min (cmap(:)) >= 0 && max (cmap(:)) <= 1); + +endfunction + + +%!assert (iscolormap (jet (64))) +%!assert (iscolormap ({0 1 0}), false) +%!assert (iscolormap ([0 1i 0]), false) +%!assert (iscolormap (ones (3,4)), false) +%!assert (iscolormap (ones (3,3,3)), false) +%!assert (iscolormap (single (jet (64))), false) +%!assert (iscolormap ([0 0 -2]), false) +%!assert (iscolormap ([0 0 2]), false)
--- a/scripts/image/module.mk +++ b/scripts/image/module.mk @@ -18,6 +18,7 @@ image/hot.m \ image/hsv.m \ image/hsv2rgb.m \ + image/iscolormap.m \ image/image.m \ image/imagesc.m \ image/imfinfo.m \
--- a/scripts/image/rgbplot.m +++ b/scripts/image/rgbplot.m @@ -17,31 +17,37 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {} rgbplot (@var{cmap}) +## @deftypefn {Function File} {} rgbplot (@var{cmap}) +## @deftypefnx {Function File} {@var{h} =} rgbplot (@var{cmap}) ## Plot the components of a colormap. ## ## The first column is plotted in red, the second column in green, and ## the third column in blue. The values are between 0 and 1 and represent ## the intensity of the RGB components in the given indexed color. +## +## The optional return value @var{h} is a graphics handle to the created plot. +## ## @seealso{colormap} ## @end deftypefn -function rgbplot (cmap) +function retval = rgbplot (cmap) if (nargin != 1) print_usage (); endif - if (! ismatrix (cmap) || ndims (cmap) != 2 || columns (cmap) != 3) - error ("rgbplot: CMAP must be a matrix of size Nx3"); - elseif (any (cmap(:) < 0) || any (cmap(:) > 1)) - error ("rgbplot: CMAP intensities must be in the range [0, 1]"); + if (! iscolormap (cmap)) + error ("rgbplot: CMAP must be a colormap"); endif - plot (cmap(:,1),"r", cmap(:,2),"g", cmap(:,3),"b"); + h = plot (cmap(:,1),"r", cmap(:,2),"g", cmap(:,3),"b"); set (gca, 'ytick', 0:0.1:1); xlabel ("color index"); + if (nargout > 0) + retval = h; + endif + endfunction @@ -52,9 +58,4 @@ %%test input validation %!error rgbplot () %!error rgbplot (1,2) -%!error <CMAP must be a matrix of size Nx3> rgbplot ({0 1 0}) -%!error <CMAP must be a matrix of size Nx3> rgbplot (ones (3,3,3)) -%!error <CMAP must be a matrix of size Nx3> rgbplot (ones (3,4)) -%!error <CMAP intensities must be in the range> rgbplot ([0 0 -2]) -%!error <CMAP intensities must be in the range> rgbplot ([0 0 2]) - +%!error <CMAP must be a colormap> rgbplot ({0 1 0})
--- a/scripts/strings/strsplit.m +++ b/scripts/strings/strsplit.m @@ -104,7 +104,7 @@ %!assert (strsplit ("road to hell", " "), {"road", "to", "hell"}) %!assert (strsplit ("road to^hell", " ^"), {"road", "to", "hell"}) %!assert (strsplit ("road to--hell", " -", true), {"road", "to", "hell"}) -%!assert (strsplit (["a,bc";",de"], ","), {"a", "bc", ones(1,0), "de "}) +%!assert (strsplit (["a,bc";",de"], ","), {"a", "bc", char(ones(1,0)), "de "}) %!assert (strsplit (["a,bc";",de"], ",", true), {"a", "bc", "de "}) %!assert (strsplit (["a,bc";",de"], ", ", true), {"a", "bc", "de"})
--- a/scripts/testfun/demo.m +++ b/scripts/testfun/demo.m @@ -101,7 +101,11 @@ endif [code, idx] = test (name, "grabdemo"); - if (isempty (idx)) + + if (idx == -1) + warning ("no function %s found", name); + return; + elseif (isempty (idx)) warning ("no demo available for %s", name); return; elseif (n >= length (idx))
--- a/scripts/testfun/test.m +++ b/scripts/testfun/test.m @@ -171,7 +171,7 @@ if (isempty (__file)) if (__grabdemo) __ret1 = ""; - __ret2 = []; + __ret2 = -1; else if (exist (__name) == 3) fprintf (__fid, "%s%s source code with tests for dynamically linked function not found\n", __signal_empty, __name);