Skip to content

Commit

Permalink
Replace LightGraphs.jl with Graphs.jl (#154)
Browse files Browse the repository at this point in the history
* Use Graphs.jl instead of LightGraphs.jl

* Formatting

* Don't test on Julia 1.0

* Update changelog

* Fix tests and docs example

* Don't test ambiguities
  • Loading branch information
mtsch authored Jan 5, 2022
1 parent cfce440 commit 9539139
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 31 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
julia-version: ['1.0', '1', 'nightly']
julia-version: ['1.6', '1', 'nightly']
name: ${{ matrix.julia-version }}
steps:
- uses: actions/checkout@v2
- name: MiniQHull deps
run: sudo apt-get install gcc libqhull-r7 libqhull-dev
if: ${{ matrix.julia-version == '1.0' }}
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.16.9

Replace LightGraps with Graphs.

# v0.16.4

Add [MLJ.jl](https://github.com/alan-turing-institute/MLJ.jl) support.
Expand All @@ -17,7 +21,7 @@ External changes:

Interface changes:

* All filtration constructors should now have to take `verbose` as a keyword argument.
* All filtration constructors now have to take `verbose` as a keyword argument.
* Replaced vectors of `ChainElement`s with `Chain`s.
* Added `AbstractCell`.
* `Cube` is now an `AbstractCell`, `AbstractSimplex` is reserved for actual simplices.
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name = "Ripserer"
uuid = "aa79e827-bd0b-42a8-9f10-2b302677a641"
authors = ["mtsch <matijacufar@gmail.com>"]
version = "0.16.8"
version = "0.16.9"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
Future = "9fa8497b-333b-5362-9e8d-4d0656e87820"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MLJModelInterface = "e80e1ace-859a-464e-9ed9-23947d8ae3ea"
MiniQhull = "978d7f02-9e05-4691-894f-ae31a51d76ca"
Expand All @@ -24,8 +24,8 @@ TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
Compat = "3.10.0"
DataStructures = "0.17, 0.18"
Distances = "0.8, 0.9, 0.10"
Graphs = "1"
IterTools = "1"
LightGraphs = "1.3.3"
MLJModelInterface = "^0.3.5, 0.4, 1"
MiniQhull = "0.2, 0.3"
PersistenceDiagrams = "0.9"
Expand Down
2 changes: 1 addition & 1 deletion benchmark/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using SparseArrays

function load_points(filename)
# ripser uses Float32
table = CSV.File(filename; header=0, type=Float32, delim=' ')
table = CSV.File(filename; header=0, types=Float32, delim=' ')
nrow = length(table)
dim = length(table[1])
result = Vector{NTuple{dim,Float32}}(undef, nrow)
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/malaria.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ nothing # hide
# pretend we were only given 200 images to work with. We have chosen the 200 images
# randomly.

uninfected = shuffle!(load.(readdir(joinpath(data_dir, "uninfected"); join=true)))
infected = shuffle!(load.(readdir(joinpath(data_dir, "infected"); join=true)))
uninfected = shuffle!(Images.load.(readdir(joinpath(data_dir, "uninfected"); join=true)))
infected = shuffle!(Images.load.(readdir(joinpath(data_dir, "infected"); join=true)))

images = [uninfected; infected]
classes = [fill(false, length(uninfected)); fill(true, length(infected))]
Expand Down
4 changes: 2 additions & 2 deletions src/Ripserer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using SparseArrays
using DataStructures
using Distances
using IterTools
using LightGraphs
using Graphs
using MiniQhull
using PersistenceDiagrams
using ProgressMeter
Expand All @@ -29,7 +29,7 @@ import MLJModelInterface

# This functionality is imported to avoid having to deal with name clashes. There is no
# piracy involved here.
import LightGraphs: vertices, edges, nv, adjacency_matrix
import Graphs: vertices, edges, nv, adjacency_matrix

# Reexporting basics makes Ripserer usable without having to import another package.
import PersistenceDiagrams: birth, threshold, dim
Expand Down
24 changes: 12 additions & 12 deletions src/extra/cycles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ _in(σ, g::OneSkeleton) = !isnothing(σ) && birth(σ) ≤ g.threshold && σ ∉
_linear(g, i) = LinearIndices(vertices(g.filtration))[i]
_inv_linear(g, i) = vertices(g.filtration)[i]

LightGraphs.edgetype(::OneSkeleton) = Edge{Int}
Graphs.edgetype(::OneSkeleton) = Edge{Int}

function LightGraphs.has_edge(g::OneSkeleton, u::Integer, v::Integer)
function Graphs.has_edge(g::OneSkeleton, u::Integer, v::Integer)
if u vertices(g) || v vertices(g)
return false
else
Expand All @@ -44,7 +44,7 @@ function LightGraphs.has_edge(g::OneSkeleton, u::Integer, v::Integer)
end
end

function LightGraphs.edges(g::OneSkeleton)
function Graphs.edges(g::OneSkeleton)
result = edgetype(g)[]
for sx in Ripserer.edges(g.filtration)
if _in(sx, g)
Expand All @@ -54,7 +54,7 @@ function LightGraphs.edges(g::OneSkeleton)
end
return result
end
function LightGraphs.outneighbors(g::OneSkeleton, u::Integer)
function Graphs.outneighbors(g::OneSkeleton, u::Integer)
root = simplex(g.filtration, Val(0), (_inv_linear(g, u),))
neighbors = Int[]
for sx in Ripserer.coboundary(g.filtration, root)
Expand All @@ -69,18 +69,18 @@ function LightGraphs.outneighbors(g::OneSkeleton, u::Integer)
end
return neighbors
end
LightGraphs.inneighbors(g::OneSkeleton, u::Integer) = outneighbors(g, u)
Graphs.inneighbors(g::OneSkeleton, u::Integer) = outneighbors(g, u)

Base.eltype(::OneSkeleton) = Int
LightGraphs.has_vertex(g::OneSkeleton, u) = 1 u nv(g)
LightGraphs.ne(g::OneSkeleton) = length(edges(g))
LightGraphs.nv(g::OneSkeleton) = nv(g.filtration)
LightGraphs.vertices(g::OneSkeleton) = Base.OneTo(nv(g))
LightGraphs.is_directed(::OneSkeleton) = false
LightGraphs.is_directed(::Type{<:OneSkeleton}) = false
Graphs.has_vertex(g::OneSkeleton, u) = 1 u nv(g)
Graphs.ne(g::OneSkeleton) = length(edges(g))
Graphs.nv(g::OneSkeleton) = nv(g.filtration)
Graphs.vertices(g::OneSkeleton) = Base.OneTo(nv(g))
Graphs.is_directed(::OneSkeleton) = false
Graphs.is_directed(::Type{<:OneSkeleton}) = false

# need default dist for filtrations...
LightGraphs.weights(g::OneSkeleton) = g.weights
Graphs.weights(g::OneSkeleton) = g.weights

_heuristic(filtration, src, distances) = dst -> distances[dst, src]
function _path_length(dists, cyc)
Expand Down
4 changes: 2 additions & 2 deletions test/extra/cycles.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using LightGraphs
using Graphs
using Ripserer
using Test

using Ripserer: distance_matrix, OneSkeleton

@testset "OneSkeleton respects the LightGraphs interface" begin
@testset "OneSkeleton respects the Graphs interface" begin
@testset "no threshold or removed simplices" begin
flt = Rips(
[
Expand Down
8 changes: 4 additions & 4 deletions test/extra/mlj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ function test_mlj_model(model, X)
Xt = transform(mach, X)

@test nrows(Xt) == length(X)
@test length(first(Xt)) 30
@test length(propertynames(Xt)) 30

model.vectorizer = PersistenceCurveVectorizer()
fit!(mach; verbosity=0)
Xt = transform(mach, X)

@test nrows(Xt) == length(X)
@test length(first(Xt)) == 20
@test length(propertynames(Xt)) == 20

model.vectorizer.length = 100
fit!(mach; verbosity=0)
Xt = transform(mach, X)
@test nrows(Xt) == length(X)
@test length(first(Xt)) == 200
@test length(propertynames(Xt)) == 200

model.dim_max = 2
fit!(mach; verbosity=0)
Xt = transform(mach, X)
@test nrows(Xt) == length(X)
@test length(first(Xt)) == 300
@test length(propertynames(Xt)) == 300
end

@testset "Rips" begin
Expand Down

2 comments on commit 9539139

@mtsch
Copy link
Owner Author

@mtsch mtsch commented on 9539139 Jan 5, 2022

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/51693

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.16.9 -m "<description of version>" 95391396bea1b2b922967f7da21de05d6b3b67bb
git push origin v0.16.9

Please sign in to comment.