Skip to content

Commit 1d9a910

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 f4adc25 commit 1d9a910

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())
@@ -9541,6 +9542,7 @@ def bipartite_double(self, extended=False):
95419542
G.name("%sBipartite Double of %s" % (prefix, self.name()))
95429543
return G
95439544

9545+
@cached_method
95449546
@doc_index("Graph properties")
95459547
def is_projective_planar(self, return_map=False):
95469548
r"""
@@ -9568,7 +9570,7 @@ def is_projective_planar(self, return_map=False):
95689570
The Peterson graph is a known projective planar graph::
95699571
95709572
sage: P = graphs.PetersenGraph()
9571-
sage: P.is_projective_planar() # long time
9573+
sage: P.is_projective_planar()
95729574
True
95739575
95749576
`K_{4,4}` has a projective plane crossing number of 2. One of the

0 commit comments

Comments
 (0)