• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mtsch / Ripserer.jl / 8545078607

03 Apr 2024 08:26PM UTC coverage: 96.51% (+0.09%) from 96.417%
8545078607

Pull #166

github

web-flow
Merge ed46e50d4 into 3f2d63fae
Pull Request #166: Better homology

245 of 250 new or added lines in 5 files covered. (98.0%)

3 existing lines in 3 files now uncovered.

1770 of 1834 relevant lines covered (96.51%)

3302629.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.13
/src/base/simplexrecipes.jl
1
"""
2
    index_data(indices, args...)
3

4
Index into each arg with `indices`, placing `NaN`s where `indices` are zero.
5
"""
6
function index_data(indices, pts::AbstractVector{<:NTuple{N}}) where {N}
×
7
    return map(indices) do i
×
8
        i == 0 ? ntuple(_ -> NaN, N) : Float64.(pts[i])
×
9
    end
10
end
11
function index_data(indices, x::AbstractVector)
20✔
12
    return map(indices) do i
20✔
13
        i == 0 ? NaN : Float64(x[i])
245✔
14
    end
15
end
16
# images
17
function index_data(indices, x::AbstractMatrix)
×
18
    cart = CartesianIndices(x)
×
19
    return map(indices) do i
×
20
        i == 0 ? (NaN, NaN) : (cart[i][2], cart[i][1])
×
21
    end
22
end
23
function index_data(indices, x, y)
×
24
    return index_data(indices, x), index_data(indices, y)
×
25
end
26
function index_data(indices, x, y, z)
×
27
    return index_data(indices, x), index_data(indices, y), index_data(indices, z)
×
28
end
29

30
"""
31
    plottable(sx::AbstractCell, args...)
32
    plottable(sx::PersistenceInterval, args...)
33
    plottable(sx::Vector{<:AbstractCell}, args...)
34

35
Turn `sx` into a series that can be plotted. `args...`, should contain the data which tells
36
the plot where to place simplex vertices.
37
"""
38
function plottable(sx::AbstractCell, args...)
8✔
39
    return plottable([sx], args...)
8✔
40
end
41
function plottable(int::PersistenceInterval, args...)
×
42
    return plottable(simplex.(representative(int)), args...)
×
43
end
44
function plottable(rep::AbstractVector{<:AbstractChainElement}, args...)
×
45
    return plottable(simplex.(rep), args...)
×
46
end
47
function plottable(element::AbstractChainElement, args...)
×
48
    return plottable(simplex(element), args...)
×
49
end
50
function plottable(sxs::AbstractVector{<:AbstractCell{0}}, args...)
5✔
51
    indices = sort(only.(vertices.(sxs)))
5✔
52
    return index_data(indices, args...), [:seriestype => :scatter], 0
5✔
53
end
54
function plottable(sxs::AbstractVector{<:AbstractCell{1}}, args...)
5✔
55
    indices = mapreduce(vcat, vertices.(sxs)) do (u, v)
5✔
56
        [u, v, 0]
15✔
57
    end
58
    return index_data(indices, args...), [:seriestype => :path], 1
5✔
59
end
60
function plottable(sxs::AbstractVector{<:AbstractCell{D}}, args...) where {D}
10✔
61
    indices = mapreduce(vcat, vertices.(sxs)) do vs
10✔
62
        idxs = Int[]
10✔
63
        for (u, v, w) in subsets(vs, Val(3))
10✔
64
            append!(idxs, (u, v, w, u))
25✔
65
        end
40✔
66
        push!(idxs, 0)
10✔
UNCOV
67
        idxs
×
68
    end
69
    return index_data(indices, args...), [:seriestype => :path], D
10✔
70
end
71

72
function apply_threshold(sx::AbstractCell, thresh, thresh_strict)
4✔
73
    return birth(sx) ≤ thresh && birth(sx) < thresh_strict ? sx : nothing
4✔
74
end
75
function apply_threshold(sxs::AbstractVector{<:AbstractCell}, thresh, thresh_strict)
12✔
76
    return filter(sx -> birth(sx) ≤ thresh && birth(sx) < thresh_strict, sxs)
24✔
77
end
78
function apply_threshold(els::AbstractVector{<:AbstractChainElement}, thresh, thresh_strict)
4✔
79
    return apply_threshold(simplex.(els), thresh, thresh_strict)
4✔
80
end
81
function apply_threshold(int::PersistenceInterval, thresh, thresh_strict)
8✔
82
    if hasproperty(int, :representative)
8✔
83
        return apply_threshold(representative(int), thresh, thresh_strict)
4✔
84
    else
85
        error("interval has no representative. Run `ripserer` with `representatives=true`")
4✔
86
    end
87
end
88

89
@recipe function f(
×
90
    sx::Union{
91
        AbstractCell,
92
        AbstractChainElement,
93
        AbstractVector{<:AbstractCell},
94
        AbstractVector{<:AbstractChainElement},
95
        PersistenceInterval,
96
    },
97
    args...;
98
    threshold=Inf,
99
    threshold_strict=Inf,
100
)
101
    sx = apply_threshold(sx, threshold, threshold_strict)
20✔
102
    isnothing(sx) && return ()
16✔
103
    series, attrs, D = plottable(sx, args...)
16✔
104
    for (key, value) in attrs
16✔
105
        plotattributes[key] = get(plotattributes, key, value)
16✔
106
    end
16✔
107
    # splat colors and similar attributes over simplices
108
    for attr in keys(plotattributes)
16✔
109
        value = plotattributes[attr]
48✔
110
        if value isa Vector
48✔
111
            n = D < 2 ? D + 2 : 4 * binomial(D + 1, 3) + 1
×
112
            plotattributes[attr] = mapreduce(x -> fill(x, n), vcat, value)
×
113
        end
114
    end
48✔
115
    return series
16✔
116
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc