comparison scripts/statistics/distributions/gamrnd.m @ 19867: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
19866:a1acca0c2216 19867: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 (a) || !isscalar (b)) 47 if (! isscalar (a) || ! isscalar (b))
48 [retval, a, b] = common_size (a, b); 48 [retval, a, b] = common_size (a, b);
49 if (retval > 0) 49 if (retval > 0)
50 error ("gamrnd: A and B must be of common size or scalars"); 50 error ("gamrnd: A and B 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 ("gamrnd: dimension vector must be row vector of non-negative integers"); 66 error ("gamrnd: 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 ("gamrnd: dimensions must be non-negative integers"); 70 error ("gamrnd: 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 (a) && !isequal (size (a), sz)) 75 if (! isscalar (a) && ! isequal (size (a), sz))
76 error ("gamrnd: A and B must be scalar or of size SZ"); 76 error ("gamrnd: A and B must be scalar or of size SZ");
77 endif 77 endif
78 78
79 if (isa (a, "single") || isa (b, "single")) 79 if (isa (a, "single") || isa (b, "single"))
80 cls = "single"; 80 cls = "single";
105 %!assert (size (gamrnd (1, 2*ones (2,2))), [2, 2]) 105 %!assert (size (gamrnd (1, 2*ones (2,2))), [2, 2])
106 %!assert (size (gamrnd (1, 2, 3)), [3, 3]) 106 %!assert (size (gamrnd (1, 2, 3)), [3, 3])
107 %!assert (size (gamrnd (1, 2, [4 1])), [4, 1]) 107 %!assert (size (gamrnd (1, 2, [4 1])), [4, 1])
108 %!assert (size (gamrnd (1, 2, 4, 1)), [4, 1]) 108 %!assert (size (gamrnd (1, 2, 4, 1)), [4, 1])
109 109
110 %% Test class of input preserved 110 ## Test class of input preserved
111 %!assert (class (gamrnd (1, 2)), "double") 111 %!assert (class (gamrnd (1, 2)), "double")
112 %!assert (class (gamrnd (single (1), 2)), "single") 112 %!assert (class (gamrnd (single (1), 2)), "single")
113 %!assert (class (gamrnd (single ([1 1]), 2)), "single") 113 %!assert (class (gamrnd (single ([1 1]), 2)), "single")
114 %!assert (class (gamrnd (1, single (2))), "single") 114 %!assert (class (gamrnd (1, single (2))), "single")
115 %!assert (class (gamrnd (1, single ([2 2]))), "single") 115 %!assert (class (gamrnd (1, single ([2 2]))), "single")
116 116
117 %% Test input validation 117 ## Test input validation
118 %!error gamrnd () 118 %!error gamrnd ()
119 %!error gamrnd (1) 119 %!error gamrnd (1)
120 %!error gamrnd (ones (3), ones (2)) 120 %!error gamrnd (ones (3), ones (2))
121 %!error gamrnd (ones (2), ones (3)) 121 %!error gamrnd (ones (2), ones (3))
122 %!error gamrnd (i, 2) 122 %!error gamrnd (i, 2)