Add a trait to tie together compile-time and runtime number of dimensions #1575
+226
−46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the next PR to address #1506. In the previous PR (#1568) we established a trait for capturing the "dimensionality" or "rank" of an array at the type level. This PR is focused on providing a bridge from type-level dimensionality to runtime dimensionality, which we do through the new
Rankedtrait.First, a note on language: we now have three words / phrases to refer to the same thing: number of dimensions, dimensionality, and rank. That's ok, they're all accurate, but I'm worried it will be confusing as time goes on. Similarly, in #1568, we decided on using
Rankas the name of the associated type that tells you the compile-time number of dimensions. However, the function that has traditionally provided the number of dimensions isndim. So we have a slight vocabulary problem. I would really love some input and feedback about what language we should be using; especially from people for whom English is not their first / primary language.The
Rankedtrait is pretty simple: require an associated type (Rank) that carries compile-time dimensionality, and a functionfn rank(&self) -> usizethat tells the user runtime dimensionality. Thesrc/layout/ranked.rsfile contains the definition, implementations, and blanket implementations. There are likely some/many types in the library or outside of it that I forgot to implementRankedfor, but I'm sure we'll find them as time goes on.I've also removed the
Rankassociated type onDimensionand madeRankeda supertrait ofDimension. I think this is the best way to do this, but it does mean that I've had to remove the"unstable"feature flag we had introduced. Since this code isn't merging to main yet, I think that's fine.