Skip to content

Commit

Permalink
h5save: check dataset vs shape if specified
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Oct 19, 2022
1 parent 1ad73dd commit 6ffc2d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
5 changes: 3 additions & 2 deletions +stdlib/+hdf5nc/private/defaultSize.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function s = defaultSize(A)

if isvector(A)
if isscalar(A)
s = 0;
elseif isvector(A)
s = length(A);
else
s = size(A);
Expand Down
6 changes: 5 additions & 1 deletion +stdlib/+hdf5nc/private/h5_exist_file.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ function h5_exist_file(filename, varname, A, sizeA)
diskshape = h5size(filename, varname);
if length(diskshape) >= 2
% start is always a row vector, regardless of shape of array
start = ones(1,ndims(A));
start = ones(1, ndims(A));
elseif ~isempty(diskshape)
start = 1;
end

if isempty(sizeA)
sizeA = defaultSize(A);
elseif all(sizeA > 0)
assert(numel(A) == prod(sizeA), 'hdf5nc:h5save:shape_error', "dataset # of elements %d != prod(sizeA) %d", numel(A), prod(sizeA))
elseif ~isscalar(sizeA)
error('hdf5nc:h5save:shape_error', "only scalar size may be 0")
end

if isscalar(A)
Expand Down
12 changes: 5 additions & 7 deletions +stdlib/+hdf5nc/private/h5_new_file.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
function h5_new_file(filename, varname, A, sizeA)

if isempty(sizeA)
if isscalar(A)
sizeA = 0;
elseif isvector(A)
sizeA = length(A);
else
sizeA = size(A);
end
sizeA = defaultSize(A);
elseif all(sizeA > 0)
assert(numel(A) == prod(sizeA), 'hdf5nc:h5save:shape_error', "dataset # of elements %d != prod(sizeA) %d", numel(A), prod(sizeA))
elseif ~isscalar(sizeA)
error('hdf5nc:h5save:shape_error', "only scalar size may be 0")
end

if isscalar(sizeA)
Expand Down

0 comments on commit 6ffc2d6

Please sign in to comment.