Mercurial > hg > octave-nkf
changeset 18505:888cd8f62c67 gui-release
maint: Periodic merge of stable to gui-release.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 08 Feb 2014 13:33:05 -0800 |
parents | f74c6aaa6d0f (current diff) 5d14a08e7533 (diff) |
children | e76d50d65278 9fbea0c395ec |
files | configure.ac libgui/src/main-window.cc libinterp/parse-tree/lex.ll |
diffstat | 12 files changed, 233 insertions(+), 197 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac +++ b/configure.ac @@ -1662,7 +1662,7 @@ ;; *-*-darwin*) DL_LDFLAGS='-bundle -bundle_loader $(top_builddir)/libinterp/octave $(LDFLAGS)' - MKOCTFILE_DL_LDFLAGS='-bundle -bundle_loader $$BINDIR/octave-$$OCTAVE_VERSION$$EXEEXT' + MKOCTFILE_DL_LDFLAGS='-bundle -bundle_loader $(bindir)/octave-$(version)$(EXEEXT)' SH_LDFLAGS='-dynamiclib -single_module $(LDFLAGS)' case $canonical_host_type in powerpc-*)
--- a/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp +++ b/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp @@ -59,6 +59,7 @@ font.setPointSize(10); #endif setTerminalFont(font); + setFocusPolicy (Qt::StrongFocus); setFocusProxy(m_terminalView); setFocus(Qt::OtherFocusReason);
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -917,7 +917,10 @@ void main_window::set_window_layout (QSettings *settings) { - QList<octave_dock_widget *> float_and_visible; +#if ! defined (Q_OS_WIN32) + restoreState (settings->value ("MainWindow/windowState").toByteArray ()); + restoreGeometry (settings->value ("MainWindow/geometry").toByteArray ()); +#endif // Restore the geometry of all dock-widgets foreach (octave_dock_widget *widget, dock_widget_list ()) @@ -931,20 +934,24 @@ bool visible = settings->value ("DockWidgets/" + name + "Visible", true).toBool (); -#if defined (Q_OS_WIN32) // If floating, make window from widget. if (floating) widget->make_window (); else if (! widget->parent ()) // should not be floating but is widget->make_widget (false); // no docking, just reparent -#else +#if ! defined (Q_OS_WIN32) // restore geometry QVariant val = settings->value ("DockWidgets/" + name); widget->restoreGeometry (val.toByteArray ()); #endif // make widget visible if desired if (floating && visible) // floating and visible - float_and_visible.append (widget); // not show before main win + { + if (settings->value ("DockWidgets/" + widget->objectName () + "_minimized").toBool ()) + widget->showMinimized (); + else + widget->setVisible (true); + } else { widget->make_widget (); @@ -953,31 +960,12 @@ } } -#if ! defined (Q_OS_WIN32) - // show main first but minimized to avoid flickering, - // otherwise the name of a floating widget is shown in a global menu bar - showMinimized (); - // hide again, otherwise the geometry is not exactly restored - hide (); -#endif - // restore geomoetry of main window +#if defined (Q_OS_WIN32) restoreState (settings->value ("MainWindow/windowState").toByteArray ()); restoreGeometry (settings->value ("MainWindow/geometry").toByteArray ()); - // show main window +#endif + show (); - - // show floating widgets after main win to ensure "Octave" in central menu - foreach (octave_dock_widget *widget, float_and_visible) - { -#if ! defined (Q_OS_WIN32) - widget->make_window (); -#endif - if (settings->value ("DockWidgets/" + widget->objectName () + "_minimized").toBool ()) - widget->showMinimized (); - else - widget->setVisible (true); - } - } void
--- a/libgui/src/terminal-dock-widget.cc +++ b/libgui/src/terminal-dock-widget.cc @@ -38,6 +38,8 @@ set_title (tr ("Command Window")); setWidget (terminal); + setFocusProxy (terminal); + setFocusPolicy (Qt::StrongFocus); connect (terminal, SIGNAL (interrupt_signal (void)), this, SLOT (terminal_interrupt ()));
--- a/libinterp/corefcn/lu.cc +++ b/libinterp/corefcn/lu.cc @@ -206,61 +206,53 @@ else if (arg_is_empty > 0) return octave_value_list (5, SparseMatrix ()); - ColumnVector Qinit; - if (nargout < 4) - { - Qinit.resize (nc); - for (octave_idx_type i = 0; i < nc; i++) - Qinit (i) = i; - } - if (arg.is_real_type ()) { + SparseMatrix m = arg.sparse_matrix_value (); - switch (nargout) + if ( nargout < 4 ) { - case 0: - case 1: - case 2: - { - SparseLU fact (m, Qinit, thres, false, true); + + ColumnVector Qinit; + Qinit.resize (nc); + for (octave_idx_type i = 0; i < nc; i++) + Qinit (i) = i; + SparseLU fact (m, Qinit, thres, false, true); - if (nargout < 2) + if ( nargout < 2 ) retval(0) = fact.Y (); - else - { - PermMatrix P = fact.Pr_mat (); - SparseMatrix L = P.transpose () * fact.L (); - retval(1) = octave_value (fact.U (), - MatrixType (MatrixType::Upper)); + else + { + + retval(1) + = octave_value ( + fact.U () * fact.Pc_mat ().transpose (), + MatrixType (MatrixType::Permuted_Upper, + nc, fact.col_perm ())); - retval(0) - = octave_value (L, MatrixType (MatrixType::Permuted_Lower, - nr, fact.row_perm ())); - } - } - break; - - case 3: - { - SparseLU fact (m, Qinit, thres, false, true); + PermMatrix P = fact.Pr_mat (); + SparseMatrix L = fact.L (); + if ( nargout < 3 ) + retval(0) + = octave_value ( P.transpose () * L, + MatrixType (MatrixType::Permuted_Lower, + nr, fact.row_perm ())); + else + { + retval(0) = L; + if ( vecout ) + retval(2) = fact.Pr_vec(); + else + retval(2) = P; + } - if (vecout) - retval(2) = fact.Pr_vec (); - else - retval(2) = fact.Pr_mat (); + } - retval(1) = octave_value (fact.U (), - MatrixType (MatrixType::Upper)); - retval(0) = octave_value (fact.L (), - MatrixType (MatrixType::Lower)); - } - break; + } + else + { - case 4: - default: - { SparseLU fact (m, thres, scale); if (scale) @@ -280,57 +272,57 @@ MatrixType (MatrixType::Upper)); retval(0) = octave_value (fact.L (), MatrixType (MatrixType::Lower)); - } - break; } + } else if (arg.is_complex_type ()) { SparseComplexMatrix m = arg.sparse_complex_matrix_value (); - switch (nargout) + if ( nargout < 4 ) { - case 0: - case 1: - case 2: - { - SparseComplexLU fact (m, Qinit, thres, false, true); + + ColumnVector Qinit; + Qinit.resize (nc); + for (octave_idx_type i = 0; i < nc; i++) + Qinit (i) = i; + SparseComplexLU fact (m, Qinit, thres, false, true); + + if ( nargout < 2 ) - if (nargout < 2) retval(0) = fact.Y (); - else - { - PermMatrix P = fact.Pr_mat (); - SparseComplexMatrix L = P.transpose () * fact.L (); - retval(1) = octave_value (fact.U (), - MatrixType (MatrixType::Upper)); + + else + { + + retval(1) + = octave_value ( + fact.U () * fact.Pc_mat ().transpose (), + MatrixType (MatrixType::Permuted_Upper, + nc, fact.col_perm ())); - retval(0) - = octave_value (L, MatrixType (MatrixType::Permuted_Lower, - nr, fact.row_perm ())); - } - } - break; - - case 3: - { - SparseComplexLU fact (m, Qinit, thres, false, true); + PermMatrix P = fact.Pr_mat (); + SparseComplexMatrix L = fact.L (); + if ( nargout < 3 ) + retval(0) + = octave_value ( P.transpose () * L, + MatrixType (MatrixType::Permuted_Lower, + nr, fact.row_perm ())); + else + { + retval(0) = L; + if ( vecout ) + retval(2) = fact.Pr_vec(); + else + retval(2) = P; + } - if (vecout) - retval(2) = fact.Pr_vec (); - else - retval(2) = fact.Pr_mat (); + } - retval(1) = octave_value (fact.U (), - MatrixType (MatrixType::Upper)); - retval(0) = octave_value (fact.L (), - MatrixType (MatrixType::Lower)); - } - break; + } + else + { - case 4: - default: - { SparseComplexLU fact (m, thres, scale); if (scale) @@ -350,9 +342,8 @@ MatrixType (MatrixType::Upper)); retval(0) = octave_value (fact.L (), MatrixType (MatrixType::Lower)); - } - break; } + } else gripe_wrong_type_arg ("lu", arg); @@ -582,6 +573,19 @@ %!error lu () %!error <can not define pivoting threshold> lu ([1, 2; 3, 4], 2) + +%!test +%! Bi = [1 2 3 4 5 2 3 6 7 8 4 5 7 8 9]; +%! Bj = [1 3 4 5 6 7 8 9 11 12 13 14 15 16 17]; +%! Bv = [1 1 1 1 1 1 -1 1 1 1 1 -1 1 -1 1]; +%! B = sparse (Bi, Bj, Bv); +%! [L, U] = lu (B); +%! assert (L*U, B); +%! [L, U, P] = lu(B); +%! assert (P'*L*U, B); +%! [L, U, P, Q] = lu (B); +%! assert (P'*L*U*Q', B); + */ static
--- a/libinterp/corefcn/pr-output.cc +++ b/libinterp/corefcn/pr-output.cc @@ -3979,13 +3979,15 @@ @deftypefnx {Built-in Function} {@var{old_val} =} fixed_point_format (@var{new_val})\n\ @deftypefnx {Built-in Function} {} fixed_point_format (@var{new_val}, \"local\")\n\ Query or set the internal variable that controls whether Octave will\n\ -use a scaled format to print matrix values such that the largest\n\ -element may be written with a single leading digit with the scaling\n\ -factor is printed on the first line of output. For example:\n\ +use a scaled format to print matrix values.\n\ +\n\ +The scaled format prints a scaling factor on the first line of output chosen\n\ +such that the largest matrix element can be written with a single leading\n\ +digit. For example:\n\ \n\ @example\n\ @group\n\ -octave:1> logspace (1, 7, 5)'\n\ +logspace (1, 7, 5)'\n\ ans =\n\ \n\ 1.0e+07 *\n\ @@ -3999,9 +4001,9 @@ @end example\n\ \n\ @noindent\n\ -Notice that first value appears to be zero when it is actually 1. For\n\ -this reason, you should be careful when setting\n\ -@code{fixed_point_format} to a nonzero value.\n\ +Notice that the first value appears to be 0 when it is actually 1. Because\n\ +of the possibilty for confusion you should be careful about enabling\n\ +@code{fixed_point_format}.\n\ \n\ When called from inside a function with the @qcode{\"local\"} option, the\n\ variable is changed locally for the function and any subroutines it calls. \n\
--- a/libinterp/corefcn/rand.cc +++ b/libinterp/corefcn/rand.cc @@ -366,8 +366,8 @@ DEFUN (rand, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} rand (@var{n})\n\ -@deftypefnx {Built-in Function} {} rand (@var{n}, @var{m}, @dots{})\n\ -@deftypefnx {Built-in Function} {} rand ([@var{n} @var{m} @dots{}])\n\ +@deftypefnx {Built-in Function} {} rand (@var{m}, @var{n}, @dots{})\n\ +@deftypefnx {Built-in Function} {} rand ([@var{m} @var{n} @dots{}])\n\ @deftypefnx {Built-in Function} {@var{v} =} rand (\"state\")\n\ @deftypefnx {Built-in Function} {} rand (\"state\", @var{v})\n\ @deftypefnx {Built-in Function} {} rand (\"state\", \"reset\")\n\ @@ -553,8 +553,8 @@ DEFUN (randn, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} randn (@var{n})\n\ -@deftypefnx {Built-in Function} {} randn (@var{n}, @var{m}, @dots{})\n\ -@deftypefnx {Built-in Function} {} randn ([@var{n} @var{m} @dots{}])\n\ +@deftypefnx {Built-in Function} {} randn (@var{m}, @var{n}, @dots{})\n\ +@deftypefnx {Built-in Function} {} randn ([@var{m} @var{n} @dots{}])\n\ @deftypefnx {Built-in Function} {@var{v} =} randn (\"state\")\n\ @deftypefnx {Built-in Function} {} randn (\"state\", @var{v})\n\ @deftypefnx {Built-in Function} {} randn (\"state\", \"reset\")\n\ @@ -625,8 +625,8 @@ DEFUN (rande, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} rande (@var{n})\n\ -@deftypefnx {Built-in Function} {} rande (@var{n}, @var{m}, @dots{})\n\ -@deftypefnx {Built-in Function} {} rande ([@var{n} @var{m} @dots{}])\n\ +@deftypefnx {Built-in Function} {} rande (@var{m}, @var{n}, @dots{})\n\ +@deftypefnx {Built-in Function} {} rande ([@var{m} @var{n} @dots{}])\n\ @deftypefnx {Built-in Function} {@var{v} =} rande (\"state\")\n\ @deftypefnx {Built-in Function} {} rande (\"state\", @var{v})\n\ @deftypefnx {Built-in Function} {} rande (\"state\", \"reset\")\n\ @@ -698,8 +698,8 @@ DEFUN (randg, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} randg (@var{n})\n\ -@deftypefnx {Built-in Function} {} randg (@var{n}, @var{m}, @dots{})\n\ -@deftypefnx {Built-in Function} {} randg ([@var{n} @var{m} @dots{}])\n\ +@deftypefnx {Built-in Function} {} randg (@var{m}, @var{n}, @dots{})\n\ +@deftypefnx {Built-in Function} {} randg ([@var{m} @var{n} @dots{}])\n\ @deftypefnx {Built-in Function} {@var{v} =} randg (\"state\")\n\ @deftypefnx {Built-in Function} {} randg (\"state\", @var{v})\n\ @deftypefnx {Built-in Function} {} randg (\"state\", \"reset\")\n\ @@ -970,8 +970,8 @@ DEFUN (randp, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} randp (@var{l}, @var{n})\n\ -@deftypefnx {Built-in Function} {} randp (@var{l}, @var{n}, @var{m}, @dots{})\n\ -@deftypefnx {Built-in Function} {} randp (@var{l}, [@var{n} @var{m} @dots{}])\n\ +@deftypefnx {Built-in Function} {} randp (@var{l}, @var{m}, @var{n}, @dots{})\n\ +@deftypefnx {Built-in Function} {} randp (@var{l}, [@var{m} @var{n} @dots{}])\n\ @deftypefnx {Built-in Function} {@var{v} =} randp (\"state\")\n\ @deftypefnx {Built-in Function} {} randp (\"state\", @var{v})\n\ @deftypefnx {Built-in Function} {} randp (\"state\", \"reset\")\n\
--- a/libinterp/parse-tree/lex.ll +++ b/libinterp/parse-tree/lex.ll @@ -869,9 +869,8 @@ curr_lexer->string_text += '\v'; } -<DQ_STRING_START>(\.\.\.){S}*{NL} | -<DQ_STRING_START>(\.\.\.){S}*{CCHAR}{ANY_EXCEPT_NL}*{NL} { - curr_lexer->lexer_debug ("<DQ_STRING_START>(\\.\\.\\.){S}*{NL}|<DQ_STRING_START>(\\.\\.\\.){S}*{CCHAR}{ANY_EXCEPT_NL}*{NL}"); +<DQ_STRING_START>(\.\.\.){S}*{NL} { + curr_lexer->lexer_debug ("<DQ_STRING_START>(\\.\\.\\.){S}*{NL}"); static const char *msg = "'...' continuations in double-quoted character strings are obsolete and will not be allowed in a future version of Octave; please use '\\' instead"; @@ -887,9 +886,8 @@ HANDLE_STRING_CONTINUATION; } -<DQ_STRING_START>\\{S}+{NL} | -<DQ_STRING_START>\\{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL} { - curr_lexer->lexer_debug ("<DQ_STRING_START>\\\\{S}+{NL}|<DQ_STRING_START>\\\\{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL}"); +<DQ_STRING_START>\\{S}+{NL} { + curr_lexer->lexer_debug ("<DQ_STRING_START>\\\\{S}+{NL}"); static const char *msg = "white space and comments after continuation markers in double-quoted character strings are obsolete and will not be allowed in a future version of Octave";
--- a/liboctave/numeric/sparse-base-lu.cc +++ b/liboctave/numeric/sparse-base-lu.cc @@ -32,10 +32,10 @@ sparse_base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: Y (void) const { octave_idx_type nr = Lfact.rows (); - octave_idx_type nc = Ufact.rows (); - octave_idx_type rcmin = (nr > nc ? nr : nc); + octave_idx_type nz = Lfact.cols (); + octave_idx_type nc = Ufact.cols (); - lu_type Yout (nr, nc, Lfact.nnz () + Ufact.nnz ()); + lu_type Yout (nr, nc, Lfact.nnz () + Ufact.nnz () - (nr<nz?nr:nz)); octave_idx_type ii = 0; Yout.xcidx (0) = 0; @@ -46,7 +46,7 @@ Yout.xridx (ii) = Ufact.ridx (i); Yout.xdata (ii++) = Ufact.data (i); } - if (j < rcmin) + if (j < nz) { // Note the +1 skips the 1.0 on the diagonal for (octave_idx_type i = Lfact.cidx (j) + 1;
--- a/scripts/general/interp1.m +++ b/scripts/general/interp1.m @@ -22,18 +22,22 @@ ## @deftypefnx {Function File} {@var{yi} =} interp1 (@var{y}, @var{xi}) ## @deftypefnx {Function File} {@var{yi} =} interp1 (@dots{}, @var{method}) ## @deftypefnx {Function File} {@var{yi} =} interp1 (@dots{}, @var{extrap}) +## @deftypefnx {Function File} {@var{yi} =} interp1 (@dots{}, "left") +## @deftypefnx {Function File} {@var{yi} =} interp1 (@dots{}, "right") ## @deftypefnx {Function File} {@var{pp} =} interp1 (@dots{}, "pp") ## -## One-dimensional interpolation. Interpolates to determine the value of -## @var{yi} at the points, @var{xi}. If not specified, @var{x} is taken -## to be the indices of @var{y}. If @var{y} is a matrix or an N-dimensional -## array, the interpolation is performed on each column of @var{y}. +## One-dimensional interpolation. +## +## Interpolate input data to determine the value of @var{yi} at the points +## @var{xi}. If not specified, @var{x} is taken to be the indices of @var{y}. +## If @var{y} is a matrix or an N-dimensional array, the interpolation is +## performed on each column of @var{y}. ## ## Method is one of: ## ## @table @asis ## @item @qcode{"nearest"} -## Return the nearest neighbor. +## Return the nearest neighbor ## ## @item @qcode{"linear"} ## Linear interpolation from nearest neighbors @@ -49,18 +53,19 @@ ## throughout the curve ## @end table ## -## Appending '*' to the start of the above method forces @code{interp1} +## Adding '*' to the start of any method above forces @code{interp1} ## to assume that @var{x} is uniformly spaced, and only @code{@var{x}(1)} ## and @code{@var{x}(2)} are referenced. This is usually faster, ## and is never slower. The default method is @qcode{"linear"}. ## ## If @var{extrap} is the string @qcode{"extrap"}, then extrapolate values -## beyond the endpoints. If @var{extrap} is a number, replace values beyond -## the endpoints with that number. If @var{extrap} is missing, assume NA. +## beyond the endpoints using the current @var{method}. If @var{extrap} is a +## number, then replace values beyond the endpoints with that number. When +## unspecified, @var{extrap} defaults to NA. ## -## If the string argument @qcode{"pp"} is specified, then @var{xi} should not be -## supplied and @code{interp1} returns the piecewise polynomial that -## can later be used with @code{ppval} to evaluate the interpolation. +## If the string argument @qcode{"pp"} is specified, then @var{xi} should not +## be supplied and @code{interp1} returns a piecewise polynomial object. This +## object can later be used with @code{ppval} to evaluate the interpolation. ## There is an equivalence, such that @code{ppval (interp1 (@var{x}, ## @var{y}, @var{method}, @qcode{"pp"}), @var{xi}) == interp1 (@var{x}, @var{y}, ## @var{xi}, @var{method}, @qcode{"extrap"})}. @@ -71,7 +76,7 @@ ## right-continuous. If @var{x} is decreasing, the default discontinuous ## interpolant is left-continuous. ## The continuity condition of the interpolant may be specified by using -## the options, @qcode{"-left"} or @qcode{"-right"}, to select a left-continuous +## the options, @qcode{"left"} or @qcode{"right"}, to select a left-continuous ## or right-continuous interpolant, respectively. ## Discontinuous interpolation is only allowed for @qcode{"nearest"} and ## @qcode{"linear"} methods; in all other cases, the @var{x}-values must be @@ -95,7 +100,7 @@ ## @end group ## @end example ## -## @seealso{interpft} +## @seealso{interpft, interp2, interp3, interpn} ## @end deftypefn ## Author: Paul Kienzle @@ -118,7 +123,7 @@ xi = []; ispp = false; firstnumeric = true; - rightcontinuous = []; + rightcontinuous = NaN; if (nargin > 2) for i = 1:length (varargin) @@ -129,9 +134,9 @@ extrap = "extrap"; elseif (strcmp ("pp", arg)) ispp = true; - elseif (any (strcmp ({"right", "-right"}, arg))) + elseif (strcmp (arg, "right") || strcmp (arg, "-right")) rightcontinuous = true; - elseif (any (strcmp ({"left", "-left"}, arg))) + elseif (strcmp (arg, "left") || strcmp (arg, "-left")) rightcontinuous = false; else method = arg; @@ -181,7 +186,7 @@ y = y(p,:); endif - if (isempty (rightcontinuous)) + if (isnan (rightcontinuous)) ## If not specified, set the continuity condition if (x(end) < x(1)) rightcontinuous = false; @@ -205,9 +210,9 @@ jumps = x(1:end-1) == x(2:end); have_jumps = any (jumps); if (have_jumps) - if (any (strcmp (method, {"nearest", "linear"}))) + if (strcmp (method, "linear") || strcmp (method, ("nearest"))) if (any (jumps(1:nx-2) & jumps(2:nx-1))) - error ("interp1: extra points in discontinuities"); + warning ("interp1: multiple discontinuities at the same X value"); endif else error ("interp1: discontinuities not supported for method '%s'", method); @@ -217,6 +222,7 @@ ## Proceed with interpolating by all methods. switch (method) + case "nearest" pp = mkpp ([x(1); (x(1:nx-1)+x(2:nx))/2; x(nx)], shiftdim (y, 1), szy(2:end)); @@ -227,6 +233,7 @@ else yi = ppval (pp, reshape (xi, szx)); endif + case "*nearest" pp = mkpp ([x(1), x(1)+[0.5:(nx-1)]*dx, x(nx)], shiftdim (y, 1), szy(2:end)); @@ -236,19 +243,25 @@ else yi = ppval (pp, reshape (xi, szx)); endif + case "linear" - dy = diff (y); - dx = diff (x); - dx = repmat (dx, [1 size(dy)(2:end)]); - coefs = [(dy./dx).'(:), y(1:nx-1, :).'(:)]; + xx = x; - + yy = y; + nxx = nx; if (have_jumps) ## Omit zero-size intervals. - coefs(jumps, :) = []; + yy(jumps, :) = []; xx(jumps) = []; + nxx = rows (xx); endif + dy = diff (yy); + dx = diff (xx); + dx = repmat (dx, [1 size(dy)(2:end)]); + + coefs = [(dy./dx).'(:), yy(1:nxx-1, :).'(:)]; + pp = mkpp (xx, coefs, szy(2:end)); pp.orient = "first"; @@ -286,6 +299,7 @@ yi = shiftdim (yi, 1); endif endif + case {"spline", "*spline"} if (nx == 2 || starmethod) x = linspace (x(1), x(nx), ny); @@ -302,26 +316,26 @@ yi = shiftdim (yi, 1); endif endif + otherwise error ("interp1: invalid method '%s'", method); + endswitch - if (! ispp) - if (! ischar (extrap)) - ## determine which values are out of range and set them to extrap, - ## unless extrap == "extrap". - minx = min (x(1), x(nx)); - maxx = max (x(1), x(nx)); + if (! ispp && ! ischar (extrap)) + ## determine which values are out of range and set them to extrap, + ## unless extrap == "extrap". + minx = min (x(1), x(nx)); + maxx = max (x(1), x(nx)); - outliers = xi < minx | ! (xi <= maxx); # this catches even NaNs - if (size_equal (outliers, yi)) - yi(outliers) = extrap; - yi = reshape (yi, szx); - elseif (!isvector (yi)) - yi(outliers, :) = extrap; - else - yi(outliers.') = extrap; - endif + outliers = xi < minx | ! (xi <= maxx); # this even catches NaNs + if (size_equal (outliers, yi)) + yi(outliers) = extrap; + yi = reshape (yi, szx); + elseif (! isvector (yi)) + yi(outliers, :) = extrap; + else + yi(outliers.') = extrap; endif endif @@ -388,12 +402,12 @@ %! h = plot (x, interp1 (x1, y1, x), 'b', x1, y1, 'sb'); %! hold on %! g = plot (x, interp1 (x2, y2, x), 'r', x2, y2, '*r'); -%! xlim ([1 3]) -%! legend ([h(1), g(1)], {'left-continous', 'right-continuous'}, ... -%! 'location', 'east') +%! axis ([0.5 3.5 -0.5 1.5]) +%! legend ([h(1), g(1)], {'left-continuous', 'right-continuous'}, ... +%! 'location', 'northwest') %! legend boxoff %! %-------------------------------------------------------- -%! % red curve is left-continuos and blue is right-continuous at x = 2 +%! % red curve is left-continuous and blue is right-continuous at x = 2 ##FIXME: add test for n-d arguments here @@ -594,14 +608,15 @@ ## ENDBLOCK ## ENDBLOCKTEST -%!# test linear extrapolation +## test extrapolation (linear) %!assert (interp1 ([1:5],[3:2:11],[0,6],"linear","extrap"), [1, 13], eps) %!assert (interp1 (xp, yp, [-1, max(xp)+1],"linear",5), [5, 5]) +## Basic sanity checks %!assert (interp1 (1:2,1:2,1.4,"nearest"), 1) %!assert (interp1 (1:2,1:2,1.4,"linear"), 1.4) %!assert (interp1 (1:4,1:4,1.4,"cubic"), 1.4) -%!assert (interp1 (1:2,1:2,1.1, "spline"), 1.1) +%!assert (interp1 (1:2,1:2,1.1,"spline"), 1.1) %!assert (interp1 (1:3,1:3,1.4,"spline"), 1.4) %!assert (interp1 (1:2:4,1:2:4,1.4,"*nearest"), 1) @@ -612,13 +627,22 @@ %!assert (interp1 ([3,2,1],[3,2,2],2.5), 2.5) -%!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap"), [-2,0.5,4,3,1.5]) %!assert (interp1 ([4,4,3,2,0],[0,1,4,2,1],[1.5,4,4.5], "linear"), [1.75,1,NA]) %!assert (interp1 (0:4, 2.5), 1.5) +## Left and Right discontinuities +%!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "right"), [-8,2,4,3,1.5]) +%!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "left"), [-2,0.5,1,1.5,1.5]) + +%% Test input validation %!error interp1 () -%!error interp1 (1,1,1, "linear") -%!error interp1 (1,1,1, "*nearest") -%!error interp1 (1,1,1, "*linear") -%!error interp1 (1:2,1:2,1, "bogus") +%!error interp1 (1,2,3,4,5,6,7) +%!error <table too short> interp1 (1,1,1, "linear") +%!error <table too short> interp1 (1,1,1, "*nearest") +%!error <table too short> interp1 (1,1,1, "*linear") +%!warning <multiple discontinuities> interp1 ([1 1 1 2], [1 2 3 4], 1); +%!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "pchip") +%!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "cubic") +%!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "spline") +%!error <invalid method> interp1 (1:2,1:2,1, "bogus")
--- a/scripts/plot/util/figure.m +++ b/scripts/plot/util/figure.m @@ -99,8 +99,10 @@ endif set (0, "currentfigure", f); - ## When switching to figure N, make figure visible and on top of stack. - if (! init_new_figure) + ## When switching to figure N, make figure visible and on top of stack, + ## unless visibility is explicitly switched off + if (! init_new_figure && ! any (strcmpi (varargin(1:2:end), "visible") + && strcmpi (varargin(2:2:end), "off"))) set (f, "visible", "on"); endif @@ -116,6 +118,11 @@ %! unwind_protect %! assert (hf, gcf); %! assert (isfigure (hf)); +%! hf2 = figure (hf, "visible", "off"); +%! assert (hf, hf2); +%! assert (hf2, gcf); +%! assert (isfigure (hf2)); +%! assert (get (hf2, "visible"), "off"); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect
--- a/scripts/polynomial/ppval.m +++ b/scripts/polynomial/ppval.m @@ -32,7 +32,7 @@ if (nargin != 2) print_usage (); endif - if (! (isstruct (pp) && strcmp (pp.form, "pp"))) + if (! (isstruct (pp) && isfield (pp, "form") && strcmp (pp.form, "pp"))) error ("ppval: first argument must be a pp-form structure"); endif @@ -54,7 +54,7 @@ P = reshape (P, [d, n * k]); P = shiftdim (P, nd); P = reshape (P, [n, k, d]); - Pidx = P(idx(:), :);#2d matrix size x: coefs*prod(d) y: prod(sxi) + Pidx = P(idx(:), :); # 2D matrix size: x = coefs*prod(d), y = prod(sxi) if (isvector (xi)) Pidx = reshape (Pidx, [xn, k, d]); @@ -96,10 +96,9 @@ yi = shiftdim (yi, nd); endif - ## FIXME: Why is this commented out, rather than just removed? - #if (d == 1) - # yi = reshape (yi, sxi); - #endif + if (d == 1) + yi = reshape (yi, sxi); + endif endfunction @@ -111,6 +110,7 @@ %! abserr = 1e-14; %! pp2 = mkpp (b, [c;c], 2); %! xi = [1.1 1.3 1.9 2.1]; +%! %!assert (ppval (pp, 1.1), 1.1, abserr) %!assert (ppval (pp, 2.1), 1.1, abserr) %!assert (ppval (pp, xi), [1.1 1.3 1.9 1.1], abserr) @@ -120,6 +120,8 @@ %!assert (ppval (pp2, xi), [1.1 1.3 1.9 1.1;1.1 1.3 1.9 1.1], abserr) %!assert (ppval (pp2, xi'), [1.1 1.3 1.9 1.1;1.1 1.3 1.9 1.1], abserr) %!assert (size (ppval (pp2, [xi;xi])), [2 2 4]) +%!assert (ppval (mkpp([0 1],1), magic (3)), ones(3,3)) +%! %!test %! breaks = [0, 1, 2, 3]; %! coefs = rand (6, 4); @@ -129,3 +131,11 @@ %! ret(:,:,2) = ppval (pp, breaks'); %! assert (ppval (pp, [breaks',breaks']), ret) +%% Test input validation +%!error ppval () +%!error ppval (1) +%!error ppval (1,2,3) +%!error <argument must be a pp-form structure> ppval (1,2) +%!error <argument must be a pp-form structure> ppval (struct ("a", 1), 2) +%!error <argument must be a pp-form structure> ppval (struct ("form", "ab"), 2) +