# HG changeset patch # User dbateman # Date 1140639360 0 # Node ID 7171d19706df9cedee41b196bd6081f6eb94dc75 # Parent 512d0d11ae396e0e3bb79818f59e7ab9e5dfabea [project @ 2006-02-22 20:15:06 by dbateman] diff -r 512d0d11ae39 -r 7171d19706df src/ChangeLog --- a/src/ChangeLog Mon Feb 20 22:05:32 2006 +0000 +++ b/src/ChangeLog Wed Feb 22 20:16:00 2006 +0000 @@ -1,5 +1,16 @@ 2006-02-20 David Bateman + * ov.h (virtual bool is_sparse_type (bool)): New virtual function + * ov-base.h (bool is_sparse_type (bool)): New function + * ov-base-sparse.h (bool is_sparse_type (bool)): New function + * DLD-FUNCTIONS/ccolamd.cc, DLD-FUNCTION/colamd.cc, + DLD-FUNCTIONS/__glpk__.cc, DLD-FUNCTIONS/splu.cc, + DLD-FUNCTIONS/sparse.cc, DLD-FUNCTIONS/matrix_type.cc, pt-mat.cc: + Replace us of 'arg.class_name () == "sparse"' with + 'arg.is_sparse_type ()' + +2006-02-20 David Bateman + * pt-mat.cc (class tm_row_const): Add any_sparse bool variable. (tm_row_const::tm_row_const_rep::do_init_element): Initialize any_sparse variable if any matrice is sparse. diff -r 512d0d11ae39 -r 7171d19706df src/DLD-FUNCTIONS/__glpk__.cc --- a/src/DLD-FUNCTIONS/__glpk__.cc Mon Feb 20 22:05:32 2006 +0000 +++ b/src/DLD-FUNCTIONS/__glpk__.cc Wed Feb 22 20:16:00 2006 +0000 @@ -450,37 +450,7 @@ //-- 2nd Input. A matrix containing the constraints coefficients. // If matrix A is NOT a sparse matrix - if( args(1).class_name () != "sparse") - { - Matrix A (args(1).matrix_value ()); // get the matrix - - if (error_state) - { - error ("__glpk__: invalid value of A"); - return retval; - } - - mrowsA = A.rows (); - rn.resize (mrowsA*mrowsc+1); - cn.resize (mrowsA*mrowsc+1); - a.resize (mrowsA*mrowsc+1, 0.0); - - for (int i = 0; i < mrowsA; i++) - { - for (int j = 0; j < mrowsc; j++) - { - if (A(i,j) != 0) - { - nz++; - rn(nz) = i + 1; - cn(nz) = j + 1; - a(nz) = A(i,j); - } - } - } - - } - else + if (args(1).is_sparse_type ()) { SparseMatrix A = args(1).sparse_matrix_value (); // get the sparse matrix @@ -512,6 +482,36 @@ a(nz) = A.data(i); } } + else + { + Matrix A (args(1).matrix_value ()); // get the matrix + + if (error_state) + { + error ("__glpk__: invalid value of A"); + return retval; + } + + mrowsA = A.rows (); + rn.resize (mrowsA*mrowsc+1); + cn.resize (mrowsA*mrowsc+1); + a.resize (mrowsA*mrowsc+1, 0.0); + + for (int i = 0; i < mrowsA; i++) + { + for (int j = 0; j < mrowsc; j++) + { + if (A(i,j) != 0) + { + nz++; + rn(nz) = i + 1; + cn(nz) = j + 1; + a(nz) = A(i,j); + } + } + } + + } //-- 3rd Input. A column array containing the right-hand side value // for each constraint in the constraint matrix. diff -r 512d0d11ae39 -r 7171d19706df src/DLD-FUNCTIONS/ccolamd.cc --- a/src/DLD-FUNCTIONS/ccolamd.cc Mon Feb 20 22:05:32 2006 +0000 +++ b/src/DLD-FUNCTIONS/ccolamd.cc Wed Feb 22 20:16:00 2006 +0000 @@ -211,7 +211,7 @@ SparseComplexMatrix scm; SparseMatrix sm; - if (args(0).class_name () == "sparse") + if (args(0).is_sparse_type ()) { if (args(0).is_complex_type ()) { @@ -447,7 +447,7 @@ SparseMatrix sm; SparseComplexMatrix scm; - if (args(0).class_name () == "sparse") + if (args(0).is_sparse_type ()) { if (args(0).is_complex_type ()) { diff -r 512d0d11ae39 -r 7171d19706df src/DLD-FUNCTIONS/colamd.cc --- a/src/DLD-FUNCTIONS/colamd.cc Mon Feb 20 22:05:32 2006 +0000 +++ b/src/DLD-FUNCTIONS/colamd.cc Wed Feb 22 20:16:00 2006 +0000 @@ -330,7 +330,7 @@ SparseComplexMatrix scm; SparseMatrix sm; - if (args(0).class_name () == "sparse") + if (args(0).is_sparse_type ()) { if (args(0).is_complex_type ()) { @@ -539,7 +539,7 @@ SparseMatrix sm; SparseComplexMatrix scm; - if (args(0).class_name () == "sparse") + if (args(0).is_sparse_type ()) { if (args(0).is_complex_type ()) { @@ -664,7 +664,7 @@ SparseMatrix sm; SparseComplexMatrix scm; - if (args(0).class_name () == "sparse") + if (args(0).is_sparse_type ()) { if (args(0).is_complex_type ()) { diff -r 512d0d11ae39 -r 7171d19706df src/DLD-FUNCTIONS/matrix_type.cc --- a/src/DLD-FUNCTIONS/matrix_type.cc Mon Feb 20 22:05:32 2006 +0000 +++ b/src/DLD-FUNCTIONS/matrix_type.cc Wed Feb 22 20:16:00 2006 +0000 @@ -104,7 +104,7 @@ error ("matrix_type: incorrect number of arguments"); else { - if (args(0).class_name () == "sparse") + if (args(0).is_sparse_type ()) { if (nargin == 1) { diff -r 512d0d11ae39 -r 7171d19706df src/DLD-FUNCTIONS/sparse.cc --- a/src/DLD-FUNCTIONS/sparse.cc Mon Feb 20 22:05:32 2006 +0000 +++ b/src/DLD-FUNCTIONS/sparse.cc Wed Feb 22 20:16:00 2006 +0000 @@ -41,7 +41,7 @@ static bool is_sparse (const octave_value& arg) { - return (arg.class_name () == "sparse"); + return (arg.is_sparse_type ()); } DEFUN_DLD (issparse, args, , @@ -385,7 +385,7 @@ return retval; } - if (args(0).class_name () == "sparse") + if (args(0).is_sparse_type ()) { if (args(0).type_name () == "sparse matrix") retval = args(0).matrix_value (); @@ -563,7 +563,7 @@ octave_value arg = args(0); - if (arg.class_name () == "sparse") + if (arg.is_sparse_type ()) { if (arg.type_name () == "sparse matrix") retval = sparse_find (args(0).sparse_matrix_value ()); diff -r 512d0d11ae39 -r 7171d19706df src/DLD-FUNCTIONS/splu.cc --- a/src/DLD-FUNCTIONS/splu.cc Mon Feb 20 22:05:32 2006 +0000 +++ b/src/DLD-FUNCTIONS/splu.cc Wed Feb 22 20:16:00 2006 +0000 @@ -99,7 +99,7 @@ for (int k = 1; k < nargin; k++) { - if (args(k).class_name () == "sparse") + if (args(k).is_sparse_type ()) { SparseMatrix tmp = args (k).sparse_matrix_value (); diff -r 512d0d11ae39 -r 7171d19706df src/ov-base-sparse.h --- a/src/ov-base-sparse.h Mon Feb 20 22:05:32 2006 +0000 +++ b/src/ov-base-sparse.h Wed Feb 22 20:16:00 2006 +0000 @@ -126,6 +126,8 @@ bool is_numeric_type (void) const { return true; } + bool is_sparse_type (void) const { return true; } + bool is_defined (void) const { return true; } bool is_constant (void) const { return true; } diff -r 512d0d11ae39 -r 7171d19706df src/ov-base.h --- a/src/ov-base.h Mon Feb 20 22:05:32 2006 +0000 +++ b/src/ov-base.h Wed Feb 22 20:16:00 2006 +0000 @@ -163,6 +163,8 @@ bool is_numeric_type (void) const { return false; } + bool is_sparse_type (void) const { return false; } + bool valid_as_scalar_index (void) const { return false; } bool valid_as_zero_index (void) const { return false; } diff -r 512d0d11ae39 -r 7171d19706df src/ov.h --- a/src/ov.h Mon Feb 20 22:05:32 2006 +0000 +++ b/src/ov.h Wed Feb 22 20:16:00 2006 +0000 @@ -487,6 +487,9 @@ virtual bool is_numeric_type (void) const { return rep->is_numeric_type (); } + virtual bool is_sparse_type (void) const + { return rep->is_sparse_type (); } + virtual bool valid_as_scalar_index (void) const { return rep->valid_as_scalar_index (); } diff -r 512d0d11ae39 -r 7171d19706df src/pt-mat.cc --- a/src/pt-mat.cc Mon Feb 20 22:05:32 2006 +0000 +++ b/src/pt-mat.cc Wed Feb 22 20:16:00 2006 +0000 @@ -346,7 +346,7 @@ if (all_cmplx && ! (val.is_complex_type () || val.is_real_type ())) all_cmplx = false; - if (!any_sparse && val.class_name() == "sparse") + if (!any_sparse && val.is_sparse_type ()) any_sparse = true; return true;