Skip to content

Commit 223a650

Browse files
fangqclaude
andcommitted
[easyh5] sync the loadh5 fix for transposed complex and sparse arrays
saveh5 transposes an array before writing and then derives the Real/Imag parts and SparseIndex from the transposed matrix, while loadh5 only undid the transpose for values that came back numeric. Complex and sparse data arrive as a compound type, so they were returned transposed - for a non-symmetric sparse matrix that is silent data corruption. Fixed upstream in easyh5, their home. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 43b3fd0 commit 223a650

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎loadh5.m‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,15 @@
234234
if ((isnumeric(sub_data) && inputdata.opt.dotranspose) || (iscell(sub_data) && length(sub_data) > 1))
235235
sub_data = permute(sub_data, ndims(sub_data):-1:1);
236236
end
237+
wascompound = isstruct(sub_data);
237238
sub_data = fix_data(sub_data, attr, inputdata.opt);
239+
if (wascompound && isnumeric(sub_data) && inputdata.opt.dotranspose)
240+
% complex and sparse arrays are transposed by saveh5 before their
241+
% Real/Imag parts and SparseIndex are computed, so they reach this
242+
% point as a compound type and miss the transpose applied above;
243+
% undo it now that fix_data has rebuilt the numeric array
244+
sub_data = permute(sub_data, ndims(sub_data):-1:1);
245+
end
238246
if (encodename)
239247
name = encodevarname(name);
240248
else

0 commit comments

Comments
 (0)