From 8deb9a915a3e616493bc25a491eba91c821b1b46 Mon Sep 17 00:00:00 2001 From: Riccardo Foffi Date: Fri, 10 Jan 2025 13:00:10 +0100 Subject: [PATCH] Remove unfolding (#10) * remove unfolding * bump minor version --- Project.toml | 2 +- src/MeanSquaredDisplacement.jl | 3 -- src/unfold.jl | 59 ---------------------------------- test/runtests.jl | 29 ----------------- 4 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 src/unfold.jl diff --git a/Project.toml b/Project.toml index c56d987..7221725 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MeanSquaredDisplacement" uuid = "13c93d70-909c-440c-af92-39d48ffa2ba2" authors = ["Riccardo Foffi "] -version = "0.2.1" +version = "0.3.0" [deps] Autocorrelations = "b9118d5e-f165-4cbd-b2ae-b030566b7b26" diff --git a/src/MeanSquaredDisplacement.jl b/src/MeanSquaredDisplacement.jl index 05d87a3..1ce05e0 100644 --- a/src/MeanSquaredDisplacement.jl +++ b/src/MeanSquaredDisplacement.jl @@ -73,7 +73,4 @@ function imsd(x::AbstractVector, lags=0:size(x,1)-1) @. S₁ - 2S₂ end - -include("unfold.jl") - end # module MeanSquaredDisplacement diff --git a/src/unfold.jl b/src/unfold.jl deleted file mode 100644 index 9c702bd..0000000 --- a/src/unfold.jl +++ /dev/null @@ -1,59 +0,0 @@ -""" - unfold(x::AbstractVector, P) -Unfold timeseries `x` from a periodic domain extending from `0` to `P`. -""" -function unfold(x::AbstractVector, P) - y = deepcopy(x) - unfold!(y, P) - return y -end - -""" - unfold!(x::AbstractVector, P) -Unfold timeseries `x` from a periodic domain extending from `0` to `P`. -The periodicity `P` can be either a real number (for a cubic domain) or -a collection (`AbstractVector` or `NTuple`) with one value for each dimension. -""" -function unfold!(x::AbstractVector, P) - indices = eachindex(x) - ind_prev = @view indices[1:end-1] - ind_next = @view indices[2:end] - for (i,j) in zip(ind_prev, ind_next) - x0 = x[i] - x1 = x[j] - x[j] = unfold(x1, x0, P) - end - return x -end - -NTupleOrVec = Union{NTuple{D,<:Real},AbstractVector{<:Real}} where D -function unfold(x1::AbstractVector, x0::AbstractVector, P::Real) - @assert length(x1) == length(x0) - map(i -> unfold(x1[i], x0[i], P), eachindex(x1)) -end -function unfold(x1::NTuple{D}, x0::NTuple{D}, P::Real) where D - ntuple(i -> unfold(x1[i], x0[i], P), D) -end -function unfold(x1::AbstractVector, x0::AbstractVector, P::NTupleOrVec) - @assert length(x1) == length(x0) == length(P) - map(i -> unfold(x1[i], x0[i], P[i]), eachindex(x1)) -end -function unfold(x1::NTuple{D}, x0::NTuple{D}, P::NTupleOrVec) where D - @assert D == length(P) - ntuple(i -> unfold(x1[i], x0[i], P[i]), D) -end - -""" - unfold(x1::Real, x0::Real, P::Real) -Unfold the value of `x1` with respect to `x0` from a -domain of periodicity `P`. -""" -function unfold(x1::Real, x0::Real, P::Real) - dx = x1 - x0 - a = round(abs(dx / P)) - if abs(dx) > P/2 - return x1 - a*P*sign(dx) - else - return x1 - end -end diff --git a/test/runtests.jl b/test/runtests.jl index 622e5f6..0ac7962 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -45,33 +45,4 @@ using Test mb = [imsd(b); repeat([0.0], na-nb)] divisor = [repeat([2], nb); repeat([1], na-nb)] @test m ≈ (ma .+ mb) ./ divisor - - @testset "Unfolding" begin - function wrap(x,L) - s = x - while !(0 ≤ s < L) - δ = s < 0 ? +L : s > L ? -L : 0 - s += δ - end - return s - end - x = cumsum(rand(1000)) - # wrap trajectory between 0 and L - L = 10 - y = wrap.(x, L) - z = copy(y) - unfold!(y, L) - @test y ≈ x - y2 = unfold(x, L) - @test y2 == y - - Lx, Ly = 8.6, 13.0 - x = (1:100) .% Lx - y = (1:100) .% Ly - traj = Tuple.(zip(x,y)) - utraj = copy(traj) - unfold!(utraj, (Lx, Ly)) - @test first.(utraj) == (1:100) - @test last.(utraj) == (1:100) - end end