Skip to content

Commit

Permalink
Merge pull request #278 from JuliaArrays/ksh/aatest
Browse files Browse the repository at this point in the history
Fix bug for sizedarray_similar_type, more tests
  • Loading branch information
kshyatt authored Aug 11, 2017
2 parents e7d42d6 + f8734e8 commit 7276787
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mutable_similar_type{T,S,D}(::Type{T}, s::Size{S}, ::Type{Val{D}}) = MArray{Tupl
#similar_type{SA<:SizedArray,T,S}(::Type{SA},::Type{T},s::Size{S}) = sizedarray_similar_type(T,s,length_val(s))
#similar_type{A<:Array,T,S}(::Type{A},::Type{T},s::Size{S}) = sizedarray_similar_type(T,s,length_val(s))

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

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

Expand Down
9 changes: 8 additions & 1 deletion test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
@test isa(@inferred(similar(SArray{Tuple{1,1,1},Int,3,1}, Float64)), MArray{Tuple{1,1,1},Float64,3,1})
@test isa(@inferred(similar(sv, Size(3,3,3))), MArray{Tuple{3,3,3},Int,3,27})
@test isa(@inferred(similar(sv, Float64, Size(3,3,3))), MArray{Tuple{3,3,3},Float64,3,27})

@test isa(@inferred(similar(Diagonal{Int}, Size(2,2))), MArray{Tuple{2, 2}, Int, 2, 4})
@test isa(@inferred(similar(Matrix{Int}, Int, Size(2,2))), SizedArray{Tuple{2, 2}, Int, 2, 2})
end

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

# AbstractArray
@test reshape(view(ones(4,4), 1:4, 1:2), Size(4,2)) == SMatrix{4,2}(ones(4,2))
# CartesianIndex
@test reshape(view(ones(4, 4), 1:4, 1:2), Size(4, 2)) == SMatrix{4,2}(ones(4, 2))
# IndexLinear
@test reshape(view(ones(4, 4), 1, 1:4), Size(4, 1)) == SMatrix{4,1}(ones(4, 1))
@test_throws DimensionMismatch reshape(view(ones(4,4), 1:4, 1:2), Size(5, 2))
end

@testset "copy" begin
Expand Down

0 comments on commit 7276787

Please sign in to comment.