Skip to content

Commit 68b10c2

Browse files
authored
Generate reverse for StaticVector types (#802)
1 parent 94ce5e2 commit 68b10c2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/abstractarray.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ reshape(a::Array, ::Size{S}) where {S} = SizedArray{Tuple{S...}}(a)
185185
@inline copy(a::StaticArray) = typeof(a)(Tuple(a))
186186
@inline copy(a::SizedArray) = typeof(a)(copy(a.data))
187187

188-
@inline reverse(v::StaticVector) = typeof(v)(reverse(Tuple(v)))
188+
@inline reverse(v::StaticVector) = typeof(v)(_reverse(v))
189+
190+
@generated function _reverse(v::StaticVector{N,T}) where {N,T}
191+
return Expr(:tuple, (:(v[$i]) for i = N:(-1):1)...)
192+
end
189193

190194
# TODO permutedims?
191195

0 commit comments

Comments
 (0)