Skip to content

Commit

Permalink
rename simplex tree coercers to specify interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
corybrunson committed Jun 17, 2022
1 parent 1ab4372 commit 3bb125f
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 107 deletions.
22 changes: 11 additions & 11 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ S3method(as_network,default)
S3method(as_network,gudhi.simplex_tree.SimplexTree)
S3method(as_network,igraph)
S3method(as_network,network)
S3method(as_py_gudhi,Rcpp_SimplexTree)
S3method(as_py_gudhi,default)
S3method(as_py_gudhi,igraph)
S3method(as_py_gudhi,network)
S3method(as_simplextree,Rcpp_SimplexTree)
S3method(as_simplextree,default)
S3method(as_simplextree,gudhi.simplex_tree.SimplexTree)
S3method(as_simplextree,igraph)
S3method(as_simplextree,network)
S3method(as_py_gudhi_simplextree,Rcpp_SimplexTree)
S3method(as_py_gudhi_simplextree,default)
S3method(as_py_gudhi_simplextree,igraph)
S3method(as_py_gudhi_simplextree,network)
S3method(as_rcpp_simplextree,Rcpp_SimplexTree)
S3method(as_rcpp_simplextree,default)
S3method(as_rcpp_simplextree,gudhi.simplex_tree.SimplexTree)
S3method(as_rcpp_simplextree,igraph)
S3method(as_rcpp_simplextree,network)
export(as_cmplx)
export(as_igraph)
export(as_network)
export(as_py_gudhi)
export(as_simplextree)
export(as_py_gudhi_simplextree)
export(as_rcpp_simplextree)
2 changes: 1 addition & 1 deletion R/as-igraph.r
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ as_igraph.Rcpp_SimplexTree <- function(x, index = NULL, ...) {
res
}

