Skip to content

Commit b52ce77

Browse files
committed
sage.graphs.graph: make is_projective_planar() a @cached_method
The is_projective_planar() function can be very slow. The first example in the documentation is the Petersen graph, on which the method is taking over six minutes to arrive at the answer (True). We mark it as a @cached_method, since that will allow us to pre- fill the cache for graphs that are known to be projective planar, saving the user a lot of time.
1 parent 4e2319b commit b52ce77

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/sage/graphs/graph.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@
428428
from sage.parallel.decorate import parallel
429429
from sage.misc.lazy_import import lazy_import, LazyImport
430430
from sage.features.mcqd import Mcqd
431+
from sage.misc.cachefunc import cached_method
431432

432433
lazy_import('sage.graphs.mcqd', ['mcqd'],
433434
feature=Mcqd())
@@ -9501,6 +9502,7 @@ def bipartite_double(self, extended=False):
95019502
G.name("%sBipartite Double of %s" % (prefix, self.name()))
95029503
return G
95039504

9505+
@cached_method
95049506
@doc_index("Graph properties")
95059507
def is_projective_planar(self, return_map=False):
95069508
r"""
@@ -9528,7 +9530,7 @@ def is_projective_planar(self, return_map=False):
95289530
The Petersen graph is a known projective planar graph::
95299531
95309532
sage: P = graphs.PetersenGraph()
9531-
sage: P.is_projective_planar() # long time
9533+
sage: P.is_projective_planar()
95329534
True
95339535
95349536
`K_{4,4}` has a projective plane crossing number of 2. One of the

0 commit comments

Comments
 (0)