Skip to content

Commit

Permalink
Add SparseRips constructor with point cloud inputs (#79)
Browse files Browse the repository at this point in the history
* Add SparseRips constructor with points

* bump version

* add tests
  • Loading branch information
mtsch authored Aug 13, 2020
1 parent b3af06c commit 24c1b4b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Ripserer"
uuid = "aa79e827-bd0b-42a8-9f10-2b302677a641"
authors = ["mtsch <matijacufar@gmail.com>"]
version = "0.14.2"
version = "0.14.3"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
3 changes: 3 additions & 0 deletions src/ripsfiltration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ end
function SparseRips(dist; threshold=nothing)
return SparseRips{Int}(dist; threshold=threshold)
end
function SparseRips{I}(points::AbstractVector; metric=Euclidean(), kwargs...) where I
return SparseRips{I}(distances(metric, points); kwargs...)
end

@propagate_inbounds function dist(rips::SparseRips{<:Any, T}, i, j) where T
res = rips.dist[i, j]
Expand Down
21 changes: 16 additions & 5 deletions test/ripsfiltration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,24 @@ for Filtration in (Rips, SparseRips)
end

@testset "Rips points constructor" begin
filtration = Rips([(sin(x), cos(x)) for x in range(0, 2π, length=100)])
@test all(x -> x > 0, dist(filtration, i, j) for i in 1:10 for j in i+1:9)
filtration = Rips(
[(sin(x), cos(x)) for x in range(0, 2π, length=101)[1:end-1]]
)
@test all(x -> x > 0, dist(filtration, i, j) for i in 1:100 for j in i+1:100)
@test eltype(edges(filtration)) === Simplex{1, Float64, Int}

filtration = Rips{Int32}([(sin(x), cos(x)) for x in range(0, 2π, length=100)])
@test all(x -> x > 0, dist(filtration, i, j) for i in 1:10 for j in i+1:9)
@test eltype(edges(filtration)) === Simplex{1, Float64, Int32}
filtration = Rips{Int32}(
[(sin(x), cos(x)) for x in range(0f0, 2f0π, length=101)[1:end-1]]
)
@test all(x -> x > 0, dist(filtration, i, j) for i in 1:100 for j in i+1:100)
@test eltype(edges(filtration)) === Simplex{1, Float32, Int32}
end

@testset "Rips points constructor" begin
filtration = SparseRips(
[(sin(x), cos(x)) for x in range(0, 2π, length=101)[1:end-1]], threshold=0.1
)
@test maximum(dist(filtration)) 0.1
end

@testset "Errors" begin
Expand Down

2 comments on commit 24c1b4b

@mtsch
Copy link
Owner Author

@mtsch mtsch commented on 24c1b4b Aug 13, 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/19421

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.14.3 -m "<description of version>" 24c1b4bce38ab1abd35b8f5412a519a7ff46655f
git push origin v0.14.3

Please sign in to comment.