fridom.framework.utils.decorators.cache_figure

Contents

fridom.framework.utils.decorators.cache_figure#

fridom.framework.utils.decorators.cache_figure(func: Callable, name: str = None, force_recompute: bool = False, dpi: int = 200) callable[source]#

Cache a figure to disk, if it exists return the image from disk.

Description#

This decorator caches a figure to disk. If the figure already exists on disk, the image is loaded from disk. If the figure does not exist on disk, the figure is computed and saved to disk. This is useful to avoid recomputing expensive figures.

Parameters#

funcCallable

The function that computes the figure. This function must return a matplotlib figure.

namestr

The name of the figure file.

force_recomputebool (default=False)

If True, the figure is recomputed even if it exists on disk.

dpiint (default=200)

The DPI of the figure.

Returns#

Callable

The function that returns the image.