Skip to content

Commit f30509b

Browse files
authored
Merge pull request #275 from JuliaArrays/ksh/testagain
Fix reshape bug and add tests
2 parents b69cc63 + 861d6f7 commit f30509b

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/abstractarray.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ similar{A<:Array,T,S}(::Type{A},::Type{T},s::Size{S}) = sizedarray_similar_type(
100100

101101

102102
@inline reshape(a::StaticArray, s::Size) = similar_type(a, s)(Tuple(a))
103-
@inline reshape(a::AbstractArray, s::Size) = _reshape(s, IndexStyle(a), a)
103+
@inline reshape(a::AbstractArray, s::Size) = _reshape(a, IndexStyle(a), s)
104104
@generated function _reshape(a::AbstractArray, indexstyle, s::Size{S}) where {S}
105105
if indexstyle == IndexLinear
106106
exprs = [:(a[$i]) for i = 1:prod(S)]
107107
else
108-
exprs = [:(a[$(inds...)]) for inds CartesianRange(S)]
108+
exprs = [:(a[$(inds)]) for inds CartesianRange(S)]
109109
end
110110

111111
return quote

test/abstractarray.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
@test @inferred(reshape([1,2,3,4], Size(2,2)))::SizedArray{Tuple{2,2},Int,2,1} == [1 3; 2 4]
6868

6969
@test @inferred(vec(SMatrix{2, 2}([1 2; 3 4])))::SVector{4,Int} == [1, 3, 2, 4]
70+
71+
# AbstractArray
72+
@test reshape(view(ones(4,4), 1:4, 1:2), Size(4,2)) == SMatrix{4,2}(ones(4,2))
7073
end
7174

7275
@testset "copy" begin

test/core.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@
106106
@test @inferred(convert(SArray{Tuple{1},Float64,1}, ma_int)) === sa_float
107107
@test @inferred(convert(SArray{Tuple{1},Float64,1,1}, ma_int)) === sa_float
108108
end
109-
109+
110110
@testset "AbstractArray conversion" begin
111111
sa = SArray{Tuple{2,2}, Int}((3, 4, 5, 6))
112112
ma = MArray{Tuple{2,2}, Int}((3, 4, 5, 6))
113113
a = [3 5; 4 6]
114114

115115
@test @inferred(convert(SArray{Tuple{2,2}}, a)) === sa
116-
@test @inferred(convert(SArray{Tuple{2,2},Int}, a)) === sa
116+
@test @inferred(convert(SArray{Tuple{2,2},Int}, a)) === sa
117117
@test @inferred(convert(SArray{Tuple{2,2},Int,2}, a)) === sa
118118
@test @inferred(convert(SArray{Tuple{2,2},Int,2,4}, a)) === sa
119119

@@ -132,7 +132,7 @@
132132
end
133133
@test_throws Exception Length{2.5}()
134134
@test Length(2) == Length{2}()
135-
@test Tuple{2, 3, 5} != Size{(2, 3, 4)}
136-
@test Size{(2, 3, 4)} != Tuple{2, 3, 5}
137-
135+
@test Tuple{2, 3, 5} != StaticArrays.Size{(2, 3, 4)}
136+
@test StaticArrays.Size{(2, 3, 4)} != Tuple{2, 3, 5}
137+
@test StaticArrays.check_length(2) == nothing
138138
end

0 commit comments

Comments
 (0)