octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Double-prec diag and permutation matrices fall back to sparse ma


From: Jason Riedy
Subject: [PATCH] Double-prec diag and permutation matrices fall back to sparse matrices.
Date: Thu, 05 Mar 2009 13:55:18 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.91 (gnu/linux)

With this change, diag ([1;2;3]) * sprand (3, 3, .5) will produce a
scaled sparse matrix.  Single-precision sparse matrices are not yet
supported in Octave, so the single-precision diagonal matrices still
fall back to dense.

This change only affects the default conversions in Octave, not the
operations available in liboctave.

Signed-of-by: Jason Riedy <address@hidden>
---
  Yes, this is a git patch.  It's just for comments.  A "real" patch
  later will be in Mercurial form.

 src/ChangeLog              |    9 ++++++++
 src/ov-cx-diag.cc          |    5 ++-
 src/ov-perm.cc             |    5 ++-
 src/ov-re-diag.cc          |    5 ++-
 test/ChangeLog             |   10 +++++++++
 test/build_sparse_tests.sh |   47 ++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 75 insertions(+), 6 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 8fd7629..70dc3f5 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
+2009-03-05  Jason Riedy  <address@hidden>
+
+       * ov-re-diag.cc (default_numeric_conversion_function): Fall back
+       into a sparse matrix.
+       (numeric_conversion_function): Return the sparse id.
+       * ov-cx-diag.cc (default_numeric_conversion_function): Fall back
+       into a sparse matrix.
+       (numeric_conversion_function): Return the sparse id.
+
 2009-03-05  Jaroslav Hajek  <address@hidden>
 
        * DLD-FUNCTIONS/sparse.cc (Fsparse): Handle diagonal and permutation
diff --git a/src/ov-cx-diag.cc b/src/ov-cx-diag.cc
index 1ad342b..e53e752 100644
--- a/src/ov-cx-diag.cc
+++ b/src/ov-cx-diag.cc
@@ -32,6 +32,7 @@ along with Octave; see the file COPYING.  If not, see
 #include "ov-base-diag.cc"
 #include "ov-complex.h"
 #include "ov-cx-mat.h"
+#include "ov-cx-sparse.h"
 #include "ls-utils.h"
 
 template class octave_base_diag<ComplexDiagMatrix, ComplexMatrix>;
@@ -46,14 +47,14 @@ default_numeric_conversion_function (const 
octave_base_value& a)
 {
   CAST_CONV_ARG (const octave_complex_diag_matrix&);
 
-  return new octave_complex_matrix (v.complex_matrix_value ());
+  return new octave_sparse_complex_matrix (v.sparse_complex_matrix_value ());
 }
 
 octave_base_value::type_conv_info
 octave_complex_diag_matrix::numeric_conversion_function (void) const
 {
   return octave_base_value::type_conv_info 
(default_numeric_conversion_function,
-                                            
octave_complex_matrix::static_type_id ());
+                                            
octave_sparse_complex_matrix::static_type_id ());
 }
 
 static octave_base_value *
diff --git a/src/ov-perm.cc b/src/ov-perm.cc
index 8326c66..6db3514 100644
--- a/src/ov-perm.cc
+++ b/src/ov-perm.cc
@@ -29,6 +29,7 @@ along with Octave; see the file COPYING.  If not, see
 #include "ov-perm.h"
 #include "ov-flt-perm.h"
 #include "ov-re-mat.h"
+#include "ov-re-sparse.h"
 #include "ov-scalar.h"
 #include "error.h"
 #include "gripes.h"
@@ -469,14 +470,14 @@ default_numeric_conversion_function (const 
octave_base_value& a)
 {
   CAST_CONV_ARG (const octave_perm_matrix&);
 
-  return new octave_matrix (v.matrix_value ());
+  return new octave_sparse_matrix (v.sparse_matrix_value ());
 }
 
 octave_base_value::type_conv_info
 octave_perm_matrix::numeric_conversion_function (void) const
 {
   return octave_base_value::type_conv_info 
(default_numeric_conversion_function,
-                                            octave_matrix::static_type_id ());
+                                            
octave_sparse_matrix::static_type_id ());
 }
 
 static octave_base_value *
