Skip to content

Commit e9feffe

Browse files
committed
Matlab >= R2020b
1 parent a069a9a commit e9feffe

130 files changed

Lines changed: 528 additions & 740 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

+stdlib/Backend.m

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,9 @@
2424
methods
2525

2626
function self = Backend(functionName, backendReq)
27-
% arguments
28-
% functionName (1,1) string = ""
29-
% backendReq (1,:) string = string.empty
30-
% end
31-
if nargin < 1
32-
functionName = "";
33-
end
34-
if nargin < 2
35-
backendReq = string.empty;
36-
else
37-
backendReq = string(backendReq);
27+
arguments
28+
functionName (1,1) string = ""
29+
backendReq (1,:) string = string.empty
3830
end
3931

4032
if isempty(backendReq) || ~isscalar(backendReq)
@@ -54,19 +46,11 @@
5446

5547

5648
function backendAvailable = select(self, functionName, backendReq, firstOnly)
57-
% arguments
58-
% self
59-
% functionName (1,1) string
60-
% backendReq (1,:) string = string.empty
61-
% firstOnly (1,1) logical = false
62-
% end
63-
if nargin < 3
64-
backendReq = string.empty;
65-
else
66-
backendReq = string(backendReq);
67-
end
68-
if nargin < 4
69-
firstOnly = false;
49+
arguments
50+
self
51+
functionName (1,1) string
52+
backendReq (1,:) string = string.empty
53+
firstOnly (1,1) logical = false
7054
end
7155

7256
backendAvailable = string.empty;
@@ -151,15 +135,10 @@
151135

152136

153137
function func = getFunc(self, functionName, backendReq)
154-
% arguments
155-
% self
156-
% functionName (1,1) string
157-
% backendReq (1,:) string = string.empty
158-
% end
159-
if nargin < 3
160-
backendReq = string.empty;
161-
else
162-
backendReq = string(backendReq);
138+
arguments
139+
self
140+
functionName (1,1) string
141+
backendReq (1,:) string = string.empty
163142
end
164143

165144
if isscalar(backendReq)

+stdlib/absolute.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
% non-existant path is made absolute relative to pwd
1717

1818
function c = absolute(p, base)
19-
if nargin < 2
20-
base = pwd();
19+
arguments
20+
p {mustBeTextScalar}
21+
base {mustBeTextScalar} = pwd()
2122
end
2223

2324
if stdlib.is_absolute(p)
@@ -48,5 +49,3 @@
4849
end
4950

5051
end
51-
52-
%!assert(~isempty(stdlib.absolute('')))

+stdlib/allToolboxes.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%% ALLTOOLBOXES tell all the Matlab toolboxes known for this Matlab release
2-
% requires: java, Matlab >= R2018a
2+
% requires: java
33

44
function names = allToolboxes()
55

+stdlib/append.m

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,21 @@
22
% APPEND(S1, S2, ...) appends strings or character vectors S1, S2, ... together.
33
% the output is a scalar string or character vector
44
%
5-
% builtin append() is for Matlab >= R2019a, while this works back to R2016b.
65
% strcat() has the side effect of trimming whitespace, so we prefer
76
% stdlib.append() for string concatenation in case a user path has trailing whitespace.
87

9-
function s = append(txt, varargin)
10-
11-
s = string(txt);
12-
13-
if stdlib.matlabOlderThan('R2019a')
14-
for i = 1:numel(varargin)
15-
s = s + varargin{i};
16-
end
17-
else
18-
s = s.append(varargin{:});
8+
function s = append(txt, a)
9+
arguments
10+
txt {mustBeTextScalar}
11+
end
12+
arguments (Repeating)
13+
a {mustBeText}
1914
end
2015

21-
if ischar(txt) && all(cellfun(@ischar, varargin))
16+
s = string(txt).append(a{:});
17+
18+
if ischar(txt) && all(cellfun(@ischar, a))
2219
s = char(s);
2320
end
2421

2522
end
26-
27-
28-
%!assert(stdlib.append('a','b'), 'ab')

+stdlib/auto_chunk_size.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
% * dims: proposed dataset dimensions (like size())
88

