Mercurial > hg > octave-nkf
comparison libinterp/corefcn/max.cc @ 17403:db8b90a56298
doc: Reword docstrings for cummax, cummin.
* libinterp/corefcn/max.cc: Reword docstrings for cummax, cummin.
Add %!tests for both functions.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 10 Sep 2013 10:57:52 -0700 |
parents | 7ce21619a4b9 |
children | d63878346099 |
comparison
equal
deleted
inserted
replaced
17402:3cf4250cc67e | 17403:db8b90a56298 |
---|---|
661 DEFUN (cummin, args, nargout, | 661 DEFUN (cummin, args, nargout, |
662 "-*- texinfo -*-\n\ | 662 "-*- texinfo -*-\n\ |
663 @deftypefn {Built-in Function} {} cummin (@var{x})\n\ | 663 @deftypefn {Built-in Function} {} cummin (@var{x})\n\ |
664 @deftypefnx {Built-in Function} {} cummin (@var{x}, @var{dim})\n\ | 664 @deftypefnx {Built-in Function} {} cummin (@var{x}, @var{dim})\n\ |
665 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummin (@var{x})\n\ | 665 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummin (@var{x})\n\ |
666 Return the cumulative minimum values along dimension @var{dim}. If @var{dim}\n\ | 666 Return the cumulative minimum values along dimension @var{dim}.\n\ |
667 is unspecified it defaults to column-wise operation. For example:\n\ | 667 \n\ |
668 If @var{dim} is unspecified it defaults to column-wise operation. For\n\ | |
669 example:\n\ | |
668 \n\ | 670 \n\ |
669 @example\n\ | 671 @example\n\ |
670 @group\n\ | 672 @group\n\ |
671 cummin ([5 4 6 2 3 1])\n\ | 673 cummin ([5 4 6 2 3 1])\n\ |
672 @result{} 5 4 4 2 2 1\n\ | 674 @result{} 5 4 4 2 2 1\n\ |
673 @end group\n\ | 675 @end group\n\ |
674 @end example\n\ | 676 @end example\n\ |
675 \n\ | 677 \n\ |
676 \n\ | 678 If called with two output arguments the index of the minimum value is also\n\ |
677 The call\n\ | 679 returned.\n\ |
678 \n\ | |
679 @example\n\ | |
680 [w, iw] = cummin (x)\n\ | |
681 @end example\n\ | |
682 \n\ | |
683 @noindent\n\ | |
684 with @code{x} a vector, is equivalent to the following code:\n\ | |
685 \n\ | 680 \n\ |
686 @example\n\ | 681 @example\n\ |
687 @group\n\ | 682 @group\n\ |
688 w = iw = zeros (size (x));\n\ | 683 [w, iw] = cummin ([5 4 6 2 3 1])\n\ |
689 for i = 1:length (x)\n\ | 684 @result{}\n\ |
690 [w(i), iw(i)] = max (x(1:i));\n\ | 685 w = 5 4 4 2 2 1\n\ |
691 endfor\n\ | 686 iw = 1 2 2 4 4 6\n\ |
692 @end group\n\ | 687 @end group\n\ |
693 @end example\n\ | 688 @end example\n\ |
694 \n\ | 689 \n\ |
695 @noindent\n\ | |
696 but computed in a much faster manner.\n\ | |
697 @seealso{cummax, min, max}\n\ | 690 @seealso{cummax, min, max}\n\ |
698 @end deftypefn") | 691 @end deftypefn") |
699 { | 692 { |
700 return do_cumminmax_body (args, nargout, true); | 693 return do_cumminmax_body (args, nargout, true); |
701 } | 694 } |
695 | |
696 /* | |
697 %!assert (cummin ([1, 4, 2, 3]), [1 1 1 1]) | |
698 %!assert (cummin ([1; -10; 5; -2]), [1; -10; -10; -10]) | |
699 %!assert (cummin ([4, i; -2, 2]), [4, i; -2, i]) | |
700 | |
701 %!test | |
702 %! x = reshape (1:8, [2,2,2]); | |
703 %! assert (cummin (x, 1), reshape ([1 1 3 3 5 5 7 7], [2,2,2])); | |
704 %! assert (cummin (x, 2), reshape ([1 2 1 2 5 6 5 6], [2,2,2])); | |
705 %! [w, iw] = cummin (x, 3); | |
706 %! assert (ndims (w), 3); | |
707 %! assert (w, repmat ([1 3; 2 4], [1 1 2])); | |
708 %! assert (ndims (iw), 3); | |
709 %! assert (iw, ones (2,2,2)); | |
710 | |
711 %!error cummin () | |
712 %!error cummin (1, 2, 3) | |
713 */ | |
702 | 714 |
703 DEFUN (cummax, args, nargout, | 715 DEFUN (cummax, args, nargout, |
704 "-*- texinfo -*-\n\ | 716 "-*- texinfo -*-\n\ |
705 @deftypefn {Built-in Function} {} cummax (@var{x})\n\ | 717 @deftypefn {Built-in Function} {} cummax (@var{x})\n\ |
706 @deftypefnx {Built-in Function} {} cummax (@var{x}, @var{dim})\n\ | 718 @deftypefnx {Built-in Function} {} cummax (@var{x}, @var{dim})\n\ |
707 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummax (@var{x})\n\ | 719 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummax (@dots{})\n\ |
708 Return the cumulative maximum values along dimension @var{dim}. If @var{dim}\n\ | 720 Return the cumulative maximum values along dimension @var{dim}.\n\ |
709 is unspecified it defaults to column-wise operation. For example:\n\ | 721 \n\ |
722 If @var{dim} is unspecified it defaults to column-wise operation. For\n\ | |
723 example:\n\ | |
710 \n\ | 724 \n\ |
711 @example\n\ | 725 @example\n\ |
712 @group\n\ | 726 @group\n\ |
713 cummax ([1 3 2 6 4 5])\n\ | 727 cummax ([1 3 2 6 4 5])\n\ |
714 @result{} 1 3 3 6 6 6\n\ | 728 @result{} 1 3 3 6 6 6\n\ |
715 @end group\n\ | 729 @end group\n\ |
716 @end example\n\ | 730 @end example\n\ |
717 \n\ | 731 \n\ |
718 The call\n\ | 732 If called with two output arguments the index of the maximum value is also\n\ |
719 \n\ | 733 returned.\n\ |
720 @example\n\ | |
721 [w, iw] = cummax (x, dim)\n\ | |
722 @end example\n\ | |
723 \n\ | |
724 @noindent\n\ | |
725 with @code{x} a vector, is equivalent to the following code:\n\ | |
726 \n\ | 734 \n\ |
727 @example\n\ | 735 @example\n\ |
728 @group\n\ | 736 @group\n\ |
729 w = iw = zeros (size (x));\n\ | 737 [w, iw] = cummax ([1 3 2 6 4 5])\n\ |
730 for i = 1:length (x)\n\ | 738 @result{}\n\ |
731 [w(i), iw(i)] = max (x(1:i));\n\ | 739 w = 1 3 3 6 6 6\n\ |
732 endfor\n\ | 740 iw = 1 2 2 4 4 4\n\ |
733 @end group\n\ | 741 @end group\n\ |
734 @end example\n\ | 742 @end example\n\ |
735 \n\ | 743 \n\ |
736 @noindent\n\ | |
737 but computed in a much faster manner.\n\ | |
738 @seealso{cummin, max, min}\n\ | 744 @seealso{cummin, max, min}\n\ |
739 @end deftypefn") | 745 @end deftypefn") |
740 { | 746 { |
741 return do_cumminmax_body (args, nargout, false); | 747 return do_cumminmax_body (args, nargout, false); |
742 } | 748 } |
749 | |
750 /* | |
751 %!assert (cummax ([1, 4, 2, 3]), [1 4 4 4]) | |
752 %!assert (cummax ([1; -10; 5; -2]), [1; 1; 5; 5]) | |
753 %!assert (cummax ([4, i 4.9, -2, 2, 3+4i]), [4, 4, 4.9, 4.9, 4.9, 3+4i]) | |
754 | |
755 %!test | |
756 %! x = reshape (8:-1:1, [2,2,2]); | |
757 %! assert (cummax (x, 1), reshape ([8 8 6 6 4 4 2 2], [2,2,2])); | |
758 %! assert (cummax (x, 2), reshape ([8 7 8 7 4 3 4 3], [2,2,2])); | |
759 %! [w, iw] = cummax (x, 3); | |
760 %! assert (ndims (w), 3); | |
761 %! assert (w, repmat ([8 6; 7 5], [1 1 2])); | |
762 %! assert (ndims (iw), 3); | |
763 %! assert (iw, ones (2,2,2)); | |
764 | |
765 %!error cummax () | |
766 %!error cummax (1, 2, 3) | |
767 */ | |
768 |