Side effects of using a zero-based indexing package?

I saw @ChrisRackauckas starred a package on github recently about 2-based indexing

// probably related to this ProgrammerHumor post:

https://www.reddit.com/r/ProgrammerHumor/comments/6jea7z/array_indexing_round_2/djdnjxi/


Going with it, I made a package that adds 0-based indexing to a module.

What are the downsides of using it? (i.e. the negative implications)

1 Like

There is already Tim Holy’s OffsetArrays type, which is more general.
It would be interesting to see a performance comparison between the two, when the OffsetArrays is using 0 for the offset,
and seeing how either package fares against the “built-in” Julia Array type.

1 Like

Don’t OffsetArrays and this have different use cases?

  • OffsetArrays is for compartamentalizing offsets in arrays
  • ZeroBasedIndexing is for changing the offset globally throughout the module

One use case of ZeroBasedIndexing could be to make translating a python package easier


What I’m trying to ask is what weird complications come from doing this?

// e.g. do imported modules get messed up?

Some issues with that implementation:

  • Dictionaries are broken (as are any other data structures that use non-numeric keys)
  • end is broken
  • Cartesian indexing is broken
  • eachindex is broken (as are any other functions that return a set of indices)
  • : indexing is broken
  • Logical indexing is broken
  • view isn’t also zero-based

It doesn’t affect any other modules, though. Just the code you write within the module you use it in.

2 Likes

For a better approach, you should use CustomUnitRanges and exploit the ZeroRange type to create your own ZArray{T,N} <: AbstractArray{T,N}. See the code in OffsetArrays for inspiration.

1 Like

I really hope that one of the experts will work out this special case on the basis of Tim Holy’s modules!

It’s actually a great exercise for someone who wants to make the transition newbie => expert. If you submit the package for inclusion in JuliaArrays, I can promise you that you’ll get thorough code-review; it’s like having a professional consultant giving you free advice about how to become a better Julia programmer. Why on earth would an expert want to take such an opportunity away from someone? :slightly_smiling_face:

4 Likes

(taking notes from the expert on how to get contributors…)

2 Likes

From what I can tell, you are expert at that particular skill already! Go, DiffEq!

1 Like