Skip to content

Commit af9e1dc

Browse files
kagalenko-m-bkagalenko-m-b
kagalenko-m-b
authored and
kagalenko-m-b
committed
Apply suggestions from code review
1 parent 2efdf68 commit af9e1dc

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

src/signalcorr.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ function crosscov!(r::AbstractMatrix, x::AbstractVector, y::AbstractMatrix, lags
302302
return r
303303
end
304304

305-
function crosscov!(r::AbstractArray{U,3} where U, x::AbstractMatrix, y::AbstractMatrix, lags::AbstractVector{<:Integer}; demean::Bool=true)
305+
function crosscov!(r::AbstractArray{<:Any}, x::AbstractMatrix, y::AbstractMatrix, lags::AbstractVector{<:Integer}; demean::Bool=true)
306306
lx = size(x, 1)
307307
nx = size(x, 2)
308308
ny = size(y, 2)
@@ -458,7 +458,7 @@ function crosscor!(r::AbstractMatrix, x::AbstractVector, y::AbstractMatrix, lags
458458
return r
459459
end
460460

461-
function crosscor!(r::AbstractArray{U,3} where U, x::AbstractMatrix, y::AbstractMatrix, lags::AbstractVector{<:Integer}; demean::Bool=true)
461+
function crosscor!(r::AbstractArray{<:Any}, x::AbstractMatrix, y::AbstractMatrix, lags::AbstractVector{<:Integer}; demean::Bool=true)
462462
lx = size(x, 1)
463463
nx = size(x, 2)
464464
ny = size(y, 2)

src/toeplitzsolvers.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,24 @@
33
44
Solve Yule-Walker equations using Durbin algorithm.
55
6-
Solution of NxN system is obtained iteratively, by solving 1x1, 2x2, ...
6+
Solution of N×N system is obtained iteratively, by solving 1×1, 2×2, ...
77
in succession. For use in computing partial autocorrelation matrix,
8-
return the last elements of the successive solutions in vector p[].
8+
return the last elements of the successive solutions in vector `p`.
99
10-
The section 4.7 of Golub,VanLoan "Matrix Computations," 4th ed.,
11-
discusses the algorithm in detail.
10+
Reference: Golub, G. H., and C. F. Van Loan. "Matrix computations 4th edition the johns hopkins university press." Baltimore, MD (2013), section 4.7
1211
1312
# Arguments
14-
- `r::AbstractVector`: first column of a herimitian positive definite
13+
- `r::AbstractVector`: first column of a Herimitian positive definite
1514
Toeplitz matrix, excluding the diagonal element (equal to one).
1615
- `y::AbstractVector`: work vector for solution, should have the same length
17-
as r[]
16+
as `r`
1817
- `p::AbstractVector`: last elements of the successive solutions, should
19-
have the same length as r[]
18+
have the same length as `r`
2019
2120
# Returns
22-
- `y::AbstractVector`: same as the second argument
21+
- `y::AbstractVector`: return the solution vector (same as the second argument)
2322
"""
24-
function durbin!(r::AbstractVector{T}, y::AbstractVector{T}, p::AbstractVector{T}) where T
23+
function durbin!(r::AbstractVector{T}, y::AbstractVector{T}, p::AbstractVector{T}) where {T}
2524
n = length(r)
2625
n <= length(p) || n <= length(y) || throw(DimensionMismatch("Auxiliary vectors cannot be shorter than data vector"))
2726
y[1] = -r[1]
@@ -48,7 +47,7 @@ function durbin!(r::AbstractVector{T}, y::AbstractVector{T}, p::AbstractVector{T
4847
end
4948
return y
5049
end
51-
durbin(r::AbstractVector{T}) where T = durbin!(r, zeros(T, length(r)), zeros(T, length(r)))
50+
durbin(r::AbstractVector{T}) where {T} = durbin!(r, zeros(T, length(r)), zeros(T, length(r)))
5251

5352
function levinson!(r::AbstractVector{T}, b::AbstractVector{T}, x::AbstractVector{T}) where T<:BlasReal
5453
n = length(b)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tests = ["ambiguous",
1515
"hist",
1616
"rankcorr",
1717
"signalcorr",
18+
"signalcorr_real",
1819
"misc",
1920
"pairwise",
2021
"reliability",

test/signalcorr_complex.jl renamed to test/signalcorr.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ cmplx_x2 = convert(AbstractVector{Complex}, x2)
2929

3030
@test autocov([1:5;]) [2.0, 0.8, -0.2, -0.8, -0.8]
3131
@test autocor([1, 2, 3, 4, 5]) [1.0, 0.4, -0.1, -0.4, -0.4]
32+
@test_throws MethodError autocov([1 missing 2 3 4 5])
33+
@test_throws MethodError autocor([1 missing 2 3 4 5])
3234

3335
acovx1 = [0.755284179631112 + 0.0im,
3436
-0.005333112170365584 - 0.18633291805458002im,
@@ -90,6 +92,7 @@ c22 = crosscov(x2, x2)
9092
@test crosscov(cmplx_x1, cmplx_x) [c11 c12]
9193
@test crosscov(x, x) cat([c11 c21], [c12 c22], dims=3)
9294
@test crosscov(cmplx_x, cmplx_x) cat([c11 c21], [c12 c22], dims=3)
95+
@test_throws MethodError crosscov([1 6; 2 7; missing 8; 3 9; 4 10; 5 11])
9396

9497
rcor0 = [0.230940107675850,
9598
-0.230940107675850,
@@ -116,7 +119,7 @@ c22 = crosscor(x2, x2)
116119
@test crosscor(cmplx_x1, cmplx_x) [c11 c12]
117120
@test crosscor(x, x) cat([c11 c21], [c12 c22], dims=3)
118121
@test crosscor(cmplx_x, cmplx_x) cat([c11 c21], [c12 c22], dims=3)
119-
122+
@test_throws MethodError crosscor([1 6; 2 7; missing 8; 3 9; 4 10; 5 11])
120123

121124
## pacf least squares
122125
pacf_ls = [-1.598495044296996e-03 - 2.915104118351207e-01im
@@ -134,7 +137,7 @@ function yulewalker_qr(v::AbstractVector)
134137
x = -A\b
135138
end
136139
function toeplitz(v::AbstractVector{T}) where T
137-
N=length(v)
140+
N = length(v)
138141
A = zeros(T, N - 1, N - 1)
139142
for n in 1:N-1
140143
A[n, n+1:end] = conj(v[2:N-n])

0 commit comments

Comments
 (0)