{"id":16705041,"url":"https://github.com/mcabbott/starslice.jl","last_synced_at":"2026-03-18T21:35:12.131Z","repository":{"id":117871515,"uuid":"247208422","full_name":"mcabbott/StarSlice.jl","owner":"mcabbott","description":"🥒","archived":false,"fork":false,"pushed_at":"2020-03-16T21:20:51.000Z","size":12,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-13T19:28:30.830Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcabbott.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-03-14T04:02:15.000Z","updated_at":"2022-12-05T08:00:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"27a4df95-d7f2-4ef1-914c-96da13630265","html_url":"https://github.com/mcabbott/StarSlice.jl","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"6843cdf98b46440531b606b1b08f3b8bdaf2206b"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcabbott%2FStarSlice.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcabbott%2FStarSlice.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcabbott%2FStarSlice.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcabbott%2FStarSlice.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcabbott","download_url":"https://codeload.github.com/mcabbott/StarSlice.jl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243561206,"owners_count":20311053,"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-12T19:28:29.063Z","updated_at":"2026-01-29T14:10:50.237Z","avatar_url":"https://github.com/mcabbott.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StarSlice.jl\n\nThis package overloads `getindex` and friends to make slices. \nInserting `*` means that a given index will label the position in the outer container.\n`view` makes views, and `eachslice` makes a generator:\n\n```julia\njulia\u003e ones(Int, 2,3,4)[:, *, 4]\n3-element Array{Array{Int64,1},1}:\n [1, 1]\n [1, 1]\n [1, 1]\n\njulia\u003e @view ones(Int, 2,3)[*, :]\n2-element Array{SubArray{Int64,1,Array{Int64,2},Tuple{Int64,Base.Slice{Base.OneTo{Int64}}},true},1}:\n [1, 1, 1]\n [1, 1, 1]\n\njulia\u003e eachslice(ones(Int, 2,3,4,5), *, :, 4, *) |\u003e typeof\nBase.Generator{Base.Iterators.ProductIterator{Tuple{Base.OneTo{Int64},Base.RefValue{Colon},\n  Base.RefValue{Int64},Base.OneTo{Int64}}},StarSlice.var\"#75#76\"{Array{Int64,4}}}\n```\n\nWhile dimensions marked `*` belong only to the outer container, \nand those marked `:` belong only to the inner array,\nthose marked `\u0026` or `!` belong to both, \nsurviving as trivial dimensions of either the slices, or the container.\n\n```julia\njulia\u003e ones(Int, 2,3,4)[!, *, 4]   # with `!` in place of `:`, outer array keeps 1st dimension\n1×3 Array{Array{Int64,1},2}:\n [1, 1]  [1, 1]  [1, 1]\n\njulia\u003e ones(Int, 2,3,4)[:, \u0026, 4]   # with `\u0026` in place of `*`, inner arrays keep 2nd dimension\n3-element Array{Array{Int64,2},1}:\n [1; 1]\n [1; 1]\n [1; 1]\n\njulia\u003e size(first(ans))\n(2, 1)\n```\n\nOne use of this is for `mapslices`-like operations. It goes well with [LazyStack.jl](https://github.com/mcabbott/LazyStack.jl):\n\n```julia\njulia\u003e using StarSlice, LazyStack\n\njulia\u003e info(x) = [ndims(x), size(x)...]\ninfo (generic function with 1 method)\n\njulia\u003e mapslices(info, rand(10,20,30), dims=(1,3))\n3×20×1 Array{Int64,3}:\n[:, :, 1] =\n  2   2   2   2   2   2   2   2  …   2   2   2   2   2   2   2\n 10  10  10  10  10  10  10  10     10  10  10  10  10  10  10\n 30  30  30  30  30  30  30  30     30  30  30  30  30  30  30\n\njulia\u003e stack(info, @view rand(10,20,30)[:,*,:])\n3×20 Array{Int64,2}:\n  2   2   2   2   2   2   2   2  …   2   2   2   2   2   2   2\n 10  10  10  10  10  10  10  10     10  10  10  10  10  10  10\n 30  30  30  30  30  30  30  30     30  30  30  30  30  30  30\n```\n\nAnother is to explore reductions...\n\n```julia\nmat = rand(1:99, 3, 4)\n\nprod.(mat[!,*]) == prod(mat, dims=1)\nprod.(mat[:,*]) == dropdims(prod(mat, dims=1), dims=1)\n\nsum(mat[:,\u0026]) == sum(mat, dims=2) # but this won't work for prod\nsum(mat[:,*]) == dropdims(sum(mat, dims=2), dims=2)\n```\n\nRight now the `eachslice` generator returns an `Array` not a view, and re-uses the same one. But this appears to provide few benefits. \n\n### See also\n\n* [JuliennedArrays.jl](https://github.com/bramtayl/JuliennedArrays.jl)\n\n* [LazyStack.jl](https://github.com/mcabbott/LazyStack.jl)\n\n* [SliceMap.jl](https://github.com/mcabbott/SliceMap.jl), differentiable mapslices.\n\n* [JuliaLang/julia#32310](https://github.com/JuliaLang/julia/pull/32310) about `EachSlice` type\n\n* [tkf/ReduceDims.jl](https://github.com/tkf/ReduceDims.jl) from [JuliaLang/julia#16606](https://github.com/JuliaLang/julia/issues/16606). Compare:\n\n```julia\nusing ReduceDims, StarSlice\nmat = rand(1:99, 3, 4)\n\ns1 = sum(along(mat, \u0026, :)) # lazy mapreduce along \"\u0026\" directions\nsum(mat, dims=1) .== s1    # all equal\nsum(mat[\u0026, :]) == sum.(mat[:, \u0026]) == copy(s1)\n\np1 = prod(along(mat, \u0026, :)) |\u003e copy\nprod(mat, dims=1) == p1\nprod.(mat[:, *]) == vec(p1) # and prod(mat[*, :]) is an error\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcabbott%2Fstarslice.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcabbott%2Fstarslice.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcabbott%2Fstarslice.jl/lists"}