Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions npy-matlab/readNPY.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
fid = fopen(filename, 'r', 'b');
end

ishalf = strcmp(dataType, 'half');
if ishalf; dataType = 'uint16'; end

try

[~] = fread(fid, totalHeaderLength, 'uint8');

% read the data
data = fread(fid, prod(shape), [dataType '=>' dataType]);
if ishalf; data = half.typecast(data); end
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: move this code outside of the try-catch body.


if length(shape)>1 && ~fortranOrder
data = reshape(data, shape(end:-1:1));
Expand Down
4 changes: 2 additions & 2 deletions npy-matlab/readNPYheader.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

try

dtypesMatlab = {'uint8','uint16','uint32','uint64','int8','int16','int32','int64','single','double', 'logical'};
dtypesNPY = {'u1', 'u2', 'u4', 'u8', 'i1', 'i2', 'i4', 'i8', 'f4', 'f8', 'b1'};
dtypesMatlab = {'uint8','uint16','uint32','uint64','int8','int16','int32','int64','half','single','double','logical'};
dtypesNPY = {'u1', 'u2', 'u4', 'u8', 'i1', 'i2', 'i4', 'i8', 'f2', 'f4', 'f8', 'b1'};


magicString = fread(fid, [1 6], 'uint8=>uint8');
Expand Down