Skip to content

Commit aa72f77

Browse files
authored
Make vec just return the argument for MVector and SizedVector. (#982)
* Make `vec` just return the argument for `MVector` and `SizedVector`. * bump version
1 parent 6e12349 commit aa72f77

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StaticArrays"
22
uuid = "90137ffa-7385-5640-81b9-e52037218182"
3-
version = "1.3.0"
3+
version = "1.3.1"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/abstractarray.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,17 @@ homogenize_shape(shape::Tuple{Vararg{HeterogeneousShape}}) = map(last, shape)
190190
@inline function reshape(a::StaticArray, s::Tuple{SOneTo,Vararg{SOneTo}})
191191
return __reshape(a, map(u -> last(u), s), homogenize_shape(s))
192192
end
193-
@inline function __reshape(a, shape, ::Size{S}) where {S}
194-
return SizedArray{Tuple{S...}}(Base._reshape(a, shape))
193+
@inline function __reshape(a, shape, s::Size)
194+
return _maybewrap_reshape(Base._reshape(a, shape), Size(a), s)
195195
end
196-
@inline function __reshape(a::SizedArray, shape, ::Size{S}) where {S}
197-
return SizedArray{Tuple{S...}}(Base._reshape(a.data, shape))
196+
@inline function __reshape(a::SizedArray, shape, s::Size)
197+
return _maybewrap_reshape(Base._reshape(a.data, shape), Size(a), s)
198+
end
199+
@inline function _maybewrap_reshape(a, ::Size{Sa}, ::Size{S}) where {Sa,S}
200+
return SizedArray{Tuple{S...}}(a)
201+
end
202+
@inline function _maybewrap_reshape(a::StaticArray, ::Size{S}, ::Size{S}) where {S}
203+
return a
198204
end
199205

200206
reshape(a::Vector, ::Size{S}) where {S} = SizedArray{Tuple{S...}}(a)

test/abstractarray.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ using StaticArrays, Test, LinearAlgebra
115115
@test_throws DimensionMismatch reshape([1 2 3], axes(SMatrix{2,2}(1,2,3,4)))
116116

117117
@test @inferred(vec(SMatrix{2, 2}([1 2; 3 4])))::SVector{4,Int} == [1, 3, 2, 4]
118+
a = @MVector [1, 2, 3, 4]
119+
@test @inferred(vec(a)) === a
120+
121+
as = SizedVector(a)
122+
@test @inferred(vec(as)) === as
118123

119124
# AbstractArray
120125
# CartesianIndex

0 commit comments

Comments
 (0)