You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
smooth!() in src/tools.jl might cause unexpected array size change for 1d Array as follows:
using SeisNoise
t = collect(0.0:0.05:60.0)
A = sin.(0.2*pi.*t)
# first time
smooth!(A);
len1 = length(A)
# second time
smooth!(A);
len2 = length(A)
# third time
smooth!(A);
len3 = length(A)
I found that the movingaverage() could cause this issue; the modification of A::AbstractArray seems to affect the returned value (although it shouldn't be without !). So this might be Julia-related issue.
For the moment, I modified them as follows:
function smooth_debug!(A::AbstractArray, half_win::Int=3)
if ndims(A) == 1
return movingaverage_debug(A,half_win)
end
Nrows, Ncols = size(A)
for ii = 1:Ncols
A[:,ii] .= movingaverage_debug(A[:,ii],half_win)
end
return nothing
end
function movingaverage_debug(U::AbstractArray, half_win::Int=3)
#NOTE: avoid to rewrite A
A = deepcopy(U)
#----------#
prepend!(A,A[1:half_win])
append!(A,A[end-half_win:end])
N = length(A)
B = zeros(eltype(A),N)
window_len = 2 * half_win + 1
s = sum(A[1:window_len])
B[half_win+1] = s
for ii = half_win+2:N-half_win
s = s - A[ii-half_win] + A[ii+half_win]
B[ii] = s
end
B ./= window_len
return B[half_win+1:end-half_win-1]
end
And it's solved:
B = sin.(0.2*pi.*t)
# first time
smooth_debug!(B);
len1 = length(B)
# second time
smooth_debug!(B);
len2 = length(B)
# third time
smooth_debug!(B);
len3 = length(B)
Thanks for pointing this out. I think the smooth function as currently implemented assumes a 2D array. I added a new version of the smooth function to the GPU branch a54a642. This removes the dependence on movingaverage and should work for any dimension. It's also faster (for 2D arrays) and works on the GPU! Since this is a bug, I'll push this commit to master.
Hi Tim,
smooth!()
in src/tools.jl might cause unexpected array size change for 1d Array as follows:OUTPUT:
I found that the
movingaverage()
could cause this issue; the modification ofA::AbstractArray
seems to affect the returned value (although it shouldn't be without!
). So this might be Julia-related issue.For the moment, I modified them as follows:
And it's solved:
OUTPUT:
Can you manage that until we figure out the call by reference in Julia?
Kurama
The text was updated successfully, but these errors were encountered: