Skip to content

Commit

Permalink
chore: update C core and regenerate interfaces (#1237)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviator-app[bot] authored Feb 12, 2024
2 parents c787de1 + 6fd4bce commit e402eec
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 77 deletions.
3 changes: 1 addition & 2 deletions R/aaa-auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ widest_path_widths_floyd_warshall_impl <- function(graph, from=V(graph), to=V(gr
res
}

spanner_impl <- function(graph, stretch, weights) {
spanner_impl <- function(graph, stretch, weights=NULL) {
# Argument checks
ensure_igraph(graph)
stretch <- as.numeric(stretch)
Expand Down Expand Up @@ -1880,7 +1880,6 @@ pseudo_diameter_impl <- function(graph, start.vid, directed=TRUE, unconnected=TR
res
}

# https://github.com/igraph/igraph/commit/d455f61f4832d5207cb0a0475fb5ddc02409ae76#r138442064
pseudo_diameter_dijkstra_impl <- function(graph, weights=NULL, start.vid, directed=TRUE, unconnected=TRUE) {
# Argument checks
ensure_igraph(graph)
Expand Down
2 changes: 1 addition & 1 deletion src/rinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2725,7 +2725,7 @@ SEXP R_igraph_spanner(SEXP graph, SEXP stretch, SEXP weights) {
c_stretch = REAL(stretch)[0];
if (!Rf_isNull(weights)) { R_SEXP_to_vector(weights, &c_weights); }
/* Call igraph */
IGRAPH_R_CHECK(igraph_spanner(&c_graph, &c_spanner, c_stretch, (Rf_isNull(weights) ? 0 : &c_weights)));
IGRAPH_R_CHECK(igraph_spanner(&c_graph, &c_spanner, c_stretch, (Rf_isNull(weights) ? 0 : (Rf_isNull(weights) ? 0 : &c_weights))));

/* Convert output */
PROTECT(spanner=R_igraph_vector_int_to_SEXPp1(&c_spanner));
Expand Down
11 changes: 10 additions & 1 deletion src/vendor/cigraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## [master]

### Fixed

- `igraph_is_forest()` determined that a graph is not a directed forest, and the `roots` output parameter was set to `NULL`, it would incorrectly cache that the graph is also not an undirected forest.
- `igraph_spanner()` now correctly ignores edge directions, and no longer crashes on directed graphs.

### Other

- Documentation improvements.

## [0.10.9] - 2024-02-02

### Added
Expand All @@ -26,7 +35,7 @@
- Performance: Reduced memory usage and improved initialization performance for `igraph_strvector_t`.
- Performance: Improved cache use by `igraph_is_bipartite()`.
- The documentation is now also generated in Texinfo format.
- Documentation improvements
- Documentation improvements.

## [0.10.8] - 2023-11-17

Expand Down
10 changes: 4 additions & 6 deletions src/vendor/cigraph/interfaces/functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ igraph_add_edges:
PARAMS: INOUT GRAPH graph, VERTEX_INDEX_PAIRS edges, ATTRIBUTES attr
DEPS: edges ON graph

igraph_empty_attrs:
PARAMS: OUT GRAPH graph, INTEGER n, BOOLEAN directed, ATTRIBUTES attr

igraph_add_vertices:
PARAMS: INOUT GRAPH graph, INTEGER nv, ATTRIBUTES attr

Expand Down Expand Up @@ -66,9 +69,6 @@ igraph_edges:
PARAMS: GRAPH graph, EDGE_SELECTOR eids, OUT VECTOR_INT edges
DEPS: eids ON graph

igraph_empty_attrs:
PARAMS: OUT GRAPH graph, INTEGER n, BOOLEAN directed, ATTRIBUTES attr

igraph_get_eid:
PARAMS: |-
GRAPH graph, OUT EDGE eid, VERTEX from, VERTEX to,
Expand Down Expand Up @@ -621,7 +621,7 @@ igraph_widest_path_widths_floyd_warshall:

igraph_spanner:
PARAMS: |-
GRAPH graph, OUT EDGE_INDICES spanner, REAL stretch, EDGEWEIGHTS weights
GRAPH graph, OUT EDGE_INDICES spanner, REAL stretch, OPTIONAL EDGEWEIGHTS weights
DEPS: weights ON graph

igraph_subcomponent:
Expand Down Expand Up @@ -1065,14 +1065,12 @@ igraph_radius_dijkstra:
DEPS: weights ON graph

igraph_pseudo_diameter:
NAME-R: pseudo_diameter
PARAMS: |-
GRAPH graph, OUT REAL diameter, VERTEX start_vid,
OUT INTEGER from=NULL, OUT INTEGER to=NULL,
BOOLEAN directed=True, BOOLEAN unconnected=True
igraph_pseudo_diameter_dijkstra:
NAME-R: pseudo_diameter
PARAMS: |-
GRAPH graph, EDGEWEIGHTS weights=NULL,
OUT REAL diameter, VERTEX start_vid,
Expand Down
2 changes: 1 addition & 1 deletion src/vendor/cigraph/src/centrality/truss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ igraph_error_t igraph_trussness(const igraph_t* graph, igraph_vector_int_t* trus
IGRAPH_CHECK(igraph_has_mutual(graph, &is_multigraph, /* loops */ false));
}
if (is_multigraph) {
IGRAPH_ERROR("Trussness is not implemented for graph with multi-edges.", IGRAPH_UNIMPLEMENTED);
IGRAPH_ERROR("Trussness is not implemented for graphs with multi-edges.", IGRAPH_UNIMPLEMENTED);
}

/* Manage the stack to make it memory safe: do not change the order of
Expand Down
2 changes: 1 addition & 1 deletion src/vendor/cigraph/src/graph/basic_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* \ingroup structural
* \function igraph_are_connected
* \brief Decides whether two vertices are connected.
* \brief Decides whether two vertices are adjacent.
*
* Decides whether there are any edges that have \p v1 and \p v2
* as endpoints. This function is of course symmetric for undirected
Expand Down
11 changes: 7 additions & 4 deletions src/vendor/cigraph/src/graph/type_indexededgelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1352,20 +1352,23 @@ igraph_error_t igraph_degree(const igraph_t *graph, igraph_vector_int_t *res,

/**
* \function igraph_get_eid
* \brief Get the edge ID from the end points of an edge.
* \brief Get the edge ID from the endpoints of an edge.
*
* For undirected graphs \c from and \c to are exchangeable.
*
* \param graph The graph object.
* \param eid Pointer to an integer, the edge ID will be stored here.
* If \p error is false and no edge was found, <code>-1</code>
* will be returned.
* \param from The starting point of the edge.
* \param to The end point of the edge.
* \param directed Logical constant, whether to search for directed
* edges in a directed graph. Ignored for undirected graphs.
* \param error Logical scalar, whether to report an error if the edge
* was not found. If it is false, then -1 will be assigned to \p eid.
* Note that invalid vertex IDs in input arguments (\p from or \p to)
* always return an error code.
* was not found. If it is false, then <code>-1</code> will be
* assigned to \p eid. Note that invalid vertex IDs in input
* arguments (\p from or \p to) always trigger an error,
* regardless of this setting.
* \return Error code.
* \sa \ref igraph_edge() for the opposite operation, \ref igraph_get_all_eids_between()
* to retrieve all edge IDs between a pair of vertices.
Expand Down
4 changes: 3 additions & 1 deletion src/vendor/cigraph/src/paths/all_shortest_paths.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
* \brief All shortest paths (geodesics) from a vertex.
*
* When there is more than one shortest path between two vertices,
* all of them will be returned.
* all of them will be returned. Every edge is considered separately,
* therefore in graphs with multi-edges, this function may produce
* a very large number of results.
*
* \param graph The graph object.
* \param vertices The result, the IDs of the vertices along the paths.
Expand Down
41 changes: 21 additions & 20 deletions src/vendor/cigraph/src/paths/sparsifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ static void igraph_i_clear_lightest_edges_to_clusters(
* \function igraph_spanner
* \brief Calculates a spanner of a graph with a given stretch factor.
*
* A spanner of a graph G = (V,E) with a stretch t is a subgraph
* H = (V,Es) such that Es is a subset of E and the distance
* between any pair of nodes in H is at most t times the distance
* in G. The returned graph is always a spanner of the
* given graph with the specified stretch. For weighted graphs the
* number of edges in the spanner is O(k * n^(1 + 1 / k)), where k is
* k = (stretch + 1) / 2, m is the number of edges and n is the number
* of nodes in G. For unweighted graphs the number of edges is
* O(n^(1 + 1 / k) + kn).
* A spanner of a graph <code>G = (V,E)</code> with a stretch \c t is a
* subgraph <code>H = (V,Es)</code> such that \c Es is a subset of \c E
* and the distance between any pair of nodes in \c H is at most \c t
* times the distance in \c G. The returned graph is always a spanner of
* the given graph with the specified stretch. For weighted graphs the
* number of edges in the spanner is <code>O(k n^(1 + 1 / k))</code>, where
* \c k is <code>k = (t + 1) / 2</code>, \c m is the number of edges
* and \c n is the number of nodes in \c G. For unweighted graphs the number
* of edges is <code>O(n^(1 + 1 / k) + kn)</code>.
*
* </para><para>
* This function is based on the algorithm of Baswana and Sen: "A Simple and
Expand All @@ -138,10 +138,10 @@ static void igraph_i_clear_lightest_edges_to_clusters(
* is directed, the directions of the edges will be ignored.
* \param spanner An initialized vector, the IDs of the edges that constitute
* the calculated spanner will be returned here. Use
* \ref igraph_subgraph_from_edges() to extract the spanner as a separate
* \ref igraph_subgraph_from_edges() to extract the spanner as a separate
* graph object.
* \param stretch The stretch factor of the spanner.
* \param weights The edge weights or NULL.
* \param stretch The stretch factor \c t of the spanner.
* \param weights The edge weights or \c NULL.
*
* \return Error code:
* \clist
Expand All @@ -150,13 +150,14 @@ static void igraph_i_clear_lightest_edges_to_clusters(
* \endclist
*
* Time complexity: The algorithm is a randomized Las Vegas algorithm. The expected
* running time is O(km) where k is the value mentioned above.
* running time is O(km) where k is the value mentioned above and m is the number
* of edges.
*/
igraph_error_t igraph_spanner(const igraph_t *graph, igraph_vector_int_t *spanner,
igraph_real_t stretch, const igraph_vector_t *weights) {

igraph_integer_t no_of_nodes = igraph_vcount(graph);
igraph_integer_t no_of_edges = igraph_ecount(graph);
const igraph_integer_t no_of_nodes = igraph_vcount(graph);
const igraph_integer_t no_of_edges = igraph_ecount(graph);
igraph_integer_t i, j, v, nlen, neighbor, cluster;
igraph_real_t sample_prob, k = (stretch + 1) / 2, weight, lightest_sampled_weight;
igraph_vector_int_t clustering, lightest_eid;
Expand All @@ -178,21 +179,21 @@ igraph_error_t igraph_spanner(const igraph_t *graph, igraph_vector_int_t *spanne

/* Test validity of stretch factor */
if (stretch < 1) {
IGRAPH_ERROR("Stretch factor must be at least 1", IGRAPH_EINVAL);
IGRAPH_ERROR("Stretch factor must be at least 1.", IGRAPH_EINVAL);
}

/* Test validity of weights vector */
if (weights) {
if (igraph_vector_size(weights) != no_of_edges) {
IGRAPH_ERROR("Weight vector length does not match", IGRAPH_EINVAL);
IGRAPH_ERROR("Weight vector length does not match.", IGRAPH_EINVAL);
}
if (no_of_edges > 0) {
igraph_real_t min = igraph_vector_min(weights);
if (min < 0) {
IGRAPH_ERROR("Weight vector must be non-negative", IGRAPH_EINVAL);
IGRAPH_ERROR("Weight vector must be non-negative.", IGRAPH_EINVAL);
}
else if (isnan(min)) {
IGRAPH_ERROR("Weight vector must not contain NaN values", IGRAPH_EINVAL);
IGRAPH_ERROR("Weight vector must not contain NaN values.", IGRAPH_EINVAL);
}
}
}
Expand All @@ -205,7 +206,7 @@ igraph_error_t igraph_spanner(const igraph_t *graph, igraph_vector_int_t *spanne
// explicitly; it will only exist in terms of the incidence and the adjacency
// lists, maintained in parallel as the edges are removed from the residual
// graph.
IGRAPH_CHECK(igraph_inclist_init(graph, &inclist, IGRAPH_OUT, IGRAPH_NO_LOOPS));
IGRAPH_CHECK(igraph_inclist_init(graph, &inclist, IGRAPH_ALL, IGRAPH_NO_LOOPS));
IGRAPH_FINALLY(igraph_inclist_destroy, &inclist);
IGRAPH_CHECK(igraph_adjlist_init_from_inclist(graph, &adjlist, &inclist));
IGRAPH_FINALLY(igraph_adjlist_destroy, &adjlist);
Expand Down
Loading

0 comments on commit e402eec

Please sign in to comment.