{"id":17113034,"url":"https://github.com/emmt/structuredarrays.jl","last_synced_at":"2025-08-02T06:10:40.568Z","repository":{"id":61799653,"uuid":"256163145","full_name":"emmt/StructuredArrays.jl","owner":"emmt","description":"Structured arrays for Julia","archived":false,"fork":false,"pushed_at":"2025-03-14T22:30:35.000Z","size":251,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T22:34:47.088Z","etag":null,"topics":["arrays","julia-package"],"latest_commit_sha":null,"homepage":"","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-04-16T09:03:32.000Z","updated_at":"2025-03-14T22:11:05.000Z","dependencies_parsed_at":"2024-06-10T08:20:05.021Z","dependency_job_id":"e673004b-c6d4-4512-a6cd-b0dfb9ebc8b0","html_url":"https://github.com/emmt/StructuredArrays.jl","commit_stats":{"total_commits":71,"total_committers":1,"mean_commits":71.0,"dds":0.0,"last_synced_commit":"2308f259d03fdd07c589890045a8ff1df6e0380c"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FStructuredArrays.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FStructuredArrays.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FStructuredArrays.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FStructuredArrays.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emmt","download_url":"https://codeload.github.com/emmt/StructuredArrays.jl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248107880,"owners_count":21049026,"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":["arrays","julia-package"],"created_at":"2024-10-14T17:02:26.862Z","updated_at":"2025-04-09T20:33:48.499Z","avatar_url":"https://github.com/emmt.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Structured arrays for Julia\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`StructuredArrays` is a [Julia][julia-url] package which provides multi-dimensional arrays\nbehaving like regular arrays but whose elements have the same given value or are lazily\ncomputed by applying a given function to their indices. The main advantage of such arrays\nis that they are very light in terms of memory: their storage requirement is `O(1)`\nwhatever their size instead of `O(n)` for an ordinary array of `n` elements.\n\nNote that `StructuredArrays` has a different purpose than\n[`StructArrays`](https://github.com/JuliaArrays/StructArrays.jl) which is designed for\narrays whose elements are `struct`.\n\n\n## Installation\n\nTo install the latest stable release with Julia's package manager:\n\n``` julia\n] add StructuredArrays\n```\n\n\n## Uniform arrays\n\nAll elements of a uniform array have the same value. A uniform array thus require to only\nstore this value and the dimensions (or the axes) of the array. In addition, some\noperations (e.g., `minimum`, `maximum`, `extrema`, `all`, `any`, `sum`, `prod`, `count`,\n`findmin`, `findmax`, `reverse`, or `unique`) may be implemented so as to be very fast for\nuniform arrays.\n\nTo build a uniform array, call:\n\n```julia\nA = UniformArray(val, inds...)\n```\n\nwhich yields an array `A` behaving as a read-only array whose values are all `val` and\nwhose *shape* is defined by `inds...`. Each of `inds...` defines an array axis and can be\nan integer for a 1-based index or an integer-valued unit step range. It is thus possible\nto have offset axes as in the\n[`OffsetArrays`](https://github.com/JuliaArrays/OffsetArrays.jl) package.\n\nUniform arrays implement conventional linear indexing: `A[i]` yields `val` for all linear\nindices `i` in the range `1:length(A)`.\n\nThe statement `A[i] = x` is however not implemented because uniform arrays are considered\nas read-only. You may call `MutableUniformArray(val,dims)` to create a mutable uniform\narray. For example:\n\n```julia\nB = MutableUniformArray(val, inds...)\n```\n\nFor `B`, the statement `B[i] = x` is allowed to change the value of all the elements of\n`B` provided index `i` represents all possible indices in `B`. Typically `B[:] = x` or\n`B[1:end] = x` are accepted but not `B[1] = x`, unless `B` has a single element.\n\nApart from all values being the same, uniform arrays behave like ordinary Julia arrays.\n\nWhen calling a uniform array constructor, the element type `T` and the number of\ndimensions `N` may be specified. This is most useful for `T` to enforce a given element\ntype. By default, `T = typeof(val)` is assumed. For example:\n\n```julia\nA = UniformArray{T}(val, inds...)\nB = MutableUniformArray{T,N}(val, inds...)\n```\n\n\n## Fast uniform arrays\n\nA fast uniform array is like an immutable uniform array but with the value of all elements\nbeing part of the signature so that this value is known at compile time. To build such an\narray, call one of:\n\n```julia\nA = FastUniformArray(val, inds...)\nA = FastUniformArray{T}(val, inds...)\nA = FastUniformArray{T,N}(val, inds...)\n```\n\n\n## Structured arrays\n\nThe values of the elements of a structured array are computed on the fly as a function of\ntheir indices. To build such an array, call:\n\n```julia\nA = StructuredArray(func, inds...)\n```\n\nwhich yields a read-only array `A` whose value at index `i` is computed as `func(i)` and\nwhose *shape* is defined by `inds...`. In other words, `A[i]` yields `func(i)`.\n\nAn optional leading argument `S` may be used to specify another index style than the\ndefault `IndexCartesian`:\n\n```julia\nA = StructuredArray(S, func, inds...)\n```\n\nwhere `S` may be a sub-type of `IndexStyle` or an instance of such a sub-type. If `S` is\n`IndexCartesian` (the default), the function `func` will be called with `N` integer\narguments, a `Vararg{Int,N}`, `N` being the number of dimensions. If `S` is `IndexLinear`,\nthe function `func` will be called with a single integer argument, an `Int`.\n\nA structured array can be used to specify the location of structural non-zeros in a sparse\nmatrix. For instance, the structure of a lower triangular matrix of size `m×n` could be\ngiven by:\n\n```julia\nStructuredArray((i,j) -\u003e (i ≥ j), m, n)\n```\n\nbut with a constant small storage requirement whatever the size of the matrix.\n\nAlthough the callable object `func` may not be a *pure function*, its return type shall be\nstable and structured arrays are considered as immutable in the sense that a statement\nlike `A[i] = x` is not implemented. The type, say, `T` of the elements of structured array\nis inferred by applying `func` to the unit index or may be explicitly specified:\n\n```julia\nStructuredArray{T}(S, func, dims)\n```\n\nwhere, if omitted, `S = IndexCartesian` is assumed. The `StructuredArray` constructor also\nsupports the number of dimensions `N` and the indexing style `S` as optional type\nparameters. The two following examples are equivalent:\n\n```julia\nA = StructuredArray{T,N}(S, func, inds...)\nA = StructuredArray{T,N,S}(func, inds...)\n```\n\n\n## Cartesian meshes\n\nAs implemented in `StructuredArrays`, `N`-dimensional Cartesian meshes have equally spaced\nnodes with given **step** and **origin**. The mesh **step** is the spacing between\ncontiguous nodes, it may be different (in length and units) along the different dimensions\nof the mesh. The mesh **origin** is the index of the node whose coordinates are all equal\nto zero, this index has no units and may be fractional.\n\nThe coordinates of the node at Cartesian index `i = (i1,i2,...)` are formally given by:\n\n```julia\nstep .* i             # if `origin` is `nothing`\nstep .* (i .- origin) # else\n```\n\nwhich yields a `N`-tuple of coordinates. Thanks to broadcasting rules, each of `step` and\n`origin` may be specified as a scalar to assume that this parameter is the same for all\ndimensions, or as a `N`-tuple otherwise. `origin` may also be `nothing` (the default), to\nassume that the origin of the mesh is at index `(0,0,...)`. In the implementation, the\nexact formula used to compute the coordinates of the nodes is optimized for the different\npossible cases. As a consequence, specifying `origin` as `0` or as a `N`-tuple of `0`s\nyields a mesh with the same coordinates but computed with more overheads than with `origin\n= nothing`.\n\nThe values of `step` and `origin` stored by a mesh object `A` may be retrieved by calling\n`step(A)` or `origin(A)`. To retrieve a `N`-dimensional *step* or *origin* in all cases,\ncall `step(Tuple,A)` or `origin(Tuple,A)` instead.\n\n\n### Cartesian mesh as a function\n\nTo create a Cartesian mesh as a function, call:\n\n```julia\nmesh = CartesianMesh{N}(step, origin = nothing)\n```\n\nwhich yields a callable object such that `mesh(i1,i2,...)` generates the coordinates of\nthe node at `N`-dimensional index `(i1,i2,...)` according to the above formula. If any of\n`step` or `origin` is a `N`-tuple, the parameter `N` may be omitted. When calling the\nobject, the node indices may also be specified as a `N`-tuple or as a `CartesianIndex`.\n\nThe values of `step` and `origin` stored by a mesh are automatically converted at\nconstruction time to reduce the number of operations when computing coordinates. This\noptimization assumes that all indices are specified as `Int`s but fractional indices (i.e.\nreals) are also accepted.\n\n\n### Cartesian mesh as an array\n\nA typical usage is to wrap a Cartesian mesh function in a `StructuredArray` to build an\nabstract array whose values are the coordinates of the nodes of a finite size Cartesian\nmesh. For example:\n\n``` julia\nA = StructuredArray(CartesianMesh{N}(step, origin), inds...)\n```\n\nwith `inds...` the *shape* (indices and/or dimensions) of the mesh. This can also be done\nby calling:\n\n\n``` julia\nA = CartesianMeshArray(inds...; step, origin=nothing)\n```\n\nThen the syntax `A[i1,i2,...]` yields the coordinates of the node at index `(i1,i2,...)`.\nNode indices may also be specified as a tuple of `Int`s or as a `CartesianIndex`. The\ncoordinates are lazily computed and the storage is `O(1)`.\n\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/StructuredArrays.jl/actions/workflows/CI.yml/badge.svg?branch=master\n[github-ci-url]: https://github.com/emmt/StructuredArrays.jl/actions/workflows/CI.yml?query=branch%3Amaster\n\n[appveyor-img]: https://ci.appveyor.com/api/projects/status/github/emmt/StructuredArrays.jl?branch=master\n[appveyor-url]: https://ci.appveyor.com/project/emmt/StructuredArrays-jl/branch/master\n\n[codecov-img]: https://codecov.io/github/emmt/StructuredArrays.jl/graph/badge.svg?token=QhmKO7PmN1\n[codecov-url]: https://codecov.io/github/emmt/StructuredArrays.jl\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%2Fstructuredarrays.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femmt%2Fstructuredarrays.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmt%2Fstructuredarrays.jl/lists"}