The flatsurf.cache Modules#

Adapts sage.misc.cachefunc for sage-flatsurf.

Some methods on surfaces in sage-flatsurf benefit a lot from caching. However, we cannot simply put @cached_method on these surfaces since they are often defined in a class that is used by both, mutable and immutable surfaces. Caching for mutable surfaces would be incorrect, or we would have to manually clear caches upon mutation.

Therefore, we add a decorator @cached_surface_method that only caches if the surface is immutable.

EXAMPLES:

sage: from flatsurf import MutableOrientedSimilaritySurface, translation_surfaces
sage: S = MutableOrientedSimilaritySurface.from_surface(translation_surfaces.square_torus())
sage: S.edge_matrix(0, 0) is S.edge_matrix(0, 0)
False

When we call flatsurf.geometry.surface.MutablePolygonalSurface.set_immutable(), caching is enabled for this method:

sage: S.set_immutable()
sage: S.edge_matrix(0, 0) is S.edge_matrix(0, 0)
True
class flatsurf.cache.CachedSurfaceMethod(f, name, key, do_pickle)[source]#

Customizes a method in a class so that it conditionally enables caching just like SageMath’s sage.misc.cachefunc.CachedMethod does.

class flatsurf.cache.CachedSurfaceMethodCaller(cached_caller, *args, **kwargs)[source]#

Adapts the sage.misc.cachefunc.CachedMethodCaller from SageMath to not do any caching if the defining surface is mutable.

Note that this only handles methods with arguments, for methods without arguments, a caller that customizes sage.misc.cachefunc.CachedMethodCallerNoArgs must be used.

flatsurf.cache.cached_surface_method(f, name=None, key=None, do_pickle=None)[source]#

Make a surface method cached as soon as the surface is immutable.

This is a drop-in replacement for SageMath’s sage.misc.cachefunc.cached_method but it does not provide any caching for mutable surfaces.