Skip to content

Commit 4210c6f

Browse files
committed
speedup and compatibility
1 parent 5a03508 commit 4210c6f

File tree

14 files changed

+80
-33
lines changed

14 files changed

+80
-33
lines changed

+stdlib/filename.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88
function f = filename(p, backend)
99
arguments
1010
p string
11-
backend = 'pattern'
11+
backend = 'fileparts'
1212
end
1313

14-
% the pattern backend is a few percent faster than regexp
14+
% the pattern backend is a litle slower than
15+
% fileparts is 5x to 10x faster than regexp and pattern
1516
switch backend
17+
case 'fileparts'
18+
[~, f, ext] = fileparts(p);
19+
f = f + ext;
1620
case 'pattern'
1721
f = extractAfter(p, asManyOfPattern(wildcardPattern + ("/" | filesep)));
1822
case 'regexp'
1923
f = regexp(p, ['[^/\' filesep ']*$'], 'match', 'once');
2024
f(ismissing(f)) = "";
21-
otherwise, error('must be backend "pattern" or "regexp"')
25+
otherwise, error('must be backend "pattern", "regexp" or "fileparts"')
2226
end
2327

2428
end

+stdlib/h5save.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function h5save(filename, varname, A, opts)
4242
h5save_exist(filename, varname, A, opts.size)
4343
catch e
4444
switch e.identifier
45-
case {'MATLAB:imagesci:hdf5io:resourceNotFound', 'MATLAB:imagesci:h5info:unableToFind'}
45+
case {'MATLAB:imagesci:hdf5io:resourceNotFound', 'MATLAB:imagesci:h5info:unableToFind', 'MATLAB:imagesci:h5info:fileOpenErr'}
4646
h5save_new(filename, varname, A, opts.size, opts.compressLevel)
4747
otherwise
4848
rethrow(e)

+stdlib/ini2struct.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
% Based on init2struct.m by Andriy Nych
55

66
function Struct = ini2struct(filename)
7-
arguments
8-
filename {mustBeFile}
9-
end
107

118
f = fopen(filename,'r'); % open file
129

+stdlib/platform_tell.m

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
function json = platform_tell()
44

5-
r = matlabRelease();
6-
raw = struct("matlab_release", r.Release, ...
5+
try
6+
r = matlabRelease().Release;
7+
catch
8+
r = "R" + version('-release');
9+
end
10+
11+
raw = struct("matlab_release", r, ...
712
"matlab_arch", computer('arch'), ...
813
"cpu_arch", stdlib.cpu_arch(), ...
914
"hdf5", stdlib.h5get_version(), ...
@@ -38,6 +43,14 @@
3843
end
3944
end
4045

41-
json = jsonencode(raw, "PrettyPrint", true);
46+
try
47+
json = jsonencode(raw, "PrettyPrint", true);
48+
catch e
49+
if e.identifier ~= "MATLAB:json:UnmatchedParameter"
50+
rethrow(e)
51+
end
52+
53+
json = jsonencode(raw);
54+
end
4255

4356
end

+stdlib/private/h5save_new.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ function h5save_new(filename, varname, A, sizeA, compressLevel)
2323
h5save_scalar(filename, varname, A)
2424
return
2525
else
26-
h5create(filename, varname, sizeA, Datatype=class(A))
26+
h5create(filename, varname, sizeA, 'Datatype', class(A))
2727
end
2828
elseif ~compressLevel || stdlib.isoctave()
29-
h5create(filename, varname, sizeA, Datatype=class(A))
29+
h5create(filename, varname, sizeA, 'Datatype', class(A))
3030
else
31-
h5create(filename, varname, sizeA, Datatype=class(A), Fletcher32=true, Shuffle=true, ...
32-
Chunksize=stdlib.auto_chunk_size(sizeA), ...
33-
Deflate=compressLevel)
31+
h5create(filename, varname, sizeA, 'Datatype', class(A), ...
32+
'Fletcher32', true, 'Shuffle', true, ...
33+
'Chunksize', stdlib.auto_chunk_size(sizeA), ...
34+
'Deflate', compressLevel)
3435
end
3536

3637
h5write(filename, varname, A)

+stdlib/set_permissions.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
function [ok, b] = set_permissions(file, readable, writable, executable, backend)
1414
arguments
1515
file (1,1) string
16-
readable (1,1) {mustBeInteger, mustBeInRange(readable, -1, 1)}
17-
writable (1,1) {mustBeInteger, mustBeInRange(writable, -1, 1)}
18-
executable (1,1) {mustBeInteger, mustBeInRange(executable, -1, 1)}
16+
readable (1,1) {mustBeInteger}
17+
writable (1,1) {mustBeInteger}
18+
executable (1,1) {mustBeInteger}
1919
backend (1,:) string = ["native", "legacy"]
2020
end
2121

test/TestHDF5.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function setup_file(tc)
4646

4747
stdlib.h5save(tc.file, '/A1', tc.A1)
4848
stdlib.h5save(tc.file, '/A2', tc.A2)
49-
stdlib.h5save(tc.file, '/A3', tc.A3, size=size(tc.A3))
49+
stdlib.h5save(tc.file, '/A3', tc.A3, 'size', size(tc.A3))
5050
stdlib.h5save(tc.file, '/A4', tc.A4)
5151

5252
if ~stdlib.matlabOlderThan("R2020b")

test/TestNetCDF.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function setup_file(tc)
5959
methods (Test, TestTags=["R2019b", "netcdf"])
6060

6161
function test_netcdf_version(tc)
62-
tc.verifyTrue(stdlib.version_atleast(stdlib.nc_get_version(), "4.7"), "version unexpected")
62+
tc.verifyTrue(stdlib.version_atleast(stdlib.nc_get_version(), "4.6"), "version unexpected")
6363
end
6464

6565
function test_get_variables(tc)

test/TestParent.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ function test_parent(tc, p, backend)
2323
tc.verifyEqual(pr, p{2}, sprintf("parent(%s, %s)", p{1}, backend))
2424
end
2525

26+
end
27+
28+
29+
methods (Test, TestTags=["R2020b", "pure"])
30+
2631
function test_parent_array(tc)
32+
tc.assumeFalse(stdlib.matlabOlderThan('R2020b'))
33+
2734
in = ["", ".", "..", "../..", "a/", "a/b", "ab/.parent", "ab/.parent.txt", "a/b/../.parent.txt"];
2835
exp = [".", ".", ".", "..", ".", "a", "ab", "ab", fullfile("a", "b", "..")];
2936

@@ -32,7 +39,6 @@ function test_parent_array(tc)
3239
end
3340

3441
end
35-
3642
end
3743

3844

test/TestStem.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ function test_stem(tc, p)
2828
tc.verifyEqual(stdlib.stem(p{1}), p{2})
2929
end
3030

31+
end
32+
33+
methods (Test, TestTags=["R2020b", "pure"])
34+
3135
function test_stem_array(tc)
36+
tc.assumeFalse(stdlib.matlabOlderThan('R2020b'))
3237
in = ["", ".txt", "a/b/c.txt", "a/b/c.txt.gz", "a/b/c"];
3338
exp = ["", ".txt", "c", "c.txt", "c"];
3439
out = stdlib.stem(in);

0 commit comments

Comments
 (0)