[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
warn_* built-in variables
From: |
John W. Eaton |
Subject: |
warn_* built-in variables |
Date: |
Tue, 2 May 2006 15:58:51 -0400 |
I just checked in a largeish change that eliminates all warn_*
built-in variables. Here is the NEWS file entry I wrote for this
change:
* Previous versions of Octave had a number of built-in variables to
control warnings (for example, warn_divide_by_zero). These
variables have been replaced by warning identifiers that are used
with the warning function to control the state of warnings. Now,
instead of writing
warn_divide_by_zero = false;
to disable divide-by-zero warnings, you should write
warning ("off", "Octave:divide-by-zero");
You may use the same technique in your own code to control
warnings. For example, you can use
warning ("My-package:phase-of-the-moon",
"the phase of the moon could cause trouble today");
to allow users to control this warning using the
"My-package:phase-of-the-moon" warning identifier.
You may also enable or disable all warnings, or turn them into
errors:
warning ("on", "all");
warning ("off", "all");
warning ("error", "Octave:divide-by-zero");
warning ("error", "all");
You can query the state of current warnings using
warning ("query", ID)
warning ("query")
(only those warning IDs which have been explicitly set are
returned).
A partial list and description of warning identifiers is available
using
help warning_ids
The following patch will also adapt Octave Forge to this change and
also removes some old #ifdef cruft.
BTW, when I updated my copy of Octave Forge, it did not include the
recent changes I posted to handle changes in the structure of the
octave_value classes. Am I missing something? Should I be using CVS
HEAD or a branch to get the latest Octave Forge sources that are
intended to work with the Octave CVS sources?
Thanks,
jwe
Index: main/comm/ov-galois.cc
===================================================================
RCS file: /cvsroot/octave/octave-forge/main/comm/ov-galois.cc,v
retrieving revision 1.13
diff -u -r1.13 ov-galois.cc
--- main/comm/ov-galois.cc 9 Nov 2004 23:34:49 -0000 1.13
+++ main/comm/ov-galois.cc 2 May 2006 19:44:29 -0000
@@ -322,20 +326,13 @@
{
double retval = lo_ieee_nan_value ();
- // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar()
-#if defined(HAVE_DO_FORTRAN_INDEXING)
- if ((rows () == 1 && columns () == 1)
- || (Vdo_fortran_indexing && rows () > 0 && columns () > 0))
- retval = (double) gval (0, 0);
-#else
if (rows () > 0 && columns () > 0)
{
- if (Vwarn_fortran_indexing)
- gripe_implicit_conversion ("real matrix", "real scalar");
+ gripe_implicit_conversion ("Octave:array-as-scalar",
+ "real matrix", "real scalar");
retval = (double) gval (0, 0);
}
-#endif
else
gripe_invalid_conversion ("galois", "real scalar");
@@ -349,19 +346,13 @@
Complex retval (tmp, tmp);
-#if defined(HAVE_DO_FORTRAN_INDEXING)
- if ((rows () == 1 && columns () == 1)
- || (Vdo_fortran_indexing && rows () > 0 && columns () > 0))
- retval = (double) gval (0, 0);
-#else
if (rows () > 0 && columns () > 0)
{
- if (Vwarn_fortran_indexing)
- gripe_implicit_conversion ("real matrix", "real scalar");
+ gripe_implicit_conversion ("Octave:array-as-scalar",
+ "real matrix", "real scalar");
retval = (double) gval (0, 0);
}
-#endif
else
gripe_invalid_conversion ("galois", "complex scalar");
Index: main/fixed/ov-fixed-complex.cc
===================================================================
RCS file: /cvsroot/octave/octave-forge/main/fixed/ov-fixed-complex.cc,v
retrieving revision 1.4
diff -u -r1.4 ov-fixed-complex.cc
--- main/fixed/ov-fixed-complex.cc 9 Nov 2004 23:34:49 -0000 1.4
+++ main/fixed/ov-fixed-complex.cc 2 May 2006 19:44:30 -0000
@@ -73,20 +73,12 @@
octave_fixed_complex::array_value (bool force_conversion) const
{
NDArray retval;
- int flag = force_conversion;
-#if defined(HAVE_OK_TO_LOSE_IMAGINARY_PART)
- if (! flag)
- flag = Vok_to_lose_imaginary_part;
-#else
- if (! flag)
- flag = (Vwarn_imag_to_real ? -1 : 1);
-#endif
+ if (! force_conversion)
+ gripe_implicit_conversion ("Octave:imag-to-real",
+ "fixed complex", "matrix");
- if (flag > 0)
- retval = NDArray (dim_vector (1, 1), real (scalar.fixedpoint ()));
- else
- gripe_implicit_conversion ("fixed complex", "matrix");
+ retval = NDArray (dim_vector (1, 1), real (scalar.fixedpoint ()));
return retval;
}
@@ -247,23 +239,11 @@
{
FixedPoint retval;
- int flag = force_conversion;
-
-#if defined(HAVE_OK_TO_LOSE_IMAGINARY_PART)
- if (! flag)
- flag = Vok_to_lose_imaginary_part;
-#else
- if (! flag)
- flag = (Vwarn_imag_to_real ? -1 : 1);
-#endif
-
- if (flag < 0)
- gripe_implicit_conversion ("fixed complex", "fixed scalar");
+ if (! force_conversion)
+ gripe_implicit_conversion ("Octave:imag-to-real",
+ "fixed complex", "fixed scalar");
- if (flag)
- retval = FixedPoint(real (scalar));
- else
- gripe_invalid_conversion ("fixed complex", "fixed scalar");
+ retval = FixedPoint(real (scalar));
return retval;
}
@@ -273,20 +253,11 @@
{
FixedMatrix retval;
- int flag = force_conversion;
-
-#if defined(HAVE_OK_TO_LOSE_IMAGINARY_PART)
- if (! flag)
- flag = Vok_to_lose_imaginary_part;
-#else
- if (! flag)
- flag = (Vwarn_imag_to_real ? -1 : 1);
-#endif
-
- if (flag > 0)
- retval = FixedMatrix(1,1,real (scalar));
- else
- gripe_invalid_conversion ("fixed complex", "fixed matrix");
+ if (! force_conversion)
+ gripe_implicit_conversion ("Octave:imag-to-real",
+ "fixed complex", "fixed matrix");
+
+ retval = FixedMatrix(1,1,real (scalar));
return retval;
}
Index: main/fixed/ov-fixed-cx-mat.cc
===================================================================
RCS file: /cvsroot/octave/octave-forge/main/fixed/ov-fixed-cx-mat.cc,v
retrieving revision 1.5
diff -u -r1.5 ov-fixed-cx-mat.cc
--- main/fixed/ov-fixed-cx-mat.cc 9 Nov 2004 23:34:49 -0000 1.5
+++ main/fixed/ov-fixed-cx-mat.cc 2 May 2006 19:44:30 -0000
@@ -94,29 +94,19 @@
octave_fixed_complex_matrix::array_value (bool force_conversion) const
{
NDArray retval;
- int flag = force_conversion;
-#if defined(HAVE_OK_TO_LOSE_IMAGINARY_PART)
- if (! flag)
- flag = Vok_to_lose_imaginary_part;
-#else
- if (! flag)
- flag = (Vwarn_imag_to_real ? -1 : 1);
-#endif
+ if (! force_conversion)
+ gripe_implicit_conversion ("Octave:imag-to-real",
+ "fixed complex", "matrix");
- if (flag > 0)
- {
- int nr = rows ();
- int nc = columns ();
- dim_vector dv(nr,nc);
- retval.resize (dv);
-
- for (int i=0; i<nr; i++)
- for (int j=0; j<nc; j++)
- retval(i + j*nr) = real (matrix(i,j).fixedpoint());
- }
- else
- gripe_implicit_conversion ("fixed complex", "matrix");
+ int nr = rows ();
+ int nc = columns ();
+ dim_vector dv(nr,nc);
+ retval.resize (dv);
+
+ for (int i=0; i<nr; i++)
+ for (int j=0; j<nc; j++)
+ retval(i + j*nr) = real (matrix(i,j).fixedpoint());
return retval;
}
@@ -349,37 +339,16 @@
{
double retval = lo_ieee_nan_value ();
- int flag = force_conversion;
+ if (! force_conversion)
+ gripe_implicit_conversion ("Octave:imag-to-real",
+ "fixed complex matrix", "real scalar");
-#if defined(HAVE_OK_TO_LOSE_IMAGINARY_PART)
- if (! flag)
- flag = Vok_to_lose_imaginary_part;
-#else
- if (! flag)
- flag = (Vwarn_imag_to_real ? -1 : 1);
-#endif
-
- if (flag < 0)
- gripe_implicit_conversion ("fixed complex matrix", "real scalar");
-
- if (flag)
+ if (rows () > 0 && columns () > 0)
{
-
-#if defined(HAVE_DO_FORTRAN_INDEXING)
- if ((rows () == 1 && columns () == 1)
- || (Vdo_fortran_indexing && rows () > 0 && columns () > 0))
- retval = std::real (matrix (0, 0) .fixedpoint());
-#else
- if (rows () > 0 && columns () > 0)
- {
- if (Vwarn_fortran_indexing)
- gripe_implicit_conversion ("real matrix", "real scalar");
+ gripe_implicit_conversion ("Octave:array-as-scalar",
+ "real matrix", "real scalar");
- retval = std::real (matrix (0, 0) .fixedpoint());
- }
-#endif
- else
- gripe_invalid_conversion ("fixed complex matrix", "real scalar");
+ retval = std::real (matrix (0, 0) .fixedpoint());
}
else
gripe_invalid_conversion ("fixed complex matrix", "real scalar");
@@ -392,36 +361,16 @@
{
FixedPoint retval;
- int flag = force_conversion;
-
-#if defined(HAVE_OK_TO_LOSE_IMAGINARY_PART)
- if (! flag)
- flag = Vok_to_lose_imaginary_part;
-#else
- if (! flag)
- flag = (Vwarn_imag_to_real ? -1 : 1);
-#endif
+ if (! force_conversion)
+ gripe_implicit_conversion ("Octave:imag-to-real",
+ "fixed complex matrix", "fixed scalar");
- if (flag < 0)
- gripe_implicit_conversion ("fixed complex matrix", "fixed scalar");
-
- if (flag)
+ if (rows () > 0 && columns () > 0)
{
-#if defined(HAVE_DO_FORTRAN_INDEXING)
- if ((rows () == 1 && columns () == 1)
- || (Vdo_fortran_indexing && rows () > 0 && columns () > 0))
- retval = real( matrix (0, 0));
-#else
- if (rows () > 0 && columns () > 0)
- {
- if (Vwarn_fortran_indexing)
- gripe_implicit_conversion ("real matrix", "real scalar");
-
- retval = real( matrix (0, 0));
- }
-#endif
- else
- gripe_invalid_conversion ("fixed complex matrix", "fixed scalar");
+ gripe_implicit_conversion ("Octave:array-as-scalar",
+ "real matrix", "real scalar");
+
+ retval = real( matrix (0, 0));
}
else
gripe_invalid_conversion ("fixed complex matrix", "fixed scalar");
@@ -434,23 +383,12 @@
{
Matrix retval;
- int flag = force_conversion;
+ if (! force_conversion)
+ gripe_implicit_conversion ("Octave:imag-to-real",
+ "fixed complex matrix", "real matrix");
-#if defined(HAVE_OK_TO_LOSE_IMAGINARY_PART)
- if (! flag)
- flag = Vok_to_lose_imaginary_part;
-#else
- if (! flag)
- flag = (Vwarn_imag_to_real ? -1 : 1);
-#endif
- if (flag < 0)
- gripe_implicit_conversion ("fixed complex matrix", "real matrix");
-
- if (flag)
- retval = ::real (matrix.fixedpoint());
- else
- gripe_invalid_conversion ("fixed complex matrix", "real matrix");
+ retval = ::real (matrix.fixedpoint());
return retval;
}
@@ -460,23 +398,11 @@
{
FixedMatrix retval;
- int flag = force_conversion;
+ if (! force_conversion)
+ gripe_implicit_conversion ("Octave:imag-to-real",
+ "fixed complex matrix", "fixed matrix");
-#if defined(HAVE_OK_TO_LOSE_IMAGINARY_PART)
- if (! flag)
- flag = Vok_to_lose_imaginary_part;
-#else
- if (! flag)
- flag = (Vwarn_imag_to_real ? -1 : 1);
-#endif
-
- if (flag < 0)
- gripe_implicit_conversion ("fixed complex matrix", "fixed matrix");
-
- if (flag)
- retval = real (matrix);
- else
- gripe_invalid_conversion ("fixed complex matrix", "fixed matrix");
+ retval = real (matrix);
return retval;
}
@@ -488,19 +414,13 @@
Complex retval (tmp, tmp);
-#if defined(HAVE_DO_FORTRAN_INDEXING)
- if ((rows () == 1 && columns () == 1)
- || (Vdo_fortran_indexing && rows () > 0 && columns () > 0))
- retval = matrix (0, 0) .fixedpoint();
-#else
- if (rows () > 0 && columns () > 0)
- {
- if (Vwarn_fortran_indexing)
- gripe_implicit_conversion ("real matrix", "real scalar");
+ if (rows () > 0 && columns () > 0)
+ {
+ gripe_implicit_conversion ("Octave:array-as-scalar",
+ "real matrix", "real scalar");
- retval = matrix (0, 0) .fixedpoint();
- }
-#endif
+ retval = matrix (0, 0) .fixedpoint();
+ }
else
gripe_invalid_conversion ("fixed matrix", "complex scalar");
Index: main/fixed/ov-fixed-mat.cc
===================================================================
RCS file: /cvsroot/octave/octave-forge/main/fixed/ov-fixed-mat.cc,v
retrieving revision 1.6
diff -u -r1.6 ov-fixed-mat.cc
--- main/fixed/ov-fixed-mat.cc 9 Nov 2004 23:34:49 -0000 1.6
+++ main/fixed/ov-fixed-mat.cc 2 May 2006 19:44:30 -0000
@@ -309,20 +309,13 @@
{
double retval = lo_ieee_nan_value ();
- // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar()
-#if defined(HAVE_DO_FORTRAN_INDEXING)
- if ((rows () == 1 && columns () == 1)
- || (Vdo_fortran_indexing && rows () > 0 && columns () > 0))
- retval = matrix (0, 0) .fixedpoint();
-#else
if (rows () > 0 && columns () > 0)
{
- if (Vwarn_fortran_indexing)
- gripe_implicit_conversion ("real matrix", "real scalar");
+ gripe_implicit_conversion ("Octave:array-as-scalar",
+ "real matrix", "real scalar");
retval = matrix (0, 0) .fixedpoint();
}
-#endif
else
gripe_invalid_conversion ("fixed matrix", "real scalar");
@@ -349,19 +342,13 @@
Complex retval (tmp, tmp);
-#if defined(HAVE_DO_FORTRAN_INDEXING)
- if ((rows () == 1 && columns () == 1)
- || (Vdo_fortran_indexing && rows () > 0 && columns () > 0))
- retval = matrix (0, 0) .fixedpoint();
-#else
if (rows () > 0 && columns () > 0)
{
- if (Vwarn_fortran_indexing)
- gripe_implicit_conversion ("real matrix", "real scalar");
+ gripe_implicit_conversion ("Octave:array-as-scalar",
+ "real matrix", "real scalar");
retval = matrix (0, 0) .fixedpoint();
}
-#endif
else
gripe_invalid_conversion ("fixed matrix", "complex scalar");
- warn_* built-in variables,
John W. Eaton <=