Skip to content

Commit

Permalink
* Added predefined literals for consonant letters. Thanks, @suever!
Browse files Browse the repository at this point in the history
* `o` now behaves like `mod(..., 2)` for inputs that are already `double`

* 1-input versions of `*`, `+`, `-`, `<`, `>` now use transposed first input as second input. Thanks to @suever for the suggestion!

* Corrected a bug that affected automatic generation of input/output specs for command-line help
  • Loading branch information
lmendo committed Jun 18, 2016
1 parent 426c9ba commit 80967c0
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 11 deletions.
Binary file modified doc/MATL_spec.pdf
Binary file not shown.
Binary file modified doc/function_table.pdf
Binary file not shown.
Binary file modified funDef.mat
Binary file not shown.
32 changes: 22 additions & 10 deletions funDef.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ Z) 1 inf 2 1 2 1 2 true true true true array = in{1}; reference ( ) indexing wi
out{1} = array(indices{:});
if nout>1, y = array; y(indices{:}) = []; out{2} = y; end
% Z) is the same as ) except for the `indices = ...` line
* 0 inf 2 numel(STACK) 1 1 1 true true true true if isempty(in), y = 1; else y = in{1}; for n=2:numel(in), y = bsxfun(@times, y, in{n}); end; end; out{1} = y; clear y n; array product (element-wise, singleton expansion) \matlab+.*+ (\matlab+times+), element-wise with singleton expansion
* 1 inf 2 1 1 1 1 true true true true if numel(in)==1, in{2} = in{1}.'; end array product (element-wise, singleton expansion) \matlab+.*+ (\matlab+times+), element-wise with singleton expansion. If $1$ input: a second input is used given by the first transposed
y = in{1}; for n=2:numel(in), y = bsxfun(@times, y, in{n}); end;
out{1} = y; clear y n;
X* 2 2 2 1 1 1 true true true true out{1} = kron(double(in{1}), double(in{2})); Kronecker tensor product \matlab+kron+
Y* 2 2 2 1 1 1 true true true true if islogical(in{1}), in{1} = double(in{1}); end matrix product matrix product, \matlab+*+ (\matlab+mtimes+)
if islogical(in{2}), in{2} = double(in{2}); end
Expand All @@ -253,7 +255,9 @@ Z* 1 inf 2 numel(STACK) 1 1 1 true true true true n = numel(in); combs = cell(1
[combs{end:-1:1}] = ndgrid(in{end:-1:1});
combs = cat(n+1, combs{:}); combs = reshape(combs,[],n);
out{1} = combs; clear combs n
+ 0 inf 2 numel(STACK) 1 1 1 true true true true if isempty(in), y = 0; else y = in{1}; for n=2:numel(in), y = bsxfun(@plus, y, in{n}); end; end; out{1} = y; clear y n; addition (element-wise, singleton expansion) \matlab|+| (\matlab+plus+), element-wise with singleton expansion
+ 1 inf 2 1 1 1 1 true true true true if numel(in)==1, in{2} = in{1}.'; end addition (element-wise, singleton expansion) \matlab|+| (\matlab+plus+), element-wise with singleton expansion. If $1$ input: a second input is used given by the first transposed
y = in{1}; for n=2:numel(in), y = bsxfun(@plus, y, in{n}); end;
out{1} = y; clear y n;
X+
Y+ 2 3 2 3 1 1 1 true true true true str = {'same' 'valid' 'full'}; two-dimensional convolution \matlab+conv2+. Doesn't allow two-vector and one matrix mode. Converts first two inputs to \matlab+double+. This function allows flag strings in third and subsequent inputs to be replaced by numbers, as follows: 1: \matlab+'same'+, 2: \matlab+'valid'+, 3: \matlab+'full'+. \sa \matl|Z+|
for k = 3:numel(in), if isnumeric(in{k}), in(k) = str(in{k}); end; end; clear str
Expand All @@ -265,7 +269,8 @@ Z+ 2 2 2 1 1 1 true true true true if issparse(in{1}), in{1} = full(in{1}); en
X, 1 1 1 1 1 1 true true true true out{1} = cos(in{1}); cosine (radians) \matlab+cos+
Y, 1 1 1 1 1 1 true true true true out{1} = sin(in{1}); sine (radians) \matlab+sin+
Z, 1 1 1 1 1 1 true true true true out{1} = tan(in{1}); tangent (radians) \matlab+tan+
- 2 2 2 1 1 1 true true true true out{1} = bsxfun(@minus, in{1}, in{2}); subtraction (element-wise, singleton expansion) \matlab+-+ (\matlab+minus+), element-wise with singleton expansion
- 1 2 2 1 1 1 1 true true true true if numel(in)==1, in{2} = in{1}.'; end subtraction (element-wise, singleton expansion) \matlab+-+ (\matlab+minus+), element-wise with singleton expansion. If $1$ input: a second input is used given by the first transposed
out{1} = bsxfun(@minus, in{1}, in{2});
X- 2 4 2 3 1 2 1 true true true true str = {'rows' 'stable' 'sorted'}; set difference \matlab+setdiff+. Uses the \matlab+'stable'+ flag by default. If one input is char and the other is numeric, the latter is converted to char. This function allows flag strings in third and subsequent inputs to be replaced by numbers, as follows: 1: \matlab+'rows'+, 2: \matlab+'stable'+, 3: \matlab+'sorted'+
for k = 3:numel(in), if isnumeric(in{k}), in(k) = str(in{k}); end; end; clear str
if ischar(in{1}) && isnumeric(in{2}), in{2} = char(in{2}); end
Expand Down Expand Up @@ -367,17 +372,20 @@ Z: 2 4 3 1 1 1 true true true true if ischar(in{1}), in{1} = double(in{1}); en
X; 1 1 1 1 1 1 true true true true out{1} = acos(in{1}); inverse cosine (radians) \matlab+acos+
Y; 1 1 1 1 1 1 true true true true out{1} = asin(in{1}); inverse sine (radians) \matlab+asin+
Z; 2 2 2 1 1 1 true true true true out{1} = bsxfun(@atan2, in{1}, in{2}); four quadrant inverse tangent (radians; element-wise, singleton expansion) \matlab+atan2+, element-wise with singleton expansion
< 2 2 2 1 1 1 true true true true out{1} = bsxfun(@lt, in{1}, in{2}); is less than? (element-wise, singleton expansion) \matlab+<+ (\matlab+lt+), element-wise with singleton expansion
< 1 2 2 1 1 1 1 true true true true if numel(in)==1, in{2} = in{1}.'; end is less than? (element-wise, singleton expansion) \matlab+<+ (\matlab+lt+), element-wise with singleton expansion. If $1$ input: a second input is used given by the first transposed
out{1} = bsxfun(@lt, in{1}, in{2});
X< 1 3 1 1 2 1 [false true] true true true true if numel(in)==2, out{1} = bsxfun(@min, in{1}, in{2}); minimum \matlab+min+. If $2$ inputs: element-wise with singleton expansion. With more than $2$ inputs, the second is replaced by \matl+[]+
elseif numel(in)==1, [out{:}] = min(in{:});
else in{2} = []; [out{:}] = min(in{:}); end
Y< 1 3 1 2 1 1 1 true true true true out{1} = cummin(in{:}); cumulative minimum \matlab+cummin+
Z<
= 2 2 2 1 1 1 true true true true out{1} = bsxfun(@eq, in{1}, in{2}); is equal? (element-wise, singleton expansion) \matlab+==+ (\matlab+eq+), element-wise with singleton expansion
= 1 2 2 1 1 1 1 true true true true if numel(in)==1, in{2} = in{1}.'; end is equal? (element-wise, singleton expansion) \matlab+==+ (\matlab+eq+), element-wise with singleton expansion. If $1$ input: a second input is used given by the first transposed
out{1} = bsxfun(@eq, in{1}, in{2});
X= 2 inf 2 1 1 1 true true true true out{1} = isequal(in{:}); true if arrays are numerically equal \matlab+isequal+
Y= 2 2 2 1 1 1 true true true true if isnumeric(in{1}), in{1} = char(in{1}); end; if isnumeric(in{2}), in{2} = char(in{2}); end; out{1} = strcmp(in{:}); compare strings \matlab+strcmp+. If first or second inputs are numeric they are converted to char
Z= 3 3 3 1 1 1 true true true true if isnumeric(in{1}), in{1} = char(in{1}); end; if isnumeric(in{2}), in{2} = char(in{2}); end; out{1} = strncmp(in{:}); compare first characters of strings \matlab+strncmp+. If first or second inputs are numeric they are converted to char
> 2 2 2 1 1 1 true true true true out{1} = bsxfun(@gt, in{1}, in{2}); is greater than? (element-wise, singleton expansion) \matlab+>+ (\matlab+gt+), element-wise with singleton expansion
> 1 2 2 1 1 1 1 true true true true if numel(in)==1, in{2} = in{1}.'; end is greater than? (element-wise, singleton expansion) \matlab+>+ (\matlab+gt+), element-wise with singleton expansion. If $1$ input: a second input is used given by the first transposed
out{1} = bsxfun(@gt, in{1}, in{2});
X> 1 3 1 1 2 1 [false true] true true true true if numel(in)==2, out{1} = bsxfun(@max, in{1}, in{2}); maximum \matlab+max+. If $2$ inputs: element-wise with singleton expansion. With more than $2$ inputs, the second is replaced by \matl+[]+
elseif numel(in)==1, [out{:}] = max(in{:});
else in{2} = []; [out{:}] = max(in{:}); end
Expand Down Expand Up @@ -753,9 +761,9 @@ X[ 2 2 2 1 inf 2 true true true true siz = double(in{1}); ndx = in{2}; lensiz
% This code above was taken from Matlab's `ind2sub`
Y[
Z[
\ 2 2 2 1 2 1 2 true true true true out{1} = bsxfun(@mod, in{1}, in{2}); modulus/quotient after division (element-wise, singleton expansion) \matlab+mod+, element-wise with singleton expansion. With $2$ outputs: second output is `floor(.../...)`.
\ 2 2 2 1 2 1 2 true true true true out{1} = bsxfun(@mod, in{1}, in{2}); modulo/quotient after division (element-wise, singleton expansion) \matlab+mod+, element-wise with singleton expansion. With $2$ outputs: second output is \matlab+floor(.../...)+. \sa \matl|X\|, \matl|o|
if numel(out)==2, out{2} = floor(bsxfun(@rdivide, in{1}, in{2})); end
X\ 2 2 2 1 1 1 true true true true out{1} = bsxfun(@mod, in{1}-1, in{2})+1; modulus on the interval [1,divisor) (element-wise, singleton expansion) \matlab|mod(...-1)+1|, element-wise with singleton expansion
X\ 2 2 2 1 1 1 true true true true out{1} = bsxfun(@mod, in{1}-1, in{2})+1; modulo on the interval [1,divisor+1) (element-wise, singleton expansion) \matlab|mod(...-1, ...)+1|, element-wise with singleton expansion. \sa \matl|\|
Y\ 2 2 2 1 1 1 true true true true out{1} = in{1}\in{2}; left matrix division left matrix division, \matlab+\+ (\matlab+mldivide+)
Z\
]
Expand Down Expand Up @@ -900,7 +908,7 @@ d 1 3 1 2 1 1 1 true true true true if numel(in)==1, out{1} = diff(in{1}); diff
elseif numel(in)==2, out{1} = diff(in{1}, [], in{2});
elseif numel(in)==3, out{1} = diff(in{[1 3 2]});
else error('MATL:runtime', 'MATL run-time error: incorrect number of inputs'), end
Xd 1 4 1 2 1 2 1 true true true true if numel(in)==1 && numel(out)==1, out{1} = diag(in{:}); diagonal matrices and diagonals of a matrix If $1$ input and $1$ output: \matlab+diag+. Otherwise: \matlab+spdiags+, with char inputs automatically converted to double
Xd 1 4 1 2 1 2 1 true true true true if numel(in)==1 && numel(out)==1, out{1} = diag(in{:}); diagonal matrices and diagonals of a matrix If $1$ input and $1$ output: \matlab+diag+. Otherwise: \matlab+spdiags+, with char inputs automatically converted to \matlab+double+
elseif numel(in)==2 && numel(out)==1 && isrow(in{1})
y = zeros(size(in{2})); mask = (in{2}>=0) & (in{2}<=numel(in{1})-1); y(mask) = in{1}(in{2}(mask)+1); out{1} = y; clear y
elseif numel(in)==2 && numel(out)==1 && iscolumn(in{1})
Expand Down Expand Up @@ -1114,9 +1122,13 @@ Yn 1 5 2 4 1 1 1 true true true true if numel(in)==1 interpolation (table looku
out{1} = interp1(in{:});
end
Zn
o 1 3 1 1 1 1 true true true true if ~iscell(in{1}) convert to double precision array \matlab+double+. For cell array input behaves similarly to \matlab+char+: linearizes cell array, converts cell contents to double and concatenates vertically, padding if needed. By default, padding is with zeros on the left. Optional second input indicates fill side: left if it evaluates to \matlab+false+, right if it evaluates to \matlab+true+. Third optional input specifies fill value
o 1 3 1 1 1 1 true true true true if ~iscell(in{1}) convert to double precision array / modulo 2 (i) \matlab+double+. (ii) For cell array input behaves similarly to \matlab+char+: linearizes cell array, converts cell contents to \matlab+double+ and concatenates vertically, padding if needed. By default, padding is with zeros on the left. Optional second input indicates fill side: left if it evaluates to \matlab+false+, right if it evaluates to \matlab+true+. Third optional input specifies fill value. (iii) If input is already of type \matlab+double+: \matlab+mod(..., 2)+
if ~isa(in{1}, 'double')
out{1} = double(in{1});
else
out{1} = mod(in{1}, 2);
end
else
in{1} = in{1}(:);
n = max(cellfun(@(c) size(c,2), in{1}));
if numel(in)>=2, lr = in{2}; else, lr = false; end
Expand Down
2 changes: 1 addition & 1 deletion genHelp.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
else
inFormatted{n} = sprintf('%i-- (%s / %s)', minIn, defInStr, altInStr);
end
elseif (minOut == maxOut) && ~isempty(altOutStr)
elseif (minIn == maxIn) && ~isempty(altInStr)
inFormatted{n} = sprintf('%i (%s / %s)', maxIn, defInStr, altInStr);
else
if (maxIn ~= defIn) % || ~isempty(altInStr) % We removed this condition for the same reasons as for the output
Expand Down
Binary file modified help.mat
Binary file not shown.
Binary file modified preLit.mat
Binary file not shown.
3 changes: 3 additions & 0 deletions preLit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ Y2
11 'aeiou'
12 'AEIOU'
13 'aeiouAEIOU'
14 'bcdfghjklmnpqrstvwxyz'
15 'BCDFGHJKLMNPQRSTVWXYZ'
16 'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ'
20 ['Mon'; 'Tue'; 'Wed'; 'Thu'; 'Fri'; 'Sat'; 'Sun']
21 [298 302 288 305 289 296 310]
22 {'January' 'February' 'March' 'April' 'May' 'June' 'July' 'August' 'September' 'October' 'November' 'December'}
Expand Down

0 comments on commit 80967c0

Please sign in to comment.