comparison src/DLD-FUNCTIONS/cellfun.cc @ 9988:76cf4aec34e9

allow functions returning no value in cellfun
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 15 Dec 2009 13:07:05 +0100
parents 78ac37d73557
children f349847c4541
comparison
equal deleted inserted replaced
9987:bb30843c4929 9988:76cf4aec34e9
270 @seealso{isempty, islogical, isreal, length, ndims, numel, size}\n\ 270 @seealso{isempty, islogical, isreal, length, ndims, numel, size}\n\
271 @end deftypefn") 271 @end deftypefn")
272 { 272 {
273 octave_value_list retval; 273 octave_value_list retval;
274 int nargin = args.length (); 274 int nargin = args.length ();
275 nargout = (nargout < 1 ? 1 : nargout); 275 int nargout1 = (nargout < 1 ? 1 : nargout);
276 276
277 if (nargin < 2) 277 if (nargin < 2)
278 { 278 {
279 error ("cellfun: you must supply at least 2 arguments"); 279 error ("cellfun: you must supply at least 2 arguments");
280 print_usage (); 280 print_usage ();
507 if (error_handler.is_defined ()) 507 if (error_handler.is_defined ())
508 buffer_error_messages++; 508 buffer_error_messages++;
509 509
510 if (uniform_output) 510 if (uniform_output)
511 { 511 {
512 OCTAVE_LOCAL_BUFFER (std::auto_ptr<scalar_col_helper>, retptr, nargout); 512 OCTAVE_LOCAL_BUFFER (std::auto_ptr<scalar_col_helper>, retptr, nargout1);
513 513
514 for (octave_idx_type count = 0; count < k ; count++) 514 for (octave_idx_type count = 0; count < k ; count++)
515 { 515 {
516 for (int j = 0; j < nargin; j++) 516 for (int j = 0; j < nargin; j++)
517 { 517 {
539 } 539 }
540 540
541 if (error_state) 541 if (error_state)
542 goto cellfun_err; 542 goto cellfun_err;
543 543
544 if (tmp.length() < nargout) 544 if (tmp.length () < nargout1)
545 { 545 {
546 error ("cellfun: too many output arguments"); 546 if (tmp.length () < nargout)
547 goto cellfun_err; 547 {
548 error ("cellfun: too many output arguments");
549 goto cellfun_err;
550 }
551 else
552 nargout1 = 0;
548 } 553 }
549 554
550 if (count == 0) 555 if (count == 0)
551 { 556 {
552 for (int j = 0; j < nargout; j++) 557 for (int j = 0; j < nargout1; j++)
553 { 558 {
554 octave_value val = tmp(j); 559 octave_value val = tmp(j);
555 560
556 if (val.numel () == 1) 561 if (val.numel () == 1)
557 retptr[j].reset (make_col_helper (val, fdims)); 562 retptr[j].reset (make_col_helper (val, fdims));
562 } 567 }
563 } 568 }
564 } 569 }
565 else 570 else
566 { 571 {
567 for (int j = 0; j < nargout; j++) 572 for (int j = 0; j < nargout1; j++)
568 { 573 {
569 octave_value val = tmp(j); 574 octave_value val = tmp(j);
570 575
571 if (! retptr[j]->collect (count, val)) 576 if (! retptr[j]->collect (count, val))
572 { 577 {
581 586
582 if (error_state) 587 if (error_state)
583 break; 588 break;
584 } 589 }
585 590
586 retval.resize (nargout); 591 retval.resize (nargout1);
587 for (int j = 0; j < nargout; j++) 592 for (int j = 0; j < nargout1; j++)
588 { 593 {
589 if (retptr[j].get ()) 594 if (retptr[j].get ())
590 retval(j) = retptr[j]->result (); 595 retval(j) = retptr[j]->result ();
591 else 596 else
592 retval(j) = Matrix (); 597 retval(j) = Matrix ();
593 } 598 }
594 } 599 }
595 else 600 else
596 { 601 {
597 OCTAVE_LOCAL_BUFFER (Cell, results, nargout); 602 OCTAVE_LOCAL_BUFFER (Cell, results, nargout1);
598 for (int j = 0; j < nargout; j++) 603 for (int j = 0; j < nargout1; j++)
599 results[j].resize (fdims); 604 results[j].resize (fdims);
600 605
601 for (octave_idx_type count = 0; count < k ; count++) 606 for (octave_idx_type count = 0; count < k ; count++)
602 { 607 {
603 for (int j = 0; j < nargin; j++) 608 for (int j = 0; j < nargin; j++)
626 } 631 }
627 632
628 if (error_state) 633 if (error_state)
629 goto cellfun_err; 634 goto cellfun_err;
630 635
631 if (tmp.length() < nargout) 636 if (tmp.length () < nargout1)
632 { 637 {
633 error ("cellfun: too many output arguments"); 638 if (tmp.length () < nargout)
634 goto cellfun_err; 639 {
635 } 640 error ("cellfun: too many output arguments");
636 641 goto cellfun_err;
637 642 }
638 for (int j = 0; j < nargout; j++) 643 else
644 nargout1 = 0;
645 }
646
647
648 for (int j = 0; j < nargout1; j++)
639 results[j](count) = tmp(j); 649 results[j](count) = tmp(j);
640 } 650 }
641 651
642 retval.resize(nargout); 652 retval.resize(nargout1);
643 for (int j = 0; j < nargout; j++) 653 for (int j = 0; j < nargout1; j++)
644 retval(j) = results[j]; 654 retval(j) = results[j];
645 } 655 }
646 656
647 cellfun_err: 657 cellfun_err:
648 if (error_state) 658 if (error_state)