Mercurial > hg > octave-nkf
diff liboctave/array/CSparse.cc @ 17682:93e272018df2
Correct dimesion of return values form sparse min/max function with empty
matrices (bug #40295)
* dSparse.cc (SparseMatrix SparseMatrix::max (Array<octave_idx-type>&, int)) :
Specialize return values if called with an empty matrix
(SparseMatrix SparseMatrix::min (Array<octave_idx-type>&, int)) : ditto
* CSparse.cc (SparseComplexMatrix SparseComplexMatrix::max (
Array<octave_idx-type>&, int)) : Specialize return values if called with
an empty matrix
(SparseComplexMatrix SparseComplexMatrix::min (Array<octave_idx-type>&,
int)) : ditto
author | David Bateman <dbateman@free.fr> |
---|---|
date | Fri, 18 Oct 2013 01:36:31 +0200 |
parents | c81debf315e0 |
children | 8a54a481ecb5 |
line wrap: on
line diff
--- a/liboctave/array/CSparse.cc +++ b/liboctave/array/CSparse.cc @@ -261,15 +261,23 @@ octave_idx_type nr = dv(0); octave_idx_type nc = dv(1); - if (nr == 0 || nc == 0 || dim >= dv.length ()) - return result; + + if (dim >= dv.length ()) + { + idx_arg.resize (dim_vector (nr, nc), 0); + return *this; + } if (dim < 0) dim = dv.first_non_singleton (); if (dim == 0) { - idx_arg.clear (1, nc); + idx_arg.resize (dim_vector (nr == 0 ? 0 : 1, nc), 0); + + if (nr == 0 || nc == 0 || dim >= dv.length ()) + return SparseComplexMatrix (nr == 0 ? 0 : 1, nc); + octave_idx_type nel = 0; for (octave_idx_type j = 0; j < nc; j++) { @@ -329,6 +337,12 @@ } else { + idx_arg.resize (dim_vector (nr, nc == 0 ? 0 : 1), 0); + + if (nr == 0 || nc == 0 || dim >= dv.length ()) + return SparseComplexMatrix (nr, nc == 0 ? 0 : 1); + + idx_arg.resize (dim_vector (nr, 1), 0); for (octave_idx_type i = cidx (0); i < cidx (1); i++) @@ -415,15 +429,22 @@ octave_idx_type nr = dv(0); octave_idx_type nc = dv(1); - if (nr == 0 || nc == 0 || dim >= dv.length ()) - return result; + if (dim >= dv.length ()) + { + idx_arg.resize (dim_vector (nr, nc), 0); + return *this; + } if (dim < 0) dim = dv.first_non_singleton (); if (dim == 0) { - idx_arg.clear (1, nc); + idx_arg.resize (dim_vector (nr == 0 ? 0 : 1, nc), 0); + + if (nr == 0 || nc == 0 || dim >= dv.length ()) + return SparseComplexMatrix (nr == 0 ? 0 : 1, nc); + octave_idx_type nel = 0; for (octave_idx_type j = 0; j < nc; j++) { @@ -483,7 +504,10 @@ } else { - idx_arg.resize (dim_vector (nr, 1), 0); + idx_arg.resize (dim_vector (nr, nc == 0 ? 0 : 1), 0); + + if (nr == 0 || nc == 0 || dim >= dv.length ()) + return SparseComplexMatrix (nr, nc == 0 ? 0 : 1); for (octave_idx_type i = cidx (0); i < cidx (1); i++) idx_arg.elem (ridx (i)) = -1;