From 04dd43eedbdd8fc9fd6945c1958f0927b11c2ea6 Mon Sep 17 00:00:00 2001 From: Nathan Zimmerberg <39104088+nhz2@users.noreply.github.com> Date: Mon, 27 Nov 2023 12:01:23 -0500 Subject: [PATCH] Change saving order from F to C (#42) --- Project.toml | 4 ++-- src/loading.jl | 2 +- src/saving.jl | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 6e355e7..464b71e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SmallZarrGroups" uuid = "d423b6e5-1c84-4ae2-8d2d-b903aee15ac7" authors = ["nhz2 "] -version = "0.7.1" +version = "0.8.0" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" @@ -25,5 +25,5 @@ DataStructures = "0.18" JSON3 = "1" StructArrays = "0.6" TranscodingStreams = "0.9, 0.10" -ZipArchives = "0.3, 0.4, 0.5, 1" +ZipArchives = "1" julia = "1.8" diff --git a/src/loading.jl b/src/loading.jl index cd941db..5012141 100644 --- a/src/loading.jl +++ b/src/loading.jl @@ -108,7 +108,7 @@ function load_dir(reader::AbstractReader)::ZGroup end end - zarray = if metadata.is_column_major + zarray = if metadata.is_column_major || ndims(array) ≤ 1 ZArray(array; chunks = Tuple(chunks), compressor = metadata.compressor, diff --git a/src/saving.jl b/src/saving.jl index cbab9f9..35c3122 100644 --- a/src/saving.jl +++ b/src/saving.jl @@ -89,7 +89,8 @@ function _save_zarray(writer::AbstractWriter, key_prefix::String, z::ZArray) if zarr_size != 0 && !any(iszero, shape) chunks = Tuple(z.chunks) # store chunks - shaped_chunkdata = zeros(UInt8, zarr_size, chunks...) + shaped_chunkdata = zeros(UInt8, zarr_size, reverse(chunks)...) + permuted_shaped_chunkdata = PermutedDimsArray(shaped_chunkdata, (1, ndims(z)+1:-1:2...)) shaped_array = if dtype.julia_size == 1 reshape(reinterpret(reshape, UInt8, data), 1, shape...) else @@ -102,7 +103,7 @@ function _save_zarray(writer::AbstractWriter, key_prefix::String, z::ZArray) real_chunksize = chunkstop .- chunkstart .+ 1 # now create overlapping views array_view = view(shaped_array, :, (range.(chunkstart, chunkstop))...) - chunk_view = view(shaped_chunkdata, :, (range.(1, real_chunksize))...) + chunk_view = view(permuted_shaped_chunkdata, :, (range.(1, real_chunksize))...) # TODO check if the data can just be directly copied. for (zarr_byte, julia_byte) in enumerate(dtype.byteorder) selectdim(chunk_view, 1, zarr_byte) .= selectdim(array_view, 1, julia_byte) @@ -122,7 +123,7 @@ function _save_zarray(writer::AbstractWriter, key_prefix::String, z::ZArray) "dtype": $dtype_str, "fill_value": null, "filters": null, - "order": "F", + "order": "C", "shape": [$(join(shape, ", "))], "zarr_format": 2 }