Skip to content

Commit b089425

Browse files
Merge pull request #595 from devmotion/reshape
Reshape with tuple of SOneTo
2 parents 48cd0e4 + bb32ad1 commit b089425

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/abstractarray.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ homogenize_shape(shape::Tuple{Vararg{HeterogeneousShape}}) = map(last, shape)
137137

138138
@inline reshape(a::StaticArray, s::Size) = similar_type(a, s)(Tuple(a))
139139
@inline reshape(a::AbstractArray, s::Size) = _reshape(a, IndexStyle(a), s)
140+
@inline reshape(a::StaticArray, s::Tuple{SOneTo,Vararg{SOneTo}}) = reshape(a, homogenize_shape(s))
140141
@generated function _reshape(a::AbstractArray, indexstyle, s::Size{S}) where {S}
141142
if indexstyle == IndexLinear
142143
exprs = [:(a[$i]) for i = 1:prod(S)]

test/abstractarray.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ using StaticArrays, Test, LinearAlgebra
9292

9393

9494
@testset "reshape" begin
95+
@test @inferred(reshape(SVector(1,2,3,4), axes(SMatrix{2,2}(1,2,3,4)))) === SMatrix{2,2}(1,2,3,4)
9596
@test @inferred(reshape(SVector(1,2,3,4), Size(2,2))) === SMatrix{2,2}(1,2,3,4)
9697
@test @inferred(reshape([1,2,3,4], Size(2,2)))::SizedArray{Tuple{2,2},Int,2,1} == [1 3; 2 4]
9798

0 commit comments

Comments
 (0)