Skip to content

Commit 1de645d

Browse files
committed
restore Matlab 'arguments' syntax for reliability
1 parent 922f1f5 commit 1de645d

Some content is hidden

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

53 files changed

+228
-289
lines changed

+stdlib/auto_chunk_size.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +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
13-
14-
assert(isvector(dims), 'dims must be a vector')
15-
mustBePositive(dims)
10+
arguments
11+
dims (1,:) {mustBeInteger,mustBePositive}
12+
end
1613

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

+stdlib/canonical.m

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#getCanonicalPath()
1515

1616
function c = canonical(p, expand_tilde, use_java)
17-
% arguments
18-
% p (1,1) string
19-
% expand_tilde (1,1) logical = true
20-
% use_java (1,1) logical = false
21-
% end
22-
if nargin < 2, expand_tilde = true; end
23-
if nargin < 3, use_java = false; end
17+
arguments
18+
p (1,1) string
19+
expand_tilde (1,1) logical = true
20+
use_java (1,1) logical = false
21+
end
22+
2423

2524
if expand_tilde
2625
c = stdlib.expanduser(p, use_java);
@@ -61,6 +60,6 @@
6160

6261
end
6362

64-
%!assert(canonical(""), "")
65-
%!assert(canonical("~"), homedir())
66-
%!assert(canonical("a/b/.."), "a")
63+
%!assert(canonical("", 1, 0), "")
64+
%!assert(canonical("~", 1, 0), homedir())
65+
%!assert(canonical("a/b/..", 1, 0), "a")

+stdlib/checkRAM.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
% certainly CAN'T create an array without digging deep into swap or worse.
77

88
function [OK,newSizeBytes,freebytes] = checkRAM(newSize, myclass)
9-
% arguments
10-
% newSize (1,:) {mustBeNumeric}
11-
% myclass (1,1) string
12-
% end
9+
arguments
10+
newSize (1,:) {mustBeNumeric}
11+
myclass (1,1) string
12+
end
1313

1414
% get available RAM
1515
freebytes = stdlib.ram_free();

+stdlib/create_symlink.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
% Ref: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#createSymbolicLink(java.nio.file.Path,java.nio.file.Path,java.nio.file.attribute.FileAttribute...)
1010

1111
function ok = create_symlink(target, link)
12-
% arguments
13-
% target (1,1) string
14-
% link (1,1) string
15-
% end
12+
arguments
13+
target (1,1) string
14+
link (1,1) string
15+
end
1616

1717
if stdlib.isoctave()
1818

+stdlib/diskfree.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
% Ref: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#getUsableSpace()
77

88
function f = diskfree(d)
9-
% arguments
10-
% d (1,1) string
11-
% end
9+
arguments
10+
d (1,1) string
11+
end
1212

1313
if stdlib.isoctave()
1414
o = javaObject("java.io.File", d);

+stdlib/drop_slash.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
%% DROP_SLASH drop repeated and trailing slash
22

33
function d = drop_slash(p)
4-
% arguments
5-
% p (1,1) string
6-
% end
4+
arguments
5+
p (1,1) string
6+
end
77

88
s = stdlib.posix(p);
99

+stdlib/exists.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
%
1212

1313
function ok = exists(p, use_java)
14-
% arguments
15-
% p (1,1) string
16-
% use_java (1,1) logical = false
17-
% end
18-
if nargin < 2, use_java = false; end
14+
arguments
15+
p (1,1) string
16+
use_java (1,1) logical = false
17+
end
1918

2019
if stdlib.isoctave()
2120
ok = javaObject("java.io.File", p).exists();

+stdlib/expanduser.m

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
% * e: expanded path
99

1010
function e = expanduser(p, use_java)
11-
% arguments
12-
% p (1,1) string
13-
% use_java (1,1) logical = false
14-
% end
15-
if nargin < 2, use_java = false; end
11+
arguments
12+
p (1,1) string
13+
use_java (1,1) logical = false
14+
end
1615

1716
e = stdlib.drop_slash(p);
1817

@@ -30,26 +29,28 @@
3029

3130
home = stdlib.homedir(use_java);
3231

33-
if ~isempty(home)
34-
d = home;
35-
if L < 2
36-
e = d;
37-
return
38-
end
39-
40-
if ischar(e)
41-
e = strcat(d, '/', e(3:end));
42-
else
43-
e = d + "/" + extractAfter(e, 2);
44-
end
32+
if stdlib.len(home) == 0
33+
return
34+
end
35+
36+
d = home;
37+
if L < 2
38+
e = d;
39+
return
40+
end
41+
42+
if ischar(e)
43+
e = strcat(d, '/', e(3:end));
44+
else
45+
e = d + "/" + extractAfter(e, 2);
4546
end
4647

4748
end
4849

4950

50-
%!assert(expanduser(''), '')
51-
%!assert(expanduser("~"), homedir())
52-
%!assert(expanduser("~/"), homedir())
53-
%!assert(expanduser("~user"), "~user")
54-
%!assert(expanduser("~user/"), "~user")
55-
%!assert(expanduser("~///c"), strcat(homedir(), "/c"))
51+
%!assert(expanduser('', 0), '')
52+
%!assert(expanduser("~", 0), homedir())
53+
%!assert(expanduser("~/", 0), homedir())
54+
%!assert(expanduser("~user", 0), "~user")
55+
%!assert(expanduser("~user/", 0), "~user")
56+
%!assert(expanduser("~///c", 0), strcat(homedir(), "/c"))

+stdlib/file_checksum.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
% Ref: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/security/MessageDigest.html#getInstance(java.lang.String)
1111

1212
function hash = file_checksum(file, method)
13-
% arguments
14-
% file (1,1) string {mustBeFile}
15-
% method (1,1) string
16-
% end
13+
arguments
14+
file (1,1) string {mustBeFile}
15+
method (1,1) string
16+
end
1717

1818
if strcmp(method, "sha256") || strcmp(method, "SHA256")
1919
method = "SHA-256";

+stdlib/file_size.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
% FILE_SIZE size in bytes of file
22

33
function s = file_size(p, use_java)
4-
% arguments
5-
% p (1,1) string {mustBeFile}
6-
% use_java (1,1) logical = false
7-
% end
8-
if nargin < 2, use_java = false; end
4+
arguments
5+
p (1,1) string {mustBeFile}
6+
use_java (1,1) logical = false
7+
end
98

109
if stdlib.isoctave()
1110
s = javaObject("java.io.File", p).length();

0 commit comments

Comments
 (0)