Skip to content

Feature request: Allow syntax @SVector 2:N-1 #223

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

Closed
DNF2 opened this issue Jun 10, 2017 · 2 comments
Closed

Feature request: Allow syntax @SVector 2:N-1 #223

DNF2 opened this issue Jun 10, 2017 · 2 comments
Labels
design speculative design related issue feature features and feature requests

Comments

@DNF2
Copy link

DNF2 commented Jun 10, 2017

The @SVector macro currently supports functions like rand, fill and so on. Is it possible to support StepRanges? For example, could

ind = @SVector 2:2:N-1

where N is a type parameter, be allowed?

One use case would be convenient slicing of SArrays, as discussed here, without the need for writing a custom function for each different slice.

This request might be a special case of the comprehension syntax, which cannot currently make use of type parameters.

@andyferris
Copy link
Member

andyferris commented Jun 10, 2017

Yes, I think some way of doing this should be provided.

Unless we can find an easy shortcut, the roadmap in my head is:

  • Add a static unit range type, which is returned from e.g. indices(::SVector). This would be a dataless "singleton"
  • Maybe add another static step range type. With a pure constructor we can have SStepRange(2,2,N-1) deal with type parameters at run-time. The biggest problem here is actually the N-1...
  • Define conversions from these to SVector
  • Make the macro do this / define a new @SA macro that does multiple things.

For now, I would define an extra pure function this way:

Base.@pure function myrange(N::Int)
    r = 2:2:N-1
    SVector((r...))
end

a[myrange(N)]

@c42f c42f added design speculative design related issue feature features and feature requests labels Jul 31, 2019
@c42f
Copy link
Member

c42f commented Aug 1, 2019

I think this is basically a dup of #97 / #26

@c42f c42f closed this as completed Aug 1, 2019
@c42f c42f mentioned this issue Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design speculative design related issue feature features and feature requests
Projects
None yet
Development

No branches or pull requests

3 participants