|
1 | 1 | using FunctionMaps:
|
2 |
| - to_matrix, to_vector, |
| 2 | + to_matrix, |
| 3 | + to_vector, |
| 4 | + zeromatrix, |
| 5 | + zerovector, |
3 | 6 | matrix_pinv
|
4 | 7 |
|
5 | 8 | function test_affine_maps(T)
|
6 | 9 | A = rand(T,2,2)
|
7 |
| - @test FunctionMaps.to_matrix(Vector{T}, A) == A |
8 |
| - @test FunctionMaps.to_matrix(T, 2) == 2 |
9 |
| - @test FunctionMaps.to_matrix(SVector{2,T}, 2) == SMatrix{2,2}(2,0,0,2) |
10 |
| - @test FunctionMaps.to_matrix(SVector{2,T}, LinearAlgebra.I) == SMatrix{2,2}(1,0,0,1) |
11 |
| - @test FunctionMaps.to_matrix(Vector{T}, 2) == UniformScaling(2) |
12 |
| - @test FunctionMaps.to_matrix(Vector{T}, LinearAlgebra.I) == LinearAlgebra.I |
| 10 | + @test to_matrix(Vector{T}, A) == A |
| 11 | + @test to_matrix(T, 2) == 2 |
| 12 | + @test to_matrix(SVector{2,T}, 2) == SMatrix{2,2}(2,0,0,2) |
| 13 | + @test to_matrix(SVector{2,T}, LinearAlgebra.I) == SMatrix{2,2}(1,0,0,1) |
| 14 | + @test to_matrix(Vector{T}, 2) == UniformScaling(2) |
| 15 | + @test to_matrix(T, LinearAlgebra.I) == one(T) |
| 16 | + @test to_matrix(Vector{T}, LinearAlgebra.I) == LinearAlgebra.I |
13 | 17 | # test fallback with nonsensical call
|
14 |
| - @test FunctionMaps.to_matrix(Tuple{Int}, 2) == 2 |
15 |
| - |
16 |
| - @test FunctionMaps.to_matrix(T, A, 2) == A |
17 |
| - @test FunctionMaps.to_matrix(T, 2, 3) == 2 |
18 |
| - @test FunctionMaps.to_matrix(T, UniformScaling(2), 3) == 2 |
19 |
| - @test FunctionMaps.to_matrix(T, LinearAlgebra.I, zero(T)) isa T |
20 |
| - @test FunctionMaps.to_matrix(SVector{2,T}, 2, SVector(1,1)) == SMatrix{2,2}(2,0,0,2) |
21 |
| - @test FunctionMaps.to_matrix(Vector{T}, 2, [1,2]) == [2 0 ; 0 2] |
22 |
| - |
23 |
| - @test FunctionMaps.to_vector(T, 2) == 0 |
24 |
| - @test FunctionMaps.to_vector(SVector{2,T}, 2) == SVector(0,0) |
25 |
| - @test FunctionMaps.to_vector(Vector{T}, A) == [0,0] |
26 |
| - @test FunctionMaps.to_vector(T, 2, 3) == 3 |
| 18 | + @test to_matrix(Tuple{Int}, 2) == 2 |
| 19 | + |
| 20 | + @test to_matrix(Tuple{Int}, 2, 3) == 2 |
| 21 | + @test to_matrix(T, A, 2) == A |
| 22 | + @test to_matrix(T, 2, 3) == 2 |
| 23 | + @test to_matrix(T, UniformScaling(2), 3) == 2 |
| 24 | + @test to_matrix(T, LinearAlgebra.I, zero(T)) isa T |
| 25 | + @test to_matrix(SVector{2,T}, 2, SVector(1,1)) == SMatrix{2,2}(2,0,0,2) |
| 26 | + @test to_matrix(Vector{T}, 2, [1,2]) == [2 0 ; 0 2] |
| 27 | + |
| 28 | + @test to_vector(T, 2) == 0 |
| 29 | + @test to_vector(SVector{2,T}, 2) == SVector(0,0) |
| 30 | + @test to_vector(Vector{T}, A) == [0,0] |
| 31 | + @test to_vector(T, 2, 3) == 3 |
| 32 | + |
| 33 | + @test zeromatrix(LinearMap(2.0)) == 0 |
| 34 | + @test zeromatrix(LinearMap([2.0])) == [0.0] |
| 35 | + @test zeromatrix(LinearMap(SA[2.0])) isa SVector |
| 36 | + @test zeromatrix(LinearMap(SA[2.0])) == [0.0] |
| 37 | + @test zeromatrix(LinearMap(SA[2.0])) isa SVector |
| 38 | + @test zeromatrix(LinearMap(SA[2 1; 1 2])) isa SMatrix{2,2} |
| 39 | + @test zeromatrix(LinearMap(SA[2 1; 1 2])) == [0 0; 0 0] |
| 40 | + @test zeromatrix(ConstantMap{SVector{2,Float64}}(2.0)) isa Transpose{Float64,SVector{2,Float64}} |
| 41 | + @test zeromatrix(ConstantMap{SVector{2,Float64}}(2.0)) == [0 0] |
| 42 | + @test zeromatrix(LinearMap{SVector{2,Int}}(transpose(SA[1, 2]))) isa Transpose{Int,SVector{2,Int}} |
| 43 | + @test zeromatrix(LinearMap{SVector{2,Int}}(transpose(SA[1, 2]))) == [0 0] |
| 44 | + @test zeromatrix(LinearMap(transpose([1, 2]))) isa Transpose{Int,Vector{Int}} |
| 45 | + @test zeromatrix(LinearMap(transpose([1, 2]))) == [0 0] |
27 | 46 |
|
28 | 47 | if T != BigFloat # BigFloat's make pinv fail for StaticArrays
|
29 | 48 | @test FunctionMaps.matrix_pinv(SMatrix{2,2}(rand(T),rand(T),rand(T),rand(T))) isa SMatrix{2,2}
|
|
0 commit comments