From 24c1b4bce38ab1abd35b8f5412a519a7ff46655f Mon Sep 17 00:00:00 2001 From: mtsch Date: Thu, 13 Aug 2020 19:43:55 +1200 Subject: [PATCH] Add `SparseRips` constructor with point cloud inputs (#79) * Add SparseRips constructor with points * bump version * add tests --- Project.toml | 2 +- src/ripsfiltration.jl | 3 +++ test/ripsfiltration.jl | 21 ++++++++++++++++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 84538c95..a5f364a2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Ripserer" uuid = "aa79e827-bd0b-42a8-9f10-2b302677a641" authors = ["mtsch "] -version = "0.14.2" +version = "0.14.3" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" diff --git a/src/ripsfiltration.jl b/src/ripsfiltration.jl index 0a79cd55..0778aeab 100644 --- a/src/ripsfiltration.jl +++ b/src/ripsfiltration.jl @@ -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] diff --git a/test/ripsfiltration.jl b/test/ripsfiltration.jl index 65bc476e..8f757380 100644 --- a/test/ripsfiltration.jl +++ b/test/ripsfiltration.jl @@ -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