fix: Fix direction of edges when restoring#805
Conversation
|
This appears to work also with igraph/igraphdata#5. |
|
How can we test correct restoration in this repo? |
|
On the current main branch: options(conflicts.policy = list(warn = FALSE))
library(igraph)
g <- make_ring(3, directed = TRUE)
g
#> IGRAPH a6d007c D--- 3 3 -- Ring graph
#> + attr: name (g/c), mutual (g/l), circular (g/l)
#> + edges from a6d007c:
#> [1] 1->2 2->3 3->1
gs <- unserialize(serialize(g, NULL))
gs
#> IGRAPH a6d007c D--- 3 3 -- Ring graph
#> + attr: name (g/c), mutual (g/l), circular (g/l)
#> + edges from a6d007c:
#> [1] 2->1 3->2 1->3Created on 2023-05-21 with reprex v2.0.2 |
|
I also created small C example to play around with this in igraph. It should be #include <igraph.h>
void print_vector_int(igraph_vector_int_t *v) {
igraph_integer_t i, n = igraph_vector_int_size(v);
for (i = 0; i < n; i++) {
printf(" %" IGRAPH_PRId, VECTOR(*v)[i]);
}
printf("\n");
}
int main(void) {
igraph_t g;
igraph_vector_int_t v1, v2;
/* simple use */
igraph_vector_int_init(&v1, 8);
VECTOR(v1)[0] = 0;
VECTOR(v1)[1] = 1;
VECTOR(v1)[2] = 1;
VECTOR(v1)[3] = 2;
VECTOR(v1)[4] = 3;
VECTOR(v1)[5] = 2;
VECTOR(v1)[6] = 2;
VECTOR(v1)[7] = 2;
igraph_bool_t directed = 1;
igraph_create(&g, &v1, 0, directed);
igraph_vector_int_t v;
igraph_integer_t i, s=igraph_vector_int_size(&g.from);
igraph_vector_int_init(&v, s*2);
for (i = 0; i < s; ++i) {
igraph_integer_t from_v=VECTOR(g.from)[i];
igraph_integer_t to_v=VECTOR(g.to)[i];
igraph_vector_int_set(&v, i*2, from_v);
igraph_vector_int_set(&v, i*2+1, to_v);
}
print_vector_int(&g.from);
print_vector_int(&g.to);
print_vector_int(&v);
igraph_t g2;
igraph_empty(&g2, g.n, directed);
igraph_add_edges(&g2, &v, NULL);
print_vector_int(&g2.from);
print_vector_int(&g2.to);
igraph_destroy(&g);
igraph_destroy(&g2);
igraph_vector_int_destroy(&v);
return 0;
} |
|
Working on a test here. |
|
@Antonov548: The test failures are interesting. Can you replicate on Ubuntu? What happens here? https://github.com/igraph/rigraph/actions/runs/5038508208/jobs/9036118195?pr=805#step:6:205 |
|
I can't replicate on Ubuntu. I'll remove the snapshot test for now and merge. |
It's very strange. But I can replicate it time to time. Sometime it prints edges some time not. I there any function which is responsible for this printing? |
|
Yes, weird. We need a reprex first. Does it fail on your machine when you print in a loop? How many iterations do you need? |
|
What version of R are you running? I'm not seeing failures with R 4.3.0 on Ubuntu. |
|
I see it coming from |


Should the order be from->to?