@@ -22,39 +22,46 @@ x = [0.5316732188954801 + 0.015032026010878084im -0.8051436916816284 - 0.7302380
22
22
23
23
x1 = view (x, :, 1 )
24
24
x2 = view (x, :, 2 )
25
-
25
+ cmplx_x = convert (AbstractMatrix{Complex}, x)
26
+ cmplx_x1 = convert (AbstractVector{Complex}, x1)
27
+ cmplx_x2 = convert (AbstractVector{Complex}, x2)
26
28
# autocov & autocorr
27
29
28
30
@test autocov ([1 : 5 ;]) ≈ [2.0 , 0.8 , - 0.2 , - 0.8 , - 0.8 ]
29
31
@test autocor ([1 , 2 , 3 , 4 , 5 ]) ≈ [1.0 , 0.4 , - 0.1 , - 0.4 , - 0.4 ]
30
32
31
- racovx1 = [0.755284179631112 + 0.0im ,
32
- - 0.005333112170365584 - 0.18633291805458002im ,
33
- - 0.28638133506011604 + 0.1397225175604478im ,
34
- - 0.05476759020476188 + 0.12991227531087618im ,
35
- - 0.00499902418309206 + 0.023463421186162473im ,
36
- 0.11854989361702409 - 0.0028772373657594066im ,
37
- - 0.005123812003979093 - 0.08041878599400383im ,
38
- - 0.14090692583679154 + 0.035230042290069444im ,
39
- 0.039899180711674635 + 0.004918236900383659im ,
40
- - 0.03857936468514856 - 0.04063999068714769im ]
41
-
42
- @test autocov (x1) ≈ racovx1
33
+ acovx1 = [0.755284179631112 + 0.0im ,
34
+ - 0.005333112170365584 - 0.18633291805458002im ,
35
+ - 0.28638133506011604 + 0.1397225175604478im ,
36
+ - 0.05476759020476188 + 0.12991227531087618im ,
37
+ - 0.00499902418309206 + 0.023463421186162473im ,
38
+ 0.11854989361702409 - 0.0028772373657594066im ,
39
+ - 0.005123812003979093 - 0.08041878599400383im ,
40
+ - 0.14090692583679154 + 0.035230042290069444im ,
41
+ 0.039899180711674635 + 0.004918236900383659im ,
42
+ - 0.03857936468514856 - 0.04063999068714769im ]
43
+
44
+ @test autocov (x1) ≈ acovx1
45
+ @test autocov (cmplx_x1) ≈ acovx1
43
46
@test autocov (x) ≈ [autocov (x1) autocov (x2)]
44
-
45
- racorx1 = [1.0 + 0.0im ,
46
- - 0.007061066965510023 - 0.24670570770539213im ,
47
- - 0.3791703080554228 + 0.18499330626611243im ,
48
- - 0.07251256107537019 + 0.17200449686941222im ,
49
- - 0.006618732813301651 + 0.031065686027770673im ,
50
- 0.1569606471499575 - 0.0038094765432061303im ,
51
- - 0.00678395250709688 - 0.106474871528861im ,
52
- - 0.18656146869859214 + 0.04664475073114351im ,
53
- 0.05282671316002114 + 0.0065117700502952056im ,
54
- - 0.051079270194684986 - 0.0538075492419246im ]
55
-
56
- @test autocor (x1) ≈ racorx1
47
+ @test autocov (cmplx_x) ≈ [autocov (cmplx_x1) autocov (cmplx_x2)]
48
+
49
+ acorx1 = [1.0 + 0.0im ,
50
+ - 0.007061066965510023 - 0.24670570770539213im ,
51
+ - 0.3791703080554228 + 0.18499330626611243im ,
52
+ - 0.07251256107537019 + 0.17200449686941222im ,
53
+ - 0.006618732813301651 + 0.031065686027770673im ,
54
+ 0.1569606471499575 - 0.0038094765432061303im ,
55
+ - 0.00678395250709688 - 0.106474871528861im ,
56
+ - 0.18656146869859214 + 0.04664475073114351im ,
57
+ 0.05282671316002114 + 0.0065117700502952056im ,
58
+ - 0.051079270194684986 - 0.0538075492419246im ]
59
+
60
+ @test autocor (x1) ≈ acorx1
61
+ @test autocor (cmplx_x1) ≈ acorx1
57
62
@test autocor (x) ≈ [autocor (x1) autocor (x2)]
63
+ @test autocor (cmplx_x) ≈ [autocor (cmplx_x1) autocor (cmplx_x2)]
64
+
58
65
59
66
# crosscov & crosscor
60
67
@@ -75,10 +82,14 @@ c11 = crosscov(x1, x1)
75
82
c12 = crosscov (x1, x2)
76
83
c21 = crosscov (x2, x1)
77
84
c22 = crosscov (x2, x2)
85
+ @test crosscov (cmplx_x1, cmplx_x2) ≈ c12
78
86
79
87
@test crosscov (x, x1) ≈ [c11 c21]
88
+ @test crosscov (cmplx_x, cmplx_x1) ≈ [c11 c21]
80
89
@test crosscov (x1, x) ≈ [c11 c12]
90
+ @test crosscov (cmplx_x1, cmplx_x) ≈ [c11 c12]
81
91
@test crosscov (x, x) ≈ cat ([c11 c21], [c12 c22], dims= 3 )
92
+ @test crosscov (cmplx_x, cmplx_x) ≈ cat ([c11 c21], [c12 c22], dims= 3 )
82
93
83
94
# issue #805: avoid converting one input to the other's eltype
84
95
@test crosscov ([34566.5345 , 3466.4566 ], Float16[1 , 10 ]) ≈
@@ -102,10 +113,14 @@ c11 = crosscor(x1, x1)
102
113
c12 = crosscor (x1, x2)
103
114
c21 = crosscor (x2, x1)
104
115
c22 = crosscor (x2, x2)
116
+ @test crosscor (cmplx_x1, cmplx_x2) ≈ c12
105
117
106
118
@test crosscor (x, x1) ≈ [c11 c21]
119
+ @test crosscor (cmplx_x, cmplx_x1) ≈ [c11 c21]
107
120
@test crosscor (x1, x) ≈ [c11 c12]
121
+ @test crosscor (cmplx_x1, cmplx_x) ≈ [c11 c12]
108
122
@test crosscor (x, x) ≈ cat ([c11 c21], [c12 c22], dims= 3 )
123
+ @test crosscor (cmplx_x, cmplx_x) ≈ cat ([c11 c21], [c12 c22], dims= 3 )
109
124
110
125
# issue #805: avoid converting one input to the other's eltype
111
126
@test crosscor ([34566.5345 , 3466.4566 ], Float16[1 , 10 ]) ≈
@@ -139,9 +154,10 @@ function toeplitz(v::AbstractVector{T}) where T
139
154
end
140
155
# durbin solver
141
156
acf = autocor (x1)
142
- p = [yulewalker_qr (acf[1 : n])[n- 1 ] for n in 2 : length (acf)]
143
- @test p ≈ StatsBase. durbin (acf[2 : end ])
144
-
145
- pacfy = [];
157
+ p_qr = [yulewalker_qr (acf[1 : n])[n- 1 ] for n in 2 : length (acf)]
158
+ y = similar (acf[2 : end ])
159
+ pd = similar (acf[2 : end ])
160
+ StatsBase. durbin! (acf[2 : end ], y, pd)
161
+ @test p_qr ≈ pd
146
162
147
- @test pacf (x1, 1 : 4 , method= :yulewalker ) ≈ - p [1 : 4 ]
163
+ @test pacf (x1, 1 : 4 , method= :yulewalker ) ≈ - p_qr [1 : 4 ]
0 commit comments