mdmultispec silently modifies input
Issue #27
closed
mdmultispec
modifies the input vector x
in place without declaring this in the docs:
julia> using Multitaper
julia> x = collect(1:10)
y = rand(10)
y′ = copy(y)
mdmultispec(x, y′)
y == y′
false
This is because x
is modified in place in multispec_coef
at src/MDmwps.jl:48
:
function multispec_coef(tt, x, u, n, nfft, nfft2)
x .-= mean(x)
Two possible solutions:
- Modify
multispec_coef
so thatx̂ = x .- mean(x)
, and using the new vector`x̂`
which has the mean removed. (Preferred option probably.) - Change the name of
multispec_coef
tomultispec_coef!
, document that thex
argument is updated, and do likewise formdmultispec
→mdmultispec!
Comments (3)
-
repo owner -
reporter This is great, thanks.
Usually when bugs are found, I would also add a test to check things work as per the fix. I’m not sure that is so strictly needed here, though, and I’m happy with this fix.
-
repo owner - changed status to closed
Thanks, will test in the future.
- Log in to comment
I’m glad you caught this. I’ve followed your first suggestion here.