Mercurial > hg > octave-lyh
comparison liboctave/Array.cc @ 11242:0090bb47d0b5
simplify special case for concatenation of empty matrices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 12 Nov 2010 13:19:24 -0500 |
parents | 80e01d79cf80 |
children | c3ad80f4ce36 |
comparison
equal
deleted
inserted
replaced
11241:80e01d79cf80 | 11242:0090bb47d0b5 |
---|---|
2535 else if (n == 0) | 2535 else if (n == 0) |
2536 return Array<T> (); | 2536 return Array<T> (); |
2537 | 2537 |
2538 // Special case: | 2538 // Special case: |
2539 // | 2539 // |
2540 // cat (dim, [], ..., [], A) | 2540 // cat (dim, [], ..., [], A, ...) |
2541 // | 2541 // |
2542 // with dim > 2, A not 0x0, and at least three arguments to | 2542 // with dim > 2, A not 0x0, and at least three arguments to |
2543 // concatenate results in A. Note that this check must be performed | 2543 // concatenate is equivalent to |
2544 // here because for full-on braindead Matlab compatibility, we need | 2544 // |
2545 // the above to succeed, but things like | 2545 // cat (dim, A, ...) |
2546 // | |
2547 // Note that this check must be performed here because for full-on | |
2548 // braindead Matlab compatibility, we need to have things like | |
2549 // | |
2550 // cat (3, [], [], A) | |
2551 // | |
2552 // succeed, but to have things like | |
2546 // | 2553 // |
2547 // cat (3, cat (3, [], []), A) | 2554 // cat (3, cat (3, [], []), A) |
2548 // cat (3, zeros (0, 0, 2), A) | 2555 // cat (3, zeros (0, 0, 2), A) |
2549 // | 2556 // |
2550 // to fail. See also bug report #31615. | 2557 // fail. See also bug report #31615. |
2558 | |
2559 octave_idx_type istart = 0; | |
2551 | 2560 |
2552 if (n > 2 && dim > 1) | 2561 if (n > 2 && dim > 1) |
2553 { | 2562 { |
2554 dim_vector dv = array_list[n-1].dims (); | 2563 for (octave_idx_type i = 0; i < n; i++) |
2555 | 2564 { |
2556 if (! dv.zero_by_zero ()) | 2565 dim_vector dv = array_list[i].dims (); |
2557 { | 2566 |
2558 bool all_but_last_are_zero_by_zero = true; | 2567 if (dv.zero_by_zero ()) |
2559 | 2568 istart++; |
2560 if (all_but_last_are_zero_by_zero) | 2569 else |
2561 { | 2570 break; |
2562 for (octave_idx_type i = 0; i < n-1; i++) | 2571 } |
2563 { | 2572 |
2564 dim_vector dv = array_list[i].dims (); | 2573 // Don't skip any initial aguments if they are all empty. |
2565 | 2574 if (istart >= n) |
2566 if (! dv.zero_by_zero ()) | 2575 istart = 0; |
2567 { | 2576 } |
2568 all_but_last_are_zero_by_zero = false; | 2577 |
2569 break; | 2578 dim_vector dv = array_list[istart++].dims (); |
2570 } | 2579 |
2571 } | 2580 for (octave_idx_type i = istart; i < n; i++) |
2572 } | |
2573 | |
2574 if (all_but_last_are_zero_by_zero) | |
2575 return array_list[n-1]; | |
2576 } | |
2577 } | |
2578 | |
2579 | |
2580 dim_vector dv = array_list[0].dims (); | |
2581 | |
2582 for (octave_idx_type i = 1; i < n; i++) | |
2583 if (! (dv.*concat_rule) (array_list[i].dims (), dim)) | 2581 if (! (dv.*concat_rule) (array_list[i].dims (), dim)) |
2584 (*current_liboctave_error_handler) | 2582 (*current_liboctave_error_handler) |
2585 ("cat: dimension mismatch"); | 2583 ("cat: dimension mismatch"); |
2586 | 2584 |
2587 Array<T> retval (dv); | 2585 Array<T> retval (dv); |