Mercurial > hg > octave-nkf
comparison 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 |
comparison
equal
deleted
inserted
replaced
17681:f6fded839513 | 17682:93e272018df2 |
---|---|
259 SparseComplexMatrix result; | 259 SparseComplexMatrix result; |
260 dim_vector dv = dims (); | 260 dim_vector dv = dims (); |
261 octave_idx_type nr = dv(0); | 261 octave_idx_type nr = dv(0); |
262 octave_idx_type nc = dv(1); | 262 octave_idx_type nc = dv(1); |
263 | 263 |
264 if (nr == 0 || nc == 0 || dim >= dv.length ()) | 264 |
265 return result; | 265 if (dim >= dv.length ()) |
266 { | |
267 idx_arg.resize (dim_vector (nr, nc), 0); | |
268 return *this; | |
269 } | |
266 | 270 |
267 if (dim < 0) | 271 if (dim < 0) |
268 dim = dv.first_non_singleton (); | 272 dim = dv.first_non_singleton (); |
269 | 273 |
270 if (dim == 0) | 274 if (dim == 0) |
271 { | 275 { |
272 idx_arg.clear (1, nc); | 276 idx_arg.resize (dim_vector (nr == 0 ? 0 : 1, nc), 0); |
277 | |
278 if (nr == 0 || nc == 0 || dim >= dv.length ()) | |
279 return SparseComplexMatrix (nr == 0 ? 0 : 1, nc); | |
280 | |
273 octave_idx_type nel = 0; | 281 octave_idx_type nel = 0; |
274 for (octave_idx_type j = 0; j < nc; j++) | 282 for (octave_idx_type j = 0; j < nc; j++) |
275 { | 283 { |
276 Complex tmp_max; | 284 Complex tmp_max; |
277 double abs_max = octave_NaN; | 285 double abs_max = octave_NaN; |
327 result.xcidx (j+1) = ii; | 335 result.xcidx (j+1) = ii; |
328 } | 336 } |
329 } | 337 } |
330 else | 338 else |
331 { | 339 { |
340 idx_arg.resize (dim_vector (nr, nc == 0 ? 0 : 1), 0); | |
341 | |
342 if (nr == 0 || nc == 0 || dim >= dv.length ()) | |
343 return SparseComplexMatrix (nr, nc == 0 ? 0 : 1); | |
344 | |
345 | |
332 idx_arg.resize (dim_vector (nr, 1), 0); | 346 idx_arg.resize (dim_vector (nr, 1), 0); |
333 | 347 |
334 for (octave_idx_type i = cidx (0); i < cidx (1); i++) | 348 for (octave_idx_type i = cidx (0); i < cidx (1); i++) |
335 idx_arg.elem (ridx (i)) = -1; | 349 idx_arg.elem (ridx (i)) = -1; |
336 | 350 |
413 SparseComplexMatrix result; | 427 SparseComplexMatrix result; |
414 dim_vector dv = dims (); | 428 dim_vector dv = dims (); |
415 octave_idx_type nr = dv(0); | 429 octave_idx_type nr = dv(0); |
416 octave_idx_type nc = dv(1); | 430 octave_idx_type nc = dv(1); |
417 | 431 |
418 if (nr == 0 || nc == 0 || dim >= dv.length ()) | 432 if (dim >= dv.length ()) |
419 return result; | 433 { |
434 idx_arg.resize (dim_vector (nr, nc), 0); | |
435 return *this; | |
436 } | |
420 | 437 |
421 if (dim < 0) | 438 if (dim < 0) |
422 dim = dv.first_non_singleton (); | 439 dim = dv.first_non_singleton (); |
423 | 440 |
424 if (dim == 0) | 441 if (dim == 0) |
425 { | 442 { |
426 idx_arg.clear (1, nc); | 443 idx_arg.resize (dim_vector (nr == 0 ? 0 : 1, nc), 0); |
444 | |
445 if (nr == 0 || nc == 0 || dim >= dv.length ()) | |
446 return SparseComplexMatrix (nr == 0 ? 0 : 1, nc); | |
447 | |
427 octave_idx_type nel = 0; | 448 octave_idx_type nel = 0; |
428 for (octave_idx_type j = 0; j < nc; j++) | 449 for (octave_idx_type j = 0; j < nc; j++) |
429 { | 450 { |
430 Complex tmp_min; | 451 Complex tmp_min; |
431 double abs_min = octave_NaN; | 452 double abs_min = octave_NaN; |
481 result.xcidx (j+1) = ii; | 502 result.xcidx (j+1) = ii; |
482 } | 503 } |
483 } | 504 } |
484 else | 505 else |
485 { | 506 { |
486 idx_arg.resize (dim_vector (nr, 1), 0); | 507 idx_arg.resize (dim_vector (nr, nc == 0 ? 0 : 1), 0); |
508 | |
509 if (nr == 0 || nc == 0 || dim >= dv.length ()) | |
510 return SparseComplexMatrix (nr, nc == 0 ? 0 : 1); | |
487 | 511 |
488 for (octave_idx_type i = cidx (0); i < cidx (1); i++) | 512 for (octave_idx_type i = cidx (0); i < cidx (1); i++) |
489 idx_arg.elem (ridx (i)) = -1; | 513 idx_arg.elem (ridx (i)) = -1; |
490 | 514 |
491 for (octave_idx_type j = 0; j < nc; j++) | 515 for (octave_idx_type j = 0; j < nc; j++) |