Skip to content

Commit

Permalink
Various changes
Browse files Browse the repository at this point in the history
* `Yk` (closest value) now includes a third output with indices of
selected values

* `Z^` (Cartesian power) now allows inputs in reverse order if the
second is an array of at least two elements

* `m` (`ismember`) and `u` (`unique`) now accept numeric content in cell
array input

* `Z+` (2D convolution; see also `Y+`) now produces output the same size
as the input

* Bug corrected in `e` (`reshape`) for `logical` input

* Modular indexing has been added, only for scalar indices (thanks to
@dennis for the suggestion)

* Bug corrected in `ZA`. In addition, now it allows cell array input,
and ignores non-recognized digits

* `o` with cell input now allows specifying fill value and padding side

* `Z}` (split array) now by default splits along the first non-singleton
dimension

* Added `W` function: 2 raised to input, element-wise

* Updated the Fibonacci example in the documentation (1 byte fewer using
`y`), and included the new features

* `YS` (`circshift`) now allows second input to be a vector with third
input specifying dimension when first input is a 2D array

* `Xd` (`diag`) now includes `spdiags` functionality

* `format` function has been integrated with `ZG`

* `h` (horizontal concatenation) and `v` (vertical concatenation) now
linearize their inputs if sizes don't match
  • Loading branch information
lmendo committed Mar 26, 2016
1 parent ce77a4a commit bf2c69a
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 67 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.
177 changes: 118 additions & 59 deletions funDef.txt

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions genHelp.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@
inFormatted{n} = sprintf('%i', defIn);
end

% Format output spec. Changes done here should be done in MATL_spec.tex too
if isnan(defOut) && ~isempty(F(n).defOut) % F(n).defOut contains a string that couldn't be converted to a number
% Format output spec. Changes done here should also be done in genFunDefTableLatex.m and in MATL_spec.tex
if (isnan(defOut) || defOut<0) && ~isempty(F(n).defOut) % F(n).defOut contains a string that couldn't be converted to a number, or a negative number
switch F(n).defOut
case {'numel(CB_H)' 'numel(CB_I)' 'numel(CB_J)' 'numel(CB_K)'}
defOutStr = 'number of elements in clipboard';
Expand All @@ -181,6 +181,10 @@
defOutStr = 'according to specified keywords';
case 'numel(in)'
defOutStr = 'number of inputs';
case '-1'
defOutStr = 'number of elements that will be produced';
case '-2'
defOutStr = 'number of subarrays that will be produced';
otherwise
error('Unrecognized default number of outputs')
end
Expand All @@ -198,7 +202,7 @@
end
else
if maxOut ~= defOut
error('Incorrect specification of number of inputs')
error('Incorrect specification of number of outputs')
end
outFormatted{n} = sprintf('%i', defOut);
end
Expand Down
Binary file modified help.mat
Binary file not shown.
29 changes: 25 additions & 4 deletions matl_compile.m
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,30 @@
end

function newLines = funPre(minIn, maxIn, defIn, minOut, maxOut, defOut, consume, funInClipboard)
% Code generated at the beginning of functions: check S_IN and S_OUT,
% get inputs, prepare outputs, consume inputs if applicable.
% Code generated at the beginning of functions: check `S_IN` and `S_OUT`,
% define `nout`, get inputs, prepare outputs, consume inputs if applicable.
% `consume` indicates if inputs should be removed from the stack
% (1) If `nout` is a non-negative number (specified or by default), the function should
% produce that number of outputs. For MATL functions that simply call a MATLAB function,
% this implies calling the MATLAB function with that number of outputs. For MATL functions
% that are implemented "manually", it's their responsibility to produce `nout` outputs.
% If `n_out` is a logical array, the number of outputs produced by the function
% should be the number of elements in the logical array. At the end (funPost), the
% outputs corresponding to false values will be discarded.
% (2) For functions for which the default value of S_OUT depends on the
% inputs (cannot be computed at compile-time) and can be computed at
% run-time at the beginning of the function, this default value is
% specified in the function definition file as the appropriate code, in the form of
% a string that will be evaluated at the beginning of the function call.
% That result from string will be assigned to `nout`.
% (3) For functions for which the default value of S_OUT depends on the inputs
% and is very difficult to compute even at run-time at the beginning of the function,
% a negative number is specified as default value in the function definition file. A negative
% number means "`nout` unspecified, the function will build the variable `out` with the default
% number of outputs as defined by the function, or with `nout` outputs if `nout` is nonnegative".
% A negative value of the default number of outputs is translated into the appropriate text
% in the help and documentation; different negative values can be used to select that text.
% If possible, it's probably safer to use method (2) than (3).
global implicitInputBlock
newLines = { ...
sprintf('if isempty(S_IN), S_IN = %s; end', defIn) ...
Expand All @@ -336,12 +357,12 @@
end
newLines = [newLines, {...
sprintf('if isempty(S_OUT), S_OUT = %s; end', defOut) ...
sprintf('if isnumeric(S_OUT) && numel(S_OUT) == 1, if S_OUT < %s || S_OUT > 2*(%s), error(''MATL:runner'', ''MATL run-time error: incorrect output specification''), end', minOut, maxOut) ...
sprintf('if isnumeric(S_OUT) && numel(S_OUT) == 1, if S_OUT >= 0 && (S_OUT < %s || S_OUT > 2*(%s)), error(''MATL:runner'', ''MATL run-time error: incorrect output specification''), end', minOut, maxOut) ...
sprintf('elseif islogical(S_OUT), if numel(S_OUT) < %s || numel(S_OUT) > %s, error(''MATL:runner'', ''MATL run-time error: incorrect output specification''), end', minOut, maxOut) ...
'else error(''MATL:runner'', ''MATL run-time error: output specification not recognized''), end' ...
sprintf('if isnumeric(S_OUT) && S_OUT > %s, S_OUT = [false(1,S_OUT-(%s+1)) true]; end', maxOut, maxOut) ...
'if isnumeric(S_OUT), nout = S_OUT; else nout = numel(S_OUT); end' ...
'out = cell(1,nout);' }];
'if nout>=0, out = cell(1,nout); end' }];
% 2*(...) because a number in maxOut+1:2*maxOut corresponds to a logical vector with a single true value
% For logical S_IN we use nnz (the inputs are picked from the stack), but
% for logical S_OUT we use numel (the function is called with that many outputs)
Expand Down
Binary file modified preLit.mat
Binary file not shown.
10 changes: 9 additions & 1 deletion preLit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,12 @@ Y5
3 'both'
4 'circular'
5 'replicate'
6 'symmetric'
6 'symmetric'


Y6

1 [false true false; true false true; false true false]
2 [false true false; true true true; false true false]
3 [true true true; true false true; true true true]
4 [true true true; true true true; true true true]

0 comments on commit bf2c69a

Please sign in to comment.