changeset 4668:7849788ca4bd

[project @ 2003-11-26 04:28:39 by jwe]
author jwe
date Wed, 26 Nov 2003 04:28:39 +0000
parents e6260247a166
children 334a27c8f453
files src/ChangeLog src/defun.h src/mappers.cc src/ov-bool-mat.cc src/ov-ch-mat.h src/ov-range.h src/ov-str-mat.cc src/ov-str-mat.h
diffstat 8 files changed, 96 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Nov 25 17:19:12 2003 +0000
+++ b/src/ChangeLog	Wed Nov 26 04:28:39 2003 +0000
@@ -1,3 +1,29 @@
+2003-11-25  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* ov-str-mat.cc (CHAR_MATRIX_CONV): New macro.
+	* ov-str-mat.h (octave_char_matrix_str::double_value,
+	octave_char_matrix_str::matrix_value,
+	octave_char_matrix_str::array_value,
+	octave_char_matrix_str::complex_value,
+	octave_char_matrix_str::complex_matrix_value,
+	(octave_char_matrix_str::complex_array_value): Use it.
+
+	* ov-bool-mat.cc (default_numeric_conversion_function):
+	Convert to NDArray, not Matrix.
+	* ov-str-mat.cc (default_numeric_conversion_function): Likewise.
+
+	* ov-range.h (octave_range::array_value): New function.
+	(octave_range::complex_array_value): Likewise.
+	* ov-ch-mat.h (charNDArray::array_value): New function.
+	(charNDArray::complex_array_value): Likewise.
+	* ov-str-mat.h (octave_char_matrix_str::array_value): Likewise.
+	(octave_char_matrix_str::complex_value): Likewise.
+	(octave_char_matrix_str::complex_matrix_value): Likewise.
+	(octave_char_matrix_str::complex_array_value): Likewise.
+
+	* mappers.cc (acosh, log, log10, sqrt):
+	Use octave_Inf instead of DBL_MAX for range limit.
+
 2003-11-24  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* version.h (OCTAVE_VERSION): Now 2.1.52.
--- a/src/defun.h	Tue Nov 25 17:19:12 2003 +0000
+++ b/src/defun.h	Wed Nov 26 04:28:39 2003 +0000
@@ -128,11 +128,11 @@
 //   c_c_map is a pointer to a function that should be called for
 //     complex arguments that are expected to create complex results.
 //
-//   lo is the lower bound of the range for which real arguments can
-//     become complex.  (e.g., lo == -Inf for sqrt).
+//   lo is the lower bound of the range for which real arguments
+//     return real results (e.g., lo == 0 for sqrt).
 //
-//   hi is the upper bound of the range for which real arguments can
-//     become complex.  (e.g., hi == 0 for sqrt).
+//   hi is the upper bound of the range for which real arguments
+//     return real results (e.g., hi == Inf for sqrt).
 //
 //   ch_map_flag has the following meanings for the ch_map function:
 //
--- a/src/mappers.cc	Tue Nov 25 17:19:12 2003 +0000
+++ b/src/mappers.cc	Wed Nov 26 04:28:39 2003 +0000
@@ -197,7 +197,7 @@
 Compute the inverse cosine of each element of @var{x}.\n\
 @end deftypefn");
 
-  DEFUN_MAPPER (acosh, 0, 0, 0, acosh, 0, acosh, 1.0, DBL_MAX, 0, 1,
+  DEFUN_MAPPER (acosh, 0, 0, 0, acosh, 0, acosh, 1.0, octave_Inf, 0, 1,
     "-*- texinfo -*-\n\
 @deftypefn {Mapping Function} {} acosh (@var{x})\n\
 Compute the inverse hyperbolic cosine of each element of @var{x}.\n\
@@ -543,7 +543,7 @@
 @end deftypefn\n\
 @seealso{gamma and gammai}");
 
-  DEFUN_MAPPER (log, 0, 0, 0, log, 0, log, 0.0, DBL_MAX, 0, 1,
+  DEFUN_MAPPER (log, 0, 0, 0, log, 0, log, 0.0, octave_Inf, 0, 1,
     "-*- texinfo -*-\n\
 @deftypefn {Mapping Function} {} log (@var{x})\n\
 Compute the natural logarithm for each element of @var{x}.  To compute the\n\
@@ -551,7 +551,7 @@
 @end deftypefn\n\
 @seealso{log2, log10, logspace, and exp}");
 
-  DEFUN_MAPPER (log10, 0, 0, 0, log10, 0, log10, 0.0, DBL_MAX, 0, 1,
+  DEFUN_MAPPER (log10, 0, 0, 0, log10, 0, log10, 0.0, octave_Inf, 0, 1,
     "-*- texinfo -*-\n\
 @deftypefn {Mapping Function} {} log10 (@var{x})\n\
 Compute the base-10 logarithm for each element of @var{x}.\n\
@@ -608,7 +608,7 @@
 Compute the inverse hyperbolic sin of each element of @var{x}.\n\
 @end deftypefn");
 
-  DEFUN_MAPPER (sqrt, 0, 0, 0, sqrt, 0, sqrt, 0.0, DBL_MAX, 0, 1,
+  DEFUN_MAPPER (sqrt, 0, 0, 0, sqrt, 0, sqrt, 0.0, octave_Inf, 0, 1,
     "-*- texinfo -*-\n\
 @deftypefn {Mapping Function} {} sqrt (@var{x})\n\
 Compute the square root of @var{x}.  If @var{x} is negative, a complex\n\
--- a/src/ov-bool-mat.cc	Tue Nov 25 17:19:12 2003 +0000
+++ b/src/ov-bool-mat.cc	Wed Nov 26 04:28:39 2003 +0000
@@ -56,7 +56,7 @@
 {
   CAST_CONV_ARG (const octave_bool_matrix&);
 
-  return new octave_matrix (Matrix (v.bool_matrix_value ()));
+  return new octave_matrix (NDArray (v.bool_array_value ()));
 }
 
 type_conv_fcn
--- a/src/ov-ch-mat.h	Tue Nov 25 17:19:12 2003 +0000
+++ b/src/ov-ch-mat.h	Wed Nov 26 04:28:39 2003 +0000
@@ -98,11 +98,17 @@
   Matrix matrix_value (bool = false) const
     { return Matrix (matrix.matrix_value ()); }
 
+  NDArray array_value (bool = false) const
+    { return NDArray (matrix); }
+
   Complex complex_value (bool = false) const;
 
   ComplexMatrix complex_matrix_value (bool = false) const
     { return ComplexMatrix (matrix.matrix_value ()); }
 
+  ComplexNDArray complex_array_value (bool = false) const
+    { return ComplexNDArray (matrix); }
+
   charMatrix char_matrix_value (bool = false) const
     { return matrix.matrix_value (); }
 
--- a/src/ov-range.h	Tue Nov 25 17:19:12 2003 +0000
+++ b/src/ov-range.h	Wed Nov 26 04:28:39 2003 +0000
@@ -150,11 +150,17 @@
   Matrix matrix_value (bool = false) const
     { return range.matrix_value (); }
 
+  NDArray array_value (bool = false) const
+    { return range.matrix_value (); }
+
   Complex complex_value (bool = false) const;
 
   ComplexMatrix complex_matrix_value (bool = false) const
     { return ComplexMatrix (range.matrix_value ()); }
 
+  ComplexNDArray complex_array_value (bool = false) const
+    { return ComplexMatrix (range.matrix_value ()); }
+
   Range range_value (void) const { return range; }
 
   octave_value convert_to_str_internal (bool pad, bool force) const;
--- a/src/ov-str-mat.cc	Tue Nov 25 17:19:12 2003 +0000
+++ b/src/ov-str-mat.cc	Wed Nov 26 04:28:39 2003 +0000
@@ -50,9 +50,9 @@
 {
   CAST_CONV_ARG (const octave_char_matrix_str&);
 
-  Matrix m = v.matrix_value (true);
+  NDArray nda = v.array_value (true);
 
-  return error_state ? 0 : new octave_matrix (m);
+  return error_state ? 0 : new octave_matrix (nda);
 }
 
 type_conv_fcn
@@ -131,40 +131,56 @@
   return retval;
 }
 
+#define CHAR_MATRIX_CONV(T, INIT, TNAME, FCN) \
+  T retval INIT; \
+ \
+  if (! force_string_conv) \
+    gripe_invalid_conversion ("string", TNAME); \
+  else \
+    { \
+      if (Vwarn_str_to_num) \
+	gripe_implicit_conversion ("string", TNAME); \
+ \
+      retval = octave_char_matrix::FCN (); \
+    } \
+ \
+  return retval
+
 double
 octave_char_matrix_str::double_value (bool force_string_conv) const
 {
-  double retval = 0;
+  CHAR_MATRIX_CONV (double, = 0, "real scalar", double_value);
+}
 
-  if (! force_string_conv)
-    gripe_invalid_conversion ("string", "real scalar");
-  else
-    {
-      if (Vwarn_str_to_num)
-	gripe_implicit_conversion ("string", "real scalar");
-
-      retval = octave_char_matrix::double_value ();
-    }
-
-  return retval;
+Complex
+octave_char_matrix_str::complex_value (bool force_string_conv) const
+{
+  CHAR_MATRIX_CONV (Complex, = 0, "complex scalar", complex_value);
 }
 
 Matrix
 octave_char_matrix_str::matrix_value (bool force_string_conv) const
 {
-  Matrix retval;
+  CHAR_MATRIX_CONV (Matrix, , "real matrix", matrix_value);
+}
+
+ComplexMatrix
+octave_char_matrix_str::complex_matrix_value (bool force_string_conv) const
+{
+  CHAR_MATRIX_CONV (ComplexMatrix, , "complex matrix", complex_matrix_value);
+}
 
-  if (! force_string_conv)
-    gripe_invalid_conversion ("string", "real matrix");
-  else
-    {
-      if (Vwarn_str_to_num)
-	gripe_implicit_conversion ("string", "real matrix");
+NDArray
+octave_char_matrix_str::array_value (bool force_string_conv) const
+{
+  CHAR_MATRIX_CONV (NDArray, , "real N-d array", array_value);
+}
 
-      retval = octave_char_matrix::matrix_value ();
-    }
-
-  return retval;
+ComplexNDArray
+octave_char_matrix_str::complex_array_value (bool force_string_conv) const
+{
+  CHAR_MATRIX_CONV (ComplexNDArray, , "complex N-d array",
+		    complex_array_value);
 }
 
 string_vector
--- a/src/ov-str-mat.h	Tue Nov 25 17:19:12 2003 +0000
+++ b/src/ov-str-mat.h	Wed Nov 26 04:28:39 2003 +0000
@@ -108,6 +108,14 @@
 
   Matrix matrix_value (bool = false) const;
 
+  NDArray array_value (bool = false) const;
+
+  Complex complex_value (bool = false) const;
+
+  ComplexMatrix complex_matrix_value (bool = false) const;
+
+  ComplexNDArray complex_array_value (bool = false) const;
+
   string_vector all_strings (bool pad = false, bool force = false) const;
 
   std::string string_value (bool force = false) const;