{"id":19093692,"url":"https://github.com/juliaarrays/customunitranges.jl","last_synced_at":"2026-05-25T19:30:18.794Z","repository":{"id":48083570,"uuid":"62911630","full_name":"JuliaArrays/CustomUnitRanges.jl","owner":"JuliaArrays","description":"Package-specific AbstractUnitRange types for julia","archived":false,"fork":false,"pushed_at":"2024-04-08T04:39:16.000Z","size":53,"stargazers_count":8,"open_issues_count":3,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-21T23:18:41.591Z","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-07-08T19:12:41.000Z","updated_at":"2024-08-14T03:58:05.000Z","dependencies_parsed_at":"2022-08-12T18:11:03.298Z","dependency_job_id":"5aeab76e-435b-4c8a-bce1-dc80391bcda8","html_url":"https://github.com/JuliaArrays/CustomUnitRanges.jl","commit_stats":{"total_commits":38,"total_committers":11,"mean_commits":"3.4545454545454546","dds":0.3157894736842105,"last_synced_commit":"d5f93a4fc1d0ce28c158308ea8799588393f5552"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaArrays%2FCustomUnitRanges.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaArrays%2FCustomUnitRanges.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaArrays%2FCustomUnitRanges.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaArrays%2FCustomUnitRanges.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JuliaArrays","download_url":"https://codeload.github.com/JuliaArrays/CustomUnitRanges.jl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240142861,"owners_count":19754639,"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:44.808Z","updated_at":"2026-05-25T19:30:18.742Z","avatar_url":"https://github.com/JuliaArrays.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CustomUnitRanges\n\n[![Build Status](https://travis-ci.org/JuliaArrays/CustomUnitRanges.jl.svg?branch=master)](https://travis-ci.org/JuliaArrays/CustomUnitRanges.jl)\n\n[![codecov.io](http://codecov.io/github/JuliaArrays/CustomUnitRanges.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaArrays/CustomUnitRanges.jl?branch=master)\n\nThis Julia package supports the creation of array types with\n\"unconventional\" indices, i.e., when the indices may not start at 1.\nWith this package, each custom array type can have a corresponding\n`axes` range type, consequently providing a means for consistency\nin allocation by `similar`.\n\nSee https://docs.julialang.org/en/v1/devdocs/offset-arrays/ for\nmore information about defining and using array types with non-1\nindices.\n\n# What's in this package\n\nCurrently this package defines two `AbstractUnitRange` types:\n\n- `ZeroRange`, where `ZeroRange(n)` is the equivalent of `0:n-1`, except that\n  Julia's type system knows that the lower bound is 0. (This is\n  analogous to `Base`'s `OneTo` type.) This is useful for defining\n  arrays that are indexed starting with 0.\n\n- `URange`, a parallel to `UnitRange`, for defining arbitrary range indices.\n\n# Usage\n\nThis package has a somewhat atypical usage: you should `include` files\nfrom this repository at the source level. The reason is that this\npackage's range types should be **private** to the module that needs\nthem; consequently you don't want to define a module in the global\nnamespace.\n\nInstead, suppose you're defining an array type that supports arbitrary\nindices. In broad terms, your module might look like this:\n\n```julia\nmodule MyArrayType\n\nusing CustomUnitRanges: filename_for_urange\ninclude(filename_for_urange)\n\nstruct MyArray{T,N} \u003c: AbstractArray{T,N}\n    ...\nend\n\nBase.axes(A::MyArray) = Base.Slice.(map(URange, #=starting indices=#, #=ending indices=#))\n\n...\n\nend\n```\n\nHere,\n```\nusing CustomUnitRanges: filename_for_urange\n```\n\nbrings a non-exported string, `filename_for_urange`, into the scope of\n`MyArrayType`. The key line is the `include(filename_for_urange)`\nstatement, which will load (at source-level) the code for the `URange`\ntype into your `MyArrayType` module.  We chose `\"URange.jl\"` because\nhere we want arbitrary indices; had we wanted zero-based indices, we\nwould have chosen `\"ZeroRange.jl\"` instead. Second, note that the\noutput of `axes` is a `Slice` containing a `URange` type. More specifically, it's\ncreating a tuple of slices with `MyArrayType.URange`---there is no \"global\"\n`URange` type, so the indices-tuple is therefore *specific to this\npackage*.\n\nThe important result is that two packages, defining `MyArray` and\n`OtherArray`, can independently exploit `URange`.  If `MyArrayType`\nincludes the specialization\n\n```jl\nfunction Base.similar(f::Union{Type,Function}, shape::Tuple{URange,Vararg{URange}}\n    MyArray(f(map(length, shape)), #=something for the offset=#)\nend\n```\n\nand similarly for `OtherArrayType`. Then, if `A` is a `MyArray` and\n`B` is an `OtherArray`,\n\n- `similar(Array{Int}, axes(A))` will create another `MyArray`\n- `similar(Array{Int}, axes(B))` will create another `OtherArray`\n\ndespite the fact that they both use `URange`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliaarrays%2Fcustomunitranges.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliaarrays%2Fcustomunitranges.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliaarrays%2Fcustomunitranges.jl/lists"}