Mercurial > octave
comparison liboctave/array/dSparse.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 | 8031fc73f291 |
comparison
equal
deleted
inserted
replaced
17681:f6fded839513 | 17682:93e272018df2 |
---|---|
277 SparseMatrix result; | 277 SparseMatrix result; |
278 dim_vector dv = dims (); | 278 dim_vector dv = dims (); |
279 octave_idx_type nr = dv(0); | 279 octave_idx_type nr = dv(0); |
280 octave_idx_type nc = dv(1); | 280 octave_idx_type nc = dv(1); |
281 | 281 |
282 if (nr == 0 || nc == 0 || dim >= dv.length ()) | 282 if (dim >= dv.length ()) |
283 return result; | 283 { |
284 idx_arg.resize (dim_vector (nr, nc), 0); | |
285 return *this; | |
286 } | |
284 | 287 |
285 if (dim < 0) | 288 if (dim < 0) |
286 dim = dv.first_non_singleton (); | 289 dim = dv.first_non_singleton (); |
287 | 290 |
288 if (dim == 0) | 291 if (dim == 0) |
289 { | 292 { |
290 idx_arg.clear (1, nc); | 293 idx_arg.resize (dim_vector (nr == 0 ? 0 : 1, nc), 0); |
294 | |
295 if (nr == 0 || nc == 0 || dim >= dv.length ()) | |
296 return SparseMatrix (nr == 0 ? 0 : 1, nc); | |
297 | |
291 octave_idx_type nel = 0; | 298 octave_idx_type nel = 0; |
292 for (octave_idx_type j = 0; j < nc; j++) | 299 for (octave_idx_type j = 0; j < nc; j++) |
293 { | 300 { |
294 double tmp_max = octave_NaN; | 301 double tmp_max = octave_NaN; |
295 octave_idx_type idx_j = 0; | 302 octave_idx_type idx_j = 0; |
339 | 346 |
340 } | 347 } |
341 } | 348 } |
342 else | 349 else |
343 { | 350 { |
344 idx_arg.resize (dim_vector (nr, 1), 0); | 351 idx_arg.resize (dim_vector (nr, nc == 0 ? 0 : 1), 0); |
352 | |
353 if (nr == 0 || nc == 0 || dim >= dv.length ()) | |
354 return SparseMatrix (nr, nc == 0 ? 0 : 1); | |
345 | 355 |
346 for (octave_idx_type i = cidx (0); i < cidx (1); i++) | 356 for (octave_idx_type i = cidx (0); i < cidx (1); i++) |
347 idx_arg.elem (ridx (i)) = -1; | 357 idx_arg.elem (ridx (i)) = -1; |
348 | 358 |
349 for (octave_idx_type j = 0; j < nc; j++) | 359 for (octave_idx_type j = 0; j < nc; j++) |
425 SparseMatrix result; | 435 SparseMatrix result; |
426 dim_vector dv = dims (); | 436 dim_vector dv = dims (); |
427 octave_idx_type nr = dv(0); | 437 octave_idx_type nr = dv(0); |
428 octave_idx_type nc = dv(1); | 438 octave_idx_type nc = dv(1); |
429 | 439 |
430 if (nr == 0 || nc == 0 || dim >= dv.length ()) | 440 if (dim >= dv.length ()) |
431 return result; | 441 { |
442 idx_arg.resize (dim_vector (nr, nc), 0); | |
443 return *this; | |
444 } | |
432 | 445 |
433 if (dim < 0) | 446 if (dim < 0) |
434 dim = dv.first_non_singleton (); | 447 dim = dv.first_non_singleton (); |
435 | 448 |
436 if (dim == 0) | 449 if (dim == 0) |
437 { | 450 { |
438 idx_arg.clear (1, nc); | 451 idx_arg.resize (dim_vector (nr == 0 ? 0 : 1, nc), 0); |
452 | |
453 if (nr == 0 || nc == 0 || dim >= dv.length ()) | |
454 return SparseMatrix (nr == 0 ? 0 : 1, nc); | |
455 | |
439 octave_idx_type nel = 0; | 456 octave_idx_type nel = 0; |
440 for (octave_idx_type j = 0; j < nc; j++) | 457 for (octave_idx_type j = 0; j < nc; j++) |
441 { | 458 { |
442 double tmp_min = octave_NaN; | 459 double tmp_min = octave_NaN; |
443 octave_idx_type idx_j = 0; | 460 octave_idx_type idx_j = 0; |
487 | 504 |
488 } | 505 } |
489 } | 506 } |
490 else | 507 else |
491 { | 508 { |
492 idx_arg.resize (dim_vector (nr, 1), 0); | 509 idx_arg.resize (dim_vector (nr, nc == 0 ? 0 : 1), 0); |
510 | |
511 if (nr == 0 || nc == 0 || dim >= dv.length ()) | |
512 return SparseMatrix (nr, nc == 0 ? 0 : 1); | |
493 | 513 |
494 for (octave_idx_type i = cidx (0); i < cidx (1); i++) | 514 for (octave_idx_type i = cidx (0); i < cidx (1); i++) |
495 idx_arg.elem (ridx (i)) = -1; | 515 idx_arg.elem (ridx (i)) = -1; |
496 | 516 |
497 for (octave_idx_type j = 0; j < nc; j++) | 517 for (octave_idx_type j = 0; j < nc; j++) |