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