@@ -11,60 +11,80 @@ function Fcomplex(s)
1111 return 1 / (s - α)
1212end
1313
14- # Test scalar-functionality of arrcoeff, Fcomplex=(s-a)⁻¹
15- let arr = try InverseLaplace. _arrcoeff (Fcomplex,4 ,1.0 ,1.0 );
16- InverseLaplace. _arrcoeff (Fcomplex,4 ,1.0 ,1.0 )
17- catch
18- InverseLaplace. _arrcoeff (Fcomplex,4 ,1.0 ,1.0 )
19- end , scal = InverseLaplace. _wcoeff (Fcomplex,4 ,1.0 ,1.0 )
14+ @testset " Array functionality" begin
15+ @testset " Internal functions" begin
16+ # Test scalar-functionality of arrcoeff, Fcomplex=(s-a)⁻¹
17+ let arr = try InverseLaplace. _arrcoeff (Fcomplex,4 ,1.0 ,1.0 );
18+ InverseLaplace. _arrcoeff (Fcomplex,4 ,1.0 ,1.0 )
19+ catch
20+ InverseLaplace. _arrcoeff (Fcomplex,4 ,1.0 ,1.0 )
21+ end , scal = InverseLaplace. _wcoeff (Fcomplex,4 ,1.0 ,1.0 )
2022
21- @test arr == scal
22- end
23-
24- # Test for ordering of array valued coefficients (along first dimension)
25- let arr = try InverseLaplace. _arrcoeff (arrFcomplex,4 ,1.0 ,1.0 );
26- InverseLaplace. _arrcoeff (arrFcomplex,4 ,1.0 ,1.0 )
27- catch
28- InverseLaplace. _arrcoeff (arrFcomplex,4 ,1.0 ,1.0 )
29- end , scal = InverseLaplace. _wcoeff (Fcomplex,4 ,1.0 ,1.0 )
30- @test arr[:,1 ,1 ] == scal
31- @test arr[:,1 ,2 ] == 2 .* arr[:,1 ,1 ]
32- @test isapprox (arr[:,2 ,1 ] , 3 .* arr[:,1 ,1 ], atol= 1E-15 )
33- @test arr[:,2 ,2 ] == 4 .* arr[:,1 ,1 ]
34- end
23+ @test arr == scal
24+ end
3525
36- # Compare _get_coefficients and _laguerre for array functions and scalar functions
37- let arr = try InverseLaplace. _get_array_coefficients (arrFcomplex,4 ,1.0 ,1.0 ,Complex);
38- InverseLaplace. _get_array_coefficients (arrFcomplex,4 ,1.0 ,1.0 ,Complex)
39- catch
40- InverseLaplace. _get_array_coefficients (arrFcomplex,4 ,1.0 ,1.0 ,Complex)
41- end , scal = InverseLaplace. _get_coefficients (Fcomplex,4 ,1.0 ,1.0 ,Complex)
42- @test arr[:,1 ,1 ] == scal
43- @test arr[:,1 ,2 ] == 2 .* scal
44- @test isapprox (arr[:,2 ,1 ] , 3 .* scal, atol= 1E-15 )
45- @test arr[:,2 ,2 ] == 4 .* scal
46-
47- laguerreeval = reshape (mapslices (i -> InverseLaplace. _laguerre (i,1.0 ),arr,dims= (1 )),(2 ,2 ))
48- @test isapprox (laguerreeval, [1 2 ; 3 4 ] .* InverseLaplace. _laguerre (scal,1.0 ), atol = 1E-15 )
49- end
26+ # Test for ordering of array valued coefficients (along first dimension)
27+ let arr = try InverseLaplace. _arrcoeff (arrFcomplex,4 ,1.0 ,1.0 );
28+ InverseLaplace. _arrcoeff (arrFcomplex,4 ,1.0 ,1.0 )
29+ catch
30+ InverseLaplace. _arrcoeff (arrFcomplex,4 ,1.0 ,1.0 )
31+ end , scal = InverseLaplace. _wcoeff (Fcomplex,4 ,1.0 ,1.0 )
32+ @test arr[:,1 ,1 ] == scal
33+ @test arr[:,1 ,2 ] == 2 .* arr[:,1 ,1 ]
34+ @test isapprox (arr[:,2 ,1 ] , 3 .* arr[:,1 ,1 ], atol= 1E-15 )
35+ @test arr[:,2 ,2 ] == 4 .* arr[:,1 ,1 ]
36+ end
5037
38+ # Compare _get_coefficients and _laguerre for array functions and scalar functions
39+ let arr = try InverseLaplace. _get_array_coefficients (arrFcomplex,4 ,1.0 ,1.0 ,Complex);
40+ InverseLaplace. _get_array_coefficients (arrFcomplex,4 ,1.0 ,1.0 ,Complex)
41+ catch
42+ InverseLaplace. _get_array_coefficients (arrFcomplex,4 ,1.0 ,1.0 ,Complex)
43+ end , scal = InverseLaplace. _get_coefficients (Fcomplex,4 ,1.0 ,1.0 ,Complex)
44+ @test arr[:,1 ,1 ] == scal
45+ @test arr[:,1 ,2 ] == 2 .* scal
46+ @test isapprox (arr[:,2 ,1 ] , 3 .* scal, atol= 1E-15 )
47+ @test arr[:,2 ,2 ] == 4 .* scal
5148
49+ laguerreeval = reshape (mapslices (i -> InverseLaplace. _laguerre (i,1.0 ),arr,dims= (1 )),(2 ,2 ))
50+ @test isapprox (laguerreeval, [1 2 ; 3 4 ] .* InverseLaplace. _laguerre (scal,1.0 ), atol = 1E-15 )
51+ end
52+ end
53+ @testset " ILT for arrays" begin
54+ # Test the ILT calculation for arrays and compare with the scalar Weeks method
55+ let
56+ # Weeks parameters
57+ N = 4
58+ σ = 1.0
59+ b = 0.5
60+ t = 1.0
61+ testingrank = 2
62+ funcdims = size (arrFcomplex (rand (Complex{Float64}))) # (2,2)
5263
53- # Test the ILT calculation for arrays and compare with the scalar Weeks method
54- let
55- # Weeks parameters
56- σ = 1.0
57- b = 0.5
58- t = 1.0
64+ # Evaluating ILT for array valued function
65+ coef = InverseLaplace. _get_array_coefficients (arrFcomplex,4 ,σ,b,Complex)
66+ lag = reshape (mapslices (i -> InverseLaplace. _laguerre (i,2 * b * t),coef,dims= (1 )),(2 ,2 ))
67+ inverse = lag .* exp ((σ - b) * t)
5968
60- # Evaluating ILT for array valued function
61- coef = InverseLaplace. _get_array_coefficients (arrFcomplex,4 ,σ,b,Complex)
62- lag = reshape (mapslices (i -> InverseLaplace. _laguerre (i,2 * b * t),coef,dims= (1 )),(2 ,2 ))
63- inverse = lag .* exp ((σ - b) * t)
69+ # Evaluating ILT for scalar function, then multiplying by an array
70+ Ft = Weeks (Fcomplex,4 ,σ,b,datatype= Complex)
71+ Ft_array_eval = [1 2 ;3 4 ] .* Ft (1.0 )
6472
65- # Evaluating ILT for scalar function, then multiplying by an array
66- Ft = Weeks (Fcomplex,4 ,σ,b,datatype= Complex)
67- Ft_array_eval = [1 2 ;3 4 ] .* Ft (1.0 )
73+ @test isapprox (Ft_array_eval , inverse, atol= 1E-15 )
6874
69- @test isapprox (Ft_array_eval , inverse, atol= 1E-15 )
75+ # Test the array constructor for Weeks{T}, both real and complex
76+ Arr_c = Weeks (arrFcomplex,N,σ,b,datatype= Complex,rank= testingrank)
77+ Scal_c = Weeks (Fcomplex,N,σ,b,datatype= Complex)
78+ Arr_r = Weeks (arrFcomplex,N,σ,b,rank= testingrank)
79+ Scal_r = Weeks (Fcomplex,N,σ,b)
80+ @test ndims (Arr_c. coefficients) == testingrank + 1
81+ @test size (Arr_c. coefficients) == (Arr_c. Nterms, 2 ,2 )
82+ @test ndims (Arr_r. coefficients) == testingrank + 1
83+ @test size (Arr_r. coefficients) == (Arr_r. Nterms,2 ,2 )
84+ @test real (Arr_c. coefficients) == Arr_r. coefficients
85+ @test isapprox (Arr_c (t),[1 2 ; 3 4 ] .* Scal_c (t),atol= 1E-15 )
86+ @test isapprox (Arr_r (t),[1 2 ; 3 4 ] .* Scal_r (t),atol= 1E-15 )
87+ @test isapprox (real (Arr_c (t)),Arr_r (t),atol= 1E-15 )
88+ end
89+ end
7090end
0 commit comments