diff src/DLD-FUNCTIONS/sparse.cc @ 7505:f5005d9510f4

Remove dispatched sparse functions and treat in the generic versions of the functions
author David Bateman <dbateman@free.fr>
date Wed, 20 Feb 2008 15:52:11 -0500
parents d8209a80e093
children f3c00dc0912b
line wrap: on
line diff
--- a/src/DLD-FUNCTIONS/sparse.cc
+++ b/src/DLD-FUNCTIONS/sparse.cc
@@ -487,360 +487,6 @@
   SPARSE_DIM_ARG_BODY (spsumsq, sumsq);
 }
 
-#define MINMAX_BODY(FCN) \
- \
-  octave_value_list retval;  \
- \
-  int nargin = args.length (); \
- \
-  if (nargin < 1 || nargin > 3 || nargout > 2) \
-    { \
-      print_usage (); \
-      return retval; \
-    } \
- \
-  octave_value arg1; \
-  octave_value arg2; \
-  octave_value arg3; \
- \
-  switch (nargin) \
-    { \
-    case 3: \
-      arg3 = args(2); \
- \
-    case 2: \
-      arg2 = args(1); \
- \
-    case 1: \
-      arg1 = args(0); \
-      break; \
- \
-    default: \
-      panic_impossible (); \
-      break; \
-    } \
- \
-  int dim; \
-  dim_vector dv = arg1.dims (); \
-  if (error_state) \
-    { \
-      gripe_wrong_type_arg (#FCN, arg1);  \
-      return retval; \
-    } \
- \
-  if (nargin == 3) \
-    { \
-      dim = arg3.nint_value () - 1;  \
-      if (dim < 0 || dim >= dv.length ()) \
-        { \
-	  error ("%s: invalid dimension", #FCN); \
-	  return retval; \
-	} \
-    } \
-  else \
-    { \
-      dim = 0; \
-      while ((dim < dv.length ()) && (dv (dim) <= 1)) \
-	dim++; \
-      if (dim == dv.length ()) \
-	dim = 0; \
-    } \
- \
-  bool single_arg = (nargin == 1) || arg2.is_empty();	\
- \
-  if (single_arg && (nargout == 1 || nargout == 0)) \
-    { \
-      if (arg1.type_id () == octave_sparse_matrix::static_type_id ()) \
-	retval(0) = arg1.sparse_matrix_value () .FCN (dim); \
-      else if (arg1.type_id () == \
-	       octave_sparse_complex_matrix::static_type_id ()) \
-	retval(0) = arg1.sparse_complex_matrix_value () .FCN (dim); \
-      else \
-	gripe_wrong_type_arg (#FCN, arg1); \
-    } \
-  else if (single_arg && nargout == 2) \
-    { \
-      Array2<octave_idx_type> index; \
- \
-      if (arg1.type_id () == octave_sparse_matrix::static_type_id ()) \
-	retval(0) = arg1.sparse_matrix_value () .FCN (index, dim); \
-      else if (arg1.type_id () == \
-	       octave_sparse_complex_matrix::static_type_id ()) \
-	retval(0) = arg1.sparse_complex_matrix_value () .FCN (index, dim); \
-      else \
-	gripe_wrong_type_arg (#FCN, arg1); \
- \
-      octave_idx_type len = index.numel (); \
- \
-      if (len > 0) \
-	{ \
-	  double nan_val = lo_ieee_nan_value (); \
- \
-	  NDArray idx (index.dims ()); \
- \
-	  for (octave_idx_type i = 0; i < len; i++) \
-	    { \
-	      OCTAVE_QUIT; \
-	      octave_idx_type tmp = index.elem (i) + 1; \
-	      idx.elem (i) = (tmp <= 0) \
-		? nan_val : static_cast<double> (tmp); \
-	    } \
- \
-	  retval(1) = idx; \
-	} \
-      else \
-	retval(1) = NDArray (); \
-    } \
-  else \
-    { \
-      int arg1_is_scalar = arg1.is_scalar_type (); \
-      int arg2_is_scalar = arg2.is_scalar_type (); \
- \
-      int arg1_is_complex = arg1.is_complex_type (); \
-      int arg2_is_complex = arg2.is_complex_type (); \
- \
-      if (arg1_is_scalar) \
-	{ \
-	  if (arg1_is_complex || arg2_is_complex) \
-	    { \
-	      Complex c1 = arg1.complex_value (); \
-	      \
-	      SparseComplexMatrix m2 = arg2.sparse_complex_matrix_value (); \
-	      \
-	      if (! error_state) \
-		{ \
-		  SparseComplexMatrix result = FCN (c1, m2); \
-		  if (! error_state) \
-		    retval(0) = result; \
-		} \
-	    } \
-	  else \
-	    { \
-	      double d1 = arg1.double_value (); \
-	      SparseMatrix m2 = arg2.sparse_matrix_value (); \
-	      \
-	      if (! error_state) \
-		{ \
-		  SparseMatrix result = FCN (d1, m2); \
-		  if (! error_state) \
-		    retval(0) = result; \
-		} \
-	    } \
-	} \
-      else if (arg2_is_scalar) \
-	{ \
-	  if (arg1_is_complex || arg2_is_complex) \
-	    { \
-	      SparseComplexMatrix m1 = arg1.sparse_complex_matrix_value (); \
- \
-	      if (! error_state) \
-		{ \
-		  Complex c2 = arg2.complex_value (); \
-		  SparseComplexMatrix result = FCN (m1, c2); \
-		  if (! error_state) \
-		    retval(0) = result; \
-		} \
-	    } \
-	  else \
-	    { \
-	      SparseMatrix m1 = arg1.sparse_matrix_value (); \
- \
-	      if (! error_state) \
-		{ \
-		  double d2 = arg2.double_value (); \
-		  SparseMatrix result = FCN (m1, d2); \
-		  if (! error_state) \
-		    retval(0) = result; \
-		} \
-	    } \
-	} \
-      else \
-	{ \
-	  if (arg1_is_complex || arg2_is_complex) \
-	    { \
-	      SparseComplexMatrix m1 = arg1.sparse_complex_matrix_value (); \
- \
-	      if (! error_state) \
-		{ \
-		  SparseComplexMatrix m2 = arg2.sparse_complex_matrix_value (); \
- \
-		  if (! error_state) \
-		    { \
-		      SparseComplexMatrix result = FCN (m1, m2); \
-		      if (! error_state) \
-			retval(0) = result; \
-		    } \
-		} \
-	    } \
-	  else \
-	    { \
-	      SparseMatrix m1 = arg1.sparse_matrix_value (); \
- \
-	      if (! error_state) \
-		{ \
-		  SparseMatrix m2 = arg2.sparse_matrix_value (); \
- \
-		  if (! error_state) \
-		    { \
-		      SparseMatrix result = FCN (m1, m2); \
-		      if (! error_state) \
-			retval(0) = result; \
-		    } \
-		} \
-	    } \
-	} \
-    } \
- \
-  return retval
-
-// PKG_ADD: dispatch ("min", "spmin", "sparse matrix");
-// PKG_ADD: dispatch ("min", "spmin", "sparse complex matrix");
-// PKG_ADD: dispatch ("min", "spmin", "sparse bool matrix");
-DEFUN_DLD (spmin, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Mapping Function} {} spmin (@var{x}, @var{y}, @var{dim})\n\
-@deftypefnx {Mapping Function} {[@var{w}, @var{iw}] =} spmin (@var{x})\n\
-@cindex Utility Functions\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. 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\
-@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, 5])\n\
-    @result{}  x = 0\n\
-        ix = 3\n\
-@end group\n\
-@end example\n\
-@end deftypefn")
-{
-  MINMAX_BODY (min);
-}
-
-// PKG_ADD: dispatch ("max", "spmax", "sparse matrix");
-// PKG_ADD: dispatch ("max", "spmax", "sparse complex matrix");
-// PKG_ADD: dispatch ("max", "spmax", "sparse bool matrix");
-DEFUN_DLD (spmax, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Mapping Function} {} spmax (@var{x}, @var{y}, @var{dim})\n\
-@deftypefnx {Mapping Function} {[@var{w}, @var{iw}] =} spmax (@var{x})\n\
-@cindex Utility Functions\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. 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 @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\
-@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\
-@end deftypefn")
-{
-  MINMAX_BODY (max);
-}
-
-// PKG_ADD: dispatch ("atan2", "spatan2", "sparse matrix");
-// PKG_ADD: dispatch ("atan2", "spatan2", "sparse complex matrix");
-// PKG_ADD: dispatch ("atan2", "spatan2", "sparse bool matrix");
-DEFUN_DLD (spatan2, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} spatan2 (@var{y}, @var{x})\n\
-Compute atan (Y / X) for corresponding sparse matrix elements of Y and X.\n\
-The result is in range -pi to pi.\n\
-@end deftypefn")
-{
-  octave_value retval;
-  int nargin = args.length ();
-  if (nargin == 2) {  
-    SparseMatrix a, b;
-    double da, db;
-    bool is_double_a = false;
-    bool is_double_b = false;
-
-    if (args(0).is_scalar_type ())
-      {
-	is_double_a = true;
-	da = args(0).double_value();
-      }
-    else 
-      a = args(0).sparse_matrix_value ();
-
-    if (args(1).is_scalar_type ())
-      {
-	is_double_b = true;
-	db = args(1).double_value();
-      }
-    else 
-      b = args(1).sparse_matrix_value ();
-
-    if (is_double_a && is_double_b)
-      retval = Matrix (1, 1, atan2(da, db));
-    else if (is_double_a)
-      retval = atan2 (da, b);
-    else if (is_double_b)
-      retval = atan2 (a, db);
-    else
-      retval = atan2 (a, b);
-
-  } else
-    print_usage ();
-
-  return retval;
-}
 
 static octave_value
 make_spdiag (const octave_value& a, const octave_value& b)