Skip to content

Commit 7276787

Browse files
authored
Merge pull request #278 from JuliaArrays/ksh/aatest
Fix bug for sizedarray_similar_type, more tests
2 parents e7d42d6 + f8734e8 commit 7276787

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/abstractarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ mutable_similar_type{T,S,D}(::Type{T}, s::Size{S}, ::Type{Val{D}}) = MArray{Tupl
6666
#similar_type{SA<:SizedArray,T,S}(::Type{SA},::Type{T},s::Size{S}) = sizedarray_similar_type(T,s,length_val(s))
6767
#similar_type{A<:Array,T,S}(::Type{A},::Type{T},s::Size{S}) = sizedarray_similar_type(T,s,length_val(s))
6868

69-
sizedarray_similar_type{T,S,D}(::Type{T},s::Size{S},::Type{Val{D}}) = SizedArray{Tuple{S...},T,D,D}
69+
sizedarray_similar_type{T,S,D}(::Type{T},s::Size{S},::Type{Val{D}}) = SizedArray{Tuple{S...},T,D,length(s)}
7070

7171
# Field vectors are user controlled, and currently default to SVector, etc
7272

test/abstractarray.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
@test isa(@inferred(similar(SArray{Tuple{1,1,1},Int,3,1}, Float64)), MArray{Tuple{1,1,1},Float64,3,1})
6161
@test isa(@inferred(similar(sv, Size(3,3,3))), MArray{Tuple{3,3,3},Int,3,27})
6262
@test isa(@inferred(similar(sv, Float64, Size(3,3,3))), MArray{Tuple{3,3,3},Float64,3,27})
63+
64+
@test isa(@inferred(similar(Diagonal{Int}, Size(2,2))), MArray{Tuple{2, 2}, Int, 2, 4})
65+
@test isa(@inferred(similar(Matrix{Int}, Int, Size(2,2))), SizedArray{Tuple{2, 2}, Int, 2, 2})
6366
end
6467

6568
@testset "reshape" begin
@@ -69,7 +72,11 @@
6972
@test @inferred(vec(SMatrix{2, 2}([1 2; 3 4])))::SVector{4,Int} == [1, 3, 2, 4]
7073

7174
# AbstractArray
72-
@test reshape(view(ones(4,4), 1:4, 1:2), Size(4,2)) == SMatrix{4,2}(ones(4,2))
75+
# CartesianIndex
76+
@test reshape(view(ones(4, 4), 1:4, 1:2), Size(4, 2)) == SMatrix{4,2}(ones(4, 2))
77+
# IndexLinear
78+
@test reshape(view(ones(4, 4), 1, 1:4), Size(4, 1)) == SMatrix{4,1}(ones(4, 1))
79+
@test_throws DimensionMismatch reshape(view(ones(4,4), 1:4, 1:2), Size(5, 2))
7380
end
7481

7582
@testset "copy" begin

0 commit comments

Comments
 (0)