-
-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: adapt to cut.prob's new handling of NULL in the C core #1602
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ triad.census <- function(graph) { # nocov start | |
#' @inheritParams count_motifs | ||
#' @keywords internal | ||
#' @export | ||
graph.motifs.no <- function(graph, size = 3, cut.prob = rep(0, size)) { # nocov start | ||
graph.motifs.no <- function(graph, size = 3, cut.prob = NULL) { # nocov start | ||
lifecycle::deprecate_soft("2.0.0", "graph.motifs.no()", "count_motifs()") | ||
count_motifs(graph = graph, size = size, cut.prob = cut.prob) | ||
} # nocov end | ||
|
@@ -39,7 +39,7 @@ graph.motifs.no <- function(graph, size = 3, cut.prob = rep(0, size)) { # nocov | |
#' @inheritParams sample_motifs | ||
#' @keywords internal | ||
#' @export | ||
graph.motifs.est <- function(graph, size = 3, cut.prob = rep(0, size), sample.size = vcount(graph) / 10, sample = NULL) { # nocov start | ||
graph.motifs.est <- function(graph, size = 3, cut.prob = NULL, sample.size = vcount(graph) / 10, sample = NULL) { # nocov start | ||
lifecycle::deprecate_soft("2.0.0", "graph.motifs.est()", "sample_motifs()") | ||
sample_motifs(graph = graph, size = size, cut.prob = cut.prob, sample.size = sample.size, sample = sample) | ||
} # nocov end | ||
|
@@ -54,7 +54,7 @@ graph.motifs.est <- function(graph, size = 3, cut.prob = rep(0, size), sample.si | |
#' @inheritParams motifs | ||
#' @keywords internal | ||
#' @export | ||
graph.motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { # nocov start | ||
graph.motifs <- function(graph, size = 3, cut.prob = NULL) { # nocov start | ||
lifecycle::deprecate_soft("2.0.0", "graph.motifs()", "motifs()") | ||
motifs(graph = graph, size = size, cut.prob = cut.prob) | ||
} # nocov end | ||
|
@@ -110,7 +110,8 @@ dyad.census <- function(graph) { # nocov start | |
#' directed graphs and sizes 3-6 in undirected graphs. | ||
#' @param cut.prob Numeric vector giving the probabilities that the search | ||
#' graph is cut at a certain level. Its length should be the same as the size | ||
#' of the motif (the `size` argument). By default no cuts are made. | ||
#' of the motif (the `size` argument). | ||
#' If `NULL`, the default, no cuts are made. | ||
#' @return `motifs()` returns a numeric vector, the number of occurrences of | ||
#' each motif in the graph. The motifs are ordered by their isomorphism | ||
#' classes. Note that for unconnected subgraphs, which are not considered to be | ||
|
@@ -125,10 +126,12 @@ dyad.census <- function(graph) { # nocov start | |
#' motifs(g, 3) | ||
#' count_motifs(g, 3) | ||
#' sample_motifs(g, 3) | ||
motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { | ||
motifs <- function(graph, size = 3, cut.prob = NULL) { | ||
ensure_igraph(graph) | ||
cut.prob <- as.numeric(cut.prob) | ||
if (length(cut.prob) != size) { | ||
|
||
if (!is.null(cut.prob)) cut.prob <- as.numeric(cut.prob) | ||
|
||
if (!is.null(cut.prob) && length(cut.prob) != size) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please help me understand the code below. Is it repeating the last entry to fill up the vector until it reaches What if it is longer than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just errors: motifs(make_ring(10), cut.prob=0.1)
Error in motifs(make_ring(10), cut.prob = 0.1) :
At vendor/cigraph/src/misc/motifs.c:156 : Cut probability vector size (0) must agree with motif size (3). Invalid value Why does it not trigger the I think I'm just too tired for this right now :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code path is triggered, but it produces an incorrect vector. I know this is not your code, but can you fix it @maelle ? My recommendation is:
No preference as to which from my size (maybe 1 is a tiny bit nicer, but also overly complicated?) Whatever you choose, can you document it? Also, can you make sure it's implemented in all motif functions, not just this one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So do you mean
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is option 2. Let me give examples for option 1 and option 2, assuming Option 1: Input: Input: Input: So, repeat the last entry to fill to size. Option 2: Input: Input: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @krlmlr any opinion here? |
||
cut.prob <- c( | ||
cut.prob[-length(cut.prob)], | ||
rep(cut.prob[-length(cut.prob)], length(cut.prob) - 1) | ||
|
@@ -138,7 +141,7 @@ motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { | |
on.exit(.Call(R_igraph_finalizer)) | ||
res <- .Call( | ||
R_igraph_motifs_randesu, graph, as.numeric(size), | ||
as.numeric(cut.prob) | ||
cut.prob | ||
) | ||
res[is.nan(res)] <- NA | ||
res | ||
|
@@ -156,7 +159,8 @@ motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { | |
#' @param size The size of the motif. | ||
#' @param cut.prob Numeric vector giving the probabilities that the search | ||
#' graph is cut at a certain level. Its length should be the same as the size | ||
#' of the motif (the `size` argument). By default no cuts are made. | ||
#' of the motif (the `size` argument). | ||
#' If `NULL`, the default, no cuts are made. | ||
#' @return `count_motifs()` returns a numeric scalar. | ||
#' @seealso [isomorphism_class()] | ||
#' | ||
|
@@ -168,10 +172,12 @@ motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { | |
#' motifs(g, 3) | ||
#' count_motifs(g, 3) | ||
#' sample_motifs(g, 3) | ||
count_motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { | ||
count_motifs <- function(graph, size = 3, cut.prob = NULL) { | ||
ensure_igraph(graph) | ||
cut.prob <- as.numeric(cut.prob) | ||
if (length(cut.prob) != size) { | ||
|
||
if (!is.null(cut.prob)) cut.prob <- as.numeric(cut.prob) | ||
|
||
if (!is.null(cut.prob) && length(cut.prob) != size) { | ||
cut.prob <- c( | ||
cut.prob[-length(cut.prob)], | ||
rep(cut.prob[-length(cut.prob)], length(cut.prob) - 1) | ||
|
@@ -181,7 +187,7 @@ count_motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { | |
on.exit(.Call(R_igraph_finalizer)) | ||
.Call( | ||
R_igraph_motifs_randesu_no, graph, as.numeric(size), | ||
as.numeric(cut.prob) | ||
cut.prob | ||
) | ||
} | ||
|
||
|
@@ -198,7 +204,8 @@ count_motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { | |
#' in directed graphs and sizes 3-6 in undirected graphs. | ||
#' @param cut.prob Numeric vector giving the probabilities that the search | ||
#' graph is cut at a certain level. Its length should be the same as the size | ||
#' of the motif (the `size` argument). By default no cuts are made. | ||
#' of the motif (the `size` argument). | ||
#' If `NULL`, the default, no cuts are made. | ||
#' @param sample.size The number of vertices to use as a starting point for | ||
#' finding motifs. Only used if the `sample` argument is `NULL`. | ||
#' The default is `ceiling(vcount(graph) / 10)` . | ||
|
@@ -224,8 +231,10 @@ sample_motifs <- function( | |
sample = NULL | ||
) { | ||
ensure_igraph(graph) | ||
cut.prob <- as.numeric(cut.prob) | ||
if (length(cut.prob) != size) { | ||
|
||
if (!is.null(cut.prob)) cut.prob <- as.numeric(cut.prob) | ||
|
||
if (!is.null(cut.prob) && length(cut.prob) != size) { | ||
cut.prob <- c( | ||
cut.prob[-length(cut.prob)], | ||
rep(cut.prob[-length(cut.prob)], length(cut.prob) - 1) | ||
|
@@ -244,7 +253,7 @@ sample_motifs <- function( | |
on.exit(.Call(R_igraph_finalizer)) | ||
.Call( | ||
R_igraph_motifs_randesu_estimate, graph, as.numeric(size), | ||
as.numeric(cut.prob), as.numeric(sample.size), sample | ||
cut.prob, as.numeric(sample.size), sample | ||
) | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
sample.size
should default toNULL
in this deprecated function as well, to matchsample_motifs
.Do what you think is best, just drawing attention to this.