Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sage/graphs/base/boost_graph.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ cdef extern from "boost_interface.cpp":
v_index num_verts()
void add_edge(v_index u, v_index v)
void add_edge(v_index u, v_index v, double w)
vector[pair[int, pair[int, double]]] edge_list()
vector[pair[v_index, pair[v_index, double]]] edge_list()
e_index num_edges()
result_ec edge_connectivity()
double clustering_coeff(v_index v)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/base/boost_graph.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ cdef get_predecessors(BoostWeightedGraph g, result, int_to_v, directed, weight_t
sage: johnson_shortest_paths(g, distances=False, predecessors=True) == expected
True
"""
cdef vector[pair[int, pair[int, double]]] edges
cdef vector[pair[v_index, pair[v_index, double]]] edges
Comment thread
saraedum marked this conversation as resolved.
sig_on()
edges = g.edge_list()
sig_off()
Expand Down
6 changes: 3 additions & 3 deletions src/sage/graphs/base/boost_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <iostream>
#include <utility>

typedef int v_index;
typedef long e_index;
typedef unsigned long v_index;
typedef unsigned long e_index;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this change is necessary. I think you got confused when the programmer lies to cython or something

https://cython-guidelines.readthedocs.io/en/latest/articles/lie.html

similar to #39098 (comment)

In other words: even though in the pxd the declaration is

    ctypedef unsigned long v_index
    ctypedef unsigned long e_index

in compiled code it should still use int. (before the change)

Or so I think.

Copy link
Copy Markdown
Member Author

@saraedum saraedum Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why the programmer would want to lie to Cython here? So, e_index should be the type that num_edges returns. That's boost::graph_traits<G>::edges_size_type. I don't think I can reference that type directly from a pxd (but maybe there is a way, then I should probably use it.) Let me put a static assert into the code to check that this is actually unsigned long. Similarly, v_index is vertex_index_t and size_t and vertices_size_type. I guess they are all just unsigned long but I'll add a static assert to be sure.
This is not terribly clean. If we end up building on a platform where this is not true, then we might have to stop identifying these types but I think it's just the same type on all platforms anyway.

Maybe I'll put in the extra work and actually separate these types but I think in Cython I'll just set them all to unsigned long.

I am not sure I really understood your objection here though. Maybe you can rephrase what you had in mind?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now what you meant with the v_index. It's the type used in the definition of adjacency_list. So if I change it to an unsigned type, this actually changes something.


// This struct is the output of the edge connectivity Boost algorithm.
typedef struct {
Expand Down Expand Up @@ -84,11 +84,11 @@ class BoostGraph
// This map is a parameter/output for biconnected_components function
typedef typename std::map<edge_descriptor, int, order_edges> edge_map;

public:
adjacency_list graph;
std::vector<vertex_descriptor> vertices;
vertex_to_int_map index;

public:
Comment on lines -87 to +91
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary to fix the warning. But since these fields are not part of the Cython interface, they can as well be private (would have helped me to understand things more quickly.

BoostGraph() {
}

Expand Down