Mercurial > octave-antonio
comparison scripts/statistics/distributions/nbinrnd.m @ 19833:9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Try to trim long lines to < 80 chars.
Use '##' for single line comments.
Use '(...)' around tests for if/elseif/switch/while.
Abut cell indexing operator '{' next to variable.
Abut array indexing operator '(' next to variable.
Use space between negation operator '!' and following expression.
Use two newlines between endfunction and start of %!test or %!demo code.
Remove unnecessary parens grouping between short-circuit operators.
Remove stray extra spaces (typos) between variables and assignment operators.
Remove stray extra spaces from ends of lines.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 23 Feb 2015 14:54:39 -0800 |
parents | 4197fc428c7d |
children |
comparison
equal
deleted
inserted
replaced
19832:a1acca0c2216 | 19833:9fc020886ae9 |
---|---|
42 | 42 |
43 if (nargin < 2) | 43 if (nargin < 2) |
44 print_usage (); | 44 print_usage (); |
45 endif | 45 endif |
46 | 46 |
47 if (!isscalar (n) || !isscalar (p)) | 47 if (! isscalar (n) || ! isscalar (p)) |
48 [retval, n, p] = common_size (n, p); | 48 [retval, n, p] = common_size (n, p); |
49 if (retval > 0) | 49 if (retval > 0) |
50 error ("nbinrnd: N and P must be of common size or scalars"); | 50 error ("nbinrnd: N and P must be of common size or scalars"); |
51 endif | 51 endif |
52 endif | 52 endif |
64 sz = varargin{1}; | 64 sz = varargin{1}; |
65 else | 65 else |
66 error ("nbinrnd: dimension vector must be row vector of non-negative integers"); | 66 error ("nbinrnd: dimension vector must be row vector of non-negative integers"); |
67 endif | 67 endif |
68 elseif (nargin > 3) | 68 elseif (nargin > 3) |
69 if (any (cellfun (@(x) (!isscalar (x) || x < 0), varargin))) | 69 if (any (cellfun (@(x) (! isscalar (x) || x < 0), varargin))) |
70 error ("nbinrnd: dimensions must be non-negative integers"); | 70 error ("nbinrnd: dimensions must be non-negative integers"); |
71 endif | 71 endif |
72 sz = [varargin{:}]; | 72 sz = [varargin{:}]; |
73 endif | 73 endif |
74 | 74 |
75 if (!isscalar (n) && !isequal (size (n), sz)) | 75 if (! isscalar (n) && ! isequal (size (n), sz)) |
76 error ("nbinrnd: N and P must be scalar or of size SZ"); | 76 error ("nbinrnd: N and P must be scalar or of size SZ"); |
77 endif | 77 endif |
78 | 78 |
79 if (isa (n, "single") || isa (p, "single")) | 79 if (isa (n, "single") || isa (p, "single")) |
80 cls = "single"; | 80 cls = "single"; |
110 %!assert (size (nbinrnd (2, 1/2*ones (2,2))), [2, 2]) | 110 %!assert (size (nbinrnd (2, 1/2*ones (2,2))), [2, 2]) |
111 %!assert (size (nbinrnd (2, 1/2, 3)), [3, 3]) | 111 %!assert (size (nbinrnd (2, 1/2, 3)), [3, 3]) |
112 %!assert (size (nbinrnd (2, 1/2, [4 1])), [4, 1]) | 112 %!assert (size (nbinrnd (2, 1/2, [4 1])), [4, 1]) |
113 %!assert (size (nbinrnd (2, 1/2, 4, 1)), [4, 1]) | 113 %!assert (size (nbinrnd (2, 1/2, 4, 1)), [4, 1]) |
114 | 114 |
115 %% Test class of input preserved | 115 ## Test class of input preserved |
116 %!assert (class (nbinrnd (2, 1/2)), "double") | 116 %!assert (class (nbinrnd (2, 1/2)), "double") |
117 %!assert (class (nbinrnd (single (2), 1/2)), "single") | 117 %!assert (class (nbinrnd (single (2), 1/2)), "single") |
118 %!assert (class (nbinrnd (single ([2 2]), 1/2)), "single") | 118 %!assert (class (nbinrnd (single ([2 2]), 1/2)), "single") |
119 %!assert (class (nbinrnd (2, single (1/2))), "single") | 119 %!assert (class (nbinrnd (2, single (1/2))), "single") |
120 %!assert (class (nbinrnd (2, single ([1/2 1/2]))), "single") | 120 %!assert (class (nbinrnd (2, single ([1/2 1/2]))), "single") |
121 | 121 |
122 %% Test input validation | 122 ## Test input validation |
123 %!error nbinrnd () | 123 %!error nbinrnd () |
124 %!error nbinrnd (1) | 124 %!error nbinrnd (1) |
125 %!error nbinrnd (ones (3), ones (2)) | 125 %!error nbinrnd (ones (3), ones (2)) |
126 %!error nbinrnd (ones (2), ones (3)) | 126 %!error nbinrnd (ones (2), ones (3)) |
127 %!error nbinrnd (i, 2) | 127 %!error nbinrnd (i, 2) |