diff --git a/src/ov-re-diag.cc b/src/ov-re-diag.cc
index 4086a29..eb029f1 100644
--- a/src/ov-re-diag.cc
+++ b/src/ov-re-diag.cc
@@ -31,6 +31,7 @@ along with Octave; see the file COPYING.  If not, see
 #include "ov-base-diag.cc"
 #include "ov-scalar.h"
 #include "ov-re-mat.h"
+#include "ov-re-sparse.h"
 #include "ls-utils.h"
 
 template class octave_base_diag<DiagMatrix, Matrix>;
@@ -44,14 +45,14 @@ default_numeric_conversion_function (const 
octave_base_value& a)
 {
   CAST_CONV_ARG (const octave_diag_matrix&);
 
-  return new octave_matrix (v.matrix_value ());
+  return new octave_sparse_matrix (v.sparse_matrix_value ());
 }
 
 octave_base_value::type_conv_info
 octave_diag_matrix::numeric_conversion_function (void) const
 {
   return octave_base_value::type_conv_info 
(default_numeric_conversion_function,
-                                            octave_matrix::static_type_id ());
+                                            
octave_sparse_matrix::static_type_id ());
 }
 
 static octave_base_value *
diff --git a/test/ChangeLog b/test/ChangeLog
index bae7a1c..b1a43c4 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,13 @@
+2009-03-05  Jason Riedy  <address@hidden>
+
+       * build_sparse_tests.sh (gen_diagsparse_op_tests)
+       (gen_sparsediag_op_tests): New, require that operations between
+       sparse and diagonal matrices preserve sparsity.
+       (gen_permsparse_tests): New, require that permutation matrices
+       devolve into sparse matrices.
+       (gen_rectangular_tests): Call the new diag and sparse mixing
+       tests and the new permutation test.
+
 2009-02-25  John W. Eaton  <address@hidden>
 
        * build_sparse_tests.sh: Note that saving sparse matrices to MAT
diff --git a/test/build_sparse_tests.sh b/test/build_sparse_tests.sh
index a552a65..5fecfd6 100755
--- a/test/build_sparse_tests.sh
+++ b/test/build_sparse_tests.sh
@@ -408,6 +408,50 @@ gen_matrixdiag_tests() {
 EOF
 }
 
+# test diagonal OP sparse operations
+gen_diagsparse_op_tests() {
+    cat >>$TESTS <<EOF
+%!test
+%! d1 = 5 * eye (size (as));
+%! dscal = 5 * eye (size (as, 1));
+%! assert (issparse (d1 + as));
+%! assert (issparse (d1 - as));
+%! assert (issparse (d1 .* as));
+%! assert (issparse (d1.' * as));
+%! assert (issparse (dscal \ as));
+
+EOF
+}
+
+# test diagonal OP sparse operations
+gen_sparsediag_op_tests() {
+    cat >>$TESTS <<EOF
+%!test
+%! d1 = 5 * eye (size (as));
+%! dscal = 5 * eye (size (as, 2));
+%! assert (issparse (as + d1));
+%! assert (issparse (as - d1));
+%! assert (issparse (as .* d1));
+%! assert (issparse (as.' * d1));
+%! assert (issparse (as / dscal));
+
+EOF
+}
+
+# test diagonal OP sparse operations
+gen_permsparse_tests() {
+    cat >>$TESTS <<EOF
+%!test
+%! p = eye (size (as, 1))(randperm (size (as, 1)), :);
+%! p2 = eye (size (as, 1))(randperm (size (as, 1)), :);
+%! assert (issparse (p + p2));
+%! assert (issparse (p - p2));
+%! assert (issparse (p .* p2));
+%! assert (issparse (p * as));
+
+EOF
+}
+
 # test matrix reshape operations
 gen_matrixreshape_tests() {
     cat >>$TESTS <<EOF
@@ -744,6 +788,9 @@ gen_rectangular_tests() {
     gen_matrixop_tests
     # gen_divop_tests # Disable rectangular \ and / for now
     gen_matrixdiag_tests
+    gen_diagsparse_op_tests
+    gen_sparsediag_op_tests
+    gen_permsparse_tests
     gen_matrixreshape_tests
 }
 
-- 
1.6.1.235.g87891



reply via email to

[Prev in Thread] Current Thread [Next in Thread]