Skip to content

Commit f7819df

Browse files
authored
rqa can return an AbstractDict object. (#127)
* `rqa` can return an `AbstractDict` object. * `rqa` can return an `AbstractDict` object. * Added info on `AbstractDict` to `rqa` docs
1 parent 9273f9e commit f7819df

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RecurrenceAnalysis"
22
uuid = "639c3291-70d9-5ea2-8c5b-839eba1ee399"
33
repo = "https://github.com/JuliaDynamics/RecurrenceAnalysis.jl.git"
4-
version = "1.6.2"
4+
version = "1.6.3"
55

66
[deps]
77
DelayEmbeddings = "5732040d-69e3-5649-938a-b6b4f237613f"
@@ -24,6 +24,7 @@ UnicodePlots = "0.3, 1, 2"
2424
julia = "1.5"
2525

2626
[extras]
27+
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
2728
DynamicalSystemsBase = "6e36e845-645a-534a-86f2-f5d4aa5a06b4"
2829
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
2930
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
@@ -32,4 +33,4 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
3233
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3334

3435
[targets]
35-
test = ["Statistics", "Test", "SparseArrays", "Random", "DynamicalSystemsBase", "LightGraphs"]
36+
test = ["Statistics", "Test", "SparseArrays", "Random", "DynamicalSystemsBase", "LightGraphs","DataStructures"]

src/rqa/rqa.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ in order to replicate the output of different versions:
470470
* `rqa(NamedTuple, R...)` to obtain the output of the older version (as in 1.3).
471471
* `rqa(Dict, R...)` to obtain the output of the planned future version.
472472
* `rqa(RQA, R...)` to obtain the default current output (same as `rqa(R...)`)
473-
473+
* `rqa(DT,R...)` to obtain the output as `DT` which is a subtype of `AbstractDict` (e.g. `rqa(OrderedDict,R...)` returns an `OrderedDict`)
474474
"""
475475
rqa(R; kwargs...) = rqa(RQA, R; kwargs...)
476476

@@ -479,15 +479,15 @@ function rqa(::Type{RQA}, R; kwargs...)
479479
RQA(rqa_dict)
480480
end
481481

482-
function rqa(::Type{Dict}, R; onlydiagonal=false, kwargs...)
482+
function rqa(::Type{DT}, R; onlydiagonal=false, kwargs...) where {DT<:AbstractDict}
483483
# Parse arguments for diagonal and vertical structures
484484
kw_d = Dict(kwargs)
485485
haskey(kw_d, :theilerdiag) && (kw_d[:theiler] = kw_d[:theilerdiag])
486486
haskey(kw_d, :lmindiag) && (kw_d[:lmin] = kw_d[:lmindiag])
487487
dhist = diagonalhistogram(R; kw_d...)
488488
rr_d = recurrencerate(R; kw_d...)
489489
if onlydiagonal
490-
return Dict{Symbol, Float64}(
490+
return DT{Symbol, Float64}(
491491
:RR => recurrencerate(R; kwargs...),
492492
:DET => _determinism(dhist, rr_d*_rrdenominator(R; kw_d...)),
493493
:L => _dl_average(dhist),
@@ -501,7 +501,7 @@ function rqa(::Type{Dict}, R; onlydiagonal=false, kwargs...)
501501
haskey(kw_v, :lminvert) && (kw_v[:lmin] = kw_v[:lminvert])
502502
vhist, rthist = verticalhistograms(R; kw_v...)
503503
rr_v = recurrencerate(R; kw_v...)
504-
rqa_dict = Dict{Symbol, Float64}(
504+
rqa_dict = DT{Symbol, Float64}(
505505
:RR => rr_d,
506506
:DET => _determinism(dhist, rr_d*_rrdenominator(R; kw_v...)),
507507
:L => _dl_average(dhist),

test/dynamicalsystems.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using RecurrenceAnalysis
22
using DynamicalSystemsBase, Random, Statistics, SparseArrays
33
using LightGraphs, LinearAlgebra
44
using Test
5-
5+
using DataStructures
66
RA = RecurrenceAnalysis
77

88
rng = Random.seed!(194)
@@ -140,4 +140,9 @@ dict_keys = ["Sine wave","White noise","Hénon (chaotic)","Hénon (periodic)"]
140140
rc2 = coordinates(rmat.data)
141141
@test isequal(rc1[1],rc2[1])
142142
@test isequal(rc2[2],rc2[2])
143+
144+
145+
@test isa(rqa(rmat.data).data,Dict)
146+
@test isa(rqa(Dict,rmat.data),Dict)
147+
@test isa(rqa(OrderedDict,rmat.data),OrderedDict)
143148
end

0 commit comments

Comments
 (0)