Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/encoding_implementations/ordinal_pattern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function encode(encoding::OrdinalPatternEncoding{m}, χ::AbstractVector) where {
if m != length(χ)
throw(ArgumentError("Permutation order and length of input must match!"))
end
perm = sortperm!(encoding.perm, χ)
perm = sortperm!(encoding.perm, χ; lt = encoding.lt)
return permutation_to_integer(perm)
end

Expand Down Expand Up @@ -103,7 +103,7 @@ function decode(::OrdinalPatternEncoding{m}, s::Integer) where {m}
perm[i] = popat!(xs, f[i] + 1)
end

return SVector{m, Int}(perm) # converting from SVector to MVector is essentially free
return SVector{m, Int}(perm) # converting to SVector is free
end

"""
Expand Down
11 changes: 10 additions & 1 deletion test/encodings/encodings/ordinal_pattern_encoding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ end
@test missing_outcomes(OrdinalPatterns(; m, τ), x) == 0
end

@testset "Pretty printing" begin
@testset "Pretty printing" begin
o = OrdinalPatterns{3}()
@test occursin("OrdinalPatterns{3}", repr(o))
@test occursin("encoding = OrdinalPatternEncoding(perm = [0, 0, 0], lt = isless_rand), τ = 1", repr(o))
Expand All @@ -67,3 +67,12 @@ end
s = "[OrdinalPatterns{3}(encoding = OrdinalPatternEncoding(perm = [0, 0, 0], lt = isless_rand), τ = 1), OrdinalPatterns{3}(encoding = OrdinalPatternEncoding(perm = [0, 0, 0], lt = isless_rand), τ = 1), OrdinalPatterns{3}(encoding = OrdinalPatternEncoding(perm = [0, 0, 0], lt = isless_rand), τ = 1)]"
@test occursin(s, repr(os))
end

@testset "usage of isless" begin
o = OrdinalPatternEncoding{2}() # random is less
res = [encode(o, [1,1]) for i in 1:1000]
@test sort!(unique(res)) == [1, 2]
o = OrdinalPatternEncoding{2}(isless) # normal is less
res = [encode(o, [1,1]) for i in 1:1000]
@test unique(res) == [1]
end