Skip to content

Commit c6f444d

Browse files
committed
[h5,nc]ndims: improve validation, speed test
1 parent a9a1a35 commit c6f444d

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

+stdlib/+hdf5nc/h5ndims.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111

1212
arguments
1313
file (1,1) string {mustBeFile}
14-
variable (1,1) string {mustBeNonzeroLengthText}
14+
variable string {mustBeScalarOrEmpty}
15+
end
16+
17+
if isempty(variable) || strlength(variable) == 0
18+
frank = [];
19+
return
1520
end
1621

1722
dsi = h5info(stdlib.fileio.expanduser(file), variable).Dataspace;

+stdlib/+hdf5nc/h5size.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
% variable: name of variable inside file
88
%
99
%%% Outputs
10-
% fsize: vector of variable size per dimension
10+
% fsize: vector of variable size per dimension. Empty if scalar variable.
1111

1212
arguments
1313
file (1,1) string {mustBeFile}

+stdlib/+hdf5nc/ncndims.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111

1212
arguments
1313
file (1,1) string {mustBeFile}
14-
variable (1,1) string {mustBeNonzeroLengthText}
14+
variable string {mustBeScalarOrEmpty}
15+
end
16+
17+
if isempty(variable) || strlength(variable) == 0
18+
frank = [];
19+
return
1520
end
1621

1722
dsi = ncinfo(stdlib.fileio.expanduser(file), variable);

+stdlib/+hdf5nc/ncsize.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
% variable: name of variable inside file
88
%
99
%%% Outputs
10-
% fsize: vector of variable size per dimension
10+
% fsize: vector of variable size per dimension. Empty if scalar variable.
1111

1212
arguments
1313
file (1,1) string {mustBeFile}

+stdlib/+test/TestHDF5.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ function test_size(tc)
130130
import stdlib.hdf5nc.h5ndims
131131
basic = tc.TestData.basic;
132132

133+
tc.verifyEmpty(h5ndims(basic, string.empty))
134+
tc.verifyEmpty(h5ndims(basic, ""))
135+
133136
if ~verLessThan('matlab', '9.8')
134137
r = h5ndims(basic, '/A0');
135138
s = h5size(basic, '/A0');

+stdlib/+test/TestNetCDF.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ function test_size(tc)
118118
import matlab.unittest.constraints.IsScalar
119119
basic = tc.TestData.basic;
120120

121+
tc.verifyEmpty(ncndims(basic, string.empty))
122+
tc.verifyEmpty(ncndims(basic, ""))
123+
121124
r = ncndims(basic, 'A0');
122125
s = ncsize(basic, 'A0');
123126
tc.verifyEmpty(s)

0 commit comments

Comments
 (0)