-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Range-based indexing #149
Comments
This is something that has been somewhat overlooked so far. First I'll explain why it doesn't exist right now. Currently our index trait looks like this: To resolve this I see a few solutions:
|
Initially, I also found I wanted to write up a thread on internal.rust-lang.org to see if there's any interest in providing syntax sugar for tuple indexing, i.e. In any case, that's not going to happen any time soon, so let's consider our options.
|
I should have expanded a little on why I suggested the 4th option. I was indeed thinking that we could implement the trait for Anyway, what I was trying to say was that we could do this to avoid making a strong decision right now. We get fancy range indexing with tuple syntax but don't break everyone elses indexing code (yet). I would be interested in learning more about any official movement on syntactic sugar for indexing. If you do get around to making that post please let me know :). |
@AtheMathmo: that seems reasonable, and would probably make the code a whole lot cleaner as opposed to direct implementations of A bit of a side-note: One thing I've been thinking about lately, is the fact that in some places we use e.g. offsets or pointer arithmetic. These are inherently |
It was just pointed out to me on IRC that we actually cannot return a Hence my point here is mostly moot! |
Ah I totally forgot about this part of the problem! Before we can do this (and many other cool things) we need custom DSTs. Sadly this PR was closed recently and although I'd love to keep pushing it forward myself I lack the technical know-how. |
Thanks, that was an interesting read! |
Oh, and by the way, I decided to post on internals about tuple syntax sugaring: https://internals.rust-lang.org/t/opinions-on-syntax-sugar-for-tuple-based-indexing/4776 Will be interesting to see if anyone has anything to say on the topic! |
Since we're not going to be able to do this for a potentially very long time, I will close this issue for now. I hope we can revisit it in the future. |
Currently, to take a slice of a matrix, one needs to use e.g. the
sub_slice
function. I propose to add implementations ofIndex<(Range<usize>, Range<usize>)>
. See the following example:Similarly, we can slice rows or columns (returning
Row
orColumn
) using a mix ofusize
andRange<usize>
:The range-based indexing can be implemented in terms of
Index<(R1, R2)>
whereR1
,R2
are any of the following concrete types from the stdlib:Range
,RangeFull
,RangeTo
,RangeFrom
.Any thoughts on this? I think it would really empower matrix slices.
The text was updated successfully, but these errors were encountered: