Skip to content

Allow @SVector comprehension to eval range with locals? #26

Closed
@dbeach24

Description

@dbeach24

Because the @SVector macro does not evaluate the range using the local scope, I find myself transforming code like this:

function mytransform{N}(x::SVector{N})
    @SVector [x[i] * i for i=1:N]
end

into this:

function mytransform{N,T}(x::SVector{N,T})
    SVector{N,T}(ntuple(i -> x[i] * i, N) ...)
end

I'm not sure if the second form is as efficient, but in either case, the first version is far easier to read.

Is there any chance that @SVector comprehensions can be made to support local variables in the range? Or, is there some other way I should be writing this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurefeatures and feature requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions