From 52de1e526357b53a5558be1c59474e7705f49193 Mon Sep 17 00:00:00 2001 From: N5N3 <2642243996@qq.com> Date: Sat, 23 Apr 2022 12:38:07 +0800 Subject: [PATCH] Drop `StaticSquareMatrix` & add more test. 1. remove `StaticSquareMatrix` (`StaticMatrix{N,N}` should be shorter and clear enough) 2. Add missing Test. --- src/convert.jl | 3 +-- test/SizedArray.jl | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/convert.jl b/src/convert.jl index 678a01f7d..9f3e57e0b 100644 --- a/src/convert.jl +++ b/src/convert.jl @@ -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")) @@ -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 diff --git a/test/SizedArray.jl b/test/SizedArray.jl index 845867661..8ea6e6750 100644 --- a/test/SizedArray.jl +++ b/test/SizedArray.jl @@ -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}} @@ -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] @@ -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