Mercurial > octave-libtiff
annotate scripts/specfun/nchoosek.m @ 30204:1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
* nchoosek.m: Allow input of possible values to be a character array.
Ensure output is the same type as array of possible values. New
tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 Sep 2021 00:00:12 -0400 |
parents | 7854d5752dd2 |
children | 23a907b2dbd5 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27985
diff
changeset
|
3 ## Copyright (C) 2001-2021 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
5827 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
5827 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
5827 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
5827 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
5827 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
27 ## @deftypefn {} {@var{c} =} nchoosek (@var{n}, @var{k}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
28 ## @deftypefnx {} {@var{c} =} nchoosek (@var{set}, @var{k}) |
5827 | 29 ## |
19059 | 30 ## Compute the binomial coefficient of @var{n} or list all possible |
31 ## combinations of a @var{set} of items. | |
14090
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
32 ## |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
33 ## If @var{n} is a scalar then calculate the binomial coefficient |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
34 ## of @var{n} and @var{k} which is defined as |
5827 | 35 ## @tex |
36 ## $$ | |
37 ## {n \choose k} = {n (n-1) (n-2) \cdots (n-k+1) \over k!} | |
6754 | 38 ## = {n! \over k! (n-k)!} |
5827 | 39 ## $$ |
40 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8506
diff
changeset
|
41 ## @ifnottex |
5827 | 42 ## |
43 ## @example | |
44 ## @group | |
45 ## / \ | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
46 ## | n | n (n-1) (n-2) @dots{} (n-k+1) n! |
6754 | 47 ## | | = ------------------------- = --------- |
48 ## | k | k! k! (n-k)! | |
5827 | 49 ## \ / |
50 ## @end group | |
51 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10800
diff
changeset
|
52 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8506
diff
changeset
|
53 ## @end ifnottex |
14090
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
54 ## @noindent |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
55 ## This is the number of combinations of @var{n} items taken in groups of |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
56 ## size @var{k}. |
5827 | 57 ## |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14090
diff
changeset
|
58 ## If the first argument is a vector, @var{set}, then generate all |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14090
diff
changeset
|
59 ## combinations of the elements of @var{set}, taken @var{k} at a time, with |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14090
diff
changeset
|
60 ## one row per combination. The result @var{c} has @var{k} columns and |
14090
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
61 ## @w{@code{nchoosek (length (@var{set}), @var{k})}} rows. |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
62 ## |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
63 ## For example: |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
64 ## |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
65 ## How many ways can three items be grouped into pairs? |
5827 | 66 ## |
14090
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
67 ## @example |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
68 ## @group |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
69 ## nchoosek (3, 2) |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
70 ## @result{} 3 |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
71 ## @end group |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
72 ## @end example |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
73 ## |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
74 ## What are the possible pairs? |
8404
868149aac690
nchoosek checks, warning, corner cases and tests
Francesco Potortì <pot@gnu.org>
parents:
8391
diff
changeset
|
75 ## |
14090
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
76 ## @example |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
77 ## @group |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
78 ## nchoosek (1:3, 2) |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
79 ## @result{} 1 2 |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
80 ## 1 3 |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
81 ## 2 3 |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
82 ## @end group |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
83 ## @end example |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
84 ## |
19059 | 85 ## Programming Note: When calculating the binomial coefficient @code{nchoosek} |
86 ## works only for non-negative, integer arguments. Use @code{bincoeff} for | |
87 ## non-integer and negative scalar arguments, or for computing many binomial | |
88 ## coefficients at once with vector inputs for @var{n} or @var{k}. | |
14090
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
89 ## |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
90 ## @seealso{bincoeff, perms} |
5827 | 91 ## @end deftypefn |
92 | |
19059 | 93 function C = nchoosek (v, k) |
5827 | 94 |
8404
868149aac690
nchoosek checks, warning, corner cases and tests
Francesco Potortì <pot@gnu.org>
parents:
8391
diff
changeset
|
95 if (nargin != 2 |
19059 | 96 || ! (isreal (k) && isscalar (k)) |
30204
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
97 || ! ((isnumeric (v) || ischar (v)) && isvector (v))) |
6316 | 98 print_usage (); |
5827 | 99 endif |
19059 | 100 if (k < 0 || k != fix (k)) |
101 error ("nchoosek: K must be an integer >= 0"); | |
102 elseif (isscalar (v) && (iscomplex (v) || v < k || v < 0 || v != fix (v))) | |
103 error ("nchoosek: N must be a non-negative integer >= K"); | |
8404
868149aac690
nchoosek checks, warning, corner cases and tests
Francesco Potortì <pot@gnu.org>
parents:
8391
diff
changeset
|
104 endif |
5827 | 105 |
6318 | 106 n = length (v); |
107 | |
108 if (n == 1) | |
8506 | 109 ## Improve precision at next step. |
110 k = min (k, v-k); | |
19059 | 111 C = round (prod ((v-k+1:v)./(1:k))); |
112 if (C*2*k*eps >= 0.5) | |
113 warning ("nchoosek: possible loss of precision"); | |
8391
343f0fbca6eb
implement nchoosek without recursion
Jaroslav Hajek <highegg@gmail.com>
parents:
8361
diff
changeset
|
114 endif |
8404
868149aac690
nchoosek checks, warning, corner cases and tests
Francesco Potortì <pot@gnu.org>
parents:
8391
diff
changeset
|
115 elseif (k == 0) |
30204
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
116 if (is_sq_string (v)) |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
117 C = resize ('', 1, 0); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
118 elseif (is_dq_string (v)) |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
119 C = resize ("", 1, 0); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
120 else |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
121 C = zeros (1, 0, class (v)); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
122 endif |
6318 | 123 elseif (k == 1) |
19059 | 124 C = v(:); |
8404
868149aac690
nchoosek checks, warning, corner cases and tests
Francesco Potortì <pot@gnu.org>
parents:
8391
diff
changeset
|
125 elseif (k == n) |
19059 | 126 C = v(:).'; |
8391
343f0fbca6eb
implement nchoosek without recursion
Jaroslav Hajek <highegg@gmail.com>
parents:
8361
diff
changeset
|
127 elseif (k > n) |
30204
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
128 if (is_sq_string (v)) |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
129 C = resize ('', 0, k); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
130 elseif (is_dq_string (v)) |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
131 C = resize ("", 0, k); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
132 else |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
133 C = zeros (0, k, class (v)); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
134 endif |
10800 | 135 elseif (k == 2) |
136 ## Can do it without transpose. | |
137 x = repelems (v(1:n-1), [1:n-1; n-1:-1:1]).'; | |
138 y = cat (1, cellslices (v(:), 2:n, n*ones (1, n-1)){:}); | |
19059 | 139 C = [x, y]; |
10800 | 140 elseif (k < n) |
141 v = v(:).'; | |
19059 | 142 C = v(k:n); |
10800 | 143 l = 1:n-k+1; |
144 for j = 2:k | |
19059 | 145 c = columns (C); |
146 cA = cellslices (C, l, c*ones (1, n-k+1), 2); | |
10800 | 147 l = c-l+1; |
148 b = repelems (v(k-j+1:n-j+1), [1:n-k+1; l]); | |
19059 | 149 C = [b; cA{:}]; |
10800 | 150 l = cumsum (l); |
151 l = [1, 1 + l(1:n-k)]; | |
8391
343f0fbca6eb
implement nchoosek without recursion
Jaroslav Hajek <highegg@gmail.com>
parents:
8361
diff
changeset
|
152 endfor |
19059 | 153 C = C.'; |
6318 | 154 endif |
19059 | 155 |
8361
cf620941af1a
Set max_recursion_depth and use a subfunction in nchoosek
Francesco Potortì <pot@gnu.org>
parents:
7017
diff
changeset
|
156 endfunction |
6318 | 157 |
14090
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
158 |
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
159 %!assert (nchoosek (80,10), bincoeff (80,10)) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
160 %!assert (nchoosek (1:5,3), [1:3;1,2,4;1,2,5;1,3,4;1,3,5;1,4,5;2:4;2,3,5;2,4,5;3:5]) |
18795
1514f5337781
nchoosek.m: nchoosek(N,0) now returns [](1x0) when N is a vector (bug #41890).
Pedro Angelo <fonini@poli.ufrj.br>
parents:
17744
diff
changeset
|
161 %!assert (size (nchoosek (1:5,0)), [1 0]) |
14090
281ecc6fb431
nchoosek.m: Update documentation, fix input validation, add more %!tests
Rik <octave@nomad.inbox5.com>
parents:
14062
diff
changeset
|
162 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
163 ## Test input validation |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
27985
diff
changeset
|
164 %!error <Invalid call> nchoosek () |
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
27985
diff
changeset
|
165 %!error <Invalid call> nchoosek (1) |
19059 | 166 |
167 %!error nchoosek (100, 2i) | |
168 %!error nchoosek (100, [2 3]) | |
169 %!error nchoosek (100*ones (2, 2), 45) | |
170 %!error <K must be an integer .= 0> nchoosek (100, -45) | |
171 %!error <K must be an integer .= 0> nchoosek (100, 45.5) | |
172 %!error <N must be a non-negative integer .= K> nchoosek (100i, 2) | |
173 %!error <N must be a non-negative integer .= K> nchoosek (100, 145) | |
174 %!error <N must be a non-negative integer .= K> nchoosek (-100, 45) | |
175 %!error <N must be a non-negative integer .= K> nchoosek (100.5, 45) | |
176 %!warning <possible loss of precision> nchoosek (100, 45); | |
30204
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
177 |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
178 %!assert (nchoosek ('a':'b', 2), 'ab') |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
179 %!assert (nchoosek ("a":"b", 2), "ab") |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
180 |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
181 %!test |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
182 %! x = nchoosek ('a':'b', 3); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
183 %! assert (size (x), [0, 3]); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
184 %! assert (is_sq_string (x)); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
185 %! x = nchoosek ('a':'b', 0); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
186 %! assert (size (x), [1, 0]); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
187 %! assert (is_sq_string (x)); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
188 %! |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
189 %! x = nchoosek ("a":"b", 3); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
190 %! assert (size (x), [0, 3]); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
191 %! assert (is_dq_string (x)); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
192 %! x = nchoosek ("a":"b", 0); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
193 %! assert (size (x), [1, 0]); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
194 %! assert (is_dq_string (x)); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
195 %! |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
196 %! x = nchoosek (uint8(1):uint8(2), 3); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
197 %! assert (size (x), [0, 3]); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
198 %! assert (class (x), "uint8"); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
199 %! x = nchoosek (uint8(1):uint8(2), 0); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
200 %! assert (size (x), [1, 0]); |
1cd077e9f127
allow nchoosek to accept character vectors (bug #61199)
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
201 %! assert (class (x), "uint8"); |