Skip to content

Is it possible to map enumeration to SVector? #1106

Closed
@drelatgithub

Description

@drelatgithub

When I do the following:

v = SA[10, 20, 30]
map(x -> x[1] + x[2], enumerate(v))

The result is a 3-element Vector{Int64} of values 11, 22 and 33. Is it possible to get the result in SVector since the length is known at compile time (assuming that the codes above is inside a function, and that v has fixed but unknown length)?

Other methods I tried but not did not work:

  1. I tried to use comprehension and macro @SVector, but it seems that in this case I need length(v) but its value is unknown during macro expansion.
  2. I also tried eachindex(v) but it seems that the result is converted to MVector instead of SVector. This part seems to have been covered in map SOneTo to SVector #1032

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions