-
Notifications
You must be signed in to change notification settings - Fork 321
Support subviews in slice s! syntax #215
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
Comments
It's a natural idea, but it's not easily realizable because taking subviews changes the number of of axes, which changes the type of the array (D type parameter), unless the array is a dynamically dimensioned array ( Some major type hackery would be needed for the slice method to support this, but another macro might be able to do it. |
We have a fundamental tension in our choice to have explicit type-level axis counts in ndarray. |
This can be implemented for dynamic dimension arrays. Needs a design that shows how, though :) |
I'd really like this feature, too. I put together a proof-of-concept of one possible strategy: jturner314/ndarray@7b41f5f Basically, what I did is:
The code needs some refinement but shows that this feature is possible with basically the same API as the existing slicing functionality. What do you think? |
Looks absolutely promising, happy you're keeping the compile time checking that the number of indices matches up. |
Having the cryptic and short name |
After working on this a little more, I think I prefer an alternative approach: jturner314/ndarray@1987787 This is a summary:
Note that it would also be possible to add an The implementation is simpler, and the usage is more concise (e.g. What do you think? |
It's worth pointing out that it would be feasible to provide slicing without any macros in the API, if that's desired. You could do it like this:
The implementation side is the complex part of this approach, because you'd have to provide an implementation for all possible tuple inputs. It's still feasible, though, (with use of macros or code generation to write the implementation) because there are only 2^6 = 64 possibilities for the largest fixed dimension ( My preference is the approach in my previous comment ( If you like the |
It would be nice, if giving just an integer (not a range) to the
s!
macro, would result into asubview
.I imagine it like this
where a is a vector (an array with shape
(2,1)
). So this would make slicing similar to thea[0, :, 1]
syntax in Python's Numpy.Is this feasible?
The text was updated successfully, but these errors were encountered: