Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

[Discussion] Separating labels and integers #4

@lkdvos

Description

@lkdvos

The current design for labelled numbers incurs a rather large number of method ambiguities and can possibly lead to invalidations, since defining new integer types etc is a big source of that.
Of course, this should not be an argument to never define new number types, but just to carefully consider the benefits.

Here, (correct me if I'm wrong), the main purpose is to have labels attached to GradedUnitRange objects, such that these can easily/automatically be carried along.
One alternative could be to separate the labels and the integers again, and manually handle that kind of logic in GradedUnitRange. The benefit is that this does not suffer from ambiguities and invalidations, but of course requires a bit more manual work.

Just to add this information here, as @mtfishman mentioned, one nice feature that we probably should preserve in any case is that indexing into a gradedrange outputs something that contains both the label as well as the range information:

what I like about the current design is that when you index into a GradedUnitRange, i.e. g[2], it outputs the range value along with information about the sector. That is consistent with the fact that we want slices like g[Block.(2:3)], g[2:5], g[Block(2)], etc. to preserve the sector information.

(linking #3)

After thinking about this a bit more, it seems to me that - at least for slicing operations - this should not be a real problem to support in any case, since indexing into a gradedrange object returns another gradedrange, which thus retains that information. The harder case to figure out is what "scalar indexing" should do, similar to how scalar indexing into BlockArrays becomes a bit more involved. The normal Julia array behavior is to drop scalar dimensions, reducing the total number of dimensions as you index. This is slightly annoying to deal with for ranges/axes that want to hold on to more information, since there you really don't want to drop these dimensions, because that would also discard the label/grading information.
Effectively, I would probably advocate that for these kinds of arrays, indexing should either be "fully scalar", and if not, considered as a slicing operation.

a[1,2,3] # scalar
a[1:3, 2:4, 2:3] # slicing: Array{T,3} as result
a[1, :, :] # slicing: Matrix as result -- should really just stay Array{T,3}!!

To achieve this, effectively you would have that a[i, ...] would become a[i:i, ...] whenever not all indices are "scalar". This would also solve the issue that indexing with a scalar into a gradedrange loses the label information, as now g[i:i] would still output a range.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions