{"id":27555242,"url":"https://github.com/juliaarrays/zerodimensionalarrays.jl","last_synced_at":"2025-06-24T13:03:37.822Z","repository":{"id":287170065,"uuid":"963835294","full_name":"JuliaArrays/ZeroDimensionalArrays.jl","owner":"JuliaArrays","description":"zero-dimensional array package for Julia","archived":false,"fork":false,"pushed_at":"2025-04-10T10:43:04.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-10T10:51:04.843Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JuliaArrays.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2025-04-10T09:28:36.000Z","updated_at":"2025-04-10T10:43:08.000Z","dependencies_parsed_at":"2025-04-10T11:01:36.498Z","dependency_job_id":null,"html_url":"https://github.com/JuliaArrays/ZeroDimensionalArrays.jl","commit_stats":null,"previous_names":["juliaarrays/zerodimensionalarrays.jl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaArrays%2FZeroDimensionalArrays.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaArrays%2FZeroDimensionalArrays.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaArrays%2FZeroDimensionalArrays.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaArrays%2FZeroDimensionalArrays.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JuliaArrays","download_url":"https://codeload.github.com/JuliaArrays/ZeroDimensionalArrays.jl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249742699,"owners_count":21318974,"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":"2025-04-19T16:52:54.614Z","updated_at":"2025-04-19T16:52:55.244Z","avatar_url":"https://github.com/JuliaArrays.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZeroDimensionalArrays\n\n[![Build Status](https://github.com/JuliaArrays/ZeroDimensionalArrays.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/JuliaArrays/ZeroDimensionalArrays.jl/actions/workflows/CI.yml?query=branch%3Amain)\n[![Package version](https://juliahub.com/docs/General/ZeroDimensionalArrays/stable/version.svg)](https://juliahub.com/ui/Packages/General/ZeroDimensionalArrays)\n[![Package dependencies](https://juliahub.com/docs/General/ZeroDimensionalArrays/stable/deps.svg)](https://juliahub.com/ui/Packages/General/ZeroDimensionalArrays?t=2)\n[![PkgEval](https://JuliaCI.github.io/NanosoldierReports/pkgeval_badges/Z/ZeroDimensionalArrays.svg)](https://JuliaCI.github.io/NanosoldierReports/pkgeval_badges/Z/ZeroDimensionalArrays.html)\n[![Aqua](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)\n\nA tiny software package for the Julia programming language, providing zero-dimensional array types. `Ref`-killer.\n\nExports these zero-dimensional subtypes of `AbstractArray`, differing on topics such as mutability and identity:\n* `ZeroDimArray`\n    * declared with `struct`, not with `mutable struct`\n    * does not support `setfield!`, or mutating the element otherwise\n    * `isbits` when the element is `isbits`\n* `Box`\n    * declared with `mutable struct`\n    * supports `setfield!` for mutating the element\n    * acts as a reference to its element\n* `BoxConst`\n    * declared with `mutable struct`\n    * does not support `setfield!`, or mutating the element otherwise\n    * acts as a reference to its element\n\nAny zero-dimensional array is an iterator containing exactly one element (this follows from the zero-dimensional shape). `Ref`, too, is a zero-dimensional iterator, however it's not an array. Even though `Ref` supports being indexed like a zero-dimensional array is commonly indexed, without an index: `x[]`.\n\nThe motivation for creating this package is:\n* To prevent the frequent confusion regarding `Ref` vs `Base.RefValue` by offering a replacement that makes `Ref` unnecessary in many use cases. Previous discussion:\n    * https://github.com/JuliaLang/julia/issues/38133\n    * https://github.com/JuliaLang/julia/issues/55321\n    * https://discourse.julialang.org/t/ref-is-not-a-concrete-type-poorly-documented/120375\n    * https://discourse.julialang.org/t/understanding-type-ref-t/107711\n    * https://discourse.julialang.org/t/ref-t-vs-base-refvalue-t/127886\n* To provide \"mutable wrapper\" functionality:\n    * `Box` can be a good choice. Examples:\n        * make a `const` binding that's mutable:\n          ```julia\n          const some_const_binding = Box(0.2)\n          ```\n        * make a field within an immutable `struct` mutable (warning: it's usually more efficient to change the entire `struct` into a `mutable struct`)\n          ```julia\n          struct SomeImmutableType\n              immutable_bool::Bool\n              immutable_float::Float64\n              mutable_int::Box{Int}\n          end\n          ```\n    * previous discussion:\n        * https://github.com/JuliaLang/julia/issues/40369\n        * https://discourse.julialang.org/t/dynamic-immutable-type/127168\n* To provide a [*boxing*](https://en.wikipedia.org/wiki/Boxing_(computer_programming)) feature, for example for data deduplication to avoid excessive memory use. Either `Box` or `BoxConst` might be a good choice here, depending on whether mutability is desired. Compare:\n    * ```julia-repl\n      julia\u003e large_data = ntuple(identity, 8)\n      (1, 2, 3, 4, 5, 6, 7, 8)\n\n      julia\u003e for _ ∈ 1:4\n                 large_data = (large_data, large_data)\n             end\n\n      julia\u003e Base.summarysize(large_data)\n      1024\n\n      julia\u003e Base.summarysize([large_data for _ ∈ 1:1000])  # duplicates `large_data` a thousand times\n      1024040\n\n      julia\u003e using ZeroDimensionalArrays\n\n      julia\u003e large_data_reference = Box(large_data);\n\n      julia\u003e Base.summarysize([large_data_reference for _ ∈ 1:1000])  # `large_data` isn't stored inline\n      9064\n      ```\n* To provide a wrapper type for treating a value as a scalar in broadcasting:\n    * `ZeroDimArray` can be a good choice:\n      ```julia-repl\n      julia\u003e using ZeroDimensionalArrays\n\n      julia\u003e isa.([1,2,3], [Array, Dict, Int])\n      3-element BitVector:\n       0\n       0\n       1\n\n      julia\u003e isa.(ZeroDimArray([1,2,3]), [Array, Dict, Int])  # now escape the vector from broadcasting using `ZeroDimArray`\n      3-element BitVector:\n       1\n       0\n       0\n      ```\n      The other types, `Box` or `BoxConst` would work for this use case, too, as would any zero-dimensional array, but `ZeroDimArray` is more likely to have zero cost for performance.\n    * previous discussion regarding `Ref`:\n        * https://discourse.julialang.org/t/ref-vs-zero-dimensional-arrays/24434\n\n## Comparison with other potential solutions\n\n* Zero-dimensional `Array`:\n    * `fill(x)`, creating a zero-dimensional `Array` containing `x` as its element, is often used instead of `Ref(x)`.\n    * `Array{T, 0} where {T}` is very similar to `Box`, albeit less efficient. The inefficiency is due to the fact that the implementation of `Array` supports resizeability (even though that's currently only available to users in the one-dimensional case of `Vector`), implying extra indirection, leading to extra pointer dereferences and extra allocation.\n* [FixedSizeArrays.jl](https://github.com/JuliaArrays/FixedSizeArrays.jl):\n    * Less heavy than `Array`, but still may be less efficient than `Box`.\n* [FillArrays.jl](https://github.com/JuliaArrays/FillArrays.jl):\n    * Zero-dimensional `Fill`, constructible with `Fill(x)`, is equivalent to `ZeroDimArray`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliaarrays%2Fzerodimensionalarrays.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliaarrays%2Fzerodimensionalarrays.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliaarrays%2Fzerodimensionalarrays.jl/lists"}