Skip to content

Commit

Permalink
Calculate n_vertices from dist in Rips filtrations, fix unsafe_co…
Browse files Browse the repository at this point in the history
…facet (#61)

* n_vertices calculated from dist

* fix argument order in unsafe_cofacet
  • Loading branch information
mtsch authored Jun 27, 2020
1 parent d2961fa commit cb6dff1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
16 changes: 8 additions & 8 deletions src/abstractfiltration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ simplices.
* [`simplex_type(::AbstractFiltration, dim)`](@ref)
* [`simplex(::AbstractFiltration, ::Val{dim}, vertices, sign)`](@ref)
* [`unsafe_simplex(::AbstractFiltration, ::Val{dim}, vertices, sign)`](@ref)
* [`unsafe_cofacet`](@ref)`(::AbstractFiltration, simplex, vertices, vertex[, edges, sign])`
* [`unsafe_cofacet`](@ref)`(::AbstractFiltration, simplex, vertices, vertex[, sign, edges])`
* [`birth(::AbstractFiltration, v)`](@ref)
* [`threshold(::AbstractFiltration)`](@ref)
* [`postprocess_interval(::AbstractFiltration, ::Any)`](@ref)
Expand Down Expand Up @@ -73,7 +73,7 @@ to ensure vertices are sorted and unique.
unsafe_simplex(::AbstractFiltration, ::Val, vertices, sign)

"""
unsafe_cofacet(filtration, simplex, cofacet_vertices, new_vertex[, edges, sign=1])
unsafe_cofacet(filtration, simplex, cofacet_vertices, new_vertex, sign[, edges])
Return cofacet of `simplex` with vertices equal to `cofacet_vertices`. `new_vertex` is the
vertex that was added to construct the cofacet. In the case of sparse rips filtrations, an
Expand All @@ -86,12 +86,12 @@ unique.
Default implementation uses [`unsafe_simplex`](@ref).
"""
function unsafe_cofacet(
flt::AbstractFiltration, ::AbstractSimplex{D}, vertices, v, sign=1
) where D
return unsafe_simplex(flt, Val(D + 1), vertices, sign)
end
function unsafe_cofacet(
flt::AbstractFiltration, ::AbstractSimplex{D}, vertices, v, edges::SVector, sign=1
flt::AbstractFiltration,
::AbstractSimplex{D},
vertices,
v,
sign,
edges=nothing
) where D
return unsafe_simplex(flt, Val(D + 1), vertices, sign)
end
Expand Down
19 changes: 10 additions & 9 deletions src/ripsfiltration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
An abstract Vietoris-Rips filtration. Its subtypes can overload [`dist`](@ref) and get the
following default implementations.
* [`n_vertices`](@ref)
* [`edges`](@ref)
* [`simplex_type`](@ref).
* [`simplex`](@ref).
* [`unsafe_simplex`](@ref).
* [`unsafe_cofacet`](@ref).
* [`simplex_type`](@ref)
* [`simplex`](@ref)
* [`unsafe_simplex`](@ref)
* [`unsafe_cofacet`](@ref)
"""
abstract type AbstractRipsFiltration{I<:Signed, T} <: AbstractFiltration end

Expand All @@ -21,6 +22,8 @@ return `missing` instead. If `u` and `v` are not given, return the distance matr
"""
dist(::AbstractRipsFiltration, ::Any, ::Any)

n_vertices(rips::AbstractRipsFiltration) = size(dist(rips), 1)

simplex_type(::AbstractRipsFiltration{I, T}, dim) where {I, T} = Simplex{dim, T, I}

function unsafe_simplex(
Expand Down Expand Up @@ -52,7 +55,7 @@ end
simplex::IndexedSimplex{D},
cofacet_vertices,
new_vertex,
sign=1,
sign,
) where {I, T, D}
diameter = diam(simplex)
for v in cofacet_vertices
Expand All @@ -75,8 +78,8 @@ end
sx::IndexedSimplex{D},
cofacet_vertices,
::Any,
sign,
new_edges::SVector,
sign=1,
) where {I, D}
new_diam = diam(sx)
for i in 1:D + 1
Expand Down Expand Up @@ -187,7 +190,6 @@ end
end
dist(rips::Rips) = rips.dist

n_vertices(rips::Rips) = size(rips.dist, 1)
threshold(rips::Rips) = rips.threshold
birth(rips::Rips, i) = rips.dist[i, i]

Expand Down Expand Up @@ -232,7 +234,6 @@ end
end
dist(rips::SparseRips) = rips.dist

n_vertices(rips::SparseRips) = size(rips.dist, 1)
threshold(rips::SparseRips) = rips.threshold
birth(rips::SparseRips, i) = rips.dist[i, i]
simplex_type(::SparseRips{I, T}, dim) where {I, T} = Simplex{dim, T, I}
Expand Down Expand Up @@ -314,7 +315,7 @@ function Base.iterate(
new_vertices = insert(it.vertices, D - k + 1, v)
new_edges = nzval[ptrs]
sx = unsafe_cofacet(
it.filtration, it.simplex, new_vertices, v, new_edges, sign
it.filtration, it.simplex, new_vertices, v, sign, new_edges
)
if !isnothing(sx)
_sx::simplex_type(it.filtration, D) = sx
Expand Down

2 comments on commit cb6dff1

@mtsch
Copy link
Owner Author

@mtsch mtsch commented on cb6dff1 Jun 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/17049

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.0 -m "<description of version>" cb6dff1f14b3b5cbf9c5cedb70e226ba85b7727b
git push origin v0.12.0

Please sign in to comment.