Skip to content

Commit

Permalink
Drop StaticSquareMatrix & add more test.
Browse files Browse the repository at this point in the history
1. remove `StaticSquareMatrix` (`StaticMatrix{N,N}` should be shorter and clear enough)
2. Add missing Test.
  • Loading branch information
N5N3 committed May 6, 2022
1 parent 66b1db9 commit 52de1e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ end
@pure has_size1(::Type{<:StaticMatrix{M}}) where {M} = @isdefined M
@pure has_size1(::Type{<:StaticMatrix}) = false
_size1(::Type{<:StaticMatrix{M}}) where {M} = M
StaticSquareMatrix{N,T} = StaticMatrix{N,N,T}
@generated function _sqrt(::Length{L}) where {L}
N = round(Int, sqrt(L))
N^2 == L || throw(DimensionMismatch("Input's length must be perfect square"))
Expand Down Expand Up @@ -73,7 +72,7 @@ function adapt_size(::Type{SA}, x) where {SA<:StaticArray}
M = len ÷ N
M * N == len || throw(DimensionMismatch("Incorrect matrix sizes. $len does not divide $N elements"))
SZ = Tuple{N, M}
elseif SA <: StaticSquareMatrix
elseif SA <: StaticMatrix{N,N} where {N}
N = _sqrt(Length(len))
SZ = Tuple{N, N}
elseif x isa StaticArray
Expand Down
6 changes: 4 additions & 2 deletions test/SizedArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
@test @inferred(SizedArray{Tuple{2,2}}([1 2;3 4]))::SizedArray{Tuple{2,2},Int,2,2} == [1 2; 3 4]
# From Array, reshaped
@test @inferred(SizedArray{Tuple{2,2}}([1,2,3,4]))::SizedArray{Tuple{2,2},Int,2,1} == [1 3; 2 4]
@test SizedArray{Tuple{4}}([1 2; 3 4]) == vec([1 2; 3 4])
@test_throws DimensionMismatch SizedArray{Tuple{1,4}}([1 2; 3 4])
# Uninitialized
@test @inferred(SizedArray{Tuple{2,2},Int,2,2,Matrix{Int}}(undef)) isa SizedArray{Tuple{2,2},Int,2,2,Matrix{Int}}
Expand Down Expand Up @@ -76,6 +77,9 @@
# Reshaping
@test @inferred(SizedMatrix{2,2}([1,2,3,4]))::SizedArray{Tuple{2,2},Int,2,1} == [1 3; 2 4]
@test @inferred(SizedMatrix{2,2}((1,2,3,4)))::SizedArray{Tuple{2,2},Int,2,2} == [1 3; 2 4]
@test @inferred(SizedMatrix{2,2,Int}(SVector(1,2,3,4)))::SizedMatrix{2,2,Int,2} == [1 3; 2 4]
@test @inferred(SizedMatrix{2,2,Int,1}(SVector(1,2,3,4)))::SizedMatrix{2,2,Int,1} == [1 3; 2 4]
@test @inferred(SizedMatrix{2,2,Int,1,SVector{4,Int}}(SVector(1,2,3,4)))::SizedMatrix{2,2,Int,1} == [1 3; 2 4]
# Back to Matrix
@test Matrix(SizedMatrix{2,2}([1 2;3 4])) == [1 2; 3 4]
@test convert(Matrix, SizedMatrix{2,2}([1 2;3 4])) == [1 2; 3 4]
Expand Down Expand Up @@ -268,6 +272,4 @@ Base.axes(::OVector) = (0:9,)
@test (@inferred(SizedMatrix{1}(1, 2))::SizedMatrix{1,2,Int}) == reshape(1:2, 1, 2)
@test (@inferred(SizedMatrix{2}((1, 2)))::SizedMatrix{2,1,Int}) == reshape(1:2, 2, 1)
@test (@inferred(SizedMatrix{2}(1, 2))::SizedMatrix{2,1,Int}) == reshape(1:2, 2, 1)


end

0 comments on commit 52de1e5

Please sign in to comment.