99
function csize = auto_chunk_size(dims)
10-
% arguments
11-
% dims (1,:) {mustBeInteger,mustBePositive}
12-
% end
10+
arguments
11+
dims (1,:) {mustBeInteger,mustBePositive}
12+
end
1313

1414
CHUNK_BASE = 16000; % Multiplier by which chunks are adjusted
1515
CHUNK_MIN = 8000; % lower limit: 8 kbyte

+stdlib/canonical.m

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
% * c: canonical path, if determined
1414

1515
function c = canonical(file, strict)
16-
if nargin < 2
17-
strict = false;
16+
arguments
17+
file {mustBeTextScalar}
18+
strict (1,1) logical = false
1819
end
1920

2021
c = '';
@@ -26,20 +27,22 @@
2627
c = char(c);
2728
end
2829
catch e
29-
switch e.identifier
30-
case 'MATLAB:io:filesystem:filePermissions:CannotFindLocation'
31-
if ~strict && ~stdlib.strempty(file)
32-
c = stdlib.normalize(file);
33-
end
34-
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
35-
[s, r] = fileAttribCompatible(file);
36-
if s == 1
37-
c = r.Name;
38-
elseif ~strict && ~stdlib.strempty(r)
39-
c = stdlib.normalize(file);
40-
end
41-
otherwise
42-
rethrow(e)
30+
if ~stdlib.strempty(file)
31+
switch e.identifier
32+
case 'MATLAB:io:filesystem:filePermissions:CannotFindLocation'
33+
if ~strict
34+
c = stdlib.normalize(file);
35+
end
36+
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
37+
[s, r] = fileattrib(file);
38+
if s == 1
39+
c = r.Name;
40+
elseif ~strict
41+
c = stdlib.normalize(file);
42+
end
43+
otherwise
44+
rethrow(e)
45+
end
4346
end
4447

4548
if isstring(file)
@@ -48,5 +51,3 @@
4851
end
4952

5053
end
51-
52-
%!assert (length(stdlib.canonical('.')) > 1)

+stdlib/checkRAM.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616

1717
function [OK,newSizeBytes,freebytes] = checkRAM(newSize, myclass)
18+
arguments
19+
newSize (1,:) {mustBePositive, mustBeInteger}
20+
myclass {mustBeTextScalar}
21+
end
1822

1923
% get available RAM
2024
freebytes = stdlib.ram_free();

+stdlib/checkout_license.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
% be used rather than just checking if the relevant toolbox is installed.
1212

1313
function [ok, featureName] = checkout_license(packageName)
14-
% arguments
15-
% packageName (1,1) string
16-
% end
14+
arguments
15+
packageName {mustBeTextScalar}
16+
end
1717

1818
ok = false;
1919
featureName = string.empty;

+stdlib/cpu_load.m

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
% If the system recent cpu usage is not available, the backend returns a negative or NaN value.
1111

1212
function [i, b] = cpu_load(backend)
13-
if nargin < 1
14-
backend = {'java', 'python', 'shell'};
15-
else
16-
backend = cellstr(backend);
13+
arguments
14+
backend (1,:) string = ["java", "python", "shell"]
1715
end
1816

1917
i = [];
2018

21-
for j = 1:numel(backend)
22-
b = backend{j};
19+
for b = backend
2320
switch b
2421
case 'java'
2522
i = stdlib.java.cpu_load();
@@ -39,5 +36,3 @@
3936
end
4037

4138
end
42-
43-
%!assert (stdlib.cpu_load() >= 0)

+stdlib/create_symlink.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
% * b: backend used
99

1010
function [i, b] = create_symlink(target, link, backend)
11-
if nargin < 3
12-
backend = {'native', 'dotnet', 'python', 'shell'};
13-
else
14-
backend = cellstr(backend);
11+
arguments
12+
target {mustBeTextScalar}
13+
link {mustBeTextScalar}
14+
backend (1,:) string = ["native", "dotnet", "python", "shell"]
1515
end
1616

1717
i = logical([]);
1818

19-
for j = 1:numel(backend)
20-
b = backend{j};
19+
for b = backend
2120
switch b
2221
case 'native'
2322
i = stdlib.native.create_symlink(target, link);

0 commit comments

Comments
 (0)