|
279 | 279 | end |
280 | 280 | ndata = typecast(allbytes, arraytype); |
281 | 281 | else |
282 | | - % N-D chunked decode: iterate 1D row-major cell, fill tiles directly |
283 | | - arrsize = double(data(j).(N_ArrayZipSize)); |
284 | | - ndim = numel(arrsize); |
285 | | - nchunks_nd = ceil(arrsize ./ chunkshape); |
286 | | - ntiles = prod(nchunks_nd); |
287 | | - iscpx_arr = isfield(data, N_ArrayIsComplex) && data(j).(N_ArrayIsComplex); |
288 | | - if (iscpx_arr) |
289 | | - ndata = complex(cast(zeros(arrsize), arraytype)); |
290 | | - else |
291 | | - ndata = cast(zeros(arrsize), arraytype); |
292 | | - end |
293 | | - tidx = cell(1, ndim); |
294 | | - for ci = 1:ntiles |
295 | | - [tidx{:}] = ind2sub(nchunks_nd, ci); |
296 | | - chunkblob = uint8(chunks_cell{ci}(:)'); |
297 | | - if (needbase64 && ~strcmp(zipmethod, 'base64')) |
298 | | - chunkblob = base64decode(chunkblob); |
| 282 | + % N-D chunked decode: two modes depending on array type. |
| 283 | + % Dense: _ArrayChunks_ is in _ArraySize_ (original) order; |
| 284 | + % tiles the row-major permuted intermediate. |
| 285 | + % Non-dense (sparse/shaped): _ArrayChunks_ is in _ArrayZipSize_ order; |
| 286 | + % tiles the logical processed array. |
| 287 | + isdense_chunk = ~(isfield(data, N_ArrayIsSparse) && data(j).(N_ArrayIsSparse)) && ~isfield(data, N_ArrayShape); |
| 288 | + if (isdense_chunk) |
| 289 | + origsize = double(data(j).(N_ArraySize)(:)'); % e.g. [3,4,5] |
| 290 | + ndim = numel(origsize); |
| 291 | + chunkshape_perm = fliplr(chunkshape); % permuted-space chunk |
| 292 | + arrsize_perm = fliplr(origsize); % e.g. [5,4,3] |
| 293 | + chunkshape_perm(end + 1:ndim) = arrsize_perm(numel(chunkshape_perm) + 1:end); |
| 294 | + chunkshape_perm = min(chunkshape_perm, arrsize_perm); |
| 295 | + nchunks_nd = ceil(arrsize_perm ./ chunkshape_perm); |
| 296 | + ntiles = prod(nchunks_nd); |
| 297 | + iscpx_arr = isfield(data, N_ArrayIsComplex) && data(j).(N_ArrayIsComplex); |
| 298 | + if (iscpx_arr) |
| 299 | + ndata = complex(cast(zeros(arrsize_perm), arraytype)); |
| 300 | + else |
| 301 | + ndata = cast(zeros(arrsize_perm), arraytype); |
299 | 302 | end |
300 | | - rawchunk = typecast(decompfun(chunkblob, decodeparam{:}), arraytype); |
301 | | - ranges = cell(1, ndim); |
302 | | - tilesize = zeros(1, ndim); |
303 | | - for d = 1:ndim |
304 | | - r1 = (tidx{d} - 1) * chunkshape(d) + 1; |
305 | | - r2 = min(tidx{d} * chunkshape(d), arrsize(d)); |
306 | | - ranges{d} = r1:r2; |
307 | | - tilesize(d) = r2 - r1 + 1; |
| 303 | + tidx = cell(1, ndim); |
| 304 | + for ci = 1:ntiles |
| 305 | + [tidx{:}] = ind2sub(nchunks_nd, ci); |
| 306 | + chunkblob = uint8(chunks_cell{ci}(:)'); |
| 307 | + if (needbase64 && ~strcmp(zipmethod, 'base64')) |
| 308 | + chunkblob = base64decode(chunkblob); |
| 309 | + end |
| 310 | + rawchunk = typecast(decompfun(chunkblob, decodeparam{:}), arraytype); |
| 311 | + ranges = cell(1, ndim); |
| 312 | + tilesize = zeros(1, ndim); |
| 313 | + for d = 1:ndim |
| 314 | + r1 = (tidx{d} - 1) * chunkshape_perm(d) + 1; |
| 315 | + r2 = min(tidx{d} * chunkshape_perm(d), arrsize_perm(d)); |
| 316 | + ranges{d} = r1:r2; |
| 317 | + tilesize(d) = r2 - r1 + 1; |
| 318 | + end |
| 319 | + if (iscpx_arr) |
| 320 | + half = numel(rawchunk) / 2; |
| 321 | + ndata(ranges{:}) = complex(reshape(rawchunk(1:half), tilesize), ... |
| 322 | + reshape(rawchunk(half + 1:end), tilesize)); |
| 323 | + else |
| 324 | + ndata(ranges{:}) = reshape(rawchunk, tilesize); |
| 325 | + end |
308 | 326 | end |
| 327 | + % Flatten assembled permuted array to row for downstream processing |
309 | 328 | if (iscpx_arr) |
310 | | - half = numel(rawchunk) / 2; |
311 | | - ndata(ranges{:}) = complex(reshape(rawchunk(1:half), tilesize), ... |
312 | | - reshape(rawchunk(half + 1:end), tilesize)); |
| 329 | + ndata = [real(ndata(:))', imag(ndata(:))']; |
| 330 | + data(j).(N_ArrayZipSize) = [2, numel(ndata) / 2]; |
313 | 331 | else |
314 | | - ndata(ranges{:}) = reshape(rawchunk, tilesize); |
| 332 | + ndata = ndata(:).'; |
| 333 | + data(j).(N_ArrayZipSize) = [1, numel(ndata)]; |
315 | 334 | end |
316 | | - end |
317 | | - if (iscpx_arr) |
318 | | - ndata = [real(ndata(:))', imag(ndata(:))']; |
| 335 | + dims = data(j).(N_ArrayZipSize); |
319 | 336 | else |
320 | | - ndata = ndata(:).'; |
| 337 | + % Non-dense: tile logical _ArrayZipSize_ shape; keep ZipSize unchanged. |
| 338 | + zipsize = double(data(j).(N_ArrayZipSize)(:)'); % e.g. [3,K] sparse |
| 339 | + ndim = numel(zipsize); |
| 340 | + chunkshape_nd = chunkshape; |
| 341 | + chunkshape_nd(end + 1:ndim) = zipsize(numel(chunkshape_nd) + 1:end); |
| 342 | + chunkshape_nd = min(chunkshape_nd, zipsize); |
| 343 | + nchunks_nd = ceil(zipsize ./ chunkshape_nd); |
| 344 | + ntiles = prod(nchunks_nd); |
| 345 | + ndata = cast(zeros(zipsize), arraytype); |
| 346 | + tidx = cell(1, ndim); |
| 347 | + for ci = 1:ntiles |
| 348 | + [tidx{:}] = ind2sub(nchunks_nd, ci); |
| 349 | + chunkblob = uint8(chunks_cell{ci}(:)'); |
| 350 | + if (needbase64 && ~strcmp(zipmethod, 'base64')) |
| 351 | + chunkblob = base64decode(chunkblob); |
| 352 | + end |
| 353 | + rawchunk = typecast(decompfun(chunkblob, decodeparam{:}), arraytype); |
| 354 | + ranges = cell(1, ndim); |
| 355 | + tilesize = zeros(1, ndim); |
| 356 | + for d = 1:ndim |
| 357 | + r1 = (tidx{d} - 1) * chunkshape_nd(d) + 1; |
| 358 | + r2 = min(tidx{d} * chunkshape_nd(d), zipsize(d)); |
| 359 | + ranges{d} = r1:r2; |
| 360 | + tilesize(d) = r2 - r1 + 1; |
| 361 | + end |
| 362 | + ndata(ranges{:}) = reshape(rawchunk, tilesize); |
| 363 | + end |
| 364 | + % Re-flatten to "rows-concatenated" format for downstream ZipSize block |
| 365 | + ndata = permute(ndata, ndim:-1:1); |
| 366 | + ndata = ndata(:)'; |
| 367 | + % _ArrayZipSize_ stays unchanged; dims already set from line 236 |
321 | 368 | end |
322 | 369 | end |
323 | | - % Restore ZipSize for downstream complex reconstruction |
324 | | - if (isfield(data, N_ArrayIsComplex) && data(j).(N_ArrayIsComplex)) |
325 | | - data(j).(N_ArrayZipSize) = [2, numel(ndata) / 2]; |
326 | | - else |
327 | | - data(j).(N_ArrayZipSize) = [1, numel(ndata)]; |
328 | | - end |
329 | | - dims = data(j).(N_ArrayZipSize); |
330 | 370 | elseif (needbase64 && strcmp(zipmethod, 'base64') == 0) |
331 | 371 | ndata = reshape(typecast(decompfun(base64decode(data(j).(N_ArrayZipData)), decodeparam{:}), arraytype), dims); |
332 | 372 | else |
|
0 commit comments