[RFC PATCH 2/2] Add Octave:unexpected-densifying warning.
Jason Riedy
ejr at cs.berkeley.edu
Thu Dec 6 18:32:08 CST 2007
Warn whenever a sparse matrix is converted to a dense matrix
in an unexpected context. The context is made "expected" by
disabling the warning. Possibly not the best idea, but the
warning is disabled by default.
The only expected context included here is full().
---
scripts/ChangeLog | 5 +++++
scripts/miscellaneous/warning_ids.m | 6 ++++++
src/ChangeLog | 25 +++++++++++++++++++++++++
src/DLD-FUNCTIONS/sparse.cc | 1 +
src/error.cc | 1 +
src/gripes.cc | 7 +++++++
src/gripes.h | 3 +++
src/ov-bool-sparse.cc | 6 ++++++
src/ov-cx-sparse.cc | 3 +++
src/ov-re-sparse.cc | 5 +++++
10 files changed, 62 insertions(+), 0 deletions(-)
diff --git a/scripts/ChangeLog b/scripts/ChangeLog
index 6b72c5c..7a8be38 100644
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,8 @@
+2007-12-06 Jason Riedy <ejr at cs.berkeley.edu>
+
+ * miscellaneous/warning_ids.m: Add Octave:unexpectedly-densifying
+ description.
+
2007-12-06 John W. Eaton <jwe at octave.org>
* general/issymmetric.m: Move tests here from test/test_number.m
diff --git a/scripts/miscellaneous/warning_ids.m b/scripts/miscellaneous/warning_ids.m
index 3bbfae4..41a4e13 100644
--- a/scripts/miscellaneous/warning_ids.m
+++ b/scripts/miscellaneous/warning_ids.m
@@ -234,4 +234,10 @@
## will print a warning if a switch label is not a constant or constant
## expression. By default, the @code{Octave:variable-switch-label}
## warning is disabled.
+##
+## @item Octave:unexpectedly-densifying
+## If the @code{Octave:unexpectedly-densifying} warning is enabled, Octave
+## will print a warning if a sparse matrix is converted to a dense
+## matrix in an unexpected context.By default, the
+## @code{Octave:unexpectedly-densifying} warning is disabled.
## @end table
diff --git a/src/ChangeLog b/src/ChangeLog
index 5278a66..2166ec2 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,30 @@
2007-12-06 Jason Riedy <ejr at cs.berkeley.edu>
+ * gripes.h (unexpectedly_densifying): Declare a warning for
+ when a sparse matrix is converted to a dense matrix in an
+ unexpected conext.
+ * gripes.cc (unexpectedly_densifying): Define.
+ * error.cc (initialize_default_warning_state): Disable warning by
+ default.
+ * ov-bool-sparse.cc (octave_sparse_bool_matrix::matrix_value,
+ octave_sparse_bool_matrix::complex_matrix_value,
+ octave_sparse_bool_matrix::complex_array_value,
+ octave_sparse_bool_matrix::array_value,
+ octave_sparse_bool_matrix::bool_matrix_value,
+ octave_sparse_bool_matrix::bool_array_value): Warn.
+ * ov-re-sparse.cc (octave_sparse_matrix::matrix_value,
+ octave_sparse_matrix::complex_matrix_value,
+ octave_sparse_matrix::complex_array_value,
+ octave_sparse_matrix::array_value,
+ octave_sparse_matrix::bool_array_value): Warn.
+ * ov-cx-sparse.cc (octave_sparse_complex_matrix::matrix_value,
+ octave_sparse_complex_matrix::complex_matrix_value,
+ octave_sparse_complex_matrix::complex_array_value): Warn.
+ * DLD-FUNCTIONS/sparse.cc (Ffull): Expect to densify here, so
+ disable the warning.
+
+2007-12-06 Jason Riedy <ejr at cs.berkeley.edu>
+
* error.h (struct octave_warning_suspend): New class for disabling
a warning within a scope.
* error.cc (octave_warning_suspend_init): Common init and
diff --git a/src/DLD-FUNCTIONS/sparse.cc b/src/DLD-FUNCTIONS/sparse.cc
index f69ae8b..e004e31 100644
--- a/src/DLD-FUNCTIONS/sparse.cc
+++ b/src/DLD-FUNCTIONS/sparse.cc
@@ -370,6 +370,7 @@ DEFUN_DLD (full, args, ,
@end deftypefn")
{
octave_value retval;
+ octave_warning_suspend("Octave:unexpectedly-densifying");
if (args.length() < 1)
{
diff --git a/src/error.cc b/src/error.cc
index 2638a0c..7bd6fe3 100644
--- a/src/error.cc
+++ b/src/error.cc
@@ -1413,6 +1413,7 @@ initialize_default_warning_state (void)
disable_warning ("Octave:str-to-num");
disable_warning ("Octave:string-concat");
disable_warning ("Octave:variable-switch-label");
+ disable_warning ("Octave:unexpectedly-densifying");
}
DEFUN (lasterror, args, ,
diff --git a/src/gripes.cc b/src/gripes.cc
index 74942df..3aaae53 100644
--- a/src/gripes.cc
+++ b/src/gripes.cc
@@ -197,6 +197,13 @@ gripe_logical_conversion (void)
"value not equal to 1 or 0 converted to logical 1");
}
+extern void
+gripe_unexpectedly_densifying (void)
+{
+ warning_with_id ("Octave:unexpectedly-densifying",
+ "sparse matrix unexpectedly converted to dense");
+}
+
/*
;;; Local Variables: ***
;;; mode: C++ ***
diff --git a/src/gripes.h b/src/gripes.h
index 0c0a12a..2cd5e45 100644
--- a/src/gripes.h
+++ b/src/gripes.h
@@ -109,6 +109,9 @@ gripe_divide_by_zero (void);
extern OCTINTERP_API void
gripe_logical_conversion (void);
+extern OCTINTERP_API void
+gripe_unexpectedly_densifying (void);
+
#endif
/*
diff --git a/src/ov-bool-sparse.cc b/src/ov-bool-sparse.cc
index f5cf3ca..78a3653 100644
--- a/src/ov-bool-sparse.cc
+++ b/src/ov-bool-sparse.cc
@@ -150,36 +150,42 @@ octave_sparse_bool_matrix::convert_to_str_internal (bool pad, bool force,
Matrix
octave_sparse_bool_matrix::matrix_value (bool) const
{
+ gripe_unexpectedly_densifying ();
return Matrix (matrix.matrix_value ());
}
ComplexMatrix
octave_sparse_bool_matrix::complex_matrix_value (bool) const
{
+ gripe_unexpectedly_densifying ();
return ComplexMatrix (matrix.matrix_value ());
}
ComplexNDArray
octave_sparse_bool_matrix::complex_array_value (bool) const
{
+ gripe_unexpectedly_densifying ();
return ComplexNDArray (ComplexMatrix (matrix.matrix_value ()));
}
NDArray
octave_sparse_bool_matrix::array_value (bool) const
{
+ gripe_unexpectedly_densifying ();
return NDArray (Matrix(matrix.matrix_value ()));
}
boolMatrix
octave_sparse_bool_matrix::bool_matrix_value (bool) const
{
+ gripe_unexpectedly_densifying ();
return matrix.matrix_value ();
}
boolNDArray
octave_sparse_bool_matrix::bool_array_value (bool) const
{
+ gripe_unexpectedly_densifying ();
return boolNDArray (matrix.matrix_value ());
}
diff --git a/src/ov-cx-sparse.cc b/src/ov-cx-sparse.cc
index cc241c6..3d5cc4e 100644
--- a/src/ov-cx-sparse.cc
+++ b/src/ov-cx-sparse.cc
@@ -155,6 +155,7 @@ octave_sparse_complex_matrix::matrix_value (bool force_conversion) const
if (! force_conversion)
gripe_implicit_conversion ("Octave:imag-to-real",
"complex sparse matrix", "real matrix");
+ gripe_unexpectedly_densifying ();
retval = ::real (matrix.matrix_value ());
@@ -186,12 +187,14 @@ octave_sparse_complex_matrix::complex_value (bool) const
ComplexMatrix
octave_sparse_complex_matrix::complex_matrix_value (bool) const
{
+ gripe_unexpectedly_densifying ();
return matrix.matrix_value ();
}
ComplexNDArray
octave_sparse_complex_matrix::complex_array_value (bool) const
{
+ gripe_unexpectedly_densifying ();
return ComplexNDArray (matrix.matrix_value ());
}
diff --git a/src/ov-re-sparse.cc b/src/ov-re-sparse.cc
index c4757bc..10b72e8 100644
--- a/src/ov-re-sparse.cc
+++ b/src/ov-re-sparse.cc
@@ -139,6 +139,7 @@ octave_sparse_matrix::complex_value (bool) const
Matrix
octave_sparse_matrix::matrix_value (bool) const
{
+ gripe_unexpectedly_densifying ();
return matrix.matrix_value ();
}
@@ -149,6 +150,7 @@ octave_sparse_matrix::bool_array_value (bool warn) const
if (warn && m.any_element_not_one_or_zero ())
gripe_logical_conversion ();
+ gripe_unexpectedly_densifying ();
return boolNDArray (m);
}
@@ -156,18 +158,21 @@ octave_sparse_matrix::bool_array_value (bool warn) const
ComplexMatrix
octave_sparse_matrix::complex_matrix_value (bool) const
{
+ gripe_unexpectedly_densifying ();
return ComplexMatrix (matrix.matrix_value ());
}
ComplexNDArray
octave_sparse_matrix::complex_array_value (bool) const
{
+ gripe_unexpectedly_densifying ();
return ComplexNDArray (ComplexMatrix (matrix.matrix_value ()));
}
NDArray
octave_sparse_matrix::array_value (bool) const
{
+ gripe_unexpectedly_densifying ();
return NDArray (matrix.matrix_value ());
}
--
debian.1.5.3.7.1-dirty
More information about the Octave-maintainers
mailing list