Skip to content

Commit d30125f

Browse files
committed
vectorize
1 parent f2b253a commit d30125f

22 files changed

+69
-97
lines changed

+stdlib/+java/inode.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
function i = inode(p)
22

3-
opt = javaMethod("values", "java.nio.file.LinkOption");
3+
opt = java.nio.file.LinkOption.values();
44

55
jp = javaPathObject(stdlib.absolute(p));
66
% Java 1.8 benefits from the absolute() for stability--it's not an issue
77
% on every computer.
88

9-
i = javaMethod("getAttribute", "java.nio.file.Files", jp, "unix:ino", opt);
9+
i = java.nio.file.Files.getAttribute(jp, "unix:ino", opt);
1010

1111
i = uint64(i);
1212
end

+stdlib/drop_slash.m

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

4-
function d = drop_slash(p)
4+
function d = drop_slash(filepath)
55
arguments
6-
p {mustBeTextScalar}
6+
filepath string
77
end
88

9-
s = stdlib.posix(p);
9+
s = stdlib.posix(filepath);
1010

1111
% drop repeated slashes inside string
1212
d = regexprep(s, '/+', '/');
1313

1414
% drop all trailing slashes
15-
if ~strcmp(d, '/') && ~strcmp(d, stdlib.root(s))
16-
d = regexprep(d, '/$', '');
17-
end
15+
i = ~strcmp(d, '/') & ~strcmp(d, stdlib.root(s));
16+
17+
d(i) = regexprep(d(i), '/$', '');
1818

1919
end

+stdlib/h5exists.m

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@
77
% * exists: boolean
88

99
function exists = h5exists(file, variable)
10-
arguments
11-
file
12-
variable (1,1) string
13-
end
14-
15-
exists = false;
1610

1711
try
1812
h5info(file, variable);
1913
exists = true;
2014
catch e
21-
if ~strcmp(e.identifier, 'MATLAB:imagesci:h5info:unableToFind')
15+
if e.identifier ~= "MATLAB:imagesci:h5info:unableToFind"
2216
rethrow(e)
2317
end
18+
19+
exists = false;
2420
end
2521

2622
end

+stdlib/inode.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88

99
function [i, b] = inode(file, backend)
1010
arguments
11-
file {mustBeTextScalar}
11+
file string
1212
backend (1,:) string = ["java", "python", "sys"]
1313
end
1414

1515
[fun, b] = hbackend(backend, "inode");
1616

17-
i = fun(file);
17+
if isscalar(file)
18+
i = fun(file);
19+
else
20+
i = arrayfun(fun, file);
21+
end
1822

1923
end

+stdlib/is_executable_binary.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
% (ELF) formats.
1717

1818
function y = is_executable_binary(filename)
19-
arguments
20-
filename {mustBeTextScalar}
21-
end
2219

2320
y = false;
2421

+stdlib/is_hdf5.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
%% IS_HDF5 is file an HDF5 file?
22

33
function is_hdf5 = is_hdf5(filename)
4-
arguments
5-
filename {mustBeTextScalar}
6-
end
74

85
is_hdf5 = H5F.is_hdf5(filename) == 1;
96

+stdlib/is_mex_fun.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
%% IS_MEX_FUN detect if a function is loaded as MEX or plain .m
22

33
function y = is_mex_fun(name)
4-
arguments
5-
name {mustBeTextScalar}
6-
end
74

85
% this method is 4x faster than using inmem() and processing strings
96

+stdlib/is_mount.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414

1515
function [ok, b] = is_mount(filepath, backend)
1616
arguments
17-
filepath {mustBeTextScalar}
17+
filepath string
1818
backend (1,:) string = ["python", "sys"]
1919
end
2020

2121
[fun, b] = hbackend(backend, "is_mount");
2222

23-
ok = fun(filepath);
23+
if isscalar(filepath)
24+
ok = fun(filepath);
25+
else
26+
ok = arrayfun(fun, filepath);
27+
end
2428

2529
end

+stdlib/is_prefix.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
% duplicated slashes are dropped
44

55
function s = is_prefix(prefix, pth)
6-
arguments
7-
prefix {mustBeTextScalar}
8-
pth {mustBeTextScalar}
9-
end
106

117
pr = stdlib.drop_slash(prefix);
128
p = stdlib.drop_slash(pth);
139

1410
Lp = strlength(p);
1511

16-
s = Lp && startsWith(p, pr) && (Lp >= strlength(pr));
12+
s = Lp & startsWith(p, pr) & (Lp >= strlength(pr));
1713

1814
end

+stdlib/is_regular_file.m

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
%% IS_REGULAR_FILE check if path is a regular file
22
% requires: java
33

4-
function r = is_regular_file(p)
5-
arguments
6-
p {mustBeTextScalar}
7-
end
8-
4+
function r = is_regular_file(file)
95
% needs absolute()
10-
p = stdlib.absolute(p, pwd());
6+
file = stdlib.absolute(file);
117

12-
op = javaPathObject(p);
13-
opt = javaMethod("values", "java.nio.file.LinkOption");
8+
op = javaPathObject(file);
9+
opt = java.nio.file.LinkOption.values();
1410

15-
r = javaMethod("isRegularFile", "java.nio.file.Files", op, opt);
11+
r = java.nio.file.Files.isRegularFile(op, opt);
1612

1713
end

0 commit comments

Comments
 (0)