#' @rdname as_simplextree
#' @rdname as_igraph
#' @export
as_igraph.gudhi.simplex_tree.SimplexTree <- function(x, index = NULL, ...) {

Expand Down
24 changes: 12 additions & 12 deletions R/as-py-gudhi.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#'
#' @details
#'
#' `as_py_gudhi()` is a generic function with specific methods for different
#' simplicial complex S3 classes. It returns an object of class
#' `as_py_gudhi_simplextree()` is a generic function with specific methods for
#' different simplicial complex S3 classes. It returns an object of class
#' 'gudhi.simplex_tree.SimplexTree', which is a
#' [reticulate][reticulate::reticulate] accessor to a Python object of class
#' 'SimplexTree' implemented in GUDHI.
Expand All @@ -23,11 +23,11 @@
#' @author Jason Cory Brunson
#' @author Yara Skaf
#' @export
as_py_gudhi <- function(x, ...) UseMethod("as_py_gudhi")
as_py_gudhi_simplextree <- function(x, ...) UseMethod("as_py_gudhi_simplextree")

#' @rdname as_py_gudhi
#' @rdname as_py_gudhi_simplextree
#' @export
as_py_gudhi.default <- function(x, ...) {
as_py_gudhi_simplextree.default <- function(x, ...) {
x <- ensure_cmplx(x)
x <- ensure_list(x)
# import GUDHI
Expand All @@ -40,9 +40,9 @@ as_py_gudhi.default <- function(x, ...) {
res
}

#' @rdname as_py_gudhi
#' @rdname as_py_gudhi_simplextree
#' @export
as_py_gudhi.Rcpp_SimplexTree <- function(x, ...) {
as_py_gudhi_simplextree.Rcpp_SimplexTree <- function(x, ...) {
# import GUDHI
gd <- reticulate::import("gudhi")

Expand All @@ -68,9 +68,9 @@ as_py_gudhi.Rcpp_SimplexTree <- function(x, ...) {
res
}

#' @rdname as_py_gudhi
#' @rdname as_py_gudhi_simplextree
#' @export
as_py_gudhi.igraph <- function(x, index = NULL, ...) {
as_py_gudhi_simplextree.igraph <- function(x, index = NULL, ...) {
if (! is.null(index)) ensure_index(x, index)
# import GUDHI
gd <- reticulate::import("gudhi")
Expand All @@ -91,13 +91,13 @@ as_py_gudhi.igraph <- function(x, index = NULL, ...) {
res
}

#' @rdname as_py_gudhi
#' @rdname as_py_gudhi_simplextree
#' @export
as_py_gudhi.network <- function(x, index = NULL, ...) {
as_py_gudhi_simplextree.network <- function(x, index = NULL, ...) {

# coerce to an igraph object
x <- intergraph::asIgraph(x, ...)

# invoke 'igraph' method
as_py_gudhi(x, index = index)
as_py_gudhi_simplextree(x, index = index)
}
28 changes: 14 additions & 14 deletions R/as-simplextree.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#'
#' @details
#'
#' `as_simplextree()` is a generic function with specific methods for different
#' simplicial complex S3 classes. It returns an object of class
#' `as_rcpp_simplextree()` is a generic function with specific methods for
#' different simplicial complex S3 classes. It returns an object of class
#' ['Rcpp_SimplexTree'][simplextree::Rcpp_SimplexTree], which is an [Rcpp
#' Module][Rcpp::Module] that exposes an instance of a C++ instance of a simplex
#' tree.
Expand All @@ -21,11 +21,11 @@
#' 'Rcpp_SimplexTree'.
#' @example inst/examples/ex-as-simplextree.r
#' @export
as_simplextree <- function(x, ...) UseMethod("as_simplextree")
as_rcpp_simplextree <- function(x, ...) UseMethod("as_rcpp_simplextree")

#' @rdname as_simplextree
#' @rdname as_rcpp_simplextree
#' @export
as_simplextree.default <- function(x, ...) {
as_rcpp_simplextree.default <- function(x, ...) {
x <- ensure_cmplx(x)
x <- ensure_list(x)

Expand All @@ -35,13 +35,13 @@ as_simplextree.default <- function(x, ...) {
res
}

#' @rdname as_simplextree
#' @rdname as_rcpp_simplextree
#' @export
as_simplextree.Rcpp_SimplexTree <- function(x, ...) x
as_rcpp_simplextree.Rcpp_SimplexTree <- function(x, ...) x

#' @rdname as_simplextree
#' @rdname as_rcpp_simplextree
#' @export
as_simplextree.gudhi.simplex_tree.SimplexTree <- function(x, ...) {
as_rcpp_simplextree.gudhi.simplex_tree.SimplexTree <- function(x, ...) {

# initialize simplex tree
res <- simplextree::simplex_tree()
Expand All @@ -51,9 +51,9 @@ as_simplextree.gudhi.simplex_tree.SimplexTree <- function(x, ...) {
res
}

#' @rdname as_simplextree
#' @rdname as_rcpp_simplextree
#' @export
as_simplextree.igraph <- function(x, index = NULL, ...) {
as_rcpp_simplextree.igraph <- function(x, index = NULL, ...) {
if (! is.null(index)) ensure_index(x, index)

# generate vertex list
Expand All @@ -75,13 +75,13 @@ as_simplextree.igraph <- function(x, index = NULL, ...) {
res
}

#' @rdname as_simplextree
#' @rdname as_rcpp_simplextree
#' @export
as_simplextree.network <- function(x, index = NULL, ...) {
as_rcpp_simplextree.network <- function(x, index = NULL, ...) {

# coerce to an igraph object
x <- intergraph::asIgraph(x, ...)

# invoke 'igraph' method
as_simplextree(x, index = index)
as_rcpp_simplextree(x, index = index)
}
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The check flagged the same spellings as the R-hub check.

## Version dependencies

The method `as_py_gudhi.Rcpp_SimplexTree()` operates differently depending on the version of {simplextree} installed. This has not been flagged by documentation and checks but may be important for the maintainers to know.
The method `as_py_gudhi_simplextree.Rcpp_SimplexTree()` operates differently depending on the version of {simplextree} installed. This has not been flagged by documentation and checks but may be important for the maintainers to know.

## Reverse dependencies

Expand Down
12 changes: 6 additions & 6 deletions inst/examples/ex-as-py-gudhi.r
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@ rf <- TDA::ripsFiltration(
maxdimension = 2L, maxscale = 1.7
)
print(rf$cmplx)
gd_rf <- as_py_gudhi(rf)
gd_rf <- as_py_gudhi_simplextree(rf)
print_py_gudhi(gd_rf)
gd_rf2 <- as_py_gudhi(rf$cmplx)
gd_rf2 <- as_py_gudhi_simplextree(rf$cmplx)
print_py_gudhi(gd_rf2)

# convert a simplextree object
st <- simplextree::simplex_tree()
st$insert(list(3:5, 5:6, 8))
gd_st <- as_py_gudhi(st)
gd_st <- as_py_gudhi_simplextree(st)
print_py_gudhi(gd_st)

# convert an igraph object
ig <- igraph::graph(c(1,2, 2,3, 1,3, 3,4))
print(ig)
gd_ig <- as_py_gudhi(ig)
gd_ig <- as_py_gudhi_simplextree(ig)
print_py_gudhi(gd_ig)

# specify 0-simplex indices
set.seed(0L)
ig <- igraph::set_vertex_attr(ig, "id", value = sample(igraph::vcount(ig)) + 1L)
igraph::V(ig)$id
igraph::as_edgelist(ig)
gd_ig2 <- as_py_gudhi(ig, index = "id")
gd_ig2 <- as_py_gudhi_simplextree(ig, index = "id")
print_py_gudhi(gd_ig2)

# convert a network object
el <- data.frame(tails = c(1, 2, 1, 3), heads = c(2, 3, 3, 4))
nw <- network::network.edgelist(el, network::network.initialize(4))
print(nw)
gd_nw <- as_py_gudhi(nw)
gd_nw <- as_py_gudhi_simplextree(nw)
print_py_gudhi(gd_nw)
}
12 changes: 6 additions & 6 deletions inst/examples/ex-as-simplextree.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ rf <- TDA::ripsFiltration(
maxdimension = 2L, maxscale = 1.7
)
print(rf$cmplx)
st_rf <- as_simplextree(rf)
st_rf <- as_rcpp_simplextree(rf)
print(st_rf)
st_rf2 <- as_simplextree(rf$cmplx)
st_rf2 <- as_rcpp_simplextree(rf$cmplx)
print(st_rf2)

\dontrun{
Expand All @@ -16,28 +16,28 @@ print(st_rf2)
gd <- reticulate::import("gudhi")
gd_st <- gd$SimplexTree()
for (s in list(3:5, 5:6, 8)) gd_st$insert(as.list(s))
st_gd <- as_simplextree(gd_st)
st_gd <- as_rcpp_simplextree(gd_st)
st_gd$as_list()
}

# convert an igraph object
ig <- igraph::graph(c(1,2, 2,3, 1,3, 3,4))
print(ig)
st_ig <- as_simplextree(ig)
st_ig <- as_rcpp_simplextree(ig)
print(st_ig)

# specify 0-simplex indices
set.seed(0L)
ig <- igraph::set_vertex_attr(ig, "id", value = sample(igraph::vcount(ig)) + 1L)
igraph::V(ig)$id
igraph::as_edgelist(ig)
st_ig <- as_simplextree(ig, index = "id")
st_ig <- as_rcpp_simplextree(ig, index = "id")
st_ig$vertices
st_ig$edges

# convert a network object
el <- data.frame(tails = c(1, 2, 1, 3), heads = c(2, 3, 3, 4))
nw <- network::network.edgelist(el, network::network.initialize(4))
print(nw)
st_nw <- as_simplextree(nw)
st_nw <- as_rcpp_simplextree(nw)
print(st_nw)
3 changes: 3 additions & 0 deletions man/as_igraph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions man/as_py_gudhi.Rd → man/as_py_gudhi_simplextree.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3bb125f

Please sign in to comment.