changeset 15061:9aab13f6697d classdef

maint: periodic merge of default to classdef
author John W. Eaton <jwe@octave.org>
date Fri, 27 Jul 2012 21:59:10 -0400
parents 56b8eb7c9c04 (current diff) bc61fba0e9fd (diff)
children 069c552587a0
files src/DLD-FUNCTIONS/__contourc__.cc src/DLD-FUNCTIONS/__dispatch__.cc src/DLD-FUNCTIONS/__lin_interpn__.cc src/DLD-FUNCTIONS/__pchip_deriv__.cc src/DLD-FUNCTIONS/__qp__.cc src/DLD-FUNCTIONS/balance.cc src/DLD-FUNCTIONS/besselj.cc src/DLD-FUNCTIONS/betainc.cc src/DLD-FUNCTIONS/bsxfun.cc src/DLD-FUNCTIONS/cellfun.cc src/DLD-FUNCTIONS/colloc.cc src/DLD-FUNCTIONS/conv2.cc src/DLD-FUNCTIONS/daspk.cc src/DLD-FUNCTIONS/dasrt.cc src/DLD-FUNCTIONS/dassl.cc src/DLD-FUNCTIONS/det.cc src/DLD-FUNCTIONS/dlmread.cc src/DLD-FUNCTIONS/dot.cc src/DLD-FUNCTIONS/eig.cc src/DLD-FUNCTIONS/fft.cc src/DLD-FUNCTIONS/fft2.cc src/DLD-FUNCTIONS/fftn.cc src/DLD-FUNCTIONS/filter.cc src/DLD-FUNCTIONS/find.cc src/DLD-FUNCTIONS/gammainc.cc src/DLD-FUNCTIONS/gcd.cc src/DLD-FUNCTIONS/getgrent.cc src/DLD-FUNCTIONS/getpwent.cc src/DLD-FUNCTIONS/getrusage.cc src/DLD-FUNCTIONS/givens.cc src/DLD-FUNCTIONS/hess.cc src/DLD-FUNCTIONS/hex2num.cc src/DLD-FUNCTIONS/inv.cc src/DLD-FUNCTIONS/kron.cc src/DLD-FUNCTIONS/lookup.cc src/DLD-FUNCTIONS/lsode.cc src/DLD-FUNCTIONS/lu.cc src/DLD-FUNCTIONS/luinc.cc src/DLD-FUNCTIONS/matrix_type.cc src/DLD-FUNCTIONS/max.cc src/DLD-FUNCTIONS/md5sum.cc src/DLD-FUNCTIONS/mgorth.cc src/DLD-FUNCTIONS/nproc.cc src/DLD-FUNCTIONS/pinv.cc src/DLD-FUNCTIONS/quad.cc src/DLD-FUNCTIONS/quadcc.cc src/DLD-FUNCTIONS/qz.cc src/DLD-FUNCTIONS/rand.cc src/DLD-FUNCTIONS/rcond.cc src/DLD-FUNCTIONS/regexp.cc src/DLD-FUNCTIONS/schur.cc src/DLD-FUNCTIONS/spparms.cc src/DLD-FUNCTIONS/sqrtm.cc src/DLD-FUNCTIONS/str2double.cc src/DLD-FUNCTIONS/strfind.cc src/DLD-FUNCTIONS/sub2ind.cc src/DLD-FUNCTIONS/svd.cc src/DLD-FUNCTIONS/syl.cc src/DLD-FUNCTIONS/time.cc src/DLD-FUNCTIONS/tril.cc src/DLD-FUNCTIONS/typecast.cc src/Makefile.am
diffstat 138 files changed, 30179 insertions(+), 30148 deletions(-) [+]
line wrap: on
line diff
--- a/build-aux/mk-opts.pl	Fri Jul 27 17:10:25 2012 -0400
+++ b/build-aux/mk-opts.pl	Fri Jul 27 21:59:10 2012 -0400
@@ -513,7 +513,7 @@
 
 #include "$header"
 
-#include "defun-dld.h"
+#include "defun.h"
 #include "pr-output.h"
 
 #include "oct-obj.h"
@@ -909,11 +909,11 @@
 sub emit_options_function
 {
   print <<"_END_EMIT_OPTIONS_FUNCTION_HDR_";
-DEFUN_DLD ($OPT_FCN_NAME, args, ,
+DEFUN ($OPT_FCN_NAME, args, ,
   "-*- texinfo -*-\\n\\
-\@deftypefn  {Loadable Function} {} $OPT_FCN_NAME ()\\n\\
-\@deftypefnx {Loadable Function} {val =} $OPT_FCN_NAME (\@var{opt})\\n\\
-\@deftypefnx {Loadable Function} {} $OPT_FCN_NAME (\@var{opt}, \@var{val})\\n\\
+\@deftypefn  {Built-in Function} {} $OPT_FCN_NAME ()\\n\\
+\@deftypefnx {Built-in Function} {val =} $OPT_FCN_NAME (\@var{opt})\\n\\
+\@deftypefnx {Built-in Function} {} $OPT_FCN_NAME (\@var{opt}, \@var{val})\\n\\
 $DOC_STRING\\n\\
 \\n\\
 Options include\\n\\
--- a/doc/interpreter/doccheck/aspell-octave.en.pws	Fri Jul 27 17:10:25 2012 -0400
+++ b/doc/interpreter/doccheck/aspell-octave.en.pws	Fri Jul 27 21:59:10 2012 -0400
@@ -450,6 +450,7 @@
 isreal
 issparse
 isvector
+iter
 ith
 iy
 Jacobian
@@ -611,6 +612,7 @@
 nd
 ndgrid
 ne
+Nelder
 neq
 Neudecker
 Neumann
--- a/scripts/help/type.m	Fri Jul 27 17:10:25 2012 -0400
+++ b/scripts/help/type.m	Fri Jul 27 21:59:10 2012 -0400
@@ -118,7 +118,7 @@
 %! typestr = typestr{1}(1:17);
 %! assert (typestr, "var is a variable");
 
-%!assert (type ("dot"){1}, "dot is a dynamically-linked function")
+%!assert (type ("amd"){1}, "amd is a dynamically-linked function")
 %!assert (type ("cat"){1}, "cat is a built-in function")
 %!assert (type ("+"){1}, "+ is an operator")
 %!assert (type ("end"){1}, "end is a keyword")
--- a/scripts/help/which.m	Fri Jul 27 17:10:25 2012 -0400
+++ b/scripts/help/which.m	Fri Jul 27 21:59:10 2012 -0400
@@ -59,8 +59,8 @@
 %! str = which ("ls");
 %! assert (str(end-17:end), strcat ("miscellaneous", filesep (), "ls.m"));
 %!test
-%! str = which ("dot");
-%! assert (str(end-6:end), "dot.oct");
+%! str = which ("amd");
+%! assert (str(end-6:end), "amd.oct");
 
 %!assert (which ("_NO_SUCH_NAME_"), "")
 
--- a/scripts/image/cmunique.m	Fri Jul 27 17:10:25 2012 -0400
+++ b/scripts/image/cmunique.m	Fri Jul 27 21:59:10 2012 -0400
@@ -29,8 +29,8 @@
 ## eliminated.  The output image, @var{Y}, is the original input image with
 ## the indices adjusted to match the new, possibly smaller, colormap.
 ##
-## When the input is an RGB image (an MxNx3 array), the output colormap
-## will contain one entry for every unique color in the original image.  
+## When the input is an RGB image (an @nospell{MxNx3} array), the output
+## colormap will contain one entry for every unique color in the original image.
 ## In the worst case the new map could have as many rows as the number of
 ## pixels in the original image.
 ##
--- a/src/DLD-FUNCTIONS/__contourc__.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,340 +0,0 @@
-/* Contour lines for function evaluated on a grid.
-
-Copyright (C) 2007-2012 Kai Habel
-Copyright (C) 2004, 2007 Shai Ayal
-
-Adapted to an oct file from the stand alone contourl by Victro Munoz
-Copyright (C) 2004 Victor Munoz
-
-Based on contour plot routine (plcont.c) in PLPlot package
-http://plplot.org/
-
-Copyright (C) 1995, 2000, 2001 Maurice LeBrun
-Copyright (C) 2000, 2002 Joao Cardoso
-Copyright (C) 2000, 2001, 2002, 2004  Alan W. Irwin
-Copyright (C) 2004  Andrew Ross
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <cfloat>
-
-#include "quit.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "oct-obj.h"
-
-static Matrix this_contour;
-static Matrix contourc;
-static int elem;
-
-// This is the quanta in which we increase this_contour.
-#define CONTOUR_QUANT 50
-
-// Add a coordinate point (x,y) to this_contour.
-
-static void
-add_point (double x, double y)
-{
-  if (elem % CONTOUR_QUANT == 0)
-    this_contour = this_contour.append (Matrix (2, CONTOUR_QUANT, 0));
-
-  this_contour (0, elem) = x;
-  this_contour (1, elem) = y;
-  elem++;
-}
-
-// Add contents of current contour to contourc.
-// this_contour.cols () - 1;
-
-static void
-end_contour (void)
-{
-  if (elem > 2)
-    {
-      this_contour (1, 0) = elem - 1;
-      contourc = contourc.append (this_contour.extract_n (0, 0, 2, elem));
-    }
-
-  this_contour = Matrix ();
-  elem = 0;
-}
-
-// Start a new contour, and add contents of current one to contourc.
-
-static void
-start_contour (double lvl, double x, double y)
-{
-  end_contour ();
-  this_contour.resize (2, 0);
-  add_point (lvl, 0);
-  add_point (x, y);
-}
-
-static void
-drawcn (const RowVector& X, const RowVector& Y, const Matrix& Z,
-        double lvl, int r, int c, double ct_x, double ct_y,
-        unsigned int start_edge, bool first, charMatrix& mark)
-{
-  double px[4], py[4], pz[4], tmp;
-  unsigned int stop_edge, next_edge, pt[2];
-  int next_r, next_c;
-
-  //get x, y, and z - lvl for current facet
-  px[0] = px[3] = X(c);
-  px[1] = px[2] = X(c+1);
-
-  py[0] = py[1] = Y(r);
-  py[2] = py[3] = Y(r+1);
-
-  pz[3] = Z(r+1, c) - lvl;
-  pz[2] = Z(r+1, c + 1) - lvl;
-  pz[1] = Z(r, c+1) - lvl;
-  pz[0] = Z(r, c) - lvl;
-
-  // Facet edge and point naming assignment.
-  //
-  //  0-----1   .-0-.
-  //  |     |   |   |
-  //  |     |   3   1
-  //  |     |   |   |
-  //  3-----2   .-2-.
-
-  // Get mark value of current facet.
-  char id = static_cast<char> (mark(r, c));
-
-  // Check startedge s.
-  if (start_edge == 255)
-    {
-      // Find start edge.
-      for (unsigned int k = 0; k < 4; k++)
-        if (static_cast<char> (1 << k) & id)
-          start_edge = k;
-    }
-
-  if (start_edge == 255)
-    return;
-
-  // Decrease mark value of current facet for start edge.
-  mark(r, c) -= static_cast<char> (1 << start_edge);
-
-  // Next point (clockwise).
-  pt[0] = start_edge;
-  pt[1] = (pt[0] + 1) % 4;
-
-  // Calculate contour segment start if first of contour.
-  if (first)
-    {
-      tmp = fabs (pz[pt[1]]) / fabs (pz[pt[0]]);
-
-      if (xisnan (tmp))
-        ct_x = ct_y = 0.5;
-      else
-        {
-          ct_x = px[pt[0]] + (px[pt[1]] - px[pt[0]])/(1 + tmp);
-          ct_y = py[pt[0]] + (py[pt[1]] - py[pt[0]])/(1 + tmp);
-        }
-
-      start_contour (lvl, ct_x, ct_y);
-    }
-
-  // Find stop edge.
-  // FIXME -- perhaps this should use a while loop?
-  for (unsigned int k = 1; k <= 4; k++)
-    {
-      if (start_edge == 0 || start_edge == 2)
-        stop_edge = (start_edge + k) % 4;
-      else
-        stop_edge = (start_edge - k) % 4;
-
-      if (static_cast<char> (1 << stop_edge) & id)
-        break;
-    }
-
-  pt[0] = stop_edge;
-  pt[1] = (pt[0] + 1) % 4;
-  tmp = fabs (pz[pt[1]]) / fabs (pz[pt[0]]);
-
-  if (xisnan (tmp))
-    ct_x = ct_y = 0.5;
-  else
-    {
-      ct_x = px[pt[0]] + (px[pt[1]] - px[pt[0]])/(1 + tmp);
-      ct_y = py[pt[0]] + (py[pt[1]] - py[pt[0]])/(1 + tmp);
-    }
-
-  // Add point to contour.
-  add_point (ct_x, ct_y);
-
-  // Decrease id value of current facet for start edge.
-  mark(r, c) -= static_cast<char> (1 << stop_edge);
-
-  // Find next facet.
-  next_c = c;
-  next_r = r;
-
-  if (stop_edge == 0)
-    next_r--;
-  else if (stop_edge == 1)
-    next_c++;
-  else if (stop_edge == 2)
-    next_r++;
-  else if (stop_edge == 3)
-    next_c--;
-
-  // Check if next facet is not done yet.
-  // Go to next facet.
-  if (next_r >= 0 && next_c >= 0 && next_r < mark.rows ()
-      && next_c < mark.cols () && mark(next_r, next_c) > 0)
-    {
-      next_edge = (stop_edge + 2) % 4;
-      drawcn (X, Y, Z, lvl, next_r, next_c, ct_x, ct_y, next_edge, false, mark);
-    }
-}
-
-static void
-mark_facets (const Matrix& Z, charMatrix& mark, double lvl)
-{
-  unsigned int nr = mark.rows ();
-  unsigned int nc = mark.cols ();
-
-  double f[4];
-
-  for (unsigned int c = 0; c < nc; c++)
-    for (unsigned int r = 0; r < nr; r++)
-      {
-        f[0] = Z(r, c) - lvl;
-        f[1] = Z(r, c+1) - lvl;
-        f[3] = Z(r+1, c) - lvl;
-        f[2] = Z(r+1, c+1) - lvl;
-
-        for (unsigned int i = 0; i < 4; i++)
-          if (fabs(f[i]) < DBL_EPSILON)
-            f[i] = DBL_EPSILON;
-
-        if (f[1] * f[2] < 0)
-          mark(r, c) += 2;
-
-        if (f[0] * f[3] < 0)
-          mark(r, c) += 8;
-      }
-
-  for (unsigned int r = 0; r < nr; r++)
-    for (unsigned int c = 0; c < nc; c++)
-      {
-        f[0] = Z(r, c) - lvl;
-        f[1] = Z(r, c+1) - lvl;
-        f[3] = Z(r+1, c) - lvl;
-        f[2] = Z(r+1, c+1) - lvl;
-
-        for (unsigned int i = 0; i < 4; i++)
-          if (fabs(f[i]) < DBL_EPSILON)
-            f[i] = DBL_EPSILON;
-
-        if (f[0] * f[1] < 0)
-          mark(r, c) += 1;
-
-        if (f[2] * f[3] < 0)
-          mark(r, c) += 4;
-      }
-}
-
-static void
-cntr (const RowVector& X, const RowVector& Y, const Matrix& Z, double lvl)
-{
-  unsigned int nr = Z.rows ();
-  unsigned int nc = Z.cols ();
-
-  charMatrix mark (nr - 1, nc - 1, 0);
-
-  mark_facets (Z, mark, lvl);
-
-  // Find contours that start at a domain edge.
-
-  for (unsigned int c = 0; c < nc - 1; c++)
-    {
-      // Top.
-      if (mark(0, c) & 1)
-        drawcn (X, Y, Z, lvl, 0, c, 0.0, 0.0, 0, true, mark);
-
-      // Bottom.
-      if (mark(nr - 2, c) & 4)
-        drawcn (X, Y, Z, lvl, nr - 2, c, 0.0, 0.0, 2, true, mark);
-    }
-
-  for (unsigned int r = 0; r < nr - 1; r++)
-    {
-      // Left.
-      if (mark(r, 0) & 8)
-        drawcn (X, Y, Z, lvl, r, 0, 0.0, 0.0, 3, true, mark);
-
-      // Right.
-      if (mark(r, nc - 2) & 2)
-        drawcn (X, Y, Z, lvl, r, nc - 2, 0.0, 0.0, 1, true, mark);
-    }
-
-  for (unsigned int r = 0; r < nr - 1; r++)
-    for (unsigned int c = 0; c < nc - 1; c++)
-      if (mark (r, c) > 0)
-        drawcn (X, Y, Z, lvl, r, c, 0.0, 0.0, 255, true, mark);
-}
-
-DEFUN_DLD (__contourc__, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} __contourc__ (@var{x}, @var{y}, @var{z}, @var{levels})\n\
-Undocumented internal function.\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  if (args.length () == 4)
-    {
-      RowVector X = args (0).row_vector_value ();
-      RowVector Y = args (1).row_vector_value ();
-      Matrix Z = args (2).matrix_value ();
-      RowVector L = args (3).row_vector_value ();
-
-      if (! error_state)
-        {
-          contourc.resize (2, 0);
-
-          for (int i = 0; i < L.length (); i++)
-            cntr (X, Y, Z, L (i));
-
-          end_contour ();
-
-          retval = contourc;
-        }
-      else
-        error ("__contourc__: invalid argument values");
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-## No test needed for internal helper function.
-%!assert (1)
-*/
--- a/src/DLD-FUNCTIONS/__dispatch__.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-/*
-
-Copyright (C) 2001-2012 John W. Eaton and Paul Kienzle
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <list>
-#include <map>
-#include <string>
-
-#include "Cell.h"
-#include "oct-map.h"
-#include "defun-dld.h"
-#include "ov.h"
-#include "ov-fcn.h"
-#include "ov-typeinfo.h"
-#include "pager.h"
-#include "parse.h"
-#include "symtab.h"
-#include "variables.h"
-
-DEFUN_DLD (__dispatch__, args, nargout,
-  "Undocumented internal function")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  std::string f, r, t;
-
-  if (nargin > 0 && nargin < 4)
-    {
-      if (nargin > 0)
-        {
-          f = args(0).string_value ();
-
-          if (error_state)
-            {
-              error ("__dispatch__: first argument must be a function name");
-              return retval;
-            }
-        }
-
-      if (nargin > 1)
-        {
-          r = args(1).string_value ();
-
-          if (error_state)
-            {
-              error ("__dispatch__: second argument must be a function name");
-              return retval;
-            }
-        }
-
-      if (nargin > 2)
-        {
-          t = args(2).string_value ();
-
-          if (error_state)
-            {
-              error ("__dispatch__: third argument must be a type name");
-              return retval;
-            }
-        }
-
-      if (nargin == 1)
-        {
-          if (nargout > 0)
-            {
-              symbol_table::fcn_info::dispatch_map_type dm
-                = symbol_table::get_dispatch (f);
-
-              size_t len = dm.size ();
-
-              Cell type_field (len, 1);
-              Cell name_field (len, 1);
-
-              symbol_table::fcn_info::dispatch_map_type::const_iterator p
-                = dm.begin ();
-
-              for (size_t i = 0; i < len; i++)
-                {
-                  type_field(i) = p->first;
-                  name_field(i) = p->second;
-
-                  p++;
-                }
-
-              octave_scalar_map m;
-
-              m.assign ("type", type_field);
-              m.assign ("name", name_field);
-
-              retval = m;
-            }
-          else
-            symbol_table::print_dispatch (octave_stdout, f);
-        }
-      else if (nargin == 2)
-        {
-          t = r;
-          symbol_table::clear_dispatch (f, t);
-        }
-      else
-        symbol_table::add_dispatch (f, t, r);
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-## No test needed for internal helper function.
-%!assert (1)
-*/
--- a/src/DLD-FUNCTIONS/__lin_interpn__.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,362 +0,0 @@
-/*
-
-Copyright (C) 2007-2012 Alexander Barth
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "lo-ieee.h"
-#include "dNDArray.h"
-#include "oct-locbuf.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "oct-obj.h"
-
-// equivalent to isvector.m
-
-template <class T>
-bool
-isvector (const T& array)
-{
-  const dim_vector dv = array.dims ();
-  return dv.length () == 2 && (dv(0) == 1 || dv(1) == 1);
-}
-
-// lookup a value in a sorted table (lookup.m)
-template <class T>
-octave_idx_type
-lookup (const T *x, octave_idx_type n, T y)
-{
-  octave_idx_type j;
-
-  if (x[0] < x[n-1])
-    {
-      // increasing x
-
-      if (y > x[n-1] || y < x[0])
-        return -1;
-
-#ifdef EXHAUSTIF
-      for (j = 0; j < n - 1; j++)
-        {
-          if (x[j] <= y && y <= x[j+1])
-            return j;
-        }
-#else
-      octave_idx_type j0 = 0;
-      octave_idx_type j1 = n - 1;
-
-      while (true)
-        {
-          j = (j0+j1)/2;
-
-          if (y <= x[j+1])
-            {
-              if (x[j] <= y)
-                return j;
-
-              j1 = j;
-            }
-
-          if (x[j] <= y)
-            j0 = j;
-        }
-#endif
-    }
-  else
-    {
-      // decreasing x
-      // previous code with x -> -x and y -> -y
-
-      if (y > x[0] || y < x[n-1])
-        return -1;
-
-#ifdef EXHAUSTIF
-      for (j = 0; j < n - 1; j++)
-        {
-          if (x[j+1] <= y && y <= x[j])
-            return j;
-        }
-#else
-      octave_idx_type j0 = 0;
-      octave_idx_type j1 = n - 1;
-
-      while (true)
-        {
-          j = (j0+j1)/2;
-
-          if (y >= x[j+1])
-            {
-              if (x[j] >= y)
-                return j;
-
-              j1 = j;
-            }
-
-          if (x[j] >= y)
-            j0 = j;
-        }
-#endif
-    }
-}
-
-// n-dimensional linear interpolation
-
-template <class T>
-void
-lin_interpn (int n, const octave_idx_type *size, const octave_idx_type *scale,
-             octave_idx_type Ni, T extrapval, const T **x,
-             const T *v, const T **y, T *vi)
-{
-  bool out = false;
-  int bit;
-
-  OCTAVE_LOCAL_BUFFER (T, coef, 2*n);
-  OCTAVE_LOCAL_BUFFER (octave_idx_type, index, n);
-
-  // loop over all points
-  for (octave_idx_type m = 0; m < Ni; m++)
-    {
-      // loop over all dimensions
-      for (int i = 0; i < n; i++)
-        {
-          index[i] = lookup (x[i], size[i], y[i][m]);
-          out = index[i] == -1;
-
-          if (out)
-            break;
-          else
-            {
-              octave_idx_type j = index[i];
-              coef[2*i+1] = (y[i][m] - x[i][j])/(x[i][j+1] - x[i][j]);
-              coef[2*i] = 1 - coef[2*i+1];
-            }
-        }
-
-
-      if (out)
-        vi[m] = extrapval;
-      else
-        {
-          vi[m] = 0;
-
-          // loop over all corners of hypercube (1<<n = 2^n)
-          for (int i = 0; i < (1 << n); i++)
-            {
-              T c = 1;
-              octave_idx_type l = 0;
-
-              // loop over all dimensions
-              for (int j = 0; j < n; j++)
-                {
-                  // test if the jth bit in i is set
-                  bit = i >> j & 1;
-                  l += scale[j] * (index[j] + bit);
-                  c *= coef[2*j+bit];
-                }
-
-              vi[m] += c * v[l];
-            }
-        }
-    }
-}
-
-template <class T, class M>
-octave_value
-lin_interpn (int n, M *X, const M V, M *Y)
-{
-  octave_value retval;
-
-  M Vi = M (Y[0].dims ());
-
-  OCTAVE_LOCAL_BUFFER (const T *, y, n);
-  OCTAVE_LOCAL_BUFFER (octave_idx_type, size, n);
-
-  for (int i = 0; i < n; i++)
-    {
-      y[i] = Y[i].data ();
-      size[i] =  V.dims ()(i);
-    }
-
-  OCTAVE_LOCAL_BUFFER (const T *, x, n);
-  OCTAVE_LOCAL_BUFFER (octave_idx_type, scale, n);
-
-  const T *v = V.data ();
-  T *vi = Vi.fortran_vec ();
-  octave_idx_type Ni = Vi.numel ();
-
-  T extrapval = octave_NA;
-
-  // offset in memory of each dimension
-
-  scale[0] = 1;
-
-  for (int i = 1; i < n; i++)
-    scale[i] = scale[i-1] * size[i-1];
-
-  // tests if X[0] is a vector, if yes, assume that all elements of X are
-  // in the ndgrid format.
-
-  if (! isvector (X[0]))
-    {
-      for (int i = 0; i < n; i++)
-        {
-          if (X[i].dims () != V.dims ())
-            {
-              error ("interpn: incompatible size of argument number %d", i+1);
-              return retval;
-            }
-          else
-            {
-              M tmp = M (dim_vector (size[i], 1));
-
-              for (octave_idx_type j = 0; j < size[i]; j++)
-                tmp(j) =  X[i](scale[i]*j);
-
-              X[i] = tmp;
-            }
-        }
-    }
-
-  for (int i = 0; i < n; i++)
-    {
-      if (! isvector (X[i]) && X[i].numel () != size[i])
-        {
-          error ("interpn: incompatible size of argument number %d", i+1);
-          return retval;
-        }
-      else
-        x[i] = X[i].data ();
-    }
-
-  lin_interpn (n, size, scale, Ni, extrapval, x, v, y, vi);
-
-  retval = Vi;
-
-  return retval;
-}
-
-// Perform @var{n}-dimensional interpolation.  Each element of then
-// @var{n}-dimensional array @var{v} represents a value at a location
-// given by the parameters @var{x1}, @var{x2},...,@var{xn}. The parameters
-// @var{x1}, @var{x2}, @dots{}, @var{xn} are either @var{n}-dimensional
-// arrays of the same size as the array @var{v} in the \"ndgrid\" format
-// or vectors.  The parameters @var{y1}, @var{y2}, @dots{}, @var{yn} are
-// all @var{n}-dimensional arrays of the same size and represent the
-// points at which the array @var{vi} is interpolated.
-//
-//This function only performs linear interpolation.
-
-DEFUN_DLD (__lin_interpn__, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{vi} =} __lin_interpn__ (@var{x1}, @var{x2}, @dots{}, @var{xn}, @var{v}, @var{y1}, @var{y2}, @dots{}, @var{yn})\n\
-Undocumented internal function.\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 2 ||  nargin % 2 == 0)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  // dimension of the problem
-  int n = (nargin-1)/2;
-
-  if (args(n).is_single_type ())
-    {
-      OCTAVE_LOCAL_BUFFER (FloatNDArray, X, n);
-      OCTAVE_LOCAL_BUFFER (FloatNDArray, Y, n);
-
-      const FloatNDArray V = args(n).float_array_value ();
-
-      if (error_state)
-        {
-          print_usage ();
-          return retval;
-        }
-
-      for (int i = 0; i < n; i++)
-        {
-          X[i] = args(i).float_array_value ();
-          Y[i] = args(n+i+1).float_array_value ();
-
-          if (error_state)
-            {
-              print_usage ();
-              return retval;
-            }
-
-          if (Y[0].dims () != Y[i].dims ())
-            {
-              error ("interpn: incompatible size of argument number %d", n+i+2);
-              return retval;
-            }
-        }
-
-      retval = lin_interpn<float, FloatNDArray> (n, X, V, Y);
-    }
-  else
-    {
-      OCTAVE_LOCAL_BUFFER (NDArray, X, n);
-      OCTAVE_LOCAL_BUFFER (NDArray, Y, n);
-
-      const NDArray V = args(n).array_value ();
-
-      if (error_state)
-        {
-          print_usage ();
-          return retval;
-        }
-
-      for (int i = 0; i < n; i++)
-        {
-          X[i] = args(i).array_value ();
-          Y[i] = args(n+i+1).array_value ();
-
-          if (error_state)
-            {
-              print_usage ();
-              return retval;
-            }
-
-          if (Y[0].dims () != Y[i].dims ())
-            {
-              error ("interpn: incompatible size of argument number %d", n+i+2);
-              return retval;
-            }
-        }
-
-      retval = lin_interpn<double, NDArray> (n, X, V, Y);
-    }
-
-  return retval;
-}
-
-/*
-## No test needed for internal helper function.
-%!assert (1)
-*/
--- a/src/DLD-FUNCTIONS/__pchip_deriv__.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,168 +0,0 @@
-/*
-
-Copyright (C) 2002-2012 Kai Habel
-Copyright (C) 2008-2009 Jaroslav Hajek
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-#include "f77-fcn.h"
-
-extern "C"
-{
-  F77_RET_T
-  F77_FUNC (dpchim, DPCHIM) (const octave_idx_type& n, const double *x,
-                             const double *f, double *d,
-                             const octave_idx_type &incfd,
-                             octave_idx_type *ierr);
-
-  F77_RET_T
-  F77_FUNC (pchim, PCHIM) (const octave_idx_type& n, const float *x,
-                           const float *f, float *d,
-                           const octave_idx_type& incfd,
-                           octave_idx_type *ierr);
-}
-
-// Wrapper for SLATEC/PCHIP function DPCHIM to calculate the derivates
-// for piecewise polynomials.
-
-DEFUN_DLD (__pchip_deriv__, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} __pchip_deriv__ (@var{x}, @var{y}, @var{dim})\n\
-Undocumented internal function.\n\
-@end deftypefn")
-{
-  octave_value retval;
-  const int nargin = args.length ();
-
-  bool rows = (nargin == 3 && args (2).uint_value () == 2);
-
-  if (nargin >= 2)
-    {
-      if (args(0).is_single_type () || args(1).is_single_type ())
-        {
-          FloatColumnVector xvec (args(0).float_vector_value ());
-          FloatMatrix ymat (args(1).float_matrix_value ());
-
-          octave_idx_type nx = xvec.length ();
-
-          if (nx < 2)
-            {
-              error ("__pchip_deriv__: X must be at least of length 2");
-              return retval;
-            }
-
-          octave_idx_type nyr = ymat.rows ();
-          octave_idx_type nyc = ymat.columns ();
-
-          if (nx != (rows ? nyc : nyr))
-            {
-              error ("__pchip_deriv__: X and Y dimension mismatch");
-              return retval;
-            }
-
-          const float *yvec = ymat.data ();
-          FloatMatrix dmat (nyr, nyc);
-          float *dvec = dmat.fortran_vec ();
-
-          octave_idx_type ierr;
-          const octave_idx_type incfd = rows ? nyr : 1;
-          const octave_idx_type inc = rows ? 1 : nyr;
-
-          for (octave_idx_type i = (rows ? nyr : nyc); i > 0; i--)
-            {
-              F77_FUNC (pchim, PCHIM) (nx, xvec.data (),
-                                       yvec, dvec, incfd, &ierr);
-
-              yvec += inc;
-              dvec += inc;
-
-              if (ierr < 0)
-                {
-                  error ("PCHIM: error: %i\n", ierr);
-                  return retval;
-                }
-            }
-
-          retval = dmat;
-        }
-      else
-        {
-          ColumnVector xvec (args(0).vector_value ());
-          Matrix ymat (args(1).matrix_value ());
-
-          octave_idx_type nx = xvec.length ();
-
-          if (nx < 2)
-            {
-              error ("__pchip_deriv__: X must be at least of length 2");
-              return retval;
-            }
-
-          octave_idx_type nyr = ymat.rows ();
-          octave_idx_type nyc = ymat.columns ();
-
-          if (nx != (rows ? nyc : nyr))
-            {
-              error ("__pchip_deriv__: X and Y dimension mismatch");
-              return retval;
-            }
-
-          const double *yvec = ymat.data ();
-          Matrix dmat (nyr, nyc);
-          double *dvec = dmat.fortran_vec ();
-
-          octave_idx_type ierr;
-          const octave_idx_type incfd = rows ? nyr : 1;
-          const octave_idx_type inc = rows ? 1 : nyr;
-
-          for (octave_idx_type i = (rows ? nyr : nyc); i > 0; i--)
-            {
-              F77_FUNC (dpchim, DPCHIM) (nx, xvec.data (),
-                                         yvec, dvec, incfd, &ierr);
-
-              yvec += inc;
-              dvec += inc;
-
-              if (ierr < 0)
-                {
-                  error ("DPCHIM: error: %i\n", ierr);
-                  return retval;
-                }
-            }
-
-          retval = dmat;
-        }
-    }
-
-  return retval;
-}
-
-/*
-## No test needed for internal helper function.
-%!assert (1)
-*/
--- a/src/DLD-FUNCTIONS/__qp__.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,535 +0,0 @@
-/*
-
-Copyright (C) 2000-2012 Gabriele Pannocchia
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <cfloat>
-
-#include "dbleCHOL.h"
-#include "dbleSVD.h"
-#include "mx-m-dm.h"
-#include "EIG.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "pr-output.h"
-#include "utils.h"
-
-static Matrix
-null (const Matrix& A, octave_idx_type& rank)
-{
-  Matrix retval;
-
-  rank = 0;
-
-  if (! A.is_empty ())
-    {
-      SVD A_svd (A);
-
-      DiagMatrix S = A_svd.singular_values ();
-
-      ColumnVector s = S.diag ();
-
-      Matrix V = A_svd.right_singular_matrix ();
-
-      octave_idx_type A_nr = A.rows ();
-      octave_idx_type A_nc = A.cols ();
-
-      octave_idx_type tmp = A_nr > A_nc ? A_nr : A_nc;
-
-      double tol = tmp * s(0) * DBL_EPSILON;
-
-      octave_idx_type n = s.length ();
-
-      for (octave_idx_type i = 0; i < n; i++)
-        {
-          if (s(i) > tol)
-            rank++;
-        }
-
-      if (rank < A_nc)
-        retval = V.extract (0, rank, A_nc-1, A_nc-1);
-      else
-        retval.resize (A_nc, 0);
-
-      for (octave_idx_type i = 0; i < retval.numel (); i++)
-        if (std::abs (retval(i)) < DBL_EPSILON)
-          retval(i) = 0;
-    }
-
-  return retval;
-}
-
-static int
-qp (const Matrix& H, const ColumnVector& q,
-    const Matrix& Aeq, const ColumnVector& beq,
-    const Matrix& Ain, const ColumnVector& bin,
-    int maxit,
-    ColumnVector& x, ColumnVector& lambda, int& iter)
-{
-  int info = 0;
-
-  iter = 0;
-
-  double rtol = sqrt (DBL_EPSILON);
-
-  // Problem dimension.
-  octave_idx_type n = x.length ();
-
-  // Dimension of constraints.
-  octave_idx_type n_eq = beq.length ();
-  octave_idx_type n_in = bin.length ();
-
-  // Filling the current active set.
-
-  octave_idx_type n_act = n_eq;
-
-  octave_idx_type n_tot = n_eq + n_in;
-
-  // Equality constraints come first.  We won't check the sign of the
-  // Lagrange multiplier for those.
-
-  Matrix Aact = Aeq;
-  ColumnVector bact = beq;
-  ColumnVector Wact;
-
-  if (n_in > 0)
-    {
-      ColumnVector res = Ain*x - bin;
-
-      for (octave_idx_type i = 0; i < n_in; i++)
-        {
-          res(i) /= (1.0 + std::abs (bin(i)));
-
-          if (res(i) < rtol)
-            {
-              n_act++;
-              Aact = Aact.stack (Ain.row (i));
-              bact.resize (n_act, bin(i));
-              Wact.resize (n_act-n_eq, i);
-            }
-        }
-    }
-
-  // Computing the ???
-
-  EIG eigH (H);
-
-  if (error_state)
-    {
-      error ("qp: failed to compute eigenvalues of H");
-      return -1;
-    }
-
-  ColumnVector eigenvalH = real (eigH.eigenvalues ());
-  Matrix eigenvecH = real (eigH.eigenvectors ());
-  double minReal = eigenvalH.min ();
-  octave_idx_type indminR = 0;
-  for (octave_idx_type i = 0; i < n; i++)
-    {
-      if (minReal == eigenvalH(i))
-        {
-          indminR = i;
-          break;
-        }
-    }
-
-  bool done = false;
-
-  double alpha = 0.0;
-
-  Matrix R;
-  Matrix Y (n, 0, 0.0);
-
-  ColumnVector g (n, 0.0);
-  ColumnVector p (n, 0.0);
-
-  ColumnVector lambda_tmp (n_in, 0.0);
-
-  while (! done)
-    {
-      iter++;
-
-      // Current Gradient
-      // g = q + H * x;
-
-      g = q + H * x;
-
-      if (n_act == 0)
-        {
-          // There are no active constraints.
-
-          if (minReal > 0.0)
-            {
-              // Inverting the Hessian.  Using the Cholesky
-              // factorization since the Hessian is positive
-              // definite.
-
-              CHOL cholH (H);
-
-              R = cholH.chol_matrix ();
-
-              Matrix Hinv = chol2inv (R);
-
-              // Computing the unconstrained step.
-              // p = -Hinv * g;
-
-              p = -Hinv * g;
-
-              info = 0;
-            }
-          else
-            {
-              // Finding the negative curvature of H.
-
-              p = eigenvecH.column (indminR);
-
-              // Following the negative curvature of H.
-
-              if (p.transpose () * g > DBL_EPSILON)
-                p = -p;
-
-              info = 1;
-            }
-
-          // Multipliers are zero.
-          lambda_tmp.fill (0.0);
-        }
-      else
-        {
-          // There are active constraints.
-
-          // Computing the null space.
-
-          octave_idx_type rank;
-
-          Matrix Z = null (Aact, rank);
-
-          octave_idx_type dimZ = n - rank;
-
-          // FIXME -- still remain to handle the case of
-          // non-full rank active set matrix.
-
-          // Computing the Y matrix (orthogonal to Z)
-          Y = Aact.pseudo_inverse ();
-
-          // Reduced Hessian
-          Matrix Zt = Z.transpose ();
-          Matrix rH = Zt * H * Z;
-
-          octave_idx_type pR = 0;
-
-          if (dimZ > 0)
-            {
-              // Computing the Cholesky factorization (pR = 0 means
-              // that the reduced Hessian was positive definite).
-
-              CHOL cholrH (rH, pR);
-              Matrix tR = cholrH.chol_matrix ();
-              if (pR == 0)
-                R = tR;
-            }
-
-          if (pR == 0)
-            {
-              info = 0;
-
-              // Computing the step pz.
-              if (dimZ > 0)
-                {
-                  // Using the Cholesky factorization to invert rH
-
-                  Matrix rHinv = chol2inv (R);
-
-                  ColumnVector pz = -rHinv * Zt * g;
-
-                  // Global step.
-                  p = Z * pz;
-                }
-              else
-                {
-                  // Global step.
-                  p.fill (0.0);
-                }
-            }
-          else
-            {
-              info = 1;
-
-              // Searching for the most negative curvature.
-
-              EIG eigrH (rH);
-
-              if (error_state)
-                {
-                  error ("qp: failed to compute eigenvalues of rH");
-                  return -1;
-                }
-
-              ColumnVector eigenvalrH = real (eigrH.eigenvalues ());
-              Matrix eigenvecrH = real (eigrH.eigenvectors ());
-              double mRrH = eigenvalrH.min ();
-              indminR = 0;
-              for (octave_idx_type i = 0; i < n; i++)
-                {
-                  if (mRrH == eigenvalH(i))
-                    {
-                      indminR = i;
-                      break;
-                    }
-                }
-
-              ColumnVector eVrH = eigenvecrH.column (indminR);
-
-              // Computing the step pz.
-              p = Z * eVrH;
-
-              if (p.transpose () * g > DBL_EPSILON)
-                p = -p;
-            }
-        }
-
-      // Checking the step-size.
-      ColumnVector abs_p (n);
-      for (octave_idx_type i = 0; i < n; i++)
-        abs_p(i) = std::abs (p(i));
-      double max_p = abs_p.max ();
-
-      if (max_p < rtol)
-        {
-          // The step is null.  Checking constraints.
-          if (n_act - n_eq == 0)
-            // Solution is found because no inequality
-            // constraints are active.
-            done = true;
-          else
-            {
-              // Computing the multipliers only for the inequality
-              // constraints that are active.  We do NOT compute
-              // multipliers for the equality constraints.
-              Matrix Yt = Y.transpose ();
-              Yt = Yt.extract_n (n_eq, 0, n_act-n_eq, n);
-              lambda_tmp = Yt * (g + H * p);
-
-              // Checking the multipliers.  We remove the most
-              // negative from the set (if any).
-              double min_lambda = lambda_tmp.min ();
-              if (min_lambda >= 0)
-                {
-                  // Solution is found.
-                  done = true;
-                }
-              else
-                {
-                  octave_idx_type which_eig = 0;
-                  for (octave_idx_type i = 0; i < n_act; i++)
-                    {
-                      if (lambda_tmp(i) == min_lambda)
-                        {
-                          which_eig = i;
-                          break;
-                        }
-                    }
-
-                  // At least one multiplier is negative, we
-                  // remove it from the set.
-
-                  n_act--;
-                  for (octave_idx_type i = which_eig; i < n_act - n_eq; i++)
-                    {
-                      Wact(i) = Wact(i+1);
-                      for (octave_idx_type j = 0; j < n; j++)
-                        Aact(n_eq+i,j) = Aact(n_eq+i+1,j);
-                      bact(n_eq+i) = bact(n_eq+i+1);
-                    }
-
-                  // Resizing the active set.
-                  Wact.resize (n_act-n_eq);
-                  bact.resize (n_act);
-                  Aact.resize (n_act, n);
-                }
-            }
-        }
-      else
-        {
-          // The step is not null.
-          if (n_act - n_eq == n_in)
-            {
-              // All inequality constraints were active.  We can
-              // add the whole step.
-              x += p;
-            }
-          else
-            {
-              // Some constraints were not active.  Checking if
-              // there is a blocking constraint.
-              alpha = 1.0;
-              octave_idx_type is_block = -1;
-
-              for (octave_idx_type i = 0; i < n_in; i++)
-                {
-                  bool found = false;
-
-                  for (octave_idx_type j = 0; j < n_act-n_eq; j++)
-                    {
-                      if (Wact(j) == i)
-                        {
-                          found = true;
-                          break;
-                        }
-                    }
-
-                  if (! found)
-                    {
-                      // The i-th constraint was not in the set.  Is it a
-                      // blocking constraint?
-
-                      RowVector tmp_row = Ain.row (i);
-                      double tmp = tmp_row * p;
-                      double res = tmp_row * x;
-
-                      if (tmp < 0.0)
-                        {
-                          double alpha_tmp = (bin(i) - res) / tmp;
-
-                          if (alpha_tmp < alpha)
-                            {
-                              alpha = alpha_tmp;
-                              is_block = i;
-                            }
-                        }
-                    }
-                }
-
-              // In is_block there is the index of the blocking
-              // constraint (if any).
-              if (is_block >= 0)
-                {
-                  // There is a blocking constraint (index in
-                  // is_block) which is added to the active set.
-                  n_act++;
-                  Aact = Aact.stack (Ain.row (is_block));
-                  bact.resize (n_act, bin(is_block));
-                  Wact.resize (n_act-n_eq, is_block);
-
-                  // Adding the reduced step
-                  x += alpha * p;
-                }
-              else
-                {
-                  // There are no blocking constraints.  Adding the
-                  // whole step.
-                  x += alpha * p;
-                }
-            }
-        }
-
-      if (iter == maxit)
-        {
-          done = true;
-          // warning ("qp_main: maximum number of iteration reached");
-          info = 3;
-        }
-    }
-
-  lambda_tmp = Y.transpose () * (g + H * p);
-
-  // Reordering the Lagrange multipliers.
-
-  lambda.resize (n_tot);
-  lambda.fill (0.0);
-  for (octave_idx_type i = 0; i < n_eq; i++)
-    lambda(i) = lambda_tmp(i);
-
-  for (octave_idx_type i = n_eq; i < n_tot; i++)
-    {
-      for (octave_idx_type j = 0; j < n_act-n_eq; j++)
-        {
-          if (Wact(j) == i - n_eq)
-            {
-              lambda(i) = lambda_tmp(n_eq+j);
-              break;
-            }
-        }
-    }
-
-  return info;
-}
-
-DEFUN_DLD (__qp__, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{x}, @var{lambda}, @var{info}, @var{iter}] =} __qp__ (@var{x0}, @var{H}, @var{q}, @var{Aeq}, @var{beq}, @var{Ain}, @var{bin}, @var{maxit})\n\
-Undocumented internal function.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  if (args.length () == 8)
-    {
-      const ColumnVector x0  (args(0) . vector_value ());
-      const Matrix H         (args(1) . matrix_value ());
-      const ColumnVector q   (args(2) . vector_value ());
-      const Matrix Aeq       (args(3) . matrix_value ());
-      const ColumnVector beq (args(4) . vector_value ());
-      const Matrix Ain       (args(5) . matrix_value ());
-      const ColumnVector bin (args(6) . vector_value ());
-      const int maxit        (args(7) . int_value ());
-
-      if (! error_state)
-        {
-          int iter = 0;
-
-          // Copying the initial guess in the working variable
-          ColumnVector x = x0;
-
-          // Reordering the Lagrange multipliers
-          ColumnVector lambda;
-
-          int info = qp (H, q, Aeq, beq, Ain, bin, maxit, x, lambda, iter);
-
-          if (! error_state)
-            {
-              retval(3) = iter;
-              retval(2) = info;
-              retval(1) = lambda;
-              retval(0) = x;
-            }
-          else
-            error ("qp: internal error");
-        }
-      else
-        error ("__qp__: invalid arguments");
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-## No test needed for internal helper function.
-%!assert (1)
-*/
--- a/src/DLD-FUNCTIONS/balance.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,389 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-Copyright (C) 2008-2009 Jaroslav Hajek
-
-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/>.
-
-*/
-
-// Author: A. S. Hodel <scotte@eng.auburn.edu>
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-
-#include "CmplxAEPBAL.h"
-#include "fCmplxAEPBAL.h"
-#include "dbleAEPBAL.h"
-#include "floatAEPBAL.h"
-#include "CmplxGEPBAL.h"
-#include "fCmplxGEPBAL.h"
-#include "dbleGEPBAL.h"
-#include "floatGEPBAL.h"
-#include "quit.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "f77-fcn.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-DEFUN_DLD (balance, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{AA} =} balance (@var{A})\n\
-@deftypefnx {Loadable Function} {@var{AA} =} balance (@var{A}, @var{opt})\n\
-@deftypefnx {Loadable Function} {[@var{DD}, @var{AA}] =} balance (@var{A}, @var{opt})\n\
-@deftypefnx {Loadable Function} {[@var{D}, @var{P}, @var{AA}] =} balance (@var{A}, @var{opt})\n\
-@deftypefnx {Loadable Function} {[@var{CC}, @var{DD}, @var{AA}, @var{BB}] =} balance (@var{A}, @var{B}, @var{opt})\n\
-\n\
-Compute @code{@var{AA} = @var{DD} \\ @var{A} * @var{DD}} in which @var{AA}\n\
-is a matrix whose row and column norms are roughly equal in magnitude, and\n\
-@code{@var{DD} = @var{P} * @var{D}}, in which @var{P} is a permutation\n\
-matrix and @var{D} is a diagonal matrix of powers of two.  This allows the\n\
-equilibration to be computed without round-off.  Results of eigenvalue\n\
-calculation are typically improved by balancing first.\n\
-\n\
-If two output values are requested, @code{balance} returns\n\
-the diagonal @var{D} and the permutation @var{P} separately as vectors.\n\
-In this case, @code{@var{DD} = eye(n)(:,@var{P}) * diag (@var{D})}, where\n\
-@math{n} is the matrix size.\n\
-\n\
-If four output values are requested, compute @code{@var{AA} =\n\
-@var{CC}*@var{A}*@var{DD}} and @code{@var{BB} = @var{CC}*@var{B}*@var{DD}},\n\
-in which @var{AA} and @var{BB} have non-zero elements of approximately the\n\
-same magnitude and @var{CC} and @var{DD} are permuted diagonal matrices as\n\
-in @var{DD} for the algebraic eigenvalue problem.\n\
-\n\
-The eigenvalue balancing option @var{opt} may be one of:\n\
-\n\
-@table @asis\n\
-@item \"noperm\", \"S\"\n\
-Scale only; do not permute.\n\
-\n\
-@item \"noscal\", \"P\"\n\
-Permute only; do not scale.\n\
-@end table\n\
-\n\
-Algebraic eigenvalue balancing uses standard @sc{lapack} routines.\n\
-\n\
-Generalized eigenvalue problem balancing uses Ward's algorithm\n\
-(SIAM Journal on Scientific and Statistical Computing, 1981).\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 1 || nargin > 3 || nargout < 0 || nargout > 4)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  // determine if it's AEP or GEP
-  bool AEPcase = nargin == 1 || args(1).is_string ();
-
-  // problem dimension
-  octave_idx_type nn = args(0).rows ();
-
-  if (nn != args(0).columns ())
-    {
-      gripe_square_matrix_required ("balance");
-      return retval;
-    }
-
-  bool isfloat = args(0).is_single_type () ||
-    (! AEPcase && args(1).is_single_type ());
-
-  bool complex_case = (args(0).is_complex_type () ||
-                       (! AEPcase && args(1).is_complex_type ()));
-
-  // Extract argument 1 parameter for both AEP and GEP.
-  Matrix aa;
-  ComplexMatrix caa;
-  FloatMatrix faa;
-  FloatComplexMatrix fcaa;
-
-  if (isfloat)
-    {
-      if (complex_case)
-        fcaa = args(0).float_complex_matrix_value ();
-      else
-        faa = args(0).float_matrix_value ();
-    }
-  else
-    {
-      if (complex_case)
-        caa = args(0).complex_matrix_value ();
-      else
-        aa = args(0).matrix_value ();
-    }
-
-  if (error_state)
-    return retval;
-
-  // Treat AEP/GEP cases.
-  if (AEPcase)
-    {
-      // Algebraic eigenvalue problem.
-      bool noperm = false, noscal = false;
-      if (nargin > 1)
-        {
-          std::string a1s = args(1).string_value ();
-          noperm = a1s == "noperm" || a1s == "S";
-          noscal = a1s == "noscal" || a1s == "P";
-        }
-
-      // balance the AEP
-      if (isfloat)
-        {
-          if (complex_case)
-            {
-              FloatComplexAEPBALANCE result (fcaa, noperm, noscal);
-
-              if (nargout == 0 || nargout == 1)
-                retval(0) = result.balanced_matrix ();
-              else if (nargout == 2)
-                {
-                  retval(1) = result.balanced_matrix ();
-                  retval(0) = result.balancing_matrix ();
-                }
-              else
-                {
-                  retval(2) = result.balanced_matrix ();
-                  retval(1) = result.permuting_vector ();
-                  retval(0) = result.scaling_vector ();
-                }
-
-            }
-          else
-            {
-              FloatAEPBALANCE result (faa, noperm, noscal);
-
-              if (nargout == 0 || nargout == 1)
-                retval(0) = result.balanced_matrix ();
-              else if (nargout == 2)
-                {
-                  retval(1) = result.balanced_matrix ();
-                  retval(0) = result.balancing_matrix ();
-                }
-              else
-                {
-                  retval(2) = result.balanced_matrix ();
-                  retval(1) = result.permuting_vector ();
-                  retval(0) = result.scaling_vector ();
-                }
-            }
-        }
-      else
-        {
-          if (complex_case)
-            {
-              ComplexAEPBALANCE result (caa, noperm, noscal);
-
-              if (nargout == 0 || nargout == 1)
-                retval(0) = result.balanced_matrix ();
-              else if (nargout == 2)
-                {
-                  retval(1) = result.balanced_matrix ();
-                  retval(0) = result.balancing_matrix ();
-                }
-              else
-                {
-                  retval(2) = result.balanced_matrix ();
-                  retval(1) = result.permuting_vector ();
-                  retval(0) = result.scaling_vector ();
-                }
-            }
-          else
-            {
-              AEPBALANCE result (aa, noperm, noscal);
-
-              if (nargout == 0 || nargout == 1)
-                retval(0) = result.balanced_matrix ();
-              else if (nargout == 2)
-                {
-                  retval(1) = result.balanced_matrix ();
-                  retval(0) = result.balancing_matrix ();
-                }
-              else
-                {
-                  retval(2) = result.balanced_matrix ();
-                  retval(1) = result.permuting_vector ();
-                  retval(0) = result.scaling_vector ();
-                }
-            }
-        }
-    }
-  else
-    {
-      std::string bal_job;
-      if (nargout == 1)
-        warning ("balance: used GEP, should have two output arguments");
-
-      // Generalized eigenvalue problem.
-      if (nargin == 2)
-        bal_job = "B";
-      else if (args(2).is_string ())
-        bal_job = args(2).string_value ();
-      else
-        {
-          error ("balance: OPT argument must be a string");
-          return retval;
-        }
-
-      if ((nn != args(1).columns ()) || (nn != args(1).rows ()))
-        {
-          gripe_nonconformant ();
-          return retval;
-        }
-
-      Matrix bb;
-      ComplexMatrix cbb;
-      FloatMatrix fbb;
-      FloatComplexMatrix fcbb;
-
-      if (isfloat)
-        {
-          if (complex_case)
-            fcbb = args(1).float_complex_matrix_value ();
-          else
-            fbb = args(1).float_matrix_value ();
-        }
-      else
-        {
-          if (complex_case)
-            cbb = args(1).complex_matrix_value ();
-          else
-            bb = args(1).matrix_value ();
-        }
-
-      // balance the GEP
-      if (isfloat)
-        {
-          if (complex_case)
-            {
-              FloatComplexGEPBALANCE result (fcaa, fcbb, bal_job);
-
-              switch (nargout)
-                {
-                case 4:
-                  retval(3) = result.balanced_matrix2 ();
-                  // fall through
-                case 3:
-                  retval(2) = result.balanced_matrix ();
-                  retval(1) = result.balancing_matrix2 ();
-                  retval(0) = result.balancing_matrix ();
-                  break;
-                case 2:
-                  retval(1) = result.balancing_matrix2 ();
-                  // fall through
-                case 1:
-                  retval(0) = result.balancing_matrix ();
-                  break;
-                default:
-                  error ("balance: invalid number of output arguments");
-                  break;
-                }
-            }
-          else
-            {
-              FloatGEPBALANCE result (faa, fbb, bal_job);
-
-              switch (nargout)
-                {
-                case 4:
-                  retval(3) = result.balanced_matrix2 ();
-                  // fall through
-                case 3:
-                  retval(2) = result.balanced_matrix ();
-                  retval(1) = result.balancing_matrix2 ();
-                  retval(0) = result.balancing_matrix ();
-                  break;
-                case 2:
-                  retval(1) = result.balancing_matrix2 ();
-                  // fall through
-                case 1:
-                  retval(0) = result.balancing_matrix ();
-                  break;
-                default:
-                  error ("balance: invalid number of output arguments");
-                  break;
-                }
-            }
-        }
-      else
-        {
-          if (complex_case)
-            {
-              ComplexGEPBALANCE result (caa, cbb, bal_job);
-
-              switch (nargout)
-                {
-                case 4:
-                  retval(3) = result.balanced_matrix2 ();
-                  // fall through
-                case 3:
-                  retval(2) = result.balanced_matrix ();
-                  retval(1) = result.balancing_matrix2 ();
-                  retval(0) = result.balancing_matrix ();
-                  break;
-                case 2:
-                  retval(1) = result.balancing_matrix2 ();
-                  // fall through
-                case 1:
-                  retval(0) = result.balancing_matrix ();
-                  break;
-                default:
-                  error ("balance: invalid number of output arguments");
-                  break;
-                }
-            }
-          else
-            {
-              GEPBALANCE result (aa, bb, bal_job);
-
-              switch (nargout)
-                {
-                case 4:
-                  retval(3) = result.balanced_matrix2 ();
-                  // fall through
-                case 3:
-                  retval(2) = result.balanced_matrix ();
-                  retval(1) = result.balancing_matrix2 ();
-                  retval(0) = result.balancing_matrix ();
-                  break;
-                case 2:
-                  retval(1) = result.balancing_matrix2 ();
-                  // fall through
-                case 1:
-                  retval(0) = result.balancing_matrix ();
-                  break;
-                default:
-                  error ("balance: invalid number of output arguments");
-                  break;
-                }
-            }
-        }
-    }
-
-  return retval;
-}
--- a/src/DLD-FUNCTIONS/besselj.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1246 +0,0 @@
-/*
-
-Copyright (C) 1997-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "lo-specfun.h"
-#include "quit.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-enum bessel_type
-{
-  BESSEL_J,
-  BESSEL_Y,
-  BESSEL_I,
-  BESSEL_K,
-  BESSEL_H1,
-  BESSEL_H2
-};
-
-#define DO_BESSEL(type, alpha, x, scaled, ierr, result) \
-  do \
-    { \
-      switch (type) \
-        { \
-          case BESSEL_J: \
-            result = besselj (alpha, x, scaled, ierr); \
-            break; \
- \
-          case BESSEL_Y: \
-            result = bessely (alpha, x, scaled, ierr); \
-            break; \
- \
-          case BESSEL_I: \
-            result = besseli (alpha, x, scaled, ierr); \
-            break; \
- \
-          case BESSEL_K: \
-            result = besselk (alpha, x, scaled, ierr); \
-            break; \
- \
-          case BESSEL_H1: \
-            result = besselh1 (alpha, x, scaled, ierr); \
-            break; \
- \
-          case BESSEL_H2: \
-            result = besselh2 (alpha, x, scaled, ierr); \
-            break; \
- \
-          default: \
-            break; \
-        } \
-    } \
-  while (0)
-
-static void
-gripe_bessel_arg (const char *fn, const char *arg)
-{
-  error ("%s: expecting scalar or matrix as %s argument", fn, arg);
-}
-
-octave_value_list
-do_bessel (enum bessel_type type, const char *fn,
-           const octave_value_list& args, int nargout)
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin == 2 || nargin == 3)
-    {
-      bool scaled = (nargin == 3);
-
-      octave_value alpha_arg = args(0);
-      octave_value x_arg = args(1);
-
-      if (alpha_arg.is_single_type () || x_arg.is_single_type ())
-        {
-          if (alpha_arg.is_scalar_type ())
-            {
-              float alpha = args(0).float_value ();
-
-              if (! error_state)
-                {
-                  if (x_arg.is_scalar_type ())
-                    {
-                      FloatComplex x = x_arg.float_complex_value ();
-
-                      if (! error_state)
-                        {
-                          octave_idx_type ierr;
-                          octave_value result;
-
-                          DO_BESSEL (type, alpha, x, scaled, ierr, result);
-
-                          if (nargout > 1)
-                            retval(1) = static_cast<float> (ierr);
-
-                          retval(0) = result;
-                        }
-                      else
-                        gripe_bessel_arg (fn, "second");
-                    }
-                  else
-                    {
-                      FloatComplexNDArray x = x_arg.float_complex_array_value ();
-
-                      if (! error_state)
-                        {
-                          Array<octave_idx_type> ierr;
-                          octave_value result;
-
-                          DO_BESSEL (type, alpha, x, scaled, ierr, result);
-
-                          if (nargout > 1)
-                            retval(1) = NDArray (ierr);
-
-                          retval(0) = result;
-                        }
-                      else
-                        gripe_bessel_arg (fn, "second");
-                    }
-                }
-              else
-                gripe_bessel_arg (fn, "first");
-            }
-          else
-            {
-              dim_vector dv0 = args(0).dims ();
-              dim_vector dv1 = args(1).dims ();
-
-              bool args0_is_row_vector = (dv0 (1) == dv0.numel ());
-              bool args1_is_col_vector = (dv1 (0) == dv1.numel ());
-
-              if (args0_is_row_vector && args1_is_col_vector)
-                {
-                  FloatRowVector ralpha = args(0).float_row_vector_value ();
-
-                  if (! error_state)
-                    {
-                      FloatComplexColumnVector cx =
-                        x_arg.float_complex_column_vector_value ();
-
-                      if (! error_state)
-                        {
-                          Array<octave_idx_type> ierr;
-                          octave_value result;
-
-                          DO_BESSEL (type, ralpha, cx, scaled, ierr, result);
-
-                          if (nargout > 1)
-                            retval(1) = NDArray (ierr);
-
-                          retval(0) = result;
-                        }
-                      else
-                        gripe_bessel_arg (fn, "second");
-                    }
-                  else
-                    gripe_bessel_arg (fn, "first");
-                }
-              else
-                {
-                  FloatNDArray alpha = args(0).float_array_value ();
-
-                  if (! error_state)
-                    {
-                      if (x_arg.is_scalar_type ())
-                        {
-                          FloatComplex x = x_arg.float_complex_value ();
-
-                          if (! error_state)
-                            {
-                              Array<octave_idx_type> ierr;
-                              octave_value result;
-
-                              DO_BESSEL (type, alpha, x, scaled, ierr, result);
-
-                              if (nargout > 1)
-                                retval(1) = NDArray (ierr);
-
-                              retval(0) = result;
-                            }
-                          else
-                            gripe_bessel_arg (fn, "second");
-                        }
-                      else
-                        {
-                          FloatComplexNDArray x = x_arg.float_complex_array_value ();
-
-                          if (! error_state)
-                            {
-                              Array<octave_idx_type> ierr;
-                              octave_value result;
-
-                              DO_BESSEL (type, alpha, x, scaled, ierr, result);
-
-                              if (nargout > 1)
-                                retval(1) = NDArray (ierr);
-
-                              retval(0) = result;
-                            }
-                          else
-                            gripe_bessel_arg (fn, "second");
-                        }
-                    }
-                  else
-                    gripe_bessel_arg (fn, "first");
-                }
-            }
-        }
-      else
-        {
-          if (alpha_arg.is_scalar_type ())
-            {
-              double alpha = args(0).double_value ();
-
-              if (! error_state)
-                {
-                  if (x_arg.is_scalar_type ())
-                    {
-                      Complex x = x_arg.complex_value ();
-
-                      if (! error_state)
-                        {
-                          octave_idx_type ierr;
-                          octave_value result;
-
-                          DO_BESSEL (type, alpha, x, scaled, ierr, result);
-
-                          if (nargout > 1)
-                            retval(1) = static_cast<double> (ierr);
-
-                          retval(0) = result;
-                        }
-                      else
-                        gripe_bessel_arg (fn, "second");
-                    }
-                  else
-                    {
-                      ComplexNDArray x = x_arg.complex_array_value ();
-
-                      if (! error_state)
-                        {
-                          Array<octave_idx_type> ierr;
-                          octave_value result;
-
-                          DO_BESSEL (type, alpha, x, scaled, ierr, result);
-
-                          if (nargout > 1)
-                            retval(1) = NDArray (ierr);
-
-                          retval(0) = result;
-                        }
-                      else
-                        gripe_bessel_arg (fn, "second");
-                    }
-                }
-              else
-                gripe_bessel_arg (fn, "first");
-            }
-          else
-            {
-              dim_vector dv0 = args(0).dims ();
-              dim_vector dv1 = args(1).dims ();
-
-              bool args0_is_row_vector = (dv0 (1) == dv0.numel ());
-              bool args1_is_col_vector = (dv1 (0) == dv1.numel ());
-
-              if (args0_is_row_vector && args1_is_col_vector)
-                {
-                  RowVector ralpha = args(0).row_vector_value ();
-
-                  if (! error_state)
-                    {
-                      ComplexColumnVector cx =
-                        x_arg.complex_column_vector_value ();
-
-                      if (! error_state)
-                        {
-                          Array<octave_idx_type> ierr;
-                          octave_value result;
-
-                          DO_BESSEL (type, ralpha, cx, scaled, ierr, result);
-
-                          if (nargout > 1)
-                            retval(1) = NDArray (ierr);
-
-                          retval(0) = result;
-                        }
-                      else
-                        gripe_bessel_arg (fn, "second");
-                    }
-                  else
-                    gripe_bessel_arg (fn, "first");
-                }
-              else
-                {
-                  NDArray alpha = args(0).array_value ();
-
-                  if (! error_state)
-                    {
-                      if (x_arg.is_scalar_type ())
-                        {
-                          Complex x = x_arg.complex_value ();
-
-                          if (! error_state)
-                            {
-                              Array<octave_idx_type> ierr;
-                              octave_value result;
-
-                              DO_BESSEL (type, alpha, x, scaled, ierr, result);
-
-                              if (nargout > 1)
-                                retval(1) = NDArray (ierr);
-
-                              retval(0) = result;
-                            }
-                          else
-                            gripe_bessel_arg (fn, "second");
-                        }
-                      else
-                        {
-                          ComplexNDArray x = x_arg.complex_array_value ();
-
-                          if (! error_state)
-                            {
-                              Array<octave_idx_type> ierr;
-                              octave_value result;
-
-                              DO_BESSEL (type, alpha, x, scaled, ierr, result);
-
-                              if (nargout > 1)
-                                retval(1) = NDArray (ierr);
-
-                              retval(0) = result;
-                            }
-                          else
-                            gripe_bessel_arg (fn, "second");
-                        }
-                    }
-                  else
-                    gripe_bessel_arg (fn, "first");
-                }
-            }
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-DEFUN_DLD (besselj, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {[@var{j}, @var{ierr}] =} besselj (@var{alpha}, @var{x}, @var{opt})\n\
-@deftypefnx {Loadable Function} {[@var{y}, @var{ierr}] =} bessely (@var{alpha}, @var{x}, @var{opt})\n\
-@deftypefnx {Loadable Function} {[@var{i}, @var{ierr}] =} besseli (@var{alpha}, @var{x}, @var{opt})\n\
-@deftypefnx {Loadable Function} {[@var{k}, @var{ierr}] =} besselk (@var{alpha}, @var{x}, @var{opt})\n\
-@deftypefnx {Loadable Function} {[@var{h}, @var{ierr}] =} besselh (@var{alpha}, @var{k}, @var{x}, @var{opt})\n\
-Compute Bessel or Hankel functions of various kinds:\n\
-\n\
-@table @code\n\
-@item besselj\n\
-Bessel functions of the first kind.  If the argument @var{opt} is supplied,\n\
-the result is multiplied by @code{exp (-abs (imag (@var{x})))}.\n\
-\n\
-@item bessely\n\
-Bessel functions of the second kind.  If the argument @var{opt} is supplied,\n\
-the result is multiplied by @code{exp (-abs (imag (@var{x})))}.\n\
-\n\
-@item besseli\n\
-\n\
-Modified Bessel functions of the first kind.  If the argument @var{opt} is\n\
-supplied, the result is multiplied by @code{exp (-abs (real (@var{x})))}.\n\
-\n\
-@item besselk\n\
-\n\
-Modified Bessel functions of the second kind.  If the argument @var{opt} is\n\
-supplied, the result is multiplied by @code{exp (@var{x})}.\n\
-\n\
-@item besselh\n\
-Compute Hankel functions of the first (@var{k} = 1) or second (@var{k}\n\
-= 2) kind.  If the argument @var{opt} is supplied, the result is multiplied\n\
-by @code{exp (-I*@var{x})} for @var{k} = 1 or @code{exp (I*@var{x})} for\n\
-@var{k} = 2.\n\
-@end table\n\
-\n\
-If @var{alpha} is a scalar, the result is the same size as @var{x}.\n\
-If @var{x} is a scalar, the result is the same size as @var{alpha}.\n\
-If @var{alpha} is a row vector and @var{x} is a column vector, the\n\
-result is a matrix with @code{length (@var{x})} rows and\n\
-@code{length (@var{alpha})} columns.  Otherwise, @var{alpha} and\n\
-@var{x} must conform and the result will be the same size.\n\
-\n\
-The value of @var{alpha} must be real.  The value of @var{x} may be\n\
-complex.\n\
-\n\
-If requested, @var{ierr} contains the following status information\n\
-and is the same size as the result.\n\
-\n\
-@enumerate 0\n\
-@item\n\
-Normal return.\n\
-\n\
-@item\n\
-Input error, return @code{NaN}.\n\
-\n\
-@item\n\
-Overflow, return @code{Inf}.\n\
-\n\
-@item\n\
-Loss of significance by argument reduction results in less than\n\
-half of machine accuracy.\n\
-\n\
-@item\n\
-Complete loss of significance by argument reduction, return @code{NaN}.\n\
-\n\
-@item\n\
-Error---no computation, algorithm termination condition not met,\n\
-return @code{NaN}.\n\
-@end enumerate\n\
-@end deftypefn")
-{
-  return do_bessel (BESSEL_J, "besselj", args, nargout);
-}
-
-DEFUN_DLD (bessely, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{y}, @var{ierr}] =} bessely (@var{alpha}, @var{x}, @var{opt})\n\
-See besselj.\n\
-@end deftypefn")
-{
-  return do_bessel (BESSEL_Y, "bessely", args, nargout);
-}
-
-DEFUN_DLD (besseli, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{i}, @var{ierr}] =} besseli (@var{alpha}, @var{x}, @var{opt})\n\
-See besselj.\n\
-@end deftypefn")
-{
-  return do_bessel (BESSEL_I, "besseli", args, nargout);
-}
-
-DEFUN_DLD (besselk, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{k}, @var{ierr}] =} besselk (@var{alpha}, @var{x}, @var{opt})\n\
-See besselj.\n\
-@end deftypefn")
-{
-  return do_bessel (BESSEL_K, "besselk", args, nargout);
-}
-
-DEFUN_DLD (besselh, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{h}, @var{ierr}] =} besselh (@var{alpha}, @var{k}, @var{x}, @var{opt})\n\
-See besselj.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin == 2)
-    {
-      retval = do_bessel (BESSEL_H1, "besselh", args, nargout);
-    }
-  else if (nargin == 3 || nargin == 4)
-    {
-      octave_idx_type kind = args(1).int_value ();
-
-      if (! error_state)
-        {
-          octave_value_list tmp_args;
-
-          if (nargin == 4)
-            tmp_args(2) = args(3);
-
-          tmp_args(1) = args(2);
-          tmp_args(0) = args(0);
-
-          if (kind == 1)
-            retval = do_bessel (BESSEL_H1, "besselh", tmp_args, nargout);
-          else if (kind == 2)
-            retval = do_bessel (BESSEL_H2, "besselh", tmp_args, nargout);
-          else
-            error ("besselh: expecting K = 1 or 2");
-        }
-      else
-        error ("besselh: invalid value of K");
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-DEFUN_DLD (airy, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{a}, @var{ierr}] =} airy (@var{k}, @var{z}, @var{opt})\n\
-Compute Airy functions of the first and second kind, and their\n\
-derivatives.\n\
-\n\
-@example\n\
-@group\n\
- K   Function   Scale factor (if 'opt' is supplied)\n\
----  --------   ---------------------------------------\n\
- 0   Ai (Z)     exp ((2/3) * Z * sqrt (Z))\n\
- 1   dAi(Z)/dZ  exp ((2/3) * Z * sqrt (Z))\n\
- 2   Bi (Z)     exp (-abs (real ((2/3) * Z * sqrt (Z))))\n\
- 3   dBi(Z)/dZ  exp (-abs (real ((2/3) * Z * sqrt (Z))))\n\
-@end group\n\
-@end example\n\
-\n\
-The function call @code{airy (@var{z})} is equivalent to\n\
-@code{airy (0, @var{z})}.\n\
-\n\
-The result is the same size as @var{z}.\n\
-\n\
-If requested, @var{ierr} contains the following status information and\n\
-is the same size as the result.\n\
-\n\
-@enumerate 0\n\
-@item\n\
-Normal return.\n\
-\n\
-@item\n\
-Input error, return @code{NaN}.\n\
-\n\
-@item\n\
-Overflow, return @code{Inf}.\n\
-\n\
-@item\n\
-Loss of significance by argument reduction results in less than half\n\
- of machine accuracy.\n\
-\n\
-@item\n\
-Complete loss of significance by argument reduction, return @code{NaN}.\n\
-\n\
-@item\n\
-Error---no computation, algorithm termination condition not met,\n\
-return @code{NaN}.\n\
-@end enumerate\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin > 0 && nargin < 4)
-    {
-      bool scale = (nargin == 3);
-
-      int kind = 0;
-
-      if (nargin > 1)
-        {
-          kind = args(0).int_value ();
-
-          if (! error_state)
-            {
-              if (kind < 0 || kind > 3)
-                error ("airy: expecting K = 0, 1, 2, or 3");
-            }
-          else
-            error ("airy: K must be an integer value");
-        }
-
-      if (! error_state)
-        {
-          int idx = nargin == 1 ? 0 : 1;
-
-          if (args (idx).is_single_type ())
-            {
-              FloatComplexNDArray z = args(idx).float_complex_array_value ();
-
-              if (! error_state)
-                {
-                  Array<octave_idx_type> ierr;
-                  octave_value result;
-
-                  if (kind > 1)
-                    result = biry (z, kind == 3, scale, ierr);
-                  else
-                    result = airy (z, kind == 1, scale, ierr);
-
-                  if (nargout > 1)
-                    retval(1) = NDArray (ierr);
-
-                  retval(0) = result;
-                }
-              else
-                error ("airy: Z must be a complex matrix");
-            }
-          else
-            {
-              ComplexNDArray z = args(idx).complex_array_value ();
-
-              if (! error_state)
-                {
-                  Array<octave_idx_type> ierr;
-                  octave_value result;
-
-                  if (kind > 1)
-                    result = biry (z, kind == 3, scale, ierr);
-                  else
-                    result = airy (z, kind == 1, scale, ierr);
-
-                  if (nargout > 1)
-                    retval(1) = NDArray (ierr);
-
-                  retval(0) = result;
-                }
-              else
-                error ("airy: Z must be a complex matrix");
-            }
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%! # Test values computed with GP/PARI version 2.3.3
-%!
-%!shared alpha, x, jx, yx, ix, kx, nix
-%!
-%! # Bessel functions, even order, positive and negative x
-%! alpha = 2;  x = 1.25;
-%! jx = 0.1710911312405234823613091417;
-%! yx = -1.193199310178553861283790424;
-%! ix = 0.2220184483766341752692212604;
-%! kx = 0.9410016167388185767085460540;
-%!
-%!assert (besselj (alpha,x), jx, 100*eps)
-%!assert (bessely (alpha,x), yx, 100*eps)
-%!assert (besseli (alpha,x), ix, 100*eps)
-%!assert (besselk (alpha,x), kx, 100*eps)
-%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
-%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
-%!
-%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
-%!
-%!assert (besselj (-alpha,x), jx, 100*eps)
-%!assert (bessely (-alpha,x), yx, 100*eps)
-%!assert (besseli (-alpha,x), ix, 100*eps)
-%!assert (besselk (-alpha,x), kx, 100*eps)
-%!assert (besselh (-alpha,1,x), jx + I*yx, 100*eps)
-%!assert (besselh (-alpha,2,x), jx - I*yx, 100*eps)
-%!
-%!assert (besselj (-alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (-alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (-alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (-alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (-alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
-%!
-%! x *= -1;
-%! yx = -1.193199310178553861283790424 + 0.3421822624810469647226182835*I;
-%! kx = 0.9410016167388185767085460540 - 0.6974915263814386815610060884*I;
-%!
-%!assert (besselj (alpha,x), jx, 100*eps)
-%!assert (bessely (alpha,x), yx, 100*eps)
-%!assert (besseli (alpha,x), ix, 100*eps)
-%!assert (besselk (alpha,x), kx, 100*eps)
-%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
-%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
-%!
-%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
-%!
-%! # Bessel functions, odd order, positive and negative x
-%! alpha = 3;  x = 2.5;
-%! jx = 0.2166003910391135247666890035;
-%! yx = -0.7560554967536709968379029772;
-%! ix = 0.4743704087780355895548240179;
-%! kx = 0.2682271463934492027663765197;
-%!
-%!assert (besselj (alpha,x), jx, 100*eps)
-%!assert (bessely (alpha,x), yx, 100*eps)
-%!assert (besseli (alpha,x), ix, 100*eps)
-%!assert (besselk (alpha,x), kx, 100*eps)
-%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
-%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
-%!
-%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
-%!
-%!assert (besselj (-alpha,x), -jx, 100*eps)
-%!assert (bessely (-alpha,x), -yx, 100*eps)
-%!assert (besseli (-alpha,x), ix, 100*eps)
-%!assert (besselk (-alpha,x), kx, 100*eps)
-%!assert (besselh (-alpha,1,x), -(jx + I*yx), 100*eps)
-%!assert (besselh (-alpha,2,x), -(jx - I*yx), 100*eps)
-%!
-%!assert (besselj (-alpha,x,1), -jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (-alpha,x,1), -yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (-alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (-alpha,1,x,1), -(jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (-alpha,2,x,1), -(jx - I*yx)*exp(I*x), 100*eps)
-%!
-%! x *= -1;
-%! jx = -jx;
-%! yx = 0.7560554967536709968379029772 - 0.4332007820782270495333780070*I;
-%! ix = -ix;
-%! kx = -0.2682271463934492027663765197 - 1.490278591297463775542004240*I;
-%!
-%!assert (besselj (alpha,x), jx, 100*eps)
-%!assert (bessely (alpha,x), yx, 100*eps)
-%!assert (besseli (alpha,x), ix, 100*eps)
-%!assert (besselk (alpha,x), kx, 100*eps)
-%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
-%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
-%!
-%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
-%!
-%! # Bessel functions, fractional order, positive and negative x
-%!
-%! alpha = 3.5;  x = 2.75;
-%! jx = 0.1691636439842384154644784389;
-%! yx = -0.8301381935499356070267953387;
-%! ix = 0.3930540878794826310979363668;
-%! kx = 0.2844099013460621170288192503;
-%!
-%!assert (besselj (alpha,x), jx, 100*eps)
-%!assert (bessely (alpha,x), yx, 100*eps)
-%!assert (besseli (alpha,x), ix, 100*eps)
-%!assert (besselk (alpha,x), kx, 100*eps)
-%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
-%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
-%!
-%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
-%!
-%! nix = 0.2119931212254662995364461998;
-%!
-%!assert (besselj (-alpha,x), yx, 100*eps)
-%!assert (bessely (-alpha,x), -jx, 100*eps)
-%!assert (besseli (-alpha,x), nix, 100*eps)
-%!assert (besselk (-alpha,x), kx, 100*eps)
-%!assert (besselh (-alpha,1,x), -I*(jx + I*yx), 100*eps)
-%!assert (besselh (-alpha,2,x), I*(jx - I*yx), 100*eps)
-%!
-%!assert (besselj (-alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (-alpha,x,1), -jx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (-alpha,x,1), nix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (-alpha,1,x,1), -I*(jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (-alpha,2,x,1), I*(jx - I*yx)*exp(I*x), 100*eps)
-%!
-%! x *= -1;
-%! jx *= -I;
-%! yx = -0.8301381935499356070267953387*I;
-%! ix *= -I;
-%! kx = -0.9504059335995575096509874508*I;
-%!
-%!assert (besselj (alpha,x), jx, 100*eps)
-%!assert (bessely (alpha,x), yx, 100*eps)
-%!assert (besseli (alpha,x), ix, 100*eps)
-%!assert (besselk (alpha,x), kx, 100*eps)
-%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
-%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
-%!
-%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
-%!
-%! # Bessel functions, even order, complex x
-%!
-%! alpha = 2;  x = 1.25 + 3.625 * I;
-%! jx = -1.299533366810794494030065917 + 4.370833116012278943267479589*I;
-%! yx = -4.370357232383223896393056727 - 1.283083391453582032688834041*I;
-%! ix = -0.6717801680341515541002273932 - 0.2314623443930774099910228553*I;
-%! kx = -0.01108009888623253515463783379 + 0.2245218229358191588208084197*I;
-%!
-%!assert (besselj (alpha,x), jx, 100*eps)
-%!assert (bessely (alpha,x), yx, 100*eps)
-%!assert (besseli (alpha,x), ix, 100*eps)
-%!assert (besselk (alpha,x), kx, 100*eps)
-%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
-%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
-%!
-%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
-%!
-%!assert (besselj (-alpha,x), jx, 100*eps)
-%!assert (bessely (-alpha,x), yx, 100*eps)
-%!assert (besseli (-alpha,x), ix, 100*eps)
-%!assert (besselk (-alpha,x), kx, 100*eps)
-%!assert (besselh (-alpha,1,x), jx + I*yx, 100*eps)
-%!assert (besselh (-alpha,2,x), jx - I*yx, 100*eps)
-%!
-%!assert (besselj (-alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (-alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (-alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (-alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (-alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
-%!
-%! # Bessel functions, odd order, complex x
-%!
-%! alpha = 3; x = 2.5 + 1.875 * I;
-%! jx = 0.1330721523048277493333458596 + 0.5386295217249660078754395597*I;
-%! yx = -0.6485072392105829901122401551 + 0.2608129289785456797046996987*I;
-%! ix = -0.6182064685486998097516365709 + 0.4677561094683470065767989920*I;
-%! kx = -0.1568585587733540007867882337 - 0.05185853709490846050505141321*I;
-%!
-%!assert (besselj (alpha,x), jx, 100*eps)
-%!assert (bessely (alpha,x), yx, 100*eps)
-%!assert (besseli (alpha,x), ix, 100*eps)
-%!assert (besselk (alpha,x), kx, 100*eps)
-%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
-%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
-%!
-%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
-%!
-%!assert (besselj (-alpha,x), -jx, 100*eps)
-%!assert (bessely (-alpha,x), -yx, 100*eps)
-%!assert (besseli (-alpha,x), ix, 100*eps)
-%!assert (besselk (-alpha,x), kx, 100*eps)
-%!assert (besselh (-alpha,1,x), -(jx + I*yx), 100*eps)
-%!assert (besselh (-alpha,2,x), -(jx - I*yx), 100*eps)
-%!
-%!assert (besselj (-alpha,x,1), -jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (-alpha,x,1), -yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (-alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (-alpha,1,x,1), -(jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (-alpha,2,x,1), -(jx - I*yx)*exp(I*x), 100*eps)
-%!
-%! # Bessel functions, fractional order, complex x
-%!
-%! alpha = 3.5;  x = 1.75 + 4.125 * I;
-%! jx = -3.018566131370455929707009100 - 0.7585648436793900607704057611*I;
-%! yx = 0.7772278839106298215614791107 - 3.018518722313849782683792010*I;
-%! ix = 0.2100873577220057189038160913 - 0.6551765604618246531254970926*I;
-%! kx = 0.1757147290513239935341488069 + 0.08772348296883849205562558311*I;
-%!
-%!assert (besselj (alpha,x), jx, 100*eps)
-%!assert (bessely (alpha,x), yx, 100*eps)
-%!assert (besseli (alpha,x), ix, 100*eps)
-%!assert (besselk (alpha,x), kx, 100*eps)
-%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
-%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
-%!
-%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
-%!
-%!  nix = 0.09822388691172060573913739253 - 0.7110230642207380127317227407*I;
-%!
-%!assert (besselj (-alpha,x), yx, 100*eps)
-%!assert (bessely (-alpha,x), -jx, 100*eps)
-%!assert (besseli (-alpha,x), nix, 100*eps)
-%!assert (besselk (-alpha,x), kx, 100*eps)
-%!assert (besselh (-alpha,1,x), -I*(jx + I*yx), 100*eps)
-%!assert (besselh (-alpha,2,x), I*(jx - I*yx), 100*eps)
-%!
-%!assert (besselj (-alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
-%!assert (bessely (-alpha,x,1), -jx*exp(-abs(imag(x))), 100*eps)
-%!assert (besseli (-alpha,x,1), nix*exp(-abs(real(x))), 100*eps)
-%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps)
-%!assert (besselh (-alpha,1,x,1), -I*(jx + I*yx)*exp(-I*x), 100*eps)
-%!assert (besselh (-alpha,2,x,1), I*(jx - I*yx)*exp(I*x), 100*eps)
-
-
-Tests contributed by Robert T. Short.
-Tests are based on the properties and tables in A&S:
- Abramowitz and Stegun, "Handbook of Mathematical Functions",
- 1972.
-
-For regular Bessel functions, there are 3 tests. These compare octave
-results against Tables 9.1, 9.2, and 9.4 in A&S. Tables 9.1 and 9.2
-are good to only a few decimal places, so any failures should be
-considered a broken implementation. Table 9.4 is an extended table
-for larger orders and arguments. There are some differences between
-Octave and Table 9.4, mostly in the last decimal place but in a very
-few instances the errors are in the last two places. The comparison
-tolerance has been changed to reflect this.
-
-Similarly for modifed Bessel functions, there are 3 tests. These
-compare octave results against Tables 9.8, 9.9, and 9.11 in A&S.
-Tables 9.8 and 9.9 are good to only a few decimal places, so any
-failures should be considered a broken implementation. Table 9.11 is
-an extended table for larger orders and arguments. There are some
-differences between octave and Table 9.11, mostly in the last decimal
-place but in a very few instances the errors are in the last two
-places. The comparison tolerance has been changed to reflect this.
-
-For spherical Bessel functions, there are also three tests, comparing
-octave results to Tables 10.1, 10.2, and 10.4 in A&S. Very similar
-comments may be made here as in the previous lines. At this time,
-modified spherical Bessel function tests are not included.
-
-% Table 9.1 - J and Y for integer orders 0, 1, 2.
-% Compare against excerpts of Table 9.1, Abramowitz and Stegun.
-%!test
-%! n = 0:2;
-%! z = (0:2.5:17.5)';
-%!
-%! Jt = [[ 1.000000000000000,  0.0000000000,  0.0000000000];
-%!       [-0.048383776468198,  0.4970941025,  0.4460590584];
-%!       [-0.177596771314338, -0.3275791376,  0.0465651163];
-%!       [ 0.266339657880378,  0.1352484276, -0.2302734105];
-%!       [-0.245935764451348,  0.0434727462,  0.2546303137];
-%!       [ 0.146884054700421, -0.1654838046, -0.1733614634];
-%!       [-0.014224472826781,  0.2051040386,  0.0415716780];
-%!       [-0.103110398228686, -0.1634199694,  0.0844338303]];
-%!
-%! Yt = [[-Inf,          -Inf,          -Inf        ];
-%!       [ 0.4980703596,  0.1459181380, -0.38133585 ];
-%!       [-0.3085176252,  0.1478631434,  0.36766288 ];
-%!       [ 0.1173132861, -0.2591285105, -0.18641422 ];
-%!       [ 0.0556711673,  0.2490154242, -0.00586808 ];
-%!       [-0.1712143068, -0.1538382565,  0.14660019 ];
-%!       [ 0.2054642960,  0.0210736280, -0.20265448 ];
-%!       [-0.1604111925,  0.0985727987,  0.17167666 ]];
-%!
-%! J = besselj (n,z);
-%! Y = bessely (n,z);
-%! assert (Jt(:,1), J(:,1), 0.5e-10);
-%! assert (Yt(:,1), Y(:,1), 0.5e-10);
-%! assert (Jt(:,2:3), J(:,2:3), 0.5e-10);
-
-Table 9.2 - J and Y for integer orders 3-9.
-
-%!test
-%! n = (3:9);
-%! z = (0:2:20).';
-%!
-%! Jt = [[ 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00];
-%!       [ 1.2894e-01, 3.3996e-02, 7.0396e-03, 1.2024e-03, 1.7494e-04, 2.2180e-05, 2.4923e-06];
-%!       [ 4.3017e-01, 2.8113e-01, 1.3209e-01, 4.9088e-02, 1.5176e-02, 4.0287e-03, 9.3860e-04];
-%!       [ 1.1477e-01, 3.5764e-01, 3.6209e-01, 2.4584e-01, 1.2959e-01, 5.6532e-02, 2.1165e-02];
-%!       [-2.9113e-01,-1.0536e-01, 1.8577e-01, 3.3758e-01, 3.2059e-01, 2.2345e-01, 1.2632e-01];
-%!       [ 5.8379e-02,-2.1960e-01,-2.3406e-01,-1.4459e-02, 2.1671e-01, 3.1785e-01, 2.9186e-01];
-%!       [ 1.9514e-01, 1.8250e-01,-7.3471e-02,-2.4372e-01,-1.7025e-01, 4.5095e-02, 2.3038e-01];
-%!       [-1.7681e-01, 7.6244e-02, 2.2038e-01, 8.1168e-02,-1.5080e-01,-2.3197e-01,-1.1431e-01];
-%!       [-4.3847e-02,-2.0264e-01,-5.7473e-02, 1.6672e-01, 1.8251e-01,-7.0211e-03,-1.8953e-01];
-%!       [ 1.8632e-01, 6.9640e-02,-1.5537e-01,-1.5596e-01, 5.1399e-02, 1.9593e-01, 1.2276e-01];
-%!       [-9.8901e-02, 1.3067e-01, 1.5117e-01,-5.5086e-02,-1.8422e-01,-7.3869e-02, 1.2513e-01]];
-%!
-%! Yt = [[       -Inf,       -Inf,       -Inf,       -Inf,       -Inf,       -Inf,       -Inf];
-%!       [-1.1278e+00,-2.7659e+00,-9.9360e+00,-4.6914e+01,-2.7155e+02,-1.8539e+03,-1.4560e+04];
-%!       [-1.8202e-01,-4.8894e-01,-7.9585e-01,-1.5007e+00,-3.7062e+00,-1.1471e+01,-4.2178e+01];
-%!       [ 3.2825e-01, 9.8391e-02,-1.9706e-01,-4.2683e-01,-6.5659e-01,-1.1052e+00,-2.2907e+00];
-%!       [ 2.6542e-02, 2.8294e-01, 2.5640e-01, 3.7558e-02,-2.0006e-01,-3.8767e-01,-5.7528e-01];
-%!       [-2.5136e-01,-1.4495e-01, 1.3540e-01, 2.8035e-01, 2.0102e-01, 1.0755e-03,-1.9930e-01];
-%!       [ 1.2901e-01,-1.5122e-01,-2.2982e-01,-4.0297e-02, 1.8952e-01, 2.6140e-01, 1.5902e-01];
-%!       [ 1.2350e-01, 2.0393e-01,-6.9717e-03,-2.0891e-01,-1.7209e-01, 3.6816e-02, 2.1417e-01];
-%!       [-1.9637e-01,-7.3222e-05, 1.9633e-01, 1.2278e-01,-1.0425e-01,-2.1399e-01,-1.0975e-01];
-%!       [ 3.3724e-02,-1.7722e-01,-1.1249e-01, 1.1472e-01, 1.8897e-01, 3.2253e-02,-1.6030e-01];
-%!       [ 1.4967e-01, 1.2409e-01,-1.0004e-01,-1.7411e-01,-4.4312e-03, 1.7101e-01, 1.4124e-01]];
-%!
-%! n = (3:9);
-%! z = (0:2:20).';
-%! J = besselj (n,z);
-%! Y = bessely (n,z);
-%!
-%! assert (J(1,:), zeros (1, columns (J)));
-%! assert (J(2:end,:), Jt(2:end,:), -5e-5);
-%! assert (Yt(1,:), Y(1,:));
-%! assert (Y(2:end,:), Yt(2:end,:), -5e-5);
-
-Table 9.4 - J and Y for various integer orders and arguments.
-
-%!test
-%! Jt = [[ 7.651976866e-01,   2.238907791e-01,  -1.775967713e-01,  -2.459357645e-01,  5.581232767e-02,  1.998585030e-02];
-%!       [ 2.497577302e-04,   7.039629756e-03,   2.611405461e-01,  -2.340615282e-01, -8.140024770e-02, -7.419573696e-02];
-%!       [ 2.630615124e-10,   2.515386283e-07,   1.467802647e-03,   2.074861066e-01, -1.138478491e-01, -5.473217694e-02];
-%!       [ 2.297531532e-17,   7.183016356e-13,   4.796743278e-07,   4.507973144e-03, -1.082255990e-01,  1.519812122e-02];
-%!       [ 3.873503009e-25,   3.918972805e-19,   2.770330052e-11,   1.151336925e-05, -1.167043528e-01,  6.221745850e-02];
-%!       [ 3.482869794e-42,   3.650256266e-33,   2.671177278e-21,   1.551096078e-12,  4.843425725e-02,  8.146012958e-02];
-%!       [ 1.107915851e-60,   1.196077458e-48,   8.702241617e-33,   6.030895312e-21, -1.381762812e-01,  7.270175482e-02];
-%!       [ 2.906004948e-80,   3.224095839e-65,   2.294247616e-45,   1.784513608e-30,  1.214090219e-01, -3.869833973e-02];
-%!       [ 8.431828790e-189,  1.060953112e-158,  6.267789396e-119,  6.597316064e-89,  1.115927368e-21,  9.636667330e-02]];
-%!
-%! Yt = [[ 8.825696420e-02,   5.103756726e-01,  -3.085176252e-01,   5.567116730e-02, -9.806499547e-02, -7.724431337e-02]
-%!       [-2.604058666e+02,  -9.935989128e+00,  -4.536948225e-01,   1.354030477e-01, -7.854841391e-02, -2.948019628e-02]
-%!       [-1.216180143e+08,  -1.291845422e+05,  -2.512911010e+01,  -3.598141522e-01,  5.723897182e-03,  5.833157424e-02]
-%!       [-9.256973276e+14,  -2.981023646e+10,  -4.694049564e+04,  -6.364745877e+00,  4.041280205e-02,  7.879068695e-02]
-%!       [-4.113970315e+22,  -4.081651389e+16,  -5.933965297e+08,  -1.597483848e+03,  1.644263395e-02,  5.124797308e-02]
-%!       [-3.048128783e+39,  -2.913223848e+30,  -4.028568418e+18,  -7.256142316e+09, -1.164572349e-01,  6.138839212e-03]
-%!       [-7.184874797e+57,  -6.661541235e+45,  -9.216816571e+29,  -1.362803297e+18, -4.530801120e-02,  4.074685217e-02]
-%!       [-2.191142813e+77,  -1.976150576e+62,  -2.788837017e+42,  -3.641066502e+27, -2.103165546e-01,  7.650526394e-02]
-%!       [-3.775287810e+185, -3.000826049e+155, -5.084863915e+115, -4.849148271e+85, -3.293800188e+18, -1.669214114e-01]];
-%!
-%! n = [(0:5:20).';30;40;50;100];
-%! z = [1,2,5,10,50,100];
-%! J = besselj (n.', z.').';
-%! Y = bessely (n.', z.').';
-%! assert (J, Jt, -1e-9);
-%! assert (Y, Yt, -1e-9);
-
-Table 9.8 - I and K for integer orders 0, 1, 2.
-
-%!test
-%! n  = 0:2;
-%! z1 = [0.1;2.5;5.0];
-%! z2 = [7.5;10.0;15.0;20.0];
-%! rtbl = [[ 0.9071009258   0.0452984468   0.1251041992   2.6823261023  10.890182683    1.995039646  ];
-%!         [ 0.2700464416   0.2065846495   0.2042345837   0.7595486903   0.9001744239   0.759126289  ];
-%!         [ 0.1835408126   0.1639722669   0.7002245988   0.5478075643   0.6002738588   0.132723593  ];
-%!         [ 0.1483158301   0.1380412115   0.111504840    0.4505236991   0.4796689336   0.57843541   ];
-%!         [ 0.1278333372   0.1212626814   0.103580801    0.3916319344   0.4107665704   0.47378525   ];
-%!         [ 0.1038995314   0.1003741751   0.090516308    0.3210023535   0.3315348950   0.36520701   ];
-%!         [ 0.0897803119   0.0875062222   0.081029690    0.2785448768   0.2854254970   0.30708743   ]];
-%!
-%! tbl = [besseli(n,z1,1), besselk(n,z1,1)];
-%! tbl(:,3) = tbl(:,3) .* (exp (z1) .* z1.^(-2));
-%! tbl(:,6) = tbl(:,6) .* (exp (-z1) .* z1.^(2));
-%! tbl = [tbl;[besseli(n,z2,1),besselk(n,z2,1)]];
-%!
-%! assert (tbl, rtbl, -2e-8);
-
-Table 9.9 - I and K for orders 3-9.
-
-%!test
-%! It = [[  0.0000e+00  0.0000e+00  0.0000e+00  0.0000e+00  0.0000e+00  0.0000e+00  0.0000e+00];
-%!       [  2.8791e-02  6.8654e-03  1.3298e-03  2.1656e-04  3.0402e-05  3.7487e-06  4.1199e-07];
-%!       [  6.1124e-02  2.5940e-02  9.2443e-03  2.8291e-03  7.5698e-04  1.7968e-04  3.8284e-05];
-%!       [  7.4736e-02  4.1238e-02  1.9752e-02  8.3181e-03  3.1156e-03  1.0484e-03  3.1978e-04];
-%!       [  7.9194e-02  5.0500e-02  2.8694e-02  1.4633e-02  6.7449e-03  2.8292e-03  1.0866e-03];
-%!       [  7.9830e-02  5.5683e-02  3.5284e-02  2.0398e-02  1.0806e-02  5.2694e-03  2.3753e-03];
-%!       [  7.8848e-02  5.8425e-02  3.9898e-02  2.5176e-02  1.4722e-02  8.0010e-03  4.0537e-03];
-%!       [  7.7183e-02  5.9723e-02  4.3056e-02  2.8969e-02  1.8225e-02  1.0744e-02  5.9469e-03];
-%!       [  7.5256e-02  6.0155e-02  4.5179e-02  3.1918e-02  2.1240e-02  1.3333e-02  7.9071e-03];
-%!       [  7.3263e-02  6.0059e-02  4.6571e-02  3.4186e-02  2.3780e-02  1.5691e-02  9.8324e-03];
-%!       [  7.1300e-02  5.9640e-02  4.7444e-02  3.5917e-02  2.5894e-02  1.7792e-02  1.1661e-02]];
-%!
-%! Kt = [[ Inf         Inf         Inf         Inf         Inf         Inf         Inf];
-%!      [  4.7836e+00  1.6226e+01  6.9687e+01  3.6466e+02  2.2576e+03  1.6168e+04  1.3160e+05];
-%!      [  1.6317e+00  3.3976e+00  8.4268e+00  2.4465e+01  8.1821e+01  3.1084e+02  1.3252e+03];
-%!      [  9.9723e-01  1.6798e+00  3.2370e+00  7.0748e+00  1.7387e+01  4.7644e+01  1.4444e+02];
-%!      [  7.3935e-01  1.1069e+00  1.8463e+00  3.4148e+00  6.9684e+00  1.5610e+01  3.8188e+01];
-%!      [  6.0028e-01  8.3395e-01  1.2674e+00  2.1014e+00  3.7891e+00  7.4062e+00  1.5639e+01];
-%!      [  5.1294e-01  6.7680e-01  9.6415e-01  1.4803e+00  2.4444e+00  4.3321e+00  8.2205e+00];
-%!      [  4.5266e-01  5.7519e-01  7.8133e-01  1.1333e+00  1.7527e+00  2.8860e+00  5.0510e+00];
-%!      [  4.0829e-01  5.0414e-01  6.6036e-01  9.1686e-01  1.3480e+00  2.0964e+00  3.4444e+00];
-%!      [  3.7411e-01  4.5162e-01  5.7483e-01  7.7097e-01  1.0888e+00  1.6178e+00  2.5269e+00];
-%!      [  3.4684e-01  4.1114e-01  5.1130e-01  6.6679e-01  9.1137e-01  1.3048e+00  1.9552e+00]];
-%!
-%! n = (3:9);
-%! z = (0:2:20).';
-%! I = besseli (n,z,1);
-%! K = besselk (n,z,1);
-%!
-%! assert (abs (I(1,:)), zeros (1, columns (I)));
-%! assert (I(2:end,:), It(2:end,:), -5e-5);
-%! assert (Kt(1,:), K(1,:));
-%! assert (K(2:end,:), Kt(2:end,:), -5e-5);
-
-Table 9.11 - I and K for various integer orders and arguments.
-
-%!test
-%! It = [[   1.266065878e+00    2.279585302e+00    2.723987182e+01    2.815716628e+03     2.93255378e+20     1.07375171e+42 ];
-%!       [   2.714631560e-04    9.825679323e-03    2.157974547e+00    7.771882864e+02     2.27854831e+20     9.47009387e+41 ];
-%!       [   2.752948040e-10    3.016963879e-07    4.580044419e-03    2.189170616e+01     1.07159716e+20     6.49897552e+41 ];
-%!       [   2.370463051e-17    8.139432531e-13    1.047977675e-06    1.043714907e-01     3.07376455e+19     3.47368638e+41 ];
-%!       [   3.966835986e-25    4.310560576e-19    5.024239358e-11    1.250799736e-04     5.44200840e+18     1.44834613e+41 ];
-%!       [   3.539500588e-42    3.893519664e-33    3.997844971e-21    7.787569783e-12     4.27499365e+16     1.20615487e+40 ];
-%!       [   1.121509741e-60    1.255869192e-48    1.180426980e-32    2.042123274e-20     6.00717897e+13     3.84170550e+38 ];
-%!       [   2.934635309e-80    3.353042830e-65    2.931469647e-45    4.756894561e-30     1.76508024e+10     4.82195809e+36 ];
-%!       [   8.473674008e-189   1.082171475e-158   7.093551489e-119   1.082344202e-88     2.72788795e-16     4.64153494e+21 ]];
-%!
-%! Kt = [[   4.210244382e-01    1.138938727e-01    3.691098334e-03    1.778006232e-05     3.41016774e-23     4.65662823e-45 ];
-%!       [   3.609605896e+02    9.431049101e+00    3.270627371e-02    5.754184999e-05     4.36718224e-23     5.27325611e-45 ];
-%!       [   1.807132899e+08    1.624824040e+05    9.758562829e+00    1.614255300e-03     9.15098819e-23     7.65542797e-45 ];
-%!       [   1.403066801e+15    4.059213332e+10    3.016976630e+04    2.656563849e-01     3.11621117e-22     1.42348325e-44 ];
-%!       [   6.294369360e+22    5.770856853e+16    4.827000521e+08    1.787442782e+02     1.70614838e-21     3.38520541e-44 ];
-%!       [   4.706145527e+39    4.271125755e+30    4.112132063e+18    2.030247813e+09     2.00581681e-19     3.97060205e-43 ];
-%!       [   1.114220651e+58    9.940839886e+45    1.050756722e+30    5.938224681e+17     1.29986971e-16     1.20842080e-41 ];
-%!       [   3.406896854e+77    2.979981740e+62    3.394322243e+42    2.061373775e+27     4.00601349e-13     9.27452265e-40 ];
-%!       [   5.900333184e+185   4.619415978e+155   7.039860193e+115   4.596674084e+85     1.63940352e+13     7.61712963e-25 ]];
-%!
-%! n = [(0:5:20).';30;40;50;100];
-%! z = [1,2,5,10,50,100];
-%! I = besseli (n.', z.').';
-%! K = besselk (n.', z.').';
-%! assert (I, It, -5e-9);
-%! assert (K, Kt, -5e-9);
-
-The next section checks that negative integer orders and positive
-integer orders are appropriately related.
-
-%!test
-%! n = (0:2:20);
-%! assert (besselj (n,1), besselj (-n,1), 1e-8);
-%! assert (-besselj (n+1,1), besselj (-n-1,1), 1e-8);
-
-besseli (n,z) = besseli (-n,z);
-
-%!test
-%! n = (0:2:20);
-%! assert (besseli (n,1), besseli (-n,1), 1e-8);
-
-Table 10.1 - j and y for integer orders 0, 1, 2.
-Compare against excerpts of Table 10.1, Abramowitz and Stegun.
-
-%!test
-%! n = (0:2);
-%! z = [0.1;(2.5:2.5:10.0).'];
-%!
-%! jt = [[ 9.9833417e-01  3.33000119e-02  6.6619061e-04 ];
-%!       [ 2.3938886e-01  4.16212989e-01  2.6006673e-01 ];
-%!       [-1.9178485e-01 -9.50894081e-02  1.3473121e-01 ];
-%!       [    1.2507e-01     -2.9542e-02    -1.3688e-01 ];
-%!       [   -5.4402e-02      7.8467e-02     7.7942e-02 ]];
-%!
-%! yt = [[-9.9500417e+00  -1.0049875e+02 -3.0050125e+03 ];
-%!       [ 3.2045745e-01  -1.1120588e-01 -4.5390450e-01 ];
-%!       [-5.6732437e-02   1.8043837e-01  1.6499546e-01 ];
-%!       [   -4.6218e-02     -1.3123e-01    -6.2736e-03 ];
-%!       [    8.3907e-02      6.2793e-02    -6.5069e-02 ]];
-%!
-%! j = sqrt ((pi/2)./z) .* besselj (n+1/2,z);
-%! y = sqrt ((pi/2)./z) .* bessely (n+1/2,z);
-%! assert (jt, j, -5e-5);
-%! assert (yt, y, -5e-5);
-
-Table 10.2 - j and y for orders 3-8.
-Compare against excerpts of Table 10.2, Abramowitzh and Stegun.
-
- Important note: In A&S, y_4(0.1) = -1.0507e+7, but Octave returns
- y_4(0.1) = -1.0508e+07 (-10507503.75).  If I compute the same term using
- a series, the difference is in the eighth significant digit so I left
- the Octave results in place.
-
-%!test
-%! n = (3:8);
-%! z = (0:2.5:10).';  z(1) = 0.1;
-%!
-%! jt = [[ 9.5185e-06  1.0577e-07  9.6163e-10  7.3975e-12  4.9319e-14  2.9012e-16];
-%!       [ 1.0392e-01  3.0911e-02  7.3576e-03  1.4630e-03  2.5009e-04  3.7516e-05];
-%!       [ 2.2982e-01  1.8702e-01  1.0681e-01  4.7967e-02  1.7903e-02  5.7414e-03];
-%!       [-6.1713e-02  7.9285e-02  1.5685e-01  1.5077e-01  1.0448e-01  5.8188e-02];
-%!       [-3.9496e-02 -1.0559e-01 -5.5535e-02  4.4501e-02  1.1339e-01  1.2558e-01]];
-%!
-%! yt = [[-1.5015e+05 -1.0508e+07 -9.4553e+08 -1.0400e+11 -1.3519e+13 -2.0277e+15];
-%!       [-7.9660e-01 -1.7766e+00 -5.5991e+00 -2.2859e+01 -1.1327e+02 -6.5676e+02];
-%!       [-1.5443e-02 -1.8662e-01 -3.2047e-01 -5.1841e-01 -1.0274e+00 -2.5638e+00];
-%!       [ 1.2705e-01  1.2485e-01  2.2774e-02 -9.1449e-02 -1.8129e-01 -2.7112e-01];
-%!       [-9.5327e-02 -1.6599e-03  9.3834e-02  1.0488e-01  4.2506e-02 -4.1117e-02]];
-%!
-%! j = sqrt ((pi/2)./z) .* besselj (n+1/2,z);
-%! y = sqrt ((pi/2)./z) .* bessely (n+1/2,z);
-%!
-%! assert (jt, j, -5e-5);
-%! assert (yt, y, -5e-5);
-
-Table 10.4 - j and y for various integer orders and arguments.
-
-%!test
-%! jt = [[ 8.414709848e-01    4.546487134e-01   -1.917848549e-01   -5.440211109e-02   -5.247497074e-03   -5.063656411e-03];
-%!       [ 9.256115861e-05    2.635169770e-03    1.068111615e-01   -5.553451162e-02   -2.004830056e-02   -9.290148935e-03];
-%!       [ 7.116552640e-11    6.825300865e-08    4.073442442e-04    6.460515449e-02   -1.503922146e-02   -1.956578597e-04];
-%!       [ 5.132686115e-18    1.606982166e-13    1.084280182e-07    1.063542715e-03   -1.129084539e-02    7.877261748e-03];
-%!       [ 7.537795722e-26    7.632641101e-20    5.427726761e-12    2.308371961e-06   -1.578502990e-02    1.010767128e-02];
-%!       [ 5.566831267e-43    5.836617888e-34    4.282730217e-22    2.512057385e-13   -1.494673454e-03    8.700628514e-03];
-%!       [ 1.538210374e-61    1.660978779e-49    1.210347583e-33    8.435671634e-22   -2.606336952e-02    1.043410851e-02];
-%!       [ 3.615274717e-81    4.011575290e-66    2.857479350e-46    2.230696023e-31    1.882910737e-02    5.797140882e-04];
-%!       [7.444727742e-190   9.367832591e-160   5.535650303e-120    5.832040182e-90    1.019012263e-22    1.088047701e-02]];
-%!
-%! yt = [[ -5.403023059e-01    2.080734183e-01   -5.673243709e-02    8.390715291e-02   -1.929932057e-02   -8.623188723e-03]
-%!       [ -9.994403434e+02   -1.859144531e+01   -3.204650467e-01    9.383354168e-02   -6.971131965e-04    3.720678486e-03]
-%!       [ -6.722150083e+08   -3.554147201e+05   -2.665611441e+01   -1.724536721e-01    1.352468751e-02    1.002577737e-02]
-%!       [ -6.298007233e+15   -1.012182944e+11   -6.288146513e+04   -3.992071745e+00    1.712319725e-02    6.258641510e-03]
-%!       [ -3.239592219e+23   -1.605436493e+17   -9.267951403e+08   -1.211210605e+03    1.375953130e-02    5.631729379e-05]
-%!       [ -2.946428547e+40   -1.407393871e+31   -7.760717570e+18   -6.908318646e+09   -2.241226812e-02   -5.412929349e-03]
-%!       [ -8.028450851e+58   -3.720929322e+46   -2.055758716e+30   -1.510304919e+18    4.978797221e-05   -7.048420407e-04]
-%!       [ -2.739192285e+78   -1.235021944e+63   -6.964109188e+42   -4.528227272e+27   -4.190000150e-02    1.074782297e-02]
-%!       [-6.683079463e+186  -2.655955830e+156  -1.799713983e+116   -8.573226309e+85   -1.125692891e+18   -2.298385049e-02]];
-%!
-%! n = [(0:5:20).';30;40;50;100];
-%! z = [1,2,5,10,50,100];
-%! j = sqrt ((pi/2)./z) .* besselj ((n+1/2).', z.').';
-%! y = sqrt ((pi/2)./z) .* bessely ((n+1/2).', z.').';
-%! assert (j, jt, -1e-9);
-%! assert (y, yt, -1e-9);
-*/
--- a/src/DLD-FUNCTIONS/betainc.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,491 +0,0 @@
-/*
-
-Copyright (C) 1997-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "lo-specfun.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-// FIXME: These functions do not need to be dynamically loaded.  They should
-//        be placed elsewhere in the Octave code hierarchy.
-
-DEFUN_DLD (betainc, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Mapping Function} {} betainc (@var{x}, @var{a}, @var{b})\n\
-Return the regularized incomplete Beta function,\n\
-@tex\n\
-$$\n\
- I (x, a, b) = {1 \\over {B (a, b)}} \\int_0^x t^{(a-z)} (1-t)^{(b-1)} dt.\n\
-$$\n\
-@end tex\n\
-@ifnottex\n\
-@c Set example in small font to prevent overfull line\n\
-\n\
-@smallexample\n\
-@group\n\
-                                   x\n\
-                          1       /\n\
-betainc (x, a, b) = -----------   | t^(a-1) (1-t)^(b-1) dt.\n\
-                    beta (a, b)   /\n\
-                               t=0\n\
-@end group\n\
-@end smallexample\n\
-\n\
-@end ifnottex\n\
-\n\
-If @var{x} has more than one component, both @var{a} and @var{b} must be\n\
-scalars.  If @var{x} is a scalar, @var{a} and @var{b} must be of\n\
-compatible dimensions.\n\
-@seealso{betaincinv, beta, betaln}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin == 3)
-    {
-      octave_value x_arg = args(0);
-      octave_value a_arg = args(1);
-      octave_value b_arg = args(2);
-
-      // FIXME Can we make a template version of the duplicated code below
-      if (x_arg.is_single_type () || a_arg.is_single_type () ||
-          b_arg.is_single_type ())
-        {
-          if (x_arg.is_scalar_type ())
-            {
-              float x = x_arg.float_value ();
-
-              if (a_arg.is_scalar_type ())
-                {
-                  float a = a_arg.float_value ();
-
-                  if (! error_state)
-                    {
-                      if (b_arg.is_scalar_type ())
-                        {
-                          float b = b_arg.float_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                      else
-                        {
-                          Array<float> b = b_arg.float_array_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                    }
-                }
-              else
-                {
-                  Array<float> a = a_arg.float_array_value ();
-
-                  if (! error_state)
-                    {
-                      if (b_arg.is_scalar_type ())
-                        {
-                          float b = b_arg.float_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                      else
-                        {
-                          Array<float> b = b_arg.float_array_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                    }
-                }
-            }
-          else
-            {
-              Array<float> x = x_arg.float_array_value ();
-
-              if (a_arg.is_scalar_type ())
-                {
-                  float a = a_arg.float_value ();
-
-                  if (! error_state)
-                    {
-                      if (b_arg.is_scalar_type ())
-                        {
-                          float b = b_arg.float_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                      else
-                        {
-                          Array<float> b = b_arg.float_array_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                    }
-                }
-              else
-                {
-                  Array<float> a = a_arg.float_array_value ();
-
-                  if (! error_state)
-                    {
-                      if (b_arg.is_scalar_type ())
-                        {
-                          float b = b_arg.float_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                      else
-                        {
-                          Array<float> b = b_arg.float_array_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                    }
-                }
-            }
-        }
-      else
-        {
-          if (x_arg.is_scalar_type ())
-            {
-              double x = x_arg.double_value ();
-
-              if (a_arg.is_scalar_type ())
-                {
-                  double a = a_arg.double_value ();
-
-                  if (! error_state)
-                    {
-                      if (b_arg.is_scalar_type ())
-                        {
-                          double b = b_arg.double_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                      else
-                        {
-                          Array<double> b = b_arg.array_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                    }
-                }
-              else
-                {
-                  Array<double> a = a_arg.array_value ();
-
-                  if (! error_state)
-                    {
-                      if (b_arg.is_scalar_type ())
-                        {
-                          double b = b_arg.double_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                      else
-                        {
-                          Array<double> b = b_arg.array_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                    }
-                }
-            }
-          else
-            {
-              Array<double> x = x_arg.array_value ();
-
-              if (a_arg.is_scalar_type ())
-                {
-                  double a = a_arg.double_value ();
-
-                  if (! error_state)
-                    {
-                      if (b_arg.is_scalar_type ())
-                        {
-                          double b = b_arg.double_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                      else
-                        {
-                          Array<double> b = b_arg.array_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                    }
-                }
-              else
-                {
-                  Array<double> a = a_arg.array_value ();
-
-                  if (! error_state)
-                    {
-                      if (b_arg.is_scalar_type ())
-                        {
-                          double b = b_arg.double_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                      else
-                        {
-                          Array<double> b = b_arg.array_value ();
-
-                          if (! error_state)
-                            retval = betainc (x, a, b);
-                        }
-                    }
-                }
-            }
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-## Double precision
-%!test
-%! a = [1, 1.5, 2, 3];
-%! b = [4, 3, 2, 1];
-%! v1 = betainc (1,a,b);
-%! v2 = [1,1,1,1];
-%! x = [.2, .4, .6, .8];
-%! v3 = betainc (x, a, b);
-%! v4 = 1 - betainc (1.-x, b, a);
-%! assert (v1, v2, sqrt (eps));
-%! assert (v3, v4, sqrt (eps));
-
-## Single precision
-%!test
-%! a = single ([1, 1.5, 2, 3]);
-%! b = single ([4, 3, 2, 1]);
-%! v1 = betainc (1,a,b);
-%! v2 = single ([1,1,1,1]);
-%! x = single ([.2, .4, .6, .8]);
-%! v3 = betainc (x, a, b);
-%! v4 = 1 - betainc (1.-x, b, a);
-%! assert (v1, v2, sqrt (eps ("single")));
-%! assert (v3, v4, sqrt (eps ("single")));
-
-## Mixed double/single precision
-%!test
-%! a = single ([1, 1.5, 2, 3]);
-%! b = [4, 3, 2, 1];
-%! v1 = betainc (1,a,b);
-%! v2 = single ([1,1,1,1]);
-%! x = [.2, .4, .6, .8];
-%! v3 = betainc (x, a, b);
-%! v4 = 1-betainc (1.-x, b, a);
-%! assert (v1, v2, sqrt (eps ("single")));
-%! assert (v3, v4, sqrt (eps ("single")));
-
-%!error betainc ()
-%!error betainc (1)
-%!error betainc (1,2)
-%!error betainc (1,2,3,4)
-*/
-
-DEFUN_DLD (betaincinv, args, ,
-    "-*- texinfo -*-\n\
-@deftypefn {Mapping Function} {} betaincinv (@var{y}, @var{a}, @var{b})\n\
-Compute the inverse of the incomplete Beta function, i.e., @var{x} such that\n\
-\n\
-@example\n\
-@var{y} == betainc (@var{x}, @var{a}, @var{b}) \n\
-@end example\n\
-@seealso{betainc, beta, betaln}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin == 3)
-    {
-      octave_value x_arg = args(0);
-      octave_value a_arg = args(1);
-      octave_value b_arg = args(2);
-
-      if (x_arg.is_scalar_type ())
-        {
-          double x = x_arg.double_value ();
-
-          if (a_arg.is_scalar_type ())
-            {
-              double a = a_arg.double_value ();
-
-              if (! error_state)
-                {
-                  if (b_arg.is_scalar_type ())
-                    {
-                      double b = b_arg.double_value ();
-
-                      if (! error_state)
-                        retval = betaincinv (x, a, b);
-                    }
-                  else
-                    {
-                      Array<double> b = b_arg.array_value ();
-
-                      if (! error_state)
-                        retval = betaincinv (x, a, b);
-                    }
-                }
-            }
-          else
-            {
-              Array<double> a = a_arg.array_value ();
-
-              if (! error_state)
-                {
-                  if (b_arg.is_scalar_type ())
-                    {
-                      double b = b_arg.double_value ();
-
-                      if (! error_state)
-                        retval = betaincinv (x, a, b);
-                    }
-                  else
-                    {
-                      Array<double> b = b_arg.array_value ();
-
-                      if (! error_state)
-                        retval = betaincinv (x, a, b);
-                    }
-                }
-            }
-        }
-      else
-        {
-          Array<double> x = x_arg.array_value ();
-
-          if (a_arg.is_scalar_type ())
-            {
-              double a = a_arg.double_value ();
-
-              if (! error_state)
-                {
-                  if (b_arg.is_scalar_type ())
-                    {
-                      double b = b_arg.double_value ();
-
-                      if (! error_state)
-                        retval = betaincinv (x, a, b);
-                    }
-                  else
-                    {
-                      Array<double> b = b_arg.array_value ();
-
-                      if (! error_state)
-                        retval = betaincinv (x, a, b);
-                    }
-                }
-            }
-          else
-            {
-              Array<double> a = a_arg.array_value ();
-
-              if (! error_state)
-                {
-                  if (b_arg.is_scalar_type ())
-                    {
-                      double b = b_arg.double_value ();
-
-                      if (! error_state)
-                        retval = betaincinv (x, a, b);
-                    }
-                  else
-                    {
-                      Array<double> b = b_arg.array_value ();
-
-                      if (! error_state)
-                        retval = betaincinv (x, a, b);
-                    }
-                }
-            }
-        }
-
-      // FIXME: It would be better to have an algorithm for betaincinv which
-      // accepted float inputs and returned float outputs.  As it is, we do
-      // extra work to calculate betaincinv to double precision and then throw
-      // that precision away.
-      if (x_arg.is_single_type () || a_arg.is_single_type () ||
-          b_arg.is_single_type ())
-        {
-          retval = Array<float> (retval.array_value ());
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!assert (betaincinv ([0.875 0.6875], [1 2], 3), [0.5 0.5], sqrt (eps))
-%!assert (betaincinv (0.5, 3, 3), 0.5, sqrt (eps))
-%!assert (betaincinv (0.34375, 4, 3), 0.5, sqrt (eps))
-%!assert (betaincinv (0.2265625, 5, 3), 0.5, sqrt (eps))
-%!assert (betaincinv (0.14453125, 6, 3), 0.5, sqrt (eps))
-%!assert (betaincinv (0.08984375, 7, 3), 0.5, sqrt (eps))
-%!assert (betaincinv (0.0546875, 8, 3), 0.5, sqrt (eps))
-%!assert (betaincinv (0.03271484375, 9, 3), 0.5, sqrt (eps))
-%!assert (betaincinv (0.019287109375, 10, 3), 0.5, sqrt (eps))
-
-## Test class single as well
-%!assert (betaincinv ([0.875 0.6875], [1 2], single (3)), [0.5 0.5], sqrt (eps ("single")))
-%!assert (betaincinv (0.5, 3, single (3)), 0.5, sqrt (eps ("single")))
-%!assert (betaincinv (0.34375, 4, single (3)), 0.5, sqrt (eps ("single")))
-
-## Extreme values
-%!assert (betaincinv (0, 42, 42), 0, sqrt (eps))
-%!assert (betaincinv (1, 42, 42), 1, sqrt (eps))
-
-%!error betaincinv ()
-%!error betaincinv (1, 2)
-*/
-
--- a/src/DLD-FUNCTIONS/bsxfun.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,813 +0,0 @@
-/*
-
-Copyright (C) 2007-2012 David Bateman
-Copyright (C) 2009 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-#include <vector>
-#include <list>
-
-#include "lo-mappers.h"
-
-#include "oct-map.h"
-#include "defun-dld.h"
-#include "parse.h"
-#include "variables.h"
-#include "ov-colon.h"
-#include "unwind-prot.h"
-#include "ov-fcn-handle.h"
-
-// Optimized bsxfun operations
-enum bsxfun_builtin_op
-{
-  bsxfun_builtin_plus = 0,
-  bsxfun_builtin_minus,
-  bsxfun_builtin_times,
-  bsxfun_builtin_divide,
-  bsxfun_builtin_max,
-  bsxfun_builtin_min,
-  bsxfun_builtin_eq,
-  bsxfun_builtin_ne,
-  bsxfun_builtin_lt,
-  bsxfun_builtin_le,
-  bsxfun_builtin_gt,
-  bsxfun_builtin_ge,
-  bsxfun_builtin_and,
-  bsxfun_builtin_or,
-  bsxfun_builtin_power,
-  bsxfun_builtin_unknown,
-  bsxfun_num_builtin_ops = bsxfun_builtin_unknown
-};
-
-const char *bsxfun_builtin_names[] =
-{
-  "plus",
-  "minus",
-  "times",
-  "rdivide",
-  "max",
-  "min",
-  "eq",
-  "ne",
-  "lt",
-  "le",
-  "gt",
-  "ge",
-  "and",
-  "or",
-  "power"
-};
-
-static bsxfun_builtin_op
-bsxfun_builtin_lookup (const std::string& name)
-{
-  for (int i = 0; i < bsxfun_num_builtin_ops; i++)
-    if (name == bsxfun_builtin_names[i])
-      return static_cast<bsxfun_builtin_op> (i);
-  return bsxfun_builtin_unknown;
-}
-
-typedef octave_value (*bsxfun_handler) (const octave_value&, const octave_value&);
-
-// Static table of handlers.
-bsxfun_handler bsxfun_handler_table[bsxfun_num_builtin_ops][btyp_num_types];
-
-template <class NDA, NDA (bsxfun_op) (const NDA&, const NDA&)>
-static octave_value
-bsxfun_forward_op (const octave_value& x, const octave_value& y)
-{
-  NDA xa = octave_value_extract<NDA> (x);
-  NDA ya = octave_value_extract<NDA> (y);
-  return octave_value (bsxfun_op (xa, ya));
-}
-
-template <class NDA, boolNDArray (bsxfun_rel) (const NDA&, const NDA&)>
-static octave_value
-bsxfun_forward_rel (const octave_value& x, const octave_value& y)
-{
-  NDA xa = octave_value_extract<NDA> (x);
-  NDA ya = octave_value_extract<NDA> (y);
-  return octave_value (bsxfun_rel (xa, ya));
-}
-
-// Pow needs a special handler for reals because of the potentially complex result.
-template <class NDA, class CNDA>
-static octave_value
-do_bsxfun_real_pow (const octave_value& x, const octave_value& y)
-{
-  NDA xa = octave_value_extract<NDA> (x);
-  NDA ya = octave_value_extract<NDA> (y);
-  if (! ya.all_integers () && xa.any_element_is_negative ())
-    return octave_value (bsxfun_pow (CNDA (xa), ya));
-  else
-    return octave_value (bsxfun_pow (xa, ya));
-}
-
-static void maybe_fill_table (void)
-{
-  static bool filled = false;
-  if (filled)
-    return;
-
-#define REGISTER_OP_HANDLER(OP, BTYP, NDA, FUNOP) \
-  bsxfun_handler_table[OP][BTYP] = bsxfun_forward_op<NDA, FUNOP>
-#define REGISTER_REL_HANDLER(REL, BTYP, NDA, FUNREL) \
-  bsxfun_handler_table[REL][BTYP] = bsxfun_forward_rel<NDA, FUNREL>
-#define REGISTER_STD_HANDLERS(BTYP, NDA) \
-  REGISTER_OP_HANDLER (bsxfun_builtin_plus, BTYP, NDA, bsxfun_add); \
-  REGISTER_OP_HANDLER (bsxfun_builtin_minus, BTYP, NDA, bsxfun_sub); \
-  REGISTER_OP_HANDLER (bsxfun_builtin_times, BTYP, NDA, bsxfun_mul); \
-  REGISTER_OP_HANDLER (bsxfun_builtin_divide, BTYP, NDA, bsxfun_div); \
-  REGISTER_OP_HANDLER (bsxfun_builtin_max, BTYP, NDA, bsxfun_max); \
-  REGISTER_OP_HANDLER (bsxfun_builtin_min, BTYP, NDA, bsxfun_min); \
-  REGISTER_REL_HANDLER (bsxfun_builtin_eq, BTYP, NDA, bsxfun_eq); \
-  REGISTER_REL_HANDLER (bsxfun_builtin_ne, BTYP, NDA, bsxfun_ne); \
-  REGISTER_REL_HANDLER (bsxfun_builtin_lt, BTYP, NDA, bsxfun_lt); \
-  REGISTER_REL_HANDLER (bsxfun_builtin_le, BTYP, NDA, bsxfun_le); \
-  REGISTER_REL_HANDLER (bsxfun_builtin_gt, BTYP, NDA, bsxfun_gt); \
-  REGISTER_REL_HANDLER (bsxfun_builtin_ge, BTYP, NDA, bsxfun_ge)
-
-  REGISTER_STD_HANDLERS (btyp_double, NDArray);
-  REGISTER_STD_HANDLERS (btyp_float, FloatNDArray);
-  REGISTER_STD_HANDLERS (btyp_complex, ComplexNDArray);
-  REGISTER_STD_HANDLERS (btyp_float_complex, FloatComplexNDArray);
-  REGISTER_STD_HANDLERS (btyp_int8,  int8NDArray);
-  REGISTER_STD_HANDLERS (btyp_int16, int16NDArray);
-  REGISTER_STD_HANDLERS (btyp_int32, int32NDArray);
-  REGISTER_STD_HANDLERS (btyp_int64, int64NDArray);
-  REGISTER_STD_HANDLERS (btyp_uint8,  uint8NDArray);
-  REGISTER_STD_HANDLERS (btyp_uint16, uint16NDArray);
-  REGISTER_STD_HANDLERS (btyp_uint32, uint32NDArray);
-  REGISTER_STD_HANDLERS (btyp_uint64, uint64NDArray);
-
-  // For bools, we register and/or.
-  REGISTER_OP_HANDLER (bsxfun_builtin_and, btyp_bool, boolNDArray, bsxfun_and);
-  REGISTER_OP_HANDLER (bsxfun_builtin_or, btyp_bool, boolNDArray, bsxfun_or);
-
-  // Register power handlers.
-  bsxfun_handler_table[bsxfun_builtin_power][btyp_double] =
-    do_bsxfun_real_pow<NDArray, ComplexNDArray>;
-  bsxfun_handler_table[bsxfun_builtin_power][btyp_float] =
-    do_bsxfun_real_pow<FloatNDArray, FloatComplexNDArray>;
-
-  REGISTER_OP_HANDLER (bsxfun_builtin_power, btyp_complex, ComplexNDArray, bsxfun_pow);
-  REGISTER_OP_HANDLER (bsxfun_builtin_power, btyp_float_complex, FloatComplexNDArray, bsxfun_pow);
-
-  // For chars, we want just relational handlers.
-  REGISTER_REL_HANDLER (bsxfun_builtin_eq, btyp_char, charNDArray, bsxfun_eq);
-  REGISTER_REL_HANDLER (bsxfun_builtin_ne, btyp_char, charNDArray, bsxfun_ne);
-  REGISTER_REL_HANDLER (bsxfun_builtin_lt, btyp_char, charNDArray, bsxfun_lt);
-  REGISTER_REL_HANDLER (bsxfun_builtin_le, btyp_char, charNDArray, bsxfun_le);
-  REGISTER_REL_HANDLER (bsxfun_builtin_gt, btyp_char, charNDArray, bsxfun_gt);
-  REGISTER_REL_HANDLER (bsxfun_builtin_ge, btyp_char, charNDArray, bsxfun_ge);
-
-  filled = true;
-}
-
-static octave_value
-maybe_optimized_builtin (const std::string& name,
-                         const octave_value& a, const octave_value& b)
-{
-  octave_value retval;
-
-  maybe_fill_table ();
-
-  bsxfun_builtin_op op = bsxfun_builtin_lookup (name);
-  if (op != bsxfun_builtin_unknown)
-    {
-      builtin_type_t btyp_a = a.builtin_type (), btyp_b = b.builtin_type ();
-
-      // Simplify single/double combinations.
-      if (btyp_a == btyp_float && btyp_b == btyp_double)
-        btyp_b = btyp_float;
-      else if (btyp_a == btyp_double && btyp_b == btyp_float)
-        btyp_a = btyp_float;
-      else if (btyp_a == btyp_float_complex && btyp_b == btyp_complex)
-        btyp_b = btyp_float_complex;
-      else if (btyp_a == btyp_complex && btyp_b == btyp_float_complex)
-        btyp_a = btyp_float_complex;
-
-      if (btyp_a == btyp_b && btyp_a != btyp_unknown)
-        {
-          bsxfun_handler handler = bsxfun_handler_table[op][btyp_a];
-          if (handler)
-            retval = handler (a, b);
-        }
-    }
-
-  return retval;
-}
-
-static bool
-maybe_update_column (octave_value& Ac, const octave_value& A,
-                     const dim_vector& dva, const dim_vector& dvc,
-                     octave_idx_type i, octave_value_list &idx)
-{
-  octave_idx_type nd = dva.length ();
-
-  if (i == 0)
-    {
-      idx(0) = octave_value (':');
-      for (octave_idx_type j = 1; j < nd; j++)
-        {
-          if (dva (j) == 1)
-            idx(j) = octave_value (1);
-          else
-            idx(j) = octave_value ((i % dvc(j)) + 1);
-
-          i = i / dvc (j);
-        }
-
-      Ac = A;
-      Ac = Ac.single_subsref ("(", idx);
-      return true;
-    }
-  else
-    {
-      bool is_changed = false;
-      octave_idx_type k = i;
-      octave_idx_type k1 = i - 1;
-      for (octave_idx_type j = 1; j < nd; j++)
-        {
-          if (dva(j) != 1 && k % dvc (j) != k1 % dvc (j))
-            {
-              idx (j) = octave_value ((k % dvc(j)) + 1);
-              is_changed = true;
-            }
-
-          k = k / dvc (j);
-          k1 = k1 / dvc (j);
-        }
-
-      if (is_changed)
-        {
-          Ac = A;
-          Ac = Ac.single_subsref ("(", idx);
-          return true;
-        }
-      else
-        return false;
-    }
-}
-
-#if 0
-// FIXME -- this function is not used; is it OK to delete it?
-static void
-update_index (octave_value_list& idx, const dim_vector& dv, octave_idx_type i)
-{
-  octave_idx_type nd = dv.length ();
-
-  if (i == 0)
-    {
-      for (octave_idx_type j = nd - 1; j > 0; j--)
-        idx(j) = octave_value (static_cast<double>(1));
-      idx(0) = octave_value (':');
-    }
-  else
-    {
-      for (octave_idx_type j = 1; j < nd; j++)
-        {
-          idx (j) = octave_value (i % dv (j) + 1);
-          i = i / dv (j);
-        }
-    }
-}
-#endif
-
-static void
-update_index (Array<int>& idx, const dim_vector& dv, octave_idx_type i)
-{
-  octave_idx_type nd = dv.length ();
-
-  idx(0) = 0;
-  for (octave_idx_type j = 1; j < nd; j++)
-    {
-      idx (j) = i % dv (j);
-      i = i / dv (j);
-    }
-}
-
-DEFUN_DLD (bsxfun, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} bsxfun (@var{f}, @var{A}, @var{B})\n\
-The binary singleton expansion function applier performs broadcasting,\n\
-that is, applies a binary function @var{f} element-by-element to two\n\
-array arguments @var{A} and @var{B}, and expands as necessary\n\
-singleton dimensions in either input argument.  @var{f} is a function\n\
-handle, inline function, or string containing the name of the function\n\
-to evaluate.  The function @var{f} must be capable of accepting two\n\
-column-vector arguments of equal length, or one column vector argument\n\
-and a scalar.\n\
-\n\
-The dimensions of @var{A} and @var{B} must be equal or singleton.  The\n\
-singleton dimensions of the arrays will be expanded to the same\n\
-dimensionality as the other array.\n\
-@seealso{arrayfun, cellfun}\n\
-@end deftypefn")
-{
-  int nargin = args.length ();
-  octave_value_list retval;
-
-  if (nargin != 3)
-    print_usage ();
-  else
-    {
-      octave_value func = args(0);
-
-      if (func.is_string ())
-        {
-          std::string name = func.string_value ();
-          func = symbol_table::find_function (name);
-          if (func.is_undefined ())
-            error ("bsxfun: invalid function name: %s", name.c_str ());
-        }
-      else if (! (args(0).is_function_handle () || args(0).is_inline_function ()))
-        error ("bsxfun: F must be a string or function handle");
-
-      const octave_value A = args (1);
-      const octave_value B = args (2);
-
-      if (func.is_builtin_function ()
-          || (func.is_function_handle () && ! A.is_object () && ! B.is_object ()))
-        {
-          // This may break if the default behavior is overriden. But if you override
-          // arithmetic operators for builtin classes, you should expect mayhem
-          // anyway (constant folding etc). Querying is_overloaded may not be
-          // exactly what we need here.
-          octave_function *fcn_val = func.function_value ();
-          if (fcn_val)
-            {
-              octave_value tmp = maybe_optimized_builtin (fcn_val->name (), A, B);
-              if (tmp.is_defined ())
-                retval(0) = tmp;
-            }
-        }
-
-      if (! error_state && retval.empty ())
-        {
-          dim_vector dva = A.dims ();
-          octave_idx_type nda = dva.length ();
-          dim_vector dvb = B.dims ();
-          octave_idx_type ndb = dvb.length ();
-          octave_idx_type nd = nda;
-
-          if (nda > ndb)
-              dvb.resize (nda, 1);
-          else if (nda < ndb)
-            {
-              dva.resize (ndb, 1);
-              nd = ndb;
-            }
-
-          for (octave_idx_type i = 0; i < nd; i++)
-            if (dva (i) != dvb (i) && dva (i) != 1 && dvb (i) != 1)
-              {
-                error ("bsxfun: dimensions of A and B must match");
-                break;
-              }
-
-          if (!error_state)
-            {
-              // Find the size of the output
-              dim_vector dvc;
-              dvc.resize (nd);
-
-              for (octave_idx_type i = 0; i < nd; i++)
-                dvc (i) = (dva (i) < 1  ? dva (i) : (dvb (i) < 1 ? dvb (i) :
-                      (dva (i) > dvb (i) ? dva (i) : dvb (i))));
-
-              if (dva == dvb || dva.numel () == 1 || dvb.numel () == 1)
-                {
-                  octave_value_list inputs;
-                  inputs (0) = A;
-                  inputs (1) = B;
-                  retval = func.do_multi_index_op (1, inputs);
-                }
-              else if (dvc.numel () < 1)
-                {
-                  octave_value_list inputs;
-                  inputs (0) = A.resize (dvc);
-                  inputs (1) = B.resize (dvc);
-                  retval = func.do_multi_index_op (1, inputs);
-                }
-              else
-                {
-                  octave_idx_type ncount = 1;
-                  for (octave_idx_type i = 1; i < nd; i++)
-                    ncount *= dvc (i);
-
-#define BSXDEF(T) \
-                  T result_ ## T; \
-                  bool have_ ## T = false;
-
-                  BSXDEF(NDArray);
-                  BSXDEF(ComplexNDArray);
-                  BSXDEF(FloatNDArray);
-                  BSXDEF(FloatComplexNDArray);
-                  BSXDEF(boolNDArray);
-                  BSXDEF(int8NDArray);
-                  BSXDEF(int16NDArray);
-                  BSXDEF(int32NDArray);
-                  BSXDEF(int64NDArray);
-                  BSXDEF(uint8NDArray);
-                  BSXDEF(uint16NDArray);
-                  BSXDEF(uint32NDArray);
-                  BSXDEF(uint64NDArray);
-
-                  octave_value Ac ;
-                  octave_value_list idxA;
-                  octave_value Bc;
-                  octave_value_list idxB;
-                  octave_value C;
-                  octave_value_list inputs;
-                  Array<int> ra_idx (dim_vector (dvc.length (), 1), 0);
-
-
-                  for (octave_idx_type i = 0; i < ncount; i++)
-                    {
-                      if (maybe_update_column (Ac, A, dva, dvc, i, idxA))
-                        inputs (0) = Ac;
-
-                      if (maybe_update_column (Bc, B, dvb, dvc, i, idxB))
-                        inputs (1) = Bc;
-
-                      octave_value_list tmp = func.do_multi_index_op (1, inputs);
-
-                      if (error_state)
-                        break;
-
-#define BSXINIT(T, CLS, EXTRACTOR) \
-                      (result_type == CLS) \
-                        { \
-                            have_ ## T = true; \
-                            result_ ## T = \
-                                tmp (0). EXTRACTOR ## _array_value (); \
-                            result_ ## T .resize (dvc); \
-                        }
-
-                      if (i == 0)
-                        {
-                          if (! tmp(0).is_sparse_type ())
-                            {
-                              std::string result_type = tmp(0).class_name ();
-                              if (result_type == "double")
-                                {
-                                  if (tmp(0).is_real_type ())
-                                    {
-                                      have_NDArray = true;
-                                      result_NDArray = tmp(0).array_value ();
-                                      result_NDArray.resize (dvc);
-                                    }
-                                  else
-                                    {
-                                      have_ComplexNDArray = true;
-                                      result_ComplexNDArray =
-                                        tmp(0).complex_array_value ();
-                                      result_ComplexNDArray.resize (dvc);
-                                    }
-                                }
-                              else if (result_type == "single")
-                                {
-                                  if (tmp(0).is_real_type ())
-                                    {
-                                      have_FloatNDArray = true;
-                                      result_FloatNDArray = tmp(0).float_array_value ();
-                                      result_FloatNDArray.resize (dvc);
-                                    }
-                                  else
-                                    {
-                                      have_ComplexNDArray = true;
-                                      result_ComplexNDArray =
-                                        tmp(0).complex_array_value ();
-                                      result_ComplexNDArray.resize (dvc);
-                                    }
-                                }
-                              else if BSXINIT(boolNDArray, "logical", bool)
-                              else if BSXINIT(int8NDArray, "int8", int8)
-                              else if BSXINIT(int16NDArray, "int16", int16)
-                              else if BSXINIT(int32NDArray, "int32", int32)
-                              else if BSXINIT(int64NDArray, "int64", int64)
-                              else if BSXINIT(uint8NDArray, "uint8", uint8)
-                              else if BSXINIT(uint16NDArray, "uint16", uint16)
-                              else if BSXINIT(uint32NDArray, "uint32", uint32)
-                              else if BSXINIT(uint64NDArray, "uint64", uint64)
-                              else
-                                {
-                                  C = tmp (0);
-                                  C = C.resize (dvc);
-                                }
-                            }
-                        }
-                      else
-                        {
-                          update_index (ra_idx, dvc, i);
-
-                          if (have_FloatNDArray ||
-                              have_FloatComplexNDArray)
-                            {
-                              if (! tmp(0).is_float_type ())
-                                {
-                                  if (have_FloatNDArray)
-                                    {
-                                      have_FloatNDArray = false;
-                                      C = result_FloatNDArray;
-                                    }
-                                  else
-                                    {
-                                      have_FloatComplexNDArray = false;
-                                      C = result_FloatComplexNDArray;
-                                    }
-                                  C = do_cat_op (C, tmp(0), ra_idx);
-                                }
-                              else if (tmp(0).is_double_type ())
-                                {
-                                  if (tmp(0).is_complex_type () &&
-                                      have_FloatNDArray)
-                                    {
-                                      result_ComplexNDArray =
-                                        ComplexNDArray (result_FloatNDArray);
-                                      result_ComplexNDArray.insert
-                                        (tmp(0).complex_array_value (), ra_idx);
-                                      have_FloatComplexNDArray = false;
-                                      have_ComplexNDArray = true;
-                                    }
-                                  else
-                                    {
-                                      result_NDArray =
-                                        NDArray (result_FloatNDArray);
-                                      result_NDArray.insert
-                                        (tmp(0).array_value (), ra_idx);
-                                      have_FloatNDArray = false;
-                                      have_NDArray = true;
-                                    }
-                                }
-                              else if (tmp(0).is_real_type ())
-                                result_FloatNDArray.insert
-                                  (tmp(0).float_array_value (), ra_idx);
-                              else
-                                {
-                                  result_FloatComplexNDArray =
-                                    FloatComplexNDArray (result_FloatNDArray);
-                                  result_FloatComplexNDArray.insert
-                                    (tmp(0).float_complex_array_value (), ra_idx);
-                                  have_FloatNDArray = false;
-                                  have_FloatComplexNDArray = true;
-                                }
-                            }
-                          else if (have_NDArray)
-                            {
-                              if (! tmp(0).is_float_type ())
-                                {
-                                  have_NDArray = false;
-                                  C = result_NDArray;
-                                  C = do_cat_op (C, tmp(0), ra_idx);
-                                }
-                              else if (tmp(0).is_real_type ())
-                                result_NDArray.insert (tmp(0).array_value (),
-                                                       ra_idx);
-                              else
-                                {
-                                  result_ComplexNDArray =
-                                    ComplexNDArray (result_NDArray);
-                                  result_ComplexNDArray.insert
-                                    (tmp(0).complex_array_value (), ra_idx);
-                                  have_NDArray = false;
-                                  have_ComplexNDArray = true;
-                                }
-                            }
-
-#define BSXLOOP(T, CLS, EXTRACTOR) \
-                        (have_ ## T) \
-                          { \
-                            if (tmp (0).class_name () != CLS) \
-                              { \
-                                have_ ## T = false; \
-                                C = result_ ## T; \
-                                C = do_cat_op (C, tmp (0), ra_idx); \
-                              } \
-                            else \
-                              result_ ## T .insert \
-                                (tmp(0). EXTRACTOR ## _array_value (), \
-                                ra_idx); \
-                          }
-
-                          else if BSXLOOP(ComplexNDArray, "double", complex)
-                          else if BSXLOOP(boolNDArray, "logical", bool)
-                          else if BSXLOOP(int8NDArray, "int8", int8)
-                          else if BSXLOOP(int16NDArray, "int16", int16)
-                          else if BSXLOOP(int32NDArray, "int32", int32)
-                          else if BSXLOOP(int64NDArray, "int64", int64)
-                          else if BSXLOOP(uint8NDArray, "uint8", uint8)
-                          else if BSXLOOP(uint16NDArray, "uint16", uint16)
-                          else if BSXLOOP(uint32NDArray, "uint32", uint32)
-                          else if BSXLOOP(uint64NDArray, "uint64", uint64)
-                          else
-                            C = do_cat_op (C, tmp(0), ra_idx);
-                        }
-                    }
-
-#define BSXEND(T) \
-                  (have_ ## T) \
-                    retval(0) = result_ ## T;
-
-                  if BSXEND(NDArray)
-                  else if BSXEND(ComplexNDArray)
-                  else if BSXEND(FloatNDArray)
-                  else if BSXEND(FloatComplexNDArray)
-                  else if BSXEND(boolNDArray)
-                  else if BSXEND(int8NDArray)
-                  else if BSXEND(int16NDArray)
-                  else if BSXEND(int32NDArray)
-                  else if BSXEND(int64NDArray)
-                  else if BSXEND(uint8NDArray)
-                  else if BSXEND(uint16NDArray)
-                  else if BSXEND(uint32NDArray)
-                  else if BSXEND(uint64NDArray)
-                  else
-                    retval(0) = C;
-                }
-            }
-        }
-    }
-
-  return retval;
-}
-
-/*
-
-%!shared a, b, c, f
-%! a = randn (4, 4);
-%! b = mean (a, 1);
-%! c = mean (a, 2);
-%! f = @minus;
-%!error (bsxfun (f))
-%!error (bsxfun (f, a))
-%!error (bsxfun (a, b))
-%!error (bsxfun (a, b, c))
-%!error (bsxfun (f, a, b, c))
-%!error (bsxfun (f, ones (4, 0), ones (4, 4)))
-%!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0))
-%!assert (bsxfun (f, ones (1, 4), ones (4, 1)), zeros (4, 4))
-%!assert (bsxfun (f, a, b), a - repmat (b, 4, 1))
-%!assert (bsxfun (f, a, c), a - repmat (c, 1, 4))
-%!assert (bsxfun ("minus", ones (1, 4), ones (4, 1)), zeros (4, 4))
-
-%!shared a, b, c, f
-%! a = randn (4, 4);
-%! a(1) *= 1i;
-%! b = mean (a, 1);
-%! c = mean (a, 2);
-%! f = @minus;
-%!error (bsxfun (f))
-%!error (bsxfun (f, a))
-%!error (bsxfun (a, b))
-%!error (bsxfun (a, b, c))
-%!error (bsxfun (f, a, b, c))
-%!error (bsxfun (f, ones (4, 0), ones (4, 4)))
-%!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0))
-%!assert (bsxfun (f, ones (1, 4), ones (4, 1)), zeros (4, 4))
-%!assert (bsxfun (f, a, b), a - repmat (b, 4, 1))
-%!assert (bsxfun (f, a, c), a - repmat (c, 1, 4))
-%!assert (bsxfun ("minus", ones (1, 4), ones (4, 1)), zeros (4, 4))
-
-%!shared a, b, c, f
-%! a = randn (4, 4);
-%! a(end) *= 1i;
-%! b = mean (a, 1);
-%! c = mean (a, 2);
-%! f = @minus;
-%!error (bsxfun (f))
-%!error (bsxfun (f, a))
-%!error (bsxfun (a, b))
-%!error (bsxfun (a, b, c))
-%!error (bsxfun (f, a, b, c))
-%!error (bsxfun (f, ones (4, 0), ones (4, 4)))
-%!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0))
-%!assert (bsxfun (f, ones (1, 4), ones (4, 1)), zeros (4, 4))
-%!assert (bsxfun (f, a, b), a - repmat (b, 4, 1))
-%!assert (bsxfun (f, a, c), a - repmat (c, 1, 4))
-%!assert (bsxfun ("minus", ones (1, 4), ones (4, 1)), zeros (4, 4))
-
-%!shared a, b, c, f
-%! a = randn (4, 4);
-%! b = a (1, :);
-%! c = a (:, 1);
-%! f = @(x, y) x == y;
-%!error (bsxfun (f))
-%!error (bsxfun (f, a))
-%!error (bsxfun (a, b))
-%!error (bsxfun (a, b, c))
-%!error (bsxfun (f, a, b, c))
-%!error (bsxfun (f, ones (4, 0), ones (4, 4)))
-%!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0, "logical"))
-%!assert (bsxfun (f, ones (1, 4), ones (4, 1)), ones (4, 4, "logical"))
-%!assert (bsxfun (f, a, b), a == repmat (b, 4, 1))
-%!assert (bsxfun (f, a, c), a == repmat (c, 1, 4))
-
-%!shared a, b, c, d, f
-%! a = randn (4, 4, 4);
-%! b = mean (a, 1);
-%! c = mean (a, 2);
-%! d = mean (a, 3);
-%! f = @minus;
-%!error (bsxfun (f, ones ([4, 0, 4]), ones ([4, 4, 4])))
-%!assert (bsxfun (f, ones ([4, 0, 4]), ones ([4, 1, 4])), zeros ([4, 0, 4]))
-%!assert (bsxfun (f, ones ([4, 4, 0]), ones ([4, 1, 1])), zeros ([4, 4, 0]))
-%!assert (bsxfun (f, ones ([1, 4, 4]), ones ([4, 1, 4])), zeros ([4, 4, 4]))
-%!assert (bsxfun (f, ones ([4, 4, 1]), ones ([4, 1, 4])), zeros ([4, 4, 4]))
-%!assert (bsxfun (f, ones ([4, 1, 4]), ones ([1, 4, 4])), zeros ([4, 4, 4]))
-%!assert (bsxfun (f, ones ([4, 1, 4]), ones ([1, 4, 1])), zeros ([4, 4, 4]))
-%!assert (bsxfun (f, a, b), a - repmat (b, [4, 1, 1]))
-%!assert (bsxfun (f, a, c), a - repmat (c, [1, 4, 1]))
-%!assert (bsxfun (f, a, d), a - repmat (d, [1, 1, 4]))
-%!assert (bsxfun ("minus", ones ([4, 0, 4]), ones ([4, 1, 4])), zeros ([4, 0, 4]))
-
-%% The test below is a very hard case to treat
-%!assert (bsxfun (f, ones ([4, 1, 4, 1]), ones ([1, 4, 1, 4])), zeros ([4, 4, 4, 4]));
-
-%!shared a, b, aa, bb
-%! a = randn (3, 1, 3);
-%! aa = a(:, ones (1, 3), :, ones (1, 3));
-%! b = randn (1, 3, 3, 3);
-%! bb = b(ones (1, 3), :, :, :);
-%!assert (bsxfun (@plus, a, b), aa + bb)
-%!assert (bsxfun (@minus, a, b), aa - bb)
-%!assert (bsxfun (@times, a, b), aa .* bb)
-%!assert (bsxfun (@rdivide, a, b), aa ./ bb)
-%!assert (bsxfun (@ldivide, a, b), aa .\ bb)
-%!assert (bsxfun (@power, a, b), aa .^ bb)
-%!assert (bsxfun (@power, abs (a), b), abs (aa) .^ bb)
-%!assert (bsxfun (@eq, round (a), round (b)), round (aa) == round (bb))
-%!assert (bsxfun (@ne, round (a), round (b)), round (aa) != round (bb))
-%!assert (bsxfun (@lt, a, b), aa < bb)
-%!assert (bsxfun (@le, a, b), aa <= bb)
-%!assert (bsxfun (@gt, a, b), aa > bb)
-%!assert (bsxfun (@ge, a, b), aa >= bb)
-%!assert (bsxfun (@min, a, b), min (aa, bb))
-%!assert (bsxfun (@max, a, b), max (aa, bb))
-%!assert (bsxfun (@and, a > 0, b > 0), (aa > 0) & (bb > 0))
-%!assert (bsxfun (@or, a > 0, b > 0), (aa > 0) | (bb > 0))
-
-%% Test automatic bsxfun
-%
-%!test
-%! funs = {@plus, @minus, @times, @rdivide, @ldivide, @power, @max, @min, \
-%!         @rem, @mod, @atan2, @hypot, @eq, @ne, @lt, @le, @gt, @ge, \
-%!         @and, @or, @xor };
-%!
-%! float_types = {@single, @double};
-%! int_types = {@int8, @int16, @int32, @int64, \
-%!              @uint8, @uint16, @uint32, @uint64};
-%!
-%! x = rand (3) * 10-5;
-%! y = rand (3,1) * 10-5;
-%!
-%! for i=1:length (funs)
-%!   for j = 1:length (float_types)
-%!     for k = 1:length (int_types)
-%!
-%!       fun = funs{i};
-%!       f_type = float_types{j};
-%!       i_type = int_types{k};
-%!
-%!         assert (bsxfun (fun, f_type (x), i_type (y)), \
-%!                 fun (f_type(x), i_type (y)));
-%!         assert (bsxfun (fun, f_type (y), i_type (x)), \
-%!                 fun (f_type(y), i_type (x)));
-%!
-%!         assert (bsxfun (fun, i_type (x), i_type (y)), \
-%!                 fun (i_type (x), i_type (y)));
-%!         assert (bsxfun (fun, i_type (y), i_type (x)), \
-%!                 fun (i_type (y), i_type (x)));
-%!
-%!         assert (bsxfun (fun, f_type (x), f_type (y)), \
-%!                 fun (f_type (x), f_type (y)));
-%!         assert (bsxfun (fun, f_type(y), f_type(x)), \
-%!                 fun (f_type (y), f_type (x)));
-%!     endfor
-%!   endfor
-%! endfor
-%!
-*/
--- a/src/DLD-FUNCTIONS/cellfun.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2472 +0,0 @@
-/*
-
-Copyright (C) 2005-2012 Mohamed Kamoun
-Copyright (C) 2006-2012 Bill Denney
-Copyright (C) 2009 Jaroslav Hajek
-Copyright (C) 2010 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-#include <vector>
-#include <list>
-#include <memory>
-
-#include "caseless-str.h"
-#include "lo-mappers.h"
-#include "oct-locbuf.h"
-
-#include "Cell.h"
-#include "oct-map.h"
-#include "defun-dld.h"
-#include "parse.h"
-#include "variables.h"
-#include "ov-colon.h"
-#include "unwind-prot.h"
-#include "gripes.h"
-#include "utils.h"
-
-#include "ov-class.h"
-#include "ov-scalar.h"
-#include "ov-float.h"
-#include "ov-complex.h"
-#include "ov-flt-complex.h"
-#include "ov-bool.h"
-#include "ov-int8.h"
-#include "ov-int16.h"
-#include "ov-int32.h"
-#include "ov-int64.h"
-#include "ov-uint8.h"
-#include "ov-uint16.h"
-#include "ov-uint32.h"
-#include "ov-uint64.h"
-
-#include "ov-fcn-handle.h"
-
-static octave_value_list
-get_output_list (octave_idx_type count, octave_idx_type nargout,
-                 const octave_value_list& inputlist,
-                 octave_value& func,
-                 octave_value& error_handler)
-{
-  octave_value_list tmp = func.do_multi_index_op (nargout, inputlist);
-
-  if (error_state)
-    {
-      if (error_handler.is_defined ())
-        {
-          octave_scalar_map msg;
-          msg.assign ("identifier", last_error_id ());
-          msg.assign ("message", last_error_message ());
-          msg.assign ("index", static_cast<double> (count + static_cast<octave_idx_type>(1)));
-
-          octave_value_list errlist = inputlist;
-          errlist.prepend (msg);
-
-          buffer_error_messages--;
-
-          error_state = 0;
-
-          tmp = error_handler.do_multi_index_op (nargout, errlist);
-
-          buffer_error_messages++;
-
-          if (error_state)
-            tmp.clear ();
-        }
-      else
-        tmp.clear ();
-    }
-
-  return tmp;
-}
-
-static octave_value_list
-try_cellfun_internal_ops (const octave_value_list& args, int nargin)
-{
-  octave_value_list retval;
-
-  std::string name = args(0).string_value ();
-
-  const Cell f_args = args(1).cell_value ();
-
-  octave_idx_type k = f_args.numel ();
-
-  if (name == "isempty")
-    {
-      boolNDArray result (f_args.dims ());
-      for (octave_idx_type count = 0; count < k; count++)
-        result(count) = f_args.elem (count).is_empty ();
-      retval(0) = result;
-    }
-  else if (name == "islogical")
-    {
-      boolNDArray result (f_args.dims ());
-      for (octave_idx_type  count= 0; count < k; count++)
-        result(count) = f_args.elem (count).is_bool_type ();
-      retval(0) = result;
-    }
-  else if (name == "isreal")
-    {
-      boolNDArray result (f_args.dims ());
-      for (octave_idx_type  count= 0; count < k; count++)
-        result(count) = f_args.elem (count).is_real_type ();
-      retval(0) = result;
-    }
-  else if (name == "length")
-    {
-      NDArray result (f_args.dims ());
-      for (octave_idx_type  count= 0; count < k; count++)
-        result(count) = static_cast<double> (f_args.elem (count).length ());
-      retval(0) = result;
-    }
-  else if (name == "ndims")
-    {
-      NDArray result (f_args.dims ());
-      for (octave_idx_type count = 0; count < k; count++)
-        result(count) = static_cast<double> (f_args.elem (count).ndims ());
-      retval(0) = result;
-    }
-  else if (name == "prodofsize" || name == "numel")
-    {
-      NDArray result (f_args.dims ());
-      for (octave_idx_type count = 0; count < k; count++)
-        result(count) = static_cast<double> (f_args.elem (count).numel ());
-      retval(0) = result;
-    }
-  else if (name == "size")
-    {
-      if (nargin == 3)
-        {
-          int d = args(2).nint_value () - 1;
-
-          if (d < 0)
-            error ("cellfun: K must be a positive integer");
-
-          if (! error_state)
-            {
-              NDArray result (f_args.dims ());
-              for (octave_idx_type count = 0; count < k; count++)
-                {
-                  dim_vector dv = f_args.elem (count).dims ();
-                  if (d < dv.length ())
-                    result(count) = static_cast<double> (dv(d));
-                  else
-                    result(count) = 1.0;
-                }
-              retval(0) = result;
-            }
-        }
-      else
-        error ("cellfun: not enough arguments for \"size\"");
-    }
-  else if (name == "isclass")
-    {
-      if (nargin == 3)
-        {
-          std::string class_name = args(2).string_value ();
-          boolNDArray result (f_args.dims ());
-          for (octave_idx_type count = 0; count < k; count++)
-            result(count) = (f_args.elem (count).class_name () == class_name);
-
-          retval(0) = result;
-        }
-      else
-        error ("cellfun: not enough arguments for \"isclass\"");
-    }
-
-  return retval;
-}
-
-static void
-get_mapper_fun_options (const octave_value_list& args, int& nargin,
-                        bool& uniform_output, octave_value& error_handler)
-{
-  while (nargin > 3 && args(nargin-2).is_string ())
-    {
-      caseless_str arg = args(nargin-2).string_value ();
-
-      size_t compare_len = std::max (arg.length (), static_cast<size_t> (2));
-
-      if (arg.compare ("uniformoutput", compare_len))
-        uniform_output = args(nargin-1).bool_value ();
-      else if (arg.compare ("errorhandler", compare_len))
-        {
-          if (args(nargin-1).is_function_handle ()
-              || args(nargin-1).is_inline_function ())
-            {
-              error_handler = args(nargin-1);
-            }
-          else if (args(nargin-1).is_string ())
-            {
-              std::string err_name = args(nargin-1).string_value ();
-
-              error_handler = symbol_table::find_function (err_name);
-
-              if (error_handler.is_undefined ())
-                {
-                  error ("cellfun: invalid function NAME: %s",
-                         err_name.c_str ());
-                  break;
-                }
-            }
-          else
-            {
-              error ("cellfun: invalid value for 'ErrorHandler' function");
-              break;
-            }
-        }
-      else
-        {
-          error ("cellfun: unrecognized parameter %s",
-                 arg.c_str ());
-          break;
-        }
-
-      nargin -= 2;
-    }
-
-  nargin -= 1;
-}
-
-DEFUN_DLD (cellfun, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} cellfun (@var{name}, @var{C})\n\
-@deftypefnx {Loadable Function} {} cellfun (\"size\", @var{C}, @var{k})\n\
-@deftypefnx {Loadable Function} {} cellfun (\"isclass\", @var{C}, @var{class})\n\
-@deftypefnx {Loadable Function} {} cellfun (@var{func}, @var{C})\n\
-@deftypefnx {Loadable Function} {} cellfun (@var{func}, @var{C}, @var{D})\n\
-@deftypefnx {Loadable Function} {[@var{a}, @dots{}] =} cellfun (@dots{})\n\
-@deftypefnx {Loadable Function} {} cellfun (@dots{}, \"ErrorHandler\", @var{errfunc})\n\
-@deftypefnx {Loadable Function} {} cellfun (@dots{}, \"UniformOutput\", @var{val})\n\
-\n\
-Evaluate the function named @var{name} on the elements of the cell array\n\
-@var{C}.  Elements in @var{C} are passed on to the named function\n\
-individually.  The function @var{name} can be one of the functions\n\
-\n\
-@table @code\n\
-@item isempty\n\
-Return 1 for empty elements.\n\
-\n\
-@item islogical\n\
-Return 1 for logical elements.\n\
-\n\
-@item isreal\n\
-Return 1 for real elements.\n\
-\n\
-@item length\n\
-Return a vector of the lengths of cell elements.\n\
-\n\
-@item ndims\n\
-Return the number of dimensions of each element.\n\
-\n\
-@item numel\n\
-@itemx prodofsize\n\
-Return the number of elements contained within each cell element.  The\n\
-number is the product of the dimensions of the object at each cell element.\n\
-\n\
-@item size\n\
-Return the size along the @var{k}-th dimension.\n\
-\n\
-@item isclass\n\
-Return 1 for elements of @var{class}.\n\
-@end table\n\
-\n\
-Additionally, @code{cellfun} accepts an arbitrary function @var{func}\n\
-in the form of an inline function, function handle, or the name of a\n\
-function (in a character string).  In the case of a character string\n\
-argument, the function must accept a single argument named @var{x}, and\n\
-it must return a string value.  The function can take one or more arguments,\n\
-with the inputs arguments given by @var{C}, @var{D}, etc.  Equally the\n\
-function can return one or more output arguments.  For example:\n\
-\n\
-@example\n\
-@group\n\
-cellfun (\"atan2\", @{1, 0@}, @{0, 1@})\n\
-     @result{} [ 1.57080   0.00000 ]\n\
-@end group\n\
-@end example\n\
-\n\
-The number of output arguments of @code{cellfun} matches the number of output\n\
-arguments of the function.  The outputs of the function will be collected\n\
-into the output arguments of @code{cellfun} like this:\n\
-\n\
-@example\n\
-@group\n\
-function [a, b] = twoouts (x)\n\
-  a = x;\n\
-  b = x*x;\n\
-endfunction\n\
-[aa, bb] = cellfun (@@twoouts, @{1, 2, 3@})\n\
-     @result{}\n\
-        aa =\n\
-           1 2 3\n\
-        bb =\n\
-           1 4 9\n\
-@end group\n\
-@end example\n\
-\n\
-Note that per default the output argument(s) are arrays of the same size as\n\
-the input arguments.  Input arguments that are singleton (1x1) cells will be\n\
-automatically expanded to the size of the other arguments.\n\
-\n\
-If the parameter \"UniformOutput\" is set to true (the default), then the\n\
-function must return scalars which will be concatenated into the return\n\
-array(s).  If \"UniformOutput\" is false, the outputs are concatenated into a\n\
-cell array (or cell arrays).  For example:\n\
-\n\
-@example\n\
-@group\n\
-cellfun (\"tolower\", @{\"Foo\", \"Bar\", \"FooBar\"@},\n\
-         \"UniformOutput\", false)\n\
-@result{} @{\"foo\", \"bar\", \"foobar\"@}\n\
-@end group\n\
-@end example\n\
-\n\
-Given the parameter \"ErrorHandler\", then @var{errfunc} defines a function\n\
-to call in case @var{func} generates an error.  The form of the function is\n\
-\n\
-@example\n\
-function [@dots{}] = errfunc (@var{s}, @dots{})\n\
-@end example\n\
-\n\
-@noindent\n\
-where there is an additional input argument to @var{errfunc} relative to\n\
-@var{func}, given by @var{s}.  This is a structure with the elements\n\
-'identifier', 'message' and 'index', giving respectively the error\n\
-identifier, the error message, and the index into the input arguments\n\
-of the element that caused the error.  For example:\n\
-\n\
-@example\n\
-@group\n\
-function y = foo (s, x), y = NaN; endfunction\n\
-cellfun (\"factorial\", @{-1,2@}, \"ErrorHandler\", @@foo)\n\
-@result{} [NaN 2]\n\
-@end group\n\
-@end example\n\
-\n\
-Use @code{cellfun} intelligently.  The @code{cellfun} function is a\n\
-useful tool for avoiding loops.  It is often used with anonymous\n\
-function handles; however, calling an anonymous function involves an\n\
-overhead quite comparable to the overhead of an m-file function.\n\
-Passing a handle to a built-in function is faster, because the\n\
-interpreter is not involved in the internal loop.  For example:\n\
-\n\
-@example\n\
-@group\n\
-a = @{@dots{}@}\n\
-v = cellfun (@@(x) det (x), a); # compute determinants\n\
-v = cellfun (@@det, a); # faster\n\
-@end group\n\
-@end example\n\
-\n\
-@seealso{arrayfun, structfun, spfun}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-  int nargin = args.length ();
-  int nargout1 = (nargout < 1 ? 1 : nargout);
-
-  if (nargin < 2)
-    {
-      error ("cellfun: function requires at least 2 arguments");
-      print_usage ();
-      return retval;
-    }
-
-  octave_value func = args(0);
-
-  if (! args(1).is_cell ())
-    {
-      error ("cellfun: C must be a cell array");
-
-      return retval;
-    }
-
-  if (func.is_string ())
-    {
-      retval = try_cellfun_internal_ops (args, nargin);
-
-      if (error_state || ! retval.empty ())
-        return retval;
-
-      // See if we can convert the string into a function.
-
-      std::string name = args(0).string_value ();
-
-      if (! valid_identifier (name))
-        {
-          std::string fcn_name = unique_symbol_name ("__cellfun_fcn_");
-          std::string fname = "function y = " + fcn_name + "(x) y = ";
-
-          octave_function *ptr_func
-            = extract_function (args(0), "cellfun", fcn_name,
-                                fname, "; endfunction");
-
-          if (ptr_func && ! error_state)
-            func = octave_value (ptr_func, true);
-        }
-      else
-        {
-          func = symbol_table::find_function (name);
-
-          if (func.is_undefined ())
-            error ("cellfun: invalid function NAME: %s", name.c_str ());
-        }
-
-      if (error_state || ! retval.empty ())
-        return retval;
-    }
-
-  if (func.is_function_handle () || func.is_inline_function ()
-      || func.is_function ())
-    {
-
-      // The following is an optimisation because the symbol table can
-      // give a more specific function class, so this can result in
-      // fewer polymorphic function calls as the function gets called
-      // for each value of the array.
-      {
-        if (func.is_function_handle ())
-          {
-            octave_fcn_handle* f = func.fcn_handle_value ();
-
-            // Overloaded function handles need to check the type of the
-            // arguments for each element of the array, so they cannot
-            // be optimised this way.
-            if (f -> is_overloaded ())
-              goto nevermind;
-          }
-
-        std::string name = func.function_value () -> name ();
-        octave_value f = symbol_table::find_function (name);
-
-        if (f.is_defined ())
-          {
-            //Except for these two which are special cases...
-            if (name != "size" && name != "class")
-              {
-                //Try first the optimised code path for built-in functions
-                octave_value_list tmp_args = args;
-                tmp_args(0) = name;
-                retval = try_cellfun_internal_ops (tmp_args, nargin);
-                if (error_state || ! retval.empty ())
-                  return retval;
-              }
-
-            //Okay, we tried, doesn't work, let's do the best we can
-            //instead and avoid polymorphic calls for each element of
-            //the array.
-            func = f;
-          }
-      }
-    nevermind:
-
-      bool uniform_output = true;
-      octave_value error_handler;
-
-      get_mapper_fun_options (args, nargin, uniform_output, error_handler);
-
-      if (error_state)
-        return octave_value_list ();
-
-      // Extract cell arguments.
-
-      octave_value_list inputlist (nargin, octave_value ());
-
-      OCTAVE_LOCAL_BUFFER (Cell, inputs, nargin);
-      OCTAVE_LOCAL_BUFFER (bool, mask, nargin);
-
-      // This is to prevent copy-on-write.
-      const Cell *cinputs = inputs;
-
-      octave_idx_type k = 1;
-
-      dim_vector fdims (1, 1);
-
-      // Collect arguments.  Pre-fill scalar elements of inputlist
-      // array.
-
-      for (int j = 0; j < nargin; j++)
-        {
-          if (! args(j+1).is_cell ())
-            {
-              error ("cellfun: arguments must be cells");
-              return octave_value_list ();
-            }
-
-          inputs[j] = args(j+1).cell_value ();
-          mask[j] = inputs[j].numel () != 1;
-          if (! mask[j])
-            inputlist(j) = cinputs[j](0);
-        }
-
-      for (int j = 0; j < nargin; j++)
-        {
-          if (mask[j])
-            {
-              fdims = inputs[j].dims ();
-              k = inputs[j].numel ();
-              for (int i = j+1; i < nargin; i++)
-                {
-                  if (mask[i] && inputs[i].dims () != fdims)
-                    {
-                      error ("cellfun: dimensions mismatch");
-                      return octave_value_list ();
-                    }
-                }
-              break;
-            }
-        }
-
-      unwind_protect frame;
-      frame.protect_var (buffer_error_messages);
-
-      if (error_handler.is_defined ())
-        buffer_error_messages++;
-
-      // Apply functions.
-
-      if (uniform_output)
-        {
-          std::list<octave_value_list> idx_list (1);
-          idx_list.front ().resize (1);
-          std::string idx_type = "(";
-
-          OCTAVE_LOCAL_BUFFER (octave_value, retv, nargout1);
-
-          for (octave_idx_type count = 0; count < k; count++)
-            {
-              for (int j = 0; j < nargin; j++)
-                {
-                  if (mask[j])
-                    inputlist.xelem (j) = cinputs[j](count);
-                }
-
-              const octave_value_list tmp
-                = get_output_list (count, nargout, inputlist, func,
-                                   error_handler);
-
-              if (error_state)
-                return retval;
-
-              if (nargout > 0 && tmp.length () < nargout)
-                {
-                  error ("cellfun: function returned fewer than nargout values");
-                  return retval;
-                }
-
-              if  (nargout > 0
-                   || (nargout == 0
-                       && tmp.length () > 0 && tmp(0).is_defined ()))
-                {
-                  int num_to_copy = tmp.length ();
-
-                  if (num_to_copy > nargout1)
-                    num_to_copy = nargout1;
-
-                  if (count == 0)
-                    {
-                      for (int j = 0; j < num_to_copy; j++)
-                        {
-                          if (tmp(j).is_defined ())
-                            {
-                              octave_value val = tmp(j);
-
-                              if (val.numel () == 1)
-                                retv[j] = val.resize (fdims);
-                              else
-                                {
-                                  error ("cellfun: all values must be scalars when UniformOutput = true");
-                                  break;
-                                }
-                            }
-                        }
-                    }
-                  else
-                    {
-                      for (int j = 0; j < num_to_copy; j++)
-                        {
-                          if (tmp(j).is_defined ())
-                            {
-                              octave_value val = tmp(j);
-
-                              if (! retv[j].fast_elem_insert (count, val))
-                                {
-                                  if (val.numel () == 1)
-                                    {
-                                      idx_list.front ()(0) = count + 1.0;
-                                      retv[j].assign (octave_value::op_asn_eq,
-                                                      idx_type, idx_list, val);
-
-                                      if (error_state)
-                                        break;
-                                    }
-                                  else
-                                    {
-                                      error ("cellfun: all values must be scalars when UniformOutput = true");
-                                      break;
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-
-              if (error_state)
-                break;
-            }
-
-          retval.resize (nargout1);
-
-          for (int j = 0; j < nargout1; j++)
-            {
-              if (nargout > 0 && retv[j].is_undefined ())
-                retval(j) = NDArray (fdims);
-              else
-                retval(j) = retv[j];
-            }
-        }
-      else
-        {
-          OCTAVE_LOCAL_BUFFER (Cell, results, nargout1);
-
-          for (int j = 0; j < nargout1; j++)
-            results[j].resize (fdims, Matrix ());
-
-          bool have_some_output = false;
-
-          for (octave_idx_type count = 0; count < k; count++)
-            {
-              for (int j = 0; j < nargin; j++)
-                {
-                  if (mask[j])
-                    inputlist.xelem (j) = cinputs[j](count);
-                }
-
-              const octave_value_list tmp
-                = get_output_list (count, nargout, inputlist, func,
-                                   error_handler);
-
-              if (error_state)
-                return retval;
-
-              if (nargout > 0 && tmp.length () < nargout)
-                {
-                  error ("cellfun: function returned fewer than nargout values");
-                  return retval;
-                }
-
-              if  (nargout > 0
-                   || (nargout == 0
-                       && tmp.length () > 0 && tmp(0).is_defined ()))
-                {
-                  int num_to_copy = tmp.length ();
-
-                  if (num_to_copy > nargout1)
-                    num_to_copy = nargout1;
-
-                  if (num_to_copy > 0)
-                    have_some_output = true;
-
-                  for (int j = 0; j < num_to_copy; j++)
-                    results[j](count) = tmp(j);
-                }
-            }
-
-          if (have_some_output || fdims.any_zero ())
-            {
-              retval.resize (nargout1);
-
-              for (int j = 0; j < nargout1; j++)
-                retval(j) = results[j];
-            }
-        }
-    }
-  else
-    error ("cellfun: argument NAME must be a string or function handle");
-
-  return retval;
-}
-
-/*
-
-%!function r = __f11 (x)
-%!  global __cellfun_test_num_outputs__;
-%!  __cellfun_test_num_outputs__ = nargout;
-%!  r = x;
-%!endfunction
-
-%!function __f01 (x)
-%!  global __cellfun_test_num_outputs__;
-%!  __cellfun_test_num_outputs__ = nargout;
-%!endfunction
-
-%!test
-%! global __cellfun_test_num_outputs__;
-%! cellfun (@__f11, {1});
-%! assert (__cellfun_test_num_outputs__, 0);
-%! x = cellfun (@__f11, {1});
-%! assert (__cellfun_test_num_outputs__, 1);
-
-%!test
-%! global __cellfun_test_num_outputs__;
-%! cellfun (@__f01, {1});
-%! assert (__cellfun_test_num_outputs__, 0);
-
-%!error x = cellfun (@__f01, {1, 2});
-
-%!test
-%! assert (cellfun (@__f11, {1, 2}), [1, 2]);
-%! assert (cellfun (@__f11, {1, 2}, 'uniformoutput', false), {1, 2});
-
-%!test
-%! [a,b] = cellfun (@(x) x, cell (2, 0));
-%! assert (a, zeros (2, 0));
-%! assert (b, zeros (2, 0));
-
-%!test
-%! [a,b] = cellfun (@(x) x, cell (2, 0), "uniformoutput", false);
-%! assert (a, cell (2, 0));
-%! assert (b, cell (2, 0));
-
-%% Test function to check the "Errorhandler" option
-%!function z = __cellfunerror (S, varargin)
-%!  z = S;
-%!endfunction
-
-%% First input argument can be a string, an inline function,
-%% a function_handle or an anonymous function
-%!test
-%! A = cellfun ("islogical", {true, 0.1, false, i*2});
-%! assert (A, [true, false, true, false]);
-%!test
-%! A = cellfun (inline ("islogical (x)", "x"), {true, 0.1, false, i*2});
-%! assert (A, [true, false, true, false]);
-%!test
-%! A = cellfun (@islogical, {true, 0.1, false, i*2});
-%! assert (A, [true, false, true, false]);
-%!test
-%! A = cellfun (@(x) islogical (x), {true, 0.1, false, i*2});
-%! assert (A, [true, false, true, false]);
-
-%% First input argument can be the special string "isreal",
-%% "isempty", "islogical", "length", "ndims" or "prodofsize"
-%!test
-%! A = cellfun ("isreal", {true, 0.1, {}, i*2, [], "abc"});
-%! assert (A, [true, true, false, false, true, true]);
-%!test
-%! A = cellfun ("isempty", {true, 0.1, false, i*2, [], "abc"});
-%! assert (A, [false, false, false, false, true, false]);
-%!test
-%! A = cellfun ("islogical", {true, 0.1, false, i*2, [], "abc"});
-%! assert (A, [true, false, true, false, false, false]);
-%!test
-%! A = cellfun ("length", {true, 0.1, false, i*2, [], "abc"});
-%! assert (A, [1, 1, 1, 1, 0, 3]);
-%!test
-%! A = cellfun ("ndims", {[1, 2; 3, 4]; (cell (1,2,3,4))});
-%! assert (A, [2; 4]);
-%!test
-%! A = cellfun ("prodofsize", {[1, 2; 3, 4], (cell (1,2,3,4))});
-%! assert (A, [4, 24]);
-
-%% Number of input and output arguments may not be limited to one
-%!test
-%! A = cellfun (@(x,y,z) x + y + z, {1, 1, 1}, {2, 2, 2}, {3, 4, 5});
-%! assert (A, [6, 7, 8]);
-%!test
-%! A = cellfun (@(x,y,z) x + y + z, {1, 1, 1}, {2, 2, 2}, {3, 4, 5}, \
-%!              "UniformOutput", false);
-%! assert (A, {6, 7, 8});
-%!test %% Two input arguments of different types
-%! A = cellfun (@(x,y) islogical (x) && ischar (y), {false, true}, {"a", 3});
-%! assert (A, [true, false]);
-%!test %% Pass another variable to the anonymous function
-%! y = true;
-%! A = cellfun (@(x) islogical (x) && y, {false, 0.3});
-%! assert (A, [true, false]);
-%!test %% Three ouptut arguments of different type
-%! [A, B, C] = cellfun (@find, {10, 11; 0, 12}, "UniformOutput", false);
-%! assert (isequal (A, {true, true; [], true}));
-%! assert (isequal (B, {true, true; [], true}));
-%! assert (isequal (C, {10, 11; [], 12}));
-
-%% Input arguments can be of type cell array of logical
-%!test
-%! A = cellfun (@(x,y) x == y, {false, true}, {true, true});
-%! assert (A, [false, true]);
-%!test
-%! A = cellfun (@(x,y) x == y, {false; true}, {true; true}, \
-%!              "UniformOutput", true);
-%! assert (A, [false; true]);
-%!test
-%! A = cellfun (@(x) x, {false, true; false, true}, "UniformOutput", false);
-%! assert (A, {false, true; false, true});
-%!test %% Three ouptut arguments of same type
-%! [A, B, C] = cellfun (@find, {true, false; false, true}, \
-%!                      "UniformOutput", false);
-%! assert (isequal (A, {true, []; [], true}));
-%! assert (isequal (B, {true, []; [], true}));
-%! assert (isequal (C, {true, []; [], true}));
-%!test
-%! A = cellfun (@(x,y) cell2str (x,y), {true}, {true}, \
-%!              "ErrorHandler", @__cellfunerror);
-%! assert (isfield (A, "identifier"), true);
-%! assert (isfield (A, "message"), true);
-%! assert (isfield (A, "index"), true);
-%! assert (isempty (A.message), false);
-%! assert (A.index, 1);
-%!test %% Overwriting setting of "UniformOutput" true
-%! A = cellfun (@(x,y) cell2str (x,y), {true}, {true}, \
-%!              "UniformOutput", true, "ErrorHandler", @__cellfunerror);
-%! assert (isfield (A, "identifier"), true);
-%! assert (isfield (A, "message"), true);
-%! assert (isfield (A, "index"), true);
-%! assert (isempty (A.message), false);
-%! assert (A.index, 1);
-
-%% Input arguments can be of type cell array of numeric
-%!test
-%! A = cellfun (@(x,y) x>y, {1.1, 4.2}, {3.1, 2+3*i});
-%! assert (A, [false, true]);
-%!test
-%! A = cellfun (@(x,y) x>y, {1.1, 4.2; 2, 4}, {3.1, 2; 2, 4+2*i}, \
-%!              "UniformOutput", true);
-%! assert (A, [false, true; false, false]);
-%!test
-%! A = cellfun (@(x,y) x:y, {1.1, 4}, {3.1, 6}, "UniformOutput", false);
-%! assert (isequal (A{1}, [1.1, 2.1, 3.1]));
-%! assert (isequal (A{2}, [4, 5, 6]));
-%!test %% Three ouptut arguments of different type
-%! [A, B, C] = cellfun (@find, {10, 11; 0, 12}, "UniformOutput", false);
-%! assert (isequal (A, {true, true; [], true}));
-%! assert (isequal (B, {true, true; [], true}));
-%! assert (isequal (C, {10, 11; [], 12}));
-%!test
-%! A = cellfun (@(x,y) cell2str (x,y), {1.1, 4}, {3.1, 6}, \
-%!              "ErrorHandler", @__cellfunerror);
-%! B = isfield (A(1), "message") && isfield (A(1), "index");
-%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
-%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
-%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
-%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
-%! assert ([A(1).index, A(2).index], [1, 2]);
-%!test %% Overwriting setting of "UniformOutput" true
-%! A = cellfun (@(x,y) cell2str (x,y), {1.1, 4}, {3.1, 6}, \
-%!              "UniformOutput", true, "ErrorHandler", @__cellfunerror);
-%! B = isfield (A(1), "message") && isfield (A(1), "index");
-%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
-%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
-%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
-%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
-%! assert ([A(1).index, A(2).index], [1, 2]);
-
-%% Input arguments can be of type cell arrays of character or strings
-%!error %% "UniformOutput" false should be used
-%! A = cellfun (@(x,y) x>y, {"ad", "c", "ghi"}, {"cc", "d", "fgh"});
-%!test
-%! A = cellfun (@(x,y) x>y, {"a"; "f"}, {"c"; "d"}, "UniformOutput", true);
-%! assert (A, [false; true]);
-%!test
-%! A = cellfun (@(x,y) x:y, {"a", "d"}, {"c", "f"}, "UniformOutput", false);
-%! assert (A, {"abc", "def"});
-%!test
-%! A = cellfun (@(x,y) cell2str (x,y), {"a", "d"}, {"c", "f"}, \
-%!              "ErrorHandler", @__cellfunerror);
-%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
-%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
-%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
-%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
-%! assert ([A(1).index, A(2).index], [1, 2]);
-%!test %% Overwriting setting of "UniformOutput" true
-%! A = cellfun (@(x,y) cell2str (x,y), {"a", "d"}, {"c", "f"}, \
-%!              "UniformOutput", true, "ErrorHandler", @__cellfunerror);
-%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
-%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
-%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
-%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
-%! assert ([A(1).index, A(2).index], [1, 2]);
-
-%% Structures cannot be handled by cellfun
-%!error
-%! vst1.a = 1.1;  vst1.b = 4.2;  vst2.a = 3.1;  vst2.b = 2;
-%! A = cellfun (@(x,y) (x.a < y.a) && (x.b > y.b), vst1, vst2);
-
-%% Input arguments can be of type cell array of cell arrays
-%!test
-%! A = cellfun (@(x,y) x{1} < y{1}, {{1.1}, {4.2}}, {{3.1}, {2}});
-%! assert (A, [1, 0], 1e-16);
-%!test
-%! A = cellfun (@(x,y) x{1} < y{1}, {{1.1}; {4.2}}, {{3.1}; {2}}, \
-%!              "UniformOutput", true);
-%! assert (A, [1; 0], 1e-16);
-%!test
-%! A = cellfun (@(x,y) x{1} < y{1}, {{1.1}, {4.2}}, {{3.1}, {2}}, \
-%!              "UniformOutput", false);
-%! assert (A, {true, false});
-%!test
-%! A = cellfun (@(x,y) mat2str (x,y), {{1.1}, {4.2}}, {{3.1}, {2}}, \
-%!              "ErrorHandler", @__cellfunerror);
-%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
-%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
-%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
-%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
-%! assert ([A(1).index, A(2).index], [1, 2]);
-%!test %% Overwriting setting of "UniformOutput" true
-%! A = cellfun (@(x,y) mat2str (x,y), {{1.1}, {4.2}}, {{3.1}, {2}}, \
-%!              "UniformOutput", true, "ErrorHandler", @__cellfunerror);
-%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
-%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
-%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
-%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
-%! assert ([A(1).index, A(2).index], [1, 2]);
-
-%% Input arguments can be of type cell array of structure arrays
-%!test
-%! a = struct ("a", 1, "b", 2);  b = struct ("a", 1, "b", 3);
-%! A = cellfun (@(x,y) (x.a == y.a) && (x.b < y.b), {a}, {b});
-%! assert (A, true);
-%!test
-%! a = struct ("a", 1, "b", 2);  b = struct ("a", 1, "b", 3);
-%! A = cellfun (@(x,y) (x.a == y.a) && (x.b < y.b) , {a}, {b}, \
-%!              "UniformOutput", true);
-%! assert (A, true);
-%!test
-%! a = struct ("a", 1, "b", 2);  b = struct ("a", 1, "b", 3);
-%! A = cellfun (@(x,y) (x.a == y.a) && (x.b < y.b) , {a}, {b}, \
-%!              "UniformOutput", false);
-%! assert (A, {true});
-%!test
-%! a = struct ("a", 1, "b", 2);  b = struct ("a", 1, "b", 3);
-%! A = cellfun (@(x,y) cell2str (x.a, y.a), {a}, {b}, \
-%!              "ErrorHandler", @__cellfunerror);
-%! assert (isfield (A, "identifier"), true);
-%! assert (isfield (A, "message"), true);
-%! assert (isfield (A, "index"), true);
-%! assert (isempty (A.message), false);
-%! assert (A.index, 1);
-%!test %% Overwriting setting of "UniformOutput" true
-%! a = struct ("a", 1, "b", 2);  b = struct ("a", 1, "b", 3);
-%! A = cellfun (@(x,y) cell2str (x.a, y.a), {a}, {b}, \
-%!              "UniformOutput", true, "ErrorHandler", @__cellfunerror);
-%! assert (isfield (A, "identifier"), true);
-%! assert (isfield (A, "message"), true);
-%! assert (isfield (A, "index"), true);
-%! assert (isempty (A.message), false);
-%! assert (A.index, 1);
-
-%% A lot of other tests
-%!assert (cellfun (@sin, {0,1}), sin ([0,1]))
-%!assert (cellfun (inline ("sin (x)"), {0,1}), sin ([0,1]))
-%!assert (cellfun ("sin", {0,1}), sin ([0,1]))
-%!assert (cellfun ("isempty", {1,[]}), [false,true])
-%!assert (cellfun ("islogical", {false,pi}), [true,false])
-%!assert (cellfun ("isreal", {1i,1}), [false,true])
-%!assert (cellfun ("length", {zeros(2,2),1}), [2,1])
-%!assert (cellfun ("prodofsize", {zeros(2,2),1}), [4,1])
-%!assert (cellfun ("ndims", {zeros([2,2,2]),1}), [3,2])
-%!assert (cellfun ("isclass", {zeros([2,2,2]),"test"}, "double"), [true,false])
-%!assert (cellfun ("size", {zeros([1,2,3]),1}, 1), [1,1])
-%!assert (cellfun ("size", {zeros([1,2,3]),1}, 2), [2,1])
-%!assert (cellfun ("size", {zeros([1,2,3]),1}, 3), [3,1])
-%!assert (cellfun (@atan2, {1,1}, {1,2}), [atan2(1,1), atan2(1,2)])
-%!assert (cellfun (@atan2, {1,1}, {1,2},"UniformOutput", false), {atan2(1,1), atan2(1,2)})
-%!assert (cellfun (@sin, {1,2;3,4}), sin ([1,2;3,4]))
-%!assert (cellfun (@atan2, {1,1;1,1}, {1,2;1,2}), atan2 ([1,1;1,1],[1,2;1,2]))
-%!error cellfun (@factorial, {-1,3})
-%!assert (cellfun (@factorial,{-1,3},"ErrorHandler",@(x,y) NaN), [NaN,6])
-%!test
-%! [a,b,c] = cellfun (@fileparts, {fullfile("a","b","c.d"), fullfile("e","f","g.h")}, "UniformOutput", false);
-%! assert (a, {fullfile("a","b"), fullfile("e","f")});
-%! assert (b, {"c", "g"});
-%! assert (c, {".d", ".h"});
-
-%!error cellfun (1)
-%!error cellfun ("isclass", 1)
-%!error cellfun ("size", 1)
-%!error cellfun (@sin, {[]}, "BadParam", false)
-%!error cellfun (@sin, {[]}, "UniformOuput")
-%!error cellfun (@sin, {[]}, "ErrorHandler")
-*/
-
-// Arrayfun was originally a .m file written by Bill Denney and Jaroslav
-// Hajek.  It was converted to C++ by jwe so that it could properly
-// handle the nargout = 0 case.
-
-DEFUN_DLD (arrayfun, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Function File} {} arrayfun (@var{func}, @var{A})\n\
-@deftypefnx {Function File} {@var{x} =} arrayfun (@var{func}, @var{A})\n\
-@deftypefnx {Function File} {@var{x} =} arrayfun (@var{func}, @var{A}, @var{b}, @dots{})\n\
-@deftypefnx {Function File} {[@var{x}, @var{y}, @dots{}] =} arrayfun (@var{func}, @var{A}, @dots{})\n\
-@deftypefnx {Function File} {} arrayfun (@dots{}, \"UniformOutput\", @var{val})\n\
-@deftypefnx {Function File} {} arrayfun (@dots{}, \"ErrorHandler\", @var{errfunc})\n\
-\n\
-Execute a function on each element of an array.  This is useful for\n\
-functions that do not accept array arguments.  If the function does\n\
-accept array arguments it is better to call the function directly.\n\
-\n\
-The first input argument @var{func} can be a string, a function\n\
-handle, an inline function, or an anonymous function.  The input\n\
-argument @var{A} can be a logic array, a numeric array, a string\n\
-array, a structure array, or a cell array.  By a call of the function\n\
-@command{arrayfun} all elements of @var{A} are passed on to the named\n\
-function @var{func} individually.\n\
-\n\
-The named function can also take more than two input arguments, with\n\
-the input arguments given as third input argument @var{b}, fourth\n\
-input argument @var{c}, @dots{}  If given more than one array input\n\
-argument then all input arguments must have the same sizes, for\n\
-example:\n\
-\n\
-@example\n\
-@group\n\
-arrayfun (@@atan2, [1, 0], [0, 1])\n\
-     @result{} [ 1.5708   0.0000 ]\n\
-@end group\n\
-@end example\n\
-\n\
-If the parameter @var{val} after a further string input argument\n\
-\"UniformOutput\" is set @code{true} (the default), then the named\n\
-function @var{func} must return a single element which then will be\n\
-concatenated into the return value and is of type matrix.  Otherwise,\n\
-if that parameter is set to @code{false}, then the outputs are\n\
-concatenated in a cell array.  For example:\n\
-\n\
-@example\n\
-@group\n\
-arrayfun (@@(x,y) x:y, \"abc\", \"def\", \"UniformOutput\", false)\n\
-@result{}\n\
-   @{\n\
-     [1,1] = abcd\n\
-     [1,2] = bcde\n\
-     [1,3] = cdef\n\
-   @}\n\
-@end group\n\
-@end example\n\
-\n\
-If more than one output arguments are given then the named function\n\
-must return the number of return values that also are expected, for\n\
-example:\n\
-\n\
-@example\n\
-@group\n\
-[A, B, C] = arrayfun (@@find, [10; 0], \"UniformOutput\", false)\n\
-@result{}\n\
-A =\n\
-@{\n\
-   [1,1] =  1\n\
-   [2,1] = [](0x0)\n\
-@}\n\
-B =\n\
-@{\n\
-   [1,1] =  1\n\
-   [2,1] = [](0x0)\n\
-@}\n\
-C =\n\
-@{\n\
-   [1,1] =  10\n\
-   [2,1] = [](0x0)\n\
-@}\n\
-@end group\n\
-@end example\n\
-\n\
-If the parameter @var{errfunc} after a further string input argument\n\
-\"ErrorHandler\" is another string, a function handle, an inline\n\
-function, or an anonymous function, then @var{errfunc} defines a\n\
-function to call in the case that @var{func} generates an error.\n\
-The definition of the function must be of the form\n\
-\n\
-@example\n\
-function [@dots{}] = errfunc (@var{s}, @dots{})\n\
-@end example\n\
-\n\
-@noindent\n\
-where there is an additional input argument to @var{errfunc}\n\
-relative to @var{func}, given by @var{s}.  This is a structure with\n\
-the elements \"identifier\", \"message\", and \"index\" giving,\n\
-respectively, the error identifier, the error message, and the index of\n\
-the array elements that caused the error.  The size of the output\n\
-argument of @var{errfunc} must have the same size as the output\n\
-argument of @var{func}, otherwise a real error is thrown.  For\n\
-example:\n\
-\n\
-@example\n\
-@group\n\
-function y = ferr (s, x), y = \"MyString\"; endfunction\n\
-arrayfun (@@str2num, [1234],\n\
-          \"UniformOutput\", false, \"ErrorHandler\", @@ferr)\n\
-@result{}\n\
-   @{\n\
-     [1,1] = MyString\n\
-   @}\n\
-@end group\n\
-@end example\n\
-\n\
-@seealso{spfun, cellfun, structfun}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-  int nargin = args.length ();
-  int nargout1 = (nargout < 1 ? 1 : nargout);
-
-  if (nargin < 2)
-    {
-      error ("arrayfun: function requires at least 2 arguments");
-      print_usage ();
-      return retval;
-    }
-
-  octave_value func = args(0);
-  bool symbol_table_lookup = false;
-
-  if (func.is_string ())
-    {
-      // See if we can convert the string into a function.
-
-      std::string name = args(0).string_value ();
-
-      if (! valid_identifier (name))
-        {
-          std::string fcn_name = unique_symbol_name ("__arrayfun_fcn_");
-          std::string fname = "function y = " + fcn_name + "(x) y = ";
-
-          octave_function *ptr_func
-            = extract_function (args(0), "arrayfun", fcn_name,
-                                fname, "; endfunction");
-
-          if (ptr_func && ! error_state)
-            func = octave_value (ptr_func, true);
-        }
-      else
-        {
-          func = symbol_table::find_function (name);
-
-          if (func.is_undefined ())
-            error ("arrayfun: invalid function NAME: %s", name.c_str ());
-
-          symbol_table_lookup = true;
-        }
-
-      if (error_state)
-        return retval;
-    }
-
-  if (func.is_function_handle () || func.is_inline_function ()
-      || func.is_function ())
-    {
-      // The following is an optimisation because the symbol table can
-      // give a more specific function class, so this can result in
-      // fewer polymorphic function calls as the function gets called
-      // for each value of the array.
-
-      if (! symbol_table_lookup )
-        {
-          if (func.is_function_handle ())
-            {
-              octave_fcn_handle* f = func.fcn_handle_value ();
-
-              // Overloaded function handles need to check the type of
-              // the arguments for each element of the array, so they
-              // cannot be optimised this way.
-
-              if (f -> is_overloaded ())
-                goto nevermind;
-            }
-          octave_value f = symbol_table::find_function (func.function_value ()
-                                                         -> name ());
-          if (f.is_defined ())
-            func = f;
-        }
-
-    nevermind:
-
-      bool uniform_output = true;
-      octave_value error_handler;
-      
-      get_mapper_fun_options (args, nargin, uniform_output, error_handler);
-
-      if (error_state)
-        return octave_value_list ();
-
-      octave_value_list inputlist (nargin, octave_value ());
-
-      OCTAVE_LOCAL_BUFFER (octave_value, inputs, nargin);
-      OCTAVE_LOCAL_BUFFER (bool, mask, nargin);
-
-      octave_idx_type k = 1;
-
-      dim_vector fdims (1, 1);
-
-      // Collect arguments.  Pre-fill scalar elements of inputlist
-      // array.
-
-      for (int j = 0; j < nargin; j++)
-        {
-          inputs[j] = args(j+1);
-          mask[j] = inputs[j].numel () != 1;
-
-          if (! mask[j])
-            inputlist(j) = inputs[j];
-        }
-
-      for (int j = 0; j < nargin; j++)
-        {
-          if (mask[j])
-            {
-              fdims = inputs[j].dims ();
-              k = inputs[j].numel ();
-
-              for (int i = j+1; i < nargin; i++)
-                {
-                  if (mask[i] && inputs[i].dims () != fdims)
-                    {
-                      error ("arrayfun: dimensions mismatch");
-                      return retval;
-                    }
-                }
-              break;
-            }
-        }
-
-
-      unwind_protect frame;
-      frame.protect_var (buffer_error_messages);
-
-      if (error_handler.is_defined ())
-        buffer_error_messages++;
-
-      // Apply functions.
-
-      if (uniform_output)
-        {
-          std::list<octave_value_list> idx_list (1);
-          idx_list.front ().resize (1);
-          std::string idx_type = "(";
-
-          OCTAVE_LOCAL_BUFFER (octave_value, retv, nargout1);
-
-          for (octave_idx_type count = 0; count < k; count++)
-            {
-              idx_list.front ()(0) = count + 1.0;
-
-              for (int j = 0; j < nargin; j++)
-                {
-                  if (mask[j])
-                    inputlist.xelem (j) = inputs[j].do_index_op (idx_list);
-
-                  if (error_state)
-                    return retval;
-                }
-
-              const octave_value_list tmp
-                = get_output_list (count, nargout, inputlist, func,
-                                   error_handler);
-
-              if (error_state)
-                return retval;
-
-              if (nargout > 0 && tmp.length () < nargout)
-                {
-                  error ("arrayfun: function returned fewer than nargout values");
-                  return retval;
-                }
-
-              if  (nargout > 0
-                   || (nargout == 0
-                       && tmp.length () > 0 && tmp(0).is_defined ()))
-                {
-                  int num_to_copy = tmp.length ();
-
-                  if (num_to_copy > nargout1)
-                    num_to_copy = nargout1;
-
-                  if (count == 0)
-                    {
-                      for (int j = 0; j < num_to_copy; j++)
-                        {
-                          if (tmp(j).is_defined ())
-                            {
-                              octave_value val = tmp(j);
-
-                              if (val.numel () == 1)
-                                retv[j] = val.resize (fdims);
-                              else
-                                {
-                                  error ("arrayfun: all values must be scalars when UniformOutput = true");
-                                  break;
-                                }
-                            }
-                        }
-                    }
-                  else
-                    {
-                      for (int j = 0; j < num_to_copy; j++)
-                        {
-                          if (tmp(j).is_defined ())
-                            {
-                              octave_value val = tmp(j);
-
-                              if (! retv[j].fast_elem_insert (count, val))
-                                {
-                                  if (val.numel () == 1)
-                                    {
-                                      idx_list.front ()(0) = count + 1.0;
-                                      retv[j].assign (octave_value::op_asn_eq,
-                                                      idx_type, idx_list, val);
-
-                                      if (error_state)
-                                        break;
-                                    }
-                                  else
-                                    {
-                                      error ("arrayfun: all values must be scalars when UniformOutput = true");
-                                      break;
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-
-              if (error_state)
-                break;
-            }
-
-          retval.resize (nargout1);
-
-          for (int j = 0; j < nargout1; j++)
-            {
-              if (nargout > 0 && retv[j].is_undefined ())
-                retval(j) = NDArray (fdims);
-              else
-                retval(j) = retv[j];
-            }
-        }
-      else
-        {
-          std::list<octave_value_list> idx_list (1);
-          idx_list.front ().resize (1);
-          std::string idx_type = "(";
-
-          OCTAVE_LOCAL_BUFFER (Cell, results, nargout1);
-
-          for (int j = 0; j < nargout1; j++)
-            results[j].resize (fdims, Matrix ());
-
-          bool have_some_output = false;
-
-          for (octave_idx_type count = 0; count < k; count++)
-            {
-              idx_list.front ()(0) = count + 1.0;
-
-              for (int j = 0; j < nargin; j++)
-                {
-                  if (mask[j])
-                    inputlist.xelem (j) = inputs[j].do_index_op (idx_list);
-
-                  if (error_state)
-                    return retval;
-                }
-
-              const octave_value_list tmp
-                = get_output_list (count, nargout, inputlist, func,
-                                   error_handler);
-
-              if (error_state)
-                return retval;
-
-              if (nargout > 0 && tmp.length () < nargout)
-                {
-                  error ("arrayfun: function returned fewer than nargout values");
-                  return retval;
-                }
-
-              if  (nargout > 0
-                   || (nargout == 0
-                       && tmp.length () > 0 && tmp(0).is_defined ()))
-                {
-                  int num_to_copy = tmp.length ();
-
-                  if (num_to_copy > nargout1)
-                    num_to_copy = nargout1;
-
-                  if (num_to_copy > 0)
-                    have_some_output = true;
-
-                  for (int j = 0; j < num_to_copy; j++)
-                    results[j](count) = tmp(j);
-                }
-            }
-
-          if (have_some_output || fdims.any_zero ())
-            {
-              retval.resize (nargout1);
-
-              for (int j = 0; j < nargout1; j++)
-                retval(j) = results[j];
-            }
-        }
-    }
-  else
-    error ("arrayfun: argument NAME must be a string or function handle");
-
-  return retval;
-}
-
-/*
-%!function r = __f11 (x)
-%!  global __arrayfun_test_num_outputs__;
-%!  __arrayfun_test_num_outputs__ = nargout;
-%!  r = x;
-%!endfunction
-
-%!function __f01 (x)
-%!  global __arrayfun_test_num_outputs__;
-%!  __arrayfun_test_num_outputs__ = nargout;
-%!endfunction
-
-%!test
-%! global __arrayfun_test_num_outputs__;
-%! arrayfun (@__f11, {1});
-%! assert (__arrayfun_test_num_outputs__, 0);
-%! x = arrayfun (@__f11, {1});
-%! assert (__arrayfun_test_num_outputs__, 1);
-
-%!test
-%! global __arrayfun_test_num_outputs__;
-%! arrayfun (@__f01, {1});
-%! assert (__arrayfun_test_num_outputs__, 0);
-
-%!error x = arrayfun (@__f01, [1, 2]);
-
-%!test
-%! assert (arrayfun (@__f11, [1, 2]), [1, 2]);
-%! assert (arrayfun (@__f11, [1, 2], "uniformoutput", false), {1, 2});
-%! assert (arrayfun (@__f11, {1, 2}), {1, 2});
-%! assert (arrayfun (@__f11, {1, 2}, "uniformoutput", false), {{1}, {2}});
-
-%!assert (arrayfun (@ones, 1, [2,3], "uniformoutput", false), {[1,1], [1,1,1]})
-
-%% Test function to check the "Errorhandler" option
-%!function z = __arrayfunerror (S, varargin)
-%!  z = S;
-%!endfunction
-%% First input argument can be a string, an inline function, a
-%% function_handle or an anonymous function
-%!test
-%! arrayfun (@isequal, [false, true], [true, true]); %% No output argument
-%!error
-%! arrayfun (@isequal); %% One or less input arguments
-%!test
-%! A = arrayfun ("isequal", [false, true], [true, true]);
-%! assert (A, [false, true]);
-%!test
-%! A = arrayfun (inline ("(x == y)", "x", "y"), [false, true], [true, true]);
-%! assert (A, [false, true]);
-%!test
-%! A = arrayfun (@isequal, [false, true], [true, true]);
-%! assert (A, [false, true]);
-%!test
-%! A = arrayfun (@(x,y) isequal (x,y), [false, true], [true, true]);
-%! assert (A, [false, true]);
-
-%% Number of input and output arguments may be greater than one
-%#!test
-%! A = arrayfun (@(x) islogical (x), false);
-%! assert (A, true);
-%!test
-%! A = arrayfun (@(x,y,z) x + y + z, [1, 1, 1], [2, 2, 2], [3, 4, 5]);
-%! assert (A, [6, 7, 8], 1e-16);
-%!test %% Two input arguments of different types
-%! A = arrayfun (@(x,y) islogical (x) && ischar (y), false, "a");
-%! assert (A, true);
-%!test %% Pass another variable to the anonymous function
-%! y = true;
-%! A = arrayfun (@(x) islogical (x && y), false);
-%! assert (A, true);
-%!test %% Three ouptut arguments of different type
-%! [A, B, C] = arrayfun (@find, [10, 11; 0, 12], "UniformOutput", false);
-%! assert (isequal (A, {true, true; [], true}));
-%! assert (isequal (B, {true, true; [], true}));
-%! assert (isequal (C, {10, 11; [], 12}));
-
-%% Input arguments can be of type logical
-%!test
-%! A = arrayfun (@(x,y) x == y, [false, true], [true, true]);
-%! assert (A, [false, true]);
-%!test
-%! A = arrayfun (@(x,y) x == y, [false; true], [true; true], "UniformOutput", true);
-%! assert (A, [false; true]);
-%!test
-%! A = arrayfun (@(x) x, [false, true, false, true], "UniformOutput", false);
-%! assert (A, {false, true, false, true});
-%!test %% Three ouptut arguments of same type
-%! [A, B, C] = arrayfun (@find, [true, false; false, true], "UniformOutput", false);
-%! assert (isequal (A, {true, []; [], true}));
-%! assert (isequal (B, {true, []; [], true}));
-%! assert (isequal (C, {true, []; [], true}));
-%!test
-%! A = arrayfun (@(x,y) array2str (x,y), true, true, \
-%!               "ErrorHandler", @__arrayfunerror);
-%! assert (isfield (A, "identifier"), true);
-%! assert (isfield (A, "message"), true);
-%! assert (isfield (A, "index"), true);
-%! assert (isempty (A.message), false);
-%! assert (A.index, 1);
-%!test %% Overwriting setting of "UniformOutput" true
-%! A = arrayfun (@(x,y) array2str (x,y), true, true, "UniformOutput", true, \
-%!               "ErrorHandler", @__arrayfunerror);
-%! assert (isfield (A, "identifier"), true);
-%! assert (isfield (A, "message"), true);
-%! assert (isfield (A, "index"), true);
-%! assert (isempty (A.message), false);
-%! assert (A.index, 1);
-
-%% Input arguments can be of type numeric
-%!test
-%! A = arrayfun (@(x,y) x>y, [1.1, 4.2], [3.1, 2+3*i]);
-%! assert (A, [false, true]);
-%!test
-%! A = arrayfun (@(x,y) x>y, [1.1, 4.2; 2, 4], [3.1, 2; 2, 4+2*i], "UniformOutput", true);
-%! assert (A, [false, true; false, false]);
-%!test
-%! A = arrayfun (@(x,y) x:y, [1.1, 4], [3.1, 6], "UniformOutput", false);
-%! assert (isequal (A{1}, [1.1, 2.1, 3.1]));
-%! assert (isequal (A{2}, [4, 5, 6]));
-%!test %% Three ouptut arguments of different type
-%! [A, B, C] = arrayfun (@find, [10, 11; 0, 12], "UniformOutput", false);
-%! assert (isequal (A, {true, true; [], true}));
-%! assert (isequal (B, {true, true; [], true}));
-%! assert (isequal (C, {10, 11; [], 12}));
-%!test
-%! A = arrayfun (@(x,y) array2str (x,y), {1.1, 4}, {3.1, 6}, \
-%!               "ErrorHandler", @__arrayfunerror);
-%! B = isfield (A(1), "message") && isfield (A(1), "index");
-%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
-%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
-%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
-%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
-%! assert ([A(1).index, A(2).index], [1, 2]);
-%!test %% Overwriting setting of "UniformOutput" true
-%! A = arrayfun (@(x,y) array2str (x,y), {1.1, 4}, {3.1, 6}, \
-%!               "UniformOutput", true, "ErrorHandler", @__arrayfunerror);
-%! B = isfield (A(1), "message") && isfield (A(1), "index");
-%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
-%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
-%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
-%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
-%! assert ([A(1).index, A(2).index], [1, 2]);
-
-%% Input arguments can be of type character or strings
-%!test
-%! A = arrayfun (@(x,y) x>y, ["ad", "c", "ghi"], ["cc", "d", "fgh"]);
-%! assert (A, [false, true, false, true, true, true]);
-%!test
-%! A = arrayfun (@(x,y) x>y, ["a"; "f"], ["c"; "d"], "UniformOutput", true);
-%! assert (A, [false; true]);
-%!test
-%! A = arrayfun (@(x,y) x:y, ["a", "d"], ["c", "f"], "UniformOutput", false);
-%! assert (A, {"abc", "def"});
-%!test
-%! A = arrayfun (@(x,y) cell2str (x,y), ["a", "d"], ["c", "f"], \
-%!               "ErrorHandler", @__arrayfunerror);
-%! B = isfield (A(1), "identifier") && isfield (A(1), "message") && isfield (A(1), "index");
-%! assert (B, true);
-
-%% Input arguments can be of type structure
-%!test
-%! a = struct ("a", 1.1, "b", 4.2);  b = struct ("a", 3.1, "b", 2);
-%! A = arrayfun (@(x,y) (x.a < y.a) && (x.b > y.b), a, b);
-%! assert (A, true);
-%!test
-%! a = struct ("a", 1.1, "b", 4.2);  b = struct ("a", 3.1, "b", 2);
-%! A = arrayfun (@(x,y) (x.a < y.a) && (x.b > y.b), a, b, "UniformOutput", true);
-%! assert (A, true);
-%!test
-%! a = struct ("a", 1.1, "b", 4.2);  b = struct ("a", 3.1, "b", 2);
-%! A = arrayfun (@(x,y) x.a:y.a, a, b, "UniformOutput", false);
-%! assert (isequal (A, {[1.1, 2.1, 3.1]}));
-%!test
-%! A = arrayfun (@(x) mat2str(x), "a", "ErrorHandler", @__arrayfunerror);
-%! assert (isfield (A, "identifier"), true);
-%! assert (isfield (A, "message"), true);
-%! assert (isfield (A, "index"), true);
-%! assert (isempty (A.message), false);
-%! assert (A.index, 1);
-%!test %% Overwriting setting of "UniformOutput" true
-%! A = arrayfun (@(x) mat2str(x), "a", "UniformOutput", true, \
-%!               "ErrorHandler", @__arrayfunerror);
-%! assert (isfield (A, "identifier"), true);
-%! assert (isfield (A, "message"), true);
-%! assert (isfield (A, "index"), true);
-%! assert (isempty (A.message), false);
-%! assert (A.index, 1);
-
-%% Input arguments can be of type cell array
-%!test
-%! A = arrayfun (@(x,y) x{1} < y{1}, {1.1, 4.2}, {3.1, 2});
-%! assert (A, [true, false]);
-%!test
-%! A = arrayfun (@(x,y) x{1} < y{1}, {1.1; 4.2}, {3.1; 2}, "UniformOutput", true);
-%! assert (A, [true; false]);
-%!test
-%! A = arrayfun (@(x,y) x{1} < y{1}, {1.1, 4.2}, {3.1, 2}, "UniformOutput", false);
-%! assert (A, {true, false});
-%!test
-%! A = arrayfun (@(x,y) num2str(x,y), {1.1, 4.2}, {3.1, 2}, "ErrorHandler", @__arrayfunerror);
-%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
-%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
-%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
-%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
-%! assert ([A(1).index, A(2).index], [1, 2]);
-%!test
-%! A = arrayfun (@(x,y) num2str (x,y), {1.1, 4.2}, {3.1, 2}, \
-%!               "UniformOutput", true, "ErrorHandler", @__arrayfunerror);
-%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
-%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
-%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
-%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
-%! assert ([A(1).index, A(2).index], [1, 2]);
-*/
-
-static void
-do_num2cell_helper (const dim_vector& dv,
-                    const Array<int>& dimv,
-                    dim_vector& celldv, dim_vector& arraydv,
-                    Array<int>& perm)
-{
-  int dvl = dimv.length ();
-  int maxd = dv.length ();
-  celldv = dv;
-  for (int i = 0; i < dvl; i++)
-    maxd = std::max (maxd, dimv(i));
-  if (maxd > dv.length ())
-    celldv.resize (maxd, 1);
-  arraydv = celldv;
-
-  OCTAVE_LOCAL_BUFFER_INIT (bool, sing, maxd, false);
-
-  perm.clear (maxd, 1);
-  for (int i = 0; i < dvl; i++)
-    {
-      int k = dimv(i) - 1;
-      if (k < 0)
-        {
-          error ("num2cell: dimension indices must be positive");
-          return;
-        }
-      else if (i > 0 && k < dimv(i-1) - 1)
-        {
-          error ("num2cell: dimension indices must be strictly increasing");
-          return;
-        }
-
-      sing[k] = true;
-      perm(i) = k;
-    }
-
-  for (int k = 0, i = dvl; k < maxd; k++)
-    if (! sing[k])
-      perm(i++) = k;
-
-  for (int i = 0; i < maxd; i++)
-    if (sing[i])
-      celldv(i) = 1;
-    else
-      arraydv(i) = 1;
-}
-
-template<class NDA>
-static inline typename NDA::element_type
-do_num2cell_elem (const NDA& array, octave_idx_type i)
-{ return array(i); }
-
-static inline Cell
-do_num2cell_elem (const Cell& array, octave_idx_type i)
-{ return Cell (array(i)); }
-
-
-template<class NDA>
-static Cell
-do_num2cell (const NDA& array, const Array<int>& dimv)
-{
-  if (dimv.is_empty ())
-    {
-      Cell retval (array.dims ());
-      octave_idx_type nel = array.numel ();
-      for (octave_idx_type i = 0; i < nel; i++)
-        retval.xelem (i) = do_num2cell_elem (array, i);
-
-      return retval;
-    }
-  else
-    {
-      dim_vector celldv, arraydv;
-      Array<int> perm;
-      do_num2cell_helper (array.dims (), dimv, celldv, arraydv, perm);
-      if (error_state)
-        return Cell ();
-
-      NDA parray = array.permute (perm);
-
-      octave_idx_type nela = arraydv.numel (), nelc = celldv.numel ();
-      parray = parray.reshape (dim_vector (nela, nelc));
-
-      Cell retval (celldv);
-      for (octave_idx_type i = 0; i < nelc; i++)
-        {
-          retval.xelem (i) = NDA (parray.column (i).reshape (arraydv));
-        }
-
-      return retval;
-    }
-}
-
-// FIXME -- this is a mess, but if a size method for the object exists,
-// we have to call it to get the size of the object instead of using the
-// internal dims method.
-
-static dim_vector
-get_object_dims (octave_value& obj)
-{
-  dim_vector retval;
-
-  Matrix m = obj.size ();
-
-  int n = m.numel ();
-
-  retval.resize (n);
-
-  for (int i = 0; i < n; i++)
-    retval(i) = m(i);
-
-  return retval;
-}
-
-static Cell
-do_object2cell (const octave_value& obj, const Array<int>& dimv)
-{
-  Cell retval;
-
-  // FIXME -- this copy is only needed because the octave_value::size
-  // method is not const.
-  octave_value array = obj;
-
-  if (dimv.is_empty ())
-    {
-      dim_vector dv = get_object_dims (array);
-
-      if (! error_state)
-        {
-          retval.resize (dv);
-
-          octave_value_list idx (1);
-
-          for (octave_idx_type i = 0; i < dv.numel (); i++)
-            {
-              octave_quit ();
-
-              idx(0) = double (i+1);
-
-              retval.xelem (i) = array.single_subsref ("(", idx);
-
-              if (error_state)
-                break;
-            }
-        }
-    }
-  else
-    {
-      error ("num2cell (A, dim) not implemented for class objects");
-    }
-
-  return retval;
-}
-
-DEFUN_DLD (num2cell, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{C} =} num2cell (@var{A})\n\
-@deftypefnx {Loadable Function} {@var{C} =} num2cell (@var{A}, @var{dim})\n\
-Convert the numeric matrix @var{A} to a cell array.  If @var{dim} is\n\
-defined, the value @var{C} is of dimension 1 in this dimension and the\n\
-elements of @var{A} are placed into @var{C} in slices.  For example:\n\
-\n\
-@example\n\
-@group\n\
-num2cell ([1,2;3,4])\n\
-   @result{}\n\
-      @{\n\
-        [1,1] =  1\n\
-        [2,1] =  3\n\
-        [1,2] =  2\n\
-        [2,2] =  4\n\
-      @}\n\
-num2cell ([1,2;3,4],1)\n\
-   @result{}\n\
-      @{\n\
-        [1,1] =\n\
-           1\n\
-           3\n\
-        [1,2] =\n\
-           2\n\
-           4\n\
-      @}\n\
-@end group\n\
-@end example\n\
-\n\
-@seealso{mat2cell}\n\
-@end deftypefn")
-{
-  int nargin =  args.length ();
-  octave_value retval;
-
-  if (nargin < 1 || nargin > 2)
-    print_usage ();
-  else
-    {
-      octave_value array = args(0);
-      Array<int> dimv;
-      if (nargin > 1)
-        dimv = args (1).int_vector_value (true);
-
-      if (error_state)
-        ;
-      else if (array.is_bool_type ())
-        retval = do_num2cell (array.bool_array_value (), dimv);
-      else if (array.is_char_matrix ())
-        retval = do_num2cell (array.char_array_value (), dimv);
-      else if (array.is_numeric_type ())
-        {
-          if (array.is_integer_type ())
-            {
-              if (array.is_int8_type ())
-                retval = do_num2cell (array.int8_array_value (), dimv);
-              else if (array.is_int16_type ())
-                retval = do_num2cell (array.int16_array_value (), dimv);
-              else if (array.is_int32_type ())
-                retval = do_num2cell (array.int32_array_value (), dimv);
-              else if (array.is_int64_type ())
-                retval = do_num2cell (array.int64_array_value (), dimv);
-              else if (array.is_uint8_type ())
-                retval = do_num2cell (array.uint8_array_value (), dimv);
-              else if (array.is_uint16_type ())
-                retval = do_num2cell (array.uint16_array_value (), dimv);
-              else if (array.is_uint32_type ())
-                retval = do_num2cell (array.uint32_array_value (), dimv);
-              else if (array.is_uint64_type ())
-                retval = do_num2cell (array.uint64_array_value (), dimv);
-            }
-          else if (array.is_complex_type ())
-            {
-              if (array.is_single_type ())
-                retval = do_num2cell (array.float_complex_array_value (), dimv);
-              else
-                retval = do_num2cell (array.complex_array_value (), dimv);
-            }
-          else
-            {
-              if (array.is_single_type ())
-                retval = do_num2cell (array.float_array_value (), dimv);
-              else
-                retval = do_num2cell (array.array_value (), dimv);
-            }
-        }
-      else if (array.is_object ())
-        retval = do_object2cell (array, dimv);
-      else if (array.is_map ())
-        retval = do_num2cell (array.map_value (), dimv);
-      else if (array.is_cell ())
-        retval = do_num2cell (array.cell_value (), dimv);
-      else if (array.is_object ())
-        retval = do_num2cell (array.cell_value (), dimv);
-      else
-        gripe_wrong_type_arg ("num2cell", array);
-    }
-
-  return retval;
-}
-
-/*
-%!assert (num2cell ([1,2;3,4]), {1,2;3,4})
-%!assert (num2cell ([1,2;3,4], 1), {[1;3],[2;4]})
-%!assert (num2cell ([1,2;3,4], 2), {[1,2];[3,4]})
-*/
-
-static bool
-mat2cell_mismatch (const dim_vector& dv,
-                   const Array<octave_idx_type> *d, int nd)
-{
-  for (int i = 0; i < nd; i++)
-    {
-      octave_idx_type s = 0;
-      for (octave_idx_type j = 0; j < d[i].length (); j++)
-        s += d[i](j);
-
-      octave_idx_type r = i < dv.length () ? dv(i) : 1;
-
-      if (s != r)
-        {
-          error ("mat2cell: mismatch on %d-th dimension (%d != %d)",
-                 i+1, r, s);
-          return true;
-        }
-    }
-
-  return false;
-}
-
-template<class container>
-static void
-prepare_idx (container *idx, int idim, int nd,
-             const Array<octave_idx_type>* d)
-{
-  octave_idx_type nidx = idim < nd ? d[idim].numel () : 1;
-  if (nidx == 1)
-    idx[0] = idx_vector::colon;
-  else
-    {
-      octave_idx_type l = 0;
-      for (octave_idx_type i = 0; i < nidx; i++)
-        {
-          octave_idx_type u = l + d[idim](i);
-          idx[i] = idx_vector (l, u);
-          l = u;
-        }
-    }
-}
-
-// 2D specialization, works for Array, Sparse and octave_map.
-// Uses 1D or 2D indexing.
-
-template <class Array2D>
-static Cell
-do_mat2cell_2d (const Array2D& a, const Array<octave_idx_type> *d, int nd)
-{
-  NoAlias<Cell> retval;
-  assert (nd == 1 || nd == 2);
-  assert (a.ndims () == 2);
-
-  if (mat2cell_mismatch (a.dims (), d, nd))
-    return retval;
-
-  octave_idx_type nridx = d[0].length ();
-  octave_idx_type ncidx = nd == 1 ? 1 : d[1].length ();
-  retval.clear (nridx, ncidx);
-
-  int ivec = -1;
-  if (a.rows () > 1 && a.cols () == 1 && ncidx == 1)
-    ivec = 0;
-  else if (a.rows () == 1 && nridx == 1 && nd == 2)
-    ivec = 1;
-
-  if (ivec >= 0)
-    {
-      // Vector split. Use 1D indexing.
-      octave_idx_type l = 0, nidx = (ivec == 0 ? nridx : ncidx);
-      for (octave_idx_type i = 0; i < nidx; i++)
-        {
-          octave_idx_type u = l + d[ivec](i);
-          retval(i) = a.index (idx_vector (l, u));
-          l = u;
-        }
-    }
-  else
-    {
-      // General 2D case. Use 2D indexing.
-      OCTAVE_LOCAL_BUFFER (idx_vector, ridx, nridx);
-      prepare_idx (ridx, 0, nd, d);
-
-      OCTAVE_LOCAL_BUFFER (idx_vector, cidx, ncidx);
-      prepare_idx (cidx, 1, nd, d);
-
-      for (octave_idx_type j = 0; j < ncidx; j++)
-        for (octave_idx_type i = 0; i < nridx; i++)
-          {
-            octave_quit ();
-
-            retval(i,j) = a.index (ridx[i], cidx[j]);
-          }
-    }
-
-  return retval;
-}
-
-// Nd case. Works for Arrays and octave_map.
-// Uses Nd indexing.
-
-template <class ArrayND>
-Cell
-do_mat2cell_nd (const ArrayND& a, const Array<octave_idx_type> *d, int nd)
-{
-  NoAlias<Cell> retval;
-  assert (nd >= 1);
-
-  if (mat2cell_mismatch (a.dims (), d, nd))
-    return retval;
-
-  dim_vector rdv = dim_vector::alloc (nd);
-  OCTAVE_LOCAL_BUFFER (octave_idx_type, nidx, nd);
-  octave_idx_type idxtot = 0;
-  for (int i = 0; i < nd; i++)
-    {
-      rdv(i) = nidx[i] = d[i].length ();
-      idxtot += nidx[i];
-    }
-
-  retval.clear (rdv);
-
-  OCTAVE_LOCAL_BUFFER (idx_vector, xidx, idxtot);
-  OCTAVE_LOCAL_BUFFER (idx_vector *, idx, nd);
-
-  idxtot = 0;
-  for (int i = 0; i < nd; i++)
-    {
-      idx[i] = xidx + idxtot;
-      prepare_idx (idx[i], i, nd, d);
-      idxtot += nidx[i];
-    }
-
-  OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, ridx, nd, 0);
-  NoAlias< Array<idx_vector> > ra_idx
-    (dim_vector (1, std::max (nd, a.ndims ())), idx_vector::colon);
-
-  for (octave_idx_type j = 0; j < retval.numel (); j++)
-    {
-      octave_quit ();
-
-      for (int i = 0; i < nd; i++)
-        ra_idx(i) = idx[i][ridx[i]];
-
-      retval(j) = a.index (ra_idx);
-
-      rdv.increment_index (ridx);
-    }
-
-  return retval;
-}
-
-// Dispatcher.
-template <class ArrayND>
-Cell
-do_mat2cell (const ArrayND& a, const Array<octave_idx_type> *d, int nd)
-{
-  if (a.ndims () == 2 && nd <= 2)
-    return do_mat2cell_2d (a, d, nd);
-  else
-    return do_mat2cell_nd (a, d, nd);
-}
-
-// General case. Works for any class supporting do_index_op.
-// Uses Nd indexing.
-
-Cell
-do_mat2cell (octave_value& a, const Array<octave_idx_type> *d, int nd)
-{
-  NoAlias<Cell> retval;
-  assert (nd >= 1);
-
-  if (mat2cell_mismatch (a.dims (), d, nd))
-    return retval;
-
-  dim_vector rdv = dim_vector::alloc (nd);
-  OCTAVE_LOCAL_BUFFER (octave_idx_type, nidx, nd);
-  octave_idx_type idxtot = 0;
-  for (int i = 0; i < nd; i++)
-    {
-      rdv(i) = nidx[i] = d[i].length ();
-      idxtot += nidx[i];
-    }
-
-  retval.clear (rdv);
-
-  OCTAVE_LOCAL_BUFFER (octave_value, xidx, idxtot);
-  OCTAVE_LOCAL_BUFFER (octave_value *, idx, nd);
-
-  idxtot = 0;
-  for (int i = 0; i < nd; i++)
-    {
-      idx[i] = xidx + idxtot;
-      prepare_idx (idx[i], i, nd, d);
-      idxtot += nidx[i];
-    }
-
-  OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, ridx, nd, 0);
-  octave_value_list ra_idx (std::max (nd, a.ndims ()),
-                            octave_value::magic_colon_t);
-
-  for (octave_idx_type j = 0; j < retval.numel (); j++)
-    {
-      octave_quit ();
-
-      for (int i = 0; i < nd; i++)
-        ra_idx(i) = idx[i][ridx[i]];
-
-      retval(j) = a.do_index_op (ra_idx);
-
-      if (error_state)
-        break;
-
-      rdv.increment_index (ridx);
-    }
-
-  return retval;
-}
-
-DEFUN_DLD (mat2cell, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{C} =} mat2cell (@var{A}, @var{m}, @var{n})\n\
-@deftypefnx {Loadable Function} {@var{C} =} mat2cell (@var{A}, @var{d1}, @var{d2}, @dots{})\n\
-@deftypefnx {Loadable Function} {@var{C} =} mat2cell (@var{A}, @var{r})\n\
-Convert the matrix @var{A} to a cell array.  If @var{A} is 2-D, then\n\
-it is required that @code{sum (@var{m}) == size (@var{A}, 1)} and\n\
-@code{sum (@var{n}) == size (@var{A}, 2)}.  Similarly, if @var{A} is\n\
-multi-dimensional and the number of dimensional arguments is equal\n\
-to the dimensions of @var{A}, then it is required that @code{sum (@var{di})\n\
-== size (@var{A}, i)}.\n\
-\n\
-Given a single dimensional argument @var{r}, the other dimensional\n\
-arguments are assumed to equal @code{size (@var{A},@var{i})}.\n\
-\n\
-An example of the use of mat2cell is\n\
-\n\
-@example\n\
-mat2cell (reshape (1:16,4,4), [3,1], [3,1])\n\
-@result{}\n\
-@{\n\
-   [1,1] =\n\
-\n\
-      1   5   9\n\
-      2   6  10\n\
-      3   7  11\n\
-\n\
-   [2,1] =\n\
-\n\
-      4   8  12\n\
-\n\
-   [1,2] =\n\
-\n\
-     13\n\
-     14\n\
-     15\n\
-\n\
-   [2,2] = 16\n\
-@}\n\
-@end example\n\
-@seealso{num2cell, cell2mat}\n\
-@end deftypefn")
-{
-  int nargin = args.length ();
-  octave_value retval;
-
-  if (nargin < 2)
-    print_usage ();
-  else
-    {
-      // Prepare indices.
-      OCTAVE_LOCAL_BUFFER (Array<octave_idx_type>, d, nargin-1);
-
-      for (int i = 1; i < nargin; i++)
-        {
-          d[i-1] = args(i).octave_idx_type_vector_value (true);
-          if (error_state)
-            return retval;
-        }
-
-      octave_value a = args(0);
-      bool sparse = a.is_sparse_type ();
-      if (sparse && nargin > 3)
-        {
-          error ("mat2cell: sparse arguments only support 2D indexing");
-          return retval;
-        }
-
-      switch (a.builtin_type ())
-        {
-        case btyp_double:
-          {
-            if (sparse)
-              retval = do_mat2cell_2d (a.sparse_matrix_value (), d, nargin-1);
-            else
-              retval = do_mat2cell (a.array_value (), d, nargin - 1);
-            break;
-          }
-        case btyp_complex:
-          {
-            if (sparse)
-              retval = do_mat2cell_2d (a.sparse_complex_matrix_value (), d, nargin-1);
-            else
-              retval = do_mat2cell (a.complex_array_value (), d, nargin - 1);
-            break;
-          }
-#define BTYP_BRANCH(X,Y) \
-        case btyp_ ## X: \
-            retval = do_mat2cell (a.Y ## _value (), d, nargin - 1); \
-          break
-
-        BTYP_BRANCH (float, float_array);
-        BTYP_BRANCH (float_complex, float_complex_array);
-        BTYP_BRANCH (bool, bool_array);
-        BTYP_BRANCH (char, char_array);
-
-        BTYP_BRANCH (int8,  int8_array);
-        BTYP_BRANCH (int16, int16_array);
-        BTYP_BRANCH (int32, int32_array);
-        BTYP_BRANCH (int64, int64_array);
-        BTYP_BRANCH (uint8,  uint8_array);
-        BTYP_BRANCH (uint16, uint16_array);
-        BTYP_BRANCH (uint32, uint32_array);
-        BTYP_BRANCH (uint64, uint64_array);
-
-        BTYP_BRANCH (cell, cell);
-        BTYP_BRANCH (struct, map);
-#undef BTYP_BRANCH
-
-        case btyp_func_handle:
-          gripe_wrong_type_arg ("mat2cell", a);
-          break;
-        default:
-          retval = do_mat2cell (a, d, nargin-1);
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!test
-%! x = reshape (1:20, 5, 4);
-%! c = mat2cell (x, [3,2], [3,1]);
-%! assert (c, {[1,6,11;2,7,12;3,8,13],[16;17;18];[4,9,14;5,10,15],[19;20]});
-
-%!test
-%! x = "abcdefghij";
-%! c = mat2cell (x, 1, [0,4,2,0,4,0]);
-%! empty1by0str = resize ("", 1, 0);
-%! assert (c, {empty1by0str,"abcd","ef",empty1by0str,"ghij",empty1by0str});
-*/
-
-// FIXME: it would be nice to allow ranges being handled without a conversion.
-template <class NDA>
-static Cell
-do_cellslices_nda (const NDA& array,
-                   const Array<octave_idx_type>& lb,
-                   const Array<octave_idx_type>& ub,
-                   int dim = -1)
-{
-  octave_idx_type n = lb.length ();
-  Cell retval (1, n);
-  if (array.is_vector () && (dim == -1
-                             || (dim == 0 && array.columns () == 1)
-                             || (dim == 1 && array.rows () == 1)))
-    {
-      for (octave_idx_type i = 0; i < n && ! error_state; i++)
-        retval(i) = array.index (idx_vector (lb(i) - 1, ub(i)));
-    }
-  else
-    {
-      const dim_vector dv = array.dims ();
-      int ndims = dv.length ();
-      if (dim < 0)
-        dim = dv.first_non_singleton ();
-      ndims = std::max (ndims, dim + 1);
-
-      Array<idx_vector> idx (dim_vector (ndims, 1), idx_vector::colon);
-
-      for (octave_idx_type i = 0; i < n && ! error_state; i++)
-        {
-          idx(dim) = idx_vector (lb(i) - 1, ub(i));
-          retval(i) = array.index (idx);
-        }
-    }
-
-  return retval;
-}
-
-DEFUN_DLD (cellslices, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{sl} =} cellslices (@var{x}, @var{lb}, @var{ub}, @var{dim})\n\
-Given an array @var{x}, this function produces a cell array of slices from\n\
-the array determined by the index vectors @var{lb}, @var{ub}, for lower and\n\
-upper bounds, respectively.  In other words, it is equivalent to the\n\
-following code:\n\
-\n\
-@example\n\
-@group\n\
-n = length (lb);\n\
-sl = cell (1, n);\n\
-for i = 1:length (lb)\n\
-  sl@{i@} = x(:,@dots{},lb(i):ub(i),@dots{},:);\n\
-endfor\n\
-@end group\n\
-@end example\n\
-\n\
-The position of the index is determined by @var{dim}.  If not specified,\n\
-slicing is done along the first non-singleton dimension.\n\
-@seealso{cell2mat, cellindexmat, cellfun}\n\
-@end deftypefn")
-{
-  octave_value retval;
-  int nargin = args.length ();
-  if (nargin == 3 || nargin == 4)
-    {
-      octave_value x = args(0);
-      Array<octave_idx_type> lb = args(1).octave_idx_type_vector_value ();
-      Array<octave_idx_type> ub = args(2).octave_idx_type_vector_value ();
-      int dim = -1;
-      if (nargin == 4)
-        {
-          dim = args(3).int_value () - 1;
-          if (dim < 0)
-            error ("cellslices: DIM must be a valid dimension");
-        }
-
-      if (! error_state)
-        {
-          if (lb.length () != ub.length ())
-            error ("cellslices: the lengths of LB and UB must match");
-          else
-            {
-              Cell retcell;
-              if (! x.is_sparse_type () && x.is_matrix_type ())
-                {
-                  // specialize for some dense arrays.
-                  if (x.is_bool_type ())
-                    retcell = do_cellslices_nda (x.bool_array_value (), lb, ub, dim);
-                  else if (x.is_char_matrix ())
-                    retcell = do_cellslices_nda (x.char_array_value (), lb, ub, dim);
-                  else if (x.is_integer_type ())
-                    {
-                      if (x.is_int8_type ())
-                        retcell = do_cellslices_nda (x.int8_array_value (), lb, ub, dim);
-                      else if (x.is_int16_type ())
-                        retcell = do_cellslices_nda (x.int16_array_value (), lb, ub, dim);
-                      else if (x.is_int32_type ())
-                        retcell = do_cellslices_nda (x.int32_array_value (), lb, ub, dim);
-                      else if (x.is_int64_type ())
-                        retcell = do_cellslices_nda (x.int64_array_value (), lb, ub, dim);
-                      else if (x.is_uint8_type ())
-                        retcell = do_cellslices_nda (x.uint8_array_value (), lb, ub, dim);
-                      else if (x.is_uint16_type ())
-                        retcell = do_cellslices_nda (x.uint16_array_value (), lb, ub, dim);
-                      else if (x.is_uint32_type ())
-                        retcell = do_cellslices_nda (x.uint32_array_value (), lb, ub, dim);
-                      else if (x.is_uint64_type ())
-                        retcell = do_cellslices_nda (x.uint64_array_value (), lb, ub, dim);
-                    }
-                  else if (x.is_complex_type ())
-                    {
-                      if (x.is_single_type ())
-                        retcell = do_cellslices_nda (x.float_complex_array_value (), lb, ub, dim);
-                      else
-                        retcell = do_cellslices_nda (x.complex_array_value (), lb, ub, dim);
-                    }
-                  else
-                    {
-                      if (x.is_single_type ())
-                        retcell = do_cellslices_nda (x.float_array_value (), lb, ub, dim);
-                      else
-                        retcell = do_cellslices_nda (x.array_value (), lb, ub, dim);
-                    }
-                }
-              else
-                {
-                  // generic code.
-                  octave_idx_type n = lb.length ();
-                  retcell = Cell (1, n);
-                  const dim_vector dv = x.dims ();
-                  int ndims = dv.length ();
-                  if (dim < 0)
-                    dim = dv.first_non_singleton ();
-                  ndims = std::max (ndims, dim + 1);
-                  octave_value_list idx (ndims, octave_value::magic_colon_t);
-                  for (octave_idx_type i = 0; i < n && ! error_state; i++)
-                    {
-                      idx(dim) = Range (lb(i), ub(i));
-                      retcell(i) = x.do_index_op (idx);
-                    }
-                }
-              if (! error_state)
-                retval = retcell;
-            }
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!test
-%! m = [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12];
-%! c = cellslices (m, [1, 2], [2, 3], 2);
-%! assert (c, {[1, 2; 5, 6; 9, 10], [2, 3; 6, 7; 10, 11]});
-*/
-
-DEFUN_DLD (cellindexmat, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{y} =} cellindexmat (@var{x}, @var{varargin})\n\
-Given a cell array of matrices @var{x}, this function computes\n\
-\n\
-@example\n\
-@group\n\
-Y = cell (size (X));\n\
-for i = 1:numel (X)\n\
-  Y@{i@} = X@{i@}(varargin@{:@});\n\
-endfor\n\
-@end group\n\
-@end example\n\
-@seealso{cellslices, cellfun}\n\
-@end deftypefn")
-{
-  octave_value retval;
-  if (args.length () >= 1)
-    {
-      if (args(0).is_cell ())
-        {
-          const Cell x = args(0).cell_value ();
-          NoAlias<Cell> y(x.dims ());
-          octave_idx_type nel = x.numel ();
-          octave_value_list idx = args.slice (1, args.length () - 1);
-
-          for (octave_idx_type i = 0; i < nel; i++)
-            {
-              octave_quit ();
-              octave_value tmp = x(i);
-              y(i) = tmp.do_index_op (idx);
-              if (error_state)
-                break;
-            }
-
-          retval = y;
-        }
-      else
-        error ("cellindexmat: X must be a cell");
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
--- a/src/DLD-FUNCTIONS/colloc.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-
-#include "CollocWt.h"
-#include "lo-mappers.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-DEFUN_DLD (colloc, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{r}, @var{amat}, @var{bmat}, @var{q}] =} colloc (@var{n}, \"left\", \"right\")\n\
-Compute derivative and integral weight matrices for orthogonal\n\
-collocation using the subroutines given in J. Villadsen and\n\
-M. L. Michelsen, @cite{Solution of Differential Equation Models by\n\
-Polynomial Approximation}.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 1 || nargin > 3)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  if (! args(0).is_scalar_type ())
-    {
-      error ("colloc: N must be a scalar");
-      return retval;
-    }
-
-  double tmp = args(0).double_value ();
-
-  if (error_state)
-    return retval;
-
-  if (xisnan (tmp))
-    {
-      error ("colloc: N cannot be NaN");
-      return retval;
-    }
-
-  octave_idx_type ncol = NINTbig (tmp);
-  if (ncol < 0)
-    {
-      error ("colloc: N must be positive");
-      return retval;
-    }
-
-  octave_idx_type ntot = ncol;
-  octave_idx_type left = 0;
-  octave_idx_type right = 0;
-
-  for (int i = 1; i < nargin; i++)
-    {
-      if (args(i).is_defined ())
-        {
-          if (! args(i).is_string ())
-            {
-              error ("colloc: expecting string argument \"left\" or \"right\"");
-              return retval;
-            }
-
-          std::string s = args(i).string_value ();
-
-          if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r'))
-              || s == "right")
-            {
-              right = 1;
-            }
-          else if ((s.length () == 1 && (s[0] == 'L' || s[0] == 'l'))
-                   || s == "left")
-            {
-              left = 1;
-            }
-          else
-            {
-              error ("colloc: unrecognized argument");
-              return retval;
-            }
-        }
-      else
-        {
-          error ("colloc: unexpected empty argument");
-          return retval;
-        }
-    }
-
-  ntot += left + right;
-  if (ntot < 1)
-    {
-      error ("colloc: the total number of roots must be positive");
-      return retval;
-    }
-
-  CollocWt wts (ncol, left, right);
-
-  ColumnVector r = wts.roots ();
-  Matrix A = wts.first ();
-  Matrix B = wts.second ();
-  ColumnVector q = wts.quad_weights ();
-
-  retval(3) = q;
-  retval(2) = B;
-  retval(1) = A;
-  retval(0) = r;
-
-  return retval;
-}
--- a/src/DLD-FUNCTIONS/config-module.awk	Fri Jul 27 17:10:25 2012 -0400
+++ b/src/DLD-FUNCTIONS/config-module.awk	Fri Jul 27 21:59:10 2012 -0400
@@ -52,7 +52,7 @@
   }
   print "else";
   print "";
-  print "noinst_LTLIBRARIES = $(DLD_FUNCTIONS_LIBS)";
+  print "noinst_LTLIBRARIES += $(DLD_FUNCTIONS_LIBS)";
   print "";
   print "endif";
 
--- a/src/DLD-FUNCTIONS/conv2.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,393 +0,0 @@
-/*
-
-Copyright (C) 1999-2012 Andy Adler
-Copyright (C) 2010 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "oct-convn.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-enum Shape { SHAPE_FULL, SHAPE_SAME, SHAPE_VALID };
-
-DEFUN_DLD (conv2, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} conv2 (@var{A}, @var{B})\n\
-@deftypefnx {Loadable Function} {} conv2 (@var{v1}, @var{v2}, @var{m})\n\
-@deftypefnx {Loadable Function} {} conv2 (@dots{}, @var{shape})\n\
-Return the 2-D convolution of @var{A} and @var{B}.  The size of the result\n\
-is determined by the optional @var{shape} argument which takes the following\n\
-values\n\
-\n\
-@table @asis\n\
-@item @var{shape} = \"full\"\n\
-Return the full convolution.  (default)\n\
-\n\
-@item @var{shape} = \"same\"\n\
-Return the central part of the convolution with the same size as @var{A}.\n\
-The central part of the convolution begins at the indices\n\
-@code{floor ([size(@var{B})/2] + 1)}.\n\
-\n\
-@item @var{shape} = \"valid\"\n\
-Return only the parts which do not include zero-padded edges.\n\
-The size of the result is @code{max (size (A) - size (B) + 1, 0)}.\n\
-@end table\n\
-\n\
-When the third argument is a matrix, return the convolution of the matrix\n\
-@var{m} by the vector @var{v1} in the column direction and by the vector\n\
-@var{v2} in the row direction.\n\
-@seealso{conv, convn}\n\
-@end deftypefn")
-{
-  octave_value retval;
-  octave_value tmp;
-  int nargin = args.length ();
-  std::string shape = "full";   // default
-  bool separable = false;
-  convn_type ct;
-
-  if (nargin < 2)
-    {
-     print_usage ();
-     return retval;
-    }
-  else if (nargin == 3)
-    {
-      if (args(2).is_string ())
-        shape = args(2).string_value ();
-      else
-        separable = true;
-    }
-  else if (nargin >= 4)
-    {
-      separable = true;
-      shape = args(3).string_value ();
-    }
-
-  if (shape == "full")
-    ct = convn_full;
-  else if (shape == "same")
-    ct = convn_same;
-  else if (shape == "valid")
-    ct = convn_valid;
-  else
-    {
-      error ("conv2: SHAPE type not valid");
-      print_usage ();
-      return retval;
-    }
-
-   if (separable)
-     {
-      // If user requests separable, check first two params are vectors
-
-       if (! (1 == args(0).rows () || 1 == args(0).columns ())
-           || ! (1 == args(1).rows () || 1 == args(1).columns ()))
-         {
-           print_usage ();
-           return retval;
-         }
-
-       if (args(0).is_single_type () || args(1).is_single_type ()
-           || args(2).is_single_type ())
-         {
-           if (args(0).is_complex_type () || args(1).is_complex_type ()
-               || args(2).is_complex_type ())
-             {
-               FloatComplexMatrix a (args(2).float_complex_matrix_value ());
-               if (args(1).is_real_type () && args(2).is_real_type ())
-                 {
-                   FloatColumnVector v1 (args(0).float_vector_value ());
-                   FloatRowVector v2 (args(1).float_vector_value ());
-                   retval = convn (a, v1, v2, ct);
-                 }
-               else
-                 {
-                   FloatComplexColumnVector v1 (args(0).float_complex_vector_value ());
-                   FloatComplexRowVector v2 (args(1).float_complex_vector_value ());
-                   retval = convn (a, v1, v2, ct);
-                 }
-             }
-           else
-             {
-               FloatColumnVector v1 (args(0).float_vector_value ());
-               FloatRowVector v2 (args(1).float_vector_value ());
-               FloatMatrix a (args(2).float_matrix_value ());
-               retval = convn (a, v1, v2, ct);
-             }
-         }
-       else
-         {
-           if (args(0).is_complex_type () || args(1).is_complex_type ()
-               || args(2).is_complex_type ())
-             {
-               ComplexMatrix a (args(2).complex_matrix_value ());
-               if (args(1).is_real_type () && args(2).is_real_type ())
-                 {
-                   ColumnVector v1 (args(0).vector_value ());
-                   RowVector v2 (args(1).vector_value ());
-                   retval = convn (a, v1, v2, ct);
-                 }
-               else
-                 {
-                   ComplexColumnVector v1 (args(0).complex_vector_value ());
-                   ComplexRowVector v2 (args(1).complex_vector_value ());
-                   retval = convn (a, v1, v2, ct);
-                 }
-             }
-           else
-             {
-               ColumnVector v1 (args(0).vector_value ());
-               RowVector v2 (args(1).vector_value ());
-               Matrix a (args(2).matrix_value ());
-               retval = convn (a, v1, v2, ct);
-             }
-         }
-     } // if (separable)
-   else
-     {
-       if (args(0).is_single_type () || args(1).is_single_type ())
-         {
-           if (args(0).is_complex_type () || args(1).is_complex_type ())
-             {
-               FloatComplexMatrix a (args(0).float_complex_matrix_value ());
-               if (args(1).is_real_type ())
-                 {
-                   FloatMatrix b (args(1).float_matrix_value ());
-                   retval = convn (a, b, ct);
-                 }
-               else
-                 {
-                   FloatComplexMatrix b (args(1).float_complex_matrix_value ());
-                   retval = convn (a, b, ct);
-                 }
-             }
-           else
-             {
-               FloatMatrix a (args(0).float_matrix_value ());
-               FloatMatrix b (args(1).float_matrix_value ());
-               retval = convn (a, b, ct);
-             }
-         }
-       else
-         {
-           if (args(0).is_complex_type () || args(1).is_complex_type ())
-             {
-               ComplexMatrix a (args(0).complex_matrix_value ());
-               if (args(1).is_real_type ())
-                 {
-                   Matrix b (args(1).matrix_value ());
-                   retval = convn (a, b, ct);
-                 }
-               else
-                 {
-                   ComplexMatrix b (args(1).complex_matrix_value ());
-                   retval = convn (a, b, ct);
-                 }
-             }
-           else
-             {
-               Matrix a (args(0).matrix_value ());
-               Matrix b (args(1).matrix_value ());
-               retval = convn (a, b, ct);
-             }
-         }
-
-     } // if (separable)
-
-   return retval;
-}
-
-/*
-%!test
-%! c = [0,1,2,3;1,8,12,12;4,20,24,21;7,22,25,18];
-%! assert (conv2 ([0,1;1,2], [1,2,3;4,5,6;7,8,9]), c);
-
-%!test
-%! c = single ([0,1,2,3;1,8,12,12;4,20,24,21;7,22,25,18]);
-%! assert (conv2 (single ([0,1;1,2]), single ([1,2,3;4,5,6;7,8,9])), c);
-
-%!test
-%! c = [1,4,4;5,18,16;14,48,40;19,62,48;15,48,36];
-%! assert (conv2 (1:3, 1:2, [1,2;3,4;5,6]), c);
-
-%!assert (conv2 (1:3, 1:2, [1,2;3,4;5,6], "full"),
-%!        conv2 (1:3, 1:2, [1,2;3,4;5,6]));
-
-%% Test shapes
-%!shared A, B, C
-%! A = rand (3, 4);
-%! B = rand (4);
-%! C = conv2 (A, B);
-%!assert (conv2 (A,B, "full"), C)
-%!assert (conv2 (A,B, "same"), C(3:5,3:6))
-%!assert (conv2 (A,B, "valid"), zeros (0, 1))
-%!assert (size (conv2 (B,A, "valid")), [2 1])
-
-%!test
-%! B = rand (5);
-%! C = conv2 (A, B);
-%!assert (conv2 (A,B, "full"), C)
-%!assert (conv2 (A,B, "same"), C(3:5,3:6))
-%!assert (conv2 (A,B, "valid"), zeros (0, 0))
-%!assert (size (conv2 (B,A, "valid")), [3 2])
-
-%% Clear shared variables so they are not reported for tests below
-%!shared
-
-%% Test cases from Bug #34893
-%!assert (conv2 ([1:5;1:5], [1:2], "same"), [4 7 10 13 10; 4 7 10 13 10])
-%!assert (conv2 ([1:5;1:5]', [1:2]', "same"), [4 7 10 13 10; 4 7 10 13 10]')
-%!assert (conv2 ([1:5;1:5], [1:2], "valid"), [4 7 10 13; 4 7 10 13])
-%!assert (conv2 ([1:5;1:5]', [1:2]', "valid"), [4 7 10 13; 4 7 10 13]')
-
-%!test
-%! rand ("seed", 42);
-%! x = rand (100);
-%! y = ones (5);
-%! A = conv2 (x, y)(5:end-4,5:end-4);
-%! B = conv2 (x, y, "valid");
-%! assert (B, A); ## Yes, this test is for *exact* equivalence.
-
-
-%% Test input validation
-%!error conv2 ()
-%!error conv2 (1)
-%!error <SHAPE type not valid> conv2 (1,2, "NOT_A_SHAPE")
-%% Test alternate calling form which should be 2 vectors and a matrix
-%!error conv2 (ones (2), 1, 1)
-%!error conv2 (1, ones (2), 1)
-*/
-
-DEFUN_DLD (convn, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{C} =} convn (@var{A}, @var{B})\n\
-@deftypefnx {Loadable Function} {@var{C} =} convn (@var{A}, @var{B}, @var{shape})\n\
-Return the n-D convolution of @var{A} and @var{B}.  The size of the result\n\
-is determined by the optional @var{shape} argument which takes the following\n\
-values\n\
-\n\
-@table @asis\n\
-@item @var{shape} = \"full\"\n\
-Return the full convolution.  (default)\n\
-\n\
-@item @var{shape} = \"same\"\n\
-Return central part of the convolution with the same size as @var{A}.\n\
-The central part of the convolution begins at the indices\n\
-@code{floor ([size(@var{B})/2] + 1)}.\n\
-\n\
-@item @var{shape} = \"valid\"\n\
-Return only the parts which do not include zero-padded edges.\n\
-The size of the result is @code{max (size (A) - size (B) + 1, 0)}.\n\
-@end table\n\
-\n\
-@seealso{conv2, conv}\n\
-@end deftypefn")
-{
-  octave_value retval;
-  octave_value tmp;
-  int nargin = args.length ();
-  std::string shape = "full";   // default
-  convn_type ct;
-
-  if (nargin < 2 || nargin > 3)
-    {
-     print_usage ();
-     return retval;
-    }
-  else if (nargin == 3)
-    {
-      if (args(2).is_string ())
-        shape = args(2).string_value ();
-    }
-
-  if (shape == "full")
-    ct = convn_full;
-  else if (shape == "same")
-    ct = convn_same;
-  else if (shape == "valid")
-    ct = convn_valid;
-  else
-    {
-      error ("convn: SHAPE type not valid");
-      print_usage ();
-      return retval;
-    }
-
-  if (args(0).is_single_type () || args(1).is_single_type ())
-    {
-      if (args(0).is_complex_type () || args(1).is_complex_type ())
-        {
-          FloatComplexNDArray a (args(0).float_complex_array_value ());
-          if (args(1).is_real_type ())
-            {
-              FloatNDArray b (args(1).float_array_value ());
-              retval = convn (a, b, ct);
-            }
-          else
-            {
-              FloatComplexNDArray b (args(1).float_complex_array_value ());
-              retval = convn (a, b, ct);
-            }
-        }
-      else
-        {
-          FloatNDArray a (args(0).float_array_value ());
-          FloatNDArray b (args(1).float_array_value ());
-          retval = convn (a, b, ct);
-        }
-    }
-  else
-    {
-      if (args(0).is_complex_type () || args(1).is_complex_type ())
-        {
-          ComplexNDArray a (args(0).complex_array_value ());
-          if (args(1).is_real_type ())
-            {
-              NDArray b (args(1).array_value ());
-              retval = convn (a, b, ct);
-            }
-          else
-            {
-              ComplexNDArray b (args(1).complex_array_value ());
-              retval = convn (a, b, ct);
-            }
-        }
-      else
-        {
-          NDArray a (args(0).array_value ());
-          NDArray b (args(1).array_value ());
-          retval = convn (a, b, ct);
-        }
-    }
-
-   return retval;
-}
-
-/*
- FIXME: Need tests for convn in addition to conv2.
-*/
--- a/src/DLD-FUNCTIONS/daspk.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,480 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-
-#include <iomanip>
-#include <iostream>
-
-#include "DASPK.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "ov-fcn.h"
-#include "ov-cell.h"
-#include "pager.h"
-#include "unwind-prot.h"
-#include "utils.h"
-#include "variables.h"
-
-#include "DASPK-opts.cc"
-
-// Global pointer for user defined function required by daspk.
-static octave_function *daspk_fcn;
-
-// Global pointer for optional user defined jacobian function.
-static octave_function *daspk_jac;
-
-// Have we warned about imaginary values returned from user function?
-static bool warned_fcn_imaginary = false;
-static bool warned_jac_imaginary = false;
-
-// Is this a recursive call?
-static int call_depth = 0;
-
-ColumnVector
-daspk_user_function (const ColumnVector& x, const ColumnVector& xdot,
-                     double t, octave_idx_type& ires)
-{
-  ColumnVector retval;
-
-  assert (x.capacity () == xdot.capacity ());
-
-  octave_value_list args;
-
-  args(2) = t;
-  args(1) = xdot;
-  args(0) = x;
-
-  if (daspk_fcn)
-    {
-      octave_value_list tmp = daspk_fcn->do_multi_index_op (1, args);
-
-      if (error_state)
-        {
-          gripe_user_supplied_eval ("daspk");
-          return retval;
-        }
-
-      int tlen = tmp.length ();
-      if (tlen > 0 && tmp(0).is_defined ())
-        {
-          if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
-            {
-              warning ("daspk: ignoring imaginary part returned from user-supplied function");
-              warned_fcn_imaginary = true;
-            }
-
-          retval = ColumnVector (tmp(0).vector_value ());
-
-          if (tlen > 1)
-            ires = tmp(1).int_value ();
-
-          if (error_state || retval.length () == 0)
-            gripe_user_supplied_eval ("daspk");
-        }
-      else
-        gripe_user_supplied_eval ("daspk");
-    }
-
-  return retval;
-}
-
-Matrix
-daspk_user_jacobian (const ColumnVector& x, const ColumnVector& xdot,
-                     double t, double cj)
-{
-  Matrix retval;
-
-  assert (x.capacity () == xdot.capacity ());
-
-  octave_value_list args;
-
-  args(3) = cj;
-  args(2) = t;
-  args(1) = xdot;
-  args(0) = x;
-
-  if (daspk_jac)
-    {
-      octave_value_list tmp = daspk_jac->do_multi_index_op (1, args);
-
-      if (error_state)
-        {
-          gripe_user_supplied_eval ("daspk");
-          return retval;
-        }
-
-      int tlen = tmp.length ();
-      if (tlen > 0 && tmp(0).is_defined ())
-        {
-          if (! warned_jac_imaginary && tmp(0).is_complex_type ())
-            {
-              warning ("daspk: ignoring imaginary part returned from user-supplied jacobian function");
-              warned_jac_imaginary = true;
-            }
-
-          retval = tmp(0).matrix_value ();
-
-          if (error_state || retval.length () == 0)
-            gripe_user_supplied_eval ("daspk");
-        }
-      else
-        gripe_user_supplied_eval ("daspk");
-    }
-
-  return retval;
-}
-
-#define DASPK_ABORT() \
-  return retval
-
-#define DASPK_ABORT1(msg) \
-  do \
-    { \
-      ::error ("daspk: " msg); \
-      DASPK_ABORT (); \
-    } \
-  while (0)
-
-#define DASPK_ABORT2(fmt, arg) \
-  do \
-    { \
-      ::error ("daspk: " fmt, arg); \
-      DASPK_ABORT (); \
-    } \
-  while (0)
-
-DEFUN_DLD (daspk, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{x}, @var{xdot}, @var{istate}, @var{msg}] =} daspk (@var{fcn}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\
-Solve the set of differential-algebraic equations\n\
-@tex\n\
-$$ 0 = f (x, \\dot{x}, t) $$\n\
-with\n\
-$$ x(t_0) = x_0, \\dot{x}(t_0) = \\dot{x}_0 $$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-0 = f (x, xdot, t)\n\
-@end example\n\
-\n\
-@noindent\n\
-with\n\
-\n\
-@example\n\
-x(t_0) = x_0, xdot(t_0) = xdot_0\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-The solution is returned in the matrices @var{x} and @var{xdot},\n\
-with each row in the result matrices corresponding to one of the\n\
-elements in the vector @var{t}.  The first element of @var{t}\n\
-should be @math{t_0} and correspond to the initial state of the\n\
-system @var{x_0} and its derivative @var{xdot_0}, so that the first\n\
-row of the output @var{x} is @var{x_0} and the first row\n\
-of the output @var{xdot} is @var{xdot_0}.\n\
-\n\
-The first argument, @var{fcn}, is a string, inline, or function handle\n\
-that names the function @math{f} to call to compute the vector of\n\
-residuals for the set of equations.  It must have the form\n\
-\n\
-@example\n\
-@var{res} = f (@var{x}, @var{xdot}, @var{t})\n\
-@end example\n\
-\n\
-@noindent\n\
-in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a\n\
-scalar.\n\
-\n\
-If @var{fcn} is a two-element string array or a two-element cell array\n\
-of strings, inline functions, or function handles, the first element names\n\
-the function @math{f} described above, and the second element names a\n\
-function to compute the modified Jacobian\n\
-@tex\n\
-$$\n\
-J = {\\partial f \\over \\partial x}\n\
-  + c {\\partial f \\over \\partial \\dot{x}}\n\
-$$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-@group\n\
-      df       df\n\
-jac = -- + c ------\n\
-      dx     d xdot\n\
-@end group\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-\n\
-The modified Jacobian function must have the form\n\
-\n\
-@example\n\
-@group\n\
-\n\
-@var{jac} = j (@var{x}, @var{xdot}, @var{t}, @var{c})\n\
-\n\
-@end group\n\
-@end example\n\
-\n\
-The second and third arguments to @code{daspk} specify the initial\n\
-condition of the states and their derivatives, and the fourth argument\n\
-specifies a vector of output times at which the solution is desired,\n\
-including the time corresponding to the initial condition.\n\
-\n\
-The set of initial states and derivatives are not strictly required to\n\
-be consistent.  If they are not consistent, you must use the\n\
-@code{daspk_options} function to provide additional information so\n\
-that @code{daspk} can compute a consistent starting point.\n\
-\n\
-The fifth argument is optional, and may be used to specify a set of\n\
-times that the DAE solver should not integrate past.  It is useful for\n\
-avoiding difficulties with singularities and points where there is a\n\
-discontinuity in the derivative.\n\
-\n\
-After a successful computation, the value of @var{istate} will be\n\
-greater than zero (consistent with the Fortran version of @sc{daspk}).\n\
-\n\
-If the computation is not successful, the value of @var{istate} will be\n\
-less than zero and @var{msg} will contain additional information.\n\
-\n\
-You can use the function @code{daspk_options} to set optional\n\
-parameters for @code{daspk}.\n\
-@seealso{dassl}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  warned_fcn_imaginary = false;
-  warned_jac_imaginary = false;
-
-  unwind_protect frame;
-
-  frame.protect_var (call_depth);
-  call_depth++;
-
-  if (call_depth > 1)
-    DASPK_ABORT1 ("invalid recursive call");
-
-  int nargin = args.length ();
-
-  if (nargin > 3 && nargin < 6)
-    {
-      std::string fcn_name, fname, jac_name, jname;
-      daspk_fcn = 0;
-      daspk_jac = 0;
-
-      octave_value f_arg = args(0);
-
-      if (f_arg.is_cell ())
-        {
-          Cell c = f_arg.cell_value ();
-          if (c.length () == 1)
-            f_arg = c(0);
-          else if (c.length () == 2)
-            {
-              if (c(0).is_function_handle () || c(0).is_inline_function ())
-                daspk_fcn = c(0).function_value ();
-              else
-                {
-                  fcn_name = unique_symbol_name ("__daspk_fcn__");
-                  fname = "function y = ";
-                  fname.append (fcn_name);
-                  fname.append (" (x, xdot, t) y = ");
-                  daspk_fcn = extract_function
-                    (c(0), "daspk", fcn_name, fname, "; endfunction");
-                }
-
-              if (daspk_fcn)
-                {
-                  if (c(1).is_function_handle () || c(1).is_inline_function ())
-                    daspk_jac = c(1).function_value ();
-                  else
-                    {
-                      jac_name = unique_symbol_name ("__daspk_jac__");
-                      jname = "function jac = ";
-                      jname.append (jac_name);
-                      jname.append (" (x, xdot, t, cj) jac = ");
-                      daspk_jac = extract_function
-                        (c(1), "daspk", jac_name, jname, "; endfunction");
-
-                      if (!daspk_jac)
-                        {
-                          if (fcn_name.length ())
-                            clear_function (fcn_name);
-                          daspk_fcn = 0;
-                        }
-                    }
-                }
-            }
-          else
-            DASPK_ABORT1 ("incorrect number of elements in cell array");
-        }
-
-      if (!daspk_fcn && ! f_arg.is_cell ())
-        {
-          if (f_arg.is_function_handle () || f_arg.is_inline_function ())
-            daspk_fcn = f_arg.function_value ();
-          else
-            {
-              switch (f_arg.rows ())
-                {
-                case 1:
-                  do
-                    {
-                      fcn_name = unique_symbol_name ("__daspk_fcn__");
-                      fname = "function y = ";
-                      fname.append (fcn_name);
-                      fname.append (" (x, xdot, t) y = ");
-                      daspk_fcn = extract_function
-                        (f_arg, "daspk", fcn_name, fname, "; endfunction");
-                    }
-                  while (0);
-                  break;
-
-                case 2:
-                  {
-                    string_vector tmp = f_arg.all_strings ();
-
-                    if (! error_state)
-                      {
-                        fcn_name = unique_symbol_name ("__daspk_fcn__");
-                        fname = "function y = ";
-                        fname.append (fcn_name);
-                        fname.append (" (x, xdot, t) y = ");
-                        daspk_fcn = extract_function
-                          (tmp(0), "daspk", fcn_name, fname, "; endfunction");
-
-                        if (daspk_fcn)
-                          {
-                            jac_name = unique_symbol_name ("__daspk_jac__");
-                            jname = "function jac = ";
-                            jname.append (jac_name);
-                            jname.append (" (x, xdot, t, cj) jac = ");
-                            daspk_jac = extract_function
-                              (tmp(1), "daspk", jac_name, jname,
-                               "; endfunction");
-
-                            if (!daspk_jac)
-                              {
-                                if (fcn_name.length ())
-                                  clear_function (fcn_name);
-                                daspk_fcn = 0;
-                              }
-                          }
-                      }
-                  }
-                }
-            }
-        }
-
-      if (error_state || ! daspk_fcn)
-        DASPK_ABORT ();
-
-      ColumnVector state = ColumnVector (args(1).vector_value ());
-
-      if (error_state)
-        DASPK_ABORT1 ("expecting state vector as second argument");
-
-      ColumnVector deriv (args(2).vector_value ());
-
-      if (error_state)
-        DASPK_ABORT1 ("expecting derivative vector as third argument");
-
-      ColumnVector out_times (args(3).vector_value ());
-
-      if (error_state)
-        DASPK_ABORT1 ("expecting output time vector as fourth argument");
-
-      ColumnVector crit_times;
-      int crit_times_set = 0;
-      if (nargin > 4)
-        {
-          crit_times = ColumnVector (args(4).vector_value ());
-
-          if (error_state)
-            DASPK_ABORT1 ("expecting critical time vector as fifth argument");
-
-          crit_times_set = 1;
-        }
-
-      if (state.capacity () != deriv.capacity ())
-        DASPK_ABORT1 ("x and xdot must have the same size");
-
-      double tzero = out_times (0);
-
-      DAEFunc func (daspk_user_function);
-      if (daspk_jac)
-        func.set_jacobian_function (daspk_user_jacobian);
-
-      DASPK dae (state, deriv, tzero, func);
-      dae.set_options (daspk_opts);
-
-      Matrix output;
-      Matrix deriv_output;
-
-      if (crit_times_set)
-        output = dae.integrate (out_times, deriv_output, crit_times);
-      else
-        output = dae.integrate (out_times, deriv_output);
-
-      if (fcn_name.length ())
-        clear_function (fcn_name);
-      if (jac_name.length ())
-        clear_function (jac_name);
-
-      if (! error_state)
-        {
-          std::string msg = dae.error_message ();
-
-          retval(3) = msg;
-          retval(2) = static_cast<double> (dae.integration_state ());
-
-          if (dae.integration_ok ())
-            {
-              retval(1) = deriv_output;
-              retval(0) = output;
-            }
-          else
-            {
-              retval(1) = Matrix ();
-              retval(0) = Matrix ();
-
-              if (nargout < 3)
-                error ("daspk: %s", msg.c_str ());
-            }
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
--- a/src/DLD-FUNCTIONS/dasrt.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,590 +0,0 @@
-/*
-
-Copyright (C) 2002-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <iostream>
-#include <string>
-
-#include "DASRT.h"
-#include "lo-mappers.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "ov-fcn.h"
-#include "ov-cell.h"
-#include "pager.h"
-#include "parse.h"
-#include "unwind-prot.h"
-#include "utils.h"
-#include "variables.h"
-
-#include "DASRT-opts.cc"
-
-// Global pointers for user defined function required by dasrt.
-static octave_function *dasrt_f;
-static octave_function *dasrt_j;
-static octave_function *dasrt_cf;
-
-// Have we warned about imaginary values returned from user function?
-static bool warned_fcn_imaginary = false;
-static bool warned_jac_imaginary = false;
-static bool warned_cf_imaginary = false;
-
-// Is this a recursive call?
-static int call_depth = 0;
-
-static ColumnVector
-dasrt_user_f (const ColumnVector& x, const ColumnVector& xdot,
-              double t, octave_idx_type&)
-{
-  ColumnVector retval;
-
-  assert (x.capacity () == xdot.capacity ());
-
-  octave_value_list args;
-
-  args(2) = t;
-  args(1) = xdot;
-  args(0) = x;
-
-  if (dasrt_f)
-    {
-      octave_value_list tmp = dasrt_f->do_multi_index_op (1, args);
-
-      if (error_state)
-        {
-          gripe_user_supplied_eval ("dasrt");
-          return retval;
-        }
-
-      if (tmp.length () > 0 && tmp(0).is_defined ())
-        {
-          if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
-            {
-              warning ("dasrt: ignoring imaginary part returned from user-supplied function");
-              warned_fcn_imaginary = true;
-            }
-
-          retval = ColumnVector (tmp(0).vector_value ());
-
-          if (error_state || retval.length () == 0)
-            gripe_user_supplied_eval ("dasrt");
-        }
-      else
-        gripe_user_supplied_eval ("dasrt");
-    }
-
-  return retval;
-}
-
-static ColumnVector
-dasrt_user_cf (const ColumnVector& x, double t)
-{
-  ColumnVector retval;
-
-  octave_value_list args;
-
-  args(1) = t;
-  args(0) = x;
-
-  if (dasrt_cf)
-    {
-      octave_value_list tmp = dasrt_cf->do_multi_index_op (1, args);
-
-      if (error_state)
-        {
-          gripe_user_supplied_eval ("dasrt");
-          return retval;
-        }
-
-      if (tmp.length () > 0 && tmp(0).is_defined ())
-        {
-          if (! warned_cf_imaginary && tmp(0).is_complex_type ())
-            {
-              warning ("dasrt: ignoring imaginary part returned from user-supplied constraint function");
-              warned_cf_imaginary = true;
-            }
-
-          retval = ColumnVector (tmp(0).vector_value ());
-
-          if (error_state || retval.length () == 0)
-            gripe_user_supplied_eval ("dasrt");
-        }
-      else
-        gripe_user_supplied_eval ("dasrt");
-    }
-
-  return retval;
-}
-
-static Matrix
-dasrt_user_j (const ColumnVector& x, const ColumnVector& xdot,
-              double t, double cj)
-{
-  Matrix retval;
-
-  assert (x.capacity () == xdot.capacity ());
-
-  octave_value_list args;
-
-  args(3) = cj;
-  args(2) = t;
-  args(1) = xdot;
-  args(0) = x;
-
-  if (dasrt_j)
-    {
-      octave_value_list tmp = dasrt_j->do_multi_index_op (1, args);
-
-      if (error_state)
-        {
-          gripe_user_supplied_eval ("dasrt");
-          return retval;
-        }
-
-      int tlen = tmp.length ();
-      if (tlen > 0 && tmp(0).is_defined ())
-        {
-          if (! warned_jac_imaginary && tmp(0).is_complex_type ())
-            {
-              warning ("dasrt: ignoring imaginary part returned from user-supplied jacobian function");
-              warned_jac_imaginary = true;
-            }
-
-          retval = tmp(0).matrix_value ();
-
-          if (error_state || retval.length () == 0)
-            gripe_user_supplied_eval ("dasrt");
-        }
-      else
-        gripe_user_supplied_eval ("dasrt");
-    }
-
-  return retval;
-}
-
-#define DASRT_ABORT \
-  return retval
-
-#define DASRT_ABORT1(msg) \
-  do \
-    { \
-      ::error ("dasrt: " msg); \
-      DASRT_ABORT; \
-    } \
-  while (0)
-
-#define DASRT_ABORT2(fmt, arg) \
-  do \
-    { \
-      ::error ("dasrt: " fmt, arg); \
-      DASRT_ABORT; \
-    } \
-  while (0)
-
-DEFUN_DLD (dasrt, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {[@var{x}, @var{xdot}, @var{t_out}, @var{istat}, @var{msg}] =} dasrt (@var{fcn}, [], @var{x_0}, @var{xdot_0}, @var{t})\n\
-@deftypefnx {Loadable Function} {@dots{} =} dasrt (@var{fcn}, @var{g}, @var{x_0}, @var{xdot_0}, @var{t})\n\
-@deftypefnx {Loadable Function} {@dots{} =} dasrt (@var{fcn}, [], @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\
-@deftypefnx {Loadable Function} {@dots{} =} dasrt (@var{fcn}, @var{g}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\
-Solve the set of differential-algebraic equations\n\
-@tex\n\
-$$ 0 = f (x, \\dot{x}, t) $$\n\
-with\n\
-$$ x(t_0) = x_0, \\dot{x}(t_0) = \\dot{x}_0 $$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-0 = f (x, xdot, t)\n\
-@end example\n\
-\n\
-@noindent\n\
-with\n\
-\n\
-@example\n\
-x(t_0) = x_0, xdot(t_0) = xdot_0\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-with functional stopping criteria (root solving).\n\
-\n\
-The solution is returned in the matrices @var{x} and @var{xdot},\n\
-with each row in the result matrices corresponding to one of the\n\
-elements in the vector @var{t_out}.  The first element of @var{t}\n\
-should be @math{t_0} and correspond to the initial state of the\n\
-system @var{x_0} and its derivative @var{xdot_0}, so that the first\n\
-row of the output @var{x} is @var{x_0} and the first row\n\
-of the output @var{xdot} is @var{xdot_0}.\n\
-\n\
-The vector @var{t} provides an upper limit on the length of the\n\
-integration.  If the stopping condition is met, the vector\n\
-@var{t_out} will be shorter than @var{t}, and the final element of\n\
-@var{t_out} will be the point at which the stopping condition was met,\n\
-and may not correspond to any element of the vector @var{t}.\n\
-\n\
-The first argument, @var{fcn}, is a string, inline, or function handle\n\
-that names the function @math{f} to call to compute the vector of\n\
-residuals for the set of equations.  It must have the form\n\
-\n\
-@example\n\
-@var{res} = f (@var{x}, @var{xdot}, @var{t})\n\
-@end example\n\
-\n\
-@noindent\n\
-in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a\n\
-scalar.\n\
-\n\
-If @var{fcn} is a two-element string array or a two-element cell array\n\
-of strings, inline functions, or function handles, the first element names\n\
-the function @math{f} described above, and the second element names a\n\
-function to compute the modified Jacobian\n\
-\n\
-@tex\n\
-$$\n\
-J = {\\partial f \\over \\partial x}\n\
-  + c {\\partial f \\over \\partial \\dot{x}}\n\
-$$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-@group\n\
-      df       df\n\
-jac = -- + c ------\n\
-      dx     d xdot\n\
-@end group\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-\n\
-The modified Jacobian function must have the form\n\
-\n\
-@example\n\
-@group\n\
-\n\
-@var{jac} = j (@var{x}, @var{xdot}, @var{t}, @var{c})\n\
-\n\
-@end group\n\
-@end example\n\
-\n\
-The optional second argument names a function that defines the\n\
-constraint functions whose roots are desired during the integration.\n\
-This function must have the form\n\
-\n\
-@example\n\
-@var{g_out} = g (@var{x}, @var{t})\n\
-@end example\n\
-\n\
-@noindent\n\
-and return a vector of the constraint function values.\n\
-If the value of any of the constraint functions changes sign, @sc{dasrt}\n\
-will attempt to stop the integration at the point of the sign change.\n\
-\n\
-If the name of the constraint function is omitted, @code{dasrt} solves\n\
-the same problem as @code{daspk} or @code{dassl}.\n\
-\n\
-Note that because of numerical errors in the constraint functions\n\
-due to round-off and integration error, @sc{dasrt} may return false\n\
-roots, or return the same root at two or more nearly equal values of\n\
-@var{T}.  If such false roots are suspected, the user should consider\n\
-smaller error tolerances or higher precision in the evaluation of the\n\
-constraint functions.\n\
-\n\
-If a root of some constraint function defines the end of the problem,\n\
-the input to @sc{dasrt} should nevertheless allow integration to a\n\
-point slightly past that root, so that @sc{dasrt} can locate the root\n\
-by interpolation.\n\
-\n\
-The third and fourth arguments to @code{dasrt} specify the initial\n\
-condition of the states and their derivatives, and the fourth argument\n\
-specifies a vector of output times at which the solution is desired,\n\
-including the time corresponding to the initial condition.\n\
-\n\
-The set of initial states and derivatives are not strictly required to\n\
-be consistent.  In practice, however, @sc{dassl} is not very good at\n\
-determining a consistent set for you, so it is best if you ensure that\n\
-the initial values result in the function evaluating to zero.\n\
-\n\
-The sixth argument is optional, and may be used to specify a set of\n\
-times that the DAE solver should not integrate past.  It is useful for\n\
-avoiding difficulties with singularities and points where there is a\n\
-discontinuity in the derivative.\n\
-\n\
-After a successful computation, the value of @var{istate} will be\n\
-greater than zero (consistent with the Fortran version of @sc{dassl}).\n\
-\n\
-If the computation is not successful, the value of @var{istate} will be\n\
-less than zero and @var{msg} will contain additional information.\n\
-\n\
-You can use the function @code{dasrt_options} to set optional\n\
-parameters for @code{dasrt}.\n\
-@seealso{dasrt_options, daspk, dasrt, lsode}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  warned_fcn_imaginary = false;
-  warned_jac_imaginary = false;
-  warned_cf_imaginary = false;
-
-  unwind_protect frame;
-
-  frame.protect_var (call_depth);
-  call_depth++;
-
-  if (call_depth > 1)
-    DASRT_ABORT1 ("invalid recursive call");
-
-  int argp = 0;
-
-  int nargin = args.length ();
-
-  if (nargin < 4 || nargin > 6)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  std::string fcn_name, fname, jac_name, jname;
-  dasrt_f = 0;
-  dasrt_j = 0;
-  dasrt_cf = 0;
-
-  // Check all the arguments.  Are they the right animals?
-
-  // Here's where I take care of f and j in one shot:
-
-  octave_value f_arg = args(0);
-
-  if (f_arg.is_cell ())
-    {
-      Cell c = f_arg.cell_value ();
-      if (c.length () == 1)
-        f_arg = c(0);
-      else if (c.length () == 2)
-        {
-          if (c(0).is_function_handle () || c(0).is_inline_function ())
-            dasrt_f = c(0).function_value ();
-          else
-            {
-              fcn_name = unique_symbol_name ("__dasrt_fcn__");
-              fname = "function y = ";
-              fname.append (fcn_name);
-              fname.append (" (x, xdot, t) y = ");
-              dasrt_f = extract_function
-                (c(0), "dasrt", fcn_name, fname, "; endfunction");
-            }
-
-          if (dasrt_f)
-            {
-              if (c(1).is_function_handle () || c(1).is_inline_function ())
-                dasrt_j = c(1).function_value ();
-              else
-                {
-                  jac_name = unique_symbol_name ("__dasrt_jac__");
-                  jname = "function jac = ";
-                  jname.append (jac_name);
-                  jname.append (" (x, xdot, t, cj) jac = ");
-                  dasrt_j = extract_function
-                    (c(1), "dasrt", jac_name, jname, "; endfunction");
-
-                  if (!dasrt_j)
-                    {
-                      if (fcn_name.length ())
-                        clear_function (fcn_name);
-                      dasrt_f = 0;
-                    }
-                }
-            }
-        }
-      else
-        DASRT_ABORT1 ("incorrect number of elements in cell array");
-    }
-
-  if (!dasrt_f && ! f_arg.is_cell ())
-    {
-      if (f_arg.is_function_handle () || f_arg.is_inline_function ())
-        dasrt_f = f_arg.function_value ();
-      else
-        {
-          switch (f_arg.rows ())
-            {
-            case 1:
-              fcn_name = unique_symbol_name ("__dasrt_fcn__");
-              fname = "function y = ";
-              fname.append (fcn_name);
-              fname.append (" (x, xdot, t) y = ");
-              dasrt_f = extract_function
-                (f_arg, "dasrt", fcn_name, fname, "; endfunction");
-              break;
-
-            case 2:
-              {
-                string_vector tmp = args(0).all_strings ();
-
-                if (! error_state)
-                  {
-                    fcn_name = unique_symbol_name ("__dasrt_fcn__");
-                    fname = "function y = ";
-                    fname.append (fcn_name);
-                    fname.append (" (x, xdot, t) y = ");
-                    dasrt_f = extract_function
-                      (tmp(0), "dasrt", fcn_name, fname, "; endfunction");
-
-                    if (dasrt_f)
-                      {
-                        jac_name = unique_symbol_name ("__dasrt_jac__");
-                        jname = "function jac = ";
-                        jname.append (jac_name);
-                        jname.append (" (x, xdot, t, cj) jac = ");
-                        dasrt_j = extract_function
-                          (tmp(1), "dasrt", jac_name, jname, "; endfunction");
-
-                        if (! dasrt_j)
-                          dasrt_f = 0;
-                      }
-                  }
-              }
-              break;
-
-            default:
-              DASRT_ABORT1
-                ("first arg should be a string or 2-element string array");
-            }
-        }
-    }
-
-  if (error_state || (! dasrt_f))
-    DASRT_ABORT;
-
-  DAERTFunc func (dasrt_user_f);
-
-  argp++;
-
-  if (args(1).is_function_handle () || args(1).is_inline_function ())
-    {
-      dasrt_cf = args(1).function_value ();
-
-      if (! dasrt_cf)
-        DASRT_ABORT1 ("expecting function name as argument 2");
-
-      argp++;
-
-      func.set_constraint_function (dasrt_user_cf);
-    }
-  else if (args(1).is_string ())
-    {
-      dasrt_cf = is_valid_function (args(1), "dasrt", true);
-      if (! dasrt_cf)
-        DASRT_ABORT1 ("expecting function name as argument 2");
-
-      argp++;
-
-      func.set_constraint_function (dasrt_user_cf);
-    }
-
-  ColumnVector state (args(argp++).vector_value ());
-
-  if (error_state)
-    DASRT_ABORT2 ("expecting state vector as argument %d", argp);
-
-  ColumnVector stateprime (args(argp++).vector_value ());
-
-  if (error_state)
-    DASRT_ABORT2
-       ("expecting time derivative of state vector as argument %d", argp);
-
-  ColumnVector out_times (args(argp++).vector_value ());
-
-  if (error_state)
-    DASRT_ABORT2
-        ("expecting output time vector as %s argument %d", argp);
-
-  double tzero = out_times (0);
-
-  ColumnVector crit_times;
-
-  bool crit_times_set = false;
-
-  if (argp < nargin)
-    {
-      crit_times = ColumnVector (args(argp++).vector_value ());
-
-      if (error_state)
-        DASRT_ABORT2
-          ("expecting critical time vector as argument %d", argp);
-
-      crit_times_set = true;
-    }
-
-  if (dasrt_j)
-    func.set_jacobian_function (dasrt_user_j);
-
-  DASRT_result output;
-
-  DASRT dae = DASRT (state, stateprime, tzero, func);
-
-  dae.set_options (dasrt_opts);
-
-  if (crit_times_set)
-    output = dae.integrate (out_times, crit_times);
-  else
-    output = dae.integrate (out_times);
-
-  if (fcn_name.length ())
-    clear_function (fcn_name);
-  if (jac_name.length ())
-    clear_function (jac_name);
-
-  if (! error_state)
-    {
-      std::string msg = dae.error_message ();
-
-      retval(4) = msg;
-      retval(3) = static_cast<double> (dae.integration_state ());
-
-      if (dae.integration_ok ())
-        {
-          retval(2) = output.times ();
-          retval(1) = output.deriv ();
-          retval(0) = output.state ();
-        }
-      else
-        {
-          retval(2) = Matrix ();
-          retval(1) = Matrix ();
-          retval(0) = Matrix ();
-
-          if (nargout < 4)
-            error ("dasrt: %s", msg.c_str ());
-        }
-    }
-
-  return retval;
-}
--- a/src/DLD-FUNCTIONS/dassl.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,565 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-
-#include <iomanip>
-#include <iostream>
-
-#include "DASSL.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "ov-fcn.h"
-#include "ov-cell.h"
-#include "pager.h"
-#include "unwind-prot.h"
-#include "utils.h"
-#include "variables.h"
-
-#include "DASSL-opts.cc"
-
-// Global pointer for user defined function required by dassl.
-static octave_function *dassl_fcn;
-
-// Global pointer for optional user defined jacobian function.
-static octave_function *dassl_jac;
-
-// Have we warned about imaginary values returned from user function?
-static bool warned_fcn_imaginary = false;
-static bool warned_jac_imaginary = false;
-
-// Is this a recursive call?
-static int call_depth = 0;
-
-ColumnVector
-dassl_user_function (const ColumnVector& x, const ColumnVector& xdot,
-                     double t, octave_idx_type& ires)
-{
-  ColumnVector retval;
-
-  assert (x.capacity () == xdot.capacity ());
-
-  octave_value_list args;
-
-  args(2) = t;
-  args(1) = xdot;
-  args(0) = x;
-
-  if (dassl_fcn)
-    {
-      octave_value_list tmp = dassl_fcn->do_multi_index_op (1, args);
-
-      if (error_state)
-        {
-          gripe_user_supplied_eval ("dassl");
-          return retval;
-        }
-
-      int tlen = tmp.length ();
-      if (tlen > 0 && tmp(0).is_defined ())
-        {
-          if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
-            {
-              warning ("dassl: ignoring imaginary part returned from user-supplied function");
-              warned_fcn_imaginary = true;
-            }
-
-          retval = ColumnVector (tmp(0).vector_value ());
-
-          if (tlen > 1)
-            ires = tmp(1).int_value ();
-
-          if (error_state || retval.length () == 0)
-            gripe_user_supplied_eval ("dassl");
-        }
-      else
-        gripe_user_supplied_eval ("dassl");
-    }
-
-  return retval;
-}
-
-Matrix
-dassl_user_jacobian (const ColumnVector& x, const ColumnVector& xdot,
-                     double t, double cj)
-{
-  Matrix retval;
-
-  assert (x.capacity () == xdot.capacity ());
-
-  octave_value_list args;
-
-  args(3) = cj;
-  args(2) = t;
-  args(1) = xdot;
-  args(0) = x;
-
-  if (dassl_jac)
-    {
-      octave_value_list tmp = dassl_jac->do_multi_index_op (1, args);
-
-      if (error_state)
-        {
-          gripe_user_supplied_eval ("dassl");
-          return retval;
-        }
-
-      int tlen = tmp.length ();
-      if (tlen > 0 && tmp(0).is_defined ())
-        {
-          if (! warned_jac_imaginary && tmp(0).is_complex_type ())
-            {
-              warning ("dassl: ignoring imaginary part returned from user-supplied jacobian function");
-              warned_jac_imaginary = true;
-            }
-
-          retval = tmp(0).matrix_value ();
-
-          if (error_state || retval.length () == 0)
-            gripe_user_supplied_eval ("dassl");
-        }
-      else
-        gripe_user_supplied_eval ("dassl");
-    }
-
-  return retval;
-}
-
-#define DASSL_ABORT() \
-  return retval
-
-#define DASSL_ABORT1(msg) \
-  do \
-    { \
-      ::error ("dassl: " msg); \
-      DASSL_ABORT (); \
-    } \
-  while (0)
-
-#define DASSL_ABORT2(fmt, arg) \
-  do \
-    { \
-      ::error ("dassl: " fmt, arg); \
-      DASSL_ABORT (); \
-    } \
-  while (0)
-
-DEFUN_DLD (dassl, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{x}, @var{xdot}, @var{istate}, @var{msg}] =} dassl (@var{fcn}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\
-Solve the set of differential-algebraic equations\n\
-@tex\n\
-$$ 0 = f (x, \\dot{x}, t) $$\n\
-with\n\
-$$ x(t_0) = x_0, \\dot{x}(t_0) = \\dot{x}_0 $$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-0 = f (x, xdot, t)\n\
-@end example\n\
-\n\
-@noindent\n\
-with\n\
-\n\
-@example\n\
-x(t_0) = x_0, xdot(t_0) = xdot_0\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-The solution is returned in the matrices @var{x} and @var{xdot},\n\
-with each row in the result matrices corresponding to one of the\n\
-elements in the vector @var{t}.  The first element of @var{t}\n\
-should be @math{t_0} and correspond to the initial state of the\n\
-system @var{x_0} and its derivative @var{xdot_0}, so that the first\n\
-row of the output @var{x} is @var{x_0} and the first row\n\
-of the output @var{xdot} is @var{xdot_0}.\n\
-\n\
-The first argument, @var{fcn}, is a string, inline, or function handle\n\
-that names the function @math{f} to call to compute the vector of\n\
-residuals for the set of equations.  It must have the form\n\
-\n\
-@example\n\
-@var{res} = f (@var{x}, @var{xdot}, @var{t})\n\
-@end example\n\
-\n\
-@noindent\n\
-in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a\n\
-scalar.\n\
-\n\
-If @var{fcn} is a two-element string array or a two-element cell array\n\
-of strings, inline functions, or function handles, the first element names\n\
-the function @math{f} described above, and the second element names a\n\
-function to compute the modified Jacobian\n\
-\n\
-@tex\n\
-$$\n\
-J = {\\partial f \\over \\partial x}\n\
-  + c {\\partial f \\over \\partial \\dot{x}}\n\
-$$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-@group\n\
-      df       df\n\
-jac = -- + c ------\n\
-      dx     d xdot\n\
-@end group\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-\n\
-The modified Jacobian function must have the form\n\
-\n\
-@example\n\
-@group\n\
-\n\
-@var{jac} = j (@var{x}, @var{xdot}, @var{t}, @var{c})\n\
-\n\
-@end group\n\
-@end example\n\
-\n\
-The second and third arguments to @code{dassl} specify the initial\n\
-condition of the states and their derivatives, and the fourth argument\n\
-specifies a vector of output times at which the solution is desired,\n\
-including the time corresponding to the initial condition.\n\
-\n\
-The set of initial states and derivatives are not strictly required to\n\
-be consistent.  In practice, however, @sc{dassl} is not very good at\n\
-determining a consistent set for you, so it is best if you ensure that\n\
-the initial values result in the function evaluating to zero.\n\
-\n\
-The fifth argument is optional, and may be used to specify a set of\n\
-times that the DAE solver should not integrate past.  It is useful for\n\
-avoiding difficulties with singularities and points where there is a\n\
-discontinuity in the derivative.\n\
-\n\
-After a successful computation, the value of @var{istate} will be\n\
-greater than zero (consistent with the Fortran version of @sc{dassl}).\n\
-\n\
-If the computation is not successful, the value of @var{istate} will be\n\
-less than zero and @var{msg} will contain additional information.\n\
-\n\
-You can use the function @code{dassl_options} to set optional\n\
-parameters for @code{dassl}.\n\
-@seealso{daspk, dasrt, lsode}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  warned_fcn_imaginary = false;
-  warned_jac_imaginary = false;
-
-  unwind_protect frame;
-
-  frame.protect_var (call_depth);
-  call_depth++;
-
-  if (call_depth > 1)
-    DASSL_ABORT1 ("invalid recursive call");
-
-  int nargin = args.length ();
-
-  if (nargin > 3 && nargin < 6 && nargout < 5)
-    {
-      std::string fcn_name, fname, jac_name, jname;
-      dassl_fcn = 0;
-      dassl_jac = 0;
-
-      octave_value f_arg = args(0);
-
-      if (f_arg.is_cell ())
-        {
-          Cell c = f_arg.cell_value ();
-          if (c.length () == 1)
-            f_arg = c(0);
-          else if (c.length () == 2)
-            {
-              if (c(0).is_function_handle () || c(0).is_inline_function ())
-                dassl_fcn = c(0).function_value ();
-              else
-                {
-                  fcn_name = unique_symbol_name ("__dassl_fcn__");
-                  fname = "function y = ";
-                  fname.append (fcn_name);
-                  fname.append (" (x, xdot, t) y = ");
-                  dassl_fcn = extract_function
-                    (c(0), "dassl", fcn_name, fname, "; endfunction");
-                }
-
-              if (dassl_fcn)
-                {
-                  if (c(1).is_function_handle () || c(1).is_inline_function ())
-                    dassl_jac = c(1).function_value ();
-                  else
-                    {
-                        jac_name = unique_symbol_name ("__dassl_jac__");
-                        jname = "function jac = ";
-                        jname.append (jac_name);
-                        jname.append (" (x, xdot, t, cj) jac = ");
-                        dassl_jac = extract_function
-                          (c(1), "dassl", jac_name, jname, "; endfunction");
-
-                        if (!dassl_jac)
-                          {
-                            if (fcn_name.length ())
-                              clear_function (fcn_name);
-                            dassl_fcn = 0;
-                          }
-                    }
-                }
-            }
-          else
-            DASSL_ABORT1 ("incorrect number of elements in cell array");
-        }
-
-      if (!dassl_fcn && ! f_arg.is_cell ())
-        {
-          if (f_arg.is_function_handle () || f_arg.is_inline_function ())
-            dassl_fcn = f_arg.function_value ();
-          else
-            {
-              switch (f_arg.rows ())
-                {
-                case 1:
-                  do
-                    {
-                      fcn_name = unique_symbol_name ("__dassl_fcn__");
-                      fname = "function y = ";
-                      fname.append (fcn_name);
-                      fname.append (" (x, xdot, t) y = ");
-                      dassl_fcn = extract_function
-                        (f_arg, "dassl", fcn_name, fname, "; endfunction");
-                    }
-                  while (0);
-                  break;
-
-                case 2:
-                  {
-                    string_vector tmp = f_arg.all_strings ();
-
-                    if (! error_state)
-                      {
-                        fcn_name = unique_symbol_name ("__dassl_fcn__");
-                        fname = "function y = ";
-                        fname.append (fcn_name);
-                        fname.append (" (x, xdot, t) y = ");
-                        dassl_fcn = extract_function
-                          (tmp(0), "dassl", fcn_name, fname, "; endfunction");
-
-                        if (dassl_fcn)
-                          {
-                            jac_name = unique_symbol_name ("__dassl_jac__");
-                            jname = "function jac = ";
-                            jname.append (jac_name);
-                            jname.append (" (x, xdot, t, cj) jac = ");
-                            dassl_jac = extract_function
-                              (tmp(1), "dassl", jac_name, jname,
-                               "; endfunction");
-
-                            if (!dassl_jac)
-                              {
-                                if (fcn_name.length ())
-                                  clear_function (fcn_name);
-                                dassl_fcn = 0;
-                              }
-                          }
-                      }
-                  }
-                }
-            }
-        }
-
-      if (error_state || ! dassl_fcn)
-        DASSL_ABORT ();
-
-      ColumnVector state = ColumnVector (args(1).vector_value ());
-
-      if (error_state)
-        DASSL_ABORT1 ("expecting state vector as second argument");
-
-      ColumnVector deriv (args(2).vector_value ());
-
-      if (error_state)
-        DASSL_ABORT1 ("expecting derivative vector as third argument");
-
-      ColumnVector out_times (args(3).vector_value ());
-
-      if (error_state)
-        DASSL_ABORT1 ("expecting output time vector as fourth argument");
-
-      ColumnVector crit_times;
-      int crit_times_set = 0;
-      if (nargin > 4)
-        {
-          crit_times = ColumnVector (args(4).vector_value ());
-
-          if (error_state)
-            DASSL_ABORT1 ("expecting critical time vector as fifth argument");
-
-          crit_times_set = 1;
-        }
-
-      if (state.capacity () != deriv.capacity ())
-        DASSL_ABORT1 ("x and xdot must have the same size");
-
-      double tzero = out_times (0);
-
-      DAEFunc func (dassl_user_function);
-      if (dassl_jac)
-        func.set_jacobian_function (dassl_user_jacobian);
-
-      DASSL dae (state, deriv, tzero, func);
-
-      dae.set_options (dassl_opts);
-
-      Matrix output;
-      Matrix deriv_output;
-
-      if (crit_times_set)
-        output = dae.integrate (out_times, deriv_output, crit_times);
-      else
-        output = dae.integrate (out_times, deriv_output);
-
-      if (fcn_name.length ())
-        clear_function (fcn_name);
-      if (jac_name.length ())
-        clear_function (jac_name);
-
-      if (! error_state)
-        {
-          std::string msg = dae.error_message ();
-
-          retval(3) = msg;
-          retval(2) = static_cast<double> (dae.integration_state ());
-
-          if (dae.integration_ok ())
-            {
-              retval(1) = deriv_output;
-              retval(0) = output;
-            }
-          else
-            {
-              retval(1) = Matrix ();
-              retval(0) = Matrix ();
-
-              if (nargout < 3)
-                error ("dassl: %s", msg.c_str ());
-            }
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-## dassl-1.m
-##
-## Test dassl() function
-##
-## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-##         Comalco Research and Technology
-##         20 May 1998
-##
-## Problem
-##
-##    y1' = -y2,   y1(0) = 1
-##    y2' =  y1,   y2(0) = 0
-##
-## Solution
-##
-##    y1(t) = cos(t)
-##    y2(t) = sin(t)
-##
-%!function res = __f (x, xdot, t)
-%!  res = [xdot(1)+x(2); xdot(2)-x(1)];
-%!endfunction
-
-%!test
-%!
-%! x0 = [1; 0];
-%! xdot0 = [0; 1];
-%! t = (0:1:10)';
-%!
-%! tol = 100 * dassl_options ("relative tolerance");
-%!
-%! [x, xdot] = dassl ("__f", x0, xdot0, t);
-%!
-%! y = [cos(t), sin(t)];
-%!
-%! assert (x, y, tol);
-
-## dassl-2.m
-##
-## Test dassl() function
-##
-## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-##         Comalco Research and Technology
-##         20 May 1998
-##
-## Based on SLATEC quick check for DASSL by Linda Petzold
-##
-## Problem
-##
-##   x1' + 10*x1 = 0,   x1(0) = 1
-##   x1  + x2    = 1,   x2(0) = 0
-##
-##
-## Solution
-##
-##  x1(t) = exp(-10*t)
-##  x2(t) = 1 - x(1)
-##
-%!function res = __f (x, xdot, t)
-%!  res = [xdot(1)+10*x(1); x(1)+x(2)-1];
-%!endfunction
-
-%!test
-%!
-%! x0 = [1; 0];
-%! xdot0 = [-10; 10];
-%! t = (0:0.2:1)';
-%!
-%! tol = 500 * dassl_options ("relative tolerance");
-%!
-%! [x, xdot] = dassl ("__f", x0, xdot0, t);
-%!
-%! y = [exp(-10*t), 1-exp(-10*t)];
-%!
-%! assert (x, y, tol);
-
-%!test
-%! dassl_options ("absolute tolerance", eps);
-%! assert (dassl_options ("absolute tolerance") == eps);
-
-%!error dassl_options ("foo", 1, 2)
-*/
--- a/src/DLD-FUNCTIONS/det.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,253 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "DET.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-#include "ops.h"
-
-#include "ov-re-mat.h"
-#include "ov-cx-mat.h"
-#include "ov-flt-re-mat.h"
-#include "ov-flt-cx-mat.h"
-#include "ov-re-diag.h"
-#include "ov-cx-diag.h"
-#include "ov-flt-re-diag.h"
-#include "ov-flt-cx-diag.h"
-#include "ov-perm.h"
-
-#define MAYBE_CAST(VAR, CLASS) \
-  const CLASS *VAR = arg.type_id () == CLASS::static_type_id () ? \
-   dynamic_cast<const CLASS *> (&arg.get_rep ()) : 0
-
-DEFUN_DLD (det, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} det (@var{A})\n\
-@deftypefnx {Loadable Function} {[@var{d}, @var{rcond}] =} det (@var{A})\n\
-Compute the determinant of @var{A}.\n\
-\n\
-Return an estimate of the reciprocal condition number if requested.\n\
-\n\
-Routines from @sc{lapack} are used for full matrices and code from\n\
-@sc{umfpack} is used for sparse matrices.\n\
-\n\
-The determinant should not be used to check a matrix for singularity.\n\
-For that, use any of the condition number functions: @code{cond},\n\
-@code{condest}, @code{rcond}.\n\
-@seealso{cond, condest, rcond}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin != 1)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value arg = args(0);
-
-  octave_idx_type nr = arg.rows ();
-  octave_idx_type nc = arg.columns ();
-
-  if (nr == 0 && nc == 0)
-    {
-      retval(0) = 1.0;
-      return retval;
-    }
-
-  int arg_is_empty = empty_arg ("det", nr, nc);
-  if (arg_is_empty < 0)
-    return retval;
-  if (arg_is_empty > 0)
-    return octave_value (Matrix (1, 1, 1.0));
-
-
-  if (nr != nc)
-    {
-      gripe_square_matrix_required ("det");
-      return retval;
-    }
-
-  bool isfloat = arg.is_single_type ();
-
-  if (arg.is_diag_matrix ())
-    {
-      if (arg.is_complex_type ())
-        {
-          if (isfloat)
-            {
-              retval(0) = arg.float_complex_diag_matrix_value ().determinant ().value ();
-              if (nargout > 1)
-                retval(1) = arg.float_complex_diag_matrix_value ().rcond ();
-            }
-          else
-            {
-              retval(0) = arg.complex_diag_matrix_value ().determinant ().value ();
-              if (nargout > 1)
-                retval(1) = arg.complex_diag_matrix_value ().rcond ();
-            }
-        }
-      else
-        {
-          if (isfloat)
-            {
-              retval(0) = arg.float_diag_matrix_value ().determinant ().value ();
-              if (nargout > 1)
-                retval(1) = arg.float_diag_matrix_value ().rcond ();
-            }
-          else
-            {
-              retval(0) = arg.diag_matrix_value ().determinant ().value ();
-              if (nargout > 1)
-                retval(1) = arg.diag_matrix_value ().rcond ();
-            }
-        }
-    }
-  else if (arg.is_perm_matrix ())
-    {
-      retval(0) = static_cast<double> (arg.perm_matrix_value ().determinant ());
-      if (nargout > 1)
-        retval(1) = 1.0;
-    }
-  else if (arg.is_single_type ())
-    {
-      if (arg.is_real_type ())
-        {
-          octave_idx_type info;
-          float rcond = 0.0;
-          // Always compute rcond, so we can detect numerically
-          // singular matrices.
-          FloatMatrix m = arg.float_matrix_value ();
-          if (! error_state)
-            {
-              MAYBE_CAST (rep, octave_float_matrix);
-              MatrixType mtype = rep ? rep -> matrix_type () : MatrixType ();
-              FloatDET det = m.determinant (mtype, info, rcond);
-              retval(1) = rcond;
-              retval(0) = info == -1 ? static_cast<float>(0.0) : det.value ();
-              if (rep) rep->matrix_type (mtype);
-            }
-        }
-      else if (arg.is_complex_type ())
-        {
-          octave_idx_type info;
-          float rcond = 0.0;
-          // Always compute rcond, so we can detect numerically
-          // singular matrices.
-          FloatComplexMatrix m = arg.float_complex_matrix_value ();
-          if (! error_state)
-            {
-              MAYBE_CAST (rep, octave_float_complex_matrix);
-              MatrixType mtype = rep ? rep -> matrix_type () : MatrixType ();
-              FloatComplexDET det = m.determinant (mtype, info, rcond);
-              retval(1) = rcond;
-              retval(0) = info == -1 ? FloatComplex (0.0) : det.value ();
-              if (rep) rep->matrix_type (mtype);
-            }
-        }
-    }
-  else
-    {
-      if (arg.is_real_type ())
-        {
-          octave_idx_type info;
-          double rcond = 0.0;
-          // Always compute rcond, so we can detect numerically
-          // singular matrices.
-          if (arg.is_sparse_type ())
-            {
-              SparseMatrix m = arg.sparse_matrix_value ();
-              if (! error_state)
-                {
-                  DET det = m.determinant (info, rcond);
-                  retval(1) = rcond;
-                  retval(0) = info == -1 ? 0.0 : det.value ();
-                }
-            }
-          else
-            {
-              Matrix m = arg.matrix_value ();
-              if (! error_state)
-                {
-                  MAYBE_CAST (rep, octave_matrix);
-                  MatrixType mtype = rep ? rep -> matrix_type () : MatrixType ();
-                  DET det = m.determinant (mtype, info, rcond);
-                  retval(1) = rcond;
-                  retval(0) = info == -1 ? 0.0 : det.value ();
-                  if (rep) rep->matrix_type (mtype);
-                }
-            }
-        }
-      else if (arg.is_complex_type ())
-        {
-          octave_idx_type info;
-          double rcond = 0.0;
-          // Always compute rcond, so we can detect numerically
-          // singular matrices.
-          if (arg.is_sparse_type ())
-            {
-              SparseComplexMatrix m = arg.sparse_complex_matrix_value ();
-              if (! error_state)
-                {
-                  ComplexDET det = m.determinant (info, rcond);
-                  retval(1) = rcond;
-                  retval(0) = info == -1 ? Complex (0.0) : det.value ();
-                }
-            }
-          else
-            {
-              ComplexMatrix m = arg.complex_matrix_value ();
-              if (! error_state)
-                {
-                  MAYBE_CAST (rep, octave_complex_matrix);
-                  MatrixType mtype = rep ? rep -> matrix_type () : MatrixType ();
-                  ComplexDET det = m.determinant (mtype, info, rcond);
-                  retval(1) = rcond;
-                  retval(0) = info == -1 ? Complex (0.0) : det.value ();
-                  if (rep) rep->matrix_type (mtype);
-                }
-            }
-        }
-      else
-        gripe_wrong_type_arg ("det", arg);
-    }
-  return retval;
-}
-
-/*
-%!assert (det ([1, 2; 3, 4]), -2, 10*eps)
-%!assert (det (single ([1, 2; 3, 4])), single (-2), 10*eps ("single"))
-%!error det ()
-%!error det (1, 2)
-%!error <argument must be a square matrix> det ([1, 2; 3, 4; 5, 6])
-*/
--- a/src/DLD-FUNCTIONS/dlmread.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,520 +0,0 @@
-/*
-
-Copyright (C) 2008-2012 Jonathan Stickel
-Copyright (C) 2010 Jaroslav Hajek
-
-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/>.
-
-*/
-
-// Adapted from previous version of dlmread.occ as authored by Kai
-// Habel, but core code has been completely re-written.
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <cctype>
-#include <fstream>
-#include <limits>
-
-#include "file-ops.h"
-#include "lo-ieee.h"
-
-#include "defun-dld.h"
-#include "oct-stream.h"
-#include "error.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-static const octave_idx_type idx_max =  std::numeric_limits<octave_idx_type>::max ();
-
-static bool
-read_cell_spec (std::istream& is, octave_idx_type& row, octave_idx_type& col)
-{
-  bool stat = false;
-
-  if (is.peek () == std::istream::traits_type::eof ())
-    stat = true;
-  else
-    {
-      if (::isalpha (is.peek ()))
-        {
-          col = 0;
-          while (is && ::isalpha (is.peek ()))
-            {
-              char ch = is.get ();
-              col *= 26;
-              if (ch >= 'a')
-                col += ch - 'a' + 1;
-              else
-                col += ch - 'A' + 1;
-            }
-          col --;
-
-          if (is)
-            {
-              is >> row;
-              row --;
-              if (is)
-                stat = true;
-            }
-        }
-    }
-
-  return stat;
-}
-
-static bool
-parse_range_spec (const octave_value& range_spec,
-                  octave_idx_type& rlo, octave_idx_type& clo,
-                  octave_idx_type& rup, octave_idx_type& cup)
-{
-  bool stat = true;
-
-  if (range_spec.is_string ())
-    {
-      std::istringstream is (range_spec.string_value ());
-      char ch = is.peek ();
-
-      if (ch == '.' || ch == ':')
-        {
-          rlo = 0;
-          clo = 0;
-          ch = is.get ();
-          if (ch == '.')
-            {
-              ch = is.get ();
-              if (ch != '.')
-                stat = false;
-            }
-        }
-      else
-        {
-          stat = read_cell_spec (is, rlo, clo);
-
-          if (stat)
-            {
-              ch = is.peek ();
-
-              if (ch == '.' || ch == ':')
-                {
-                  ch = is.get ();
-                  if (ch == '.')
-                    {
-                      ch = is.get ();
-                      if (!is || ch != '.')
-                        stat = false;
-                    }
-
-                  rup = idx_max - 1;
-                  cup = idx_max - 1;
-                }
-              else
-                {
-                  rup = rlo;
-                  cup = clo;
-                  if (!is || !is.eof ())
-                    stat = false;
-                }
-            }
-        }
-
-      if (stat && is && !is.eof ())
-        stat = read_cell_spec (is, rup, cup);
-
-      if (!is || !is.eof ())
-        stat = false;
-    }
-  else if (range_spec.is_real_matrix () && range_spec.numel () == 4)
-    {
-      ColumnVector range(range_spec.vector_value ());
-      // double --> unsigned int
-      rlo = static_cast<octave_idx_type> (range(0));
-      clo = static_cast<octave_idx_type> (range(1));
-      rup = static_cast<octave_idx_type> (range(2));
-      cup = static_cast<octave_idx_type> (range(3));
-    }
-  else
-    stat = false;
-
-  return stat;
-}
-
-DEFUN_DLD (dlmread, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{data} =} dlmread (@var{file})\n\
-@deftypefnx {Loadable Function} {@var{data} =} dlmread (@var{file}, @var{sep})\n\
-@deftypefnx {Loadable Function} {@var{data} =} dlmread (@var{file}, @var{sep}, @var{r0}, @var{c0})\n\
-@deftypefnx {Loadable Function} {@var{data} =} dlmread (@var{file}, @var{sep}, @var{range})\n\
-@deftypefnx {Loadable Function} {@var{data} =} dlmread (@dots{}, \"emptyvalue\", @var{EMPTYVAL})\n\
-Read the matrix @var{data} from a text file.  If not defined the separator\n\
-between fields is determined from the file itself.  Otherwise the\n\
-separation character is defined by @var{sep}.\n\
-\n\
-Given two scalar arguments @var{r0} and @var{c0}, these define the starting\n\
-row and column of the data to be read.  These values are indexed from zero,\n\
-such that the first row corresponds to an index of zero.\n\
-\n\
-The @var{range} parameter may be a 4-element vector containing the upper\n\
-left and lower right corner @code{[@var{R0},@var{C0},@var{R1},@var{C1}]}\n\
-where the lowest index value is zero.  Alternatively, a spreadsheet style\n\
-range such as \"A2..Q15\" or \"T1:AA5\" can be used.  The lowest alphabetical\n\
-index 'A' refers to the first column.  The lowest row index is 1.\n\
-\n\
-@var{file} should be a file name or file id given by @code{fopen}.  In the\n\
-latter case, the file is read until end of file is reached.\n\
-\n\
-The \"emptyvalue\" option may be used to specify the value used to fill empty\n\
-fields.  The default is zero.\n\
-@seealso{csvread, textscan, textread, dlmwrite}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  double empty_value = 0.0;
-
-  if (nargin > 2 && args(nargin-2).is_string ()
-      && args(nargin-2).string_value () == "emptyvalue")
-    {
-      empty_value = args(nargin-1).double_value ();
-      if (error_state)
-         return retval;
-      nargin -= 2;
-    }
-
-  if (nargin < 1 || nargin > 4)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  std::istream *input = 0;
-  std::ifstream input_file;
-
-  if (args(0).is_string ())
-    {
-      // File name.
-      std::string fname (args(0).string_value ());
-      if (error_state)
-         return retval;
-
-      std::string tname = file_ops::tilde_expand (fname);
-
-      input_file.open (tname.c_str (), std::ios::in);
-
-      if (! input_file)
-        {
-          error ("dlmread: unable to open file `%s'", fname.c_str ());
-          return retval;
-        }
-      else
-        input = &input_file;
-    }
-  else if (args(0).is_scalar_type ())
-    {
-      octave_stream is = octave_stream_list::lookup (args(0), "dlmread");
-
-      if (error_state)
-         return retval;
-
-      input = is.input_stream ();
-
-      if (! input)
-        {
-          error ("dlmread: stream FILE not open for input");
-          return retval;
-        }
-    }
-  else
-    {
-      error ("dlmread: FILE argument must be a string or file id");
-      return retval;
-    }
-
-  // Set default separator.
-  std::string sep;
-  if (nargin > 1)
-    {
-      if (args(1).is_sq_string ())
-        sep = do_string_escapes (args(1).string_value ());
-      else
-        sep = args(1).string_value ();
-
-      if (error_state)
-        return retval;
-    }
-
-  // Take a subset if a range was given.
-  octave_idx_type r0 = 0, c0 = 0, r1 = idx_max-1, c1 = idx_max-1;
-  if (nargin > 2)
-    {
-      if (nargin == 3)
-        {
-          if (!parse_range_spec (args (2), r0, c0, r1, c1))
-            error ("dlmread: error parsing RANGE");
-        }
-      else if (nargin == 4)
-        {
-          r0 = args(2).idx_type_value ();
-          c0 = args(3).idx_type_value ();
-
-          if (error_state)
-            return retval;
-        }
-
-      if (r0 < 0 || c0 < 0)
-        error ("dlmread: left & top must be positive");
-    }
-
-  if (!error_state)
-    {
-      octave_idx_type i = 0, j = 0, r = 1, c = 1, rmax = 0, cmax = 0;
-
-      Matrix rdata;
-      ComplexMatrix cdata;
-
-      bool iscmplx = false;
-      bool sepflag = false;
-
-      std::string line;
-
-      // Skip the r0 leading lines as these might be a header.
-      for (octave_idx_type m = 0; m < r0; m++)
-        getline (*input, line);
-      r1 -= r0;
-
-      std::istringstream tmp_stream;
-
-      // Read in the data one field at a time, growing the data matrix
-      // as needed.
-      while (getline (*input, line))
-        {
-          // Skip blank lines for compatibility.
-          if (line.find_first_not_of (" \t") == std::string::npos)
-            continue;
-
-          // To be compatible with matlab, blank separator should
-          // correspond to whitespace as delimter.
-          if (!sep.length ())
-            {
-              size_t n = line.find_first_of (",:; \t",
-                                             line.find_first_of ("0123456789"));
-              if (n == std::string::npos)
-                {
-                  sep = " \t";
-                  sepflag = true;
-                }
-              else
-                {
-                  char ch = line.at (n);
-
-                  switch (line.at (n))
-                    {
-                    case ' ':
-                    case '\t':
-                      sepflag = true;
-                      sep = " \t";
-                      break;
-
-                    default:
-                      sep = ch;
-                      break;
-                    }
-                }
-            }
-
-          if (cmax == 0)
-            {
-              // Try to estimate the number of columns.  Skip leading
-              // whitespace.
-              size_t pos1 = line.find_first_not_of (" \t");
-              do
-                {
-                  size_t pos2 = line.find_first_of (sep, pos1);
-
-                  if (sepflag && pos2 != std::string::npos)
-                    // Treat consecutive separators as one.
-                    {
-                      pos2 = line.find_first_not_of (sep, pos2);
-                      if (pos2 != std::string::npos)
-                        pos2 -= 1;
-                      else
-                        pos2 = line.length () - 1;
-                    }
-
-                  cmax++;
-
-                  if (pos2 != std::string::npos)
-                    pos1 = pos2 + 1;
-                  else
-                    pos1 = std::string::npos;
-
-                }
-              while (pos1 != std::string::npos);
-
-              if (iscmplx)
-                cdata.resize (rmax, cmax);
-              else
-                rdata.resize (rmax, cmax);
-            }
-
-          r = (r > i + 1 ? r : i + 1);
-          j = 0;
-          // Skip leading whitespace.
-          size_t pos1 = line.find_first_not_of (" \t");
-          do
-            {
-              octave_quit ();
-
-              size_t pos2 = line.find_first_of (sep, pos1);
-              std::string str = line.substr (pos1, pos2 - pos1);
-
-              if (sepflag && pos2 != std::string::npos)
-                // Treat consecutive separators as one.
-                pos2 = line.find_first_not_of (sep, pos2) - 1;
-
-              c = (c > j + 1 ? c : j + 1);
-              if (r > rmax || c > cmax)
-                {
-                  // Use resize_and_fill for the case of not-equal
-                  // length rows.
-                  rmax = 2*r;
-                  cmax = c;
-                  if (iscmplx)
-                    cdata.resize (rmax, cmax);
-                  else
-                    rdata.resize (rmax, cmax);
-                }
-
-              tmp_stream.str (str);
-              tmp_stream.clear ();
-
-              double x = octave_read_double (tmp_stream);
-              if (tmp_stream)
-                {
-                  if (tmp_stream.eof ())
-                    {
-                      if (iscmplx)
-                        cdata(i,j++) = x;
-                      else
-                        rdata(i,j++) = x;
-                    }
-                  else if (std::toupper (tmp_stream.peek ()) == 'I')
-                    {
-                      // This is to allow pure imaginary numbers.
-                      if (iscmplx)
-                        cdata(i,j++) = x;
-                      else
-                        rdata(i,j++) = x;
-                    }
-                  else
-                    {
-                      double y = octave_read_double (tmp_stream);
-
-                      if (!iscmplx && y != 0.)
-                        {
-                          iscmplx = true;
-                          cdata = ComplexMatrix (rdata);
-                        }
-
-                      if (iscmplx)
-                        cdata(i,j++) = Complex (x, y);
-                      else
-                        rdata(i,j++) = x;
-                    }
-                }
-              else if (iscmplx)
-                cdata(i,j++) = empty_value;
-              else
-                rdata(i,j++) = empty_value;
-
-              if (pos2 != std::string::npos)
-                pos1 = pos2 + 1;
-              else
-                pos1 = std::string::npos;
-
-            }
-          while (pos1 != std::string::npos);
-
-          if (i == r1)
-            break;
-
-          i++;
-        }
-
-      if (r1 >= r)
-        r1 = r - 1;
-      if (c1 >= c)
-        c1 = c - 1;
-
-      // Now take the subset of the matrix.
-      if (iscmplx)
-        cdata = cdata.extract (0, c0, r1, c1);
-      else
-        rdata = rdata.extract (0, c0, r1, c1);
-
-      if (iscmplx)
-        retval(0) = cdata;
-      else
-        retval(0) = rdata;
-    }
-
-  return retval;
-}
-
-/*
-%!shared file
-%! file = tmpnam ();
-%! fid = fopen (file, "wt");
-%! fwrite (fid, "1, 2, 3\n4, 5, 6\n7, 8, 9\n10, 11, 12");
-%! fclose (fid);
-
-%!assert (dlmread (file), [1, 2, 3; 4, 5, 6; 7, 8, 9;10, 11, 12])
-%!assert (dlmread (file, ","), [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12])
-%!assert (dlmread (file, ",", [1, 0, 2, 1]), [4, 5; 7, 8])
-%!assert (dlmread (file, ",", "B1..C2"), [2, 3; 5, 6])
-%!assert (dlmread (file, ",", "B1:C2"), [2, 3; 5, 6])
-%!assert (dlmread (file, ",", "..C2"), [1, 2, 3; 4, 5, 6])
-%!assert (dlmread (file, ",", 0, 1), [2, 3; 5, 6; 8, 9; 11, 12])
-%!assert (dlmread (file, ",", "B1.."), [2, 3; 5, 6; 8, 9; 11, 12])
-%!error (dlmread (file, ",", [0 1]))
-
-%!test
-%! unlink (file);
-
-%!shared file
-%! file = tmpnam ();
-%! fid = fopen (file, "wt");
-%! fwrite (fid, "1, 2, 3\n4+4i, 5, 6\n7, 8, 9\n10, 11, 12");
-%! fclose (fid);
-
-%!assert (dlmread (file), [1, 2, 3; 4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12])
-%!assert (dlmread (file, ","), [1, 2, 3; 4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12])
-%!assert (dlmread (file, ",", [1, 0, 2, 1]), [4 + 4i, 5; 7, 8])
-%!assert (dlmread (file, ",", "A2..B3"), [4 + 4i, 5; 7, 8])
-%!assert (dlmread (file, ",", "A2:B3"), [4 + 4i, 5; 7, 8])
-%!assert (dlmread (file, ",", "..B3"), [1, 2; 4 + 4i, 5; 7, 8])
-%!assert (dlmread (file, ",", 1, 0), [4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12])
-%!assert (dlmread (file, ",", "A2.."), [4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12])
-%!error (dlmread (file, ",", [0 1]))
-
-%!test
-%! unlink (file);
-*/
--- a/src/DLD-FUNCTIONS/dot.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,364 +0,0 @@
-/*
-
-Copyright (C) 2009-2012 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "f77-fcn.h"
-#include "mx-base.h"
-#include "error.h"
-#include "defun-dld.h"
-#include "parse.h"
-
-extern "C"
-{
-  F77_RET_T
-  F77_FUNC (ddot3, DDOT3) (const octave_idx_type&, const octave_idx_type&,
-                           const octave_idx_type&, const double*,
-                           const double*, double*);
-
-  F77_RET_T
-  F77_FUNC (sdot3, SDOT3) (const octave_idx_type&, const octave_idx_type&,
-                           const octave_idx_type&, const float*,
-                           const float*, float*);
-
-  F77_RET_T
-  F77_FUNC (zdotc3, ZDOTC3) (const octave_idx_type&, const octave_idx_type&,
-                             const octave_idx_type&, const Complex*,
-                             const Complex*, Complex*);
-
-  F77_RET_T
-  F77_FUNC (cdotc3, CDOTC3) (const octave_idx_type&, const octave_idx_type&,
-                             const octave_idx_type&, const FloatComplex*,
-                             const FloatComplex*, FloatComplex*);
-
-  F77_RET_T
-  F77_FUNC (dmatm3, DMATM3) (const octave_idx_type&, const octave_idx_type&,
-                             const octave_idx_type&, const octave_idx_type&,
-                             const double*, const double*, double*);
-
-  F77_RET_T
-  F77_FUNC (smatm3, SMATM3) (const octave_idx_type&, const octave_idx_type&,
-                             const octave_idx_type&, const octave_idx_type&,
-                             const float*, const float*, float*);
-
-  F77_RET_T
-  F77_FUNC (zmatm3, ZMATM3) (const octave_idx_type&, const octave_idx_type&,
-                             const octave_idx_type&, const octave_idx_type&,
-                             const Complex*, const Complex*, Complex*);
-
-  F77_RET_T
-  F77_FUNC (cmatm3, CMATM3) (const octave_idx_type&, const octave_idx_type&,
-                             const octave_idx_type&, const octave_idx_type&,
-                             const FloatComplex*, const FloatComplex*,
-                             FloatComplex*);
-}
-
-static void
-get_red_dims (const dim_vector& x, const dim_vector& y, int dim,
-              dim_vector& z, octave_idx_type& m, octave_idx_type& n,
-              octave_idx_type& k)
-{
-  int nd = x.length ();
-  assert (nd == y.length ());
-  z = dim_vector::alloc (nd);
-  m = 1, n = 1, k = 1;
-  for (int i = 0; i < nd; i++)
-    {
-      if (i < dim)
-        {
-          z(i) = x(i);
-          m *= x(i);
-        }
-      else if (i > dim)
-        {
-          z(i) = x(i);
-          n *= x(i);
-        }
-      else
-        {
-          k = x(i);
-          z(i) = 1;
-        }
-    }
-}
-
-DEFUN_DLD (dot, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} dot (@var{x}, @var{y}, @var{dim})\n\
-Compute the dot product of two vectors.  If @var{x} and @var{y}\n\
-are matrices, calculate the dot products along the first\n\
-non-singleton dimension.  If the optional argument @var{dim} is\n\
-given, calculate the dot products along this dimension.\n\
-\n\
-This is equivalent to\n\
-@code{sum (conj (@var{X}) .* @var{Y}, @var{dim})},\n\
-but avoids forming a temporary array and is faster.  When @var{X} and\n\
-@var{Y} are column vectors, the result is equivalent to\n\
-@code{@var{X}' * @var{Y}}.\n\
-@seealso{cross, divergence}\n\
-@end deftypefn")
-{
-  octave_value retval;
-  int nargin = args.length ();
-
-  if (nargin < 2 || nargin > 3)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value argx = args(0), argy = args(1);
-
-  if (argx.is_numeric_type () && argy.is_numeric_type ())
-    {
-      dim_vector dimx = argx.dims (), dimy = argy.dims ();
-      bool match = dimx == dimy;
-      if (! match && nargin == 2
-          && dimx.is_vector () && dimy.is_vector ())
-        {
-          // Change to column vectors.
-          dimx = dimx.redim (1);
-          argx = argx.reshape (dimx);
-          dimy = dimy.redim (1);
-          argy = argy.reshape (dimy);
-          match = ! error_state;
-        }
-
-      if (match)
-        {
-          int dim;
-          if (nargin == 2)
-            dim = dimx.first_non_singleton ();
-          else
-            dim = args(2).int_value (true) - 1;
-
-          if (error_state)
-            ;
-          else if (dim < 0)
-            error ("dot: DIM must be a valid dimension");
-          else
-            {
-              octave_idx_type m, n, k;
-              dim_vector dimz;
-              if (argx.is_complex_type () || argy.is_complex_type ())
-                {
-                  if (argx.is_single_type () || argy.is_single_type ())
-                    {
-                      FloatComplexNDArray x = argx.float_complex_array_value ();
-                      FloatComplexNDArray y = argy.float_complex_array_value ();
-                      get_red_dims (dimx, dimy, dim, dimz, m, n, k);
-                      FloatComplexNDArray z(dimz);
-                      if (! error_state)
-                        F77_XFCN (cdotc3, CDOTC3, (m, n, k, x.data (), y.data (),
-                                                   z.fortran_vec ()));
-                      retval = z;
-                    }
-                  else
-                    {
-                      ComplexNDArray x = argx.complex_array_value ();
-                      ComplexNDArray y = argy.complex_array_value ();
-                      get_red_dims (dimx, dimy, dim, dimz, m, n, k);
-                      ComplexNDArray z(dimz);
-                      if (! error_state)
-                        F77_XFCN (zdotc3, ZDOTC3, (m, n, k, x.data (), y.data (),
-                                                   z.fortran_vec ()));
-                      retval = z;
-                    }
-                }
-              else if (argx.is_float_type () && argy.is_float_type ())
-                {
-                  if (argx.is_single_type () || argy.is_single_type ())
-                    {
-                      FloatNDArray x = argx.float_array_value ();
-                      FloatNDArray y = argy.float_array_value ();
-                      get_red_dims (dimx, dimy, dim, dimz, m, n, k);
-                      FloatNDArray z(dimz);
-                      if (! error_state)
-                        F77_XFCN (sdot3, SDOT3, (m, n, k, x.data (), y.data (),
-                                                 z.fortran_vec ()));
-                      retval = z;
-                    }
-                  else
-                    {
-                      NDArray x = argx.array_value ();
-                      NDArray y = argy.array_value ();
-                      get_red_dims (dimx, dimy, dim, dimz, m, n, k);
-                      NDArray z(dimz);
-                      if (! error_state)
-                        F77_XFCN (ddot3, DDOT3, (m, n, k, x.data (), y.data (),
-                                                 z.fortran_vec ()));
-                      retval = z;
-                    }
-                }
-              else
-                {
-                  // Non-optimized evaluation.
-                  octave_value_list tmp;
-                  tmp(1) = args(2);
-                  tmp(0) = do_binary_op (octave_value::op_el_mul, argx, argy);
-                  if (! error_state)
-                    {
-                      tmp = feval ("sum", tmp, 1);
-                      if (! tmp.empty ())
-                        retval = tmp(0);
-                    }
-                }
-            }
-        }
-      else
-        error ("dot: sizes of X and Y must match");
-
-    }
-  else
-    error ("dot: X and Y must be numeric");
-
-  return retval;
-}
-
-/*
-%!assert (dot ([1, 2], [2, 3]), 8)
-
-%!test
-%! x = [2, 1; 2, 1];
-%! y = [-0.5, 2; 0.5, -2];
-%! assert (dot (x, y), [0 0]);
-
-%!test
-%! x = [1+i, 3-i; 1-i, 3-i];
-%! assert (dot (x, x), [4, 20]);
-*/
-
-DEFUN_DLD (blkmm, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} blkmm (@var{A}, @var{B})\n\
-Compute products of matrix blocks.  The blocks are given as\n\
-2-dimensional subarrays of the arrays @var{A}, @var{B}.\n\
-The size of @var{A} must have the form @code{[m,k,@dots{}]} and\n\
-size of @var{B} must be @code{[k,n,@dots{}]}.  The result is\n\
-then of size @code{[m,n,@dots{}]} and is computed as follows:\n\
-\n\
-@example\n\
-@group\n\
-for i = 1:prod (size (@var{A})(3:end))\n\
-  @var{C}(:,:,i) = @var{A}(:,:,i) * @var{B}(:,:,i)\n\
-endfor\n\
-@end group\n\
-@end example\n\
-@end deftypefn")
-{
-  octave_value retval;
-  int nargin = args.length ();
-
-  if (nargin != 2)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value argx = args(0), argy = args(1);
-
-  if (argx.is_numeric_type () && argy.is_numeric_type ())
-    {
-      const dim_vector dimx = argx.dims (), dimy = argy.dims ();
-      int nd = dimx.length ();
-      octave_idx_type m = dimx(0), k = dimx(1), n = dimy(1), np = 1;
-      bool match = dimy(0) == k && nd == dimy.length ();
-      dim_vector dimz = dim_vector::alloc (nd);
-      dimz(0) = m;
-      dimz(1) = n;
-      for (int i = 2; match && i < nd; i++)
-        {
-          match = match && dimx(i) == dimy(i);
-          dimz(i) = dimx(i);
-          np *= dimz(i);
-        }
-
-      if (match)
-        {
-          if (argx.is_complex_type () || argy.is_complex_type ())
-            {
-              if (argx.is_single_type () || argy.is_single_type ())
-                {
-                  FloatComplexNDArray x = argx.float_complex_array_value ();
-                  FloatComplexNDArray y = argy.float_complex_array_value ();
-                  FloatComplexNDArray z(dimz);
-                  if (! error_state)
-                    F77_XFCN (cmatm3, CMATM3, (m, n, k, np, x.data (), y.data (),
-                                               z.fortran_vec ()));
-                  retval = z;
-                }
-              else
-                {
-                  ComplexNDArray x = argx.complex_array_value ();
-                  ComplexNDArray y = argy.complex_array_value ();
-                  ComplexNDArray z(dimz);
-                  if (! error_state)
-                    F77_XFCN (zmatm3, ZMATM3, (m, n, k, np, x.data (), y.data (),
-                                               z.fortran_vec ()));
-                  retval = z;
-                }
-            }
-          else
-            {
-              if (argx.is_single_type () || argy.is_single_type ())
-                {
-                  FloatNDArray x = argx.float_array_value ();
-                  FloatNDArray y = argy.float_array_value ();
-                  FloatNDArray z(dimz);
-                  if (! error_state)
-                    F77_XFCN (smatm3, SMATM3, (m, n, k, np, x.data (), y.data (),
-                                               z.fortran_vec ()));
-                  retval = z;
-                }
-              else
-                {
-                  NDArray x = argx.array_value ();
-                  NDArray y = argy.array_value ();
-                  NDArray z(dimz);
-                  if (! error_state)
-                    F77_XFCN (dmatm3, DMATM3, (m, n, k, np, x.data (), y.data (),
-                                               z.fortran_vec ()));
-                  retval = z;
-                }
-            }
-        }
-      else
-        error ("blkmm: A and B dimensions don't match: (%s) and (%s)",
-               dimx.str ().c_str (), dimy.str ().c_str ());
-
-    }
-  else
-    error ("blkmm: A and B must be numeric");
-
-  return retval;
-}
-
-/*
-%!test
-%! x(:,:,1) = [1 2; 3 4];
-%! x(:,:,2) = [1 1; 1 1];
-%! z(:,:,1) = [7 10; 15 22];
-%! z(:,:,2) = [2 2; 2 2];
-%! assert (blkmm (x,x), z);
-*/
--- a/src/DLD-FUNCTIONS/eig.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,334 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "EIG.h"
-#include "fEIG.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-DEFUN_DLD (eig, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{lambda} =} eig (@var{A})\n\
-@deftypefnx {Loadable Function} {@var{lambda} =} eig (@var{A}, @var{B})\n\
-@deftypefnx {Loadable Function} {[@var{V}, @var{lambda}] =} eig (@var{A})\n\
-@deftypefnx {Loadable Function} {[@var{V}, @var{lambda}] =} eig (@var{A}, @var{B})\n\
-Compute the eigenvalues (and optionally the eigenvectors) of a matrix\n\
-or a pair of matrices\n\
-\n\
-The algorithm used depends on whether there are one or two input\n\
-matrices, if they are real or complex and if they are symmetric\n\
-(Hermitian if complex) or nonsymmetric.\n\
-\n\
-The eigenvalues returned by @code{eig} are not ordered.\n\
-@seealso{eigs, svd}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin > 2 || nargin == 0 || nargout > 2)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value arg_a, arg_b;
-
-  octave_idx_type nr_a = 0, nr_b = 0;
-  octave_idx_type nc_a = 0, nc_b = 0;
-
-  arg_a = args(0);
-  nr_a = arg_a.rows ();
-  nc_a = arg_a.columns ();
-
-  int arg_is_empty = empty_arg ("eig", nr_a, nc_a);
-  if (arg_is_empty < 0)
-    return retval;
-  else if (arg_is_empty > 0)
-    return octave_value_list (2, Matrix ());
-
-  if (!(arg_a.is_single_type () || arg_a.is_double_type ()))
-    {
-      gripe_wrong_type_arg ("eig", arg_a);
-      return retval;
-    }
-
-  if (nargin == 2)
-    {
-      arg_b = args(1);
-      nr_b = arg_b.rows ();
-      nc_b = arg_b.columns ();
-
-      arg_is_empty = empty_arg ("eig", nr_b, nc_b);
-      if (arg_is_empty < 0)
-        return retval;
-      else if (arg_is_empty > 0)
-        return octave_value_list (2, Matrix ());
-
-      if (!(arg_b.is_single_type () || arg_b.is_double_type ()))
-        {
-          gripe_wrong_type_arg ("eig", arg_b);
-          return retval;
-        }
-    }
-
-  if (nr_a != nc_a)
-    {
-      gripe_square_matrix_required ("eig");
-      return retval;
-    }
-
-  if (nargin == 2 && nr_b != nc_b)
-    {
-      gripe_square_matrix_required ("eig");
-      return retval;
-    }
-
-  Matrix tmp_a, tmp_b;
-  ComplexMatrix ctmp_a, ctmp_b;
-  FloatMatrix ftmp_a, ftmp_b;
-  FloatComplexMatrix fctmp_a, fctmp_b;
-
-  if (arg_a.is_single_type ())
-    {
-      FloatEIG result;
-
-      if (nargin == 1)
-        {
-          if (arg_a.is_real_type ())
-            {
-              ftmp_a = arg_a.float_matrix_value ();
-
-              if (error_state)
-                return retval;
-              else
-                result = FloatEIG (ftmp_a, nargout > 1);
-            }
-          else
-            {
-              fctmp_a = arg_a.float_complex_matrix_value ();
-
-              if (error_state)
-                return retval;
-              else
-                result = FloatEIG (fctmp_a, nargout > 1);
-            }
-        }
-      else if (nargin == 2)
-        {
-          if (arg_a.is_real_type () && arg_b.is_real_type ())
-            {
-              ftmp_a = arg_a.float_matrix_value ();
-              ftmp_b = arg_b.float_matrix_value ();
-
-              if (error_state)
-                return retval;
-              else
-                result = FloatEIG (ftmp_a, ftmp_b, nargout > 1);
-            }
-          else
-            {
-              fctmp_a = arg_a.float_complex_matrix_value ();
-              fctmp_b = arg_b.float_complex_matrix_value ();
-
-              if (error_state)
-                return retval;
-              else
-                result = FloatEIG (fctmp_a, fctmp_b, nargout > 1);
-            }
-        }
-
-      if (! error_state)
-        {
-          if (nargout == 0 || nargout == 1)
-            {
-              retval(0) = result.eigenvalues ();
-            }
-          else
-            {
-              // Blame it on Matlab.
-
-              FloatComplexDiagMatrix d (result.eigenvalues ());
-
-              retval(1) = d;
-              retval(0) = result.eigenvectors ();
-            }
-        }
-    }
-  else
-    {
-      EIG result;
-
-      if (nargin == 1)
-        {
-          if (arg_a.is_real_type ())
-            {
-              tmp_a = arg_a.matrix_value ();
-
-              if (error_state)
-                return retval;
-              else
-                result = EIG (tmp_a, nargout > 1);
-            }
-          else
-            {
-              ctmp_a = arg_a.complex_matrix_value ();
-
-              if (error_state)
-                return retval;
-              else
-                result = EIG (ctmp_a, nargout > 1);
-            }
-        }
-      else if (nargin == 2)
-        {
-          if (arg_a.is_real_type () && arg_b.is_real_type ())
-            {
-              tmp_a = arg_a.matrix_value ();
-              tmp_b = arg_b.matrix_value ();
-
-              if (error_state)
-                return retval;
-              else
-                result = EIG (tmp_a, tmp_b, nargout > 1);
-            }
-          else
-            {
-              ctmp_a = arg_a.complex_matrix_value ();
-              ctmp_b = arg_b.complex_matrix_value ();
-
-              if (error_state)
-                return retval;
-              else
-                result = EIG (ctmp_a, ctmp_b, nargout > 1);
-            }
-        }
-
-      if (! error_state)
-        {
-          if (nargout == 0 || nargout == 1)
-            {
-              retval(0) = result.eigenvalues ();
-            }
-          else
-            {
-              // Blame it on Matlab.
-
-              ComplexDiagMatrix d (result.eigenvalues ());
-
-              retval(1) = d;
-              retval(0) = result.eigenvectors ();
-            }
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!assert (eig ([1, 2; 2, 1]), [-1; 3], sqrt (eps))
-
-%!test
-%! [v, d] = eig ([1, 2; 2, 1]);
-%! x = 1 / sqrt (2);
-%! assert (d, [-1, 0; 0, 3], sqrt (eps));
-%! assert (v, [-x, x; x, x], sqrt (eps));
-
-%!assert (eig (single ([1, 2; 2, 1])), single ([-1; 3]), sqrt (eps ("single")))
-
-%!test
-%! [v, d] = eig (single ([1, 2; 2, 1]));
-%! x = single (1 / sqrt (2));
-%! assert (d, single ([-1, 0; 0, 3]), sqrt (eps ("single")));
-%! assert (v, [-x, x; x, x], sqrt (eps ("single")));
-
-%!test
-%! A = [1, 2; -1, 1];  B = [3, 3; 1, 2];
-%! [v, d] = eig (A, B);
-%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps));
-%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps));
-
-%!test
-%! A = single ([1, 2; -1, 1]);  B = single ([3, 3; 1, 2]);
-%! [v, d] = eig (A, B);
-%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps ("single")));
-%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps ("single")));
-
-%!test
-%! A = [1, 2; 2, 1];  B = [3, -2; -2, 3];
-%! [v, d] = eig (A, B);
-%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps));
-%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps));
-
-%!test
-%! A = single ([1, 2; 2, 1]);  B = single ([3, -2; -2, 3]);
-%! [v, d] = eig (A, B);
-%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps ("single")));
-%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps ("single")));
-
-%!test
-%! A = [1+3i, 2+i; 2-i, 1+3i];  B = [5+9i, 2+i; 2-i, 5+9i];
-%! [v, d] = eig (A, B);
-%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps));
-%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps));
-
-%!test
-%! A = single ([1+3i, 2+i; 2-i, 1+3i]);  B = single ([5+9i, 2+i; 2-i, 5+9i]);
-%! [v, d] = eig (A, B);
-%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps ("single")));
-%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps ("single")));
-
-%!test
-%! A = [1+3i, 2+3i; 3-8i, 8+3i];  B = [8+i, 3+i; 4-9i, 3+i];
-%! [v, d] = eig (A, B);
-%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps));
-%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps));
-
-%!test
-%! A = single ([1+3i, 2+3i; 3-8i, 8+3i]);  B = single ([8+i, 3+i; 4-9i, 3+i]);
-%! [v, d] = eig (A, B);
-%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps ("single")));
-%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps ("single")));
-
-%!test
-%! A = [1, 2; 3, 8];  B = [8, 3; 4, 3];
-%! [v, d] = eig (A, B);
-%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps));
-%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps));
-
-%!error eig ()
-%!error eig ([1, 2; 3, 4], [4, 3; 2, 1], 1)
-%!error <EIG requires same size matrices> eig ([1, 2; 3, 4], 2)
-%!error <argument must be a square matrix> eig ([1, 2; 3, 4; 5, 6])
-%!error <wrong type argument> eig ("abcd")
-%!error <wrong type argument> eig ([1 2 ; 2 3], "abcd")
-%!error <wrong type argument> eig (false, [1 2 ; 2 3])
-*/
--- a/src/DLD-FUNCTIONS/fft.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,319 +0,0 @@
-/*
-
-Copyright (C) 1997-2012 David Bateman
-Copyright (C) 1996-1997 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "lo-mappers.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-#if defined (HAVE_FFTW)
-#define FFTSRC "@sc{fftw}"
-#else
-#define FFTSRC "@sc{fftpack}"
-#endif
-
-static octave_value
-do_fft (const octave_value_list &args, const char *fcn, int type)
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 1 || nargin > 3)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value arg = args(0);
-  dim_vector dims = arg.dims ();
-  octave_idx_type n_points = -1;
-  int dim = -1;
-
-  if (nargin > 1)
-    {
-      if (! args(1).is_empty ())
-        {
-          double dval = args(1).double_value ();
-          if (xisnan (dval))
-            error ("%s: number of points (N) cannot be NaN", fcn);
-          else
-            {
-              n_points = NINTbig (dval);
-              if (n_points < 0)
-                error ("%s: number of points (N) must be greater than zero", fcn);
-            }
-        }
-    }
-
-  if (error_state)
-    return retval;
-
-  if (nargin > 2)
-    {
-      double dval = args(2).double_value ();
-      if (xisnan (dval))
-        error ("%s: DIM cannot be NaN", fcn);
-      else if (dval < 1 || dval > dims.length ())
-        error ("%s: DIM must be a valid dimension along which to perform FFT", fcn);
-      else
-        // to be safe, cast it back to int since dim is an int
-        dim = NINT (dval) - 1;
-    }
-
-  if (error_state)
-    return retval;
-
-  for (octave_idx_type i = 0; i < dims.length (); i++)
-    if (dims(i) < 0)
-      return retval;
-
-  if (dim < 0)
-    {
-      for (octave_idx_type i = 0; i < dims.length (); i++)
-        if (dims(i) > 1)
-          {
-            dim = i;
-            break;
-          }
-
-      // And if the first argument is scalar?
-      if (dim < 0)
-        dim = 1;
-    }
-
-  if (n_points < 0)
-    n_points = dims (dim);
-  else
-    dims (dim) = n_points;
-
-  if (dims.any_zero () || n_points == 0)
-    {
-      if (arg.is_single_type ())
-        return octave_value (FloatNDArray (dims));
-      else
-        return octave_value (NDArray (dims));
-    }
-
-  if (arg.is_single_type ())
-    {
-      if (arg.is_real_type ())
-        {
-          FloatNDArray nda = arg.float_array_value ();
-
-          if (! error_state)
-            {
-              nda.resize (dims, 0.0);
-              retval = (type != 0 ? nda.ifourier (dim) : nda.fourier (dim));
-            }
-        }
-      else
-        {
-          FloatComplexNDArray cnda = arg.float_complex_array_value ();
-
-          if (! error_state)
-            {
-              cnda.resize (dims, 0.0);
-              retval = (type != 0 ? cnda.ifourier (dim) : cnda.fourier (dim));
-            }
-        }
-    }
-  else
-    {
-      if (arg.is_real_type ())
-        {
-          NDArray nda = arg.array_value ();
-
-          if (! error_state)
-            {
-              nda.resize (dims, 0.0);
-              retval = (type != 0 ? nda.ifourier (dim) : nda.fourier (dim));
-            }
-        }
-      else if (arg.is_complex_type ())
-        {
-          ComplexNDArray cnda = arg.complex_array_value ();
-
-          if (! error_state)
-            {
-              cnda.resize (dims, 0.0);
-              retval = (type != 0 ? cnda.ifourier (dim) : cnda.fourier (dim));
-            }
-        }
-      else
-        {
-          gripe_wrong_type_arg (fcn, arg);
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!assert (fft ([]), [])
-%!assert (fft (zeros (10,0)), zeros (10,0))
-%!assert (fft (zeros (0,10)), zeros (0,10))
-%!assert (fft (0), 0)
-%!assert (fft (1), 1)
-%!assert (fft (ones (2,2)), [2,2; 0,0])
-%!assert (fft (eye (2,2)), [1,1; 1,-1])
-
-%!assert (fft (single ([])), single ([]))
-%!assert (fft (zeros (10,0,"single")), zeros (10,0,"single"))
-%!assert (fft (zeros (0,10,"single")), zeros (0,10,"single"))
-%!assert (fft (single (0)), single (0))
-%!assert (fft (single (1)), single (1))
-%!assert (fft (ones (2,2,"single")), single ([2,2; 0,0]))
-%!assert (fft (eye (2,2,"single")), single ([1,1; 1,-1]))
-
-%!error (fft ())
-*/
-
-
-DEFUN_DLD (fft, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} fft (@var{x})\n\
-@deftypefnx {Loadable Function} {} fft (@var{x}, @var{n})\n\
-@deftypefnx {Loadable Function} {} fft (@var{x}, @var{n}, @var{dim})\n\
-Compute the discrete Fourier transform of @var{A} using\n\
-a Fast Fourier Transform (FFT) algorithm.\n\
-\n\
-The FFT is calculated along the first non-singleton dimension of the\n\
-array.  Thus if @var{x} is a matrix, @code{fft (@var{x})} computes the\n\
-FFT for each column of @var{x}.\n\
-\n\
-If called with two arguments, @var{n} is expected to be an integer\n\
-specifying the number of elements of @var{x} to use, or an empty\n\
-matrix to specify that its value should be ignored.  If @var{n} is\n\
-larger than the dimension along which the FFT is calculated, then\n\
-@var{x} is resized and padded with zeros.  Otherwise, if @var{n} is\n\
-smaller than the dimension along which the FFT is calculated, then\n\
-@var{x} is truncated.\n\
-\n\
-If called with three arguments, @var{dim} is an integer specifying the\n\
-dimension of the matrix along which the FFT is performed\n\
-@seealso{ifft, fft2, fftn, fftw}\n\
-@end deftypefn")
-{
-  return do_fft (args, "fft", 0);
-}
-
-
-DEFUN_DLD (ifft, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} ifft (@var{x})\n\
-@deftypefnx {Loadable Function} {} ifft (@var{x}, @var{n})\n\
-@deftypefnx {Loadable Function} {} ifft (@var{x}, @var{n}, @var{dim})\n\
-Compute the inverse discrete Fourier transform of @var{A}\n\
-using a Fast Fourier Transform (FFT) algorithm.\n\
-\n\
-The inverse FFT is calculated along the first non-singleton dimension\n\
-of the array.  Thus if @var{x} is a matrix, @code{fft (@var{x})} computes\n\
-the inverse FFT for each column of @var{x}.\n\
-\n\
-If called with two arguments, @var{n} is expected to be an integer\n\
-specifying the number of elements of @var{x} to use, or an empty\n\
-matrix to specify that its value should be ignored.  If @var{n} is\n\
-larger than the dimension along which the inverse FFT is calculated, then\n\
-@var{x} is resized and padded with zeros.  Otherwise, if @var{n} is\n\
-smaller than the dimension along which the inverse FFT is calculated,\n\
-then @var{x} is truncated.\n\
-\n\
-If called with three arguments, @var{dim} is an integer specifying the\n\
-dimension of the matrix along which the inverse FFT is performed\n\
-@seealso{fft, ifft2, ifftn, fftw}\n\
-@end deftypefn")
-{
-  return do_fft (args, "ifft", 1);
-}
-
-/*
-%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-%%         Comalco Research and Technology
-%%         02 May 2000
-%!test
-%! N = 64;
-%! n = 4;
-%! t = 2*pi*(0:1:N-1)/N;
-%! s = cos (n*t);
-%! S = fft (s);
-%!
-%! answer = zeros (size (t));
-%! answer(n+1) = N/2;
-%! answer(N-n+1) = N/2;
-%!
-%! assert (S, answer, 4*N*eps);
-
-%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-%%         Comalco Research and Technology
-%%         02 May 2000
-%!test
-%! N = 64;
-%! n = 7;
-%! t = 2*pi*(0:1:N-1)/N;
-%! s = cos (n*t);
-%!
-%! S = zeros (size (t));
-%! S(n+1) = N/2;
-%! S(N-n+1) = N/2;
-%!
-%! assert (ifft (S), s, 4*N*eps);
-
-%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-%%         Comalco Research and Technology
-%%         02 May 2000
-%!test
-%! N = 64;
-%! n = 4;
-%! t = single (2*pi*(0:1:N-1)/N);
-%! s = cos (n*t);
-%! S = fft (s);
-%!
-%! answer = zeros (size (t), "single");
-%! answer(n+1) = N/2;
-%! answer(N-n+1) = N/2;
-%!
-%! assert (S, answer, 4*N*eps ("single"));
-
-%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-%%         Comalco Research and Technology
-%%         02 May 2000
-%!test
-%! N = 64;
-%! n = 7;
-%! t = 2*pi*(0:1:N-1)/N;
-%! s = cos (n*t);
-%!
-%! S = zeros (size (t), "single");
-%! S(n+1) = N/2;
-%! S(N-n+1) = N/2;
-%!
-%! assert (ifft (S), s, 4*N*eps ("single"));
-*/
--- a/src/DLD-FUNCTIONS/fft2.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,294 +0,0 @@
-/*
-
-Copyright (C) 1997-2012 David Bateman
-Copyright (C) 1996-1997 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "lo-mappers.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-// This function should be merged with Fifft.
-
-#if defined (HAVE_FFTW)
-#define FFTSRC "@sc{fftw}"
-#else
-#define FFTSRC "@sc{fftpack}"
-#endif
-
-static octave_value
-do_fft2 (const octave_value_list &args, const char *fcn, int type)
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 1 || nargin > 3)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value arg = args(0);
-  dim_vector dims = arg.dims ();
-  octave_idx_type n_rows = -1;
-
-  if (nargin > 1)
-    {
-      double dval = args(1).double_value ();
-      if (xisnan (dval))
-        error ("%s: number of rows (N) cannot be NaN", fcn);
-      else
-        {
-          n_rows = NINTbig (dval);
-          if (n_rows < 0)
-            error ("%s: number of rows (N) must be greater than zero", fcn);
-        }
-    }
-
-  if (error_state)
-    return retval;
-
-  octave_idx_type n_cols = -1;
-  if (nargin > 2)
-    {
-      double dval = args(2).double_value ();
-      if (xisnan (dval))
-        error ("%s: number of columns (M) cannot be NaN", fcn);
-      else
-        {
-          n_cols = NINTbig (dval);
-          if (n_cols < 0)
-            error ("%s: number of columns (M) must be greater than zero", fcn);
-        }
-    }
-
-  if (error_state)
-    return retval;
-
-  for (int i = 0; i < dims.length (); i++)
-    if (dims(i) < 0)
-      return retval;
-
-  if (n_rows < 0)
-    n_rows = dims (0);
-  else
-    dims (0) = n_rows;
-
-  if (n_cols < 0)
-    n_cols = dims (1);
-  else
-    dims (1) = n_cols;
-
-  if (dims.all_zero () || n_rows == 0 || n_cols == 0)
-    {
-      if (arg.is_single_type ())
-        return octave_value (FloatMatrix ());
-      else
-        return octave_value (Matrix ());
-    }
-
-  if (arg.is_single_type ())
-    {
-      if (arg.is_real_type ())
-        {
-          FloatNDArray nda = arg.float_array_value ();
-
-          if (! error_state)
-            {
-              nda.resize (dims, 0.0);
-              retval = (type != 0 ? nda.ifourier2d () : nda.fourier2d ());
-            }
-        }
-      else
-        {
-          FloatComplexNDArray cnda = arg.float_complex_array_value ();
-
-          if (! error_state)
-            {
-              cnda.resize (dims, 0.0);
-              retval = (type != 0 ? cnda.ifourier2d () : cnda.fourier2d ());
-            }
-        }
-    }
-  else
-    {
-      if (arg.is_real_type ())
-        {
-          NDArray nda = arg.array_value ();
-
-          if (! error_state)
-            {
-              nda.resize (dims, 0.0);
-              retval = (type != 0 ? nda.ifourier2d () : nda.fourier2d ());
-            }
-        }
-      else if (arg.is_complex_type ())
-        {
-          ComplexNDArray cnda = arg.complex_array_value ();
-
-          if (! error_state)
-            {
-              cnda.resize (dims, 0.0);
-              retval = (type != 0 ? cnda.ifourier2d () : cnda.fourier2d ());
-            }
-        }
-      else
-        {
-          gripe_wrong_type_arg (fcn, arg);
-        }
-    }
-
-  return retval;
-}
-
-DEFUN_DLD (fft2, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} fft2 (@var{A})\n\
-@deftypefnx {Loadable Function} {} fft2 (@var{A}, @var{m}, @var{n})\n\
-Compute the two-dimensional discrete Fourier transform of @var{A} using\n\
-a Fast Fourier Transform (FFT) algorithm.\n\
-\n\
-The optional arguments @var{m} and @var{n} may be used specify the\n\
-number of rows and columns of @var{A} to use.  If either of these is\n\
-larger than the size of @var{A}, @var{A} is resized and padded with\n\
-zeros.\n\
-\n\
-If @var{A} is a multi-dimensional matrix, each two-dimensional sub-matrix\n\
-of @var{A} is treated separately.\n\
-@seealso {ifft2, fft, fftn, fftw}\n\
-@end deftypefn")
-{
-  return do_fft2 (args, "fft2", 0);
-}
-
-
-DEFUN_DLD (ifft2, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} ifft2 (@var{A})\n\
-@deftypefnx {Loadable Function} {} ifft2 (@var{A}, @var{m}, @var{n})\n\
-Compute the inverse two-dimensional discrete Fourier transform of @var{A}\n\
-using a Fast Fourier Transform (FFT) algorithm.\n\
-\n\
-The optional arguments @var{m} and @var{n} may be used specify the\n\
-number of rows and columns of @var{A} to use.  If either of these is\n\
-larger than the size of @var{A}, @var{A} is resized and padded with\n\
-zeros.\n\
-\n\
-If @var{A} is a multi-dimensional matrix, each two-dimensional sub-matrix\n\
-of @var{A} is treated separately\n\
-@seealso {fft2, ifft, ifftn, fftw}\n\
-@end deftypefn")
-{
-  return do_fft2 (args, "ifft2", 1);
-}
-
-/*
-%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-%%         Comalco Research and Technology
-%%         02 May 2000
-%!test
-%! M = 16;
-%! N = 8;
-%!
-%! m = 5;
-%! n = 3;
-%!
-%! x = 2*pi*(0:1:M-1)/M;
-%! y = 2*pi*(0:1:N-1)/N;
-%! sx = cos (m*x);
-%! sy = sin (n*y);
-%! s = kron (sx',sy);
-%! S = fft2 (s);
-%! answer = kron (fft (sx)', fft (sy));
-%! assert (S, answer, 4*M*N*eps);
-
-%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-%%         Comalco Research and Technology
-%%         02 May 2000
-%!test
-%! M = 12;
-%! N = 7;
-%!
-%! m = 3;
-%! n = 2;
-%!
-%! x = 2*pi*(0:1:M-1)/M;
-%! y = 2*pi*(0:1:N-1)/N;
-%!
-%! sx = cos (m*x);
-%! sy = cos (n*y);
-%!
-%! S = kron (fft (sx)', fft (sy));
-%! answer = kron (sx', sy);
-%! s = ifft2 (S);
-%!
-%! assert (s, answer, 30*eps);
-
-
-%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-%%         Comalco Research and Technology
-%%         02 May 2000
-%!test
-%! M = 16;
-%! N = 8;
-%!
-%! m = 5;
-%! n = 3;
-%!
-%! x = 2*pi*(0:1:M-1)/M;
-%! y = 2*pi*(0:1:N-1)/N;
-%! sx = single (cos (m*x));
-%! sy = single (sin (n*y));
-%! s = kron (sx', sy);
-%! S = fft2 (s);
-%! answer = kron (fft (sx)', fft (sy));
-%! assert (S, answer, 4*M*N*eps ("single"));
-
-%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-%%         Comalco Research and Technology
-%%         02 May 2000
-%!test
-%! M = 12;
-%! N = 7;
-%!
-%! m = 3;
-%! n = 2;
-%!
-%! x = single (2*pi*(0:1:M-1)/M);
-%! y = single (2*pi*(0:1:N-1)/N);
-%!
-%! sx = cos (m*x);
-%! sy = cos (n*y);
-%!
-%! S = kron (fft (sx)', fft (sy));
-%! answer = kron (sx', sy);
-%! s = ifft2 (S);
-%!
-%! assert (s, answer, 30*eps ("single"));
-*/
--- a/src/DLD-FUNCTIONS/fftn.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,188 +0,0 @@
-/*
-
-Copyright (C) 2004-2012 David Bateman
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "lo-mappers.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-// This function should be merged with Fifft.
-
-#if defined (HAVE_FFTW)
-#define FFTSRC "@sc{fftw}"
-#else
-#define FFTSRC "@sc{fftpack}"
-#endif
-
-static octave_value
-do_fftn (const octave_value_list &args, const char *fcn, int type)
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 1 || nargin > 2)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value arg = args(0);
-  dim_vector dims = arg.dims ();
-
-  for (int i = 0; i < dims.length (); i++)
-    if (dims(i) < 0)
-      return retval;
-
-  if (nargin > 1)
-    {
-      Matrix val = args(1).matrix_value ();
-      if (val.rows () > val.columns ())
-        val = val.transpose ();
-
-      if (error_state || val.columns () != dims.length () || val.rows () != 1)
-        error ("%s: SIZE must be a vector of length dim", fcn);
-      else
-        {
-          for (int i = 0; i < dims.length (); i++)
-            {
-              if (xisnan (val(i,0)))
-                error ("%s: SIZE has invalid NaN entries", fcn);
-              else if (NINTbig (val(i,0)) < 0)
-                error ("%s: all dimensions in SIZE must be greater than zero", fcn);
-              else
-                {
-                  dims(i) = NINTbig(val(i,0));
-                }
-            }
-        }
-    }
-
-  if (error_state)
-    return retval;
-
-  if (dims.all_zero ())
-    {
-      if (arg.is_single_type ())
-        return octave_value (FloatMatrix ());
-      else
-        return octave_value (Matrix ());
-    }
-
-  if (arg.is_single_type ())
-    {
-      if (arg.is_real_type ())
-        {
-          FloatNDArray nda = arg.float_array_value ();
-
-          if (! error_state)
-            {
-              nda.resize (dims, 0.0);
-              retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ());
-            }
-        }
-      else
-        {
-          FloatComplexNDArray cnda = arg.float_complex_array_value ();
-
-          if (! error_state)
-            {
-              cnda.resize (dims, 0.0);
-              retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ());
-            }
-        }
-    }
-  else
-    {
-      if (arg.is_real_type ())
-        {
-          NDArray nda = arg.array_value ();
-
-          if (! error_state)
-            {
-              nda.resize (dims, 0.0);
-              retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ());
-            }
-        }
-      else if (arg.is_complex_type ())
-        {
-          ComplexNDArray cnda = arg.complex_array_value ();
-
-          if (! error_state)
-            {
-              cnda.resize (dims, 0.0);
-              retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ());
-            }
-        }
-      else
-        {
-          gripe_wrong_type_arg (fcn, arg);
-        }
-    }
-
-  return retval;
-}
-
-DEFUN_DLD (fftn, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} fftn (@var{A})\n\
-@deftypefnx {Loadable Function} {} fftn (@var{A}, @var{size})\n\
-Compute the N-dimensional discrete Fourier transform of @var{A} using\n\
-a Fast Fourier Transform (FFT) algorithm.\n\
-\n\
-The optional vector argument @var{size} may be used specify the\n\
-dimensions of the array to be used.  If an element of @var{size} is\n\
-smaller than the corresponding dimension of @var{A}, then the dimension of\n\
-@var{A} is truncated prior to performing the FFT@.  Otherwise, if an element\n\
-of @var{size} is larger than the corresponding dimension then @var{A}\n\
-is resized and padded with zeros.\n\
-@seealso{ifftn, fft, fft2, fftw}\n\
-@end deftypefn")
-{
-  return do_fftn (args, "fftn", 0);
-}
-
-DEFUN_DLD (ifftn, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} ifftn (@var{A})\n\
-@deftypefnx {Loadable Function} {} ifftn (@var{A}, @var{size})\n\
-Compute the inverse N-dimensional discrete Fourier transform of @var{A}\n\
-using a Fast Fourier Transform (FFT) algorithm.\n\
-\n\
-The optional vector argument @var{size} may be used specify the\n\
-dimensions of the array to be used.  If an element of @var{size} is\n\
-smaller than the corresponding dimension of @var{A}, then the dimension of\n\
-@var{A} is truncated prior to performing the inverse FFT@.  Otherwise, if an\n\
-element of @var{size} is larger than the corresponding dimension then @var{A}\n\
-is resized and padded with zeros.\n\
-@seealso{fftn, ifft, ifft2, fftw}\n\
-@end deftypefn")
-{
-  return do_fftn (args, "ifftn", 1);
-}
--- a/src/DLD-FUNCTIONS/filter.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,738 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-// Based on Tony Richardson's filter.m.
-//
-// Originally translated to C++ by KH (Kurt.Hornik@wu-wien.ac.at)
-// with help from Fritz Leisch and Andreas Weingessel on Oct 20, 1994.
-//
-// Rewritten to use templates to handle both real and complex cases by
-// jwe, Wed Nov  1 19:15:29 1995.
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "quit.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "oct-obj.h"
-
-#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL)
-extern MArray<double>
-filter (MArray<double>&, MArray<double>&, MArray<double>&, int dim);
-
-extern MArray<Complex>
-filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, int dim);
-
-extern MArray<float>
-filter (MArray<float>&, MArray<float>&, MArray<float>&, int dim);
-
-extern MArray<FloatComplex>
-filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&, int dim);
-#endif
-
-template <class T>
-MArray<T>
-filter (MArray<T>& b, MArray<T>& a, MArray<T>& x, MArray<T>& si,
-        int dim = 0)
-{
-  MArray<T> y;
-
-  octave_idx_type a_len  = a.length ();
-  octave_idx_type b_len  = b.length ();
-
-  octave_idx_type ab_len = a_len > b_len ? a_len : b_len;
-
-  // FIXME: The two lines below should be unecessary because
-  //        this template is called with a and b as column vectors
-  //        already.  However the a.resize line is currently (2011/04/26)
-  //        necessary to stop bug #33164.
-  b.resize (dim_vector (ab_len, 1), 0.0);
-  if (a_len > 1)
-    a.resize (dim_vector (ab_len, 1), 0.0);
-
-  T norm = a (0);
-
-  if (norm == static_cast<T>(0.0))
-    {
-      error ("filter: the first element of A must be non-zero");
-      return y;
-    }
-
-  dim_vector x_dims = x.dims ();
-  if (dim < 0 || dim > x_dims.length ())
-    {
-      error ("filter: DIM must be a valid dimension");
-      return y;
-    }
-
-  octave_idx_type x_len = x_dims(dim);
-
-  dim_vector si_dims = si.dims ();
-  octave_idx_type si_len = si_dims(0);
-
-  if (si_len != ab_len - 1)
-    {
-      error ("filter: first dimension of SI must be of length max (length (a), length (b)) - 1");
-      return y;
-    }
-
-  if (si_dims.length () != x_dims.length ())
-    {
-      error ("filter: dimensionality of SI and X must agree");
-      return y;
-    }
-
-  for (octave_idx_type i = 1; i < dim; i++)
-    {
-      if (si_dims(i) != x_dims(i-1))
-        {
-          error ("filter: dimensionality of SI and X must agree");
-          return y;
-        }
-    }
-  for (octave_idx_type i = dim+1; i < x_dims.length (); i++)
-    {
-      if (si_dims(i) != x_dims(i))
-        {
-          error ("filter: dimensionality of SI and X must agree");
-          return y;
-        }
-    }
-
-  if (x_len == 0)
-    return x;
-
-  if (norm != static_cast<T>(1.0))
-    {
-      a = a / norm;
-      b = b / norm;
-    }
-
-  if (a_len <= 1 && si_len <= 0)
-    return b(0) * x;
-
-  y.resize (x_dims, 0.0);
-
-  int x_stride = 1;
-  for (int i = 0; i < dim; i++)
-    x_stride *= x_dims(i);
-
-  octave_idx_type x_num = x_dims.numel () / x_len;
-  for (octave_idx_type num = 0; num < x_num; num++)
-    {
-      octave_idx_type x_offset;
-      if (x_stride == 1)
-        x_offset = num * x_len;
-      else
-        {
-          octave_idx_type x_offset2 = 0;
-          x_offset = num;
-          while (x_offset >= x_stride)
-            {
-              x_offset -= x_stride;
-              x_offset2++;
-            }
-          x_offset += x_offset2 * x_stride * x_len;
-        }
-      octave_idx_type si_offset = num * si_len;
-
-      if (a_len > 1)
-        {
-          T *py = y.fortran_vec ();
-          T *psi = si.fortran_vec ();
-
-          const T *pa = a.data ();
-          const T *pb = b.data ();
-          const T *px = x.data ();
-
-          psi += si_offset;
-
-          for (octave_idx_type i = 0, idx = x_offset; i < x_len; i++, idx += x_stride)
-            {
-              py[idx] = psi[0] + pb[0] * px[idx];
-
-              if (si_len > 0)
-                {
-                  for (octave_idx_type j = 0; j < si_len - 1; j++)
-                    {
-                      OCTAVE_QUIT;
-
-                      psi[j] = psi[j+1] - pa[j+1] * py[idx] + pb[j+1] * px[idx];
-                    }
-
-                  psi[si_len-1] = pb[si_len] * px[idx] - pa[si_len] * py[idx];
-                }
-              else
-                {
-                  OCTAVE_QUIT;
-
-                  psi[0] = pb[si_len] * px[idx] - pa[si_len] * py[idx];
-                }
-            }
-        }
-      else if (si_len > 0)
-        {
-          T *py = y.fortran_vec ();
-          T *psi = si.fortran_vec ();
-
-          const T *pb = b.data ();
-          const T *px = x.data ();
-
-          psi += si_offset;
-
-          for (octave_idx_type i = 0, idx = x_offset; i < x_len; i++, idx += x_stride)
-            {
-              py[idx] = psi[0] + pb[0] * px[idx];
-
-              if (si_len > 1)
-                {
-                  for (octave_idx_type j = 0; j < si_len - 1; j++)
-                    {
-                      OCTAVE_QUIT;
-
-                      psi[j] = psi[j+1] + pb[j+1] * px[idx];
-                    }
-
-                  psi[si_len-1] = pb[si_len] * px[idx];
-                }
-              else
-                {
-                  OCTAVE_QUIT;
-
-                  psi[0] = pb[1] * px[idx];
-                }
-            }
-        }
-    }
-
-  return y;
-}
-
-#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL)
-extern MArray<double>
-filter (MArray<double>&, MArray<double>&, MArray<double>&,
-        MArray<double>&, int dim);
-
-extern MArray<Complex>
-filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&,
-        MArray<Complex>&, int dim);
-
-extern MArray<float>
-filter (MArray<float>&, MArray<float>&, MArray<float>&,
-        MArray<float>&, int dim);
-
-extern MArray<FloatComplex>
-filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&,
-        MArray<FloatComplex>&, int dim);
-#endif
-
-template <class T>
-MArray<T>
-filter (MArray<T>& b, MArray<T>& a, MArray<T>& x, int dim = -1)
-{
-  dim_vector x_dims = x.dims ();
-
-  if (dim < 0)
-    {
-      // Find first non-singleton dimension
-      while (dim < x_dims.length () && x_dims(dim) <= 1)
-        dim++;
-
-      // All dimensions singleton, pick first dimension
-      if (dim == x_dims.length ())
-        dim = 0;
-    }
-  else
-    if (dim < 0 || dim > x_dims.length ())
-      {
-        error ("filter: DIM must be a valid dimension");
-        return MArray<T> ();
-      }
-
-  octave_idx_type a_len = a.length ();
-  octave_idx_type b_len = b.length ();
-
-  octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
-  dim_vector si_dims = x.dims ();
-  for (int i = dim; i > 0; i--)
-    si_dims(i) = si_dims(i-1);
-  si_dims(0) = si_len;
-
-  MArray<T> si (si_dims, T (0.0));
-
-  return filter (b, a, x, si, dim);
-}
-
-DEFUN_DLD (filter, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {y =} filter (@var{b}, @var{a}, @var{x})\n\
-@deftypefnx {Loadable Function} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, @var{si})\n\
-@deftypefnx {Loadable Function} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, [], @var{dim})\n\
-@deftypefnx {Loadable Function} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, @var{si}, @var{dim})\n\
-Return the solution to the following linear, time-invariant difference\n\
-equation:\n\
-@tex\n\
-$$\n\
-\\sum_{k=0}^N a_{k+1} y_{n-k} = \\sum_{k=0}^M b_{k+1} x_{n-k}, \\qquad\n\
- 1 \\le n \\le P\n\
-$$\n\
-@end tex\n\
-@ifnottex\n\
-@c Set example in small font to prevent overfull line\n\
-\n\
-@smallexample\n\
-@group\n\
- N                   M\n\
-SUM a(k+1) y(n-k) = SUM b(k+1) x(n-k)    for 1<=n<=length(x)\n\
-k=0                 k=0\n\
-@end group\n\
-@end smallexample\n\
-\n\
-@end ifnottex\n\
-\n\
-@noindent\n\
-where\n\
-@ifnottex\n\
-N=length(a)-1 and M=length(b)-1.\n\
-@end ifnottex\n\
-@tex\n\
-$a \\in \\Re^{N-1}$, $b \\in \\Re^{M-1}$, and $x \\in \\Re^P$.\n\
-@end tex\n\
-The result is calculated over the first non-singleton dimension of @var{x}\n\
-or over @var{dim} if supplied.\n\
-\n\
-An equivalent form of the equation is:\n\
-@tex\n\
-$$\n\
-y_n = -\\sum_{k=1}^N c_{k+1} y_{n-k} + \\sum_{k=0}^M d_{k+1} x_{n-k}, \\qquad\n\
- 1 \\le n \\le P\n\
-$$\n\
-@end tex\n\
-@ifnottex\n\
-@c Set example in small font to prevent overfull line\n\
-\n\
-@smallexample\n\
-@group\n\
-          N                   M\n\
-y(n) = - SUM c(k+1) y(n-k) + SUM d(k+1) x(n-k)  for 1<=n<=length(x)\n\
-         k=1                 k=0\n\
-@end group\n\
-@end smallexample\n\
-\n\
-@end ifnottex\n\
-\n\
-@noindent\n\
-where\n\
-@ifnottex\n\
- c = a/a(1) and d = b/a(1).\n\
-@end ifnottex\n\
-@tex\n\
-$c = a/a_1$ and $d = b/a_1$.\n\
-@end tex\n\
-\n\
-If the fourth argument @var{si} is provided, it is taken as the\n\
-initial state of the system and the final state is returned as\n\
-@var{sf}.  The state vector is a column vector whose length is\n\
-equal to the length of the longest coefficient vector minus one.\n\
-If @var{si} is not supplied, the initial state vector is set to all\n\
-zeros.\n\
-\n\
-In terms of the Z Transform, y is the result of passing the discrete-\n\
-time signal x through a system characterized by the following rational\n\
-system function:\n\
-@tex\n\
-$$\n\
-H(z) = {\\displaystyle\\sum_{k=0}^M d_{k+1} z^{-k}\n\
-        \\over 1 + \\displaystyle\\sum_{k+1}^N c_{k+1} z^{-k}}\n\
-$$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-@group\n\
-          M\n\
-         SUM d(k+1) z^(-k)\n\
-         k=0\n\
-H(z) = ---------------------\n\
-            N\n\
-       1 + SUM c(k+1) z^(-k)\n\
-           k=1\n\
-@end group\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-@seealso{filter2, fftfilt, freqz}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin  = args.length ();
-
-  if (nargin < 3 || nargin > 5)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  const char *errmsg = "filter: arguments a and b must be vectors";
-
-  int dim;
-  dim_vector x_dims = args(2).dims ();
-
-  if (nargin == 5)
-    {
-      dim = args(4).nint_value () - 1;
-      if (dim < 0 || dim >= x_dims.length ())
-        {
-          error ("filter: DIM must be a valid dimension");
-          return retval;
-        }
-    }
-  else
-    {
-      // Find first non-singleton dimension
-      dim = 0;
-      while (dim < x_dims.length () && x_dims(dim) <= 1)
-        dim++;
-
-      // All dimensions singleton, pick first dimension
-      if (dim == x_dims.length ())
-        dim = 0;
-    }
-
-  bool isfloat = (args(0).is_single_type ()
-                  || args(1).is_single_type ()
-                  || args(2).is_single_type ()
-                  || (nargin >= 4 && args(3).is_single_type ()));
-
-  if (args(0).is_complex_type ()
-      || args(1).is_complex_type ()
-      || args(2).is_complex_type ()
-      || (nargin >= 4 && args(3).is_complex_type ()))
-    {
-      if (isfloat)
-        {
-          FloatComplexColumnVector b (args(0).float_complex_vector_value ());
-          FloatComplexColumnVector a (args(1).float_complex_vector_value ());
-
-          FloatComplexNDArray x (args(2).float_complex_array_value ());
-
-          if (! error_state)
-            {
-              FloatComplexNDArray si;
-
-              if (nargin == 3 || args(3).is_empty ())
-                {
-                  octave_idx_type a_len = a.length ();
-                  octave_idx_type b_len = b.length ();
-
-                  octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
-
-                  dim_vector si_dims = x.dims ();
-                  for (int i = dim; i > 0; i--)
-                    si_dims(i) = si_dims(i-1);
-                  si_dims(0) = si_len;
-
-                  si.resize (si_dims, 0.0);
-                }
-              else
-                {
-                  si = args(3).float_complex_array_value ();
-
-                  if (si.is_vector () && x.is_vector ())
-                    si = si.reshape (dim_vector (si.numel (), 1));
-                }
-
-              if (! error_state)
-                {
-                  FloatComplexNDArray y (filter (b, a, x, si, dim));
-
-                  if (nargout == 2)
-                    retval(1) = si;
-
-                  retval(0) = y;
-                }
-              else
-                error (errmsg);
-            }
-          else
-            error (errmsg);
-        }
-      else
-        {
-          ComplexColumnVector b (args(0).complex_vector_value ());
-          ComplexColumnVector a (args(1).complex_vector_value ());
-
-          ComplexNDArray x (args(2).complex_array_value ());
-
-          if (! error_state)
-            {
-              ComplexNDArray si;
-
-              if (nargin == 3 || args(3).is_empty ())
-                {
-                  octave_idx_type a_len = a.length ();
-                  octave_idx_type b_len = b.length ();
-
-                  octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
-
-                  dim_vector si_dims = x.dims ();
-                  for (int i = dim; i > 0; i--)
-                    si_dims(i) = si_dims(i-1);
-                  si_dims(0) = si_len;
-
-                  si.resize (si_dims, 0.0);
-                }
-              else
-                {
-                  si = args(3).complex_array_value ();
-
-                  if (si.is_vector () && x.is_vector ())
-                    si = si.reshape (dim_vector (si.numel (), 1));
-                }
-
-              if (! error_state)
-                {
-                  ComplexNDArray y (filter (b, a, x, si, dim));
-
-                  if (nargout == 2)
-                    retval(1) = si;
-
-                  retval(0) = y;
-                }
-              else
-                error (errmsg);
-            }
-          else
-            error (errmsg);
-        }
-    }
-  else
-    {
-      if (isfloat)
-        {
-          FloatColumnVector b (args(0).float_vector_value ());
-          FloatColumnVector a (args(1).float_vector_value ());
-
-          FloatNDArray x (args(2).float_array_value ());
-
-          if (! error_state)
-            {
-              FloatNDArray si;
-
-              if (nargin == 3 || args(3).is_empty ())
-                {
-                  octave_idx_type a_len = a.length ();
-                  octave_idx_type b_len = b.length ();
-
-                  octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
-
-                  dim_vector si_dims = x.dims ();
-                  for (int i = dim; i > 0; i--)
-                    si_dims(i) = si_dims(i-1);
-                  si_dims(0) = si_len;
-
-                  si.resize (si_dims, 0.0);
-                }
-              else
-                {
-                  si = args(3).float_array_value ();
-
-                  if (si.is_vector () && x.is_vector ())
-                    si = si.reshape (dim_vector (si.numel (), 1));
-                }
-
-              if (! error_state)
-                {
-                  FloatNDArray y (filter (b, a, x, si, dim));
-
-                  if (nargout == 2)
-                    retval(1) = si;
-
-                  retval(0) = y;
-                }
-              else
-                error (errmsg);
-            }
-          else
-            error (errmsg);
-        }
-      else
-        {
-          ColumnVector b (args(0).vector_value ());
-          ColumnVector a (args(1).vector_value ());
-
-          NDArray x (args(2).array_value ());
-
-          if (! error_state)
-            {
-              NDArray si;
-
-              if (nargin == 3 || args(3).is_empty ())
-                {
-                  octave_idx_type a_len = a.length ();
-                  octave_idx_type b_len = b.length ();
-
-                  octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
-
-                  dim_vector si_dims = x.dims ();
-                  for (int i = dim; i > 0; i--)
-                    si_dims(i) = si_dims(i-1);
-                  si_dims(0) = si_len;
-
-                  si.resize (si_dims, 0.0);
-                }
-              else
-                {
-                  si = args(3).array_value ();
-
-                  if (si.is_vector () && x.is_vector ())
-                    si = si.reshape (dim_vector (si.numel (), 1));
-                }
-
-              if (! error_state)
-                {
-                  NDArray y (filter (b, a, x, si, dim));
-
-                  if (nargout == 2)
-                    retval(1) = si;
-
-                  retval(0) = y;
-                }
-              else
-                error (errmsg);
-            }
-          else
-            error (errmsg);
-        }
-    }
-
-  return retval;
-}
-
-template MArray<double>
-filter (MArray<double>&, MArray<double>&, MArray<double>&,
-        MArray<double>&, int dim);
-
-template MArray<double>
-filter (MArray<double>&, MArray<double>&, MArray<double>&, int dim);
-
-template MArray<Complex>
-filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&,
-        MArray<Complex>&, int dim);
-
-template MArray<Complex>
-filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, int dim);
-
-template MArray<float>
-filter (MArray<float>&, MArray<float>&, MArray<float>&,
-        MArray<float>&, int dim);
-
-template MArray<float>
-filter (MArray<float>&, MArray<float>&, MArray<float>&, int dim);
-
-template MArray<FloatComplex>
-filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&,
-        MArray<FloatComplex>&, int dim);
-
-template MArray<FloatComplex>
-filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&, int dim);
-
-/*
-%!shared a, b, x, r
-%!test
-%! a = [1 1];
-%! b = [1 1];
-%! x = zeros (1,10);  x(1) = 1;
-%! assert (filter (b,   [1], x  ), [1 1 0 0 0 0 0 0 0 0]);
-%! assert (filter (b,   [1], x.'), [1 1 0 0 0 0 0 0 0 0].');
-%! assert (filter (b.', [1], x  ), [1 1 0 0 0 0 0 0 0 0]  );
-%! assert (filter (b.', [1], x.'), [1 1 0 0 0 0 0 0 0 0].');
-%! assert (filter ([1], a,   x  ), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1]  );
-%! assert (filter ([1], a,   x.'), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1].');
-%! assert (filter ([1], a.', x  ), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1]  );
-%! assert (filter ([1], a.', x.'), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1].');
-%! assert (filter (b,   a,   x  ), [1 0 0 0 0 0 0 0 0 0]  );
-%! assert (filter (b.', a,   x  ), [1 0 0 0 0 0 0 0 0 0]  );
-%! assert (filter (b,   a.', x  ), [1 0 0 0 0 0 0 0 0 0]  );
-%! assert (filter (b.', a,   x  ), [1 0 0 0 0 0 0 0 0 0]  );
-%! assert (filter (b,   a,   x.'), [1 0 0 0 0 0 0 0 0 0].');
-%! assert (filter (b.', a,   x.'), [1 0 0 0 0 0 0 0 0 0].');
-%! assert (filter (b,   a.', x.'), [1 0 0 0 0 0 0 0 0 0].');
-%! assert (filter (b.', a,   x.'), [1 0 0 0 0 0 0 0 0 0].');
-
-%!test
-%! r = sqrt (1/2) * (1+i);
-%! a = a*r;
-%! b = b*r;
-%! assert (filter (b, [1], x   ), r*[1 1 0 0 0 0 0 0 0 0]   );
-%! assert (filter (b, [1], r*x ), r*r*[1 1 0 0 0 0 0 0 0 0] );
-%! assert (filter (b, [1], x.' ), r*[1 1 0 0 0 0 0 0 0 0].' );
-%! assert (filter (b, a,   x   ),   [1 0 0 0 0 0 0 0 0 0]   );
-%! assert (filter (b, a,   r*x ), r*[1 0 0 0 0 0 0 0 0 0]   );
-
-%!shared a, b, x, y, so
-%!test
-%! a = [1,1];
-%! b = [1,1];
-%! x = zeros (1,10);  x(1) = 1;
-%! [y, so] = filter (b, [1], x, [-1]);
-%! assert (y, [0 1 0 0 0 0 0 0 0 0]);
-%! assert (so, 0);
-
-%!test
-%! x  = zeros (10,3);  x(1,1) = -1;  x(1,2) = 1;
-%! y0 = zeros (10,3); y0(1:2,1) = -1;  y0(1:2,2) = 1;
-%! y = filter (b, [1], x);
-%! assert (y, y0);
-
-%!test
-%! a = [1,1];
-%! b=[1,1];
-%! x = zeros (4,4,2);  x(1,1:4,1) = +1;  x(1,1:4,2) = -1;
-%! y0 = zeros (4,4,2);  y0(1:2,1:4,1) = +1;  y0(1:2,1:4,2) = -1;
-%! y = filter (b, [1], x);
-%! assert (y, y0);
-
-%!assert (filter (1, ones (10,1) / 10, []), [])
-%!assert (filter (1, ones (10,1) / 10, zeros (0,10)), zeros (0,10))
-%!assert (filter (1, ones (10,1) / 10, single (1:5)), repmat (single (10), 1, 5))
-
-%% Test using initial conditions
-%!assert (filter ([1, 1, 1], [1, 1], [1 2], [1, 1]), [2 2])
-%!assert (filter ([1, 1, 1], [1, 1], [1 2], [1, 1]'), [2 2])
-%!assert (filter ([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]), [5 7; 6 10; 14 18])
-%!error (filter ([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]'))
-%!assert (filter ([1, 3, 2], [1], [1 2; 3 4; 5 6], [1 0 0; 1 0 0], 2), [2 6; 3 13; 5 21])
-
-## Test of DIM parameter
-%!test
-%! x = ones (2, 1, 3, 4);
-%! x(1,1,:,:) = [1 2 3 4; 5 6 7 8; 9 10 11 12];
-%! y0 = [1 1 6 2 15 3 2 1 8 2 18 3 3 1 10 2 21 3 4 1 12 2 24 3];
-%! y0 = reshape (y0, size (x));
-%! y = filter ([1 1 1], 1, x, [], 3);
-%! assert (y, y0);
-*/
--- a/src/DLD-FUNCTIONS/find.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,621 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "quit.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-
-// Find at most N_TO_FIND nonzero elements in NDA.  Search forward if
-// DIRECTION is 1, backward if it is -1.  NARGOUT is the number of
-// output arguments.  If N_TO_FIND is -1, find all nonzero elements.
-
-template <typename T>
-octave_value_list
-find_nonzero_elem_idx (const Array<T>& nda, int nargout,
-                       octave_idx_type n_to_find, int direction)
-{
-  octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ());
-
-  Array<octave_idx_type> idx;
-  if (n_to_find >= 0)
-    idx = nda.find (n_to_find, direction == -1);
-  else
-    idx = nda.find ();
-
-  // The maximum element is always at the end.
-  octave_idx_type iext = idx.is_empty () ? 0 : idx.xelem (idx.numel () - 1) + 1;
-
-  switch (nargout)
-    {
-    default:
-    case 3:
-      retval(2) = Array<T> (nda.index (idx_vector (idx)));
-      // Fall through!
-
-    case 2:
-      {
-        Array<octave_idx_type> jdx (idx.dims ());
-        octave_idx_type n = idx.length (), nr = nda.rows ();
-        for (octave_idx_type i = 0; i < n; i++)
-          {
-            jdx.xelem (i) = idx.xelem (i) / nr;
-            idx.xelem (i) %= nr;
-          }
-        iext = -1;
-        retval(1) = idx_vector (jdx, -1);
-      }
-      // Fall through!
-
-    case 1:
-    case 0:
-      retval(0) = idx_vector (idx, iext);
-      break;
-    }
-
-  return retval;
-}
-
-template <typename T>
-octave_value_list
-find_nonzero_elem_idx (const Sparse<T>& v, int nargout,
-                       octave_idx_type n_to_find, int direction)
-{
-  octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ());
-
-
-  octave_idx_type nc = v.cols ();
-  octave_idx_type nr = v.rows ();
-  octave_idx_type nz = v.nnz ();
-
-  // Search in the default range.
-  octave_idx_type start_nc = -1;
-  octave_idx_type end_nc = -1;
-  octave_idx_type count;
-
-  // Search for the range to search
-  if (n_to_find < 0)
-    {
-      start_nc = 0;
-      end_nc = nc;
-      n_to_find = nz;
-      count = nz;
-    }
-  else if (direction > 0)
-    {
-      for (octave_idx_type j = 0; j < nc; j++)
-        {
-          OCTAVE_QUIT;
-          if (v.cidx (j) == 0 && v.cidx (j+1) != 0)
-            start_nc = j;
-          if (v.cidx (j+1) >= n_to_find)
-            {
-              end_nc = j + 1;
-              break;
-            }
-        }
-    }
-  else
-    {
-      for (octave_idx_type j = nc; j > 0; j--)
-        {
-          OCTAVE_QUIT;
-          if (v.cidx (j) == nz && v.cidx (j-1) != nz)
-            end_nc = j;
-          if (nz - v.cidx (j-1) >= n_to_find)
-            {
-              start_nc = j - 1;
-              break;
-            }
-        }
-    }
-
-  count = (n_to_find > v.cidx (end_nc) - v.cidx (start_nc) ?
-           v.cidx (end_nc) - v.cidx (start_nc) : n_to_find);
-
-  // If the original argument was a row vector, force a row vector of
-  // the overall indices to be returned.  But see below for scalar
-  // case...
-
-  octave_idx_type result_nr = count;
-  octave_idx_type result_nc = 1;
-
-  bool scalar_arg = false;
-
-  if (v.rows () == 1)
-    {
-      result_nr = 1;
-      result_nc = count;
-
-      scalar_arg = (v.columns () == 1);
-    }
-
-  Matrix idx (result_nr, result_nc);
-
-  Matrix i_idx (result_nr, result_nc);
-  Matrix j_idx (result_nr, result_nc);
-
-  Array<T> val (dim_vector (result_nr, result_nc));
-
-  if (count > 0)
-    {
-      // Search for elements to return.  Only search the region where
-      // there are elements to be found using the count that we want
-      // to find.
-      for (octave_idx_type j = start_nc, cx = 0; j < end_nc; j++)
-        for (octave_idx_type i = v.cidx (j); i < v.cidx (j+1); i++ )
-          {
-            OCTAVE_QUIT;
-            if (direction < 0 && i < nz - count)
-              continue;
-            i_idx(cx) = static_cast<double> (v.ridx (i) + 1);
-            j_idx(cx) = static_cast<double> (j + 1);
-            idx(cx) = j * nr + v.ridx (i) + 1;
-            val(cx) = v.data(i);
-            cx++;
-            if (cx == count)
-              break;
-          }
-    }
-  else if (scalar_arg)
-    {
-      idx.resize (0, 0);
-
-      i_idx.resize (0, 0);
-      j_idx.resize (0, 0);
-
-      val.resize (dim_vector (0, 0));
-    }
-
-  switch (nargout)
-    {
-    case 0:
-    case 1:
-      retval(0) = idx;
-      break;
-
-    case 5:
-      retval(4) = nc;
-      // Fall through
-
-    case 4:
-      retval(3) = nr;
-      // Fall through
-
-    case 3:
-      retval(2) = val;
-      // Fall through!
-
-    case 2:
-      retval(1) = j_idx;
-      retval(0) = i_idx;
-      break;
-
-    default:
-      panic_impossible ();
-      break;
-    }
-
-  return retval;
-}
-
-octave_value_list
-find_nonzero_elem_idx (const PermMatrix& v, int nargout,
-                       octave_idx_type n_to_find, int direction)
-{
-  // There are far fewer special cases to handle for a PermMatrix.
-  octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ());
-
-  octave_idx_type nc = v.cols ();
-  octave_idx_type start_nc, count;
-
-  // Determine the range to search.
-  if (n_to_find < 0 || n_to_find >= nc)
-    {
-      start_nc = 0;
-      n_to_find = nc;
-      count = nc;
-    }
-  else if (direction > 0)
-    {
-      start_nc = 0;
-      count = n_to_find;
-    }
-  else
-    {
-      start_nc = nc - n_to_find;
-      count = n_to_find;
-    }
-
-  bool scalar_arg = (v.rows () == 1 && v.cols () == 1);
-
-  Matrix idx (count, 1);
-  Matrix i_idx (count, 1);
-  Matrix j_idx (count, 1);
-  // Every value is 1.
-  Array<double> val (dim_vector (count, 1), 1.0);
-
-  if (count > 0)
-    {
-      const octave_idx_type* p = v.data ();
-      if (v.is_col_perm ())
-        {
-          for (octave_idx_type k = 0; k < count; k++)
-            {
-              OCTAVE_QUIT;
-              const octave_idx_type j = start_nc + k;
-              const octave_idx_type i = p[j];
-              i_idx(k) = static_cast<double> (1+i);
-              j_idx(k) = static_cast<double> (1+j);
-              idx(k) = j * nc + i + 1;
-            }
-        }
-      else
-        {
-          for (octave_idx_type k = 0; k < count; k++)
-            {
-              OCTAVE_QUIT;
-              const octave_idx_type i = start_nc + k;
-              const octave_idx_type j = p[i];
-              // Scatter into the index arrays according to
-              // j adjusted by the start point.
-              const octave_idx_type koff = j - start_nc;
-              i_idx(koff) = static_cast<double> (1+i);
-              j_idx(koff) = static_cast<double> (1+j);
-              idx(koff) = j * nc + i + 1;
-            }
-        }
-    }
-  else if (scalar_arg)
-    {
-      // Same odd compatibility case as the other overrides.
-      idx.resize (0, 0);
-      i_idx.resize (0, 0);
-      j_idx.resize (0, 0);
-      val.resize (dim_vector (0, 0));
-    }
-
-  switch (nargout)
-    {
-    case 0:
-    case 1:
-      retval(0) = idx;
-      break;
-
-    case 5:
-      retval(4) = nc;
-      // Fall through
-
-    case 4:
-      retval(3) = nc;
-      // Fall through
-
-    case 3:
-      retval(2) = val;
-      // Fall through!
-
-    case 2:
-      retval(1) = j_idx;
-      retval(0) = i_idx;
-      break;
-
-    default:
-      panic_impossible ();
-      break;
-    }
-
-  return retval;
-}
-
-DEFUN_DLD (find, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{idx} =} find (@var{x})\n\
-@deftypefnx {Loadable Function} {@var{idx} =} find (@var{x}, @var{n})\n\
-@deftypefnx {Loadable Function} {@var{idx} =} find (@var{x}, @var{n}, @var{direction})\n\
-@deftypefnx {Loadable Function} {[i, j] =} find (@dots{})\n\
-@deftypefnx {Loadable Function} {[i, j, v] =} find (@dots{})\n\
-Return a vector of indices of nonzero elements of a matrix, as a row if\n\
-@var{x} is a row vector or as a column otherwise.  To obtain a single index\n\
-for each matrix element, Octave pretends that the columns of a matrix form\n\
-one long vector (like Fortran arrays are stored).  For example:\n\
-\n\
-@example\n\
-@group\n\
-find (eye (2))\n\
-  @result{} [ 1; 4 ]\n\
-@end group\n\
-@end example\n\
-\n\
-If two outputs are requested, @code{find} returns the row and column\n\
-indices of nonzero elements of a matrix.  For example:\n\
-\n\
-@example\n\
-@group\n\
-[i, j] = find (2 * eye (2))\n\
-    @result{} i = [ 1; 2 ]\n\
-    @result{} j = [ 1; 2 ]\n\
-@end group\n\
-@end example\n\
-\n\
-If three outputs are requested, @code{find} also returns a vector\n\
-containing the nonzero values.  For example:\n\
-\n\
-@example\n\
-@group\n\
-[i, j, v] = find (3 * eye (2))\n\
-       @result{} i = [ 1; 2 ]\n\
-       @result{} j = [ 1; 2 ]\n\
-       @result{} v = [ 3; 3 ]\n\
-@end group\n\
-@end example\n\
-\n\
-If two inputs are given, @var{n} indicates the maximum number of\n\
-elements to find from the beginning of the matrix or vector.\n\
-\n\
-If three inputs are given, @var{direction} should be one of \"first\" or\n\
-\"last\", requesting only the first or last @var{n} indices, respectively.\n\
-However, the indices are always returned in ascending order.\n\
-\n\
-Note that this function is particularly useful for sparse matrices, as\n\
-it extracts the non-zero elements as vectors, which can then be used to\n\
-create the original matrix.  For example:\n\
-\n\
-@example\n\
-@group\n\
-sz = size (a);\n\
-[i, j, v] = find (a);\n\
-b = sparse (i, j, v, sz(1), sz(2));\n\
-@end group\n\
-@end example\n\
-@seealso{nonzeros}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin > 3 || nargin < 1)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  // Setup the default options.
-  octave_idx_type n_to_find = -1;
-  if (nargin > 1)
-    {
-      double val = args(1).scalar_value ();
-
-      if (error_state || (val < 0 || (! xisinf (val) && val != xround (val))))
-        {
-          error ("find: N must be a non-negative integer");
-          return retval;
-        }
-      else if (! xisinf (val))
-        n_to_find = val;
-    }
-
-  // Direction to do the searching (1 == forward, -1 == reverse).
-  int direction = 1;
-  if (nargin > 2)
-    {
-      direction = 0;
-
-      std::string s_arg = args(2).string_value ();
-
-      if (! error_state)
-        {
-          if (s_arg == "first")
-            direction = 1;
-          else if (s_arg == "last")
-            direction = -1;
-        }
-
-      if (direction == 0)
-        {
-          error ("find: DIRECTION must be \"first\" or \"last\"");
-          return retval;
-        }
-    }
-
-  octave_value arg = args(0);
-
-  if (arg.is_bool_type ())
-    {
-      if (arg.is_sparse_type ())
-        {
-          SparseBoolMatrix v = arg.sparse_bool_matrix_value ();
-
-          if (! error_state)
-            retval = find_nonzero_elem_idx (v, nargout,
-                                            n_to_find, direction);
-        }
-      else if (nargout <= 1 && n_to_find == -1 && direction == 1)
-        {
-          // This case is equivalent to extracting indices from a logical
-          // matrix. Try to reuse the possibly cached index vector.
-          retval(0) = arg.index_vector ().unmask ();
-        }
-      else
-        {
-          boolNDArray v = arg.bool_array_value ();
-
-          if (! error_state)
-            retval = find_nonzero_elem_idx (v, nargout,
-                                            n_to_find, direction);
-        }
-    }
-  else if (arg.is_integer_type ())
-    {
-#define DO_INT_BRANCH(INTT) \
-      else if (arg.is_ ## INTT ## _type ()) \
-        { \
-          INTT ## NDArray v = arg.INTT ## _array_value (); \
-          \
-          if (! error_state) \
-            retval = find_nonzero_elem_idx (v, nargout, \
-                                            n_to_find, direction);\
-        }
-
-      if (false)
-        ;
-      DO_INT_BRANCH (int8)
-      DO_INT_BRANCH (int16)
-      DO_INT_BRANCH (int32)
-      DO_INT_BRANCH (int64)
-      DO_INT_BRANCH (uint8)
-      DO_INT_BRANCH (uint16)
-      DO_INT_BRANCH (uint32)
-      DO_INT_BRANCH (uint64)
-      else
-        panic_impossible ();
-    }
-  else if (arg.is_sparse_type ())
-    {
-      if (arg.is_real_type ())
-        {
-          SparseMatrix v = arg.sparse_matrix_value ();
-
-          if (! error_state)
-            retval = find_nonzero_elem_idx (v, nargout,
-                                            n_to_find, direction);
-        }
-      else if (arg.is_complex_type ())
-        {
-          SparseComplexMatrix v = arg.sparse_complex_matrix_value ();
-
-          if (! error_state)
-            retval = find_nonzero_elem_idx (v, nargout,
-                                            n_to_find, direction);
-        }
-      else
-        gripe_wrong_type_arg ("find", arg);
-    }
-  else if (arg.is_perm_matrix ())
-    {
-      PermMatrix P = arg.perm_matrix_value ();
-
-      if (! error_state)
-        retval = find_nonzero_elem_idx (P, nargout, n_to_find, direction);
-    }
-  else if (arg.is_string ())
-    {
-      charNDArray chnda = arg.char_array_value ();
-
-      if (! error_state)
-        retval = find_nonzero_elem_idx (chnda, nargout, n_to_find, direction);
-    }
-  else if (arg.is_single_type ())
-    {
-      if (arg.is_real_type ())
-        {
-          FloatNDArray nda = arg.float_array_value ();
-
-          if (! error_state)
-            retval = find_nonzero_elem_idx (nda, nargout, n_to_find,
-                                            direction);
-        }
-      else if (arg.is_complex_type ())
-        {
-          FloatComplexNDArray cnda = arg.float_complex_array_value ();
-
-          if (! error_state)
-            retval = find_nonzero_elem_idx (cnda, nargout, n_to_find,
-                                            direction);
-        }
-    }
-  else if (arg.is_real_type ())
-    {
-      NDArray nda = arg.array_value ();
-
-      if (! error_state)
-        retval = find_nonzero_elem_idx (nda, nargout, n_to_find, direction);
-    }
-  else if (arg.is_complex_type ())
-    {
-      ComplexNDArray cnda = arg.complex_array_value ();
-
-      if (! error_state)
-        retval = find_nonzero_elem_idx (cnda, nargout, n_to_find, direction);
-    }
-  else
-    gripe_wrong_type_arg ("find", arg);
-
-  return retval;
-}
-
-/*
-%!assert (find (char ([0, 97])), 2)
-%!assert (find ([1, 0, 1, 0, 1]), [1, 3, 5])
-%!assert (find ([1; 0; 3; 0; 1]), [1; 3; 5])
-%!assert (find ([0, 0, 2; 0, 3, 0; -1, 0, 0]), [3; 5; 7])
-
-%!test
-%! [i, j, v] = find ([0, 0, 2; 0, 3, 0; -1, 0, 0]);
-%!
-%! assert (i, [3; 2; 1]);
-%! assert (j, [1; 2; 3]);
-%! assert (v, [-1; 3; 2]);
-
-%!assert (find (single ([1, 0, 1, 0, 1])), [1, 3, 5])
-%!assert (find (single ([1; 0; 3; 0; 1])), [1; 3; 5])
-%!assert (find (single ([0, 0, 2; 0, 3, 0; -1, 0, 0])), [3; 5; 7])
-
-%!test
-%! [i, j, v] = find (single ([0, 0, 2; 0, 3, 0; -1, 0, 0]));
-%!
-%! assert (i, [3; 2; 1]);
-%! assert (j, [1; 2; 3]);
-%! assert (v, single ([-1; 3; 2]));
-
-%!test
-%! pcol = [5 1 4 3 2];
-%! P = eye (5) (:, pcol);
-%! [i, j, v] = find (P);
-%! [ifull, jfull, vfull] = find (full (P));
-%! assert (i, ifull);
-%! assert (j, jfull);
-%! assert (all (v == 1));
-
-%!test
-%! prow = [5 1 4 3 2];
-%! P = eye (5) (prow, :);
-%! [i, j, v] = find (P);
-%! [ifull, jfull, vfull] = find (full (P));
-%! assert (i, ifull);
-%! assert (j, jfull);
-%! assert (all (v == 1));
-
-%!assert (find ([2 0 1 0 5 0], 1), 1)
-%!assert (find ([2 0 1 0 5 0], 2, "last"), [3, 5])
-
-%!assert (find ([2 0 1 0 5 0], Inf), [1, 3, 5])
-%!assert (find ([2 0 1 0 5 0], Inf, "last"), [1, 3, 5])
-
-%!error find ()
-*/
--- a/src/DLD-FUNCTIONS/gammainc.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,230 +0,0 @@
-/*
-
-Copyright (C) 1997-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "lo-specfun.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-DEFUN_DLD (gammainc, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Mapping Function} {} gammainc (@var{x}, @var{a})\n\
-@deftypefnx {Mapping Function} {} gammainc (@var{x}, @var{a}, \"lower\")\n\
-@deftypefnx {Mapping Function} {} gammainc (@var{x}, @var{a}, \"upper\")\n\
-Compute the normalized incomplete gamma function,\n\
-@tex\n\
-$$\n\
- \\gamma (x, a) = {1 \\over {\\Gamma (a)}}\\displaystyle{\\int_0^x t^{a-1} e^{-t} dt}\n\
-$$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-@group\n\
-                                x\n\
-                       1       /\n\
-gammainc (x, a) = ---------    | exp (-t) t^(a-1) dt\n\
-                  gamma (a)    /\n\
-                            t=0\n\
-@end group\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-with the limiting value of 1 as @var{x} approaches infinity.\n\
-The standard notation is @math{P(a,x)}, e.g., Abramowitz and Stegun (6.5.1).\n\
-\n\
-If @var{a} is scalar, then @code{gammainc (@var{x}, @var{a})} is returned\n\
-for each element of @var{x} and vice versa.\n\
-\n\
-If neither @var{x} nor @var{a} is scalar, the sizes of @var{x} and\n\
-@var{a} must agree, and @code{gammainc} is applied element-by-element.\n\
-\n\
-By default the incomplete gamma function integrated from 0 to @var{x} is\n\
-computed.  If \"upper\" is given then the complementary function integrated\n\
-from @var{x} to infinity is calculated.  It should be noted that\n\
-\n\
-@example\n\
-gammainc (@var{x}, @var{a}) @equiv{} 1 - gammainc (@var{x}, @var{a}, \"upper\")\n\
-@end example\n\
-@seealso{gamma, lgamma}\n\
-@end deftypefn")
-{
-  octave_value retval;
-  bool lower = true;
-
-  int nargin = args.length ();
-
-  if (nargin == 3)
-    {
-      if (args(2).is_string ())
-        {
-          std::string s = args(2).string_value ();
-          std::transform (s.begin (), s.end (), s.begin (), tolower);
-          if (s == "upper")
-            lower = false;
-          else if (s != "lower")
-            error ("gammainc: third argument must be \"lower\" or \"upper\"");
-        }
-      else
-        error ("gammainc: third argument must be \"lower\" or \"upper\"");
-
-    }
-
-  if (!error_state && nargin >= 2  && nargin <= 3)
-    {
-      octave_value x_arg = args(0);
-      octave_value a_arg = args(1);
-
-      // FIXME Can we make a template version of the duplicated code below
-      if (x_arg.is_single_type () || a_arg.is_single_type ())
-        {
-          if (x_arg.is_scalar_type ())
-            {
-              float x = x_arg.float_value ();
-
-              if (! error_state)
-                {
-                  if (a_arg.is_scalar_type ())
-                    {
-                      float a = a_arg.float_value ();
-
-                      if (! error_state)
-                        retval = lower ? gammainc (x, a)
-                          : static_cast<float>(1) - gammainc (x, a);
-                    }
-                  else
-                    {
-                      FloatNDArray a = a_arg.float_array_value ();
-
-                      if (! error_state)
-                        retval = lower ? gammainc (x, a)
-                          : static_cast<float>(1) - gammainc (x, a);
-                    }
-                }
-            }
-          else
-            {
-              FloatNDArray x = x_arg.float_array_value ();
-
-              if (! error_state)
-                {
-                  if (a_arg.is_scalar_type ())
-                    {
-                      float a = a_arg.float_value ();
-
-                      if (! error_state)
-                        retval = lower ? gammainc (x, a)
-                          : static_cast<float>(1) - gammainc (x, a);
-                    }
-                  else
-                    {
-                      FloatNDArray a = a_arg.float_array_value ();
-
-                      if (! error_state)
-                        retval = lower ? gammainc (x, a)
-                          : static_cast<float>(1) - gammainc (x, a);
-                    }
-                }
-            }
-        }
-      else
-        {
-          if (x_arg.is_scalar_type ())
-            {
-              double x = x_arg.double_value ();
-
-              if (! error_state)
-                {
-                  if (a_arg.is_scalar_type ())
-                    {
-                      double a = a_arg.double_value ();
-
-                      if (! error_state)
-                        retval = lower ? gammainc (x, a) : 1. - gammainc (x, a);
-                    }
-                  else
-                    {
-                      NDArray a = a_arg.array_value ();
-
-                      if (! error_state)
-                        retval = lower ? gammainc (x, a) : 1. - gammainc (x, a);
-                    }
-                }
-            }
-          else
-            {
-              NDArray x = x_arg.array_value ();
-
-              if (! error_state)
-                {
-                  if (a_arg.is_scalar_type ())
-                    {
-                      double a = a_arg.double_value ();
-
-                      if (! error_state)
-                        retval = lower ? gammainc (x, a) : 1. - gammainc (x, a);
-                    }
-                  else
-                    {
-                      NDArray a = a_arg.array_value ();
-
-                      if (! error_state)
-                        retval = lower ? gammainc (x, a) : 1. - gammainc (x, a);
-                    }
-                }
-            }
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!test
-%! a = [.5 .5 .5 .5 .5];
-%! x = [0 1 2 3 4];
-%! v1 = sqrt (pi)*erf (x)./gamma (a);
-%! v3 = gammainc (x.*x, a);
-%! assert (v1, v3, sqrt (eps));
-
-%!assert (gammainc (0:4,0.5, "upper"), 1-gammainc (0:4,0.5), 1e-10)
-
-%!test
-%! a = single ([.5 .5 .5 .5 .5]);
-%! x = single ([0 1 2 3 4]);
-%! v1 = sqrt (pi ("single"))*erf (x)./gamma (a);
-%! v3 = gammainc (x.*x, a);
-%! assert (v1, v3, sqrt (eps ("single")));
-
-%!assert (gammainc (single (0:4), single (0.5), "upper"), 
-%!        single (1)-gammainc (single (0:4), single (0.5)),
-%!        single (1e-7))
-*/
--- a/src/DLD-FUNCTIONS/gcd.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,528 +0,0 @@
-/*
-
-Copyright (C) 2004-2012 David Bateman
-Copyright (C) 2010 Jaroslav Hajek, Jordi Gutiérrez Hermoso
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "dNDArray.h"
-#include "CNDArray.h"
-#include "fNDArray.h"
-#include "fCNDArray.h"
-#include "lo-mappers.h"
-#include "oct-binmap.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "oct-obj.h"
-
-static double
-simple_gcd (double a, double b)
-{
-  if (! xisinteger (a) || ! xisinteger (b))
-    (*current_liboctave_error_handler)
-      ("gcd: all values must be integers");
-
-  double aa = fabs (a);
-  double bb = fabs (b);
-
-  while (bb != 0)
-    {
-      double tt = fmod (aa, bb);
-      aa = bb;
-      bb = tt;
-    }
-
-  return aa;
-}
-
-// Don't use the Complex and FloatComplex typedefs because we need to
-// refer to the actual float precision FP in the body (and when gcc
-// implements template aliases from C++0x, can do a small fix here).
-template <typename FP>
-static void
-divide (const std::complex<FP>& a, const std::complex<FP>& b,
-        std::complex<FP>& q, std::complex<FP>& r)
-{
-  FP qr = gnulib::floor ((a/b).real () + 0.5);
-  FP qi = gnulib::floor ((a/b).imag () + 0.5);
-
-  q = std::complex<FP> (qr, qi);
-
-  r = a - q*b;
-}
-
-template <typename FP>
-static std::complex<FP>
-simple_gcd (const std::complex<FP>& a, const std::complex<FP>& b)
-{
-  if (! xisinteger (a.real ()) || ! xisinteger (a.imag ())
-      || ! xisinteger (b.real ()) || ! xisinteger (b.imag ()))
-    (*current_liboctave_error_handler)
-      ("gcd: all complex parts must be integers");
-
-  std::complex<FP> aa = a;
-  std::complex<FP> bb = b;
-
-  if (abs (aa) < abs (bb))
-    std::swap (aa, bb);
-
-  while (abs (bb) != 0)
-    {
-      std::complex<FP> qq, rr;
-      divide (aa, bb, qq, rr);
-      aa = bb;
-      bb = rr;
-    }
-
-  return aa;
-}
-
-template <class T>
-static octave_int<T>
-simple_gcd (const octave_int<T>& a, const octave_int<T>& b)
-{
-  T aa = a.abs ().value ();
-  T bb = b.abs ().value ();
-
-  while (bb != 0)
-    {
-      T tt = aa % bb;
-      aa = bb;
-      bb = tt;
-    }
-
-  return aa;
-}
-
-static double
-extended_gcd (double a, double b, double& x, double& y)
-{
-  if (! xisinteger (a) || ! xisinteger (b))
-    (*current_liboctave_error_handler)
-      ("gcd: all values must be integers");
-
-  double aa = fabs (a);
-  double bb = fabs (b);
-
-  double xx = 0, yy = 1;
-  double lx = 1, ly = 0;
-
-  while (bb != 0)
-    {
-      double qq = gnulib::floor (aa / bb);
-      double tt = fmod (aa, bb);
-
-      aa = bb;
-      bb = tt;
-
-      double tx = lx - qq*xx;
-      lx = xx;
-      xx = tx;
-
-      double ty = ly - qq*yy;
-      ly = yy;
-      yy = ty;
-    }
-
-  x = a >= 0 ? lx : -lx;
-  y = b >= 0 ? ly : -ly;
-
-  return aa;
-}
-
-template <typename FP>
-static std::complex<FP>
-extended_gcd (const std::complex<FP>& a, const std::complex<FP>& b,
-              std::complex<FP>& x, std::complex<FP>& y)
-{
-  if (! xisinteger (a.real ()) || ! xisinteger (a.imag ())
-      || ! xisinteger (b.real ()) || ! xisinteger (b.imag ()))
-    (*current_liboctave_error_handler)
-      ("gcd: all complex parts must be integers");
-
-  std::complex<FP> aa = a, bb = b;
-  bool swapped = false;
-  if (abs (aa) < abs (bb))
-    {
-      std::swap (aa, bb);
-      swapped = true;
-    }
-
-  std::complex<FP> xx = 0, lx = 1;
-  std::complex<FP> yy = 1, ly = 0;
-
-  while (abs(bb) != 0)
-    {
-      std::complex<FP> qq, rr;
-      divide (aa, bb, qq, rr);
-      aa = bb;
-      bb = rr;
-
-      std::complex<FP> tx = lx - qq*xx;
-      lx = xx;
-      xx = tx;
-
-      std::complex<FP> ty = ly - qq*yy;
-      ly = yy;
-      yy = ty;
-    }
-
-  x = lx;
-  y = ly;
-
-  if (swapped)
-    std::swap (x, y);
-
-  return aa;
-}
-
-template <class T>
-static octave_int<T>
-extended_gcd (const octave_int<T>& a, const octave_int<T>& b,
-              octave_int<T>& x, octave_int<T>& y)
-{
-  T aa = a.abs ().value ();
-  T bb = b.abs ().value ();
-  T xx = 0, lx = 1;
-  T yy = 1, ly = 0;
-
-  while (bb != 0)
-    {
-      T qq = aa / bb;
-      T tt = aa % bb;
-      aa = bb;
-      bb = tt;
-
-      T tx = lx - qq*xx;
-      lx = xx;
-      xx = tx;
-
-      T ty = ly - qq*yy;
-      ly = yy;
-      yy = ty;
-    }
-
-  x = octave_int<T> (lx) * a.signum ();
-  y = octave_int<T> (ly) * b.signum ();
-
-  return aa;
-}
-
-template<class NDA>
-static octave_value
-do_simple_gcd (const octave_value& a, const octave_value& b)
-{
-  typedef typename NDA::element_type T;
-  octave_value retval;
-
-  if (a.is_scalar_type () && b.is_scalar_type ())
-    {
-      // Optimize scalar case.
-      T aa = octave_value_extract<T> (a);
-      T bb = octave_value_extract<T> (b);
-      retval = simple_gcd (aa, bb);
-    }
-  else
-    {
-      NDA aa = octave_value_extract<NDA> (a);
-      NDA bb = octave_value_extract<NDA> (b);
-      retval = binmap<T> (aa, bb, simple_gcd, "gcd");
-    }
-
-  return retval;
-}
-
-// Dispatcher
-static octave_value
-do_simple_gcd (const octave_value& a, const octave_value& b)
-{
-  octave_value retval;
-  builtin_type_t btyp = btyp_mixed_numeric (a.builtin_type (),
-                                            b.builtin_type ());
-  switch (btyp)
-    {
-    case btyp_double:
-      if (a.is_sparse_type () && b.is_sparse_type ())
-        {
-          retval = do_simple_gcd<SparseMatrix> (a, b);
-          break;
-        }
-      // fall through!
-
-    case btyp_float:
-      retval = do_simple_gcd<NDArray> (a, b);
-      break;
-
-#define MAKE_INT_BRANCH(X) \
-    case btyp_ ## X: \
-      retval = do_simple_gcd<X ## NDArray> (a, b); \
-      break
-
-    MAKE_INT_BRANCH (int8);
-    MAKE_INT_BRANCH (int16);
-    MAKE_INT_BRANCH (int32);
-    MAKE_INT_BRANCH (int64);
-    MAKE_INT_BRANCH (uint8);
-    MAKE_INT_BRANCH (uint16);
-    MAKE_INT_BRANCH (uint32);
-    MAKE_INT_BRANCH (uint64);
-
-#undef MAKE_INT_BRANCH
-
-    case btyp_complex:
-      retval = do_simple_gcd<ComplexNDArray> (a, b);
-      break;
-
-    case btyp_float_complex:
-      retval = do_simple_gcd<FloatComplexNDArray> (a, b);
-      break;
-
-    default:
-      error ("gcd: invalid class combination for gcd: %s and %s\n",
-             a.class_name ().c_str (), b.class_name ().c_str ());
-    }
-
-  if (btyp == btyp_float)
-    retval = retval.float_array_value ();
-
-  return retval;
-}
-
-template<class NDA>
-static octave_value
-do_extended_gcd (const octave_value& a, const octave_value& b,
-                 octave_value& x, octave_value& y)
-{
-  typedef typename NDA::element_type T;
-  octave_value retval;
-
-  if (a.is_scalar_type () && b.is_scalar_type ())
-    {
-      // Optimize scalar case.
-      T aa = octave_value_extract<T> (a);
-      T bb = octave_value_extract<T> (b);
-      T xx, yy;
-      retval = extended_gcd (aa, bb, xx, yy);
-      x = xx;
-      y = yy;
-    }
-  else
-    {
-      NDA aa = octave_value_extract<NDA> (a);
-      NDA bb = octave_value_extract<NDA> (b);
-
-      dim_vector dv = aa.dims ();
-      if (aa.numel () == 1)
-        dv = bb.dims ();
-      else if (bb.numel () != 1 && bb.dims () != dv)
-        gripe_nonconformant ("gcd", a.dims (), b.dims ());
-
-      NDA gg (dv), xx (dv), yy (dv);
-
-      const T *aptr = aa.fortran_vec ();
-      const T *bptr = bb.fortran_vec ();
-
-      bool inca = aa.numel () != 1;
-      bool incb = bb.numel () != 1;
-
-      T *gptr = gg.fortran_vec ();
-      T *xptr = xx.fortran_vec (), *yptr = yy.fortran_vec ();
-
-      octave_idx_type n = gg.numel ();
-      for (octave_idx_type i = 0; i < n; i++)
-        {
-          octave_quit ();
-
-          *gptr++ = extended_gcd (*aptr, *bptr, *xptr++, *yptr++);
-
-          aptr += inca;
-          bptr += incb;
-        }
-
-      x = xx;
-      y = yy;
-
-      retval = gg;
-    }
-
-  return retval;
-}
-
-// Dispatcher
-static octave_value
-do_extended_gcd (const octave_value& a, const octave_value& b,
-                 octave_value& x, octave_value& y)
-{
-  octave_value retval;
-
-  builtin_type_t btyp = btyp_mixed_numeric (a.builtin_type (),
-                                            b.builtin_type ());
-  switch (btyp)
-    {
-    case btyp_double:
-    case btyp_float:
-      retval = do_extended_gcd<NDArray> (a, b, x, y);
-      break;
-
-#define MAKE_INT_BRANCH(X) \
-    case btyp_ ## X: \
-      retval = do_extended_gcd<X ## NDArray> (a, b, x, y); \
-      break
-
-    MAKE_INT_BRANCH (int8);
-    MAKE_INT_BRANCH (int16);
-    MAKE_INT_BRANCH (int32);
-    MAKE_INT_BRANCH (int64);
-    MAKE_INT_BRANCH (uint8);
-    MAKE_INT_BRANCH (uint16);
-    MAKE_INT_BRANCH (uint32);
-    MAKE_INT_BRANCH (uint64);
-
-#undef MAKE_INT_BRANCH
-
-    case btyp_complex:
-      retval = do_extended_gcd<ComplexNDArray> (a, b, x, y);
-      break;
-
-    case btyp_float_complex:
-      retval = do_extended_gcd<FloatComplexNDArray> (a, b, x, y);
-      break;
-
-    default:
-      error ("gcd: invalid class combination for gcd: %s and %s\n",
-             a.class_name ().c_str (), b.class_name ().c_str ());
-    }
-
-  // For consistency.
-  if (! error_state && a.is_sparse_type () && b.is_sparse_type ())
-    {
-      retval = retval.sparse_matrix_value ();
-      x = x.sparse_matrix_value ();
-      y = y.sparse_matrix_value ();
-    }
-
-  if (btyp == btyp_float)
-    {
-      retval = retval.float_array_value ();
-      x = x.float_array_value ();
-      y = y.float_array_value ();
-    }
-
-  return retval;
-}
-
-DEFUN_DLD (gcd, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{g} =} gcd (@var{a1}, @var{a2}, @dots{})\n\
-@deftypefnx {Loadable Function} {[@var{g}, @var{v1}, @dots{}] =} gcd (@var{a1}, @var{a2}, @dots{})\n\
-\n\
-Compute the greatest common divisor of @var{a1}, @var{a2}, @dots{}.  If more\n\
-than one argument is given all arguments must be the same size or scalar.\n\
-In this case the greatest common divisor is calculated for each element\n\
-individually.  All elements must be ordinary or Gaussian (complex)\n\
-integers.  Note that for Gaussian integers, the gcd is not unique up to\n\
-units (multiplication by 1, -1, @var{i} or -@var{i}), so an arbitrary\n\
-greatest common divisor amongst four possible is returned.\n\
-\n\
-Example code:\n\
-\n\
-@example\n\
-@group\n\
-gcd ([15, 9], [20, 18])\n\
-   @result{}  5  9\n\
-@end group\n\
-@end example\n\
-\n\
-Optional return arguments @var{v1}, etc., contain integer vectors such\n\
-that,\n\
-\n\
-@tex\n\
-$g = v_1 a_1 + v_2 a_2 + \\cdots$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-@var{g} = @var{v1} .* @var{a1} + @var{v2} .* @var{a2} + @dots{}\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-\n\
-@seealso{lcm, factor}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin > 1)
-    {
-      if (nargout > 1)
-        {
-          retval.resize (nargin + 1);
-
-          retval(0) = do_extended_gcd (args(0), args(1), retval(1), retval(2));
-
-          for (int j = 2; j < nargin; j++)
-            {
-              octave_value x;
-              retval(0) = do_extended_gcd (retval(0), args(j),
-                                           x, retval(j+1));
-              for (int i = 0; i < j; i++)
-                retval(i+1).assign (octave_value::op_el_mul_eq, x);
-
-              if (error_state)
-                break;
-            }
-        }
-      else
-        {
-          retval(0) = do_simple_gcd (args(0), args(1));
-
-          for (int j = 2; j < nargin; j++)
-            {
-              retval(0) = do_simple_gcd (retval(0), args(j));
-
-              if (error_state)
-                break;
-            }
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!assert (gcd (200, 300, 50, 35), 5)
-%!assert (gcd (int16 (200), int16 (300), int16 (50), int16 (35)), int16 (5))
-%!assert (gcd (uint64 (200), uint64 (300), uint64 (50), uint64 (35)), uint64 (5))
-%!assert (gcd (18-i, -29+3i), -3-4i)
-
-%!error gcd ()
-
-%!test
-%! s.a = 1;
-%! fail ("gcd (s)");
-*/
--- a/src/DLD-FUNCTIONS/getgrent.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,215 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-
-#include <sys/types.h>
-
-#include "oct-group.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-map.h"
-#include "ov.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-// Group file functions.  (Why not?)
-
-static octave_value
-mk_gr_map (const octave_group& gr)
-{
-  octave_value retval;
-
-  if (gr)
-    {
-      octave_scalar_map m;
-
-      m.assign ("name", gr.name ());
-      m.assign ("passwd", gr.passwd ());
-      m.assign ("gid", static_cast<double> (gr.gid ()));
-      m.assign ("mem", octave_value (gr.mem ()));
-
-      retval = m;
-    }
-  else
-    retval = 0;
-
-  return retval;
-}
-
-DEFUN_DLD (getgrent, args, ,
- "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{grp_struct} =} getgrent ()\n\
-Return an entry from the group database, opening it if necessary.\n\
-Once the end of data has been reached, @code{getgrent} returns 0.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  retval(1) = std::string ();
-  retval(0) = 0;
-
-  int nargin = args.length ();
-
-  if (nargin == 0)
-    {
-      std::string msg;
-
-      retval(1) = msg;
-      retval(0) = mk_gr_map (octave_group::getgrent (msg));
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-DEFUN_DLD (getgrgid, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{grp_struct} =} getgrgid (@var{gid}).\n\
-Return the first entry from the group database with the group ID\n\
-@var{gid}.  If the group ID does not exist in the database,\n\
-@code{getgrgid} returns 0.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  retval(1) = std::string ();
-  retval(0) = 0;
-
-  int nargin = args.length ();
-
-  if (nargin == 1)
-    {
-      double dval = args(0).double_value ();
-
-      if (! error_state)
-        {
-          if (D_NINT (dval) == dval)
-            {
-              gid_t gid = static_cast<gid_t> (dval);
-
-              std::string msg;
-
-              retval(1) = msg;
-              retval(0) = mk_gr_map (octave_group::getgrgid (gid, msg));
-            }
-          else
-            error ("getgrgid: GID must be an integer");
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-DEFUN_DLD (getgrnam, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{grp_struct} =} getgrnam (@var{name})\n\
-Return the first entry from the group database with the group name\n\
-@var{name}.  If the group name does not exist in the database,\n\
-@code{getgrnam} returns 0.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  retval(1) = std::string ();
-  retval(0) = 0;
-
-  int nargin = args.length ();
-
-  if (nargin == 1)
-    {
-      std::string s = args(0).string_value ();
-
-      if (! error_state)
-        {
-          std::string msg;
-
-          retval(1) = msg;
-          retval(0) = mk_gr_map (octave_group::getgrnam (s.c_str (), msg));
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-DEFUN_DLD (setgrent, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} setgrent ()\n\
-Return the internal pointer to the beginning of the group database.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  retval(1) = std::string ();
-  retval(0) = -1.0;
-
-  int nargin = args.length ();
-
-  if (nargin == 0)
-    {
-      std::string msg;
-
-      retval(1) = msg;
-      retval(0) = static_cast<double> (octave_group::setgrent (msg));
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-DEFUN_DLD (endgrent, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} endgrent ()\n\
-Close the group database.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  retval(1) = std::string ();
-  retval(0) = -1.0;
-
-  int nargin = args.length ();
-
-  if (nargin == 0)
-    {
-      std::string msg;
-
-      retval(1) = msg;
-      retval(0) = static_cast<double> (octave_group::endgrent (msg));
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
--- a/src/DLD-FUNCTIONS/getpwent.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,219 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-
-#include <sys/types.h>
-
-#include "oct-passwd.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-map.h"
-#include "ov.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-// Password file functions.  (Why not?)
-
-static octave_value
-mk_pw_map (const octave_passwd& pw)
-{
-  octave_value retval;
-
-  if (pw)
-    {
-      octave_scalar_map m;
-
-      m.assign ("name", pw.name ());
-      m.assign ("passwd", pw.passwd ());
-      m.assign ("uid", static_cast<double> (pw.uid ()));
-      m.assign ("gid", static_cast<double> (pw.gid ()));
-      m.assign ("gecos", pw.gecos ());
-      m.assign ("dir", pw.dir ());
-      m.assign ("shell", pw.shell ());
-
-      retval = m;
-    }
-  else
-    retval = 0;
-
-  return retval;
-}
-
-DEFUN_DLD (getpwent, args, ,
- "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{pw_struct} =} getpwent ()\n\
-Return a structure containing an entry from the password database,\n\
-opening it if necessary.  Once the end of the data has been reached,\n\
-@code{getpwent} returns 0.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  retval(1) = std::string ();
-  retval(0) = 0;
-
-  int nargin = args.length ();
-
-  if (nargin == 0)
-    {
-      std::string msg;
-
-      retval(1) = msg;
-      retval(0) = mk_pw_map (octave_passwd::getpwent (msg));
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-DEFUN_DLD (getpwuid, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{pw_struct} =} getpwuid (@var{uid}).\n\
-Return a structure containing the first entry from the password database\n\
-with the user ID @var{uid}.  If the user ID does not exist in the\n\
-database, @code{getpwuid} returns 0.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  retval(1) = std::string ();
-  retval(0) = 0;
-
-  int nargin = args.length ();
-
-  if (nargin == 1)
-    {
-      double dval = args(0).double_value ();
-
-      if (! error_state)
-        {
-          if (D_NINT (dval) == dval)
-            {
-              uid_t uid = static_cast<uid_t> (dval);
-
-              std::string msg;
-
-              retval(1) = msg;
-              retval(0) = mk_pw_map (octave_passwd::getpwuid (uid, msg));
-            }
-          else
-            error ("getpwuid: UID must be an integer");
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-DEFUN_DLD (getpwnam, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{pw_struct} =} getpwnam (@var{name})\n\
-Return a structure containing the first entry from the password database\n\
-with the user name @var{name}.  If the user name does not exist in the\n\
-database, @code{getpwname} returns 0.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  retval(1) = std::string ();
-  retval(0) = 0.0;
-
-  int nargin = args.length ();
-
-  if (nargin == 1)
-    {
-      std::string s = args(0).string_value ();
-
-      if (! error_state)
-        {
-          std::string msg;
-
-          retval(1) = msg;
-          retval(0) = mk_pw_map (octave_passwd::getpwnam (s, msg));
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-DEFUN_DLD (setpwent, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} setpwent ()\n\
-Return the internal pointer to the beginning of the password database.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  retval(1) = std::string ();
-  retval(0) = -1.0;
-
-  int nargin = args.length ();
-
-  if (nargin == 0)
-    {
-      std::string msg;
-
-      retval(1) = msg;
-      retval(0) = static_cast<double> (octave_passwd::setpwent (msg));
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-DEFUN_DLD (endpwent, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} endpwent ()\n\
-Close the password database.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  retval(1) = std::string ();
-  retval(0) = -1.0;
-
-  int nargin = args.length ();
-
-  if (nargin == 0)
-    {
-      std::string msg;
-
-      retval(1) = msg;
-      retval(0) = static_cast<double> (octave_passwd::endpwent (msg));
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
--- a/src/DLD-FUNCTIONS/getrusage.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,205 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <sys/time.h>
-#include <sys/times.h>
-#include <sys/types.h>
-
-#ifdef HAVE_SYS_RESOURCE_H
-#include <sys/resource.h>
-#endif
-
-#if defined (HAVE_SYS_PARAM_H)
-#include <sys/param.h>
-#endif
-
-#include "defun-dld.h"
-#include "oct-map.h"
-#include "sysdep.h"
-#include "ov.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-#if !defined (HZ)
-#if defined (CLK_TCK)
-#define HZ CLK_TCK
-#elif defined (USG)
-#define HZ 100
-#else
-#define HZ 60
-#endif
-#endif
-
-#ifndef RUSAGE_SELF
-#define RUSAGE_SELF 0
-#endif
-
-// System resource functions.
-
-DEFUN_DLD (getrusage, , ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} getrusage ()\n\
-Return a structure containing a number of statistics about the current\n\
-Octave process.  Not all fields are available on all systems.  If it is\n\
-not possible to get CPU time statistics, the CPU time slots are set to\n\
-zero.  Other missing data are replaced by NaN@.  The list of possible\n\
-fields is:\n\
-\n\
-@table @code\n\
-@item idrss\n\
-Unshared data size.\n\
-\n\
-@item inblock\n\
-Number of block input operations.\n\
-\n\
-@item isrss\n\
-Unshared stack size.\n\
-\n\
-@item ixrss\n\
-Shared memory size.\n\
-\n\
-@item majflt\n\
-Number of major page faults.\n\
-\n\
-@item maxrss\n\
-Maximum data size.\n\
-\n\
-@item minflt\n\
-Number of minor page faults.\n\
-\n\
-@item msgrcv\n\
-Number of messages received.\n\
-\n\
-@item msgsnd\n\
-Number of messages sent.\n\
-\n\
-@item nivcsw\n\
-Number of involuntary context switches.\n\
-\n\
-@item nsignals\n\
-Number of signals received.\n\
-\n\
-@item nswap\n\
-Number of swaps.\n\
-\n\
-@item nvcsw\n\
-Number of voluntary context switches.\n\
-\n\
-@item oublock\n\
-Number of block output operations.\n\
-\n\
-@item stime\n\
-A structure containing the system CPU time used.  The structure has the\n\
-elements @code{sec} (seconds) @code{usec} (microseconds).\n\
-\n\
-@item utime\n\
-A structure containing the user CPU time used.  The structure has the\n\
-elements @code{sec} (seconds) @code{usec} (microseconds).\n\
-@end table\n\
-@end deftypefn")
-{
-  octave_scalar_map m;
-  octave_scalar_map tv_tmp;
-
-  // FIXME -- maybe encapsulate all of this in a liboctave class
-#if defined (HAVE_GETRUSAGE)
-
-  struct rusage ru;
-
-  getrusage (RUSAGE_SELF, &ru);
-
-  tv_tmp.assign ("sec", static_cast<double> (ru.ru_utime.tv_sec));
-  tv_tmp.assign ("usec", static_cast<double> (ru.ru_utime.tv_usec));
-  m.assign ("utime", octave_value (tv_tmp));
-
-  tv_tmp.assign ("sec", static_cast<double> (ru.ru_stime.tv_sec));
-  tv_tmp.assign ("usec", static_cast<double> (ru.ru_stime.tv_usec));
-  m.assign ("stime", octave_value (tv_tmp));
-
-#if ! defined (RUSAGE_TIMES_ONLY)
-  m.assign ("maxrss", static_cast<double> (ru.ru_maxrss));
-  m.assign ("ixrss", static_cast<double> (ru.ru_ixrss));
-  m.assign ("idrss", static_cast<double> (ru.ru_idrss));
-  m.assign ("isrss", static_cast<double> (ru.ru_isrss));
-  m.assign ("minflt", static_cast<double> (ru.ru_minflt));
-  m.assign ("majflt", static_cast<double> (ru.ru_majflt));
-  m.assign ("nswap", static_cast<double> (ru.ru_nswap));
-  m.assign ("inblock", static_cast<double> (ru.ru_inblock));
-  m.assign ("oublock", static_cast<double> (ru.ru_oublock));
-  m.assign ("msgsnd", static_cast<double> (ru.ru_msgsnd));
-  m.assign ("msgrcv", static_cast<double> (ru.ru_msgrcv));
-  m.assign ("nsignals", static_cast<double> (ru.ru_nsignals));
-  m.assign ("nvcsw", static_cast<double> (ru.ru_nvcsw));
-  m.assign ("nivcsw", static_cast<double> (ru.ru_nivcsw));
-#endif
-
-#else
-
-  struct tms t;
-
-  times (&t);
-
-  unsigned long ticks;
-  unsigned long seconds;
-  unsigned long fraction;
-
-  ticks = t.tms_utime + t.tms_cutime;
-  fraction = ticks % HZ;
-  seconds = ticks / HZ;
-
-  tv_tmp.assign ("sec", static_cast<double> (seconds));
-  tv_tmp.assign ("usec", static_cast<double> (fraction * 1e6 / HZ));
-  m.assign ("utime", octave_value (tv_tmp));
-
-  ticks = t.tms_stime + t.tms_cstime;
-  fraction = ticks % HZ;
-  seconds = ticks / HZ;
-
-  tv_tmp.assign ("sec", static_cast<double> (seconds));
-  tv_tmp.assign ("usec", static_cast<double> (fraction * 1e6 / HZ));
-  m.assign ("stime", octave_value (tv_tmp));
-
-  double tmp = lo_ieee_nan_value ();
-
-  m.assign ("maxrss", tmp);
-  m.assign ("ixrss", tmp);
-  m.assign ("idrss", tmp);
-  m.assign ("isrss", tmp);
-  m.assign ("minflt", tmp);
-  m.assign ("majflt", tmp);
-  m.assign ("nswap", tmp);
-  m.assign ("inblock", tmp);
-  m.assign ("oublock", tmp);
-  m.assign ("msgsnd", tmp);
-  m.assign ("msgrcv", tmp);
-  m.assign ("nsignals", tmp);
-  m.assign ("nvcsw", tmp);
-  m.assign ("nivcsw", tmp);
-
-#endif
-
-  return octave_value (m);
-}
--- a/src/DLD-FUNCTIONS/givens.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,214 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-// Originally written by A. S. Hodel <scotte@eng.auburn.edu>
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "defun-dld.h"
-#include "error.h"
-#include "oct-obj.h"
-
-DEFUN_DLD (givens, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{g} =} givens (@var{x}, @var{y})\n\
-@deftypefnx {Loadable Function} {[@var{c}, @var{s}] =} givens (@var{x}, @var{y})\n\
-@tex\n\
-Return a $2\\times 2$ orthogonal matrix\n\
-$$\n\
- G = \\left[\\matrix{c & s\\cr -s'& c\\cr}\\right]\n\
-$$\n\
-such that\n\
-$$\n\
- G \\left[\\matrix{x\\cr y}\\right] = \\left[\\matrix{\\ast\\cr 0}\\right]\n\
-$$\n\
-with $x$ and $y$ scalars.\n\
-@end tex\n\
-@ifnottex\n\
-Return a 2 by 2 orthogonal matrix\n\
-@code{@var{g} = [@var{c} @var{s}; -@var{s}' @var{c}]} such that\n\
-@code{@var{g} [@var{x}; @var{y}] = [*; 0]} with @var{x} and @var{y} scalars.\n\
-@end ifnottex\n\
-\n\
-For example:\n\
-\n\
-@example\n\
-@group\n\
-givens (1, 1)\n\
-   @result{}   0.70711   0.70711\n\
-       -0.70711   0.70711\n\
-@end group\n\
-@end example\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin != 2 || nargout > 2)
-    {
-      print_usage ();
-      return retval;
-    }
-  else
-    {
-      if (args(0).is_single_type () || args(1).is_single_type ())
-        {
-          if (args(0).is_complex_type () || args(1).is_complex_type ())
-            {
-              FloatComplex cx = args(0).float_complex_value ();
-              FloatComplex cy = args(1).float_complex_value ();
-
-              if (! error_state)
-                {
-                  FloatComplexMatrix result = Givens (cx, cy);
-
-                  if (! error_state)
-                    {
-                      switch (nargout)
-                        {
-                        case 0:
-                        case 1:
-                          retval(0) = result;
-                          break;
-
-                        case 2:
-                          retval(1) = result (0, 1);
-                          retval(0) = result (0, 0);
-                          break;
-
-                        default:
-                          error ("givens: invalid number of output arguments");
-                          break;
-                        }
-                    }
-                }
-            }
-          else
-            {
-              float x = args(0).float_value ();
-              float y = args(1).float_value ();
-
-              if (! error_state)
-                {
-                  FloatMatrix result = Givens (x, y);
-
-                  if (! error_state)
-                    {
-                      switch (nargout)
-                        {
-                        case 0:
-                        case 1:
-                          retval(0) = result;
-                          break;
-
-                        case 2:
-                          retval(1) = result (0, 1);
-                          retval(0) = result (0, 0);
-                          break;
-
-                        default:
-                          error ("givens: invalid number of output arguments");
-                          break;
-                        }
-                    }
-                }
-            }
-        }
-      else
-        {
-          if (args(0).is_complex_type () || args(1).is_complex_type ())
-            {
-              Complex cx = args(0).complex_value ();
-              Complex cy = args(1).complex_value ();
-
-              if (! error_state)
-                {
-                  ComplexMatrix result = Givens (cx, cy);
-
-                  if (! error_state)
-                    {
-                      switch (nargout)
-                        {
-                        case 0:
-                        case 1:
-                          retval(0) = result;
-                          break;
-
-                        case 2:
-                          retval(1) = result (0, 1);
-                          retval(0) = result (0, 0);
-                          break;
-
-                        default:
-                          error ("givens: invalid number of output arguments");
-                          break;
-                        }
-                    }
-                }
-            }
-          else
-            {
-              double x = args(0).double_value ();
-              double y = args(1).double_value ();
-
-              if (! error_state)
-                {
-                  Matrix result = Givens (x, y);
-
-                  if (! error_state)
-                    {
-                      switch (nargout)
-                        {
-                        case 0:
-                        case 1:
-                          retval(0) = result;
-                          break;
-
-                        case 2:
-                          retval(1) = result (0, 1);
-                          retval(0) = result (0, 0);
-                          break;
-
-                        default:
-                          error ("givens: invalid number of output arguments");
-                          break;
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!assert (givens (1,1), [1, 1; -1, 1] / sqrt (2), 2*eps)
-%!assert (givens (1,0), eye (2))
-%!assert (givens (0,1), [0, 1; -1 0])
-
-%!error givens ()
-%!error givens (1)
-*/
--- a/src/DLD-FUNCTIONS/hess.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,189 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "CmplxHESS.h"
-#include "dbleHESS.h"
-#include "fCmplxHESS.h"
-#include "floatHESS.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-DEFUN_DLD (hess, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{H} =} hess (@var{A})\n\
-@deftypefnx {Loadable Function} {[@var{P}, @var{H}] =} hess (@var{A})\n\
-@cindex Hessenberg decomposition\n\
-Compute the Hessenberg decomposition of the matrix @var{A}.\n\
-\n\
-The Hessenberg decomposition is\n\
-@tex\n\
-$$\n\
-A = PHP^T\n\
-$$\n\
-where $P$ is a square unitary matrix ($P^TP = I$), and $H$\n\
-is upper Hessenberg ($H_{i,j} = 0, \\forall i \\ge j+1$).\n\
-@end tex\n\
-@ifnottex\n\
-@code{@var{P} * @var{H} * @var{P}' = @var{A}} where @var{P} is a square\n\
-unitary matrix (@code{@var{P}' * @var{P} = I}, using complex-conjugate\n\
-transposition) and @var{H} is upper Hessenberg\n\
-(@code{@var{H}(i, j) = 0 forall i >= j+1)}.\n\
-@end ifnottex\n\
-\n\
-The Hessenberg decomposition is usually used as the first step in an\n\
-eigenvalue computation, but has other applications as well (see Golub,\n\
-Nash, and Van Loan, IEEE Transactions on Automatic Control, 1979).\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin != 1 || nargout > 2)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value arg = args(0);
-
-  octave_idx_type nr = arg.rows ();
-  octave_idx_type nc = arg.columns ();
-
-  int arg_is_empty = empty_arg ("hess", nr, nc);
-
-  if (arg_is_empty < 0)
-    return retval;
-  else if (arg_is_empty > 0)
-    return octave_value_list (2, Matrix ());
-
-  if (nr != nc)
-    {
-      gripe_square_matrix_required ("hess");
-      return retval;
-    }
-
-  if (arg.is_single_type ())
-    {
-      if (arg.is_real_type ())
-        {
-         FloatMatrix tmp = arg.float_matrix_value ();
-
-          if (! error_state)
-            {
-              FloatHESS result (tmp);
-
-              if (nargout <= 1)
-                retval(0) = result.hess_matrix ();
-              else
-                {
-                  retval(1) = result.hess_matrix ();
-                  retval(0) = result.unitary_hess_matrix ();
-                }
-            }
-        }
-      else if (arg.is_complex_type ())
-        {
-          FloatComplexMatrix ctmp = arg.float_complex_matrix_value ();
-
-          if (! error_state)
-            {
-              FloatComplexHESS result (ctmp);
-
-              if (nargout <= 1)
-                retval(0) = result.hess_matrix ();
-              else
-                {
-                  retval(1) = result.hess_matrix ();
-                  retval(0) = result.unitary_hess_matrix ();
-                }
-            }
-        }
-    }
-  else
-    {
-      if (arg.is_real_type ())
-        {
-          Matrix tmp = arg.matrix_value ();
-
-          if (! error_state)
-            {
-              HESS result (tmp);
-
-              if (nargout <= 1)
-                retval(0) = result.hess_matrix ();
-              else
-                {
-                  retval(1) = result.hess_matrix ();
-                  retval(0) = result.unitary_hess_matrix ();
-                }
-            }
-        }
-      else if (arg.is_complex_type ())
-        {
-          ComplexMatrix ctmp = arg.complex_matrix_value ();
-
-          if (! error_state)
-            {
-              ComplexHESS result (ctmp);
-
-              if (nargout <= 1)
-                retval(0) = result.hess_matrix ();
-              else
-                {
-                  retval(1) = result.hess_matrix ();
-                  retval(0) = result.unitary_hess_matrix ();
-                }
-            }
-        }
-      else
-        {
-          gripe_wrong_type_arg ("hess", arg);
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!test
-%! a = [1, 2, 3; 5, 4, 6; 8, 7, 9];
-%! [p, h] = hess (a);
-%! assert (p * h * p', a, sqrt (eps));
-
-%!test
-%! a = single ([1, 2, 3; 5, 4, 6; 8, 7, 9]);
-%! [p, h] = hess (a);
-%! assert (p * h * p', a, sqrt (eps ("single")));
-
-%!error hess ()
-%!error hess ([1, 2; 3, 4], 2)
-%!error <argument must be a square matrix> hess ([1, 2; 3, 4; 5, 6])
-*/
--- a/src/DLD-FUNCTIONS/hex2num.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,192 +0,0 @@
-/*
-
-Copyright (C) 2008-2012 David Bateman
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <algorithm>
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-DEFUN_DLD (hex2num, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{n} =} hex2num (@var{s})\n\
-Typecast the 16 character hexadecimal character string to an IEEE 754\n\
-double precision number.  If fewer than 16 characters are given the\n\
-strings are right padded with '0' characters.\n\
-\n\
-Given a string matrix, @code{hex2num} treats each row as a separate\n\
-number.\n\
-\n\
-@example\n\
-@group\n\
-hex2num ([\"4005bf0a8b145769\"; \"4024000000000000\"])\n\
-   @result{} [2.7183; 10.000]\n\
-@end group\n\
-@end example\n\
-@seealso{num2hex, hex2dec, dec2hex}\n\
-@end deftypefn")
-{
-  int nargin = args.length ();
-  octave_value retval;
-
-  if (nargin != 1)
-    print_usage ();
-  else
-    {
-      const charMatrix cmat = args(0).char_matrix_value ();
-
-      if (cmat.columns () > 16)
-        error ("hex2num: S must be no more than 16 characters");
-      else if (! error_state)
-        {
-          octave_idx_type nr = cmat.rows ();
-          octave_idx_type nc = cmat.columns ();
-          ColumnVector m (nr);
-
-          for (octave_idx_type i = 0; i < nr; i++)
-            {
-              union
-              {
-                uint64_t ival;
-                double dval;
-              } num;
-
-              num.ival = 0;
-
-              for (octave_idx_type j = 0; j < nc; j++)
-                {
-                  unsigned char ch = cmat.elem (i, j);
-
-                  if (isxdigit (ch))
-                    {
-                      num.ival <<= 4;
-                      if (ch >= 'a')
-                        num.ival += static_cast<uint64_t> (ch - 'a' + 10);
-                      else if (ch >= 'A')
-                        num.ival += static_cast<uint64_t> (ch - 'A' + 10);
-                      else
-                        num.ival += static_cast<uint64_t> (ch - '0');
-                    }
-                  else
-                    {
-                      error ("hex2num: illegal character found in string S");
-                      break;
-                    }
-                }
-
-              if (error_state)
-                break;
-              else
-                {
-                  if (nc < 16)
-                    num.ival <<= (16 - nc) * 4;
-
-                  m(i) = num.dval;
-                }
-            }
-
-          if (! error_state)
-            retval =  m;
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!assert (hex2num (["c00";"bff";"000";"3ff";"400"]), [-2:2]')
-*/
-
-DEFUN_DLD (num2hex, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{s} =} num2hex (@var{n})\n\
-Typecast a double precision number or vector to a 16 character hexadecimal\n\
-string of the IEEE 754 representation of the number.  For example:\n\
-\n\
-@example\n\
-@group\n\
-num2hex ([-1, 1, e, Inf, NaN, NA])\n\
-@result{} \"bff0000000000000\n\
-    3ff0000000000000\n\
-    4005bf0a8b145769\n\
-    7ff0000000000000\n\
-    fff8000000000000\n\
-    7ff00000000007a2\"\n\
-@end group\n\
-@end example\n\
-@seealso{hex2num, hex2dec, dec2hex}\n\
-@end deftypefn")
-{
-  int nargin = args.length ();
-  octave_value retval;
-
-  if (nargin != 1)
-    print_usage ();
-  else
-    {
-      const ColumnVector v (args(0).vector_value ());
-
-      if (! error_state)
-        {
-          octave_idx_type nr = v.length ();
-          charMatrix m (nr, 16);
-          const double *pv = v.fortran_vec ();
-
-          for (octave_idx_type i = 0; i < nr; i++)
-            {
-              union
-              {
-                uint64_t ival;
-                double dval;
-              } num;
-
-              num.dval = *pv++;
-
-              for (octave_idx_type j = 0; j < 16; j++)
-                {
-                  unsigned char ch =
-                    static_cast<char> (num.ival >> ((15 - j) * 4) & 0xF);
-                  if (ch >= 10)
-                    ch += 'a' - 10;
-                  else
-                    ch += '0';
-
-                  m.elem (i, j) = ch;
-                }
-            }
-
-          retval = m;
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!assert (num2hex (-2:2), ["c000000000000000";"bff0000000000000";"0000000000000000";"3ff0000000000000";"4000000000000000"])
-*/
--- a/src/DLD-FUNCTIONS/inv.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,250 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "ops.h"
-#include "ov-re-diag.h"
-#include "ov-cx-diag.h"
-#include "ov-flt-re-diag.h"
-#include "ov-flt-cx-diag.h"
-#include "ov-perm.h"
-#include "utils.h"
-
-DEFUN_DLD (inv, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{x} =} inv (@var{A})\n\
-@deftypefnx {Loadable Function} {[@var{x}, @var{rcond}] =} inv (@var{A})\n\
-Compute the inverse of the square matrix @var{A}.  Return an estimate\n\
-of the reciprocal condition number if requested, otherwise warn of an\n\
-ill-conditioned matrix if the reciprocal condition number is small.\n\
-\n\
-In general it is best to avoid calculating the inverse of a matrix\n\
-directly.  For example, it is both faster and more accurate to solve\n\
-systems of equations (@var{A}*@math{x} = @math{b}) with\n\
-@code{@var{y} = @var{A} \\ @math{b}}, rather than\n\
-@code{@var{y} = inv (@var{A}) * @math{b}}.\n\
-\n\
-If called with a sparse matrix, then in general @var{x} will be a full\n\
-matrix requiring significantly more storage.  Avoid forming the inverse\n\
-of a sparse matrix if possible.\n\
-@seealso{ldivide, rdivide}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin != 1)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value arg = args(0);
-
-  octave_idx_type nr = arg.rows ();
-  octave_idx_type nc = arg.columns ();
-
-  int arg_is_empty = empty_arg ("inverse", nr, nc);
-
-  if (arg_is_empty < 0)
-    return retval;
-  else if (arg_is_empty > 0)
-    return octave_value (Matrix ());
-
-  if (nr != nc)
-    {
-      gripe_square_matrix_required ("inverse");
-      return retval;
-    }
-
-  octave_value result;
-  octave_idx_type info;
-  double rcond = 0.0;
-  float frcond = 0.0;
-  bool isfloat = arg.is_single_type ();
-
-  if (arg.is_diag_matrix ())
-    {
-      rcond = 1.0;
-      frcond = 1.0f;
-      if (arg.is_complex_type ())
-        {
-          if (isfloat)
-            {
-              result = arg.float_complex_diag_matrix_value ().inverse (info);
-              if (nargout > 1)
-                frcond = arg.float_complex_diag_matrix_value ().rcond ();
-            }
-          else
-            {
-              result = arg.complex_diag_matrix_value ().inverse (info);
-              if (nargout > 1)
-                rcond = arg.complex_diag_matrix_value ().rcond ();
-            }
-        }
-      else
-        {
-          if (isfloat)
-            {
-              result = arg.float_diag_matrix_value ().inverse (info);
-              if (nargout > 1)
-                frcond = arg.float_diag_matrix_value ().rcond ();
-            }
-          else
-            {
-              result = arg.diag_matrix_value ().inverse (info);
-              if (nargout > 1)
-                rcond = arg.diag_matrix_value ().rcond ();
-            }
-        }
-    }
-  else if (arg.is_perm_matrix ())
-    {
-      rcond = 1.0;
-      info = 0;
-      result = arg.perm_matrix_value ().inverse ();
-    }
-  else if (isfloat)
-    {
-      if (arg.is_real_type ())
-        {
-          FloatMatrix m = arg.float_matrix_value ();
-          if (! error_state)
-            {
-              MatrixType mattyp = args(0).matrix_type ();
-              result = m.inverse (mattyp, info, frcond, 1);
-              args(0).matrix_type (mattyp);
-            }
-        }
-      else if (arg.is_complex_type ())
-        {
-          FloatComplexMatrix m = arg.float_complex_matrix_value ();
-          if (! error_state)
-            {
-              MatrixType mattyp = args(0).matrix_type ();
-              result = m.inverse (mattyp, info, frcond, 1);
-              args(0).matrix_type (mattyp);
-            }
-        }
-    }
-  else
-    {
-      if (arg.is_real_type ())
-        {
-          if (arg.is_sparse_type ())
-            {
-              SparseMatrix m = arg.sparse_matrix_value ();
-              if (! error_state)
-                {
-                  MatrixType mattyp = args(0).matrix_type ();
-                  result = m.inverse (mattyp, info, rcond, 1);
-                  args(0).matrix_type (mattyp);
-                }
-            }
-          else
-            {
-              Matrix m = arg.matrix_value ();
-              if (! error_state)
-                {
-                  MatrixType mattyp = args(0).matrix_type ();
-                  result = m.inverse (mattyp, info, rcond, 1);
-                  args(0).matrix_type (mattyp);
-                }
-            }
-        }
-      else if (arg.is_complex_type ())
-        {
-          if (arg.is_sparse_type ())
-            {
-              SparseComplexMatrix m = arg.sparse_complex_matrix_value ();
-              if (! error_state)
-                {
-                  MatrixType mattyp = args(0).matrix_type ();
-                  result = m.inverse (mattyp, info, rcond, 1);
-                  args(0).matrix_type (mattyp);
-                }
-            }
-          else
-            {
-              ComplexMatrix m = arg.complex_matrix_value ();
-              if (! error_state)
-                {
-                  MatrixType mattyp = args(0).matrix_type ();
-                  result = m.inverse (mattyp, info, rcond, 1);
-                  args(0).matrix_type (mattyp);
-                }
-            }
-        }
-      else
-        gripe_wrong_type_arg ("inv", arg);
-    }
-
-  if (! error_state)
-    {
-      if (nargout > 1)
-        retval(1) = isfloat ? octave_value (frcond) : octave_value (rcond);
-
-      retval(0) = result;
-
-      volatile double xrcond = rcond;
-      xrcond += 1.0;
-      if (nargout < 2 && (info == -1 || xrcond == 1.0))
-        warning ("inverse: matrix singular to machine precision, rcond = %g",
-                 rcond);
-    }
-
-  return retval;
-}
-
-/*
-%!assert (inv ([1, 2; 3, 4]), [-2, 1; 1.5, -0.5], sqrt (eps))
-%!assert (inv (single ([1, 2; 3, 4])), single ([-2, 1; 1.5, -0.5]), sqrt (eps ("single")))
-
-%!error inv ()
-%!error inv ([1, 2; 3, 4], 2)
-%!error <argument must be a square matrix> inv ([1, 2; 3, 4; 5, 6])
-*/
-
-// FIXME -- this should really be done with an alias, but
-// alias_builtin() won't do the right thing if we are actually using
-// dynamic linking.
-
-DEFUN_DLD (inverse, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{x} =} inverse (@var{A})\n\
-@deftypefnx {Loadable Function} {[@var{x}, @var{rcond}] =} inverse (@var{A})\n\
-Compute the inverse of the square matrix @var{A}.\n\
-\n\
-This is an alias for @code{inv}.\n\
-@seealso{inv}\n\
-@end deftypefn")
-{
-  return Finv (args, nargout);
-}
--- a/src/DLD-FUNCTIONS/kron.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,321 +0,0 @@
-/*
-
-Copyright (C) 2002-2012 John W. Eaton
-
-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/>.
-
-*/
-
-// Author: Paul Kienzle <pkienzle@users.sf.net>
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "dMatrix.h"
-#include "fMatrix.h"
-#include "CMatrix.h"
-#include "fCMatrix.h"
-
-#include "dSparse.h"
-#include "CSparse.h"
-
-#include "dDiagMatrix.h"
-#include "fDiagMatrix.h"
-#include "CDiagMatrix.h"
-#include "fCDiagMatrix.h"
-
-#include "PermMatrix.h"
-
-#include "mx-inlines.cc"
-#include "quit.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "oct-obj.h"
-
-template <class R, class T>
-static MArray<T>
-kron (const MArray<R>& a, const MArray<T>& b)
-{
-  assert (a.ndims () == 2);
-  assert (b.ndims () == 2);
-
-  octave_idx_type nra = a.rows (), nrb = b.rows ();
-  octave_idx_type nca = a.cols (), ncb = b.cols ();
-
-  MArray<T> c (dim_vector (nra*nrb, nca*ncb));
-  T *cv = c.fortran_vec ();
-
-  for (octave_idx_type ja = 0; ja < nca; ja++)
-    for (octave_idx_type jb = 0; jb < ncb; jb++)
-      for (octave_idx_type ia = 0; ia < nra; ia++)
-        {
-          octave_quit ();
-          mx_inline_mul (nrb, cv, a(ia, ja), b.data () + nrb*jb);
-          cv += nrb;
-        }
-
-  return c;
-}
-
-template <class R, class T>
-static MArray<T>
-kron (const MDiagArray2<R>& a, const MArray<T>& b)
-{
-  assert (b.ndims () == 2);
-
-  octave_idx_type nra = a.rows (), nrb = b.rows (), dla = a.diag_length ();
-  octave_idx_type nca = a.cols (), ncb = b.cols ();
-
-  MArray<T> c (dim_vector (nra*nrb, nca*ncb), T ());
-
-  for (octave_idx_type ja = 0; ja < dla; ja++)
-    for (octave_idx_type jb = 0; jb < ncb; jb++)
-      {
-        octave_quit ();
-        mx_inline_mul (nrb, &c.xelem (ja*nrb, ja*ncb + jb), a.dgelem (ja), b.data () + nrb*jb);
-      }
-
-  return c;
-}
-
-template <class T>
-static MSparse<T>
-kron (const MSparse<T>& A, const MSparse<T>& B)
-{
-  octave_idx_type idx = 0;
-  MSparse<T> C (A.rows () * B.rows (), A.columns () * B.columns (),
-                A.nnz () * B.nnz ());
-
-  C.cidx (0) = 0;
-
-  for (octave_idx_type Aj = 0; Aj < A.columns (); Aj++)
-    for (octave_idx_type Bj = 0; Bj < B.columns (); Bj++)
-      {
-        octave_quit ();
-        for (octave_idx_type Ai = A.cidx (Aj); Ai < A.cidx (Aj+1); Ai++)
-          {
-            octave_idx_type Ci = A.ridx (Ai) * B.rows ();
-            const T v = A.data (Ai);
-
-            for (octave_idx_type Bi = B.cidx (Bj); Bi < B.cidx (Bj+1); Bi++)
-              {
-                C.data (idx) = v * B.data (Bi);
-                C.ridx (idx++) = Ci + B.ridx (Bi);
-              }
-          }
-        C.cidx (Aj * B.columns () + Bj + 1) = idx;
-      }
-
-  return C;
-}
-
-static PermMatrix
-kron (const PermMatrix& a, const PermMatrix& b)
-{
-  octave_idx_type na = a.rows (), nb = b.rows ();
-  const octave_idx_type *pa = a.data (), *pb = b.data ();
-  PermMatrix c(na*nb); // Row permutation.
-  octave_idx_type *pc = c.fortran_vec ();
-
-  bool cola = a.is_col_perm (), colb = b.is_col_perm ();
-  if (cola && colb)
-    {
-      for (octave_idx_type i = 0; i < na; i++)
-        for (octave_idx_type j = 0; j < nb; j++)
-          pc[pa[i]*nb+pb[j]] = i*nb+j;
-    }
-  else if (cola)
-    {
-      for (octave_idx_type i = 0; i < na; i++)
-        for (octave_idx_type j = 0; j < nb; j++)
-          pc[pa[i]*nb+j] = i*nb+pb[j];
-    }
-  else if (colb)
-    {
-      for (octave_idx_type i = 0; i < na; i++)
-        for (octave_idx_type j = 0; j < nb; j++)
-          pc[i*nb+pb[j]] = pa[i]*nb+j;
-    }
-  else
-    {
-      for (octave_idx_type i = 0; i < na; i++)
-        for (octave_idx_type j = 0; j < nb; j++)
-          pc[i*nb+j] = pa[i]*nb+pb[j];
-    }
-
-  return c;
-}
-
-template <class MTA, class MTB>
-octave_value
-do_kron (const octave_value& a, const octave_value& b)
-{
-  MTA am = octave_value_extract<MTA> (a);
-  MTB bm = octave_value_extract<MTB> (b);
-  return octave_value (kron (am, bm));
-}
-
-octave_value
-dispatch_kron (const octave_value& a, const octave_value& b)
-{
-  octave_value retval;
-  if (a.is_perm_matrix () && b.is_perm_matrix ())
-    retval = do_kron<PermMatrix, PermMatrix> (a, b);
-  else if (a.is_diag_matrix ())
-    {
-      if (b.is_diag_matrix () && a.rows () == a.columns ()
-          && b.rows () == b.columns ())
-        {
-          // We have two diagonal matrices, the product of those will be
-          // another diagonal matrix.  To do that efficiently, extract
-          // the diagonals as vectors and compute the product.  That
-          // will be another vector, which we then use to construct a
-          // diagonal matrix object.  Note that this will fail if our
-          // digaonal matrix object is modified to allow the non-zero
-          // values to be stored off of the principal diagonal (i.e., if
-          // diag ([1,2], 3) is modified to return a diagonal matrix
-          // object instead of a full matrix object).
-
-          octave_value tmp = dispatch_kron (a.diag (), b.diag ());
-          retval = tmp.diag ();
-        }
-      else if (a.is_single_type () || b.is_single_type ())
-        {
-          if (a.is_complex_type ())
-            retval = do_kron<FloatComplexDiagMatrix, FloatComplexMatrix> (a, b);
-          else if (b.is_complex_type ())
-            retval = do_kron<FloatDiagMatrix, FloatComplexMatrix> (a, b);
-          else
-            retval = do_kron<FloatDiagMatrix, FloatMatrix> (a, b);
-        }
-      else
-        {
-          if (a.is_complex_type ())
-            retval = do_kron<ComplexDiagMatrix, ComplexMatrix> (a, b);
-          else if (b.is_complex_type ())
-            retval = do_kron<DiagMatrix, ComplexMatrix> (a, b);
-          else
-            retval = do_kron<DiagMatrix, Matrix> (a, b);
-        }
-    }
-  else if (a.is_sparse_type () || b.is_sparse_type ())
-    {
-      if (a.is_complex_type () || b.is_complex_type ())
-        retval = do_kron<SparseComplexMatrix, SparseComplexMatrix> (a, b);
-      else
-        retval = do_kron<SparseMatrix, SparseMatrix> (a, b);
-    }
-  else if (a.is_single_type () || b.is_single_type ())
-    {
-      if (a.is_complex_type ())
-        retval = do_kron<FloatComplexMatrix, FloatComplexMatrix> (a, b);
-      else if (b.is_complex_type ())
-        retval = do_kron<FloatMatrix, FloatComplexMatrix> (a, b);
-      else
-        retval = do_kron<FloatMatrix, FloatMatrix> (a, b);
-    }
-  else
-    {
-      if (a.is_complex_type ())
-        retval = do_kron<ComplexMatrix, ComplexMatrix> (a, b);
-      else if (b.is_complex_type ())
-        retval = do_kron<Matrix, ComplexMatrix> (a, b);
-      else
-        retval = do_kron<Matrix, Matrix> (a, b);
-    }
-  return retval;
-}
-
-
-DEFUN_DLD (kron, args, , "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} kron (@var{A}, @var{B})\n\
-@deftypefnx {Loadable Function} {} kron (@var{A1}, @var{A2}, @dots{})\n\
-Form the Kronecker product of two or more matrices, defined block by \n\
-block as\n\
-\n\
-@example\n\
-x = [ a(i,j)*b ]\n\
-@end example\n\
-\n\
-For example:\n\
-\n\
-@example\n\
-@group\n\
-kron (1:4, ones (3, 1))\n\
-     @result{}  1  2  3  4\n\
-         1  2  3  4\n\
-         1  2  3  4\n\
-@end group\n\
-@end example\n\
-\n\
-If there are more than two input arguments @var{A1}, @var{A2}, @dots{}, \n\
-@var{An} the Kronecker product is computed as\n\
-\n\
-@example\n\
-kron (kron (@var{A1}, @var{A2}), @dots{}, @var{An})\n\
-@end example\n\
-\n\
-@noindent\n\
-Since the Kronecker product is associative, this is well-defined.\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin >= 2)
-    {
-      octave_value a = args(0), b = args(1);
-      retval = dispatch_kron (a, b);
-      for (octave_idx_type i = 2; i < nargin; i++)
-        retval = dispatch_kron (retval, args(i));
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-
-/*
-%!test
-%! x = ones (2);
-%! assert (kron (x, x), ones (4));
-
-%!shared x, y, z
-%! x =  [1, 2];
-%! y =  [-1, -2];
-%! z =  [1,  2,  3,  4; 1,  2,  3,  4; 1,  2,  3,  4];
-%!assert (kron (1:4, ones (3, 1)), z)
-%!assert (kron (x, y, z), kron (kron (x, y), z))
-%!assert (kron (x, y, z), kron (x, kron (y, z)))
-
-%!assert (kron (diag ([1, 2]), diag ([3, 4])), diag ([3, 4, 6, 8]))
-
-%% Test for two diag matrices.  See the comments above in
-%% dispatch_kron for this case.
-%%
-%!test
-%! expected = zeros (16, 16);
-%! expected (1, 11) = 3;
-%! expected (2, 12) = 4;
-%! expected (5, 15) = 6;
-%! expected (6, 16) = 8;
-%! assert (kron (diag ([1, 2], 2), diag ([3, 4], 2)), expected)
-*/
--- a/src/DLD-FUNCTIONS/lookup.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,397 +0,0 @@
-/*
-
-Copyright (C) 2008-2012 VZLU Prague a.s., Czech Republic
-
-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/>.
-
-*/
-
-// Author: Jaroslav Hajek <highegg@gmail.com>
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <cctype>
-#include <functional>
-#include <algorithm>
-
-#include "dNDArray.h"
-#include "CNDArray.h"
-
-#include "Cell.h"
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "ov.h"
-
-static
-bool
-contains_char (const std::string& str, char c)
-{
-  return (str.find (c) != std::string::npos
-          || str.find (std::toupper (c)) != std::string::npos);
-}
-
-// case-insensitive character comparison functors
-struct icmp_char_lt : public std::binary_function<char, char, bool>
-{
-  bool operator () (char x, char y) const
-    { return std::toupper (x) < std::toupper (y); }
-};
-
-struct icmp_char_gt : public std::binary_function<char, char, bool>
-{
-  bool operator () (char x, char y) const
-    { return std::toupper (x) > std::toupper (y); }
-};
-
-// FIXME -- maybe these should go elsewhere?
-// FIXME -- are they even needed now?
-// case-insensitive ascending comparator
-#if 0
-static bool
-stri_comp_lt (const std::string& a, const std::string& b)
-{
-  return std::lexicographical_compare (a.begin (), a.end (),
-                                       b.begin (), b.end (),
-                                       icmp_char_lt ());
-}
-
-// case-insensitive descending comparator
-static bool
-stri_comp_gt (const std::string& a, const std::string& b)
-{
-  return std::lexicographical_compare (a.begin (), a.end (),
-                                       b.begin (), b.end (),
-                                       icmp_char_gt ());
-}
-#endif
-
-template <class T>
-inline sortmode
-get_sort_mode (const Array<T>& array,
-               typename octave_sort<T>::compare_fcn_type desc_comp
-               = octave_sort<T>::descending_compare)
-{
-  octave_idx_type n = array.numel ();
-  if (n > 1 && desc_comp (array (0), array (n-1)))
-    return DESCENDING;
-  else
-    return ASCENDING;
-}
-
-// FIXME: perhaps there should be octave_value::lookup?
-// The question is, how should it behave w.r.t. the second argument's type.
-// We'd need a dispatch on two arguments. Hmmm...
-
-#define INT_ARRAY_LOOKUP(TYPE) \
-  (table.is_ ## TYPE ## _type () && y.is_ ## TYPE ## _type ()) \
-    retval = do_numeric_lookup (table.TYPE ## _array_value (), \
-                                y.TYPE ## _array_value (), \
-                                left_inf, right_inf, \
-                                match_idx, match_bool);
-template <class ArrayT>
-static octave_value
-do_numeric_lookup (const ArrayT& array, const ArrayT& values,
-                   bool left_inf, bool right_inf,
-                   bool match_idx, bool match_bool)
-{
-  octave_value retval;
-
-  Array<octave_idx_type> idx = array.lookup (values);
-  octave_idx_type n = array.numel (), nval = values.numel ();
-
-  // Post-process.
-  if (match_bool)
-    {
-      boolNDArray match (idx.dims ());
-      for (octave_idx_type i = 0; i < nval; i++)
-        {
-          octave_idx_type j = idx.xelem (i);
-          match.xelem (i) = j != 0 && values(i) == array(j-1);
-        }
-
-      retval = match;
-    }
-  else if (match_idx || left_inf || right_inf)
-    {
-      if (match_idx)
-        {
-          NDArray ridx (idx.dims ());
-
-          for (octave_idx_type i = 0; i < nval; i++)
-            {
-              octave_idx_type j = idx.xelem (i);
-              ridx.xelem (i) = (j != 0 && values(i) == array(j-1)) ? j : 0;
-            }
-
-          retval = ridx;
-        }
-      else if (left_inf && right_inf)
-        {
-          // Results in valid indices. Optimize using lazy index.
-          octave_idx_type zero = 0;
-          for (octave_idx_type i = 0; i < nval; i++)
-            {
-              octave_idx_type j = idx.xelem (i) - 1;
-              idx.xelem (i) = std::max (zero, std::min (j, n-2));
-            }
-
-          retval = idx_vector (idx);
-        }
-      else if (left_inf)
-        {
-          // Results in valid indices. Optimize using lazy index.
-          octave_idx_type zero = 0;
-          for (octave_idx_type i = 0; i < nval; i++)
-            {
-              octave_idx_type j = idx.xelem (i) - 1;
-              idx.xelem (i) = std::max (zero, j);
-            }
-
-          retval = idx_vector (idx);
-        }
-      else if (right_inf)
-        {
-          NDArray ridx (idx.dims ());
-
-          for (octave_idx_type i = 0; i < nval; i++)
-            {
-              octave_idx_type j = idx.xelem (i);
-              ridx.xelem (i) = std::min (j, n-1);
-            }
-
-          retval = ridx;
-        }
-    }
-  else
-    retval = idx;
-
-  return retval;
-}
-
-DEFUN_DLD (lookup, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{idx} =} lookup (@var{table}, @var{y})\n\
-@deftypefnx {Loadable Function} {@var{idx} =} lookup (@var{table}, @var{y}, @var{opt})\n\
-Lookup values in a sorted table.  Usually used as a prelude to\n\
-interpolation.\n\
-\n\
-If table is increasing and @code{idx = lookup (table, y)}, then\n\
-@code{table(idx(i)) <= y(i) < table(idx(i+1))} for all @code{y(i)}\n\
-within the table.  If @code{y(i) < table(1)} then\n\
-@code{idx(i)} is 0. If @code{y(i) >= table(end)} or @code{isnan (y(i))} then\n\
-@code{idx(i)} is @code{n}.\n\
-\n\
-If the table is decreasing, then the tests are reversed.\n\
-For non-strictly monotonic tables, empty intervals are always skipped.\n\
-The result is undefined if @var{table} is not monotonic, or if\n\
-@var{table} contains a NaN.\n\
-\n\
-The complexity of the lookup is O(M*log(N)) where N is the size of\n\
-@var{table} and M is the size of @var{y}.  In the special case when @var{y}\n\
-is also sorted, the complexity is O(min(M*log(N),M+N)).\n\
-\n\
-@var{table} and @var{y} can also be cell arrays of strings\n\
-(or @var{y} can be a single string).  In this case, string lookup\n\
-is performed using lexicographical comparison.\n\
-\n\
-If @var{opts} is specified, it must be a string with letters indicating\n\
-additional options.\n\
-\n\
-@table @code\n\
-@item m\n\
-@code{table(idx(i)) == val(i)} if @code{val(i)}\n\
-occurs in table; otherwise, @code{idx(i)} is zero.\n\
-\n\
-@item b\n\
-@code{idx(i)} is a logical 1 or 0, indicating whether\n\
-@code{val(i)} is contained in table or not.\n\
-\n\
-@item l\n\
-For numeric lookups\n\
-the leftmost subinterval shall be extended to infinity (i.e., all indices\n\
-at least 1)\n\
-\n\
-@item r\n\
-For numeric lookups\n\
-the rightmost subinterval shall be extended to infinity (i.e., all indices\n\
-at most n-1).\n\
-@end table\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 2 || nargin > 3 || (nargin == 3 && ! args(2).is_string ()))
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value table = args(0), y = args(1);
-  if (table.ndims () > 2 || (table.columns () > 1 && table.rows () > 1))
-    warning ("lookup: table is not a vector");
-
-  bool num_case = ((table.is_numeric_type () && y.is_numeric_type ())
-                   || (table.is_char_matrix () && y.is_char_matrix ()));
-  bool str_case = table.is_cellstr () && (y.is_string () || y.is_cellstr ());
-  bool left_inf = false;
-  bool right_inf = false;
-  bool match_idx = false;
-  bool match_bool = false;
-
-  if (nargin == 3)
-    {
-      std::string opt = args(2).string_value ();
-      left_inf = contains_char (opt, 'l');
-      right_inf = contains_char (opt, 'r');
-      match_idx = contains_char (opt, 'm');
-      match_bool = contains_char (opt, 'b');
-      if (opt.find_first_not_of ("lrmb") != std::string::npos)
-        {
-          error ("lookup: unrecognized option: %c",
-                 opt[opt.find_first_not_of ("lrmb")]);
-          return retval;
-        }
-    }
-
-  if ((match_idx || match_bool) && (left_inf || right_inf))
-    error ("lookup: m, b cannot be specified with l or r");
-  else if (match_idx && match_bool)
-    error ("lookup: only one of m or b can be specified");
-  else if (str_case && (left_inf || right_inf))
-    error ("lookup: l, r are not recognized for string lookups");
-
-  if (error_state)
-    return retval;
-
-  if (num_case)
-    {
-
-      // In the case of a complex array, absolute values will be used for compatibility
-      // (though it's not too meaningful).
-
-      if (table.is_complex_type ())
-        table = table.abs ();
-
-      if (y.is_complex_type ())
-        y = y.abs ();
-
-      Array<octave_idx_type> idx;
-
-      // PS: I learned this from data.cc
-      if INT_ARRAY_LOOKUP (int8)
-      else if INT_ARRAY_LOOKUP (int16)
-      else if INT_ARRAY_LOOKUP (int32)
-      else if INT_ARRAY_LOOKUP (int64)
-      else if INT_ARRAY_LOOKUP (uint8)
-      else if INT_ARRAY_LOOKUP (uint16)
-      else if INT_ARRAY_LOOKUP (uint32)
-      else if INT_ARRAY_LOOKUP (uint64)
-      else if (table.is_char_matrix () && y.is_char_matrix ())
-        retval = do_numeric_lookup (table.char_array_value (),
-                                    y.char_array_value (),
-                                    left_inf, right_inf,
-                                    match_idx, match_bool);
-      else if (table.is_single_type () || y.is_single_type ())
-        retval = do_numeric_lookup (table.float_array_value (),
-                                    y.float_array_value (),
-                                    left_inf, right_inf,
-                                    match_idx, match_bool);
-      else
-        retval = do_numeric_lookup (table.array_value (),
-                                    y.array_value (),
-                                    left_inf, right_inf,
-                                    match_idx, match_bool);
-
-    }
-  else if (str_case)
-    {
-      Array<std::string> str_table = table.cellstr_value ();
-      Array<std::string> str_y (dim_vector (1, 1));
-
-      if (y.is_cellstr ())
-        str_y = y.cellstr_value ();
-      else
-        str_y(0) = y.string_value ();
-
-      Array<octave_idx_type> idx = str_table.lookup (str_y);
-      octave_idx_type nval = str_y.numel ();
-
-      // Post-process.
-      if (match_bool)
-        {
-          boolNDArray match (idx.dims ());
-          for (octave_idx_type i = 0; i < nval; i++)
-            {
-              octave_idx_type j = idx.xelem (i);
-              match.xelem (i) = j != 0 && str_y(i) == str_table(j-1);
-            }
-
-          retval = match;
-        }
-      else if (match_idx)
-        {
-          NDArray ridx (idx.dims ());
-          if (match_idx)
-            {
-              for (octave_idx_type i = 0; i < nval; i++)
-                {
-                  octave_idx_type j = idx.xelem (i);
-                  ridx.xelem (i) = (j != 0 && str_y(i) == str_table(j-1)) ? j : 0;
-                }
-            }
-
-          retval = ridx;
-        }
-      else
-        retval = idx;
-    }
-  else
-    print_usage ();
-
-  return retval;
-
-}
-
-/*
-%!assert (lookup (1:3, 0.5), 0)     # value before table
-%!assert (lookup (1:3, 3.5), 3)     # value after table error
-%!assert (lookup (1:3, 1.5), 1)     # value within table error
-%!assert (lookup (1:3, [3,2,1]), [3,2,1])
-%!assert (lookup ([1:4]', [1.2, 3.5]'), [1, 3]')
-%!assert (lookup ([1:4], [1.2, 3.5]'), [1, 3]')
-%!assert (lookup ([1:4]', [1.2, 3.5]), [1, 3])
-%!assert (lookup ([1:4], [1.2, 3.5]), [1, 3])
-%!assert (lookup (1:3, [3, 2, 1]), [3, 2, 1])
-%!assert (lookup ([3:-1:1], [3.5, 3, 1.2, 2.5, 2.5]), [0, 1, 2, 1, 1])
-%!assert (isempty (lookup ([1:3], [])))
-%!assert (isempty (lookup ([1:3]', [])))
-%!assert (lookup (1:3, [1, 2; 3, 0.5]), [1, 2; 3, 0])
-%!assert (lookup (1:4, [1, 1.2; 3, 2.5], "m"), [1, 0; 3, 0])
-%!assert (lookup (4:-1:1, [1, 1.2; 3, 2.5], "m"), [4, 0; 2, 0])
-%!assert (lookup (1:4, [1, 1.2; 3, 2.5], "b"), logical ([1, 0; 3, 0]))
-%!assert (lookup (4:-1:1, [1, 1.2; 3, 2.5], "b"), logical ([4, 0; 2, 0]))
-%!
-%!assert (lookup ({"apple","lemon","orange"}, {"banana","kiwi"; "ananas","mango"}), [1,1;0,2])
-%!assert (lookup ({"apple","lemon","orange"}, "potato"), 3)
-%!assert (lookup ({"orange","lemon","apple"}, "potato"), 0)
-*/
--- a/src/DLD-FUNCTIONS/lsode.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,548 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-
-#include <iomanip>
-#include <iostream>
-
-#include "LSODE.h"
-#include "lo-mappers.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "ov-fcn.h"
-#include "ov-cell.h"
-#include "pager.h"
-#include "pr-output.h"
-#include "unwind-prot.h"
-#include "utils.h"
-#include "variables.h"
-
-#include "LSODE-opts.cc"
-
-// Global pointer for user defined function required by lsode.
-static octave_function *lsode_fcn;
-
-// Global pointer for optional user defined jacobian function used by lsode.
-static octave_function *lsode_jac;
-
-// Have we warned about imaginary values returned from user function?
-static bool warned_fcn_imaginary = false;
-static bool warned_jac_imaginary = false;
-
-// Is this a recursive call?
-static int call_depth = 0;
-
-ColumnVector
-lsode_user_function (const ColumnVector& x, double t)
-{
-  ColumnVector retval;
-
-  octave_value_list args;
-  args(1) = t;
-  args(0) = x;
-
-  if (lsode_fcn)
-    {
-      octave_value_list tmp = lsode_fcn->do_multi_index_op (1, args);
-
-      if (error_state)
-        {
-          gripe_user_supplied_eval ("lsode");
-          return retval;
-        }
-
-      if (tmp.length () > 0 && tmp(0).is_defined ())
-        {
-          if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
-            {
-              warning ("lsode: ignoring imaginary part returned from user-supplied function");
-              warned_fcn_imaginary = true;
-            }
-
-          retval = ColumnVector (tmp(0).vector_value ());
-
-          if (error_state || retval.length () == 0)
-            gripe_user_supplied_eval ("lsode");
-        }
-      else
-        gripe_user_supplied_eval ("lsode");
-    }
-
-  return retval;
-}
-
-Matrix
-lsode_user_jacobian (const ColumnVector& x, double t)
-{
-  Matrix retval;
-
-  octave_value_list args;
-  args(1) = t;
-  args(0) = x;
-
-  if (lsode_jac)
-    {
-      octave_value_list tmp = lsode_jac->do_multi_index_op (1, args);
-
-      if (error_state)
-        {
-          gripe_user_supplied_eval ("lsode");
-          return retval;
-        }
-
-      if (tmp.length () > 0 && tmp(0).is_defined ())
-        {
-          if (! warned_jac_imaginary && tmp(0).is_complex_type ())
-            {
-              warning ("lsode: ignoring imaginary part returned from user-supplied jacobian function");
-              warned_jac_imaginary = true;
-            }
-
-          retval = tmp(0).matrix_value ();
-
-          if (error_state || retval.length () == 0)
-            gripe_user_supplied_eval ("lsode");
-        }
-      else
-        gripe_user_supplied_eval ("lsode");
-    }
-
-  return retval;
-}
-
-#define LSODE_ABORT() \
-  return retval
-
-#define LSODE_ABORT1(msg) \
-  do \
-    { \
-      ::error ("lsode: " msg); \
-      LSODE_ABORT (); \
-    } \
-  while (0)
-
-#define LSODE_ABORT2(fmt, arg) \
-  do \
-    { \
-      ::error ("lsode: " fmt, arg); \
-      LSODE_ABORT (); \
-    } \
-  while (0)
-
-DEFUN_DLD (lsode, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {[@var{x}, @var{istate}, @var{msg}] =} lsode (@var{fcn}, @var{x_0}, @var{t})\n\
-@deftypefnx {Loadable Function} {[@var{x}, @var{istate}, @var{msg}] =} lsode (@var{fcn}, @var{x_0}, @var{t}, @var{t_crit})\n\
-Solve the set of differential equations\n\
-@tex\n\
-$$ {dx \\over dt} = f (x, t) $$\n\
-with\n\
-$$ x(t_0) = x_0 $$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-@group\n\
-dx\n\
--- = f (x, t)\n\
-dt\n\
-@end group\n\
-@end example\n\
-\n\
-@noindent\n\
-with\n\
-\n\
-@example\n\
-x(t_0) = x_0\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-The solution is returned in the matrix @var{x}, with each row\n\
-corresponding to an element of the vector @var{t}.  The first element\n\
-of @var{t} should be @math{t_0} and should correspond to the initial\n\
-state of the system @var{x_0}, so that the first row of the output\n\
-is @var{x_0}.\n\
-\n\
-The first argument, @var{fcn}, is a string, inline, or function handle\n\
-that names the function @math{f} to call to compute the vector of right\n\
-hand sides for the set of equations.  The function must have the form\n\
-\n\
-@example\n\
-@var{xdot} = f (@var{x}, @var{t})\n\
-@end example\n\
-\n\
-@noindent\n\
-in which @var{xdot} and @var{x} are vectors and @var{t} is a scalar.\n\
-\n\
-If @var{fcn} is a two-element string array or a two-element cell array\n\
-of strings, inline functions, or function handles, the first element names\n\
-the function @math{f} described above, and the second element names a\n\
-function to compute the Jacobian of @math{f}.  The Jacobian function\n\
-must have the form\n\
-\n\
-@example\n\
-@var{jac} = j (@var{x}, @var{t})\n\
-@end example\n\
-\n\
-@noindent\n\
-in which @var{jac} is the matrix of partial derivatives\n\
-@tex\n\
-$$ J = {\\partial f_i \\over \\partial x_j} = \\left[\\matrix{\n\
-{\\partial f_1 \\over \\partial x_1}\n\
-  & {\\partial f_1 \\over \\partial x_2}\n\
-  & \\cdots\n\
-  & {\\partial f_1 \\over \\partial x_N} \\cr\n\
-{\\partial f_2 \\over \\partial x_1}\n\
-  & {\\partial f_2 \\over \\partial x_2}\n\
-  & \\cdots\n\
-  & {\\partial f_2 \\over \\partial x_N} \\cr\n\
- \\vdots & \\vdots & \\ddots & \\vdots \\cr\n\
-{\\partial f_3 \\over \\partial x_1}\n\
-  & {\\partial f_3 \\over \\partial x_2}\n\
-  & \\cdots\n\
-  & {\\partial f_3 \\over \\partial x_N} \\cr}\\right]$$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-@group\n\
-             | df_1  df_1       df_1 |\n\
-             | ----  ----  ...  ---- |\n\
-             | dx_1  dx_2       dx_N |\n\
-             |                       |\n\
-             | df_2  df_2       df_2 |\n\
-             | ----  ----  ...  ---- |\n\
-      df_i   | dx_1  dx_2       dx_N |\n\
-jac = ---- = |                       |\n\
-      dx_j   |  .    .     .    .    |\n\
-             |  .    .      .   .    |\n\
-             |  .    .       .  .    |\n\
-             |                       |\n\
-             | df_N  df_N       df_N |\n\
-             | ----  ----  ...  ---- |\n\
-             | dx_1  dx_2       dx_N |\n\
-@end group\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-\n\
-The second and third arguments specify the initial state of the system,\n\
-@math{x_0}, and the initial value of the independent variable @math{t_0}.\n\
-\n\
-The fourth argument is optional, and may be used to specify a set of\n\
-times that the ODE solver should not integrate past.  It is useful for\n\
-avoiding difficulties with singularities and points where there is a\n\
-discontinuity in the derivative.\n\
-\n\
-After a successful computation, the value of @var{istate} will be 2\n\
-(consistent with the Fortran version of @sc{lsode}).\n\
-\n\
-If the computation is not successful, @var{istate} will be something\n\
-other than 2 and @var{msg} will contain additional information.\n\
-\n\
-You can use the function @code{lsode_options} to set optional\n\
-parameters for @code{lsode}.\n\
-@seealso{daspk, dassl, dasrt}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  warned_fcn_imaginary = false;
-  warned_jac_imaginary = false;
-
-  unwind_protect frame;
-
-  frame.protect_var (call_depth);
-  call_depth++;
-
-  if (call_depth > 1)
-    LSODE_ABORT1 ("invalid recursive call");
-
-  int nargin = args.length ();
-
-  if (nargin > 2 && nargin < 5 && nargout < 4)
-    {
-      std::string fcn_name, fname, jac_name, jname;
-      lsode_fcn = 0;
-      lsode_jac = 0;
-
-      octave_value f_arg = args(0);
-
-      if (f_arg.is_cell ())
-        {
-          Cell c = f_arg.cell_value ();
-          if (c.length () == 1)
-            f_arg = c(0);
-          else if (c.length () == 2)
-            {
-              if (c(0).is_function_handle () || c(0).is_inline_function ())
-                lsode_fcn = c(0).function_value ();
-              else
-                {
-                  fcn_name = unique_symbol_name ("__lsode_fcn__");
-                  fname = "function y = ";
-                  fname.append (fcn_name);
-                  fname.append (" (x, t) y = ");
-                  lsode_fcn = extract_function
-                    (c(0), "lsode", fcn_name, fname, "; endfunction");
-                }
-
-              if (lsode_fcn)
-                {
-                  if (c(1).is_function_handle () || c(1).is_inline_function ())
-                    lsode_jac = c(1).function_value ();
-                  else
-                    {
-                        jac_name = unique_symbol_name ("__lsode_jac__");
-                        jname = "function jac = ";
-                        jname.append (jac_name);
-                        jname.append (" (x, t) jac = ");
-                        lsode_jac = extract_function
-                          (c(1), "lsode", jac_name, jname, "; endfunction");
-
-                      if (!lsode_jac)
-                        {
-                          if (fcn_name.length ())
-                            clear_function (fcn_name);
-                          lsode_fcn = 0;
-                        }
-                    }
-                }
-            }
-          else
-            LSODE_ABORT1 ("incorrect number of elements in cell array");
-        }
-
-      if (!lsode_fcn && ! f_arg.is_cell ())
-        {
-          if (f_arg.is_function_handle () || f_arg.is_inline_function ())
-            lsode_fcn = f_arg.function_value ();
-          else
-            {
-              switch (f_arg.rows ())
-                {
-                case 1:
-                  do
-                    {
-                      fcn_name = unique_symbol_name ("__lsode_fcn__");
-                      fname = "function y = ";
-                      fname.append (fcn_name);
-                      fname.append (" (x, t) y = ");
-                      lsode_fcn = extract_function
-                        (f_arg, "lsode", fcn_name, fname, "; endfunction");
-                    }
-                  while (0);
-                  break;
-
-                case 2:
-                  {
-                    string_vector tmp = f_arg.all_strings ();
-
-                    if (! error_state)
-                      {
-                        fcn_name = unique_symbol_name ("__lsode_fcn__");
-                        fname = "function y = ";
-                        fname.append (fcn_name);
-                        fname.append (" (x, t) y = ");
-                        lsode_fcn = extract_function
-                          (tmp(0), "lsode", fcn_name, fname, "; endfunction");
-
-                        if (lsode_fcn)
-                          {
-                            jac_name = unique_symbol_name ("__lsode_jac__");
-                            jname = "function jac = ";
-                            jname.append (jac_name);
-                            jname.append (" (x, t) jac = ");
-                            lsode_jac = extract_function
-                              (tmp(1), "lsode", jac_name, jname,
-                              "; endfunction");
-
-                            if (!lsode_jac)
-                              {
-                                if (fcn_name.length ())
-                                  clear_function (fcn_name);
-                                lsode_fcn = 0;
-                              }
-                          }
-                      }
-                  }
-                  break;
-
-                default:
-                  LSODE_ABORT1
-                    ("first arg should be a string or 2-element string array");
-                }
-            }
-        }
-
-      if (error_state || ! lsode_fcn)
-        LSODE_ABORT ();
-
-      ColumnVector state (args(1).vector_value ());
-
-      if (error_state)
-        LSODE_ABORT1 ("expecting state vector as second argument");
-
-      ColumnVector out_times (args(2).vector_value ());
-
-      if (error_state)
-        LSODE_ABORT1 ("expecting output time vector as third argument");
-
-      ColumnVector crit_times;
-
-      int crit_times_set = 0;
-      if (nargin > 3)
-        {
-          crit_times = ColumnVector (args(3).vector_value ());
-
-          if (error_state)
-            LSODE_ABORT1 ("expecting critical time vector as fourth argument");
-
-          crit_times_set = 1;
-        }
-
-      double tzero = out_times (0);
-
-      ODEFunc func (lsode_user_function);
-      if (lsode_jac)
-        func.set_jacobian_function (lsode_user_jacobian);
-
-      LSODE ode (state, tzero, func);
-
-      ode.set_options (lsode_opts);
-
-      Matrix output;
-      if (crit_times_set)
-        output = ode.integrate (out_times, crit_times);
-      else
-        output = ode.integrate (out_times);
-
-      if (fcn_name.length ())
-        clear_function (fcn_name);
-      if (jac_name.length ())
-        clear_function (jac_name);
-
-      if (! error_state)
-        {
-          std::string msg = ode.error_message ();
-
-          retval(2) = msg;
-          retval(1) = static_cast<double> (ode.integration_state ());
-
-          if (ode.integration_ok ())
-            retval(0) = output;
-          else
-            {
-              retval(0) = Matrix ();
-
-              if (nargout < 2)
-                error ("lsode: %s", msg.c_str ());
-            }
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-
-## dassl-1.m
-##
-## Test lsode() function
-##
-## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-##         Comalco Research and Technology
-##         20 May 1998
-##
-## Problem
-##
-##    y1' = -y2,   y1(0) = 1
-##    y2' =  y1,   y2(0) = 0
-##
-## Solution
-##
-##    y1(t) = cos(t)
-##    y2(t) = sin(t)
-##
-%!function xdot = __f (x, t)
-%!  xdot = [-x(2); x(1)];
-%!endfunction
-%!test
-%!
-%! x0 = [1; 0];
-%! xdot0 = [0; 1];
-%! t = (0:1:10)';
-%!
-%! tol = 500 * lsode_options ("relative tolerance");
-%!
-%! x = lsode ("__f", x0, t);
-%!
-%! y = [cos(t), sin(t)];
-%!
-%! assert (x, y, tol);
-
-%!function xdotdot = __f (x, t)
-%!  xdotdot = [x(2); -x(1)];
-%!endfunction
-%!test
-%!
-%! x0 = [1; 0];
-%! t = [0; 2*pi];
-%! tol = 100 * dassl_options ("relative tolerance");
-%!
-%! x = lsode ("__f", x0, t);
-%!
-%! y = [1, 0; 1, 0];
-%!
-%! assert (x, y, tol);
-
-%!function xdot = __f (x, t)
-%!  xdot = x;
-%!endfunction
-%!test
-%!
-%! x0 = 1;
-%! t = [0; 1];
-%! tol = 100 * dassl_options ("relative tolerance");
-%!
-%! x = lsode ("__f", x0, t);
-%!
-%! y = [1; e];
-%!
-%! assert (x, y, tol);
-
-%!test
-%! lsode_options ("absolute tolerance", eps);
-%! assert (lsode_options ("absolute tolerance") == eps);
-
-%!error lsode_options ("foo", 1, 2)
-*/
--- a/src/DLD-FUNCTIONS/lu.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,857 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "CmplxLU.h"
-#include "dbleLU.h"
-#include "fCmplxLU.h"
-#include "floatLU.h"
-#include "SparseCmplxLU.h"
-#include "SparsedbleLU.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-#include "ov-re-sparse.h"
-#include "ov-cx-sparse.h"
-
-template <class MT>
-static octave_value
-get_lu_l (const base_lu<MT>& fact)
-{
-  MT L = fact.L ();
-  if (L.is_square ())
-    return octave_value (L, MatrixType (MatrixType::Lower));
-  else
-    return L;
-}
-
-template <class MT>
-static octave_value
-get_lu_u (const base_lu<MT>& fact)
-{
-  MT U = fact.U ();
-  if (U.is_square () && fact.regular ())
-    return octave_value (U, MatrixType (MatrixType::Upper));
-  else
-    return U;
-}
-
-DEFUN_DLD (lu, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {[@var{L}, @var{U}] =} lu (@var{A})\n\
-@deftypefnx {Loadable Function} {[@var{L}, @var{U}, @var{P}] =} lu (@var{A})\n\
-@deftypefnx {Loadable Function} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} lu (@var{S})\n\
-@deftypefnx {Loadable Function} {[@var{L}, @var{U}, @var{P}, @var{Q}, @var{R}] =} lu (@var{S})\n\
-@deftypefnx {Loadable Function} {[@dots{}] =} lu (@var{S}, @var{thres})\n\
-@deftypefnx {Loadable Function} {@var{y} =} lu (@dots{})\n\
-@deftypefnx {Loadable Function} {[@dots{}] =} lu (@dots{}, \"vector\")\n\
-@cindex LU decomposition\n\
-Compute the LU@tie{}decomposition of @var{A}.  If @var{A} is full\n\
-subroutines from\n\
-@sc{lapack} are used and if @var{A} is sparse then @sc{umfpack} is used.  The\n\
-result is returned in a permuted form, according to the optional return\n\
-value @var{P}.  For example, given the matrix @code{a = [1, 2; 3, 4]},\n\
-\n\
-@example\n\
-[l, u, p] = lu (@var{a})\n\
-@end example\n\
-\n\
-@noindent\n\
-returns\n\
-\n\
-@example\n\
-@group\n\
-l =\n\
-\n\
-  1.00000  0.00000\n\
-  0.33333  1.00000\n\
-\n\
-u =\n\
-\n\
-  3.00000  4.00000\n\
-  0.00000  0.66667\n\
-\n\
-p =\n\
-\n\
-  0  1\n\
-  1  0\n\
-@end group\n\
-@end example\n\
-\n\
-The matrix is not required to be square.\n\
-\n\
-When called with two or three output arguments and a spare input matrix,\n\
-@code{lu} does not attempt to perform sparsity preserving column\n\
-permutations.  Called with a fourth output argument, the sparsity\n\
-preserving column transformation @var{Q} is returned, such that\n\
-@code{@var{P} * @var{A} * @var{Q} = @var{L} * @var{U}}.\n\
-\n\
-Called with a fifth output argument and a sparse input matrix,\n\
-@code{lu} attempts to use a scaling factor @var{R} on the input matrix\n\
-such that\n\
-@code{@var{P} * (@var{R} \\ @var{A}) * @var{Q} = @var{L} * @var{U}}.\n\
-This typically leads to a sparser and more stable factorization.\n\
-\n\
-An additional input argument @var{thres}, that defines the pivoting\n\
-threshold can be given.  @var{thres} can be a scalar, in which case\n\
-it defines the @sc{umfpack} pivoting tolerance for both symmetric and\n\
-unsymmetric cases.  If @var{thres} is a 2-element vector, then the first\n\
-element defines the pivoting tolerance for the unsymmetric @sc{umfpack}\n\
-pivoting strategy and the second for the symmetric strategy.  By default,\n\
-the values defined by @code{spparms} are used ([0.1, 0.001]).\n\
-\n\
-Given the string argument \"vector\", @code{lu} returns the values of @var{P}\n\
-and @var{Q} as vector values, such that for full matrix, @code{@var{A}\n\
-(@var{P},:) = @var{L} * @var{U}}, and @code{@var{R}(@var{P},:) * @var{A}\n\
-(:, @var{Q}) = @var{L} * @var{U}}.\n\
-\n\
-With two output arguments, returns the permuted forms of the upper and\n\
-lower triangular matrices, such that @code{@var{A} = @var{L} * @var{U}}.\n\
-With one output argument @var{y}, then the matrix returned by the @sc{lapack}\n\
-routines is returned.  If the input matrix is sparse then the matrix @var{L}\n\
-is embedded into @var{U} to give a return value similar to the full case.\n\
-For both full and sparse matrices, @code{lu} loses the permutation\n\
-information.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-  int nargin = args.length ();
-  bool issparse = (nargin > 0 && args(0).is_sparse_type ());
-  bool scale = (nargout  == 5);
-
-  if (nargin < 1 || (issparse && (nargin > 3 || nargout > 5))
-      || (!issparse && (nargin > 2 || nargout > 3)))
-    {
-      print_usage ();
-      return retval;
-    }
-
-  bool vecout = false;
-  Matrix thres;
-
-  int n = 1;
-  while (n < nargin && ! error_state)
-    {
-      if (args (n).is_string ())
-        {
-          std::string tmp = args(n++).string_value ();
-
-          if (! error_state )
-            {
-              if (tmp.compare ("vector") == 0)
-                vecout = true;
-              else
-                error ("lu: unrecognized string argument");
-            }
-        }
-      else
-        {
-          Matrix tmp = args(n++).matrix_value ();
-
-          if (! error_state )
-            {
-              if (!issparse)
-                error ("lu: can not define pivoting threshold THRES for full matrices");
-              else if (tmp.nelem () == 1)
-                {
-                  thres.resize (1,2);
-                  thres(0) = tmp(0);
-                  thres(1) = tmp(0);
-                }
-              else if (tmp.nelem () == 2)
-                thres = tmp;
-              else
-                error ("lu: expecting 2-element vector for THRES");
-            }
-        }
-    }
-
-  octave_value arg = args(0);
-
-  octave_idx_type nr = arg.rows ();
-  octave_idx_type nc = arg.columns ();
-
-  int arg_is_empty = empty_arg ("lu", nr, nc);
-
-  if (issparse)
-    {
-      if (arg_is_empty < 0)
-        return retval;
-      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)
-            {
-            case 0:
-            case 1:
-            case 2:
-              {
-                SparseLU fact (m, Qinit, thres, false, true);
-
-                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));
-
-                    retval(0) = octave_value (L,
-                        MatrixType (MatrixType::Permuted_Lower,
-                                    nr, fact.row_perm ()));
-                  }
-              }
-              break;
-
-            case 3:
-              {
-                SparseLU fact (m, Qinit, thres, false, true);
-
-                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;
-
-            case 4:
-            default:
-              {
-                SparseLU fact (m, thres, scale);
-
-                if (scale)
-                  retval(4) = fact.R ();
-
-                if (vecout)
-                  {
-                    retval(3) = fact.Pc_vec ();
-                    retval(2) = fact.Pr_vec ();
-                  }
-                else
-                  {
-                    retval(3) = fact.Pc_mat ();
-                    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 if (arg.is_complex_type ())
-        {
-          SparseComplexMatrix m = arg.sparse_complex_matrix_value ();
-
-          switch (nargout)
-            {
-            case 0:
-            case 1:
-            case 2:
-              {
-                SparseComplexLU fact (m, Qinit, thres, false, true);
-
-                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));
-
-                    retval(0) = octave_value (L,
-                        MatrixType (MatrixType::Permuted_Lower,
-                                    nr, fact.row_perm ()));
-                  }
-              }
-              break;
-
-            case 3:
-              {
-                SparseComplexLU fact (m, Qinit, thres, false, true);
-
-                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;
-
-            case 4:
-            default:
-              {
-                SparseComplexLU fact (m, thres, scale);
-
-                if (scale)
-                  retval(4) = fact.R ();
-
-                if (vecout)
-                  {
-                    retval(3) = fact.Pc_vec ();
-                    retval(2) = fact.Pr_vec ();
-                  }
-                else
-                  {
-                    retval(3) = fact.Pc_mat ();
-                    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
-        gripe_wrong_type_arg ("lu", arg);
-    }
-  else
-    {
-      if (arg_is_empty < 0)
-        return retval;
-      else if (arg_is_empty > 0)
-        return octave_value_list (3, Matrix ());
-
-      if (arg.is_real_type ())
-        {
-          if (arg.is_single_type ())
-            {
-              FloatMatrix m = arg.float_matrix_value ();
-
-              if (! error_state)
-                {
-                  FloatLU fact (m);
-
-                  switch (nargout)
-                    {
-                    case 0:
-                    case 1:
-                      retval(0) = fact.Y ();
-                      break;
-
-                    case 2:
-                      {
-                        PermMatrix P = fact.P ();
-                        FloatMatrix L = P.transpose () * fact.L ();
-                        retval(1) = get_lu_u (fact);
-                        retval(0) = L;
-                      }
-                      break;
-
-                    case 3:
-                    default:
-                      {
-                        if (vecout)
-                          retval(2) = fact.P_vec ();
-                        else
-                          retval(2) = fact.P ();
-                        retval(1) = get_lu_u (fact);
-                        retval(0) = get_lu_l (fact);
-                      }
-                      break;
-                    }
-                }
-            }
-          else
-            {
-              Matrix m = arg.matrix_value ();
-
-              if (! error_state)
-                {
-                  LU fact (m);
-
-                  switch (nargout)
-                    {
-                    case 0:
-                    case 1:
-                      retval(0) = fact.Y ();
-                      break;
-
-                    case 2:
-                      {
-                        PermMatrix P = fact.P ();
-                        Matrix L = P.transpose () * fact.L ();
-                        retval(1) = get_lu_u (fact);
-                        retval(0) = L;
-                      }
-                      break;
-
-                    case 3:
-                    default:
-                      {
-                        if (vecout)
-                          retval(2) = fact.P_vec ();
-                        else
-                          retval(2) = fact.P ();
-                        retval(1) = get_lu_u (fact);
-                        retval(0) = get_lu_l (fact);
-                      }
-                      break;
-                    }
-                }
-            }
-        }
-      else if (arg.is_complex_type ())
-        {
-          if (arg.is_single_type ())
-            {
-              FloatComplexMatrix m = arg.float_complex_matrix_value ();
-
-              if (! error_state)
-                {
-                  FloatComplexLU fact (m);
-
-                  switch (nargout)
-                    {
-                    case 0:
-                    case 1:
-                      retval(0) = fact.Y ();
-                      break;
-
-                    case 2:
-                      {
-                        PermMatrix P = fact.P ();
-                        FloatComplexMatrix L = P.transpose () * fact.L ();
-                        retval(1) = get_lu_u (fact);
-                        retval(0) = L;
-                      }
-                      break;
-
-                    case 3:
-                    default:
-                      {
-                        if (vecout)
-                          retval(2) = fact.P_vec ();
-                        else
-                          retval(2) = fact.P ();
-                        retval(1) = get_lu_u (fact);
-                        retval(0) = get_lu_l (fact);
-                      }
-                      break;
-                    }
-                }
-            }
-          else
-            {
-              ComplexMatrix m = arg.complex_matrix_value ();
-
-              if (! error_state)
-                {
-                  ComplexLU fact (m);
-
-                  switch (nargout)
-                    {
-                    case 0:
-                    case 1:
-                      retval(0) = fact.Y ();
-                      break;
-
-                    case 2:
-                      {
-                        PermMatrix P = fact.P ();
-                        ComplexMatrix L = P.transpose () * fact.L ();
-                        retval(1) = get_lu_u (fact);
-                        retval(0) = L;
-                      }
-                      break;
-
-                    case 3:
-                    default:
-                      {
-                        if (vecout)
-                          retval(2) = fact.P_vec ();
-                        else
-                          retval(2) = fact.P ();
-                        retval(1) = get_lu_u (fact);
-                        retval(0) = get_lu_l (fact);
-                      }
-                      break;
-                    }
-                }
-            }
-        }
-      else
-        gripe_wrong_type_arg ("lu", arg);
-    }
-
-  return retval;
-}
-
-/*
-%!assert(lu ([1, 2; 3, 4]), [3, 4; 1/3, 2/3], eps);
-
-%!test
-%! [l, u] = lu ([1, 2; 3, 4]);
-%! assert (l, [1/3, 1; 1, 0], sqrt (eps));
-%! assert (u, [3, 4; 0, 2/3], sqrt (eps));
-
-%!test
-%! [l, u, p] = lu ([1, 2; 3, 4]);
-%! assert (l, [1, 0; 1/3, 1], sqrt (eps));
-%! assert (u, [3, 4; 0, 2/3], sqrt (eps));
-%! assert (p(:,:), [0, 1; 1, 0], sqrt (eps));
-
-%!test
-%! [l, u, p] = lu ([1, 2; 3, 4], "vector");
-%! assert (l, [1, 0; 1/3, 1], sqrt (eps));
-%! assert (u, [3, 4; 0, 2/3], sqrt (eps));
-%! assert (p, [2;1], sqrt (eps));
-
-%!test
-%! [l, u, p] = lu ([1, 2; 3, 4; 5, 6]);
-%! assert (l, [1, 0; 1/5, 1; 3/5, 1/2], sqrt (eps));
-%! assert (u, [5, 6; 0, 4/5], sqrt (eps));
-%! assert (p(:,:), [0, 0, 1; 1, 0, 0; 0 1 0], sqrt (eps));
-
-%!assert (lu (single ([1, 2; 3, 4])), single ([3, 4; 1/3, 2/3]), eps ("single"))
-
-%!test
-%! [l, u] = lu (single ([1, 2; 3, 4]));
-%! assert (l, single ([1/3, 1; 1, 0]), sqrt (eps ("single")));
-%! assert (u, single ([3, 4; 0, 2/3]), sqrt (eps ("single")));
-
-%!test
-%! [l, u, p] = lu (single ([1, 2; 3, 4]));
-%! assert (l, single ([1, 0; 1/3, 1]), sqrt (eps ("single")));
-%! assert (u, single ([3, 4; 0, 2/3]), sqrt (eps ("single")));
-%! assert (p(:,:), single ([0, 1; 1, 0]), sqrt (eps ("single")));
-
-%!test
-%! [l, u, p] = lu (single ([1, 2; 3, 4]), "vector");
-%! assert (l, single ([1, 0; 1/3, 1]), sqrt (eps ("single")));
-%! assert (u, single ([3, 4; 0, 2/3]), sqrt (eps ("single")));
-%! assert (p, single ([2;1]), sqrt (eps ("single")));
-
-%!test
-%! [l u p] = lu (single ([1, 2; 3, 4; 5, 6]));
-%! assert (l, single ([1, 0; 1/5, 1; 3/5, 1/2]), sqrt (eps ("single")));
-%! assert (u, single ([5, 6; 0, 4/5]), sqrt (eps ("single")));
-%! assert (p(:,:), single ([0, 0, 1; 1, 0, 0; 0 1 0]), sqrt (eps ("single")));
-
-%!error lu ()
-%!error <can not define pivoting threshold> lu ([1, 2; 3, 4], 2)
-*/
-
-static
-bool check_lu_dims (const octave_value& l, const octave_value& u,
-                    const octave_value& p)
-{
-  octave_idx_type m = l.rows (), k = u.rows (), n = u.columns ();
-  return ((l.ndims () == 2 && u.ndims () == 2 && k == l.columns ())
-            && k == std::min (m, n) &&
-            (p.is_undefined () || p.rows () == m));
-}
-
-DEFUN_DLD (luupdate, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {[@var{L}, @var{U}] =} luupdate (@var{L}, @var{U}, @var{x}, @var{y})\n\
-@deftypefnx {Loadable Function} {[@var{L}, @var{U}, @var{P}] =} luupdate (@var{L}, @var{U}, @var{P}, @var{x}, @var{y})\n\
-Given an LU@tie{}factorization of a real or complex matrix\n\
-@w{@var{A} = @var{L}*@var{U}}, @var{L}@tie{}lower unit trapezoidal and\n\
-@var{U}@tie{}upper trapezoidal, return the LU@tie{}factorization\n\
-of @w{@var{A} + @var{x}*@var{y}.'}, where @var{x} and @var{y} are\n\
-column vectors (rank-1 update) or matrices with equal number of columns\n\
-(rank-k update).\n\
-Optionally, row-pivoted updating can be used by supplying\n\
-a row permutation (pivoting) matrix @var{P};\n\
-in that case, an updated permutation matrix is returned.\n\
-Note that if @var{L}, @var{U}, @var{P} is a pivoted LU@tie{}factorization\n\
-as obtained by @code{lu}:\n\
-\n\
-@example\n\
-[@var{L}, @var{U}, @var{P}] = lu (@var{A});\n\
-@end example\n\
-\n\
-@noindent\n\
-then a factorization of @xcode{@var{A}+@var{x}*@var{y}.'} can be obtained\n\
-either as\n\
-\n\
-@example\n\
-[@var{L1}, @var{U1}] = lu (@var{L}, @var{U}, @var{P}*@var{x}, @var{y})\n\
-@end example\n\
-\n\
-@noindent\n\
-or\n\
-\n\
-@example\n\
-[@var{L1}, @var{U1}, @var{P1}] = lu (@var{L}, @var{U}, @var{P}, @var{x}, @var{y})\n\
-@end example\n\
-\n\
-The first form uses the unpivoted algorithm, which is faster, but less\n\
-stable.  The second form uses a slower pivoted algorithm, which is more\n\
-stable.\n\
-\n\
-The matrix case is done as a sequence of rank-1 updates;\n\
-thus, for large enough k, it will be both faster and more accurate to\n\
-recompute the factorization from scratch.\n\
-@seealso{lu, qrupdate, cholupdate}\n\
-@end deftypefn")
-{
-  octave_idx_type nargin = args.length ();
-  octave_value_list retval;
-
-  bool pivoted = nargin == 5;
-
-  if (nargin != 4 && nargin != 5)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value argl = args(0);
-  octave_value argu = args(1);
-  octave_value argp = pivoted ? args(2) : octave_value ();
-  octave_value argx = args(2 + pivoted);
-  octave_value argy = args(3 + pivoted);
-
-  if (argl.is_numeric_type () && argu.is_numeric_type ()
-      && argx.is_numeric_type () && argy.is_numeric_type ()
-      && (! pivoted || argp.is_perm_matrix ()))
-    {
-      if (check_lu_dims (argl, argu, argp))
-        {
-          PermMatrix P = (pivoted
-                          ? argp.perm_matrix_value ()
-                          : PermMatrix::eye (argl.rows ()));
-
-          if (argl.is_real_type ()
-              && argu.is_real_type ()
-              && argx.is_real_type ()
-              && argy.is_real_type ())
-            {
-              // all real case
-              if (argl.is_single_type ()
-                  || argu.is_single_type ()
-                  || argx.is_single_type ()
-                  || argy.is_single_type ())
-                {
-                  FloatMatrix L = argl.float_matrix_value ();
-                  FloatMatrix U = argu.float_matrix_value ();
-                  FloatMatrix x = argx.float_matrix_value ();
-                  FloatMatrix y = argy.float_matrix_value ();
-
-                  FloatLU fact (L, U, P);
-                  if (pivoted)
-                    fact.update_piv (x, y);
-                  else
-                    fact.update (x, y);
-
-                  if (pivoted)
-                    retval(2) = fact.P ();
-                  retval(1) = get_lu_u (fact);
-                  retval(0) = get_lu_l (fact);
-                }
-              else
-                {
-                  Matrix L = argl.matrix_value ();
-                  Matrix U = argu.matrix_value ();
-                  Matrix x = argx.matrix_value ();
-                  Matrix y = argy.matrix_value ();
-
-                  LU fact (L, U, P);
-                  if (pivoted)
-                    fact.update_piv (x, y);
-                  else
-                    fact.update (x, y);
-
-                  if (pivoted)
-                    retval(2) = fact.P ();
-                  retval(1) = get_lu_u (fact);
-                  retval(0) = get_lu_l (fact);
-                }
-            }
-          else
-            {
-              // complex case
-              if (argl.is_single_type ()
-                  || argu.is_single_type ()
-                  || argx.is_single_type ()
-                  || argy.is_single_type ())
-                {
-                  FloatComplexMatrix L = argl.float_complex_matrix_value ();
-                  FloatComplexMatrix U = argu.float_complex_matrix_value ();
-                  FloatComplexMatrix x = argx.float_complex_matrix_value ();
-                  FloatComplexMatrix y = argy.float_complex_matrix_value ();
-
-                  FloatComplexLU fact (L, U, P);
-                  if (pivoted)
-                    fact.update_piv (x, y);
-                  else
-                    fact.update (x, y);
-
-                  if (pivoted)
-                    retval(2) = fact.P ();
-                  retval(1) = get_lu_u (fact);
-                  retval(0) = get_lu_l (fact);
-                }
-              else
-                {
-                  ComplexMatrix L = argl.complex_matrix_value ();
-                  ComplexMatrix U = argu.complex_matrix_value ();
-                  ComplexMatrix x = argx.complex_matrix_value ();
-                  ComplexMatrix y = argy.complex_matrix_value ();
-
-                  ComplexLU fact (L, U, P);
-                  if (pivoted)
-                    fact.update_piv (x, y);
-                  else
-                    fact.update (x, y);
-
-                  if (pivoted)
-                    retval(2) = fact.P ();
-                  retval(1) = get_lu_u (fact);
-                  retval(0) = get_lu_l (fact);
-                }
-            }
-        }
-      else
-        error ("luupdate: dimension mismatch");
-    }
-  else
-    error ("luupdate: L, U, X, and Y must be numeric");
-
-  return retval;
-}
-
-/*
-%!shared A, u, v, Ac, uc, vc
-%! A = [0.091364  0.613038  0.999083;
-%!      0.594638  0.425302  0.603537;
-%!      0.383594  0.291238  0.085574;
-%!      0.265712  0.268003  0.238409;
-%!      0.669966  0.743851  0.445057 ];
-%!
-%! u = [0.85082;
-%!      0.76426;
-%!      0.42883;
-%!      0.53010;
-%!      0.80683 ];
-%!
-%! v = [0.98810;
-%!      0.24295;
-%!      0.43167 ];
-%!
-%! Ac = [0.620405 + 0.956953i  0.480013 + 0.048806i  0.402627 + 0.338171i;
-%!       0.589077 + 0.658457i  0.013205 + 0.279323i  0.229284 + 0.721929i;
-%!       0.092758 + 0.345687i  0.928679 + 0.241052i  0.764536 + 0.832406i;
-%!       0.912098 + 0.721024i  0.049018 + 0.269452i  0.730029 + 0.796517i;
-%!       0.112849 + 0.603871i  0.486352 + 0.142337i  0.355646 + 0.151496i ];
-%!
-%! uc = [0.20351 + 0.05401i;
-%!       0.13141 + 0.43708i;
-%!       0.29808 + 0.08789i;
-%!       0.69821 + 0.38844i;
-%!       0.74871 + 0.25821i ];
-%!
-%! vc = [0.85839 + 0.29468i;
-%!       0.20820 + 0.93090i;
-%!       0.86184 + 0.34689i ];
-%!
-
-%!testif HAVE_QRUPDATE_LUU
-%! [L,U,P] = lu (A);
-%! [L,U] = luupdate (L,U,P*u,v);
-%! assert (norm (vec (tril (L)-L), Inf) == 0);
-%! assert (norm (vec (triu (U)-U), Inf) == 0);
-%! assert (norm (vec (P'*L*U - A - u*v.'), Inf) < norm (A)*1e1*eps);
-%!
-%!testif HAVE_QRUPDATE_LUU
-%! [L,U,P] = lu (Ac);
-%! [L,U] = luupdate (L,U,P*uc,vc);
-%! assert (norm (vec (tril (L)-L), Inf) == 0);
-%! assert (norm (vec (triu (U)-U), Inf) == 0);
-%! assert (norm (vec (P'*L*U - Ac - uc*vc.'), Inf) < norm (Ac)*1e1*eps);
-
-%!testif HAVE_QRUPDATE_LUU
-%! [L,U,P] = lu (single (A));
-%! [L,U] = luupdate (L,U,P*single (u), single (v));
-%! assert (norm (vec (tril (L)-L), Inf) == 0);
-%! assert (norm (vec (triu (U)-U), Inf) == 0);
-%! assert (norm (vec (P'*L*U - single (A) - single (u)*single (v).'), Inf) < norm (single (A))*1e1*eps ("single"));
-%!
-%!testif HAVE_QRUPDATE_LUU
-%! [L,U,P] = lu (single (Ac));
-%! [L,U] = luupdate (L,U,P*single (uc),single (vc));
-%! assert (norm (vec (tril (L)-L), Inf) == 0);
-%! assert (norm (vec (triu (U)-U), Inf) == 0);
-%! assert (norm (vec (P'*L*U - single (Ac) - single (uc)*single (vc).'), Inf) < norm (single (Ac))*1e1*eps ("single"));
-
-%!testif HAVE_QRUPDATE_LUU
-%! [L,U,P] = lu (A);
-%! [L,U,P] = luupdate (L,U,P,u,v);
-%! assert (norm (vec (tril (L)-L), Inf) == 0);
-%! assert (norm (vec (triu (U)-U), Inf) == 0);
-%! assert (norm (vec (P'*L*U - A - u*v.'), Inf) < norm (A)*1e1*eps);
-%!
-%!testif HAVE_QRUPDATE_LUU
-%! [L,U,P] = lu (Ac);
-%! [L,U,P] = luupdate (L,U,P,uc,vc);
-%! assert (norm (vec (tril (L)-L), Inf) == 0);
-%! assert (norm (vec (triu (U)-U), Inf) == 0);
-%! assert (norm (vec (P'*L*U - Ac - uc*vc.'), Inf) < norm (Ac)*1e1*eps);
-
-%!testif HAVE_QRUPDATE_LUU
-%! [L,U,P] = lu (single (A));
-%! [L,U,P] = luupdate (L,U,P,single (u),single (v));
-%! assert (norm (vec (tril (L)-L), Inf) == 0);
-%! assert (norm (vec (triu (U)-U), Inf) == 0);
-%! assert (norm (vec (P'*L*U - single (A) - single (u)*single (v).'), Inf) < norm (single (A))*1e1*eps ("single"));
-%!
-%!testif HAVE_QRUPDATE_LUU
-%! [L,U,P] = lu (single (Ac));
-%! [L,U,P] = luupdate (L,U,P,single (uc),single (vc));
-%! assert (norm (vec (tril (L)-L), Inf) == 0);
-%! assert (norm (vec (triu (U)-U), Inf) == 0);
-%! assert (norm (vec (P'*L*U - single (Ac) - single (uc)*single (vc).'), Inf) < norm (single (Ac))*1e1*eps ("single"));
-*/
--- a/src/DLD-FUNCTIONS/luinc.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,383 +0,0 @@
-/*
-
-Copyright (C) 2005-2012 David Bateman
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-#include "oct-map.h"
-
-#include "MatrixType.h"
-#include "SparseCmplxLU.h"
-#include "SparsedbleLU.h"
-#include "ov-re-sparse.h"
-#include "ov-cx-sparse.h"
-
-DEFUN_DLD (luinc, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} luinc (@var{A}, '0')\n\
-@deftypefnx {Loadable Function} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} luinc (@var{A}, @var{droptol})\n\
-@deftypefnx {Loadable Function} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} luinc (@var{A}, @var{opts})\n\
-@cindex LU decomposition\n\
-Produce the incomplete LU@tie{}factorization of the sparse matrix @var{A}.\n\
-Two types of incomplete factorization are possible, and the type\n\
-is determined by the second argument to @code{luinc}.\n\
-\n\
-Called with a second argument of '0', the zero-level incomplete\n\
-LU@tie{}factorization is produced.  This creates a factorization of @var{A}\n\
-where the position of the non-zero arguments correspond to the same\n\
-positions as in the matrix @var{A}.\n\
-\n\
-Alternatively, the fill-in of the incomplete LU@tie{}factorization can\n\
-be controlled through the variable @var{droptol} or the structure\n\
-@var{opts}.  The @sc{umfpack} multifrontal factorization code by Tim A.\n\
-Davis is used for the incomplete LU@tie{}factorization, (availability\n\
-@url{http://www.cise.ufl.edu/research/sparse/umfpack/})\n\
-\n\
-@var{droptol} determines the values below which the values in the\n\
-LU@tie{} factorization are dropped and replaced by zero.  It must be a\n\
-positive scalar, and any values in the factorization whose absolute value\n\
-are less than this value are dropped, expect if leaving them increase the\n\
-sparsity of the matrix.  Setting @var{droptol} to zero results in a complete\n\
-LU@tie{}factorization which is the default.\n\
-\n\
-@var{opts} is a structure containing one or more of the fields\n\
-\n\
-@table @code\n\
-@item droptol\n\
-The drop tolerance as above.  If @var{opts} only contains @code{droptol}\n\
-then this is equivalent to using the variable @var{droptol}.\n\
-\n\
-@item milu\n\
-A logical variable flagging whether to use the modified incomplete\n\
-LU@tie{} factorization.  In the case that @code{milu} is true, the dropped\n\
-values are subtracted from the diagonal of the matrix @var{U} of the\n\
-factorization.  The default is @code{false}.\n\
-\n\
-@item udiag\n\
-A logical variable that flags whether zero elements on the diagonal of\n\
-@var{U} should be replaced with @var{droptol} to attempt to avoid singular\n\
-factors.  The default is @code{false}.\n\
-\n\
-@item thresh\n\
-Defines the pivot threshold in the interval [0,1].  Values outside that\n\
-range are ignored.\n\
-@end table\n\
-\n\
-All other fields in @var{opts} are ignored.  The outputs from @code{luinc}\n\
-are the same as for @code{lu}.\n\
-\n\
-Given the string argument \"vector\", @code{luinc} returns the values of\n\
-@var{p} @var{q} as vector values.\n\
-@seealso{sparse, lu}\n\
-@end deftypefn")
-{
-  int nargin = args.length ();
-  octave_value_list retval;
-
-  if (nargin == 0)
-    print_usage ();
-  else if (nargin < 2 || nargin > 3)
-    error ("luinc: incorrect number of arguments");
-  else
-    {
-      bool zero_level = false;
-      bool milu = false;
-      bool udiag = false;
-      Matrix thresh;
-      double droptol = -1.;
-      bool vecout = false;
-
-      if (args(1).is_string ())
-        {
-          if (args(1).string_value () == "0")
-            zero_level = true;
-          else
-            error ("luinc: unrecognized string argument");
-        }
-      else if (args(1).is_map ())
-        {
-          octave_scalar_map map = args(1).scalar_map_value ();
-
-          if (! error_state)
-            {
-              octave_value tmp;
-
-              tmp = map.getfield ("droptol");
-              if (tmp.is_defined ())
-                droptol = tmp.double_value ();
-
-              tmp = map.getfield ("milu");
-              if (tmp.is_defined ())
-                {
-                  double val = tmp.double_value ();
-
-                  milu = (val == 0. ? false : true);
-                }
-
-              tmp = map.getfield ("udiag");
-              if (tmp.is_defined ())
-                {
-                  double val = tmp.double_value ();
-
-                  udiag = (val == 0. ? false : true);
-                }
-
-              tmp = map.getfield ("thresh");
-              if (tmp.is_defined ())
-                {
-                  thresh = tmp.matrix_value ();
-
-                  if (thresh.nelem () == 1)
-                    {
-                      thresh.resize (1,2);
-                      thresh(1) = thresh(0);
-                    }
-                  else if (thresh.nelem () != 2)
-                    {
-                      error ("luinc: expecting 2-element vector for thresh");
-                      return retval;
-                    }
-                }
-            }
-          else
-            {
-              error ("luinc: OPTS must be a scalar structure");
-              return retval;
-            }
-        }
-      else
-        droptol = args(1).double_value ();
-
-      if (nargin == 3)
-        {
-          std::string tmp = args(2).string_value ();
-
-          if (! error_state )
-            {
-              if (tmp.compare ("vector") == 0)
-                vecout = true;
-              else
-                error ("luinc: unrecognized string argument");
-            }
-        }
-
-      // FIXME Add code for zero-level factorization
-      if (zero_level)
-        error ("luinc: zero-level factorization not implemented");
-
-      if (!error_state)
-        {
-          if (args(0).type_name () == "sparse matrix")
-            {
-              SparseMatrix sm = args(0).sparse_matrix_value ();
-              octave_idx_type sm_nr = sm.rows ();
-              octave_idx_type sm_nc = sm.cols ();
-              ColumnVector Qinit (sm_nc);
-
-              for (octave_idx_type i = 0; i < sm_nc; i++)
-                Qinit (i) = i;
-
-              if (! error_state)
-                {
-                  switch (nargout)
-                    {
-                    case 0:
-                    case 1:
-                    case 2:
-                      {
-                        SparseLU fact (sm, Qinit, thresh, false, true, droptol,
-                                       milu, udiag);
-
-                        if (! error_state)
-                          {
-                            SparseMatrix P = fact.Pr ();
-                            SparseMatrix L = P.transpose () * fact.L ();
-                            retval(1) = octave_value (fact.U (),
-                                                      MatrixType (MatrixType::Upper));
-                            retval(0) = octave_value (L, MatrixType
-                                                      (MatrixType::Permuted_Lower,
-                                                       sm_nr, fact.row_perm ()));
-                          }
-                      }
-                      break;
-
-                    case 3:
-                      {
-                        SparseLU fact (sm, Qinit, thresh, false, true, droptol,
-                                       milu, udiag);
-
-                        if (! error_state)
-                          {
-                            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;
-
-                    case 4:
-                    default:
-                      {
-                        SparseLU fact (sm, Qinit, thresh, false, false, droptol,
-                                       milu, udiag);
-
-                        if (! error_state)
-                          {
-                            if (vecout)
-                              {
-                                retval(3) = fact.Pc_vec ();
-                                retval(2) = fact.Pr_vec ();
-                              }
-                            else
-                              {
-                                retval(3) = fact.Pc_mat ();
-                                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 if (args(0).type_name () == "sparse complex matrix")
-            {
-              SparseComplexMatrix sm =
-                args(0).sparse_complex_matrix_value ();
-              octave_idx_type sm_nr = sm.rows ();
-              octave_idx_type sm_nc = sm.cols ();
-              ColumnVector Qinit (sm_nc);
-
-              for (octave_idx_type i = 0; i < sm_nc; i++)
-                Qinit (i) = i;
-
-              if (! error_state)
-                {
-                  switch (nargout)
-                    {
-                    case 0:
-                    case 1:
-                    case 2:
-                      {
-                        SparseComplexLU fact (sm, Qinit, thresh, false, true,
-                                              droptol, milu, udiag);
-
-
-                        if (! error_state)
-                          {
-                            SparseMatrix P = fact.Pr ();
-                            SparseComplexMatrix L = P.transpose () * fact.L ();
-                            retval(1) = octave_value (fact.U (),
-                                                      MatrixType (MatrixType::Upper));
-                            retval(0) = octave_value (L, MatrixType
-                                                      (MatrixType::Permuted_Lower,
-                                                       sm_nr, fact.row_perm ()));
-                          }
-                      }
-                      break;
-
-                    case 3:
-                      {
-                        SparseComplexLU fact (sm, Qinit, thresh, false, true,
-                                              droptol, milu, udiag);
-
-                        if (! error_state)
-                          {
-                            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;
-
-                    case 4:
-                    default:
-                      {
-                        SparseComplexLU fact (sm, Qinit, thresh, false, false,
-                                              droptol, milu, udiag);
-
-                        if (! error_state)
-                          {
-                            if (vecout)
-                              {
-                                retval(3) = fact.Pc_vec ();
-                                retval(2) = fact.Pr_vec ();
-                              }
-                            else
-                              {
-                                retval(3) = fact.Pc_mat ();
-                                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
-            error ("luinc: matrix A must be sparse");
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!testif HAVE_UMFPACK
-%! a = sparse ([1,2,0,0;0,1,2,0;1e-14,0,3,0;0,0,0,1]);
-%! [l,u] = luinc (a, 1e-10);
-%! assert (l*u, sparse ([1,2,0,0;0,1,2,0;0,0,3,0;0,0,0,1]), 1e-10);
-%! opts.droptol = 1e-10;
-%! [l,u] = luinc (a, opts);
-%! assert (l*u, sparse ([1,2,0,0;0,1,2,0;0,0,3,0;0,0,0,1]), 1e-10);
-
-%!testif HAVE_UMFPACK
-%! a = sparse ([1i,2,0,0;0,1,2,0;1e-14,0,3,0;0,0,0,1]);
-%! [l,u] = luinc (a, 1e-10);
-%! assert (l*u, sparse ([1i,2,0,0;0,1,2,0;0,0,3,0;0,0,0,1]), 1e-10);
-%! opts.droptol = 1e-10;
-%! [l,u] = luinc (a, opts);
-%! assert (l*u, sparse ([1i,2,0,0;0,1,2,0;0,0,3,0;0,0,0,1]), 1e-10);
-*/
--- a/src/DLD-FUNCTIONS/matrix_type.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,621 +0,0 @@
-/*
-
-Copyright (C) 2005-2012 David Bateman
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <algorithm>
-
-#include "ov.h"
-#include "defun-dld.h"
-#include "error.h"
-#include "ov-re-mat.h"
-#include "ov-cx-mat.h"
-#include "ov-re-sparse.h"
-#include "ov-cx-sparse.h"
-#include "MatrixType.h"
-#include "oct-locbuf.h"
-
-DEFUN_DLD (matrix_type, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{type} =} matrix_type (@var{A})\n\
-@deftypefnx {Loadable Function} {@var{type} =} matrix_type (@var{A}, \"nocompute\")\n\
-@deftypefnx {Loadable Function} {@var{A} =} matrix_type (@var{A}, @var{type})\n\
-@deftypefnx {Loadable Function} {@var{A} =} matrix_type (@var{A}, \"upper\", @var{perm})\n\
-@deftypefnx {Loadable Function} {@var{A} =} matrix_type (@var{A}, \"lower\", @var{perm})\n\
-@deftypefnx {Loadable Function} {@var{A} =} matrix_type (@var{A}, \"banded\", @var{nl}, @var{nu})\n\
-Identify the matrix type or mark a matrix as a particular type.  This allows\n\
-more rapid solutions of linear equations involving @var{A} to be performed.\n\
-Called with a single argument, @code{matrix_type} returns the type of the\n\
-matrix and caches it for future use.  Called with more than one argument,\n\
-@code{matrix_type} allows the type of the matrix to be defined.\n\
-\n\
-If the option \"nocompute\" is given, the function will not attempt to guess\n\
-the type if it is still unknown.  This is useful for debugging purposes.\n\
-\n\
-The possible matrix types depend on whether the matrix is full or sparse, and\n\
-can be one of the following\n\
-\n\
-@table @asis\n\
-@item \"unknown\"\n\
-Remove any previously cached matrix type, and mark type as unknown.\n\
-\n\
-@item \"full\"\n\
-Mark the matrix as full.\n\
-\n\
-@item \"positive definite\"\n\
-Probable full positive definite matrix.\n\
-\n\
-@item \"diagonal\"\n\
-Diagonal matrix.  (Sparse matrices only)\n\
-\n\
-@item \"permuted diagonal\"\n\
-Permuted Diagonal matrix.  The permutation does not need to be specifically\n\
-indicated, as the structure of the matrix explicitly gives this.  (Sparse\n\
-matrices only)\n\
-\n\
-@item \"upper\"\n\
-Upper triangular.  If the optional third argument @var{perm} is given, the\n\
-matrix is assumed to be a permuted upper triangular with the permutations\n\
-defined by the vector @var{perm}.\n\
-\n\
-@item \"lower\"\n\
-Lower triangular.  If the optional third argument @var{perm} is given, the\n\
-matrix is assumed to be a permuted lower triangular with the permutations\n\
-defined by the vector @var{perm}.\n\
-\n\
-@item \"banded\"\n\
-@itemx \"banded positive definite\"\n\
-Banded matrix with the band size of @var{nl} below the diagonal and @var{nu}\n\
-above it.  If @var{nl} and @var{nu} are 1, then the matrix is tridiagonal and\n\
-treated with specialized code.  In addition the matrix can be marked as\n\
-probably a positive definite.  (Sparse matrices only)\n\
-\n\
-@item \"singular\"\n\
-The matrix is assumed to be singular and will be treated with a minimum norm\n\
-solution.\n\
-\n\
-@end table\n\
-\n\
-Note that the matrix type will be discovered automatically on the first\n\
-attempt to solve a linear equation involving @var{A}.  Therefore\n\
-@code{matrix_type} is only useful to give Octave hints of the matrix type.\n\
-Incorrectly defining the matrix type will result in incorrect results from\n\
-solutions of linear equations; it is entirely @strong{the responsibility of\n\
-the user} to correctly identify the matrix type.\n\
-\n\
-Also, the test for positive definiteness is a low-cost test for a Hermitian\n\
-matrix with a real positive diagonal.  This does not guarantee that the\n\
-matrix is positive definite, but only that it is a probable candidate.  When\n\
-such a matrix is factorized, a Cholesky@tie{}factorization is first\n\
-attempted, and if that fails the matrix is then treated with an\n\
-LU@tie{}factorization.  Once the matrix has been factorized,\n\
-@code{matrix_type} will return the correct classification of the matrix.\n\
-@end deftypefn")
-{
-  int nargin = args.length ();
-  octave_value retval;
-
-  if (nargin == 0)
-    print_usage ();
-  else if (nargin > 4)
-    error ("matrix_type: incorrect number of arguments");
-  else
-    {
-      bool autocomp = true;
-      if (nargin == 2 && args(1).is_string () && args(1).string_value () == "nocompute")
-        {
-          nargin = 1;
-          autocomp = false;
-        }
-
-      if (args(0).is_scalar_type ())
-        {
-          if (nargin == 1)
-            retval = octave_value ("Diagonal");
-          else
-            retval = args(0);
-        }
-      else if (args(0).is_sparse_type ())
-        {
-          if (nargin == 1)
-            {
-              MatrixType mattyp;
-
-              if (args(0).is_complex_type ())
-                {
-                  mattyp = args(0).matrix_type ();
-
-                  if (mattyp.is_unknown () && autocomp )
-                    {
-                      SparseComplexMatrix m =
-                        args(0).sparse_complex_matrix_value ();
-                      if (!error_state)
-                        {
-                          mattyp = MatrixType (m);
-                          args(0).matrix_type (mattyp);
-                        }
-                    }
-                }
-              else
-                {
-                  mattyp = args(0).matrix_type ();
-
-                  if (mattyp.is_unknown () && autocomp)
-                    {
-                      SparseMatrix m = args(0).sparse_matrix_value ();
-                      if (!error_state)
-                        {
-                          mattyp = MatrixType (m);
-                          args(0).matrix_type (mattyp);
-                        }
-                    }
-                }
-
-              int typ = mattyp.type ();
-
-              if (typ == MatrixType::Diagonal)
-                retval = octave_value ("Diagonal");
-              else if (typ == MatrixType::Permuted_Diagonal)
-                retval = octave_value ("Permuted Diagonal");
-              else if (typ == MatrixType::Upper)
-                retval = octave_value ("Upper");
-              else if (typ == MatrixType::Permuted_Upper)
-                retval = octave_value ("Permuted Upper");
-              else if (typ == MatrixType::Lower)
-                retval = octave_value ("Lower");
-              else if (typ == MatrixType::Permuted_Lower)
-                retval = octave_value ("Permuted Lower");
-              else if (typ == MatrixType::Banded)
-                retval = octave_value ("Banded");
-              else if (typ == MatrixType::Banded_Hermitian)
-                retval = octave_value ("Banded Positive Definite");
-              else if (typ == MatrixType::Tridiagonal)
-                retval = octave_value ("Tridiagonal");
-              else if (typ == MatrixType::Tridiagonal_Hermitian)
-                retval = octave_value ("Tridiagonal Positive Definite");
-              else if (typ == MatrixType::Hermitian)
-                retval = octave_value ("Positive Definite");
-              else if (typ == MatrixType::Rectangular)
-                {
-                  if (args(0).rows () == args(0).columns ())
-                    retval = octave_value ("Singular");
-                  else
-                    retval = octave_value ("Rectangular");
-                }
-              else if (typ == MatrixType::Full)
-                retval = octave_value ("Full");
-              else
-                retval = octave_value ("Unknown");
-            }
-          else
-            {
-              // Ok, we're changing the matrix type
-              std::string str_typ = args(1).string_value ();
-
-              // FIXME -- why do I have to explicitly call the constructor?
-              MatrixType mattyp = MatrixType ();
-
-              octave_idx_type nl = 0;
-              octave_idx_type nu = 0;
-
-              if (error_state)
-                error ("matrix_type: TYPE must be a string");
-              else
-                {
-                  // Use STL function to convert to lower case
-                  std::transform (str_typ.begin (), str_typ.end (),
-                                  str_typ.begin (), tolower);
-
-                  if (str_typ == "diagonal")
-                    mattyp.mark_as_diagonal ();
-                  if (str_typ == "permuted diagonal")
-                    mattyp.mark_as_permuted_diagonal ();
-                  else if (str_typ == "upper")
-                    mattyp.mark_as_upper_triangular ();
-                  else if (str_typ == "lower")
-                    mattyp.mark_as_lower_triangular ();
-                  else if (str_typ == "banded" || str_typ == "banded positive definite")
-                    {
-                      if (nargin != 4)
-                        error ("matrix_type: banded matrix type requires 4 arguments");
-                      else
-                        {
-                          nl = args(2).nint_value ();
-                          nu = args(3).nint_value ();
-
-                          if (error_state)
-                            error ("matrix_type: band size NL, NU must be integers");
-                          else
-                            {
-                              if (nl == 1 && nu == 1)
-                                mattyp.mark_as_tridiagonal ();
-                              else
-                                mattyp.mark_as_banded (nu, nl);
-
-                              if (str_typ == "banded positive definite")
-                                mattyp.mark_as_symmetric ();
-                            }
-                        }
-                    }
-                  else if (str_typ == "positive definite")
-                    {
-                      mattyp.mark_as_full ();
-                      mattyp.mark_as_symmetric ();
-                    }
-                  else if (str_typ == "singular")
-                    mattyp.mark_as_rectangular ();
-                  else if (str_typ == "full")
-                    mattyp.mark_as_full ();
-                  else if (str_typ == "unknown")
-                    mattyp.invalidate_type ();
-                  else
-                    error ("matrix_type: Unknown matrix type %s", str_typ.c_str ());
-
-                  if (! error_state)
-                    {
-                      if (nargin == 3 && (str_typ == "upper" || str_typ == "lower"))
-                        {
-                          const ColumnVector perm =
-                            ColumnVector (args (2).vector_value ());
-
-                          if (error_state)
-                            error ("matrix_type: Invalid permutation vector PERM");
-                          else
-                            {
-                              octave_idx_type len = perm.length ();
-                              dim_vector dv = args(0).dims ();
-
-                              if (len != dv(0))
-                                error ("matrix_type: Invalid permutation vector PERM");
-                              else
-                                {
-                                  OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len);
-
-                                  for (octave_idx_type i = 0; i < len; i++)
-                                    p[i] = static_cast<octave_idx_type> (perm (i)) - 1;
-
-                                  if (str_typ == "upper")
-                                    mattyp.mark_as_permuted (len, p);
-                                  else
-                                    mattyp.mark_as_permuted (len, p);
-                                }
-                            }
-                        }
-                      else if (nargin != 2 && str_typ != "banded positive definite" &&
-                               str_typ != "banded")
-                        error ("matrix_type: Invalid number of arguments");
-
-                      if (! error_state)
-                        {
-                          // Set the matrix type
-                          if (args(0).is_complex_type ())
-                            retval =
-                              octave_value (args(0).sparse_complex_matrix_value (),
-                                            mattyp);
-                          else
-                            retval = octave_value (args(0).sparse_matrix_value (),
-                                                   mattyp);
-                        }
-                    }
-                }
-            }
-        }
-      else
-        {
-          if (nargin == 1)
-            {
-              MatrixType mattyp;
-
-              if (args(0).is_complex_type ())
-                {
-                  mattyp = args(0).matrix_type ();
-
-                  if (mattyp.is_unknown () && autocomp)
-                    {
-                      if (args(0).is_single_type ())
-                        {
-                          FloatComplexMatrix m = args(0).float_complex_matrix_value ();
-                          if (!error_state)
-                            {
-                              mattyp = MatrixType (m);
-                              args(0).matrix_type (mattyp);
-                            }
-                        }
-                      else
-                        {
-                          ComplexMatrix m = args(0).complex_matrix_value ();
-                          if (!error_state)
-                            {
-                              mattyp = MatrixType (m);
-                              args(0).matrix_type (mattyp);
-                            }
-                        }
-                    }
-                }
-              else
-                {
-                  mattyp = args(0).matrix_type ();
-
-                  if (mattyp.is_unknown () && autocomp)
-                    {
-                      if (args(0).is_single_type ())
-                        {
-                          FloatMatrix m = args(0).float_matrix_value ();
-                          if (!error_state)
-                            {
-                              mattyp = MatrixType (m);
-                              args(0).matrix_type (mattyp);
-                            }
-                        }
-                      else
-                        {
-                          Matrix m = args(0).matrix_value ();
-                          if (!error_state)
-                            {
-                              mattyp = MatrixType (m);
-                              args(0).matrix_type (mattyp);
-                            }
-                        }
-                    }
-                }
-
-              int typ = mattyp.type ();
-
-              if (typ == MatrixType::Upper)
-                retval = octave_value ("Upper");
-              else if (typ == MatrixType::Permuted_Upper)
-                retval = octave_value ("Permuted Upper");
-              else if (typ == MatrixType::Lower)
-                retval = octave_value ("Lower");
-              else if (typ == MatrixType::Permuted_Lower)
-                retval = octave_value ("Permuted Lower");
-              else if (typ == MatrixType::Hermitian)
-                retval = octave_value ("Positive Definite");
-              else if (typ == MatrixType::Rectangular)
-                {
-                  if (args(0).rows () == args(0).columns ())
-                    retval = octave_value ("Singular");
-                  else
-                    retval = octave_value ("Rectangular");
-                }
-              else if (typ == MatrixType::Full)
-                retval = octave_value ("Full");
-              else
-                retval = octave_value ("Unknown");
-            }
-          else
-            {
-              // Ok, we're changing the matrix type
-              std::string str_typ = args(1).string_value ();
-
-              // FIXME -- why do I have to explicitly call the constructor?
-              MatrixType mattyp = MatrixType (MatrixType::Unknown, true);
-
-              if (error_state)
-                error ("matrix_type: TYPE must be a string");
-              else
-                {
-                  // Use STL function to convert to lower case
-                  std::transform (str_typ.begin (), str_typ.end (),
-                                  str_typ.begin (), tolower);
-
-                  if (str_typ == "upper")
-                    mattyp.mark_as_upper_triangular ();
-                  else if (str_typ == "lower")
-                    mattyp.mark_as_lower_triangular ();
-                  else if (str_typ == "positive definite")
-                    {
-                      mattyp.mark_as_full ();
-                      mattyp.mark_as_symmetric ();
-                    }
-                  else if (str_typ == "singular")
-                    mattyp.mark_as_rectangular ();
-                  else if (str_typ == "full")
-                    mattyp.mark_as_full ();
-                  else if (str_typ == "unknown")
-                    mattyp.invalidate_type ();
-                  else
-                    error ("matrix_type: Unknown matrix type %s", str_typ.c_str ());
-
-                  if (! error_state)
-                    {
-                      if (nargin == 3 && (str_typ == "upper"
-                                          || str_typ == "lower"))
-                        {
-                          const ColumnVector perm =
-                            ColumnVector (args (2).vector_value ());
-
-                          if (error_state)
-                            error ("matrix_type: Invalid permutation vector PERM");
-                          else
-                            {
-                              octave_idx_type len = perm.length ();
-                              dim_vector dv = args(0).dims ();
-
-                              if (len != dv(0))
-                                error ("matrix_type: Invalid permutation vector PERM");
-                              else
-                                {
-                                  OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len);
-
-                                  for (octave_idx_type i = 0; i < len; i++)
-                                    p[i] = static_cast<octave_idx_type> (perm (i)) - 1;
-
-                                  if (str_typ == "upper")
-                                    mattyp.mark_as_permuted (len, p);
-                                  else
-                                    mattyp.mark_as_permuted (len, p);
-                                }
-                            }
-                        }
-                      else if (nargin != 2)
-                        error ("matrix_type: Invalid number of arguments");
-
-                      if (! error_state)
-                        {
-                          // Set the matrix type
-                          if (args(0).is_single_type ())
-                            {
-                              if (args(0).is_complex_type ())
-                                retval = octave_value
-                                  (args(0).float_complex_matrix_value (),
-                                   mattyp);
-                              else
-                                retval = octave_value
-                                  (args(0).float_matrix_value (),
-                                   mattyp);
-                            }
-                          else
-                            {
-                              if (args(0).is_complex_type ())
-                                retval = octave_value
-                                  (args(0).complex_matrix_value (),
-                                   mattyp);
-                              else
-                                retval = octave_value
-                                  (args(0).matrix_value (),
-                                   mattyp);
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-  return retval;
-}
-
-/*
-## FIXME:
-## Disable tests for lower under-determined and upper over-determined
-## matrices as this detection is disabled in MatrixType due to issues
-## of non minimum norm solution being found.
-
-%!assert (matrix_type (speye (10,10)), "Diagonal")
-%!assert (matrix_type (speye (10,10)([2:10,1],:)), "Permuted Diagonal")
-%!assert (matrix_type ([[speye(10,10);sparse(1,10)],[1;sparse(9,1);1]]), "Upper")
-%!assert (matrix_type ([[speye(10,10);sparse(1,10)],[1;sparse(9,1);1]](:,[2,1,3:11])), "Permuted Upper")
-%!assert (matrix_type ([speye(10,10),sparse(10,1);1,sparse(1,9),1]), "Lower")
-%!assert (matrix_type ([speye(10,10),sparse(10,1);1,sparse(1,9),1]([2,1,3:11],:)), "Permuted Lower")
-
-%!test
-%! bnd = spparms ("bandden");
-%! spparms ("bandden", 0.5);
-%! a = spdiags (rand (10,3)-0.5,[-1,0,1],10,10);
-%! assert (matrix_type (a), "Tridiagonal");
-%! assert (matrix_type (a'+a+2*speye (10)), "Tridiagonal Positive Definite");
-%! spparms ("bandden", bnd);
-%!test
-%! bnd=spparms ("bandden");
-%! spparms ("bandden", 0.5);
-%! a = spdiags (randn (10,4),[-2:1],10,10);
-%! assert (matrix_type (a), "Banded");
-%! assert (matrix_type (a'*a), "Banded Positive Definite");
-%! spparms ("bandden", bnd);
-%!test
-%! a = [speye(10,10),[sparse(9,1);1];-1,sparse(1,9),1];
-%! assert (matrix_type (a), "Full");
-%! assert (matrix_type (a'*a), "Positive Definite");
-
-%!assert (matrix_type (speye (10,11)), "Diagonal")
-%!assert (matrix_type (speye (10,11)([2:10,1],:)), "Permuted Diagonal")
-%!assert (matrix_type (speye (11,10)), "Diagonal")
-%!assert (matrix_type (speye (11,10)([2:11,1],:)), "Permuted Diagonal")
-%#!assert (matrix_type ([[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]]), "Upper")
-%#!assert (matrix_type ([[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]](:,[2,1,3:12])), "Permuted Upper")
-%!assert (matrix_type ([speye(11,9),[1;sparse(8,1);1;0]]), "Upper")
-%!assert (matrix_type ([speye(11,9),[1;sparse(8,1);1;0]](:,[2,1,3:10])), "Permuted Upper")
-%#!assert (matrix_type ([speye(10,10),sparse(10,1);[1;1],sparse(2,9),[1;1]]), "Lower")
-%#!assert (matrix_type ([speye(10,10),sparse(10,1);[1;1],sparse(2,9),[1;1]]([2,1,3:12],:)), "Permuted Lower")
-%!assert (matrix_type ([speye(9,11);[1,sparse(1,8),1,0]]), "Lower")
-%!assert (matrix_type ([speye(9,11);[1,sparse(1,8),1,0]]([2,1,3:10],:)), "Permuted Lower")
-%!assert (matrix_type (spdiags (randn (10,4),[-2:1],10,9)), "Rectangular")
-
-%!assert (matrix_type (1i*speye (10,10)), "Diagonal")
-%!assert (matrix_type (1i*speye (10,10)([2:10,1],:)), "Permuted Diagonal")
-%!assert (matrix_type ([[speye(10,10);sparse(1,10)],[1i;sparse(9,1);1]]), "Upper")
-%!assert (matrix_type ([[speye(10,10);sparse(1,10)],[1i;sparse(9,1);1]](:,[2,1,3:11])), "Permuted Upper")
-%!assert (matrix_type ([speye(10,10),sparse(10,1);1i,sparse(1,9),1]), "Lower")
-%!assert (matrix_type ([speye(10,10),sparse(10,1);1i,sparse(1,9),1]([2,1,3:11],:)), "Permuted Lower")
-
-%!test
-%! bnd = spparms ("bandden");
-%! spparms ("bandden", 0.5);
-%! assert (matrix_type (spdiags (1i*randn (10,3),[-1,0,1],10,10)), "Tridiagonal");
-%! a = 1i*(rand (9,1)-0.5);
-%! a = [[a;0],ones(10,1),[0;-a]];
-%! assert (matrix_type (spdiags (a,[-1,0,1],10,10)), "Tridiagonal Positive Definite");
-%! spparms ("bandden", bnd);
-%!test
-%! bnd = spparms ("bandden");
-%! spparms ("bandden", 0.5);
-%! assert (matrix_type (spdiags (1i*randn (10,4),[-2:1],10,10)), "Banded");
-%! a = 1i*(rand (9,2)-0.5);
-%! a = [[a;[0,0]],ones(10,1),[[0;-a(:,2)],[0;0;-a(1:8,1)]]];
-%! assert (matrix_type (spdiags (a,[-2:2],10,10)), "Banded Positive Definite");
-%! spparms ("bandden", bnd);
-%!test
-%! a = [speye(10,10),[sparse(9,1);1i];-1,sparse(1,9),1];
-%! assert (matrix_type (a), "Full");
-%! assert (matrix_type (a'*a), "Positive Definite");
-
-%!assert (matrix_type (1i*speye (10,11)), "Diagonal")
-%!assert (matrix_type (1i*speye (10,11)([2:10,1],:)), "Permuted Diagonal")
-%!assert (matrix_type (1i*speye (11,10)), "Diagonal")
-%!assert (matrix_type (1i*speye (11,10)([2:11,1],:)), "Permuted Diagonal")
-%#!assert (matrix_type ([[speye(10,10);sparse(1,10)],[[1i,1i];sparse(9,2);[1i,1i]]]), "Upper")
-%#!assert (matrix_type ([[speye(10,10);sparse(1,10)],[[1i,1i];sparse(9,2);[1i,1i]]](:,[2,1,3:12])), "Permuted Upper")
-%!assert (matrix_type ([speye(11,9),[1i;sparse(8,1);1i;0]]), "Upper")
-%!assert (matrix_type ([speye(11,9),[1i;sparse(8,1);1i;0]](:,[2,1,3:10])), "Permuted Upper")
-%#!assert (matrix_type ([speye(10,10),sparse(10,1);[1i;1i],sparse(2,9),[1i;1i]]), "Lower")
-%#!assert (matrix_type ([speye(10,10),sparse(10,1);[1i;1i],sparse(2,9),[1i;1i]]([2,1,3:12],:)), "Permuted Lower")
-%!assert (matrix_type ([speye(9,11);[1i,sparse(1,8),1i,0]]), "Lower")
-%!assert (matrix_type ([speye(9,11);[1i,sparse(1,8),1i,0]]([2,1,3:10],:)), "Permuted Lower")
-%!assert (matrix_type (1i*spdiags(randn(10,4),[-2:1],10,9)), "Rectangular")
-
-%!test
-%! a = matrix_type (spdiags (randn (10,3),[-1,0,1],10,10), "Singular");
-%! assert (matrix_type (a), "Singular");
-
-%!assert (matrix_type (triu (ones(10,10))), "Upper")
-%!assert (matrix_type (triu (ones(10,10),-1)), "Full")
-%!assert (matrix_type (tril (ones(10,10))), "Lower")
-%!assert (matrix_type (tril (ones(10,10),1)), "Full")
-%!assert (matrix_type (10*eye (10,10) + ones (10,10)), "Positive Definite")
-%!assert (matrix_type (ones (11,10)), "Rectangular")
-%!test
-%! a = matrix_type (ones (10,10), "Singular");
-%! assert (matrix_type (a), "Singular");
-
-%!assert (matrix_type (triu (1i*ones (10,10))), "Upper")
-%!assert (matrix_type (triu (1i*ones (10,10),-1)), "Full")
-%!assert (matrix_type (tril (1i*ones (10,10))), "Lower")
-%!assert (matrix_type (tril (1i*ones (10,10),1)), "Full")
-%!assert (matrix_type (10*eye (10,10) + 1i*triu (ones (10,10),1) -1i*tril (ones (10,10),-1)), "Positive Definite")
-%!assert (matrix_type (ones (11,10)), "Rectangular")
-%!test
-%! a = matrix_type (ones (10,10), "Singular");
-%! assert (matrix_type (a), "Singular");
-*/
--- a/src/DLD-FUNCTIONS/max.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,632 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-Copyright (C) 2009 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "lo-ieee.h"
-#include "lo-mappers.h"
-#include "lo-math.h"
-#include "dNDArray.h"
-#include "CNDArray.h"
-#include "quit.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-
-#include "ov-cx-mat.h"
-#include "ov-re-sparse.h"
-#include "ov-cx-sparse.h"
-
-template <class ArrayType>
-static octave_value_list
-do_minmax_red_op (const octave_value& arg,
-                  int nargout, int dim, bool ismin)
-{
-  octave_value_list retval;
-  ArrayType array = octave_value_extract<ArrayType> (arg);
-
-  if (error_state)
-    return retval;
-
-  if (nargout == 2)
-    {
-      retval.resize (2);
-      Array<octave_idx_type> idx;
-      if (ismin)
-        retval(0) = array.min (idx, dim);
-      else
-        retval(0) = array.max (idx, dim);
-
-      retval(1) = octave_value (idx, true, true);
-    }
-  else
-    {
-      if (ismin)
-        retval(0) = array.min (dim);
-      else
-        retval(0) = array.max (dim);
-    }
-
-  return retval;
-}
-
-// Specialization for bool arrays.
-template <>
-octave_value_list
-do_minmax_red_op<boolNDArray> (const octave_value& arg,
-                               int nargout, int dim, bool ismin)
-{
-  octave_value_list retval;
-
-  if (nargout <= 1)
-    {
-      // This case can be handled using any/all.
-      boolNDArray array = arg.bool_array_value ();
-
-      if (array.is_empty ())
-        retval(0) = array;
-      else if (ismin)
-        retval(0) = array.all (dim);
-      else
-        retval(0) = array.any (dim);
-    }
-  else
-    {
-      // any/all don't have indexed versions, so do it via a conversion.
-      retval = do_minmax_red_op<int8NDArray> (arg, nargout, dim, ismin);
-      if (! error_state)
-        retval(0) = retval(0).bool_array_value ();
-    }
-
-  return retval;
-}
-
-template <class ArrayType>
-static octave_value
-do_minmax_bin_op (const octave_value& argx, const octave_value& argy,
-                  bool ismin)
-{
-  typedef typename ArrayType::element_type ScalarType;
-
-  octave_value retval;
-
-  if (argx.is_scalar_type () == 1)
-    {
-      ScalarType x = octave_value_extract<ScalarType> (argx);
-      ArrayType y = octave_value_extract<ArrayType> (argy);
-
-      if (error_state)
-        ;
-      else if (ismin)
-        retval = min (x, y);
-      else
-        retval = max (x, y);
-    }
-  else if (argy.is_scalar_type () == 1)
-    {
-      ArrayType x = octave_value_extract<ArrayType> (argx);
-      ScalarType y = octave_value_extract<ScalarType> (argy);
-
-      if (error_state)
-        ;
-      else if (ismin)
-        retval = min (x, y);
-      else
-        retval = max (x, y);
-    }
-  else
-    {
-      ArrayType x = octave_value_extract<ArrayType> (argx);
-      ArrayType y = octave_value_extract<ArrayType> (argy);
-
-      if (error_state)
-        ;
-      else if (ismin)
-        retval = min (x, y);
-      else
-        retval = max (x, y);
-    }
-
-  return retval;
-}
-
-static octave_value_list
-do_minmax_body (const octave_value_list& args,
-                int nargout, bool ismin)
-{
-  octave_value_list retval;
-
-  const char *func = ismin ? "min" : "max";
-
-  int nargin = args.length ();
-
-  if (nargin == 3 || nargin == 1)
-    {
-      octave_value arg = args(0);
-      int dim = -1;
-      if (nargin == 3)
-        {
-          dim = args(2).int_value (true) - 1;
-          if (error_state || dim < 0)
-            {
-              error ("%s: DIM must be a valid dimension", func);
-              return retval;
-            }
-
-          if (! args(1).is_empty ())
-            warning ("%s: second argument is ignored", func);
-        }
-
-      switch (arg.builtin_type ())
-        {
-        case btyp_double:
-          {
-            if (arg.is_range () && (dim == -1 || dim == 1))
-              {
-                Range range = arg.range_value ();
-                if (range.nelem () == 0)
-                  {
-                    retval(0) = arg;
-                    if (nargout > 1)
-                      retval(1) = arg;
-                  }
-                else if (ismin)
-                  {
-                    retval(0) = range.min ();
-                    if (nargout > 1)
-                      retval(1) = static_cast<double> (range.inc () < 0 ? range.nelem () : 1);
-                  }
-                else
-                  {
-                    retval(0) = range.max ();
-                    if (nargout > 1)
-                      retval(1) = static_cast<double> (range.inc () >= 0 ? range.nelem () : 1);
-                  }
-              }
-            else if (arg.is_sparse_type ())
-              retval = do_minmax_red_op<SparseMatrix> (arg, nargout, dim, ismin);
-            else
-              retval = do_minmax_red_op<NDArray> (arg, nargout, dim, ismin);
-            break;
-          }
-        case btyp_complex:
-          {
-            if (arg.is_sparse_type ())
-              retval = do_minmax_red_op<SparseComplexMatrix> (arg, nargout, dim, ismin);
-            else
-              retval = do_minmax_red_op<ComplexNDArray> (arg, nargout, dim, ismin);
-            break;
-          }
-        case btyp_float:
-          retval = do_minmax_red_op<FloatNDArray> (arg, nargout, dim, ismin);
-          break;
-        case btyp_float_complex:
-          retval = do_minmax_red_op<FloatComplexNDArray> (arg, nargout, dim, ismin);
-          break;
-#define MAKE_INT_BRANCH(X) \
-        case btyp_ ## X: \
-          retval = do_minmax_red_op<X ## NDArray> (arg, nargout, dim, ismin); \
-          break;
-        MAKE_INT_BRANCH (int8);
-        MAKE_INT_BRANCH (int16);
-        MAKE_INT_BRANCH (int32);
-        MAKE_INT_BRANCH (int64);
-        MAKE_INT_BRANCH (uint8);
-        MAKE_INT_BRANCH (uint16);
-        MAKE_INT_BRANCH (uint32);
-        MAKE_INT_BRANCH (uint64);
-#undef MAKE_INT_BRANCH
-        case btyp_bool:
-          retval = do_minmax_red_op<boolNDArray> (arg, nargout, dim, ismin);
-          break;
-        default:
-          gripe_wrong_type_arg (func, arg);
-      }
-    }
-  else if (nargin == 2)
-    {
-      octave_value argx = args(0), argy = args(1);
-      builtin_type_t xtyp = argx.builtin_type (), ytyp = argy.builtin_type ();
-      builtin_type_t rtyp = btyp_mixed_numeric (xtyp, ytyp);
-
-      switch (rtyp)
-        {
-        case btyp_double:
-          {
-            if ((argx.is_sparse_type ()
-                 && (argy.is_sparse_type () || argy.is_scalar_type ()))
-                || (argy.is_sparse_type () && argx.is_scalar_type ()))
-              retval = do_minmax_bin_op<SparseMatrix> (argx, argy, ismin);
-            else
-              retval = do_minmax_bin_op<NDArray> (argx, argy, ismin);
-            break;
-          }
-        case btyp_complex:
-          {
-            if ((argx.is_sparse_type ()
-                 && (argy.is_sparse_type () || argy.is_scalar_type ()))
-                || (argy.is_sparse_type () && argx.is_scalar_type ()))
-              retval = do_minmax_bin_op<SparseComplexMatrix> (argx, argy, ismin);
-            else
-              retval = do_minmax_bin_op<ComplexNDArray> (argx, argy, ismin);
-            break;
-          }
-        case btyp_float:
-          retval = do_minmax_bin_op<FloatNDArray> (argx, argy, ismin);
-          break;
-        case btyp_float_complex:
-          retval = do_minmax_bin_op<FloatComplexNDArray> (argx, argy, ismin);
-          break;
-#define MAKE_INT_BRANCH(X) \
-        case btyp_ ## X: \
-          retval = do_minmax_bin_op<X ## NDArray> (argx, argy, ismin); \
-          break;
-        MAKE_INT_BRANCH (int8);
-        MAKE_INT_BRANCH (int16);
-        MAKE_INT_BRANCH (int32);
-        MAKE_INT_BRANCH (int64);
-        MAKE_INT_BRANCH (uint8);
-        MAKE_INT_BRANCH (uint16);
-        MAKE_INT_BRANCH (uint32);
-        MAKE_INT_BRANCH (uint64);
-#undef MAKE_INT_BRANCH
-        default:
-          error ("%s: cannot compute %s (%s, %s)", func, func,
-                 argx.type_name ().c_str (), argy.type_name ().c_str ());
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-DEFUN_DLD (min, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} min (@var{x})\n\
-@deftypefnx {Loadable Function} {} min (@var{x}, @var{y})\n\
-@deftypefnx {Loadable Function} {} min (@var{x}, [], @var{dim})\n\
-@deftypefnx {Loadable Function} {} min (@var{x}, @var{y}, @var{dim})\n\
-@deftypefnx {Loadable Function} {[@var{w}, @var{iw}] =} min (@var{x})\n\
-For a vector argument, return the minimum value.  For a matrix\n\
-argument, return the minimum value from each column, as a row\n\
-vector, or over the dimension @var{dim} if defined, in which case @var{y} \n\
-should be set to the empty matrix (it's ignored otherwise).  For two matrices\n\
-(or a matrix and scalar), return the pair-wise minimum.\n\
-Thus,\n\
-\n\
-@example\n\
-min (min (@var{x}))\n\
-@end example\n\
-\n\
-@noindent\n\
-returns the smallest element of @var{x}, and\n\
-\n\
-@example\n\
-@group\n\
-min (2:5, pi)\n\
-    @result{}  2.0000  3.0000  3.1416  3.1416\n\
-@end group\n\
-@end example\n\
-\n\
-@noindent\n\
-compares each element of the range @code{2:5} with @code{pi}, and\n\
-returns a row vector of the minimum values.\n\
-\n\
-For complex arguments, the magnitude of the elements are used for\n\
-comparison.\n\
-\n\
-If called with one input and two output arguments,\n\
-@code{min} also returns the first index of the\n\
-minimum value(s).  Thus,\n\
-\n\
-@example\n\
-@group\n\
-[x, ix] = min ([1, 3, 0, 2, 0])\n\
-    @result{}  x = 0\n\
-        ix = 3\n\
-@end group\n\
-@end example\n\
-@seealso{max, cummin, cummax}\n\
-@end deftypefn")
-{
-  return do_minmax_body (args, nargout, true);
-}
-
-/*
-%!assert (min ([1, 4, 2, 3]), 1)
-%!assert (min ([1; -10; 5; -2]), -10)
-%!assert (min ([4, i; -2, 2]), [-2, i])
-
-%!test
-%! x = reshape (1:8, [2,2,2]);
-%! assert (max (x, [], 1), reshape ([2, 4, 6, 8], [1,2,2]));
-%! assert (max (x, [], 2), reshape ([3, 4, 7, 8], [2,1,2]));
-%! [y, i] = max (x, [], 3);
-%! assert (ndims (y), 2);
-%! assert (y, [5, 7; 6, 8]);
-%! assert (ndims (i), 2);
-%! assert (i, [2, 2; 2, 2]);
-
-%!error min ()
-%!error min (1, 2, 3, 4)
-*/
-
-DEFUN_DLD (max, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} max (@var{x})\n\
-@deftypefnx {Loadable Function} {} max (@var{x}, @var{y})\n\
-@deftypefnx {Loadable Function} {} max (@var{x}, [], @var{dim})\n\
-@deftypefnx {Loadable Function} {} max (@var{x}, @var{y}, @var{dim})\n\
-@deftypefnx {Loadable Function} {[@var{w}, @var{iw}] =} max (@var{x})\n\
-For a vector argument, return the maximum value.  For a matrix\n\
-argument, return the maximum value from each column, as a row\n\
-vector, or over the dimension @var{dim} if defined, in which case @var{y} \n\
-should be set to the empty matrix (it's ignored otherwise).  For two matrices\n\
-(or a matrix and scalar), return the pair-wise maximum.\n\
-Thus,\n\
-\n\
-@example\n\
-max (max (@var{x}))\n\
-@end example\n\
-\n\
-@noindent\n\
-returns the largest element of the matrix @var{x}, and\n\
-\n\
-@example\n\
-@group\n\
-max (2:5, pi)\n\
-    @result{}  3.1416  3.1416  4.0000  5.0000\n\
-@end group\n\
-@end example\n\
-\n\
-@noindent\n\
-compares each element of the range @code{2:5} with @code{pi}, and\n\
-returns a row vector of the maximum values.\n\
-\n\
-For complex arguments, the magnitude of the elements are used for\n\
-comparison.\n\
-\n\
-If called with one input and two output arguments,\n\
-@code{max} also returns the first index of the\n\
-maximum value(s).  Thus,\n\
-\n\
-@example\n\
-@group\n\
-[x, ix] = max ([1, 3, 5, 2, 5])\n\
-    @result{}  x = 5\n\
-        ix = 3\n\
-@end group\n\
-@end example\n\
-@seealso{min, cummax, cummin}\n\
-@end deftypefn")
-{
-  return do_minmax_body (args, nargout, false);
-}
-
-/*
-%!assert (max ([1, 4, 2, 3]), 4)
-%!assert (max ([1; -10; 5; -2]), 5)
-%!assert (max ([4, i 4.999; -2, 2, 3+4i]), [4, 2, 3+4i])
-
-%!test
-%! x = reshape (1:8, [2,2,2]);
-%! assert (min (x, [], 1), reshape ([1, 3, 5, 7], [1,2,2]));
-%! assert (min (x, [], 2), reshape ([1, 2, 5, 6], [2,1,2]));
-%! [y, i] = min (x, [], 3);
-%! assert (ndims(y), 2);
-%! assert (y, [1, 3; 2, 4]);
-%! assert (ndims(i), 2);
-%! assert (i, [1, 1; 1, 1]);
-
-%!error max ()
-%!error max (1, 2, 3, 4)
-*/
-
-template <class ArrayType>
-static octave_value_list
-do_cumminmax_red_op (const octave_value& arg,
-                     int nargout, int dim, bool ismin)
-{
-  octave_value_list retval;
-  ArrayType array = octave_value_extract<ArrayType> (arg);
-
-  if (error_state)
-    return retval;
-
-  if (nargout == 2)
-    {
-      retval.resize (2);
-      Array<octave_idx_type> idx;
-      if (ismin)
-        retval(0) = array.cummin (idx, dim);
-      else
-        retval(0) = array.cummax (idx, dim);
-
-      retval(1) = octave_value (idx, true, true);
-    }
-  else
-    {
-      if (ismin)
-        retval(0) = array.cummin (dim);
-      else
-        retval(0) = array.cummax (dim);
-    }
-
-  return retval;
-}
-
-static octave_value_list
-do_cumminmax_body (const octave_value_list& args,
-                   int nargout, bool ismin)
-{
-  octave_value_list retval;
-
-  const char *func = ismin ? "cummin" : "cummax";
-
-  int nargin = args.length ();
-
-  if (nargin == 1 || nargin == 2)
-    {
-      octave_value arg = args(0);
-      int dim = -1;
-      if (nargin == 2)
-        {
-          dim = args(1).int_value (true) - 1;
-          if (error_state || dim < 0)
-            {
-              error ("%s: DIM must be a valid dimension", func);
-              return retval;
-            }
-        }
-
-      switch (arg.builtin_type ())
-        {
-        case btyp_double:
-          retval = do_cumminmax_red_op<NDArray> (arg, nargout, dim, ismin);
-          break;
-        case btyp_complex:
-          retval = do_cumminmax_red_op<ComplexNDArray> (arg, nargout, dim, ismin);
-          break;
-        case btyp_float:
-          retval = do_cumminmax_red_op<FloatNDArray> (arg, nargout, dim, ismin);
-          break;
-        case btyp_float_complex:
-          retval = do_cumminmax_red_op<FloatComplexNDArray> (arg, nargout, dim, ismin);
-          break;
-#define MAKE_INT_BRANCH(X) \
-        case btyp_ ## X: \
-          retval = do_cumminmax_red_op<X ## NDArray> (arg, nargout, dim, ismin); \
-          break;
-        MAKE_INT_BRANCH (int8);
-        MAKE_INT_BRANCH (int16);
-        MAKE_INT_BRANCH (int32);
-        MAKE_INT_BRANCH (int64);
-        MAKE_INT_BRANCH (uint8);
-        MAKE_INT_BRANCH (uint16);
-        MAKE_INT_BRANCH (uint32);
-        MAKE_INT_BRANCH (uint64);
-#undef MAKE_INT_BRANCH
-        case btyp_bool:
-          {
-            retval = do_cumminmax_red_op<int8NDArray> (arg, nargout, dim, ismin);
-            if (retval.length () > 0)
-              retval(0) = retval(0).bool_array_value ();
-            break;
-          }
-        default:
-          gripe_wrong_type_arg (func, arg);
-      }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-DEFUN_DLD (cummin, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} cummin (@var{x})\n\
-@deftypefnx {Loadable Function} {} cummin (@var{x}, @var{dim})\n\
-@deftypefnx {Loadable Function} {[@var{w}, @var{iw}] =} cummin (@var{x})\n\
-Return the cumulative minimum values along dimension @var{dim}.  If @var{dim}\n\
-is unspecified it defaults to column-wise operation.  For example:\n\
-\n\
-@example\n\
-@group\n\
-cummin ([5 4 6 2 3 1])\n\
-   @result{}  5  4  4  2  2  1\n\
-@end group\n\
-@end example\n\
-\n\
-\n\
-The call\n\
-\n\
-@example\n\
-  [w, iw] = cummin (x)\n\
-@end example\n\
-\n\
-@noindent\n\
-with @code{x} a vector, is equivalent to the following code:\n\
-\n\
-@example\n\
-@group\n\
-w = iw = zeros (size (x));\n\
-for i = 1:length (x)\n\
-  [w(i), iw(i)] = max (x(1:i));\n\
-endfor\n\
-@end group\n\
-@end example\n\
-\n\
-@noindent\n\
-but computed in a much faster manner.\n\
-@seealso{cummax, min, max}\n\
-@end deftypefn")
-{
-  return do_cumminmax_body (args, nargout, true);
-}
-
-DEFUN_DLD (cummax, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} cummax (@var{x})\n\
-@deftypefnx {Loadable Function} {} cummax (@var{x}, @var{dim})\n\
-@deftypefnx {Loadable Function} {[@var{w}, @var{iw}] =} cummax (@var{x})\n\
-Return the cumulative maximum values along dimension @var{dim}.  If @var{dim}\n\
-is unspecified it defaults to column-wise operation.  For example:\n\
-\n\
-@example\n\
-@group\n\
-cummax ([1 3 2 6 4 5])\n\
-   @result{}  1  3  3  6  6  6\n\
-@end group\n\
-@end example\n\
-\n\
-The call\n\
-\n\
-@example\n\
-[w, iw] = cummax (x, dim)\n\
-@end example\n\
-\n\
-@noindent\n\
-with @code{x} a vector, is equivalent to the following code:\n\
-\n\
-@example\n\
-@group\n\
-w = iw = zeros (size (x));\n\
-for i = 1:length (x)\n\
-  [w(i), iw(i)] = max (x(1:i));\n\
-endfor\n\
-@end group\n\
-@end example\n\
-\n\
-@noindent\n\
-but computed in a much faster manner.\n\
-@seealso{cummin, max, min}\n\
-@end deftypefn")
-{
-  return do_cumminmax_body (args, nargout, false);
-}
--- a/src/DLD-FUNCTIONS/md5sum.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,101 +0,0 @@
-/*
-
-Copyright (C) 2007-2012 David Bateman
-
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-#include <vector>
-
-#include "defun-dld.h"
-#include "file-stat.h"
-#include "file-ops.h"
-#include "gripes.h"
-#include "load-path.h"
-#include "oct-env.h"
-#include "oct-md5.h"
-
-DEFUN_DLD (md5sum, args, ,
-   "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} md5sum (@var{file})\n\
-@deftypefnx {Loadable Function} {} md5sum (@var{str}, @var{opt})\n\
-Calculate the MD5 sum of the file @var{file}.  If the second parameter\n\
-@var{opt} exists and is true, then calculate the MD5 sum of the\n\
-string @var{str}.\n\
-@end deftypefn")
-{
-  octave_value retval;
-  int nargin = args.length ();
-
-  if (nargin != 1 && nargin != 2)
-    print_usage ();
-  else
-    {
-      bool have_str = false;
-      std::string str = args(0).string_value ();
-
-      if (nargin == 2)
-        have_str = args(1).bool_value ();
-
-      if (!error_state)
-        {
-          if (have_str)
-            retval = oct_md5 (str);
-          else
-            {
-              file_stat fs (str);
-
-              if (! fs.exists ())
-                {
-                  std::string tmp
-                    = octave_env::make_absolute (load_path::find_file (str));
-
-                  if (! tmp.empty ())
-                    {
-                      warning_with_id ("Octave:md5sum-file-in-path",
-                                       "md5sum: file found in load path");
-                      str = tmp;
-                    }
-                }
-
-              retval = oct_md5_file (str);
-            }
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!assert (md5sum ("abc\0", true), "147a664a2ca9410911e61986d3f0d52a");
-
-%!test
-%! tfile = tmpnam ();
-%! fid = fopen (tfile, "wb");
-%! fwrite (fid, "abc\0");
-%! fclose (fid);
-%! assert (md5sum (tfile), "147a664a2ca9410911e61986d3f0d52a");
-%! unlink (tfile);
-*/
-
--- a/src/DLD-FUNCTIONS/mgorth.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,154 +0,0 @@
-/*
-
-Copyright (C) 2009-2012 Carlo de Falco
-Copyright (C) 2010 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "oct-norm.h"
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-
-template <class ColumnVector, class Matrix, class RowVector>
-static void
-do_mgorth (ColumnVector& x, const Matrix& V, RowVector& h)
-{
-  octave_idx_type Vc = V.columns ();
-  h = RowVector (Vc + 1);
-  for (octave_idx_type j = 0; j < Vc; j++)
-    {
-      ColumnVector Vcj = V.column (j);
-      h(j) = RowVector (Vcj.hermitian ()) * x;
-      x -= h(j) * Vcj;
-    }
-
-  h(Vc) = xnorm (x);
-  if (real (h(Vc)) > 0)
-    x = x / h(Vc);
-}
-
-DEFUN_DLD (mgorth, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{y}, @var{h}] =} mgorth (@var{x}, @var{v})\n\
-Orthogonalize a given column vector @var{x} with respect to a given\n\
-orthonormal basis @var{v} using a modified Gram-Schmidt orthogonalization.  \n\
-On exit, @var{y} is a unit vector such that:\n\
-\n\
-@example\n\
-@group\n\
-  norm (@var{y}) = 1\n\
-  @var{v}' * @var{y} = 0\n\
-  @var{x} = @var{h}*[@var{v}, @var{y}]\n\
-@end group\n\
-@end example\n\
-\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin != 2 || nargout > 2)
-  {
-    print_usage ();
-    return retval;
-  }
-
-  octave_value arg_x = args(0);
-  octave_value arg_v = args(1);
-
-  if (arg_v.ndims () != 2 || arg_x.ndims () != 2 || arg_x.columns () != 1
-      || arg_v.rows () != arg_x.rows ())
-    {
-      error ("mgorth: V should me a matrix, and X a column vector with"
-             " the same number of rows as V.");
-      return retval;
-    }
-
-  if (! arg_x.is_numeric_type () && ! arg_v.is_numeric_type ())
-    {
-      error ("mgorth: X and V must be numeric");
-    }
-
-  bool iscomplex = (arg_x.is_complex_type () || arg_v.is_complex_type ());
-  if (arg_x.is_single_type () || arg_v.is_single_type ())
-    {
-      if (iscomplex)
-        {
-          FloatComplexColumnVector x = arg_x.float_complex_column_vector_value ();
-          FloatComplexMatrix V = arg_v.float_complex_matrix_value ();
-          FloatComplexRowVector h;
-          do_mgorth (x, V, h);
-          retval(1) = h;
-          retval(0) = x;
-        }
-      else
-        {
-          FloatColumnVector x = arg_x.float_column_vector_value ();
-          FloatMatrix V = arg_v.float_matrix_value ();
-          FloatRowVector h;
-          do_mgorth (x, V, h);
-          retval(1) = h;
-          retval(0) = x;
-        }
-    }
-  else
-    {
-      if (iscomplex)
-        {
-          ComplexColumnVector x = arg_x.complex_column_vector_value ();
-          ComplexMatrix V = arg_v.complex_matrix_value ();
-          ComplexRowVector h;
-          do_mgorth (x, V, h);
-          retval(1) = h;
-          retval(0) = x;
-        }
-      else
-        {
-          ColumnVector x = arg_x.column_vector_value ();
-          Matrix V = arg_v.matrix_value ();
-          RowVector h;
-          do_mgorth (x, V, h);
-          retval(1) = h;
-          retval(0) = x;
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!test
-%! for ii=1:100
-%!   assert (abs (mgorth (randn (5, 1), eye (5, 4))), [0 0 0 0 1]', eps);
-%! endfor
-
-%!test
-%! a = hilb (5);
-%! a(:, 1) /= norm (a(:, 1));
-%! for ii = 1:5
-%!   a(:, ii) = mgorth (a(:, ii), a(:, 1:ii-1));
-%! endfor
-%! assert (a' * a, eye (5), 1e10);
-*/
--- a/src/DLD-FUNCTIONS/module-files	Fri Jul 27 17:10:25 2012 -0400
+++ b/src/DLD-FUNCTIONS/module-files	Fri Jul 27 21:59:10 2012 -0400
@@ -1,83 +1,22 @@
 # FILE|CPPFLAGS|LDFLAGS|LIBRARIES
-__contourc__.cc
+chol.cc
 __delaunayn__.cc|$(QHULL_CPPFLAGS)|$(QHULL_LDFLAGS)|$(QHULL_LIBS)
-__dispatch__.cc
 __dsearchn__.cc
 __fltk_uigetfile__.cc|$(GRAPHICS_CFLAGS) $(FT2_CPPFLAGS)|$(GRAPHICS_LDFLAGS) $(FT2_LDFLAGS)|$(GRAPHICS_LIBS) $(FT2_LIBS)
 __glpk__.cc|$(GLPK_CPPFLAGS)|$(GLPK_LDFLAGS)|$(GLPK_LIBS)
 __init_fltk__.cc|$(GRAPHICS_CFLAGS) $(FT2_CPPFLAGS)|$(GRAPHICS_LDFLAGS) $(FT2_LDFLAGS)|$(GRAPHICS_LIBS) $(FT2_LIBS)
 __init_gnuplot__.cc
-__lin_interpn__.cc
 __magick_read__.cc|$(MAGICK_CPPFLAGS)|$(MAGICK_LDFLAGS)|$(MAGICK_LIBS)
-__pchip_deriv__.cc
-__qp__.cc
 __voronoi__.cc|$(QHULL_CPPFLAGS)|$(QHULL_LDFLAGS)|$(QHULL_LIBS)
 amd.cc|$(SPARSE_XCPPFLAGS)|$(SPARSE_XLDFLAGS)|$(SPARSE_XLIBS)
-balance.cc
-besselj.cc
-betainc.cc
-bsxfun.cc
 ccolamd.cc|$(SPARSE_XCPPFLAGS)|$(SPARSE_XLDFLAGS)|$(SPARSE_XLIBS)
-cellfun.cc
-chol.cc|$(QRUPDATE_CPPFLAGS) $(SPARSE_XCPPFLAGS)|$(QRUPDATE_LDFLAGS) $(SPARSE_XLDFLAGS)|$(QRUPDATE_LIBS) $(SPARSE_XLIBS)
 colamd.cc|$(SPARSE_XCPPFLAGS)|$(SPARSE_XLDFLAGS)|$(SPARSE_XLIBS)
-colloc.cc
-conv2.cc
 convhulln.cc|$(QHULL_CPPFLAGS)|$(QHULL_LDFLAGS)|$(QHULL_LIBS)
-daspk.cc
-dasrt.cc
-dassl.cc
-det.cc
-dlmread.cc
 dmperm.cc|$(SPARSE_XCPPFLAGS)|$(SPARSE_XLDFLAGS)|$(SPARSE_XLIBS)
-dot.cc
-eig.cc
 eigs.cc|$(ARPACK_CPPFLAGS) $(SPARSE_XCPPFLAGS)|$(ARPACK_LDFLAGS) $(SPARSE_XLDFLAGS)|$(ARPACK_LIBS) $(SPARSE_XLIBS) $(LAPACK_LIBS) $(BLAS_LIBS)
-fft.cc|$(FFTW_XCPPFLAGS)|$(FFTW_XLDFLAGS)|$(FFTW_XLIBS)
-fft2.cc|$(FFTW_XCPPFLAGS)|$(FFTW_XLDFLAGS)|$(FFTW_XLIBS)
-fftn.cc|$(FFTW_XCPPFLAGS)|$(FFTW_XLDFLAGS)|$(FFTW_XLIBS)
 fftw.cc|$(FFTW_XCPPFLAGS)|$(FFTW_XLDFLAGS)|$(FFTW_XLIBS)
-filter.cc
-find.cc
-gammainc.cc
-gcd.cc
-getgrent.cc
-getpwent.cc
-getrusage.cc
-givens.cc
-hess.cc
-hex2num.cc
-inv.cc
-kron.cc
-lookup.cc
-lsode.cc
-lu.cc
-luinc.cc
-matrix_type.cc
-max.cc
-md5sum.cc
-mgorth.cc
-nproc.cc
-pinv.cc
 qr.cc|$(QRUPDATE_CPPFLAGS) $(SPARSE_XCPPFLAGS)|$(QRUPDATE_LDFLAGS) $(SPARSE_XLDFLAGS)|$(QRUPDATE_LIBS) $(SPARSE_XLIBS)
-quad.cc
-quadcc.cc
-qz.cc|||$(LAPACK_LIBS) $(BLAS_LIBS)
-rand.cc
-rcond.cc
-regexp.cc|$(REGEX_CPPFLAGS)|$(REGEX_LDFLAGS)|$(REGEX_LIBS)
-schur.cc
-spparms.cc
-sqrtm.cc
-strfind.cc
-str2double.cc
-sub2ind.cc
-svd.cc
-syl.cc
 symbfact.cc|$(SPARSE_XCPPFLAGS)|$(SPARSE_XLDFLAGS)|$(SPARSE_XLIBS)
 symrcm.cc|$(SPARSE_XCPPFLAGS)|$(SPARSE_XLDFLAGS)|$(SPARSE_XLIBS)
-time.cc
-tril.cc
 tsearch.cc
-typecast.cc
 urlwrite.cc|$(CURL_CPPFLAGS)|$(CURL_LDFLAGS)|$(CURL_LIBS)
--- a/src/DLD-FUNCTIONS/nproc.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-/*
-
-Copyright (C) 2012 Iain Murray
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "defun-dld.h"
-#include "nproc.h"
-
-DEFUN_DLD (nproc, args, nargout,
-   "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} nproc ()\n\
-@deftypefnx {Loadable Function} {} nproc (@var{query})\n\
-Return the current number of available processors.\n\
-\n\
-If called with the optional argument @var{query}, modify how processors\n\
-are counted as follows:\n\
-\n\
-@table @code\n\
-@item all\n\
-total number of processors.\n\
-\n\
-@item current\n\
-processors available to the current process.\n\
-\n\
-@item overridable\n\
-likewise, but overridable through the @w{@env{OMP_NUM_THREADS}} environment\n\
-variable.\n\
-@end table\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if ((nargin != 0 && nargin != 1) || (nargout != 0 && nargout != 1))
-    {
-      print_usage ();
-      return retval;
-    }
-
-  nproc_query query = NPROC_CURRENT;
-  if (nargin == 1)
-    {
-      std::string arg = args(0).string_value ();
-
-      std::transform (arg.begin (), arg.end (), arg.begin (), tolower);
-
-      if (arg == "all")
-        query = NPROC_ALL;
-      else if (arg == "current")
-        query = NPROC_CURRENT;
-      else if (arg == "overridable")
-        query = NPROC_CURRENT_OVERRIDABLE;
-      else
-        {
-          error ("nproc: invalid value for QUERY");
-          return retval;
-        }
-    }
-
-  retval = num_processors (query);
-
-  return retval;
-}
-
-/*
-## Must always report at least 1 cpu available
-%!assert (nproc () >= 1);
-*/
--- a/src/DLD-FUNCTIONS/pinv.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,192 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-#include "ops.h"
-#include "ov-re-diag.h"
-#include "ov-cx-diag.h"
-#include "ov-flt-re-diag.h"
-#include "ov-flt-cx-diag.h"
-#include "ov-perm.h"
-
-DEFUN_DLD (pinv, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} pinv (@var{x})\n\
-@deftypefnx {Loadable Function} {} pinv (@var{x}, @var{tol})\n\
-Return the pseudoinverse of @var{x}.  Singular values less than\n\
-@var{tol} are ignored.\n\
-\n\
-If the second argument is omitted, it is taken to be\n\
-\n\
-@example\n\
-tol = max (size (@var{x})) * sigma_max (@var{x}) * eps,\n\
-@end example\n\
-\n\
-@noindent\n\
-where @code{sigma_max (@var{x})} is the maximal singular value of @var{x}.\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 1 || nargin > 2)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value arg = args(0);
-
-  int arg_is_empty = empty_arg ("pinv", arg.rows (), arg.columns ());
-
-  if (arg_is_empty < 0)
-    return retval;
-  else if (arg_is_empty > 0)
-    return octave_value (Matrix ());
-
-  bool isfloat = arg.is_single_type ();
-
-  if (arg.is_diag_matrix ())
-    {
-      if (nargin == 2)
-        warning ("pinv: tol is ignored for diagonal matrices");
-
-      if (arg.is_complex_type ())
-        {
-          if (isfloat)
-            retval = arg.float_complex_diag_matrix_value ().pseudo_inverse ();
-          else
-            retval = arg.complex_diag_matrix_value ().pseudo_inverse ();
-        }
-      else
-        {
-          if (isfloat)
-            retval = arg.float_diag_matrix_value ().pseudo_inverse ();
-          else
-            retval = arg.diag_matrix_value ().pseudo_inverse ();
-        }
-    }
-  else if (arg.is_perm_matrix ())
-    {
-      retval = arg.perm_matrix_value ().inverse ();
-    }
-  else if (isfloat)
-    {
-      float tol = 0.0;
-      if (nargin == 2)
-        tol = args(1).float_value ();
-
-      if (error_state)
-        return retval;
-
-      if (tol < 0.0)
-        {
-          error ("pinv: TOL must be greater than zero");
-          return retval;
-        }
-
-      if (arg.is_real_type ())
-        {
-          FloatMatrix m = arg.float_matrix_value ();
-
-          if (! error_state)
-            retval = m.pseudo_inverse (tol);
-        }
-      else if (arg.is_complex_type ())
-        {
-          FloatComplexMatrix m = arg.float_complex_matrix_value ();
-
-          if (! error_state)
-            retval = m.pseudo_inverse (tol);
-        }
-      else
-        {
-          gripe_wrong_type_arg ("pinv", arg);
-        }
-    }
-  else
-    {
-      double tol = 0.0;
-      if (nargin == 2)
-        tol = args(1).double_value ();
-
-      if (error_state)
-        return retval;
-
-      if (tol < 0.0)
-        {
-          error ("pinv: TOL must be greater than zero");
-          return retval;
-        }
-
-      if (arg.is_real_type ())
-        {
-          Matrix m = arg.matrix_value ();
-
-          if (! error_state)
-            retval = m.pseudo_inverse (tol);
-        }
-      else if (arg.is_complex_type ())
-        {
-          ComplexMatrix m = arg.complex_matrix_value ();
-
-          if (! error_state)
-            retval = m.pseudo_inverse (tol);
-        }
-      else
-        {
-          gripe_wrong_type_arg ("pinv", arg);
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!shared a, b, tol, hitol, d, u, x, y
-%! a = reshape (rand*[1:16], 4, 4);   ## Rank 2 matrix
-%! b = pinv (a);
-%! tol = 4e-14;
-%! hitol = 40*sqrt (eps);
-%! d = diag ([rand, rand, hitol, hitol]);
-%! u = rand (4);                      ## Could be singular by freak accident
-%! x = inv (u)*d*u;
-%! y = pinv (x, sqrt (eps));
-%!
-%!assert (a*b*a, a, tol)
-%!assert (b*a*b, b, tol)
-%!assert ((b*a)', b*a, tol)
-%!assert ((a*b)', a*b, tol)
-%!assert (x*y*x, x, -hitol)
-%!assert (y*x*y, y, -hitol)
-%!assert ((x*y)', x*y, hitol)
-%!assert ((y*x)', y*x, hitol)
-*/
--- a/src/DLD-FUNCTIONS/quad.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,518 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-
-#include <iomanip>
-#include <iostream>
-
-#include "Quad.h"
-#include "lo-mappers.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "pager.h"
-#include "oct-obj.h"
-#include "ov-fcn.h"
-#include "unwind-prot.h"
-#include "utils.h"
-#include "variables.h"
-
-#include "Quad-opts.cc"
-
-#if defined (quad)
-#undef quad
-#endif
-
-// Global pointer for user defined function required by quadrature functions.
-static octave_function *quad_fcn;
-
-// Have we warned about imaginary values returned from user function?
-static bool warned_imaginary = false;
-
-// Is this a recursive call?
-static int call_depth = 0;
-
-double
-quad_user_function (double x)
-{
-  double retval = 0.0;
-
-  octave_value_list args;
-  args(0) = x;
-
-  if (quad_fcn)
-    {
-      octave_value_list tmp = quad_fcn->do_multi_index_op (1, args);
-
-      if (error_state)
-        {
-          quad_integration_error = 1;  // FIXME
-          gripe_user_supplied_eval ("quad");
-          return retval;
-        }
-
-      if (tmp.length () && tmp(0).is_defined ())
-        {
-          if (! warned_imaginary && tmp(0).is_complex_type ())
-            {
-              warning ("quad: ignoring imaginary part returned from user-supplied function");
-              warned_imaginary = true;
-            }
-
-          retval = tmp(0).double_value ();
-
-          if (error_state)
-            {
-              quad_integration_error = 1;  // FIXME
-              gripe_user_supplied_eval ("quad");
-            }
-        }
-      else
-        {
-          quad_integration_error = 1;  // FIXME
-          gripe_user_supplied_eval ("quad");
-        }
-    }
-
-  return retval;
-}
-
-float
-quad_float_user_function (float x)
-{
-  float retval = 0.0;
-
-  octave_value_list args;
-  args(0) = x;
-
-  if (quad_fcn)
-    {
-      octave_value_list tmp = quad_fcn->do_multi_index_op (1, args);
-
-      if (error_state)
-        {
-          quad_integration_error = 1;  // FIXME
-          gripe_user_supplied_eval ("quad");
-          return retval;
-        }
-
-      if (tmp.length () && tmp(0).is_defined ())
-        {
-          if (! warned_imaginary && tmp(0).is_complex_type ())
-            {
-              warning ("quad: ignoring imaginary part returned from user-supplied function");
-              warned_imaginary = true;
-            }
-
-          retval = tmp(0).float_value ();
-
-          if (error_state)
-            {
-              quad_integration_error = 1;  // FIXME
-              gripe_user_supplied_eval ("quad");
-            }
-        }
-      else
-        {
-          quad_integration_error = 1;  // FIXME
-          gripe_user_supplied_eval ("quad");
-        }
-    }
-
-  return retval;
-}
-
-#define QUAD_ABORT() \
-  do \
-    { \
-      if (fcn_name.length ()) \
-        clear_function (fcn_name); \
-      return retval; \
-    } \
-  while (0)
-
-#define QUAD_ABORT1(msg) \
-  do \
-    { \
-      ::error ("quad: " msg); \
-      QUAD_ABORT (); \
-    } \
-  while (0)
-
-#define QUAD_ABORT2(fmt, arg) \
-  do \
-    { \
-      ::error ("quad: " fmt, arg); \
-      QUAD_ABORT (); \
-    } \
-  while (0)
-
-DEFUN_DLD (quad, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b})\n\
-@deftypefnx {Loadable Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b}, @var{tol})\n\
-@deftypefnx {Loadable Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b}, @var{tol}, @var{sing})\n\
-@deftypefnx {Loadable Function} {[@var{q}, @var{ier}, @var{nfun}, @var{err}] =} quad (@dots{})\n\
-Numerically evaluate the integral of @var{f} from @var{a} to @var{b} using\n\
-Fortran routines from @w{@sc{quadpack}}.  @var{f} is a function handle,\n\
-inline function, or a string containing the name of the function to\n\
-evaluate.  The function must have the form @code{y = f (x)} where @var{y} and\n\
-@var{x} are scalars.\n\
-\n\
-@var{a} and @var{b} are the lower and upper limits of integration.  Either\n\
-or both may be infinite.\n\
-\n\
-The optional argument @var{tol} is a vector that specifies the desired\n\
-accuracy of the result.  The first element of the vector is the desired\n\
-absolute tolerance, and the second element is the desired relative\n\
-tolerance.  To choose a relative test only, set the absolute\n\
-tolerance to zero.  To choose an absolute test only, set the relative\n\
-tolerance to zero.  Both tolerances default to @code{sqrt (eps)} or\n\
-approximately @math{1.5e^{-8}}.\n\
-\n\
-The optional argument @var{sing} is a vector of values at which the\n\
-integrand is known to be singular.\n\
-\n\
-The result of the integration is returned in @var{q}.  @var{ier}\n\
-contains an integer error code (0 indicates a successful integration).\n\
-@var{nfun} indicates the number of function evaluations that were\n\
-made, and @var{err} contains an estimate of the error in the\n\
-solution.\n\
-\n\
-The function @code{quad_options} can set other optional\n\
-parameters for @code{quad}.\n\
-\n\
-Note: because @code{quad} is written in Fortran it cannot be called\n\
-recursively.  This prevents its use in integrating over more than one\n\
-variable by routines @code{dblquad} and @code{triplequad}.\n\
-@seealso{quad_options, quadv, quadl, quadgk, quadcc, trapz, dblquad, triplequad}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  std::string fcn_name;
-
-  warned_imaginary = false;
-
-  unwind_protect frame;
-
-  frame.protect_var (call_depth);
-  call_depth++;
-
-  if (call_depth > 1)
-    QUAD_ABORT1 ("invalid recursive call");
-
-  int nargin = args.length ();
-
-  if (nargin > 2 && nargin < 6 && nargout < 5)
-    {
-      if (args(0).is_function_handle () || args(0).is_inline_function ())
-        quad_fcn = args(0).function_value ();
-      else
-        {
-          fcn_name = unique_symbol_name ("__quad_fcn_");
-          std::string fname = "function y = ";
-          fname.append (fcn_name);
-          fname.append ("(x) y = ");
-          quad_fcn = extract_function (args(0), "quad", fcn_name, fname,
-                                       "; endfunction");
-        }
-
-      if (! quad_fcn)
-        QUAD_ABORT ();
-
-      if (args(1).is_single_type () || args(2).is_single_type ())
-        {
-          float a = args(1).float_value ();
-
-          if (error_state)
-            QUAD_ABORT1 ("expecting second argument to be a scalar");
-
-          float b = args(2).float_value ();
-
-          if (error_state)
-            QUAD_ABORT1 ("expecting third argument to be a scalar");
-
-          int indefinite = 0;
-          FloatIndefQuad::IntegralType indef_type = FloatIndefQuad::doubly_infinite;
-          float bound = 0.0;
-          if (xisinf (a) && xisinf (b))
-            {
-              indefinite = 1;
-              indef_type = FloatIndefQuad::doubly_infinite;
-            }
-          else if (xisinf (a))
-            {
-              indefinite = 1;
-              bound = b;
-              indef_type = FloatIndefQuad::neg_inf_to_bound;
-            }
-          else if (xisinf (b))
-            {
-              indefinite = 1;
-              bound = a;
-              indef_type = FloatIndefQuad::bound_to_inf;
-            }
-
-          octave_idx_type ier = 0;
-          octave_idx_type nfun = 0;
-          float abserr = 0.0;
-          float val = 0.0;
-          bool have_sing = false;
-          FloatColumnVector sing;
-          FloatColumnVector tol;
-
-          switch (nargin)
-            {
-            case 5:
-              if (indefinite)
-                QUAD_ABORT1 ("singularities not allowed on infinite intervals");
-
-              have_sing = true;
-
-              sing = FloatColumnVector (args(4).float_vector_value ());
-
-              if (error_state)
-                QUAD_ABORT1 ("expecting vector of singularities as fourth argument");
-
-            case 4:
-              tol = FloatColumnVector (args(3).float_vector_value ());
-
-              if (error_state)
-                QUAD_ABORT1 ("expecting vector of tolerances as fifth argument");
-
-              switch (tol.capacity ())
-                {
-                case 2:
-                  quad_opts.set_single_precision_relative_tolerance (tol (1));
-
-                case 1:
-                  quad_opts.set_single_precision_absolute_tolerance (tol (0));
-                  break;
-
-                default:
-                  QUAD_ABORT1 ("expecting tol to contain no more than two values");
-                }
-
-            case 3:
-              if (indefinite)
-                {
-                  FloatIndefQuad iq (quad_float_user_function, bound,
-                                     indef_type);
-                  iq.set_options (quad_opts);
-                  val = iq.float_integrate (ier, nfun, abserr);
-                }
-              else
-                {
-                  if (have_sing)
-                    {
-                      FloatDefQuad dq (quad_float_user_function, a, b, sing);
-                      dq.set_options (quad_opts);
-                      val = dq.float_integrate (ier, nfun, abserr);
-                    }
-                  else
-                    {
-                      FloatDefQuad dq (quad_float_user_function, a, b);
-                      dq.set_options (quad_opts);
-                      val = dq.float_integrate (ier, nfun, abserr);
-                    }
-                }
-              break;
-
-            default:
-              panic_impossible ();
-              break;
-            }
-
-          retval(3) = abserr;
-          retval(2) = nfun;
-          retval(1) = ier;
-          retval(0) = val;
-
-        }
-      else
-        {
-          double a = args(1).double_value ();
-
-          if (error_state)
-            QUAD_ABORT1 ("expecting second argument to be a scalar");
-
-          double b = args(2).double_value ();
-
-          if (error_state)
-            QUAD_ABORT1 ("expecting third argument to be a scalar");
-
-          int indefinite = 0;
-          IndefQuad::IntegralType indef_type = IndefQuad::doubly_infinite;
-          double bound = 0.0;
-          if (xisinf (a) && xisinf (b))
-            {
-              indefinite = 1;
-              indef_type = IndefQuad::doubly_infinite;
-            }
-          else if (xisinf (a))
-            {
-              indefinite = 1;
-              bound = b;
-              indef_type = IndefQuad::neg_inf_to_bound;
-            }
-          else if (xisinf (b))
-            {
-              indefinite = 1;
-              bound = a;
-              indef_type = IndefQuad::bound_to_inf;
-            }
-
-          octave_idx_type ier = 0;
-          octave_idx_type nfun = 0;
-          double abserr = 0.0;
-          double val = 0.0;
-          bool have_sing = false;
-          ColumnVector sing;
-          ColumnVector tol;
-
-          switch (nargin)
-            {
-            case 5:
-              if (indefinite)
-                QUAD_ABORT1 ("singularities not allowed on infinite intervals");
-
-              have_sing = true;
-
-              sing = ColumnVector (args(4).vector_value ());
-
-              if (error_state)
-                QUAD_ABORT1 ("expecting vector of singularities as fourth argument");
-
-            case 4:
-              tol = ColumnVector (args(3).vector_value ());
-
-              if (error_state)
-                QUAD_ABORT1 ("expecting vector of tolerances as fifth argument");
-
-              switch (tol.capacity ())
-                {
-                case 2:
-                  quad_opts.set_relative_tolerance (tol (1));
-
-                case 1:
-                  quad_opts.set_absolute_tolerance (tol (0));
-                  break;
-
-                default:
-                  QUAD_ABORT1 ("expecting tol to contain no more than two values");
-                }
-
-            case 3:
-              if (indefinite)
-                {
-                  IndefQuad iq (quad_user_function, bound, indef_type);
-                  iq.set_options (quad_opts);
-                  val = iq.integrate (ier, nfun, abserr);
-                }
-              else
-                {
-                  if (have_sing)
-                    {
-                      DefQuad dq (quad_user_function, a, b, sing);
-                      dq.set_options (quad_opts);
-                      val = dq.integrate (ier, nfun, abserr);
-                    }
-                  else
-                    {
-                      DefQuad dq (quad_user_function, a, b);
-                      dq.set_options (quad_opts);
-                      val = dq.integrate (ier, nfun, abserr);
-                    }
-                }
-              break;
-
-            default:
-              panic_impossible ();
-              break;
-            }
-
-          retval(3) = abserr;
-          retval(2) = nfun;
-          retval(1) = ier;
-          retval(0) = val;
-        }
-
-      if (fcn_name.length ())
-        clear_function (fcn_name);
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!function y = __f (x)
-%!  y = x + 1;
-%!endfunction
-
-%!test
-%! [v, ier, nfun, err] = quad ("__f", 0, 5);
-%! assert (ier, 0);
-%! assert (v, 17.5, sqrt (eps));
-%! assert (nfun > 0);
-%! assert (err < sqrt (eps));
-
-%!test
-%! [v, ier, nfun, err] = quad ("__f", single (0), single (5));
-%! assert (ier, 0);
-%! assert (v, 17.5, sqrt (eps ("single")));
-%! assert (nfun > 0);
-%! assert (err < sqrt (eps ("single")));
-
-%!function y = __f (x)
-%!  y = x .* sin (1 ./ x) .* sqrt (abs (1 - x));
-%!endfunction
-
-%!test
-%!  [v, ier, nfun, err] = quad ("__f", 0.001, 3);
-%! assert (ier == 0 || ier == 1);
-%! assert (v, 1.98194120273598, sqrt (eps));
-%! assert (nfun > 0);
-
-%!test
-%!  [v, ier, nfun, err] = quad ("__f", single (0.001), single (3));
-%! assert (ier == 0 || ier == 1);
-%! assert (v, 1.98194120273598, sqrt (eps ("single")));
-%! assert (nfun > 0);
-
-%!error quad ()
-%!error quad ("__f", 1, 2, 3, 4, 5)
-
-%!test
-%! quad_options ("absolute tolerance", eps);
-%! assert (quad_options ("absolute tolerance") == eps);
-
-%!error quad_options (1, 2, 3)
-*/
--- a/src/DLD-FUNCTIONS/quadcc.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2263 +0,0 @@
-/*
-
-Copyright (C) 2010-2012 Pedro Gonnet
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include "lo-math.h"
-#include "lo-ieee.h"
-#include "oct.h"
-#include "parse.h"
-#include "ov-fcn-handle.h"
-
-/* Define the size of the interval heap. */
-#define cquad_heapsize                  200
-
-
-/* Data of a single interval */
-typedef struct
-{
-  double a, b;
-  double c[64];
-  double fx[33];
-  double igral, err;
-  int depth, rdepth, ndiv;
-} cquad_ival;
-
-/* Some constants and matrices that we'll need.  */
-
-static const double xi[33] = {
-  -1., -0.99518472667219688624, -0.98078528040323044912,
-  -0.95694033573220886493, -0.92387953251128675612,
-  -0.88192126434835502970, -0.83146961230254523708,
-  -0.77301045336273696082, -0.70710678118654752440,
-  -0.63439328416364549822, -0.55557023301960222475,
-  -0.47139673682599764857, -0.38268343236508977173,
-  -0.29028467725446236764, -0.19509032201612826785,
-  -0.098017140329560601995, 0., 0.098017140329560601995,
-  0.19509032201612826785, 0.29028467725446236764, 0.38268343236508977173,
-  0.47139673682599764857, 0.55557023301960222475, 0.63439328416364549822,
-  0.70710678118654752440, 0.77301045336273696082, 0.83146961230254523708,
-  0.88192126434835502970, 0.92387953251128675612, 0.95694033573220886493,
-  0.98078528040323044912, 0.99518472667219688624, 1.
-};
-
-static const double bee[68] = {
-  0.00000000000000e+00, 2.28868854108532e-01, 0.00000000000000e+00,
-  -8.15740215243451e-01, 0.00000000000000e+00, 5.31212715259731e-01,
-  0.00000000000000e+00, 1.38538036812454e-02, 0.00000000000000e+00,
-  3.74405228908818e-02, 0.00000000000000e+00, 2.12224115039342e-01,
-  0.00000000000000e+00, -8.16362644507898e-01, 0.00000000000000e+00,
-  5.35648426691481e-01, 0.00000000000000e+00, 1.52417902753662e-03,
-  0.00000000000000e+00, 2.63058840550873e-03, 0.00000000000000e+00,
-  4.15292106318904e-03, 0.00000000000000e+00, 6.97106011119775e-03,
-  0.00000000000000e+00, 1.35535708431058e-02, 0.00000000000000e+00,
-  3.52132898424856e-02, 0.00000000000000e+00, 2.06946714741884e-01,
-  0.00000000000000e+00, -8.15674251283876e-01, 0.00000000000000e+00,
-  5.38841175520580e-01, 0.00000000000000e+00, 1.84909689577590e-04,
-  0.00000000000000e+00, 2.90936325007499e-04, 0.00000000000000e+00,
-  3.84877750950089e-04, 0.00000000000000e+00, 4.86436656735046e-04,
-  0.00000000000000e+00, 6.08688640346879e-04, 0.00000000000000e+00,
-  7.66732830740331e-04, 0.00000000000000e+00, 9.82753336104205e-04,
-  0.00000000000000e+00, 1.29359957505615e-03, 0.00000000000000e+00,
-  1.76616363801885e-03, 0.00000000000000e+00, 2.53323433039089e-03,
-  0.00000000000000e+00, 3.88872172121956e-03, 0.00000000000000e+00,
-  6.58635106468291e-03, 0.00000000000000e+00, 1.30326736343254e-02,
-  0.00000000000000e+00, 3.44353850696714e-02, 0.00000000000000e+00,
-  2.05025409531915e-01, 0.00000000000000e+00, -8.14985893995401e-01,
-  0.00000000000000e+00, 5.40679930965238e-01
-};
-
-static const double Lalpha[33] = {
-  5.77350269189626e-01, 5.16397779494322e-01, 5.07092552837110e-01,
-  5.03952630678970e-01, 5.02518907629606e-01, 5.01745206004255e-01,
-  5.01280411827603e-01, 5.00979432868120e-01, 5.00773395667191e-01,
-  5.00626174321759e-01, 5.00517330712619e-01, 5.00434593736979e-01,
-  5.00370233297676e-01, 5.00319182924304e-01, 5.00278009473803e-01,
-  5.00244319584578e-01, 5.00216403386025e-01, 5.00193012939056e-01,
-  5.00173220168024e-01, 5.00156323280355e-01, 5.00141783641018e-01,
-  5.00129182278347e-01, 5.00118189340972e-01, 5.00108542278496e-01,
-  5.00100030010004e-01, 5.00092481273333e-01, 5.00085755939229e-01,
-  5.00079738458365e-01, 5.00074332862969e-01, 5.00069458915387e-01,
-  5.00065049112355e-01, 5.00061046334395e-01, 5.00057401986298e-01
-};
-
-static const double Lgamma[33] = {
-  0.0, 0.0, 5.16397779494322e-01, 5.07092552837110e-01, 5.03952630678970e-01,
-  5.02518907629606e-01, 5.01745206004255e-01, 5.01280411827603e-01,
-  5.00979432868120e-01, 5.00773395667191e-01, 5.00626174321759e-01,
-  5.00517330712619e-01, 5.00434593736979e-01, 5.00370233297676e-01,
-  5.00319182924304e-01, 5.00278009473803e-01, 5.00244319584578e-01,
-  5.00216403386025e-01, 5.00193012939056e-01, 5.00173220168024e-01,
-  5.00156323280355e-01, 5.00141783641018e-01, 5.00129182278347e-01,
-  5.00118189340972e-01, 5.00108542278496e-01, 5.00100030010003e-01,
-  5.00092481273333e-01, 5.00085755939229e-01, 5.00079738458365e-01,
-  5.00074332862969e-01, 5.00069458915387e-01, 5.00065049112355e-01,
-  5.00061046334395e-01
-};
-
-static const double V1inv[5 * 5] = {
-  .47140452079103168293e-1, .37712361663282534635, .56568542494923801952,
-  .37712361663282534635, .47140452079103168293e-1,
-  -.81649658092772603273e-1, -.46188021535170061160, 0,
-  .46188021535170061160, .81649658092772603273e-1, .15058465048420853962,
-  .12046772038736683169, -.54210474174315074262, .12046772038736683169,
-  .15058465048420853962, -.21380899352993950775, .30237157840738178177, -0.,
-  -.30237157840738178177, .21380899352993950775, .10774960475223581324,
-  -.21549920950447162648, .21549920950447162648, -.21549920950447162648,
-  .10774960475223581324
-};
-
-static const double V2inv[9 * 9] = {
-  .11223917161691230546e-1, .10339219839658349826, .19754094204576565761,
-  .25577315077753587922, .27835314560994251755, .25577315077753587922,
-  .19754094204576565761, .10339219839658349826, .11223917161691230546e-1,
-  -.19440394783993476970e-1, -.16544884625069155470, -.24193725566041460608,
-  -.16953338808305493604, 0.0, .16953338808305493604, .24193725566041460608,
-  .16544884625069155470, .19440394783993476970e-1, .26466393115406349388e-1,
-  .17766815796285469394, .11316664642449611462, -.16306601003711325980,
-  -.30847037493128779631, -.16306601003711325980, .11316664642449611462,
-  .17766815796285469394, .26466393115406349388e-1,
-  -.32395302049990834508e-1, -.15521142532414866547,
-  .88573492664788602740e-1, .29570405784974857322, 0.0,
-  -.29570405784974857322, -.88573492664788602740e-1, .15521142532414866547,
-  .32395302049990834508e-1, .41442155673936851246e-1,
-  .98186757907405608245e-1, -.23056908429499411784,
-  -.68047008326360625520e-1, .31797435808002456774,
-  -.68047008326360625520e-1, -.23056908429499411784,
-  .98186757907405608245e-1, .41442155673936851246e-1,
-  -.49981120317798783134e-1, -.24861810572835756217e-1,
-  .23561326072010832539, -.24472785656448415351, 0.0, .24472785656448415351,
-  -.23561326072010832539, .24861810572835756217e-1,
-  .49981120317798783134e-1, .79691635865674781228e-1,
-  -.95725617891693941833e-1, -.57957553356854386344e-1,
-  .21164072460540271452, -.27529837844505833514, .21164072460540271452,
-  -.57957553356854386344e-1, -.95725617891693941833e-1,
-  .79691635865674781228e-1,
-  -.10894869830716590913, .20131094491947531782, -.15407672674888869038,
-  .83385723639789791384e-1, 0.0, -.83385723639789791384e-1,
-  .15407672674888869038, -.20131094491947531782, .10894869830716590913,
-  .54581057089643838221e-1, -.10916211417928767644, .10916211417928767644,
-  -.10916211417928767644, .10916211417928767644, -.10916211417928767644,
-  .10916211417928767644, -.10916211417928767644, .54581057089643838221e-1
-};
-
-static const double V3inv[17 * 17] = {
-  .27729677693590098996e-2, .26423663180333065153e-1,
-  .53374068493933898312e-1, .77007854739523195947e-1,
-  .98257061072911596869e-1, .11538049741786835604, .12832134344120884559,
-  .13612785914022865001, .13888293186236181317, .13612785914022865001,
-  .12832134344120884559, .11538049741786835604, .98257061072911596869e-1,
-  .77007854739523195947e-1, .53374068493933898312e-1,
-  .26423663180333065153e-1, .27729677693590098996e-2,
-  -.48029210642807413690e-2, -.44887724635478800254e-1,
-  -.85409520147301089416e-1, -.11090267822061423050, -.12033983162705862441,
-  -.11102786862182788886, -.85054870109799336515e-1,
-  -.45998467987742225160e-1, 0.0, .45998467987742225160e-1,
-  .85054870109799336515e-1, .11102786862182788886, .12033983162705862441,
-  .11090267822061423050, .85409520147301089416e-1, .44887724635478800254e-1,
-  .48029210642807413690e-2, .62758546879582030087e-2,
-  .55561297093529155869e-1,
-  .93281491021051539742e-1, .92320151237493695139e-1,
-  .55077987469605684531e-1,
-  -.96998141716497488255e-2, -.80285961895427405567e-1,
-  -.13496839655913850224,
-  -.15512521776684524331, -.13496839655913850224, -.80285961895427405567e-1,
-  -.96998141716497488255e-2, .55077987469605684531e-1,
-  .92320151237493695139e-1, .93281491021051539742e-1,
-  .55561297093529155869e-1, .62758546879582030087e-2,
-  -.74850969394858555939e-2, -.61751608943839234096e-1,
-  -.82974150437304275958e-1, -.38437763431942633378e-1,
-  .45745502025779701366e-1, .12369235652734542162, .14720439712852868239,
-  .98768034347019704401e-1, 0.0,
-  -.98768034347019704401e-1, -.14720439712852868239, -.12369235652734542162,
-  -.45745502025779701366e-1, .38437763431942633378e-1,
-  .82974150437304275958e-1, .61751608943839234096e-1,
-  .74850969394858555939e-2, .86710099994384056338e-2,
-  .64006230103659573344e-1, .58517426396091675690e-1,
-  -.29743410528985802680e-1,
-  -.11934127779157114754, -.12686773515361299409, -.30729137153877447035e-1,
-  .97307836256600731568e-1, .15635811574451401023, .97307836256600731568e-1,
-  -.30729137153877447035e-1, -.12686773515361299409, -.11934127779157114754,
-  -.29743410528985802680e-1, .58517426396091675690e-1,
-  .64006230103659573344e-1, .86710099994384056338e-2,
-  -.97486395666294840165e-2, -.62995604908060224672e-1,
-  -.24373234450275529219e-1, .87760984413626872730e-1,
-  .12205204576993351394,
-  .16216004196864002088e-1, -.12422320942156845775, -.13682714580929614678,
-  0.0, .13682714580929614678, .12422320942156845775,
-  -.16216004196864002088e-1, -.12205204576993351394,
-  -.87760984413626872730e-1, .24373234450275529219e-1,
-  .62995604908060224672e-1, .97486395666294840165e-2,
-  .10956271233750488468e-1, .58613204255294358939e-1,
-  -.13306063940736618859e-1, -.11606666444978454399,
-  -.52059598001115805639e-1, .10868540217796151849, .12594452879014618005,
-  -.44678658254872910434e-1, -.15617684362128533405,
-  -.44678658254872910434e-1, .12594452879014618005, .10868540217796151849,
-  -.52059598001115805639e-1, -.11606666444978454399,
-  -.13306063940736618859e-1, .58613204255294358939e-1,
-  .10956271233750488468e-1, -.12098893000863087230e-1,
-  -.51626244709126208453e-1, .48919433304746979330e-1,
-  .10467644465949427090,
-  -.48729879523084673782e-1, -.13668732103524749234, .28190838706814496438e-1,
-  .15434223333238741600, 0.0, -.15434223333238741600,
-  -.28190838706814496438e-1, .13668732103524749234,
-  .48729879523084673782e-1, -.10467644465949427090,
-  -.48919433304746979330e-1, .51626244709126208453e-1,
-  .12098893000863087230e-1, .13542668300437944822e-1,
-  .41712033418258689308e-1,
-  -.76190463272803434388e-1, -.58303943170068132010e-1, .12158068748245606853,
-  .42121099930651007882e-1, -.14684425840766337756,
-  -.16108203535058647043e-1, .15698075850757976092,
-  -.16108203535058647043e-1, -.14684425840766337756,
-  .42121099930651007882e-1, .12158068748245606853,
-  -.58303943170068132010e-1, -.76190463272803434388e-1,
-  .41712033418258689308e-1, .13542668300437944822e-1,
-  -.14939634995117694417e-1, -.30047246373341564039e-1,
-  .91624635082546425678e-1, -.79133374319110026377e-2,
-  -.12292558212072233355, .90013382617762643524e-1,
-  .84013717196539593395e-1, -.14813033309980695856, 0.0,
-  .14813033309980695856, -.84013717196539593395e-1,
-  -.90013382617762643524e-1,
-  .12292558212072233355, .79133374319110026377e-2, -.91624635082546425678e-1,
-  .30047246373341564039e-1, .14939634995117694417e-1,
-  .16986031342807474208e-1,
-  .15760203882617033601e-1, -.91494054040950941996e-1,
-  .70082459207876130806e-1,
-  .53390713710144539104e-1, -.14340746778352039430, .84048122493418898508e-1,
-  .72456667788091316868e-1, -.15564535320096811360,
-  .72456667788091316868e-1, .84048122493418898508e-1,
-  -.14340746778352039430, .53390713710144539104e-1,
-  .70082459207876130806e-1, -.91494054040950941996e-1,
-  .15760203882617033601e-1,
-  .16986031342807474208e-1, -.18994065631858742028e-1,
-  -.82901821370405592927e-3, .77239669773015192888e-1,
-  -.10850735431039424680, .47524484622086496464e-1,
-  .69148184871588737021e-1, -.14829314646228194928, .11992057742398672066,
-  0.0, -.11992057742398672066, .14829314646228194928,
-  -.69148184871588737021e-1, -.47524484622086496464e-1,
-  .10850735431039424680, -.77239669773015192888e-1,
-  .82901821370405592927e-3, .18994065631858742028e-1,
-  .22761703826371535132e-1, -.17728848711449643358e-1,
-  -.47496371572480503788e-1, .10659958402328690063, -.11696013966166296514,
-  .63073750910894244526e-1, .32928881123602721303e-1,
-  -.12280950532497593683, .15926189077282729505, -.12280950532497593683,
-  .32928881123602721303e-1, .63073750910894244526e-1,
-  -.11696013966166296514, .10659958402328690063, -.47496371572480503788e-1,
-  -.17728848711449643358e-1, .22761703826371535132e-1,
-  -.26493215276042203434e-1, .35579780856128386192e-1,
-  .10447309718398935122e-1, -.68616154085314996709e-1,
-  .11775363082763954214, -.13918901977011837274, .12312819418827395690,
-  -.72053565748259077905e-1, 0.0, .72053565748259077905e-1,
-  -.12312819418827395690, .13918901977011837274, -.11775363082763954214,
-  .68616154085314996709e-1, -.10447309718398935122e-1,
-  -.35579780856128386192e-1,
-  .26493215276042203434e-1, .40742523354399706918e-1,
-  -.73124912999529117195e-1, .49317266444153837821e-1,
-  -.13686605413876015320e-1, -.28342624942191100464e-1,
-  .70371855298258216249e-1, -.10600251632853603875, .12981016288391131812,
-  -.13817029659318161476, .12981016288391131812, -.10600251632853603875,
-  .70371855298258216249e-1, -.28342624942191100464e-1,
-  -.13686605413876015320e-1,
-  .49317266444153837821e-1, -.73124912999529117195e-1,
-  .40742523354399706918e-1, -.54944368958699908688e-1,
-  .10777725663147408190, -.10152395581538265428, .91369146312596428468e-1,
-  -.77703071757424700773e-1, .61050911730999815031e-1,
-  -.42052599404498348871e-1, .21438229266251454773e-1, 0.0,
-  -.21438229266251454773e-1, .42052599404498348871e-1,
-  -.61050911730999815031e-1, .77703071757424700773e-1,
-  -.91369146312596428468e-1,
-  .10152395581538265428, -.10777725663147408190, .54944368958699908688e-1,
-  .27485608464748840573e-1, -.54971216929497681146e-1,
-  .54971216929497681146e-1,
-  -.54971216929497681146e-1, .54971216929497681146e-1,
-  -.54971216929497681146e-1, .54971216929497681146e-1,
-  -.54971216929497681146e-1, .54971216929497681146e-1,
-  -.54971216929497681146e-1, .54971216929497681146e-1,
-  -.54971216929497681146e-1, .54971216929497681146e-1,
-  -.54971216929497681146e-1, .54971216929497681146e-1,
-  -.54971216929497681146e-1, .27485608464748840573e-1
-};
-
-static const double V4inv[33 * 33] = {
-  .69120897476690862600e-3, .66419939766331555194e-2,
-  .13600665164323186111e-1, .20122785860913684493e-1,
-  .26583214101668429944e-1, .32712713318999268739e-1,
-  .38576221976287138036e-1, .44033030938268925133e-1,
-  .49092709529622799673e-1, .53657949874312515646e-1,
-  .57724533144734311859e-1, .61219564530655179096e-1,
-  .64138907503837875026e-1, .66427905189318792009e-1,
-  .68088956652280022887e-1, .69083051391555695878e-1,
-  .69422738116739271449e-1, .69083051391555695878e-1,
-  .68088956652280022887e-1, .66427905189318792009e-1,
-  .64138907503837875026e-1, .61219564530655179096e-1,
-  .57724533144734311859e-1, .53657949874312515646e-1,
-  .49092709529622799673e-1, .44033030938268925133e-1,
-  .38576221976287138036e-1, .32712713318999268739e-1,
-  .26583214101668429944e-1, .20122785860913684493e-1,
-  .13600665164323186111e-1, .66419939766331555194e-2,
-  .69120897476690862600e-3, -.11972090629438798134e-2,
-  -.11448874821643225573e-1, -.23104401104002905904e-1,
-  -.33352899418646530133e-1, -.42538626424075425908e-1,
-  -.49969730733911825941e-1, -.55555454015360728353e-1,
-  -.58955533624852604918e-1, -.60126044219122513907e-1,
-  -.58959430451175833624e-1, -.55546925396227130606e-1,
-  -.49984739749347973762e-1, -.42513009141170294365e-1,
-  -.33399140950669746346e-1, -.23007690803851790829e-1,
-  -.11728275717520066169e-1, 0.0, .11728275717520066169e-1,
-  .23007690803851790829e-1, .33399140950669746346e-1,
-  .42513009141170294365e-1, .49984739749347973762e-1,
-  .55546925396227130606e-1, .58959430451175833624e-1,
-  .60126044219122513907e-1, .58955533624852604918e-1,
-  .55555454015360728353e-1, .49969730733911825941e-1,
-  .42538626424075425908e-1, .33352899418646530133e-1,
-  .23104401104002905904e-1, .11448874821643225573e-1,
-  .11972090629438798134e-2, .15501585012936019146e-2,
-  .14628781502199620482e-1, .28684915921474815271e-1,
-  .39299396074628048026e-1, .46393418975496284204e-1,
-  .48756902531094699526e-1, .46331333488337494692e-1,
-  .39012645376980228775e-1, .27452795421085791153e-1,
-  .12430953621169863781e-1, -.47682978056024928800e-2,
-  -.22825828045428973853e-1,
-  -.40195512090720278312e-1, -.55503004262826221955e-1,
-  -.67424537752827046308e-1, -.75020199300113606452e-1,
-  -.77607844312483656131e-1, -.75020199300113606452e-1,
-  -.67424537752827046308e-1, -.55503004262826221955e-1,
-  -.40195512090720278312e-1, -.22825828045428973853e-1,
-  -.47682978056024928800e-2, .12430953621169863781e-1,
-  .27452795421085791153e-1, .39012645376980228775e-1,
-  .46331333488337494692e-1, .48756902531094699526e-1,
-  .46393418975496284204e-1, .39299396074628048026e-1,
-  .28684915921474815271e-1, .14628781502199620482e-1,
-  .15501585012936019146e-2, -.18377757558949194214e-2,
-  -.17050470050949761565e-1, -.31952119564923250836e-1,
-  -.40197423449026348155e-1,
-  -.41205649520281371624e-1, -.33909965817492272248e-1,
-  -.19393664422115332144e-1, .56661049630886784692e-3,
-  .22948272173686561721e-1, .44489719570904738207e-1,
-  .61790363672287920596e-1, .72121014727028013894e-1,
-  .73627151185287858579e-1, .65784665375961398923e-1,
-  .49369676372333667559e-1, .26444326317059715065e-1, 0.0,
-  -.26444326317059715065e-1, -.49369676372333667559e-1,
-  -.65784665375961398923e-1, -.73627151185287858579e-1,
-  -.72121014727028013894e-1, -.61790363672287920596e-1,
-  -.44489719570904738207e-1, -.22948272173686561721e-1,
-  -.56661049630886784692e-3, .19393664422115332144e-1,
-  .33909965817492272248e-1, .41205649520281371624e-1,
-  .40197423449026348155e-1, .31952119564923250836e-1,
-  .17050470050949761565e-1, .18377757558949194214e-2,
-  .20942714740729767769e-2, .18935902405146518232e-1,
-  .33335840852491735126e-1, .36770680999102286065e-1,
-  .28873194534132768509e-1, .10267303017729535513e-1,
-  -.14607738306201572890e-1, -.40139568545572305818e-1,
-  -.59808326733858291561e-1, -.68528358823372627506e-1,
-  -.63306535387619244879e-1, -.44508601817574921056e-1,
-  -.15449116105605395357e-1, .17941083795006546367e-1,
-  .48747356011657242123e-1, .70329553984201665523e-1,
-  .78106117292526169663e-1, .70329553984201665523e-1,
-  .48747356011657242123e-1, .17941083795006546367e-1,
-  -.15449116105605395357e-1, -.44508601817574921056e-1,
-  -.63306535387619244879e-1, -.68528358823372627506e-1,
-  -.59808326733858291561e-1,
-  -.40139568545572305818e-1, -.14607738306201572890e-1,
-  .10267303017729535513e-1, .28873194534132768509e-1,
-  .36770680999102286065e-1, .33335840852491735126e-1,
-  .18935902405146518232e-1, .20942714740729767769e-2,
-  -.23245285491878278419e-2, -.20401404737639389919e-1,
-  -.33019548231022514097e-1, -.29709828426463720091e-1,
-  -.11760070922697422156e-1, .15987584743850393793e-1,
-  .43619012891472813485e-1, .61177322409671487721e-1,
-  .61144030218486655594e-1,
-  .41895377620089086167e-1, .80232011820644308033e-2,
-  -.30574701186675900915e-1,
-  -.62072243008844865848e-1, -.76336186183574765586e-1,
-  -.68435466095345537115e-1, -.40237669208466966207e-1, 0.0,
-  .40237669208466966207e-1, .68435466095345537115e-1,
-  .76336186183574765586e-1, .62072243008844865848e-1,
-  .30574701186675900915e-1, -.80232011820644308033e-2,
-  -.41895377620089086167e-1, -.61144030218486655594e-1,
-  -.61177322409671487721e-1, -.43619012891472813485e-1,
-  -.15987584743850393793e-1, .11760070922697422156e-1,
-  .29709828426463720091e-1, .33019548231022514097e-1,
-  .20401404737639389919e-1, .23245285491878278419e-2,
-  .25451717261579269307e-2, .21480418595666878775e-1,
-  .31177212469293007998e-1, .19816333607013379373e-1,
-  -.72439496274458793681e-2, -.38404203906598342397e-1,
-  -.57633632255322221046e-1, -.54070547403585392952e-1,
-  -.26249823354368866005e-1, .15643058212336881516e-1,
-  .54539832735118677194e-1, .73283028002473989724e-1,
-  .62835303524135936213e-1, .26175977027801048141e-1,
-  -.22193636309998606610e-1, -.62597049956093311234e-1,
-  -.78206986173170212505e-1, -.62597049956093311234e-1,
-  -.22193636309998606610e-1, .26175977027801048141e-1,
-  .62835303524135936213e-1,
-  .73283028002473989724e-1, .54539832735118677194e-1,
-  .15643058212336881516e-1,
-  -.26249823354368866005e-1, -.54070547403585392952e-1,
-  -.57633632255322221046e-1, -.38404203906598342397e-1,
-  -.72439496274458793681e-2, .19816333607013379373e-1,
-  .31177212469293007998e-1, .21480418595666878775e-1,
-  .25451717261579269307e-2, -.27506573922483820005e-2,
-  -.22224442095099251870e-1, -.27949927254215773020e-1,
-  -.80918481053370034987e-2, .25121859354449306916e-1,
-  .51563535009373061074e-1, .51936965107145960512e-1,
-  .22146626648171527753e-1,
-  -.24172689882103382748e-1, -.61731229104853568296e-1,
-  -.68477262429344201201e-1, -.38311232728303704742e-1,
-  .14160578713659552679e-1, .61248813427564184033e-1,
-  .77136328841293031805e-1, .52514801765183697988e-1, 0.0,
-  -.52514801765183697988e-1, -.77136328841293031805e-1,
-  -.61248813427564184033e-1, -.14160578713659552679e-1,
-  .38311232728303704742e-1,
-  .68477262429344201201e-1, .61731229104853568296e-1,
-  .24172689882103382748e-1,
-  -.22146626648171527753e-1, -.51936965107145960512e-1,
-  -.51563535009373061074e-1, -.25121859354449306916e-1,
-  .80918481053370034987e-2, .27949927254215773020e-1,
-  .22224442095099251870e-1, .27506573922483820005e-2,
-  .29562461131654311467e-2, .22630271480554450613e-1,
-  .23547399831373800971e-1, -.43964593440902476642e-2,
-  -.39055315767504970597e-1, -.52369643937940066804e-1,
-  -.28506131614971613422e-1, .19906048093338832322e-1,
-  .60408880866392420279e-1, .62493397473656883090e-1,
-  .21391278377641297859e-1, -.37302864786623254746e-1,
-  -.73665127933539496872e-1, -.61706142476854010202e-1,
-  -.78065168882546327888e-2, .52335307373945544428e-1,
-  .78278746279419264777e-1, .52335307373945544428e-1,
-  -.78065168882546327888e-2, -.61706142476854010202e-1,
-  -.73665127933539496872e-1, -.37302864786623254746e-1,
-  .21391278377641297859e-1, .62493397473656883090e-1,
-  .60408880866392420279e-1, .19906048093338832322e-1,
-  -.28506131614971613422e-1, -.52369643937940066804e-1,
-  -.39055315767504970597e-1, -.43964593440902476642e-2,
-  .23547399831373800971e-1, .22630271480554450613e-1,
-  .29562461131654311467e-2, -.31515718415504761303e-2,
-  -.22739451096655080673e-1, -.18157123602272119779e-1,
-  .16496480897167303621e-1, .46921166788569301124e-1,
-  .40644395739978416354e-1, -.46275803430732216900e-2,
-  -.52883375891308909486e-1, -.61116483226324111734e-1,
-  -.17411698764545629853e-1, .44773430013166822765e-1,
-  .73441577962383869198e-1, .42127368371995472815e-1,
-  -.25504645957196772465e-1, -.74126818045972742488e-1,
-  -.62780077864719287317e-1, 0.0, .62780077864719287317e-1,
-  .74126818045972742488e-1, .25504645957196772465e-1,
-  -.42127368371995472815e-1, -.73441577962383869198e-1,
-  -.44773430013166822765e-1, .17411698764545629853e-1,
-  .61116483226324111734e-1, .52883375891308909486e-1,
-  .46275803430732216900e-2, -.40644395739978416354e-1,
-  -.46921166788569301124e-1, -.16496480897167303621e-1,
-  .18157123602272119779e-1, .22739451096655080673e-1,
-  .31515718415504761303e-2, .33536559294882188208e-2,
-  .22535348942792006185e-1,
-  .12048629300953560767e-1, -.27166076791299493403e-1,
-  -.47492745604230978367e-1, -.19246623430993153174e-1,
-  .36231297307556299322e-1, .61713617181636122004e-1,
-  .25928029734266134490e-1, -.40478700752883602818e-1,
-  -.71053889866326412049e-1, -.31870824482961751482e-1,
-  .41515251100219081281e-1, .76481960760098381651e-1,
-  .36726509155999912440e-1, -.40090067032627055969e-1,
-  -.78270742903374539397e-1, -.40090067032627055969e-1,
-  .36726509155999912440e-1, .76481960760098381651e-1,
-  .41515251100219081281e-1, -.31870824482961751482e-1,
-  -.71053889866326412049e-1, -.40478700752883602818e-1,
-  .25928029734266134490e-1, .61713617181636122004e-1,
-  .36231297307556299322e-1, -.19246623430993153174e-1,
-  -.47492745604230978367e-1, -.27166076791299493403e-1,
-  .12048629300953560767e-1, .22535348942792006185e-1,
-  .33536559294882188208e-2,
-  -.35481220456925318865e-2, -.22062913693073191150e-1,
-  -.54487362861834144999e-2, .35438821865804087489e-1,
-  .40733077820527411302e-1, -.67403098138950720914e-2,
-  -.55559584405239171054e-1, -.42417050790865158745e-1,
-  .24499901971884704925e-1, .68721232891705409302e-1,
-  .34086082787461126592e-1, -.43441000373118474002e-1,
-  -.73878085292669148950e-1, -.18846995664706657127e-1,
-  .59827776178286834498e-1, .70644634584085901794e-1, 0.0,
-  -.70644634584085901794e-1, -.59827776178286834498e-1,
-  .18846995664706657127e-1, .73878085292669148950e-1,
-  .43441000373118474002e-1, -.34086082787461126592e-1,
-  -.68721232891705409302e-1, -.24499901971884704925e-1,
-  .42417050790865158745e-1, .55559584405239171054e-1,
-  .67403098138950720914e-2, -.40733077820527411302e-1,
-  -.35438821865804087489e-1, .54487362861834144999e-2,
-  .22062913693073191150e-1, .35481220456925318865e-2,
-  .37554176816665075631e-2, .21297045781589919482e-1,
-  -.13327293083183431816e-2,
-  -.40635299172764596484e-1, -.27659860508374175359e-1,
-  .31089232744083445986e-1, .56113781541334176109e-1,
-  .37577840643257763400e-2, -.60511227350664590865e-1,
-  -.46670556446129053853e-1, .33263195878575888247e-1,
-  .72757324720645228775e-1, .15011712351692283635e-1,
-  -.65601212994924119078e-1, -.60016855838843789772e-1,
-  .26220858553188665966e-1, .78322776605833552980e-1,
-  .26220858553188665966e-1, -.60016855838843789772e-1,
-  -.65601212994924119078e-1,
-  .15011712351692283635e-1, .72757324720645228775e-1,
-  .33263195878575888247e-1,
-  -.46670556446129053853e-1, -.60511227350664590865e-1,
-  .37577840643257763400e-2, .56113781541334176109e-1,
-  .31089232744083445986e-1, -.27659860508374175359e-1,
-  -.40635299172764596484e-1, -.13327293083183431816e-2,
-  .21297045781589919482e-1, .37554176816665075631e-2,
-  -.39566995305720591229e-2, -.20291873414438919995e-1,
-  .80617453830770930551e-2, .42270189157016547906e-1,
-  .10332624526759093004e-1, -.48054759547616142024e-1,
-  -.37678032941171643972e-1,
-  .36617192625732482394e-1, .61009425973424865714e-1,
-  -.95589113168026591466e-2,
-  -.71023202645076922361e-1, -.25097788086808784456e-1,
-  .62406621963267050244e-1, .56907293171100693511e-1,
-  -.36435383083882206257e-1, -.75790105119208756348e-1, 0.0,
-  .75790105119208756348e-1, .36435383083882206257e-1,
-  -.56907293171100693511e-1, -.62406621963267050244e-1,
-  .25097788086808784456e-1, .71023202645076922361e-1,
-  .95589113168026591466e-2,
-  -.61009425973424865714e-1, -.36617192625732482394e-1,
-  .37678032941171643972e-1, .48054759547616142024e-1,
-  -.10332624526759093004e-1, -.42270189157016547906e-1,
-  -.80617453830770930551e-2, .20291873414438919995e-1,
-  .39566995305720591229e-2, .41776092289182138591e-2,
-  .19013221163904414395e-1, -.14420609729849899876e-1,
-  -.40259160586844441220e-1, .86327811113710831649e-2,
-  .53564430703021034399e-1, .65469185402150431933e-2,
-  -.60383116311280629856e-1,
-  -.25657793784058876939e-1, .58745680576829226900e-1,
-  .45649937869034420296e-1,
-  -.49167932056844167772e-1, -.62696614328552187977e-1,
-  .32540234556426699997e-1, .74280410383464269758e-1,
-  -.11425672633410999870e-1, -.78280649404686404903e-1,
-  -.11425672633410999870e-1, .74280410383464269758e-1,
-  .32540234556426699997e-1, -.62696614328552187977e-1,
-  -.49167932056844167772e-1, .45649937869034420296e-1,
-  .58745680576829226900e-1, -.25657793784058876939e-1,
-  -.60383116311280629856e-1, .65469185402150431933e-2,
-  .53564430703021034399e-1,
-  .86327811113710831649e-2, -.40259160586844441220e-1,
-  -.14420609729849899876e-1, .19013221163904414395e-1,
-  .41776092289182138591e-2, -.43935502082478059199e-2,
-  -.17528761237509401631e-1, .20208915249153872535e-1,
-  .34734743119040669109e-1, -.26275910172353637955e-1,
-  -.46368003346018878786e-1,
-  .26800056330709381025e-1, .56681476464606609921e-1,
-  -.24749011438127255898e-1,
-  -.64934612189056658992e-1, .20333742247679279535e-1,
-  .71429299070059318651e-1,
-  -.14452513210428671266e-1, -.75793341281736586582e-1,
-  .74717094137184935270e-2, .78034921554757317374e-1, 0.0,
-  -.78034921554757317374e-1, -.74717094137184935270e-2,
-  .75793341281736586582e-1, .14452513210428671266e-1,
-  -.71429299070059318651e-1, -.20333742247679279535e-1,
-  .64934612189056658992e-1, .24749011438127255898e-1,
-  -.56681476464606609921e-1,
-  -.26800056330709381025e-1, .46368003346018878786e-1,
-  .26275910172353637955e-1,
-  -.34734743119040669109e-1, -.20208915249153872535e-1,
-  .17528761237509401631e-1, .43935502082478059199e-2,
-  .46379089482818671473e-2, .15791188144791287229e-1,
-  -.25134290048737455284e-1, -.26249795071946841205e-1,
-  .39960457575789924651e-1, .28111892450146525404e-1,
-  -.51026476400767918226e-1,
-  -.27266747278681831364e-1, .60708796647861610865e-1,
-  .23532306960642115854e-1,
-  -.68169639871532441111e-1, -.18204924701958312032e-1,
-  .73822890510656128485e-1, .11373392486424717019e-1,
-  -.77133324017644609416e-1, -.39295877480342619961e-2,
-  .78351902829418987960e-1, -.39295877480342619961e-2,
-  -.77133324017644609416e-1, .11373392486424717019e-1,
-  .73822890510656128485e-1, -.18204924701958312032e-1,
-  -.68169639871532441111e-1, .23532306960642115854e-1,
-  .60708796647861610865e-1, -.27266747278681831364e-1,
-  -.51026476400767918226e-1, .28111892450146525404e-1,
-  .39960457575789924651e-1, -.26249795071946841205e-1,
-  -.25134290048737455284e-1, .15791188144791287229e-1,
-  .46379089482818671473e-2, -.48780095920069827068e-2,
-  -.13886961667516983541e-1, .29071311049368895844e-1,
-  .15480559452075811600e-1, -.47527977686242313065e-1,
-  -.31929089844361042178e-2, .58015667638415922967e-1,
-  -.14547915466597622925e-1, -.61067668299848923244e-1,
-  .35093678009090186851e-1, .55378399159800654657e-1,
-  -.54277226474891610385e-1, -.42023830782434076509e-1,
-  .69197384645944912066e-1, .22610783557709586445e-1,
-  -.77269275900637030185e-1, 0.0, .77269275900637030185e-1,
-  -.22610783557709586445e-1,
-  -.69197384645944912066e-1, .42023830782434076509e-1,
-  .54277226474891610385e-1,
-  -.55378399159800654657e-1, -.35093678009090186851e-1,
-  .61067668299848923244e-1, .14547915466597622925e-1,
-  -.58015667638415922967e-1, .31929089844361042178e-2,
-  .47527977686242313065e-1, -.15480559452075811600e-1,
-  -.29071311049368895844e-1, .13886961667516983541e-1,
-  .48780095920069827068e-2, .51591759101720291381e-2,
-  .11747497650231330965e-1, -.31777863364694653331e-1,
-  -.34555825499804605557e-2, .47914131921157015198e-1,
-  -.22573685920142225247e-1, -.45320344390022666738e-1,
-  .49660630547172186418e-1, .25707858143963615736e-1,
-  -.68132707341917233933e-1, .67534860185243140399e-2,
-  .69268150370037450063e-1, -.41585011920451477177e-1,
-  -.51622397460510041271e-1, .68408139576363036148e-1,
-  .18981259024768933323e-1, -.78265472429342305554e-1,
-  .18981259024768933323e-1, .68408139576363036148e-1,
-  -.51622397460510041271e-1,
-  -.41585011920451477177e-1, .69268150370037450063e-1,
-  .67534860185243140399e-2,
-  -.68132707341917233933e-1, .25707858143963615736e-1,
-  .49660630547172186418e-1,
-  -.45320344390022666738e-1, -.22573685920142225247e-1,
-  .47914131921157015198e-1, -.34555825499804605557e-2,
-  -.31777863364694653331e-1, .11747497650231330965e-1,
-  .51591759101720291381e-2, -.54365757412741340377e-2,
-  -.94862516619529080191e-2, .33240472093448190877e-1,
-  -.88698898099681552229e-2,
-  -.40973252097216337576e-1, .42995673349795657065e-1,
-  .17320914507876958783e-1,
-  -.62201292691914856803e-1, .24726274174637346693e-1,
-  .51320859246515407288e-1,
-  -.62882063373810501763e-1, -.11003569131725622672e-1,
-  .73842261324108943465e-1, -.39240120294802923208e-1,
-  -.49293966443941122807e-1, .73552644778818223475e-1, 0.0,
-  -.73552644778818223475e-1, .49293966443941122807e-1,
-  .39240120294802923208e-1, -.73842261324108943465e-1,
-  .11003569131725622672e-1, .62882063373810501763e-1,
-  -.51320859246515407288e-1,
-  -.24726274174637346693e-1, .62201292691914856803e-1,
-  -.17320914507876958783e-1, -.42995673349795657065e-1,
-  .40973252097216337576e-1, .88698898099681552229e-2,
-  -.33240472093448190877e-1, .94862516619529080191e-2,
-  .54365757412741340377e-2, .57750194549356126240e-2,
-  .69981166020044116791e-2, -.33274982140403110792e-1,
-  .20297071020698356116e-1, .27898517839646066582e-1,
-  -.53368678853282030262e-1, .16656482990394548343e-1,
-  .46342901447260614255e-1,
-  -.60536796508149003365e-1, .29109107483842596340e-2,
-  .63224486124385124504e-1,
-  -.59028872851312033411e-1, -.14783105962696191734e-1,
-  .74269399241069253865e-1, -.49053677339382384625e-1,
-  -.33525466624811186739e-1, .78397349622515386647e-1,
-  -.33525466624811186739e-1, -.49053677339382384625e-1,
-  .74269399241069253865e-1, -.14783105962696191734e-1,
-  -.59028872851312033411e-1,
-  .63224486124385124504e-1, .29109107483842596340e-2,
-  -.60536796508149003365e-1,
-  .46342901447260614255e-1, .16656482990394548343e-1,
-  -.53368678853282030262e-1,
-  .27898517839646066582e-1, .20297071020698356116e-1,
-  -.33274982140403110792e-1,
-  .69981166020044116791e-2, .57750194549356126240e-2,
-  -.61100308370519200637e-2, -.44383614355738148616e-2,
-  .32011283412619094811e-1, -.29965011866372897633e-1,
-  -.10560682331349193348e-1, .51110336443392506342e-1,
-  -.45012284729681775492e-1, -.94236825555873320102e-2,
-  .60860695783141264746e-1,
-  -.55014628647083368926e-1, -.73474782382499482121e-2,
-  .66640148475243034781e-1, -.62533116045749887988e-1,
-  -.38650525912400102585e-2, .68429769005837003777e-1,
-  -.66984505412544901945e-1, 0.0, .66984505412544901945e-1,
-  -.68429769005837003777e-1, .38650525912400102585e-2,
-  .62533116045749887988e-1, -.66640148475243034781e-1,
-  .73474782382499482121e-2,
-  .55014628647083368926e-1, -.60860695783141264746e-1,
-  .94236825555873320102e-2,
-  .45012284729681775492e-1, -.51110336443392506342e-1,
-  .10560682331349193348e-1,
-  .29965011866372897633e-1, -.32011283412619094811e-1,
-  .44383614355738148616e-2,
-  .61100308370519200637e-2, .65409373892036191538e-2,
-  .16350101107071157065e-2, -.29301957285983144319e-1,
-  .36838667173388832579e-1, -.81922703976491586393e-2,
-  -.36955670021050133434e-1, .58374851095540469865e-1,
-  -.31977016246946181856e-1, -.25311073698658094646e-1,
-  .66674413950106952577e-1,
-  -.54865713324521039571e-1, -.39797027891537985440e-2,
-  .62830285264808449064e-1, -.72226313251296100676e-1,
-  .22560232697133353980e-1, .46455784709904033738e-1,
-  -.78200930751070349956e-1, .46455784709904033738e-1,
-  .22560232697133353980e-1, -.72226313251296100676e-1,
-  .62830285264808449064e-1, -.39797027891537985440e-2,
-  -.54865713324521039571e-1, .66674413950106952577e-1,
-  -.25311073698658094646e-1, -.31977016246946181856e-1,
-  .58374851095540469865e-1, -.36955670021050133434e-1,
-  -.81922703976491586393e-2, .36838667173388832579e-1,
-  -.29301957285983144319e-1, .16350101107071157065e-2,
-  .65409373892036191538e-2, -.69686180931868703196e-2,
-  .11849538727632789870e-2, .25452286414610537766e-1,
-  -.40522480651713943230e-1, .25694679053362813183e-1,
-  .14057118113748390637e-1, -.52037614725803488893e-1,
-  .58849342223684035589e-1,
-  -.25075229077361409271e-1, -.29559771094034181083e-1,
-  .68296746944165720199e-1, -.62890462146423984955e-1,
-  .14457636466274596445e-1, .45787612031322361496e-1,
-  -.77231759014655809742e-1, .57881203613910543657e-1, 0.0,
-  -.57881203613910543657e-1, .77231759014655809742e-1,
-  -.45787612031322361496e-1, -.14457636466274596445e-1,
-  .62890462146423984955e-1,
-  -.68296746944165720199e-1, .29559771094034181083e-1,
-  .25075229077361409271e-1,
-  -.58849342223684035589e-1, .52037614725803488893e-1,
-  -.14057118113748390637e-1, -.25694679053362813183e-1,
-  .40522480651713943230e-1, -.25452286414610537766e-1,
-  -.11849538727632789870e-2, .69686180931868703196e-2,
-  .75611653617520254845e-2, -.43290610418608409141e-2,
-  -.20277062025115566914e-1,
-  .40362947027704828926e-1, -.38938808024132120254e-1,
-  .11831186195916702262e-1,
-  .28476667401744525357e-1, -.59320969056617684621e-1,
-  .61101629747436200186e-1,
-  -.29514834848355389223e-1, -.20668001885001084821e-1,
-  .62923592802445122793e-1, -.73558456263588833115e-1,
-  .45314556330160999776e-1, .79031645918426015574e-2,
-  -.58136953576334689357e-1, .78538474524006405758e-1,
-  -.58136953576334689357e-1, .79031645918426015574e-2,
-  .45314556330160999776e-1, -.73558456263588833115e-1,
-  .62923592802445122793e-1, -.20668001885001084821e-1,
-  -.29514834848355389223e-1, .61101629747436200186e-1,
-  -.59320969056617684621e-1, .28476667401744525357e-1,
-  .11831186195916702262e-1, -.38938808024132120254e-1,
-  .40362947027704828926e-1, -.20277062025115566914e-1,
-  -.43290610418608409141e-2, .75611653617520254845e-2,
-  -.81505692478987769484e-2, .74297333588288568430e-2,
-  .14314212513540223314e-1, -.36711242251332751607e-1,
-  .46240027755503814626e-1, -.34921532671769023773e-1,
-  .46930051972353714773e-2,
-  .32842770336385381562e-1, -.61317813706529588466e-1,
-  .67000809902468893103e-1,
-  -.45337449655535622885e-1, .35794459576271920867e-2,
-  .41830061526027213385e-1,
-  -.72091371931944711708e-1, .74150028530317793195e-1,
-  -.46487632538609942002e-1, 0.0, .46487632538609942002e-1,
-  -.74150028530317793195e-1, .72091371931944711708e-1,
-  -.41830061526027213385e-1, -.35794459576271920867e-2,
-  .45337449655535622885e-1, -.67000809902468893103e-1,
-  .61317813706529588466e-1, -.32842770336385381562e-1,
-  -.46930051972353714773e-2, .34921532671769023773e-1,
-  -.46240027755503814626e-1, .36711242251332751607e-1,
-  -.14314212513540223314e-1, -.74297333588288568430e-2,
-  .81505692478987769484e-2, .90693182942442189743e-2,
-  -.11121000903959576737e-1, -.71308296141317458546e-2,
-  .29219439765986671645e-1, -.45820286629778129593e-1,
-  .49088381175879124421e-1, -.35614888785023038938e-1,
-  .78906970900092777895e-2,
-  .26262843038404929480e-1, -.56143674270125757857e-1,
-  .71700220472378350694e-1,
-  -.66963544500697307945e-1, .42215091779892228883e-1,
-  -.41338867413966866997e-2, -.36164891772995367321e-1,
-  .66584367783847858225e-1, -.77874712365070098328e-1,
-  .66584367783847858225e-1, -.36164891772995367321e-1,
-  -.41338867413966866997e-2, .42215091779892228883e-1,
-  -.66963544500697307945e-1,
-  .71700220472378350694e-1, -.56143674270125757857e-1,
-  .26262843038404929480e-1,
-  .78906970900092777895e-2, -.35614888785023038938e-1,
-  .49088381175879124421e-1,
-  -.45820286629778129593e-1, .29219439765986671645e-1,
-  -.71308296141317458546e-2, -.11121000903959576737e-1,
-  .90693182942442189743e-2, -.99848472706332791043e-2,
-  .14701271465939718856e-1, -.32917820356048383366e-3,
-  -.19201195309873585230e-1, .38409681836626963278e-1,
-  -.51647324405878909521e-1, .54522171113149311354e-1,
-  -.45040302741689006270e-1, .24183738595685990149e-1,
-  .42204134165479735097e-2, -.34317295181348742251e-1,
-  .59542472465494579941e-1, -.74135115907618101263e-1,
-  .74491937840566532596e-1, -.60042604725161994304e-1,
-  .33437677409000083169e-1, 0.0,
-  -.33437677409000083169e-1, .60042604725161994304e-1,
-  -.74491937840566532596e-1, .74135115907618101263e-1,
-  -.59542472465494579941e-1, .34317295181348742251e-1,
-  -.42204134165479735097e-2, -.24183738595685990149e-1,
-  .45040302741689006270e-1, -.54522171113149311354e-1,
-  .51647324405878909521e-1, -.38409681836626963278e-1,
-  .19201195309873585230e-1, .32917820356048383366e-3,
-  -.14701271465939718856e-1, .99848472706332791043e-2,
-  .11775579274769383373e-1, -.19892153937316935880e-1,
-  .95335114477449041055e-2, .57661528440359081617e-2,
-  -.23382690532380910781e-1, .40237257037170725321e-1,
-  -.53280289903551636474e-1, .59974361806023689068e-1,
-  -.58701684061992853224e-1, .49033407111597129616e-1,
-  -.31818835267847249219e-1, .90800541261162098886e-2,
-  .16272906819312603838e-1, -.40863896581186229487e-1,
-  .61346046297517367703e-1,
-  -.74896047554167268919e-1, .79632642148310325817e-1,
-  -.74896047554167268919e-1, .61346046297517367703e-1,
-  -.40863896581186229487e-1, .16272906819312603838e-1,
-  .90800541261162098886e-2, -.31818835267847249219e-1,
-  .49033407111597129616e-1, -.58701684061992853224e-1,
-  .59974361806023689068e-1, -.53280289903551636474e-1,
-  .40237257037170725321e-1, -.23382690532380910781e-1,
-  .57661528440359081617e-2, .95335114477449041055e-2,
-  -.19892153937316935880e-1,
-  .11775579274769383373e-1, -.13562702617218467450e-1,
-  .24885419969649845849e-1, -.18368693901908875583e-1,
-  .81673147806084084638e-2, .47890591326129587131e-2,
-  -.19313752945227974024e-1, .34065953398362954708e-1,
-  -.47667045133463415672e-1, .58820377816690514309e-1,
-  -.66424139824618415970e-1,
-  .69667606260856092515e-1, -.68102459384364543253e-1,
-  .61683024923302547971e-1,
-  -.50771943476441639136e-1, .36110771847327189215e-1,
-  -.18758028464284563358e-1, 0.0, .18758028464284563358e-1,
-  -.36110771847327189215e-1, .50771943476441639136e-1,
-  -.61683024923302547971e-1, .68102459384364543253e-1,
-  -.69667606260856092515e-1, .66424139824618415970e-1,
-  -.58820377816690514309e-1, .47667045133463415672e-1,
-  -.34065953398362954708e-1, .19313752945227974024e-1,
-  -.47890591326129587131e-2, -.81673147806084084638e-2,
-  .18368693901908875583e-1, -.24885419969649845849e-1,
-  .13562702617218467450e-1, .20576545037980523979e-1,
-  -.40093155172981004337e-1, .36954083167944054826e-1,
-  -.31856506837591907746e-1, .24996323181546255126e-1,
-  -.16637165210473614136e-1, .71002706773325085237e-2,
-  .32478629093205201133e-2,
-  -.14009562579050569518e-1, .24771262248780618922e-1,
-  -.35119395835433647559e-1, .44656290368574753171e-1,
-  -.53015448339647394161e-1, .59875631995693046782e-1,
-  -.64973208326045193862e-1, .68112280331082143373e-1,
-  -.69172215234062186994e-1, .68112280331082143373e-1,
-  -.64973208326045193862e-1, .59875631995693046782e-1,
-  -.53015448339647394161e-1, .44656290368574753171e-1,
-  -.35119395835433647559e-1, .24771262248780618922e-1,
-  -.14009562579050569518e-1, .32478629093205201133e-2,
-  .71002706773325085237e-2, -.16637165210473614136e-1,
-  .24996323181546255126e-1, -.31856506837591907746e-1,
-  .36954083167944054826e-1, -.40093155172981004337e-1,
-  .20576545037980523979e-1, -.27584914609096156163e-1,
-  .54904171411058497973e-1, -.54109756419563083153e-1,
-  .52794234894345577483e-1, -.50970276026831042415e-1,
-  .48655445537990983379e-1,
-  -.45872036510847994332e-1, .42646854695899611372e-1,
-  -.39010960357087507670e-1, .34999369144476467749e-1,
-  -.30650714874402762189e-1, .26006877464703437057e-1,
-  -.21112579608213651273e-1, .16014956068786763273e-1,
-  -.10763099747751940252e-1, .54075888924374485533e-2, 0.0,
-  -.54075888924374485533e-2, .10763099747751940252e-1,
-  -.16014956068786763273e-1,
-  .21112579608213651273e-1, -.26006877464703437057e-1,
-  .30650714874402762189e-1,
-  -.34999369144476467749e-1, .39010960357087507670e-1,
-  -.42646854695899611372e-1, .45872036510847994332e-1,
-  -.48655445537990983379e-1, .50970276026831042415e-1,
-  -.52794234894345577483e-1, .54109756419563083153e-1,
-  -.54904171411058497973e-1, .27584914609096156163e-1,
-  .13794141262469565740e-1, -.27588282524939131481e-1,
-  .27588282524939131481e-1, -.27588282524939131481e-1,
-  .27588282524939131481e-1, -.27588282524939131481e-1,
-  .27588282524939131481e-1,
-  -.27588282524939131481e-1, .27588282524939131481e-1,
-  -.27588282524939131481e-1, .27588282524939131481e-1,
-  -.27588282524939131481e-1, .27588282524939131481e-1,
-  -.27588282524939131481e-1, .27588282524939131481e-1,
-  -.27588282524939131481e-1, .27588282524939131481e-1,
-  -.27588282524939131481e-1, .27588282524939131481e-1,
-  -.27588282524939131481e-1, .27588282524939131481e-1,
-  -.27588282524939131481e-1, .27588282524939131481e-1,
-  -.27588282524939131481e-1, .27588282524939131481e-1,
-  -.27588282524939131481e-1, .27588282524939131481e-1,
-  -.27588282524939131481e-1, .27588282524939131481e-1,
-  -.27588282524939131481e-1, .27588282524939131481e-1,
-  -.27588282524939131481e-1, .13794141262469565740e-1
-};
-
-static const double Tleft[33 * 33] = {
-  1., -.86602540378443864678, 0., .33071891388307382381, 0.,
-  -.20728904939721249057, 0., .15128841196122722208, 0.,
-  -.11918864298744029244, 0., .98352013661686631224e-1, 0.,
-  -.83727065404940845733e-1, 0., .72893399403505841203e-1, 0.,
-  -.64544632643375022436e-1, 0., .57913170372415565639e-1, 0.,
-  -.52518242575729562263e-1, 0., .48043311993977520457e-1, 0.,
-  -.44271433659733990243e-1, 0., .41048928022856771981e-1, 0.,
-  -.38263878662008271459e-1, 0., .35832844026365304501e-1, 0., 0.,
-  .50000000000000000000, -.96824583655185422130, .57282196186948000082,
-  .21650635094610966169, -.35903516540862679125, -.97578093724974971969e-1,
-  .26203921611325660506, .55792409597991015609e-1, -.20644078533943456204,
-  -.36172381205961199479e-1, .17035068468874958194,
-  .25371838001497225980e-1, -.14501953125000000000,
-  -.18786835250972344757e-1, .12625507130328301066,
-  .14473795929590520582e-1, -.11179458309419422675,
-  -.11494434254897626155e-1, .10030855351241635862,
-  .93498556820544479096e-2, -.90964264465390582629e-1,
-  -.77546391824364392762e-2, .83213457337452292745e-1,
-  .65358085945588638605e-2, -.76680372422574234569e-1,
-  -.55835321940047427169e-2, .71098828931825789428e-1,
-  .48253327982967591019e-2, -.66274981937248958553e-1,
-  -.42118078245337801387e-2, .62064306433355646267e-1,
-  .37083386598903548973e-2, 0., 0., .25000000000000000000,
-  -.73950997288745200531, .83852549156242113615, -.23175620272173946716,
-  -.37791833195149451496, .25710129174850522325, .21608307321780204633,
-  -.22844049245646009157, -.14009503000335388415, .19897685605518413847,
-  .98264706042471226893e-1, -.17445445004279014046,
-  -.72761100054958328401e-1, .15463589893742108388,
-  .56056770591708784481e-1, -.13855313872640495158,
-  -.44517752443294564781e-1, .12534277657695128850,
-  .36211835346039665762e-1, -.11434398255136139683,
-  -.30033588409423828125e-1, .10506705408753910481,
-  .25313077840725783008e-1, -.97149327637744872155e-1,
-  -.21624927200393328444e-1, .90319582367202122625e-1,
-  .18688433567711780666e-1, -.84372291635345108584e-1,
-  -.16312261561845420752e-1, .79149526894804751586e-1,
-  .14362333871852474757e-1, 0., 0., 0., .12500000000000000000,
-  -.49607837082461073572, .82265291131801144317, -.59621200088559103072,
-  -.80054302859059362371e-1, .42612156697795759420,
-  -.90098145270865592887e-1, -.29769623255090078484, .13630307904779758221,
-  .21638835185708931831, -.14600247270306082052, -.16348801804014290453,
-  .14340708728599057249, .12755243353979286190, -.13661523715071346961,
-  -.10215585947881057394, .12864248070157166547, .83592528025348693602e-1,
-  -.12066728689302565222, -.69633728678718053052e-1, .11314245177331919532,
-  .58882939251410088028e-1, -.10621835858758221487,
-  -.50432266865187597572e-1, .99916834723527771581e-1,
-  .43672094283057258509e-1, -.94206380251950852413e-1,
-  -.38181356812697746418e-1, .89035739656537771225e-1,
-  .33661934598216332678e-1, 0., 0., 0., 0., .62500000000000000000e-1,
-  -.31093357409581873586, .67604086414949799246, -.75644205980613611039,
-  .28990586430124175741, .30648508196770360914, -.35801372616842500052,
-  -.91326869828709014708e-1, .31127929687500000000,
-  -.90915752838698393094e-2, -.25637381283965534330,
-  .57601077850322797594e-1, .21019685709225757945,
-  -.81244992138514014256e-1, -.17375078516720988858,
-  .92289437277967051125e-1, .14527351914265391374,
-  -.96675340792832019889e-1, -.12289485697108543415,
-  .97448175340011084006e-1, .10511755943298339844,
-  -.96242247086378239657e-1, -.90822942272780513537e-1,
-  .93966350452322132384e-1, .79189411876493712558e-1,
-  -.91139307067989309325e-1, -.69613039934383197265e-1,
-  .88062491671135767870e-1, .61646331729340817494e-1, 0., 0., 0., 0., 0.,
-  .31250000000000000000e-1, -.18684782411095934408, .50176689760410660236,
-  -.74784031498626095398, .56472001151566251186, .14842464993721351203e-1,
-  -.41162920273003120936, .20243071230196532282, .23772054897172750436,
-  -.24963810923972235950, -.12116179938394678936, .24330535483519110663,
-  .47903849781124471359e-1, -.22133299683101224293,
-  -.20542915138527200983e-2, .19653465717678146728,
-  -.26818172626509178444e-1, -.17319122357631210944,
-  .45065391411065545445e-1, .15253391395444065941,
-  -.56543897711725408302e-1, -.13469154928743585367,
-  .63632471400208840155e-1, .11941684923913523817,
-  -.67828850207933293098e-1, -.10636309084510652670,
-  .70095786922999181504e-1, .95187373095150709082e-1, 0., 0., 0., 0., 0.,
-  0., .15625000000000000000e-1, -.10909562534194485289,
-  .34842348626527747318, -.64461114561628111443, .69382480527334683659,
-  -.29551102358528827763, -.25527584713978439819, .38878771718544715394,
-  -.82956185835347407489e-2, -.31183177761966943912, .12831420840372374767,
-  .22067618205599434368, -.17569196937129496961, -.14598057000132284135,
-  .18864406621763419484, .89921002550386645767e-1, -.18571835020187122114,
-  -.48967672227195481777e-1, .17584685670380332798,
-  .19267984545067426324e-1, -.16335437520503462738,
-  .22598055455032407594e-2, .15032800884170631129,
-  -.17883358353754640871e-1, -.13774837869432209951,
-  .29227555960587143675e-1, .12604194747513151053, 0., 0., 0., 0., 0., 0.,
-  0., .78125000000000000000e-2, -.62377810244809812496e-1,
-  .23080781467370883845, -.50841310636012325368, .69834547012574056043,
-  -.52572723156526459672, .11464215704954976471e-1, .38698869011491210342,
-  -.26125646622255207507, -.16951698812361607510, .29773875898928782269,
-  .20130501202570367491e-1, -.26332493149159310198,
-  .67734613690401207009e-1, .21207315477103762715, -.11541543390889415193,
-  -.16249634759782417533, .13885887405041735068, .11996491328010275427,
-  -.14810432001630926895, -.85177658352556243411e-1, .14918860659904380587,
-  .57317789510444151564e-1, -.14569827645586660151,
-  -.35213090145965327390e-1, .13975998126844578198, 0., 0., 0., 0., 0., 0.,
-  0., 0., .39062500000000000000e-2, -.35101954600803571207e-1,
-  .14761284084133737720, -.37655033076080192966, .62410290231517322776,
-  -.64335622317683389875, .28188168266139524244, .22488495672137010675,
-  -.39393811089283576186, .75184777995770096714e-1, .28472023119398293003,
-  -.20410910833705899572, -.15590046962908511750, .23814567544617953125,
-  .54442805556829031204e-1, -.22855930338589720954,
-  .16303223615756629897e-1, .20172722433875559213,
-  -.62723406421217419404e-1, -.17012230831020922010,
-  .91754642766136561612e-1, .13927644821381121197, -.10886600968068418181,
-  -.11139075654373395292, .11797455976331702879, 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., .19531250000000000000e-2, -.19506820659607596598e-1,
-  .91865676095362231937e-1, -.26604607809696493849, .51425874205091288223,
-  -.66047561132505329292, .48660109511591303851, -.17575661168678285615e-1,
-  -.36594333408055703366, .29088854695378694533, .11318677346656537927,
-  -.31110645235730182168, .60733219161008787341e-1, .24333848233620420826,
-  -.15254312332655419708, -.15995968483455388613, .19010344455215289289,
-  .86040636766440260000e-1, -.19652589954665259945,
-  -.27633388517205837713e-1, .18660848552712880387,
-  -.15942583868416775867e-1, -.16902042462382064786,
-  .47278526495327740646e-1, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  .97656250000000000000e-3, -.10731084460857378207e-1,
-  .55939644713816406331e-1, -.18118487371914493668, .39914857299829864263,
-  -.60812322949933902435, .60011887183061967583, -.26002695805835928795,
-  -.20883922404786010096, .38988130966114638081, -.11797833550782589082,
-  -.25231824756239520077, .24817859972953934712, .90516417677868996417e-1,
-  -.26079073291293066798, .30259468817169480161e-1, .22178195264114178432,
-  -.10569877864302048175, -.16679648389266977455, .14637718550245050850,
-  .11219272032739559870, -.16359363640525750353, -.64358194509092101393e-1,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .48828125000000000000e-3,
-  -.58542865274813470967e-2, .33461741635290096452e-1,
-  -.11979993155896201271, .29580223766987206958, -.51874761979436016742,
-  .62861483498014306968, -.44868895761051453296, .12567502628371529386e-1,
-  .35040366183235474275, -.30466868455569500886, -.70903913601490112666e-1,
-  .30822791893032512740, -.11969443264190207736, -.20764760317621313946,
-  .20629838355452128532, .95269702915334718507e-1, -.22432624768705133300,
-  -.33103381593477797101e-2, .20570036048155716333,
-  -.62208282720094518964e-1, -.17095309330441436348, 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., .24414062500000000000e-3,
-  -.31714797501871532475e-2, .19721062526127334100e-1,
-  -.77311181185536498246e-1, .21124871792841566575, -.41777980401893650886,
-  .59401977834943551650, -.56132417807488349048, .23433675061367565951,
-  .20222775295220942126, -.38280372496506190127, .14443804214023095767,
-  .22268950939178466797, -.27211314150777981984, -.34184876506180717313e-1,
-  .26006498895669734842, -.97650425186005090107e-1, -.19024527660129101293,
-  .16789164198044635671, .10875811641651905252, -.19276785058805921298, 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .12207031250000000000e-3,
-  -.17078941137247586143e-2, .11477733754843910060e-1,
-  -.48887017020924625462e-1, .14634927241421789683, -.32156282683019547854,
-  .52165811920227223937, -.60001958466396926460, .41208501541480733755,
-  -.11366945503190350975e-2, -.33968093962672089159, .30955190935923386766,
-  .40657421856578262210e-1, -.29873400409871531764, .16094481791768257440,
-  .16876122436206497694, -.23650217045022161255, -.33070260090574765012e-1,
-  .22985258456375907796, -.68645651043827097771e-1, 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., .61035156250000000000e-4,
-  -.91501857608428649078e-3, .66085179496951987952e-2,
-  -.30383171695850355404e-1, .98840838845366876117e-1,
-  -.23855447246420318989, .43322017468145613917, -.58049033744876107191,
-  .52533893203742699346, -.20681056202371946180, -.20180000924562504384,
-  .37503922291962681797, -.15988102869837429062, -.19823558102762374094,
-  .28393023878803799622, -.11188133439357510403e-1, -.24730368377168229255,
-  .14731529061377942839, .14878558042884266021, 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., .30517578125000000000e-4,
-  -.48804277318479845551e-3, .37696080990601968396e-2,
-  -.18603912108994738255e-1, .65325006755649582964e-1,
-  -.17162960707938819795, .34411527956476971322, -.52289350347082497959,
-  .57319653625674910592, -.37662253421045430413, -.14099055105384663902e-1,
-  .33265570610216904208, -.30921265572647566661, -.19911390594166455281e-1,
-  .28738590811031797718, -.18912130469738472647, -.13235936203215819193,
-  .25076406142356675279, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., .15258789062500000000e-4, -.25928719280954633249e-3,
-  .21327398937568540428e-2, -.11244626133630732010e-1,
-  .42375605740664331966e-1, -.12031130345907846211, .26352562258934426830,
-  -.44590628258512682078, .56682835613700749379, -.49116715128261660395,
-  .17845943097110339078, .20541650677432497477, -.36739803642257458221,
-  .16776034069210108273, .17920950989905112908, -.28867732805385066532,
-  .46473465543376206337e-1, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., .76293945312500000000e-5, -.13727610943181290891e-3,
-  .11979683091449349286e-2, -.67195313034570709806e-2,
-  .27044920779931968175e-1, -.82472196498517457862e-1,
-  .19570475044896150093, -.36391620788543817693, .52241392782736588032,
-  -.54727504974907879912, .34211551468813581183, .31580472732719957762e-1,
-  -.32830006549176759667, .30563797665254420769, .64905014620683140120e-2,
-  -.27642986248995073032, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., .38146972656250000000e-5,
-  -.72454147007837596854e-4, .66859847582761390285e-3,
-  -.39751311980366118437e-2, .17015198650201528366e-1,
-  -.55443621868993855715e-1, .14157060481641692131, -.28641242619559616836,
-  .45610665490966615415, -.55262786406029265394, .45818352706035500108,
-  -.14984403004611673047, -.21163807462970713245, .36007252928843413718,
-  -.17030961385712954159, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., .19073486328125000000e-5,
-  -.38135049864067468562e-4, .37101393638555730015e-3,
-  -.23305339886279723213e-2, .10569913448297127219e-1,
-  -.36640175162216897547e-1, .10010476414320235508, -.21860074212675559892,
-  .38124757096345313719, -.52020999209879669177, .52172632730659212045,
-  -.30841620620308814614, -.50322546186721500184e-1, .32577618885114899053,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., .95367431640625000000e-6, -.20021483206955925244e-4,
-  .20481807322420625431e-3, -.13553476938058909882e-2,
-  .64919676350791905019e-2, -.23848725425069251903e-1,
-  .69384632678886421292e-1, -.16249711393618776934, .30736618106830314788,
-  -.46399909601971539157, .53765031034002467225, -.42598991476520183929,
-  .12130445348350215652, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., .47683715820312500000e-6,
-  -.10487707828484902486e-4, .11254146162337528943e-3,
-  -.78248929534271987118e-3, .39468337145306794566e-2,
-  -.15313546659475671763e-1, .47249070825218564146e-1,
-  -.11804374107101480543, .24031796927792491122, -.39629215049166341285,
-  .51629108968402548545, -.49622372075429782915, 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  .23841857910156250000e-6, -.54823314130625337326e-5,
-  .61575377321535518154e-4, -.44877834366497538134e-3,
-  .23774612048621955857e-2, -.97136347645161687796e-2,
-  .31671599547606636717e-1, -.84028665767000747480e-1,
-  .18298487576742964949, -.32647878537696945218, .46970971486488895077, 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., .11920928955078125000e-6, -.28604020001177375838e-5,
-  .33559227978295551013e-4, -.25583821662860610560e-3,
-  .14201552747787302339e-2, -.60938046986874414969e-2,
-  .20930869247951926793e-1, -.58745021125678072911e-1,
-  .13613725780285953720, -.26083988356030237586, 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  .59604644775390625000e-7, -.14898180663526043291e-5,
-  .18224991282807693921e-4, -.14504433444608833821e-3,
-  .84184722720281809548e-3, -.37846965430000478789e-2,
-  .13656355548211376864e-1, -.40409541997718853934e-1,
-  .99226988101858325902e-1, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  .29802322387695312500e-7, -.77471708843445529468e-6,
-  .98649879372606876995e-5, -.81814934772838523887e-4,
-  .49554483992403011328e-3, -.23290922072351413938e-2,
-  .88068134250844034186e-2, -.27393666952485719070e-1, 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., .14901161193847656250e-7, -.40226235946098233685e-6,
-  .53236418690561306700e-5, -.45933829691164002269e-4,
-  .28982005232838857913e-3, -.14212974043211018374e-2,
-  .56192363087488842264e-2, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  .74505805969238281250e-8, -.20858299254133430408e-6,
-  .28648457300134381744e-5, -.25677535898258910850e-4,
-  .16849420429491355445e-3, -.86062824010315834002e-3, 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., .37252902984619140625e-8, -.10801736017613096861e-6,
-  .15376606719887104015e-5, -.14296523739727437959e-4,
-  .97419023656050887203e-4, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  .18626451492309570312e-8, -.55871592916438890146e-7,
-  .82331193828137454068e-6, -.79302250528382787666e-5, 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., .93132257461547851562e-9,
-  -.28867244235852488244e-7, .43982811713864556957e-6, 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., .46566128730773925781e-9,
-  -.14899342093408253335e-7, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-  0., 0., .23283064365386962891e-9
-};
-
-static const double Tright[33 * 33] = {
-  1., .86602540378443864678, 0., -.33071891388307382381, 0.,
-    .20728904939721249057, 0., -.15128841196122722208, 0.,
-    .11918864298744029244, 0., -.98352013661686631224e-1, 0.,
-    .83727065404940845733e-1, 0., -.72893399403505841203e-1, 0.,
-    .64544632643375022436e-1, 0., -.57913170372415565639e-1, 0.,
-    .52518242575729562263e-1, 0., -.48043311993977520457e-1, 0.,
-    .44271433659733990243e-1, 0., -.41048928022856771981e-1, 0.,
-    .38263878662008271459e-1, 0., -.35832844026365304501e-1, 0., 0.,
-    .50000000000000000000, .96824583655185422130, .57282196186948000082,
-    -.21650635094610966169, -.35903516540862679125, .97578093724974971969e-1,
-    .26203921611325660506, -.55792409597991015609e-1, -.20644078533943456204,
-    .36172381205961199479e-1, .17035068468874958194,
-    -.25371838001497225980e-1, -.14501953125000000000,
-    .18786835250972344757e-1, .12625507130328301066,
-    -.14473795929590520582e-1, -.11179458309419422675,
-    .11494434254897626155e-1, .10030855351241635862,
-    -.93498556820544479096e-2, -.90964264465390582629e-1,
-    .77546391824364392762e-2, .83213457337452292745e-1,
-    -.65358085945588638605e-2, -.76680372422574234569e-1,
-    .55835321940047427169e-2, .71098828931825789428e-1,
-    -.48253327982967591019e-2, -.66274981937248958553e-1,
-    .42118078245337801387e-2, .62064306433355646267e-1,
-    -.37083386598903548973e-2, 0., 0., .25000000000000000000,
-    .73950997288745200531, .83852549156242113615, .23175620272173946716,
-    -.37791833195149451496, -.25710129174850522325, .21608307321780204633,
-    .22844049245646009157, -.14009503000335388415, -.19897685605518413847,
-    .98264706042471226893e-1, .17445445004279014046,
-    -.72761100054958328401e-1, -.15463589893742108388,
-    .56056770591708784481e-1, .13855313872640495158,
-    -.44517752443294564781e-1, -.12534277657695128850,
-    .36211835346039665762e-1, .11434398255136139683,
-    -.30033588409423828125e-1, -.10506705408753910481,
-    .25313077840725783008e-1, .97149327637744872155e-1,
-    -.21624927200393328444e-1, -.90319582367202122625e-1,
-    .18688433567711780666e-1, .84372291635345108584e-1,
-    -.16312261561845420752e-1, -.79149526894804751586e-1,
-    .14362333871852474757e-1, 0., 0., 0., .12500000000000000000,
-    .49607837082461073572, .82265291131801144317, .59621200088559103072,
-    -.80054302859059362371e-1, -.42612156697795759420,
-    -.90098145270865592887e-1, .29769623255090078484, .13630307904779758221,
-    -.21638835185708931831, -.14600247270306082052, .16348801804014290453,
-    .14340708728599057249, -.12755243353979286190, -.13661523715071346961,
-    .10215585947881057394, .12864248070157166547, -.83592528025348693602e-1,
-    -.12066728689302565222, .69633728678718053052e-1, .11314245177331919532,
-    -.58882939251410088028e-1, -.10621835858758221487,
-    .50432266865187597572e-1, .99916834723527771581e-1,
-    -.43672094283057258509e-1, -.94206380251950852413e-1,
-    .38181356812697746418e-1, .89035739656537771225e-1,
-    -.33661934598216332678e-1, 0., 0., 0., 0., .62500000000000000000e-1,
-    .31093357409581873586, .67604086414949799246, .75644205980613611039,
-    .28990586430124175741, -.30648508196770360914, -.35801372616842500052,
-    .91326869828709014708e-1, .31127929687500000000, .90915752838698393094e-2,
-    -.25637381283965534330, -.57601077850322797594e-1, .21019685709225757945,
-    .81244992138514014256e-1, -.17375078516720988858,
-    -.92289437277967051125e-1, .14527351914265391374,
-    .96675340792832019889e-1, -.12289485697108543415,
-    -.97448175340011084006e-1, .10511755943298339844,
-    .96242247086378239657e-1, -.90822942272780513537e-1,
-    -.93966350452322132384e-1, .79189411876493712558e-1,
-    .91139307067989309325e-1, -.69613039934383197265e-1,
-    -.88062491671135767870e-1, .61646331729340817494e-1, 0., 0., 0., 0., 0.,
-    .31250000000000000000e-1, .18684782411095934408, .50176689760410660236,
-    .74784031498626095398, .56472001151566251186, -.14842464993721351203e-1,
-    -.41162920273003120936, -.20243071230196532282, .23772054897172750436,
-    .24963810923972235950, -.12116179938394678936, -.24330535483519110663,
-    .47903849781124471359e-1, .22133299683101224293,
-    -.20542915138527200983e-2, -.19653465717678146728,
-    -.26818172626509178444e-1, .17319122357631210944,
-    .45065391411065545445e-1, -.15253391395444065941,
-    -.56543897711725408302e-1, .13469154928743585367,
-    .63632471400208840155e-1, -.11941684923913523817,
-    -.67828850207933293098e-1, .10636309084510652670,
-    .70095786922999181504e-1, -.95187373095150709082e-1, 0., 0., 0., 0., 0.,
-    0., .15625000000000000000e-1, .10909562534194485289,
-    .34842348626527747318, .64461114561628111443, .69382480527334683659,
-    .29551102358528827763, -.25527584713978439819, -.38878771718544715394,
-    -.82956185835347407489e-2, .31183177761966943912, .12831420840372374767,
-    -.22067618205599434368, -.17569196937129496961, .14598057000132284135,
-    .18864406621763419484, -.89921002550386645767e-1, -.18571835020187122114,
-    .48967672227195481777e-1, .17584685670380332798,
-    -.19267984545067426324e-1, -.16335437520503462738,
-    -.22598055455032407594e-2, .15032800884170631129,
-    .17883358353754640871e-1, -.13774837869432209951,
-    -.29227555960587143675e-1, .12604194747513151053, 0., 0., 0., 0., 0., 0.,
-    0., .78125000000000000000e-2, .62377810244809812496e-1,
-    .23080781467370883845, .50841310636012325368, .69834547012574056043,
-    .52572723156526459672, .11464215704954976471e-1, -.38698869011491210342,
-    -.26125646622255207507, .16951698812361607510, .29773875898928782269,
-    -.20130501202570367491e-1, -.26332493149159310198,
-    -.67734613690401207009e-1, .21207315477103762715, .11541543390889415193,
-    -.16249634759782417533, -.13885887405041735068, .11996491328010275427,
-    .14810432001630926895, -.85177658352556243411e-1, -.14918860659904380587,
-    .57317789510444151564e-1, .14569827645586660151,
-    -.35213090145965327390e-1, -.13975998126844578198, 0., 0., 0., 0., 0., 0.,
-    0., 0., .39062500000000000000e-2, .35101954600803571207e-1,
-    .14761284084133737720, .37655033076080192966, .62410290231517322776,
-    .64335622317683389875, .28188168266139524244, -.22488495672137010675,
-    -.39393811089283576186, -.75184777995770096714e-1, .28472023119398293003,
-    .20410910833705899572, -.15590046962908511750, -.23814567544617953125,
-    .54442805556829031204e-1, .22855930338589720954, .16303223615756629897e-1,
-    -.20172722433875559213, -.62723406421217419404e-1, .17012230831020922010,
-    .91754642766136561612e-1, -.13927644821381121197, -.10886600968068418181,
-    .11139075654373395292, .11797455976331702879, 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., .19531250000000000000e-2, .19506820659607596598e-1,
-    .91865676095362231937e-1, .26604607809696493849, .51425874205091288223,
-    .66047561132505329292, .48660109511591303851, .17575661168678285615e-1,
-    -.36594333408055703366, -.29088854695378694533, .11318677346656537927,
-    .31110645235730182168, .60733219161008787341e-1, -.24333848233620420826,
-    -.15254312332655419708, .15995968483455388613, .19010344455215289289,
-    -.86040636766440260000e-1, -.19652589954665259945,
-    .27633388517205837713e-1, .18660848552712880387, .15942583868416775867e-1,
-    -.16902042462382064786, -.47278526495327740646e-1, 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., .97656250000000000000e-3, .10731084460857378207e-1,
-    .55939644713816406331e-1, .18118487371914493668, .39914857299829864263,
-    .60812322949933902435, .60011887183061967583, .26002695805835928795,
-    -.20883922404786010096, -.38988130966114638081, -.11797833550782589082,
-    .25231824756239520077, .24817859972953934712, -.90516417677868996417e-1,
-    -.26079073291293066798, -.30259468817169480161e-1, .22178195264114178432,
-    .10569877864302048175, -.16679648389266977455, -.14637718550245050850,
-    .11219272032739559870, .16359363640525750353, -.64358194509092101393e-1,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .48828125000000000000e-3,
-    .58542865274813470967e-2, .33461741635290096452e-1, .11979993155896201271,
-    .29580223766987206958, .51874761979436016742, .62861483498014306968,
-    .44868895761051453296, .12567502628371529386e-1, -.35040366183235474275,
-    -.30466868455569500886, .70903913601490112666e-1, .30822791893032512740,
-    .11969443264190207736, -.20764760317621313946, -.20629838355452128532,
-    .95269702915334718507e-1, .22432624768705133300,
-    -.33103381593477797101e-2, -.20570036048155716333,
-    -.62208282720094518964e-1, .17095309330441436348, 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., .24414062500000000000e-3,
-    .31714797501871532475e-2, .19721062526127334100e-1,
-    .77311181185536498246e-1, .21124871792841566575, .41777980401893650886,
-    .59401977834943551650, .56132417807488349048, .23433675061367565951,
-    -.20222775295220942126, -.38280372496506190127, -.14443804214023095767,
-    .22268950939178466797, .27211314150777981984, -.34184876506180717313e-1,
-    -.26006498895669734842, -.97650425186005090107e-1, .19024527660129101293,
-    .16789164198044635671, -.10875811641651905252, -.19276785058805921298, 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .12207031250000000000e-3,
-    .17078941137247586143e-2, .11477733754843910060e-1,
-    .48887017020924625462e-1, .14634927241421789683, .32156282683019547854,
-    .52165811920227223937, .60001958466396926460, .41208501541480733755,
-    .11366945503190350975e-2, -.33968093962672089159, -.30955190935923386766,
-    .40657421856578262210e-1, .29873400409871531764, .16094481791768257440,
-    -.16876122436206497694, -.23650217045022161255, .33070260090574765012e-1,
-    .22985258456375907796, .68645651043827097771e-1, 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., .61035156250000000000e-4,
-    .91501857608428649078e-3, .66085179496951987952e-2,
-    .30383171695850355404e-1, .98840838845366876117e-1, .23855447246420318989,
-    .43322017468145613917, .58049033744876107191, .52533893203742699346,
-    .20681056202371946180, -.20180000924562504384, -.37503922291962681797,
-    -.15988102869837429062, .19823558102762374094, .28393023878803799622,
-    .11188133439357510403e-1, -.24730368377168229255, -.14731529061377942839,
-    .14878558042884266021, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., .30517578125000000000e-4, .48804277318479845551e-3,
-    .37696080990601968396e-2, .18603912108994738255e-1,
-    .65325006755649582964e-1, .17162960707938819795, .34411527956476971322,
-    .52289350347082497959, .57319653625674910592, .37662253421045430413,
-    -.14099055105384663902e-1, -.33265570610216904208, -.30921265572647566661,
-    .19911390594166455281e-1, .28738590811031797718, .18912130469738472647,
-    -.13235936203215819193, -.25076406142356675279, 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .15258789062500000000e-4,
-    .25928719280954633249e-3, .21327398937568540428e-2,
-    .11244626133630732010e-1, .42375605740664331966e-1, .12031130345907846211,
-    .26352562258934426830, .44590628258512682078, .56682835613700749379,
-    .49116715128261660395, .17845943097110339078, -.20541650677432497477,
-    -.36739803642257458221, -.16776034069210108273, .17920950989905112908,
-    .28867732805385066532, .46473465543376206337e-1, 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .76293945312500000000e-5,
-    .13727610943181290891e-3, .11979683091449349286e-2,
-    .67195313034570709806e-2, .27044920779931968175e-1,
-    .82472196498517457862e-1, .19570475044896150093, .36391620788543817693,
-    .52241392782736588032, .54727504974907879912, .34211551468813581183,
-    -.31580472732719957762e-1, -.32830006549176759667, -.30563797665254420769,
-    .64905014620683140120e-2, .27642986248995073032, 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .38146972656250000000e-5,
-    .72454147007837596854e-4, .66859847582761390285e-3,
-    .39751311980366118437e-2, .17015198650201528366e-1,
-    .55443621868993855715e-1, .14157060481641692131, .28641242619559616836,
-    .45610665490966615415, .55262786406029265394, .45818352706035500108,
-    .14984403004611673047, -.21163807462970713245, -.36007252928843413718,
-    -.17030961385712954159, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., .19073486328125000000e-5,
-    .38135049864067468562e-4, .37101393638555730015e-3,
-    .23305339886279723213e-2, .10569913448297127219e-1,
-    .36640175162216897547e-1, .10010476414320235508, .21860074212675559892,
-    .38124757096345313719, .52020999209879669177, .52172632730659212045,
-    .30841620620308814614, -.50322546186721500184e-1, -.32577618885114899053,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., .95367431640625000000e-6, .20021483206955925244e-4,
-    .20481807322420625431e-3, .13553476938058909882e-2,
-    .64919676350791905019e-2, .23848725425069251903e-1,
-    .69384632678886421292e-1, .16249711393618776934, .30736618106830314788,
-    .46399909601971539157, .53765031034002467225, .42598991476520183929,
-    .12130445348350215652, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., .47683715820312500000e-6,
-    .10487707828484902486e-4, .11254146162337528943e-3,
-    .78248929534271987118e-3, .39468337145306794566e-2,
-    .15313546659475671763e-1, .47249070825218564146e-1, .11804374107101480543,
-    .24031796927792491122, .39629215049166341285, .51629108968402548545,
-    .49622372075429782915, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., .23841857910156250000e-6,
-    .54823314130625337326e-5, .61575377321535518154e-4,
-    .44877834366497538134e-3, .23774612048621955857e-2,
-    .97136347645161687796e-2, .31671599547606636717e-1,
-    .84028665767000747480e-1, .18298487576742964949, .32647878537696945218,
-    .46970971486488895077, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .11920928955078125000e-6,
-    .28604020001177375838e-5, .33559227978295551013e-4,
-    .25583821662860610560e-3, .14201552747787302339e-2,
-    .60938046986874414969e-2, .20930869247951926793e-1,
-    .58745021125678072911e-1, .13613725780285953720, .26083988356030237586,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., .59604644775390625000e-7,
-    .14898180663526043291e-5, .18224991282807693921e-4,
-    .14504433444608833821e-3, .84184722720281809548e-3,
-    .37846965430000478789e-2, .13656355548211376864e-1,
-    .40409541997718853934e-1, .99226988101858325902e-1, 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., .29802322387695312500e-7, .77471708843445529468e-6,
-    .98649879372606876995e-5, .81814934772838523887e-4,
-    .49554483992403011328e-3, .23290922072351413938e-2,
-    .88068134250844034186e-2, .27393666952485719070e-1, 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., .14901161193847656250e-7, .40226235946098233685e-6,
-    .53236418690561306700e-5, .45933829691164002269e-4,
-    .28982005232838857913e-3, .14212974043211018374e-2,
-    .56192363087488842264e-2, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    .74505805969238281250e-8, .20858299254133430408e-6,
-    .28648457300134381744e-5, .25677535898258910850e-4,
-    .16849420429491355445e-3, .86062824010315834002e-3, 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., .37252902984619140625e-8, .10801736017613096861e-6,
-    .15376606719887104015e-5, .14296523739727437959e-4,
-    .97419023656050887203e-4, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    .18626451492309570312e-8, .55871592916438890146e-7,
-    .82331193828137454068e-6, .79302250528382787666e-5, 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., .93132257461547851562e-9,
-    .28867244235852488244e-7, .43982811713864556957e-6, 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., .46566128730773925781e-9,
-    .14899342093408253335e-7, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
-    0., 0., .23283064365386962891e-9
-};
-
-/* Allocates a workspace for the given maximum number of intervals.
-    Note that if the workspace gets filled, the intervals with the
-    lowest error estimates are dropped. The maximum number of
-    intervals is therefore not the maximum number of intervals
-    that will be computed, but merely the size of the buffer.
-    */
-
-/* Compute the product of the fx with one of the inverse
-    Vandermonde-like matrices. */
-
-void
-Vinvfx (const double *fx, double *c, const int d)
-{
-
-  int i, j;
-
-  switch (d)
-    {
-    case 0:
-      for (i = 0; i <= 4; i++)
-        {
-          c[i] = 0.0;
-          for (j = 0; j <= 4; j++)
-            c[i] += V1inv[i * 5 + j] * fx[j * 8];
-        }
-      break;
-    case 1:
-      for (i = 0; i <= 8; i++)
-        {
-          c[i] = 0.0;
-          for (j = 0; j <= 8; j++)
-            c[i] += V2inv[i * 9 + j] * fx[j * 4];
-        }
-      break;
-    case 2:
-      for (i = 0; i <= 16; i++)
-        {
-          c[i] = 0.0;
-          for (j = 0; j <= 16; j++)
-            c[i] += V3inv[i * 17 + j] * fx[j * 2];
-        }
-      break;
-    case 3:
-      for (i = 0; i <= 32; i++)
-        {
-          c[i] = 0.0;
-          for (j = 0; j <= 32; j++)
-            c[i] += V4inv[i * 33 + j] * fx[j];
-        }
-      break;
-    }
-
-}
-
-
-/* Downdate the interpolation given by the n coefficients c
-    by removing the nodes with indices in nans. */
-
-void
-downdate (double *c, int n, int d, int *nans, int nnans)
-{
-
-  static const int bidx[4] = { 0, 6, 16, 34 };
-  double b_new[34], alpha;
-  int i, j;
-
-  for (i = 0; i <= n + 1; i++)
-    b_new[i] = bee[bidx[d] + i];
-  for (i = 0; i < nnans; i++)
-    {
-      b_new[n + 1] = b_new[n + 1] / Lalpha[n];
-      b_new[n] = (b_new[n] + xi[nans[i]] * b_new[n + 1]) / Lalpha[n - 1];
-      for (j = n - 1; j > 0; j--)
-        b_new[j] =
-          (b_new[j] + xi[nans[i]] * b_new[j + 1] -
-           Lgamma[j + 1] * b_new[j + 2]) / Lalpha[j - 1];
-      for (j = 0; j <= n; j++)
-        b_new[j] = b_new[j + 1];
-      alpha = c[n] / b_new[n];
-      for (j = 0; j < n; j++)
-        c[j] -= alpha * b_new[j];
-      c[n] = 0;
-      n--;
-    }
-
-}
-
-
-/* The actual integration routine.  */
-
-DEFUN_DLD (quadcc, args, nargout,
-"-*- texinfo -*-\n\
-@deftypefn  {Function File} {@var{q} =} quadcc (@var{f}, @var{a}, @var{b})\n\
-@deftypefnx {Function File} {@var{q} =} quadcc (@var{f}, @var{a}, @var{b}, @var{tol})\n\
-@deftypefnx {Function File} {@var{q} =} quadcc (@var{f}, @var{a}, @var{b}, @var{tol}, @var{sing})\n\
-@deftypefnx {Function File} {[@var{q}, @var{err}, @var{nr_points}] =} quadcc (@dots{})\n\
-Numerically evaluate the integral of @var{f} from @var{a} to @var{b}\n\
-using the doubly-adaptive Clenshaw-Curtis quadrature described by P. Gonnet\n\
-in @cite{Increasing the Reliability of Adaptive Quadrature Using Explicit\n\
-Interpolants}.\n\
-@var{f} is a function handle, inline function, or string\n\
-containing the name of the function to evaluate.\n\
-The function @var{f} must be vectorized and must return a vector of output\n\
-values if given a vector of input values.  For example,\n\
-\n\
-@example\n\
-f = @@(x) x .* sin (1./x) .* sqrt (abs (1 - x));\n\
-@end example\n\
-\n\
-@noindent\n\
-which uses the element-by-element `dot' form for all operators.\n\
-\n\
-@var{a} and @var{b} are the lower and upper limits of integration.  Either\n\
-or both limits may be infinite.  @code{quadcc} handles an inifinite limit\n\
-by substituting the variable of integration with @code{x = tan (pi/2*u)}.\n\
-\n\
-The optional argument @var{tol} defines the relative tolerance used to stop\n\
-the integration procedure.  The default value is @math{1e^{-6}}.\n\
-\n\
-The optional argument @var{sing} contains a list of points where the\n\
-integrand has known singularities, or discontinuities\n\
-in any of its derivatives, inside the integration interval.\n\
-For the example above, which has a discontinuity at x=1, the call to\n\
-@code{quadcc} would be as follows\n\
-\n\
-@example\n\
-int = quadcc (f, a, b, 1.0e-6, [ 1 ]);\n\
-@end example\n\
-\n\
-The result of the integration is returned in @var{q}.\n\
-@var{err} is an estimate of the absolute integration error and\n\
-@var{nr_points} is the number of points at which the integrand was evaluated.\n\
-If the adaptive integration did not converge, the value of\n\
-@var{err} will be larger than the requested tolerance.  Therefore, it is\n\
-recommended to verify this value for difficult integrands.\n\
-\n\
-@code{quadcc} is capable of dealing with non-numeric\n\
-values of the integrand such as @code{NaN} or @code{Inf}.\n\
-If the integral diverges, and @code{quadcc} detects this,\n\
-then a warning is issued and @code{Inf} or @code{-Inf} is returned.\n\
-\n\
-Note: @code{quadcc} is a general purpose quadrature algorithm\n\
-and, as such, may be less efficient for a smooth or otherwise\n\
-well-behaved integrand than other methods such as @code{quadgk}.\n\
-\n\
-The algorithm uses Clenshaw-Curtis quadrature rules of increasing\n\
-degree in each interval and bisects the interval if either the\n\
-function does not appear to be smooth or a rule of maximum\n\
-degree has been reached.  The error estimate is computed from the\n\
-L2-norm of the difference between two successive interpolations\n\
-of the integrand over the nodes of the respective quadrature rules.\n\
-\n\
-Reference: P. Gonnet, @cite{Increasing the Reliability of Adaptive\n\
-Quadrature Using Explicit Interpolants}, ACM Transactions on\n\
-Mathematical Software, Vol. 37, Issue 3, Article No. 3, 2010.\n\
-@seealso{quad, quadv, quadl, quadgk, trapz, dblquad, triplequad}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  /* Some constants that we will need. */
-  static const int n[4] = { 4, 8, 16, 32 };
-  static const int skip[4] = { 8, 4, 2, 1 };
-  static const int idx[4] = { 0, 5, 14, 31 };
-  static const double w = M_SQRT2 / 2;
-  static const int ndiv_max = 20;
-
-  /* The interval heap. */
-  cquad_ival ivals[cquad_heapsize];
-  int heap[cquad_heapsize];
-
-  /* Arguments left and right */
-  int nargin = args.length ();
-  octave_function *fcn;
-  double a, b, tol, iivals[cquad_heapsize], *sing;
-
-  /* Variables needed for transforming the integrand. */
-  bool wrap = false;
-  double xw;
-
-  /* Stuff we will need to call the integrand. */
-  octave_value_list fargs, fvals;
-
-  /* Actual variables (as opposed to constants above). */
-  double m, h, ml, hl, mr, hr, temp;
-  double igral, err, igral_final, err_final;
-  int nivals, neval = 0;
-  int i, j, d, split, t;
-  int nnans, nans[33];
-  cquad_ival *iv, *ivl, *ivr;
-  double nc, ncdiff;
-
-
-  /* Parse the input arguments. */
-  if (nargin < 3)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  if (args(0).is_function_handle () || args(0).is_inline_function ())
-    fcn = args(0).function_value ();
-  else
-    {
-       std::string fcn_name = unique_symbol_name ("__quadcc_fcn_");
-       std::string fname = "function y = ";
-       fname.append (fcn_name);
-       fname.append ("(x) y = ");
-       fcn = extract_function (args(0), "quadcc", fcn_name, fname,
-                               "; endfunction");
-    }
-
-  if (!args(1).is_real_scalar ())
-    {
-      error ("quadcc: lower limit of integration (A) must be a single real scalar");
-      return retval;
-    }
-  else
-    a = args(1).double_value ();
-
-  if (!args(2).is_real_scalar ())
-    {
-      error ("quadcc: upper limit of integration (B) must be a single real scalar");
-      return retval;
-    }
-  else
-    b = args(2).double_value ();
-
-  if (nargin < 4 || args(3).is_empty ())
-    tol = 1.0e-6;
-  else if (!args(3).is_real_scalar () || args(3).double_value () <= 0)
-    {
-      error ("quadcc: tolerance (TOL) must be a single real scalar > 0");
-      return retval;
-    }
-  else
-    tol = args(3).double_value ();
-
-  if (nargin < 5)
-    {
-      nivals = 1;
-      iivals[0] = a;
-      iivals[1] = b;
-    }
-  else if (!(args(4).is_real_scalar () || args(4).is_real_matrix ()))
-    {
-      error ("quadcc: list of singularities (SING) must be a vector of real values");
-      return retval;
-    }
-  else
-    {
-      nivals = 1 + args(4).length ();
-      if (nivals > cquad_heapsize)
-        {
-          error ("quadcc: maximum number of singular points is limited to %i",
-                 cquad_heapsize-1);
-          return retval;
-        }
-      sing = args(4).array_value ().fortran_vec ();
-      iivals[0] = a;
-      for (i = 0; i < nivals - 2; i++)
-        iivals[i + 1] = sing[i];
-      iivals[nivals] = b;
-    }
-
-  /* If a or b are +/-Inf, transform the integral. */
-  if (xisinf (a) || xisinf (b))
-    {
-      wrap = true;
-      for (i = 0; i <= nivals; i++)
-        if (xisinf (iivals[i]))
-          iivals[i] = gnulib::copysign (1.0, iivals[i]);
-        else
-          iivals[i] = 2.0 * atan (iivals[i]) / M_PI;
-    }
-
-
-  /* Initialize the heaps. */
-  for (i = 0; i < cquad_heapsize; i++)
-    heap[i] = i;
-
-
-  /* Create the first interval(s). */
-  igral = 0.0;
-  err = 0.0;
-  for (j = 0; j < nivals; j++)
-    {
-
-      /* Initialize the interval. */
-      iv = &(ivals[heap[j]]);
-      m = (iivals[j] + iivals[j + 1]) / 2;
-      h = (iivals[j + 1] - iivals[j]) / 2;
-      nnans = 0;
-      ColumnVector ex (33);
-      if (wrap)
-        {
-          for (i = 0; i <= n[3]; i++)
-            ex (i) = tan (M_PI / 2 * (m + xi[i] * h));
-        }
-      else
-        {
-          for (i = 0; i <= n[3]; i++)
-            ex (i) = m + xi[i] * h;
-        }
-      fargs(0) = ex;
-      fvals = feval (fcn, fargs, 1);
-      if (fvals.length () != 1 || !fvals(0).is_real_matrix ())
-        {
-          error ("quadcc: integrand F must return a single, real-valued vector");
-          return retval;
-        }
-      Matrix effex = fvals(0).matrix_value ();
-      if (effex.length () != ex.length ())
-        {
-          error ("quadcc: integrand F must return a single, real-valued vector of the same size as the input");
-          return retval;
-        }
-      for (i = 0; i <= n[3]; i++)
-        {
-          iv->fx[i] = effex (i);
-          if (wrap)
-            {
-              xw = ex(i);
-              iv->fx[i] *= (1.0 + xw * xw) * M_PI / 2;
-            }
-          neval++;
-          if (!xfinite (iv->fx[i]))
-            {
-              nans[nnans++] = i;
-              iv->fx[i] = 0.0;
-            }
-        }
-      Vinvfx (iv->fx, &(iv->c[idx[3]]), 3);
-      Vinvfx (iv->fx, &(iv->c[idx[2]]), 2);
-      Vinvfx (iv->fx, &(iv->c[0]), 0);
-      for (i = 0; i < nnans; i++)
-        iv->fx[i] = octave_NaN;
-      iv->a = iivals[j];
-      iv->b = iivals[j + 1];
-      iv->depth = 3;
-      iv->rdepth = 1;
-      iv->ndiv = 0;
-      iv->igral = 2 * h * iv->c[idx[3]] * w;
-      nc = 0.0;
-      for (i = n[2] + 1; i <= n[3]; i++)
-        {
-          temp = iv->c[idx[3] + i];
-          nc += temp * temp;
-        }
-      ncdiff = nc;
-      for (i = 0; i <= n[2]; i++)
-        {
-          temp = iv->c[idx[2] + i] - iv->c[idx[3] + i];
-          ncdiff += temp * temp;
-          nc += iv->c[idx[3] + i] * iv->c[idx[3] + i];
-        }
-      ncdiff = sqrt (ncdiff);
-      nc = sqrt (nc);
-      iv->err = ncdiff * 2 * h;
-      if (ncdiff / nc > 0.1 && iv->err < 2 * h * nc)
-        iv->err = 2 * h * nc;
-
-      /* Tabulate this interval's data. */
-      igral += iv->igral;
-      err += iv->err;
-
-      /* Sift it up the heap. */
-      i = j;
-      while (i > 0 && ivals[heap[i / 2]].err < ivals[heap[i]].err)
-        {
-          temp = heap[i];
-          heap[i] = heap[i / 2];
-          heap[i / 2] = temp;
-          i /= 2;
-        }
-
-    }
-
-
-  /* Initialize some global values. */
-  igral_final = 0.0;
-  err_final = 0.0;
-
-
-  /* Main loop. */
-  while (nivals > 0 && err > 0.0 && err > fabs (igral) * tol
-         && !(err_final > fabs (igral) * tol
-              && err - err_final < fabs (igral) * tol))
-    {
-
-      /* Allow the user to interrupt. */
-      OCTAVE_QUIT;
-
-      /* Put our finger on the interval with the largest error. */
-      iv = &(ivals[heap[0]]);
-      m = (iv->a + iv->b) / 2;
-      h = (iv->b - iv->a) / 2;
-
-/*      printf
-        ("quadcc: processing ival %i (of %i) with [%e,%e] int=%e, err=%e, depth=%i\n",
-         heap[0], nivals, iv->a, iv->b, iv->igral, iv->err, iv->depth);
-*/
-      /* Should we try to increase the degree? */
-      if (iv->depth < 3)
-        {
-
-          /* Keep tabs on some variables. */
-          d = ++iv->depth;
-
-          /* Get the new (missing) function values */
-          {
-            ColumnVector ex (n[d] / 2);
-            if (wrap)
-              {
-                for (i = 0; i < n[d] / 2; i++)
-                  ex (i) =
-                    tan (M_PI / 2 * (m + xi[(2 * i + 1) * skip[d]] * h));
-              }
-            else
-              {
-                for (i = 0; i < n[d] / 2; i++)
-                  ex (i) = m + xi[(2 * i + 1) * skip[d]] * h;
-              }
-            fargs(0) = ex;
-            fvals = feval (fcn, fargs, 1);
-            if (fvals.length () != 1 || !fvals(0).is_real_matrix ())
-              {
-                error ("quadcc: integrand F must return a single, real-valued vector");
-                return retval;
-              }
-            Matrix effex = fvals(0).matrix_value ();
-            if (effex.length () != ex.length ())
-              {
-                error ("quadcc: integrand F must return a single, real-valued vector of the same size as the input");
-                return retval;
-              }
-            neval += effex.length ();
-            for (i = 0; i < n[d] / 2; i++)
-              {
-                j = (2 * i + 1) * skip[d];
-                iv->fx[j] = effex (i);
-                if (wrap)
-                  {
-                    xw = ex(i);
-                    iv->fx[j] *= (1.0 + xw * xw) * M_PI / 2;
-                  }
-              }
-          }
-          nnans = 0;
-          for (i = 0; i <= 32; i += skip[d])
-            {
-              if (!xfinite (iv->fx[i]))
-                {
-                  nans[nnans++] = i;
-                  iv->fx[i] = 0.0;
-                }
-            }
-
-          /* Compute the new coefficients. */
-          Vinvfx (iv->fx, &(iv->c[idx[d]]), d);
-          /* Downdate any NaNs. */
-          if (nnans > 0)
-            {
-              downdate (&(iv->c[idx[d]]), n[d], d, nans, nnans);
-              for (i = 0; i < nnans; i++)
-                iv->fx[i] = octave_NaN;
-            }
-
-          /* Compute the error estimate. */
-          nc = 0.0;
-          for (i = n[d - 1] + 1; i <= n[d]; i++)
-            {
-              temp = iv->c[idx[d] + i];
-              nc += temp * temp;
-            }
-          ncdiff = nc;
-          for (i = 0; i <= n[d - 1]; i++)
-            {
-              temp = iv->c[idx[d - 1] + i] - iv->c[idx[d] + i];
-              ncdiff += temp * temp;
-              nc += iv->c[idx[d] + i] * iv->c[idx[d] + i];
-            }
-          ncdiff = sqrt (ncdiff);
-          nc = sqrt (nc);
-          iv->err = ncdiff * 2 * h;
-          /* Compute the local integral. */
-          iv->igral = 2 * h * w * iv->c[idx[d]];
-          /* Split the interval prematurely? */
-          split = (nc > 0 && ncdiff / nc > 0.1);
-        }
-
-      /* Maximum degree reached, just split. */
-      else
-        {
-          split = 1;
-        }
-
-
-      /* Should we drop this interval? */
-      if ((m + h * xi[0]) >= (m + h * xi[1])
-          || (m + h * xi[31]) >= (m + h * xi[32])
-          || iv->err < fabs (iv->igral) * DBL_EPSILON * 10)
-        {
-
-/*          printf
-            ("quadcc: dropping ival %i (of %i) with [%e,%e] int=%e, err=%e, depth=%i\n",
-             heap[0], nivals, iv->a, iv->b, iv->igral, iv->err,
-             iv->depth);
-*/
-          /* Keep this interval's contribution */
-          err_final += iv->err;
-          igral_final += iv->igral;
-          /* Swap with the last element on the heap */
-          t = heap[nivals - 1];
-          heap[nivals - 1] = heap[0];
-          heap[0] = t;
-          nivals--;
-          /* Fix up the heap */
-          i = 0;
-          while (2 * i + 1 < nivals)
-            {
-
-              /* Get the kids */
-              j = 2 * i + 1;
-              /* If the j+1st entry exists and is larger than the jth,
-                 use it instead. */
-              if (j + 1 < nivals
-                  && ivals[heap[j + 1]].err >= ivals[heap[j]].err)
-                j++;
-              /* Do we need to move the ith entry up? */
-              if (ivals[heap[j]].err <= ivals[heap[i]].err)
-                break;
-              else
-                {
-                  t = heap[j];
-                  heap[j] = heap[i];
-                  heap[i] = t;
-                  i = j;
-                }
-            }
-
-        }
-
-      /* Do we need to split this interval? */
-      else if (split)
-        {
-
-          /* Some values we will need often... */
-          d = iv->depth;
-          /* Generate the interval on the left */
-          ivl = &(ivals[heap[nivals++]]);
-          ivl->a = iv->a;
-          ivl->b = m;
-          ml = (ivl->a + ivl->b) / 2;
-          hl = h / 2;
-          ivl->depth = 0;
-          ivl->rdepth = iv->rdepth + 1;
-          ivl->fx[0] = iv->fx[0];
-          ivl->fx[32] = iv->fx[16];
-          {
-            ColumnVector ex (n[0] - 1);
-            if (wrap)
-              {
-                for (i = 0; i < n[0] - 1; i++)
-                  ex (i) = tan (M_PI / 2 * (ml + xi[(i + 1) * skip[0]] * hl));
-              }
-            else
-              {
-                for (i = 0; i < n[0] - 1; i++)
-                  ex (i) = ml + xi[(i + 1) * skip[0]] * hl;
-              }
-            fargs(0) = ex;
-            fvals = feval (fcn, fargs, 1);
-            if (fvals.length () != 1 || !fvals(0).is_real_matrix ())
-              {
-                error ("quadcc: integrand F must return a single, real-valued vector");
-                return retval;
-              }
-            Matrix effex = fvals(0).matrix_value ();
-            if (effex.length () != ex.length ())
-              {
-                error ("quadcc: integrand F must return a single, real-valued vector of the same size as the input");
-                return retval;
-              }
-            neval += effex.length ();
-            for (i = 0; i < n[0] - 1; i++)
-              {
-                j = (i + 1) * skip[0];
-                ivl->fx[j] = effex (i);
-                if (wrap)
-                  {
-                    xw = ex(i);
-                    ivl->fx[j] *= (1.0 + xw * xw) * M_PI / 2;
-                  }
-              }
-          }
-          nnans = 0;
-          for (i = 0; i <= 32; i += skip[0])
-            {
-              if (!xfinite (ivl->fx[i]))
-                {
-                  nans[nnans++] = i;
-                  ivl->fx[i] = 0.0;
-                }
-            }
-          Vinvfx (ivl->fx, ivl->c, 0);
-          if (nnans > 0)
-            {
-              downdate (ivl->c, n[0], 0, nans, nnans);
-              for (i = 0; i < nnans; i++)
-                ivl->fx[i] = octave_NaN;
-            }
-          for (i = 0; i <= n[d]; i++)
-            {
-              ivl->c[idx[d] + i] = 0.0;
-              for (j = i; j <= n[d]; j++)
-                ivl->c[idx[d] + i] += Tleft[i * 33 + j] * iv->c[idx[d] + j];
-            }
-          ncdiff = 0.0;
-          for (i = 0; i <= n[0]; i++)
-            {
-              temp = ivl->c[i] - ivl->c[idx[d] + i];
-              ncdiff += temp * temp;
-            }
-          for (i = n[0] + 1; i <= n[d]; i++)
-            {
-              temp = ivl->c[idx[d] + i];
-              ncdiff += temp * temp;
-            }
-          ncdiff = sqrt (ncdiff);
-          ivl->err = ncdiff * h;
-          /* Check for divergence. */
-          ivl->ndiv = iv->ndiv + (fabs (iv->c[0]) > 0
-                                  && ivl->c[0] / iv->c[0] > 2);
-          if (ivl->ndiv > ndiv_max && 2 * ivl->ndiv > ivl->rdepth)
-            {
-              igral = gnulib::copysign (octave_Inf, igral);
-              warning ("quadcc: divergent integral detected");
-              break;
-            }
-
-          /* Compute the local integral. */
-          ivl->igral = h * w * ivl->c[0];
-
-
-          /* Generate the interval on the right */
-          ivr = &(ivals[heap[nivals++]]);
-          ivr->a = m;
-          ivr->b = iv->b;
-          mr = (ivr->a + ivr->b) / 2;
-          hr = h / 2;
-          ivr->depth = 0;
-          ivr->rdepth = iv->rdepth + 1;
-          ivr->fx[0] = iv->fx[16];
-          ivr->fx[32] = iv->fx[32];
-          {
-            ColumnVector ex (n[0] - 1);
-            if (wrap)
-              {
-                for (i = 0; i < n[0] - 1; i++)
-                  ex (i) = tan (M_PI / 2 * (mr + xi[(i + 1) * skip[0]] * hr));
-              }
-            else
-              {
-                for (i = 0; i < n[0] - 1; i++)
-                  ex (i) = mr + xi[(i + 1) * skip[0]] * hr;
-              }
-            fargs(0) = ex;
-            fvals = feval (fcn, fargs, 1);
-            if (fvals.length () != 1 || !fvals(0).is_real_matrix ())
-              {
-                error ("quadcc: integrand F must return a single, real-valued vector");
-                return retval;
-              }
-            Matrix effex = fvals(0).matrix_value ();
-            if (effex.length () != ex.length ())
-              {
-                error ("quadcc: integrand F must return a single, real-valued vector of the same size as the input");
-                return retval;
-              }
-            neval += effex.length ();
-            for (i = 0; i < n[0] - 1; i++)
-              {
-                j = (i + 1) * skip[0];
-                ivr->fx[j] = effex (i);
-                if (wrap)
-                  {
-                    xw = ex(i);
-                    ivr->fx[j] *= (1.0 + xw * xw) * M_PI / 2;
-                  }
-              }
-          }
-          nnans = 0;
-          for (i = 0; i <= 32; i += skip[0])
-            {
-              if (!xfinite (ivr->fx[i]))
-                {
-                  nans[nnans++] = i;
-                  ivr->fx[i] = 0.0;
-                }
-            }
-          Vinvfx (ivr->fx, ivr->c, 0);
-          if (nnans > 0)
-            {
-              downdate (ivr->c, n[0], 0, nans, nnans);
-              for (i = 0; i < nnans; i++)
-                ivr->fx[i] = octave_NaN;
-            }
-          for (i = 0; i <= n[d]; i++)
-            {
-              ivr->c[idx[d] + i] = 0.0;
-              for (j = i; j <= n[d]; j++)
-                ivr->c[idx[d] + i] += Tright[i * 33 + j] * iv->c[idx[d] + j];
-            }
-          ncdiff = 0.0;
-          for (i = 0; i <= n[0]; i++)
-            {
-              temp = ivr->c[i] - ivr->c[idx[d] + i];
-              ncdiff += temp * temp;
-            }
-          for (i = n[0] + 1; i <= n[d]; i++)
-            {
-              temp = ivr->c[idx[d] + i];
-              ncdiff += temp * temp;
-            }
-          ncdiff = sqrt (ncdiff);
-          ivr->err = ncdiff * h;
-          /* Check for divergence. */
-          ivr->ndiv = iv->ndiv + (fabs (iv->c[0]) > 0
-                                  && ivr->c[0] / iv->c[0] > 2);
-          if (ivr->ndiv > ndiv_max && 2 * ivr->ndiv > ivr->rdepth)
-            {
-              igral = gnulib::copysign (octave_Inf, igral);
-              warning ("quadcc: divergent integral detected");
-              break;
-            }
-
-          /* Compute the local integral. */
-          ivr->igral = h * w * ivr->c[0];
-
-
-          /* Fix-up the heap: we now have one interval on top
-             that we don't need any more and two new, unsorted
-             ones at the bottom. */
-          /* Flip the last interval to the top of the heap and
-             sift down. */
-          t = heap[nivals - 1];
-          heap[nivals - 1] = heap[0];
-          heap[0] = t;
-          nivals--;
-          /* Sift this interval back down the heap. */
-          i = 0;
-          while (2 * i + 1 < nivals - 1)
-            {
-              j = 2 * i + 1;
-              if (j + 1 < nivals - 1
-                  && ivals[heap[j + 1]].err >= ivals[heap[j]].err)
-                j++;
-              if (ivals[heap[j]].err <= ivals[heap[i]].err)
-                break;
-              else
-                {
-                  t = heap[j];
-                  heap[j] = heap[i];
-                  heap[i] = t;
-                  i = j;
-                }
-            }
-
-          /* Now grab the last interval and sift it up the heap. */
-          i = nivals - 1;
-          while (i > 0)
-            {
-              j = (i - 1) / 2;
-              if (ivals[heap[j]].err < ivals[heap[i]].err)
-                {
-                  t = heap[j];
-                  heap[j] = heap[i];
-                  heap[i] = t;
-                  i = j;
-                }
-              else
-                break;
-            }
-
-
-        }
-
-      /* Otherwise, just fix-up the heap. */
-      else
-        {
-          i = 0;
-          while (2 * i + 1 < nivals)
-            {
-              j = 2 * i + 1;
-              if (j + 1 < nivals
-                  && ivals[heap[j + 1]].err >= ivals[heap[j]].err)
-                j++;
-              if (ivals[heap[j]].err <= ivals[heap[i]].err)
-                break;
-              else
-                {
-                  t = heap[j];
-                  heap[j] = heap[i];
-                  heap[i] = t;
-                  i = j;
-                }
-            }
-
-        }
-
-      /* If the heap is about to overflow, remove the last two
-         intervals. */
-      while (nivals > cquad_heapsize - 2)
-        {
-          iv = &(ivals[heap[nivals - 1]]);
-/*          printf
-            ("quadcc: dropping ival %i (of %i) with [%e,%e] int=%e, err=%e, depth=%i\n",
-             heap[0], nivals, iv->a, iv->b, iv->igral, iv->err,
-             iv->depth);
-*/
-          err_final += iv->err;
-          igral_final += iv->igral;
-          nivals--;
-        }
-
-      /* Collect the value of the integral and error. */
-      igral = igral_final;
-      err = err_final;
-      for (i = 0; i < nivals; i++)
-        {
-          igral += ivals[heap[i]].igral;
-          err += ivals[heap[i]].err;
-        }
-
-    }
-
-  /* Dump the contents of the heap. */
-/*  for (i = 0; i < nivals; i++)
-    {
-      iv = &(ivals[heap[i]]);
-      printf
-        ("quadcc: ival %i (%i) with [%e,%e], int=%e, err=%e, depth=%i, rdepth=%i, ndiv=%i\n",
-         i, heap[i], iv->a, iv->b, iv->igral, iv->err, iv->depth,
-         iv->rdepth, iv->ndiv);
-    }
-*/
-  /* Clean up and present the results. */
-  if (nargout > 2)
-    retval(2) = neval;
-  if (nargout > 1)
-    retval(1) = err;
-  retval(0) = igral;
-  /* All is well that ends well. */
-  return retval;
-}
-
-
-/*
-%!assert (quadcc (@sin, -pi, pi), 0, 1e-6)
-%!assert (quadcc (inline ("sin"),- pi, pi), 0, 1e-6)
-%!assert (quadcc ("sin", -pi, pi), 0, 1e-6)
-
-%!assert (quadcc (@sin, -pi, 0), -2, 1e-6)
-%!assert (quadcc (@sin, 0, pi), 2, 1e-6)
-%!assert (quadcc (@(x) 1./sqrt (x), 0, 1), 2, 1e-6)
-%!assert (quadcc (@(x) 1./(sqrt (x).*(x+1)), 0, Inf), pi, 1e-6)
-
-%!assert (quadcc (@(x) exp (-x .^ 2), -Inf, Inf), sqrt (pi), 1e-6)
-%!assert (quadcc (@(x) exp (-x .^ 2), -Inf, 0), sqrt (pi)/2, 1e-6)
-
-%% Test input validation
-%!error (quadcc ())
-%!error (quadcc (@sin))
-%!error (quadcc (@sin, 0))
-%!error (quadcc (@sin, ones (2), pi))
-%!error (quadcc (@sin, -i, pi))
-%!error (quadcc (@sin, 0, ones (2)))
-%!error (quadcc (@sin, 0, i))
-%!error (quadcc (@sin, 0, pi, 0))
-%!error (quadcc (@sin, 0, pi, 1e-6, [ i ]))
-*/
--- a/src/DLD-FUNCTIONS/qz.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1278 +0,0 @@
-/*
-
-Copyright (C) 1998-2012 A. S. Hodel
-
-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/>.
-
-*/
-
-// Generalized eigenvalue balancing via LAPACK
-
-// Author: A. S. Hodel <scotte@eng.auburn.edu>
-
-#undef DEBUG
-#undef DEBUG_SORT
-#undef DEBUG_EIG
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <cfloat>
-
-#include <iostream>
-#include <iomanip>
-
-#include "CmplxQRP.h"
-#include "CmplxQR.h"
-#include "dbleQR.h"
-#include "f77-fcn.h"
-#include "lo-math.h"
-#include "quit.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "oct-map.h"
-#include "ov.h"
-#include "pager.h"
-#if defined (DEBUG) || defined (DEBUG_SORT)
-#include "pr-output.h"
-#endif
-#include "symtab.h"
-#include "utils.h"
-#include "variables.h"
-
-typedef octave_idx_type (*sort_function) (const octave_idx_type& LSIZE, const double& ALPHA,
-                              const double& BETA, const double& S,
-                              const double& P);
-
-extern "C"
-{
-  F77_RET_T
-  F77_FUNC (dggbal, DGGBAL) (F77_CONST_CHAR_ARG_DECL,
-                             const octave_idx_type& N, double* A,
-                             const octave_idx_type& LDA, double* B,
-                             const octave_idx_type& LDB, octave_idx_type& ILO,
-                             octave_idx_type& IHI, double* LSCALE,
-                             double* RSCALE, double* WORK,
-                             octave_idx_type& INFO
-                             F77_CHAR_ARG_LEN_DECL);
-
-F77_RET_T
-  F77_FUNC (zggbal, ZGGBAL) (F77_CONST_CHAR_ARG_DECL,
-                             const octave_idx_type& N, Complex* A,
-                             const octave_idx_type& LDA, Complex* B,
-                             const octave_idx_type& LDB, octave_idx_type& ILO,
-                             octave_idx_type& IHI, double* LSCALE,
-                             double* RSCALE, double* WORK,
-                             octave_idx_type& INFO
-                             F77_CHAR_ARG_LEN_DECL);
-
-  F77_RET_T
-  F77_FUNC (dggbak, DGGBAK) (F77_CONST_CHAR_ARG_DECL,
-                             F77_CONST_CHAR_ARG_DECL,
-                             const octave_idx_type& N,
-                             const octave_idx_type& ILO,
-                             const octave_idx_type& IHI,
-                             const double* LSCALE, const double* RSCALE,
-                             octave_idx_type& M, double* V,
-                             const octave_idx_type& LDV, octave_idx_type& INFO
-                             F77_CHAR_ARG_LEN_DECL
-                             F77_CHAR_ARG_LEN_DECL);
-
-F77_RET_T
-  F77_FUNC (zggbak, ZGGBAK) (F77_CONST_CHAR_ARG_DECL,
-                             F77_CONST_CHAR_ARG_DECL,
-                             const octave_idx_type& N,
-                             const octave_idx_type& ILO,
-                             const octave_idx_type& IHI,
-                             const double* LSCALE, const double* RSCALE,
-                             octave_idx_type& M, Complex* V,
-                             const octave_idx_type& LDV, octave_idx_type& INFO
-                             F77_CHAR_ARG_LEN_DECL
-                             F77_CHAR_ARG_LEN_DECL);
-
-  F77_RET_T
-  F77_FUNC (dgghrd, DGGHRD) (F77_CONST_CHAR_ARG_DECL,
-                             F77_CONST_CHAR_ARG_DECL,
-                             const octave_idx_type& N,
-                             const octave_idx_type& ILO,
-                             const octave_idx_type& IHI, double* A,
-                             const octave_idx_type& LDA, double* B,
-                             const octave_idx_type& LDB, double* Q,
-                             const octave_idx_type& LDQ, double* Z,
-                             const octave_idx_type& LDZ, octave_idx_type& INFO
-                             F77_CHAR_ARG_LEN_DECL
-                             F77_CHAR_ARG_LEN_DECL);
-
- F77_RET_T
-  F77_FUNC (zgghrd, ZGGHRD) (F77_CONST_CHAR_ARG_DECL,
-                             F77_CONST_CHAR_ARG_DECL,
-                             const octave_idx_type& N,
-                             const octave_idx_type& ILO,
-                             const octave_idx_type& IHI, Complex* A,
-                             const octave_idx_type& LDA, Complex* B,
-                             const octave_idx_type& LDB, Complex* Q,
-                             const octave_idx_type& LDQ, Complex* Z,
-                             const octave_idx_type& LDZ, octave_idx_type& INFO
-                             F77_CHAR_ARG_LEN_DECL
-                             F77_CHAR_ARG_LEN_DECL);
-
-  F77_RET_T
-  F77_FUNC (dhgeqz, DHGEQZ) (F77_CONST_CHAR_ARG_DECL,
-                             F77_CONST_CHAR_ARG_DECL,
-                             F77_CONST_CHAR_ARG_DECL,
-                             const octave_idx_type& N,
-                             const octave_idx_type& ILO,
-                             const octave_idx_type& IHI,
-                             double* A, const octave_idx_type& LDA, double* B,
-                             const octave_idx_type& LDB, double* ALPHAR,
-                             double* ALPHAI, double* BETA, double* Q,
-                             const octave_idx_type& LDQ, double* Z,
-                             const octave_idx_type& LDZ, double* WORK,
-                             const octave_idx_type& LWORK,
-                             octave_idx_type& INFO
-                             F77_CHAR_ARG_LEN_DECL
-                             F77_CHAR_ARG_LEN_DECL
-                             F77_CHAR_ARG_LEN_DECL);
-
-F77_RET_T
-  F77_FUNC (zhgeqz, ZHGEQZ) (F77_CONST_CHAR_ARG_DECL,
-                             F77_CONST_CHAR_ARG_DECL,
-                             F77_CONST_CHAR_ARG_DECL,
-                             const octave_idx_type& N,
-                             const octave_idx_type& ILO,
-                             const octave_idx_type& IHI,
-                             Complex* A, const octave_idx_type& LDA,
-                             Complex* B, const octave_idx_type& LDB,
-                             Complex* ALPHA, Complex* BETA, Complex* CQ,
-                             const octave_idx_type& LDQ,
-                             Complex* CZ, const octave_idx_type& LDZ,
-                             Complex* WORK, const octave_idx_type& LWORK,
-                             double* RWORK, octave_idx_type& INFO
-                             F77_CHAR_ARG_LEN_DECL
-                             F77_CHAR_ARG_LEN_DECL
-                             F77_CHAR_ARG_LEN_DECL);
-
-  F77_RET_T
-  F77_FUNC (dlag2, DLAG2) (const double* A, const octave_idx_type& LDA,
-                           const double* B, const octave_idx_type& LDB,
-                           const double& SAFMIN, double& SCALE1,
-                           double& SCALE2, double& WR1, double& WR2,
-                           double& WI);
-
-  // Van Dooren's code (netlib.org: toms/590) for reordering
-  // GEP.  Only processes Z, not Q.
-  F77_RET_T
-  F77_FUNC (dsubsp, DSUBSP) (const octave_idx_type& NMAX,
-                             const octave_idx_type& N, double* A,
-                             double* B, double* Z, sort_function,
-                             const double& EPS, octave_idx_type& NDIM,
-                             octave_idx_type& FAIL, octave_idx_type* IND);
-
-  // Documentation for DTGEVC incorrectly states that VR, VL are
-  // complex*16; they are declared in DTGEVC as double precision
-  // (probably a cut and paste problem fro ZTGEVC).
-  F77_RET_T
-  F77_FUNC (dtgevc, DTGEVC) (F77_CONST_CHAR_ARG_DECL,
-                             F77_CONST_CHAR_ARG_DECL,
-                             octave_idx_type* SELECT,
-                             const octave_idx_type& N, double* A,
-                             const octave_idx_type& LDA, double* B,
-                             const octave_idx_type& LDB, double* VL,
-                             const octave_idx_type& LDVL, double* VR,
-                             const octave_idx_type& LDVR,
-                             const octave_idx_type& MM, octave_idx_type& M,
-                             double* WORK, octave_idx_type& INFO
-                             F77_CHAR_ARG_LEN_DECL
-                             F77_CHAR_ARG_LEN_DECL);
-
-F77_RET_T
-  F77_FUNC (ztgevc, ZTGEVC) (F77_CONST_CHAR_ARG_DECL,
-                             F77_CONST_CHAR_ARG_DECL,
-                             octave_idx_type* SELECT,
-                             const octave_idx_type& N, const Complex* A,
-                             const octave_idx_type& LDA,const Complex* B,
-                             const octave_idx_type& LDB, Complex* xVL,
-                             const octave_idx_type& LDVL, Complex* xVR,
-                             const octave_idx_type& LDVR,
-                             const octave_idx_type& MM, octave_idx_type& M,
-                             Complex* CWORK, double* RWORK,
-                             octave_idx_type& INFO
-                             F77_CHAR_ARG_LEN_DECL
-                             F77_CHAR_ARG_LEN_DECL);
-
-  F77_RET_T
-  F77_FUNC (xdlamch, XDLAMCH) (F77_CONST_CHAR_ARG_DECL,
-                               double& retval
-                               F77_CHAR_ARG_LEN_DECL);
-
-  F77_RET_T
-  F77_FUNC (xdlange, XDLANGE) (F77_CONST_CHAR_ARG_DECL,
-                               const octave_idx_type&,
-                               const octave_idx_type&, const double*,
-                               const octave_idx_type&, double*, double&
-                               F77_CHAR_ARG_LEN_DECL);
-}
-
-// fcrhp, fin, fout, folhp:
-// routines for ordering of generalized eigenvalues
-// return 1 if  test is passed, 0 otherwise
-//    fin: |lambda| < 1
-//    fout: |lambda| >= 1
-//    fcrhp: real(lambda) >= 0
-//    folhp: real(lambda) < 0
-
-static octave_idx_type
-fcrhp (const octave_idx_type& lsize, const double& alpha,
-       const double& beta, const double& s, const double&)
-{
-  if (lsize == 1)
-    return (alpha * beta >= 0 ? 1 : -1);
-  else
-    return (s >= 0 ? 1 : -1);
-}
-
-static octave_idx_type
-fin (const octave_idx_type& lsize, const double& alpha,
-     const double& beta, const double&, const double& p)
-{
-  octave_idx_type retval;
-
-  if (lsize == 1)
-    retval = (fabs (alpha) < fabs (beta) ? 1 : -1);
-  else
-    retval = (fabs (p) < 1 ? 1 : -1);
-
-#ifdef DEBUG
-  std::cout << "qz: fin: retval=" << retval << std::endl;
-#endif
-
-  return retval;
-}
-
-static octave_idx_type
-folhp (const octave_idx_type& lsize, const double& alpha,
-       const double& beta, const double& s, const double&)
-{
-  if (lsize == 1)
-    return (alpha * beta < 0 ? 1 : -1);
-  else
-    return (s < 0 ? 1 : -1);
-}
-
-static octave_idx_type
-fout (const octave_idx_type& lsize, const double& alpha,
-      const double& beta, const double&, const double& p)
-{
-  if (lsize == 1)
-    return (fabs (alpha) >= fabs (beta) ? 1 : -1);
-  else
-    return (fabs (p) >= 1 ? 1 : -1);
-}
-
-
-//FIXME: Matlab does not produce lambda as the first output argument.
-//       Compatibility problem?
-DEFUN_DLD (qz, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{lambda} =} qz (@var{A}, @var{B})\n\
-@deftypefnx {Loadable Function} {@var{lambda} =} qz (@var{A}, @var{B}, @var{opt})\n\
-QZ@tie{}decomposition of the generalized eigenvalue problem\n\
-(@math{A x = s B x}).  There are three ways to call this function:\n\
-@enumerate\n\
-@item @code{@var{lambda} = qz (@var{A}, @var{B})}\n\
-\n\
-Computes the generalized eigenvalues\n\
-@tex\n\
-$\\lambda$\n\
-@end tex\n\
-@ifnottex\n\
-@var{lambda}\n\
-@end ifnottex\n\
-of @math{(A - s B)}.\n\
-\n\
-@item @code{[AA, BB, Q, Z, V, W, @var{lambda}] = qz (@var{A}, @var{B})}\n\
-\n\
-Computes QZ@tie{}decomposition, generalized eigenvectors, and\n\
-generalized eigenvalues of @math{(A - s B)}\n\
-@tex\n\
-$$ AV = BV{ \\rm diag }(\\lambda) $$\n\
-$$ W^T A = { \\rm diag }(\\lambda)W^T B $$\n\
-$$ AA = Q^T AZ, BB = Q^T BZ $$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-@group\n\
-\n\
-A * V = B * V * diag (@var{lambda})\n\
-W' * A = diag (@var{lambda}) * W' * B\n\
-AA = Q * A * Z, BB = Q * B * Z\n\
-\n\
-@end group\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-with @var{Q} and @var{Z} orthogonal (unitary)= @var{I}\n\
-\n\
-@item @code{[AA,BB,Z@{, @var{lambda}@}] = qz (@var{A}, @var{B}, @var{opt})}\n\
-\n\
-As in form [2], but allows ordering of generalized eigenpairs\n\
-for (e.g.) solution of discrete time algebraic Riccati equations.\n\
-Form 3 is not available for complex matrices, and does not compute\n\
-the generalized eigenvectors @var{V}, @var{W}, nor the orthogonal matrix\n\
-@var{Q}.\n\
-\n\
-@table @var\n\
-@item opt\n\
-for ordering eigenvalues of the GEP pencil.  The leading block\n\
-of the revised pencil contains all eigenvalues that satisfy:\n\
-\n\
-@table @asis\n\
-@item \"N\"\n\
-= unordered (default)\n\
-\n\
-@item \"S\"\n\
-= small: leading block has all |lambda| @leq{} 1\n\
-\n\
-@item \"B\"\n\
-= big: leading block has all |lambda| @geq{} 1\n\
-\n\
-@item \"-\"\n\
-= negative real part: leading block has all eigenvalues\n\
-in the open left half-plane\n\
-\n\
-@item \"+\"\n\
-= non-negative real part: leading block has all eigenvalues\n\
-in the closed right half-plane\n\
-@end table\n\
-@end table\n\
-@end enumerate\n\
-\n\
-Note: @code{qz} performs permutation balancing, but not scaling\n\
-(@pxref{doc-balance}).  The order of output arguments was selected for\n\
-compatibility with @sc{matlab}.\n\
-@seealso{balance, eig, schur}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-  int nargin = args.length ();
-
-#ifdef DEBUG
-  std::cout << "qz: nargin = " << nargin << ", nargout = " << nargout << std::endl;
-#endif
-
-  if (nargin < 2 || nargin > 3 || nargout > 7)
-    {
-      print_usage ();
-      return retval;
-    }
-  else if (nargin == 3 && (nargout < 3 || nargout > 4))
-    {
-      error ("qz: invalid number of output arguments for form [3] call");
-      return retval;
-    }
-
-#ifdef DEBUG
-  std::cout << "qz: determine ordering option" << std::endl;
-#endif
-
-  // Determine ordering option.
-  volatile char ord_job = 0;
-  static double safmin;
-
-  if (nargin == 2)
-    ord_job = 'N';
-  else if (!args(2).is_string ())
-    {
-      error ("qz: OPT must be a string");
-      return retval;
-    }
-  else
-    {
-      std::string tmp = args(2).string_value ();
-
-      if (! tmp.empty ())
-        ord_job = tmp[0];
-
-      if (! (ord_job == 'N' || ord_job == 'n'
-             || ord_job == 'S' || ord_job == 's'
-             || ord_job == 'B' || ord_job == 'b'
-             || ord_job == '+' || ord_job == '-'))
-        {
-          error ("qz: invalid order option");
-          return retval;
-        }
-
-      // overflow constant required by dlag2
-      F77_FUNC (xdlamch, XDLAMCH) (F77_CONST_CHAR_ARG2 ("S", 1),
-                                   safmin
-                                   F77_CHAR_ARG_LEN (1));
-
-#ifdef DEBUG_EIG
-      std::cout << "qz: initial value of safmin=" << setiosflags (std::ios::scientific)
-           << safmin << std::endl;
-#endif
-
-      // Some machines (e.g., DEC alpha) get safmin = 0;
-      // for these, use eps instead to avoid problems in dlag2.
-      if (safmin == 0)
-        {
-#ifdef DEBUG_EIG
-          std::cout << "qz: DANGER WILL ROBINSON: safmin is 0!" << std::endl;
-#endif
-
-          F77_FUNC (xdlamch, XDLAMCH) (F77_CONST_CHAR_ARG2 ("E", 1),
-                                       safmin
-                                       F77_CHAR_ARG_LEN (1));
-
-#ifdef DEBUG_EIG
-          std::cout << "qz: safmin set to " << setiosflags (std::ios::scientific)
-               << safmin << std::endl;
-#endif
-        }
-    }
-
-#ifdef DEBUG
-  std::cout << "qz: check argument 1" << std::endl;
-#endif
-
-  // Argument 1: check if it's o.k. dimensioned.
-  octave_idx_type nn = args(0).rows ();
-
-#ifdef DEBUG
-  std::cout << "argument 1 dimensions: (" << nn << "," << args(0).columns () << ")"
-       << std::endl;
-#endif
-
-  int arg_is_empty = empty_arg ("qz", nn, args(0).columns ());
-
-  if (arg_is_empty < 0)
-    {
-      gripe_empty_arg ("qz: parameter 1", 0);
-      return retval;
-    }
-  else if (arg_is_empty > 0)
-    {
-      gripe_empty_arg ("qz: parameter 1; continuing", 0);
-      return octave_value_list (2, Matrix ());
-    }
-  else if (args(0).columns () != nn)
-    {
-      gripe_square_matrix_required ("qz");
-      return retval;
-    }
-
-  // Argument 1: dimensions look good; get the value.
-  Matrix aa;
-  ComplexMatrix caa;
-
-  if (args(0).is_complex_type ())
-    caa = args(0).complex_matrix_value ();
-  else
-    aa = args(0).matrix_value ();
-
-  if (error_state)
-    return retval;
-
-#ifdef DEBUG
-  std::cout << "qz: check argument 2" << std::endl;
-#endif
-
-  // Extract argument 2 (bb, or cbb if complex).
-  if ((nn != args(1).columns ()) || (nn != args(1).rows ()))
-    {
-      gripe_nonconformant ();
-      return retval;
-    }
-
-  Matrix bb;
-  ComplexMatrix cbb;
-
-  if (args(1).is_complex_type ())
-    cbb = args(1).complex_matrix_value ();
-  else
-    bb = args(1).matrix_value ();
-
-  if (error_state)
-    return retval;
-
-  // Both matrices loaded, now let's check what kind of arithmetic:
-  // declared volatile to avoid compiler warnings about long jumps,
-  // vforks.
-
-  volatile int complex_case
-    = (args(0).is_complex_type () || args(1).is_complex_type ());
-
-  if (nargin == 3 && complex_case)
-    {
-      error ("qz: cannot re-order complex qz decomposition");
-      return retval;
-    }
-
-  // First, declare variables used in both the real and complex case.
-  Matrix QQ(nn,nn), ZZ(nn,nn), VR(nn,nn), VL(nn,nn);
-  RowVector alphar(nn), alphai(nn), betar(nn);
-  ComplexRowVector xalpha(nn), xbeta(nn);
-  ComplexMatrix CQ(nn,nn), CZ(nn,nn), CVR(nn,nn), CVL(nn,nn);
-  octave_idx_type ilo, ihi, info;
-  char compq = (nargout >= 3 ? 'V' : 'N');
-  char compz = ((nargout >= 4 || nargin == 3)? 'V' : 'N');
-
-  // Initialize Q, Z to identity if we need either of them.
-  if (compq == 'V' || compz == 'V')
-    for (octave_idx_type ii = 0; ii < nn; ii++)
-      for (octave_idx_type jj = 0; jj < nn; jj++)
-        {
-          OCTAVE_QUIT;
-          QQ(ii,jj) = ZZ(ii,jj) = (ii == jj ? 1.0 : 0.0);
-        }
-
-  // Always perform permutation balancing.
-  const char bal_job = 'P';
-  RowVector lscale (nn), rscale (nn), work (6 * nn), rwork (nn);
-
-  if (complex_case)
-    {
-#ifdef DEBUG
-      if (compq == 'V')
-        std::cout << "qz: performing balancing; CQ=" << std::endl << CQ << std::endl;
-#endif
-      if (args(0).is_real_type ())
-        caa = ComplexMatrix (aa);
-
-      if (args(1).is_real_type ())
-        cbb = ComplexMatrix (bb);
-
-      if (compq == 'V')
-        CQ = ComplexMatrix (QQ);
-
-      if (compz == 'V')
-        CZ = ComplexMatrix (ZZ);
-
-      F77_XFCN (zggbal, ZGGBAL,
-                (F77_CONST_CHAR_ARG2 (&bal_job, 1),
-                 nn, caa.fortran_vec (), nn, cbb.fortran_vec (),
-                 nn, ilo, ihi, lscale.fortran_vec (),
-                 rscale.fortran_vec (), work.fortran_vec (), info
-                 F77_CHAR_ARG_LEN (1)));
-    }
-  else
-    {
-#ifdef DEBUG
-      if (compq == 'V')
-        std::cout << "qz: performing balancing; QQ=" << std::endl << QQ << std::endl;
-#endif
-
-      F77_XFCN (dggbal, DGGBAL,
-                (F77_CONST_CHAR_ARG2 (&bal_job, 1),
-                 nn, aa.fortran_vec (), nn, bb.fortran_vec (),
-                 nn, ilo, ihi, lscale.fortran_vec (),
-                 rscale.fortran_vec (), work.fortran_vec (), info
-                 F77_CHAR_ARG_LEN (1)));
-    }
-
-  // Since we just want the balancing matrices, we can use dggbal
-  // for both the real and complex cases; left first
-
-#if 0
-  if (compq == 'V')
-    {
-      F77_XFCN (dggbak, DGGBAK,
-                (F77_CONST_CHAR_ARG2 (&bal_job, 1),
-                 F77_CONST_CHAR_ARG2 ("L", 1),
-                 nn, ilo, ihi, lscale.data (), rscale.data (),
-                 nn, QQ.fortran_vec (), nn, info
-                 F77_CHAR_ARG_LEN (1)
-                 F77_CHAR_ARG_LEN (1)));
-
-#ifdef DEBUG
-      if (compq == 'V')
-        std::cout << "qz: balancing done; QQ=" << std::endl << QQ << std::endl;
-#endif
-  }
-
-  // then right
-  if (compz == 'V')
-    {
-      F77_XFCN (dggbak, DGGBAK,
-                (F77_CONST_CHAR_ARG2 (&bal_job, 1),
-                 F77_CONST_CHAR_ARG2 ("R", 1),
-                 nn, ilo, ihi, lscale.data (), rscale.data (),
-                 nn, ZZ.fortran_vec (), nn, info
-                 F77_CHAR_ARG_LEN (1)
-                 F77_CHAR_ARG_LEN (1)));
-
-#ifdef DEBUG
-      if (compz == 'V')
-        std::cout << "qz: balancing done; ZZ=" << std::endl << ZZ << std::endl;
-#endif
-    }
-#endif
-
-  static char qz_job;
-  qz_job = (nargout < 2 ? 'E' : 'S');
-
-  if (complex_case)
-    {
-      // Complex case.
-
-      // The QR decomposition of cbb.
-      ComplexQR cbqr (cbb);
-      // The R matrix of QR decomposition for cbb.
-      cbb = cbqr.R ();
-      // (Q*)caa for following work.
-      caa = (cbqr.Q ().hermitian ()) * caa;
-      CQ = CQ * cbqr.Q ();
-
-      F77_XFCN (zgghrd, ZGGHRD,
-                (F77_CONST_CHAR_ARG2 (&compq, 1),
-                 F77_CONST_CHAR_ARG2 (&compz, 1),
-                 nn, ilo, ihi, caa.fortran_vec (),
-                 nn, cbb.fortran_vec (), nn, CQ.fortran_vec (), nn,
-                 CZ.fortran_vec (), nn, info
-                 F77_CHAR_ARG_LEN (1)
-                 F77_CHAR_ARG_LEN (1)));
-
-      ComplexRowVector cwork (1 * nn);
-
-      F77_XFCN (zhgeqz, ZHGEQZ,
-                (F77_CONST_CHAR_ARG2 (&qz_job, 1),
-                 F77_CONST_CHAR_ARG2 (&compq, 1),
-                 F77_CONST_CHAR_ARG2 (&compz, 1),
-                 nn, ilo, ihi,
-                 caa.fortran_vec (), nn,
-                 cbb.fortran_vec (),nn,
-                 xalpha.fortran_vec (), xbeta.fortran_vec (),
-                 CQ.fortran_vec (), nn,
-                 CZ.fortran_vec (), nn,
-                 cwork.fortran_vec (), nn, rwork.fortran_vec (), info
-                 F77_CHAR_ARG_LEN (1)
-                 F77_CHAR_ARG_LEN (1)
-                 F77_CHAR_ARG_LEN (1)));
-
-      if (compq == 'V')
-        {
-          // Left eigenvector.
-          F77_XFCN (zggbak, ZGGBAK,
-                    (F77_CONST_CHAR_ARG2 (&bal_job, 1),
-                     F77_CONST_CHAR_ARG2 ("L", 1),
-                     nn, ilo, ihi, lscale.data (), rscale.data (),
-                     nn, CQ.fortran_vec (), nn, info
-                     F77_CHAR_ARG_LEN (1)
-                     F77_CHAR_ARG_LEN (1)));
-        }
-
-      // Right eigenvector.
-      if (compz == 'V')
-        {
-          F77_XFCN (zggbak, ZGGBAK,
-                    (F77_CONST_CHAR_ARG2 (&bal_job, 1),
-                     F77_CONST_CHAR_ARG2 ("R", 1),
-                     nn, ilo, ihi, lscale.data (), rscale.data (),
-                     nn, CZ.fortran_vec (), nn, info
-                     F77_CHAR_ARG_LEN (1)
-                     F77_CHAR_ARG_LEN (1)));
-        }
-
-    }
-  else
-    {
-#ifdef DEBUG
-      std::cout << "qz: peforming qr decomposition of bb" << std::endl;
-#endif
-
-      // Compute the QR factorization of bb.
-      QR bqr (bb);
-
-#ifdef DEBUG
-      std::cout << "qz: qr (bb) done; now peforming qz decomposition" << std::endl;
-#endif
-
-      bb = bqr.R ();
-
-#ifdef DEBUG
-      std::cout << "qz: extracted bb" << std::endl;
-#endif
-
-      aa = (bqr.Q ()).transpose () * aa;
-
-#ifdef DEBUG
-      std::cout << "qz: updated aa " << std::endl;
-      std::cout << "bqr.Q () = " << std::endl << bqr.Q () << std::endl;
-
-      if (compq == 'V')
-        std::cout << "QQ =" << QQ << std::endl;
-#endif
-
-      if (compq == 'V')
-        QQ = QQ * bqr.Q ();
-
-#ifdef DEBUG
-      std::cout << "qz: precursors done..." << std::endl;
-#endif
-
-#ifdef DEBUG
-      std::cout << "qz: compq = " << compq << ", compz = " << compz << std::endl;
-#endif
-
-      // Reduce  to generalized hessenberg form.
-      F77_XFCN (dgghrd, DGGHRD,
-                (F77_CONST_CHAR_ARG2 (&compq, 1),
-                 F77_CONST_CHAR_ARG2 (&compz, 1),
-                 nn, ilo, ihi, aa.fortran_vec (),
-                 nn, bb.fortran_vec (), nn, QQ.fortran_vec (), nn,
-                 ZZ.fortran_vec (), nn, info
-                 F77_CHAR_ARG_LEN (1)
-                 F77_CHAR_ARG_LEN (1)));
-
-      // Check if just computing generalized eigenvalues or if we're
-      // actually computing the decomposition.
-
-      // Reduce to generalized Schur form.
-      F77_XFCN (dhgeqz, DHGEQZ,
-                (F77_CONST_CHAR_ARG2 (&qz_job, 1),
-                 F77_CONST_CHAR_ARG2 (&compq, 1),
-                 F77_CONST_CHAR_ARG2 (&compz, 1),
-                 nn, ilo, ihi, aa.fortran_vec (), nn, bb.fortran_vec (),
-                 nn, alphar.fortran_vec (), alphai.fortran_vec (),
-                 betar.fortran_vec (), QQ.fortran_vec (), nn,
-                 ZZ.fortran_vec (), nn, work.fortran_vec (), nn, info
-                 F77_CHAR_ARG_LEN (1)
-                 F77_CHAR_ARG_LEN (1)
-                 F77_CHAR_ARG_LEN (1)));
-
-      if (compq == 'V')
-        {
-          F77_XFCN (dggbak, DGGBAK,
-                    (F77_CONST_CHAR_ARG2 (&bal_job, 1),
-                     F77_CONST_CHAR_ARG2 ("L", 1),
-                     nn, ilo, ihi, lscale.data (), rscale.data (),
-                     nn, QQ.fortran_vec (), nn, info
-                     F77_CHAR_ARG_LEN (1)
-                     F77_CHAR_ARG_LEN (1)));
-
-#ifdef DEBUG
-          if (compq == 'V')
-            std::cout << "qz: balancing done; QQ=" << std::endl << QQ << std::endl;
-#endif
-        }
-
-  // then right
-      if (compz == 'V')
-        {
-           F77_XFCN (dggbak, DGGBAK,
-                     (F77_CONST_CHAR_ARG2 (&bal_job, 1),
-                      F77_CONST_CHAR_ARG2 ("R", 1),
-                      nn, ilo, ihi, lscale.data (), rscale.data (),
-                      nn, ZZ.fortran_vec (), nn, info
-                      F77_CHAR_ARG_LEN (1)
-                      F77_CHAR_ARG_LEN (1)));
-
-#ifdef DEBUG
-           if (compz == 'V')
-             std::cout << "qz: balancing done; ZZ=" << std::endl << ZZ << std::endl;
-#endif
-        }
-
-    }
-
-  // Order the QZ decomposition?
-  if (! (ord_job == 'N' || ord_job == 'n'))
-    {
-      if (complex_case)
-        {
-          // Probably not needed, but better be safe.
-          error ("qz: cannot re-order complex qz decomposition");
-          return retval;
-        }
-      else
-        {
-#ifdef DEBUG_SORT
-          std::cout << "qz: ordering eigenvalues: ord_job = "
-                    << ord_job << std::endl;
-#endif
-
-          // Declared static to avoid vfork/long jump compiler complaints.
-          static sort_function sort_test;
-          sort_test = 0;
-
-          switch (ord_job)
-            {
-            case 'S':
-            case 's':
-              sort_test = &fin;
-              break;
-
-            case 'B':
-            case 'b':
-              sort_test = &fout;
-              break;
-
-            case '+':
-              sort_test = &fcrhp;
-              break;
-
-            case '-':
-              sort_test = &folhp;
-              break;
-
-            default:
-              // Invalid order option (should never happen, since we
-              // checked the options at the top).
-              panic_impossible ();
-              break;
-            }
-
-          octave_idx_type ndim, fail;
-          double inf_norm;
-
-          F77_XFCN (xdlange, XDLANGE,
-                    (F77_CONST_CHAR_ARG2 ("I", 1),
-                     nn, nn, aa.data (), nn, work.fortran_vec (), inf_norm
-                     F77_CHAR_ARG_LEN (1)));
-
-          double eps = DBL_EPSILON * inf_norm * nn;
-
-#ifdef DEBUG_SORT
-          std::cout << "qz: calling dsubsp: aa=" << std::endl;
-          octave_print_internal (std::cout, aa, 0);
-          std::cout << std::endl << "bb="  << std::endl;
-          octave_print_internal (std::cout, bb, 0);
-          if (compz == 'V')
-            {
-              std::cout << std::endl << "ZZ="  << std::endl;
-              octave_print_internal (std::cout, ZZ, 0);
-            }
-          std::cout << std::endl;
-          std::cout << "alphar = " << std::endl;
-          octave_print_internal (std::cout, (Matrix) alphar, 0);
-          std::cout << std::endl << "alphai = " << std::endl;
-          octave_print_internal (std::cout, (Matrix) alphai, 0);
-          std::cout << std::endl << "beta = " << std::endl;
-          octave_print_internal (std::cout, (Matrix) betar, 0);
-          std::cout << std::endl;
-#endif
-
-          Array<octave_idx_type> ind (dim_vector (nn, 1));
-
-          F77_XFCN (dsubsp, DSUBSP,
-                    (nn, nn, aa.fortran_vec (), bb.fortran_vec (),
-                     ZZ.fortran_vec (), sort_test, eps, ndim, fail,
-                     ind.fortran_vec ()));
-
-#ifdef DEBUG
-          std::cout << "qz: back from dsubsp: aa=" << std::endl;
-          octave_print_internal (std::cout, aa, 0);
-          std::cout << std::endl << "bb="  << std::endl;
-          octave_print_internal (std::cout, bb, 0);
-          if (compz == 'V')
-            {
-              std::cout << std::endl << "ZZ="  << std::endl;
-              octave_print_internal (std::cout, ZZ, 0);
-            }
-          std::cout << std::endl;
-#endif
-
-          // Manually update alphar, alphai, betar.
-          static int jj;
-
-          jj = 0;
-          while (jj < nn)
-            {
-#ifdef DEBUG_EIG
-              std::cout << "computing gen eig #" << jj << std::endl;
-#endif
-
-              // Number of zeros in this block.
-              static int zcnt;
-
-              if (jj == (nn-1))
-                zcnt = 1;
-              else if (aa(jj+1,jj) == 0)
-                zcnt = 1;
-              else zcnt = 2;
-
-              if (zcnt == 1)
-                {
-                  // Real zero.
-#ifdef DEBUG_EIG
-                  std::cout << "  single gen eig:" << std::endl;
-                  std::cout << "  alphar(" << jj << ") = " << aa(jj,jj) << std::endl;
-                  std::cout << "  betar( " << jj << ") = " << bb(jj,jj) << std::endl;
-                  std::cout << "  alphai(" << jj << ") = 0" << std::endl;
-#endif
-
-                  alphar(jj) = aa(jj,jj);
-                  alphai(jj) = 0;
-                  betar(jj) = bb(jj,jj);
-                }
-              else
-                {
-                  // Complex conjugate pair.
-#ifdef DEBUG_EIG
-                  std::cout << "qz: calling dlag2:" << std::endl;
-                  std::cout << "safmin="
-                       << setiosflags (std::ios::scientific) << safmin << std::endl;
-
-                  for (int idr = jj; idr <= jj+1; idr++)
-                    {
-                      for (int idc = jj; idc <= jj+1; idc++)
-                        {
-                          std::cout << "aa(" << idr << "," << idc << ")="
-                               << aa(idr,idc) << std::endl;
-                          std::cout << "bb(" << idr << "," << idc << ")="
-                               << bb(idr,idc) << std::endl;
-                        }
-                    }
-#endif
-
-                  // FIXME -- probably should be using
-                  // fortran_vec instead of &aa(jj,jj) here.
-
-                  double scale1, scale2, wr1, wr2, wi;
-                  const double *aa_ptr = aa.data () + jj * nn + jj;
-                  const double *bb_ptr = bb.data () + jj * nn + jj;
-                  F77_XFCN (dlag2, DLAG2,
-                            (aa_ptr, nn, bb_ptr, nn, safmin,
-                             scale1, scale2, wr1, wr2, wi));
-
-#ifdef DEBUG_EIG
-                  std::cout << "dlag2 returns: scale1=" << scale1
-                       << "\tscale2=" << scale2 << std::endl
-                       << "\twr1=" << wr1 << "\twr2=" << wr2
-                       << "\twi=" << wi << std::endl;
-#endif
-
-                  // Just to be safe, check if it's a real pair.
-                  if (wi == 0)
-                    {
-                      alphar(jj) = wr1;
-                      alphai(jj) = 0;
-                      betar(jj) = scale1;
-                      alphar(jj+1) = wr2;
-                      alphai(jj+1) = 0;
-                      betar(jj+1) = scale2;
-                    }
-                  else
-                    {
-                      alphar(jj) = alphar(jj+1) = wr1;
-                      alphai(jj) = -(alphai(jj+1) = wi);
-                      betar(jj)  = betar(jj+1) = scale1;
-                    }
-                }
-
-              // Advance past this block.
-              jj += zcnt;
-            }
-
-#ifdef DEBUG_SORT
-          std::cout << "qz: back from dsubsp: aa=" << std::endl;
-          octave_print_internal (std::cout, aa, 0);
-          std::cout << std::endl << "bb="  << std::endl;
-          octave_print_internal (std::cout, bb, 0);
-
-          if (compz == 'V')
-            {
-              std::cout << std::endl << "ZZ="  << std::endl;
-              octave_print_internal (std::cout, ZZ, 0);
-            }
-          std::cout << std::endl << "qz: ndim=" << ndim << std::endl
-               << "fail=" << fail << std::endl;
-          std::cout << "alphar = " << std::endl;
-          octave_print_internal (std::cout, (Matrix) alphar, 0);
-          std::cout << std::endl << "alphai = " << std::endl;
-          octave_print_internal (std::cout, (Matrix) alphai, 0);
-          std::cout << std::endl << "beta = " << std::endl;
-          octave_print_internal (std::cout, (Matrix) betar, 0);
-          std::cout << std::endl;
-#endif
-        }
-    }
-
-  // Compute generalized eigenvalues?
-  ComplexColumnVector gev;
-
-  if (nargout < 2 || nargout == 7 || (nargin == 3 && nargout == 4))
-    {
-      if (complex_case)
-        {
-          int cnt = 0;
-
-          for (int ii = 0; ii < nn; ii++)
-            cnt++;
-
-          ComplexColumnVector tmp (cnt);
-
-          cnt = 0;
-          for (int ii = 0; ii < nn; ii++)
-            tmp(cnt++) = xalpha(ii) / xbeta(ii);
-
-          gev = tmp;
-        }
-      else
-        {
-#ifdef DEBUG
-          std::cout << "qz: computing generalized eigenvalues" << std::endl;
-#endif
-
-          // Return finite generalized eigenvalues.
-          int cnt = 0;
-
-          for (int ii = 0; ii < nn; ii++)
-            if (betar(ii) != 0)
-              cnt++;
-
-          ComplexColumnVector tmp (cnt);
-
-          cnt = 0;
-          for (int ii = 0; ii < nn; ii++)
-            if (betar(ii) != 0)
-              tmp(cnt++) = Complex(alphar(ii), alphai(ii))/betar(ii);
-
-          gev = tmp;
-        }
-    }
-
-  // Right, left eigenvector matrices.
-  if (nargout >= 5)
-    {
-      // Which side to compute?
-      char side = (nargout == 5 ? 'R' : 'B');
-      // Compute all of them and backtransform
-      char howmny = 'B';
-      // Dummy pointer; select is not used.
-      octave_idx_type *select = 0;
-
-      if (complex_case)
-        {
-          CVL = CQ;
-          CVR = CZ;
-          ComplexRowVector cwork2 (2 * nn);
-          RowVector rwork2 (8 * nn);
-          octave_idx_type m;
-
-          F77_XFCN (ztgevc, ZTGEVC,
-                    (F77_CONST_CHAR_ARG2 (&side, 1),
-                     F77_CONST_CHAR_ARG2 (&howmny, 1),
-                     select, nn, caa.fortran_vec (), nn, cbb.fortran_vec (),
-                     nn, CVL.fortran_vec (), nn, CVR.fortran_vec (), nn, nn,
-                     m, cwork2.fortran_vec (), rwork2.fortran_vec (), info
-                     F77_CHAR_ARG_LEN (1)
-                     F77_CHAR_ARG_LEN (1)));
-        }
-      else
-        {
-#ifdef DEBUG
-          std::cout << "qz: computing  generalized eigenvectors" << std::endl;
-#endif
-
-          VL = QQ;
-          VR = ZZ;
-          octave_idx_type m;
-
-          F77_XFCN (dtgevc, DTGEVC,
-                    (F77_CONST_CHAR_ARG2 (&side, 1),
-                     F77_CONST_CHAR_ARG2 (&howmny, 1),
-                     select, nn, aa.fortran_vec (), nn, bb.fortran_vec (),
-                     nn, VL.fortran_vec (), nn, VR.fortran_vec (), nn, nn,
-                     m, work.fortran_vec (), info
-                     F77_CHAR_ARG_LEN (1)
-                     F77_CHAR_ARG_LEN (1)));
-
-          // Now construct the complex form of VV, WW.
-          int jj = 0;
-
-          while (jj < nn)
-            {
-              OCTAVE_QUIT;
-
-              // See if real or complex eigenvalue.
-
-              // Column increment; assume complex eigenvalue.
-              int cinc = 2;
-
-              if (jj == (nn-1))
-                // Single column.
-                cinc = 1;
-              else if (aa(jj+1,jj) == 0)
-                cinc = 1;
-
-              // Now copy the eigenvector (s) to CVR, CVL.
-              if (cinc == 1)
-                {
-                  for (int ii = 0; ii < nn; ii++)
-                    CVR(ii,jj) = VR(ii,jj);
-
-                  if (side == 'B')
-                    for (int ii = 0; ii < nn; ii++)
-                      CVL(ii,jj) = VL(ii,jj);
-                }
-              else
-                {
-                  // Double column; complex vector.
-
-                  for (int ii = 0; ii < nn; ii++)
-                    {
-                      CVR(ii,jj) = Complex (VR(ii,jj), VR(ii,jj+1));
-                      CVR(ii,jj+1) = Complex (VR(ii,jj), -VR(ii,jj+1));
-                    }
-
-                  if (side == 'B')
-                    for (int ii = 0; ii < nn; ii++)
-                      {
-                        CVL(ii,jj) = Complex (VL(ii,jj), VL(ii,jj+1));
-                        CVL(ii,jj+1) = Complex (VL(ii,jj), -VL(ii,jj+1));
-                      }
-                }
-
-              // Advance to next eigenvectors (if any).
-              jj += cinc;
-            }
-        }
-    }
-
-  switch (nargout)
-    {
-    case 7:
-      retval(6) = gev;
-
-    case 6:
-      // Return eigenvectors.
-      retval(5) = CVL;
-
-    case 5:
-      // Return eigenvectors.
-      retval(4) = CVR;
-
-    case 4:
-      if (nargin == 3)
-        {
-#ifdef DEBUG
-          std::cout << "qz: sort: retval(3) = gev = " << std::endl;
-          octave_print_internal (std::cout, gev);
-          std::cout << std::endl;
-#endif
-          retval(3) = gev;
-        }
-      else
-        {
-          if (complex_case)
-            retval(3) = CZ;
-          else
-            retval(3) = ZZ;
-        }
-
-    case 3:
-      if (nargin == 3)
-        {
-          if (complex_case)
-            retval(2) = CZ;
-          else
-            retval(2) = ZZ;
-        }
-      else
-        {
-          if (complex_case)
-            retval(2) = CQ.hermitian ();
-          else
-            retval(2) = QQ.transpose ();
-        }
-
-    case 2:
-      {
-        if (complex_case)
-          {
-#ifdef DEBUG
-            std::cout << "qz: retval(1) = cbb = " << std::endl;
-            octave_print_internal (std::cout, cbb, 0);
-            std::cout << std::endl << "qz: retval(0) = caa = " <<std::endl;
-            octave_print_internal (std::cout, caa, 0);
-            std::cout << std::endl;
-#endif
-            retval(1) = cbb;
-            retval(0) = caa;
-          }
-      else
-        {
-#ifdef DEBUG
-          std::cout << "qz: retval(1) = bb = " << std::endl;
-          octave_print_internal (std::cout, bb, 0);
-          std::cout << std::endl << "qz: retval(0) = aa = " <<std::endl;
-          octave_print_internal (std::cout, aa, 0);
-          std::cout << std::endl;
-#endif
-          retval(1) = bb;
-          retval(0) = aa;
-        }
-      }
-      break;
-
-
-    case 1:
-    case 0:
-#ifdef DEBUG
-      std::cout << "qz: retval(0) = gev = " << gev << std::endl;
-#endif
-      retval(0) = gev;
-      break;
-
-    default:
-      error ("qz: too many return arguments");
-      break;
-  }
-
-#ifdef DEBUG
-  std::cout << "qz: exiting (at long last)" << std::endl;
-#endif
-
-  return retval;
-}
-
-/*
-%!shared a, b, c
-%! a = [1 2; 0 3];
-%! b = [1 0; 0 0];
-%! c = [0 1; 0 0];
-%!assert (qz (a,b), 1)
-%!assert (isempty (qz (a,c)))
-
-## Exaple 7.7.3 in Golub & Van Loan
-%!test
-%! a = [ 10  1  2;
-%!        1  2 -1;
-%!        1  1  2];
-%! b = reshape (1:9,3,3);
-%! [aa, bb, q, z, v, w, lambda] = qz (a, b);
-%! sz = length (lambda);
-%! observed = (b * v * diag ([lambda;0])) (:, 1:sz);
-%! assert ( (a*v) (:, 1:sz), observed, norm (observed) * 1e-14);
-%! observed = (diag ([lambda;0]) * w' * b) (1:sz, :);
-%! assert ( (w'*a) (1:sz, :) , observed, norm (observed) * 1e-13);
-%! assert (q * a * z, aa, norm (aa) * 1e-14);
-%! assert (q * b * z, bb, norm (bb) * 1e-14);
-
-%!test
-%! A = [0, 0, -1, 0; 1, 0, 0, 0; -1, 0, -2, -1; 0, -1, 1, 0];
-%! B = [0, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1];
-%! [AA, BB, Q, Z1] = qz (A, B);
-%! [AA, BB, Z2] = qz (A, B, '-');
-%! assert (Z1, Z2);
-*/
--- a/src/DLD-FUNCTIONS/rand.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1221 +0,0 @@
-
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-Copyright (C) 2009 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <ctime>
-#if defined (HAVE_UNORDERED_MAP)
-#include <unordered_map>
-#elif defined (HAVE_TR1_UNORDERED_MAP)
-#include <tr1/unordered_map>
-#endif
-#include <string>
-
-#include "f77-fcn.h"
-#include "lo-mappers.h"
-#include "oct-rand.h"
-#include "quit.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "unwind-prot.h"
-#include "utils.h"
-#include "ov-re-mat.h"
-
-/*
-%!shared __random_statistical_tests__
-%! # Flag whether the statistical tests should be run in "make check" or not
-%! __random_statistical_tests__ = 0;
-*/
-
-static octave_value
-do_rand (const octave_value_list& args, int nargin, const char *fcn,
-         const std::string& distribution, bool additional_arg = false)
-{
-  octave_value retval;
-  NDArray a;
-  int idx = 0;
-  dim_vector dims;
-  bool is_single = false;
-
-  unwind_protect frame;
-  // Restore current distribution on any exit.
-  frame.add_fcn (octave_rand::distribution,
-                 octave_rand::distribution ());
-
-  octave_rand::distribution (distribution);
-
-  if (nargin > 0 && args(nargin-1).is_string ())
-    {
-      std::string s_arg = args(nargin-1).string_value ();
-
-      if (s_arg == "single")
-        {
-          is_single = true;
-          nargin--;
-        }
-      else if (s_arg == "double")
-        nargin--;
-    }
-
-  if (additional_arg)
-    {
-      if (nargin == 0)
-        {
-          error ("%s: expecting at least one argument", fcn);
-          goto done;
-        }
-      else if (args(0).is_string ())
-        additional_arg = false;
-      else
-        {
-          a = args(0).array_value ();
-          if (error_state)
-            {
-              error ("%s: expecting scalar or matrix arguments", fcn);
-              goto done;
-            }
-          idx++;
-          nargin--;
-        }
-    }
-
-  switch (nargin)
-    {
-    case 0:
-      {
-        if (additional_arg)
-          dims = a.dims ();
-        else
-          {
-            dims.resize (2);
-
-            dims(0) = 1;
-            dims(1) = 1;
-          }
-        goto gen_matrix;
-      }
-      break;
-
-    case 1:
-      {
-        octave_value tmp = args(idx);
-
-        if (tmp.is_string ())
-          {
-            std::string s_arg = tmp.string_value ();
-
-            if (s_arg == "dist")
-              {
-                retval = octave_rand::distribution ();
-              }
-            else if (s_arg == "seed")
-              {
-                retval = octave_rand::seed ();
-              }
-            else if (s_arg == "state" || s_arg == "twister")
-              {
-                retval = octave_rand::state (fcn);
-              }
-            else if (s_arg == "uniform")
-              {
-                octave_rand::uniform_distribution ();
-              }
-            else if (s_arg == "normal")
-              {
-                octave_rand::normal_distribution ();
-              }
-            else if (s_arg == "exponential")
-              {
-                octave_rand::exponential_distribution ();
-              }
-            else if (s_arg == "poisson")
-              {
-                octave_rand::poisson_distribution ();
-              }
-            else if (s_arg == "gamma")
-              {
-                octave_rand::gamma_distribution ();
-              }
-            else
-              error ("%s: unrecognized string argument", fcn);
-          }
-        else if (tmp.is_scalar_type ())
-          {
-            double dval = tmp.double_value ();
-
-            if (xisnan (dval))
-              {
-                error ("%s: NaN is invalid matrix dimension", fcn);
-              }
-            else
-              {
-                dims.resize (2);
-
-                dims(0) = NINTbig (tmp.double_value ());
-                dims(1) = NINTbig (tmp.double_value ());
-
-                if (! error_state)
-                  goto gen_matrix;
-              }
-          }
-        else if (tmp.is_range ())
-          {
-            Range r = tmp.range_value ();
-
-            if (r.all_elements_are_ints ())
-              {
-                octave_idx_type n = r.nelem ();
-
-                dims.resize (n);
-
-                octave_idx_type base = NINTbig (r.base ());
-                octave_idx_type incr = NINTbig (r.inc ());
-
-                for (octave_idx_type i = 0; i < n; i++)
-                  {
-                    //Negative dimensions are treated as zero for Matlab
-                    //compatibility
-                    dims(i) = base >= 0 ? base : 0;
-                    base += incr;
-                  }
-
-                goto gen_matrix;
-
-              }
-            else
-              error ("%s: all elements of range must be integers",
-                     fcn);
-          }
-        else if (tmp.is_matrix_type ())
-          {
-            Array<int> iv = tmp.int_vector_value (true);
-
-            if (! error_state)
-              {
-                octave_idx_type len = iv.length ();
-
-                dims.resize (len);
-
-                for (octave_idx_type i = 0; i < len; i++)
-                  {
-                    //Negative dimensions are treated as zero for Matlab
-                    //compatibility
-                    octave_idx_type elt = iv(i);
-                    dims(i) = elt >=0 ? elt : 0;
-                  }
-
-                goto gen_matrix;
-              }
-            else
-              error ("%s: expecting integer vector", fcn);
-          }
-        else
-          {
-            gripe_wrong_type_arg ("rand", tmp);
-            return retval;
-          }
-      }
-      break;
-
-    default:
-      {
-        octave_value tmp = args(idx);
-
-        if (nargin == 2 && tmp.is_string ())
-          {
-            std::string ts = tmp.string_value ();
-
-            if (ts == "seed")
-              {
-                if (args(idx+1).is_real_scalar ())
-                  {
-                    double d = args(idx+1).double_value ();
-
-                    if (! error_state)
-                      octave_rand::seed (d);
-                  }
-                else if (args(idx+1).is_string ()
-                         && args(idx+1).string_value () == "reset")
-                  octave_rand::reset ();
-                else
-                  error ("%s: seed must be a real scalar", fcn);
-              }
-            else if (ts == "state" || ts == "twister")
-              {
-                if (args(idx+1).is_string ()
-                    && args(idx+1).string_value () == "reset")
-                  octave_rand::reset (fcn);
-                else
-                  {
-                    ColumnVector s =
-                      ColumnVector (args(idx+1).vector_value(false, true));
-
-                    if (! error_state)
-                      octave_rand::state (s, fcn);
-                  }
-              }
-            else
-              error ("%s: unrecognized string argument", fcn);
-          }
-        else
-          {
-            dims.resize (nargin);
-
-            for (int i = 0; i < nargin; i++)
-              {
-                octave_idx_type elt = args(idx+i).int_value ();
-                if (error_state)
-                  {
-                    error ("%s: expecting integer arguments", fcn);
-                    goto done;
-                  }
-                //Negative is zero for Matlab compatibility
-                dims(i) = elt >= 0 ? elt : 0;
-              }
-
-            goto gen_matrix;
-          }
-      }
-      break;
-    }
-
- done:
-
-  return retval;
-
- gen_matrix:
-
-  dims.chop_trailing_singletons ();
-
-  if (is_single)
-    {
-      if (additional_arg)
-        {
-          if (a.length () == 1)
-            return octave_rand::float_nd_array (dims, a(0));
-          else
-            {
-              if (a.dims () != dims)
-                {
-                  error ("%s: mismatch in argument size", fcn);
-                  return retval;
-                }
-              octave_idx_type len = a.length ();
-              FloatNDArray m (dims);
-              float *v = m.fortran_vec ();
-              for (octave_idx_type i = 0; i < len; i++)
-                v[i] = octave_rand::float_scalar (a(i));
-              return m;
-            }
-        }
-      else
-        return octave_rand::float_nd_array (dims);
-    }
-  else
-    {
-      if (additional_arg)
-        {
-          if (a.length () == 1)
-            return octave_rand::nd_array (dims, a(0));
-          else
-            {
-              if (a.dims () != dims)
-                {
-                  error ("%s: mismatch in argument size", fcn);
-                  return retval;
-                }
-              octave_idx_type len = a.length ();
-              NDArray m (dims);
-              double *v = m.fortran_vec ();
-              for (octave_idx_type i = 0; i < len; i++)
-                v[i] = octave_rand::scalar (a(i));
-              return m;
-            }
-        }
-      else
-        return octave_rand::nd_array (dims);
-    }
-}
-
-DEFUN_DLD (rand, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} rand (@var{n})\n\
-@deftypefnx {Loadable Function} {} rand (@var{n}, @var{m}, @dots{})\n\
-@deftypefnx {Loadable Function} {} rand ([@var{n} @var{m} @dots{}])\n\
-@deftypefnx {Loadable Function} {@var{v} =} rand (\"state\")\n\
-@deftypefnx {Loadable Function} {} rand (\"state\", @var{v})\n\
-@deftypefnx {Loadable Function} {} rand (\"state\", \"reset\")\n\
-@deftypefnx {Loadable Function} {@var{v} =} rand (\"seed\")\n\
-@deftypefnx {Loadable Function} {} rand (\"seed\", @var{v})\n\
-@deftypefnx {Loadable Function} {} rand (\"seed\", \"reset\")\n\
-@deftypefnx {Loadable Function} {} rand (@dots{}, \"single\")\n\
-@deftypefnx {Loadable Function} {} rand (@dots{}, \"double\")\n\
-Return a matrix with random elements uniformly distributed on the\n\
-interval (0, 1).  The arguments are handled the same as the arguments\n\
-for @code{eye}.\n\
-\n\
-You can query the state of the random number generator using the\n\
-form\n\
-\n\
-@example\n\
-v = rand (\"state\")\n\
-@end example\n\
-\n\
-This returns a column vector @var{v} of length 625.  Later, you can\n\
-restore the random number generator to the state @var{v}\n\
-using the form\n\
-\n\
-@example\n\
-rand (\"state\", v)\n\
-@end example\n\
-\n\
-@noindent\n\
-You may also initialize the state vector from an arbitrary vector of\n\
-length @leq{} 625 for @var{v}.  This new state will be a hash based on the\n\
-value of @var{v}, not @var{v} itself.\n\
-\n\
-By default, the generator is initialized from @code{/dev/urandom} if it is\n\
-available, otherwise from CPU time, wall clock time, and the current\n\
-fraction of a second.  Note that this differs from @sc{matlab}, which\n\
-always initializes the state to the same state at startup.  To obtain\n\
-behavior comparable to @sc{matlab}, initialize with a deterministic state\n\
-vector in Octave's startup files (@pxref{Startup Files}).\n\
-\n\
-To compute the pseudo-random sequence, @code{rand} uses the Mersenne\n\
-Twister with a period of @math{2^{19937}-1} (See M. Matsumoto and\n\
-T. Nishimura,\n\
-@cite{Mersenne Twister: A 623-dimensionally equidistributed uniform\n\
-pseudorandom number generator}, ACM Trans. on\n\
-Modeling and Computer Simulation Vol. 8, No. 1, pp. 3-30, January 1998,\n\
-@url{http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html}).\n\
-Do @strong{not} use for cryptography without securely hashing\n\
-several returned values together, otherwise the generator state\n\
-can be learned after reading 624 consecutive values.\n\
-\n\
-Older versions of Octave used a different random number generator.\n\
-The new generator is used by default\n\
-as it is significantly faster than the old generator, and produces\n\
-random numbers with a significantly longer cycle time.  However, in\n\
-some circumstances it might be desirable to obtain the same random\n\
-sequences as used by the old generators.  To do this the keyword\n\
-\"seed\" is used to specify that the old generators should be use,\n\
-as in\n\
-\n\
-@example\n\
-rand (\"seed\", val)\n\
-@end example\n\
-\n\
-@noindent\n\
-which sets the seed of the generator to @var{val}.  The seed of the\n\
-generator can be queried with\n\
-\n\
-@example\n\
-s = rand (\"seed\")\n\
-@end example\n\
-\n\
-However, it should be noted that querying the seed will not cause\n\
-@code{rand} to use the old generators, only setting the seed will.\n\
-To cause @code{rand} to once again use the new generators, the\n\
-keyword \"state\" should be used to reset the state of the @code{rand}.\n\
-\n\
-The state or seed of the generator can be reset to a new random value\n\
-using the \"reset\" keyword.\n\
-\n\
-The class of the value returned can be controlled by a trailing \"double\"\n\
-or \"single\" argument.  These are the only valid classes.\n\
-@seealso{randn, rande, randg, randp}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  retval = do_rand (args, nargin, "rand", "uniform");
-
-  return retval;
-}
-
-// FIXME -- The old generator (selected when "seed" is set) will not
-// work properly if compiled to use 64-bit integers.
-
-/*
-%!test  # "state" can be a scalar
-%! rand ("state", 12);  x = rand (1,4);
-%! rand ("state", 12);  y = rand (1,4);
-%! assert (x, y);
-%!test  # "state" can be a vector
-%! rand ("state", [12,13]);  x = rand (1,4);
-%! rand ("state", [12;13]);  y = rand (1,4);
-%! assert (x, y);
-%!test  # querying "state" doesn't disturb sequence
-%! rand ("state", 12);  rand (1,2);  x = rand (1,2);
-%! rand ("state", 12);  rand (1,2);
-%! s = rand ("state");  y = rand (1,2);
-%! assert (x, y);
-%! rand ("state", s);  z = rand (1,2);
-%! assert (x, z);
-%!test  # "seed" must be a scalar
-%! rand ("seed", 12);  x = rand (1,4);
-%! rand ("seed", 12);  y = rand (1,4);
-%! assert (x, y);
-%!error <seed must be a real scalar> rand ("seed", [12,13])
-%!test  # querying "seed" returns a value which can be used later
-%! s = rand ("seed");  x = rand (1,2);
-%! rand ("seed", s);  y = rand (1,2);
-%! assert (x, y);
-%!test  # querying "seed" doesn't disturb sequence
-%! rand ("seed", 12);  rand (1,2);  x = rand (1,2);
-%! rand ("seed", 12);  rand (1,2);
-%! s = rand ("seed");  y = rand (1,2);
-%! assert (x, y);
-%! rand ("seed", s);  z = rand (1,2);
-%! assert (x, z);
-*/
-
-/*
-%!test
-%! # Test fixed state
-%! rand ("state", 1);
-%! assert (rand (1,6), [0.1343642441124013 0.8474337369372327 0.763774618976614 0.2550690257394218 0.495435087091941 0.4494910647887382], 1e-6);
-%!test
-%! # Test fixed seed
-%! rand ("seed", 1);
-%! assert (rand (1,6), [0.8668024251237512 0.9126510815694928 0.09366085007786751 0.1664607301354408 0.7408077004365623 0.7615650338120759], 1e-6);
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   rand ("state", 12);
-%!   x = rand (100000, 1);
-%!   assert (max (x) < 1);   #*** Please report this!!! ***
-%!   assert (min (x) > 0);   #*** Please report this!!! ***
-%!   assert (mean (x), 0.5, 0.0024);
-%!   assert (var (x), 1/48, 0.0632);
-%!   assert (skewness (x), 0, 0.012);
-%!   assert (kurtosis (x), -6/5, 0.0094);
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   rand ("seed", 12);
-%!   x = rand (100000, 1);
-%!   assert (max (x) < 1);   #*** Please report this!!! ***
-%!   assert (min (x) > 0);   #*** Please report this!!! ***
-%!   assert (mean (x), 0.5, 0.0024);
-%!   assert (var (x), 1/48, 0.0632);
-%!   assert (skewness (x), 0, 0.012);
-%!   assert (kurtosis (x), -6/5, 0.0094);
-%! endif
-*/
-
-static std::string current_distribution = octave_rand::distribution ();
-
-DEFUN_DLD (randn, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} randn (@var{n})\n\
-@deftypefnx {Loadable Function} {} randn (@var{n}, @var{m}, @dots{})\n\
-@deftypefnx {Loadable Function} {} randn ([@var{n} @var{m} @dots{}])\n\
-@deftypefnx {Loadable Function} {@var{v} =} randn (\"state\")\n\
-@deftypefnx {Loadable Function} {} randn (\"state\", @var{v})\n\
-@deftypefnx {Loadable Function} {} randn (\"state\", \"reset\")\n\
-@deftypefnx {Loadable Function} {@var{v} =} randn (\"seed\")\n\
-@deftypefnx {Loadable Function} {} randn (\"seed\", @var{v})\n\
-@deftypefnx {Loadable Function} {} randn (\"seed\", \"reset\")\n\
-@deftypefnx {Loadable Function} {} randn (@dots{}, \"single\")\n\
-@deftypefnx {Loadable Function} {} randn (@dots{}, \"double\")\n\
-Return a matrix with normally distributed random\n\
-elements having zero mean and variance one.  The arguments are\n\
-handled the same as the arguments for @code{rand}.\n\
-\n\
-By default, @code{randn} uses the Marsaglia and Tsang ``Ziggurat technique''\n\
-to transform from a uniform to a normal distribution.\n\
-\n\
-The class of the value returned can be controlled by a trailing \"double\"\n\
-or \"single\" argument.  These are the only valid classes.\n\
-\n\
-Reference: G. Marsaglia and W.W. Tsang,\n\
-@cite{Ziggurat Method for Generating Random Variables},\n\
-J. Statistical Software, vol 5, 2000,\n\
-@url{http://www.jstatsoft.org/v05/i08/})\n\
-\n\
-@seealso{rand, rande, randg, randp}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  retval = do_rand (args, nargin, "randn", "normal");
-
-  return retval;
-}
-
-/*
-%!test
-%! # Test fixed state
-%! randn ("state", 1);
-%! assert (randn (1, 6), [-2.666521678978671 -0.7381719971724564 1.507903992673601 0.6019427189162239 -0.450661261143348 -0.7054431351574116], 1e-6);
-%!test
-%! # Test fixed seed
-%! randn ("seed", 1);
-%! assert (randn (1, 6), [-1.039402365684509 -1.25938892364502 0.1968704611063004 0.3874166905879974 -0.5976632833480835 -0.6615074276924133], 1e-6);
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randn ("state", 12);
-%!   x = randn (100000, 1);
-%!   assert (mean (x), 0, 0.01);
-%!   assert (var (x), 1, 0.02);
-%!   assert (skewness (x), 0, 0.02);
-%!   assert (kurtosis (x), 0, 0.04);
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randn ("seed", 12);
-%!   x = randn (100000, 1);
-%!   assert (mean (x), 0, 0.01);
-%!   assert (var (x), 1, 0.02);
-%!   assert (skewness (x), 0, 0.02);
-%!   assert (kurtosis (x), 0, 0.04);
-%! endif
-*/
-
-DEFUN_DLD (rande, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} rande (@var{n})\n\
-@deftypefnx {Loadable Function} {} rande (@var{n}, @var{m}, @dots{})\n\
-@deftypefnx {Loadable Function} {} rande ([@var{n} @var{m} @dots{}])\n\
-@deftypefnx {Loadable Function} {@var{v} =} rande (\"state\")\n\
-@deftypefnx {Loadable Function} {} rande (\"state\", @var{v})\n\
-@deftypefnx {Loadable Function} {} rande (\"state\", \"reset\")\n\
-@deftypefnx {Loadable Function} {@var{v} =} rande (\"seed\")\n\
-@deftypefnx {Loadable Function} {} rande (\"seed\", @var{v})\n\
-@deftypefnx {Loadable Function} {} rande (\"seed\", \"reset\")\n\
-@deftypefnx {Loadable Function} {} rande (@dots{}, \"single\")\n\
-@deftypefnx {Loadable Function} {} rande (@dots{}, \"double\")\n\
-Return a matrix with exponentially distributed random elements.  The\n\
-arguments are handled the same as the arguments for @code{rand}.\n\
-\n\
-By default, @code{randn} uses the Marsaglia and Tsang ``Ziggurat technique''\n\
-to transform from a uniform to an exponential distribution.\n\
-\n\
-The class of the value returned can be controlled by a trailing \"double\"\n\
-or \"single\" argument.  These are the only valid classes.\n\
-\n\
-Reference: G. Marsaglia and W.W. Tsang,\n\
-@cite{Ziggurat Method for Generating Random Variables},\n\
-J. Statistical Software, vol 5, 2000,\n\
-@url{http://www.jstatsoft.org/v05/i08/})\n\
-\n\
-@seealso{rand, randn, randg, randp}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  retval = do_rand (args, nargin, "rande", "exponential");
-
-  return retval;
-}
-
-/*
-%!test
-%! # Test fixed state
-%! rande ("state", 1);
-%! assert (rande (1, 6), [3.602973885835625 0.1386190677555021 0.6743112889616958 0.4512830847258422 0.7255744741233175 0.3415969205292291], 1e-6);
-%!test
-%! # Test fixed seed
-%! rande ("seed", 1);
-%! assert (rande (1, 6), [0.06492075175653866 1.717980206012726 0.4816154008731246 0.5231300676241517 0.103910739364359 1.668931916356087], 1e-6);
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally
-%!   rande ("state", 1);
-%!   x = rande (100000, 1);
-%!   assert (min (x) > 0);   # *** Please report this!!! ***
-%!   assert (mean (x), 1, 0.01);
-%!   assert (var (x), 1, 0.03);
-%!   assert (skewness (x), 2, 0.06);
-%!   assert (kurtosis (x), 6, 0.7);
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally
-%!   rande ("seed", 1);
-%!   x = rande (100000, 1);
-%!   assert (min (x)>0);   # *** Please report this!!! ***
-%!   assert (mean (x), 1, 0.01);
-%!   assert (var (x), 1, 0.03);
-%!   assert (skewness (x), 2, 0.06);
-%!   assert (kurtosis (x), 6, 0.7);
-%! endif
-*/
-
-DEFUN_DLD (randg, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} randg (@var{n})\n\
-@deftypefnx {Loadable Function} {} randg (@var{n}, @var{m}, @dots{})\n\
-@deftypefnx {Loadable Function} {} randg ([@var{n} @var{m} @dots{}])\n\
-@deftypefnx {Loadable Function} {@var{v} =} randg (\"state\")\n\
-@deftypefnx {Loadable Function} {} randg (\"state\", @var{v})\n\
-@deftypefnx {Loadable Function} {} randg (\"state\", \"reset\")\n\
-@deftypefnx {Loadable Function} {@var{v} =} randg (\"seed\")\n\
-@deftypefnx {Loadable Function} {} randg (\"seed\", @var{v})\n\
-@deftypefnx {Loadable Function} {} randg (\"seed\", \"reset\")\n\
-@deftypefnx {Loadable Function} {} randg (@dots{}, \"single\")\n\
-@deftypefnx {Loadable Function} {} randg (@dots{}, \"double\")\n\
-Return a matrix with @code{gamma (@var{a},1)} distributed random elements.\n\
-The arguments are handled the same as the arguments for @code{rand},\n\
-except for the argument @var{a}.\n\
-\n\
-This can be used to generate many distributions:\n\
-\n\
-@table @asis\n\
-@item @code{gamma (a, b)} for @code{a > -1}, @code{b > 0}\n\
-\n\
-@example\n\
-r = b * randg (a)\n\
-@end example\n\
-\n\
-@item @code{beta (a, b)} for @code{a > -1}, @code{b > -1}\n\
-\n\
-@example\n\
-@group\n\
-r1 = randg (a, 1)\n\
-r = r1 / (r1 + randg (b, 1))\n\
-@end group\n\
-@end example\n\
-\n\
-@item @code{Erlang (a, n)}\n\
-\n\
-@example\n\
-r = a * randg (n)\n\
-@end example\n\
-\n\
-@item @code{chisq (df)} for @code{df > 0}\n\
-\n\
-@example\n\
-r = 2 * randg (df / 2)\n\
-@end example\n\
-\n\
-@item @code{t (df)} for @code{0 < df < inf} (use randn if df is infinite)\n\
-\n\
-@example\n\
-r = randn () / sqrt (2 * randg (df / 2) / df)\n\
-@end example\n\
-\n\
-@item @code{F (n1, n2)} for @code{0 < n1}, @code{0 < n2}\n\
-\n\
-@example\n\
-@group\n\
-## r1 equals 1 if n1 is infinite\n\
-r1 = 2 * randg (n1 / 2) / n1\n\
-## r2 equals 1 if n2 is infinite\n\
-r2 = 2 * randg (n2 / 2) / n2\n\
-r = r1 / r2\n\n\
-@end group\n\
-@end example\n\
-\n\
-@item negative @code{binomial (n, p)} for @code{n > 0}, @code{0 < p <= 1}\n\
-\n\
-@example\n\
-r = randp ((1 - p) / p * randg (n))\n\
-@end example\n\
-\n\
-@item non-central @code{chisq (df, L)}, for @code{df >= 0} and @code{L > 0}\n\
-(use chisq if @code{L = 0})\n\
-\n\
-@example\n\
-@group\n\
-r = randp (L / 2)\n\
-r(r > 0) = 2 * randg (r(r > 0))\n\
-r(df > 0) += 2 * randg (df(df > 0)/2)\n\
-@end group\n\
-@end example\n\
-\n\
-@item @code{Dirichlet (a1, @dots{} ak)}\n\
-\n\
-@example\n\
-@group\n\
-r = (randg (a1), @dots{}, randg (ak))\n\
-r = r / sum (r)\n\
-@end group\n\
-@end example\n\
-\n\
-@end table\n\
-\n\
-The class of the value returned can be controlled by a trailing \"double\"\n\
-or \"single\" argument.  These are the only valid classes.\n\
-@seealso{rand, randn, rande, randp}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 1)
-    error ("randg: insufficient arguments");
-  else
-    retval = do_rand (args, nargin, "randg", "gamma", true);
-
-  return retval;
-}
-
-/*
-%!test
-%! randg ("state", 12)
-%! assert (randg ([-inf, -1, 0, inf, nan]), [nan, nan, nan, nan, nan]); # *** Please report
-
-%!test
-%! # Test fixed state
-%! randg ("state", 1);
-%! assert (randg (0.1, 1, 6), [0.0103951513331241 8.335671459898252e-05 0.00138691397249762 0.000587308416993855 0.495590518784736 2.3921917414795e-12], 1e-6);
-%!test
-%! # Test fixed state
-%! randg ("state", 1);
-%! assert (randg (0.95, 1, 6), [3.099382433255327 0.3974529788871218 0.644367450750855 1.143261091802246 1.964111762696822 0.04011915547957939], 1e-6);
-%!test
-%! # Test fixed state
-%! randg ("state", 1);
-%! assert (randg (1, 1, 6), [0.2273389379645993 1.288822625058359 0.2406335209340746 1.218869553370733 1.024649860162554 0.09631230343599533], 1e-6);
-%!test
-%! # Test fixed state
-%! randg ("state", 1);
-%! assert (randg (10, 1, 6), [3.520369644331133 15.15369864472106 8.332112081991205 8.406211067432674 11.81193475187611 10.88792728177059], 1e-5);
-%!test
-%! # Test fixed state
-%! randg ("state", 1);
-%! assert (randg (100, 1, 6), [75.34570255262264 115.4911985594699 95.23493031356388 95.48926019250911 106.2397448229803 103.4813150404118], 1e-4);
-%!test
-%! # Test fixed seed
-%! randg ("seed", 1);
-%! assert (randg (0.1, 1, 6), [0.07144210487604141 0.460641473531723 0.4749028384685516 0.06823389977216721 0.000293838675133884 1.802567535340305e-12], 1e-6);
-%!test
-%! # Test fixed seed
-%! randg ("seed", 1);
-%! assert (randg (0.95, 1, 6), [1.664905071258545 1.879976987838745 1.905677795410156 0.9948706030845642 0.5606933236122131 0.0766092911362648], 1e-6);
-%!test
-%! # Test fixed seed
-%! randg ("seed", 1);
-%! assert (randg (1, 1, 6), [0.03512085229158401 0.6488978862762451 0.8114678859710693 0.1666885763406754 1.60791552066803 1.90356981754303], 1e-6);
-%!test
-%! # Test fixed seed
-%! randg ("seed", 1);
-%! assert (randg (10, 1, 6), [6.566435813903809 10.11648464202881 10.73162078857422 7.747178077697754 6.278522491455078 6.240195751190186], 1e-5);
-%!test
-%! # Test fixed seed
-%! randg ("seed", 1);
-%! assert (randg (100, 1, 6), [89.40208435058594 101.4734725952148 103.4020004272461 93.62763214111328 88.33104705810547 88.1871337890625], 1e-4);
-
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randg ("state", 12);
-%!   a = 0.1;
-%!   x = randg (a, 100000, 1);
-%!   assert (mean (x),     a,          0.01);
-%!   assert (var (x),      a,          0.01);
-%!   assert (skewness (x), 2/sqrt (a), 1);
-%!   assert (kurtosis (x), 6/a,        50);
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randg ("state", 12);
-%!   a = 0.95;
-%!   x = randg (a, 100000, 1);
-%!   assert (mean (x),     a,          0.01);
-%!   assert (var (x),      a,          0.04);
-%!   assert (skewness (x), 2/sqrt (a), 0.2);
-%!   assert (kurtosis (x), 6/a,        2);
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randg ("state", 12);
-%!   a = 1;
-%!   x = randg (a, 100000, 1);
-%!   assert (mean (x),     a,          0.01);
-%!   assert (var (x),      a,          0.04);
-%!   assert (skewness (x), 2/sqrt (a), 0.2);
-%!   assert (kurtosis (x), 6/a,        2);
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randg ("state", 12);
-%!   a = 10;
-%!   x = randg (a, 100000, 1);
-%!   assert (mean (x),     a,          0.1);
-%!   assert (var (x),      a,          0.5);
-%!   assert (skewness (x), 2/sqrt (a), 0.1);
-%!   assert (kurtosis (x), 6/a,        0.5);
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randg ("state", 12);
-%!   a = 100;
-%!   x = randg (a, 100000, 1);
-%!   assert (mean (x),     a,          0.2);
-%!   assert (var (x),      a,          2);
-%!   assert (skewness (x), 2/sqrt (a), 0.05);
-%!   assert (kurtosis (x), 6/a,        0.2);
-%! endif
-%!test
-%! randg ("seed", 12);
-%!assert (randg ([-inf, -1, 0, inf, nan]), [nan, nan, nan, nan, nan]) # *** Please report
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randg ("seed", 12);
-%!   a = 0.1;
-%!   x = randg (a, 100000, 1);
-%!   assert (mean (x),     a,          0.01);
-%!   assert (var (x),      a,          0.01);
-%!   assert (skewness (x), 2/sqrt (a), 1);
-%!   assert (kurtosis (x), 6/a,        50);
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randg ("seed", 12);
-%!   a = 0.95;
-%!   x = randg (a, 100000, 1);
-%!   assert (mean (x),     a,          0.01);
-%!   assert (var (x),      a,          0.04);
-%!   assert (skewness (x), 2/sqrt (a), 0.2);
-%!   assert (kurtosis (x), 6/a,        2);
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randg ("seed", 12);
-%!   a = 1;
-%!   x = randg (a, 100000, 1);
-%!   assert (mean (x),     a,          0.01);
-%!   assert (var (x),      a,          0.04);
-%!   assert (skewness (x), 2/sqrt (a), 0.2);
-%!   assert (kurtosis (x), 6/a,        2);
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randg ("seed", 12);
-%!   a = 10;
-%!   x = randg (a, 100000, 1);
-%!   assert (mean (x),     a,          0.1);
-%!   assert (var (x),      a,          0.5);
-%!   assert (skewness (x), 2/sqrt (a), 0.1);
-%!   assert (kurtosis (x), 6/a,        0.5);
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randg ("seed", 12);
-%!   a = 100;
-%!   x = randg (a, 100000, 1);
-%!   assert (mean (x),     a,          0.2);
-%!   assert (var (x),      a,          2);
-%!   assert (skewness (x), 2/sqrt (a), 0.05);
-%!   assert (kurtosis (x), 6/a,        0.2);
-%! endif
-*/
-
-DEFUN_DLD (randp, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} randp (@var{l}, @var{n})\n\
-@deftypefnx {Loadable Function} {} randp (@var{l}, @var{n}, @var{m}, @dots{})\n\
-@deftypefnx {Loadable Function} {} randp (@var{l}, [@var{n} @var{m} @dots{}])\n\
-@deftypefnx {Loadable Function} {@var{v} =} randp (\"state\")\n\
-@deftypefnx {Loadable Function} {} randp (\"state\", @var{v})\n\
-@deftypefnx {Loadable Function} {} randp (\"state\", \"reset\")\n\
-@deftypefnx {Loadable Function} {@var{v} =} randp (\"seed\")\n\
-@deftypefnx {Loadable Function} {} randp (\"seed\", @var{v})\n\
-@deftypefnx {Loadable Function} {} randp (\"seed\", \"reset\")\n\
-@deftypefnx {Loadable Function} {} randp (@dots{}, \"single\")\n\
-@deftypefnx {Loadable Function} {} randp (@dots{}, \"double\")\n\
-Return a matrix with Poisson distributed random elements with mean value\n\
-parameter given by the first argument, @var{l}.  The arguments\n\
-are handled the same as the arguments for @code{rand}, except for the\n\
-argument @var{l}.\n\
-\n\
-Five different algorithms are used depending on the range of @var{l}\n\
-and whether or not @var{l} is a scalar or a matrix.\n\
-\n\
-@table @asis\n\
-@item For scalar @var{l} @leq{} 12, use direct method.\n\
-W.H. Press, et al., @cite{Numerical Recipes in C},\n\
-Cambridge University Press, 1992.\n\
-\n\
-@item For scalar @var{l} > 12, use rejection method.[1]\n\
-W.H. Press, et al., @cite{Numerical Recipes in C},\n\
-Cambridge University Press, 1992.\n\
-\n\
-@item For matrix @var{l} @leq{} 10, use inversion method.[2]\n\
-E. Stadlober, et al., WinRand source code, available via FTP.\n\
-\n\
-@item For matrix @var{l} > 10, use patchwork rejection method.\n\
-E. Stadlober, et al., WinRand source code, available via FTP, or\n\
-H. Zechner, @cite{Efficient sampling from continuous and discrete\n\
-unimodal distributions}, Doctoral Dissertation, 156pp., Technical\n\
-University Graz, Austria, 1994.\n\
-\n\
-@item For @var{l} > 1e8, use normal approximation.\n\
-L. Montanet, et al., @cite{Review of Particle Properties}, Physical Review\n\
-D 50 p1284, 1994.\n\
-@end table\n\
-\n\
-The class of the value returned can be controlled by a trailing \"double\"\n\
-or \"single\" argument.  These are the only valid classes.\n\
-@seealso{rand, randn, rande, randg}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 1)
-    error ("randp: insufficient arguments");
-  else
-    retval = do_rand (args, nargin, "randp", "poisson", true);
-
-  return retval;
-}
-
-/*
-%!test
-%! randp ("state", 12);
-%! assert (randp ([-inf, -1, 0, inf, nan]), [nan, nan, 0, nan, nan]);   # *** Please report
-%!test
-%! # Test fixed state
-%! randp ("state", 1);
-%! assert (randp (5, 1, 6), [5 5 3 7 7 3])
-%!test
-%! # Test fixed state
-%! randp ("state", 1);
-%! assert (randp (15, 1, 6), [13 15 8 18 18 15])
-%!test
-%! # Test fixed state
-%! randp ("state", 1);
-%! assert (randp (1e9, 1, 6), [999915677 999976657 1000047684 1000019035 999985749 999977692], -1e-6)
-%!test
-%! # Test fixed state
-%! randp ("seed", 1);
-%! %%assert (randp (5, 1, 6), [8 2 3 6 6 8])
-%! assert (randp (5, 1, 5), [8 2 3 6 6])
-%!test
-%! # Test fixed state
-%! randp ("seed", 1);
-%! assert (randp (15, 1, 6), [15 16 12 10 10 12])
-%!test
-%! # Test fixed state
-%! randp ("seed", 1);
-%! assert (randp (1e9, 1, 6), [1000006208 1000012224 999981120 999963520 999963072 999981440], -1e-6)
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randp ("state", 12);
-%!   for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
-%!     x = randp (a (1), 100000, 1);
-%!     assert (min (x) >= 0);   # *** Please report this!!! ***
-%!     assert (mean (x), a(1), a(2));
-%!     assert (var (x), a(1), 0.02*a(1));
-%!     assert (skewness (x), 1/sqrt (a(1)), a(3));
-%!     assert (kurtosis (x), 1/a(1), 3*a(3));
-%!   endfor
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randp ("state", 12);
-%!   for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
-%!     x = randp (a(1)*ones (100000, 1), 100000, 1);
-%!     assert (min (x) >= 0);   # *** Please report this!!! ***
-%!     assert (mean (x), a(1), a(2));
-%!     assert (var (x), a(1), 0.02*a(1));
-%!     assert (skewness (x), 1/sqrt (a(1)), a(3));
-%!     assert (kurtosis (x), 1/a(1), 3*a(3));
-%!   endfor
-%! endif
-%!test
-%! randp ("seed", 12);
-%! assert (randp ([-inf, -1, 0, inf, nan]), [nan, nan, 0, nan, nan]);   # *** Please report
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randp ("seed", 12);
-%!   for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
-%!     x = randp (a(1), 100000, 1);
-%!     assert (min (x) >= 0);   # *** Please report this!!! ***
-%!     assert (mean (x), a(1), a(2));
-%!     assert (var (x), a(1), 0.02*a(1));
-%!     assert (skewness (x), 1/sqrt (a(1)), a(3));
-%!     assert (kurtosis (x), 1/a(1), 3*a(3));
-%!   endfor
-%! endif
-%!test
-%! if (__random_statistical_tests__)
-%!   # statistical tests may fail occasionally.
-%!   randp ("seed", 12);
-%!   for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
-%!     x = randp (a(1)*ones (100000, 1), 100000, 1);
-%!     assert (min (x) >= 0);   # *** Please report this!!! ***
-%!     assert (mean (x), a(1), a(2));
-%!     assert (var (x), a(1), 0.02*a(1));
-%!     assert (skewness (x), 1/sqrt (a(1)), a(3));
-%!     assert (kurtosis (x), 1/a(1), 3*a(3));
-%!   endfor
-%! endif
-*/
-
-DEFUN_DLD (randperm, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} randperm (@var{n})\n\
-@deftypefnx {Loadable Function} {} randperm (@var{n}, @var{m})\n\
-Return a row vector containing a random permutation of @code{1:@var{n}}.\n\
-If @var{m} is supplied, return @var{m} unique entries, sampled without\n\
-replacement from @code{1:@var{n}}.  The complexity is O(@var{n}) in\n\
-memory and O(@var{m}) in time, unless @var{m} < @var{n}/5, in which case\n\
-O(@var{m}) memory is used as well.  The randomization is performed using\n\
-rand().  All permutations are equally likely.\n\
-@seealso{perms}\n\
-@end deftypefn")
-{
-
-#ifdef USE_UNORDERED_MAP_WITH_TR1
-using std::tr1::unordered_map;
-#else
-using std::unordered_map;
-#endif
-
-  int nargin = args.length ();
-  octave_value retval;
-
-  if (nargin == 1 || nargin == 2)
-    {
-      octave_idx_type n, m;
-
-      n = args(0).idx_type_value (true);
-
-      if (nargin == 2)
-        m = args(1).idx_type_value (true);
-      else
-        m = n;
-
-      if (m < 0 || n < 0)
-        error ("randperm: M and N must be non-negative");
-
-      if (m > n)
-        error ("randperm: M must be less than or equal to N");
-
-      // Quick and dirty heuristic to decide if we allocate or not the
-      // whole vector for tracking the truncated shuffle.
-      bool short_shuffle = m < n/5 && m < 1e5;
-
-      if (! error_state)
-        {
-          // Generate random numbers.
-          NDArray r = octave_rand::nd_array (dim_vector (1, m));
-          double *rvec = r.fortran_vec ();
-
-          octave_idx_type idx_len = short_shuffle ? m : n;
-          Array<octave_idx_type> idx (dim_vector (1, idx_len));
-          octave_idx_type *ivec = idx.fortran_vec ();
-
-          for (octave_idx_type i = 0; i < idx_len; i++)
-            ivec[i] = i;
-
-          if (short_shuffle)
-            {
-              unordered_map<octave_idx_type, octave_idx_type> map (m);
-
-              // Perform the Knuth shuffle only keeping track of moved
-              // entries in the map
-              for (octave_idx_type i = 0; i < m; i++)
-                {
-                  octave_idx_type k = i +
-                    gnulib::floor (rvec[i] * (n - i));
-
-                  //For shuffling first m entries, no need to use extra
-                  //storage
-                  if (k < m)
-                    {
-                      std::swap (ivec[i], ivec[k]);
-                    }
-                  else
-                    {
-                      if (map.find (k) == map.end ())
-                        map[k] = k;
-
-                      std::swap (ivec[i], map[k]);
-                    }
-                }
-            }
-          else
-            {
-
-              // Perform the Knuth shuffle of the first m entries
-              for (octave_idx_type i = 0; i < m; i++)
-                {
-                  octave_idx_type k = i +
-                    gnulib::floor (rvec[i] * (n - i));
-                  std::swap (ivec[i], ivec[k]);
-                }
-            }
-
-          // Convert to doubles, reusing r.
-          for (octave_idx_type i = 0; i < m; i++)
-            rvec[i] = ivec[i] + 1;
-
-          if (m < n)
-            idx.resize (dim_vector (1, m));
-
-          // Now create an array object with a cached idx_vector.
-          retval = new octave_matrix (r, idx_vector (idx));
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!assert (sort (randperm (20)), 1:20)
-%!assert (length (randperm (20,10)), 10)
-
-%!test
-%! rand ("seed", 0);
-%! for i = 1:100
-%!   p = randperm (305, 30);
-%!   assert (length (unique (p)), 30);
-%! endfor
-*/
--- a/src/DLD-FUNCTIONS/rcond.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +0,0 @@
-/*
-
-Copyright (C) 2008-2012 David Bateman
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-DEFUN_DLD (rcond, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{c} =} rcond (@var{A})\n\
-Compute the 1-norm estimate of the reciprocal condition number as returned\n\
-by @sc{lapack}.  If the matrix is well-conditioned then @var{c} will be near\n\
-1 and if the matrix is poorly conditioned it will be close to zero.\n\
-\n\
-The matrix @var{A} must not be sparse.  If the matrix is sparse then\n\
-@code{condest (@var{A})} or @code{rcond (full (@var{A}))} should be used\n\
-instead.\n\
-@seealso{cond, condest}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin != 1)
-    print_usage ();
-  else if (args(0).is_sparse_type ())
-    error ("rcond: for sparse matrices use 'rcond (full (a))' or 'condest (a)' instead");
-  else if (args(0).is_single_type ())
-    {
-      if (args(0).is_complex_type ())
-        {
-          FloatComplexMatrix m = args(0).float_complex_matrix_value ();
-          MatrixType mattyp;
-          retval = m.rcond (mattyp);
-          args(0).matrix_type (mattyp);
-        }
-      else
-        {
-          FloatMatrix m = args(0).float_matrix_value ();
-          MatrixType mattyp;
-          retval = m.rcond (mattyp);
-          args(0).matrix_type (mattyp);
-        }
-    }
-  else if (args(0).is_complex_type ())
-    {
-      ComplexMatrix m = args(0).complex_matrix_value ();
-      MatrixType mattyp;
-      retval = m.rcond (mattyp);
-      args(0).matrix_type (mattyp);
-    }
-  else
-    {
-      Matrix m = args(0).matrix_value ();
-      MatrixType mattyp;
-      retval = m.rcond (mattyp);
-      args(0).matrix_type (mattyp);
-    }
-
-  return retval;
-}
-
-/*
-%!assert (rcond (eye (2)), 1)
-%!assert (rcond (ones (2)), 0)
-%!assert (rcond ([1 1; 2 1]), 1/9)
-%!assert (rcond (magic (4)), 0, eps)
-*/
--- a/src/DLD-FUNCTIONS/regexp.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1408 +0,0 @@
-/*
-
-Copyright (C) 2005-2012 David Bateman
-Copyright (C) 2002-2005 Paul Kienzle
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <list>
-#include <sstream>
-
-#include <pcre.h>
-
-#include "base-list.h"
-#include "oct-locbuf.h"
-#include "quit.h"
-#include "regexp.h"
-#include "str-vec.h"
-
-#include "defun-dld.h"
-#include "Cell.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-map.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-// Replace backslash escapes in a string with the real values.  We need
-// this special function instead of the one in utils.cc because the set
-// of escape sequences used in regexps is different from those used in
-// the *printf functions.
-
-static std::string
-do_regexp_string_escapes (const std::string& s)
-{
-  std::string retval;
-
-  size_t i = 0;
-  size_t j = 0;
-  size_t len = s.length ();
-
-  retval.resize (len);
-
-  while (j < len)
-    {
-      if (s[j] == '\\' && j+1 < len)
-        {
-          switch (s[++j])
-            {
-            case '$':
-              retval[i] = '$';
-              break;
-
-            case 'a':
-              retval[i] = '\a';
-              break;
-
-            case 'b': // backspace
-              retval[i] = '\b';
-              break;
-
-            case 'f': // formfeed
-              retval[i] = '\f';
-              break;
-
-            case 'n': // newline
-              retval[i] = '\n';
-              break;
-
-            case 'r': // carriage return
-              retval[i] = '\r';
-              break;
-
-            case 't': // horizontal tab
-              retval[i] = '\t';
-              break;
-
-            case 'v': // vertical tab
-              retval[i] = '\v';
-              break;
-
-            case '\\': // backslash
-              retval[i] = '\\';
-              break;
-
-#if 0
-// FIXME -- to be complete, we need to handle \oN, \o{N}, \xN, and
-// \x{N}.  Hex digits may be upper or lower case.  Brackets are
-// optional, so \x5Bz is the same as \x{5B}z.
-
-            case 'o': // octal number
-            case 'x': // hex number
-#endif
-
-            default:
-              retval[i] = '\\';
-              retval[++i] = s[j];
-              break;
-            }
-        }
-      else
-        {
-          retval[i] = s[j];
-        }
-
-      i++;
-      j++;
-    }
-
-  retval.resize (i);
-
-  return retval;
-}
-
-static void
-parse_options (regexp::opts& options, const octave_value_list& args,
-               const std::string& who, int skip, bool& extra_args)
-{
-  int nargin = args.length ();
-
-  extra_args = false;
-
-  for (int i = skip; i < nargin; i++)
-    {
-      std::string str = args(i).string_value ();
-
-      if (error_state)
-        {
-          error ("%s: optional arguments must be character strings",
-                 who.c_str ());
-          break;
-        }
-
-      std::transform (str.begin (), str.end (), str.begin (), tolower);
-
-      if (str.find ("once", 0) == 0)
-        options.once (true);
-      else if (str.find ("matchcase", 0) == 0)
-        options.case_insensitive (false);
-      else if (str.find ("ignorecase", 0) == 0)
-        options.case_insensitive (true);
-      else if (str.find ("dotall", 0) == 0)
-        options.dotexceptnewline (false);
-      else if (str.find ("stringanchors", 0) == 0)
-        options.lineanchors (false);
-      else if (str.find ("literalspacing", 0) == 0)
-        options.freespacing (false);
-      else if (str.find ("noemptymatch", 0) == 0)
-        options.emptymatch (false);
-      else if (str.find ("dotexceptnewline", 0) == 0)
-        options.dotexceptnewline (true);
-      else if (str.find ("lineanchors", 0) == 0)
-        options.lineanchors (true);
-      else if (str.find ("freespacing", 0) == 0)
-        options.freespacing (true);
-      else if (str.find ("emptymatch", 0) == 0)
-        options.emptymatch (true);
-      else if (str.find ("start", 0) == 0
-               || str.find ("end", 0) == 0
-               || str.find ("tokenextents", 0) == 0
-               || str.find ("match", 0) == 0
-               || str.find ("tokens", 0) == 0
-               || str.find ("names", 0) == 0
-               || str.find ("split", 0) == 0)
-        extra_args = true;
-      else
-        error ("%s: unrecognized option", who.c_str ());
-    }
-}
-
-static octave_value_list
-octregexp (const octave_value_list &args, int nargout,
-           const std::string &who, bool case_insensitive = false)
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  // Make sure we have string, pattern
-  const std::string buffer = args(0).string_value ();
-  if (error_state)
-    return retval;
-
-  std::string pattern = args(1).string_value ();
-  if (error_state)
-    return retval;
-  // Matlab compatibility.
-  if (args(1).is_sq_string ())
-    pattern = do_regexp_string_escapes (pattern);
-
-  regexp::opts options;
-  options.case_insensitive (case_insensitive);
-  bool extra_options = false;
-  parse_options (options, args, who, 2, extra_options);
-  if (error_state)
-    return retval;
-
-  regexp::match_data rx_lst = regexp_match (pattern, buffer, options, who);
-
-  string_vector named_pats = rx_lst.named_patterns ();
-
-  size_t sz = rx_lst.size ();
-
-  if (! error_state)
-    {
-      // Converted the linked list in the correct form for the return values
-
-      octave_idx_type i = 0;
-      octave_scalar_map nmap;
-
-      retval.resize (7);
-
-      if (sz == 1)
-        {
-          string_vector named_tokens = rx_lst.begin ()->named_tokens ();
-
-          for (int j = 0; j < named_pats.length (); j++)
-            nmap.assign (named_pats(j), named_tokens(j));
-
-          retval(5) = nmap;
-        }
-      else
-        {
-          for (int j = 0; j < named_pats.length (); j++)
-            {
-              Cell tmp (dim_vector (1, sz));
-
-              i = 0;
-              for (regexp::match_data::const_iterator p = rx_lst.begin ();
-                   p != rx_lst.end (); p++)
-                {
-                  string_vector named_tokens = p->named_tokens ();
-
-                  tmp(i++) = named_tokens(j);
-                }
-
-              nmap.assign (named_pats(j), octave_value (tmp));
-            }
-
-          retval(5) = nmap;
-        }
-
-      if (options.once ())
-        {
-          regexp::match_data::const_iterator p = rx_lst.begin ();
-
-          retval(4) = sz ? p->tokens () : Cell ();
-          retval(3) = sz ? p->match_string () : std::string ();
-          retval(2) = sz ? p->token_extents () : Matrix ();
-
-          if (sz)
-            {
-              double start = p->start ();
-              double end = p->end ();
-
-              Cell split (dim_vector (1, 2));
-              split(0) = buffer.substr (0, start-1);
-              split(1) = buffer.substr (end);
-
-              retval(6) = split;
-              retval(1) = end;
-              retval(0) = start;
-            }
-          else
-            {
-              retval(6) = buffer;
-              retval(1) = Matrix ();
-              retval(0) = Matrix ();
-            }
-        }
-      else
-        {
-          Cell tokens (dim_vector (1, sz));
-          Cell match_string (dim_vector (1, sz));
-          Cell token_extents (dim_vector (1, sz));
-          NDArray end (dim_vector (1, sz));
-          NDArray start (dim_vector (1, sz));
-          Cell split (dim_vector (1, sz+1));
-          size_t sp_start = 0;
-
-          i = 0;
-          for (regexp::match_data::const_iterator p = rx_lst.begin ();
-               p != rx_lst.end (); p++)
-            {
-              double s = p->start ();
-              double e = p->end ();
-
-              string_vector tmp = p->tokens ();
-              tokens(i) = Cell (dim_vector (1, tmp.length ()), tmp);
-              match_string(i) = p->match_string ();
-              token_extents(i) = p->token_extents ();
-              end(i) = e;
-              start(i) = s;
-              split(i) = buffer.substr (sp_start, s-sp_start-1);
-              sp_start = e;
-              i++;
-            }
-
-          split(i) = buffer.substr (sp_start);
-
-          retval(6) = split;
-          retval(4) = tokens;
-          retval(3) = match_string;
-          retval(2) = token_extents;
-          retval(1) = end;
-          retval(0) = start;
-        }
-
-      // Alter the order of the output arguments
-
-      if (extra_options)
-        {
-          int n = 0;
-          octave_value_list new_retval;
-          new_retval.resize (nargout);
-
-          OCTAVE_LOCAL_BUFFER (int, arg_used, 6);
-          for (int j = 0; j < 6; j++)
-            arg_used[j] = false;
-
-          for (int j = 2; j < nargin; j++)
-            {
-              int k = 0;
-              std::string str = args(j).string_value ();
-              std::transform (str.begin (), str.end (), str.begin (), tolower);
-
-              if (str.find ("once", 0) == 0
-                  || str.find ("stringanchors", 0) == 0
-                  || str.find ("lineanchors", 0) == 0
-                  || str.find ("matchcase", 0) == 0
-                  || str.find ("ignorecase", 0) == 0
-                  || str.find ("dotall", 0) == 0
-                  || str.find ("dotexceptnewline", 0) == 0
-                  || str.find ("literalspacing", 0) == 0
-                  || str.find ("freespacing", 0) == 0
-                  || str.find ("noemptymatch", 0) == 0
-                  || str.find ("emptymatch", 0) == 0)
-                continue;
-              else if (str.find ("start", 0) == 0)
-                k = 0;
-              else if (str.find ("end", 0) == 0)
-                k = 1;
-              else if (str.find ("tokenextents", 0) == 0)
-                k = 2;
-              else if (str.find ("match", 0) == 0)
-                k = 3;
-              else if (str.find ("tokens", 0) == 0)
-                k = 4;
-              else if (str.find ("names", 0) == 0)
-                k = 5;
-              else if (str.find ("split", 0) == 0)
-                k = 6;
-
-              new_retval(n++) = retval(k);
-              arg_used[k] = true;
-
-              if (n == nargout)
-                break;
-            }
-
-          // Fill in the rest of the arguments
-          if (n < nargout)
-            {
-              for (int j = 0; j < 6; j++)
-                {
-                  if (! arg_used[j])
-                    new_retval(n++) = retval(j);
-                }
-            }
-
-          retval = new_retval;
-        }
-    }
-
-  return retval;
-}
-
-static octave_value_list
-octcellregexp (const octave_value_list &args, int nargout,
-               const std::string &who, bool case_insensitive = false)
-{
-  octave_value_list retval;
-
-  if (args(0).is_cell ())
-    {
-      OCTAVE_LOCAL_BUFFER (Cell, newretval, nargout);
-      octave_value_list new_args = args;
-      Cell cellstr = args(0).cell_value ();
-      if (args(1).is_cell ())
-        {
-          Cell cellpat = args(1).cell_value ();
-
-          if (cellpat.numel () == 1)
-            {
-              for (int j = 0; j < nargout; j++)
-                newretval[j].resize (cellstr.dims ());
-
-              new_args(1) = cellpat(0);
-
-              for (octave_idx_type i = 0; i < cellstr.numel (); i++)
-                {
-                  new_args(0) = cellstr(i);
-                  octave_value_list tmp = octregexp (new_args, nargout, who,
-                                                     case_insensitive);
-
-                  if (error_state)
-                    break;
-
-                  for (int j = 0; j < nargout; j++)
-                    newretval[j](i) = tmp(j);
-                }
-            }
-          else if (cellstr.numel () == 1)
-            {
-              for (int j = 0; j < nargout; j++)
-                newretval[j].resize (cellpat.dims ());
-
-              new_args(0) = cellstr(0);
-
-              for (octave_idx_type i = 0; i < cellpat.numel (); i++)
-                {
-                  new_args(1) = cellpat(i);
-                  octave_value_list tmp = octregexp (new_args, nargout, who,
-                                                     case_insensitive);
-
-                  if (error_state)
-                    break;
-
-                  for (int j = 0; j < nargout; j++)
-                    newretval[j](i) = tmp(j);
-                }
-            }
-          else if (cellstr.numel () == cellpat.numel ())
-            {
-
-              if (cellstr.dims () != cellpat.dims ())
-                error ("%s: inconsistent cell array dimensions", who.c_str ());
-              else
-                {
-                  for (int j = 0; j < nargout; j++)
-                    newretval[j].resize (cellstr.dims ());
-
-                  for (octave_idx_type i = 0; i < cellstr.numel (); i++)
-                    {
-                      new_args(0) = cellstr(i);
-                      new_args(1) = cellpat(i);
-
-                      octave_value_list tmp = octregexp (new_args, nargout, who,
-                                                         case_insensitive);
-
-                      if (error_state)
-                        break;
-
-                      for (int j = 0; j < nargout; j++)
-                        newretval[j](i) = tmp(j);
-                    }
-                }
-            }
-          else
-            error ("regexp: cell array arguments must be scalar or equal size");
-        }
-      else
-        {
-          for (int j = 0; j < nargout; j++)
-            newretval[j].resize (cellstr.dims ());
-
-          for (octave_idx_type i = 0; i < cellstr.numel (); i++)
-            {
-              new_args(0) = cellstr(i);
-              octave_value_list tmp = octregexp (new_args, nargout, who,
-                                                 case_insensitive);
-
-              if (error_state)
-                break;
-
-              for (int j = 0; j < nargout; j++)
-                newretval[j](i) = tmp(j);
-            }
-        }
-
-      if (!error_state)
-        for (int j = 0; j < nargout; j++)
-          retval(j) = octave_value (newretval[j]);
-    }
-  else if (args(1).is_cell ())
-    {
-      OCTAVE_LOCAL_BUFFER (Cell, newretval, nargout);
-      octave_value_list new_args = args;
-      Cell cellpat = args(1).cell_value ();
-
-      for (int j = 0; j < nargout; j++)
-        newretval[j].resize (cellpat.dims ());
-
-      for (octave_idx_type i = 0; i < cellpat.numel (); i++)
-        {
-          new_args(1) = cellpat(i);
-          octave_value_list tmp = octregexp (new_args, nargout, who,
-                                             case_insensitive);
-
-          if (error_state)
-            break;
-
-          for (int j = 0; j < nargout; j++)
-            newretval[j](i) = tmp(j);
-        }
-
-      if (!error_state)
-        {
-          for (int j = 0; j < nargout; j++)
-            retval(j) = octave_value (newretval[j]);
-        }
-    }
-  else
-    retval = octregexp (args, nargout, who, case_insensitive);
-
-  return retval;
-
-}
-
-DEFUN_DLD (regexp, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexp (@var{str}, @var{pat})\n\
-@deftypefnx {Loadable Function} {[@dots{}] =} regexp (@var{str}, @var{pat}, \"@var{opt1}\", @dots{})\n\
-Regular expression string matching.  Search for @var{pat} in @var{str} and\n\
-return the positions and substrings of any matches, or empty values if there\n\
-are none.\n\
-\n\
-The matched pattern @var{pat} can include any of the standard regex\n\
-operators, including:\n\
-\n\
-@table @code\n\
-@item .\n\
-Match any character\n\
-\n\
-@item * + ? @{@}\n\
-Repetition operators, representing\n\
-\n\
-@table @code\n\
-@item *\n\
-Match zero or more times\n\
-\n\
-@item +\n\
-Match one or more times\n\
-\n\
-@item ?\n\
-Match zero or one times\n\
-\n\
-@item @{@var{n}@}\n\
-Match exactly @var{n} times\n\
-\n\
-@item @{@var{n},@}\n\
-Match @var{n} or more times\n\
-\n\
-@item @{@var{m},@var{n}@}\n\
-Match between @var{m} and @var{n} times\n\
-@end table\n\
-\n\
-@item [@dots{}] [^@dots{}]\n\
-\n\
-List operators.  The pattern will match any character listed between \"[\"\n\
-and \"]\".  If the first character is \"^\" then the pattern is inverted and\n\
-any character except those listed between brackets will match.\n\
-\n\
-Escape sequences defined below can also be used inside list\n\
-operators.  For example, a template for a floating point number might be\n\
-@code{[-+.\\d]+}.\n\
-\n\
-@item () (?:)\n\
-Grouping operator.  The first form, parentheses only, also creates a token.\n\
-\n\
-@item |\n\
-Alternation operator.  Match one of a choice of regular expressions.  The\n\
-alternatives must be delimited by the grouping operator @code{()} above.\n\
-\n\
-@item ^ $\n\
-Anchoring operators.  Requires pattern to occur at the start (@code{^}) or\n\
-end (@code{$}) of the string.\n\
-@end table\n\
-\n\
-In addition, the following escaped characters have special meaning.  Note,\n\
-it is recommended to quote @var{pat} in single quotes, rather than double\n\
-quotes, to avoid the escape sequences being interpreted by Octave before\n\
-being passed to @code{regexp}.\n\
-\n\
-@table @code\n\
-@item \\b\n\
-Match a word boundary\n\
-\n\
-@item \\B\n\
-Match within a word\n\
-\n\
-@item \\w\n\
-Match any word character\n\
-\n\
-@item \\W\n\
-Match any non-word character\n\
-\n\
-@item \\<\n\
-Match the beginning of a word\n\
-\n\
-@item \\>\n\
-Match the end of a word\n\
-\n\
-@item \\s\n\
-Match any whitespace character\n\
-\n\
-@item \\S\n\
-Match any non-whitespace character\n\
-\n\
-@item \\d\n\
-Match any digit\n\
-\n\
-@item \\D\n\
-Match any non-digit\n\
-@end table\n\
-\n\
-The outputs of @code{regexp} default to the order given below\n\
-\n\
-@table @var\n\
-@item s\n\
-The start indices of each matching substring\n\
-\n\
-@item e\n\
-The end indices of each matching substring\n\
-\n\
-@item te\n\
-The extents of each matched token surrounded by @code{(@dots{})} in\n\
-@var{pat}\n\
-\n\
-@item m\n\
-A cell array of the text of each match\n\
-\n\
-@item t\n\
-A cell array of the text of each token matched\n\
-\n\
-@item nm\n\
-A structure containing the text of each matched named token, with the name\n\
-being used as the fieldname.  A named token is denoted by\n\
-@code{(?<name>@dots{})}.\n\
-\n\
-@item sp\n\
-A cell array of the text not returned by match, i.e., what remains if you\n\
-split the string based on @var{pat}.\n\
-@end table\n\
-\n\
-Particular output arguments, or the order of the output arguments, can be\n\
-selected by additional @var{opt} arguments.  These are strings and the\n\
-correspondence between the output arguments and the optional argument\n\
-are\n\
-\n\
-@multitable @columnfractions 0.2 0.3 0.3 0.2\n\
-@item @tab 'start'        @tab @var{s}  @tab\n\
-@item @tab 'end'          @tab @var{e}  @tab\n\
-@item @tab 'tokenExtents' @tab @var{te} @tab\n\
-@item @tab 'match'        @tab @var{m}  @tab\n\
-@item @tab 'tokens'       @tab @var{t}  @tab\n\
-@item @tab 'names'        @tab @var{nm} @tab\n\
-@item @tab 'split'        @tab @var{sp} @tab\n\
-@end multitable\n\
-\n\
-Additional arguments are summarized below.\n\
-\n\
-@table @samp\n\
-@item once\n\
-Return only the first occurrence of the pattern.\n\
-\n\
-@item matchcase\n\
-Make the matching case sensitive.  (default)\n\
-\n\
-Alternatively, use (?-i) in the pattern.\n\
-\n\
-@item ignorecase\n\
-Ignore case when matching the pattern to the string.\n\
-\n\
-Alternatively, use (?i) in the pattern.\n\
-\n\
-@item stringanchors\n\
-Match the anchor characters at the beginning and end of the string.\n\
-(default)\n\
-\n\
-Alternatively, use (?-m) in the pattern.\n\
-\n\
-@item lineanchors\n\
-Match the anchor characters at the beginning and end of the line.\n\
-\n\
-Alternatively, use (?m) in the pattern.\n\
-\n\
-@item dotall\n\
-The pattern @code{.} matches all characters including the newline character.\n\
- (default)\n\
-\n\
-Alternatively, use (?s) in the pattern.\n\
-\n\
-@item dotexceptnewline\n\
-The pattern @code{.} matches all characters except the newline character.\n\
-\n\
-Alternatively, use (?-s) in the pattern.\n\
-\n\
-@item literalspacing\n\
-All characters in the pattern, including whitespace, are significant and are\n\
-used in pattern matching.  (default)\n\
-\n\
-Alternatively, use (?-x) in the pattern.\n\
-\n\
-@item freespacing\n\
-The pattern may include arbitrary whitespace and also comments beginning with\n\
-the character @samp{#}.\n\
-\n\
-Alternatively, use (?x) in the pattern.\n\
-\n\
-@item noemptymatch\n\
-Zero-length matches are not returned.  (default)\n\
-\n\
-@item emptymatch\n\
-Return zero-length matches.\n\
-\n\
-@code{regexp ('a', 'b*', 'emptymatch'} returns @code{[1 2]} because there are\n\
-zero or more 'b' characters at positions 1 and end-of-string.\n\
-\n\
-@end table\n\
-@seealso{regexpi, strfind, regexprep}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 2)
-    print_usage ();
-  else if (args(0).is_cell () || args(1).is_cell ())
-    retval = octcellregexp (args, (nargout > 0 ? nargout : 1), "regexp");
-  else
-    retval = octregexp (args, nargout, "regexp");
-
-  return retval;
-}
-
-/*
-## PCRE_ERROR_MATCHLIMIT test
-%!test
-%! s = sprintf ('\t4\n0000\t-0.00\t-0.0000\t4\t-0.00\t-0.0000\t4\n0000\t-0.00\t-0.0000\t0\t-0.00\t-');
-%! ws = warning ("query");
-%! unwind_protect
-%!   warning ("off");
-%!   regexp (s, '(\s*-*\d+[.]*\d*\s*)+\n');
-%! unwind_protect_cleanup
-%!   warning (ws);
-%! end_unwind_protect
-
-## segfault test
-%!assert (regexp ("abcde", "."), [1,2,3,4,5])
-## Infinite loop test
-%!assert (isempty (regexp ("abcde", "")))
-
-## Check that anchoring of pattern works correctly
-%!assert (regexp ('abcabc', '^abc'), 1)
-%!assert (regexp ('abcabc', 'abc$'), 4)
-%!assert (regexp ('abcabc', '^abc$'), zeros (1,0))
-
-%!test
-%! [s, e, te, m, t] = regexp (' No Match ', 'f(.*)uck');
-%! assert (s, zeros (1,0));
-%! assert (e, zeros (1,0));
-%! assert (te, cell (1,0));
-%! assert (m, cell (1,0));
-%! assert (t, cell (1,0));
-
-%!test
-%! [s, e, te, m, t] = regexp (' FiRetrUck ', 'f(.*)uck');
-%! assert (s, zeros (1,0));
-%! assert (e, zeros (1,0));
-%! assert (te, cell (1,0));
-%! assert (m, cell (1,0));
-%! assert (t, cell (1,0));
-
-%!test
-%! [s, e, te, m, t] = regexp (' firetruck ', 'f(.*)uck');
-%! assert (s, 2);
-%! assert (e, 10);
-%! assert (te{1}, [3, 7]);
-%! assert (m{1}, 'firetruck');
-%! assert (t{1}{1}, 'iretr');
-
-%!test
-%! [s, e, te, m, t] = regexp ('short test string', '\w*r\w*');
-%! assert (s, [1, 12]);
-%! assert (e, [5, 17]);
-%! assert (size (te), [1, 2]);
-%! assert (isempty (te{1}));
-%! assert (isempty (te{2}));
-%! assert (m{1}, 'short');
-%! assert (m{2}, 'string');
-%! assert (size (t), [1, 2]);
-%! assert (isempty (t{1}));
-%! assert (isempty (t{2}));
-
-%!test
-%! [s, e, te, m, t] = regexp ('short test string', '\w*r\w*', 'once');
-%! assert (s, 1);
-%! assert (e, 5);
-%! assert (isempty (te));
-%! assert (m, 'short');
-%! assert (isempty (t));
-
-%!test
-%! [m, te, e, s, t] = regexp ('short test string', '\w*r\w*', 'once', 'match', 'tokenExtents', 'end', 'start', 'tokens');
-%! assert (s, 1);
-%! assert (e, 5);
-%! assert (isempty (te));
-%! assert (m, 'short');
-%! assert (isempty (t));
-
-%!test
-%! [s, e, te, m, t, nm] = regexp ('short test string', '(?<word1>\w*t)\s*(?<word2>\w*t)');
-%! assert (s, 1);
-%! assert (e, 10);
-%! assert (size (te), [1, 1]);
-%! assert (te{1}, [1,5; 7,10]);
-%! assert (m{1}, 'short test');
-%! assert (size (t), [1, 1]);
-%! assert (t{1}{1}, 'short');
-%! assert (t{1}{2}, 'test');
-%! assert (size (nm), [1, 1]);
-%! assert (! isempty (fieldnames (nm)));
-%! assert (sort (fieldnames (nm)), {'word1';'word2'});
-%! assert (nm.word1, 'short');
-%! assert (nm.word2, 'test');
-
-%!test
-%! [nm, m, te, e, s, t] = regexp ('short test string', '(?<word1>\w*t)\s*(?<word2>\w*t)', 'names', 'match', 'tokenExtents', 'end', 'start', 'tokens');
-%! assert (s, 1);
-%! assert (e, 10);
-%! assert (size (te), [1, 1]);
-%! assert (te{1}, [1,5; 7,10]);
-%! assert (m{1}, 'short test');
-%! assert (size (t), [1, 1]);
-%! assert (t{1}{1}, 'short');
-%! assert (t{1}{2}, 'test');
-%! assert (size (nm), [1, 1]);
-%! assert (!isempty (fieldnames (nm)));
-%! assert (sort (fieldnames (nm)), {'word1';'word2'});
-%! assert (nm.word1, 'short');
-%! assert (nm.word2, 'test');
-
-%!test
-%! [t, nm] = regexp ("John Davis\nRogers, James", '(?<first>\w+)\s+(?<last>\w+)|(?<last>\w+),\s+(?<first>\w+)', 'tokens', 'names');
-%! assert (size (t), [1, 2]);
-%! assert (t{1}{1}, 'John');
-%! assert (t{1}{2}, 'Davis');
-%! assert (t{2}{1}, 'Rogers');
-%! assert (t{2}{2}, 'James');
-%! assert (size (nm), [1, 1]);
-%! assert (nm.first{1}, 'John');
-%! assert (nm.first{2}, 'James');
-%! assert (nm.last{1}, 'Davis');
-%! assert (nm.last{2}, 'Rogers');
-
-## Tests for named tokens
-%!test
-%! # Parenthesis in named token (ie (int)) causes a problem
-%! assert (regexp ('qwe int asd', ['(?<typestr>(int))'], 'names'), struct ('typestr', 'int'));
-
-%!test
-%! ## Mix of named and unnamed tokens can cause segfault (bug #35683)
-%! str = "abcde";
-%! ptn = '(?<T1>a)(\w+)(?<T2>d\w+)';
-%! tokens = regexp (str, ptn, "names");
-%! assert (isstruct (tokens) && numel (tokens) == 1);
-%! assert (tokens.T1, "a");
-%! assert (tokens.T2, "de");
-
-%!assert (regexp ("abc\nabc", '.'), [1:7])
-%!assert (regexp ("abc\nabc", '.', 'dotall'), [1:7])
-%!test
-%! assert (regexp ("abc\nabc", '(?s).'), [1:7]);
-%! assert (regexp ("abc\nabc", '.', 'dotexceptnewline'), [1,2,3,5,6,7]);
-%! assert (regexp ("abc\nabc", '(?-s).'), [1,2,3,5,6,7]);
-
-%!assert (regexp ("caseCaSe", 'case'), 1)
-%!assert (regexp ("caseCaSe", 'case', "matchcase"), 1)
-%!assert (regexp ("caseCaSe", 'case', "ignorecase"), [1,5])
-%!test
-%! assert (regexp ("caseCaSe", '(?-i)case'), 1);
-%! assert (regexp ("caseCaSe", '(?i)case'), [1, 5]);
-
-%!assert (regexp ("abc\nabc", 'c$'), 7)
-%!assert (regexp ("abc\nabc", 'c$', "stringanchors"), 7)
-%!test
-%! assert (regexp ("abc\nabc", '(?-m)c$'), 7);
-%! assert (regexp ("abc\nabc", 'c$',"lineanchors"), [3, 7]);
-%! assert (regexp ("abc\nabc", '(?m)c$'), [3,7]);
-
-%!assert (regexp ("this word", 's w'), 4)
-%!assert (regexp ("this word", 's w', 'literalspacing'), 4)
-%!test
-%! assert (regexp ("this word", '(?-x)s w', 'literalspacing'), 4);
-%! assert (regexp ("this word", 's w', 'freespacing'), zeros (1,0));
-%! assert (regexp ("this word", '(?x)s w'), zeros (1,0));
-
-%!test
-%! [s, e, te, m, t, nm, sp] = regexp ('OCTAVE', '[VOCT]*', 'noemptymatch');
-%! assert (s, [1 5]);
-%! assert (e, [3 5]);
-%! assert (te, { zeros(0,2), zeros(0,2) });
-%! assert (m, { "OCT", "V" });
-%! assert (t, { cell(1,0), cell(1,0) });
-%! assert (isempty (fieldnames (nm)));
-%! assert (sp, { "", "A", "E" });
-
-%!test
-%! [s, e, te, m, t, nm, sp] = regexp ('OCTAVE', '([VOCT]*)', 'noemptymatch');
-%! assert (s, [1 5]);
-%! assert (e, [3 5]);
-%! assert (te, { [1 3], [5 5] });
-%! assert (m, { "OCT", "V" });
-%! assert (t, { {"OCT"}, {"V"} });
-%! assert (isempty (fieldnames (nm)));
-%! assert (sp, { "", "A", "E" });
-
-%!test
-%! [s, e, te, m, t, nm, sp] = regexp ('OCTAVE', '[VOCT]*', 'emptymatch');
-%! assert (s, [1 4 5 6 7]);
-%! assert (e, [3 3 5 5 6]);
-%! assert (te, repmat ({zeros(0,2)}, [1, 5]));
-%! assert (m, { "OCT", "", "V", "", "" });
-%! assert (t, repmat({cell(1,0)}, [1, 5]));
-%! assert (isempty (fieldnames (nm)));
-%! assert (sp, { "", "", "A", "", "E", "" });
-
-%!test
-%! [s, e, te, m, t, nm, sp] = regexp ('OCTAVE', '([VOCT]*)', 'emptymatch');
-%! assert (s, [1 4 5 6 7]);
-%! assert (e, [3 3 5 5 6]);
-%! assert (te, { [1 3], [4 3], [5 5], [6 5], [7 6] });
-%! assert (m, { "OCT", "", "V", "", "" });
-%! assert (t, { {"OCT"}, {""}, {"V"}, {""}, {""} });
-%! assert (isempty (fieldnames (nm)));
-%! assert (sp, { "", "", "A", "", "E", "" });
-
-%!error regexp ('string', 'tri', 'BadArg')
-%!error regexp ('string')
-
-%!assert (regexp ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, '-'), {6;[1,5,9];zeros(1,0)})
-%!assert (regexp ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, {'-';'f';'q'}), {6;[3,7];[1,9]})
-%!assert (regexp ('Strings', {'t','s'}), {2, 7})
-
-## Test case for lookaround operators
-%!test
-%! assert (regexp ('Iraq', 'q(?!u)'), 4);
-%! assert (regexp ('quit', 'q(?!u)'), zeros (1, 0));
-%! assert (regexp ('quit', 'q(?=u)' , 'match'), {'q'});
-%! assert (regexp ("quit", 'q(?=u+)', 'match'), {'q'});
-%! assert (regexp ("qit",  'q(?=u+)', 'match'), cell (1, 0));
-%! assert (regexp ("qit",  'q(?=u*)', 'match'), {'q'});
-%! assert (regexp ('thingamabob', '(?<=a)b'), 9);
-
-## Tests for split option.
-%!shared str
-%! str = "foo bar foo";
-%!test
-%! [a, b] = regexp (str, "f..", "match", "split");
-%! assert (a, {"foo", "foo"});
-%! assert (b, {"", " bar ", ""});
-%!test
-%! [a, b] = regexp (str, "f..", "match", "split", "once");
-%! assert (a, "foo");
-%! assert (b, {"", " bar foo"});
-%!test
-%! [a, b] = regexp (str, "fx.", "match", "split");
-%! assert (a, cell (1, 0));
-%! assert (b, {"foo bar foo"});
-%!test
-%! [a, b] = regexp (str, "fx.", "match", "split", "once");
-%! assert (a, "");;
-%! assert (b, "foo bar foo");
-
-%!shared str
-%! str = "foo bar";
-%!test
-%! [a, b] = regexp (str, "f..", "match", "split");
-%! assert (a, {"foo"});
-%! assert (b, {"", " bar"});
-%!test
-%! [a, b] = regexp (str, "b..", "match", "split");
-%! assert (a, {"bar"});
-%! assert (b, {"foo ", ""});
-%!test
-%! [a, b] = regexp (str, "x", "match", "split");
-%! assert (a, cell (1, 0));
-%! assert (b, {"foo bar"});
-%!test
-%! [a, b] = regexp (str, "[o]+", "match", "split");
-%! assert (a, {"oo"});
-%! assert (b, {"f", " bar"});
-
-%!assert (regexp ("\n", '\n'), 1);
-%!assert (regexp ("\n", "\n"), 1);
-*/
-
-DEFUN_DLD (regexpi, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexpi (@var{str}, @var{pat})\n\
-@deftypefnx {Loadable Function} {[@dots{}] =} regexpi (@var{str}, @var{pat}, \"@var{opt1}\", @dots{})\n\
-\n\
-Case insensitive regular expression string matching.  Search for @var{pat} in\n\
-@var{str} and return the positions and substrings of any matches, or empty\n\
-values if there are none.  @xref{doc-regexp,,regexp}, for details on the\n\
-syntax of the search pattern.\n\
-@seealso{regexp}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 2)
-    print_usage ();
-  else if (args(0).is_cell () || args(1).is_cell ())
-    retval = octcellregexp (args, (nargout > 0 ? nargout : 1), "regexpi", true);
-  else
-    retval = octregexp (args, nargout, "regexpi", true);
-
-  return retval;
-}
-
-/*
-## segfault test
-%!assert (regexpi ("abcde", "."), [1,2,3,4,5])
-
-## Check that anchoring of pattern works correctly
-%!assert (regexpi ('abcabc', '^ABC'), 1)
-%!assert (regexpi ('abcabc', 'ABC$'), 4)
-%!assert (regexpi ('abcabc', '^ABC$'), zeros (1,0))
-
-%!test
-%! [s, e, te, m, t] = regexpi (' No Match ', 'f(.*)uck');
-%! assert (s, zeros (1,0));
-%! assert (e, zeros (1,0));
-%! assert (te, cell (1,0));
-%! assert (m, cell (1,0));
-%! assert (t, cell (1,0));
-
-%!test
-%! [s, e, te, m, t] = regexpi (' FiRetrUck ', 'f(.*)uck');
-%! assert (s, 2);
-%! assert (e, 10);
-%! assert (te{1}, [3, 7]);
-%! assert (m{1}, 'FiRetrUck');
-%! assert (t{1}{1}, 'iRetr');
-
-%!test
-%! [s, e, te, m, t] = regexpi (' firetruck ', 'f(.*)uck');
-%! assert (s, 2);
-%! assert (e, 10);
-%! assert (te{1}, [3, 7]);
-%! assert (m{1}, 'firetruck');
-%! assert (t{1}{1}, 'iretr');
-
-%!test
-%! [s, e, te, m, t] = regexpi ('ShoRt Test String', '\w*r\w*');
-%! assert (s, [1, 12]);
-%! assert (e, [5, 17]);
-%! assert (size (te), [1, 2]);
-%! assert (isempty (te{1}));
-%! assert (isempty (te{2}));
-%! assert (m{1}, 'ShoRt');
-%! assert (m{2}, 'String');
-%! assert (size (t), [1, 2]);
-%! assert (isempty (t{1}));
-%! assert (isempty (t{2}));
-
-%!test
-%! [s, e, te, m, t] = regexpi ('ShoRt Test String', '\w*r\w*', 'once');
-%! assert (s, 1);
-%! assert (e, 5);
-%! assert (isempty (te));
-%! assert (m, 'ShoRt');
-%! assert (isempty (t));
-
-%!test
-%! [m, te, e, s, t] = regexpi ('ShoRt Test String', '\w*r\w*', 'once', 'match', 'tokenExtents', 'end', 'start', 'tokens');
-%! assert (s, 1);
-%! assert (e, 5);
-%! assert (isempty (te));
-%! assert (m, 'ShoRt');
-%! assert (isempty (t));
-
-%!test
-%! [s, e, te, m, t, nm] = regexpi ('ShoRt Test String', '(?<word1>\w*t)\s*(?<word2>\w*t)');
-%! assert (s, 1);
-%! assert (e, 10);
-%! assert (size (te), [1, 1]);
-%! assert (te{1}, [1,5; 7,10]);
-%! assert (m{1}, 'ShoRt Test');
-%! assert (size (t), [1, 1]);
-%! assert (t{1}{1}, 'ShoRt');
-%! assert (t{1}{2}, 'Test');
-%! assert (size (nm), [1, 1]);
-%! assert (! isempty (fieldnames (nm)));
-%! assert (sort (fieldnames (nm)), {'word1';'word2'});
-%! assert (nm.word1, 'ShoRt');
-%! assert (nm.word2, 'Test');
-
-%!test
-%! [nm, m, te, e, s, t] = regexpi ('ShoRt Test String', '(?<word1>\w*t)\s*(?<word2>\w*t)', 'names', 'match', 'tokenExtents', 'end', 'start', 'tokens');
-%! assert (s, 1);
-%! assert (e, 10);
-%! assert (size (te), [1, 1]);
-%! assert (te{1}, [1,5; 7,10]);
-%! assert (m{1}, 'ShoRt Test');
-%! assert (size (t), [1, 1]);
-%! assert (t{1}{1}, 'ShoRt');
-%! assert (t{1}{2}, 'Test');
-%! assert (size (nm), [1, 1]);
-%! assert (!isempty (fieldnames (nm)));
-%! assert (sort (fieldnames (nm)), {'word1';'word2'});
-%! assert (nm.word1, 'ShoRt');
-%! assert (nm.word2, 'Test');
-
-%!assert (regexpi ("abc\nabc", '.'), [1:7])
-%!assert (regexpi ("abc\nabc", '.', 'dotall'), [1:7])
-%!test
-%! assert (regexpi ("abc\nabc", '(?s).'), [1:7]);
-%! assert (regexpi ("abc\nabc", '.', 'dotexceptnewline'), [1,2,3,5,6,7]);
-%! assert (regexpi ("abc\nabc", '(?-s).'), [1,2,3,5,6,7]);
-
-%!assert (regexpi ("caseCaSe", 'case'), [1, 5])
-%!assert (regexpi ("caseCaSe", 'case', "matchcase"), 1)
-%!assert (regexpi ("caseCaSe", 'case', "ignorecase"), [1, 5])
-%!test
-%! assert (regexpi ("caseCaSe", '(?-i)case'), 1);
-%! assert (regexpi ("caseCaSe", '(?i)case'), [1, 5]);
-
-%!assert (regexpi ("abc\nabc", 'C$'), 7)
-%!assert (regexpi ("abc\nabc", 'C$', "stringanchors"), 7)
-%!test
-%! assert (regexpi ("abc\nabc", '(?-m)C$'), 7);
-%! assert (regexpi ("abc\nabc", 'C$', "lineanchors"), [3, 7]);
-%! assert (regexpi ("abc\nabc", '(?m)C$'), [3, 7]);
-
-%!assert (regexpi ("this word", 'S w'), 4)
-%!assert (regexpi ("this word", 'S w', 'literalspacing'), 4)
-%!test
-%! assert (regexpi ("this word", '(?-x)S w', 'literalspacing'), 4);
-%! assert (regexpi ("this word", 'S w', 'freespacing'), zeros (1,0));
-%! assert (regexpi ("this word", '(?x)S w'), zeros (1,0));
-
-%!error regexpi ('string', 'tri', 'BadArg')
-%!error regexpi ('string')
-
-%!assert (regexpi ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, '-'), {6;[1,5,9];zeros(1, 0)})
-%!assert (regexpi ({'asdfg-dfd', '-dfd-dfd-', 'qasfdfdaq'}, '-'), {6, [1,5,9], zeros(1,0)})
-%!assert (regexpi ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, {'-';'f';'q'}), {6;[3,7];[1,9]})
-%!assert (regexpi ('Strings', {'t', 's'}), {2, [1, 7]})
-
-%!assert (regexpi ("\n", '\n'), 1);
-%!assert (regexpi ("\n", "\n"), 1);
-*/
-
-static octave_value
-octregexprep (const octave_value_list &args, const std::string &who)
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  // Make sure we have string, pattern, replacement
-  const std::string buffer = args(0).string_value ();
-  if (error_state)
-    return retval;
-
-  std::string pattern = args(1).string_value ();
-  if (error_state)
-    return retval;
-  // Matlab compatibility.
-  if (args(1).is_sq_string ())
-    pattern = do_regexp_string_escapes (pattern);
-
-  std::string replacement = args(2).string_value ();
-  if (error_state)
-    return retval;
-  // Matlab compatibility.
-  if (args(2).is_sq_string ())
-    replacement = do_regexp_string_escapes (replacement);
-
-  // Pack options excluding 'tokenize' and various output
-  // reordering strings into regexp arg list
-  octave_value_list regexpargs (nargin-3, octave_value ());
-
-  int len = 0;
-  for (int i = 3; i < nargin; i++)
-    {
-      const std::string opt = args(i).string_value ();
-      if (opt != "tokenize" && opt != "start" && opt != "end"
-          && opt != "tokenextents" && opt != "match" && opt != "tokens"
-          && opt != "names"  && opt != "split" && opt != "warnings")
-        {
-          regexpargs(len++) = args(i);
-        }
-    }
-  regexpargs.resize (len);
-
-  regexp::opts options;
-  bool extra_args = false;
-  parse_options (options, regexpargs, who, 0, extra_args);
-  if (error_state)
-    return retval;
-
-  return regexp_replace (pattern, buffer, replacement, options, who);
-}
-
-DEFUN_DLD (regexprep, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr})\n\
-@deftypefnx {Loadable Function} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr}, \"@var{opt1}\", @dots{})\n\
-Replace occurrences of pattern @var{pat} in @var{string} with @var{repstr}.\n\
-\n\
-The pattern is a regular expression as documented for @code{regexp}.\n\
-@xref{doc-regexp,,regexp}.\n\
-\n\
-The replacement string may contain @code{$i}, which substitutes\n\
-for the ith set of parentheses in the match string.  For example,\n\
-\n\
-@example\n\
-regexprep (\"Bill Dunn\", '(\\w+) (\\w+)', '$2, $1')\n\
-@end example\n\
-\n\
-@noindent\n\
-returns \"Dunn, Bill\"\n\
-\n\
-Options in addition to those of @code{regexp} are\n\
-\n\
-@table @samp\n\
-\n\
-@item once\n\
-Replace only the first occurrence of @var{pat} in the result.\n\
-\n\
-@item warnings\n\
-This option is present for compatibility but is ignored.\n\
-\n\
-@end table\n\
-@seealso{regexp, regexpi, strrep}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-  int nargin = args.length ();
-
-  if (nargin < 3)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  if (args(0).is_cell () || args(1).is_cell () || args(2).is_cell ())
-    {
-      Cell str;
-      Cell pat;
-      Cell rep;
-      dim_vector dv0;
-      dim_vector dv1 (1, 1);
-
-      if (args(0).is_cell ())
-        str = args(0).cell_value ();
-      else
-        str = Cell (args(0));
-
-      if (args(1).is_cell ())
-        pat = args(1).cell_value ();
-      else
-        pat = Cell (args(1));
-
-      if (args(2).is_cell ())
-        rep = args(2).cell_value ();
-      else
-        rep = Cell (args(2));
-
-      dv0 = str.dims ();
-      if (pat.numel () != 1)
-        {
-          dv1 = pat.dims ();
-          if (rep.numel () != 1 && dv1 != rep.dims ())
-            error ("regexprep: inconsistent cell array dimensions");
-        }
-      else if (rep.numel () != 1)
-        dv1 = rep.dims ();
-
-      if (!error_state)
-        {
-          Cell ret (dv0);
-          octave_value_list new_args = args;
-
-          for (octave_idx_type i = 0; i < dv0.numel (); i++)
-            {
-              new_args(0) = str(i);
-              if (pat.numel () == 1)
-                new_args(1) = pat(0);
-              if (rep.numel () == 1)
-                new_args(2) = rep(0);
-
-              for (octave_idx_type j = 0; j < dv1.numel (); j++)
-                {
-                  if (pat.numel () != 1)
-                    new_args(1) = pat(j);
-                  if (rep.numel () != 1)
-                    new_args(2) = rep(j);
-                  new_args(0) = octregexprep (new_args, "regexprep");
-
-                  if (error_state)
-                    break;
-                }
-
-              if (error_state)
-                break;
-
-              ret(i) = new_args(0);
-            }
-
-          if (!error_state)
-            retval = args(0).is_cell ()
-              ? octave_value (ret) : octave_value (ret(0));
-        }
-    }
-  else
-    retval = octregexprep (args, "regexprep");
-
-  return retval;
-}
-
-/*
-%!test  # Replace with empty
-%! xml = '<!-- This is some XML --> <tag v="hello">some stuff<!-- sample tag--></tag>';
-%! t = regexprep (xml, '<[!?][^>]*>', '');
-%! assert (t, ' <tag v="hello">some stuff</tag>');
-
-%!test  # Replace with non-empty
-%! xml = '<!-- This is some XML --> <tag v="hello">some stuff<!-- sample tag--></tag>';
-%! t = regexprep (xml, '<[!?][^>]*>', '?');
-%! assert (t, '? <tag v="hello">some stuff?</tag>');
-
-%!test  # Check that 'tokenize' is ignored
-%! xml = '<!-- This is some XML --> <tag v="hello">some stuff<!-- sample tag--></tag>';
-%! t = regexprep (xml, '<[!?][^>]*>', '', 'tokenize');
-%! assert (t, ' <tag v="hello">some stuff</tag>');
-
-## Test capture replacement
-%!test
-%! data = "Bob Smith\nDavid Hollerith\nSam Jenkins";
-%! result = "Smith, Bob\nHollerith, David\nJenkins, Sam";
-%! t = regexprep (data, '(?m)^(\w+)\s+(\w+)$', '$2, $1');
-%! assert (t, result);
-
-## Return the original if no match
-%!assert (regexprep ('hello', 'world', 'earth'), 'hello')
-
-## Test emptymatch
-%!assert (regexprep ('World', '^', 'Hello '), 'World')
-%!assert (regexprep ('World', '^', 'Hello ', 'emptymatch'), 'Hello World')
-
-## Test a general replacement
-%!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Za-z0-9_]", "_"), "a_b_c_d_e_f_g")
-
-## Make sure it works at the beginning and end
-%!assert (regexprep ("a[b]c{d}e-f=g", "a", "_"), "_[b]c{d}e-f=g")
-%!assert (regexprep ("a[b]c{d}e-f=g", "g", "_"), "a[b]c{d}e-f=_")
-
-## Options
-%!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Za-z0-9_]", "_", "once"), "a_b]c{d}e-f=g")
-%!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Z0-9_]", "_", "ignorecase"), "a_b_c_d_e_f_g")
-
-## Option combinations
-%!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Z0-9_]", "_", "once", "ignorecase"), "a_b]c{d}e-f=g")
-
-## End conditions on replacement
-%!assert (regexprep ("abc", "(b)", ".$1"), "a.bc");
-%!assert (regexprep ("abc", "(b)", "$1"), "abc");
-%!assert (regexprep ("abc", "(b)", "$1."), "ab.c");
-%!assert (regexprep ("abc", "(b)", "$1.."), "ab..c");
-
-## Test cell array arguments
-%!assert (regexprep ("abc", {"b","a"}, "?"), "??c")
-%!assert (regexprep ({"abc","cba"}, "b", "?"), {"a?c","c?a"})
-%!assert (regexprep ({"abc","cba"}, {"b","a"}, {"?","!"}), {"!?c","c?!"})
-
-# Nasty lookbehind expression
-%!assert (regexprep ('x^(-1)+y(-1)+z(-1)=0', '(?<=[a-z]+)\(\-[1-9]*\)', '_minus1'),'x^(-1)+y_minus1+z_minus1=0')
-
-%!assert (regexprep ("\n", '\n', "X"), "X");
-%!assert (regexprep ("\n", "\n", "X"), "X");
-*/
--- a/src/DLD-FUNCTIONS/schur.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,381 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-
-#include "CmplxSCHUR.h"
-#include "dbleSCHUR.h"
-#include "fCmplxSCHUR.h"
-#include "floatSCHUR.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-template <class Matrix>
-static octave_value
-mark_upper_triangular (const Matrix& a)
-{
-  octave_value retval = a;
-
-  octave_idx_type n = a.rows ();
-  assert (a.columns () == n);
-
-  const typename Matrix::element_type zero = typename Matrix::element_type ();
-
-  for (octave_idx_type i = 0; i < n; i++)
-    if (a(i,i) == zero)
-      return retval;
-
-  retval.matrix_type (MatrixType::Upper);
-
-  return retval;
-}
-
-DEFUN_DLD (schur, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{S} =} schur (@var{A})\n\
-@deftypefnx {Loadable Function} {@var{S} =} schur (@var{A}, \"real\")\n\
-@deftypefnx {Loadable Function} {@var{S} =} schur (@var{A}, \"complex\")\n\
-@deftypefnx {Loadable Function} {@var{S} =} schur (@var{A}, @var{opt})\n\
-@deftypefnx {Loadable Function} {[@var{U}, @var{S}] =} schur (@var{A}, @dots{})\n\
-@cindex Schur decomposition\n\
-Compute the Schur@tie{}decomposition of @var{A}\n\
-@tex\n\
-$$\n\
- S = U^T A U\n\
-$$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-@code{@var{S} = @var{U}' * @var{A} * @var{U}}\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-where @var{U} is a unitary matrix\n\
-@tex\n\
-($U^T U$ is identity)\n\
-@end tex\n\
-@ifnottex\n\
-(@code{@var{U}'* @var{U}} is identity)\n\
-@end ifnottex\n\
-and @var{S} is upper triangular.  The eigenvalues of @var{A} (and @var{S})\n\
-are the diagonal elements of @var{S}.  If the matrix @var{A}\n\
-is real, then the real Schur@tie{}decomposition is computed, in which the\n\
-matrix @var{U} is orthogonal and @var{S} is block upper triangular\n\
-with blocks of size at most\n\
-@tex\n\
-$2 \\times 2$\n\
-@end tex\n\
-@ifnottex\n\
-@code{2 x 2}\n\
-@end ifnottex\n\
-along the diagonal.  The diagonal elements of @var{S}\n\
-(or the eigenvalues of the\n\
-@tex\n\
-$2 \\times 2$\n\
-@end tex\n\
-@ifnottex\n\
-@code{2 x 2}\n\
-@end ifnottex\n\
-blocks, when appropriate) are the eigenvalues of @var{A} and @var{S}.\n\
-\n\
-The default for real matrices is a real Schur@tie{}decomposition.\n\
-A complex decomposition may be forced by passing the flag \"complex\".\n\
-\n\
-The eigenvalues are optionally ordered along the diagonal according to\n\
-the value of @var{opt}.  @code{@var{opt} = \"a\"} indicates that all\n\
-eigenvalues with negative real parts should be moved to the leading\n\
-block of @var{S}\n\
-(used in @code{are}), @code{@var{opt} = \"d\"} indicates that all eigenvalues\n\
-with magnitude less than one should be moved to the leading block of @var{S}\n\
-(used in @code{dare}), and @code{@var{opt} = \"u\"}, the default, indicates\n\
-that no ordering of eigenvalues should occur.  The leading @var{k}\n\
-columns of @var{U} always span the @var{A}-invariant\n\
-subspace corresponding to the @var{k} leading eigenvalues of @var{S}.\n\
-\n\
-The Schur@tie{}decomposition is used to compute eigenvalues of a\n\
-square matrix, and has applications in the solution of algebraic\n\
-Riccati equations in control (see @code{are} and @code{dare}).\n\
-@seealso{rsf2csf}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 1 || nargin > 2 || nargout > 2)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value arg = args(0);
-
-  std::string ord;
-
-  if (nargin == 2)
-    {
-      ord = args(1).string_value ();
-
-      if (error_state)
-        {
-          error ("schur: second argument must be a string");
-          return retval;
-        }
-    }
-
-  bool force_complex = false;
-
-  if (ord == "real")
-    {
-      ord = std::string ();
-    }
-  else if (ord == "complex")
-    {
-      force_complex = true;
-      ord = std::string ();
-    }
-  else
-    {
-      char ord_char = ord.empty () ? 'U' : ord[0];
-
-      if (ord_char != 'U' && ord_char != 'A' && ord_char != 'D'
-          && ord_char != 'u' && ord_char != 'a' && ord_char != 'd')
-        {
-          warning ("schur: incorrect ordered schur argument `%c'",
-                   ord.c_str ());
-          return retval;
-        }
-    }
-
-  octave_idx_type nr = arg.rows ();
-  octave_idx_type nc = arg.columns ();
-
-  if (nr != nc)
-    {
-      gripe_square_matrix_required ("schur");
-      return retval;
-    }
-
-  if (! arg.is_numeric_type ())
-    gripe_wrong_type_arg ("schur", arg);
-  else if (arg.is_single_type ())
-    {
-      if (! force_complex && arg.is_real_type ())
-        {
-          FloatMatrix tmp = arg.float_matrix_value ();
-
-          if (! error_state)
-            {
-              if (nargout == 0 || nargout == 1)
-                {
-                  FloatSCHUR result (tmp, ord, false);
-                  retval(0) = result.schur_matrix ();
-                }
-              else
-                {
-                  FloatSCHUR result (tmp, ord, true);
-                  retval(1) = result.schur_matrix ();
-                  retval(0) = result.unitary_matrix ();
-                }
-            }
-        }
-      else
-        {
-          FloatComplexMatrix ctmp = arg.float_complex_matrix_value ();
-
-          if (! error_state)
-            {
-
-              if (nargout == 0 || nargout == 1)
-                {
-                  FloatComplexSCHUR result (ctmp, ord, false);
-                  retval(0) = mark_upper_triangular (result.schur_matrix ());
-                }
-              else
-                {
-                  FloatComplexSCHUR result (ctmp, ord, true);
-                  retval(1) = mark_upper_triangular (result.schur_matrix ());
-                  retval(0) = result.unitary_matrix ();
-                }
-            }
-        }
-    }
-  else
-    {
-      if (! force_complex && arg.is_real_type ())
-        {
-          Matrix tmp = arg.matrix_value ();
-
-          if (! error_state)
-            {
-              if (nargout == 0 || nargout == 1)
-                {
-                  SCHUR result (tmp, ord, false);
-                  retval(0) = result.schur_matrix ();
-                }
-              else
-                {
-                  SCHUR result (tmp, ord, true);
-                  retval(1) = result.schur_matrix ();
-                  retval(0) = result.unitary_matrix ();
-                }
-            }
-        }
-      else
-        {
-          ComplexMatrix ctmp = arg.complex_matrix_value ();
-
-          if (! error_state)
-            {
-
-              if (nargout == 0 || nargout == 1)
-                {
-                  ComplexSCHUR result (ctmp, ord, false);
-                  retval(0) = mark_upper_triangular (result.schur_matrix ());
-                }
-              else
-                {
-                  ComplexSCHUR result (ctmp, ord, true);
-                  retval(1) = mark_upper_triangular (result.schur_matrix ());
-                  retval(0) = result.unitary_matrix ();
-                }
-            }
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!test
-%! a = [1, 2, 3; 4, 5, 9; 7, 8, 6];
-%! [u, s] = schur (a);
-%! assert (u' * a * u, s, sqrt (eps));
-
-%!test
-%! a = single ([1, 2, 3; 4, 5, 9; 7, 8, 6]);
-%! [u, s] = schur (a);
-%! assert (u' * a * u, s, sqrt (eps ("single")));
-
-%!test
-%! fail ("schur ([1, 2; 3, 4], 2)", "warning");
-
-%!error schur ()
-%!error <argument must be a square matrix> schur ([1, 2, 3; 4, 5, 6])
-*/
-
-DEFUN_DLD (rsf2csf, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Function File} {[@var{U}, @var{T}] =} rsf2csf (@var{UR}, @var{TR})\n\
-Convert a real, upper quasi-triangular Schur@tie{}form @var{TR} to a complex,\n\
-upper triangular Schur@tie{}form @var{T}.\n\
-\n\
-Note that the following relations hold:\n\
-\n\
-@tex\n\
-$UR \\cdot TR \\cdot {UR}^T = U T U^{\\dagger}$ and\n\
-$U^{\\dagger} U$ is the identity matrix I.\n\
-@end tex\n\
-@ifnottex\n\
-@xcode{@var{UR} * @var{TR} * @var{UR}' = @var{U} * @var{T} * @var{U}'} and\n\
-@code{@var{U}' * @var{U}} is the identity matrix I.\n\
-@end ifnottex\n\
-\n\
-Note also that @var{U} and @var{T} are not unique.\n\
-@seealso{schur}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  if (args.length () == 2 && nargout <= 2)
-    {
-      if (! args(0).is_numeric_type ())
-        gripe_wrong_type_arg ("rsf2csf", args(0));
-      else if (! args(1).is_numeric_type ())
-        gripe_wrong_type_arg ("rsf2csf", args(1));
-      else if (args(0).is_complex_type () || args(1).is_complex_type ())
-        error ("rsf2csf: UR and TR must be real matrices");
-      else
-        {
-
-          if (args(0).is_single_type () || args(1).is_single_type ())
-            {
-              FloatMatrix u = args(0).float_matrix_value ();
-              FloatMatrix t = args(1).float_matrix_value ();
-              if (! error_state)
-                {
-                  FloatComplexSCHUR cs (FloatSCHUR (t, u));
-
-                  retval(1) = cs.schur_matrix ();
-                  retval(0) = cs.unitary_matrix ();
-                }
-            }
-          else
-            {
-              Matrix u = args(0).matrix_value ();
-              Matrix t = args(1).matrix_value ();
-              if (! error_state)
-                {
-                  ComplexSCHUR cs (SCHUR (t, u));
-
-                  retval(1) = cs.schur_matrix ();
-                  retval(0) = cs.unitary_matrix ();
-                }
-            }
-        }
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!test
-%! A = [1, 1, 1, 2; 1, 2, 1, 1; 1, 1, 3, 1; -2, 1, 1, 1];
-%! [u, t] = schur (A);
-%! [U, T] = rsf2csf (u, t);
-%! assert (norm (u * t * u' - U * T * U'), 0, 1e-12);
-%! assert (norm (A - U * T * U'), 0, 1e-12);
-
-%!test
-%! A = rand (10);
-%! [u, t] = schur (A);
-%! [U, T] = rsf2csf (u, t);
-%! assert (norm (tril (T, -1)), 0);
-%! assert (norm (U * U'), 1, 1e-14);
-
-%!test
-%! A = [0, 1;-1, 0];
-%! [u, t] = schur (A);
-%! [U, T] = rsf2csf (u,t);
-%! assert (U * T * U', A, 1e-14);
-*/
--- a/src/DLD-FUNCTIONS/spparms.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,208 +0,0 @@
-/*
-
-Copyright (C) 2004-2012 David Bateman
-Copyright (C) 1998-2004 Andy Adler
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "defun-dld.h"
-#include "ov.h"
-#include "pager.h"
-#include "error.h"
-#include "gripes.h"
-
-#include "oct-spparms.h"
-
-DEFUN_DLD (spparms, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} { } spparms ()\n\
-@deftypefnx {Loadable Function} {@var{vals} =} spparms ()\n\
-@deftypefnx {Loadable Function} {[@var{keys}, @var{vals}] =} spparms ()\n\
-@deftypefnx {Loadable Function} {@var{val} =} spparms (@var{key})\n\
-@deftypefnx {Loadable Function} { } spparms (@var{vals})\n\
-@deftypefnx {Loadable Function} { } spparms (\"defaults\")\n\
-@deftypefnx {Loadable Function} { } spparms (\"tight\")\n\
-@deftypefnx {Loadable Function} { } spparms (@var{key}, @var{val})\n\
-Query or set the parameters used by the sparse solvers and factorization\n\
-functions.  The first four calls above get information about the current\n\
-settings, while the others change the current settings.  The parameters are\n\
-stored as pairs of keys and values, where the values are all floats and the\n\
-keys are one of the following strings:\n\
-\n\
-@table @samp\n\
-@item spumoni\n\
-Printing level of debugging information of the solvers (default 0)\n\
-\n\
-@item ths_rel\n\
-Included for compatibility.  Not used.  (default 1)\n\
-\n\
-@item ths_abs\n\
-Included for compatibility.  Not used.  (default 1)\n\
-\n\
-@item exact_d\n\
-Included for compatibility.  Not used.  (default 0)\n\
-\n\
-@item supernd\n\
-Included for compatibility.  Not used.  (default 3)\n\
-\n\
-@item rreduce\n\
-Included for compatibility.  Not used.  (default 3)\n\
-\n\
-@item wh_frac\n\
-Included for compatibility.  Not used.  (default 0.5)\n\
-\n\
-@item autommd\n\
-Flag whether the LU/QR and the '\\' and '/' operators will automatically\n\
-use the sparsity preserving mmd functions (default 1)\n\
-\n\
-@item autoamd\n\
-Flag whether the LU and the '\\' and '/' operators will automatically\n\
-use the sparsity preserving amd functions (default 1)\n\
-\n\
-@item piv_tol\n\
-The pivot tolerance of the @sc{umfpack} solvers (default 0.1)\n\
-\n\
-@item sym_tol\n\
-The pivot tolerance of the @sc{umfpack} symmetric solvers (default 0.001)\n\
-\n\
-@item bandden\n\
-The density of non-zero elements in a banded matrix before it is treated\n\
-by the @sc{lapack} banded solvers (default 0.5)\n\
-\n\
-@item umfpack\n\
-Flag whether the @sc{umfpack} or mmd solvers are used for the LU, '\\' and\n\
-'/' operations (default 1)\n\
-@end table\n\
-\n\
-The value of individual keys can be set with\n\
-@code{spparms (@var{key}, @var{val})}.\n\
-The default values can be restored with the special keyword\n\
-\"defaults\".  The special keyword \"tight\" can be used to set the mmd\n\
-solvers to attempt a sparser solution at the potential cost of longer\n\
-running time.\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-  int nargin = args.length ();
-
-  if (nargin == 0)
-    {
-      if (nargout == 0)
-        octave_sparse_params::print_info (octave_stdout, "");
-      else if (nargout == 1)
-        retval(0) =  octave_sparse_params::get_vals ();
-      else if (nargout == 2)
-        {
-          retval(1) = octave_sparse_params::get_vals ();
-          retval(0) = octave_sparse_params::get_keys ();
-        }
-      else
-        error ("spparms: too many output arguments");
-    }
-  else if (nargin == 1)
-    {
-      if (args(0).is_string ())
-        {
-          std::string str = args(0).string_value ();
-          int len = str.length ();
-          for (int i = 0; i < len; i++)
-            str[i] = tolower (str[i]);
-
-          if (str == "defaults")
-            octave_sparse_params::defaults ();
-          else if (str == "tight")
-            octave_sparse_params::tight ();
-          else
-            {
-              double val = octave_sparse_params::get_key (str);
-              if (xisnan (val))
-                error ("spparms: KEY not recognized");
-              else
-                retval(0) = val;
-            }
-        }
-      else
-        {
-          NDArray vals = args(0).array_value ();
-
-          if (error_state)
-            error ("spparms: input must be a string or a vector");
-          else if (vals.numel () > OCTAVE_SPARSE_CONTROLS_SIZE)
-            error ("spparms: too many elements in vector VALS");
-          else
-            octave_sparse_params::set_vals (vals);
-        }
-    }
-  else if (nargin == 2)
-    {
-      if (args(0).is_string ())
-        {
-          std::string str = args(0).string_value ();
-
-          double val = args(1).double_value ();
-
-          if (error_state)
-            error ("spparms: second argument must be a real scalar");
-          else if (str == "umfpack")
-            warning ("spparms: request to disable umfpack solvers ignored");
-          else if (!octave_sparse_params::set_key (str, val))
-            error ("spparms: KEY not found");
-        }
-      else
-        error ("spparms: first argument must be a string");
-    }
-  else
-    error ("spparms: too many input arguments");
-
-  return retval;
-}
-
-/*
-%!test
-%! old_vals = spparms ();  # save state
-%! spparms ("defaults");
-%! vals = spparms ();
-%! assert (vals, [0 1 1 0 3 3 0.5 1.0 1.0 0.1 0.5 1.0 0.001]');
-%! [keys, vals] = spparms ();
-%! assert (rows (keys), 13);
-%! assert (keys(2,:), "ths_rel");
-%! assert (vals, [0 1 1 0 3 3 0.5 1.0 1.0 0.1 0.5 1.0 0.001]');
-%! spparms ([3 2 1]);
-%! assert (spparms ()(1:3), [3, 2, 1]');
-%! assert (spparms ("ths_rel"), 2);
-%! spparms ("exact_d", 5);
-%! assert (spparms ("exact_d"), 5);
-%! spparms (old_vals);     # restore state
-
-%% Test input validation
-%!error <too many input arguments> spparms (1, 2, 3)
-%!error <too many output arguments> [x, y, z] = spparms ()
-%!error <KEY not recognized> spparms ("UNKNOWN_KEY")
-%!#error <input must be a string> spparms ({1, 2, 3})
-%!error spparms ({1, 2, 3})
-%!error <too many elements in vector VALS> spparms (ones (14, 1))
-%!error <first argument must be a string> spparms (1, 1)
-%!#error <second argument must be a real scalar> spparms ("ths_rel", "hello")
-%!error spparms ("ths_rel", "hello")
-%!error <KEY not found> spparms ("UNKNOWN_KEY", 1)
-*/
--- a/src/DLD-FUNCTIONS/sqrtm.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,276 +0,0 @@
-/*
-
-Copyright (C) 2001-2012 Ross Lippert and Paul Kienzle
-Copyright (C) 2010 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <float.h>
-
-#include "CmplxSCHUR.h"
-#include "fCmplxSCHUR.h"
-#include "lo-ieee.h"
-#include "lo-mappers.h"
-#include "oct-norm.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "utils.h"
-#include "xnorm.h"
-
-template <class Matrix>
-static void
-sqrtm_utri_inplace (Matrix& T)
-{
-  typedef typename Matrix::element_type element_type;
-
-  const element_type zero = element_type ();
-
-  bool singular = false;
-
-  // The following code is equivalent to this triple loop:
-  //
-  //   n = rows (T);
-  //   for j = 1:n
-  //     T(j,j) = sqrt (T(j,j));
-  //     for i = j-1:-1:1
-  //       T(i,j) /= (T(i,i) + T(j,j));
-  //       k = 1:i-1;
-  //       T(k,j) -= T(k,i) * T(i,j);
-  //     endfor
-  //   endfor
-  //
-  // this is an in-place, cache-aligned variant of the code
-  // given in Higham's paper.
-
-  const octave_idx_type n = T.rows ();
-  element_type *Tp = T.fortran_vec ();
-  for (octave_idx_type j = 0; j < n; j++)
-    {
-      element_type *colj = Tp + n*j;
-      if (colj[j] != zero)
-        colj[j] = sqrt (colj[j]);
-      else
-        singular = true;
-
-      for (octave_idx_type i = j-1; i >= 0; i--)
-        {
-          const element_type *coli = Tp + n*i;
-          const element_type colji = colj[i] /= (coli[i] + colj[j]);
-          for (octave_idx_type k = 0; k < i; k++)
-            colj[k] -= coli[k] * colji;
-        }
-    }
-
-  if (singular)
-    warning_with_id ("Octave:sqrtm:SingularMatrix",
-                     "sqrtm: matrix is singular, may not have a square root");
-}
-
-template <class Matrix, class ComplexMatrix, class ComplexSCHUR>
-static octave_value
-do_sqrtm (const octave_value& arg)
-{
-
-  octave_value retval;
-
-  MatrixType mt = arg.matrix_type ();
-
-  bool iscomplex = arg.is_complex_type ();
-
-  typedef typename Matrix::element_type real_type;
-
-  real_type cutoff = 0, one = 1;
-  real_type eps = std::numeric_limits<real_type>::epsilon ();
-
-  if (! iscomplex)
-    {
-      Matrix x = octave_value_extract<Matrix> (arg);
-
-      if (mt.is_unknown ()) // if type is not known, compute it now.
-        arg.matrix_type (mt = MatrixType (x));
-
-      switch (mt.type ())
-        {
-        case MatrixType::Upper:
-        case MatrixType::Diagonal:
-          if (! x.diag ().any_element_is_negative ())
-            {
-              // Do it in real arithmetic.
-              sqrtm_utri_inplace (x);
-              retval = x;
-              retval.matrix_type (mt);
-            }
-          else
-            iscomplex = true;
-          break;
-
-        case MatrixType::Lower:
-          if (! x.diag ().any_element_is_negative ())
-            {
-              x = x.transpose ();
-              sqrtm_utri_inplace (x);
-              retval = x.transpose ();
-              retval.matrix_type (mt);
-            }
-          else
-            iscomplex = true;
-          break;
-
-        default:
-          iscomplex = true;
-          break;
-        }
-
-      if (iscomplex)
-        cutoff = 10 * x.rows () * eps * xnorm (x, one);
-    }
-
-  if (iscomplex)
-    {
-      ComplexMatrix x = octave_value_extract<ComplexMatrix> (arg);
-
-      if (mt.is_unknown ()) // if type is not known, compute it now.
-        arg.matrix_type (mt = MatrixType (x));
-
-      switch (mt.type ())
-        {
-        case MatrixType::Upper:
-        case MatrixType::Diagonal:
-          sqrtm_utri_inplace (x);
-          retval = x;
-          retval.matrix_type (mt);
-          break;
-
-        case MatrixType::Lower:
-          x = x.transpose ();
-          sqrtm_utri_inplace (x);
-          retval = x.transpose ();
-          retval.matrix_type (mt);
-          break;
-
-        default:
-          {
-            ComplexMatrix u;
-
-            do
-              {
-                ComplexSCHUR schur (x, std::string (), true);
-                x = schur.schur_matrix ();
-                u = schur.unitary_matrix ();
-              }
-            while (0); // schur no longer needed.
-
-            sqrtm_utri_inplace (x);
-
-            x = u * x; // original x no longer needed.
-            ComplexMatrix res = xgemm (x, u, blas_no_trans, blas_conj_trans);
-
-            if (cutoff > 0 && xnorm (imag (res), one) <= cutoff)
-              retval = real (res);
-            else
-              retval = res;
-          }
-          break;
-        }
-    }
-
-  return retval;
-}
-
-DEFUN_DLD (sqrtm, args, nargout,
- "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{s} =} sqrtm (@var{A})\n\
-@deftypefnx {Loadable Function} {[@var{s}, @var{error_estimate}] =} sqrtm (@var{A})\n\
-Compute the matrix square root of the square matrix @var{A}.\n\
-\n\
-Ref: N.J. Higham.  @cite{A New sqrtm for @sc{matlab}}.  Numerical\n\
-Analysis Report No. 336, Manchester @nospell{Centre} for Computational\n\
-Mathematics, Manchester, England, January 1999.\n\
-@seealso{expm, logm}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin != 1)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value arg = args(0);
-
-  octave_idx_type n = arg.rows ();
-  octave_idx_type nc = arg.columns ();
-
-  if (n != nc || arg.ndims () > 2)
-    {
-      gripe_square_matrix_required ("sqrtm");
-      return retval;
-    }
-
-  if (nargout > 1)
-    {
-      retval.resize (1, 2);
-      retval(2) = -1.0;
-    }
-
-  if (arg.is_diag_matrix ())
-    // sqrtm of a diagonal matrix is just sqrt.
-    retval(0) = arg.sqrt ();
-  else if (arg.is_single_type ())
-    retval(0) = do_sqrtm<FloatMatrix, FloatComplexMatrix, FloatComplexSCHUR> (arg);
-  else if (arg.is_numeric_type ())
-    retval(0) = do_sqrtm<Matrix, ComplexMatrix, ComplexSCHUR> (arg);
-
-  if (nargout > 1 && ! error_state)
-    {
-      // This corresponds to generic code
-      //
-      //   norm (s*s - x, "fro") / norm (x, "fro");
-
-      octave_value s = retval(0);
-      retval(1) = xfrobnorm (s*s - arg) / xfrobnorm (arg);
-    }
-
-  return retval;
-}
-
-/*
-%!assert (sqrtm (2*ones (2)), ones (2), 3*eps)
-
-## The following two tests are from the reference in the docstring above.
-%!test
-%! x = [0 1; 0 0];
-%! assert (any (isnan (sqrtm (x))(:)));
-
-%!test
-%! x = eye (4);  x(2,2) = x(3,3) = 2^-26;  x(1,4) = 1;
-%! z = eye (4);  z(2,2) = z(3,3) = 2^-13;  z(1,4) = 0.5;
-%! [y, err] = sqrtm (x);
-%! assert (y, z);
-%! assert (err, 0);   ## Yes, this one has to hold exactly
-*/
--- a/src/DLD-FUNCTIONS/str2double.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,406 +0,0 @@
-/*
-
-Copyright (C) 2010-2012 Jaroslav Hajek
-Copyright (C) 2010 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-#include <cctype>
-#include <sstream>
-#include <algorithm>
-
-#include "lo-ieee.h"
-
-#include "Cell.h"
-#include "ov.h"
-#include "defun-dld.h"
-#include "gripes.h"
-#include "utils.h"
-
-static inline bool
-is_imag_unit (int c)
-{ return c == 'i' || c == 'j'; }
-
-static std::istringstream&
-single_num (std::istringstream& is, double& num)
-{
-  char c = is.peek ();
-
-  // Skip spaces.
-  while (isspace (c))
-    {
-      is.get ();
-      c = is.peek ();
-    }
-
-  if (std::toupper (c) == 'I')
-    {
-      // It's infinity.
-      is.get ();
-      char c1 = is.get (), c2 = is.get ();
-      if (std::tolower (c1) == 'n' && std::tolower (c2) == 'f')
-        {
-          num = octave_Inf;
-          is.peek (); // May set EOF bit.
-        }
-      else
-        is.setstate (std::ios::failbit); // indicate that read has failed.
-    }
-  else if (c == 'N')
-    {
-      // It's NA or NaN
-      is.get ();
-      char c1 = is.get ();
-      if (c1 == 'A')
-        {
-          num = octave_NA;
-          is.peek (); // May set EOF bit.
-        }
-      else
-        {
-          char c2 = is.get ();
-          if (c1 == 'a' && c2 == 'N')
-            {
-              num = octave_NaN;
-              is.peek (); // May set EOF bit.
-            }
-          else
-            is.setstate (std::ios::failbit); // indicate that read has failed.
-        }
-    }
-  else
-    is >> num;
-
-  return is;
-}
-
-static std::istringstream&
-extract_num (std::istringstream& is, double& num, bool& imag, bool& have_sign)
-{
-  have_sign = imag = false;
-
-  char c = is.peek ();
-
-  // Skip leading spaces.
-  while (isspace (c))
-    {
-      is.get ();
-      c = is.peek ();
-    }
-
-  bool negative = false;
-
-  // Accept leading sign.
-  if (c == '+' || c == '-')
-    {
-      negative = c == '-';
-      is.get ();
-      c = is.peek ();
-      have_sign = true;
-    }
-
-  // Skip spaces after sign.
-  while (isspace (c))
-    {
-      is.get ();
-      c = is.peek ();
-    }
-
-  // Imaginary number (i*num or just i), or maybe 'inf'.
-  if (c == 'i')
-    {
-      // possible infinity.
-      is.get ();
-      c = is.peek ();
-
-      if (is.eof ())
-        {
-          // just 'i' and string is finished.  Return immediately.
-          imag = true;
-          num = 1.0;
-          if (negative)
-            num = -num;
-          return is;
-        }
-      else
-        { 
-          if (std::tolower (c) != 'n')
-            imag = true;
-          is.unget ();
-        }
-    }
-  else if (c == 'j')
-    imag = true;
-    
-  // It's i*num or just i
-  if (imag)
-    {
-      is.get ();
-      c = is.peek ();
-      // Skip spaces after imaginary unit.
-      while (isspace (c))
-        {
-          is.get ();
-          c = is.peek ();
-        }
-
-      if (c == '*')
-        {
-          // Multiplier follows, we extract it as a number.
-          is.get ();
-          single_num (is, num);
-          if (is.good ())
-            c = is.peek ();
-        }
-      else
-        num = 1.0;
-    }
-  else
-    {
-      // It's num, num*i, or numi.
-      single_num (is, num);
-      if (is.good ())
-        {
-          c = is.peek ();
-
-          // Skip spaces after number.
-          while (isspace (c))
-            {
-              is.get ();
-              c = is.peek ();
-            }
-
-          if (c == '*')
-            {
-              is.get ();
-              c = is.peek ();
-
-              // Skip spaces after operator.
-              while (isspace (c))
-                {
-                  is.get ();
-                  c = is.peek ();
-                }
-
-              if (is_imag_unit (c))
-                {
-                  imag = true;
-                  is.get ();
-                  c = is.peek ();
-                }
-              else
-                is.setstate (std::ios::failbit); // indicate that read has failed.
-            }
-          else if (is_imag_unit (c))
-            {
-              imag = true;
-              is.get ();
-              c = is.peek ();
-            }
-        }
-    }
-
-  if (is.good ())
-    {
-      // Skip trailing spaces.
-      while (isspace (c))
-        {
-          is.get ();
-          c = is.peek ();
-        }
-    }
-
-  if (negative)
-    num = -num;
-
-  return is;
-}
-
-static inline void
-set_component (Complex& c, double num, bool imag)
-{
-#if defined (HAVE_CXX_COMPLEX_SETTERS)
-  if (imag)
-    c.imag (num);
-  else
-    c.real (num);
-#elif defined (HAVE_CXX_COMPLEX_REFERENCE_ACCESSORS)
-  if (imag)
-    c.imag () = num;
-  else
-    c.real () = num;
-#else
-  if (imag)
-    c = Complex (c.real (), num);
-  else
-    c = Complex (num, c.imag ());
-#endif
-}
-
-static Complex
-str2double1 (const std::string& str_arg)
-{
-  Complex val (0.0, 0.0);
-
-  std::string str = str_arg;
-
-  // FIXME -- removing all commas does too much...
-  std::string::iterator se = str.end ();
-  se = std::remove (str.begin (), se, ',');
-  str.erase (se, str.end ());
-  std::istringstream is (str);
-
-  double num;
-  bool i1, i2, s1, s2;
-
-  if (is.eof ())
-    val = octave_NaN;
-  else if (! extract_num (is, num, i1, s1))
-    val = octave_NaN;
-  else
-    {
-      set_component (val, num, i1);
-
-      if (! is.eof ())
-        {
-          if (! extract_num (is, num, i2, s2) || i1 == i2 || ! s2)
-            val = octave_NaN;
-          else
-            set_component (val, num, i2);
-        }
-    }
-
-  return val;
-}
-
-DEFUN_DLD (str2double, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Built-in Function} {} str2double (@var{s})\n\
-Convert a string to a real or complex number.\n\
-\n\
-The string must be in one of the following formats where\n\
-a and b are real numbers and the complex unit is 'i' or 'j':\n\
-\n\
-@itemize\n\
-@item a + bi\n\
-\n\
-@item a + b*i\n\
-\n\
-@item a + i*b\n\
-\n\
-@item bi + a\n\
-\n\
-@item b*i + a\n\
-\n\
-@item i*b + a\n\
-@end itemize\n\
-\n\
-If present, a and/or b are of the form @nospell{[+-]d[,.]d[[eE][+-]d]} where\n\
-the brackets indicate optional arguments and 'd' indicates zero or more\n\
-digits.  The special input values @code{Inf}, @code{NaN}, and @code{NA} are\n\
-also accepted.\n\
-\n\
-@var{s} may also be a character matrix, in which case the conversion is\n\
-repeated for each row.  Or @var{s} may be a cell array of strings, in which\n\
-case each element is converted and an array of the same dimensions is\n\
-returned.\n\
-\n\
-@code{str2double} returns NaN for elements of @var{s} which cannot be\n\
-converted.\n\
-\n\
-@code{str2double} can replace @code{str2num}, and it avoids the security\n\
-risk of using @code{eval} on unknown data.\n\
-@seealso{str2num}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  if (args.length () != 1)
-    print_usage ();
-  else if (args(0).is_string ())
-    {
-      if (args(0).rows () == 1 && args(0).ndims () == 2)
-        {
-          retval = str2double1 (args(0).string_value ());
-        }
-      else
-        {
-          const string_vector sv = args(0).all_strings ();
-          if (! error_state)
-            retval = sv.map<Complex> (str2double1);
-        }
-    }
-  else if (args(0).is_cell ())
-    {
-      const Cell cell = args(0).cell_value ();
-
-      if (! error_state)
-      {
-        ComplexNDArray output (cell.dims (), octave_NaN);
-        for (octave_idx_type i = 0; i < cell.numel (); i++)
-        {
-          if (cell(i).is_string ())
-            output(i) = str2double1 (cell(i).string_value ());
-        }
-        retval = output;
-      }
-    }
-  else
-    retval = NDArray (args(0).dims (), octave_NaN);
-
-
-  return retval;
-}
-
-/*
-%!assert (str2double ("1"), 1)
-%!assert (str2double ("-.1e-5"), -1e-6)
-%!assert (str2double (char ("1", "2 3", "4i")), [1; NaN; 4i])
-%!assert (str2double ("-.1e-5"), -1e-6)
-%!assert (str2double ("1,222.5"), 1222.5)
-%!assert (str2double ("i"), i)
-%!assert (str2double ("2j"), 2i)
-%!assert (str2double ("2 + j"), 2+j)
-%!assert (str2double ("i*2 + 3"), 3+2i)
-%!assert (str2double (".5*i + 3.5"), 3.5+0.5i)
-%!assert (str2double ("1e-3 + i*.25"), 1e-3 + 0.25i)
-%!assert (str2double (["2 + j";"1.25e-3";"-05"]), [2+i; 1.25e-3; -5])
-%!assert (str2double ({"2 + j","1.25e-3","-05"}), [2+i, 1.25e-3, -5])
-%!assert (str2double (1), NaN)
-%!assert (str2double ("1 2 3 4"), NaN)
-%!assert (str2double ("Hello World"), NaN)
-%!assert (str2double ("NaN"), NaN)
-%!assert (str2double ("NA"), NA)
-%!assert (str2double ("Inf"), Inf)
-%!assert (str2double ("iNF"), Inf)
-%!assert (str2double ("-Inf"), -Inf)
-%!assert (str2double ("Inf*i"), complex (0, Inf))
-%!assert (str2double ("iNF*i"), complex (0, Inf))
-%!assert (str2double ("NaN + Inf*i"), complex (NaN, Inf))
-%!assert (str2double ("Inf - Inf*i"), complex (Inf, -Inf))
-%!assert (str2double ("-i*NaN - Inf"), complex (-Inf, -NaN))
-%!assert (str2double ({"abc", "4i"}), [NaN + 0i, 4i])
-%!assert (str2double ({2, "4i"}), [NaN + 0i, 4i])
-%!assert (str2double (zeros (3,1,2)), NaN (3,1,2))
-*/
--- a/src/DLD-FUNCTIONS/strfind.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,415 +0,0 @@
-/*
-
-Copyright (C) 2009-2012 Jaroslav Hajek
-Copyright (C) 2009-2010 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-#include <climits>
-#include <algorithm>
-#include <deque>
-
-#include "Cell.h"
-#include "ov.h"
-#include "defun-dld.h"
-#include "unwind-prot.h"
-#include "gripes.h"
-#include "utils.h"
-
-// This allows safe indexing with char. In C++, char may be (and often is) signed!
-#define ORD(ch) static_cast<unsigned char>(ch)
-#define TABSIZE (UCHAR_MAX + 1)
-
-// This is the quick search algorithm, as described at
-// http://www-igm.univ-mlv.fr/~lecroq/string/node19.html
-static void
-qs_preprocess (const Array<char>& needle,
-               octave_idx_type table[TABSIZE])
-{
-  const char *x = needle.data ();
-  octave_idx_type m = needle.numel ();
-
-   for (octave_idx_type i = 0; i < TABSIZE; i++)
-      table[i] = m + 1;
-   for (octave_idx_type i = 0; i < m; i++)
-      table[ORD(x[i])] = m - i;
-}
-
-
-static Array<octave_idx_type>
-qs_search (const Array<char>& needle,
-           const Array<char>& haystack,
-           const octave_idx_type table[TABSIZE],
-           bool overlaps = true)
-{
-  const char *x = needle.data ();
-  octave_idx_type m = needle.numel ();
-  const char *y = haystack.data ();
-  octave_idx_type n = haystack.numel ();
-
-  // We'll use deque because it typically has the most favorable properties for
-  // the operation we need.
-  std::deque<octave_idx_type> accum;
-  if (m == 1)
-    {
-      // Looking for a single character.
-      for (octave_idx_type i = 0; i < n; i++)
-        {
-          if (y[i] == x[0])
-            accum.push_back (i);
-        }
-    }
-  else if (m == 2)
-    {
-      // Two characters.
-      if (overlaps)
-        {
-          for (octave_idx_type i = 0; i < n-1; i++)
-            {
-              if (y[i] == x[0] && y[i+1] == x[1])
-                accum.push_back (i);
-            }
-        }
-      else
-        {
-          for (octave_idx_type i = 0; i < n-1; i++)
-            {
-              if (y[i] == x[0] && y[i+1] == x[1])
-                accum.push_back (i++);
-            }
-        }
-    }
-  else if (n >= m)
-    {
-      // General case.
-      octave_idx_type j = 0;
-
-      if (overlaps)
-        {
-          while (j < n - m)
-            {
-              if (std::equal (x, x + m, y + j))
-                accum.push_back (j);
-              j += table[ORD(y[j + m])];
-            }
-        }
-      else
-        {
-          while (j < n - m)
-            {
-              if (std::equal (x, x + m, y + j))
-                {
-                  accum.push_back (j);
-                  j += m;
-                }
-              else
-                j += table[ORD(y[j + m])];
-            }
-        }
-
-      if (j == n - m && std::equal (x, x + m, y + j))
-        accum.push_back (j);
-    }
-
-  octave_idx_type nmatch = accum.size ();
-  octave_idx_type one = 1;
-  Array<octave_idx_type> result (dim_vector (std::min (one, nmatch), nmatch));
-  octave_idx_type k = 0;
-  for (std::deque<octave_idx_type>::const_iterator iter = accum.begin ();
-       iter != accum.end (); iter++)
-    {
-      result.xelem (k++) = *iter;
-    }
-
-  return result;
-}
-
-DEFUN_DLD (strfind, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{idx} =} strfind (@var{str}, @var{pattern})\n\
-@deftypefnx {Loadable Function} {@var{idx} =} strfind (@var{cellstr}, @var{pattern})\n\
-Search for @var{pattern} in the string @var{str} and return the\n\
-starting index of every such occurrence in the vector @var{idx}.\n\
-If there is no such occurrence, or if @var{pattern} is longer\n\
-than @var{str}, then @var{idx} is the empty array @code{[]}.\n\
-\n\
-If a cell array of strings @var{cellstr} is specified\n\
-then @var{idx} is a cell array of vectors, as specified\n\
-above.  Examples:\n\
-\n\
-@example\n\
-@group\n\
-strfind (\"abababa\", \"aba\")\n\
-     @result{} [1, 3, 5]\n\
-\n\
-strfind (@{\"abababa\", \"bebebe\", \"ab\"@}, \"aba\")\n\
-     @result{}\n\
-        @{\n\
-          [1,1] =\n\
-\n\
-             1   3   5\n\
-\n\
-          [1,2] = [](1x0)\n\
-          [1,3] = [](1x0)\n\
-        @}\n\
-@end group\n\
-@end example\n\
-@seealso{findstr, strmatch, regexp, regexpi, find}\n\
-@end deftypefn")
-{
-  octave_value retval;
-  int nargin = args.length ();
-  bool overlaps = true;
-
-  if (nargin == 4 && args(2).is_string () && args(3).is_scalar_type ())
-    {
-      std::string opt = args(2).string_value ();
-      if (opt == "overlaps")
-        {
-          overlaps = args(3).bool_value ();
-          nargin = 2;
-        }
-      else
-        {
-          error ("strfind: unknown option: %s", opt.c_str ());
-          return retval;
-        }
-    }
-
-  if (nargin == 2)
-    {
-      octave_value argstr = args(0), argpat = args(1);
-      if (argpat.is_string ())
-        {
-          Array<char> needle = argpat.char_array_value ();
-          OCTAVE_LOCAL_BUFFER (octave_idx_type, table, TABSIZE);
-          qs_preprocess (needle, table);
-
-          if (argstr.is_string ())
-            retval = octave_value (qs_search (needle, argstr.char_array_value (),
-                                              table, overlaps),
-                                   true, true);
-          else if (argstr.is_cell ())
-            {
-              const Cell argsc = argstr.cell_value ();
-              Cell retc (argsc.dims ());
-              octave_idx_type ns = argsc.numel ();
-
-              for (octave_idx_type i = 0; i < ns; i++)
-                {
-                  octave_value argse = argsc(i);
-                  if (argse.is_string ())
-                    retc(i) = octave_value (qs_search (needle, argse.char_array_value (),
-                                                       table, overlaps),
-                                            true, true);
-                  else
-                    {
-                      error ("strfind: each element of CELLSTR must be a string");
-                      break;
-                    }
-                }
-
-              retval = retc;
-            }
-          else
-            error ("strfind: first argument must be a string or cell array of strings");
-        }
-      else if (argpat.is_cell ())
-        retval = do_simple_cellfun (Fstrfind, "strfind", args);
-      else
-        error ("strfind: PATTERN must be a string or cell array of strings");
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!assert (strfind ("abababa", "aba"), [1, 3, 5])
-%!assert (strfind ("abababa", "aba", "overlaps", false), [1, 5])
-%!assert (strfind ({"abababa", "bla", "bla"}, "a"), {[1, 3, 5, 7], 3, 3})
-%!assert (strfind ("Linux _is_ user-friendly. It just isn't ignorant-friendly or idiot-friendly.", "friendly"), [17, 50, 68])
-
-%!error strfind ()
-%!error strfind ("foo", "bar", 1)
-%!error <PATTERN must be a string> strfind ("foo", 100)
-%!error <first argument must be a string> strfind (100, "foo")
-*/
-
-static Array<char>
-qs_replace (const Array<char>& str, const Array<char>& pat,
-            const Array<char>& rep,
-            const octave_idx_type table[TABSIZE],
-            bool overlaps = true)
-{
-  Array<char> ret = str;
-
-  octave_idx_type siz = str.numel (), psiz = pat.numel (), rsiz = rep.numel ();
-
-  if (psiz != 0)
-    {
-      // Look up matches, without overlaps.
-      const Array<octave_idx_type> idx = qs_search (pat, str, table, overlaps);
-      octave_idx_type nidx = idx.numel ();
-
-      if (nidx)
-        {
-          // Compute result size.
-          octave_idx_type retsiz;
-          if (overlaps)
-            {
-              retsiz = 0;
-              // OMG. Is this the "right answer" MW always looks for, or
-              // someone was just lazy?
-              octave_idx_type k = 0;
-              for (octave_idx_type i = 0; i < nidx; i++)
-                {
-                  octave_idx_type j = idx(i);
-                  if (j >= k)
-                    retsiz += j - k;
-                  retsiz += rsiz;
-                  k = j + psiz;
-                }
-
-              retsiz += siz - k;
-            }
-          else
-            retsiz = siz + nidx * (rsiz - psiz);
-
-          ret.clear (dim_vector (1, retsiz));
-          const char *src = str.data (), *reps = rep.data ();
-          char *dest = ret.fortran_vec ();
-
-          octave_idx_type k = 0;
-          for (octave_idx_type i = 0; i < nidx; i++)
-            {
-              octave_idx_type j = idx(i);
-              if (j >= k)
-                dest = std::copy (src + k, src + j, dest);
-              dest = std::copy (reps, reps + rsiz, dest);
-              k = j + psiz;
-            }
-
-          std::copy (src + k, src + siz, dest);
-        }
-    }
-
-  return ret;
-}
-
-DEFUN_DLD (strrep, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} strrep (@var{s}, @var{ptn}, @var{rep})\n\
-@deftypefnx {Loadable Function} {} strrep (@var{s}, @var{ptn}, @var{rep}, \"overlaps\", @var{o})\n\
-Replace all occurrences of the substring @var{ptn} in the string @var{s}\n\
-with the string @var{rep} and return the result.  For example:\n\
-\n\
-@example\n\
-@group\n\
-strrep (\"This is a test string\", \"is\", \"&%$\")\n\
-    @result{}  \"Th&%$ &%$ a test string\"\n\
-@end group\n\
-@end example\n\
-\n\
-@var{s} may also be a cell array of strings, in which case the replacement is\n\
-done for each element and a cell array is returned.\n\
-@seealso{regexprep, strfind, findstr}\n\
-@end deftypefn")
-{
-  octave_value retval;
-  int nargin = args.length ();
-  bool overlaps = true;
-
-  if (nargin == 5 && args(3).is_string () && args(4).is_scalar_type ())
-    {
-      std::string opt = args(3).string_value ();
-      if (opt == "overlaps")
-        {
-          overlaps = args(4).bool_value ();
-          nargin = 3;
-        }
-      else
-        {
-          error ("strrep: unknown option: %s", opt.c_str ());
-          return retval;
-        }
-    }
-
-  if (nargin == 3)
-    {
-      octave_value argstr = args(0), argpat = args(1), argrep = args(2);
-      if (argpat.is_string () && argrep.is_string ())
-        {
-          const Array<char> pat = argpat.char_array_value ();
-          const Array<char> rep = argrep.char_array_value ();
-
-          OCTAVE_LOCAL_BUFFER (octave_idx_type, table, TABSIZE);
-          qs_preprocess (pat, table);
-
-          if (argstr.is_string ())
-            retval = qs_replace (argstr.char_array_value (), pat, rep, table, overlaps);
-          else if (argstr.is_cell ())
-            {
-              const Cell argsc = argstr.cell_value ();
-              Cell retc (argsc.dims ());
-              octave_idx_type ns = argsc.numel ();
-
-              for (octave_idx_type i = 0; i < ns; i++)
-                {
-                  octave_value argse = argsc(i);
-                  if (argse.is_string ())
-                    retc(i) = qs_replace (argse.char_array_value (), pat, rep, table, overlaps);
-                  else
-                    {
-                      error ("strrep: each element of S must be a string");
-                      break;
-                    }
-                }
-
-              retval = retc;
-            }
-          else
-            error ("strrep: S must be a string or cell array of strings");
-        }
-      else if (argpat.is_cell () || argrep.is_cell ())
-        retval = do_simple_cellfun (Fstrrep, "strrep", args);
-      else
-        error ("strrep: PTN and REP arguments must be strings or cell arrays of strings");
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!assert (strrep ("This is a test string", "is", "&%$"),
-%!                "Th&%$ &%$ a test string")
-%!assert (strrep ("abababc", "abab", "xyz"), "xyzxyzc")
-%!assert (strrep ("abababc", "abab", "xyz", "overlaps", false), "xyzabc")
-
-%!error strrep ()
-%!error strrep ("foo", "bar", 3, 4)
-*/
--- a/src/DLD-FUNCTIONS/sub2ind.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,209 +0,0 @@
-/*
-
-Copyright (C) 2009-2012 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "quit.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-
-
-static dim_vector
-get_dim_vector (const octave_value& val, const char *name)
-{
-  RowVector dimsv = val.row_vector_value (false, true);
-  dim_vector dv;
-  octave_idx_type n = dimsv.length ();
-
-  if (n < 1)
-    error ("%s: dimension vector DIMS must not be empty", name);
-  else
-    {
-      dv.resize (std::max (n, static_cast<octave_idx_type> (2)));
-      dv(1) = 1;
-      for (octave_idx_type i = 0; i < n; i++)
-        {
-          octave_idx_type ii = dimsv(i);
-          if (ii == dimsv(i) && ii >= 0)
-            dv(i) = ii;
-          else
-            {
-              error ("%s: dimension vector DIMS must contain integers", name);
-              break;
-            }
-        }
-    }
-
-  return dv;
-}
-
-DEFUN_DLD (sub2ind, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Function File} {@var{ind} =} sub2ind (@var{dims}, @var{i}, @var{j})\n\
-@deftypefnx {Function File} {@var{ind} =} sub2ind (@var{dims}, @var{s1}, @var{s2}, @dots{}, @var{sN})\n\
-Convert subscripts to a linear index.\n\
-\n\
-The following example shows how to convert the two-dimensional\n\
-index @code{(2,3)} of a 3-by-3 matrix to a linear index.  The matrix\n\
-is linearly indexed moving from one column to next, filling up\n\
-all rows in each column.\n\
-\n\
-@example\n\
-@group\n\
-linear_index = sub2ind ([3, 3], 2, 3)\n\
-@result{} 8\n\
-@end group\n\
-@end example\n\
-@seealso{ind2sub}\n\
-@end deftypefn")
-{
-  int nargin = args.length ();
-  octave_value retval;
-
-  if (nargin < 2)
-    print_usage ();
-  else
-    {
-      dim_vector dv = get_dim_vector (args(0), "sub2ind");
-      Array<idx_vector> idxa (dim_vector (nargin-1, 1));
-
-      if (! error_state)
-        {
-          dv = dv.redim (nargin - 1);
-          for (int j = 0; j < nargin - 1; j++)
-            {
-              if (args(j+1).is_numeric_type ())
-                {
-                  idxa(j) = args(j+1).index_vector ();
-                  if (error_state)
-                    break;
-                  else if (j > 0 && args(j+1).dims () != args(1).dims ())
-                    error ("sub2ind: all subscripts must be of the same size");
-                }
-              else
-                error ("sub2ind: subscripts must be numeric");
-
-              if (error_state)
-                break;
-            }
-        }
-
-      if (! error_state)
-        {
-          idx_vector idx = sub2ind (dv, idxa);
-          retval = idx;
-        }
-    }
-
-  return retval;
-}
-
-/*
-## Test evaluation
-%!test
-%! s1 = [ 1   1   1   1 ; 2   2   2   2 ];
-%! s2 = [ 1   1   2   2 ; 1   1   2   2 ];
-%! s3 = [ 1   2   1   2 ; 1   2   1   2 ];
-%! in = [ 1 101  11 111 ; 2 102  12 112 ];
-%! assert (sub2ind ([10 10 10], s1, s2, s3), in);
-
-# Test low index
-%!assert (sub2ind ([10 10 10], 1, 1, 1), 1)
-%!error <subscript indices> sub2ind ([10 10 10], 0, 1, 1)
-%!error <subscript indices> sub2ind ([10 10 10], 1, 0, 1)
-%!error <subscript indices> sub2ind ([10 10 10], 1, 1, 0)
-
-# Test high index
-%!assert (sub2ind ([10 10 10], 10, 10, 10), 1000)
-%!error <index out of range> sub2ind ([10 10 10], 11, 10, 10)
-%!error <index out of range> sub2ind ([10 10 10], 10, 11, 10)
-%!error <index out of range> sub2ind ([10 10 10], 10, 10, 11)
-
-# Test high index in the trailing dimensions
-%!assert (sub2ind ([10, 1], 2, 1, 1), 2)
-%!error <index out of range> sub2ind ([10, 1], 1, 2, 1)
-%!error <index out of range> sub2ind ([10, 1], 1, 1, 2)
-%!assert (sub2ind ([10 10], 2, 2, 1), 12)
-%!error <index out of range> sub2ind ([10 10], 2, 1, 2)
-%!error <index out of range> sub2ind ([10 10], 1, 2, 2)
-
-# Test handling of empty arguments
-%!assert (sub2ind ([10 10], zeros (0,0), zeros (0,0)), zeros (0,0))
-%!assert (sub2ind ([10 10], zeros (2,0), zeros (2,0)), zeros (2,0))
-%!assert (sub2ind ([10 10], zeros (0,2), zeros (0,2)), zeros (0,2))
-%!error <all subscripts .* same size> sub2ind ([10 10 10], zeros (0,2), zeros (2,0))
-
-# Test handling of arguments of different size
-%!error <all subscripts .* same size> sub2ind ([10 10], ones (1,2), ones (1,3))
-%!error <all subscripts .* same size> sub2ind ([10 10], ones (1,2), ones (2,1))
-
-## Test input validation
-%!error <dimension vector> sub2ind ([10 10.5], 1, 1)
-%!error <subscript indices> sub2ind ([10 10], 1.5, 1)
-%!error <subscript indices> sub2ind ([10 10], 1, 1.5)
-*/
-
-DEFUN_DLD (ind2sub, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Function File} {[@var{s1}, @var{s2}, @dots{}, @var{sN}] =} ind2sub (@var{dims}, @var{ind})\n\
-Convert a linear index to subscripts.\n\
-\n\
-The following example shows how to convert the linear index @code{8}\n\
-in a 3-by-3 matrix into a subscript.  The matrix is linearly indexed\n\
-moving from one column to next, filling up all rows in each column.\n\
-\n\
-@example\n\
-@group\n\
-[r, c] = ind2sub ([3, 3], 8)\n\
-    @result{} r =  2\n\
-    @result{} c =  3\n\
-@end group\n\
-@end example\n\
-@seealso{sub2ind}\n\
-@end deftypefn")
-{
-  int nargin = args.length ();
-  octave_value_list retval;
-
-  if (nargin != 2)
-    print_usage ();
-  else
-    {
-      dim_vector dv = get_dim_vector (args(0), "ind2sub");
-      idx_vector idx = args(1).index_vector ();
-      if (! error_state)
-        {
-          if (nargout > dv.length ())
-            dv = dv.redim (nargout);
-
-          Array<idx_vector> idxa = ind2sub (dv, idx);
-          retval = Array<octave_value> (idxa);
-        }
-    }
-
-  return retval;
-}
--- a/src/DLD-FUNCTIONS/svd.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,423 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "CmplxSVD.h"
-#include "dbleSVD.h"
-#include "fCmplxSVD.h"
-#include "floatSVD.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "pr-output.h"
-#include "utils.h"
-#include "variables.h"
-
-static int Vsvd_driver = SVD::GESVD;
-
-DEFUN_DLD (svd, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{s} =} svd (@var{A})\n\
-@deftypefnx {Loadable Function} {[@var{U}, @var{S}, @var{V}] =} svd (@var{A})\n\
-@deftypefnx {Loadable Function} {[@var{U}, @var{S}, @var{V}] =} svd (@var{A}, @var{econ})\n\
-@cindex singular value decomposition\n\
-Compute the singular value decomposition of @var{A}\n\
-@tex\n\
-$$\n\
- A = U S V^{\\dagger}\n\
-$$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-A = U*S*V'\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-\n\
-The function @code{svd} normally returns only the vector of singular values.\n\
-When called with three return values, it computes\n\
-@tex\n\
-$U$, $S$, and $V$.\n\
-@end tex\n\
-@ifnottex\n\
-@var{U}, @var{S}, and @var{V}.\n\
-@end ifnottex\n\
-For example,\n\
-\n\
-@example\n\
-svd (hilb (3))\n\
-@end example\n\
-\n\
-@noindent\n\
-returns\n\
-\n\
-@example\n\
-@group\n\
-ans =\n\
-\n\
-  1.4083189\n\
-  0.1223271\n\
-  0.0026873\n\
-@end group\n\
-@end example\n\
-\n\
-@noindent\n\
-and\n\
-\n\
-@example\n\
-[u, s, v] = svd (hilb (3))\n\
-@end example\n\
-\n\
-@noindent\n\
-returns\n\
-\n\
-@example\n\
-@group\n\
-u =\n\
-\n\
-  -0.82704   0.54745   0.12766\n\
-  -0.45986  -0.52829  -0.71375\n\
-  -0.32330  -0.64901   0.68867\n\
-\n\
-s =\n\
-\n\
-  1.40832  0.00000  0.00000\n\
-  0.00000  0.12233  0.00000\n\
-  0.00000  0.00000  0.00269\n\
-\n\
-v =\n\
-\n\
-  -0.82704   0.54745   0.12766\n\
-  -0.45986  -0.52829  -0.71375\n\
-  -0.32330  -0.64901   0.68867\n\
-@end group\n\
-@end example\n\
-\n\
-If given a second argument, @code{svd} returns an economy-sized\n\
-decomposition, eliminating the unnecessary rows or columns of @var{U} or\n\
-@var{V}.\n\
-@seealso{svd_driver, svds, eig}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  int nargin = args.length ();
-
-  if (nargin < 1 || nargin > 2 || nargout == 2 || nargout > 3)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value arg = args(0);
-
-  octave_idx_type nr = arg.rows ();
-  octave_idx_type nc = arg.columns ();
-
-  if (arg.ndims () != 2)
-    {
-      error ("svd: A must be a 2-D matrix");
-      return retval;
-    }
-
-  bool isfloat = arg.is_single_type ();
-
-  SVD::type type = ((nargout == 0 || nargout == 1)
-                    ? SVD::sigma_only
-                    : (nargin == 2) ? SVD::economy : SVD::std);
-
-  SVD::driver driver = static_cast<SVD::driver> (Vsvd_driver);
-
-  if (nr == 0 || nc == 0)
-    {
-      if (isfloat)
-        {
-          switch (type)
-            {
-            case SVD::std:
-              retval(2) = FloatDiagMatrix (nc, nc, 1.0f);
-              retval(1) = FloatMatrix (nr, nc);
-              retval(0) = FloatDiagMatrix (nr, nr, 1.0f);
-              break;
-            case SVD::economy:
-              retval(2) = FloatDiagMatrix (0, nc, 1.0f);
-              retval(1) = FloatMatrix (0, 0);
-              retval(0) = FloatDiagMatrix (nr, 0, 1.0f);
-              break;
-            case SVD::sigma_only: default:
-              retval(0) = FloatMatrix (0, 1);
-              break;
-            }
-        }
-      else
-        {
-          switch (type)
-            {
-            case SVD::std:
-              retval(2) = DiagMatrix (nc, nc, 1.0);
-              retval(1) = Matrix (nr, nc);
-              retval(0) = DiagMatrix (nr, nr, 1.0);
-              break;
-            case SVD::economy:
-              retval(2) = DiagMatrix (0, nc, 1.0);
-              retval(1) = Matrix (0, 0);
-              retval(0) = DiagMatrix (nr, 0, 1.0);
-              break;
-            case SVD::sigma_only: default:
-              retval(0) = Matrix (0, 1);
-              break;
-            }
-        }
-    }
-  else
-    {
-      if (isfloat)
-        {
-          if (arg.is_real_type ())
-            {
-              FloatMatrix tmp = arg.float_matrix_value ();
-
-              if (! error_state)
-                {
-                  if (tmp.any_element_is_inf_or_nan ())
-                    {
-                      error ("svd: cannot take SVD of matrix containing Inf or NaN values");
-                      return retval;
-                    }
-
-                  FloatSVD result (tmp, type, driver);
-
-                  FloatDiagMatrix sigma = result.singular_values ();
-
-                  if (nargout == 0 || nargout == 1)
-                    {
-                      retval(0) = sigma.diag ();
-                    }
-                  else
-                    {
-                      retval(2) = result.right_singular_matrix ();
-                      retval(1) = sigma;
-                      retval(0) = result.left_singular_matrix ();
-                    }
-                }
-            }
-          else if (arg.is_complex_type ())
-            {
-              FloatComplexMatrix ctmp = arg.float_complex_matrix_value ();
-
-              if (! error_state)
-                {
-                  if (ctmp.any_element_is_inf_or_nan ())
-                    {
-                      error ("svd: cannot take SVD of matrix containing Inf or NaN values");
-                      return retval;
-                    }
-
-                  FloatComplexSVD result (ctmp, type, driver);
-
-                  FloatDiagMatrix sigma = result.singular_values ();
-
-                  if (nargout == 0 || nargout == 1)
-                    {
-                      retval(0) = sigma.diag ();
-                    }
-                  else
-                    {
-                      retval(2) = result.right_singular_matrix ();
-                      retval(1) = sigma;
-                      retval(0) = result.left_singular_matrix ();
-                    }
-                }
-            }
-        }
-      else
-        {
-          if (arg.is_real_type ())
-            {
-              Matrix tmp = arg.matrix_value ();
-
-              if (! error_state)
-                {
-                  if (tmp.any_element_is_inf_or_nan ())
-                    {
-                      error ("svd: cannot take SVD of matrix containing Inf or NaN values");
-                      return retval;
-                    }
-
-                  SVD result (tmp, type, driver);
-
-                  DiagMatrix sigma = result.singular_values ();
-
-                  if (nargout == 0 || nargout == 1)
-                    {
-                      retval(0) = sigma.diag ();
-                    }
-                  else
-                    {
-                      retval(2) = result.right_singular_matrix ();
-                      retval(1) = sigma;
-                      retval(0) = result.left_singular_matrix ();
-                    }
-                }
-            }
-          else if (arg.is_complex_type ())
-            {
-              ComplexMatrix ctmp = arg.complex_matrix_value ();
-
-              if (! error_state)
-                {
-                  if (ctmp.any_element_is_inf_or_nan ())
-                    {
-                      error ("svd: cannot take SVD of matrix containing Inf or NaN values");
-                      return retval;
-                    }
-
-                  ComplexSVD result (ctmp, type, driver);
-
-                  DiagMatrix sigma = result.singular_values ();
-
-                  if (nargout == 0 || nargout == 1)
-                    {
-                      retval(0) = sigma.diag ();
-                    }
-                  else
-                    {
-                      retval(2) = result.right_singular_matrix ();
-                      retval(1) = sigma;
-                      retval(0) = result.left_singular_matrix ();
-                    }
-                }
-            }
-          else
-            {
-              gripe_wrong_type_arg ("svd", arg);
-              return retval;
-            }
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!assert (svd ([1, 2; 2, 1]), [3; 1], sqrt (eps))
-
-%!test
-%! [u, s, v] = svd ([1, 2; 2, 1]);
-%! x = 1 / sqrt (2);
-%! assert (u, [-x, -x; -x, x], sqrt (eps));
-%! assert (s, [3, 0; 0, 1], sqrt (eps));
-%! assert (v, [-x, x; -x, -x], sqrt (eps));
-
-%!test
-%! a = [1, 2, 3; 4, 5, 6];
-%! [u, s, v] = svd (a);
-%! assert (u * s * v', a, sqrt (eps));
-
-%!test
-%! a = [1, 2; 3, 4; 5, 6];
-%! [u, s, v] = svd (a);
-%! assert (u * s * v', a, sqrt (eps));
-
-%!test
-%! a = [1, 2, 3; 4, 5, 6];
-%! [u, s, v] = svd (a, 1);
-%! assert (u * s * v', a, sqrt (eps));
-
-%!test
-%! a = [1, 2; 3, 4; 5, 6];
-%! [u, s, v] = svd (a, 1);
-%! assert (u * s * v', a, sqrt (eps));
-
-%!assert (svd (single ([1, 2; 2, 1])), single ([3; 1]), sqrt (eps ("single")))
-
-%!test
-%! [u, s, v] = svd (single ([1, 2; 2, 1]));
-%! x = single (1 / sqrt (2));
-%! assert (u, [-x, -x; -x, x], sqrt (eps ("single")));
-%! assert (s, single ([3, 0; 0, 1]), sqrt (eps ("single")));
-%! assert (v, [-x, x; -x, -x], sqrt (eps ("single")));
-
-%!test
-%! a = single ([1, 2, 3; 4, 5, 6]);
-%! [u, s, v] = svd (a);
-%! assert (u * s * v', a, sqrt (eps ("single")));
-
-%!test
-%! a = single ([1, 2; 3, 4; 5, 6]);
-%! [u, s, v] = svd (a);
-%! assert (u * s * v', a, sqrt (eps ("single")));
-
-%!test
-%! a = single ([1, 2, 3; 4, 5, 6]);
-%! [u, s, v] = svd (a, 1);
-%! assert (u * s * v', a, sqrt (eps ("single")));
-
-%!test
-%! a = single ([1, 2; 3, 4; 5, 6]);
-%! [u, s, v] = svd (a, 1);
-%! assert (u * s * v', a, sqrt (eps ("single")));
-
-%!test
-%! a = zeros (0, 5);
-%! [u, s, v] = svd (a);
-%! assert (size (u), [0, 0]);
-%! assert (size (s), [0, 5]);
-%! assert (size (v), [5, 5]);
-
-%!test
-%! a = zeros (5, 0);
-%! [u, s, v] = svd (a, 1);
-%! assert (size (u), [5, 0]);
-%! assert (size (s), [0, 0]);
-%! assert (size (v), [0, 0]);
-
-%!error svd ()
-%!error svd ([1, 2; 4, 5], 2, 3)
-%!error [u, v] = svd ([1, 2; 3, 4])
-*/
-
-DEFUN_DLD (svd_driver, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{val} =} svd_driver ()\n\
-@deftypefnx {Loadable Function} {@var{old_val} =} svd_driver (@var{new_val})\n\
-@deftypefnx {Loadable Function} {} svd_driver (@var{new_val}, \"local\")\n\
-Query or set the underlying @sc{lapack} driver used by @code{svd}.\n\
-Currently recognized values are \"gesvd\" and \"gesdd\".  The default\n\
-is \"gesvd\".\n\
-\n\
-When called from inside a function with the \"local\" option, the variable is\n\
-changed locally for the function and any subroutines it calls.  The original\n\
-variable value is restored when exiting the function.\n\
-@seealso{svd}\n\
-@end deftypefn")
-{
-  static const char *driver_names[] = { "gesvd", "gesdd", 0 };
-
-  return SET_INTERNAL_VARIABLE_CHOICES (svd_driver, driver_names);
-}
--- a/src/DLD-FUNCTIONS/syl.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,218 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-// Author: A. S. Hodel <scotte@eng.auburn.edu>
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "utils.h"
-
-DEFUN_DLD (syl, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{x} =} syl (@var{A}, @var{B}, @var{C})\n\
-Solve the Sylvester equation\n\
-@tex\n\
-$$\n\
- A X + X B + C = 0\n\
-$$\n\
-@end tex\n\
-@ifnottex\n\
-\n\
-@example\n\
-A X + X B + C = 0\n\
-@end example\n\
-\n\
-@end ifnottex\n\
-using standard @sc{lapack} subroutines.  For example:\n\
-\n\
-@example\n\
-@group\n\
-syl ([1, 2; 3, 4], [5, 6; 7, 8], [9, 10; 11, 12])\n\
-   @result{} [ -0.50000, -0.66667; -0.66667, -0.50000 ]\n\
-@end group\n\
-@end example\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin != 3 || nargout > 1)
-    {
-      print_usage ();
-      return retval;
-    }
-
-  octave_value arg_a = args(0);
-  octave_value arg_b = args(1);
-  octave_value arg_c = args(2);
-
-  octave_idx_type a_nr = arg_a.rows ();
-  octave_idx_type a_nc = arg_a.columns ();
-
-  octave_idx_type b_nr = arg_b.rows ();
-  octave_idx_type b_nc = arg_b.columns ();
-
-  octave_idx_type c_nr = arg_c.rows ();
-  octave_idx_type c_nc = arg_c.columns ();
-
-  int arg_a_is_empty = empty_arg ("syl", a_nr, a_nc);
-  int arg_b_is_empty = empty_arg ("syl", b_nr, b_nc);
-  int arg_c_is_empty = empty_arg ("syl", c_nr, c_nc);
-
-  bool isfloat = arg_a.is_single_type () || arg_b.is_single_type () ||
-    arg_c.is_single_type ();
-
-  if (arg_a_is_empty > 0 && arg_b_is_empty > 0 && arg_c_is_empty > 0)
-    if (isfloat)
-      return octave_value (FloatMatrix ());
-    else
-      return octave_value (Matrix ());
-  else if (arg_a_is_empty || arg_b_is_empty || arg_c_is_empty)
-    return retval;
-
-  // Arguments are not empty, so check for correct dimensions.
-
-  if (a_nr != a_nc || b_nr != b_nc)
-    {
-      gripe_square_matrix_required ("syl: first two parameters:");
-      return retval;
-    }
-  else if (a_nr != c_nr || b_nr != c_nc)
-    {
-      gripe_nonconformant ();
-      return retval;
-    }
-
-  // Dimensions look o.k., let's solve the problem.
-  if (isfloat)
-    {
-      if (arg_a.is_complex_type ()
-          || arg_b.is_complex_type ()
-          || arg_c.is_complex_type ())
-        {
-          // Do everything in complex arithmetic;
-
-          FloatComplexMatrix ca = arg_a.float_complex_matrix_value ();
-
-          if (error_state)
-            return retval;
-
-          FloatComplexMatrix cb = arg_b.float_complex_matrix_value ();
-
-          if (error_state)
-            return retval;
-
-          FloatComplexMatrix cc = arg_c.float_complex_matrix_value ();
-
-          if (error_state)
-            return retval;
-
-          retval = Sylvester (ca, cb, cc);
-        }
-      else
-        {
-          // Do everything in real arithmetic.
-
-          FloatMatrix ca = arg_a.float_matrix_value ();
-
-          if (error_state)
-            return retval;
-
-          FloatMatrix cb = arg_b.float_matrix_value ();
-
-          if (error_state)
-            return retval;
-
-          FloatMatrix cc = arg_c.float_matrix_value ();
-
-          if (error_state)
-            return retval;
-
-          retval = Sylvester (ca, cb, cc);
-        }
-    }
-  else
-    {
-      if (arg_a.is_complex_type ()
-          || arg_b.is_complex_type ()
-          || arg_c.is_complex_type ())
-        {
-          // Do everything in complex arithmetic;
-
-          ComplexMatrix ca = arg_a.complex_matrix_value ();
-
-          if (error_state)
-            return retval;
-
-          ComplexMatrix cb = arg_b.complex_matrix_value ();
-
-          if (error_state)
-            return retval;
-
-          ComplexMatrix cc = arg_c.complex_matrix_value ();
-
-          if (error_state)
-            return retval;
-
-          retval = Sylvester (ca, cb, cc);
-        }
-      else
-        {
-          // Do everything in real arithmetic.
-
-          Matrix ca = arg_a.matrix_value ();
-
-          if (error_state)
-            return retval;
-
-          Matrix cb = arg_b.matrix_value ();
-
-          if (error_state)
-            return retval;
-
-          Matrix cc = arg_c.matrix_value ();
-
-          if (error_state)
-            return retval;
-
-          retval = Sylvester (ca, cb, cc);
-        }
-    }
-
-  return retval;
-}
-
-/*
-%!assert (syl ([1, 2; 3, 4], [5, 6; 7, 8], [9, 10; 11, 12]), [-1/2, -2/3; -2/3, -1/2], sqrt (eps))
-%!assert (syl (single ([1, 2; 3, 4]), single ([5, 6; 7, 8]), single ([9, 10; 11, 12])), single ([-1/2, -2/3; -2/3, -1/2]), sqrt (eps ("single")))
-
-%!error syl ()
-%!error syl (1, 2, 3, 4)
-%!error <must be a square matrix> syl ([1, 2; 3, 4], [1, 2, 3; 4, 5, 6], [4, 3])
-*/
--- a/src/DLD-FUNCTIONS/time.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,539 +0,0 @@
-/*
-
-Copyright (C) 1996-2012 John W. Eaton
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string>
-
-#include "defun-dld.h"
-#include "error.h"
-#include "oct-map.h"
-#include "oct-time.h"
-#include "ov.h"
-#include "oct-obj.h"
-
-// Date and time functions.
-
-static octave_scalar_map
-mk_tm_map (const octave_base_tm& t)
-{
-  octave_scalar_map m;
-
-  m.assign ("usec", static_cast<double> (t.usec ()));
-  m.assign ("sec", static_cast<double> (t.sec ()));
-  m.assign ("min", static_cast<double> (t.min ()));
-  m.assign ("hour", static_cast<double> (t.hour ()));
-  m.assign ("mday", static_cast<double> (t.mday ()));
-  m.assign ("mon", static_cast<double> (t.mon ()));
-  m.assign ("year", static_cast<double> (t.year ()));
-  m.assign ("wday", static_cast<double> (t.wday ()));
-  m.assign ("yday", static_cast<double> (t.yday ()));
-  m.assign ("isdst", static_cast<double> (t.isdst ()));
-  m.assign ("zone", t.zone ());
-
-  return m;
-}
-
-static inline int
-intfield (const octave_scalar_map& m, const std::string& k)
-{
-  int retval = 0;
-
-  octave_value v = m.getfield (k);
-
-  if (! v.is_empty ())
-    retval = v.int_value ();
-
-  return retval;
-}
-
-static inline std::string
-stringfield (const octave_scalar_map& m, const std::string& k)
-{
-  std::string retval;
-
-  octave_value v = m.getfield (k);
-
-  if (! v.is_empty ())
-    retval = v.string_value ();
-
-  return retval;
-}
-
-static octave_base_tm
-extract_tm (const octave_scalar_map& m)
-{
-  octave_base_tm tm;
-
-  tm.usec (intfield (m, "usec"));
-  tm.sec (intfield (m, "sec"));
-  tm.min (intfield (m, "min"));
-  tm.hour (intfield (m, "hour"));
-  tm.mday (intfield (m, "mday"));
-  tm.mon (intfield (m, "mon"));
-  tm.year (intfield (m, "year"));
-  tm.wday (intfield (m, "wday"));
-  tm.yday (intfield (m, "yday"));
-  tm.isdst (intfield (m, "isdst"));
-  tm.zone (stringfield (m, "zone"));
-
-  return tm;
-}
-
-DEFUN_DLD (time, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{seconds} =} time ()\n\
-Return the current time as the number of seconds since the epoch.  The\n\
-epoch is referenced to 00:00:00 CUT (Coordinated Universal Time) 1 Jan\n\
-1970.  For example, on Monday February 17, 1997 at 07:15:06 CUT, the\n\
-value returned by @code{time} was 856163706.\n\
-@seealso{strftime, strptime, localtime, gmtime, mktime, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  if (args.length () == 0)
-    retval = octave_time ();
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!assert (time () > 0)
-*/
-
-DEFUN_DLD (gmtime, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{tm_struct} =} gmtime (@var{t})\n\
-Given a value returned from @code{time}, or any non-negative integer,\n\
-return a time structure corresponding to CUT (Coordinated Universal Time).\n\
-For example:\n\
-\n\
-@example\n\
-@group\n\
-gmtime (time ())\n\
-     @result{} @{\n\
-           usec = 0\n\
-           sec = 6\n\
-           min = 15\n\
-           hour = 7\n\
-           mday = 17\n\
-           mon = 1\n\
-           year = 97\n\
-           wday = 1\n\
-           yday = 47\n\
-           isdst = 0\n\
-           zone = CST\n\
-        @}\n\
-@end group\n\
-@end example\n\
-@seealso{strftime, strptime, localtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  if (args.length () == 1)
-    {
-      double tmp = args(0).double_value ();
-
-      if (! error_state)
-        retval = octave_value (mk_tm_map (octave_gmtime (tmp)));
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!test
-%! ts = gmtime (time ());
-%! assert (isstruct (ts));
-%! assert (isfield (ts, "usec"));
-%! assert (isfield (ts, "year"));
-%! assert (isfield (ts, "mon"));
-%! assert (isfield (ts, "mday"));
-%! assert (isfield (ts, "sec"));
-%! assert (isfield (ts, "min"));
-%! assert (isfield (ts, "wday"));
-%! assert (isfield (ts, "hour"));
-%! assert (isfield (ts, "isdst"));
-%! assert (isfield (ts, "yday"));
-
-%!error gmtime ()
-%!error gmtime (1, 2)
-*/
-
-DEFUN_DLD (localtime, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{tm_struct} =} localtime (@var{t})\n\
-Given a value returned from @code{time}, or any non-negative integer,\n\
-return a time structure corresponding to the local time zone.\n\
-\n\
-@example\n\
-@group\n\
-localtime (time ())\n\
-     @result{} @{\n\
-           usec = 0\n\
-           sec = 6\n\
-           min = 15\n\
-           hour = 1\n\
-           mday = 17\n\
-           mon = 1\n\
-           year = 97\n\
-           wday = 1\n\
-           yday = 47\n\
-           isdst = 0\n\
-           zone = CST\n\
-        @}\n\
-@end group\n\
-@end example\n\
-@seealso{strftime, strptime, gmtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  if (args.length () == 1)
-    {
-      double tmp = args(0).double_value ();
-
-      if (! error_state)
-        retval = octave_value (mk_tm_map (octave_localtime (tmp)));
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!test
-%! ts = localtime (time ());
-%! assert (isstruct (ts));
-%! assert (isfield (ts, "usec"));
-%! assert (isfield (ts, "year"));
-%! assert (isfield (ts, "mon"));
-%! assert (isfield (ts, "mday"));
-%! assert (isfield (ts, "sec"));
-%! assert (isfield (ts, "min"));
-%! assert (isfield (ts, "wday"));
-%! assert (isfield (ts, "hour"));
-%! assert (isfield (ts, "isdst"));
-%! assert (isfield (ts, "yday"));
-
-%!error localtime ()
-%!error localtime (1, 2)
-*/
-
-DEFUN_DLD (mktime, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{seconds} =} mktime (@var{tm_struct})\n\
-Convert a time structure corresponding to the local time to the number\n\
-of seconds since the epoch.  For example:\n\
-\n\
-@example\n\
-@group\n\
-mktime (localtime (time ()))\n\
-     @result{} 856163706\n\
-@end group\n\
-@end example\n\
-@seealso{strftime, strptime, localtime, gmtime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  if (args.length () == 1)
-    {
-      octave_scalar_map map = args(0).scalar_map_value ();
-
-      if (! error_state)
-        {
-          octave_base_tm tm = extract_tm (map);
-
-          if (! error_state)
-            retval = octave_time (tm);
-          else
-            error ("mktime: invalid TM_STRUCT argument");
-        }
-      else
-        error ("mktime: TM_STRUCT argument must be a structure");
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!test
-%! t = time ();
-%! assert (fix (mktime (localtime (t))) == fix (t));
-
-## These tests fail on systems with mktime functions of limited
-## intelligence:
-%!assert (datestr (datenum (1969, 1, 1), 0), "01-Jan-1969 00:00:00")
-%!assert (datestr (datenum (1901, 1, 1), 0), "01-Jan-1901 00:00:00")
-%!assert (datestr (datenum (1795, 1, 1), 0), "01-Jan-1795 00:00:00")
-
-%!error mktime ()
-%!error mktime (1, 2, 3)
-*/
-
-DEFUN_DLD (strftime, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} strftime (@var{fmt}, @var{tm_struct})\n\
-Format the time structure @var{tm_struct} in a flexible way using the\n\
-format string @var{fmt} that contains @samp{%} substitutions\n\
-similar to those in @code{printf}.  Except where noted, substituted\n\
-fields have a fixed size; numeric fields are padded if necessary.\n\
-Padding is with zeros by default; for fields that display a single\n\
-number, padding can be changed or inhibited by following the @samp{%}\n\
-with one of the modifiers described below.  Unknown field specifiers are\n\
-copied as normal characters.  All other characters are copied to the\n\
-output without change.  For example:\n\
-\n\
-@example\n\
-@group\n\
-strftime (\"%r (%Z) %A %e %B %Y\", localtime (time ()))\n\
-      @result{} \"01:15:06 AM (CST) Monday 17 February 1997\"\n\
-@end group\n\
-@end example\n\
-\n\
-Octave's @code{strftime} function supports a superset of the ANSI C\n\
-field specifiers.\n\
-\n\
-@noindent\n\
-Literal character fields:\n\
-\n\
-@table @code\n\
-@item %%\n\
-% character.\n\
-\n\
-@item %n\n\
-Newline character.\n\
-\n\
-@item %t\n\
-Tab character.\n\
-@end table\n\
-\n\
-@noindent\n\
-Numeric modifiers (a nonstandard extension):\n\
-\n\
-@table @code\n\
-@item - (dash)\n\
-Do not pad the field.\n\
-\n\
-@item _ (underscore)\n\
-Pad the field with spaces.\n\
-@end table\n\
-\n\
-@noindent\n\
-Time fields:\n\
-\n\
-@table @code\n\
-@item %H\n\
-Hour (00-23).\n\
-\n\
-@item %I\n\
-Hour (01-12).\n\
-\n\
-@item %k\n\
-Hour (0-23).\n\
-\n\
-@item %l\n\
-Hour (1-12).\n\
-\n\
-@item %M\n\
-Minute (00-59).\n\
-\n\
-@item %p\n\
-Locale's AM or PM.\n\
-\n\
-@item %r\n\
-Time, 12-hour (hh:mm:ss [AP]M).\n\
-\n\
-@item %R\n\
-Time, 24-hour (hh:mm).\n\
-\n\
-@item %s\n\
-Time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension).\n\
-\n\
-@item %S\n\
-Second (00-61).\n\
-\n\
-@item %T\n\
-Time, 24-hour (hh:mm:ss).\n\
-\n\
-@item %X\n\
-Locale's time representation (%H:%M:%S).\n\
-\n\
-@item %Z\n\
-Time zone (EDT), or nothing if no time zone is determinable.\n\
-@end table\n\
-\n\
-@noindent\n\
-Date fields:\n\
-\n\
-@table @code\n\
-@item %a\n\
-Locale's abbreviated weekday name (Sun-Sat).\n\
-\n\
-@item %A\n\
-Locale's full weekday name, variable length (Sunday-Saturday).\n\
-\n\
-@item %b\n\
-Locale's abbreviated month name (Jan-Dec).\n\
-\n\
-@item %B\n\
-Locale's full month name, variable length (January-December).\n\
-\n\
-@item %c\n\
-Locale's date and time (Sat Nov 04 12:02:33 EST 1989).\n\
-\n\
-@item %C\n\
-Century (00-99).\n\
-\n\
-@item %d\n\
-Day of month (01-31).\n\
-\n\
-@item %e\n\
-Day of month ( 1-31).\n\
-\n\
-@item %D\n\
-Date (mm/dd/yy).\n\
-\n\
-@item %h\n\
-Same as %b.\n\
-\n\
-@item %j\n\
-Day of year (001-366).\n\
-\n\
-@item %m\n\
-Month (01-12).\n\
-\n\
-@item %U\n\
-Week number of year with Sunday as first day of week (00-53).\n\
-\n\
-@item %w\n\
-Day of week (0-6).\n\
-\n\
-@item %W\n\
-Week number of year with Monday as first day of week (00-53).\n\
-\n\
-@item %x\n\
-Locale's date representation (mm/dd/yy).\n\
-\n\
-@item %y\n\
-Last two digits of year (00-99).\n\
-\n\
-@item %Y\n\
-Year (1970-).\n\
-@end table\n\
-@seealso{strptime, localtime, gmtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  if (args.length () == 2)
-    {
-      std::string fmt = args(0).string_value ();
-
-      if (! error_state)
-        {
-          octave_scalar_map map = args(1).scalar_map_value ();
-
-          if (! error_state)
-            {
-              octave_base_tm tm = extract_tm (map);
-
-              if (! error_state)
-                retval = tm.strftime (fmt);
-              else
-                error ("strftime: invalid TM_STRUCT argument");
-            }
-          else
-            error ("strftime: TM_STRUCT must be a structure");
-        }
-      else
-        error ("strftime: FMT must be a string");
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-/*
-%!assert (ischar (strftime ("%%%n%t%H%I%k%l", localtime (time ()))));
-%!assert (ischar (strftime ("%M%p%r%R%s%S%T", localtime (time ()))));
-%!assert (ischar (strftime ("%X%Z%z%a%A%b%B", localtime (time ()))));
-%!assert (ischar (strftime ("%c%C%d%e%D%h%j", localtime (time ()))));
-%!assert (ischar (strftime ("%m%U%w%W%x%y%Y", localtime (time ()))));
-
-%!error strftime ()
-%!error strftime ("foo", localtime (time ()), 1)
-*/
-
-DEFUN_DLD (strptime, args, ,
- "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{tm_struct}, @var{nchars}] =} strptime (@var{str}, @var{fmt})\n\
-Convert the string @var{str} to the time structure @var{tm_struct} under\n\
-the control of the format string @var{fmt}.\n\
-\n\
-If @var{fmt} fails to match, @var{nchars} is 0; otherwise, it is set to the\n\
-position of last matched character plus 1. Always check for this unless\n\
-you're absolutely sure the date string will be parsed correctly.\n\
-@seealso{strftime, localtime, gmtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
-@end deftypefn")
-{
-  octave_value_list retval;
-
-  if (args.length () == 2)
-    {
-      std::string str = args(0).string_value ();
-
-      if (! error_state)
-        {
-          std::string fmt = args(1).string_value ();
-
-          if (! error_state)
-            {
-              octave_strptime t (str, fmt);
-
-              retval(1) = t.characters_converted ();
-              retval(0) = octave_value (mk_tm_map (t));
-            }
-          else
-            error ("strptime: FMT must be a string");
-        }
-      else
-        error ("strptime: argument STR must be a string");
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
--- a/src/DLD-FUNCTIONS/tril.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,430 +0,0 @@
-/*
-
-Copyright (C) 2004-2012 David Bateman
-Copyright (C) 2009 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <algorithm>
-#include "Array.h"
-#include "Sparse.h"
-#include "mx-base.h"
-
-#include "ov.h"
-#include "Cell.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "oct-obj.h"
-
-// The bulk of the work.
-template <class T>
-static Array<T>
-do_tril (const Array<T>& a, octave_idx_type k, bool pack)
-{
-  octave_idx_type nr = a.rows (), nc = a.columns ();
-  const T *avec = a.fortran_vec ();
-  octave_idx_type zero = 0;
-
-  if (pack)
-    {
-      octave_idx_type j1 = std::min (std::max (zero, k), nc);
-      octave_idx_type j2 = std::min (std::max (zero, nr + k), nc);
-      octave_idx_type n = j1 * nr + ((j2 - j1) * (nr-(j1-k) + nr-(j2-1-k))) / 2;
-      Array<T> r (dim_vector (n, 1));
-      T *rvec = r.fortran_vec ();
-      for (octave_idx_type j = 0; j < nc; j++)
-        {
-          octave_idx_type ii = std::min (std::max (zero, j - k), nr);
-          rvec = std::copy (avec + ii, avec + nr, rvec);
-          avec += nr;
-        }
-
-      return r;
-    }
-  else
-    {
-      Array<T> r (a.dims ());
-      T *rvec = r.fortran_vec ();
-      for (octave_idx_type j = 0; j < nc; j++)
-        {
-          octave_idx_type ii = std::min (std::max (zero, j - k), nr);
-          std::fill (rvec, rvec + ii, T ());
-          std::copy (avec + ii, avec + nr, rvec + ii);
-          avec += nr;
-          rvec += nr;
-        }
-
-      return r;
-    }
-}
-
-template <class T>
-static Array<T>
-do_triu (const Array<T>& a, octave_idx_type k, bool pack)
-{
-  octave_idx_type nr = a.rows (), nc = a.columns ();
-  const T *avec = a.fortran_vec ();
-  octave_idx_type zero = 0;
-
-  if (pack)
-    {
-      octave_idx_type j1 = std::min (std::max (zero, k), nc);
-      octave_idx_type j2 = std::min (std::max (zero, nr + k), nc);
-      octave_idx_type n = ((j2 - j1) * ((j1+1-k) + (j2-k))) / 2 + (nc - j2) * nr;
-      Array<T> r (dim_vector (n, 1));
-      T *rvec = r.fortran_vec ();
-      for (octave_idx_type j = 0; j < nc; j++)
-        {
-          octave_idx_type ii = std::min (std::max (zero, j + 1 - k), nr);
-          rvec = std::copy (avec, avec + ii, rvec);
-          avec += nr;
-        }
-
-      return r;
-    }
-  else
-    {
-      NoAlias<Array<T> > r (a.dims ());
-      T *rvec = r.fortran_vec ();
-      for (octave_idx_type j = 0; j < nc; j++)
-        {
-          octave_idx_type ii = std::min (std::max (zero, j + 1 - k), nr);
-          std::copy (avec, avec + ii, rvec);
-          std::fill (rvec + ii, rvec + nr, T ());
-          avec += nr;
-          rvec += nr;
-        }
-
-      return r;
-    }
-}
-
-// These two are by David Bateman.
-// FIXME: optimizations possible. "pack" support missing.
-
-template <class T>
-static Sparse<T>
-do_tril (const Sparse<T>& a, octave_idx_type k, bool pack)
-{
-  if (pack) // FIXME
-    {
-      error ("tril: \"pack\" not implemented for sparse matrices");
-      return Sparse<T> ();
-    }
-
-  Sparse<T> m = a;
-  octave_idx_type nc = m.cols ();
-
-  for (octave_idx_type j = 0; j < nc; j++)
-    for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++)
-      if (m.ridx (i) < j-k)
-        m.data(i) = 0.;
-
-  m.maybe_compress (true);
-  return m;
-}
-
-template <class T>
-static Sparse<T>
-do_triu (const Sparse<T>& a, octave_idx_type k, bool pack)
-{
-  if (pack) // FIXME
-    {
-      error ("triu: \"pack\" not implemented for sparse matrices");
-      return Sparse<T> ();
-    }
-
-  Sparse<T> m = a;
-  octave_idx_type nc = m.cols ();
-
-  for (octave_idx_type j = 0; j < nc; j++)
-    for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++)
-      if (m.ridx (i) > j-k)
-        m.data(i) = 0.;
-
-  m.maybe_compress (true);
-  return m;
-}
-
-// Convenience dispatchers.
-template <class T>
-static Array<T>
-do_trilu (const Array<T>& a, octave_idx_type k, bool lower, bool pack)
-{
-  return lower ? do_tril (a, k, pack) : do_triu (a, k, pack);
-}
-
-template <class T>
-static Sparse<T>
-do_trilu (const Sparse<T>& a, octave_idx_type k, bool lower, bool pack)
-{
-  return lower ? do_tril (a, k, pack) : do_triu (a, k, pack);
-}
-
-static octave_value
-do_trilu (const std::string& name,
-          const octave_value_list& args)
-{
-  bool lower = name == "tril";
-
-  octave_value retval;
-  int nargin = args.length ();
-  octave_idx_type k = 0;
-  bool pack = false;
-  if (nargin >= 2 && args(nargin-1).is_string ())
-    {
-      pack = args(nargin-1).string_value () == "pack";
-      nargin--;
-    }
-
-  if (nargin == 2)
-    {
-      k = args(1).int_value (true);
-
-      if (error_state)
-        return retval;
-    }
-
-  if (nargin < 1 || nargin > 2)
-    print_usage ();
-  else
-    {
-      octave_value arg = args (0);
-
-      dim_vector dims = arg.dims ();
-      if (dims.length () != 2)
-        error ("%s: need a 2-D matrix", name.c_str ());
-      else if (k < -dims (0) || k > dims(1))
-        error ("%s: requested diagonal out of range", name.c_str ());
-      else
-        {
-          switch (arg.builtin_type ())
-            {
-            case btyp_double:
-              if (arg.is_sparse_type ())
-                retval = do_trilu (arg.sparse_matrix_value (), k, lower, pack);
-              else
-                retval = do_trilu (arg.array_value (), k, lower, pack);
-              break;
-            case btyp_complex:
-              if (arg.is_sparse_type ())
-                retval = do_trilu (arg.sparse_complex_matrix_value (), k, lower, pack);
-              else
-                retval = do_trilu (arg.complex_array_value (), k, lower, pack);
-              break;
-            case btyp_bool:
-              if (arg.is_sparse_type ())
-                retval = do_trilu (arg.sparse_bool_matrix_value (), k, lower, pack);
-              else
-                retval = do_trilu (arg.bool_array_value (), k, lower, pack);
-              break;
-#define ARRAYCASE(TYP) \
-            case btyp_ ## TYP: \
-              retval = do_trilu (arg.TYP ## _array_value (), k, lower, pack); \
-              break
-            ARRAYCASE (float);
-            ARRAYCASE (float_complex);
-            ARRAYCASE (int8);
-            ARRAYCASE (int16);
-            ARRAYCASE (int32);
-            ARRAYCASE (int64);
-            ARRAYCASE (uint8);
-            ARRAYCASE (uint16);
-            ARRAYCASE (uint32);
-            ARRAYCASE (uint64);
-            ARRAYCASE (char);
-#undef ARRAYCASE
-            default:
-              {
-                // Generic code that works on octave-values, that is slow
-                // but will also work on arbitrary user types
-
-                if (pack) // FIXME
-                  {
-                    error ("%s: \"pack\" not implemented for class %s",
-                           name.c_str (), arg.class_name ().c_str ());
-                    return octave_value ();
-                  }
-
-                octave_value tmp = arg;
-                if (arg.numel () == 0)
-                  return arg;
-
-                octave_idx_type nr = dims(0), nc = dims (1);
-
-                // The sole purpose of the below is to force the correct
-                // matrix size. This would not be necessary if the
-                // octave_value resize function allowed a fill_value.
-                // It also allows odd attributes in some user types
-                // to be handled. With a fill_value ot should be replaced
-                // with
-                //
-                // octave_value_list ov_idx;
-                // tmp = tmp.resize(dim_vector (0,0)).resize (dims, fill_value);
-
-                octave_value_list ov_idx;
-                std::list<octave_value_list> idx_tmp;
-                ov_idx(1) = static_cast<double> (nc+1);
-                ov_idx(0) = Range (1, nr);
-                idx_tmp.push_back (ov_idx);
-                ov_idx(1) = static_cast<double> (nc);
-                tmp = tmp.resize (dim_vector (0,0));
-                tmp = tmp.subsasgn ("(",idx_tmp, arg.do_index_op (ov_idx));
-                tmp = tmp.resize (dims);
-
-                if (lower)
-                  {
-                    octave_idx_type st = nc < nr + k ? nc : nr + k;
-
-                    for (octave_idx_type j = 1; j <= st; j++)
-                      {
-                        octave_idx_type nr_limit = 1 > j - k ? 1 : j - k;
-                        ov_idx(1) = static_cast<double> (j);
-                        ov_idx(0) = Range (nr_limit, nr);
-                        std::list<octave_value_list> idx;
-                        idx.push_back (ov_idx);
-
-                        tmp = tmp.subsasgn ("(", idx, arg.do_index_op (ov_idx));
-
-                        if (error_state)
-                          return retval;
-                      }
-                  }
-                else
-                  {
-                    octave_idx_type st = k + 1 > 1 ? k + 1 : 1;
-
-                    for (octave_idx_type j = st; j <= nc; j++)
-                      {
-                        octave_idx_type nr_limit = nr < j - k ? nr : j - k;
-                        ov_idx(1) = static_cast<double> (j);
-                        ov_idx(0) = Range (1, nr_limit);
-                        std::list<octave_value_list> idx;
-                        idx.push_back (ov_idx);
-
-                        tmp = tmp.subsasgn ("(", idx, arg.do_index_op (ov_idx));
-
-                        if (error_state)
-                          return retval;
-                      }
-                  }
-
-                retval = tmp;
-              }
-            }
-        }
-    }
-
-  return retval;
-}
-
-DEFUN_DLD (tril, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Function File} {} tril (@var{A})\n\
-@deftypefnx {Function File} {} tril (@var{A}, @var{k})\n\
-@deftypefnx {Function File} {} tril (@var{A}, @var{k}, @var{pack})\n\
-@deftypefnx {Function File} {} triu (@var{A})\n\
-@deftypefnx {Function File} {} triu (@var{A}, @var{k})\n\
-@deftypefnx {Function File} {} triu (@var{A}, @var{k}, @var{pack})\n\
-Return a new matrix formed by extracting the lower (@code{tril})\n\
-or upper (@code{triu}) triangular part of the matrix @var{A}, and\n\
-setting all other elements to zero.  The second argument is optional,\n\
-and specifies how many diagonals above or below the main diagonal should\n\
-also be set to zero.\n\
-\n\
-The default value of @var{k} is zero, so that @code{triu} and\n\
-@code{tril} normally include the main diagonal as part of the result.\n\
-\n\
-If the value of @var{k} is negative, additional elements above (for\n\
-@code{tril}) or below (for @code{triu}) the main diagonal are also\n\
-selected.\n\
-\n\
-The absolute value of @var{k} must not be greater than the number of\n\
-sub-diagonals or super-diagonals.\n\
-\n\
-For example:\n\
-\n\
-@example\n\
-@group\n\
-tril (ones (3), -1)\n\
-     @result{}  0  0  0\n\
-         1  0  0\n\
-         1  1  0\n\
-@end group\n\
-@end example\n\
-\n\
-@noindent\n\
-and\n\
-\n\
-@example\n\
-@group\n\
-tril (ones (3), 1)\n\
-     @result{}  1  1  0\n\
-         1  1  1\n\
-         1  1  1\n\
-@end group\n\
-@end example\n\
-\n\
-If the option \"pack\" is given as third argument, the extracted elements\n\
-are not inserted into a matrix, but rather stacked column-wise one above\n\
-other.\n\
-@seealso{diag}\n\
-@end deftypefn")
-{
-  return do_trilu ("tril", args);
-}
-
-DEFUN_DLD (triu, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn  {Function File} {} triu (@var{A})\n\
-@deftypefnx {Function File} {} triu (@var{A}, @var{k})\n\
-@deftypefnx {Function File} {} triu (@var{A}, @var{k}, @var{pack})\n\
-See the documentation for the @code{tril} function (@pxref{tril}).\n\
-@end deftypefn")
-{
-  return do_trilu ("triu", args);
-}
-
-/*
-%!test
-%! a = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12];
-%!
-%! l0 = [1, 0, 0; 4, 5, 0; 7, 8, 9; 10, 11, 12];
-%! l1 = [1, 2, 0; 4, 5, 6; 7, 8, 9; 10, 11, 12];
-%! l2 = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12];
-%! lm1 = [0, 0, 0; 4, 0, 0; 7, 8, 0; 10, 11, 12];
-%! lm2 = [0, 0, 0; 0, 0, 0; 7, 0, 0; 10, 11, 0];
-%! lm3 = [0, 0, 0; 0, 0, 0; 0, 0, 0; 10, 0, 0];
-%! lm4 = [0, 0, 0; 0, 0, 0; 0, 0, 0; 0, 0, 0];
-%!
-%! assert (tril (a, -4), lm4); 
-%! assert (tril (a, -3), lm3);
-%! assert (tril (a, -2), lm2);
-%! assert (tril (a, -1), lm1);
-%! assert (tril (a), l0);
-%! assert (tril (a, 1), l1);
-%! assert (tril (a, 2), l2);
-
-%!error tril ()
-*/
--- a/src/DLD-FUNCTIONS/typecast.cc	Fri Jul 27 17:10:25 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,460 +0,0 @@
-/*
-
-Copyright (C) 2007-2012 David Bateman
-Copyright (C) 2009 VZLU Prague
-
-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/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "mx-base.h"
-
-#include "defun-dld.h"
-#include "error.h"
-#include "gripes.h"
-#include "oct-obj.h"
-#include "unwind-prot.h"
-
-static dim_vector
-get_vec_dims (const dim_vector& old_dims, octave_idx_type n)
-{
-  if (old_dims.length () == 2 && old_dims(0) == 1)
-    return dim_vector (1, n);
-  else if (old_dims.length () == 2 && old_dims (0) == 0 && old_dims (1) == 0)
-    return dim_vector ();
-  else
-    return dim_vector (n, 1);
-}
-
-template <class ArrayType>
-static void
-get_data_and_bytesize (const ArrayType& array,
-                       const void *& data,
-                       octave_idx_type& byte_size,
-                       dim_vector& old_dims,
-                       unwind_protect& frame)
-{
-  // The array given may be a temporary, constructed from a scalar or sparse
-  // array. This will ensure the data will be deallocated after we exit.
-  frame.add_delete (new ArrayType (array));
-
-  data = reinterpret_cast<const void *> (array.data ());
-  byte_size = array.byte_size ();
-
-  old_dims = array.dims ();
-}
-
-template <class ArrayType>
-static ArrayType
-reinterpret_copy (const void *data, octave_idx_type byte_size,
-                  const dim_vector& old_dims)
-{
-  typedef typename ArrayType::element_type T;
-  octave_idx_type n = byte_size / sizeof (T);
-
-  if (n * static_cast<int> (sizeof (T)) == byte_size)
-    {
-      ArrayType retval (get_vec_dims (old_dims, n));
-      T *dest = retval.fortran_vec ();
-      std::memcpy (dest, data, n * sizeof (T));
-
-      return retval;
-    }
-  else
-    {
-      error ("typecast: incorrect number of input values to make output value");
-      return ArrayType ();
-    }
-}
-
-
-DEFUN_DLD (typecast, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} typecast (@var{x}, @var{class})\n\
-Return a new array @var{y} resulting from interpreting the data of\n\
-@var{x} in memory as data of the numeric class @var{class}.  Both the class\n\
-of @var{x} and @var{class} must be one of the built-in numeric classes:\n\
-\n\
-@example\n\
-@group\n\
-\"logical\"\n\
-\"char\"\n\
-\"int8\"\n\
-\"int16\"\n\
-\"int32\"\n\
-\"int64\"\n\
-\"uint8\"\n\
-\"uint16\"\n\
-\"uint32\"\n\
-\"uint64\"\n\
-\"double\"\n\
-\"single\"\n\
-\"double complex\"\n\
-\"single complex\"\n\
-@end group\n\
-@end example\n\
-\n\
-@noindent\n\
-the last two are reserved for @var{class}; they indicate that a\n\
-complex-valued result is requested.  Complex arrays are stored in memory as\n\
-consecutive pairs of real numbers.  The sizes of integer types are given by\n\
-their bit counts.  Both logical and char are typically one byte wide;\n\
-however, this is not guaranteed by C++.  If your system is IEEE conformant,\n\
-single and double should be 4 bytes and 8 bytes wide, respectively.\n\
-\"logical\" is not allowed for @var{class}.  If the input is a row vector,\n\
-the return value is a row vector, otherwise it is a column vector.  If the\n\
-bit length of @var{x} is not divisible by that of @var{class}, an error\n\
-occurs.\n\
-\n\
-An example of the use of typecast on a little-endian machine is\n\
-\n\
-@example\n\
-@group\n\
-@var{x} = uint16 ([1, 65535]);\n\
-typecast (@var{x}, \"uint8\")\n\
-  @result{} [   0,   1, 255, 255]\n\
-@end group\n\
-@end example\n\
-@seealso{cast, bitunpack, bitpack, swapbytes}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  if (args.length () == 2)
-    {
-      unwind_protect frame;
-      const void *data = 0;
-      octave_idx_type byte_size = 0;
-      dim_vector old_dims;
-
-      octave_value array = args(0);
-
-      if (array.is_bool_type ())
-        get_data_and_bytesize (array.bool_array_value (), data, byte_size, old_dims, frame);
-      else if (array.is_string ())
-        get_data_and_bytesize (array.char_array_value (), data, byte_size, old_dims, frame);
-      else if (array.is_integer_type ())
-        {
-          if (array.is_int8_type ())
-            get_data_and_bytesize (array.int8_array_value (), data, byte_size, old_dims, frame);
-          else if (array.is_int16_type ())
-            get_data_and_bytesize (array.int16_array_value (), data, byte_size, old_dims, frame);
-          else if (array.is_int32_type ())
-            get_data_and_bytesize (array.int32_array_value (), data, byte_size, old_dims, frame);
-          else if (array.is_int64_type ())
-            get_data_and_bytesize (array.int64_array_value (), data, byte_size, old_dims, frame);
-          else if (array.is_uint8_type ())
-            get_data_and_bytesize (array.uint8_array_value (), data, byte_size, old_dims, frame);
-          else if (array.is_uint16_type ())
-            get_data_and_bytesize (array.uint16_array_value (), data, byte_size, old_dims, frame);
-          else if (array.is_uint32_type ())
-            get_data_and_bytesize (array.uint32_array_value (), data, byte_size, old_dims, frame);
-          else if (array.is_uint64_type ())
-            get_data_and_bytesize (array.uint64_array_value (), data, byte_size, old_dims, frame);
-          else
-            assert (0);
-        }
-      else if (array.is_complex_type ())
-        {
-          if (array.is_single_type ())
-            get_data_and_bytesize (array.float_complex_array_value (), data, byte_size, old_dims, frame);
-          else
-            get_data_and_bytesize (array.complex_array_value (), data, byte_size, old_dims, frame);
-        }
-      else if (array.is_real_type ())
-        {
-          if (array.is_single_type ())
-            get_data_and_bytesize (array.float_array_value (), data, byte_size, old_dims, frame);
-          else
-            get_data_and_bytesize (array.array_value (), data, byte_size, old_dims, frame);
-        }
-      else
-        error ("typecast: invalid input class: %s", array.class_name ().c_str ());
-
-      std::string numclass = args(1).string_value ();
-
-      if (error_state || numclass.size () == 0)
-        ;
-      else if (numclass == "char")
-        retval = octave_value (reinterpret_copy<charNDArray> (data, byte_size, old_dims), array.is_dq_string () ? '"' : '\'');
-      else if (numclass[0] == 'i')
-        {
-          if (numclass == "int8")
-            retval = reinterpret_copy<int8NDArray> (data, byte_size, old_dims);
-          else if (numclass == "int16")
-            retval = reinterpret_copy<int16NDArray> (data, byte_size, old_dims);
-          else if (numclass == "int32")
-            retval = reinterpret_copy<int32NDArray> (data, byte_size, old_dims);
-          else if (numclass == "int64")
-            retval = reinterpret_copy<int64NDArray> (data, byte_size, old_dims);
-        }
-      else if (numclass[0] == 'u')
-        {
-          if (numclass == "uint8")
-            retval = reinterpret_copy<uint8NDArray> (data, byte_size, old_dims);
-          else if (numclass == "uint16")
-            retval = reinterpret_copy<uint16NDArray> (data, byte_size, old_dims);
-          else if (numclass == "uint32")
-            retval = reinterpret_copy<uint32NDArray> (data, byte_size, old_dims);
-          else if (numclass == "uint64")
-            retval = reinterpret_copy<uint64NDArray> (data, byte_size, old_dims);
-        }
-      else if (numclass == "single")
-        retval = reinterpret_copy<FloatNDArray> (data, byte_size, old_dims);
-      else if (numclass == "double")
-        retval = reinterpret_copy<NDArray> (data, byte_size, old_dims);
-      else if (numclass == "single complex")
-        retval = reinterpret_copy<FloatComplexNDArray> (data, byte_size, old_dims);
-      else if (numclass == "double complex")
-        retval = reinterpret_copy<ComplexNDArray> (data, byte_size, old_dims);
-
-      if (! error_state && retval.is_undefined ())
-        error ("typecast: cannot convert to %s class", numclass.c_str ());
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-template <class ArrayType>
-ArrayType
-do_bitpack (const boolNDArray& bitp)
-{
-  typedef typename ArrayType::element_type T;
-  octave_idx_type n = bitp.numel () / (sizeof (T) * CHAR_BIT);
-
-  if (n * static_cast<int> (sizeof (T)) * CHAR_BIT == bitp.numel ())
-    {
-
-      ArrayType retval (get_vec_dims (bitp.dims (), n));
-
-      const bool *bits = bitp.fortran_vec ();
-      char *packed = reinterpret_cast<char *> (retval.fortran_vec ());
-
-      octave_idx_type m = n * sizeof (T);
-
-      for (octave_idx_type i = 0; i < m; i++)
-        {
-          char c = bits[0];
-          for (int j = 1; j < CHAR_BIT; j++)
-            c |= bits[j] << j;
-
-          packed[i] = c;
-          bits += CHAR_BIT;
-        }
-
-      return retval;
-    }
-  else
-    {
-      error ("bitpack: incorrect number of bits to make up output value");
-      return ArrayType ();
-    }
-}
-
-DEFUN_DLD (bitpack, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{y} =} bitpack (@var{x}, @var{class})\n\
-Return a new array @var{y} resulting from interpreting an array\n\
-@var{x} as raw bit patterns for data of the numeric class @var{class}.\n\
-@var{class} must be one of the built-in numeric classes:\n\
-\n\
-@example\n\
-@group\n\
-\"char\"\n\
-\"int8\"\n\
-\"int16\"\n\
-\"int32\"\n\
-\"int64\"\n\
-\"uint8\"\n\
-\"uint16\"\n\
-\"uint32\"\n\
-\"uint64\"\n\
-\"double\"\n\
-\"single\"\n\
-@end group\n\
-@end example\n\
-\n\
-The number of elements of @var{x} should be divisible by the bit length of\n\
-@var{class}.  If it is not, excess bits are discarded.  Bits come in\n\
-increasing order of significance, i.e., @code{x(1)} is bit 0, @code{x(2)} is\n\
-bit 1, etc.  The result is a row vector if @var{x} is a row vector, otherwise\n\
-it is a column vector.\n\
-@seealso{bitunpack, typecast}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  if (args.length () == 2 && args(0).is_bool_type ())
-    {
-      boolNDArray bitp = args(0).bool_array_value ();
-
-      std::string numclass = args(1).string_value ();
-
-      if (error_state || numclass.size () == 0)
-        ;
-      else if (numclass == "char")
-        retval = octave_value (do_bitpack<charNDArray> (bitp), '\'');
-      else if (numclass[0] == 'i')
-        {
-          if (numclass == "int8")
-            retval = do_bitpack<int8NDArray> (bitp);
-          else if (numclass == "int16")
-            retval = do_bitpack<int16NDArray> (bitp);
-          else if (numclass == "int32")
-            retval = do_bitpack<int32NDArray> (bitp);
-          else if (numclass == "int64")
-            retval = do_bitpack<int64NDArray> (bitp);
-        }
-      else if (numclass[0] == 'u')
-        {
-          if (numclass == "uint8")
-            retval = do_bitpack<uint8NDArray> (bitp);
-          else if (numclass == "uint16")
-            retval = do_bitpack<uint16NDArray> (bitp);
-          else if (numclass == "uint32")
-            retval = do_bitpack<uint32NDArray> (bitp);
-          else if (numclass == "uint64")
-            retval = do_bitpack<uint64NDArray> (bitp);
-        }
-      else if (numclass == "single")
-        retval = do_bitpack<FloatNDArray> (bitp);
-      else if (numclass == "double")
-        retval = do_bitpack<NDArray> (bitp);
-      else if (numclass == "single complex")
-        retval = do_bitpack<FloatComplexNDArray> (bitp);
-      else if (numclass == "double complex")
-        retval = do_bitpack<ComplexNDArray> (bitp);
-
-      if (! error_state && retval.is_undefined ())
-        error ("bitpack: cannot pack to %s class", numclass.c_str ());
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
-
-template <class ArrayType>
-boolNDArray
-do_bitunpack (const ArrayType& array)
-{
-  typedef typename ArrayType::element_type T;
-  octave_idx_type n = array.numel () * sizeof (T) * CHAR_BIT;
-
-  boolNDArray retval (get_vec_dims (array.dims (), n));
-
-  const char *packed = reinterpret_cast<const char *> (array.fortran_vec ());
-  bool *bits = retval.fortran_vec ();
-
-  octave_idx_type m = n / CHAR_BIT;
-
-  for (octave_idx_type i = 0; i < m; i++)
-    {
-      char c = packed[i];
-      bits[0] = c & 1;
-      for (int j = 1; j < CHAR_BIT; j++)
-        bits[j] = (c >>= 1) & 1;
-      bits += CHAR_BIT;
-    }
-
-  return retval;
-}
-
-DEFUN_DLD (bitunpack, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{y} =} bitunpack (@var{x})\n\
-Return an array @var{y} corresponding to the raw bit patterns of\n\
-@var{x}.  @var{x} must belong to one of the built-in numeric classes:\n\
-\n\
-@example\n\
-@group\n\
-\"char\"\n\
-\"int8\"\n\
-\"int16\"\n\
-\"int32\"\n\
-\"int64\"\n\
-\"uint8\"\n\
-\"uint16\"\n\
-\"uint32\"\n\
-\"uint64\"\n\
-\"double\"\n\
-\"single\"\n\
-@end group\n\
-@end example\n\
-\n\
-The result is a row vector if @var{x} is a row vector; otherwise, it is a\n\
-column vector.\n\
-@seealso{bitpack, typecast}\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  if (args.length () == 1 && (args(0).is_numeric_type () || args(0).is_string ()))
-    {
-      octave_value array = args(0);
-
-      if (array.is_string ())
-        retval = do_bitunpack (array.char_array_value ());
-      else if (array.is_integer_type ())
-        {
-          if (array.is_int8_type ())
-            retval = do_bitunpack (array.int8_array_value ());
-          else if (array.is_int16_type ())
-            retval = do_bitunpack (array.int16_array_value ());
-          else if (array.is_int32_type ())
-            retval = do_bitunpack (array.int32_array_value ());
-          else if (array.is_int64_type ())
-            retval = do_bitunpack (array.int64_array_value ());
-          else if (array.is_uint8_type ())
-            retval = do_bitunpack (array.uint8_array_value ());
-          else if (array.is_uint16_type ())
-            retval = do_bitunpack (array.uint16_array_value ());
-          else if (array.is_uint32_type ())
-            retval = do_bitunpack (array.uint32_array_value ());
-          else if (array.is_uint64_type ())
-            retval = do_bitunpack (array.uint64_array_value ());
-          else
-            assert (0);
-        }
-      else if (array.is_complex_type ())
-        {
-          if (array.is_single_type ())
-            retval = do_bitunpack (array.float_complex_array_value ());
-          else
-            retval = do_bitunpack (array.complex_array_value ());
-        }
-      else if (array.is_real_type ())
-        {
-          if (array.is_single_type ())
-            retval = do_bitunpack (array.float_array_value ());
-          else
-            retval = do_bitunpack (array.array_value ());
-        }
-      else
-        error ("bitunpack: invalid input class: %s", array.class_name ().c_str ());
-    }
-  else
-    print_usage ();
-
-  return retval;
-}
--- a/src/Makefile.am	Fri Jul 27 17:10:25 2012 -0400
+++ b/src/Makefile.am	Fri Jul 27 21:59:10 2012 -0400
@@ -25,6 +25,7 @@
   -I../libgnu -I$(top_srcdir)/libgnu \
   -I$(top_srcdir)/libcruft/misc \
   -I../liboctave -I$(top_srcdir)/liboctave \
+  -Icorefcn -I$(srcdir)/corefcn \
   -I. -I$(srcdir) \
   @CPPFLAGS@
 
@@ -44,7 +45,7 @@
 
 octave_config_SOURCES =
 nodist_octave_config_SOURCES = octave-config.cc
-octave_config_LDADD = ../libgnu/libgnu.la $(LIBS)
+octave_config_LDADD = corefcn/libcorefcn.la ../libgnu/libgnu.la $(LIBS)
 
 BUILT_SOURCES_EXTRA = \
   mkoctfile.cc \
@@ -421,6 +422,10 @@
   jit-ir.cc \
   pt-jit.cc
 
+#noinst_LTLIBRARIES =
+#
+#include corefcn/module.mk
+#
 DIST_SRC = \
   Cell.cc \
   bitfcns.cc \
@@ -492,10 +497,14 @@
   xnorm.cc \
   xpow.cc \
   zfstream.cc \
+  $(corefcn_SRC) \
   $(OV_SRC) \
   $(PT_SRC) \
   $(JIT_SRC)
 
+noinst_LTLIBRARIES =
+
+include corefcn/module.mk
 include DLD-FUNCTIONS/module.mk
 
 $(srcdir)/DLD-FUNCTIONS/module.mk: $(srcdir)/DLD-FUNCTIONS/config-module.sh $(srcdir)/DLD-FUNCTIONS/config-module.awk $(srcdir)/DLD-FUNCTIONS/module-files
@@ -554,6 +563,9 @@
 
 display.df display.lo: CPPFLAGS += $(X11_FLAGS)
 
+## FIXME: Does this rule need to be uncommented?
+#fft.df fft.lo fft2.df fft2.lo fftn.df fftn.lo: CPPFLAGS += $(FFTW_XCPPFLAGS)
+
 octave_SOURCES = main.c
 
 octave_LDADD = \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/__contourc__.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,340 @@
+/* Contour lines for function evaluated on a grid.
+
+Copyright (C) 2007-2012 Kai Habel
+Copyright (C) 2004, 2007 Shai Ayal
+
+Adapted to an oct file from the stand alone contourl by Victro Munoz
+Copyright (C) 2004 Victor Munoz
+
+Based on contour plot routine (plcont.c) in PLPlot package
+http://plplot.org/
+
+Copyright (C) 1995, 2000, 2001 Maurice LeBrun
+Copyright (C) 2000, 2002 Joao Cardoso
+Copyright (C) 2000, 2001, 2002, 2004  Alan W. Irwin
+Copyright (C) 2004  Andrew Ross
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cfloat>
+
+#include "quit.h"
+
+#include "defun.h"
+#include "error.h"
+#include "oct-obj.h"
+
+static Matrix this_contour;
+static Matrix contourc;
+static int elem;
+
+// This is the quanta in which we increase this_contour.
+#define CONTOUR_QUANT 50
+
+// Add a coordinate point (x,y) to this_contour.
+
+static void
+add_point (double x, double y)
+{
+  if (elem % CONTOUR_QUANT == 0)
+    this_contour = this_contour.append (Matrix (2, CONTOUR_QUANT, 0));
+
+  this_contour (0, elem) = x;
+  this_contour (1, elem) = y;
+  elem++;
+}
+
+// Add contents of current contour to contourc.
+// this_contour.cols () - 1;
+
+static void
+end_contour (void)
+{
+  if (elem > 2)
+    {
+      this_contour (1, 0) = elem - 1;
+      contourc = contourc.append (this_contour.extract_n (0, 0, 2, elem));
+    }
+
+  this_contour = Matrix ();
+  elem = 0;
+}
+
+// Start a new contour, and add contents of current one to contourc.
+
+static void
+start_contour (double lvl, double x, double y)
+{
+  end_contour ();
+  this_contour.resize (2, 0);
+  add_point (lvl, 0);
+  add_point (x, y);
+}
+
+static void
+drawcn (const RowVector& X, const RowVector& Y, const Matrix& Z,
+        double lvl, int r, int c, double ct_x, double ct_y,
+        unsigned int start_edge, bool first, charMatrix& mark)
+{
+  double px[4], py[4], pz[4], tmp;
+  unsigned int stop_edge, next_edge, pt[2];
+  int next_r, next_c;
+
+  //get x, y, and z - lvl for current facet
+  px[0] = px[3] = X(c);
+  px[1] = px[2] = X(c+1);
+
+  py[0] = py[1] = Y(r);
+  py[2] = py[3] = Y(r+1);
+
+  pz[3] = Z(r+1, c) - lvl;
+  pz[2] = Z(r+1, c + 1) - lvl;
+  pz[1] = Z(r, c+1) - lvl;
+  pz[0] = Z(r, c) - lvl;
+
+  // Facet edge and point naming assignment.
+  //
+  //  0-----1   .-0-.
+  //  |     |   |   |
+  //  |     |   3   1
+  //  |     |   |   |
+  //  3-----2   .-2-.
+
+  // Get mark value of current facet.
+  char id = static_cast<char> (mark(r, c));
+
+  // Check startedge s.
+  if (start_edge == 255)
+    {
+      // Find start edge.
+      for (unsigned int k = 0; k < 4; k++)
+        if (static_cast<char> (1 << k) & id)
+          start_edge = k;
+    }
+
+  if (start_edge == 255)
+    return;
+
+  // Decrease mark value of current facet for start edge.
+  mark(r, c) -= static_cast<char> (1 << start_edge);
+
+  // Next point (clockwise).
+  pt[0] = start_edge;
+  pt[1] = (pt[0] + 1) % 4;
+
+  // Calculate contour segment start if first of contour.
+  if (first)
+    {
+      tmp = fabs (pz[pt[1]]) / fabs (pz[pt[0]]);
+
+      if (xisnan (tmp))
+        ct_x = ct_y = 0.5;
+      else
+        {
+          ct_x = px[pt[0]] + (px[pt[1]] - px[pt[0]])/(1 + tmp);
+          ct_y = py[pt[0]] + (py[pt[1]] - py[pt[0]])/(1 + tmp);
+        }
+
+      start_contour (lvl, ct_x, ct_y);
+    }
+
+  // Find stop edge.
+  // FIXME -- perhaps this should use a while loop?
+  for (unsigned int k = 1; k <= 4; k++)
+    {
+      if (start_edge == 0 || start_edge == 2)
+        stop_edge = (start_edge + k) % 4;
+      else
+        stop_edge = (start_edge - k) % 4;
+
+      if (static_cast<char> (1 << stop_edge) & id)
+        break;
+    }
+
+  pt[0] = stop_edge;
+  pt[1] = (pt[0] + 1) % 4;
+  tmp = fabs (pz[pt[1]]) / fabs (pz[pt[0]]);
+
+  if (xisnan (tmp))
+    ct_x = ct_y = 0.5;
+  else
+    {
+      ct_x = px[pt[0]] + (px[pt[1]] - px[pt[0]])/(1 + tmp);
+      ct_y = py[pt[0]] + (py[pt[1]] - py[pt[0]])/(1 + tmp);
+    }
+
+  // Add point to contour.
+  add_point (ct_x, ct_y);
+
+  // Decrease id value of current facet for start edge.
+  mark(r, c) -= static_cast<char> (1 << stop_edge);
+
+  // Find next facet.
+  next_c = c;
+  next_r = r;
+
+  if (stop_edge == 0)
+    next_r--;
+  else if (stop_edge == 1)
+    next_c++;
+  else if (stop_edge == 2)
+    next_r++;
+  else if (stop_edge == 3)
+    next_c--;
+
+  // Check if next facet is not done yet.
+  // Go to next facet.
+  if (next_r >= 0 && next_c >= 0 && next_r < mark.rows ()
+      && next_c < mark.cols () && mark(next_r, next_c) > 0)
+    {
+      next_edge = (stop_edge + 2) % 4;
+      drawcn (X, Y, Z, lvl, next_r, next_c, ct_x, ct_y, next_edge, false, mark);
+    }
+}
+
+static void
+mark_facets (const Matrix& Z, charMatrix& mark, double lvl)
+{
+  unsigned int nr = mark.rows ();
+  unsigned int nc = mark.cols ();
+
+  double f[4];
+
+  for (unsigned int c = 0; c < nc; c++)
+    for (unsigned int r = 0; r < nr; r++)
+      {
+        f[0] = Z(r, c) - lvl;
+        f[1] = Z(r, c+1) - lvl;
+        f[3] = Z(r+1, c) - lvl;
+        f[2] = Z(r+1, c+1) - lvl;
+
+        for (unsigned int i = 0; i < 4; i++)
+          if (fabs(f[i]) < DBL_EPSILON)
+            f[i] = DBL_EPSILON;
+
+        if (f[1] * f[2] < 0)
+          mark(r, c) += 2;
+
+        if (f[0] * f[3] < 0)
+          mark(r, c) += 8;
+      }
+
+  for (unsigned int r = 0; r < nr; r++)
+    for (unsigned int c = 0; c < nc; c++)
+      {
+        f[0] = Z(r, c) - lvl;
+        f[1] = Z(r, c+1) - lvl;
+        f[3] = Z(r+1, c) - lvl;
+        f[2] = Z(r+1, c+1) - lvl;
+
+        for (unsigned int i = 0; i < 4; i++)
+          if (fabs(f[i]) < DBL_EPSILON)
+            f[i] = DBL_EPSILON;
+
+        if (f[0] * f[1] < 0)
+          mark(r, c) += 1;
+
+        if (f[2] * f[3] < 0)
+          mark(r, c) += 4;
+      }
+}
+
+static void
+cntr (const RowVector& X, const RowVector& Y, const Matrix& Z, double lvl)
+{
+  unsigned int nr = Z.rows ();
+  unsigned int nc = Z.cols ();
+
+  charMatrix mark (nr - 1, nc - 1, 0);
+
+  mark_facets (Z, mark, lvl);
+
+  // Find contours that start at a domain edge.
+
+  for (unsigned int c = 0; c < nc - 1; c++)
+    {
+      // Top.
+      if (mark(0, c) & 1)
+        drawcn (X, Y, Z, lvl, 0, c, 0.0, 0.0, 0, true, mark);
+
+      // Bottom.
+      if (mark(nr - 2, c) & 4)
+        drawcn (X, Y, Z, lvl, nr - 2, c, 0.0, 0.0, 2, true, mark);
+    }
+
+  for (unsigned int r = 0; r < nr - 1; r++)
+    {
+      // Left.
+      if (mark(r, 0) & 8)
+        drawcn (X, Y, Z, lvl, r, 0, 0.0, 0.0, 3, true, mark);
+
+      // Right.
+      if (mark(r, nc - 2) & 2)
+        drawcn (X, Y, Z, lvl, r, nc - 2, 0.0, 0.0, 1, true, mark);
+    }
+
+  for (unsigned int r = 0; r < nr - 1; r++)
+    for (unsigned int c = 0; c < nc - 1; c++)
+      if (mark (r, c) > 0)
+        drawcn (X, Y, Z, lvl, r, c, 0.0, 0.0, 255, true, mark);
+}
+
+DEFUN (__contourc__, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} __contourc__ (@var{x}, @var{y}, @var{z}, @var{levels})\n\
+Undocumented internal function.\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () == 4)
+    {
+      RowVector X = args (0).row_vector_value ();
+      RowVector Y = args (1).row_vector_value ();
+      Matrix Z = args (2).matrix_value ();
+      RowVector L = args (3).row_vector_value ();
+
+      if (! error_state)
+        {
+          contourc.resize (2, 0);
+
+          for (int i = 0; i < L.length (); i++)
+            cntr (X, Y, Z, L (i));
+
+          end_contour ();
+
+          retval = contourc;
+        }
+      else
+        error ("__contourc__: invalid argument values");
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+## No test needed for internal helper function.
+%!assert (1)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/__dispatch__.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,136 @@
+/*
+
+Copyright (C) 2001-2012 John W. Eaton and Paul Kienzle
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <list>
+#include <map>
+#include <string>
+
+#include "Cell.h"
+#include "oct-map.h"
+#include "defun.h"
+#include "ov.h"
+#include "ov-fcn.h"
+#include "ov-typeinfo.h"
+#include "pager.h"
+#include "parse.h"
+#include "symtab.h"
+#include "variables.h"
+
+DEFUN (__dispatch__, args, nargout,
+  "Undocumented internal function")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  std::string f, r, t;
+
+  if (nargin > 0 && nargin < 4)
+    {
+      if (nargin > 0)
+        {
+          f = args(0).string_value ();
+
+          if (error_state)
+            {
+              error ("__dispatch__: first argument must be a function name");
+              return retval;
+            }
+        }
+
+      if (nargin > 1)
+        {
+          r = args(1).string_value ();
+
+          if (error_state)
+            {
+              error ("__dispatch__: second argument must be a function name");
+              return retval;
+            }
+        }
+
+      if (nargin > 2)
+        {
+          t = args(2).string_value ();
+
+          if (error_state)
+            {
+              error ("__dispatch__: third argument must be a type name");
+              return retval;
+            }
+        }
+
+      if (nargin == 1)
+        {
+          if (nargout > 0)
+            {
+              symbol_table::fcn_info::dispatch_map_type dm
+                = symbol_table::get_dispatch (f);
+
+              size_t len = dm.size ();
+
+              Cell type_field (len, 1);
+              Cell name_field (len, 1);
+
+              symbol_table::fcn_info::dispatch_map_type::const_iterator p
+                = dm.begin ();
+
+              for (size_t i = 0; i < len; i++)
+                {
+                  type_field(i) = p->first;
+                  name_field(i) = p->second;
+
+                  p++;
+                }
+
+              octave_scalar_map m;
+
+              m.assign ("type", type_field);
+              m.assign ("name", name_field);
+
+              retval = m;
+            }
+          else
+            symbol_table::print_dispatch (octave_stdout, f);
+        }
+      else if (nargin == 2)
+        {
+          t = r;
+          symbol_table::clear_dispatch (f, t);
+        }
+      else
+        symbol_table::add_dispatch (f, t, r);
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+## No test needed for internal helper function.
+%!assert (1)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/__lin_interpn__.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,362 @@
+/*
+
+Copyright (C) 2007-2012 Alexander Barth
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "lo-ieee.h"
+#include "dNDArray.h"
+#include "oct-locbuf.h"
+
+#include "defun.h"
+#include "error.h"
+#include "oct-obj.h"
+
+// equivalent to isvector.m
+
+template <class T>
+bool
+isvector (const T& array)
+{
+  const dim_vector dv = array.dims ();
+  return dv.length () == 2 && (dv(0) == 1 || dv(1) == 1);
+}
+
+// lookup a value in a sorted table (lookup.m)
+template <class T>
+octave_idx_type
+lookup (const T *x, octave_idx_type n, T y)
+{
+  octave_idx_type j;
+
+  if (x[0] < x[n-1])
+    {
+      // increasing x
+
+      if (y > x[n-1] || y < x[0])
+        return -1;
+
+#ifdef EXHAUSTIF
+      for (j = 0; j < n - 1; j++)
+        {
+          if (x[j] <= y && y <= x[j+1])
+            return j;
+        }
+#else
+      octave_idx_type j0 = 0;
+      octave_idx_type j1 = n - 1;
+
+      while (true)
+        {
+          j = (j0+j1)/2;
+
+          if (y <= x[j+1])
+            {
+              if (x[j] <= y)
+                return j;
+
+              j1 = j;
+            }
+
+          if (x[j] <= y)
+            j0 = j;
+        }
+#endif
+    }
+  else
+    {
+      // decreasing x
+      // previous code with x -> -x and y -> -y
+
+      if (y > x[0] || y < x[n-1])
+        return -1;
+
+#ifdef EXHAUSTIF
+      for (j = 0; j < n - 1; j++)
+        {
+          if (x[j+1] <= y && y <= x[j])
+            return j;
+        }
+#else
+      octave_idx_type j0 = 0;
+      octave_idx_type j1 = n - 1;
+
+      while (true)
+        {
+          j = (j0+j1)/2;
+
+          if (y >= x[j+1])
+            {
+              if (x[j] >= y)
+                return j;
+
+              j1 = j;
+            }
+
+          if (x[j] >= y)
+            j0 = j;
+        }
+#endif
+    }
+}
+
+// n-dimensional linear interpolation
+
+template <class T>
+void
+lin_interpn (int n, const octave_idx_type *size, const octave_idx_type *scale,
+             octave_idx_type Ni, T extrapval, const T **x,
+             const T *v, const T **y, T *vi)
+{
+  bool out = false;
+  int bit;
+
+  OCTAVE_LOCAL_BUFFER (T, coef, 2*n);
+  OCTAVE_LOCAL_BUFFER (octave_idx_type, index, n);
+
+  // loop over all points
+  for (octave_idx_type m = 0; m < Ni; m++)
+    {
+      // loop over all dimensions
+      for (int i = 0; i < n; i++)
+        {
+          index[i] = lookup (x[i], size[i], y[i][m]);
+          out = index[i] == -1;
+
+          if (out)
+            break;
+          else
+            {
+              octave_idx_type j = index[i];
+              coef[2*i+1] = (y[i][m] - x[i][j])/(x[i][j+1] - x[i][j]);
+              coef[2*i] = 1 - coef[2*i+1];
+            }
+        }
+
+
+      if (out)
+        vi[m] = extrapval;
+      else
+        {
+          vi[m] = 0;
+
+          // loop over all corners of hypercube (1<<n = 2^n)
+          for (int i = 0; i < (1 << n); i++)
+            {
+              T c = 1;
+              octave_idx_type l = 0;
+
+              // loop over all dimensions
+              for (int j = 0; j < n; j++)
+                {
+                  // test if the jth bit in i is set
+                  bit = i >> j & 1;
+                  l += scale[j] * (index[j] + bit);
+                  c *= coef[2*j+bit];
+                }
+
+              vi[m] += c * v[l];
+            }
+        }
+    }
+}
+
+template <class T, class M>
+octave_value
+lin_interpn (int n, M *X, const M V, M *Y)
+{
+  octave_value retval;
+
+  M Vi = M (Y[0].dims ());
+
+  OCTAVE_LOCAL_BUFFER (const T *, y, n);
+  OCTAVE_LOCAL_BUFFER (octave_idx_type, size, n);
+
+  for (int i = 0; i < n; i++)
+    {
+      y[i] = Y[i].data ();
+      size[i] =  V.dims ()(i);
+    }
+
+  OCTAVE_LOCAL_BUFFER (const T *, x, n);
+  OCTAVE_LOCAL_BUFFER (octave_idx_type, scale, n);
+
+  const T *v = V.data ();
+  T *vi = Vi.fortran_vec ();
+  octave_idx_type Ni = Vi.numel ();
+
+  T extrapval = octave_NA;
+
+  // offset in memory of each dimension
+
+  scale[0] = 1;
+
+  for (int i = 1; i < n; i++)
+    scale[i] = scale[i-1] * size[i-1];
+
+  // tests if X[0] is a vector, if yes, assume that all elements of X are
+  // in the ndgrid format.
+
+  if (! isvector (X[0]))
+    {
+      for (int i = 0; i < n; i++)
+        {
+          if (X[i].dims () != V.dims ())
+            {
+              error ("interpn: incompatible size of argument number %d", i+1);
+              return retval;
+            }
+          else
+            {
+              M tmp = M (dim_vector (size[i], 1));
+
+              for (octave_idx_type j = 0; j < size[i]; j++)
+                tmp(j) =  X[i](scale[i]*j);
+
+              X[i] = tmp;
+            }
+        }
+    }
+
+  for (int i = 0; i < n; i++)
+    {
+      if (! isvector (X[i]) && X[i].numel () != size[i])
+        {
+          error ("interpn: incompatible size of argument number %d", i+1);
+          return retval;
+        }
+      else
+        x[i] = X[i].data ();
+    }
+
+  lin_interpn (n, size, scale, Ni, extrapval, x, v, y, vi);
+
+  retval = Vi;
+
+  return retval;
+}
+
+// Perform @var{n}-dimensional interpolation.  Each element of then
+// @var{n}-dimensional array @var{v} represents a value at a location
+// given by the parameters @var{x1}, @var{x2},...,@var{xn}. The parameters
+// @var{x1}, @var{x2}, @dots{}, @var{xn} are either @var{n}-dimensional
+// arrays of the same size as the array @var{v} in the \"ndgrid\" format
+// or vectors.  The parameters @var{y1}, @var{y2}, @dots{}, @var{yn} are
+// all @var{n}-dimensional arrays of the same size and represent the
+// points at which the array @var{vi} is interpolated.
+//
+//This function only performs linear interpolation.
+
+DEFUN (__lin_interpn__, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{vi} =} __lin_interpn__ (@var{x1}, @var{x2}, @dots{}, @var{xn}, @var{v}, @var{y1}, @var{y2}, @dots{}, @var{yn})\n\
+Undocumented internal function.\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 2 ||  nargin % 2 == 0)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  // dimension of the problem
+  int n = (nargin-1)/2;
+
+  if (args(n).is_single_type ())
+    {
+      OCTAVE_LOCAL_BUFFER (FloatNDArray, X, n);
+      OCTAVE_LOCAL_BUFFER (FloatNDArray, Y, n);
+
+      const FloatNDArray V = args(n).float_array_value ();
+
+      if (error_state)
+        {
+          print_usage ();
+          return retval;
+        }
+
+      for (int i = 0; i < n; i++)
+        {
+          X[i] = args(i).float_array_value ();
+          Y[i] = args(n+i+1).float_array_value ();
+
+          if (error_state)
+            {
+              print_usage ();
+              return retval;
+            }
+
+          if (Y[0].dims () != Y[i].dims ())
+            {
+              error ("interpn: incompatible size of argument number %d", n+i+2);
+              return retval;
+            }
+        }
+
+      retval = lin_interpn<float, FloatNDArray> (n, X, V, Y);
+    }
+  else
+    {
+      OCTAVE_LOCAL_BUFFER (NDArray, X, n);
+      OCTAVE_LOCAL_BUFFER (NDArray, Y, n);
+
+      const NDArray V = args(n).array_value ();
+
+      if (error_state)
+        {
+          print_usage ();
+          return retval;
+        }
+
+      for (int i = 0; i < n; i++)
+        {
+          X[i] = args(i).array_value ();
+          Y[i] = args(n+i+1).array_value ();
+
+          if (error_state)
+            {
+              print_usage ();
+              return retval;
+            }
+
+          if (Y[0].dims () != Y[i].dims ())
+            {
+              error ("interpn: incompatible size of argument number %d", n+i+2);
+              return retval;
+            }
+        }
+
+      retval = lin_interpn<double, NDArray> (n, X, V, Y);
+    }
+
+  return retval;
+}
+
+/*
+## No test needed for internal helper function.
+%!assert (1)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/__pchip_deriv__.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,168 @@
+/*
+
+Copyright (C) 2002-2012 Kai Habel
+Copyright (C) 2008-2009 Jaroslav Hajek
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+#include "f77-fcn.h"
+
+extern "C"
+{
+  F77_RET_T
+  F77_FUNC (dpchim, DPCHIM) (const octave_idx_type& n, const double *x,
+                             const double *f, double *d,
+                             const octave_idx_type &incfd,
+                             octave_idx_type *ierr);
+
+  F77_RET_T
+  F77_FUNC (pchim, PCHIM) (const octave_idx_type& n, const float *x,
+                           const float *f, float *d,
+                           const octave_idx_type& incfd,
+                           octave_idx_type *ierr);
+}
+
+// Wrapper for SLATEC/PCHIP function DPCHIM to calculate the derivates
+// for piecewise polynomials.
+
+DEFUN (__pchip_deriv__, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} __pchip_deriv__ (@var{x}, @var{y}, @var{dim})\n\
+Undocumented internal function.\n\
+@end deftypefn")
+{
+  octave_value retval;
+  const int nargin = args.length ();
+
+  bool rows = (nargin == 3 && args (2).uint_value () == 2);
+
+  if (nargin >= 2)
+    {
+      if (args(0).is_single_type () || args(1).is_single_type ())
+        {
+          FloatColumnVector xvec (args(0).float_vector_value ());
+          FloatMatrix ymat (args(1).float_matrix_value ());
+
+          octave_idx_type nx = xvec.length ();
+
+          if (nx < 2)
+            {
+              error ("__pchip_deriv__: X must be at least of length 2");
+              return retval;
+            }
+
+          octave_idx_type nyr = ymat.rows ();
+          octave_idx_type nyc = ymat.columns ();
+
+          if (nx != (rows ? nyc : nyr))
+            {
+              error ("__pchip_deriv__: X and Y dimension mismatch");
+              return retval;
+            }
+
+          const float *yvec = ymat.data ();
+          FloatMatrix dmat (nyr, nyc);
+          float *dvec = dmat.fortran_vec ();
+
+          octave_idx_type ierr;
+          const octave_idx_type incfd = rows ? nyr : 1;
+          const octave_idx_type inc = rows ? 1 : nyr;
+
+          for (octave_idx_type i = (rows ? nyr : nyc); i > 0; i--)
+            {
+              F77_FUNC (pchim, PCHIM) (nx, xvec.data (),
+                                       yvec, dvec, incfd, &ierr);
+
+              yvec += inc;
+              dvec += inc;
+
+              if (ierr < 0)
+                {
+                  error ("PCHIM: error: %i\n", ierr);
+                  return retval;
+                }
+            }
+
+          retval = dmat;
+        }
+      else
+        {
+          ColumnVector xvec (args(0).vector_value ());
+          Matrix ymat (args(1).matrix_value ());
+
+          octave_idx_type nx = xvec.length ();
+
+          if (nx < 2)
+            {
+              error ("__pchip_deriv__: X must be at least of length 2");
+              return retval;
+            }
+
+          octave_idx_type nyr = ymat.rows ();
+          octave_idx_type nyc = ymat.columns ();
+
+          if (nx != (rows ? nyc : nyr))
+            {
+              error ("__pchip_deriv__: X and Y dimension mismatch");
+              return retval;
+            }
+
+          const double *yvec = ymat.data ();
+          Matrix dmat (nyr, nyc);
+          double *dvec = dmat.fortran_vec ();
+
+          octave_idx_type ierr;
+          const octave_idx_type incfd = rows ? nyr : 1;
+          const octave_idx_type inc = rows ? 1 : nyr;
+
+          for (octave_idx_type i = (rows ? nyr : nyc); i > 0; i--)
+            {
+              F77_FUNC (dpchim, DPCHIM) (nx, xvec.data (),
+                                         yvec, dvec, incfd, &ierr);
+
+              yvec += inc;
+              dvec += inc;
+
+              if (ierr < 0)
+                {
+                  error ("DPCHIM: error: %i\n", ierr);
+                  return retval;
+                }
+            }
+
+          retval = dmat;
+        }
+    }
+
+  return retval;
+}
+
+/*
+## No test needed for internal helper function.
+%!assert (1)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/__qp__.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,535 @@
+/*
+
+Copyright (C) 2000-2012 Gabriele Pannocchia
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cfloat>
+
+#include "dbleCHOL.h"
+#include "dbleSVD.h"
+#include "mx-m-dm.h"
+#include "EIG.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "pr-output.h"
+#include "utils.h"
+
+static Matrix
+null (const Matrix& A, octave_idx_type& rank)
+{
+  Matrix retval;
+
+  rank = 0;
+
+  if (! A.is_empty ())
+    {
+      SVD A_svd (A);
+
+      DiagMatrix S = A_svd.singular_values ();
+
+      ColumnVector s = S.diag ();
+
+      Matrix V = A_svd.right_singular_matrix ();
+
+      octave_idx_type A_nr = A.rows ();
+      octave_idx_type A_nc = A.cols ();
+
+      octave_idx_type tmp = A_nr > A_nc ? A_nr : A_nc;
+
+      double tol = tmp * s(0) * DBL_EPSILON;
+
+      octave_idx_type n = s.length ();
+
+      for (octave_idx_type i = 0; i < n; i++)
+        {
+          if (s(i) > tol)
+            rank++;
+        }
+
+      if (rank < A_nc)
+        retval = V.extract (0, rank, A_nc-1, A_nc-1);
+      else
+        retval.resize (A_nc, 0);
+
+      for (octave_idx_type i = 0; i < retval.numel (); i++)
+        if (std::abs (retval(i)) < DBL_EPSILON)
+          retval(i) = 0;
+    }
+
+  return retval;
+}
+
+static int
+qp (const Matrix& H, const ColumnVector& q,
+    const Matrix& Aeq, const ColumnVector& beq,
+    const Matrix& Ain, const ColumnVector& bin,
+    int maxit,
+    ColumnVector& x, ColumnVector& lambda, int& iter)
+{
+  int info = 0;
+
+  iter = 0;
+
+  double rtol = sqrt (DBL_EPSILON);
+
+  // Problem dimension.
+  octave_idx_type n = x.length ();
+
+  // Dimension of constraints.
+  octave_idx_type n_eq = beq.length ();
+  octave_idx_type n_in = bin.length ();
+
+  // Filling the current active set.
+
+  octave_idx_type n_act = n_eq;
+
+  octave_idx_type n_tot = n_eq + n_in;
+
+  // Equality constraints come first.  We won't check the sign of the
+  // Lagrange multiplier for those.
+
+  Matrix Aact = Aeq;
+  ColumnVector bact = beq;
+  ColumnVector Wact;
+
+  if (n_in > 0)
+    {
+      ColumnVector res = Ain*x - bin;
+
+      for (octave_idx_type i = 0; i < n_in; i++)
+        {
+          res(i) /= (1.0 + std::abs (bin(i)));
+
+          if (res(i) < rtol)
+            {
+              n_act++;
+              Aact = Aact.stack (Ain.row (i));
+              bact.resize (n_act, bin(i));
+              Wact.resize (n_act-n_eq, i);
+            }
+        }
+    }
+
+  // Computing the ???
+
+  EIG eigH (H);
+
+  if (error_state)
+    {
+      error ("qp: failed to compute eigenvalues of H");
+      return -1;
+    }
+
+  ColumnVector eigenvalH = real (eigH.eigenvalues ());
+  Matrix eigenvecH = real (eigH.eigenvectors ());
+  double minReal = eigenvalH.min ();
+  octave_idx_type indminR = 0;
+  for (octave_idx_type i = 0; i < n; i++)
+    {
+      if (minReal == eigenvalH(i))
+        {
+          indminR = i;
+          break;
+        }
+    }
+
+  bool done = false;
+
+  double alpha = 0.0;
+
+  Matrix R;
+  Matrix Y (n, 0, 0.0);
+
+  ColumnVector g (n, 0.0);
+  ColumnVector p (n, 0.0);
+
+  ColumnVector lambda_tmp (n_in, 0.0);
+
+  while (! done)
+    {
+      iter++;
+
+      // Current Gradient
+      // g = q + H * x;
+
+      g = q + H * x;
+
+      if (n_act == 0)
+        {
+          // There are no active constraints.
+
+          if (minReal > 0.0)
+            {
+              // Inverting the Hessian.  Using the Cholesky
+              // factorization since the Hessian is positive
+              // definite.
+
+              CHOL cholH (H);
+
+              R = cholH.chol_matrix ();
+
+              Matrix Hinv = chol2inv (R);
+
+              // Computing the unconstrained step.
+              // p = -Hinv * g;
+
+              p = -Hinv * g;
+
+              info = 0;
+            }
+          else
+            {
+              // Finding the negative curvature of H.
+
+              p = eigenvecH.column (indminR);
+
+              // Following the negative curvature of H.
+
+              if (p.transpose () * g > DBL_EPSILON)
+                p = -p;
+
+              info = 1;
+            }
+
+          // Multipliers are zero.
+          lambda_tmp.fill (0.0);
+        }
+      else
+        {
+          // There are active constraints.
+
+          // Computing the null space.
+
+          octave_idx_type rank;
+
+          Matrix Z = null (Aact, rank);
+
+          octave_idx_type dimZ = n - rank;
+
+          // FIXME -- still remain to handle the case of
+          // non-full rank active set matrix.
+
+          // Computing the Y matrix (orthogonal to Z)
+          Y = Aact.pseudo_inverse ();
+
+          // Reduced Hessian
+          Matrix Zt = Z.transpose ();
+          Matrix rH = Zt * H * Z;
+
+          octave_idx_type pR = 0;
+
+          if (dimZ > 0)
+            {
+              // Computing the Cholesky factorization (pR = 0 means
+              // that the reduced Hessian was positive definite).
+
+              CHOL cholrH (rH, pR);
+              Matrix tR = cholrH.chol_matrix ();
+              if (pR == 0)
+                R = tR;
+            }
+
+          if (pR == 0)
+            {
+              info = 0;
+
+              // Computing the step pz.
+              if (dimZ > 0)
+                {
+                  // Using the Cholesky factorization to invert rH
+
+                  Matrix rHinv = chol2inv (R);
+
+                  ColumnVector pz = -rHinv * Zt * g;
+
+                  // Global step.
+                  p = Z * pz;
+                }
+              else
+                {
+                  // Global step.
+                  p.fill (0.0);
+                }
+            }
+          else
+            {
+              info = 1;
+
+              // Searching for the most negative curvature.
+
+              EIG eigrH (rH);
+
+              if (error_state)
+                {
+                  error ("qp: failed to compute eigenvalues of rH");
+                  return -1;
+                }
+
+              ColumnVector eigenvalrH = real (eigrH.eigenvalues ());
+              Matrix eigenvecrH = real (eigrH.eigenvectors ());
+              double mRrH = eigenvalrH.min ();
+              indminR = 0;
+              for (octave_idx_type i = 0; i < n; i++)
+                {
+                  if (mRrH == eigenvalH(i))
+                    {
+                      indminR = i;
+                      break;
+                    }
+                }
+
+              ColumnVector eVrH = eigenvecrH.column (indminR);
+
+              // Computing the step pz.
+              p = Z * eVrH;
+
+              if (p.transpose () * g > DBL_EPSILON)
+                p = -p;
+            }
+        }
+
+      // Checking the step-size.
+      ColumnVector abs_p (n);
+      for (octave_idx_type i = 0; i < n; i++)
+        abs_p(i) = std::abs (p(i));
+      double max_p = abs_p.max ();
+
+      if (max_p < rtol)
+        {
+          // The step is null.  Checking constraints.
+          if (n_act - n_eq == 0)
+            // Solution is found because no inequality
+            // constraints are active.
+            done = true;
+          else
+            {
+              // Computing the multipliers only for the inequality
+              // constraints that are active.  We do NOT compute
+              // multipliers for the equality constraints.
+              Matrix Yt = Y.transpose ();
+              Yt = Yt.extract_n (n_eq, 0, n_act-n_eq, n);
+              lambda_tmp = Yt * (g + H * p);
+
+              // Checking the multipliers.  We remove the most
+              // negative from the set (if any).
+              double min_lambda = lambda_tmp.min ();
+              if (min_lambda >= 0)
+                {
+                  // Solution is found.
+                  done = true;
+                }
+              else
+                {
+                  octave_idx_type which_eig = 0;
+                  for (octave_idx_type i = 0; i < n_act; i++)
+                    {
+                      if (lambda_tmp(i) == min_lambda)
+                        {
+                          which_eig = i;
+                          break;
+                        }
+                    }
+
+                  // At least one multiplier is negative, we
+                  // remove it from the set.
+
+                  n_act--;
+                  for (octave_idx_type i = which_eig; i < n_act - n_eq; i++)
+                    {
+                      Wact(i) = Wact(i+1);
+                      for (octave_idx_type j = 0; j < n; j++)
+                        Aact(n_eq+i,j) = Aact(n_eq+i+1,j);
+                      bact(n_eq+i) = bact(n_eq+i+1);
+                    }
+
+                  // Resizing the active set.
+                  Wact.resize (n_act-n_eq);
+                  bact.resize (n_act);
+                  Aact.resize (n_act, n);
+                }
+            }
+        }
+      else
+        {
+          // The step is not null.
+          if (n_act - n_eq == n_in)
+            {
+              // All inequality constraints were active.  We can
+              // add the whole step.
+              x += p;
+            }
+          else
+            {
+              // Some constraints were not active.  Checking if
+              // there is a blocking constraint.
+              alpha = 1.0;
+              octave_idx_type is_block = -1;
+
+              for (octave_idx_type i = 0; i < n_in; i++)
+                {
+                  bool found = false;
+
+                  for (octave_idx_type j = 0; j < n_act-n_eq; j++)
+                    {
+                      if (Wact(j) == i)
+                        {
+                          found = true;
+                          break;
+                        }
+                    }
+
+                  if (! found)
+                    {
+                      // The i-th constraint was not in the set.  Is it a
+                      // blocking constraint?
+
+                      RowVector tmp_row = Ain.row (i);
+                      double tmp = tmp_row * p;
+                      double res = tmp_row * x;
+
+                      if (tmp < 0.0)
+                        {
+                          double alpha_tmp = (bin(i) - res) / tmp;
+
+                          if (alpha_tmp < alpha)
+                            {
+                              alpha = alpha_tmp;
+                              is_block = i;
+                            }
+                        }
+                    }
+                }
+
+              // In is_block there is the index of the blocking
+              // constraint (if any).
+              if (is_block >= 0)
+                {
+                  // There is a blocking constraint (index in
+                  // is_block) which is added to the active set.
+                  n_act++;
+                  Aact = Aact.stack (Ain.row (is_block));
+                  bact.resize (n_act, bin(is_block));
+                  Wact.resize (n_act-n_eq, is_block);
+
+                  // Adding the reduced step
+                  x += alpha * p;
+                }
+              else
+                {
+                  // There are no blocking constraints.  Adding the
+                  // whole step.
+                  x += alpha * p;
+                }
+            }
+        }
+
+      if (iter == maxit)
+        {
+          done = true;
+          // warning ("qp_main: maximum number of iteration reached");
+          info = 3;
+        }
+    }
+
+  lambda_tmp = Y.transpose () * (g + H * p);
+
+  // Reordering the Lagrange multipliers.
+
+  lambda.resize (n_tot);
+  lambda.fill (0.0);
+  for (octave_idx_type i = 0; i < n_eq; i++)
+    lambda(i) = lambda_tmp(i);
+
+  for (octave_idx_type i = n_eq; i < n_tot; i++)
+    {
+      for (octave_idx_type j = 0; j < n_act-n_eq; j++)
+        {
+          if (Wact(j) == i - n_eq)
+            {
+              lambda(i) = lambda_tmp(n_eq+j);
+              break;
+            }
+        }
+    }
+
+  return info;
+}
+
+DEFUN (__qp__, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {[@var{x}, @var{lambda}, @var{info}, @var{iter}] =} __qp__ (@var{x0}, @var{H}, @var{q}, @var{Aeq}, @var{beq}, @var{Ain}, @var{bin}, @var{maxit})\n\
+Undocumented internal function.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  if (args.length () == 8)
+    {
+      const ColumnVector x0  (args(0) . vector_value ());
+      const Matrix H         (args(1) . matrix_value ());
+      const ColumnVector q   (args(2) . vector_value ());
+      const Matrix Aeq       (args(3) . matrix_value ());
+      const ColumnVector beq (args(4) . vector_value ());
+      const Matrix Ain       (args(5) . matrix_value ());
+      const ColumnVector bin (args(6) . vector_value ());
+      const int maxit        (args(7) . int_value ());
+
+      if (! error_state)
+        {
+          int iter = 0;
+
+          // Copying the initial guess in the working variable
+          ColumnVector x = x0;
+
+          // Reordering the Lagrange multipliers
+          ColumnVector lambda;
+
+          int info = qp (H, q, Aeq, beq, Ain, bin, maxit, x, lambda, iter);
+
+          if (! error_state)
+            {
+              retval(3) = iter;
+              retval(2) = info;
+              retval(1) = lambda;
+              retval(0) = x;
+            }
+          else
+            error ("qp: internal error");
+        }
+      else
+        error ("__qp__: invalid arguments");
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+## No test needed for internal helper function.
+%!assert (1)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/balance.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,389 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+Copyright (C) 2008-2009 Jaroslav Hajek
+
+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/>.
+
+*/
+
+// Author: A. S. Hodel <scotte@eng.auburn.edu>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+
+#include "CmplxAEPBAL.h"
+#include "fCmplxAEPBAL.h"
+#include "dbleAEPBAL.h"
+#include "floatAEPBAL.h"
+#include "CmplxGEPBAL.h"
+#include "fCmplxGEPBAL.h"
+#include "dbleGEPBAL.h"
+#include "floatGEPBAL.h"
+#include "quit.h"
+
+#include "defun.h"
+#include "error.h"
+#include "f77-fcn.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+DEFUN (balance, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{AA} =} balance (@var{A})\n\
+@deftypefnx {Built-in Function} {@var{AA} =} balance (@var{A}, @var{opt})\n\
+@deftypefnx {Built-in Function} {[@var{DD}, @var{AA}] =} balance (@var{A}, @var{opt})\n\
+@deftypefnx {Built-in Function} {[@var{D}, @var{P}, @var{AA}] =} balance (@var{A}, @var{opt})\n\
+@deftypefnx {Built-in Function} {[@var{CC}, @var{DD}, @var{AA}, @var{BB}] =} balance (@var{A}, @var{B}, @var{opt})\n\
+\n\
+Compute @code{@var{AA} = @var{DD} \\ @var{A} * @var{DD}} in which @var{AA}\n\
+is a matrix whose row and column norms are roughly equal in magnitude, and\n\
+@code{@var{DD} = @var{P} * @var{D}}, in which @var{P} is a permutation\n\
+matrix and @var{D} is a diagonal matrix of powers of two.  This allows the\n\
+equilibration to be computed without round-off.  Results of eigenvalue\n\
+calculation are typically improved by balancing first.\n\
+\n\
+If two output values are requested, @code{balance} returns\n\
+the diagonal @var{D} and the permutation @var{P} separately as vectors.\n\
+In this case, @code{@var{DD} = eye(n)(:,@var{P}) * diag (@var{D})}, where\n\
+@math{n} is the matrix size.\n\
+\n\
+If four output values are requested, compute @code{@var{AA} =\n\
+@var{CC}*@var{A}*@var{DD}} and @code{@var{BB} = @var{CC}*@var{B}*@var{DD}},\n\
+in which @var{AA} and @var{BB} have non-zero elements of approximately the\n\
+same magnitude and @var{CC} and @var{DD} are permuted diagonal matrices as\n\
+in @var{DD} for the algebraic eigenvalue problem.\n\
+\n\
+The eigenvalue balancing option @var{opt} may be one of:\n\
+\n\
+@table @asis\n\
+@item \"noperm\", \"S\"\n\
+Scale only; do not permute.\n\
+\n\
+@item \"noscal\", \"P\"\n\
+Permute only; do not scale.\n\
+@end table\n\
+\n\
+Algebraic eigenvalue balancing uses standard @sc{lapack} routines.\n\
+\n\
+Generalized eigenvalue problem balancing uses Ward's algorithm\n\
+(SIAM Journal on Scientific and Statistical Computing, 1981).\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 1 || nargin > 3 || nargout < 0 || nargout > 4)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  // determine if it's AEP or GEP
+  bool AEPcase = nargin == 1 || args(1).is_string ();
+
+  // problem dimension
+  octave_idx_type nn = args(0).rows ();
+
+  if (nn != args(0).columns ())
+    {
+      gripe_square_matrix_required ("balance");
+      return retval;
+    }
+
+  bool isfloat = args(0).is_single_type () ||
+    (! AEPcase && args(1).is_single_type ());
+
+  bool complex_case = (args(0).is_complex_type () ||
+                       (! AEPcase && args(1).is_complex_type ()));
+
+  // Extract argument 1 parameter for both AEP and GEP.
+  Matrix aa;
+  ComplexMatrix caa;
+  FloatMatrix faa;
+  FloatComplexMatrix fcaa;
+
+  if (isfloat)
+    {
+      if (complex_case)
+        fcaa = args(0).float_complex_matrix_value ();
+      else
+        faa = args(0).float_matrix_value ();
+    }
+  else
+    {
+      if (complex_case)
+        caa = args(0).complex_matrix_value ();
+      else
+        aa = args(0).matrix_value ();
+    }
+
+  if (error_state)
+    return retval;
+
+  // Treat AEP/GEP cases.
+  if (AEPcase)
+    {
+      // Algebraic eigenvalue problem.
+      bool noperm = false, noscal = false;
+      if (nargin > 1)
+        {
+          std::string a1s = args(1).string_value ();
+          noperm = a1s == "noperm" || a1s == "S";
+          noscal = a1s == "noscal" || a1s == "P";
+        }
+
+      // balance the AEP
+      if (isfloat)
+        {
+          if (complex_case)
+            {
+              FloatComplexAEPBALANCE result (fcaa, noperm, noscal);
+
+              if (nargout == 0 || nargout == 1)
+                retval(0) = result.balanced_matrix ();
+              else if (nargout == 2)
+                {
+                  retval(1) = result.balanced_matrix ();
+                  retval(0) = result.balancing_matrix ();
+                }
+              else
+                {
+                  retval(2) = result.balanced_matrix ();
+                  retval(1) = result.permuting_vector ();
+                  retval(0) = result.scaling_vector ();
+                }
+
+            }
+          else
+            {
+              FloatAEPBALANCE result (faa, noperm, noscal);
+
+              if (nargout == 0 || nargout == 1)
+                retval(0) = result.balanced_matrix ();
+              else if (nargout == 2)
+                {
+                  retval(1) = result.balanced_matrix ();
+                  retval(0) = result.balancing_matrix ();
+                }
+              else
+                {
+                  retval(2) = result.balanced_matrix ();
+                  retval(1) = result.permuting_vector ();
+                  retval(0) = result.scaling_vector ();
+                }
+            }
+        }
+      else
+        {
+          if (complex_case)
+            {
+              ComplexAEPBALANCE result (caa, noperm, noscal);
+
+              if (nargout == 0 || nargout == 1)
+                retval(0) = result.balanced_matrix ();
+              else if (nargout == 2)
+                {
+                  retval(1) = result.balanced_matrix ();
+                  retval(0) = result.balancing_matrix ();
+                }
+              else
+                {
+                  retval(2) = result.balanced_matrix ();
+                  retval(1) = result.permuting_vector ();
+                  retval(0) = result.scaling_vector ();
+                }
+            }
+          else
+            {
+              AEPBALANCE result (aa, noperm, noscal);
+
+              if (nargout == 0 || nargout == 1)
+                retval(0) = result.balanced_matrix ();
+              else if (nargout == 2)
+                {
+                  retval(1) = result.balanced_matrix ();
+                  retval(0) = result.balancing_matrix ();
+                }
+              else
+                {
+                  retval(2) = result.balanced_matrix ();
+                  retval(1) = result.permuting_vector ();
+                  retval(0) = result.scaling_vector ();
+                }
+            }
+        }
+    }
+  else
+    {
+      std::string bal_job;
+      if (nargout == 1)
+        warning ("balance: used GEP, should have two output arguments");
+
+      // Generalized eigenvalue problem.
+      if (nargin == 2)
+        bal_job = "B";
+      else if (args(2).is_string ())
+        bal_job = args(2).string_value ();
+      else
+        {
+          error ("balance: OPT argument must be a string");
+          return retval;
+        }
+
+      if ((nn != args(1).columns ()) || (nn != args(1).rows ()))
+        {
+          gripe_nonconformant ();
+          return retval;
+        }
+
+      Matrix bb;
+      ComplexMatrix cbb;
+      FloatMatrix fbb;
+      FloatComplexMatrix fcbb;
+
+      if (isfloat)
+        {
+          if (complex_case)
+            fcbb = args(1).float_complex_matrix_value ();
+          else
+            fbb = args(1).float_matrix_value ();
+        }
+      else
+        {
+          if (complex_case)
+            cbb = args(1).complex_matrix_value ();
+          else
+            bb = args(1).matrix_value ();
+        }
+
+      // balance the GEP
+      if (isfloat)
+        {
+          if (complex_case)
+            {
+              FloatComplexGEPBALANCE result (fcaa, fcbb, bal_job);
+
+              switch (nargout)
+                {
+                case 4:
+                  retval(3) = result.balanced_matrix2 ();
+                  // fall through
+                case 3:
+                  retval(2) = result.balanced_matrix ();
+                  retval(1) = result.balancing_matrix2 ();
+                  retval(0) = result.balancing_matrix ();
+                  break;
+                case 2:
+                  retval(1) = result.balancing_matrix2 ();
+                  // fall through
+                case 1:
+                  retval(0) = result.balancing_matrix ();
+                  break;
+                default:
+                  error ("balance: invalid number of output arguments");
+                  break;
+                }
+            }
+          else
+            {
+              FloatGEPBALANCE result (faa, fbb, bal_job);
+
+              switch (nargout)
+                {
+                case 4:
+                  retval(3) = result.balanced_matrix2 ();
+                  // fall through
+                case 3:
+                  retval(2) = result.balanced_matrix ();
+                  retval(1) = result.balancing_matrix2 ();
+                  retval(0) = result.balancing_matrix ();
+                  break;
+                case 2:
+                  retval(1) = result.balancing_matrix2 ();
+                  // fall through
+                case 1:
+                  retval(0) = result.balancing_matrix ();
+                  break;
+                default:
+                  error ("balance: invalid number of output arguments");
+                  break;
+                }
+            }
+        }
+      else
+        {
+          if (complex_case)
+            {
+              ComplexGEPBALANCE result (caa, cbb, bal_job);
+
+              switch (nargout)
+                {
+                case 4:
+                  retval(3) = result.balanced_matrix2 ();
+                  // fall through
+                case 3:
+                  retval(2) = result.balanced_matrix ();
+                  retval(1) = result.balancing_matrix2 ();
+                  retval(0) = result.balancing_matrix ();
+                  break;
+                case 2:
+                  retval(1) = result.balancing_matrix2 ();
+                  // fall through
+                case 1:
+                  retval(0) = result.balancing_matrix ();
+                  break;
+                default:
+                  error ("balance: invalid number of output arguments");
+                  break;
+                }
+            }
+          else
+            {
+              GEPBALANCE result (aa, bb, bal_job);
+
+              switch (nargout)
+                {
+                case 4:
+                  retval(3) = result.balanced_matrix2 ();
+                  // fall through
+                case 3:
+                  retval(2) = result.balanced_matrix ();
+                  retval(1) = result.balancing_matrix2 ();
+                  retval(0) = result.balancing_matrix ();
+                  break;
+                case 2:
+                  retval(1) = result.balancing_matrix2 ();
+                  // fall through
+                case 1:
+                  retval(0) = result.balancing_matrix ();
+                  break;
+                default:
+                  error ("balance: invalid number of output arguments");
+                  break;
+                }
+            }
+        }
+    }
+
+  return retval;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/besselj.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,1246 @@
+/*
+
+Copyright (C) 1997-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "lo-specfun.h"
+#include "quit.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+enum bessel_type
+{
+  BESSEL_J,
+  BESSEL_Y,
+  BESSEL_I,
+  BESSEL_K,
+  BESSEL_H1,
+  BESSEL_H2
+};
+
+#define DO_BESSEL(type, alpha, x, scaled, ierr, result) \
+  do \
+    { \
+      switch (type) \
+        { \
+          case BESSEL_J: \
+            result = besselj (alpha, x, scaled, ierr); \
+            break; \
+ \
+          case BESSEL_Y: \
+            result = bessely (alpha, x, scaled, ierr); \
+            break; \
+ \
+          case BESSEL_I: \
+            result = besseli (alpha, x, scaled, ierr); \
+            break; \
+ \
+          case BESSEL_K: \
+            result = besselk (alpha, x, scaled, ierr); \
+            break; \
+ \
+          case BESSEL_H1: \
+            result = besselh1 (alpha, x, scaled, ierr); \
+            break; \
+ \
+          case BESSEL_H2: \
+            result = besselh2 (alpha, x, scaled, ierr); \
+            break; \
+ \
+          default: \
+            break; \
+        } \
+    } \
+  while (0)
+
+static void
+gripe_bessel_arg (const char *fn, const char *arg)
+{
+  error ("%s: expecting scalar or matrix as %s argument", fn, arg);
+}
+
+octave_value_list
+do_bessel (enum bessel_type type, const char *fn,
+           const octave_value_list& args, int nargout)
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin == 2 || nargin == 3)
+    {
+      bool scaled = (nargin == 3);
+
+      octave_value alpha_arg = args(0);
+      octave_value x_arg = args(1);
+
+      if (alpha_arg.is_single_type () || x_arg.is_single_type ())
+        {
+          if (alpha_arg.is_scalar_type ())
+            {
+              float alpha = args(0).float_value ();
+
+              if (! error_state)
+                {
+                  if (x_arg.is_scalar_type ())
+                    {
+                      FloatComplex x = x_arg.float_complex_value ();
+
+                      if (! error_state)
+                        {
+                          octave_idx_type ierr;
+                          octave_value result;
+
+                          DO_BESSEL (type, alpha, x, scaled, ierr, result);
+
+                          if (nargout > 1)
+                            retval(1) = static_cast<float> (ierr);
+
+                          retval(0) = result;
+                        }
+                      else
+                        gripe_bessel_arg (fn, "second");
+                    }
+                  else
+                    {
+                      FloatComplexNDArray x = x_arg.float_complex_array_value ();
+
+                      if (! error_state)
+                        {
+                          Array<octave_idx_type> ierr;
+                          octave_value result;
+
+                          DO_BESSEL (type, alpha, x, scaled, ierr, result);
+
+                          if (nargout > 1)
+                            retval(1) = NDArray (ierr);
+
+                          retval(0) = result;
+                        }
+                      else
+                        gripe_bessel_arg (fn, "second");
+                    }
+                }
+              else
+                gripe_bessel_arg (fn, "first");
+            }
+          else
+            {
+              dim_vector dv0 = args(0).dims ();
+              dim_vector dv1 = args(1).dims ();
+
+              bool args0_is_row_vector = (dv0 (1) == dv0.numel ());
+              bool args1_is_col_vector = (dv1 (0) == dv1.numel ());
+
+              if (args0_is_row_vector && args1_is_col_vector)
+                {
+                  FloatRowVector ralpha = args(0).float_row_vector_value ();
+
+                  if (! error_state)
+                    {
+                      FloatComplexColumnVector cx =
+                        x_arg.float_complex_column_vector_value ();
+
+                      if (! error_state)
+                        {
+                          Array<octave_idx_type> ierr;
+                          octave_value result;
+
+                          DO_BESSEL (type, ralpha, cx, scaled, ierr, result);
+
+                          if (nargout > 1)
+                            retval(1) = NDArray (ierr);
+
+                          retval(0) = result;
+                        }
+                      else
+                        gripe_bessel_arg (fn, "second");
+                    }
+                  else
+                    gripe_bessel_arg (fn, "first");
+                }
+              else
+                {
+                  FloatNDArray alpha = args(0).float_array_value ();
+
+                  if (! error_state)
+                    {
+                      if (x_arg.is_scalar_type ())
+                        {
+                          FloatComplex x = x_arg.float_complex_value ();
+
+                          if (! error_state)
+                            {
+                              Array<octave_idx_type> ierr;
+                              octave_value result;
+
+                              DO_BESSEL (type, alpha, x, scaled, ierr, result);
+
+                              if (nargout > 1)
+                                retval(1) = NDArray (ierr);
+
+                              retval(0) = result;
+                            }
+                          else
+                            gripe_bessel_arg (fn, "second");
+                        }
+                      else
+                        {
+                          FloatComplexNDArray x = x_arg.float_complex_array_value ();
+
+                          if (! error_state)
+                            {
+                              Array<octave_idx_type> ierr;
+                              octave_value result;
+
+                              DO_BESSEL (type, alpha, x, scaled, ierr, result);
+
+                              if (nargout > 1)
+                                retval(1) = NDArray (ierr);
+
+                              retval(0) = result;
+                            }
+                          else
+                            gripe_bessel_arg (fn, "second");
+                        }
+                    }
+                  else
+                    gripe_bessel_arg (fn, "first");
+                }
+            }
+        }
+      else
+        {
+          if (alpha_arg.is_scalar_type ())
+            {
+              double alpha = args(0).double_value ();
+
+              if (! error_state)
+                {
+                  if (x_arg.is_scalar_type ())
+                    {
+                      Complex x = x_arg.complex_value ();
+
+                      if (! error_state)
+                        {
+                          octave_idx_type ierr;
+                          octave_value result;
+
+                          DO_BESSEL (type, alpha, x, scaled, ierr, result);
+
+                          if (nargout > 1)
+                            retval(1) = static_cast<double> (ierr);
+
+                          retval(0) = result;
+                        }
+                      else
+                        gripe_bessel_arg (fn, "second");
+                    }
+                  else
+                    {
+                      ComplexNDArray x = x_arg.complex_array_value ();
+
+                      if (! error_state)
+                        {
+                          Array<octave_idx_type> ierr;
+                          octave_value result;
+
+                          DO_BESSEL (type, alpha, x, scaled, ierr, result);
+
+                          if (nargout > 1)
+                            retval(1) = NDArray (ierr);
+
+                          retval(0) = result;
+                        }
+                      else
+                        gripe_bessel_arg (fn, "second");
+                    }
+                }
+              else
+                gripe_bessel_arg (fn, "first");
+            }
+          else
+            {
+              dim_vector dv0 = args(0).dims ();
+              dim_vector dv1 = args(1).dims ();
+
+              bool args0_is_row_vector = (dv0 (1) == dv0.numel ());
+              bool args1_is_col_vector = (dv1 (0) == dv1.numel ());
+
+              if (args0_is_row_vector && args1_is_col_vector)
+                {
+                  RowVector ralpha = args(0).row_vector_value ();
+
+                  if (! error_state)
+                    {
+                      ComplexColumnVector cx =
+                        x_arg.complex_column_vector_value ();
+
+                      if (! error_state)
+                        {
+                          Array<octave_idx_type> ierr;
+                          octave_value result;
+
+                          DO_BESSEL (type, ralpha, cx, scaled, ierr, result);
+
+                          if (nargout > 1)
+                            retval(1) = NDArray (ierr);
+
+                          retval(0) = result;
+                        }
+                      else
+                        gripe_bessel_arg (fn, "second");
+                    }
+                  else
+                    gripe_bessel_arg (fn, "first");
+                }
+              else
+                {
+                  NDArray alpha = args(0).array_value ();
+
+                  if (! error_state)
+                    {
+                      if (x_arg.is_scalar_type ())
+                        {
+                          Complex x = x_arg.complex_value ();
+
+                          if (! error_state)
+                            {
+                              Array<octave_idx_type> ierr;
+                              octave_value result;
+
+                              DO_BESSEL (type, alpha, x, scaled, ierr, result);
+
+                              if (nargout > 1)
+                                retval(1) = NDArray (ierr);
+
+                              retval(0) = result;
+                            }
+                          else
+                            gripe_bessel_arg (fn, "second");
+                        }
+                      else
+                        {
+                          ComplexNDArray x = x_arg.complex_array_value ();
+
+                          if (! error_state)
+                            {
+                              Array<octave_idx_type> ierr;
+                              octave_value result;
+
+                              DO_BESSEL (type, alpha, x, scaled, ierr, result);
+
+                              if (nargout > 1)
+                                retval(1) = NDArray (ierr);
+
+                              retval(0) = result;
+                            }
+                          else
+                            gripe_bessel_arg (fn, "second");
+                        }
+                    }
+                  else
+                    gripe_bessel_arg (fn, "first");
+                }
+            }
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+DEFUN (besselj, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {[@var{j}, @var{ierr}] =} besselj (@var{alpha}, @var{x}, @var{opt})\n\
+@deftypefnx {Built-in Function} {[@var{y}, @var{ierr}] =} bessely (@var{alpha}, @var{x}, @var{opt})\n\
+@deftypefnx {Built-in Function} {[@var{i}, @var{ierr}] =} besseli (@var{alpha}, @var{x}, @var{opt})\n\
+@deftypefnx {Built-in Function} {[@var{k}, @var{ierr}] =} besselk (@var{alpha}, @var{x}, @var{opt})\n\
+@deftypefnx {Built-in Function} {[@var{h}, @var{ierr}] =} besselh (@var{alpha}, @var{k}, @var{x}, @var{opt})\n\
+Compute Bessel or Hankel functions of various kinds:\n\
+\n\
+@table @code\n\
+@item besselj\n\
+Bessel functions of the first kind.  If the argument @var{opt} is supplied,\n\
+the result is multiplied by @code{exp (-abs (imag (@var{x})))}.\n\
+\n\
+@item bessely\n\
+Bessel functions of the second kind.  If the argument @var{opt} is supplied,\n\
+the result is multiplied by @code{exp (-abs (imag (@var{x})))}.\n\
+\n\
+@item besseli\n\
+\n\
+Modified Bessel functions of the first kind.  If the argument @var{opt} is\n\
+supplied, the result is multiplied by @code{exp (-abs (real (@var{x})))}.\n\
+\n\
+@item besselk\n\
+\n\
+Modified Bessel functions of the second kind.  If the argument @var{opt} is\n\
+supplied, the result is multiplied by @code{exp (@var{x})}.\n\
+\n\
+@item besselh\n\
+Compute Hankel functions of the first (@var{k} = 1) or second (@var{k}\n\
+= 2) kind.  If the argument @var{opt} is supplied, the result is multiplied\n\
+by @code{exp (-I*@var{x})} for @var{k} = 1 or @code{exp (I*@var{x})} for\n\
+@var{k} = 2.\n\
+@end table\n\
+\n\
+If @var{alpha} is a scalar, the result is the same size as @var{x}.\n\
+If @var{x} is a scalar, the result is the same size as @var{alpha}.\n\
+If @var{alpha} is a row vector and @var{x} is a column vector, the\n\
+result is a matrix with @code{length (@var{x})} rows and\n\
+@code{length (@var{alpha})} columns.  Otherwise, @var{alpha} and\n\
+@var{x} must conform and the result will be the same size.\n\
+\n\
+The value of @var{alpha} must be real.  The value of @var{x} may be\n\
+complex.\n\
+\n\
+If requested, @var{ierr} contains the following status information\n\
+and is the same size as the result.\n\
+\n\
+@enumerate 0\n\
+@item\n\
+Normal return.\n\
+\n\
+@item\n\
+Input error, return @code{NaN}.\n\
+\n\
+@item\n\
+Overflow, return @code{Inf}.\n\
+\n\
+@item\n\
+Loss of significance by argument reduction results in less than\n\
+half of machine accuracy.\n\
+\n\
+@item\n\
+Complete loss of significance by argument reduction, return @code{NaN}.\n\
+\n\
+@item\n\
+Error---no computation, algorithm termination condition not met,\n\
+return @code{NaN}.\n\
+@end enumerate\n\
+@end deftypefn")
+{
+  return do_bessel (BESSEL_J, "besselj", args, nargout);
+}
+
+DEFUN (bessely, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {[@var{y}, @var{ierr}] =} bessely (@var{alpha}, @var{x}, @var{opt})\n\
+See besselj.\n\
+@end deftypefn")
+{
+  return do_bessel (BESSEL_Y, "bessely", args, nargout);
+}
+
+DEFUN (besseli, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {[@var{i}, @var{ierr}] =} besseli (@var{alpha}, @var{x}, @var{opt})\n\
+See besselj.\n\
+@end deftypefn")
+{
+  return do_bessel (BESSEL_I, "besseli", args, nargout);
+}
+
+DEFUN (besselk, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {[@var{k}, @var{ierr}] =} besselk (@var{alpha}, @var{x}, @var{opt})\n\
+See besselj.\n\
+@end deftypefn")
+{
+  return do_bessel (BESSEL_K, "besselk", args, nargout);
+}
+
+DEFUN (besselh, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {[@var{h}, @var{ierr}] =} besselh (@var{alpha}, @var{k}, @var{x}, @var{opt})\n\
+See besselj.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin == 2)
+    {
+      retval = do_bessel (BESSEL_H1, "besselh", args, nargout);
+    }
+  else if (nargin == 3 || nargin == 4)
+    {
+      octave_idx_type kind = args(1).int_value ();
+
+      if (! error_state)
+        {
+          octave_value_list tmp_args;
+
+          if (nargin == 4)
+            tmp_args(2) = args(3);
+
+          tmp_args(1) = args(2);
+          tmp_args(0) = args(0);
+
+          if (kind == 1)
+            retval = do_bessel (BESSEL_H1, "besselh", tmp_args, nargout);
+          else if (kind == 2)
+            retval = do_bessel (BESSEL_H2, "besselh", tmp_args, nargout);
+          else
+            error ("besselh: expecting K = 1 or 2");
+        }
+      else
+        error ("besselh: invalid value of K");
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+DEFUN (airy, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {[@var{a}, @var{ierr}] =} airy (@var{k}, @var{z}, @var{opt})\n\
+Compute Airy functions of the first and second kind, and their\n\
+derivatives.\n\
+\n\
+@example\n\
+@group\n\
+ K   Function   Scale factor (if 'opt' is supplied)\n\
+---  --------   ---------------------------------------\n\
+ 0   Ai (Z)     exp ((2/3) * Z * sqrt (Z))\n\
+ 1   dAi(Z)/dZ  exp ((2/3) * Z * sqrt (Z))\n\
+ 2   Bi (Z)     exp (-abs (real ((2/3) * Z * sqrt (Z))))\n\
+ 3   dBi(Z)/dZ  exp (-abs (real ((2/3) * Z * sqrt (Z))))\n\
+@end group\n\
+@end example\n\
+\n\
+The function call @code{airy (@var{z})} is equivalent to\n\
+@code{airy (0, @var{z})}.\n\
+\n\
+The result is the same size as @var{z}.\n\
+\n\
+If requested, @var{ierr} contains the following status information and\n\
+is the same size as the result.\n\
+\n\
+@enumerate 0\n\
+@item\n\
+Normal return.\n\
+\n\
+@item\n\
+Input error, return @code{NaN}.\n\
+\n\
+@item\n\
+Overflow, return @code{Inf}.\n\
+\n\
+@item\n\
+Loss of significance by argument reduction results in less than half\n\
+ of machine accuracy.\n\
+\n\
+@item\n\
+Complete loss of significance by argument reduction, return @code{NaN}.\n\
+\n\
+@item\n\
+Error---no computation, algorithm termination condition not met,\n\
+return @code{NaN}.\n\
+@end enumerate\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin > 0 && nargin < 4)
+    {
+      bool scale = (nargin == 3);
+
+      int kind = 0;
+
+      if (nargin > 1)
+        {
+          kind = args(0).int_value ();
+
+          if (! error_state)
+            {
+              if (kind < 0 || kind > 3)
+                error ("airy: expecting K = 0, 1, 2, or 3");
+            }
+          else
+            error ("airy: K must be an integer value");
+        }
+
+      if (! error_state)
+        {
+          int idx = nargin == 1 ? 0 : 1;
+
+          if (args (idx).is_single_type ())
+            {
+              FloatComplexNDArray z = args(idx).float_complex_array_value ();
+
+              if (! error_state)
+                {
+                  Array<octave_idx_type> ierr;
+                  octave_value result;
+
+                  if (kind > 1)
+                    result = biry (z, kind == 3, scale, ierr);
+                  else
+                    result = airy (z, kind == 1, scale, ierr);
+
+                  if (nargout > 1)
+                    retval(1) = NDArray (ierr);
+
+                  retval(0) = result;
+                }
+              else
+                error ("airy: Z must be a complex matrix");
+            }
+          else
+            {
+              ComplexNDArray z = args(idx).complex_array_value ();
+
+              if (! error_state)
+                {
+                  Array<octave_idx_type> ierr;
+                  octave_value result;
+
+                  if (kind > 1)
+                    result = biry (z, kind == 3, scale, ierr);
+                  else
+                    result = airy (z, kind == 1, scale, ierr);
+
+                  if (nargout > 1)
+                    retval(1) = NDArray (ierr);
+
+                  retval(0) = result;
+                }
+              else
+                error ("airy: Z must be a complex matrix");
+            }
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%! # Test values computed with GP/PARI version 2.3.3
+%!
+%!shared alpha, x, jx, yx, ix, kx, nix
+%!
+%! # Bessel functions, even order, positive and negative x
+%! alpha = 2;  x = 1.25;
+%! jx = 0.1710911312405234823613091417;
+%! yx = -1.193199310178553861283790424;
+%! ix = 0.2220184483766341752692212604;
+%! kx = 0.9410016167388185767085460540;
+%!
+%!assert (besselj (alpha,x), jx, 100*eps)
+%!assert (bessely (alpha,x), yx, 100*eps)
+%!assert (besseli (alpha,x), ix, 100*eps)
+%!assert (besselk (alpha,x), kx, 100*eps)
+%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
+%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
+%!
+%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
+%!
+%!assert (besselj (-alpha,x), jx, 100*eps)
+%!assert (bessely (-alpha,x), yx, 100*eps)
+%!assert (besseli (-alpha,x), ix, 100*eps)
+%!assert (besselk (-alpha,x), kx, 100*eps)
+%!assert (besselh (-alpha,1,x), jx + I*yx, 100*eps)
+%!assert (besselh (-alpha,2,x), jx - I*yx, 100*eps)
+%!
+%!assert (besselj (-alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (-alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (-alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (-alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (-alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
+%!
+%! x *= -1;
+%! yx = -1.193199310178553861283790424 + 0.3421822624810469647226182835*I;
+%! kx = 0.9410016167388185767085460540 - 0.6974915263814386815610060884*I;
+%!
+%!assert (besselj (alpha,x), jx, 100*eps)
+%!assert (bessely (alpha,x), yx, 100*eps)
+%!assert (besseli (alpha,x), ix, 100*eps)
+%!assert (besselk (alpha,x), kx, 100*eps)
+%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
+%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
+%!
+%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
+%!
+%! # Bessel functions, odd order, positive and negative x
+%! alpha = 3;  x = 2.5;
+%! jx = 0.2166003910391135247666890035;
+%! yx = -0.7560554967536709968379029772;
+%! ix = 0.4743704087780355895548240179;
+%! kx = 0.2682271463934492027663765197;
+%!
+%!assert (besselj (alpha,x), jx, 100*eps)
+%!assert (bessely (alpha,x), yx, 100*eps)
+%!assert (besseli (alpha,x), ix, 100*eps)
+%!assert (besselk (alpha,x), kx, 100*eps)
+%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
+%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
+%!
+%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
+%!
+%!assert (besselj (-alpha,x), -jx, 100*eps)
+%!assert (bessely (-alpha,x), -yx, 100*eps)
+%!assert (besseli (-alpha,x), ix, 100*eps)
+%!assert (besselk (-alpha,x), kx, 100*eps)
+%!assert (besselh (-alpha,1,x), -(jx + I*yx), 100*eps)
+%!assert (besselh (-alpha,2,x), -(jx - I*yx), 100*eps)
+%!
+%!assert (besselj (-alpha,x,1), -jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (-alpha,x,1), -yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (-alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (-alpha,1,x,1), -(jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (-alpha,2,x,1), -(jx - I*yx)*exp(I*x), 100*eps)
+%!
+%! x *= -1;
+%! jx = -jx;
+%! yx = 0.7560554967536709968379029772 - 0.4332007820782270495333780070*I;
+%! ix = -ix;
+%! kx = -0.2682271463934492027663765197 - 1.490278591297463775542004240*I;
+%!
+%!assert (besselj (alpha,x), jx, 100*eps)
+%!assert (bessely (alpha,x), yx, 100*eps)
+%!assert (besseli (alpha,x), ix, 100*eps)
+%!assert (besselk (alpha,x), kx, 100*eps)
+%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
+%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
+%!
+%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
+%!
+%! # Bessel functions, fractional order, positive and negative x
+%!
+%! alpha = 3.5;  x = 2.75;
+%! jx = 0.1691636439842384154644784389;
+%! yx = -0.8301381935499356070267953387;
+%! ix = 0.3930540878794826310979363668;
+%! kx = 0.2844099013460621170288192503;
+%!
+%!assert (besselj (alpha,x), jx, 100*eps)
+%!assert (bessely (alpha,x), yx, 100*eps)
+%!assert (besseli (alpha,x), ix, 100*eps)
+%!assert (besselk (alpha,x), kx, 100*eps)
+%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
+%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
+%!
+%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
+%!
+%! nix = 0.2119931212254662995364461998;
+%!
+%!assert (besselj (-alpha,x), yx, 100*eps)
+%!assert (bessely (-alpha,x), -jx, 100*eps)
+%!assert (besseli (-alpha,x), nix, 100*eps)
+%!assert (besselk (-alpha,x), kx, 100*eps)
+%!assert (besselh (-alpha,1,x), -I*(jx + I*yx), 100*eps)
+%!assert (besselh (-alpha,2,x), I*(jx - I*yx), 100*eps)
+%!
+%!assert (besselj (-alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (-alpha,x,1), -jx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (-alpha,x,1), nix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (-alpha,1,x,1), -I*(jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (-alpha,2,x,1), I*(jx - I*yx)*exp(I*x), 100*eps)
+%!
+%! x *= -1;
+%! jx *= -I;
+%! yx = -0.8301381935499356070267953387*I;
+%! ix *= -I;
+%! kx = -0.9504059335995575096509874508*I;
+%!
+%!assert (besselj (alpha,x), jx, 100*eps)
+%!assert (bessely (alpha,x), yx, 100*eps)
+%!assert (besseli (alpha,x), ix, 100*eps)
+%!assert (besselk (alpha,x), kx, 100*eps)
+%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
+%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
+%!
+%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
+%!
+%! # Bessel functions, even order, complex x
+%!
+%! alpha = 2;  x = 1.25 + 3.625 * I;
+%! jx = -1.299533366810794494030065917 + 4.370833116012278943267479589*I;
+%! yx = -4.370357232383223896393056727 - 1.283083391453582032688834041*I;
+%! ix = -0.6717801680341515541002273932 - 0.2314623443930774099910228553*I;
+%! kx = -0.01108009888623253515463783379 + 0.2245218229358191588208084197*I;
+%!
+%!assert (besselj (alpha,x), jx, 100*eps)
+%!assert (bessely (alpha,x), yx, 100*eps)
+%!assert (besseli (alpha,x), ix, 100*eps)
+%!assert (besselk (alpha,x), kx, 100*eps)
+%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
+%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
+%!
+%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
+%!
+%!assert (besselj (-alpha,x), jx, 100*eps)
+%!assert (bessely (-alpha,x), yx, 100*eps)
+%!assert (besseli (-alpha,x), ix, 100*eps)
+%!assert (besselk (-alpha,x), kx, 100*eps)
+%!assert (besselh (-alpha,1,x), jx + I*yx, 100*eps)
+%!assert (besselh (-alpha,2,x), jx - I*yx, 100*eps)
+%!
+%!assert (besselj (-alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (-alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (-alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (-alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (-alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
+%!
+%! # Bessel functions, odd order, complex x
+%!
+%! alpha = 3; x = 2.5 + 1.875 * I;
+%! jx = 0.1330721523048277493333458596 + 0.5386295217249660078754395597*I;
+%! yx = -0.6485072392105829901122401551 + 0.2608129289785456797046996987*I;
+%! ix = -0.6182064685486998097516365709 + 0.4677561094683470065767989920*I;
+%! kx = -0.1568585587733540007867882337 - 0.05185853709490846050505141321*I;
+%!
+%!assert (besselj (alpha,x), jx, 100*eps)
+%!assert (bessely (alpha,x), yx, 100*eps)
+%!assert (besseli (alpha,x), ix, 100*eps)
+%!assert (besselk (alpha,x), kx, 100*eps)
+%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
+%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
+%!
+%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
+%!
+%!assert (besselj (-alpha,x), -jx, 100*eps)
+%!assert (bessely (-alpha,x), -yx, 100*eps)
+%!assert (besseli (-alpha,x), ix, 100*eps)
+%!assert (besselk (-alpha,x), kx, 100*eps)
+%!assert (besselh (-alpha,1,x), -(jx + I*yx), 100*eps)
+%!assert (besselh (-alpha,2,x), -(jx - I*yx), 100*eps)
+%!
+%!assert (besselj (-alpha,x,1), -jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (-alpha,x,1), -yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (-alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (-alpha,1,x,1), -(jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (-alpha,2,x,1), -(jx - I*yx)*exp(I*x), 100*eps)
+%!
+%! # Bessel functions, fractional order, complex x
+%!
+%! alpha = 3.5;  x = 1.75 + 4.125 * I;
+%! jx = -3.018566131370455929707009100 - 0.7585648436793900607704057611*I;
+%! yx = 0.7772278839106298215614791107 - 3.018518722313849782683792010*I;
+%! ix = 0.2100873577220057189038160913 - 0.6551765604618246531254970926*I;
+%! kx = 0.1757147290513239935341488069 + 0.08772348296883849205562558311*I;
+%!
+%!assert (besselj (alpha,x), jx, 100*eps)
+%!assert (bessely (alpha,x), yx, 100*eps)
+%!assert (besseli (alpha,x), ix, 100*eps)
+%!assert (besselk (alpha,x), kx, 100*eps)
+%!assert (besselh (alpha,1,x), jx + I*yx, 100*eps)
+%!assert (besselh (alpha,2,x), jx - I*yx, 100*eps)
+%!
+%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps)
+%!
+%!  nix = 0.09822388691172060573913739253 - 0.7110230642207380127317227407*I;
+%!
+%!assert (besselj (-alpha,x), yx, 100*eps)
+%!assert (bessely (-alpha,x), -jx, 100*eps)
+%!assert (besseli (-alpha,x), nix, 100*eps)
+%!assert (besselk (-alpha,x), kx, 100*eps)
+%!assert (besselh (-alpha,1,x), -I*(jx + I*yx), 100*eps)
+%!assert (besselh (-alpha,2,x), I*(jx - I*yx), 100*eps)
+%!
+%!assert (besselj (-alpha,x,1), yx*exp(-abs(imag(x))), 100*eps)
+%!assert (bessely (-alpha,x,1), -jx*exp(-abs(imag(x))), 100*eps)
+%!assert (besseli (-alpha,x,1), nix*exp(-abs(real(x))), 100*eps)
+%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps)
+%!assert (besselh (-alpha,1,x,1), -I*(jx + I*yx)*exp(-I*x), 100*eps)
+%!assert (besselh (-alpha,2,x,1), I*(jx - I*yx)*exp(I*x), 100*eps)
+
+
+Tests contributed by Robert T. Short.
+Tests are based on the properties and tables in A&S:
+ Abramowitz and Stegun, "Handbook of Mathematical Functions",
+ 1972.
+
+For regular Bessel functions, there are 3 tests. These compare octave
+results against Tables 9.1, 9.2, and 9.4 in A&S. Tables 9.1 and 9.2
+are good to only a few decimal places, so any failures should be
+considered a broken implementation. Table 9.4 is an extended table
+for larger orders and arguments. There are some differences between
+Octave and Table 9.4, mostly in the last decimal place but in a very
+few instances the errors are in the last two places. The comparison
+tolerance has been changed to reflect this.
+
+Similarly for modifed Bessel functions, there are 3 tests. These
+compare octave results against Tables 9.8, 9.9, and 9.11 in A&S.
+Tables 9.8 and 9.9 are good to only a few decimal places, so any
+failures should be considered a broken implementation. Table 9.11 is
+an extended table for larger orders and arguments. There are some
+differences between octave and Table 9.11, mostly in the last decimal
+place but in a very few instances the errors are in the last two
+places. The comparison tolerance has been changed to reflect this.
+
+For spherical Bessel functions, there are also three tests, comparing
+octave results to Tables 10.1, 10.2, and 10.4 in A&S. Very similar
+comments may be made here as in the previous lines. At this time,
+modified spherical Bessel function tests are not included.
+
+% Table 9.1 - J and Y for integer orders 0, 1, 2.
+% Compare against excerpts of Table 9.1, Abramowitz and Stegun.
+%!test
+%! n = 0:2;
+%! z = (0:2.5:17.5)';
+%!
+%! Jt = [[ 1.000000000000000,  0.0000000000,  0.0000000000];
+%!       [-0.048383776468198,  0.4970941025,  0.4460590584];
+%!       [-0.177596771314338, -0.3275791376,  0.0465651163];
+%!       [ 0.266339657880378,  0.1352484276, -0.2302734105];
+%!       [-0.245935764451348,  0.0434727462,  0.2546303137];
+%!       [ 0.146884054700421, -0.1654838046, -0.1733614634];
+%!       [-0.014224472826781,  0.2051040386,  0.0415716780];
+%!       [-0.103110398228686, -0.1634199694,  0.0844338303]];
+%!
+%! Yt = [[-Inf,          -Inf,          -Inf        ];
+%!       [ 0.4980703596,  0.1459181380, -0.38133585 ];
+%!       [-0.3085176252,  0.1478631434,  0.36766288 ];
+%!       [ 0.1173132861, -0.2591285105, -0.18641422 ];
+%!       [ 0.0556711673,  0.2490154242, -0.00586808 ];
+%!       [-0.1712143068, -0.1538382565,  0.14660019 ];
+%!       [ 0.2054642960,  0.0210736280, -0.20265448 ];
+%!       [-0.1604111925,  0.0985727987,  0.17167666 ]];
+%!
+%! J = besselj (n,z);
+%! Y = bessely (n,z);
+%! assert (Jt(:,1), J(:,1), 0.5e-10);
+%! assert (Yt(:,1), Y(:,1), 0.5e-10);
+%! assert (Jt(:,2:3), J(:,2:3), 0.5e-10);
+
+Table 9.2 - J and Y for integer orders 3-9.
+
+%!test
+%! n = (3:9);
+%! z = (0:2:20).';
+%!
+%! Jt = [[ 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00];
+%!       [ 1.2894e-01, 3.3996e-02, 7.0396e-03, 1.2024e-03, 1.7494e-04, 2.2180e-05, 2.4923e-06];
+%!       [ 4.3017e-01, 2.8113e-01, 1.3209e-01, 4.9088e-02, 1.5176e-02, 4.0287e-03, 9.3860e-04];
+%!       [ 1.1477e-01, 3.5764e-01, 3.6209e-01, 2.4584e-01, 1.2959e-01, 5.6532e-02, 2.1165e-02];
+%!       [-2.9113e-01,-1.0536e-01, 1.8577e-01, 3.3758e-01, 3.2059e-01, 2.2345e-01, 1.2632e-01];
+%!       [ 5.8379e-02,-2.1960e-01,-2.3406e-01,-1.4459e-02, 2.1671e-01, 3.1785e-01, 2.9186e-01];
+%!       [ 1.9514e-01, 1.8250e-01,-7.3471e-02,-2.4372e-01,-1.7025e-01, 4.5095e-02, 2.3038e-01];
+%!       [-1.7681e-01, 7.6244e-02, 2.2038e-01, 8.1168e-02,-1.5080e-01,-2.3197e-01,-1.1431e-01];
+%!       [-4.3847e-02,-2.0264e-01,-5.7473e-02, 1.6672e-01, 1.8251e-01,-7.0211e-03,-1.8953e-01];
+%!       [ 1.8632e-01, 6.9640e-02,-1.5537e-01,-1.5596e-01, 5.1399e-02, 1.9593e-01, 1.2276e-01];
+%!       [-9.8901e-02, 1.3067e-01, 1.5117e-01,-5.5086e-02,-1.8422e-01,-7.3869e-02, 1.2513e-01]];
+%!
+%! Yt = [[       -Inf,       -Inf,       -Inf,       -Inf,       -Inf,       -Inf,       -Inf];
+%!       [-1.1278e+00,-2.7659e+00,-9.9360e+00,-4.6914e+01,-2.7155e+02,-1.8539e+03,-1.4560e+04];
+%!       [-1.8202e-01,-4.8894e-01,-7.9585e-01,-1.5007e+00,-3.7062e+00,-1.1471e+01,-4.2178e+01];
+%!       [ 3.2825e-01, 9.8391e-02,-1.9706e-01,-4.2683e-01,-6.5659e-01,-1.1052e+00,-2.2907e+00];
+%!       [ 2.6542e-02, 2.8294e-01, 2.5640e-01, 3.7558e-02,-2.0006e-01,-3.8767e-01,-5.7528e-01];
+%!       [-2.5136e-01,-1.4495e-01, 1.3540e-01, 2.8035e-01, 2.0102e-01, 1.0755e-03,-1.9930e-01];
+%!       [ 1.2901e-01,-1.5122e-01,-2.2982e-01,-4.0297e-02, 1.8952e-01, 2.6140e-01, 1.5902e-01];
+%!       [ 1.2350e-01, 2.0393e-01,-6.9717e-03,-2.0891e-01,-1.7209e-01, 3.6816e-02, 2.1417e-01];
+%!       [-1.9637e-01,-7.3222e-05, 1.9633e-01, 1.2278e-01,-1.0425e-01,-2.1399e-01,-1.0975e-01];
+%!       [ 3.3724e-02,-1.7722e-01,-1.1249e-01, 1.1472e-01, 1.8897e-01, 3.2253e-02,-1.6030e-01];
+%!       [ 1.4967e-01, 1.2409e-01,-1.0004e-01,-1.7411e-01,-4.4312e-03, 1.7101e-01, 1.4124e-01]];
+%!
+%! n = (3:9);
+%! z = (0:2:20).';
+%! J = besselj (n,z);
+%! Y = bessely (n,z);
+%!
+%! assert (J(1,:), zeros (1, columns (J)));
+%! assert (J(2:end,:), Jt(2:end,:), -5e-5);
+%! assert (Yt(1,:), Y(1,:));
+%! assert (Y(2:end,:), Yt(2:end,:), -5e-5);
+
+Table 9.4 - J and Y for various integer orders and arguments.
+
+%!test
+%! Jt = [[ 7.651976866e-01,   2.238907791e-01,  -1.775967713e-01,  -2.459357645e-01,  5.581232767e-02,  1.998585030e-02];
+%!       [ 2.497577302e-04,   7.039629756e-03,   2.611405461e-01,  -2.340615282e-01, -8.140024770e-02, -7.419573696e-02];
+%!       [ 2.630615124e-10,   2.515386283e-07,   1.467802647e-03,   2.074861066e-01, -1.138478491e-01, -5.473217694e-02];
+%!       [ 2.297531532e-17,   7.183016356e-13,   4.796743278e-07,   4.507973144e-03, -1.082255990e-01,  1.519812122e-02];
+%!       [ 3.873503009e-25,   3.918972805e-19,   2.770330052e-11,   1.151336925e-05, -1.167043528e-01,  6.221745850e-02];
+%!       [ 3.482869794e-42,   3.650256266e-33,   2.671177278e-21,   1.551096078e-12,  4.843425725e-02,  8.146012958e-02];
+%!       [ 1.107915851e-60,   1.196077458e-48,   8.702241617e-33,   6.030895312e-21, -1.381762812e-01,  7.270175482e-02];
+%!       [ 2.906004948e-80,   3.224095839e-65,   2.294247616e-45,   1.784513608e-30,  1.214090219e-01, -3.869833973e-02];
+%!       [ 8.431828790e-189,  1.060953112e-158,  6.267789396e-119,  6.597316064e-89,  1.115927368e-21,  9.636667330e-02]];
+%!
+%! Yt = [[ 8.825696420e-02,   5.103756726e-01,  -3.085176252e-01,   5.567116730e-02, -9.806499547e-02, -7.724431337e-02]
+%!       [-2.604058666e+02,  -9.935989128e+00,  -4.536948225e-01,   1.354030477e-01, -7.854841391e-02, -2.948019628e-02]
+%!       [-1.216180143e+08,  -1.291845422e+05,  -2.512911010e+01,  -3.598141522e-01,  5.723897182e-03,  5.833157424e-02]
+%!       [-9.256973276e+14,  -2.981023646e+10,  -4.694049564e+04,  -6.364745877e+00,  4.041280205e-02,  7.879068695e-02]
+%!       [-4.113970315e+22,  -4.081651389e+16,  -5.933965297e+08,  -1.597483848e+03,  1.644263395e-02,  5.124797308e-02]
+%!       [-3.048128783e+39,  -2.913223848e+30,  -4.028568418e+18,  -7.256142316e+09, -1.164572349e-01,  6.138839212e-03]
+%!       [-7.184874797e+57,  -6.661541235e+45,  -9.216816571e+29,  -1.362803297e+18, -4.530801120e-02,  4.074685217e-02]
+%!       [-2.191142813e+77,  -1.976150576e+62,  -2.788837017e+42,  -3.641066502e+27, -2.103165546e-01,  7.650526394e-02]
+%!       [-3.775287810e+185, -3.000826049e+155, -5.084863915e+115, -4.849148271e+85, -3.293800188e+18, -1.669214114e-01]];
+%!
+%! n = [(0:5:20).';30;40;50;100];
+%! z = [1,2,5,10,50,100];
+%! J = besselj (n.', z.').';
+%! Y = bessely (n.', z.').';
+%! assert (J, Jt, -1e-9);
+%! assert (Y, Yt, -1e-9);
+
+Table 9.8 - I and K for integer orders 0, 1, 2.
+
+%!test
+%! n  = 0:2;
+%! z1 = [0.1;2.5;5.0];
+%! z2 = [7.5;10.0;15.0;20.0];
+%! rtbl = [[ 0.9071009258   0.0452984468   0.1251041992   2.6823261023  10.890182683    1.995039646  ];
+%!         [ 0.2700464416   0.2065846495   0.2042345837   0.7595486903   0.9001744239   0.759126289  ];
+%!         [ 0.1835408126   0.1639722669   0.7002245988   0.5478075643   0.6002738588   0.132723593  ];
+%!         [ 0.1483158301   0.1380412115   0.111504840    0.4505236991   0.4796689336   0.57843541   ];
+%!         [ 0.1278333372   0.1212626814   0.103580801    0.3916319344   0.4107665704   0.47378525   ];
+%!         [ 0.1038995314   0.1003741751   0.090516308    0.3210023535   0.3315348950   0.36520701   ];
+%!         [ 0.0897803119   0.0875062222   0.081029690    0.2785448768   0.2854254970   0.30708743   ]];
+%!
+%! tbl = [besseli(n,z1,1), besselk(n,z1,1)];
+%! tbl(:,3) = tbl(:,3) .* (exp (z1) .* z1.^(-2));
+%! tbl(:,6) = tbl(:,6) .* (exp (-z1) .* z1.^(2));
+%! tbl = [tbl;[besseli(n,z2,1),besselk(n,z2,1)]];
+%!
+%! assert (tbl, rtbl, -2e-8);
+
+Table 9.9 - I and K for orders 3-9.
+
+%!test
+%! It = [[  0.0000e+00  0.0000e+00  0.0000e+00  0.0000e+00  0.0000e+00  0.0000e+00  0.0000e+00];
+%!       [  2.8791e-02  6.8654e-03  1.3298e-03  2.1656e-04  3.0402e-05  3.7487e-06  4.1199e-07];
+%!       [  6.1124e-02  2.5940e-02  9.2443e-03  2.8291e-03  7.5698e-04  1.7968e-04  3.8284e-05];
+%!       [  7.4736e-02  4.1238e-02  1.9752e-02  8.3181e-03  3.1156e-03  1.0484e-03  3.1978e-04];
+%!       [  7.9194e-02  5.0500e-02  2.8694e-02  1.4633e-02  6.7449e-03  2.8292e-03  1.0866e-03];
+%!       [  7.9830e-02  5.5683e-02  3.5284e-02  2.0398e-02  1.0806e-02  5.2694e-03  2.3753e-03];
+%!       [  7.8848e-02  5.8425e-02  3.9898e-02  2.5176e-02  1.4722e-02  8.0010e-03  4.0537e-03];
+%!       [  7.7183e-02  5.9723e-02  4.3056e-02  2.8969e-02  1.8225e-02  1.0744e-02  5.9469e-03];
+%!       [  7.5256e-02  6.0155e-02  4.5179e-02  3.1918e-02  2.1240e-02  1.3333e-02  7.9071e-03];
+%!       [  7.3263e-02  6.0059e-02  4.6571e-02  3.4186e-02  2.3780e-02  1.5691e-02  9.8324e-03];
+%!       [  7.1300e-02  5.9640e-02  4.7444e-02  3.5917e-02  2.5894e-02  1.7792e-02  1.1661e-02]];
+%!
+%! Kt = [[ Inf         Inf         Inf         Inf         Inf         Inf         Inf];
+%!      [  4.7836e+00  1.6226e+01  6.9687e+01  3.6466e+02  2.2576e+03  1.6168e+04  1.3160e+05];
+%!      [  1.6317e+00  3.3976e+00  8.4268e+00  2.4465e+01  8.1821e+01  3.1084e+02  1.3252e+03];
+%!      [  9.9723e-01  1.6798e+00  3.2370e+00  7.0748e+00  1.7387e+01  4.7644e+01  1.4444e+02];
+%!      [  7.3935e-01  1.1069e+00  1.8463e+00  3.4148e+00  6.9684e+00  1.5610e+01  3.8188e+01];
+%!      [  6.0028e-01  8.3395e-01  1.2674e+00  2.1014e+00  3.7891e+00  7.4062e+00  1.5639e+01];
+%!      [  5.1294e-01  6.7680e-01  9.6415e-01  1.4803e+00  2.4444e+00  4.3321e+00  8.2205e+00];
+%!      [  4.5266e-01  5.7519e-01  7.8133e-01  1.1333e+00  1.7527e+00  2.8860e+00  5.0510e+00];
+%!      [  4.0829e-01  5.0414e-01  6.6036e-01  9.1686e-01  1.3480e+00  2.0964e+00  3.4444e+00];
+%!      [  3.7411e-01  4.5162e-01  5.7483e-01  7.7097e-01  1.0888e+00  1.6178e+00  2.5269e+00];
+%!      [  3.4684e-01  4.1114e-01  5.1130e-01  6.6679e-01  9.1137e-01  1.3048e+00  1.9552e+00]];
+%!
+%! n = (3:9);
+%! z = (0:2:20).';
+%! I = besseli (n,z,1);
+%! K = besselk (n,z,1);
+%!
+%! assert (abs (I(1,:)), zeros (1, columns (I)));
+%! assert (I(2:end,:), It(2:end,:), -5e-5);
+%! assert (Kt(1,:), K(1,:));
+%! assert (K(2:end,:), Kt(2:end,:), -5e-5);
+
+Table 9.11 - I and K for various integer orders and arguments.
+
+%!test
+%! It = [[   1.266065878e+00    2.279585302e+00    2.723987182e+01    2.815716628e+03     2.93255378e+20     1.07375171e+42 ];
+%!       [   2.714631560e-04    9.825679323e-03    2.157974547e+00    7.771882864e+02     2.27854831e+20     9.47009387e+41 ];
+%!       [   2.752948040e-10    3.016963879e-07    4.580044419e-03    2.189170616e+01     1.07159716e+20     6.49897552e+41 ];
+%!       [   2.370463051e-17    8.139432531e-13    1.047977675e-06    1.043714907e-01     3.07376455e+19     3.47368638e+41 ];
+%!       [   3.966835986e-25    4.310560576e-19    5.024239358e-11    1.250799736e-04     5.44200840e+18     1.44834613e+41 ];
+%!       [   3.539500588e-42    3.893519664e-33    3.997844971e-21    7.787569783e-12     4.27499365e+16     1.20615487e+40 ];
+%!       [   1.121509741e-60    1.255869192e-48    1.180426980e-32    2.042123274e-20     6.00717897e+13     3.84170550e+38 ];
+%!       [   2.934635309e-80    3.353042830e-65    2.931469647e-45    4.756894561e-30     1.76508024e+10     4.82195809e+36 ];
+%!       [   8.473674008e-189   1.082171475e-158   7.093551489e-119   1.082344202e-88     2.72788795e-16     4.64153494e+21 ]];
+%!
+%! Kt = [[   4.210244382e-01    1.138938727e-01    3.691098334e-03    1.778006232e-05     3.41016774e-23     4.65662823e-45 ];
+%!       [   3.609605896e+02    9.431049101e+00    3.270627371e-02    5.754184999e-05     4.36718224e-23     5.27325611e-45 ];
+%!       [   1.807132899e+08    1.624824040e+05    9.758562829e+00    1.614255300e-03     9.15098819e-23     7.65542797e-45 ];
+%!       [   1.403066801e+15    4.059213332e+10    3.016976630e+04    2.656563849e-01     3.11621117e-22     1.42348325e-44 ];
+%!       [   6.294369360e+22    5.770856853e+16    4.827000521e+08    1.787442782e+02     1.70614838e-21     3.38520541e-44 ];
+%!       [   4.706145527e+39    4.271125755e+30    4.112132063e+18    2.030247813e+09     2.00581681e-19     3.97060205e-43 ];
+%!       [   1.114220651e+58    9.940839886e+45    1.050756722e+30    5.938224681e+17     1.29986971e-16     1.20842080e-41 ];
+%!       [   3.406896854e+77    2.979981740e+62    3.394322243e+42    2.061373775e+27     4.00601349e-13     9.27452265e-40 ];
+%!       [   5.900333184e+185   4.619415978e+155   7.039860193e+115   4.596674084e+85     1.63940352e+13     7.61712963e-25 ]];
+%!
+%! n = [(0:5:20).';30;40;50;100];
+%! z = [1,2,5,10,50,100];
+%! I = besseli (n.', z.').';
+%! K = besselk (n.', z.').';
+%! assert (I, It, -5e-9);
+%! assert (K, Kt, -5e-9);
+
+The next section checks that negative integer orders and positive
+integer orders are appropriately related.
+
+%!test
+%! n = (0:2:20);
+%! assert (besselj (n,1), besselj (-n,1), 1e-8);
+%! assert (-besselj (n+1,1), besselj (-n-1,1), 1e-8);
+
+besseli (n,z) = besseli (-n,z);
+
+%!test
+%! n = (0:2:20);
+%! assert (besseli (n,1), besseli (-n,1), 1e-8);
+
+Table 10.1 - j and y for integer orders 0, 1, 2.
+Compare against excerpts of Table 10.1, Abramowitz and Stegun.
+
+%!test
+%! n = (0:2);
+%! z = [0.1;(2.5:2.5:10.0).'];
+%!
+%! jt = [[ 9.9833417e-01  3.33000119e-02  6.6619061e-04 ];
+%!       [ 2.3938886e-01  4.16212989e-01  2.6006673e-01 ];
+%!       [-1.9178485e-01 -9.50894081e-02  1.3473121e-01 ];
+%!       [    1.2507e-01     -2.9542e-02    -1.3688e-01 ];
+%!       [   -5.4402e-02      7.8467e-02     7.7942e-02 ]];
+%!
+%! yt = [[-9.9500417e+00  -1.0049875e+02 -3.0050125e+03 ];
+%!       [ 3.2045745e-01  -1.1120588e-01 -4.5390450e-01 ];
+%!       [-5.6732437e-02   1.8043837e-01  1.6499546e-01 ];
+%!       [   -4.6218e-02     -1.3123e-01    -6.2736e-03 ];
+%!       [    8.3907e-02      6.2793e-02    -6.5069e-02 ]];
+%!
+%! j = sqrt ((pi/2)./z) .* besselj (n+1/2,z);
+%! y = sqrt ((pi/2)./z) .* bessely (n+1/2,z);
+%! assert (jt, j, -5e-5);
+%! assert (yt, y, -5e-5);
+
+Table 10.2 - j and y for orders 3-8.
+Compare against excerpts of Table 10.2, Abramowitzh and Stegun.
+
+ Important note: In A&S, y_4(0.1) = -1.0507e+7, but Octave returns
+ y_4(0.1) = -1.0508e+07 (-10507503.75).  If I compute the same term using
+ a series, the difference is in the eighth significant digit so I left
+ the Octave results in place.
+
+%!test
+%! n = (3:8);
+%! z = (0:2.5:10).';  z(1) = 0.1;
+%!
+%! jt = [[ 9.5185e-06  1.0577e-07  9.6163e-10  7.3975e-12  4.9319e-14  2.9012e-16];
+%!       [ 1.0392e-01  3.0911e-02  7.3576e-03  1.4630e-03  2.5009e-04  3.7516e-05];
+%!       [ 2.2982e-01  1.8702e-01  1.0681e-01  4.7967e-02  1.7903e-02  5.7414e-03];
+%!       [-6.1713e-02  7.9285e-02  1.5685e-01  1.5077e-01  1.0448e-01  5.8188e-02];
+%!       [-3.9496e-02 -1.0559e-01 -5.5535e-02  4.4501e-02  1.1339e-01  1.2558e-01]];
+%!
+%! yt = [[-1.5015e+05 -1.0508e+07 -9.4553e+08 -1.0400e+11 -1.3519e+13 -2.0277e+15];
+%!       [-7.9660e-01 -1.7766e+00 -5.5991e+00 -2.2859e+01 -1.1327e+02 -6.5676e+02];
+%!       [-1.5443e-02 -1.8662e-01 -3.2047e-01 -5.1841e-01 -1.0274e+00 -2.5638e+00];
+%!       [ 1.2705e-01  1.2485e-01  2.2774e-02 -9.1449e-02 -1.8129e-01 -2.7112e-01];
+%!       [-9.5327e-02 -1.6599e-03  9.3834e-02  1.0488e-01  4.2506e-02 -4.1117e-02]];
+%!
+%! j = sqrt ((pi/2)./z) .* besselj (n+1/2,z);
+%! y = sqrt ((pi/2)./z) .* bessely (n+1/2,z);
+%!
+%! assert (jt, j, -5e-5);
+%! assert (yt, y, -5e-5);
+
+Table 10.4 - j and y for various integer orders and arguments.
+
+%!test
+%! jt = [[ 8.414709848e-01    4.546487134e-01   -1.917848549e-01   -5.440211109e-02   -5.247497074e-03   -5.063656411e-03];
+%!       [ 9.256115861e-05    2.635169770e-03    1.068111615e-01   -5.553451162e-02   -2.004830056e-02   -9.290148935e-03];
+%!       [ 7.116552640e-11    6.825300865e-08    4.073442442e-04    6.460515449e-02   -1.503922146e-02   -1.956578597e-04];
+%!       [ 5.132686115e-18    1.606982166e-13    1.084280182e-07    1.063542715e-03   -1.129084539e-02    7.877261748e-03];
+%!       [ 7.537795722e-26    7.632641101e-20    5.427726761e-12    2.308371961e-06   -1.578502990e-02    1.010767128e-02];
+%!       [ 5.566831267e-43    5.836617888e-34    4.282730217e-22    2.512057385e-13   -1.494673454e-03    8.700628514e-03];
+%!       [ 1.538210374e-61    1.660978779e-49    1.210347583e-33    8.435671634e-22   -2.606336952e-02    1.043410851e-02];
+%!       [ 3.615274717e-81    4.011575290e-66    2.857479350e-46    2.230696023e-31    1.882910737e-02    5.797140882e-04];
+%!       [7.444727742e-190   9.367832591e-160   5.535650303e-120    5.832040182e-90    1.019012263e-22    1.088047701e-02]];
+%!
+%! yt = [[ -5.403023059e-01    2.080734183e-01   -5.673243709e-02    8.390715291e-02   -1.929932057e-02   -8.623188723e-03]
+%!       [ -9.994403434e+02   -1.859144531e+01   -3.204650467e-01    9.383354168e-02   -6.971131965e-04    3.720678486e-03]
+%!       [ -6.722150083e+08   -3.554147201e+05   -2.665611441e+01   -1.724536721e-01    1.352468751e-02    1.002577737e-02]
+%!       [ -6.298007233e+15   -1.012182944e+11   -6.288146513e+04   -3.992071745e+00    1.712319725e-02    6.258641510e-03]
+%!       [ -3.239592219e+23   -1.605436493e+17   -9.267951403e+08   -1.211210605e+03    1.375953130e-02    5.631729379e-05]
+%!       [ -2.946428547e+40   -1.407393871e+31   -7.760717570e+18   -6.908318646e+09   -2.241226812e-02   -5.412929349e-03]
+%!       [ -8.028450851e+58   -3.720929322e+46   -2.055758716e+30   -1.510304919e+18    4.978797221e-05   -7.048420407e-04]
+%!       [ -2.739192285e+78   -1.235021944e+63   -6.964109188e+42   -4.528227272e+27   -4.190000150e-02    1.074782297e-02]
+%!       [-6.683079463e+186  -2.655955830e+156  -1.799713983e+116   -8.573226309e+85   -1.125692891e+18   -2.298385049e-02]];
+%!
+%! n = [(0:5:20).';30;40;50;100];
+%! z = [1,2,5,10,50,100];
+%! j = sqrt ((pi/2)./z) .* besselj ((n+1/2).', z.').';
+%! y = sqrt ((pi/2)./z) .* bessely ((n+1/2).', z.').';
+%! assert (j, jt, -1e-9);
+%! assert (y, yt, -1e-9);
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/betainc.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,491 @@
+/*
+
+Copyright (C) 1997-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "lo-specfun.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+// FIXME: These functions do not need to be dynamically loaded.  They should
+//        be placed elsewhere in the Octave code hierarchy.
+
+DEFUN (betainc, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Mapping Function} {} betainc (@var{x}, @var{a}, @var{b})\n\
+Return the regularized incomplete Beta function,\n\
+@tex\n\
+$$\n\
+ I (x, a, b) = {1 \\over {B (a, b)}} \\int_0^x t^{(a-z)} (1-t)^{(b-1)} dt.\n\
+$$\n\
+@end tex\n\
+@ifnottex\n\
+@c Set example in small font to prevent overfull line\n\
+\n\
+@smallexample\n\
+@group\n\
+                                   x\n\
+                          1       /\n\
+betainc (x, a, b) = -----------   | t^(a-1) (1-t)^(b-1) dt.\n\
+                    beta (a, b)   /\n\
+                               t=0\n\
+@end group\n\
+@end smallexample\n\
+\n\
+@end ifnottex\n\
+\n\
+If @var{x} has more than one component, both @var{a} and @var{b} must be\n\
+scalars.  If @var{x} is a scalar, @var{a} and @var{b} must be of\n\
+compatible dimensions.\n\
+@seealso{betaincinv, beta, betaln}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin == 3)
+    {
+      octave_value x_arg = args(0);
+      octave_value a_arg = args(1);
+      octave_value b_arg = args(2);
+
+      // FIXME Can we make a template version of the duplicated code below
+      if (x_arg.is_single_type () || a_arg.is_single_type () ||
+          b_arg.is_single_type ())
+        {
+          if (x_arg.is_scalar_type ())
+            {
+              float x = x_arg.float_value ();
+
+              if (a_arg.is_scalar_type ())
+                {
+                  float a = a_arg.float_value ();
+
+                  if (! error_state)
+                    {
+                      if (b_arg.is_scalar_type ())
+                        {
+                          float b = b_arg.float_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                      else
+                        {
+                          Array<float> b = b_arg.float_array_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                    }
+                }
+              else
+                {
+                  Array<float> a = a_arg.float_array_value ();
+
+                  if (! error_state)
+                    {
+                      if (b_arg.is_scalar_type ())
+                        {
+                          float b = b_arg.float_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                      else
+                        {
+                          Array<float> b = b_arg.float_array_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                    }
+                }
+            }
+          else
+            {
+              Array<float> x = x_arg.float_array_value ();
+
+              if (a_arg.is_scalar_type ())
+                {
+                  float a = a_arg.float_value ();
+
+                  if (! error_state)
+                    {
+                      if (b_arg.is_scalar_type ())
+                        {
+                          float b = b_arg.float_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                      else
+                        {
+                          Array<float> b = b_arg.float_array_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                    }
+                }
+              else
+                {
+                  Array<float> a = a_arg.float_array_value ();
+
+                  if (! error_state)
+                    {
+                      if (b_arg.is_scalar_type ())
+                        {
+                          float b = b_arg.float_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                      else
+                        {
+                          Array<float> b = b_arg.float_array_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                    }
+                }
+            }
+        }
+      else
+        {
+          if (x_arg.is_scalar_type ())
+            {
+              double x = x_arg.double_value ();
+
+              if (a_arg.is_scalar_type ())
+                {
+                  double a = a_arg.double_value ();
+
+                  if (! error_state)
+                    {
+                      if (b_arg.is_scalar_type ())
+                        {
+                          double b = b_arg.double_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                      else
+                        {
+                          Array<double> b = b_arg.array_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                    }
+                }
+              else
+                {
+                  Array<double> a = a_arg.array_value ();
+
+                  if (! error_state)
+                    {
+                      if (b_arg.is_scalar_type ())
+                        {
+                          double b = b_arg.double_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                      else
+                        {
+                          Array<double> b = b_arg.array_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                    }
+                }
+            }
+          else
+            {
+              Array<double> x = x_arg.array_value ();
+
+              if (a_arg.is_scalar_type ())
+                {
+                  double a = a_arg.double_value ();
+
+                  if (! error_state)
+                    {
+                      if (b_arg.is_scalar_type ())
+                        {
+                          double b = b_arg.double_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                      else
+                        {
+                          Array<double> b = b_arg.array_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                    }
+                }
+              else
+                {
+                  Array<double> a = a_arg.array_value ();
+
+                  if (! error_state)
+                    {
+                      if (b_arg.is_scalar_type ())
+                        {
+                          double b = b_arg.double_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                      else
+                        {
+                          Array<double> b = b_arg.array_value ();
+
+                          if (! error_state)
+                            retval = betainc (x, a, b);
+                        }
+                    }
+                }
+            }
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+## Double precision
+%!test
+%! a = [1, 1.5, 2, 3];
+%! b = [4, 3, 2, 1];
+%! v1 = betainc (1,a,b);
+%! v2 = [1,1,1,1];
+%! x = [.2, .4, .6, .8];
+%! v3 = betainc (x, a, b);
+%! v4 = 1 - betainc (1.-x, b, a);
+%! assert (v1, v2, sqrt (eps));
+%! assert (v3, v4, sqrt (eps));
+
+## Single precision
+%!test
+%! a = single ([1, 1.5, 2, 3]);
+%! b = single ([4, 3, 2, 1]);
+%! v1 = betainc (1,a,b);
+%! v2 = single ([1,1,1,1]);
+%! x = single ([.2, .4, .6, .8]);
+%! v3 = betainc (x, a, b);
+%! v4 = 1 - betainc (1.-x, b, a);
+%! assert (v1, v2, sqrt (eps ("single")));
+%! assert (v3, v4, sqrt (eps ("single")));
+
+## Mixed double/single precision
+%!test
+%! a = single ([1, 1.5, 2, 3]);
+%! b = [4, 3, 2, 1];
+%! v1 = betainc (1,a,b);
+%! v2 = single ([1,1,1,1]);
+%! x = [.2, .4, .6, .8];
+%! v3 = betainc (x, a, b);
+%! v4 = 1-betainc (1.-x, b, a);
+%! assert (v1, v2, sqrt (eps ("single")));
+%! assert (v3, v4, sqrt (eps ("single")));
+
+%!error betainc ()
+%!error betainc (1)
+%!error betainc (1,2)
+%!error betainc (1,2,3,4)
+*/
+
+DEFUN (betaincinv, args, ,
+    "-*- texinfo -*-\n\
+@deftypefn {Mapping Function} {} betaincinv (@var{y}, @var{a}, @var{b})\n\
+Compute the inverse of the incomplete Beta function, i.e., @var{x} such that\n\
+\n\
+@example\n\
+@var{y} == betainc (@var{x}, @var{a}, @var{b}) \n\
+@end example\n\
+@seealso{betainc, beta, betaln}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin == 3)
+    {
+      octave_value x_arg = args(0);
+      octave_value a_arg = args(1);
+      octave_value b_arg = args(2);
+
+      if (x_arg.is_scalar_type ())
+        {
+          double x = x_arg.double_value ();
+
+          if (a_arg.is_scalar_type ())
+            {
+              double a = a_arg.double_value ();
+
+              if (! error_state)
+                {
+                  if (b_arg.is_scalar_type ())
+                    {
+                      double b = b_arg.double_value ();
+
+                      if (! error_state)
+                        retval = betaincinv (x, a, b);
+                    }
+                  else
+                    {
+                      Array<double> b = b_arg.array_value ();
+
+                      if (! error_state)
+                        retval = betaincinv (x, a, b);
+                    }
+                }
+            }
+          else
+            {
+              Array<double> a = a_arg.array_value ();
+
+              if (! error_state)
+                {
+                  if (b_arg.is_scalar_type ())
+                    {
+                      double b = b_arg.double_value ();
+
+                      if (! error_state)
+                        retval = betaincinv (x, a, b);
+                    }
+                  else
+                    {
+                      Array<double> b = b_arg.array_value ();
+
+                      if (! error_state)
+                        retval = betaincinv (x, a, b);
+                    }
+                }
+            }
+        }
+      else
+        {
+          Array<double> x = x_arg.array_value ();
+
+          if (a_arg.is_scalar_type ())
+            {
+              double a = a_arg.double_value ();
+
+              if (! error_state)
+                {
+                  if (b_arg.is_scalar_type ())
+                    {
+                      double b = b_arg.double_value ();
+
+                      if (! error_state)
+                        retval = betaincinv (x, a, b);
+                    }
+                  else
+                    {
+                      Array<double> b = b_arg.array_value ();
+
+                      if (! error_state)
+                        retval = betaincinv (x, a, b);
+                    }
+                }
+            }
+          else
+            {
+              Array<double> a = a_arg.array_value ();
+
+              if (! error_state)
+                {
+                  if (b_arg.is_scalar_type ())
+                    {
+                      double b = b_arg.double_value ();
+
+                      if (! error_state)
+                        retval = betaincinv (x, a, b);
+                    }
+                  else
+                    {
+                      Array<double> b = b_arg.array_value ();
+
+                      if (! error_state)
+                        retval = betaincinv (x, a, b);
+                    }
+                }
+            }
+        }
+
+      // FIXME: It would be better to have an algorithm for betaincinv which
+      // accepted float inputs and returned float outputs.  As it is, we do
+      // extra work to calculate betaincinv to double precision and then throw
+      // that precision away.
+      if (x_arg.is_single_type () || a_arg.is_single_type () ||
+          b_arg.is_single_type ())
+        {
+          retval = Array<float> (retval.array_value ());
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!assert (betaincinv ([0.875 0.6875], [1 2], 3), [0.5 0.5], sqrt (eps))
+%!assert (betaincinv (0.5, 3, 3), 0.5, sqrt (eps))
+%!assert (betaincinv (0.34375, 4, 3), 0.5, sqrt (eps))
+%!assert (betaincinv (0.2265625, 5, 3), 0.5, sqrt (eps))
+%!assert (betaincinv (0.14453125, 6, 3), 0.5, sqrt (eps))
+%!assert (betaincinv (0.08984375, 7, 3), 0.5, sqrt (eps))
+%!assert (betaincinv (0.0546875, 8, 3), 0.5, sqrt (eps))
+%!assert (betaincinv (0.03271484375, 9, 3), 0.5, sqrt (eps))
+%!assert (betaincinv (0.019287109375, 10, 3), 0.5, sqrt (eps))
+
+## Test class single as well
+%!assert (betaincinv ([0.875 0.6875], [1 2], single (3)), [0.5 0.5], sqrt (eps ("single")))
+%!assert (betaincinv (0.5, 3, single (3)), 0.5, sqrt (eps ("single")))
+%!assert (betaincinv (0.34375, 4, single (3)), 0.5, sqrt (eps ("single")))
+
+## Extreme values
+%!assert (betaincinv (0, 42, 42), 0, sqrt (eps))
+%!assert (betaincinv (1, 42, 42), 1, sqrt (eps))
+
+%!error betaincinv ()
+%!error betaincinv (1, 2)
+*/
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/bsxfun.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,813 @@
+/*
+
+Copyright (C) 2007-2012 David Bateman
+Copyright (C) 2009 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+#include <vector>
+#include <list>
+
+#include "lo-mappers.h"
+
+#include "oct-map.h"
+#include "defun.h"
+#include "parse.h"
+#include "variables.h"
+#include "ov-colon.h"
+#include "unwind-prot.h"
+#include "ov-fcn-handle.h"
+
+// Optimized bsxfun operations
+enum bsxfun_builtin_op
+{
+  bsxfun_builtin_plus = 0,
+  bsxfun_builtin_minus,
+  bsxfun_builtin_times,
+  bsxfun_builtin_divide,
+  bsxfun_builtin_max,
+  bsxfun_builtin_min,
+  bsxfun_builtin_eq,
+  bsxfun_builtin_ne,
+  bsxfun_builtin_lt,
+  bsxfun_builtin_le,
+  bsxfun_builtin_gt,
+  bsxfun_builtin_ge,
+  bsxfun_builtin_and,
+  bsxfun_builtin_or,
+  bsxfun_builtin_power,
+  bsxfun_builtin_unknown,
+  bsxfun_num_builtin_ops = bsxfun_builtin_unknown
+};
+
+const char *bsxfun_builtin_names[] =
+{
+  "plus",
+  "minus",
+  "times",
+  "rdivide",
+  "max",
+  "min",
+  "eq",
+  "ne",
+  "lt",
+  "le",
+  "gt",
+  "ge",
+  "and",
+  "or",
+  "power"
+};
+
+static bsxfun_builtin_op
+bsxfun_builtin_lookup (const std::string& name)
+{
+  for (int i = 0; i < bsxfun_num_builtin_ops; i++)
+    if (name == bsxfun_builtin_names[i])
+      return static_cast<bsxfun_builtin_op> (i);
+  return bsxfun_builtin_unknown;
+}
+
+typedef octave_value (*bsxfun_handler) (const octave_value&, const octave_value&);
+
+// Static table of handlers.
+bsxfun_handler bsxfun_handler_table[bsxfun_num_builtin_ops][btyp_num_types];
+
+template <class NDA, NDA (bsxfun_op) (const NDA&, const NDA&)>
+static octave_value
+bsxfun_forward_op (const octave_value& x, const octave_value& y)
+{
+  NDA xa = octave_value_extract<NDA> (x);
+  NDA ya = octave_value_extract<NDA> (y);
+  return octave_value (bsxfun_op (xa, ya));
+}
+
+template <class NDA, boolNDArray (bsxfun_rel) (const NDA&, const NDA&)>
+static octave_value
+bsxfun_forward_rel (const octave_value& x, const octave_value& y)
+{
+  NDA xa = octave_value_extract<NDA> (x);
+  NDA ya = octave_value_extract<NDA> (y);
+  return octave_value (bsxfun_rel (xa, ya));
+}
+
+// Pow needs a special handler for reals because of the potentially complex result.
+template <class NDA, class CNDA>
+static octave_value
+do_bsxfun_real_pow (const octave_value& x, const octave_value& y)
+{
+  NDA xa = octave_value_extract<NDA> (x);
+  NDA ya = octave_value_extract<NDA> (y);
+  if (! ya.all_integers () && xa.any_element_is_negative ())
+    return octave_value (bsxfun_pow (CNDA (xa), ya));
+  else
+    return octave_value (bsxfun_pow (xa, ya));
+}
+
+static void maybe_fill_table (void)
+{
+  static bool filled = false;
+  if (filled)
+    return;
+
+#define REGISTER_OP_HANDLER(OP, BTYP, NDA, FUNOP) \
+  bsxfun_handler_table[OP][BTYP] = bsxfun_forward_op<NDA, FUNOP>
+#define REGISTER_REL_HANDLER(REL, BTYP, NDA, FUNREL) \
+  bsxfun_handler_table[REL][BTYP] = bsxfun_forward_rel<NDA, FUNREL>
+#define REGISTER_STD_HANDLERS(BTYP, NDA) \
+  REGISTER_OP_HANDLER (bsxfun_builtin_plus, BTYP, NDA, bsxfun_add); \
+  REGISTER_OP_HANDLER (bsxfun_builtin_minus, BTYP, NDA, bsxfun_sub); \
+  REGISTER_OP_HANDLER (bsxfun_builtin_times, BTYP, NDA, bsxfun_mul); \
+  REGISTER_OP_HANDLER (bsxfun_builtin_divide, BTYP, NDA, bsxfun_div); \
+  REGISTER_OP_HANDLER (bsxfun_builtin_max, BTYP, NDA, bsxfun_max); \
+  REGISTER_OP_HANDLER (bsxfun_builtin_min, BTYP, NDA, bsxfun_min); \
+  REGISTER_REL_HANDLER (bsxfun_builtin_eq, BTYP, NDA, bsxfun_eq); \
+  REGISTER_REL_HANDLER (bsxfun_builtin_ne, BTYP, NDA, bsxfun_ne); \
+  REGISTER_REL_HANDLER (bsxfun_builtin_lt, BTYP, NDA, bsxfun_lt); \
+  REGISTER_REL_HANDLER (bsxfun_builtin_le, BTYP, NDA, bsxfun_le); \
+  REGISTER_REL_HANDLER (bsxfun_builtin_gt, BTYP, NDA, bsxfun_gt); \
+  REGISTER_REL_HANDLER (bsxfun_builtin_ge, BTYP, NDA, bsxfun_ge)
+
+  REGISTER_STD_HANDLERS (btyp_double, NDArray);
+  REGISTER_STD_HANDLERS (btyp_float, FloatNDArray);
+  REGISTER_STD_HANDLERS (btyp_complex, ComplexNDArray);
+  REGISTER_STD_HANDLERS (btyp_float_complex, FloatComplexNDArray);
+  REGISTER_STD_HANDLERS (btyp_int8,  int8NDArray);
+  REGISTER_STD_HANDLERS (btyp_int16, int16NDArray);
+  REGISTER_STD_HANDLERS (btyp_int32, int32NDArray);
+  REGISTER_STD_HANDLERS (btyp_int64, int64NDArray);
+  REGISTER_STD_HANDLERS (btyp_uint8,  uint8NDArray);
+  REGISTER_STD_HANDLERS (btyp_uint16, uint16NDArray);
+  REGISTER_STD_HANDLERS (btyp_uint32, uint32NDArray);
+  REGISTER_STD_HANDLERS (btyp_uint64, uint64NDArray);
+
+  // For bools, we register and/or.
+  REGISTER_OP_HANDLER (bsxfun_builtin_and, btyp_bool, boolNDArray, bsxfun_and);
+  REGISTER_OP_HANDLER (bsxfun_builtin_or, btyp_bool, boolNDArray, bsxfun_or);
+
+  // Register power handlers.
+  bsxfun_handler_table[bsxfun_builtin_power][btyp_double] =
+    do_bsxfun_real_pow<NDArray, ComplexNDArray>;
+  bsxfun_handler_table[bsxfun_builtin_power][btyp_float] =
+    do_bsxfun_real_pow<FloatNDArray, FloatComplexNDArray>;
+
+  REGISTER_OP_HANDLER (bsxfun_builtin_power, btyp_complex, ComplexNDArray, bsxfun_pow);
+  REGISTER_OP_HANDLER (bsxfun_builtin_power, btyp_float_complex, FloatComplexNDArray, bsxfun_pow);
+
+  // For chars, we want just relational handlers.
+  REGISTER_REL_HANDLER (bsxfun_builtin_eq, btyp_char, charNDArray, bsxfun_eq);
+  REGISTER_REL_HANDLER (bsxfun_builtin_ne, btyp_char, charNDArray, bsxfun_ne);
+  REGISTER_REL_HANDLER (bsxfun_builtin_lt, btyp_char, charNDArray, bsxfun_lt);
+  REGISTER_REL_HANDLER (bsxfun_builtin_le, btyp_char, charNDArray, bsxfun_le);
+  REGISTER_REL_HANDLER (bsxfun_builtin_gt, btyp_char, charNDArray, bsxfun_gt);
+  REGISTER_REL_HANDLER (bsxfun_builtin_ge, btyp_char, charNDArray, bsxfun_ge);
+
+  filled = true;
+}
+
+static octave_value
+maybe_optimized_builtin (const std::string& name,
+                         const octave_value& a, const octave_value& b)
+{
+  octave_value retval;
+
+  maybe_fill_table ();
+
+  bsxfun_builtin_op op = bsxfun_builtin_lookup (name);
+  if (op != bsxfun_builtin_unknown)
+    {
+      builtin_type_t btyp_a = a.builtin_type (), btyp_b = b.builtin_type ();
+
+      // Simplify single/double combinations.
+      if (btyp_a == btyp_float && btyp_b == btyp_double)
+        btyp_b = btyp_float;
+      else if (btyp_a == btyp_double && btyp_b == btyp_float)
+        btyp_a = btyp_float;
+      else if (btyp_a == btyp_float_complex && btyp_b == btyp_complex)
+        btyp_b = btyp_float_complex;
+      else if (btyp_a == btyp_complex && btyp_b == btyp_float_complex)
+        btyp_a = btyp_float_complex;
+
+      if (btyp_a == btyp_b && btyp_a != btyp_unknown)
+        {
+          bsxfun_handler handler = bsxfun_handler_table[op][btyp_a];
+          if (handler)
+            retval = handler (a, b);
+        }
+    }
+
+  return retval;
+}
+
+static bool
+maybe_update_column (octave_value& Ac, const octave_value& A,
+                     const dim_vector& dva, const dim_vector& dvc,
+                     octave_idx_type i, octave_value_list &idx)
+{
+  octave_idx_type nd = dva.length ();
+
+  if (i == 0)
+    {
+      idx(0) = octave_value (':');
+      for (octave_idx_type j = 1; j < nd; j++)
+        {
+          if (dva (j) == 1)
+            idx(j) = octave_value (1);
+          else
+            idx(j) = octave_value ((i % dvc(j)) + 1);
+
+          i = i / dvc (j);
+        }
+
+      Ac = A;
+      Ac = Ac.single_subsref ("(", idx);
+      return true;
+    }
+  else
+    {
+      bool is_changed = false;
+      octave_idx_type k = i;
+      octave_idx_type k1 = i - 1;
+      for (octave_idx_type j = 1; j < nd; j++)
+        {
+          if (dva(j) != 1 && k % dvc (j) != k1 % dvc (j))
+            {
+              idx (j) = octave_value ((k % dvc(j)) + 1);
+              is_changed = true;
+            }
+
+          k = k / dvc (j);
+          k1 = k1 / dvc (j);
+        }
+
+      if (is_changed)
+        {
+          Ac = A;
+          Ac = Ac.single_subsref ("(", idx);
+          return true;
+        }
+      else
+        return false;
+    }
+}
+
+#if 0
+// FIXME -- this function is not used; is it OK to delete it?
+static void
+update_index (octave_value_list& idx, const dim_vector& dv, octave_idx_type i)
+{
+  octave_idx_type nd = dv.length ();
+
+  if (i == 0)
+    {
+      for (octave_idx_type j = nd - 1; j > 0; j--)
+        idx(j) = octave_value (static_cast<double>(1));
+      idx(0) = octave_value (':');
+    }
+  else
+    {
+      for (octave_idx_type j = 1; j < nd; j++)
+        {
+          idx (j) = octave_value (i % dv (j) + 1);
+          i = i / dv (j);
+        }
+    }
+}
+#endif
+
+static void
+update_index (Array<int>& idx, const dim_vector& dv, octave_idx_type i)
+{
+  octave_idx_type nd = dv.length ();
+
+  idx(0) = 0;
+  for (octave_idx_type j = 1; j < nd; j++)
+    {
+      idx (j) = i % dv (j);
+      i = i / dv (j);
+    }
+}
+
+DEFUN (bsxfun, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} bsxfun (@var{f}, @var{A}, @var{B})\n\
+The binary singleton expansion function applier performs broadcasting,\n\
+that is, applies a binary function @var{f} element-by-element to two\n\
+array arguments @var{A} and @var{B}, and expands as necessary\n\
+singleton dimensions in either input argument.  @var{f} is a function\n\
+handle, inline function, or string containing the name of the function\n\
+to evaluate.  The function @var{f} must be capable of accepting two\n\
+column-vector arguments of equal length, or one column vector argument\n\
+and a scalar.\n\
+\n\
+The dimensions of @var{A} and @var{B} must be equal or singleton.  The\n\
+singleton dimensions of the arrays will be expanded to the same\n\
+dimensionality as the other array.\n\
+@seealso{arrayfun, cellfun}\n\
+@end deftypefn")
+{
+  int nargin = args.length ();
+  octave_value_list retval;
+
+  if (nargin != 3)
+    print_usage ();
+  else
+    {
+      octave_value func = args(0);
+
+      if (func.is_string ())
+        {
+          std::string name = func.string_value ();
+          func = symbol_table::find_function (name);
+          if (func.is_undefined ())
+            error ("bsxfun: invalid function name: %s", name.c_str ());
+        }
+      else if (! (args(0).is_function_handle () || args(0).is_inline_function ()))
+        error ("bsxfun: F must be a string or function handle");
+
+      const octave_value A = args (1);
+      const octave_value B = args (2);
+
+      if (func.is_builtin_function ()
+          || (func.is_function_handle () && ! A.is_object () && ! B.is_object ()))
+        {
+          // This may break if the default behavior is overriden. But if you override
+          // arithmetic operators for builtin classes, you should expect mayhem
+          // anyway (constant folding etc). Querying is_overloaded may not be
+          // exactly what we need here.
+          octave_function *fcn_val = func.function_value ();
+          if (fcn_val)
+            {
+              octave_value tmp = maybe_optimized_builtin (fcn_val->name (), A, B);
+              if (tmp.is_defined ())
+                retval(0) = tmp;
+            }
+        }
+
+      if (! error_state && retval.empty ())
+        {
+          dim_vector dva = A.dims ();
+          octave_idx_type nda = dva.length ();
+          dim_vector dvb = B.dims ();
+          octave_idx_type ndb = dvb.length ();
+          octave_idx_type nd = nda;
+
+          if (nda > ndb)
+              dvb.resize (nda, 1);
+          else if (nda < ndb)
+            {
+              dva.resize (ndb, 1);
+              nd = ndb;
+            }
+
+          for (octave_idx_type i = 0; i < nd; i++)
+            if (dva (i) != dvb (i) && dva (i) != 1 && dvb (i) != 1)
+              {
+                error ("bsxfun: dimensions of A and B must match");
+                break;
+              }
+
+          if (!error_state)
+            {
+              // Find the size of the output
+              dim_vector dvc;
+              dvc.resize (nd);
+
+              for (octave_idx_type i = 0; i < nd; i++)
+                dvc (i) = (dva (i) < 1  ? dva (i) : (dvb (i) < 1 ? dvb (i) :
+                      (dva (i) > dvb (i) ? dva (i) : dvb (i))));
+
+              if (dva == dvb || dva.numel () == 1 || dvb.numel () == 1)
+                {
+                  octave_value_list inputs;
+                  inputs (0) = A;
+                  inputs (1) = B;
+                  retval = func.do_multi_index_op (1, inputs);
+                }
+              else if (dvc.numel () < 1)
+                {
+                  octave_value_list inputs;
+                  inputs (0) = A.resize (dvc);
+                  inputs (1) = B.resize (dvc);
+                  retval = func.do_multi_index_op (1, inputs);
+                }
+              else
+                {
+                  octave_idx_type ncount = 1;
+                  for (octave_idx_type i = 1; i < nd; i++)
+                    ncount *= dvc (i);
+
+#define BSXDEF(T) \
+                  T result_ ## T; \
+                  bool have_ ## T = false;
+
+                  BSXDEF(NDArray);
+                  BSXDEF(ComplexNDArray);
+                  BSXDEF(FloatNDArray);
+                  BSXDEF(FloatComplexNDArray);
+                  BSXDEF(boolNDArray);
+                  BSXDEF(int8NDArray);
+                  BSXDEF(int16NDArray);
+                  BSXDEF(int32NDArray);
+                  BSXDEF(int64NDArray);
+                  BSXDEF(uint8NDArray);
+                  BSXDEF(uint16NDArray);
+                  BSXDEF(uint32NDArray);
+                  BSXDEF(uint64NDArray);
+
+                  octave_value Ac ;
+                  octave_value_list idxA;
+                  octave_value Bc;
+                  octave_value_list idxB;
+                  octave_value C;
+                  octave_value_list inputs;
+                  Array<int> ra_idx (dim_vector (dvc.length (), 1), 0);
+
+
+                  for (octave_idx_type i = 0; i < ncount; i++)
+                    {
+                      if (maybe_update_column (Ac, A, dva, dvc, i, idxA))
+                        inputs (0) = Ac;
+
+                      if (maybe_update_column (Bc, B, dvb, dvc, i, idxB))
+                        inputs (1) = Bc;
+
+                      octave_value_list tmp = func.do_multi_index_op (1, inputs);
+
+                      if (error_state)
+                        break;
+
+#define BSXINIT(T, CLS, EXTRACTOR) \
+                      (result_type == CLS) \
+                        { \
+                            have_ ## T = true; \
+                            result_ ## T = \
+                                tmp (0). EXTRACTOR ## _array_value (); \
+                            result_ ## T .resize (dvc); \
+                        }
+
+                      if (i == 0)
+                        {
+                          if (! tmp(0).is_sparse_type ())
+                            {
+                              std::string result_type = tmp(0).class_name ();
+                              if (result_type == "double")
+                                {
+                                  if (tmp(0).is_real_type ())
+                                    {
+                                      have_NDArray = true;
+                                      result_NDArray = tmp(0).array_value ();
+                                      result_NDArray.resize (dvc);
+                                    }
+                                  else
+                                    {
+                                      have_ComplexNDArray = true;
+                                      result_ComplexNDArray =
+                                        tmp(0).complex_array_value ();
+                                      result_ComplexNDArray.resize (dvc);
+                                    }
+                                }
+                              else if (result_type == "single")
+                                {
+                                  if (tmp(0).is_real_type ())
+                                    {
+                                      have_FloatNDArray = true;
+                                      result_FloatNDArray = tmp(0).float_array_value ();
+                                      result_FloatNDArray.resize (dvc);
+                                    }
+                                  else
+                                    {
+                                      have_ComplexNDArray = true;
+                                      result_ComplexNDArray =
+                                        tmp(0).complex_array_value ();
+                                      result_ComplexNDArray.resize (dvc);
+                                    }
+                                }
+                              else if BSXINIT(boolNDArray, "logical", bool)
+                              else if BSXINIT(int8NDArray, "int8", int8)
+                              else if BSXINIT(int16NDArray, "int16", int16)
+                              else if BSXINIT(int32NDArray, "int32", int32)
+                              else if BSXINIT(int64NDArray, "int64", int64)
+                              else if BSXINIT(uint8NDArray, "uint8", uint8)
+                              else if BSXINIT(uint16NDArray, "uint16", uint16)
+                              else if BSXINIT(uint32NDArray, "uint32", uint32)
+                              else if BSXINIT(uint64NDArray, "uint64", uint64)
+                              else
+                                {
+                                  C = tmp (0);
+                                  C = C.resize (dvc);
+                                }
+                            }
+                        }
+                      else
+                        {
+                          update_index (ra_idx, dvc, i);
+
+                          if (have_FloatNDArray ||
+                              have_FloatComplexNDArray)
+                            {
+                              if (! tmp(0).is_float_type ())
+                                {
+                                  if (have_FloatNDArray)
+                                    {
+                                      have_FloatNDArray = false;
+                                      C = result_FloatNDArray;
+                                    }
+                                  else
+                                    {
+                                      have_FloatComplexNDArray = false;
+                                      C = result_FloatComplexNDArray;
+                                    }
+                                  C = do_cat_op (C, tmp(0), ra_idx);
+                                }
+                              else if (tmp(0).is_double_type ())
+                                {
+                                  if (tmp(0).is_complex_type () &&
+                                      have_FloatNDArray)
+                                    {
+                                      result_ComplexNDArray =
+                                        ComplexNDArray (result_FloatNDArray);
+                                      result_ComplexNDArray.insert
+                                        (tmp(0).complex_array_value (), ra_idx);
+                                      have_FloatComplexNDArray = false;
+                                      have_ComplexNDArray = true;
+                                    }
+                                  else
+                                    {
+                                      result_NDArray =
+                                        NDArray (result_FloatNDArray);
+                                      result_NDArray.insert
+                                        (tmp(0).array_value (), ra_idx);
+                                      have_FloatNDArray = false;
+                                      have_NDArray = true;
+                                    }
+                                }
+                              else if (tmp(0).is_real_type ())
+                                result_FloatNDArray.insert
+                                  (tmp(0).float_array_value (), ra_idx);
+                              else
+                                {
+                                  result_FloatComplexNDArray =
+                                    FloatComplexNDArray (result_FloatNDArray);
+                                  result_FloatComplexNDArray.insert
+                                    (tmp(0).float_complex_array_value (), ra_idx);
+                                  have_FloatNDArray = false;
+                                  have_FloatComplexNDArray = true;
+                                }
+                            }
+                          else if (have_NDArray)
+                            {
+                              if (! tmp(0).is_float_type ())
+                                {
+                                  have_NDArray = false;
+                                  C = result_NDArray;
+                                  C = do_cat_op (C, tmp(0), ra_idx);
+                                }
+                              else if (tmp(0).is_real_type ())
+                                result_NDArray.insert (tmp(0).array_value (),
+                                                       ra_idx);
+                              else
+                                {
+                                  result_ComplexNDArray =
+                                    ComplexNDArray (result_NDArray);
+                                  result_ComplexNDArray.insert
+                                    (tmp(0).complex_array_value (), ra_idx);
+                                  have_NDArray = false;
+                                  have_ComplexNDArray = true;
+                                }
+                            }
+
+#define BSXLOOP(T, CLS, EXTRACTOR) \
+                        (have_ ## T) \
+                          { \
+                            if (tmp (0).class_name () != CLS) \
+                              { \
+                                have_ ## T = false; \
+                                C = result_ ## T; \
+                                C = do_cat_op (C, tmp (0), ra_idx); \
+                              } \
+                            else \
+                              result_ ## T .insert \
+                                (tmp(0). EXTRACTOR ## _array_value (), \
+                                ra_idx); \
+                          }
+
+                          else if BSXLOOP(ComplexNDArray, "double", complex)
+                          else if BSXLOOP(boolNDArray, "logical", bool)
+                          else if BSXLOOP(int8NDArray, "int8", int8)
+                          else if BSXLOOP(int16NDArray, "int16", int16)
+                          else if BSXLOOP(int32NDArray, "int32", int32)
+                          else if BSXLOOP(int64NDArray, "int64", int64)
+                          else if BSXLOOP(uint8NDArray, "uint8", uint8)
+                          else if BSXLOOP(uint16NDArray, "uint16", uint16)
+                          else if BSXLOOP(uint32NDArray, "uint32", uint32)
+                          else if BSXLOOP(uint64NDArray, "uint64", uint64)
+                          else
+                            C = do_cat_op (C, tmp(0), ra_idx);
+                        }
+                    }
+
+#define BSXEND(T) \
+                  (have_ ## T) \
+                    retval(0) = result_ ## T;
+
+                  if BSXEND(NDArray)
+                  else if BSXEND(ComplexNDArray)
+                  else if BSXEND(FloatNDArray)
+                  else if BSXEND(FloatComplexNDArray)
+                  else if BSXEND(boolNDArray)
+                  else if BSXEND(int8NDArray)
+                  else if BSXEND(int16NDArray)
+                  else if BSXEND(int32NDArray)
+                  else if BSXEND(int64NDArray)
+                  else if BSXEND(uint8NDArray)
+                  else if BSXEND(uint16NDArray)
+                  else if BSXEND(uint32NDArray)
+                  else if BSXEND(uint64NDArray)
+                  else
+                    retval(0) = C;
+                }
+            }
+        }
+    }
+
+  return retval;
+}
+
+/*
+
+%!shared a, b, c, f
+%! a = randn (4, 4);
+%! b = mean (a, 1);
+%! c = mean (a, 2);
+%! f = @minus;
+%!error (bsxfun (f))
+%!error (bsxfun (f, a))
+%!error (bsxfun (a, b))
+%!error (bsxfun (a, b, c))
+%!error (bsxfun (f, a, b, c))
+%!error (bsxfun (f, ones (4, 0), ones (4, 4)))
+%!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0))
+%!assert (bsxfun (f, ones (1, 4), ones (4, 1)), zeros (4, 4))
+%!assert (bsxfun (f, a, b), a - repmat (b, 4, 1))
+%!assert (bsxfun (f, a, c), a - repmat (c, 1, 4))
+%!assert (bsxfun ("minus", ones (1, 4), ones (4, 1)), zeros (4, 4))
+
+%!shared a, b, c, f
+%! a = randn (4, 4);
+%! a(1) *= 1i;
+%! b = mean (a, 1);
+%! c = mean (a, 2);
+%! f = @minus;
+%!error (bsxfun (f))
+%!error (bsxfun (f, a))
+%!error (bsxfun (a, b))
+%!error (bsxfun (a, b, c))
+%!error (bsxfun (f, a, b, c))
+%!error (bsxfun (f, ones (4, 0), ones (4, 4)))
+%!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0))
+%!assert (bsxfun (f, ones (1, 4), ones (4, 1)), zeros (4, 4))
+%!assert (bsxfun (f, a, b), a - repmat (b, 4, 1))
+%!assert (bsxfun (f, a, c), a - repmat (c, 1, 4))
+%!assert (bsxfun ("minus", ones (1, 4), ones (4, 1)), zeros (4, 4))
+
+%!shared a, b, c, f
+%! a = randn (4, 4);
+%! a(end) *= 1i;
+%! b = mean (a, 1);
+%! c = mean (a, 2);
+%! f = @minus;
+%!error (bsxfun (f))
+%!error (bsxfun (f, a))
+%!error (bsxfun (a, b))
+%!error (bsxfun (a, b, c))
+%!error (bsxfun (f, a, b, c))
+%!error (bsxfun (f, ones (4, 0), ones (4, 4)))
+%!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0))
+%!assert (bsxfun (f, ones (1, 4), ones (4, 1)), zeros (4, 4))
+%!assert (bsxfun (f, a, b), a - repmat (b, 4, 1))
+%!assert (bsxfun (f, a, c), a - repmat (c, 1, 4))
+%!assert (bsxfun ("minus", ones (1, 4), ones (4, 1)), zeros (4, 4))
+
+%!shared a, b, c, f
+%! a = randn (4, 4);
+%! b = a (1, :);
+%! c = a (:, 1);
+%! f = @(x, y) x == y;
+%!error (bsxfun (f))
+%!error (bsxfun (f, a))
+%!error (bsxfun (a, b))
+%!error (bsxfun (a, b, c))
+%!error (bsxfun (f, a, b, c))
+%!error (bsxfun (f, ones (4, 0), ones (4, 4)))
+%!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0, "logical"))
+%!assert (bsxfun (f, ones (1, 4), ones (4, 1)), ones (4, 4, "logical"))
+%!assert (bsxfun (f, a, b), a == repmat (b, 4, 1))
+%!assert (bsxfun (f, a, c), a == repmat (c, 1, 4))
+
+%!shared a, b, c, d, f
+%! a = randn (4, 4, 4);
+%! b = mean (a, 1);
+%! c = mean (a, 2);
+%! d = mean (a, 3);
+%! f = @minus;
+%!error (bsxfun (f, ones ([4, 0, 4]), ones ([4, 4, 4])))
+%!assert (bsxfun (f, ones ([4, 0, 4]), ones ([4, 1, 4])), zeros ([4, 0, 4]))
+%!assert (bsxfun (f, ones ([4, 4, 0]), ones ([4, 1, 1])), zeros ([4, 4, 0]))
+%!assert (bsxfun (f, ones ([1, 4, 4]), ones ([4, 1, 4])), zeros ([4, 4, 4]))
+%!assert (bsxfun (f, ones ([4, 4, 1]), ones ([4, 1, 4])), zeros ([4, 4, 4]))
+%!assert (bsxfun (f, ones ([4, 1, 4]), ones ([1, 4, 4])), zeros ([4, 4, 4]))
+%!assert (bsxfun (f, ones ([4, 1, 4]), ones ([1, 4, 1])), zeros ([4, 4, 4]))
+%!assert (bsxfun (f, a, b), a - repmat (b, [4, 1, 1]))
+%!assert (bsxfun (f, a, c), a - repmat (c, [1, 4, 1]))
+%!assert (bsxfun (f, a, d), a - repmat (d, [1, 1, 4]))
+%!assert (bsxfun ("minus", ones ([4, 0, 4]), ones ([4, 1, 4])), zeros ([4, 0, 4]))
+
+%% The test below is a very hard case to treat
+%!assert (bsxfun (f, ones ([4, 1, 4, 1]), ones ([1, 4, 1, 4])), zeros ([4, 4, 4, 4]));
+
+%!shared a, b, aa, bb
+%! a = randn (3, 1, 3);
+%! aa = a(:, ones (1, 3), :, ones (1, 3));
+%! b = randn (1, 3, 3, 3);
+%! bb = b(ones (1, 3), :, :, :);
+%!assert (bsxfun (@plus, a, b), aa + bb)
+%!assert (bsxfun (@minus, a, b), aa - bb)
+%!assert (bsxfun (@times, a, b), aa .* bb)
+%!assert (bsxfun (@rdivide, a, b), aa ./ bb)
+%!assert (bsxfun (@ldivide, a, b), aa .\ bb)
+%!assert (bsxfun (@power, a, b), aa .^ bb)
+%!assert (bsxfun (@power, abs (a), b), abs (aa) .^ bb)
+%!assert (bsxfun (@eq, round (a), round (b)), round (aa) == round (bb))
+%!assert (bsxfun (@ne, round (a), round (b)), round (aa) != round (bb))
+%!assert (bsxfun (@lt, a, b), aa < bb)
+%!assert (bsxfun (@le, a, b), aa <= bb)
+%!assert (bsxfun (@gt, a, b), aa > bb)
+%!assert (bsxfun (@ge, a, b), aa >= bb)
+%!assert (bsxfun (@min, a, b), min (aa, bb))
+%!assert (bsxfun (@max, a, b), max (aa, bb))
+%!assert (bsxfun (@and, a > 0, b > 0), (aa > 0) & (bb > 0))
+%!assert (bsxfun (@or, a > 0, b > 0), (aa > 0) | (bb > 0))
+
+%% Test automatic bsxfun
+%
+%!test
+%! funs = {@plus, @minus, @times, @rdivide, @ldivide, @power, @max, @min, \
+%!         @rem, @mod, @atan2, @hypot, @eq, @ne, @lt, @le, @gt, @ge, \
+%!         @and, @or, @xor };
+%!
+%! float_types = {@single, @double};
+%! int_types = {@int8, @int16, @int32, @int64, \
+%!              @uint8, @uint16, @uint32, @uint64};
+%!
+%! x = rand (3) * 10-5;
+%! y = rand (3,1) * 10-5;
+%!
+%! for i=1:length (funs)
+%!   for j = 1:length (float_types)
+%!     for k = 1:length (int_types)
+%!
+%!       fun = funs{i};
+%!       f_type = float_types{j};
+%!       i_type = int_types{k};
+%!
+%!         assert (bsxfun (fun, f_type (x), i_type (y)), \
+%!                 fun (f_type(x), i_type (y)));
+%!         assert (bsxfun (fun, f_type (y), i_type (x)), \
+%!                 fun (f_type(y), i_type (x)));
+%!
+%!         assert (bsxfun (fun, i_type (x), i_type (y)), \
+%!                 fun (i_type (x), i_type (y)));
+%!         assert (bsxfun (fun, i_type (y), i_type (x)), \
+%!                 fun (i_type (y), i_type (x)));
+%!
+%!         assert (bsxfun (fun, f_type (x), f_type (y)), \
+%!                 fun (f_type (x), f_type (y)));
+%!         assert (bsxfun (fun, f_type(y), f_type(x)), \
+%!                 fun (f_type (y), f_type (x)));
+%!     endfor
+%!   endfor
+%! endfor
+%!
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/cellfun.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,2472 @@
+/*
+
+Copyright (C) 2005-2012 Mohamed Kamoun
+Copyright (C) 2006-2012 Bill Denney
+Copyright (C) 2009 Jaroslav Hajek
+Copyright (C) 2010 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+#include <vector>
+#include <list>
+#include <memory>
+
+#include "caseless-str.h"
+#include "lo-mappers.h"
+#include "oct-locbuf.h"
+
+#include "Cell.h"
+#include "oct-map.h"
+#include "defun.h"
+#include "parse.h"
+#include "variables.h"
+#include "ov-colon.h"
+#include "unwind-prot.h"
+#include "gripes.h"
+#include "utils.h"
+
+#include "ov-class.h"
+#include "ov-scalar.h"
+#include "ov-float.h"
+#include "ov-complex.h"
+#include "ov-flt-complex.h"
+#include "ov-bool.h"
+#include "ov-int8.h"
+#include "ov-int16.h"
+#include "ov-int32.h"
+#include "ov-int64.h"
+#include "ov-uint8.h"
+#include "ov-uint16.h"
+#include "ov-uint32.h"
+#include "ov-uint64.h"
+
+#include "ov-fcn-handle.h"
+
+static octave_value_list
+get_output_list (octave_idx_type count, octave_idx_type nargout,
+                 const octave_value_list& inputlist,
+                 octave_value& func,
+                 octave_value& error_handler)
+{
+  octave_value_list tmp = func.do_multi_index_op (nargout, inputlist);
+
+  if (error_state)
+    {
+      if (error_handler.is_defined ())
+        {
+          octave_scalar_map msg;
+          msg.assign ("identifier", last_error_id ());
+          msg.assign ("message", last_error_message ());
+          msg.assign ("index", static_cast<double> (count + static_cast<octave_idx_type>(1)));
+
+          octave_value_list errlist = inputlist;
+          errlist.prepend (msg);
+
+          buffer_error_messages--;
+
+          error_state = 0;
+
+          tmp = error_handler.do_multi_index_op (nargout, errlist);
+
+          buffer_error_messages++;
+
+          if (error_state)
+            tmp.clear ();
+        }
+      else
+        tmp.clear ();
+    }
+
+  return tmp;
+}
+
+static octave_value_list
+try_cellfun_internal_ops (const octave_value_list& args, int nargin)
+{
+  octave_value_list retval;
+
+  std::string name = args(0).string_value ();
+
+  const Cell f_args = args(1).cell_value ();
+
+  octave_idx_type k = f_args.numel ();
+
+  if (name == "isempty")
+    {
+      boolNDArray result (f_args.dims ());
+      for (octave_idx_type count = 0; count < k; count++)
+        result(count) = f_args.elem (count).is_empty ();
+      retval(0) = result;
+    }
+  else if (name == "islogical")
+    {
+      boolNDArray result (f_args.dims ());
+      for (octave_idx_type  count= 0; count < k; count++)
+        result(count) = f_args.elem (count).is_bool_type ();
+      retval(0) = result;
+    }
+  else if (name == "isreal")
+    {
+      boolNDArray result (f_args.dims ());
+      for (octave_idx_type  count= 0; count < k; count++)
+        result(count) = f_args.elem (count).is_real_type ();
+      retval(0) = result;
+    }
+  else if (name == "length")
+    {
+      NDArray result (f_args.dims ());
+      for (octave_idx_type  count= 0; count < k; count++)
+        result(count) = static_cast<double> (f_args.elem (count).length ());
+      retval(0) = result;
+    }
+  else if (name == "ndims")
+    {
+      NDArray result (f_args.dims ());
+      for (octave_idx_type count = 0; count < k; count++)
+        result(count) = static_cast<double> (f_args.elem (count).ndims ());
+      retval(0) = result;
+    }
+  else if (name == "prodofsize" || name == "numel")
+    {
+      NDArray result (f_args.dims ());
+      for (octave_idx_type count = 0; count < k; count++)
+        result(count) = static_cast<double> (f_args.elem (count).numel ());
+      retval(0) = result;
+    }
+  else if (name == "size")
+    {
+      if (nargin == 3)
+        {
+          int d = args(2).nint_value () - 1;
+
+          if (d < 0)
+            error ("cellfun: K must be a positive integer");
+
+          if (! error_state)
+            {
+              NDArray result (f_args.dims ());
+              for (octave_idx_type count = 0; count < k; count++)
+                {
+                  dim_vector dv = f_args.elem (count).dims ();
+                  if (d < dv.length ())
+                    result(count) = static_cast<double> (dv(d));
+                  else
+                    result(count) = 1.0;
+                }
+              retval(0) = result;
+            }
+        }
+      else
+        error ("cellfun: not enough arguments for \"size\"");
+    }
+  else if (name == "isclass")
+    {
+      if (nargin == 3)
+        {
+          std::string class_name = args(2).string_value ();
+          boolNDArray result (f_args.dims ());
+          for (octave_idx_type count = 0; count < k; count++)
+            result(count) = (f_args.elem (count).class_name () == class_name);
+
+          retval(0) = result;
+        }
+      else
+        error ("cellfun: not enough arguments for \"isclass\"");
+    }
+
+  return retval;
+}
+
+static void
+get_mapper_fun_options (const octave_value_list& args, int& nargin,
+                        bool& uniform_output, octave_value& error_handler)
+{
+  while (nargin > 3 && args(nargin-2).is_string ())
+    {
+      caseless_str arg = args(nargin-2).string_value ();
+
+      size_t compare_len = std::max (arg.length (), static_cast<size_t> (2));
+
+      if (arg.compare ("uniformoutput", compare_len))
+        uniform_output = args(nargin-1).bool_value ();
+      else if (arg.compare ("errorhandler", compare_len))
+        {
+          if (args(nargin-1).is_function_handle ()
+              || args(nargin-1).is_inline_function ())
+            {
+              error_handler = args(nargin-1);
+            }
+          else if (args(nargin-1).is_string ())
+            {
+              std::string err_name = args(nargin-1).string_value ();
+
+              error_handler = symbol_table::find_function (err_name);
+
+              if (error_handler.is_undefined ())
+                {
+                  error ("cellfun: invalid function NAME: %s",
+                         err_name.c_str ());
+                  break;
+                }
+            }
+          else
+            {
+              error ("cellfun: invalid value for 'ErrorHandler' function");
+              break;
+            }
+        }
+      else
+        {
+          error ("cellfun: unrecognized parameter %s",
+                 arg.c_str ());
+          break;
+        }
+
+      nargin -= 2;
+    }
+
+  nargin -= 1;
+}
+
+DEFUN (cellfun, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} cellfun (@var{name}, @var{C})\n\
+@deftypefnx {Built-in Function} {} cellfun (\"size\", @var{C}, @var{k})\n\
+@deftypefnx {Built-in Function} {} cellfun (\"isclass\", @var{C}, @var{class})\n\
+@deftypefnx {Built-in Function} {} cellfun (@var{func}, @var{C})\n\
+@deftypefnx {Built-in Function} {} cellfun (@var{func}, @var{C}, @var{D})\n\
+@deftypefnx {Built-in Function} {[@var{a}, @dots{}] =} cellfun (@dots{})\n\
+@deftypefnx {Built-in Function} {} cellfun (@dots{}, \"ErrorHandler\", @var{errfunc})\n\
+@deftypefnx {Built-in Function} {} cellfun (@dots{}, \"UniformOutput\", @var{val})\n\
+\n\
+Evaluate the function named @var{name} on the elements of the cell array\n\
+@var{C}.  Elements in @var{C} are passed on to the named function\n\
+individually.  The function @var{name} can be one of the functions\n\
+\n\
+@table @code\n\
+@item isempty\n\
+Return 1 for empty elements.\n\
+\n\
+@item islogical\n\
+Return 1 for logical elements.\n\
+\n\
+@item isreal\n\
+Return 1 for real elements.\n\
+\n\
+@item length\n\
+Return a vector of the lengths of cell elements.\n\
+\n\
+@item ndims\n\
+Return the number of dimensions of each element.\n\
+\n\
+@item numel\n\
+@itemx prodofsize\n\
+Return the number of elements contained within each cell element.  The\n\
+number is the product of the dimensions of the object at each cell element.\n\
+\n\
+@item size\n\
+Return the size along the @var{k}-th dimension.\n\
+\n\
+@item isclass\n\
+Return 1 for elements of @var{class}.\n\
+@end table\n\
+\n\
+Additionally, @code{cellfun} accepts an arbitrary function @var{func}\n\
+in the form of an inline function, function handle, or the name of a\n\
+function (in a character string).  In the case of a character string\n\
+argument, the function must accept a single argument named @var{x}, and\n\
+it must return a string value.  The function can take one or more arguments,\n\
+with the inputs arguments given by @var{C}, @var{D}, etc.  Equally the\n\
+function can return one or more output arguments.  For example:\n\
+\n\
+@example\n\
+@group\n\
+cellfun (\"atan2\", @{1, 0@}, @{0, 1@})\n\
+     @result{} [ 1.57080   0.00000 ]\n\
+@end group\n\
+@end example\n\
+\n\
+The number of output arguments of @code{cellfun} matches the number of output\n\
+arguments of the function.  The outputs of the function will be collected\n\
+into the output arguments of @code{cellfun} like this:\n\
+\n\
+@example\n\
+@group\n\
+function [a, b] = twoouts (x)\n\
+  a = x;\n\
+  b = x*x;\n\
+endfunction\n\
+[aa, bb] = cellfun (@@twoouts, @{1, 2, 3@})\n\
+     @result{}\n\
+        aa =\n\
+           1 2 3\n\
+        bb =\n\
+           1 4 9\n\
+@end group\n\
+@end example\n\
+\n\
+Note that per default the output argument(s) are arrays of the same size as\n\
+the input arguments.  Input arguments that are singleton (1x1) cells will be\n\
+automatically expanded to the size of the other arguments.\n\
+\n\
+If the parameter \"UniformOutput\" is set to true (the default), then the\n\
+function must return scalars which will be concatenated into the return\n\
+array(s).  If \"UniformOutput\" is false, the outputs are concatenated into a\n\
+cell array (or cell arrays).  For example:\n\
+\n\
+@example\n\
+@group\n\
+cellfun (\"tolower\", @{\"Foo\", \"Bar\", \"FooBar\"@},\n\
+         \"UniformOutput\", false)\n\
+@result{} @{\"foo\", \"bar\", \"foobar\"@}\n\
+@end group\n\
+@end example\n\
+\n\
+Given the parameter \"ErrorHandler\", then @var{errfunc} defines a function\n\
+to call in case @var{func} generates an error.  The form of the function is\n\
+\n\
+@example\n\
+function [@dots{}] = errfunc (@var{s}, @dots{})\n\
+@end example\n\
+\n\
+@noindent\n\
+where there is an additional input argument to @var{errfunc} relative to\n\
+@var{func}, given by @var{s}.  This is a structure with the elements\n\
+'identifier', 'message' and 'index', giving respectively the error\n\
+identifier, the error message, and the index into the input arguments\n\
+of the element that caused the error.  For example:\n\
+\n\
+@example\n\
+@group\n\
+function y = foo (s, x), y = NaN; endfunction\n\
+cellfun (\"factorial\", @{-1,2@}, \"ErrorHandler\", @@foo)\n\
+@result{} [NaN 2]\n\
+@end group\n\
+@end example\n\
+\n\
+Use @code{cellfun} intelligently.  The @code{cellfun} function is a\n\
+useful tool for avoiding loops.  It is often used with anonymous\n\
+function handles; however, calling an anonymous function involves an\n\
+overhead quite comparable to the overhead of an m-file function.\n\
+Passing a handle to a built-in function is faster, because the\n\
+interpreter is not involved in the internal loop.  For example:\n\
+\n\
+@example\n\
+@group\n\
+a = @{@dots{}@}\n\
+v = cellfun (@@(x) det (x), a); # compute determinants\n\
+v = cellfun (@@det, a); # faster\n\
+@end group\n\
+@end example\n\
+\n\
+@seealso{arrayfun, structfun, spfun}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+  int nargin = args.length ();
+  int nargout1 = (nargout < 1 ? 1 : nargout);
+
+  if (nargin < 2)
+    {
+      error ("cellfun: function requires at least 2 arguments");
+      print_usage ();
+      return retval;
+    }
+
+  octave_value func = args(0);
+
+  if (! args(1).is_cell ())
+    {
+      error ("cellfun: C must be a cell array");
+
+      return retval;
+    }
+
+  if (func.is_string ())
+    {
+      retval = try_cellfun_internal_ops (args, nargin);
+
+      if (error_state || ! retval.empty ())
+        return retval;
+
+      // See if we can convert the string into a function.
+
+      std::string name = args(0).string_value ();
+
+      if (! valid_identifier (name))
+        {
+          std::string fcn_name = unique_symbol_name ("__cellfun_fcn_");
+          std::string fname = "function y = " + fcn_name + "(x) y = ";
+
+          octave_function *ptr_func
+            = extract_function (args(0), "cellfun", fcn_name,
+                                fname, "; endfunction");
+
+          if (ptr_func && ! error_state)
+            func = octave_value (ptr_func, true);
+        }
+      else
+        {
+          func = symbol_table::find_function (name);
+
+          if (func.is_undefined ())
+            error ("cellfun: invalid function NAME: %s", name.c_str ());
+        }
+
+      if (error_state || ! retval.empty ())
+        return retval;
+    }
+
+  if (func.is_function_handle () || func.is_inline_function ()
+      || func.is_function ())
+    {
+
+      // The following is an optimisation because the symbol table can
+      // give a more specific function class, so this can result in
+      // fewer polymorphic function calls as the function gets called
+      // for each value of the array.
+      {
+        if (func.is_function_handle ())
+          {
+            octave_fcn_handle* f = func.fcn_handle_value ();
+
+            // Overloaded function handles need to check the type of the
+            // arguments for each element of the array, so they cannot
+            // be optimised this way.
+            if (f -> is_overloaded ())
+              goto nevermind;
+          }
+
+        std::string name = func.function_value () -> name ();
+        octave_value f = symbol_table::find_function (name);
+
+        if (f.is_defined ())
+          {
+            //Except for these two which are special cases...
+            if (name != "size" && name != "class")
+              {
+                //Try first the optimised code path for built-in functions
+                octave_value_list tmp_args = args;
+                tmp_args(0) = name;
+                retval = try_cellfun_internal_ops (tmp_args, nargin);
+                if (error_state || ! retval.empty ())
+                  return retval;
+              }
+
+            //Okay, we tried, doesn't work, let's do the best we can
+            //instead and avoid polymorphic calls for each element of
+            //the array.
+            func = f;
+          }
+      }
+    nevermind:
+
+      bool uniform_output = true;
+      octave_value error_handler;
+
+      get_mapper_fun_options (args, nargin, uniform_output, error_handler);
+
+      if (error_state)
+        return octave_value_list ();
+
+      // Extract cell arguments.
+
+      octave_value_list inputlist (nargin, octave_value ());
+
+      OCTAVE_LOCAL_BUFFER (Cell, inputs, nargin);
+      OCTAVE_LOCAL_BUFFER (bool, mask, nargin);
+
+      // This is to prevent copy-on-write.
+      const Cell *cinputs = inputs;
+
+      octave_idx_type k = 1;
+
+      dim_vector fdims (1, 1);
+
+      // Collect arguments.  Pre-fill scalar elements of inputlist
+      // array.
+
+      for (int j = 0; j < nargin; j++)
+        {
+          if (! args(j+1).is_cell ())
+            {
+              error ("cellfun: arguments must be cells");
+              return octave_value_list ();
+            }
+
+          inputs[j] = args(j+1).cell_value ();
+          mask[j] = inputs[j].numel () != 1;
+          if (! mask[j])
+            inputlist(j) = cinputs[j](0);
+        }
+
+      for (int j = 0; j < nargin; j++)
+        {
+          if (mask[j])
+            {
+              fdims = inputs[j].dims ();
+              k = inputs[j].numel ();
+              for (int i = j+1; i < nargin; i++)
+                {
+                  if (mask[i] && inputs[i].dims () != fdims)
+                    {
+                      error ("cellfun: dimensions mismatch");
+                      return octave_value_list ();
+                    }
+                }
+              break;
+            }
+        }
+
+      unwind_protect frame;
+      frame.protect_var (buffer_error_messages);
+
+      if (error_handler.is_defined ())
+        buffer_error_messages++;
+
+      // Apply functions.
+
+      if (uniform_output)
+        {
+          std::list<octave_value_list> idx_list (1);
+          idx_list.front ().resize (1);
+          std::string idx_type = "(";
+
+          OCTAVE_LOCAL_BUFFER (octave_value, retv, nargout1);
+
+          for (octave_idx_type count = 0; count < k; count++)
+            {
+              for (int j = 0; j < nargin; j++)
+                {
+                  if (mask[j])
+                    inputlist.xelem (j) = cinputs[j](count);
+                }
+
+              const octave_value_list tmp
+                = get_output_list (count, nargout, inputlist, func,
+                                   error_handler);
+
+              if (error_state)
+                return retval;
+
+              if (nargout > 0 && tmp.length () < nargout)
+                {
+                  error ("cellfun: function returned fewer than nargout values");
+                  return retval;
+                }
+
+              if  (nargout > 0
+                   || (nargout == 0
+                       && tmp.length () > 0 && tmp(0).is_defined ()))
+                {
+                  int num_to_copy = tmp.length ();
+
+                  if (num_to_copy > nargout1)
+                    num_to_copy = nargout1;
+
+                  if (count == 0)
+                    {
+                      for (int j = 0; j < num_to_copy; j++)
+                        {
+                          if (tmp(j).is_defined ())
+                            {
+                              octave_value val = tmp(j);
+
+                              if (val.numel () == 1)
+                                retv[j] = val.resize (fdims);
+                              else
+                                {
+                                  error ("cellfun: all values must be scalars when UniformOutput = true");
+                                  break;
+                                }
+                            }
+                        }
+                    }
+                  else
+                    {
+                      for (int j = 0; j < num_to_copy; j++)
+                        {
+                          if (tmp(j).is_defined ())
+                            {
+                              octave_value val = tmp(j);
+
+                              if (! retv[j].fast_elem_insert (count, val))
+                                {
+                                  if (val.numel () == 1)
+                                    {
+                                      idx_list.front ()(0) = count + 1.0;
+                                      retv[j].assign (octave_value::op_asn_eq,
+                                                      idx_type, idx_list, val);
+
+                                      if (error_state)
+                                        break;
+                                    }
+                                  else
+                                    {
+                                      error ("cellfun: all values must be scalars when UniformOutput = true");
+                                      break;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+
+              if (error_state)
+                break;
+            }
+
+          retval.resize (nargout1);
+
+          for (int j = 0; j < nargout1; j++)
+            {
+              if (nargout > 0 && retv[j].is_undefined ())
+                retval(j) = NDArray (fdims);
+              else
+                retval(j) = retv[j];
+            }
+        }
+      else
+        {
+          OCTAVE_LOCAL_BUFFER (Cell, results, nargout1);
+
+          for (int j = 0; j < nargout1; j++)
+            results[j].resize (fdims, Matrix ());
+
+          bool have_some_output = false;
+
+          for (octave_idx_type count = 0; count < k; count++)
+            {
+              for (int j = 0; j < nargin; j++)
+                {
+                  if (mask[j])
+                    inputlist.xelem (j) = cinputs[j](count);
+                }
+
+              const octave_value_list tmp
+                = get_output_list (count, nargout, inputlist, func,
+                                   error_handler);
+
+              if (error_state)
+                return retval;
+
+              if (nargout > 0 && tmp.length () < nargout)
+                {
+                  error ("cellfun: function returned fewer than nargout values");
+                  return retval;
+                }
+
+              if  (nargout > 0
+                   || (nargout == 0
+                       && tmp.length () > 0 && tmp(0).is_defined ()))
+                {
+                  int num_to_copy = tmp.length ();
+
+                  if (num_to_copy > nargout1)
+                    num_to_copy = nargout1;
+
+                  if (num_to_copy > 0)
+                    have_some_output = true;
+
+                  for (int j = 0; j < num_to_copy; j++)
+                    results[j](count) = tmp(j);
+                }
+            }
+
+          if (have_some_output || fdims.any_zero ())
+            {
+              retval.resize (nargout1);
+
+              for (int j = 0; j < nargout1; j++)
+                retval(j) = results[j];
+            }
+        }
+    }
+  else
+    error ("cellfun: argument NAME must be a string or function handle");
+
+  return retval;
+}
+
+/*
+
+%!function r = __f11 (x)
+%!  global __cellfun_test_num_outputs__;
+%!  __cellfun_test_num_outputs__ = nargout;
+%!  r = x;
+%!endfunction
+
+%!function __f01 (x)
+%!  global __cellfun_test_num_outputs__;
+%!  __cellfun_test_num_outputs__ = nargout;
+%!endfunction
+
+%!test
+%! global __cellfun_test_num_outputs__;
+%! cellfun (@__f11, {1});
+%! assert (__cellfun_test_num_outputs__, 0);
+%! x = cellfun (@__f11, {1});
+%! assert (__cellfun_test_num_outputs__, 1);
+
+%!test
+%! global __cellfun_test_num_outputs__;
+%! cellfun (@__f01, {1});
+%! assert (__cellfun_test_num_outputs__, 0);
+
+%!error x = cellfun (@__f01, {1, 2});
+
+%!test
+%! assert (cellfun (@__f11, {1, 2}), [1, 2]);
+%! assert (cellfun (@__f11, {1, 2}, 'uniformoutput', false), {1, 2});
+
+%!test
+%! [a,b] = cellfun (@(x) x, cell (2, 0));
+%! assert (a, zeros (2, 0));
+%! assert (b, zeros (2, 0));
+
+%!test
+%! [a,b] = cellfun (@(x) x, cell (2, 0), "uniformoutput", false);
+%! assert (a, cell (2, 0));
+%! assert (b, cell (2, 0));
+
+%% Test function to check the "Errorhandler" option
+%!function z = __cellfunerror (S, varargin)
+%!  z = S;
+%!endfunction
+
+%% First input argument can be a string, an inline function,
+%% a function_handle or an anonymous function
+%!test
+%! A = cellfun ("islogical", {true, 0.1, false, i*2});
+%! assert (A, [true, false, true, false]);
+%!test
+%! A = cellfun (inline ("islogical (x)", "x"), {true, 0.1, false, i*2});
+%! assert (A, [true, false, true, false]);
+%!test
+%! A = cellfun (@islogical, {true, 0.1, false, i*2});
+%! assert (A, [true, false, true, false]);
+%!test
+%! A = cellfun (@(x) islogical (x), {true, 0.1, false, i*2});
+%! assert (A, [true, false, true, false]);
+
+%% First input argument can be the special string "isreal",
+%% "isempty", "islogical", "length", "ndims" or "prodofsize"
+%!test
+%! A = cellfun ("isreal", {true, 0.1, {}, i*2, [], "abc"});
+%! assert (A, [true, true, false, false, true, true]);
+%!test
+%! A = cellfun ("isempty", {true, 0.1, false, i*2, [], "abc"});
+%! assert (A, [false, false, false, false, true, false]);
+%!test
+%! A = cellfun ("islogical", {true, 0.1, false, i*2, [], "abc"});
+%! assert (A, [true, false, true, false, false, false]);
+%!test
+%! A = cellfun ("length", {true, 0.1, false, i*2, [], "abc"});
+%! assert (A, [1, 1, 1, 1, 0, 3]);
+%!test
+%! A = cellfun ("ndims", {[1, 2; 3, 4]; (cell (1,2,3,4))});
+%! assert (A, [2; 4]);
+%!test
+%! A = cellfun ("prodofsize", {[1, 2; 3, 4], (cell (1,2,3,4))});
+%! assert (A, [4, 24]);
+
+%% Number of input and output arguments may not be limited to one
+%!test
+%! A = cellfun (@(x,y,z) x + y + z, {1, 1, 1}, {2, 2, 2}, {3, 4, 5});
+%! assert (A, [6, 7, 8]);
+%!test
+%! A = cellfun (@(x,y,z) x + y + z, {1, 1, 1}, {2, 2, 2}, {3, 4, 5}, \
+%!              "UniformOutput", false);
+%! assert (A, {6, 7, 8});
+%!test %% Two input arguments of different types
+%! A = cellfun (@(x,y) islogical (x) && ischar (y), {false, true}, {"a", 3});
+%! assert (A, [true, false]);
+%!test %% Pass another variable to the anonymous function
+%! y = true;
+%! A = cellfun (@(x) islogical (x) && y, {false, 0.3});
+%! assert (A, [true, false]);
+%!test %% Three ouptut arguments of different type
+%! [A, B, C] = cellfun (@find, {10, 11; 0, 12}, "UniformOutput", false);
+%! assert (isequal (A, {true, true; [], true}));
+%! assert (isequal (B, {true, true; [], true}));
+%! assert (isequal (C, {10, 11; [], 12}));
+
+%% Input arguments can be of type cell array of logical
+%!test
+%! A = cellfun (@(x,y) x == y, {false, true}, {true, true});
+%! assert (A, [false, true]);
+%!test
+%! A = cellfun (@(x,y) x == y, {false; true}, {true; true}, \
+%!              "UniformOutput", true);
+%! assert (A, [false; true]);
+%!test
+%! A = cellfun (@(x) x, {false, true; false, true}, "UniformOutput", false);
+%! assert (A, {false, true; false, true});
+%!test %% Three ouptut arguments of same type
+%! [A, B, C] = cellfun (@find, {true, false; false, true}, \
+%!                      "UniformOutput", false);
+%! assert (isequal (A, {true, []; [], true}));
+%! assert (isequal (B, {true, []; [], true}));
+%! assert (isequal (C, {true, []; [], true}));
+%!test
+%! A = cellfun (@(x,y) cell2str (x,y), {true}, {true}, \
+%!              "ErrorHandler", @__cellfunerror);
+%! assert (isfield (A, "identifier"), true);
+%! assert (isfield (A, "message"), true);
+%! assert (isfield (A, "index"), true);
+%! assert (isempty (A.message), false);
+%! assert (A.index, 1);
+%!test %% Overwriting setting of "UniformOutput" true
+%! A = cellfun (@(x,y) cell2str (x,y), {true}, {true}, \
+%!              "UniformOutput", true, "ErrorHandler", @__cellfunerror);
+%! assert (isfield (A, "identifier"), true);
+%! assert (isfield (A, "message"), true);
+%! assert (isfield (A, "index"), true);
+%! assert (isempty (A.message), false);
+%! assert (A.index, 1);
+
+%% Input arguments can be of type cell array of numeric
+%!test
+%! A = cellfun (@(x,y) x>y, {1.1, 4.2}, {3.1, 2+3*i});
+%! assert (A, [false, true]);
+%!test
+%! A = cellfun (@(x,y) x>y, {1.1, 4.2; 2, 4}, {3.1, 2; 2, 4+2*i}, \
+%!              "UniformOutput", true);
+%! assert (A, [false, true; false, false]);
+%!test
+%! A = cellfun (@(x,y) x:y, {1.1, 4}, {3.1, 6}, "UniformOutput", false);
+%! assert (isequal (A{1}, [1.1, 2.1, 3.1]));
+%! assert (isequal (A{2}, [4, 5, 6]));
+%!test %% Three ouptut arguments of different type
+%! [A, B, C] = cellfun (@find, {10, 11; 0, 12}, "UniformOutput", false);
+%! assert (isequal (A, {true, true; [], true}));
+%! assert (isequal (B, {true, true; [], true}));
+%! assert (isequal (C, {10, 11; [], 12}));
+%!test
+%! A = cellfun (@(x,y) cell2str (x,y), {1.1, 4}, {3.1, 6}, \
+%!              "ErrorHandler", @__cellfunerror);
+%! B = isfield (A(1), "message") && isfield (A(1), "index");
+%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
+%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
+%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
+%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
+%! assert ([A(1).index, A(2).index], [1, 2]);
+%!test %% Overwriting setting of "UniformOutput" true
+%! A = cellfun (@(x,y) cell2str (x,y), {1.1, 4}, {3.1, 6}, \
+%!              "UniformOutput", true, "ErrorHandler", @__cellfunerror);
+%! B = isfield (A(1), "message") && isfield (A(1), "index");
+%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
+%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
+%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
+%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
+%! assert ([A(1).index, A(2).index], [1, 2]);
+
+%% Input arguments can be of type cell arrays of character or strings
+%!error %% "UniformOutput" false should be used
+%! A = cellfun (@(x,y) x>y, {"ad", "c", "ghi"}, {"cc", "d", "fgh"});
+%!test
+%! A = cellfun (@(x,y) x>y, {"a"; "f"}, {"c"; "d"}, "UniformOutput", true);
+%! assert (A, [false; true]);
+%!test
+%! A = cellfun (@(x,y) x:y, {"a", "d"}, {"c", "f"}, "UniformOutput", false);
+%! assert (A, {"abc", "def"});
+%!test
+%! A = cellfun (@(x,y) cell2str (x,y), {"a", "d"}, {"c", "f"}, \
+%!              "ErrorHandler", @__cellfunerror);
+%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
+%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
+%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
+%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
+%! assert ([A(1).index, A(2).index], [1, 2]);
+%!test %% Overwriting setting of "UniformOutput" true
+%! A = cellfun (@(x,y) cell2str (x,y), {"a", "d"}, {"c", "f"}, \
+%!              "UniformOutput", true, "ErrorHandler", @__cellfunerror);
+%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
+%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
+%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
+%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
+%! assert ([A(1).index, A(2).index], [1, 2]);
+
+%% Structures cannot be handled by cellfun
+%!error
+%! vst1.a = 1.1;  vst1.b = 4.2;  vst2.a = 3.1;  vst2.b = 2;
+%! A = cellfun (@(x,y) (x.a < y.a) && (x.b > y.b), vst1, vst2);
+
+%% Input arguments can be of type cell array of cell arrays
+%!test
+%! A = cellfun (@(x,y) x{1} < y{1}, {{1.1}, {4.2}}, {{3.1}, {2}});
+%! assert (A, [1, 0], 1e-16);
+%!test
+%! A = cellfun (@(x,y) x{1} < y{1}, {{1.1}; {4.2}}, {{3.1}; {2}}, \
+%!              "UniformOutput", true);
+%! assert (A, [1; 0], 1e-16);
+%!test
+%! A = cellfun (@(x,y) x{1} < y{1}, {{1.1}, {4.2}}, {{3.1}, {2}}, \
+%!              "UniformOutput", false);
+%! assert (A, {true, false});
+%!test
+%! A = cellfun (@(x,y) mat2str (x,y), {{1.1}, {4.2}}, {{3.1}, {2}}, \
+%!              "ErrorHandler", @__cellfunerror);
+%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
+%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
+%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
+%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
+%! assert ([A(1).index, A(2).index], [1, 2]);
+%!test %% Overwriting setting of "UniformOutput" true
+%! A = cellfun (@(x,y) mat2str (x,y), {{1.1}, {4.2}}, {{3.1}, {2}}, \
+%!              "UniformOutput", true, "ErrorHandler", @__cellfunerror);
+%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
+%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
+%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
+%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
+%! assert ([A(1).index, A(2).index], [1, 2]);
+
+%% Input arguments can be of type cell array of structure arrays
+%!test
+%! a = struct ("a", 1, "b", 2);  b = struct ("a", 1, "b", 3);
+%! A = cellfun (@(x,y) (x.a == y.a) && (x.b < y.b), {a}, {b});
+%! assert (A, true);
+%!test
+%! a = struct ("a", 1, "b", 2);  b = struct ("a", 1, "b", 3);
+%! A = cellfun (@(x,y) (x.a == y.a) && (x.b < y.b) , {a}, {b}, \
+%!              "UniformOutput", true);
+%! assert (A, true);
+%!test
+%! a = struct ("a", 1, "b", 2);  b = struct ("a", 1, "b", 3);
+%! A = cellfun (@(x,y) (x.a == y.a) && (x.b < y.b) , {a}, {b}, \
+%!              "UniformOutput", false);
+%! assert (A, {true});
+%!test
+%! a = struct ("a", 1, "b", 2);  b = struct ("a", 1, "b", 3);
+%! A = cellfun (@(x,y) cell2str (x.a, y.a), {a}, {b}, \
+%!              "ErrorHandler", @__cellfunerror);
+%! assert (isfield (A, "identifier"), true);
+%! assert (isfield (A, "message"), true);
+%! assert (isfield (A, "index"), true);
+%! assert (isempty (A.message), false);
+%! assert (A.index, 1);
+%!test %% Overwriting setting of "UniformOutput" true
+%! a = struct ("a", 1, "b", 2);  b = struct ("a", 1, "b", 3);
+%! A = cellfun (@(x,y) cell2str (x.a, y.a), {a}, {b}, \
+%!              "UniformOutput", true, "ErrorHandler", @__cellfunerror);
+%! assert (isfield (A, "identifier"), true);
+%! assert (isfield (A, "message"), true);
+%! assert (isfield (A, "index"), true);
+%! assert (isempty (A.message), false);
+%! assert (A.index, 1);
+
+%% A lot of other tests
+%!assert (cellfun (@sin, {0,1}), sin ([0,1]))
+%!assert (cellfun (inline ("sin (x)"), {0,1}), sin ([0,1]))
+%!assert (cellfun ("sin", {0,1}), sin ([0,1]))
+%!assert (cellfun ("isempty", {1,[]}), [false,true])
+%!assert (cellfun ("islogical", {false,pi}), [true,false])
+%!assert (cellfun ("isreal", {1i,1}), [false,true])
+%!assert (cellfun ("length", {zeros(2,2),1}), [2,1])
+%!assert (cellfun ("prodofsize", {zeros(2,2),1}), [4,1])
+%!assert (cellfun ("ndims", {zeros([2,2,2]),1}), [3,2])
+%!assert (cellfun ("isclass", {zeros([2,2,2]),"test"}, "double"), [true,false])
+%!assert (cellfun ("size", {zeros([1,2,3]),1}, 1), [1,1])
+%!assert (cellfun ("size", {zeros([1,2,3]),1}, 2), [2,1])
+%!assert (cellfun ("size", {zeros([1,2,3]),1}, 3), [3,1])
+%!assert (cellfun (@atan2, {1,1}, {1,2}), [atan2(1,1), atan2(1,2)])
+%!assert (cellfun (@atan2, {1,1}, {1,2},"UniformOutput", false), {atan2(1,1), atan2(1,2)})
+%!assert (cellfun (@sin, {1,2;3,4}), sin ([1,2;3,4]))
+%!assert (cellfun (@atan2, {1,1;1,1}, {1,2;1,2}), atan2 ([1,1;1,1],[1,2;1,2]))
+%!error cellfun (@factorial, {-1,3})
+%!assert (cellfun (@factorial,{-1,3},"ErrorHandler",@(x,y) NaN), [NaN,6])
+%!test
+%! [a,b,c] = cellfun (@fileparts, {fullfile("a","b","c.d"), fullfile("e","f","g.h")}, "UniformOutput", false);
+%! assert (a, {fullfile("a","b"), fullfile("e","f")});
+%! assert (b, {"c", "g"});
+%! assert (c, {".d", ".h"});
+
+%!error cellfun (1)
+%!error cellfun ("isclass", 1)
+%!error cellfun ("size", 1)
+%!error cellfun (@sin, {[]}, "BadParam", false)
+%!error cellfun (@sin, {[]}, "UniformOuput")
+%!error cellfun (@sin, {[]}, "ErrorHandler")
+*/
+
+// Arrayfun was originally a .m file written by Bill Denney and Jaroslav
+// Hajek.  It was converted to C++ by jwe so that it could properly
+// handle the nargout = 0 case.
+
+DEFUN (arrayfun, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Function File} {} arrayfun (@var{func}, @var{A})\n\
+@deftypefnx {Function File} {@var{x} =} arrayfun (@var{func}, @var{A})\n\
+@deftypefnx {Function File} {@var{x} =} arrayfun (@var{func}, @var{A}, @var{b}, @dots{})\n\
+@deftypefnx {Function File} {[@var{x}, @var{y}, @dots{}] =} arrayfun (@var{func}, @var{A}, @dots{})\n\
+@deftypefnx {Function File} {} arrayfun (@dots{}, \"UniformOutput\", @var{val})\n\
+@deftypefnx {Function File} {} arrayfun (@dots{}, \"ErrorHandler\", @var{errfunc})\n\
+\n\
+Execute a function on each element of an array.  This is useful for\n\
+functions that do not accept array arguments.  If the function does\n\
+accept array arguments it is better to call the function directly.\n\
+\n\
+The first input argument @var{func} can be a string, a function\n\
+handle, an inline function, or an anonymous function.  The input\n\
+argument @var{A} can be a logic array, a numeric array, a string\n\
+array, a structure array, or a cell array.  By a call of the function\n\
+@command{arrayfun} all elements of @var{A} are passed on to the named\n\
+function @var{func} individually.\n\
+\n\
+The named function can also take more than two input arguments, with\n\
+the input arguments given as third input argument @var{b}, fourth\n\
+input argument @var{c}, @dots{}  If given more than one array input\n\
+argument then all input arguments must have the same sizes, for\n\
+example:\n\
+\n\
+@example\n\
+@group\n\
+arrayfun (@@atan2, [1, 0], [0, 1])\n\
+     @result{} [ 1.5708   0.0000 ]\n\
+@end group\n\
+@end example\n\
+\n\
+If the parameter @var{val} after a further string input argument\n\
+\"UniformOutput\" is set @code{true} (the default), then the named\n\
+function @var{func} must return a single element which then will be\n\
+concatenated into the return value and is of type matrix.  Otherwise,\n\
+if that parameter is set to @code{false}, then the outputs are\n\
+concatenated in a cell array.  For example:\n\
+\n\
+@example\n\
+@group\n\
+arrayfun (@@(x,y) x:y, \"abc\", \"def\", \"UniformOutput\", false)\n\
+@result{}\n\
+   @{\n\
+     [1,1] = abcd\n\
+     [1,2] = bcde\n\
+     [1,3] = cdef\n\
+   @}\n\
+@end group\n\
+@end example\n\
+\n\
+If more than one output arguments are given then the named function\n\
+must return the number of return values that also are expected, for\n\
+example:\n\
+\n\
+@example\n\
+@group\n\
+[A, B, C] = arrayfun (@@find, [10; 0], \"UniformOutput\", false)\n\
+@result{}\n\
+A =\n\
+@{\n\
+   [1,1] =  1\n\
+   [2,1] = [](0x0)\n\
+@}\n\
+B =\n\
+@{\n\
+   [1,1] =  1\n\
+   [2,1] = [](0x0)\n\
+@}\n\
+C =\n\
+@{\n\
+   [1,1] =  10\n\
+   [2,1] = [](0x0)\n\
+@}\n\
+@end group\n\
+@end example\n\
+\n\
+If the parameter @var{errfunc} after a further string input argument\n\
+\"ErrorHandler\" is another string, a function handle, an inline\n\
+function, or an anonymous function, then @var{errfunc} defines a\n\
+function to call in the case that @var{func} generates an error.\n\
+The definition of the function must be of the form\n\
+\n\
+@example\n\
+function [@dots{}] = errfunc (@var{s}, @dots{})\n\
+@end example\n\
+\n\
+@noindent\n\
+where there is an additional input argument to @var{errfunc}\n\
+relative to @var{func}, given by @var{s}.  This is a structure with\n\
+the elements \"identifier\", \"message\", and \"index\" giving,\n\
+respectively, the error identifier, the error message, and the index of\n\
+the array elements that caused the error.  The size of the output\n\
+argument of @var{errfunc} must have the same size as the output\n\
+argument of @var{func}, otherwise a real error is thrown.  For\n\
+example:\n\
+\n\
+@example\n\
+@group\n\
+function y = ferr (s, x), y = \"MyString\"; endfunction\n\
+arrayfun (@@str2num, [1234],\n\
+          \"UniformOutput\", false, \"ErrorHandler\", @@ferr)\n\
+@result{}\n\
+   @{\n\
+     [1,1] = MyString\n\
+   @}\n\
+@end group\n\
+@end example\n\
+\n\
+@seealso{spfun, cellfun, structfun}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+  int nargin = args.length ();
+  int nargout1 = (nargout < 1 ? 1 : nargout);
+
+  if (nargin < 2)
+    {
+      error ("arrayfun: function requires at least 2 arguments");
+      print_usage ();
+      return retval;
+    }
+
+  octave_value func = args(0);
+  bool symbol_table_lookup = false;
+
+  if (func.is_string ())
+    {
+      // See if we can convert the string into a function.
+
+      std::string name = args(0).string_value ();
+
+      if (! valid_identifier (name))
+        {
+          std::string fcn_name = unique_symbol_name ("__arrayfun_fcn_");
+          std::string fname = "function y = " + fcn_name + "(x) y = ";
+
+          octave_function *ptr_func
+            = extract_function (args(0), "arrayfun", fcn_name,
+                                fname, "; endfunction");
+
+          if (ptr_func && ! error_state)
+            func = octave_value (ptr_func, true);
+        }
+      else
+        {
+          func = symbol_table::find_function (name);
+
+          if (func.is_undefined ())
+            error ("arrayfun: invalid function NAME: %s", name.c_str ());
+
+          symbol_table_lookup = true;
+        }
+
+      if (error_state)
+        return retval;
+    }
+
+  if (func.is_function_handle () || func.is_inline_function ()
+      || func.is_function ())
+    {
+      // The following is an optimisation because the symbol table can
+      // give a more specific function class, so this can result in
+      // fewer polymorphic function calls as the function gets called
+      // for each value of the array.
+
+      if (! symbol_table_lookup )
+        {
+          if (func.is_function_handle ())
+            {
+              octave_fcn_handle* f = func.fcn_handle_value ();
+
+              // Overloaded function handles need to check the type of
+              // the arguments for each element of the array, so they
+              // cannot be optimised this way.
+
+              if (f -> is_overloaded ())
+                goto nevermind;
+            }
+          octave_value f = symbol_table::find_function (func.function_value ()
+                                                         -> name ());
+          if (f.is_defined ())
+            func = f;
+        }
+
+    nevermind:
+
+      bool uniform_output = true;
+      octave_value error_handler;
+      
+      get_mapper_fun_options (args, nargin, uniform_output, error_handler);
+
+      if (error_state)
+        return octave_value_list ();
+
+      octave_value_list inputlist (nargin, octave_value ());
+
+      OCTAVE_LOCAL_BUFFER (octave_value, inputs, nargin);
+      OCTAVE_LOCAL_BUFFER (bool, mask, nargin);
+
+      octave_idx_type k = 1;
+
+      dim_vector fdims (1, 1);
+
+      // Collect arguments.  Pre-fill scalar elements of inputlist
+      // array.
+
+      for (int j = 0; j < nargin; j++)
+        {
+          inputs[j] = args(j+1);
+          mask[j] = inputs[j].numel () != 1;
+
+          if (! mask[j])
+            inputlist(j) = inputs[j];
+        }
+
+      for (int j = 0; j < nargin; j++)
+        {
+          if (mask[j])
+            {
+              fdims = inputs[j].dims ();
+              k = inputs[j].numel ();
+
+              for (int i = j+1; i < nargin; i++)
+                {
+                  if (mask[i] && inputs[i].dims () != fdims)
+                    {
+                      error ("arrayfun: dimensions mismatch");
+                      return retval;
+                    }
+                }
+              break;
+            }
+        }
+
+
+      unwind_protect frame;
+      frame.protect_var (buffer_error_messages);
+
+      if (error_handler.is_defined ())
+        buffer_error_messages++;
+
+      // Apply functions.
+
+      if (uniform_output)
+        {
+          std::list<octave_value_list> idx_list (1);
+          idx_list.front ().resize (1);
+          std::string idx_type = "(";
+
+          OCTAVE_LOCAL_BUFFER (octave_value, retv, nargout1);
+
+          for (octave_idx_type count = 0; count < k; count++)
+            {
+              idx_list.front ()(0) = count + 1.0;
+
+              for (int j = 0; j < nargin; j++)
+                {
+                  if (mask[j])
+                    inputlist.xelem (j) = inputs[j].do_index_op (idx_list);
+
+                  if (error_state)
+                    return retval;
+                }
+
+              const octave_value_list tmp
+                = get_output_list (count, nargout, inputlist, func,
+                                   error_handler);
+
+              if (error_state)
+                return retval;
+
+              if (nargout > 0 && tmp.length () < nargout)
+                {
+                  error ("arrayfun: function returned fewer than nargout values");
+                  return retval;
+                }
+
+              if  (nargout > 0
+                   || (nargout == 0
+                       && tmp.length () > 0 && tmp(0).is_defined ()))
+                {
+                  int num_to_copy = tmp.length ();
+
+                  if (num_to_copy > nargout1)
+                    num_to_copy = nargout1;
+
+                  if (count == 0)
+                    {
+                      for (int j = 0; j < num_to_copy; j++)
+                        {
+                          if (tmp(j).is_defined ())
+                            {
+                              octave_value val = tmp(j);
+
+                              if (val.numel () == 1)
+                                retv[j] = val.resize (fdims);
+                              else
+                                {
+                                  error ("arrayfun: all values must be scalars when UniformOutput = true");
+                                  break;
+                                }
+                            }
+                        }
+                    }
+                  else
+                    {
+                      for (int j = 0; j < num_to_copy; j++)
+                        {
+                          if (tmp(j).is_defined ())
+                            {
+                              octave_value val = tmp(j);
+
+                              if (! retv[j].fast_elem_insert (count, val))
+                                {
+                                  if (val.numel () == 1)
+                                    {
+                                      idx_list.front ()(0) = count + 1.0;
+                                      retv[j].assign (octave_value::op_asn_eq,
+                                                      idx_type, idx_list, val);
+
+                                      if (error_state)
+                                        break;
+                                    }
+                                  else
+                                    {
+                                      error ("arrayfun: all values must be scalars when UniformOutput = true");
+                                      break;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+
+              if (error_state)
+                break;
+            }
+
+          retval.resize (nargout1);
+
+          for (int j = 0; j < nargout1; j++)
+            {
+              if (nargout > 0 && retv[j].is_undefined ())
+                retval(j) = NDArray (fdims);
+              else
+                retval(j) = retv[j];
+            }
+        }
+      else
+        {
+          std::list<octave_value_list> idx_list (1);
+          idx_list.front ().resize (1);
+          std::string idx_type = "(";
+
+          OCTAVE_LOCAL_BUFFER (Cell, results, nargout1);
+
+          for (int j = 0; j < nargout1; j++)
+            results[j].resize (fdims, Matrix ());
+
+          bool have_some_output = false;
+
+          for (octave_idx_type count = 0; count < k; count++)
+            {
+              idx_list.front ()(0) = count + 1.0;
+
+              for (int j = 0; j < nargin; j++)
+                {
+                  if (mask[j])
+                    inputlist.xelem (j) = inputs[j].do_index_op (idx_list);
+
+                  if (error_state)
+                    return retval;
+                }
+
+              const octave_value_list tmp
+                = get_output_list (count, nargout, inputlist, func,
+                                   error_handler);
+
+              if (error_state)
+                return retval;
+
+              if (nargout > 0 && tmp.length () < nargout)
+                {
+                  error ("arrayfun: function returned fewer than nargout values");
+                  return retval;
+                }
+
+              if  (nargout > 0
+                   || (nargout == 0
+                       && tmp.length () > 0 && tmp(0).is_defined ()))
+                {
+                  int num_to_copy = tmp.length ();
+
+                  if (num_to_copy > nargout1)
+                    num_to_copy = nargout1;
+
+                  if (num_to_copy > 0)
+                    have_some_output = true;
+
+                  for (int j = 0; j < num_to_copy; j++)
+                    results[j](count) = tmp(j);
+                }
+            }
+
+          if (have_some_output || fdims.any_zero ())
+            {
+              retval.resize (nargout1);
+
+              for (int j = 0; j < nargout1; j++)
+                retval(j) = results[j];
+            }
+        }
+    }
+  else
+    error ("arrayfun: argument NAME must be a string or function handle");
+
+  return retval;
+}
+
+/*
+%!function r = __f11 (x)
+%!  global __arrayfun_test_num_outputs__;
+%!  __arrayfun_test_num_outputs__ = nargout;
+%!  r = x;
+%!endfunction
+
+%!function __f01 (x)
+%!  global __arrayfun_test_num_outputs__;
+%!  __arrayfun_test_num_outputs__ = nargout;
+%!endfunction
+
+%!test
+%! global __arrayfun_test_num_outputs__;
+%! arrayfun (@__f11, {1});
+%! assert (__arrayfun_test_num_outputs__, 0);
+%! x = arrayfun (@__f11, {1});
+%! assert (__arrayfun_test_num_outputs__, 1);
+
+%!test
+%! global __arrayfun_test_num_outputs__;
+%! arrayfun (@__f01, {1});
+%! assert (__arrayfun_test_num_outputs__, 0);
+
+%!error x = arrayfun (@__f01, [1, 2]);
+
+%!test
+%! assert (arrayfun (@__f11, [1, 2]), [1, 2]);
+%! assert (arrayfun (@__f11, [1, 2], "uniformoutput", false), {1, 2});
+%! assert (arrayfun (@__f11, {1, 2}), {1, 2});
+%! assert (arrayfun (@__f11, {1, 2}, "uniformoutput", false), {{1}, {2}});
+
+%!assert (arrayfun (@ones, 1, [2,3], "uniformoutput", false), {[1,1], [1,1,1]})
+
+%% Test function to check the "Errorhandler" option
+%!function z = __arrayfunerror (S, varargin)
+%!  z = S;
+%!endfunction
+%% First input argument can be a string, an inline function, a
+%% function_handle or an anonymous function
+%!test
+%! arrayfun (@isequal, [false, true], [true, true]); %% No output argument
+%!error
+%! arrayfun (@isequal); %% One or less input arguments
+%!test
+%! A = arrayfun ("isequal", [false, true], [true, true]);
+%! assert (A, [false, true]);
+%!test
+%! A = arrayfun (inline ("(x == y)", "x", "y"), [false, true], [true, true]);
+%! assert (A, [false, true]);
+%!test
+%! A = arrayfun (@isequal, [false, true], [true, true]);
+%! assert (A, [false, true]);
+%!test
+%! A = arrayfun (@(x,y) isequal (x,y), [false, true], [true, true]);
+%! assert (A, [false, true]);
+
+%% Number of input and output arguments may be greater than one
+%#!test
+%! A = arrayfun (@(x) islogical (x), false);
+%! assert (A, true);
+%!test
+%! A = arrayfun (@(x,y,z) x + y + z, [1, 1, 1], [2, 2, 2], [3, 4, 5]);
+%! assert (A, [6, 7, 8], 1e-16);
+%!test %% Two input arguments of different types
+%! A = arrayfun (@(x,y) islogical (x) && ischar (y), false, "a");
+%! assert (A, true);
+%!test %% Pass another variable to the anonymous function
+%! y = true;
+%! A = arrayfun (@(x) islogical (x && y), false);
+%! assert (A, true);
+%!test %% Three ouptut arguments of different type
+%! [A, B, C] = arrayfun (@find, [10, 11; 0, 12], "UniformOutput", false);
+%! assert (isequal (A, {true, true; [], true}));
+%! assert (isequal (B, {true, true; [], true}));
+%! assert (isequal (C, {10, 11; [], 12}));
+
+%% Input arguments can be of type logical
+%!test
+%! A = arrayfun (@(x,y) x == y, [false, true], [true, true]);
+%! assert (A, [false, true]);
+%!test
+%! A = arrayfun (@(x,y) x == y, [false; true], [true; true], "UniformOutput", true);
+%! assert (A, [false; true]);
+%!test
+%! A = arrayfun (@(x) x, [false, true, false, true], "UniformOutput", false);
+%! assert (A, {false, true, false, true});
+%!test %% Three ouptut arguments of same type
+%! [A, B, C] = arrayfun (@find, [true, false; false, true], "UniformOutput", false);
+%! assert (isequal (A, {true, []; [], true}));
+%! assert (isequal (B, {true, []; [], true}));
+%! assert (isequal (C, {true, []; [], true}));
+%!test
+%! A = arrayfun (@(x,y) array2str (x,y), true, true, \
+%!               "ErrorHandler", @__arrayfunerror);
+%! assert (isfield (A, "identifier"), true);
+%! assert (isfield (A, "message"), true);
+%! assert (isfield (A, "index"), true);
+%! assert (isempty (A.message), false);
+%! assert (A.index, 1);
+%!test %% Overwriting setting of "UniformOutput" true
+%! A = arrayfun (@(x,y) array2str (x,y), true, true, "UniformOutput", true, \
+%!               "ErrorHandler", @__arrayfunerror);
+%! assert (isfield (A, "identifier"), true);
+%! assert (isfield (A, "message"), true);
+%! assert (isfield (A, "index"), true);
+%! assert (isempty (A.message), false);
+%! assert (A.index, 1);
+
+%% Input arguments can be of type numeric
+%!test
+%! A = arrayfun (@(x,y) x>y, [1.1, 4.2], [3.1, 2+3*i]);
+%! assert (A, [false, true]);
+%!test
+%! A = arrayfun (@(x,y) x>y, [1.1, 4.2; 2, 4], [3.1, 2; 2, 4+2*i], "UniformOutput", true);
+%! assert (A, [false, true; false, false]);
+%!test
+%! A = arrayfun (@(x,y) x:y, [1.1, 4], [3.1, 6], "UniformOutput", false);
+%! assert (isequal (A{1}, [1.1, 2.1, 3.1]));
+%! assert (isequal (A{2}, [4, 5, 6]));
+%!test %% Three ouptut arguments of different type
+%! [A, B, C] = arrayfun (@find, [10, 11; 0, 12], "UniformOutput", false);
+%! assert (isequal (A, {true, true; [], true}));
+%! assert (isequal (B, {true, true; [], true}));
+%! assert (isequal (C, {10, 11; [], 12}));
+%!test
+%! A = arrayfun (@(x,y) array2str (x,y), {1.1, 4}, {3.1, 6}, \
+%!               "ErrorHandler", @__arrayfunerror);
+%! B = isfield (A(1), "message") && isfield (A(1), "index");
+%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
+%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
+%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
+%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
+%! assert ([A(1).index, A(2).index], [1, 2]);
+%!test %% Overwriting setting of "UniformOutput" true
+%! A = arrayfun (@(x,y) array2str (x,y), {1.1, 4}, {3.1, 6}, \
+%!               "UniformOutput", true, "ErrorHandler", @__arrayfunerror);
+%! B = isfield (A(1), "message") && isfield (A(1), "index");
+%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
+%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
+%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
+%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
+%! assert ([A(1).index, A(2).index], [1, 2]);
+
+%% Input arguments can be of type character or strings
+%!test
+%! A = arrayfun (@(x,y) x>y, ["ad", "c", "ghi"], ["cc", "d", "fgh"]);
+%! assert (A, [false, true, false, true, true, true]);
+%!test
+%! A = arrayfun (@(x,y) x>y, ["a"; "f"], ["c"; "d"], "UniformOutput", true);
+%! assert (A, [false; true]);
+%!test
+%! A = arrayfun (@(x,y) x:y, ["a", "d"], ["c", "f"], "UniformOutput", false);
+%! assert (A, {"abc", "def"});
+%!test
+%! A = arrayfun (@(x,y) cell2str (x,y), ["a", "d"], ["c", "f"], \
+%!               "ErrorHandler", @__arrayfunerror);
+%! B = isfield (A(1), "identifier") && isfield (A(1), "message") && isfield (A(1), "index");
+%! assert (B, true);
+
+%% Input arguments can be of type structure
+%!test
+%! a = struct ("a", 1.1, "b", 4.2);  b = struct ("a", 3.1, "b", 2);
+%! A = arrayfun (@(x,y) (x.a < y.a) && (x.b > y.b), a, b);
+%! assert (A, true);
+%!test
+%! a = struct ("a", 1.1, "b", 4.2);  b = struct ("a", 3.1, "b", 2);
+%! A = arrayfun (@(x,y) (x.a < y.a) && (x.b > y.b), a, b, "UniformOutput", true);
+%! assert (A, true);
+%!test
+%! a = struct ("a", 1.1, "b", 4.2);  b = struct ("a", 3.1, "b", 2);
+%! A = arrayfun (@(x,y) x.a:y.a, a, b, "UniformOutput", false);
+%! assert (isequal (A, {[1.1, 2.1, 3.1]}));
+%!test
+%! A = arrayfun (@(x) mat2str(x), "a", "ErrorHandler", @__arrayfunerror);
+%! assert (isfield (A, "identifier"), true);
+%! assert (isfield (A, "message"), true);
+%! assert (isfield (A, "index"), true);
+%! assert (isempty (A.message), false);
+%! assert (A.index, 1);
+%!test %% Overwriting setting of "UniformOutput" true
+%! A = arrayfun (@(x) mat2str(x), "a", "UniformOutput", true, \
+%!               "ErrorHandler", @__arrayfunerror);
+%! assert (isfield (A, "identifier"), true);
+%! assert (isfield (A, "message"), true);
+%! assert (isfield (A, "index"), true);
+%! assert (isempty (A.message), false);
+%! assert (A.index, 1);
+
+%% Input arguments can be of type cell array
+%!test
+%! A = arrayfun (@(x,y) x{1} < y{1}, {1.1, 4.2}, {3.1, 2});
+%! assert (A, [true, false]);
+%!test
+%! A = arrayfun (@(x,y) x{1} < y{1}, {1.1; 4.2}, {3.1; 2}, "UniformOutput", true);
+%! assert (A, [true; false]);
+%!test
+%! A = arrayfun (@(x,y) x{1} < y{1}, {1.1, 4.2}, {3.1, 2}, "UniformOutput", false);
+%! assert (A, {true, false});
+%!test
+%! A = arrayfun (@(x,y) num2str(x,y), {1.1, 4.2}, {3.1, 2}, "ErrorHandler", @__arrayfunerror);
+%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
+%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
+%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
+%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
+%! assert ([A(1).index, A(2).index], [1, 2]);
+%!test
+%! A = arrayfun (@(x,y) num2str (x,y), {1.1, 4.2}, {3.1, 2}, \
+%!               "UniformOutput", true, "ErrorHandler", @__arrayfunerror);
+%! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
+%! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
+%! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
+%! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
+%! assert ([A(1).index, A(2).index], [1, 2]);
+*/
+
+static void
+do_num2cell_helper (const dim_vector& dv,
+                    const Array<int>& dimv,
+                    dim_vector& celldv, dim_vector& arraydv,
+                    Array<int>& perm)
+{
+  int dvl = dimv.length ();
+  int maxd = dv.length ();
+  celldv = dv;
+  for (int i = 0; i < dvl; i++)
+    maxd = std::max (maxd, dimv(i));
+  if (maxd > dv.length ())
+    celldv.resize (maxd, 1);
+  arraydv = celldv;
+
+  OCTAVE_LOCAL_BUFFER_INIT (bool, sing, maxd, false);
+
+  perm.clear (maxd, 1);
+  for (int i = 0; i < dvl; i++)
+    {
+      int k = dimv(i) - 1;
+      if (k < 0)
+        {
+          error ("num2cell: dimension indices must be positive");
+          return;
+        }
+      else if (i > 0 && k < dimv(i-1) - 1)
+        {
+          error ("num2cell: dimension indices must be strictly increasing");
+          return;
+        }
+
+      sing[k] = true;
+      perm(i) = k;
+    }
+
+  for (int k = 0, i = dvl; k < maxd; k++)
+    if (! sing[k])
+      perm(i++) = k;
+
+  for (int i = 0; i < maxd; i++)
+    if (sing[i])
+      celldv(i) = 1;
+    else
+      arraydv(i) = 1;
+}
+
+template<class NDA>
+static inline typename NDA::element_type
+do_num2cell_elem (const NDA& array, octave_idx_type i)
+{ return array(i); }
+
+static inline Cell
+do_num2cell_elem (const Cell& array, octave_idx_type i)
+{ return Cell (array(i)); }
+
+
+template<class NDA>
+static Cell
+do_num2cell (const NDA& array, const Array<int>& dimv)
+{
+  if (dimv.is_empty ())
+    {
+      Cell retval (array.dims ());
+      octave_idx_type nel = array.numel ();
+      for (octave_idx_type i = 0; i < nel; i++)
+        retval.xelem (i) = do_num2cell_elem (array, i);
+
+      return retval;
+    }
+  else
+    {
+      dim_vector celldv, arraydv;
+      Array<int> perm;
+      do_num2cell_helper (array.dims (), dimv, celldv, arraydv, perm);
+      if (error_state)
+        return Cell ();
+
+      NDA parray = array.permute (perm);
+
+      octave_idx_type nela = arraydv.numel (), nelc = celldv.numel ();
+      parray = parray.reshape (dim_vector (nela, nelc));
+
+      Cell retval (celldv);
+      for (octave_idx_type i = 0; i < nelc; i++)
+        {
+          retval.xelem (i) = NDA (parray.column (i).reshape (arraydv));
+        }
+
+      return retval;
+    }
+}
+
+// FIXME -- this is a mess, but if a size method for the object exists,
+// we have to call it to get the size of the object instead of using the
+// internal dims method.
+
+static dim_vector
+get_object_dims (octave_value& obj)
+{
+  dim_vector retval;
+
+  Matrix m = obj.size ();
+
+  int n = m.numel ();
+
+  retval.resize (n);
+
+  for (int i = 0; i < n; i++)
+    retval(i) = m(i);
+
+  return retval;
+}
+
+static Cell
+do_object2cell (const octave_value& obj, const Array<int>& dimv)
+{
+  Cell retval;
+
+  // FIXME -- this copy is only needed because the octave_value::size
+  // method is not const.
+  octave_value array = obj;
+
+  if (dimv.is_empty ())
+    {
+      dim_vector dv = get_object_dims (array);
+
+      if (! error_state)
+        {
+          retval.resize (dv);
+
+          octave_value_list idx (1);
+
+          for (octave_idx_type i = 0; i < dv.numel (); i++)
+            {
+              octave_quit ();
+
+              idx(0) = double (i+1);
+
+              retval.xelem (i) = array.single_subsref ("(", idx);
+
+              if (error_state)
+                break;
+            }
+        }
+    }
+  else
+    {
+      error ("num2cell (A, dim) not implemented for class objects");
+    }
+
+  return retval;
+}
+
+DEFUN (num2cell, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{C} =} num2cell (@var{A})\n\
+@deftypefnx {Built-in Function} {@var{C} =} num2cell (@var{A}, @var{dim})\n\
+Convert the numeric matrix @var{A} to a cell array.  If @var{dim} is\n\
+defined, the value @var{C} is of dimension 1 in this dimension and the\n\
+elements of @var{A} are placed into @var{C} in slices.  For example:\n\
+\n\
+@example\n\
+@group\n\
+num2cell ([1,2;3,4])\n\
+   @result{}\n\
+      @{\n\
+        [1,1] =  1\n\
+        [2,1] =  3\n\
+        [1,2] =  2\n\
+        [2,2] =  4\n\
+      @}\n\
+num2cell ([1,2;3,4],1)\n\
+   @result{}\n\
+      @{\n\
+        [1,1] =\n\
+           1\n\
+           3\n\
+        [1,2] =\n\
+           2\n\
+           4\n\
+      @}\n\
+@end group\n\
+@end example\n\
+\n\
+@seealso{mat2cell}\n\
+@end deftypefn")
+{
+  int nargin =  args.length ();
+  octave_value retval;
+
+  if (nargin < 1 || nargin > 2)
+    print_usage ();
+  else
+    {
+      octave_value array = args(0);
+      Array<int> dimv;
+      if (nargin > 1)
+        dimv = args (1).int_vector_value (true);
+
+      if (error_state)
+        ;
+      else if (array.is_bool_type ())
+        retval = do_num2cell (array.bool_array_value (), dimv);
+      else if (array.is_char_matrix ())
+        retval = do_num2cell (array.char_array_value (), dimv);
+      else if (array.is_numeric_type ())
+        {
+          if (array.is_integer_type ())
+            {
+              if (array.is_int8_type ())
+                retval = do_num2cell (array.int8_array_value (), dimv);
+              else if (array.is_int16_type ())
+                retval = do_num2cell (array.int16_array_value (), dimv);
+              else if (array.is_int32_type ())
+                retval = do_num2cell (array.int32_array_value (), dimv);
+              else if (array.is_int64_type ())
+                retval = do_num2cell (array.int64_array_value (), dimv);
+              else if (array.is_uint8_type ())
+                retval = do_num2cell (array.uint8_array_value (), dimv);
+              else if (array.is_uint16_type ())
+                retval = do_num2cell (array.uint16_array_value (), dimv);
+              else if (array.is_uint32_type ())
+                retval = do_num2cell (array.uint32_array_value (), dimv);
+              else if (array.is_uint64_type ())
+                retval = do_num2cell (array.uint64_array_value (), dimv);
+            }
+          else if (array.is_complex_type ())
+            {
+              if (array.is_single_type ())
+                retval = do_num2cell (array.float_complex_array_value (), dimv);
+              else
+                retval = do_num2cell (array.complex_array_value (), dimv);
+            }
+          else
+            {
+              if (array.is_single_type ())
+                retval = do_num2cell (array.float_array_value (), dimv);
+              else
+                retval = do_num2cell (array.array_value (), dimv);
+            }
+        }
+      else if (array.is_object ())
+        retval = do_object2cell (array, dimv);
+      else if (array.is_map ())
+        retval = do_num2cell (array.map_value (), dimv);
+      else if (array.is_cell ())
+        retval = do_num2cell (array.cell_value (), dimv);
+      else if (array.is_object ())
+        retval = do_num2cell (array.cell_value (), dimv);
+      else
+        gripe_wrong_type_arg ("num2cell", array);
+    }
+
+  return retval;
+}
+
+/*
+%!assert (num2cell ([1,2;3,4]), {1,2;3,4})
+%!assert (num2cell ([1,2;3,4], 1), {[1;3],[2;4]})
+%!assert (num2cell ([1,2;3,4], 2), {[1,2];[3,4]})
+*/
+
+static bool
+mat2cell_mismatch (const dim_vector& dv,
+                   const Array<octave_idx_type> *d, int nd)
+{
+  for (int i = 0; i < nd; i++)
+    {
+      octave_idx_type s = 0;
+      for (octave_idx_type j = 0; j < d[i].length (); j++)
+        s += d[i](j);
+
+      octave_idx_type r = i < dv.length () ? dv(i) : 1;
+
+      if (s != r)
+        {
+          error ("mat2cell: mismatch on %d-th dimension (%d != %d)",
+                 i+1, r, s);
+          return true;
+        }
+    }
+
+  return false;
+}
+
+template<class container>
+static void
+prepare_idx (container *idx, int idim, int nd,
+             const Array<octave_idx_type>* d)
+{
+  octave_idx_type nidx = idim < nd ? d[idim].numel () : 1;
+  if (nidx == 1)
+    idx[0] = idx_vector::colon;
+  else
+    {
+      octave_idx_type l = 0;
+      for (octave_idx_type i = 0; i < nidx; i++)
+        {
+          octave_idx_type u = l + d[idim](i);
+          idx[i] = idx_vector (l, u);
+          l = u;
+        }
+    }
+}
+
+// 2D specialization, works for Array, Sparse and octave_map.
+// Uses 1D or 2D indexing.
+
+template <class Array2D>
+static Cell
+do_mat2cell_2d (const Array2D& a, const Array<octave_idx_type> *d, int nd)
+{
+  NoAlias<Cell> retval;
+  assert (nd == 1 || nd == 2);
+  assert (a.ndims () == 2);
+
+  if (mat2cell_mismatch (a.dims (), d, nd))
+    return retval;
+
+  octave_idx_type nridx = d[0].length ();
+  octave_idx_type ncidx = nd == 1 ? 1 : d[1].length ();
+  retval.clear (nridx, ncidx);
+
+  int ivec = -1;
+  if (a.rows () > 1 && a.cols () == 1 && ncidx == 1)
+    ivec = 0;
+  else if (a.rows () == 1 && nridx == 1 && nd == 2)
+    ivec = 1;
+
+  if (ivec >= 0)
+    {
+      // Vector split. Use 1D indexing.
+      octave_idx_type l = 0, nidx = (ivec == 0 ? nridx : ncidx);
+      for (octave_idx_type i = 0; i < nidx; i++)
+        {
+          octave_idx_type u = l + d[ivec](i);
+          retval(i) = a.index (idx_vector (l, u));
+          l = u;
+        }
+    }
+  else
+    {
+      // General 2D case. Use 2D indexing.
+      OCTAVE_LOCAL_BUFFER (idx_vector, ridx, nridx);
+      prepare_idx (ridx, 0, nd, d);
+
+      OCTAVE_LOCAL_BUFFER (idx_vector, cidx, ncidx);
+      prepare_idx (cidx, 1, nd, d);
+
+      for (octave_idx_type j = 0; j < ncidx; j++)
+        for (octave_idx_type i = 0; i < nridx; i++)
+          {
+            octave_quit ();
+
+            retval(i,j) = a.index (ridx[i], cidx[j]);
+          }
+    }
+
+  return retval;
+}
+
+// Nd case. Works for Arrays and octave_map.
+// Uses Nd indexing.
+
+template <class ArrayND>
+Cell
+do_mat2cell_nd (const ArrayND& a, const Array<octave_idx_type> *d, int nd)
+{
+  NoAlias<Cell> retval;
+  assert (nd >= 1);
+
+  if (mat2cell_mismatch (a.dims (), d, nd))
+    return retval;
+
+  dim_vector rdv = dim_vector::alloc (nd);
+  OCTAVE_LOCAL_BUFFER (octave_idx_type, nidx, nd);
+  octave_idx_type idxtot = 0;
+  for (int i = 0; i < nd; i++)
+    {
+      rdv(i) = nidx[i] = d[i].length ();
+      idxtot += nidx[i];
+    }
+
+  retval.clear (rdv);
+
+  OCTAVE_LOCAL_BUFFER (idx_vector, xidx, idxtot);
+  OCTAVE_LOCAL_BUFFER (idx_vector *, idx, nd);
+
+  idxtot = 0;
+  for (int i = 0; i < nd; i++)
+    {
+      idx[i] = xidx + idxtot;
+      prepare_idx (idx[i], i, nd, d);
+      idxtot += nidx[i];
+    }
+
+  OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, ridx, nd, 0);
+  NoAlias< Array<idx_vector> > ra_idx
+    (dim_vector (1, std::max (nd, a.ndims ())), idx_vector::colon);
+
+  for (octave_idx_type j = 0; j < retval.numel (); j++)
+    {
+      octave_quit ();
+
+      for (int i = 0; i < nd; i++)
+        ra_idx(i) = idx[i][ridx[i]];
+
+      retval(j) = a.index (ra_idx);
+
+      rdv.increment_index (ridx);
+    }
+
+  return retval;
+}
+
+// Dispatcher.
+template <class ArrayND>
+Cell
+do_mat2cell (const ArrayND& a, const Array<octave_idx_type> *d, int nd)
+{
+  if (a.ndims () == 2 && nd <= 2)
+    return do_mat2cell_2d (a, d, nd);
+  else
+    return do_mat2cell_nd (a, d, nd);
+}
+
+// General case. Works for any class supporting do_index_op.
+// Uses Nd indexing.
+
+Cell
+do_mat2cell (octave_value& a, const Array<octave_idx_type> *d, int nd)
+{
+  NoAlias<Cell> retval;
+  assert (nd >= 1);
+
+  if (mat2cell_mismatch (a.dims (), d, nd))
+    return retval;
+
+  dim_vector rdv = dim_vector::alloc (nd);
+  OCTAVE_LOCAL_BUFFER (octave_idx_type, nidx, nd);
+  octave_idx_type idxtot = 0;
+  for (int i = 0; i < nd; i++)
+    {
+      rdv(i) = nidx[i] = d[i].length ();
+      idxtot += nidx[i];
+    }
+
+  retval.clear (rdv);
+
+  OCTAVE_LOCAL_BUFFER (octave_value, xidx, idxtot);
+  OCTAVE_LOCAL_BUFFER (octave_value *, idx, nd);
+
+  idxtot = 0;
+  for (int i = 0; i < nd; i++)
+    {
+      idx[i] = xidx + idxtot;
+      prepare_idx (idx[i], i, nd, d);
+      idxtot += nidx[i];
+    }
+
+  OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, ridx, nd, 0);
+  octave_value_list ra_idx (std::max (nd, a.ndims ()),
+                            octave_value::magic_colon_t);
+
+  for (octave_idx_type j = 0; j < retval.numel (); j++)
+    {
+      octave_quit ();
+
+      for (int i = 0; i < nd; i++)
+        ra_idx(i) = idx[i][ridx[i]];
+
+      retval(j) = a.do_index_op (ra_idx);
+
+      if (error_state)
+        break;
+
+      rdv.increment_index (ridx);
+    }
+
+  return retval;
+}
+
+DEFUN (mat2cell, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{C} =} mat2cell (@var{A}, @var{m}, @var{n})\n\
+@deftypefnx {Built-in Function} {@var{C} =} mat2cell (@var{A}, @var{d1}, @var{d2}, @dots{})\n\
+@deftypefnx {Built-in Function} {@var{C} =} mat2cell (@var{A}, @var{r})\n\
+Convert the matrix @var{A} to a cell array.  If @var{A} is 2-D, then\n\
+it is required that @code{sum (@var{m}) == size (@var{A}, 1)} and\n\
+@code{sum (@var{n}) == size (@var{A}, 2)}.  Similarly, if @var{A} is\n\
+multi-dimensional and the number of dimensional arguments is equal\n\
+to the dimensions of @var{A}, then it is required that @code{sum (@var{di})\n\
+== size (@var{A}, i)}.\n\
+\n\
+Given a single dimensional argument @var{r}, the other dimensional\n\
+arguments are assumed to equal @code{size (@var{A},@var{i})}.\n\
+\n\
+An example of the use of mat2cell is\n\
+\n\
+@example\n\
+mat2cell (reshape (1:16,4,4), [3,1], [3,1])\n\
+@result{}\n\
+@{\n\
+   [1,1] =\n\
+\n\
+      1   5   9\n\
+      2   6  10\n\
+      3   7  11\n\
+\n\
+   [2,1] =\n\
+\n\
+      4   8  12\n\
+\n\
+   [1,2] =\n\
+\n\
+     13\n\
+     14\n\
+     15\n\
+\n\
+   [2,2] = 16\n\
+@}\n\
+@end example\n\
+@seealso{num2cell, cell2mat}\n\
+@end deftypefn")
+{
+  int nargin = args.length ();
+  octave_value retval;
+
+  if (nargin < 2)
+    print_usage ();
+  else
+    {
+      // Prepare indices.
+      OCTAVE_LOCAL_BUFFER (Array<octave_idx_type>, d, nargin-1);
+
+      for (int i = 1; i < nargin; i++)
+        {
+          d[i-1] = args(i).octave_idx_type_vector_value (true);
+          if (error_state)
+            return retval;
+        }
+
+      octave_value a = args(0);
+      bool sparse = a.is_sparse_type ();
+      if (sparse && nargin > 3)
+        {
+          error ("mat2cell: sparse arguments only support 2D indexing");
+          return retval;
+        }
+
+      switch (a.builtin_type ())
+        {
+        case btyp_double:
+          {
+            if (sparse)
+              retval = do_mat2cell_2d (a.sparse_matrix_value (), d, nargin-1);
+            else
+              retval = do_mat2cell (a.array_value (), d, nargin - 1);
+            break;
+          }
+        case btyp_complex:
+          {
+            if (sparse)
+              retval = do_mat2cell_2d (a.sparse_complex_matrix_value (), d, nargin-1);
+            else
+              retval = do_mat2cell (a.complex_array_value (), d, nargin - 1);
+            break;
+          }
+#define BTYP_BRANCH(X,Y) \
+        case btyp_ ## X: \
+            retval = do_mat2cell (a.Y ## _value (), d, nargin - 1); \
+          break
+
+        BTYP_BRANCH (float, float_array);
+        BTYP_BRANCH (float_complex, float_complex_array);
+        BTYP_BRANCH (bool, bool_array);
+        BTYP_BRANCH (char, char_array);
+
+        BTYP_BRANCH (int8,  int8_array);
+        BTYP_BRANCH (int16, int16_array);
+        BTYP_BRANCH (int32, int32_array);
+        BTYP_BRANCH (int64, int64_array);
+        BTYP_BRANCH (uint8,  uint8_array);
+        BTYP_BRANCH (uint16, uint16_array);
+        BTYP_BRANCH (uint32, uint32_array);
+        BTYP_BRANCH (uint64, uint64_array);
+
+        BTYP_BRANCH (cell, cell);
+        BTYP_BRANCH (struct, map);
+#undef BTYP_BRANCH
+
+        case btyp_func_handle:
+          gripe_wrong_type_arg ("mat2cell", a);
+          break;
+        default:
+          retval = do_mat2cell (a, d, nargin-1);
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!test
+%! x = reshape (1:20, 5, 4);
+%! c = mat2cell (x, [3,2], [3,1]);
+%! assert (c, {[1,6,11;2,7,12;3,8,13],[16;17;18];[4,9,14;5,10,15],[19;20]});
+
+%!test
+%! x = "abcdefghij";
+%! c = mat2cell (x, 1, [0,4,2,0,4,0]);
+%! empty1by0str = resize ("", 1, 0);
+%! assert (c, {empty1by0str,"abcd","ef",empty1by0str,"ghij",empty1by0str});
+*/
+
+// FIXME: it would be nice to allow ranges being handled without a conversion.
+template <class NDA>
+static Cell
+do_cellslices_nda (const NDA& array,
+                   const Array<octave_idx_type>& lb,
+                   const Array<octave_idx_type>& ub,
+                   int dim = -1)
+{
+  octave_idx_type n = lb.length ();
+  Cell retval (1, n);
+  if (array.is_vector () && (dim == -1
+                             || (dim == 0 && array.columns () == 1)
+                             || (dim == 1 && array.rows () == 1)))
+    {
+      for (octave_idx_type i = 0; i < n && ! error_state; i++)
+        retval(i) = array.index (idx_vector (lb(i) - 1, ub(i)));
+    }
+  else
+    {
+      const dim_vector dv = array.dims ();
+      int ndims = dv.length ();
+      if (dim < 0)
+        dim = dv.first_non_singleton ();
+      ndims = std::max (ndims, dim + 1);
+
+      Array<idx_vector> idx (dim_vector (ndims, 1), idx_vector::colon);
+
+      for (octave_idx_type i = 0; i < n && ! error_state; i++)
+        {
+          idx(dim) = idx_vector (lb(i) - 1, ub(i));
+          retval(i) = array.index (idx);
+        }
+    }
+
+  return retval;
+}
+
+DEFUN (cellslices, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{sl} =} cellslices (@var{x}, @var{lb}, @var{ub}, @var{dim})\n\
+Given an array @var{x}, this function produces a cell array of slices from\n\
+the array determined by the index vectors @var{lb}, @var{ub}, for lower and\n\
+upper bounds, respectively.  In other words, it is equivalent to the\n\
+following code:\n\
+\n\
+@example\n\
+@group\n\
+n = length (lb);\n\
+sl = cell (1, n);\n\
+for i = 1:length (lb)\n\
+  sl@{i@} = x(:,@dots{},lb(i):ub(i),@dots{},:);\n\
+endfor\n\
+@end group\n\
+@end example\n\
+\n\
+The position of the index is determined by @var{dim}.  If not specified,\n\
+slicing is done along the first non-singleton dimension.\n\
+@seealso{cell2mat, cellindexmat, cellfun}\n\
+@end deftypefn")
+{
+  octave_value retval;
+  int nargin = args.length ();
+  if (nargin == 3 || nargin == 4)
+    {
+      octave_value x = args(0);
+      Array<octave_idx_type> lb = args(1).octave_idx_type_vector_value ();
+      Array<octave_idx_type> ub = args(2).octave_idx_type_vector_value ();
+      int dim = -1;
+      if (nargin == 4)
+        {
+          dim = args(3).int_value () - 1;
+          if (dim < 0)
+            error ("cellslices: DIM must be a valid dimension");
+        }
+
+      if (! error_state)
+        {
+          if (lb.length () != ub.length ())
+            error ("cellslices: the lengths of LB and UB must match");
+          else
+            {
+              Cell retcell;
+              if (! x.is_sparse_type () && x.is_matrix_type ())
+                {
+                  // specialize for some dense arrays.
+                  if (x.is_bool_type ())
+                    retcell = do_cellslices_nda (x.bool_array_value (), lb, ub, dim);
+                  else if (x.is_char_matrix ())
+                    retcell = do_cellslices_nda (x.char_array_value (), lb, ub, dim);
+                  else if (x.is_integer_type ())
+                    {
+                      if (x.is_int8_type ())
+                        retcell = do_cellslices_nda (x.int8_array_value (), lb, ub, dim);
+                      else if (x.is_int16_type ())
+                        retcell = do_cellslices_nda (x.int16_array_value (), lb, ub, dim);
+                      else if (x.is_int32_type ())
+                        retcell = do_cellslices_nda (x.int32_array_value (), lb, ub, dim);
+                      else if (x.is_int64_type ())
+                        retcell = do_cellslices_nda (x.int64_array_value (), lb, ub, dim);
+                      else if (x.is_uint8_type ())
+                        retcell = do_cellslices_nda (x.uint8_array_value (), lb, ub, dim);
+                      else if (x.is_uint16_type ())
+                        retcell = do_cellslices_nda (x.uint16_array_value (), lb, ub, dim);
+                      else if (x.is_uint32_type ())
+                        retcell = do_cellslices_nda (x.uint32_array_value (), lb, ub, dim);
+                      else if (x.is_uint64_type ())
+                        retcell = do_cellslices_nda (x.uint64_array_value (), lb, ub, dim);
+                    }
+                  else if (x.is_complex_type ())
+                    {
+                      if (x.is_single_type ())
+                        retcell = do_cellslices_nda (x.float_complex_array_value (), lb, ub, dim);
+                      else
+                        retcell = do_cellslices_nda (x.complex_array_value (), lb, ub, dim);
+                    }
+                  else
+                    {
+                      if (x.is_single_type ())
+                        retcell = do_cellslices_nda (x.float_array_value (), lb, ub, dim);
+                      else
+                        retcell = do_cellslices_nda (x.array_value (), lb, ub, dim);
+                    }
+                }
+              else
+                {
+                  // generic code.
+                  octave_idx_type n = lb.length ();
+                  retcell = Cell (1, n);
+                  const dim_vector dv = x.dims ();
+                  int ndims = dv.length ();
+                  if (dim < 0)
+                    dim = dv.first_non_singleton ();
+                  ndims = std::max (ndims, dim + 1);
+                  octave_value_list idx (ndims, octave_value::magic_colon_t);
+                  for (octave_idx_type i = 0; i < n && ! error_state; i++)
+                    {
+                      idx(dim) = Range (lb(i), ub(i));
+                      retcell(i) = x.do_index_op (idx);
+                    }
+                }
+              if (! error_state)
+                retval = retcell;
+            }
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!test
+%! m = [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12];
+%! c = cellslices (m, [1, 2], [2, 3], 2);
+%! assert (c, {[1, 2; 5, 6; 9, 10], [2, 3; 6, 7; 10, 11]});
+*/
+
+DEFUN (cellindexmat, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{y} =} cellindexmat (@var{x}, @var{varargin})\n\
+Given a cell array of matrices @var{x}, this function computes\n\
+\n\
+@example\n\
+@group\n\
+Y = cell (size (X));\n\
+for i = 1:numel (X)\n\
+  Y@{i@} = X@{i@}(varargin@{:@});\n\
+endfor\n\
+@end group\n\
+@end example\n\
+@seealso{cellslices, cellfun}\n\
+@end deftypefn")
+{
+  octave_value retval;
+  if (args.length () >= 1)
+    {
+      if (args(0).is_cell ())
+        {
+          const Cell x = args(0).cell_value ();
+          NoAlias<Cell> y(x.dims ());
+          octave_idx_type nel = x.numel ();
+          octave_value_list idx = args.slice (1, args.length () - 1);
+
+          for (octave_idx_type i = 0; i < nel; i++)
+            {
+              octave_quit ();
+              octave_value tmp = x(i);
+              y(i) = tmp.do_index_op (idx);
+              if (error_state)
+                break;
+            }
+
+          retval = y;
+        }
+      else
+        error ("cellindexmat: X must be a cell");
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/colloc.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,139 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+
+#include "CollocWt.h"
+#include "lo-mappers.h"
+
+#include "defun.h"
+#include "error.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+DEFUN (colloc, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {[@var{r}, @var{amat}, @var{bmat}, @var{q}] =} colloc (@var{n}, \"left\", \"right\")\n\
+Compute derivative and integral weight matrices for orthogonal\n\
+collocation using the subroutines given in J. Villadsen and\n\
+M. L. Michelsen, @cite{Solution of Differential Equation Models by\n\
+Polynomial Approximation}.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 1 || nargin > 3)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  if (! args(0).is_scalar_type ())
+    {
+      error ("colloc: N must be a scalar");
+      return retval;
+    }
+
+  double tmp = args(0).double_value ();
+
+  if (error_state)
+    return retval;
+
+  if (xisnan (tmp))
+    {
+      error ("colloc: N cannot be NaN");
+      return retval;
+    }
+
+  octave_idx_type ncol = NINTbig (tmp);
+  if (ncol < 0)
+    {
+      error ("colloc: N must be positive");
+      return retval;
+    }
+
+  octave_idx_type ntot = ncol;
+  octave_idx_type left = 0;
+  octave_idx_type right = 0;
+
+  for (int i = 1; i < nargin; i++)
+    {
+      if (args(i).is_defined ())
+        {
+          if (! args(i).is_string ())
+            {
+              error ("colloc: expecting string argument \"left\" or \"right\"");
+              return retval;
+            }
+
+          std::string s = args(i).string_value ();
+
+          if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r'))
+              || s == "right")
+            {
+              right = 1;
+            }
+          else if ((s.length () == 1 && (s[0] == 'L' || s[0] == 'l'))
+                   || s == "left")
+            {
+              left = 1;
+            }
+          else
+            {
+              error ("colloc: unrecognized argument");
+              return retval;
+            }
+        }
+      else
+        {
+          error ("colloc: unexpected empty argument");
+          return retval;
+        }
+    }
+
+  ntot += left + right;
+  if (ntot < 1)
+    {
+      error ("colloc: the total number of roots must be positive");
+      return retval;
+    }
+
+  CollocWt wts (ncol, left, right);
+
+  ColumnVector r = wts.roots ();
+  Matrix A = wts.first ();
+  Matrix B = wts.second ();
+  ColumnVector q = wts.quad_weights ();
+
+  retval(3) = q;
+  retval(2) = B;
+  retval(1) = A;
+  retval(0) = r;
+
+  return retval;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/conv2.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,393 @@
+/*
+
+Copyright (C) 1999-2012 Andy Adler
+Copyright (C) 2010 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "oct-convn.h"
+
+#include "defun.h"
+#include "error.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+enum Shape { SHAPE_FULL, SHAPE_SAME, SHAPE_VALID };
+
+DEFUN (conv2, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} conv2 (@var{A}, @var{B})\n\
+@deftypefnx {Built-in Function} {} conv2 (@var{v1}, @var{v2}, @var{m})\n\
+@deftypefnx {Built-in Function} {} conv2 (@dots{}, @var{shape})\n\
+Return the 2-D convolution of @var{A} and @var{B}.  The size of the result\n\
+is determined by the optional @var{shape} argument which takes the following\n\
+values\n\
+\n\
+@table @asis\n\
+@item @var{shape} = \"full\"\n\
+Return the full convolution.  (default)\n\
+\n\
+@item @var{shape} = \"same\"\n\
+Return the central part of the convolution with the same size as @var{A}.\n\
+The central part of the convolution begins at the indices\n\
+@code{floor ([size(@var{B})/2] + 1)}.\n\
+\n\
+@item @var{shape} = \"valid\"\n\
+Return only the parts which do not include zero-padded edges.\n\
+The size of the result is @code{max (size (A) - size (B) + 1, 0)}.\n\
+@end table\n\
+\n\
+When the third argument is a matrix, return the convolution of the matrix\n\
+@var{m} by the vector @var{v1} in the column direction and by the vector\n\
+@var{v2} in the row direction.\n\
+@seealso{conv, convn}\n\
+@end deftypefn")
+{
+  octave_value retval;
+  octave_value tmp;
+  int nargin = args.length ();
+  std::string shape = "full";   // default
+  bool separable = false;
+  convn_type ct;
+
+  if (nargin < 2)
+    {
+     print_usage ();
+     return retval;
+    }
+  else if (nargin == 3)
+    {
+      if (args(2).is_string ())
+        shape = args(2).string_value ();
+      else
+        separable = true;
+    }
+  else if (nargin >= 4)
+    {
+      separable = true;
+      shape = args(3).string_value ();
+    }
+
+  if (shape == "full")
+    ct = convn_full;
+  else if (shape == "same")
+    ct = convn_same;
+  else if (shape == "valid")
+    ct = convn_valid;
+  else
+    {
+      error ("conv2: SHAPE type not valid");
+      print_usage ();
+      return retval;
+    }
+
+   if (separable)
+     {
+      // If user requests separable, check first two params are vectors
+
+       if (! (1 == args(0).rows () || 1 == args(0).columns ())
+           || ! (1 == args(1).rows () || 1 == args(1).columns ()))
+         {
+           print_usage ();
+           return retval;
+         }
+
+       if (args(0).is_single_type () || args(1).is_single_type ()
+           || args(2).is_single_type ())
+         {
+           if (args(0).is_complex_type () || args(1).is_complex_type ()
+               || args(2).is_complex_type ())
+             {
+               FloatComplexMatrix a (args(2).float_complex_matrix_value ());
+               if (args(1).is_real_type () && args(2).is_real_type ())
+                 {
+                   FloatColumnVector v1 (args(0).float_vector_value ());
+                   FloatRowVector v2 (args(1).float_vector_value ());
+                   retval = convn (a, v1, v2, ct);
+                 }
+               else
+                 {
+                   FloatComplexColumnVector v1 (args(0).float_complex_vector_value ());
+                   FloatComplexRowVector v2 (args(1).float_complex_vector_value ());
+                   retval = convn (a, v1, v2, ct);
+                 }
+             }
+           else
+             {
+               FloatColumnVector v1 (args(0).float_vector_value ());
+               FloatRowVector v2 (args(1).float_vector_value ());
+               FloatMatrix a (args(2).float_matrix_value ());
+               retval = convn (a, v1, v2, ct);
+             }
+         }
+       else
+         {
+           if (args(0).is_complex_type () || args(1).is_complex_type ()
+               || args(2).is_complex_type ())
+             {
+               ComplexMatrix a (args(2).complex_matrix_value ());
+               if (args(1).is_real_type () && args(2).is_real_type ())
+                 {
+                   ColumnVector v1 (args(0).vector_value ());
+                   RowVector v2 (args(1).vector_value ());
+                   retval = convn (a, v1, v2, ct);
+                 }
+               else
+                 {
+                   ComplexColumnVector v1 (args(0).complex_vector_value ());
+                   ComplexRowVector v2 (args(1).complex_vector_value ());
+                   retval = convn (a, v1, v2, ct);
+                 }
+             }
+           else
+             {
+               ColumnVector v1 (args(0).vector_value ());
+               RowVector v2 (args(1).vector_value ());
+               Matrix a (args(2).matrix_value ());
+               retval = convn (a, v1, v2, ct);
+             }
+         }
+     } // if (separable)
+   else
+     {
+       if (args(0).is_single_type () || args(1).is_single_type ())
+         {
+           if (args(0).is_complex_type () || args(1).is_complex_type ())
+             {
+               FloatComplexMatrix a (args(0).float_complex_matrix_value ());
+               if (args(1).is_real_type ())
+                 {
+                   FloatMatrix b (args(1).float_matrix_value ());
+                   retval = convn (a, b, ct);
+                 }
+               else
+                 {
+                   FloatComplexMatrix b (args(1).float_complex_matrix_value ());
+                   retval = convn (a, b, ct);
+                 }
+             }
+           else
+             {
+               FloatMatrix a (args(0).float_matrix_value ());
+               FloatMatrix b (args(1).float_matrix_value ());
+               retval = convn (a, b, ct);
+             }
+         }
+       else
+         {
+           if (args(0).is_complex_type () || args(1).is_complex_type ())
+             {
+               ComplexMatrix a (args(0).complex_matrix_value ());
+               if (args(1).is_real_type ())
+                 {
+                   Matrix b (args(1).matrix_value ());
+                   retval = convn (a, b, ct);
+                 }
+               else
+                 {
+                   ComplexMatrix b (args(1).complex_matrix_value ());
+                   retval = convn (a, b, ct);
+                 }
+             }
+           else
+             {
+               Matrix a (args(0).matrix_value ());
+               Matrix b (args(1).matrix_value ());
+               retval = convn (a, b, ct);
+             }
+         }
+
+     } // if (separable)
+
+   return retval;
+}
+
+/*
+%!test
+%! c = [0,1,2,3;1,8,12,12;4,20,24,21;7,22,25,18];
+%! assert (conv2 ([0,1;1,2], [1,2,3;4,5,6;7,8,9]), c);
+
+%!test
+%! c = single ([0,1,2,3;1,8,12,12;4,20,24,21;7,22,25,18]);
+%! assert (conv2 (single ([0,1;1,2]), single ([1,2,3;4,5,6;7,8,9])), c);
+
+%!test
+%! c = [1,4,4;5,18,16;14,48,40;19,62,48;15,48,36];
+%! assert (conv2 (1:3, 1:2, [1,2;3,4;5,6]), c);
+
+%!assert (conv2 (1:3, 1:2, [1,2;3,4;5,6], "full"),
+%!        conv2 (1:3, 1:2, [1,2;3,4;5,6]));
+
+%% Test shapes
+%!shared A, B, C
+%! A = rand (3, 4);
+%! B = rand (4);
+%! C = conv2 (A, B);
+%!assert (conv2 (A,B, "full"), C)
+%!assert (conv2 (A,B, "same"), C(3:5,3:6))
+%!assert (conv2 (A,B, "valid"), zeros (0, 1))
+%!assert (size (conv2 (B,A, "valid")), [2 1])
+
+%!test
+%! B = rand (5);
+%! C = conv2 (A, B);
+%!assert (conv2 (A,B, "full"), C)
+%!assert (conv2 (A,B, "same"), C(3:5,3:6))
+%!assert (conv2 (A,B, "valid"), zeros (0, 0))
+%!assert (size (conv2 (B,A, "valid")), [3 2])
+
+%% Clear shared variables so they are not reported for tests below
+%!shared
+
+%% Test cases from Bug #34893
+%!assert (conv2 ([1:5;1:5], [1:2], "same"), [4 7 10 13 10; 4 7 10 13 10])
+%!assert (conv2 ([1:5;1:5]', [1:2]', "same"), [4 7 10 13 10; 4 7 10 13 10]')
+%!assert (conv2 ([1:5;1:5], [1:2], "valid"), [4 7 10 13; 4 7 10 13])
+%!assert (conv2 ([1:5;1:5]', [1:2]', "valid"), [4 7 10 13; 4 7 10 13]')
+
+%!test
+%! rand ("seed", 42);
+%! x = rand (100);
+%! y = ones (5);
+%! A = conv2 (x, y)(5:end-4,5:end-4);
+%! B = conv2 (x, y, "valid");
+%! assert (B, A); ## Yes, this test is for *exact* equivalence.
+
+
+%% Test input validation
+%!error conv2 ()
+%!error conv2 (1)
+%!error <SHAPE type not valid> conv2 (1,2, "NOT_A_SHAPE")
+%% Test alternate calling form which should be 2 vectors and a matrix
+%!error conv2 (ones (2), 1, 1)
+%!error conv2 (1, ones (2), 1)
+*/
+
+DEFUN (convn, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{C} =} convn (@var{A}, @var{B})\n\
+@deftypefnx {Built-in Function} {@var{C} =} convn (@var{A}, @var{B}, @var{shape})\n\
+Return the n-D convolution of @var{A} and @var{B}.  The size of the result\n\
+is determined by the optional @var{shape} argument which takes the following\n\
+values\n\
+\n\
+@table @asis\n\
+@item @var{shape} = \"full\"\n\
+Return the full convolution.  (default)\n\
+\n\
+@item @var{shape} = \"same\"\n\
+Return central part of the convolution with the same size as @var{A}.\n\
+The central part of the convolution begins at the indices\n\
+@code{floor ([size(@var{B})/2] + 1)}.\n\
+\n\
+@item @var{shape} = \"valid\"\n\
+Return only the parts which do not include zero-padded edges.\n\
+The size of the result is @code{max (size (A) - size (B) + 1, 0)}.\n\
+@end table\n\
+\n\
+@seealso{conv2, conv}\n\
+@end deftypefn")
+{
+  octave_value retval;
+  octave_value tmp;
+  int nargin = args.length ();
+  std::string shape = "full";   // default
+  convn_type ct;
+
+  if (nargin < 2 || nargin > 3)
+    {
+     print_usage ();
+     return retval;
+    }
+  else if (nargin == 3)
+    {
+      if (args(2).is_string ())
+        shape = args(2).string_value ();
+    }
+
+  if (shape == "full")
+    ct = convn_full;
+  else if (shape == "same")
+    ct = convn_same;
+  else if (shape == "valid")
+    ct = convn_valid;
+  else
+    {
+      error ("convn: SHAPE type not valid");
+      print_usage ();
+      return retval;
+    }
+
+  if (args(0).is_single_type () || args(1).is_single_type ())
+    {
+      if (args(0).is_complex_type () || args(1).is_complex_type ())
+        {
+          FloatComplexNDArray a (args(0).float_complex_array_value ());
+          if (args(1).is_real_type ())
+            {
+              FloatNDArray b (args(1).float_array_value ());
+              retval = convn (a, b, ct);
+            }
+          else
+            {
+              FloatComplexNDArray b (args(1).float_complex_array_value ());
+              retval = convn (a, b, ct);
+            }
+        }
+      else
+        {
+          FloatNDArray a (args(0).float_array_value ());
+          FloatNDArray b (args(1).float_array_value ());
+          retval = convn (a, b, ct);
+        }
+    }
+  else
+    {
+      if (args(0).is_complex_type () || args(1).is_complex_type ())
+        {
+          ComplexNDArray a (args(0).complex_array_value ());
+          if (args(1).is_real_type ())
+            {
+              NDArray b (args(1).array_value ());
+              retval = convn (a, b, ct);
+            }
+          else
+            {
+              ComplexNDArray b (args(1).complex_array_value ());
+              retval = convn (a, b, ct);
+            }
+        }
+      else
+        {
+          NDArray a (args(0).array_value ());
+          NDArray b (args(1).array_value ());
+          retval = convn (a, b, ct);
+        }
+    }
+
+   return retval;
+}
+
+/*
+ FIXME: Need tests for convn in addition to conv2.
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/daspk.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,480 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+
+#include <iomanip>
+#include <iostream>
+
+#include "DASPK.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "ov-fcn.h"
+#include "ov-cell.h"
+#include "pager.h"
+#include "unwind-prot.h"
+#include "utils.h"
+#include "variables.h"
+
+#include "DASPK-opts.cc"
+
+// Global pointer for user defined function required by daspk.
+static octave_function *daspk_fcn;
+
+// Global pointer for optional user defined jacobian function.
+static octave_function *daspk_jac;
+
+// Have we warned about imaginary values returned from user function?
+static bool warned_fcn_imaginary = false;
+static bool warned_jac_imaginary = false;
+
+// Is this a recursive call?
+static int call_depth = 0;
+
+ColumnVector
+daspk_user_function (const ColumnVector& x, const ColumnVector& xdot,
+                     double t, octave_idx_type& ires)
+{
+  ColumnVector retval;
+
+  assert (x.capacity () == xdot.capacity ());
+
+  octave_value_list args;
+
+  args(2) = t;
+  args(1) = xdot;
+  args(0) = x;
+
+  if (daspk_fcn)
+    {
+      octave_value_list tmp = daspk_fcn->do_multi_index_op (1, args);
+
+      if (error_state)
+        {
+          gripe_user_supplied_eval ("daspk");
+          return retval;
+        }
+
+      int tlen = tmp.length ();
+      if (tlen > 0 && tmp(0).is_defined ())
+        {
+          if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
+            {
+              warning ("daspk: ignoring imaginary part returned from user-supplied function");
+              warned_fcn_imaginary = true;
+            }
+
+          retval = ColumnVector (tmp(0).vector_value ());
+
+          if (tlen > 1)
+            ires = tmp(1).int_value ();
+
+          if (error_state || retval.length () == 0)
+            gripe_user_supplied_eval ("daspk");
+        }
+      else
+        gripe_user_supplied_eval ("daspk");
+    }
+
+  return retval;
+}
+
+Matrix
+daspk_user_jacobian (const ColumnVector& x, const ColumnVector& xdot,
+                     double t, double cj)
+{
+  Matrix retval;
+
+  assert (x.capacity () == xdot.capacity ());
+
+  octave_value_list args;
+
+  args(3) = cj;
+  args(2) = t;
+  args(1) = xdot;
+  args(0) = x;
+
+  if (daspk_jac)
+    {
+      octave_value_list tmp = daspk_jac->do_multi_index_op (1, args);
+
+      if (error_state)
+        {
+          gripe_user_supplied_eval ("daspk");
+          return retval;
+        }
+
+      int tlen = tmp.length ();
+      if (tlen > 0 && tmp(0).is_defined ())
+        {
+          if (! warned_jac_imaginary && tmp(0).is_complex_type ())
+            {
+              warning ("daspk: ignoring imaginary part returned from user-supplied jacobian function");
+              warned_jac_imaginary = true;
+            }
+
+          retval = tmp(0).matrix_value ();
+
+          if (error_state || retval.length () == 0)
+            gripe_user_supplied_eval ("daspk");
+        }
+      else
+        gripe_user_supplied_eval ("daspk");
+    }
+
+  return retval;
+}
+
+#define DASPK_ABORT() \
+  return retval
+
+#define DASPK_ABORT1(msg) \
+  do \
+    { \
+      ::error ("daspk: " msg); \
+      DASPK_ABORT (); \
+    } \
+  while (0)
+
+#define DASPK_ABORT2(fmt, arg) \
+  do \
+    { \
+      ::error ("daspk: " fmt, arg); \
+      DASPK_ABORT (); \
+    } \
+  while (0)
+
+DEFUN (daspk, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {[@var{x}, @var{xdot}, @var{istate}, @var{msg}] =} daspk (@var{fcn}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\
+Solve the set of differential-algebraic equations\n\
+@tex\n\
+$$ 0 = f (x, \\dot{x}, t) $$\n\
+with\n\
+$$ x(t_0) = x_0, \\dot{x}(t_0) = \\dot{x}_0 $$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+0 = f (x, xdot, t)\n\
+@end example\n\
+\n\
+@noindent\n\
+with\n\
+\n\
+@example\n\
+x(t_0) = x_0, xdot(t_0) = xdot_0\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+The solution is returned in the matrices @var{x} and @var{xdot},\n\
+with each row in the result matrices corresponding to one of the\n\
+elements in the vector @var{t}.  The first element of @var{t}\n\
+should be @math{t_0} and correspond to the initial state of the\n\
+system @var{x_0} and its derivative @var{xdot_0}, so that the first\n\
+row of the output @var{x} is @var{x_0} and the first row\n\
+of the output @var{xdot} is @var{xdot_0}.\n\
+\n\
+The first argument, @var{fcn}, is a string, inline, or function handle\n\
+that names the function @math{f} to call to compute the vector of\n\
+residuals for the set of equations.  It must have the form\n\
+\n\
+@example\n\
+@var{res} = f (@var{x}, @var{xdot}, @var{t})\n\
+@end example\n\
+\n\
+@noindent\n\
+in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a\n\
+scalar.\n\
+\n\
+If @var{fcn} is a two-element string array or a two-element cell array\n\
+of strings, inline functions, or function handles, the first element names\n\
+the function @math{f} described above, and the second element names a\n\
+function to compute the modified Jacobian\n\
+@tex\n\
+$$\n\
+J = {\\partial f \\over \\partial x}\n\
+  + c {\\partial f \\over \\partial \\dot{x}}\n\
+$$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+@group\n\
+      df       df\n\
+jac = -- + c ------\n\
+      dx     d xdot\n\
+@end group\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+\n\
+The modified Jacobian function must have the form\n\
+\n\
+@example\n\
+@group\n\
+\n\
+@var{jac} = j (@var{x}, @var{xdot}, @var{t}, @var{c})\n\
+\n\
+@end group\n\
+@end example\n\
+\n\
+The second and third arguments to @code{daspk} specify the initial\n\
+condition of the states and their derivatives, and the fourth argument\n\
+specifies a vector of output times at which the solution is desired,\n\
+including the time corresponding to the initial condition.\n\
+\n\
+The set of initial states and derivatives are not strictly required to\n\
+be consistent.  If they are not consistent, you must use the\n\
+@code{daspk_options} function to provide additional information so\n\
+that @code{daspk} can compute a consistent starting point.\n\
+\n\
+The fifth argument is optional, and may be used to specify a set of\n\
+times that the DAE solver should not integrate past.  It is useful for\n\
+avoiding difficulties with singularities and points where there is a\n\
+discontinuity in the derivative.\n\
+\n\
+After a successful computation, the value of @var{istate} will be\n\
+greater than zero (consistent with the Fortran version of @sc{daspk}).\n\
+\n\
+If the computation is not successful, the value of @var{istate} will be\n\
+less than zero and @var{msg} will contain additional information.\n\
+\n\
+You can use the function @code{daspk_options} to set optional\n\
+parameters for @code{daspk}.\n\
+@seealso{dassl}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  warned_fcn_imaginary = false;
+  warned_jac_imaginary = false;
+
+  unwind_protect frame;
+
+  frame.protect_var (call_depth);
+  call_depth++;
+
+  if (call_depth > 1)
+    DASPK_ABORT1 ("invalid recursive call");
+
+  int nargin = args.length ();
+
+  if (nargin > 3 && nargin < 6)
+    {
+      std::string fcn_name, fname, jac_name, jname;
+      daspk_fcn = 0;
+      daspk_jac = 0;
+
+      octave_value f_arg = args(0);
+
+      if (f_arg.is_cell ())
+        {
+          Cell c = f_arg.cell_value ();
+          if (c.length () == 1)
+            f_arg = c(0);
+          else if (c.length () == 2)
+            {
+              if (c(0).is_function_handle () || c(0).is_inline_function ())
+                daspk_fcn = c(0).function_value ();
+              else
+                {
+                  fcn_name = unique_symbol_name ("__daspk_fcn__");
+                  fname = "function y = ";
+                  fname.append (fcn_name);
+                  fname.append (" (x, xdot, t) y = ");
+                  daspk_fcn = extract_function
+                    (c(0), "daspk", fcn_name, fname, "; endfunction");
+                }
+
+              if (daspk_fcn)
+                {
+                  if (c(1).is_function_handle () || c(1).is_inline_function ())
+                    daspk_jac = c(1).function_value ();
+                  else
+                    {
+                      jac_name = unique_symbol_name ("__daspk_jac__");
+                      jname = "function jac = ";
+                      jname.append (jac_name);
+                      jname.append (" (x, xdot, t, cj) jac = ");
+                      daspk_jac = extract_function
+                        (c(1), "daspk", jac_name, jname, "; endfunction");
+
+                      if (!daspk_jac)
+                        {
+                          if (fcn_name.length ())
+                            clear_function (fcn_name);
+                          daspk_fcn = 0;
+                        }
+                    }
+                }
+            }
+          else
+            DASPK_ABORT1 ("incorrect number of elements in cell array");
+        }
+
+      if (!daspk_fcn && ! f_arg.is_cell ())
+        {
+          if (f_arg.is_function_handle () || f_arg.is_inline_function ())
+            daspk_fcn = f_arg.function_value ();
+          else
+            {
+              switch (f_arg.rows ())
+                {
+                case 1:
+                  do
+                    {
+                      fcn_name = unique_symbol_name ("__daspk_fcn__");
+                      fname = "function y = ";
+                      fname.append (fcn_name);
+                      fname.append (" (x, xdot, t) y = ");
+                      daspk_fcn = extract_function
+                        (f_arg, "daspk", fcn_name, fname, "; endfunction");
+                    }
+                  while (0);
+                  break;
+
+                case 2:
+                  {
+                    string_vector tmp = f_arg.all_strings ();
+
+                    if (! error_state)
+                      {
+                        fcn_name = unique_symbol_name ("__daspk_fcn__");
+                        fname = "function y = ";
+                        fname.append (fcn_name);
+                        fname.append (" (x, xdot, t) y = ");
+                        daspk_fcn = extract_function
+                          (tmp(0), "daspk", fcn_name, fname, "; endfunction");
+
+                        if (daspk_fcn)
+                          {
+                            jac_name = unique_symbol_name ("__daspk_jac__");
+                            jname = "function jac = ";
+                            jname.append (jac_name);
+                            jname.append (" (x, xdot, t, cj) jac = ");
+                            daspk_jac = extract_function
+                              (tmp(1), "daspk", jac_name, jname,
+                               "; endfunction");
+
+                            if (!daspk_jac)
+                              {
+                                if (fcn_name.length ())
+                                  clear_function (fcn_name);
+                                daspk_fcn = 0;
+                              }
+                          }
+                      }
+                  }
+                }
+            }
+        }
+
+      if (error_state || ! daspk_fcn)
+        DASPK_ABORT ();
+
+      ColumnVector state = ColumnVector (args(1).vector_value ());
+
+      if (error_state)
+        DASPK_ABORT1 ("expecting state vector as second argument");
+
+      ColumnVector deriv (args(2).vector_value ());
+
+      if (error_state)
+        DASPK_ABORT1 ("expecting derivative vector as third argument");
+
+      ColumnVector out_times (args(3).vector_value ());
+
+      if (error_state)
+        DASPK_ABORT1 ("expecting output time vector as fourth argument");
+
+      ColumnVector crit_times;
+      int crit_times_set = 0;
+      if (nargin > 4)
+        {
+          crit_times = ColumnVector (args(4).vector_value ());
+
+          if (error_state)
+            DASPK_ABORT1 ("expecting critical time vector as fifth argument");
+
+          crit_times_set = 1;
+        }
+
+      if (state.capacity () != deriv.capacity ())
+        DASPK_ABORT1 ("x and xdot must have the same size");
+
+      double tzero = out_times (0);
+
+      DAEFunc func (daspk_user_function);
+      if (daspk_jac)
+        func.set_jacobian_function (daspk_user_jacobian);
+
+      DASPK dae (state, deriv, tzero, func);
+      dae.set_options (daspk_opts);
+
+      Matrix output;
+      Matrix deriv_output;
+
+      if (crit_times_set)
+        output = dae.integrate (out_times, deriv_output, crit_times);
+      else
+        output = dae.integrate (out_times, deriv_output);
+
+      if (fcn_name.length ())
+        clear_function (fcn_name);
+      if (jac_name.length ())
+        clear_function (jac_name);
+
+      if (! error_state)
+        {
+          std::string msg = dae.error_message ();
+
+          retval(3) = msg;
+          retval(2) = static_cast<double> (dae.integration_state ());
+
+          if (dae.integration_ok ())
+            {
+              retval(1) = deriv_output;
+              retval(0) = output;
+            }
+          else
+            {
+              retval(1) = Matrix ();
+              retval(0) = Matrix ();
+
+              if (nargout < 3)
+                error ("daspk: %s", msg.c_str ());
+            }
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/dasrt.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,590 @@
+/*
+
+Copyright (C) 2002-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <iostream>
+#include <string>
+
+#include "DASRT.h"
+#include "lo-mappers.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "ov-fcn.h"
+#include "ov-cell.h"
+#include "pager.h"
+#include "parse.h"
+#include "unwind-prot.h"
+#include "utils.h"
+#include "variables.h"
+
+#include "DASRT-opts.cc"
+
+// Global pointers for user defined function required by dasrt.
+static octave_function *dasrt_f;
+static octave_function *dasrt_j;
+static octave_function *dasrt_cf;
+
+// Have we warned about imaginary values returned from user function?
+static bool warned_fcn_imaginary = false;
+static bool warned_jac_imaginary = false;
+static bool warned_cf_imaginary = false;
+
+// Is this a recursive call?
+static int call_depth = 0;
+
+static ColumnVector
+dasrt_user_f (const ColumnVector& x, const ColumnVector& xdot,
+              double t, octave_idx_type&)
+{
+  ColumnVector retval;
+
+  assert (x.capacity () == xdot.capacity ());
+
+  octave_value_list args;
+
+  args(2) = t;
+  args(1) = xdot;
+  args(0) = x;
+
+  if (dasrt_f)
+    {
+      octave_value_list tmp = dasrt_f->do_multi_index_op (1, args);
+
+      if (error_state)
+        {
+          gripe_user_supplied_eval ("dasrt");
+          return retval;
+        }
+
+      if (tmp.length () > 0 && tmp(0).is_defined ())
+        {
+          if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
+            {
+              warning ("dasrt: ignoring imaginary part returned from user-supplied function");
+              warned_fcn_imaginary = true;
+            }
+
+          retval = ColumnVector (tmp(0).vector_value ());
+
+          if (error_state || retval.length () == 0)
+            gripe_user_supplied_eval ("dasrt");
+        }
+      else
+        gripe_user_supplied_eval ("dasrt");
+    }
+
+  return retval;
+}
+
+static ColumnVector
+dasrt_user_cf (const ColumnVector& x, double t)
+{
+  ColumnVector retval;
+
+  octave_value_list args;
+
+  args(1) = t;
+  args(0) = x;
+
+  if (dasrt_cf)
+    {
+      octave_value_list tmp = dasrt_cf->do_multi_index_op (1, args);
+
+      if (error_state)
+        {
+          gripe_user_supplied_eval ("dasrt");
+          return retval;
+        }
+
+      if (tmp.length () > 0 && tmp(0).is_defined ())
+        {
+          if (! warned_cf_imaginary && tmp(0).is_complex_type ())
+            {
+              warning ("dasrt: ignoring imaginary part returned from user-supplied constraint function");
+              warned_cf_imaginary = true;
+            }
+
+          retval = ColumnVector (tmp(0).vector_value ());
+
+          if (error_state || retval.length () == 0)
+            gripe_user_supplied_eval ("dasrt");
+        }
+      else
+        gripe_user_supplied_eval ("dasrt");
+    }
+
+  return retval;
+}
+
+static Matrix
+dasrt_user_j (const ColumnVector& x, const ColumnVector& xdot,
+              double t, double cj)
+{
+  Matrix retval;
+
+  assert (x.capacity () == xdot.capacity ());
+
+  octave_value_list args;
+
+  args(3) = cj;
+  args(2) = t;
+  args(1) = xdot;
+  args(0) = x;
+
+  if (dasrt_j)
+    {
+      octave_value_list tmp = dasrt_j->do_multi_index_op (1, args);
+
+      if (error_state)
+        {
+          gripe_user_supplied_eval ("dasrt");
+          return retval;
+        }
+
+      int tlen = tmp.length ();
+      if (tlen > 0 && tmp(0).is_defined ())
+        {
+          if (! warned_jac_imaginary && tmp(0).is_complex_type ())
+            {
+              warning ("dasrt: ignoring imaginary part returned from user-supplied jacobian function");
+              warned_jac_imaginary = true;
+            }
+
+          retval = tmp(0).matrix_value ();
+
+          if (error_state || retval.length () == 0)
+            gripe_user_supplied_eval ("dasrt");
+        }
+      else
+        gripe_user_supplied_eval ("dasrt");
+    }
+
+  return retval;
+}
+
+#define DASRT_ABORT \
+  return retval
+
+#define DASRT_ABORT1(msg) \
+  do \
+    { \
+      ::error ("dasrt: " msg); \
+      DASRT_ABORT; \
+    } \
+  while (0)
+
+#define DASRT_ABORT2(fmt, arg) \
+  do \
+    { \
+      ::error ("dasrt: " fmt, arg); \
+      DASRT_ABORT; \
+    } \
+  while (0)
+
+DEFUN (dasrt, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {[@var{x}, @var{xdot}, @var{t_out}, @var{istat}, @var{msg}] =} dasrt (@var{fcn}, [], @var{x_0}, @var{xdot_0}, @var{t})\n\
+@deftypefnx {Built-in Function} {@dots{} =} dasrt (@var{fcn}, @var{g}, @var{x_0}, @var{xdot_0}, @var{t})\n\
+@deftypefnx {Built-in Function} {@dots{} =} dasrt (@var{fcn}, [], @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\
+@deftypefnx {Built-in Function} {@dots{} =} dasrt (@var{fcn}, @var{g}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\
+Solve the set of differential-algebraic equations\n\
+@tex\n\
+$$ 0 = f (x, \\dot{x}, t) $$\n\
+with\n\
+$$ x(t_0) = x_0, \\dot{x}(t_0) = \\dot{x}_0 $$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+0 = f (x, xdot, t)\n\
+@end example\n\
+\n\
+@noindent\n\
+with\n\
+\n\
+@example\n\
+x(t_0) = x_0, xdot(t_0) = xdot_0\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+with functional stopping criteria (root solving).\n\
+\n\
+The solution is returned in the matrices @var{x} and @var{xdot},\n\
+with each row in the result matrices corresponding to one of the\n\
+elements in the vector @var{t_out}.  The first element of @var{t}\n\
+should be @math{t_0} and correspond to the initial state of the\n\
+system @var{x_0} and its derivative @var{xdot_0}, so that the first\n\
+row of the output @var{x} is @var{x_0} and the first row\n\
+of the output @var{xdot} is @var{xdot_0}.\n\
+\n\
+The vector @var{t} provides an upper limit on the length of the\n\
+integration.  If the stopping condition is met, the vector\n\
+@var{t_out} will be shorter than @var{t}, and the final element of\n\
+@var{t_out} will be the point at which the stopping condition was met,\n\
+and may not correspond to any element of the vector @var{t}.\n\
+\n\
+The first argument, @var{fcn}, is a string, inline, or function handle\n\
+that names the function @math{f} to call to compute the vector of\n\
+residuals for the set of equations.  It must have the form\n\
+\n\
+@example\n\
+@var{res} = f (@var{x}, @var{xdot}, @var{t})\n\
+@end example\n\
+\n\
+@noindent\n\
+in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a\n\
+scalar.\n\
+\n\
+If @var{fcn} is a two-element string array or a two-element cell array\n\
+of strings, inline functions, or function handles, the first element names\n\
+the function @math{f} described above, and the second element names a\n\
+function to compute the modified Jacobian\n\
+\n\
+@tex\n\
+$$\n\
+J = {\\partial f \\over \\partial x}\n\
+  + c {\\partial f \\over \\partial \\dot{x}}\n\
+$$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+@group\n\
+      df       df\n\
+jac = -- + c ------\n\
+      dx     d xdot\n\
+@end group\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+\n\
+The modified Jacobian function must have the form\n\
+\n\
+@example\n\
+@group\n\
+\n\
+@var{jac} = j (@var{x}, @var{xdot}, @var{t}, @var{c})\n\
+\n\
+@end group\n\
+@end example\n\
+\n\
+The optional second argument names a function that defines the\n\
+constraint functions whose roots are desired during the integration.\n\
+This function must have the form\n\
+\n\
+@example\n\
+@var{g_out} = g (@var{x}, @var{t})\n\
+@end example\n\
+\n\
+@noindent\n\
+and return a vector of the constraint function values.\n\
+If the value of any of the constraint functions changes sign, @sc{dasrt}\n\
+will attempt to stop the integration at the point of the sign change.\n\
+\n\
+If the name of the constraint function is omitted, @code{dasrt} solves\n\
+the same problem as @code{daspk} or @code{dassl}.\n\
+\n\
+Note that because of numerical errors in the constraint functions\n\
+due to round-off and integration error, @sc{dasrt} may return false\n\
+roots, or return the same root at two or more nearly equal values of\n\
+@var{T}.  If such false roots are suspected, the user should consider\n\
+smaller error tolerances or higher precision in the evaluation of the\n\
+constraint functions.\n\
+\n\
+If a root of some constraint function defines the end of the problem,\n\
+the input to @sc{dasrt} should nevertheless allow integration to a\n\
+point slightly past that root, so that @sc{dasrt} can locate the root\n\
+by interpolation.\n\
+\n\
+The third and fourth arguments to @code{dasrt} specify the initial\n\
+condition of the states and their derivatives, and the fourth argument\n\
+specifies a vector of output times at which the solution is desired,\n\
+including the time corresponding to the initial condition.\n\
+\n\
+The set of initial states and derivatives are not strictly required to\n\
+be consistent.  In practice, however, @sc{dassl} is not very good at\n\
+determining a consistent set for you, so it is best if you ensure that\n\
+the initial values result in the function evaluating to zero.\n\
+\n\
+The sixth argument is optional, and may be used to specify a set of\n\
+times that the DAE solver should not integrate past.  It is useful for\n\
+avoiding difficulties with singularities and points where there is a\n\
+discontinuity in the derivative.\n\
+\n\
+After a successful computation, the value of @var{istate} will be\n\
+greater than zero (consistent with the Fortran version of @sc{dassl}).\n\
+\n\
+If the computation is not successful, the value of @var{istate} will be\n\
+less than zero and @var{msg} will contain additional information.\n\
+\n\
+You can use the function @code{dasrt_options} to set optional\n\
+parameters for @code{dasrt}.\n\
+@seealso{dasrt_options, daspk, dasrt, lsode}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  warned_fcn_imaginary = false;
+  warned_jac_imaginary = false;
+  warned_cf_imaginary = false;
+
+  unwind_protect frame;
+
+  frame.protect_var (call_depth);
+  call_depth++;
+
+  if (call_depth > 1)
+    DASRT_ABORT1 ("invalid recursive call");
+
+  int argp = 0;
+
+  int nargin = args.length ();
+
+  if (nargin < 4 || nargin > 6)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  std::string fcn_name, fname, jac_name, jname;
+  dasrt_f = 0;
+  dasrt_j = 0;
+  dasrt_cf = 0;
+
+  // Check all the arguments.  Are they the right animals?
+
+  // Here's where I take care of f and j in one shot:
+
+  octave_value f_arg = args(0);
+
+  if (f_arg.is_cell ())
+    {
+      Cell c = f_arg.cell_value ();
+      if (c.length () == 1)
+        f_arg = c(0);
+      else if (c.length () == 2)
+        {
+          if (c(0).is_function_handle () || c(0).is_inline_function ())
+            dasrt_f = c(0).function_value ();
+          else
+            {
+              fcn_name = unique_symbol_name ("__dasrt_fcn__");
+              fname = "function y = ";
+              fname.append (fcn_name);
+              fname.append (" (x, xdot, t) y = ");
+              dasrt_f = extract_function
+                (c(0), "dasrt", fcn_name, fname, "; endfunction");
+            }
+
+          if (dasrt_f)
+            {
+              if (c(1).is_function_handle () || c(1).is_inline_function ())
+                dasrt_j = c(1).function_value ();
+              else
+                {
+                  jac_name = unique_symbol_name ("__dasrt_jac__");
+                  jname = "function jac = ";
+                  jname.append (jac_name);
+                  jname.append (" (x, xdot, t, cj) jac = ");
+                  dasrt_j = extract_function
+                    (c(1), "dasrt", jac_name, jname, "; endfunction");
+
+                  if (!dasrt_j)
+                    {
+                      if (fcn_name.length ())
+                        clear_function (fcn_name);
+                      dasrt_f = 0;
+                    }
+                }
+            }
+        }
+      else
+        DASRT_ABORT1 ("incorrect number of elements in cell array");
+    }
+
+  if (!dasrt_f && ! f_arg.is_cell ())
+    {
+      if (f_arg.is_function_handle () || f_arg.is_inline_function ())
+        dasrt_f = f_arg.function_value ();
+      else
+        {
+          switch (f_arg.rows ())
+            {
+            case 1:
+              fcn_name = unique_symbol_name ("__dasrt_fcn__");
+              fname = "function y = ";
+              fname.append (fcn_name);
+              fname.append (" (x, xdot, t) y = ");
+              dasrt_f = extract_function
+                (f_arg, "dasrt", fcn_name, fname, "; endfunction");
+              break;
+
+            case 2:
+              {
+                string_vector tmp = args(0).all_strings ();
+
+                if (! error_state)
+                  {
+                    fcn_name = unique_symbol_name ("__dasrt_fcn__");
+                    fname = "function y = ";
+                    fname.append (fcn_name);
+                    fname.append (" (x, xdot, t) y = ");
+                    dasrt_f = extract_function
+                      (tmp(0), "dasrt", fcn_name, fname, "; endfunction");
+
+                    if (dasrt_f)
+                      {
+                        jac_name = unique_symbol_name ("__dasrt_jac__");
+                        jname = "function jac = ";
+                        jname.append (jac_name);
+                        jname.append (" (x, xdot, t, cj) jac = ");
+                        dasrt_j = extract_function
+                          (tmp(1), "dasrt", jac_name, jname, "; endfunction");
+
+                        if (! dasrt_j)
+                          dasrt_f = 0;
+                      }
+                  }
+              }
+              break;
+
+            default:
+              DASRT_ABORT1
+                ("first arg should be a string or 2-element string array");
+            }
+        }
+    }
+
+  if (error_state || (! dasrt_f))
+    DASRT_ABORT;
+
+  DAERTFunc func (dasrt_user_f);
+
+  argp++;
+
+  if (args(1).is_function_handle () || args(1).is_inline_function ())
+    {
+      dasrt_cf = args(1).function_value ();
+
+      if (! dasrt_cf)
+        DASRT_ABORT1 ("expecting function name as argument 2");
+
+      argp++;
+
+      func.set_constraint_function (dasrt_user_cf);
+    }
+  else if (args(1).is_string ())
+    {
+      dasrt_cf = is_valid_function (args(1), "dasrt", true);
+      if (! dasrt_cf)
+        DASRT_ABORT1 ("expecting function name as argument 2");
+
+      argp++;
+
+      func.set_constraint_function (dasrt_user_cf);
+    }
+
+  ColumnVector state (args(argp++).vector_value ());
+
+  if (error_state)
+    DASRT_ABORT2 ("expecting state vector as argument %d", argp);
+
+  ColumnVector stateprime (args(argp++).vector_value ());
+
+  if (error_state)
+    DASRT_ABORT2
+       ("expecting time derivative of state vector as argument %d", argp);
+
+  ColumnVector out_times (args(argp++).vector_value ());
+
+  if (error_state)
+    DASRT_ABORT2
+        ("expecting output time vector as %s argument %d", argp);
+
+  double tzero = out_times (0);
+
+  ColumnVector crit_times;
+
+  bool crit_times_set = false;
+
+  if (argp < nargin)
+    {
+      crit_times = ColumnVector (args(argp++).vector_value ());
+
+      if (error_state)
+        DASRT_ABORT2
+          ("expecting critical time vector as argument %d", argp);
+
+      crit_times_set = true;
+    }
+
+  if (dasrt_j)
+    func.set_jacobian_function (dasrt_user_j);
+
+  DASRT_result output;
+
+  DASRT dae = DASRT (state, stateprime, tzero, func);
+
+  dae.set_options (dasrt_opts);
+
+  if (crit_times_set)
+    output = dae.integrate (out_times, crit_times);
+  else
+    output = dae.integrate (out_times);
+
+  if (fcn_name.length ())
+    clear_function (fcn_name);
+  if (jac_name.length ())
+    clear_function (jac_name);
+
+  if (! error_state)
+    {
+      std::string msg = dae.error_message ();
+
+      retval(4) = msg;
+      retval(3) = static_cast<double> (dae.integration_state ());
+
+      if (dae.integration_ok ())
+        {
+          retval(2) = output.times ();
+          retval(1) = output.deriv ();
+          retval(0) = output.state ();
+        }
+      else
+        {
+          retval(2) = Matrix ();
+          retval(1) = Matrix ();
+          retval(0) = Matrix ();
+
+          if (nargout < 4)
+            error ("dasrt: %s", msg.c_str ());
+        }
+    }
+
+  return retval;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/dassl.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,565 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+
+#include <iomanip>
+#include <iostream>
+
+#include "DASSL.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "ov-fcn.h"
+#include "ov-cell.h"
+#include "pager.h"
+#include "unwind-prot.h"
+#include "utils.h"
+#include "variables.h"
+
+#include "DASSL-opts.cc"
+
+// Global pointer for user defined function required by dassl.
+static octave_function *dassl_fcn;
+
+// Global pointer for optional user defined jacobian function.
+static octave_function *dassl_jac;
+
+// Have we warned about imaginary values returned from user function?
+static bool warned_fcn_imaginary = false;
+static bool warned_jac_imaginary = false;
+
+// Is this a recursive call?
+static int call_depth = 0;
+
+ColumnVector
+dassl_user_function (const ColumnVector& x, const ColumnVector& xdot,
+                     double t, octave_idx_type& ires)
+{
+  ColumnVector retval;
+
+  assert (x.capacity () == xdot.capacity ());
+
+  octave_value_list args;
+
+  args(2) = t;
+  args(1) = xdot;
+  args(0) = x;
+
+  if (dassl_fcn)
+    {
+      octave_value_list tmp = dassl_fcn->do_multi_index_op (1, args);
+
+      if (error_state)
+        {
+          gripe_user_supplied_eval ("dassl");
+          return retval;
+        }
+
+      int tlen = tmp.length ();
+      if (tlen > 0 && tmp(0).is_defined ())
+        {
+          if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
+            {
+              warning ("dassl: ignoring imaginary part returned from user-supplied function");
+              warned_fcn_imaginary = true;
+            }
+
+          retval = ColumnVector (tmp(0).vector_value ());
+
+          if (tlen > 1)
+            ires = tmp(1).int_value ();
+
+          if (error_state || retval.length () == 0)
+            gripe_user_supplied_eval ("dassl");
+        }
+      else
+        gripe_user_supplied_eval ("dassl");
+    }
+
+  return retval;
+}
+
+Matrix
+dassl_user_jacobian (const ColumnVector& x, const ColumnVector& xdot,
+                     double t, double cj)
+{
+  Matrix retval;
+
+  assert (x.capacity () == xdot.capacity ());
+
+  octave_value_list args;
+
+  args(3) = cj;
+  args(2) = t;
+  args(1) = xdot;
+  args(0) = x;
+
+  if (dassl_jac)
+    {
+      octave_value_list tmp = dassl_jac->do_multi_index_op (1, args);
+
+      if (error_state)
+        {
+          gripe_user_supplied_eval ("dassl");
+          return retval;
+        }
+
+      int tlen = tmp.length ();
+      if (tlen > 0 && tmp(0).is_defined ())
+        {
+          if (! warned_jac_imaginary && tmp(0).is_complex_type ())
+            {
+              warning ("dassl: ignoring imaginary part returned from user-supplied jacobian function");
+              warned_jac_imaginary = true;
+            }
+
+          retval = tmp(0).matrix_value ();
+
+          if (error_state || retval.length () == 0)
+            gripe_user_supplied_eval ("dassl");
+        }
+      else
+        gripe_user_supplied_eval ("dassl");
+    }
+
+  return retval;
+}
+
+#define DASSL_ABORT() \
+  return retval
+
+#define DASSL_ABORT1(msg) \
+  do \
+    { \
+      ::error ("dassl: " msg); \
+      DASSL_ABORT (); \
+    } \
+  while (0)
+
+#define DASSL_ABORT2(fmt, arg) \
+  do \
+    { \
+      ::error ("dassl: " fmt, arg); \
+      DASSL_ABORT (); \
+    } \
+  while (0)
+
+DEFUN (dassl, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {[@var{x}, @var{xdot}, @var{istate}, @var{msg}] =} dassl (@var{fcn}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\
+Solve the set of differential-algebraic equations\n\
+@tex\n\
+$$ 0 = f (x, \\dot{x}, t) $$\n\
+with\n\
+$$ x(t_0) = x_0, \\dot{x}(t_0) = \\dot{x}_0 $$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+0 = f (x, xdot, t)\n\
+@end example\n\
+\n\
+@noindent\n\
+with\n\
+\n\
+@example\n\
+x(t_0) = x_0, xdot(t_0) = xdot_0\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+The solution is returned in the matrices @var{x} and @var{xdot},\n\
+with each row in the result matrices corresponding to one of the\n\
+elements in the vector @var{t}.  The first element of @var{t}\n\
+should be @math{t_0} and correspond to the initial state of the\n\
+system @var{x_0} and its derivative @var{xdot_0}, so that the first\n\
+row of the output @var{x} is @var{x_0} and the first row\n\
+of the output @var{xdot} is @var{xdot_0}.\n\
+\n\
+The first argument, @var{fcn}, is a string, inline, or function handle\n\
+that names the function @math{f} to call to compute the vector of\n\
+residuals for the set of equations.  It must have the form\n\
+\n\
+@example\n\
+@var{res} = f (@var{x}, @var{xdot}, @var{t})\n\
+@end example\n\
+\n\
+@noindent\n\
+in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a\n\
+scalar.\n\
+\n\
+If @var{fcn} is a two-element string array or a two-element cell array\n\
+of strings, inline functions, or function handles, the first element names\n\
+the function @math{f} described above, and the second element names a\n\
+function to compute the modified Jacobian\n\
+\n\
+@tex\n\
+$$\n\
+J = {\\partial f \\over \\partial x}\n\
+  + c {\\partial f \\over \\partial \\dot{x}}\n\
+$$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+@group\n\
+      df       df\n\
+jac = -- + c ------\n\
+      dx     d xdot\n\
+@end group\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+\n\
+The modified Jacobian function must have the form\n\
+\n\
+@example\n\
+@group\n\
+\n\
+@var{jac} = j (@var{x}, @var{xdot}, @var{t}, @var{c})\n\
+\n\
+@end group\n\
+@end example\n\
+\n\
+The second and third arguments to @code{dassl} specify the initial\n\
+condition of the states and their derivatives, and the fourth argument\n\
+specifies a vector of output times at which the solution is desired,\n\
+including the time corresponding to the initial condition.\n\
+\n\
+The set of initial states and derivatives are not strictly required to\n\
+be consistent.  In practice, however, @sc{dassl} is not very good at\n\
+determining a consistent set for you, so it is best if you ensure that\n\
+the initial values result in the function evaluating to zero.\n\
+\n\
+The fifth argument is optional, and may be used to specify a set of\n\
+times that the DAE solver should not integrate past.  It is useful for\n\
+avoiding difficulties with singularities and points where there is a\n\
+discontinuity in the derivative.\n\
+\n\
+After a successful computation, the value of @var{istate} will be\n\
+greater than zero (consistent with the Fortran version of @sc{dassl}).\n\
+\n\
+If the computation is not successful, the value of @var{istate} will be\n\
+less than zero and @var{msg} will contain additional information.\n\
+\n\
+You can use the function @code{dassl_options} to set optional\n\
+parameters for @code{dassl}.\n\
+@seealso{daspk, dasrt, lsode}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  warned_fcn_imaginary = false;
+  warned_jac_imaginary = false;
+
+  unwind_protect frame;
+
+  frame.protect_var (call_depth);
+  call_depth++;
+
+  if (call_depth > 1)
+    DASSL_ABORT1 ("invalid recursive call");
+
+  int nargin = args.length ();
+
+  if (nargin > 3 && nargin < 6 && nargout < 5)
+    {
+      std::string fcn_name, fname, jac_name, jname;
+      dassl_fcn = 0;
+      dassl_jac = 0;
+
+      octave_value f_arg = args(0);
+
+      if (f_arg.is_cell ())
+        {
+          Cell c = f_arg.cell_value ();
+          if (c.length () == 1)
+            f_arg = c(0);
+          else if (c.length () == 2)
+            {
+              if (c(0).is_function_handle () || c(0).is_inline_function ())
+                dassl_fcn = c(0).function_value ();
+              else
+                {
+                  fcn_name = unique_symbol_name ("__dassl_fcn__");
+                  fname = "function y = ";
+                  fname.append (fcn_name);
+                  fname.append (" (x, xdot, t) y = ");
+                  dassl_fcn = extract_function
+                    (c(0), "dassl", fcn_name, fname, "; endfunction");
+                }
+
+              if (dassl_fcn)
+                {
+                  if (c(1).is_function_handle () || c(1).is_inline_function ())
+                    dassl_jac = c(1).function_value ();
+                  else
+                    {
+                        jac_name = unique_symbol_name ("__dassl_jac__");
+                        jname = "function jac = ";
+                        jname.append (jac_name);
+                        jname.append (" (x, xdot, t, cj) jac = ");
+                        dassl_jac = extract_function
+                          (c(1), "dassl", jac_name, jname, "; endfunction");
+
+                        if (!dassl_jac)
+                          {
+                            if (fcn_name.length ())
+                              clear_function (fcn_name);
+                            dassl_fcn = 0;
+                          }
+                    }
+                }
+            }
+          else
+            DASSL_ABORT1 ("incorrect number of elements in cell array");
+        }
+
+      if (!dassl_fcn && ! f_arg.is_cell ())
+        {
+          if (f_arg.is_function_handle () || f_arg.is_inline_function ())
+            dassl_fcn = f_arg.function_value ();
+          else
+            {
+              switch (f_arg.rows ())
+                {
+                case 1:
+                  do
+                    {
+                      fcn_name = unique_symbol_name ("__dassl_fcn__");
+                      fname = "function y = ";
+                      fname.append (fcn_name);
+                      fname.append (" (x, xdot, t) y = ");
+                      dassl_fcn = extract_function
+                        (f_arg, "dassl", fcn_name, fname, "; endfunction");
+                    }
+                  while (0);
+                  break;
+
+                case 2:
+                  {
+                    string_vector tmp = f_arg.all_strings ();
+
+                    if (! error_state)
+                      {
+                        fcn_name = unique_symbol_name ("__dassl_fcn__");
+                        fname = "function y = ";
+                        fname.append (fcn_name);
+                        fname.append (" (x, xdot, t) y = ");
+                        dassl_fcn = extract_function
+                          (tmp(0), "dassl", fcn_name, fname, "; endfunction");
+
+                        if (dassl_fcn)
+                          {
+                            jac_name = unique_symbol_name ("__dassl_jac__");
+                            jname = "function jac = ";
+                            jname.append (jac_name);
+                            jname.append (" (x, xdot, t, cj) jac = ");
+                            dassl_jac = extract_function
+                              (tmp(1), "dassl", jac_name, jname,
+                               "; endfunction");
+
+                            if (!dassl_jac)
+                              {
+                                if (fcn_name.length ())
+                                  clear_function (fcn_name);
+                                dassl_fcn = 0;
+                              }
+                          }
+                      }
+                  }
+                }
+            }
+        }
+
+      if (error_state || ! dassl_fcn)
+        DASSL_ABORT ();
+
+      ColumnVector state = ColumnVector (args(1).vector_value ());
+
+      if (error_state)
+        DASSL_ABORT1 ("expecting state vector as second argument");
+
+      ColumnVector deriv (args(2).vector_value ());
+
+      if (error_state)
+        DASSL_ABORT1 ("expecting derivative vector as third argument");
+
+      ColumnVector out_times (args(3).vector_value ());
+
+      if (error_state)
+        DASSL_ABORT1 ("expecting output time vector as fourth argument");
+
+      ColumnVector crit_times;
+      int crit_times_set = 0;
+      if (nargin > 4)
+        {
+          crit_times = ColumnVector (args(4).vector_value ());
+
+          if (error_state)
+            DASSL_ABORT1 ("expecting critical time vector as fifth argument");
+
+          crit_times_set = 1;
+        }
+
+      if (state.capacity () != deriv.capacity ())
+        DASSL_ABORT1 ("x and xdot must have the same size");
+
+      double tzero = out_times (0);
+
+      DAEFunc func (dassl_user_function);
+      if (dassl_jac)
+        func.set_jacobian_function (dassl_user_jacobian);
+
+      DASSL dae (state, deriv, tzero, func);
+
+      dae.set_options (dassl_opts);
+
+      Matrix output;
+      Matrix deriv_output;
+
+      if (crit_times_set)
+        output = dae.integrate (out_times, deriv_output, crit_times);
+      else
+        output = dae.integrate (out_times, deriv_output);
+
+      if (fcn_name.length ())
+        clear_function (fcn_name);
+      if (jac_name.length ())
+        clear_function (jac_name);
+
+      if (! error_state)
+        {
+          std::string msg = dae.error_message ();
+
+          retval(3) = msg;
+          retval(2) = static_cast<double> (dae.integration_state ());
+
+          if (dae.integration_ok ())
+            {
+              retval(1) = deriv_output;
+              retval(0) = output;
+            }
+          else
+            {
+              retval(1) = Matrix ();
+              retval(0) = Matrix ();
+
+              if (nargout < 3)
+                error ("dassl: %s", msg.c_str ());
+            }
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+## dassl-1.m
+##
+## Test dassl() function
+##
+## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+##         Comalco Research and Technology
+##         20 May 1998
+##
+## Problem
+##
+##    y1' = -y2,   y1(0) = 1
+##    y2' =  y1,   y2(0) = 0
+##
+## Solution
+##
+##    y1(t) = cos(t)
+##    y2(t) = sin(t)
+##
+%!function res = __f (x, xdot, t)
+%!  res = [xdot(1)+x(2); xdot(2)-x(1)];
+%!endfunction
+
+%!test
+%!
+%! x0 = [1; 0];
+%! xdot0 = [0; 1];
+%! t = (0:1:10)';
+%!
+%! tol = 100 * dassl_options ("relative tolerance");
+%!
+%! [x, xdot] = dassl ("__f", x0, xdot0, t);
+%!
+%! y = [cos(t), sin(t)];
+%!
+%! assert (x, y, tol);
+
+## dassl-2.m
+##
+## Test dassl() function
+##
+## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+##         Comalco Research and Technology
+##         20 May 1998
+##
+## Based on SLATEC quick check for DASSL by Linda Petzold
+##
+## Problem
+##
+##   x1' + 10*x1 = 0,   x1(0) = 1
+##   x1  + x2    = 1,   x2(0) = 0
+##
+##
+## Solution
+##
+##  x1(t) = exp(-10*t)
+##  x2(t) = 1 - x(1)
+##
+%!function res = __f (x, xdot, t)
+%!  res = [xdot(1)+10*x(1); x(1)+x(2)-1];
+%!endfunction
+
+%!test
+%!
+%! x0 = [1; 0];
+%! xdot0 = [-10; 10];
+%! t = (0:0.2:1)';
+%!
+%! tol = 500 * dassl_options ("relative tolerance");
+%!
+%! [x, xdot] = dassl ("__f", x0, xdot0, t);
+%!
+%! y = [exp(-10*t), 1-exp(-10*t)];
+%!
+%! assert (x, y, tol);
+
+%!test
+%! dassl_options ("absolute tolerance", eps);
+%! assert (dassl_options ("absolute tolerance") == eps);
+
+%!error dassl_options ("foo", 1, 2)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/det.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,253 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "DET.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+#include "ops.h"
+
+#include "ov-re-mat.h"
+#include "ov-cx-mat.h"
+#include "ov-flt-re-mat.h"
+#include "ov-flt-cx-mat.h"
+#include "ov-re-diag.h"
+#include "ov-cx-diag.h"
+#include "ov-flt-re-diag.h"
+#include "ov-flt-cx-diag.h"
+#include "ov-perm.h"
+
+#define MAYBE_CAST(VAR, CLASS) \
+  const CLASS *VAR = arg.type_id () == CLASS::static_type_id () ? \
+   dynamic_cast<const CLASS *> (&arg.get_rep ()) : 0
+
+DEFUN (det, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} det (@var{A})\n\
+@deftypefnx {Built-in Function} {[@var{d}, @var{rcond}] =} det (@var{A})\n\
+Compute the determinant of @var{A}.\n\
+\n\
+Return an estimate of the reciprocal condition number if requested.\n\
+\n\
+Routines from @sc{lapack} are used for full matrices and code from\n\
+@sc{umfpack} is used for sparse matrices.\n\
+\n\
+The determinant should not be used to check a matrix for singularity.\n\
+For that, use any of the condition number functions: @code{cond},\n\
+@code{condest}, @code{rcond}.\n\
+@seealso{cond, condest, rcond}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin != 1)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value arg = args(0);
+
+  octave_idx_type nr = arg.rows ();
+  octave_idx_type nc = arg.columns ();
+
+  if (nr == 0 && nc == 0)
+    {
+      retval(0) = 1.0;
+      return retval;
+    }
+
+  int arg_is_empty = empty_arg ("det", nr, nc);
+  if (arg_is_empty < 0)
+    return retval;
+  if (arg_is_empty > 0)
+    return octave_value (Matrix (1, 1, 1.0));
+
+
+  if (nr != nc)
+    {
+      gripe_square_matrix_required ("det");
+      return retval;
+    }
+
+  bool isfloat = arg.is_single_type ();
+
+  if (arg.is_diag_matrix ())
+    {
+      if (arg.is_complex_type ())
+        {
+          if (isfloat)
+            {
+              retval(0) = arg.float_complex_diag_matrix_value ().determinant ().value ();
+              if (nargout > 1)
+                retval(1) = arg.float_complex_diag_matrix_value ().rcond ();
+            }
+          else
+            {
+              retval(0) = arg.complex_diag_matrix_value ().determinant ().value ();
+              if (nargout > 1)
+                retval(1) = arg.complex_diag_matrix_value ().rcond ();
+            }
+        }
+      else
+        {
+          if (isfloat)
+            {
+              retval(0) = arg.float_diag_matrix_value ().determinant ().value ();
+              if (nargout > 1)
+                retval(1) = arg.float_diag_matrix_value ().rcond ();
+            }
+          else
+            {
+              retval(0) = arg.diag_matrix_value ().determinant ().value ();
+              if (nargout > 1)
+                retval(1) = arg.diag_matrix_value ().rcond ();
+            }
+        }
+    }
+  else if (arg.is_perm_matrix ())
+    {
+      retval(0) = static_cast<double> (arg.perm_matrix_value ().determinant ());
+      if (nargout > 1)
+        retval(1) = 1.0;
+    }
+  else if (arg.is_single_type ())
+    {
+      if (arg.is_real_type ())
+        {
+          octave_idx_type info;
+          float rcond = 0.0;
+          // Always compute rcond, so we can detect numerically
+          // singular matrices.
+          FloatMatrix m = arg.float_matrix_value ();
+          if (! error_state)
+            {
+              MAYBE_CAST (rep, octave_float_matrix);
+              MatrixType mtype = rep ? rep -> matrix_type () : MatrixType ();
+              FloatDET det = m.determinant (mtype, info, rcond);
+              retval(1) = rcond;
+              retval(0) = info == -1 ? static_cast<float>(0.0) : det.value ();
+              if (rep) rep->matrix_type (mtype);
+            }
+        }
+      else if (arg.is_complex_type ())
+        {
+          octave_idx_type info;
+          float rcond = 0.0;
+          // Always compute rcond, so we can detect numerically
+          // singular matrices.
+          FloatComplexMatrix m = arg.float_complex_matrix_value ();
+          if (! error_state)
+            {
+              MAYBE_CAST (rep, octave_float_complex_matrix);
+              MatrixType mtype = rep ? rep -> matrix_type () : MatrixType ();
+              FloatComplexDET det = m.determinant (mtype, info, rcond);
+              retval(1) = rcond;
+              retval(0) = info == -1 ? FloatComplex (0.0) : det.value ();
+              if (rep) rep->matrix_type (mtype);
+            }
+        }
+    }
+  else
+    {
+      if (arg.is_real_type ())
+        {
+          octave_idx_type info;
+          double rcond = 0.0;
+          // Always compute rcond, so we can detect numerically
+          // singular matrices.
+          if (arg.is_sparse_type ())
+            {
+              SparseMatrix m = arg.sparse_matrix_value ();
+              if (! error_state)
+                {
+                  DET det = m.determinant (info, rcond);
+                  retval(1) = rcond;
+                  retval(0) = info == -1 ? 0.0 : det.value ();
+                }
+            }
+          else
+            {
+              Matrix m = arg.matrix_value ();
+              if (! error_state)
+                {
+                  MAYBE_CAST (rep, octave_matrix);
+                  MatrixType mtype = rep ? rep -> matrix_type () : MatrixType ();
+                  DET det = m.determinant (mtype, info, rcond);
+                  retval(1) = rcond;
+                  retval(0) = info == -1 ? 0.0 : det.value ();
+                  if (rep) rep->matrix_type (mtype);
+                }
+            }
+        }
+      else if (arg.is_complex_type ())
+        {
+          octave_idx_type info;
+          double rcond = 0.0;
+          // Always compute rcond, so we can detect numerically
+          // singular matrices.
+          if (arg.is_sparse_type ())
+            {
+              SparseComplexMatrix m = arg.sparse_complex_matrix_value ();
+              if (! error_state)
+                {
+                  ComplexDET det = m.determinant (info, rcond);
+                  retval(1) = rcond;
+                  retval(0) = info == -1 ? Complex (0.0) : det.value ();
+                }
+            }
+          else
+            {
+              ComplexMatrix m = arg.complex_matrix_value ();
+              if (! error_state)
+                {
+                  MAYBE_CAST (rep, octave_complex_matrix);
+                  MatrixType mtype = rep ? rep -> matrix_type () : MatrixType ();
+                  ComplexDET det = m.determinant (mtype, info, rcond);
+                  retval(1) = rcond;
+                  retval(0) = info == -1 ? Complex (0.0) : det.value ();
+                  if (rep) rep->matrix_type (mtype);
+                }
+            }
+        }
+      else
+        gripe_wrong_type_arg ("det", arg);
+    }
+  return retval;
+}
+
+/*
+%!assert (det ([1, 2; 3, 4]), -2, 10*eps)
+%!assert (det (single ([1, 2; 3, 4])), single (-2), 10*eps ("single"))
+%!error det ()
+%!error det (1, 2)
+%!error <argument must be a square matrix> det ([1, 2; 3, 4; 5, 6])
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/dlmread.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,520 @@
+/*
+
+Copyright (C) 2008-2012 Jonathan Stickel
+Copyright (C) 2010 Jaroslav Hajek
+
+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/>.
+
+*/
+
+// Adapted from previous version of dlmread.occ as authored by Kai
+// Habel, but core code has been completely re-written.
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cctype>
+#include <fstream>
+#include <limits>
+
+#include "file-ops.h"
+#include "lo-ieee.h"
+
+#include "defun.h"
+#include "oct-stream.h"
+#include "error.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+static const octave_idx_type idx_max =  std::numeric_limits<octave_idx_type>::max ();
+
+static bool
+read_cell_spec (std::istream& is, octave_idx_type& row, octave_idx_type& col)
+{
+  bool stat = false;
+
+  if (is.peek () == std::istream::traits_type::eof ())
+    stat = true;
+  else
+    {
+      if (::isalpha (is.peek ()))
+        {
+          col = 0;
+          while (is && ::isalpha (is.peek ()))
+            {
+              char ch = is.get ();
+              col *= 26;
+              if (ch >= 'a')
+                col += ch - 'a' + 1;
+              else
+                col += ch - 'A' + 1;
+            }
+          col --;
+
+          if (is)
+            {
+              is >> row;
+              row --;
+              if (is)
+                stat = true;
+            }
+        }
+    }
+
+  return stat;
+}
+
+static bool
+parse_range_spec (const octave_value& range_spec,
+                  octave_idx_type& rlo, octave_idx_type& clo,
+                  octave_idx_type& rup, octave_idx_type& cup)
+{
+  bool stat = true;
+
+  if (range_spec.is_string ())
+    {
+      std::istringstream is (range_spec.string_value ());
+      char ch = is.peek ();
+
+      if (ch == '.' || ch == ':')
+        {
+          rlo = 0;
+          clo = 0;
+          ch = is.get ();
+          if (ch == '.')
+            {
+              ch = is.get ();
+              if (ch != '.')
+                stat = false;
+            }
+        }
+      else
+        {
+          stat = read_cell_spec (is, rlo, clo);
+
+          if (stat)
+            {
+              ch = is.peek ();
+
+              if (ch == '.' || ch == ':')
+                {
+                  ch = is.get ();
+                  if (ch == '.')
+                    {
+                      ch = is.get ();
+                      if (!is || ch != '.')
+                        stat = false;
+                    }
+
+                  rup = idx_max - 1;
+                  cup = idx_max - 1;
+                }
+              else
+                {
+                  rup = rlo;
+                  cup = clo;
+                  if (!is || !is.eof ())
+                    stat = false;
+                }
+            }
+        }
+
+      if (stat && is && !is.eof ())
+        stat = read_cell_spec (is, rup, cup);
+
+      if (!is || !is.eof ())
+        stat = false;
+    }
+  else if (range_spec.is_real_matrix () && range_spec.numel () == 4)
+    {
+      ColumnVector range(range_spec.vector_value ());
+      // double --> unsigned int
+      rlo = static_cast<octave_idx_type> (range(0));
+      clo = static_cast<octave_idx_type> (range(1));
+      rup = static_cast<octave_idx_type> (range(2));
+      cup = static_cast<octave_idx_type> (range(3));
+    }
+  else
+    stat = false;
+
+  return stat;
+}
+
+DEFUN (dlmread, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{data} =} dlmread (@var{file})\n\
+@deftypefnx {Built-in Function} {@var{data} =} dlmread (@var{file}, @var{sep})\n\
+@deftypefnx {Built-in Function} {@var{data} =} dlmread (@var{file}, @var{sep}, @var{r0}, @var{c0})\n\
+@deftypefnx {Built-in Function} {@var{data} =} dlmread (@var{file}, @var{sep}, @var{range})\n\
+@deftypefnx {Built-in Function} {@var{data} =} dlmread (@dots{}, \"emptyvalue\", @var{EMPTYVAL})\n\
+Read the matrix @var{data} from a text file.  If not defined the separator\n\
+between fields is determined from the file itself.  Otherwise the\n\
+separation character is defined by @var{sep}.\n\
+\n\
+Given two scalar arguments @var{r0} and @var{c0}, these define the starting\n\
+row and column of the data to be read.  These values are indexed from zero,\n\
+such that the first row corresponds to an index of zero.\n\
+\n\
+The @var{range} parameter may be a 4-element vector containing the upper\n\
+left and lower right corner @code{[@var{R0},@var{C0},@var{R1},@var{C1}]}\n\
+where the lowest index value is zero.  Alternatively, a spreadsheet style\n\
+range such as \"A2..Q15\" or \"T1:AA5\" can be used.  The lowest alphabetical\n\
+index 'A' refers to the first column.  The lowest row index is 1.\n\
+\n\
+@var{file} should be a file name or file id given by @code{fopen}.  In the\n\
+latter case, the file is read until end of file is reached.\n\
+\n\
+The \"emptyvalue\" option may be used to specify the value used to fill empty\n\
+fields.  The default is zero.\n\
+@seealso{csvread, textscan, textread, dlmwrite}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  double empty_value = 0.0;
+
+  if (nargin > 2 && args(nargin-2).is_string ()
+      && args(nargin-2).string_value () == "emptyvalue")
+    {
+      empty_value = args(nargin-1).double_value ();
+      if (error_state)
+         return retval;
+      nargin -= 2;
+    }
+
+  if (nargin < 1 || nargin > 4)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  std::istream *input = 0;
+  std::ifstream input_file;
+
+  if (args(0).is_string ())
+    {
+      // File name.
+      std::string fname (args(0).string_value ());
+      if (error_state)
+         return retval;
+
+      std::string tname = file_ops::tilde_expand (fname);
+
+      input_file.open (tname.c_str (), std::ios::in);
+
+      if (! input_file)
+        {
+          error ("dlmread: unable to open file `%s'", fname.c_str ());
+          return retval;
+        }
+      else
+        input = &input_file;
+    }
+  else if (args(0).is_scalar_type ())
+    {
+      octave_stream is = octave_stream_list::lookup (args(0), "dlmread");
+
+      if (error_state)
+         return retval;
+
+      input = is.input_stream ();
+
+      if (! input)
+        {
+          error ("dlmread: stream FILE not open for input");
+          return retval;
+        }
+    }
+  else
+    {
+      error ("dlmread: FILE argument must be a string or file id");
+      return retval;
+    }
+
+  // Set default separator.
+  std::string sep;
+  if (nargin > 1)
+    {
+      if (args(1).is_sq_string ())
+        sep = do_string_escapes (args(1).string_value ());
+      else
+        sep = args(1).string_value ();
+
+      if (error_state)
+        return retval;
+    }
+
+  // Take a subset if a range was given.
+  octave_idx_type r0 = 0, c0 = 0, r1 = idx_max-1, c1 = idx_max-1;
+  if (nargin > 2)
+    {
+      if (nargin == 3)
+        {
+          if (!parse_range_spec (args (2), r0, c0, r1, c1))
+            error ("dlmread: error parsing RANGE");
+        }
+      else if (nargin == 4)
+        {
+          r0 = args(2).idx_type_value ();
+          c0 = args(3).idx_type_value ();
+
+          if (error_state)
+            return retval;
+        }
+
+      if (r0 < 0 || c0 < 0)
+        error ("dlmread: left & top must be positive");
+    }
+
+  if (!error_state)
+    {
+      octave_idx_type i = 0, j = 0, r = 1, c = 1, rmax = 0, cmax = 0;
+
+      Matrix rdata;
+      ComplexMatrix cdata;
+
+      bool iscmplx = false;
+      bool sepflag = false;
+
+      std::string line;
+
+      // Skip the r0 leading lines as these might be a header.
+      for (octave_idx_type m = 0; m < r0; m++)
+        getline (*input, line);
+      r1 -= r0;
+
+      std::istringstream tmp_stream;
+
+      // Read in the data one field at a time, growing the data matrix
+      // as needed.
+      while (getline (*input, line))
+        {
+          // Skip blank lines for compatibility.
+          if (line.find_first_not_of (" \t") == std::string::npos)
+            continue;
+
+          // To be compatible with matlab, blank separator should
+          // correspond to whitespace as delimter.
+          if (!sep.length ())
+            {
+              size_t n = line.find_first_of (",:; \t",
+                                             line.find_first_of ("0123456789"));
+              if (n == std::string::npos)
+                {
+                  sep = " \t";
+                  sepflag = true;
+                }
+              else
+                {
+                  char ch = line.at (n);
+
+                  switch (line.at (n))
+                    {
+                    case ' ':
+                    case '\t':
+                      sepflag = true;
+                      sep = " \t";
+                      break;
+
+                    default:
+                      sep = ch;
+                      break;
+                    }
+                }
+            }
+
+          if (cmax == 0)
+            {
+              // Try to estimate the number of columns.  Skip leading
+              // whitespace.
+              size_t pos1 = line.find_first_not_of (" \t");
+              do
+                {
+                  size_t pos2 = line.find_first_of (sep, pos1);
+
+                  if (sepflag && pos2 != std::string::npos)
+                    // Treat consecutive separators as one.
+                    {
+                      pos2 = line.find_first_not_of (sep, pos2);
+                      if (pos2 != std::string::npos)
+                        pos2 -= 1;
+                      else
+                        pos2 = line.length () - 1;
+                    }
+
+                  cmax++;
+
+                  if (pos2 != std::string::npos)
+                    pos1 = pos2 + 1;
+                  else
+                    pos1 = std::string::npos;
+
+                }
+              while (pos1 != std::string::npos);
+
+              if (iscmplx)
+                cdata.resize (rmax, cmax);
+              else
+                rdata.resize (rmax, cmax);
+            }
+
+          r = (r > i + 1 ? r : i + 1);
+          j = 0;
+          // Skip leading whitespace.
+          size_t pos1 = line.find_first_not_of (" \t");
+          do
+            {
+              octave_quit ();
+
+              size_t pos2 = line.find_first_of (sep, pos1);
+              std::string str = line.substr (pos1, pos2 - pos1);
+
+              if (sepflag && pos2 != std::string::npos)
+                // Treat consecutive separators as one.
+                pos2 = line.find_first_not_of (sep, pos2) - 1;
+
+              c = (c > j + 1 ? c : j + 1);
+              if (r > rmax || c > cmax)
+                {
+                  // Use resize_and_fill for the case of not-equal
+                  // length rows.
+                  rmax = 2*r;
+                  cmax = c;
+                  if (iscmplx)
+                    cdata.resize (rmax, cmax);
+                  else
+                    rdata.resize (rmax, cmax);
+                }
+
+              tmp_stream.str (str);
+              tmp_stream.clear ();
+
+              double x = octave_read_double (tmp_stream);
+              if (tmp_stream)
+                {
+                  if (tmp_stream.eof ())
+                    {
+                      if (iscmplx)
+                        cdata(i,j++) = x;
+                      else
+                        rdata(i,j++) = x;
+                    }
+                  else if (std::toupper (tmp_stream.peek ()) == 'I')
+                    {
+                      // This is to allow pure imaginary numbers.
+                      if (iscmplx)
+                        cdata(i,j++) = x;
+                      else
+                        rdata(i,j++) = x;
+                    }
+                  else
+                    {
+                      double y = octave_read_double (tmp_stream);
+
+                      if (!iscmplx && y != 0.)
+                        {
+                          iscmplx = true;
+                          cdata = ComplexMatrix (rdata);
+                        }
+
+                      if (iscmplx)
+                        cdata(i,j++) = Complex (x, y);
+                      else
+                        rdata(i,j++) = x;
+                    }
+                }
+              else if (iscmplx)
+                cdata(i,j++) = empty_value;
+              else
+                rdata(i,j++) = empty_value;
+
+              if (pos2 != std::string::npos)
+                pos1 = pos2 + 1;
+              else
+                pos1 = std::string::npos;
+
+            }
+          while (pos1 != std::string::npos);
+
+          if (i == r1)
+            break;
+
+          i++;
+        }
+
+      if (r1 >= r)
+        r1 = r - 1;
+      if (c1 >= c)
+        c1 = c - 1;
+
+      // Now take the subset of the matrix.
+      if (iscmplx)
+        cdata = cdata.extract (0, c0, r1, c1);
+      else
+        rdata = rdata.extract (0, c0, r1, c1);
+
+      if (iscmplx)
+        retval(0) = cdata;
+      else
+        retval(0) = rdata;
+    }
+
+  return retval;
+}
+
+/*
+%!shared file
+%! file = tmpnam ();
+%! fid = fopen (file, "wt");
+%! fwrite (fid, "1, 2, 3\n4, 5, 6\n7, 8, 9\n10, 11, 12");
+%! fclose (fid);
+
+%!assert (dlmread (file), [1, 2, 3; 4, 5, 6; 7, 8, 9;10, 11, 12])
+%!assert (dlmread (file, ","), [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12])
+%!assert (dlmread (file, ",", [1, 0, 2, 1]), [4, 5; 7, 8])
+%!assert (dlmread (file, ",", "B1..C2"), [2, 3; 5, 6])
+%!assert (dlmread (file, ",", "B1:C2"), [2, 3; 5, 6])
+%!assert (dlmread (file, ",", "..C2"), [1, 2, 3; 4, 5, 6])
+%!assert (dlmread (file, ",", 0, 1), [2, 3; 5, 6; 8, 9; 11, 12])
+%!assert (dlmread (file, ",", "B1.."), [2, 3; 5, 6; 8, 9; 11, 12])
+%!error (dlmread (file, ",", [0 1]))
+
+%!test
+%! unlink (file);
+
+%!shared file
+%! file = tmpnam ();
+%! fid = fopen (file, "wt");
+%! fwrite (fid, "1, 2, 3\n4+4i, 5, 6\n7, 8, 9\n10, 11, 12");
+%! fclose (fid);
+
+%!assert (dlmread (file), [1, 2, 3; 4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12])
+%!assert (dlmread (file, ","), [1, 2, 3; 4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12])
+%!assert (dlmread (file, ",", [1, 0, 2, 1]), [4 + 4i, 5; 7, 8])
+%!assert (dlmread (file, ",", "A2..B3"), [4 + 4i, 5; 7, 8])
+%!assert (dlmread (file, ",", "A2:B3"), [4 + 4i, 5; 7, 8])
+%!assert (dlmread (file, ",", "..B3"), [1, 2; 4 + 4i, 5; 7, 8])
+%!assert (dlmread (file, ",", 1, 0), [4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12])
+%!assert (dlmread (file, ",", "A2.."), [4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12])
+%!error (dlmread (file, ",", [0 1]))
+
+%!test
+%! unlink (file);
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/dot.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,364 @@
+/*
+
+Copyright (C) 2009-2012 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "f77-fcn.h"
+#include "mx-base.h"
+#include "error.h"
+#include "defun.h"
+#include "parse.h"
+
+extern "C"
+{
+  F77_RET_T
+  F77_FUNC (ddot3, DDOT3) (const octave_idx_type&, const octave_idx_type&,
+                           const octave_idx_type&, const double*,
+                           const double*, double*);
+
+  F77_RET_T
+  F77_FUNC (sdot3, SDOT3) (const octave_idx_type&, const octave_idx_type&,
+                           const octave_idx_type&, const float*,
+                           const float*, float*);
+
+  F77_RET_T
+  F77_FUNC (zdotc3, ZDOTC3) (const octave_idx_type&, const octave_idx_type&,
+                             const octave_idx_type&, const Complex*,
+                             const Complex*, Complex*);
+
+  F77_RET_T
+  F77_FUNC (cdotc3, CDOTC3) (const octave_idx_type&, const octave_idx_type&,
+                             const octave_idx_type&, const FloatComplex*,
+                             const FloatComplex*, FloatComplex*);
+
+  F77_RET_T
+  F77_FUNC (dmatm3, DMATM3) (const octave_idx_type&, const octave_idx_type&,
+                             const octave_idx_type&, const octave_idx_type&,
+                             const double*, const double*, double*);
+
+  F77_RET_T
+  F77_FUNC (smatm3, SMATM3) (const octave_idx_type&, const octave_idx_type&,
+                             const octave_idx_type&, const octave_idx_type&,
+                             const float*, const float*, float*);
+
+  F77_RET_T
+  F77_FUNC (zmatm3, ZMATM3) (const octave_idx_type&, const octave_idx_type&,
+                             const octave_idx_type&, const octave_idx_type&,
+                             const Complex*, const Complex*, Complex*);
+
+  F77_RET_T
+  F77_FUNC (cmatm3, CMATM3) (const octave_idx_type&, const octave_idx_type&,
+                             const octave_idx_type&, const octave_idx_type&,
+                             const FloatComplex*, const FloatComplex*,
+                             FloatComplex*);
+}
+
+static void
+get_red_dims (const dim_vector& x, const dim_vector& y, int dim,
+              dim_vector& z, octave_idx_type& m, octave_idx_type& n,
+              octave_idx_type& k)
+{
+  int nd = x.length ();
+  assert (nd == y.length ());
+  z = dim_vector::alloc (nd);
+  m = 1, n = 1, k = 1;
+  for (int i = 0; i < nd; i++)
+    {
+      if (i < dim)
+        {
+          z(i) = x(i);
+          m *= x(i);
+        }
+      else if (i > dim)
+        {
+          z(i) = x(i);
+          n *= x(i);
+        }
+      else
+        {
+          k = x(i);
+          z(i) = 1;
+        }
+    }
+}
+
+DEFUN (dot, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} dot (@var{x}, @var{y}, @var{dim})\n\
+Compute the dot product of two vectors.  If @var{x} and @var{y}\n\
+are matrices, calculate the dot products along the first\n\
+non-singleton dimension.  If the optional argument @var{dim} is\n\
+given, calculate the dot products along this dimension.\n\
+\n\
+This is equivalent to\n\
+@code{sum (conj (@var{X}) .* @var{Y}, @var{dim})},\n\
+but avoids forming a temporary array and is faster.  When @var{X} and\n\
+@var{Y} are column vectors, the result is equivalent to\n\
+@code{@var{X}' * @var{Y}}.\n\
+@seealso{cross, divergence}\n\
+@end deftypefn")
+{
+  octave_value retval;
+  int nargin = args.length ();
+
+  if (nargin < 2 || nargin > 3)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value argx = args(0), argy = args(1);
+
+  if (argx.is_numeric_type () && argy.is_numeric_type ())
+    {
+      dim_vector dimx = argx.dims (), dimy = argy.dims ();
+      bool match = dimx == dimy;
+      if (! match && nargin == 2
+          && dimx.is_vector () && dimy.is_vector ())
+        {
+          // Change to column vectors.
+          dimx = dimx.redim (1);
+          argx = argx.reshape (dimx);
+          dimy = dimy.redim (1);
+          argy = argy.reshape (dimy);
+          match = ! error_state;
+        }
+
+      if (match)
+        {
+          int dim;
+          if (nargin == 2)
+            dim = dimx.first_non_singleton ();
+          else
+            dim = args(2).int_value (true) - 1;
+
+          if (error_state)
+            ;
+          else if (dim < 0)
+            error ("dot: DIM must be a valid dimension");
+          else
+            {
+              octave_idx_type m, n, k;
+              dim_vector dimz;
+              if (argx.is_complex_type () || argy.is_complex_type ())
+                {
+                  if (argx.is_single_type () || argy.is_single_type ())
+                    {
+                      FloatComplexNDArray x = argx.float_complex_array_value ();
+                      FloatComplexNDArray y = argy.float_complex_array_value ();
+                      get_red_dims (dimx, dimy, dim, dimz, m, n, k);
+                      FloatComplexNDArray z(dimz);
+                      if (! error_state)
+                        F77_XFCN (cdotc3, CDOTC3, (m, n, k, x.data (), y.data (),
+                                                   z.fortran_vec ()));
+                      retval = z;
+                    }
+                  else
+                    {
+                      ComplexNDArray x = argx.complex_array_value ();
+                      ComplexNDArray y = argy.complex_array_value ();
+                      get_red_dims (dimx, dimy, dim, dimz, m, n, k);
+                      ComplexNDArray z(dimz);
+                      if (! error_state)
+                        F77_XFCN (zdotc3, ZDOTC3, (m, n, k, x.data (), y.data (),
+                                                   z.fortran_vec ()));
+                      retval = z;
+                    }
+                }
+              else if (argx.is_float_type () && argy.is_float_type ())
+                {
+                  if (argx.is_single_type () || argy.is_single_type ())
+                    {
+                      FloatNDArray x = argx.float_array_value ();
+                      FloatNDArray y = argy.float_array_value ();
+                      get_red_dims (dimx, dimy, dim, dimz, m, n, k);
+                      FloatNDArray z(dimz);
+                      if (! error_state)
+                        F77_XFCN (sdot3, SDOT3, (m, n, k, x.data (), y.data (),
+                                                 z.fortran_vec ()));
+                      retval = z;
+                    }
+                  else
+                    {
+                      NDArray x = argx.array_value ();
+                      NDArray y = argy.array_value ();
+                      get_red_dims (dimx, dimy, dim, dimz, m, n, k);
+                      NDArray z(dimz);
+                      if (! error_state)
+                        F77_XFCN (ddot3, DDOT3, (m, n, k, x.data (), y.data (),
+                                                 z.fortran_vec ()));
+                      retval = z;
+                    }
+                }
+              else
+                {
+                  // Non-optimized evaluation.
+                  octave_value_list tmp;
+                  tmp(1) = args(2);
+                  tmp(0) = do_binary_op (octave_value::op_el_mul, argx, argy);
+                  if (! error_state)
+                    {
+                      tmp = feval ("sum", tmp, 1);
+                      if (! tmp.empty ())
+                        retval = tmp(0);
+                    }
+                }
+            }
+        }
+      else
+        error ("dot: sizes of X and Y must match");
+
+    }
+  else
+    error ("dot: X and Y must be numeric");
+
+  return retval;
+}
+
+/*
+%!assert (dot ([1, 2], [2, 3]), 8)
+
+%!test
+%! x = [2, 1; 2, 1];
+%! y = [-0.5, 2; 0.5, -2];
+%! assert (dot (x, y), [0 0]);
+
+%!test
+%! x = [1+i, 3-i; 1-i, 3-i];
+%! assert (dot (x, x), [4, 20]);
+*/
+
+DEFUN (blkmm, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} blkmm (@var{A}, @var{B})\n\
+Compute products of matrix blocks.  The blocks are given as\n\
+2-dimensional subarrays of the arrays @var{A}, @var{B}.\n\
+The size of @var{A} must have the form @code{[m,k,@dots{}]} and\n\
+size of @var{B} must be @code{[k,n,@dots{}]}.  The result is\n\
+then of size @code{[m,n,@dots{}]} and is computed as follows:\n\
+\n\
+@example\n\
+@group\n\
+for i = 1:prod (size (@var{A})(3:end))\n\
+  @var{C}(:,:,i) = @var{A}(:,:,i) * @var{B}(:,:,i)\n\
+endfor\n\
+@end group\n\
+@end example\n\
+@end deftypefn")
+{
+  octave_value retval;
+  int nargin = args.length ();
+
+  if (nargin != 2)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value argx = args(0), argy = args(1);
+
+  if (argx.is_numeric_type () && argy.is_numeric_type ())
+    {
+      const dim_vector dimx = argx.dims (), dimy = argy.dims ();
+      int nd = dimx.length ();
+      octave_idx_type m = dimx(0), k = dimx(1), n = dimy(1), np = 1;
+      bool match = dimy(0) == k && nd == dimy.length ();
+      dim_vector dimz = dim_vector::alloc (nd);
+      dimz(0) = m;
+      dimz(1) = n;
+      for (int i = 2; match && i < nd; i++)
+        {
+          match = match && dimx(i) == dimy(i);
+          dimz(i) = dimx(i);
+          np *= dimz(i);
+        }
+
+      if (match)
+        {
+          if (argx.is_complex_type () || argy.is_complex_type ())
+            {
+              if (argx.is_single_type () || argy.is_single_type ())
+                {
+                  FloatComplexNDArray x = argx.float_complex_array_value ();
+                  FloatComplexNDArray y = argy.float_complex_array_value ();
+                  FloatComplexNDArray z(dimz);
+                  if (! error_state)
+                    F77_XFCN (cmatm3, CMATM3, (m, n, k, np, x.data (), y.data (),
+                                               z.fortran_vec ()));
+                  retval = z;
+                }
+              else
+                {
+                  ComplexNDArray x = argx.complex_array_value ();
+                  ComplexNDArray y = argy.complex_array_value ();
+                  ComplexNDArray z(dimz);
+                  if (! error_state)
+                    F77_XFCN (zmatm3, ZMATM3, (m, n, k, np, x.data (), y.data (),
+                                               z.fortran_vec ()));
+                  retval = z;
+                }
+            }
+          else
+            {
+              if (argx.is_single_type () || argy.is_single_type ())
+                {
+                  FloatNDArray x = argx.float_array_value ();
+                  FloatNDArray y = argy.float_array_value ();
+                  FloatNDArray z(dimz);
+                  if (! error_state)
+                    F77_XFCN (smatm3, SMATM3, (m, n, k, np, x.data (), y.data (),
+                                               z.fortran_vec ()));
+                  retval = z;
+                }
+              else
+                {
+                  NDArray x = argx.array_value ();
+                  NDArray y = argy.array_value ();
+                  NDArray z(dimz);
+                  if (! error_state)
+                    F77_XFCN (dmatm3, DMATM3, (m, n, k, np, x.data (), y.data (),
+                                               z.fortran_vec ()));
+                  retval = z;
+                }
+            }
+        }
+      else
+        error ("blkmm: A and B dimensions don't match: (%s) and (%s)",
+               dimx.str ().c_str (), dimy.str ().c_str ());
+
+    }
+  else
+    error ("blkmm: A and B must be numeric");
+
+  return retval;
+}
+
+/*
+%!test
+%! x(:,:,1) = [1 2; 3 4];
+%! x(:,:,2) = [1 1; 1 1];
+%! z(:,:,1) = [7 10; 15 22];
+%! z(:,:,2) = [2 2; 2 2];
+%! assert (blkmm (x,x), z);
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/eig.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,334 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "EIG.h"
+#include "fEIG.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+DEFUN (eig, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{lambda} =} eig (@var{A})\n\
+@deftypefnx {Built-in Function} {@var{lambda} =} eig (@var{A}, @var{B})\n\
+@deftypefnx {Built-in Function} {[@var{V}, @var{lambda}] =} eig (@var{A})\n\
+@deftypefnx {Built-in Function} {[@var{V}, @var{lambda}] =} eig (@var{A}, @var{B})\n\
+Compute the eigenvalues (and optionally the eigenvectors) of a matrix\n\
+or a pair of matrices\n\
+\n\
+The algorithm used depends on whether there are one or two input\n\
+matrices, if they are real or complex and if they are symmetric\n\
+(Hermitian if complex) or non-symmetric.\n\
+\n\
+The eigenvalues returned by @code{eig} are not ordered.\n\
+@seealso{eigs, svd}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin > 2 || nargin == 0 || nargout > 2)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value arg_a, arg_b;
+
+  octave_idx_type nr_a = 0, nr_b = 0;
+  octave_idx_type nc_a = 0, nc_b = 0;
+
+  arg_a = args(0);
+  nr_a = arg_a.rows ();
+  nc_a = arg_a.columns ();
+
+  int arg_is_empty = empty_arg ("eig", nr_a, nc_a);
+  if (arg_is_empty < 0)
+    return retval;
+  else if (arg_is_empty > 0)
+    return octave_value_list (2, Matrix ());
+
+  if (!(arg_a.is_single_type () || arg_a.is_double_type ()))
+    {
+      gripe_wrong_type_arg ("eig", arg_a);
+      return retval;
+    }
+
+  if (nargin == 2)
+    {
+      arg_b = args(1);
+      nr_b = arg_b.rows ();
+      nc_b = arg_b.columns ();
+
+      arg_is_empty = empty_arg ("eig", nr_b, nc_b);
+      if (arg_is_empty < 0)
+        return retval;
+      else if (arg_is_empty > 0)
+        return octave_value_list (2, Matrix ());
+
+      if (!(arg_b.is_single_type () || arg_b.is_double_type ()))
+        {
+          gripe_wrong_type_arg ("eig", arg_b);
+          return retval;
+        }
+    }
+
+  if (nr_a != nc_a)
+    {
+      gripe_square_matrix_required ("eig");
+      return retval;
+    }
+
+  if (nargin == 2 && nr_b != nc_b)
+    {
+      gripe_square_matrix_required ("eig");
+      return retval;
+    }
+
+  Matrix tmp_a, tmp_b;
+  ComplexMatrix ctmp_a, ctmp_b;
+  FloatMatrix ftmp_a, ftmp_b;
+  FloatComplexMatrix fctmp_a, fctmp_b;
+
+  if (arg_a.is_single_type ())
+    {
+      FloatEIG result;
+
+      if (nargin == 1)
+        {
+          if (arg_a.is_real_type ())
+            {
+              ftmp_a = arg_a.float_matrix_value ();
+
+              if (error_state)
+                return retval;
+              else
+                result = FloatEIG (ftmp_a, nargout > 1);
+            }
+          else
+            {
+              fctmp_a = arg_a.float_complex_matrix_value ();
+
+              if (error_state)
+                return retval;
+              else
+                result = FloatEIG (fctmp_a, nargout > 1);
+            }
+        }
+      else if (nargin == 2)
+        {
+          if (arg_a.is_real_type () && arg_b.is_real_type ())
+            {
+              ftmp_a = arg_a.float_matrix_value ();
+              ftmp_b = arg_b.float_matrix_value ();
+
+              if (error_state)
+                return retval;
+              else
+                result = FloatEIG (ftmp_a, ftmp_b, nargout > 1);
+            }
+          else
+            {
+              fctmp_a = arg_a.float_complex_matrix_value ();
+              fctmp_b = arg_b.float_complex_matrix_value ();
+
+              if (error_state)
+                return retval;
+              else
+                result = FloatEIG (fctmp_a, fctmp_b, nargout > 1);
+            }
+        }
+
+      if (! error_state)
+        {
+          if (nargout == 0 || nargout == 1)
+            {
+              retval(0) = result.eigenvalues ();
+            }
+          else
+            {
+              // Blame it on Matlab.
+
+              FloatComplexDiagMatrix d (result.eigenvalues ());
+
+              retval(1) = d;
+              retval(0) = result.eigenvectors ();
+            }
+        }
+    }
+  else
+    {
+      EIG result;
+
+      if (nargin == 1)
+        {
+          if (arg_a.is_real_type ())
+            {
+              tmp_a = arg_a.matrix_value ();
+
+              if (error_state)
+                return retval;
+              else
+                result = EIG (tmp_a, nargout > 1);
+            }
+          else
+            {
+              ctmp_a = arg_a.complex_matrix_value ();
+
+              if (error_state)
+                return retval;
+              else
+                result = EIG (ctmp_a, nargout > 1);
+            }
+        }
+      else if (nargin == 2)
+        {
+          if (arg_a.is_real_type () && arg_b.is_real_type ())
+            {
+              tmp_a = arg_a.matrix_value ();
+              tmp_b = arg_b.matrix_value ();
+
+              if (error_state)
+                return retval;
+              else
+                result = EIG (tmp_a, tmp_b, nargout > 1);
+            }
+          else
+            {
+              ctmp_a = arg_a.complex_matrix_value ();
+              ctmp_b = arg_b.complex_matrix_value ();
+
+              if (error_state)
+                return retval;
+              else
+                result = EIG (ctmp_a, ctmp_b, nargout > 1);
+            }
+        }
+
+      if (! error_state)
+        {
+          if (nargout == 0 || nargout == 1)
+            {
+              retval(0) = result.eigenvalues ();
+            }
+          else
+            {
+              // Blame it on Matlab.
+
+              ComplexDiagMatrix d (result.eigenvalues ());
+
+              retval(1) = d;
+              retval(0) = result.eigenvectors ();
+            }
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!assert (eig ([1, 2; 2, 1]), [-1; 3], sqrt (eps))
+
+%!test
+%! [v, d] = eig ([1, 2; 2, 1]);
+%! x = 1 / sqrt (2);
+%! assert (d, [-1, 0; 0, 3], sqrt (eps));
+%! assert (v, [-x, x; x, x], sqrt (eps));
+
+%!assert (eig (single ([1, 2; 2, 1])), single ([-1; 3]), sqrt (eps ("single")))
+
+%!test
+%! [v, d] = eig (single ([1, 2; 2, 1]));
+%! x = single (1 / sqrt (2));
+%! assert (d, single ([-1, 0; 0, 3]), sqrt (eps ("single")));
+%! assert (v, [-x, x; x, x], sqrt (eps ("single")));
+
+%!test
+%! A = [1, 2; -1, 1];  B = [3, 3; 1, 2];
+%! [v, d] = eig (A, B);
+%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps));
+%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps));
+
+%!test
+%! A = single ([1, 2; -1, 1]);  B = single ([3, 3; 1, 2]);
+%! [v, d] = eig (A, B);
+%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps ("single")));
+%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps ("single")));
+
+%!test
+%! A = [1, 2; 2, 1];  B = [3, -2; -2, 3];
+%! [v, d] = eig (A, B);
+%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps));
+%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps));
+
+%!test
+%! A = single ([1, 2; 2, 1]);  B = single ([3, -2; -2, 3]);
+%! [v, d] = eig (A, B);
+%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps ("single")));
+%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps ("single")));
+
+%!test
+%! A = [1+3i, 2+i; 2-i, 1+3i];  B = [5+9i, 2+i; 2-i, 5+9i];
+%! [v, d] = eig (A, B);
+%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps));
+%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps));
+
+%!test
+%! A = single ([1+3i, 2+i; 2-i, 1+3i]);  B = single ([5+9i, 2+i; 2-i, 5+9i]);
+%! [v, d] = eig (A, B);
+%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps ("single")));
+%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps ("single")));
+
+%!test
+%! A = [1+3i, 2+3i; 3-8i, 8+3i];  B = [8+i, 3+i; 4-9i, 3+i];
+%! [v, d] = eig (A, B);
+%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps));
+%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps));
+
+%!test
+%! A = single ([1+3i, 2+3i; 3-8i, 8+3i]);  B = single ([8+i, 3+i; 4-9i, 3+i]);
+%! [v, d] = eig (A, B);
+%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps ("single")));
+%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps ("single")));
+
+%!test
+%! A = [1, 2; 3, 8];  B = [8, 3; 4, 3];
+%! [v, d] = eig (A, B);
+%! assert (A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps));
+%! assert (A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps));
+
+%!error eig ()
+%!error eig ([1, 2; 3, 4], [4, 3; 2, 1], 1)
+%!error <EIG requires same size matrices> eig ([1, 2; 3, 4], 2)
+%!error <argument must be a square matrix> eig ([1, 2; 3, 4; 5, 6])
+%!error <wrong type argument> eig ("abcd")
+%!error <wrong type argument> eig ([1 2 ; 2 3], "abcd")
+%!error <wrong type argument> eig (false, [1 2 ; 2 3])
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/fft.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,319 @@
+/*
+
+Copyright (C) 1997-2012 David Bateman
+Copyright (C) 1996-1997 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "lo-mappers.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+#if defined (HAVE_FFTW)
+#define FFTSRC "@sc{fftw}"
+#else
+#define FFTSRC "@sc{fftpack}"
+#endif
+
+static octave_value
+do_fft (const octave_value_list &args, const char *fcn, int type)
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 1 || nargin > 3)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value arg = args(0);
+  dim_vector dims = arg.dims ();
+  octave_idx_type n_points = -1;
+  int dim = -1;
+
+  if (nargin > 1)
+    {
+      if (! args(1).is_empty ())
+        {
+          double dval = args(1).double_value ();
+          if (xisnan (dval))
+            error ("%s: number of points (N) cannot be NaN", fcn);
+          else
+            {
+              n_points = NINTbig (dval);
+              if (n_points < 0)
+                error ("%s: number of points (N) must be greater than zero", fcn);
+            }
+        }
+    }
+
+  if (error_state)
+    return retval;
+
+  if (nargin > 2)
+    {
+      double dval = args(2).double_value ();
+      if (xisnan (dval))
+        error ("%s: DIM cannot be NaN", fcn);
+      else if (dval < 1 || dval > dims.length ())
+        error ("%s: DIM must be a valid dimension along which to perform FFT", fcn);
+      else
+        // to be safe, cast it back to int since dim is an int
+        dim = NINT (dval) - 1;
+    }
+
+  if (error_state)
+    return retval;
+
+  for (octave_idx_type i = 0; i < dims.length (); i++)
+    if (dims(i) < 0)
+      return retval;
+
+  if (dim < 0)
+    {
+      for (octave_idx_type i = 0; i < dims.length (); i++)
+        if (dims(i) > 1)
+          {
+            dim = i;
+            break;
+          }
+
+      // And if the first argument is scalar?
+      if (dim < 0)
+        dim = 1;
+    }
+
+  if (n_points < 0)
+    n_points = dims (dim);
+  else
+    dims (dim) = n_points;
+
+  if (dims.any_zero () || n_points == 0)
+    {
+      if (arg.is_single_type ())
+        return octave_value (FloatNDArray (dims));
+      else
+        return octave_value (NDArray (dims));
+    }
+
+  if (arg.is_single_type ())
+    {
+      if (arg.is_real_type ())
+        {
+          FloatNDArray nda = arg.float_array_value ();
+
+          if (! error_state)
+            {
+              nda.resize (dims, 0.0);
+              retval = (type != 0 ? nda.ifourier (dim) : nda.fourier (dim));
+            }
+        }
+      else
+        {
+          FloatComplexNDArray cnda = arg.float_complex_array_value ();
+
+          if (! error_state)
+            {
+              cnda.resize (dims, 0.0);
+              retval = (type != 0 ? cnda.ifourier (dim) : cnda.fourier (dim));
+            }
+        }
+    }
+  else
+    {
+      if (arg.is_real_type ())
+        {
+          NDArray nda = arg.array_value ();
+
+          if (! error_state)
+            {
+              nda.resize (dims, 0.0);
+              retval = (type != 0 ? nda.ifourier (dim) : nda.fourier (dim));
+            }
+        }
+      else if (arg.is_complex_type ())
+        {
+          ComplexNDArray cnda = arg.complex_array_value ();
+
+          if (! error_state)
+            {
+              cnda.resize (dims, 0.0);
+              retval = (type != 0 ? cnda.ifourier (dim) : cnda.fourier (dim));
+            }
+        }
+      else
+        {
+          gripe_wrong_type_arg (fcn, arg);
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!assert (fft ([]), [])
+%!assert (fft (zeros (10,0)), zeros (10,0))
+%!assert (fft (zeros (0,10)), zeros (0,10))
+%!assert (fft (0), 0)
+%!assert (fft (1), 1)
+%!assert (fft (ones (2,2)), [2,2; 0,0])
+%!assert (fft (eye (2,2)), [1,1; 1,-1])
+
+%!assert (fft (single ([])), single ([]))
+%!assert (fft (zeros (10,0,"single")), zeros (10,0,"single"))
+%!assert (fft (zeros (0,10,"single")), zeros (0,10,"single"))
+%!assert (fft (single (0)), single (0))
+%!assert (fft (single (1)), single (1))
+%!assert (fft (ones (2,2,"single")), single ([2,2; 0,0]))
+%!assert (fft (eye (2,2,"single")), single ([1,1; 1,-1]))
+
+%!error (fft ())
+*/
+
+
+DEFUN (fft, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} fft (@var{x})\n\
+@deftypefnx {Built-in Function} {} fft (@var{x}, @var{n})\n\
+@deftypefnx {Built-in Function} {} fft (@var{x}, @var{n}, @var{dim})\n\
+Compute the discrete Fourier transform of @var{A} using\n\
+a Fast Fourier Transform (FFT) algorithm.\n\
+\n\
+The FFT is calculated along the first non-singleton dimension of the\n\
+array.  Thus if @var{x} is a matrix, @code{fft (@var{x})} computes the\n\
+FFT for each column of @var{x}.\n\
+\n\
+If called with two arguments, @var{n} is expected to be an integer\n\
+specifying the number of elements of @var{x} to use, or an empty\n\
+matrix to specify that its value should be ignored.  If @var{n} is\n\
+larger than the dimension along which the FFT is calculated, then\n\
+@var{x} is resized and padded with zeros.  Otherwise, if @var{n} is\n\
+smaller than the dimension along which the FFT is calculated, then\n\
+@var{x} is truncated.\n\
+\n\
+If called with three arguments, @var{dim} is an integer specifying the\n\
+dimension of the matrix along which the FFT is performed\n\
+@seealso{ifft, fft2, fftn, fftw}\n\
+@end deftypefn")
+{
+  return do_fft (args, "fft", 0);
+}
+
+
+DEFUN (ifft, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} ifft (@var{x})\n\
+@deftypefnx {Built-in Function} {} ifft (@var{x}, @var{n})\n\
+@deftypefnx {Built-in Function} {} ifft (@var{x}, @var{n}, @var{dim})\n\
+Compute the inverse discrete Fourier transform of @var{A}\n\
+using a Fast Fourier Transform (FFT) algorithm.\n\
+\n\
+The inverse FFT is calculated along the first non-singleton dimension\n\
+of the array.  Thus if @var{x} is a matrix, @code{fft (@var{x})} computes\n\
+the inverse FFT for each column of @var{x}.\n\
+\n\
+If called with two arguments, @var{n} is expected to be an integer\n\
+specifying the number of elements of @var{x} to use, or an empty\n\
+matrix to specify that its value should be ignored.  If @var{n} is\n\
+larger than the dimension along which the inverse FFT is calculated, then\n\
+@var{x} is resized and padded with zeros.  Otherwise, if @var{n} is\n\
+smaller than the dimension along which the inverse FFT is calculated,\n\
+then @var{x} is truncated.\n\
+\n\
+If called with three arguments, @var{dim} is an integer specifying the\n\
+dimension of the matrix along which the inverse FFT is performed\n\
+@seealso{fft, ifft2, ifftn, fftw}\n\
+@end deftypefn")
+{
+  return do_fft (args, "ifft", 1);
+}
+
+/*
+%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+%%         Comalco Research and Technology
+%%         02 May 2000
+%!test
+%! N = 64;
+%! n = 4;
+%! t = 2*pi*(0:1:N-1)/N;
+%! s = cos (n*t);
+%! S = fft (s);
+%!
+%! answer = zeros (size (t));
+%! answer(n+1) = N/2;
+%! answer(N-n+1) = N/2;
+%!
+%! assert (S, answer, 4*N*eps);
+
+%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+%%         Comalco Research and Technology
+%%         02 May 2000
+%!test
+%! N = 64;
+%! n = 7;
+%! t = 2*pi*(0:1:N-1)/N;
+%! s = cos (n*t);
+%!
+%! S = zeros (size (t));
+%! S(n+1) = N/2;
+%! S(N-n+1) = N/2;
+%!
+%! assert (ifft (S), s, 4*N*eps);
+
+%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+%%         Comalco Research and Technology
+%%         02 May 2000
+%!test
+%! N = 64;
+%! n = 4;
+%! t = single (2*pi*(0:1:N-1)/N);
+%! s = cos (n*t);
+%! S = fft (s);
+%!
+%! answer = zeros (size (t), "single");
+%! answer(n+1) = N/2;
+%! answer(N-n+1) = N/2;
+%!
+%! assert (S, answer, 4*N*eps ("single"));
+
+%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+%%         Comalco Research and Technology
+%%         02 May 2000
+%!test
+%! N = 64;
+%! n = 7;
+%! t = 2*pi*(0:1:N-1)/N;
+%! s = cos (n*t);
+%!
+%! S = zeros (size (t), "single");
+%! S(n+1) = N/2;
+%! S(N-n+1) = N/2;
+%!
+%! assert (ifft (S), s, 4*N*eps ("single"));
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/fft2.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,294 @@
+/*
+
+Copyright (C) 1997-2012 David Bateman
+Copyright (C) 1996-1997 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "lo-mappers.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+// This function should be merged with Fifft.
+
+#if defined (HAVE_FFTW)
+#define FFTSRC "@sc{fftw}"
+#else
+#define FFTSRC "@sc{fftpack}"
+#endif
+
+static octave_value
+do_fft2 (const octave_value_list &args, const char *fcn, int type)
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 1 || nargin > 3)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value arg = args(0);
+  dim_vector dims = arg.dims ();
+  octave_idx_type n_rows = -1;
+
+  if (nargin > 1)
+    {
+      double dval = args(1).double_value ();
+      if (xisnan (dval))
+        error ("%s: number of rows (N) cannot be NaN", fcn);
+      else
+        {
+          n_rows = NINTbig (dval);
+          if (n_rows < 0)
+            error ("%s: number of rows (N) must be greater than zero", fcn);
+        }
+    }
+
+  if (error_state)
+    return retval;
+
+  octave_idx_type n_cols = -1;
+  if (nargin > 2)
+    {
+      double dval = args(2).double_value ();
+      if (xisnan (dval))
+        error ("%s: number of columns (M) cannot be NaN", fcn);
+      else
+        {
+          n_cols = NINTbig (dval);
+          if (n_cols < 0)
+            error ("%s: number of columns (M) must be greater than zero", fcn);
+        }
+    }
+
+  if (error_state)
+    return retval;
+
+  for (int i = 0; i < dims.length (); i++)
+    if (dims(i) < 0)
+      return retval;
+
+  if (n_rows < 0)
+    n_rows = dims (0);
+  else
+    dims (0) = n_rows;
+
+  if (n_cols < 0)
+    n_cols = dims (1);
+  else
+    dims (1) = n_cols;
+
+  if (dims.all_zero () || n_rows == 0 || n_cols == 0)
+    {
+      if (arg.is_single_type ())
+        return octave_value (FloatMatrix ());
+      else
+        return octave_value (Matrix ());
+    }
+
+  if (arg.is_single_type ())
+    {
+      if (arg.is_real_type ())
+        {
+          FloatNDArray nda = arg.float_array_value ();
+
+          if (! error_state)
+            {
+              nda.resize (dims, 0.0);
+              retval = (type != 0 ? nda.ifourier2d () : nda.fourier2d ());
+            }
+        }
+      else
+        {
+          FloatComplexNDArray cnda = arg.float_complex_array_value ();
+
+          if (! error_state)
+            {
+              cnda.resize (dims, 0.0);
+              retval = (type != 0 ? cnda.ifourier2d () : cnda.fourier2d ());
+            }
+        }
+    }
+  else
+    {
+      if (arg.is_real_type ())
+        {
+          NDArray nda = arg.array_value ();
+
+          if (! error_state)
+            {
+              nda.resize (dims, 0.0);
+              retval = (type != 0 ? nda.ifourier2d () : nda.fourier2d ());
+            }
+        }
+      else if (arg.is_complex_type ())
+        {
+          ComplexNDArray cnda = arg.complex_array_value ();
+
+          if (! error_state)
+            {
+              cnda.resize (dims, 0.0);
+              retval = (type != 0 ? cnda.ifourier2d () : cnda.fourier2d ());
+            }
+        }
+      else
+        {
+          gripe_wrong_type_arg (fcn, arg);
+        }
+    }
+
+  return retval;
+}
+
+DEFUN (fft2, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} fft2 (@var{A})\n\
+@deftypefnx {Built-in Function} {} fft2 (@var{A}, @var{m}, @var{n})\n\
+Compute the two-dimensional discrete Fourier transform of @var{A} using\n\
+a Fast Fourier Transform (FFT) algorithm.\n\
+\n\
+The optional arguments @var{m} and @var{n} may be used specify the\n\
+number of rows and columns of @var{A} to use.  If either of these is\n\
+larger than the size of @var{A}, @var{A} is resized and padded with\n\
+zeros.\n\
+\n\
+If @var{A} is a multi-dimensional matrix, each two-dimensional sub-matrix\n\
+of @var{A} is treated separately.\n\
+@seealso {ifft2, fft, fftn, fftw}\n\
+@end deftypefn")
+{
+  return do_fft2 (args, "fft2", 0);
+}
+
+
+DEFUN (ifft2, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} ifft2 (@var{A})\n\
+@deftypefnx {Built-in Function} {} ifft2 (@var{A}, @var{m}, @var{n})\n\
+Compute the inverse two-dimensional discrete Fourier transform of @var{A}\n\
+using a Fast Fourier Transform (FFT) algorithm.\n\
+\n\
+The optional arguments @var{m} and @var{n} may be used specify the\n\
+number of rows and columns of @var{A} to use.  If either of these is\n\
+larger than the size of @var{A}, @var{A} is resized and padded with\n\
+zeros.\n\
+\n\
+If @var{A} is a multi-dimensional matrix, each two-dimensional sub-matrix\n\
+of @var{A} is treated separately\n\
+@seealso {fft2, ifft, ifftn, fftw}\n\
+@end deftypefn")
+{
+  return do_fft2 (args, "ifft2", 1);
+}
+
+/*
+%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+%%         Comalco Research and Technology
+%%         02 May 2000
+%!test
+%! M = 16;
+%! N = 8;
+%!
+%! m = 5;
+%! n = 3;
+%!
+%! x = 2*pi*(0:1:M-1)/M;
+%! y = 2*pi*(0:1:N-1)/N;
+%! sx = cos (m*x);
+%! sy = sin (n*y);
+%! s = kron (sx',sy);
+%! S = fft2 (s);
+%! answer = kron (fft (sx)', fft (sy));
+%! assert (S, answer, 4*M*N*eps);
+
+%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+%%         Comalco Research and Technology
+%%         02 May 2000
+%!test
+%! M = 12;
+%! N = 7;
+%!
+%! m = 3;
+%! n = 2;
+%!
+%! x = 2*pi*(0:1:M-1)/M;
+%! y = 2*pi*(0:1:N-1)/N;
+%!
+%! sx = cos (m*x);
+%! sy = cos (n*y);
+%!
+%! S = kron (fft (sx)', fft (sy));
+%! answer = kron (sx', sy);
+%! s = ifft2 (S);
+%!
+%! assert (s, answer, 30*eps);
+
+
+%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+%%         Comalco Research and Technology
+%%         02 May 2000
+%!test
+%! M = 16;
+%! N = 8;
+%!
+%! m = 5;
+%! n = 3;
+%!
+%! x = 2*pi*(0:1:M-1)/M;
+%! y = 2*pi*(0:1:N-1)/N;
+%! sx = single (cos (m*x));
+%! sy = single (sin (n*y));
+%! s = kron (sx', sy);
+%! S = fft2 (s);
+%! answer = kron (fft (sx)', fft (sy));
+%! assert (S, answer, 4*M*N*eps ("single"));
+
+%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+%%         Comalco Research and Technology
+%%         02 May 2000
+%!test
+%! M = 12;
+%! N = 7;
+%!
+%! m = 3;
+%! n = 2;
+%!
+%! x = single (2*pi*(0:1:M-1)/M);
+%! y = single (2*pi*(0:1:N-1)/N);
+%!
+%! sx = cos (m*x);
+%! sy = cos (n*y);
+%!
+%! S = kron (fft (sx)', fft (sy));
+%! answer = kron (sx', sy);
+%! s = ifft2 (S);
+%!
+%! assert (s, answer, 30*eps ("single"));
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/fftn.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,188 @@
+/*
+
+Copyright (C) 2004-2012 David Bateman
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "lo-mappers.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+// This function should be merged with Fifft.
+
+#if defined (HAVE_FFTW)
+#define FFTSRC "@sc{fftw}"
+#else
+#define FFTSRC "@sc{fftpack}"
+#endif
+
+static octave_value
+do_fftn (const octave_value_list &args, const char *fcn, int type)
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 1 || nargin > 2)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value arg = args(0);
+  dim_vector dims = arg.dims ();
+
+  for (int i = 0; i < dims.length (); i++)
+    if (dims(i) < 0)
+      return retval;
+
+  if (nargin > 1)
+    {
+      Matrix val = args(1).matrix_value ();
+      if (val.rows () > val.columns ())
+        val = val.transpose ();
+
+      if (error_state || val.columns () != dims.length () || val.rows () != 1)
+        error ("%s: SIZE must be a vector of length dim", fcn);
+      else
+        {
+          for (int i = 0; i < dims.length (); i++)
+            {
+              if (xisnan (val(i,0)))
+                error ("%s: SIZE has invalid NaN entries", fcn);
+              else if (NINTbig (val(i,0)) < 0)
+                error ("%s: all dimensions in SIZE must be greater than zero", fcn);
+              else
+                {
+                  dims(i) = NINTbig(val(i,0));
+                }
+            }
+        }
+    }
+
+  if (error_state)
+    return retval;
+
+  if (dims.all_zero ())
+    {
+      if (arg.is_single_type ())
+        return octave_value (FloatMatrix ());
+      else
+        return octave_value (Matrix ());
+    }
+
+  if (arg.is_single_type ())
+    {
+      if (arg.is_real_type ())
+        {
+          FloatNDArray nda = arg.float_array_value ();
+
+          if (! error_state)
+            {
+              nda.resize (dims, 0.0);
+              retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ());
+            }
+        }
+      else
+        {
+          FloatComplexNDArray cnda = arg.float_complex_array_value ();
+
+          if (! error_state)
+            {
+              cnda.resize (dims, 0.0);
+              retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ());
+            }
+        }
+    }
+  else
+    {
+      if (arg.is_real_type ())
+        {
+          NDArray nda = arg.array_value ();
+
+          if (! error_state)
+            {
+              nda.resize (dims, 0.0);
+              retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ());
+            }
+        }
+      else if (arg.is_complex_type ())
+        {
+          ComplexNDArray cnda = arg.complex_array_value ();
+
+          if (! error_state)
+            {
+              cnda.resize (dims, 0.0);
+              retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ());
+            }
+        }
+      else
+        {
+          gripe_wrong_type_arg (fcn, arg);
+        }
+    }
+
+  return retval;
+}
+
+DEFUN (fftn, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} fftn (@var{A})\n\
+@deftypefnx {Built-in Function} {} fftn (@var{A}, @var{size})\n\
+Compute the N-dimensional discrete Fourier transform of @var{A} using\n\
+a Fast Fourier Transform (FFT) algorithm.\n\
+\n\
+The optional vector argument @var{size} may be used specify the\n\
+dimensions of the array to be used.  If an element of @var{size} is\n\
+smaller than the corresponding dimension of @var{A}, then the dimension of\n\
+@var{A} is truncated prior to performing the FFT@.  Otherwise, if an element\n\
+of @var{size} is larger than the corresponding dimension then @var{A}\n\
+is resized and padded with zeros.\n\
+@seealso{ifftn, fft, fft2, fftw}\n\
+@end deftypefn")
+{
+  return do_fftn (args, "fftn", 0);
+}
+
+DEFUN (ifftn, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} ifftn (@var{A})\n\
+@deftypefnx {Built-in Function} {} ifftn (@var{A}, @var{size})\n\
+Compute the inverse N-dimensional discrete Fourier transform of @var{A}\n\
+using a Fast Fourier Transform (FFT) algorithm.\n\
+\n\
+The optional vector argument @var{size} may be used specify the\n\
+dimensions of the array to be used.  If an element of @var{size} is\n\
+smaller than the corresponding dimension of @var{A}, then the dimension of\n\
+@var{A} is truncated prior to performing the inverse FFT@.  Otherwise, if an\n\
+element of @var{size} is larger than the corresponding dimension then @var{A}\n\
+is resized and padded with zeros.\n\
+@seealso{fftn, ifft, ifft2, fftw}\n\
+@end deftypefn")
+{
+  return do_fftn (args, "ifftn", 1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/filter.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,738 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+// Based on Tony Richardson's filter.m.
+//
+// Originally translated to C++ by KH (Kurt.Hornik@wu-wien.ac.at)
+// with help from Fritz Leisch and Andreas Weingessel on Oct 20, 1994.
+//
+// Rewritten to use templates to handle both real and complex cases by
+// jwe, Wed Nov  1 19:15:29 1995.
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "quit.h"
+
+#include "defun.h"
+#include "error.h"
+#include "oct-obj.h"
+
+#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL)
+extern MArray<double>
+filter (MArray<double>&, MArray<double>&, MArray<double>&, int dim);
+
+extern MArray<Complex>
+filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, int dim);
+
+extern MArray<float>
+filter (MArray<float>&, MArray<float>&, MArray<float>&, int dim);
+
+extern MArray<FloatComplex>
+filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&, int dim);
+#endif
+
+template <class T>
+MArray<T>
+filter (MArray<T>& b, MArray<T>& a, MArray<T>& x, MArray<T>& si,
+        int dim = 0)
+{
+  MArray<T> y;
+
+  octave_idx_type a_len  = a.length ();
+  octave_idx_type b_len  = b.length ();
+
+  octave_idx_type ab_len = a_len > b_len ? a_len : b_len;
+
+  // FIXME: The two lines below should be unecessary because
+  //        this template is called with a and b as column vectors
+  //        already.  However the a.resize line is currently (2011/04/26)
+  //        necessary to stop bug #33164.
+  b.resize (dim_vector (ab_len, 1), 0.0);
+  if (a_len > 1)
+    a.resize (dim_vector (ab_len, 1), 0.0);
+
+  T norm = a (0);
+
+  if (norm == static_cast<T>(0.0))
+    {
+      error ("filter: the first element of A must be non-zero");
+      return y;
+    }
+
+  dim_vector x_dims = x.dims ();
+  if (dim < 0 || dim > x_dims.length ())
+    {
+      error ("filter: DIM must be a valid dimension");
+      return y;
+    }
+
+  octave_idx_type x_len = x_dims(dim);
+
+  dim_vector si_dims = si.dims ();
+  octave_idx_type si_len = si_dims(0);
+
+  if (si_len != ab_len - 1)
+    {
+      error ("filter: first dimension of SI must be of length max (length (a), length (b)) - 1");
+      return y;
+    }
+
+  if (si_dims.length () != x_dims.length ())
+    {
+      error ("filter: dimensionality of SI and X must agree");
+      return y;
+    }
+
+  for (octave_idx_type i = 1; i < dim; i++)
+    {
+      if (si_dims(i) != x_dims(i-1))
+        {
+          error ("filter: dimensionality of SI and X must agree");
+          return y;
+        }
+    }
+  for (octave_idx_type i = dim+1; i < x_dims.length (); i++)
+    {
+      if (si_dims(i) != x_dims(i))
+        {
+          error ("filter: dimensionality of SI and X must agree");
+          return y;
+        }
+    }
+
+  if (x_len == 0)
+    return x;
+
+  if (norm != static_cast<T>(1.0))
+    {
+      a = a / norm;
+      b = b / norm;
+    }
+
+  if (a_len <= 1 && si_len <= 0)
+    return b(0) * x;
+
+  y.resize (x_dims, 0.0);
+
+  int x_stride = 1;
+  for (int i = 0; i < dim; i++)
+    x_stride *= x_dims(i);
+
+  octave_idx_type x_num = x_dims.numel () / x_len;
+  for (octave_idx_type num = 0; num < x_num; num++)
+    {
+      octave_idx_type x_offset;
+      if (x_stride == 1)
+        x_offset = num * x_len;
+      else
+        {
+          octave_idx_type x_offset2 = 0;
+          x_offset = num;
+          while (x_offset >= x_stride)
+            {
+              x_offset -= x_stride;
+              x_offset2++;
+            }
+          x_offset += x_offset2 * x_stride * x_len;
+        }
+      octave_idx_type si_offset = num * si_len;
+
+      if (a_len > 1)
+        {
+          T *py = y.fortran_vec ();
+          T *psi = si.fortran_vec ();
+
+          const T *pa = a.data ();
+          const T *pb = b.data ();
+          const T *px = x.data ();
+
+          psi += si_offset;
+
+          for (octave_idx_type i = 0, idx = x_offset; i < x_len; i++, idx += x_stride)
+            {
+              py[idx] = psi[0] + pb[0] * px[idx];
+
+              if (si_len > 0)
+                {
+                  for (octave_idx_type j = 0; j < si_len - 1; j++)
+                    {
+                      OCTAVE_QUIT;
+
+                      psi[j] = psi[j+1] - pa[j+1] * py[idx] + pb[j+1] * px[idx];
+                    }
+
+                  psi[si_len-1] = pb[si_len] * px[idx] - pa[si_len] * py[idx];
+                }
+              else
+                {
+                  OCTAVE_QUIT;
+
+                  psi[0] = pb[si_len] * px[idx] - pa[si_len] * py[idx];
+                }
+            }
+        }
+      else if (si_len > 0)
+        {
+          T *py = y.fortran_vec ();
+          T *psi = si.fortran_vec ();
+
+          const T *pb = b.data ();
+          const T *px = x.data ();
+
+          psi += si_offset;
+
+          for (octave_idx_type i = 0, idx = x_offset; i < x_len; i++, idx += x_stride)
+            {
+              py[idx] = psi[0] + pb[0] * px[idx];
+
+              if (si_len > 1)
+                {
+                  for (octave_idx_type j = 0; j < si_len - 1; j++)
+                    {
+                      OCTAVE_QUIT;
+
+                      psi[j] = psi[j+1] + pb[j+1] * px[idx];
+                    }
+
+                  psi[si_len-1] = pb[si_len] * px[idx];
+                }
+              else
+                {
+                  OCTAVE_QUIT;
+
+                  psi[0] = pb[1] * px[idx];
+                }
+            }
+        }
+    }
+
+  return y;
+}
+
+#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL)
+extern MArray<double>
+filter (MArray<double>&, MArray<double>&, MArray<double>&,
+        MArray<double>&, int dim);
+
+extern MArray<Complex>
+filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&,
+        MArray<Complex>&, int dim);
+
+extern MArray<float>
+filter (MArray<float>&, MArray<float>&, MArray<float>&,
+        MArray<float>&, int dim);
+
+extern MArray<FloatComplex>
+filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&,
+        MArray<FloatComplex>&, int dim);
+#endif
+
+template <class T>
+MArray<T>
+filter (MArray<T>& b, MArray<T>& a, MArray<T>& x, int dim = -1)
+{
+  dim_vector x_dims = x.dims ();
+
+  if (dim < 0)
+    {
+      // Find first non-singleton dimension
+      while (dim < x_dims.length () && x_dims(dim) <= 1)
+        dim++;
+
+      // All dimensions singleton, pick first dimension
+      if (dim == x_dims.length ())
+        dim = 0;
+    }
+  else
+    if (dim < 0 || dim > x_dims.length ())
+      {
+        error ("filter: DIM must be a valid dimension");
+        return MArray<T> ();
+      }
+
+  octave_idx_type a_len = a.length ();
+  octave_idx_type b_len = b.length ();
+
+  octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
+  dim_vector si_dims = x.dims ();
+  for (int i = dim; i > 0; i--)
+    si_dims(i) = si_dims(i-1);
+  si_dims(0) = si_len;
+
+  MArray<T> si (si_dims, T (0.0));
+
+  return filter (b, a, x, si, dim);
+}
+
+DEFUN (filter, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {y =} filter (@var{b}, @var{a}, @var{x})\n\
+@deftypefnx {Built-in Function} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, @var{si})\n\
+@deftypefnx {Built-in Function} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, [], @var{dim})\n\
+@deftypefnx {Built-in Function} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, @var{si}, @var{dim})\n\
+Return the solution to the following linear, time-invariant difference\n\
+equation:\n\
+@tex\n\
+$$\n\
+\\sum_{k=0}^N a_{k+1} y_{n-k} = \\sum_{k=0}^M b_{k+1} x_{n-k}, \\qquad\n\
+ 1 \\le n \\le P\n\
+$$\n\
+@end tex\n\
+@ifnottex\n\
+@c Set example in small font to prevent overfull line\n\
+\n\
+@smallexample\n\
+@group\n\
+ N                   M\n\
+SUM a(k+1) y(n-k) = SUM b(k+1) x(n-k)    for 1<=n<=length(x)\n\
+k=0                 k=0\n\
+@end group\n\
+@end smallexample\n\
+\n\
+@end ifnottex\n\
+\n\
+@noindent\n\
+where\n\
+@ifnottex\n\
+N=length(a)-1 and M=length(b)-1.\n\
+@end ifnottex\n\
+@tex\n\
+$a \\in \\Re^{N-1}$, $b \\in \\Re^{M-1}$, and $x \\in \\Re^P$.\n\
+@end tex\n\
+The result is calculated over the first non-singleton dimension of @var{x}\n\
+or over @var{dim} if supplied.\n\
+\n\
+An equivalent form of the equation is:\n\
+@tex\n\
+$$\n\
+y_n = -\\sum_{k=1}^N c_{k+1} y_{n-k} + \\sum_{k=0}^M d_{k+1} x_{n-k}, \\qquad\n\
+ 1 \\le n \\le P\n\
+$$\n\
+@end tex\n\
+@ifnottex\n\
+@c Set example in small font to prevent overfull line\n\
+\n\
+@smallexample\n\
+@group\n\
+          N                   M\n\
+y(n) = - SUM c(k+1) y(n-k) + SUM d(k+1) x(n-k)  for 1<=n<=length(x)\n\
+         k=1                 k=0\n\
+@end group\n\
+@end smallexample\n\
+\n\
+@end ifnottex\n\
+\n\
+@noindent\n\
+where\n\
+@ifnottex\n\
+ c = a/a(1) and d = b/a(1).\n\
+@end ifnottex\n\
+@tex\n\
+$c = a/a_1$ and $d = b/a_1$.\n\
+@end tex\n\
+\n\
+If the fourth argument @var{si} is provided, it is taken as the\n\
+initial state of the system and the final state is returned as\n\
+@var{sf}.  The state vector is a column vector whose length is\n\
+equal to the length of the longest coefficient vector minus one.\n\
+If @var{si} is not supplied, the initial state vector is set to all\n\
+zeros.\n\
+\n\
+In terms of the Z Transform, y is the result of passing the discrete-\n\
+time signal x through a system characterized by the following rational\n\
+system function:\n\
+@tex\n\
+$$\n\
+H(z) = {\\displaystyle\\sum_{k=0}^M d_{k+1} z^{-k}\n\
+        \\over 1 + \\displaystyle\\sum_{k+1}^N c_{k+1} z^{-k}}\n\
+$$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+@group\n\
+          M\n\
+         SUM d(k+1) z^(-k)\n\
+         k=0\n\
+H(z) = ---------------------\n\
+            N\n\
+       1 + SUM c(k+1) z^(-k)\n\
+           k=1\n\
+@end group\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+@seealso{filter2, fftfilt, freqz}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin  = args.length ();
+
+  if (nargin < 3 || nargin > 5)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  const char *errmsg = "filter: arguments a and b must be vectors";
+
+  int dim;
+  dim_vector x_dims = args(2).dims ();
+
+  if (nargin == 5)
+    {
+      dim = args(4).nint_value () - 1;
+      if (dim < 0 || dim >= x_dims.length ())
+        {
+          error ("filter: DIM must be a valid dimension");
+          return retval;
+        }
+    }
+  else
+    {
+      // Find first non-singleton dimension
+      dim = 0;
+      while (dim < x_dims.length () && x_dims(dim) <= 1)
+        dim++;
+
+      // All dimensions singleton, pick first dimension
+      if (dim == x_dims.length ())
+        dim = 0;
+    }
+
+  bool isfloat = (args(0).is_single_type ()
+                  || args(1).is_single_type ()
+                  || args(2).is_single_type ()
+                  || (nargin >= 4 && args(3).is_single_type ()));
+
+  if (args(0).is_complex_type ()
+      || args(1).is_complex_type ()
+      || args(2).is_complex_type ()
+      || (nargin >= 4 && args(3).is_complex_type ()))
+    {
+      if (isfloat)
+        {
+          FloatComplexColumnVector b (args(0).float_complex_vector_value ());
+          FloatComplexColumnVector a (args(1).float_complex_vector_value ());
+
+          FloatComplexNDArray x (args(2).float_complex_array_value ());
+
+          if (! error_state)
+            {
+              FloatComplexNDArray si;
+
+              if (nargin == 3 || args(3).is_empty ())
+                {
+                  octave_idx_type a_len = a.length ();
+                  octave_idx_type b_len = b.length ();
+
+                  octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
+
+                  dim_vector si_dims = x.dims ();
+                  for (int i = dim; i > 0; i--)
+                    si_dims(i) = si_dims(i-1);
+                  si_dims(0) = si_len;
+
+                  si.resize (si_dims, 0.0);
+                }
+              else
+                {
+                  si = args(3).float_complex_array_value ();
+
+                  if (si.is_vector () && x.is_vector ())
+                    si = si.reshape (dim_vector (si.numel (), 1));
+                }
+
+              if (! error_state)
+                {
+                  FloatComplexNDArray y (filter (b, a, x, si, dim));
+
+                  if (nargout == 2)
+                    retval(1) = si;
+
+                  retval(0) = y;
+                }
+              else
+                error (errmsg);
+            }
+          else
+            error (errmsg);
+        }
+      else
+        {
+          ComplexColumnVector b (args(0).complex_vector_value ());
+          ComplexColumnVector a (args(1).complex_vector_value ());
+
+          ComplexNDArray x (args(2).complex_array_value ());
+
+          if (! error_state)
+            {
+              ComplexNDArray si;
+
+              if (nargin == 3 || args(3).is_empty ())
+                {
+                  octave_idx_type a_len = a.length ();
+                  octave_idx_type b_len = b.length ();
+
+                  octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
+
+                  dim_vector si_dims = x.dims ();
+                  for (int i = dim; i > 0; i--)
+                    si_dims(i) = si_dims(i-1);
+                  si_dims(0) = si_len;
+
+                  si.resize (si_dims, 0.0);
+                }
+              else
+                {
+                  si = args(3).complex_array_value ();
+
+                  if (si.is_vector () && x.is_vector ())
+                    si = si.reshape (dim_vector (si.numel (), 1));
+                }
+
+              if (! error_state)
+                {
+                  ComplexNDArray y (filter (b, a, x, si, dim));
+
+                  if (nargout == 2)
+                    retval(1) = si;
+
+                  retval(0) = y;
+                }
+              else
+                error (errmsg);
+            }
+          else
+            error (errmsg);
+        }
+    }
+  else
+    {
+      if (isfloat)
+        {
+          FloatColumnVector b (args(0).float_vector_value ());
+          FloatColumnVector a (args(1).float_vector_value ());
+
+          FloatNDArray x (args(2).float_array_value ());
+
+          if (! error_state)
+            {
+              FloatNDArray si;
+
+              if (nargin == 3 || args(3).is_empty ())
+                {
+                  octave_idx_type a_len = a.length ();
+                  octave_idx_type b_len = b.length ();
+
+                  octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
+
+                  dim_vector si_dims = x.dims ();
+                  for (int i = dim; i > 0; i--)
+                    si_dims(i) = si_dims(i-1);
+                  si_dims(0) = si_len;
+
+                  si.resize (si_dims, 0.0);
+                }
+              else
+                {
+                  si = args(3).float_array_value ();
+
+                  if (si.is_vector () && x.is_vector ())
+                    si = si.reshape (dim_vector (si.numel (), 1));
+                }
+
+              if (! error_state)
+                {
+                  FloatNDArray y (filter (b, a, x, si, dim));
+
+                  if (nargout == 2)
+                    retval(1) = si;
+
+                  retval(0) = y;
+                }
+              else
+                error (errmsg);
+            }
+          else
+            error (errmsg);
+        }
+      else
+        {
+          ColumnVector b (args(0).vector_value ());
+          ColumnVector a (args(1).vector_value ());
+
+          NDArray x (args(2).array_value ());
+
+          if (! error_state)
+            {
+              NDArray si;
+
+              if (nargin == 3 || args(3).is_empty ())
+                {
+                  octave_idx_type a_len = a.length ();
+                  octave_idx_type b_len = b.length ();
+
+                  octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
+
+                  dim_vector si_dims = x.dims ();
+                  for (int i = dim; i > 0; i--)
+                    si_dims(i) = si_dims(i-1);
+                  si_dims(0) = si_len;
+
+                  si.resize (si_dims, 0.0);
+                }
+              else
+                {
+                  si = args(3).array_value ();
+
+                  if (si.is_vector () && x.is_vector ())
+                    si = si.reshape (dim_vector (si.numel (), 1));
+                }
+
+              if (! error_state)
+                {
+                  NDArray y (filter (b, a, x, si, dim));
+
+                  if (nargout == 2)
+                    retval(1) = si;
+
+                  retval(0) = y;
+                }
+              else
+                error (errmsg);
+            }
+          else
+            error (errmsg);
+        }
+    }
+
+  return retval;
+}
+
+template MArray<double>
+filter (MArray<double>&, MArray<double>&, MArray<double>&,
+        MArray<double>&, int dim);
+
+template MArray<double>
+filter (MArray<double>&, MArray<double>&, MArray<double>&, int dim);
+
+template MArray<Complex>
+filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&,
+        MArray<Complex>&, int dim);
+
+template MArray<Complex>
+filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, int dim);
+
+template MArray<float>
+filter (MArray<float>&, MArray<float>&, MArray<float>&,
+        MArray<float>&, int dim);
+
+template MArray<float>
+filter (MArray<float>&, MArray<float>&, MArray<float>&, int dim);
+
+template MArray<FloatComplex>
+filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&,
+        MArray<FloatComplex>&, int dim);
+
+template MArray<FloatComplex>
+filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&, int dim);
+
+/*
+%!shared a, b, x, r
+%!test
+%! a = [1 1];
+%! b = [1 1];
+%! x = zeros (1,10);  x(1) = 1;
+%! assert (filter (b,   [1], x  ), [1 1 0 0 0 0 0 0 0 0]);
+%! assert (filter (b,   [1], x.'), [1 1 0 0 0 0 0 0 0 0].');
+%! assert (filter (b.', [1], x  ), [1 1 0 0 0 0 0 0 0 0]  );
+%! assert (filter (b.', [1], x.'), [1 1 0 0 0 0 0 0 0 0].');
+%! assert (filter ([1], a,   x  ), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1]  );
+%! assert (filter ([1], a,   x.'), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1].');
+%! assert (filter ([1], a.', x  ), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1]  );
+%! assert (filter ([1], a.', x.'), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1].');
+%! assert (filter (b,   a,   x  ), [1 0 0 0 0 0 0 0 0 0]  );
+%! assert (filter (b.', a,   x  ), [1 0 0 0 0 0 0 0 0 0]  );
+%! assert (filter (b,   a.', x  ), [1 0 0 0 0 0 0 0 0 0]  );
+%! assert (filter (b.', a,   x  ), [1 0 0 0 0 0 0 0 0 0]  );
+%! assert (filter (b,   a,   x.'), [1 0 0 0 0 0 0 0 0 0].');
+%! assert (filter (b.', a,   x.'), [1 0 0 0 0 0 0 0 0 0].');
+%! assert (filter (b,   a.', x.'), [1 0 0 0 0 0 0 0 0 0].');
+%! assert (filter (b.', a,   x.'), [1 0 0 0 0 0 0 0 0 0].');
+
+%!test
+%! r = sqrt (1/2) * (1+i);
+%! a = a*r;
+%! b = b*r;
+%! assert (filter (b, [1], x   ), r*[1 1 0 0 0 0 0 0 0 0]   );
+%! assert (filter (b, [1], r*x ), r*r*[1 1 0 0 0 0 0 0 0 0] );
+%! assert (filter (b, [1], x.' ), r*[1 1 0 0 0 0 0 0 0 0].' );
+%! assert (filter (b, a,   x   ),   [1 0 0 0 0 0 0 0 0 0]   );
+%! assert (filter (b, a,   r*x ), r*[1 0 0 0 0 0 0 0 0 0]   );
+
+%!shared a, b, x, y, so
+%!test
+%! a = [1,1];
+%! b = [1,1];
+%! x = zeros (1,10);  x(1) = 1;
+%! [y, so] = filter (b, [1], x, [-1]);
+%! assert (y, [0 1 0 0 0 0 0 0 0 0]);
+%! assert (so, 0);
+
+%!test
+%! x  = zeros (10,3);  x(1,1) = -1;  x(1,2) = 1;
+%! y0 = zeros (10,3); y0(1:2,1) = -1;  y0(1:2,2) = 1;
+%! y = filter (b, [1], x);
+%! assert (y, y0);
+
+%!test
+%! a = [1,1];
+%! b=[1,1];
+%! x = zeros (4,4,2);  x(1,1:4,1) = +1;  x(1,1:4,2) = -1;
+%! y0 = zeros (4,4,2);  y0(1:2,1:4,1) = +1;  y0(1:2,1:4,2) = -1;
+%! y = filter (b, [1], x);
+%! assert (y, y0);
+
+%!assert (filter (1, ones (10,1) / 10, []), [])
+%!assert (filter (1, ones (10,1) / 10, zeros (0,10)), zeros (0,10))
+%!assert (filter (1, ones (10,1) / 10, single (1:5)), repmat (single (10), 1, 5))
+
+%% Test using initial conditions
+%!assert (filter ([1, 1, 1], [1, 1], [1 2], [1, 1]), [2 2])
+%!assert (filter ([1, 1, 1], [1, 1], [1 2], [1, 1]'), [2 2])
+%!assert (filter ([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]), [5 7; 6 10; 14 18])
+%!error (filter ([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]'))
+%!assert (filter ([1, 3, 2], [1], [1 2; 3 4; 5 6], [1 0 0; 1 0 0], 2), [2 6; 3 13; 5 21])
+
+## Test of DIM parameter
+%!test
+%! x = ones (2, 1, 3, 4);
+%! x(1,1,:,:) = [1 2 3 4; 5 6 7 8; 9 10 11 12];
+%! y0 = [1 1 6 2 15 3 2 1 8 2 18 3 3 1 10 2 21 3 4 1 12 2 24 3];
+%! y0 = reshape (y0, size (x));
+%! y = filter ([1 1 1], 1, x, [], 3);
+%! assert (y, y0);
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/find.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,621 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "quit.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+
+// Find at most N_TO_FIND nonzero elements in NDA.  Search forward if
+// DIRECTION is 1, backward if it is -1.  NARGOUT is the number of
+// output arguments.  If N_TO_FIND is -1, find all nonzero elements.
+
+template <typename T>
+octave_value_list
+find_nonzero_elem_idx (const Array<T>& nda, int nargout,
+                       octave_idx_type n_to_find, int direction)
+{
+  octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ());
+
+  Array<octave_idx_type> idx;
+  if (n_to_find >= 0)
+    idx = nda.find (n_to_find, direction == -1);
+  else
+    idx = nda.find ();
+
+  // The maximum element is always at the end.
+  octave_idx_type iext = idx.is_empty () ? 0 : idx.xelem (idx.numel () - 1) + 1;
+
+  switch (nargout)
+    {
+    default:
+    case 3:
+      retval(2) = Array<T> (nda.index (idx_vector (idx)));
+      // Fall through!
+
+    case 2:
+      {
+        Array<octave_idx_type> jdx (idx.dims ());
+        octave_idx_type n = idx.length (), nr = nda.rows ();
+        for (octave_idx_type i = 0; i < n; i++)
+          {
+            jdx.xelem (i) = idx.xelem (i) / nr;
+            idx.xelem (i) %= nr;
+          }
+        iext = -1;
+        retval(1) = idx_vector (jdx, -1);
+      }
+      // Fall through!
+
+    case 1:
+    case 0:
+      retval(0) = idx_vector (idx, iext);
+      break;
+    }
+
+  return retval;
+}
+
+template <typename T>
+octave_value_list
+find_nonzero_elem_idx (const Sparse<T>& v, int nargout,
+                       octave_idx_type n_to_find, int direction)
+{
+  octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ());
+
+
+  octave_idx_type nc = v.cols ();
+  octave_idx_type nr = v.rows ();
+  octave_idx_type nz = v.nnz ();
+
+  // Search in the default range.
+  octave_idx_type start_nc = -1;
+  octave_idx_type end_nc = -1;
+  octave_idx_type count;
+
+  // Search for the range to search
+  if (n_to_find < 0)
+    {
+      start_nc = 0;
+      end_nc = nc;
+      n_to_find = nz;
+      count = nz;
+    }
+  else if (direction > 0)
+    {
+      for (octave_idx_type j = 0; j < nc; j++)
+        {
+          OCTAVE_QUIT;
+          if (v.cidx (j) == 0 && v.cidx (j+1) != 0)
+            start_nc = j;
+          if (v.cidx (j+1) >= n_to_find)
+            {
+              end_nc = j + 1;
+              break;
+            }
+        }
+    }
+  else
+    {
+      for (octave_idx_type j = nc; j > 0; j--)
+        {
+          OCTAVE_QUIT;
+          if (v.cidx (j) == nz && v.cidx (j-1) != nz)
+            end_nc = j;
+          if (nz - v.cidx (j-1) >= n_to_find)
+            {
+              start_nc = j - 1;
+              break;
+            }
+        }
+    }
+
+  count = (n_to_find > v.cidx (end_nc) - v.cidx (start_nc) ?
+           v.cidx (end_nc) - v.cidx (start_nc) : n_to_find);
+
+  // If the original argument was a row vector, force a row vector of
+  // the overall indices to be returned.  But see below for scalar
+  // case...
+
+  octave_idx_type result_nr = count;
+  octave_idx_type result_nc = 1;
+
+  bool scalar_arg = false;
+
+  if (v.rows () == 1)
+    {
+      result_nr = 1;
+      result_nc = count;
+
+      scalar_arg = (v.columns () == 1);
+    }
+
+  Matrix idx (result_nr, result_nc);
+
+  Matrix i_idx (result_nr, result_nc);
+  Matrix j_idx (result_nr, result_nc);
+
+  Array<T> val (dim_vector (result_nr, result_nc));
+
+  if (count > 0)
+    {
+      // Search for elements to return.  Only search the region where
+      // there are elements to be found using the count that we want
+      // to find.
+      for (octave_idx_type j = start_nc, cx = 0; j < end_nc; j++)
+        for (octave_idx_type i = v.cidx (j); i < v.cidx (j+1); i++ )
+          {
+            OCTAVE_QUIT;
+            if (direction < 0 && i < nz - count)
+              continue;
+            i_idx(cx) = static_cast<double> (v.ridx (i) + 1);
+            j_idx(cx) = static_cast<double> (j + 1);
+            idx(cx) = j * nr + v.ridx (i) + 1;
+            val(cx) = v.data(i);
+            cx++;
+            if (cx == count)
+              break;
+          }
+    }
+  else if (scalar_arg)
+    {
+      idx.resize (0, 0);
+
+      i_idx.resize (0, 0);
+      j_idx.resize (0, 0);
+
+      val.resize (dim_vector (0, 0));
+    }
+
+  switch (nargout)
+    {
+    case 0:
+    case 1:
+      retval(0) = idx;
+      break;
+
+    case 5:
+      retval(4) = nc;
+      // Fall through
+
+    case 4:
+      retval(3) = nr;
+      // Fall through
+
+    case 3:
+      retval(2) = val;
+      // Fall through!
+
+    case 2:
+      retval(1) = j_idx;
+      retval(0) = i_idx;
+      break;
+
+    default:
+      panic_impossible ();
+      break;
+    }
+
+  return retval;
+}
+
+octave_value_list
+find_nonzero_elem_idx (const PermMatrix& v, int nargout,
+                       octave_idx_type n_to_find, int direction)
+{
+  // There are far fewer special cases to handle for a PermMatrix.
+  octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ());
+
+  octave_idx_type nc = v.cols ();
+  octave_idx_type start_nc, count;
+
+  // Determine the range to search.
+  if (n_to_find < 0 || n_to_find >= nc)
+    {
+      start_nc = 0;
+      n_to_find = nc;
+      count = nc;
+    }
+  else if (direction > 0)
+    {
+      start_nc = 0;
+      count = n_to_find;
+    }
+  else
+    {
+      start_nc = nc - n_to_find;
+      count = n_to_find;
+    }
+
+  bool scalar_arg = (v.rows () == 1 && v.cols () == 1);
+
+  Matrix idx (count, 1);
+  Matrix i_idx (count, 1);
+  Matrix j_idx (count, 1);
+  // Every value is 1.
+  Array<double> val (dim_vector (count, 1), 1.0);
+
+  if (count > 0)
+    {
+      const octave_idx_type* p = v.data ();
+      if (v.is_col_perm ())
+        {
+          for (octave_idx_type k = 0; k < count; k++)
+            {
+              OCTAVE_QUIT;
+              const octave_idx_type j = start_nc + k;
+              const octave_idx_type i = p[j];
+              i_idx(k) = static_cast<double> (1+i);
+              j_idx(k) = static_cast<double> (1+j);
+              idx(k) = j * nc + i + 1;
+            }
+        }
+      else
+        {
+          for (octave_idx_type k = 0; k < count; k++)
+            {
+              OCTAVE_QUIT;
+              const octave_idx_type i = start_nc + k;
+              const octave_idx_type j = p[i];
+              // Scatter into the index arrays according to
+              // j adjusted by the start point.
+              const octave_idx_type koff = j - start_nc;
+              i_idx(koff) = static_cast<double> (1+i);
+              j_idx(koff) = static_cast<double> (1+j);
+              idx(koff) = j * nc + i + 1;
+            }
+        }
+    }
+  else if (scalar_arg)
+    {
+      // Same odd compatibility case as the other overrides.
+      idx.resize (0, 0);
+      i_idx.resize (0, 0);
+      j_idx.resize (0, 0);
+      val.resize (dim_vector (0, 0));
+    }
+
+  switch (nargout)
+    {
+    case 0:
+    case 1:
+      retval(0) = idx;
+      break;
+
+    case 5:
+      retval(4) = nc;
+      // Fall through
+
+    case 4:
+      retval(3) = nc;
+      // Fall through
+
+    case 3:
+      retval(2) = val;
+      // Fall through!
+
+    case 2:
+      retval(1) = j_idx;
+      retval(0) = i_idx;
+      break;
+
+    default:
+      panic_impossible ();
+      break;
+    }
+
+  return retval;
+}
+
+DEFUN (find, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{idx} =} find (@var{x})\n\
+@deftypefnx {Built-in Function} {@var{idx} =} find (@var{x}, @var{n})\n\
+@deftypefnx {Built-in Function} {@var{idx} =} find (@var{x}, @var{n}, @var{direction})\n\
+@deftypefnx {Built-in Function} {[i, j] =} find (@dots{})\n\
+@deftypefnx {Built-in Function} {[i, j, v] =} find (@dots{})\n\
+Return a vector of indices of nonzero elements of a matrix, as a row if\n\
+@var{x} is a row vector or as a column otherwise.  To obtain a single index\n\
+for each matrix element, Octave pretends that the columns of a matrix form\n\
+one long vector (like Fortran arrays are stored).  For example:\n\
+\n\
+@example\n\
+@group\n\
+find (eye (2))\n\
+  @result{} [ 1; 4 ]\n\
+@end group\n\
+@end example\n\
+\n\
+If two outputs are requested, @code{find} returns the row and column\n\
+indices of nonzero elements of a matrix.  For example:\n\
+\n\
+@example\n\
+@group\n\
+[i, j] = find (2 * eye (2))\n\
+    @result{} i = [ 1; 2 ]\n\
+    @result{} j = [ 1; 2 ]\n\
+@end group\n\
+@end example\n\
+\n\
+If three outputs are requested, @code{find} also returns a vector\n\
+containing the nonzero values.  For example:\n\
+\n\
+@example\n\
+@group\n\
+[i, j, v] = find (3 * eye (2))\n\
+       @result{} i = [ 1; 2 ]\n\
+       @result{} j = [ 1; 2 ]\n\
+       @result{} v = [ 3; 3 ]\n\
+@end group\n\
+@end example\n\
+\n\
+If two inputs are given, @var{n} indicates the maximum number of\n\
+elements to find from the beginning of the matrix or vector.\n\
+\n\
+If three inputs are given, @var{direction} should be one of \"first\" or\n\
+\"last\", requesting only the first or last @var{n} indices, respectively.\n\
+However, the indices are always returned in ascending order.\n\
+\n\
+Note that this function is particularly useful for sparse matrices, as\n\
+it extracts the non-zero elements as vectors, which can then be used to\n\
+create the original matrix.  For example:\n\
+\n\
+@example\n\
+@group\n\
+sz = size (a);\n\
+[i, j, v] = find (a);\n\
+b = sparse (i, j, v, sz(1), sz(2));\n\
+@end group\n\
+@end example\n\
+@seealso{nonzeros}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin > 3 || nargin < 1)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  // Setup the default options.
+  octave_idx_type n_to_find = -1;
+  if (nargin > 1)
+    {
+      double val = args(1).scalar_value ();
+
+      if (error_state || (val < 0 || (! xisinf (val) && val != xround (val))))
+        {
+          error ("find: N must be a non-negative integer");
+          return retval;
+        }
+      else if (! xisinf (val))
+        n_to_find = val;
+    }
+
+  // Direction to do the searching (1 == forward, -1 == reverse).
+  int direction = 1;
+  if (nargin > 2)
+    {
+      direction = 0;
+
+      std::string s_arg = args(2).string_value ();
+
+      if (! error_state)
+        {
+          if (s_arg == "first")
+            direction = 1;
+          else if (s_arg == "last")
+            direction = -1;
+        }
+
+      if (direction == 0)
+        {
+          error ("find: DIRECTION must be \"first\" or \"last\"");
+          return retval;
+        }
+    }
+
+  octave_value arg = args(0);
+
+  if (arg.is_bool_type ())
+    {
+      if (arg.is_sparse_type ())
+        {
+          SparseBoolMatrix v = arg.sparse_bool_matrix_value ();
+
+          if (! error_state)
+            retval = find_nonzero_elem_idx (v, nargout,
+                                            n_to_find, direction);
+        }
+      else if (nargout <= 1 && n_to_find == -1 && direction == 1)
+        {
+          // This case is equivalent to extracting indices from a logical
+          // matrix. Try to reuse the possibly cached index vector.
+          retval(0) = arg.index_vector ().unmask ();
+        }
+      else
+        {
+          boolNDArray v = arg.bool_array_value ();
+
+          if (! error_state)
+            retval = find_nonzero_elem_idx (v, nargout,
+                                            n_to_find, direction);
+        }
+    }
+  else if (arg.is_integer_type ())
+    {
+#define DO_INT_BRANCH(INTT) \
+      else if (arg.is_ ## INTT ## _type ()) \
+        { \
+          INTT ## NDArray v = arg.INTT ## _array_value (); \
+          \
+          if (! error_state) \
+            retval = find_nonzero_elem_idx (v, nargout, \
+                                            n_to_find, direction);\
+        }
+
+      if (false)
+        ;
+      DO_INT_BRANCH (int8)
+      DO_INT_BRANCH (int16)
+      DO_INT_BRANCH (int32)
+      DO_INT_BRANCH (int64)
+      DO_INT_BRANCH (uint8)
+      DO_INT_BRANCH (uint16)
+      DO_INT_BRANCH (uint32)
+      DO_INT_BRANCH (uint64)
+      else
+        panic_impossible ();
+    }
+  else if (arg.is_sparse_type ())
+    {
+      if (arg.is_real_type ())
+        {
+          SparseMatrix v = arg.sparse_matrix_value ();
+
+          if (! error_state)
+            retval = find_nonzero_elem_idx (v, nargout,
+                                            n_to_find, direction);
+        }
+      else if (arg.is_complex_type ())
+        {
+          SparseComplexMatrix v = arg.sparse_complex_matrix_value ();
+
+          if (! error_state)
+            retval = find_nonzero_elem_idx (v, nargout,
+                                            n_to_find, direction);
+        }
+      else
+        gripe_wrong_type_arg ("find", arg);
+    }
+  else if (arg.is_perm_matrix ())
+    {
+      PermMatrix P = arg.perm_matrix_value ();
+
+      if (! error_state)
+        retval = find_nonzero_elem_idx (P, nargout, n_to_find, direction);
+    }
+  else if (arg.is_string ())
+    {
+      charNDArray chnda = arg.char_array_value ();
+
+      if (! error_state)
+        retval = find_nonzero_elem_idx (chnda, nargout, n_to_find, direction);
+    }
+  else if (arg.is_single_type ())
+    {
+      if (arg.is_real_type ())
+        {
+          FloatNDArray nda = arg.float_array_value ();
+
+          if (! error_state)
+            retval = find_nonzero_elem_idx (nda, nargout, n_to_find,
+                                            direction);
+        }
+      else if (arg.is_complex_type ())
+        {
+          FloatComplexNDArray cnda = arg.float_complex_array_value ();
+
+          if (! error_state)
+            retval = find_nonzero_elem_idx (cnda, nargout, n_to_find,
+                                            direction);
+        }
+    }
+  else if (arg.is_real_type ())
+    {
+      NDArray nda = arg.array_value ();
+
+      if (! error_state)
+        retval = find_nonzero_elem_idx (nda, nargout, n_to_find, direction);
+    }
+  else if (arg.is_complex_type ())
+    {
+      ComplexNDArray cnda = arg.complex_array_value ();
+
+      if (! error_state)
+        retval = find_nonzero_elem_idx (cnda, nargout, n_to_find, direction);
+    }
+  else
+    gripe_wrong_type_arg ("find", arg);
+
+  return retval;
+}
+
+/*
+%!assert (find (char ([0, 97])), 2)
+%!assert (find ([1, 0, 1, 0, 1]), [1, 3, 5])
+%!assert (find ([1; 0; 3; 0; 1]), [1; 3; 5])
+%!assert (find ([0, 0, 2; 0, 3, 0; -1, 0, 0]), [3; 5; 7])
+
+%!test
+%! [i, j, v] = find ([0, 0, 2; 0, 3, 0; -1, 0, 0]);
+%!
+%! assert (i, [3; 2; 1]);
+%! assert (j, [1; 2; 3]);
+%! assert (v, [-1; 3; 2]);
+
+%!assert (find (single ([1, 0, 1, 0, 1])), [1, 3, 5])
+%!assert (find (single ([1; 0; 3; 0; 1])), [1; 3; 5])
+%!assert (find (single ([0, 0, 2; 0, 3, 0; -1, 0, 0])), [3; 5; 7])
+
+%!test
+%! [i, j, v] = find (single ([0, 0, 2; 0, 3, 0; -1, 0, 0]));
+%!
+%! assert (i, [3; 2; 1]);
+%! assert (j, [1; 2; 3]);
+%! assert (v, single ([-1; 3; 2]));
+
+%!test
+%! pcol = [5 1 4 3 2];
+%! P = eye (5) (:, pcol);
+%! [i, j, v] = find (P);
+%! [ifull, jfull, vfull] = find (full (P));
+%! assert (i, ifull);
+%! assert (j, jfull);
+%! assert (all (v == 1));
+
+%!test
+%! prow = [5 1 4 3 2];
+%! P = eye (5) (prow, :);
+%! [i, j, v] = find (P);
+%! [ifull, jfull, vfull] = find (full (P));
+%! assert (i, ifull);
+%! assert (j, jfull);
+%! assert (all (v == 1));
+
+%!assert (find ([2 0 1 0 5 0], 1), 1)
+%!assert (find ([2 0 1 0 5 0], 2, "last"), [3, 5])
+
+%!assert (find ([2 0 1 0 5 0], Inf), [1, 3, 5])
+%!assert (find ([2 0 1 0 5 0], Inf, "last"), [1, 3, 5])
+
+%!error find ()
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/gammainc.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,230 @@
+/*
+
+Copyright (C) 1997-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "lo-specfun.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+DEFUN (gammainc, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Mapping Function} {} gammainc (@var{x}, @var{a})\n\
+@deftypefnx {Mapping Function} {} gammainc (@var{x}, @var{a}, \"lower\")\n\
+@deftypefnx {Mapping Function} {} gammainc (@var{x}, @var{a}, \"upper\")\n\
+Compute the normalized incomplete gamma function,\n\
+@tex\n\
+$$\n\
+ \\gamma (x, a) = {1 \\over {\\Gamma (a)}}\\displaystyle{\\int_0^x t^{a-1} e^{-t} dt}\n\
+$$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+@group\n\
+                                x\n\
+                       1       /\n\
+gammainc (x, a) = ---------    | exp (-t) t^(a-1) dt\n\
+                  gamma (a)    /\n\
+                            t=0\n\
+@end group\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+with the limiting value of 1 as @var{x} approaches infinity.\n\
+The standard notation is @math{P(a,x)}, e.g., Abramowitz and Stegun (6.5.1).\n\
+\n\
+If @var{a} is scalar, then @code{gammainc (@var{x}, @var{a})} is returned\n\
+for each element of @var{x} and vice versa.\n\
+\n\
+If neither @var{x} nor @var{a} is scalar, the sizes of @var{x} and\n\
+@var{a} must agree, and @code{gammainc} is applied element-by-element.\n\
+\n\
+By default the incomplete gamma function integrated from 0 to @var{x} is\n\
+computed.  If \"upper\" is given then the complementary function integrated\n\
+from @var{x} to infinity is calculated.  It should be noted that\n\
+\n\
+@example\n\
+gammainc (@var{x}, @var{a}) @equiv{} 1 - gammainc (@var{x}, @var{a}, \"upper\")\n\
+@end example\n\
+@seealso{gamma, lgamma}\n\
+@end deftypefn")
+{
+  octave_value retval;
+  bool lower = true;
+
+  int nargin = args.length ();
+
+  if (nargin == 3)
+    {
+      if (args(2).is_string ())
+        {
+          std::string s = args(2).string_value ();
+          std::transform (s.begin (), s.end (), s.begin (), tolower);
+          if (s == "upper")
+            lower = false;
+          else if (s != "lower")
+            error ("gammainc: third argument must be \"lower\" or \"upper\"");
+        }
+      else
+        error ("gammainc: third argument must be \"lower\" or \"upper\"");
+
+    }
+
+  if (!error_state && nargin >= 2  && nargin <= 3)
+    {
+      octave_value x_arg = args(0);
+      octave_value a_arg = args(1);
+
+      // FIXME Can we make a template version of the duplicated code below
+      if (x_arg.is_single_type () || a_arg.is_single_type ())
+        {
+          if (x_arg.is_scalar_type ())
+            {
+              float x = x_arg.float_value ();
+
+              if (! error_state)
+                {
+                  if (a_arg.is_scalar_type ())
+                    {
+                      float a = a_arg.float_value ();
+
+                      if (! error_state)
+                        retval = lower ? gammainc (x, a)
+                          : static_cast<float>(1) - gammainc (x, a);
+                    }
+                  else
+                    {
+                      FloatNDArray a = a_arg.float_array_value ();
+
+                      if (! error_state)
+                        retval = lower ? gammainc (x, a)
+                          : static_cast<float>(1) - gammainc (x, a);
+                    }
+                }
+            }
+          else
+            {
+              FloatNDArray x = x_arg.float_array_value ();
+
+              if (! error_state)
+                {
+                  if (a_arg.is_scalar_type ())
+                    {
+                      float a = a_arg.float_value ();
+
+                      if (! error_state)
+                        retval = lower ? gammainc (x, a)
+                          : static_cast<float>(1) - gammainc (x, a);
+                    }
+                  else
+                    {
+                      FloatNDArray a = a_arg.float_array_value ();
+
+                      if (! error_state)
+                        retval = lower ? gammainc (x, a)
+                          : static_cast<float>(1) - gammainc (x, a);
+                    }
+                }
+            }
+        }
+      else
+        {
+          if (x_arg.is_scalar_type ())
+            {
+              double x = x_arg.double_value ();
+
+              if (! error_state)
+                {
+                  if (a_arg.is_scalar_type ())
+                    {
+                      double a = a_arg.double_value ();
+
+                      if (! error_state)
+                        retval = lower ? gammainc (x, a) : 1. - gammainc (x, a);
+                    }
+                  else
+                    {
+                      NDArray a = a_arg.array_value ();
+
+                      if (! error_state)
+                        retval = lower ? gammainc (x, a) : 1. - gammainc (x, a);
+                    }
+                }
+            }
+          else
+            {
+              NDArray x = x_arg.array_value ();
+
+              if (! error_state)
+                {
+                  if (a_arg.is_scalar_type ())
+                    {
+                      double a = a_arg.double_value ();
+
+                      if (! error_state)
+                        retval = lower ? gammainc (x, a) : 1. - gammainc (x, a);
+                    }
+                  else
+                    {
+                      NDArray a = a_arg.array_value ();
+
+                      if (! error_state)
+                        retval = lower ? gammainc (x, a) : 1. - gammainc (x, a);
+                    }
+                }
+            }
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!test
+%! a = [.5 .5 .5 .5 .5];
+%! x = [0 1 2 3 4];
+%! v1 = sqrt (pi)*erf (x)./gamma (a);
+%! v3 = gammainc (x.*x, a);
+%! assert (v1, v3, sqrt (eps));
+
+%!assert (gammainc (0:4,0.5, "upper"), 1-gammainc (0:4,0.5), 1e-10)
+
+%!test
+%! a = single ([.5 .5 .5 .5 .5]);
+%! x = single ([0 1 2 3 4]);
+%! v1 = sqrt (pi ("single"))*erf (x)./gamma (a);
+%! v3 = gammainc (x.*x, a);
+%! assert (v1, v3, sqrt (eps ("single")));
+
+%!assert (gammainc (single (0:4), single (0.5), "upper"), 
+%!        single (1)-gammainc (single (0:4), single (0.5)),
+%!        single (1e-7))
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/gcd.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,528 @@
+/*
+
+Copyright (C) 2004-2012 David Bateman
+Copyright (C) 2010 Jaroslav Hajek, Jordi Gutiérrez Hermoso
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "dNDArray.h"
+#include "CNDArray.h"
+#include "fNDArray.h"
+#include "fCNDArray.h"
+#include "lo-mappers.h"
+#include "oct-binmap.h"
+
+#include "defun.h"
+#include "error.h"
+#include "oct-obj.h"
+
+static double
+simple_gcd (double a, double b)
+{
+  if (! xisinteger (a) || ! xisinteger (b))
+    (*current_liboctave_error_handler)
+      ("gcd: all values must be integers");
+
+  double aa = fabs (a);
+  double bb = fabs (b);
+
+  while (bb != 0)
+    {
+      double tt = fmod (aa, bb);
+      aa = bb;
+      bb = tt;
+    }
+
+  return aa;
+}
+
+// Don't use the Complex and FloatComplex typedefs because we need to
+// refer to the actual float precision FP in the body (and when gcc
+// implements template aliases from C++0x, can do a small fix here).
+template <typename FP>
+static void
+divide (const std::complex<FP>& a, const std::complex<FP>& b,
+        std::complex<FP>& q, std::complex<FP>& r)
+{
+  FP qr = gnulib::floor ((a/b).real () + 0.5);
+  FP qi = gnulib::floor ((a/b).imag () + 0.5);
+
+  q = std::complex<FP> (qr, qi);
+
+  r = a - q*b;
+}
+
+template <typename FP>
+static std::complex<FP>
+simple_gcd (const std::complex<FP>& a, const std::complex<FP>& b)
+{
+  if (! xisinteger (a.real ()) || ! xisinteger (a.imag ())
+      || ! xisinteger (b.real ()) || ! xisinteger (b.imag ()))
+    (*current_liboctave_error_handler)
+      ("gcd: all complex parts must be integers");
+
+  std::complex<FP> aa = a;
+  std::complex<FP> bb = b;
+
+  if (abs (aa) < abs (bb))
+    std::swap (aa, bb);
+
+  while (abs (bb) != 0)
+    {
+      std::complex<FP> qq, rr;
+      divide (aa, bb, qq, rr);
+      aa = bb;
+      bb = rr;
+    }
+
+  return aa;
+}
+
+template <class T>
+static octave_int<T>
+simple_gcd (const octave_int<T>& a, const octave_int<T>& b)
+{
+  T aa = a.abs ().value ();
+  T bb = b.abs ().value ();
+
+  while (bb != 0)
+    {
+      T tt = aa % bb;
+      aa = bb;
+      bb = tt;
+    }
+
+  return aa;
+}
+
+static double
+extended_gcd (double a, double b, double& x, double& y)
+{
+  if (! xisinteger (a) || ! xisinteger (b))
+    (*current_liboctave_error_handler)
+      ("gcd: all values must be integers");
+
+  double aa = fabs (a);
+  double bb = fabs (b);
+
+  double xx = 0, yy = 1;
+  double lx = 1, ly = 0;
+
+  while (bb != 0)
+    {
+      double qq = gnulib::floor (aa / bb);
+      double tt = fmod (aa, bb);
+
+      aa = bb;
+      bb = tt;
+
+      double tx = lx - qq*xx;
+      lx = xx;
+      xx = tx;
+
+      double ty = ly - qq*yy;
+      ly = yy;
+      yy = ty;
+    }
+
+  x = a >= 0 ? lx : -lx;
+  y = b >= 0 ? ly : -ly;
+
+  return aa;
+}
+
+template <typename FP>
+static std::complex<FP>
+extended_gcd (const std::complex<FP>& a, const std::complex<FP>& b,
+              std::complex<FP>& x, std::complex<FP>& y)
+{
+  if (! xisinteger (a.real ()) || ! xisinteger (a.imag ())
+      || ! xisinteger (b.real ()) || ! xisinteger (b.imag ()))
+    (*current_liboctave_error_handler)
+      ("gcd: all complex parts must be integers");
+
+  std::complex<FP> aa = a, bb = b;
+  bool swapped = false;
+  if (abs (aa) < abs (bb))
+    {
+      std::swap (aa, bb);
+      swapped = true;
+    }
+
+  std::complex<FP> xx = 0, lx = 1;
+  std::complex<FP> yy = 1, ly = 0;
+
+  while (abs(bb) != 0)
+    {
+      std::complex<FP> qq, rr;
+      divide (aa, bb, qq, rr);
+      aa = bb;
+      bb = rr;
+
+      std::complex<FP> tx = lx - qq*xx;
+      lx = xx;
+      xx = tx;
+
+      std::complex<FP> ty = ly - qq*yy;
+      ly = yy;
+      yy = ty;
+    }
+
+  x = lx;
+  y = ly;
+
+  if (swapped)
+    std::swap (x, y);
+
+  return aa;
+}
+
+template <class T>
+static octave_int<T>
+extended_gcd (const octave_int<T>& a, const octave_int<T>& b,
+              octave_int<T>& x, octave_int<T>& y)
+{
+  T aa = a.abs ().value ();
+  T bb = b.abs ().value ();
+  T xx = 0, lx = 1;
+  T yy = 1, ly = 0;
+
+  while (bb != 0)
+    {
+      T qq = aa / bb;
+      T tt = aa % bb;
+      aa = bb;
+      bb = tt;
+
+      T tx = lx - qq*xx;
+      lx = xx;
+      xx = tx;
+
+      T ty = ly - qq*yy;
+      ly = yy;
+      yy = ty;
+    }
+
+  x = octave_int<T> (lx) * a.signum ();
+  y = octave_int<T> (ly) * b.signum ();
+
+  return aa;
+}
+
+template<class NDA>
+static octave_value
+do_simple_gcd (const octave_value& a, const octave_value& b)
+{
+  typedef typename NDA::element_type T;
+  octave_value retval;
+
+  if (a.is_scalar_type () && b.is_scalar_type ())
+    {
+      // Optimize scalar case.
+      T aa = octave_value_extract<T> (a);
+      T bb = octave_value_extract<T> (b);
+      retval = simple_gcd (aa, bb);
+    }
+  else
+    {
+      NDA aa = octave_value_extract<NDA> (a);
+      NDA bb = octave_value_extract<NDA> (b);
+      retval = binmap<T> (aa, bb, simple_gcd, "gcd");
+    }
+
+  return retval;
+}
+
+// Dispatcher
+static octave_value
+do_simple_gcd (const octave_value& a, const octave_value& b)
+{
+  octave_value retval;
+  builtin_type_t btyp = btyp_mixed_numeric (a.builtin_type (),
+                                            b.builtin_type ());
+  switch (btyp)
+    {
+    case btyp_double:
+      if (a.is_sparse_type () && b.is_sparse_type ())
+        {
+          retval = do_simple_gcd<SparseMatrix> (a, b);
+          break;
+        }
+      // fall through!
+
+    case btyp_float:
+      retval = do_simple_gcd<NDArray> (a, b);
+      break;
+
+#define MAKE_INT_BRANCH(X) \
+    case btyp_ ## X: \
+      retval = do_simple_gcd<X ## NDArray> (a, b); \
+      break
+
+    MAKE_INT_BRANCH (int8);
+    MAKE_INT_BRANCH (int16);
+    MAKE_INT_BRANCH (int32);
+    MAKE_INT_BRANCH (int64);
+    MAKE_INT_BRANCH (uint8);
+    MAKE_INT_BRANCH (uint16);
+    MAKE_INT_BRANCH (uint32);
+    MAKE_INT_BRANCH (uint64);
+
+#undef MAKE_INT_BRANCH
+
+    case btyp_complex:
+      retval = do_simple_gcd<ComplexNDArray> (a, b);
+      break;
+
+    case btyp_float_complex:
+      retval = do_simple_gcd<FloatComplexNDArray> (a, b);
+      break;
+
+    default:
+      error ("gcd: invalid class combination for gcd: %s and %s\n",
+             a.class_name ().c_str (), b.class_name ().c_str ());
+    }
+
+  if (btyp == btyp_float)
+    retval = retval.float_array_value ();
+
+  return retval;
+}
+
+template<class NDA>
+static octave_value
+do_extended_gcd (const octave_value& a, const octave_value& b,
+                 octave_value& x, octave_value& y)
+{
+  typedef typename NDA::element_type T;
+  octave_value retval;
+
+  if (a.is_scalar_type () && b.is_scalar_type ())
+    {
+      // Optimize scalar case.
+      T aa = octave_value_extract<T> (a);
+      T bb = octave_value_extract<T> (b);
+      T xx, yy;
+      retval = extended_gcd (aa, bb, xx, yy);
+      x = xx;
+      y = yy;
+    }
+  else
+    {
+      NDA aa = octave_value_extract<NDA> (a);
+      NDA bb = octave_value_extract<NDA> (b);
+
+      dim_vector dv = aa.dims ();
+      if (aa.numel () == 1)
+        dv = bb.dims ();
+      else if (bb.numel () != 1 && bb.dims () != dv)
+        gripe_nonconformant ("gcd", a.dims (), b.dims ());
+
+      NDA gg (dv), xx (dv), yy (dv);
+
+      const T *aptr = aa.fortran_vec ();
+      const T *bptr = bb.fortran_vec ();
+
+      bool inca = aa.numel () != 1;
+      bool incb = bb.numel () != 1;
+
+      T *gptr = gg.fortran_vec ();
+      T *xptr = xx.fortran_vec (), *yptr = yy.fortran_vec ();
+
+      octave_idx_type n = gg.numel ();
+      for (octave_idx_type i = 0; i < n; i++)
+        {
+          octave_quit ();
+
+          *gptr++ = extended_gcd (*aptr, *bptr, *xptr++, *yptr++);
+
+          aptr += inca;
+          bptr += incb;
+        }
+
+      x = xx;
+      y = yy;
+
+      retval = gg;
+    }
+
+  return retval;
+}
+
+// Dispatcher
+static octave_value
+do_extended_gcd (const octave_value& a, const octave_value& b,
+                 octave_value& x, octave_value& y)
+{
+  octave_value retval;
+
+  builtin_type_t btyp = btyp_mixed_numeric (a.builtin_type (),
+                                            b.builtin_type ());
+  switch (btyp)
+    {
+    case btyp_double:
+    case btyp_float:
+      retval = do_extended_gcd<NDArray> (a, b, x, y);
+      break;
+
+#define MAKE_INT_BRANCH(X) \
+    case btyp_ ## X: \
+      retval = do_extended_gcd<X ## NDArray> (a, b, x, y); \
+      break
+
+    MAKE_INT_BRANCH (int8);
+    MAKE_INT_BRANCH (int16);
+    MAKE_INT_BRANCH (int32);
+    MAKE_INT_BRANCH (int64);
+    MAKE_INT_BRANCH (uint8);
+    MAKE_INT_BRANCH (uint16);
+    MAKE_INT_BRANCH (uint32);
+    MAKE_INT_BRANCH (uint64);
+
+#undef MAKE_INT_BRANCH
+
+    case btyp_complex:
+      retval = do_extended_gcd<ComplexNDArray> (a, b, x, y);
+      break;
+
+    case btyp_float_complex:
+      retval = do_extended_gcd<FloatComplexNDArray> (a, b, x, y);
+      break;
+
+    default:
+      error ("gcd: invalid class combination for gcd: %s and %s\n",
+             a.class_name ().c_str (), b.class_name ().c_str ());
+    }
+
+  // For consistency.
+  if (! error_state && a.is_sparse_type () && b.is_sparse_type ())
+    {
+      retval = retval.sparse_matrix_value ();
+      x = x.sparse_matrix_value ();
+      y = y.sparse_matrix_value ();
+    }
+
+  if (btyp == btyp_float)
+    {
+      retval = retval.float_array_value ();
+      x = x.float_array_value ();
+      y = y.float_array_value ();
+    }
+
+  return retval;
+}
+
+DEFUN (gcd, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{g} =} gcd (@var{a1}, @var{a2}, @dots{})\n\
+@deftypefnx {Built-in Function} {[@var{g}, @var{v1}, @dots{}] =} gcd (@var{a1}, @var{a2}, @dots{})\n\
+\n\
+Compute the greatest common divisor of @var{a1}, @var{a2}, @dots{}.  If more\n\
+than one argument is given all arguments must be the same size or scalar.\n\
+In this case the greatest common divisor is calculated for each element\n\
+individually.  All elements must be ordinary or Gaussian (complex)\n\
+integers.  Note that for Gaussian integers, the gcd is not unique up to\n\
+units (multiplication by 1, -1, @var{i} or -@var{i}), so an arbitrary\n\
+greatest common divisor amongst four possible is returned.\n\
+\n\
+Example code:\n\
+\n\
+@example\n\
+@group\n\
+gcd ([15, 9], [20, 18])\n\
+   @result{}  5  9\n\
+@end group\n\
+@end example\n\
+\n\
+Optional return arguments @var{v1}, etc., contain integer vectors such\n\
+that,\n\
+\n\
+@tex\n\
+$g = v_1 a_1 + v_2 a_2 + \\cdots$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+@var{g} = @var{v1} .* @var{a1} + @var{v2} .* @var{a2} + @dots{}\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+\n\
+@seealso{lcm, factor}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin > 1)
+    {
+      if (nargout > 1)
+        {
+          retval.resize (nargin + 1);
+
+          retval(0) = do_extended_gcd (args(0), args(1), retval(1), retval(2));
+
+          for (int j = 2; j < nargin; j++)
+            {
+              octave_value x;
+              retval(0) = do_extended_gcd (retval(0), args(j),
+                                           x, retval(j+1));
+              for (int i = 0; i < j; i++)
+                retval(i+1).assign (octave_value::op_el_mul_eq, x);
+
+              if (error_state)
+                break;
+            }
+        }
+      else
+        {
+          retval(0) = do_simple_gcd (args(0), args(1));
+
+          for (int j = 2; j < nargin; j++)
+            {
+              retval(0) = do_simple_gcd (retval(0), args(j));
+
+              if (error_state)
+                break;
+            }
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!assert (gcd (200, 300, 50, 35), 5)
+%!assert (gcd (int16 (200), int16 (300), int16 (50), int16 (35)), int16 (5))
+%!assert (gcd (uint64 (200), uint64 (300), uint64 (50), uint64 (35)), uint64 (5))
+%!assert (gcd (18-i, -29+3i), -3-4i)
+
+%!error gcd ()
+
+%!test
+%! s.a = 1;
+%! fail ("gcd (s)");
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/getgrent.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,215 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+
+#include <sys/types.h>
+
+#include "oct-group.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-map.h"
+#include "ov.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+// Group file functions.  (Why not?)
+
+static octave_value
+mk_gr_map (const octave_group& gr)
+{
+  octave_value retval;
+
+  if (gr)
+    {
+      octave_scalar_map m;
+
+      m.assign ("name", gr.name ());
+      m.assign ("passwd", gr.passwd ());
+      m.assign ("gid", static_cast<double> (gr.gid ()));
+      m.assign ("mem", octave_value (gr.mem ()));
+
+      retval = m;
+    }
+  else
+    retval = 0;
+
+  return retval;
+}
+
+DEFUN (getgrent, args, ,
+ "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{grp_struct} =} getgrent ()\n\
+Return an entry from the group database, opening it if necessary.\n\
+Once the end of data has been reached, @code{getgrent} returns 0.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  retval(1) = std::string ();
+  retval(0) = 0;
+
+  int nargin = args.length ();
+
+  if (nargin == 0)
+    {
+      std::string msg;
+
+      retval(1) = msg;
+      retval(0) = mk_gr_map (octave_group::getgrent (msg));
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+DEFUN (getgrgid, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{grp_struct} =} getgrgid (@var{gid}).\n\
+Return the first entry from the group database with the group ID\n\
+@var{gid}.  If the group ID does not exist in the database,\n\
+@code{getgrgid} returns 0.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  retval(1) = std::string ();
+  retval(0) = 0;
+
+  int nargin = args.length ();
+
+  if (nargin == 1)
+    {
+      double dval = args(0).double_value ();
+
+      if (! error_state)
+        {
+          if (D_NINT (dval) == dval)
+            {
+              gid_t gid = static_cast<gid_t> (dval);
+
+              std::string msg;
+
+              retval(1) = msg;
+              retval(0) = mk_gr_map (octave_group::getgrgid (gid, msg));
+            }
+          else
+            error ("getgrgid: GID must be an integer");
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+DEFUN (getgrnam, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{grp_struct} =} getgrnam (@var{name})\n\
+Return the first entry from the group database with the group name\n\
+@var{name}.  If the group name does not exist in the database,\n\
+@code{getgrnam} returns 0.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  retval(1) = std::string ();
+  retval(0) = 0;
+
+  int nargin = args.length ();
+
+  if (nargin == 1)
+    {
+      std::string s = args(0).string_value ();
+
+      if (! error_state)
+        {
+          std::string msg;
+
+          retval(1) = msg;
+          retval(0) = mk_gr_map (octave_group::getgrnam (s.c_str (), msg));
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+DEFUN (setgrent, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} setgrent ()\n\
+Return the internal pointer to the beginning of the group database.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  retval(1) = std::string ();
+  retval(0) = -1.0;
+
+  int nargin = args.length ();
+
+  if (nargin == 0)
+    {
+      std::string msg;
+
+      retval(1) = msg;
+      retval(0) = static_cast<double> (octave_group::setgrent (msg));
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+DEFUN (endgrent, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} endgrent ()\n\
+Close the group database.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  retval(1) = std::string ();
+  retval(0) = -1.0;
+
+  int nargin = args.length ();
+
+  if (nargin == 0)
+    {
+      std::string msg;
+
+      retval(1) = msg;
+      retval(0) = static_cast<double> (octave_group::endgrent (msg));
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/getpwent.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,219 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+
+#include <sys/types.h>
+
+#include "oct-passwd.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-map.h"
+#include "ov.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+// Password file functions.  (Why not?)
+
+static octave_value
+mk_pw_map (const octave_passwd& pw)
+{
+  octave_value retval;
+
+  if (pw)
+    {
+      octave_scalar_map m;
+
+      m.assign ("name", pw.name ());
+      m.assign ("passwd", pw.passwd ());
+      m.assign ("uid", static_cast<double> (pw.uid ()));
+      m.assign ("gid", static_cast<double> (pw.gid ()));
+      m.assign ("gecos", pw.gecos ());
+      m.assign ("dir", pw.dir ());
+      m.assign ("shell", pw.shell ());
+
+      retval = m;
+    }
+  else
+    retval = 0;
+
+  return retval;
+}
+
+DEFUN (getpwent, args, ,
+ "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{pw_struct} =} getpwent ()\n\
+Return a structure containing an entry from the password database,\n\
+opening it if necessary.  Once the end of the data has been reached,\n\
+@code{getpwent} returns 0.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  retval(1) = std::string ();
+  retval(0) = 0;
+
+  int nargin = args.length ();
+
+  if (nargin == 0)
+    {
+      std::string msg;
+
+      retval(1) = msg;
+      retval(0) = mk_pw_map (octave_passwd::getpwent (msg));
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+DEFUN (getpwuid, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{pw_struct} =} getpwuid (@var{uid}).\n\
+Return a structure containing the first entry from the password database\n\
+with the user ID @var{uid}.  If the user ID does not exist in the\n\
+database, @code{getpwuid} returns 0.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  retval(1) = std::string ();
+  retval(0) = 0;
+
+  int nargin = args.length ();
+
+  if (nargin == 1)
+    {
+      double dval = args(0).double_value ();
+
+      if (! error_state)
+        {
+          if (D_NINT (dval) == dval)
+            {
+              uid_t uid = static_cast<uid_t> (dval);
+
+              std::string msg;
+
+              retval(1) = msg;
+              retval(0) = mk_pw_map (octave_passwd::getpwuid (uid, msg));
+            }
+          else
+            error ("getpwuid: UID must be an integer");
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+DEFUN (getpwnam, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{pw_struct} =} getpwnam (@var{name})\n\
+Return a structure containing the first entry from the password database\n\
+with the user name @var{name}.  If the user name does not exist in the\n\
+database, @code{getpwname} returns 0.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  retval(1) = std::string ();
+  retval(0) = 0.0;
+
+  int nargin = args.length ();
+
+  if (nargin == 1)
+    {
+      std::string s = args(0).string_value ();
+
+      if (! error_state)
+        {
+          std::string msg;
+
+          retval(1) = msg;
+          retval(0) = mk_pw_map (octave_passwd::getpwnam (s, msg));
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+DEFUN (setpwent, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} setpwent ()\n\
+Return the internal pointer to the beginning of the password database.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  retval(1) = std::string ();
+  retval(0) = -1.0;
+
+  int nargin = args.length ();
+
+  if (nargin == 0)
+    {
+      std::string msg;
+
+      retval(1) = msg;
+      retval(0) = static_cast<double> (octave_passwd::setpwent (msg));
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+DEFUN (endpwent, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} endpwent ()\n\
+Close the password database.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  retval(1) = std::string ();
+  retval(0) = -1.0;
+
+  int nargin = args.length ();
+
+  if (nargin == 0)
+    {
+      std::string msg;
+
+      retval(1) = msg;
+      retval(0) = static_cast<double> (octave_passwd::endpwent (msg));
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/getrusage.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,205 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/time.h>
+#include <sys/times.h>
+#include <sys/types.h>
+
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+
+#if defined (HAVE_SYS_PARAM_H)
+#include <sys/param.h>
+#endif
+
+#include "defun.h"
+#include "oct-map.h"
+#include "sysdep.h"
+#include "ov.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+#if !defined (HZ)
+#if defined (CLK_TCK)
+#define HZ CLK_TCK
+#elif defined (USG)
+#define HZ 100
+#else
+#define HZ 60
+#endif
+#endif
+
+#ifndef RUSAGE_SELF
+#define RUSAGE_SELF 0
+#endif
+
+// System resource functions.
+
+DEFUN (getrusage, , ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} getrusage ()\n\
+Return a structure containing a number of statistics about the current\n\
+Octave process.  Not all fields are available on all systems.  If it is\n\
+not possible to get CPU time statistics, the CPU time slots are set to\n\
+zero.  Other missing data are replaced by NaN@.  The list of possible\n\
+fields is:\n\
+\n\
+@table @code\n\
+@item idrss\n\
+Unshared data size.\n\
+\n\
+@item inblock\n\
+Number of block input operations.\n\
+\n\
+@item isrss\n\
+Unshared stack size.\n\
+\n\
+@item ixrss\n\
+Shared memory size.\n\
+\n\
+@item majflt\n\
+Number of major page faults.\n\
+\n\
+@item maxrss\n\
+Maximum data size.\n\
+\n\
+@item minflt\n\
+Number of minor page faults.\n\
+\n\
+@item msgrcv\n\
+Number of messages received.\n\
+\n\
+@item msgsnd\n\
+Number of messages sent.\n\
+\n\
+@item nivcsw\n\
+Number of involuntary context switches.\n\
+\n\
+@item nsignals\n\
+Number of signals received.\n\
+\n\
+@item nswap\n\
+Number of swaps.\n\
+\n\
+@item nvcsw\n\
+Number of voluntary context switches.\n\
+\n\
+@item oublock\n\
+Number of block output operations.\n\
+\n\
+@item stime\n\
+A structure containing the system CPU time used.  The structure has the\n\
+elements @code{sec} (seconds) @code{usec} (microseconds).\n\
+\n\
+@item utime\n\
+A structure containing the user CPU time used.  The structure has the\n\
+elements @code{sec} (seconds) @code{usec} (microseconds).\n\
+@end table\n\
+@end deftypefn")
+{
+  octave_scalar_map m;
+  octave_scalar_map tv_tmp;
+
+  // FIXME -- maybe encapsulate all of this in a liboctave class
+#if defined (HAVE_GETRUSAGE)
+
+  struct rusage ru;
+
+  getrusage (RUSAGE_SELF, &ru);
+
+  tv_tmp.assign ("sec", static_cast<double> (ru.ru_utime.tv_sec));
+  tv_tmp.assign ("usec", static_cast<double> (ru.ru_utime.tv_usec));
+  m.assign ("utime", octave_value (tv_tmp));
+
+  tv_tmp.assign ("sec", static_cast<double> (ru.ru_stime.tv_sec));
+  tv_tmp.assign ("usec", static_cast<double> (ru.ru_stime.tv_usec));
+  m.assign ("stime", octave_value (tv_tmp));
+
+#if ! defined (RUSAGE_TIMES_ONLY)
+  m.assign ("maxrss", static_cast<double> (ru.ru_maxrss));
+  m.assign ("ixrss", static_cast<double> (ru.ru_ixrss));
+  m.assign ("idrss", static_cast<double> (ru.ru_idrss));
+  m.assign ("isrss", static_cast<double> (ru.ru_isrss));
+  m.assign ("minflt", static_cast<double> (ru.ru_minflt));
+  m.assign ("majflt", static_cast<double> (ru.ru_majflt));
+  m.assign ("nswap", static_cast<double> (ru.ru_nswap));
+  m.assign ("inblock", static_cast<double> (ru.ru_inblock));
+  m.assign ("oublock", static_cast<double> (ru.ru_oublock));
+  m.assign ("msgsnd", static_cast<double> (ru.ru_msgsnd));
+  m.assign ("msgrcv", static_cast<double> (ru.ru_msgrcv));
+  m.assign ("nsignals", static_cast<double> (ru.ru_nsignals));
+  m.assign ("nvcsw", static_cast<double> (ru.ru_nvcsw));
+  m.assign ("nivcsw", static_cast<double> (ru.ru_nivcsw));
+#endif
+
+#else
+
+  struct tms t;
+
+  times (&t);
+
+  unsigned long ticks;
+  unsigned long seconds;
+  unsigned long fraction;
+
+  ticks = t.tms_utime + t.tms_cutime;
+  fraction = ticks % HZ;
+  seconds = ticks / HZ;
+
+  tv_tmp.assign ("sec", static_cast<double> (seconds));
+  tv_tmp.assign ("usec", static_cast<double> (fraction * 1e6 / HZ));
+  m.assign ("utime", octave_value (tv_tmp));
+
+  ticks = t.tms_stime + t.tms_cstime;
+  fraction = ticks % HZ;
+  seconds = ticks / HZ;
+
+  tv_tmp.assign ("sec", static_cast<double> (seconds));
+  tv_tmp.assign ("usec", static_cast<double> (fraction * 1e6 / HZ));
+  m.assign ("stime", octave_value (tv_tmp));
+
+  double tmp = lo_ieee_nan_value ();
+
+  m.assign ("maxrss", tmp);
+  m.assign ("ixrss", tmp);
+  m.assign ("idrss", tmp);
+  m.assign ("isrss", tmp);
+  m.assign ("minflt", tmp);
+  m.assign ("majflt", tmp);
+  m.assign ("nswap", tmp);
+  m.assign ("inblock", tmp);
+  m.assign ("oublock", tmp);
+  m.assign ("msgsnd", tmp);
+  m.assign ("msgrcv", tmp);
+  m.assign ("nsignals", tmp);
+  m.assign ("nvcsw", tmp);
+  m.assign ("nivcsw", tmp);
+
+#endif
+
+  return octave_value (m);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/givens.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,214 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+// Originally written by A. S. Hodel <scotte@eng.auburn.edu>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "defun.h"
+#include "error.h"
+#include "oct-obj.h"
+
+DEFUN (givens, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{g} =} givens (@var{x}, @var{y})\n\
+@deftypefnx {Built-in Function} {[@var{c}, @var{s}] =} givens (@var{x}, @var{y})\n\
+@tex\n\
+Return a $2\\times 2$ orthogonal matrix\n\
+$$\n\
+ G = \\left[\\matrix{c & s\\cr -s'& c\\cr}\\right]\n\
+$$\n\
+such that\n\
+$$\n\
+ G \\left[\\matrix{x\\cr y}\\right] = \\left[\\matrix{\\ast\\cr 0}\\right]\n\
+$$\n\
+with $x$ and $y$ scalars.\n\
+@end tex\n\
+@ifnottex\n\
+Return a 2 by 2 orthogonal matrix\n\
+@code{@var{g} = [@var{c} @var{s}; -@var{s}' @var{c}]} such that\n\
+@code{@var{g} [@var{x}; @var{y}] = [*; 0]} with @var{x} and @var{y} scalars.\n\
+@end ifnottex\n\
+\n\
+For example:\n\
+\n\
+@example\n\
+@group\n\
+givens (1, 1)\n\
+   @result{}   0.70711   0.70711\n\
+       -0.70711   0.70711\n\
+@end group\n\
+@end example\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin != 2 || nargout > 2)
+    {
+      print_usage ();
+      return retval;
+    }
+  else
+    {
+      if (args(0).is_single_type () || args(1).is_single_type ())
+        {
+          if (args(0).is_complex_type () || args(1).is_complex_type ())
+            {
+              FloatComplex cx = args(0).float_complex_value ();
+              FloatComplex cy = args(1).float_complex_value ();
+
+              if (! error_state)
+                {
+                  FloatComplexMatrix result = Givens (cx, cy);
+
+                  if (! error_state)
+                    {
+                      switch (nargout)
+                        {
+                        case 0:
+                        case 1:
+                          retval(0) = result;
+                          break;
+
+                        case 2:
+                          retval(1) = result (0, 1);
+                          retval(0) = result (0, 0);
+                          break;
+
+                        default:
+                          error ("givens: invalid number of output arguments");
+                          break;
+                        }
+                    }
+                }
+            }
+          else
+            {
+              float x = args(0).float_value ();
+              float y = args(1).float_value ();
+
+              if (! error_state)
+                {
+                  FloatMatrix result = Givens (x, y);
+
+                  if (! error_state)
+                    {
+                      switch (nargout)
+                        {
+                        case 0:
+                        case 1:
+                          retval(0) = result;
+                          break;
+
+                        case 2:
+                          retval(1) = result (0, 1);
+                          retval(0) = result (0, 0);
+                          break;
+
+                        default:
+                          error ("givens: invalid number of output arguments");
+                          break;
+                        }
+                    }
+                }
+            }
+        }
+      else
+        {
+          if (args(0).is_complex_type () || args(1).is_complex_type ())
+            {
+              Complex cx = args(0).complex_value ();
+              Complex cy = args(1).complex_value ();
+
+              if (! error_state)
+                {
+                  ComplexMatrix result = Givens (cx, cy);
+
+                  if (! error_state)
+                    {
+                      switch (nargout)
+                        {
+                        case 0:
+                        case 1:
+                          retval(0) = result;
+                          break;
+
+                        case 2:
+                          retval(1) = result (0, 1);
+                          retval(0) = result (0, 0);
+                          break;
+
+                        default:
+                          error ("givens: invalid number of output arguments");
+                          break;
+                        }
+                    }
+                }
+            }
+          else
+            {
+              double x = args(0).double_value ();
+              double y = args(1).double_value ();
+
+              if (! error_state)
+                {
+                  Matrix result = Givens (x, y);
+
+                  if (! error_state)
+                    {
+                      switch (nargout)
+                        {
+                        case 0:
+                        case 1:
+                          retval(0) = result;
+                          break;
+
+                        case 2:
+                          retval(1) = result (0, 1);
+                          retval(0) = result (0, 0);
+                          break;
+
+                        default:
+                          error ("givens: invalid number of output arguments");
+                          break;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!assert (givens (1,1), [1, 1; -1, 1] / sqrt (2), 2*eps)
+%!assert (givens (1,0), eye (2))
+%!assert (givens (0,1), [0, 1; -1 0])
+
+%!error givens ()
+%!error givens (1)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/hess.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,189 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CmplxHESS.h"
+#include "dbleHESS.h"
+#include "fCmplxHESS.h"
+#include "floatHESS.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+DEFUN (hess, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{H} =} hess (@var{A})\n\
+@deftypefnx {Built-in Function} {[@var{P}, @var{H}] =} hess (@var{A})\n\
+@cindex Hessenberg decomposition\n\
+Compute the Hessenberg decomposition of the matrix @var{A}.\n\
+\n\
+The Hessenberg decomposition is\n\
+@tex\n\
+$$\n\
+A = PHP^T\n\
+$$\n\
+where $P$ is a square unitary matrix ($P^TP = I$), and $H$\n\
+is upper Hessenberg ($H_{i,j} = 0, \\forall i \\ge j+1$).\n\
+@end tex\n\
+@ifnottex\n\
+@code{@var{P} * @var{H} * @var{P}' = @var{A}} where @var{P} is a square\n\
+unitary matrix (@code{@var{P}' * @var{P} = I}, using complex-conjugate\n\
+transposition) and @var{H} is upper Hessenberg\n\
+(@code{@var{H}(i, j) = 0 forall i >= j+1)}.\n\
+@end ifnottex\n\
+\n\
+The Hessenberg decomposition is usually used as the first step in an\n\
+eigenvalue computation, but has other applications as well (see Golub,\n\
+Nash, and Van Loan, IEEE Transactions on Automatic Control, 1979).\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin != 1 || nargout > 2)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value arg = args(0);
+
+  octave_idx_type nr = arg.rows ();
+  octave_idx_type nc = arg.columns ();
+
+  int arg_is_empty = empty_arg ("hess", nr, nc);
+
+  if (arg_is_empty < 0)
+    return retval;
+  else if (arg_is_empty > 0)
+    return octave_value_list (2, Matrix ());
+
+  if (nr != nc)
+    {
+      gripe_square_matrix_required ("hess");
+      return retval;
+    }
+
+  if (arg.is_single_type ())
+    {
+      if (arg.is_real_type ())
+        {
+         FloatMatrix tmp = arg.float_matrix_value ();
+
+          if (! error_state)
+            {
+              FloatHESS result (tmp);
+
+              if (nargout <= 1)
+                retval(0) = result.hess_matrix ();
+              else
+                {
+                  retval(1) = result.hess_matrix ();
+                  retval(0) = result.unitary_hess_matrix ();
+                }
+            }
+        }
+      else if (arg.is_complex_type ())
+        {
+          FloatComplexMatrix ctmp = arg.float_complex_matrix_value ();
+
+          if (! error_state)
+            {
+              FloatComplexHESS result (ctmp);
+
+              if (nargout <= 1)
+                retval(0) = result.hess_matrix ();
+              else
+                {
+                  retval(1) = result.hess_matrix ();
+                  retval(0) = result.unitary_hess_matrix ();
+                }
+            }
+        }
+    }
+  else
+    {
+      if (arg.is_real_type ())
+        {
+          Matrix tmp = arg.matrix_value ();
+
+          if (! error_state)
+            {
+              HESS result (tmp);
+
+              if (nargout <= 1)
+                retval(0) = result.hess_matrix ();
+              else
+                {
+                  retval(1) = result.hess_matrix ();
+                  retval(0) = result.unitary_hess_matrix ();
+                }
+            }
+        }
+      else if (arg.is_complex_type ())
+        {
+          ComplexMatrix ctmp = arg.complex_matrix_value ();
+
+          if (! error_state)
+            {
+              ComplexHESS result (ctmp);
+
+              if (nargout <= 1)
+                retval(0) = result.hess_matrix ();
+              else
+                {
+                  retval(1) = result.hess_matrix ();
+                  retval(0) = result.unitary_hess_matrix ();
+                }
+            }
+        }
+      else
+        {
+          gripe_wrong_type_arg ("hess", arg);
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!test
+%! a = [1, 2, 3; 5, 4, 6; 8, 7, 9];
+%! [p, h] = hess (a);
+%! assert (p * h * p', a, sqrt (eps));
+
+%!test
+%! a = single ([1, 2, 3; 5, 4, 6; 8, 7, 9]);
+%! [p, h] = hess (a);
+%! assert (p * h * p', a, sqrt (eps ("single")));
+
+%!error hess ()
+%!error hess ([1, 2; 3, 4], 2)
+%!error <argument must be a square matrix> hess ([1, 2; 3, 4; 5, 6])
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/hex2num.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,192 @@
+/*
+
+Copyright (C) 2008-2012 David Bateman
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <algorithm>
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+DEFUN (hex2num, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{n} =} hex2num (@var{s})\n\
+Typecast the 16 character hexadecimal character string to an IEEE 754\n\
+double precision number.  If fewer than 16 characters are given the\n\
+strings are right padded with '0' characters.\n\
+\n\
+Given a string matrix, @code{hex2num} treats each row as a separate\n\
+number.\n\
+\n\
+@example\n\
+@group\n\
+hex2num ([\"4005bf0a8b145769\"; \"4024000000000000\"])\n\
+   @result{} [2.7183; 10.000]\n\
+@end group\n\
+@end example\n\
+@seealso{num2hex, hex2dec, dec2hex}\n\
+@end deftypefn")
+{
+  int nargin = args.length ();
+  octave_value retval;
+
+  if (nargin != 1)
+    print_usage ();
+  else
+    {
+      const charMatrix cmat = args(0).char_matrix_value ();
+
+      if (cmat.columns () > 16)
+        error ("hex2num: S must be no more than 16 characters");
+      else if (! error_state)
+        {
+          octave_idx_type nr = cmat.rows ();
+          octave_idx_type nc = cmat.columns ();
+          ColumnVector m (nr);
+
+          for (octave_idx_type i = 0; i < nr; i++)
+            {
+              union
+              {
+                uint64_t ival;
+                double dval;
+              } num;
+
+              num.ival = 0;
+
+              for (octave_idx_type j = 0; j < nc; j++)
+                {
+                  unsigned char ch = cmat.elem (i, j);
+
+                  if (isxdigit (ch))
+                    {
+                      num.ival <<= 4;
+                      if (ch >= 'a')
+                        num.ival += static_cast<uint64_t> (ch - 'a' + 10);
+                      else if (ch >= 'A')
+                        num.ival += static_cast<uint64_t> (ch - 'A' + 10);
+                      else
+                        num.ival += static_cast<uint64_t> (ch - '0');
+                    }
+                  else
+                    {
+                      error ("hex2num: illegal character found in string S");
+                      break;
+                    }
+                }
+
+              if (error_state)
+                break;
+              else
+                {
+                  if (nc < 16)
+                    num.ival <<= (16 - nc) * 4;
+
+                  m(i) = num.dval;
+                }
+            }
+
+          if (! error_state)
+            retval =  m;
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!assert (hex2num (["c00";"bff";"000";"3ff";"400"]), [-2:2]')
+*/
+
+DEFUN (num2hex, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{s} =} num2hex (@var{n})\n\
+Typecast a double precision number or vector to a 16 character hexadecimal\n\
+string of the IEEE 754 representation of the number.  For example:\n\
+\n\
+@example\n\
+@group\n\
+num2hex ([-1, 1, e, Inf, NaN, NA])\n\
+@result{} \"bff0000000000000\n\
+    3ff0000000000000\n\
+    4005bf0a8b145769\n\
+    7ff0000000000000\n\
+    fff8000000000000\n\
+    7ff00000000007a2\"\n\
+@end group\n\
+@end example\n\
+@seealso{hex2num, hex2dec, dec2hex}\n\
+@end deftypefn")
+{
+  int nargin = args.length ();
+  octave_value retval;
+
+  if (nargin != 1)
+    print_usage ();
+  else
+    {
+      const ColumnVector v (args(0).vector_value ());
+
+      if (! error_state)
+        {
+          octave_idx_type nr = v.length ();
+          charMatrix m (nr, 16);
+          const double *pv = v.fortran_vec ();
+
+          for (octave_idx_type i = 0; i < nr; i++)
+            {
+              union
+              {
+                uint64_t ival;
+                double dval;
+              } num;
+
+              num.dval = *pv++;
+
+              for (octave_idx_type j = 0; j < 16; j++)
+                {
+                  unsigned char ch =
+                    static_cast<char> (num.ival >> ((15 - j) * 4) & 0xF);
+                  if (ch >= 10)
+                    ch += 'a' - 10;
+                  else
+                    ch += '0';
+
+                  m.elem (i, j) = ch;
+                }
+            }
+
+          retval = m;
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!assert (num2hex (-2:2), ["c000000000000000";"bff0000000000000";"0000000000000000";"3ff0000000000000";"4000000000000000"])
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/inv.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,250 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "ops.h"
+#include "ov-re-diag.h"
+#include "ov-cx-diag.h"
+#include "ov-flt-re-diag.h"
+#include "ov-flt-cx-diag.h"
+#include "ov-perm.h"
+#include "utils.h"
+
+DEFUN (inv, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{x} =} inv (@var{A})\n\
+@deftypefnx {Built-in Function} {[@var{x}, @var{rcond}] =} inv (@var{A})\n\
+Compute the inverse of the square matrix @var{A}.  Return an estimate\n\
+of the reciprocal condition number if requested, otherwise warn of an\n\
+ill-conditioned matrix if the reciprocal condition number is small.\n\
+\n\
+In general it is best to avoid calculating the inverse of a matrix\n\
+directly.  For example, it is both faster and more accurate to solve\n\
+systems of equations (@var{A}*@math{x} = @math{b}) with\n\
+@code{@var{y} = @var{A} \\ @math{b}}, rather than\n\
+@code{@var{y} = inv (@var{A}) * @math{b}}.\n\
+\n\
+If called with a sparse matrix, then in general @var{x} will be a full\n\
+matrix requiring significantly more storage.  Avoid forming the inverse\n\
+of a sparse matrix if possible.\n\
+@seealso{ldivide, rdivide}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin != 1)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value arg = args(0);
+
+  octave_idx_type nr = arg.rows ();
+  octave_idx_type nc = arg.columns ();
+
+  int arg_is_empty = empty_arg ("inverse", nr, nc);
+
+  if (arg_is_empty < 0)
+    return retval;
+  else if (arg_is_empty > 0)
+    return octave_value (Matrix ());
+
+  if (nr != nc)
+    {
+      gripe_square_matrix_required ("inverse");
+      return retval;
+    }
+
+  octave_value result;
+  octave_idx_type info;
+  double rcond = 0.0;
+  float frcond = 0.0;
+  bool isfloat = arg.is_single_type ();
+
+  if (arg.is_diag_matrix ())
+    {
+      rcond = 1.0;
+      frcond = 1.0f;
+      if (arg.is_complex_type ())
+        {
+          if (isfloat)
+            {
+              result = arg.float_complex_diag_matrix_value ().inverse (info);
+              if (nargout > 1)
+                frcond = arg.float_complex_diag_matrix_value ().rcond ();
+            }
+          else
+            {
+              result = arg.complex_diag_matrix_value ().inverse (info);
+              if (nargout > 1)
+                rcond = arg.complex_diag_matrix_value ().rcond ();
+            }
+        }
+      else
+        {
+          if (isfloat)
+            {
+              result = arg.float_diag_matrix_value ().inverse (info);
+              if (nargout > 1)
+                frcond = arg.float_diag_matrix_value ().rcond ();
+            }
+          else
+            {
+              result = arg.diag_matrix_value ().inverse (info);
+              if (nargout > 1)
+                rcond = arg.diag_matrix_value ().rcond ();
+            }
+        }
+    }
+  else if (arg.is_perm_matrix ())
+    {
+      rcond = 1.0;
+      info = 0;
+      result = arg.perm_matrix_value ().inverse ();
+    }
+  else if (isfloat)
+    {
+      if (arg.is_real_type ())
+        {
+          FloatMatrix m = arg.float_matrix_value ();
+          if (! error_state)
+            {
+              MatrixType mattyp = args(0).matrix_type ();
+              result = m.inverse (mattyp, info, frcond, 1);
+              args(0).matrix_type (mattyp);
+            }
+        }
+      else if (arg.is_complex_type ())
+        {
+          FloatComplexMatrix m = arg.float_complex_matrix_value ();
+          if (! error_state)
+            {
+              MatrixType mattyp = args(0).matrix_type ();
+              result = m.inverse (mattyp, info, frcond, 1);
+              args(0).matrix_type (mattyp);
+            }
+        }
+    }
+  else
+    {
+      if (arg.is_real_type ())
+        {
+          if (arg.is_sparse_type ())
+            {
+              SparseMatrix m = arg.sparse_matrix_value ();
+              if (! error_state)
+                {
+                  MatrixType mattyp = args(0).matrix_type ();
+                  result = m.inverse (mattyp, info, rcond, 1);
+                  args(0).matrix_type (mattyp);
+                }
+            }
+          else
+            {
+              Matrix m = arg.matrix_value ();
+              if (! error_state)
+                {
+                  MatrixType mattyp = args(0).matrix_type ();
+                  result = m.inverse (mattyp, info, rcond, 1);
+                  args(0).matrix_type (mattyp);
+                }
+            }
+        }
+      else if (arg.is_complex_type ())
+        {
+          if (arg.is_sparse_type ())
+            {
+              SparseComplexMatrix m = arg.sparse_complex_matrix_value ();
+              if (! error_state)
+                {
+                  MatrixType mattyp = args(0).matrix_type ();
+                  result = m.inverse (mattyp, info, rcond, 1);
+                  args(0).matrix_type (mattyp);
+                }
+            }
+          else
+            {
+              ComplexMatrix m = arg.complex_matrix_value ();
+              if (! error_state)
+                {
+                  MatrixType mattyp = args(0).matrix_type ();
+                  result = m.inverse (mattyp, info, rcond, 1);
+                  args(0).matrix_type (mattyp);
+                }
+            }
+        }
+      else
+        gripe_wrong_type_arg ("inv", arg);
+    }
+
+  if (! error_state)
+    {
+      if (nargout > 1)
+        retval(1) = isfloat ? octave_value (frcond) : octave_value (rcond);
+
+      retval(0) = result;
+
+      volatile double xrcond = rcond;
+      xrcond += 1.0;
+      if (nargout < 2 && (info == -1 || xrcond == 1.0))
+        warning ("inverse: matrix singular to machine precision, rcond = %g",
+                 rcond);
+    }
+
+  return retval;
+}
+
+/*
+%!assert (inv ([1, 2; 3, 4]), [-2, 1; 1.5, -0.5], sqrt (eps))
+%!assert (inv (single ([1, 2; 3, 4])), single ([-2, 1; 1.5, -0.5]), sqrt (eps ("single")))
+
+%!error inv ()
+%!error inv ([1, 2; 3, 4], 2)
+%!error <argument must be a square matrix> inv ([1, 2; 3, 4; 5, 6])
+*/
+
+// FIXME -- this should really be done with an alias, but
+// alias_builtin() won't do the right thing if we are actually using
+// dynamic linking.
+
+DEFUN (inverse, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{x} =} inverse (@var{A})\n\
+@deftypefnx {Built-in Function} {[@var{x}, @var{rcond}] =} inverse (@var{A})\n\
+Compute the inverse of the square matrix @var{A}.\n\
+\n\
+This is an alias for @code{inv}.\n\
+@seealso{inv}\n\
+@end deftypefn")
+{
+  return Finv (args, nargout);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/kron.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,321 @@
+/*
+
+Copyright (C) 2002-2012 John W. Eaton
+
+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/>.
+
+*/
+
+// Author: Paul Kienzle <pkienzle@users.sf.net>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "dMatrix.h"
+#include "fMatrix.h"
+#include "CMatrix.h"
+#include "fCMatrix.h"
+
+#include "dSparse.h"
+#include "CSparse.h"
+
+#include "dDiagMatrix.h"
+#include "fDiagMatrix.h"
+#include "CDiagMatrix.h"
+#include "fCDiagMatrix.h"
+
+#include "PermMatrix.h"
+
+#include "mx-inlines.cc"
+#include "quit.h"
+
+#include "defun.h"
+#include "error.h"
+#include "oct-obj.h"
+
+template <class R, class T>
+static MArray<T>
+kron (const MArray<R>& a, const MArray<T>& b)
+{
+  assert (a.ndims () == 2);
+  assert (b.ndims () == 2);
+
+  octave_idx_type nra = a.rows (), nrb = b.rows ();
+  octave_idx_type nca = a.cols (), ncb = b.cols ();
+
+  MArray<T> c (dim_vector (nra*nrb, nca*ncb));
+  T *cv = c.fortran_vec ();
+
+  for (octave_idx_type ja = 0; ja < nca; ja++)
+    for (octave_idx_type jb = 0; jb < ncb; jb++)
+      for (octave_idx_type ia = 0; ia < nra; ia++)
+        {
+          octave_quit ();
+          mx_inline_mul (nrb, cv, a(ia, ja), b.data () + nrb*jb);
+          cv += nrb;
+        }
+
+  return c;
+}
+
+template <class R, class T>
+static MArray<T>
+kron (const MDiagArray2<R>& a, const MArray<T>& b)
+{
+  assert (b.ndims () == 2);
+
+  octave_idx_type nra = a.rows (), nrb = b.rows (), dla = a.diag_length ();
+  octave_idx_type nca = a.cols (), ncb = b.cols ();
+
+  MArray<T> c (dim_vector (nra*nrb, nca*ncb), T ());
+
+  for (octave_idx_type ja = 0; ja < dla; ja++)
+    for (octave_idx_type jb = 0; jb < ncb; jb++)
+      {
+        octave_quit ();
+        mx_inline_mul (nrb, &c.xelem (ja*nrb, ja*ncb + jb), a.dgelem (ja), b.data () + nrb*jb);
+      }
+
+  return c;
+}
+
+template <class T>
+static MSparse<T>
+kron (const MSparse<T>& A, const MSparse<T>& B)
+{
+  octave_idx_type idx = 0;
+  MSparse<T> C (A.rows () * B.rows (), A.columns () * B.columns (),
+                A.nnz () * B.nnz ());
+
+  C.cidx (0) = 0;
+
+  for (octave_idx_type Aj = 0; Aj < A.columns (); Aj++)
+    for (octave_idx_type Bj = 0; Bj < B.columns (); Bj++)
+      {
+        octave_quit ();
+        for (octave_idx_type Ai = A.cidx (Aj); Ai < A.cidx (Aj+1); Ai++)
+          {
+            octave_idx_type Ci = A.ridx (Ai) * B.rows ();
+            const T v = A.data (Ai);
+
+            for (octave_idx_type Bi = B.cidx (Bj); Bi < B.cidx (Bj+1); Bi++)
+              {
+                C.data (idx) = v * B.data (Bi);
+                C.ridx (idx++) = Ci + B.ridx (Bi);
+              }
+          }
+        C.cidx (Aj * B.columns () + Bj + 1) = idx;
+      }
+
+  return C;
+}
+
+static PermMatrix
+kron (const PermMatrix& a, const PermMatrix& b)
+{
+  octave_idx_type na = a.rows (), nb = b.rows ();
+  const octave_idx_type *pa = a.data (), *pb = b.data ();
+  PermMatrix c(na*nb); // Row permutation.
+  octave_idx_type *pc = c.fortran_vec ();
+
+  bool cola = a.is_col_perm (), colb = b.is_col_perm ();
+  if (cola && colb)
+    {
+      for (octave_idx_type i = 0; i < na; i++)
+        for (octave_idx_type j = 0; j < nb; j++)
+          pc[pa[i]*nb+pb[j]] = i*nb+j;
+    }
+  else if (cola)
+    {
+      for (octave_idx_type i = 0; i < na; i++)
+        for (octave_idx_type j = 0; j < nb; j++)
+          pc[pa[i]*nb+j] = i*nb+pb[j];
+    }
+  else if (colb)
+    {
+      for (octave_idx_type i = 0; i < na; i++)
+        for (octave_idx_type j = 0; j < nb; j++)
+          pc[i*nb+pb[j]] = pa[i]*nb+j;
+    }
+  else
+    {
+      for (octave_idx_type i = 0; i < na; i++)
+        for (octave_idx_type j = 0; j < nb; j++)
+          pc[i*nb+j] = pa[i]*nb+pb[j];
+    }
+
+  return c;
+}
+
+template <class MTA, class MTB>
+octave_value
+do_kron (const octave_value& a, const octave_value& b)
+{
+  MTA am = octave_value_extract<MTA> (a);
+  MTB bm = octave_value_extract<MTB> (b);
+  return octave_value (kron (am, bm));
+}
+
+octave_value
+dispatch_kron (const octave_value& a, const octave_value& b)
+{
+  octave_value retval;
+  if (a.is_perm_matrix () && b.is_perm_matrix ())
+    retval = do_kron<PermMatrix, PermMatrix> (a, b);
+  else if (a.is_diag_matrix ())
+    {
+      if (b.is_diag_matrix () && a.rows () == a.columns ()
+          && b.rows () == b.columns ())
+        {
+          // We have two diagonal matrices, the product of those will be
+          // another diagonal matrix.  To do that efficiently, extract
+          // the diagonals as vectors and compute the product.  That
+          // will be another vector, which we then use to construct a
+          // diagonal matrix object.  Note that this will fail if our
+          // digaonal matrix object is modified to allow the non-zero
+          // values to be stored off of the principal diagonal (i.e., if
+          // diag ([1,2], 3) is modified to return a diagonal matrix
+          // object instead of a full matrix object).
+
+          octave_value tmp = dispatch_kron (a.diag (), b.diag ());
+          retval = tmp.diag ();
+        }
+      else if (a.is_single_type () || b.is_single_type ())
+        {
+          if (a.is_complex_type ())
+            retval = do_kron<FloatComplexDiagMatrix, FloatComplexMatrix> (a, b);
+          else if (b.is_complex_type ())
+            retval = do_kron<FloatDiagMatrix, FloatComplexMatrix> (a, b);
+          else
+            retval = do_kron<FloatDiagMatrix, FloatMatrix> (a, b);
+        }
+      else
+        {
+          if (a.is_complex_type ())
+            retval = do_kron<ComplexDiagMatrix, ComplexMatrix> (a, b);
+          else if (b.is_complex_type ())
+            retval = do_kron<DiagMatrix, ComplexMatrix> (a, b);
+          else
+            retval = do_kron<DiagMatrix, Matrix> (a, b);
+        }
+    }
+  else if (a.is_sparse_type () || b.is_sparse_type ())
+    {
+      if (a.is_complex_type () || b.is_complex_type ())
+        retval = do_kron<SparseComplexMatrix, SparseComplexMatrix> (a, b);
+      else
+        retval = do_kron<SparseMatrix, SparseMatrix> (a, b);
+    }
+  else if (a.is_single_type () || b.is_single_type ())
+    {
+      if (a.is_complex_type ())
+        retval = do_kron<FloatComplexMatrix, FloatComplexMatrix> (a, b);
+      else if (b.is_complex_type ())
+        retval = do_kron<FloatMatrix, FloatComplexMatrix> (a, b);
+      else
+        retval = do_kron<FloatMatrix, FloatMatrix> (a, b);
+    }
+  else
+    {
+      if (a.is_complex_type ())
+        retval = do_kron<ComplexMatrix, ComplexMatrix> (a, b);
+      else if (b.is_complex_type ())
+        retval = do_kron<Matrix, ComplexMatrix> (a, b);
+      else
+        retval = do_kron<Matrix, Matrix> (a, b);
+    }
+  return retval;
+}
+
+
+DEFUN (kron, args, , "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} kron (@var{A}, @var{B})\n\
+@deftypefnx {Built-in Function} {} kron (@var{A1}, @var{A2}, @dots{})\n\
+Form the Kronecker product of two or more matrices, defined block by \n\
+block as\n\
+\n\
+@example\n\
+x = [ a(i,j)*b ]\n\
+@end example\n\
+\n\
+For example:\n\
+\n\
+@example\n\
+@group\n\
+kron (1:4, ones (3, 1))\n\
+     @result{}  1  2  3  4\n\
+         1  2  3  4\n\
+         1  2  3  4\n\
+@end group\n\
+@end example\n\
+\n\
+If there are more than two input arguments @var{A1}, @var{A2}, @dots{}, \n\
+@var{An} the Kronecker product is computed as\n\
+\n\
+@example\n\
+kron (kron (@var{A1}, @var{A2}), @dots{}, @var{An})\n\
+@end example\n\
+\n\
+@noindent\n\
+Since the Kronecker product is associative, this is well-defined.\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin >= 2)
+    {
+      octave_value a = args(0), b = args(1);
+      retval = dispatch_kron (a, b);
+      for (octave_idx_type i = 2; i < nargin; i++)
+        retval = dispatch_kron (retval, args(i));
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+
+/*
+%!test
+%! x = ones (2);
+%! assert (kron (x, x), ones (4));
+
+%!shared x, y, z
+%! x =  [1, 2];
+%! y =  [-1, -2];
+%! z =  [1,  2,  3,  4; 1,  2,  3,  4; 1,  2,  3,  4];
+%!assert (kron (1:4, ones (3, 1)), z)
+%!assert (kron (x, y, z), kron (kron (x, y), z))
+%!assert (kron (x, y, z), kron (x, kron (y, z)))
+
+%!assert (kron (diag ([1, 2]), diag ([3, 4])), diag ([3, 4, 6, 8]))
+
+%% Test for two diag matrices.  See the comments above in
+%% dispatch_kron for this case.
+%%
+%!test
+%! expected = zeros (16, 16);
+%! expected (1, 11) = 3;
+%! expected (2, 12) = 4;
+%! expected (5, 15) = 6;
+%! expected (6, 16) = 8;
+%! assert (kron (diag ([1, 2], 2), diag ([3, 4], 2)), expected)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/lookup.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,397 @@
+/*
+
+Copyright (C) 2008-2012 VZLU Prague a.s., Czech Republic
+
+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/>.
+
+*/
+
+// Author: Jaroslav Hajek <highegg@gmail.com>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cctype>
+#include <functional>
+#include <algorithm>
+
+#include "dNDArray.h"
+#include "CNDArray.h"
+
+#include "Cell.h"
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "ov.h"
+
+static
+bool
+contains_char (const std::string& str, char c)
+{
+  return (str.find (c) != std::string::npos
+          || str.find (std::toupper (c)) != std::string::npos);
+}
+
+// case-insensitive character comparison functors
+struct icmp_char_lt : public std::binary_function<char, char, bool>
+{
+  bool operator () (char x, char y) const
+    { return std::toupper (x) < std::toupper (y); }
+};
+
+struct icmp_char_gt : public std::binary_function<char, char, bool>
+{
+  bool operator () (char x, char y) const
+    { return std::toupper (x) > std::toupper (y); }
+};
+
+// FIXME -- maybe these should go elsewhere?
+// FIXME -- are they even needed now?
+// case-insensitive ascending comparator
+#if 0
+static bool
+stri_comp_lt (const std::string& a, const std::string& b)
+{
+  return std::lexicographical_compare (a.begin (), a.end (),
+                                       b.begin (), b.end (),
+                                       icmp_char_lt ());
+}
+
+// case-insensitive descending comparator
+static bool
+stri_comp_gt (const std::string& a, const std::string& b)
+{
+  return std::lexicographical_compare (a.begin (), a.end (),
+                                       b.begin (), b.end (),
+                                       icmp_char_gt ());
+}
+#endif
+
+template <class T>
+inline sortmode
+get_sort_mode (const Array<T>& array,
+               typename octave_sort<T>::compare_fcn_type desc_comp
+               = octave_sort<T>::descending_compare)
+{
+  octave_idx_type n = array.numel ();
+  if (n > 1 && desc_comp (array (0), array (n-1)))
+    return DESCENDING;
+  else
+    return ASCENDING;
+}
+
+// FIXME: perhaps there should be octave_value::lookup?
+// The question is, how should it behave w.r.t. the second argument's type.
+// We'd need a dispatch on two arguments. Hmmm...
+
+#define INT_ARRAY_LOOKUP(TYPE) \
+  (table.is_ ## TYPE ## _type () && y.is_ ## TYPE ## _type ()) \
+    retval = do_numeric_lookup (table.TYPE ## _array_value (), \
+                                y.TYPE ## _array_value (), \
+                                left_inf, right_inf, \
+                                match_idx, match_bool);
+template <class ArrayT>
+static octave_value
+do_numeric_lookup (const ArrayT& array, const ArrayT& values,
+                   bool left_inf, bool right_inf,
+                   bool match_idx, bool match_bool)
+{
+  octave_value retval;
+
+  Array<octave_idx_type> idx = array.lookup (values);
+  octave_idx_type n = array.numel (), nval = values.numel ();
+
+  // Post-process.
+  if (match_bool)
+    {
+      boolNDArray match (idx.dims ());
+      for (octave_idx_type i = 0; i < nval; i++)
+        {
+          octave_idx_type j = idx.xelem (i);
+          match.xelem (i) = j != 0 && values(i) == array(j-1);
+        }
+
+      retval = match;
+    }
+  else if (match_idx || left_inf || right_inf)
+    {
+      if (match_idx)
+        {
+          NDArray ridx (idx.dims ());
+
+          for (octave_idx_type i = 0; i < nval; i++)
+            {
+              octave_idx_type j = idx.xelem (i);
+              ridx.xelem (i) = (j != 0 && values(i) == array(j-1)) ? j : 0;
+            }
+
+          retval = ridx;
+        }
+      else if (left_inf && right_inf)
+        {
+          // Results in valid indices. Optimize using lazy index.
+          octave_idx_type zero = 0;
+          for (octave_idx_type i = 0; i < nval; i++)
+            {
+              octave_idx_type j = idx.xelem (i) - 1;
+              idx.xelem (i) = std::max (zero, std::min (j, n-2));
+            }
+
+          retval = idx_vector (idx);
+        }
+      else if (left_inf)
+        {
+          // Results in valid indices. Optimize using lazy index.
+          octave_idx_type zero = 0;
+          for (octave_idx_type i = 0; i < nval; i++)
+            {
+              octave_idx_type j = idx.xelem (i) - 1;
+              idx.xelem (i) = std::max (zero, j);
+            }
+
+          retval = idx_vector (idx);
+        }
+      else if (right_inf)
+        {
+          NDArray ridx (idx.dims ());
+
+          for (octave_idx_type i = 0; i < nval; i++)
+            {
+              octave_idx_type j = idx.xelem (i);
+              ridx.xelem (i) = std::min (j, n-1);
+            }
+
+          retval = ridx;
+        }
+    }
+  else
+    retval = idx;
+
+  return retval;
+}
+
+DEFUN (lookup, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{idx} =} lookup (@var{table}, @var{y})\n\
+@deftypefnx {Built-in Function} {@var{idx} =} lookup (@var{table}, @var{y}, @var{opt})\n\
+Lookup values in a sorted table.  Usually used as a prelude to\n\
+interpolation.\n\
+\n\
+If table is increasing and @code{idx = lookup (table, y)}, then\n\
+@code{table(idx(i)) <= y(i) < table(idx(i+1))} for all @code{y(i)}\n\
+within the table.  If @code{y(i) < table(1)} then\n\
+@code{idx(i)} is 0. If @code{y(i) >= table(end)} or @code{isnan (y(i))} then\n\
+@code{idx(i)} is @code{n}.\n\
+\n\
+If the table is decreasing, then the tests are reversed.\n\
+For non-strictly monotonic tables, empty intervals are always skipped.\n\
+The result is undefined if @var{table} is not monotonic, or if\n\
+@var{table} contains a NaN.\n\
+\n\
+The complexity of the lookup is O(M*log(N)) where N is the size of\n\
+@var{table} and M is the size of @var{y}.  In the special case when @var{y}\n\
+is also sorted, the complexity is O(min(M*log(N),M+N)).\n\
+\n\
+@var{table} and @var{y} can also be cell arrays of strings\n\
+(or @var{y} can be a single string).  In this case, string lookup\n\
+is performed using lexicographical comparison.\n\
+\n\
+If @var{opts} is specified, it must be a string with letters indicating\n\
+additional options.\n\
+\n\
+@table @code\n\
+@item m\n\
+@code{table(idx(i)) == val(i)} if @code{val(i)}\n\
+occurs in table; otherwise, @code{idx(i)} is zero.\n\
+\n\
+@item b\n\
+@code{idx(i)} is a logical 1 or 0, indicating whether\n\
+@code{val(i)} is contained in table or not.\n\
+\n\
+@item l\n\
+For numeric lookups\n\
+the leftmost subinterval shall be extended to infinity (i.e., all indices\n\
+at least 1)\n\
+\n\
+@item r\n\
+For numeric lookups\n\
+the rightmost subinterval shall be extended to infinity (i.e., all indices\n\
+at most n-1).\n\
+@end table\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 2 || nargin > 3 || (nargin == 3 && ! args(2).is_string ()))
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value table = args(0), y = args(1);
+  if (table.ndims () > 2 || (table.columns () > 1 && table.rows () > 1))
+    warning ("lookup: table is not a vector");
+
+  bool num_case = ((table.is_numeric_type () && y.is_numeric_type ())
+                   || (table.is_char_matrix () && y.is_char_matrix ()));
+  bool str_case = table.is_cellstr () && (y.is_string () || y.is_cellstr ());
+  bool left_inf = false;
+  bool right_inf = false;
+  bool match_idx = false;
+  bool match_bool = false;
+
+  if (nargin == 3)
+    {
+      std::string opt = args(2).string_value ();
+      left_inf = contains_char (opt, 'l');
+      right_inf = contains_char (opt, 'r');
+      match_idx = contains_char (opt, 'm');
+      match_bool = contains_char (opt, 'b');
+      if (opt.find_first_not_of ("lrmb") != std::string::npos)
+        {
+          error ("lookup: unrecognized option: %c",
+                 opt[opt.find_first_not_of ("lrmb")]);
+          return retval;
+        }
+    }
+
+  if ((match_idx || match_bool) && (left_inf || right_inf))
+    error ("lookup: m, b cannot be specified with l or r");
+  else if (match_idx && match_bool)
+    error ("lookup: only one of m or b can be specified");
+  else if (str_case && (left_inf || right_inf))
+    error ("lookup: l, r are not recognized for string lookups");
+
+  if (error_state)
+    return retval;
+
+  if (num_case)
+    {
+
+      // In the case of a complex array, absolute values will be used for compatibility
+      // (though it's not too meaningful).
+
+      if (table.is_complex_type ())
+        table = table.abs ();
+
+      if (y.is_complex_type ())
+        y = y.abs ();
+
+      Array<octave_idx_type> idx;
+
+      // PS: I learned this from data.cc
+      if INT_ARRAY_LOOKUP (int8)
+      else if INT_ARRAY_LOOKUP (int16)
+      else if INT_ARRAY_LOOKUP (int32)
+      else if INT_ARRAY_LOOKUP (int64)
+      else if INT_ARRAY_LOOKUP (uint8)
+      else if INT_ARRAY_LOOKUP (uint16)
+      else if INT_ARRAY_LOOKUP (uint32)
+      else if INT_ARRAY_LOOKUP (uint64)
+      else if (table.is_char_matrix () && y.is_char_matrix ())
+        retval = do_numeric_lookup (table.char_array_value (),
+                                    y.char_array_value (),
+                                    left_inf, right_inf,
+                                    match_idx, match_bool);
+      else if (table.is_single_type () || y.is_single_type ())
+        retval = do_numeric_lookup (table.float_array_value (),
+                                    y.float_array_value (),
+                                    left_inf, right_inf,
+                                    match_idx, match_bool);
+      else
+        retval = do_numeric_lookup (table.array_value (),
+                                    y.array_value (),
+                                    left_inf, right_inf,
+                                    match_idx, match_bool);
+
+    }
+  else if (str_case)
+    {
+      Array<std::string> str_table = table.cellstr_value ();
+      Array<std::string> str_y (dim_vector (1, 1));
+
+      if (y.is_cellstr ())
+        str_y = y.cellstr_value ();
+      else
+        str_y(0) = y.string_value ();
+
+      Array<octave_idx_type> idx = str_table.lookup (str_y);
+      octave_idx_type nval = str_y.numel ();
+
+      // Post-process.
+      if (match_bool)
+        {
+          boolNDArray match (idx.dims ());
+          for (octave_idx_type i = 0; i < nval; i++)
+            {
+              octave_idx_type j = idx.xelem (i);
+              match.xelem (i) = j != 0 && str_y(i) == str_table(j-1);
+            }
+
+          retval = match;
+        }
+      else if (match_idx)
+        {
+          NDArray ridx (idx.dims ());
+          if (match_idx)
+            {
+              for (octave_idx_type i = 0; i < nval; i++)
+                {
+                  octave_idx_type j = idx.xelem (i);
+                  ridx.xelem (i) = (j != 0 && str_y(i) == str_table(j-1)) ? j : 0;
+                }
+            }
+
+          retval = ridx;
+        }
+      else
+        retval = idx;
+    }
+  else
+    print_usage ();
+
+  return retval;
+
+}
+
+/*
+%!assert (lookup (1:3, 0.5), 0)     # value before table
+%!assert (lookup (1:3, 3.5), 3)     # value after table error
+%!assert (lookup (1:3, 1.5), 1)     # value within table error
+%!assert (lookup (1:3, [3,2,1]), [3,2,1])
+%!assert (lookup ([1:4]', [1.2, 3.5]'), [1, 3]')
+%!assert (lookup ([1:4], [1.2, 3.5]'), [1, 3]')
+%!assert (lookup ([1:4]', [1.2, 3.5]), [1, 3])
+%!assert (lookup ([1:4], [1.2, 3.5]), [1, 3])
+%!assert (lookup (1:3, [3, 2, 1]), [3, 2, 1])
+%!assert (lookup ([3:-1:1], [3.5, 3, 1.2, 2.5, 2.5]), [0, 1, 2, 1, 1])
+%!assert (isempty (lookup ([1:3], [])))
+%!assert (isempty (lookup ([1:3]', [])))
+%!assert (lookup (1:3, [1, 2; 3, 0.5]), [1, 2; 3, 0])
+%!assert (lookup (1:4, [1, 1.2; 3, 2.5], "m"), [1, 0; 3, 0])
+%!assert (lookup (4:-1:1, [1, 1.2; 3, 2.5], "m"), [4, 0; 2, 0])
+%!assert (lookup (1:4, [1, 1.2; 3, 2.5], "b"), logical ([1, 0; 3, 0]))
+%!assert (lookup (4:-1:1, [1, 1.2; 3, 2.5], "b"), logical ([4, 0; 2, 0]))
+%!
+%!assert (lookup ({"apple","lemon","orange"}, {"banana","kiwi"; "ananas","mango"}), [1,1;0,2])
+%!assert (lookup ({"apple","lemon","orange"}, "potato"), 3)
+%!assert (lookup ({"orange","lemon","apple"}, "potato"), 0)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/lsode.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,548 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+
+#include <iomanip>
+#include <iostream>
+
+#include "LSODE.h"
+#include "lo-mappers.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "ov-fcn.h"
+#include "ov-cell.h"
+#include "pager.h"
+#include "pr-output.h"
+#include "unwind-prot.h"
+#include "utils.h"
+#include "variables.h"
+
+#include "LSODE-opts.cc"
+
+// Global pointer for user defined function required by lsode.
+static octave_function *lsode_fcn;
+
+// Global pointer for optional user defined jacobian function used by lsode.
+static octave_function *lsode_jac;
+
+// Have we warned about imaginary values returned from user function?
+static bool warned_fcn_imaginary = false;
+static bool warned_jac_imaginary = false;
+
+// Is this a recursive call?
+static int call_depth = 0;
+
+ColumnVector
+lsode_user_function (const ColumnVector& x, double t)
+{
+  ColumnVector retval;
+
+  octave_value_list args;
+  args(1) = t;
+  args(0) = x;
+
+  if (lsode_fcn)
+    {
+      octave_value_list tmp = lsode_fcn->do_multi_index_op (1, args);
+
+      if (error_state)
+        {
+          gripe_user_supplied_eval ("lsode");
+          return retval;
+        }
+
+      if (tmp.length () > 0 && tmp(0).is_defined ())
+        {
+          if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
+            {
+              warning ("lsode: ignoring imaginary part returned from user-supplied function");
+              warned_fcn_imaginary = true;
+            }
+
+          retval = ColumnVector (tmp(0).vector_value ());
+
+          if (error_state || retval.length () == 0)
+            gripe_user_supplied_eval ("lsode");
+        }
+      else
+        gripe_user_supplied_eval ("lsode");
+    }
+
+  return retval;
+}
+
+Matrix
+lsode_user_jacobian (const ColumnVector& x, double t)
+{
+  Matrix retval;
+
+  octave_value_list args;
+  args(1) = t;
+  args(0) = x;
+
+  if (lsode_jac)
+    {
+      octave_value_list tmp = lsode_jac->do_multi_index_op (1, args);
+
+      if (error_state)
+        {
+          gripe_user_supplied_eval ("lsode");
+          return retval;
+        }
+
+      if (tmp.length () > 0 && tmp(0).is_defined ())
+        {
+          if (! warned_jac_imaginary && tmp(0).is_complex_type ())
+            {
+              warning ("lsode: ignoring imaginary part returned from user-supplied jacobian function");
+              warned_jac_imaginary = true;
+            }
+
+          retval = tmp(0).matrix_value ();
+
+          if (error_state || retval.length () == 0)
+            gripe_user_supplied_eval ("lsode");
+        }
+      else
+        gripe_user_supplied_eval ("lsode");
+    }
+
+  return retval;
+}
+
+#define LSODE_ABORT() \
+  return retval
+
+#define LSODE_ABORT1(msg) \
+  do \
+    { \
+      ::error ("lsode: " msg); \
+      LSODE_ABORT (); \
+    } \
+  while (0)
+
+#define LSODE_ABORT2(fmt, arg) \
+  do \
+    { \
+      ::error ("lsode: " fmt, arg); \
+      LSODE_ABORT (); \
+    } \
+  while (0)
+
+DEFUN (lsode, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {[@var{x}, @var{istate}, @var{msg}] =} lsode (@var{fcn}, @var{x_0}, @var{t})\n\
+@deftypefnx {Built-in Function} {[@var{x}, @var{istate}, @var{msg}] =} lsode (@var{fcn}, @var{x_0}, @var{t}, @var{t_crit})\n\
+Solve the set of differential equations\n\
+@tex\n\
+$$ {dx \\over dt} = f (x, t) $$\n\
+with\n\
+$$ x(t_0) = x_0 $$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+@group\n\
+dx\n\
+-- = f (x, t)\n\
+dt\n\
+@end group\n\
+@end example\n\
+\n\
+@noindent\n\
+with\n\
+\n\
+@example\n\
+x(t_0) = x_0\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+The solution is returned in the matrix @var{x}, with each row\n\
+corresponding to an element of the vector @var{t}.  The first element\n\
+of @var{t} should be @math{t_0} and should correspond to the initial\n\
+state of the system @var{x_0}, so that the first row of the output\n\
+is @var{x_0}.\n\
+\n\
+The first argument, @var{fcn}, is a string, inline, or function handle\n\
+that names the function @math{f} to call to compute the vector of right\n\
+hand sides for the set of equations.  The function must have the form\n\
+\n\
+@example\n\
+@var{xdot} = f (@var{x}, @var{t})\n\
+@end example\n\
+\n\
+@noindent\n\
+in which @var{xdot} and @var{x} are vectors and @var{t} is a scalar.\n\
+\n\
+If @var{fcn} is a two-element string array or a two-element cell array\n\
+of strings, inline functions, or function handles, the first element names\n\
+the function @math{f} described above, and the second element names a\n\
+function to compute the Jacobian of @math{f}.  The Jacobian function\n\
+must have the form\n\
+\n\
+@example\n\
+@var{jac} = j (@var{x}, @var{t})\n\
+@end example\n\
+\n\
+@noindent\n\
+in which @var{jac} is the matrix of partial derivatives\n\
+@tex\n\
+$$ J = {\\partial f_i \\over \\partial x_j} = \\left[\\matrix{\n\
+{\\partial f_1 \\over \\partial x_1}\n\
+  & {\\partial f_1 \\over \\partial x_2}\n\
+  & \\cdots\n\
+  & {\\partial f_1 \\over \\partial x_N} \\cr\n\
+{\\partial f_2 \\over \\partial x_1}\n\
+  & {\\partial f_2 \\over \\partial x_2}\n\
+  & \\cdots\n\
+  & {\\partial f_2 \\over \\partial x_N} \\cr\n\
+ \\vdots & \\vdots & \\ddots & \\vdots \\cr\n\
+{\\partial f_3 \\over \\partial x_1}\n\
+  & {\\partial f_3 \\over \\partial x_2}\n\
+  & \\cdots\n\
+  & {\\partial f_3 \\over \\partial x_N} \\cr}\\right]$$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+@group\n\
+             | df_1  df_1       df_1 |\n\
+             | ----  ----  ...  ---- |\n\
+             | dx_1  dx_2       dx_N |\n\
+             |                       |\n\
+             | df_2  df_2       df_2 |\n\
+             | ----  ----  ...  ---- |\n\
+      df_i   | dx_1  dx_2       dx_N |\n\
+jac = ---- = |                       |\n\
+      dx_j   |  .    .     .    .    |\n\
+             |  .    .      .   .    |\n\
+             |  .    .       .  .    |\n\
+             |                       |\n\
+             | df_N  df_N       df_N |\n\
+             | ----  ----  ...  ---- |\n\
+             | dx_1  dx_2       dx_N |\n\
+@end group\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+\n\
+The second and third arguments specify the initial state of the system,\n\
+@math{x_0}, and the initial value of the independent variable @math{t_0}.\n\
+\n\
+The fourth argument is optional, and may be used to specify a set of\n\
+times that the ODE solver should not integrate past.  It is useful for\n\
+avoiding difficulties with singularities and points where there is a\n\
+discontinuity in the derivative.\n\
+\n\
+After a successful computation, the value of @var{istate} will be 2\n\
+(consistent with the Fortran version of @sc{lsode}).\n\
+\n\
+If the computation is not successful, @var{istate} will be something\n\
+other than 2 and @var{msg} will contain additional information.\n\
+\n\
+You can use the function @code{lsode_options} to set optional\n\
+parameters for @code{lsode}.\n\
+@seealso{daspk, dassl, dasrt}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  warned_fcn_imaginary = false;
+  warned_jac_imaginary = false;
+
+  unwind_protect frame;
+
+  frame.protect_var (call_depth);
+  call_depth++;
+
+  if (call_depth > 1)
+    LSODE_ABORT1 ("invalid recursive call");
+
+  int nargin = args.length ();
+
+  if (nargin > 2 && nargin < 5 && nargout < 4)
+    {
+      std::string fcn_name, fname, jac_name, jname;
+      lsode_fcn = 0;
+      lsode_jac = 0;
+
+      octave_value f_arg = args(0);
+
+      if (f_arg.is_cell ())
+        {
+          Cell c = f_arg.cell_value ();
+          if (c.length () == 1)
+            f_arg = c(0);
+          else if (c.length () == 2)
+            {
+              if (c(0).is_function_handle () || c(0).is_inline_function ())
+                lsode_fcn = c(0).function_value ();
+              else
+                {
+                  fcn_name = unique_symbol_name ("__lsode_fcn__");
+                  fname = "function y = ";
+                  fname.append (fcn_name);
+                  fname.append (" (x, t) y = ");
+                  lsode_fcn = extract_function
+                    (c(0), "lsode", fcn_name, fname, "; endfunction");
+                }
+
+              if (lsode_fcn)
+                {
+                  if (c(1).is_function_handle () || c(1).is_inline_function ())
+                    lsode_jac = c(1).function_value ();
+                  else
+                    {
+                        jac_name = unique_symbol_name ("__lsode_jac__");
+                        jname = "function jac = ";
+                        jname.append (jac_name);
+                        jname.append (" (x, t) jac = ");
+                        lsode_jac = extract_function
+                          (c(1), "lsode", jac_name, jname, "; endfunction");
+
+                      if (!lsode_jac)
+                        {
+                          if (fcn_name.length ())
+                            clear_function (fcn_name);
+                          lsode_fcn = 0;
+                        }
+                    }
+                }
+            }
+          else
+            LSODE_ABORT1 ("incorrect number of elements in cell array");
+        }
+
+      if (!lsode_fcn && ! f_arg.is_cell ())
+        {
+          if (f_arg.is_function_handle () || f_arg.is_inline_function ())
+            lsode_fcn = f_arg.function_value ();
+          else
+            {
+              switch (f_arg.rows ())
+                {
+                case 1:
+                  do
+                    {
+                      fcn_name = unique_symbol_name ("__lsode_fcn__");
+                      fname = "function y = ";
+                      fname.append (fcn_name);
+                      fname.append (" (x, t) y = ");
+                      lsode_fcn = extract_function
+                        (f_arg, "lsode", fcn_name, fname, "; endfunction");
+                    }
+                  while (0);
+                  break;
+
+                case 2:
+                  {
+                    string_vector tmp = f_arg.all_strings ();
+
+                    if (! error_state)
+                      {
+                        fcn_name = unique_symbol_name ("__lsode_fcn__");
+                        fname = "function y = ";
+                        fname.append (fcn_name);
+                        fname.append (" (x, t) y = ");
+                        lsode_fcn = extract_function
+                          (tmp(0), "lsode", fcn_name, fname, "; endfunction");
+
+                        if (lsode_fcn)
+                          {
+                            jac_name = unique_symbol_name ("__lsode_jac__");
+                            jname = "function jac = ";
+                            jname.append (jac_name);
+                            jname.append (" (x, t) jac = ");
+                            lsode_jac = extract_function
+                              (tmp(1), "lsode", jac_name, jname,
+                              "; endfunction");
+
+                            if (!lsode_jac)
+                              {
+                                if (fcn_name.length ())
+                                  clear_function (fcn_name);
+                                lsode_fcn = 0;
+                              }
+                          }
+                      }
+                  }
+                  break;
+
+                default:
+                  LSODE_ABORT1
+                    ("first arg should be a string or 2-element string array");
+                }
+            }
+        }
+
+      if (error_state || ! lsode_fcn)
+        LSODE_ABORT ();
+
+      ColumnVector state (args(1).vector_value ());
+
+      if (error_state)
+        LSODE_ABORT1 ("expecting state vector as second argument");
+
+      ColumnVector out_times (args(2).vector_value ());
+
+      if (error_state)
+        LSODE_ABORT1 ("expecting output time vector as third argument");
+
+      ColumnVector crit_times;
+
+      int crit_times_set = 0;
+      if (nargin > 3)
+        {
+          crit_times = ColumnVector (args(3).vector_value ());
+
+          if (error_state)
+            LSODE_ABORT1 ("expecting critical time vector as fourth argument");
+
+          crit_times_set = 1;
+        }
+
+      double tzero = out_times (0);
+
+      ODEFunc func (lsode_user_function);
+      if (lsode_jac)
+        func.set_jacobian_function (lsode_user_jacobian);
+
+      LSODE ode (state, tzero, func);
+
+      ode.set_options (lsode_opts);
+
+      Matrix output;
+      if (crit_times_set)
+        output = ode.integrate (out_times, crit_times);
+      else
+        output = ode.integrate (out_times);
+
+      if (fcn_name.length ())
+        clear_function (fcn_name);
+      if (jac_name.length ())
+        clear_function (jac_name);
+
+      if (! error_state)
+        {
+          std::string msg = ode.error_message ();
+
+          retval(2) = msg;
+          retval(1) = static_cast<double> (ode.integration_state ());
+
+          if (ode.integration_ok ())
+            retval(0) = output;
+          else
+            {
+              retval(0) = Matrix ();
+
+              if (nargout < 2)
+                error ("lsode: %s", msg.c_str ());
+            }
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+
+## dassl-1.m
+##
+## Test lsode() function
+##
+## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+##         Comalco Research and Technology
+##         20 May 1998
+##
+## Problem
+##
+##    y1' = -y2,   y1(0) = 1
+##    y2' =  y1,   y2(0) = 0
+##
+## Solution
+##
+##    y1(t) = cos(t)
+##    y2(t) = sin(t)
+##
+%!function xdot = __f (x, t)
+%!  xdot = [-x(2); x(1)];
+%!endfunction
+%!test
+%!
+%! x0 = [1; 0];
+%! xdot0 = [0; 1];
+%! t = (0:1:10)';
+%!
+%! tol = 500 * lsode_options ("relative tolerance");
+%!
+%! x = lsode ("__f", x0, t);
+%!
+%! y = [cos(t), sin(t)];
+%!
+%! assert (x, y, tol);
+
+%!function xdotdot = __f (x, t)
+%!  xdotdot = [x(2); -x(1)];
+%!endfunction
+%!test
+%!
+%! x0 = [1; 0];
+%! t = [0; 2*pi];
+%! tol = 100 * dassl_options ("relative tolerance");
+%!
+%! x = lsode ("__f", x0, t);
+%!
+%! y = [1, 0; 1, 0];
+%!
+%! assert (x, y, tol);
+
+%!function xdot = __f (x, t)
+%!  xdot = x;
+%!endfunction
+%!test
+%!
+%! x0 = 1;
+%! t = [0; 1];
+%! tol = 100 * dassl_options ("relative tolerance");
+%!
+%! x = lsode ("__f", x0, t);
+%!
+%! y = [1; e];
+%!
+%! assert (x, y, tol);
+
+%!test
+%! lsode_options ("absolute tolerance", eps);
+%! assert (lsode_options ("absolute tolerance") == eps);
+
+%!error lsode_options ("foo", 1, 2)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/lu.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,857 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CmplxLU.h"
+#include "dbleLU.h"
+#include "fCmplxLU.h"
+#include "floatLU.h"
+#include "SparseCmplxLU.h"
+#include "SparsedbleLU.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+#include "ov-re-sparse.h"
+#include "ov-cx-sparse.h"
+
+template <class MT>
+static octave_value
+get_lu_l (const base_lu<MT>& fact)
+{
+  MT L = fact.L ();
+  if (L.is_square ())
+    return octave_value (L, MatrixType (MatrixType::Lower));
+  else
+    return L;
+}
+
+template <class MT>
+static octave_value
+get_lu_u (const base_lu<MT>& fact)
+{
+  MT U = fact.U ();
+  if (U.is_square () && fact.regular ())
+    return octave_value (U, MatrixType (MatrixType::Upper));
+  else
+    return U;
+}
+
+DEFUN (lu, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {[@var{L}, @var{U}] =} lu (@var{A})\n\
+@deftypefnx {Built-in Function} {[@var{L}, @var{U}, @var{P}] =} lu (@var{A})\n\
+@deftypefnx {Built-in Function} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} lu (@var{S})\n\
+@deftypefnx {Built-in Function} {[@var{L}, @var{U}, @var{P}, @var{Q}, @var{R}] =} lu (@var{S})\n\
+@deftypefnx {Built-in Function} {[@dots{}] =} lu (@var{S}, @var{thres})\n\
+@deftypefnx {Built-in Function} {@var{y} =} lu (@dots{})\n\
+@deftypefnx {Built-in Function} {[@dots{}] =} lu (@dots{}, \"vector\")\n\
+@cindex LU decomposition\n\
+Compute the LU@tie{}decomposition of @var{A}.  If @var{A} is full\n\
+subroutines from\n\
+@sc{lapack} are used and if @var{A} is sparse then @sc{umfpack} is used.  The\n\
+result is returned in a permuted form, according to the optional return\n\
+value @var{P}.  For example, given the matrix @code{a = [1, 2; 3, 4]},\n\
+\n\
+@example\n\
+[l, u, p] = lu (@var{a})\n\
+@end example\n\
+\n\
+@noindent\n\
+returns\n\
+\n\
+@example\n\
+@group\n\
+l =\n\
+\n\
+  1.00000  0.00000\n\
+  0.33333  1.00000\n\
+\n\
+u =\n\
+\n\
+  3.00000  4.00000\n\
+  0.00000  0.66667\n\
+\n\
+p =\n\
+\n\
+  0  1\n\
+  1  0\n\
+@end group\n\
+@end example\n\
+\n\
+The matrix is not required to be square.\n\
+\n\
+When called with two or three output arguments and a spare input matrix,\n\
+@code{lu} does not attempt to perform sparsity preserving column\n\
+permutations.  Called with a fourth output argument, the sparsity\n\
+preserving column transformation @var{Q} is returned, such that\n\
+@code{@var{P} * @var{A} * @var{Q} = @var{L} * @var{U}}.\n\
+\n\
+Called with a fifth output argument and a sparse input matrix,\n\
+@code{lu} attempts to use a scaling factor @var{R} on the input matrix\n\
+such that\n\
+@code{@var{P} * (@var{R} \\ @var{A}) * @var{Q} = @var{L} * @var{U}}.\n\
+This typically leads to a sparser and more stable factorization.\n\
+\n\
+An additional input argument @var{thres}, that defines the pivoting\n\
+threshold can be given.  @var{thres} can be a scalar, in which case\n\
+it defines the @sc{umfpack} pivoting tolerance for both symmetric and\n\
+unsymmetric cases.  If @var{thres} is a 2-element vector, then the first\n\
+element defines the pivoting tolerance for the unsymmetric @sc{umfpack}\n\
+pivoting strategy and the second for the symmetric strategy.  By default,\n\
+the values defined by @code{spparms} are used ([0.1, 0.001]).\n\
+\n\
+Given the string argument \"vector\", @code{lu} returns the values of @var{P}\n\
+and @var{Q} as vector values, such that for full matrix, @code{@var{A}\n\
+(@var{P},:) = @var{L} * @var{U}}, and @code{@var{R}(@var{P},:) * @var{A}\n\
+(:, @var{Q}) = @var{L} * @var{U}}.\n\
+\n\
+With two output arguments, returns the permuted forms of the upper and\n\
+lower triangular matrices, such that @code{@var{A} = @var{L} * @var{U}}.\n\
+With one output argument @var{y}, then the matrix returned by the @sc{lapack}\n\
+routines is returned.  If the input matrix is sparse then the matrix @var{L}\n\
+is embedded into @var{U} to give a return value similar to the full case.\n\
+For both full and sparse matrices, @code{lu} loses the permutation\n\
+information.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+  int nargin = args.length ();
+  bool issparse = (nargin > 0 && args(0).is_sparse_type ());
+  bool scale = (nargout  == 5);
+
+  if (nargin < 1 || (issparse && (nargin > 3 || nargout > 5))
+      || (!issparse && (nargin > 2 || nargout > 3)))
+    {
+      print_usage ();
+      return retval;
+    }
+
+  bool vecout = false;
+  Matrix thres;
+
+  int n = 1;
+  while (n < nargin && ! error_state)
+    {
+      if (args (n).is_string ())
+        {
+          std::string tmp = args(n++).string_value ();
+
+          if (! error_state )
+            {
+              if (tmp.compare ("vector") == 0)
+                vecout = true;
+              else
+                error ("lu: unrecognized string argument");
+            }
+        }
+      else
+        {
+          Matrix tmp = args(n++).matrix_value ();
+
+          if (! error_state )
+            {
+              if (!issparse)
+                error ("lu: can not define pivoting threshold THRES for full matrices");
+              else if (tmp.nelem () == 1)
+                {
+                  thres.resize (1,2);
+                  thres(0) = tmp(0);
+                  thres(1) = tmp(0);
+                }
+              else if (tmp.nelem () == 2)
+                thres = tmp;
+              else
+                error ("lu: expecting 2-element vector for THRES");
+            }
+        }
+    }
+
+  octave_value arg = args(0);
+
+  octave_idx_type nr = arg.rows ();
+  octave_idx_type nc = arg.columns ();
+
+  int arg_is_empty = empty_arg ("lu", nr, nc);
+
+  if (issparse)
+    {
+      if (arg_is_empty < 0)
+        return retval;
+      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)
+            {
+            case 0:
+            case 1:
+            case 2:
+              {
+                SparseLU fact (m, Qinit, thres, false, true);
+
+                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));
+
+                    retval(0) = octave_value (L,
+                        MatrixType (MatrixType::Permuted_Lower,
+                                    nr, fact.row_perm ()));
+                  }
+              }
+              break;
+
+            case 3:
+              {
+                SparseLU fact (m, Qinit, thres, false, true);
+
+                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;
+
+            case 4:
+            default:
+              {
+                SparseLU fact (m, thres, scale);
+
+                if (scale)
+                  retval(4) = fact.R ();
+
+                if (vecout)
+                  {
+                    retval(3) = fact.Pc_vec ();
+                    retval(2) = fact.Pr_vec ();
+                  }
+                else
+                  {
+                    retval(3) = fact.Pc_mat ();
+                    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 if (arg.is_complex_type ())
+        {
+          SparseComplexMatrix m = arg.sparse_complex_matrix_value ();
+
+          switch (nargout)
+            {
+            case 0:
+            case 1:
+            case 2:
+              {
+                SparseComplexLU fact (m, Qinit, thres, false, true);
+
+                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));
+
+                    retval(0) = octave_value (L,
+                        MatrixType (MatrixType::Permuted_Lower,
+                                    nr, fact.row_perm ()));
+                  }
+              }
+              break;
+
+            case 3:
+              {
+                SparseComplexLU fact (m, Qinit, thres, false, true);
+
+                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;
+
+            case 4:
+            default:
+              {
+                SparseComplexLU fact (m, thres, scale);
+
+                if (scale)
+                  retval(4) = fact.R ();
+
+                if (vecout)
+                  {
+                    retval(3) = fact.Pc_vec ();
+                    retval(2) = fact.Pr_vec ();
+                  }
+                else
+                  {
+                    retval(3) = fact.Pc_mat ();
+                    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
+        gripe_wrong_type_arg ("lu", arg);
+    }
+  else
+    {
+      if (arg_is_empty < 0)
+        return retval;
+      else if (arg_is_empty > 0)
+        return octave_value_list (3, Matrix ());
+
+      if (arg.is_real_type ())
+        {
+          if (arg.is_single_type ())
+            {
+              FloatMatrix m = arg.float_matrix_value ();
+
+              if (! error_state)
+                {
+                  FloatLU fact (m);
+
+                  switch (nargout)
+                    {
+                    case 0:
+                    case 1:
+                      retval(0) = fact.Y ();
+                      break;
+
+                    case 2:
+                      {
+                        PermMatrix P = fact.P ();
+                        FloatMatrix L = P.transpose () * fact.L ();
+                        retval(1) = get_lu_u (fact);
+                        retval(0) = L;
+                      }
+                      break;
+
+                    case 3:
+                    default:
+                      {
+                        if (vecout)
+                          retval(2) = fact.P_vec ();
+                        else
+                          retval(2) = fact.P ();
+                        retval(1) = get_lu_u (fact);
+                        retval(0) = get_lu_l (fact);
+                      }
+                      break;
+                    }
+                }
+            }
+          else
+            {
+              Matrix m = arg.matrix_value ();
+
+              if (! error_state)
+                {
+                  LU fact (m);
+
+                  switch (nargout)
+                    {
+                    case 0:
+                    case 1:
+                      retval(0) = fact.Y ();
+                      break;
+
+                    case 2:
+                      {
+                        PermMatrix P = fact.P ();
+                        Matrix L = P.transpose () * fact.L ();
+                        retval(1) = get_lu_u (fact);
+                        retval(0) = L;
+                      }
+                      break;
+
+                    case 3:
+                    default:
+                      {
+                        if (vecout)
+                          retval(2) = fact.P_vec ();
+                        else
+                          retval(2) = fact.P ();
+                        retval(1) = get_lu_u (fact);
+                        retval(0) = get_lu_l (fact);
+                      }
+                      break;
+                    }
+                }
+            }
+        }
+      else if (arg.is_complex_type ())
+        {
+          if (arg.is_single_type ())
+            {
+              FloatComplexMatrix m = arg.float_complex_matrix_value ();
+
+              if (! error_state)
+                {
+                  FloatComplexLU fact (m);
+
+                  switch (nargout)
+                    {
+                    case 0:
+                    case 1:
+                      retval(0) = fact.Y ();
+                      break;
+
+                    case 2:
+                      {
+                        PermMatrix P = fact.P ();
+                        FloatComplexMatrix L = P.transpose () * fact.L ();
+                        retval(1) = get_lu_u (fact);
+                        retval(0) = L;
+                      }
+                      break;
+
+                    case 3:
+                    default:
+                      {
+                        if (vecout)
+                          retval(2) = fact.P_vec ();
+                        else
+                          retval(2) = fact.P ();
+                        retval(1) = get_lu_u (fact);
+                        retval(0) = get_lu_l (fact);
+                      }
+                      break;
+                    }
+                }
+            }
+          else
+            {
+              ComplexMatrix m = arg.complex_matrix_value ();
+
+              if (! error_state)
+                {
+                  ComplexLU fact (m);
+
+                  switch (nargout)
+                    {
+                    case 0:
+                    case 1:
+                      retval(0) = fact.Y ();
+                      break;
+
+                    case 2:
+                      {
+                        PermMatrix P = fact.P ();
+                        ComplexMatrix L = P.transpose () * fact.L ();
+                        retval(1) = get_lu_u (fact);
+                        retval(0) = L;
+                      }
+                      break;
+
+                    case 3:
+                    default:
+                      {
+                        if (vecout)
+                          retval(2) = fact.P_vec ();
+                        else
+                          retval(2) = fact.P ();
+                        retval(1) = get_lu_u (fact);
+                        retval(0) = get_lu_l (fact);
+                      }
+                      break;
+                    }
+                }
+            }
+        }
+      else
+        gripe_wrong_type_arg ("lu", arg);
+    }
+
+  return retval;
+}
+
+/*
+%!assert(lu ([1, 2; 3, 4]), [3, 4; 1/3, 2/3], eps);
+
+%!test
+%! [l, u] = lu ([1, 2; 3, 4]);
+%! assert (l, [1/3, 1; 1, 0], sqrt (eps));
+%! assert (u, [3, 4; 0, 2/3], sqrt (eps));
+
+%!test
+%! [l, u, p] = lu ([1, 2; 3, 4]);
+%! assert (l, [1, 0; 1/3, 1], sqrt (eps));
+%! assert (u, [3, 4; 0, 2/3], sqrt (eps));
+%! assert (p(:,:), [0, 1; 1, 0], sqrt (eps));
+
+%!test
+%! [l, u, p] = lu ([1, 2; 3, 4], "vector");
+%! assert (l, [1, 0; 1/3, 1], sqrt (eps));
+%! assert (u, [3, 4; 0, 2/3], sqrt (eps));
+%! assert (p, [2;1], sqrt (eps));
+
+%!test
+%! [l, u, p] = lu ([1, 2; 3, 4; 5, 6]);
+%! assert (l, [1, 0; 1/5, 1; 3/5, 1/2], sqrt (eps));
+%! assert (u, [5, 6; 0, 4/5], sqrt (eps));
+%! assert (p(:,:), [0, 0, 1; 1, 0, 0; 0 1 0], sqrt (eps));
+
+%!assert (lu (single ([1, 2; 3, 4])), single ([3, 4; 1/3, 2/3]), eps ("single"))
+
+%!test
+%! [l, u] = lu (single ([1, 2; 3, 4]));
+%! assert (l, single ([1/3, 1; 1, 0]), sqrt (eps ("single")));
+%! assert (u, single ([3, 4; 0, 2/3]), sqrt (eps ("single")));
+
+%!test
+%! [l, u, p] = lu (single ([1, 2; 3, 4]));
+%! assert (l, single ([1, 0; 1/3, 1]), sqrt (eps ("single")));
+%! assert (u, single ([3, 4; 0, 2/3]), sqrt (eps ("single")));
+%! assert (p(:,:), single ([0, 1; 1, 0]), sqrt (eps ("single")));
+
+%!test
+%! [l, u, p] = lu (single ([1, 2; 3, 4]), "vector");
+%! assert (l, single ([1, 0; 1/3, 1]), sqrt (eps ("single")));
+%! assert (u, single ([3, 4; 0, 2/3]), sqrt (eps ("single")));
+%! assert (p, single ([2;1]), sqrt (eps ("single")));
+
+%!test
+%! [l u p] = lu (single ([1, 2; 3, 4; 5, 6]));
+%! assert (l, single ([1, 0; 1/5, 1; 3/5, 1/2]), sqrt (eps ("single")));
+%! assert (u, single ([5, 6; 0, 4/5]), sqrt (eps ("single")));
+%! assert (p(:,:), single ([0, 0, 1; 1, 0, 0; 0 1 0]), sqrt (eps ("single")));
+
+%!error lu ()
+%!error <can not define pivoting threshold> lu ([1, 2; 3, 4], 2)
+*/
+
+static
+bool check_lu_dims (const octave_value& l, const octave_value& u,
+                    const octave_value& p)
+{
+  octave_idx_type m = l.rows (), k = u.rows (), n = u.columns ();
+  return ((l.ndims () == 2 && u.ndims () == 2 && k == l.columns ())
+            && k == std::min (m, n) &&
+            (p.is_undefined () || p.rows () == m));
+}
+
+DEFUN (luupdate, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {[@var{L}, @var{U}] =} luupdate (@var{L}, @var{U}, @var{x}, @var{y})\n\
+@deftypefnx {Built-in Function} {[@var{L}, @var{U}, @var{P}] =} luupdate (@var{L}, @var{U}, @var{P}, @var{x}, @var{y})\n\
+Given an LU@tie{}factorization of a real or complex matrix\n\
+@w{@var{A} = @var{L}*@var{U}}, @var{L}@tie{}lower unit trapezoidal and\n\
+@var{U}@tie{}upper trapezoidal, return the LU@tie{}factorization\n\
+of @w{@var{A} + @var{x}*@var{y}.'}, where @var{x} and @var{y} are\n\
+column vectors (rank-1 update) or matrices with equal number of columns\n\
+(rank-k update).\n\
+Optionally, row-pivoted updating can be used by supplying\n\
+a row permutation (pivoting) matrix @var{P};\n\
+in that case, an updated permutation matrix is returned.\n\
+Note that if @var{L}, @var{U}, @var{P} is a pivoted LU@tie{}factorization\n\
+as obtained by @code{lu}:\n\
+\n\
+@example\n\
+[@var{L}, @var{U}, @var{P}] = lu (@var{A});\n\
+@end example\n\
+\n\
+@noindent\n\
+then a factorization of @xcode{@var{A}+@var{x}*@var{y}.'} can be obtained\n\
+either as\n\
+\n\
+@example\n\
+[@var{L1}, @var{U1}] = lu (@var{L}, @var{U}, @var{P}*@var{x}, @var{y})\n\
+@end example\n\
+\n\
+@noindent\n\
+or\n\
+\n\
+@example\n\
+[@var{L1}, @var{U1}, @var{P1}] = lu (@var{L}, @var{U}, @var{P}, @var{x}, @var{y})\n\
+@end example\n\
+\n\
+The first form uses the unpivoted algorithm, which is faster, but less\n\
+stable.  The second form uses a slower pivoted algorithm, which is more\n\
+stable.\n\
+\n\
+The matrix case is done as a sequence of rank-1 updates;\n\
+thus, for large enough k, it will be both faster and more accurate to\n\
+recompute the factorization from scratch.\n\
+@seealso{lu, qrupdate, cholupdate}\n\
+@end deftypefn")
+{
+  octave_idx_type nargin = args.length ();
+  octave_value_list retval;
+
+  bool pivoted = nargin == 5;
+
+  if (nargin != 4 && nargin != 5)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value argl = args(0);
+  octave_value argu = args(1);
+  octave_value argp = pivoted ? args(2) : octave_value ();
+  octave_value argx = args(2 + pivoted);
+  octave_value argy = args(3 + pivoted);
+
+  if (argl.is_numeric_type () && argu.is_numeric_type ()
+      && argx.is_numeric_type () && argy.is_numeric_type ()
+      && (! pivoted || argp.is_perm_matrix ()))
+    {
+      if (check_lu_dims (argl, argu, argp))
+        {
+          PermMatrix P = (pivoted
+                          ? argp.perm_matrix_value ()
+                          : PermMatrix::eye (argl.rows ()));
+
+          if (argl.is_real_type ()
+              && argu.is_real_type ()
+              && argx.is_real_type ()
+              && argy.is_real_type ())
+            {
+              // all real case
+              if (argl.is_single_type ()
+                  || argu.is_single_type ()
+                  || argx.is_single_type ()
+                  || argy.is_single_type ())
+                {
+                  FloatMatrix L = argl.float_matrix_value ();
+                  FloatMatrix U = argu.float_matrix_value ();
+                  FloatMatrix x = argx.float_matrix_value ();
+                  FloatMatrix y = argy.float_matrix_value ();
+
+                  FloatLU fact (L, U, P);
+                  if (pivoted)
+                    fact.update_piv (x, y);
+                  else
+                    fact.update (x, y);
+
+                  if (pivoted)
+                    retval(2) = fact.P ();
+                  retval(1) = get_lu_u (fact);
+                  retval(0) = get_lu_l (fact);
+                }
+              else
+                {
+                  Matrix L = argl.matrix_value ();
+                  Matrix U = argu.matrix_value ();
+                  Matrix x = argx.matrix_value ();
+                  Matrix y = argy.matrix_value ();
+
+                  LU fact (L, U, P);
+                  if (pivoted)
+                    fact.update_piv (x, y);
+                  else
+                    fact.update (x, y);
+
+                  if (pivoted)
+                    retval(2) = fact.P ();
+                  retval(1) = get_lu_u (fact);
+                  retval(0) = get_lu_l (fact);
+                }
+            }
+          else
+            {
+              // complex case
+              if (argl.is_single_type ()
+                  || argu.is_single_type ()
+                  || argx.is_single_type ()
+                  || argy.is_single_type ())
+                {
+                  FloatComplexMatrix L = argl.float_complex_matrix_value ();
+                  FloatComplexMatrix U = argu.float_complex_matrix_value ();
+                  FloatComplexMatrix x = argx.float_complex_matrix_value ();
+                  FloatComplexMatrix y = argy.float_complex_matrix_value ();
+
+                  FloatComplexLU fact (L, U, P);
+                  if (pivoted)
+                    fact.update_piv (x, y);
+                  else
+                    fact.update (x, y);
+
+                  if (pivoted)
+                    retval(2) = fact.P ();
+                  retval(1) = get_lu_u (fact);
+                  retval(0) = get_lu_l (fact);
+                }
+              else
+                {
+                  ComplexMatrix L = argl.complex_matrix_value ();
+                  ComplexMatrix U = argu.complex_matrix_value ();
+                  ComplexMatrix x = argx.complex_matrix_value ();
+                  ComplexMatrix y = argy.complex_matrix_value ();
+
+                  ComplexLU fact (L, U, P);
+                  if (pivoted)
+                    fact.update_piv (x, y);
+                  else
+                    fact.update (x, y);
+
+                  if (pivoted)
+                    retval(2) = fact.P ();
+                  retval(1) = get_lu_u (fact);
+                  retval(0) = get_lu_l (fact);
+                }
+            }
+        }
+      else
+        error ("luupdate: dimension mismatch");
+    }
+  else
+    error ("luupdate: L, U, X, and Y must be numeric");
+
+  return retval;
+}
+
+/*
+%!shared A, u, v, Ac, uc, vc
+%! A = [0.091364  0.613038  0.999083;
+%!      0.594638  0.425302  0.603537;
+%!      0.383594  0.291238  0.085574;
+%!      0.265712  0.268003  0.238409;
+%!      0.669966  0.743851  0.445057 ];
+%!
+%! u = [0.85082;
+%!      0.76426;
+%!      0.42883;
+%!      0.53010;
+%!      0.80683 ];
+%!
+%! v = [0.98810;
+%!      0.24295;
+%!      0.43167 ];
+%!
+%! Ac = [0.620405 + 0.956953i  0.480013 + 0.048806i  0.402627 + 0.338171i;
+%!       0.589077 + 0.658457i  0.013205 + 0.279323i  0.229284 + 0.721929i;
+%!       0.092758 + 0.345687i  0.928679 + 0.241052i  0.764536 + 0.832406i;
+%!       0.912098 + 0.721024i  0.049018 + 0.269452i  0.730029 + 0.796517i;
+%!       0.112849 + 0.603871i  0.486352 + 0.142337i  0.355646 + 0.151496i ];
+%!
+%! uc = [0.20351 + 0.05401i;
+%!       0.13141 + 0.43708i;
+%!       0.29808 + 0.08789i;
+%!       0.69821 + 0.38844i;
+%!       0.74871 + 0.25821i ];
+%!
+%! vc = [0.85839 + 0.29468i;
+%!       0.20820 + 0.93090i;
+%!       0.86184 + 0.34689i ];
+%!
+
+%!testif HAVE_QRUPDATE_LUU
+%! [L,U,P] = lu (A);
+%! [L,U] = luupdate (L,U,P*u,v);
+%! assert (norm (vec (tril (L)-L), Inf) == 0);
+%! assert (norm (vec (triu (U)-U), Inf) == 0);
+%! assert (norm (vec (P'*L*U - A - u*v.'), Inf) < norm (A)*1e1*eps);
+%!
+%!testif HAVE_QRUPDATE_LUU
+%! [L,U,P] = lu (Ac);
+%! [L,U] = luupdate (L,U,P*uc,vc);
+%! assert (norm (vec (tril (L)-L), Inf) == 0);
+%! assert (norm (vec (triu (U)-U), Inf) == 0);
+%! assert (norm (vec (P'*L*U - Ac - uc*vc.'), Inf) < norm (Ac)*1e1*eps);
+
+%!testif HAVE_QRUPDATE_LUU
+%! [L,U,P] = lu (single (A));
+%! [L,U] = luupdate (L,U,P*single (u), single (v));
+%! assert (norm (vec (tril (L)-L), Inf) == 0);
+%! assert (norm (vec (triu (U)-U), Inf) == 0);
+%! assert (norm (vec (P'*L*U - single (A) - single (u)*single (v).'), Inf) < norm (single (A))*1e1*eps ("single"));
+%!
+%!testif HAVE_QRUPDATE_LUU
+%! [L,U,P] = lu (single (Ac));
+%! [L,U] = luupdate (L,U,P*single (uc),single (vc));
+%! assert (norm (vec (tril (L)-L), Inf) == 0);
+%! assert (norm (vec (triu (U)-U), Inf) == 0);
+%! assert (norm (vec (P'*L*U - single (Ac) - single (uc)*single (vc).'), Inf) < norm (single (Ac))*1e1*eps ("single"));
+
+%!testif HAVE_QRUPDATE_LUU
+%! [L,U,P] = lu (A);
+%! [L,U,P] = luupdate (L,U,P,u,v);
+%! assert (norm (vec (tril (L)-L), Inf) == 0);
+%! assert (norm (vec (triu (U)-U), Inf) == 0);
+%! assert (norm (vec (P'*L*U - A - u*v.'), Inf) < norm (A)*1e1*eps);
+%!
+%!testif HAVE_QRUPDATE_LUU
+%! [L,U,P] = lu (Ac);
+%! [L,U,P] = luupdate (L,U,P,uc,vc);
+%! assert (norm (vec (tril (L)-L), Inf) == 0);
+%! assert (norm (vec (triu (U)-U), Inf) == 0);
+%! assert (norm (vec (P'*L*U - Ac - uc*vc.'), Inf) < norm (Ac)*1e1*eps);
+
+%!testif HAVE_QRUPDATE_LUU
+%! [L,U,P] = lu (single (A));
+%! [L,U,P] = luupdate (L,U,P,single (u),single (v));
+%! assert (norm (vec (tril (L)-L), Inf) == 0);
+%! assert (norm (vec (triu (U)-U), Inf) == 0);
+%! assert (norm (vec (P'*L*U - single (A) - single (u)*single (v).'), Inf) < norm (single (A))*1e1*eps ("single"));
+%!
+%!testif HAVE_QRUPDATE_LUU
+%! [L,U,P] = lu (single (Ac));
+%! [L,U,P] = luupdate (L,U,P,single (uc),single (vc));
+%! assert (norm (vec (tril (L)-L), Inf) == 0);
+%! assert (norm (vec (triu (U)-U), Inf) == 0);
+%! assert (norm (vec (P'*L*U - single (Ac) - single (uc)*single (vc).'), Inf) < norm (single (Ac))*1e1*eps ("single"));
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/luinc.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,383 @@
+/*
+
+Copyright (C) 2005-2012 David Bateman
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+#include "oct-map.h"
+
+#include "MatrixType.h"
+#include "SparseCmplxLU.h"
+#include "SparsedbleLU.h"
+#include "ov-re-sparse.h"
+#include "ov-cx-sparse.h"
+
+DEFUN (luinc, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} luinc (@var{A}, '0')\n\
+@deftypefnx {Built-in Function} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} luinc (@var{A}, @var{droptol})\n\
+@deftypefnx {Built-in Function} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} luinc (@var{A}, @var{opts})\n\
+@cindex LU decomposition\n\
+Produce the incomplete LU@tie{}factorization of the sparse matrix @var{A}.\n\
+Two types of incomplete factorization are possible, and the type\n\
+is determined by the second argument to @code{luinc}.\n\
+\n\
+Called with a second argument of '0', the zero-level incomplete\n\
+LU@tie{}factorization is produced.  This creates a factorization of @var{A}\n\
+where the position of the non-zero arguments correspond to the same\n\
+positions as in the matrix @var{A}.\n\
+\n\
+Alternatively, the fill-in of the incomplete LU@tie{}factorization can\n\
+be controlled through the variable @var{droptol} or the structure\n\
+@var{opts}.  The @sc{umfpack} multifrontal factorization code by Tim A.\n\
+Davis is used for the incomplete LU@tie{}factorization, (availability\n\
+@url{http://www.cise.ufl.edu/research/sparse/umfpack/})\n\
+\n\
+@var{droptol} determines the values below which the values in the\n\
+LU@tie{} factorization are dropped and replaced by zero.  It must be a\n\
+positive scalar, and any values in the factorization whose absolute value\n\
+are less than this value are dropped, expect if leaving them increase the\n\
+sparsity of the matrix.  Setting @var{droptol} to zero results in a complete\n\
+LU@tie{}factorization which is the default.\n\
+\n\
+@var{opts} is a structure containing one or more of the fields\n\
+\n\
+@table @code\n\
+@item droptol\n\
+The drop tolerance as above.  If @var{opts} only contains @code{droptol}\n\
+then this is equivalent to using the variable @var{droptol}.\n\
+\n\
+@item milu\n\
+A logical variable flagging whether to use the modified incomplete\n\
+LU@tie{} factorization.  In the case that @code{milu} is true, the dropped\n\
+values are subtracted from the diagonal of the matrix @var{U} of the\n\
+factorization.  The default is @code{false}.\n\
+\n\
+@item udiag\n\
+A logical variable that flags whether zero elements on the diagonal of\n\
+@var{U} should be replaced with @var{droptol} to attempt to avoid singular\n\
+factors.  The default is @code{false}.\n\
+\n\
+@item thresh\n\
+Defines the pivot threshold in the interval [0,1].  Values outside that\n\
+range are ignored.\n\
+@end table\n\
+\n\
+All other fields in @var{opts} are ignored.  The outputs from @code{luinc}\n\
+are the same as for @code{lu}.\n\
+\n\
+Given the string argument \"vector\", @code{luinc} returns the values of\n\
+@var{p} @var{q} as vector values.\n\
+@seealso{sparse, lu}\n\
+@end deftypefn")
+{
+  int nargin = args.length ();
+  octave_value_list retval;
+
+  if (nargin == 0)
+    print_usage ();
+  else if (nargin < 2 || nargin > 3)
+    error ("luinc: incorrect number of arguments");
+  else
+    {
+      bool zero_level = false;
+      bool milu = false;
+      bool udiag = false;
+      Matrix thresh;
+      double droptol = -1.;
+      bool vecout = false;
+
+      if (args(1).is_string ())
+        {
+          if (args(1).string_value () == "0")
+            zero_level = true;
+          else
+            error ("luinc: unrecognized string argument");
+        }
+      else if (args(1).is_map ())
+        {
+          octave_scalar_map map = args(1).scalar_map_value ();
+
+          if (! error_state)
+            {
+              octave_value tmp;
+
+              tmp = map.getfield ("droptol");
+              if (tmp.is_defined ())
+                droptol = tmp.double_value ();
+
+              tmp = map.getfield ("milu");
+              if (tmp.is_defined ())
+                {
+                  double val = tmp.double_value ();
+
+                  milu = (val == 0. ? false : true);
+                }
+
+              tmp = map.getfield ("udiag");
+              if (tmp.is_defined ())
+                {
+                  double val = tmp.double_value ();
+
+                  udiag = (val == 0. ? false : true);
+                }
+
+              tmp = map.getfield ("thresh");
+              if (tmp.is_defined ())
+                {
+                  thresh = tmp.matrix_value ();
+
+                  if (thresh.nelem () == 1)
+                    {
+                      thresh.resize (1,2);
+                      thresh(1) = thresh(0);
+                    }
+                  else if (thresh.nelem () != 2)
+                    {
+                      error ("luinc: expecting 2-element vector for thresh");
+                      return retval;
+                    }
+                }
+            }
+          else
+            {
+              error ("luinc: OPTS must be a scalar structure");
+              return retval;
+            }
+        }
+      else
+        droptol = args(1).double_value ();
+
+      if (nargin == 3)
+        {
+          std::string tmp = args(2).string_value ();
+
+          if (! error_state )
+            {
+              if (tmp.compare ("vector") == 0)
+                vecout = true;
+              else
+                error ("luinc: unrecognized string argument");
+            }
+        }
+
+      // FIXME Add code for zero-level factorization
+      if (zero_level)
+        error ("luinc: zero-level factorization not implemented");
+
+      if (!error_state)
+        {
+          if (args(0).type_name () == "sparse matrix")
+            {
+              SparseMatrix sm = args(0).sparse_matrix_value ();
+              octave_idx_type sm_nr = sm.rows ();
+              octave_idx_type sm_nc = sm.cols ();
+              ColumnVector Qinit (sm_nc);
+
+              for (octave_idx_type i = 0; i < sm_nc; i++)
+                Qinit (i) = i;
+
+              if (! error_state)
+                {
+                  switch (nargout)
+                    {
+                    case 0:
+                    case 1:
+                    case 2:
+                      {
+                        SparseLU fact (sm, Qinit, thresh, false, true, droptol,
+                                       milu, udiag);
+
+                        if (! error_state)
+                          {
+                            SparseMatrix P = fact.Pr ();
+                            SparseMatrix L = P.transpose () * fact.L ();
+                            retval(1) = octave_value (fact.U (),
+                                                      MatrixType (MatrixType::Upper));
+                            retval(0) = octave_value (L, MatrixType
+                                                      (MatrixType::Permuted_Lower,
+                                                       sm_nr, fact.row_perm ()));
+                          }
+                      }
+                      break;
+
+                    case 3:
+                      {
+                        SparseLU fact (sm, Qinit, thresh, false, true, droptol,
+                                       milu, udiag);
+
+                        if (! error_state)
+                          {
+                            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;
+
+                    case 4:
+                    default:
+                      {
+                        SparseLU fact (sm, Qinit, thresh, false, false, droptol,
+                                       milu, udiag);
+
+                        if (! error_state)
+                          {
+                            if (vecout)
+                              {
+                                retval(3) = fact.Pc_vec ();
+                                retval(2) = fact.Pr_vec ();
+                              }
+                            else
+                              {
+                                retval(3) = fact.Pc_mat ();
+                                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 if (args(0).type_name () == "sparse complex matrix")
+            {
+              SparseComplexMatrix sm =
+                args(0).sparse_complex_matrix_value ();
+              octave_idx_type sm_nr = sm.rows ();
+              octave_idx_type sm_nc = sm.cols ();
+              ColumnVector Qinit (sm_nc);
+
+              for (octave_idx_type i = 0; i < sm_nc; i++)
+                Qinit (i) = i;
+
+              if (! error_state)
+                {
+                  switch (nargout)
+                    {
+                    case 0:
+                    case 1:
+                    case 2:
+                      {
+                        SparseComplexLU fact (sm, Qinit, thresh, false, true,
+                                              droptol, milu, udiag);
+
+
+                        if (! error_state)
+                          {
+                            SparseMatrix P = fact.Pr ();
+                            SparseComplexMatrix L = P.transpose () * fact.L ();
+                            retval(1) = octave_value (fact.U (),
+                                                      MatrixType (MatrixType::Upper));
+                            retval(0) = octave_value (L, MatrixType
+                                                      (MatrixType::Permuted_Lower,
+                                                       sm_nr, fact.row_perm ()));
+                          }
+                      }
+                      break;
+
+                    case 3:
+                      {
+                        SparseComplexLU fact (sm, Qinit, thresh, false, true,
+                                              droptol, milu, udiag);
+
+                        if (! error_state)
+                          {
+                            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;
+
+                    case 4:
+                    default:
+                      {
+                        SparseComplexLU fact (sm, Qinit, thresh, false, false,
+                                              droptol, milu, udiag);
+
+                        if (! error_state)
+                          {
+                            if (vecout)
+                              {
+                                retval(3) = fact.Pc_vec ();
+                                retval(2) = fact.Pr_vec ();
+                              }
+                            else
+                              {
+                                retval(3) = fact.Pc_mat ();
+                                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
+            error ("luinc: matrix A must be sparse");
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!testif HAVE_UMFPACK
+%! a = sparse ([1,2,0,0;0,1,2,0;1e-14,0,3,0;0,0,0,1]);
+%! [l,u] = luinc (a, 1e-10);
+%! assert (l*u, sparse ([1,2,0,0;0,1,2,0;0,0,3,0;0,0,0,1]), 1e-10);
+%! opts.droptol = 1e-10;
+%! [l,u] = luinc (a, opts);
+%! assert (l*u, sparse ([1,2,0,0;0,1,2,0;0,0,3,0;0,0,0,1]), 1e-10);
+
+%!testif HAVE_UMFPACK
+%! a = sparse ([1i,2,0,0;0,1,2,0;1e-14,0,3,0;0,0,0,1]);
+%! [l,u] = luinc (a, 1e-10);
+%! assert (l*u, sparse ([1i,2,0,0;0,1,2,0;0,0,3,0;0,0,0,1]), 1e-10);
+%! opts.droptol = 1e-10;
+%! [l,u] = luinc (a, opts);
+%! assert (l*u, sparse ([1i,2,0,0;0,1,2,0;0,0,3,0;0,0,0,1]), 1e-10);
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/matrix_type.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,621 @@
+/*
+
+Copyright (C) 2005-2012 David Bateman
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <algorithm>
+
+#include "ov.h"
+#include "defun.h"
+#include "error.h"
+#include "ov-re-mat.h"
+#include "ov-cx-mat.h"
+#include "ov-re-sparse.h"
+#include "ov-cx-sparse.h"
+#include "MatrixType.h"
+#include "oct-locbuf.h"
+
+DEFUN (matrix_type, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{type} =} matrix_type (@var{A})\n\
+@deftypefnx {Built-in Function} {@var{type} =} matrix_type (@var{A}, \"nocompute\")\n\
+@deftypefnx {Built-in Function} {@var{A} =} matrix_type (@var{A}, @var{type})\n\
+@deftypefnx {Built-in Function} {@var{A} =} matrix_type (@var{A}, \"upper\", @var{perm})\n\
+@deftypefnx {Built-in Function} {@var{A} =} matrix_type (@var{A}, \"lower\", @var{perm})\n\
+@deftypefnx {Built-in Function} {@var{A} =} matrix_type (@var{A}, \"banded\", @var{nl}, @var{nu})\n\
+Identify the matrix type or mark a matrix as a particular type.  This allows\n\
+more rapid solutions of linear equations involving @var{A} to be performed.\n\
+Called with a single argument, @code{matrix_type} returns the type of the\n\
+matrix and caches it for future use.  Called with more than one argument,\n\
+@code{matrix_type} allows the type of the matrix to be defined.\n\
+\n\
+If the option \"nocompute\" is given, the function will not attempt to guess\n\
+the type if it is still unknown.  This is useful for debugging purposes.\n\
+\n\
+The possible matrix types depend on whether the matrix is full or sparse, and\n\
+can be one of the following\n\
+\n\
+@table @asis\n\
+@item \"unknown\"\n\
+Remove any previously cached matrix type, and mark type as unknown.\n\
+\n\
+@item \"full\"\n\
+Mark the matrix as full.\n\
+\n\
+@item \"positive definite\"\n\
+Probable full positive definite matrix.\n\
+\n\
+@item \"diagonal\"\n\
+Diagonal matrix.  (Sparse matrices only)\n\
+\n\
+@item \"permuted diagonal\"\n\
+Permuted Diagonal matrix.  The permutation does not need to be specifically\n\
+indicated, as the structure of the matrix explicitly gives this.  (Sparse\n\
+matrices only)\n\
+\n\
+@item \"upper\"\n\
+Upper triangular.  If the optional third argument @var{perm} is given, the\n\
+matrix is assumed to be a permuted upper triangular with the permutations\n\
+defined by the vector @var{perm}.\n\
+\n\
+@item \"lower\"\n\
+Lower triangular.  If the optional third argument @var{perm} is given, the\n\
+matrix is assumed to be a permuted lower triangular with the permutations\n\
+defined by the vector @var{perm}.\n\
+\n\
+@item \"banded\"\n\
+@itemx \"banded positive definite\"\n\
+Banded matrix with the band size of @var{nl} below the diagonal and @var{nu}\n\
+above it.  If @var{nl} and @var{nu} are 1, then the matrix is tridiagonal and\n\
+treated with specialized code.  In addition the matrix can be marked as\n\
+probably a positive definite.  (Sparse matrices only)\n\
+\n\
+@item \"singular\"\n\
+The matrix is assumed to be singular and will be treated with a minimum norm\n\
+solution.\n\
+\n\
+@end table\n\
+\n\
+Note that the matrix type will be discovered automatically on the first\n\
+attempt to solve a linear equation involving @var{A}.  Therefore\n\
+@code{matrix_type} is only useful to give Octave hints of the matrix type.\n\
+Incorrectly defining the matrix type will result in incorrect results from\n\
+solutions of linear equations; it is entirely @strong{the responsibility of\n\
+the user} to correctly identify the matrix type.\n\
+\n\
+Also, the test for positive definiteness is a low-cost test for a Hermitian\n\
+matrix with a real positive diagonal.  This does not guarantee that the\n\
+matrix is positive definite, but only that it is a probable candidate.  When\n\
+such a matrix is factorized, a Cholesky@tie{}factorization is first\n\
+attempted, and if that fails the matrix is then treated with an\n\
+LU@tie{}factorization.  Once the matrix has been factorized,\n\
+@code{matrix_type} will return the correct classification of the matrix.\n\
+@end deftypefn")
+{
+  int nargin = args.length ();
+  octave_value retval;
+
+  if (nargin == 0)
+    print_usage ();
+  else if (nargin > 4)
+    error ("matrix_type: incorrect number of arguments");
+  else
+    {
+      bool autocomp = true;
+      if (nargin == 2 && args(1).is_string () && args(1).string_value () == "nocompute")
+        {
+          nargin = 1;
+          autocomp = false;
+        }
+
+      if (args(0).is_scalar_type ())
+        {
+          if (nargin == 1)
+            retval = octave_value ("Diagonal");
+          else
+            retval = args(0);
+        }
+      else if (args(0).is_sparse_type ())
+        {
+          if (nargin == 1)
+            {
+              MatrixType mattyp;
+
+              if (args(0).is_complex_type ())
+                {
+                  mattyp = args(0).matrix_type ();
+
+                  if (mattyp.is_unknown () && autocomp )
+                    {
+                      SparseComplexMatrix m =
+                        args(0).sparse_complex_matrix_value ();
+                      if (!error_state)
+                        {
+                          mattyp = MatrixType (m);
+                          args(0).matrix_type (mattyp);
+                        }
+                    }
+                }
+              else
+                {
+                  mattyp = args(0).matrix_type ();
+
+                  if (mattyp.is_unknown () && autocomp)
+                    {
+                      SparseMatrix m = args(0).sparse_matrix_value ();
+                      if (!error_state)
+                        {
+                          mattyp = MatrixType (m);
+                          args(0).matrix_type (mattyp);
+                        }
+                    }
+                }
+
+              int typ = mattyp.type ();
+
+              if (typ == MatrixType::Diagonal)
+                retval = octave_value ("Diagonal");
+              else if (typ == MatrixType::Permuted_Diagonal)
+                retval = octave_value ("Permuted Diagonal");
+              else if (typ == MatrixType::Upper)
+                retval = octave_value ("Upper");
+              else if (typ == MatrixType::Permuted_Upper)
+                retval = octave_value ("Permuted Upper");
+              else if (typ == MatrixType::Lower)
+                retval = octave_value ("Lower");
+              else if (typ == MatrixType::Permuted_Lower)
+                retval = octave_value ("Permuted Lower");
+              else if (typ == MatrixType::Banded)
+                retval = octave_value ("Banded");
+              else if (typ == MatrixType::Banded_Hermitian)
+                retval = octave_value ("Banded Positive Definite");
+              else if (typ == MatrixType::Tridiagonal)
+                retval = octave_value ("Tridiagonal");
+              else if (typ == MatrixType::Tridiagonal_Hermitian)
+                retval = octave_value ("Tridiagonal Positive Definite");
+              else if (typ == MatrixType::Hermitian)
+                retval = octave_value ("Positive Definite");
+              else if (typ == MatrixType::Rectangular)
+                {
+                  if (args(0).rows () == args(0).columns ())
+                    retval = octave_value ("Singular");
+                  else
+                    retval = octave_value ("Rectangular");
+                }
+              else if (typ == MatrixType::Full)
+                retval = octave_value ("Full");
+              else
+                retval = octave_value ("Unknown");
+            }
+          else
+            {
+              // Ok, we're changing the matrix type
+              std::string str_typ = args(1).string_value ();
+
+              // FIXME -- why do I have to explicitly call the constructor?
+              MatrixType mattyp = MatrixType ();
+
+              octave_idx_type nl = 0;
+              octave_idx_type nu = 0;
+
+              if (error_state)
+                error ("matrix_type: TYPE must be a string");
+              else
+                {
+                  // Use STL function to convert to lower case
+                  std::transform (str_typ.begin (), str_typ.end (),
+                                  str_typ.begin (), tolower);
+
+                  if (str_typ == "diagonal")
+                    mattyp.mark_as_diagonal ();
+                  if (str_typ == "permuted diagonal")
+                    mattyp.mark_as_permuted_diagonal ();
+                  else if (str_typ == "upper")
+                    mattyp.mark_as_upper_triangular ();
+                  else if (str_typ == "lower")
+                    mattyp.mark_as_lower_triangular ();
+                  else if (str_typ == "banded" || str_typ == "banded positive definite")
+                    {
+                      if (nargin != 4)
+                        error ("matrix_type: banded matrix type requires 4 arguments");
+                      else
+                        {
+                          nl = args(2).nint_value ();
+                          nu = args(3).nint_value ();
+
+                          if (error_state)
+                            error ("matrix_type: band size NL, NU must be integers");
+                          else
+                            {
+                              if (nl == 1 && nu == 1)
+                                mattyp.mark_as_tridiagonal ();
+                              else
+                                mattyp.mark_as_banded (nu, nl);
+
+                              if (str_typ == "banded positive definite")
+                                mattyp.mark_as_symmetric ();
+                            }
+                        }
+                    }
+                  else if (str_typ == "positive definite")
+                    {
+                      mattyp.mark_as_full ();
+                      mattyp.mark_as_symmetric ();
+                    }
+                  else if (str_typ == "singular")
+                    mattyp.mark_as_rectangular ();
+                  else if (str_typ == "full")
+                    mattyp.mark_as_full ();
+                  else if (str_typ == "unknown")
+                    mattyp.invalidate_type ();
+                  else
+                    error ("matrix_type: Unknown matrix type %s", str_typ.c_str ());
+
+                  if (! error_state)
+                    {
+                      if (nargin == 3 && (str_typ == "upper" || str_typ == "lower"))
+                        {
+                          const ColumnVector perm =
+                            ColumnVector (args (2).vector_value ());
+
+                          if (error_state)
+                            error ("matrix_type: Invalid permutation vector PERM");
+                          else
+                            {
+                              octave_idx_type len = perm.length ();
+                              dim_vector dv = args(0).dims ();
+
+                              if (len != dv(0))
+                                error ("matrix_type: Invalid permutation vector PERM");
+                              else
+                                {
+                                  OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len);
+
+                                  for (octave_idx_type i = 0; i < len; i++)
+                                    p[i] = static_cast<octave_idx_type> (perm (i)) - 1;
+
+                                  if (str_typ == "upper")
+                                    mattyp.mark_as_permuted (len, p);
+                                  else
+                                    mattyp.mark_as_permuted (len, p);
+                                }
+                            }
+                        }
+                      else if (nargin != 2 && str_typ != "banded positive definite" &&
+                               str_typ != "banded")
+                        error ("matrix_type: Invalid number of arguments");
+
+                      if (! error_state)
+                        {
+                          // Set the matrix type
+                          if (args(0).is_complex_type ())
+                            retval =
+                              octave_value (args(0).sparse_complex_matrix_value (),
+                                            mattyp);
+                          else
+                            retval = octave_value (args(0).sparse_matrix_value (),
+                                                   mattyp);
+                        }
+                    }
+                }
+            }
+        }
+      else
+        {
+          if (nargin == 1)
+            {
+              MatrixType mattyp;
+
+              if (args(0).is_complex_type ())
+                {
+                  mattyp = args(0).matrix_type ();
+
+                  if (mattyp.is_unknown () && autocomp)
+                    {
+                      if (args(0).is_single_type ())
+                        {
+                          FloatComplexMatrix m = args(0).float_complex_matrix_value ();
+                          if (!error_state)
+                            {
+                              mattyp = MatrixType (m);
+                              args(0).matrix_type (mattyp);
+                            }
+                        }
+                      else
+                        {
+                          ComplexMatrix m = args(0).complex_matrix_value ();
+                          if (!error_state)
+                            {
+                              mattyp = MatrixType (m);
+                              args(0).matrix_type (mattyp);
+                            }
+                        }
+                    }
+                }
+              else
+                {
+                  mattyp = args(0).matrix_type ();
+
+                  if (mattyp.is_unknown () && autocomp)
+                    {
+                      if (args(0).is_single_type ())
+                        {
+                          FloatMatrix m = args(0).float_matrix_value ();
+                          if (!error_state)
+                            {
+                              mattyp = MatrixType (m);
+                              args(0).matrix_type (mattyp);
+                            }
+                        }
+                      else
+                        {
+                          Matrix m = args(0).matrix_value ();
+                          if (!error_state)
+                            {
+                              mattyp = MatrixType (m);
+                              args(0).matrix_type (mattyp);
+                            }
+                        }
+                    }
+                }
+
+              int typ = mattyp.type ();
+
+              if (typ == MatrixType::Upper)
+                retval = octave_value ("Upper");
+              else if (typ == MatrixType::Permuted_Upper)
+                retval = octave_value ("Permuted Upper");
+              else if (typ == MatrixType::Lower)
+                retval = octave_value ("Lower");
+              else if (typ == MatrixType::Permuted_Lower)
+                retval = octave_value ("Permuted Lower");
+              else if (typ == MatrixType::Hermitian)
+                retval = octave_value ("Positive Definite");
+              else if (typ == MatrixType::Rectangular)
+                {
+                  if (args(0).rows () == args(0).columns ())
+                    retval = octave_value ("Singular");
+                  else
+                    retval = octave_value ("Rectangular");
+                }
+              else if (typ == MatrixType::Full)
+                retval = octave_value ("Full");
+              else
+                retval = octave_value ("Unknown");
+            }
+          else
+            {
+              // Ok, we're changing the matrix type
+              std::string str_typ = args(1).string_value ();
+
+              // FIXME -- why do I have to explicitly call the constructor?
+              MatrixType mattyp = MatrixType (MatrixType::Unknown, true);
+
+              if (error_state)
+                error ("matrix_type: TYPE must be a string");
+              else
+                {
+                  // Use STL function to convert to lower case
+                  std::transform (str_typ.begin (), str_typ.end (),
+                                  str_typ.begin (), tolower);
+
+                  if (str_typ == "upper")
+                    mattyp.mark_as_upper_triangular ();
+                  else if (str_typ == "lower")
+                    mattyp.mark_as_lower_triangular ();
+                  else if (str_typ == "positive definite")
+                    {
+                      mattyp.mark_as_full ();
+                      mattyp.mark_as_symmetric ();
+                    }
+                  else if (str_typ == "singular")
+                    mattyp.mark_as_rectangular ();
+                  else if (str_typ == "full")
+                    mattyp.mark_as_full ();
+                  else if (str_typ == "unknown")
+                    mattyp.invalidate_type ();
+                  else
+                    error ("matrix_type: Unknown matrix type %s", str_typ.c_str ());
+
+                  if (! error_state)
+                    {
+                      if (nargin == 3 && (str_typ == "upper"
+                                          || str_typ == "lower"))
+                        {
+                          const ColumnVector perm =
+                            ColumnVector (args (2).vector_value ());
+
+                          if (error_state)
+                            error ("matrix_type: Invalid permutation vector PERM");
+                          else
+                            {
+                              octave_idx_type len = perm.length ();
+                              dim_vector dv = args(0).dims ();
+
+                              if (len != dv(0))
+                                error ("matrix_type: Invalid permutation vector PERM");
+                              else
+                                {
+                                  OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len);
+
+                                  for (octave_idx_type i = 0; i < len; i++)
+                                    p[i] = static_cast<octave_idx_type> (perm (i)) - 1;
+
+                                  if (str_typ == "upper")
+                                    mattyp.mark_as_permuted (len, p);
+                                  else
+                                    mattyp.mark_as_permuted (len, p);
+                                }
+                            }
+                        }
+                      else if (nargin != 2)
+                        error ("matrix_type: Invalid number of arguments");
+
+                      if (! error_state)
+                        {
+                          // Set the matrix type
+                          if (args(0).is_single_type ())
+                            {
+                              if (args(0).is_complex_type ())
+                                retval = octave_value
+                                  (args(0).float_complex_matrix_value (),
+                                   mattyp);
+                              else
+                                retval = octave_value
+                                  (args(0).float_matrix_value (),
+                                   mattyp);
+                            }
+                          else
+                            {
+                              if (args(0).is_complex_type ())
+                                retval = octave_value
+                                  (args(0).complex_matrix_value (),
+                                   mattyp);
+                              else
+                                retval = octave_value
+                                  (args(0).matrix_value (),
+                                   mattyp);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+  return retval;
+}
+
+/*
+## FIXME:
+## Disable tests for lower under-determined and upper over-determined
+## matrices as this detection is disabled in MatrixType due to issues
+## of non minimum norm solution being found.
+
+%!assert (matrix_type (speye (10,10)), "Diagonal")
+%!assert (matrix_type (speye (10,10)([2:10,1],:)), "Permuted Diagonal")
+%!assert (matrix_type ([[speye(10,10);sparse(1,10)],[1;sparse(9,1);1]]), "Upper")
+%!assert (matrix_type ([[speye(10,10);sparse(1,10)],[1;sparse(9,1);1]](:,[2,1,3:11])), "Permuted Upper")
+%!assert (matrix_type ([speye(10,10),sparse(10,1);1,sparse(1,9),1]), "Lower")
+%!assert (matrix_type ([speye(10,10),sparse(10,1);1,sparse(1,9),1]([2,1,3:11],:)), "Permuted Lower")
+
+%!test
+%! bnd = spparms ("bandden");
+%! spparms ("bandden", 0.5);
+%! a = spdiags (rand (10,3)-0.5,[-1,0,1],10,10);
+%! assert (matrix_type (a), "Tridiagonal");
+%! assert (matrix_type (a'+a+2*speye (10)), "Tridiagonal Positive Definite");
+%! spparms ("bandden", bnd);
+%!test
+%! bnd=spparms ("bandden");
+%! spparms ("bandden", 0.5);
+%! a = spdiags (randn (10,4),[-2:1],10,10);
+%! assert (matrix_type (a), "Banded");
+%! assert (matrix_type (a'*a), "Banded Positive Definite");
+%! spparms ("bandden", bnd);
+%!test
+%! a = [speye(10,10),[sparse(9,1);1];-1,sparse(1,9),1];
+%! assert (matrix_type (a), "Full");
+%! assert (matrix_type (a'*a), "Positive Definite");
+
+%!assert (matrix_type (speye (10,11)), "Diagonal")
+%!assert (matrix_type (speye (10,11)([2:10,1],:)), "Permuted Diagonal")
+%!assert (matrix_type (speye (11,10)), "Diagonal")
+%!assert (matrix_type (speye (11,10)([2:11,1],:)), "Permuted Diagonal")
+%#!assert (matrix_type ([[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]]), "Upper")
+%#!assert (matrix_type ([[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]](:,[2,1,3:12])), "Permuted Upper")
+%!assert (matrix_type ([speye(11,9),[1;sparse(8,1);1;0]]), "Upper")
+%!assert (matrix_type ([speye(11,9),[1;sparse(8,1);1;0]](:,[2,1,3:10])), "Permuted Upper")
+%#!assert (matrix_type ([speye(10,10),sparse(10,1);[1;1],sparse(2,9),[1;1]]), "Lower")
+%#!assert (matrix_type ([speye(10,10),sparse(10,1);[1;1],sparse(2,9),[1;1]]([2,1,3:12],:)), "Permuted Lower")
+%!assert (matrix_type ([speye(9,11);[1,sparse(1,8),1,0]]), "Lower")
+%!assert (matrix_type ([speye(9,11);[1,sparse(1,8),1,0]]([2,1,3:10],:)), "Permuted Lower")
+%!assert (matrix_type (spdiags (randn (10,4),[-2:1],10,9)), "Rectangular")
+
+%!assert (matrix_type (1i*speye (10,10)), "Diagonal")
+%!assert (matrix_type (1i*speye (10,10)([2:10,1],:)), "Permuted Diagonal")
+%!assert (matrix_type ([[speye(10,10);sparse(1,10)],[1i;sparse(9,1);1]]), "Upper")
+%!assert (matrix_type ([[speye(10,10);sparse(1,10)],[1i;sparse(9,1);1]](:,[2,1,3:11])), "Permuted Upper")
+%!assert (matrix_type ([speye(10,10),sparse(10,1);1i,sparse(1,9),1]), "Lower")
+%!assert (matrix_type ([speye(10,10),sparse(10,1);1i,sparse(1,9),1]([2,1,3:11],:)), "Permuted Lower")
+
+%!test
+%! bnd = spparms ("bandden");
+%! spparms ("bandden", 0.5);
+%! assert (matrix_type (spdiags (1i*randn (10,3),[-1,0,1],10,10)), "Tridiagonal");
+%! a = 1i*(rand (9,1)-0.5);
+%! a = [[a;0],ones(10,1),[0;-a]];
+%! assert (matrix_type (spdiags (a,[-1,0,1],10,10)), "Tridiagonal Positive Definite");
+%! spparms ("bandden", bnd);
+%!test
+%! bnd = spparms ("bandden");
+%! spparms ("bandden", 0.5);
+%! assert (matrix_type (spdiags (1i*randn (10,4),[-2:1],10,10)), "Banded");
+%! a = 1i*(rand (9,2)-0.5);
+%! a = [[a;[0,0]],ones(10,1),[[0;-a(:,2)],[0;0;-a(1:8,1)]]];
+%! assert (matrix_type (spdiags (a,[-2:2],10,10)), "Banded Positive Definite");
+%! spparms ("bandden", bnd);
+%!test
+%! a = [speye(10,10),[sparse(9,1);1i];-1,sparse(1,9),1];
+%! assert (matrix_type (a), "Full");
+%! assert (matrix_type (a'*a), "Positive Definite");
+
+%!assert (matrix_type (1i*speye (10,11)), "Diagonal")
+%!assert (matrix_type (1i*speye (10,11)([2:10,1],:)), "Permuted Diagonal")
+%!assert (matrix_type (1i*speye (11,10)), "Diagonal")
+%!assert (matrix_type (1i*speye (11,10)([2:11,1],:)), "Permuted Diagonal")
+%#!assert (matrix_type ([[speye(10,10);sparse(1,10)],[[1i,1i];sparse(9,2);[1i,1i]]]), "Upper")
+%#!assert (matrix_type ([[speye(10,10);sparse(1,10)],[[1i,1i];sparse(9,2);[1i,1i]]](:,[2,1,3:12])), "Permuted Upper")
+%!assert (matrix_type ([speye(11,9),[1i;sparse(8,1);1i;0]]), "Upper")
+%!assert (matrix_type ([speye(11,9),[1i;sparse(8,1);1i;0]](:,[2,1,3:10])), "Permuted Upper")
+%#!assert (matrix_type ([speye(10,10),sparse(10,1);[1i;1i],sparse(2,9),[1i;1i]]), "Lower")
+%#!assert (matrix_type ([speye(10,10),sparse(10,1);[1i;1i],sparse(2,9),[1i;1i]]([2,1,3:12],:)), "Permuted Lower")
+%!assert (matrix_type ([speye(9,11);[1i,sparse(1,8),1i,0]]), "Lower")
+%!assert (matrix_type ([speye(9,11);[1i,sparse(1,8),1i,0]]([2,1,3:10],:)), "Permuted Lower")
+%!assert (matrix_type (1i*spdiags(randn(10,4),[-2:1],10,9)), "Rectangular")
+
+%!test
+%! a = matrix_type (spdiags (randn (10,3),[-1,0,1],10,10), "Singular");
+%! assert (matrix_type (a), "Singular");
+
+%!assert (matrix_type (triu (ones(10,10))), "Upper")
+%!assert (matrix_type (triu (ones(10,10),-1)), "Full")
+%!assert (matrix_type (tril (ones(10,10))), "Lower")
+%!assert (matrix_type (tril (ones(10,10),1)), "Full")
+%!assert (matrix_type (10*eye (10,10) + ones (10,10)), "Positive Definite")
+%!assert (matrix_type (ones (11,10)), "Rectangular")
+%!test
+%! a = matrix_type (ones (10,10), "Singular");
+%! assert (matrix_type (a), "Singular");
+
+%!assert (matrix_type (triu (1i*ones (10,10))), "Upper")
+%!assert (matrix_type (triu (1i*ones (10,10),-1)), "Full")
+%!assert (matrix_type (tril (1i*ones (10,10))), "Lower")
+%!assert (matrix_type (tril (1i*ones (10,10),1)), "Full")
+%!assert (matrix_type (10*eye (10,10) + 1i*triu (ones (10,10),1) -1i*tril (ones (10,10),-1)), "Positive Definite")
+%!assert (matrix_type (ones (11,10)), "Rectangular")
+%!test
+%! a = matrix_type (ones (10,10), "Singular");
+%! assert (matrix_type (a), "Singular");
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/max.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,632 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+Copyright (C) 2009 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "lo-ieee.h"
+#include "lo-mappers.h"
+#include "lo-math.h"
+#include "dNDArray.h"
+#include "CNDArray.h"
+#include "quit.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+
+#include "ov-cx-mat.h"
+#include "ov-re-sparse.h"
+#include "ov-cx-sparse.h"
+
+template <class ArrayType>
+static octave_value_list
+do_minmax_red_op (const octave_value& arg,
+                  int nargout, int dim, bool ismin)
+{
+  octave_value_list retval;
+  ArrayType array = octave_value_extract<ArrayType> (arg);
+
+  if (error_state)
+    return retval;
+
+  if (nargout == 2)
+    {
+      retval.resize (2);
+      Array<octave_idx_type> idx;
+      if (ismin)
+        retval(0) = array.min (idx, dim);
+      else
+        retval(0) = array.max (idx, dim);
+
+      retval(1) = octave_value (idx, true, true);
+    }
+  else
+    {
+      if (ismin)
+        retval(0) = array.min (dim);
+      else
+        retval(0) = array.max (dim);
+    }
+
+  return retval;
+}
+
+// Specialization for bool arrays.
+template <>
+octave_value_list
+do_minmax_red_op<boolNDArray> (const octave_value& arg,
+                               int nargout, int dim, bool ismin)
+{
+  octave_value_list retval;
+
+  if (nargout <= 1)
+    {
+      // This case can be handled using any/all.
+      boolNDArray array = arg.bool_array_value ();
+
+      if (array.is_empty ())
+        retval(0) = array;
+      else if (ismin)
+        retval(0) = array.all (dim);
+      else
+        retval(0) = array.any (dim);
+    }
+  else
+    {
+      // any/all don't have indexed versions, so do it via a conversion.
+      retval = do_minmax_red_op<int8NDArray> (arg, nargout, dim, ismin);
+      if (! error_state)
+        retval(0) = retval(0).bool_array_value ();
+    }
+
+  return retval;
+}
+
+template <class ArrayType>
+static octave_value
+do_minmax_bin_op (const octave_value& argx, const octave_value& argy,
+                  bool ismin)
+{
+  typedef typename ArrayType::element_type ScalarType;
+
+  octave_value retval;
+
+  if (argx.is_scalar_type () == 1)
+    {
+      ScalarType x = octave_value_extract<ScalarType> (argx);
+      ArrayType y = octave_value_extract<ArrayType> (argy);
+
+      if (error_state)
+        ;
+      else if (ismin)
+        retval = min (x, y);
+      else
+        retval = max (x, y);
+    }
+  else if (argy.is_scalar_type () == 1)
+    {
+      ArrayType x = octave_value_extract<ArrayType> (argx);
+      ScalarType y = octave_value_extract<ScalarType> (argy);
+
+      if (error_state)
+        ;
+      else if (ismin)
+        retval = min (x, y);
+      else
+        retval = max (x, y);
+    }
+  else
+    {
+      ArrayType x = octave_value_extract<ArrayType> (argx);
+      ArrayType y = octave_value_extract<ArrayType> (argy);
+
+      if (error_state)
+        ;
+      else if (ismin)
+        retval = min (x, y);
+      else
+        retval = max (x, y);
+    }
+
+  return retval;
+}
+
+static octave_value_list
+do_minmax_body (const octave_value_list& args,
+                int nargout, bool ismin)
+{
+  octave_value_list retval;
+
+  const char *func = ismin ? "min" : "max";
+
+  int nargin = args.length ();
+
+  if (nargin == 3 || nargin == 1)
+    {
+      octave_value arg = args(0);
+      int dim = -1;
+      if (nargin == 3)
+        {
+          dim = args(2).int_value (true) - 1;
+          if (error_state || dim < 0)
+            {
+              error ("%s: DIM must be a valid dimension", func);
+              return retval;
+            }
+
+          if (! args(1).is_empty ())
+            warning ("%s: second argument is ignored", func);
+        }
+
+      switch (arg.builtin_type ())
+        {
+        case btyp_double:
+          {
+            if (arg.is_range () && (dim == -1 || dim == 1))
+              {
+                Range range = arg.range_value ();
+                if (range.nelem () == 0)
+                  {
+                    retval(0) = arg;
+                    if (nargout > 1)
+                      retval(1) = arg;
+                  }
+                else if (ismin)
+                  {
+                    retval(0) = range.min ();
+                    if (nargout > 1)
+                      retval(1) = static_cast<double> (range.inc () < 0 ? range.nelem () : 1);
+                  }
+                else
+                  {
+                    retval(0) = range.max ();
+                    if (nargout > 1)
+                      retval(1) = static_cast<double> (range.inc () >= 0 ? range.nelem () : 1);
+                  }
+              }
+            else if (arg.is_sparse_type ())
+              retval = do_minmax_red_op<SparseMatrix> (arg, nargout, dim, ismin);
+            else
+              retval = do_minmax_red_op<NDArray> (arg, nargout, dim, ismin);
+            break;
+          }
+        case btyp_complex:
+          {
+            if (arg.is_sparse_type ())
+              retval = do_minmax_red_op<SparseComplexMatrix> (arg, nargout, dim, ismin);
+            else
+              retval = do_minmax_red_op<ComplexNDArray> (arg, nargout, dim, ismin);
+            break;
+          }
+        case btyp_float:
+          retval = do_minmax_red_op<FloatNDArray> (arg, nargout, dim, ismin);
+          break;
+        case btyp_float_complex:
+          retval = do_minmax_red_op<FloatComplexNDArray> (arg, nargout, dim, ismin);
+          break;
+#define MAKE_INT_BRANCH(X) \
+        case btyp_ ## X: \
+          retval = do_minmax_red_op<X ## NDArray> (arg, nargout, dim, ismin); \
+          break;
+        MAKE_INT_BRANCH (int8);
+        MAKE_INT_BRANCH (int16);
+        MAKE_INT_BRANCH (int32);
+        MAKE_INT_BRANCH (int64);
+        MAKE_INT_BRANCH (uint8);
+        MAKE_INT_BRANCH (uint16);
+        MAKE_INT_BRANCH (uint32);
+        MAKE_INT_BRANCH (uint64);
+#undef MAKE_INT_BRANCH
+        case btyp_bool:
+          retval = do_minmax_red_op<boolNDArray> (arg, nargout, dim, ismin);
+          break;
+        default:
+          gripe_wrong_type_arg (func, arg);
+      }
+    }
+  else if (nargin == 2)
+    {
+      octave_value argx = args(0), argy = args(1);
+      builtin_type_t xtyp = argx.builtin_type (), ytyp = argy.builtin_type ();
+      builtin_type_t rtyp = btyp_mixed_numeric (xtyp, ytyp);
+
+      switch (rtyp)
+        {
+        case btyp_double:
+          {
+            if ((argx.is_sparse_type ()
+                 && (argy.is_sparse_type () || argy.is_scalar_type ()))
+                || (argy.is_sparse_type () && argx.is_scalar_type ()))
+              retval = do_minmax_bin_op<SparseMatrix> (argx, argy, ismin);
+            else
+              retval = do_minmax_bin_op<NDArray> (argx, argy, ismin);
+            break;
+          }
+        case btyp_complex:
+          {
+            if ((argx.is_sparse_type ()
+                 && (argy.is_sparse_type () || argy.is_scalar_type ()))
+                || (argy.is_sparse_type () && argx.is_scalar_type ()))
+              retval = do_minmax_bin_op<SparseComplexMatrix> (argx, argy, ismin);
+            else
+              retval = do_minmax_bin_op<ComplexNDArray> (argx, argy, ismin);
+            break;
+          }
+        case btyp_float:
+          retval = do_minmax_bin_op<FloatNDArray> (argx, argy, ismin);
+          break;
+        case btyp_float_complex:
+          retval = do_minmax_bin_op<FloatComplexNDArray> (argx, argy, ismin);
+          break;
+#define MAKE_INT_BRANCH(X) \
+        case btyp_ ## X: \
+          retval = do_minmax_bin_op<X ## NDArray> (argx, argy, ismin); \
+          break;
+        MAKE_INT_BRANCH (int8);
+        MAKE_INT_BRANCH (int16);
+        MAKE_INT_BRANCH (int32);
+        MAKE_INT_BRANCH (int64);
+        MAKE_INT_BRANCH (uint8);
+        MAKE_INT_BRANCH (uint16);
+        MAKE_INT_BRANCH (uint32);
+        MAKE_INT_BRANCH (uint64);
+#undef MAKE_INT_BRANCH
+        default:
+          error ("%s: cannot compute %s (%s, %s)", func, func,
+                 argx.type_name ().c_str (), argy.type_name ().c_str ());
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+DEFUN (min, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} min (@var{x})\n\
+@deftypefnx {Built-in Function} {} min (@var{x}, @var{y})\n\
+@deftypefnx {Built-in Function} {} min (@var{x}, [], @var{dim})\n\
+@deftypefnx {Built-in Function} {} min (@var{x}, @var{y}, @var{dim})\n\
+@deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} min (@var{x})\n\
+For a vector argument, return the minimum value.  For a matrix\n\
+argument, return the minimum value from each column, as a row\n\
+vector, or over the dimension @var{dim} if defined, in which case @var{y} \n\
+should be set to the empty matrix (it's ignored otherwise).  For two matrices\n\
+(or a matrix and scalar), return the pair-wise minimum.\n\
+Thus,\n\
+\n\
+@example\n\
+min (min (@var{x}))\n\
+@end example\n\
+\n\
+@noindent\n\
+returns the smallest element of @var{x}, and\n\
+\n\
+@example\n\
+@group\n\
+min (2:5, pi)\n\
+    @result{}  2.0000  3.0000  3.1416  3.1416\n\
+@end group\n\
+@end example\n\
+\n\
+@noindent\n\
+compares each element of the range @code{2:5} with @code{pi}, and\n\
+returns a row vector of the minimum values.\n\
+\n\
+For complex arguments, the magnitude of the elements are used for\n\
+comparison.\n\
+\n\
+If called with one input and two output arguments,\n\
+@code{min} also returns the first index of the\n\
+minimum value(s).  Thus,\n\
+\n\
+@example\n\
+@group\n\
+[x, ix] = min ([1, 3, 0, 2, 0])\n\
+    @result{}  x = 0\n\
+        ix = 3\n\
+@end group\n\
+@end example\n\
+@seealso{max, cummin, cummax}\n\
+@end deftypefn")
+{
+  return do_minmax_body (args, nargout, true);
+}
+
+/*
+%!assert (min ([1, 4, 2, 3]), 1)
+%!assert (min ([1; -10; 5; -2]), -10)
+%!assert (min ([4, i; -2, 2]), [-2, i])
+
+%!test
+%! x = reshape (1:8, [2,2,2]);
+%! assert (max (x, [], 1), reshape ([2, 4, 6, 8], [1,2,2]));
+%! assert (max (x, [], 2), reshape ([3, 4, 7, 8], [2,1,2]));
+%! [y, i] = max (x, [], 3);
+%! assert (ndims (y), 2);
+%! assert (y, [5, 7; 6, 8]);
+%! assert (ndims (i), 2);
+%! assert (i, [2, 2; 2, 2]);
+
+%!error min ()
+%!error min (1, 2, 3, 4)
+*/
+
+DEFUN (max, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} max (@var{x})\n\
+@deftypefnx {Built-in Function} {} max (@var{x}, @var{y})\n\
+@deftypefnx {Built-in Function} {} max (@var{x}, [], @var{dim})\n\
+@deftypefnx {Built-in Function} {} max (@var{x}, @var{y}, @var{dim})\n\
+@deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} max (@var{x})\n\
+For a vector argument, return the maximum value.  For a matrix\n\
+argument, return the maximum value from each column, as a row\n\
+vector, or over the dimension @var{dim} if defined, in which case @var{y} \n\
+should be set to the empty matrix (it's ignored otherwise).  For two matrices\n\
+(or a matrix and scalar), return the pair-wise maximum.\n\
+Thus,\n\
+\n\
+@example\n\
+max (max (@var{x}))\n\
+@end example\n\
+\n\
+@noindent\n\
+returns the largest element of the matrix @var{x}, and\n\
+\n\
+@example\n\
+@group\n\
+max (2:5, pi)\n\
+    @result{}  3.1416  3.1416  4.0000  5.0000\n\
+@end group\n\
+@end example\n\
+\n\
+@noindent\n\
+compares each element of the range @code{2:5} with @code{pi}, and\n\
+returns a row vector of the maximum values.\n\
+\n\
+For complex arguments, the magnitude of the elements are used for\n\
+comparison.\n\
+\n\
+If called with one input and two output arguments,\n\
+@code{max} also returns the first index of the\n\
+maximum value(s).  Thus,\n\
+\n\
+@example\n\
+@group\n\
+[x, ix] = max ([1, 3, 5, 2, 5])\n\
+    @result{}  x = 5\n\
+        ix = 3\n\
+@end group\n\
+@end example\n\
+@seealso{min, cummax, cummin}\n\
+@end deftypefn")
+{
+  return do_minmax_body (args, nargout, false);
+}
+
+/*
+%!assert (max ([1, 4, 2, 3]), 4)
+%!assert (max ([1; -10; 5; -2]), 5)
+%!assert (max ([4, i 4.999; -2, 2, 3+4i]), [4, 2, 3+4i])
+
+%!test
+%! x = reshape (1:8, [2,2,2]);
+%! assert (min (x, [], 1), reshape ([1, 3, 5, 7], [1,2,2]));
+%! assert (min (x, [], 2), reshape ([1, 2, 5, 6], [2,1,2]));
+%! [y, i] = min (x, [], 3);
+%! assert (ndims(y), 2);
+%! assert (y, [1, 3; 2, 4]);
+%! assert (ndims(i), 2);
+%! assert (i, [1, 1; 1, 1]);
+
+%!error max ()
+%!error max (1, 2, 3, 4)
+*/
+
+template <class ArrayType>
+static octave_value_list
+do_cumminmax_red_op (const octave_value& arg,
+                     int nargout, int dim, bool ismin)
+{
+  octave_value_list retval;
+  ArrayType array = octave_value_extract<ArrayType> (arg);
+
+  if (error_state)
+    return retval;
+
+  if (nargout == 2)
+    {
+      retval.resize (2);
+      Array<octave_idx_type> idx;
+      if (ismin)
+        retval(0) = array.cummin (idx, dim);
+      else
+        retval(0) = array.cummax (idx, dim);
+
+      retval(1) = octave_value (idx, true, true);
+    }
+  else
+    {
+      if (ismin)
+        retval(0) = array.cummin (dim);
+      else
+        retval(0) = array.cummax (dim);
+    }
+
+  return retval;
+}
+
+static octave_value_list
+do_cumminmax_body (const octave_value_list& args,
+                   int nargout, bool ismin)
+{
+  octave_value_list retval;
+
+  const char *func = ismin ? "cummin" : "cummax";
+
+  int nargin = args.length ();
+
+  if (nargin == 1 || nargin == 2)
+    {
+      octave_value arg = args(0);
+      int dim = -1;
+      if (nargin == 2)
+        {
+          dim = args(1).int_value (true) - 1;
+          if (error_state || dim < 0)
+            {
+              error ("%s: DIM must be a valid dimension", func);
+              return retval;
+            }
+        }
+
+      switch (arg.builtin_type ())
+        {
+        case btyp_double:
+          retval = do_cumminmax_red_op<NDArray> (arg, nargout, dim, ismin);
+          break;
+        case btyp_complex:
+          retval = do_cumminmax_red_op<ComplexNDArray> (arg, nargout, dim, ismin);
+          break;
+        case btyp_float:
+          retval = do_cumminmax_red_op<FloatNDArray> (arg, nargout, dim, ismin);
+          break;
+        case btyp_float_complex:
+          retval = do_cumminmax_red_op<FloatComplexNDArray> (arg, nargout, dim, ismin);
+          break;
+#define MAKE_INT_BRANCH(X) \
+        case btyp_ ## X: \
+          retval = do_cumminmax_red_op<X ## NDArray> (arg, nargout, dim, ismin); \
+          break;
+        MAKE_INT_BRANCH (int8);
+        MAKE_INT_BRANCH (int16);
+        MAKE_INT_BRANCH (int32);
+        MAKE_INT_BRANCH (int64);
+        MAKE_INT_BRANCH (uint8);
+        MAKE_INT_BRANCH (uint16);
+        MAKE_INT_BRANCH (uint32);
+        MAKE_INT_BRANCH (uint64);
+#undef MAKE_INT_BRANCH
+        case btyp_bool:
+          {
+            retval = do_cumminmax_red_op<int8NDArray> (arg, nargout, dim, ismin);
+            if (retval.length () > 0)
+              retval(0) = retval(0).bool_array_value ();
+            break;
+          }
+        default:
+          gripe_wrong_type_arg (func, arg);
+      }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+DEFUN (cummin, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} cummin (@var{x})\n\
+@deftypefnx {Built-in Function} {} cummin (@var{x}, @var{dim})\n\
+@deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummin (@var{x})\n\
+Return the cumulative minimum values along dimension @var{dim}.  If @var{dim}\n\
+is unspecified it defaults to column-wise operation.  For example:\n\
+\n\
+@example\n\
+@group\n\
+cummin ([5 4 6 2 3 1])\n\
+   @result{}  5  4  4  2  2  1\n\
+@end group\n\
+@end example\n\
+\n\
+\n\
+The call\n\
+\n\
+@example\n\
+  [w, iw] = cummin (x)\n\
+@end example\n\
+\n\
+@noindent\n\
+with @code{x} a vector, is equivalent to the following code:\n\
+\n\
+@example\n\
+@group\n\
+w = iw = zeros (size (x));\n\
+for i = 1:length (x)\n\
+  [w(i), iw(i)] = max (x(1:i));\n\
+endfor\n\
+@end group\n\
+@end example\n\
+\n\
+@noindent\n\
+but computed in a much faster manner.\n\
+@seealso{cummax, min, max}\n\
+@end deftypefn")
+{
+  return do_cumminmax_body (args, nargout, true);
+}
+
+DEFUN (cummax, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} cummax (@var{x})\n\
+@deftypefnx {Built-in Function} {} cummax (@var{x}, @var{dim})\n\
+@deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummax (@var{x})\n\
+Return the cumulative maximum values along dimension @var{dim}.  If @var{dim}\n\
+is unspecified it defaults to column-wise operation.  For example:\n\
+\n\
+@example\n\
+@group\n\
+cummax ([1 3 2 6 4 5])\n\
+   @result{}  1  3  3  6  6  6\n\
+@end group\n\
+@end example\n\
+\n\
+The call\n\
+\n\
+@example\n\
+[w, iw] = cummax (x, dim)\n\
+@end example\n\
+\n\
+@noindent\n\
+with @code{x} a vector, is equivalent to the following code:\n\
+\n\
+@example\n\
+@group\n\
+w = iw = zeros (size (x));\n\
+for i = 1:length (x)\n\
+  [w(i), iw(i)] = max (x(1:i));\n\
+endfor\n\
+@end group\n\
+@end example\n\
+\n\
+@noindent\n\
+but computed in a much faster manner.\n\
+@seealso{cummin, max, min}\n\
+@end deftypefn")
+{
+  return do_cumminmax_body (args, nargout, false);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/md5sum.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,101 @@
+/*
+
+Copyright (C) 2007-2012 David Bateman
+
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+#include <vector>
+
+#include "defun.h"
+#include "file-stat.h"
+#include "file-ops.h"
+#include "gripes.h"
+#include "load-path.h"
+#include "oct-env.h"
+#include "oct-md5.h"
+
+DEFUN (md5sum, args, ,
+   "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} md5sum (@var{file})\n\
+@deftypefnx {Built-in Function} {} md5sum (@var{str}, @var{opt})\n\
+Calculate the MD5 sum of the file @var{file}.  If the second parameter\n\
+@var{opt} exists and is true, then calculate the MD5 sum of the\n\
+string @var{str}.\n\
+@end deftypefn")
+{
+  octave_value retval;
+  int nargin = args.length ();
+
+  if (nargin != 1 && nargin != 2)
+    print_usage ();
+  else
+    {
+      bool have_str = false;
+      std::string str = args(0).string_value ();
+
+      if (nargin == 2)
+        have_str = args(1).bool_value ();
+
+      if (!error_state)
+        {
+          if (have_str)
+            retval = oct_md5 (str);
+          else
+            {
+              file_stat fs (str);
+
+              if (! fs.exists ())
+                {
+                  std::string tmp
+                    = octave_env::make_absolute (load_path::find_file (str));
+
+                  if (! tmp.empty ())
+                    {
+                      warning_with_id ("Octave:md5sum-file-in-path",
+                                       "md5sum: file found in load path");
+                      str = tmp;
+                    }
+                }
+
+              retval = oct_md5_file (str);
+            }
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!assert (md5sum ("abc\0", true), "147a664a2ca9410911e61986d3f0d52a");
+
+%!test
+%! tfile = tmpnam ();
+%! fid = fopen (tfile, "wb");
+%! fwrite (fid, "abc\0");
+%! fclose (fid);
+%! assert (md5sum (tfile), "147a664a2ca9410911e61986d3f0d52a");
+%! unlink (tfile);
+*/
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/mgorth.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,154 @@
+/*
+
+Copyright (C) 2009-2012 Carlo de Falco
+Copyright (C) 2010 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "oct-norm.h"
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+
+template <class ColumnVector, class Matrix, class RowVector>
+static void
+do_mgorth (ColumnVector& x, const Matrix& V, RowVector& h)
+{
+  octave_idx_type Vc = V.columns ();
+  h = RowVector (Vc + 1);
+  for (octave_idx_type j = 0; j < Vc; j++)
+    {
+      ColumnVector Vcj = V.column (j);
+      h(j) = RowVector (Vcj.hermitian ()) * x;
+      x -= h(j) * Vcj;
+    }
+
+  h(Vc) = xnorm (x);
+  if (real (h(Vc)) > 0)
+    x = x / h(Vc);
+}
+
+DEFUN (mgorth, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {[@var{y}, @var{h}] =} mgorth (@var{x}, @var{v})\n\
+Orthogonalize a given column vector @var{x} with respect to a given\n\
+orthonormal basis @var{v} using a modified Gram-Schmidt orthogonalization.  \n\
+On exit, @var{y} is a unit vector such that:\n\
+\n\
+@example\n\
+@group\n\
+  norm (@var{y}) = 1\n\
+  @var{v}' * @var{y} = 0\n\
+  @var{x} = @var{h}*[@var{v}, @var{y}]\n\
+@end group\n\
+@end example\n\
+\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin != 2 || nargout > 2)
+  {
+    print_usage ();
+    return retval;
+  }
+
+  octave_value arg_x = args(0);
+  octave_value arg_v = args(1);
+
+  if (arg_v.ndims () != 2 || arg_x.ndims () != 2 || arg_x.columns () != 1
+      || arg_v.rows () != arg_x.rows ())
+    {
+      error ("mgorth: V should me a matrix, and X a column vector with"
+             " the same number of rows as V.");
+      return retval;
+    }
+
+  if (! arg_x.is_numeric_type () && ! arg_v.is_numeric_type ())
+    {
+      error ("mgorth: X and V must be numeric");
+    }
+
+  bool iscomplex = (arg_x.is_complex_type () || arg_v.is_complex_type ());
+  if (arg_x.is_single_type () || arg_v.is_single_type ())
+    {
+      if (iscomplex)
+        {
+          FloatComplexColumnVector x = arg_x.float_complex_column_vector_value ();
+          FloatComplexMatrix V = arg_v.float_complex_matrix_value ();
+          FloatComplexRowVector h;
+          do_mgorth (x, V, h);
+          retval(1) = h;
+          retval(0) = x;
+        }
+      else
+        {
+          FloatColumnVector x = arg_x.float_column_vector_value ();
+          FloatMatrix V = arg_v.float_matrix_value ();
+          FloatRowVector h;
+          do_mgorth (x, V, h);
+          retval(1) = h;
+          retval(0) = x;
+        }
+    }
+  else
+    {
+      if (iscomplex)
+        {
+          ComplexColumnVector x = arg_x.complex_column_vector_value ();
+          ComplexMatrix V = arg_v.complex_matrix_value ();
+          ComplexRowVector h;
+          do_mgorth (x, V, h);
+          retval(1) = h;
+          retval(0) = x;
+        }
+      else
+        {
+          ColumnVector x = arg_x.column_vector_value ();
+          Matrix V = arg_v.matrix_value ();
+          RowVector h;
+          do_mgorth (x, V, h);
+          retval(1) = h;
+          retval(0) = x;
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!test
+%! for ii=1:100
+%!   assert (abs (mgorth (randn (5, 1), eye (5, 4))), [0 0 0 0 1]', eps);
+%! endfor
+
+%!test
+%! a = hilb (5);
+%! a(:, 1) /= norm (a(:, 1));
+%! for ii = 1:5
+%!   a(:, ii) = mgorth (a(:, ii), a(:, 1:ii-1));
+%! endfor
+%! assert (a' * a, eye (5), 1e10);
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/module.mk	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,70 @@
+EXTRA_DIST += \
+  corefcn/module.mk
+
+corefcn_SRC = \
+  corefcn/__contourc__.cc \
+  corefcn/__dispatch__.cc \
+  corefcn/__lin_interpn__.cc \
+  corefcn/__pchip_deriv__.cc \
+  corefcn/__qp__.cc \
+  corefcn/balance.cc \
+  corefcn/besselj.cc \
+  corefcn/betainc.cc \
+  corefcn/bsxfun.cc \
+  corefcn/cellfun.cc \
+  corefcn/colloc.cc \
+  corefcn/conv2.cc \
+  corefcn/daspk.cc \
+  corefcn/dasrt.cc \
+  corefcn/dassl.cc \
+  corefcn/det.cc \
+  corefcn/dlmread.cc \
+  corefcn/dot.cc \
+  corefcn/eig.cc \
+  corefcn/fft.cc \
+  corefcn/fft2.cc \
+  corefcn/fftn.cc \
+  corefcn/filter.cc \
+  corefcn/find.cc \
+  corefcn/gammainc.cc \
+  corefcn/gcd.cc \
+  corefcn/getgrent.cc \
+  corefcn/getpwent.cc \
+  corefcn/getrusage.cc \
+  corefcn/givens.cc \
+  corefcn/hess.cc \
+  corefcn/hex2num.cc \
+  corefcn/inv.cc \
+  corefcn/kron.cc \
+  corefcn/lookup.cc \
+  corefcn/lsode.cc \
+  corefcn/lu.cc \
+  corefcn/luinc.cc \
+  corefcn/matrix_type.cc \
+  corefcn/max.cc \
+  corefcn/md5sum.cc \
+  corefcn/mgorth.cc \
+  corefcn/nproc.cc \
+  corefcn/pinv.cc \
+  corefcn/quad.cc \
+  corefcn/quadcc.cc \
+  corefcn/qz.cc \
+  corefcn/rand.cc \
+  corefcn/rcond.cc \
+  corefcn/regexp.cc \
+  corefcn/schur.cc \
+  corefcn/spparms.cc \
+  corefcn/sqrtm.cc \
+  corefcn/str2double.cc \
+  corefcn/strfind.cc \
+  corefcn/sub2ind.cc \
+  corefcn/svd.cc \
+  corefcn/syl.cc \
+  corefcn/time.cc \
+  corefcn/tril.cc \
+  corefcn/typecast.cc
+
+noinst_LTLIBRARIES += corefcn/libcorefcn.la
+
+corefcn_libcorefcn_la_SOURCES = $(corefcn_SRC)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/nproc.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,90 @@
+/*
+
+Copyright (C) 2012 Iain Murray
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "defun.h"
+#include "nproc.h"
+
+DEFUN (nproc, args, nargout,
+   "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} nproc ()\n\
+@deftypefnx {Built-in Function} {} nproc (@var{query})\n\
+Return the current number of available processors.\n\
+\n\
+If called with the optional argument @var{query}, modify how processors\n\
+are counted as follows:\n\
+\n\
+@table @code\n\
+@item all\n\
+total number of processors.\n\
+\n\
+@item current\n\
+processors available to the current process.\n\
+\n\
+@item overridable\n\
+likewise, but overridable through the @w{@env{OMP_NUM_THREADS}} environment\n\
+variable.\n\
+@end table\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if ((nargin != 0 && nargin != 1) || (nargout != 0 && nargout != 1))
+    {
+      print_usage ();
+      return retval;
+    }
+
+  nproc_query query = NPROC_CURRENT;
+  if (nargin == 1)
+    {
+      std::string arg = args(0).string_value ();
+
+      std::transform (arg.begin (), arg.end (), arg.begin (), tolower);
+
+      if (arg == "all")
+        query = NPROC_ALL;
+      else if (arg == "current")
+        query = NPROC_CURRENT;
+      else if (arg == "overridable")
+        query = NPROC_CURRENT_OVERRIDABLE;
+      else
+        {
+          error ("nproc: invalid value for QUERY");
+          return retval;
+        }
+    }
+
+  retval = num_processors (query);
+
+  return retval;
+}
+
+/*
+## Must always report at least 1 cpu available
+%!assert (nproc () >= 1);
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/pinv.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,192 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+#include "ops.h"
+#include "ov-re-diag.h"
+#include "ov-cx-diag.h"
+#include "ov-flt-re-diag.h"
+#include "ov-flt-cx-diag.h"
+#include "ov-perm.h"
+
+DEFUN (pinv, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} pinv (@var{x})\n\
+@deftypefnx {Built-in Function} {} pinv (@var{x}, @var{tol})\n\
+Return the pseudoinverse of @var{x}.  Singular values less than\n\
+@var{tol} are ignored.\n\
+\n\
+If the second argument is omitted, it is taken to be\n\
+\n\
+@example\n\
+tol = max (size (@var{x})) * sigma_max (@var{x}) * eps,\n\
+@end example\n\
+\n\
+@noindent\n\
+where @code{sigma_max (@var{x})} is the maximal singular value of @var{x}.\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 1 || nargin > 2)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value arg = args(0);
+
+  int arg_is_empty = empty_arg ("pinv", arg.rows (), arg.columns ());
+
+  if (arg_is_empty < 0)
+    return retval;
+  else if (arg_is_empty > 0)
+    return octave_value (Matrix ());
+
+  bool isfloat = arg.is_single_type ();
+
+  if (arg.is_diag_matrix ())
+    {
+      if (nargin == 2)
+        warning ("pinv: tol is ignored for diagonal matrices");
+
+      if (arg.is_complex_type ())
+        {
+          if (isfloat)
+            retval = arg.float_complex_diag_matrix_value ().pseudo_inverse ();
+          else
+            retval = arg.complex_diag_matrix_value ().pseudo_inverse ();
+        }
+      else
+        {
+          if (isfloat)
+            retval = arg.float_diag_matrix_value ().pseudo_inverse ();
+          else
+            retval = arg.diag_matrix_value ().pseudo_inverse ();
+        }
+    }
+  else if (arg.is_perm_matrix ())
+    {
+      retval = arg.perm_matrix_value ().inverse ();
+    }
+  else if (isfloat)
+    {
+      float tol = 0.0;
+      if (nargin == 2)
+        tol = args(1).float_value ();
+
+      if (error_state)
+        return retval;
+
+      if (tol < 0.0)
+        {
+          error ("pinv: TOL must be greater than zero");
+          return retval;
+        }
+
+      if (arg.is_real_type ())
+        {
+          FloatMatrix m = arg.float_matrix_value ();
+
+          if (! error_state)
+            retval = m.pseudo_inverse (tol);
+        }
+      else if (arg.is_complex_type ())
+        {
+          FloatComplexMatrix m = arg.float_complex_matrix_value ();
+
+          if (! error_state)
+            retval = m.pseudo_inverse (tol);
+        }
+      else
+        {
+          gripe_wrong_type_arg ("pinv", arg);
+        }
+    }
+  else
+    {
+      double tol = 0.0;
+      if (nargin == 2)
+        tol = args(1).double_value ();
+
+      if (error_state)
+        return retval;
+
+      if (tol < 0.0)
+        {
+          error ("pinv: TOL must be greater than zero");
+          return retval;
+        }
+
+      if (arg.is_real_type ())
+        {
+          Matrix m = arg.matrix_value ();
+
+          if (! error_state)
+            retval = m.pseudo_inverse (tol);
+        }
+      else if (arg.is_complex_type ())
+        {
+          ComplexMatrix m = arg.complex_matrix_value ();
+
+          if (! error_state)
+            retval = m.pseudo_inverse (tol);
+        }
+      else
+        {
+          gripe_wrong_type_arg ("pinv", arg);
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!shared a, b, tol, hitol, d, u, x, y
+%! a = reshape (rand*[1:16], 4, 4);   ## Rank 2 matrix
+%! b = pinv (a);
+%! tol = 4e-14;
+%! hitol = 40*sqrt (eps);
+%! d = diag ([rand, rand, hitol, hitol]);
+%! u = rand (4);                      ## Could be singular by freak accident
+%! x = inv (u)*d*u;
+%! y = pinv (x, sqrt (eps));
+%!
+%!assert (a*b*a, a, tol)
+%!assert (b*a*b, b, tol)
+%!assert ((b*a)', b*a, tol)
+%!assert ((a*b)', a*b, tol)
+%!assert (x*y*x, x, -hitol)
+%!assert (y*x*y, y, -hitol)
+%!assert ((x*y)', x*y, hitol)
+%!assert ((y*x)', y*x, hitol)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/quad.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,518 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+
+#include <iomanip>
+#include <iostream>
+
+#include "Quad.h"
+#include "lo-mappers.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "pager.h"
+#include "oct-obj.h"
+#include "ov-fcn.h"
+#include "unwind-prot.h"
+#include "utils.h"
+#include "variables.h"
+
+#include "Quad-opts.cc"
+
+#if defined (quad)
+#undef quad
+#endif
+
+// Global pointer for user defined function required by quadrature functions.
+static octave_function *quad_fcn;
+
+// Have we warned about imaginary values returned from user function?
+static bool warned_imaginary = false;
+
+// Is this a recursive call?
+static int call_depth = 0;
+
+double
+quad_user_function (double x)
+{
+  double retval = 0.0;
+
+  octave_value_list args;
+  args(0) = x;
+
+  if (quad_fcn)
+    {
+      octave_value_list tmp = quad_fcn->do_multi_index_op (1, args);
+
+      if (error_state)
+        {
+          quad_integration_error = 1;  // FIXME
+          gripe_user_supplied_eval ("quad");
+          return retval;
+        }
+
+      if (tmp.length () && tmp(0).is_defined ())
+        {
+          if (! warned_imaginary && tmp(0).is_complex_type ())
+            {
+              warning ("quad: ignoring imaginary part returned from user-supplied function");
+              warned_imaginary = true;
+            }
+
+          retval = tmp(0).double_value ();
+
+          if (error_state)
+            {
+              quad_integration_error = 1;  // FIXME
+              gripe_user_supplied_eval ("quad");
+            }
+        }
+      else
+        {
+          quad_integration_error = 1;  // FIXME
+          gripe_user_supplied_eval ("quad");
+        }
+    }
+
+  return retval;
+}
+
+float
+quad_float_user_function (float x)
+{
+  float retval = 0.0;
+
+  octave_value_list args;
+  args(0) = x;
+
+  if (quad_fcn)
+    {
+      octave_value_list tmp = quad_fcn->do_multi_index_op (1, args);
+
+      if (error_state)
+        {
+          quad_integration_error = 1;  // FIXME
+          gripe_user_supplied_eval ("quad");
+          return retval;
+        }
+
+      if (tmp.length () && tmp(0).is_defined ())
+        {
+          if (! warned_imaginary && tmp(0).is_complex_type ())
+            {
+              warning ("quad: ignoring imaginary part returned from user-supplied function");
+              warned_imaginary = true;
+            }
+
+          retval = tmp(0).float_value ();
+
+          if (error_state)
+            {
+              quad_integration_error = 1;  // FIXME
+              gripe_user_supplied_eval ("quad");
+            }
+        }
+      else
+        {
+          quad_integration_error = 1;  // FIXME
+          gripe_user_supplied_eval ("quad");
+        }
+    }
+
+  return retval;
+}
+
+#define QUAD_ABORT() \
+  do \
+    { \
+      if (fcn_name.length ()) \
+        clear_function (fcn_name); \
+      return retval; \
+    } \
+  while (0)
+
+#define QUAD_ABORT1(msg) \
+  do \
+    { \
+      ::error ("quad: " msg); \
+      QUAD_ABORT (); \
+    } \
+  while (0)
+
+#define QUAD_ABORT2(fmt, arg) \
+  do \
+    { \
+      ::error ("quad: " fmt, arg); \
+      QUAD_ABORT (); \
+    } \
+  while (0)
+
+DEFUN (quad, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b})\n\
+@deftypefnx {Built-in Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b}, @var{tol})\n\
+@deftypefnx {Built-in Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b}, @var{tol}, @var{sing})\n\
+@deftypefnx {Built-in Function} {[@var{q}, @var{ier}, @var{nfun}, @var{err}] =} quad (@dots{})\n\
+Numerically evaluate the integral of @var{f} from @var{a} to @var{b} using\n\
+Fortran routines from @w{@sc{quadpack}}.  @var{f} is a function handle,\n\
+inline function, or a string containing the name of the function to\n\
+evaluate.  The function must have the form @code{y = f (x)} where @var{y} and\n\
+@var{x} are scalars.\n\
+\n\
+@var{a} and @var{b} are the lower and upper limits of integration.  Either\n\
+or both may be infinite.\n\
+\n\
+The optional argument @var{tol} is a vector that specifies the desired\n\
+accuracy of the result.  The first element of the vector is the desired\n\
+absolute tolerance, and the second element is the desired relative\n\
+tolerance.  To choose a relative test only, set the absolute\n\
+tolerance to zero.  To choose an absolute test only, set the relative\n\
+tolerance to zero.  Both tolerances default to @code{sqrt (eps)} or\n\
+approximately @math{1.5e^{-8}}.\n\
+\n\
+The optional argument @var{sing} is a vector of values at which the\n\
+integrand is known to be singular.\n\
+\n\
+The result of the integration is returned in @var{q}.  @var{ier}\n\
+contains an integer error code (0 indicates a successful integration).\n\
+@var{nfun} indicates the number of function evaluations that were\n\
+made, and @var{err} contains an estimate of the error in the\n\
+solution.\n\
+\n\
+The function @code{quad_options} can set other optional\n\
+parameters for @code{quad}.\n\
+\n\
+Note: because @code{quad} is written in Fortran it cannot be called\n\
+recursively.  This prevents its use in integrating over more than one\n\
+variable by routines @code{dblquad} and @code{triplequad}.\n\
+@seealso{quad_options, quadv, quadl, quadgk, quadcc, trapz, dblquad, triplequad}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  std::string fcn_name;
+
+  warned_imaginary = false;
+
+  unwind_protect frame;
+
+  frame.protect_var (call_depth);
+  call_depth++;
+
+  if (call_depth > 1)
+    QUAD_ABORT1 ("invalid recursive call");
+
+  int nargin = args.length ();
+
+  if (nargin > 2 && nargin < 6 && nargout < 5)
+    {
+      if (args(0).is_function_handle () || args(0).is_inline_function ())
+        quad_fcn = args(0).function_value ();
+      else
+        {
+          fcn_name = unique_symbol_name ("__quad_fcn_");
+          std::string fname = "function y = ";
+          fname.append (fcn_name);
+          fname.append ("(x) y = ");
+          quad_fcn = extract_function (args(0), "quad", fcn_name, fname,
+                                       "; endfunction");
+        }
+
+      if (! quad_fcn)
+        QUAD_ABORT ();
+
+      if (args(1).is_single_type () || args(2).is_single_type ())
+        {
+          float a = args(1).float_value ();
+
+          if (error_state)
+            QUAD_ABORT1 ("expecting second argument to be a scalar");
+
+          float b = args(2).float_value ();
+
+          if (error_state)
+            QUAD_ABORT1 ("expecting third argument to be a scalar");
+
+          int indefinite = 0;
+          FloatIndefQuad::IntegralType indef_type = FloatIndefQuad::doubly_infinite;
+          float bound = 0.0;
+          if (xisinf (a) && xisinf (b))
+            {
+              indefinite = 1;
+              indef_type = FloatIndefQuad::doubly_infinite;
+            }
+          else if (xisinf (a))
+            {
+              indefinite = 1;
+              bound = b;
+              indef_type = FloatIndefQuad::neg_inf_to_bound;
+            }
+          else if (xisinf (b))
+            {
+              indefinite = 1;
+              bound = a;
+              indef_type = FloatIndefQuad::bound_to_inf;
+            }
+
+          octave_idx_type ier = 0;
+          octave_idx_type nfun = 0;
+          float abserr = 0.0;
+          float val = 0.0;
+          bool have_sing = false;
+          FloatColumnVector sing;
+          FloatColumnVector tol;
+
+          switch (nargin)
+            {
+            case 5:
+              if (indefinite)
+                QUAD_ABORT1 ("singularities not allowed on infinite intervals");
+
+              have_sing = true;
+
+              sing = FloatColumnVector (args(4).float_vector_value ());
+
+              if (error_state)
+                QUAD_ABORT1 ("expecting vector of singularities as fourth argument");
+
+            case 4:
+              tol = FloatColumnVector (args(3).float_vector_value ());
+
+              if (error_state)
+                QUAD_ABORT1 ("expecting vector of tolerances as fifth argument");
+
+              switch (tol.capacity ())
+                {
+                case 2:
+                  quad_opts.set_single_precision_relative_tolerance (tol (1));
+
+                case 1:
+                  quad_opts.set_single_precision_absolute_tolerance (tol (0));
+                  break;
+
+                default:
+                  QUAD_ABORT1 ("expecting tol to contain no more than two values");
+                }
+
+            case 3:
+              if (indefinite)
+                {
+                  FloatIndefQuad iq (quad_float_user_function, bound,
+                                     indef_type);
+                  iq.set_options (quad_opts);
+                  val = iq.float_integrate (ier, nfun, abserr);
+                }
+              else
+                {
+                  if (have_sing)
+                    {
+                      FloatDefQuad dq (quad_float_user_function, a, b, sing);
+                      dq.set_options (quad_opts);
+                      val = dq.float_integrate (ier, nfun, abserr);
+                    }
+                  else
+                    {
+                      FloatDefQuad dq (quad_float_user_function, a, b);
+                      dq.set_options (quad_opts);
+                      val = dq.float_integrate (ier, nfun, abserr);
+                    }
+                }
+              break;
+
+            default:
+              panic_impossible ();
+              break;
+            }
+
+          retval(3) = abserr;
+          retval(2) = nfun;
+          retval(1) = ier;
+          retval(0) = val;
+
+        }
+      else
+        {
+          double a = args(1).double_value ();
+
+          if (error_state)
+            QUAD_ABORT1 ("expecting second argument to be a scalar");
+
+          double b = args(2).double_value ();
+
+          if (error_state)
+            QUAD_ABORT1 ("expecting third argument to be a scalar");
+
+          int indefinite = 0;
+          IndefQuad::IntegralType indef_type = IndefQuad::doubly_infinite;
+          double bound = 0.0;
+          if (xisinf (a) && xisinf (b))
+            {
+              indefinite = 1;
+              indef_type = IndefQuad::doubly_infinite;
+            }
+          else if (xisinf (a))
+            {
+              indefinite = 1;
+              bound = b;
+              indef_type = IndefQuad::neg_inf_to_bound;
+            }
+          else if (xisinf (b))
+            {
+              indefinite = 1;
+              bound = a;
+              indef_type = IndefQuad::bound_to_inf;
+            }
+
+          octave_idx_type ier = 0;
+          octave_idx_type nfun = 0;
+          double abserr = 0.0;
+          double val = 0.0;
+          bool have_sing = false;
+          ColumnVector sing;
+          ColumnVector tol;
+
+          switch (nargin)
+            {
+            case 5:
+              if (indefinite)
+                QUAD_ABORT1 ("singularities not allowed on infinite intervals");
+
+              have_sing = true;
+
+              sing = ColumnVector (args(4).vector_value ());
+
+              if (error_state)
+                QUAD_ABORT1 ("expecting vector of singularities as fourth argument");
+
+            case 4:
+              tol = ColumnVector (args(3).vector_value ());
+
+              if (error_state)
+                QUAD_ABORT1 ("expecting vector of tolerances as fifth argument");
+
+              switch (tol.capacity ())
+                {
+                case 2:
+                  quad_opts.set_relative_tolerance (tol (1));
+
+                case 1:
+                  quad_opts.set_absolute_tolerance (tol (0));
+                  break;
+
+                default:
+                  QUAD_ABORT1 ("expecting tol to contain no more than two values");
+                }
+
+            case 3:
+              if (indefinite)
+                {
+                  IndefQuad iq (quad_user_function, bound, indef_type);
+                  iq.set_options (quad_opts);
+                  val = iq.integrate (ier, nfun, abserr);
+                }
+              else
+                {
+                  if (have_sing)
+                    {
+                      DefQuad dq (quad_user_function, a, b, sing);
+                      dq.set_options (quad_opts);
+                      val = dq.integrate (ier, nfun, abserr);
+                    }
+                  else
+                    {
+                      DefQuad dq (quad_user_function, a, b);
+                      dq.set_options (quad_opts);
+                      val = dq.integrate (ier, nfun, abserr);
+                    }
+                }
+              break;
+
+            default:
+              panic_impossible ();
+              break;
+            }
+
+          retval(3) = abserr;
+          retval(2) = nfun;
+          retval(1) = ier;
+          retval(0) = val;
+        }
+
+      if (fcn_name.length ())
+        clear_function (fcn_name);
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!function y = __f (x)
+%!  y = x + 1;
+%!endfunction
+
+%!test
+%! [v, ier, nfun, err] = quad ("__f", 0, 5);
+%! assert (ier, 0);
+%! assert (v, 17.5, sqrt (eps));
+%! assert (nfun > 0);
+%! assert (err < sqrt (eps));
+
+%!test
+%! [v, ier, nfun, err] = quad ("__f", single (0), single (5));
+%! assert (ier, 0);
+%! assert (v, 17.5, sqrt (eps ("single")));
+%! assert (nfun > 0);
+%! assert (err < sqrt (eps ("single")));
+
+%!function y = __f (x)
+%!  y = x .* sin (1 ./ x) .* sqrt (abs (1 - x));
+%!endfunction
+
+%!test
+%!  [v, ier, nfun, err] = quad ("__f", 0.001, 3);
+%! assert (ier == 0 || ier == 1);
+%! assert (v, 1.98194120273598, sqrt (eps));
+%! assert (nfun > 0);
+
+%!test
+%!  [v, ier, nfun, err] = quad ("__f", single (0.001), single (3));
+%! assert (ier == 0 || ier == 1);
+%! assert (v, 1.98194120273598, sqrt (eps ("single")));
+%! assert (nfun > 0);
+
+%!error quad ()
+%!error quad ("__f", 1, 2, 3, 4, 5)
+
+%!test
+%! quad_options ("absolute tolerance", eps);
+%! assert (quad_options ("absolute tolerance") == eps);
+
+%!error quad_options (1, 2, 3)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/quadcc.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,2268 @@
+/*
+
+Copyright (C) 2010-2012 Pedro Gonnet
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "lo-ieee.h"
+#include "parse.h"
+#include "variables.h"
+
+#include "defun.h"
+#include "error.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+//#include "oct.h"
+//#include "defun.h"
+
+/* Define the size of the interval heap. */
+#define cquad_heapsize                  200
+
+
+/* Data of a single interval */
+typedef struct
+{
+  double a, b;
+  double c[64];
+  double fx[33];
+  double igral, err;
+  int depth, rdepth, ndiv;
+} cquad_ival;
+
+/* Some constants and matrices that we'll need.  */
+
+static const double xi[33] = {
+  -1., -0.99518472667219688624, -0.98078528040323044912,
+  -0.95694033573220886493, -0.92387953251128675612,
+  -0.88192126434835502970, -0.83146961230254523708,
+  -0.77301045336273696082, -0.70710678118654752440,
+  -0.63439328416364549822, -0.55557023301960222475,
+  -0.47139673682599764857, -0.38268343236508977173,
+  -0.29028467725446236764, -0.19509032201612826785,
+  -0.098017140329560601995, 0., 0.098017140329560601995,
+  0.19509032201612826785, 0.29028467725446236764, 0.38268343236508977173,
+  0.47139673682599764857, 0.55557023301960222475, 0.63439328416364549822,
+  0.70710678118654752440, 0.77301045336273696082, 0.83146961230254523708,
+  0.88192126434835502970, 0.92387953251128675612, 0.95694033573220886493,
+  0.98078528040323044912, 0.99518472667219688624, 1.
+};
+
+static const double bee[68] = {
+  0.00000000000000e+00, 2.28868854108532e-01, 0.00000000000000e+00,
+  -8.15740215243451e-01, 0.00000000000000e+00, 5.31212715259731e-01,
+  0.00000000000000e+00, 1.38538036812454e-02, 0.00000000000000e+00,
+  3.74405228908818e-02, 0.00000000000000e+00, 2.12224115039342e-01,
+  0.00000000000000e+00, -8.16362644507898e-01, 0.00000000000000e+00,
+  5.35648426691481e-01, 0.00000000000000e+00, 1.52417902753662e-03,
+  0.00000000000000e+00, 2.63058840550873e-03, 0.00000000000000e+00,
+  4.15292106318904e-03, 0.00000000000000e+00, 6.97106011119775e-03,
+  0.00000000000000e+00, 1.35535708431058e-02, 0.00000000000000e+00,
+  3.52132898424856e-02, 0.00000000000000e+00, 2.06946714741884e-01,
+  0.00000000000000e+00, -8.15674251283876e-01, 0.00000000000000e+00,
+  5.38841175520580e-01, 0.00000000000000e+00, 1.84909689577590e-04,
+  0.00000000000000e+00, 2.90936325007499e-04, 0.00000000000000e+00,
+  3.84877750950089e-04, 0.00000000000000e+00, 4.86436656735046e-04,
+  0.00000000000000e+00, 6.08688640346879e-04, 0.00000000000000e+00,
+  7.66732830740331e-04, 0.00000000000000e+00, 9.82753336104205e-04,
+  0.00000000000000e+00, 1.29359957505615e-03, 0.00000000000000e+00,
+  1.76616363801885e-03, 0.00000000000000e+00, 2.53323433039089e-03,
+  0.00000000000000e+00, 3.88872172121956e-03, 0.00000000000000e+00,
+  6.58635106468291e-03, 0.00000000000000e+00, 1.30326736343254e-02,
+  0.00000000000000e+00, 3.44353850696714e-02, 0.00000000000000e+00,
+  2.05025409531915e-01, 0.00000000000000e+00, -8.14985893995401e-01,
+  0.00000000000000e+00, 5.40679930965238e-01
+};
+
+static const double Lalpha[33] = {
+  5.77350269189626e-01, 5.16397779494322e-01, 5.07092552837110e-01,
+  5.03952630678970e-01, 5.02518907629606e-01, 5.01745206004255e-01,
+  5.01280411827603e-01, 5.00979432868120e-01, 5.00773395667191e-01,
+  5.00626174321759e-01, 5.00517330712619e-01, 5.00434593736979e-01,
+  5.00370233297676e-01, 5.00319182924304e-01, 5.00278009473803e-01,
+  5.00244319584578e-01, 5.00216403386025e-01, 5.00193012939056e-01,
+  5.00173220168024e-01, 5.00156323280355e-01, 5.00141783641018e-01,
+  5.00129182278347e-01, 5.00118189340972e-01, 5.00108542278496e-01,
+  5.00100030010004e-01, 5.00092481273333e-01, 5.00085755939229e-01,
+  5.00079738458365e-01, 5.00074332862969e-01, 5.00069458915387e-01,
+  5.00065049112355e-01, 5.00061046334395e-01, 5.00057401986298e-01
+};
+
+static const double Lgamma[33] = {
+  0.0, 0.0, 5.16397779494322e-01, 5.07092552837110e-01, 5.03952630678970e-01,
+  5.02518907629606e-01, 5.01745206004255e-01, 5.01280411827603e-01,
+  5.00979432868120e-01, 5.00773395667191e-01, 5.00626174321759e-01,
+  5.00517330712619e-01, 5.00434593736979e-01, 5.00370233297676e-01,
+  5.00319182924304e-01, 5.00278009473803e-01, 5.00244319584578e-01,
+  5.00216403386025e-01, 5.00193012939056e-01, 5.00173220168024e-01,
+  5.00156323280355e-01, 5.00141783641018e-01, 5.00129182278347e-01,
+  5.00118189340972e-01, 5.00108542278496e-01, 5.00100030010003e-01,
+  5.00092481273333e-01, 5.00085755939229e-01, 5.00079738458365e-01,
+  5.00074332862969e-01, 5.00069458915387e-01, 5.00065049112355e-01,
+  5.00061046334395e-01
+};
+
+static const double V1inv[5 * 5] = {
+  .47140452079103168293e-1, .37712361663282534635, .56568542494923801952,
+  .37712361663282534635, .47140452079103168293e-1,
+  -.81649658092772603273e-1, -.46188021535170061160, 0,
+  .46188021535170061160, .81649658092772603273e-1, .15058465048420853962,
+  .12046772038736683169, -.54210474174315074262, .12046772038736683169,
+  .15058465048420853962, -.21380899352993950775, .30237157840738178177, -0.,
+  -.30237157840738178177, .21380899352993950775, .10774960475223581324,
+  -.21549920950447162648, .21549920950447162648, -.21549920950447162648,
+  .10774960475223581324
+};
+
+static const double V2inv[9 * 9] = {
+  .11223917161691230546e-1, .10339219839658349826, .19754094204576565761,
+  .25577315077753587922, .27835314560994251755, .25577315077753587922,
+  .19754094204576565761, .10339219839658349826, .11223917161691230546e-1,
+  -.19440394783993476970e-1, -.16544884625069155470, -.24193725566041460608,
+  -.16953338808305493604, 0.0, .16953338808305493604, .24193725566041460608,
+  .16544884625069155470, .19440394783993476970e-1, .26466393115406349388e-1,
+  .17766815796285469394, .11316664642449611462, -.16306601003711325980,
+  -.30847037493128779631, -.16306601003711325980, .11316664642449611462,
+  .17766815796285469394, .26466393115406349388e-1,
+  -.32395302049990834508e-1, -.15521142532414866547,
+  .88573492664788602740e-1, .29570405784974857322, 0.0,
+  -.29570405784974857322, -.88573492664788602740e-1, .15521142532414866547,
+  .32395302049990834508e-1, .41442155673936851246e-1,
+  .98186757907405608245e-1, -.23056908429499411784,
+  -.68047008326360625520e-1, .31797435808002456774,
+  -.68047008326360625520e-1, -.23056908429499411784,
+  .98186757907405608245e-1, .41442155673936851246e-1,
+  -.49981120317798783134e-1, -.24861810572835756217e-1,
+  .23561326072010832539, -.24472785656448415351, 0.0, .24472785656448415351,
+  -.23561326072010832539, .24861810572835756217e-1,
+  .49981120317798783134e-1, .79691635865674781228e-1,
+  -.95725617891693941833e-1, -.57957553356854386344e-1,
+  .21164072460540271452, -.27529837844505833514, .21164072460540271452,
+  -.57957553356854386344e-1, -.95725617891693941833e-1,
+  .79691635865674781228e-1,
+  -.10894869830716590913, .20131094491947531782, -.15407672674888869038,
+  .83385723639789791384e-1, 0.0, -.83385723639789791384e-1,
+  .15407672674888869038, -.20131094491947531782, .10894869830716590913,
+  .54581057089643838221e-1, -.10916211417928767644, .10916211417928767644,
+  -.10916211417928767644, .10916211417928767644, -.10916211417928767644,
+  .10916211417928767644, -.10916211417928767644, .54581057089643838221e-1
+};
+
+static const double V3inv[17 * 17] = {
+  .27729677693590098996e-2, .26423663180333065153e-1,
+  .53374068493933898312e-1, .77007854739523195947e-1,
+  .98257061072911596869e-1, .11538049741786835604, .12832134344120884559,
+  .13612785914022865001, .13888293186236181317, .13612785914022865001,
+  .12832134344120884559, .11538049741786835604, .98257061072911596869e-1,
+  .77007854739523195947e-1, .53374068493933898312e-1,
+  .26423663180333065153e-1, .27729677693590098996e-2,
+  -.48029210642807413690e-2, -.44887724635478800254e-1,
+  -.85409520147301089416e-1, -.11090267822061423050, -.12033983162705862441,
+  -.11102786862182788886, -.85054870109799336515e-1,
+  -.45998467987742225160e-1, 0.0, .45998467987742225160e-1,
+  .85054870109799336515e-1, .11102786862182788886, .12033983162705862441,
+  .11090267822061423050, .85409520147301089416e-1, .44887724635478800254e-1,
+  .48029210642807413690e-2, .62758546879582030087e-2,
+  .55561297093529155869e-1,
+  .93281491021051539742e-1, .92320151237493695139e-1,
+  .55077987469605684531e-1,
+  -.96998141716497488255e-2, -.80285961895427405567e-1,
+  -.13496839655913850224,
+  -.15512521776684524331, -.13496839655913850224, -.80285961895427405567e-1,
+  -.96998141716497488255e-2, .55077987469605684531e-1,
+  .92320151237493695139e-1, .93281491021051539742e-1,
+  .55561297093529155869e-1, .62758546879582030087e-2,
+  -.74850969394858555939e-2, -.61751608943839234096e-1,
+  -.82974150437304275958e-1, -.38437763431942633378e-1,
+  .45745502025779701366e-1, .12369235652734542162, .14720439712852868239,
+  .98768034347019704401e-1, 0.0,
+  -.98768034347019704401e-1, -.14720439712852868239, -.12369235652734542162,
+  -.45745502025779701366e-1, .38437763431942633378e-1,
+  .82974150437304275958e-1, .61751608943839234096e-1,
+  .74850969394858555939e-2, .86710099994384056338e-2,
+  .64006230103659573344e-1, .58517426396091675690e-1,
+  -.29743410528985802680e-1,
+  -.11934127779157114754, -.12686773515361299409, -.30729137153877447035e-1,
+  .97307836256600731568e-1, .15635811574451401023, .97307836256600731568e-1,
+  -.30729137153877447035e-1, -.12686773515361299409, -.11934127779157114754,
+  -.29743410528985802680e-1, .58517426396091675690e-1,
+  .64006230103659573344e-1, .86710099994384056338e-2,
+  -.97486395666294840165e-2, -.62995604908060224672e-1,
+  -.24373234450275529219e-1, .87760984413626872730e-1,
+  .12205204576993351394,
+  .16216004196864002088e-1, -.12422320942156845775, -.13682714580929614678,
+  0.0, .13682714580929614678, .12422320942156845775,
+  -.16216004196864002088e-1, -.12205204576993351394,
+  -.87760984413626872730e-1, .24373234450275529219e-1,
+  .62995604908060224672e-1, .97486395666294840165e-2,
+  .10956271233750488468e-1, .58613204255294358939e-1,
+  -.13306063940736618859e-1, -.11606666444978454399,
+  -.52059598001115805639e-1, .10868540217796151849, .12594452879014618005,
+  -.44678658254872910434e-1, -.15617684362128533405,
+  -.44678658254872910434e-1, .12594452879014618005, .10868540217796151849,
+  -.52059598001115805639e-1, -.11606666444978454399,
+  -.13306063940736618859e-1, .58613204255294358939e-1,
+  .10956271233750488468e-1, -.12098893000863087230e-1,
+  -.51626244709126208453e-1, .48919433304746979330e-1,
+  .10467644465949427090,
+  -.48729879523084673782e-1, -.13668732103524749234, .28190838706814496438e-1,
+  .15434223333238741600, 0.0, -.15434223333238741600,
+  -.28190838706814496438e-1, .13668732103524749234,
+  .48729879523084673782e-1, -.10467644465949427090,
+  -.48919433304746979330e-1, .51626244709126208453e-1,
+  .12098893000863087230e-1, .13542668300437944822e-1,
+  .41712033418258689308e-1,
+  -.76190463272803434388e-1, -.58303943170068132010e-1, .12158068748245606853,
+  .42121099930651007882e-1, -.14684425840766337756,
+  -.16108203535058647043e-1, .15698075850757976092,
+  -.16108203535058647043e-1, -.14684425840766337756,
+  .42121099930651007882e-1, .12158068748245606853,
+  -.58303943170068132010e-1, -.76190463272803434388e-1,
+  .41712033418258689308e-1, .13542668300437944822e-1,
+  -.14939634995117694417e-1, -.30047246373341564039e-1,
+  .91624635082546425678e-1, -.79133374319110026377e-2,
+  -.12292558212072233355, .90013382617762643524e-1,
+  .84013717196539593395e-1, -.14813033309980695856, 0.0,
+  .14813033309980695856, -.84013717196539593395e-1,
+  -.90013382617762643524e-1,
+  .12292558212072233355, .79133374319110026377e-2, -.91624635082546425678e-1,
+  .30047246373341564039e-1, .14939634995117694417e-1,
+  .16986031342807474208e-1,
+  .15760203882617033601e-1, -.91494054040950941996e-1,
+  .70082459207876130806e-1,
+  .53390713710144539104e-1, -.14340746778352039430, .84048122493418898508e-1,
+  .72456667788091316868e-1, -.15564535320096811360,
+  .72456667788091316868e-1, .84048122493418898508e-1,
+  -.14340746778352039430, .53390713710144539104e-1,
+  .70082459207876130806e-1, -.91494054040950941996e-1,
+  .15760203882617033601e-1,
+  .16986031342807474208e-1, -.18994065631858742028e-1,
+  -.82901821370405592927e-3, .77239669773015192888e-1,
+  -.10850735431039424680, .47524484622086496464e-1,
+  .69148184871588737021e-1, -.14829314646228194928, .11992057742398672066,
+  0.0, -.11992057742398672066, .14829314646228194928,
+  -.69148184871588737021e-1, -.47524484622086496464e-1,
+  .10850735431039424680, -.77239669773015192888e-1,
+  .82901821370405592927e-3, .18994065631858742028e-1,
+  .22761703826371535132e-1, -.17728848711449643358e-1,
+  -.47496371572480503788e-1, .10659958402328690063, -.11696013966166296514,
+  .63073750910894244526e-1, .32928881123602721303e-1,
+  -.12280950532497593683, .15926189077282729505, -.12280950532497593683,
+  .32928881123602721303e-1, .63073750910894244526e-1,
+  -.11696013966166296514, .10659958402328690063, -.47496371572480503788e-1,
+  -.17728848711449643358e-1, .22761703826371535132e-1,
+  -.26493215276042203434e-1, .35579780856128386192e-1,
+  .10447309718398935122e-1, -.68616154085314996709e-1,
+  .11775363082763954214, -.13918901977011837274, .12312819418827395690,
+  -.72053565748259077905e-1, 0.0, .72053565748259077905e-1,
+  -.12312819418827395690, .13918901977011837274, -.11775363082763954214,
+  .68616154085314996709e-1, -.10447309718398935122e-1,
+  -.35579780856128386192e-1,
+  .26493215276042203434e-1, .40742523354399706918e-1,
+  -.73124912999529117195e-1, .49317266444153837821e-1,
+  -.13686605413876015320e-1, -.28342624942191100464e-1,
+  .70371855298258216249e-1, -.10600251632853603875, .12981016288391131812,
+  -.13817029659318161476, .12981016288391131812, -.10600251632853603875,
+  .70371855298258216249e-1, -.28342624942191100464e-1,
+  -.13686605413876015320e-1,
+  .49317266444153837821e-1, -.73124912999529117195e-1,
+  .40742523354399706918e-1, -.54944368958699908688e-1,
+  .10777725663147408190, -.10152395581538265428, .91369146312596428468e-1,
+  -.77703071757424700773e-1, .61050911730999815031e-1,
+  -.42052599404498348871e-1, .21438229266251454773e-1, 0.0,
+  -.21438229266251454773e-1, .42052599404498348871e-1,
+  -.61050911730999815031e-1, .77703071757424700773e-1,
+  -.91369146312596428468e-1,
+  .10152395581538265428, -.10777725663147408190, .54944368958699908688e-1,
+  .27485608464748840573e-1, -.54971216929497681146e-1,
+  .54971216929497681146e-1,
+  -.54971216929497681146e-1, .54971216929497681146e-1,
+  -.54971216929497681146e-1, .54971216929497681146e-1,
+  -.54971216929497681146e-1, .54971216929497681146e-1,
+  -.54971216929497681146e-1, .54971216929497681146e-1,
+  -.54971216929497681146e-1, .54971216929497681146e-1,
+  -.54971216929497681146e-1, .54971216929497681146e-1,
+  -.54971216929497681146e-1, .27485608464748840573e-1
+};
+
+static const double V4inv[33 * 33] = {
+  .69120897476690862600e-3, .66419939766331555194e-2,
+  .13600665164323186111e-1, .20122785860913684493e-1,
+  .26583214101668429944e-1, .32712713318999268739e-1,
+  .38576221976287138036e-1, .44033030938268925133e-1,
+  .49092709529622799673e-1, .53657949874312515646e-1,
+  .57724533144734311859e-1, .61219564530655179096e-1,
+  .64138907503837875026e-1, .66427905189318792009e-1,
+  .68088956652280022887e-1, .69083051391555695878e-1,
+  .69422738116739271449e-1, .69083051391555695878e-1,
+  .68088956652280022887e-1, .66427905189318792009e-1,
+  .64138907503837875026e-1, .61219564530655179096e-1,
+  .57724533144734311859e-1, .53657949874312515646e-1,
+  .49092709529622799673e-1, .44033030938268925133e-1,
+  .38576221976287138036e-1, .32712713318999268739e-1,
+  .26583214101668429944e-1, .20122785860913684493e-1,
+  .13600665164323186111e-1, .66419939766331555194e-2,
+  .69120897476690862600e-3, -.11972090629438798134e-2,
+  -.11448874821643225573e-1, -.23104401104002905904e-1,
+  -.33352899418646530133e-1, -.42538626424075425908e-1,
+  -.49969730733911825941e-1, -.55555454015360728353e-1,
+  -.58955533624852604918e-1, -.60126044219122513907e-1,
+  -.58959430451175833624e-1, -.55546925396227130606e-1,
+  -.49984739749347973762e-1, -.42513009141170294365e-1,
+  -.33399140950669746346e-1, -.23007690803851790829e-1,
+  -.11728275717520066169e-1, 0.0, .11728275717520066169e-1,
+  .23007690803851790829e-1, .33399140950669746346e-1,
+  .42513009141170294365e-1, .49984739749347973762e-1,
+  .55546925396227130606e-1, .58959430451175833624e-1,
+  .60126044219122513907e-1, .58955533624852604918e-1,
+  .55555454015360728353e-1, .49969730733911825941e-1,
+  .42538626424075425908e-1, .33352899418646530133e-1,
+  .23104401104002905904e-1, .11448874821643225573e-1,
+  .11972090629438798134e-2, .15501585012936019146e-2,
+  .14628781502199620482e-1, .28684915921474815271e-1,
+  .39299396074628048026e-1, .46393418975496284204e-1,
+  .48756902531094699526e-1, .46331333488337494692e-1,
+  .39012645376980228775e-1, .27452795421085791153e-1,
+  .12430953621169863781e-1, -.47682978056024928800e-2,
+  -.22825828045428973853e-1,
+  -.40195512090720278312e-1, -.55503004262826221955e-1,
+  -.67424537752827046308e-1, -.75020199300113606452e-1,
+  -.77607844312483656131e-1, -.75020199300113606452e-1,
+  -.67424537752827046308e-1, -.55503004262826221955e-1,
+  -.40195512090720278312e-1, -.22825828045428973853e-1,
+  -.47682978056024928800e-2, .12430953621169863781e-1,
+  .27452795421085791153e-1, .39012645376980228775e-1,
+  .46331333488337494692e-1, .48756902531094699526e-1,
+  .46393418975496284204e-1, .39299396074628048026e-1,
+  .28684915921474815271e-1, .14628781502199620482e-1,
+  .15501585012936019146e-2, -.18377757558949194214e-2,
+  -.17050470050949761565e-1, -.31952119564923250836e-1,
+  -.40197423449026348155e-1,
+  -.41205649520281371624e-1, -.33909965817492272248e-1,
+  -.19393664422115332144e-1, .56661049630886784692e-3,
+  .22948272173686561721e-1, .44489719570904738207e-1,
+  .61790363672287920596e-1, .72121014727028013894e-1,
+  .73627151185287858579e-1, .65784665375961398923e-1,
+  .49369676372333667559e-1, .26444326317059715065e-1, 0.0,
+  -.26444326317059715065e-1, -.49369676372333667559e-1,
+  -.65784665375961398923e-1, -.73627151185287858579e-1,
+  -.72121014727028013894e-1, -.61790363672287920596e-1,
+  -.44489719570904738207e-1, -.22948272173686561721e-1,
+  -.56661049630886784692e-3, .19393664422115332144e-1,
+  .33909965817492272248e-1, .41205649520281371624e-1,
+  .40197423449026348155e-1, .31952119564923250836e-1,
+  .17050470050949761565e-1, .18377757558949194214e-2,
+  .20942714740729767769e-2, .18935902405146518232e-1,
+  .33335840852491735126e-1, .36770680999102286065e-1,
+  .28873194534132768509e-1, .10267303017729535513e-1,
+  -.14607738306201572890e-1, -.40139568545572305818e-1,
+  -.59808326733858291561e-1, -.68528358823372627506e-1,
+  -.63306535387619244879e-1, -.44508601817574921056e-1,
+  -.15449116105605395357e-1, .17941083795006546367e-1,
+  .48747356011657242123e-1, .70329553984201665523e-1,
+  .78106117292526169663e-1, .70329553984201665523e-1,
+  .48747356011657242123e-1, .17941083795006546367e-1,
+  -.15449116105605395357e-1, -.44508601817574921056e-1,
+  -.63306535387619244879e-1, -.68528358823372627506e-1,
+  -.59808326733858291561e-1,
+  -.40139568545572305818e-1, -.14607738306201572890e-1,
+  .10267303017729535513e-1, .28873194534132768509e-1,
+  .36770680999102286065e-1, .33335840852491735126e-1,
+  .18935902405146518232e-1, .20942714740729767769e-2,
+  -.23245285491878278419e-2, -.20401404737639389919e-1,
+  -.33019548231022514097e-1, -.29709828426463720091e-1,
+  -.11760070922697422156e-1, .15987584743850393793e-1,
+  .43619012891472813485e-1, .61177322409671487721e-1,
+  .61144030218486655594e-1,
+  .41895377620089086167e-1, .80232011820644308033e-2,
+  -.30574701186675900915e-1,
+  -.62072243008844865848e-1, -.76336186183574765586e-1,
+  -.68435466095345537115e-1, -.40237669208466966207e-1, 0.0,
+  .40237669208466966207e-1, .68435466095345537115e-1,
+  .76336186183574765586e-1, .62072243008844865848e-1,
+  .30574701186675900915e-1, -.80232011820644308033e-2,
+  -.41895377620089086167e-1, -.61144030218486655594e-1,
+  -.61177322409671487721e-1, -.43619012891472813485e-1,
+  -.15987584743850393793e-1, .11760070922697422156e-1,
+  .29709828426463720091e-1, .33019548231022514097e-1,
+  .20401404737639389919e-1, .23245285491878278419e-2,
+  .25451717261579269307e-2, .21480418595666878775e-1,
+  .31177212469293007998e-1, .19816333607013379373e-1,
+  -.72439496274458793681e-2, -.38404203906598342397e-1,
+  -.57633632255322221046e-1, -.54070547403585392952e-1,
+  -.26249823354368866005e-1, .15643058212336881516e-1,
+  .54539832735118677194e-1, .73283028002473989724e-1,
+  .62835303524135936213e-1, .26175977027801048141e-1,
+  -.22193636309998606610e-1, -.62597049956093311234e-1,
+  -.78206986173170212505e-1, -.62597049956093311234e-1,
+  -.22193636309998606610e-1, .26175977027801048141e-1,
+  .62835303524135936213e-1,
+  .73283028002473989724e-1, .54539832735118677194e-1,
+  .15643058212336881516e-1,
+  -.26249823354368866005e-1, -.54070547403585392952e-1,
+  -.57633632255322221046e-1, -.38404203906598342397e-1,
+  -.72439496274458793681e-2, .19816333607013379373e-1,
+  .31177212469293007998e-1, .21480418595666878775e-1,
+  .25451717261579269307e-2, -.27506573922483820005e-2,
+  -.22224442095099251870e-1, -.27949927254215773020e-1,
+  -.80918481053370034987e-2, .25121859354449306916e-1,
+  .51563535009373061074e-1, .51936965107145960512e-1,
+  .22146626648171527753e-1,
+  -.24172689882103382748e-1, -.61731229104853568296e-1,
+  -.68477262429344201201e-1, -.38311232728303704742e-1,
+  .14160578713659552679e-1, .61248813427564184033e-1,
+  .77136328841293031805e-1, .52514801765183697988e-1, 0.0,
+  -.52514801765183697988e-1, -.77136328841293031805e-1,
+  -.61248813427564184033e-1, -.14160578713659552679e-1,
+  .38311232728303704742e-1,
+  .68477262429344201201e-1, .61731229104853568296e-1,
+  .24172689882103382748e-1,
+  -.22146626648171527753e-1, -.51936965107145960512e-1,
+  -.51563535009373061074e-1, -.25121859354449306916e-1,
+  .80918481053370034987e-2, .27949927254215773020e-1,
+  .22224442095099251870e-1, .27506573922483820005e-2,
+  .29562461131654311467e-2, .22630271480554450613e-1,
+  .23547399831373800971e-1, -.43964593440902476642e-2,
+  -.39055315767504970597e-1, -.52369643937940066804e-1,
+  -.28506131614971613422e-1, .19906048093338832322e-1,
+  .60408880866392420279e-1, .62493397473656883090e-1,
+  .21391278377641297859e-1, -.37302864786623254746e-1,
+  -.73665127933539496872e-1, -.61706142476854010202e-1,
+  -.78065168882546327888e-2, .52335307373945544428e-1,
+  .78278746279419264777e-1, .52335307373945544428e-1,
+  -.78065168882546327888e-2, -.61706142476854010202e-1,
+  -.73665127933539496872e-1, -.37302864786623254746e-1,
+  .21391278377641297859e-1, .62493397473656883090e-1,
+  .60408880866392420279e-1, .19906048093338832322e-1,
+  -.28506131614971613422e-1, -.52369643937940066804e-1,
+  -.39055315767504970597e-1, -.43964593440902476642e-2,
+  .23547399831373800971e-1, .22630271480554450613e-1,
+  .29562461131654311467e-2, -.31515718415504761303e-2,
+  -.22739451096655080673e-1, -.18157123602272119779e-1,
+  .16496480897167303621e-1, .46921166788569301124e-1,
+  .40644395739978416354e-1, -.46275803430732216900e-2,
+  -.52883375891308909486e-1, -.61116483226324111734e-1,
+  -.17411698764545629853e-1, .44773430013166822765e-1,
+  .73441577962383869198e-1, .42127368371995472815e-1,
+  -.25504645957196772465e-1, -.74126818045972742488e-1,
+  -.62780077864719287317e-1, 0.0, .62780077864719287317e-1,
+  .74126818045972742488e-1, .25504645957196772465e-1,
+  -.42127368371995472815e-1, -.73441577962383869198e-1,
+  -.44773430013166822765e-1, .17411698764545629853e-1,
+  .61116483226324111734e-1, .52883375891308909486e-1,
+  .46275803430732216900e-2, -.40644395739978416354e-1,
+  -.46921166788569301124e-1, -.16496480897167303621e-1,
+  .18157123602272119779e-1, .22739451096655080673e-1,
+  .31515718415504761303e-2, .33536559294882188208e-2,
+  .22535348942792006185e-1,
+  .12048629300953560767e-1, -.27166076791299493403e-1,
+  -.47492745604230978367e-1, -.19246623430993153174e-1,
+  .36231297307556299322e-1, .61713617181636122004e-1,
+  .25928029734266134490e-1, -.40478700752883602818e-1,
+  -.71053889866326412049e-1, -.31870824482961751482e-1,
+  .41515251100219081281e-1, .76481960760098381651e-1,
+  .36726509155999912440e-1, -.40090067032627055969e-1,
+  -.78270742903374539397e-1, -.40090067032627055969e-1,
+  .36726509155999912440e-1, .76481960760098381651e-1,
+  .41515251100219081281e-1, -.31870824482961751482e-1,
+  -.71053889866326412049e-1, -.40478700752883602818e-1,
+  .25928029734266134490e-1, .61713617181636122004e-1,
+  .36231297307556299322e-1, -.19246623430993153174e-1,
+  -.47492745604230978367e-1, -.27166076791299493403e-1,
+  .12048629300953560767e-1, .22535348942792006185e-1,
+  .33536559294882188208e-2,
+  -.35481220456925318865e-2, -.22062913693073191150e-1,
+  -.54487362861834144999e-2, .35438821865804087489e-1,
+  .40733077820527411302e-1, -.67403098138950720914e-2,
+  -.55559584405239171054e-1, -.42417050790865158745e-1,
+  .24499901971884704925e-1, .68721232891705409302e-1,
+  .34086082787461126592e-1, -.43441000373118474002e-1,
+  -.73878085292669148950e-1, -.18846995664706657127e-1,
+  .59827776178286834498e-1, .70644634584085901794e-1, 0.0,
+  -.70644634584085901794e-1, -.59827776178286834498e-1,
+  .18846995664706657127e-1, .73878085292669148950e-1,
+  .43441000373118474002e-1, -.34086082787461126592e-1,
+  -.68721232891705409302e-1, -.24499901971884704925e-1,
+  .42417050790865158745e-1, .55559584405239171054e-1,
+  .67403098138950720914e-2, -.40733077820527411302e-1,
+  -.35438821865804087489e-1, .54487362861834144999e-2,
+  .22062913693073191150e-1, .35481220456925318865e-2,
+  .37554176816665075631e-2, .21297045781589919482e-1,
+  -.13327293083183431816e-2,
+  -.40635299172764596484e-1, -.27659860508374175359e-1,
+  .31089232744083445986e-1, .56113781541334176109e-1,
+  .37577840643257763400e-2, -.60511227350664590865e-1,
+  -.46670556446129053853e-1, .33263195878575888247e-1,
+  .72757324720645228775e-1, .15011712351692283635e-1,
+  -.65601212994924119078e-1, -.60016855838843789772e-1,
+  .26220858553188665966e-1, .78322776605833552980e-1,
+  .26220858553188665966e-1, -.60016855838843789772e-1,
+  -.65601212994924119078e-1,
+  .15011712351692283635e-1, .72757324720645228775e-1,
+  .33263195878575888247e-1,
+  -.46670556446129053853e-1, -.60511227350664590865e-1,
+  .37577840643257763400e-2, .56113781541334176109e-1,
+  .31089232744083445986e-1, -.27659860508374175359e-1,
+  -.40635299172764596484e-1, -.13327293083183431816e-2,
+  .21297045781589919482e-1, .37554176816665075631e-2,
+  -.39566995305720591229e-2, -.20291873414438919995e-1,
+  .80617453830770930551e-2, .42270189157016547906e-1,
+  .10332624526759093004e-1, -.48054759547616142024e-1,
+  -.37678032941171643972e-1,
+  .36617192625732482394e-1, .61009425973424865714e-1,
+  -.95589113168026591466e-2,
+  -.71023202645076922361e-1, -.25097788086808784456e-1,
+  .62406621963267050244e-1, .56907293171100693511e-1,
+  -.36435383083882206257e-1, -.75790105119208756348e-1, 0.0,
+  .75790105119208756348e-1, .36435383083882206257e-1,
+  -.56907293171100693511e-1, -.62406621963267050244e-1,
+  .25097788086808784456e-1, .71023202645076922361e-1,
+  .95589113168026591466e-2,
+  -.61009425973424865714e-1, -.36617192625732482394e-1,
+  .37678032941171643972e-1, .48054759547616142024e-1,
+  -.10332624526759093004e-1, -.42270189157016547906e-1,
+  -.80617453830770930551e-2, .20291873414438919995e-1,
+  .39566995305720591229e-2, .41776092289182138591e-2,
+  .19013221163904414395e-1, -.14420609729849899876e-1,
+  -.40259160586844441220e-1, .86327811113710831649e-2,
+  .53564430703021034399e-1, .65469185402150431933e-2,
+  -.60383116311280629856e-1,
+  -.25657793784058876939e-1, .58745680576829226900e-1,
+  .45649937869034420296e-1,
+  -.49167932056844167772e-1, -.62696614328552187977e-1,
+  .32540234556426699997e-1, .74280410383464269758e-1,
+  -.11425672633410999870e-1, -.78280649404686404903e-1,
+  -.11425672633410999870e-1, .74280410383464269758e-1,
+  .32540234556426699997e-1, -.62696614328552187977e-1,
+  -.49167932056844167772e-1, .45649937869034420296e-1,
+  .58745680576829226900e-1, -.25657793784058876939e-1,
+  -.60383116311280629856e-1, .65469185402150431933e-2,
+  .53564430703021034399e-1,
+  .86327811113710831649e-2, -.40259160586844441220e-1,
+  -.14420609729849899876e-1, .19013221163904414395e-1,
+  .41776092289182138591e-2, -.43935502082478059199e-2,
+  -.17528761237509401631e-1, .20208915249153872535e-1,
+  .34734743119040669109e-1, -.26275910172353637955e-1,
+  -.46368003346018878786e-1,
+  .26800056330709381025e-1, .56681476464606609921e-1,
+  -.24749011438127255898e-1,
+  -.64934612189056658992e-1, .20333742247679279535e-1,
+  .71429299070059318651e-1,
+  -.14452513210428671266e-1, -.75793341281736586582e-1,
+  .74717094137184935270e-2, .78034921554757317374e-1, 0.0,
+  -.78034921554757317374e-1, -.74717094137184935270e-2,
+  .75793341281736586582e-1, .14452513210428671266e-1,
+  -.71429299070059318651e-1, -.20333742247679279535e-1,
+  .64934612189056658992e-1, .24749011438127255898e-1,
+  -.56681476464606609921e-1,
+  -.26800056330709381025e-1, .46368003346018878786e-1,
+  .26275910172353637955e-1,
+  -.34734743119040669109e-1, -.20208915249153872535e-1,
+  .17528761237509401631e-1, .43935502082478059199e-2,
+  .46379089482818671473e-2, .15791188144791287229e-1,
+  -.25134290048737455284e-1, -.26249795071946841205e-1,
+  .39960457575789924651e-1, .28111892450146525404e-1,
+  -.51026476400767918226e-1,
+  -.27266747278681831364e-1, .60708796647861610865e-1,
+  .23532306960642115854e-1,
+  -.68169639871532441111e-1, -.18204924701958312032e-1,
+  .73822890510656128485e-1, .11373392486424717019e-1,
+  -.77133324017644609416e-1, -.39295877480342619961e-2,
+  .78351902829418987960e-1, -.39295877480342619961e-2,
+  -.77133324017644609416e-1, .11373392486424717019e-1,
+  .73822890510656128485e-1, -.18204924701958312032e-1,
+  -.68169639871532441111e-1, .23532306960642115854e-1,
+  .60708796647861610865e-1, -.27266747278681831364e-1,
+  -.51026476400767918226e-1, .28111892450146525404e-1,
+  .39960457575789924651e-1, -.26249795071946841205e-1,
+  -.25134290048737455284e-1, .15791188144791287229e-1,
+  .46379089482818671473e-2, -.48780095920069827068e-2,
+  -.13886961667516983541e-1, .29071311049368895844e-1,
+  .15480559452075811600e-1, -.47527977686242313065e-1,
+  -.31929089844361042178e-2, .58015667638415922967e-1,
+  -.14547915466597622925e-1, -.61067668299848923244e-1,
+  .35093678009090186851e-1, .55378399159800654657e-1,
+  -.54277226474891610385e-1, -.42023830782434076509e-1,
+  .69197384645944912066e-1, .22610783557709586445e-1,
+  -.77269275900637030185e-1, 0.0, .77269275900637030185e-1,
+  -.22610783557709586445e-1,
+  -.69197384645944912066e-1, .42023830782434076509e-1,
+  .54277226474891610385e-1,
+  -.55378399159800654657e-1, -.35093678009090186851e-1,
+  .61067668299848923244e-1, .14547915466597622925e-1,
+  -.58015667638415922967e-1, .31929089844361042178e-2,
+  .47527977686242313065e-1, -.15480559452075811600e-1,
+  -.29071311049368895844e-1, .13886961667516983541e-1,
+  .48780095920069827068e-2, .51591759101720291381e-2,
+  .11747497650231330965e-1, -.31777863364694653331e-1,
+  -.34555825499804605557e-2, .47914131921157015198e-1,
+  -.22573685920142225247e-1, -.45320344390022666738e-1,
+  .49660630547172186418e-1, .25707858143963615736e-1,
+  -.68132707341917233933e-1, .67534860185243140399e-2,
+  .69268150370037450063e-1, -.41585011920451477177e-1,
+  -.51622397460510041271e-1, .68408139576363036148e-1,
+  .18981259024768933323e-1, -.78265472429342305554e-1,
+  .18981259024768933323e-1, .68408139576363036148e-1,
+  -.51622397460510041271e-1,
+  -.41585011920451477177e-1, .69268150370037450063e-1,
+  .67534860185243140399e-2,
+  -.68132707341917233933e-1, .25707858143963615736e-1,
+  .49660630547172186418e-1,
+  -.45320344390022666738e-1, -.22573685920142225247e-1,
+  .47914131921157015198e-1, -.34555825499804605557e-2,
+  -.31777863364694653331e-1, .11747497650231330965e-1,
+  .51591759101720291381e-2, -.54365757412741340377e-2,
+  -.94862516619529080191e-2, .33240472093448190877e-1,
+  -.88698898099681552229e-2,
+  -.40973252097216337576e-1, .42995673349795657065e-1,
+  .17320914507876958783e-1,
+  -.62201292691914856803e-1, .24726274174637346693e-1,
+  .51320859246515407288e-1,
+  -.62882063373810501763e-1, -.11003569131725622672e-1,
+  .73842261324108943465e-1, -.39240120294802923208e-1,
+  -.49293966443941122807e-1, .73552644778818223475e-1, 0.0,
+  -.73552644778818223475e-1, .49293966443941122807e-1,
+  .39240120294802923208e-1, -.73842261324108943465e-1,
+  .11003569131725622672e-1, .62882063373810501763e-1,
+  -.51320859246515407288e-1,
+  -.24726274174637346693e-1, .62201292691914856803e-1,
+  -.17320914507876958783e-1, -.42995673349795657065e-1,
+  .40973252097216337576e-1, .88698898099681552229e-2,
+  -.33240472093448190877e-1, .94862516619529080191e-2,
+  .54365757412741340377e-2, .57750194549356126240e-2,
+  .69981166020044116791e-2, -.33274982140403110792e-1,
+  .20297071020698356116e-1, .27898517839646066582e-1,
+  -.53368678853282030262e-1, .16656482990394548343e-1,
+  .46342901447260614255e-1,
+  -.60536796508149003365e-1, .29109107483842596340e-2,
+  .63224486124385124504e-1,
+  -.59028872851312033411e-1, -.14783105962696191734e-1,
+  .74269399241069253865e-1, -.49053677339382384625e-1,
+  -.33525466624811186739e-1, .78397349622515386647e-1,
+  -.33525466624811186739e-1, -.49053677339382384625e-1,
+  .74269399241069253865e-1, -.14783105962696191734e-1,
+  -.59028872851312033411e-1,
+  .63224486124385124504e-1, .29109107483842596340e-2,
+  -.60536796508149003365e-1,
+  .46342901447260614255e-1, .16656482990394548343e-1,
+  -.53368678853282030262e-1,
+  .27898517839646066582e-1, .20297071020698356116e-1,
+  -.33274982140403110792e-1,
+  .69981166020044116791e-2, .57750194549356126240e-2,
+  -.61100308370519200637e-2, -.44383614355738148616e-2,
+  .32011283412619094811e-1, -.29965011866372897633e-1,
+  -.10560682331349193348e-1, .51110336443392506342e-1,
+  -.45012284729681775492e-1, -.94236825555873320102e-2,
+  .60860695783141264746e-1,
+  -.55014628647083368926e-1, -.73474782382499482121e-2,
+  .66640148475243034781e-1, -.62533116045749887988e-1,
+  -.38650525912400102585e-2, .68429769005837003777e-1,
+  -.66984505412544901945e-1, 0.0, .66984505412544901945e-1,
+  -.68429769005837003777e-1, .38650525912400102585e-2,
+  .62533116045749887988e-1, -.66640148475243034781e-1,
+  .73474782382499482121e-2,
+  .55014628647083368926e-1, -.60860695783141264746e-1,
+  .94236825555873320102e-2,
+  .45012284729681775492e-1, -.51110336443392506342e-1,
+  .10560682331349193348e-1,
+  .29965011866372897633e-1, -.32011283412619094811e-1,
+  .44383614355738148616e-2,
+  .61100308370519200637e-2, .65409373892036191538e-2,
+  .16350101107071157065e-2, -.29301957285983144319e-1,
+  .36838667173388832579e-1, -.81922703976491586393e-2,
+  -.36955670021050133434e-1, .58374851095540469865e-1,
+  -.31977016246946181856e-1, -.25311073698658094646e-1,
+  .66674413950106952577e-1,
+  -.54865713324521039571e-1, -.39797027891537985440e-2,
+  .62830285264808449064e-1, -.72226313251296100676e-1,
+  .22560232697133353980e-1, .46455784709904033738e-1,
+  -.78200930751070349956e-1, .46455784709904033738e-1,
+  .22560232697133353980e-1, -.72226313251296100676e-1,
+  .62830285264808449064e-1, -.39797027891537985440e-2,
+  -.54865713324521039571e-1, .66674413950106952577e-1,
+  -.25311073698658094646e-1, -.31977016246946181856e-1,
+  .58374851095540469865e-1, -.36955670021050133434e-1,
+  -.81922703976491586393e-2, .36838667173388832579e-1,
+  -.29301957285983144319e-1, .16350101107071157065e-2,
+  .65409373892036191538e-2, -.69686180931868703196e-2,
+  .11849538727632789870e-2, .25452286414610537766e-1,
+  -.40522480651713943230e-1, .25694679053362813183e-1,
+  .14057118113748390637e-1, -.52037614725803488893e-1,
+  .58849342223684035589e-1,
+  -.25075229077361409271e-1, -.29559771094034181083e-1,
+  .68296746944165720199e-1, -.62890462146423984955e-1,
+  .14457636466274596445e-1, .45787612031322361496e-1,
+  -.77231759014655809742e-1, .57881203613910543657e-1, 0.0,
+  -.57881203613910543657e-1, .77231759014655809742e-1,
+  -.45787612031322361496e-1, -.14457636466274596445e-1,
+  .62890462146423984955e-1,
+  -.68296746944165720199e-1, .29559771094034181083e-1,
+  .25075229077361409271e-1,
+  -.58849342223684035589e-1, .52037614725803488893e-1,
+  -.14057118113748390637e-1, -.25694679053362813183e-1,
+  .40522480651713943230e-1, -.25452286414610537766e-1,
+  -.11849538727632789870e-2, .69686180931868703196e-2,
+  .75611653617520254845e-2, -.43290610418608409141e-2,
+  -.20277062025115566914e-1,
+  .40362947027704828926e-1, -.38938808024132120254e-1,
+  .11831186195916702262e-1,
+  .28476667401744525357e-1, -.59320969056617684621e-1,
+  .61101629747436200186e-1,
+  -.29514834848355389223e-1, -.20668001885001084821e-1,
+  .62923592802445122793e-1, -.73558456263588833115e-1,
+  .45314556330160999776e-1, .79031645918426015574e-2,
+  -.58136953576334689357e-1, .78538474524006405758e-1,
+  -.58136953576334689357e-1, .79031645918426015574e-2,
+  .45314556330160999776e-1, -.73558456263588833115e-1,
+  .62923592802445122793e-1, -.20668001885001084821e-1,
+  -.29514834848355389223e-1, .61101629747436200186e-1,
+  -.59320969056617684621e-1, .28476667401744525357e-1,
+  .11831186195916702262e-1, -.38938808024132120254e-1,
+  .40362947027704828926e-1, -.20277062025115566914e-1,
+  -.43290610418608409141e-2, .75611653617520254845e-2,
+  -.81505692478987769484e-2, .74297333588288568430e-2,
+  .14314212513540223314e-1, -.36711242251332751607e-1,
+  .46240027755503814626e-1, -.34921532671769023773e-1,
+  .46930051972353714773e-2,
+  .32842770336385381562e-1, -.61317813706529588466e-1,
+  .67000809902468893103e-1,
+  -.45337449655535622885e-1, .35794459576271920867e-2,
+  .41830061526027213385e-1,
+  -.72091371931944711708e-1, .74150028530317793195e-1,
+  -.46487632538609942002e-1, 0.0, .46487632538609942002e-1,
+  -.74150028530317793195e-1, .72091371931944711708e-1,
+  -.41830061526027213385e-1, -.35794459576271920867e-2,
+  .45337449655535622885e-1, -.67000809902468893103e-1,
+  .61317813706529588466e-1, -.32842770336385381562e-1,
+  -.46930051972353714773e-2, .34921532671769023773e-1,
+  -.46240027755503814626e-1, .36711242251332751607e-1,
+  -.14314212513540223314e-1, -.74297333588288568430e-2,
+  .81505692478987769484e-2, .90693182942442189743e-2,
+  -.11121000903959576737e-1, -.71308296141317458546e-2,
+  .29219439765986671645e-1, -.45820286629778129593e-1,
+  .49088381175879124421e-1, -.35614888785023038938e-1,
+  .78906970900092777895e-2,
+  .26262843038404929480e-1, -.56143674270125757857e-1,
+  .71700220472378350694e-1,
+  -.66963544500697307945e-1, .42215091779892228883e-1,
+  -.41338867413966866997e-2, -.36164891772995367321e-1,
+  .66584367783847858225e-1, -.77874712365070098328e-1,
+  .66584367783847858225e-1, -.36164891772995367321e-1,
+  -.41338867413966866997e-2, .42215091779892228883e-1,
+  -.66963544500697307945e-1,
+  .71700220472378350694e-1, -.56143674270125757857e-1,
+  .26262843038404929480e-1,
+  .78906970900092777895e-2, -.35614888785023038938e-1,
+  .49088381175879124421e-1,
+  -.45820286629778129593e-1, .29219439765986671645e-1,
+  -.71308296141317458546e-2, -.11121000903959576737e-1,
+  .90693182942442189743e-2, -.99848472706332791043e-2,
+  .14701271465939718856e-1, -.32917820356048383366e-3,
+  -.19201195309873585230e-1, .38409681836626963278e-1,
+  -.51647324405878909521e-1, .54522171113149311354e-1,
+  -.45040302741689006270e-1, .24183738595685990149e-1,
+  .42204134165479735097e-2, -.34317295181348742251e-1,
+  .59542472465494579941e-1, -.74135115907618101263e-1,
+  .74491937840566532596e-1, -.60042604725161994304e-1,
+  .33437677409000083169e-1, 0.0,
+  -.33437677409000083169e-1, .60042604725161994304e-1,
+  -.74491937840566532596e-1, .74135115907618101263e-1,
+  -.59542472465494579941e-1, .34317295181348742251e-1,
+  -.42204134165479735097e-2, -.24183738595685990149e-1,
+  .45040302741689006270e-1, -.54522171113149311354e-1,
+  .51647324405878909521e-1, -.38409681836626963278e-1,
+  .19201195309873585230e-1, .32917820356048383366e-3,
+  -.14701271465939718856e-1, .99848472706332791043e-2,
+  .11775579274769383373e-1, -.19892153937316935880e-1,
+  .95335114477449041055e-2, .57661528440359081617e-2,
+  -.23382690532380910781e-1, .40237257037170725321e-1,
+  -.53280289903551636474e-1, .59974361806023689068e-1,
+  -.58701684061992853224e-1, .49033407111597129616e-1,
+  -.31818835267847249219e-1, .90800541261162098886e-2,
+  .16272906819312603838e-1, -.40863896581186229487e-1,
+  .61346046297517367703e-1,
+  -.74896047554167268919e-1, .79632642148310325817e-1,
+  -.74896047554167268919e-1, .61346046297517367703e-1,
+  -.40863896581186229487e-1, .16272906819312603838e-1,
+  .90800541261162098886e-2, -.31818835267847249219e-1,
+  .49033407111597129616e-1, -.58701684061992853224e-1,
+  .59974361806023689068e-1, -.53280289903551636474e-1,
+  .40237257037170725321e-1, -.23382690532380910781e-1,
+  .57661528440359081617e-2, .95335114477449041055e-2,
+  -.19892153937316935880e-1,
+  .11775579274769383373e-1, -.13562702617218467450e-1,
+  .24885419969649845849e-1, -.18368693901908875583e-1,
+  .81673147806084084638e-2, .47890591326129587131e-2,
+  -.19313752945227974024e-1, .34065953398362954708e-1,
+  -.47667045133463415672e-1, .58820377816690514309e-1,
+  -.66424139824618415970e-1,
+  .69667606260856092515e-1, -.68102459384364543253e-1,
+  .61683024923302547971e-1,
+  -.50771943476441639136e-1, .36110771847327189215e-1,
+  -.18758028464284563358e-1, 0.0, .18758028464284563358e-1,
+  -.36110771847327189215e-1, .50771943476441639136e-1,
+  -.61683024923302547971e-1, .68102459384364543253e-1,
+  -.69667606260856092515e-1, .66424139824618415970e-1,
+  -.58820377816690514309e-1, .47667045133463415672e-1,
+  -.34065953398362954708e-1, .19313752945227974024e-1,
+  -.47890591326129587131e-2, -.81673147806084084638e-2,
+  .18368693901908875583e-1, -.24885419969649845849e-1,
+  .13562702617218467450e-1, .20576545037980523979e-1,
+  -.40093155172981004337e-1, .36954083167944054826e-1,
+  -.31856506837591907746e-1, .24996323181546255126e-1,
+  -.16637165210473614136e-1, .71002706773325085237e-2,
+  .32478629093205201133e-2,
+  -.14009562579050569518e-1, .24771262248780618922e-1,
+  -.35119395835433647559e-1, .44656290368574753171e-1,
+  -.53015448339647394161e-1, .59875631995693046782e-1,
+  -.64973208326045193862e-1, .68112280331082143373e-1,
+  -.69172215234062186994e-1, .68112280331082143373e-1,
+  -.64973208326045193862e-1, .59875631995693046782e-1,
+  -.53015448339647394161e-1, .44656290368574753171e-1,
+  -.35119395835433647559e-1, .24771262248780618922e-1,
+  -.14009562579050569518e-1, .32478629093205201133e-2,
+  .71002706773325085237e-2, -.16637165210473614136e-1,
+  .24996323181546255126e-1, -.31856506837591907746e-1,
+  .36954083167944054826e-1, -.40093155172981004337e-1,
+  .20576545037980523979e-1, -.27584914609096156163e-1,
+  .54904171411058497973e-1, -.54109756419563083153e-1,
+  .52794234894345577483e-1, -.50970276026831042415e-1,
+  .48655445537990983379e-1,
+  -.45872036510847994332e-1, .42646854695899611372e-1,
+  -.39010960357087507670e-1, .34999369144476467749e-1,
+  -.30650714874402762189e-1, .26006877464703437057e-1,
+  -.21112579608213651273e-1, .16014956068786763273e-1,
+  -.10763099747751940252e-1, .54075888924374485533e-2, 0.0,
+  -.54075888924374485533e-2, .10763099747751940252e-1,
+  -.16014956068786763273e-1,
+  .21112579608213651273e-1, -.26006877464703437057e-1,
+  .30650714874402762189e-1,
+  -.34999369144476467749e-1, .39010960357087507670e-1,
+  -.42646854695899611372e-1, .45872036510847994332e-1,
+  -.48655445537990983379e-1, .50970276026831042415e-1,
+  -.52794234894345577483e-1, .54109756419563083153e-1,
+  -.54904171411058497973e-1, .27584914609096156163e-1,
+  .13794141262469565740e-1, -.27588282524939131481e-1,
+  .27588282524939131481e-1, -.27588282524939131481e-1,
+  .27588282524939131481e-1, -.27588282524939131481e-1,
+  .27588282524939131481e-1,
+  -.27588282524939131481e-1, .27588282524939131481e-1,
+  -.27588282524939131481e-1, .27588282524939131481e-1,
+  -.27588282524939131481e-1, .27588282524939131481e-1,
+  -.27588282524939131481e-1, .27588282524939131481e-1,
+  -.27588282524939131481e-1, .27588282524939131481e-1,
+  -.27588282524939131481e-1, .27588282524939131481e-1,
+  -.27588282524939131481e-1, .27588282524939131481e-1,
+  -.27588282524939131481e-1, .27588282524939131481e-1,
+  -.27588282524939131481e-1, .27588282524939131481e-1,
+  -.27588282524939131481e-1, .27588282524939131481e-1,
+  -.27588282524939131481e-1, .27588282524939131481e-1,
+  -.27588282524939131481e-1, .27588282524939131481e-1,
+  -.27588282524939131481e-1, .13794141262469565740e-1
+};
+
+static const double Tleft[33 * 33] = {
+  1., -.86602540378443864678, 0., .33071891388307382381, 0.,
+  -.20728904939721249057, 0., .15128841196122722208, 0.,
+  -.11918864298744029244, 0., .98352013661686631224e-1, 0.,
+  -.83727065404940845733e-1, 0., .72893399403505841203e-1, 0.,
+  -.64544632643375022436e-1, 0., .57913170372415565639e-1, 0.,
+  -.52518242575729562263e-1, 0., .48043311993977520457e-1, 0.,
+  -.44271433659733990243e-1, 0., .41048928022856771981e-1, 0.,
+  -.38263878662008271459e-1, 0., .35832844026365304501e-1, 0., 0.,
+  .50000000000000000000, -.96824583655185422130, .57282196186948000082,
+  .21650635094610966169, -.35903516540862679125, -.97578093724974971969e-1,
+  .26203921611325660506, .55792409597991015609e-1, -.20644078533943456204,
+  -.36172381205961199479e-1, .17035068468874958194,
+  .25371838001497225980e-1, -.14501953125000000000,
+  -.18786835250972344757e-1, .12625507130328301066,
+  .14473795929590520582e-1, -.11179458309419422675,
+  -.11494434254897626155e-1, .10030855351241635862,
+  .93498556820544479096e-2, -.90964264465390582629e-1,
+  -.77546391824364392762e-2, .83213457337452292745e-1,
+  .65358085945588638605e-2, -.76680372422574234569e-1,
+  -.55835321940047427169e-2, .71098828931825789428e-1,
+  .48253327982967591019e-2, -.66274981937248958553e-1,
+  -.42118078245337801387e-2, .62064306433355646267e-1,
+  .37083386598903548973e-2, 0., 0., .25000000000000000000,
+  -.73950997288745200531, .83852549156242113615, -.23175620272173946716,
+  -.37791833195149451496, .25710129174850522325, .21608307321780204633,
+  -.22844049245646009157, -.14009503000335388415, .19897685605518413847,
+  .98264706042471226893e-1, -.17445445004279014046,
+  -.72761100054958328401e-1, .15463589893742108388,
+  .56056770591708784481e-1, -.13855313872640495158,
+  -.44517752443294564781e-1, .12534277657695128850,
+  .36211835346039665762e-1, -.11434398255136139683,
+  -.30033588409423828125e-1, .10506705408753910481,
+  .25313077840725783008e-1, -.97149327637744872155e-1,
+  -.21624927200393328444e-1, .90319582367202122625e-1,
+  .18688433567711780666e-1, -.84372291635345108584e-1,
+  -.16312261561845420752e-1, .79149526894804751586e-1,
+  .14362333871852474757e-1, 0., 0., 0., .12500000000000000000,
+  -.49607837082461073572, .82265291131801144317, -.59621200088559103072,
+  -.80054302859059362371e-1, .42612156697795759420,
+  -.90098145270865592887e-1, -.29769623255090078484, .13630307904779758221,
+  .21638835185708931831, -.14600247270306082052, -.16348801804014290453,
+  .14340708728599057249, .12755243353979286190, -.13661523715071346961,
+  -.10215585947881057394, .12864248070157166547, .83592528025348693602e-1,
+  -.12066728689302565222, -.69633728678718053052e-1, .11314245177331919532,
+  .58882939251410088028e-1, -.10621835858758221487,
+  -.50432266865187597572e-1, .99916834723527771581e-1,
+  .43672094283057258509e-1, -.94206380251950852413e-1,
+  -.38181356812697746418e-1, .89035739656537771225e-1,
+  .33661934598216332678e-1, 0., 0., 0., 0., .62500000000000000000e-1,
+  -.31093357409581873586, .67604086414949799246, -.75644205980613611039,
+  .28990586430124175741, .30648508196770360914, -.35801372616842500052,
+  -.91326869828709014708e-1, .31127929687500000000,
+  -.90915752838698393094e-2, -.25637381283965534330,
+  .57601077850322797594e-1, .21019685709225757945,
+  -.81244992138514014256e-1, -.17375078516720988858,
+  .92289437277967051125e-1, .14527351914265391374,
+  -.96675340792832019889e-1, -.12289485697108543415,
+  .97448175340011084006e-1, .10511755943298339844,
+  -.96242247086378239657e-1, -.90822942272780513537e-1,
+  .93966350452322132384e-1, .79189411876493712558e-1,
+  -.91139307067989309325e-1, -.69613039934383197265e-1,
+  .88062491671135767870e-1, .61646331729340817494e-1, 0., 0., 0., 0., 0.,
+  .31250000000000000000e-1, -.18684782411095934408, .50176689760410660236,
+  -.74784031498626095398, .56472001151566251186, .14842464993721351203e-1,
+  -.41162920273003120936, .20243071230196532282, .23772054897172750436,
+  -.24963810923972235950, -.12116179938394678936, .24330535483519110663,
+  .47903849781124471359e-1, -.22133299683101224293,
+  -.20542915138527200983e-2, .19653465717678146728,
+  -.26818172626509178444e-1, -.17319122357631210944,
+  .45065391411065545445e-1, .15253391395444065941,
+  -.56543897711725408302e-1, -.13469154928743585367,
+  .63632471400208840155e-1, .11941684923913523817,
+  -.67828850207933293098e-1, -.10636309084510652670,
+  .70095786922999181504e-1, .95187373095150709082e-1, 0., 0., 0., 0., 0.,
+  0., .15625000000000000000e-1, -.10909562534194485289,
+  .34842348626527747318, -.64461114561628111443, .69382480527334683659,
+  -.29551102358528827763, -.25527584713978439819, .38878771718544715394,
+  -.82956185835347407489e-2, -.31183177761966943912, .12831420840372374767,
+  .22067618205599434368, -.17569196937129496961, -.14598057000132284135,
+  .18864406621763419484, .89921002550386645767e-1, -.18571835020187122114,
+  -.48967672227195481777e-1, .17584685670380332798,
+  .19267984545067426324e-1, -.16335437520503462738,
+  .22598055455032407594e-2, .15032800884170631129,
+  -.17883358353754640871e-1, -.13774837869432209951,
+  .29227555960587143675e-1, .12604194747513151053, 0., 0., 0., 0., 0., 0.,
+  0., .78125000000000000000e-2, -.62377810244809812496e-1,
+  .23080781467370883845, -.50841310636012325368, .69834547012574056043,
+  -.52572723156526459672, .11464215704954976471e-1, .38698869011491210342,
+  -.26125646622255207507, -.16951698812361607510, .29773875898928782269,
+  .20130501202570367491e-1, -.26332493149159310198,
+  .67734613690401207009e-1, .21207315477103762715, -.11541543390889415193,
+  -.16249634759782417533, .13885887405041735068, .11996491328010275427,
+  -.14810432001630926895, -.85177658352556243411e-1, .14918860659904380587,
+  .57317789510444151564e-1, -.14569827645586660151,
+  -.35213090145965327390e-1, .13975998126844578198, 0., 0., 0., 0., 0., 0.,
+  0., 0., .39062500000000000000e-2, -.35101954600803571207e-1,
+  .14761284084133737720, -.37655033076080192966, .62410290231517322776,
+  -.64335622317683389875, .28188168266139524244, .22488495672137010675,
+  -.39393811089283576186, .75184777995770096714e-1, .28472023119398293003,
+  -.20410910833705899572, -.15590046962908511750, .23814567544617953125,
+  .54442805556829031204e-1, -.22855930338589720954,
+  .16303223615756629897e-1, .20172722433875559213,
+  -.62723406421217419404e-1, -.17012230831020922010,
+  .91754642766136561612e-1, .13927644821381121197, -.10886600968068418181,
+  -.11139075654373395292, .11797455976331702879, 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., .19531250000000000000e-2, -.19506820659607596598e-1,
+  .91865676095362231937e-1, -.26604607809696493849, .51425874205091288223,
+  -.66047561132505329292, .48660109511591303851, -.17575661168678285615e-1,
+  -.36594333408055703366, .29088854695378694533, .11318677346656537927,
+  -.31110645235730182168, .60733219161008787341e-1, .24333848233620420826,
+  -.15254312332655419708, -.15995968483455388613, .19010344455215289289,
+  .86040636766440260000e-1, -.19652589954665259945,
+  -.27633388517205837713e-1, .18660848552712880387,
+  -.15942583868416775867e-1, -.16902042462382064786,
+  .47278526495327740646e-1, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  .97656250000000000000e-3, -.10731084460857378207e-1,
+  .55939644713816406331e-1, -.18118487371914493668, .39914857299829864263,
+  -.60812322949933902435, .60011887183061967583, -.26002695805835928795,
+  -.20883922404786010096, .38988130966114638081, -.11797833550782589082,
+  -.25231824756239520077, .24817859972953934712, .90516417677868996417e-1,
+  -.26079073291293066798, .30259468817169480161e-1, .22178195264114178432,
+  -.10569877864302048175, -.16679648389266977455, .14637718550245050850,
+  .11219272032739559870, -.16359363640525750353, -.64358194509092101393e-1,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .48828125000000000000e-3,
+  -.58542865274813470967e-2, .33461741635290096452e-1,
+  -.11979993155896201271, .29580223766987206958, -.51874761979436016742,
+  .62861483498014306968, -.44868895761051453296, .12567502628371529386e-1,
+  .35040366183235474275, -.30466868455569500886, -.70903913601490112666e-1,
+  .30822791893032512740, -.11969443264190207736, -.20764760317621313946,
+  .20629838355452128532, .95269702915334718507e-1, -.22432624768705133300,
+  -.33103381593477797101e-2, .20570036048155716333,
+  -.62208282720094518964e-1, -.17095309330441436348, 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., .24414062500000000000e-3,
+  -.31714797501871532475e-2, .19721062526127334100e-1,
+  -.77311181185536498246e-1, .21124871792841566575, -.41777980401893650886,
+  .59401977834943551650, -.56132417807488349048, .23433675061367565951,
+  .20222775295220942126, -.38280372496506190127, .14443804214023095767,
+  .22268950939178466797, -.27211314150777981984, -.34184876506180717313e-1,
+  .26006498895669734842, -.97650425186005090107e-1, -.19024527660129101293,
+  .16789164198044635671, .10875811641651905252, -.19276785058805921298, 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .12207031250000000000e-3,
+  -.17078941137247586143e-2, .11477733754843910060e-1,
+  -.48887017020924625462e-1, .14634927241421789683, -.32156282683019547854,
+  .52165811920227223937, -.60001958466396926460, .41208501541480733755,
+  -.11366945503190350975e-2, -.33968093962672089159, .30955190935923386766,
+  .40657421856578262210e-1, -.29873400409871531764, .16094481791768257440,
+  .16876122436206497694, -.23650217045022161255, -.33070260090574765012e-1,
+  .22985258456375907796, -.68645651043827097771e-1, 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., .61035156250000000000e-4,
+  -.91501857608428649078e-3, .66085179496951987952e-2,
+  -.30383171695850355404e-1, .98840838845366876117e-1,
+  -.23855447246420318989, .43322017468145613917, -.58049033744876107191,
+  .52533893203742699346, -.20681056202371946180, -.20180000924562504384,
+  .37503922291962681797, -.15988102869837429062, -.19823558102762374094,
+  .28393023878803799622, -.11188133439357510403e-1, -.24730368377168229255,
+  .14731529061377942839, .14878558042884266021, 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., .30517578125000000000e-4,
+  -.48804277318479845551e-3, .37696080990601968396e-2,
+  -.18603912108994738255e-1, .65325006755649582964e-1,
+  -.17162960707938819795, .34411527956476971322, -.52289350347082497959,
+  .57319653625674910592, -.37662253421045430413, -.14099055105384663902e-1,
+  .33265570610216904208, -.30921265572647566661, -.19911390594166455281e-1,
+  .28738590811031797718, -.18912130469738472647, -.13235936203215819193,
+  .25076406142356675279, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., .15258789062500000000e-4, -.25928719280954633249e-3,
+  .21327398937568540428e-2, -.11244626133630732010e-1,
+  .42375605740664331966e-1, -.12031130345907846211, .26352562258934426830,
+  -.44590628258512682078, .56682835613700749379, -.49116715128261660395,
+  .17845943097110339078, .20541650677432497477, -.36739803642257458221,
+  .16776034069210108273, .17920950989905112908, -.28867732805385066532,
+  .46473465543376206337e-1, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., .76293945312500000000e-5, -.13727610943181290891e-3,
+  .11979683091449349286e-2, -.67195313034570709806e-2,
+  .27044920779931968175e-1, -.82472196498517457862e-1,
+  .19570475044896150093, -.36391620788543817693, .52241392782736588032,
+  -.54727504974907879912, .34211551468813581183, .31580472732719957762e-1,
+  -.32830006549176759667, .30563797665254420769, .64905014620683140120e-2,
+  -.27642986248995073032, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., .38146972656250000000e-5,
+  -.72454147007837596854e-4, .66859847582761390285e-3,
+  -.39751311980366118437e-2, .17015198650201528366e-1,
+  -.55443621868993855715e-1, .14157060481641692131, -.28641242619559616836,
+  .45610665490966615415, -.55262786406029265394, .45818352706035500108,
+  -.14984403004611673047, -.21163807462970713245, .36007252928843413718,
+  -.17030961385712954159, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., .19073486328125000000e-5,
+  -.38135049864067468562e-4, .37101393638555730015e-3,
+  -.23305339886279723213e-2, .10569913448297127219e-1,
+  -.36640175162216897547e-1, .10010476414320235508, -.21860074212675559892,
+  .38124757096345313719, -.52020999209879669177, .52172632730659212045,
+  -.30841620620308814614, -.50322546186721500184e-1, .32577618885114899053,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., .95367431640625000000e-6, -.20021483206955925244e-4,
+  .20481807322420625431e-3, -.13553476938058909882e-2,
+  .64919676350791905019e-2, -.23848725425069251903e-1,
+  .69384632678886421292e-1, -.16249711393618776934, .30736618106830314788,
+  -.46399909601971539157, .53765031034002467225, -.42598991476520183929,
+  .12130445348350215652, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., .47683715820312500000e-6,
+  -.10487707828484902486e-4, .11254146162337528943e-3,
+  -.78248929534271987118e-3, .39468337145306794566e-2,
+  -.15313546659475671763e-1, .47249070825218564146e-1,
+  -.11804374107101480543, .24031796927792491122, -.39629215049166341285,
+  .51629108968402548545, -.49622372075429782915, 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  .23841857910156250000e-6, -.54823314130625337326e-5,
+  .61575377321535518154e-4, -.44877834366497538134e-3,
+  .23774612048621955857e-2, -.97136347645161687796e-2,
+  .31671599547606636717e-1, -.84028665767000747480e-1,
+  .18298487576742964949, -.32647878537696945218, .46970971486488895077, 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., .11920928955078125000e-6, -.28604020001177375838e-5,
+  .33559227978295551013e-4, -.25583821662860610560e-3,
+  .14201552747787302339e-2, -.60938046986874414969e-2,
+  .20930869247951926793e-1, -.58745021125678072911e-1,
+  .13613725780285953720, -.26083988356030237586, 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  .59604644775390625000e-7, -.14898180663526043291e-5,
+  .18224991282807693921e-4, -.14504433444608833821e-3,
+  .84184722720281809548e-3, -.37846965430000478789e-2,
+  .13656355548211376864e-1, -.40409541997718853934e-1,
+  .99226988101858325902e-1, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  .29802322387695312500e-7, -.77471708843445529468e-6,
+  .98649879372606876995e-5, -.81814934772838523887e-4,
+  .49554483992403011328e-3, -.23290922072351413938e-2,
+  .88068134250844034186e-2, -.27393666952485719070e-1, 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., .14901161193847656250e-7, -.40226235946098233685e-6,
+  .53236418690561306700e-5, -.45933829691164002269e-4,
+  .28982005232838857913e-3, -.14212974043211018374e-2,
+  .56192363087488842264e-2, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  .74505805969238281250e-8, -.20858299254133430408e-6,
+  .28648457300134381744e-5, -.25677535898258910850e-4,
+  .16849420429491355445e-3, -.86062824010315834002e-3, 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., .37252902984619140625e-8, -.10801736017613096861e-6,
+  .15376606719887104015e-5, -.14296523739727437959e-4,
+  .97419023656050887203e-4, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  .18626451492309570312e-8, -.55871592916438890146e-7,
+  .82331193828137454068e-6, -.79302250528382787666e-5, 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., .93132257461547851562e-9,
+  -.28867244235852488244e-7, .43982811713864556957e-6, 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., .46566128730773925781e-9,
+  -.14899342093408253335e-7, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+  0., 0., .23283064365386962891e-9
+};
+
+static const double Tright[33 * 33] = {
+  1., .86602540378443864678, 0., -.33071891388307382381, 0.,
+    .20728904939721249057, 0., -.15128841196122722208, 0.,
+    .11918864298744029244, 0., -.98352013661686631224e-1, 0.,
+    .83727065404940845733e-1, 0., -.72893399403505841203e-1, 0.,
+    .64544632643375022436e-1, 0., -.57913170372415565639e-1, 0.,
+    .52518242575729562263e-1, 0., -.48043311993977520457e-1, 0.,
+    .44271433659733990243e-1, 0., -.41048928022856771981e-1, 0.,
+    .38263878662008271459e-1, 0., -.35832844026365304501e-1, 0., 0.,
+    .50000000000000000000, .96824583655185422130, .57282196186948000082,
+    -.21650635094610966169, -.35903516540862679125, .97578093724974971969e-1,
+    .26203921611325660506, -.55792409597991015609e-1, -.20644078533943456204,
+    .36172381205961199479e-1, .17035068468874958194,
+    -.25371838001497225980e-1, -.14501953125000000000,
+    .18786835250972344757e-1, .12625507130328301066,
+    -.14473795929590520582e-1, -.11179458309419422675,
+    .11494434254897626155e-1, .10030855351241635862,
+    -.93498556820544479096e-2, -.90964264465390582629e-1,
+    .77546391824364392762e-2, .83213457337452292745e-1,
+    -.65358085945588638605e-2, -.76680372422574234569e-1,
+    .55835321940047427169e-2, .71098828931825789428e-1,
+    -.48253327982967591019e-2, -.66274981937248958553e-1,
+    .42118078245337801387e-2, .62064306433355646267e-1,
+    -.37083386598903548973e-2, 0., 0., .25000000000000000000,
+    .73950997288745200531, .83852549156242113615, .23175620272173946716,
+    -.37791833195149451496, -.25710129174850522325, .21608307321780204633,
+    .22844049245646009157, -.14009503000335388415, -.19897685605518413847,
+    .98264706042471226893e-1, .17445445004279014046,
+    -.72761100054958328401e-1, -.15463589893742108388,
+    .56056770591708784481e-1, .13855313872640495158,
+    -.44517752443294564781e-1, -.12534277657695128850,
+    .36211835346039665762e-1, .11434398255136139683,
+    -.30033588409423828125e-1, -.10506705408753910481,
+    .25313077840725783008e-1, .97149327637744872155e-1,
+    -.21624927200393328444e-1, -.90319582367202122625e-1,
+    .18688433567711780666e-1, .84372291635345108584e-1,
+    -.16312261561845420752e-1, -.79149526894804751586e-1,
+    .14362333871852474757e-1, 0., 0., 0., .12500000000000000000,
+    .49607837082461073572, .82265291131801144317, .59621200088559103072,
+    -.80054302859059362371e-1, -.42612156697795759420,
+    -.90098145270865592887e-1, .29769623255090078484, .13630307904779758221,
+    -.21638835185708931831, -.14600247270306082052, .16348801804014290453,
+    .14340708728599057249, -.12755243353979286190, -.13661523715071346961,
+    .10215585947881057394, .12864248070157166547, -.83592528025348693602e-1,
+    -.12066728689302565222, .69633728678718053052e-1, .11314245177331919532,
+    -.58882939251410088028e-1, -.10621835858758221487,
+    .50432266865187597572e-1, .99916834723527771581e-1,
+    -.43672094283057258509e-1, -.94206380251950852413e-1,
+    .38181356812697746418e-1, .89035739656537771225e-1,
+    -.33661934598216332678e-1, 0., 0., 0., 0., .62500000000000000000e-1,
+    .31093357409581873586, .67604086414949799246, .75644205980613611039,
+    .28990586430124175741, -.30648508196770360914, -.35801372616842500052,
+    .91326869828709014708e-1, .31127929687500000000, .90915752838698393094e-2,
+    -.25637381283965534330, -.57601077850322797594e-1, .21019685709225757945,
+    .81244992138514014256e-1, -.17375078516720988858,
+    -.92289437277967051125e-1, .14527351914265391374,
+    .96675340792832019889e-1, -.12289485697108543415,
+    -.97448175340011084006e-1, .10511755943298339844,
+    .96242247086378239657e-1, -.90822942272780513537e-1,
+    -.93966350452322132384e-1, .79189411876493712558e-1,
+    .91139307067989309325e-1, -.69613039934383197265e-1,
+    -.88062491671135767870e-1, .61646331729340817494e-1, 0., 0., 0., 0., 0.,
+    .31250000000000000000e-1, .18684782411095934408, .50176689760410660236,
+    .74784031498626095398, .56472001151566251186, -.14842464993721351203e-1,
+    -.41162920273003120936, -.20243071230196532282, .23772054897172750436,
+    .24963810923972235950, -.12116179938394678936, -.24330535483519110663,
+    .47903849781124471359e-1, .22133299683101224293,
+    -.20542915138527200983e-2, -.19653465717678146728,
+    -.26818172626509178444e-1, .17319122357631210944,
+    .45065391411065545445e-1, -.15253391395444065941,
+    -.56543897711725408302e-1, .13469154928743585367,
+    .63632471400208840155e-1, -.11941684923913523817,
+    -.67828850207933293098e-1, .10636309084510652670,
+    .70095786922999181504e-1, -.95187373095150709082e-1, 0., 0., 0., 0., 0.,
+    0., .15625000000000000000e-1, .10909562534194485289,
+    .34842348626527747318, .64461114561628111443, .69382480527334683659,
+    .29551102358528827763, -.25527584713978439819, -.38878771718544715394,
+    -.82956185835347407489e-2, .31183177761966943912, .12831420840372374767,
+    -.22067618205599434368, -.17569196937129496961, .14598057000132284135,
+    .18864406621763419484, -.89921002550386645767e-1, -.18571835020187122114,
+    .48967672227195481777e-1, .17584685670380332798,
+    -.19267984545067426324e-1, -.16335437520503462738,
+    -.22598055455032407594e-2, .15032800884170631129,
+    .17883358353754640871e-1, -.13774837869432209951,
+    -.29227555960587143675e-1, .12604194747513151053, 0., 0., 0., 0., 0., 0.,
+    0., .78125000000000000000e-2, .62377810244809812496e-1,
+    .23080781467370883845, .50841310636012325368, .69834547012574056043,
+    .52572723156526459672, .11464215704954976471e-1, -.38698869011491210342,
+    -.26125646622255207507, .16951698812361607510, .29773875898928782269,
+    -.20130501202570367491e-1, -.26332493149159310198,
+    -.67734613690401207009e-1, .21207315477103762715, .11541543390889415193,
+    -.16249634759782417533, -.13885887405041735068, .11996491328010275427,
+    .14810432001630926895, -.85177658352556243411e-1, -.14918860659904380587,
+    .57317789510444151564e-1, .14569827645586660151,
+    -.35213090145965327390e-1, -.13975998126844578198, 0., 0., 0., 0., 0., 0.,
+    0., 0., .39062500000000000000e-2, .35101954600803571207e-1,
+    .14761284084133737720, .37655033076080192966, .62410290231517322776,
+    .64335622317683389875, .28188168266139524244, -.22488495672137010675,
+    -.39393811089283576186, -.75184777995770096714e-1, .28472023119398293003,
+    .20410910833705899572, -.15590046962908511750, -.23814567544617953125,
+    .54442805556829031204e-1, .22855930338589720954, .16303223615756629897e-1,
+    -.20172722433875559213, -.62723406421217419404e-1, .17012230831020922010,
+    .91754642766136561612e-1, -.13927644821381121197, -.10886600968068418181,
+    .11139075654373395292, .11797455976331702879, 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., .19531250000000000000e-2, .19506820659607596598e-1,
+    .91865676095362231937e-1, .26604607809696493849, .51425874205091288223,
+    .66047561132505329292, .48660109511591303851, .17575661168678285615e-1,
+    -.36594333408055703366, -.29088854695378694533, .11318677346656537927,
+    .31110645235730182168, .60733219161008787341e-1, -.24333848233620420826,
+    -.15254312332655419708, .15995968483455388613, .19010344455215289289,
+    -.86040636766440260000e-1, -.19652589954665259945,
+    .27633388517205837713e-1, .18660848552712880387, .15942583868416775867e-1,
+    -.16902042462382064786, -.47278526495327740646e-1, 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., .97656250000000000000e-3, .10731084460857378207e-1,
+    .55939644713816406331e-1, .18118487371914493668, .39914857299829864263,
+    .60812322949933902435, .60011887183061967583, .26002695805835928795,
+    -.20883922404786010096, -.38988130966114638081, -.11797833550782589082,
+    .25231824756239520077, .24817859972953934712, -.90516417677868996417e-1,
+    -.26079073291293066798, -.30259468817169480161e-1, .22178195264114178432,
+    .10569877864302048175, -.16679648389266977455, -.14637718550245050850,
+    .11219272032739559870, .16359363640525750353, -.64358194509092101393e-1,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .48828125000000000000e-3,
+    .58542865274813470967e-2, .33461741635290096452e-1, .11979993155896201271,
+    .29580223766987206958, .51874761979436016742, .62861483498014306968,
+    .44868895761051453296, .12567502628371529386e-1, -.35040366183235474275,
+    -.30466868455569500886, .70903913601490112666e-1, .30822791893032512740,
+    .11969443264190207736, -.20764760317621313946, -.20629838355452128532,
+    .95269702915334718507e-1, .22432624768705133300,
+    -.33103381593477797101e-2, -.20570036048155716333,
+    -.62208282720094518964e-1, .17095309330441436348, 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., .24414062500000000000e-3,
+    .31714797501871532475e-2, .19721062526127334100e-1,
+    .77311181185536498246e-1, .21124871792841566575, .41777980401893650886,
+    .59401977834943551650, .56132417807488349048, .23433675061367565951,
+    -.20222775295220942126, -.38280372496506190127, -.14443804214023095767,
+    .22268950939178466797, .27211314150777981984, -.34184876506180717313e-1,
+    -.26006498895669734842, -.97650425186005090107e-1, .19024527660129101293,
+    .16789164198044635671, -.10875811641651905252, -.19276785058805921298, 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .12207031250000000000e-3,
+    .17078941137247586143e-2, .11477733754843910060e-1,
+    .48887017020924625462e-1, .14634927241421789683, .32156282683019547854,
+    .52165811920227223937, .60001958466396926460, .41208501541480733755,
+    .11366945503190350975e-2, -.33968093962672089159, -.30955190935923386766,
+    .40657421856578262210e-1, .29873400409871531764, .16094481791768257440,
+    -.16876122436206497694, -.23650217045022161255, .33070260090574765012e-1,
+    .22985258456375907796, .68645651043827097771e-1, 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., .61035156250000000000e-4,
+    .91501857608428649078e-3, .66085179496951987952e-2,
+    .30383171695850355404e-1, .98840838845366876117e-1, .23855447246420318989,
+    .43322017468145613917, .58049033744876107191, .52533893203742699346,
+    .20681056202371946180, -.20180000924562504384, -.37503922291962681797,
+    -.15988102869837429062, .19823558102762374094, .28393023878803799622,
+    .11188133439357510403e-1, -.24730368377168229255, -.14731529061377942839,
+    .14878558042884266021, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., .30517578125000000000e-4, .48804277318479845551e-3,
+    .37696080990601968396e-2, .18603912108994738255e-1,
+    .65325006755649582964e-1, .17162960707938819795, .34411527956476971322,
+    .52289350347082497959, .57319653625674910592, .37662253421045430413,
+    -.14099055105384663902e-1, -.33265570610216904208, -.30921265572647566661,
+    .19911390594166455281e-1, .28738590811031797718, .18912130469738472647,
+    -.13235936203215819193, -.25076406142356675279, 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .15258789062500000000e-4,
+    .25928719280954633249e-3, .21327398937568540428e-2,
+    .11244626133630732010e-1, .42375605740664331966e-1, .12031130345907846211,
+    .26352562258934426830, .44590628258512682078, .56682835613700749379,
+    .49116715128261660395, .17845943097110339078, -.20541650677432497477,
+    -.36739803642257458221, -.16776034069210108273, .17920950989905112908,
+    .28867732805385066532, .46473465543376206337e-1, 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .76293945312500000000e-5,
+    .13727610943181290891e-3, .11979683091449349286e-2,
+    .67195313034570709806e-2, .27044920779931968175e-1,
+    .82472196498517457862e-1, .19570475044896150093, .36391620788543817693,
+    .52241392782736588032, .54727504974907879912, .34211551468813581183,
+    -.31580472732719957762e-1, -.32830006549176759667, -.30563797665254420769,
+    .64905014620683140120e-2, .27642986248995073032, 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .38146972656250000000e-5,
+    .72454147007837596854e-4, .66859847582761390285e-3,
+    .39751311980366118437e-2, .17015198650201528366e-1,
+    .55443621868993855715e-1, .14157060481641692131, .28641242619559616836,
+    .45610665490966615415, .55262786406029265394, .45818352706035500108,
+    .14984403004611673047, -.21163807462970713245, -.36007252928843413718,
+    -.17030961385712954159, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., .19073486328125000000e-5,
+    .38135049864067468562e-4, .37101393638555730015e-3,
+    .23305339886279723213e-2, .10569913448297127219e-1,
+    .36640175162216897547e-1, .10010476414320235508, .21860074212675559892,
+    .38124757096345313719, .52020999209879669177, .52172632730659212045,
+    .30841620620308814614, -.50322546186721500184e-1, -.32577618885114899053,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., .95367431640625000000e-6, .20021483206955925244e-4,
+    .20481807322420625431e-3, .13553476938058909882e-2,
+    .64919676350791905019e-2, .23848725425069251903e-1,
+    .69384632678886421292e-1, .16249711393618776934, .30736618106830314788,
+    .46399909601971539157, .53765031034002467225, .42598991476520183929,
+    .12130445348350215652, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., .47683715820312500000e-6,
+    .10487707828484902486e-4, .11254146162337528943e-3,
+    .78248929534271987118e-3, .39468337145306794566e-2,
+    .15313546659475671763e-1, .47249070825218564146e-1, .11804374107101480543,
+    .24031796927792491122, .39629215049166341285, .51629108968402548545,
+    .49622372075429782915, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., .23841857910156250000e-6,
+    .54823314130625337326e-5, .61575377321535518154e-4,
+    .44877834366497538134e-3, .23774612048621955857e-2,
+    .97136347645161687796e-2, .31671599547606636717e-1,
+    .84028665767000747480e-1, .18298487576742964949, .32647878537696945218,
+    .46970971486488895077, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., .11920928955078125000e-6,
+    .28604020001177375838e-5, .33559227978295551013e-4,
+    .25583821662860610560e-3, .14201552747787302339e-2,
+    .60938046986874414969e-2, .20930869247951926793e-1,
+    .58745021125678072911e-1, .13613725780285953720, .26083988356030237586,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., .59604644775390625000e-7,
+    .14898180663526043291e-5, .18224991282807693921e-4,
+    .14504433444608833821e-3, .84184722720281809548e-3,
+    .37846965430000478789e-2, .13656355548211376864e-1,
+    .40409541997718853934e-1, .99226988101858325902e-1, 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., .29802322387695312500e-7, .77471708843445529468e-6,
+    .98649879372606876995e-5, .81814934772838523887e-4,
+    .49554483992403011328e-3, .23290922072351413938e-2,
+    .88068134250844034186e-2, .27393666952485719070e-1, 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., .14901161193847656250e-7, .40226235946098233685e-6,
+    .53236418690561306700e-5, .45933829691164002269e-4,
+    .28982005232838857913e-3, .14212974043211018374e-2,
+    .56192363087488842264e-2, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    .74505805969238281250e-8, .20858299254133430408e-6,
+    .28648457300134381744e-5, .25677535898258910850e-4,
+    .16849420429491355445e-3, .86062824010315834002e-3, 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., .37252902984619140625e-8, .10801736017613096861e-6,
+    .15376606719887104015e-5, .14296523739727437959e-4,
+    .97419023656050887203e-4, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    .18626451492309570312e-8, .55871592916438890146e-7,
+    .82331193828137454068e-6, .79302250528382787666e-5, 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., .93132257461547851562e-9,
+    .28867244235852488244e-7, .43982811713864556957e-6, 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., .46566128730773925781e-9,
+    .14899342093408253335e-7, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
+    0., 0., .23283064365386962891e-9
+};
+
+/* Allocates a workspace for the given maximum number of intervals.
+    Note that if the workspace gets filled, the intervals with the
+    lowest error estimates are dropped. The maximum number of
+    intervals is therefore not the maximum number of intervals
+    that will be computed, but merely the size of the buffer.
+    */
+
+/* Compute the product of the fx with one of the inverse
+    Vandermonde-like matrices. */
+
+void
+Vinvfx (const double *fx, double *c, const int d)
+{
+
+  int i, j;
+
+  switch (d)
+    {
+    case 0:
+      for (i = 0; i <= 4; i++)
+        {
+          c[i] = 0.0;
+          for (j = 0; j <= 4; j++)
+            c[i] += V1inv[i * 5 + j] * fx[j * 8];
+        }
+      break;
+    case 1:
+      for (i = 0; i <= 8; i++)
+        {
+          c[i] = 0.0;
+          for (j = 0; j <= 8; j++)
+            c[i] += V2inv[i * 9 + j] * fx[j * 4];
+        }
+      break;
+    case 2:
+      for (i = 0; i <= 16; i++)
+        {
+          c[i] = 0.0;
+          for (j = 0; j <= 16; j++)
+            c[i] += V3inv[i * 17 + j] * fx[j * 2];
+        }
+      break;
+    case 3:
+      for (i = 0; i <= 32; i++)
+        {
+          c[i] = 0.0;
+          for (j = 0; j <= 32; j++)
+            c[i] += V4inv[i * 33 + j] * fx[j];
+        }
+      break;
+    }
+
+}
+
+
+/* Downdate the interpolation given by the n coefficients c
+    by removing the nodes with indices in nans. */
+
+void
+downdate (double *c, int n, int d, int *nans, int nnans)
+{
+
+  static const int bidx[4] = { 0, 6, 16, 34 };
+  double b_new[34], alpha;
+  int i, j;
+
+  for (i = 0; i <= n + 1; i++)
+    b_new[i] = bee[bidx[d] + i];
+  for (i = 0; i < nnans; i++)
+    {
+      b_new[n + 1] = b_new[n + 1] / Lalpha[n];
+      b_new[n] = (b_new[n] + xi[nans[i]] * b_new[n + 1]) / Lalpha[n - 1];
+      for (j = n - 1; j > 0; j--)
+        b_new[j] =
+          (b_new[j] + xi[nans[i]] * b_new[j + 1] -
+           Lgamma[j + 1] * b_new[j + 2]) / Lalpha[j - 1];
+      for (j = 0; j <= n; j++)
+        b_new[j] = b_new[j + 1];
+      alpha = c[n] / b_new[n];
+      for (j = 0; j < n; j++)
+        c[j] -= alpha * b_new[j];
+      c[n] = 0;
+      n--;
+    }
+
+}
+
+
+/* The actual integration routine.  */
+
+DEFUN (quadcc, args, nargout,
+"-*- texinfo -*-\n\
+@deftypefn  {Function File} {@var{q} =} quadcc (@var{f}, @var{a}, @var{b})\n\
+@deftypefnx {Function File} {@var{q} =} quadcc (@var{f}, @var{a}, @var{b}, @var{tol})\n\
+@deftypefnx {Function File} {@var{q} =} quadcc (@var{f}, @var{a}, @var{b}, @var{tol}, @var{sing})\n\
+@deftypefnx {Function File} {[@var{q}, @var{err}, @var{nr_points}] =} quadcc (@dots{})\n\
+Numerically evaluate the integral of @var{f} from @var{a} to @var{b}\n\
+using the doubly-adaptive Clenshaw-Curtis quadrature described by P. Gonnet\n\
+in @cite{Increasing the Reliability of Adaptive Quadrature Using Explicit\n\
+Interpolants}.\n\
+@var{f} is a function handle, inline function, or string\n\
+containing the name of the function to evaluate.\n\
+The function @var{f} must be vectorized and must return a vector of output\n\
+values if given a vector of input values.  For example,\n\
+\n\
+@example\n\
+f = @@(x) x .* sin (1./x) .* sqrt (abs (1 - x));\n\
+@end example\n\
+\n\
+@noindent\n\
+which uses the element-by-element `dot' form for all operators.\n\
+\n\
+@var{a} and @var{b} are the lower and upper limits of integration.  Either\n\
+or both limits may be infinite.  @code{quadcc} handles an inifinite limit\n\
+by substituting the variable of integration with @code{x = tan (pi/2*u)}.\n\
+\n\
+The optional argument @var{tol} defines the relative tolerance used to stop\n\
+the integration procedure.  The default value is @math{1e^{-6}}.\n\
+\n\
+The optional argument @var{sing} contains a list of points where the\n\
+integrand has known singularities, or discontinuities\n\
+in any of its derivatives, inside the integration interval.\n\
+For the example above, which has a discontinuity at x=1, the call to\n\
+@code{quadcc} would be as follows\n\
+\n\
+@example\n\
+int = quadcc (f, a, b, 1.0e-6, [ 1 ]);\n\
+@end example\n\
+\n\
+The result of the integration is returned in @var{q}.\n\
+@var{err} is an estimate of the absolute integration error and\n\
+@var{nr_points} is the number of points at which the integrand was evaluated.\n\
+If the adaptive integration did not converge, the value of\n\
+@var{err} will be larger than the requested tolerance.  Therefore, it is\n\
+recommended to verify this value for difficult integrands.\n\
+\n\
+@code{quadcc} is capable of dealing with non-numeric\n\
+values of the integrand such as @code{NaN} or @code{Inf}.\n\
+If the integral diverges, and @code{quadcc} detects this,\n\
+then a warning is issued and @code{Inf} or @code{-Inf} is returned.\n\
+\n\
+Note: @code{quadcc} is a general purpose quadrature algorithm\n\
+and, as such, may be less efficient for a smooth or otherwise\n\
+well-behaved integrand than other methods such as @code{quadgk}.\n\
+\n\
+The algorithm uses Clenshaw-Curtis quadrature rules of increasing\n\
+degree in each interval and bisects the interval if either the\n\
+function does not appear to be smooth or a rule of maximum\n\
+degree has been reached.  The error estimate is computed from the\n\
+L2-norm of the difference between two successive interpolations\n\
+of the integrand over the nodes of the respective quadrature rules.\n\
+\n\
+Reference: P. Gonnet, @cite{Increasing the Reliability of Adaptive\n\
+Quadrature Using Explicit Interpolants}, ACM Transactions on\n\
+Mathematical Software, Vol. 37, Issue 3, Article No. 3, 2010.\n\
+@seealso{quad, quadv, quadl, quadgk, trapz, dblquad, triplequad}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  /* Some constants that we will need. */
+  static const int n[4] = { 4, 8, 16, 32 };
+  static const int skip[4] = { 8, 4, 2, 1 };
+  static const int idx[4] = { 0, 5, 14, 31 };
+  static const double w = M_SQRT2 / 2;
+  static const int ndiv_max = 20;
+
+  /* The interval heap. */
+  cquad_ival ivals[cquad_heapsize];
+  int heap[cquad_heapsize];
+
+  /* Arguments left and right */
+  int nargin = args.length ();
+  octave_function *fcn;
+  double a, b, tol, iivals[cquad_heapsize], *sing;
+
+  /* Variables needed for transforming the integrand. */
+  bool wrap = false;
+  double xw;
+
+  /* Stuff we will need to call the integrand. */
+  octave_value_list fargs, fvals;
+
+  /* Actual variables (as opposed to constants above). */
+  double m, h, ml, hl, mr, hr, temp;
+  double igral, err, igral_final, err_final;
+  int nivals, neval = 0;
+  int i, j, d, split, t;
+  int nnans, nans[33];
+  cquad_ival *iv, *ivl, *ivr;
+  double nc, ncdiff;
+
+
+  /* Parse the input arguments. */
+  if (nargin < 3)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  if (args(0).is_function_handle () || args(0).is_inline_function ())
+    fcn = args(0).function_value ();
+  else
+    {
+       std::string fcn_name = unique_symbol_name ("__quadcc_fcn_");
+       std::string fname = "function y = ";
+       fname.append (fcn_name);
+       fname.append ("(x) y = ");
+       fcn = extract_function (args(0), "quadcc", fcn_name, fname,
+                               "; endfunction");
+    }
+
+  if (!args(1).is_real_scalar ())
+    {
+      error ("quadcc: lower limit of integration (A) must be a single real scalar");
+      return retval;
+    }
+  else
+    a = args(1).double_value ();
+
+  if (!args(2).is_real_scalar ())
+    {
+      error ("quadcc: upper limit of integration (B) must be a single real scalar");
+      return retval;
+    }
+  else
+    b = args(2).double_value ();
+
+  if (nargin < 4 || args(3).is_empty ())
+    tol = 1.0e-6;
+  else if (!args(3).is_real_scalar () || args(3).double_value () <= 0)
+    {
+      error ("quadcc: tolerance (TOL) must be a single real scalar > 0");
+      return retval;
+    }
+  else
+    tol = args(3).double_value ();
+
+  if (nargin < 5)
+    {
+      nivals = 1;
+      iivals[0] = a;
+      iivals[1] = b;
+    }
+  else if (!(args(4).is_real_scalar () || args(4).is_real_matrix ()))
+    {
+      error ("quadcc: list of singularities (SING) must be a vector of real values");
+      return retval;
+    }
+  else
+    {
+      nivals = 1 + args(4).length ();
+      if (nivals > cquad_heapsize)
+        {
+          error ("quadcc: maximum number of singular points is limited to %i",
+                 cquad_heapsize-1);
+          return retval;
+        }
+      sing = args(4).array_value ().fortran_vec ();
+      iivals[0] = a;
+      for (i = 0; i < nivals - 2; i++)
+        iivals[i + 1] = sing[i];
+      iivals[nivals] = b;
+    }
+
+  /* If a or b are +/-Inf, transform the integral. */
+  if (xisinf (a) || xisinf (b))
+    {
+      wrap = true;
+      for (i = 0; i <= nivals; i++)
+        if (xisinf (iivals[i]))
+          iivals[i] = gnulib::copysign (1.0, iivals[i]);
+        else
+          iivals[i] = 2.0 * atan (iivals[i]) / M_PI;
+    }
+
+
+  /* Initialize the heaps. */
+  for (i = 0; i < cquad_heapsize; i++)
+    heap[i] = i;
+
+
+  /* Create the first interval(s). */
+  igral = 0.0;
+  err = 0.0;
+  for (j = 0; j < nivals; j++)
+    {
+
+      /* Initialize the interval. */
+      iv = &(ivals[heap[j]]);
+      m = (iivals[j] + iivals[j + 1]) / 2;
+      h = (iivals[j + 1] - iivals[j]) / 2;
+      nnans = 0;
+      ColumnVector ex (33);
+      if (wrap)
+        {
+          for (i = 0; i <= n[3]; i++)
+            ex (i) = tan (M_PI / 2 * (m + xi[i] * h));
+        }
+      else
+        {
+          for (i = 0; i <= n[3]; i++)
+            ex (i) = m + xi[i] * h;
+        }
+      fargs(0) = ex;
+      fvals = feval (fcn, fargs, 1);
+      if (fvals.length () != 1 || !fvals(0).is_real_matrix ())
+        {
+          error ("quadcc: integrand F must return a single, real-valued vector");
+          return retval;
+        }
+      Matrix effex = fvals(0).matrix_value ();
+      if (effex.length () != ex.length ())
+        {
+          error ("quadcc: integrand F must return a single, real-valued vector of the same size as the input");
+          return retval;
+        }
+      for (i = 0; i <= n[3]; i++)
+        {
+          iv->fx[i] = effex (i);
+          if (wrap)
+            {
+              xw = ex(i);
+              iv->fx[i] *= (1.0 + xw * xw) * M_PI / 2;
+            }
+          neval++;
+          if (!xfinite (iv->fx[i]))
+            {
+              nans[nnans++] = i;
+              iv->fx[i] = 0.0;
+            }
+        }
+      Vinvfx (iv->fx, &(iv->c[idx[3]]), 3);
+      Vinvfx (iv->fx, &(iv->c[idx[2]]), 2);
+      Vinvfx (iv->fx, &(iv->c[0]), 0);
+      for (i = 0; i < nnans; i++)
+        iv->fx[i] = octave_NaN;
+      iv->a = iivals[j];
+      iv->b = iivals[j + 1];
+      iv->depth = 3;
+      iv->rdepth = 1;
+      iv->ndiv = 0;
+      iv->igral = 2 * h * iv->c[idx[3]] * w;
+      nc = 0.0;
+      for (i = n[2] + 1; i <= n[3]; i++)
+        {
+          temp = iv->c[idx[3] + i];
+          nc += temp * temp;
+        }
+      ncdiff = nc;
+      for (i = 0; i <= n[2]; i++)
+        {
+          temp = iv->c[idx[2] + i] - iv->c[idx[3] + i];
+          ncdiff += temp * temp;
+          nc += iv->c[idx[3] + i] * iv->c[idx[3] + i];
+        }
+      ncdiff = sqrt (ncdiff);
+      nc = sqrt (nc);
+      iv->err = ncdiff * 2 * h;
+      if (ncdiff / nc > 0.1 && iv->err < 2 * h * nc)
+        iv->err = 2 * h * nc;
+
+      /* Tabulate this interval's data. */
+      igral += iv->igral;
+      err += iv->err;
+
+      /* Sift it up the heap. */
+      i = j;
+      while (i > 0 && ivals[heap[i / 2]].err < ivals[heap[i]].err)
+        {
+          temp = heap[i];
+          heap[i] = heap[i / 2];
+          heap[i / 2] = temp;
+          i /= 2;
+        }
+
+    }
+
+
+  /* Initialize some global values. */
+  igral_final = 0.0;
+  err_final = 0.0;
+
+
+  /* Main loop. */
+  while (nivals > 0 && err > 0.0 && err > fabs (igral) * tol
+         && !(err_final > fabs (igral) * tol
+              && err - err_final < fabs (igral) * tol))
+    {
+
+      /* Allow the user to interrupt. */
+      OCTAVE_QUIT;
+
+      /* Put our finger on the interval with the largest error. */
+      iv = &(ivals[heap[0]]);
+      m = (iv->a + iv->b) / 2;
+      h = (iv->b - iv->a) / 2;
+
+/*      printf
+        ("quadcc: processing ival %i (of %i) with [%e,%e] int=%e, err=%e, depth=%i\n",
+         heap[0], nivals, iv->a, iv->b, iv->igral, iv->err, iv->depth);
+*/
+      /* Should we try to increase the degree? */
+      if (iv->depth < 3)
+        {
+
+          /* Keep tabs on some variables. */
+          d = ++iv->depth;
+
+          /* Get the new (missing) function values */
+          {
+            ColumnVector ex (n[d] / 2);
+            if (wrap)
+              {
+                for (i = 0; i < n[d] / 2; i++)
+                  ex (i) =
+                    tan (M_PI / 2 * (m + xi[(2 * i + 1) * skip[d]] * h));
+              }
+            else
+              {
+                for (i = 0; i < n[d] / 2; i++)
+                  ex (i) = m + xi[(2 * i + 1) * skip[d]] * h;
+              }
+            fargs(0) = ex;
+            fvals = feval (fcn, fargs, 1);
+            if (fvals.length () != 1 || !fvals(0).is_real_matrix ())
+              {
+                error ("quadcc: integrand F must return a single, real-valued vector");
+                return retval;
+              }
+            Matrix effex = fvals(0).matrix_value ();
+            if (effex.length () != ex.length ())
+              {
+                error ("quadcc: integrand F must return a single, real-valued vector of the same size as the input");
+                return retval;
+              }
+            neval += effex.length ();
+            for (i = 0; i < n[d] / 2; i++)
+              {
+                j = (2 * i + 1) * skip[d];
+                iv->fx[j] = effex (i);
+                if (wrap)
+                  {
+                    xw = ex(i);
+                    iv->fx[j] *= (1.0 + xw * xw) * M_PI / 2;
+                  }
+              }
+          }
+          nnans = 0;
+          for (i = 0; i <= 32; i += skip[d])
+            {
+              if (!xfinite (iv->fx[i]))
+                {
+                  nans[nnans++] = i;
+                  iv->fx[i] = 0.0;
+                }
+            }
+
+          /* Compute the new coefficients. */
+          Vinvfx (iv->fx, &(iv->c[idx[d]]), d);
+          /* Downdate any NaNs. */
+          if (nnans > 0)
+            {
+              downdate (&(iv->c[idx[d]]), n[d], d, nans, nnans);
+              for (i = 0; i < nnans; i++)
+                iv->fx[i] = octave_NaN;
+            }
+
+          /* Compute the error estimate. */
+          nc = 0.0;
+          for (i = n[d - 1] + 1; i <= n[d]; i++)
+            {
+              temp = iv->c[idx[d] + i];
+              nc += temp * temp;
+            }
+          ncdiff = nc;
+          for (i = 0; i <= n[d - 1]; i++)
+            {
+              temp = iv->c[idx[d - 1] + i] - iv->c[idx[d] + i];
+              ncdiff += temp * temp;
+              nc += iv->c[idx[d] + i] * iv->c[idx[d] + i];
+            }
+          ncdiff = sqrt (ncdiff);
+          nc = sqrt (nc);
+          iv->err = ncdiff * 2 * h;
+          /* Compute the local integral. */
+          iv->igral = 2 * h * w * iv->c[idx[d]];
+          /* Split the interval prematurely? */
+          split = (nc > 0 && ncdiff / nc > 0.1);
+        }
+
+      /* Maximum degree reached, just split. */
+      else
+        {
+          split = 1;
+        }
+
+
+      /* Should we drop this interval? */
+      if ((m + h * xi[0]) >= (m + h * xi[1])
+          || (m + h * xi[31]) >= (m + h * xi[32])
+          || iv->err < fabs (iv->igral) * DBL_EPSILON * 10)
+        {
+
+/*          printf
+            ("quadcc: dropping ival %i (of %i) with [%e,%e] int=%e, err=%e, depth=%i\n",
+             heap[0], nivals, iv->a, iv->b, iv->igral, iv->err,
+             iv->depth);
+*/
+          /* Keep this interval's contribution */
+          err_final += iv->err;
+          igral_final += iv->igral;
+          /* Swap with the last element on the heap */
+          t = heap[nivals - 1];
+          heap[nivals - 1] = heap[0];
+          heap[0] = t;
+          nivals--;
+          /* Fix up the heap */
+          i = 0;
+          while (2 * i + 1 < nivals)
+            {
+
+              /* Get the kids */
+              j = 2 * i + 1;
+              /* If the j+1st entry exists and is larger than the jth,
+                 use it instead. */
+              if (j + 1 < nivals
+                  && ivals[heap[j + 1]].err >= ivals[heap[j]].err)
+                j++;
+              /* Do we need to move the ith entry up? */
+              if (ivals[heap[j]].err <= ivals[heap[i]].err)
+                break;
+              else
+                {
+                  t = heap[j];
+                  heap[j] = heap[i];
+                  heap[i] = t;
+                  i = j;
+                }
+            }
+
+        }
+
+      /* Do we need to split this interval? */
+      else if (split)
+        {
+
+          /* Some values we will need often... */
+          d = iv->depth;
+          /* Generate the interval on the left */
+          ivl = &(ivals[heap[nivals++]]);
+          ivl->a = iv->a;
+          ivl->b = m;
+          ml = (ivl->a + ivl->b) / 2;
+          hl = h / 2;
+          ivl->depth = 0;
+          ivl->rdepth = iv->rdepth + 1;
+          ivl->fx[0] = iv->fx[0];
+          ivl->fx[32] = iv->fx[16];
+          {
+            ColumnVector ex (n[0] - 1);
+            if (wrap)
+              {
+                for (i = 0; i < n[0] - 1; i++)
+                  ex (i) = tan (M_PI / 2 * (ml + xi[(i + 1) * skip[0]] * hl));
+              }
+            else
+              {
+                for (i = 0; i < n[0] - 1; i++)
+                  ex (i) = ml + xi[(i + 1) * skip[0]] * hl;
+              }
+            fargs(0) = ex;
+            fvals = feval (fcn, fargs, 1);
+            if (fvals.length () != 1 || !fvals(0).is_real_matrix ())
+              {
+                error ("quadcc: integrand F must return a single, real-valued vector");
+                return retval;
+              }
+            Matrix effex = fvals(0).matrix_value ();
+            if (effex.length () != ex.length ())
+              {
+                error ("quadcc: integrand F must return a single, real-valued vector of the same size as the input");
+                return retval;
+              }
+            neval += effex.length ();
+            for (i = 0; i < n[0] - 1; i++)
+              {
+                j = (i + 1) * skip[0];
+                ivl->fx[j] = effex (i);
+                if (wrap)
+                  {
+                    xw = ex(i);
+                    ivl->fx[j] *= (1.0 + xw * xw) * M_PI / 2;
+                  }
+              }
+          }
+          nnans = 0;
+          for (i = 0; i <= 32; i += skip[0])
+            {
+              if (!xfinite (ivl->fx[i]))
+                {
+                  nans[nnans++] = i;
+                  ivl->fx[i] = 0.0;
+                }
+            }
+          Vinvfx (ivl->fx, ivl->c, 0);
+          if (nnans > 0)
+            {
+              downdate (ivl->c, n[0], 0, nans, nnans);
+              for (i = 0; i < nnans; i++)
+                ivl->fx[i] = octave_NaN;
+            }
+          for (i = 0; i <= n[d]; i++)
+            {
+              ivl->c[idx[d] + i] = 0.0;
+              for (j = i; j <= n[d]; j++)
+                ivl->c[idx[d] + i] += Tleft[i * 33 + j] * iv->c[idx[d] + j];
+            }
+          ncdiff = 0.0;
+          for (i = 0; i <= n[0]; i++)
+            {
+              temp = ivl->c[i] - ivl->c[idx[d] + i];
+              ncdiff += temp * temp;
+            }
+          for (i = n[0] + 1; i <= n[d]; i++)
+            {
+              temp = ivl->c[idx[d] + i];
+              ncdiff += temp * temp;
+            }
+          ncdiff = sqrt (ncdiff);
+          ivl->err = ncdiff * h;
+          /* Check for divergence. */
+          ivl->ndiv = iv->ndiv + (fabs (iv->c[0]) > 0
+                                  && ivl->c[0] / iv->c[0] > 2);
+          if (ivl->ndiv > ndiv_max && 2 * ivl->ndiv > ivl->rdepth)
+            {
+              igral = gnulib::copysign (octave_Inf, igral);
+              warning ("quadcc: divergent integral detected");
+              break;
+            }
+
+          /* Compute the local integral. */
+          ivl->igral = h * w * ivl->c[0];
+
+
+          /* Generate the interval on the right */
+          ivr = &(ivals[heap[nivals++]]);
+          ivr->a = m;
+          ivr->b = iv->b;
+          mr = (ivr->a + ivr->b) / 2;
+          hr = h / 2;
+          ivr->depth = 0;
+          ivr->rdepth = iv->rdepth + 1;
+          ivr->fx[0] = iv->fx[16];
+          ivr->fx[32] = iv->fx[32];
+          {
+            ColumnVector ex (n[0] - 1);
+            if (wrap)
+              {
+                for (i = 0; i < n[0] - 1; i++)
+                  ex (i) = tan (M_PI / 2 * (mr + xi[(i + 1) * skip[0]] * hr));
+              }
+            else
+              {
+                for (i = 0; i < n[0] - 1; i++)
+                  ex (i) = mr + xi[(i + 1) * skip[0]] * hr;
+              }
+            fargs(0) = ex;
+            fvals = feval (fcn, fargs, 1);
+            if (fvals.length () != 1 || !fvals(0).is_real_matrix ())
+              {
+                error ("quadcc: integrand F must return a single, real-valued vector");
+                return retval;
+              }
+            Matrix effex = fvals(0).matrix_value ();
+            if (effex.length () != ex.length ())
+              {
+                error ("quadcc: integrand F must return a single, real-valued vector of the same size as the input");
+                return retval;
+              }
+            neval += effex.length ();
+            for (i = 0; i < n[0] - 1; i++)
+              {
+                j = (i + 1) * skip[0];
+                ivr->fx[j] = effex (i);
+                if (wrap)
+                  {
+                    xw = ex(i);
+                    ivr->fx[j] *= (1.0 + xw * xw) * M_PI / 2;
+                  }
+              }
+          }
+          nnans = 0;
+          for (i = 0; i <= 32; i += skip[0])
+            {
+              if (!xfinite (ivr->fx[i]))
+                {
+                  nans[nnans++] = i;
+                  ivr->fx[i] = 0.0;
+                }
+            }
+          Vinvfx (ivr->fx, ivr->c, 0);
+          if (nnans > 0)
+            {
+              downdate (ivr->c, n[0], 0, nans, nnans);
+              for (i = 0; i < nnans; i++)
+                ivr->fx[i] = octave_NaN;
+            }
+          for (i = 0; i <= n[d]; i++)
+            {
+              ivr->c[idx[d] + i] = 0.0;
+              for (j = i; j <= n[d]; j++)
+                ivr->c[idx[d] + i] += Tright[i * 33 + j] * iv->c[idx[d] + j];
+            }
+          ncdiff = 0.0;
+          for (i = 0; i <= n[0]; i++)
+            {
+              temp = ivr->c[i] - ivr->c[idx[d] + i];
+              ncdiff += temp * temp;
+            }
+          for (i = n[0] + 1; i <= n[d]; i++)
+            {
+              temp = ivr->c[idx[d] + i];
+              ncdiff += temp * temp;
+            }
+          ncdiff = sqrt (ncdiff);
+          ivr->err = ncdiff * h;
+          /* Check for divergence. */
+          ivr->ndiv = iv->ndiv + (fabs (iv->c[0]) > 0
+                                  && ivr->c[0] / iv->c[0] > 2);
+          if (ivr->ndiv > ndiv_max && 2 * ivr->ndiv > ivr->rdepth)
+            {
+              igral = gnulib::copysign (octave_Inf, igral);
+              warning ("quadcc: divergent integral detected");
+              break;
+            }
+
+          /* Compute the local integral. */
+          ivr->igral = h * w * ivr->c[0];
+
+
+          /* Fix-up the heap: we now have one interval on top
+             that we don't need any more and two new, unsorted
+             ones at the bottom. */
+          /* Flip the last interval to the top of the heap and
+             sift down. */
+          t = heap[nivals - 1];
+          heap[nivals - 1] = heap[0];
+          heap[0] = t;
+          nivals--;
+          /* Sift this interval back down the heap. */
+          i = 0;
+          while (2 * i + 1 < nivals - 1)
+            {
+              j = 2 * i + 1;
+              if (j + 1 < nivals - 1
+                  && ivals[heap[j + 1]].err >= ivals[heap[j]].err)
+                j++;
+              if (ivals[heap[j]].err <= ivals[heap[i]].err)
+                break;
+              else
+                {
+                  t = heap[j];
+                  heap[j] = heap[i];
+                  heap[i] = t;
+                  i = j;
+                }
+            }
+
+          /* Now grab the last interval and sift it up the heap. */
+          i = nivals - 1;
+          while (i > 0)
+            {
+              j = (i - 1) / 2;
+              if (ivals[heap[j]].err < ivals[heap[i]].err)
+                {
+                  t = heap[j];
+                  heap[j] = heap[i];
+                  heap[i] = t;
+                  i = j;
+                }
+              else
+                break;
+            }
+
+
+        }
+
+      /* Otherwise, just fix-up the heap. */
+      else
+        {
+          i = 0;
+          while (2 * i + 1 < nivals)
+            {
+              j = 2 * i + 1;
+              if (j + 1 < nivals
+                  && ivals[heap[j + 1]].err >= ivals[heap[j]].err)
+                j++;
+              if (ivals[heap[j]].err <= ivals[heap[i]].err)
+                break;
+              else
+                {
+                  t = heap[j];
+                  heap[j] = heap[i];
+                  heap[i] = t;
+                  i = j;
+                }
+            }
+
+        }
+
+      /* If the heap is about to overflow, remove the last two
+         intervals. */
+      while (nivals > cquad_heapsize - 2)
+        {
+          iv = &(ivals[heap[nivals - 1]]);
+/*          printf
+            ("quadcc: dropping ival %i (of %i) with [%e,%e] int=%e, err=%e, depth=%i\n",
+             heap[0], nivals, iv->a, iv->b, iv->igral, iv->err,
+             iv->depth);
+*/
+          err_final += iv->err;
+          igral_final += iv->igral;
+          nivals--;
+        }
+
+      /* Collect the value of the integral and error. */
+      igral = igral_final;
+      err = err_final;
+      for (i = 0; i < nivals; i++)
+        {
+          igral += ivals[heap[i]].igral;
+          err += ivals[heap[i]].err;
+        }
+
+    }
+
+  /* Dump the contents of the heap. */
+/*  for (i = 0; i < nivals; i++)
+    {
+      iv = &(ivals[heap[i]]);
+      printf
+        ("quadcc: ival %i (%i) with [%e,%e], int=%e, err=%e, depth=%i, rdepth=%i, ndiv=%i\n",
+         i, heap[i], iv->a, iv->b, iv->igral, iv->err, iv->depth,
+         iv->rdepth, iv->ndiv);
+    }
+*/
+  /* Clean up and present the results. */
+  if (nargout > 2)
+    retval(2) = neval;
+  if (nargout > 1)
+    retval(1) = err;
+  retval(0) = igral;
+  /* All is well that ends well. */
+  return retval;
+}
+
+
+/*
+%!assert (quadcc (@sin, -pi, pi), 0, 1e-6)
+%!assert (quadcc (inline ("sin"),- pi, pi), 0, 1e-6)
+%!assert (quadcc ("sin", -pi, pi), 0, 1e-6)
+
+%!assert (quadcc (@sin, -pi, 0), -2, 1e-6)
+%!assert (quadcc (@sin, 0, pi), 2, 1e-6)
+%!assert (quadcc (@(x) 1./sqrt (x), 0, 1), 2, 1e-6)
+%!assert (quadcc (@(x) 1./(sqrt (x).*(x+1)), 0, Inf), pi, 1e-6)
+
+%!assert (quadcc (@(x) exp (-x .^ 2), -Inf, Inf), sqrt (pi), 1e-6)
+%!assert (quadcc (@(x) exp (-x .^ 2), -Inf, 0), sqrt (pi)/2, 1e-6)
+
+%% Test input validation
+%!error (quadcc ())
+%!error (quadcc (@sin))
+%!error (quadcc (@sin, 0))
+%!error (quadcc (@sin, ones (2), pi))
+%!error (quadcc (@sin, -i, pi))
+%!error (quadcc (@sin, 0, ones (2)))
+%!error (quadcc (@sin, 0, i))
+%!error (quadcc (@sin, 0, pi, 0))
+%!error (quadcc (@sin, 0, pi, 1e-6, [ i ]))
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/qz.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,1278 @@
+/*
+
+Copyright (C) 1998-2012 A. S. Hodel
+
+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/>.
+
+*/
+
+// Generalized eigenvalue balancing via LAPACK
+
+// Author: A. S. Hodel <scotte@eng.auburn.edu>
+
+#undef DEBUG
+#undef DEBUG_SORT
+#undef DEBUG_EIG
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cfloat>
+
+#include <iostream>
+#include <iomanip>
+
+#include "CmplxQRP.h"
+#include "CmplxQR.h"
+#include "dbleQR.h"
+#include "f77-fcn.h"
+#include "lo-math.h"
+#include "quit.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "oct-map.h"
+#include "ov.h"
+#include "pager.h"
+#if defined (DEBUG) || defined (DEBUG_SORT)
+#include "pr-output.h"
+#endif
+#include "symtab.h"
+#include "utils.h"
+#include "variables.h"
+
+typedef octave_idx_type (*sort_function) (const octave_idx_type& LSIZE, const double& ALPHA,
+                              const double& BETA, const double& S,
+                              const double& P);
+
+extern "C"
+{
+  F77_RET_T
+  F77_FUNC (dggbal, DGGBAL) (F77_CONST_CHAR_ARG_DECL,
+                             const octave_idx_type& N, double* A,
+                             const octave_idx_type& LDA, double* B,
+                             const octave_idx_type& LDB, octave_idx_type& ILO,
+                             octave_idx_type& IHI, double* LSCALE,
+                             double* RSCALE, double* WORK,
+                             octave_idx_type& INFO
+                             F77_CHAR_ARG_LEN_DECL);
+
+F77_RET_T
+  F77_FUNC (zggbal, ZGGBAL) (F77_CONST_CHAR_ARG_DECL,
+                             const octave_idx_type& N, Complex* A,
+                             const octave_idx_type& LDA, Complex* B,
+                             const octave_idx_type& LDB, octave_idx_type& ILO,
+                             octave_idx_type& IHI, double* LSCALE,
+                             double* RSCALE, double* WORK,
+                             octave_idx_type& INFO
+                             F77_CHAR_ARG_LEN_DECL);
+
+  F77_RET_T
+  F77_FUNC (dggbak, DGGBAK) (F77_CONST_CHAR_ARG_DECL,
+                             F77_CONST_CHAR_ARG_DECL,
+                             const octave_idx_type& N,
+                             const octave_idx_type& ILO,
+                             const octave_idx_type& IHI,
+                             const double* LSCALE, const double* RSCALE,
+                             octave_idx_type& M, double* V,
+                             const octave_idx_type& LDV, octave_idx_type& INFO
+                             F77_CHAR_ARG_LEN_DECL
+                             F77_CHAR_ARG_LEN_DECL);
+
+F77_RET_T
+  F77_FUNC (zggbak, ZGGBAK) (F77_CONST_CHAR_ARG_DECL,
+                             F77_CONST_CHAR_ARG_DECL,
+                             const octave_idx_type& N,
+                             const octave_idx_type& ILO,
+                             const octave_idx_type& IHI,
+                             const double* LSCALE, const double* RSCALE,
+                             octave_idx_type& M, Complex* V,
+                             const octave_idx_type& LDV, octave_idx_type& INFO
+                             F77_CHAR_ARG_LEN_DECL
+                             F77_CHAR_ARG_LEN_DECL);
+
+  F77_RET_T
+  F77_FUNC (dgghrd, DGGHRD) (F77_CONST_CHAR_ARG_DECL,
+                             F77_CONST_CHAR_ARG_DECL,
+                             const octave_idx_type& N,
+                             const octave_idx_type& ILO,
+                             const octave_idx_type& IHI, double* A,
+                             const octave_idx_type& LDA, double* B,
+                             const octave_idx_type& LDB, double* Q,
+                             const octave_idx_type& LDQ, double* Z,
+                             const octave_idx_type& LDZ, octave_idx_type& INFO
+                             F77_CHAR_ARG_LEN_DECL
+                             F77_CHAR_ARG_LEN_DECL);
+
+ F77_RET_T
+  F77_FUNC (zgghrd, ZGGHRD) (F77_CONST_CHAR_ARG_DECL,
+                             F77_CONST_CHAR_ARG_DECL,
+                             const octave_idx_type& N,
+                             const octave_idx_type& ILO,
+                             const octave_idx_type& IHI, Complex* A,
+                             const octave_idx_type& LDA, Complex* B,
+                             const octave_idx_type& LDB, Complex* Q,
+                             const octave_idx_type& LDQ, Complex* Z,
+                             const octave_idx_type& LDZ, octave_idx_type& INFO
+                             F77_CHAR_ARG_LEN_DECL
+                             F77_CHAR_ARG_LEN_DECL);
+
+  F77_RET_T
+  F77_FUNC (dhgeqz, DHGEQZ) (F77_CONST_CHAR_ARG_DECL,
+                             F77_CONST_CHAR_ARG_DECL,
+                             F77_CONST_CHAR_ARG_DECL,
+                             const octave_idx_type& N,
+                             const octave_idx_type& ILO,
+                             const octave_idx_type& IHI,
+                             double* A, const octave_idx_type& LDA, double* B,
+                             const octave_idx_type& LDB, double* ALPHAR,
+                             double* ALPHAI, double* BETA, double* Q,
+                             const octave_idx_type& LDQ, double* Z,
+                             const octave_idx_type& LDZ, double* WORK,
+                             const octave_idx_type& LWORK,
+                             octave_idx_type& INFO
+                             F77_CHAR_ARG_LEN_DECL
+                             F77_CHAR_ARG_LEN_DECL
+                             F77_CHAR_ARG_LEN_DECL);
+
+F77_RET_T
+  F77_FUNC (zhgeqz, ZHGEQZ) (F77_CONST_CHAR_ARG_DECL,
+                             F77_CONST_CHAR_ARG_DECL,
+                             F77_CONST_CHAR_ARG_DECL,
+                             const octave_idx_type& N,
+                             const octave_idx_type& ILO,
+                             const octave_idx_type& IHI,
+                             Complex* A, const octave_idx_type& LDA,
+                             Complex* B, const octave_idx_type& LDB,
+                             Complex* ALPHA, Complex* BETA, Complex* CQ,
+                             const octave_idx_type& LDQ,
+                             Complex* CZ, const octave_idx_type& LDZ,
+                             Complex* WORK, const octave_idx_type& LWORK,
+                             double* RWORK, octave_idx_type& INFO
+                             F77_CHAR_ARG_LEN_DECL
+                             F77_CHAR_ARG_LEN_DECL
+                             F77_CHAR_ARG_LEN_DECL);
+
+  F77_RET_T
+  F77_FUNC (dlag2, DLAG2) (const double* A, const octave_idx_type& LDA,
+                           const double* B, const octave_idx_type& LDB,
+                           const double& SAFMIN, double& SCALE1,
+                           double& SCALE2, double& WR1, double& WR2,
+                           double& WI);
+
+  // Van Dooren's code (netlib.org: toms/590) for reordering
+  // GEP.  Only processes Z, not Q.
+  F77_RET_T
+  F77_FUNC (dsubsp, DSUBSP) (const octave_idx_type& NMAX,
+                             const octave_idx_type& N, double* A,
+                             double* B, double* Z, sort_function,
+                             const double& EPS, octave_idx_type& NDIM,
+                             octave_idx_type& FAIL, octave_idx_type* IND);
+
+  // Documentation for DTGEVC incorrectly states that VR, VL are
+  // complex*16; they are declared in DTGEVC as double precision
+  // (probably a cut and paste problem fro ZTGEVC).
+  F77_RET_T
+  F77_FUNC (dtgevc, DTGEVC) (F77_CONST_CHAR_ARG_DECL,
+                             F77_CONST_CHAR_ARG_DECL,
+                             octave_idx_type* SELECT,
+                             const octave_idx_type& N, double* A,
+                             const octave_idx_type& LDA, double* B,
+                             const octave_idx_type& LDB, double* VL,
+                             const octave_idx_type& LDVL, double* VR,
+                             const octave_idx_type& LDVR,
+                             const octave_idx_type& MM, octave_idx_type& M,
+                             double* WORK, octave_idx_type& INFO
+                             F77_CHAR_ARG_LEN_DECL
+                             F77_CHAR_ARG_LEN_DECL);
+
+F77_RET_T
+  F77_FUNC (ztgevc, ZTGEVC) (F77_CONST_CHAR_ARG_DECL,
+                             F77_CONST_CHAR_ARG_DECL,
+                             octave_idx_type* SELECT,
+                             const octave_idx_type& N, const Complex* A,
+                             const octave_idx_type& LDA,const Complex* B,
+                             const octave_idx_type& LDB, Complex* xVL,
+                             const octave_idx_type& LDVL, Complex* xVR,
+                             const octave_idx_type& LDVR,
+                             const octave_idx_type& MM, octave_idx_type& M,
+                             Complex* CWORK, double* RWORK,
+                             octave_idx_type& INFO
+                             F77_CHAR_ARG_LEN_DECL
+                             F77_CHAR_ARG_LEN_DECL);
+
+  F77_RET_T
+  F77_FUNC (xdlamch, XDLAMCH) (F77_CONST_CHAR_ARG_DECL,
+                               double& retval
+                               F77_CHAR_ARG_LEN_DECL);
+
+  F77_RET_T
+  F77_FUNC (xdlange, XDLANGE) (F77_CONST_CHAR_ARG_DECL,
+                               const octave_idx_type&,
+                               const octave_idx_type&, const double*,
+                               const octave_idx_type&, double*, double&
+                               F77_CHAR_ARG_LEN_DECL);
+}
+
+// fcrhp, fin, fout, folhp:
+// routines for ordering of generalized eigenvalues
+// return 1 if  test is passed, 0 otherwise
+//    fin: |lambda| < 1
+//    fout: |lambda| >= 1
+//    fcrhp: real(lambda) >= 0
+//    folhp: real(lambda) < 0
+
+static octave_idx_type
+fcrhp (const octave_idx_type& lsize, const double& alpha,
+       const double& beta, const double& s, const double&)
+{
+  if (lsize == 1)
+    return (alpha * beta >= 0 ? 1 : -1);
+  else
+    return (s >= 0 ? 1 : -1);
+}
+
+static octave_idx_type
+fin (const octave_idx_type& lsize, const double& alpha,
+     const double& beta, const double&, const double& p)
+{
+  octave_idx_type retval;
+
+  if (lsize == 1)
+    retval = (fabs (alpha) < fabs (beta) ? 1 : -1);
+  else
+    retval = (fabs (p) < 1 ? 1 : -1);
+
+#ifdef DEBUG
+  std::cout << "qz: fin: retval=" << retval << std::endl;
+#endif
+
+  return retval;
+}
+
+static octave_idx_type
+folhp (const octave_idx_type& lsize, const double& alpha,
+       const double& beta, const double& s, const double&)
+{
+  if (lsize == 1)
+    return (alpha * beta < 0 ? 1 : -1);
+  else
+    return (s < 0 ? 1 : -1);
+}
+
+static octave_idx_type
+fout (const octave_idx_type& lsize, const double& alpha,
+      const double& beta, const double&, const double& p)
+{
+  if (lsize == 1)
+    return (fabs (alpha) >= fabs (beta) ? 1 : -1);
+  else
+    return (fabs (p) >= 1 ? 1 : -1);
+}
+
+
+//FIXME: Matlab does not produce lambda as the first output argument.
+//       Compatibility problem?
+DEFUN (qz, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{lambda} =} qz (@var{A}, @var{B})\n\
+@deftypefnx {Built-in Function} {@var{lambda} =} qz (@var{A}, @var{B}, @var{opt})\n\
+QZ@tie{}decomposition of the generalized eigenvalue problem\n\
+(@math{A x = s B x}).  There are three ways to call this function:\n\
+@enumerate\n\
+@item @code{@var{lambda} = qz (@var{A}, @var{B})}\n\
+\n\
+Computes the generalized eigenvalues\n\
+@tex\n\
+$\\lambda$\n\
+@end tex\n\
+@ifnottex\n\
+@var{lambda}\n\
+@end ifnottex\n\
+of @math{(A - s B)}.\n\
+\n\
+@item @code{[AA, BB, Q, Z, V, W, @var{lambda}] = qz (@var{A}, @var{B})}\n\
+\n\
+Computes QZ@tie{}decomposition, generalized eigenvectors, and\n\
+generalized eigenvalues of @math{(A - s B)}\n\
+@tex\n\
+$$ AV = BV{ \\rm diag }(\\lambda) $$\n\
+$$ W^T A = { \\rm diag }(\\lambda)W^T B $$\n\
+$$ AA = Q^T AZ, BB = Q^T BZ $$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+@group\n\
+\n\
+A * V = B * V * diag (@var{lambda})\n\
+W' * A = diag (@var{lambda}) * W' * B\n\
+AA = Q * A * Z, BB = Q * B * Z\n\
+\n\
+@end group\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+with @var{Q} and @var{Z} orthogonal (unitary)= @var{I}\n\
+\n\
+@item @code{[AA,BB,Z@{, @var{lambda}@}] = qz (@var{A}, @var{B}, @var{opt})}\n\
+\n\
+As in form [2], but allows ordering of generalized eigenpairs\n\
+for (e.g.) solution of discrete time algebraic Riccati equations.\n\
+Form 3 is not available for complex matrices, and does not compute\n\
+the generalized eigenvectors @var{V}, @var{W}, nor the orthogonal matrix\n\
+@var{Q}.\n\
+\n\
+@table @var\n\
+@item opt\n\
+for ordering eigenvalues of the GEP pencil.  The leading block\n\
+of the revised pencil contains all eigenvalues that satisfy:\n\
+\n\
+@table @asis\n\
+@item \"N\"\n\
+= unordered (default)\n\
+\n\
+@item \"S\"\n\
+= small: leading block has all |lambda| @leq{} 1\n\
+\n\
+@item \"B\"\n\
+= big: leading block has all |lambda| @geq{} 1\n\
+\n\
+@item \"-\"\n\
+= negative real part: leading block has all eigenvalues\n\
+in the open left half-plane\n\
+\n\
+@item \"+\"\n\
+= non-negative real part: leading block has all eigenvalues\n\
+in the closed right half-plane\n\
+@end table\n\
+@end table\n\
+@end enumerate\n\
+\n\
+Note: @code{qz} performs permutation balancing, but not scaling\n\
+(@pxref{doc-balance}).  The order of output arguments was selected for\n\
+compatibility with @sc{matlab}.\n\
+@seealso{balance, eig, schur}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+  int nargin = args.length ();
+
+#ifdef DEBUG
+  std::cout << "qz: nargin = " << nargin << ", nargout = " << nargout << std::endl;
+#endif
+
+  if (nargin < 2 || nargin > 3 || nargout > 7)
+    {
+      print_usage ();
+      return retval;
+    }
+  else if (nargin == 3 && (nargout < 3 || nargout > 4))
+    {
+      error ("qz: invalid number of output arguments for form [3] call");
+      return retval;
+    }
+
+#ifdef DEBUG
+  std::cout << "qz: determine ordering option" << std::endl;
+#endif
+
+  // Determine ordering option.
+  volatile char ord_job = 0;
+  static double safmin;
+
+  if (nargin == 2)
+    ord_job = 'N';
+  else if (!args(2).is_string ())
+    {
+      error ("qz: OPT must be a string");
+      return retval;
+    }
+  else
+    {
+      std::string tmp = args(2).string_value ();
+
+      if (! tmp.empty ())
+        ord_job = tmp[0];
+
+      if (! (ord_job == 'N' || ord_job == 'n'
+             || ord_job == 'S' || ord_job == 's'
+             || ord_job == 'B' || ord_job == 'b'
+             || ord_job == '+' || ord_job == '-'))
+        {
+          error ("qz: invalid order option");
+          return retval;
+        }
+
+      // overflow constant required by dlag2
+      F77_FUNC (xdlamch, XDLAMCH) (F77_CONST_CHAR_ARG2 ("S", 1),
+                                   safmin
+                                   F77_CHAR_ARG_LEN (1));
+
+#ifdef DEBUG_EIG
+      std::cout << "qz: initial value of safmin=" << setiosflags (std::ios::scientific)
+           << safmin << std::endl;
+#endif
+
+      // Some machines (e.g., DEC alpha) get safmin = 0;
+      // for these, use eps instead to avoid problems in dlag2.
+      if (safmin == 0)
+        {
+#ifdef DEBUG_EIG
+          std::cout << "qz: DANGER WILL ROBINSON: safmin is 0!" << std::endl;
+#endif
+
+          F77_FUNC (xdlamch, XDLAMCH) (F77_CONST_CHAR_ARG2 ("E", 1),
+                                       safmin
+                                       F77_CHAR_ARG_LEN (1));
+
+#ifdef DEBUG_EIG
+          std::cout << "qz: safmin set to " << setiosflags (std::ios::scientific)
+               << safmin << std::endl;
+#endif
+        }
+    }
+
+#ifdef DEBUG
+  std::cout << "qz: check argument 1" << std::endl;
+#endif
+
+  // Argument 1: check if it's o.k. dimensioned.
+  octave_idx_type nn = args(0).rows ();
+
+#ifdef DEBUG
+  std::cout << "argument 1 dimensions: (" << nn << "," << args(0).columns () << ")"
+       << std::endl;
+#endif
+
+  int arg_is_empty = empty_arg ("qz", nn, args(0).columns ());
+
+  if (arg_is_empty < 0)
+    {
+      gripe_empty_arg ("qz: parameter 1", 0);
+      return retval;
+    }
+  else if (arg_is_empty > 0)
+    {
+      gripe_empty_arg ("qz: parameter 1; continuing", 0);
+      return octave_value_list (2, Matrix ());
+    }
+  else if (args(0).columns () != nn)
+    {
+      gripe_square_matrix_required ("qz");
+      return retval;
+    }
+
+  // Argument 1: dimensions look good; get the value.
+  Matrix aa;
+  ComplexMatrix caa;
+
+  if (args(0).is_complex_type ())
+    caa = args(0).complex_matrix_value ();
+  else
+    aa = args(0).matrix_value ();
+
+  if (error_state)
+    return retval;
+
+#ifdef DEBUG
+  std::cout << "qz: check argument 2" << std::endl;
+#endif
+
+  // Extract argument 2 (bb, or cbb if complex).
+  if ((nn != args(1).columns ()) || (nn != args(1).rows ()))
+    {
+      gripe_nonconformant ();
+      return retval;
+    }
+
+  Matrix bb;
+  ComplexMatrix cbb;
+
+  if (args(1).is_complex_type ())
+    cbb = args(1).complex_matrix_value ();
+  else
+    bb = args(1).matrix_value ();
+
+  if (error_state)
+    return retval;
+
+  // Both matrices loaded, now let's check what kind of arithmetic:
+  // declared volatile to avoid compiler warnings about long jumps,
+  // vforks.
+
+  volatile int complex_case
+    = (args(0).is_complex_type () || args(1).is_complex_type ());
+
+  if (nargin == 3 && complex_case)
+    {
+      error ("qz: cannot re-order complex qz decomposition");
+      return retval;
+    }
+
+  // First, declare variables used in both the real and complex case.
+  Matrix QQ(nn,nn), ZZ(nn,nn), VR(nn,nn), VL(nn,nn);
+  RowVector alphar(nn), alphai(nn), betar(nn);
+  ComplexRowVector xalpha(nn), xbeta(nn);
+  ComplexMatrix CQ(nn,nn), CZ(nn,nn), CVR(nn,nn), CVL(nn,nn);
+  octave_idx_type ilo, ihi, info;
+  char compq = (nargout >= 3 ? 'V' : 'N');
+  char compz = ((nargout >= 4 || nargin == 3)? 'V' : 'N');
+
+  // Initialize Q, Z to identity if we need either of them.
+  if (compq == 'V' || compz == 'V')
+    for (octave_idx_type ii = 0; ii < nn; ii++)
+      for (octave_idx_type jj = 0; jj < nn; jj++)
+        {
+          OCTAVE_QUIT;
+          QQ(ii,jj) = ZZ(ii,jj) = (ii == jj ? 1.0 : 0.0);
+        }
+
+  // Always perform permutation balancing.
+  const char bal_job = 'P';
+  RowVector lscale (nn), rscale (nn), work (6 * nn), rwork (nn);
+
+  if (complex_case)
+    {
+#ifdef DEBUG
+      if (compq == 'V')
+        std::cout << "qz: performing balancing; CQ=" << std::endl << CQ << std::endl;
+#endif
+      if (args(0).is_real_type ())
+        caa = ComplexMatrix (aa);
+
+      if (args(1).is_real_type ())
+        cbb = ComplexMatrix (bb);
+
+      if (compq == 'V')
+        CQ = ComplexMatrix (QQ);
+
+      if (compz == 'V')
+        CZ = ComplexMatrix (ZZ);
+
+      F77_XFCN (zggbal, ZGGBAL,
+                (F77_CONST_CHAR_ARG2 (&bal_job, 1),
+                 nn, caa.fortran_vec (), nn, cbb.fortran_vec (),
+                 nn, ilo, ihi, lscale.fortran_vec (),
+                 rscale.fortran_vec (), work.fortran_vec (), info
+                 F77_CHAR_ARG_LEN (1)));
+    }
+  else
+    {
+#ifdef DEBUG
+      if (compq == 'V')
+        std::cout << "qz: performing balancing; QQ=" << std::endl << QQ << std::endl;
+#endif
+
+      F77_XFCN (dggbal, DGGBAL,
+                (F77_CONST_CHAR_ARG2 (&bal_job, 1),
+                 nn, aa.fortran_vec (), nn, bb.fortran_vec (),
+                 nn, ilo, ihi, lscale.fortran_vec (),
+                 rscale.fortran_vec (), work.fortran_vec (), info
+                 F77_CHAR_ARG_LEN (1)));
+    }
+
+  // Since we just want the balancing matrices, we can use dggbal
+  // for both the real and complex cases; left first
+
+#if 0
+  if (compq == 'V')
+    {
+      F77_XFCN (dggbak, DGGBAK,
+                (F77_CONST_CHAR_ARG2 (&bal_job, 1),
+                 F77_CONST_CHAR_ARG2 ("L", 1),
+                 nn, ilo, ihi, lscale.data (), rscale.data (),
+                 nn, QQ.fortran_vec (), nn, info
+                 F77_CHAR_ARG_LEN (1)
+                 F77_CHAR_ARG_LEN (1)));
+
+#ifdef DEBUG
+      if (compq == 'V')
+        std::cout << "qz: balancing done; QQ=" << std::endl << QQ << std::endl;
+#endif
+  }
+
+  // then right
+  if (compz == 'V')
+    {
+      F77_XFCN (dggbak, DGGBAK,
+                (F77_CONST_CHAR_ARG2 (&bal_job, 1),
+                 F77_CONST_CHAR_ARG2 ("R", 1),
+                 nn, ilo, ihi, lscale.data (), rscale.data (),
+                 nn, ZZ.fortran_vec (), nn, info
+                 F77_CHAR_ARG_LEN (1)
+                 F77_CHAR_ARG_LEN (1)));
+
+#ifdef DEBUG
+      if (compz == 'V')
+        std::cout << "qz: balancing done; ZZ=" << std::endl << ZZ << std::endl;
+#endif
+    }
+#endif
+
+  static char qz_job;
+  qz_job = (nargout < 2 ? 'E' : 'S');
+
+  if (complex_case)
+    {
+      // Complex case.
+
+      // The QR decomposition of cbb.
+      ComplexQR cbqr (cbb);
+      // The R matrix of QR decomposition for cbb.
+      cbb = cbqr.R ();
+      // (Q*)caa for following work.
+      caa = (cbqr.Q ().hermitian ()) * caa;
+      CQ = CQ * cbqr.Q ();
+
+      F77_XFCN (zgghrd, ZGGHRD,
+                (F77_CONST_CHAR_ARG2 (&compq, 1),
+                 F77_CONST_CHAR_ARG2 (&compz, 1),
+                 nn, ilo, ihi, caa.fortran_vec (),
+                 nn, cbb.fortran_vec (), nn, CQ.fortran_vec (), nn,
+                 CZ.fortran_vec (), nn, info
+                 F77_CHAR_ARG_LEN (1)
+                 F77_CHAR_ARG_LEN (1)));
+
+      ComplexRowVector cwork (1 * nn);
+
+      F77_XFCN (zhgeqz, ZHGEQZ,
+                (F77_CONST_CHAR_ARG2 (&qz_job, 1),
+                 F77_CONST_CHAR_ARG2 (&compq, 1),
+                 F77_CONST_CHAR_ARG2 (&compz, 1),
+                 nn, ilo, ihi,
+                 caa.fortran_vec (), nn,
+                 cbb.fortran_vec (),nn,
+                 xalpha.fortran_vec (), xbeta.fortran_vec (),
+                 CQ.fortran_vec (), nn,
+                 CZ.fortran_vec (), nn,
+                 cwork.fortran_vec (), nn, rwork.fortran_vec (), info
+                 F77_CHAR_ARG_LEN (1)
+                 F77_CHAR_ARG_LEN (1)
+                 F77_CHAR_ARG_LEN (1)));
+
+      if (compq == 'V')
+        {
+          // Left eigenvector.
+          F77_XFCN (zggbak, ZGGBAK,
+                    (F77_CONST_CHAR_ARG2 (&bal_job, 1),
+                     F77_CONST_CHAR_ARG2 ("L", 1),
+                     nn, ilo, ihi, lscale.data (), rscale.data (),
+                     nn, CQ.fortran_vec (), nn, info
+                     F77_CHAR_ARG_LEN (1)
+                     F77_CHAR_ARG_LEN (1)));
+        }
+
+      // Right eigenvector.
+      if (compz == 'V')
+        {
+          F77_XFCN (zggbak, ZGGBAK,
+                    (F77_CONST_CHAR_ARG2 (&bal_job, 1),
+                     F77_CONST_CHAR_ARG2 ("R", 1),
+                     nn, ilo, ihi, lscale.data (), rscale.data (),
+                     nn, CZ.fortran_vec (), nn, info
+                     F77_CHAR_ARG_LEN (1)
+                     F77_CHAR_ARG_LEN (1)));
+        }
+
+    }
+  else
+    {
+#ifdef DEBUG
+      std::cout << "qz: peforming qr decomposition of bb" << std::endl;
+#endif
+
+      // Compute the QR factorization of bb.
+      QR bqr (bb);
+
+#ifdef DEBUG
+      std::cout << "qz: qr (bb) done; now peforming qz decomposition" << std::endl;
+#endif
+
+      bb = bqr.R ();
+
+#ifdef DEBUG
+      std::cout << "qz: extracted bb" << std::endl;
+#endif
+
+      aa = (bqr.Q ()).transpose () * aa;
+
+#ifdef DEBUG
+      std::cout << "qz: updated aa " << std::endl;
+      std::cout << "bqr.Q () = " << std::endl << bqr.Q () << std::endl;
+
+      if (compq == 'V')
+        std::cout << "QQ =" << QQ << std::endl;
+#endif
+
+      if (compq == 'V')
+        QQ = QQ * bqr.Q ();
+
+#ifdef DEBUG
+      std::cout << "qz: precursors done..." << std::endl;
+#endif
+
+#ifdef DEBUG
+      std::cout << "qz: compq = " << compq << ", compz = " << compz << std::endl;
+#endif
+
+      // Reduce  to generalized hessenberg form.
+      F77_XFCN (dgghrd, DGGHRD,
+                (F77_CONST_CHAR_ARG2 (&compq, 1),
+                 F77_CONST_CHAR_ARG2 (&compz, 1),
+                 nn, ilo, ihi, aa.fortran_vec (),
+                 nn, bb.fortran_vec (), nn, QQ.fortran_vec (), nn,
+                 ZZ.fortran_vec (), nn, info
+                 F77_CHAR_ARG_LEN (1)
+                 F77_CHAR_ARG_LEN (1)));
+
+      // Check if just computing generalized eigenvalues or if we're
+      // actually computing the decomposition.
+
+      // Reduce to generalized Schur form.
+      F77_XFCN (dhgeqz, DHGEQZ,
+                (F77_CONST_CHAR_ARG2 (&qz_job, 1),
+                 F77_CONST_CHAR_ARG2 (&compq, 1),
+                 F77_CONST_CHAR_ARG2 (&compz, 1),
+                 nn, ilo, ihi, aa.fortran_vec (), nn, bb.fortran_vec (),
+                 nn, alphar.fortran_vec (), alphai.fortran_vec (),
+                 betar.fortran_vec (), QQ.fortran_vec (), nn,
+                 ZZ.fortran_vec (), nn, work.fortran_vec (), nn, info
+                 F77_CHAR_ARG_LEN (1)
+                 F77_CHAR_ARG_LEN (1)
+                 F77_CHAR_ARG_LEN (1)));
+
+      if (compq == 'V')
+        {
+          F77_XFCN (dggbak, DGGBAK,
+                    (F77_CONST_CHAR_ARG2 (&bal_job, 1),
+                     F77_CONST_CHAR_ARG2 ("L", 1),
+                     nn, ilo, ihi, lscale.data (), rscale.data (),
+                     nn, QQ.fortran_vec (), nn, info
+                     F77_CHAR_ARG_LEN (1)
+                     F77_CHAR_ARG_LEN (1)));
+
+#ifdef DEBUG
+          if (compq == 'V')
+            std::cout << "qz: balancing done; QQ=" << std::endl << QQ << std::endl;
+#endif
+        }
+
+  // then right
+      if (compz == 'V')
+        {
+           F77_XFCN (dggbak, DGGBAK,
+                     (F77_CONST_CHAR_ARG2 (&bal_job, 1),
+                      F77_CONST_CHAR_ARG2 ("R", 1),
+                      nn, ilo, ihi, lscale.data (), rscale.data (),
+                      nn, ZZ.fortran_vec (), nn, info
+                      F77_CHAR_ARG_LEN (1)
+                      F77_CHAR_ARG_LEN (1)));
+
+#ifdef DEBUG
+           if (compz == 'V')
+             std::cout << "qz: balancing done; ZZ=" << std::endl << ZZ << std::endl;
+#endif
+        }
+
+    }
+
+  // Order the QZ decomposition?
+  if (! (ord_job == 'N' || ord_job == 'n'))
+    {
+      if (complex_case)
+        {
+          // Probably not needed, but better be safe.
+          error ("qz: cannot re-order complex qz decomposition");
+          return retval;
+        }
+      else
+        {
+#ifdef DEBUG_SORT
+          std::cout << "qz: ordering eigenvalues: ord_job = "
+                    << ord_job << std::endl;
+#endif
+
+          // Declared static to avoid vfork/long jump compiler complaints.
+          static sort_function sort_test;
+          sort_test = 0;
+
+          switch (ord_job)
+            {
+            case 'S':
+            case 's':
+              sort_test = &fin;
+              break;
+
+            case 'B':
+            case 'b':
+              sort_test = &fout;
+              break;
+
+            case '+':
+              sort_test = &fcrhp;
+              break;
+
+            case '-':
+              sort_test = &folhp;
+              break;
+
+            default:
+              // Invalid order option (should never happen, since we
+              // checked the options at the top).
+              panic_impossible ();
+              break;
+            }
+
+          octave_idx_type ndim, fail;
+          double inf_norm;
+
+          F77_XFCN (xdlange, XDLANGE,
+                    (F77_CONST_CHAR_ARG2 ("I", 1),
+                     nn, nn, aa.data (), nn, work.fortran_vec (), inf_norm
+                     F77_CHAR_ARG_LEN (1)));
+
+          double eps = DBL_EPSILON * inf_norm * nn;
+
+#ifdef DEBUG_SORT
+          std::cout << "qz: calling dsubsp: aa=" << std::endl;
+          octave_print_internal (std::cout, aa, 0);
+          std::cout << std::endl << "bb="  << std::endl;
+          octave_print_internal (std::cout, bb, 0);
+          if (compz == 'V')
+            {
+              std::cout << std::endl << "ZZ="  << std::endl;
+              octave_print_internal (std::cout, ZZ, 0);
+            }
+          std::cout << std::endl;
+          std::cout << "alphar = " << std::endl;
+          octave_print_internal (std::cout, (Matrix) alphar, 0);
+          std::cout << std::endl << "alphai = " << std::endl;
+          octave_print_internal (std::cout, (Matrix) alphai, 0);
+          std::cout << std::endl << "beta = " << std::endl;
+          octave_print_internal (std::cout, (Matrix) betar, 0);
+          std::cout << std::endl;
+#endif
+
+          Array<octave_idx_type> ind (dim_vector (nn, 1));
+
+          F77_XFCN (dsubsp, DSUBSP,
+                    (nn, nn, aa.fortran_vec (), bb.fortran_vec (),
+                     ZZ.fortran_vec (), sort_test, eps, ndim, fail,
+                     ind.fortran_vec ()));
+
+#ifdef DEBUG
+          std::cout << "qz: back from dsubsp: aa=" << std::endl;
+          octave_print_internal (std::cout, aa, 0);
+          std::cout << std::endl << "bb="  << std::endl;
+          octave_print_internal (std::cout, bb, 0);
+          if (compz == 'V')
+            {
+              std::cout << std::endl << "ZZ="  << std::endl;
+              octave_print_internal (std::cout, ZZ, 0);
+            }
+          std::cout << std::endl;
+#endif
+
+          // Manually update alphar, alphai, betar.
+          static int jj;
+
+          jj = 0;
+          while (jj < nn)
+            {
+#ifdef DEBUG_EIG
+              std::cout << "computing gen eig #" << jj << std::endl;
+#endif
+
+              // Number of zeros in this block.
+              static int zcnt;
+
+              if (jj == (nn-1))
+                zcnt = 1;
+              else if (aa(jj+1,jj) == 0)
+                zcnt = 1;
+              else zcnt = 2;
+
+              if (zcnt == 1)
+                {
+                  // Real zero.
+#ifdef DEBUG_EIG
+                  std::cout << "  single gen eig:" << std::endl;
+                  std::cout << "  alphar(" << jj << ") = " << aa(jj,jj) << std::endl;
+                  std::cout << "  betar( " << jj << ") = " << bb(jj,jj) << std::endl;
+                  std::cout << "  alphai(" << jj << ") = 0" << std::endl;
+#endif
+
+                  alphar(jj) = aa(jj,jj);
+                  alphai(jj) = 0;
+                  betar(jj) = bb(jj,jj);
+                }
+              else
+                {
+                  // Complex conjugate pair.
+#ifdef DEBUG_EIG
+                  std::cout << "qz: calling dlag2:" << std::endl;
+                  std::cout << "safmin="
+                       << setiosflags (std::ios::scientific) << safmin << std::endl;
+
+                  for (int idr = jj; idr <= jj+1; idr++)
+                    {
+                      for (int idc = jj; idc <= jj+1; idc++)
+                        {
+                          std::cout << "aa(" << idr << "," << idc << ")="
+                               << aa(idr,idc) << std::endl;
+                          std::cout << "bb(" << idr << "," << idc << ")="
+                               << bb(idr,idc) << std::endl;
+                        }
+                    }
+#endif
+
+                  // FIXME -- probably should be using
+                  // fortran_vec instead of &aa(jj,jj) here.
+
+                  double scale1, scale2, wr1, wr2, wi;
+                  const double *aa_ptr = aa.data () + jj * nn + jj;
+                  const double *bb_ptr = bb.data () + jj * nn + jj;
+                  F77_XFCN (dlag2, DLAG2,
+                            (aa_ptr, nn, bb_ptr, nn, safmin,
+                             scale1, scale2, wr1, wr2, wi));
+
+#ifdef DEBUG_EIG
+                  std::cout << "dlag2 returns: scale1=" << scale1
+                       << "\tscale2=" << scale2 << std::endl
+                       << "\twr1=" << wr1 << "\twr2=" << wr2
+                       << "\twi=" << wi << std::endl;
+#endif
+
+                  // Just to be safe, check if it's a real pair.
+                  if (wi == 0)
+                    {
+                      alphar(jj) = wr1;
+                      alphai(jj) = 0;
+                      betar(jj) = scale1;
+                      alphar(jj+1) = wr2;
+                      alphai(jj+1) = 0;
+                      betar(jj+1) = scale2;
+                    }
+                  else
+                    {
+                      alphar(jj) = alphar(jj+1) = wr1;
+                      alphai(jj) = -(alphai(jj+1) = wi);
+                      betar(jj)  = betar(jj+1) = scale1;
+                    }
+                }
+
+              // Advance past this block.
+              jj += zcnt;
+            }
+
+#ifdef DEBUG_SORT
+          std::cout << "qz: back from dsubsp: aa=" << std::endl;
+          octave_print_internal (std::cout, aa, 0);
+          std::cout << std::endl << "bb="  << std::endl;
+          octave_print_internal (std::cout, bb, 0);
+
+          if (compz == 'V')
+            {
+              std::cout << std::endl << "ZZ="  << std::endl;
+              octave_print_internal (std::cout, ZZ, 0);
+            }
+          std::cout << std::endl << "qz: ndim=" << ndim << std::endl
+               << "fail=" << fail << std::endl;
+          std::cout << "alphar = " << std::endl;
+          octave_print_internal (std::cout, (Matrix) alphar, 0);
+          std::cout << std::endl << "alphai = " << std::endl;
+          octave_print_internal (std::cout, (Matrix) alphai, 0);
+          std::cout << std::endl << "beta = " << std::endl;
+          octave_print_internal (std::cout, (Matrix) betar, 0);
+          std::cout << std::endl;
+#endif
+        }
+    }
+
+  // Compute generalized eigenvalues?
+  ComplexColumnVector gev;
+
+  if (nargout < 2 || nargout == 7 || (nargin == 3 && nargout == 4))
+    {
+      if (complex_case)
+        {
+          int cnt = 0;
+
+          for (int ii = 0; ii < nn; ii++)
+            cnt++;
+
+          ComplexColumnVector tmp (cnt);
+
+          cnt = 0;
+          for (int ii = 0; ii < nn; ii++)
+            tmp(cnt++) = xalpha(ii) / xbeta(ii);
+
+          gev = tmp;
+        }
+      else
+        {
+#ifdef DEBUG
+          std::cout << "qz: computing generalized eigenvalues" << std::endl;
+#endif
+
+          // Return finite generalized eigenvalues.
+          int cnt = 0;
+
+          for (int ii = 0; ii < nn; ii++)
+            if (betar(ii) != 0)
+              cnt++;
+
+          ComplexColumnVector tmp (cnt);
+
+          cnt = 0;
+          for (int ii = 0; ii < nn; ii++)
+            if (betar(ii) != 0)
+              tmp(cnt++) = Complex(alphar(ii), alphai(ii))/betar(ii);
+
+          gev = tmp;
+        }
+    }
+
+  // Right, left eigenvector matrices.
+  if (nargout >= 5)
+    {
+      // Which side to compute?
+      char side = (nargout == 5 ? 'R' : 'B');
+      // Compute all of them and backtransform
+      char howmny = 'B';
+      // Dummy pointer; select is not used.
+      octave_idx_type *select = 0;
+
+      if (complex_case)
+        {
+          CVL = CQ;
+          CVR = CZ;
+          ComplexRowVector cwork2 (2 * nn);
+          RowVector rwork2 (8 * nn);
+          octave_idx_type m;
+
+          F77_XFCN (ztgevc, ZTGEVC,
+                    (F77_CONST_CHAR_ARG2 (&side, 1),
+                     F77_CONST_CHAR_ARG2 (&howmny, 1),
+                     select, nn, caa.fortran_vec (), nn, cbb.fortran_vec (),
+                     nn, CVL.fortran_vec (), nn, CVR.fortran_vec (), nn, nn,
+                     m, cwork2.fortran_vec (), rwork2.fortran_vec (), info
+                     F77_CHAR_ARG_LEN (1)
+                     F77_CHAR_ARG_LEN (1)));
+        }
+      else
+        {
+#ifdef DEBUG
+          std::cout << "qz: computing  generalized eigenvectors" << std::endl;
+#endif
+
+          VL = QQ;
+          VR = ZZ;
+          octave_idx_type m;
+
+          F77_XFCN (dtgevc, DTGEVC,
+                    (F77_CONST_CHAR_ARG2 (&side, 1),
+                     F77_CONST_CHAR_ARG2 (&howmny, 1),
+                     select, nn, aa.fortran_vec (), nn, bb.fortran_vec (),
+                     nn, VL.fortran_vec (), nn, VR.fortran_vec (), nn, nn,
+                     m, work.fortran_vec (), info
+                     F77_CHAR_ARG_LEN (1)
+                     F77_CHAR_ARG_LEN (1)));
+
+          // Now construct the complex form of VV, WW.
+          int jj = 0;
+
+          while (jj < nn)
+            {
+              OCTAVE_QUIT;
+
+              // See if real or complex eigenvalue.
+
+              // Column increment; assume complex eigenvalue.
+              int cinc = 2;
+
+              if (jj == (nn-1))
+                // Single column.
+                cinc = 1;
+              else if (aa(jj+1,jj) == 0)
+                cinc = 1;
+
+              // Now copy the eigenvector (s) to CVR, CVL.
+              if (cinc == 1)
+                {
+                  for (int ii = 0; ii < nn; ii++)
+                    CVR(ii,jj) = VR(ii,jj);
+
+                  if (side == 'B')
+                    for (int ii = 0; ii < nn; ii++)
+                      CVL(ii,jj) = VL(ii,jj);
+                }
+              else
+                {
+                  // Double column; complex vector.
+
+                  for (int ii = 0; ii < nn; ii++)
+                    {
+                      CVR(ii,jj) = Complex (VR(ii,jj), VR(ii,jj+1));
+                      CVR(ii,jj+1) = Complex (VR(ii,jj), -VR(ii,jj+1));
+                    }
+
+                  if (side == 'B')
+                    for (int ii = 0; ii < nn; ii++)
+                      {
+                        CVL(ii,jj) = Complex (VL(ii,jj), VL(ii,jj+1));
+                        CVL(ii,jj+1) = Complex (VL(ii,jj), -VL(ii,jj+1));
+                      }
+                }
+
+              // Advance to next eigenvectors (if any).
+              jj += cinc;
+            }
+        }
+    }
+
+  switch (nargout)
+    {
+    case 7:
+      retval(6) = gev;
+
+    case 6:
+      // Return eigenvectors.
+      retval(5) = CVL;
+
+    case 5:
+      // Return eigenvectors.
+      retval(4) = CVR;
+
+    case 4:
+      if (nargin == 3)
+        {
+#ifdef DEBUG
+          std::cout << "qz: sort: retval(3) = gev = " << std::endl;
+          octave_print_internal (std::cout, gev);
+          std::cout << std::endl;
+#endif
+          retval(3) = gev;
+        }
+      else
+        {
+          if (complex_case)
+            retval(3) = CZ;
+          else
+            retval(3) = ZZ;
+        }
+
+    case 3:
+      if (nargin == 3)
+        {
+          if (complex_case)
+            retval(2) = CZ;
+          else
+            retval(2) = ZZ;
+        }
+      else
+        {
+          if (complex_case)
+            retval(2) = CQ.hermitian ();
+          else
+            retval(2) = QQ.transpose ();
+        }
+
+    case 2:
+      {
+        if (complex_case)
+          {
+#ifdef DEBUG
+            std::cout << "qz: retval(1) = cbb = " << std::endl;
+            octave_print_internal (std::cout, cbb, 0);
+            std::cout << std::endl << "qz: retval(0) = caa = " <<std::endl;
+            octave_print_internal (std::cout, caa, 0);
+            std::cout << std::endl;
+#endif
+            retval(1) = cbb;
+            retval(0) = caa;
+          }
+      else
+        {
+#ifdef DEBUG
+          std::cout << "qz: retval(1) = bb = " << std::endl;
+          octave_print_internal (std::cout, bb, 0);
+          std::cout << std::endl << "qz: retval(0) = aa = " <<std::endl;
+          octave_print_internal (std::cout, aa, 0);
+          std::cout << std::endl;
+#endif
+          retval(1) = bb;
+          retval(0) = aa;
+        }
+      }
+      break;
+
+
+    case 1:
+    case 0:
+#ifdef DEBUG
+      std::cout << "qz: retval(0) = gev = " << gev << std::endl;
+#endif
+      retval(0) = gev;
+      break;
+
+    default:
+      error ("qz: too many return arguments");
+      break;
+  }
+
+#ifdef DEBUG
+  std::cout << "qz: exiting (at long last)" << std::endl;
+#endif
+
+  return retval;
+}
+
+/*
+%!shared a, b, c
+%! a = [1 2; 0 3];
+%! b = [1 0; 0 0];
+%! c = [0 1; 0 0];
+%!assert (qz (a,b), 1)
+%!assert (isempty (qz (a,c)))
+
+## Exaple 7.7.3 in Golub & Van Loan
+%!test
+%! a = [ 10  1  2;
+%!        1  2 -1;
+%!        1  1  2];
+%! b = reshape (1:9,3,3);
+%! [aa, bb, q, z, v, w, lambda] = qz (a, b);
+%! sz = length (lambda);
+%! observed = (b * v * diag ([lambda;0])) (:, 1:sz);
+%! assert ( (a*v) (:, 1:sz), observed, norm (observed) * 1e-14);
+%! observed = (diag ([lambda;0]) * w' * b) (1:sz, :);
+%! assert ( (w'*a) (1:sz, :) , observed, norm (observed) * 1e-13);
+%! assert (q * a * z, aa, norm (aa) * 1e-14);
+%! assert (q * b * z, bb, norm (bb) * 1e-14);
+
+%!test
+%! A = [0, 0, -1, 0; 1, 0, 0, 0; -1, 0, -2, -1; 0, -1, 1, 0];
+%! B = [0, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1];
+%! [AA, BB, Q, Z1] = qz (A, B);
+%! [AA, BB, Z2] = qz (A, B, '-');
+%! assert (Z1, Z2);
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/rand.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,1221 @@
+
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+Copyright (C) 2009 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <ctime>
+#if defined (HAVE_UNORDERED_MAP)
+#include <unordered_map>
+#elif defined (HAVE_TR1_UNORDERED_MAP)
+#include <tr1/unordered_map>
+#endif
+#include <string>
+
+#include "f77-fcn.h"
+#include "lo-mappers.h"
+#include "oct-rand.h"
+#include "quit.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "unwind-prot.h"
+#include "utils.h"
+#include "ov-re-mat.h"
+
+/*
+%!shared __random_statistical_tests__
+%! # Flag whether the statistical tests should be run in "make check" or not
+%! __random_statistical_tests__ = 0;
+*/
+
+static octave_value
+do_rand (const octave_value_list& args, int nargin, const char *fcn,
+         const std::string& distribution, bool additional_arg = false)
+{
+  octave_value retval;
+  NDArray a;
+  int idx = 0;
+  dim_vector dims;
+  bool is_single = false;
+
+  unwind_protect frame;
+  // Restore current distribution on any exit.
+  frame.add_fcn (octave_rand::distribution,
+                 octave_rand::distribution ());
+
+  octave_rand::distribution (distribution);
+
+  if (nargin > 0 && args(nargin-1).is_string ())
+    {
+      std::string s_arg = args(nargin-1).string_value ();
+
+      if (s_arg == "single")
+        {
+          is_single = true;
+          nargin--;
+        }
+      else if (s_arg == "double")
+        nargin--;
+    }
+
+  if (additional_arg)
+    {
+      if (nargin == 0)
+        {
+          error ("%s: expecting at least one argument", fcn);
+          goto done;
+        }
+      else if (args(0).is_string ())
+        additional_arg = false;
+      else
+        {
+          a = args(0).array_value ();
+          if (error_state)
+            {
+              error ("%s: expecting scalar or matrix arguments", fcn);
+              goto done;
+            }
+          idx++;
+          nargin--;
+        }
+    }
+
+  switch (nargin)
+    {
+    case 0:
+      {
+        if (additional_arg)
+          dims = a.dims ();
+        else
+          {
+            dims.resize (2);
+
+            dims(0) = 1;
+            dims(1) = 1;
+          }
+        goto gen_matrix;
+      }
+      break;
+
+    case 1:
+      {
+        octave_value tmp = args(idx);
+
+        if (tmp.is_string ())
+          {
+            std::string s_arg = tmp.string_value ();
+
+            if (s_arg == "dist")
+              {
+                retval = octave_rand::distribution ();
+              }
+            else if (s_arg == "seed")
+              {
+                retval = octave_rand::seed ();
+              }
+            else if (s_arg == "state" || s_arg == "twister")
+              {
+                retval = octave_rand::state (fcn);
+              }
+            else if (s_arg == "uniform")
+              {
+                octave_rand::uniform_distribution ();
+              }
+            else if (s_arg == "normal")
+              {
+                octave_rand::normal_distribution ();
+              }
+            else if (s_arg == "exponential")
+              {
+                octave_rand::exponential_distribution ();
+              }
+            else if (s_arg == "poisson")
+              {
+                octave_rand::poisson_distribution ();
+              }
+            else if (s_arg == "gamma")
+              {
+                octave_rand::gamma_distribution ();
+              }
+            else
+              error ("%s: unrecognized string argument", fcn);
+          }
+        else if (tmp.is_scalar_type ())
+          {
+            double dval = tmp.double_value ();
+
+            if (xisnan (dval))
+              {
+                error ("%s: NaN is invalid matrix dimension", fcn);
+              }
+            else
+              {
+                dims.resize (2);
+
+                dims(0) = NINTbig (tmp.double_value ());
+                dims(1) = NINTbig (tmp.double_value ());
+
+                if (! error_state)
+                  goto gen_matrix;
+              }
+          }
+        else if (tmp.is_range ())
+          {
+            Range r = tmp.range_value ();
+
+            if (r.all_elements_are_ints ())
+              {
+                octave_idx_type n = r.nelem ();
+
+                dims.resize (n);
+
+                octave_idx_type base = NINTbig (r.base ());
+                octave_idx_type incr = NINTbig (r.inc ());
+
+                for (octave_idx_type i = 0; i < n; i++)
+                  {
+                    //Negative dimensions are treated as zero for Matlab
+                    //compatibility
+                    dims(i) = base >= 0 ? base : 0;
+                    base += incr;
+                  }
+
+                goto gen_matrix;
+
+              }
+            else
+              error ("%s: all elements of range must be integers",
+                     fcn);
+          }
+        else if (tmp.is_matrix_type ())
+          {
+            Array<int> iv = tmp.int_vector_value (true);
+
+            if (! error_state)
+              {
+                octave_idx_type len = iv.length ();
+
+                dims.resize (len);
+
+                for (octave_idx_type i = 0; i < len; i++)
+                  {
+                    //Negative dimensions are treated as zero for Matlab
+                    //compatibility
+                    octave_idx_type elt = iv(i);
+                    dims(i) = elt >=0 ? elt : 0;
+                  }
+
+                goto gen_matrix;
+              }
+            else
+              error ("%s: expecting integer vector", fcn);
+          }
+        else
+          {
+            gripe_wrong_type_arg ("rand", tmp);
+            return retval;
+          }
+      }
+      break;
+
+    default:
+      {
+        octave_value tmp = args(idx);
+
+        if (nargin == 2 && tmp.is_string ())
+          {
+            std::string ts = tmp.string_value ();
+
+            if (ts == "seed")
+              {
+                if (args(idx+1).is_real_scalar ())
+                  {
+                    double d = args(idx+1).double_value ();
+
+                    if (! error_state)
+                      octave_rand::seed (d);
+                  }
+                else if (args(idx+1).is_string ()
+                         && args(idx+1).string_value () == "reset")
+                  octave_rand::reset ();
+                else
+                  error ("%s: seed must be a real scalar", fcn);
+              }
+            else if (ts == "state" || ts == "twister")
+              {
+                if (args(idx+1).is_string ()
+                    && args(idx+1).string_value () == "reset")
+                  octave_rand::reset (fcn);
+                else
+                  {
+                    ColumnVector s =
+                      ColumnVector (args(idx+1).vector_value(false, true));
+
+                    if (! error_state)
+                      octave_rand::state (s, fcn);
+                  }
+              }
+            else
+              error ("%s: unrecognized string argument", fcn);
+          }
+        else
+          {
+            dims.resize (nargin);
+
+            for (int i = 0; i < nargin; i++)
+              {
+                octave_idx_type elt = args(idx+i).int_value ();
+                if (error_state)
+                  {
+                    error ("%s: expecting integer arguments", fcn);
+                    goto done;
+                  }
+                //Negative is zero for Matlab compatibility
+                dims(i) = elt >= 0 ? elt : 0;
+              }
+
+            goto gen_matrix;
+          }
+      }
+      break;
+    }
+
+ done:
+
+  return retval;
+
+ gen_matrix:
+
+  dims.chop_trailing_singletons ();
+
+  if (is_single)
+    {
+      if (additional_arg)
+        {
+          if (a.length () == 1)
+            return octave_rand::float_nd_array (dims, a(0));
+          else
+            {
+              if (a.dims () != dims)
+                {
+                  error ("%s: mismatch in argument size", fcn);
+                  return retval;
+                }
+              octave_idx_type len = a.length ();
+              FloatNDArray m (dims);
+              float *v = m.fortran_vec ();
+              for (octave_idx_type i = 0; i < len; i++)
+                v[i] = octave_rand::float_scalar (a(i));
+              return m;
+            }
+        }
+      else
+        return octave_rand::float_nd_array (dims);
+    }
+  else
+    {
+      if (additional_arg)
+        {
+          if (a.length () == 1)
+            return octave_rand::nd_array (dims, a(0));
+          else
+            {
+              if (a.dims () != dims)
+                {
+                  error ("%s: mismatch in argument size", fcn);
+                  return retval;
+                }
+              octave_idx_type len = a.length ();
+              NDArray m (dims);
+              double *v = m.fortran_vec ();
+              for (octave_idx_type i = 0; i < len; i++)
+                v[i] = octave_rand::scalar (a(i));
+              return m;
+            }
+        }
+      else
+        return octave_rand::nd_array (dims);
+    }
+}
+
+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} {@var{v} =} rand (\"state\")\n\
+@deftypefnx {Built-in Function} {} rand (\"state\", @var{v})\n\
+@deftypefnx {Built-in Function} {} rand (\"state\", \"reset\")\n\
+@deftypefnx {Built-in Function} {@var{v} =} rand (\"seed\")\n\
+@deftypefnx {Built-in Function} {} rand (\"seed\", @var{v})\n\
+@deftypefnx {Built-in Function} {} rand (\"seed\", \"reset\")\n\
+@deftypefnx {Built-in Function} {} rand (@dots{}, \"single\")\n\
+@deftypefnx {Built-in Function} {} rand (@dots{}, \"double\")\n\
+Return a matrix with random elements uniformly distributed on the\n\
+interval (0, 1).  The arguments are handled the same as the arguments\n\
+for @code{eye}.\n\
+\n\
+You can query the state of the random number generator using the\n\
+form\n\
+\n\
+@example\n\
+v = rand (\"state\")\n\
+@end example\n\
+\n\
+This returns a column vector @var{v} of length 625.  Later, you can\n\
+restore the random number generator to the state @var{v}\n\
+using the form\n\
+\n\
+@example\n\
+rand (\"state\", v)\n\
+@end example\n\
+\n\
+@noindent\n\
+You may also initialize the state vector from an arbitrary vector of\n\
+length @leq{} 625 for @var{v}.  This new state will be a hash based on the\n\
+value of @var{v}, not @var{v} itself.\n\
+\n\
+By default, the generator is initialized from @code{/dev/urandom} if it is\n\
+available, otherwise from CPU time, wall clock time, and the current\n\
+fraction of a second.  Note that this differs from @sc{matlab}, which\n\
+always initializes the state to the same state at startup.  To obtain\n\
+behavior comparable to @sc{matlab}, initialize with a deterministic state\n\
+vector in Octave's startup files (@pxref{Startup Files}).\n\
+\n\
+To compute the pseudo-random sequence, @code{rand} uses the Mersenne\n\
+Twister with a period of @math{2^{19937}-1} (See M. Matsumoto and\n\
+T. Nishimura,\n\
+@cite{Mersenne Twister: A 623-dimensionally equidistributed uniform\n\
+pseudorandom number generator}, ACM Trans. on\n\
+Modeling and Computer Simulation Vol. 8, No. 1, pp. 3-30, January 1998,\n\
+@url{http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html}).\n\
+Do @strong{not} use for cryptography without securely hashing\n\
+several returned values together, otherwise the generator state\n\
+can be learned after reading 624 consecutive values.\n\
+\n\
+Older versions of Octave used a different random number generator.\n\
+The new generator is used by default\n\
+as it is significantly faster than the old generator, and produces\n\
+random numbers with a significantly longer cycle time.  However, in\n\
+some circumstances it might be desirable to obtain the same random\n\
+sequences as used by the old generators.  To do this the keyword\n\
+\"seed\" is used to specify that the old generators should be use,\n\
+as in\n\
+\n\
+@example\n\
+rand (\"seed\", val)\n\
+@end example\n\
+\n\
+@noindent\n\
+which sets the seed of the generator to @var{val}.  The seed of the\n\
+generator can be queried with\n\
+\n\
+@example\n\
+s = rand (\"seed\")\n\
+@end example\n\
+\n\
+However, it should be noted that querying the seed will not cause\n\
+@code{rand} to use the old generators, only setting the seed will.\n\
+To cause @code{rand} to once again use the new generators, the\n\
+keyword \"state\" should be used to reset the state of the @code{rand}.\n\
+\n\
+The state or seed of the generator can be reset to a new random value\n\
+using the \"reset\" keyword.\n\
+\n\
+The class of the value returned can be controlled by a trailing \"double\"\n\
+or \"single\" argument.  These are the only valid classes.\n\
+@seealso{randn, rande, randg, randp}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  retval = do_rand (args, nargin, "rand", "uniform");
+
+  return retval;
+}
+
+// FIXME -- The old generator (selected when "seed" is set) will not
+// work properly if compiled to use 64-bit integers.
+
+/*
+%!test  # "state" can be a scalar
+%! rand ("state", 12);  x = rand (1,4);
+%! rand ("state", 12);  y = rand (1,4);
+%! assert (x, y);
+%!test  # "state" can be a vector
+%! rand ("state", [12,13]);  x = rand (1,4);
+%! rand ("state", [12;13]);  y = rand (1,4);
+%! assert (x, y);
+%!test  # querying "state" doesn't disturb sequence
+%! rand ("state", 12);  rand (1,2);  x = rand (1,2);
+%! rand ("state", 12);  rand (1,2);
+%! s = rand ("state");  y = rand (1,2);
+%! assert (x, y);
+%! rand ("state", s);  z = rand (1,2);
+%! assert (x, z);
+%!test  # "seed" must be a scalar
+%! rand ("seed", 12);  x = rand (1,4);
+%! rand ("seed", 12);  y = rand (1,4);
+%! assert (x, y);
+%!error <seed must be a real scalar> rand ("seed", [12,13])
+%!test  # querying "seed" returns a value which can be used later
+%! s = rand ("seed");  x = rand (1,2);
+%! rand ("seed", s);  y = rand (1,2);
+%! assert (x, y);
+%!test  # querying "seed" doesn't disturb sequence
+%! rand ("seed", 12);  rand (1,2);  x = rand (1,2);
+%! rand ("seed", 12);  rand (1,2);
+%! s = rand ("seed");  y = rand (1,2);
+%! assert (x, y);
+%! rand ("seed", s);  z = rand (1,2);
+%! assert (x, z);
+*/
+
+/*
+%!test
+%! # Test fixed state
+%! rand ("state", 1);
+%! assert (rand (1,6), [0.1343642441124013 0.8474337369372327 0.763774618976614 0.2550690257394218 0.495435087091941 0.4494910647887382], 1e-6);
+%!test
+%! # Test fixed seed
+%! rand ("seed", 1);
+%! assert (rand (1,6), [0.8668024251237512 0.9126510815694928 0.09366085007786751 0.1664607301354408 0.7408077004365623 0.7615650338120759], 1e-6);
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   rand ("state", 12);
+%!   x = rand (100000, 1);
+%!   assert (max (x) < 1);   #*** Please report this!!! ***
+%!   assert (min (x) > 0);   #*** Please report this!!! ***
+%!   assert (mean (x), 0.5, 0.0024);
+%!   assert (var (x), 1/48, 0.0632);
+%!   assert (skewness (x), 0, 0.012);
+%!   assert (kurtosis (x), -6/5, 0.0094);
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   rand ("seed", 12);
+%!   x = rand (100000, 1);
+%!   assert (max (x) < 1);   #*** Please report this!!! ***
+%!   assert (min (x) > 0);   #*** Please report this!!! ***
+%!   assert (mean (x), 0.5, 0.0024);
+%!   assert (var (x), 1/48, 0.0632);
+%!   assert (skewness (x), 0, 0.012);
+%!   assert (kurtosis (x), -6/5, 0.0094);
+%! endif
+*/
+
+static std::string current_distribution = octave_rand::distribution ();
+
+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} {@var{v} =} randn (\"state\")\n\
+@deftypefnx {Built-in Function} {} randn (\"state\", @var{v})\n\
+@deftypefnx {Built-in Function} {} randn (\"state\", \"reset\")\n\
+@deftypefnx {Built-in Function} {@var{v} =} randn (\"seed\")\n\
+@deftypefnx {Built-in Function} {} randn (\"seed\", @var{v})\n\
+@deftypefnx {Built-in Function} {} randn (\"seed\", \"reset\")\n\
+@deftypefnx {Built-in Function} {} randn (@dots{}, \"single\")\n\
+@deftypefnx {Built-in Function} {} randn (@dots{}, \"double\")\n\
+Return a matrix with normally distributed random\n\
+elements having zero mean and variance one.  The arguments are\n\
+handled the same as the arguments for @code{rand}.\n\
+\n\
+By default, @code{randn} uses the Marsaglia and Tsang ``Ziggurat technique''\n\
+to transform from a uniform to a normal distribution.\n\
+\n\
+The class of the value returned can be controlled by a trailing \"double\"\n\
+or \"single\" argument.  These are the only valid classes.\n\
+\n\
+Reference: G. Marsaglia and W.W. Tsang,\n\
+@cite{Ziggurat Method for Generating Random Variables},\n\
+J. Statistical Software, vol 5, 2000,\n\
+@url{http://www.jstatsoft.org/v05/i08/})\n\
+\n\
+@seealso{rand, rande, randg, randp}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  retval = do_rand (args, nargin, "randn", "normal");
+
+  return retval;
+}
+
+/*
+%!test
+%! # Test fixed state
+%! randn ("state", 1);
+%! assert (randn (1, 6), [-2.666521678978671 -0.7381719971724564 1.507903992673601 0.6019427189162239 -0.450661261143348 -0.7054431351574116], 1e-6);
+%!test
+%! # Test fixed seed
+%! randn ("seed", 1);
+%! assert (randn (1, 6), [-1.039402365684509 -1.25938892364502 0.1968704611063004 0.3874166905879974 -0.5976632833480835 -0.6615074276924133], 1e-6);
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randn ("state", 12);
+%!   x = randn (100000, 1);
+%!   assert (mean (x), 0, 0.01);
+%!   assert (var (x), 1, 0.02);
+%!   assert (skewness (x), 0, 0.02);
+%!   assert (kurtosis (x), 0, 0.04);
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randn ("seed", 12);
+%!   x = randn (100000, 1);
+%!   assert (mean (x), 0, 0.01);
+%!   assert (var (x), 1, 0.02);
+%!   assert (skewness (x), 0, 0.02);
+%!   assert (kurtosis (x), 0, 0.04);
+%! endif
+*/
+
+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} {@var{v} =} rande (\"state\")\n\
+@deftypefnx {Built-in Function} {} rande (\"state\", @var{v})\n\
+@deftypefnx {Built-in Function} {} rande (\"state\", \"reset\")\n\
+@deftypefnx {Built-in Function} {@var{v} =} rande (\"seed\")\n\
+@deftypefnx {Built-in Function} {} rande (\"seed\", @var{v})\n\
+@deftypefnx {Built-in Function} {} rande (\"seed\", \"reset\")\n\
+@deftypefnx {Built-in Function} {} rande (@dots{}, \"single\")\n\
+@deftypefnx {Built-in Function} {} rande (@dots{}, \"double\")\n\
+Return a matrix with exponentially distributed random elements.  The\n\
+arguments are handled the same as the arguments for @code{rand}.\n\
+\n\
+By default, @code{randn} uses the Marsaglia and Tsang ``Ziggurat technique''\n\
+to transform from a uniform to an exponential distribution.\n\
+\n\
+The class of the value returned can be controlled by a trailing \"double\"\n\
+or \"single\" argument.  These are the only valid classes.\n\
+\n\
+Reference: G. Marsaglia and W.W. Tsang,\n\
+@cite{Ziggurat Method for Generating Random Variables},\n\
+J. Statistical Software, vol 5, 2000,\n\
+@url{http://www.jstatsoft.org/v05/i08/})\n\
+\n\
+@seealso{rand, randn, randg, randp}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  retval = do_rand (args, nargin, "rande", "exponential");
+
+  return retval;
+}
+
+/*
+%!test
+%! # Test fixed state
+%! rande ("state", 1);
+%! assert (rande (1, 6), [3.602973885835625 0.1386190677555021 0.6743112889616958 0.4512830847258422 0.7255744741233175 0.3415969205292291], 1e-6);
+%!test
+%! # Test fixed seed
+%! rande ("seed", 1);
+%! assert (rande (1, 6), [0.06492075175653866 1.717980206012726 0.4816154008731246 0.5231300676241517 0.103910739364359 1.668931916356087], 1e-6);
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally
+%!   rande ("state", 1);
+%!   x = rande (100000, 1);
+%!   assert (min (x) > 0);   # *** Please report this!!! ***
+%!   assert (mean (x), 1, 0.01);
+%!   assert (var (x), 1, 0.03);
+%!   assert (skewness (x), 2, 0.06);
+%!   assert (kurtosis (x), 6, 0.7);
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally
+%!   rande ("seed", 1);
+%!   x = rande (100000, 1);
+%!   assert (min (x)>0);   # *** Please report this!!! ***
+%!   assert (mean (x), 1, 0.01);
+%!   assert (var (x), 1, 0.03);
+%!   assert (skewness (x), 2, 0.06);
+%!   assert (kurtosis (x), 6, 0.7);
+%! endif
+*/
+
+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} {@var{v} =} randg (\"state\")\n\
+@deftypefnx {Built-in Function} {} randg (\"state\", @var{v})\n\
+@deftypefnx {Built-in Function} {} randg (\"state\", \"reset\")\n\
+@deftypefnx {Built-in Function} {@var{v} =} randg (\"seed\")\n\
+@deftypefnx {Built-in Function} {} randg (\"seed\", @var{v})\n\
+@deftypefnx {Built-in Function} {} randg (\"seed\", \"reset\")\n\
+@deftypefnx {Built-in Function} {} randg (@dots{}, \"single\")\n\
+@deftypefnx {Built-in Function} {} randg (@dots{}, \"double\")\n\
+Return a matrix with @code{gamma (@var{a},1)} distributed random elements.\n\
+The arguments are handled the same as the arguments for @code{rand},\n\
+except for the argument @var{a}.\n\
+\n\
+This can be used to generate many distributions:\n\
+\n\
+@table @asis\n\
+@item @code{gamma (a, b)} for @code{a > -1}, @code{b > 0}\n\
+\n\
+@example\n\
+r = b * randg (a)\n\
+@end example\n\
+\n\
+@item @code{beta (a, b)} for @code{a > -1}, @code{b > -1}\n\
+\n\
+@example\n\
+@group\n\
+r1 = randg (a, 1)\n\
+r = r1 / (r1 + randg (b, 1))\n\
+@end group\n\
+@end example\n\
+\n\
+@item @code{Erlang (a, n)}\n\
+\n\
+@example\n\
+r = a * randg (n)\n\
+@end example\n\
+\n\
+@item @code{chisq (df)} for @code{df > 0}\n\
+\n\
+@example\n\
+r = 2 * randg (df / 2)\n\
+@end example\n\
+\n\
+@item @code{t (df)} for @code{0 < df < inf} (use randn if df is infinite)\n\
+\n\
+@example\n\
+r = randn () / sqrt (2 * randg (df / 2) / df)\n\
+@end example\n\
+\n\
+@item @code{F (n1, n2)} for @code{0 < n1}, @code{0 < n2}\n\
+\n\
+@example\n\
+@group\n\
+## r1 equals 1 if n1 is infinite\n\
+r1 = 2 * randg (n1 / 2) / n1\n\
+## r2 equals 1 if n2 is infinite\n\
+r2 = 2 * randg (n2 / 2) / n2\n\
+r = r1 / r2\n\n\
+@end group\n\
+@end example\n\
+\n\
+@item negative @code{binomial (n, p)} for @code{n > 0}, @code{0 < p <= 1}\n\
+\n\
+@example\n\
+r = randp ((1 - p) / p * randg (n))\n\
+@end example\n\
+\n\
+@item non-central @code{chisq (df, L)}, for @code{df >= 0} and @code{L > 0}\n\
+(use chisq if @code{L = 0})\n\
+\n\
+@example\n\
+@group\n\
+r = randp (L / 2)\n\
+r(r > 0) = 2 * randg (r(r > 0))\n\
+r(df > 0) += 2 * randg (df(df > 0)/2)\n\
+@end group\n\
+@end example\n\
+\n\
+@item @code{Dirichlet (a1, @dots{} ak)}\n\
+\n\
+@example\n\
+@group\n\
+r = (randg (a1), @dots{}, randg (ak))\n\
+r = r / sum (r)\n\
+@end group\n\
+@end example\n\
+\n\
+@end table\n\
+\n\
+The class of the value returned can be controlled by a trailing \"double\"\n\
+or \"single\" argument.  These are the only valid classes.\n\
+@seealso{rand, randn, rande, randp}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 1)
+    error ("randg: insufficient arguments");
+  else
+    retval = do_rand (args, nargin, "randg", "gamma", true);
+
+  return retval;
+}
+
+/*
+%!test
+%! randg ("state", 12)
+%! assert (randg ([-inf, -1, 0, inf, nan]), [nan, nan, nan, nan, nan]); # *** Please report
+
+%!test
+%! # Test fixed state
+%! randg ("state", 1);
+%! assert (randg (0.1, 1, 6), [0.0103951513331241 8.335671459898252e-05 0.00138691397249762 0.000587308416993855 0.495590518784736 2.3921917414795e-12], 1e-6);
+%!test
+%! # Test fixed state
+%! randg ("state", 1);
+%! assert (randg (0.95, 1, 6), [3.099382433255327 0.3974529788871218 0.644367450750855 1.143261091802246 1.964111762696822 0.04011915547957939], 1e-6);
+%!test
+%! # Test fixed state
+%! randg ("state", 1);
+%! assert (randg (1, 1, 6), [0.2273389379645993 1.288822625058359 0.2406335209340746 1.218869553370733 1.024649860162554 0.09631230343599533], 1e-6);
+%!test
+%! # Test fixed state
+%! randg ("state", 1);
+%! assert (randg (10, 1, 6), [3.520369644331133 15.15369864472106 8.332112081991205 8.406211067432674 11.81193475187611 10.88792728177059], 1e-5);
+%!test
+%! # Test fixed state
+%! randg ("state", 1);
+%! assert (randg (100, 1, 6), [75.34570255262264 115.4911985594699 95.23493031356388 95.48926019250911 106.2397448229803 103.4813150404118], 1e-4);
+%!test
+%! # Test fixed seed
+%! randg ("seed", 1);
+%! assert (randg (0.1, 1, 6), [0.07144210487604141 0.460641473531723 0.4749028384685516 0.06823389977216721 0.000293838675133884 1.802567535340305e-12], 1e-6);
+%!test
+%! # Test fixed seed
+%! randg ("seed", 1);
+%! assert (randg (0.95, 1, 6), [1.664905071258545 1.879976987838745 1.905677795410156 0.9948706030845642 0.5606933236122131 0.0766092911362648], 1e-6);
+%!test
+%! # Test fixed seed
+%! randg ("seed", 1);
+%! assert (randg (1, 1, 6), [0.03512085229158401 0.6488978862762451 0.8114678859710693 0.1666885763406754 1.60791552066803 1.90356981754303], 1e-6);
+%!test
+%! # Test fixed seed
+%! randg ("seed", 1);
+%! assert (randg (10, 1, 6), [6.566435813903809 10.11648464202881 10.73162078857422 7.747178077697754 6.278522491455078 6.240195751190186], 1e-5);
+%!test
+%! # Test fixed seed
+%! randg ("seed", 1);
+%! assert (randg (100, 1, 6), [89.40208435058594 101.4734725952148 103.4020004272461 93.62763214111328 88.33104705810547 88.1871337890625], 1e-4);
+
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randg ("state", 12);
+%!   a = 0.1;
+%!   x = randg (a, 100000, 1);
+%!   assert (mean (x),     a,          0.01);
+%!   assert (var (x),      a,          0.01);
+%!   assert (skewness (x), 2/sqrt (a), 1);
+%!   assert (kurtosis (x), 6/a,        50);
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randg ("state", 12);
+%!   a = 0.95;
+%!   x = randg (a, 100000, 1);
+%!   assert (mean (x),     a,          0.01);
+%!   assert (var (x),      a,          0.04);
+%!   assert (skewness (x), 2/sqrt (a), 0.2);
+%!   assert (kurtosis (x), 6/a,        2);
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randg ("state", 12);
+%!   a = 1;
+%!   x = randg (a, 100000, 1);
+%!   assert (mean (x),     a,          0.01);
+%!   assert (var (x),      a,          0.04);
+%!   assert (skewness (x), 2/sqrt (a), 0.2);
+%!   assert (kurtosis (x), 6/a,        2);
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randg ("state", 12);
+%!   a = 10;
+%!   x = randg (a, 100000, 1);
+%!   assert (mean (x),     a,          0.1);
+%!   assert (var (x),      a,          0.5);
+%!   assert (skewness (x), 2/sqrt (a), 0.1);
+%!   assert (kurtosis (x), 6/a,        0.5);
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randg ("state", 12);
+%!   a = 100;
+%!   x = randg (a, 100000, 1);
+%!   assert (mean (x),     a,          0.2);
+%!   assert (var (x),      a,          2);
+%!   assert (skewness (x), 2/sqrt (a), 0.05);
+%!   assert (kurtosis (x), 6/a,        0.2);
+%! endif
+%!test
+%! randg ("seed", 12);
+%!assert (randg ([-inf, -1, 0, inf, nan]), [nan, nan, nan, nan, nan]) # *** Please report
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randg ("seed", 12);
+%!   a = 0.1;
+%!   x = randg (a, 100000, 1);
+%!   assert (mean (x),     a,          0.01);
+%!   assert (var (x),      a,          0.01);
+%!   assert (skewness (x), 2/sqrt (a), 1);
+%!   assert (kurtosis (x), 6/a,        50);
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randg ("seed", 12);
+%!   a = 0.95;
+%!   x = randg (a, 100000, 1);
+%!   assert (mean (x),     a,          0.01);
+%!   assert (var (x),      a,          0.04);
+%!   assert (skewness (x), 2/sqrt (a), 0.2);
+%!   assert (kurtosis (x), 6/a,        2);
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randg ("seed", 12);
+%!   a = 1;
+%!   x = randg (a, 100000, 1);
+%!   assert (mean (x),     a,          0.01);
+%!   assert (var (x),      a,          0.04);
+%!   assert (skewness (x), 2/sqrt (a), 0.2);
+%!   assert (kurtosis (x), 6/a,        2);
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randg ("seed", 12);
+%!   a = 10;
+%!   x = randg (a, 100000, 1);
+%!   assert (mean (x),     a,          0.1);
+%!   assert (var (x),      a,          0.5);
+%!   assert (skewness (x), 2/sqrt (a), 0.1);
+%!   assert (kurtosis (x), 6/a,        0.5);
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randg ("seed", 12);
+%!   a = 100;
+%!   x = randg (a, 100000, 1);
+%!   assert (mean (x),     a,          0.2);
+%!   assert (var (x),      a,          2);
+%!   assert (skewness (x), 2/sqrt (a), 0.05);
+%!   assert (kurtosis (x), 6/a,        0.2);
+%! endif
+*/
+
+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} {@var{v} =} randp (\"state\")\n\
+@deftypefnx {Built-in Function} {} randp (\"state\", @var{v})\n\
+@deftypefnx {Built-in Function} {} randp (\"state\", \"reset\")\n\
+@deftypefnx {Built-in Function} {@var{v} =} randp (\"seed\")\n\
+@deftypefnx {Built-in Function} {} randp (\"seed\", @var{v})\n\
+@deftypefnx {Built-in Function} {} randp (\"seed\", \"reset\")\n\
+@deftypefnx {Built-in Function} {} randp (@dots{}, \"single\")\n\
+@deftypefnx {Built-in Function} {} randp (@dots{}, \"double\")\n\
+Return a matrix with Poisson distributed random elements with mean value\n\
+parameter given by the first argument, @var{l}.  The arguments\n\
+are handled the same as the arguments for @code{rand}, except for the\n\
+argument @var{l}.\n\
+\n\
+Five different algorithms are used depending on the range of @var{l}\n\
+and whether or not @var{l} is a scalar or a matrix.\n\
+\n\
+@table @asis\n\
+@item For scalar @var{l} @leq{} 12, use direct method.\n\
+W.H. Press, et al., @cite{Numerical Recipes in C},\n\
+Cambridge University Press, 1992.\n\
+\n\
+@item For scalar @var{l} > 12, use rejection method.[1]\n\
+W.H. Press, et al., @cite{Numerical Recipes in C},\n\
+Cambridge University Press, 1992.\n\
+\n\
+@item For matrix @var{l} @leq{} 10, use inversion method.[2]\n\
+E. Stadlober, et al., WinRand source code, available via FTP.\n\
+\n\
+@item For matrix @var{l} > 10, use patchwork rejection method.\n\
+E. Stadlober, et al., WinRand source code, available via FTP, or\n\
+H. Zechner, @cite{Efficient sampling from continuous and discrete\n\
+unimodal distributions}, Doctoral Dissertation, 156pp., Technical\n\
+University Graz, Austria, 1994.\n\
+\n\
+@item For @var{l} > 1e8, use normal approximation.\n\
+L. Montanet, et al., @cite{Review of Particle Properties}, Physical Review\n\
+D 50 p1284, 1994.\n\
+@end table\n\
+\n\
+The class of the value returned can be controlled by a trailing \"double\"\n\
+or \"single\" argument.  These are the only valid classes.\n\
+@seealso{rand, randn, rande, randg}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 1)
+    error ("randp: insufficient arguments");
+  else
+    retval = do_rand (args, nargin, "randp", "poisson", true);
+
+  return retval;
+}
+
+/*
+%!test
+%! randp ("state", 12);
+%! assert (randp ([-inf, -1, 0, inf, nan]), [nan, nan, 0, nan, nan]);   # *** Please report
+%!test
+%! # Test fixed state
+%! randp ("state", 1);
+%! assert (randp (5, 1, 6), [5 5 3 7 7 3])
+%!test
+%! # Test fixed state
+%! randp ("state", 1);
+%! assert (randp (15, 1, 6), [13 15 8 18 18 15])
+%!test
+%! # Test fixed state
+%! randp ("state", 1);
+%! assert (randp (1e9, 1, 6), [999915677 999976657 1000047684 1000019035 999985749 999977692], -1e-6)
+%!test
+%! # Test fixed state
+%! randp ("seed", 1);
+%! %%assert (randp (5, 1, 6), [8 2 3 6 6 8])
+%! assert (randp (5, 1, 5), [8 2 3 6 6])
+%!test
+%! # Test fixed state
+%! randp ("seed", 1);
+%! assert (randp (15, 1, 6), [15 16 12 10 10 12])
+%!test
+%! # Test fixed state
+%! randp ("seed", 1);
+%! assert (randp (1e9, 1, 6), [1000006208 1000012224 999981120 999963520 999963072 999981440], -1e-6)
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randp ("state", 12);
+%!   for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
+%!     x = randp (a (1), 100000, 1);
+%!     assert (min (x) >= 0);   # *** Please report this!!! ***
+%!     assert (mean (x), a(1), a(2));
+%!     assert (var (x), a(1), 0.02*a(1));
+%!     assert (skewness (x), 1/sqrt (a(1)), a(3));
+%!     assert (kurtosis (x), 1/a(1), 3*a(3));
+%!   endfor
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randp ("state", 12);
+%!   for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
+%!     x = randp (a(1)*ones (100000, 1), 100000, 1);
+%!     assert (min (x) >= 0);   # *** Please report this!!! ***
+%!     assert (mean (x), a(1), a(2));
+%!     assert (var (x), a(1), 0.02*a(1));
+%!     assert (skewness (x), 1/sqrt (a(1)), a(3));
+%!     assert (kurtosis (x), 1/a(1), 3*a(3));
+%!   endfor
+%! endif
+%!test
+%! randp ("seed", 12);
+%! assert (randp ([-inf, -1, 0, inf, nan]), [nan, nan, 0, nan, nan]);   # *** Please report
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randp ("seed", 12);
+%!   for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
+%!     x = randp (a(1), 100000, 1);
+%!     assert (min (x) >= 0);   # *** Please report this!!! ***
+%!     assert (mean (x), a(1), a(2));
+%!     assert (var (x), a(1), 0.02*a(1));
+%!     assert (skewness (x), 1/sqrt (a(1)), a(3));
+%!     assert (kurtosis (x), 1/a(1), 3*a(3));
+%!   endfor
+%! endif
+%!test
+%! if (__random_statistical_tests__)
+%!   # statistical tests may fail occasionally.
+%!   randp ("seed", 12);
+%!   for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
+%!     x = randp (a(1)*ones (100000, 1), 100000, 1);
+%!     assert (min (x) >= 0);   # *** Please report this!!! ***
+%!     assert (mean (x), a(1), a(2));
+%!     assert (var (x), a(1), 0.02*a(1));
+%!     assert (skewness (x), 1/sqrt (a(1)), a(3));
+%!     assert (kurtosis (x), 1/a(1), 3*a(3));
+%!   endfor
+%! endif
+*/
+
+DEFUN (randperm, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} randperm (@var{n})\n\
+@deftypefnx {Built-in Function} {} randperm (@var{n}, @var{m})\n\
+Return a row vector containing a random permutation of @code{1:@var{n}}.\n\
+If @var{m} is supplied, return @var{m} unique entries, sampled without\n\
+replacement from @code{1:@var{n}}.  The complexity is O(@var{n}) in\n\
+memory and O(@var{m}) in time, unless @var{m} < @var{n}/5, in which case\n\
+O(@var{m}) memory is used as well.  The randomization is performed using\n\
+rand().  All permutations are equally likely.\n\
+@seealso{perms}\n\
+@end deftypefn")
+{
+
+#ifdef USE_UNORDERED_MAP_WITH_TR1
+using std::tr1::unordered_map;
+#else
+using std::unordered_map;
+#endif
+
+  int nargin = args.length ();
+  octave_value retval;
+
+  if (nargin == 1 || nargin == 2)
+    {
+      octave_idx_type n, m;
+
+      n = args(0).idx_type_value (true);
+
+      if (nargin == 2)
+        m = args(1).idx_type_value (true);
+      else
+        m = n;
+
+      if (m < 0 || n < 0)
+        error ("randperm: M and N must be non-negative");
+
+      if (m > n)
+        error ("randperm: M must be less than or equal to N");
+
+      // Quick and dirty heuristic to decide if we allocate or not the
+      // whole vector for tracking the truncated shuffle.
+      bool short_shuffle = m < n/5 && m < 1e5;
+
+      if (! error_state)
+        {
+          // Generate random numbers.
+          NDArray r = octave_rand::nd_array (dim_vector (1, m));
+          double *rvec = r.fortran_vec ();
+
+          octave_idx_type idx_len = short_shuffle ? m : n;
+          Array<octave_idx_type> idx (dim_vector (1, idx_len));
+          octave_idx_type *ivec = idx.fortran_vec ();
+
+          for (octave_idx_type i = 0; i < idx_len; i++)
+            ivec[i] = i;
+
+          if (short_shuffle)
+            {
+              unordered_map<octave_idx_type, octave_idx_type> map (m);
+
+              // Perform the Knuth shuffle only keeping track of moved
+              // entries in the map
+              for (octave_idx_type i = 0; i < m; i++)
+                {
+                  octave_idx_type k = i +
+                    gnulib::floor (rvec[i] * (n - i));
+
+                  //For shuffling first m entries, no need to use extra
+                  //storage
+                  if (k < m)
+                    {
+                      std::swap (ivec[i], ivec[k]);
+                    }
+                  else
+                    {
+                      if (map.find (k) == map.end ())
+                        map[k] = k;
+
+                      std::swap (ivec[i], map[k]);
+                    }
+                }
+            }
+          else
+            {
+
+              // Perform the Knuth shuffle of the first m entries
+              for (octave_idx_type i = 0; i < m; i++)
+                {
+                  octave_idx_type k = i +
+                    gnulib::floor (rvec[i] * (n - i));
+                  std::swap (ivec[i], ivec[k]);
+                }
+            }
+
+          // Convert to doubles, reusing r.
+          for (octave_idx_type i = 0; i < m; i++)
+            rvec[i] = ivec[i] + 1;
+
+          if (m < n)
+            idx.resize (dim_vector (1, m));
+
+          // Now create an array object with a cached idx_vector.
+          retval = new octave_matrix (r, idx_vector (idx));
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!assert (sort (randperm (20)), 1:20)
+%!assert (length (randperm (20,10)), 10)
+
+%!test
+%! rand ("seed", 0);
+%! for i = 1:100
+%!   p = randperm (305, 30);
+%!   assert (length (unique (p)), 30);
+%! endfor
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/rcond.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,94 @@
+/*
+
+Copyright (C) 2008-2012 David Bateman
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+DEFUN (rcond, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{c} =} rcond (@var{A})\n\
+Compute the 1-norm estimate of the reciprocal condition number as returned\n\
+by @sc{lapack}.  If the matrix is well-conditioned then @var{c} will be near\n\
+1 and if the matrix is poorly conditioned it will be close to zero.\n\
+\n\
+The matrix @var{A} must not be sparse.  If the matrix is sparse then\n\
+@code{condest (@var{A})} or @code{rcond (full (@var{A}))} should be used\n\
+instead.\n\
+@seealso{cond, condest}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin != 1)
+    print_usage ();
+  else if (args(0).is_sparse_type ())
+    error ("rcond: for sparse matrices use 'rcond (full (a))' or 'condest (a)' instead");
+  else if (args(0).is_single_type ())
+    {
+      if (args(0).is_complex_type ())
+        {
+          FloatComplexMatrix m = args(0).float_complex_matrix_value ();
+          MatrixType mattyp;
+          retval = m.rcond (mattyp);
+          args(0).matrix_type (mattyp);
+        }
+      else
+        {
+          FloatMatrix m = args(0).float_matrix_value ();
+          MatrixType mattyp;
+          retval = m.rcond (mattyp);
+          args(0).matrix_type (mattyp);
+        }
+    }
+  else if (args(0).is_complex_type ())
+    {
+      ComplexMatrix m = args(0).complex_matrix_value ();
+      MatrixType mattyp;
+      retval = m.rcond (mattyp);
+      args(0).matrix_type (mattyp);
+    }
+  else
+    {
+      Matrix m = args(0).matrix_value ();
+      MatrixType mattyp;
+      retval = m.rcond (mattyp);
+      args(0).matrix_type (mattyp);
+    }
+
+  return retval;
+}
+
+/*
+%!assert (rcond (eye (2)), 1)
+%!assert (rcond (ones (2)), 0)
+%!assert (rcond ([1 1; 2 1]), 1/9)
+%!assert (rcond (magic (4)), 0, eps)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/regexp.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,1408 @@
+/*
+
+Copyright (C) 2005-2012 David Bateman
+Copyright (C) 2002-2005 Paul Kienzle
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <list>
+#include <sstream>
+
+#include <pcre.h>
+
+#include "base-list.h"
+#include "oct-locbuf.h"
+#include "quit.h"
+#include "regexp.h"
+#include "str-vec.h"
+
+#include "defun.h"
+#include "Cell.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-map.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+// Replace backslash escapes in a string with the real values.  We need
+// this special function instead of the one in utils.cc because the set
+// of escape sequences used in regexps is different from those used in
+// the *printf functions.
+
+static std::string
+do_regexp_string_escapes (const std::string& s)
+{
+  std::string retval;
+
+  size_t i = 0;
+  size_t j = 0;
+  size_t len = s.length ();
+
+  retval.resize (len);
+
+  while (j < len)
+    {
+      if (s[j] == '\\' && j+1 < len)
+        {
+          switch (s[++j])
+            {
+            case '$':
+              retval[i] = '$';
+              break;
+
+            case 'a':
+              retval[i] = '\a';
+              break;
+
+            case 'b': // backspace
+              retval[i] = '\b';
+              break;
+
+            case 'f': // formfeed
+              retval[i] = '\f';
+              break;
+
+            case 'n': // newline
+              retval[i] = '\n';
+              break;
+
+            case 'r': // carriage return
+              retval[i] = '\r';
+              break;
+
+            case 't': // horizontal tab
+              retval[i] = '\t';
+              break;
+
+            case 'v': // vertical tab
+              retval[i] = '\v';
+              break;
+
+            case '\\': // backslash
+              retval[i] = '\\';
+              break;
+
+#if 0
+// FIXME -- to be complete, we need to handle \oN, \o{N}, \xN, and
+// \x{N}.  Hex digits may be upper or lower case.  Brackets are
+// optional, so \x5Bz is the same as \x{5B}z.
+
+            case 'o': // octal number
+            case 'x': // hex number
+#endif
+
+            default:
+              retval[i] = '\\';
+              retval[++i] = s[j];
+              break;
+            }
+        }
+      else
+        {
+          retval[i] = s[j];
+        }
+
+      i++;
+      j++;
+    }
+
+  retval.resize (i);
+
+  return retval;
+}
+
+static void
+parse_options (regexp::opts& options, const octave_value_list& args,
+               const std::string& who, int skip, bool& extra_args)
+{
+  int nargin = args.length ();
+
+  extra_args = false;
+
+  for (int i = skip; i < nargin; i++)
+    {
+      std::string str = args(i).string_value ();
+
+      if (error_state)
+        {
+          error ("%s: optional arguments must be character strings",
+                 who.c_str ());
+          break;
+        }
+
+      std::transform (str.begin (), str.end (), str.begin (), tolower);
+
+      if (str.find ("once", 0) == 0)
+        options.once (true);
+      else if (str.find ("matchcase", 0) == 0)
+        options.case_insensitive (false);
+      else if (str.find ("ignorecase", 0) == 0)
+        options.case_insensitive (true);
+      else if (str.find ("dotall", 0) == 0)
+        options.dotexceptnewline (false);
+      else if (str.find ("stringanchors", 0) == 0)
+        options.lineanchors (false);
+      else if (str.find ("literalspacing", 0) == 0)
+        options.freespacing (false);
+      else if (str.find ("noemptymatch", 0) == 0)
+        options.emptymatch (false);
+      else if (str.find ("dotexceptnewline", 0) == 0)
+        options.dotexceptnewline (true);
+      else if (str.find ("lineanchors", 0) == 0)
+        options.lineanchors (true);
+      else if (str.find ("freespacing", 0) == 0)
+        options.freespacing (true);
+      else if (str.find ("emptymatch", 0) == 0)
+        options.emptymatch (true);
+      else if (str.find ("start", 0) == 0
+               || str.find ("end", 0) == 0
+               || str.find ("tokenextents", 0) == 0
+               || str.find ("match", 0) == 0
+               || str.find ("tokens", 0) == 0
+               || str.find ("names", 0) == 0
+               || str.find ("split", 0) == 0)
+        extra_args = true;
+      else
+        error ("%s: unrecognized option", who.c_str ());
+    }
+}
+
+static octave_value_list
+octregexp (const octave_value_list &args, int nargout,
+           const std::string &who, bool case_insensitive = false)
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  // Make sure we have string, pattern
+  const std::string buffer = args(0).string_value ();
+  if (error_state)
+    return retval;
+
+  std::string pattern = args(1).string_value ();
+  if (error_state)
+    return retval;
+  // Matlab compatibility.
+  if (args(1).is_sq_string ())
+    pattern = do_regexp_string_escapes (pattern);
+
+  regexp::opts options;
+  options.case_insensitive (case_insensitive);
+  bool extra_options = false;
+  parse_options (options, args, who, 2, extra_options);
+  if (error_state)
+    return retval;
+
+  regexp::match_data rx_lst = regexp_match (pattern, buffer, options, who);
+
+  string_vector named_pats = rx_lst.named_patterns ();
+
+  size_t sz = rx_lst.size ();
+
+  if (! error_state)
+    {
+      // Converted the linked list in the correct form for the return values
+
+      octave_idx_type i = 0;
+      octave_scalar_map nmap;
+
+      retval.resize (7);
+
+      if (sz == 1)
+        {
+          string_vector named_tokens = rx_lst.begin ()->named_tokens ();
+
+          for (int j = 0; j < named_pats.length (); j++)
+            nmap.assign (named_pats(j), named_tokens(j));
+
+          retval(5) = nmap;
+        }
+      else
+        {
+          for (int j = 0; j < named_pats.length (); j++)
+            {
+              Cell tmp (dim_vector (1, sz));
+
+              i = 0;
+              for (regexp::match_data::const_iterator p = rx_lst.begin ();
+                   p != rx_lst.end (); p++)
+                {
+                  string_vector named_tokens = p->named_tokens ();
+
+                  tmp(i++) = named_tokens(j);
+                }
+
+              nmap.assign (named_pats(j), octave_value (tmp));
+            }
+
+          retval(5) = nmap;
+        }
+
+      if (options.once ())
+        {
+          regexp::match_data::const_iterator p = rx_lst.begin ();
+
+          retval(4) = sz ? p->tokens () : Cell ();
+          retval(3) = sz ? p->match_string () : std::string ();
+          retval(2) = sz ? p->token_extents () : Matrix ();
+
+          if (sz)
+            {
+              double start = p->start ();
+              double end = p->end ();
+
+              Cell split (dim_vector (1, 2));
+              split(0) = buffer.substr (0, start-1);
+              split(1) = buffer.substr (end);
+
+              retval(6) = split;
+              retval(1) = end;
+              retval(0) = start;
+            }
+          else
+            {
+              retval(6) = buffer;
+              retval(1) = Matrix ();
+              retval(0) = Matrix ();
+            }
+        }
+      else
+        {
+          Cell tokens (dim_vector (1, sz));
+          Cell match_string (dim_vector (1, sz));
+          Cell token_extents (dim_vector (1, sz));
+          NDArray end (dim_vector (1, sz));
+          NDArray start (dim_vector (1, sz));
+          Cell split (dim_vector (1, sz+1));
+          size_t sp_start = 0;
+
+          i = 0;
+          for (regexp::match_data::const_iterator p = rx_lst.begin ();
+               p != rx_lst.end (); p++)
+            {
+              double s = p->start ();
+              double e = p->end ();
+
+              string_vector tmp = p->tokens ();
+              tokens(i) = Cell (dim_vector (1, tmp.length ()), tmp);
+              match_string(i) = p->match_string ();
+              token_extents(i) = p->token_extents ();
+              end(i) = e;
+              start(i) = s;
+              split(i) = buffer.substr (sp_start, s-sp_start-1);
+              sp_start = e;
+              i++;
+            }
+
+          split(i) = buffer.substr (sp_start);
+
+          retval(6) = split;
+          retval(4) = tokens;
+          retval(3) = match_string;
+          retval(2) = token_extents;
+          retval(1) = end;
+          retval(0) = start;
+        }
+
+      // Alter the order of the output arguments
+
+      if (extra_options)
+        {
+          int n = 0;
+          octave_value_list new_retval;
+          new_retval.resize (nargout);
+
+          OCTAVE_LOCAL_BUFFER (int, arg_used, 6);
+          for (int j = 0; j < 6; j++)
+            arg_used[j] = false;
+
+          for (int j = 2; j < nargin; j++)
+            {
+              int k = 0;
+              std::string str = args(j).string_value ();
+              std::transform (str.begin (), str.end (), str.begin (), tolower);
+
+              if (str.find ("once", 0) == 0
+                  || str.find ("stringanchors", 0) == 0
+                  || str.find ("lineanchors", 0) == 0
+                  || str.find ("matchcase", 0) == 0
+                  || str.find ("ignorecase", 0) == 0
+                  || str.find ("dotall", 0) == 0
+                  || str.find ("dotexceptnewline", 0) == 0
+                  || str.find ("literalspacing", 0) == 0
+                  || str.find ("freespacing", 0) == 0
+                  || str.find ("noemptymatch", 0) == 0
+                  || str.find ("emptymatch", 0) == 0)
+                continue;
+              else if (str.find ("start", 0) == 0)
+                k = 0;
+              else if (str.find ("end", 0) == 0)
+                k = 1;
+              else if (str.find ("tokenextents", 0) == 0)
+                k = 2;
+              else if (str.find ("match", 0) == 0)
+                k = 3;
+              else if (str.find ("tokens", 0) == 0)
+                k = 4;
+              else if (str.find ("names", 0) == 0)
+                k = 5;
+              else if (str.find ("split", 0) == 0)
+                k = 6;
+
+              new_retval(n++) = retval(k);
+              arg_used[k] = true;
+
+              if (n == nargout)
+                break;
+            }
+
+          // Fill in the rest of the arguments
+          if (n < nargout)
+            {
+              for (int j = 0; j < 6; j++)
+                {
+                  if (! arg_used[j])
+                    new_retval(n++) = retval(j);
+                }
+            }
+
+          retval = new_retval;
+        }
+    }
+
+  return retval;
+}
+
+static octave_value_list
+octcellregexp (const octave_value_list &args, int nargout,
+               const std::string &who, bool case_insensitive = false)
+{
+  octave_value_list retval;
+
+  if (args(0).is_cell ())
+    {
+      OCTAVE_LOCAL_BUFFER (Cell, newretval, nargout);
+      octave_value_list new_args = args;
+      Cell cellstr = args(0).cell_value ();
+      if (args(1).is_cell ())
+        {
+          Cell cellpat = args(1).cell_value ();
+
+          if (cellpat.numel () == 1)
+            {
+              for (int j = 0; j < nargout; j++)
+                newretval[j].resize (cellstr.dims ());
+
+              new_args(1) = cellpat(0);
+
+              for (octave_idx_type i = 0; i < cellstr.numel (); i++)
+                {
+                  new_args(0) = cellstr(i);
+                  octave_value_list tmp = octregexp (new_args, nargout, who,
+                                                     case_insensitive);
+
+                  if (error_state)
+                    break;
+
+                  for (int j = 0; j < nargout; j++)
+                    newretval[j](i) = tmp(j);
+                }
+            }
+          else if (cellstr.numel () == 1)
+            {
+              for (int j = 0; j < nargout; j++)
+                newretval[j].resize (cellpat.dims ());
+
+              new_args(0) = cellstr(0);
+
+              for (octave_idx_type i = 0; i < cellpat.numel (); i++)
+                {
+                  new_args(1) = cellpat(i);
+                  octave_value_list tmp = octregexp (new_args, nargout, who,
+                                                     case_insensitive);
+
+                  if (error_state)
+                    break;
+
+                  for (int j = 0; j < nargout; j++)
+                    newretval[j](i) = tmp(j);
+                }
+            }
+          else if (cellstr.numel () == cellpat.numel ())
+            {
+
+              if (cellstr.dims () != cellpat.dims ())
+                error ("%s: inconsistent cell array dimensions", who.c_str ());
+              else
+                {
+                  for (int j = 0; j < nargout; j++)
+                    newretval[j].resize (cellstr.dims ());
+
+                  for (octave_idx_type i = 0; i < cellstr.numel (); i++)
+                    {
+                      new_args(0) = cellstr(i);
+                      new_args(1) = cellpat(i);
+
+                      octave_value_list tmp = octregexp (new_args, nargout, who,
+                                                         case_insensitive);
+
+                      if (error_state)
+                        break;
+
+                      for (int j = 0; j < nargout; j++)
+                        newretval[j](i) = tmp(j);
+                    }
+                }
+            }
+          else
+            error ("regexp: cell array arguments must be scalar or equal size");
+        }
+      else
+        {
+          for (int j = 0; j < nargout; j++)
+            newretval[j].resize (cellstr.dims ());
+
+          for (octave_idx_type i = 0; i < cellstr.numel (); i++)
+            {
+              new_args(0) = cellstr(i);
+              octave_value_list tmp = octregexp (new_args, nargout, who,
+                                                 case_insensitive);
+
+              if (error_state)
+                break;
+
+              for (int j = 0; j < nargout; j++)
+                newretval[j](i) = tmp(j);
+            }
+        }
+
+      if (!error_state)
+        for (int j = 0; j < nargout; j++)
+          retval(j) = octave_value (newretval[j]);
+    }
+  else if (args(1).is_cell ())
+    {
+      OCTAVE_LOCAL_BUFFER (Cell, newretval, nargout);
+      octave_value_list new_args = args;
+      Cell cellpat = args(1).cell_value ();
+
+      for (int j = 0; j < nargout; j++)
+        newretval[j].resize (cellpat.dims ());
+
+      for (octave_idx_type i = 0; i < cellpat.numel (); i++)
+        {
+          new_args(1) = cellpat(i);
+          octave_value_list tmp = octregexp (new_args, nargout, who,
+                                             case_insensitive);
+
+          if (error_state)
+            break;
+
+          for (int j = 0; j < nargout; j++)
+            newretval[j](i) = tmp(j);
+        }
+
+      if (!error_state)
+        {
+          for (int j = 0; j < nargout; j++)
+            retval(j) = octave_value (newretval[j]);
+        }
+    }
+  else
+    retval = octregexp (args, nargout, who, case_insensitive);
+
+  return retval;
+
+}
+
+DEFUN (regexp, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexp (@var{str}, @var{pat})\n\
+@deftypefnx {Built-in Function} {[@dots{}] =} regexp (@var{str}, @var{pat}, \"@var{opt1}\", @dots{})\n\
+Regular expression string matching.  Search for @var{pat} in @var{str} and\n\
+return the positions and substrings of any matches, or empty values if there\n\
+are none.\n\
+\n\
+The matched pattern @var{pat} can include any of the standard regex\n\
+operators, including:\n\
+\n\
+@table @code\n\
+@item .\n\
+Match any character\n\
+\n\
+@item * + ? @{@}\n\
+Repetition operators, representing\n\
+\n\
+@table @code\n\
+@item *\n\
+Match zero or more times\n\
+\n\
+@item +\n\
+Match one or more times\n\
+\n\
+@item ?\n\
+Match zero or one times\n\
+\n\
+@item @{@var{n}@}\n\
+Match exactly @var{n} times\n\
+\n\
+@item @{@var{n},@}\n\
+Match @var{n} or more times\n\
+\n\
+@item @{@var{m},@var{n}@}\n\
+Match between @var{m} and @var{n} times\n\
+@end table\n\
+\n\
+@item [@dots{}] [^@dots{}]\n\
+\n\
+List operators.  The pattern will match any character listed between \"[\"\n\
+and \"]\".  If the first character is \"^\" then the pattern is inverted and\n\
+any character except those listed between brackets will match.\n\
+\n\
+Escape sequences defined below can also be used inside list\n\
+operators.  For example, a template for a floating point number might be\n\
+@code{[-+.\\d]+}.\n\
+\n\
+@item () (?:)\n\
+Grouping operator.  The first form, parentheses only, also creates a token.\n\
+\n\
+@item |\n\
+Alternation operator.  Match one of a choice of regular expressions.  The\n\
+alternatives must be delimited by the grouping operator @code{()} above.\n\
+\n\
+@item ^ $\n\
+Anchoring operators.  Requires pattern to occur at the start (@code{^}) or\n\
+end (@code{$}) of the string.\n\
+@end table\n\
+\n\
+In addition, the following escaped characters have special meaning.  Note,\n\
+it is recommended to quote @var{pat} in single quotes, rather than double\n\
+quotes, to avoid the escape sequences being interpreted by Octave before\n\
+being passed to @code{regexp}.\n\
+\n\
+@table @code\n\
+@item \\b\n\
+Match a word boundary\n\
+\n\
+@item \\B\n\
+Match within a word\n\
+\n\
+@item \\w\n\
+Match any word character\n\
+\n\
+@item \\W\n\
+Match any non-word character\n\
+\n\
+@item \\<\n\
+Match the beginning of a word\n\
+\n\
+@item \\>\n\
+Match the end of a word\n\
+\n\
+@item \\s\n\
+Match any whitespace character\n\
+\n\
+@item \\S\n\
+Match any non-whitespace character\n\
+\n\
+@item \\d\n\
+Match any digit\n\
+\n\
+@item \\D\n\
+Match any non-digit\n\
+@end table\n\
+\n\
+The outputs of @code{regexp} default to the order given below\n\
+\n\
+@table @var\n\
+@item s\n\
+The start indices of each matching substring\n\
+\n\
+@item e\n\
+The end indices of each matching substring\n\
+\n\
+@item te\n\
+The extents of each matched token surrounded by @code{(@dots{})} in\n\
+@var{pat}\n\
+\n\
+@item m\n\
+A cell array of the text of each match\n\
+\n\
+@item t\n\
+A cell array of the text of each token matched\n\
+\n\
+@item nm\n\
+A structure containing the text of each matched named token, with the name\n\
+being used as the fieldname.  A named token is denoted by\n\
+@code{(?<name>@dots{})}.\n\
+\n\
+@item sp\n\
+A cell array of the text not returned by match, i.e., what remains if you\n\
+split the string based on @var{pat}.\n\
+@end table\n\
+\n\
+Particular output arguments, or the order of the output arguments, can be\n\
+selected by additional @var{opt} arguments.  These are strings and the\n\
+correspondence between the output arguments and the optional argument\n\
+are\n\
+\n\
+@multitable @columnfractions 0.2 0.3 0.3 0.2\n\
+@item @tab 'start'        @tab @var{s}  @tab\n\
+@item @tab 'end'          @tab @var{e}  @tab\n\
+@item @tab 'tokenExtents' @tab @var{te} @tab\n\
+@item @tab 'match'        @tab @var{m}  @tab\n\
+@item @tab 'tokens'       @tab @var{t}  @tab\n\
+@item @tab 'names'        @tab @var{nm} @tab\n\
+@item @tab 'split'        @tab @var{sp} @tab\n\
+@end multitable\n\
+\n\
+Additional arguments are summarized below.\n\
+\n\
+@table @samp\n\
+@item once\n\
+Return only the first occurrence of the pattern.\n\
+\n\
+@item matchcase\n\
+Make the matching case sensitive.  (default)\n\
+\n\
+Alternatively, use (?-i) in the pattern.\n\
+\n\
+@item ignorecase\n\
+Ignore case when matching the pattern to the string.\n\
+\n\
+Alternatively, use (?i) in the pattern.\n\
+\n\
+@item stringanchors\n\
+Match the anchor characters at the beginning and end of the string.\n\
+(default)\n\
+\n\
+Alternatively, use (?-m) in the pattern.\n\
+\n\
+@item lineanchors\n\
+Match the anchor characters at the beginning and end of the line.\n\
+\n\
+Alternatively, use (?m) in the pattern.\n\
+\n\
+@item dotall\n\
+The pattern @code{.} matches all characters including the newline character.\n\
+ (default)\n\
+\n\
+Alternatively, use (?s) in the pattern.\n\
+\n\
+@item dotexceptnewline\n\
+The pattern @code{.} matches all characters except the newline character.\n\
+\n\
+Alternatively, use (?-s) in the pattern.\n\
+\n\
+@item literalspacing\n\
+All characters in the pattern, including whitespace, are significant and are\n\
+used in pattern matching.  (default)\n\
+\n\
+Alternatively, use (?-x) in the pattern.\n\
+\n\
+@item freespacing\n\
+The pattern may include arbitrary whitespace and also comments beginning with\n\
+the character @samp{#}.\n\
+\n\
+Alternatively, use (?x) in the pattern.\n\
+\n\
+@item noemptymatch\n\
+Zero-length matches are not returned.  (default)\n\
+\n\
+@item emptymatch\n\
+Return zero-length matches.\n\
+\n\
+@code{regexp ('a', 'b*', 'emptymatch'} returns @code{[1 2]} because there are\n\
+zero or more 'b' characters at positions 1 and end-of-string.\n\
+\n\
+@end table\n\
+@seealso{regexpi, strfind, regexprep}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 2)
+    print_usage ();
+  else if (args(0).is_cell () || args(1).is_cell ())
+    retval = octcellregexp (args, (nargout > 0 ? nargout : 1), "regexp");
+  else
+    retval = octregexp (args, nargout, "regexp");
+
+  return retval;
+}
+
+/*
+## PCRE_ERROR_MATCHLIMIT test
+%!test
+%! s = sprintf ('\t4\n0000\t-0.00\t-0.0000\t4\t-0.00\t-0.0000\t4\n0000\t-0.00\t-0.0000\t0\t-0.00\t-');
+%! ws = warning ("query");
+%! unwind_protect
+%!   warning ("off");
+%!   regexp (s, '(\s*-*\d+[.]*\d*\s*)+\n');
+%! unwind_protect_cleanup
+%!   warning (ws);
+%! end_unwind_protect
+
+## segfault test
+%!assert (regexp ("abcde", "."), [1,2,3,4,5])
+## Infinite loop test
+%!assert (isempty (regexp ("abcde", "")))
+
+## Check that anchoring of pattern works correctly
+%!assert (regexp ('abcabc', '^abc'), 1)
+%!assert (regexp ('abcabc', 'abc$'), 4)
+%!assert (regexp ('abcabc', '^abc$'), zeros (1,0))
+
+%!test
+%! [s, e, te, m, t] = regexp (' No Match ', 'f(.*)uck');
+%! assert (s, zeros (1,0));
+%! assert (e, zeros (1,0));
+%! assert (te, cell (1,0));
+%! assert (m, cell (1,0));
+%! assert (t, cell (1,0));
+
+%!test
+%! [s, e, te, m, t] = regexp (' FiRetrUck ', 'f(.*)uck');
+%! assert (s, zeros (1,0));
+%! assert (e, zeros (1,0));
+%! assert (te, cell (1,0));
+%! assert (m, cell (1,0));
+%! assert (t, cell (1,0));
+
+%!test
+%! [s, e, te, m, t] = regexp (' firetruck ', 'f(.*)uck');
+%! assert (s, 2);
+%! assert (e, 10);
+%! assert (te{1}, [3, 7]);
+%! assert (m{1}, 'firetruck');
+%! assert (t{1}{1}, 'iretr');
+
+%!test
+%! [s, e, te, m, t] = regexp ('short test string', '\w*r\w*');
+%! assert (s, [1, 12]);
+%! assert (e, [5, 17]);
+%! assert (size (te), [1, 2]);
+%! assert (isempty (te{1}));
+%! assert (isempty (te{2}));
+%! assert (m{1}, 'short');
+%! assert (m{2}, 'string');
+%! assert (size (t), [1, 2]);
+%! assert (isempty (t{1}));
+%! assert (isempty (t{2}));
+
+%!test
+%! [s, e, te, m, t] = regexp ('short test string', '\w*r\w*', 'once');
+%! assert (s, 1);
+%! assert (e, 5);
+%! assert (isempty (te));
+%! assert (m, 'short');
+%! assert (isempty (t));
+
+%!test
+%! [m, te, e, s, t] = regexp ('short test string', '\w*r\w*', 'once', 'match', 'tokenExtents', 'end', 'start', 'tokens');
+%! assert (s, 1);
+%! assert (e, 5);
+%! assert (isempty (te));
+%! assert (m, 'short');
+%! assert (isempty (t));
+
+%!test
+%! [s, e, te, m, t, nm] = regexp ('short test string', '(?<word1>\w*t)\s*(?<word2>\w*t)');
+%! assert (s, 1);
+%! assert (e, 10);
+%! assert (size (te), [1, 1]);
+%! assert (te{1}, [1,5; 7,10]);
+%! assert (m{1}, 'short test');
+%! assert (size (t), [1, 1]);
+%! assert (t{1}{1}, 'short');
+%! assert (t{1}{2}, 'test');
+%! assert (size (nm), [1, 1]);
+%! assert (! isempty (fieldnames (nm)));
+%! assert (sort (fieldnames (nm)), {'word1';'word2'});
+%! assert (nm.word1, 'short');
+%! assert (nm.word2, 'test');
+
+%!test
+%! [nm, m, te, e, s, t] = regexp ('short test string', '(?<word1>\w*t)\s*(?<word2>\w*t)', 'names', 'match', 'tokenExtents', 'end', 'start', 'tokens');
+%! assert (s, 1);
+%! assert (e, 10);
+%! assert (size (te), [1, 1]);
+%! assert (te{1}, [1,5; 7,10]);
+%! assert (m{1}, 'short test');
+%! assert (size (t), [1, 1]);
+%! assert (t{1}{1}, 'short');
+%! assert (t{1}{2}, 'test');
+%! assert (size (nm), [1, 1]);
+%! assert (!isempty (fieldnames (nm)));
+%! assert (sort (fieldnames (nm)), {'word1';'word2'});
+%! assert (nm.word1, 'short');
+%! assert (nm.word2, 'test');
+
+%!test
+%! [t, nm] = regexp ("John Davis\nRogers, James", '(?<first>\w+)\s+(?<last>\w+)|(?<last>\w+),\s+(?<first>\w+)', 'tokens', 'names');
+%! assert (size (t), [1, 2]);
+%! assert (t{1}{1}, 'John');
+%! assert (t{1}{2}, 'Davis');
+%! assert (t{2}{1}, 'Rogers');
+%! assert (t{2}{2}, 'James');
+%! assert (size (nm), [1, 1]);
+%! assert (nm.first{1}, 'John');
+%! assert (nm.first{2}, 'James');
+%! assert (nm.last{1}, 'Davis');
+%! assert (nm.last{2}, 'Rogers');
+
+## Tests for named tokens
+%!test
+%! # Parenthesis in named token (ie (int)) causes a problem
+%! assert (regexp ('qwe int asd', ['(?<typestr>(int))'], 'names'), struct ('typestr', 'int'));
+
+%!test
+%! ## Mix of named and unnamed tokens can cause segfault (bug #35683)
+%! str = "abcde";
+%! ptn = '(?<T1>a)(\w+)(?<T2>d\w+)';
+%! tokens = regexp (str, ptn, "names");
+%! assert (isstruct (tokens) && numel (tokens) == 1);
+%! assert (tokens.T1, "a");
+%! assert (tokens.T2, "de");
+
+%!assert (regexp ("abc\nabc", '.'), [1:7])
+%!assert (regexp ("abc\nabc", '.', 'dotall'), [1:7])
+%!test
+%! assert (regexp ("abc\nabc", '(?s).'), [1:7]);
+%! assert (regexp ("abc\nabc", '.', 'dotexceptnewline'), [1,2,3,5,6,7]);
+%! assert (regexp ("abc\nabc", '(?-s).'), [1,2,3,5,6,7]);
+
+%!assert (regexp ("caseCaSe", 'case'), 1)
+%!assert (regexp ("caseCaSe", 'case', "matchcase"), 1)
+%!assert (regexp ("caseCaSe", 'case', "ignorecase"), [1,5])
+%!test
+%! assert (regexp ("caseCaSe", '(?-i)case'), 1);
+%! assert (regexp ("caseCaSe", '(?i)case'), [1, 5]);
+
+%!assert (regexp ("abc\nabc", 'c$'), 7)
+%!assert (regexp ("abc\nabc", 'c$', "stringanchors"), 7)
+%!test
+%! assert (regexp ("abc\nabc", '(?-m)c$'), 7);
+%! assert (regexp ("abc\nabc", 'c$',"lineanchors"), [3, 7]);
+%! assert (regexp ("abc\nabc", '(?m)c$'), [3,7]);
+
+%!assert (regexp ("this word", 's w'), 4)
+%!assert (regexp ("this word", 's w', 'literalspacing'), 4)
+%!test
+%! assert (regexp ("this word", '(?-x)s w', 'literalspacing'), 4);
+%! assert (regexp ("this word", 's w', 'freespacing'), zeros (1,0));
+%! assert (regexp ("this word", '(?x)s w'), zeros (1,0));
+
+%!test
+%! [s, e, te, m, t, nm, sp] = regexp ('OCTAVE', '[VOCT]*', 'noemptymatch');
+%! assert (s, [1 5]);
+%! assert (e, [3 5]);
+%! assert (te, { zeros(0,2), zeros(0,2) });
+%! assert (m, { "OCT", "V" });
+%! assert (t, { cell(1,0), cell(1,0) });
+%! assert (isempty (fieldnames (nm)));
+%! assert (sp, { "", "A", "E" });
+
+%!test
+%! [s, e, te, m, t, nm, sp] = regexp ('OCTAVE', '([VOCT]*)', 'noemptymatch');
+%! assert (s, [1 5]);
+%! assert (e, [3 5]);
+%! assert (te, { [1 3], [5 5] });
+%! assert (m, { "OCT", "V" });
+%! assert (t, { {"OCT"}, {"V"} });
+%! assert (isempty (fieldnames (nm)));
+%! assert (sp, { "", "A", "E" });
+
+%!test
+%! [s, e, te, m, t, nm, sp] = regexp ('OCTAVE', '[VOCT]*', 'emptymatch');
+%! assert (s, [1 4 5 6 7]);
+%! assert (e, [3 3 5 5 6]);
+%! assert (te, repmat ({zeros(0,2)}, [1, 5]));
+%! assert (m, { "OCT", "", "V", "", "" });
+%! assert (t, repmat({cell(1,0)}, [1, 5]));
+%! assert (isempty (fieldnames (nm)));
+%! assert (sp, { "", "", "A", "", "E", "" });
+
+%!test
+%! [s, e, te, m, t, nm, sp] = regexp ('OCTAVE', '([VOCT]*)', 'emptymatch');
+%! assert (s, [1 4 5 6 7]);
+%! assert (e, [3 3 5 5 6]);
+%! assert (te, { [1 3], [4 3], [5 5], [6 5], [7 6] });
+%! assert (m, { "OCT", "", "V", "", "" });
+%! assert (t, { {"OCT"}, {""}, {"V"}, {""}, {""} });
+%! assert (isempty (fieldnames (nm)));
+%! assert (sp, { "", "", "A", "", "E", "" });
+
+%!error regexp ('string', 'tri', 'BadArg')
+%!error regexp ('string')
+
+%!assert (regexp ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, '-'), {6;[1,5,9];zeros(1,0)})
+%!assert (regexp ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, {'-';'f';'q'}), {6;[3,7];[1,9]})
+%!assert (regexp ('Strings', {'t','s'}), {2, 7})
+
+## Test case for lookaround operators
+%!test
+%! assert (regexp ('Iraq', 'q(?!u)'), 4);
+%! assert (regexp ('quit', 'q(?!u)'), zeros (1, 0));
+%! assert (regexp ('quit', 'q(?=u)' , 'match'), {'q'});
+%! assert (regexp ("quit", 'q(?=u+)', 'match'), {'q'});
+%! assert (regexp ("qit",  'q(?=u+)', 'match'), cell (1, 0));
+%! assert (regexp ("qit",  'q(?=u*)', 'match'), {'q'});
+%! assert (regexp ('thingamabob', '(?<=a)b'), 9);
+
+## Tests for split option.
+%!shared str
+%! str = "foo bar foo";
+%!test
+%! [a, b] = regexp (str, "f..", "match", "split");
+%! assert (a, {"foo", "foo"});
+%! assert (b, {"", " bar ", ""});
+%!test
+%! [a, b] = regexp (str, "f..", "match", "split", "once");
+%! assert (a, "foo");
+%! assert (b, {"", " bar foo"});
+%!test
+%! [a, b] = regexp (str, "fx.", "match", "split");
+%! assert (a, cell (1, 0));
+%! assert (b, {"foo bar foo"});
+%!test
+%! [a, b] = regexp (str, "fx.", "match", "split", "once");
+%! assert (a, "");;
+%! assert (b, "foo bar foo");
+
+%!shared str
+%! str = "foo bar";
+%!test
+%! [a, b] = regexp (str, "f..", "match", "split");
+%! assert (a, {"foo"});
+%! assert (b, {"", " bar"});
+%!test
+%! [a, b] = regexp (str, "b..", "match", "split");
+%! assert (a, {"bar"});
+%! assert (b, {"foo ", ""});
+%!test
+%! [a, b] = regexp (str, "x", "match", "split");
+%! assert (a, cell (1, 0));
+%! assert (b, {"foo bar"});
+%!test
+%! [a, b] = regexp (str, "[o]+", "match", "split");
+%! assert (a, {"oo"});
+%! assert (b, {"f", " bar"});
+
+%!assert (regexp ("\n", '\n'), 1);
+%!assert (regexp ("\n", "\n"), 1);
+*/
+
+DEFUN (regexpi, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexpi (@var{str}, @var{pat})\n\
+@deftypefnx {Built-in Function} {[@dots{}] =} regexpi (@var{str}, @var{pat}, \"@var{opt1}\", @dots{})\n\
+\n\
+Case insensitive regular expression string matching.  Search for @var{pat} in\n\
+@var{str} and return the positions and substrings of any matches, or empty\n\
+values if there are none.  @xref{doc-regexp,,regexp}, for details on the\n\
+syntax of the search pattern.\n\
+@seealso{regexp}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 2)
+    print_usage ();
+  else if (args(0).is_cell () || args(1).is_cell ())
+    retval = octcellregexp (args, (nargout > 0 ? nargout : 1), "regexpi", true);
+  else
+    retval = octregexp (args, nargout, "regexpi", true);
+
+  return retval;
+}
+
+/*
+## segfault test
+%!assert (regexpi ("abcde", "."), [1,2,3,4,5])
+
+## Check that anchoring of pattern works correctly
+%!assert (regexpi ('abcabc', '^ABC'), 1)
+%!assert (regexpi ('abcabc', 'ABC$'), 4)
+%!assert (regexpi ('abcabc', '^ABC$'), zeros (1,0))
+
+%!test
+%! [s, e, te, m, t] = regexpi (' No Match ', 'f(.*)uck');
+%! assert (s, zeros (1,0));
+%! assert (e, zeros (1,0));
+%! assert (te, cell (1,0));
+%! assert (m, cell (1,0));
+%! assert (t, cell (1,0));
+
+%!test
+%! [s, e, te, m, t] = regexpi (' FiRetrUck ', 'f(.*)uck');
+%! assert (s, 2);
+%! assert (e, 10);
+%! assert (te{1}, [3, 7]);
+%! assert (m{1}, 'FiRetrUck');
+%! assert (t{1}{1}, 'iRetr');
+
+%!test
+%! [s, e, te, m, t] = regexpi (' firetruck ', 'f(.*)uck');
+%! assert (s, 2);
+%! assert (e, 10);
+%! assert (te{1}, [3, 7]);
+%! assert (m{1}, 'firetruck');
+%! assert (t{1}{1}, 'iretr');
+
+%!test
+%! [s, e, te, m, t] = regexpi ('ShoRt Test String', '\w*r\w*');
+%! assert (s, [1, 12]);
+%! assert (e, [5, 17]);
+%! assert (size (te), [1, 2]);
+%! assert (isempty (te{1}));
+%! assert (isempty (te{2}));
+%! assert (m{1}, 'ShoRt');
+%! assert (m{2}, 'String');
+%! assert (size (t), [1, 2]);
+%! assert (isempty (t{1}));
+%! assert (isempty (t{2}));
+
+%!test
+%! [s, e, te, m, t] = regexpi ('ShoRt Test String', '\w*r\w*', 'once');
+%! assert (s, 1);
+%! assert (e, 5);
+%! assert (isempty (te));
+%! assert (m, 'ShoRt');
+%! assert (isempty (t));
+
+%!test
+%! [m, te, e, s, t] = regexpi ('ShoRt Test String', '\w*r\w*', 'once', 'match', 'tokenExtents', 'end', 'start', 'tokens');
+%! assert (s, 1);
+%! assert (e, 5);
+%! assert (isempty (te));
+%! assert (m, 'ShoRt');
+%! assert (isempty (t));
+
+%!test
+%! [s, e, te, m, t, nm] = regexpi ('ShoRt Test String', '(?<word1>\w*t)\s*(?<word2>\w*t)');
+%! assert (s, 1);
+%! assert (e, 10);
+%! assert (size (te), [1, 1]);
+%! assert (te{1}, [1,5; 7,10]);
+%! assert (m{1}, 'ShoRt Test');
+%! assert (size (t), [1, 1]);
+%! assert (t{1}{1}, 'ShoRt');
+%! assert (t{1}{2}, 'Test');
+%! assert (size (nm), [1, 1]);
+%! assert (! isempty (fieldnames (nm)));
+%! assert (sort (fieldnames (nm)), {'word1';'word2'});
+%! assert (nm.word1, 'ShoRt');
+%! assert (nm.word2, 'Test');
+
+%!test
+%! [nm, m, te, e, s, t] = regexpi ('ShoRt Test String', '(?<word1>\w*t)\s*(?<word2>\w*t)', 'names', 'match', 'tokenExtents', 'end', 'start', 'tokens');
+%! assert (s, 1);
+%! assert (e, 10);
+%! assert (size (te), [1, 1]);
+%! assert (te{1}, [1,5; 7,10]);
+%! assert (m{1}, 'ShoRt Test');
+%! assert (size (t), [1, 1]);
+%! assert (t{1}{1}, 'ShoRt');
+%! assert (t{1}{2}, 'Test');
+%! assert (size (nm), [1, 1]);
+%! assert (!isempty (fieldnames (nm)));
+%! assert (sort (fieldnames (nm)), {'word1';'word2'});
+%! assert (nm.word1, 'ShoRt');
+%! assert (nm.word2, 'Test');
+
+%!assert (regexpi ("abc\nabc", '.'), [1:7])
+%!assert (regexpi ("abc\nabc", '.', 'dotall'), [1:7])
+%!test
+%! assert (regexpi ("abc\nabc", '(?s).'), [1:7]);
+%! assert (regexpi ("abc\nabc", '.', 'dotexceptnewline'), [1,2,3,5,6,7]);
+%! assert (regexpi ("abc\nabc", '(?-s).'), [1,2,3,5,6,7]);
+
+%!assert (regexpi ("caseCaSe", 'case'), [1, 5])
+%!assert (regexpi ("caseCaSe", 'case', "matchcase"), 1)
+%!assert (regexpi ("caseCaSe", 'case', "ignorecase"), [1, 5])
+%!test
+%! assert (regexpi ("caseCaSe", '(?-i)case'), 1);
+%! assert (regexpi ("caseCaSe", '(?i)case'), [1, 5]);
+
+%!assert (regexpi ("abc\nabc", 'C$'), 7)
+%!assert (regexpi ("abc\nabc", 'C$', "stringanchors"), 7)
+%!test
+%! assert (regexpi ("abc\nabc", '(?-m)C$'), 7);
+%! assert (regexpi ("abc\nabc", 'C$', "lineanchors"), [3, 7]);
+%! assert (regexpi ("abc\nabc", '(?m)C$'), [3, 7]);
+
+%!assert (regexpi ("this word", 'S w'), 4)
+%!assert (regexpi ("this word", 'S w', 'literalspacing'), 4)
+%!test
+%! assert (regexpi ("this word", '(?-x)S w', 'literalspacing'), 4);
+%! assert (regexpi ("this word", 'S w', 'freespacing'), zeros (1,0));
+%! assert (regexpi ("this word", '(?x)S w'), zeros (1,0));
+
+%!error regexpi ('string', 'tri', 'BadArg')
+%!error regexpi ('string')
+
+%!assert (regexpi ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, '-'), {6;[1,5,9];zeros(1, 0)})
+%!assert (regexpi ({'asdfg-dfd', '-dfd-dfd-', 'qasfdfdaq'}, '-'), {6, [1,5,9], zeros(1,0)})
+%!assert (regexpi ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, {'-';'f';'q'}), {6;[3,7];[1,9]})
+%!assert (regexpi ('Strings', {'t', 's'}), {2, [1, 7]})
+
+%!assert (regexpi ("\n", '\n'), 1);
+%!assert (regexpi ("\n", "\n"), 1);
+*/
+
+static octave_value
+octregexprep (const octave_value_list &args, const std::string &who)
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  // Make sure we have string, pattern, replacement
+  const std::string buffer = args(0).string_value ();
+  if (error_state)
+    return retval;
+
+  std::string pattern = args(1).string_value ();
+  if (error_state)
+    return retval;
+  // Matlab compatibility.
+  if (args(1).is_sq_string ())
+    pattern = do_regexp_string_escapes (pattern);
+
+  std::string replacement = args(2).string_value ();
+  if (error_state)
+    return retval;
+  // Matlab compatibility.
+  if (args(2).is_sq_string ())
+    replacement = do_regexp_string_escapes (replacement);
+
+  // Pack options excluding 'tokenize' and various output
+  // reordering strings into regexp arg list
+  octave_value_list regexpargs (nargin-3, octave_value ());
+
+  int len = 0;
+  for (int i = 3; i < nargin; i++)
+    {
+      const std::string opt = args(i).string_value ();
+      if (opt != "tokenize" && opt != "start" && opt != "end"
+          && opt != "tokenextents" && opt != "match" && opt != "tokens"
+          && opt != "names"  && opt != "split" && opt != "warnings")
+        {
+          regexpargs(len++) = args(i);
+        }
+    }
+  regexpargs.resize (len);
+
+  regexp::opts options;
+  bool extra_args = false;
+  parse_options (options, regexpargs, who, 0, extra_args);
+  if (error_state)
+    return retval;
+
+  return regexp_replace (pattern, buffer, replacement, options, who);
+}
+
+DEFUN (regexprep, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr})\n\
+@deftypefnx {Built-in Function} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr}, \"@var{opt1}\", @dots{})\n\
+Replace occurrences of pattern @var{pat} in @var{string} with @var{repstr}.\n\
+\n\
+The pattern is a regular expression as documented for @code{regexp}.\n\
+@xref{doc-regexp,,regexp}.\n\
+\n\
+The replacement string may contain @code{$i}, which substitutes\n\
+for the ith set of parentheses in the match string.  For example,\n\
+\n\
+@example\n\
+regexprep (\"Bill Dunn\", '(\\w+) (\\w+)', '$2, $1')\n\
+@end example\n\
+\n\
+@noindent\n\
+returns \"Dunn, Bill\"\n\
+\n\
+Options in addition to those of @code{regexp} are\n\
+\n\
+@table @samp\n\
+\n\
+@item once\n\
+Replace only the first occurrence of @var{pat} in the result.\n\
+\n\
+@item warnings\n\
+This option is present for compatibility but is ignored.\n\
+\n\
+@end table\n\
+@seealso{regexp, regexpi, strrep}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+  int nargin = args.length ();
+
+  if (nargin < 3)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  if (args(0).is_cell () || args(1).is_cell () || args(2).is_cell ())
+    {
+      Cell str;
+      Cell pat;
+      Cell rep;
+      dim_vector dv0;
+      dim_vector dv1 (1, 1);
+
+      if (args(0).is_cell ())
+        str = args(0).cell_value ();
+      else
+        str = Cell (args(0));
+
+      if (args(1).is_cell ())
+        pat = args(1).cell_value ();
+      else
+        pat = Cell (args(1));
+
+      if (args(2).is_cell ())
+        rep = args(2).cell_value ();
+      else
+        rep = Cell (args(2));
+
+      dv0 = str.dims ();
+      if (pat.numel () != 1)
+        {
+          dv1 = pat.dims ();
+          if (rep.numel () != 1 && dv1 != rep.dims ())
+            error ("regexprep: inconsistent cell array dimensions");
+        }
+      else if (rep.numel () != 1)
+        dv1 = rep.dims ();
+
+      if (!error_state)
+        {
+          Cell ret (dv0);
+          octave_value_list new_args = args;
+
+          for (octave_idx_type i = 0; i < dv0.numel (); i++)
+            {
+              new_args(0) = str(i);
+              if (pat.numel () == 1)
+                new_args(1) = pat(0);
+              if (rep.numel () == 1)
+                new_args(2) = rep(0);
+
+              for (octave_idx_type j = 0; j < dv1.numel (); j++)
+                {
+                  if (pat.numel () != 1)
+                    new_args(1) = pat(j);
+                  if (rep.numel () != 1)
+                    new_args(2) = rep(j);
+                  new_args(0) = octregexprep (new_args, "regexprep");
+
+                  if (error_state)
+                    break;
+                }
+
+              if (error_state)
+                break;
+
+              ret(i) = new_args(0);
+            }
+
+          if (!error_state)
+            retval = args(0).is_cell ()
+              ? octave_value (ret) : octave_value (ret(0));
+        }
+    }
+  else
+    retval = octregexprep (args, "regexprep");
+
+  return retval;
+}
+
+/*
+%!test  # Replace with empty
+%! xml = '<!-- This is some XML --> <tag v="hello">some stuff<!-- sample tag--></tag>';
+%! t = regexprep (xml, '<[!?][^>]*>', '');
+%! assert (t, ' <tag v="hello">some stuff</tag>');
+
+%!test  # Replace with non-empty
+%! xml = '<!-- This is some XML --> <tag v="hello">some stuff<!-- sample tag--></tag>';
+%! t = regexprep (xml, '<[!?][^>]*>', '?');
+%! assert (t, '? <tag v="hello">some stuff?</tag>');
+
+%!test  # Check that 'tokenize' is ignored
+%! xml = '<!-- This is some XML --> <tag v="hello">some stuff<!-- sample tag--></tag>';
+%! t = regexprep (xml, '<[!?][^>]*>', '', 'tokenize');
+%! assert (t, ' <tag v="hello">some stuff</tag>');
+
+## Test capture replacement
+%!test
+%! data = "Bob Smith\nDavid Hollerith\nSam Jenkins";
+%! result = "Smith, Bob\nHollerith, David\nJenkins, Sam";
+%! t = regexprep (data, '(?m)^(\w+)\s+(\w+)$', '$2, $1');
+%! assert (t, result);
+
+## Return the original if no match
+%!assert (regexprep ('hello', 'world', 'earth'), 'hello')
+
+## Test emptymatch
+%!assert (regexprep ('World', '^', 'Hello '), 'World')
+%!assert (regexprep ('World', '^', 'Hello ', 'emptymatch'), 'Hello World')
+
+## Test a general replacement
+%!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Za-z0-9_]", "_"), "a_b_c_d_e_f_g")
+
+## Make sure it works at the beginning and end
+%!assert (regexprep ("a[b]c{d}e-f=g", "a", "_"), "_[b]c{d}e-f=g")
+%!assert (regexprep ("a[b]c{d}e-f=g", "g", "_"), "a[b]c{d}e-f=_")
+
+## Options
+%!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Za-z0-9_]", "_", "once"), "a_b]c{d}e-f=g")
+%!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Z0-9_]", "_", "ignorecase"), "a_b_c_d_e_f_g")
+
+## Option combinations
+%!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Z0-9_]", "_", "once", "ignorecase"), "a_b]c{d}e-f=g")
+
+## End conditions on replacement
+%!assert (regexprep ("abc", "(b)", ".$1"), "a.bc");
+%!assert (regexprep ("abc", "(b)", "$1"), "abc");
+%!assert (regexprep ("abc", "(b)", "$1."), "ab.c");
+%!assert (regexprep ("abc", "(b)", "$1.."), "ab..c");
+
+## Test cell array arguments
+%!assert (regexprep ("abc", {"b","a"}, "?"), "??c")
+%!assert (regexprep ({"abc","cba"}, "b", "?"), {"a?c","c?a"})
+%!assert (regexprep ({"abc","cba"}, {"b","a"}, {"?","!"}), {"!?c","c?!"})
+
+# Nasty lookbehind expression
+%!assert (regexprep ('x^(-1)+y(-1)+z(-1)=0', '(?<=[a-z]+)\(\-[1-9]*\)', '_minus1'),'x^(-1)+y_minus1+z_minus1=0')
+
+%!assert (regexprep ("\n", '\n', "X"), "X");
+%!assert (regexprep ("\n", "\n", "X"), "X");
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/schur.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,381 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+
+#include "CmplxSCHUR.h"
+#include "dbleSCHUR.h"
+#include "fCmplxSCHUR.h"
+#include "floatSCHUR.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+template <class Matrix>
+static octave_value
+mark_upper_triangular (const Matrix& a)
+{
+  octave_value retval = a;
+
+  octave_idx_type n = a.rows ();
+  assert (a.columns () == n);
+
+  const typename Matrix::element_type zero = typename Matrix::element_type ();
+
+  for (octave_idx_type i = 0; i < n; i++)
+    if (a(i,i) == zero)
+      return retval;
+
+  retval.matrix_type (MatrixType::Upper);
+
+  return retval;
+}
+
+DEFUN (schur, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{S} =} schur (@var{A})\n\
+@deftypefnx {Built-in Function} {@var{S} =} schur (@var{A}, \"real\")\n\
+@deftypefnx {Built-in Function} {@var{S} =} schur (@var{A}, \"complex\")\n\
+@deftypefnx {Built-in Function} {@var{S} =} schur (@var{A}, @var{opt})\n\
+@deftypefnx {Built-in Function} {[@var{U}, @var{S}] =} schur (@var{A}, @dots{})\n\
+@cindex Schur decomposition\n\
+Compute the Schur@tie{}decomposition of @var{A}\n\
+@tex\n\
+$$\n\
+ S = U^T A U\n\
+$$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+@code{@var{S} = @var{U}' * @var{A} * @var{U}}\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+where @var{U} is a unitary matrix\n\
+@tex\n\
+($U^T U$ is identity)\n\
+@end tex\n\
+@ifnottex\n\
+(@code{@var{U}'* @var{U}} is identity)\n\
+@end ifnottex\n\
+and @var{S} is upper triangular.  The eigenvalues of @var{A} (and @var{S})\n\
+are the diagonal elements of @var{S}.  If the matrix @var{A}\n\
+is real, then the real Schur@tie{}decomposition is computed, in which the\n\
+matrix @var{U} is orthogonal and @var{S} is block upper triangular\n\
+with blocks of size at most\n\
+@tex\n\
+$2 \\times 2$\n\
+@end tex\n\
+@ifnottex\n\
+@code{2 x 2}\n\
+@end ifnottex\n\
+along the diagonal.  The diagonal elements of @var{S}\n\
+(or the eigenvalues of the\n\
+@tex\n\
+$2 \\times 2$\n\
+@end tex\n\
+@ifnottex\n\
+@code{2 x 2}\n\
+@end ifnottex\n\
+blocks, when appropriate) are the eigenvalues of @var{A} and @var{S}.\n\
+\n\
+The default for real matrices is a real Schur@tie{}decomposition.\n\
+A complex decomposition may be forced by passing the flag \"complex\".\n\
+\n\
+The eigenvalues are optionally ordered along the diagonal according to\n\
+the value of @var{opt}.  @code{@var{opt} = \"a\"} indicates that all\n\
+eigenvalues with negative real parts should be moved to the leading\n\
+block of @var{S}\n\
+(used in @code{are}), @code{@var{opt} = \"d\"} indicates that all eigenvalues\n\
+with magnitude less than one should be moved to the leading block of @var{S}\n\
+(used in @code{dare}), and @code{@var{opt} = \"u\"}, the default, indicates\n\
+that no ordering of eigenvalues should occur.  The leading @var{k}\n\
+columns of @var{U} always span the @var{A}-invariant\n\
+subspace corresponding to the @var{k} leading eigenvalues of @var{S}.\n\
+\n\
+The Schur@tie{}decomposition is used to compute eigenvalues of a\n\
+square matrix, and has applications in the solution of algebraic\n\
+Riccati equations in control (see @code{are} and @code{dare}).\n\
+@seealso{rsf2csf}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 1 || nargin > 2 || nargout > 2)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value arg = args(0);
+
+  std::string ord;
+
+  if (nargin == 2)
+    {
+      ord = args(1).string_value ();
+
+      if (error_state)
+        {
+          error ("schur: second argument must be a string");
+          return retval;
+        }
+    }
+
+  bool force_complex = false;
+
+  if (ord == "real")
+    {
+      ord = std::string ();
+    }
+  else if (ord == "complex")
+    {
+      force_complex = true;
+      ord = std::string ();
+    }
+  else
+    {
+      char ord_char = ord.empty () ? 'U' : ord[0];
+
+      if (ord_char != 'U' && ord_char != 'A' && ord_char != 'D'
+          && ord_char != 'u' && ord_char != 'a' && ord_char != 'd')
+        {
+          warning ("schur: incorrect ordered schur argument `%c'",
+                   ord.c_str ());
+          return retval;
+        }
+    }
+
+  octave_idx_type nr = arg.rows ();
+  octave_idx_type nc = arg.columns ();
+
+  if (nr != nc)
+    {
+      gripe_square_matrix_required ("schur");
+      return retval;
+    }
+
+  if (! arg.is_numeric_type ())
+    gripe_wrong_type_arg ("schur", arg);
+  else if (arg.is_single_type ())
+    {
+      if (! force_complex && arg.is_real_type ())
+        {
+          FloatMatrix tmp = arg.float_matrix_value ();
+
+          if (! error_state)
+            {
+              if (nargout == 0 || nargout == 1)
+                {
+                  FloatSCHUR result (tmp, ord, false);
+                  retval(0) = result.schur_matrix ();
+                }
+              else
+                {
+                  FloatSCHUR result (tmp, ord, true);
+                  retval(1) = result.schur_matrix ();
+                  retval(0) = result.unitary_matrix ();
+                }
+            }
+        }
+      else
+        {
+          FloatComplexMatrix ctmp = arg.float_complex_matrix_value ();
+
+          if (! error_state)
+            {
+
+              if (nargout == 0 || nargout == 1)
+                {
+                  FloatComplexSCHUR result (ctmp, ord, false);
+                  retval(0) = mark_upper_triangular (result.schur_matrix ());
+                }
+              else
+                {
+                  FloatComplexSCHUR result (ctmp, ord, true);
+                  retval(1) = mark_upper_triangular (result.schur_matrix ());
+                  retval(0) = result.unitary_matrix ();
+                }
+            }
+        }
+    }
+  else
+    {
+      if (! force_complex && arg.is_real_type ())
+        {
+          Matrix tmp = arg.matrix_value ();
+
+          if (! error_state)
+            {
+              if (nargout == 0 || nargout == 1)
+                {
+                  SCHUR result (tmp, ord, false);
+                  retval(0) = result.schur_matrix ();
+                }
+              else
+                {
+                  SCHUR result (tmp, ord, true);
+                  retval(1) = result.schur_matrix ();
+                  retval(0) = result.unitary_matrix ();
+                }
+            }
+        }
+      else
+        {
+          ComplexMatrix ctmp = arg.complex_matrix_value ();
+
+          if (! error_state)
+            {
+
+              if (nargout == 0 || nargout == 1)
+                {
+                  ComplexSCHUR result (ctmp, ord, false);
+                  retval(0) = mark_upper_triangular (result.schur_matrix ());
+                }
+              else
+                {
+                  ComplexSCHUR result (ctmp, ord, true);
+                  retval(1) = mark_upper_triangular (result.schur_matrix ());
+                  retval(0) = result.unitary_matrix ();
+                }
+            }
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!test
+%! a = [1, 2, 3; 4, 5, 9; 7, 8, 6];
+%! [u, s] = schur (a);
+%! assert (u' * a * u, s, sqrt (eps));
+
+%!test
+%! a = single ([1, 2, 3; 4, 5, 9; 7, 8, 6]);
+%! [u, s] = schur (a);
+%! assert (u' * a * u, s, sqrt (eps ("single")));
+
+%!test
+%! fail ("schur ([1, 2; 3, 4], 2)", "warning");
+
+%!error schur ()
+%!error <argument must be a square matrix> schur ([1, 2, 3; 4, 5, 6])
+*/
+
+DEFUN (rsf2csf, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Function File} {[@var{U}, @var{T}] =} rsf2csf (@var{UR}, @var{TR})\n\
+Convert a real, upper quasi-triangular Schur@tie{}form @var{TR} to a complex,\n\
+upper triangular Schur@tie{}form @var{T}.\n\
+\n\
+Note that the following relations hold:\n\
+\n\
+@tex\n\
+$UR \\cdot TR \\cdot {UR}^T = U T U^{\\dagger}$ and\n\
+$U^{\\dagger} U$ is the identity matrix I.\n\
+@end tex\n\
+@ifnottex\n\
+@xcode{@var{UR} * @var{TR} * @var{UR}' = @var{U} * @var{T} * @var{U}'} and\n\
+@code{@var{U}' * @var{U}} is the identity matrix I.\n\
+@end ifnottex\n\
+\n\
+Note also that @var{U} and @var{T} are not unique.\n\
+@seealso{schur}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  if (args.length () == 2 && nargout <= 2)
+    {
+      if (! args(0).is_numeric_type ())
+        gripe_wrong_type_arg ("rsf2csf", args(0));
+      else if (! args(1).is_numeric_type ())
+        gripe_wrong_type_arg ("rsf2csf", args(1));
+      else if (args(0).is_complex_type () || args(1).is_complex_type ())
+        error ("rsf2csf: UR and TR must be real matrices");
+      else
+        {
+
+          if (args(0).is_single_type () || args(1).is_single_type ())
+            {
+              FloatMatrix u = args(0).float_matrix_value ();
+              FloatMatrix t = args(1).float_matrix_value ();
+              if (! error_state)
+                {
+                  FloatComplexSCHUR cs (FloatSCHUR (t, u));
+
+                  retval(1) = cs.schur_matrix ();
+                  retval(0) = cs.unitary_matrix ();
+                }
+            }
+          else
+            {
+              Matrix u = args(0).matrix_value ();
+              Matrix t = args(1).matrix_value ();
+              if (! error_state)
+                {
+                  ComplexSCHUR cs (SCHUR (t, u));
+
+                  retval(1) = cs.schur_matrix ();
+                  retval(0) = cs.unitary_matrix ();
+                }
+            }
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!test
+%! A = [1, 1, 1, 2; 1, 2, 1, 1; 1, 1, 3, 1; -2, 1, 1, 1];
+%! [u, t] = schur (A);
+%! [U, T] = rsf2csf (u, t);
+%! assert (norm (u * t * u' - U * T * U'), 0, 1e-12);
+%! assert (norm (A - U * T * U'), 0, 1e-12);
+
+%!test
+%! A = rand (10);
+%! [u, t] = schur (A);
+%! [U, T] = rsf2csf (u, t);
+%! assert (norm (tril (T, -1)), 0);
+%! assert (norm (U * U'), 1, 1e-14);
+
+%!test
+%! A = [0, 1;-1, 0];
+%! [u, t] = schur (A);
+%! [U, T] = rsf2csf (u,t);
+%! assert (U * T * U', A, 1e-14);
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/spparms.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,208 @@
+/*
+
+Copyright (C) 2004-2012 David Bateman
+Copyright (C) 1998-2004 Andy Adler
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "defun.h"
+#include "ov.h"
+#include "pager.h"
+#include "error.h"
+#include "gripes.h"
+
+#include "oct-spparms.h"
+
+DEFUN (spparms, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} { } spparms ()\n\
+@deftypefnx {Built-in Function} {@var{vals} =} spparms ()\n\
+@deftypefnx {Built-in Function} {[@var{keys}, @var{vals}] =} spparms ()\n\
+@deftypefnx {Built-in Function} {@var{val} =} spparms (@var{key})\n\
+@deftypefnx {Built-in Function} { } spparms (@var{vals})\n\
+@deftypefnx {Built-in Function} { } spparms (\"defaults\")\n\
+@deftypefnx {Built-in Function} { } spparms (\"tight\")\n\
+@deftypefnx {Built-in Function} { } spparms (@var{key}, @var{val})\n\
+Query or set the parameters used by the sparse solvers and factorization\n\
+functions.  The first four calls above get information about the current\n\
+settings, while the others change the current settings.  The parameters are\n\
+stored as pairs of keys and values, where the values are all floats and the\n\
+keys are one of the following strings:\n\
+\n\
+@table @samp\n\
+@item spumoni\n\
+Printing level of debugging information of the solvers (default 0)\n\
+\n\
+@item ths_rel\n\
+Included for compatibility.  Not used.  (default 1)\n\
+\n\
+@item ths_abs\n\
+Included for compatibility.  Not used.  (default 1)\n\
+\n\
+@item exact_d\n\
+Included for compatibility.  Not used.  (default 0)\n\
+\n\
+@item supernd\n\
+Included for compatibility.  Not used.  (default 3)\n\
+\n\
+@item rreduce\n\
+Included for compatibility.  Not used.  (default 3)\n\
+\n\
+@item wh_frac\n\
+Included for compatibility.  Not used.  (default 0.5)\n\
+\n\
+@item autommd\n\
+Flag whether the LU/QR and the '\\' and '/' operators will automatically\n\
+use the sparsity preserving mmd functions (default 1)\n\
+\n\
+@item autoamd\n\
+Flag whether the LU and the '\\' and '/' operators will automatically\n\
+use the sparsity preserving amd functions (default 1)\n\
+\n\
+@item piv_tol\n\
+The pivot tolerance of the @sc{umfpack} solvers (default 0.1)\n\
+\n\
+@item sym_tol\n\
+The pivot tolerance of the @sc{umfpack} symmetric solvers (default 0.001)\n\
+\n\
+@item bandden\n\
+The density of non-zero elements in a banded matrix before it is treated\n\
+by the @sc{lapack} banded solvers (default 0.5)\n\
+\n\
+@item umfpack\n\
+Flag whether the @sc{umfpack} or mmd solvers are used for the LU, '\\' and\n\
+'/' operations (default 1)\n\
+@end table\n\
+\n\
+The value of individual keys can be set with\n\
+@code{spparms (@var{key}, @var{val})}.\n\
+The default values can be restored with the special keyword\n\
+\"defaults\".  The special keyword \"tight\" can be used to set the mmd\n\
+solvers to attempt a sparser solution at the potential cost of longer\n\
+running time.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+  int nargin = args.length ();
+
+  if (nargin == 0)
+    {
+      if (nargout == 0)
+        octave_sparse_params::print_info (octave_stdout, "");
+      else if (nargout == 1)
+        retval(0) =  octave_sparse_params::get_vals ();
+      else if (nargout == 2)
+        {
+          retval(1) = octave_sparse_params::get_vals ();
+          retval(0) = octave_sparse_params::get_keys ();
+        }
+      else
+        error ("spparms: too many output arguments");
+    }
+  else if (nargin == 1)
+    {
+      if (args(0).is_string ())
+        {
+          std::string str = args(0).string_value ();
+          int len = str.length ();
+          for (int i = 0; i < len; i++)
+            str[i] = tolower (str[i]);
+
+          if (str == "defaults")
+            octave_sparse_params::defaults ();
+          else if (str == "tight")
+            octave_sparse_params::tight ();
+          else
+            {
+              double val = octave_sparse_params::get_key (str);
+              if (xisnan (val))
+                error ("spparms: KEY not recognized");
+              else
+                retval(0) = val;
+            }
+        }
+      else
+        {
+          NDArray vals = args(0).array_value ();
+
+          if (error_state)
+            error ("spparms: input must be a string or a vector");
+          else if (vals.numel () > OCTAVE_SPARSE_CONTROLS_SIZE)
+            error ("spparms: too many elements in vector VALS");
+          else
+            octave_sparse_params::set_vals (vals);
+        }
+    }
+  else if (nargin == 2)
+    {
+      if (args(0).is_string ())
+        {
+          std::string str = args(0).string_value ();
+
+          double val = args(1).double_value ();
+
+          if (error_state)
+            error ("spparms: second argument must be a real scalar");
+          else if (str == "umfpack")
+            warning ("spparms: request to disable umfpack solvers ignored");
+          else if (!octave_sparse_params::set_key (str, val))
+            error ("spparms: KEY not found");
+        }
+      else
+        error ("spparms: first argument must be a string");
+    }
+  else
+    error ("spparms: too many input arguments");
+
+  return retval;
+}
+
+/*
+%!test
+%! old_vals = spparms ();  # save state
+%! spparms ("defaults");
+%! vals = spparms ();
+%! assert (vals, [0 1 1 0 3 3 0.5 1.0 1.0 0.1 0.5 1.0 0.001]');
+%! [keys, vals] = spparms ();
+%! assert (rows (keys), 13);
+%! assert (keys(2,:), "ths_rel");
+%! assert (vals, [0 1 1 0 3 3 0.5 1.0 1.0 0.1 0.5 1.0 0.001]');
+%! spparms ([3 2 1]);
+%! assert (spparms ()(1:3), [3, 2, 1]');
+%! assert (spparms ("ths_rel"), 2);
+%! spparms ("exact_d", 5);
+%! assert (spparms ("exact_d"), 5);
+%! spparms (old_vals);     # restore state
+
+%% Test input validation
+%!error <too many input arguments> spparms (1, 2, 3)
+%!error <too many output arguments> [x, y, z] = spparms ()
+%!error <KEY not recognized> spparms ("UNKNOWN_KEY")
+%!#error <input must be a string> spparms ({1, 2, 3})
+%!error spparms ({1, 2, 3})
+%!error <too many elements in vector VALS> spparms (ones (14, 1))
+%!error <first argument must be a string> spparms (1, 1)
+%!#error <second argument must be a real scalar> spparms ("ths_rel", "hello")
+%!error spparms ("ths_rel", "hello")
+%!error <KEY not found> spparms ("UNKNOWN_KEY", 1)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/sqrtm.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,276 @@
+/*
+
+Copyright (C) 2001-2012 Ross Lippert and Paul Kienzle
+Copyright (C) 2010 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <float.h>
+
+#include "CmplxSCHUR.h"
+#include "fCmplxSCHUR.h"
+#include "lo-ieee.h"
+#include "lo-mappers.h"
+#include "oct-norm.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "utils.h"
+#include "xnorm.h"
+
+template <class Matrix>
+static void
+sqrtm_utri_inplace (Matrix& T)
+{
+  typedef typename Matrix::element_type element_type;
+
+  const element_type zero = element_type ();
+
+  bool singular = false;
+
+  // The following code is equivalent to this triple loop:
+  //
+  //   n = rows (T);
+  //   for j = 1:n
+  //     T(j,j) = sqrt (T(j,j));
+  //     for i = j-1:-1:1
+  //       T(i,j) /= (T(i,i) + T(j,j));
+  //       k = 1:i-1;
+  //       T(k,j) -= T(k,i) * T(i,j);
+  //     endfor
+  //   endfor
+  //
+  // this is an in-place, cache-aligned variant of the code
+  // given in Higham's paper.
+
+  const octave_idx_type n = T.rows ();
+  element_type *Tp = T.fortran_vec ();
+  for (octave_idx_type j = 0; j < n; j++)
+    {
+      element_type *colj = Tp + n*j;
+      if (colj[j] != zero)
+        colj[j] = sqrt (colj[j]);
+      else
+        singular = true;
+
+      for (octave_idx_type i = j-1; i >= 0; i--)
+        {
+          const element_type *coli = Tp + n*i;
+          const element_type colji = colj[i] /= (coli[i] + colj[j]);
+          for (octave_idx_type k = 0; k < i; k++)
+            colj[k] -= coli[k] * colji;
+        }
+    }
+
+  if (singular)
+    warning_with_id ("Octave:sqrtm:SingularMatrix",
+                     "sqrtm: matrix is singular, may not have a square root");
+}
+
+template <class Matrix, class ComplexMatrix, class ComplexSCHUR>
+static octave_value
+do_sqrtm (const octave_value& arg)
+{
+
+  octave_value retval;
+
+  MatrixType mt = arg.matrix_type ();
+
+  bool iscomplex = arg.is_complex_type ();
+
+  typedef typename Matrix::element_type real_type;
+
+  real_type cutoff = 0, one = 1;
+  real_type eps = std::numeric_limits<real_type>::epsilon ();
+
+  if (! iscomplex)
+    {
+      Matrix x = octave_value_extract<Matrix> (arg);
+
+      if (mt.is_unknown ()) // if type is not known, compute it now.
+        arg.matrix_type (mt = MatrixType (x));
+
+      switch (mt.type ())
+        {
+        case MatrixType::Upper:
+        case MatrixType::Diagonal:
+          if (! x.diag ().any_element_is_negative ())
+            {
+              // Do it in real arithmetic.
+              sqrtm_utri_inplace (x);
+              retval = x;
+              retval.matrix_type (mt);
+            }
+          else
+            iscomplex = true;
+          break;
+
+        case MatrixType::Lower:
+          if (! x.diag ().any_element_is_negative ())
+            {
+              x = x.transpose ();
+              sqrtm_utri_inplace (x);
+              retval = x.transpose ();
+              retval.matrix_type (mt);
+            }
+          else
+            iscomplex = true;
+          break;
+
+        default:
+          iscomplex = true;
+          break;
+        }
+
+      if (iscomplex)
+        cutoff = 10 * x.rows () * eps * xnorm (x, one);
+    }
+
+  if (iscomplex)
+    {
+      ComplexMatrix x = octave_value_extract<ComplexMatrix> (arg);
+
+      if (mt.is_unknown ()) // if type is not known, compute it now.
+        arg.matrix_type (mt = MatrixType (x));
+
+      switch (mt.type ())
+        {
+        case MatrixType::Upper:
+        case MatrixType::Diagonal:
+          sqrtm_utri_inplace (x);
+          retval = x;
+          retval.matrix_type (mt);
+          break;
+
+        case MatrixType::Lower:
+          x = x.transpose ();
+          sqrtm_utri_inplace (x);
+          retval = x.transpose ();
+          retval.matrix_type (mt);
+          break;
+
+        default:
+          {
+            ComplexMatrix u;
+
+            do
+              {
+                ComplexSCHUR schur (x, std::string (), true);
+                x = schur.schur_matrix ();
+                u = schur.unitary_matrix ();
+              }
+            while (0); // schur no longer needed.
+
+            sqrtm_utri_inplace (x);
+
+            x = u * x; // original x no longer needed.
+            ComplexMatrix res = xgemm (x, u, blas_no_trans, blas_conj_trans);
+
+            if (cutoff > 0 && xnorm (imag (res), one) <= cutoff)
+              retval = real (res);
+            else
+              retval = res;
+          }
+          break;
+        }
+    }
+
+  return retval;
+}
+
+DEFUN (sqrtm, args, nargout,
+ "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{s} =} sqrtm (@var{A})\n\
+@deftypefnx {Built-in Function} {[@var{s}, @var{error_estimate}] =} sqrtm (@var{A})\n\
+Compute the matrix square root of the square matrix @var{A}.\n\
+\n\
+Ref: N.J. Higham.  @cite{A New sqrtm for @sc{matlab}}.  Numerical\n\
+Analysis Report No. 336, Manchester @nospell{Centre} for Computational\n\
+Mathematics, Manchester, England, January 1999.\n\
+@seealso{expm, logm}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin != 1)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value arg = args(0);
+
+  octave_idx_type n = arg.rows ();
+  octave_idx_type nc = arg.columns ();
+
+  if (n != nc || arg.ndims () > 2)
+    {
+      gripe_square_matrix_required ("sqrtm");
+      return retval;
+    }
+
+  if (nargout > 1)
+    {
+      retval.resize (1, 2);
+      retval(2) = -1.0;
+    }
+
+  if (arg.is_diag_matrix ())
+    // sqrtm of a diagonal matrix is just sqrt.
+    retval(0) = arg.sqrt ();
+  else if (arg.is_single_type ())
+    retval(0) = do_sqrtm<FloatMatrix, FloatComplexMatrix, FloatComplexSCHUR> (arg);
+  else if (arg.is_numeric_type ())
+    retval(0) = do_sqrtm<Matrix, ComplexMatrix, ComplexSCHUR> (arg);
+
+  if (nargout > 1 && ! error_state)
+    {
+      // This corresponds to generic code
+      //
+      //   norm (s*s - x, "fro") / norm (x, "fro");
+
+      octave_value s = retval(0);
+      retval(1) = xfrobnorm (s*s - arg) / xfrobnorm (arg);
+    }
+
+  return retval;
+}
+
+/*
+%!assert (sqrtm (2*ones (2)), ones (2), 3*eps)
+
+## The following two tests are from the reference in the docstring above.
+%!test
+%! x = [0 1; 0 0];
+%! assert (any (isnan (sqrtm (x))(:)));
+
+%!test
+%! x = eye (4);  x(2,2) = x(3,3) = 2^-26;  x(1,4) = 1;
+%! z = eye (4);  z(2,2) = z(3,3) = 2^-13;  z(1,4) = 0.5;
+%! [y, err] = sqrtm (x);
+%! assert (y, z);
+%! assert (err, 0);   ## Yes, this one has to hold exactly
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/str2double.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,406 @@
+/*
+
+Copyright (C) 2010-2012 Jaroslav Hajek
+Copyright (C) 2010 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+#include <cctype>
+#include <sstream>
+#include <algorithm>
+
+#include "lo-ieee.h"
+
+#include "Cell.h"
+#include "ov.h"
+#include "defun.h"
+#include "gripes.h"
+#include "utils.h"
+
+static inline bool
+is_imag_unit (int c)
+{ return c == 'i' || c == 'j'; }
+
+static std::istringstream&
+single_num (std::istringstream& is, double& num)
+{
+  char c = is.peek ();
+
+  // Skip spaces.
+  while (isspace (c))
+    {
+      is.get ();
+      c = is.peek ();
+    }
+
+  if (std::toupper (c) == 'I')
+    {
+      // It's infinity.
+      is.get ();
+      char c1 = is.get (), c2 = is.get ();
+      if (std::tolower (c1) == 'n' && std::tolower (c2) == 'f')
+        {
+          num = octave_Inf;
+          is.peek (); // May set EOF bit.
+        }
+      else
+        is.setstate (std::ios::failbit); // indicate that read has failed.
+    }
+  else if (c == 'N')
+    {
+      // It's NA or NaN
+      is.get ();
+      char c1 = is.get ();
+      if (c1 == 'A')
+        {
+          num = octave_NA;
+          is.peek (); // May set EOF bit.
+        }
+      else
+        {
+          char c2 = is.get ();
+          if (c1 == 'a' && c2 == 'N')
+            {
+              num = octave_NaN;
+              is.peek (); // May set EOF bit.
+            }
+          else
+            is.setstate (std::ios::failbit); // indicate that read has failed.
+        }
+    }
+  else
+    is >> num;
+
+  return is;
+}
+
+static std::istringstream&
+extract_num (std::istringstream& is, double& num, bool& imag, bool& have_sign)
+{
+  have_sign = imag = false;
+
+  char c = is.peek ();
+
+  // Skip leading spaces.
+  while (isspace (c))
+    {
+      is.get ();
+      c = is.peek ();
+    }
+
+  bool negative = false;
+
+  // Accept leading sign.
+  if (c == '+' || c == '-')
+    {
+      negative = c == '-';
+      is.get ();
+      c = is.peek ();
+      have_sign = true;
+    }
+
+  // Skip spaces after sign.
+  while (isspace (c))
+    {
+      is.get ();
+      c = is.peek ();
+    }
+
+  // Imaginary number (i*num or just i), or maybe 'inf'.
+  if (c == 'i')
+    {
+      // possible infinity.
+      is.get ();
+      c = is.peek ();
+
+      if (is.eof ())
+        {
+          // just 'i' and string is finished.  Return immediately.
+          imag = true;
+          num = 1.0;
+          if (negative)
+            num = -num;
+          return is;
+        }
+      else
+        { 
+          if (std::tolower (c) != 'n')
+            imag = true;
+          is.unget ();
+        }
+    }
+  else if (c == 'j')
+    imag = true;
+    
+  // It's i*num or just i
+  if (imag)
+    {
+      is.get ();
+      c = is.peek ();
+      // Skip spaces after imaginary unit.
+      while (isspace (c))
+        {
+          is.get ();
+          c = is.peek ();
+        }
+
+      if (c == '*')
+        {
+          // Multiplier follows, we extract it as a number.
+          is.get ();
+          single_num (is, num);
+          if (is.good ())
+            c = is.peek ();
+        }
+      else
+        num = 1.0;
+    }
+  else
+    {
+      // It's num, num*i, or numi.
+      single_num (is, num);
+      if (is.good ())
+        {
+          c = is.peek ();
+
+          // Skip spaces after number.
+          while (isspace (c))
+            {
+              is.get ();
+              c = is.peek ();
+            }
+
+          if (c == '*')
+            {
+              is.get ();
+              c = is.peek ();
+
+              // Skip spaces after operator.
+              while (isspace (c))
+                {
+                  is.get ();
+                  c = is.peek ();
+                }
+
+              if (is_imag_unit (c))
+                {
+                  imag = true;
+                  is.get ();
+                  c = is.peek ();
+                }
+              else
+                is.setstate (std::ios::failbit); // indicate that read has failed.
+            }
+          else if (is_imag_unit (c))
+            {
+              imag = true;
+              is.get ();
+              c = is.peek ();
+            }
+        }
+    }
+
+  if (is.good ())
+    {
+      // Skip trailing spaces.
+      while (isspace (c))
+        {
+          is.get ();
+          c = is.peek ();
+        }
+    }
+
+  if (negative)
+    num = -num;
+
+  return is;
+}
+
+static inline void
+set_component (Complex& c, double num, bool imag)
+{
+#if defined (HAVE_CXX_COMPLEX_SETTERS)
+  if (imag)
+    c.imag (num);
+  else
+    c.real (num);
+#elif defined (HAVE_CXX_COMPLEX_REFERENCE_ACCESSORS)
+  if (imag)
+    c.imag () = num;
+  else
+    c.real () = num;
+#else
+  if (imag)
+    c = Complex (c.real (), num);
+  else
+    c = Complex (num, c.imag ());
+#endif
+}
+
+static Complex
+str2double1 (const std::string& str_arg)
+{
+  Complex val (0.0, 0.0);
+
+  std::string str = str_arg;
+
+  // FIXME -- removing all commas does too much...
+  std::string::iterator se = str.end ();
+  se = std::remove (str.begin (), se, ',');
+  str.erase (se, str.end ());
+  std::istringstream is (str);
+
+  double num;
+  bool i1, i2, s1, s2;
+
+  if (is.eof ())
+    val = octave_NaN;
+  else if (! extract_num (is, num, i1, s1))
+    val = octave_NaN;
+  else
+    {
+      set_component (val, num, i1);
+
+      if (! is.eof ())
+        {
+          if (! extract_num (is, num, i2, s2) || i1 == i2 || ! s2)
+            val = octave_NaN;
+          else
+            set_component (val, num, i2);
+        }
+    }
+
+  return val;
+}
+
+DEFUN (str2double, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} str2double (@var{s})\n\
+Convert a string to a real or complex number.\n\
+\n\
+The string must be in one of the following formats where\n\
+a and b are real numbers and the complex unit is 'i' or 'j':\n\
+\n\
+@itemize\n\
+@item a + bi\n\
+\n\
+@item a + b*i\n\
+\n\
+@item a + i*b\n\
+\n\
+@item bi + a\n\
+\n\
+@item b*i + a\n\
+\n\
+@item i*b + a\n\
+@end itemize\n\
+\n\
+If present, a and/or b are of the form @nospell{[+-]d[,.]d[[eE][+-]d]} where\n\
+the brackets indicate optional arguments and 'd' indicates zero or more\n\
+digits.  The special input values @code{Inf}, @code{NaN}, and @code{NA} are\n\
+also accepted.\n\
+\n\
+@var{s} may also be a character matrix, in which case the conversion is\n\
+repeated for each row.  Or @var{s} may be a cell array of strings, in which\n\
+case each element is converted and an array of the same dimensions is\n\
+returned.\n\
+\n\
+@code{str2double} returns NaN for elements of @var{s} which cannot be\n\
+converted.\n\
+\n\
+@code{str2double} can replace @code{str2num}, and it avoids the security\n\
+risk of using @code{eval} on unknown data.\n\
+@seealso{str2num}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () != 1)
+    print_usage ();
+  else if (args(0).is_string ())
+    {
+      if (args(0).rows () == 1 && args(0).ndims () == 2)
+        {
+          retval = str2double1 (args(0).string_value ());
+        }
+      else
+        {
+          const string_vector sv = args(0).all_strings ();
+          if (! error_state)
+            retval = sv.map<Complex> (str2double1);
+        }
+    }
+  else if (args(0).is_cell ())
+    {
+      const Cell cell = args(0).cell_value ();
+
+      if (! error_state)
+      {
+        ComplexNDArray output (cell.dims (), octave_NaN);
+        for (octave_idx_type i = 0; i < cell.numel (); i++)
+        {
+          if (cell(i).is_string ())
+            output(i) = str2double1 (cell(i).string_value ());
+        }
+        retval = output;
+      }
+    }
+  else
+    retval = NDArray (args(0).dims (), octave_NaN);
+
+
+  return retval;
+}
+
+/*
+%!assert (str2double ("1"), 1)
+%!assert (str2double ("-.1e-5"), -1e-6)
+%!assert (str2double (char ("1", "2 3", "4i")), [1; NaN; 4i])
+%!assert (str2double ("-.1e-5"), -1e-6)
+%!assert (str2double ("1,222.5"), 1222.5)
+%!assert (str2double ("i"), i)
+%!assert (str2double ("2j"), 2i)
+%!assert (str2double ("2 + j"), 2+j)
+%!assert (str2double ("i*2 + 3"), 3+2i)
+%!assert (str2double (".5*i + 3.5"), 3.5+0.5i)
+%!assert (str2double ("1e-3 + i*.25"), 1e-3 + 0.25i)
+%!assert (str2double (["2 + j";"1.25e-3";"-05"]), [2+i; 1.25e-3; -5])
+%!assert (str2double ({"2 + j","1.25e-3","-05"}), [2+i, 1.25e-3, -5])
+%!assert (str2double (1), NaN)
+%!assert (str2double ("1 2 3 4"), NaN)
+%!assert (str2double ("Hello World"), NaN)
+%!assert (str2double ("NaN"), NaN)
+%!assert (str2double ("NA"), NA)
+%!assert (str2double ("Inf"), Inf)
+%!assert (str2double ("iNF"), Inf)
+%!assert (str2double ("-Inf"), -Inf)
+%!assert (str2double ("Inf*i"), complex (0, Inf))
+%!assert (str2double ("iNF*i"), complex (0, Inf))
+%!assert (str2double ("NaN + Inf*i"), complex (NaN, Inf))
+%!assert (str2double ("Inf - Inf*i"), complex (Inf, -Inf))
+%!assert (str2double ("-i*NaN - Inf"), complex (-Inf, -NaN))
+%!assert (str2double ({"abc", "4i"}), [NaN + 0i, 4i])
+%!assert (str2double ({2, "4i"}), [NaN + 0i, 4i])
+%!assert (str2double (zeros (3,1,2)), NaN (3,1,2))
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/strfind.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,415 @@
+/*
+
+Copyright (C) 2009-2012 Jaroslav Hajek
+Copyright (C) 2009-2010 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+#include <climits>
+#include <algorithm>
+#include <deque>
+
+#include "Cell.h"
+#include "ov.h"
+#include "defun.h"
+#include "unwind-prot.h"
+#include "gripes.h"
+#include "utils.h"
+
+// This allows safe indexing with char. In C++, char may be (and often is) signed!
+#define ORD(ch) static_cast<unsigned char>(ch)
+#define TABSIZE (UCHAR_MAX + 1)
+
+// This is the quick search algorithm, as described at
+// http://www-igm.univ-mlv.fr/~lecroq/string/node19.html
+static void
+qs_preprocess (const Array<char>& needle,
+               octave_idx_type table[TABSIZE])
+{
+  const char *x = needle.data ();
+  octave_idx_type m = needle.numel ();
+
+   for (octave_idx_type i = 0; i < TABSIZE; i++)
+      table[i] = m + 1;
+   for (octave_idx_type i = 0; i < m; i++)
+      table[ORD(x[i])] = m - i;
+}
+
+
+static Array<octave_idx_type>
+qs_search (const Array<char>& needle,
+           const Array<char>& haystack,
+           const octave_idx_type table[TABSIZE],
+           bool overlaps = true)
+{
+  const char *x = needle.data ();
+  octave_idx_type m = needle.numel ();
+  const char *y = haystack.data ();
+  octave_idx_type n = haystack.numel ();
+
+  // We'll use deque because it typically has the most favorable properties for
+  // the operation we need.
+  std::deque<octave_idx_type> accum;
+  if (m == 1)
+    {
+      // Looking for a single character.
+      for (octave_idx_type i = 0; i < n; i++)
+        {
+          if (y[i] == x[0])
+            accum.push_back (i);
+        }
+    }
+  else if (m == 2)
+    {
+      // Two characters.
+      if (overlaps)
+        {
+          for (octave_idx_type i = 0; i < n-1; i++)
+            {
+              if (y[i] == x[0] && y[i+1] == x[1])
+                accum.push_back (i);
+            }
+        }
+      else
+        {
+          for (octave_idx_type i = 0; i < n-1; i++)
+            {
+              if (y[i] == x[0] && y[i+1] == x[1])
+                accum.push_back (i++);
+            }
+        }
+    }
+  else if (n >= m)
+    {
+      // General case.
+      octave_idx_type j = 0;
+
+      if (overlaps)
+        {
+          while (j < n - m)
+            {
+              if (std::equal (x, x + m, y + j))
+                accum.push_back (j);
+              j += table[ORD(y[j + m])];
+            }
+        }
+      else
+        {
+          while (j < n - m)
+            {
+              if (std::equal (x, x + m, y + j))
+                {
+                  accum.push_back (j);
+                  j += m;
+                }
+              else
+                j += table[ORD(y[j + m])];
+            }
+        }
+
+      if (j == n - m && std::equal (x, x + m, y + j))
+        accum.push_back (j);
+    }
+
+  octave_idx_type nmatch = accum.size ();
+  octave_idx_type one = 1;
+  Array<octave_idx_type> result (dim_vector (std::min (one, nmatch), nmatch));
+  octave_idx_type k = 0;
+  for (std::deque<octave_idx_type>::const_iterator iter = accum.begin ();
+       iter != accum.end (); iter++)
+    {
+      result.xelem (k++) = *iter;
+    }
+
+  return result;
+}
+
+DEFUN (strfind, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{idx} =} strfind (@var{str}, @var{pattern})\n\
+@deftypefnx {Built-in Function} {@var{idx} =} strfind (@var{cellstr}, @var{pattern})\n\
+Search for @var{pattern} in the string @var{str} and return the\n\
+starting index of every such occurrence in the vector @var{idx}.\n\
+If there is no such occurrence, or if @var{pattern} is longer\n\
+than @var{str}, then @var{idx} is the empty array @code{[]}.\n\
+\n\
+If a cell array of strings @var{cellstr} is specified\n\
+then @var{idx} is a cell array of vectors, as specified\n\
+above.  Examples:\n\
+\n\
+@example\n\
+@group\n\
+strfind (\"abababa\", \"aba\")\n\
+     @result{} [1, 3, 5]\n\
+\n\
+strfind (@{\"abababa\", \"bebebe\", \"ab\"@}, \"aba\")\n\
+     @result{}\n\
+        @{\n\
+          [1,1] =\n\
+\n\
+             1   3   5\n\
+\n\
+          [1,2] = [](1x0)\n\
+          [1,3] = [](1x0)\n\
+        @}\n\
+@end group\n\
+@end example\n\
+@seealso{findstr, strmatch, regexp, regexpi, find}\n\
+@end deftypefn")
+{
+  octave_value retval;
+  int nargin = args.length ();
+  bool overlaps = true;
+
+  if (nargin == 4 && args(2).is_string () && args(3).is_scalar_type ())
+    {
+      std::string opt = args(2).string_value ();
+      if (opt == "overlaps")
+        {
+          overlaps = args(3).bool_value ();
+          nargin = 2;
+        }
+      else
+        {
+          error ("strfind: unknown option: %s", opt.c_str ());
+          return retval;
+        }
+    }
+
+  if (nargin == 2)
+    {
+      octave_value argstr = args(0), argpat = args(1);
+      if (argpat.is_string ())
+        {
+          Array<char> needle = argpat.char_array_value ();
+          OCTAVE_LOCAL_BUFFER (octave_idx_type, table, TABSIZE);
+          qs_preprocess (needle, table);
+
+          if (argstr.is_string ())
+            retval = octave_value (qs_search (needle, argstr.char_array_value (),
+                                              table, overlaps),
+                                   true, true);
+          else if (argstr.is_cell ())
+            {
+              const Cell argsc = argstr.cell_value ();
+              Cell retc (argsc.dims ());
+              octave_idx_type ns = argsc.numel ();
+
+              for (octave_idx_type i = 0; i < ns; i++)
+                {
+                  octave_value argse = argsc(i);
+                  if (argse.is_string ())
+                    retc(i) = octave_value (qs_search (needle, argse.char_array_value (),
+                                                       table, overlaps),
+                                            true, true);
+                  else
+                    {
+                      error ("strfind: each element of CELLSTR must be a string");
+                      break;
+                    }
+                }
+
+              retval = retc;
+            }
+          else
+            error ("strfind: first argument must be a string or cell array of strings");
+        }
+      else if (argpat.is_cell ())
+        retval = do_simple_cellfun (Fstrfind, "strfind", args);
+      else
+        error ("strfind: PATTERN must be a string or cell array of strings");
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!assert (strfind ("abababa", "aba"), [1, 3, 5])
+%!assert (strfind ("abababa", "aba", "overlaps", false), [1, 5])
+%!assert (strfind ({"abababa", "bla", "bla"}, "a"), {[1, 3, 5, 7], 3, 3})
+%!assert (strfind ("Linux _is_ user-friendly. It just isn't ignorant-friendly or idiot-friendly.", "friendly"), [17, 50, 68])
+
+%!error strfind ()
+%!error strfind ("foo", "bar", 1)
+%!error <PATTERN must be a string> strfind ("foo", 100)
+%!error <first argument must be a string> strfind (100, "foo")
+*/
+
+static Array<char>
+qs_replace (const Array<char>& str, const Array<char>& pat,
+            const Array<char>& rep,
+            const octave_idx_type table[TABSIZE],
+            bool overlaps = true)
+{
+  Array<char> ret = str;
+
+  octave_idx_type siz = str.numel (), psiz = pat.numel (), rsiz = rep.numel ();
+
+  if (psiz != 0)
+    {
+      // Look up matches, without overlaps.
+      const Array<octave_idx_type> idx = qs_search (pat, str, table, overlaps);
+      octave_idx_type nidx = idx.numel ();
+
+      if (nidx)
+        {
+          // Compute result size.
+          octave_idx_type retsiz;
+          if (overlaps)
+            {
+              retsiz = 0;
+              // OMG. Is this the "right answer" MW always looks for, or
+              // someone was just lazy?
+              octave_idx_type k = 0;
+              for (octave_idx_type i = 0; i < nidx; i++)
+                {
+                  octave_idx_type j = idx(i);
+                  if (j >= k)
+                    retsiz += j - k;
+                  retsiz += rsiz;
+                  k = j + psiz;
+                }
+
+              retsiz += siz - k;
+            }
+          else
+            retsiz = siz + nidx * (rsiz - psiz);
+
+          ret.clear (dim_vector (1, retsiz));
+          const char *src = str.data (), *reps = rep.data ();
+          char *dest = ret.fortran_vec ();
+
+          octave_idx_type k = 0;
+          for (octave_idx_type i = 0; i < nidx; i++)
+            {
+              octave_idx_type j = idx(i);
+              if (j >= k)
+                dest = std::copy (src + k, src + j, dest);
+              dest = std::copy (reps, reps + rsiz, dest);
+              k = j + psiz;
+            }
+
+          std::copy (src + k, src + siz, dest);
+        }
+    }
+
+  return ret;
+}
+
+DEFUN (strrep, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} strrep (@var{s}, @var{ptn}, @var{rep})\n\
+@deftypefnx {Built-in Function} {} strrep (@var{s}, @var{ptn}, @var{rep}, \"overlaps\", @var{o})\n\
+Replace all occurrences of the substring @var{ptn} in the string @var{s}\n\
+with the string @var{rep} and return the result.  For example:\n\
+\n\
+@example\n\
+@group\n\
+strrep (\"This is a test string\", \"is\", \"&%$\")\n\
+    @result{}  \"Th&%$ &%$ a test string\"\n\
+@end group\n\
+@end example\n\
+\n\
+@var{s} may also be a cell array of strings, in which case the replacement is\n\
+done for each element and a cell array is returned.\n\
+@seealso{regexprep, strfind, findstr}\n\
+@end deftypefn")
+{
+  octave_value retval;
+  int nargin = args.length ();
+  bool overlaps = true;
+
+  if (nargin == 5 && args(3).is_string () && args(4).is_scalar_type ())
+    {
+      std::string opt = args(3).string_value ();
+      if (opt == "overlaps")
+        {
+          overlaps = args(4).bool_value ();
+          nargin = 3;
+        }
+      else
+        {
+          error ("strrep: unknown option: %s", opt.c_str ());
+          return retval;
+        }
+    }
+
+  if (nargin == 3)
+    {
+      octave_value argstr = args(0), argpat = args(1), argrep = args(2);
+      if (argpat.is_string () && argrep.is_string ())
+        {
+          const Array<char> pat = argpat.char_array_value ();
+          const Array<char> rep = argrep.char_array_value ();
+
+          OCTAVE_LOCAL_BUFFER (octave_idx_type, table, TABSIZE);
+          qs_preprocess (pat, table);
+
+          if (argstr.is_string ())
+            retval = qs_replace (argstr.char_array_value (), pat, rep, table, overlaps);
+          else if (argstr.is_cell ())
+            {
+              const Cell argsc = argstr.cell_value ();
+              Cell retc (argsc.dims ());
+              octave_idx_type ns = argsc.numel ();
+
+              for (octave_idx_type i = 0; i < ns; i++)
+                {
+                  octave_value argse = argsc(i);
+                  if (argse.is_string ())
+                    retc(i) = qs_replace (argse.char_array_value (), pat, rep, table, overlaps);
+                  else
+                    {
+                      error ("strrep: each element of S must be a string");
+                      break;
+                    }
+                }
+
+              retval = retc;
+            }
+          else
+            error ("strrep: S must be a string or cell array of strings");
+        }
+      else if (argpat.is_cell () || argrep.is_cell ())
+        retval = do_simple_cellfun (Fstrrep, "strrep", args);
+      else
+        error ("strrep: PTN and REP arguments must be strings or cell arrays of strings");
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!assert (strrep ("This is a test string", "is", "&%$"),
+%!                "Th&%$ &%$ a test string")
+%!assert (strrep ("abababc", "abab", "xyz"), "xyzxyzc")
+%!assert (strrep ("abababc", "abab", "xyz", "overlaps", false), "xyzabc")
+
+%!error strrep ()
+%!error strrep ("foo", "bar", 3, 4)
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/sub2ind.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,209 @@
+/*
+
+Copyright (C) 2009-2012 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "quit.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+
+
+static dim_vector
+get_dim_vector (const octave_value& val, const char *name)
+{
+  RowVector dimsv = val.row_vector_value (false, true);
+  dim_vector dv;
+  octave_idx_type n = dimsv.length ();
+
+  if (n < 1)
+    error ("%s: dimension vector DIMS must not be empty", name);
+  else
+    {
+      dv.resize (std::max (n, static_cast<octave_idx_type> (2)));
+      dv(1) = 1;
+      for (octave_idx_type i = 0; i < n; i++)
+        {
+          octave_idx_type ii = dimsv(i);
+          if (ii == dimsv(i) && ii >= 0)
+            dv(i) = ii;
+          else
+            {
+              error ("%s: dimension vector DIMS must contain integers", name);
+              break;
+            }
+        }
+    }
+
+  return dv;
+}
+
+DEFUN (sub2ind, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Function File} {@var{ind} =} sub2ind (@var{dims}, @var{i}, @var{j})\n\
+@deftypefnx {Function File} {@var{ind} =} sub2ind (@var{dims}, @var{s1}, @var{s2}, @dots{}, @var{sN})\n\
+Convert subscripts to a linear index.\n\
+\n\
+The following example shows how to convert the two-dimensional\n\
+index @code{(2,3)} of a 3-by-3 matrix to a linear index.  The matrix\n\
+is linearly indexed moving from one column to next, filling up\n\
+all rows in each column.\n\
+\n\
+@example\n\
+@group\n\
+linear_index = sub2ind ([3, 3], 2, 3)\n\
+@result{} 8\n\
+@end group\n\
+@end example\n\
+@seealso{ind2sub}\n\
+@end deftypefn")
+{
+  int nargin = args.length ();
+  octave_value retval;
+
+  if (nargin < 2)
+    print_usage ();
+  else
+    {
+      dim_vector dv = get_dim_vector (args(0), "sub2ind");
+      Array<idx_vector> idxa (dim_vector (nargin-1, 1));
+
+      if (! error_state)
+        {
+          dv = dv.redim (nargin - 1);
+          for (int j = 0; j < nargin - 1; j++)
+            {
+              if (args(j+1).is_numeric_type ())
+                {
+                  idxa(j) = args(j+1).index_vector ();
+                  if (error_state)
+                    break;
+                  else if (j > 0 && args(j+1).dims () != args(1).dims ())
+                    error ("sub2ind: all subscripts must be of the same size");
+                }
+              else
+                error ("sub2ind: subscripts must be numeric");
+
+              if (error_state)
+                break;
+            }
+        }
+
+      if (! error_state)
+        {
+          idx_vector idx = sub2ind (dv, idxa);
+          retval = idx;
+        }
+    }
+
+  return retval;
+}
+
+/*
+## Test evaluation
+%!test
+%! s1 = [ 1   1   1   1 ; 2   2   2   2 ];
+%! s2 = [ 1   1   2   2 ; 1   1   2   2 ];
+%! s3 = [ 1   2   1   2 ; 1   2   1   2 ];
+%! in = [ 1 101  11 111 ; 2 102  12 112 ];
+%! assert (sub2ind ([10 10 10], s1, s2, s3), in);
+
+# Test low index
+%!assert (sub2ind ([10 10 10], 1, 1, 1), 1)
+%!error <subscript indices> sub2ind ([10 10 10], 0, 1, 1)
+%!error <subscript indices> sub2ind ([10 10 10], 1, 0, 1)
+%!error <subscript indices> sub2ind ([10 10 10], 1, 1, 0)
+
+# Test high index
+%!assert (sub2ind ([10 10 10], 10, 10, 10), 1000)
+%!error <index out of range> sub2ind ([10 10 10], 11, 10, 10)
+%!error <index out of range> sub2ind ([10 10 10], 10, 11, 10)
+%!error <index out of range> sub2ind ([10 10 10], 10, 10, 11)
+
+# Test high index in the trailing dimensions
+%!assert (sub2ind ([10, 1], 2, 1, 1), 2)
+%!error <index out of range> sub2ind ([10, 1], 1, 2, 1)
+%!error <index out of range> sub2ind ([10, 1], 1, 1, 2)
+%!assert (sub2ind ([10 10], 2, 2, 1), 12)
+%!error <index out of range> sub2ind ([10 10], 2, 1, 2)
+%!error <index out of range> sub2ind ([10 10], 1, 2, 2)
+
+# Test handling of empty arguments
+%!assert (sub2ind ([10 10], zeros (0,0), zeros (0,0)), zeros (0,0))
+%!assert (sub2ind ([10 10], zeros (2,0), zeros (2,0)), zeros (2,0))
+%!assert (sub2ind ([10 10], zeros (0,2), zeros (0,2)), zeros (0,2))
+%!error <all subscripts .* same size> sub2ind ([10 10 10], zeros (0,2), zeros (2,0))
+
+# Test handling of arguments of different size
+%!error <all subscripts .* same size> sub2ind ([10 10], ones (1,2), ones (1,3))
+%!error <all subscripts .* same size> sub2ind ([10 10], ones (1,2), ones (2,1))
+
+## Test input validation
+%!error <dimension vector> sub2ind ([10 10.5], 1, 1)
+%!error <subscript indices> sub2ind ([10 10], 1.5, 1)
+%!error <subscript indices> sub2ind ([10 10], 1, 1.5)
+*/
+
+DEFUN (ind2sub, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Function File} {[@var{s1}, @var{s2}, @dots{}, @var{sN}] =} ind2sub (@var{dims}, @var{ind})\n\
+Convert a linear index to subscripts.\n\
+\n\
+The following example shows how to convert the linear index @code{8}\n\
+in a 3-by-3 matrix into a subscript.  The matrix is linearly indexed\n\
+moving from one column to next, filling up all rows in each column.\n\
+\n\
+@example\n\
+@group\n\
+[r, c] = ind2sub ([3, 3], 8)\n\
+    @result{} r =  2\n\
+    @result{} c =  3\n\
+@end group\n\
+@end example\n\
+@seealso{sub2ind}\n\
+@end deftypefn")
+{
+  int nargin = args.length ();
+  octave_value_list retval;
+
+  if (nargin != 2)
+    print_usage ();
+  else
+    {
+      dim_vector dv = get_dim_vector (args(0), "ind2sub");
+      idx_vector idx = args(1).index_vector ();
+      if (! error_state)
+        {
+          if (nargout > dv.length ())
+            dv = dv.redim (nargout);
+
+          Array<idx_vector> idxa = ind2sub (dv, idx);
+          retval = Array<octave_value> (idxa);
+        }
+    }
+
+  return retval;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/svd.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,423 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CmplxSVD.h"
+#include "dbleSVD.h"
+#include "fCmplxSVD.h"
+#include "floatSVD.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "pr-output.h"
+#include "utils.h"
+#include "variables.h"
+
+static int Vsvd_driver = SVD::GESVD;
+
+DEFUN (svd, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{s} =} svd (@var{A})\n\
+@deftypefnx {Built-in Function} {[@var{U}, @var{S}, @var{V}] =} svd (@var{A})\n\
+@deftypefnx {Built-in Function} {[@var{U}, @var{S}, @var{V}] =} svd (@var{A}, @var{econ})\n\
+@cindex singular value decomposition\n\
+Compute the singular value decomposition of @var{A}\n\
+@tex\n\
+$$\n\
+ A = U S V^{\\dagger}\n\
+$$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+A = U*S*V'\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+\n\
+The function @code{svd} normally returns only the vector of singular values.\n\
+When called with three return values, it computes\n\
+@tex\n\
+$U$, $S$, and $V$.\n\
+@end tex\n\
+@ifnottex\n\
+@var{U}, @var{S}, and @var{V}.\n\
+@end ifnottex\n\
+For example,\n\
+\n\
+@example\n\
+svd (hilb (3))\n\
+@end example\n\
+\n\
+@noindent\n\
+returns\n\
+\n\
+@example\n\
+@group\n\
+ans =\n\
+\n\
+  1.4083189\n\
+  0.1223271\n\
+  0.0026873\n\
+@end group\n\
+@end example\n\
+\n\
+@noindent\n\
+and\n\
+\n\
+@example\n\
+[u, s, v] = svd (hilb (3))\n\
+@end example\n\
+\n\
+@noindent\n\
+returns\n\
+\n\
+@example\n\
+@group\n\
+u =\n\
+\n\
+  -0.82704   0.54745   0.12766\n\
+  -0.45986  -0.52829  -0.71375\n\
+  -0.32330  -0.64901   0.68867\n\
+\n\
+s =\n\
+\n\
+  1.40832  0.00000  0.00000\n\
+  0.00000  0.12233  0.00000\n\
+  0.00000  0.00000  0.00269\n\
+\n\
+v =\n\
+\n\
+  -0.82704   0.54745   0.12766\n\
+  -0.45986  -0.52829  -0.71375\n\
+  -0.32330  -0.64901   0.68867\n\
+@end group\n\
+@end example\n\
+\n\
+If given a second argument, @code{svd} returns an economy-sized\n\
+decomposition, eliminating the unnecessary rows or columns of @var{U} or\n\
+@var{V}.\n\
+@seealso{svd_driver, svds, eig}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin < 1 || nargin > 2 || nargout == 2 || nargout > 3)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value arg = args(0);
+
+  octave_idx_type nr = arg.rows ();
+  octave_idx_type nc = arg.columns ();
+
+  if (arg.ndims () != 2)
+    {
+      error ("svd: A must be a 2-D matrix");
+      return retval;
+    }
+
+  bool isfloat = arg.is_single_type ();
+
+  SVD::type type = ((nargout == 0 || nargout == 1)
+                    ? SVD::sigma_only
+                    : (nargin == 2) ? SVD::economy : SVD::std);
+
+  SVD::driver driver = static_cast<SVD::driver> (Vsvd_driver);
+
+  if (nr == 0 || nc == 0)
+    {
+      if (isfloat)
+        {
+          switch (type)
+            {
+            case SVD::std:
+              retval(2) = FloatDiagMatrix (nc, nc, 1.0f);
+              retval(1) = FloatMatrix (nr, nc);
+              retval(0) = FloatDiagMatrix (nr, nr, 1.0f);
+              break;
+            case SVD::economy:
+              retval(2) = FloatDiagMatrix (0, nc, 1.0f);
+              retval(1) = FloatMatrix (0, 0);
+              retval(0) = FloatDiagMatrix (nr, 0, 1.0f);
+              break;
+            case SVD::sigma_only: default:
+              retval(0) = FloatMatrix (0, 1);
+              break;
+            }
+        }
+      else
+        {
+          switch (type)
+            {
+            case SVD::std:
+              retval(2) = DiagMatrix (nc, nc, 1.0);
+              retval(1) = Matrix (nr, nc);
+              retval(0) = DiagMatrix (nr, nr, 1.0);
+              break;
+            case SVD::economy:
+              retval(2) = DiagMatrix (0, nc, 1.0);
+              retval(1) = Matrix (0, 0);
+              retval(0) = DiagMatrix (nr, 0, 1.0);
+              break;
+            case SVD::sigma_only: default:
+              retval(0) = Matrix (0, 1);
+              break;
+            }
+        }
+    }
+  else
+    {
+      if (isfloat)
+        {
+          if (arg.is_real_type ())
+            {
+              FloatMatrix tmp = arg.float_matrix_value ();
+
+              if (! error_state)
+                {
+                  if (tmp.any_element_is_inf_or_nan ())
+                    {
+                      error ("svd: cannot take SVD of matrix containing Inf or NaN values");
+                      return retval;
+                    }
+
+                  FloatSVD result (tmp, type, driver);
+
+                  FloatDiagMatrix sigma = result.singular_values ();
+
+                  if (nargout == 0 || nargout == 1)
+                    {
+                      retval(0) = sigma.diag ();
+                    }
+                  else
+                    {
+                      retval(2) = result.right_singular_matrix ();
+                      retval(1) = sigma;
+                      retval(0) = result.left_singular_matrix ();
+                    }
+                }
+            }
+          else if (arg.is_complex_type ())
+            {
+              FloatComplexMatrix ctmp = arg.float_complex_matrix_value ();
+
+              if (! error_state)
+                {
+                  if (ctmp.any_element_is_inf_or_nan ())
+                    {
+                      error ("svd: cannot take SVD of matrix containing Inf or NaN values");
+                      return retval;
+                    }
+
+                  FloatComplexSVD result (ctmp, type, driver);
+
+                  FloatDiagMatrix sigma = result.singular_values ();
+
+                  if (nargout == 0 || nargout == 1)
+                    {
+                      retval(0) = sigma.diag ();
+                    }
+                  else
+                    {
+                      retval(2) = result.right_singular_matrix ();
+                      retval(1) = sigma;
+                      retval(0) = result.left_singular_matrix ();
+                    }
+                }
+            }
+        }
+      else
+        {
+          if (arg.is_real_type ())
+            {
+              Matrix tmp = arg.matrix_value ();
+
+              if (! error_state)
+                {
+                  if (tmp.any_element_is_inf_or_nan ())
+                    {
+                      error ("svd: cannot take SVD of matrix containing Inf or NaN values");
+                      return retval;
+                    }
+
+                  SVD result (tmp, type, driver);
+
+                  DiagMatrix sigma = result.singular_values ();
+
+                  if (nargout == 0 || nargout == 1)
+                    {
+                      retval(0) = sigma.diag ();
+                    }
+                  else
+                    {
+                      retval(2) = result.right_singular_matrix ();
+                      retval(1) = sigma;
+                      retval(0) = result.left_singular_matrix ();
+                    }
+                }
+            }
+          else if (arg.is_complex_type ())
+            {
+              ComplexMatrix ctmp = arg.complex_matrix_value ();
+
+              if (! error_state)
+                {
+                  if (ctmp.any_element_is_inf_or_nan ())
+                    {
+                      error ("svd: cannot take SVD of matrix containing Inf or NaN values");
+                      return retval;
+                    }
+
+                  ComplexSVD result (ctmp, type, driver);
+
+                  DiagMatrix sigma = result.singular_values ();
+
+                  if (nargout == 0 || nargout == 1)
+                    {
+                      retval(0) = sigma.diag ();
+                    }
+                  else
+                    {
+                      retval(2) = result.right_singular_matrix ();
+                      retval(1) = sigma;
+                      retval(0) = result.left_singular_matrix ();
+                    }
+                }
+            }
+          else
+            {
+              gripe_wrong_type_arg ("svd", arg);
+              return retval;
+            }
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!assert (svd ([1, 2; 2, 1]), [3; 1], sqrt (eps))
+
+%!test
+%! [u, s, v] = svd ([1, 2; 2, 1]);
+%! x = 1 / sqrt (2);
+%! assert (u, [-x, -x; -x, x], sqrt (eps));
+%! assert (s, [3, 0; 0, 1], sqrt (eps));
+%! assert (v, [-x, x; -x, -x], sqrt (eps));
+
+%!test
+%! a = [1, 2, 3; 4, 5, 6];
+%! [u, s, v] = svd (a);
+%! assert (u * s * v', a, sqrt (eps));
+
+%!test
+%! a = [1, 2; 3, 4; 5, 6];
+%! [u, s, v] = svd (a);
+%! assert (u * s * v', a, sqrt (eps));
+
+%!test
+%! a = [1, 2, 3; 4, 5, 6];
+%! [u, s, v] = svd (a, 1);
+%! assert (u * s * v', a, sqrt (eps));
+
+%!test
+%! a = [1, 2; 3, 4; 5, 6];
+%! [u, s, v] = svd (a, 1);
+%! assert (u * s * v', a, sqrt (eps));
+
+%!assert (svd (single ([1, 2; 2, 1])), single ([3; 1]), sqrt (eps ("single")))
+
+%!test
+%! [u, s, v] = svd (single ([1, 2; 2, 1]));
+%! x = single (1 / sqrt (2));
+%! assert (u, [-x, -x; -x, x], sqrt (eps ("single")));
+%! assert (s, single ([3, 0; 0, 1]), sqrt (eps ("single")));
+%! assert (v, [-x, x; -x, -x], sqrt (eps ("single")));
+
+%!test
+%! a = single ([1, 2, 3; 4, 5, 6]);
+%! [u, s, v] = svd (a);
+%! assert (u * s * v', a, sqrt (eps ("single")));
+
+%!test
+%! a = single ([1, 2; 3, 4; 5, 6]);
+%! [u, s, v] = svd (a);
+%! assert (u * s * v', a, sqrt (eps ("single")));
+
+%!test
+%! a = single ([1, 2, 3; 4, 5, 6]);
+%! [u, s, v] = svd (a, 1);
+%! assert (u * s * v', a, sqrt (eps ("single")));
+
+%!test
+%! a = single ([1, 2; 3, 4; 5, 6]);
+%! [u, s, v] = svd (a, 1);
+%! assert (u * s * v', a, sqrt (eps ("single")));
+
+%!test
+%! a = zeros (0, 5);
+%! [u, s, v] = svd (a);
+%! assert (size (u), [0, 0]);
+%! assert (size (s), [0, 5]);
+%! assert (size (v), [5, 5]);
+
+%!test
+%! a = zeros (5, 0);
+%! [u, s, v] = svd (a, 1);
+%! assert (size (u), [5, 0]);
+%! assert (size (s), [0, 0]);
+%! assert (size (v), [0, 0]);
+
+%!error svd ()
+%!error svd ([1, 2; 4, 5], 2, 3)
+%!error [u, v] = svd ([1, 2; 3, 4])
+*/
+
+DEFUN (svd_driver, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{val} =} svd_driver ()\n\
+@deftypefnx {Built-in Function} {@var{old_val} =} svd_driver (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} svd_driver (@var{new_val}, \"local\")\n\
+Query or set the underlying @sc{lapack} driver used by @code{svd}.\n\
+Currently recognized values are \"gesvd\" and \"gesdd\".  The default\n\
+is \"gesvd\".\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
+@seealso{svd}\n\
+@end deftypefn")
+{
+  static const char *driver_names[] = { "gesvd", "gesdd", 0 };
+
+  return SET_INTERNAL_VARIABLE_CHOICES (svd_driver, driver_names);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/syl.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,218 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+// Author: A. S. Hodel <scotte@eng.auburn.edu>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "utils.h"
+
+DEFUN (syl, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{x} =} syl (@var{A}, @var{B}, @var{C})\n\
+Solve the Sylvester equation\n\
+@tex\n\
+$$\n\
+ A X + X B + C = 0\n\
+$$\n\
+@end tex\n\
+@ifnottex\n\
+\n\
+@example\n\
+A X + X B + C = 0\n\
+@end example\n\
+\n\
+@end ifnottex\n\
+using standard @sc{lapack} subroutines.  For example:\n\
+\n\
+@example\n\
+@group\n\
+syl ([1, 2; 3, 4], [5, 6; 7, 8], [9, 10; 11, 12])\n\
+   @result{} [ -0.50000, -0.66667; -0.66667, -0.50000 ]\n\
+@end group\n\
+@end example\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin != 3 || nargout > 1)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  octave_value arg_a = args(0);
+  octave_value arg_b = args(1);
+  octave_value arg_c = args(2);
+
+  octave_idx_type a_nr = arg_a.rows ();
+  octave_idx_type a_nc = arg_a.columns ();
+
+  octave_idx_type b_nr = arg_b.rows ();
+  octave_idx_type b_nc = arg_b.columns ();
+
+  octave_idx_type c_nr = arg_c.rows ();
+  octave_idx_type c_nc = arg_c.columns ();
+
+  int arg_a_is_empty = empty_arg ("syl", a_nr, a_nc);
+  int arg_b_is_empty = empty_arg ("syl", b_nr, b_nc);
+  int arg_c_is_empty = empty_arg ("syl", c_nr, c_nc);
+
+  bool isfloat = arg_a.is_single_type () || arg_b.is_single_type () ||
+    arg_c.is_single_type ();
+
+  if (arg_a_is_empty > 0 && arg_b_is_empty > 0 && arg_c_is_empty > 0)
+    if (isfloat)
+      return octave_value (FloatMatrix ());
+    else
+      return octave_value (Matrix ());
+  else if (arg_a_is_empty || arg_b_is_empty || arg_c_is_empty)
+    return retval;
+
+  // Arguments are not empty, so check for correct dimensions.
+
+  if (a_nr != a_nc || b_nr != b_nc)
+    {
+      gripe_square_matrix_required ("syl: first two parameters:");
+      return retval;
+    }
+  else if (a_nr != c_nr || b_nr != c_nc)
+    {
+      gripe_nonconformant ();
+      return retval;
+    }
+
+  // Dimensions look o.k., let's solve the problem.
+  if (isfloat)
+    {
+      if (arg_a.is_complex_type ()
+          || arg_b.is_complex_type ()
+          || arg_c.is_complex_type ())
+        {
+          // Do everything in complex arithmetic;
+
+          FloatComplexMatrix ca = arg_a.float_complex_matrix_value ();
+
+          if (error_state)
+            return retval;
+
+          FloatComplexMatrix cb = arg_b.float_complex_matrix_value ();
+
+          if (error_state)
+            return retval;
+
+          FloatComplexMatrix cc = arg_c.float_complex_matrix_value ();
+
+          if (error_state)
+            return retval;
+
+          retval = Sylvester (ca, cb, cc);
+        }
+      else
+        {
+          // Do everything in real arithmetic.
+
+          FloatMatrix ca = arg_a.float_matrix_value ();
+
+          if (error_state)
+            return retval;
+
+          FloatMatrix cb = arg_b.float_matrix_value ();
+
+          if (error_state)
+            return retval;
+
+          FloatMatrix cc = arg_c.float_matrix_value ();
+
+          if (error_state)
+            return retval;
+
+          retval = Sylvester (ca, cb, cc);
+        }
+    }
+  else
+    {
+      if (arg_a.is_complex_type ()
+          || arg_b.is_complex_type ()
+          || arg_c.is_complex_type ())
+        {
+          // Do everything in complex arithmetic;
+
+          ComplexMatrix ca = arg_a.complex_matrix_value ();
+
+          if (error_state)
+            return retval;
+
+          ComplexMatrix cb = arg_b.complex_matrix_value ();
+
+          if (error_state)
+            return retval;
+
+          ComplexMatrix cc = arg_c.complex_matrix_value ();
+
+          if (error_state)
+            return retval;
+
+          retval = Sylvester (ca, cb, cc);
+        }
+      else
+        {
+          // Do everything in real arithmetic.
+
+          Matrix ca = arg_a.matrix_value ();
+
+          if (error_state)
+            return retval;
+
+          Matrix cb = arg_b.matrix_value ();
+
+          if (error_state)
+            return retval;
+
+          Matrix cc = arg_c.matrix_value ();
+
+          if (error_state)
+            return retval;
+
+          retval = Sylvester (ca, cb, cc);
+        }
+    }
+
+  return retval;
+}
+
+/*
+%!assert (syl ([1, 2; 3, 4], [5, 6; 7, 8], [9, 10; 11, 12]), [-1/2, -2/3; -2/3, -1/2], sqrt (eps))
+%!assert (syl (single ([1, 2; 3, 4]), single ([5, 6; 7, 8]), single ([9, 10; 11, 12])), single ([-1/2, -2/3; -2/3, -1/2]), sqrt (eps ("single")))
+
+%!error syl ()
+%!error syl (1, 2, 3, 4)
+%!error <must be a square matrix> syl ([1, 2; 3, 4], [1, 2, 3; 4, 5, 6], [4, 3])
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/time.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,539 @@
+/*
+
+Copyright (C) 1996-2012 John W. Eaton
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string>
+
+#include "defun.h"
+#include "error.h"
+#include "oct-map.h"
+#include "oct-time.h"
+#include "ov.h"
+#include "oct-obj.h"
+
+// Date and time functions.
+
+static octave_scalar_map
+mk_tm_map (const octave_base_tm& t)
+{
+  octave_scalar_map m;
+
+  m.assign ("usec", static_cast<double> (t.usec ()));
+  m.assign ("sec", static_cast<double> (t.sec ()));
+  m.assign ("min", static_cast<double> (t.min ()));
+  m.assign ("hour", static_cast<double> (t.hour ()));
+  m.assign ("mday", static_cast<double> (t.mday ()));
+  m.assign ("mon", static_cast<double> (t.mon ()));
+  m.assign ("year", static_cast<double> (t.year ()));
+  m.assign ("wday", static_cast<double> (t.wday ()));
+  m.assign ("yday", static_cast<double> (t.yday ()));
+  m.assign ("isdst", static_cast<double> (t.isdst ()));
+  m.assign ("zone", t.zone ());
+
+  return m;
+}
+
+static inline int
+intfield (const octave_scalar_map& m, const std::string& k)
+{
+  int retval = 0;
+
+  octave_value v = m.getfield (k);
+
+  if (! v.is_empty ())
+    retval = v.int_value ();
+
+  return retval;
+}
+
+static inline std::string
+stringfield (const octave_scalar_map& m, const std::string& k)
+{
+  std::string retval;
+
+  octave_value v = m.getfield (k);
+
+  if (! v.is_empty ())
+    retval = v.string_value ();
+
+  return retval;
+}
+
+static octave_base_tm
+extract_tm (const octave_scalar_map& m)
+{
+  octave_base_tm tm;
+
+  tm.usec (intfield (m, "usec"));
+  tm.sec (intfield (m, "sec"));
+  tm.min (intfield (m, "min"));
+  tm.hour (intfield (m, "hour"));
+  tm.mday (intfield (m, "mday"));
+  tm.mon (intfield (m, "mon"));
+  tm.year (intfield (m, "year"));
+  tm.wday (intfield (m, "wday"));
+  tm.yday (intfield (m, "yday"));
+  tm.isdst (intfield (m, "isdst"));
+  tm.zone (stringfield (m, "zone"));
+
+  return tm;
+}
+
+DEFUN (time, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{seconds} =} time ()\n\
+Return the current time as the number of seconds since the epoch.  The\n\
+epoch is referenced to 00:00:00 CUT (Coordinated Universal Time) 1 Jan\n\
+1970.  For example, on Monday February 17, 1997 at 07:15:06 CUT, the\n\
+value returned by @code{time} was 856163706.\n\
+@seealso{strftime, strptime, localtime, gmtime, mktime, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () == 0)
+    retval = octave_time ();
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!assert (time () > 0)
+*/
+
+DEFUN (gmtime, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{tm_struct} =} gmtime (@var{t})\n\
+Given a value returned from @code{time}, or any non-negative integer,\n\
+return a time structure corresponding to CUT (Coordinated Universal Time).\n\
+For example:\n\
+\n\
+@example\n\
+@group\n\
+gmtime (time ())\n\
+     @result{} @{\n\
+           usec = 0\n\
+           sec = 6\n\
+           min = 15\n\
+           hour = 7\n\
+           mday = 17\n\
+           mon = 1\n\
+           year = 97\n\
+           wday = 1\n\
+           yday = 47\n\
+           isdst = 0\n\
+           zone = CST\n\
+        @}\n\
+@end group\n\
+@end example\n\
+@seealso{strftime, strptime, localtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () == 1)
+    {
+      double tmp = args(0).double_value ();
+
+      if (! error_state)
+        retval = octave_value (mk_tm_map (octave_gmtime (tmp)));
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!test
+%! ts = gmtime (time ());
+%! assert (isstruct (ts));
+%! assert (isfield (ts, "usec"));
+%! assert (isfield (ts, "year"));
+%! assert (isfield (ts, "mon"));
+%! assert (isfield (ts, "mday"));
+%! assert (isfield (ts, "sec"));
+%! assert (isfield (ts, "min"));
+%! assert (isfield (ts, "wday"));
+%! assert (isfield (ts, "hour"));
+%! assert (isfield (ts, "isdst"));
+%! assert (isfield (ts, "yday"));
+
+%!error gmtime ()
+%!error gmtime (1, 2)
+*/
+
+DEFUN (localtime, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{tm_struct} =} localtime (@var{t})\n\
+Given a value returned from @code{time}, or any non-negative integer,\n\
+return a time structure corresponding to the local time zone.\n\
+\n\
+@example\n\
+@group\n\
+localtime (time ())\n\
+     @result{} @{\n\
+           usec = 0\n\
+           sec = 6\n\
+           min = 15\n\
+           hour = 1\n\
+           mday = 17\n\
+           mon = 1\n\
+           year = 97\n\
+           wday = 1\n\
+           yday = 47\n\
+           isdst = 0\n\
+           zone = CST\n\
+        @}\n\
+@end group\n\
+@end example\n\
+@seealso{strftime, strptime, gmtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () == 1)
+    {
+      double tmp = args(0).double_value ();
+
+      if (! error_state)
+        retval = octave_value (mk_tm_map (octave_localtime (tmp)));
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!test
+%! ts = localtime (time ());
+%! assert (isstruct (ts));
+%! assert (isfield (ts, "usec"));
+%! assert (isfield (ts, "year"));
+%! assert (isfield (ts, "mon"));
+%! assert (isfield (ts, "mday"));
+%! assert (isfield (ts, "sec"));
+%! assert (isfield (ts, "min"));
+%! assert (isfield (ts, "wday"));
+%! assert (isfield (ts, "hour"));
+%! assert (isfield (ts, "isdst"));
+%! assert (isfield (ts, "yday"));
+
+%!error localtime ()
+%!error localtime (1, 2)
+*/
+
+DEFUN (mktime, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{seconds} =} mktime (@var{tm_struct})\n\
+Convert a time structure corresponding to the local time to the number\n\
+of seconds since the epoch.  For example:\n\
+\n\
+@example\n\
+@group\n\
+mktime (localtime (time ()))\n\
+     @result{} 856163706\n\
+@end group\n\
+@end example\n\
+@seealso{strftime, strptime, localtime, gmtime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () == 1)
+    {
+      octave_scalar_map map = args(0).scalar_map_value ();
+
+      if (! error_state)
+        {
+          octave_base_tm tm = extract_tm (map);
+
+          if (! error_state)
+            retval = octave_time (tm);
+          else
+            error ("mktime: invalid TM_STRUCT argument");
+        }
+      else
+        error ("mktime: TM_STRUCT argument must be a structure");
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!test
+%! t = time ();
+%! assert (fix (mktime (localtime (t))) == fix (t));
+
+## These tests fail on systems with mktime functions of limited
+## intelligence:
+%!assert (datestr (datenum (1969, 1, 1), 0), "01-Jan-1969 00:00:00")
+%!assert (datestr (datenum (1901, 1, 1), 0), "01-Jan-1901 00:00:00")
+%!assert (datestr (datenum (1795, 1, 1), 0), "01-Jan-1795 00:00:00")
+
+%!error mktime ()
+%!error mktime (1, 2, 3)
+*/
+
+DEFUN (strftime, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} strftime (@var{fmt}, @var{tm_struct})\n\
+Format the time structure @var{tm_struct} in a flexible way using the\n\
+format string @var{fmt} that contains @samp{%} substitutions\n\
+similar to those in @code{printf}.  Except where noted, substituted\n\
+fields have a fixed size; numeric fields are padded if necessary.\n\
+Padding is with zeros by default; for fields that display a single\n\
+number, padding can be changed or inhibited by following the @samp{%}\n\
+with one of the modifiers described below.  Unknown field specifiers are\n\
+copied as normal characters.  All other characters are copied to the\n\
+output without change.  For example:\n\
+\n\
+@example\n\
+@group\n\
+strftime (\"%r (%Z) %A %e %B %Y\", localtime (time ()))\n\
+      @result{} \"01:15:06 AM (CST) Monday 17 February 1997\"\n\
+@end group\n\
+@end example\n\
+\n\
+Octave's @code{strftime} function supports a superset of the ANSI C\n\
+field specifiers.\n\
+\n\
+@noindent\n\
+Literal character fields:\n\
+\n\
+@table @code\n\
+@item %%\n\
+% character.\n\
+\n\
+@item %n\n\
+Newline character.\n\
+\n\
+@item %t\n\
+Tab character.\n\
+@end table\n\
+\n\
+@noindent\n\
+Numeric modifiers (a nonstandard extension):\n\
+\n\
+@table @code\n\
+@item - (dash)\n\
+Do not pad the field.\n\
+\n\
+@item _ (underscore)\n\
+Pad the field with spaces.\n\
+@end table\n\
+\n\
+@noindent\n\
+Time fields:\n\
+\n\
+@table @code\n\
+@item %H\n\
+Hour (00-23).\n\
+\n\
+@item %I\n\
+Hour (01-12).\n\
+\n\
+@item %k\n\
+Hour (0-23).\n\
+\n\
+@item %l\n\
+Hour (1-12).\n\
+\n\
+@item %M\n\
+Minute (00-59).\n\
+\n\
+@item %p\n\
+Locale's AM or PM.\n\
+\n\
+@item %r\n\
+Time, 12-hour (hh:mm:ss [AP]M).\n\
+\n\
+@item %R\n\
+Time, 24-hour (hh:mm).\n\
+\n\
+@item %s\n\
+Time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension).\n\
+\n\
+@item %S\n\
+Second (00-61).\n\
+\n\
+@item %T\n\
+Time, 24-hour (hh:mm:ss).\n\
+\n\
+@item %X\n\
+Locale's time representation (%H:%M:%S).\n\
+\n\
+@item %Z\n\
+Time zone (EDT), or nothing if no time zone is determinable.\n\
+@end table\n\
+\n\
+@noindent\n\
+Date fields:\n\
+\n\
+@table @code\n\
+@item %a\n\
+Locale's abbreviated weekday name (Sun-Sat).\n\
+\n\
+@item %A\n\
+Locale's full weekday name, variable length (Sunday-Saturday).\n\
+\n\
+@item %b\n\
+Locale's abbreviated month name (Jan-Dec).\n\
+\n\
+@item %B\n\
+Locale's full month name, variable length (January-December).\n\
+\n\
+@item %c\n\
+Locale's date and time (Sat Nov 04 12:02:33 EST 1989).\n\
+\n\
+@item %C\n\
+Century (00-99).\n\
+\n\
+@item %d\n\
+Day of month (01-31).\n\
+\n\
+@item %e\n\
+Day of month ( 1-31).\n\
+\n\
+@item %D\n\
+Date (mm/dd/yy).\n\
+\n\
+@item %h\n\
+Same as %b.\n\
+\n\
+@item %j\n\
+Day of year (001-366).\n\
+\n\
+@item %m\n\
+Month (01-12).\n\
+\n\
+@item %U\n\
+Week number of year with Sunday as first day of week (00-53).\n\
+\n\
+@item %w\n\
+Day of week (0-6).\n\
+\n\
+@item %W\n\
+Week number of year with Monday as first day of week (00-53).\n\
+\n\
+@item %x\n\
+Locale's date representation (mm/dd/yy).\n\
+\n\
+@item %y\n\
+Last two digits of year (00-99).\n\
+\n\
+@item %Y\n\
+Year (1970-).\n\
+@end table\n\
+@seealso{strptime, localtime, gmtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () == 2)
+    {
+      std::string fmt = args(0).string_value ();
+
+      if (! error_state)
+        {
+          octave_scalar_map map = args(1).scalar_map_value ();
+
+          if (! error_state)
+            {
+              octave_base_tm tm = extract_tm (map);
+
+              if (! error_state)
+                retval = tm.strftime (fmt);
+              else
+                error ("strftime: invalid TM_STRUCT argument");
+            }
+          else
+            error ("strftime: TM_STRUCT must be a structure");
+        }
+      else
+        error ("strftime: FMT must be a string");
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!assert (ischar (strftime ("%%%n%t%H%I%k%l", localtime (time ()))));
+%!assert (ischar (strftime ("%M%p%r%R%s%S%T", localtime (time ()))));
+%!assert (ischar (strftime ("%X%Z%z%a%A%b%B", localtime (time ()))));
+%!assert (ischar (strftime ("%c%C%d%e%D%h%j", localtime (time ()))));
+%!assert (ischar (strftime ("%m%U%w%W%x%y%Y", localtime (time ()))));
+
+%!error strftime ()
+%!error strftime ("foo", localtime (time ()), 1)
+*/
+
+DEFUN (strptime, args, ,
+ "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {[@var{tm_struct}, @var{nchars}] =} strptime (@var{str}, @var{fmt})\n\
+Convert the string @var{str} to the time structure @var{tm_struct} under\n\
+the control of the format string @var{fmt}.\n\
+\n\
+If @var{fmt} fails to match, @var{nchars} is 0; otherwise, it is set to the\n\
+position of last matched character plus 1. Always check for this unless\n\
+you're absolutely sure the date string will be parsed correctly.\n\
+@seealso{strftime, localtime, gmtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  if (args.length () == 2)
+    {
+      std::string str = args(0).string_value ();
+
+      if (! error_state)
+        {
+          std::string fmt = args(1).string_value ();
+
+          if (! error_state)
+            {
+              octave_strptime t (str, fmt);
+
+              retval(1) = t.characters_converted ();
+              retval(0) = octave_value (mk_tm_map (t));
+            }
+          else
+            error ("strptime: FMT must be a string");
+        }
+      else
+        error ("strptime: argument STR must be a string");
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/tril.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,430 @@
+/*
+
+Copyright (C) 2004-2012 David Bateman
+Copyright (C) 2009 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <algorithm>
+#include "Array.h"
+#include "Sparse.h"
+#include "mx-base.h"
+
+#include "ov.h"
+#include "Cell.h"
+
+#include "defun.h"
+#include "error.h"
+#include "oct-obj.h"
+
+// The bulk of the work.
+template <class T>
+static Array<T>
+do_tril (const Array<T>& a, octave_idx_type k, bool pack)
+{
+  octave_idx_type nr = a.rows (), nc = a.columns ();
+  const T *avec = a.fortran_vec ();
+  octave_idx_type zero = 0;
+
+  if (pack)
+    {
+      octave_idx_type j1 = std::min (std::max (zero, k), nc);
+      octave_idx_type j2 = std::min (std::max (zero, nr + k), nc);
+      octave_idx_type n = j1 * nr + ((j2 - j1) * (nr-(j1-k) + nr-(j2-1-k))) / 2;
+      Array<T> r (dim_vector (n, 1));
+      T *rvec = r.fortran_vec ();
+      for (octave_idx_type j = 0; j < nc; j++)
+        {
+          octave_idx_type ii = std::min (std::max (zero, j - k), nr);
+          rvec = std::copy (avec + ii, avec + nr, rvec);
+          avec += nr;
+        }
+
+      return r;
+    }
+  else
+    {
+      Array<T> r (a.dims ());
+      T *rvec = r.fortran_vec ();
+      for (octave_idx_type j = 0; j < nc; j++)
+        {
+          octave_idx_type ii = std::min (std::max (zero, j - k), nr);
+          std::fill (rvec, rvec + ii, T ());
+          std::copy (avec + ii, avec + nr, rvec + ii);
+          avec += nr;
+          rvec += nr;
+        }
+
+      return r;
+    }
+}
+
+template <class T>
+static Array<T>
+do_triu (const Array<T>& a, octave_idx_type k, bool pack)
+{
+  octave_idx_type nr = a.rows (), nc = a.columns ();
+  const T *avec = a.fortran_vec ();
+  octave_idx_type zero = 0;
+
+  if (pack)
+    {
+      octave_idx_type j1 = std::min (std::max (zero, k), nc);
+      octave_idx_type j2 = std::min (std::max (zero, nr + k), nc);
+      octave_idx_type n = ((j2 - j1) * ((j1+1-k) + (j2-k))) / 2 + (nc - j2) * nr;
+      Array<T> r (dim_vector (n, 1));
+      T *rvec = r.fortran_vec ();
+      for (octave_idx_type j = 0; j < nc; j++)
+        {
+          octave_idx_type ii = std::min (std::max (zero, j + 1 - k), nr);
+          rvec = std::copy (avec, avec + ii, rvec);
+          avec += nr;
+        }
+
+      return r;
+    }
+  else
+    {
+      NoAlias<Array<T> > r (a.dims ());
+      T *rvec = r.fortran_vec ();
+      for (octave_idx_type j = 0; j < nc; j++)
+        {
+          octave_idx_type ii = std::min (std::max (zero, j + 1 - k), nr);
+          std::copy (avec, avec + ii, rvec);
+          std::fill (rvec + ii, rvec + nr, T ());
+          avec += nr;
+          rvec += nr;
+        }
+
+      return r;
+    }
+}
+
+// These two are by David Bateman.
+// FIXME: optimizations possible. "pack" support missing.
+
+template <class T>
+static Sparse<T>
+do_tril (const Sparse<T>& a, octave_idx_type k, bool pack)
+{
+  if (pack) // FIXME
+    {
+      error ("tril: \"pack\" not implemented for sparse matrices");
+      return Sparse<T> ();
+    }
+
+  Sparse<T> m = a;
+  octave_idx_type nc = m.cols ();
+
+  for (octave_idx_type j = 0; j < nc; j++)
+    for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++)
+      if (m.ridx (i) < j-k)
+        m.data(i) = 0.;
+
+  m.maybe_compress (true);
+  return m;
+}
+
+template <class T>
+static Sparse<T>
+do_triu (const Sparse<T>& a, octave_idx_type k, bool pack)
+{
+  if (pack) // FIXME
+    {
+      error ("triu: \"pack\" not implemented for sparse matrices");
+      return Sparse<T> ();
+    }
+
+  Sparse<T> m = a;
+  octave_idx_type nc = m.cols ();
+
+  for (octave_idx_type j = 0; j < nc; j++)
+    for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++)
+      if (m.ridx (i) > j-k)
+        m.data(i) = 0.;
+
+  m.maybe_compress (true);
+  return m;
+}
+
+// Convenience dispatchers.
+template <class T>
+static Array<T>
+do_trilu (const Array<T>& a, octave_idx_type k, bool lower, bool pack)
+{
+  return lower ? do_tril (a, k, pack) : do_triu (a, k, pack);
+}
+
+template <class T>
+static Sparse<T>
+do_trilu (const Sparse<T>& a, octave_idx_type k, bool lower, bool pack)
+{
+  return lower ? do_tril (a, k, pack) : do_triu (a, k, pack);
+}
+
+static octave_value
+do_trilu (const std::string& name,
+          const octave_value_list& args)
+{
+  bool lower = name == "tril";
+
+  octave_value retval;
+  int nargin = args.length ();
+  octave_idx_type k = 0;
+  bool pack = false;
+  if (nargin >= 2 && args(nargin-1).is_string ())
+    {
+      pack = args(nargin-1).string_value () == "pack";
+      nargin--;
+    }
+
+  if (nargin == 2)
+    {
+      k = args(1).int_value (true);
+
+      if (error_state)
+        return retval;
+    }
+
+  if (nargin < 1 || nargin > 2)
+    print_usage ();
+  else
+    {
+      octave_value arg = args (0);
+
+      dim_vector dims = arg.dims ();
+      if (dims.length () != 2)
+        error ("%s: need a 2-D matrix", name.c_str ());
+      else if (k < -dims (0) || k > dims(1))
+        error ("%s: requested diagonal out of range", name.c_str ());
+      else
+        {
+          switch (arg.builtin_type ())
+            {
+            case btyp_double:
+              if (arg.is_sparse_type ())
+                retval = do_trilu (arg.sparse_matrix_value (), k, lower, pack);
+              else
+                retval = do_trilu (arg.array_value (), k, lower, pack);
+              break;
+            case btyp_complex:
+              if (arg.is_sparse_type ())
+                retval = do_trilu (arg.sparse_complex_matrix_value (), k, lower, pack);
+              else
+                retval = do_trilu (arg.complex_array_value (), k, lower, pack);
+              break;
+            case btyp_bool:
+              if (arg.is_sparse_type ())
+                retval = do_trilu (arg.sparse_bool_matrix_value (), k, lower, pack);
+              else
+                retval = do_trilu (arg.bool_array_value (), k, lower, pack);
+              break;
+#define ARRAYCASE(TYP) \
+            case btyp_ ## TYP: \
+              retval = do_trilu (arg.TYP ## _array_value (), k, lower, pack); \
+              break
+            ARRAYCASE (float);
+            ARRAYCASE (float_complex);
+            ARRAYCASE (int8);
+            ARRAYCASE (int16);
+            ARRAYCASE (int32);
+            ARRAYCASE (int64);
+            ARRAYCASE (uint8);
+            ARRAYCASE (uint16);
+            ARRAYCASE (uint32);
+            ARRAYCASE (uint64);
+            ARRAYCASE (char);
+#undef ARRAYCASE
+            default:
+              {
+                // Generic code that works on octave-values, that is slow
+                // but will also work on arbitrary user types
+
+                if (pack) // FIXME
+                  {
+                    error ("%s: \"pack\" not implemented for class %s",
+                           name.c_str (), arg.class_name ().c_str ());
+                    return octave_value ();
+                  }
+
+                octave_value tmp = arg;
+                if (arg.numel () == 0)
+                  return arg;
+
+                octave_idx_type nr = dims(0), nc = dims (1);
+
+                // The sole purpose of the below is to force the correct
+                // matrix size. This would not be necessary if the
+                // octave_value resize function allowed a fill_value.
+                // It also allows odd attributes in some user types
+                // to be handled. With a fill_value ot should be replaced
+                // with
+                //
+                // octave_value_list ov_idx;
+                // tmp = tmp.resize(dim_vector (0,0)).resize (dims, fill_value);
+
+                octave_value_list ov_idx;
+                std::list<octave_value_list> idx_tmp;
+                ov_idx(1) = static_cast<double> (nc+1);
+                ov_idx(0) = Range (1, nr);
+                idx_tmp.push_back (ov_idx);
+                ov_idx(1) = static_cast<double> (nc);
+                tmp = tmp.resize (dim_vector (0,0));
+                tmp = tmp.subsasgn ("(",idx_tmp, arg.do_index_op (ov_idx));
+                tmp = tmp.resize (dims);
+
+                if (lower)
+                  {
+                    octave_idx_type st = nc < nr + k ? nc : nr + k;
+
+                    for (octave_idx_type j = 1; j <= st; j++)
+                      {
+                        octave_idx_type nr_limit = 1 > j - k ? 1 : j - k;
+                        ov_idx(1) = static_cast<double> (j);
+                        ov_idx(0) = Range (nr_limit, nr);
+                        std::list<octave_value_list> idx;
+                        idx.push_back (ov_idx);
+
+                        tmp = tmp.subsasgn ("(", idx, arg.do_index_op (ov_idx));
+
+                        if (error_state)
+                          return retval;
+                      }
+                  }
+                else
+                  {
+                    octave_idx_type st = k + 1 > 1 ? k + 1 : 1;
+
+                    for (octave_idx_type j = st; j <= nc; j++)
+                      {
+                        octave_idx_type nr_limit = nr < j - k ? nr : j - k;
+                        ov_idx(1) = static_cast<double> (j);
+                        ov_idx(0) = Range (1, nr_limit);
+                        std::list<octave_value_list> idx;
+                        idx.push_back (ov_idx);
+
+                        tmp = tmp.subsasgn ("(", idx, arg.do_index_op (ov_idx));
+
+                        if (error_state)
+                          return retval;
+                      }
+                  }
+
+                retval = tmp;
+              }
+            }
+        }
+    }
+
+  return retval;
+}
+
+DEFUN (tril, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Function File} {} tril (@var{A})\n\
+@deftypefnx {Function File} {} tril (@var{A}, @var{k})\n\
+@deftypefnx {Function File} {} tril (@var{A}, @var{k}, @var{pack})\n\
+@deftypefnx {Function File} {} triu (@var{A})\n\
+@deftypefnx {Function File} {} triu (@var{A}, @var{k})\n\
+@deftypefnx {Function File} {} triu (@var{A}, @var{k}, @var{pack})\n\
+Return a new matrix formed by extracting the lower (@code{tril})\n\
+or upper (@code{triu}) triangular part of the matrix @var{A}, and\n\
+setting all other elements to zero.  The second argument is optional,\n\
+and specifies how many diagonals above or below the main diagonal should\n\
+also be set to zero.\n\
+\n\
+The default value of @var{k} is zero, so that @code{triu} and\n\
+@code{tril} normally include the main diagonal as part of the result.\n\
+\n\
+If the value of @var{k} is negative, additional elements above (for\n\
+@code{tril}) or below (for @code{triu}) the main diagonal are also\n\
+selected.\n\
+\n\
+The absolute value of @var{k} must not be greater than the number of\n\
+sub-diagonals or super-diagonals.\n\
+\n\
+For example:\n\
+\n\
+@example\n\
+@group\n\
+tril (ones (3), -1)\n\
+     @result{}  0  0  0\n\
+         1  0  0\n\
+         1  1  0\n\
+@end group\n\
+@end example\n\
+\n\
+@noindent\n\
+and\n\
+\n\
+@example\n\
+@group\n\
+tril (ones (3), 1)\n\
+     @result{}  1  1  0\n\
+         1  1  1\n\
+         1  1  1\n\
+@end group\n\
+@end example\n\
+\n\
+If the option \"pack\" is given as third argument, the extracted elements\n\
+are not inserted into a matrix, but rather stacked column-wise one above\n\
+other.\n\
+@seealso{diag}\n\
+@end deftypefn")
+{
+  return do_trilu ("tril", args);
+}
+
+DEFUN (triu, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Function File} {} triu (@var{A})\n\
+@deftypefnx {Function File} {} triu (@var{A}, @var{k})\n\
+@deftypefnx {Function File} {} triu (@var{A}, @var{k}, @var{pack})\n\
+See the documentation for the @code{tril} function (@pxref{tril}).\n\
+@end deftypefn")
+{
+  return do_trilu ("triu", args);
+}
+
+/*
+%!test
+%! a = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12];
+%!
+%! l0 = [1, 0, 0; 4, 5, 0; 7, 8, 9; 10, 11, 12];
+%! l1 = [1, 2, 0; 4, 5, 6; 7, 8, 9; 10, 11, 12];
+%! l2 = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12];
+%! lm1 = [0, 0, 0; 4, 0, 0; 7, 8, 0; 10, 11, 12];
+%! lm2 = [0, 0, 0; 0, 0, 0; 7, 0, 0; 10, 11, 0];
+%! lm3 = [0, 0, 0; 0, 0, 0; 0, 0, 0; 10, 0, 0];
+%! lm4 = [0, 0, 0; 0, 0, 0; 0, 0, 0; 0, 0, 0];
+%!
+%! assert (tril (a, -4), lm4); 
+%! assert (tril (a, -3), lm3);
+%! assert (tril (a, -2), lm2);
+%! assert (tril (a, -1), lm1);
+%! assert (tril (a), l0);
+%! assert (tril (a, 1), l1);
+%! assert (tril (a, 2), l2);
+
+%!error tril ()
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/corefcn/typecast.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -0,0 +1,460 @@
+/*
+
+Copyright (C) 2007-2012 David Bateman
+Copyright (C) 2009 VZLU Prague
+
+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/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "mx-base.h"
+
+#include "defun.h"
+#include "error.h"
+#include "gripes.h"
+#include "oct-obj.h"
+#include "unwind-prot.h"
+
+static dim_vector
+get_vec_dims (const dim_vector& old_dims, octave_idx_type n)
+{
+  if (old_dims.length () == 2 && old_dims(0) == 1)
+    return dim_vector (1, n);
+  else if (old_dims.length () == 2 && old_dims (0) == 0 && old_dims (1) == 0)
+    return dim_vector ();
+  else
+    return dim_vector (n, 1);
+}
+
+template <class ArrayType>
+static void
+get_data_and_bytesize (const ArrayType& array,
+                       const void *& data,
+                       octave_idx_type& byte_size,
+                       dim_vector& old_dims,
+                       unwind_protect& frame)
+{
+  // The array given may be a temporary, constructed from a scalar or sparse
+  // array. This will ensure the data will be deallocated after we exit.
+  frame.add_delete (new ArrayType (array));
+
+  data = reinterpret_cast<const void *> (array.data ());
+  byte_size = array.byte_size ();
+
+  old_dims = array.dims ();
+}
+
+template <class ArrayType>
+static ArrayType
+reinterpret_copy (const void *data, octave_idx_type byte_size,
+                  const dim_vector& old_dims)
+{
+  typedef typename ArrayType::element_type T;
+  octave_idx_type n = byte_size / sizeof (T);
+
+  if (n * static_cast<int> (sizeof (T)) == byte_size)
+    {
+      ArrayType retval (get_vec_dims (old_dims, n));
+      T *dest = retval.fortran_vec ();
+      std::memcpy (dest, data, n * sizeof (T));
+
+      return retval;
+    }
+  else
+    {
+      error ("typecast: incorrect number of input values to make output value");
+      return ArrayType ();
+    }
+}
+
+
+DEFUN (typecast, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} typecast (@var{x}, @var{class})\n\
+Return a new array @var{y} resulting from interpreting the data of\n\
+@var{x} in memory as data of the numeric class @var{class}.  Both the class\n\
+of @var{x} and @var{class} must be one of the built-in numeric classes:\n\
+\n\
+@example\n\
+@group\n\
+\"logical\"\n\
+\"char\"\n\
+\"int8\"\n\
+\"int16\"\n\
+\"int32\"\n\
+\"int64\"\n\
+\"uint8\"\n\
+\"uint16\"\n\
+\"uint32\"\n\
+\"uint64\"\n\
+\"double\"\n\
+\"single\"\n\
+\"double complex\"\n\
+\"single complex\"\n\
+@end group\n\
+@end example\n\
+\n\
+@noindent\n\
+the last two are reserved for @var{class}; they indicate that a\n\
+complex-valued result is requested.  Complex arrays are stored in memory as\n\
+consecutive pairs of real numbers.  The sizes of integer types are given by\n\
+their bit counts.  Both logical and char are typically one byte wide;\n\
+however, this is not guaranteed by C++.  If your system is IEEE conformant,\n\
+single and double should be 4 bytes and 8 bytes wide, respectively.\n\
+\"logical\" is not allowed for @var{class}.  If the input is a row vector,\n\
+the return value is a row vector, otherwise it is a column vector.  If the\n\
+bit length of @var{x} is not divisible by that of @var{class}, an error\n\
+occurs.\n\
+\n\
+An example of the use of typecast on a little-endian machine is\n\
+\n\
+@example\n\
+@group\n\
+@var{x} = uint16 ([1, 65535]);\n\
+typecast (@var{x}, \"uint8\")\n\
+  @result{} [   0,   1, 255, 255]\n\
+@end group\n\
+@end example\n\
+@seealso{cast, bitunpack, bitpack, swapbytes}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () == 2)
+    {
+      unwind_protect frame;
+      const void *data = 0;
+      octave_idx_type byte_size = 0;
+      dim_vector old_dims;
+
+      octave_value array = args(0);
+
+      if (array.is_bool_type ())
+        get_data_and_bytesize (array.bool_array_value (), data, byte_size, old_dims, frame);
+      else if (array.is_string ())
+        get_data_and_bytesize (array.char_array_value (), data, byte_size, old_dims, frame);
+      else if (array.is_integer_type ())
+        {
+          if (array.is_int8_type ())
+            get_data_and_bytesize (array.int8_array_value (), data, byte_size, old_dims, frame);
+          else if (array.is_int16_type ())
+            get_data_and_bytesize (array.int16_array_value (), data, byte_size, old_dims, frame);
+          else if (array.is_int32_type ())
+            get_data_and_bytesize (array.int32_array_value (), data, byte_size, old_dims, frame);
+          else if (array.is_int64_type ())
+            get_data_and_bytesize (array.int64_array_value (), data, byte_size, old_dims, frame);
+          else if (array.is_uint8_type ())
+            get_data_and_bytesize (array.uint8_array_value (), data, byte_size, old_dims, frame);
+          else if (array.is_uint16_type ())
+            get_data_and_bytesize (array.uint16_array_value (), data, byte_size, old_dims, frame);
+          else if (array.is_uint32_type ())
+            get_data_and_bytesize (array.uint32_array_value (), data, byte_size, old_dims, frame);
+          else if (array.is_uint64_type ())
+            get_data_and_bytesize (array.uint64_array_value (), data, byte_size, old_dims, frame);
+          else
+            assert (0);
+        }
+      else if (array.is_complex_type ())
+        {
+          if (array.is_single_type ())
+            get_data_and_bytesize (array.float_complex_array_value (), data, byte_size, old_dims, frame);
+          else
+            get_data_and_bytesize (array.complex_array_value (), data, byte_size, old_dims, frame);
+        }
+      else if (array.is_real_type ())
+        {
+          if (array.is_single_type ())
+            get_data_and_bytesize (array.float_array_value (), data, byte_size, old_dims, frame);
+          else
+            get_data_and_bytesize (array.array_value (), data, byte_size, old_dims, frame);
+        }
+      else
+        error ("typecast: invalid input class: %s", array.class_name ().c_str ());
+
+      std::string numclass = args(1).string_value ();
+
+      if (error_state || numclass.size () == 0)
+        ;
+      else if (numclass == "char")
+        retval = octave_value (reinterpret_copy<charNDArray> (data, byte_size, old_dims), array.is_dq_string () ? '"' : '\'');
+      else if (numclass[0] == 'i')
+        {
+          if (numclass == "int8")
+            retval = reinterpret_copy<int8NDArray> (data, byte_size, old_dims);
+          else if (numclass == "int16")
+            retval = reinterpret_copy<int16NDArray> (data, byte_size, old_dims);
+          else if (numclass == "int32")
+            retval = reinterpret_copy<int32NDArray> (data, byte_size, old_dims);
+          else if (numclass == "int64")
+            retval = reinterpret_copy<int64NDArray> (data, byte_size, old_dims);
+        }
+      else if (numclass[0] == 'u')
+        {
+          if (numclass == "uint8")
+            retval = reinterpret_copy<uint8NDArray> (data, byte_size, old_dims);
+          else if (numclass == "uint16")
+            retval = reinterpret_copy<uint16NDArray> (data, byte_size, old_dims);
+          else if (numclass == "uint32")
+            retval = reinterpret_copy<uint32NDArray> (data, byte_size, old_dims);
+          else if (numclass == "uint64")
+            retval = reinterpret_copy<uint64NDArray> (data, byte_size, old_dims);
+        }
+      else if (numclass == "single")
+        retval = reinterpret_copy<FloatNDArray> (data, byte_size, old_dims);
+      else if (numclass == "double")
+        retval = reinterpret_copy<NDArray> (data, byte_size, old_dims);
+      else if (numclass == "single complex")
+        retval = reinterpret_copy<FloatComplexNDArray> (data, byte_size, old_dims);
+      else if (numclass == "double complex")
+        retval = reinterpret_copy<ComplexNDArray> (data, byte_size, old_dims);
+
+      if (! error_state && retval.is_undefined ())
+        error ("typecast: cannot convert to %s class", numclass.c_str ());
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+template <class ArrayType>
+ArrayType
+do_bitpack (const boolNDArray& bitp)
+{
+  typedef typename ArrayType::element_type T;
+  octave_idx_type n = bitp.numel () / (sizeof (T) * CHAR_BIT);
+
+  if (n * static_cast<int> (sizeof (T)) * CHAR_BIT == bitp.numel ())
+    {
+
+      ArrayType retval (get_vec_dims (bitp.dims (), n));
+
+      const bool *bits = bitp.fortran_vec ();
+      char *packed = reinterpret_cast<char *> (retval.fortran_vec ());
+
+      octave_idx_type m = n * sizeof (T);
+
+      for (octave_idx_type i = 0; i < m; i++)
+        {
+          char c = bits[0];
+          for (int j = 1; j < CHAR_BIT; j++)
+            c |= bits[j] << j;
+
+          packed[i] = c;
+          bits += CHAR_BIT;
+        }
+
+      return retval;
+    }
+  else
+    {
+      error ("bitpack: incorrect number of bits to make up output value");
+      return ArrayType ();
+    }
+}
+
+DEFUN (bitpack, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{y} =} bitpack (@var{x}, @var{class})\n\
+Return a new array @var{y} resulting from interpreting an array\n\
+@var{x} as raw bit patterns for data of the numeric class @var{class}.\n\
+@var{class} must be one of the built-in numeric classes:\n\
+\n\
+@example\n\
+@group\n\
+\"char\"\n\
+\"int8\"\n\
+\"int16\"\n\
+\"int32\"\n\
+\"int64\"\n\
+\"uint8\"\n\
+\"uint16\"\n\
+\"uint32\"\n\
+\"uint64\"\n\
+\"double\"\n\
+\"single\"\n\
+@end group\n\
+@end example\n\
+\n\
+The number of elements of @var{x} should be divisible by the bit length of\n\
+@var{class}.  If it is not, excess bits are discarded.  Bits come in\n\
+increasing order of significance, i.e., @code{x(1)} is bit 0, @code{x(2)} is\n\
+bit 1, etc.  The result is a row vector if @var{x} is a row vector, otherwise\n\
+it is a column vector.\n\
+@seealso{bitunpack, typecast}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () == 2 && args(0).is_bool_type ())
+    {
+      boolNDArray bitp = args(0).bool_array_value ();
+
+      std::string numclass = args(1).string_value ();
+
+      if (error_state || numclass.size () == 0)
+        ;
+      else if (numclass == "char")
+        retval = octave_value (do_bitpack<charNDArray> (bitp), '\'');
+      else if (numclass[0] == 'i')
+        {
+          if (numclass == "int8")
+            retval = do_bitpack<int8NDArray> (bitp);
+          else if (numclass == "int16")
+            retval = do_bitpack<int16NDArray> (bitp);
+          else if (numclass == "int32")
+            retval = do_bitpack<int32NDArray> (bitp);
+          else if (numclass == "int64")
+            retval = do_bitpack<int64NDArray> (bitp);
+        }
+      else if (numclass[0] == 'u')
+        {
+          if (numclass == "uint8")
+            retval = do_bitpack<uint8NDArray> (bitp);
+          else if (numclass == "uint16")
+            retval = do_bitpack<uint16NDArray> (bitp);
+          else if (numclass == "uint32")
+            retval = do_bitpack<uint32NDArray> (bitp);
+          else if (numclass == "uint64")
+            retval = do_bitpack<uint64NDArray> (bitp);
+        }
+      else if (numclass == "single")
+        retval = do_bitpack<FloatNDArray> (bitp);
+      else if (numclass == "double")
+        retval = do_bitpack<NDArray> (bitp);
+      else if (numclass == "single complex")
+        retval = do_bitpack<FloatComplexNDArray> (bitp);
+      else if (numclass == "double complex")
+        retval = do_bitpack<ComplexNDArray> (bitp);
+
+      if (! error_state && retval.is_undefined ())
+        error ("bitpack: cannot pack to %s class", numclass.c_str ());
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+template <class ArrayType>
+boolNDArray
+do_bitunpack (const ArrayType& array)
+{
+  typedef typename ArrayType::element_type T;
+  octave_idx_type n = array.numel () * sizeof (T) * CHAR_BIT;
+
+  boolNDArray retval (get_vec_dims (array.dims (), n));
+
+  const char *packed = reinterpret_cast<const char *> (array.fortran_vec ());
+  bool *bits = retval.fortran_vec ();
+
+  octave_idx_type m = n / CHAR_BIT;
+
+  for (octave_idx_type i = 0; i < m; i++)
+    {
+      char c = packed[i];
+      bits[0] = c & 1;
+      for (int j = 1; j < CHAR_BIT; j++)
+        bits[j] = (c >>= 1) & 1;
+      bits += CHAR_BIT;
+    }
+
+  return retval;
+}
+
+DEFUN (bitunpack, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{y} =} bitunpack (@var{x})\n\
+Return an array @var{y} corresponding to the raw bit patterns of\n\
+@var{x}.  @var{x} must belong to one of the built-in numeric classes:\n\
+\n\
+@example\n\
+@group\n\
+\"char\"\n\
+\"int8\"\n\
+\"int16\"\n\
+\"int32\"\n\
+\"int64\"\n\
+\"uint8\"\n\
+\"uint16\"\n\
+\"uint32\"\n\
+\"uint64\"\n\
+\"double\"\n\
+\"single\"\n\
+@end group\n\
+@end example\n\
+\n\
+The result is a row vector if @var{x} is a row vector; otherwise, it is a\n\
+column vector.\n\
+@seealso{bitpack, typecast}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () == 1 && (args(0).is_numeric_type () || args(0).is_string ()))
+    {
+      octave_value array = args(0);
+
+      if (array.is_string ())
+        retval = do_bitunpack (array.char_array_value ());
+      else if (array.is_integer_type ())
+        {
+          if (array.is_int8_type ())
+            retval = do_bitunpack (array.int8_array_value ());
+          else if (array.is_int16_type ())
+            retval = do_bitunpack (array.int16_array_value ());
+          else if (array.is_int32_type ())
+            retval = do_bitunpack (array.int32_array_value ());
+          else if (array.is_int64_type ())
+            retval = do_bitunpack (array.int64_array_value ());
+          else if (array.is_uint8_type ())
+            retval = do_bitunpack (array.uint8_array_value ());
+          else if (array.is_uint16_type ())
+            retval = do_bitunpack (array.uint16_array_value ());
+          else if (array.is_uint32_type ())
+            retval = do_bitunpack (array.uint32_array_value ());
+          else if (array.is_uint64_type ())
+            retval = do_bitunpack (array.uint64_array_value ());
+          else
+            assert (0);
+        }
+      else if (array.is_complex_type ())
+        {
+          if (array.is_single_type ())
+            retval = do_bitunpack (array.float_complex_array_value ());
+          else
+            retval = do_bitunpack (array.complex_array_value ());
+        }
+      else if (array.is_real_type ())
+        {
+          if (array.is_single_type ())
+            retval = do_bitunpack (array.float_array_value ());
+          else
+            retval = do_bitunpack (array.array_value ());
+        }
+      else
+        error ("bitunpack: invalid input class: %s", array.class_name ().c_str ());
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
--- a/src/data.cc	Fri Jul 27 17:10:25 2012 -0400
+++ b/src/data.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -5066,7 +5066,7 @@
 
 DEFUN (full, args, ,
     "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{FM} =} full (@var{SM})\n\
+@deftypefn {Built-in Function} {@var{FM} =} full (@var{SM})\n\
 Return a full storage matrix from a sparse, diagonal, permutation matrix\n\
 or a range.\n\
 @seealso{sparse}\n\
@@ -5865,10 +5865,10 @@
 
 DEFUN (sort, args, nargout,
   "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {[@var{s}, @var{i}] =} sort (@var{x})\n\
-@deftypefnx {Loadable Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim})\n\
-@deftypefnx {Loadable Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{mode})\n\
-@deftypefnx {Loadable Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim}, @var{mode})\n\
+@deftypefn  {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x})\n\
+@deftypefnx {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim})\n\
+@deftypefnx {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{mode})\n\
+@deftypefnx {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim}, @var{mode})\n\
 Return a copy of @var{x} with the elements arranged in increasing\n\
 order.  For matrices, @code{sort} orders the elements within columns\n\
 \n\
--- a/src/debug.cc	Fri Jul 27 17:10:25 2012 -0400
+++ b/src/debug.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -504,8 +504,8 @@
 
 DEFUN (dbstop, args, ,
   "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{rline} =} dbstop (\"@var{func}\")\n\
-@deftypefnx {Loadable Function} {@var{rline} =} dbstop (\"@var{func}\", @var{line}, @dots{})\n\
+@deftypefn  {Built-in Function} {@var{rline} =} dbstop (\"@var{func}\")\n\
+@deftypefnx {Built-in Function} {@var{rline} =} dbstop (\"@var{func}\", @var{line}, @dots{})\n\
 Set a breakpoint in function @var{func}.\n\
 \n\
 Arguments are\n\
@@ -548,8 +548,8 @@
 
 DEFUN (dbclear, args, ,
   "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} dbclear (\"@var{func}\")\n\
-@deftypefnx {Loadable Function} {} dbclear (\"@var{func}\", @var{line}, @dots{})\n\
+@deftypefn  {Built-in Function} {} dbclear (\"@var{func}\")\n\
+@deftypefnx {Built-in Function} {} dbclear (\"@var{func}\", @var{line}, @dots{})\n\
 Delete a breakpoint in the function @var{func}.\n\
 \n\
 Arguments are\n\
@@ -585,9 +585,9 @@
 
 DEFUN (dbstatus, args, nargout,
   "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} dbstatus ()\n\
-@deftypefnx {Loadable Function} {@var{brk_list} =} dbstatus ()\n\
-@deftypefnx {Loadable Function} {@var{brk_list} =} dbstatus (\"@var{func}\")\n\
+@deftypefn  {Built-in Function} {} dbstatus ()\n\
+@deftypefnx {Built-in Function} {@var{brk_list} =} dbstatus ()\n\
+@deftypefnx {Built-in Function} {@var{brk_list} =} dbstatus (\"@var{func}\")\n\
 Report the location of active breakpoints.\n\
 \n\
 When called with no input or output arguments, print the list of\n\
@@ -701,7 +701,7 @@
 
 DEFUN (dbwhere, , ,
   "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} dbwhere ()\n\
+@deftypefn {Built-in Function} {} dbwhere ()\n\
 In debugging mode, report the current file and line number where\n\
 execution is stopped.\n\
 @seealso{dbstatus, dbcont, dbstep, dbup}\n\
@@ -794,13 +794,13 @@
 
 DEFUN (dbtype, args, ,
   "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} dbtype ()\n\
-@deftypefnx {Loadable Function} {} dbtype (\"startl:endl\")\n\
-@deftypefnx {Loadable Function} {} dbtype (\"startl:end\")\n\
-@deftypefnx {Loadable Function} {} dbtype (\"@var{func}\")\n\
-@deftypefnx {Loadable Function} {} dbtype (\"@var{func}\", \"startl\")\n\
-@deftypefnx {Loadable Function} {} dbtype (\"@var{func}\", \"startl:endl\")\n\
-@deftypefnx {Loadable Function} {} dbtype (\"@var{func}\", \"startl:end\")\n\
+@deftypefn  {Built-in Function} {} dbtype ()\n\
+@deftypefnx {Built-in Function} {} dbtype (\"startl:endl\")\n\
+@deftypefnx {Built-in Function} {} dbtype (\"startl:end\")\n\
+@deftypefnx {Built-in Function} {} dbtype (\"@var{func}\")\n\
+@deftypefnx {Built-in Function} {} dbtype (\"@var{func}\", \"startl\")\n\
+@deftypefnx {Built-in Function} {} dbtype (\"@var{func}\", \"startl:endl\")\n\
+@deftypefnx {Built-in Function} {} dbtype (\"@var{func}\", \"startl:end\")\n\
 When in debugging mode and called with no arguments, list the script file\n\
 being debugged with line numbers.  An optional range specification,\n\
 specified as a string, can be used to list only a portion of the file.\n\
@@ -1022,9 +1022,9 @@
 
 DEFUN (dbstack, args, nargout,
   "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} dbstack ()\n\
-@deftypefnx {Loadable Function} {} dbstack (@var{n})\n\
-@deftypefnx {Loadable Function} {[@var{stack}, @var{idx}] =} dbstack (@dots{})\n\
+@deftypefn  {Built-in Function} {} dbstack ()\n\
+@deftypefnx {Built-in Function} {} dbstack (@var{n})\n\
+@deftypefnx {Built-in Function} {[@var{stack}, @var{idx}] =} dbstack (@dots{})\n\
 Display or return current debugging function stack information.\n\
 With optional argument @var{n}, omit the @var{n} innermost stack frames.\n\
 \n\
@@ -1090,8 +1090,8 @@
 
 DEFUN (dbup, args, ,
   "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} dbup\n\
-@deftypefnx {Loadable Function} {} dbup (@var{n})\n\
+@deftypefn  {Built-in Function} {} dbup\n\
+@deftypefnx {Built-in Function} {} dbup (@var{n})\n\
 In debugging mode, move up the execution stack @var{n} frames.\n\
 If @var{n} is omitted, move up one frame.\n\
 @seealso{dbstack, dbdown}\n\
@@ -1106,8 +1106,8 @@
 
 DEFUN (dbdown, args, ,
   "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {} dbdown\n\
-@deftypefnx {Loadable Function} {} dbdown (@var{n})\n\
+@deftypefn  {Built-in Function} {} dbdown\n\
+@deftypefnx {Built-in Function} {} dbdown (@var{n})\n\
 In debugging mode, move down the execution stack @var{n} frames.\n\
 If @var{n} is omitted, move down one frame.\n\
 @seealso{dbstack, dbup}\n\
@@ -1252,7 +1252,7 @@
 
 DEFUN (isdebugmode, args, ,
   "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} isdebugmode ()\n\
+@deftypefn {Built-in Function} {} isdebugmode ()\n\
 Return true if in debugging mode, otherwise false.\n\
 @seealso{dbwhere, dbstack, dbstatus}\n\
 @end deftypefn")
--- a/src/find-defun-files.sh	Fri Jul 27 17:10:25 2012 -0400
+++ b/src/find-defun-files.sh	Fri Jul 27 21:59:10 2012 -0400
@@ -21,6 +21,6 @@
     file="$srcdir/$arg"
   fi
   if [ "`$EGREP -l "$DEFUN_PATTERN" $file`" ]; then
-    echo "$file" | $SED 's,.*/,,; s/\.cc$/.df/; s/\.ll$/.df/; s/\.yy$/.df/';
+    echo "$file" | $SED "s,\\$srcdir/,," | $SED 's/\.cc$/.df/; s/\.ll$/.df/; s/\.yy$/.df/';
   fi
 done
--- a/src/help.cc	Fri Jul 27 17:10:25 2012 -0400
+++ b/src/help.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -954,7 +954,7 @@
 }
 
 DEFUN (get_help_text, args, , "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{text}, @var{format}] =} get_help_text (@var{name})\n\
+@deftypefn {Built-in Function} {[@var{text}, @var{format}] =} get_help_text (@var{name})\n\
 Return the raw help text of function @var{name}.\n\
 \n\
 The raw help text is returned in @var{text} and the format in @var{format}\n\
@@ -1023,7 +1023,7 @@
 
 DEFUN (get_help_text_from_file, args, ,
   "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{text}, @var{format}] =} get_help_text_from_file (@var{fname})\n\
+@deftypefn {Built-in Function} {[@var{text}, @var{format}] =} get_help_text_from_file (@var{fname})\n\
 Return the raw help text from the file @var{fname}.\n\
 \n\
 The raw help text is returned in @var{text} and the format in @var{format}\n\
--- a/src/link-deps.mk	Fri Jul 27 17:10:25 2012 -0400
+++ b/src/link-deps.mk	Fri Jul 27 21:59:10 2012 -0400
@@ -11,6 +11,8 @@
   $(FT2_LIBS) \
   $(HDF5_LIBS) \
   $(Z_LIBS) \
+  $(FFTW_XLIBS) \
+  $(REGEX_LIBS) \
   $(OPENGL_LIBS) \
   $(X11_LIBS) \
   $(CARBON_LIBS) \
@@ -22,6 +24,7 @@
   $(HDF5_LDFLAGS) \
   $(Z_LDFLAGS) \
   $(REGEX_LDFLAGS) \
+  $(FFTW_XLDFLAGS) \
   $(LLVM_LDFLAGS)
 
 OCT_LINK_DEPS =
--- a/src/ov-oncleanup.cc	Fri Jul 27 17:10:25 2012 -0400
+++ b/src/ov-oncleanup.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -191,7 +191,7 @@
 
 DEFUN (onCleanup, args, ,
   "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{c} =} onCleanup (@var{action})\n\
+@deftypefn {Built-in Function} {@var{c} =} onCleanup (@var{action})\n\
 Create a special object that executes a given function upon destruction.\n\
 If the object is copied to multiple variables (or cell or struct array\n\
 elements) or returned from a function, @var{action} will be executed after\n\
--- a/src/sparse.cc	Fri Jul 27 17:10:25 2012 -0400
+++ b/src/sparse.cc	Fri Jul 27 21:59:10 2012 -0400
@@ -43,7 +43,7 @@
 
 DEFUN (issparse, args, ,
   "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} issparse (@var{x})\n\
+@deftypefn {Built-in Function} {} issparse (@var{x})\n\
 Return true if @var{x} is a sparse matrix.\n\
 @seealso{ismatrix}\n\
 @end deftypefn")
@@ -59,11 +59,11 @@
 
 DEFUN (sparse, args, ,
     "-*- texinfo -*-\n\
-@deftypefn  {Loadable Function} {@var{s} =} sparse (@var{a})\n\
-@deftypefnx {Loadable Function} {@var{s} =} sparse (@var{i}, @var{j}, @var{sv}, @var{m}, @var{n}, @var{nzmax})\n\
-@deftypefnx {Loadable Function} {@var{s} =} sparse (@var{i}, @var{j}, @var{sv})\n\
-@deftypefnx {Loadable Function} {@var{s} =} sparse (@var{i}, @var{j}, @var{s}, @var{m}, @var{n}, \"unique\")\n\
-@deftypefnx {Loadable Function} {@var{s} =} sparse (@var{m}, @var{n})\n\
+@deftypefn  {Built-in Function} {@var{s} =} sparse (@var{a})\n\
+@deftypefnx {Built-in Function} {@var{s} =} sparse (@var{i}, @var{j}, @var{sv}, @var{m}, @var{n}, @var{nzmax})\n\
+@deftypefnx {Built-in Function} {@var{s} =} sparse (@var{i}, @var{j}, @var{sv})\n\
+@deftypefnx {Built-in Function} {@var{s} =} sparse (@var{i}, @var{j}, @var{s}, @var{m}, @var{n}, \"unique\")\n\
+@deftypefnx {Built-in Function} {@var{s} =} sparse (@var{m}, @var{n})\n\
 Create a sparse matrix from the full matrix or row, column, value triplets.\n\
 If @var{a} is a full matrix, convert it to a sparse matrix representation,\n\
 removing all zero values in the process.\n\
@@ -209,7 +209,7 @@
 
 DEFUN (spalloc, args, ,
     "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {@var{s} =} spalloc (@var{m}, @var{n}, @var{nz})\n\
+@deftypefn {Built-in Function} {@var{s} =} spalloc (@var{m}, @var{n}, @var{nz})\n\
 Create an @var{m}-by-@var{n} sparse matrix with pre-allocated space for at\n\
 most @var{nz} nonzero elements.  This is useful for building the matrix\n\
 incrementally by a sequence of indexed assignments.  Subsequent indexed\n\