# HG changeset patch # User jwe # Date 1156279017 0 # Node ID cdef72fcd206604d338f73dea558ee10bb5220ca # Parent fc46f9c990289b3fdb8b8d60cddc1001c6d6d350 [project @ 2006-08-22 20:36:56 by jwe] diff -r fc46f9c99028 -r cdef72fcd206 liboctave/CMatrix.cc --- a/liboctave/CMatrix.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/liboctave/CMatrix.cc Tue Aug 22 20:36:57 2006 +0000 @@ -3464,6 +3464,82 @@ // i/o +// Used when converting Inf to something that gnuplot can read. + +#ifndef OCT_RBV +#define OCT_RBV DBL_MAX / 100.0 +#endif + +std::ostream& +ComplexMatrix::save_ascii (std::ostream& os, bool& infnan_warned, + int strip_nan_and_inf) +{ + if (strip_nan_and_inf) + { + octave_idx_type nr = rows (); + octave_idx_type nc = columns (); + + for (octave_idx_type i = 0; i < nr; i++) + { + if (strip_nan_and_inf) + { + for (octave_idx_type j = 0; j < nc; j++) + { + Complex c = elem (i, j); + + if (xisnan (c)) + { + if (strip_nan_and_inf == 1) + goto next_row; + else if (strip_nan_and_inf == 2) + goto next_row_with_newline; + } + } + } + + for (octave_idx_type j = 0; j < nc; j++) + { + Complex c = elem (i, j); + + if (strip_nan_and_inf) + { + double re = std::real (c); + double im = std::imag (c); + + if (xisinf (re)) + re = re > 0 ? OCT_RBV : -OCT_RBV; + + if (xisinf (im)) + im = im > 0 ? OCT_RBV : -OCT_RBV; + + c = Complex (re, im); + } + else if (! infnan_warned && (xisnan (c) || xisinf (c))) + { + (*current_liboctave_warning_handler) + ("save: Inf or NaN values may not be reloadable"); + + infnan_warned = true; + } + + octave_write_complex (os, c); + + os << " "; + } + + next_row_with_newline: + os << "\n"; + + next_row: + continue; + } + } + else + os << *this; + + return os; +} + std::ostream& operator << (std::ostream& os, const ComplexMatrix& a) { diff -r fc46f9c99028 -r cdef72fcd206 liboctave/CMatrix.h --- a/liboctave/CMatrix.h Tue Aug 22 18:37:43 2006 +0000 +++ b/liboctave/CMatrix.h Tue Aug 22 20:36:57 2006 +0000 @@ -319,6 +319,9 @@ // i/o + std::ostream& save_ascii (std::ostream& os, bool& infnan_warned, + int strip_nan_and_inf); + friend std::ostream& operator << (std::ostream& os, const ComplexMatrix& a); friend std::istream& operator >> (std::istream& is, ComplexMatrix& a); diff -r fc46f9c99028 -r cdef72fcd206 liboctave/ChangeLog --- a/liboctave/ChangeLog Tue Aug 22 18:37:43 2006 +0000 +++ b/liboctave/ChangeLog Tue Aug 22 20:36:57 2006 +0000 @@ -1,5 +1,8 @@ 2006-08-22 John W. Eaton + * CMatrix.cc (ComplexMatrix::save_ascii): New function. + * dMatrix.cc (Matrix::save_ascii): New function. + * mx-inlines.cc (MX_ND_CUMULATIVE_OP): Correctly detect empty arrays. If array is empty, return value is same size as array. (MX_ND_REDUCTION): Correctly detect empty arrays. diff -r fc46f9c99028 -r cdef72fcd206 liboctave/dMatrix.cc --- a/liboctave/dMatrix.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/liboctave/dMatrix.cc Tue Aug 22 20:36:57 2006 +0000 @@ -2851,6 +2851,74 @@ return result; } +// Used when converting Inf to something that gnuplot can read. + +#ifndef OCT_RBV +#define OCT_RBV DBL_MAX / 100.0 +#endif + +std::ostream& +Matrix::save_ascii (std::ostream& os, bool& infnan_warned, + int strip_nan_and_inf) +{ + if (strip_nan_and_inf) + { + octave_idx_type nr = rows (); + octave_idx_type nc = columns (); + + for (octave_idx_type i = 0; i < nr; i++) + { + if (strip_nan_and_inf) + { + for (octave_idx_type j = 0; j < nc; j++) + { + double d = elem (i, j); + + if (xisnan (d)) + { + if (strip_nan_and_inf == 1) + goto next_row; + else if (strip_nan_and_inf == 2) + goto next_row_with_newline; + } + } + } + + for (octave_idx_type j = 0; j < nc; j++) + { + double d = elem (i, j); + + if (strip_nan_and_inf) + { + if (xisinf (d)) + d = d > 0 ? OCT_RBV : -OCT_RBV; + } + else if (! infnan_warned && (xisnan (d) || xisinf (d))) + { + (*current_liboctave_warning_handler) + ("save: Inf or NaN values may not be reloadable"); + + infnan_warned = true; + } + + octave_write_double (os, d); + + os << " "; + } + + next_row_with_newline: + os << "\n"; + + next_row: + continue; + } + } + else + os << *this; + + return os; +} + std::ostream& operator << (std::ostream& os, const Matrix& a) { diff -r fc46f9c99028 -r cdef72fcd206 liboctave/dMatrix.h --- a/liboctave/dMatrix.h Tue Aug 22 18:37:43 2006 +0000 +++ b/liboctave/dMatrix.h Tue Aug 22 20:36:57 2006 +0000 @@ -274,6 +274,9 @@ // i/o + std::ostream& save_ascii (std::ostream& os, bool& infnan_warned, + int strip_nan_and_inf); + friend std::ostream& operator << (std::ostream& os, const Matrix& a); friend std::istream& operator >> (std::istream& is, Matrix& a); diff -r fc46f9c99028 -r cdef72fcd206 src/ChangeLog --- a/src/ChangeLog Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ChangeLog Tue Aug 22 20:36:57 2006 +0000 @@ -1,5 +1,44 @@ 2006-08-22 John W. Eaton + * ov.h (octave_value::save_ascii): strip_nan_and_inf is now int, + not bool. + * ov-base.h, ov-base.cc (octave_base_value::save_ascii): Likewise. + * ov-base-int.h, ov-base-int.cc (octave_base_int_matrix::save_ascii, + octave_base_int_scalar::save_ascii, ): Likewise. + * ov-base-sparse.cc, ov-base-sparse.h + (octave_base_sparse::save_ascii): Likewise. + * ov-bool-mat.cc, ov-bool-mat.h (octave_bool_matrix::save_ascii): + Likewise. + * ov-bool.cc, ov-bool.h (octave_bool::save_ascii): Likewise. + * ov-cell.cc, ov-cell.h (octave_cell::save_ascii): Likewise. + * ov-complex.cc, ov-complex.h (octave_complex::save_ascii): Likewise. + * ov-fcn-handle.cc, ov-fcn-handle.h (octave_fcn_handle::save_ascii): + Likewise. + * ov-fcn-inline.cc, ov-fcn-inline.h (octave_fcn_inline::save_ascii): + Likewise. + * ov-list.cc, ov-list.h (octave_list::save_ascii): Likewise. + * ov-range.cc, ov-range.h (octave_range::save_ascii): Likewise. + * ov-scalar.cc, ov-scalar.h (octave_scalar::save_ascii): Likewise. + * ov-str-mat.cc, ov-str-mat.h (octave_char_matrix_str::save_ascii): + Likewise. + * ov-struct.cc, ov-struct.h (octave_struct::save_ascii): Likewise. + * ov-re-mat.cc, ov-re-mat.cc (octave_matrix::save_ascii): Likewise. + * ov-cx-mat.cc, ov-cx-mat.cc (octave_complex_matrix::save_ascii): Likewise. + + * ov-cx-mat.cc, ov-cx-mat.cc (octave_complex_matrix::save_ascii): + Don't strip Inf and NaN here. Call ComplexMatrix::save_ascii to + do the real work. + * ov-re-mat.cc, ov-re-mat.cc (octave_matrix::save_ascii): + Don't strip Inf and NaN here. Call Matrix::save_ascii to do the + real work. + + * ov-re-mat.cc, ov-cx-mat.cc (strip_infnan): Delete. + * ls-oct-ascii.cc, ls-oct-ascii.h (save_ascii_data): + strip_nan_and_inf is now int, not bool. + (strip_infnan): Delete. + (save_ascii_data_for_plotting): Call save_ascii_data with + strip_nan_and_inf = 2. + * Makefile.in (INCLUDES): Remove matrix.h from the list. 2006-08-22 David Bateman diff -r fc46f9c99028 -r cdef72fcd206 src/ls-oct-ascii.cc --- a/src/ls-oct-ascii.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ls-oct-ascii.cc Tue Aug 22 20:36:57 2006 +0000 @@ -72,37 +72,6 @@ // Functions for reading ascii data. -static Matrix -strip_infnan (const Matrix& m) -{ - octave_idx_type nr = m.rows (); - octave_idx_type nc = m.columns (); - - Matrix retval (nr, nc); - - octave_idx_type k = 0; - for (octave_idx_type i = 0; i < nr; i++) - { - for (octave_idx_type j = 0; j < nc; j++) - { - double d = m (i, j); - if (xisnan (d)) - goto next_row; - else - retval (k, j) = xisinf (d) ? (d > 0 ? OCT_RBV : -OCT_RBV) : d; - } - k++; - - next_row: - continue; - } - - if (k > 0) - retval.resize (k, nc); - - return retval; -} - // Extract a KEYWORD and its value from stream IS, returning the // associated value in a new string. // @@ -338,10 +307,12 @@ // flag MARK_AS_GLOBAL on stream OS in the plain text format described // above for load_ascii_data. If NAME is empty, the name: line is not // generated. PRECISION specifies the number of decimal digits to print. -// If STRIP_NAN_AND_INF is TRUE, rows containing NaNs are deleted, +// If STRIP_NAN_AND_INF is 1, rows containing NaNs are deleted, // and Infinite values are converted to +/-OCT_RBV (A Real Big Value, // but not so big that gnuplot can't handle it when trying to compute -// axis ranges, etc.). +// axis ranges, etc.). If STRIP_NAN_AND_INF is 2, rows containing +// NaNs are converted to blank lines in the output file and infinite +// values are converted to +/-OCT_RBV. // // Assumes ranges and strings cannot contain Inf or NaN values. // @@ -352,7 +323,7 @@ bool save_ascii_data (std::ostream& os, const octave_value& val_arg, const std::string& name, bool& infnan_warned, - bool strip_nan_and_inf, bool mark_as_global, + int strip_nan_and_inf, bool mark_as_global, int precision) { bool success = true; @@ -386,7 +357,7 @@ { bool infnan_warned = true; - return save_ascii_data (os, t, name, infnan_warned, false, false, 0); + return save_ascii_data (os, t, name, infnan_warned, 2, false, 0); } // Maybe this should be a static function in tree-plot.cc? diff -r fc46f9c99028 -r cdef72fcd206 src/ls-oct-ascii.h --- a/src/ls-oct-ascii.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ls-oct-ascii.h Tue Aug 22 20:36:57 2006 +0000 @@ -51,7 +51,7 @@ extern bool save_ascii_data (std::ostream& os, const octave_value& val_arg, const std::string& name, bool& infnan_warned, - bool strip_nan_and_inf, bool mark_as_global, + int strip_nan_and_inf, bool mark_as_global, int precision); extern bool diff -r fc46f9c99028 -r cdef72fcd206 src/ov-base-int.cc --- a/src/ov-base-int.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-base-int.cc Tue Aug 22 20:36:57 2006 +0000 @@ -70,7 +70,7 @@ template bool -octave_base_int_matrix::save_ascii (std::ostream& os, bool&, bool) +octave_base_int_matrix::save_ascii (std::ostream& os, bool&, int) { dim_vector d = this->dims (); @@ -331,7 +331,7 @@ template bool -octave_base_int_scalar::save_ascii (std::ostream& os, bool& , bool) +octave_base_int_scalar::save_ascii (std::ostream& os, bool& , int) { os << this->scalar << "\n"; return true; diff -r fc46f9c99028 -r cdef72fcd206 src/ov-base-int.h --- a/src/ov-base-int.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-base-int.h Tue Aug 22 20:36:57 2006 +0000 @@ -68,7 +68,7 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); @@ -109,7 +109,7 @@ // void decrement (void) { scalar -= 1; } - bool save_ascii (std::ostream& os, bool&, bool ); + bool save_ascii (std::ostream& os, bool&, int); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-base-sparse.cc --- a/src/ov-base-sparse.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-base-sparse.cc Tue Aug 22 20:36:57 2006 +0000 @@ -295,7 +295,7 @@ template bool -octave_base_sparse::save_ascii (std::ostream& os, bool&, bool) +octave_base_sparse::save_ascii (std::ostream& os, bool&, int) { dim_vector dv = this->dims (); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-base-sparse.h --- a/src/ov-base-sparse.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-base-sparse.h Tue Aug 22 20:36:57 2006 +0000 @@ -142,7 +142,7 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-base.cc --- a/src/ov-base.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-base.cc Tue Aug 22 20:36:57 2006 +0000 @@ -815,7 +815,7 @@ } bool -octave_base_value::save_ascii (std::ostream&, bool&, bool) +octave_base_value::save_ascii (std::ostream&, bool&, int) { gripe_wrong_type_arg ("octave_base_value::save_ascii()", type_name ()); return false; diff -r fc46f9c99028 -r cdef72fcd206 src/ov-base.h --- a/src/ov-base.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-base.h Tue Aug 22 20:36:57 2006 +0000 @@ -415,7 +415,7 @@ virtual void print_info (std::ostream& os, const std::string& prefix) const; virtual bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); virtual bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-bool-mat.cc --- a/src/ov-bool-mat.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-bool-mat.cc Tue Aug 22 20:36:57 2006 +0000 @@ -150,7 +150,7 @@ bool octave_bool_matrix::save_ascii (std::ostream& os, bool& /* infnan_warned */, - bool /* strip_nan_and_inf */) + int /* strip_nan_and_inf */) { dim_vector d = dims (); if (d.length () > 2) diff -r fc46f9c99028 -r cdef72fcd206 src/ov-bool-mat.h --- a/src/ov-bool-mat.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-bool-mat.h Tue Aug 22 20:36:57 2006 +0000 @@ -165,7 +165,7 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-bool.cc --- a/src/ov-bool.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-bool.cc Tue Aug 22 20:36:57 2006 +0000 @@ -134,7 +134,7 @@ bool octave_bool::save_ascii (std::ostream& os, bool& /* infnan_warned */, - bool /* strip_nan_and_inf */) + int /* strip_nan_and_inf */) { double d = double_value (); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-bool.h --- a/src/ov-bool.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-bool.h Tue Aug 22 20:36:57 2006 +0000 @@ -157,7 +157,7 @@ octave_value convert_to_str_internal (bool pad, bool force, char type) const; bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-cell.cc --- a/src/ov-cell.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-cell.cc Tue Aug 22 20:36:57 2006 +0000 @@ -434,7 +434,7 @@ bool octave_cell::save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf) + int strip_nan_and_inf) { dim_vector d = dims (); if (d.length () > 2) diff -r fc46f9c99028 -r cdef72fcd206 src/ov-cell.h --- a/src/ov-cell.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-cell.h Tue Aug 22 20:36:57 2006 +0000 @@ -114,7 +114,7 @@ bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-complex.cc --- a/src/ov-complex.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-complex.cc Tue Aug 22 20:36:57 2006 +0000 @@ -177,7 +177,7 @@ bool octave_complex::save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf) + int strip_nan_and_inf) { Complex c = complex_value (); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-complex.h --- a/src/ov-complex.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-complex.h Tue Aug 22 20:36:57 2006 +0000 @@ -117,7 +117,7 @@ void decrement (void) { scalar -= 1.0; } bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-cx-mat.cc --- a/src/ov-cx-mat.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-cx-mat.cc Tue Aug 22 20:36:57 2006 +0000 @@ -200,48 +200,9 @@ return SparseComplexMatrix (matrix.matrix_value ()); } -static ComplexMatrix -strip_infnan (const ComplexMatrix& m) -{ - octave_idx_type nr = m.rows (); - octave_idx_type nc = m.columns (); - - ComplexMatrix retval (nr, nc); - - octave_idx_type k = 0; - for (octave_idx_type i = 0; i < nr; i++) - { - for (octave_idx_type j = 0; j < nc; j++) - { - Complex c = m (i, j); - if (xisnan (c)) - goto next_row; - else - { - double re = std::real (c); - double im = std::imag (c); - - re = xisinf (re) ? (re > 0 ? OCT_RBV : -OCT_RBV) : re; - im = xisinf (im) ? (im > 0 ? OCT_RBV : -OCT_RBV) : im; - - retval (k, j) = Complex (re, im); - } - } - k++; - - next_row: - continue; - } - - if (k > 0) - retval.resize (k, nc); - - return retval; -} - bool octave_complex_matrix::save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf) + int strip_nan_and_inf) { dim_vector d = dims (); if (d.length () > 2) @@ -276,15 +237,7 @@ ComplexMatrix tmp = complex_matrix_value (); - if (strip_nan_and_inf) - tmp = strip_infnan (tmp); - else if (! infnan_warned && tmp.any_element_is_inf_or_nan ()) - { - warning ("save: Inf or NaN values may not be reloadable"); - infnan_warned = true; - } - - os << tmp; + tmp.save_ascii (os, infnan_warned, strip_nan_and_inf); } return true; diff -r fc46f9c99028 -r cdef72fcd206 src/ov-cx-mat.h --- a/src/ov-cx-mat.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-cx-mat.h Tue Aug 22 20:36:57 2006 +0000 @@ -121,7 +121,7 @@ void decrement (void) { matrix -= Complex (1.0); } bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-fcn-handle.cc --- a/src/ov-fcn-handle.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-fcn-handle.cc Tue Aug 22 20:36:57 2006 +0000 @@ -144,7 +144,7 @@ } bool -octave_fcn_handle::save_ascii (std::ostream& os, bool&, bool) +octave_fcn_handle::save_ascii (std::ostream& os, bool&, int) { os << nm << "\n"; diff -r fc46f9c99028 -r cdef72fcd206 src/ov-fcn-handle.h --- a/src/ov-fcn-handle.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-fcn-handle.h Tue Aug 22 20:36:57 2006 +0000 @@ -85,7 +85,7 @@ std::string fcn_name (void) const { return nm; } bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-fcn-inline.cc --- a/src/ov-fcn-inline.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-fcn-inline.cc Tue Aug 22 20:36:57 2006 +0000 @@ -90,7 +90,7 @@ } bool -octave_fcn_inline::save_ascii (std::ostream& os, bool&, bool) +octave_fcn_inline::save_ascii (std::ostream& os, bool&, int) { os << "# nargs: " << ifargs.length () << "\n"; for (int i = 0; i < ifargs.length (); i++) diff -r fc46f9c99028 -r cdef72fcd206 src/ov-fcn-inline.h --- a/src/ov-fcn-inline.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-fcn-inline.h Tue Aug 22 20:36:57 2006 +0000 @@ -66,7 +66,7 @@ octave_value convert_to_str_internal (bool, bool, char) const; bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-list.cc --- a/src/ov-list.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-list.cc Tue Aug 22 20:36:57 2006 +0000 @@ -539,7 +539,7 @@ bool octave_list::save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf) + int strip_nan_and_inf) { octave_value_list lst = list_value (); os << "# length: " << lst.length () << "\n"; diff -r fc46f9c99028 -r cdef72fcd206 src/ov-list.h --- a/src/ov-list.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-list.h Tue Aug 22 20:36:57 2006 +0000 @@ -100,7 +100,7 @@ bool print_name_tag (std::ostream& os, const std::string& name) const; bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-range.cc --- a/src/ov-range.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-range.cc Tue Aug 22 20:36:57 2006 +0000 @@ -286,7 +286,7 @@ bool octave_range::save_ascii (std::ostream& os, bool& /* infnan_warned */, - bool /* strip_nan_and_inf */) + int /* strip_nan_and_inf */) { Range r = range_value (); double base = r.base (); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-range.h --- a/src/ov-range.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-range.h Tue Aug 22 20:36:57 2006 +0000 @@ -187,7 +187,7 @@ bool print_name_tag (std::ostream& os, const std::string& name) const; bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-re-mat.cc --- a/src/ov-re-mat.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-re-mat.cc Tue Aug 22 20:36:57 2006 +0000 @@ -254,40 +254,9 @@ return retval; } -static Matrix -strip_infnan (const Matrix& m) -{ - octave_idx_type nr = m.rows (); - octave_idx_type nc = m.columns (); - - Matrix retval (nr, nc); - - octave_idx_type k = 0; - for (octave_idx_type i = 0; i < nr; i++) - { - for (octave_idx_type j = 0; j < nc; j++) - { - double d = m (i, j); - if (xisnan (d)) - goto next_row; - else - retval (k, j) = xisinf (d) ? (d > 0 ? OCT_RBV : -OCT_RBV) : d; - } - k++; - - next_row: - continue; - } - - if (k > 0) - retval.resize (k, nc); - - return retval; -} - bool octave_matrix::save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf) + int strip_nan_and_inf) { dim_vector d = dims (); if (d.length () > 2) @@ -322,15 +291,7 @@ Matrix tmp = matrix_value (); - if (strip_nan_and_inf) - tmp = strip_infnan (tmp); - else if (! infnan_warned && tmp.any_element_is_inf_or_nan ()) - { - warning ("save: Inf or NaN values may not be reloadable"); - infnan_warned = true; - } - - os << tmp; + tmp.save_ascii (os, infnan_warned, strip_nan_and_inf); } return true; diff -r fc46f9c99028 -r cdef72fcd206 src/ov-re-mat.h --- a/src/ov-re-mat.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-re-mat.h Tue Aug 22 20:36:57 2006 +0000 @@ -156,7 +156,7 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-scalar.cc --- a/src/ov-scalar.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-scalar.cc Tue Aug 22 20:36:57 2006 +0000 @@ -157,7 +157,7 @@ bool octave_scalar::save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf) + int strip_nan_and_inf) { double d = double_value (); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-scalar.h --- a/src/ov-scalar.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-scalar.h Tue Aug 22 20:36:57 2006 +0000 @@ -187,7 +187,7 @@ void decrement (void) { --scalar; } bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-str-mat.cc --- a/src/ov-str-mat.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-str-mat.cc Tue Aug 22 20:36:57 2006 +0000 @@ -271,7 +271,7 @@ bool octave_char_matrix_str::save_ascii (std::ostream& os, bool& /* infnan_warned */, - bool /* strip_nan_and_inf */) + int /* strip_nan_and_inf */) { dim_vector d = dims (); if (d.length () > 2) diff -r fc46f9c99028 -r cdef72fcd206 src/ov-str-mat.h --- a/src/ov-str-mat.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-str-mat.h Tue Aug 22 20:36:57 2006 +0000 @@ -130,7 +130,7 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov-struct.cc --- a/src/ov-struct.cc Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-struct.cc Tue Aug 22 20:36:57 2006 +0000 @@ -1017,7 +1017,7 @@ bool octave_struct::save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf) + int strip_nan_and_inf) { Octave_map m = map_value (); os << "# length: " << m.length () << "\n"; diff -r fc46f9c99028 -r cdef72fcd206 src/ov-struct.h --- a/src/ov-struct.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov-struct.h Tue Aug 22 20:36:57 2006 +0000 @@ -118,7 +118,7 @@ bool print_name_tag (std::ostream& os, const std::string& name) const; bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf); + int strip_nan_and_inf); bool load_ascii (std::istream& is); diff -r fc46f9c99028 -r cdef72fcd206 src/ov.h --- a/src/ov.h Tue Aug 22 18:37:43 2006 +0000 +++ b/src/ov.h Tue Aug 22 20:36:57 2006 +0000 @@ -779,7 +779,7 @@ const std::string& prefix = std::string ()) const; bool save_ascii (std::ostream& os, bool& infnan_warned, - bool strip_nan_and_inf) + int strip_nan_and_inf) { return rep->save_ascii (os, infnan_warned, strip_nan_and_inf); } bool load_ascii (std::istream& is)