{"id":19093696,"url":"https://github.com/juliaarrays/mappedarrays.jl","last_synced_at":"2026-01-27T19:04:55.398Z","repository":{"id":39613484,"uuid":"61634088","full_name":"JuliaArrays/MappedArrays.jl","owner":"JuliaArrays","description":"Lazy in-place transformations of arrays","archived":false,"fork":false,"pushed_at":"2024-04-08T07:55:56.000Z","size":66,"stargazers_count":88,"open_issues_count":12,"forks_count":17,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-20T19:57:40.523Z","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/JuliaArrays.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2016-06-21T13:00:35.000Z","updated_at":"2024-10-24T06:52:05.000Z","dependencies_parsed_at":"2024-01-22T10:04:27.064Z","dependency_job_id":"89703ba6-01eb-470e-97de-ae2ecc982b93","html_url":"https://github.com/JuliaArrays/MappedArrays.jl","commit_stats":{"total_commits":51,"total_committers":13,"mean_commits":3.923076923076923,"dds":"0.33333333333333337","last_synced_commit":"5da1e79bbf28b6c971402e383f91d0b414265114"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaArrays%2FMappedArrays.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaArrays%2FMappedArrays.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaArrays%2FMappedArrays.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaArrays%2FMappedArrays.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JuliaArrays","download_url":"https://codeload.github.com/JuliaArrays/MappedArrays.jl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240142863,"owners_count":19754640,"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-11-09T03:25:45.100Z","updated_at":"2026-01-27T19:04:50.341Z","avatar_url":"https://github.com/JuliaArrays.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MappedArrays\n\n[![CI](https://github.com/JuliaArrays/MappedArrays.jl/workflows/CI/badge.svg)](https://github.com/JuliaArrays/MappedArrays.jl/actions?query=workflow%3ACI)\n[![codecov.io](http://codecov.io/github/JuliaArrays/MappedArrays.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaArrays/MappedArrays.jl?branch=master)\n\nThis package implements \"lazy\" in-place elementwise transformations of\narrays for the Julia programming language. Explicitly, it provides a\n\"view\" `M` of an array `A` so that `M[i] = f(A[i])` for a specified\n(but arbitrary) function `f`, without ever having to compute `M`\nexplicitly (in the sense of allocating storage for `M`).  The name of\nthe package comes from the fact that `M == map(f, A)`.\n\n## Usage\n\n### Single source arrays\n\n```jl\njulia\u003e using MappedArrays\n\njulia\u003e a = [1,4,9,16]\n4-element Array{Int64,1}:\n  1\n  4\n  9\n 16\n\njulia\u003e b = mappedarray(sqrt, a)\n4-element mappedarray(sqrt, ::Array{Int64,1}) with eltype Float64:\n 1.0\n 2.0\n 3.0\n 4.0\n\njulia\u003e b[3]\n3.0\n```\n\nNote that you can't set values in the array:\n\n```jl\njulia\u003e b[3] = 2\nERROR: setindex! not defined for ReadonlyMappedArray{Float64,1,Array{Int64,1},typeof(sqrt)}\nStacktrace:\n [1] error(::String, ::Type) at ./error.jl:42\n [2] error_if_canonical_setindex at ./abstractarray.jl:1005 [inlined]\n [3] setindex!(::ReadonlyMappedArray{Float64,1,Array{Int64,1},typeof(sqrt)}, ::Int64, ::Int64) at ./abstractarray.jl:996\n [4] top-level scope at none:0\n```\n\n**unless** you also supply the inverse function, using `mappedarray(f, finv, A)`:\n\n```\njulia\u003e c = mappedarray(sqrt, x-\u003ex*x, a)\n4-element mappedarray(sqrt, x-\u003ex * x, ::Array{Int64,1}) with eltype Float64:\n 1.0\n 2.0\n 3.0\n 4.0\n\njulia\u003e c[3]\n3.0\n\njulia\u003e c[3] = 2\n2\n\njulia\u003e a\n4-element Array{Int64,1}:\n  1\n  4\n  4\n 16\n```\n\nNaturally, the \"backing\" array `a` has to be able to represent any value that you set:\n\n```jl\njulia\u003e c[3] = 2.2\nERROR: InexactError: Int64(Int64, 4.840000000000001)\nStacktrace:\n [1] Type at ./float.jl:692 [inlined]\n [2] convert at ./number.jl:7 [inlined]\n [3] setindex! at ./array.jl:743 [inlined]\n [4] setindex!(::MappedArray{Float64,1,Array{Int64,1},typeof(sqrt),getfield(Main, Symbol(\"##5#6\"))}, ::Float64, ::Int64) at /home/tim/.julia/dev/MappedArrays/src/MappedArrays.jl:173\n [5] top-level scope at none:0\n```\n\nbecause `2.2^2 = 4.84` is not representable as an `Int`. In contrast,\n\n```jl\njulia\u003e a = [1.0, 4.0, 9.0, 16.0]\n4-element Array{Float64,1}:\n  1.0\n  4.0\n  9.0\n 16.0\n\njulia\u003e c = mappedarray(sqrt, x-\u003ex*x, a)\n4-element mappedarray(sqrt, x-\u003ex * x, ::Array{Float64,1}) with eltype Float64:\n 1.0\n 2.0\n 3.0\n 4.0\n\njulia\u003e c[3] = 2.2\n2.2\n\njulia\u003e a\n4-element Array{Float64,1}:\n  1.0\n  4.0\n  4.840000000000001\n 16.0\n```\n\nworks without trouble.\n\nSo far our examples have all been one-dimensional, but this package\nalso supports arbitrary-dimensional arrays:\n\n```jl\njulia\u003e a = randn(3,5,2)\n3×5×2 Array{Float64,3}:\n[:, :, 1] =\n  1.47716    0.323915   0.448389  -0.56426   2.67922\n -0.255123  -0.752548  -0.41303    0.306604  1.5196\n  0.154179   0.425001  -1.95575   -0.982299  0.145111\n\n[:, :, 2] =\n -0.799232  -0.301813  -0.457817  -0.115742  -1.22948\n -0.486558  -1.27959   -1.59661    1.05867    2.06828\n -0.315976  -0.188828  -0.567672   0.405086   1.06983\n\njulia\u003e b = mappedarray(abs, a)\n3×5×2 mappedarray(abs, ::Array{Float64,3}) with eltype Float64:\n[:, :, 1] =\n 1.47716   0.323915  0.448389  0.56426   2.67922\n 0.255123  0.752548  0.41303   0.306604  1.5196\n 0.154179  0.425001  1.95575   0.982299  0.145111\n\n[:, :, 2] =\n 0.799232  0.301813  0.457817  0.115742  1.22948\n 0.486558  1.27959   1.59661   1.05867   2.06828\n 0.315976  0.188828  0.567672  0.405086  1.06983\n```\n\n### Multiple source arrays\n\nJust as `map(f, a, b)` can take multiple containers `a` and `b`, `mappedarray` can too:\n```julia\njulia\u003e a = [0.1 0.2; 0.3 0.4]\n2×2 Array{Float64,2}:\n 0.1  0.2\n 0.3  0.4\n\njulia\u003e b = [1 2; 3 4]\n2×2 Array{Int64,2}:\n 1  2\n 3  4\n\njulia\u003e c = mappedarray(+, a, b)\n2×2 mappedarray(+, ::Array{Float64,2}, ::Array{Int64,2}) with eltype Float64:\n 1.1  2.2\n 3.3  4.4\n```\n\nIn some cases you can also supply an inverse function, which should return a tuple (one value for each input array):\n```julia\njulia\u003e using ColorTypes\n\njulia\u003e redchan = [0.1 0.2; 0.3 0.4];\n\njulia\u003e greenchan = [0.8 0.75; 0.7 0.65];\n\njulia\u003e bluechan = [0 1; 0 1];\n\njulia\u003e m = mappedarray(RGB{Float64}, c-\u003e(red(c), green(c), blue(c)), redchan, greenchan, bluechan)\n2×2 mappedarray(RGB{Float64}, getfield(Main, Symbol(\"##11#12\"))(), ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Int64,2}) with eltype RGB{Float64}:\n RGB{Float64}(0.1,0.8,0.0)  RGB{Float64}(0.2,0.75,1.0)\n RGB{Float64}(0.3,0.7,0.0)  RGB{Float64}(0.4,0.65,1.0)\n\n julia\u003e m[1,2] = RGB(0,0,0)\nRGB{N0f8}(0.0,0.0,0.0)\n\njulia\u003e redchan\n2×2 Array{Float64,2}:\n 0.1  0.0\n 0.3  0.4\n```\n\nNote that in some cases the function or inverse-function is too\ncomplicated to print nicely in the summary line.\n\n### of_eltype\n\nThis package defines a convenience method, `of_eltype`, which\n\"lazily-converts\" arrays to a specific `eltype`.  (It works simply by\ndefining `convert` functions for both `f` and `finv`.)\n\nUsing `of_eltype` you can \"convert\" a series of arrays to a chosen element type:\n\n```julia\njulia\u003e arrays = (rand(2,2), rand(Int,2,2), [0x01 0x03; 0x02 0x04])\n([0.984799 0.871579; 0.106783 0.0619827], [-6481735407318330164 5092084295348224098; -6063116549749853620 -8721118838052351006], UInt8[0x01 0x03; 0x02 0x04])\n\njulia\u003e arraysT = map(A-\u003eof_eltype(Float64, A), arrays)\n([0.984799 0.871579; 0.106783 0.0619827], [-6.48174e18 5.09208e18; -6.06312e18 -8.72112e18], [1.0 3.0; 2.0 4.0])\n```\n\nThis construct is inferrable (type-stable), so it can be a useful\nmeans to \"coerce\" arrays to a common type. This can sometimes solve\ntype-stability problems without requiring that one copy the data.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliaarrays%2Fmappedarrays.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliaarrays%2Fmappedarrays.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliaarrays%2Fmappedarrays.jl/lists"}