{"id":17113005,"url":"https://github.com/emmt/zippedarrays.jl","last_synced_at":"2025-06-30T02:36:55.034Z","repository":{"id":61800131,"uuid":"309803865","full_name":"emmt/ZippedArrays.jl","owner":"emmt","description":"Zipping Julia arrays together","archived":false,"fork":false,"pushed_at":"2024-05-02T16:50:17.000Z","size":49,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-29T14:25:17.894Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emmt.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-03T20:50:18.000Z","updated_at":"2025-04-16T20:43:17.000Z","dependencies_parsed_at":"2024-01-27T00:28:42.875Z","dependency_job_id":"a3f122a7-5231-4056-b537-08c455ed7d5b","html_url":"https://github.com/emmt/ZippedArrays.jl","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/emmt/ZippedArrays.jl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FZippedArrays.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FZippedArrays.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FZippedArrays.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FZippedArrays.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emmt","download_url":"https://codeload.github.com/emmt/ZippedArrays.jl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FZippedArrays.jl/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262699849,"owners_count":23350386,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T17:02:17.813Z","updated_at":"2025-06-30T02:36:55.005Z","avatar_url":"https://github.com/emmt.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zipping Julia arrays together\n\n[![License][license-img]][license-url]\n[![Build Status][github-ci-img]][github-ci-url]\n[![Build Status][appveyor-img]][appveyor-url]\n[![Coverage][codecov-img]][codecov-url]\n\n`ZippedArrays` is a [Julia][julia-url] package to zip several (abstract) arrays\ntogether for accessing their elements simultaneously. For instance, assuming\nthat `A`, `B` and `C` are 3 Julia arrays, then:\n\n```julia\nusing ZippedArrays\nZ = ZippedArray(A,B,C)\n```\n\nbuilds a zipped array instance `Z` such that the syntax `Z[i]` yields the\n3-tuple `(A[i],B[i],C[i])` while the syntax `Z[i] = (a,b,c)` is equivalent to\n`(A[i],B[i],C[i]) = (a,b,c)`.\n\nAny number of arrays can be zipped together, they must however have the same\nindices (as returned by the `axes` method).\n\nTo build an uninitialized zipped array of size `dims` whose elements are tuples\nof items of types `T1`, `T2`, etc., call:\n\n```julia\nZ = ZippedArray{Tuple{T1,T2,...}}(undef, dims)\n```\n\nFor example:\n\n```julia\nZ = ZippedArray{Tuple{Int,Float64}}(undef, 2, 3, 4)\n```\n\nbuilds a 3-dimensional array of size `(2,3,4)` and whose elements are 2-tuples\nof type `Tuple{Int,Float64}`.\n\nElement type of a zipped array can also be a structure type. For example:\n\n```julia\nZ = ZippedArray{Complex{Float32}}(undef, dims)\n```\n\ncreates an uninitialized array of `Complex{Float32}` elements, of size `dims`,\nand such that the real and imaginary parts are stored into two separate arrays.\nAs another example:\n\n```julia\nZ = ZippedArray{Complex{Float32}}(A, B))\n```\n\nwraps arrays `A` and `B` into an abstract array of `Complex{Float32}` elements,\nof same size as `A` and `B` and such that `Z[i]` yields\n`Complex{Float32}(A[i],B[i])`.\n\nA zipped array, say `A::ZippedArray{T,N}`, enforces the type of the returned\nelements by calling `convert(T, x)` with `x` the tuple of values and if `T` is\na tuple type, or by calling the constructor `T(x...)` if `T` is not a tuple\ntype. This guarantees the type of the returned elements with no speed penalties\nwhen `x` needs no conversion. This can be also exploited to perform lazy\nconversion (in the above example `A` and `B` may have other element type than\n`Float32`). If the type `T` has no constructor matching the syntax `T(x...)`,\nthe method `ZippedArrays.build(::Type{T}, x)` can be specialized to yield an\nobject of type `T` whose fields are given by the tuple of values `x`.\n\nCompared to the `zip` function which only provides means to iterate through its\narguments, a zipped array can be accessed in random order and for reading and\nwriting. This makes zipped arrays useful for in-place multi-key sorting. For\ninstance:\n\n```julia\nsort!(ZippedArray(A,B);\n      lt = (x,y) -\u003e ifelse(x[1] == y[1], x[2] \u003c y[2], x[1] \u003c y[1]))\n```\n\nwill sort in-place vectors `A` and `B` such that the values in `A` are in\nincreasing order and, in case of equality, the values in `B` are in increasing\norder.\n\nA zipped array is a simple immutable structure wrapped around the arguments of\n`ZippedArray` so zipped arrays are almost costless to build. Below is an\nexample of how to build an array `C` whose elements are pairs of values from\n`A` and `B` and a zipped array `Z` also built from `A` and `B`:\n\n```julia\nusing ZippedArrays\nn = 10_000\nA = rand(Float64, n)\nB = rand(Int64, n)\nC = [(A[i],B[i]) for i in 1:n]\nZ = ZippedArray(A,B)\nC == Z # yields true\n```\n\nThe comparison `C == Z` shows that the two arrays are virtually the same\n(although not the same object, that is `C !== Z`). Building `Z` however\nrequires no copy of array elements and hardly requires additional memory, the\nsizes of `Z` and `C` are indeed quite different:\n\n```julia\njulia\u003e sizeof(Z)\n16\n\njulia\u003e sizeof(C)\n160000\n```\n\nThese numbers may depend on the architecture (here a 64-bit processor).\n\nThanks to the in-lining of functions and optimizations, a zipped array may also\nbe faster. For instance, with the arrays `C` and `Z` defined above:\n\n```julia\nusing BenchmarkTools\nfunction sum_first(A::AbstractArray{\u003c:Tuple})\n    s = 0.0\n    @inbounds @simd for i in eachindex(A)\n        s += first(A[i])\n    end\n    return s\nend\n@btime sum_first($C) # 1.615 μs (0 allocations: 0 bytes)\n@btime sum_first($Z) # 643.983 ns (0 allocations: 0 bytes)\n```\n\n[doc-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg\n[doc-stable-url]: https://emmt.github.io/ZippedArrays.jl/stable\n\n[doc-dev-img]: https://img.shields.io/badge/docs-dev-blue.svg\n[doc-dev-url]: https://emmt.github.io/ZippedArrays.jl/dev\n\n[license-url]: ./LICENSE.md\n[license-img]: http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat\n\n[github-ci-img]: https://github.com/emmt/ZippedArrays.jl/actions/workflows/CI.yml/badge.svg?branch=master\n[github-ci-url]: https://github.com/emmt/ZippedArrays.jl/actions/workflows/CI.yml?query=branch%3Amaster\n\n[appveyor-img]: https://ci.appveyor.com/api/projects/status/github/emmt/ZippedArrays.jl?branch=master\n[appveyor-url]: https://ci.appveyor.com/project/emmt/ZippedArrays-jl/branch/master\n\n[codecov-img]: http://codecov.io/github/emmt/ZippedArrays.jl/coverage.svg?branch=master\n[codecov-url]: http://codecov.io/github/emmt/ZippedArrays.jl?branch=master\n\n[julia-url]: https://julialang.org/\n[julia-pkgs-url]: https://pkg.julialang.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmt%2Fzippedarrays.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femmt%2Fzippedarrays.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmt%2Fzippedarrays.jl/lists"}