Skip to content

Commit

Permalink
coerce_ds: float32=>single, float64=>double
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed May 19, 2022
1 parent e67dcc0 commit 4043432
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 7 additions & 1 deletion +stdlib/+hdf5nc/private/coerce_ds.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
return
end

if dtype == "float64"
dtype = "double";
elseif dtype == "float32"
dtype = "single";
end

switch dtype
case ""
return
case {'float64', 'double', 'float32', 'single', 'int8', 'int16', 'int32', 'int64','uint8', 'uint16', 'uint32', 'uint64'}
case {'double', 'single', 'int8', 'int16', 'int32', 'int64','uint8', 'uint16', 'uint32', 'uint64'}
A = cast(A, dtype);
case 'char'
A = string(A);
Expand Down
14 changes: 12 additions & 2 deletions +stdlib/TestHDF5.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
end

properties (TestParameter)
type = {'single', 'double', 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64'}
type = {'single', 'double', 'float32', 'float64', ...
'int8', 'int16', 'int32', 'int64', ...
'uint8', 'uint16', 'uint32', 'uint64'}
vars = {'A0', 'A1', 'A2', 'A3', 'A4'}
str = {"string", 'char'}
end
Expand Down Expand Up @@ -224,7 +226,15 @@ function test_coerce(tc, type)

tc.assumeThat(basic, IsFile)

tc.verifyClass(h5read(basic, vn), type)
if type == "float32"
vtype = "single";
elseif type == "float64"
vtype = "double";
else
vtype = type;
end

tc.verifyClass(h5read(basic, vn), vtype)
end


Expand Down

0 comments on commit 4043432

Please sign in to comment.