Skip to content

Commit

Permalink
Speed up detrend with stable typing
Browse files Browse the repository at this point in the history
  • Loading branch information
tclements committed Sep 17, 2019
1 parent 527a486 commit 3ad6119
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ArrayFuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ export detrend, detrend!, demean, demean!, bandpass, bandpass!, bandstop, bandst
Remove linear trend from array `X` using least-squares regression.
"""
function detrend!(X::AbstractArray{<:Union{Float32,Float64},1})
T = eltype(X)
N = length(X)
A = ones(N,2)
A[:,1] = Array(1:N) ./ N
A = ones(T,N,2)
A[:,1] .= range(T(1/N),T(1),length=N)
coeff = A \ X
X[:] .= X .- A *coeff
return nothing
Expand Down

0 comments on commit 3ad6119

Please sign in to comment.